providers: Claude Code's and Codex's Accounts say switching needs no connecting (Greatrobbort on X)

Greatrobbort on X: "多账号这个我一直都没搞明白到底需要在magpie关联agent不". The
owner asked for the window to say it: to have accounts switched
automatically, the agent needn't be connected. magpie moves Claude Code's
and Codex's own sign-in to the next account with room either way
(KeepOnAnAccountWithRoom runs SwitchWhenSpent for both, whether or not the
agent's config points at magpie).

The Accounts field's hint on Claude's and Codex's subscriptions now ends
"Just want accounts switched? {agent} needn't be connected to magpie.", after
whichever hint it shows (Routing's or the sign-in one). zh, zh-TW, ja and de
have it. Other subscriptions, which only the gateway uses, don't.

app.js stays in its budget (9 bytes over main, 12 of room): three
account-row comments cut down, no raise.

accounts-switch-alone.test.cjs opens Claude's (no Routing) and Codex's
(Routing smart) editors and finds the line, Copilot's and doesn't; Chromium
and WebKit, en zh zh-TW ja de, 1000 and 560px, and the editor no wider
than the window.

Run at this head (on origin/main 50aaa5726), on mote through mote-run:
- go test -run Budget ./internal/gui/: ok.
- node --test i18n-keys, agent-failover, agent-switch-accounts,
  claude-setup-token, keep-login, panel-switch-accounts, plugin-move,
  account-rows-fit, accounts-switch-alone: 155 ok, 0 red at f73c2fc8f;
  after 50aaa5726's app.js change, budget ok again and i18n-keys,
  agent-switch-accounts, keep-login, account-rows-fit, accounts-switch-alone
  and codex-subagent-model: 113 ok, 0 red.

Broken by hand: with "+ alone" taken off the hint, accounts-switch-alone is
red 20 of 20 ("Claude's editor doesn't say it needs no connecting").

Not tried: the real app's window; the whole GUI suite (mote at load ~90
with other sessions' suites).
This commit is contained in:
yetone
2026-11-04 22:28:53 +08:00
parent 127f1e77dc
commit 823e7c250b
3 changed files with 81 additions and 8 deletions
+6 -8
View File
@@ -9372,8 +9372,9 @@ function drawEditor(p, presetID) {
if (subOf(a.agent)) {
// no Claude Code on Windows: the gateway runs the one in WSL
if (a.agent === "claude" && !p.switchOnly) ed.append(claudeModeRow());
const via = a.wsl ? t("Runs through WSL · {distro}: Claude Code there signs in and answers; Windows has none of its own.", { distro: a.wsl }) + " " : "";
ed.append(...field(t("Accounts"), renderAccounts(a, p), via + (p.routing ? t("Tick every account to use; Routing says how requests spread over them.") : subOf(a.agent).single ? t("{agent} keeps one account; the gateway runs it for every request. Signing in to another replaces it.", { agent: a.agentName }) : subOf(a.agent).own && (a.logins || []).some((l) => l.own) ? t("The gateway uses the first. Tick more and it moves on to the next when the one before it is out of quota. {agent} itself stays signed in as it is.", { agent: a.agentName && a.agentName !== a.agent ? a.agentName : p.name }) : subOf(a.agent).own || subOf(a.agent).plugin ? t("The gateway uses the first. Tick more and it moves on to the next when the one before it is out of quota.") : t("{agent} signs in to the first. Tick more and magpie moves on to the next when the one before it is out of quota. Sessions already running keep theirs until restarted.", { agent: a.agentName }))));
// switched connected or not (Greatrobbort on X)
const via = a.wsl ? t("Runs through WSL · {distro}: Claude Code there signs in and answers; Windows has none of its own.", { distro: a.wsl }) + " " : "", alone = /^c(laude|odex)$/.test(a.agent) ? " " + t("Just want accounts switched? {agent} needn't be connected to magpie.", { agent: a.agentName }) : "";
ed.append(...field(t("Accounts"), renderAccounts(a, p), via + (p.routing ? t("Tick every account to use; Routing says how requests spread over them.") : subOf(a.agent).single ? t("{agent} keeps one account; the gateway runs it for every request. Signing in to another replaces it.", { agent: a.agentName }) : subOf(a.agent).own && (a.logins || []).some((l) => l.own) ? t("The gateway uses the first. Tick more and it moves on to the next when the one before it is out of quota. {agent} itself stays signed in as it is.", { agent: a.agentName && a.agentName !== a.agent ? a.agentName : p.name }) : subOf(a.agent).own || subOf(a.agent).plugin ? t("The gateway uses the first. Tick more and it moves on to the next when the one before it is out of quota.") : t("{agent} signs in to the first. Tick more and magpie moves on to the next when the one before it is out of quota. Sessions already running keep theirs until restarted.", { agent: a.agentName })) + alone));
if ((a.logins || []).filter((l) => l.active || l.on).length > 1) ed.append(...renderRouting(p));
if (p.move) ed.append(...renderMove(p));
} else {
@@ -13168,8 +13169,7 @@ function renderAccounts(a, p) {
if (amPill) pill(amPill);
// its usage cap: the share of each window it is used to at most
const cap = accountCapOf(p, l.user);
// the agent signed in to it asks its vendor itself: with no other
// account, the cap holds back only magpie's (𝕏 on Discord)
// alone, the cap holds back only magpie's (𝕏 on Discord)
const direct = l.active && !several && (a.agent === "claude" || a.agent === "codex") ? a.agentName : "";
if (p) pill(accountCapPill(p, l.user, cap, direct));
// and each window's own, set on its meter (willz on Discord)
@@ -13213,8 +13213,7 @@ function renderAccounts(a, p) {
if (a.agent === "qoder" || a.agent === "qoder-cn" || l.own) {
line.append(forgetOf(l.own));
} else if (a.agent === "codex" && ls.length === 1) {
// Codex's only account: no other to sign it in to first, so it is
// signed out, as codex logout does (ForgetLogin)
// Codex's only account: signed out, as codex logout does
const out = el("button", "text quiet", t("Sign out"));
out.title = t("Signs Codex out of this account, as codex logout does");
out.onclick = () => askSignOutLogin(a, l);
@@ -13231,8 +13230,7 @@ function renderAccounts(a, p) {
line.append(again);
}
if (kept) {
// the sign-in stays where it is kept: Make first is the order's,
// and an account not in use is ticked on by its dot
// Make first is the order's; the sign-in stays where it is
line.append(forget);
if (l.user === firstUser) line.append(el("span", "using", t("First")));
else if (on) line.append(makeFirst(l));
+4
View File
@@ -4,6 +4,7 @@
// works. {name} slots are filled by t(str, vars).
const I18N = {
zh: {
"Just want accounts switched? {agent} needn't be connected to magpie.": "只想自动切换账号?不需要把 {agent} 接入 magpie。",
"No spend cap": "无消费上限",
"{spent} of {cap} today": "今日 {spent} / {cap}",
"{spent} of {cap} this month": "本月 {spent} / {cap}",
@@ -4604,6 +4605,7 @@ const I18N = {
"This report is no longer kept: magpie keeps the last 5.": "这份报告已经不在了:magpie 只保留最近 5 份。",
},
"zh-TW": {
"Just want accounts switched? {agent} needn't be connected to magpie.": "只想自動切換帳號?不需要把 {agent} 接入 magpie。",
"No spend cap": "無消費上限",
"{spent} of {cap} today": "今日 {spent} / {cap}",
"{spent} of {cap} this month": "本月 {spent} / {cap}",
@@ -9189,6 +9191,7 @@ const I18N = {
"This report is no longer kept: magpie keeps the last 5.": "這份報告已經不在了:magpie 只保留最近 5 份。",
},
ja: {
"Just want accounts switched? {agent} needn't be connected to magpie.": "アカウントを自動で切り替えたいだけなら、{agent} を magpie に接続する必要はありません。",
"No spend cap": "支出上限なし",
"{spent} of {cap} today": "今日 {spent} / {cap}",
"{spent} of {cap} this month": "今月 {spent} / {cap}",
@@ -13776,6 +13779,7 @@ const I18N = {
"This report is no longer kept: magpie keeps the last 5.": "このレポートはもう残っていません。magpie は最新の 5 件だけを保存します。",
},
de: {
"Just want accounts switched? {agent} needn't be connected to magpie.": "Sollen nur die Konten automatisch gewechselt werden? Dafür muss {agent} nicht mit magpie verbunden sein.",
"No spend cap": "Kein Ausgabenlimit",
"{spent} of {cap} today": "Heute {spent} von {cap}",
"{spent} of {cap} this month": "Diesen Monat {spent} von {cap}",
@@ -0,0 +1,71 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Claude Code's and Codex's Accounts say that switching accounts needs no
// connecting the agent (Greatrobbort on X: "多账号这个我一直都没搞明白到底需要
// 在magpie关联agent不"): magpie moves the agent's own sign-in either way. A
// subscription the gateway alone uses, Copilot here, doesn't say it.
// Chromium and WebKit, every language, a wide and a narrow window; no
// backend, the API is faked here.
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 users = ["one@example.com", "two@example.com"];
const sub = (id, name, icon, agentName, routing) => ({
id, name, icon, models: [], agents: [], fallback: [], headers: {}, keyList: [], ...(routing ? { routing } : {}),
account: { agent: id, agentName, user: users[0], plan: "pro", logins: users.map((user, i) => ({ user, plan: "pro", active: i === 0, on: true })) },
});
const providers = [sub("claude", "Claude", "claudecode-color", "Claude Code"), sub("codex", "Codex", "openai", "Codex", "smart"), sub("copilot", "Copilot", "githubcopilot", "Copilot")];
function serve(lang) {
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"dark",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang, theme: "dark" } });
if (url.pathname === "/api/providers") return json({ providers, presets: [], excluded: [], gateway: { running: true, window: true } });
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
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)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
}
const says = {
en: (a) => `${a} needn't be connected to magpie`,
zh: (a) => `不需要把 ${a} 接入 magpie`,
"zh-TW": (a) => `不需要把 ${a} 接入 magpie`,
ja: (a) => `${a} を magpie に接続する必要はありません`,
de: (a) => `Dafür muss ${a} nicht mit magpie verbunden sein`,
};
const engines = process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"];
for (const engine of engines) {
for (const lang of Object.keys(says)) {
for (const width of [1000, 560]) {
test(`${engine} ${lang} ${width}px: Claude Code's and Codex's Accounts say switching needs no connecting`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await browser.newPage({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang));
for (const [name, agent, shown] of [["Claude", "Claude Code", true], ["Codex", "Codex", true], ["Copilot", "Copilot", false]]) {
await page.goto("http://magpie.test/?view=providers");
await page.locator(".row.provider", { hasText: name }).first().click();
await page.locator(".editor .acc").first().waitFor();
const text = await page.locator(".editor").innerText();
assert.equal(text.includes(says[lang](agent)), shown, `${name}'s editor ${shown ? "doesn't say" : "says"} it needs no connecting`);
if (shown) assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false, `${name}'s editor is wider than the window`);
}
assert.deepEqual(errors, []);
});
}
}
}