Commit Graph
3260 Commits
Author SHA1 Message Date
yetone c4e6abf3cc gui, cli: a model id typed with a space in it stays one model, "Opus 5.5" not Opus and 5.5 (#1976)
elonnzhang on #1976: on a Baidu OneAPI relay, typing `Opus 5.5` in the
provider editor's add box (or the add form's Models field) and pressing
Enter added two models, `Opus` and `5.5`. Both read the box with
split(/[,\s]+/), while their hints say "comma separated".

- app.js: one typedIds() for both, split at commas (and line breaks)
  with each id trimmed. chosenIds() (the add box, and an id left in it
  at Save) and the add form's Models field use it.
- CLI siblings, which split the same way: `magpie provider set
  models=` now splits at commas only. A group's models=, models-=,
  fast= and weight= split at commas, and an item with a space that
  names no model the group can have is still split at its spaces, so
  `models=m,b/x a/m` (TestApplyGroupPairs) still works. levels= and
  `magpie visible` (effort levels and family names) are unchanged.
- Tests: the reporter's two GUI assertions in models-add-and-icons
  (from their fork branch). A new model-id-space.test.cjs covers both
  boxes in en, zh, zh-TW, ja and de, Chromium and WebKit, at 1100 and
  420 wide. TestModelIDsKeepTheirSpace covers the CLI. The fork's change
  to provider-add-models.test.cjs is not taken: filling the Models field
  there replaces the picks it holds, so it failed on its own terms.

Run: on the old split, model-id-space fails (4/4 for en and de at 420
in Chromium) and TestModelIDsKeepTheirSpace fails (models = ["Opus"
"5.5" ...]). With the whole-item check forced off, it fails on members.
With the fix: model-id-space 40/40, models-add-and-icons 4/4 and
provider-add-models 4/4 pass. `go test -tags nogui ./internal/cli` is
ok. gofmt is clean, and go vet passes for darwin, linux (-tags nogui)
and windows.
Not tried: a real relay with a spaced model id served end to end.
2026-10-13 18:16:03 +08:00
yetone 47ec2a969f provider: a Sub2API Claude account comes in by its email_address, with its account and organization (#1975)
KKKKKKKEM's Sub2API export of a Claude OAuth account was refused, "the
file doesn't say which Claude account this is": sub2apiEntry read only
credentials.email, and Sub2API keeps a Claude account's email under
Anthropic's own name, email_address. Its CreateAccountModal stores the
token Sub2API was given whole as credentials ({...tokenInfo}: access_token,
refresh_token, expires_at, scope, org_uuid, account_uuid, email_address)
and the uuids and email again in extra (useAccountOAuth's
buildExtraInfo); read in Wei-Shaw/sub2api's source.

The siblings in the same export now come in too:
- email_address in credentials or extra (and extra.email);
- scope, OAuth's space-separated string, as Claude Code's scopes instead
  of the four magpie assumes when a file says none (importScopes, shared
  with loginEntry's scopes);
- account_uuid and org_uuid as the oauthAccount's accountUuid and
  organizationUuid, so sameLogin tells two Team seats of one email apart
  as it does for a sign-in in magpie, and the session identity has its
  account id.
A ChatGPT Sub2API account already read email, id_token and
chatgpt_account_id, Sub2API's names for them (useOpenAIOAuth's
buildCredentials). The Google importer reads no Sub2API shape, and CC
Switch's import is of API-key providers, with no account email.
docs/subsystems/providers-accounts.md says which fields are read.

Run:
- TestImportSub2APIClaudeAccounts imports the reporter's file as filed
  (tokens put back) and a Sub2API-shaped export with two Team seats of one
  email. Old code: "got #1:failed,#2:failed,#3:failed … the file doesn't
  say which Claude account this is". With only the reporter's one-line
  fix (credentials email_address): "#3:failed", the seat whose email is
  only in extra. With org_uuid not kept: "sk-ant-ort01-a kept as
  team@example.com org \"\"". With scope not read: the seat kept the four
  default scopes.
- gofmt -l, go vet (darwin), GOOS=linux go vet -tags nogui, GOOS=windows
  go vet on internal/provider: clean.
- go test -tags nogui ./internal/provider -count=1: ok (130s).

Not tried: a real Sub2API export or account; `magpie accounts import`
itself, which on macOS writes the active Claude sign-in to the Keychain.
It calls the same ImportLogins.
2026-10-13 18:16:03 +08:00
yetone a19ecdea90 gateway: a relay's data:[DONE] ends the stream, so an agent that hangs up on it is not logged as 499 (#1978)
zhaoyaoyuan's relay ends its Chat stream with `data:[DONE]`, no space
after the colon, which SSE allows. holdWriter.see only knew
"data: [DONE]", so the try never counted as ended, and pi, which stops
reading at [DONE], was logged 499 "the agent canceled the request" for
a reply it had whole (48 of 58 requests through that relay).

streamEnds now lists every spelling a relay sends: data: with and
without the space, event: message_stop with and without it, and the
JSON type markers with and without a space after the colon (Python
relays write `"type": "message_stop"`). The SSE markers are anchored to
the start of a line, and the stream's first byte counts as one, so a
reply whose text quotes "data:[DONE]" no longer ends it (the old
unanchored "data: [DONE]" did).

Siblings: every other SSE reader in the gateway, middleware, redact and
library (sniff, sse.readSSE, ttft, streamEvent, loop_guard, member,
chattidy, textcalls, toolsearch, grok_*, gemini_signature, codex_limits,
qoder, provider/test.go) cuts "data:" and trims the space already, so
holdWriter.see was the only one with a spelling written in.

Not changed: an agent that hangs up on the finish_reason chunk, before
[DONE] (the repro script's --early mode), is still 499. The usage chunk
and [DONE] come after finish_reason in Chat, and the OpenAI SDK pi uses
reads on to [DONE].

Run:
- TestHangUpAfterStreamEndIsNotCanceled goes through the real Handler
  with an upstream that writes the reporter's stream tail and an agent
  that hangs up the moment [DONE] / message_stop reaches it. With the
  old streamEnds: chat unspaced, chat unspaced CRLF and anthropic
  unspaced FAIL "a reply the agent had whole was logged as 499 \"the
  agent canceled the request\", out=31"; chat spaced passes on both.
- TestHoldWriterSeesEveryStreamEnd cuts each stream at every byte. Old
  code: "chat unspaced cut at 1: ended = false, want true". With the
  markers unanchored: "text about DONE cut at 1: ended = true, want false".
- gofmt -l, go vet (darwin), GOOS=linux go vet -tags nogui, GOOS=windows
  go vet on internal/gateway: clean.
- go test -tags nogui ./internal/gateway -count=1: ok (371s).

Not tried: the reporter's relay itself, or the built binary with pi.
2026-10-13 18:16:03 +08:00
yetone db0af71864 gui: the menu bar can show today's or the last 7 days' tokens and cost (#1984)
Settings → Usage → "In the menu bar" lists two more rows after the
subscriptions: "Tokens and cost today" and "Tokens and cost, last 7 days",
ticked and saved as a card is (ids "usage:today", "usage:7d" in
trayUsages; provider ids are [a-z0-9-], so the prefix can't collide). They
show beside the allowances or alone.

- trayusage.go: a total is a card built from usage.SummarizeTop(p, 0)'s
  Totals (the Usage page's own cached numbers, Input+Output as its
  tokensOf counts them): tokens over cost, in the currency Settings picks,
  "+" when some requests had no known price. On the Mac it is a Plain cell
  (no vendor logo; the bird beside it says whose it is); on Windows/Linux
  the tray's text label and tooltip ("Today in magpie / 1.2M tokens (912K
  in · 318K out) / ≈$3.40+ / 152 requests…"). Quotas aren't fetched when
  only totals are picked.
- Clicked, a total opens the Usage page's Overview at its period
  (quotaView → ?view=usage&tab=usage&period=…, read and dropped from the
  URL) or the panel's Usage tab at that period (panelUseFocus).
- Only today and 7d: the Usage page has no 3-day window, and a menu-bar
  number nobody can open in magpie at the same span would disagree with it.
- The pill names a lone total, and counts a mix as "{n} shown" rather than
  calling it subscriptions. Strings in en/zh/zh-TW/ja/de.
- docs/reference.md and gui-shell.md say so.

Run:
- go test -tags nogui ./internal/gui/ (sandbox HOME): ok. The new
  TestTrayTotals/BesideCards/TrayCount went red with each piece broken by
  hand (no Plain, no text branch, no quotaView branch, 3d accepted).
- tray-totals.test.cjs (new) plus tray-usages, tray-inuse,
  proto-menu-overflow (updated for the two rows), i18n-keys, panel-usage,
  allowance-open-read, tray-cell-click: 46/46 in Chromium and WebKit, five
  languages, 1100 and 420 wide. tray-totals fails 5/5 against the old
  app.js.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
- The Mac cell image rendered and looked at (bird, "1.2M" over "$3.40").

Not tried: a real macOS menu bar, nor a Windows or Linux tray; the tray
tooltip is English, as the existing tray tooltips are.
2026-10-13 18:15:18 +08:00
yetone 5241de909a gateway: an image URL a caller sends is downloaded only from public addresses
An images request (/v1/images/edits, /v1/images/generations) may name a
reference image by URL. For a model that takes the image as bytes (an
images API's multipart edit, Gemini's own API, Code Assist), magpie
downloaded the URL itself with the gateway's client, to any address and
through any redirect, and sent what came to the vendor as the image.

fetchPicture, the one place a caller's URL is downloaded (all three draw
paths go through it), now uses publicClient (image_fetch_guard.go):
- the host is resolved and every address must be public (publicAddr:
  not loopback, RFC 1918, fc00::/7, link-local incl. 169.254.169.254,
  CGNAT 100.64/10, unspecified, multicast, documentation/reserved
  ranges, Teredo, nor an IPv4-mapped, NAT64 or 6to4 form of one);
- the request is pinned to the address checked (Host and TLS
  ServerName keep the name), so a name resolving differently later
  changes nothing; a direct dial is checked again in the dialer's
  Control on the address actually connected;
- through a proxy (magpie's, the provider's, the system's) the proxy is
  chosen by the name and sent the pinned address (CONNECT or SOCKS);
  a plain http:// URL through an HTTP proxy is asked for by address in
  Host too, since Go writes the absolute URI from Host;
- redirects (at most 5) go through the same transport; only http(s);
  no keep-alives; the existing 64 MB / stall / 5-minute limits stay;
- what comes back must sniff as image/*, else 400 without the body.

Policy: a request from this computer (local(): loopback, no proxy or
tunnel headers, and not fromBrowser) keeps downloading from anywhere,
since its sender reaches those addresses already and a local agent may
serve images on localhost. Everyone else, a gateway key's holder
included, is held to public addresses. Vendor-returned image URLs
(FetchImage for b64_json, imagemcp, video content) are unchanged: they
are the vendor's, not the caller's. No other gateway path downloads a
caller's URL: chat/Responses/Anthropic/Gemini image URLs are passed on
for the vendor to fetch. Documented in docs/subsystems/gateway-routing.md.

Run:
- go test -race -count=3 -run 'PublicAddr|EditImageURL|PrivateDialer'
- broke by hand, each went red: old client in fetchPicture (all three
  e2e tests), no Unmap (::ffff:100.64.0.1), no pinning (proxy test
  sees the name), no resolve check (redirect to 192.168.1.10 through
  the proxy served), no dialer check, no image sniff, browser allowed
- go test -tags nogui ./internal/gateway/... (full)
- gofmt -l; go vet -tags nogui for darwin, GOOS=linux, GOOS=windows
- not tried: an https:// image through a real HTTP or SOCKS proxy
2026-10-13 18:15:06 +08:00
yetone 6d7b440924 gateway: a request's ms end with its reply, not with what magpie writes down after it (#1939)
bytecode-x's full-suite failures (Millis 3772 for a stream that ended at
~450 ms; Flow 377, so DecodeOf's flow*HeldShare < window told 0/0) came
from after the reply: serve took call.Millis at its very end, after the
answered bookkeeping. answered() saves sticks and servedCandidate's
provider.NoteServed rewrites the last-answer file, both on disk. With
timing stamps added between the last content byte and call.Millis, 12
CPU burners alone gave at most 7 ms of tail (420 samples); with three
dd+sync writers beside them the block between "before served" and
"after served" took 0.7-1.5 s, the whole of the tail, while the stream
itself had ended. A user's busy disk meets the same: a paced reply reads
as one held back and shows no speed, and its duration grows.

- serve keeps `ended`, the time the last try's reply ended (when its Try
  is made), reset at each try; call.Millis is ended-start when a try was
  made, as before otherwise (a lane turn-away). The handed-on records
  of a refused try take try.Millis, the same end.
- decide_group's usage row is timed before servedCandidate, the same
  sibling.
- ttft_test's paced fixture left a leading "~" on its first event (it
  strips it only for i > 0), so those fixtures' first event was no SSE
  event at all (bytecode-x's second point): it now strips it without a
  gap.
- docs/subsystems/gui-shell.md says where a duration ends.

Run: TestSpeedEndsWithTheReply (new: holds sticksSaving for 2 s during a
paced reasoning stream; the request must still take >= 2 s, and its
Millis must not), TestReasoningSpeed*, TestBurstTellsNoSpeed,
TestCodexBackendBurstTellsNoSpeed, TestHiddenReasoning*, TestTTFT*;
full internal/gateway and internal/provider; gofmt -l; go vet darwin,
windows, linux -tags nogui.
Broken by hand: gateway.go's change reverted -> TestSpeedEndsWithTheReply
red ("the reply's ms 2001 count the 2s magpie took saving after it").
Not done: the bookkeeping itself still runs before serve returns, so a
client that waits for the response's end still waits for the disk;
moving those writes off the request path is a separate change. The
decide_group sibling has no test of its own.
2026-10-13 18:11:23 +08:00
yetone af39ee4b5f gateway: a 402 for a usage limit rests the model out of quota, until the window renews (#1979)
Factory answers a Standard pool used up with 402 "You've reached your
weekly standard usage limit (resets in 0h 19min). Switch to Droid Core
...". failure() read every 402 as out of credit, so the whole account
rested a fixed 30 minutes: its Droid Core models (GLM-5.3, the
reporter's fallback) were skipped with it, the "resets in" was ignored,
and renewed() never lifted the rest when the window came back, since it
lifts only failQuota or By=="window" rests (Ziqi-Cui, 09:16Z).

- failure(): a 402 that matches usedUpWords and says nothing of money
  (creditWords, insufficient_quota) is failQuota. A payment 402, an
  empty one, Kiro's monthly count, Command Code's credits stay credit.
- With failQuota the pooled check applies: Factory's Standard windows
  are scoped away from Core (built-in factoryQuota matches; the
  plugin's notModels/models through quotaOfPlugin), so only the model
  rests, and only until its window's end.
- resetsAt also reads "resets in Xd Yh Zmin" (resetsAfter) when no
  windows are known, capped at longestWritten.
- FactoryAllowanceForTest / PluginAllowanceForTest let the gateway test
  build both paths' allowances from their real payloads.

Run: TestFactoryStandardOutLeavesCore (built-in and plugin:factory),
TestPaymentRequiredReadByItsWords, TestResetsInWords; full
internal/gateway (327s) and internal/provider ok; gofmt -l; go vet
darwin, windows, linux -tags nogui.
Broken by hand: the new failure() case removed -> both subtests red
(account rested for credit, GLM resting); resetsAfter returning 0 ->
TestResetsInWords red; quotaOfPlugin's notModels ignored -> plugin
subtest red.
Not tried: a live Factory account; Factory's Droid Core used-up
wording is assumed to read like Standard's.
2026-10-13 18:11:23 +08:00
yetone d46fb1e590 gateway: a tool's strict an upstream refuses is asked again without it, and left out after (#1980)
OpenCode 2 sends "strict": false on every tool through
@ai-sdk/openai-compatible. thonatos's custom provider turned it away with
400 "Unsupported Chat Completions API field: tools[0].function.strict",
which magpie relayed, and OpenCode ended the session. The reporter's
@ai-sdk/openai workaround worked only because magpie's Responses->Chat
translation leaves strict out.

What changed: in passthrough's retry loop, a 400 that names a tool's
strict as unsupported, unknown, unrecognized, not permitted or
extra_forbidden (toolStrictRefusal, strict_refused.go) is asked once more
with strict deleted from Chat tools[].function and Responses tools[]
(namespaces recursed), and marked for that provider and API
(toolStrictRefused, markUnfit). The next request leaves it out before
sending. An upstream that never refused it still gets strict, which the
ChatGPT backend needs (#383, TestResponsesToolStrict unchanged). The fix
is in the gateway, not in what magpie writes to opencode.json: any
client's strict reaches the same refusal.

What was run:
- Real OpenCode 2.0.25 in a sandbox HOME against a gateway built at the
  old code and a fake upstream refusing strict: the reporter's exact
  error ("custom-provider: Unsupported Chat Completions API field:
  tools[0].function.strict", opencode rc=1). With this change: answered.
- TestToolStrictLeftOutWhereRefused with the two recorded OpenCode 2.0.25
  requests (Chat and Responses, 12 tools each): first request carries
  strict, the retry none, the next turn none at once (3 upstream
  requests), another provider still gets strict.
- Broken by hand: without the retry branch both subtests get the 400;
  without the pre-send check, "next turn: 200, asked 4 times".
- TestToolStrictRefusalWordings, with negatives (an invalid schema, an
  invalid type for strict, an unsupported 'store').
- gofmt -l; go vet darwin, linux -tags nogui, windows; go test -tags
  nogui ./internal/gateway -count=1 (ok, 324s).

Not tried: the reporter's actual upstream vendor (not named in the
issue); the Responses refusal wording is assumed to match the Chat one.
A translated request (Chat->Responses) that an upstream refuses for
strict isn't retried by this.
2026-10-13 18:11:22 +08:00
yetone ffd0778696 agent: an agent reaching magpie through a reverse proxy isn't drift, and a sync keeps the proxy's path (#1985)
davisjiahao put magpie behind a company nginx (https://ai.corp.example/magpie)
and pointed their agents there with magpie's key. Every agent whose Check
compares its URL exactly called that "unwired", offered Reconnect (which
writes 127.0.0.1 back), and each start's sync replaced the origin but
dropped the /magpie path.

Decision: a URL that isn't magpie's is still magpie when it ends with
magpie's path, the rest is an http/https address on another machine, and
GET <rest>/ answers as the gateway's GET / ({"name":"magpie"}). Something
else there (a relay CC Switch wrote) stays drift. Loopback on another port
is magpie on an older port: drift, never probed. An unknown answer is not
drift (as unreachable/proxied), so Reconnect isn't offered before the
probe has answered.

- reach.go: magpieAt / realMagpieProbe / reachesMagpie, probed in the
  background through the existing cache; answersAsMagpie shared with
  codex_proxy.go's realProxyProbe. offLoopback takes https too.
- applied.go: wiringOff (the choke point for ~40 agents) accepts it;
  Codex's "bypassed" isn't told for a request to the host the config
  keeps magpie at, or one the gateway saw from it after.
- claude.go (managed settings) and reasonix.go: their own exact checks.
- codex.go: codexKeptGateway keeps https, default ports and a path prefix
  (#816's kept address, trusted by magpie's key); viaBase matches the kept
  codexURL, since at.host() falls back to loopback for https.
- keptaway.go: awayPath keeps the path every URL at the away address had.
- Port moves need nothing: Rewire/OnGateway re-set only unwired agents.
- Picking a model in magpie still points the agent at this magpie
  (documented, unchanged).

Run (sandbox HOME, worktree):
- go test -tags nogui ./internal/agent: ok (297s) rebased on 12ecb6d8e.
  Before the rebase only TestFolderVarsAreListed failed, fixed on main by
  c6de0d2a5.
- New proxy_kept_test.go: every agent behind the proxy has no Check/
  unwired drift, at a relay all but Codex are told, SyncCatalog keeps
  https://ai.corp.example/magpie with its path in every file; Claude
  managed settings; unknown-then-not-magpie; loopback not probed; the
  real probe against httptest serving the gateway's handler under
  /magpie/; Codex https kept address, Reached and lastSeen; signed-in
  Codex via openai_base_url; awayPath table.
- Broke each fix by hand, each went red: wiringOff (claude, claude-desktop,
  gemini, opencode... told), claude managed, reasonix, awayPath (every
  synced file lost /magpie), bypassed host and lastSeen, unknown-as-drift,
  codexKeptGateway http-only/no-path, viaBase.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.

Not tried: a real nginx (Host rewriting, auth in front of GET /), the
Windows box, a real CC Switch. No GUI change.
2026-10-13 18:07:03 +08:00
yetone f64d9312ff site, docs: a Privacy page lists everything magpie sends and how to turn it off (#1986)
#1986 asked what the daily count sends, where the id lives and how to stop
it. The answer was spread over one README paragraph and the reference. A
new page, /docs/privacy (en, zh, ja), lists it from the code:

- the daily PostHog batch (internal/stats): a whole example, the label
  rules for agents/providers/models, partner counts, the
  $process_person_profile:false flag;
- every switch: Settings -> Privacy's two toggles, noStats/noUsageStats,
  DO_NOT_TRACK / MAGPIE_NO_STATS, noAutoUpdate (About -> Automatic
  updates), and that a change applies at the next hourly look;
- the files: install-id (made at the first send, not at first run, as the
  issue said) and stats-sent in settings.Dir(), partner-counts.json in
  the cache folder, their paths per OS and portable, and deleting them;
- what usemagpie.ai sees whatever the settings (update feed every 6h,
  notes, partner list with its 1-in-10 sampled count, /go links, the icon
  proxy) and the Cloudflare Web Analytics on the site's own pages;
- public lists fetched (models.dev, open.er-api.com, npm, GitHub) and
  providers' quota reads with the user's own accounts;
- OTLP export, off by default, its env vars;
- why the count stays on by default in releases.

Every docs page in all three languages gets a Privacy link in its nav and
footer. README (en, zh) and start.html's "What does magpie send about
me?" (en, zh, ja) link to the page. docs/reference.md's Files list gains
install-id, stats-sent and partner-counts.json, and Counting users says
when the id is made, the hourly try, and links the page.

Checked against: internal/stats/stats.go, usage.go,
provider/partner_events.go, settings (NoStats, NoUsageStats,
NoAutoUpdate, UpdateEvery 360, otel.go), appdir, update, fx, catalog,
site/worker.js, and the GUI's Settings tabs/labels in index.html, app.js
and i18n.js (zh, ja).

Run: Playwright (Chromium and WebKit) on all three pages at 1100 and 420
wide, light and dark: no horizontal scroll, no element past the viewport,
no page errors (24/24), screenshots looked at for zh at 420 dark. Every
href/anchor in site/public/docs resolves; relative links in README and
reference resolve. node site/worker.test.mjs passes.
Not run: the page on the deployed worker (the site deploys by hand with
wrangler, so it is live at the next deploy); the language redirect for
/docs/privacy was not exercised beyond the worker's existing tests.
2026-10-13 18:02:01 +08:00
yetone 9e76fcdc68 plugin, cli, gui: a plugin's "password" question is typed unseen, as an API key is (#1982)
A sign-in method's prompts could only be "text" or "select", so a token a
plugin asks for (the Qoder plugin's PAT sign-in, magpie-community/plugins#103)
showed on screen as it was typed, in the app and in `magpie plugin login`.

What changed:
- internal/gui/assets/app.js renderPluginAsk: a prompt of type "password"
  gets a password field (masked), the same field an "api" method's key
  gets. A "text" prompt is unchanged.
- internal/cli/plugins_cli.go askPrompt: on a terminal a "password" prompt
  is read with term.ReadPassword (no echo); piped in it is read as a line,
  as a script answers it, and an empty answer still goes to the plugin's
  validate, as a text one does.
- internal/plugin/providers.go: the Prompt type lists "password". host.js
  passes the type through untouched, so nothing there changes. The TUI has
  no plugin sign-in.
- Docs: docs/reference.md and site/public/docs (en, zh, ja) plugins.html
  say what "password" does and that it is magpie's own (OpenCode has text
  and select).

The answer is only sent to /api/plugin-signin/prompt and the sign-in, as a
text answer is; nothing logs or shows it.

What was run:
- TestAskPromptPasswordIsUnseen (internal/cli): with the password branch
  disabled by hand it fails with `password on a terminal =
  "typed-in-the-open", <nil>, hidden reads 0; want pt-secret read unseen`;
  restored it passes.
- plugin-password-prompt.test.cjs: Chromium and WebKit, en/zh/zh-TW/ja/de,
  1100 and 420 wide, 11/11 each. With app.js put back it fails with
  expected 'password', actual 'text'. plugin-signin and
  plugin-signed-out-account 16/16 in both engines; i18n-keys passes in both.
- gofmt -l clean; go vet for darwin, GOOS=linux -tags nogui and
  GOOS=windows on internal/cli, internal/plugin, internal/gui; go test
  -tags nogui of those three packages in a sandbox HOME: ok.

Not tried: a real Qoder PAT through the community plugin (its PR isn't
merged), and the CLI on a real Windows console (term.ReadPassword is the
same call `magpie plugin login` already uses for an API key).
2026-10-13 18:01:20 +08:00
yetone 12ecb6d8e9 gateway: a gateway key held to a budget, models or accounts is told none of this magpie's accounts, only its own limit and routes (#1981)
321sssrt-bit shared magpie on the LAN with a gateway key held to a budget,
and that key still read every account's quota and balance. A held key
(heldKey: a budget, models or accounts) is someone else's to use, so it
now gets 403 with code gateway_key_held (refuseHeld) on
/v1/magpie/quotas, quotas/history, quotas/cards, POST quotas/refresh and
/v1/magpie/concurrency. That holds from loopback as well as the LAN, the
same as usageSummary already did. /v1/magpie/route tells it only the
routes of its own requests. Route.callerKey is set by trace.beginFor at
all five begin sites, so a route begun without it fails closed. It still
reads its own limit at /v1/magpie/limit. Unrestricted keys and the local
owner are unchanged.

Client side (remote magpie): a 403 gateway_key_held drops the cards kept
from before and shows only the key's own card, instead of "isn't shared".
The cache is now keyed by provider and key (remoteCardsID), so a changed
key never shows what the old one was told, and keepRemoteCards keeps a
read only over one asked before it, so a slow pre-held answer can't bring
cards back.

Decided against letting an account-held key see its own accounts' cards:
that would still show the host's account email and balance to the key's
holder.

Run:
- New TestHeldKeyToldNoAccounts covers keys held by budget, models and
  accounts plus one held to nothing, from 127.0.0.1 and 192.168.1.9.
  Every route goes red with the refuseHeld calls or the route filter
  removed by hand.
- New TestRemoteMagpieHeldKeyShowsOnlyItsOwnCard goes red with the
  errKeyHeld mapping removed. TestRemoteMagpieCardsKeptByKey goes red with
  the cache keyed by p.ID alone.
- gofmt -l and go vet (darwin, linux -tags nogui, windows) are clean.
- go test -tags nogui ./internal/gateway ./internal/provider -count=1
  passes in a sandbox HOME.

Not tried: two real machines over the LAN; the tests drive the handler
with LAN remote addresses. An older client shows "isn't shared" (or its
cached cards until they expire) against an updated host until it updates
too.
2026-10-13 17:59:36 +08:00
yetone 5f3a492541 gui: Settings › Usage turns each Codex account's auto-use resets on and off (Avalon on Discord)
Avalon followed up on foobra12's report (a Codex reset used by itself,
"这个设置在哪儿找呢"): the switch seemed reachable only from the quota in
the tray. The window's Usage page has it on each Codex card, but nothing
in Settings named it, so a search there found nothing.

Change: Settings › Usage gets "Codex: auto-use resets", with a line on
when a reset is used (week used up and no other account can answer, or
before one expires unused; off until turned on, account by account) and
an Off/On row per signed-in Codex account (s.codexUsers, plus any account
still in codexAutoReset that is no longer signed in, so it can be turned
off). A pick posts settings/codex-auto-reset, the same call as the card's
switch; the card's switch redraws these rows. The row is hidden with no
Codex account. Strings in zh, zh-TW, ja and de.

Run (playwright 1.62.0, NODE_PATH to it):
- new codex-auto-reset-settings.test.cjs: 22/22, chromium and webkit,
  en/zh/zh-TW/ja/de at 1100 and 420, plus the no-account case. With the
  renderAutoResetOwn call removed by hand it goes red.
- click-scroll, codex-auto-reset, codex-resets-used, gui-de, gui-ja,
  gui-zh-tw, i18n-keys, reset-reminder, settings-search,
  settings-sections, settings-general, warm-at-own, warm-at-times,
  routing-auto-reset: all green.
- old-webkit: 5/6. The red is app.css's ":has()" (Safari 15.4) at
  ~2836, which is on origin/main 42216ea60 without this change; this
  commit doesn't touch app.css.
- gofmt -l; go vet darwin, linux -tags nogui, windows on internal/gui;
  go test -tags nogui ./internal/gui/: ok.
Not tried: the real app window with a real Codex account; the full GUI
suite.
2026-10-13 17:57:12 +08:00
yetone c6de0d2a54 daemon, agentenv: the service tools run through proc, and PI_DESKTOP_DATA_DIR is cleared in every sandbox
main has been red on ubuntu and macOS since 692a779d3's run (38376844048),
with two guards that each caught a commit run on chosen packages only:

- TestNoCommandBypassesProc: 5617281f5's daemon.run called exec.Command,
  so on Windows the service tools would open a console window. It now uses
  proc.Command.
- TestFolderVarsAreListed: cdb7b5ff7 made Sessions read PI-Desktop's data
  folder from $PI_DESKTOP_DATA_DIR without listing it in agentenv.Vars, so
  a test could read a developer's real PI-Desktop chats.

Run: go test -tags nogui -count=1 ./internal/agent ./internal/proc
./internal/daemon ./internal/agentenv ./internal/sessions (sandbox HOME),
all ok; both tests failed on the run above before; gofmt -l; go vet
darwin, GOOS=linux -tags nogui, GOOS=windows.
2026-10-13 17:49:07 +08:00
yetone 42216ea609 gateway, gui: one model out of its pool rests on that model's rows only, not on the account's other models (#1960, WardLu)
An Antigravity account out of its Claude & GPT pool (claude-opus-5.5
refused until Sunday) rests that model alone: the gateway keys the rest
by restID and still sends gemini-3.8-flash, in its own pool, to the
account. Routing's page didn't know a rest could be one model's: it
kept rests by key or account, so the stage marked the account's
gemini-3.8-flash row "quota used up · back at Sun 17:53", and the row
under Accounts and keys said the whole account was out.

- gateway: Rest.Model names the model a rest is for when it rests by
  restID (a pool, a model not served, a paid model beside free ones);
  "" for an account- or key-wide rest.
- routing.js: restModel reads it (or, for a kept request from before,
  the model on the end of Rest.Key). The stage keeps a model's own rest
  by key and model, so only that model's row rests; an answered try
  ends the account's rest and its own model's. Accounts and keys keeps
  an account's model rests apart from its own: the account isn't shown
  as out, a line names the models resting with why and when, and Try
  now lifts those rests. An account resting as a whole is as before.
- docs/subsystems/gateway-routing.md says so.

Run: routing-model-rest.test.cjs (new), Chromium and WebKit, 1100 and
420, en/zh/zh-TW/ja/de, 20/20; with the old routing.js it fails
("old@x.test: gemini-3.8-flash rests with Opus"). All 74 routing/rest
GUI test files in both engines (456 each, 0 fail).
TestPoolRefusalRestsTheModelOnly checks Rest.Model, set and read back.
go test ./internal/gateway ./internal/gui, gofmt -l, go vet
darwin/linux/windows (-tags nogui).
Not tried: the reporter's real Antigravity account in the app.
2026-10-13 17:40:47 +08:00
yetone 4795f56469 provider, gui, cli: a Codex account's card says the last reset magpie used, when and why (foobra12 on Discord)
foobra12: "magpie会自动使用codex重置卡吗 我发现刚才好像不小心自动给我使用了
一张". Auto-use is off by default and spends only for accounts switched on
(the week used up with no other account to answer, or a reset ~30 min
before it expires), but a reset magpie spent was said only in the gateway's
log. A reset gone from the card read the same whether magpie used it, the
user did, or it ran out.

Each reset magpie spends is now kept in codex-resets-used.json (by account,
when, why: week / expiring / hand, windows started again; 90 days, 200 at
most, under a cross-process filelock, written with steady.WriteFile; a file
that doesn't parse is copied aside to .bad-<ts>, never read as empty). Only
a consume whose outcome is "reset" is kept. useCodexReset carries why:
AutoUseCodexReset passes week, SpendExpiringCodexResets expiring, and
UseCodexReset (Usage page, panel, CLI) hand.

loginReading, the choke point for LoginUsage and the Usage page, attaches
an account's last 5 uses to its reading (cached readings too, so a reading
kept from before a use still says it), and Quota/SubscriptionQuota carry
resetsUsed. The auto-use row on the Usage page's and the panel's card adds
a line "Last reset used: {when} · {why}" (zh 上次用卡:… · 自动,重置卡到期前),
every kept use in its title; an account in brief has it in its switch's
title. `magpie quota auto-reset <account>` lists them. en, zh, zh-TW, ja, de.

The default (off) and the expiry rule are unchanged: both are documented in
the switch's title and only reach accounts the user turned on.

Run:
- go test -tags nogui -count=10 -run TestResetUse ./internal/provider/
- break by hand: noteResetUsed call removed -> TestResetUsesKept red
  ("kept [], want [week hand expiring]"); loginReading attach removed ->
  red ("the card's reading has []")
- node --test codex-resets-used.test.cjs: chromium+webkit, 1100 and 420,
  en zh zh-TW ja de, the Usage page card, brief title, the panel card; 3
  runs green; with the say.append removed, 5/5 red
- codex-auto-reset, routing-auto-reset, quota-curve, click-scroll,
  tray-usages, i18n-keys, gui-ja, gui-de, gui-zh-tw: green.
  old-webkit is red on "Safari 15.0 styles" at app.css .prefs
  .val:has(> .side-effort), from dc2f0da82, the same on origin/main
  692a779d3; not this change's.
- gofmt -l, go vet (darwin, linux -tags nogui, windows), full tests of
  internal/provider, internal/cli, internal/gui, internal/gateway

Not tried: no real Codex account and no real reset spent (the ChatGPT
endpoints are faked); no notification when magpie spends one.
2026-10-13 17:32:39 +08:00
yetone 692a779d3d library: an instruction set can be kept in a file of your own, such as ~/.agents/AGENTS.md (新v学员 on Discord)
新v学员 keeps one user-level ~/.agents/AGENTS.md by hand and wants every
agent to follow it. Only Factory Droid, omp and Cline CLI read that file
natively; Codex, Claude Code, Gemini, OpenCode, Pi, Amp and the rest
don't. Rather than teach magpie a new agent target, a set of shared
instructions can now be kept in that file instead of a copy in the
library, and the library writes it into every agent that is on, as it
does any set.

What changed:
- InstrSet.File: a set kept in a file of the user's own. Its text is
  read from that file, Save writes to it (kept aside in the backups
  first, written atomically, never removed: emptied, it stays empty),
  and Remove lets go of the set without touching the file.
- The file is refused when it is relative, a folder, an agent's own
  instructions or override file (magpie writes into those), a file
  holding magpie's marked block, inside the library, or another set's.
  A file not there yet is made on the first save.
- The GUI checks the active linked file every 30s (KeepLinked) and
  writes a change made in an editor into the agents.
- Carried by davsync or a backup, a linked set goes as its text; where
  the file is stays this computer's. Put back, the set keeps its file
  and the file gets the carried text, never emptied for a text not
  carried. A profile restored with no text doesn't empty it either.
- GUI: New set has "Keep in a file…" (filled with ~/.agents/AGENTS.md);
  a linked set is tagged "Your file", says where it is kept, and warns
  when Droid or omp is on, as they read ~/.agents/AGENTS.md themselves
  and would get it twice. Strings in zh, zh-TW, ja and de.

Run:
- gofmt -l; go vet for darwin, linux/amd64 -tags nogui and
  windows/amd64 on ./internal/library ./internal/gui.
- go test ./internal/library ./internal/gui -count=1: ok.
- New TestLinkedSet, TestLinkRefused, TestLinkedSetCarried. Each was
  broken by hand and went red: putText writing a linked file like a
  library one, Collect not stripping File, Put not restoring it,
  SyncLinked not syncing, linkable not checking agents' own files.
- library-linked-set.test.cjs in chromium and webkit, at 1100 and 420,
  in en, zh, zh-TW, ja, de: 22 pass; red with the file left out of
  create. library-instr-sets and i18n-keys still pass.

Not done or tried:
- No CLI to link a set (`magpie library instructions set <file>` still
  copies once), and the headless `magpie serve` doesn't watch the file:
  after an edit there, `magpie library sync` writes it out.
- Not tried with real Droid or omp reading the same file.
2026-10-13 17:28:26 +08:00
yetone 113672508a claude: a re-told conversation says whose Claude Code's "[Image: …]" notes are, so a text-only turn isn't read as carrying the history's images (#1751)
arvakme's request from Pi over /v1/chat/completions: a read tool's image in an
earlier turn, then a text-only question. Through the Claude subscription the
model quoted "[Image: source: …-magpie-claude-work-501/<uuid>/images/1.png]"
and said the message had an image attached.

Why: a new run is told the whole conversation in one message, and Claude Code
2.1.296 notes every image block of the message it is given in a note of its
own after the message, so after </current_turn>. Read from its binary: with
the session kept on disk (the shared work folder, where the bridge drops
--no-session-persistence for savedSession) it stores each base64 image to
<tmp>/<session>/images/N.png and the note names the path; with the session
off it still notes any image it scaled down ("[Image: original 3000x2000,
displayed at 2000x1333 …]"). So turning persistence off was not enough. Images
under url sources are not noted.

What changed: when the history has images, the current turn's opening says
the notes after it are the history's (or, when the turn has images too, the
history's first and then the turn's), in currentTurnOpen. A history with no
image is told exactly as before, and the history's own text is unchanged, so
its cached chunks are too. countImages is shared with start's log line.

Run against the real model (owner's Max account, its access token in a
sandbox CLAUDE_CONFIG_DIR, Claude Code 2.1.296 with the bridge's flags and
the stream-json message renderClaudePrompt makes from arvakme's request, a
120x60 red PNG):
- old prompt, session kept (as the bridge runs): sonnet-5-5 2 of 2 said an
  image was attached and quoted the path; opus-5-5 2 of 2 quoted it and
  offered to read the file. Old prompt with a 3000x2000 image and the session
  off: 2 of 2 said attached (the size note).
- new prompt, session kept: sonnet-5-5 3 of 3 "no image attached", the note
  named as the earlier image's; opus-5-5 2 of 2 the same; 3000x2000 history
  image 2 of 2 the same; a new blue image in the turn after the red one in
  the history: 2 of 2 "one image, blue", note 1 the history's, note 2 the
  turn's.
The Anthropic request bodies were also captured from Claude Code against a
local fake API to see where the note lands (a text block after the turn).

TestClaudePromptSaysWhoseImageNotesAre builds arvakme's request through
parseChat; it fails on the old code (historyClose always) and with the mixed
case broken by hand. gofmt, go vet (darwin, GOOS=linux -tags nogui,
GOOS=windows), builds on all three and go test -tags nogui ./internal/gateway/
pass.

Not done: the original report's duplicates (18 image blocks for 10 images
from Codex) are a separate question; Codex desktop itself was not run.
2026-10-13 17:24:46 +08:00
yetone ea1ba22c32 gateway, gui: Codex's composer predictions go where Settings › General says, Off among them (#1970)
pluo's Usage view showed Codex calls of kind composer_predictions at
133k-231k tokens each with no cache read: ChatGPT.app's Codex guesses the
user's next message with a hidden turn on a fork of the thread, on the
thread's own model, reading the whole conversation again each time. It
asks only when the thread's provider is "openai", so through Codex's own
ChatGPT sign-in (and a custom table pointed at magpie). The app's bundle
(fge) asks for {suggestion: string|null} and uses b.suggestion||null.

What changed:
- settings.CodexPredictions: "" as Codex sends it, "off", or a model id
  (provider/model, group/<id>); anything else is refused on load.
- gateway: codexPredictionsTo + codexPrediction, wired beside the
  descriptions at both entrypoints (gateway.go and codex_backend.go).
  Off answers {"suggestion":null} from magpie and sends nothing (the
  title Off path made generic as sentNowhere). A model's answer goes back
  only as the object Codex asked for (predictionJSON: think tags and code
  fences stripped, suggestion trimmed, blank = null). Plain text is never
  taken as a suggestion, since Codex would put it in the user's composer
  as their next message; it gives null and is recorded as a failure
  ("prediction: ...").
- usage: purpose "Prediction" for composer_predictions (purposes.js
  regenerated).
- gui: POST /api/settings/codex-predictions, kept by the general save;
  Settings › General row "Codex composer predictions" (Codex's own / Off /
  magpie's models, the app's picker), hidden in gateway mode; Routing's
  story for the kind says Codex's own switch (Settings › General › Show
  predictions) and magpie's. i18n in zh, zh-TW, ja, de.
- docs: gateway-routing.md's Codex section, reference.md's gateway-mode
  list. site/ docs left for the owner.

What was run:
- go test -tags nogui ./internal/gateway/ (full, -timeout 40m),
  ./internal/gui/ ./internal/settings/ ./internal/usage/: pass.
  New: TestCodexPredictionsSetting (default to ChatGPT, off sent nowhere,
  model routed, plain turn untouched, ledger kinds), TestNoPrediction,
  TestCodexPredictionOnMagpie (/v1/responses and the backend path),
  TestPredictionJSON; gui TestCodexPredictionsSetting.
- Broken by hand, each went red: backend wiring removed; plain text
  accepted as a suggestion; the general save not keeping the setting;
  the Routing story's kind check.
- Playwright codex-predictions.test.cjs: chromium + webkit, 1100 and 420
  wide, en/zh/zh-TW/ja/de (20 pass). routing-kind (with the new kind),
  codex-descriptions, codex-titles, i18n-keys, gateway-mode,
  purpose-filter, routing-purpose-state, settings-general,
  settings-sections, settings-search: pass.
- gofmt -l clean; go vet darwin, linux -tags nogui, windows.

Not tried: the real ChatGPT.app's predictions against magpie (the
feature is gated server-side by /wham/predictions/config and isn't on for
the owner's account); the reply shape is from the app's bundle.
2026-10-13 17:23:00 +08:00
yetone 05edac2c36 daemon: the service's PATH has the Node a terminal gets, nvm's default among them (bookyue on Discord)
What changed: `magpie daemon install` now widens PATH before writing it
into the systemd unit or launch agent, the way the app does when opened
from the Dock (proc.UserPath): the version managers' and npm's folders
that exist, nvm's default Node (not its newest), then the login shell's
own PATH (proc.LoginPath), each after the folders the install's shell
already had. When no node is found even then, the install says so.

Why: the service has only the PATH written into it. With nvm loaded
lazily, or an install run over ssh without a login shell, that PATH had
no node, and plugins (and the MCP servers and agent CLIs they start)
couldn't find it under systemd (bookyue, #feedback 838099).

Run: gofmt -l; go vet darwin, linux -tags nogui, windows (daemon, cli);
go test ./internal/daemon ./internal/cli -count=1 on macOS; the daemon
test binary for linux/arm64 in debian:bookworm-slim (all pass).
TestInstallFindsNvmNode uses the real widening with a sandbox HOME
holding nvm v20 (default) and v22: the unit's PATH has v20's bin, not
v22's, after the shell's own. With the widenPath() call removed by hand
it fails (PATH is the shell's alone, Node() empty).

Not run: a real systemd install with nvm since this change (the earlier
container run, before it, covered install/restart/linger); not tried
with fnm or volta, which UserPath handles the same way for the app.
2026-10-13 17:15:51 +08:00
yetone cdb7b5ff7e sessions: a PI-Desktop chat goes by the title PI-Desktop gave it, not its id (#1967)
PI-Desktop (vastsa/PI-Desktop) sends its chats through magpie with
X-Magpie-Session set to its own session id. Those are gateway sessions
with no file magpie reads, so Sessions and the context page listed them
by id. PI-Desktop keeps the name only in its index database, pi.sqlite's
sessions table (id, title, deleted_at).

PIDesktopTitles reads that table from $PI_DESKTOP_DATA_DIR or
~/.pi-desktop. It opens the database only through openCursorStore:
immutable when there is no write-ahead log, or from a temp copy when
there is one (a running PI-Desktop keeps one). It is re-read when the
database or its log changes, at most once a second. Deleted and untitled
rows are skipped. A database that can't be read leaves the names last
read standing. MergeExternal, MergeExternalStats and the GUI's context
page use it for sessions attributed to pi-desktop (aec6908c6) or pi,
which PI-Desktop was counted as before.

Run:
- TestPIDesktopTitlesNameGatewaySessions builds pi.sqlite with
  PI-Desktop's schema in WAL mode with checkpoints off. It checks that
  pi and pi-desktop sessions get the title, a claude session with the
  same id doesn't, deleted and untitled rows don't, a rename shows up on
  the next read, and the folder's files are unchanged.
- Broken by hand: isPIDesktop returning false made it red (titles
  stayed the id), and so did dropping `deleted_at IS NULL` (the deleted
  row got its title).
- go test -tags nogui ./internal/sessions/ ./internal/gui/ passes.
- gofmt -l is clean. go vet passes on darwin, linux (nogui) and windows.

Not tried: a real PI-Desktop install. The schema is from its source. A
data folder the user picked in PI-Desktop's own settings, other than
$PI_DESKTOP_DATA_DIR, isn't followed.
2026-10-13 17:10:25 +08:00
yetone 5617281f55 cli: magpie daemon install|uninstall|start|stop|restart|status keeps the gateway running as a service (HuanCheng on Discord)
What changed: a new internal/daemon package and `magpie daemon`, which run
`magpie serve` as the user's own service, with no window and no desktop
session.
- Linux: a systemd user unit at ~/.config/systemd/user/magpie.service
  (Restart=on-failure), driven by systemctl --user. status reads
  `systemctl --user show`, and says `sudo loginctl enable-linger $USER`
  when the user doesn't linger. su/sudo without the user's bus, no
  systemd, and WSL without systemd each get an error that says what to
  do.
- macOS: a launch agent, com.yetone.magpie.serve (RunAtLoad, KeepAlive on
  failure), loaded with launchctl bootstrap gui/$UID. Its log is
  ~/Library/Logs/magpie/serve.log.
- Windows and Android: refused, pointing to `magpie autostart on` (or to
  WSL).
- The service carries PATH, the proxy variables, MAGPIE_*, the XDG folders
  and the agents' folder variables from the install shell. The file is
  0600 because a proxy can hold a password. It runs magpie by its PATH
  name when that is the same file, so Homebrew's link survives updates.
  It refuses a go-build binary and an AppTranslocation copy.
- Install is refused while `magpie autostart` is on: the tray app serves
  the gateway too, and the two would crash-loop on the port.
- Docs: a reference.md section, and one sentence on the site's start page
  (en, zh, ja).

Why: users on headless Linux boxes asked for a supported way to keep
`magpie serve` up across reboots instead of hand-written units. The
existing `magpie autostart` needs a desktop session (an XDG autostart
entry).

What was run:
- gofmt -l; go vet on darwin, GOOS=linux -tags nogui, and GOOS=windows.
- go test ./internal/daemon ./internal/cli on macOS, at origin/main
  5b9530b56.
- The daemon tests cross-built for linux/arm64 and run in a Debian
  container.
- The tests use fake systemctl, launchctl and loginctl on PATH in a test
  home.
- Each guarantee was broken by hand and its test went red: the % escape,
  the autostart refusal, the 0600 chmod, the bootout before re-bootstrap,
  the go-build refusal, the bus advice, the last-exit filter and the
  PATH link.
- Real use on Linux: a Debian bookworm container running systemd as PID 1,
  with the linux/arm64 build, as an unprivileged user.
  - install: the gateway answered on :3425, and the unit was 0600.
  - kill -9: systemd restarted it 5s later.
  - Container restart with linger on: it came back by itself.
  - restart, stop, start and uninstall worked, and the unit and its wants
    link were gone afterwards.
  - Under sudo without XDG_RUNTIME_DIR it printed the bus advice.
- macOS: the darwin build ran `magpie daemon install` under a sandbox HOME
  with a fake launchctl. plutil -lint passed on the plist, and the calls
  were print and then bootstrap.

What wasn't: no real launch agent was loaded on a Mac (deliberately: never
on this machine), so launchd's own acceptance of the plist is checked
only by plutil. The linger advice was checked by the unit test, not seen
from a real SSH login. Windows was not run beyond vet.
2026-10-13 17:05:59 +08:00
yetone 5b9530b567 agent: Claude Code's model notes name the Codex account magpie goes to first, not the one Codex is signed in to (#1957, parkavenue9639)
With the signed-in ChatGPT account paused for the others ("this
account off, the others on"), the gateway sends codex/<model> to the
first account still on, yet Claude Code's /model list still said
"<signed-in user> · via magpie". The note now names the account that
comes first in the gateway's order: provider.FirstLogin gives
inUseLogin without the allowance-room check (the note is written once,
not per request), so a kept "keep signed in to X" still names the
account at its place, and a paused own account is passed over.

Not changed: magpie still writes openai_base_url for Codex failover
when several accounts are on. That is the failover itself; the
"Only switch Codex's sign-in" tick (#1907, v0.1.1224) already keeps
magpie out of Codex's config for those who don't want it.

Run: TestViaMagpieNamesTheAccountFirstInOrder (new) fails with the
note reverted to a.User and passes with the fix;
TestCodexPausedOwnAccountPassedOver and TestKeptLoginStandsAtItsPlace
also check FirstLogin against the account the gateway served. Full
internal/agent tests, gateway/provider login tests, gofmt -l, go vet
for darwin/linux/windows (-tags nogui).
Not tried: a real Claude Code /model list with two real ChatGPT seats.
2026-10-13 17:02:05 +08:00
yetone 0c2dad1e12 provider: a Codex approval's auto-review is served by an account kept to some models, not refused as every account barred (#1959, parkavenue9639)
With Codex's own model calls going through magpie's account failover
(another ChatGPT account on), Codex's auto-review of an approval
(x-openai-subagent: guardian, model codex-auto-review) became
codex/codex-auto-review and went through perKey. An account with its own
list of models ("only serve these", #474) was struck from it, because
the list is picked from the provider's models and codex-auto-review is
hidden from those (#1460), so no list could hold it. With the signed-in
account paused, every approval got 403 "every account barred". Relayed
as it came (no failover) the same call was a 200.

AccountServes now lets a Codex account serve codex-auto-review whatever
its list says (codexOwnHidden), as freeOnChatGPT already passes it by the
usage windows. A gateway key's own model list (access.Key.Models) is not
changed: that is a restriction the user set on a key they hand out.

Test: TestCodexReviewPassesAnAccountsModelList reproduces the report:
me@ signed in and paused, spare@ on with a list of gpt-6.1-sol and
gpt-5.6-luna, a guardian call on codex-auto-review through Codex's
endpoint. It goes to acct-2 as codex-auto-review; a model the list leaves
out is still 403 and one it names still served. With the
codexOwnHidden check taken out it fails with the reporter's 403
("is set not to be served by any account or key of Codex").

Run: go test -tags nogui ./internal/provider ./internal/gateway (ok),
gofmt -l, go vet for darwin, linux (-tags nogui) and windows.
Not tried: a real ChatGPT account's approval through the failover.
2026-10-13 17:02:05 +08:00
yetone aef0327b61 gateway, provider: comments no longer say magpie spends Claude's usage resets (#1972)
AutoReset and ResetOutcome still named Claude's resets, which 9bf6d4352
took out on purpose (reading or spending one means magpie calling
Anthropic with the account's token). #1972 read them as a place left
for the feature. Comments only; no code changes.

Run: gofmt, go build -tags nogui ./internal/gateway ./internal/provider.
2026-10-13 17:01:26 +08:00
yetone aec6908c6d agent: PI-Desktop's requests, sent as pi-desktop/<ver>, are its own and no longer Pi's (#1966, dgmico)
PI-Desktop (vastsa/PI-Desktop) runs Pi's own library, so by default it
sends pi's User-Agent ("pi (darwin …)") and is counted as Pi. Its provider
settings take a custom User-Agent ("pi-desktop/0.0.0" in its own tests),
but that name started with Pi's "pi-" prefix, so it was still Pi.

agents.go's others gains PI-Desktop (id pi-desktop, UA "pi-desktop", Pi's
icon). AgentOf matches it by its exact name first and by the longer
prefix, so pi-desktop/<ver> and the key magpie-pi-desktop are PI-Desktop,
while "pi (…)" and other "pi-" clients stay Pi.

Run: TestPIDesktopIsNotPi (red without the agents.go entry: pi-desktop/0.1.0
went to pi), go test -tags nogui ./internal/agent ./internal/usage, gofmt,
vet darwin/linux(nogui)/windows. A sandbox gateway (temp HOME, port 3561)
given a /v1/chat/completions request with User-Agent pi-desktop/0.1.0
recorded agent "pi-desktop" in usage.jsonl.
Not tried: the real PI-Desktop app; with its default User-Agent it still
reads as Pi, which nothing in the request can tell apart.
2026-10-13 16:57:58 +08:00
yetone 7d6358ff6b gateway: /v1/models can list each model by its bare id too, for apps moved from another proxy (love1sbug on X)
love1sbug moved from CLIProxyAPI: their clients ask for gpt-5.6-sol, and
magpie's /v1/models gave only codex/gpt-5.6-sol. "Provider in model names"
(36ca5432d, 6fa3109ea, 250bdd5c4) changes labels in agents' lists, never
ids, so no setting changed what the list returned. A bare request already
routed (serve: GroupFor, then Resolve); only the list didn't offer it.

What changed
- settings.BareModelIDs, off by default; Settings › Network and sharing ›
  "Model ids without the provider" (en, zh, zh-TW, ja, de), posted on its
  own to POST /api/settings/bare-ids (the general settings save keeps it).
  Drawn in gateway mode too, where such apps are.
- On, /v1/models (and ?format=text) lists every row it listed before,
  unchanged and first, then one row per bare model id
  (provider.BareEntries): the row of the entry that id reaches, its label
  that one's. GET /v1/models/{id} answers a bare id the same way.
- Which entry is decided by the gateway's own resolution (groupForIn, the
  GroupFor loop now shared; then resolveIn), so the list never offers what
  a request wouldn't reach: a model several providers serve is listed once
  and goes to its found group (found groups on) or the first provider in
  the Providers order (off), exactly as a bare request did before. An id
  already a catalog id isn't listed twice.
- The target must be in the shown list, so a gateway key held to some
  models sees only bare ids that reach them. Never listed for another
  magpie (DrawersHeader), whose remote provider would list each twice, nor
  in Claude Desktop's list.
- No agent file changes: magpie still writes provider/model ids, so the
  switch rewrites nothing and nobody who hasn't turned it on sees a change.
- docs/subsystems/gateway-routing.md: a section and verification lines.

What was run
- go test -tags nogui ./internal/gateway -run TestBareModelIDs: the
  reporter's case (a Codex provider with gpt-5.6-sol listed as
  gpt-5.6-sol, then asked for it on chat, responses and messages against a
  fake ChatGPT backend that saw gpt-5.6-sol; off, the list is byte-equal
  to before) and several providers with found groups on and off, a held
  key, another magpie. Both go red with the listing disabled by hand.
- go test -tags nogui ./internal/gui -run 'TestBareModelIDsSetting|TestSettingsSave'.
- node --test internal/gui/tests/bare-ids.test.cjs (playwright 1.62.0):
  Chromium and WebKit, 420px (gateway mode) and 900px, all five languages,
  20/20; i18n-keys.test.cjs passes.
- gofmt -l clean; go vet ./... (darwin), go vet -tags nogui ./... on
  darwin, GOOS=linux, GOOS=windows clean.
- go test -tags nogui ./internal/provider ./internal/gateway ./internal/gui
  ./internal/settings ./internal/cli ./internal/agent -timeout 40m,
  rebased on origin/main 06ff45fed: all six ok (gateway 533s, agent 460s,
  the machine at load ~130; the default 10m ran out on wall time in an
  earlier run, the test then running 1s in, nothing failed). Before the
  rebase agent's TestFolderVarsAreListed was red on REASONIX_STATE_HOME,
  fixed upstream by 24146c031.
- After the rebase (a conflict with #1914's tiers for every client, kept;
  a bare row carries its source row's tiers): gofmt, vet on all three, and
  bare-ids, i18n-keys, plain-names, gateway-port .test.cjs, 31/31.
- Rebased again on 9b52fb504 (side efforts touched settings, api.go,
  app.js, i18n.js; a doc table conflict, upstream's rows kept): gofmt, go
  vet ./... and -tags nogui on linux and windows, go test ./internal/gui
  ./internal/settings, gateway -run 'TestBareModelIDs|TestModels|
  TestCodexTiers|TestSideEffort', and bare-ids, i18n-keys, side-effort
  .test.cjs 31/31.

Not tried: a real CLIProxyAPI client against a live gateway, or the
reporter's own setup; no CLI command for the switch (Settings only).
2026-10-13 16:55:27 +08:00
yetone 9b52fb504a gateway: Codex's web search on magpie's models answers, no longer 404 (anton on Discord)
anton on Discord (Linux): asked to look something up, Codex called its
web.run tool, which posts to <base_url>/alpha/search, here
http://127.0.0.1:3425/v1/alpha/search. magpie had no such route and
answered 404, and Codex takes any failed web.run as fatal, so the turn
ended.

Why Codex sends it: since 0.143 (#29909) Codex offers web.run to a
provider that sends x-openai-actor-authorization, as magpie's provider
table does, on a model whose catalog entry says use_responses_lite, as a
ChatGPT account's models do in magpie (codexcat copies Codex's own
entry). The request is codex-api's SearchRequest (id, model, input,
commands.search_query/open/click/find..., settings, max_output_tokens)
and the reply is {encrypted_output, output, results}, output being what
the model is shown.

What changed:
- POST /v1/alpha/search and /alpha/search are served (codex_search.go).
- A ChatGPT account's model goes to the ChatGPT backend's
  /backend-api/codex/alpha/search, as the official client sends it: on
  the account's sign-in (codexSign, no SSE Accept), the model bare, the
  body otherwise as it came (through redaction), only Codex's own
  x-openai-*/x-codex-* headers kept (codexHeader: never magpie's token or
  the actor header). Its own paused sign-in is passed over, the key's
  account and model holds kept, and the next account is asked on a
  non-2xx; the backend's answer is relayed as it is.
- Any other model's search_query/image_query (domains as site:) is
  searched by webSearch, as magpie searches for a model that can't. When
  nothing answers, or only open/click/find were asked, the reason goes
  back as a 200 with output, which the model reads, instead of a failure
  that ends the turn. A ChatGPT search that fails on every account falls
  back to the same, saying why.
- On the Codex backend path a magpie model's /alpha/search is served
  the same, never relayed on Codex's own sign-in; one of Codex's own
  models goes through magpie's accounts when its turns would
  (codexAccounts), else is relayed as before.
- docs/subsystems/gateway-routing.md names the route.

What was run (worktree on origin/main, sandbox HOME, private GOCACHE):
- New tests from Codex's own wire fixture (codex-api endpoint/search.rs):
  TestCodexWebRunSearchesOnChatGPTAccount (both paths; acct-1 429 ->
  acct-2, bare model, body kept, no magpie token/actor header, turn
  metadata kept), TestCodexWebRunChatGPTFailsSearchedByMagpie,
  TestCodexWebRunOnOtherModelSearchedByMagpie (no searcher hint, search
  API asked "OpenAI news site:openai.com", open-only, bad JSON 400, and
  a stub ChatGPT backend that fails the test if reached).
- Broken by hand three ways, each red: without the /v1 route (404 as
  anton saw), without the codexBackend case (relayed to the backend on
  Codex's sign-in), without the ChatGPT forward (searched by magpie).
- go test ./internal/gateway/ -timeout 30m, gofmt -l, go vet darwin,
  GOOS=linux go vet -tags nogui, GOOS=windows go vet.

Not tried: the real codex binary against a sandbox magpie, nor a real
ChatGPT account's /alpha/search; the shape is from Codex's source and
its own test fixture.
2026-10-13 16:49:29 +08:00
yetone 776c255f56 library: a market skill kept only in a repository's .claude/skills installs (#1964, UFO404)
The market lists ui-ux-pro-max from nextlevelbuilder/ui-ux-pro-max-skill,
whose SKILL.md is only at .claude/skills/ui-ux-pro-max. candidates()
skipped every hidden folder, so the install said "has no skill
ui-ux-pro-max any more".

candidates() now looks into a hidden folder only for its skills folder
(.claude/skills, .agents/skills, .codex/skills ...), the same agent
folders the skills CLI behind skills.sh reads. A skill found there that
the repository also has outside hidden folders (that repo keeps brand,
design, slides... in both .claude/skills and cli/assets/skills) is listed
once, as the one outside, as the skills CLI does by name. skillDirsIn,
which the new-skills check reads from GitHub's tree, follows the same
rule, so the two paths agree. A hidden folder that isn't an agent's
skills folder (skills/.hidden, .claude-plugin/x) is still skipped.

TestSkillsFromATooBigRepository (#1941) expected hindsight's own
.claude/skills/ship-it to be left out; it is listed now, as the skills
CLI lists it.

Run:
- TestMarketInstallsASkillKeptInClaudesFolder, with the repository's
  real paths. On the old code it fails with "has no skill ui-ux-pro-max
  any more". Turning off the de-duplication and the skills-folder rule by
  hand each turns it red.
- A throwaway test (not committed) installing ui-ux-pro-max from the
  real GitHub repository in a sandbox HOME: installed, candidates are the
  six cli/assets skills plus .claude/skills/ui-ux-pro-max.
- go test ./internal/library (nogui), gofmt -l, go vet for darwin, linux
  and windows.
Not tried: the GUI Market page itself.
2026-10-13 16:49:07 +08:00
yetone dc2f0da820 gateway, gui: Image recognition and Web search pick how hard their model thinks (MOMO on Discord)
MOMO asked on Discord, "外置模型能不能提供思考深度选项": the model that
describes images (Image recognition, analyze_image) and the searcher's
model (e.g. Antigravity's Gemini 3 Flash) had no reasoning level of
their own to pick.

Settings › Models now has a chip beside each of those two pickers. It
opens the app's menu (openProtoMenu, no native select) and offers
Default plus only the levels that model has (Efforts, weakest first;
none shown when the model's levels aren't known, or the row is Off).
The pick is saved as settings.visionEffort / searcherEffort, one of
catalog.EffortRank or empty, and is checked on save. prefsKeep carries
both, so saving another setting keeps them.

Default keeps what magpie did before. Image recognition is still asked
at the least level the model has (classifyEffort), and the searcher
still gets no level. A picked level is fitted to the model's levels at
call time (fitEffort), and only these two calls carry it
(side_effort.go):
- askVisionWith sends reasoning_effort. The image cache key includes
  the level, so changing the level reads the image again.
- searchBody puts thinking (disabled for none, else enabled with
  budgetOf's budget) and output_config.effort (except for pre-adaptive
  Claude) on the searcher's Anthropic body. The gateway's translation
  turns that into each vendor's own form: adaptive or between_tools
  for new Claude, reasoning.effort for Responses, and thinkingLevel
  for Gemini 3 on Code Assist / Antigravity.
- A picked level raises max_tokens by its budget (replyRoom), so the
  thinking doesn't eat the reply.
- ownSearch and Kimi's search service are sent no level. A fallback
  searcher is sent the level fitted to its own model.

docs/subsystems/gateway-routing.md: new "How hard a side model thinks".

Tests:
- TestVisionEffortPicked and TestVisionEffortOnAnthropic check the
  vision body.
- TestSearcherEffortPicked checks the searcher body on new Claude, old
  Claude and Responses.
- TestSearcherEffortOnGemini checks the searcher body through
  buildCodeAssist for antigravity.
- TestSideEffortChecked covers settings validation.
- side-effort.test.cjs covers the chips: levels shown, a pick saved,
  Default clears it, toggle and Escape, no scroll, fit in the row and
  the menu inside the window. It runs in Chromium and WebKit at 1100
  and 420, in en/zh/zh-TW/ja/de.

Run:
- go test -tags nogui ./internal/gateway/ (full, -timeout 30m) on
  origin/main 3a9d73c5c + this change: everything passes except
  TestRateLimitIsWaitedOut "an hour away" (1.9s against its 1s bound,
  load ~190). That test passes on freshly fetched origin/main 41972b25f
  alone (-count=10) and in 8 parallel -cpu 1 copies. Filed as #1971.
- go test -tags nogui ./internal/settings/ ./internal/gui/: ok.
- Broken by hand, each goes red:
  - searchBody dropping the effort fails TestSearcherEffortPicked and
    TestSearcherEffortOnGemini;
  - askVisionWith back to classifyEffort fails TestVisionEffortPicked
    and TestVisionEffortOnAnthropic;
  - the settings check removed fails TestSideEffortChecked;
  - prefsKeep without the two fields fails side-effort.test.cjs.
- GUI:
  - side-effort.test.cjs: 10/10.
  - searcher-pick, images-*, vision-mcp, settings-search/sections/
    general, routing-vision-why and i18n-keys: 123/123.
  - 67 more Settings files: 778 pass. text-size "zh, dark ... 150%"
    failed in WebKit under parallel load; it passes 11/11 alone and is
    #1866.
- gofmt -l is clean. go vet passes for darwin, plus GOOS=linux and
  GOOS=windows with -tags nogui, on gateway, settings and gui. go build
  passes.
- Not tried against a real Antigravity or other real account: the
  request shapes are checked against fakes and the gateway's own
  translators.
2026-10-13 16:40:24 +08:00
yetone 23611ca6a5 provider: a moved ZCode subscription takes plugin 0.1.17, which reads ZCode's sign-in from the folder its data was moved to
What changed: the zcode mover's min goes from 0.1.16 to 0.1.17, so
keepMovedCurrent updates every moved user's @magpie-community/opencode-zcode-auth.
41972b25f made the built-in follow ZCode 3.14's 数据存储路径 (dataBaseDir in the
home folder's .zcode/v2/setting.json); the plugin, which is what runs for a
moved ZCode subscription, still read ~/.zcode/v2/credentials.json and
runtime/provider only, so "ZCode app's sign-in" read the stale copy ZCode
left at home. plugins 65a7676 (0.1.17) reads dataBaseDir as ZCodeDataIn does
(trimmed, ignored when empty or not absolute) for credentials.json and the
zcode-builtin.json walk, and keeps reading setting.json from the home folder,
where ZCode keeps it (getSettingsFile; copyDataDirectory leaves it out).

ZCode's CLI session database (~/.zcode/cli/db/db.sqlite, internal/sessions)
does not move with dataBaseDir: the CLI (glm/zcode.cjs, 3.14.3) takes it
from storage.sessionDbPath, default "~/.zcode/cli/db/db.sqlite" expanded
with os.homedir(), and the host sets neither ZCODE_SESSION_DB_PATH nor
ZCODE_STORAGE_DIR; copyDataDirectory copies .zcode/v2 only. So the session
reader is unchanged.

What was run:
- npm view @magpie-community/opencode-zcode-auth@0.1.17: published (publish
  run 38370080577; that run is red only for zed-auth and zen-free-auth,
  E404 Trusted Publisher).
- Plugin: HOME=$(mktemp -d) bun test at the repo root, 1185 pass; its new
  moved.test.mjs fails with the old path.
- gofmt -l; go vet ./internal/provider (darwin), GOOS=linux and
  GOOS=windows go vet -tags nogui; go test -tags nogui ./internal/provider
  under a sandbox HOME: ok.
- Not run: a real ZCode with a moved folder, Windows.
2026-10-13 16:40:14 +08:00
yetone 06ff45fed5 gui: a request's row on Routing keeps the model that answered readable beside its metrics, and the accounts column gives up its spare room (#1926, hibaliqya-yonma)
What changed:
- The request list's columns were time, asked, to (minmax(0, 1fr)) and
  the metrics (auto). Rows share their columns (subgrid), so the metrics
  column took the widest row's whole line for every row, and "to" got
  what was left. Now "to" keeps at least 14em (30% of a narrower list)
  and the metrics take at most 40%, wrapping inside it (they already
  wrap); asked is held to 32% (was 36%). The no-subgrid fallback gets
  the same columns.
- "to" said "<account> · <model>" in one box that gave way before the
  reasoning level, so it read "· hi…". It is now two boxes: the account
  gives way first (down to 2.5em), the model stays whole when it fits,
  and the said box keeps at least 9em before the level is cut. The
  text is the same, so tests and titles that read it see no change.
- Side by side (1150px and wider), the accounts column is clamp(260px,
  28%, 360px), was clamp(280px, 32%, 400px): in a page kept to 1200px
  (61a0a69b) it gave the requests ~47px more.

Why: since 61a0a69b kept Routing to 1200px, the requests' column beside
the accounts is ~800px, just over the 760 where rows stack, so each row
stayed on one line and the model that answered was squeezed to nothing
while the metrics kept their width. Reproduced with the reporter's
shape of row in Chromium and WebKit: at 1920 the served model's box was
0px of 226.

Run:
- new routing-request-model.test.cjs: chromium and webkit, en zh zh-TW
  ja de, at 1920, 1320, 1240, 1100, 900 and 420: the model whole beside
  its account (its text's own unrounded width: WebKit cut a box a
  fraction narrower than its text, with an ellipsis scrollWidth doesn't
  show), no metric clipped or outside its row, no overlap, no sideways
  scroll. 10/10. Red with the old grid ("the model that answered is 0px
  of 30"), red without the split ("the model is cut (123px of 226)"),
  and red in WebKit with the model's box allowed to shrink.
- routing-columns.test.cjs: the accounts column's bound is now 260..360.
- routing-*.test.cjs (69 files), page-width and click-scroll, both
  engines, at load ~150: 835 passed, 1 failed. The one,
  routing-upstream's chromium en, passed 4/4 when run again. Two files,
  routing-group-fold and routing-mode-goes, ran out of the 240s per-file
  limit and passed 40/40 each when run again. After rebasing onto
  97751188e: routing-request-model 10/10, group-classifier-failed 20/20,
  routing-columns 4/4, routing-request-metrics 4/4, routing-upstream 4/4,
  routing-mode-goes 40/40, i18n-keys 1/1.
- Go, on this series at 04ff9a775: go test -tags nogui for usage,
  provider, cli and gateway (-timeout 45m), and go test ./internal/gui/,
  all ok. gofmt -l is clean. go vet passes on darwin and with -tags nogui
  on linux and windows. After rebasing onto 97751188e, the vets, usage,
  cli and gui were run again, all ok. Rebased again onto 15105161e, with
  the same results: gofmt is clean, all three vets pass, go test for
  usage, provider, cli, gateway and gui is ok, and routing-request-model
  10/10, group-classifier-failed 20/20, routing-columns 4/4 and i18n-keys
  1/1 pass. Rebased onto 54ba9042d (main had touched i18n.js,
  routing.js and the gateway): gofmt and all three vets are clean; go
  test passes for usage, for gateway and provider with -run
  Classif|Intent|Decide|MLX, and for gui; routing-request-model,
  group-classifier-failed, routing-columns, routing-request-metrics,
  routing-save-keeps-the-row and i18n-keys pass.
- Screenshots before and after at 1920/1320/1100/420 in both engines.

Not verified: a real WebView2 window on Windows; Chromium stands in for
it here.
2026-10-13 16:39:29 +08:00
yetone 08b1a60c03 gateway, gui: a routing group whose classifier fails says so on its card, and the log says why (#1929, versun)
What changed: the gateway keeps, per classifier model, why it couldn't
say the last time it was asked (an error from the request, or an answer
that was no number of the list) and when, until it answers again
(gateway.ClassifierFailure). The first failure, and each one that says
something new, is written to the log once ("routing: the classifier X
couldn't say: ..."). /api/groups sends it as a group's classifierFailed,
and the group's card on Routing shows a line "Classifier failed 3 min
ago: <why>" with an amber dot (no stripe); its title says that until the
classifier answers, no rule with an intent matches and turns reason as
the agent asked. Strings in en, zh, zh-TW, ja and de.

Why: versun's MLX-Serve answered its Clef decision model, asked as a
chat model, with a 400. The only place that said so was each request's
own details; the group's rules with an intent quietly never matched,
which read as the routing working. The preset itself is fixed in the
commit before this one (versun's, cherry-picked).

Run:
- go test: TestClassifierFailureIsKept (gateway: a 400, kept while
  resting, "not a number", cleared by an answer) and
  TestGroupsSayAClassifierThatFailed (gui: only the failing group's JSON
  has classifierFailed). Each went red with its line removed by hand
  (the record in classify(), the fill in groupsState).
- group-classifier-failed.test.cjs: chromium and webkit, en zh zh-TW ja
  de, at 1100 and 420: 20/20; with classifierFailed dropped from the
  fixture's reading in groupRow, 10/10 of one engine red. i18n-keys
  passes.
- go test -tags nogui ./internal/provider ./internal/usage ./internal/cli:
  ok. ./internal/gateway hit the 10m default timeout at load ~150-190
  (other sessions); rerun with a longer timeout before the push, below.
- go test ./internal/gui: TestDockJoinLeadsCommandTab (Command-Tab order
  had kitty in front) and TestMainWindowCorners (measuring killed under
  load) failed; both are desktop-window tests this change doesn't touch.

Not verified: a real MLX-Serve; versun ran his own.
2026-10-13 16:34:59 +08:00
Versun b2b015c584 provider: MLX-Serve's decision models classify routing groups through System One, separated from chat models by capabilities
MLX-Serve (github.com/ddalcu/mlx-serve) serves decision models (Clef,
Clef-Flash, Kev, Laya, D1) at POST /v1/systemone (and /v1/decisions). Its
/v1/models lists them alongside chat models, marking them with
capabilities: ["decisions"]. Setting a routing group classifier to an
mlx-serve decision model previously failed because the preset had no
decision endpoint and magpie offered it as a chat model, which MLX-Serve
rejected with 400.

- The mlx-serve preset has a decision base, http://localhost:11234/v1.
  An existing MLX-Serve provider saved without decide gets its chat base as
  one, at whatever port it was given (as oMLX does).
- mlxServeDecides joins listsDecisions. fetchDecide reads /v1/models and
  keeps models with the "decisions" capability under <id>.decisions, with
  the model's context window and input modalities.
- DecidesModel takes them out of the agents' chat lists and offers them as
  deciders. Jev() is the first of them. A server with no decision model
  lists none, and no Jev alias is made up for it.
- Provider test on a decision model asks System One rather than chat.

Run:
- TestMlxServeDecisionModels: fake MLX-Serve answers with real captured
  fields. Clef-Flash with capabilities: ["decisions"] is a decider, chat
  models reach agents, and RouteDecider plus AskSystemOne post to
  /v1/systemone. TestModels tests clef-flash-4bit via decide. Red without
  mlxServeDecides in listsDecisions.
- TestListedMLXServeDecideTable: real captured response, vision modalities,
  `models` field fallback with omitted input_modalities, chat-only server,
  empty list, and invalid JSON.
- TestMLXServeWithoutDecisionModels: no decision model means none, not Jev.
- Real MLX-Serve on localhost:11234 in sandbox HOME with isolated config:
  provider add mlx-serve, provider refresh, provider test mlx-serve
  clef-flash-4bit (543 ms, decide OK), group add with classifier.
- go test -tags nogui ./internal/provider/..., gofmt -l, GOOS=linux and
  GOOS=windows go vet, cross-OS builds.
2026-10-13 16:34:59 +08:00
yetone 5e30d58fe4 usage: a request's row says the upstream's own stop reason on the Requests page, in /v1/magpie/usage/requests and in the CSV (#1927, Gluxggg)
What changed: the gateway has recorded why the upstream said each reply
ended (Record.Stop: a Responses reply's "completed", Chat's "stop" or
"tool_calls", Anthropic's "end_turn") since c5b57b907, and the Requests
page has a line for it ("Upstream stop reason"). But the page, and
/v1/magpie/usage/requests, read their rows from the packed row cache
(rowChunk), whose list of a row's strings (rowText) never had Stop: every
row came back with it empty, so the line never showed and the API row had
no "stop". rowText now carries it (packedRow.Text grows; the cache is in
memory only, so nothing on disk changes shape). The CSV export gets it
too, as a last column, upstream_stop, after 30869e35a's tier columns.

The same gap, a sibling: 30869e35a (#1784) added TierAsked, TierSent
and TierServed to Record, also without rowText, so the API's rows had
them empty too. They are in rowText now, and TestRowTextHoldsEveryString
sets every string of a Record (but Computer, the chunk's; Source, the
row's own; and the unlogged bodies), packs and unpacks the row, and
names any that came back empty, so the next field added can't be lost
the same way.

Why: #1927 asks whether a /v1/responses reply that ended in
response.completed with no tool call was the upstream's own end or one
magpie made up. In a Responses-to-Responses relay magpie writes no
terminal event of its own (a stream with none ends in response.failed,
#370), and the row's stop reason is the field that shows what the upstream
said; it was recorded in usage.jsonl and lost on the way to every reader.

Run: TestRequestPageKeepsUpstreamStop (the reporter's row, through
Append and QueryPage twice, cached; the packed chunk round trip; the CSV
column) fails with rowText put back ("the upstream's stop reason was
dropped from the page's row") and with the CSV cell left empty ("CSV"),
passes with the change. TestRowTextHoldsEveryString fails with
TierServed left out ("Record.TierServed comes back from the packed row
as \"\""). TestLedger* updated for the new column. go test
-tags nogui ./internal/usage/ ./internal/cli/ ok. gofmt, vets and the
gateway suite: in the series' last push record below.
2026-10-13 16:34:59 +08:00
yetone 54ba9042d1 gui tests: routing-save-keeps-the-row runs in every language and at 420px, and wheels to the group as a reader would (#1093)
The test ran in English and Chinese at one width, with Save's text
from a map of its own. It now runs in all five languages, at 1100 and
420px, takes Save's text from the page's t(), and wheels down to the
group before opening it. WebKit never scrolls to an element for a
click, since magpie scrolls only for the reader.

Run: chromium and webkit, 20/20. With routing.js's scroll back to the
row removed, 20/20 red.
2026-10-13 16:34:23 +08:00
wizzy-yang f9f1df2e1a provider, agent, gui: saving a routing group no longer waits on a Codex usage read, and the saved row comes back into view (#1093)
Saving a group ran agent.SyncCatalog, and Codex's Sync asked whether the
signed-in ChatGPT account is used up through LoginUsage, which reads the
vendor when its one-minute cache is stale and makes the caller wait
(922-1148ms in the reporter's 17 saves, 9-20ms on a cached read).
provider.CodexUsedUpKnown() answers from what was already read and never
asks; the sync uses it. KeepOnAnAccountWithRoom still reads it every
loginSwitchEvery and touches the catalog when the answer changes, so the
sync learns of it without asking itself.

The group editor stands in for the row, so on Save the page got shorter
and the browser clamped the view to the list's foot. routing.js now
brings the saved row back with readerScrolls + scrollIntoView, and only
when it is out of view, so a click hold isn't released for nothing.

Squashed from #1093 by wizzy-yang onto current main.
2026-10-13 16:34:23 +08:00
yetone c3dc7aefba provider, settings: an idle magpie no longer parses settings.json for every account of every model's price (xsw on Discord)
xsw reported v0.1.1222 sitting at ~15% CPU while idle, with no gateway
requests. Since 8c5b9f928 (#1535, v0.1.1176), provider.All asks
settings.AccountDiscoveryOff for each account provider, and that reads
settings.json through Load, which caches the bytes but runs json.Unmarshal
on every call. agent.magpieModels prices each model under one Hold, and
each price asks All. So one pricing pass parsed settings.json models ×
accounts times. That pass runs on the GUI's drift poll (every 15s) and on
KeepDshWired (every 30s), per agent.

Evidence: `sample` of the owner's live dev build (26% average over 11.5h,
6–10% while sampled) had its top stacks in settings.loadChecked →
encoding/json under provider.All ← EntryPriceIn ← magpieModels, reached
from the drift handler and keepDshWired. A sandbox serve with an empty
config sat at 0.0%. A throwaway bench (not committed) priced 300 models
with 2 accounts: 81ms and 639 parses before, 11.5ms and 40 parses after.

All now asks once per call, from the settings the held look has already
read (heldSettings), through the new settings.AccountDiscoveryOffIn.
settings.Parses counts parses for the test, and loadChecked's comment no
longer claims the file is "parsed once".

Test: TestAllReadsNoSettingsPerLookWhileHeld prices 200 looks under one
Hold with 2 signed-in accounts and fails at >= 200 parses. Putting back
the per-account call by hand: "settings.json parsed 840 times for 200
looks at 2 accounts". With the fix: ~40, all from the first provider
build. It also checks MAGPIE_NO_ACCOUNTS=1 still hides account providers.

Run: gofmt -l; go vet -tags nogui on darwin, GOOS=linux and GOOS=windows
for internal/settings, internal/provider, internal/agent; sandbox-HOME
go test -tags nogui of those three packages, before and after rebasing
on origin/main. Other short tickers were checked (plugin host stop,
sessions readSlot, gui glide, update/claude sign-in polls): all bounded,
none run while idle.

Not run: a reproduction on xsw's machine or OS (unknown yet), a Linux or
Windows runtime CPU check, the GUI suite (no assets touched). Accounts()
still parses settings ~40 times per provider build; that is once per held
second, left for later.
2026-10-13 16:34:15 +08:00
yetone a65f2131dd gateway: a provider's model can be marked a video or image model in its editor (#1399, shen-joe)
shen-joe's relay serves a video model (agnes-video-2.5-flash), but its
/models list doesn't say "kind": "video". magpie only took a base-URL
provider's video models from that field, and its image models from that
field or from the model's name. So the model could never be asked at
/videos. They asked to tag video models, either in Settings or when
adding the provider.

What changed:
- settings.ModelKinds holds "image" or "video" by "<provider>/<model>".
  RenamePerModel carries it along with the other Model* maps.
- provider/modelkind.go:
  - MarksKinds: only a provider with its own base URL can be marked. A
    subscription, another magpie and a decision API can't.
  - ModelKind, KindModels and SetModelKind. A model can be marked if the
    provider serves it, or if its fetched list has it (a video model is
    left out of the chat list).
  - SetModelPrefs takes a "kind" with the model's other prefs.
- gateway:
  - Drawers adds the models marked image and drops the ones marked video.
  - customVideomakers adds the models marked video and drops the ones
    marked image.
  - The 400 for a model that can't make videos now says where to mark it.
- GUI: the model chip's right-click menu gets "Makes: Auto/Image
  model/Video model…" (an app menu, not a native select). The pick is
  staged until Save, and a marked model shows a small image/video tag.
  Strings are in zh, zh-TW, ja and de.
- docs/subsystems/gateway-routing.md describes it.
- settings_keep_test sets ModelKinds, so a Settings-page save is checked
  to keep it (that guard test went red until it did).

Why per model, in the provider's editor: the kind belongs to one model
of one provider, like the per-model API pref already set there.
Settings → Image/Video only pick the default model. This also covers
their "tag it on the provider" alternative.

Not done: Agnes's own video API (polling at /agnesapi?video_id=, the
finished video in "url") isn't OpenAI's GET /videos/{id}. Marking the
model gets the request to its /videos, but the poll won't match until
there's a mode for it. I've asked the reporter for real responses.

Run:
- go test ./internal/provider ./internal/settings ./internal/gui
  ./internal/gateway: ok (gateway 1658s).
- TestCustomProviderVideoTheUserMarks, which goes red with the
  KindModels loop in video.go removed.
- GUI model-kind.test.cjs, 16/16 (en/zh/ja/de, 900/420, Chromium and
  WebKit). It goes red with the menu item removed.
- Sibling GUI tests: model-api-gemini, model-copy-id, model-api-preset,
  model-test-one/as/why, provider-detect-models, provider-typed,
  i18n-keys, gui-ja and gui-de.
- gofmt, plus linux and windows go vet -tags nogui.
- Not tried against Agnes's real API (no key).
2026-10-13 16:33:44 +08:00
yetone 1d74826b9e gui: a provider's models say whether it serves the vendor's list or only those picked, and the last pick unpicked serves none (#1831, kchen0x)
kchen0x found the model picking hard to follow: with none picked the
provider served every model (dashed), one picked served that one, and
that one unpicked served every model again, while Select none served
none and looked nearly the same as "none picked".

The editor now says which of two things the provider serves, with a
segmented control above the models: "Vendor's list" (up to 24 of it,
dashed, and models it lists later) or "Picked only" (the picks; none
while none are, its balance and usage still shown, saved as noModels).
A click on a model, Select all, Select none, Free only and Working only
are all Picked only, so unpicking the last pick leaves none instead of
flipping back to the vendor's list; only "Vendor's list" goes back to
it. The hint under the list names the mode. Not shown for a decision
API's provider, whose models no agent sees. Strings in zh, zh-TW, ja, de.

Run: provider-none-picked.test.cjs, now also at 420 wide and checking
the control, the last pick unpicked and both segments, passes 30/30 in
Chromium and WebKit in en, zh, zh-TW, ja, de at 1100 and 420; with the
unpick change taken out it fails ("glm-5.3-free after the last pick
unpicked"). i18n-keys passes. The 25 other GUI tests that touch the
model chips pass in both engines (model-first-pick and model-copy-id
failed in the first run, before the hint kept "Click a model to pick
just it", and pass 14/14 and 4/4 after it).
Screenshots looked at for zh 1100 and de 420.
2026-10-13 16:26:11 +08:00
yetone 4047d00d60 agent: Claude Code's /model names a subscription's provider beside its account when the model names are plain (#1136, cjyrainbow)
cjyrainbow could not tell in Claude Code's /model which provider a
subscription model came from: its row said the model and "account ·
via magpie". Since v0.1.1223 the label follows "Names in agents' lists"
as Codex's does, so with names On it is "GPT-5.5 · Codex". With names
Off, or a name the user gave the model, the label has no provider and
the note was still the account alone.

The note now puts the provider before the account in that case
("Codex · me@example.com · via magpie"), as an API key's note already
names its provider. With the provider in the label the note is
unchanged; routing groups are unchanged.

Run: TestClaudePickerSubscriptionSaysItsProvider (a Codex sign-in in a
sandbox home, On and Off) passes; on the old claude.go it fails with
the Off row "GPT-5.5" / "me@example.com · via magpie". The TestClaude*
tests pass. Real Claude Code 2.1.296 in a sandbox CLAUDE_CONFIG_DIR
showed a picker written this way with the label and the note as its
two columns (before the note change; not run again after). go test
./internal/agent ok (1180s, under heavy machine load). gofmt -l
clean; go vet, GOOS=linux and GOOS=windows go vet -tags nogui
./internal/agent ok.
2026-10-13 16:26:10 +08:00
yetone 9c922b9f77 provider: a subscription's place in the order holds on a computer where its plugin has the other id (#1940, Sun1090)
Sun1090 put two plugin subscriptions first on one computer; the other
computer, synced, kept them where they were. The order is synced (the
providers part of WebDAV sync carries providers.json's order) and no
sign-in reorders it. But a built-in subscription served by its plugin is
"workbuddy-plugin" where the built-in isn't moved onto it and
"workbuddy" where it is (PluginID), and whether it is moved lives in
migrations.json, which isn't synced. The order from one computer named
ids the other doesn't have, and ordered() put those providers last.

ordered() now ranks a provider whose own id the order doesn't name by
its counterpart (id <-> id-plugin), only for the built-in subscription
ids (accountIDs), so a custom provider ending in -plugin is only itself.
An id the order names itself still wins.

Run: TestOrderKeepsAPluginsPlaceByEitherID passes; with the lookup taken
out it fails ("not moved here: [zhipu deepseek workbuddy-plugin
workbuddy-ai-plugin]"). go test ./internal/provider ok; gofmt -l clean;
go vet and GOOS=linux / GOOS=windows go vet -tags nogui
./internal/provider ok. Not tried across two real computers; the
reporter's ids are asked on the issue.
2026-10-13 16:26:10 +08:00
yetone 38bd14dbfd library: a well-known kit brought in before v0.1.1223 groups as one source again (#1862, WardLu)
WardLu's Feishu skills (3) and Fish Audio skills (2) still showed as 3 and
2 groups on v0.1.1223, which grouped well-known kits by their base. The
lock now says the kit's base, but each skill's From was recorded when it
was brought in from ~/.agents/skills (ImportSkills), and back then that
was the skill's own sourceUrl, e.g.
"docs.fish.audio/.well-known/agent-skills/fish-audio-api/skill.md".
repoOf takes From before the lock, so the stale per-skill key won.

fromKey reads a From that carries /.well-known/ as the base before it,
so those skills group as the lock now says, without rewriting the
user's library.

Run: TestWellKnownKitFromBeforeGrouped, built from the reporter's five
lock entries with From set to the old form, passes; on the old
skill_from.go it fails with five per-skill groups. go test
./internal/library ok; gofmt -l clean; go vet (darwin) and GOOS=linux /
GOOS=windows go vet -tags nogui ./internal/library ok. Not tried in the
reporter's own GUI.
2026-10-13 16:26:10 +08:00
yetone 41972b25fc zcode: magpie's provider reaches a ZCode whose data was moved to another folder in its settings (flower on Discord)
What changed: ZCode 3.14 has a 数据存储路径 (data storage path) setting.
Changing it copies ~/.zcode/v2 to <folder>/.zcode/v2, and from the next
start ZCode reads its providers (provider_config.json, config.json),
credentials.json and runtime/provider from there. The choice stays in the
home folder's .zcode/v2/setting.json as dataBaseDir, which ZCode's main
process reads first (readBootstrapDataBaseDirFromDisk, then setDataBaseDir;
getDataBaseDir is that, else ZCODE_DATA_BASE_DIR, else HOME). magpie always
wrote ~/.zcode/v2, so for such a user it said ZCode was connected while
ZCode's 模型设置 showed only BigModel and Start Plan and no magpie.
appdir.ZCodeDataIn reads dataBaseDir the way ZCode does (trimmed, ignored
when empty or relative); the ZCode agent target, the ZCode subscription's
credentials.json and its zcode-builtin.json glob use it. Skills, AGENTS.md
and the CLI's cli/config.json stay under the home folder: ZCode reads
those from HOME/USERPROFILE (getUserZcodeSkillRoot, the MCP config path),
so internal/library is unchanged. ZCode's session database
(internal/sessions) is not changed here: where ZCode's CLI keeps it under a
moved folder was not checked.

Read from ZCode 3.14.3's app.asar (copied to the scratchpad):
out/main/index.js (bootstrap, setDataBaseDir, buildHostProcessEnv passing
ZCODE_DATA_BASE_DIR), out/host/chunk-*.js (getAppConfigDir =
<base>/.zcode/v2) and out/host/index.js (provider_config.json under it).
flower hasn't said they moved the folder; this is the one way found in
ZCode's code for "magpie says connected, ZCode has no magpie" with a
provider_config.json magpie wrote. That file, and the one this build
writes, decode with ZCode's own decodeProviderConfigFile (run from a copy
of glm/zcode.cjs): providers ["magpie"].

What was run:
- TestZCodeMovedDataFolder (new): with dataBaseDir set, Set("magpie")
  writes both files under the moved folder and none in ~/.zcode/v2; an
  empty, blank or relative dataBaseDir keeps ~/.zcode. On the old
  zcode.go it fails: "no magpie in the moved folder's
  provider_config.json".
- Sandbox, built binary: HOME=<sandbox>, setting.json dataBaseDir=<sandbox>/D,
  `magpie zcode magpie` wrote D/.zcode/v2/{config,provider_config}.json
  and nothing under the home folder's .zcode/v2 but setting.json.
- go test -tags nogui ./internal/agent ./internal/appdir ./internal/provider
  under a temp HOME; gofmt -l; GOOS=linux and GOOS=windows go vet -tags
  nogui on the three packages.
- Not run: the ZCode app itself with a moved folder (not launched against
  any config), and Windows.
2026-10-13 16:21:56 +08:00
yetone 440d26335f gui: Gateway says gateway keys come once Share on local network is on, for other computers and tunnels (DD on Discord)
DD (Discord #feedback, v0.1.1222) wanted a Cloudflare Tunnel that needs an
API key and found no gateway keys. They are on Gateway, and only once
Settings > Network and sharing > Share on local network is on. Nothing on
either page said so.

- Gateway: while not shared, a line under Connect says what gateway keys are
  for (other computers, and a tunnel to this one such as Cloudflare Tunnel)
  and that they come with sharing; its button opens Settings > Network and
  sharing. Shared, the line gives way to the keys.
- Settings: the Share row names tunnels beside other computers.
- zh, zh-TW, ja, de for both strings.

Checked first, against a sandbox v0.1.1222 with real cloudflared (quick
tunnel, --protocol http2): a request through the tunnel carries
Cf-Connecting-Ip/X-Forwarded-For, so lanGuard counts it as remote. Not
shared it gets 403; shared it needs an enabled gateway key. No gateway
change is needed. A plain TCP forward that adds no headers still reads as
local; that is #1655.

Tests:
- new gateway-keys-off.test.cjs: chromium + webkit x en/zh/zh-TW/ja/de x
  1100/420. With the line forced hidden by hand it fails.
- gateway-model-info, gateway-systemone: wheel the model rows into view
  (reach), since the line puts them past the window's foot in WebKit.
- sse-body: measures the view after wheeling to the option it clicks, not
  before; the extra wheel moved it 1px and read as the switch's move.
  Passes on the old assets and the new.
- every GUI test that opens Gateway or Network and sharing (34 files):
  328/328.
Not run: tunnels on Linux or Windows.
2026-10-13 16:21:39 +08:00
yetone feb21d7d21 gui: an update found before its notes reached the site takes them from the next check (#649, Sun1090)
Sun1090's v0.1.1224 update dialog showed no notes. The release has them now
(GitHub and the live /api/latest both return them). The site's worker has no
GITHUB_TOKEN, so when GitHub rate-limits it, it answers from the releases
feed. That feed can lag a new release by minutes, and its answer then has
the version but empty notes. The app downloaded that version, and every
later check found the same version and kept the empty notes.

Now, when a check finds the same version as the one downloaded and that
one has empty notes, the check's notes are taken, on a copy, because the
install may still be reading the one held. Notes that are already there
are never replaced.

Run:
- TestUpdateRecheckTakesNotesLate (new) passes. It went red with the fix
  turned off ("empty notes not taken from the recheck") and with the
  empty-notes guard removed ("held notes replaced").
- go test -tags nogui ./internal/gui after rebasing on origin/main.
- gofmt -l; go vet on darwin, GOOS=linux -tags nogui and GOOS=windows.

Not verified: what the worker answered at 07:23-07:29 on 10-13. No worker
logs were read.
2026-10-13 16:20:22 +08:00
yetone 3ccbe6bc15 plugins: a runtime for built-in plugins, and Plugins › Built-in to switch them (P0)
Lxxyx on X (https://x.com/Lxxyx_/status/2109506752656150974): magpie has
too much in it. This is P0 of making magpie's parts plugins, as DeepSeek
Harness does: a runtime, plugins.yml, and the first five built-in plugins
the user can switch off.

- internal/pluginrt: a registry (Register from init), a manifest (API
  caret range, Requires/Provides, Essential, InUse, Apply, Parts,
  Defaults) and Reconcile: the plugins no longer wanted, with whatever
  needs a service they provided, are disposed newest first; the wanted
  ones are applied once their services are there. A plugin that fails or
  panics is failed and the rest run. TestPluginsImportOnlyCore keeps the
  boundary: nothing outside plugins/ imports one, none imports another.
- plugins.yml (appdir.Config()): default → preset (essentials | all) →
  the user's rows → in use. A new install is written Essentials, a magpie
  that ran here before (settings.RanBefore) All, so existing users keep
  everything. Writes are locked, whole and keep a .bak; a file that
  doesn't parse is an error, never empty, and is never written over.
- plugins/groups, library, otel, sessions, warmups. In P0 a plugin off
  is the window's alone: its page, sections and rows (data-feature) leave
  the window; the gateway, TUI and CLI serve the same, nothing is
  deleted. One in use stays on.
- The window: Plugins › Built-in, the first tab, a switch per plugin;
  GET/POST /api/plugins/builtin; boot.js says which are off before the
  first paint. CLI: magpie plugin builtin [on|off <id>], plugin preset,
  plugin dump [--json].
- docs/subsystems/plugin-runtime.md, gui-shell.md.

Run: go test ./internal/pluginrt/ ./internal/settings/ ./internal/gui/;
gofmt -l; go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows
go vet ./.... GUI: builtins.test.cjs in Chromium and WebKit, 5 languages,
1100/800/420; list-sort, mobile-web, routing-keys-fold, routing-sessions
pass. By hand under a sandbox HOME: a new install gets essentials, an
existing one all, a broken plugins.yml is refused and kept, dump works.
Full suite results after the rebase are in the push notes.
2026-10-13 16:19:13 +08:00
yetone f2b0780fa2 gateway: a held rule fails over within the member it chose, and a fallback outside it isn't kept for the turn (#1946, XcodeFish)
A group of coding-fast and coding-quality, its rule sending turns to
coding-quality: when coding-quality's member failed mid-turn the request
went to coding-fast's members before coding-quality's other one, and the
turn then stayed on coding-fast. Within a turn the rule is held, and
when affinity kept a member the rule's order wasn't applied at all
(gateway.go and nestedRules skipped `hit.Held && aff.Kept`), so the
failover order was the kept one, then the parent's own order.

ruleOver (rules.go), used at the group's rule and every nested group's:
- the kept one stays first while it is of the rule's member that goes
  first (the one it names, or a Then's while that is resting); the
  rule's other members follow it, ahead of the group's others;
- one kept outside that member, which took over when it failed, isn't
  held: once a member of the rule's target is out of its rest, the next
  request of the turn goes back to it (Affinity.Why "rule"). While all of
  it rests, the fallback stays. No new option.
docs/subsystems/gateway-routing.md says so.

Run (before the rebase onto origin/main): go test -tags nogui -count=1 ./internal/gateway/: green but for
TestKimiHeldBurstTellsNoSpeed at load average ~139 (passes 3 of 3
alone; filed as #1963, not on this path),
gofmt -l, GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gateway/.
TestHeldRuleFailsOverWithinItsMember fails on the old code (tried
[kq1 kf1], the reporter's order), and with the go-back part disabled by
hand (round 3 kept on f1).

After the rebase: gofmt, both vets, and go test -run
'Rule|Group|Affin|Nested|Stick|Turn|Classif|Decide|Pause' ./internal/gateway/ green.
2026-10-13 16:18:05 +08:00
yetone 2fd2cb60d4 usage: ZCode's calls leave the cache out of input, so the Requests page's hit rate reads 96.9%, not 49% (#1947, XcodeFish)
ZCode stores the AI SDK's counts: input includes cache reads and
writes. The session summary already took the cache out, but ocCall
passed ZCode's calls to the ledger as they were, so the Requests page,
which adds the cache to input for its hit rate, counted it twice
(the reporter's 275 calls: 49.2% instead of 96.9%).

ocCall subtracts cache read and write from input for agent "zcode";
callCacheVersion goes to calls-v12 so cached calls are parsed again.

Test: TestZCodeCallInputLeavesOutCache, with the reporter's rows; it
checks each call's tokens, the 96.9% rate, and that the session's
input equals its calls'. Fails on the old code. Ran: go test -tags
nogui ./internal/sessions/ (ok), go vet darwin/linux/windows, gofmt -l.
2026-10-13 16:17:06 +08:00
yetone 32201c6a06 gateway: what GLM leaves between a written tool call and its close is no longer sent on as text (#1945, XcodeFish)
GLM writes calls as text, <tool_call>{json}</tool_call>, and often
leaves stray "]", "}", "}}", `">` or longer runs between the JSON and
the close. hermesCall's json.Decoder stopped at the first whole object
and the tail went to the agent as an answer of its own beside the
call. A heredoc whose quotes the model left unescaped also closed the
object early, and the command went to the agent cut short.

hermesCall now looks at what follows the object: junk (blanks and
}]"'>) and then </tool_call> is taken with the call; other text before
a </tool_call> means the object closed early, so the block is no call
and stays text for the model to write again. A call with no close
followed by prose reads as before. textCallJunk also drops such a tail
after a call's own close.

The same fix for moved users is in the trae plugin 0.2.11
(magpie-community/plugins c3bcb5c).

Tests (textcalls_tail_test.go): TestTextWrittenCallTailDropped (the
issue's tails, and one after the close) and
TestTextWrittenCallCutEarlyNotCalled; both fail on the old code. Ran:
the full gateway package, go vet darwin/linux/windows, gofmt -l.
2026-10-13 16:17:06 +08:00