gui: a hover hint beside the account switch says how it works and why it is the agent's own use

The owner (11-11): "在这个切换开关旁边有一个 hover 的提示,提示这个原理是啥,
以及它为什么不会让你的账号被封禁". Beside Switch {agent}'s account
automatically, an ⓘ mark; resting on the row (or a key reaching the
switch) shows settingshints.js's card with three lines:

- how: the next account's sign-in is written where the agent keeps its
  own, as /login or codex login does; what is left is read by Claude
  Code's own /usage, or where Codex's /status reads it; sessions already
  open keep their account until restarted;
- why it is the agent's own use: Claude Code still sends every request
  itself, straight to Anthropic, unchanged, and magpie sends none (an
  account's own proxy kept); for Codex, only which of your own accounts
  it is signed in to changes;
- the limit: the same as switching by hand; use only your own accounts,
  sharing one is against the vendor's terms. It promises nothing about
  bans: that is the vendor's call.

Only where the switch moves the sign-in. Under the gateway it moves
Claude Code's requests instead, and the "straight to Anthropic" line
would be false, so SignInMovesOf now says `routed` on a kept Claude
whose requests go through the gateway, and the hint shows for `moves`
and for `kept` without it.

The lines and mark are in autoswitchtip.js, imported when the switch is
drawn; app.js gets the one import line, paid for by cutting this branch's
own two comments: the core is 1,533,771, under 1,533,802, no raise.
Strings in zh, zh-TW, ja and de.

Run (xiaomi-gpu, Windows 11, win-run; mote refuses ssh):
- node --test sign-in-moves, keep-login, pool-ends, old-webkit, i18n-keys,
  i18n-en-no-cjk, settings-hints, editor-hints: 148/152. The 4 reds are
  the same at the base 156861b3a: old-webkit's headerpresets.js (#6030)
  and Safari 15.0 :has() (#5919), and settings-hints webkit de at 420px,
  filed as #6073.
- the new test (Chromium and WebKit, en and zh): the mark sits beside
  the switch on its line, the lines rest out of sight, hovering shows the
  card with the three lines beside the row, a press on the mark posts
  nothing; no mark for kept+routed or gateway.
- Broken by hand, each red: the mark's preventDefault removed (a press
  turned the switch off); the routed check dropped (kept+routed showed
  it); Routed not set in SignInMovesOf (TestSignInMovesSaysWhatSwitchDoes).
- go test -run "SignInMoves|ClaudeRoutedSignIn|KeepLogin|SwitchOnly"
  ./internal/provider ok; go vet ./internal/provider ok;
  TestCoreScriptBudget ok; gofmt -l clean.
- A Chromium screenshot of the card in zh looked at.

Not tried: the Codex variant's card in a browser (its strings pass
i18n-keys); the real app; macOS and Linux.
This commit is contained in:
yetone
2026-11-11 13:05:16 +08:00
parent e31625f641
commit 4ddc150c66
10 changed files with 141 additions and 11 deletions
File diff suppressed because one or more lines are too long
+12
View File
@@ -2867,6 +2867,18 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
.editor .accts .auto-switch .as-head { display: flex; text-align: left; padding-top: 0; align-items: center; gap: 8px; min-height: 18px; cursor: pointer; }
.editor .accts .auto-switch .as-name { flex: 1; min-width: 0; }
.editor .accts .auto-switch .as-head .lib-switch { flex: none; }
/* how the switch works (autoswitchtip.js): its lines rest out of sight and
settingshints.js shows them in its card; the mark says one is there. A
touch screen, with no hover, keeps the lines in place and no mark */
.editor .accts .auto-switch .as-head .as-tip { display: none; flex: none; color: var(--muted); }
.editor .accts .auto-switch > .hint { margin: 0; line-height: 1.5; color: var(--fg-2); }
@media (hover: hover) {
.editor .accts .auto-switch .as-head .as-tip { display: inline-flex; }
.editor .accts .auto-switch.hint-row { position: relative; }
.editor .accts .auto-switch.hint-row > .hint {
--hint: 1; position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
}
.editor .accts .auto-switch .sign-in-moves { line-height: 1.5; color: var(--fg-2); }
.editor .accts .auto-switch .as-keep { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; color: var(--fg-2); }
.editor .accts .auto-switch .keep-as { max-width: 240px; }
+3 -2
View File
@@ -12215,7 +12215,7 @@ function routingOfDraft(p) {
if (draft?.sink !== undefined && draft.sink !== !!p.sink) out.sink = draft.sink;
return out;
}
// signInMovesLine: how magpie moves the agent's own sign-in (provider.SignInMovesOf)
// how magpie moves the agent's sign-in (provider.SignInMovesOf)
function signInMovesLine(p, agent) {
const m = p.signInMoves;
if (!m) return "";
@@ -13556,7 +13556,7 @@ function renderAccounts(a, p) {
if (amBox) row.append(amBox);
list.append(row);
}
// moving the agent's sign-in is a switch (the owner, 11-11); off: the account it stays on (#524)
// the owner, 11-11; off: the account kept (#524)
if ((a.agent === "codex" || a.agent === "claude") && several && p) {
const box = el("div", "auto-switch"), on = !!p.switchOnly || !p.keepLogin;
const head = el("label", "as-head");
@@ -13568,6 +13568,7 @@ function renderAccounts(a, p) {
}
head.append(name, sw);
box.append(head);
import("./autoswitchtip.js").then(() => autoSwitchTip(box, head, p), () => {});
let keepAs = kept;
const post = (keepLogin) => {
const body = { id: p.id, keepLogin };
+32
View File
@@ -0,0 +1,32 @@
// The hover hint beside Switch {agent}'s account automatically (the owner,
// 11-11): how magpie switches the agent's account, and why that is the
// agent's own use of the account. It says what is sent and by whom, and
// promises nothing about bans: what an account may be used for is the
// vendor's call. Its lines rest out of sight in the accounts list, and
// settingshints.js shows them in its card. Only where the switch moves the
// sign-in: under the gateway it moves Claude Code's requests instead.
// app.js imports this when it draws the switch, so the core doesn't
// carry it.
// autoSwitchTip puts the hint's lines in box and its mark after the
// switch's name in head, for p's agent (Codex or Claude Code)
window.autoSwitchTip = function (box, head, p) {
const m = p.signInMoves;
if (!m || !(m.mode === "moves" || m.mode === "kept" && !m.routed) || box.querySelector(":scope > .hint")) return;
const codex = p.account?.agent === "codex";
const lines = codex
? [t("magpie writes the next account's sign-in to Codex's own auth.json, as codex login does, and reads what is left where Codex's /status reads it. Sessions already open keep their account until they are restarted."),
t("It changes which of your own accounts Codex is signed in to, and nothing else: the requests are the ones Codex makes."),
t("So it is the same as switching accounts by hand. Use only accounts that are yours: sharing one is against OpenAI's terms.")]
: [t("magpie writes the next account's sign-in where Claude Code keeps its own, as /login does, and reads what is left by running Claude Code's own /usage. Sessions already open keep their account until they are restarted."),
t("Claude Code itself still sends every request, straight to Anthropic and unchanged; magpie sends none of them. An account with its own proxy keeps it."),
t("So it is the same as switching accounts by hand. Use only accounts that are yours: sharing one is against Anthropic's terms.")];
box.classList.add("hint-row");
box.append(...lines.map((s) => el("p", "hint", s)));
const mark = el("span", "as-tip");
mark.setAttribute("aria-hidden", "true"); // a screen reader reads the lines
mark.append(svg(INFO_I, 13, 1.6));
// a press on it is not one on the switch's label
mark.onclick = (e) => e.preventDefault();
head.querySelector(".as-name")?.after(mark);
};
+24
View File
@@ -2062,6 +2062,12 @@ const I18N = {
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and back to the first once that has room again.": "经 magpie 的请求由路由挑选账号;{agent} 直连时用它登录的账号,该账号用到 98% 时,magpie 把 {agent} 登录到下一个已勾选且有余量的账号,首选账号恢复后切回。",
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and keeps it there till that one is 98% used too.": "经 magpie 的请求由路由挑选账号;{agent} 直连时用它登录的账号,该账号用到 98% 时,magpie 把 {agent} 登录到下一个已勾选且有余量的账号,并一直用它,直到它也用到 98%。",
"Switch {agent}'s account automatically": "自动切换 {agent} 的账号",
"magpie writes the next account's sign-in to Codex's own auth.json, as codex login does, and reads what is left where Codex's /status reads it. Sessions already open keep their account until they are restarted.": "magpie 把下一个账号的登录写进 Codex 自己的 auth.json,和 codex login 一样;剩余额度从 Codex 的 /status 读取的同一处读取。已经打开的会话继续用原来的账号,直到重新启动。",
"It changes which of your own accounts Codex is signed in to, and nothing else: the requests are the ones Codex makes.": "它只改变 Codex 登录的是你自己的哪一个账号,别的都不动:请求仍是 Codex 自己发出的那些。",
"So it is the same as switching accounts by hand. Use only accounts that are yours: sharing one is against OpenAI's terms.": "所以这和你手动切换账号是一样的。请只用你自己的账号:共享账号违反 OpenAI 的条款。",
"magpie writes the next account's sign-in where Claude Code keeps its own, as /login does, and reads what is left by running Claude Code's own /usage. Sessions already open keep their account until they are restarted.": "magpie 把下一个账号的登录写到 Claude Code 自己保存登录的地方,和 /login 一样;剩余额度通过运行 Claude Code 自己的 /usage 读取。已经打开的会话继续用原来的账号,直到重新启动。",
"Claude Code itself still sends every request, straight to Anthropic and unchanged; magpie sends none of them. An account with its own proxy keeps it.": "每个请求仍由 Claude Code 本身发出,直接发往 Anthropic,原样不改;magpie 一个都不发。设了自己代理的账号继续走它的代理。",
"So it is the same as switching accounts by hand. Use only accounts that are yours: sharing one is against Anthropic's terms.": "所以这和你手动切换账号是一样的。请只用你自己的账号:共享账号违反 Anthropic 的条款。",
"Always on while magpie only switches {agent}'s sign-in": "{agent} 只切换登录时始终开启",
"{agent}'s requests go through magpie, which sends each one to an account with room; its own sign-in stays where you put it.": "{agent} 的请求经过 magpie,每个请求都发给有额度的账号;{agent} 自己的登录保持你选的账号不变。",
"When the account {agent} is signed in to is used up, magpie signs it in to the next ticked account with room.": "{agent} 登录的账号用完时,magpie 把它登录到下一个已勾选且有额度的账号。",
@@ -7084,6 +7090,12 @@ const I18N = {
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and back to the first once that has room again.": "經 magpie 的請求由路由挑選帳號;{agent} 直連時用它登入的帳號,該帳號用到 98% 時,magpie 把 {agent} 登入到下一個已勾選且有餘量的帳號,首選帳號恢復後切回。",
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and keeps it there till that one is 98% used too.": "經 magpie 的請求由路由挑選帳號;{agent} 直連時用它登入的帳號,該帳號用到 98% 時,magpie 把 {agent} 登入到下一個已勾選且有餘量的帳號,並一直用它,直到它也用到 98%。",
"Switch {agent}'s account automatically": "自動切換 {agent} 的帳號",
"magpie writes the next account's sign-in to Codex's own auth.json, as codex login does, and reads what is left where Codex's /status reads it. Sessions already open keep their account until they are restarted.": "magpie 把下一個帳號的登入寫進 Codex 自己的 auth.json,和 codex login 一樣;剩餘額度從 Codex 的 /status 讀取的同一處讀取。已經開啟的工作階段繼續用原來的帳號,直到重新啟動。",
"It changes which of your own accounts Codex is signed in to, and nothing else: the requests are the ones Codex makes.": "它只改變 Codex 登入的是你自己的哪一個帳號,其他都不動:請求仍是 Codex 自己發出的那些。",
"So it is the same as switching accounts by hand. Use only accounts that are yours: sharing one is against OpenAI's terms.": "所以這和你手動切換帳號是一樣的。請只用你自己的帳號:共用帳號違反 OpenAI 的條款。",
"magpie writes the next account's sign-in where Claude Code keeps its own, as /login does, and reads what is left by running Claude Code's own /usage. Sessions already open keep their account until they are restarted.": "magpie 把下一個帳號的登入寫到 Claude Code 自己保存登入的地方,和 /login 一樣;剩餘額度透過執行 Claude Code 自己的 /usage 讀取。已經開啟的工作階段繼續用原來的帳號,直到重新啟動。",
"Claude Code itself still sends every request, straight to Anthropic and unchanged; magpie sends none of them. An account with its own proxy keeps it.": "每個請求仍由 Claude Code 本身發出,直接送往 Anthropic,原封不動;magpie 一個都不送。設了自己代理的帳號繼續走它的代理。",
"So it is the same as switching accounts by hand. Use only accounts that are yours: sharing one is against Anthropic's terms.": "所以這和你手動切換帳號是一樣的。請只用你自己的帳號:共用帳號違反 Anthropic 的條款。",
"Always on while magpie only switches {agent}'s sign-in": "{agent} 只切換登入時始終開啟",
"{agent}'s requests go through magpie, which sends each one to an account with room; its own sign-in stays where you put it.": "{agent} 的請求經過 magpie,每個請求都發給有額度的帳號;{agent} 自己的登入保持你選的帳號不變。",
"When the account {agent} is signed in to is used up, magpie signs it in to the next ticked account with room.": "{agent} 登入的帳號用完時,magpie 把它登入到下一個已勾選且有額度的帳號。",
@@ -12082,6 +12094,12 @@ const I18N = {
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and back to the first once that has room again.": "magpie 経由のリクエストはルーティングがアカウントを選びます。{agent} 単体ではサインイン中のアカウントを使い、そのアカウントが 98% 使用されると magpie が残量のある次のチェック済みアカウントに切り替え、最初のアカウントに残量が戻ると元に戻します。",
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and keeps it there till that one is 98% used too.": "magpie 経由のリクエストはルーティングがアカウントを選びます。{agent} 単体ではサインイン中のアカウントを使い、そのアカウントが 98% 使用されると magpie が残量のある次のチェック済みアカウントに切り替え、そのアカウントも 98% 使用されるまでそのまま使います。",
"Switch {agent}'s account automatically": "{agent} のアカウントを自動で切り替える",
"magpie writes the next account's sign-in to Codex's own auth.json, as codex login does, and reads what is left where Codex's /status reads it. Sessions already open keep their account until they are restarted.": "magpie は次のアカウントのサインインを Codex 自身の auth.json に書き込みます(codex login と同じです)。残りは Codex の /status が読むのと同じところから読みます。開いているセッションは再起動するまで元のアカウントのままです。",
"It changes which of your own accounts Codex is signed in to, and nothing else: the requests are the ones Codex makes.": "変わるのは Codex がサインインしている自分のアカウントだけで、ほかは何も変えません。リクエストは Codex 自身が送るものです。",
"So it is the same as switching accounts by hand. Use only accounts that are yours: sharing one is against OpenAI's terms.": "つまり手でアカウントを切り替えるのと同じです。自分のアカウントだけを使ってください。アカウントの共有は OpenAI の規約に反します。",
"magpie writes the next account's sign-in where Claude Code keeps its own, as /login does, and reads what is left by running Claude Code's own /usage. Sessions already open keep their account until they are restarted.": "magpie は次のアカウントのサインインを Claude Code が自分のサインインを保存する場所に書き込みます(/login と同じです)。残りは Claude Code 自身の /usage を実行して読みます。開いているセッションは再起動するまで元のアカウントのままです。",
"Claude Code itself still sends every request, straight to Anthropic and unchanged; magpie sends none of them. An account with its own proxy keeps it.": "リクエストはすべて Claude Code 自身が Anthropic へ直接、そのまま送ります。magpie は一つも送りません。独自のプロキシを持つアカウントはそのプロキシを使い続けます。",
"So it is the same as switching accounts by hand. Use only accounts that are yours: sharing one is against Anthropic's terms.": "つまり手でアカウントを切り替えるのと同じです。自分のアカウントだけを使ってください。アカウントの共有は Anthropic の規約に反します。",
"Always on while magpie only switches {agent}'s sign-in": "{agent} のサインインだけを切り替えるときは常にオン",
"{agent}'s requests go through magpie, which sends each one to an account with room; its own sign-in stays where you put it.": "{agent} のリクエストは magpie を経由し、各リクエストは残量のあるアカウントに送られます。{agent} 自身のサインインは選んだアカウントのままです。",
"When the account {agent} is signed in to is used up, magpie signs it in to the next ticked account with room.": "{agent} がサインインしているアカウントを使い切ると、magpie は残量のある次のチェック済みアカウントにサインインし直します。",
@@ -17111,6 +17129,12 @@ const I18N = {
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and back to the first once that has room again.": "Die Weiterleitung wählt für jede Anfrage über magpie das Konto; {agent} selbst nutzt das Konto, bei dem es angemeldet ist; magpie meldet es beim nächsten angehakten Konto mit freiem Kontingent an, sobald das aktuelle zu 98 % verbraucht ist, und wieder beim ersten, sobald dort wieder Kontingent frei ist.",
"Routing picks the account for each request through magpie; {agent} on its own uses the one it is signed in to, which magpie moves to the next ticked account with room once it is 98% used, and keeps it there till that one is 98% used too.": "Die Weiterleitung wählt für jede Anfrage über magpie das Konto; {agent} selbst nutzt das Konto, bei dem es angemeldet ist; magpie meldet es beim nächsten angehakten Konto mit freiem Kontingent an, sobald das aktuelle zu 98 % verbraucht ist, und bleibt dort, bis auch dieses zu 98 % verbraucht ist.",
"Switch {agent}'s account automatically": "{agent}-Konto automatisch wechseln",
"magpie writes the next account's sign-in to Codex's own auth.json, as codex login does, and reads what is left where Codex's /status reads it. Sessions already open keep their account until they are restarted.": "magpie schreibt die Anmeldung des nächsten Kontos in Codex' eigene auth.json, wie codex login es tut, und liest das Verbleibende dort, wo Codex' /status es liest. Bereits offene Sitzungen behalten ihr Konto, bis sie neu gestartet werden.",
"It changes which of your own accounts Codex is signed in to, and nothing else: the requests are the ones Codex makes.": "Es ändert nur, bei welchem deiner eigenen Konten Codex angemeldet ist, sonst nichts: Die Anfragen sind die, die Codex stellt.",
"So it is the same as switching accounts by hand. Use only accounts that are yours: sharing one is against OpenAI's terms.": "Es ist also dasselbe wie ein Kontowechsel von Hand. Nutze nur Konten, die dir gehören: Ein Konto zu teilen verstößt gegen die Bedingungen von OpenAI.",
"magpie writes the next account's sign-in where Claude Code keeps its own, as /login does, and reads what is left by running Claude Code's own /usage. Sessions already open keep their account until they are restarted.": "magpie schreibt die Anmeldung des nächsten Kontos dorthin, wo Claude Code seine eigene speichert, wie /login es tut, und liest das Verbleibende, indem es Claude Codes eigenes /usage ausführt. Bereits offene Sitzungen behalten ihr Konto, bis sie neu gestartet werden.",
"Claude Code itself still sends every request, straight to Anthropic and unchanged; magpie sends none of them. An account with its own proxy keeps it.": "Claude Code selbst sendet weiterhin jede Anfrage, direkt und unverändert an Anthropic; magpie sendet keine davon. Ein Konto mit eigenem Proxy behält ihn.",
"So it is the same as switching accounts by hand. Use only accounts that are yours: sharing one is against Anthropic's terms.": "Es ist also dasselbe wie ein Kontowechsel von Hand. Nutze nur Konten, die dir gehören: Ein Konto zu teilen verstößt gegen die Bedingungen von Anthropic.",
"Always on while magpie only switches {agent}'s sign-in": "Immer an, solange magpie nur die Anmeldung von {agent} wechselt",
"{agent}'s requests go through magpie, which sends each one to an account with room; its own sign-in stays where you put it.": "Die Anfragen von {agent} laufen über magpie, das jede an ein Konto mit Kontingent schickt; die eigene Anmeldung von {agent} bleibt, wo du sie gesetzt hast.",
"When the account {agent} is signed in to is used up, magpie signs it in to the next ticked account with room.": "Ist das Konto, bei dem {agent} angemeldet ist, aufgebraucht, meldet magpie es beim nächsten angehakten Konto mit Kontingent an.",
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -172,9 +172,10 @@ test("compat.js is the first of the page's own scripts", async () => {
// pluginmd.js (a README's renderer) once plugins.js has run;
// plugincounts.js (Discover's counts) when the Plugins page loads;
// navicons.js (the sidebar lists' marks) with the first list drawn;
// autoswitchtip.js when a provider's accounts draw their switch;
// the checks above
// still read them
for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quitask.js", "checkinnow.js", "proxies.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "balfound.js", "passerrors.js", "keybalance.js", "modellimits.js", "notices.js", "videogen.js", "provlinks.js", "setfeats.js", "pageshare.js", "panelfirst.js", "panelarrange.js", "modelfind.js", "agentsmanager.js", "agentsuffix.js", "phonetabs.js", "pluginmd.js", "bark.js", "acctexport.js", "plugincounts.js", "navicons.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
for (const f of await scripts()) if (!["webfonts.js", "cfgblocked.js", "signsheets.js", "ruleedit.js", "ratewindows.js", "traywindows.js", "autoresetown.js", "registry.js", "navlamp.js", "whatsnew.js", "claudemode.js", "ctxtext.js", "resetask.js", "quotaall.js", "quitask.js", "checkinnow.js", "proxies.js", "autobackup.js", "scrollends.js", "profilerename.js", "settingshints.js", "keyspend.js", "syncfiles.js", "agentcompact.js", "balfound.js", "passerrors.js", "keybalance.js", "modellimits.js", "notices.js", "videogen.js", "provlinks.js", "setfeats.js", "pageshare.js", "panelfirst.js", "panelarrange.js", "modelfind.js", "agentsmanager.js", "agentsuffix.js", "phonetabs.js", "pluginmd.js", "bark.js", "acctexport.js", "plugincounts.js", "navicons.js", "autoswitchtip.js"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
});
test("the styles hold up in Safari 15.0", async () => {
+56 -1
View File
@@ -6,7 +6,10 @@
// the server tells it (signInMoves): moved on at 98% or once used up, back
// to the first or not, or left alone while its requests go through the
// gateway. Off, the account it stays on. Switch-only holds it on. Nothing
// with one account. English and Chinese, Chromium and WebKit.
// with one account. Beside the switch, a mark whose hover card says how
// the switch works and why it is Claude Code's own use of the account
// ("提示这个原理是啥,以及它为什么不会让你的账号被封禁"), only where the
// sign-in moves. English and Chinese, Chromium and WebKit.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
@@ -64,6 +67,11 @@ const words = {
name: "Switch Claude Code's account automatically",
keep: "Keep Claude Code signed in to",
gateway: "Claude Code's requests go through magpie, which sends each one to an account with room; its own sign-in stays where you put it.",
tip: [
"magpie writes the next account's sign-in where Claude Code keeps its own, as /login does, and reads what is left by running Claude Code's own /usage. Sessions already open keep their account until they are restarted.",
"Claude Code itself still sends every request, straight to Anthropic and unchanged; magpie sends none of them. An account with its own proxy keeps it.",
"So it is the same as switching accounts by hand. Use only accounts that are yours: sharing one is against Anthropic's terms.",
],
},
zh: {
at98: "Claude Code 登录的账号用到 98% 时,magpie 把它登录到下一个已勾选且有额度的账号。之后一直用这个账号,直到它的额度也快用完。",
@@ -71,6 +79,11 @@ const words = {
name: "自动切换 Claude Code 的账号",
keep: "Claude Code 始终登录",
gateway: "Claude Code 的请求经过 magpie,每个请求都发给有额度的账号;Claude Code 自己的登录保持你选的账号不变。",
tip: [
"magpie 把下一个账号的登录写到 Claude Code 自己保存登录的地方,和 /login 一样;剩余额度通过运行 Claude Code 自己的 /usage 读取。已经打开的会话继续用原来的账号,直到重新启动。",
"每个请求仍由 Claude Code 本身发出,直接发往 Anthropic,原样不改;magpie 一个都不发。设了自己代理的账号继续走它的代理。",
"所以这和你手动切换账号是一样的。请只用你自己的账号:共享账号违反 Anthropic 的条款。",
],
},
};
@@ -146,6 +159,48 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(errors, []);
});
test(`${engine} ${lang}: the mark beside the switch shows how it works on hover, and only where the sign-in moves`, async (t) => {
for (const [opts, shown] of [
[{}, true],
[{ signInMoves: { mode: "kept" }, keepLogin: true }, true],
[{ signInMoves: { mode: "kept", routed: true }, keepLogin: true }, false],
[{ signInMoves: { mode: "gateway" } }, false],
]) {
const { page, errors, posts } = await open(t, opts);
const mark = page.locator(".editor .accts .auto-switch .as-head .as-tip");
if (!shown) {
// the module is in by the time a shown one's mark is drawn
await page.waitForFunction(() => !!window.autoSwitchTip);
assert.equal(await mark.count(), 0, JSON.stringify(opts));
assert.equal(await page.locator(".editor .accts .auto-switch > .hint").count(), 0);
assert.deepEqual(errors, []);
await page.close();
continue;
}
await mark.waitFor();
// beside the switch, on its line
const [m, s] = await Promise.all([mark.boundingBox(), sw(page).boundingBox()]);
assert.ok(s.x - (m.x + m.width) >= 0 && s.x - (m.x + m.width) < 16, `the mark sits beside the switch: ${JSON.stringify([m, s])}`);
assert.ok(Math.abs(m.y + m.height / 2 - (s.y + s.height / 2)) < 3, "on the switch's line");
// its lines rest out of sight, read by a screen reader
const lines = page.locator(".editor .accts .auto-switch > .hint");
assert.deepEqual((await lines.allTextContents()).map((x) => x.trim()), w.tip);
assert.ok((await lines.first().boundingBox()).width <= 1, "out of sight till asked");
await mark.hover();
const card = page.locator(".set-hint.on");
await card.waitFor();
assert.deepEqual((await card.locator("p").allTextContents()).map((x) => x.trim()), w.tip);
const c = await card.boundingBox(), box = await page.locator(".editor .accts .auto-switch").boundingBox();
assert.ok(c.y >= box.y + box.height - 1 || c.y + c.height <= box.y + 1, "the card is beside the row, not over it");
// a press on the mark is no press on the switch
await mark.click();
assert.deepEqual(posts, []);
assert.equal(await sw(page).getAttribute("aria-checked"), opts.keepLogin ? "false" : "true");
assert.deepEqual(errors, []);
await page.close();
}
});
test(`${engine} ${lang}: switch-only holds it on; nothing with one account, no line when off in magpie`, async (t) => {
const only = await open(t, { switchOnly: true, keepLogin: true });
assert.equal(await sw(only.page).getAttribute("aria-checked"), "true");
+7 -2
View File
@@ -20,6 +20,10 @@ type SignInMoves struct {
// Back: once the account moved off has room again, the agent is
// signed back in to it (returnsToFirst). Only "moves".
Back bool `json:"back,omitempty"`
// Routed: kept, but Claude Code goes through the gateway, so turning
// the switch on moves requests, not its sign-in (mode "gateway"
// then). Only "kept".
Routed bool `json:"routed,omitempty"`
}
// SignInMovesOf is SignInMoves for agent; nil for one whose sign-in magpie
@@ -32,10 +36,11 @@ func SignInMovesOf(agent string) *SignInMoves {
return &SignInMoves{Mode: "off"}
}
share, keep := loginSwitching(agent)
routed := agent == "claude" && ClaudeThroughMagpie() && !SwitchOnly(agent)
switch {
case keep:
return &SignInMoves{Mode: "kept"}
case agent == "claude" && ClaudeThroughMagpie() && !SwitchOnly(agent):
return &SignInMoves{Mode: "kept", Routed: routed}
case routed:
return &SignInMoves{Mode: "gateway"}
}
return &SignInMoves{Mode: "moves", Share: share, Back: returnsToFirst(agent)}
+3 -3
View File
@@ -77,14 +77,14 @@ func TestSignInMovesSaysWhatSwitchDoes(t *testing.T) {
routing string
mode string
share float64
back bool
back, kRouted bool
}{
{name: "not routed", mode: "moves", share: SpentShare},
{name: "not routed, in order", routing: Ordered, mode: "moves", share: 100, back: true},
{name: "routed", routed: true, mode: "gateway"},
{name: "routed, switch only", routed: true, only: true, mode: "moves", share: SpentShare},
{name: "kept on the first", keep: true, mode: "kept"},
{name: "kept, routed", keep: true, routed: true, mode: "kept"},
{name: "kept, routed", keep: true, routed: true, mode: "kept", kRouted: true},
}
for _, c := range cases {
routed = c.routed
@@ -102,7 +102,7 @@ func TestSignInMovesSaysWhatSwitchDoes(t *testing.T) {
}
setLoginReturn("claude", loginReturn{})
m := SignInMovesOf("claude")
if m == nil || m.Mode != c.mode || m.Share != c.share || m.Back != c.back {
if m == nil || m.Mode != c.mode || m.Share != c.share || m.Back != c.back || m.Routed != c.kRouted {
t.Fatalf("%s: says %+v, want mode %s share %g back %v", c.name, m, c.mode, c.share, c.back)
}
to := switched()