agent: Claude Code's subagent effort writes nothing without a subagent model (KorenKrita)

KorenKrita on Discord (cause confirmed by them): with Claude Code's
subagent model unset ("Claude Code picks") and a subagent effort set,
claude.go wrote spell(tierWith(main model, effort)) into
env.CLAUDE_CODE_SUBAGENT_MODEL. That pinned every subagent to the main
model, so Claude Code's own pick (the Agent call's model, the subagent's
frontmatter) never ran.

Agent wiring (internal/agent/claude.go):
- With no subagent model, magpie writes no effort, and
  CLAUDE_CODE_SUBAGENT_MODEL stays unset.
- The saved effort is kept, not deleted (the user set it). It lives in
  the stash under claude.subagent_effort, and the subagent effort's Get
  reads "" while there is no model. A model picked later takes it
  ("v/glm:high").
- A value an older magpie wrote that way (the main model at an effort,
  not own, while routed: subagentFollowing) is moved into the stash and
  taken out of the env by writeTiers and by Sync on start.
- subagentOwn no longer counts that value as the user's own model.
- Doc: docs/subsystems/agent-wiring.md, the Claude Code "subagents" entry.

GUI (window, opened Claude Code row):
- The subagent effort moves from its square under the session defaults
  to the right of the Subagents row. It uses the tier rows' markup and
  code (effortBtn in connectPanel, ag-eff), so it lines up with
  Opus/Sonnet/Haiku's effort.
- While the subagent model is unset it shows Default, is disabled, and
  its title says "Set a subagent model first". The new string is in zh,
  zh-TW, ja and de.
- The old square is removed from the opened row. No other layout changes.
- The tray panel's own square is left alone: #3308.

Tests:
- New internal/agent/claude_subagent_effort_test.go
  (TestClaudeSubagentEffortNeedsAModel). On the old code it is red:
    an effort with no subagent model wrote
    CLAUDE_CODE_SUBAGENT_MODEL="v/glm:high"
  With the Sync branch broken by hand it is red at "Sync left an older
  magpie's CLAUDE_CODE_SUBAGENT_MODEL="v/flash:high"". It also checks
  that a set model plus effort still writes "v/glm:low".
- claude_tiereffort_test.go now expects no env for an effort with no
  model.
- New internal/gui/tests/claude-subagent-effort-row.test.cjs (16 cases):
  chromium/webkit x en/zh x 1100/560px x with/without a subagent model.
  It checks:
  - the control sits in the Subagents row at the tier efforts' x and
    height;
  - with no model it is disabled at Default and opens no slider;
  - with a model it posts subagent_effort, with no scroll;
  - the old square is gone.
  It is red against the old app.js ("the old square is still there").
- tier-effort.test.cjs is updated for the moved control.

Run at this tree (parent f985d6bdb):
- go test -count=1 ./internal/gui/ ./internal/agent/ ./internal/provider/:
  ok.
- GUI: claude-subagent-effort-row, tier-effort, i18n-keys,
  subagent-effort, claude-subagents-pick, desktop-subagent-model,
  agent-prefs, agent-tweak-fold, claude-signin and agent-field-names:
  147/147.
- gofmt clean. go vet darwin, linux -tags nogui and windows: ok.

Run at the same change before its last rebase:
- Full Go suite (`go test -count=1 -timeout 45m ./...`, sandbox HOME,
  through the suite lock) at 11b9d671c (on 45593cc1d): every package ok
  but internal/gui's TestCoreScriptBudget. app.js was 1,337,535 bytes,
  over its 1,337,000 budget, after the rebase brought in upstream growth.
  This commit trims its own additions to 1,336,991 (one shared effortBtn,
  shorter comments, a shorter new string) and raises no budget.
  TestCoreScriptBudget now passes.
- Full Go suite at 41737d214 (on 802fb6e61): all 69 packages ok.
- Whole GUI suite at 41737d214 (11,741 tests, 5.8h at load ~250): 48 red,
  none from this change.
  - Red the same on origin/main 45593cc1d, all filed: quota-count-wrap
    and quota-name-translated (#2228), quota-reads (#2150), s3-sync
    (#2448), usage-agents-hide (#2276), usage-checkin (#2549, #3091),
    usage-fold (#2163), usage-ledger (#3104, #3001).
  - Red under load only and green alone: agent-notice-lang (#2960),
    agent-stale-copies (#1949), modal-morph (#3179), plugin-card-update
    (#3079), plugin-github (#3218), and agent-field-names and
    api-key-theme (filed as #3307).
  - Also seen red once under load: codex-subagent-model's fixed 300ms
    wait (#3277).

Not tried:
- a real Claude Code run reading the written settings;
- the Windows box;
- the whole GUI suite again after the string was shortened (only the
  files above were run);
- the tray panel (#3308).
This commit is contained in:
yetone
2026-10-23 03:44:55 +08:00
parent f985d6bdb6
commit ecd9835005
10 changed files with 354 additions and 49 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ something else shows up as drift.
- Claude Code's `/model` list (`modelPicker` in its settings.json) is magpie's while it is marked in the stash (`claude.model_picker`, `claude@wsl:<distro>.model_picker` for a WSL distro) or while every row's description ends "via magpie", as every row magpie writes does (`magpiesPicker` in [`claude.go`](../../internal/agent/claude.go)). magpie keeps its own list up to date on every model set and `Sync`, and removes it when Claude Code is taken off magpie; a list the user wrote is left alone. The fingerprint covers a list whose mark an older magpie's stash lost, which otherwise stayed without every model added since (#2046).
- Claude Code 2.1.296 reads a Claude model whose version has a dot (`relay/claude-opus-4.6-us`) as Claude Opus 4: a retired warning, budget thinking, 32000 output tokens, no effort. With dashes (`relay/claude-opus-4-6-us`) it knows the model (misteer_ti. on Discord). So every model magpie writes into its settings (`model`, the tier envs, `ANTHROPIC_SMALL_FAST_MODEL`, `CLAUDE_CODE_SUBAGENT_MODEL`, `CLAUDE_CODE_AUTO_MODE_MODEL`, `modelPicker`), T3 Code's Claude slugs and Claude Desktop's Code-tab ids (`claudeLooking`) spell a dotted Claude version with dashes (`provider.ClaudeSpelled`), only when that spelling stands for one served id. A Claude model listed to Desktop with reasoning levels is given as `magpie-<n>.anthropic.<model>`, its dotted version dashed as well (`claudeModel`: Copilot's `claude-opus-5.5` is `…anthropic.claude-opus-5-5`, which Claude Code knows; it was `mythos-magpie-<n>`, an unknown model, and Haiku 4.5 got an effort Copilot refuses, #1819); a request for it is served by `<n>` alone (`aliased`), so that spelling needn't be unique. Mythos counts as Claude here too: Claude Code matches `claude-mythos-5-1` by substring, so `claude-mythos-5.1` would read as Mythos 5. Every read of those keys takes it back (`provider.ClaudeRead`: `claudeIn`'s `env`, `claudeMain`, `claudeStandInAt`), so magpie's fields, applied state and Drift keep the dotted id. The user's own values are stashed and given back as written. Values an older magpie wrote dotted are rewritten on the next Sync. Other vendors' ids are never respelled ([`claudedash.go`](../../internal/provider/claudedash.go)).
- Codex's "subagents" field is `[agents] default_subagent_model`: only the model a subagent starts on when its lead names none in `spawn_agent` (codex-rs `core/src/agent/child_config.rs`). Unset, it isn't "same as model": the lead may still name another, so the GUI calls it the lead's pick, else the model (`leadPicks` in app.js), and its title points at the "subagent model" field.
- Claude Code's "subagents" field is `env.CLAUDE_CODE_SUBAGENT_MODEL`. Unset, magpie writes nothing there (`writeTiers`, `setSubagent`), and Claude Code picks: the Agent tool call's model, then the subagent's own frontmatter model, then the variable, then the lead's model (Claude Code 2.1.306; the built-in Explore inherits, capped at opus). So the GUI calls unset "Claude Code's own pick" (`claudePicks` in app.js), not "same as model" (KorenKrita on Discord).
- Claude Code's "subagents" field is `env.CLAUDE_CODE_SUBAGENT_MODEL`. Unset, magpie writes nothing there (`writeTiers`, `setSubagent`), and Claude Code picks: the Agent tool call's model, then the subagent's own frontmatter model, then the variable, then the lead's model (Claude Code 2.1.306; the built-in Explore inherits, capped at opus). So the GUI calls unset "Claude Code's own pick" (`claudePicks` in app.js), not "same as model" (KorenKrita on Discord). Its effort is written only with a model: unset, a saved subagent effort is kept (`claude.subagent_effort` in the stash) and not applied, since writing the main model at that effort into the variable would pin every subagent to the main model (KorenKrita on Discord). A model picked later takes it. A value an older magpie wrote that way (the main model at an effort, not own) is moved into the stash and taken out of the env by `writeTiers` and Sync (`subagentFollowing`, `TestClaudeSubagentEffortNeedsAModel`). The window draws that effort at the right of the Subagents row like a tier's, disabled at Default while the model is unset (`effortBtn` in `connectPanel`, `claude-subagent-effort-row.test.cjs`); the tray panel keeps its own square.
- Codex's "subagent model" field writes nothing to Codex's config: its lead names each subagent's model in `spawn_agent`, which `[agents]` can't overrule. It is magpie's setting (`settings.CodexSubagentModel`, [`codex_subagent.go`](../../internal/provider/codex_subagent.go)), and the gateway moves the subagent's request onto it (see [gateway routing](gateway-routing.md)). Its options are every model and routing group Codex's own lists show (`CatalogFor("codex")`, so a model taken out of them or not picked is left out here too), ChatGPT accounts' first (#1633: a lead on a chat provider wants its subagents there too). A task a ChatGPT-backed lead sealed opens only on a ChatGPT account, so the gateway keeps such a subagent on its own model when the one set is another provider's. Its setter takes any `provider/model` or `group/<id>`, also one magpie doesn't serve now, so a profile or backup put back on another computer still applies (`ApplyFields` stops at the first failed Set), and refuses one of Codex's own bare names.
- Claude Desktop's "subagent model" field (`subagent_model`, `desktopSubagentField` in [`claudedesktop.go`](../../internal/agent/claudedesktop.go)) writes nothing to Desktop's config: Desktop runs its Code tab's Claude Code with `CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1`, under which Claude Code ignores `CLAUDE_CODE_SUBAGENT_MODEL`, `CLAUDE_CODE_SUBAGENT_MODEL_FORCE` and the tier variables in its settings files' `env` ("Ignoring … this session's provider routing is managed by the host", Claude Code 2.1.295), and the env Desktop builds for the Code tab has no key for it (Desktop 2.31226). It is magpie's setting (`settings.DesktopSubagentModel`, [`desktop_subagent.go`](../../internal/provider/desktop_subagent.go)), and the gateway moves each subagent's turn onto it (see [gateway routing](gateway-routing.md)). It is labelled as Codex's, so the Agents page gives it the same square. Its options are magpie's models and groups as Desktop's list shows them (`viaMagpie("claude-desktop")`), while Desktop is on magpie, as for the tiers. A Desktop alias picked is kept by its catalog id (`DesktopCatalogID`). Like Codex's, its setter takes any `provider/model` or `group/<id>`, also one magpie doesn't serve now, so a profile or backup still applies, and refuses a bare name. It is `Live`: the gateway reads it on each request.
- Claude Desktop's "subagent effort" (`desktopSubagentEffortField`, `settings.DesktopSubagentEffort`) is also Quiet and Live. Default keeps the effort the request asks for, including disabled thinking; it never selects a new default. A picked level works independently of the subagent model: no model pick, the same model and an unavailable model pick all still take the effort. While wired, the field offers the selected model's levels, or the standard levels when its model is inherited or unavailable; a model marked reasonless offers none. The stored pick survives model changes. A disconnected preference can be saved or cleared without connecting Desktop or showing restart advice, so profile restoration and Disconnect can restore a value saved before connecting; reconnect returns to the last live pick. `subEffortTitle` gives Desktop the Claude Code default explanation; Codex's default meaning is unchanged. The gateway fits each attempt to its actual model and preserves fixed group-member efforts (see [gateway routing](gateway-routing.md)).
+49 -15
View File
@@ -1264,20 +1264,39 @@ func claudeIn(at place) *Agent {
// 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.
// An effort with no model of their own is never written: the main
// model at that effort in CLAUDE_CODE_SUBAGENT_MODEL pins every
// subagent to the main model (KorenKrita on Discord).
subagentOwn := func() string {
w := env("CLAUDE_CODE_SUBAGENT_MODEL")
if m, e := tierAt(w); routed() && isMagpie(m) && (own("subagent") || w != wroteMain() && (e != "" || m != wroteMain())) {
if m, _ := tierAt(w); routed() && isMagpie(m) && (own("subagent") || m != wroteMain()) {
return w
}
return ""
}
// the effort an older magpie wrote for subagents that follow the main
// model, as the main model at that effort: "" for none
subagentFollowing := func() string {
m, e := tierAt(env("CLAUDE_CODE_SUBAGENT_MODEL"))
if routed() && e != "" && m == wroteMain() && !own("subagent") {
return e
}
return ""
}
// the subagents' effort the user gave with no model of their own: kept
// in the stash, not written, and applied once they have a model
subEffortKey := at.key("claude.subagent_effort")
subagentSaved := func() string { return cmp.Or(stashLoad()[subEffortKey], subagentFollowing()) }
// the subagents' model as written, its effort apart: "" for each while
// it follows the main model
// it follows the main model, which takes no effort of theirs
subagentAt := func() (string, string) {
m, e := tierAt(subagentOwn())
if m == wroteMain() && !own("subagent") {
m = ""
}
if m == "" {
e = ""
}
return m, e
}
// the main model and each tier's, one that has none or follows it on
@@ -1494,12 +1513,6 @@ func claudeIn(at place) *Agent {
}
}
}
// so do subagents that follow it at an effort of their own
if m, e := subagentAt(); routed() && m == "" && e != "" {
if err := edit.SetJSON(path, edit.KV{Path: "env.CLAUDE_CODE_SUBAGENT_MODEL", Value: spell(tierWith(v, e))}); err != nil {
return err
}
}
return writeTiers(v, tiers)
}
// a word that is no model: an effort level the model doesn't take,
@@ -1535,7 +1548,11 @@ func claudeIn(at place) *Agent {
return err
}
// subagents given a model of their own keep it; the others run on
// the session's, whatever /model picked, or on the tier they ask for
// the session's, whatever /model picked, or on the tier they ask for.
// An older magpie's effort on the main model goes out, kept unwritten.
if e := subagentFollowing(); e != "" && stashLoad()[subEffortKey] == "" {
stash(map[string]string{subEffortKey: e})
}
sub := subagentOwn()
// the main model is settings.json's alone: ANTHROPIC_MODEL would
// outrank a pick in /model
@@ -1816,15 +1833,24 @@ 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.
// setSubagent writes the subagents' model and effort, the main model's
// at none taking the variable away
// setSubagent writes the subagents' model and effort. With no model,
// the variable goes and the effort is kept unwritten (subagentSaved):
// the main model at an effort would pin every subagent to it.
setSubagent := func(model, effort string) error {
if model == "" && effort == "" {
if model == "" {
if effort != "" {
stash(map[string]string{subEffortKey: effort})
} else {
forget(subEffortKey)
}
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: spell(tierWith(cmp.Or(model, mainModel()), effort))}); err != nil {
return err
} else {
forget(subEffortKey)
if err := edit.SetJSON(path, edit.KV{Path: "env.CLAUDE_CODE_SUBAGENT_MODEL", Value: spell(tierWith(model, effort))}); err != nil {
return err
}
}
return writeTiers(curTiers())
}
@@ -1841,7 +1867,10 @@ func claudeIn(at place) *Agent {
if v != "" && !isMagpie(v) {
return fmt.Errorf("subagents: %q is not a model magpie serves", v)
}
_, e := subagentAt()
m, e := subagentAt()
if m == "" {
e = subagentSaved()
}
// a model picked is the user's own, the main model too
// (#2654: given the main model, the subagents' was left out
// and they followed the main model's next move); only "Same
@@ -2047,6 +2076,11 @@ func claudeIn(at place) *Agent {
return err
}
}
// subagents an older magpie pinned to the main model at an
// effort of theirs follow it again, the effort kept unwritten
if subagentFollowing() != "" {
return writeTiers(curTiers())
}
// a model of magpie's an older magpie wrote with a dotted Claude
// version goes in as Claude Code is given it now (spell)
raw := []string{jsonGet(path, "model")()}
@@ -0,0 +1,97 @@
package agent
import (
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/edit"
"github.com/yetone/magpie/internal/provider"
)
// A subagent effort with no subagent model ("Claude Code picks") writes no
// CLAUDE_CODE_SUBAGENT_MODEL: the main model at that effort there pinned
// every subagent, an Explore asking for haiku too, to the main model
// (KorenKrita on Discord). The effort is kept, not applied, and goes with a
// model the subagents are given later; a model and effort together are
// written as before. One an older magpie wrote is taken out by Sync.
func TestClaudeSubagentEffortNeedsAModel(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: "v", Name: "V", Chat: "https://example.test/v1", Key: "k",
Models: []string{"glm", "flash"}}); err != nil {
t.Fatal(err)
}
if err := catalog.SaveLive("v", "https://example.test/v1", []catalog.Model{
{ID: "glm", Context: 200000, Efforts: []string{"low", "medium", "high", "max"}},
{ID: "flash", Context: 128000, Efforts: []string{"low", "high"}},
}); err != nil {
t.Fatal(err)
}
path := filepath.Join(home, ".claude", "settings.json")
writeFile(t, path, `{}`)
a := claude(home)
sub := func() (string, bool) { return edit.GetJSON(path, "env.CLAUDE_CODE_SUBAGENT_MODEL") }
set := func(key, v string) {
t.Helper()
if err := a.Field(key).Set(v); err != nil {
t.Fatalf("%s=%s: %v", key, v, err)
}
}
set("model", "v/glm")
// no model of their own: the effort writes nothing
set("subagent_effort", "high")
if v, has := sub(); has {
t.Fatalf("an effort with no subagent model wrote CLAUDE_CODE_SUBAGENT_MODEL=%q", v)
}
if a.Field("subagent").Get() != "" || a.Field("subagent_effort").Get() != "" {
t.Fatalf("read back: %v", a.Values())
}
// nor does a new main model
set("model", "v/flash")
if v, has := sub(); has {
t.Fatalf("a new main model wrote CLAUDE_CODE_SUBAGENT_MODEL=%q", v)
}
// a model of their own takes the effort kept
set("subagent", "v/glm")
if v, _ := sub(); v != "v/glm:high" || a.Field("subagent_effort").Get() != "high" {
t.Fatalf("subagents on glm with the effort kept: %q %v", v, a.Values())
}
// a model and an effort set together, as before
set("subagent_effort", "low")
if v, _ := sub(); v != "v/glm:low" || a.Field("subagent").Get() != "v/glm" || a.Field("subagent_effort").Get() != "low" {
t.Fatalf("subagents on glm at low: %q %v", v, a.Values())
}
// back to Claude Code's pick: the variable goes, the effort is kept
set("subagent", "")
if v, has := sub(); has {
t.Fatalf("subagents back to Claude Code's pick left CLAUDE_CODE_SUBAGENT_MODEL=%q", v)
}
set("subagent", "v/flash")
if v, _ := sub(); v != "v/flash:low" {
t.Fatalf("subagents on flash with the effort kept: %q", v)
}
set("subagent", "")
// the main model at an effort, as an older magpie wrote it: Sync takes
// it out and keeps the effort for a later model
set("subagent_effort", "")
if err := edit.SetJSON(path, edit.KV{Path: "env.CLAUDE_CODE_SUBAGENT_MODEL", Value: "v/flash:high"}); err != nil {
t.Fatal(err)
}
if err := a.Sync(); err != nil {
t.Fatal(err)
}
if v, has := sub(); has {
t.Fatalf("Sync left an older magpie's CLAUDE_CODE_SUBAGENT_MODEL=%q", v)
}
set("subagent", "v/glm")
if v, _ := sub(); v != "v/glm:high" {
t.Fatalf("the older magpie's effort wasn't kept: %q", v)
}
}
+14 -8
View File
@@ -106,30 +106,36 @@ func TestClaudeTierEffort(t *testing.T) {
t.Fatal("a level that isn't one should fail")
}
// subagents: at an effort of their own on the main model, then on one of
// their own, kept through a new main model
// subagents: an effort with no model of their own is kept unwritten
// (the main model at it pinned every subagent there), and applied once
// they have one; see TestClaudeSubagentEffortNeedsAModel
set("opus", "")
set("opus_effort", "")
if env("CLAUDE_CODE_SUBAGENT_MODEL") != "" {
t.Fatalf("subagents follow: %v", a.Values())
}
set("subagent_effort", "low")
if env("CLAUDE_CODE_SUBAGENT_MODEL") != "v/flash:low" || a.Field("subagent").Get() != "" || a.Field("subagent_effort").Get() != "low" {
t.Fatalf("subagents at low: %v", a.Values())
if env("CLAUDE_CODE_SUBAGENT_MODEL") != "" || a.Field("subagent").Get() != "" || a.Field("subagent_effort").Get() != "" {
t.Fatalf("subagents at low with no model: %v", a.Values())
}
set("model", "v/glm")
if env("CLAUDE_CODE_SUBAGENT_MODEL") != "v/glm:low" || a.Field("subagent").Get() != "" {
t.Fatalf("subagents follow the new model at low: %v", a.Values())
if env("CLAUDE_CODE_SUBAGENT_MODEL") != "" || a.Field("subagent").Get() != "" {
t.Fatalf("subagents follow the new model: %v", a.Values())
}
set("subagent", "v/flash")
if env("CLAUDE_CODE_SUBAGENT_MODEL") != "v/flash:low" || a.Field("subagent").Get() != "v/flash" {
if env("CLAUDE_CODE_SUBAGENT_MODEL") != "v/flash:low" || a.Field("subagent").Get() != "v/flash" || a.Field("subagent_effort").Get() != "low" {
t.Fatalf("subagents on flash at low: %v", a.Values())
}
set("subagent", "")
set("subagent_effort", "")
if env("CLAUDE_CODE_SUBAGENT_MODEL") != "" || a.Field("subagent_effort").Get() != "" {
t.Fatalf("subagents back: %v", a.Values())
}
set("subagent_effort", "")
set("subagent", "v/flash")
if env("CLAUDE_CODE_SUBAGENT_MODEL") != "v/flash" || a.Field("subagent_effort").Get() != "" {
t.Fatalf("subagents on flash, effort cleared: %v", a.Values())
}
set("subagent", "")
// back to Claude Code as installed: nothing of magpie's left
set("model", "")
for _, k := range claudeEnv {
+2
View File
@@ -4252,6 +4252,8 @@ body.window .row + .row.agent.conn > .who { min-height: 41px; } /* the line abov
.ag-tier { width: 70px; flex: none; font-size: 12px; color: var(--fg-2); }
.ag-vl .field.ag-pick { width: 220px; justify-content: flex-start; }
.ag-vl .field.ag-eff { flex: none; }
/* the subagents' effort, while they are on Claude Code's pick: Default, dimmed, as a macOS control that can't be used yet */
.ag-vl .field.ag-eff:disabled, .ag-vl .field.ag-eff:disabled:hover { background: var(--pill); opacity: .5; cursor: default; }
.ag-vl .field.ag-pick .v { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.ag-exp .extras-cell { justify-content: flex-start; }
.ag-chip { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 6px; background: var(--card); box-shadow: inset 0 0 0 1px var(--line); font-size: 12px; color: var(--fg-2); }
+20 -13
View File
@@ -436,7 +436,7 @@ function renderAgents() {
b.title = claudePicks(a, f) && !f.value ? t("{label}: {value}", { label: t(f.label), value: t(AUTO_MODE_UNSET) }) + "\n" + t(CLAUDE_PICKS)
: t("{label}: {value}", { label: t(f.label), value: f.value || t("agent default") }) + (opt?.note ? ` · ${opt.note}` : "");
if (f.value && opt?.direct) b.title += "\n" + directSaid(a, opt);
const effort = f.key === "effort" || f.label === "effort" || f.label === "thinking" || TIER_EFFORTS.includes(f.label);
const effort = f.key === "effort" || f.label === "effort" || f.label === "thinking" || TIER_EFFORTS.includes(f.label) || f.label === SUB_EFFORT;
if (opt?.icon || opt?.icons?.length) b.append(optionIcon(opt));
// a field with no logo of its own still leads with an icon: how much
// effort, or the agent's own for its default, as the picker shows it
@@ -626,7 +626,7 @@ function renderAgents() {
// Claude Code's tiers, subagents and auto mode have rows of their own
// when opened
if (a.id === "claude") {
for (const f of a.fields.filter((f) => TIERS.includes(f.label) || f.label === "subagents" || f.label === AUTO_MODE)) extras.querySelector(`[data-key="${CSS.escape(f.key)}"]`)?.remove();
for (const f of a.fields.filter((f) => TIERS.includes(f.label) || f.label === "subagents" || f.label === SUB_EFFORT || f.label === AUTO_MODE)) extras.querySelector(`[data-key="${CSS.escape(f.key)}"]`)?.remove();
extras.querySelector('[data-key="tiers"]')?.remove();
}
row.append(agentHandle(a, row, inFold), who);
@@ -1895,22 +1895,29 @@ function connectPanel(a, { fields, fieldBtn }) {
const tiers = a.fields.filter((f) => TIERS.includes(f.label) && f.options.length);
const hint = { opus: "/model opus", sonnet: "/model sonnet", haiku: "/model haiku", fable: "/model fable" };
const also = { sonnet: " · " + t("the default tier"), haiku: " · " + t("also for small background tasks") };
// a tier's own effort (#536) or the subagents', while there are levels
// to pick; unset, at the effort Claude Code asks for (off: no model)
const effortBtn = (e, off) => {
const b = fieldBtn(off ? { ...e, value: "" } : e, "ag-eff");
b.disabled = !!off;
b.title = t("{label}: {value}", { label: t(e.label), value: off ? t("default") : e.value ? effortName(optionFor(e, e.value) || { value: e.value }) : t("the effort Claude Code asks for") }) + (off ? "\n" + t("Set a subagent model first") : "");
b.setAttribute("aria-label", b.title);
return b;
};
const rows = tiers.map((f) => {
const l = line(el("span", "ag-tier", f.label[0].toUpperCase() + f.label.slice(1)), fieldBtn(f, "ag-pick"));
// the tier's own effort (#536), while there are levels to pick;
// unset, it runs at the effort Claude Code asks for
const e = a.fields.find((x) => x.label === f.label + " effort" && (x.options.length || x.value));
if (e) {
const b = fieldBtn(e, "ag-eff");
b.title = t("{label}: {value}", { label: t(e.label), value: e.value ? effortName(optionFor(e, e.value) || { value: e.value }) : t("the effort Claude Code asks for") });
b.setAttribute("aria-label", b.title);
l.append(b);
}
if (e) l.append(effortBtn(e));
l.append(el("span", "ag-hint", (hint[f.label] || "") + (also[f.label] || "")));
return l;
});
const sub = a.fields.find((f) => f.label === "subagents" && (f.options.length || f.value));
if (sub) rows.push(line(el("span", "ag-tier", t("Subagents")), fieldBtn(sub, "ag-pick")));
if (sub) {
const l = line(el("span", "ag-tier", t("Subagents")), fieldBtn(sub, "ag-pick"));
const e = a.fields.find((x) => x.label === SUB_EFFORT && (x.options.length || x.value));
if (e) l.append(effortBtn(e, !sub.value));
rows.push(l);
}
// the model its auto mode classifier runs on; unset, Claude Code's own
const auto = a.fields.find((f) => f.label === AUTO_MODE && (f.options.length || f.value));
if (auto) rows.push(line(el("span", "ag-tier", t("Auto mode")), fieldBtn(auto, "ag-pick"), el("span", "ag-hint", t("the model that checks each action in auto mode"))));
@@ -4841,14 +4848,14 @@ function renderEffortPicker() {
}
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) {
if (opened.field.label === SUB_EFFORT && !opened.anchor.classList.contains("ag-eff")) {
opened.anchor.classList.toggle("set", !!option.value);
opened.anchor.title = subEffortTitle(opened.agent, opened.field, option);
opened.anchor.setAttribute("aria-label", opened.anchor.title);
}
// a tier's effort, opened from the tiers' square: that square's title
// and light follow the level
if (roleLevel(opened.field.label) && opened.anchor.classList.contains("ag-eff")) {
if ((roleLevel(opened.field.label) || opened.field.label === SUB_EFFORT) && opened.anchor.classList.contains("ag-eff")) {
opened.anchor.title = t("{label}: {value}", { label: t(opened.field.label), value: option.value ? effortName(option) : levelUnset(opened.agent) });
opened.anchor.setAttribute("aria-label", opened.anchor.title);
} else if (roleLevel(opened.field.label)) {
+4
View File
@@ -723,6 +723,7 @@ const I18N = {
"haiku effort": "haiku 推理强度",
"fable effort": "fable 推理强度",
"the effort Claude Code asks for": "跟随 Claude Code 请求的推理强度",
"Set a subagent model first": "先设置子代理模型",
"the session's effort, or the subagent model's own default": "跟随会话的推理强度,或子代理模型的默认强度",
"slow": "慢模型",
"smol": "小模型",
@@ -4604,6 +4605,7 @@ const I18N = {
"haiku effort": "haiku 推理強度",
"fable effort": "fable 推理強度",
"the effort Claude Code asks for": "跟隨 Claude Code 請求的推理強度",
"Set a subagent model first": "先設定子代理模型",
"the session's effort, or the subagent model's own default": "跟隨會話的推理強度,或子代理模型的預設強度",
"slow": "慢模型",
"smol": "小模型",
@@ -8451,6 +8453,7 @@ const I18N = {
"haiku effort": "haiku の推論レベル",
"fable effort": "fable の推論レベル",
"the effort Claude Code asks for": "Claude Code が要求する推論レベル",
"Set a subagent model first": "先にサブエージェントのモデルを設定してください",
"the session's effort, or the subagent model's own default": "セッションの推論レベル、またはサブエージェントのモデル自身のデフォルト",
"slow": "低速",
"smol": "小",
@@ -12315,6 +12318,7 @@ const I18N = {
"haiku effort": "Reasoning-Effort haiku",
"fable effort": "Reasoning-Effort fable",
"the effort Claude Code asks for": "der von Claude Code angeforderte Reasoning-Effort",
"Set a subagent model first": "Lege zuerst ein Modell für die Subagenten fest",
"the session's effort, or the subagent model's own default": "der Reasoning-Effort der Sitzung oder der Standard des Subagent-Modells",
"slow": "langsam",
"smol": "klein (smol)",
+11 -2
View File
@@ -445,8 +445,17 @@ effort Claude Code asks for" / 「跟随 Claude Code 请求的推理强度」 un
effort entry opens the effort slider without scrolling the page, Default its
first stop, a level picked is posted for that tier's `<tier>_effort` alone and
named in the square's title, and the session's effort stays. Its subagents'
effort is a square that says what unset means for Claude Code, and a Claude
Code not through magpie has no levels, no square and no effort entries.
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-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
class, column and height), and the old square under New sessions is gone.
With the subagents on Claude Code's pick it reads Default, is disabled and
says to set a subagent model first (KorenKrita on Discord: magpie writes no
effort then); with a model it opens the slider without scrolling the page and
posts `subagent_effort`.
`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
@@ -0,0 +1,144 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Claude Code's subagent effort sits at the right of the Subagents row in the
// opened row's Tiers, laid out as the Opus, Sonnet, Haiku and Fable rows'
// efforts are, and no longer as a square under New sessions. While the
// subagents are on Claude Code's pick (no model of their own) it reads
// Default and can't be used: magpie writes no effort then, as the main model
// at an effort pinned every subagent to it (KorenKrita on Discord). Given a
// model, it opens the effort slider and posts the level picked. In Chromium
// and WebKit, wide and narrow, 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: "magpie/v/glm", label: "GLM", ref: "v/glm" }, { value: "magpie/v/flash", label: "Flash", ref: "v/flash" }];
const levels = ["", "low", "medium", "high"].map((value) => ({ value }));
const tiers = ["opus", "sonnet", "haiku", "fable"];
const claude = (sub) => ({
id: "claude", name: "Claude Code", path: "/test/settings.json", icon: "claudecode-color", wired: true,
fields: [
{ key: "model", label: "model", value: "magpie/v/glm", options: models },
{ key: "effort", label: "effort", value: "high", options: levels },
...tiers.map((tier) => ({ key: tier, label: tier, value: "", options: models })),
...tiers.map((tier) => ({ key: tier + "_effort", label: tier + " effort", value: "", options: levels })),
{ key: "subagent", label: "subagents", value: sub, options: models },
// a level the backend still holds from before reads Default with no model
{ key: "subagent_effort", label: "subagent effort", value: sub ? "" : "high", options: levels },
],
});
function server(lang, sub, sets) {
let cur = { agents: [claude(sub)], 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[0].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: { subs: "Subagents", def: "default", high: "high", label: "subagent effort", asks: "the effort Claude Code asks for", first: "Set a subagent model first", sep: (l, v) => `${l}: ${v}` },
zh: { subs: "子代理", def: "默认", high: "高", label: "子代理推理强度", asks: "跟随 Claude Code 请求的推理强度", first: "先设置子代理模型", sep: (l, v) => `${l}:${v}` },
};
const cc = '.row.agent[data-id="claude"]';
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh"]) {
for (const width of [1100, 560]) {
for (const sub of ["", "magpie/v/flash"]) {
test(`${engine} ${lang} ${width}px: the subagent effort is on the Subagents row, ${sub ? "with a model" : "disabled with none"}`, async (t) => {
const w = W[lang];
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await browser.newPage({ viewport: { width, height: 800 } });
page.setDefaultTimeout(5000);
const errors = [], sets = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, sub, 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}-${sub ? "model" : "none"}-subagent-effort.png`), fullPage: true });
}
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();
// the old square under New sessions is gone, from the whole row
assert.equal(await page.locator(`${cc} .field.extra[data-key="subagent_effort"]`).count(), 0, "the old square is still there");
assert.equal(await page.locator(`${cc} .field[data-key="subagent_effort"]`).count(), 1);
// the Subagents row: its name, its model, then its effort at the right,
// as each tier's row has them
const row = page.locator(`${cc} .ag-exp .ag-vl`, { has: page.locator('.field[data-key="subagent"]') });
assert.equal(await row.count(), 1);
assert.deepEqual(await row.evaluate((r) => [...r.children].map((c) => c.dataset.key || c.className)), ["ag-tier", "subagent", "subagent_effort"]);
assert.equal(await row.locator(".ag-tier").textContent(), w.subs);
const eff = row.locator('.field.ag-eff[data-key="subagent_effort"]');
const opus = page.locator(`${cc} .ag-exp .field.ag-eff[data-key="opus_effort"]`);
// laid out as a tier's: the same class, bars and height, in the
// same column, right of a picker as wide as the tiers'
assert.equal(await eff.getAttribute("class"), await opus.getAttribute("class"));
assert.equal(await eff.locator(".effort-ic").count(), 1);
const [eb, ob] = [await eff.boundingBox(), await opus.boundingBox()];
assert.ok(Math.abs(eb.x - ob.x) < 0.5 && Math.abs(eb.height - ob.height) < 0.5, `effort at ${eb.x},${eb.height}; opus's at ${ob.x},${ob.height}`);
const pick = await row.locator('.field.ag-pick[data-key="subagent"]').boundingBox();
assert.ok(eb.x >= pick.x + pick.width, "the effort sits right of the model");
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), "the Agents view overflows");
if (!sub) {
// no model: Default, and it can't be used
assert.equal(await eff.isDisabled(), true);
assert.equal(await eff.locator(".v").textContent(), w.def);
const title = await eff.getAttribute("title");
assert.ok(title.startsWith(w.sep(w.label, w.def)) && title.includes(w.first), title);
await eff.click({ force: true });
assert.equal(await page.locator("#effortControl:not([hidden])").count(), 0, "a disabled effort opened the slider");
assert.deepEqual(sets, []);
} else {
// a model of their own: the slider, and the level picked posted
assert.equal(await eff.isDisabled(), false);
assert.equal(await eff.getAttribute("title"), w.sep(w.label, w.asks));
const y = await page.evaluate(() => scrollY);
await eff.click();
await page.locator("#effortControl:not([hidden])").waitFor();
assert.equal(await page.evaluate(() => scrollY), y, "a click scrolled the page");
await page.locator("#effortRange").evaluate((r) => {
r.value = "3";
r.dispatchEvent(new Event("input", { bubbles: true }));
r.dispatchEvent(new Event("change", { bubbles: true }));
});
await page.waitForFunction(() => document.querySelector("#status")?.textContent);
assert.deepEqual(sets, [{ agent: "claude", field: "subagent_effort", value: "high" }]);
assert.equal(await eff.getAttribute("title"), w.sep(w.label, w.high));
}
assert.deepEqual(errors, []);
});
}
}
}
}
+12 -10
View File
@@ -4,9 +4,10 @@
// model in the opened row's Tiers: unset it says the tier runs at the effort
// Claude Code asks for, a click opens the effort slider with Default as its
// first stop, and a level picked is posted and named in its title. (The
// tray panel keeps them as entries under the models in the tiers' square.) The subagents' effort is a square, as Codex's is, that says what
// unset means for Claude Code. Before Claude Code goes through magpie there
// are no levels: no effort entries and no square. No click scrolls the page.
// tray panel keeps them as entries under the models in the tiers' square.)
// The subagents' effort is on the Subagents row, as a tier's is. Before
// Claude Code goes through magpie there are no levels: no effort entries
// and no square. No click scrolls the page.
// In English and Chinese. No backend: the API is faked here.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
@@ -61,11 +62,11 @@ function server(lang, sets) {
const W = {
en: {
asks: "the effort Claude Code asks for", effort: (tier) => tier + " effort", title: "haiku effort", def: "default", low: "low", high: "high",
sub: "subagent effort: default\nthe effort Claude Code asks for", sep: (l, v) => `${l}: ${v}`,
sep: (l, v) => `${l}: ${v}`,
},
zh: {
asks: "跟随 Claude Code 请求的推理强度", effort: (tier) => tier + " 推理强度", title: "haiku 推理强度", def: "默认", low: "低", high: "高",
sub: "子代理推理强度:默认\n跟随 Claude Code 请求的推理强度", sep: (l, v) => `${l}:${v}`,
sep: (l, v) => `${l}:${v}`,
},
};
@@ -95,17 +96,18 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.locator(`${cc} .ag-link`).click();
await page.locator(`${cc} .ag-exp`).waitFor();
// no tier's effort is a field of the row's own; the subagents' is a square
assert.deepEqual(await page.locator(`${cc} .field:not(.ag-eff)[data-key$="_effort"]`).evaluateAll((es) => es.map((e) => e.dataset.key)), ["subagent_effort"]);
assert.equal(await page.locator(`${cc} .field.extra[data-key="subagent_effort"]`).getAttribute("aria-label"), w.sub);
// no tier's effort is a field of the row's own, nor the subagents': theirs
// is on the Subagents row (claude-subagent-effort-row.test.cjs)
assert.deepEqual(await page.locator(`${cc} .field:not(.ag-eff)[data-key$="_effort"]`).evaluateAll((es) => es.map((e) => e.dataset.key)), []);
assert.equal(await page.locator(`${cc} .field.extra[data-key="subagent_effort"]`).count(), 0);
// not through magpie: no levels, no square, no effort entries
assert.equal(await page.locator('.row.agent[data-id="cc-own"] .field[data-key$="_effort"]').count(), 0);
// each tier's row in the opened row: its model, then its effort
const effs = page.locator(`${cc} .ag-exp .field.ag-eff`);
assert.deepEqual(await effs.evaluateAll((es) => es.map((e) => e.dataset.key)), tiers.map((tier) => tier + "_effort"));
assert.deepEqual(await effs.evaluateAll((es) => es.map((e) => e.dataset.key)), [...tiers.map((tier) => tier + "_effort"), "subagent_effort"]);
for (const tier of tiers) assert.equal(await page.locator(`${cc} .ag-exp .field.ag-eff[data-key="${tier}_effort"]`).getAttribute("aria-label"), t2(w, w.effort(tier), w.asks));
assert.equal(await effs.locator(".effort-ic").count(), 4, "each effort shows the bars");
assert.equal(await effs.locator(".effort-ic").count(), 5, "each effort shows the bars");
const haiku = page.locator(`${cc} .ag-exp .field.ag-eff[data-key="haiku_effort"]`);
const y = await page.evaluate(() => scrollY);