claude-desktop: a model picked for two tiers no longer shows twice in the menu (yanghonghang on X)

v0.1.3997 showed "Gemini 4 Hydrogen · haiku" beside "Gemini 4 Hydrogen"
in Claude Desktop's model menu. dbaeaec12 (#5534) listed a model picked
for two Desktop tiers once more in magpie's inferenceModels, under an
alias id for the later tier, so Claude Code's ANTHROPIC_DEFAULT_<TIER>_MODEL
had a model. But that list is Desktop's model menu (gXn in 4.23118), so the
alias showed as a model of its own.

The later tier's alias is now a row of Desktop's /v1/models only
(DesktopTierRows: a copy of the model's row with the alias id, tagged
anthropic_family_tier and is_family_default). Desktop's gateway provider
pins a tier the list leaves out from a tagged discovered row
(shortnameIdentityOverrides, 4.23118). The list's own pins (IPn) go on top.
With an admin list, Desktop reads /v1/models only when the profile sets
modelDiscoveryEnabled, so magpie's profile carries modelDiscoveryEnabled:
true while a tier is shared (DesktopDiscovers, desktopSyncDiscovery). It
takes the value back once the picks are apart, or when the list is the
user's own. A value the user set is never written over or removed
(desktopDiscoveryMark in the stash). The gateway still reads the alias back
to the pick, so the tier is served as before.

Trade-off: Desktop takes behavesAs only from the list, so the later tier's
alias has none. A non-Claude model shared by two tiers runs on Claude
Code's generic prompt in the later tier, as an id Claude Code doesn't know.
Its window is the session's top (no modelSettings entry is needed when it
matches).

Run (mote, at this head):
- gofmt -l: clean
- go vet: darwin, GOOS=linux -tags nogui, GOOS=windows on internal/gateway
  and internal/agent
- go test -count=1 ./internal/gateway ./internal/agent: ok (1079s, 259s;
  mote at load ~38)

Red on the old code: the new TestDesktopTierSharedPick (all 4 subtests,
"3 entries in Desktop's model menu for 2 models ... labelOverride:
claude-sonnet-5-5 · Fake · haiku") and TestClaudeDesktopModelsSharedTier
were run against 406ad72f1's desktop_list.go with only the two new
functions added.

Broken by hand, each red:
- no DesktopTierRows in listModels: TestDesktopTierSharedPick, "haiku has
  no row".
- discovery never written: TestClaudeDesktopModelsSharedTier.
- the user's own modelDiscoveryEnabled taken away (`!on && has`):
  TestClaudeDesktopModelsSharedTier, "the user's true".

Checked against Desktop 4.23118's app.asar (on mote):
- shortnameIdentityOverrides skips only rows that are restricted (JT) or
  need an update (MMn).
- FPn/IPn pin only the tiers the list tags.
- adminListObviatesDiscovery is skipped once modelDiscoveryEnabled is set.

Not tried: a real Claude Desktop run with the reporter's picks. A [1m]
pick's later tier is pinned without [1m] (the row says supports_1m).
This commit is contained in:
yetone
2026-11-13 14:16:12 +08:00
parent dea131174d
commit a96d88effa
9 changed files with 291 additions and 118 deletions
+1 -1
View File
@@ -184,7 +184,7 @@ something else shows up as drift.
- 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. Unset, the GUI says "Lead's pick": the lead may name one of Codex's own models, which goes through Codex's ChatGPT sign-in. "Same as the lead" is the value `lead` (`provider.CodexSubagentLead`): every subagent on the model the lead's own turns go on, whatever it names (cleverpigo on X: a lead on WorkBuddy's DeepSeek named `gpt-5.6-sol`, the first of Codex's own models `spawn_agent` lists, under what then read "Same as the lead").
- 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 tiers also write magpie's profile's `inferenceModels` (`desktopSyncModels` in [`claudedesktop_models.go`](../../internal/agent/claudedesktop_models.go)), the list `gateway.DesktopInferenceModels` gives (see [gateway routing](gateway-routing.md)): on a tier's `Set`, as Desktop comes on magpie, and on the agent's `Sync`, so a provider saved or removed reaches it through `SyncCatalog`. Desktop 4.4212 reads no `/v1/models` while such a list has no bare tier word as a name (`adminListObviatesDiscovery` in its app.asar) and names an entry by its `labelOverride`, else its catalog's name, else the id, so every entry carries the `display_name` `/v1/models` gives its row as `labelOverride`; without it every `mythos-magpie-<number>` read as that id once a tier was picked (chengming0v0 on Discord, `TestDesktopInferenceModelsNamed`), and a catalog-named Claude model reads as that name too ("Opus 5.5 · <provider>") while the list is written. It is written through temp-and-rename and only when it changed, and taken away when no tier is picked. The list is magpie's only while its hash is one magpie recorded (`desktopModelsMark` in the stash, the next hash recorded before each write); any other list, the user's own or one carried from their own gateway profile, is never written over or taken away. A pick that runs as a Claude model (`behavesAs`) is told its own window in Claude Code's `modelSettings` (`claudeBudget.behaves`), since Claude Code would otherwise run it at that Claude model's. A model picked for two tiers is listed for the second by an id of its own (`gateway.DesktopTierAliases`), and Claude Code's settings carry that id's window and reasoning levels as they carry the first's (`claudeCapabilities`, the `modelSettings` budgets; `TestClaudeDesktopModelsSharedTier`, `TestClaudeCapabilitiesDesktopSharedTier`). Desktop reads the list as it starts. Not tried against a real Desktop 4.29 or later; a Desktop below 2 (no mythos word) is given the mythos ids `/v1/models` gives 2 and up. `TestClaudeDesktopModelsList`.
- Claude Desktop's tiers also write magpie's profile's `inferenceModels` (`desktopSyncModels` in [`claudedesktop_models.go`](../../internal/agent/claudedesktop_models.go)), the list `gateway.DesktopInferenceModels` gives (see [gateway routing](gateway-routing.md)): on a tier's `Set`, as Desktop comes on magpie, and on the agent's `Sync`, so a provider saved or removed reaches it through `SyncCatalog`. Desktop 4.4212 reads no `/v1/models` while such a list has no bare tier word as a name (`adminListObviatesDiscovery` in its app.asar) and names an entry by its `labelOverride`, else its catalog's name, else the id, so every entry carries the `display_name` `/v1/models` gives its row as `labelOverride`; without it every `mythos-magpie-<number>` read as that id once a tier was picked (chengming0v0 on Discord, `TestDesktopInferenceModelsNamed`), and a catalog-named Claude model reads as that name too ("Opus 5.5 · <provider>") while the list is written. It is written through temp-and-rename and only when it changed, and taken away when no tier is picked. The list is magpie's only while its hash is one magpie recorded (`desktopModelsMark` in the stash, the next hash recorded before each write); any other list, the user's own or one carried from their own gateway profile, is never written over or taken away. A pick that runs as a Claude model (`behavesAs`) is told its own window in Claude Code's `modelSettings` (`claudeBudget.behaves`), since Claude Code would otherwise run it at that Claude model's. A model picked for two tiers is given an id of its own for the second (`gateway.DesktopTierAliases`), served in `/v1/models` only, so while one is the profile also carries `modelDiscoveryEnabled: true` (`desktopSyncDiscovery`, `desktopDiscoveryMark` in the stash: magpie takes away only the value it wrote, never one the user set, and turns its own off when the list is the user's), and Claude Code's settings carry that id's window and reasoning levels as they carry the first's (`claudeCapabilities`, the `modelSettings` budgets; `TestClaudeDesktopModelsSharedTier`, `TestClaudeCapabilitiesDesktopSharedTier`). Desktop reads the list as it starts. Not tried against a real Desktop 4.29 or later; a Desktop below 2 (no mythos word) is given the mythos ids `/v1/models` gives 2 and up. `TestClaudeDesktopModelsList`.
- 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)).
- Claude Desktop picks its userData in its main process before any window opens: while a 3p configuration is applied and `deploymentMode` isn't `"1p"`, it is `Claude-3p` (Desktop 2.7032's `index.pre.js`, `app.setPath("userData", …-3p)`). So turning Desktop onto magpie shows none of the chats, projects and Code sessions of the Anthropic sign-in, which stay in `Claude` (xgddm88 on X: 之前的工程和会话记录全没了). magpie writes nothing in `Claude` but `deploymentMode` in its `claude_desktop_config.json`, and reads its `config.json` for the language; Off brings that history back. A row not yet connected says so before it is turned on (`CONNECT_BEFORE` in `app.js`), the opened row once it is on (`CONNECT_COST`), and the notice after each change (`noticeClaudedesktop3`, `noticeClaudedesktop4`; `TestClaudeDesktopKeepsTheSignedInHistory`, `desktop-history.test.cjs`). Opus beside the gateway's other models in that mode comes from a Claude subscription added in magpie. With `disableDeploymentModeChooser` unset Desktop's login screen would offer Claude.ai sign-in too; magpie still seeds it (as CC Switch does), so the way back is Off. The drift check asks Desktop's own question (`desktop3p`, `m4` in 4.4212's and 2.7032's `index.pre.js`): Desktop is off magpie only when Claude-3p's `deploymentMode` is `"1p"` and the applied profile leaves the chooser on. The `Claude` folder's `deploymentMode` isn't read, and Desktop 4.4212 deletes Claude-3p's itself (a stored `"1p"` with no claude.ai sign-in is dropped at start, `deploymentMode written { mode: undefined }`), so a missing one is still magpie (dev_quj on X; `TestClaudeDesktopModeAsDesktopReadsIt`).
- Claude Desktop's gateway address (`gateway` field, `DesktopGateway` in settings, [`claudedesktop_gateway.go`](../../internal/agent/claudedesktop_gateway.go); zyc-bit and ZYar-er on X, #4546). Desktop's built-in SSH remote sessions hand the profile's address and key to the remote host, which refuses a loopback address (`provider_loopback`), a non-https one off loopback ("must use https (or http on loopback)") and any host the profile's `sshHostAllowlist` (empty in 3p mode) doesn't list. So while LAN sharing is on and an address of this computer is https (`gateway.LANURLs`, HTTPS on or a `MAGPIE_PUBLIC_URL`), the row offers it beside "This computer"; the profile then holds that address and the sharing key (`agentKeyAt`), and `sshHostAllowlist` is seeded once with `["*"]` (`desktopSeedOnce`; the user may narrow it, magpie never writes it again). The pick holds only while it is still one of `desktopLANURLs()` (the first one where the network moved, loopback with sharing off): `Agent.Gateway` is `desktopGateway`, and `Rekey` runs after the sharing and HTTPS toggles, which sets Desktop again. `desktopIsOurGateway` takes this computer's own LAN addresses too, and `realReachProbe` doesn't verify a certificate (magpie's CA isn't trusted here). The remote host must trust magpie's CA (or use an imported certificate) for Desktop's requests from there. (`TestDesktopPointedAtLANHTTPS`, `desktop-gateway-address.test.cjs`)
+1 -1
View File
@@ -400,7 +400,7 @@ recorded as a prediction failure (`noPrediction`).
- A request translated to a Chat or Responses upstream that carries no `prompt_cache_key` of the client's (every Anthropic client's) gets one for its conversation when the provider is OpenAI's API with a key or one the user added by its address (`ownCacheKey`, `cacheKeyOf` in [`gateway.go`](../../internal/gateway/gateway.go)): a hash, in a UUID's shape, of the session the client names, else of its first user message, so every turn of it has the same key and nothing in it names the client or magpie. A relay can turn a request away without one ("prompt_cache_key is required", CyberCaius's AnyRouter). A vendor's preset, a signed-in account, a plugin, Bedrock and Vertex get none, nor does a provider whose extraBody names `prompt_cache_key` (the user's value is sent). An upstream whose 400 names the field is asked again without it and not sent it again; another 400 is not asked again for it, so an unrelated refusal is tried as often as before.
- Claude Desktop's check that a gateway model answers (`{"max_tokens":1,"messages":[{"role":"user","content":"."}]}`, sent as it starts and by its settings' Test connection on the shortest id it is listed with haiku in it, else sonnet, else opus, else the first model listed; `desktopProbe` in [`desktop.go`](../../internal/gateway/desktop.go)) goes to the model the user chose in one of Desktop's own model menus that magpie still serves (`desktopChosen`: `__model_selector_state` in Claude-3p's `local-agent-mode-sessions/<account>/<org>/cowork_account_settings.json`, in the order Code, Cowork, Chat; cybercaius's DeepSeek in the Code tab, v0.1.2033), unless a session's turn was sent after that file was last written: then the model that turn was for (`desktopPicked`), while magpie serves it, the newer of the two being what the user is on now (before, the last session's model came first whenever any menu still held it, so the Code tab switched off DeepSeek with Cowork left on it kept the check on DeepSeek, cybercaius on Discord, v0.1.2212), else to Desktop's default model, the first one listed to it (`desktopDefault`; Desktop's own settings call the first listed model the default), never to the haiku it names, which is another provider's quota, nor, with no menu chosen, to the model the last session ran on (`desktopPicked`), which can be days old: v0.1.1821 sent it there, a relay's GPT model CyberCaius had left for his routing group, and the relay turned it away (Discord, v0.1.1838). It is asked for 16 tokens upstream (`desktopProbeTokens`): OpenAI's models refuse fewer, and a relay in front of one (AnyRouter's "bad response status code 400") passes on no floor for `tokenFloor` to ask again at. A relay that needs `prompt_cache_key` gets one (above). It is recorded with kind `connection_check` (`KindDesktopCheck`), which the Routing page tags "Connection check" with why its model is the id Desktop named and not the one chosen in the conversation: a list with no Claude-named id made the row read "requested deepseek-flash" while the menu's gpt-6.1-sol answered (cybercaius on Discord, v0.1.2212). `TestClaudeDesktopProbeToDefaultModel`, `TestClaudeDesktopProbeToChosenModel`. `TestClaudeDesktopProbeAsksNoClassifier` checks the kind.
- Claude Desktop's `/v1/models` tags a model with `anthropic_family_tier` only when the user picked it for that tier (`DesktopTiers`, the Agents page's opus, sonnet, haiku and fable). Before, a Claude model magpie served was tagged with its own tier unpicked, so Desktop's Code tab told Claude Code to run its haiku calls (its small, fast model) on whichever provider served a `claude-haiku-…`: a chat on AgentRouter's gpt-6.1-sol sent them to Leee's `claude-haiku-5-5` (cybercaius on Discord). Untagged, Claude Code asks for its own id of the tier. A background call (no tools) or a subagent's turn asking for a Claude model by Claude's own id that is no catalog id (`claudeOwnID`) stays on the chat's provider (`desktopPicked`), even when another provider serves a model of that name: `servedBeside` gives that provider's model of that name, else its newest model of the tier, beside the chat's model first, else the call goes to the chat's model. The provider's Claude models stand in only when the chat itself is on one of them: a chat on Leee's DeepSeek had Claude Code's sonnet calls sent to Leee's `claude-sonnet-5-5`, which its key may not use (403, CyberCaius on Discord), so Claude Code's own calls in a chat on another vendor's model go to the chat's model, and a tier the user picked takes Claude Code's own id of it even where a provider lists a model by that name (`TestClaudeDesktopNonClaudeChatKeepsTierCalls`). A lead's turn and an id the user picked for a tier (a catalog id) go as asked. `TestClaudeDesktopBackgroundStaysOnChatProvider`.
- While a model is picked for one of Claude Desktop's tiers, magpie's Desktop profile also lists Desktop's models in `inferenceModels` (`DesktopInferenceModels` in [`desktop_list.go`](../../internal/gateway/desktop_list.go)), so a pick that isn't a Claude model runs in the Code tab with the prompt of its tier's newest Claude model (`behavesAs`: `claude-opus-5-5`, `claude-sonnet-5-5`, `claude-haiku-5-5`, Desktop's catalog v3739; `claude-fable-5-2`, Claude Code 2.1.321's newest Fable, which Desktop's catalog v4371 doesn't list yet), not Claude Code's generic one (moer2831 on Discord). Desktop 4.29 and later hand Claude Code `behavesAs` only from that list (z3t in its app.asar, 4.4212: `modelPicker.options` with each entry's `behavesAs`); the gateway's `behaves_as` row field feeds Desktop's own effort profile only. A non-empty list replaces `/v1/models` in Desktop's menus (pzn: a discovered row gives only its name and description, by id), so the list is every row `/v1/models` gives Desktop, by its id and in its order, each with what Desktop would have read off the row: `supports1m` for a window of 1M and up, `prefer1m` (and the row's `display_name` as `labelOverride`, where Desktop names the row by display_name) for a model listed by its `[1m]` id, and a pick's `anthropicFamilyTier` with `isFamilyDefault`. Desktop keys the list by name and reads one tier off an entry (FPn in its app.asar, 4.23118: the entry tagged with a tier names its `ANTHROPIC_DEFAULT_<TIER>_MODEL`), so a model picked for two tiers is tagged with the first (`desktopTierOf`) and listed once more, after the rows, for each later tier (`desktopSharedTiers`), by its id's form under a number of its own (`desktopTierAlias`: magpie-<number>.anthropic.<model>, mythos-magpie-<number> or anthropic/magpie-<number>), which `aliased` reads back to the model, so the gateway serves it as the pick (`desktopTierAsked`). Before, the later tier had no model: copilot/claude-sonnet-5.5 picked for sonnet and haiku gave Claude Code an empty `ANTHROPIC_DEFAULT_HAIKU_MODEL`, and its small tasks, WebFetch's page summaries among them, ran on the session's model. The rows stay first, so a new session still starts on the first row. A Claude model picked runs as itself where Claude Code knows it by the id it is listed by; a routing group led by one is listed by its mythos-magpie-<number> and runs as the group's model, as one listed by anthropic/magpie-<number> does (`desktopRunsAs`; `TestDesktopTierSharedPick`, `TestDesktopGroupPickRunsAsItsModel`). Nothing picked (or a pick of a model no longer listed): no list, and Desktop finds the models as before. Picks that can't be read are unknown, and what is written stays. Older builds take the entries' names and drop the rest (2.7032's entry is a zod object, which strips unknown keys). Desktop reads its profile only as it starts, so the tiers' menu says to restart it, and the Agents row's Restart shows (`AppBehind` reads the profile). `TestDesktopInferenceModels`.
- While a model is picked for one of Claude Desktop's tiers, magpie's Desktop profile also lists Desktop's models in `inferenceModels` (`DesktopInferenceModels` in [`desktop_list.go`](../../internal/gateway/desktop_list.go)), so a pick that isn't a Claude model runs in the Code tab with the prompt of its tier's newest Claude model (`behavesAs`: `claude-opus-5-5`, `claude-sonnet-5-5`, `claude-haiku-5-5`, Desktop's catalog v3739; `claude-fable-5-2`, Claude Code 2.1.321's newest Fable, which Desktop's catalog v4371 doesn't list yet), not Claude Code's generic one (moer2831 on Discord). Desktop 4.29 and later hand Claude Code `behavesAs` only from that list (z3t in its app.asar, 4.4212: `modelPicker.options` with each entry's `behavesAs`); the gateway's `behaves_as` row field feeds Desktop's own effort profile only. A non-empty list replaces `/v1/models` in Desktop's menus (pzn: a discovered row gives only its name and description, by id), so the list is every row `/v1/models` gives Desktop, by its id and in its order, each with what Desktop would have read off the row: `supports1m` for a window of 1M and up, `prefer1m` (and the row's `display_name` as `labelOverride`, where Desktop names the row by display_name) for a model listed by its `[1m]` id, and a pick's `anthropicFamilyTier` with `isFamilyDefault`. Desktop keys the list by name and reads one tier off an entry (FPn in its app.asar, 4.23118: the entry tagged with a tier names its `ANTHROPIC_DEFAULT_<TIER>_MODEL`), so a model picked for two tiers is tagged with the first (`desktopTierOf`). Each later tier (`desktopSharedTiers`) gets the model's id form under a number of its own (`desktopTierAlias`: magpie-<number>.anthropic.<model>, mythos-magpie-<number> or anthropic/magpie-<number>), which `aliased` reads back to the model, so the gateway serves it as the pick (`desktopTierAsked`). That id is a row of Desktop's `/v1/models` only (`DesktopTierRows`, a copy of the model's row tagged `anthropic_family_tier` and `is_family_default`), never a list entry: the list is Desktop's model menu, and an entry there showed as a model of its own, "Gemini 4 Hydrogen · haiku" beside "Gemini 4 Hydrogen" (yanghonghang on X, v0.1.3997). Desktop's discovery pins a tier the list leaves out from a tagged row (`shortnameIdentityOverrides` in its app.asar, 4.23118, under the list's own pins), and with a list it reads `/v1/models` only when the profile says `modelDiscoveryEnabled`, which magpie's profile carries while a tier is shared (`DesktopDiscovers`). The later tier has no `behavesAs`, which Desktop takes only from the list, so a model that isn't Claude runs there on Claude Code's generic prompt. Before, the later tier had no model: copilot/claude-sonnet-5.5 picked for sonnet and haiku gave Claude Code an empty `ANTHROPIC_DEFAULT_HAIKU_MODEL`, and its small tasks, WebFetch's page summaries among them, ran on the session's model. A Claude model picked runs as itself where Claude Code knows it by the id it is listed by; a routing group led by one is listed by its mythos-magpie-<number> and runs as the group's model, as one listed by anthropic/magpie-<number> does (`desktopRunsAs`; `TestDesktopTierSharedPick`, `TestDesktopGroupPickRunsAsItsModel`). Nothing picked (or a pick of a model no longer listed): no list, and Desktop finds the models as before. Picks that can't be read are unknown, and what is written stays. Older builds take the entries' names and drop the rest (2.7032's entry is a zod object, which strips unknown keys). Desktop reads its profile only as it starts, so the tiers' menu says to restart it, and the Agents row's Restart shows (`AppBehind` reads the profile). `TestDesktopInferenceModels`.
- Antigravity answers a system instruction holding one of a few lines with a 429 "Resource has been exhausted" whatever quota is left, on every model (`agTurnedAway` in [`codeassist.go`](../../internal/gateway/codeassist.go)): Claude Code's billing line, the Claude Agent SDK's identity line, Codex's identity lines for its GPT-5 models (which a Codex thread begun on a GPT model keeps after a switch), and Hermes Agent's earlier default persona. An Antigravity account's system instruction goes with zero-width spaces after the first and second character of every word of each such line (`antigravityCloak`, in `codeAssistBody`; one after the first letter only was turned away again on 11-11 for Claude Code's two lines, with Claude Code 2.1.316's prompt on a real account), which Google lets through and the model reads the same; every other provider, Gemini CLI's sign-in on the same envelope included, is sent the prompt as written. `magpie provider set antigravity prompt=as-written` (`Provider.PromptAsWritten`) turns it off. The refusal is still told against the system prompt as the agent wrote it (`antigravityTurnedAway`): a 400 with the hint for that prompt, the account not rested, and a group skipping Antigravity for that prompt for 6 hours after a refusal (`antigravityForeseen`).
- Claude Code's advisor (`/advisor`, `--advisor`) is Anthropic's server tool `advisor_20260301`, its `model` named as Claude Code names its own: on magpie, by magpie's id (the tier an alias like `opus` is on), which no vendor knows, so the request was turned away whole (JackChou on Discord). Relayed on Messages (`passthrough`), the advisor's model goes as the upstream's own name for it when it is the same provider's Claude model, or a Claude id naming no provider (`advisorTools` in [`advisor.go`](../../internal/gateway/advisor.go)); one it can't run there (another provider's, a group, not Claude's) is left out, as is every advisor when the request's own model isn't a Claude model (a vendor's Messages API knows no such tool), and the turn is answered without one. A translation drops it with every other server tool. Claude Code (2.1.300) also puts the advisor in the conversation: a `{role: "system"}` message whose text ends in its instructions ("# Advisor Tool … call advisor BEFORE substantive work") and a `tool_addition` naming it. Where the advisor is left out, that `tool_addition` goes too (and a message it leaves empty), and the instructions become Claude Code's own "The advisor tool is no longer available; disregard the earlier advisor instructions." (`withoutAdvisor` on Messages, `advisorGoneIn` in `parseAnthropic` for a translation): left there, the model called `advisor()` as one of the agent's tools and Claude Code answered "No such tool available: advisor" (JackChou on Discord). The Claude subscription's run declares only magpie's tools, so it never has one. `TestAdvisorModelAsTheUpstreamNamesIt`, `TestAdvisorLeftOutOnTranslation`.
- Kiro is told where to cache the prompt (plugins#110: a Kiro subscription read 0 from its cache). Its API takes Bedrock's `cachePoint: {"type":"default"}` on a `userInputMessage`, an `assistantResponseMessage` or as a tool entry. The built-in (`buildKiro` in [`kiro.go`](../../internal/gateway/kiro.go)) marks the first message when there is a system prompt, which it folds into that message, and the current message, as `buildAnthropic` marks Anthropic's. A moved Kiro's plugin (opencode-kiro-auth 0.1.10, the mover's `min`) turns each `cache_control` in the Anthropic body it is handed into one, at most 4, the last kept.
+1 -1
View File
@@ -627,7 +627,7 @@ const (
desktopMCPSeen = "claude-desktop.mcp-seen"
)
var desktopStashKeys = []string{desktopStashed, desktopMode, desktopMode3p, desktopApplied, desktopMade, desktopProfile, desktopLocale, desktopImport, desktopSearch, desktopSSH, desktopMCP, desktopMCPSeen, desktopModelsMark}
var desktopStashKeys = []string{desktopStashed, desktopMode, desktopMode3p, desktopApplied, desktopMade, desktopProfile, desktopLocale, desktopImport, desktopSearch, desktopSSH, desktopMCP, desktopMCPSeen, desktopModelsMark, desktopDiscoveryMark}
// desktopAdoptStash moves the stash a packaged Desktop's folders got
// before they had keys of their own (when magpie wrote only one set) onto
+37 -1
View File
@@ -23,6 +23,12 @@ import (
// takes away. Desktop reads its profile at start-up only.
const desktopModelsMark = "claude-desktop.models"
// desktopDiscoveryMark says magpie wrote the profile's
// modelDiscoveryEnabled (gateway.DesktopDiscovers): magpie takes it away
// only then, and only while it is still true. One the user wrote, either
// way, stays as they wrote it.
const desktopDiscoveryMark = "claude-desktop.discovery"
// desktopModelsHash is a list's hash, the same however it is spaced.
func desktopModelsHash(raw []byte) string {
var v any
@@ -53,7 +59,11 @@ func desktopSyncModels(p desktopPaths) error {
}
raw, has := edit.GetJSONRaw(p.prof, "inferenceModels")
if has && !slices.Contains(marks, desktopModelsHash([]byte(raw))) {
return nil // the user's
return desktopSyncDiscovery(p, false) // the list is the user's
}
discovers, _ := gateway.DesktopDiscovers()
if err := desktopSyncDiscovery(p, want != nil && discovers); err != nil {
return err
}
if want == nil {
if has {
@@ -82,3 +92,29 @@ func desktopSyncModels(p desktopPaths) error {
stash(map[string]string{key: h})
return nil
}
// desktopSyncDiscovery has Desktop read /v1/models beside magpie's
// inferenceModels while on, where Desktop's Code tab finds a later tier of
// a model picked for two (gateway.DesktopDiscovers), and takes back the
// modelDiscoveryEnabled magpie wrote once off. Unset, Desktop skips
// /v1/models while the list names no bare tier word.
func desktopSyncDiscovery(p desktopPaths, on bool) error {
key := desktopDiscoveryMark + p.key
ours := stashShared()[key] != ""
raw, has := edit.GetJSONRaw(p.prof, "modelDiscoveryEnabled")
if ours && (!has || strings.TrimSpace(raw) != "true") {
forget(key) // taken away or changed: the user's now
ours = false
}
switch {
case on && !has:
stash(map[string]string{key: "1"})
return edit.SetJSON(p.prof, edit.KV{Path: "modelDiscoveryEnabled", Value: true})
case !on && ours:
if err := edit.DelJSON(p.prof, "modelDiscoveryEnabled"); err != nil {
return err
}
forget(key)
}
return nil
}
+56 -14
View File
@@ -158,12 +158,15 @@ func TestClaudeDesktopModelsList(t *testing.T) {
}
}
// A model picked for two of Desktop's tiers is listed once more for the
// second (gateway.DesktopTierAliases), by an id of its own: Desktop keys
// the list by name and reads one tier off an entry, so before, the second
// tier had no model and Claude Code ran it on the session's model. Claude
// Code is told the pick's window under that id too, since it would take
// the behavesAs model's.
// A model picked for two of Desktop's tiers gets an id of its own for the
// second (gateway.DesktopTierAliases): Desktop keys the list by name and
// reads one tier off an entry, so before, the second tier had no model and
// Claude Code ran it on the session's model. That id was then listed in
// inferenceModels, which is Desktop's model menu, and showed as a model of
// its own, "<name> · haiku" (yanghonghang on X). It goes in /v1/models
// only, so the profile turns Desktop's discovery on beside the list while
// a tier is shared, and off again after, unless the user set it. Claude
// Code holds that id to the pick's window too.
func TestClaudeDesktopModelsSharedTier(t *testing.T) {
home, p := desktopSandbox(t)
if err := provider.Save(provider.Provider{ID: "v", Name: "V", Chat: "http://127.0.0.1:1/v1", Key: "k", Models: []string{"a", "b"}}); err != nil {
@@ -175,11 +178,19 @@ func TestClaudeDesktopModelsSharedTier(t *testing.T) {
cc := filepath.Join(home, ".claude", "settings.json")
writeFile(t, cc, `{"theme":"dark"}`)
d := claudeDesktop(home)
for _, kv := range [][2]string{{"provider", "magpie"}, {"sonnet", "v/a"}, {"haiku", "v/a"}} {
if err := d.Field(kv[0]).Set(kv[1]); err != nil {
set := func(k, v string) {
t.Helper()
if err := d.Field(k).Set(v); err != nil {
t.Fatal(err)
}
}
discovery := func() string {
raw, _ := edit.GetJSONRaw(p.prof, "modelDiscoveryEnabled")
return raw
}
for _, kv := range [][2]string{{"provider", "magpie"}, {"sonnet", "v/a"}, {"haiku", "v/a"}} {
set(kv[0], kv[1])
}
raw, ok := edit.GetJSONRaw(p.prof, "inferenceModels")
if !ok {
t.Fatal("no list")
@@ -189,14 +200,45 @@ func TestClaudeDesktopModelsSharedTier(t *testing.T) {
t.Fatalf("%v: %s", err, raw)
}
again := gateway.DesktopTierAliases()["v/a"]
if len(list) != 3 || len(again) != 1 {
t.Fatalf("a for sonnet and haiku: %v, aliases %v", list, again)
if len(list) != 2 || len(again) != 1 {
t.Fatalf("a for sonnet and haiku, in Desktop's menu: %v, aliases %v", list, again)
}
haiku := list[2]
if haiku["name"] != again[0] || haiku["anthropicFamilyTier"] != "haiku" || haiku["behavesAs"] != "claude-haiku-5-5" {
t.Fatalf("haiku's entry: %v (alias %s)", haiku, again[0])
for _, e := range list {
if e["name"] == again[0] || e["anthropicFamilyTier"] == "haiku" {
t.Fatalf("haiku's own entry in Desktop's menu: %v", list)
}
}
if v, _ := edit.GetJSON(cc, budgetPath(again[0])); v != "272000" {
if discovery() != "true" {
t.Fatalf("a shared tier, discovery: %q\n%s", discovery(), readFile(p.prof))
}
// haiku's id runs as itself, an id Claude Code doesn't know, so at
// its own entry's window, else at the session's top
v, _ := edit.GetJSON(cc, budgetPath(again[0]))
if top, _ := edit.GetJSON(cc, "env.CLAUDE_CODE_MAX_CONTEXT_TOKENS"); v != "272000" && (v != "" || top != "272000") {
t.Fatalf("a's window under haiku's id in Claude Code's settings: %q\n%s", v, readFile(cc))
}
// the picks apart: discovery off again
set("haiku", "v/b")
if v := discovery(); v != "" {
t.Fatalf("picks apart, discovery: %q", v)
}
// the user's own value stays, shared or not
if err := edit.SetJSON(p.prof, edit.KV{Path: "modelDiscoveryEnabled", Value: false}); err != nil {
t.Fatal(err)
}
set("haiku", "v/a")
if v := discovery(); v != "false" {
t.Fatalf("the user's false: %q", v)
}
set("haiku", "v/b")
if err := edit.SetJSON(p.prof, edit.KV{Path: "modelDiscoveryEnabled", Value: true}); err != nil {
t.Fatal(err)
}
set("haiku", "v/a")
set("haiku", "v/b")
if v := discovery(); v != "true" {
t.Fatalf("the user's true: %q", v)
}
}
+69 -38
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"os"
"strings"
@@ -43,16 +44,18 @@ var desktopBehavesAs = map[string]string{
}
// DesktopBehavesAs is the Claude model each picked tier's model runs as in
// Desktop's Code tab, by the id Desktop hands Claude Code (DesktopID, and
// for a tier after the first its desktopTierAlias); one Claude Code knows
// as a Claude model by that id has its own already (desktopRunsAs). ok is
// false when the picks can't be read.
// Desktop's Code tab, by the id Desktop hands Claude Code (DesktopID); one
// Claude Code knows as a Claude model by that id has its own already
// (desktopRunsAs). A tier's own id for a model picked for two
// (desktopTierAlias) has none: Desktop hands Claude Code behavesAs from
// inferenceModels alone, and that id is listed in /v1/models only
// (DesktopTierRows). ok is false when the picks can't be read.
func DesktopBehavesAs() (as map[string]string, ok bool) {
picked, ok := desktopTiersKnown()
if !ok {
return nil, false
}
tierOf, more := desktopTierOf(picked), desktopSharedTiers(picked)
tierOf := desktopTierOf(picked)
shown, _ := provider.CatalogFor("claude-desktop")
as = map[string]string{}
for _, e := range shown {
@@ -61,12 +64,6 @@ func DesktopBehavesAs() (as map[string]string, ok bool) {
as[DesktopID(e)] = b
}
}
for _, t := range more[e.ID] {
id := desktopTierAlias(e, t)
if b := desktopRunsAs(e, id, t); b != "" {
as[id] = b
}
}
}
return as, true
}
@@ -98,32 +95,32 @@ func DesktopTierAliases() map[string][]string {
// Desktop's profile: nil while no model it lists is picked for a tier,
// when Desktop finds magpie's models on its own (/v1/models). ok is false
// when the picks can't be read: whatever is written stays. A model picked
// for a tier after the first it is picked for is listed once more after
// the rows, for that tier (desktopSharedTiers), so the first row, which a
// new session starts on, stays the first.
// for two tiers is tagged here with the first only; the later tiers are
// given it through /v1/models (DesktopTierRows), as every entry here is a
// row of Desktop's model menu, which the list replaces (yanghonghang on X:
// "Gemini 4 Hydrogen · haiku" in the menu beside Gemini 4 Hydrogen).
func DesktopInferenceModels() (list []map[string]any, ok bool) {
picked, ok := desktopTiersKnown()
if !ok {
return nil, false
}
tierOf, more := desktopTierOf(picked), desktopSharedTiers(picked)
tierOf := desktopTierOf(picked)
shown, _ := provider.CatalogFor("claude-desktop")
rows := desktopModels(shown, true)
tagged := false
var again []map[string]any
for i, m := range rows {
e := shown[i]
id, _ := m["id"].(string)
name, long := strings.CutSuffix(id, "[1m]")
// Desktop reads /v1/models no more once a profile lists models
// whose names aren't bare tier words (adminListObviatesDiscovery
// in its app.asar, 4.4212), and names an entry by its
// labelOverride, else its catalog's name, else the discovered
// row's, else the id itself (pzn, ngn): every mythos-magpie-<n>
// read as that id (chengming0v0 on Discord). Each entry is
// labelled as /v1/models labels its row, a catalog-named Claude
// model too, whose provider the skipped description said
// (desktopSaidBy).
// in its app.asar, 4.4212), unless modelDiscoveryEnabled says to
// (DesktopDiscovers), and names an entry by its labelOverride,
// else its catalog's name, else the discovered row's, else the id
// itself (pzn, ngn): every mythos-magpie-<n> read as that id
// (chengming0v0 on Discord). Each entry is labelled as /v1/models
// labels its row, a catalog-named Claude model too, whose
// provider the skipped description said (desktopSaidBy).
entry := map[string]any{"name": name, "labelOverride": m["display_name"]}
if long {
entry["supports1m"], entry["prefer1m"] = true, true
@@ -138,25 +135,59 @@ func DesktopInferenceModels() (list []map[string]any, ok bool) {
}
}
list = append(list, entry)
for _, t := range more[e.ID] {
alias := desktopTierAlias(e, t)
x := map[string]any{"name": alias, "labelOverride": fmt.Sprint(m["display_name"]) + " · " + t,
"anthropicFamilyTier": t, "isFamilyDefault": true}
for _, k := range []string{"supports1m", "prefer1m"} {
if v, has := entry[k]; has {
x[k] = v
}
}
if b := desktopRunsAs(e, alias, t); b != "" {
x["behavesAs"] = b
}
again = append(again, x)
}
}
if !tagged {
return nil, true
}
return append(list, again...), true
return list, true
}
// DesktopDiscovers says magpie's Desktop profile has Desktop read
// /v1/models beside its inferenceModels (modelDiscoveryEnabled): while a
// model is picked for two tiers, whose later tiers only /v1/models gives
// (DesktopTierRows). Desktop's Code tab pins a tier from a discovered row
// tagged with it (shortnameIdentityOverrides in its app.asar, 2.7032 and
// 4.23118) and one from inferenceModels over that, while its menu is the
// list alone (gXn, 4.23118: the discovered rows only name the list's
// entries), so the later tier gets its model and no row of its own in the
// menu. ok is false when the picks can't be read.
func DesktopDiscovers() (on, ok bool) {
if _, ok := desktopTiersKnown(); !ok {
return false, false
}
return len(DesktopTierAliases()) > 0, true
}
// DesktopTierRows are the /v1/models rows, after rows (desktopModels of
// shown), that give Desktop's Code tab a model picked for two tiers for the
// later ones (desktopSharedTiers): the model's row under its tier's id
// (desktopTierAlias), tagged with that tier. Desktop keys its tiers by
// model id and reads one tier off a row, so the model's own row can't
// carry the second; the menu never shows these while inferenceModels is
// written (DesktopDiscovers).
func DesktopTierRows(shown []provider.Entry, rows []map[string]any) []map[string]any {
picked, ok := desktopTiersKnown()
if !ok {
return nil
}
more := desktopSharedTiers(picked)
var out []map[string]any
for i, e := range shown {
if i >= len(rows) {
break
}
for _, t := range more[e.ID] {
r := maps.Clone(rows[i])
r["id"] = desktopTierAlias(e, t)
r["display_name"] = fmt.Sprint(rows[i]["display_name"]) + " · " + t
r["anthropic_family_tier"], r["is_family_default"] = t, true
if strings.HasSuffix(fmt.Sprint(rows[i]["id"]), "[1m]") {
r["supports_1m"] = true
}
out = append(out, r)
}
}
return out
}
// desktopTierOf is the tier each picked model is tagged with: a model
+120 -61
View File
@@ -1,6 +1,7 @@
package gateway
import (
"encoding/json"
"io"
"net/http"
"net/http/httptest"
@@ -73,14 +74,67 @@ func tierEntries(t *testing.T, list []map[string]any) map[string]map[string]any
return out
}
// desktopListed is Claude Desktop's /v1/models, asked with its key, as
// raw rows.
func desktopListed(t *testing.T) []map[string]any {
t.Helper()
req := httptest.NewRequest("GET", "/v1/models?limit=1000", nil)
req.Header.Set("x-api-key", TokenFor("claude-desktop"))
rec := httptest.NewRecorder()
New().Handler().ServeHTTP(rec, req)
var out struct {
Data []map[string]any `json:"data"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
t.Fatal(rec.Body.String(), err)
}
return out.Data
}
// rowTiers are the /v1/models rows by the tier they carry; a tier carried
// by two rows fails.
func rowTiers(t *testing.T, rows []map[string]any) map[string]map[string]any {
t.Helper()
out := map[string]map[string]any{}
for _, r := range rows {
if tier, _ := r["anthropic_family_tier"].(string); tier != "" {
if out[tier] != nil {
t.Fatalf("%s carried twice: %v", tier, rows)
}
out[tier] = r
}
}
return out
}
// noTierEntry fails when the inferenceModels list holds an entry beyond
// the rows: Desktop's model menu is that list, so such an entry showed as
// a model of its own, "Gemini 4 Hydrogen · haiku" beside "Gemini 4
// Hydrogen" (yanghonghang on X).
func noTierEntry(t *testing.T, list []map[string]any) {
t.Helper()
shown, _ := provider.CatalogFor("claude-desktop")
if len(list) != len(shown) {
t.Fatalf("%d entries in Desktop's model menu for %d models: %v", len(list), len(shown), list)
}
for _, e := range list {
if l, _ := e["labelOverride"].(string); strings.Contains(l, " · ") && regexp.MustCompile(` · (opus|sonnet|haiku)$`).MatchString(l) {
t.Fatalf("a tier's own entry in Desktop's model menu: %v", e)
}
}
}
// A model picked for two of Claude Desktop's tiers (a user's
// copilot/claude-sonnet-5.5 for sonnet and haiku) was tagged with the
// first only: Desktop keys inferenceModels by name and reads one tier off
// an entry, so haiku had no model, Claude Code in the Code tab got an empty
// ANTHROPIC_DEFAULT_HAIKU_MODEL, and its small tasks (WebFetch's page
// summaries) ran on the session's model. The second tier is listed once
// more, after the rows, by the model's id form under a number of its own,
// which the gateway reads back to the model and serves as the pick.
// ANTHROPIC_DEFAULT_HAIKU_MODEL, and its small tasks ran on the session's
// model. The second tier was then listed once more in inferenceModels, and
// Desktop's model menu, which is that list, showed it as a model of its
// own (yanghonghang on X). The second tier now goes in /v1/models only,
// by the model's id form under a number of its own, tagged with the tier:
// Desktop's discovery pins the tier's variable to it, and the gateway reads
// it back to the model and serves it as the pick.
func TestDesktopTierSharedPick(t *testing.T) {
t.Run("claude model", func(t *testing.T) {
u := desktopPickSetup(t)
@@ -91,34 +145,34 @@ func TestDesktopTierSharedPick(t *testing.T) {
}
}
list, ok := DesktopInferenceModels()
shown, _ := provider.CatalogFor("claude-desktop")
rows := desktopModels(shown, true)
if !ok || len(list) != len(rows)+1 {
t.Fatalf("%d entries for %d rows and one more tier: %v", len(list), len(rows), list)
if !ok {
t.Fatal("no list")
}
for i, r := range rows {
if want := strings.TrimSuffix(r["id"].(string), "[1m]"); list[i]["name"] != want {
t.Fatalf("entry %d is %v, /v1/models has %s there", i, list[i]["name"], want)
}
noTierEntry(t, list)
if on, ok := DesktopDiscovers(); !on || !ok {
t.Fatalf("a shared tier needs Desktop's discovery: %v %v", on, ok)
}
tiers := tierEntries(t, list)
if e := tiers["sonnet"]; e == nil || e["name"] != DesktopID(sonnet) {
t.Fatalf("sonnet: %v", list)
}
haiku := tiers["haiku"]
if tiers["haiku"] != nil {
t.Fatalf("haiku in the list: %v", list)
}
rows := desktopListed(t)
shown, _ := provider.CatalogFor("claude-desktop")
if len(rows) != len(shown)+1 {
t.Fatalf("%d rows for %d models and one more tier: %v", len(rows), len(shown), rows)
}
haiku := rowTiers(t, rows)["haiku"]
if haiku == nil {
t.Fatalf("haiku has no entry, so Claude Code's ANTHROPIC_DEFAULT_HAIKU_MODEL is empty: %v", list)
t.Fatalf("haiku has no row, so Claude Code's ANTHROPIC_DEFAULT_HAIKU_MODEL is empty: %v", rows)
}
alias, _ := haiku["name"].(string)
alias, _ := haiku["id"].(string)
alias = strings.TrimSuffix(alias, "[1m]")
if !regexp.MustCompile(`^magpie-\d{10}\.anthropic\.claude-sonnet-5-5$`).MatchString(alias) || alias == DesktopID(sonnet) ||
haiku["isFamilyDefault"] != true || list[len(list)-1]["name"] != alias {
t.Fatalf("haiku's entry: %v (sonnet's name %s)", haiku, DesktopID(sonnet))
}
if _, has := haiku["behavesAs"]; has {
t.Fatalf("Claude Code knows %s as Claude Sonnet 5.5: %v", alias, haiku)
}
if l, _ := haiku["labelOverride"].(string); !strings.HasSuffix(l, " · haiku") {
t.Fatalf("haiku's label: %v", haiku)
haiku["is_family_default"] != true {
t.Fatalf("haiku's row: %v (sonnet's name %s)", haiku, DesktopID(sonnet))
}
for _, id := range []string{alias, alias + "[1m]"} {
if got := DesktopCatalogID(id); got != sonnet.ID {
@@ -130,7 +184,7 @@ func TestDesktopTierSharedPick(t *testing.T) {
}
// the session on m1; Claude Code's small task for the haiku tier,
// by that entry's name, goes to the pick, not the session's model
// by that row's id, goes to the pick, not the session's model
s := New()
m1 := shownEntry(t, func(e provider.Entry) bool { return e.ID == "fake/m1" })
desktopSubagentAsk(t, s, Token+"-claude-desktop", DesktopID(m1), "", "/v1/messages", true)
@@ -142,16 +196,19 @@ func TestDesktopTierSharedPick(t *testing.T) {
t.Fatalf("haiku's small task went to %q, want the haiku pick claude-sonnet-5-5", m)
}
// the picks apart again: one entry a tier, none more
// the picks apart again: no more rows, no discovery
if err := SetDesktopTier("haiku", "fake/m1"); err != nil {
t.Fatal(err)
}
if list, _ := DesktopInferenceModels(); len(list) != len(rows) {
t.Fatalf("picks apart: %v", list)
if rows := desktopListed(t); len(rows) != len(shown) {
t.Fatalf("picks apart: %v", rows)
}
if a := DesktopTierAliases(); a != nil {
t.Fatalf("picks apart, tier aliases: %v", a)
}
if on, ok := DesktopDiscovers(); on || !ok {
t.Fatalf("picks apart, discovery: %v %v", on, ok)
}
})
t.Run("other model", func(t *testing.T) {
@@ -163,20 +220,21 @@ func TestDesktopTierSharedPick(t *testing.T) {
}
}
list, _ := DesktopInferenceModels()
tiers := tierEntries(t, list)
opus, haiku := tiers["opus"], tiers["haiku"]
noTierEntry(t, list)
opus := tierEntries(t, list)["opus"]
if opus == nil || opus["name"] != DesktopID(m1) || opus["behavesAs"] != "claude-opus-5-5" {
t.Fatalf("opus: %v", list)
}
haiku := rowTiers(t, desktopListed(t))["haiku"]
if haiku == nil {
t.Fatalf("haiku has no entry: %v", list)
t.Fatal("haiku has no row")
}
alias, _ := haiku["name"].(string)
if !regexp.MustCompile(`^mythos-magpie-\d{10}$`).MatchString(alias) || alias == DesktopID(m1) || haiku["behavesAs"] != "claude-haiku-5-5" {
t.Fatalf("haiku's entry: %v", haiku)
alias, _ := haiku["id"].(string)
if !regexp.MustCompile(`^mythos-magpie-\d{10}$`).MatchString(alias) || alias == DesktopID(m1) {
t.Fatalf("haiku's row: %v", haiku)
}
as, ok := DesktopBehavesAs()
if !ok || as[DesktopID(m1)] != "claude-opus-5-5" || as[alias] != "claude-haiku-5-5" || len(as) != 2 {
if !ok || as[DesktopID(m1)] != "claude-opus-5-5" || len(as) != 1 {
t.Fatalf("behaves as: %v %v", as, ok)
}
if got := DesktopCatalogID(alias); got != m1.ID {
@@ -184,8 +242,8 @@ func TestDesktopTierSharedPick(t *testing.T) {
}
})
// one model for every tier: each tier after the first gets an entry
// of its own, by an id of its own, each served as the pick
// one model for every tier: each tier after the first gets a row of its
// own, by an id of its own, each served as the pick
t.Run("every tier", func(t *testing.T) {
u := desktopPickSetup(t)
m1 := shownEntry(t, func(e provider.Entry) bool { return e.ID == "fake/m1" })
@@ -196,30 +254,32 @@ func TestDesktopTierSharedPick(t *testing.T) {
}
}
list, _ := DesktopInferenceModels()
noTierEntry(t, list)
if e := tierEntries(t, list)["opus"]; e == nil || e["name"] != DesktopID(m1) {
t.Fatalf("opus, the first tier, on the entry: %v", list)
}
rows := desktopListed(t)
shown, _ := provider.CatalogFor("claude-desktop")
if len(list) != len(shown)+len(DesktopTierNames)-1 {
t.Fatalf("%d entries for %d rows and %d more tiers: %v", len(list), len(shown), len(DesktopTierNames)-1, list)
if len(rows) != len(shown)+len(DesktopTierNames)-1 {
t.Fatalf("%d rows for %d models and %d more tiers: %v", len(rows), len(shown), len(DesktopTierNames)-1, rows)
}
tiers := tierEntries(t, list)
names := map[string]bool{}
for _, e := range list {
n, _ := e["name"].(string)
if names[n] {
t.Fatalf("%s listed twice: %v", n, list)
ids := map[string]bool{}
for _, r := range rows {
id, _ := r["id"].(string)
if ids[id] {
t.Fatalf("%s listed twice: %v", id, rows)
}
names[n] = true
}
if tiers["opus"] == nil || tiers["opus"]["name"] != DesktopID(m1) {
t.Fatalf("opus, the first tier, on the row: %v", list)
ids[id] = true
}
tiers := rowTiers(t, rows)
s := New()
desktopSubagentAsk(t, s, Token+"-claude-desktop", DesktopID(sonnet), "", "/v1/messages", true)
for _, tier := range DesktopTierNames {
e := tiers[tier]
if e == nil || e["behavesAs"] != desktopBehavesAs[tier] || e["isFamilyDefault"] != true {
t.Fatalf("%s: %v", tier, list)
r := tiers[tier]
if r == nil || r["is_family_default"] != true {
t.Fatalf("%s: %v", tier, rows)
}
id, _ := e["name"].(string)
id, _ := r["id"].(string)
if got := DesktopCatalogID(id); got != m1.ID {
t.Fatalf("%s's %s read back as %q", tier, id, got)
}
@@ -234,9 +294,8 @@ func TestDesktopTierSharedPick(t *testing.T) {
})
// a Claude model with no reasoning levels is listed by its own id,
// which has no number to change: the later tier's entry is
// anthropic/magpie-<n>, which Claude Code doesn't know, so it runs as
// that model
// which has no number to change: the later tier's row is
// anthropic/magpie-<n>
t.Run("own id", func(t *testing.T) {
desktopPickSetup(t)
if err := provider.Save(provider.Provider{ID: "own", Name: "Own", Key: "k", Anthropic: "http://127.0.0.1:1", Models: []string{"claude-haiku-4-5"}}); err != nil {
@@ -249,14 +308,14 @@ func TestDesktopTierSharedPick(t *testing.T) {
}
}
list, _ := DesktopInferenceModels()
tiers := tierEntries(t, list)
if e := tiers["sonnet"]; e == nil || e["name"] != DesktopID(h) {
noTierEntry(t, list)
if e := tierEntries(t, list)["sonnet"]; e == nil || e["name"] != DesktopID(h) {
t.Fatalf("sonnet: %v", list)
}
haiku := tiers["haiku"]
alias, _ := haiku["name"].(string)
if !regexp.MustCompile(`^anthropic/magpie-\d{10}$`).MatchString(alias) || haiku["behavesAs"] != "claude-haiku-4-5" {
t.Fatalf("haiku's entry: %v", haiku)
haiku := rowTiers(t, desktopListed(t))["haiku"]
alias, _ := haiku["id"].(string)
if !regexp.MustCompile(`^anthropic/magpie-\d{10}$`).MatchString(alias) {
t.Fatalf("haiku's row: %v", haiku)
}
if got := DesktopCatalogID(alias); got != h.ID {
t.Fatalf("%s read back as %q", alias, got)
+5 -1
View File
@@ -48,7 +48,11 @@ func TestClaudeDesktopTiers(t *testing.T) {
}
out := map[string]row{}
for _, d := range list.Data {
out[DesktopCatalogID(d.ID)] = d.row
// a model picked for two tiers has a row for the later one
// too (TestDesktopTierSharedPick): the model's own row is first
if _, seen := out[DesktopCatalogID(d.ID)]; !seen {
out[DesktopCatalogID(d.ID)] = d.row
}
}
return out
}
+1
View File
@@ -1717,6 +1717,7 @@ func (s *Server) listModels(w http.ResponseWriter, r *http.Request) {
shown := catalogFor(r)
if agent := agentOf(r); agent == "claude-desktop" {
data = desktopModels(shown, desktopKnowsMythos(r.Header.Get("User-Agent")))
data = append(data, DesktopTierRows(shown, data)...)
} else if agent == ScienceID {
data = scienceModels(shown)
} else {