Files
magpie/docs/subsystems/agent-wiring.md
T
yetone e528aeb3ce agent: DevEco Code, Huawei's OpenCode, as an agent (#1885)
foobra asked for DevEco Code (npm @deveco/deveco-code), Huawei's
HarmonyOS coding agent. It is OpenCode underneath, so it joins through
openCodeLike as MiMo Code did (03a01a548):

- Config in ~/.config/deveco. magpie writes the first of deveco.jsonc,
  deveco.json, config.json there (the one DevEco reads last wins its
  merge), or DEVECO_CONFIG_DIR when that is an absolute folder; agentenv
  carries DEVECO_CONFIG_DIR. Auth at ~/.local/share/deveco/auth.json.
- Its provider block carries the key magpie-deveco, not the plain one.
  0.2.3 sends "deveco/0.2.3 ai-sdk/provider-utils/4.0.23 runtime/bun/1.4.2"
  on chat, but parts of its code still send opencode/<version>, so the key
  keeps its usage DevEco's whichever it sends. Check flags the plain key,
  and Sync writes DevEco's back. OpenCode's own key is unchanged.
- The user's own provider, small_model, $schema and comments stay; the
  model they were on comes back on Disconnect.
- Library: AGENTS.md instructions (with the "reads Claude Code's
  CLAUDE.md" note, as OpenCode and MiMo Code), MCP in OpenCode's shape,
  skills. No WSL folder.
- Install/update: npm @deveco/deveco-code on macOS and Windows only, as the
  package has no Linux binary (new cliSpec.only); the self installer under
  ~/.local/share/deveco/versions updates with `deveco upgrade`.
- Icon: DevEco's own logo, byte for byte from its IntelliJ plugin's
  pluginIcon.svg. Model picker /models. Route hue, READMEs (en, zh), site
  agent lists (en, zh, ja), docs/reference.md, subsystem pages, CLI help.

What was run
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
- go test -tags nogui: internal/library, agentenv, proc, cli, gui, usage
  pass; internal/agent passes in 559s with -timeout 40m;
  its first run, at the default 10m with load average ~40 from other
  sessions, was cut off by the timeout (no test had failed).
- New deveco_test.go: config lookup and DEVECO_CONFIG_DIR, the key, and
  Connect/Check/Sync/Disconnect against a deveco.jsonc holding the user's
  own model, provider, small_model, $schema and a comment. Made
  openCodeKeyAt return the plain key by hand: TestDevEcoKeyNamesIt and
  TestDevEcoConnectKeepsTheUsersOwn go red.
- GUI: new library-deveco.test.cjs (the note in en, zh, zh-TW, ja, de,
  and the icon draws), chromium and webkit; red with deveco taken out of
  library.js's note. library-instr-sets, library-instr-busy,
  panel-routing, agent-connect, library-desktop-skills, getting-started,
  filter-ime, routing-account-identity pass in both engines.
- Real use, sandbox HOME: npm-installed @deveco/deveco-code 0.2.3,
  `deveco auth consent --accept` (sandbox only, no Huawei sign-in). magpie
  serve on 127.0.0.1:3592 with a fake upstream; `magpie deveco fake/fake-1`
  wrote provider magpie (magpie-deveco, http://127.0.0.1:3592/v1) beside
  the user's own and kept the file's comment; `deveco run "Reply with one
  word: ping"` answered from the fake, and `magpie usage today` counted it
  under DevEco Code. The User-Agent above is what it sent.

Not tried
- Windows, and DevEco Studio's plugin mode; a Huawei-signed-in DevEco.
- `magpie deveco <model>` then `magpie deveco default` doesn't bring back
  the model the user was on before: the CLI set path doesn't stash. It is
  the same for OpenCode today; Connect/Disconnect in the GUI does.

Reported-by: foobra
2026-10-13 10:57:32 +08:00

49 KiB
Raw Blame History

Agent wiring

magpie connects a coding agent to its gateway by editing the agent's own config. That covers the endpoint, the key magpie-<agent> and the model, in the agent's own format. When the agent is disconnected, magpie puts back what the agent had before. Package internal/agent describes every supported agent: where its config lives, which fields matter and which values to offer. It also records what magpie set, so a later change made by something else shows up as drift.

Responsibilities and sources of truth

Part Responsibility Source
Agent description Agent has an id, name, icon, Bin and Dir for detection, Path, Fields and Native. It also has optional hooks: Notice, UA, ListsModels, Sync, Unwire, Join/Joined, Routed, Follow, RenameRefs, Check, LastUsed, Reached, Import/Added, Launch, SplitSuffix, Spelled and ModelAliases. Each hook's comment says which agents need it. agent.go
Fields and options A Field has Get, Set and Options. Set("") returns the field to the agent's default and takes magpie's wiring out. Quiet fields follow another field until set (Follows, such as Claude Code's tiers). An Option carries the picker's facts: Direct, Via, Same, Alias, Rate and Context. The GUI's and TUI's pickers list Agent.Picks: with the agent in settings' ownModelsHidden (the switch at the top of its model list, #1642), a field that offers catalog models (Ref) leaves out the agent's own (no Ref), but for its default and the value it is set to. The CLI still takes an own model by name. agent.go, route.go
The list of agents All lists every agent magpie knows, then the WSL agents (wslAgents). Clients lists every agent whose requests the gateway knows by name, which usage.Agents reads. One file per agent: claude.go, codex.go, opencode in agents.go, and so on. agents.go
Connect ConnectHow picks the model an agent starts on and reports how. How is one of: kept, again, joined, magpie, same, alike, default or first (#726). With no models to give, it returns NoModelsError (code no_models). applied.go
What magpie set Apply sets a field and records it in applied.json. Wired says whether magpie is in the config. Drift reports unwired, replaced, unreachable, proxied or bypassed. Reapply sets the record again. Keep accepts the config as it is now. applied.go
What came before The stash (stash.json) remembers what the config said before magpie pointed it at the gateway, so Disconnect restores it rather than guessing. stash.go
Disconnect and preview Disconnect runs Unwire, then returns each field still on magpie to its default. Last it runs Restore: Pi and its kin (piLike: Pi, OmO, Prime Agent) copy settings.json and models.json aside (*.before-magpie, beforeMagpie) before magpie's first write, and put that copy back byte for byte where what Disconnect left is the same JSON; a file that wasn't there goes again when only empty objects are left in it. DisconnectPreview runs the real Disconnect on a copy under a temporary home, in a subprocess (DryRunArg), and diffs the files. The preview is never a second account of what Disconnect does. applied.go, preview.go
Keeping configs current Reseat moves agents off a model magpie no longer serves (#200). OnGateway and Rewire write the new gateway address into every connected agent when the port changes. Source and Stale say what an unconnected agent runs on, and whether running copies still use the old list. reseat.go, rewire.go, connectinfo.go
Named omp profiles omp keeps a profile's settings under ~/.omp/profiles/<name> (or under PI_CONFIG_DIR), each with its own config.yml and models.yml. Every such profile is an agent of its own — omp#<name> on Windows, omp#<name>@wsl:<distro> in a distro — so each can be connected, drifted and disconnected on its own. They share omp's model lists (ListsFor), and the default omp row is the folder ompDir/ompIn already pick, so an OMP_PROFILE that row is already pointed at is not listed twice. A name omp refuses is not a row: default, a trailing dot, or a Windows reserved device name (aux, nul, com1, lpt9.x, con.work), on every platform (ompProfileOK). A distro's profile names come from its probe and are kept in wsl.json; a stopped distro is never started to list them, its profile rows showing what was last seen (asleep). omp.go, wsl.go
WSL twins On Windows each running distro is probed once, without starting a stopped one. The wslKinds agents found there become agents of their own, <id>@wsl:<distro>, edited through \\wsl.localhost\<distro>. A kind is found by its folder under the distro's home or by its command there (not one on a Windows drive). Where another tool shares one of them, the kind leaves it out: Gemini CLI is found by its command alone, because Antigravity keeps ~/.gemini too. Goose is found by its folder alone, because a goose command can be pressly's migration tool. Reasonix also needs the version its command gives (accept), because the old npm client is named reasonix too. The gateway address and key follow the distro's networking: mirrored or NAT (place, keyAt). ListsFor keeps a twin's model picks under the Windows twin's id (#927). wsl.go, gatewaykey.go
Settings tuned from use Usage › Context's "Tuned for you" advises, per agent, the settings that would have spent the fewest tokens on the user's own calls of the range, and puts one in on a click. Package tune replays the calls sessions.Calls reads from the agents' session files under each candidate value (Compact, CacheTTL); tuneOf picks the agents and models (Claude Code per model, Codex pooled). TuneRead, TuneApply and TuneUndo know where each setting lives: Claude Code's modelSettings.<model>.autoCompactWindow (where its /autocompact saves), promptCacheTtl and subagentPromptCacheTtl in ~/.claude/settings.json; Codex's top-level model_auto_compact_token_limit. The advice is weighed by tokens alone: it is labelled "Fewest tokens", and a compaction window it would change says it doesn't measure how well the agent keeps the task after a compaction, and that a lower window compacts more often (#1854, context-tune.test.cjs). A compaction row's "Other window…" opens the app menu with every value of the curve, each with its estimated extra tokens over the fewest and about how many compactions it would have made (Point.compacts, from the same replay), and puts the one picked in like Use (#1860). internal/tune, tune.go, internal/gui/tune.go
Agents a plugin adds A plugin's magpie.agent module (or a *.agent.js file) says where an agent magpie has no setup of its own keeps its model (config, format, model, prefix), and its connect returns the other keys to write. agentplug compiles each in moejs (via jsmod, as gateway middleware is), reloads it when plugins.json or the file changes, and keeps why one didn't load. plugged makes each an Agent with Plugin set, listed after magpie's own; an id one of magpie's own agents has is refused (PluginErrors). agentplug.go, plugged.go
Environment-only agents Agents that read the gateway only from the environment get a Launch command. Cursor Private Inference instead gets user-level variables (cursorLocalOn, KeepCursorLocalEnv), and magpie writes none of Cursor's own files. It is found by its product.json in the apps folders, in the folder Windows' list of installed programs names (cursorLocalInstalls, any folder picked in its installer), or as its Linux AppImage (Cursor_Private_Inference-…AppImage) in the folders downloads are kept in (#1254). Its effort field is kept in magpie (provider.AgentEffort) and asked by the gateway, its levels those of the models it lists (cursorLocalEfforts, #1003). cursorlocal.go

Runtime path

  1. Connect. The Agents page's switch calls ConnectHow (POST /api/agents/{action}/{id} in internal/gui/api.go). It stashes the current values (<id>.connect.was). It brings back the models used before a switch-off (reconnect), or calls Join where the agent keeps its own model (Codex signed in with ChatGPT). Otherwise it picks a model by the order ConnectHow documents and sets it through Apply.
  2. Pick. Pick sets a field from the model picker. Picking one of magpie's models on an agent that isn't connected connects it first.
  3. Notice. After a change the page shows Notice when the agent reads its config only at start-up and needs a restart.
  4. Drift. As the Agents page is drawn, Drift compares the config with applied.json. It runs Check first, then each field. When the config is right and points at an address off loopback (a WSL twin under NAT, or this machine's Codex at an address the user kept, #816), it tries that address (reach.go): in the background, at most every 20 s, never waited for. When nothing answers there while the gateway answers on loopback, the drift is unreachable (#1013), with what has to listen there: Share on local network, the user's portproxy, Windows' firewall. Then it checks whether the agent's latest use (LastUsed, Reached) reached the gateway.
  5. Disconnect. Disconnect puts back what the stash kept and forgets the record. It also marks the agent disconnected (<id>.disconnected in the stash, Disconnected) until the user connects it again (connect, or an Apply that leaves it wired): nothing magpie does by itself puts magpie back in meanwhile, neither a start's Sync nor Codex's account failover nor #701's magpie API wiring (paynezhuang on Discord: Codex had openai_base_url back after every update).

Constraints and failure behavior

  • magpie only removes what it wrote. Anything else in an agent's config stays as it was.
  • A sync brings magpie's models up to date, not where the agent reaches magpie. Every Sync that SyncCatalog runs (each start and update of magpie, a provider added) goes through synced, which passes each file written through keptAway (edit.Filtered, keptaway.go). In a file without the gateway's own address, whose magpie the user pointed at an address on another machine (a NAS's, or this machine's LAN address), and with no address a WSL distro was seen at, that address stays in place of gateway.URL(), and so does the key that went with it in place of magpie's own (coeo91 on Discord: the base URL went back to 127.0.0.1 after an update or restart). An address on this machine's loopback follows the gateway; with more than one address or key gone, the write is left as it is. Picking a model in magpie still points the agent at this magpie. ZCode and WorkBuddy keep such an address in their own writers too (zcodeAddress, buddyWriteAt).
  • JetBrains Air's magpie-opencode.json keeps user-added fields in provider.magpie, including nested options, on sync and model picks (air in air.go, using theirsKept in sync.go). The gateway fields and complete model list are still replaced, so removed models leave the list.
  • Copilot in JetBrains IDEs keeps its Bring Your Own Key providers in the Copilot language server's byok.json, shared with Xcode's and Eclipse's Copilot (copilotJetBrains in copilotjetbrains.go). magpie writes its own three keys there, magpie-provider-config, magpie-api-key and magpie-models-config, in the bytes the server itself writes, and only when they differ; the user's providers and keys stay. A magpie model the user hid in Manage Models (isRegistered: false) stays hidden through a sync. A new file is made 0600 in a 0700 folder, as the server makes it.
  • dsh (DeepSeek Harness) sets one API per llm-pi-ai route, so magpie writes a route per protocol (dshKinds in dsh.go; 01huadalang on Discord): magpie (Chat Completions) for most models, magpie-responses (openai-responses) for a model served on Responses, magpie-anthropic (anthropic-messages, the gateway root, forceAdaptiveThinking where AdaptiveThinking) for one served on Messages, by the model's APIs (dshRouteOf). A model's APIs is the one its provider serves it on best (Provider.Native, in magpieModels, route.go), and Pi, omp and droid read it the same way. A routing group has responses when every member is best on Responses (allResponses, #1594), so its tool-call arguments are relayed as they stream; any other group has none and stays on Chat, a Messages-only group too, as a Claude member's thinking is known by its own model. A route with no models is taken out. An api the user picked for a route in dsh's Models page is kept, and so are keys they added there. The start (agent-default-model) names its model's route, and Sync moves a start on one of magpie's routes to the route its model is now on (dshStartOnItsRoute), its effort and marks kept. Check asks the route the start names to list its model. A dsh session resumed on a model that has since moved routes asks for the model to be picked again, since dsh finds a model by route and id.
  • Ante's catalog.json keeps user-added fields in providers.magpie the same way (ante in ante.go); its auth, http_headers, extra_body and stream_idle_timeout_secs are what a gateway shared on the local network or reached from WSL needs to send a key. Ante starts a session on the provider and model of settings.json, not on what its catalog holds (#1210), so magpie sets that pair and puts back what it found there; a pick the user makes in Ante while magpie is wired is theirs and stands.
  • AstrBot keeps its providers in data/cmd_config.json under its root ($ASTRBOT_ROOT, else ~/.astrbot, the desktop app's, else ~/astrbot), written with a UTF-8 BOM, which magpie keeps (astrbot in astrbot.go). magpie adds a magpie entry to provider_sources and one magpie/<model> entry per model to provider, keeps the user's own entries byte for byte and keeps what the user changes in magpie's (timeout, proxy, enable), and sets the default chat model (agent_runner.config.model.provider_id, or provider_settings.default_provider_id before the agent runner), putting back what it found there. A pick the user makes while magpie is wired is theirs and stands. The first connect copies the file to cmd_config.json.before-magpie. AstrBot reads the file only at start-up and its WebUI writes it back whole on save, so the agent's notice says to restart AstrBot before saving in the WebUI. A Docker install's root is inside its container, which magpie doesn't reach.
  • jcode keeps its settings in config.toml in $JCODE_HOME, else ~/.jcode (jcode in jcode.go). magpie adds a named profile, [providers.magpie], as jcode provider add writes one: type = "openai-compatible", the gateway's /v1, an inline api_key naming jcode (jcode sends nothing else that tells it apart) and requires_api_key = true, since jcode sends no key to a loopback URL without it. Its models list has one entry per model, with context_window, input and reasoning for a model with effort levels. A reasoning_effort the user set on one stays while the model has that level. The model jcode starts on is [provider] default_provider = "magpie" and default_model. What was there is stashed and put back on Disconnect. A model of jcode's own picked while it is on magpie takes magpie out. Each key is set alone, so the user's other keys and tables stay, and the [[providers.magpie.models]] tables jcode writes when it saves the file itself are replaced by the one list. A sync with nothing to change doesn't write. Disconnect drops the profile whole, its sub-tables included. jcode reads the file when it starts, so the notice says to restart open sessions.
  • DevEco Code (Huawei's OpenCode fork, #1885) is wired as OpenCode is (deveco in agents.go): magpie's provider goes into the first of deveco.jsonc, deveco.json and config.json in ~/.config/deveco (the one DevEco merges last, so the one that wins), or in $DEVECO_CONFIG_DIR when that is absolute, read after them. 0.2.3 sends deveco/0.2.3 ai-sdk/… to a provider of its config, but much of the OpenCode code it keeps still sends OpenCode's own User-Agent (opencode/<version>), so its provider's key is magpie-deveco (openCodeKeyAt), not the plain magpie OpenCode and MiMo Code send, and Check asks for that key. Its npm package has no Linux binary, so no install command is offered there (cliSpec.only).
  • Grok App (RongleCat/grok-app, a desktop front end that starts Grok Build over ACP) keeps its provider channels in agent-home/config.toml under its data folder: $GROK_APP_HOME, else where its directories crate puts it, or its ~/.grok-app fallback when that is the one there (grokApp in grokapp.go). Its composer lists only Grok Build's official catalog, never the [model."magpie/…"] tables of Grok Build's row, so magpie adds itself as a channel, [model.magpie], with the keys the App's Providers page writes: the gateway's /v1, a key naming Grok App, api_backend = "chat_completions", app_provider_mode = "generic", and app_models, a JSON list of magpie's models with contextWindow, supportsVision and their effort levels (no none; a default the user marks in the App stays, else medium). The picked model's context_window (a bare integer) and supports_reasoning_effort (a bare bool, Grok Build's gate for --reasoning-effort) are on the channel, as the App puts them there when a model is picked in its composer. [models] default is the route, and magpie does not set it: setting it to "magpie" makes the App drop its own sign-in (ensure_independent_for_custom_route). The route stays whatever the App had. Pressing Use on magpie under Accounts is what switches it. A magpie that already set the route puts the old one back once, on the next sync or connect (grokAppReleased); a Use after that stays. Disconnect drops only the channel, and puts the route back only when it is still "magpie": the one stashed at connect, else the one connect.was holds. One of the App's own routes picked in magpie's model field is written as the route and takes magpie's channel out, as picking another provider does elsewhere. A sync with no channel and a route other than "magpie" writes nothing, magpie's stash included, and Check says so when the route is "magpie" with the channel gone. A model picked in the App's composer since is the user's and stays through a sync, and a sync with nothing to change doesn't write. Shared mode keeps GROK_HOME at ~/.grok (Grok Build's library row). Independent mode, which Use turns on, reads agent-home: the Library writes AGENTS.md, [mcp_servers] in the same config.toml, and skills/ there, and Grok App also reads ~/.agents/skills. RTK has no Grok hook, so the Library lists Grok App with the switch off. The notice, while the App runs, says magpie is a custom provider in Settings › Account, a chat can pick its models in the model picker, and the App stays on its current route until Use.
  • JSON/JSONC config edits and their previews reject malformed input rather than editing a partially parsed document. Object edits and VS Code's model-group array edits leave the original file untouched on a parse error; valid comments and trailing commas remain supported (internal/edit).
  • A config that starts with a UTF-8 byte order mark (a Windows settings.json or config.toml saved by PowerShell, Notepad or a channel switcher, #1534) is read without it (edit.Read), and a write keeps it (keepBOM in WriteAtomic): the user's file keeps the encoding it was saved in. That covers every format internal/edit writes (JSON/JSONC and its arrays, TOML, YAML, env); Codex reads a TOML file through a BOM too, so magpie no longer refuses one. A file read some other way trims it with edit.TrimBOM (the Claude Code and CC Switch imports). A line an edit takes out of a CRLF file goes with its \r\n.
  • Codex signed in to ChatGPT stays beside its sign-in (openai_base_url) unless the user picks magpie API. magpie becomes its provider only while the Codex app holds the active account, which it sends nothing for: /wham/usage says it isn't allowed, and it has no credits and isn't a workspace still within its overage (codexHeld, read by provider.CodexUsedUp). Where the app goes by what usage can't show (an experiment's gate, a reserve, a Team plan's overage under the reserve experiment), it counts as held: a wrong move costs ChatGPT extras, a missed one every turn. A saved reading kept through a failed read stops saying held once its used-up window has started again; a hold with no window used up stays till a fresh read. The app then loses its ChatGPT state (durable threads, remote control), so a window at 100% alone, which credits get past, doesn't move it (codex.out marks the move, and Sync undoes it once the account has room).
  • Moving a field from one of magpie's models to another (the agent's own picker) is not drift. Moving it off magpie is.
  • A field that follows another while empty (Follows: Claude Code's tiers and subagents on its main model) is read by Drift as on that field's model. The main model moved, in Claude Code's own /model, onto the model magpie had set a tier to is not drift (#1050).
  • A Claude Code tier or its subagents given a model of their own keep it when the main model moves onto that model and on again (ownKey in claudeIn), whether the main model is picked in magpie or in Claude Code's /model. Same as model, picked for them, has them follow again.
  • Claude Code's tier and subagent models the user had set for their own endpoint (claudeOwnEnv) are stashed with that endpoint and token when magpie is wired in, and come back with them when magpie steps out, by Disconnect or by Claude Code's own model (#1050).
  • 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) 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); a value in the user's ~/.claude settings comes after it.
  • 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/<model>. 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/<name>/agent.md. No other agent was found with this limit (minimax.go).
  • 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-<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).
  • 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.
  • 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), and the gateway moves the subagent's request onto it (see gateway routing). 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.
  • Codex's spawn_agent tool names only the first five models of its catalog to the lead (codex-rs MAX_SPAWN_AGENT_MODEL_OVERRIDES in child_config.rs, spawn_agent_models_description), Codex's own ahead of magpie's, though it takes any catalog model by name (find_spawn_agent_model_name). So a lead could put its subagents on none of magpie's models (Gearclickist on Discord). The gateway adds the rest of the catalog Codex was handed to that tool's description, after Codex's own list, at most 200 (spawnAgentModels in codex_spawn_models.go). A model that can search tools (supports_search_tool) isn't handed it in the request's tools: Codex defers its multi-agent V1 tools behind tool_search (codex-rs core/src/tools/spec_plan.rs), and the lead gets spawn_agent in the tool_search_output Codex puts in the conversation and sends again every turn, so that one is widened too. That text goes upstream with the prompt, to OpenAI too for a ChatGPT lead, so its header (spawnMore) stays neutral: it names neither magpie nor Codex's limit. At CodexPath that is Codex's own listed models less the hidden ones, then CodexListed unless Codex is held to its own. At /v1 it is CodexCatalog under the key's allowance. A lead the ChatGPT backend answers in multi-agent V2 seals its subagents' tasks for a ChatGPT account (#619), so it gets Codex's own only. The model catalog Codex puts in context under model_catalog_in_context (under development, off by default) is capped at five too, and isn't widened.
  • Snow CLI runs on one profile at a time (profiles/<name>.json in ~/.snow or $SNOW_CONFIG_DIR, named in active-profile.json) and copies the active one over config.json at every start, snow --ask too (snow.go). magpie writes a magpie profile, makes it the active one, and copies it to config.json itself, so a Snow already running and Snow App's "Sync Snow CLI API config" see the same. It is made from the profile the user was on, their settings kept and its OAuth sign-in left out. A vision model of that profile comes along only with an endpoint and key of its own (snowOwnVision), since one on the profile's would now go to the gateway. maxContextTokens, maxTokens and supportsVision follow the model from the catalog (snowSynced; supportsVision as every agent is told, true while magpie's Vision describes images); what magpie last wrote of them is stashed, and one the user changed since in Snow's own settings is kept through later picks and syncs. The small field is magpie's profile's basicModel, Snow's light model for summaries, compaction and file search: empty while it follows the main model, a model through magpie of its own kept through new main models and syncs; on a profile of the user's it offers nothing and is hidden. The thinking field is magpie's profile's chatThinking ({enabled: true, reasoning_effort}), the only thinking setting Snow reads on the chat protocol; empty deletes it, Snow's default, which sends thinking disabled. A chatThinking the user brought from their profile is shown, not written over. The profile they were on (or that there was no active-profile.json) and a magpie.json of their own are stashed and put back by Disconnect. A Snow from before profiles (config.json alone) gets the default.json Snow itself would have made of it, so its next start doesn't take magpie's for the user's. Picking a model of another of the user's profiles switches Snow to that profile. On magpie's profile, a value that is neither a model through magpie nor the model of one of the user's profiles is refused and changes nothing (#1457: magpie snow --help used to take magpie out and write --help as the model of the profile it went back to). Gemini CLI's auth field refuses an auth it doesn't know before it unroutes, for the same reason. On the CLI, -h/--help after any command or agent only prints its usage, before run reads or moves anything, and any other flag given to magpie <agent> … is refused (help_cli.go; TestHelpOnEveryCommandDoesNothing walks run's switch and every agent).
  • omp's enabledModels in config.yml is the list it holds its default role to: a model left out of it isn't used, whatever modelRoles.default says (#1769). So a model picked for the default role is added to a list that is there and doesn't take it in already, by name or by one of omp's globs (* not crossing /, as Bun.Glob), and once nothing in config.yml is on magpie its plain magpie/… entries are taken out (a list left empty goes, never []); a renamed provider's entries are renamed once, and folder-scoped entries are left alone (ompScope* in omp_scope.go). No list, no change: omp then takes every model. A list that leaves the default role's model out is drift, which Reapply mends.
  • A value an agent spells as its own provider's model is never taken for one of magpie's, even when magpie has a provider of the same name (Spelled, #835).
  • Reapply on unwired sets again every field on one of magpie's models and every field set to magpie itself (magpieID, as Wired takes it): Claude Desktop's drift shows on a tier, and its provider field is what writes the gateway back (dumplings on Discord). Claude Desktop's Check judges only the set of folders whose Claude-3p it ran in last (desktopRead, by desktopdir.LastRun), every set when it ran in none: magpie writes both of an MSIX install's sets, and 2.31226 reads the real %LOCALAPPDATA%\Claude-3p, so the package's copy being emptied is not Desktop off magpie.
  • unreachable never sets anything: the config is right, and the page's pill only says what has to listen. The exception is an address a WSL distro reached Windows at before (distro.Was, kept in wsl.json) while it reaches Windows at another now: the pill offers that one, and Reapply moves the config there (Agent.move, Codex's codexMoveGateway). An address no distro was seen at is the user's own and is never moved. An unknown answer (no probe yet) and a gateway down on loopback too are not drift. Tests stub reachProbe in TestMain.
  • proxied (Muma102kMichael on X: every project and every new chat 502 after magpie took Codex over) is this machine's Codex sending its requests for the gateway through a proxy that doesn't pass them on, while the gateway answers here (codex_proxy.go). Codex's reqwest takes HTTP_PROXY, else the system's proxy for http:// (macOS' HTTP entry alone, never its HTTPS or SOCKS one; Windows' ProxyServer only when it is one address for every protocol), else ALL_PROXY, and lets only an exact IP or a CIDR in NO_PROXY (on Windows, with no NO_PROXY, the bypass list with *. taken out) keep 127.0.0.1 off it: 127.* and localhost don't, and macOS' exceptions aren't read. With [features] respect_system_proxy it asks the system alone, matching its list itself, wildcards and <local> included, and goes direct when no proxy is set there; a macOS SOCKS entry alone it can't use, and takes HTTP_PROXY/ALL_PROXY then (codex-rs outbound_proxy; tried with codex-cli 0.162.1). Its reqwest has no SOCKS, so a socks5:// proxy is spoken to as an HTTP one, and the probe does the same. The environment is Codex's: the login shell's *_PROXY (proc.LoginEnv, which a terminal's Codex and the ChatGPT app's both have) over magpie's own, which a magpie opened from the Dock lacks (liu_dyj on X: a NO_PROXY=127.0.0.1 in the profile, or a macOS proxy with no HTTP entry, warned while Codex went direct). codexProxyFor works out that proxy the same way, and a GET / through it must come back as magpie's (proxyProbe), tried as reachable is. Its pill says how to fix it, as unreachable's does, naming the proxy (Addr, Detail) through netproxy.Redact, without its user and password (#1886), while the probe goes through it whole, and the dialog has Disconnect from magpie. Account failover, which magpie writes uninvited, waits for that probe (codexProxyOK) and isn't written while the proxy doesn't pass Codex on, and one it wrote goes again. Tests stub the env, the system proxy and proxyProbe in TestMain.
  • Listing never starts a stopped WSL distro. A stopped distro's agent shows what was last seen there (asleep, wsl.json); setting one of its fields writes its files, which starts the distro.
  • Codex's sign-in (login) is ChatGPT ("", the default), Always ChatGPT (chatgpt) or magpie API (api). With ChatGPT, magpie's models join Codex's own beside the sign-in (openai_base_url), and while the Codex app holds the ChatGPT account Codex is signed in to (codexUsedUp, provider.CodexUsedUp: OpenAI no longer allows the account and it has no credits left, a workspace still within its overage excepted), magpie is made Codex's provider (codex.out): the Codex app sends nothing at all on an account it holds, a magpie model's turn included (#540), and as a provider of its own magpie is past that. A window at 100% with credits left doesn't count, and Codex stays signed in. Sync puts it back beside the sign-in once the account has room. Always ChatGPT never does that: Codex stays in its ChatGPT state, and the Codex app may send nothing till the account has room, while Codex CLI's turns still reach magpie by the base URL, and its routing and other accounts serve them. With magpie API, Codex's getAuthStatus returns no token (its provider has no requires_openai_auth), so its Chrome control turns away; the option's note says to pick ChatGPT to keep it (#1824).
  • Codex signed in to ChatGPT and not connected still gets openai_base_url while more of its ChatGPT accounts are on in magpie (failover, stash codex.failover; with a CC Switch mirror as its provider, the mirror's base_url and codex.mirror_failover), so a turn its own account has no allowance for goes on to the next. That Codex is FailingOver: not Wired, yet its requests go through magpie. The Agents row says so and what turns it off (FailoverSaid in the CLI and TUI, failover in /api/state, a button to Providers › Codex in the GUI), and the gateway hands it only its own models from /backend-api/codex/models (CodexOwnOnly, set on gateway.CodexOwnOnly by main; its ETag carries provider.CodexOwnListTag, and Sync ages a models_cache.json without it). A connected WSL Codex shares the gateway path, so while one is connected every Codex gets magpie's models (#1385). A base URL the user wrote by hand (#856) isn't failover's and stays a plain not-connected row. A Codex the user disconnected gets no failover till they connect it again. The app serving the gateway takes failover out as it quits (EndFailover, EndCodexFailover in OnShutdown), so a Codex left on its own goes straight to OpenAI rather than retrying a gateway that's gone (Leon920717 on X); the next start's Sync writes it again. Codex's app-server read the old base URL as it started and keeps it, and KeepCodexDaemonCurrent ends with magpie, so EndCodexFailover restarts it there when no codex session is on it (codexDaemonCheck); with one on it, it stays on the gone gateway until the user restarts it (thisisvainxx on X: "several restarts"). A connected Codex keeps magpie as it quits: its model is one of magpie's, and Disconnect is what puts its own config back. A magpie that ends without quitting (killed, a crash, magpie serve) leaves failover in place.
  • A Codex thread keeps the provider it was started on. While a magpie model is on, CC Switch's provider tables go through magpie too (takeTables), and get their own base URL back when Codex steps off magpie (giveTables, stash codex.tables). CC Switch's OpenAI mirror (a table of another id, name = "OpenAI", requires_openai_auth, no base_url) isn't reached by openai_base_url, which takes only the built-in provider to magpie: a thread started on it and reopened went straight to ChatGPT, which refused the magpie model picked in it, and magpie never saw the request (#1796). While Codex goes to magpie by the base URL, takeMirrors gives each such mirror magpie's ChatGPT backend as its base_url (stash codex.mirrors), and giveMirrors takes it off again; a mirror a profile names, or one whose base_url was changed since, stays as it is. Moving the threads onto another provider is the Sessions page's Move (#887).
  • An agent's config is written in the form the installed version reads, taken from what that version declares, not the latest one. VSCodium has no Copilot Chat of its own, and the Marketplace's last one (0.48.1) has no Custom Endpoint provider, only OpenAI Compatible (customoai, #1014). magpie reads the provider list in the package.json of the github.copilot-chat installed under ~/.vscode-oss/extensions (vscodeChatOf). It writes its group for customendpoint when that is declared, for customoai when only that is, with each model's window as maxInputTokens + maxOutputTokens and the token as x-api-key (that version drops an Authorization in requestHeaders). A missing or unreadable extension keeps customendpoint. Sync rewrites a group written for the other provider, and Check reports it, as it does a Copilot Chat declaring neither. That Copilot Chat registers its providers only while signed in to GitHub with a personal Copilot plan, which the Notice says.
  • Tuned settings are written only on the user's click, never by Sync or Connect. The value there before is stashed once (tune.<agent>.<knob>[.<model>] in stash.json), so Undo puts it back, or takes the key out (and a modelSettings entry left empty). A value the user changed after the click is theirs: Undo then only forgets the stash. A variable that comes before the setting (CLAUDE_CODE_AUTO_COMPACT_WINDOW, FORCE_PROMPT_CACHING_5M, CLAUDE_CODE_PROMPT_CACHE_TTL, CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL, in settings.json's env or magpie's own) is shown as locked and Apply refuses, since the setting would change nothing. Claude Code compacts at the smaller of the window set and the model's own (its /autocompact says "capped to 200k by model"), so advice starts from that, and a model that isn't Claude's has no window here (magpie's own compact wiring serves it). Advice changes a value only when the replay saves 3% or more, and of the windows within 1% of the cheapest takes the largest. Tokens are weighed as billed: cache reads 0.1, 5-minute writes 1.25, hour writes 2, output 5 for Claude; reads 0.1, writes 1, output 8 otherwise.
  • A plugin's agent writes each key in place (JSON, YAML or env), the user's comments and other keys kept. An object or array connect returns is taken as its JSON text (agentplug.keys), so it is written in the order the plugin gave it, not sorted as a Go map would be: Kilo lists its effort variants in key order (#1890, TestPluggedKeepsPluginOrder). What each key held before the first write is stashed under plugin:<id>:<path>, typed, and its own model or Disconnect puts every key back and takes out the ones that weren't there; the file is never written whole. A connect that throws or takes over a second writes nothing and says why. Its gateway key is magpie-<id> (agentKeyAt), and usage names its requests by that key or by its ua words (usage.PluginAgents). Its agent.library (instructions, mcp with mcpFormat, skills) gives it the Library's three as well, written by internal/library as any agent's are (library); a mcpFormat outside agentplug.MCPFormats, or an mcp without one, keeps the plugin from loading.
  • StepCode config root resolves to the parent of an absolute STEP_CODING_AGENT_DIR (agent resources directory differs from config root; relative values ignored), or STEPCODE_CONFIG_DIR under home when native, defaulting to ~/.stepcode (stepcode.go). Project configs override global configs in StepCode, but magpie manages global configuration only (config.toml and models.json). Detection is strictly directory-only via agentDir, avoiding collision with Smallstep's bare step command on PATH. Wiring performs an atomic two-file edit (models.json provider block and config.toml top-level defaults/scope) backed by stash.json. Custom fields within providers.magpie are preserved during sync, and the original provider block is restored on disconnect. Disconnect restores original defaults, preserves user native changes and custom scope edits, and removes newly created files only when empty.
  • An agent is detected by its config file, its folder, or its command on magpie's PATH (Detected). That PATH is the login shell's plus the folders users' tools go in (proc.UserPath: ~/.local/bin, npm's prefixes, the Node nvm's default alias resolves to (the highest installed when it names none), bun, Homebrew, ...), so a CLI a terminal doesn't find can still be found and listed: an npm install under a Node the terminal no longer uses. /api/agents/cli then gives where it is (path) and offPath when the login shell's PATH (proc.LoginPath) lacks its folder, and the Agents row says "Not on your terminal's PATH", its tip naming the file (悠悠哥 on Discord: Codex 0.162.1 listed with no codex on PATH and no ~/.codex). An unknown login PATH says nothing. A folder another tool writes too doesn't count (dirShared): Pi's for omp, ~/.copilot for the Copilot CLI, which GitHub Copilot's JetBrains and VS Code plugins also write, and Qoder's and Qoder CN's, which Qoder's JetBrains plugin fills. A config file another tool writes first counts only when pathOwn says it is the agent's: Qoder's settings.json holding enabledPlugins alone is the plugin's (qoderPluginOnly; #1495, TestCopilotFolderFromAnIDEPluginIsNotTheCLI, TestQoderSettingsFromAnIDEPluginIsNotTheCLI).
  • Tests never touch the real machine. TestMain uses testenv, which points HOME, USERPROFILE, the XDG folders and APPDATA into a temporary folder, clears agentenv.Vars and puts failing stand-ins for keychain tools and agent CLIs on PATH. Agent-specific side effects (Aside, the Zed keychain, Codex's usage check) are also stubbed in TestMain.

Verification

go test -tags nogui ./internal/agent -run '^TestStepCode'
go test -tags nogui ./internal/agent -run 'TestClaudeAutoModeReview|TestT3CodeAutoModeReview|TestConnect|TestDisconnect|Drift|TestKeptAddress|TestWSLAgentAddress|TestReachProbe|TestDryRunKnowsTheAskersProviders|TestReseat|TestPort|TestWSL|TestClaudeKeepsItsClaudeAISignIn|TestClaudeSignIn|TestClaudeOwnEndpointWithAnEmptyKey|TestClaudeAtAnOlderGatewayAddress'
go test -tags nogui ./internal/agent
go test -tags nogui ./internal/agent -run '^TestAir'
go test -tags nogui ./internal/agent ./internal/edit -run 'TestSyncKeepsAnAddressOnAnotherMachine|TestKeptAwayOnlyWhatIsSure|TestKeyValuesFormats|TestFilteredWrites'
go test -tags nogui ./internal/edit -run 'BOM|CRLF'
go test -tags nogui ./internal/agent -run '^TestAnte'
go test -tags nogui ./internal/agent -run '^TestAstrBot'
go test -tags nogui ./internal/agent -run '^TestJcode'
go test -tags nogui ./internal/agent -run '^TestGrokApp'
go test -tags nogui ./internal/agent -run '^TestPlugged'
go test -tags nogui ./internal/agent -run 'TestCodexFailoverOnlyKeepsOwnModels|TestCodexOwnModelThroughMagpieWhileAccountsOn|TestCodexHandWrittenBaseURLStays|TestCodexProxyFor|TestRealProxyProbe|TestCodexEnvTakesLoginShell|TestCodexFailoverHeldWhileProxyDoesNotPassOn|TestCodexProxiedDrift|TestCodexFailoverEndsWithMagpie|TestCodexMirrorFailoverHeldAndEndsWithMagpie'
go test -tags nogui ./internal/agent -run 'TestDisconnectStaysThroughSync|TestCodexDisconnectStaysWithAccountsOn|TestCodexAPIDisconnectStays'
go test -tags nogui ./internal/tune ./internal/agent -run 'TestCompact|TestCacheTTL|TestTune'
node --test internal/gui/tests/context-tune.test.cjs
node --test internal/gui/tests/agent-connect.test.cjs internal/gui/tests/agent-disconnect-preview.test.cjs internal/gui/tests/claude-signin.test.cjs internal/gui/tests/agent-failover.test.cjs internal/gui/tests/agent-proxied.test.cjs internal/gui/tests/plugin-agent.test.cjs