Commit Graph
9 Commits
Author SHA1 Message Date
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