Commit Graph
351 Commits
Author SHA1 Message Date
yetone e4e22b23ec gateway: a relayed Gemini stream the upstream cut short ends in Gemini's own error (#1644, ggbdpq)
What: a Gemini client's stream relayed as it comes (a custom provider's
Gemini URL, Vertex AI) that the upstream stopped cleanly before a
candidate's finishReason was delivered as if whole: the relay's cut check
(#370) only knew Anthropic's message_stop and Responses'
response.completed. Now the usage sniffer marks a Gemini SSE stream ended
on geminiEnds (the #1643 rule: a candidate's finishReason, or a chunk with
no candidate), the tail switch counts Gemini, and streamFailure writes
Gemini's own mid-stream error, the shape geminiEncoder already uses:
data: {"error":{"code":502,"message":...,"status":"UNAVAILABLE"}} with no
event line (Google's SDK reads none).

Sibling: before this, a read that failed mid-reply on a Gemini relay
(cutMidReply) also went through streamFailure's default and wrote
Anthropic's "event: error" shape to a Gemini client; it now gets Gemini's.

usageMetadata is not taken as an end, as the reporter suggested: Vertex AI
sends it on every chunk (the captured vertexThought bytes).

Run:
- New TestGeminiRelayEndedShort: the captured Vertex reply cut mid-answer
  ends in the Gemini error and no event: line; the whole reply and a
  usage-only reply go as they came.
- Broken by hand three ways, each red: Gemini dropped from the tail switch
  (the cut ended silently); streamFailure's Gemini case removed (Anthropic's
  event: error was written); the sniffer's geminiEnds removed (the whole
  and usage-only replies wrongly got the error).
- go test -tags nogui ./internal/gateway -run 'GeminiRelay|Sniff|Passthrough|CustomGemini|Vertex': ok.
- go test -tags nogui -count=1 -timeout 40m ./internal/gateway after rebase on origin/main: ok (505s).
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gateway clean.

Not run: no real Gemini CLI or Vertex relay cut mid-reply; httptest
serving captured Vertex bytes cut by hand.
2026-10-12 00:36:49 +08:00
yetone 17c56ed245 gateway: a Gemini reply the upstream cut short ends in an error, not as if whole (#1643, ggbdpq)
What: a translated reply from a Gemini upstream (a custom provider's
Gemini URL, Vertex AI, Factory's generate route) or Code Assist
(Antigravity) whose stream stopped cleanly before the last chunk was
delivered to the client as a whole reply: finish_reason "stop" to a Chat
client, end_turn to Claude Code, 200 to a client that asked for no stream.
The cut check from #1562/#1563 (errEndedShort) only ran for Anthropic and
Responses, since Gemini chunks have no type and there is no [DONE].

Why this way: geminiEnds reads a candidate's finishReason (Code Assist's
inside "response"). The reporter's patch also counted usageMetadata as an
end, but Vertex AI sends usageMetadata on every chunk
({"trafficType":"ON_DEMAND"} until the last; the captured vertexThought
bytes), so a real Vertex stream cut after any chunk would still read as
whole. A chunk with no candidate at all (usage alone, a blocked prompt)
does end the stream: the reply said nothing, and #667's empty-reply path
still handles it (TestGeminiEmptyReplyIsAnError's "no candidate"). An
error chunk still reaches the client as the vendor's own error, because
failed is set and the cut check needs failed == "".

Run:
- New TestGeminiUpstreamEndedShort (Chat and Anthropic clients) and
  TestGeminiNonStreamEndedShort use the captured Vertex AI reply cut
  after "No, 391 is not prime because it is". Broken by hand (geminiKin
  dropped from the two cut checks), both fail: the Chat stream ended
  "stop", the Anthropic one end_turn, and the non-streamed one came back
  200 whole. With the fix, the Chat and Anthropic streams carry the
  error, the non-streamed request gets a 502, and the whole reply is
  served as it came.
- TestGeminiEnds: the Vertex usage-only chunk is no end; finishReason,
  Code Assist's wrapped one, and no-candidate chunks are.
- go test -tags nogui -count=1 -timeout 40m ./internal/gateway: ok (425s).
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/gateway: clean.

Not run: no real Gemini/Vertex/Antigravity stream cut mid-reply. There is
no reporter's live case; the fixture is a captured Vertex reply cut by
hand. Code Assist is covered by the geminiEnds unit test only, not an
end-to-end Antigravity request. A relay that strips finishReason from
whole Gemini streams would now get the error; none is known.
2026-10-12 00:27:55 +08:00
yetone 221e24a3c7 agents, gateway: Codex's subagent model offers every provider's models, not only ChatGPT's (#1633, laacmilan)
The Agents page's Codex "subagent model" field (settings.CodexSubagentModel,
which the gateway puts x-openai-subagent collab_spawn requests on) listed
only the ChatGPT accounts' models, and its setter refused any other
provider's. A user whose lead runs on a chat provider (Token中心, 智谱Plan)
couldn't put its subagents there.

- provider: CodexSubagentModels is Codex's shown catalog
  (CatalogFor("codex"), so hidden or unpicked models stay out), ChatGPT
  accounts first, routing groups included. SetCodexSubagentModel takes any
  provider/model or group id, refuses a bare Codex name.
  CodexSubagentUnserved says "magpie doesn't serve it now" for a non-ChatGPT
  id that isn't served. CodexAccountModel exported.
- gateway: codexSubagentPick gets the body. When the lead ran on the
  ChatGPT backend the task arrives sealed (encrypted_content), and only a
  ChatGPT account can open it: set to another provider, such a subagent
  stays on the model asked for, with Kept = sealedKept in the route trace
  (#1613's constraint; the reverse, a chat lead with a subagent on ChatGPT,
  was already handled by 149ab950e). A plain task moves, and sealed
  MESSAGE items are stripped as before.
- gui: i18n for both new reasons (zh, zh-TW, ja, de); the GUI test lists a
  chat provider's model and shows the sealed reason in every language.
- docs: agent-wiring and gateway-routing say the same.

Run:
- go test ./internal/gateway/ ./internal/agent/ ./internal/provider/
  ./internal/gui/ (ok), gofmt -l clean, GOOS=linux and windows go vet
  -tags nogui on the four packages.
- GUI node tests (codex-subagent-model, routing-kind, i18n-keys,
  codex-start-model-field, gui-ja, gui-de, gui-zh-tw) in Chromium and
  WebKit: 38/38.
- Broken by hand: without the sealed check,
  TestCodexSubagentSealedTaskStaysOffAChatProvider fails with a 400;
  options limited to ChatGPT entries, TestCodexSubagentModelTakesAnyProvider
  fails; options from Served() instead of Codex's shown catalog,
  TestAgentModelLineAllHidden and TestAgentModelsOnlyPicked fail.
- Sandbox HOME e2e with the built binary and a fake chat upstream:
  `magpie codex subagent_model token/gpt-6.1-sol` set, a bare gpt-5.5
  refused; a collab_spawn plain-task request on gpt-6-astra to
  /backend-api/codex/responses was answered by token/gpt-6.1-sol and the
  upstream got the task text.

Not tried: a real Codex CLI or ChatGPT account; the sealed case only in
unit tests.
2026-10-11 23:43:37 +08:00
yetoneandhhh2210 957aa79aa3 provider, gateway: refreshing a saved Claude account's card reads its allowance through Claude Code, without switching to it (#1630, hhh2210)
A saved (not signed-in) Claude account's Usage card read nothing on
Refresh: claudeWindows only ever ran /usage for the account Claude Code
itself is signed in to, so the button did nothing for the rest.

Now the card's own refresh (RefreshUsage for that account, savedRefresh)
runs the real Claude Code's /usage with CLAUDE_CONFIG_DIR set to the
account's claudeSavedDir (readSavedClaudeUsage). magpie still never calls
Anthropic with the token itself, and Claude Code's own account is not
switched. The 30-second per-account floor holds, background reads keep
the last reading, and asks for every card (the Usage page opened, magpie
quota, magpie accounts) start no Claude Code per saved account: they keep
the last reading, or the "not read yet: refresh this account's card"
note.

Claude Code may refresh the account's token in that directory while it
runs, spending the old refresh token. So:
- inSavedClaudeDir holds a per-account RWMutex (claudeDirRun) for the run,
  and switchSavedLogin takes it for writing first, so a switch never hands
  Claude Code a copy the run has just spent;
- syncSavedClaude copies a rotated sign-in from the directory back into
  logins.json right after the run, under savedTokenMu and loginsMu.
Two Claude Codes in one directory are kept from refreshing at once by
Claude Code's own lock file (2.1.296's refresh lock in its config dir).
A saved account's warm-up, which already ran in that directory, now goes
through inSavedClaudeDir too.

The plumbing (configDir through UsageClaudeVia, readClaudeUsage and the
gateway's claudeUsage, and TestClaudeUsageRunsInSavedAccountDirectory)
is from hhh2210's patch 043ee7d7, reviewed line by line. Its gate (any
explicit read reads every saved account) was narrowed to the card's own
refresh, and the lock and sync back are new.

Run: go test -tags nogui ./internal/provider ./internal/gateway . (sandbox
HOME, fake claude via UsageClaudeVia, no real token), gofmt -l, GOOS=linux
and GOOS=windows go vet on the three packages. Broken by hand, each red:
saved never read (all three new tests), any ask reads saved
(TestRefreshSavedClaudeUsage), switch not held and no sync back
(TestSavedClaudeUsageKeepsRotatedSignIn / SavesRotatedSignIn), run in ""
instead of the account's directory. Not tried with a real Claude Code
binary against a real saved account.

Co-authored-by: hhh2210 <hzy2210@gmail.com>
2026-10-11 23:37:34 +08:00
yetone f156d90460 agent, gui: Codex isn't handed to a magpie it can't reach, through a proxy or after magpie quits (Muma102kMichael, Leon920717, thisisvainxx on X)
Muma102kMichael (Windows): after magpie took Codex over, every project
and every new chat got 502. Codex's reqwest sends its requests for
http://127.0.0.1:3425 through HTTP_PROXY/ALL_PROXY or the system's
proxy, and only an exact IP or a CIDR in NO_PROXY (on Windows, with no
NO_PROXY, the bypass list with "*." removed) keeps 127.0.0.1 off it:
"127.*" and "localhost" don't, and macOS' exceptions aren't read. A
proxy in global mode answers 502 for every request. With [features]
respect_system_proxy Codex asks the system alone and goes direct with
no proxy set there. Account failover, which magpie writes uninvited
when 2+ ChatGPT accounts are on, put all of Codex's traffic, its own
models included, behind that proxy.

- codex_proxy.go works out Codex's proxy the way Codex does and probes
  GET / through it (must answer as magpie). Failover waits for that
  probe and isn't written while the proxy doesn't pass Codex on; one
  written before goes again.
- New drift kind "proxied": the Agents pill says Codex reaches magpie
  through a proxy that doesn't pass its requests on, How to fix names
  the fix (DIRECT rule for 127.0.0.0/8, NO_PROXY=127.0.0.1, or
  127.0.0.1 in Windows' bypass list), and the dialog has a one-click
  Disconnect from magpie (also on unreachable drift).
- Leon920717: after quitting magpie Codex kept retrying. The app that
  serves the gateway now takes failover out in OnShutdown
  (EndCodexFailover); the next start's Sync writes it again. A
  connected Codex is kept (its model is magpie's; Disconnect restores).
  A kill or crash still leaves failover in place.
- thisisvainxx: "several restarts". Codex's app-server keeps the base
  URL it started with, and KeepCodexDaemonCurrent ends with magpie, so
  EndCodexFailover restarts it when no codex session is on it.

Run:
- real codex-cli 0.162.1 in a sandbox CODEX_HOME against a fake 502
  proxy and a fake gateway: NO_PROXY=localhost,127.* -> 30 POSTs to the
  proxy; NO_PROXY=localhost -> proxy; NO_PROXY=127.0.0.1 -> gateway;
  respect_system_proxy with HTTP_PROXY set -> gateway directly.
- go test -tags nogui ./internal/agent/ (full package, 465s, ok) and
  the new tests after the daemon change; each new test went red with
  its guarantee broken by hand (failover gate, drift, EndFailover,
  daemon restart on quit).
- node --test agent-proxied/agent-unreachable/agent-failover/
  agent-disconnect-preview: 104 passed, chromium + webkit, en zh zh-TW
  ja de, window and panel.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui clean.
Not tried: the quit path in the real app, on the Windows box, or
whether computer use / remote connection broke for this same reason.
2026-10-11 23:00:00 +08:00
yetone 863af7abc8 provider: a provider's Extra body adds JSON fields to every request's body, ${sessionId} as the session (#1604, Luc-xz)
What: a provider has an Extra body (extraBody in providers.json, a JSON
object, beside Headers; an "Extra body" box in the editor under Headers).
Its fields are added at the top level of every JSON body sent to that
provider, in the gateway's forwardOnce: Messages, Chat, Responses and
Gemini, relayed as they came or translated from another API. Test models
and Detect send them too (provider.tested), so a relay that
refuses a request without them can be tested before a Save.

- A field the request already has is kept; "!name" replaces it.
- ${sessionId}, in any string at any depth, becomes the session id: the
  agent's session header (sessionOf), else the id conversationID derives
  from the first user message (magpie-<hash>), stable through one
  conversation. Test and Detect send magpie-test-<12 random letters>.
- model, stream and the conversation (messages, input, contents, system,
  systemInstruction, system_instruction, instructions, tools) are never
  set from it: Save refuses them (ExtraBodyOK), the editor says why as
  they are typed and holds the Save, and one written by hand into
  providers.json is dropped on read (cleanExtraBody).
- Not sent: count_tokens, embeddings, images, video, the decision model,
  and signed-in accounts' requests. One object goes to every API;
  per-API sections aren't done.
- A save that leaves extraBody out keeps the saved one; {} clears it.

Why: Luc-xz's relay turns Responses requests away without a
prompt_cache_key, and headers alone couldn't add one.

Docs: providers-accounts.md has an Extra body row and its tests.

Run:
- go test -tags nogui ./internal/provider ./internal/gateway ./internal/gui
  -run ExtraBody: pass. The tests are TestExtraBodyResponsesRelayed,
  ChatDerivedSession, Translated (messages→chat, chat→responses),
  Anthropic (count_tokens left alone), Gemini (relayed and from chat),
  TestExtraBodyTested/OK/ReadByHand, TestWithExtraBody and
  TestProviderExtraBodySaved.
- Broken by hand, each FAIL recorded, then restored:
  - WithExtraBody removed from forwardOnce: all 5 gateway tests FAIL.
  - the countsTokens guard dropped: TestExtraBodyAnthropic FAIL.
  - tested() without the extra body: TestExtraBodyTested FAIL.
  - Save's ExtraBodyOK skipped: TestProviderExtraBodySaved FAIL.
  - keep-when-omitted skipped: TestProviderExtraBodySaved FAIL.
- internal/gui/tests/extra-body.test.cjs: en, zh, ja and de, in Chromium
  and WebKit, 8/8 pass. It covers live errors, Save held and focused, Test
  sending the typed object, the 420px fit, Save as an object, and empty
  saving {}.
- Also run: gui-de, gui-ja, gui-zh-tw, i18n-keys, provider-*, providers-*,
  balance-fix, duplicate-pause, editor-short-window, ux-safety and
  vertex-editor.
- gofmt -l clean; go vet -tags nogui for darwin, linux and windows on
  provider, gateway and gui; the full go test ./... after the rebase.

Not tried: a real relay that needs prompt_cache_key; the fixtures are
httptest upstreams.
2026-10-11 22:41:11 +08:00
yetone 8902ec2179 library: a server that admits only the apps it lists says so at Sign in, and leaves the sign-in to each agent (#1619, Xichun123)
Figma's remote MCP server (mcp.figma.com/mcp) allow-lists clients by the
client_name they register with: its registration endpoint
(api.figma.com/v1/oauth/mcp/register) answered a plain registration
named Magpie 403 with the bare body "Forbidden" (tried once, by hand).
The Library's Sign in then showed "registering magpie with the server's
sign-in failed (403): Forbidden", which reads as a fault to retry.

magpie doesn't register under another client's name. A 401 or 403 from
registration is now mcpauth.ErrClientRefused: the server's sign-in admits
only the apps it lists and turned magpie away; the agents given it still
have the server's own address, so each signs in itself (in Claude Code,
/mcp). That address is what they already get while magpie isn't signed
in (library.through), so Claude Code, a client Figma lists, signs in
there with its own registration. The message is translated into zh,
zh-TW, ja and de. Other registration failures keep their status and body.
docs/subsystems/library.md says it.

Run: TestSignInRefusedByAnAllowListLeavesItToTheAgents (new, through
library.SignInServer against mcpauthtest serving Figma's 403 bytes)
fails without the change with the reporter's exact "registering magpie
with the server's sign-in failed (403): Forbidden", passes with it, and
checks claude, codex and cursor keep the server's own URL.
mcp-signin.test.cjs (Figma case added) passes in Chromium and WebKit, en
and zh; gui-ja, gui-de, gui-zh-tw and i18n-keys pass. go test -tags nogui
./internal/mcpauth/... ./internal/library/ ./internal/gui/ ok under a temp
HOME; gofmt -l clean; GOOS=linux and GOOS=windows go vet ok. Not tried:
Claude Code's own /mcp sign-in to Figma (no Figma account here).
2026-10-11 22:06:36 +08:00
yetone 7cba316b90 gateway, gui: a notification when an agent's long task is done, opt-in in Settings › Usage (itieniu on X)
itieniu asked for a "ding" when a long Claude Code or OpenCode task
finishes. magpie sees every request an agent sends through it, so the
gateway now follows each agent session's turn and the app notifies at
its end.

Gateway (turndone.go): a request is of the turn unless it is one the
agent makes on the side (Kind) or a Claude Code subagent's. Its reply is
scanned on the way to the agent for a tool call in every wire format
(Anthropic tool_use, Chat tool_calls/function_call, Responses
function_call/custom_tool_call/local_shell_call/..., Gemini
functionCall), as a JSON value, never a key ("tool_calls":[]) or text.
The turn is done when no request of it is going, the last reply was
whole, under 400 and called no tool, and nothing more came for 4s; a
session idle past 30m starts over. The ChatGPT backend path is followed
too. Only a turn at least Settings' TurnDoneAlert seconds long is told,
and only when the app set gateway.TurnDone: magpie serve follows nothing.

Settings: turnDoneAlert (seconds, 0 = off, the default, at most a day).
GUI: Settings › Usage "Task done alert": Off / 1 / 3 / 10 min; the
notification says "Codex is done", "Took 1m 8s · folder", in en, zh,
zh-TW, ja and de. A click on it doesn't open the Usage page.

Tests: TestTurnDoneSaidAtTheTurnsEnd (chat and anthropic through the
gateway: a tool reply, a subagent's last reply and a short turn don't
fire; a final reply fires once with session and folder),
TestTurnDoneCodexBackend, TestTurnDoneWaitsForEveryRequest,
TestTurnDoneOff, TestToolScan (every split point), TestTurnDoneText,
settings' range. Broken by hand: without the capture's scan, without the
subagent exclusion, or without the codex backend's scan, they go red.
turn-done.test.cjs: every language, 900 and 380px, chromium and webkit.
The new row moved the Usage tab's geometry: usage-alert and currency
now wheel their row clear of the header before clicking it, as a reader
would (both green 5/5 here; on base they were green as before).

Run: gofmt -l; go vet darwin, GOOS=windows ./..., GOOS=linux gateway and
settings; go test ./... (gateway alone: ok, 863s under a GUI suite's
load); the full GUI suite in both engines. codex-credits and
gateway-key-models fail now and then here on base 398f8469b too
(codex-credits filed as #1622).

Real use: a sandbox HOME, the app's dev build on 3486/3487, "1 min"
clicked in its Settings › Usage (settings.json got turnDoneAlert 60);
then the gateway in that HOME with a TurnDone that logs, and real Codex (codex exec, ChatGPT sign-in, openai_base_url at the
sandbox gateway) running `sleep 62` then answering: the turn's end came
once, agent codex (Codex), its session, folder turnproj, took 1m8s; a
short "reply hi" turn after it didn't fire. The macOS notification
itself wasn't seen: an unbundled dev binary can't post one ("require a
valid bundle identifier"); the notifier is the one usage alerts use.
Claude Code and OpenCode weren't run live; their wire formats are in
the tests.
2026-10-11 21:59:10 +08:00
yetone 1075991f90 gateway: a plugin's fetch is told the folder the agent works in and whether it is a git repository, never seeing magpie's own (plugins #86, Hipple)
A plugin runs in magpie's plugin host, so its process.cwd() is magpie's
folder. The ZCode plugin's Start Plan request said that folder
(C:\Users\<user>\.config\magpie) as the agent's "Primary working
directory", with "Is a git repository: no", and the model looked there.

forwardOnce now calls tellWorkPlace on every request to a plugin's
provider. It reads the request as sent to the plugin with workPlace (the
same reading rules by folder use) and sets two headers on the plugin's
fetch:
- x-magpie-work-dir (provider.WorkDirHeader): the folder, percent-encoded
  (url.PathEscape; decodeURIComponent reads it);
- x-magpie-work-git (provider.WorkGitHeader): yes/no. The agent's own word
  beside the folder (Claude Code's "Is a git repository: true/false",
  OpenCode's "Is directory a git repo: yes/no") wins. Otherwise it is a
  .git in the folder or above it, when the folder is on this computer
  (provider.GitSaid, provider.GitOnDisk in the new workplace.go).
Each is left off when unknown; a folder that isn't on this computer and
that the agent didn't call a repository has no git value, never "no".
host.js's fetch (unsaid) takes both headers off every request a plugin
sends, so a plugin that forwards the headers it was given sends them to
no vendor. Documented in docs/subsystems/provider-plugins.md.

Run: TestPluginToldWhereTheAgentWorks (new) sends the captured Claude Code
and Codex requests, and Pi-style ones from a temp repo subfolder and a
plain folder, through the fake plugin to fake-claude and fake-1. It checks
what the plugin read and that the vendor got neither header. Broken by
hand: without the tellWorkPlace call every case fails; without unsaid in
host.js it fails with "the vendor got X-Magpie-Work-Dir". go test
internal/gateway (-timeout 40m), internal/provider, internal/plugin;
gofmt -l; go vet on darwin, GOOS=linux and GOOS=windows for the three
packages.
2026-10-11 21:51:34 +08:00
yetone 96de5cac29 gui: Providers has a search box, and a provider's right-click moves it to the top or the bottom (#1614, ququdu)
ququdu has many providers and kept scrolling to find one, and moving one
far up the list meant a long drag. The Providers page had neither a search
nor a quick move; its rows moved only by dragging the logo or Alt+↑/↓ one
step at a time.

- A search box over the list, at its right edge as Settings' is (full width
  in a narrow window). The words typed keep the rows, on and off, whose
  text or data say them all: name, id, preset, addresses, every model's id
  and name, the account's user and plan and each login's, account names
  and key names. The Turned off fold stays open while searching; nothing
  found says so; Escape or clearing the box shows every row and the fold
  as it was (findProviders).
- A row that is on has a right-click menu, as an agent row has: Move to
  top, Move up, Move down, Move to bottom (openProviderMenu), with their
  keys. Alt+Shift+↑/↓ on the logo go to the top or the bottom.
- While searching, a row still moves, among the rows shown: Alt+↑/↓ and a
  drop put it where the shown row it passes was, and the hidden rows keep
  their order (stepProvider, shownToOn). Move to top and Move to bottom go
  to the ends of the whole list. Every move saves the whole order through
  /api/providers/arrange as before.
- After a save, the keyboard stays on the handle it is on, also when it
  was another row's taken up while the save was out (it was lost before).
- The logo's tooltip says right-click moves it to the top or the bottom.
- Drag already scrolls the page near its edges (dragRows); unchanged.

Strings in zh, zh-TW, ja and de. docs/subsystems/gui-shell.md says how it
works.

Run:
- provider-find.test.cjs (new), en, zh, zh-TW, ja, de at 420x560, Chromium
  and WebKit: matches by name, model id, account user, key name and two
  words; the off row found with its fold open; nothing-found text; Alt+↑ and
  a drag while filtered, with the posted order checked; Escape; the menu's
  four items, which are off at each end; Alt+Shift+↑/↓; nothing scrolled,
  nothing but the order posted, no overflow. Fails on the old assets ("no
  search box on the Providers page"), and goes red with each of five breaks
  by hand: steps over the full list while filtered, no right-click menu,
  drop index taken as a full-list index, no Alt+Shift, the off fold
  honoured while searching.
- provider-order.test.cjs updated for the tooltip.
- Every GUI test that opens the Providers page (150 files): WebKit 754/754;
  Chromium 748/752 under load ~100, the 4 in azure-endpoint and
  routing-save (30s waits on the add sheet and routing) pass alone in both
  engines, with provider-search, provider-order and settings-search
  (31/31). gui-zh-tw, gui-ja, gui-de pass in both.
- go test -tags nogui ./internal/gui/... (sandbox HOME), go vet darwin,
  GOOS=linux and GOOS=windows -tags nogui.
- Screenshots looked at: zh narrow with a search, zh wide with the menu.
2026-10-11 21:42:30 +08:00
yetone 0fcf563e61 routing: a pause rule can hold by folder, in some or outside them (#1606, Ti800)
Ti800 keeps a subscription's quota for one long task in one folder and
wants every other request kept off it (their option A). A pause rule
held by hours, days and agents only; it now holds by folder too.

What changed
- provider.Rule gains ExceptFolders (json exceptFolders, CLI
  except-folders=, aliases except-folder/not-in/outside): the folder the
  agent works in is in none of them. An agent that says no folder isn't
  known to be in one, so except-folders holds for it; folders= still
  never matches an unknown folder. Both conditions are allowed on send-to
  and pause rules (Rule.ByFolder, inFolders); cleanRules cleans and
  dedupes both and lets a pause hold by time, days, agents and folders.
- PausedOut takes the request's folder. The gateway reads it (workDir)
  only when a pause by folder is on the way (PausesByFolder); embeddings
  and System One's decision calls pass none. Paused carries Folder and
  ByFolder for the trace. ruleFor reads the folder for except-folders
  rules too.
- Group sharing drops every rule by folder, except-folders included.
- CLI usage, TUI hint, ParseRule/Line round-trip except-folders.
- GUI: the rule editor has a "not in folder" condition beside "in
  folder", both shown on a pause and kept when a rule turns into one; a
  folder that isn't a whole path and a pause with no condition are
  refused; the group's rule and the trace say "not in …", and a paused
  reason says the folder read or that the agent said none. Strings in
  zh, zh-TW, ja, de.
- Docs: gateway-routing.md, site start.html (en, zh, ja).

What was run
- go test -tags nogui ./internal/provider ./internal/gateway (folder,
  pause, share, rule tests); full go test ./... before pushing.
- Broke it by hand: with the gateway's folder read replaced by nothing,
  TestPauseByFolder fails (in-task requests went to the other member).
- GUI: routing-pause-folder.test.cjs (new), routing-pause,
  routing-folder, i18n-keys and 10 other rule-editor tests in Chromium
  and WebKit, en/zh/zh-TW/ja/de, at 1100px and 390px.
- gofmt -l; GOOS=linux and GOOS=windows go vet of the touched packages.

Not tried: a real Claude Code subagent's request against a live group;
by the documented rule a request without a folder is paused off the
kept member, which is what the reporter asked for.
2026-10-11 21:24:10 +08:00
yetone 149ab950e7 gateway: a Codex lead on a chat provider goes on when its subagent on one of Codex's own models sends it a message, the sealed message left out with a note (#1613, laacmilan)
laacmilan's lead was on token/gpt-6.1-sol, an API key on Chat
Completions. Codex put a subagent on one of its own models, which magpie
serves from the ChatGPT account. The ChatGPT backend seals that
subagent's send_message, and Codex hands it to the lead as an
agent_message: a plain "Message Type: MESSAGE" header plus
encrypted_content (codex-rs protocol.rs to_model_input_item). serve's
sealed gate (#619, #1237) took any sealed agent_message as a task. Only
the ChatGPT backend can read it, so the lead's next turn was refused. The
refusal said the lead "has since been on one of Codex's own models",
which it never was. This had been so since the gate was added, not only
since yesterday's release.

- A sealed message (not a task) that no candidate can open is left out
  now (withoutSealedMessages). An input_text note naming its sender goes
  in its place, and the request goes on where it was. The subagent's
  final result still reaches the lead as text. A sealed task (NEW_TASK,
  or an item with no header) is still refused, as in #619: without it
  the subagent has nothing to do.
- The refusal for a sealed task, where the provider that answered the
  lead can't seal, no longer says the lead switched models. It says the
  task came from an agent of this thread on one of Codex's own models,
  and points to Codex's subagent model on the Agents page.
- docs/subsystems/gateway-routing.md says so.

Run:
- The new tests in sealed_message_left_out_test.go. The lead and
  subagent cases fail on the old code with the reporter's exact message,
  and also fail with the strip turned off by hand.
- go test -tags nogui -run 'TestSealed|Codex|Sealed' ./internal/gateway.
- go test -tags nogui -timeout 40m ./internal/gateway.
- gofmt -l.
- GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gateway.

Not tried: real Codex desktop with a real ChatGPT account and a chat
provider. The requests are Codex-shaped fixtures built from codex-rs's
item format.
2026-10-11 21:17:02 +08:00
yetone 76f802d37d gateway: Command Code's Provider API searches by itself for the 12 models that do, and the rest keep magpie's searcher (#1590, M3chD09)
Command Code's Provider API passes a provider-defined web_search on to the
model's vendor, and only some models search: M3chD09 ran all 87 and 12
did (claude-sonnet-5-5 and claude-haiku-5-5 on Messages; gpt-6-luna,
gpt-5.6-sol, gpt-5.6-luna, meta/muse-spark-1.2/1.3 and their -contributor
ids, xai/grok-4.5/4.6/4.7 on Responses). magpie took the whole provider
as one that doesn't search, so each of those searches went to the
searcher instead. Marking the provider as searching (Searches, or its
host in searchHosts) would have sent the tool to the other 75, which take
it and don't search.

searchModels now lists, per provider and API, the models that search by
themselves; modelSearches reads it for a keyed provider made from the
"commandcode" preset or at api.commandcode.ai, and none count when the
provider is sent Command Code's x-cmd-zdr header, under which it refuses
every built-in tool (cmd_zdr_unsupported_tool, from the report). It is
read in searchesModel, so the relay/translate choice and the tool swap
both follow it, and in webSearchOf, so a remote magpie's list says
"native" for those models too. Sign-ins (the Command Code Plan, its
plugin) are not changed.

Verified:
- TestCommandCodeSearchesForSomeModels: gpt-6-luna and xai/grok-4.7 on
  Responses and claude-sonnet-5-5 on Messages are sent the agent's own
  web search tool; deepseek-v4-pro and claude-opus-5-5 aren't; with
  x-cmd-zdr: 1 none is. Without the searchesModel change it fails for the
  three searching models.
- go test -run Search ./internal/gateway, gofmt -l.
- Not tried against the real Command Code API (no key for it here); the
  list is the reporter's run of 2026-10-11.
2026-10-11 21:00:29 +08:00
yetone d82985eee1 agent: a routing group whose members are all best on Responses is asked there by Pi, omp, droid and dsh, so its tool-call arguments stream (#1594, ObsidianArch02)
magpieModels gave a routing group no native API, since its members may
each want another. Pi, omp and droid then asked every group on Chat
Completions, and dsh put it on its Chat route, even a group of GPT
members all served on Responses. The gateway translated each answer from
Responses to Chat, and that translation holds a tool call's arguments
until the call ends (#613), so Pi's Code Mode saw no code until the whole
call had been generated.

A group now has APIs ["responses"] when every member, nested groups'
included, is served best on Responses (allResponses over the group's
members, by Provider.Native). Any other group keeps none: one with a Chat
member, and a Messages-only group too, as the gateway knows whether a
Claude thinks adaptively by its own model id, not the group's. dsh moves
a start on such a group to its Responses route (dshStartOnItsRoute); a
dsh session resumed on it asks for the model once, as for any model that
moved routes.

The rest of the request (a protocol picked per group, conversion shown
per request) is not in this commit.

Verified:
- TestPiModelsAskedOnTheirNativeAPI: auto-gpt-5-5, a GPT group and a
  group of that group get openai-responses; a group with a Chat member
  and one of Messages-only members get none. Without the route.go change
  it fails for the three Responses groups.
- TestOmpModelsAskedOnTheirNativeAPI: the same for omp.
- TestGroupOnResponsesRelaysArgumentDeltas (gateway): a group of two
  Responses-only members asked on /v1/responses relays each
  function_call_arguments.delta as the vendor sent it, on /responses.
  It guards what this change relies on, and passed before it too.
- go test ./internal/agent ./internal/provider, gofmt -l, GOOS=linux and
  windows go vet -tags nogui.
- Not tried with a real Pi against a real group.
2026-10-11 21:00:29 +08:00
yetone 16b5c8700f gui: a library MCP server no agent or project has isn't checked on its own; its status says "not checked" and a click checks it (#1597, xiaozhu1337)
Opening the Library's MCP tab started (or reached) every server in the
library once a session to list its tools, the ones switched off for
every agent too. Some users keep many servers in the library and turn on
a few, and each unused one was still started.

A server that no agent has, here or in a project magpie keeps (inUse),
is now left out of that check. Its status reads "not checked", with the
reason in its tooltip, and a click checks it, as a click already checks
any other server again. Once an agent is given it, the page renders again
and the server is checked as before. New strings in zh, zh-TW, ja and de.

Verified:
- library-mcp-health.test.cjs: a server on for no agent shows "not
  checked" and is not in the first check; one on only in a project still
  is; a click on it checks it alone (fresh) and opens no editor. Chromium
  and WebKit, en and zh. Without the library.js change it fails: the
  first check asks for "idle" too.
- library-mcp-tools and library-mcp-tool-switch: their padding servers
  were on for no agent and relied on the old check, so they are on for
  Claude Code now; the tests are otherwise unchanged.
- library-servers-bulk, mcp-signin, library-mcp-copy-config,
  project-servers, library-zed-mcp, search-mcp, gui-ja, gui-de pass in
  both engines. library-mcp-tool-switch times out in WebKit at load ~180
  on some languages with and without this change (#1609, filed earlier).
2026-10-11 21:00:29 +08:00
yetone 0e89b090c1 gateway: Codex's auto-review on codex-auto-review goes through a ChatGPT account past its usage cap, since OpenAI made it free (#1593, hywang1230)
An account past the usage cap set on it in magpie was held for every
model, so Codex's auto-review on codex-auto-review was refused with
"usage cap reached" once the account reached its cap. OpenAI made
Auto-review free for every ChatGPT sign-in on 2026-10-06: the reviewer's
calls are counted in no usage window, so the cap, which keeps a share of
a window unspent, has nothing to keep for them.

capHeld now leaves the user's caps out for a Codex (ChatGPT) account's
call on codex-auto-review (freeOnChatGPT). Credits set not to be spent
still hold it at 100% of a window, as nothing says the backend answers it
there. A review run on another model, or any other model, is held as
before.

Verified:
- TestAccountCapLetsAutoReviewThrough: an account at 92% with a 90% cap
  takes codex-auto-review on Codex's backend path and as
  codex/codex-auto-review, and still refuses gpt-5.5 on both. With the
  exemption disabled it fails with the reporter's exact 429 ("usage cap
  reached: every account that serves "codex/codex-auto-review" ...").
- go test -run 'TestAccountCap|TestCodexNoCredits|TestWindowCaps'
  ./internal/gateway, gofmt -l, GOOS=linux/windows go vet -tags nogui.
- Not tried against the real ChatGPT backend with a capped account.
2026-10-11 21:00:28 +08:00
yetone e9f6e48d6a gateway, docs: keepIdle's record no longer says a reply ending after letGo kept a run twice, which serveSubscription rules out (#1596)
d1f0576a7's comment, test comment and subsystem doc named the cause of
a run under two keys as letGo keeping it at backKey and the same
request's ended then keeping it at the turn after. That order can't
happen: serveSubscription's ended callback starts with `if !gone()
{ return }`, and gone is the stop of the context.AfterFunc that calls
letGo, so for one request exactly one of the two runs. The reporter's
own overlap test drove ended by hand while letGo ran, an order the
gateway doesn't produce.

Which callers kept one run twice in the reporter's gateway is not known;
keepIdle, the only writer of b.idle, now holds the rule whichever it
was. The comments and doc say that instead. No code change.

Run: gofmt -l, GOOS=linux and GOOS=windows go vet -tags nogui
./internal/gateway, -run TestClaudeIdle ./internal/gateway.
2026-10-11 20:53:02 +08:00
yetone dbe81adae6 gateway tests: TestClaudeIdleEvictionEnds fails on what keepIdle's old loop allocates, not on a 5s deadline (#1596)
d1f0576a7's child process failed the old loop by -test.timeout=5s under
GOMEMLIMIT=64MiB, with 30s for the parent. On a busy machine (load ~130
here) starting the gateway test binary and its TestMain can take a good
part of that, so the passing case had little room. Now the child runs
the keeps in a goroutine and watches TotalAlloc: past 256 MiB without
ending, it exits 2 with what it allocated. The ending loop is done in
microseconds, so its child has 4m and the parent 5m.

The rekey scenario set idleAt before keepIdle stamped it with
time.Now(); it is now set after, so on a coarse clock (Windows) the
stale run is still the oldest and the scenario still reaches the loop.

Run: on origin/main 5c9221899, -run TestClaudeIdle ./internal/gateway
green (each child ~20ms); with internal/gateway/claude_subscription.go
from 76db4c6c2 (before the fix), rekey and stale both red in ~0.5s,
"keepIdle allocated 258 MiB without ending". gofmt -l clean, GOOS=linux
and GOOS=windows go vet -tags nogui ./internal/gateway clean;
go test -tags nogui ./internal/gateway and the full suite before push.
2026-10-11 20:53:02 +08:00
yetone 6f1b432759 provider, gui: smart routing spends WorkBuddy credits that expire soonest first (cdredfox on X)
WorkBuddy's Credits window had no reset, so in a Smart group every
WorkBuddy account ranked alike. workbuddy plugin 0.1.14 (plugins f0274d6)
reads WorkBuddy's own package lists (billing/meter/get-user-resource-paid-
packages and -free-packages, the calls WorkBuddy's client makes) and reports
on the Credits window when the soonest-ending package that still has credits
ends (runsOutAt) and how many credits it holds (runsOut). The daily Free
Plan slice (CapacityType 4) and code 001 aren't counted: they renew daily.

magpie carries runsOutAt from the plugin's usage window into QuotaWindow and
the routing Limit. Allowance.Renewal, which only Smart ranks on, treats it
as the window's reset when it is sooner than the real one. Pace, the tiers,
For, Full and resting are unchanged. The mover's min is raised to 0.1.14 so
moved users get the plugin. The usage card and account meter say "232.4
expire in 5h" in every language.

Run:
- plugin: bun test, 63 pass; 2 of the 3 new tests fail on 0.1.13's
  index.mjs. Verified live on a workbuddy-ai account in a sandbox HOME:
  Bonus Pack 232.4 left ending 10-12T16:39Z ranked before Pro (10-28).
- TestWorkBuddyCreditsRunOutForRouting and
  TestSmartSpendsWorkBuddyCreditsRunningOutFirst: both fail with the
  Renewal change removed by hand.
- GUI: credits-run-out.test.cjs in webkit and chromium, 5 languages, at
  360/440/1000px, red on the old app.js; with i18n-keys, quota-*,
  panel-usage, reset-each-title, usage-fold: 117 pass.
- go test ./... green (agent and gateway rerun with -timeout 30m after the
  default 10m ran out under load from other sessions; 378s and 492s).
- gofmt -l clean; GOOS=linux and windows go vet of provider, plugin,
  gateway clean.

Not tried: the CN workbuddy site (its token was stale, 401), so the CN
package list is assumed to have the same shape. The built-in WorkBuddy
(not moved users) doesn't get this. The account-line tooltip has no GUI
test of its own.
2026-10-11 20:07:19 +08:00
yetone e9ae318589 gateway: a relay's 500 "负载已经达到上限" is a busy server, not quota, so a group's Patience waits it out (#1418, real-jacket)
real-jacket's relay answered 500 "当前模型 gpt-5.5 负载已经达到上限,请稍后重试
(request id: …)". usedUpWords matched 上限, so failure() called it
failQuota: the key rested till a reset and busy() (5xx only when
failOther) never let Patience wait, so the agent got the 500 at once.

Change: a 5xx is out of quota only on a vendor's own quota code
(quotaCodes: Claude Code's "usage limit reached|<unix>",
usage_limit_reached, RESOURCE_EXHAUSTED). The quota words still classify a
4xx, and the 429 plan words are unchanged; credit is unchanged.
gateway-routing.md says so.

Run:
- routing_test's failure table: the literal 500 → failOther; a 503
  "upstream quota service unavailable" → failOther; 500
  usage_limit_reached and 503 RESOURCE_EXHAUSTED → failQuota; 403
  "今日额度已达上限" → failQuota; 429 "当前分组上游负载已饱和" → failRate.
- New TestGroupWaitsOutRelayLoadLimit (two members answering the literal
  500, Patience 240): fails on the old code with the 500 (a 1, b 3), now
  200 after a replan with no quota rest.
- go test ./internal/gateway, gofmt, GOOS=linux/windows go vet -tags nogui.

Not done: a 429 with the same load wording still reads as quota (no
literal case of it seen).
2026-10-11 19:59:15 +08:00
yetone 691858e064 gateway: a Codex routing group that falls to DeepSeek sends every tool call with reasoning_text, so DeepSeek no longer refuses it with 400 (#1592, waangzh)
What the reporter saw: a Codex mixed group (ChatGPT first, DeepSeek after)
answered 400 "The `reasoning_text` in the thinking mode must be passed back
to the API." once the turn fell to DeepSeek.

Cause, checked against the real api.deepseek.com/v1/responses on 2026-10-11
with the owner's key: DeepSeek refuses a history where
- a reasoning item is sealed only (ChatGPT's encrypted_content, no summary),
- a function_call/custom_tool_call has no reasoning item in its step (an
  assistant turn ChatGPT answered without one, or a second step), or
- a reasoning item's reasoning_text is empty.
It accepts reasoning_text " " (with or without encrypted_content and id).
withReasoningText only filled the third case.

Change:
- withReasoningText (passthrough) walks the input by step: a reasoning item
  with no text gets its summary, else noReasoning (" "), keeping its other
  fields (encrypted_content, id); a tool call with no reasoning item since
  the last output or user message gets one with noReasoning before it.
- buildResponses (translated, e.g. an Anthropic agent onto DeepSeek's
  Responses) does the same for a tool call with no thinking before it.
- Only where replaysReasoning says so (DeepSeek); gpt-5.4 on a relay gets
  no reasoning_text.
- gateway-routing.md describes the Responses replay.

Run:
- The reporter's 400 reproduced on the real API, directly and through the
  old binary (direct model and group/codex-different); the new binary
  answers 200 completed for each case, whole and streamed.
- New TestDeepSeekGroupMemberAfterChatGPT (8 subcases) and
  TestTranslatedDeepSeekCallWithoutReasoning fail on the old code, and
  TestDeepSeekReasoningPassedThrough's empty item; all pass now. The fake
  now refuses what the real API refuses.
- go test ./internal/gateway, gofmt, GOOS=linux/windows go vet -tags nogui.

Not done: DeepSeek's Anthropic endpoint has the same rule (a tool_use with
no thinking is refused, checked live); not changed here. Kimi and GLM
thinking were not checked: no key, and magpie has no replay rule for them.
2026-10-11 19:59:15 +08:00
yetone 35eea09464 gateway: a provider routed its own way keeps that order inside a group that routes another way (kchen0x on X)
kchen0x had a Smart routing group with Antigravity (9 accounts, set to
按顺序) and a Business account. Requests still went to the 9th account, the
one renewing soonest. planLevel pooled every member's keys and accounts
into one list for any group not routed in order, so the provider's own
routing was never read; Smart then put the soonest renewal first.

Now a member whose provider routes other than Smart, and other than the
group does (ownRouting), is planned as a nested group already is: a unit
weighed by the first account or key it would try (firstAwake), then tried
whole in its own order. A provider left on Smart is pooled as before.
leastHeld, which reorders a rotate group's first request, leaves such a
group alone as it does one holding a nested group (without that, a
rotate group still came back "k2 k1 k3 kb").

GUI hint (GROUP_NEST, 4 languages), start docs (en, zh, ja) and
gateway-routing.md say so.

Run:
- TestProviderKeepsItsOwnRoutingInAGroup covers outer Smart, rotate,
  usage, pace and manual, plus a Smart provider still being pooled. On
  the old planLevel it fails with "k3 k2 k1 kb" (the reported order).
- go test -tags nogui -count=1 -timeout 40m ./...: all ok.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet ./internal/gateway.
- GUI: i18n-keys, gui-ja/de/zh-tw and every *group*/*routing* test, both
  engines: 765 pass. A first run beside the full go test had 9 webkit
  timing reds (routing-group-fold, routing-keys-fold, routing-ctx-still,
  gateway-key-groups); each file passes alone, and the whole set passes
  when nothing else runs.
2026-10-11 19:54:55 +08:00
yetone 917a365778 gui: opening the Usage page or the tray panel's Allowances reads the allowances now, once in 30s (#1588, qq666666qq)
On Windows the tray panel's Allowances tab, and the window brought back
on Usage, showed the reading magpie kept until "Read the allowances
again now" was pressed: picking the panel's tab and the panel shown
again only loaded usage/quotas without ?asked=1, which hands back the
backend's cache, and so did the window coming back to the front on
the Usage page.

Opening the allowances is now asking to see them (quotasOpened), as
Refresh now is and as #1518 counts the Usage page opened:
- the window: Usage from the nav (as before), the Overview tab picked,
  and the window back to the front on the Overview;
- the tray panel: the Allowances tab picked, the panel brought up on it
  (focus / visibility), and a menu bar cell clicked (panelQuotaFocus).
A panel page loaded while it is put away (hidden or without focus)
doesn't ask, so a panel prepared at login sends nothing with allowance
reads at "When I ask".

An asked read makes the backend read every account again (AskUsage
clears the caches; only Claude has its own 30s floor), so an opening
within 30s of the last asked read (QUOTAS_OPEN_GAP) sends an ordinary
read instead: switching tabs and back, focus and visibilitychange both
firing, focus-follows-mouse don't reach the vendors again. Reads stay
one at a time: an opening during an ordinary read goes after it
(loadQuotas, unchanged). Refresh now still asks every time; the timed
refresh is unchanged and never asks.

Written against main from qq666666qq's fork patch
(qq666666qq/magpie#1), which asked on every tab click and every return
without a gap; this keeps their entries and adds the gap, the Overview
tab, and the hidden-panel guard.

Run: new allowance-open-read.test.cjs (Chromium and WebKit, en and zh,
panel at 360px): passes; red on the old app.js (the panel's Allowances
never asks; the window re-asks on every nav click), red with
QUOTAS_OPEN_GAP = 0, and red with the window-return line removed. The
GUI tests touching the allowances (every test naming usage/quotas, the
Usage view or the panel's Allowances tab) in both engines, and
go test -tags nogui ./internal/gui. No Go changes. Not tried in the
native Windows tray.

Of the GUI run (3164 tests, load ~120-230), the 8 failures passed when
their files were run again, except library-mcp-tool-switch in WebKit,
which fails the same with main's app.js (76db4c6c2): filed as #1609.
Rebased onto f6e1e98ee; the new test, claude-usage-asked, panel-usage,
panel-arrange, click-scroll and ./internal/gui run again after it.
2026-10-11 19:46:37 +08:00
yetone 99548470d0 gateway: Claude Code's billing line no longer goes to vendors' models, so their prompt cache is read again (#1600, justrun1983)
Claude Code puts `x-anthropic-billing-header: cc_version=…;
cc_entrypoint=…; cch=…;` in system[0], a block of its own whose cch
changes every turn. magpie sent it on to every upstream, so a vendor's
model read it as the first words of the prompt and its prefix cache
missed from byte 0 on every turn: the reporter's Claude Code on
commandcode-plan/deepseek-v4.1-flash read 4.1% of its input from the
cache, ~96-99% with the line turned off in Claude Code.

The line now goes on only to a Claude model asked on Anthropic's
Messages API (a key's, a relay's, Bedrock's), byte for byte as Claude
Code sent it (keepsBillingLine, billing_line.go). Everywhere else it is
left out and the rest of the system goes as sent, cache_control included:
- a vendor's model relayed on Messages (passthrough: DeepSeek's,
  Command Code's Provider API, a moved plugin's Messages);
- every translation to Chat, Responses or Gemini (forwardTranslated,
  a Claude model on Chat too: it is for Anthropic only);
- the subscriptions asked through their own clients' APIs: Cursor,
  Devin, Kiro, Qoder, Zed and Command Code's Go plan (attempt).
Untouched: the Claude subscription (its run sends its own, already
without the caller's: withoutBillingHeader), another magpie (it decides
for the provider it picks) and Code Assist, where antigravityTurnsAway
reads the line to explain Antigravity's refusal (#666).

Tests use the reporter's literal block (cc_version=2.1.114.aff;
cc_entrypoint=sdk-cli; cch=…): TestBillingLineLeftOutForVendors sends
two turns differing only in cch through Messages (DeepSeek), Chat
(DeepSeek and a Claude), Responses and Gemini upstreams and requires the
same body without the line; TestBillingLineLeftOutOnCommandCode does it
for Command Code's Go plan and Provider API; TestWithoutBillingLine
covers the system string, the line inside a first block, a system of the
line alone, and mentions that stay. TestBillingLineKeptForClaude and the
existing TestClaudeCodeBodyReachesRelayAsSent require a Claude model's
Messages body unchanged byte for byte. Broken by hand: dropsBillingLine
returning false turns every vendor subtest and the Command Code test red;
the backend strip removed turns the Go plan check red; keepsBillingLine
returning false turns both Claude tests red.

Run: go test -tags nogui ./internal/gateway (whole package), the full
suite under the queue lock, gofmt -l, GOOS=linux and GOOS=windows go vet
-tags nogui ./internal/gateway. Not tried against a real DeepSeek or
Command Code account: the cache-hit numbers are the reporter's.
2026-10-11 19:37:06 +08:00
yetone 15872d977a gui: with the window open, magpie leads Command-Tab's order, so one Command-Tab away and one back returns to it (#1381, ttmouse)
ttmouse on v0.1.1168: open magpie's window, Command-Tab to another app,
Command-Tab back, and magpie is last in the switcher.

Cause: magpie is out of the Dock (Accessory) until the window opens.
With Settings > Dock set to "while the window is open" (or a full-screen
window), the quick panel's focus activates magpie while it is still
Accessory, and it joins the Dock (Regular) after that. An app activated
before it joins stays last in LaunchServices' front-to-back order
(lsappinfo visibleProcessList), which Command-Tab follows, though it is
frontmost. Wails' Focus only calls activateIgnoringOtherApps when the
app isn't active, and calling it again while active is a no-op. setDock
also ran async (dispatch_async), so openMain's Show/Focus could come
before the policy change.

Fix:
- setDock runs on the main thread at once (InvokeSync), so openMain
  joins before it shows the window.
- A pure dockStep(regular, on, active, front) decides the move. Joining
  while already active activates the Dock and then magpie again
  (activateAgain), which puts magpie first in the order. Joining while
  not active just activates it; leaving never re-activates.
- The full-screen join does the same once the window is in full screen
  (DidEnterFullScreen) if magpie was active when it joined.
- Dock "off" (the default) is unchanged: magpie stays out of the Dock
  and out of Command-Tab, by design. The tray panel's behaviour is
  unchanged.
- docs/subsystems/gui-shell.md: Runtime path item 7 for the Dock setting.

Run:
- TestDockStep (table, pure). TestDockJoinLeadsCommandTab (darwin GUI
  build): a real Accessory Wails app activated, then setDock(true,
  true) + window Show/Focus, asserts it is first in lsappinfo's order.
  Red with `again` forced false (front was the test, kitty first in the
  order), green with the fix.
- go test ./internal/gui (GUI build, darwin) passes; full
  go test -tags nogui ./... passes; gofmt -l clean; go vet ./internal/gui
  (darwin) and GOOS=linux / GOOS=windows go vet -tags nogui clean.
- Real build on this Mac, sandbox HOME, own bundle id, port 3481,
  DockWindow on: launched with the quick panel, window opened through the
  Mac's reopen, then two osascript Command-Tabs. Old build: magpie front
  but 11th of 11 in the order (the report). New build: magpie 1st; after
  Command-Tab, the other app 1st and magpie 2nd; Command-Tab again brings
  magpie back. Dock "always": magpie 1st, round trip works. Dock "off":
  stays UIElement, not in the order.

Not tried: the full-screen path in the real build, a human Command-Tab
(only osascript keystrokes), real accounts (not involved).
2026-10-11 19:30:17 +08:00
yetoneandSma1lboy d1f0576a78 gateway: a Claude run kept again leaves its old key, so letting go past idleMost ends instead of spinning with the bridge locked (X, Sma1lboy)
Sma1lboy found magpie at 158 GB after two days with many omp agents on a
Claude subscription, and traced it to keepIdle.

Cause: letGo keeps a run at backKey when the client goes away mid-reply,
and the reply's ended can then keep the same run at the turn after. The
run sat in b.idle under both keys. Past idleMost, the eviction loop picked
that run as oldest on every pass but deleted only run.idleKey (the newer
key, then ""), so len(b.idle) never fell: the loop never ended, held b.mu
(stopping every Claude subscription request) and appended to drop
without bound.

Fix: keeping a run again removes its earlier entry when that entry is
still its own (not a run that replaced it), and the eviction loop deletes
the map key it found as oldest, aborting each run once.

Run: go test -tags nogui ./internal/gateway/ (ok, 396s); gofmt -l clean;
GOOS=linux and GOOS=windows go vet ./internal/gateway clean. The new
TestClaudeIdleRunMoves and TestClaudeIdleEvictionEnds (rekey and stale,
in a child process) fail on the old keepIdle: the child times out in the
loop. Not reproduced with a real two-day omp workload.

Co-authored-by: Sma1lboy <541898146chen@gmail.com>
2026-10-11 19:10:43 +08:00
yetone 85089a2400 gui: a routing group whose plugin lists none of its models no longer blanks the Routing page; it shows as matching nothing, the rest as ever (#1585, dbydd)
The reporter's Routing page showed only "null is not an object
(evaluating 'g.members.map')" and no group, while every group still
routed. A group made of patterns only whose models a provider stops
listing (a plugin behind on updates) has no members, and Go's nil slice
went out of /api/groups as "members": null. groupRow, pickedRow, the
filter and the group editor (inGroups reads every group) all call
members.map/some/flatMap, so one such group threw out the whole list.

- groups.go: groupsState says a group's members as [] when it has none,
  and an unmakeable template's too.
- providers.go: the Gateway's group entries say icons and providers as
  [], never null (app.js gatewayModels joined g.providers).
- routing.js: every /api/groups response goes through groupsFrom, which
  makes each list a list and leaves out an entry that isn't a group;
  drawGroups draws a group that still throws as one flagged row
  ("This group can't be shown: …", zh/zh-TW/ja/de), never the whole list;
  the filter shows such a group rather than throwing.
- app.js: gatewayModels reads null icons/providers as none.

Verified: a probe through provider.SaveGroup({Match: a/m*}) then the
provider listing other models gave "members":null on main; the Go test
TestGroupsNeverNullMembers goes red with groups.go reverted (group and
3 templates null) and green with it. GUI test group-null-members.test.cjs
uses that response's literal bytes: 12/12 red on the old assets, 12/12
green now (Chromium + WebKit, en + zh, 1100 and 420 wide, plus the
Gateway list). gui-de, gui-ja, i18n-keys, group-*, panel-routing,
gateway-model-info and the routing-manual/save/provider-off tests pass
(221/221). Which plugin the reporter has was not asked; the fix covers
any provider whose models a pattern group stops matching.
2026-10-11 18:57:48 +08:00
yetone 76db4c6c28 main, agent: --help on any command or agent only prints its usage, and Snow and Gemini CLI refuse a value they don't know instead of taking magpie out (#1457, blackrion)
`magpie snow --help` printed "✓ Snow CLI model --help" and did what
`magpie snow default` does. It deleted profiles/magpie.json, put back the
active profile, and wrote "--help" as advancedModel into the profile it
went back to. There were two causes:

- run's agent forms took any second argument as a model. The `len(args)==2`
  branch special-cased only `default`.
- Snow's model Set, on magpie's profile, treated a value no profile of the
  user's is on as "leave, and write it into the profile left for".

The arguments were the class, not Snow alone. Under the old code, `magpie
claude --help` and `magpie codex --help` wrote "--help" as Claude Code's
and Codex's model, and `magpie save --help` saved a profile named
"--help" (the new guard test caught each of these).

What changed:
- help_cli.go and run: -h or --help anywhere in the arguments, or help as
  the word after the command, prints that command's usage and returns
  first, before run reads, moves or starts anything. It prints the
  command's own usage where it has one (model, group, group rule, library,
  plugin, quota, sessions, search, visible, webdav, s3, claude-code), its
  lines of magpie's usage otherwise, and for an agent its forms and
  fields. The usage gains a `magpie <command> --help` line.
- `magpie <agent> …` refuses any other argument starting with "-"
  (negative numbers aside): "unknown flag X: nothing was changed".
- snow.go: on magpie's profile, a model that is neither through magpie
  nor any profile's model is refused, and the files stay as they were.
  A `magpie/<x>` that isn't in the catalog is refused on or off magpie's
  profile; it used to fall through to the same leave. A model of one of
  the user's profiles still switches Snow there, and empty still goes
  back to the profile they were on.
- gemini.go, a sibling found by auditing every agent's Set: provider is
  Gemini CLI's first field, so `magpie gemini <a model with no option>`
  reached it. It unrouted Gemini CLI (stashed key, sign-in and model put
  back) and only then said "unknown provider". An auth it doesn't know is
  now refused before unroute. The audit found no other Set that leaves
  on an unknown value. The other model Sets write an unknown value as the
  agent's own model, which is the intended own-model pick. The on/off
  provider fields of ante, claudedesktop, copilotjetbrains, cursorlocal,
  pencil, t3code, workbuddy and zcode take any non-empty value as "on".
  Both are left as they are.
- docs/subsystems/agent-wiring.md says the above.

Tests:
- TestHelpOnEveryCommandDoesNothing reads the commands from run's switch
  in main.go's AST, so a new command is covered without a list to keep.
  It adds every agent id. For each one it runs --help, -h and help in
  several positions under a sandbox home, and checks that nothing is
  written, the run returns within 20s and usage is printed.
- TestAgentHelpLeavesSnowWired is the reporter's case: Snow wired, then
  `snow --help`, `-h`, `help`, `model --help` and `snow-cli --help`,
  unknown flags, and `snow nonsense`. Snow's files must stay the same.
- TestSnowUnknownModelChangesNothing and TestGeminiUnknownAuthChangesNothing
  cover the Sets.

What was run:
- Each test was run against the old code. Old main.go: the save, snow,
  claude and codex subtests FAIL ("✓ saved profile --help" with
  profiles.json written; "✓ Snow CLI model --help"; "✓ Claude Code model
  --help"; "✓ Codex model --help"), and so does TestAgentHelpLeavesSnowWired.
- Old snow.go with old main.go: TestAgentHelpLeavesSnowWired FAILs with
  Snow's files changed, and TestSnowUnknownModelChangesNothing FAILs with
  `"--help" taken`.
- Old gemini.go: TestGeminiUnknownAuthChangesNothing FAILs with
  `"nonsense-model" changed Gemini CLI`.
- All pass with the fix.
- In a sandbox HOME with pinned Go caches, at origin/main 4dd2112ef + this
  change: `go test -tags nogui -timeout 40m ./...` is green (48 packages ok, no FAIL).
- gofmt -l is clean. go vet, GOOS=linux go vet -tags nogui and
  GOOS=windows go vet -tags nogui pass on . and ./internal/agent.
- Not tried: the real Snow CLI on Windows, the reporter's setup. The fix
  returns before anything is read, so nothing of Snow is run.
2026-10-11 15:56:06 +08:00
yetone 642bea3a99 gui, tui, provider: Remote magpie has a heading of its own in the Add sheet, Another computer's magpie, after On this machine, not among the Relays (Avalon on Discord)
Avalon on Discord (v0.1.1168): "供应商添加中没有Remote magpie 的选项". It was
there, filed under Relays (中转), where nobody looks for another computer's
magpie, since it isn't a relay.

The preset is now of its own kind, KindRemote ("remote"), declared after the
local presets. Kind only groups presets for display: the GUI's add sheet,
`magpie presets` and the TUI's add list; makerCatalogs (vendors only) and
the import matcher (skips local) are unchanged for it, as it has no URL.
- GUI: a fourth section after On this machine, "Another computer's magpie"
  / "shared on its network" (zh 另一台电脑上的 magpie / 在它的局域网上共享,
  zh-TW, ja, de too). A preset's note is now also found in the words it is
  shown in, and the zh/zh-TW/ja note begins with 远程/遠端/リモート, so 远程
  finds it as remote and magpie do.
- TUI: the add list says "Remote magpie · another computer's magpie, shared
  on its network" instead of "· relay" (kindNote).
- CLI: `magpie presets` lists it under "another computer's magpie".
- Docs: reference.md, subsystems/providers-accounts.md and the site's
  remote page (en, zh, ja) say where the tile is.

Run:
- remote-magpie.test.cjs gains "Remote magpie has its own heading in the
  add sheet" (420px, en and zh, Chromium and WebKit): the heading and hint,
  right after On this machine, Remote magpie under no other heading, no
  sideways scroll, and remote / magpie / 远程 each find it alone under its
  heading. With the old app.js it fails "no heading of its own" in both
  engines and languages; with only the note search taken out, zh fails on
  远程. Its older test now wheels the sheet to the tile (now the last row;
  a scroll from code is put back by the page's guard, which made it flaky
  in WebKit at 700px): 8 of 8 WebKit runs green.
- TestTUIAddListSaysRemoteMagpieIsAnotherComputers fails on the old note
  with `listed as "Remote magpie · remote"` (and "· relay" before the kind).
- Every GUI test that opens the add sheet (40 files) plus gui-de, gui-ja,
  gui-zh-tw and i18n-keys, in Chromium and WebKit: all pass.
- site worker.test.mjs passes.
- gofmt -l clean; go vet -tags nogui on ., internal/provider, internal/tui,
  internal/gui for darwin, GOOS=linux and GOOS=windows.
- go test -tags nogui -timeout 40m ./... under a temp HOME: all 48 packages ok.
Not tried in the real Wails window.
2026-10-11 15:21:18 +08:00
yetone 1c0eab7c84 gui, gateway: every search API takes a base URL of the user's own, under its key in Settings (#1580, xzhlksh)
The reporter has endpoints that answer as Tavily, Exa and others do, at
addresses that aren't the vendors', and Settings only took a key. The
saved SearchAPI already had a url, and the CLI's url= set it, but the
Settings row showed the field only for SearXNG and sent "" for the rest.

- Settings › Models › Web search: the add row has a base URL field on a
  line of its own under the key, for every API, with the vendor's own
  address as its placeholder (searchVendorJSON.base). Picking an API
  already added fills in its saved URL, so Add with a new key alone keeps
  it; Add with no key typed changes only the URL, the key kept (the key
  placeholder says so). Strings in zh, zh-TW, ja, de.
- provider: check() also refuses a URL with a ?query or #fragment, since
  the vendor's path goes after it.
- gateway: the key goes only to the URL set. Go drops Authorization on a
  redirect to another host but keeps Brave's X-Subscription-Token and
  Exa's x-api-key, so a search API's redirect to another host is not
  followed; the error names where it was sent. The request still goes
  through the gateway's client and so magpie's proxy settings.
- CLI: `magpie search add <api> <key>` keeps the url set before; `url=`
  with nothing after it puts the vendor's own back (was: a new key alone
  dropped the url).
- docs/subsystems/gateway-routing.md: "A search API's base URL";
  gui-shell.md: the field.
- search-api.test.cjs: Settings is drawn twice (/api/state, then
  /api/settings), so scrolling to the add row can hit a detached node
  (WebKit, 1 in ~6 runs here); it retries the scroll.

magpie ships and lists no third-party search endpoint; the URL is only
the user's.

Tests (sandbox HOME, pinned caches):
- TestSearchAPIAtItsOwnBaseURL: an httptest fake at <fake>/relay/<vendor>/
  gets tavily POST /relay/tavily/search with Bearer, exa POST
  /relay/exa/search with x-api-key, brave GET
  /relay/brave/res/v1/web/search with X-Subscription-Token, firecrawl
  POST /relay/firecrawl/v2/search with Bearer. Passes on the old gateway
  too: the backend already honoured a url.
- TestSearchKeyStaysAtItsBaseURL: with search_api.go put back, FAIL
  "a key reached another host: exa-secret / brave-secret".
- TestSearchCLI: with search_cli.go put back, FAIL "a new key took the
  base URL away"; with provider/search_api.go put back, FAIL
  "url=https://x.example.com/?k=1 taken".
- TestSearchAPIBaseURLFromSettings: POST /api/settings/search-api saves,
  keeps the key, refuses ftp/no-scheme/query URLs, lists vendor bases.
- search-api.test.cjs in Chromium and WebKit, en and zh, 980px and
  420px: 8/8; with the old app.js, FAIL "Tavily takes a base URL"
  (false !== true). WebKit 980px 10 runs in a row green after the retry.
  search-first, search-mcp, searcher-pick, i18n-keys, gui-ja, gui-de,
  gui-zh-tw, click-scroll with it: 45/45 in each engine.
- Screenshots at 980/420 in both engines checked by eye.
- go test -tags nogui -timeout 40m ./... on 5fa908c08 + this: all 48 packages ok. gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet -tags nogui on ., internal/gateway, internal/gui, internal/provider: clean.

Not tried against a real third-party endpoint or a real vendor key.
2026-10-11 14:21:29 +08:00
yetone 93c5d846ca plugin: a plugin's requests to a host on the user's own network go direct, as magpie's own do (#1572, ggbdpq)
What changed: with a proxy set (magpie's, the environment's or the
system's), the plugin host sent a plugin's requests for a host on the
user's own network - a Remote magpie, an LLM relay on the NAS - through
that proxy, which can't reach it (502 Bad Gateway) or resolve its name.
Go's netproxy.Func leaves such a host direct since #982 (lan.go onLAN);
host.js's proxyFor and its node:http2 sessions (#1035) were that rule's
siblings without it.

- host.js ports lan.go's rule: onLAN takes a private (10/8, 172.16/12,
  192.168/16, fc00::/7), link-local, loopback or CGNAT (100.64/10)
  address, a .local name, or a name every address of which is one of
  those; looked up for 400 ms at most, kept a minute (256 names), a
  failed or slow lookup is "not on the network". It is asked only when
  the global proxy would be taken (after loopback, a provider's own
  proxy or "direct", and NO_PROXY), as Func asks it, so a user without a
  proxy pays no lookup and a provider's own proxy is still taken as is.
  IPv6 is compared on its bytes, so a v4-mapped address in hex form
  (::ffff:a00:1, how URL writes it) is judged as its IPv4 address.
- http2.connect returns its session at once, so tunnel() now takes a
  promise of the proxy and connects when onLAN has answered: straight to
  the host for one on the user's network, through the CONNECT otherwise.
  Unlike the issue's patch, a LAN name that needs a lookup is covered on
  this path too.
- The issue's patch was reviewed, not applied: its lanIP missed loopback
  and hex v4-mapped IPv6, it didn't strip a trailing dot, it never
  cleared its lookup timer, and it left HTTP/2 to LAN names proxied.

New TestPluginLeavesTheUserNetworkDirect (real Bun, a proxy that keeps
every target it is asked): a fetch to this computer's private address
over http:// (absolute form) and https:// (CONNECT; a certificate for
that address via NODE_EXTRA_CA_CERTS), to "localhost." (a name decided by
what it resolves to), and an HTTP/2 session to the private address all
reach the server directly; a public address (203.0.113.5) and a name that
resolves nowhere (vendor.invalid) still go through the proxy.

Run: the new test against the old host.js fails on all three fetches
(proxy asked for each); with only the HTTP/2 check removed it fails on
the session ("h2: proxyconnect tcp: 502 Bad Gateway"); with every host
taken as LAN it fails on the public address and the vendor name. A bun
check of lanIP over 24 addresses (both sides of every range) matched
lan.go. go test ./internal/plugin ./internal/netproxy ok; full
go test -tags nogui ./... ok in every package (the five whose build
hit another session's go-build cache prune were rerun, all ok: ., agent,
gateway, gui, library); gofmt -l clean; go vet -tags
nogui internal/plugin on darwin, GOOS=linux and GOOS=windows clean.
Not tried with a real NAS or Remote magpie behind a real proxy.
2026-10-11 14:07:21 +08:00
yetone 5fa908c087 gateway, provider: Claude Desktop's requests to ModelScope go on its Responses API, which reports the cache and reasoning that its Chat API leaves out (#1578, sparrowbits)
What changed
- provider.ResponsesTellsCache: ModelScope's API-Inference (the
  "modelscope" preset, or a provider whose Responses URL is
  api-inference.modelscope.cn) with both a Chat and a Responses URL.
  ResponsesFirst is true there for every model, so `usable` puts
  Responses before Chat. A translated request (Claude Desktop / Claude
  Code's /v1/messages, a Gemini client) goes to /responses, and
  Provider.Native wires Pi, omp and droid to Responses. A Chat client's
  request is still relayed on Chat, and Codex's on Responses, as before.
- forwardTranslated: when Responses is first only for the cache report,
  a 404 there marks the model unfit on Responses and asks it on Chat. A
  ModelScope model with no Responses route then works as it did before.
  This fallback is scoped to ResponsesTellsCache.
- docs/subsystems/gateway-routing.md: the "One try" row names it.

Why
The reporter's usage.jsonl covers 202 Claude Desktop requests, all
/v1/messages -> /v1/chat/completions: 0 cache_read over 34.9M input
tokens, and reasoning 0/202. Codex on /v1/responses with the same model,
on the same day, read 94% from cache. Their direct calls show why.
ModelScope's /responses answers
input_tokens_details.cached_tokens = 12288 on the second identical
prompt. Its /chat/completions answers only prompt_tokens /
completion_tokens / total_tokens, though it is served from the same
cache. magpie already maps Chat's prompt_tokens_details.cached_tokens
(and prompt_cache_hit_tokens, cached_tokens, cache_read_input_tokens) to
cache_read_input_tokens (cUsage.usage). The new test
TestOtherChatAndResponsesKeepChat pins that. So the missing figure was
not a mapping gap: ModelScope's Chat API never sends one. The fix is to
ask on the API that does.

Scope: other presets with both Chat and Responses URLs keep Chat.
- DeepSeek, xAI, Zhipu, MiMo, Qianfan, Tencent TokenHub, Volcengine's
  plans, OpenCode Zen/Go, Command Code, PipeLLM and CherryIn have an
  Anthropic URL, so Claude-format requests are relayed on Messages as
  they are.
- Groq's and Volcengine Ark's Chat APIs report
  prompt_tokens_details.cached_tokens, and Groq's Responses API is a
  partial beta.
- OpenAI keeps its existing OpenAI-model rule.
- Nothing is known of a custom relay's Responses API.

What was run
- New tests in internal/gateway/responses_tells_cache_test.go, against
  an httptest fake that answers with the reporter's literal usage
  bodies:
  - TestModelScopeMessagesTellTheCache: streamed and whole Messages go
    to /v1/responses, and the client gets cache_read_input_tokens 12288,
    input_tokens 108 and output_tokens 32.
  - TestModelScopeModelNotOnResponsesGoesToChat: a 404 on Responses
    goes to Chat, and stays on Chat for the next request.
  - TestOtherChatAndResponsesKeepChat
  - TestModelScopeNativeIsResponses
- Broken by hand:
  - Without the ResponsesTellsCache check in ResponsesFirst,
    TestModelScopeMessagesTellTheCache fails ("Messages went to
    [/v1/chat/completions], want /v1/responses"), and so do
    TestModelScopeNativeIsResponses and the fallback test.
  - Without the 404 fallback, TestModelScopeModelNotOnResponsesGoesToChat
    fails with "404 ModelScope: Not Found".
- gofmt -l is clean. go vet, and GOOS=linux and GOOS=windows go vet
  -tags nogui, pass on internal/gateway and internal/provider.
- Full suite: go test -tags nogui ./... under a temp HOME at base 1d016ee3f: rc=0, 48 packages ok.

Not tried
- Not tried against the real ModelScope API: no ModelScope token here.
  The fake is built from the reporter's bodies.
- Which ModelScope models lack a /responses route, and what ModelScope
  answers for them, isn't known. A 404 is assumed; any other error
  reaches the client as ModelScope said it.
- Reasoning is counted from Responses' output_tokens_details, but the
  reporter's excerpt doesn't show that field, so the test doesn't assert
  on it.
2026-10-11 13:46:38 +08:00
yetone f1001ec991 library, gui: each of an MCP server's tools has a switch, and the agents that can leave one out are told to (nf1qaz2w on Discord)
nf1qaz2w asked to turn single tools of a Library MCP server on and off.
6f4fb883e listed each server's tools by name and description; each now
has a switch beside it.

What changed
- Server.DisabledTools keeps the tools turned off, by the names the
  server gives them; ServerTools (POST library/servers/tools) sets them.
  The editor's save sends none, so SaveServer keeps them.
- Each agent given the server that reads a per-tool setting is written
  it in its own form (mcp_tools_off.go, toolsOffOf), checked in source:
  - Codex: [mcp_servers.<name>] disabled_tools (codex-rs/config/src/
    mcp_types.rs, ToolFilter in codex-rs/codex-mcp/src/tools.rs;
    openai/codex cc7ba336)
  - Gemini CLI: excludeTools in the entry (docs/tools/mcp-server.md,
    mcp-client.ts; gemini-cli 9b6e0265)
  - Crush: disabled_tools in the entry (internal/config/config.go
    MCPConfig, filterTools; crush df5b024a)
  - Hermes Agent: tools.exclude in the entry, original names
    (tools/mcp_tool_registration.py, mcp-config-reference.md;
    hermes-agent c5733167)
  - Claude Code: mcp__<server>__<tool> in permissions.deny of
    settings.json (code.claude.com/docs/en/permissions; names spelt as
    Claude Code 2.1.296 normalizes them, [^a-zA-Z0-9_-] -> _)
  - OpenCode: "<server>_<tool>": false in top-level tools of
    opencode.json (docs mcp-servers "Manage"; name() in
    packages/core/src/tool/mcp.ts, migrateTools in config/normalize.ts;
    sst/opencode 0d61729b)
  Every other agent (Cursor, Copilot, Goose, Zed, Kimi, Pi, Grok, Devin,
  Antigravity, Alma, dsh, omp, ZCode, Command Code, Cline, WorkBuddy,
  CodeBuddy, Droid, Claude Desktop, MiMo Code, plugin agents) gets the
  server whole; AgentView.ToolsOff is false for it, and the open tool
  list names those agents as unable to turn off single tools.
- Applied.ToolsOff / Applied.ToolRules record only what magpie added
  (offList): a name, deny rule or tools key the user had is theirs and
  stays when the tool is turned on again; an OpenCode key the user set
  to true is never written over. A list or deny that isn't a list of
  names is a problem and the file is left as it is. The key (and an
  emptied permissions / tools) goes when magpie's were the last.
- GUI: a switch per tool, flipped at once with no repaint or scroll,
  quick clicks sent as one request; turned-off tools dimmed. zh, zh-TW,
  ja, de strings. Project files and Copy config… don't carry it
  (docs/subsystems/library.md says so).

What was run
- go test ./internal/library -run 'ToolsOff|OffList': per format the
  list is written, removed on re-enable, the user's own entries kept
  (Codex, Gemini, Crush, Hermes, Claude deny, OpenCode tools); cursor
  untouched; SaveServer keeps the list. Broken by hand (no off.apply,
  no syncToolRules): TestToolsOffInTheEntry, TestToolsOffClaudeDeny,
  TestToolsOffOpenCode go red.
- go test -tags nogui ./internal/library ./internal/gui: ok.
- library-mcp-tool-switch.test.cjs: chromium and webkit, en/zh/zh-TW/
  ja/de, 980 and 420 wide: pass; 10/10 red against the old library.js,
  library.css and i18n.js. library-mcp-tools.test.cjs' fixture gives
  Claude Code toolsOff (as the real view does).
- library-*.test.cjs, click-scroll, i18n-keys: chromium and webkit.
- gofmt -l; go vet, GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/library ./internal/gui.
- go test -tags nogui ./... (full suite, under the queue lock).
All in sandbox HOMEs; no live agent config was touched.
2026-10-11 13:44:02 +08:00
ggbdpqandfactory-droid[bot] 05cf7814eb gateway: a translated reply cut short reaches a client that asked for no stream as the error too (#1563, ggbdpq)
What changed: every translated request is asked of its upstream as a
stream, and a client that asked for no stream gets its reply assembled
from it. translate read that stream and rendered whatever came as the
whole reply, so an Anthropic upstream that stopped with no stop_reason
and no message_stop, or a Responses one with no response.completed,
handed the client a truncated answer presented as finished — the same
cut a streaming client is told of in its stream (errEndedShort). The
read now watches for the upstream's last event the same way
(upstreamEnds), and ends with the 502 "the reply ended before it was
complete" instead: nothing has been sent, so the next candidate is
asked, and the last one's error reaches the agent. An error the upstream
said still reports itself; a stream that said its last event
(stop_reason, message_stop, response.completed) is served as it came.

Review (yetone's session): with the cut check disabled by hand
TestNonStreamEndedShort fails (both subtests 200 with "Let me look at
the"); restored, green. The 502 takes the same path as the read-error
502 beside it (cutMidReply): nothing written yet, retryable() lets the
next candidate answer, and no account is rested for it as content.
The full suite, gofmt and the cross-OS vets were run on the series.

Author's run: TestNonStreamEndedShort (new; Anthropic and Responses
cases) fails on the old code — both cuts came back 200 with
finish_reason "stop"; with the change both come back 502 naming the
cut, and a reply whose last event came is served 200 whole. gofmt -l
clean; go vet and go build on darwin, linux, windows; go test -tags
nogui -race -count=20 on the relay-stop tests; the full go test -tags
nogui ./... (TestOffline and TestSearchFollowsTheSearchersProxy red on
the clean baseline too).

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-10-11 13:35:56 +08:00
ggbdpqandfactory-droid[bot] e435fe00f1 gateway: a translated Responses reply the upstream cut short ends in an error, not as if whole (#1562, ggbdpq)
What changed: streamTranslated ended a translated reply in "the reply
ended before it was complete" when an Anthropic upstream's stream stopped
with no stop_reason and no message_stop; a Responses upstream's stream
that stopped with no terminal event (no response.completed,
response.incomplete, response.failed) was still finished as if whole, and
the agent's turn ended a few words in with nothing to say why — the same
reply the passthrough already tells apart (sniff.whole, #370). It now
ends in the same error, asked again in place where the upstream goes on
from a prefill, as an Anthropic cut is. The event that ends a stream is
read by its type as the passthrough reads it (upstreamEnds, was
anthropicEnds, already lastEvent), so a response.completed carrying no
status field still counts as the reply's last. Chat (may end without
[DONE] and be whole) and Gemini stay as the passthrough treats them.

Run (review, yetone's session): TestResponsesUpstreamEndedShort passes;
with the Responses half of the end check taken out by hand it fails
("a cut reply finished as whole", finish_reason "stop", no error).
TestRelayStream*, TestRelayStop* ok. The full suite, gofmt and the
cross-OS vets are in the series' last commit.

Author's run: the red/green above, -race -count=20 on the relay-stop
tests, gofmt, go vet and go build on darwin, linux, windows, go test
./... (TestOffline red on the clean baseline too, offline machine).

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-10-11 13:35:56 +08:00
440fded2dc gateway: a turn stopped with its tool call out is answered on Google's APIs, not refused by them (#1560, ggbdpq)
What changed: a client replaying a conversation whose turn was
interrupted with the tool call still out — the call in the history, no
result for it — had every later turn refused by Google's APIs with 400
"Please ensure that the number of function response parts is equal to
the number of function call parts of the function call turn", the
conversation with it, however it was routed: a Google sign-in (Code
Assist), Vertex AI, a custom provider's Gemini URL (#1346) and a model
pinned to Gemini (9e823ad4) all build on buildCodeAssistSent, which
sent the call as it was. The chat build answers such a call with a
synthetic result (pairToolMessages, #1275) and the Responses relay
pairs its items (pairToolItems); the Gemini build now does the same
(pairFunctionTurns). A history whose every call is answered is built
byte for byte as before.

Changed in review (yetone's session): the patch put the synthetic
functionResponse at the head of the next user turn, which is usually
the user's text ("continue"). Since #1533 (ce11b1801, after the
patch's base) Gemini's build never sends a turn mixing a
functionResponse with text, which Vertex AI answers "Requests ending
with a model turn are not supported". The answer now goes beside the
client's own answers when the next turn holds some, and otherwise in a
user turn of its own before the user's words; a Claude model on
Antigravity keeps the one tool_result turn as #1533 does. A call with no
id is no longer answered twice when the client answered it by name. The
fake upstream now also refuses a mixed turn with Vertex's literal 400,
and TestPairFunctionTurnsShapes pins the four placements.

Run (review): the patch as sent, with the stricter fake, FAILS
TestGeminiInterruptedCallIsAnswered and
TestGeminiMessagesClientInterruptedCall with "Requests ending with a
model turn are not supported"; with the rework they pass, and with the
pairFunctionTurns call removed the three interrupted-call tests FAIL
with Google's literal 400 while TestGeminiAnsweredCallsUnchanged
passes. go test -tags nogui -run
'TestGemini|TestVertex|TestCodeAssist|TestAntigravity|TestAgy|TestPairFunction|TestCompact'
./internal/gateway ok. The full suite, gofmt and the cross-OS vets are
in the series' last commit.

Author's run: the four tests red/green as above; -race -count=20; go
test ./... (all ok but internal/testenv TestOffline, offline machine);
gofmt; go vet on darwin, linux, windows; go build on all three.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
Co-authored-by: yetone <yetoneful@gmail.com>
2026-10-11 13:35:56 +08:00
ggbdpqandfactory-droid[bot] fa5ef88d63 gateway: a Chat client's sampling is asked again without it when the Claude it is translated to refuses it by a name magpie can't read (#1559, ggbdpq)
What changed: forwardTranslated's retry loop now answers the
"`temperature` is deprecated for this model" refusal (#1454) the way
passthrough's does: asked once more with temperature and top_p left out.
samplingAsTaken drops the sampling up front only where the model's name
on the wire is one claudeLine reads; a Chat or Responses client's
request to a Claude behind a relay that spells it otherwise carried the
sampling into a 400 that reached the client, where the same request
relayed from an Anthropic client was asked again without it.

Review (yetone's session): the new case fails on the old code (400
"`temperature` is deprecated for this model" reaching the Chat client)
and passes with the retry. The retry is scoped to an Anthropic upstream,
a 400 matching samplingDeprecated and a request that carried sampling,
so it is asked at most once and before anything reached the client; no
account is rested for it. The doc conflict with main's prefill line was
resolved keeping main's line. The full suite, gofmt and the cross-OS
vets were run on the series.

Author's run: the new case "a name magpie can't read is asked again
from chat" red then green; the sampling/thinking/prefill tests ok; go
test -tags nogui ./... ok except internal/testenv TestOffline (offline
machine, red on the baseline too); gofmt -l clean; go vet and go build
on darwin, linux, windows.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-10-11 13:35:56 +08:00
yetone 1d016ee3f3 provider, gui: Token Plan 企业版 shows its usage on the Usage page, read with the account's SecretId and SecretKey (#1574, undirectlookable)
#1574 asks for Tencent Cloud Token Plan's usage on the Usage page through
TokenHub's cloud API (api/1823/132270). That API covers the enterprise
plan only (Token Plan 企业版; the previous commit added its regions). The
personal plan (api.lkeap.cloud.tencent.com/plan) has no usage API, only
the console, so it has no card. The API takes the account's API key, a
SecretId and SecretKey signed TC3-HMAC-SHA256, never the plan's sk- key.

provider (tencent_usage.go):
- A provider at /plan on tokenhub.tencentmaas.com (ap-guangzhou) or
  tokenhub-intl.tencentmaas.com (ap-singapore) with a SecretId and
  SecretKey gets a card per team plan in PlanQuotas
  (tencentPlanQuotas), each key and region asked once.
- It asks DescribeTokenPlanList, then DescribeTokenPlan per plan
  (version 2026-03-22), all at tokenhub.tencentcloudapi.com. Where a
  reply leaves a part out, the list's copy of it is kept.
- The window is TotalUsed of CycleQuota (else TotalQuota), in credits
  (专业套餐) or tokens (轻享套餐, enterprise-auto). It resets at
  TokenSummary.CycleEndTime. Without that, it counts months from
  StartTime and stops at ExpireTime.
- The docs don't say whether TotalUsed is the cycle's or the package's.
  This reads it as the cycle's.
- A plan that isn't enable shows its status beside the plan's name.
- An AuthFailure or UnauthorizedOperation reply says to check the key and
  its CAM rights. No plan visible to the key says so (a sub-user sees
  only the plans it made).
- The SecretId and SecretKey sit in the AccessKeyID and SecretAccessKey
  fields Volcengine's access key uses (#1427). They are stored, kept out
  of key-less backups and dropped from cached cards the same way.
  AccessKeyVendor tells the two vendors apart.

gui:
- The listing tells whose access key a provider or preset takes.
  presetAccessKey lists the regions that take one: Tencent Cloud's two
  Enterprise regions.
- The editor names the fields SecretId and SecretKey, with Tencent's
  hint, and shows them only at those regions (or at an endpoint none of
  the regions has).
- A SecretId with no SecretKey is refused only where the fields are
  shown. The new strings are in zh, zh-TW, ja and de.
- docs/subsystems/providers-accounts.md and the GUI tests README describe
  it.

Run:
- TestTC3SignMatchesDoc pins the signing doc's worked example (payload
  hash 35e9c5b0…, Signature 10b1a37a…).
- TestTencentPlanRegion, TestTencentPlanWindow and TestTencentPlanQuotas
  use the API docs' own response examples. The last is an httptest fake
  that rechecks each TC3 signature and the X-TC-* headers, and fails if
  the plan's key is ever sent.
- TestProviderListTellsTencentAccessKey covers the listing, alongside
  TestVolc* and TestPlanQuotas.
- Breaking the action's lowercasing in the signature, or dropping
  TokenSummary, turns them red.
- GUI: tencent-access-key.test.cjs (new) 12/12 in Chromium and WebKit at
  420px, en and zh. It goes red with the region hook or the vendor
  labels taken out. volc-access-key, tencent-cloud, i18n-keys, gui-ja
  and gui-de pass.
- gofmt; go vet on darwin, linux and windows; the full go test ./...

Not tried against the real API: we have no Tencent Cloud account. What
is read is what the docs show, and the reporter is asked to try it.
2026-10-11 13:06:28 +08:00
yetone 47269f448f usage, gateway, gui: the Requests card counts requests once, a try handed on to the next isn't a failure, and says how many were answered on a retry (小一 on Discord)
小一's Codex-on-credits ledger read "5,482 · 1,094 failed" while many rows
said "2 tries/3 tries" and had been answered. "Failed" counted usage rows,
not requests: besides each request's final row, the gateway writes a row
for every try a vendor refused or turned away (hw.refused/hw.turnedAway),
and each of those was counted as a call and a failure even when a later
member answered. (Ordinary failovers write no row; 499 cancels and the
agent's own client-side retries are separate requests.) In the owner's own
usage.jsonl, 24 of the 71 "failed" rows were such refusals a later member
answered.

Now a request counts once, by how it ended:
- usage.Record gains `tries` (final row, when the route took more than one)
  and `handed_on` (the row of a try that failed and handed the request on).
  Totals.count skips handed-on rows; a failure is a request whose agent got
  an error (LostRequest); one answered after a failed try is Totals.Retried
  (RetriedRequest), with a `retried=1` filter.
- Logs written before this are read the same way: the log index marks a
  failed, non-rejected row followed by another of the same route id as
  handed on and raises the later row's tries (routeRows); the packed row
  and its snapshot carry both.
- Panel card, Usage overview tile, ledger card, rankings and group rows,
  `magpie usage` and the TUI say "N answered on a retry"; the CSV adds
  `tries` and `handed_on` at the end. A row says "· handed on" (with why
  in its title) or "· N tries".
- On the ledger's Requests card "N failed" and "N answered on a retry" are
  buttons that switch the list to the Failed / new Retried filter, and back
  when pressed again. The lines wrap rather than cut a button off (German).
  zh, zh-TW, ja, de strings added.
- Docs: reference.md (counting, filter, CSV columns), gateway-routing.md.

Run:
- go test -tags nogui ./internal/usage ./internal/usageapi ./internal/tui
  ./internal/gateway . : ok. New TestRequestsCountedOnceWithTheirRetries
  (JSONL fixture: legacy refused row + 200, handed_on + 200 tries 3, 502
  tries 2, plain 200, routeless 429 → 5 calls, 2 failed, 2 retried, across
  Ledger, QueryPage, Summarize, heatmap, filters, CSV) and
  TestRetriedRequestCountsOnce (group a refuses, b 500s, c answers → 1
  call, 0 errors, 1 retried; a lone 400 → 1 error).
- Broke each by hand (count without the HandedOn skip, gateway without
  HandedOn, log index without routeRows): each test went red; restored.
- go test -tags nogui -timeout 40m ./... under the gotest lock, rebased on origin/main de1ba9f12: all ok
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on ., the
  usage, usageapi, tui, gateway and gui packages: clean.
- Playwright ledger-retried.test.cjs, Chromium and WebKit, en zh zh-TW ja
  de, 420 and 1100 wide: 20/20 (German first failed on the cut-off line,
  fixed by letting the button lines wrap). usage-*, api-key-usage,
  purpose-filter (Failed is now the 2nd of 3 options), panel-usage,
  click-scroll, request-archive-usage, both engines: all green except
  purpose-filter's Routing case (1px focus scroll), which fails the same
  on 909d76747 and de1ba9f12, in Chromium too; it is #1291 (commented)
2026-10-11 12:58:03 +08:00
yetone 310991d78f gui: a group with measured replies and floors shows both, the measured speed first, "125 tok/s (1) · ≥50 tok/s (259)" (Fallmonkey on Discord)
A group's speed showed its measured speed when it had one and dropped
its floors. With the commits before this one, a Codex model can have
one measured reply and hundreds of floors, and "125 tok/s (1)" stood
for all of them. Fallmonkey asked to see both.

ledGroupSpeed now joins the two, the measured one first:
"125 tok/s (1) · ≥50 tok/s (259)". Its tooltip has a line for each,
and the measured line drops "the others tell no speed" when the others
tell a floor (new strings in zh, zh-TW, ja and de). The Output speed
card keeps the measured speed as its figure, so a narrow card isn't
clipped, and puts the floor in its sub line. A ranking by speed still
orders and bars a group by its measured speed, or by its floor when it
has none. docs/reference.md says so.

Tests: usage-speed-count.test.cjs adds floors to sol and a new
measured-only group (astra, 62). It checks the joined text and the two
tooltip lines, the card's figure and sub line, and the ranking order
and bar, in en, zh, zh-TW, ja and de, in Chromium and WebKit, at 1400
and 560 px, with no clipping. It fails on the old app.js.

Ran: usage-speed-count, usage-session-speed, usage-ledger-detail,
usage-speed, reasoning-speed, usage-ledger-fit, usage-model-at-provider,
routing-request-metrics, gui-ja, gui-de, gui-zh-tw and i18n-keys in
both engines; go test ./internal/gui; gofmt -l; GOOS=linux/windows go
vet.
2026-10-11 12:49:27 +08:00
yetone e5b82cf38a usage, gui: Codex rows tell the least they wrote at: a call in a turn of several over its whole time, a turn of one call that reasoned by its answer after the first token (Fallmonkey on Discord)
Codex's session rows told no floor. A call in a turn of several could be
timed from inside itself; the commit before this one times it from what
asked for it, before its first output item, to its last, as Claude Code's
is. So Codex joins usage.FloorAgents and app.js's LED_FLOOR_AGENTS, and
such a call tells its output over its whole time, by the same 1,000-token
rule. On 622 stripped recent rollouts only 4 of 1,367 such calls have
1,000 tokens or more, so the floors will be few, but they are true.

A Codex turn of one call that reasoned has its first token (the turn's
time_to_first_token_ms) but not its first text, so DecodeOf tells no
speed. Fallmonkey asked for its whole output, reasoning too, over the
time after the first token. That reads high: OpenAI's reasoning is
written before the first content, so it isn't in that time. On a gateway
reply of 496 tokens, 224 of them reasoning, 827 ms after a 10.2 s first
token, that is 600 tok/s against a measured answer speed of 415 (the
bug e6dd5d20b fixed). Instead the answer, its output less the reasoning,
which all came after the first token, over that time: 329, a true floor
of the answer's speed. Any size tells one, as the wait isn't in it;
DecodeWindow's bounds still hold. The Requests row's tooltip says so, and
a group's floor tooltip now says the file doesn't say when the answer
began, true of both kinds, in en, zh, zh-TW, ja and de.

The 1,000-token rule stays (Fallmonkey asked for 5 s instead): it bounds
the share of the time the wait for the first token can be, which a
duration doesn't (a 5 s reply can be 4 s of wait). On the owner's
gateway rows, where both are known, a floor of 1,000 tokens or more read
0.40 of the measured speed (n=25), one of 5 s or more 0.18 (n=550). The
reason is in Row.Floor's comment and docs/reference.md.

Tests: TestCodexRowsTellAFloor (new) and TestGroupSpeedSaysHowManyRepliesItIsOf
(sol's 259 calls in turns of several now tell 259 floors at 50) fail on
the old ledger.go. usage-speed-count.test.cjs gains a turn-of-several row
(≥50) and the 496/224 row (≥329, its tooltip) and fails on the old app.js;
usage-session-speed.test.cjs's Codex row now tells its floor.

Ran: go test ./internal/usage ./internal/gui; usage-speed-count,
usage-session-speed, usage-ledger-detail, usage-speed, reasoning-speed,
usage-ledger-fit, usage-model-at-provider, routing-request-metrics,
gui-ja, gui-de, gui-zh-tw and i18n-keys in Chromium and WebKit, at 1400
and 560 px; gofmt -l; GOOS=linux/windows go vet.
2026-10-11 12:49:27 +08:00
yetone de1ba9f123 settings, gui: a masking rule can be edited in place, not only removed (nf1qaz2w on Discord)
nf1qaz2w on Discord: "自定义脱敏规则现在只有移除,能否增加一个编辑功能方便调整规则".
Settings → Privacy listed each custom masking rule with Remove only, so
changing a pattern meant removing it and typing it again at the end.

Each rule's row now has Edit beside Remove. Edit opens the rule in its own
row, where it stands, with its name, Prefix/Regex (the app's segs, no
<select>) and match filled in, laid out like the add row; a narrow window
puts the match, Save and Cancel on a line under the name and Prefix/Regex.
Save (or Enter) sends that one rule to the new POST
/api/settings/redact-rule with its index and its current value;
editRedactRule tidies and checks it with redact.CheckRules as an added rule
is, and refuses one that doesn't compile, matches the empty string, is left
with no prefix or pattern, repeats another rule, or is no longer at that
index (changed or removed meanwhile). A refusal is said in the row in red,
what was typed kept, and every rule stays as it was. Cancel or Escape
leaves the rule untouched and sends nothing. The gateway reads the rules
from settings per request (redactionOptions), so the edit masks the next
request. The two fixed refusals are translated (zh, zh-TW, ja, de); the
other strings (Edit, Save, Cancel, Name, Prefix, Regex) were already there.
docs/subsystems/gateway-routing.md now describes the user's own rules and
the edit.

Run:
- TestRedactRuleEdit (internal/gui): a valid edit is saved in place and
  redact.Mask with the saved rules follows it; a bad regex, a pattern that
  matches nothing, a short prefix, an empty rule, a duplicate, an index out
  of range, a negative one and a stale "was" are each refused with the
  reason, the rules unchanged. With api.go from before this change it fails:
  "edit: 404 404 page not found".
- internal/gui/tests/redact-rule-edit.test.cjs: Chromium and WebKit, en, zh,
  zh-TW, ja, de, 1100px and 420px (20 tests, all pass): Edit opens the rule
  in its place with its values, fields don't overlap and stay in the row,
  the page doesn't scroll sideways, no click moves the page, Cancel sends
  nothing, a refused regex is shown with the typed values kept, a good one
  is saved by Enter in the same place. With the old app.js it fails: no
  button.rule-edit (locator timeout). redact-rule-row.test.cjs and
  i18n-keys.test.cjs pass.
- Whole GUI suite in both engines, under heavy machine load: 5647 of 5667
  pass. Each failing file was run again alone: agent-expand-steady,
  azure-endpoint, balance-currencies, gateway-key-groups,
  library-desktop-skills, library-all, plain-names, purpose-filter and
  usage-ledger pass. skill-install-agents-all (chromium 420px "view:5,0")
  failed the same on the base commit and passes after rebasing onto
  afe0c59d. routing-keys-fold fails in webkit only under load; alone it
  passes 3x on this tree and on the base.
- After the rebase: redact-rule-edit, redact-rule-row, i18n-keys,
  skill-install-agents-all and click-scroll pass (79/79).
- gofmt -l, go vet, GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/gui: clean. go test -tags nogui ./... under a sandbox HOME:
  green (48 packages ok, no FAIL); after rebasing onto afe0c59d,
  ./internal/gui, ./internal/redact and ./internal/settings pass again.
2026-10-11 12:41:00 +08:00
yetone afe0c59d2d gui: on a Mac window a popover that opens upward stops under the traffic lights, not over them (#1573, lyston11)
In a short Mac window, Pick (an agent's model list), the field picker
(#pop) and every app menu (placeMenu) were held only 8px from the top
when they opened upward or were held to the window's top, so they
covered the traffic lights and header.top, which the system draws them
over.

popTop(pad) is now the highest a popover's top edge may go: 8px under
header.top's measured bottom on a Mac window (so it follows --zoom), and
8px from the top everywhere else, as before. openAgentModels, placePop
and placeMenu use it in place of pad for the top. placePop also holds
#pop's max-height to the room between that edge and the foot when its
CSS max-height doesn't fit, so a picker held to the top scrolls inside
itself instead of running off the bottom (it already did run off before
this change in a very short window; moving the edge down would have
made that worse). Nothing else clamps a popover to the top: the
remaining getBoundingClientRect placements (profiles in the panel, the
heat-map tip, the rail tip) are kept inside their own card or panel.

Run:
- new internal/gui/tests/popover-mac-chrome.test.cjs: Chromium and
  WebKit, en and zh, MacIntel and Win32, 480px wide: 8/8 pass, 4 runs in
  a row. On the old app.js it fails (model list top 8 < 58 on Mac, the
  picker off the bottom on Windows). Breaking each placer by hand turns
  it red on its own: model list top 8, picker top 8, menu top 17.
- related GUI tests, Chromium and WebKit, all pass: click-scroll,
  agent-models, agent-models-picker, -all-hidden, -loading, -only-picked,
  -redraw, agent-model-groups, menu-scroll, proto-menu-overflow,
  codex-app-menu-cap, desktop-model-menu, editor-short-window,
  removed-groups-menu-scroll, agent-start-pick, agent-leave-magpie,
  claude-picker-fold, header-zoom-fit, header-centre, text-size.
- HOME=<scratch> go test -tags nogui ./internal/gui: ok.
- GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gui: ok.
2026-10-11 12:32:32 +08:00
yetone 9bb68615b0 gui: a scroll not the reader's made just before a click is put back, not kept as where the reader was (#1554)
skill-install-agents-all.test.cjs was red on main in Chromium at 420px
(en, ja, de): the install picker's All chip, clicked, left the Library
view 5px down.

Cause: the browser tells the page of a scroll at the next frame. The test
clicks while the Library view is still sliding in (view-in, translateY
5px), and Playwright's click scrolls the chip into view first; with the
view 5px taller than it is high at 420px, that scroll takes the view to
its 5px foot. The click came in before that scroll's event, so the click
guard took its snapshot (held.chain, held.top) at 5px and every hold()
after kept it there, the scroll event included. A real click can do the
same: WebKit scrolls a field focused on the press, or code scrolls just
before the click, and the scroll was adopted as the reader's.

Fix (app.js, the click guard): before taking a click's snapshot, a view
not scrolled by the reader (no purposeUntil window, no scrollbar drag)
is put back where the reader left it (backToReader), as the scroll
listener would have done a frame later. A click in quick turn after
another still holds that one first, as before.

The guard is shared by every view, so every picker and button is covered;
the library picker needs no change of its own (the MCP editor's picker is
in #modal, outside any view).

Tests:
- click-scroll.test.cjs: new "a scroll the page hears of after the click
  is still put back" (scrollTop += 40 and a click in one task). Red on the
  old app.js in Chromium and WebKit (expected 2020, actual 2060), green
  with the fix.
- sessions-manage-paging.test.cjs scrolled with Playwright's
  scrollIntoViewIfNeeded and clicked Show more before the next frame, so
  it passed in Chromium only through this bug (the guard puts that scroll
  back a frame later; it was red in WebKit on main). It now scrolls with
  the reader's wheel; green in both engines.
- docs/subsystems/gui-shell.md says a click is taken where the reader
  left the view.

Run: skill-install-agents-all.test.cjs red before (en/ja/de 420px,
"view:5,0"), green after in Chromium and WebKit, every language;
click-scroll.test.cjs green in both engines; 306 GUI test files that
assert on scrolling or touch the library/skills/MCP, then the other 253,
both engines. Failures seen there were rerun alone: purpose-filter (WebKit,
1px, #1291) and search-api (WebKit zh, #1442) fail the same on the old
app.js; the rest pass alone. No Go changed.
2026-10-11 12:14:35 +08:00
yetone 909d767472 gui: with MAGPIE_PUBLIC_URL set, Gateway's Connect starts at it until the user picks an address, and magpie web shows it as the gateway's address (#1551, everpcpc)
everpcpc runs magpie web in Docker behind a reverse proxy with
MAGPIE_PUBLIC_URL=https://magpie.example.com. The page is opened from
other machines, yet Connect's Base URL, the copied shell/curl/Python/Node
snippets and the gateway's address on the Gateway page started at
http://127.0.0.1:3425. v0.1.1174 kept a picked address; the public one
still had to be picked once on every browser.

- /api/providers' gateway carries publicURL: MAGPIE_PUBLIC_URL when it is
  among the addresses Connect offers (shared, or MAGPIE_ADDR on the
  network). With no address kept in magpie.connectAddress, Connect starts
  there, so the snippets and the gateway key picked for it follow. An
  address the user picked, this computer's included, still wins.
- The option is labelled "Public address" instead of "Local network".
- /api/settings carries publicURL under the same condition, and Settings >
  About lists it beside the local Gateway URL, which stays the address
  agents here are pointed at.
- In magpie web, a page served to other machines, the Gateway page's
  address and Settings' web-search MCP server show the public URL; in the
  app they stay local. Agents' own config wiring is unchanged (#373).
- New strings in zh, zh-TW, ja, de; docs/reference.md says where it shows.

Run: public-url-default.test.cjs (new) on chromium and webkit, en, zh,
zh-TW, ja, de, at 1100 and 420 wide, 26 pass; on the old app.js 12 of 13
chromium cases fail. Making the public URL override a kept pick turns it
red too. TestPublicURLInConsole and the new TestPublicURLOnlyWhereOffered
pass. Sibling GUI tests (connect-address-kept, the gateway-key-* and
gateway-connect/caller-keys tests, api-key-theme, public-url, lan-docker,
phone-web, search-mcp, settings-sections/groups, gui-ja/de/zh-tw): 192
pass; phone-web failed once under the parallel run and passes alone on
both engines. gofmt, GOOS=linux and GOOS=windows go vet -tags nogui
./internal/gui, go test -tags nogui ./... under the queue lock: its one red
is TestAccountDiscoveryOffReadsNoSignIn (internal/provider, from 8c5b9f928),
which fails on main without this change too (1 in ~20 runs alone).

Found on the way, not changed here: in magpie web at phone width, an
open Connect menu closes at once (a scroll of #view-gateway right after
it opens), with or without MAGPIE_PUBLIC_URL.
2026-10-11 11:04:21 +08:00
yetone 4ee491e7c7 provider: a routing group shared as text leaves out its rules by folder, which name the sharer's own paths
ae70d8eac (folder rules) landed beside 3f5702421 (sharing a group): a
rule's Folders are paths on the sharer's machine, so Copy to share would
have carried their project names, and on another machine they mean
nothing. ShareGroup leaves those rules out; ImportGroup leaves out one
pasted anyway and counts it with the rules left out.

Run: go test -tags nogui ./internal/provider ./internal/gui -run
'Shared|GroupShare'; with the share-side strip removed by hand
TestSharedGroupRoundTrip goes red on the folder in the text; go vet.
2026-10-11 10:44:28 +08:00
yetone 3f57024211 provider, gui: a routing group is shared as text and imported into another magpie (laincatx on X)
A group row's menu has Copy to share: the group as JSON marked
"magpie": "routing-group" with a format version (provider.ShareGroup),
holding its members as it names them, patterns, routing, rules,
classifier and settings. A group holds provider/model ids only, so no
key, account or address goes with it; derived matches and the
found/hidden/off flags stay behind.

The Routing page's Import (by New group) opens a box the text is pasted
into, words or a code fence around it allowed. POST /api/groups/import
(provider.ImportGroup) adds it under a free name, never over a group.
A member whose provider the importer has is kept; else the same model
under one of their providers (listed as used instead); else it is left
out and listed, with the rules that send to it and its off/fast place;
a classifier gone takes the intent rules and auto effort. Nothing is
added when no member is left. Other text, a newer format or none is
refused in the reader's language (provider.ShareError, code "share").

Run:
- go test -tags nogui ./... (gateway failed once on a full disk, then
  passed alone); new TestSharedGroupRoundTrip/MissingMembers/BadText and
  TestGroupShareAndImport; the version check broken by hand turns them red
- gofmt -l; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build
- group-share.test.cjs in chromium and webkit, en/zh/zh-TW/ja/de, 420px;
  every group-*, settings-groups, filter-ime, panel-routing GUI test
  (210 pass); routing-* (550/557: webkit fold tests timed out only under
  --test-concurrency=6 and pass alone; a webkit routing-* run under the
  same load fails one test on origin/main too, a different one each run)
- real use: the owner's 12 groups from a sandbox copy of providers.json
  each shared (no key in the text) and imported back whole
2026-10-11 10:33:45 +08:00
yetone ae70d8eac8 routing: a group's rule can hold by the folder the agent works in (Cario0x on X)
Cario0x on X asked to route by the project being worked on. A group's rule now has a
"folders" condition: it matches when the request's working folder is one of the listed
folders or inside one. It combines (AND) with the existing conditions: tokens, images,
intent, time, agents and quota.

- gateway/workdir.go reads the folder each agent states in its own request:
  - Claude Code: "Primary working directory", including "(was …)" after a move.
  - Codex: <environment_context><cwd>.
  - Pi: <cwd>.
  - OpenCode: <env> "Working directory".
  The last one stated wins. Assistant text and tool results are ignored. A request
  that states no folder matches no folder rule: unknown, never empty.
- provider/rulefolder.go matches a folder only at a path boundary.
  - ~ is the home folder.
  - C:\x is the same folder as /mnt/c/x, and \\wsl$\Distro\x as /x.
  - Case is ignored on macOS and Windows, and always for a drive.
  - A rule's folder must be a whole path. Pause rules can't have folders.
- The trace's RuleHit.Folder makes the Routing page say "The agent works in …".
- GUI: an "in folder" condition in the group editor, hidden on pause rules. Strings in
  zh, zh-TW, ja and de.
- CLI: `magpie group rule add … folders=~/oss,"~/My Project"`. The TUI shows the
  condition.
- Docs: docs/subsystems/gateway-routing.md and site start.html (en, zh, ja).

Fixtures are real requests from Claude Code 2.1.296, Codex 0.162.0 and Pi 1.1.0, run in
a sandbox from a folder named "a&b <c> 中文" or "My Proj", with the sandbox path
replaced.

Run at this head:
- go test ./... green.
- gofmt -l clean.
- go vet green for darwin, GOOS=linux -tags nogui and GOOS=windows.
- GUI routing-folder.test.cjs: chromium and webkit, en, zh, zh-TW, ja and de, 1100px
  and 390px (no horizontal scroll). It fails on the old routing.js.
- Related routing, group and i18n GUI tests: 85/85.
- Full GUI suite: 5611/5631 under --test-concurrency=6. Rerun alone, every failure
  passes except:
  - skill-install-agents-all (chromium, 420px), which is red on origin/main too: #1554.
  - The menu-scroll track flake, which flakes on main as well: #1550.
- e2e: a sandbox HOME, a dev build and fake upstreams, with real Claude Code 2.1.296
  (`claude -p --model group/fd`).
  - From proj/acme/web, rule 1 matched and the request went to kb.
  - From proj/acme-old, no rule matched and the request went to ka. The trace and UI
    showed the folder.
2026-10-11 10:17:16 +08:00
yetone 3964ea656c usage, gui: a group's speed says how many replies it is of, "125 tok/s (1)", and one with only floors says "≥100 tok/s (30)" (Fallmonkey on Discord)
Fallmonkey: the Usage ranking and the Output speed card showed
gpt-6.1-sol's tok/s from the one reply of its 260 that used no tool (the
only Codex turn its session file times) beside "260 requests", while
Claude Code, whose Requests rows say "≥N tok/s" by the dozen since
0192edf1, showed none. Asked for one rule for every source: measured
replies give "N tok/s (k)", only floors give "≥N tok/s (k)", neither
gives nothing.

usage.Totals now counts DecodeN, the replies its DecodeMs/DecodeOut are
of (add and addRow), and FloorOut/FloorMs/FloorN, the floors of rows read
from Claude Code's and Claude Desktop's session files (Row.Floor, the
same rule as app.js's ledFloorSpeed: source "log", not failed, no
measured speed, 1,000+ tokens over 1 s+, under 10,000 tok/s). Floors are
never in Speed(); the Speed trend and `magpie usage` are unchanged.
app.js's ledGroupSpeed applies the rule to the ranking's rows (main page
and tray panel; the "Other" row sums the new fields), the Output speed
card and the overview's agent/model lists, with a tooltip saying which
it is and how many replies; a ranking by speed orders and bars a
floor-only group by its floor. Strings in en, zh, zh-TW, ja, de;
docs/reference.md says the rule.

Run: TestGroupSpeedSaysHowManyRepliesItIsOf (sol 260 calls, 1 measured
at 125 tok/s; Claude Code 42 calls, 30 floors at 100, a short, a failed
and a gateway row telling none; the page sums; summarize) fails to build
on the old code and goes red with the agent check taken out of
Row.Floor. usage-speed-count.test.cjs (overview, Requests rows, ranking
by tokens and by speed with order, titles and bars, the card for all and
for Claude Code's model alone, no clipping, no sideways scroll) passes in
Chromium and WebKit, en/zh/zh-TW/ja/de at 1400 and 560 px, and fails
against origin/main's assets. Related GUI suites (click-scroll, gui-de,
gui-ja, gui-zh-tw, i18n-keys, ledger-*, panel-usage, reasoning-speed,
routing-burst-speed, usage-*): 389/389 in both engines. go test -tags
nogui ./... (temp HOME) passes; gofmt -l clean; go vet nogui for darwin,
linux and windows on internal/usage and internal/gui. Not tried with
Fallmonkey's own data.
2026-10-11 10:04:15 +08:00
yetone 6f4fb883eb library, gui: an MCP server's tools are listed by name and description (nf1qaz2w on Discord)
nf1qaz2w on Discord: "mcp现在好像只能看到有几个工具,看不到具体的工具名和描述等,
能否支持下?" The Library's MCP check kept only len(tools) from tools/list.

What changed:
- internal/library/mcp_check.go: ServerHealth carries ToolList (json
  "toolList"): each tool's name and the first paragraph of its
  description, whitespace collapsed and cut at 500 runes (a tool with only
  a title gets the title); names cut at 128; at most 500 tools kept while
  Tools still counts all. tools/list is now asked through listTools, shared
  by the stdio, streamable HTTP and SSE checks: it follows nextCursor up to
  10 pages, each page with a step budget of its own (the #1467 per-step
  timeout), and a page after the first that is refused ends the list there.
  Before, nextCursor was ignored and only the first page counted.
- internal/gui/assets/library.js/.css: a server whose check listed tools
  shows a chevron on its "N tools" status; a click opens the list under the
  row (name in the code font, description under it, "N more not shown" when
  magpie kept fewer than the server has, and Check again). Clicking the
  count again shuts it. A server with no listed tools keeps the old click,
  which checks it again. The list stays while it is checked again, no
  editor opens, no left-border stripe, no native select. The click guard
  keeps the clicked status in place (a centred row gives up 1px as it
  grows).
- i18n: "Click to see them", "Click to hide them", "{n} more not shown" in
  zh, zh-TW, ja, de.
- docs/subsystems/library.md: the check's tool list and paging.
There is no CLI/TUI output of a server's check, so nothing changed there.

What was run:
- go test ./internal/library: TestCheckKeepsToolNames runs the check on the
  tools/list reply @modelcontextprotocol/server-filesystem really gave
  (captured with npx, testdata/filesystem-tools-list.json, 14 tools, the
  longest description 457 chars); TestCheckToolPages (no description, title
  only, a 1000-char description cut, two pages by nextCursor, the JSON the
  page reads); TestCheckToolPagesEnd (a server that pages forever is asked
  10 times). With the list not kept and paging off, the first two fail:
  "got {State:ok Tools:14 ToolList:[] ...}, want ok with 14 tools, each
  listed" and "...Tools:3 ToolList:[]..., want ok with 4 tools over 2 pages".
- GUI: internal/gui/tests/library-mcp-tools.test.cjs, Chromium and WebKit,
  en/zh/zh-TW/ja/de, at 980 and 420 wide: 20/20 pass; against the old
  library.js it fails. library-*.test.cjs, mcp-signin, search-mcp,
  i18n-keys and click-scroll in both engines: 377/377 pass.
- gofmt -l (nothing), go vet / GOOS=linux / GOOS=windows go vet -tags nogui
  on internal/library and internal/gui, go build for darwin, linux and
  windows (nogui). Full go test -tags nogui ./... under the queue lock:
  every package ok but internal/provider, where TestClaudeSavedAccountDir
  failed "sign-in never finished" (waitDone's 2s bound on a fake claude
  process under full-suite load); alone it passes 5/5. Not touched here.
2026-10-11 09:24:07 +08:00