Files
magpie/docs/subsystems/agent-wiring.md
T
yetone ee7a9b24a6 agent: Grok App is an agent magpie connects: a magpie provider channel with magpie's models and their efforts (#1625, fjrtdk)
fjrtdk asked for Grok App (RongleCat/grok-app, a desktop GUI over the Grok
Build CLI) as a full agent: MCP, skills, RTK, models and effort.

What was already there, read in the App's source:
- MCP: the App reads ~/.grok/config.toml's [mcp_servers] in both of its
  modes and hands them to the CLI it starts, so the Grok Build row's MCP
  sync already reaches it.
- Skills: Grok Build's ~/.agents/skills, synced from the Grok Build row.
- RTK: rtk has no installer for Grok Build, so there is nothing to wire.

What was missing is models, and that is what changed:
- internal/agent/grokapp.go: a new agent, "grok-app" (alias grokapp), for
  the App's agent-home/config.toml under its data folder: GROK_APP_HOME,
  else ~/Library/Application Support/com.grokapp.grok-app or ~/.grok-app
  on a Mac, %APPDATA%\grokapp\grok-app\data (and two older places) on
  Windows, $XDG_DATA_HOME/grok-app or ~/.grok-app on Linux; the first
  that exists.
  - Connecting writes a [model.magpie] channel in the App's own format
    (its custom routes): model, base_url = the gateway's /v1, name,
    api_key (magpie-grok-app, so usage says the App), api_backend =
    "chat_completions", app_provider_mode = "generic", app_models and
    app_efforts as JSON strings (the App unquotes them with serde_json),
    supports_reasoning_effort, app_supports_vision for a model that takes
    images, and context_window when magpie knows it. app_models lists
    magpie's models with their effort levels ("none" left out), so the
    App's model and effort pickers show them.
  - It sets [models] default = "magpie"; what was there is stashed, and
    Disconnect puts it back and drops the channel: the file is
    byte-identical to before (TestGrokApp).
  - A sync keeps the model and the default effort the user picked in the
    App while magpie still serves them, and writes nothing when nothing
    changed.
  - Picking one of the App's own routes (the official "grok", or a
    channel of the user's with a base_url) takes magpie out.
  - The notice says to start a new chat or restart the App, which reads
    its providers when it starts an agent; translated in i18n.js (zh-CN,
    zh-TW, ja, de) and listed in NOTICES.
- agents.go, agentenv.go (GROK_APP_HOME), docs/reference.md,
  docs/subsystems/agent-wiring.md, both READMEs' agent lists.

Picking magpie in the App is a custom route, so the App runs that agent in
its independent mode (its own #557): it clears agent-home's auth.json
rather than syncing the official sign-in. ~/.grok is never written.

What was run:
- go test -tags nogui ./internal/agent ./internal/agentenv ./internal/gui:
  ok. Full go test -tags nogui ./... under a temp HOME: ok.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui: ok.
- Broken by hand, each red: context_window written quoted (TestGrokApp);
  the user's picked model ignored (TestGrokAppSyncKeepsTheirs); their
  default effort dropped (SyncKeepsTheirs); Disconnect not unstashing
  (TestGrokApp); a no-op sync writing (SyncKeepsTheirs); "none" listed
  as an effort (TestGrokApp).
- Real use in a sandbox HOME: a built magpie on 127.0.0.1:3681 with a
  fake upstream; `magpie grok-app magpie/fake/echo-1` wrote the channel;
  the real grok 1.0.50, started as the App starts it on a custom route
  (GROK_HOME=agent-home, --model magpie), answered through magpie, the
  upstream saw echo-1 and usage.jsonl counted agent "grok-app". `magpie
  grok-app default` restored the file (the only difference was grok's own
  [marketplace] line written while it ran). ~/.grok/config.toml untouched.

Not tried: the real Grok App GUI (it would sign in through the keychain
and ~/.grok), a model with effort levels end to end, Windows and Linux
paths beyond TestGrokAppDir.
2026-10-12 01:55:04 +08:00

40 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 and Spelled. 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. 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.
  • 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 = "magpie" makes it the route; what was there is stashed and put back on Disconnect, which drops the channel. 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. The App switches itself to its independent mode when a channel is the route, so Grok Build then runs with GROK_HOME at agent-home; MCP servers still reach it, since the App reads ~/.grok/config.toml's [mcp_servers] in both modes and hands them to each session, and skills are Grok Build's ~/.agents/skills. The notice, while the App runs, says to start a new chat or restart it.
  • 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.
  • 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. 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.
  • 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).
  • 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/ALL_PROXY, else the system's 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 (codex-rs outbound_proxy; tried with codex-cli 0.162.1). 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, 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.
  • 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.
  • 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. 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.
  • 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 '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|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