diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index d62418181..f8ec0207c 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -4005,19 +4005,14 @@ function openRowMenu(anchor, acts) { items[0]?.focus(NO_SCROLL); } -// Claude Code's opus/sonnet/haiku/fable can each have a model of their own -// once it runs through magpie. They share one button, which lists the four; -// picking one opens the model picker for it. +// Claude Code's tiers, each a model of its own, in one button const TIERS = ["opus", "sonnet", "haiku", "fable"]; // and each an effort of its own (#536), in the same menu, under its model const TIER_EFFORTS = TIERS.map((tier) => tier + " effort"); -// fields that fall back to the agent's model when unset: omp's smol and -// slow roles take the session's, as its subagents do ("smol", not "small": -// other agents' small model is a picker of its own) +// fields that fall back to the agent's model when unset ("smol", not +// "small", another agent's own picker) const FOLLOWS_MODEL = [...TIERS, "subagents", "smol", "slow"]; -// omp's roles share one square as Claude Code's tiers do (#1397), each -// with its level ("…:high") under its model; the roles after slow say -// what omp does when unset +// omp's roles share one square (#1397); unset, what omp does const OMP_UNSET = { plan: "omp's own pick", vision: "omp's own pick", advisor: "the slow role's model, else omp's own pick", commit: "the smol role's model", tiny: "the smol role's model", memory: "the tiny role's model, else the smol role's", @@ -4026,8 +4021,7 @@ const OMP_OWN_PICK = Object.keys(OMP_UNSET); const OMP_ROLES = ["subagents", "smol", "slow", ...OMP_OWN_PICK]; // omp, a named profile of it (omp#) or either in a WSL distro const ompAgent = (a) => kindOf(a).split("#")[0] === "omp"; -// the roles an agent's square lists, and whether a field is one of them or -// one of their levels +// the roles a square lists; a field one of their levels const menuRoles = (a) => ompAgent(a) ? OMP_ROLES : TIERS; const roleLevel = (label) => TIER_EFFORTS.includes(label) || OMP_ROLES.some((r) => label === r + " thinking"); const grouped = (a, f) => menuRoles(a).includes(f.label) || roleLevel(f.label); @@ -4037,20 +4031,12 @@ const ROLE_MODELS = [...FOLLOWS_MODEL, ...OMP_OWN_PICK]; // to them (#709) const PICKS_ITSELF = ["pi", "omo", "prime-agent", "mu"]; -// A field that follows the model unless set — Codex's subagents, Claude -// Code's tiers, omp's roles — is a small square after the pickers rather -// than a third picker, which a row has no room for: it wrapped onto a line -// of its own. So is Codex's sign-in, ChatGPT or magpie as its provider, -// and the effort its subagents start at (#469), and the model Codex writes -// its memories with (Yc on Discord). +// A field that follows the model unless set is a small square after the +// pickers, which a row has no room for (#469, Yc on Discord). const SUB_EFFORT = "subagent effort"; const MEMORIES = "memories"; -// the model magpie puts every Codex subagent on, whatever its lead asked -// for (willz on Discord): any model magpie serves (#1633); a subagent -// whose task a ChatGPT-backed lead sealed stays on its own unless the one -// set is a ChatGPT account's, the Routing page saying why. Claude -// Desktop's subagent model is the same square: the gateway puts each of -// its subagents' turns on it +// the model magpie puts every Codex (or Claude Desktop) subagent on, +// whatever its lead asked for (willz on Discord, #1633) const SUB_MODEL = "subagent model"; // Claude Code's auto mode square: the model its client-side auto mode // classifier runs on (CLAUDE_CODE_AUTO_MODE_MODEL); unset, Claude Code's own @@ -4079,10 +4065,8 @@ const codexOwnSub = (a, f) => f.label === "subagents" && codexSub(a); // named rows in Codex's settings: no square too (the owner, 10-25) const hermesBot = (f) => f.key.startsWith("profile:"); const codexRowed = (a, f) => a.id === "codex" && !gatewayMode && (f.label === SUB_MODEL || f.label === MEMORIES); -// Lead's pick ("") leaves each subagent on the model the lead names for it, -// one of Codex's own as well; Same as the lead (CODEX_SUB_LEAD) holds every -// subagent to the lead's own model, whatever it names (cleverpigo on X: a -// lead on DeepSeek named gpt-5.6-sol under what read "same as the lead") +// Lead's pick ("") takes the model the lead names; Same as the lead holds +// every subagent to the lead's own (cleverpigo on X) const CODEX_SUB_LEAD = "lead"; const LEADS_PICK = "Lead's pick"; const SAME_AS_LEAD = "Same as the lead"; @@ -4141,7 +4125,11 @@ function extraField(a, f) { : t("{label}: {value}", { label: f.label === MEMORIES ? t("Codex memories model") : t(f.label), value: t(opt?.label || f.value || (f.label === MEMORIES ? MEMORIES_DEFAULT : f.label === SUB_MODEL ? "the model the lead asks for" : f.label === AUTO_MODE ? AUTO_MODE_UNSET : f.label === COMPACT_MODEL ? COMPACT_UNSET : leadPicks(a, f) ? "the lead's pick, else same as model" : "same as model")) }) + (opt?.note && !FOLLOWS_MODEL.includes(f.label) ? "\n" + t(opt.note) : "") + (leadPicks(a, f) ? "\n" + t(claudePicks(a, f) ? CLAUDE_PICKS : LEAD_PICKS) : ""); b.setAttribute("aria-label", b.title); b.dataset.key = f.key; - b.onclick = (ev) => openPicker(a, f, b, ev); + // the menu as the state is now + b.onclick = (ev) => { + const now = f.key === "tiers" && state.agents.find((x) => x.id === a.id); + openPicker(now || a, (now && tierMenu(now)) || f, b, ev); + }; return b; } @@ -4229,12 +4217,13 @@ function tierMenu(a) { foot: a.id === "claude-desktop" ? DESKTOP_TIERS_FOOT : "", summary: custom.length ? custom.map((f) => level(effortOf(f)) ? `${t(f.label)} (${level(effortOf(f))})` : t(f.label)).join(", ") : main ? t("same as model") : t("not set"), options: tiers.flatMap((f) => { + const e = effortOf(f); + // an omp role: one line, its level picked after its model (hongzaitou on X) const model = { value: f.key, label: t(f.label), icon: optionFor(f, f.value)?.icon || (main && optionFor(main, main.value)?.icon), - note: f.value ? name(f) : unset(f), + note: (f.value ? name(f) : unset(f)) + (omp && level(e) ? " · " + level(e) : ""), }; - const e = effortOf(f); - return e ? [model, { value: e.key, label: t(e.label), effortOf: e, note: level(e) || levelUnset(a) }] : [model]; + return e && !omp ? [model, { value: e.key, label: t(e.label), effortOf: e, note: level(e) || levelUnset(a) }] : [model]; }), }; } @@ -5682,7 +5671,7 @@ function move(d) { async function commit(value) { if (!pick || value == null) return; - const { agent, field, anchor } = pick; + const { agent, field, anchor, levelNext } = pick; const opt = pick.options.find((o) => o.value === value); if (field.multi && !opt?.run) { // a picker that takes several (a group's models, PAMI on Discord) @@ -5698,11 +5687,16 @@ async function commit(value) { if (opt?.run) return opt.run(); // an act rather than a value (Disconnect from magpie) if (field.onPick) return field.onPick(value, opt); // a picker opened for something other than an agent's setting if (field.menu) { - // a tier chosen from the tiers menu: now its model + // a tier chosen: its model, then an omp role's level const tier = agent.fields.find((f) => f.key === value); if (tier) openPicker(agent, tier, anchor, { stopPropagation() {} }); + if (tier && pick && ompAgent(agent)) pick.levelNext = true; return; } + if (levelNext) { + const write = value === field.value ? null : setPick(agent, field, value, opt); + return Promise.resolve(write).then(() => roleLevelStep(agent.id, field.key, anchor)); + } if (value === field.value && (value || field.label !== SUB_MODEL || !codexSubSaid(agent, field).old)) return; if (agent.native) return setPick(agent, field, value, opt); // a pick that takes a connected agent off magpie (its Default, or a @@ -5713,6 +5707,16 @@ async function commit(value) { return setPick(agent, field, value, opt); } +// roleLevelStep: an omp role's level, once it is on a model +function roleLevelStep(id, key, anchor) { + const a = state.agents.find((x) => x.id === id); + const lf = a?.fields.find((f) => f.key === key + "_thinking"); + const role = a?.fields.find((f) => f.key === key); + if (!lf?.options.length || !role?.value || pick) return; + const at = anchor.isConnected ? anchor : document.querySelector(`.agent[data-id="${CSS.escape(id)}"] .field[data-key="tiers"]`); + if (at) openPicker(a, lf, at, { stopPropagation() {} }); +} + // asideAccount: Aside's account field, which of its accounts (~/.aside/u/N) // magpie configures; empty follows the one Aside has active (#1499) function asideAccount(a, f) { diff --git a/internal/gui/tests/omp-roles.test.cjs b/internal/gui/tests/omp-roles.test.cjs index 96769a93d..e04fbb658 100644 --- a/internal/gui/tests/omp-roles.test.cjs +++ b/internal/gui/tests/omp-roles.test.cjs @@ -1,14 +1,16 @@ // Run with Node's test runner and Playwright on the module path; see README.md. // omp's roles share one square after the model picker, as Claude Code's // tiers do (#325, #1397): subagents, smol, slow, plan, vision, advisor, -// commit, tiny and memory (every chat role omp 18.8 has), each with the model it is on or what it takes unset, and a role on one -// model has its thinking level under it (KKKKKKKEM: the slow role at its -// own level). Picking a role opens the model picker for it, "Same as model" -// first for a role that follows the model; picking its level opens the -// level slider, which writes that role's level. OpenCode's small model, +// commit, tiny and memory (every chat role omp 18.8 has), each one line +// with the model it is on, "· level" after it once a level is set +// (KKKKKKKEM: the slow role at its own level), or what it takes unset. +// Picking a role opens the model picker for it, "Same as model" first for +// a role that follows the model; a model picked, the level slider comes +// next and writes that role's level (hongzaitou on X: no line of its own +// for the level). OpenCode's small model, // which doesn't follow the model, stays a picker; a named profile of omp // (omp#work) has the same square. In the connected agent's -// opened row, in English, Chinese, Japanese and German, wide and at 390px. +// opened row, in English, both Chinese, Japanese and German, wide and at 390px. // No backend: the API is faked here. const assert = require("node:assert/strict"); const fs = require("node:fs/promises"); @@ -83,26 +85,32 @@ function server(lang, sets) { // the words as i18n.js has them const W = { en: { - roles: ["subagents", "smol", "slow", "slow thinking", "plan", "vision", "advisor", "commit", "tiny", "memory"], + roles: ["subagents", "smol", "slow", "plan", "vision", "advisor", "commit", "tiny", "memory"], follows: "same as model (DeepSeek Pro)", own: "omp's own pick", advisor: "the slow role's model, else omp's own pick", smol: "the smol role's model", memory: "the tiny role's model, else the smol role's", - session: "the session's thinking level", same: "Same as model", summary: "roles: slow", high: "high", summarySet: "roles: slow (high)", + level: "slow thinking", smolLevel: "smol thinking", same: "Same as model", summary: "roles: slow", high: "high", summarySet: "roles: slow (high)", }, zh: { - roles: ["子代理", "小模型", "慢模型", "慢模型思考", "规划", "视觉", "顾问", "提交", "微模型", "记忆"], + roles: ["子代理", "小模型", "慢模型", "规划", "视觉", "顾问", "提交", "微模型", "记忆"], follows: "同主模型(DeepSeek Pro)", own: "由 omp 自己挑选", advisor: "慢模型角色的模型,未设置时由 omp 自己挑选", smol: "小模型角色的模型", memory: "微模型角色的模型,未设置时用小模型角色的", - session: "跟随会话的思考强度", same: "同主模型", summary: "角色:慢模型", high: "高", summarySet: "角色:慢模型 (高)", + level: "慢模型思考", smolLevel: "小模型思考", same: "同主模型", summary: "角色:慢模型", high: "高", summarySet: "角色:慢模型 (高)", + }, + "zh-TW": { + summary: "角色:慢模型", + roles: ["子代理", "小模型", "慢模型", "規劃", "視覺", "顧問", "提交", "微模型", "記憶"], + own: "由 omp 自己挑選", advisor: "慢模型角色的模型,未設定時由 omp 自己挑選", + smol: "小模型角色的模型", memory: "微模型角色的模型,未設定時用小模型角色的", }, ja: { summary: "ロール:低速", - roles: ["サブエージェント", "小", "低速", "低速の思考", "プラン", "ビジョン", "アドバイザー", "コミット", "極小", "メモリー"], + roles: ["サブエージェント", "小", "低速", "プラン", "ビジョン", "アドバイザー", "コミット", "極小", "メモリー"], own: "omp が自分で選ぶ", advisor: "slow ロールのモデル、未設定なら omp が自分で選ぶ", smol: "smol ロールのモデル", memory: "tiny ロールのモデル、未設定なら smol ロールのモデル", }, de: { summary: "Rollen: langsam", - roles: ["Subagenten", "klein (smol)", "langsam", "Thinking langsam", "Planung", "Vision", "Berater", "Commit", "winzig (tiny)", "Gedächtnis"], + roles: ["Subagenten", "klein (smol)", "langsam", "Planung", "Vision", "Berater", "Commit", "winzig (tiny)", "Gedächtnis"], own: "wählt omp selbst", advisor: "das Modell der Rolle slow, sonst wählt omp selbst", smol: "das Modell der Rolle smol", memory: "das Modell der Rolle tiny, sonst das der Rolle smol", }, @@ -112,7 +120,7 @@ const omp = '.row.agent[data-id="omp"]'; const items = (page) => page.locator("#pop:not([hidden]) #list li").evaluateAll((es) => es.map((e) => [e.querySelector(".v")?.textContent, e.querySelector(".n")?.textContent || ""])); for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { - for (const width of [1100, 390]) for (const lang of ["en", "zh", "ja", "de"]) { + for (const width of [1100, 390]) for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) { test(`${engine} ${lang} ${width}px: omp's roles and their thinking levels are one square, OpenCode's small model is a picker`, async (t) => { const w = W[lang]; const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); @@ -144,17 +152,17 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "the row scrolls sideways"); const y = await page.evaluate(() => scrollY); - // each role, with its model or what it takes unset; slow's level under it + // each role one line, with its model or what it takes unset await square.click(); await page.locator("#pop:not([hidden]) #list li").first().waitFor(); const rows = await items(page); assert.deepEqual(rows.map((r) => r[0]), w.roles); - assert.deepEqual(rows.slice(4).map((r) => r[1]), [w.own, w.own, w.advisor, w.smol, w.smol, w.memory]); + assert.deepEqual(rows.slice(3).map((r) => r[1]), [w.own, w.own, w.advisor, w.smol, w.smol, w.memory]); // commit's picker: Default says what omp takes unset, the smol // role's model, and no "Same as model" const commitPicker = async () => { if (!(await page.locator("#pop:not([hidden]) #list li").count())) await square.click(); - const at = (await items(page)).findIndex((r) => r[0] === w.roles[7]); + const at = (await items(page)).findIndex((r) => r[0] === w.roles[6]); await page.locator("#pop:not([hidden]) #list li").nth(at).click(); await page.locator("#pop:not([hidden]) #list li", { hasText: "DeepSeek Flash" }).first().waitFor(); const top = await page.locator("#pop:not([hidden]) #list li").first().innerText(); @@ -169,34 +177,55 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.deepEqual(errors, []); return; } - assert.deepEqual(rows.slice(0, 4).map((r) => r[1]), [w.follows, w.follows, "DeepSeek Flash", w.session]); + assert.deepEqual(rows.slice(0, 3).map((r) => r[1]), [w.follows, w.follows, "DeepSeek Flash"]); + assert.equal(await page.locator("#pop:not([hidden]) #effortControl:not([hidden])").count(), 0); - // slow's level: the slider, which writes slow_thinking - await page.locator("#pop:not([hidden]) #list li").nth(3).click(); - const range = page.locator("#effortRange"); - await range.waitFor({ state: "attached" }); - await page.waitForFunction(() => document.querySelector("#effortRange")?.offsetParent); - const at = await page.evaluate(() => Number(document.querySelector("#effortRange").max)); - const high = LEVELS.findIndex((l) => l.value === "high") + (at === LEVELS.length ? 1 : 0); - await range.evaluate((r, i) => { r.value = String(i); r.dispatchEvent(new Event("input", { bubbles: true })); r.dispatchEvent(new Event("change", { bubbles: true })); }, high); + // the level slider, opened as the model's next step: it writes the role's level + const levelStep = async (title, value) => { + await page.waitForFunction(() => document.querySelector("#effortRange")?.offsetParent); + assert.equal(await page.locator("#effortTitle").textContent(), title); + const at = await page.evaluate(() => Number(document.querySelector("#effortRange").max)); + const i = LEVELS.findIndex((l) => l.value === value) + (at === LEVELS.length ? 1 : 0); + await page.locator("#effortRange").evaluate((r, i) => { r.value = String(i); r.dispatchEvent(new Event("input", { bubbles: true })); r.dispatchEvent(new Event("change", { bubbles: true })); }, i); + }; + + // slow: its model picked again (no write), then its level + await page.locator("#pop:not([hidden]) #list li").nth(2).click(); + await page.locator("#pop:not([hidden]) #list li", { hasText: "DeepSeek Flash" }).first().click(); + await levelStep(w.level, "high"); await page.waitForFunction(() => document.querySelector("#status")?.textContent); assert.deepEqual(sets, [{ agent: "omp", field: "slow_thinking", value: "high" }]); await page.keyboard.press("Escape"); await page.waitForFunction((s) => document.querySelector('.row.agent[data-id="omp"] .field.extra[data-key="tiers"]')?.getAttribute("aria-label").startsWith(s), w.summarySet); - - // smol: the model picker, following the model first + // and its line says both await square.click(); + await page.locator("#pop:not([hidden]) #list li").first().waitFor(); + assert.deepEqual((await items(page))[2], [w.roles[2], "DeepSeek Flash · " + w.high]); + assert.equal((await items(page)).length, w.roles.length, "a level kept a line of its own"); + + // smol: the model picker, following the model first; a model picked, its level next await page.locator("#pop:not([hidden]) #list li").nth(1).click(); await page.locator("#pop:not([hidden]) #list li", { hasText: "DeepSeek Flash" }).first().waitFor(); assert.match(await page.locator("#pop:not([hidden]) #list li").first().innerText(), new RegExp(`${w.same}[\\s\\S]*DeepSeek Pro`)); await page.locator("#pop:not([hidden]) #list li", { hasText: "DeepSeek Flash" }).first().click(); - await page.waitForFunction(() => document.querySelectorAll("#status").length && !document.querySelector("#pop:not([hidden])")); - assert.deepEqual(sets[1], { agent: "omp", field: "small", value: "magpie/deepseek/flash" }); + await levelStep(w.smolLevel, "low"); + for (let i = 0; sets.length < 3 && i < 100; i++) await page.waitForTimeout(50); + await page.keyboard.press("Escape"); + assert.deepEqual(sets.slice(1), [{ agent: "omp", field: "small", value: "magpie/deepseek/flash" }, { agent: "omp", field: "small_thinking", value: "low" }]); + + // Same as model: nothing to pick a level for, so no level step + await square.click(); + await page.locator("#pop:not([hidden]) #list li").nth(1).click(); + await page.locator("#pop:not([hidden]) #list li", { hasText: w.same }).first().click(); + await page.waitForFunction((same) => document.querySelector("#status")?.textContent.includes(same), w.same); + await page.evaluate(() => new Promise(requestAnimationFrame)); + assert.deepEqual(sets[3], { agent: "omp", field: "small", value: "" }); + assert.equal(await page.locator("#pop:not([hidden])").count(), 0, "a level step for a role on no model of its own"); // plan: no "Same as model", omp picks unset await square.click(); await page.locator("#pop:not([hidden]) #list li").first().waitFor(); - const planAt = (await items(page)).findIndex((r) => r[0] === w.roles[4]); + const planAt = (await items(page)).findIndex((r) => r[0] === w.roles[3]); await page.locator("#pop:not([hidden]) #list li").nth(planAt).click(); await page.locator("#pop:not([hidden]) #list li", { hasText: "DeepSeek Flash" }).first().waitFor(); const first = await page.locator("#pop:not([hidden]) #list li").first().innerText();