The Agents page looked for ~/.claude/settings.json alone, while the
sessions, the Library, the sign-in, the account import and the gateway's
Claude subscription all read $CLAUDE_CONFIG_DIR. A Claude Code whose
folder is elsewhere (CLAUDE_CONFIG_DIR set) wasn't listed when its CLI
wasn't on magpie's PATH either, and a pick, a tune and the gateway's
stand-in went to a ~/.claude it never reads. The sibling of CODEX_HOME
(d47c0fea0).
appdir.ClaudeDir/ClaudeDirIn is now the one place that knows the folder;
the six copies in sessions, library, gateway and provider use it, and the
agent's place.claudeDir (a WSL distro keeps ~/.claude) gives it to
claudeIn, StandIn and tune.
Run: TestClaudeConfigDirTakesThePick (red with claudeDir reverted to
~/.claude), go test of agent, appdir, desktopdir, sessions, library,
gateway, provider; the full go test -tags nogui ./...; gofmt -l; go vet
-tags nogui on darwin, linux and windows; the test on the Windows box.
On Windows, PowerShell 5.1's `Set-Content -Encoding UTF8`, Notepad and
Claude Code channel switchers save ~/.claude/settings.json with a UTF-8
BOM in front. Claude Code reads such a file; magpie's JSON layer handed
the BOM to json.Valid and gjson, so `magpie claude <model>` failed with
"<path>: invalid JSON/JSONC" and the agent couldn't be wired at all. TOML
refused the same with "UTF-8 BOM is not supported", though Codex's own
parser (toml_parser's lexer) skips a BOM, and env/YAML files glued the BOM
to their first key's name.
The fix is at the package's two choke points, so every format and every
caller of edit.Read gets it:
- edit.Read returns the file without a leading BOM (the agent package's
own readers, Claude Desktop, Ante, Empryo, Snow, Pi MCP etc. go through
it).
- WriteAtomic puts the BOM back when the file it replaces starts with one
and the new bytes don't (keepBOM). The user's file keeps the encoding it
was saved in: the tools that wrote it may expect it, and the agent read
it with the mark before, so keeping it is the user's own bytes, not a
guess. A file without a BOM never gets one; an emptied file stays empty.
This is what astrbot.go already did for AstrBot's cmd_config.json.
- PatchJSON (bytes in, bytes out) reads through and keeps a BOM too.
- The TOML "BOM is not supported" error is gone with the case it named.
- Siblings read outside edit.Read: Claude Code's settings.json and CC
Switch's legacy config.json in the importer, and Crush's provider list,
trim it with the new edit.TrimBOM.
- Prime Agent's Disconnect (beforeMagpie.restore, on main since this
work began) compares the file with its copy from before through the
BOM, so a BOM'd settings.json is put back byte for byte and the copy
removed; it used to stay as magpie left it, the copy beside it.
The reporter's fork commit (AnxForever/magpie 0bb750c1) was reviewed: it
trimmed the BOM in the seven JSON entry points and wrote the file back
without it; this change keeps the BOM instead and covers TOML, YAML, env
and the readers outside the JSON layer.
Run:
- New tests built on a Windows-shaped settings.json (BOM + CRLF + the
user's env and permissions): TestJSONSettingsWithBOM, TestPatchJSONKeepsBOM,
TestJSONItemWithBOM, TestTOMLConfigWithBOM, TestEnvAndYAMLWithBOM fail on
the old code ("invalid JSON/JSONC", nothing found) and pass; with keepBOM
disabled by hand four of them go red. TestWriteAtomicAddsNoBOM.
TestPrimeAgentRoundTripWithBOM fails on main (not put back) and passes.
TestClaudeConfigDirImport (BOM case) and TestImportCCSwitchConfigWithBOM
fail on the old importer ("invalid character 'ï'") and pass.
- Full chain in a sandbox HOME: old binary `magpie claude
deepseek/deepseek-flash` on a BOM'd settings.json -> "invalid
JSON/JSONC"; new binary -> "✓ Claude Code model", BOM and CRLF kept, the
user's env untouched; `magpie claude model default` after it leaves no
blank line. Old `magpie codex gpt-5.5` on a BOM'd config.toml -> "UTF-8
BOM is not supported"; new -> set, BOM kept.
- Windows box: the edit package's test binary passes whole; magpie.exe
`claude deepseek/deepseek-flash` on a settings.json written by
PowerShell 5.1 Set-Content -Encoding UTF8 (sandboxed USERPROFILE/APPDATA)
sets the model and keeps ef bb bf.
- go test -tags nogui ./internal/edit ./internal/agent ./internal/provider
./internal/library; gofmt -l; go vet (darwin, GOOS=linux, GOOS=windows)
on the touched packages; the full suite.
Dudung1018's CC Switch had third-party providers named as magpie's
subscriptions are: a Pi proxy "workbuddy", an OpenCode relay "Claude".
Reproduced in a sandbox GUI with a CC Switch db in cc-switch's real
schema:
- the default import answered 400 "workbuddy is the id of the workbuddy
subscription; pick another name", after some picks had already been
written. That is why the reporter later saw "already added" and couldn't
find where the key went.
- the "Replace it" choice on a row named "claude" wrote the relay's models
as the Claude subscription's picks, and dropped its key and address.
What changed:
- importapps: a row whose id is a subscription's (signed in or not), or
magpie's own, is marked reserved. It is picked like a new one and added
under a free id beside the subscription. Replace is refused for it, and
key mode never joins an account or a provider at another address.
- the picker has a name field on every row whose name collides. A renamed
row is added under its new name, and Replace is no longer offered for it.
"Add as another key" names the provider the key went to.
- import links (magpie://import, magpie import) named or id'd as a
subscription get a free id.
- the new sub-line is in en, zh, zh-TW, ja and de.
What was run:
- sandbox GUI on the old build (the 400, the partial write, the Replace
case), then on the new one. The same picks gave 200 ["Relay 1487",
"Claude (findcg)", "workbuddy"]: findcg got one more key, and relay-1487
and workbuddy-2 were added at their own addresses.
- importapps_reserved_test.go: 4 tests on the real cc-switch schema, all
red on the old code.
- import-collision.test.cjs: chromium and webkit, in en/zh/zh-TW/ja/de, at
900 and 390px, 20/20 passing and red on the old assets.
provider-discovery.test.cjs still passes.
- go test -tags nogui ./... green, gofmt -l, and GOOS=linux and windows go
vet for internal/provider and internal/gui.
The same relay with the same key is often both a CC Switch entry and
what Claude Code's settings.json points at (CC Switch writes it there).
The import picker lists it under both apps as new and turns both on, so
one import added it twice ("Some Relay" and "relay.example.com"). Once
the user removed one, the other copy made the CC Switch entry "Already
added" and it could not be imported again, which is what the reporter
saw.
ImportFromApps now skips an add whose account (key at the address,
sameProvider, as the list's "same" says) a provider already holds,
including one added earlier in the same import. The picker's "Already
added" row also says which provider holds it ("magpie has {name}
already", an existing string), so a leftover copy can be found.
Run: TestImportSameAccountFromTwoAppsOnce (CC Switch db + settings.json
fixtures, default picks) fails without the change ("the relay added 2
times: [some-relay relay-example-com]") and passes with it; go test
-run TestImport ./internal/provider passes. provider-discovery.test.cjs
in Chromium and WebKit (en, zh) passes 13/13, and fails 2 with the row's
new line taken out.
Before this, only MAGPIE_ADDR could move the gateway, and the app on a Mac or one started from the Start menu has no easy way to set an env var.
The setting:
- Settings has a Gateway port field. Any port from 1024 to 65535 can be typed, then applied with Apply or Enter.
- The port is saved in settings.json and kept on this computer (KeepOwn), so a backup or WebDAV doesn't carry it across.
- MAGPIE_ADDR, where it is set, still comes first. The field is then off and says so.
- A port out of range is refused in the page.
- A port another program listens on is refused: "port N is in use by another program: pick another one". The gateway stays where it was.
- With another magpie serving the gateway, the field says to set the port there.
On a change:
- The listener moves live (Relisten listens on the new port before closing the old one).
- When the old port had been taken by another program and nothing served, the gateway starts on the new one.
- Every agent connected to magpie has its config rewritten with the new URL (agent.OnGateway before the move, agent.Rewire after):
- each one whose wiring is now "unwired" is set again;
- Codex signed in with ChatGPT is joined again and keeps its own model;
- Cursor Private Inference's variables and dsh's routes follow.
- What each agent had before magpie (the stash) is kept through this. Before, setting an agent again on the old URL would have written magpie's old URL and token over it.
- The page says how many agents moved.
What follows the saved port (through gateway.Addr()/URL() and settings.GatewayAddr):
- the CLI and healthcheck;
- Running();
- LAN sharing (Port);
- the drift check for the installed magpie, from beside a MAGPIE_ADDR one;
- importapps' "is this entry magpie's own" check.
zh, ja and de strings.
Tests, all failing on the old code:
- TestPortMovesEveryAgent: every agent with a config file is connected at 3591 and moved to 3592. No file keeps 3591, and none is off afterwards.
- TestPortMovesJoinedCodex.
- TestPortLeavesAnUnwiredAgent.
- TestPortKeepsWhatAnAgentHadBefore: the relay URL and own token come back on disconnect.
- TestDriftInstalledMagpieOnItsPort.
- TestSetPortMovesTheGateway, through the API: taken, out of range, moved, the old port silent, POST /api/settings keeps it, MAGPIE_ADDR refused.
- TestSetPortServesWhenTheOldOneWasTaken.
- TestGatewayURLOnSettingsPort.
- gateway-port.test.cjs on WebKit, en and zh:
- out of range, taken (translated), applied by Enter, the agents counted, the new URL shown;
- the MAGPIE_ADDR state;
- no select, no left border, and the page never scrolls (the row is swapped whole, or WebKit laid the list out empty and the view jumped).
Sandbox run (own HOME, settings port 3591, magpie web on 3593):
- Claude Code (over a relay with its own token) and Codex were connected at 3591.
- POST /api/settings/port:
- 3594, held by another program: refused, in use;
- 80: refused;
- 3592: moved [Claude Code, Codex].
- Both configs then say 3592. The gateway answers on 3592 and not on 3591, and `magpie healthcheck` exits 0.
- `magpie claude default` gave back https://relay.example and own-token.
lan-docker, settings-sections, settings-groups, click-scroll, gateway-caller-keys, gui-ja, gui-de and webdav-settings-refresh pass on WebKit.
go vet, the builds (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui -count=1 ./... under a temp HOME pass.
* 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.
* fix(provider): preserve Codex import headers
Copy fixed Codex provider headers into imported providers, including entries that match a preset. Compare headers when detecting duplicates or merging keys so reimports and distinct relay accounts retain their request configuration.
Signed-off-by: jimyag <git@jimyag.com>
* fix(provider): keep Codex preset identity on import
Import fixed headers only for custom providers, matching the existing Alma importer and preset request-shape rule. Cover a preset-host Codex entry so its preset and header behavior remain explicit.
Signed-off-by: jimyag <git@jimyag.com>
* fix(provider): normalize headers before import comparison
Compare headers as they are stored so importing a Codex provider again does not report a duplicate when source values contain surrounding whitespace.
Signed-off-by: jimyag <git@jimyag.com>
* fix(gateway): retain Devin reply channel while awaiting
The response reader can delete a pending call before its caller looks up the channel, causing intermittent no such call errors. Return the reply channel from send so await can receive even after the reader removes the pending entry.
Signed-off-by: jimyag <git@jimyag.com>
* Revert "fix(gateway): retain Devin reply channel while awaiting"
This reverts commit 6278c793b9b4f45dc09106168269915007abffe5.
Signed-off-by: jimyag <git@jimyag.com>
---------
Signed-off-by: jimyag <git@jimyag.com>
Each [model_providers.<id>] table in ~/.codex/config.toml (or $CODEX_HOME) becomes a provider — its base_url, wire_api and bearer token, with the models the top level and the profiles pick for it and their model catalogs; magpie's own table and catalog are left out, as are sub-tables such as http_headers. Claude Code's settings are read from $CLAUDE_CONFIG_DIR when it is set.
Co-authored-by: jimyag <jimyag@users.noreply.github.com>