kensenzhao asked for magpie's routing and quota in Claude Code's status
line. Claude Code runs the statusLine command on every update and cancels
the run that is still going, so the command must answer fast. It must never
make a vendor read.
- `magpie statusline [<provider|account>]` reads Claude Code's statusLine
JSON from stdin. It prints "→ <served model>" from
/v1/magpie/route?session=<session_id>, then each subscription account's
windows ("claude a@x* 5h 62% 7d 41%"). `*` marks the account that served
last. A window whose reset has passed shows 0%. With the gateway off it
prints an empty line. Each request times out after 1s.
- /v1/magpie/quotas?kept=1 (provider.KeptQuotaReport) builds the same
report from the kept cards (CachedCards) and never starts a vendor read.
The plain endpoint can take up to 12s.
- magpie never writes statusLine into Claude Code's settings. The user
adds `"statusLine": {"type": "command", "command": "magpie statusline"}`
themselves (magpie statusline's help, docs/reference.md).
Run: go test -tags nogui ./internal/cli ./internal/provider
./internal/gateway in a sandbox HOME; gofmt -l; go vet natively and with
GOOS=linux and GOOS=windows.
Broken by hand, each went red:
- the CLI asking without kept=1 (TestStatuslineTellsRouteAndEveryAccount);
- dropping the route line (same test);
- KeptQuotaReport calling QuotaReport (TestKeptQuotaReportAsksNobody).
Real use: a built binary against a sandbox gateway on 127.0.0.1:3517.
- kept=1 answered in 0.07s and route in under 1ms.
- `magpie statusline` with Claude-style stdin printed an empty line, since
the sandbox has no accounts.
- Its ~1.1s wall time matches `magpie version`, so that is process start.
Not tried: real accounts, or the line inside a real Claude Code statusLine.
`magpie claude sonnet` sets Claude Code's model to its own alias. That
isn't a model magpie serves, so magpie steps out (unroute) and puts back
the endpoint Claude Code had before magpie. In #2000 that endpoint was
DeepSeek's, which refused Sonnet with a 400. The command printed only
"✓ Claude Code model sonnet". An agent had run it as a read-only query of
the sonnet tier, and nothing in the output said the routing had changed.
set() now checks whether the agent was wired into magpie before the
write. When a non-empty value leaves it unwired, set() prints
"disconnected from magpie: <model> is <agent>'s own, sent to the endpoint
it had before magpie; magpie <agent> <model> with one of magpie's models
connects it again". This covers every agent and field set through
`magpie <agent> …`, not only Claude's aliases. Setting a field back to
default (empty) is left as it was. `magpie <agent> default` already says
it disconnects.
The behaviour itself is unchanged. On an Anthropic sign-in or a Claude
relay the aliases are a deliberate one-word way back to Claude Code's own
models.
`magpie claude help` now has a line under the aliases: "they are Claude
Code's own models, not magpie's: setting one takes magpie out; magpie
claude alone shows each".
Verified:
- TestClaudeAliasSaysItTookMagpieOut covers opus, sonnet, haiku and
fable. It starts from a DeepSeek-style own endpoint (.invalid host),
wires Claude Code to group/advanced and sets the alias. It checks the
notice, that the old endpoint is back, that nothing is printed when the
alias is set again while off magpie, and the help line.
- With the notice disabled by hand, the test fails:
"magpie claude opus: <nil> "✓ Claude Code model opus\n", want it to say
magpie is out" (and the same for the other three).
- TestAgentDefaultInAnyCase first went red on "codex model DEFAULT", so
empty values are excluded.
- HOME=<sandbox> go test -tags nogui ./internal/cli: ok.
- gofmt -l clean. go vet and GOOS=linux/windows go vet -tags nogui
./internal/cli: clean.
A third sync kind: github://owner/repo[/folder] keeps the same sealed
backup WebDAV and S3 keep, as <folder>/magpie/magpie.magpie-backup in a
repository the user already has, written through GitHub's Contents API
with a fine-grained token of its own (Contents read and write), kept in
sync.json apart from the library's GitHub token. The token goes only to
api.github.com: a redirect anywhere else is refused, and the passphrase
may not equal it. Each update is a commit; an empty repository is
initialised by the first backup. Settings › Sync gets a GitHub kind with
Repository, Branch, Folder and token; magpie github mirrors magpie s3.
Inactive servers of every kind are kept in Config.Servers (Other stays
for older clients).
Squashed from yetone/magpie#1130 at 6b5b1c693e1a3a23e177b4d376f3f7f70f3bc23d
onto main. Merge resolutions: the CLI moved to internal/cli since the PR
was cut, so github_cli_test.go moved there (package cli) and the github
command, its help line and `magpie help github` were wired in
internal/cli/main.go and help_cli.go; README's Sync row kept main's
links and took the PR's wording; i18n.js zh-TW kept both sides.
What: `magpie codex model` wrote model = "model" into config.toml (and
applied.json, stash.json); any agent's field name given alone, or as a
value, was set as its model, and `magpie codex DEFAULT` wrote
model = "DEFAULT". Now:
- `magpie <agent> <field>` (any case) prints that one field and writes
nothing;
- a field's name given as a value is refused with a hint
(`magpie claude effort Ultracode`);
- DEFAULT in any case takes magpie out, as `default` does;
- Claude Code's tier names (opus/sonnet/haiku/fable) still set the model,
since agent.ModelAliases marks them, and the agent's help says so.
agent.Field matches key and label in any case; agent.Running is a var
so the cli tests can say Codex isn't open.
Why: ported from waitingsnow's #1129 (commits bbe75c91f, 00bb38581,
244b24a67) onto internal/cli, where the CLI moved after the PR was
opened. The PR's --help part landed earlier as 76db4c6c2 (#1457).
Run: the five new internal/cli tests fail on origin/main without the
cli change (TestAgentFieldNameShowsIt: "✓ Codex model model" and
model = "model" written; TestAgentDefaultInAnyCase: "✓ Codex model
DEFAULT"; the tier-name help line and the Ultracode hint missing) and
pass with it. gofmt -l clean; go vet darwin, GOOS=linux -tags nogui,
GOOS=windows clean; go build for all three; go test -tags nogui ./...
green (an earlier run's internal/agent 10m timeout was a stuck open()
in TestWSLStoppedDistro under a 100%-full disk and load ~44; the WSL
tests pass alone and the full rerun passed).
The root held 89 .go files (30 commands, 59 tests). They move as they are
to internal/cli (package cli), with git mv so history follows them. The
only code change is main() becoming cli.Main(version): the root's new
main.go keeps `var version` in package main, so -ldflags "-X
main.version=…" in the Makefile, the Dockerfile and magpie-releases, and
every workflow, work unchanged. go-winres's rsrc_windows_*.syso still land
next to package main in the root.
Tests that read testdata by a root-relative path now go up one level
(../plugin/testdata/fake, ../sessions/testdata). Five subsystem doc links
point at internal/cli/.
Run:
- go build ./..., gofmt -l, go vet on darwin, linux and windows (nogui)
- builds with tags production, dev, "production nogui"; windows
-H windowsgui; linux CGO_ENABLED=0
- make release-cli TARGETS="darwin/arm64 linux/amd64 windows/amd64
android/arm64" VERSION=9.9.9-tidy: all four built, binary prints
"magpie 9.9.9-tidy"
- docker build --build-arg VERSION=7.7.7-tidy: container prints
"magpie 7.7.7-tidy"
- go test ./internal/cli (default and nogui): 152 tests, the same count
as the root on main
- go test ./...: all packages pass (agent, gateway, library, provider
timed out at 10m under other sessions' load and passed rerun alone
with -timeout 40m; none of them changed)
- the built binary in a sandbox HOME: version, help, ls, providers,
claude, and an unknown command's error