diff --git a/internal/agent/claude.go b/internal/agent/claude.go index fb78df9a5..2e1b89960 100644 --- a/internal/agent/claude.go +++ b/internal/agent/claude.go @@ -288,6 +288,29 @@ func claudeIn(at place) *Agent { // what was last written that an open Claude Code session doesn't see: // it reads settings.json at start-up, only its env as it goes stale := "" + // the model a subagent runs on when neither its definition nor the + // call names one, if the user gave it one of its own: Claude Code + // takes the Agent call's model, then the agent's frontmatter, then + // CLAUDE_CODE_SUBAGENT_MODEL, then the session's (2.1.287). Empty + // while it follows the main model, as magpie writes it by itself. + subagentOwn := func() string { + if w := env("CLAUDE_CODE_SUBAGENT_MODEL"); routed() && w != env("ANTHROPIC_MODEL") && isMagpie(w) { + return w + } + return "" + } + // the main model and each tier's, one that has none on the main one + curTiers := func() (string, map[string]string) { + main := env("ANTHROPIC_MODEL") + tiers := map[string]string{} + for _, t := range claudeTiers { + tiers[t] = env(tierEnv(t)) + if tiers[t] == "" { + tiers[t] = main + } + } + return main, tiers + } var writeTiers func(main string, tiers map[string]string) error set := func(v string) error { if v == "" { @@ -385,7 +408,10 @@ func claudeIn(at place) *Agent { kvs = append(kvs, edit.KV{Path: "env." + tierEnv(t), Value: tiers[t]}) same = same && tiers[t] == main } - if !same { + // subagents given a model of their own keep it + if sub := subagentOwn(); sub != "" { + kvs = append(kvs, edit.KV{Path: "env.CLAUDE_CODE_SUBAGENT_MODEL", Value: mark(sub)}) + } else if !same { // one model for every subagent would override the tiers they ask for if err := edit.DelJSON(path, "env.CLAUDE_CODE_SUBAGENT_MODEL"); err != nil { return err @@ -565,14 +591,7 @@ func claudeIn(at place) *Agent { if v != "" && !isMagpie(v) { return fmt.Errorf("%s: %q is not a model magpie serves", tier, v) } - main := env("ANTHROPIC_MODEL") - tiers := map[string]string{} - for _, t := range claudeTiers { - tiers[t] = env(tierEnv(t)) - if tiers[t] == "" { - tiers[t] = main - } - } + main, tiers := curTiers() tiers[tier] = v if v == "" { tiers[tier] = main @@ -587,6 +606,38 @@ func claudeIn(at place) *Agent { }, }) } + // subagents: the model one runs on when it names none (general-purpose, + // an agent of the user's without a model:). Unset, the session's, as + // before; an agent that names a tier (Explore's haiku) takes the tier's. + fields = append(fields, Field{ + Key: "subagent", Label: "subagents", Quiet: true, + Get: subagentOwn, + Set: func(v string) error { + if !routed() { + if v == "" { + return nil + } + return fmt.Errorf("pick a model through magpie for Claude Code first; its subagents can then have one of their own") + } + if v != "" && !isMagpie(v) { + return fmt.Errorf("subagents: %q is not a model magpie serves", v) + } + if v == "" { + if err := edit.DelJSON(path, "env.CLAUDE_CODE_SUBAGENT_MODEL"); err != nil { + return err + } + } else if err := edit.SetJSON(path, edit.KV{Path: "env.CLAUDE_CODE_SUBAGENT_MODEL", Value: v}); err != nil { + return err + } + return writeTiers(curTiers()) + }, + Options: func(map[string]string) []Option { + if !routed() { + return nil + } + return claudeViaMagpie() + }, + }) return &Agent{ ID: "claude", Name: "Claude Code", Icon: "claudecode-color", Aliases: []string{"cc", "claude-code"}, diff --git a/internal/agent/claude_test.go b/internal/agent/claude_test.go index 8d1e50ea9..a22eb1b40 100644 --- a/internal/agent/claude_test.go +++ b/internal/agent/claude_test.go @@ -74,6 +74,70 @@ func TestClaudeTiers(t *testing.T) { } } +// Claude Code's subagents can have a model of their own (#468): +// CLAUDE_CODE_SUBAGENT_MODEL, the model a subagent runs on when neither the +// call nor its definition names one. Unset, magpie writes it as before; +// set, it outlives a tier of its own and a new main model. +func TestClaudeSubagentModel(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + if err := provider.Save(provider.Provider{ID: "deepseek", Name: "DeepSeek", Chat: "https://api.deepseek.com/v1", Key: "k", Models: []string{"pro", "flash", "lite"}}); err != nil { + t.Fatal(err) + } + path := filepath.Join(home, ".claude", "settings.json") + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(path, []byte(`{}`), 0o644); err != nil { + t.Fatal(err) + } + a := claude(home) + sub := a.Field("subagent") + if sub == nil { + t.Fatal("no subagent field") + } + env := func(k string) string { v, _ := edit.GetJSON(path, "env."+k); return v } + if err := sub.Set("deepseek/flash"); err == nil { + t.Fatal("a subagent model before Claude Code is routed should fail") + } + if err := a.Field("model").Set("deepseek/pro"); err != nil { + t.Fatal(err) + } + if sub.Get() != "" || env("CLAUDE_CODE_SUBAGENT_MODEL") != "deepseek/pro" { + t.Fatalf("subagents should follow the model: %v", a.Values()) + } + if err := sub.Set("deepseek/flash"); err != nil { + t.Fatal(err) + } + if sub.Get() != "deepseek/flash" || env("CLAUDE_CODE_SUBAGENT_MODEL") != "deepseek/flash" || env("ANTHROPIC_DEFAULT_HAIKU_MODEL") != "deepseek/pro" { + t.Fatalf("subagents: %v", a.Values()) + } + if err := a.Field("haiku").Set("deepseek/lite"); err != nil { + t.Fatal(err) + } + if err := a.Field("model").Set("deepseek/lite"); err != nil { + t.Fatal(err) + } + if env("CLAUDE_CODE_SUBAGENT_MODEL") != "deepseek/flash" || env("ANTHROPIC_MODEL") != "deepseek/lite" { + t.Fatalf("own subagent model lost: %v", a.Values()) + } + if err := sub.Set(""); err != nil { + t.Fatal(err) + } + if sub.Get() != "" || env("CLAUDE_CODE_SUBAGENT_MODEL") != "deepseek/lite" { + t.Fatalf("back to the model: %v", a.Values()) + } + if err := a.Field("model").Set(""); err != nil { + t.Fatal(err) + } + if env("CLAUDE_CODE_SUBAGENT_MODEL") != "" { + t.Fatal("reset left the subagent model behind") + } +} + // Claude Code's settings keep an effort up to xhigh; max is its // CLAUDE_CODE_EFFORT_LEVEL, which another level takes away again. func TestClaudeEffortMax(t *testing.T) { diff --git a/internal/agent/codex.go b/internal/agent/codex.go index 0ce407259..ba9b99d56 100644 --- a/internal/agent/codex.go +++ b/internal/agent/codex.go @@ -84,6 +84,7 @@ func codexIn(at place) *Agent { } return catalog.Codex() } + var dropSubEffort func() error // keep the effort valid for the model; a fresh model gets its default. // Routed, the Codex app offers magpie's models' efforts too (#310). settle := func() error { @@ -95,9 +96,11 @@ func codexIn(at place) *Agent { ms := models() model, effort := get("model"), get("model_reasoning_effort") if e := catalog.Efforts(ms, model); len(e) > 0 && !contains(e, effort) { - return edit.SetTOMLTop(path, edit.KV{Path: "model_reasoning_effort", Value: codexcat.DefaultEffort(e)}) + if err := edit.SetTOMLTop(path, edit.KV{Path: "model_reasoning_effort", Value: codexcat.DefaultEffort(e)}); err != nil { + return err + } } - return nil + return dropSubEffort() } // magpie as a provider Codex can name; its threads started on magpie do putProvider := func() error { @@ -217,6 +220,31 @@ func codexIn(at place) *Agent { } return edit.DelTOMLKey(path, "agents", "default_subagent_model") } + // the effort spawned subagents start at, when not the parent's + // (core/src/agent/child_config.rs): checked against the model they run + // on, theirs or the parent's, and a spawn at one it lacks fails, so one + // that model doesn't take goes + subEffort := func() (string, error) { + agents, err := edit.GetTOMLTable(path, "agents") + return agents["default_subagent_reasoning_effort"], err + } + subModel := func() string { + if m, _ := subagent(); m != "" { + return m + } + return get("model") + } + subEfforts := func() []string { return catalog.Efforts(models(), subModel()) } + dropSubEffort = func() error { + e, err := subEffort() + if err != nil || e == "" { + return err + } + if l := subEfforts(); len(l) > 0 && !contains(l, e) { + return edit.DelTOMLKey(path, "agents", "default_subagent_reasoning_effort") + } + return nil + } // Codex on one of its own models goes through magpie too while more of // its ChatGPT accounts are on there, so one out of its allowance hands // the turn to the next; with none, it goes straight to OpenAI again @@ -527,10 +555,35 @@ func codexIn(at place) *Agent { if isMagpie(v) && !routed() { return fmt.Errorf("pick a model through magpie for Codex first; its subagents can then have one of their own") } - return edit.SetTOMLKey(path, "agents", "default_subagent_model", v) + if err := edit.SetTOMLKey(path, "agents", "default_subagent_model", v); err != nil { + return err + } + return dropSubEffort() }, Options: func(map[string]string) []Option { return modelOptions(routed()) }, }, + { + // [agents] default_subagent_reasoning_effort: unset, a + // subagent runs at the session's effort, or at its model's + // default when it has a model of its own + Key: "subagent_effort", Label: "subagent effort", Quiet: true, + Get: func() string { v, _ := subEffort(); return v }, + Set: func(v string) error { + if v == "" { + return edit.DelTOMLKey(path, "agents", "default_subagent_reasoning_effort") + } + if l := subEfforts(); len(l) > 0 && !contains(l, v) { + return fmt.Errorf("Codex runs %s at %s, not %q: it would refuse to start a subagent", subModel(), strings.Join(l, ", "), v) + } + return edit.SetTOMLKey(path, "agents", "default_subagent_reasoning_effort", v) + }, + Options: func(map[string]string) []Option { + if e := subEfforts(); len(e) > 0 { + return static(e...) + } + return static("low", "medium", "high", "xhigh") + }, + }, { // how Codex takes magpie's models: beside its ChatGPT // sign-in (openai_base_url), or with magpie as its provider, diff --git a/internal/agent/codex_route_test.go b/internal/agent/codex_route_test.go index 9f5307ab9..a95b6637c 100644 --- a/internal/agent/codex_route_test.go +++ b/internal/agent/codex_route_test.go @@ -209,6 +209,57 @@ func TestCodexSubagentModel(t *testing.T) { } } +// Subagents can start at an effort of their own (#469): Codex's [agents] +// default_subagent_reasoning_effort, used when a spawn names none. Codex +// refuses a spawn at a level the subagents' model lacks, so magpie takes +// only one it has, and drops one a new subagent model doesn't. +func TestCodexSubagentEffort(t *testing.T) { + home, read := codexHome(t, "", "model = \"gpt-a\"\n\n[agents]\nmax_threads = 6\n") + os.WriteFile(filepath.Join(home, ".codex", "models_cache.json"), []byte(`{"models":[ + {"slug":"gpt-a","display_name":"A","priority":1,"supported_reasoning_levels":[{"effort":"low"},{"effort":"medium"},{"effort":"high"},{"effort":"xhigh"}]}, + {"slug":"gpt-mini","display_name":"Mini","priority":2,"supported_reasoning_levels":[{"effort":"low"},{"effort":"medium"}]}]}`), 0o644) + cx := codex(home) + eff := cx.Field("subagent_effort") + if eff == nil { + t.Fatal("no subagent effort field") + } + if eff.Get() != "" { + t.Fatalf("unset effort = %q", eff.Get()) + } + if err := eff.Set("xhigh"); err != nil { + t.Fatal(err) + } + if cfg := read(); !strings.Contains(cfg, `default_subagent_reasoning_effort = "xhigh"`) || !strings.Contains(cfg, "max_threads = 6") { + t.Fatalf("\n%s", cfg) + } + // on a model that stops at medium, xhigh would fail every spawn + if err := cx.Field("subagent").Set("gpt-mini"); err != nil { + t.Fatal(err) + } + if got := eff.Get(); got != "" { + t.Fatalf("effort the subagent model lacks kept: %q\n%s", got, read()) + } + if err := eff.Set("high"); err == nil { + t.Error("an effort gpt-mini lacks was taken") + } + var levels []string + for _, o := range eff.Options(nil) { + levels = append(levels, o.Value) + } + if strings.Join(levels, ",") != "low,medium" { + t.Fatalf("options = %v", levels) + } + if err := eff.Set("low"); err != nil { + t.Fatal(err) + } + if err := eff.Set(""); err != nil { + t.Fatal(err) + } + if cfg := read(); strings.Contains(cfg, "default_subagent_reasoning_effort") || !strings.Contains(cfg, `default_subagent_model = "gpt-mini"`) { + t.Fatalf("\n%s", cfg) + } +} + func TestCodexSubagentReadErrorStopsChanges(t *testing.T) { const input = "model = \"fake/m1\"\nmodel_provider = \"magpie\"\n\n[agents]\ndefault_subagent_model = [\n" for _, model := range []string{"", "gpt-native"} { diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 437a92103..477662d28 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -1265,8 +1265,10 @@ const FOLLOWS_MODEL = [...TIERS, "subagents", "smol", "slow"]; // 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. -const extra = (f) => f.key === "tiers" || FOLLOWS_MODEL.includes(f.label) || f.label === "sign-in" || f.key === "ultracode"; +// of its own. So is Codex's sign-in, ChatGPT or magpie as its provider, +// and the effort its subagents start at (#469). +const SUB_EFFORT = "subagent effort"; +const extra = (f) => f.key === "tiers" || FOLLOWS_MODEL.includes(f.label) || f.label === "sign-in" || f.key === "ultracode" || f.label === SUB_EFFORT; const EXTRA_GLYPH = { subagents: "M4.5 2.75v10.5M4.5 9.25c0-2.2 1.6-3.75 3.9-3.75h3.35M9.9 3.6l1.9 1.9-1.9 1.9", // a feather for omp's smol role, an hourglass for its slow one @@ -1275,6 +1277,8 @@ const EXTRA_GLYPH = { tiers: "M8 2.6 2.75 5.4 8 8.2l5.25-2.8zM2.75 8.1 8 10.9l5.25-2.8M2.75 10.8 8 13.6l5.25-2.8", "sign-in": "M8 2.5a2.75 2.75 0 1 1 0 5.5 2.75 2.75 0 0 1 0-5.5zM3 13.5c.4-2.4 2.4-3.9 5-3.9s4.6 1.5 5 3.9", ultracode: "M3 4.25h4M3 8h2.5M3 11.75h4M9.5 4.25l3.5 3.75-3.5 3.75", + // the subagents' branch, with effort's rising bars after it + [SUB_EFFORT]: "M3.25 2.75v10.5M3.25 9.25c0-2.2 1.6-3.75 3.9-3.75h.6M9.25 13.25v-2M11.5 13.25v-4M13.75 13.25v-6", }; function extraField(a, f) { if (f.key === "ultracode") return ultracodeToggle(a, f); @@ -1282,7 +1286,7 @@ function extraField(a, f) { const b = el("button", "field extra" + (set ? " set" : "")); b.append(svg(EXTRA_GLYPH[f.label] || EXTRA_GLYPH.tiers, 13, 1.5)); const opt = optionFor(f, f.value); - b.title = f.menu + b.title = f.label === SUB_EFFORT ? subEffortTitle(f, opt) : f.menu ? t("{label}: {value}", { label: t(f.label), value: f.summary }) + "\n" + f.options.map((o) => `${o.label}: ${o.note}`).join("\n") : t("{label}: {value}", { label: t(f.label), value: t(opt?.label || f.value || "same as model") }) + (opt?.note && !FOLLOWS_MODEL.includes(f.label) ? "\n" + t(opt.note) : ""); b.setAttribute("aria-label", b.title); @@ -1291,6 +1295,14 @@ function extraField(a, f) { return b; } +// subEffortTitle: the effort subagents start at, and unset, what that means: +// Codex runs one at the session's effort, or, given a model of its own, at +// that model's default +function subEffortTitle(f, opt) { + return t("{label}: {value}", { label: t(f.label), value: effortName(opt || { value: f.value }) }) + + (f.value ? "" : "\n" + t("the session's effort, or the subagent model's own default")); +} + // launchButton copies the command that starts an agent on magpie, for one // that takes the gateway only from its environment (agy) function launchButton(a) { @@ -1639,7 +1651,7 @@ function openPicker(agent, field, anchor, ev, only) { // routing groups come first, before the agent's own models and each // provider's; only the picker's own choices (Automatic, Off) above them options = [...options.filter((o) => o.reset), ...options.filter((o) => !o.reset && o.group === ROUTING_GROUPS), ...options.filter((o) => !o.reset && o.group !== ROUTING_GROUPS)]; - const effortPicker = !only && (field.key === "effort" || field.label === "effort" || field.label === "thinking"); + const effortPicker = !only && (field.key === "effort" || field.label === "effort" || field.label === "thinking" || field.label === SUB_EFFORT); // Current model first, then the rest in catalog order. Effort levels keep // their natural low → high order because their position is meaningful. const i = options.findIndex((o) => o.value === cur); @@ -1853,6 +1865,12 @@ function renderEffortPicker() { value.classList.toggle("empty", !option.value); } opened.anchor.querySelector(".effort-ic")?.replaceWith(effortIcon(opened.field)); + // a square (the subagents' effort) says it in its title, lit while set + if (opened.field.label === SUB_EFFORT) { + opened.anchor.classList.toggle("set", !!option.value); + opened.anchor.title = subEffortTitle(opened.field, option); + opened.anchor.setAttribute("aria-label", opened.anchor.title); + } // Persist every settled slider value, but keep the compact control open so // the user can compare adjacent levels. Queue writes to preserve ordering // when keyboard input changes several stops quickly. diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index aa3abd4fe..eee7b3b48 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -109,6 +109,8 @@ const I18N = { "large": "大模型", "tiers": "分档", "subagents": "子 agent", + "subagent effort": "子 agent 推理强度", + "the session's effort, or the subagent model's own default": "跟随当前会话的推理强度;子 agent 指定了模型时,用该模型的默认强度", "slow": "慢模型", "smol": "小模型", "sign-in": "登录方式", diff --git a/internal/gui/tests/README.md b/internal/gui/tests/README.md index 1beda3cdf..5ffd9e24f 100644 --- a/internal/gui/tests/README.md +++ b/internal/gui/tests/README.md @@ -183,6 +183,13 @@ named "same as model" (「同主模型」), its picker opens on "Same as model" the model beside it, and picked it names the model it is on. OpenCode's small model, which doesn't follow the model, stays a picker. +`subagent-effort.test.cjs` draws Codex's subagent effort (#469) in Chromium +and WebKit, English and Chinese: a square beside the subagents' one, not a +third picker; unset, its label says what that means (the session's effort, or +the subagent model's own default; 「跟随当前会话的推理强度…」), a click opens +the effort slider without scrolling the page, Default its first stop, and a +level picked is posted for `subagent_effort` alone and lights the square. + `gateway-fold.test.cjs` folds Connect on the Gateway page with the view scrolled: its fields hide, the head keeps the base URL and a copy button, the head stays where it was, and the fold is remembered across a reload. @@ -1108,7 +1115,7 @@ Chinese, Chromium and WebKit, with `/api/plugins` faked. With Node.js and Playwright available: ```sh -node --test internal/gui/tests/menu-scroll.test.cjs internal/gui/tests/click-scroll.test.cjs internal/gui/tests/panel-fold.test.cjs internal/gui/tests/rollup-short.test.cjs internal/gui/tests/panel-routing.test.cjs internal/gui/tests/gateway-fold.test.cjs internal/gui/tests/routing-kind.test.cjs internal/gui/tests/balance-fix.test.cjs internal/gui/tests/cli-update.test.cjs internal/gui/tests/login-import.test.cjs internal/gui/tests/agy-launch.test.cjs internal/gui/tests/currency.test.cjs internal/gui/tests/usage-ledger.test.cjs internal/gui/tests/update-check.test.cjs internal/gui/tests/omarchy.test.cjs internal/gui/tests/brand.test.cjs internal/gui/tests/library-loading.test.cjs internal/gui/tests/provider-typed.test.cjs node --test internal/gui/tests/signin-callback.test.cjs internal/gui/tests/routing-steady.test.cjs internal/gui/tests/old-webkit.test.cjs internal/gui/tests/session-terminal.test.cjs internal/gui/tests/text-size.test.cjs internal/gui/tests/zcode-site.test.cjs internal/gui/tests/rail-tip.test.cjs internal/gui/tests/sync-update.test.cjs internal/gui/tests/plugin-signin.test.cjs internal/gui/tests/plugin-market.test.cjs internal/gui/tests/s3-sync.test.cjs internal/gui/tests/routing-wb-refused.test.cjs internal/gui/tests/routing-blocked.test.cjs internal/gui/tests/routing-zcode-blocked.test.cjs internal/gui/tests/routing-shape.test.cjs internal/gui/tests/market-have.test.cjs internal/gui/tests/sessions-today.test.cjs internal/gui/tests/routing-side-calls.test.cjs internal/gui/tests/import-all-skills.test.cjs internal/gui/tests/routing-flood.test.cjs internal/gui/tests/routing-busy.test.cjs internal/gui/tests/own-skill.test.cjs internal/gui/tests/routing-manual.test.cjs internal/gui/tests/tray-usages.test.cjs internal/gui/tests/provider-remove.test.cjs internal/gui/tests/signin-link.test.cjs internal/gui/tests/tray-inuse.test.cjs internal/gui/tests/codex-auto-reset.test.cjs internal/gui/tests/routing-auto-reset.test.cjs internal/gui/tests/claude-usage-asked.test.cjs internal/gui/tests/claude-risk.test.cjs internal/gui/tests/library-toggle-status.test.cjs internal/gui/tests/library-all.test.cjs internal/gui/tests/routing-reroute-title.test.cjs internal/gui/tests/plain-names.test.cjs internal/gui/tests/panel-effort.test.cjs internal/gui/tests/agent-models-all-hidden.test.cjs internal/gui/tests/omp-roles.test.cjs internal/gui/tests/claude-effort.test.cjs internal/gui/tests/remote-magpie.test.cjs internal/gui/tests/qoder-cn-tile.test.cjs internal/gui/tests/provider-levels-scroll.test.cjs internal/gui/tests/signin-paste-codex.test.cjs internal/gui/tests/signin-paste-key.test.cjs internal/gui/tests/usage-alert.test.cjs internal/gui/tests/quota-families.test.cjs internal/gui/tests/provider-search.test.cjs internal/gui/tests/webdav-settings-refresh.test.cjs internal/gui/tests/lan-docker.test.cjs internal/gui/tests/plugin-key-hint.test.cjs internal/gui/tests/update-hide.test.cjs internal/gui/tests/tray-logos.test.cjs internal/gui/tests/routing-proxy.test.cjs internal/gui/tests/sse-body.test.cjs internal/gui/tests/remote-group-served.test.cjs internal/gui/tests/plugin-move-overflow.test.cjs internal/gui/tests/routing-time.test.cjs internal/gui/tests/unlisted-models.test.cjs internal/gui/tests/plugin-updates.test.cjs internal/gui/tests/request-archive.test.cjs internal/gui/tests/group-member-fast.test.cjs internal/gui/tests/providers-off-fold.test.cjs internal/gui/tests/account-return.test.cjs internal/gui/tests/usage-ledger-detail.test.cjs internal/gui/tests/usage-ledger-chart.test.cjs internal/gui/tests/usage-chart-axis.test.cjs internal/gui/tests/panel-usage.test.cjs internal/gui/tests/usage-refresh.test.cjs internal/gui/tests/usage-ledger-content.test.cjs internal/gui/tests/claude-direct.test.cjs internal/gui/tests/signin-again.test.cjs internal/gui/tests/sessions-calendar-fill.test.cjs internal/gui/tests/editor-short-window.test.cjs internal/gui/tests/group-from-model-add.test.cjs internal/gui/tests/sync-other-kind.test.cjs internal/gui/tests/web-page.test.cjs internal/gui/tests/balance-parts.test.cjs internal/gui/tests/search-api.test.cjs internal/gui/tests/provider-file-error.test.cjs internal/gui/tests/sessions-manage.test.cjs internal/gui/tests/number-units.test.cjs internal/gui/tests/sessions-bar-names.test.cjs internal/gui/tests/model-suffix-own.test.cjs internal/gui/tests/routing-effort-change.test.cjs internal/gui/tests/every-skill.test.cjs internal/gui/tests/header-centre.test.cjs internal/gui/tests/public-url.test.cjs internal/gui/tests/strip-scrollbar.test.cjs internal/gui/tests/remove-all-skills.test.cjs internal/gui/tests/request-archive-usage.test.cjs internal/gui/tests/agent-layout.test.cjs internal/gui/tests/group-found-off.test.cjs internal/gui/tests/provider-picks-stay.test.cjs +node --test internal/gui/tests/menu-scroll.test.cjs internal/gui/tests/click-scroll.test.cjs internal/gui/tests/panel-fold.test.cjs internal/gui/tests/rollup-short.test.cjs internal/gui/tests/panel-routing.test.cjs internal/gui/tests/gateway-fold.test.cjs internal/gui/tests/routing-kind.test.cjs internal/gui/tests/balance-fix.test.cjs internal/gui/tests/cli-update.test.cjs internal/gui/tests/login-import.test.cjs internal/gui/tests/agy-launch.test.cjs internal/gui/tests/currency.test.cjs internal/gui/tests/usage-ledger.test.cjs internal/gui/tests/update-check.test.cjs internal/gui/tests/omarchy.test.cjs internal/gui/tests/brand.test.cjs internal/gui/tests/library-loading.test.cjs internal/gui/tests/provider-typed.test.cjs node --test internal/gui/tests/signin-callback.test.cjs internal/gui/tests/routing-steady.test.cjs internal/gui/tests/old-webkit.test.cjs internal/gui/tests/session-terminal.test.cjs internal/gui/tests/text-size.test.cjs internal/gui/tests/zcode-site.test.cjs internal/gui/tests/rail-tip.test.cjs internal/gui/tests/sync-update.test.cjs internal/gui/tests/plugin-signin.test.cjs internal/gui/tests/plugin-market.test.cjs internal/gui/tests/s3-sync.test.cjs internal/gui/tests/routing-wb-refused.test.cjs internal/gui/tests/routing-blocked.test.cjs internal/gui/tests/routing-zcode-blocked.test.cjs internal/gui/tests/routing-shape.test.cjs internal/gui/tests/market-have.test.cjs internal/gui/tests/sessions-today.test.cjs internal/gui/tests/routing-side-calls.test.cjs internal/gui/tests/import-all-skills.test.cjs internal/gui/tests/routing-flood.test.cjs internal/gui/tests/routing-busy.test.cjs internal/gui/tests/own-skill.test.cjs internal/gui/tests/routing-manual.test.cjs internal/gui/tests/tray-usages.test.cjs internal/gui/tests/provider-remove.test.cjs internal/gui/tests/signin-link.test.cjs internal/gui/tests/tray-inuse.test.cjs internal/gui/tests/codex-auto-reset.test.cjs internal/gui/tests/routing-auto-reset.test.cjs internal/gui/tests/claude-usage-asked.test.cjs internal/gui/tests/claude-risk.test.cjs internal/gui/tests/library-toggle-status.test.cjs internal/gui/tests/library-all.test.cjs internal/gui/tests/routing-reroute-title.test.cjs internal/gui/tests/plain-names.test.cjs internal/gui/tests/panel-effort.test.cjs internal/gui/tests/agent-models-all-hidden.test.cjs internal/gui/tests/omp-roles.test.cjs internal/gui/tests/claude-effort.test.cjs internal/gui/tests/remote-magpie.test.cjs internal/gui/tests/qoder-cn-tile.test.cjs internal/gui/tests/provider-levels-scroll.test.cjs internal/gui/tests/signin-paste-codex.test.cjs internal/gui/tests/signin-paste-key.test.cjs internal/gui/tests/usage-alert.test.cjs internal/gui/tests/quota-families.test.cjs internal/gui/tests/provider-search.test.cjs internal/gui/tests/webdav-settings-refresh.test.cjs internal/gui/tests/lan-docker.test.cjs internal/gui/tests/plugin-key-hint.test.cjs internal/gui/tests/update-hide.test.cjs internal/gui/tests/tray-logos.test.cjs internal/gui/tests/routing-proxy.test.cjs internal/gui/tests/sse-body.test.cjs internal/gui/tests/remote-group-served.test.cjs internal/gui/tests/plugin-move-overflow.test.cjs internal/gui/tests/routing-time.test.cjs internal/gui/tests/unlisted-models.test.cjs internal/gui/tests/plugin-updates.test.cjs internal/gui/tests/request-archive.test.cjs internal/gui/tests/group-member-fast.test.cjs internal/gui/tests/providers-off-fold.test.cjs internal/gui/tests/account-return.test.cjs internal/gui/tests/usage-ledger-detail.test.cjs internal/gui/tests/usage-ledger-chart.test.cjs internal/gui/tests/usage-chart-axis.test.cjs internal/gui/tests/panel-usage.test.cjs internal/gui/tests/usage-refresh.test.cjs internal/gui/tests/usage-ledger-content.test.cjs internal/gui/tests/claude-direct.test.cjs internal/gui/tests/signin-again.test.cjs internal/gui/tests/sessions-calendar-fill.test.cjs internal/gui/tests/editor-short-window.test.cjs internal/gui/tests/group-from-model-add.test.cjs internal/gui/tests/sync-other-kind.test.cjs internal/gui/tests/web-page.test.cjs internal/gui/tests/balance-parts.test.cjs internal/gui/tests/search-api.test.cjs internal/gui/tests/provider-file-error.test.cjs internal/gui/tests/sessions-manage.test.cjs internal/gui/tests/number-units.test.cjs internal/gui/tests/sessions-bar-names.test.cjs internal/gui/tests/model-suffix-own.test.cjs internal/gui/tests/routing-effort-change.test.cjs internal/gui/tests/every-skill.test.cjs internal/gui/tests/header-centre.test.cjs internal/gui/tests/public-url.test.cjs internal/gui/tests/strip-scrollbar.test.cjs internal/gui/tests/remove-all-skills.test.cjs internal/gui/tests/request-archive-usage.test.cjs internal/gui/tests/agent-layout.test.cjs internal/gui/tests/group-found-off.test.cjs internal/gui/tests/provider-picks-stay.test.cjs internal/gui/tests/subagent-effort.test.cjs ``` If Playwright is installed outside the repository, set `NODE_PATH` to the diff --git a/internal/gui/tests/subagent-effort.test.cjs b/internal/gui/tests/subagent-effort.test.cjs new file mode 100644 index 000000000..4f2352f18 --- /dev/null +++ b/internal/gui/tests/subagent-effort.test.cjs @@ -0,0 +1,121 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Codex's subagents can start at an effort of their own (#469), its [agents] +// default_subagent_reasoning_effort. It is a square beside the subagents' +// one, not a third picker: unset it says what that means (the session's +// effort, or the subagent model's own default), it opens the effort slider +// with Default as its first stop, and a level picked is posted and lights +// the square. In English and Chinese. 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 models = [{ value: "gpt-5.5", label: "GPT-5.5" }, { value: "gpt-5.4-mini", label: "GPT-5.4 mini" }]; +const levels = ["low", "medium", "high", "xhigh"].map((value) => ({ value })); +const fresh = () => ({ + agents: [{ + id: "codex", name: "Codex", path: "/test/config.toml", icon: "codex-color", + fields: [ + { key: "model", label: "model", value: "gpt-5.5", options: models }, + { key: "effort", label: "effort", value: "high", options: levels }, + { key: "subagent", label: "subagents", value: "", options: models }, + { key: "subagent_effort", label: "subagent effort", value: "", options: levels }, + ], + }], + profiles: [], +}); + +function server(lang, sets) { + let cur = fresh(); + 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 words as i18n.js has them +const W = { + en: { + unset: "subagent effort: default\nthe session's effort, or the subagent model's own default", + title: "subagent effort", def: "default", high: "high", set: "subagent effort: high", + }, + zh: { + unset: "子 agent 推理强度:默认\n跟随当前会话的推理强度;子 agent 指定了模型时,用该模型的默认强度", + title: "子 agent 推理强度", def: "默认", high: "高", set: "子 agent 推理强度:高", + }, +}; + +const codex = '.row.agent[data-id="codex"]'; + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh"]) { + test(`${engine} ${lang}: Codex's subagent effort is a square that opens the effort slider`, async (t) => { + const w = W[lang]; + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const page = await browser.newPage({ viewport: { width: 1100, height: 700 } }); + page.setDefaultTimeout(5000); + 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}-subagent-effort.png`) }); + } + await browser.close(); + }); + await page.goto("http://magpie.test/"); + await page.locator(codex).waitFor(); + + // a square beside the subagents' one; model and effort alone are pickers + const square = page.locator(`${codex} .extras-cell .field.extra[data-key="subagent_effort"]`); + assert.equal(await square.count(), 1); + assert.equal(await page.locator(`${codex} .extras-cell .field.extra[data-key="subagent"]`).count(), 1); + assert.deepEqual(await page.locator(`${codex} .field:not(.extra)`).evaluateAll((es) => es.map((e) => e.dataset.key)), ["model", "effort"]); + assert.equal(await square.getAttribute("aria-label"), w.unset); + assert.equal(await square.evaluate((e) => e.classList.contains("set")), false); + + // the effort slider, Default its first stop and the square's value on it + const y = await page.evaluate(() => scrollY); + await square.click(); + await page.locator("#effortControl:not([hidden])").waitFor(); + assert.equal(await page.evaluate(() => scrollY), y, "the click scrolled the page"); + assert.equal(await page.locator("#effortTitle").textContent(), w.title); + assert.equal(await page.locator("#effortValue").textContent(), w.def); + assert.equal(await page.locator("#effortTicks i").count(), 5); + await page.locator("#effortRange").evaluate((r) => { + r.value = "3"; + r.dispatchEvent(new Event("input", { bubbles: true })); + r.dispatchEvent(new Event("change", { bubbles: true })); + }); + assert.equal(await page.locator("#effortValue").textContent(), w.high); + await page.waitForFunction(() => document.querySelector('.row.agent[data-id="codex"] .field.extra.set[data-key="subagent_effort"]')); + await page.waitForFunction(() => document.querySelector("#status")?.textContent); + assert.deepEqual(sets, [{ agent: "codex", field: "subagent_effort", value: "high" }]); + assert.equal(await square.getAttribute("aria-label"), w.set); + // the session's effort is untouched + assert.equal(await page.locator(`${codex} .field[data-key="effort"] .v`).textContent(), w.high); + assert.deepEqual(errors, []); + }); + } +}