diff --git a/docs/subsystems/agent-wiring.md b/docs/subsystems/agent-wiring.md index 8977b1036..d4a0b2045 100644 --- a/docs/subsystems/agent-wiring.md +++ b/docs/subsystems/agent-wiring.md @@ -67,6 +67,7 @@ something else shows up as drift. - Claude Code's sign-in (`login`) is magpie's key (`""`, the default) or claude.ai (`claudeai`). claude.ai writes `ANTHROPIC_AUTH_TOKEN` empty, which Claude Code reads as no key: it keeps its claude.ai login and sends that to magpie, which never passes it on (`claudeSignIn` in the gateway). Every later write keeps the token empty (`wiredKey`), and a key put there by hand is reported by Check, not taken for magpie's. It's offered only where the gateway takes any key (`gwKey() == gateway.Token`: loopback, a WSL distro mirrored), not from a distro under NAT while magpie is shared on the network, where only the sharing key gets in. The choice is stashed, so it survives Disconnect and a port move. An empty token counts as magpie's only beside the address magpie last wrote (`claude.wired_at` in the stash, which Rewire carries to the new port, `keyOurs`): an endpoint of the user's own with an empty token stays theirs when the model goes back to Claude Code's own. - Claude Code's auto mode review (`CLAUDE_CODE_AUTO_MODE_SERVER`, `claudeReviewEnv` in [`claude.go`](../../internal/agent/claude.go)) is written `"0"` while Claude Code is routed through magpie and none of the models it can reach there is one Anthropic reviews (`claudeReviewed`, by `gateway.AutoModeReviewed`): those it is shown (and Claude Desktop's while Desktop is on magpie), a shown group's members, those providers' fallbacks, and the models it is set to. Off, it classifies locally from the start, as it does anyway behind a gateway that doesn't answer, without the "isn't eligible because your requests go through 127.0.0.1:3425" notice (1EFLOPS on X). Any reviewed model leaves it unset, since `/model` can take the session there; a model hidden from Claude Code doesn't count. It is rewritten on every model set and `Sync`, so adding a Claude provider turns the review back on. magpie's value is kept apart in the stash (`claude.auto_mode_server`), a user's own is left alone, and it goes when Claude Code is taken off magpie (`desktopOnly`, `unroute`). T3 Code's magpie instance, which runs Claude Code on the gateway through its own environment, carries the same `"0"` there by the models it lists (`t3InstanceJSON` in [`t3code.go`](../../internal/agent/t3code.go)); a value in the user's `~/.claude` settings comes after it. - Claude Code takes one window (`CLAUDE_CODE_MAX_CONTEXT_TOKENS`, `claudeContextEnv` in [`claude.go`](../../internal/agent/claude.go)) for every model it doesn't know. Claude Code alone on magpie is told its main model's (`claudeWindow`). While Claude Desktop is on magpie too, its Code tab runs Claude Code on the same `~/.claude/settings.json` with every model Desktop lists, so magpie tells it the largest window of those and of Claude Code's own models, and holds each model below it to its own with `modelSettings..autoCompactWindow` (`claudePlan` in [`claude_budget.go`](../../internal/agent/claude_budget.go), #2025: the least held a 1M model to 131K). Claude Code 2.1.296 matches that key by the id it was handed, lowercased and without `[1m]`; it comes before the top-level `autoCompactWindow`, which serves a model without one. `CLAUDE_CODE_AUTO_COMPACT_WINDOW` would take precedence over both, so in this mode magpie's working window goes in the top-level `autoCompactWindow` instead, and an entry is written only where a model's window or its own threshold differs from what it would run at without one. magpie's entries and top-level value are stashed (`claude.model_budgets`, `claude.compact_default`) and go when Desktop leaves magpie; the user's own entries, top-level value and variables stay, a user's entry past its model's window (or `auto`) holds the largest to that window, and with a `CLAUDE_CODE_AUTO_COMPACT_WINDOW` of the user's the least window is told as before. +- Claude Code is told what each of magpie's models can do in `CLAUDE_CODE_MODEL_CAPABILITIES` (`claudeCapsEnv`, `claudeCapabilities` in [`claude.go`](../../internal/agent/claude.go)): `=effort[,xhigh_effort][,max_effort]` for those it is shown, and, while Claude Desktop is on magpie, for Desktop's `mythos-magpie-` ids its Code tab hands it. A Claude model Claude Code knows gets no more than Claude Code gives it (Opus and Sonnet 4.6: no xhigh), and one with no known levels isn't named. A model that reaches max without xhigh (GLM-5.3 at low/high/max, DeepSeek V4 at high/max) is said to have xhigh too: the gateway runs xhigh at max for it (`fitEffort`), and Claude Code 2.1.299 turns Ultracode down without `xhigh_effort` ("Ultracode isn't available on …"), which in Desktop is the Ultracode level and dynamic workflows (leesunrise2364 on Discord; `TestClaudeModelCapabilities`). A value of the user's is left alone. - MiniMax Code takes a model ref with one slash in the whole (a SubAgent's `model` must match `^[^/\s]+\/[^/\s]+$`, #1387), and magpie's refs there are `custom_provider:magpie/`. So a model under `custom_provider.magpie` is written with `~` for each slash of its catalog id (`bb-codex~gpt-6.1-sol`, `provider.FlatID`), only when that spelling stands for one served id (`provider.Flattened`); the gateway takes it back. A config an older magpie wrote moves over on the next sync: the user's keys on a model go to its new key, `defaultModel`, `defaultLightModel` and `memory.captureModel`/`consolidationModel` follow (`mcodeRefs`), and the slashed key stays, switched off (`enabled: false`), so a session begun on it still resumes. magpie never edits the user's own `agents//agent.md`. No other agent was found with this limit ([`minimax.go`](../../internal/agent/minimax.go)). - 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:.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`, `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-.anthropic.`, 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-`, an unknown model, and Haiku 4.5 got an effort Copilot refuses, #1819); a request for it is served by `` 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)). diff --git a/internal/agent/claude.go b/internal/agent/claude.go index 0e2b554ae..a6a880de2 100644 --- a/internal/agent/claude.go +++ b/internal/agent/claude.go @@ -199,7 +199,9 @@ const claudeUnknownOutput = 32000 // a gateway (CLAUDE_CODE_USE_GATEWAY, as Claude Desktop's Code tab runs it) // it otherwise takes no model of magpie's for one with effort, xhigh or max, // so "ultracode": true, which needs xhigh, did nothing (#430). Each magpie -// model is said to have only the levels magpie knows it has. +// model is said to have only the levels magpie knows it has, and xhigh +// with max: the gateway runs xhigh at max for one without it, and without +// xhigh_effort Claude Code turns Ultracode down (leesunrise2364 on Discord). const claudeCapsEnv = "CLAUDE_CODE_MODEL_CAPABILITIES" // claudeReviewEnv is whether Claude Code's auto mode asks the API to review @@ -292,6 +294,12 @@ func claudeCapabilities(first []string, own, desktop bool) string { return } levels = slices.DeleteFunc(slices.Clone(levels), func(l string) bool { return !contains(claudeEffortsFor(id), l) }) + // one that reaches max without xhigh runs xhigh at max (the + // gateway's fitEffort), and Claude Code's Ultracode needs + // xhigh_effort (2.1.299: "Ultracode isn't available on …") + if contains(levels, "max") && !contains(levels, "xhigh") && contains(claudeEffortsFor(id), "xhigh") { + levels = append(levels, "xhigh") + } if c := claudeCaps(levels); c != "" && !slices.ContainsFunc(segs, func(s seg) bool { return s.id == id }) { segs = append(segs, seg{id, c}) } diff --git a/internal/agent/claude_caps_test.go b/internal/agent/claude_caps_test.go index d1ccf15e1..8ff1b7ce2 100644 --- a/internal/agent/claude_caps_test.go +++ b/internal/agent/claude_caps_test.go @@ -16,7 +16,10 @@ import ( // in CLAUDE_CODE_MODEL_CAPABILITIES what each of its models (and Desktop's // mythos-magpie- for it) can do, only the levels the model has, the // model Claude Code is set to first; a value of the user's is left alone, -// and magpie's goes when Claude Code is taken off magpie. +// and magpie's goes when Claude Code is taken off magpie. One that reaches +// max without xhigh (GLM, DeepSeek) is said to have xhigh too: the gateway +// runs it at max, and Claude Code's Ultracode needs xhigh_effort +// (leesunrise2364 on Discord, Ultracode missing on Desktop). func TestClaudeModelCapabilities(t *testing.T) { home := t.TempDir() t.Setenv("HOME", home) @@ -26,12 +29,14 @@ func TestClaudeModelCapabilities(t *testing.T) { 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: "http://127.0.0.1:1/v1", Key: "k", - Models: []string{"Deep", "mid", "plain", "claude-opus-4-6"}}); err != nil { + Models: []string{"Deep", "mid", "plain", "claude-opus-4-6", "glm", "top"}}); err != nil { t.Fatal(err) } for id, levels := range map[string][]string{ "v/Deep": {"low", "medium", "high", "xhigh", "max"}, "v/mid": {"low", "medium", "high"}, + "v/glm": {"low", "high", "max"}, + "v/top": {"high", "max"}, // Claude Code sends Opus 4.6 no xhigh, whatever the vendor says "v/claude-opus-4-6": {"low", "medium", "high", "xhigh", "max"}, } { @@ -69,6 +74,8 @@ func TestClaudeModelCapabilities(t *testing.T) { "v/mid": "effort", "group/both": "effort", "v/claude-opus-4-6": "effort,max_effort", + "v/glm": "effort,xhigh_effort,max_effort", + "v/top": "effort,xhigh_effort,max_effort", } { if got[id] != want { t.Errorf("%s: %q, want %q (%s)", id, got[id], want, caps()) @@ -175,7 +182,7 @@ func TestClaudeCapabilitiesSync(t *testing.T) { if err := a.Sync(); err != nil { t.Fatal(err) } - if caps() != "v/a=effort,xhigh_effort;w/b=effort,max_effort" { + if caps() != "v/a=effort,xhigh_effort;w/b=effort,xhigh_effort,max_effort" { t.Fatalf("after w/b was added: %q", caps()) } } diff --git a/internal/gateway/effort_test.go b/internal/gateway/effort_test.go index 4c4c6712a..3799d112f 100644 --- a/internal/gateway/effort_test.go +++ b/internal/gateway/effort_test.go @@ -24,6 +24,7 @@ func TestFitEffort(t *testing.T) { {"medium", glm, "high"}, // a tie goes up {"low", glm, "low"}, {"xhigh", glm, "max"}, + {"xhigh", []string{"high", "max"}, "max"}, // DeepSeek V4: Ultracode's xhigh {"max", []string{"low", "medium", "high"}, "high"}, {"low", []string{"none", "minimal", "medium"}, "medium"}, {"medium", nil, "medium"}, // levels not known: as asked