Commit Graph
16 Commits
Author SHA1 Message Date
yetone 5416fdb76b agent: Claude Code on magpie keeps its MCP tools deferred (ENABLE_TOOL_SEARCH)
cybercaius on Discord (#help): the MCP router's 245 tools took 124K
tokens of a 341K context ("Magpie ×245" in Usage › Context). Claude Code
before 2.1.304 keeps tool search off behind an ANTHROPIC_BASE_URL that
isn't Anthropic's, so every router tool's definition went on every
request. 2.1.304 (10-19) turned it on for gateways itself, but a
conversation begun without it stays held off.

While Claude Code is routed through magpie, magpie now writes
env.ENABLE_TOOL_SEARCH="true" into ~/.claude/settings.json: Claude
Code's own documented switch, no prompt or identity change. The gateway
carries deferred tools to every upstream already (#2660,
withoutDeferredTools). It follows the auto-mode review's ownership:
magpie's value is stashed (claude.tool_search), a value the user set,
an empty one too, is theirs, and magpie's goes in desktopOnly/unroute.
T3 Code's magpie instance gets the same "true" in its environment
unless the user gave it a value there.

Not changed, filed as #4755: agents with no tool search of their own
(OpenCode, Gemini CLI, ...) still get the router's whole list; a lazy
router mode for them needs an owner decision. Not changed: Codex, which
already sends tool_search on magpie's catalog (0.165.0 measured: 14
tools, no MCP ones), and newmax/claudescience, which run Claude Code
through the SDK and set no gateway env of this kind.

Run:
- Real Claude Code 2.1.290 on mote, sandbox HOME, sandbox magpie serve
  on 127.0.0.1:3563 built from this tree, a fake Anthropic upstream, a
  245-tool stdio MCP server in the Library behind the router, wired
  with `magpie claude up/fake-1`: first /v1/messages had 12 tools,
  27,443 bytes of tools JSON (+~9KB of deferred names in the messages).
  The same with magpie's ENABLE_TOOL_SEARCH taken out (the old
  wiring): 266 tools, 245 of them MCP, 242,346 bytes.
- Without magpie, against a capture server: 2.1.200 to 2.1.303 send
  every MCP tool (239-257KB); 2.1.304 to 2.1.316 defer them (~28KB);
  ENABLE_TOOL_SEARCH=true in settings.json env or the process env makes
  2.1.200, 2.1.260 and 2.1.290 defer them too.
- TestClaudeToolSearchOn, TestT3CodeToolSearchOn (new); #4755 filed.
- go test -tags nogui ./internal/agent on mote; GOOS=linux and
  GOOS=windows go vet ./internal/agent; gofmt -l.
Broken by hand: writeSearch stashing nothing and writing nothing, and
T3's entry left out: both new tests red. The user-value check skipped:
TestClaudeToolSearchOn red on the user's "false".
Not tried: a real model loading a deferred router tool through
ToolSearch and calling it via magpie (gateway tests cover deferred
tools); Claude Code on Windows/Linux; T3 Code's real app.
2026-11-01 16:15:27 +08:00
yetone bb478f0e50 agent: a look that only ranges over magpie's models reads the list kept
magpieModels gives each caller its own copy of the list it keeps per
agent. Most callers only range over it, or count it, and a range copies
each model anyway, so the copy guarded nothing for them (the models'
own lists were shared before too: the copy was shallow). sharedModels
is the list kept, read only; every `range magpieModels(` and
`len(magpieModels(` in internal/agent (39 files) takes it. Callers that
keep the list, append to it or hand it on still get their copy.

Real accounts (sandbox copy of the owner's HOME, network blocked), 40
polls of /api/state, /api/providers and drift, pprof alloc_space
between two heap snapshots, 616405061 (mrows) vs this (mshare):
  stampedLists.get's slices.Clone 36.7 MB -> gone (under pprof's cut);
  most of it was piOffered (22.5 MB) and claudeViaMagpie (13.7 MB)
  total 637 MB -> 584 MB (runs vary +-25 MB)
  /api/state and drift bodies byte-identical, /api/providers equal but
  for `fetched` and `lapsed` (a refused refresh in the blocked sandbox)

TestModelReadersShareTheList: sharedModels gives the kept array, not a
copy, and no non-test file in internal/agent ranges over or counts
magpieModels(. Broken by hand on mote: sharedModels through get fails
"a shared look copies the kept list"; one `range magpieModels("kimi")`
put back fails naming kimi.go.

Run on mote at this tree (before rebase): gofmt; go vet for darwin,
windows and linux; the new test with TestMagpieModelsKeptWhileCatalogStays,
TestKeptListSharedWithoutACopy and TestViaMagpieKept 3/3 ok;
go test ./internal/agent ok (201s); go test ./internal/gui: only the
known reds TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
TestMainWindowCorners (#3949).
Not run: the full ./... suite.
2026-11-01 06:09:56 +08:00
yetone 6712e367e8 agent: a look at the stash shares one read of it
Each /api/state and /api/drift poll asked the stash (stash.json) for one
value hundreds of times, through Detected, Drift and the agents' wiring
checks, and each ask read the file and parsed it again. In a real-account
heap profile (20 rounds of drift, state and providers) stashLoad was
24-34 MB of what was allocated.

stashShared reads it through filememo.Read, so every look shares one
parse until the file changes, by magpie or by another process. Every
read-only caller uses it now, the 24 files here and QwenPaw's
unstashPeek. stashLoad, which callers change and write back, still gives
each its own map, cloned from the same parse.

Real use: the owner's real-account sandbox, offline (proxy to :9),
20 warm rounds of /api/drift, /api/state and /api/providers:
- allocated 477 MB (d307aa648) -> 411 MB; stashLoad is out of the
  profile.
- /api/state and /api/drift bytes identical to d307aa648's (cmp).

Run on mote (mote-run, Go 1.26.8), at this head rebased on d307aa648:
- gofmt clean; go vet ok, also GOOS=windows and GOOS=linux.
- TestStashLooksShareOneRead alone, 3 times: ok.
- Broken by hand (stashShared reading through stashLoad): red, "a look
  at the stash read and parsed it again".
- go test -timeout 45m ./internal/agent ./internal/gateway: ok (263s,
  691s).
2026-11-01 05:32:29 +08:00
yetone d6beb9975a agent: T3 Code gets magpie on Codex too, picked in T3's model picker
karissasel_ on X: T3 Code through magpie could only run Claude Code; the
harness couldn't be chosen. T3 runs a thread on the driver of the provider
instance its model is picked under, and magpie wrote only a claudeAgent
instance. It now also writes `magpie-codex` ("magpie · Codex", driver
codex) in ~/.t3/userdata/settings.json. Its config.launchArgs (T3's
CodexSettings key, passed to `codex app-server`, and its -c pairs to
`codex exec`) are Codex's own -c overrides: model_provider=magpie, the
same model_providers.magpie table codex.go writes, and model_catalog_json
pointing at magpie-codex-models.json beside settings.json. Values are
quoted for T3's tokenizeCliArgs. ~/.codex/config.toml is not written. A
binaryPath/homePath the user gave T3's own codex instance is carried over.

The user's name, on/off and unknown keys are kept; launch args and catalog
are magpie's, and Check says when they no longer reach the gateway
(the base_url read back through T3's tokenizer; a reverse proxy to magpie
the user put there counts, reachesMagpie, as for every agent). An
older Claude-only wiring gets the instance once on Sync; one the user
removed stays removed (stash t3code.codex) until magpie is turned on for
T3 again. Turning magpie off removes both instances and the catalog. The
option's note says where to pick (4 languages); reference.md and
agent-wiring.md describe it.

Run (on mote, the tree as committed):
- real end to end, sandbox HOME (~/t3e2e/home): settings written by this
  code, magpie serve on 127.0.0.1:47811 with a fake Responses upstream,
  T3 Code server 0.1.5 (npm t3) and @openai/codex 0.165.0.
  `t3 thread start . "Reply with the word pong." --provider magpie-codex
  --model fake/fake-model --wait` answered PONG-T3-CODEX; the upstream saw
  POST /v1/responses, model fake-model, stream true, with the provider's
  own key (sent by magpie's gateway).
- go test -tags nogui ./internal/agent -count=1 -timeout 45m: ok
- gofmt -l; go vet (darwin, GOOS=linux, GOOS=windows) ./internal/agent
- node --test internal/gui/tests/i18n-keys.test.cjs: ok

Broken by hand, each red then restored: no escaping in t3Arg
(TestT3CodeCodexInstance red); Sync without t3CodexSync (both new tests
red); no stash check (TestT3CodeCodexInstanceAddedOnce red); t3CodexOff
never reporting (TestT3CodeCodexInstance red). The first full run
was red in TestReverseProxyIsStillMagpie, Check comparing the launch
args by string; that red is the break for the proxy rule.

Not tried: T3's desktop app window (the server CLI is what it runs); the
Windows quoting on a Windows box; a real vendor upstream (fake one only);
T3's other drivers (cursor, opencode, pi, grok, ...), which are off by
default in T3 and not wired.
2026-10-31 00:11:10 +08:00
yetone 0911a65e7d agent: a catalog sync leaves a magpie provider the user wrote alone while the agent isn't connected
yyddbds on Discord: in Xiaomi MiMo they added a custom provider pointing
at magpie and picked a few models by hand. MiMo's switch on the Agents
page was off, yet after an update the provider held every one of
magpie's models. SyncCatalog runs at each start and update and on every
catalog change, and MiMo Code's Sync (openCodeLike) brought any
provider.magpie block up to the catalog whether magpie wrote it or not.
magpie's default went over a list the user set.

An Agent whose Sync does nothing but keep a block of magpie's name up
to the catalog is now ListOnly, and SyncCatalog runs it only while the
agent is Wired, which is what the Agents page's switch shows. The same
sync was in every sibling, so ListOnly is on all of them: openCodeLike
(OpenCode, MiMo Code and their WSL forms), piLikeKeyed (Pi and forks),
Goose, Crush, Air, AtomCode, Command Code, Droid, Fx, jcode, Kimi,
MiniMax, Mothx, omp, OpenChamber, OpenClaw, OpenPencil, Penguin, Qwen
Code and T3 Code. Left out on purpose: Codex, Claude, Grok and Hermes,
whose Syncs also repair while not connected (Hermes keeps its bots'
magpie provider current) and have their own gates.

Trade-off: a list magpie wrote while connected doesn't follow the
catalog while the agent runs a model of its own (switch off); it does
again once a model of magpie's is picked. Users whose list was already
written over: magpie keeps no copy of the old list, so it stays full;
from this release on it is left alone, and they trim it once by hand
(or connect the agent in magpie and use its model list's Pick).

Tests: TestCatalogSyncLeavesAHandWrittenMagpieBlock (MiMo, Pi and Crush
with a hand-written magpie block stay byte for byte; connected, MiMo's
list follows the catalog; disconnected and written by hand again, left
alone; a magpie model picked in MiMo, followed again).
TestListOnlyAgentsReadConnected: every ListOnly agent magpie connects
reads as Wired (n >= 15), so none of them loses catalog updates.
Fixtures of TestSyncCatalogRewritesAgentLists,
TestModelNameAndLevelsReachAgentFiles, TestSuffixModesReachAgentFiles
and TestPiKeepsTheirKeysInMagpiesProvider, and internal/cli's
TestSaveAnswersBeforeTheAgentsSync (its Pi settings were {}), now have
Pi connected (settings.json defaultProvider magpie), as a block magpie
wrote implies.
docs/subsystems/agent-wiring.md says the rule.

Run (mote, sandbox HOME via the tests' syncHome/codexHome):
- old code + the new test: red (MiMo, Pi, Crush written over; after
  Disconnect written over).
- broken by hand: ListOnly dropped from openCodeLike: red on MiMo
  (lines 52, 82); the Wired gate in SyncCatalog replaced with true: red
  on all three.
- go test -tags nogui -count=1 ./internal/agent: ok.
- gofmt -l clean; go vet ./... for darwin, GOOS=linux and GOOS=windows:
  ok.
- full suite, go test -tags nogui -count=1 -timeout 45m ./... at base
  3bebc3839 (logs kept in the worktree): every package ok but
  internal/cli (TestSaveAnswersBeforeTheAgentsSync, mine, fixture fixed
  above, then ok alone) and internal/gateway: TestAntigravityTurned*,
  TestAntigravityTurnsCodexsGPT5ThreadAwayOnce and
  TestCodexSpentGrokFailingIsTold, red the same on a fresh origin/main
  b26fa0903 copy, filed as #4362.
- rebased on e8d42c02d: vet (darwin, linux, windows) of internal/agent and
  internal/cli, and go test of internal/agent, internal/cli,
  internal/library and internal/gui: all ok. Pushed on 764a032f6,
  whose three commits since touch gateway, usage, provider and chat only.

Not tried: the real Xiaomi MiMo desktop app (the fixture is the OpenCode
shape MiMo Code writes; whether the reporter's provider id is literally
"magpie" is unconfirmed: a provider of another id was never touched).
Lists already written over are not restored.
2026-10-30 14:25:38 +08:00
yetone 79fec406c6 agent, gui: a Claude Code provider switch (CLAUDE_CODE_USE_BEDROCK, …) steps aside while magpie is wired in and comes back after; one magpie can't take out is said (jw1dev on X)
jw1dev's ~/.claude/settings.json had CLAUDE_CODE_USE_BEDROCK=1. magpie wrote
ANTHROPIC_BASE_URL and its model ids beside it. Bedrock ignores the base URL,
so Claude Code went to AWS, Bedrock refused magpie's model, and magpie still
showed Claude Code as connected.

Claude Code 2.1.300's six switches (agentenv.ClaudeProviders: BEDROCK,
VERTEX, FOUNDRY, ANTHROPIC_AWS, ANTHROPIC_GOOGLE_CLOUD, MANTLE; on = 1, true,
yes or on, any case, trimmed):
- In a settings file magpie writes (user settings, WSL twins), a switch
  that is on is taken out on every route that writes the wiring: connect,
  model pick and Rewire/Reapply through writeTiers, and Sync. Its raw JSON
  value is stashed (claude.cloud.<var>, under the distro id for WSL). It is
  put back as written when magpie steps out (Disconnect, or the model set
  back to default), unless the user set it again since. AWS_*/GCP
  variables and a switch that is off stay.
- Where magpie doesn't write it (managed settings, ~/.claude.json's env,
  the login shell's env), Check names the variable, the cloud and the
  file. It reads them in Claude Code's own order: managed wins, then the
  user's settings, then ~/.claude.json, then the shell. Two notice
  templates, translated in zh, zh-TW, ja and de. The row's line and its
  Reconnect pill now show a drift detail through tNotice.
- proc.LoginEnv reads the switches but never sets them in magpie's env,
  and testenv unsets them.
- T3 Code: a switch is never carried onto magpie's instance. Its Check
  says when the user's ~/.claude settings have one on. That Check first
  checks the instance's ANTHROPIC_BASE_URL against the gateway (t3EnvOf),
  as every agent's Check must for TestDriftUnwiredEveryAgent,
  TestPortMovesEveryAgent and TestReverseProxyIsStillMagpie.
- Claude Desktop's Code tab runs with CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST,
  under which Claude Code ignores these switches in settings, so nothing
  changes there.

Run:
- gofmt -l: clean.
- go vet: native ./..., GOOS=linux -tags nogui, GOOS=windows: clean.
- go test -tags nogui ./...: every package ok except internal/agent, where
  t3code's first Check (cloud only) failed the three every-agent tests
  above. Fixed with the wiring check, then the whole internal/agent package
  was rerun: ok (368s).
- GUI, Chromium and WebKit, 102/102 each: new claude-cloud-drift (5
  languages, 1100 and 420px, file and shell notices), gui-de, gui-ja,
  gui-zh-tw, i18n-keys, agent-notice-lang, agent-proxied,
  agent-unreachable, cli-behind, menu-scroll, agent-connect,
  agent-disconnect.
- Sandbox HOME (scratchpad dir, live ~/.claude untouched):
  - Setup: real claude 2.1.300 with settings.json
    {CLAUDE_CODE_USE_BEDROCK:"1", AWS_REGION, AWS_PROFILE}, a magpie-cloud
    binary from this tree serving on 127.0.0.1:3487, a fake OpenAI
    upstream on 3486.
  - `magpie claude fake/fake-model` took the switch out and stashed "1".
  - `claude -p "say hi"` printed PONG-FROM-FAKE-UPSTREAM, and the fake
    logged POST /v1/chat/completions model=fake-model.
  - `magpie claude default` left settings.json byte-for-byte the same as
    before connect (cmp).
  - Control: the switch put back by hand beside the wiring (the reported
    state). Claude Code never reached magpie: the fake logged nothing.

Broken by hand, each went red:
- no dropClouds in writeTiers, then in Sync;
- putClouds returning at once, and putClouds writing over the user's own;
- no claudeCloud in Check;
- the T3 filter and the T3 Check;
- shellVars without ClaudeProviders;
- the tNotice calls taken out of the line and pill: claude-cloud-drift
  went 17 red.

Not tried:
- A project's .claude/settings.json(.local) isn't read, because magpie
  doesn't know where Claude Code runs.
- WSL and Windows were not run for real; tests only.
- Real Vertex, Foundry and AWS accounts.
- T3 Code and Claude Desktop with a switch, run for real.
- The drift shown in the real app window. The CLI has no drift output.
- The user's own ANTHROPIC_MODEL being lost across connect/disconnect is a
  separate gap, fixed in its own commit.
2026-10-15 07:41:30 +08:00
yetone 1e654d8ce7 agent: T3 Code keeps the name, auto-compact and other settings the user gave magpie's provider across a restart (#2030, Kanscape)
T3 Code's sync wrote providerInstances.magpie whole on every start, so
what the user changed on it in T3 Code (Display Name, Auto-compact
after, its switch, colour, launch args, an env var of their own) went
back to magpie's defaults when magpie restarted or updated.

Sync and the field setter now merge into what is there (t3Merged):
magpie's own parts are written as before (driver, customModels, the
gateway's ANTHROPIC_BASE_URL / ANTHROPIC_AUTH_TOKEN and the review
switch), every other key under the instance and its config is the
user's and kept (mergeTheirs), a non-empty displayName and the enabled
switch are theirs, and the environment list keeps the user's own
variables beside magpie's. T3's own claudeAgent instance is never
touched, so it and magpie's keep their settings apart.

Run:
- TestT3CodeKeepsTheUsersSettings: T3's claudeAgent instance beside
  magpie's; the user edits magpie's (name, enabled, accentColor,
  autoCompactWindow "300000", launchArgs, a stale model, a changed base
  URL, an added HTTPS_PROXY), then three syncs. Against the old
  t3code.go it fails on the name, the switch, the colour, the config
  and the env.
- go test -tags nogui ./internal/agent (whole package, ok, 1555s on
  4c746ab39; T3 tests again after rebasing on 27956002c), gofmt -l,
  go vet darwin, GOOS=linux -tags nogui, GOOS=windows.

Not tried: the real T3 Code app (not installed here); the instance
layout follows T3's settings schema from its source. A binaryPath or
homePath carried over from T3's own Claude instance stays once T3
drops it; a value the user gives magpie's review variable is put back.
2026-10-14 05:28:39 +08:00
yetone 2221b63f93 agent, provider: tests no longer read the machine's /Applications or Program Files, so a Mac with DeepSeek Harness.app installed keeps TestAsideOfflineDisconnectRestoresWithoutDaemon green (#1823)
What: every place magpie looks for installed apps outside the home folder
now goes through proc.SystemDirs, which in a test binary testenv isolated
puts the path under the test's home (as it already does for Homebrew's
bin, #1525):
- agent: a new macAppFolders(home) (/Applications via SystemDirs, plus
  ~/Applications) is used by appFolders (desktop apps: Codex, dsh),
  pencilApp, t3App and reasonixDetected;
- cursorLocalRoots: macOS through macAppFolders, Windows' ProgramFiles and
  Linux's /opt, /usr/share, /usr/lib through SystemDirs;
- zedAppPath's /Applications/Zed*.app, npmGlobalPrefix's ProgramFiles npm
  fallback, and provider's /Applications/ZCode.app builtin config.
Production behaviour is unchanged: SystemDirs returns paths as they are
outside a sandboxed test.

Why: HasApp/AppVersion read the real /Applications, so on a Mac with
DeepSeek Harness.app the dsh fixture's CLI was never "missing" and the test
failed every time; CI has no such app, so nobody else saw it. The same
shape was in five other readers.

Test: TestAppFoldersStayInTheTestHome checks every app folder lies under
testenv's home (all OSes), and on macOS that an app installed in the
sandbox's /Applications is the one found.

Run (go1.26.8, sandbox HOME, private GOCACHE):
- repro on old code: appFolders pointed at a temp folder holding a fake
  "DeepSeek Harness.app/Contents/Info.plist" (com.deepseek.dsh) ->
  TestAsideOfflineDisconnectRestoresWithoutDaemon FAIL "native fixture must
  report missing CLI".
- break check: macAppFolders put back to the literal /Applications ->
  TestAppFoldersStayInTheTestHome FAIL (appFolders, macAppFolders,
  cursorLocalRoots look in /Applications; sandbox app not found). Restored:
  pass.
- gofmt -l clean; go vet ./... (darwin), GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./...: clean.
- go test -tags nogui ./internal/agent ./internal/proc ./internal/provider: ok.
- -race -count=5 on the touched agent tests: ok.
Not run: the full go test ./...; Windows and Linux test runs (vet only);
reasonix's Windows registry lookup and Zed's mdfind fallback still ask
the machine (not folder paths) and are left as they are.

Reported-by: mdwsk88
2026-10-12 23:56:20 +08:00
yetone 24350a3722 agent, gateway: Claude Code on a model Anthropic doesn't review gets auto mode's server review turned off, so it no longer says magpie isn't eligible (1EFLOPS on X)
1EFLOPS runs Claude Code through magpie on Codex's gpt-6.1-sol. In auto
mode, Claude Code 2.1.296 says "this session isn't eligible because your
requests go through 127.0.0.1:3425 ... ask your gateway to implement
https://code.claude.com/docs/en/auto-mode-classifier-billing".

What the page asks of a gateway: pass the anthropic-beta header
(dangerous-tool-use-2026-09-03), the request's `safeguards` field, and
`safeguard_results` in the reply through unchanged, and leave tool-use ids
alone. The results are verdicts from Anthropic's own safety classifier.
For a gateway that can't provide them, the page's remedy is
CLAUDE_CODE_AUTO_MODE_SERVER=0. Pro, Max and Team plans never see the
notice. In the bundle, Claude Code falls back on server_unsupported,
server_unavailable_disabled or server_no_result, and the notice shows
whenever there's no real verdict. Only that variable removes it.

Per route:
- Claude subscription bridge, Anthropic API key, relays in front of
  Anthropic, Bedrock and Vertex: already pass the beta, `safeguards` and
  `safeguard_results` through (e8cd4bac8, 8c21a4184). This commit doesn't
  change them. serverReview now uses the shared AutoModeReviewed rule
  (adding the subscription account, which never reaches serverReview).
- Codex/OpenAI and every other non-Claude model: magpie can't answer
  honestly. A verdict would be made up, and "unsupported" still shows the
  notice. So magpie answers nothing on Anthropic's behalf. Instead the
  Claude Code wiring writes env.CLAUDE_CODE_AUTO_MODE_SERVER="0" to
  settings.json. It does this only while Claude Code is routed through
  magpie and no model it can reach there is reviewed. That means checking
  the models shown to Claude Code (and Claude Desktop's while Desktop is on
  magpie), a shown group's members, those providers' fallbacks, and the
  models it is set to (claudeReviewed). If any one is reviewed, the
  variable stays unset, because /model can move the session onto it (the
  reason 8c21a4184 didn't write it at all). The value is rewritten on every
  model set and Sync, so adding a Claude provider turns the review back on.
  It is stash-tracked (claude.auto_mode_server): a user's own value is left
  alone, and magpie's goes on Disconnect, reset or a move off magpie.
- T3 Code (sibling): its magpie instance runs Claude Code on the gateway
  through its own environment, so it gets the same "0" by the models it
  lists.
Not covered: Claude Desktop's Code tab while Claude Code itself isn't
routed through magpie. Desktop users are on Pro/Max/Team, which never see
the notice.

Tests (each fails with its part of the change broken by hand):
- TestClaudeAutoModeReview: off on a non-Claude model; on with a Claude
  model shown, in a group or as a fallback; the user's "1" and "0" kept;
  dropped on reset and on a move to Claude Code's own model.
  A group that keeps its models out of the lists (#1783, Unlists) still
  routes to them, so its Claude member counts: members come from what is
  served, not from the catalog.
- TestT3CodeAutoModeReview.
- TestAutoModeReviewedRoutes: subscription, api.anthropic.com, relay,
  Bedrock and Vertex spellings yes; Codex, DeepSeek's Anthropic API,
  openai/gpt-6 and claudette no.
Mutations that went red: skipping group members, skipping fallbacks,
skipping an unlisting group, overwriting the user's value, not dropping it off magpie, always writing
it, the T3 env always or never, and the subscription not counted.

Real Claude Code 2.1.296, sandbox HOME/CLAUDE_CONFIG_DIR, magpie serve on
127.0.0.1:3591 under a scratch HOME, fake upstreams on 3593 (OpenAI Chat)
and 3594 (Anthropic):
- Before, on fakeai/fake-gpt, -p --permission-mode auto: the notice is on
  stderr (2 of 2 fresh config dirs). With the env in settings: none.
- With this build, `magpie claude fakeai/fake-gpt` wrote the "0", and a
  fresh run shows no notice. The same settings without it show the notice.
- `magpie provider add fakeanth anthropic=... models=claude-sonnet-5`:
  Sync took the "0" out. `magpie claude fakeanth/claude-sonnet-5` and a run
  in auto mode: the upstream got the dangerous-tool-use beta and
  `safeguards` on both turns, answered not_flagged in message_delta, and
  there was no notice.
Not tried: the Claude subscription bridge with a real account (its plans
don't see the notice), and a real Codex account (a fake Chat upstream
stood in for it).

Run: gofmt -l; go vet -tags nogui ./... for darwin, linux and windows;
go test -tags nogui ./... in a scratch HOME with the Go caches pinned.
The only red was TestOTelWaterfallIncludesUnbilledFallback, whose first
export was cut before the root span under load. That is #1794, filed
earlier today; this run is noted there. This change doesn't touch OTel.
internal/agent was timed against the unchanged base under the same load
and ran at the same pace.

Re-run after rebasing on origin/main 94aa15397 (load ~100, so not the
whole suite): gofmt -l on the touched files; go vet -tags nogui
./internal/agent ./internal/gateway for darwin, linux and windows;
go test -tags nogui -count=1 ./internal/agent (1381s) and
./internal/gateway (939s), green. Breaking writeReview to never write the
"0" turned TestClaudeAutoModeReview red, and dropping the subscription from
AutoModeReviewed turned TestAutoModeReviewedRoutes red.
2026-10-12 22:25:35 +08:00
yetone bc320e249f agent: T3 Code, Air, OpenChamber and the rest send the LAN key to a gateway pinned beyond loopback (#1647, ggbdpq)
The gateway takes gateway.Token, and the keys that name an agent
(gateway.TokenFor), only from loopback. When MAGPIE_ADDR pins the
gateway to an address beyond loopback and sharing is on, keyAt gives the
LAN sharing key, and most writers use it. T3 Code's instance still wrote
gateway.Token, so every call it made got 401. Air's and OpenChamber's
Checks compared against gateway.Token, so they said the wiring Sync had
just written was off.

The same mistake was in every writer that pairs gateway.URL() or
gatewayV1() with a fixed token:
- agy, Alma, Cindy, Claude Desktop, Copilot for JetBrains, Cursor's
  local agent, OpenHanako, Pencil, VS Code / Insiders / VSCodium,
  WorkBuddy-family models.json, ZCode (both files), Zed's credential,
  Aside's provider, and the legacy Claude token rename.
- Fix: these now take agentKey(agent) or hereKey(), which are keyAt and
  agentKeyAt for gateway.URL(). On loopback they are unchanged.
- Alma re-keys a provider that holds any of magpie's keys other than the
  one it should have now.
- WorkBuddy and Aside also count the new key as theirs.
- ZCode treats a saved address equal to the pinned gateway as this
  machine's, not another magpie's.

What was run:
- New tests: TestT3CodeKeyBeyondLoopback and
  TestAirAndOpenChamberChecksTakeTheKeyForTheGateway (from the
  reporter's patch), and TestPinnedGatewayKeyForEveryWriter, which covers
  the other writers.
- With the product files reverted, all three are red. The T3 token reads
  "magpie", and each of the 11 writers shows its old key. They are green
  with the fix.
- go test -tags nogui ./internal/agent/ is green.
- gofmt -l and go vet are clean on darwin, linux and windows.

Not tried with a real T3 Code, Air, OpenChamber or a real pinned
MAGPIE_ADDR on a second machine.
2026-10-12 00:44:47 +08:00
yetone ede1e32aec agent, gui: ZCode's row picks which of magpie's models its picker lists, as Pencil's, T3 Code's, WorkBuddy's and Copilot in JetBrains' do now (#1508, NovaTrailX)
settings.hiddenModels had no "zcode", and ZCode's ~/.zcode/v2/config.json
and provider_config.json listed every model. The files magpie writes for
ZCode already leave out what is hidden for it (magpieModels(id) reads
provider.CatalogFor), but its row had no list to hide one in: ZCode's only
field puts magpie in its own picker, with no option among the catalog, and
the Agents page gives a models line and menu only to an agent that has
one (takesCatalog) or ListsModels (Cursor Private Inference).

Audit of every agent row: each agent with a field among the catalog
(viaMagpie) already had the list. Those whose only field puts magpie's
models in their own picker had none: zcode, pencil, t3code, workbuddy,
workbuddy-ai and copilot-jetbrains. They now set ListsModels; Claude
Desktop's tier pickers list the catalog once connected, and cursor-local
had it already.

- agent: ListsModels on those six, its doc says when it applies.
- gui/api.go: the row's JSON says menu (ListsModels), so app.js gives it
  the models button as it does Claude Desktop's and Cursor's, rather than
  a hard-coded set of ids.

Tests:
- TestEveryPickerOfMagpiesModelsCanBeNarrowed: any built-in agent that
  puts magpie in a picker with no option among the catalog and no
  ListsModels fails, so a new agent can't miss it.
- TestZCodeListsOnlyThePicked: from a config the user edited by hand (own
  providers, theme, rules, a manual rule for one of magpie's models, ui
  lang), hiding one model takes it out of both files at the next sync and
  showing it puts it back; the user's entries stay at every step.
- TestZCodeModelList: through the GUI handlers: connect, the row has
  menu and 2/2, hide one, settings.hiddenModels.zcode is set, the row
  reads 1/2, and after SyncCatalog both files list only the other.
- tests/zcode-models.test.cjs: ZCode's row in en, zh, zh-TW, ja, de, in
  the window (1100px) and the tray panel (420px), Chromium and WebKit:
  the line, the menu button, unticking one posts it and the count drops,
  ticking it back; no scroll, no <select>, no overflow. 20/20.
Without ZCode's ListsModels, the first and third fail (tried); without
a.menu in app.js, all 20 GUI cases fail (tried). All in a sandbox HOME;
the live ~/.zcode was never touched.

Run: go test -tags nogui ./internal/agent ./internal/gui; gofmt -l;
GOOS=linux and GOOS=windows go vet -tags nogui ./internal/agent
./internal/gui; node --test on zcode-models, agent-model*, agent-models-*,
agent-notice-lang, click-scroll, cursor-local-*, gui-de/ja/zh-tw and
i18n-keys, both engines: all pass (three load timeouts under a machine
load of ~140 passed rerun alone).

go test -tags nogui -timeout 40m ./... on the rebased tree: every package
ok but internal/gateway, whose TestQueuedStreamKeptAliveForTheMinute hit
its 1.5s read deadline at a machine load of ~130; it passes -count=3 run
alone, and this change touches nothing it runs.
2026-10-11 02:34:30 +08:00
yetone ac79966a6d agent, gateway: Claude Code knows a relay's claude-opus-4.6 as Opus 4.6, not the retired Opus 4 (misteer_ti.)
Claude Code 2.1.296 parses a Claude model id whose version has a dot
(relay/claude-opus-4.6-us[1m], as many relays name them) as Claude Opus
4: it warns the model is retired, asks with max_tokens 32000 and offers
no effort. The same id with dashes (relay/claude-opus-4-6-us) is Opus
4.6 to it: max_tokens 64000, adaptive thinking, effort.

What changed:
- provider/claudedash.go: ClaudeDashed (a Claude-family version's dots
  to dashes; other vendors' ids untouched), ClaudeSpelled (dashed only
  when that spelling comes back to exactly this served id), and
  ClaudeUndashed/ClaudeRead (a dashed spelling back to the one served
  id; an id served as spelled always wins, two ids dashing alike are
  neither; :level and [1m] kept). ClaudeRead also knows a switched-off
  provider's models, so Reseat still moves Claude Code off one
  (TestReseatOff went red without it: opus read "", not
  cop/claude-sonnet-4.5).
- agent/claude.go: every model magpie writes into Claude Code's
  settings is spelled so: model, the ANTHROPIC_DEFAULT_*_MODEL tiers,
  ANTHROPIC_SMALL_FAST_MODEL, CLAUDE_CODE_SUBAGENT_MODEL, modelPicker.
  Every read of them (env, claudeMain, claudeStandInAt) takes the
  spelling back, so fields, applied state and Drift keep the dotted id.
  The user's own values are stashed and given back raw. A Sync rewrites
  what an older magpie wrote dotted. claudeName, the capabilities env
  and the compact-window lookup see the dashed spelling.
- agent/t3code.go and gateway/desktop.go (claudeLooking): T3 Code's
  Claude slugs and Claude Desktop's Code-tab ids without efforts are
  spelled dashed too. Desktop entries with efforts still use the mythos
  alias, which Claude Code doesn't misparse.
- gateway.go: validateModel and unprefixed take the dashed spelling
  back to the served dotted id, before key limits, middleware and
  usage see it.
- docs/subsystems agent-wiring and gateway-routing say so.

What was run:
- New tests: TestClaudeDashedIDsReachTheDottedModel (gateway),
  TestClaudeDottedVersionsGoInDashed, TestClaudeDottedServedDashedToo
  (agent), TestClaudeDashedOnlyClaudeVersions, TestUndashInExactWins,
  TestClaudeSplitKeepsEffortAndMark (provider).
- Break-it checks:
  - With ClaudeSpelled/ClaudeUndashed made identity:
    TestClaudeDottedVersionsGoInDashed fails ("the main model and its
    followers": model relay/claude-opus-4.6-us).
    TestClaudeDashedIDsReachTheDottedModel fails (sent
    "claude-opus-4-6-us", want "claude-opus-4.6-us").
  - With ClaudeRead alone made identity, the agent test fails at
    "read back" (model:relay/claude-opus-4-6-us).
- Real use: the installed claude 2.1.296 in a sandbox HOME and
  CLAUDE_CONFIG_DIR, against an in-process gateway on a free port and
  a fake Anthropic upstream. The settings.json was written by
  agent.Find("claude").Apply("model", "relay/claude-opus-4.6-us").
  - Dashed (magpie's write): the upstream got model claude-opus-4.6-us,
    max_tokens 64000, thinking adaptive, effort high. Claude Code
    reported canonicalModel claude-opus-4-6, maxOutputTokens 64000.
  - The same config with the dotted id by hand: max_tokens 32000,
    canonicalModel claude-opus-4-0.
- Full go test -tags nogui ./... (TestReseatOff red on the first
  run, fixed as above; agent, provider, gateway and main rerun green),
  gofmt -l, go vet, and GOOS=linux and
  GOOS=windows go vet -tags nogui on the touched packages.
2026-10-10 19:44:26 +08:00
tobitege 21702d01ff Add German translation; harden paths against unset env vars (#770)
* Add German translation and harden paths against unset env vars

Add a German locale to the GUI, tray menu, usage alerts and website home page, and refuse to start when the home folder is unset or relative so nothing is written under the working folder; the pi plugin no longer adopts the user's PI_CODING_AGENT_DIR, and an inherited APPIMAGE no longer selects portable mode. Scripts refuse to run from the wrong folder or empty a shared out folder, and a new internal/testenv sandboxes every test package from the user's real files, which also fixes the Claude picker and Termux installer tests on Windows.

* Makefile: know magpie's folder by its go.mod, so paths with spaces work

The check compared $(CURDIR) with $(dir $(abspath …)), which make splits on spaces, so a checkout under 'My Projects' or 'John Doe' refused every target. It now reads go.mod relative to the working folder and wants magpie's module there: make -C and a symlinked Makefile work, make -f from another folder still stops before any recipe runs.

* i18n: German for the strings main added since, with a parity test

75 strings main added (group order, patterns, slow-start wait, usage caps, RTK savings …) get their German, and two that main dropped go. gui-de.test.cjs checks, as gui-ja does, that de has every zh string with its placeholders and tags, and that the window reads in German when picked or on a German system.

* appdir: ignore relative folder variables when reading, keep them for children

CheckEnv no longer unsets anything. magpie reads the XDG folders, APPDATA/LOCALAPPDATA and every agent's folder variable through appdir.Getenv/LookupEnv, which pass over a relative value; the environment stays as it is, so the agents magpie starts get the variable as the user set it. That covers what proc.UserPath lends from the login shell too, which is set after main's check and reached the desktop app unchecked. On Windows a path rooted on the current drive (\Users\x, Git Bash's /c/x) counts as usable, and magpie version and help answer without a home, before run makes any folder.

* Sandbox the tests main added since

internal/wslrun gets testenv's TestMain, and four tests main added that set HOME alone set their home with testenv.SetHome, so on Windows they don't read the runner's profile through USERPROFILE.

* agentenv: PI_CONFIG_DIR and OPENCODE_DB take relative names on purpose

omp puts $PI_CONFIG_DIR under the home and OpenCode a relative $OPENCODE_DB in its data folder, so neither depends on the working folder: appdir no longer passes them over.

* i18n: German for the Library's multi-select and System One's decision API

The 19 strings main added since (#791's skill multi-select, the decision API snippets) get their German; the one main replaced (four APIs → five APIs) goes.

* appdir: tidy the import into magpie's group; say what Go makes of /c/x

The appdir import joins the group of magpie's own imports where a file has one. rooted's comment now says that Go takes a Git Bash path like /c/x as \c\x on the current drive, not C:\x.
2026-10-04 23:30:56 +08:00
yetone 0a10be9cf9 agents: T3 Code gets a Thinking switch beside Reasoning for magpie's models (owner: T3 的 thinking 开关也加上吧) — each magpie custom model that thinks at some level (an effort other than none) now carries T3's boolean "thinking" option descriptor, on at first, as T3's own Claude Haiku has it. T3's Claude adapter sets Claude Code's alwaysThinkingEnabled from it, and Claude Code's requests with thinking off reach the gateway with none (thinking.disabled for non-Anthropic models), so the switch turns reasoning off. A model with Claude Code levels keeps its Reasoning pick, and Haiku-like ones get the switch alone. TestT3CodeEfforts covers it; t3Format accepts boolean descriptors. Not tried in a running T3 Code. 2026-10-03 11:58:14 +08:00
yetone 12cc2089e4 agents: each magpie model in T3 Code has a Reasoning pick of the levels it takes (KevinXC on Discord: 加进去的那些模型没有任何 reason 和 thinking 的设置,导致现在所有的模型都默认是 medium) — magpie's custom models in T3 Code's magpie instance were a slug and a name, and T3 shows a custom model with no capabilities with no options and sends Claude Code no effort. T3 Code's custom model entry takes capabilities.optionDescriptors (packages/contracts model.ts CustomModelEntry), which replace the driver's default in its picker, and its Claude adapter hands the effort chosen to the Agent SDK as it is for a custom model (no effortMap), which Claude Code sends to the gateway. Each model now gets an "effort" select labelled Reasoning, as T3's own Claude models have it, of the levels it takes that Claude Code can send (low, medium, high, xhigh, max, within claudeEffortsFor for Claude's own models), medium chosen first, else the lowest; a model with none (or only none/minimal) gets no pick. TestT3CodeEfforts is new, and t3Format now decodes a custom model's capabilities strictly as T3's schema has them (one default per select). Not run against a live T3 Code. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-03 01:47:42 +08:00
yetone ff36a2994f agents: T3 Code gets magpie as a provider of its own, every magpie model in it (KevinXC on Discord: T3 Code's Settings → Providers lists Codex, Claude, Cursor… each with "Add custom model"; magpie's models should be there without adding them one by one) — T3 Code (pingdotgg/t3code) keeps its settings in ~/.t3/userdata/settings.json ($T3CODE_HOME/userdata), sparse JSON its server watches and reloads on an outside edit, and besides its built-in providers takes provider instances of one's own: {"providerInstances":{"<id>":{"driver","displayName","enabled","environment":[{name,value,sensitive}],"config":{"customModels":[{slug,name}]}}}}. A claudeAgent instance runs Claude Code (the Agent SDK, ~/.claude settings read as Claude Code reads them) with its environment added, and sends a custom model's slug as Claude Code's model. The new t3code agent (t3code.go) adds the instance "magpie": driver claudeAgent, displayName magpie, ANTHROPIC_BASE_URL the gateway and ANTHROPIC_AUTH_TOKEN the token Claude Code is routed with (so its requests are Claude Code's to the gateway, haiku tier and all), not sensitive so T3 keeps them in the file rather than its secret store, and every magpie model shown to T3 Code as a custom model, a 1M one marked [1m] as for Claude Code (claude1MFor). The binary path and Claude home the user gave T3's own Claude (its instance, else the legacy providers.claudeAgent) are carried over. It is magpie's alone: the user's instances, their custom models and T3's other keys stay, off takes only it out, and the catalog sync rewrites it only where it is. T3's Codex lists Codex's model/list, which is magpie's catalog once Codex is routed through magpie, so it needs nothing; T3's own Claude asks for Claude's models by their full ids, which the gateway already sends to Claude Code's tiers (claudeTierStandIn). Found by ~/.t3 or, on a Mac, T3 Code (Alpha).app / T3 Code.app; T3CODE_HOME is in agentenv.Vars. Its icon is T3's mark (assets/prod/logo.svg, MIT), its letters alone so it draws as a mask; the option's note has its Chinese. Checked against T3 Code's own schema (effect 4.0.0-rc.115, packages/contracts at 54084ae1): the file magpie writes decodes as ServerSettings, magpie's config as ClaudeSettings, and encodes back to the same instance. Not run against a live T3 Code. TestT3CodeInstance (the user's instance, legacy Claude binary path and T3's key kept through on, sync and off; magpie's instance decoded strictly; found only with ~/.t3; among All()), TestT3CodeHomeAndInstance ($T3CODE_HOME, a file made, the Claude home carried from the user's claudeAgent instance) and TestStateListsT3Code are new. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass. 2026-10-03 00:15:53 +08:00