diff --git a/docs/subsystems/claude-subscription-bridge.md b/docs/subsystems/claude-subscription-bridge.md index d08b6b8ee..1cd96f6c8 100644 --- a/docs/subsystems/claude-subscription-bridge.md +++ b/docs/subsystems/claude-subscription-bridge.md @@ -364,8 +364,9 @@ helper presses ↓ until "Yes" is the last choice drawn and Enter only once it has stayed so for 300ms (`ready`, `trustSettle`). Pressing Enter blind chose "No, exit" in the real gateway, and no run started. -Every run is `-p` only when Settings › Models › Replies › Claude Code's -interactive mode is Off (`claudePrintMode`), or in the gateway's own +Every run is `-p` only when the Claude Code editor's "Claude Code runs +as" row is on claude -p (`claudePrintMode`; magpie web as a gateway +switches it with the editor's *Claude Code's interactive mode* row), or in the gateway's own tests, whose fake Claude Codes are `-p` ones (`claudeTUIRuns`, code `no-shim`). With it On, nothing ever runs as `-p` (the owner, 11-01): the plan counts a `-p` request as another client's, at about twice the @@ -868,8 +869,8 @@ fails the request or delays an ordinary request's keepalives. Every run is the real Claude Code. By default it keeps Claude Code's own system prompt, and the caller's instructions go after it in the interactive mode (below), and in the run's first user message inside -`` in `-p` or with client cache marks. Settings › Models › -Replies › Short Claude system prompt (`claudeLeanPrompt`, off by default) +`` in `-p` or with client cache marks. The Claude Code +editor's Short Claude system prompt (`claudeLeanPrompt`, off by default) starts a run with `--system-prompt-file` instead. The file is `system.md` in the run's temp folder, under the distro's mount in WSL (`claudeCLI.file`). It holds `leanSystem`: the caller's instructions without a client Claude diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 18102f564..6584abb5a 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -4947,6 +4947,9 @@ body .row.agent .ag-prefs .row.pref .who { display: block; } .editor .prov-prefs[hidden] { display: none; } .prov-prefs .list.prefs { margin: 0; } .prov-prefs .list.prefs[hidden] { display: none; } +/* the editor's Claude Code runs as row switches it; magpie web as a + gateway has that row's switch off, so this one shows there */ +.prov-prefs #claudeRunList:not(.gw) #claudeTuiRow { display: none; } .prov-prefs .row.pref .sub { white-space: normal; } .prov-prefs .row.pref { flex-wrap: wrap; row-gap: 8px; } .prov-prefs .row.pref .who { flex: 1 1 240px; min-width: 0; } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index b94d84768..e94705af1 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -19613,7 +19613,7 @@ const DISCORD_SVG = ' $("#" + id)); + const lists = (PROV_PREFS[agent] || []).filter((id) => !gatewayMode || id == "claudeRunList").map((id) => $("#" + id)); const g = [...$("#pluginCheckinList").children].find((x) => x.dataset.provider === agent); return g ? [...lists, g] : lists; } @@ -19647,7 +19647,7 @@ function remountProvPrefs() { provPrefMount = null; } function provPrefsField(agent) { - if (gatewayMode || !PROV_PREFS[agent] && !(prefs?.checkinPlugins || []).some((x) => x.id === agent) && prefs) return []; + if (gatewayMode && agent != "claude" || !PROV_PREFS[agent] && !(prefs?.checkinPlugins || []).some((x) => x.id === agent) && prefs) return []; const box = edAligned(el("div", "prov-prefs")); if (prefs) mountProvPrefs(box, agent); else { @@ -21677,7 +21677,10 @@ function renderReplies(s, keep) { const u = segRow("claudeTuiRow", t("Claude Code's interactive mode"), 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. On, a request runs as -p only when Anthropic refuses its agent's prompt there. Off runs every request as claude -p"), onOff, s.claudePrintMode ? "off" : "on", (v) => { claudeMode = null; savePrefs({ ...keep, claudePrintMode: v === "off" }); }); - box.append(r, l, c, u); + box.append(r, l); + // a Claude run's, in its provider's editor (PROV_PREFS) + $("#claudeRunList").replaceChildren(c, u); + $("#claudeRunList").classList.toggle("gw", gatewayMode); $("#routeList").replaceChildren(f, a, k, $("#busyLoadRow")); } diff --git a/internal/gui/assets/claudemode.js b/internal/gui/assets/claudemode.js index 921b9c09d..604fb1747 100644 --- a/internal/gui/assets/claudemode.js +++ b/internal/gui/assets/claudemode.js @@ -11,7 +11,7 @@ // why the interactive mode can't run here, or is off, by the gateway's // code (claudeMachineWhy) const CC_WHY = { - off: "the interactive mode is off in Settings", + off: "the interactive mode is turned off", os: "this system can't run the interactive mode", missing: "Claude Code isn't installed on this computer", }; @@ -40,7 +40,7 @@ function ccTip(anchor, tui) { t("Claude Code's print mode, the one scripts and the Agent SDK use: a request in, its reply out."), t("It starts at once, with no terminal of its own to open first."), t("The plan counts a -p request at about twice the interactive mode's.")), - el("div", "foot", t("Switched here or in Settings › Models › Replies. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p."))); + el("div", "foot", t("Switched here. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p."))); document.body.append(tip); const a = anchor.getBoundingClientRect(), b = tip.getBoundingClientRect(); tip.style.left = Math.max(8, Math.min(a.left, innerWidth - b.width - 8)) + "px"; diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 8b8782006..5f4ba3ea3 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -87,14 +87,14 @@ const I18N = { "Claude Code runs as": "Claude Code 运行方式", "Interactive mode (TUI)": "交互模式(TUI)", "Last request {ago}: interactive mode": "上次请求 {ago}:交互模式", - "the interactive mode is off in Settings": "设置里关闭了交互模式", + "the interactive mode is turned off": "交互模式已关闭", "this system can't run the interactive mode": "这个系统不能运行交互模式", "magpie opens Claude Code as a person does, in a terminal of its own that you don't see, types each request in and reads the reply from its transcript.": "magpie 像人一样打开 Claude Code:在一个你看不到的终端里输入每个请求,再从它的会话记录里读出回复。", "Your plan counts these requests as Claude Code's own use, at about half of the 5-hour allowance that -p uses for the same work.": "套餐把这些请求算作 Claude Code 自身的使用,同样的工作只消耗 -p 约一半的 5 小时额度。", "Claude Code's print mode, the one scripts and the Agent SDK use: a request in, its reply out.": "Claude Code 的打印模式,脚本和 Agent SDK 用的就是它:一个请求进去,一个回复出来。", "It starts at once, with no terminal of its own to open first.": "启动即用,不用先打开它自己的终端。", "The plan counts a -p request at about twice the interactive mode's.": "套餐对 -p 请求的计量约为交互模式的两倍。", - "Switched here or in Settings › Models › Replies. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p.": "可在这里或 设置 › 模型 › 回复 里切换。开着交互模式时,交互模式接不了或启动失败的请求会报错并说明原因。Anthropic 在交互模式里当作第三方应用拒绝的轮次会改走 -p。", + "Switched here. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p.": "在这里切换。开着交互模式时,交互模式接不了或启动失败的请求会报错并说明原因。Anthropic 在交互模式里当作第三方应用拒绝的轮次会改走 -p。", "Every request runs as claude -p": "每个请求都以 claude -p 运行", "MCP router": "MCP 路由", "in {agents}": "用于 {agents}", @@ -4869,14 +4869,14 @@ const I18N = { "Claude Code runs as": "Claude Code 執行方式", "Interactive mode (TUI)": "互動模式(TUI)", "Last request {ago}: interactive mode": "上次請求 {ago}:互動模式", - "the interactive mode is off in Settings": "設定裡關閉了互動模式", + "the interactive mode is turned off": "互動模式已關閉", "this system can't run the interactive mode": "這個系統無法執行互動模式", "magpie opens Claude Code as a person does, in a terminal of its own that you don't see, types each request in and reads the reply from its transcript.": "magpie 像人一樣開啟 Claude Code:在一個你看不到的終端機裡輸入每個請求,再從它的對話記錄讀出回覆。", "Your plan counts these requests as Claude Code's own use, at about half of the 5-hour allowance that -p uses for the same work.": "方案把這些請求算作 Claude Code 本身的使用,同樣的工作只消耗 -p 約一半的 5 小時額度。", "Claude Code's print mode, the one scripts and the Agent SDK use: a request in, its reply out.": "Claude Code 的列印模式,腳本和 Agent SDK 用的就是它:一個請求進去,一個回覆出來。", "It starts at once, with no terminal of its own to open first.": "啟動即用,不用先開啟它自己的終端機。", "The plan counts a -p request at about twice the interactive mode's.": "方案對 -p 請求的計量約為互動模式的兩倍。", - "Switched here or in Settings › Models › Replies. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p.": "可在這裡或 設定 › 模型 › 回覆 裡切換。開著互動模式時,互動模式接不了或啟動失敗的請求會報錯並說明原因。Anthropic 在互動模式裡當作第三方應用拒絕的輪次會改走 -p。", + "Switched here. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p.": "在這裡切換。開著互動模式時,互動模式接不了或啟動失敗的請求會報錯並說明原因。Anthropic 在互動模式裡當作第三方應用拒絕的輪次會改走 -p。", "Every request runs as claude -p": "每個請求都以 claude -p 執行", "MCP router": "MCP 路由", "in {agents}": "用於 {agents}", @@ -9636,14 +9636,14 @@ const I18N = { "Claude Code runs as": "Claude Code の実行方式", "Interactive mode (TUI)": "対話モード(TUI)", "Last request {ago}: interactive mode": "前回のリクエスト({ago}):対話モード", - "the interactive mode is off in Settings": "設定で対話モードがオフになっています", + "the interactive mode is turned off": "対話モードがオフになっています", "this system can't run the interactive mode": "このシステムでは対話モードを実行できません", "magpie opens Claude Code as a person does, in a terminal of its own that you don't see, types each request in and reads the reply from its transcript.": "magpie は人と同じように Claude Code を開きます。見えない専用のターミナルで各リクエストを入力し、トランスクリプトから応答を読み取ります。", "Your plan counts these requests as Claude Code's own use, at about half of the 5-hour allowance that -p uses for the same work.": "プランはこれらのリクエストを Claude Code 自身の利用として数え、同じ作業で -p の約半分の 5 時間枠しか使いません。", "Claude Code's print mode, the one scripts and the Agent SDK use: a request in, its reply out.": "Claude Code の print モードで、スクリプトや Agent SDK が使うものです。リクエストを渡し、応答を受け取ります。", "It starts at once, with no terminal of its own to open first.": "専用の端末を先に開くことなく、すぐに起動します。", "The plan counts a -p request at about twice the interactive mode's.": "プランは -p のリクエストを対話モードの約 2 倍として数えます。", - "Switched here or in Settings › Models › Replies. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p.": "ここか 設定 › モデル › 応答 で切り替えられます。対話モードがオンのときは、対話モードで扱えないリクエストや起動に失敗したリクエストは理由を添えてエラーになります。Anthropic が対話モードでサードパーティアプリのものとして拒否したターンは -p で実行します。", + "Switched here. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p.": "ここで切り替えます。対話モードがオンのときは、対話モードで扱えないリクエストや起動に失敗したリクエストは理由を添えてエラーになります。Anthropic が対話モードでサードパーティアプリのものとして拒否したターンは -p で実行します。", "Every request runs as claude -p": "すべてのリクエストを claude -p で実行します", "MCP router": "MCP ルーター", "in {agents}": "{agents} で使用", @@ -14405,14 +14405,14 @@ const I18N = { "Claude Code runs as": "Claude Code läuft als", "Interactive mode (TUI)": "Interaktiver Modus (TUI)", "Last request {ago}: interactive mode": "Letzte Anfrage {ago}: interaktiver Modus", - "the interactive mode is off in Settings": "der interaktive Modus ist in den Einstellungen aus", + "the interactive mode is turned off": "der interaktive Modus ist ausgeschaltet", "this system can't run the interactive mode": "dieses System kann den interaktiven Modus nicht ausführen", "magpie opens Claude Code as a person does, in a terminal of its own that you don't see, types each request in and reads the reply from its transcript.": "magpie öffnet Claude Code wie ein Mensch, in einem eigenen Terminal, das du nicht siehst, tippt jede Anfrage ein und liest die Antwort aus dem Transkript.", "Your plan counts these requests as Claude Code's own use, at about half of the 5-hour allowance that -p uses for the same work.": "Dein Plan zählt diese Anfragen als Claude Codes eigene Nutzung, mit etwa der Hälfte des 5-Stunden-Kontingents, das -p für dieselbe Arbeit braucht.", "Claude Code's print mode, the one scripts and the Agent SDK use: a request in, its reply out.": "Der Print-Modus von Claude Code, den Skripte und das Agent SDK nutzen: eine Anfrage hinein, ihre Antwort heraus.", "It starts at once, with no terminal of its own to open first.": "Er startet sofort, ohne zuerst ein eigenes Terminal zu öffnen.", "The plan counts a -p request at about twice the interactive mode's.": "Der Plan zählt eine -p-Anfrage etwa doppelt so hoch wie eine im interaktiven Modus.", - "Switched here or in Settings › Models › Replies. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p.": "Hier oder unter Einstellungen › Modelle › Antworten umschaltbar. Mit eingeschaltetem interaktivem Modus schlägt eine Anfrage, die er nicht annehmen kann oder für die er nicht startet, mit dem Grund fehl. Ein Zug, den Anthropic dort als den einer Drittanbieter-App ablehnt, läuft als -p.", + "Switched here. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p.": "Hier umschaltbar. Mit eingeschaltetem interaktivem Modus schlägt eine Anfrage, die er nicht annehmen kann oder für die er nicht startet, mit dem Grund fehl. Ein Zug, den Anthropic dort als den einer Drittanbieter-App ablehnt, läuft als -p.", "Every request runs as claude -p": "Jede Anfrage läuft als claude -p", "MCP router": "MCP-Router", "in {agents}": "in {agents}", diff --git a/internal/gui/assets/index.html b/internal/gui/assets/index.html index 27f90bafd..cddd25e3d 100644 --- a/internal/gui/assets/index.html +++ b/internal/gui/assets/index.html @@ -460,6 +460,7 @@
+
Warm up on reset
diff --git a/internal/gui/tests/claude-lean-prompt-setting.test.cjs b/internal/gui/tests/claude-lean-prompt-setting.test.cjs index b1e7269d9..917861df2 100644 --- a/internal/gui/tests/claude-lean-prompt-setting.test.cjs +++ b/internal/gui/tests/claude-lean-prompt-setting.test.cjs @@ -1,6 +1,8 @@ // Run with Node's test runner and Playwright on the module path; see README.md. -// Settings › Models › Replies: Short Claude system prompt is Off, says what -// it saves and what it risks, and On saves claudeLeanPrompt with the rest of +// The Claude subscription's editor (the scattered settings audit after +// netube99 on X: it was in Settings › Models › Replies, away from the +// subscription it changes): Short Claude system prompt is Off, says what +// it saves and what it risks, and Settings' search still finds it, and On saves claudeLeanPrompt with the rest of // the settings kept, the page not moved by the click. In English, Chinese, // Japanese and German, 1100 and 420 wide. const assert = require("node:assert/strict"); @@ -8,14 +10,14 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); -const { watchSettingsReads, settingsDrawn } = require("./reader.cjs"); +const { provPrefsProviders, openProvPrefs, inEditor, watchSettingsReads, settingsDrawn } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const words = { - en: { name: "Short Claude system prompt", head: "Replies", off: "Off", on: "On", sub: "1K fewer tokens", risk: "more at risk" }, - zh: { name: "精简 Claude 系统提示词", head: "回复", off: "关闭", on: "开启", sub: "约少 1K token", risk: "风险可能更高" }, - ja: { name: "Claude のシステムプロンプトを短く", head: "応答", off: "オフ", on: "オン", sub: "約 1K トークン少なく", risk: "リスクが高まる" }, - de: { name: "Kurzer Claude-Systemprompt", head: "Antworten", off: "Aus", on: "An", sub: "1K Token weniger", risk: "stärker gefährden" }, + en: { name: "Short Claude system prompt", off: "Off", on: "On", sub: "1K fewer tokens", risk: "more at risk" }, + zh: { name: "精简 Claude 系统提示词", off: "关闭", on: "开启", sub: "约少 1K token", risk: "风险可能更高" }, + ja: { name: "Claude のシステムプロンプトを短く", off: "オフ", on: "オン", sub: "約 1K トークン少なく", risk: "リスクが高まる" }, + de: { name: "Kurzer Claude-Systemprompt", off: "Aus", on: "An", sub: "1K Token weniger", risk: "stärker gefährden" }, }; function serve(lang, saved) { @@ -35,7 +37,8 @@ function serve(lang, saved) { return json(settings); } 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 === "/api/providers") return json(provPrefsProviders(["claude"], { claude: "Claude Code" })); + if (url.pathname === "/api/claude/mode") return json({ tui: !settings.claudePrintMode, why: settings.claudePrintMode ? "off" : "" }); 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)]; @@ -56,26 +59,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", page.on("pageerror", (e) => errors.push(e.message)); const saved = []; await page.route("**/*", serve(lang, saved)); - await watchSettingsReads(page); - await page.goto("http://magpie.test/?view=settings&tab=models"); - await settingsDrawn(page); // rows found are the ones that stay (#1659) - const row = page.locator("#replyList #claudeLeanRow"); - await row.waitFor(); - // scrolled to as a reader does, with the wheel: WebKit at 420 put - // back a scroll made from script - await page.mouse.move(width / 2, 450); - for (let i = 0; i < 40; i++) { - const box = await row.boundingBox(); - if (box && box.y >= 0 && box.y + box.height <= 900) break; - await page.mouse.wheel(0, 120); - await page.waitForTimeout(50); - } + await openProvPrefs(page, "claude"); + const row = page.locator(".editor .prov-prefs #claudeRunList > #claudeLeanRow"); + await inEditor(page, row); assert.equal(await row.locator(".name").textContent(), w.name); const sub = await row.locator(".sub").textContent(); assert(sub.includes(w.sub) && sub.includes(w.risk), sub); - // its explanation rests out of sight, shown whole in the row's hover card - // (settings-hints.test.cjs) - assert.equal(await row.locator(".sub").first().evaluate((e) => getComputedStyle(e).getPropertyValue("--hint").trim()), "1", "the explanation shows at rest"); for (const part of [".name", ".segs"]) { const fit = await row.locator(part).first().evaluate((e) => { const r = e.getBoundingClientRect(); @@ -83,7 +72,6 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", }); assert(fit, `${part} fits at ${width}`); } - assert.equal(await page.locator("#replyList").evaluate((l) => l.previousElementSibling.textContent.trim()), w.head); const on = row.locator(".segs button", { hasText: w.on }); const off = row.locator(".segs button", { hasText: w.off }); assert.equal(await off.getAttribute("aria-pressed"), "true", "Off at first"); @@ -99,6 +87,17 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(saved[0].redact, true, "the rest kept"); assert.equal(saved[0].lang, lang); assert.deepEqual(await page.evaluate(() => [scrollX, scrollY, document.scrollingElement.scrollTop]), before, "the click moved nothing"); + + // Settings has it no more, and its search leads to the editor + await watchSettingsReads(page); + await page.goto("http://magpie.test/?view=settings&tab=models"); + await settingsDrawn(page); + assert.equal(await page.locator("#view-settings #claudeLeanRow").count(), 0, "not in Settings"); + await page.locator("#setQ").fill(w.name); + const link = page.locator("#provPrefLinks .agent-pref-link", { hasText: w.name }).first(); + await link.waitFor(); + await link.locator("button").click(); + await page.locator(".editor .prov-prefs #claudeLeanRow").waitFor(); assert.deepEqual(errors, []); }); } diff --git a/internal/gui/tests/claude-mode.test.cjs b/internal/gui/tests/claude-mode.test.cjs index ef7b6accf..09d87d561 100644 --- a/internal/gui/tests/claude-mode.test.cjs +++ b/internal/gui/tests/claude-mode.test.cjs @@ -127,7 +127,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", { on: false, name: "claude -p", now: "", good: 1, bad: 1 }, ]); // nothing in the card says a request falls back to -p (the owner, 11-01) - assert.equal((await tip.locator(".foot").textContent()).trim(), await tr("Switched here or in Settings › Models › Replies. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p.")); + assert.equal((await tip.locator(".foot").textContent()).trim(), await tr("Switched here. With the interactive mode on, a request it can't take, or one it fails to start for, fails saying why. A turn Anthropic refuses there as a third-party app's runs as -p.")); assert.equal((await tip.locator(".cc-m").nth(1).locator("p.good").textContent()).trim(), await tr("It starts at once, with no terminal of its own to open first.")); const box = await tip.boundingBox(); assert(box.x >= 0 && box.y >= 0 && box.x + box.width <= width && box.y + box.height <= 760, `the card is inside the window: ${JSON.stringify(box)}`); diff --git a/internal/gui/tests/claude-tui-setting.test.cjs b/internal/gui/tests/claude-tui-setting.test.cjs index fcdb302f6..3579199f0 100644 --- a/internal/gui/tests/claude-tui-setting.test.cjs +++ b/internal/gui/tests/claude-tui-setting.test.cjs @@ -1,5 +1,8 @@ // Run with Node's test runner and Playwright on the module path; see README.md. -// Settings › Models › Replies: Claude Code's interactive mode is On, says +// The Claude subscription's editor (the scattered settings audit after +// netube99 on X: it was in Settings › Models › Replies). The editor's own +// "Claude Code runs as" row switches it, so this row shows only where that +// one can't: magpie web as a gateway. There it is On, says // what it saves, that On never runs -p and Off always does; Off saves // claudePrintMode with the rest of the settings kept, the page not moved // by the click, and On turns -p back off. There is no third choice: the @@ -10,23 +13,23 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); -const { watchSettingsReads, settingsDrawn } = require("./reader.cjs"); +const { provPrefsProviders, openProvPrefs, inEditor } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const words = { - en: { name: "Claude Code's interactive mode", head: "Replies", off: "Off", on: "On", sub: "about half", risk: "claude -p" }, - zh: { name: "Claude Code 交互模式", head: "回复", off: "关闭", on: "开启", sub: "约为 -p 的一半", risk: "claude -p" }, - ja: { name: "Claude Code の対話モード", head: "応答", off: "オフ", on: "オン", sub: "-p の約半分", risk: "claude -p" }, - de: { name: "Interaktiver Modus von Claude Code", head: "Antworten", off: "Aus", on: "An", sub: "Hälfte von -p", risk: "claude -p" }, + en: { name: "Claude Code's interactive mode", off: "Off", on: "On", sub: "about half", risk: "claude -p" }, + zh: { name: "Claude Code 交互模式", off: "关闭", on: "开启", sub: "约为 -p 的一半", risk: "claude -p" }, + ja: { name: "Claude Code の対話モード", off: "オフ", on: "オン", sub: "-p の約半分", risk: "claude -p" }, + de: { name: "Interaktiver Modus von Claude Code", off: "Aus", on: "An", sub: "Hälfte von -p", risk: "claude -p" }, }; -function serve(lang, saved) { - const settings = { lang, theme: "light", redact: true }; +function serve(lang, saved, gateway) { + const settings = { lang, theme: "light", redact: true, gatewayOn: gateway }; const state = { agents: [], profiles: [], settings }; 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 === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true,gateway:${gateway}};` }); 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/settings") { @@ -37,7 +40,8 @@ function serve(lang, saved) { return json(settings); } 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 === "/api/providers") return json(provPrefsProviders(["claude"], { claude: "Claude Code" })); + if (url.pathname === "/api/claude/mode") return json({ tui: !settings.claudePrintMode, why: settings.claudePrintMode ? "off" : "" }); 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)]; @@ -57,27 +61,22 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const errors = []; page.on("pageerror", (e) => errors.push(e.message)); const saved = []; - await page.route("**/*", serve(lang, saved)); - await watchSettingsReads(page); - await page.goto("http://magpie.test/?view=settings&tab=models"); - await settingsDrawn(page); // rows found are the ones that stay (#1659) - const row = page.locator("#replyList #claudeTuiRow"); - await row.waitFor(); - // scrolled to as a reader does, with the wheel: WebKit at 420 put - // back a scroll made from script - await page.mouse.move(width / 2, 450); - for (let i = 0; i < 40; i++) { - const box = await row.boundingBox(); - if (box && box.y >= 0 && box.y + box.height <= 900) break; - await page.mouse.wheel(0, 120); - await page.waitForTimeout(50); - } + // the app: the editor's own switch, not this row + await page.route("**/*", serve(lang, saved, false)); + await openProvPrefs(page, "claude"); + await page.locator(".editor .claude-mode .cc-pick").waitFor(); + assert.equal(await page.locator(".editor .prov-prefs #claudeRunList > #claudeTuiRow").count(), 1); + assert.equal(await page.locator(".editor .prov-prefs #claudeTuiRow").isVisible(), false, "the editor's own switch is the one shown"); + await page.unroute("**/*"); + + // magpie web as a gateway: the editor's switch is off, this row shows + await page.route("**/*", serve(lang, saved, true)); + await openProvPrefs(page, "claude"); + const row = page.locator(".editor .prov-prefs #claudeRunList > #claudeTuiRow"); + await inEditor(page, row); assert.equal(await row.locator(".name").textContent(), w.name); const sub = await row.locator(".sub").textContent(); assert(sub.includes(w.sub) && sub.includes(w.risk), sub); - // its explanation rests out of sight, shown whole in the row's hover card - // (settings-hints.test.cjs) - assert.equal(await row.locator(".sub").first().evaluate((e) => getComputedStyle(e).getPropertyValue("--hint").trim()), "1", "the explanation shows at rest"); for (const part of [".name", ".segs"]) { const fit = await row.locator(part).first().evaluate((e) => { const r = e.getBoundingClientRect(); @@ -85,7 +84,6 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", }); assert(fit, `${part} fits at ${width}`); } - assert.equal(await page.locator("#replyList").evaluate((l) => l.previousElementSibling.textContent.trim()), w.head); const seg = (text) => row.locator(".segs button", { hasText: new RegExp(`^${text}$`) }); const on = seg(w.on), off = seg(w.off); assert.equal(await row.locator(".segs button").count(), 2, "On and Off, nothing between"); @@ -106,7 +104,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual(await page.evaluate(() => [scrollX, scrollY, document.scrollingElement.scrollTop]), before, "the click moved nothing"); // the save draws the page again: the buttons are the new row's - await page.waitForFunction(() => { const r = document.querySelector("#replyList #claudeTuiRow"); return r && !r.dataset.drawn; }); + await page.waitForFunction(() => { const r = document.querySelector(".editor .prov-prefs #claudeTuiRow"); return r && !r.dataset.drawn; }); assert.equal(await seg(w.off).getAttribute("aria-pressed"), "true", "Off once saved"); await seg(w.on).click(); for (let i = 0; i < 50 && saved.length < 2; i++) await page.waitForTimeout(50); diff --git a/internal/gui/tests/provider-prefs.test.cjs b/internal/gui/tests/provider-prefs.test.cjs index a7482ff21..f39f2acb6 100644 --- a/internal/gui/tests/provider-prefs.test.cjs +++ b/internal/gui/tests/provider-prefs.test.cjs @@ -2,7 +2,8 @@ // The owner, 11-07: "这些配置难道不是应该在对应的Provider那个弹窗里面吗?为什么会散落在Settings里?" // A subscription's warm-up, daily check-in and Codex's auto-use resets are // in its provider's editor (PROV_PREFS), not in Settings › Allowances: -// Codex's has its resets and warm-up, Claude's its warm-up, WorkBuddy's its +// Codex's has its resets and warm-up, Claude's its warm-up and short +// system prompt, WorkBuddy's its // check-in, a plugin's that checks in itself its own row; Settings' search // still finds them, each a row that opens the editor. Chromium and WebKit, // at 1100 and 420, in every language; the API is faked here. @@ -85,6 +86,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await openProvPrefs(page, "claude"); assert.equal(await box.locator("#claudeWarmList").count(), 1, "Claude's warm-up"); + assert(await box.locator("#claudeRunList #claudeLeanRow").isVisible(), "Claude's short system prompt"); assert.equal(await box.locator("#codexWarmList, #codexResetList").count(), 0); await openProvPrefs(page, "workbuddy");