diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index ac9b264a9..f8c2b1864 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -2322,7 +2322,7 @@ function connectPanel(a, { fields, fieldBtn }) { for (const b of fields.querySelectorAll(":scope > .field")) { const f = a.fields.find((x) => x.key === b.dataset.key); if (f && !b.querySelector(":scope > .k")) b.prepend(el("span", "k", t(f.label))); - if (f?.key === "effort" && kindOf(a) === "claude") tierOwn(a, b); + if (f?.key === "effort" && kindOf(a) === "claude") { tierOwn(a, b); maxSaid(b, f.value); } } // Cursor Private Inference's are magpie's own (#1003) kv(t(a.id === "cursor-local" ? "Settings" : "New sessions"), line(fields)); @@ -4206,6 +4206,10 @@ const DESKTOP_TIERS_FOOT = "Claude Desktop reads the tiers as it starts: restart // it, since the agent's own field still has the old value. const ownSaid = (b, on, s) => b.title = b.title.replace(s = "\n" + t(s), "") + (on ? s : ""); const tierOwn = (a, b, f) => ownSaid(b, a.fields.some((x) => TIER_EFFORTS.includes(x.label) && (x.label === f?.label ? f.value : x.value)), "A tier with an effort of its own runs at that one"); +// Max is Claude Code's environment's (CLAUDE_CODE_EFFORT_LEVEL), which +// outranks /effort and /model's slider, so its title says so (@daix91 on X); +// s, when given, is the title's new first line (a pick in the slider) +const maxSaid = (b, v, s = b.title) => ownSaid(b, (b.title = s, v === "max"), "Max is fixed in Claude Code's environment, so /effort can't change it. Pick another level to get /effort back."); function tierSaid(b, v) { ownSaid(b, v, "Used whatever the session's effort or /effort is"); if (!v) b.querySelector(".v").textContent = t("follows session"); @@ -5127,6 +5131,9 @@ function renderEffortPicker() { for (const b of opened.anchor.closest(".row.agent").querySelectorAll('.field[data-key="effort"]')) tierOwn(opened.agent, b, opened.field); } opened.anchor.setAttribute("aria-label", opened.anchor.title); + } else if (opened.field.key === "effort" && kindOf(opened.agent) === "claude") { + // New sessions' effort: its first line names the level as fieldBtn does + maxSaid(opened.anchor, option.value, opened.anchor.title.replace(/^.*/, t("{label}: {value}", { label: t("effort"), value: option.value || t("agent default") }))); } else if (roleLevel(opened.field.label)) { const menu = tierMenu(opened.agent); if (menu) { diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index e181f5de2..3c7ee08f1 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -1135,6 +1135,7 @@ const I18N = { "the effort Claude Code asks for": "跟随 Claude Code 请求的推理强度", "Claude Desktop reads the tiers as it starts: restart it after a change.": "Claude Desktop 在启动时读取分档:改动后请重启它。", "follows session": "跟随会话", + "Max is fixed in Claude Code's environment, so /effort can't change it. Pick another level to get /effort back.": "“最高”写在 Claude Code 的环境变量里,/effort 改不了它。选其他强度即可恢复 /effort。", "Used whatever the session's effort or /effort is": "不受会话推理强度和 /effort 影响", "A tier with an effort of its own runs at that one": "设了自己推理强度的档位按它自己的运行", "Set a subagent model first": "先设置子代理模型", @@ -6656,6 +6657,7 @@ const I18N = { "the effort Claude Code asks for": "跟隨 Claude Code 請求的推理強度", "Claude Desktop reads the tiers as it starts: restart it after a change.": "Claude Desktop 在啟動時讀取分檔:改動後請重新啟動它。", "follows session": "跟隨會話", + "Max is fixed in Claude Code's environment, so /effort can't change it. Pick another level to get /effort back.": "「最高」寫在 Claude Code 的環境變數裡,/effort 改不了它。選其他強度即可恢復 /effort。", "Used whatever the session's effort or /effort is": "不受會話推理強度和 /effort 影響", "A tier with an effort of its own runs at that one": "設了自己推理強度的檔位按它自己的執行", "Set a subagent model first": "先設定子代理模型", @@ -12137,6 +12139,7 @@ const I18N = { "the effort Claude Code asks for": "Claude Code が要求する推論レベル", "Claude Desktop reads the tiers as it starts: restart it after a change.": "Claude Desktop は起動時に階層を読み込みます。変更したら再起動してください。", "follows session": "セッションに従う", + "Max is fixed in Claude Code's environment, so /effort can't change it. Pick another level to get /effort back.": "「最大」は Claude Code の環境変数で固定されるため、/effort では変更できません。別のレベルを選ぶと /effort が使えるようになります。", "Used whatever the session's effort or /effort is": "セッションの推論レベルや /effort に関係なくこのレベルを使います", "A tier with an effort of its own runs at that one": "独自の推論レベルを持つ階層はそのレベルで動きます", "Set a subagent model first": "先にサブエージェントのモデルを設定してください", @@ -17638,6 +17641,7 @@ const I18N = { "the effort Claude Code asks for": "der von Claude Code angeforderte Reasoning-Effort", "Claude Desktop reads the tiers as it starts: restart it after a change.": "Claude Desktop liest die Stufen beim Start: nach einer Änderung neu starten.", "follows session": "wie Sitzung", + "Max is fixed in Claude Code's environment, so /effort can't change it. Pick another level to get /effort back.": "Maximal ist in der Umgebung von Claude Code festgelegt, /effort kann es nicht ändern. Wähle eine andere Stufe, um /effort wieder zu nutzen.", "Used whatever the session's effort or /effort is": "Gilt unabhängig vom Reasoning-Effort der Sitzung und von /effort", "A tier with an effort of its own runs at that one": "Eine Stufe mit eigenem Reasoning-Effort läuft mit diesem", "Set a subagent model first": "Lege zuerst ein Modell für die Subagenten fest", diff --git a/internal/gui/tests/README.md b/internal/gui/tests/README.md index 181012212..8295cb2e9 100644 --- a/internal/gui/tests/README.md +++ b/internal/gui/tests/README.md @@ -550,6 +550,14 @@ named in the square's title, and the session's effort stays. Its subagents' effort is on the Subagents row, not a square, and a Claude Code not through magpie has no levels, no square and no effort entries. +`claude-effort-max.test.cjs` checks New sessions' effort in Claude Code's +Details set to max (@daix91 on X): its title ends with the line that max is +fixed in Claude Code's environment, so /effort can't change it, and nothing +new shows on the page; another level picked in the slider takes the line out +at once and in the row drawn again, and max picked puts it back. Chromium +and WebKit, five languages, 1100 and 560 wide, no sideways scroll; the API +is faked. Run with `node --test internal/gui/tests/claude-effort-max.test.cjs`. + `claude-subagent-effort-row.test.cjs` draws Claude Code's subagent effort in Chromium and WebKit, English and Chinese, at 1100px and 560px: it is at the right of the Subagents row in Tiers, laid out as the tiers' efforts are (same diff --git a/internal/gui/tests/claude-effort-max.test.cjs b/internal/gui/tests/claude-effort-max.test.cjs new file mode 100644 index 000000000..fc92d25ea --- /dev/null +++ b/internal/gui/tests/claude-effort-max.test.cjs @@ -0,0 +1,126 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Claude Code can't keep max in settings.json, so magpie puts it in Claude +// Code's environment (CLAUDE_CODE_EFFORT_LEVEL), which outranks /effort and +// /model's slider (@daix91 on X). With max set, New sessions' effort in the +// opened row says so in its title; another level picked takes the line away +// at once and in the row drawn again from the state, and max picked puts it back. The +// window, wide and narrow (no sideways scroll), in every language, +// Chromium and WebKit. No backend: the API is faked here. +const assert = require("node:assert/strict"); +const fs = require("node:fs/promises"); +const path = require("node:path"); +const { test } = require("node:test"); +const { chromium, webkit } = require("playwright"); + +const assets = path.resolve(__dirname, "../assets"); +const five = ["low", "medium", "high", "xhigh", "max"].map((value) => ({ value })); +const claude = () => ({ + id: "claude", name: "Claude Code", path: "/test/settings.json", icon: "claudecode-color", wired: true, + fields: [ + { key: "model", label: "model", value: "claude-opus-5-5", options: [{ value: "claude-opus-5-5", icon: "claude-color", ref: "claude/claude-opus-5-5" }] }, + { key: "effort", label: "effort", value: "max", options: five }, + ], +}); + +function server(lang, sets) { + let cur = { agents: [claude()], profiles: [] }; + return async (route) => { + const req = route.request(), url = new URL(req.url()); + 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 route.fulfill({ json: { ...cur, settings: { lang, theme: "light" } } }); + if (url.pathname === "/api/set") { + const body = req.postDataJSON(); + sets.push(body); + cur = JSON.parse(JSON.stringify(cur)); + cur.agents.find((a) => a.id === body.agent).fields.find((f) => f.key === body.field).value = body.value; + return route.fulfill({ json: { ...cur, settings: { lang, theme: "light" } } }); + } + if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] }); + if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } }); + if (url.pathname === "/api/agents/cli") return route.fulfill({ json: { agents: {}, pending: false } }); + if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } }); + if (url.pathname === "/api/plugins") return route.fulfill({ json: { plugins: [] } }); + if (url.pathname.startsWith("/api/")) return route.fulfill({ 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 }); + }; +} + +// the line as i18n.js has it +const MAX = { + en: "Max is fixed in Claude Code's environment, so /effort can't change it. Pick another level to get /effort back.", + zh: "“最高”写在 Claude Code 的环境变量里,/effort 改不了它。选其他强度即可恢复 /effort。", + "zh-TW": "「最高」寫在 Claude Code 的環境變數裡,/effort 改不了它。選其他強度即可恢復 /effort。", + ja: "「最大」は Claude Code の環境変数で固定されるため、/effort では変更できません。別のレベルを選ぶと /effort が使えるようになります。", + de: "Maximal ist in der Umgebung von Claude Code festgelegt, /effort kann es nicht ändern. Wähle eine andere Stufe, um /effort wieder zu nutzen.", +}; +const cc = '.row.agent[data-id="claude"]'; +// the slider's stop from its top: max is 0, high 2 (Default is its first) +const pickAt = (page, i) => page.locator("#effortRange").evaluate((r, i) => { + r.value = String(Number(r.max) - i); + r.dispatchEvent(new Event("input", { bubbles: true })); + r.dispatchEvent(new Event("change", { bubbles: true })); +}, i); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of Object.keys(MAX)) { + for (const width of [1100, 560]) { + test(`${engine} ${lang} ${width}px: Claude Code's max effort says /effort can't change it`, async (t) => { + const line = MAX[lang]; + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const page = await browser.newPage({ viewport: { width, height: 700 } }); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = [], sets = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", server(lang, sets)); + t.after(async () => { + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}-claude-effort-max.png`) }); + } + await browser.close(); + }); + await page.goto("http://magpie.test/"); + await page.locator(cc).waitFor(); + await page.locator(`${cc} .ag-link`).click(); + await page.locator(`${cc} .ag-exp`).waitFor(); + + const eff = page.locator(`${cc} .ag-exp .field[data-key="effort"]`); + const title = () => eff.getAttribute("title"); + // max: the line, once, as the title's last + assert.ok((await title()).endsWith("\n" + line), await title()); + assert.equal((await title()).split(line).length, 2); + // no new words on the page: the line is in the title only + assert.ok(!(await page.locator(cc).innerText()).includes(line)); + assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "the Agents view scrolls sideways"); + + // another level: the line goes at once, and stays gone in the row drawn again + await eff.click(); + await page.locator("#effortControl:not([hidden])").waitFor(); + await pickAt(page, 2); + assert.equal(await page.locator("#effortValue").textContent(), { en: "high", zh: "高", "zh-TW": "高", ja: "高", de: "hoch" }[lang] ?? null); + assert.ok(!(await title()).includes(line), await title()); + assert.ok((await title()).includes("high"), await title()); + await page.waitForFunction(() => document.querySelector("#status")?.textContent); + assert.deepEqual(sets, [{ agent: "claude", field: "effort", value: "high" }]); + await page.keyboard.press("Escape"); + await page.reload(); + await page.locator(`${cc} .ag-link`).click(); + await page.locator(`${cc} .ag-exp`).waitFor(); + assert.ok((await title()).includes("high"), await title()); + assert.ok(!(await title()).includes(line), await title()); + + // max again: the line is back + await eff.click(); + await page.locator("#effortControl:not([hidden])").waitFor(); + await pickAt(page, 0); + assert.ok((await title()).endsWith("\n" + line), await title()); + assert.equal((await title()).split(line).length, 2); + assert.deepEqual(errors, []); + }); + } + } +}