From c7bbd3faf6de7c59ff65848450b0640a7ee2ecb1 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 4 Nov 2026 10:19:36 +0800 Subject: [PATCH] routing: a Claude joined over the network shows its windows in Accounts and keys (yi_time on Discord) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A remote magpie's provider row on the Routing page showed no usage, while the subscriptions above it did. The remote's cards already reach the window as /api/usage/quotas entries with `from` set (provider = /), but the page's cardOf/winsOf match only kind "account" with no `from`. remoteWinsOf (plugins/routing/client.js) now draws those windows on a remote-magpie row: a claude-* model row gets the remote's claude cards, gpt/codex/o\d rows its codex cards, each window prefixed by the user when several cards match. When the remote's read failed it says "Allowance unavailable — hover for why" with the error as the title (existing string, all languages), never 0. The usage comes from the machine that owns the account; no gateway change. Run (mote, no Go change): - routing-remote-windows.test.cjs (new; 5 languages, widths 1100 and 420, chromium and webkit) and routing-account-windows.test.cjs at ec697e692 on origin/main 07f02d0d9..: 44 pass, 0 fail. - Broken by hand: render call removed, and the model-family filter removed; each took the new test to 0 pass, 11 fail. - Full go test -timeout 45m ./... at ea1aab179 (same client.js, rebased on f177c36a9): 86 ok, 2 red, neither from this change: TestCoreScriptBudget (1534154 > 1533802 at origin/main too, #5139) and TestMainWindowCorners/macOS_26_SDK (#3949). - Six routing GUI files, serial, on origin/main cd83c3147 with no change: 85 pass, 19 fail (rule-remove #3096, rule-drag #3789, row-swap #3799, order-unknown #4627, rules-line #3593; commented there). On this change 27 and 28 fail; routing-rules-line alone 6 and 7 of 20 against 4 of 20 on main, all the same 5s waitForFunction on .rt-gedit with the failing cells changing between runs. I judge it the same flake; not proven. - The full GUI suite was started and killed after ~3h unfinished; its reds were in unrelated files (account-eye passes 15/15 alone). Not tried: a real two-machine LAN run, a real Claude account on a remote, Windows or Linux GUI engines (WebKitGTK). --- docs/subsystems/gui-shell.md | 10 ++ internal/gui/assets/plugins/routing/client.js | 33 ++++++- .../gui/tests/routing-remote-windows.test.cjs | 99 +++++++++++++++++++ 3 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 internal/gui/tests/routing-remote-windows.test.cjs diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index b4966d263..02c36cbd1 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -217,6 +217,16 @@ missing or over a minute old), never `?asked=1`. A kept day's list shows none, since those requests were weighed by readings long gone. See `routing-account-windows.test.cjs`. +A Claude (or Codex) joined over the network, a Remote magpie provider's +row, shows the windows of the accounts signed in on that computer the same +way (`remoteWinsOf` in `client.js`): the Usage page's cards with `from` +whose provider id is the remote's, a slash and the card's. The computer +that holds the account tells its usage; this one reads nothing new. A +Claude model's row is told Claude's cards alone and a ChatGPT model's +Codex's; with more than one card the account's user leads each window. A +remote whose read failed shows "Allowance unavailable" with the reason on +hover, never a figure. See `routing-remote-windows.test.cjs`. + The refresh beside the Accounts and keys heading (`#rtReadAllowances`, #1834) reads them again by hand: `loadQuotas(true)`, the asked read the Usage page's Refresh now makes. It turns while the read is on its way, diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index 49a1542db..5eb65cb6a 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -4170,6 +4170,35 @@ function routingPage(part) { + (x.resetsAt ? " · " + resetInText(new Date(x.resetsAt)) : "")) : []; } + // remoteWinsOf: the windows of the accounts signed in on another + // computer's magpie (a Remote magpie provider, joined over the network), + // as the Usage page has read them from there: its cards are app.js's + // quotas with `from`, their provider id the remote's, a slash, and the + // card's. The computer that holds the account tells its usage, and the + // row says which account when the remote has more than one. A model of + // Claude's is told Claude's cards alone, ChatGPT's Codex's. A remote + // whose read failed says it is unknown, never 0 or nothing. + const REMOTE_FAMILY = [[/^claude/i, "claude"], [/^(gpt|codex|o\d)/i, "codex"]]; + function remoteWinsOf(w) { + if (w.preset !== "remote-magpie" || w.kind === "account" || !Array.isArray(quotas)) return []; + const fam = REMOTE_FAMILY.find(([re]) => re.test(w.model || ""))?.[1]; + const mine = quotas.filter((q) => q.from && q.kind === "subscription" && (q.provider === w.provider || q.provider.startsWith(w.provider + "/"))); + const cards = mine.filter((q) => q.provider !== w.provider && !q.error && q.windows?.length && (!fam || q.provider === w.provider + "/" + fam)); + if (!cards.length) { + // the remote's own card, saying why nothing was read from it + const bad = mine.find((q) => q.provider === w.provider && q.error); + return bad ? [{ text: t("Allowance unavailable — hover for why"), title: bad.error }] : []; + } + const out = []; + for (const q of cards) { + const who = cards.length > 1 && q.user ? q.user + ": " : ""; + for (const x of familyWindows(q.windows) || []) { + out.push({ text: who + t(x.name) + " " + quotaText(x) + (x.resetsAt ? " · " + resetInText(new Date(x.resetsAt)) : "") }); + } + } + return out; + } + // modelRest keeps the latest word of one of an account's models resting // alone (#1960) function modelRest(a, m, rest, when) { @@ -4347,10 +4376,10 @@ function routingPage(part) { // the Usage page read them (#1833): the figure above is the one // window routing went by. Live only: a kept day's requests were // weighed by readings long gone. - const ws = day ? [] : winsOf(w); + const ws = day ? [] : [...winsOf(w).map((text) => ({ text })), ...remoteWinsOf(w)]; if (ws.length) { const line = el("div", "wins"); - line.append(...ws.map((s) => el("span", "", s))); + line.append(...ws.map((x) => { const e = el("span", "", x.text); if (x.title) e.title = x.title; return e; })); row.append(line); } row.append(tally); diff --git a/internal/gui/tests/routing-remote-windows.test.cjs b/internal/gui/tests/routing-remote-windows.test.cjs new file mode 100644 index 000000000..e890a5fd5 --- /dev/null +++ b/internal/gui/tests/routing-remote-windows.test.cjs @@ -0,0 +1,99 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// A Claude joined over the network (a Remote magpie provider) shows its +// windows in Routing's Accounts and keys like a local account does, as the +// computer that holds the account read them: the Usage page's cards with +// `from`. Claude's row is told Claude's cards, not Codex's; a remote whose +// read failed says the allowance is unavailable, never 0. In every +// language, at a window's width and at 420px, in both engines. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); +const now = Date.now(); +const iso = (ms) => new Date(ms).toISOString(); +const remote = (id, name, model) => ({ id: id + "-k", provider: id, name, preset: "remote-magpie", icon: "magpie", kind: "provider", model, known: false }); +const accts = [remote("home", "Home", "claude-opus-5"), remote("den", "Den", "claude-opus-5")]; +const route = { + id: 7, seq: 7, time: iso(now - 2000), agent: "claude", model: "claude-opus-5", provider: "home", done: true, status: 200, ms: 900, tokens: 1500, + order: accts, tries: [{ id: "home-k", model: "claude-opus-5", start: iso(now - 2000), done: true, ms: 800, status: 200 }], +}; +const cards = [ + { provider: "home/claude", name: "Claude · Home", kind: "subscription", user: "work@example.com", from: "Home", windows: [ + { name: "5 hours", used: 40, resetsAt: iso(now + 130 * 60e3) }, + { name: "7 days", used: 12, resetsAt: iso(now + 73 * 3600e3) }, + ] }, + { provider: "home/codex", name: "Codex · Home", kind: "subscription", user: "c@example.com", from: "Home", windows: [{ name: "5 hours", used: 77 }] }, + { provider: "den", name: "Den", icon: "magpie", kind: "subscription", from: "Den", windows: [], error: "couldn't reach the remote magpie: connection refused" }, +]; + +function serve(lang, asks) { + const state = { agents: [{ id: "claude", name: "Claude Code", path: "/test/claude", fields: [] }], profiles: [], settings: { lang, theme: "light", quotaLeft: false } }; + return async (r) => { + const url = new URL(r.request().url()); + const json = (data) => r.fulfill({ json: data }); + if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` }); + if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" }); + if (url.pathname === "/api/state") return json(state); + if (url.pathname === "/api/gateway/trace") { + if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes + return json({ mine: true, now: new Date().toISOString(), seq: 7, totals: { requests: 1, rerouted: 0, errors: 0 }, routes: [route] }); + } + if (url.pathname === "/api/usage/quotas") { asks.push(url.search); return json(cards); } + if (url.pathname === "/api/usage/quotas/history") return json([]); + if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] }); + if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] }); + if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } }); + if (url.pathname.startsWith("/api/")) return json({}); + const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname); + const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)]; + await r.fulfill({ body: await fs.readFile(file), contentType }); + }; +} + +const words = { + en: { wins: ["5 hours 40% used · resets in 2h", "7 days 12% used · resets in 3d"], unknown: "Allowance unavailable — hover for why" }, + zh: { wins: ["5 小时 已用 40% · 2 小时后重置", "7 天 已用 12% · 3 天后重置"], unknown: "暂时无法获取额度 — 悬停查看原因" }, + "zh-TW": { wins: ["5 小時 已用 40% · 2 小時後重置", "7 天 已用 12% · 3 天后重置"], unknown: "暫時無法取得額度 — 懸停查看原因" }, + ja: { wins: ["5 時間 使用済み 40% · 2 時間後にリセット", "7 日 使用済み 12% · 3 日後にリセット"], unknown: "利用枠を取得できません — ホバーで理由を表示" }, + de: { wins: ["5 Stunden 40% verbraucht · Reset in 2 Std.", "7 Tage 12% verbraucht · Reset in 3 T."], unknown: "Kontingent nicht verfügbar — für den Grund darüberfahren" }, +}; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + test(`${engine}: a Claude joined over the network shows its windows in Accounts and keys`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + for (const lang of Object.keys(words)) { + for (const width of [1100, 420]) { + await t.test(`${lang} at ${width}px`, async () => { + const ctx = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" }); + try { + const page = await ctx.newPage(); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = [], asks = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, asks)); + await page.goto("http://magpie.test/?view=routing"); + await page.locator(".rt-act .wins span").first().waitFor(); + const rows = page.locator(".rt-act"); + const denRow = rows.nth(0), homeRow = rows.nth(1); // listed by name + // Claude's windows only: Codex's 77% on the same remote is not on Claude's row + assert.deepEqual(await homeRow.locator(".wins span").allTextContents(), words[lang].wins); + // a failed read is unknown, with the reason on hover, never a figure + assert.deepEqual(await denRow.locator(".wins span").allTextContents(), [words[lang].unknown]); + assert.match(await denRow.locator(".wins span").getAttribute("title"), /connection refused/); + const over = await homeRow.evaluate((e) => Math.max(e.scrollWidth - e.clientWidth, document.documentElement.scrollWidth - innerWidth)); + assert.ok(over <= 1, `${lang} at ${width}: ${over}px past`); + assert.ok(asks.every((s) => !s.includes("asked")), "never an asked read: " + asks.join(", ")); + assert.deepEqual(errors, []); + } finally { + await ctx.close(); + } + }); + } + } + }); +}