providers: a Claude subscription says whether it runs as Claude Code's interactive mode or claude -p, and why
The owner: the Claude Code provider page should say whether its runs go through the TUI or the CLI, and what tells them apart and what each gains. Under a Claude subscription's accounts a row now says "Running as Claude Code's interactive mode (TUI)" (a green dot) or "Running as claude -p (CLI)" with why: turned off in Settings, failed to start lately, Claude Code in WSL whose home wasn't found, not installed, or a system with no interactive mode. Under the TUI it says which requests still run as -p (safeguards, a JSON schema, an image by URL, a first message over 400KB). "TUI or -p?" opens what each is: entrypoint cli, the plan counting a request at about half; entrypoint sdk-cli, about twice. "Change in Settings" opens Settings › Models at the interactive mode's row. Only switch, which serves nothing, shows no row. The mode comes from GET /api/claude/mode (gateway.ClaudeModeNow), read as the editor opens and kept 30s, never in /api/providers' polls. Its machine-wide reasons are claudeMachineWhy, which claudePrintWhy now calls first, so the row and the gateway's own choice can't disagree. The row is drawn by claudemode.js, which app.js loads with that first read, so it weighs nothing on the core: after a rebase on origin/main29d0ab39fthe core was 1,541,482 bytes, over its 1,539,856, and the budget isn't raised. "Runs as" became "Running as" so its keys don't clash with a plugin's "Runs as" in i18n-keys. A per-account WSL folder the probe can't read is still found only at run time; the doc says so. Run: - go vet ./internal/gateway ./internal/gui (darwin), GOOS=windows, and GOOS=linux -tags nogui: 0. - go test -run 'ClaudeTUI|ClaudeMachine|ClaudeSub' ./internal/gateway: ok (TestClaudeMachineWhy is new). - After the rebase on29d0ab39f, on mote: go test -run 'CoreScriptBudget|I18n|Claude' ./internal/gui ok, the budget not raised; old-webkit.test.cjs lists claudemode.js with the other scripts app.js imports. Before the rebase, go test ./internal/gui: three reds that fail the same on origin/mainccc791231: TestSettingsSaveKeepsWhatItDoesNotSend (#4514), TestMainWindowCorners (#3949), and i18n-keys' "Unmarked" (#4524). - claude-mode.test.cjs in WSL (Chromium and WebKit, 1100 and 420, en, zh, ja, de): 48 of 48. - The full GUI suite on mote (load ~30) had 301 reds in 49 files; each of those files was run again in WSL at this head (743 tests, 259 red) and at origin/mainccc791231(259 red, the same tests; #4600). The one that held apart was account-weight at de web 390: the row puts the accounts a screen above By weight on a phone, and Playwright's click scrolled the chip back into view. The test now brings the chip into view before it measures, so it judges the click's own scrolling; account-weight and claude-mode, both engines: 50 of 50. - After moving the row into claudemode.js: the 142 GUI files with a Claude Code agent, in WSL (Chromium and WebKit): 1392 tests, 8 WebKit reds in 7 files. Each of those files was run again alone at this head and at29d0ab39f: the same kind of WebKit reds on both, which subtests changing from run to run (library-items, number-units, routing-rule-models, usage-heatmap, usage-ledger-chart). phone-rows' Routing click on .rt-day failed 1 of 4 runs at each (WebKit zh, ja, de); the Routing page draws no such row. Filed under #4600, #4471, #4112. - Real use on xiaomi-gpu (Windows 11, sandbox HOME, Claude Code in WSL magpie-desktop): /api/claude/mode said {"tui":true,"wsl":true}; with the setting turned off through POST /api/settings, {"tui":false,"why":"off","wsl":true}; set back, TUI again. - Rebased on origin/main02ff0e908(no file in common): on mote, vet for darwin, windows and linux nogui 0; go test ./internal/claudetui ok; -run 'CoreScriptBudget|I18n|Claude|Budget' ./internal/gui ok; -run Claude ./internal/gateway ok. In WSL claude-mode, account-weight, old-webkit and i18n-keys: 59 of 60, the one red i18n-keys' "Unmarked" (#4524). Broken by hand: the editor draws twice before the read returns, and the test's one-read check went red with two reads until the read in flight was shared (claudeModeRead). account-weight's check went red ("en 1000: a click scrolled") with the chip's click made to scroll the editor 120px. Not tried: the window on macOS with a real account (the row is the same code as the web GUI's), and the "broken" reason with a real failed start.
This commit is contained in:
@@ -200,6 +200,20 @@ The gateway's log says which (`claude: this run is -p: …`,
|
||||
`claudePrintWhy`), and the helper's own line when it becomes `-p` (below)
|
||||
is logged from the run's stderr (`lockedWriter`).
|
||||
|
||||
The Claude Code provider page says under its accounts whether runs are
|
||||
the interactive mode (TUI) or `-p` (CLI), with why when every run is
|
||||
`-p`, and opens what tells the two apart (`claudeModeRow` in app.js, drawn by
|
||||
claudemode.js, which it loads with its first read).
|
||||
It reads `GET /api/claude/mode` (`gateway.ClaudeModeNow`) as the page
|
||||
opens, kept 30 seconds and dropped when the setting changes, not in
|
||||
`/api/providers`' polls. What decides it for every run on the machine is
|
||||
`claudeMachineWhy`, whose codes the page words: `off` (the setting),
|
||||
`broken` (failed to start lately), `wsl-home`, `missing` (no Claude Code
|
||||
found), `os` and `no-shim`. What only a request decides (safeguards and
|
||||
the rest above) the page names as still `-p`; the WSL folder Windows
|
||||
can't read is per account, so the page doesn't know it. A subscription
|
||||
with Only switch serves nothing through magpie and shows no row.
|
||||
|
||||
A turn the interactive mode can't take ends the run, and the next starts
|
||||
anew: a turn with an image known by its URL, one that takes earlier turns
|
||||
back, an effort change. A run given up on (`letGo`) is not taken back, since the
|
||||
|
||||
@@ -1087,20 +1087,17 @@ func claudePrintWhy(req *Request, binary claudeCLI, prompt []map[string]any) str
|
||||
}
|
||||
}
|
||||
b, _ := json.Marshal(words)
|
||||
if _, why := claudeMachineWhy(binary); why != "" {
|
||||
return why
|
||||
}
|
||||
for _, c := range []struct {
|
||||
is bool
|
||||
why string
|
||||
}{
|
||||
{!claudeTUIRuns, "no shim"},
|
||||
{runtime.GOOS != "darwin" && runtime.GOOS != "linux" && runtime.GOOS != "windows", runtime.GOOS},
|
||||
{binary.wsl != nil && binary.wsl.Home == "", "Claude Code in WSL, its home unknown"},
|
||||
{binary.wsl == nil && binary.path == "", "no Claude Code path"},
|
||||
{len(req.Safeguards) > 0, "safeguards"},
|
||||
{req.clientCache != nil, "the client's cache marks"},
|
||||
{len(req.Format.schema()) > 0, "a JSON schema"},
|
||||
{urlImages(req.Messages) > 0, "an image known by its URL"},
|
||||
{settings.Load().ClaudePrintMode, "the interactive mode is turned off"},
|
||||
{tuiBroken(), "the interactive mode failed to start lately"},
|
||||
{len(b) > tuiPromptMost, "a first message over 400KB"},
|
||||
} {
|
||||
if c.is {
|
||||
@@ -1110,6 +1107,54 @@ func claudePrintWhy(req *Request, binary claudeCLI, prompt []map[string]any) str
|
||||
return ""
|
||||
}
|
||||
|
||||
// claudeMachineWhy is why every run on this machine is -p, whatever it
|
||||
// asks: a code for the provider page (ClaudeModeNow) and the log's words,
|
||||
// "" "" when runs can be the interactive mode.
|
||||
func claudeMachineWhy(binary claudeCLI) (code, why string) {
|
||||
for _, c := range []struct {
|
||||
is bool
|
||||
code, why string
|
||||
}{
|
||||
{!claudeTUIRuns, "no-shim", "no shim"},
|
||||
{runtime.GOOS != "darwin" && runtime.GOOS != "linux" && runtime.GOOS != "windows", "os", runtime.GOOS},
|
||||
{binary.wsl != nil && binary.wsl.Home == "", "wsl-home", "Claude Code in WSL, its home unknown"},
|
||||
{binary.wsl == nil && binary.path == "", "missing", "no Claude Code path"},
|
||||
{settings.Load().ClaudePrintMode, "off", "the interactive mode is turned off"},
|
||||
{tuiBroken(), "broken", "the interactive mode failed to start lately"},
|
||||
} {
|
||||
if c.is {
|
||||
return c.code, c.why
|
||||
}
|
||||
}
|
||||
return "", ""
|
||||
}
|
||||
|
||||
// ClaudeMode is how a Claude subscription's runs are made on this
|
||||
// machine, for the Claude Code provider page: TUI when Claude Code's
|
||||
// interactive mode, else -p, Why the code of claudeMachineWhy. A run can
|
||||
// still be -p for what only it asks (safeguards, a client's cache marks,
|
||||
// a JSON schema, an image known by its URL, a first message over 400KB).
|
||||
type ClaudeMode struct {
|
||||
TUI bool `json:"tui"`
|
||||
Why string `json:"why,omitempty"`
|
||||
Broken time.Time `json:"broken,omitzero"` // since when, for "broken"
|
||||
WSL bool `json:"wsl,omitempty"` // Claude Code in WSL
|
||||
}
|
||||
|
||||
// ClaudeModeNow is ClaudeMode as of now.
|
||||
func ClaudeModeNow() ClaudeMode {
|
||||
binary, err := claudeBinary()
|
||||
if err != nil {
|
||||
return ClaudeMode{Why: "missing"}
|
||||
}
|
||||
code, _ := claudeMachineWhy(binary)
|
||||
m := ClaudeMode{TUI: code == "", Why: code, WSL: binary.wsl != nil}
|
||||
if code == "broken" {
|
||||
m.Broken, _ = claudetui.BrokenSince()
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// safeguardBody is the safety-only form of the run's extra body.
|
||||
func safeguardBody(raw json.RawMessage) string {
|
||||
return claudeExtraBody(raw, "")
|
||||
|
||||
@@ -135,3 +135,41 @@ func TestClaudeTUIWSLUnread(t *testing.T) {
|
||||
t.Fatalf("the account's folder: %q, asked %q", got, asked)
|
||||
}
|
||||
}
|
||||
|
||||
// The provider page's codes for why every run is -p: the setting, a
|
||||
// WSL Claude Code whose home is unknown, none found; "" for the TUI.
|
||||
func TestClaudeMachineWhy(t *testing.T) {
|
||||
if runtime.GOOS != "darwin" && runtime.GOOS != "linux" && runtime.GOOS != "windows" {
|
||||
t.Skip("no interactive mode on " + runtime.GOOS)
|
||||
}
|
||||
was := settings.Load()
|
||||
t.Cleanup(func() { _ = settings.Save(was) })
|
||||
claudeTUIRuns = true
|
||||
t.Cleanup(func() { claudeTUIRuns = false })
|
||||
here := claudeCLI{path: "/usr/local/bin/claude"}
|
||||
for _, c := range []struct {
|
||||
name string
|
||||
binary claudeCLI
|
||||
print bool
|
||||
code string
|
||||
}{
|
||||
{"here", here, false, ""},
|
||||
{"in WSL", claudeCLI{wsl: &wslrun.Tool{Distro: "Ubuntu", Home: "/home/me"}}, false, ""},
|
||||
{"turned off", here, true, "off"},
|
||||
{"in WSL, its home unknown", claudeCLI{wsl: &wslrun.Tool{Distro: "Ubuntu"}}, false, "wsl-home"},
|
||||
{"none", claudeCLI{}, false, "missing"},
|
||||
} {
|
||||
st := settings.Load()
|
||||
st.ClaudePrintMode = c.print
|
||||
if err := settings.Save(st); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if code, why := claudeMachineWhy(c.binary); code != c.code || (code == "") != (why == "") {
|
||||
t.Errorf("%s: %q %q, want code %q", c.name, code, why, c.code)
|
||||
}
|
||||
}
|
||||
claudeTUIRuns = false
|
||||
if code, _ := claudeMachineWhy(here); code != "no-shim" {
|
||||
t.Errorf("no shim: %q", code)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2639,6 +2639,15 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
.accts > :is(.keep-login, .switch-only, .pool-ends) + .acc { border-top: 1px solid var(--line-2); }
|
||||
.editor .accts .keep-login, .editor .accts .switch-only, .editor .accts .pool-ends { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-height: 34px; padding: 6px 11px; font-size: 12px; border-top: 1px solid var(--line-2); }
|
||||
.editor .accts .keep-login .keep-as { max-width: 240px; }
|
||||
/* Claude Code's interactive mode or -p, with why (claudeModeRow) */
|
||||
.accts > .claude-mode + .acc { border-top: 1px solid var(--line-2); }
|
||||
.editor .accts .claude-mode { display: grid; gap: 4px; padding: 7px 11px; font-size: 12px; border-top: 1px solid var(--line-2); }
|
||||
.claude-mode .mode-head { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; }
|
||||
.claude-mode .mode-name { font-weight: 500; margin-right: auto; }
|
||||
.claude-mode .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
|
||||
.claude-mode .dot.on { background: var(--green); }
|
||||
.claude-mode .note { color: var(--fg-2); margin: 0; }
|
||||
.claude-mode .link { font-size: 12px; }
|
||||
.editor .accts .pool-ends .note { flex-basis: 100%; color: var(--fg-2); }
|
||||
.acc .n { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.acc .plan { color: var(--muted); font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--pill); white-space: nowrap; }
|
||||
|
||||
@@ -13285,6 +13285,8 @@ function renderAccounts(a, p) {
|
||||
cb.onchange = () => accountAction("provider/switchonly", { id: p.id, switchOnly: cb.checked }, cb.checked ? on : off);
|
||||
list.append(el("div", "switch-only", only));
|
||||
}
|
||||
// whether these accounts' runs are Claude Code's interactive mode or -p
|
||||
if (p && a.agent === "claude" && !p.switchOnly) list.append(claudeModeRow());
|
||||
// how a pool ends at its caps (plugins#349)
|
||||
const capped = (l) => accountCapOf(p, l.user) || windowCapsOf(p, l.user);
|
||||
if (p && (ls.some(capped) || p.capStop || p.capCareful)) {
|
||||
@@ -13317,6 +13319,22 @@ function renderAccounts(a, p) {
|
||||
return list;
|
||||
}
|
||||
|
||||
// claudeModeRow: TUI or claude -p, and why; /api/claude/mode kept 30s, the
|
||||
// row drawn by claudemode.js, loaded with its first read
|
||||
let claudeMode = null, claudeModeAt = 0, claudeModeRead = null;
|
||||
function claudeModeRow() {
|
||||
const box = el("div", "claude-mode");
|
||||
box.hidden = true;
|
||||
const draw = () => window.claudeModeDraw(box, claudeMode);
|
||||
if (claudeMode && Date.now() - claudeModeAt < 30000) draw();
|
||||
else {
|
||||
claudeModeRead ||= Promise.all([api("claude/mode"), import("./claudemode.js")]).then(([m]) => { claudeMode = m; claudeModeAt = Date.now(); })
|
||||
.finally(() => { claudeModeRead = null; });
|
||||
claudeModeRead.then(draw, () => box.remove());
|
||||
}
|
||||
return box;
|
||||
}
|
||||
|
||||
// renderCodexDaemon: Codex's background app-server, on the account before a
|
||||
// switch (user); a restart ends its sessions, so only on a press
|
||||
function renderCodexDaemon(user) {
|
||||
@@ -21635,7 +21653,7 @@ function renderReplies(s, keep) {
|
||||
el("div", "sub wraps", t("A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. Off runs it as claude -p")));
|
||||
const uval = el("div", "val");
|
||||
uval.append(segs([["off", t("Off")], ["on", t("On")]], s.claudePrintMode ? "off" : "on",
|
||||
(v) => savePrefs({ ...keep, claudePrintMode: v === "off" })));
|
||||
(v) => { claudeMode = null; savePrefs({ ...keep, claudePrintMode: v === "off" }); }));
|
||||
u.append(uwho, uval);
|
||||
box.append(r, l, f, k, c, u);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// The Claude Code provider editor's row saying whether a Claude
|
||||
// subscription's runs are Claude Code's interactive mode (TUI) or claude
|
||||
// -p, why -p, and what tells them apart. app.js imports this with the
|
||||
// row's first read of /api/claude/mode (claudeModeRow), so it weighs
|
||||
// nothing on the core.
|
||||
let open = false;
|
||||
window.claudeModeDraw = function draw(box, m) {
|
||||
if (!m) return;
|
||||
box.hidden = false;
|
||||
const why = {
|
||||
off: "The interactive mode is turned off in Settings",
|
||||
broken: "The interactive mode failed to start on this computer lately; magpie tries it again after a while",
|
||||
"wsl-home": "magpie couldn't find the home folder of Claude Code in WSL",
|
||||
missing: "Claude Code isn't installed on this computer",
|
||||
}[m.why] || (m.why ? "This system has no interactive mode for it" : "A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p");
|
||||
const head = el("div", "mode-head");
|
||||
const more = el("button", "link", t("TUI or -p?"));
|
||||
more.setAttribute("aria-expanded", String(open));
|
||||
more.onclick = () => { open = !open; draw(box, m); };
|
||||
const set = el("button", "link", t("Change in Settings"));
|
||||
set.onclick = (e) => openSettingsAt(e, "models", $("#claudeTuiRow"));
|
||||
head.append(el("span", "dot" + (m.tui ? " on" : "")),
|
||||
el("span", "mode-name", t(m.tui ? "Running as Claude Code's interactive mode (TUI)" : "Running as claude -p (CLI)")), more, set);
|
||||
box.replaceChildren(head, el("div", "note", t(why)), ...(open ? [
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.",
|
||||
].map((s) => el("p", "note wraps", t(s))) : []));
|
||||
};
|
||||
@@ -337,6 +337,17 @@ const I18N = {
|
||||
"Stop looping replies": "停止循环的回复",
|
||||
"Short Claude system prompt": "精简 Claude 系统提示词",
|
||||
"Claude Code's interactive mode": "Claude Code 交互模式",
|
||||
"The interactive mode is turned off in Settings": "交互模式已在设置中关闭",
|
||||
"The interactive mode failed to start on this computer lately; magpie tries it again after a while": "交互模式最近在这台电脑上没能启动,magpie 过一段时间会再试",
|
||||
"magpie couldn't find the home folder of Claude Code in WSL": "magpie 找不到 WSL 里 Claude Code 的主目录",
|
||||
"Claude Code isn't installed on this computer": "这台电脑上没有安装 Claude Code",
|
||||
"This system has no interactive mode for it": "这个系统上不能用交互模式",
|
||||
"Running as Claude Code's interactive mode (TUI)": "当前走 Claude Code 交互模式(TUI)",
|
||||
"Running as claude -p (CLI)": "当前走 claude -p(CLI)",
|
||||
"TUI or -p?": "TUI 和 -p 有什么区别?",
|
||||
"A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p": "带安全防护、JSON schema、以 URL 给出的图片,或首条消息超过 400KB 的请求,仍然走 -p",
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.": "TUI:magpie 像人一样在 Claude Code 的交互界面里运行它,把每个请求交给它。Anthropic 看到的是 Claude Code 自己的交互式使用(entrypoint cli),套餐对一个请求的计量大约只有 -p 的一半,同样的套餐大约能用两倍久。",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.": "-p(CLI):claude -p,Claude Code 给脚本用的模式(entrypoint sdk-cli)。它能接收请求可携带的一切,但套餐对每个请求的计量大约是交互模式的两倍。只有交互模式关闭、在这里跑不了,或请求需要只有 -p 才支持的东西时,magpie 才会用它。",
|
||||
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. Off runs it as claude -p": "Claude 订阅像人一样以交互模式运行 Claude Code,套餐对每次请求的计量约为 -p 的一半。关闭则以 claude -p 运行",
|
||||
"A Claude subscription answers with the agent's own instructions as its system prompt, in place of Claude Code's, about 1K fewer tokens each request. Still the real Claude Code, but its requests look less like Claude Code's own, which can put the account more at risk": "Claude 订阅以智能体自己的指令作为系统提示词,代替 Claude Code 的,每次请求约少 1K token。仍是真正的 Claude Code,但请求不再那么像 Claude Code 自己发出的,账号风险可能更高",
|
||||
"Ask again after a refusal": "被拒答后再问",
|
||||
@@ -4619,6 +4630,17 @@ const I18N = {
|
||||
"Stop looping replies": "停止循環的回覆",
|
||||
"Short Claude system prompt": "精簡 Claude 系統提示詞",
|
||||
"Claude Code's interactive mode": "Claude Code 互動模式",
|
||||
"The interactive mode is turned off in Settings": "互動模式已在設定中關閉",
|
||||
"The interactive mode failed to start on this computer lately; magpie tries it again after a while": "互動模式最近在這台電腦上無法啟動,magpie 過一段時間會再試",
|
||||
"magpie couldn't find the home folder of Claude Code in WSL": "magpie 找不到 WSL 中 Claude Code 的主目錄",
|
||||
"Claude Code isn't installed on this computer": "這台電腦上沒有安裝 Claude Code",
|
||||
"This system has no interactive mode for it": "這個系統上無法使用互動模式",
|
||||
"Running as Claude Code's interactive mode (TUI)": "目前走 Claude Code 互動模式(TUI)",
|
||||
"Running as claude -p (CLI)": "目前走 claude -p(CLI)",
|
||||
"TUI or -p?": "TUI 和 -p 有什麼不同?",
|
||||
"A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p": "帶安全防護、JSON schema、以 URL 提供的圖片,或首則訊息超過 400KB 的請求,仍然走 -p",
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.": "TUI:magpie 像人一樣在 Claude Code 的互動介面裡執行它,把每個請求交給它。Anthropic 看到的是 Claude Code 本身的互動式使用(entrypoint cli),方案對一個請求的計量大約只有 -p 的一半,同樣的方案大約能用兩倍久。",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.": "-p(CLI):claude -p,Claude Code 給腳本用的模式(entrypoint sdk-cli)。它能接收請求可攜帶的一切,但方案對每個請求的計量大約是互動模式的兩倍。只有互動模式關閉、在這裡無法執行,或請求需要只有 -p 才支援的東西時,magpie 才會用它。",
|
||||
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. Off runs it as claude -p": "Claude 訂閱像人一樣以互動模式執行 Claude Code,方案對每次請求的計量約為 -p 的一半。關閉則以 claude -p 執行",
|
||||
"A Claude subscription answers with the agent's own instructions as its system prompt, in place of Claude Code's, about 1K fewer tokens each request. Still the real Claude Code, but its requests look less like Claude Code's own, which can put the account more at risk": "Claude 訂閱以代理自己的指令作為系統提示詞,取代 Claude Code 的,每次請求約少 1K token。仍是真正的 Claude Code,但請求不再那麼像 Claude Code 自己發出的,帳號風險可能更高",
|
||||
"Ask again after a refusal": "被拒答後再問",
|
||||
@@ -8870,6 +8892,17 @@ const I18N = {
|
||||
"Stop looping replies": "ループする応答を止める",
|
||||
"Short Claude system prompt": "Claude のシステムプロンプトを短く",
|
||||
"Claude Code's interactive mode": "Claude Code の対話モード",
|
||||
"The interactive mode is turned off in Settings": "対話モードは設定でオフになっています",
|
||||
"The interactive mode failed to start on this computer lately; magpie tries it again after a while": "対話モードは最近このコンピュータで起動できませんでした。magpie はしばらくしてからもう一度試します",
|
||||
"magpie couldn't find the home folder of Claude Code in WSL": "magpie は WSL 内の Claude Code のホームフォルダを見つけられませんでした",
|
||||
"Claude Code isn't installed on this computer": "このコンピュータには Claude Code がインストールされていません",
|
||||
"This system has no interactive mode for it": "このシステムでは対話モードを使えません",
|
||||
"Running as Claude Code's interactive mode (TUI)": "Claude Code の対話モード(TUI)で実行中",
|
||||
"Running as claude -p (CLI)": "claude -p(CLI)で実行中",
|
||||
"TUI or -p?": "TUI と -p の違いは?",
|
||||
"A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p": "セーフガード、JSON スキーマ、URL で示された画像、または 400KB を超える最初のメッセージを含むリクエストは引き続き -p で実行されます",
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.": "TUI:magpie は人と同じように Claude Code を対話画面で動かし、各リクエストをそこで渡します。Anthropic からは Claude Code 本来の対話的な利用(entrypoint cli)に見え、プランは 1 リクエストを -p の約半分として数えるため、同じプランが約 2 倍長く持ちます。",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.": "-p(CLI):claude -p、スクリプト向けの Claude Code のモード(entrypoint sdk-cli)。リクエストが運べるものはすべて受け付けますが、プランは各リクエストを対話モードの約 2 倍として数えます。magpie がこれを使うのは、対話モードがオフのとき、ここで動かせないとき、またはリクエストが -p だけが受け付けるものを必要とするときだけです。",
|
||||
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. Off runs it as claude -p": "Claude サブスクリプションは人と同じように Claude Code を対話モードで実行し、プランはリクエストを -p の約半分として数えます。オフにすると claude -p で実行します",
|
||||
"A Claude subscription answers with the agent's own instructions as its system prompt, in place of Claude Code's, about 1K fewer tokens each request. Still the real Claude Code, but its requests look less like Claude Code's own, which can put the account more at risk": "Claude サブスクリプションは Claude Code のものの代わりにエージェント自身の指示をシステムプロンプトとして応答し、リクエストごとに約 1K トークン少なくなります。本物の Claude Code のままですが、リクエストが Claude Code 自身のものらしくなくなるため、アカウントのリスクが高まる可能性があります",
|
||||
"Ask again after a refusal": "拒否のあと聞き直す",
|
||||
@@ -13131,6 +13164,17 @@ const I18N = {
|
||||
"Stop looping replies": "Schleifende Antworten beenden",
|
||||
"Short Claude system prompt": "Kurzer Claude-Systemprompt",
|
||||
"Claude Code's interactive mode": "Interaktiver Modus von Claude Code",
|
||||
"The interactive mode is turned off in Settings": "Der interaktive Modus ist in den Einstellungen ausgeschaltet",
|
||||
"The interactive mode failed to start on this computer lately; magpie tries it again after a while": "Der interaktive Modus ließ sich auf diesem Computer zuletzt nicht starten; magpie versucht es nach einer Weile erneut",
|
||||
"magpie couldn't find the home folder of Claude Code in WSL": "magpie hat den Home-Ordner von Claude Code in WSL nicht gefunden",
|
||||
"Claude Code isn't installed on this computer": "Claude Code ist auf diesem Computer nicht installiert",
|
||||
"This system has no interactive mode for it": "Auf diesem System gibt es den interaktiven Modus nicht",
|
||||
"Running as Claude Code's interactive mode (TUI)": "Läuft im interaktiven Modus von Claude Code (TUI)",
|
||||
"Running as claude -p (CLI)": "Läuft als claude -p (CLI)",
|
||||
"TUI or -p?": "TUI oder -p?",
|
||||
"A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p": "Eine Anfrage mit Safeguards, einem JSON-Schema, einem per URL angegebenen Bild oder einer ersten Nachricht über 400 KB läuft weiterhin als -p",
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.": "TUI: magpie führt Claude Code wie ein Mensch in seiner interaktiven Oberfläche aus und gibt ihm dort jede Anfrage. Anthropic sieht die eigene interaktive Nutzung von Claude Code (entrypoint cli), und der Plan zählt eine Anfrage mit etwa der Hälfte dessen, was -p verbraucht, sodass derselbe Plan etwa doppelt so lange reicht.",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.": "-p (CLI): claude -p, der Modus von Claude Code für Skripte (entrypoint sdk-cli). Er nimmt alles an, was eine Anfrage enthalten kann, aber der Plan zählt jede Anfrage mit etwa dem Doppelten des interaktiven Modus. magpie nutzt ihn nur, wenn der interaktive Modus aus ist, hier nicht laufen kann oder eine Anfrage etwas braucht, das nur -p annimmt.",
|
||||
"A Claude subscription runs Claude Code as a person does, in its interactive mode, where the plan counts a request at about half of what -p uses. Off runs it as claude -p": "Ein Claude-Abo führt Claude Code wie ein Mensch im interaktiven Modus aus, wo der Plan eine Anfrage mit etwa der Hälfte von -p anrechnet. Aus führt es als claude -p aus",
|
||||
"A Claude subscription answers with the agent's own instructions as its system prompt, in place of Claude Code's, about 1K fewer tokens each request. Still the real Claude Code, but its requests look less like Claude Code's own, which can put the account more at risk": "Ein Claude-Abo antwortet mit den eigenen Anweisungen des Agenten als Systemprompt statt mit dem von Claude Code, etwa 1K Token weniger pro Anfrage. Weiterhin das echte Claude Code, aber seine Anfragen sehen Claude Codes eigenen weniger ähnlich, was das Konto stärker gefährden kann",
|
||||
"Ask again after a refusal": "Nach einer Ablehnung erneut fragen",
|
||||
|
||||
@@ -2298,6 +2298,12 @@ func providerRoutes(mux *http.ServeMux, w Windows) {
|
||||
writeJSON(rw, st)
|
||||
keepProviders(st) // as a provider action's: the panel's switch draws it
|
||||
})
|
||||
// whether a Claude subscription's runs are Claude Code's interactive
|
||||
// mode or -p, and why -p, for the Claude Code provider page; read when
|
||||
// the page opens, not in /api/providers' polls
|
||||
mux.HandleFunc("GET /api/claude/mode", func(rw http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(rw, gateway.ClaudeModeNow())
|
||||
})
|
||||
// Codex's background app-server, left on the account before a switch
|
||||
// or on the model list before a change (the Agents row's Restart):
|
||||
// restarting it (Codex 0.162's sessions on it reconnect, after a turn
|
||||
|
||||
@@ -109,12 +109,16 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await page.locator(".editor .accts").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${web ? "web-" : ""}${width}-account-weight.png`) });
|
||||
}
|
||||
|
||||
// a click edits it in place, Enter saves it
|
||||
// a click edits it in place, Enter saves it; the chip is brought into
|
||||
// view first (By weight can be a screen below it on a phone), as the
|
||||
// click would, so what is measured is the click's own scrolling
|
||||
await chip("pro@example.com").scrollIntoViewIfNeeded();
|
||||
const atChip = await scrolled();
|
||||
await chip("pro@example.com").click();
|
||||
const box = page.locator('.editor .acc[data-account-id="pro@example.com"] .key-weight-in');
|
||||
await box.waitFor();
|
||||
assert.equal(await box.getAttribute("aria-label"), await say(page, lang, "Account weight"), at);
|
||||
assert.equal(await scrolled(), sc, `${at}: a click scrolled`);
|
||||
assert.equal(await scrolled(), atChip, `${at}: a click scrolled`);
|
||||
await box.fill("2");
|
||||
await box.press("Enter");
|
||||
for (let i = 0; i < 60 && !posts.length; i++) await new Promise((r) => setTimeout(r, 50));
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// The owner: the Claude Code provider page says whether its runs are
|
||||
// Claude Code's interactive mode (TUI) or claude -p (CLI), and what tells
|
||||
// them apart. Under Claude's accounts a row says which, read from
|
||||
// /api/claude/mode once as the page opens, with why when -p; "TUI or -p?"
|
||||
// opens what each is and why the TUI is better, and "Change in Settings"
|
||||
// goes to the setting. Only switch (nothing served) shows no row. In
|
||||
// English, Chinese, Japanese and German, Chromium and WebKit, at 1100 and
|
||||
// 420 wide.
|
||||
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 claude = ({ switchOnly = false } = {}) => ({
|
||||
id: "claude", name: "Claude", icon: "claude-color", chat: "", responses: "", anthropic: "", catalog: "", routing: "", switchOnly,
|
||||
models: [{ id: "claude-sonnet-5", name: "Claude Sonnet 5", on: true }], agents: [], fallback: [], headers: {}, keyList: [],
|
||||
account: {
|
||||
agent: "claude", agentName: "Claude Code", user: "work@example.com", plan: "MAX",
|
||||
logins: [{ user: "work@example.com", plan: "MAX", active: true, on: true }],
|
||||
},
|
||||
});
|
||||
|
||||
function serve(lang, first, mode, reads) {
|
||||
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
||||
const providers = () => ({ providers: [first], presets: [], excluded: [], gateway: { running: true, window: true } });
|
||||
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:"light",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(state);
|
||||
if (url.pathname === "/api/providers") return json(providers());
|
||||
if (url.pathname === "/api/claude/mode") { reads.n++; return json(mode); }
|
||||
if (url.pathname === "/api/settings") return json(state.settings);
|
||||
if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] });
|
||||
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)];
|
||||
await route.fulfill({ body: await fs.readFile(file), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
const words = {
|
||||
en: { tui: "Running as Claude Code's interactive mode (TUI)", cli: "Running as claude -p (CLI)", off: "turned off in Settings", wsl: "WSL", why: "about half" },
|
||||
zh: { tui: "当前走 Claude Code 交互模式(TUI)", cli: "当前走 claude -p(CLI)", off: "设置中关闭", wsl: "WSL", why: "一半" },
|
||||
ja: { tui: "Claude Code の対話モード(TUI)で実行中", cli: "claude -p(CLI)で実行中", off: "設定でオフ", wsl: "WSL", why: "約半分" },
|
||||
de: { tui: "Läuft im interaktiven Modus von Claude Code (TUI)", cli: "Läuft als claude -p (CLI)", off: "Einstellungen ausgeschaltet", wsl: "WSL", why: "Hälfte" },
|
||||
};
|
||||
const strings = [
|
||||
"The interactive mode is turned off in Settings",
|
||||
"The interactive mode failed to start on this computer lately; magpie tries it again after a while",
|
||||
"magpie couldn't find the home folder of Claude Code in WSL",
|
||||
"Claude Code isn't installed on this computer",
|
||||
"This system has no interactive mode for it",
|
||||
"Running as Claude Code's interactive mode (TUI)",
|
||||
"Running as claude -p (CLI)",
|
||||
"TUI or -p?",
|
||||
"Change in Settings",
|
||||
"A request with safeguards, a JSON schema, an image known by its URL or a first message over 400KB still runs as -p",
|
||||
"TUI: magpie runs Claude Code as a person does, in its interactive screen, and gives it each request there. Anthropic sees Claude Code's own interactive use (entrypoint cli), and the plan counts a request at about half of what -p uses, so the same plan lasts about twice as long.",
|
||||
"-p (CLI): claude -p, Claude Code's mode for scripts (entrypoint sdk-cli). It takes everything a request can carry, but the plan counts each request at about twice the interactive mode's. magpie uses it only when the interactive mode is off, can't run here, or a request needs what only -p takes.",
|
||||
];
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const width of [1100, 420]) {
|
||||
for (const lang of Object.keys(words)) {
|
||||
const w = words[lang];
|
||||
const open = async (t, mode, opts = {}) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [], reads = { n: 0 };
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, claude(opts), mode, reads));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
// the first draw waits on the page's first reads: a load's room, not a click's (#4470)
|
||||
const row = page.locator(".row.provider", { hasText: "Claude" }).first();
|
||||
await row.waitFor({ timeout: 60000 });
|
||||
await row.click();
|
||||
await page.locator(".editor .acc").first().waitFor();
|
||||
return { page, errors, reads };
|
||||
};
|
||||
const fits = async (page, sel) => {
|
||||
const box = await page.locator(sel).boundingBox();
|
||||
assert.ok(box.x >= 0 && box.x + box.width <= width, `${sel} fits across ${width}`);
|
||||
};
|
||||
|
||||
test(`${engine} ${width} ${lang}: the TUI is said, and what tells it from -p opens`, async (t) => {
|
||||
const { page, errors, reads } = await open(t, { tui: true });
|
||||
const mode = page.locator(".editor .accts .claude-mode");
|
||||
await mode.locator(".mode-name").waitFor();
|
||||
assert.equal((await mode.locator(".mode-name").textContent()).trim(), w.tui);
|
||||
assert.ok(await mode.locator(".dot.on").count(), "the TUI's dot is lit");
|
||||
assert.match(await mode.locator(".note").first().textContent(), /400 ?KB/, "what still runs as -p is said");
|
||||
if (lang === "en") {
|
||||
const missing = await page.evaluate((ks) => ["zh", "zh-TW", "ja", "de"].flatMap((l) => ks.filter((k) => !I18N[l][k]).map((k) => `${l}: ${k}`)), strings);
|
||||
assert.deepEqual(missing, [], "every string has its translations");
|
||||
}
|
||||
await mode.scrollIntoViewIfNeeded();
|
||||
await fits(page, ".editor .accts .claude-mode");
|
||||
const more = mode.locator("button.link").first();
|
||||
assert.equal(await more.getAttribute("aria-expanded"), "false");
|
||||
await more.click();
|
||||
await page.locator(".editor .accts .claude-mode p.note").nth(1).waitFor();
|
||||
const said = await mode.locator("p.note").allTextContents();
|
||||
assert.match(said[0], new RegExp(w.why), "the TUI's saving is said");
|
||||
assert.match(said[0], /entrypoint cli/);
|
||||
assert.match(said[1], /entrypoint sdk-cli/);
|
||||
assert.equal(await mode.locator("button.link").first().getAttribute("aria-expanded"), "true");
|
||||
await fits(page, ".editor .accts .claude-mode");
|
||||
assert.equal(reads.n, 1, "the mode is read once, not on each draw");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine} ${width} ${lang}: -p says why, and Change in Settings goes to the setting`, async (t) => {
|
||||
const { page, errors } = await open(t, { tui: false, why: "off" });
|
||||
const mode = page.locator(".editor .accts .claude-mode");
|
||||
await mode.locator(".mode-name").waitFor();
|
||||
assert.equal((await mode.locator(".mode-name").textContent()).trim(), w.cli);
|
||||
assert.equal(await mode.locator(".dot.on").count(), 0);
|
||||
assert.match(await mode.locator(".note").first().textContent(), new RegExp(w.off));
|
||||
await mode.locator("button.link").nth(1).click();
|
||||
await page.locator("#claudeTuiRow").waitFor();
|
||||
assert.ok(await page.locator("#setPage-models").isVisible(), "Settings opens on the setting's page");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test(`${engine} ${width} ${lang}: Claude Code in WSL whose home is unknown says so; Only switch shows no row`, async (t) => {
|
||||
const wsl = await open(t, { tui: false, why: "wsl-home", wsl: true });
|
||||
await wsl.page.locator(".editor .accts .claude-mode .mode-name").waitFor();
|
||||
assert.match(await wsl.page.locator(".editor .accts .claude-mode .note").first().textContent(), new RegExp(w.wsl));
|
||||
const only = await open(t, { tui: true }, { switchOnly: true });
|
||||
await only.page.locator(".editor .accts .switch-only").waitFor();
|
||||
assert.equal(await only.page.locator(".editor .accts .claude-mode").count(), 0);
|
||||
assert.equal(only.reads.n, 0, "nothing is read for a row not shown");
|
||||
assert.deepEqual([...wsl.errors, ...only.errors], []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -148,8 +148,9 @@ test("compat.js is the first of the page's own scripts", async () => {
|
||||
// bar shows a card, autoresetown.js when Settings draws Codex's auto-use
|
||||
// rows, registry.js when Plugins draws its npm registry, navlamp.js when
|
||||
// the pointer comes over the sidebar, whatsnew.js when release notes
|
||||
// open; 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"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
|
||||
// open, claudemode.js when a Claude provider's editor opens; 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"].includes(f)) assert(all.includes(f), f + " is not loaded by index.html");
|
||||
});
|
||||
|
||||
test("the styles hold up in Safari 15.0", async () => {
|
||||
|
||||
Reference in New Issue
Block a user