Commit Graph
2027 Commits
Author SHA1 Message Date
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
yetone 1c9747f611 usage: a Remote magpie provider's gateway keys each show their own limit, used and left, period and reset on the Usage page (#1547, PennyVibe)
A computer that uses another magpie through gateway keys that magpie gave
it saw the other magpie's subscription cards, but not what each key may
still spend there.

What changed:
- provider/remote_key_limits.go: each key of a remote-magpie provider
  gets a section on one card, "<remote>/~keys", read from the remote's
  existing GET /v1/magpie/limit asked with that key alone (the endpoint
  answers only the calling key, from access.Caller; nothing in the
  request picks another key, so a key never sees another's numbers).
  A window per cap (tokens, spend) named for its period (today / this
  week / this month / this cycle), used against the cap, with its
  reset; SubscriptionQuota.GatewayKey carries what is left, calls, the
  cycle's days, used up and unpriced calls. A key with no limit shows
  one "Limit: Unlimited" window. Kept for remoteCardsFor like the
  remote's cards; the card's refresh reads the named key again.
- A failed read keeps the last numbers, dated (AsOf); with nothing read
  the section says why, never zero and never "no limit". A remote from
  before /v1/magpie/limit (404) says it is too old to tell.
- GUI: the card is named "Gateway keys · <remote>" (main page and the
  tray panel), a line under each key says the cycle, calls and "used
  up", and the two new errors are said plainly; strings in zh, zh-TW,
  ja, de.
- magpie quota (CLI) shows the same cards; a window with no cap now
  reads "Limit unlimited" there, not "Limit 0%" (quotaCell).
- docs: providers-accounts (Allowance), gateway-routing (Remote magpie
  APIs, verification), reference (/v1/magpie/limit).

Run:
- New tests fail on the old code: TestRemoteMagpieKeyLimits (provider)
  and TestRemoteMagpieKeyLimitCards (gateway, a real Handler, real chat
  requests moving the numbers) with the key cards taken out of
  RemoteCards; usage-remote-key-limits.test.cjs on HEAD's app.js.
  TestKeyLimitTellsOnlyTheCaller guards what was already so (key A can't
  read key B by query, header or no key from the LAN), so it passes on
  both. TestQuotaCell's unlimited case reads "Limit 0%" on the old code.
- provider, gateway -count=3; go test -tags nogui ./... (full suite).
- GUI: the new test in chromium and webkit x en/zh/zh-TW/ja/de x
  900/400px (20 pass); the whole GUI suite.
- gofmt -l clean; go vet -tags nogui darwin, linux, windows.
- Real two-magpie run, both this build, sandbox HOMEs, 127.0.0.1:38461
  (remote) and :38471 (local); the upstream was a fake OpenAI server
  (fixed 175 tokens a reply). Remote keys laptop (1000 tokens/day), desk
  (5000/week), spare (no limit); local "office" Remote magpie with all
  three, routing rotate. After 17 chats through the local gateway,
  magpie quota on the local read laptop 1050/1000 (100%), desk
  1050/5000 (21%), spare unlimited (in --json; the text line read
  "Limit 0%", which the quotaCell change above fixes), matching the remote's own
  gateway-key list; laptop's spent key was passed over (every chat
  200). With the remote stopped each key said it couldn't be reached,
  never 0. Not run against a real vendor, nor a real magpie older than
  /v1/magpie/limit (unit-tested with a 404).
2026-10-11 09:10:44 +08:00
yetone 26816de2f9 library, agentplug: an agent a plugin adds is given the Library's instructions, MCP servers and skills where its agent.library says (AlmarionAI on X)
Agent plugins wired models and keys only: library.targetOf had no case
for them, so the Library's instructions, MCP servers and skills never
reached an agent a plugin adds, while the announcement said the
Library carries over.

An agent export can now say
  library: { instructions, mcp, mcpFormat, skills }
each a path (~ and $VAR expanded, as config is). mcpFormat names the
agent whose MCP file it is shaped like (agentplug.MCPFormats: claude,
codex, gemini, opencode, cursor, zed, ... 18 of the library's
mcpFormats). A format outside the list, or an mcp without one, keeps
the plugin from loading. library.pluginTarget makes such an agent a
Target, so it is written as any agent is: magpie's marker block in the
instructions file, servers merged beside the user's own (their fields
kept), skills linked or copied, Applied recording only magpie's part,
backups kept. Takes refuses a place the plugin doesn't name, and says
which agent.library key would give it.

Docs: docs/subsystems/library.md and agent-wiring.md; plugins.html
(en, zh, ja) gets the library field and what magpie does with it.

Run:
- internal/library/agent_plugin_test.go: TestPluginAgentGetsTheLibrary,
  TestPluginAgentWithoutAPlaceIsRefused, TestPluginAgentMCPFormat,
  TestPluginMCPFormatsAreWritten. With targetOf's plugin case and the
  check() validation taken out by hand, the first three go red.
- e2e: a nogui build in a scratchpad HOME (env -i, no live configs),
  `magpie plugin add` of a throwaway toy agent plugin; `library
  instructions set/agents`, `library mcp add/rm` wrote and took back
  only magpie's block and server, the user's "mine" server, its "note"
  field and other keys kept, backups made; with mcp dropped from the
  plugin, `library mcp add ... agents=toy` is refused naming
  agent.library.mcp.
- go test -tags nogui ./... (one unrelated FIFO flake in internal/agent,
  fixed in the commit before), gofmt -l clean, go vet for GOOS=linux
  and GOOS=windows clean. No GUI code changed.
2026-10-11 07:55:23 +08:00
yetone 6b8dc4cdd8 proc, agent: magpie finds an agent CLI under the Node nvm's default names, not the folder whose name sorts last (v9 after v22)
proc.UserPath added "the newest-looking" nvm Node to magpie's PATH, the
last folder of ~/.nvm/versions/node/*/bin in string order. That isn't
the Node a terminal gets, and string order puts v9.11.2 after v22.12.0
and v22.3.0 after v22.12.0. So magpie could find, run and update a
codex/claude/gemini under a Node the user's terminal doesn't use (found
while answering 悠悠哥 on Discord, 9f407cafa). UserBinDirs (FindTool,
the Codex executable, nodeHere) took every version in reverse name
order, with the same flaw.

Now (internal/proc/nodever_other.go) the nvm folder is $NVM_DIR or
~/.nvm, and its default is resolved as nvm.sh does on load (nvm_auto
use -> nvm_resolve_local_alias default, read from nvm v0.40.3's
source): alias/default and each alias it names in turn (lts/* ->
lts/jod -> v22.x, lts/-N as nvm_normalize_lts counts it, user aliases),
a cycle being none; node/stable the highest installed; a partial
version (22, v20, 22.3) the highest installed it starts; an exact one
when its bin/node is installed. UserPath adds that one; with no usable
default (unset, not installed, cycle, iojs/unstable) the highest
version by number; with "system" none of nvm's, since the terminal then
runs the system Node. UserBinDirs lists the default first, then the
rest highest first.

Siblings:
- mise's installs and fnm's node-versions (UserBinDirs only) were in
  reverse name order too: now by number, fnm's aliases/default first
  (and $FNM_DIR looked in). mise's active Node is reached through its
  shims, which come earlier.
- volta, asdf and mise shims, and n (one copy in /usr/local/bin), pick
  the version themselves: no change.
- Windows (path_windows.go) lists no per-version folder: nvm-windows'
  current Node is its NVM_SYMLINK on the registry PATH. No change.
- The WSL probe's wslbin (internal/agent/wsl.go) globbed
  "$HOME"/.nvm/versions/node/*/bin, first in name order (v18 before the
  default v22). It now asks nvm itself (nvm.sh sourced by bash with
  --no-use, nvm_version default), then the rest highest first.
- NVM_DIR and FNM_DIR join agentenv.Vars: test sandboxes clear them, and
  UserPath takes them from the login shell like the agents' variables.

Run: TestUserPathNvmDefault (15 real nvm layouts: v9 vs v22, lts/*,
lts/iron, lts/-1, 22, v20, exact v9, node, stable, a user alias, a
default not installed, lts/* naming a line not installed, a cycle,
system direct and through an alias), TestFindToolNvmDefaultFirst,
TestUserPathNvmDir, TestUserBinDirsFnmMise, TestWSLProbeNvmDefault.
With the old path_other.go 14 of the 15 nvm cases go red (v9.11.2
picked; the exact-v9 default passes), as do the other three; with the
default ignored by hand 9 go red; with the old probe line all 3 WSL
cases go red. Cross-checked nvmDefault against
nvm v0.40.3's own nvm_version default on 19 alias layouts: same version
each time (nvm says N/A where magpie falls back, and N/A for system
with no system node). The new probe run with the real nvm.sh under
/bin/sh and /bin/dash resolved lts/*, lts/iron and 18 right. go test
./internal/proc ./internal/agent ./internal/agentenv ./internal/provider
./internal/testenv; full go test -tags nogui ./...; gofmt -l; go vet,
GOOS=linux and GOOS=windows go vet -tags nogui on the touched packages.
All under a temp HOME; no real ~/.nvm read.
2026-10-11 06:41:06 +08:00
yetone 8c5b9f928d provider, agent, gui: subscription accounts can be turned off, and then no agent's sign-in is read (#1535, MaxHaiCom)
What changed: Settings → Privacy → Subscription accounts (On/Off),
`magpie accounts discovery [on|off]` and MAGPIE_NO_ACCOUNTS=1 turn off
account discovery. It stays on by default. While it is off, magpie reads
none of the agents' sign-ins: ~/.claude/.credentials.json, .claude.json's
account, ~/.codex/auth.json, Copilot's, Cursor's, Devin's, Kiro's,
Gemini's, ZCode's, Command Code's and OpenCode's files. It runs no
`security` / `secret-tool` for the Keychain or Secret Service, and asks no
agent CLI who is signed in. It serves no subscription. API-key providers,
middleware plugins and Pi extensions work as before.

Why: the reporter runs magpie on machines where reading other tools'
credentials isn't wanted. The owner delegated the call.

How: settings.NoAccountDiscovery (kept per computer by KeepOwn) and
settings.AccountDiscoveryOff(). The variable only ever turns discovery
off. The gates sit at every reader (readAccountFile, discoveryOff) and at
every route that reads or writes a sign-in, so a route that skips
Accounts still reads nothing:
- Accounts, All, Logins, usage, renewal, warm-up, session identities,
  check-ins;
- switching, forgetting, SetLoginOn, StartSignIn, the imports;
- moves onto plugins.
The ones that write refuse with an error that names how to turn it back
on. On the agent side, Agent.Source and OpenCode's auth.json are gated,
and Codex wiring goes by magpie's stash instead of auth.json, so a
toggle never rewires Codex. logins.json and plugin-auth.json are left
untouched and serve again when discovery is turned back on. A change
applies at once (ForgetAccounts).

Docs: providers-accounts.md, README (en, zh-CN), and the site's CLI table
(en, zh, ja).

Run:
- TestAccountDiscoveryOffReadsNoSignIn (provider) and
  TestAccountDiscoveryOffAgentsReadNoSignIn (agent). Every credential
  path is a FIFO that records each open, and security, secret-tool,
  claude, codex, cursor-agent, devin, kiro-cli, copilot and grok are fakes
  on PATH. Both fail with the gate removed: they show the opens and
  `security find-generic-password -s Claude Code-credentials`, among
  others. Both pass with the gate in place.
- TestAccountDiscoverySetting and TestAccountsDiscoveryCmd.
- account-discovery.test.cjs: chromium and webkit, 900 and 360 wide,
  en/zh/zh-TW/ja/de, 32/32. The neighbouring privacy, redact,
  settings-sections and i18n-keys GUI tests: 49/49.
- The full `go test -tags nogui ./...`, gofmt -l, and go vet for darwin,
  linux and windows on the touched packages.

Not tried: a real machine under fs_usage, and Linux and Windows at
runtime. The FIFO tests are !windows.
2026-10-11 06:38:40 +08:00
yetoneandTed Li 0192edf133 gui: a long Claude Code reply read from its session file shows the least it wrote at (≥98 tok/s), and a short one no longer says it wasn't streamed (Fallmonkey on Discord)
Claude Code's session file has no first token, only when the line that
asked for a reply and its last line were written, so every Claude Code and
Claude Desktop call that didn't go through the gateway showed no speed,
with "Not streamed" though it was streamed. A reply of 1,000 output tokens
or more over a second or more now shows its tokens over that whole time as
a floor (ledFloorSpeed, "≥" in the cell, "At least: …" in its tooltip and
the row's details); the wait for the first token is inside it, so the
speed after the first token is never under it. Gateway rows and timed
session rows are unchanged, and the period's speed counts timed calls only.

Only Claude Code's and Claude Desktop's rows tell one. The contributed
version gave every session-file row a floor; a Codex call in a turn of
several is timed from the last tool output before its token count, and in
a month of real rollouts (4,588 multi-call calls) 2,968 were timed from the
output of a tool that same call asked for, written before its count, so
the window begins inside the call and a floor from it could read high.
Those rows keep "—" with "The session file has no first token". OpenCode's
created→completed time isn't checked against real sessions, so it tells
none either.

Checked against the shape of real Claude Code files (read-only, 30 days,
~198k messages, 2,011 files incl. subagents): block lines are stamped at
each block's end (single-line 1,000+ token text replies read a median 110
tok/s, not the thousands a start stamp would give); no sidechain lines in
main files; no assistant line out of clock order; a message's later lines
keep the time its first was asked (Began), so the 15,779 tool results
written between one message's blocks don't shorten it. Floors shown: 23,518,
p50 102, p99 141, max 156 tok/s for claude-opus-5-5.

Run: usage-session-speed.test.cjs (now also a Codex multi-call row, a
Claude Desktop row, and a 560px window) in Chromium and WebKit, en and zh;
red with the agent check taken out ('≥500 tok/s' !== '—'). The related
suites (gui-de/ja/zh-tw, i18n-keys, ledger-*, usage-ledger*, usage-speed,
reasoning-speed, routing-burst-speed, usage-ttft-rounding,
usage-computers): 146/146 in both engines. go test -tags nogui ./...,
gofmt, and go vet for darwin/linux/windows on internal/gui.

Co-authored-by: Ted Li <tl2493@columbia.edu>
2026-10-11 06:27:17 +08:00
yetone 9f407cafa1 agent, gui: an agent CLI found off the terminal's PATH says where it is (悠悠哥 on Discord)
悠悠哥 (macOS) saw "Codex 0.162.1 · 未接入" under 未设置 on the Agents
page while `which -a codex` found nothing and ~/.codex wasn't there.
Detected() is true when the agent's command is on magpie's own PATH, and
proc.UserPath adds to it the folders users' tools go in (~/.local/bin,
npm's prefixes, nvm's newest Node, bun, volta, pnpm, Homebrew), which a
desktop app launched from the Finder needs. A codex left in one of those
that the terminal's PATH no longer has (an npm install under a Node nvm
no longer uses) is found, runs, and gives its version, so the row looked
made up. Reproduced in a sandbox HOME: PATH=/usr/bin:/bin, no ~/.codex,
@openai/codex 0.162.1 under ~/.nvm/versions/node/v22.12.0; after
UserPath, Codex is detected with CLI 0.162.1. ChatGPT.app's bundled codex
(Contents/Resources/codex-cli, 0.162.0-alpha here) is never on magpie's
PATH and isn't what was found.

The agent is still listed: the CLI is real and runs (a lazy-loaded nvm
leaves the same folder off a login shell's PATH while the user does run
codex from it). What changes is that it says so. CLI gains path (the
file magpie runs) and offPath (its folder isn't in proc.LoginPath; false
when the login PATH can't be told, or for a CLI found at a fixed path
rather than through PATH). The Agents row shows "Not on your terminal's
PATH" after the version, its tip and the version's naming the file and
that it can be deleted if left from an uninstall; en/zh/zh-TW/ja/de. The
note gives way at the narrow width, where the version's tip still says
it. docs/subsystems/agent-wiring.md says how detection and the note work.

Run: TestCLIFoundOffTerminalPath (red with OffPath forced false);
agent-cli-offpath.test.cjs in Chromium and WebKit, five languages, 560
and 440px (16 failures on the old app.js), with agent-app-version,
agent-cli-missing, cli-update and agent-update-all (66 pass); go test
./internal/agent ./internal/gui; full go test -tags nogui ./...; gofmt;
GOOS=linux and GOOS=windows go vet -tags nogui on both packages.
2026-10-11 06:03:05 +08:00
yetone cb25d3861b gateway: a Claude subscription's tool calls reach their run on a MAGPIE_ADDR that isn't loopback (#1546, jiayeZhu)
With MAGPIE_ADDR pinned to a concrete address outside 127/8 and gateway
keys on, the Claude subscription bridge's MCP helper posted its tool
calls to http://<that address>/_magpie/claude-mcp/<token> with no key.
lanGuard answered 401, the call never reached the run, and every turn
of tool results found "no run waiting" and started a new Claude Code
told the whole conversation; the reporter's cache hits fell from ~95%
to ~30%.

- lanGuard lets that callback in by its run's own token: a POST to
  /_magpie/claude-mcp/<token> whose token (24 random bytes) is one a
  live run registered (addCallback in startRun, dropCallback in
  removeRun), compared in constant time. No path is exempt on its own:
  an unknown, ended, truncated, extended, percent-encoded or GET form
  is still asked for a key, and so is every other route.
- The helper is handed the callback URL in a 0600 file in the run's
  own temp dir rather than as an argument; RunMCP reads a path as that
  file. The test fakes read it from there.
- docs: claude-subscription-bridge, gateway-routing's HTTP surface and
  reference.md's network section say how the callback is let in.

Run:
- TestClaudeToolCallbackOnANonLoopbackAddress (new): a gateway behind
  lanGuard on this machine's own non-loopback IP, MAGPIE_ADDR set to
  it, fake Claude Code making a real helper call; red on the old guard
  with the reporter's "refused POST /_magpie/claude-mcp/... no API key
  was sent" line, green now.
- TestOnlyALiveRunsCallbackSkipsTheKey (new) and
  TestNetworkGatewayGuardsEveryRoute (now also tried with a live run's
  token as a Bearer key): red with a blanket path exemption put in by
  hand, green now.
- Real use: sandbox HOME, magpie serve on MAGPIE_ADDR=10.0.0.111:3561
  with a gateway key, a fake claude driving the real claude-mcp-helper.
  origin/main: callback refused, "tool results no run waiting", a new
  Claude Code told the whole conversation. This build: the result
  reached the same process (pid unchanged), nothing refused, a made-up
  token still 401.
- go test -tags nogui ./... (full suite), gofmt -l, GOOS=linux and
  GOOS=windows go vet -tags nogui on internal/gateway and
  internal/claudebridge.
2026-10-11 05:50:04 +08:00
yetone 6536982756 edit: an agent's config saved with a UTF-8 BOM is edited through it and keeps it — magpie claude <model> no longer says "invalid JSON/JSONC" (#1534, AnxForever)
On Windows, PowerShell 5.1's `Set-Content -Encoding UTF8`, Notepad and
Claude Code channel switchers save ~/.claude/settings.json with a UTF-8
BOM in front. Claude Code reads such a file; magpie's JSON layer handed
the BOM to json.Valid and gjson, so `magpie claude <model>` failed with
"<path>: invalid JSON/JSONC" and the agent couldn't be wired at all. TOML
refused the same with "UTF-8 BOM is not supported", though Codex's own
parser (toml_parser's lexer) skips a BOM, and env/YAML files glued the BOM
to their first key's name.

The fix is at the package's two choke points, so every format and every
caller of edit.Read gets it:
- edit.Read returns the file without a leading BOM (the agent package's
  own readers, Claude Desktop, Ante, Empryo, Snow, Pi MCP etc. go through
  it).
- WriteAtomic puts the BOM back when the file it replaces starts with one
  and the new bytes don't (keepBOM). The user's file keeps the encoding it
  was saved in: the tools that wrote it may expect it, and the agent read
  it with the mark before, so keeping it is the user's own bytes, not a
  guess. A file without a BOM never gets one; an emptied file stays empty.
  This is what astrbot.go already did for AstrBot's cmd_config.json.
- PatchJSON (bytes in, bytes out) reads through and keeps a BOM too.
- The TOML "BOM is not supported" error is gone with the case it named.
- Siblings read outside edit.Read: Claude Code's settings.json and CC
  Switch's legacy config.json in the importer, and Crush's provider list,
  trim it with the new edit.TrimBOM.
- Prime Agent's Disconnect (beforeMagpie.restore, on main since this
  work began) compares the file with its copy from before through the
  BOM, so a BOM'd settings.json is put back byte for byte and the copy
  removed; it used to stay as magpie left it, the copy beside it.

The reporter's fork commit (AnxForever/magpie 0bb750c1) was reviewed: it
trimmed the BOM in the seven JSON entry points and wrote the file back
without it; this change keeps the BOM instead and covers TOML, YAML, env
and the readers outside the JSON layer.

Run:
- New tests built on a Windows-shaped settings.json (BOM + CRLF + the
  user's env and permissions): TestJSONSettingsWithBOM, TestPatchJSONKeepsBOM,
  TestJSONItemWithBOM, TestTOMLConfigWithBOM, TestEnvAndYAMLWithBOM fail on
  the old code ("invalid JSON/JSONC", nothing found) and pass; with keepBOM
  disabled by hand four of them go red. TestWriteAtomicAddsNoBOM.
  TestPrimeAgentRoundTripWithBOM fails on main (not put back) and passes.
  TestClaudeConfigDirImport (BOM case) and TestImportCCSwitchConfigWithBOM
  fail on the old importer ("invalid character 'ï'") and pass.
- Full chain in a sandbox HOME: old binary `magpie claude
  deepseek/deepseek-flash` on a BOM'd settings.json -> "invalid
  JSON/JSONC"; new binary -> "✓ Claude Code model", BOM and CRLF kept, the
  user's env untouched; `magpie claude model default` after it leaves no
  blank line. Old `magpie codex gpt-5.5` on a BOM'd config.toml -> "UTF-8
  BOM is not supported"; new -> set, BOM kept.
- Windows box: the edit package's test binary passes whole; magpie.exe
  `claude deepseek/deepseek-flash` on a settings.json written by
  PowerShell 5.1 Set-Content -Encoding UTF8 (sandboxed USERPROFILE/APPDATA)
  sets the model and keeps ef bb bf.
- go test -tags nogui ./internal/edit ./internal/agent ./internal/provider
  ./internal/library; gofmt -l; go vet (darwin, GOOS=linux, GOOS=windows)
  on the touched packages; the full suite.
2026-10-11 05:43:45 +08:00
yetone 7c632ad0b4 lessons: 10-10/10-11 review; tests ending with their test and timing room move to the code standards
The nightly review of 10-10 13:51 to 10-11 05:20 (191 commits,
v0.1.1155 to v0.1.1172, every tag on a green run).

- Two lessons hit a third day and move into docs/code-standards.md:
  whatever a test starts ends when it does (#1524's three-step fix), and a
  timing test leaves room on both sides (TestMaxRPM was a real gap).
- "A failed read means unknown" seen again: stash.json had readLogins'
  bug (fixed in 270b5257), and StepCode copied a strict reader instead.
- "A test never loads a real page" gains f04792f9: a test's broken state
  must not reach the network either.
- New: a test reading a dependency's source (884dbdb2), a "gone"
  substring check matching generated text (6c099edd).
- Flaky tests: four reds shipped past unfiled; "same on main" against a
  stale main (db965824); two sessions on one flake again.

Ran: every cited sha checked with git cat-file; docs only, no code.
2026-10-11 05:26:14 +08:00
yetoneandump45nose 26ddb0d62f gateway: a tool-call id a client shortened goes to Gemini unsigned, not as a corrupt thought signature (#1536, jueda12)
Gemini 3's thought signature rides in the call id magpie gives the
client (<id>__ts__<base64url>). A client that caps ids (40 characters
in the report) sends back part of it, and unpadded base64 only rejects
a length that is 1 mod 4, so at three of four lengths unsignedID decoded
the leftover into a partial signature. Gemini answered it with 400
"Corrupted thought signature" instead of the call going with
skip_thought_signature_validator.

The mark now carries the signature's length: <id>__ts<n>__<sig> and
<id>__tsr<n>__<text>. unsignedID reads the first mark; a length that
doesn't match what is left, or a mark cut inside its digits, is no
signature, and the id stays as the client sent it. Ids from earlier
versions (__ts__, __tsr__, no length) are still read as before.

Every path that takes a signature off an id goes through unsignedID:
the Chat relay (chatCallSignatures), unsignCalls for translated
requests (Chat, Gemini, Code Assist/Antigravity, Vertex), and
geminiParts. The anthropic mp_ id wrapper already checks its round
trip, so a cut one is left alone.

Tests: realistic ids (Gemini's function-call-N and magpie's
call_<newID>, with vertexCallSig, a 315-byte signature as measured in
the report, and a non-canonical one) cut at every length carry no
signature; through chatCallSignatures, buildChat, buildCodeAssist and
geminiParts each cut sends skip or nothing; the reporter's 40-character
cut through the gateway reaches Gemini as skip; old-format ids still
read. All four new tests fail on the old code.

Run: go test -tags nogui ./... (full suite, under the queue lock),
gofmt -l, GOOS=linux and GOOS=windows go vet -tags nogui
./internal/gateway.

ump45nose posted the same root cause and an equivalent fix on #1536
(fork commit 415e45f2, `__tsn__<len>_` marks). Its handling matched
this one case for case; the two literal old-form ids from its test are
taken into TestOldSignedIDsStillRead.

Co-authored-by: ump45nose <52391318+ump45nose@users.noreply.github.com>
2026-10-11 05:10:50 +08:00
yetone 814a5ed73c agent: dsh asks each of magpie's models on its own API, a route per protocol (01huadalang on Discord)
dsh's llm-pi-ai sets one api for a whole route, so magpie's single
"magpie" route asked every model over Chat Completions. A GPT served on
Responses, or a Claude served on Messages, was translated from Chat, and
its sealed reasoning was lost between tool calls. 01huadalang asked for a
group per protocol.

What changed:
- dshPutRoute writes up to three routes from each model's catalog APIs
  (dshRouteOf): magpie (openai-completions, as before, for Chat models,
  Gemini-native ones, groups and agent-bridged sign-ins),
  magpie-responses (openai-responses, gateway /v1) and magpie-anthropic
  (anthropic-messages, the gateway root, forceAdaptiveThinking where
  gateway.AdaptiveThinking). A route left with no models is taken out.
  An api the user picked for a route in dsh's Models page is kept, and so
  are keys they added to it.
- The start (agent-default-model) names its model's route on a pick, an
  effort change, and the home layer's mirror. Sync moves a start on one of
  magpie's routes to the route its model is now on (dshStartOnItsRoute),
  keeping its mark, effort and other keys. A start on the user's own
  route stays.
- dshCheck checks each route's baseURL against its own api, and asks the
  route the start names to list its model.
- Disconnect, dshOurs, dshKeepPick and dshFillNewProfiles know all three
  routes. sessions' dshGatewayProvider counts dsh sessions on any of
  them as magpie's.
- docs/subsystems/agent-wiring.md: a line on the routes.

Known limit: a dsh session resumed on a model that has since moved
routes asks for the model to be picked again once, since dsh finds a
model by route and id.

Run:
- go test -tags nogui ./internal/agent (whole package, default order)
  and ./internal/sessions -run TestDsh: pass. New tests
  TestDshRoutesAModelOnItsNativeAPI,
  TestDshSyncMovesAStartToItsModelsRoute,
  TestDshCheckSaysAStartOnAnotherRoutesModel and
  TestDshGatewayProviderTakesEveryRouteOfMagpies. With dshRouteOf forced
  back to the single route, the three agent tests go red.
- Real dsh (headless, sandbox HOME and DSH_HOME) on patches magpie wrote,
  pointed at a fake gateway: the start on magpie answered from
  /v1/chat/completions, the one on magpie-responses from /v1/responses
  (reasoning.effort high), and the one on magpie-anthropic sent
  /v1/messages with thinking adaptive and output_config.effort high. dsh
  accepted all three routes. Its Anthropic turn then ended on my fake's
  SSE, not on the wiring.
- gofmt -l clean. go vet -tags nogui for darwin, GOOS=linux and
  GOOS=windows on internal/agent and internal/sessions.
2026-10-11 04:52:26 +08:00
yetone 99fcddeeba usage: the Requests tab, its filters and refresh, the charts, the TUI and magpie usage answer at once over a long history (Vantiboo1ean)
Vantiboo1ean (Discord, macOS M2, v0.1.1157) has ~750,000 requests in
usage.jsonl. On Usage > Requests every filter, model pick and refresh
spun forever and the page never updated.

Reproduced in a sandbox HOME with 750k generated records in the real
format (400 MB usage.jsonl, ~84k sessions), on magpie web and in process.
The cause: the #563 budget dropped the index's blocks once they passed
24 MB (60 MB here), so every read, of any period, parsed the whole file
again (6 s CPU) and priced every call again; All took 12 s of CPU, the
heatmap 13 s, and the page read both at once.

What changed:
- log_index: the gateway's blocks are always kept (about 80 bytes a call,
  S2-compressed instead of flate); the file is parsed once, then only
  what was appended.
- block_price: the gateway's blocks are priced per query, once per set of
  provider/model/served/effort names rather than per call, into pooled
  buffers; range loops go by pointer (a packed row is 264 bytes).
- request_page: pages are always cached (16 at most), session-file chunks
  stay in the budget, and a page asked again while it is worked out (the
  refresh button, the timer) waits for that one instead of starting a
  second scan.
- Siblings that read the same history:
  - The heatmap names each day once.
  - A day filter no longer allocates per call.
  - The ledger behind the TUI, magpie usage, the CSV export and sync
    (LedgerOf, OwnDays) reads the gateway's calls from the index instead
    of Load parsing the whole file.
  - Direct/Summaries matches the session files' calls against the index's
    blocks without pricing all 750k gateway calls.
  - A summary of more than 1024 sessions is now cached with its top 1024
    (it was not cached at all). The Usage page's /api/usage gets the top
    100 (it was sent all 84k, 19 MB, which it never draws) plus a new
    sessionCount. /v1/magpie/usage still lists every session, and magpie
    usage says "top 10 of <sessionCount>".

Timings, CPU (the box was at load 130-190 on 14 cores, so wall is
inflated; min of repeated runs), before -> after:
  Requests today            6.0 s  -> 20 ms
  Requests 7d               5.8 s  -> 93 ms
  Requests 30d              ~6 s   -> 362 ms
  Requests all              12.4 s -> 2.4 s first, ~8 ms again
  all, model filter         12.3 s -> 1.5 s
  all, agent filter         11.3 s -> 1.8 s
  30d, search "opus"        6.7 s  -> 353 ms
  day filter                6.0 s  -> ~0.1 s
  heatmap                   13.7 s -> ~2.3 s first
  summary today / all       6.0 / 9.2 s -> 25 ms / 1.6 s first, <1 ms again
  /api/usage?period=all     1.6 s + 19 MB JSON each time -> <1 ms, 53 KB
  TUI Summaries(all)        ~8.5 s (Load + ledger) -> 1.1 s first, <1 ms again
  TUI Summaries(today)      ~6 s   -> 29 ms
  Visit 7d (budget, codex)  5.9 s  -> 10 ms
The first read of the file after start costs ~5 s of CPU, once.

Tests (each seen red with its guarantee broken by hand):
- TestUsageOverBudgetHistoryIsReadOnce
- TestUsageSessionChunksStayInBudget
- TestUsageOverBudgetPageIsCached
- TestUsagePageAskedTwiceIsWorkedOutOnce
- TestUsageLedgerReadsTheIndexNotTheFile
- TestUsageLargeSummaryIsCompleteAndKeptTrimmed (was ...ButNotCached)
- TestDirectCountsOnlySessionFileCalls, now with a request-id match,
  checks that Direct/Summaries equal the ledger's.

Run: go test -tags nogui ./... (temp HOME), gofmt -l, GOOS=linux and
GOOS=windows go vet on the touched packages.
2026-10-11 04:44:13 +08:00
yetone 7a9cf4dd4d gui, provider: Detect APIs and Each picked model ask with the form as it stands before any Save, and say what is missing in place (#1545, thedavidweng)
What the user saw: on a custom provider being added (or a Duplicate not
added yet), "Each picked model" said "Pick models first" although models
were typed in the Models field, and on a relay with no model list "Detect
APIs" said "no model to try" on every API. Both worked only after a Save,
when the models became the provider's own. A Duplicate not added sent no
key at all. Hints for a missing URL or models went to the toast at the top.

Why: chosenIds() reads a saved provider's chips only, not a new one's
draft.extra; Detect picked its model from the saved provider's list or the
vendor's, never from the form; an unsaved copy posted no id, so the server
had no key to fill in.

What changed:
- provider.Detect takes the form's picks (picked ...string) and tries one
  of them per API before the saved list or the vendor's.
- /api/provider/detect takes `picked`, and for `new` + `copyOf` fills
  what the draft left empty from the copied provider, as a saved edit
  fills from its id. It still only reads: nothing is written, no provider
  is added, no route or health check changes. No new route; magpie web's
  key guard is the same.
- detectAPIs sends the add form's models (draft.extra) for a new
  provider, copyOf for an unsaved copy, and says a missing URL, missing
  models, a refusal, and "none answered, and no API key is typed" inline
  under the buttons (amber/red text, no border). One new string in zh,
  zh-TW, ja, de.
- docs/subsystems/providers-accounts.md: the detection row says so.

What was run:
- TestProviderDetectDraft (new): new draft with picked models on a relay
  with no list, Each picked model, saved provider with a masked key and an
  unsaved pick, an unsaved copy with no key typed and with a key typed,
  config folder bytes unchanged, provider.All unchanged, magpie web without
  its key -> 401 and the vendor never asked. Fails on the old detect.go /
  providers.go ("no model to try").
- provider-detect-draft.test.cjs (new): chromium + webkit, en/zh/zh-TW/ja/
  de, 900 and 360px, 20/20 pass; no scroll on click, no <select>, no
  left-border, no sideways scroll, nothing but detect posted. Fails on the
  old app.js (no inline hint).
- provider-detect, provider-detect-models, provider-add-models,
  duplicate-pause, i18n-keys: 29/29, both engines.
- go test -tags nogui ./internal/gui/ ./internal/provider/ ok; gofmt -l
  clean; GOOS=linux and GOOS=windows go vet -tags nogui ok.
- Real use: sandbox `magpie web` (nogui build) with a fake upstream. New
  provider, relay with no model list: Detect APIs and Each picked model
  answered with the typed key and models, no providers.json written. Saved
  provider with its key masked plus a model typed in its add box: both
  asked with the saved key. Duplicate not added: asked with the copied
  key. providers.json bytes unchanged. Without the web key: 401, the
  upstream got nothing.
2026-10-11 04:43:43 +08:00
yetone 9c11abbd00 agent: jcode is an agent magpie connects: a magpie profile with magpie's models, jcode started on the one picked (wani on Discord)
wani asked on Discord for jcode (1jehuang/jcode, a coding agent in Rust)
as an agent magpie connects. There was no earlier request in issues or
history.

What changed:
- internal/agent/jcode.go: a new agent for jcode's config.toml in
  $JCODE_HOME, else ~/.jcode (jcode-storage's jcode_dir). Detected by the
  file, the folder, or `jcode` on PATH.
  - Connecting adds a named profile, [providers.magpie], with the keys
    `jcode provider add` writes: type "openai-compatible", the gateway's
    /v1, an inline api_key naming jcode (magpie-jcode; jcode's requests
    carry nothing else that tells it apart) and requires_api_key = true.
    Without that key, jcode sends no key to a loopback base URL.
  - Its models list has one entry per model of magpie's: context_window
    (128000 when magpie doesn't know it; jcode would assume 200k), input
    text/image, and reasoning = true for a model with effort levels, so
    jcode's /effort offers them.
  - It sets [provider] default_provider = "magpie" and default_model, the
    model picked. What was there is stashed, and Disconnect puts it back.
  - Picking a model of jcode's own while it is on magpie takes magpie
    out: the profile goes and the user's provider comes back with that
    model.
  - Each key is set alone, so the user's other keys and tables stay, as
    do their own keys in magpie's profile (headers, extra_body) and a
    reasoning_effort they set on one of its models while the model has
    that level.
  - jcode writes a profile's models as [[providers.magpie.models]]
    tables when it rewrites the file itself (Config::save,
    to_string_pretty). Those are replaced by the one list.
  - A sync with nothing to change doesn't write.
  - Disconnect drops the profile whole, sub-tables included.
  - Check says when the profile is gone while jcode still starts on it,
    or when its base_url or key is off.
  - While jcode runs, the notice says to restart open jcode sessions,
    since it reads the file when it starts. The notice is a newNotice
    template, translated in i18n.js (zh-CN, zh-TW, ja, de) and listed in
    NOTICES, as TestEveryNoticeIsTranslated asks.
- agents.go, agentenv.go: registers it; JCODE_HOME joins the agent env.
- icons/jcode.svg: jcode's halftone mark (jcode.sh/favicon.svg) as a
  mask icon, every other dot of its lattice.
- docs/reference.md, docs/subsystems/agent-wiring.md, README.md,
  README.zh-CN.md: jcode's row and its place in the agent list.
- WSL isn't covered: jcodeAt reads the place's home and JCODE_HOME, but
  it isn't added to the WSL agent list (another session has wsl.go open).

What was run:
- go test -tags nogui ./internal/agent -run '^TestJcode'. The fixture is
  the bytes jcode 0.94.0 wrote for `jcode provider add`. The tests went
  red when, by hand, I:
  - made a no-op sync write;
  - dropped the user's reasoning_effort;
  - skipped the stash, so Disconnect wasn't byte-identical;
  - left jcode's [[providers.magpie.models]] tables in, which makes
    invalid TOML;
  - dropped requires_api_key.
- Real use:
  - jcode v0.94.0 (release binary, sha256 checked) ran under a sandbox
    HOME with JCODE_HOME set and JCODE_NO_TELEMETRY=1. Its config.toml
    was the one jcode wrote for its own "probe" profile.
  - A sandbox magpie (MAGPIE_ADDR 127.0.0.1:3671) with a fake OpenAI
    upstream on 3672 ran `magpie jcode magpie/fake/org/echo-1`, a model id
    with two slashes.
  - `jcode run 'Say hello in one word.'` answered with the upstream's
    reply, streamed. The upstream saw model org/echo-1, and usage.jsonl
    recorded the turn under agent "jcode".
  - `jcode provider add two …` while connected appended its own profile
    and left magpie's as it was.
  - `magpie jcode default` then gave back the file jcode wrote,
    byte-identical, with jcode's new [providers.two] kept.
- The icon rendered as a mask in Chromium and WebKit. The only GUI
  change is the notice's translations; TestEveryNoticeIsTranslated and
  internal/gui pass, and node --check accepts i18n.js.
- gofmt -l; go vet (darwin, GOOS=linux, GOOS=windows) on internal/agent
  and internal/agentenv; go test -tags nogui ./internal/agent
  ./internal/agentenv ./internal/gui; go test -tags nogui ./... under a
  temp HOME (load ~80): every package passed. After rebasing on
  origin/main, internal/agent and internal/agentenv were run again,
  along with internal/gui, gofmt and the linux/windows vet.
2026-10-11 04:33:53 +08:00
yetoneandump45nose ce11b18015 gateway: Codex compacts on Gemini after a tool's output, no "Requests ending with a model turn" (#1533, yycsyu)
What the user saw: Codex on Google Vertex AI (gemini-3.8-flash) failed
every compaction that came right after a tool's output with
"Google Vertex AI: Requests ending with a model turn are not supported."

Why: codexInput turns compaction_trigger into a user message holding the
compaction prompt; mergeTurns and then buildCodeAssistSent merged it with
the function_call_output's user turn, so Gemini got one user content
holding a functionResponse and text. Vertex answers that with the
"ending with a model turn" 400 although the last role is user; #1533
showed the same history with the two as separate user contents gets 200.

What changed:
- buildCodeAssistSent (every Gemini-shaped request: Vertex AI, Factory's
  Gemini, Gemini CLI's and Antigravity's Code Assist, Google sign-in)
  puts what the user said after tools' responses in a user turn of its
  own, and never merges text into a responses turn or the other way.
  Tools' images stay with their response; parallel calls' responses stay
  in one turn. A Claude model on Antigravity keeps its single tool_result
  turn as before.
- It also never ends contents with the model's turn: a user turn goes
  after it ("Continue.", or compactLastText when an agent compacts with
  the ask in its system prompt). prefillRefusal knows Gemini's wording.
- docs/subsystems/gateway-routing.md says both.

Tests: gemini_model_last_test.go uses #1533's exact Responses request
(read_sample / call_diagnostic_1 / compaction_trigger) on /v1/responses
and Codex's path against a fake Vertex that refuses as the real one did;
with the split disabled it fails with the reporter's exact message, and
TestGeminiToolResponseTurnHoldsNoText fails for all four builders.
ump45nose's fork patch on #1533 (93a2afca) found the same cause and
split the turn on Vertex AI only; this does it for every Gemini builder,
and takes its Anthropic case (a tool_result beside text in one message)
into the end-to-end test, which fails on the old code too.
TestBuildCodeAssistForGemini, TestCodeAssistToolImagesAfterEveryResponse
and TestGeminiHistoryOpeningWithModel held the old one-turn merge (from
637b2458, a choice, not a fix for a report) and now expect the question
in a turn of its own.

Run: go test ./internal/gateway ./internal/provider, the full
go test -tags nogui ./... (queue lock), gofmt -l, go vet -tags nogui for
darwin, linux and windows.
Not tried against real Vertex AI: no Vertex credentials on this machine.

Co-authored-by: ump45nose <52391318+ump45nose@users.noreply.github.com>
2026-10-11 04:33:03 +08:00
yetoneandBUKOWSKIREAL 8b393938f5 agent: StepCode can be connected to magpie, and Disconnect puts back its own model (#1526, BUKOWSKIREAL)
StepCode (StepFun's coding CLI, `step`) is a Pi fork that keeps Pi's
settings as TOML in ~/.stepcode/config.toml and Pi's models.json beside
it. It is now an agent target: Connect sets defaultProvider/defaultModel
to magpie, appends the magpie pattern to enabledModels when the user
scopes models, and writes providers.magpie into models.json with the
per-agent key. Disconnect puts back the user's own provider, model and
scope (only the patterns magpie added are taken out if the user changed
the scope since), restores or removes providers.magpie, and removes a
models.json magpie created. STEP_CODING_AGENT_DIR and STEPCODE_CONFIG_DIR
move the folder as StepCode's own resolveStepConfigRoot does; WSL is
covered.

The patch is BUKOWSKIREAL's (7cc88463 in their fork), reviewed line by
line: no network, telemetry or credential reads, writes only to the two
StepCode files and magpie's stash. Added here: a test that StepCode's
real User-Agent, "step (darwin 25.2.0; arm64)", counts as StepCode, and
the real-CLI test now looks for a "magpie" row in `step --list-models`
rather than the word anywhere (the docs path step prints can contain it).

Run:
- Config format checked against stepfun-ai/Step-Code at 3d70bae5 and the
  official 0.1.3 darwin-arm64 binary (sha256 matches latest.json):
  `step config path --json` names ~/.stepcode/config.toml and models.json.
- Sandbox HOME, sandbox gateway on 127.0.0.1:3647: a user config with
  defaultProvider "step", step-3.7-flash, thinking high, two scoped
  models, telemetry off. `magpie stepcode magpie/deepseek/deepseek-flash`,
  then `step -p` answered PONG through the gateway (usage record: agent
  stepcode, deepseek-flash, 200). `magpie stepcode default` put
  config.toml back value for value, removed models.json, and
  `step --list-models` no longer listed magpie.
- The same round trip from the real web page (sandbox `magpie web`),
  switch on, then off through the disconnect preview, which listed the
  three values it puts back; config.toml came back byte-identical. The
  row and icon checked in Chromium and WebKit, en and zh; no GUI assets
  change.
- Broke the guarantee: with unwire never restoring the defaults,
  TestStepCodeLifecycle, ...NativeChangedAndPreexisting and
  ...StrictValidationAndRollback go red. Without the "step" alias the
  new UA check goes red.
- MAGPIE_TEST_STEPCODE_BIN=<0.1.3> go test -run TestStepCodeRealCLISandbox
  passes (it failed before the row check above).
- go test -tags nogui ./... ; gofmt -l; go vet (darwin, GOOS=linux,
  GOOS=windows) on internal/agent and internal/agentenv; go build for
  darwin, linux (nogui) and windows.
Not tried on a real Windows, Linux or WSL machine.

Co-authored-by: BUKOWSKIREAL <233685554+BUKOWSKIREAL@users.noreply.github.com>
2026-10-11 04:03:29 +08:00
yetone cd93bbec0e provider, gui: a signed-in account can be given a name of the user's own, and a GLM seat's account card keeps the key plan's name and no longer flickers back to two cards (#1515, aindijrncom)
The same GLM Coding Plan team seat was added twice: as a key provider the
user had named, and as a ZCode plugin account. The Usage page kept only the
account's card, which read "31****36@qq.com" or just "ZCode", and whenever
either read failed ("BigModel API keys: not JSON") or a window had no reset
yet, the key's card came back beside it.

Seat (the flicker): the old check returned "different" on any error. It
now returns same, different or unknown (seatMatch). A match is remembered in
seats.json beside quotas.json; while the remembered account is signed in an
unknown check keeps the key card hidden, windows that disagree forget it,
and a signed-out account brings the key card back (seatCards, used by
quotas, Allotted and CachedCards). A failed read is "unknown", never "not
the same".

Names: providers.json gains accountNames (by the account in lower case,
like accountCaps), set by provider.SetAccountName. They are magpie's own
and never written into the vendor's or a plugin's sign-in. Built-in and
plugin accounts both take one; key providers are refused. Each card carries
Alias (the user's name, else the seat) and Seat (the key provider's name,
and the key's when it has several).
- GUI: the editor's account row shows the name with the address beside
  it, or the address with "≡ <key plan>"; a click or Enter renames it in
  place (posted once to provider/accountname; Escape leaves it, empty
  clears it). The name stays selectable text: dragging across it renames
  nothing.
  The Usage page's cards and the tray panel name the account the same way.
  Hide accounts hides the name too. Strings in zh, zh-TW, ja, de.
- The tray tooltip says "ZCode · <name>".
- CLI: `magpie accounts alias <agent> <email> [<name>|--clear]`.
  `magpie accounts` and `magpie quota` show the name; quota also matches
  on it.
- /v1/magpie/quotas carries alias and seat.

Run:
- account_seats_test TestSeatKeptThroughAFailedRead fails on the old code
  ("a failed read brought the key's card back") and passes now.
  TestAccountNameOfAPluginAccount uses the fake plugin and checks that
  plugin-auth.json and logins.json are byte-for-byte unchanged.
  TestAccountsAlias checks that Codex's auth.json is unchanged.
  TestTrayNamesTheAccountByItsAlias.
- account-alias.test.cjs: Chromium and WebKit; en, zh, zh-TW, ja, de;
  900 and 360px; 20/20 pass. It covers no scroll on a click, keyboard,
  selectable text, no select, no stripe, no sideways scroll and masking.
  With the post-once guard removed it goes red. account-arrange (text
  selection) passes in both engines.
- Sandbox HOME, built binary, vendors behind a dead proxy:
  - `magpie accounts alias codex Me@Example.com 某某·GLM高级版`, then
    `magpie accounts` and `magpie quota` showed the name.
  - An unknown account was refused.
  - `magpie web` on spare ports: POST /api/provider/accountname saved
    "Team seat" (whitespace folded), and an unknown account got an error.
  - Gateway /v1/magpie/quotas and /api/usage/quotas carried the alias.
  - auth.json's sha was unchanged throughout.
- go test -tags nogui ./... (temp HOME, load ~200): all ok except
  TestSetAnswersWhileDevinAndProvidersHang (15.5s under load), which
  passes alone 3/3 at ~250ms.
- gofmt -l; GOOS=linux and GOOS=windows go vet on internal/provider,
  internal/gui and the root package.
- The whole GUI suite in Chromium and WebKit, each failed file rerun
  alone. These are red on the parent commit 472b36cec as well:
  mobile-web (9), usage-heatmap (11), old-webkit (Safari 15 :has and
  :focus-visible rules), usage-alert on WebKit (2), and routing-proxy,
  which flakes 2 of 3 runs on the base. Every other file passes alone.
Not run: a real GLM key plus a real ZCode account. The seat match against
real BigModel/ZCode answers is covered only by the fake-upstream tests.
2026-10-11 03:42:35 +08:00
yetoneandxiaohei-info 3144868538 gui, gateway: the Providers and Gateway pages no longer download every recent call's bodies; an opened call reads its own (#1521, xiaohei-info)
GET /api/providers carried up to 40 recent gateway calls with their
request and response previews (up to 256 KB each) in gateway.calls,
and every provider write returned the same state. The Providers page
never shows them; only an opened row on Gateway does. With 40 calls of
~300 KB each, /api/providers was 21,019,635 bytes on origin/main.

Taken from xiaohei-info's patch (bb26b802, attached to #1521 as
external PRs are closed): providersState drops the bodies from the
calls it sends; GET /api/gateway/call returns one call's previews and
truncation flags with Cache-Control: no-store, 404 once it has left
the ring; the page fetches on open, dedupes a pending read, keeps
loaded bodies across refreshes, drops them with their call, shows
"Fetching…" and a "Try again" on a failed read; the strings in zh,
zh-TW, ja and de; the Go and Playwright tests; the gui-shell note.

Changed from the patch: a call is asked for by a number the gateway
gives it in the ring (Call.ID, Server.RecentCall), not by time, agent
and model, which two calls of one agent to one model can share. The
page keys a row by that id too (callRow), so two such calls no longer
open, or show the bodies of, each other. The tests ask with ids, and
the Playwright fixture gives two calls the same time, agent and model.

The route is on the same mux as the rest of the API, so magpie web's
key guard covers it, and the gateway's own port doesn't serve it. The
bodies are the ones the ring kept, masked as before (redacted runs
before capture). Nothing else reads gateway.calls' bodies: Routing
reads /api/gateway/trace, and the tray, TUI, CLI and /api/state don't
read the ring.

Run:
- Real use: magpie web built from origin/main and from this commit,
  sandbox HOME, a local upstream answering 300 KB, 40 calls of 300 KB.
  /api/providers 21,019,635 bytes before, 45,525 after (calls: 14,503
  bytes). Opening a row in Chromium and WebKit fetched
  /api/gateway/call once (524,412 bytes) and showed both bodies with
  their "first 256 KB" marks. Without the key: 401, also for a
  rebound Host; on the gateway port: 404; an evicted id: 404.
- TestRecentCallBodiesOnDemand fails with the bodies left in
  providersState ("providers must keep call metadata without sending
  bodies"), and with RecentCall ignoring the id ("the second call's
  detail isn't its own").
- recent-call-bodies.test.cjs fails on main's app.js, and with callRow
  keyed by time|agent|model again.
- GUI: gateway-fold, json-tree, phone-rows, recent-calls-more,
  request-archive, recent-call-bodies, sse-body: 24/24 in Chromium and
  24/24 in WebKit (en, zh, zh-TW, ja, de).
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on
  internal/gui and internal/gateway.
- Full GUI suite: 5225 tests, 71 failures under load ~200, none in a
  gateway or recent-call file. The 20 files with failures, rerun on
  this commit and on origin/main: 54 and 58 fail; what fails on one
  only (Sessions checkbox colour, Sessions paging scroll, account
  dragging, ZCode block) moves between runs on both.
- go test -tags nogui ./...: every package ok on the rebased head.

Co-authored-by: xiaohei-info <14011749+xiaohei-info@users.noreply.github.com>
2026-10-11 03:12:46 +08:00
yetone 64262a19f0 agent: Prime Agent is an Agents-page row, wired like Pi into ~/.prime/agent, and Disconnect puts its files back (#1528, takltc)
What changed
- internal/agent/primeagent.go: Prime Agent (PrimeIntellect-ai/prime-agent,
  CLI prime-agent) through the piLike path, as OmO was added. Its folder is
  ~/.prime/agent or PRIME_AGENT_CODING_AGENT_DIR (~ expands, as upstream's
  agent_dir does; appdir now lets that variable carry ~). models.json and
  settings.json were checked against upstream v0.10.0 (pa-core settings and
  models registry): Pi's camelCase fields, the same thinking levels and
  enabledModels rules. Connect writes providers.magpie, defaultProvider and
  defaultModel and keeps the user's providers and settings. Only the global
  settings.json is written; allowedModels and subagentDefaultModel are left
  alone.
- Prime Agent sends no User-Agent, so its provider block carries the key
  magpie-prime-agent and the usage log names it (piLikeKeyed). The block is
  Pi's otherwise, compat.sendSessionAffinityHeaders included (Prime Agent's
  openai_completions honours it), kept as the user set it (piBlockKept).
- Disconnect restores both files byte-for-byte: before magpie's first write
  a copy is kept (*.before-magpie, or a note that the file was absent), and
  Disconnect puts it back when nothing else changed since (Agent.Restore). A
  file changed while connected is left with only magpie's part taken out.
- WSL kind, agentenv, the icon, PICKS_ITSELF in the GUI, docs and READMEs.

Run
- go test -tags nogui ./internal/agent ./internal/appdir ./internal/agentenv
  ./internal/library ./internal/usage; the new tests went red with the key,
  the restore, the ~ expansion, PICKS_ITSELF and the icon each taken out.
- pi-default-note.test.cjs in chromium and webkit.
- Real use: prime-agent 0.10.0 installed into a sandbox HOME, a sandbox
  gateway on 127.0.0.1:3651 and a fake upstream on 3652. The interactive
  TUI with no flags started on magpie/fake/echo-1, the fake got the request
  and usage.jsonl recorded agent "prime-agent". `magpie prime-agent default`
  put models.json back byte-for-byte; settings.json got its values back, but
  Prime Agent rewrites the whole file when it runs (every key, nulls), so
  that file is equal in content, not bytes. Reconnecting over that
  null-filled file and disconnecting again left it byte-identical. After
  the rebase onto 7a5536793 (compat in Pi's block) the turn was run again:
  same result, and both files byte-identical after Disconnect.
  `prime-agent -p` ignores the saved default upstream (print mode picks a
  featured model); with --provider magpie --model it goes through magpie.
- gofmt -l, GOOS=linux and GOOS=windows go vet, full go test ./...
2026-10-11 03:11:33 +08:00
yetone 6f0301f3c3 gui: magpie web gzips its page and JSON, and keeps each versioned script for good (akic404 on Discord)
akic404 runs `magpie web` on a public server over a ~3 Mbps link, and
the page took very long to load. Measured in a sandbox (`magpie web` on
127.0.0.1:3461/3463, sandbox HOME): every load sent the page's ~4.1 MB
of scripts and styles as they are (i18n.js 1.8 MB, app.js 1.1 MB,
app.css 282 KB, routing.js 279 KB, library.js 211 KB) with no
compression, whatever the browser's Accept-Encoding, and the API's JSON
the same way: a day of the Routing page's history
(/api/gateway/history, a real 267-request day copied in) was 1.23 MB,
and the routing trace's JSON grows with every account a request could
go to. Nothing is embedded, vendored or source-mapped in routing.js;
the bytes were the uncompressed transfer.

- webHandler wraps `magpie web`'s guarded handler in gzhttp
  (klauspost/compress, already a dependency): text, scripts, CSS, JSON
  and SVG are gzipped for a client that takes gzip, with Vary:
  Accept-Encoding; PNG/WebP/ICO/JPEG go as they are. A gzipped
  response's ETag ends -gzip, and If-None-Match with it is mapped back
  so a revalidation is still a 304. A 32-byte content-keyed jitter keeps
  the compressed size from being exact (BREACH), since the page carries
  keys. The desktop windows read the page in-process through Wails'
  asset server, with no network, so they stay uncompressed.
- revalidated: a script or stylesheet asked for under its current
  content hash (?v=…, as versionedPage names it) is sent with
  Cache-Control: max-age=31536000, immutable; any other hash, no hash,
  and the page itself stay no-cache + ETag. Applies to both paths.

Numbers (curl, page + its 21 scripts/styles + /api/state):
  before: 4,142,180 bytes, with or without Accept-Encoding: gzip
  after:  1,258,298 bytes with gzip (i18n.js 565 KB, app.js 361 KB,
          routing.js 89 KB), 4,142,180 without
  /api/gateway/history?day=: 1,233,600 -> 72,538 bytes
Real browser (Playwright, ?view=routing, 6s, response body bytes):
  Chromium first load 4,340,720 -> 1,362,922; reload 75,336 -> 10,597
  WebKit   first load 4,340,672 -> 1,362,843; reload 115,667 -> 34,006
  both engines: Routing view shown, no page errors or console errors.

Tests: TestWebCompresses and TestVersionedFilesKept (web_compress_test.go).
Broken by hand, each goes red: webHandler without webCompressed
(Content-Encoding "" for app.js, routing.js, /, /api/state, SVG); no
immutable branch ("/app.js?v=…: Cache-Control no-cache"); no
If-None-Match mapping ("asked again with its gzipped ETag: 200, want
304"); compressing every type ("a PNG: Content-Encoding gzip"); no
ETag suffix ("gzipped keeps the ETag of other bytes").

Run: go test -tags nogui ./internal/gui (ok); full go test -tags nogui
-timeout 40m ./... under a sandbox HOME (all ok); gofmt -l clean; go vet
./internal/gui on darwin, GOOS=linux -tags nogui, GOOS=windows with and
without nogui. GUI: routing-*.test.cjs, panel-routing, web-page,
mobile-web, phone-web, gateway-mode in Chromium and WebKit; results
after rebase are in the report (mobile-web was red on the old base
before ca0b95e3b, which these assets don't touch).
2026-10-11 02:48:13 +08:00
yetone ce1ecaa414 gateway: MaxRPM keeps a second's slack, so a first request's dial doesn't let the vendor see one over its minute
TestMaxRPMWaitsForRoomInTheMinute went red under CI load and b1396d23
reran it without a cause. The cause is real, not only in the test: a
request is counted when it starts to go, the vendor counts it when it
arrives, and the first on a new connection arrives later by its dial
and TLS handshake. With the bare 60s window, the limit+1-th request
could reach the vendor less than 60s after the first did.

- rpm.go: a counted request stays counted for rpmWindow + rpmSlack (1s),
  in prune and in reserve.
- rpm_test.go: minuteVendor can hold the first arrival (late); the two
  vendor-timing tests hold it 150ms with a window/6 slack and now ask
  that the vendor saw the gap of a whole window, not window-50ms.
  TestRPMReserveKeepsTheSlack checks the arithmetic. shortMinute zeroes
  the slack so the exact-minute tests are unchanged.
- docs/subsystems/gateway-routing.md: the Limits row says so.

Ran:
- With rpmSpan() returning the bare window: TestMaxRPMWaitsForRoomInTheMinute
  ("the vendor saw the third 1.346s after the first, inside the 1.5s window"),
  TestMaxRPMCountsRetriesAndCounts and TestRPMReserveKeepsTheSlack fail.
  With the slack all pass.
- go test -count=5 -run RPM ./internal/gateway; -race -count=3 -run RPM.
- go test -count=1 ./internal/gateway (581s, ok).
- gofmt -l clean; go vet on darwin, GOOS=linux, GOOS=windows for the package.
2026-10-11 02:25:05 +08:00
yetone 2305ab1fc6 gateway, netproxy: a web search goes through its searcher's proxy, not the direct line of the provider serving the turn (#1522, xixijay1988)
Claude Code on opencode-go (set to "direct"), with Codex as the search
delegate and the proxy on Auto (system proxy 127.0.0.1:7890): every
WebSearch dialed chatgpt.com directly, to the addresses a poisoned DNS
gave, and failed with "no answer in 2m0s". Codex's own requests through
the same gateway went through the proxy.

Cause: attempt() puts the turn provider's proxy choice on the request
context (Provider.Via -> netproxy.With). The search runs inside that
context, and its sub-request to Codex calls Provider.Via again, but
netproxy.With(ctx, "") returned ctx unchanged, so a provider that
follows the global proxy inherited the outer provider's "direct".

- netproxy.With: "" now replaces a choice ctx already names, so any
  request made for one provider while serving another (search delegate,
  vision describer, classifier, Codex titles, all through attempt's
  p.Via) takes its own provider's proxy or the global one.
- webSearch clears the turn's choice up front: the search APIs, which
  have no proxy of their own, follow the global one.
- kimiSearch now applies the Kimi Code plan's own proxy (p.Via); it
  had none and went the turn's way.

Verified:
- New TestSearchFollowsTheSearchersProxy: a fake CONNECT proxy on a free
  port; the turn's provider is reachable only directly, the searcher, a
  Kimi Code search service and a search API only through the proxy.
  Cases: Settings' proxy, Auto (from the environment), a searcher's own
  proxy with the global direct, a search API. On the old code it fails
  with "dial tcp search.test:443: ... (dialed directly)", CONNECTs [];
  with only the With fix the search API case fails; with the kimiSearch
  change reverted the Kimi case fails. -race -count=5 passes.
- TestWith in netproxy gains With(With(ctx, outer), "") follows the
  global proxy; fails on the old With.
- go test -tags nogui: gateway, netproxy, provider, plugin, update pass;
  the full ./... suite under load ~180 passed except
  internal/agent TestDshHomePickSurvivesSyncAndEffort, which passes alone
  (-count=3) and touches no proxy code (not this change; not yet filed).
  After rebasing onto 552c2244d (search MCP, also through webSearch) the
  search, Kimi and proxy tests pass again. gofmt -l clean; go build;
  GOOS=linux and GOOS=windows go vet -tags nogui on gateway and netproxy.
- docs/subsystems/gateway-routing.md: the one-try row says how a
  sub-request picks its proxy; the test is in its run list.
- Not tried against the reporter's real proxy and DNS.
2026-10-11 02:01:32 +08:00
yetone 552c2244dd gateway, gui: magpie's web search is an MCP server too (Kayphoon on Discord)
What: /mcp/magpie/web-search serves the gateway's existing web search
(webSearch: the searcher's model, a Kimi Code plan's service, the search
APIs, in the order Settings sets) as an MCP server with one web_search
tool, so Cursor, Claude Desktop (through mcp-remote) or any agent can
mount it. Streamable HTTP only: POSTed JSON-RPC messages and batches are
answered with JSON (initialize with version negotiation, ping, tools/list,
tools/call), notifications get 202, GET/DELETE 405. Legacy SSE isn't
served. Two segments under /mcp/, so it can't hide a signed-in server's
/mcp/{name}.

Guards: lanGuard as on every route (a gateway key from another machine,
only while shared; rebound browser hosts refused), plus a local/shared
backstop in the handler. Any web page Origin (localhost too) is refused
unless listed in Settings, as the MCP spec asks of a server. keyLimited
passes /mcp/ by, so each tools/call reserves the calling key's limit
(budget.Reserve) and a spent key gets a tool error with no search. The
search is marked CallFor{MCP: true}, and Routing says the agent called
magpie's web_search MCP tool. With nothing that can search, the tool error
says where to add a search API.

GUI: Settings > Models > Web search has an "MCP server" row with the
address (from the Settings page's gateway URL) and Copy, in en, zh, zh-TW,
ja, de. docs/subsystems/gateway-routing.md has a section on it.

Run:
- go test -tags nogui -timeout 40m ./... (all ok, at the first rebase),
  then gateway/gui package tests again after rebasing onto b1396d23.
- TestSearchMCP* (protocol, guards, key limit, Routing mark, no
  searcher). Break checks: dropping Reserve, the Origin check or MCP:true
  each turns its test red; dropping the handler's local/shared check does
  not, because lanGuard already refuses (it is a backstop).
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui ./...
- GUI, Chromium + WebKit: search-mcp (new, 5 languages, 520px), i18n-keys,
  gui-ja, gui-de, gui-zh-tw, search-first, search-api, searcher-pick,
  routing-side-calls. search-mcp caught the address falling back to 3425.
  search-mcp first held its row across Settings' redraws ("not attached
  to the DOM" 3 times in ~60 WebKit runs under load ~150); it now reads
  the row in one evaluate, and 3 full runs in both engines passed 60/60.
- Sandbox magpie (temp HOME, MAGPIE_ADDR 127.0.0.1:3512) with a fake
  SearXNG on 3513: the official MCP TypeScript SDK client 1.32.1 did
  initialize (2025-06-18), tools/list, tools/call and got the hit, as did
  mcp-remote 0.14.3 over stdio; curl: GET 405, localhost/foreign Origin
  403, rebound host 403, notification 202.
2026-10-11 01:55:34 +08:00
yetone 177fbdfe28 library, gui: the agents a skill is installed for have an All chip, one click takes them all off (#1531, liuweifeng)
Installing a skill from a repository starts with every agent lit, so
installing it for one agent alone meant unticking each of the others.
The picker now has the All chip the library's skill and server rows
already have (allChip): lit while every agent that can take it is lit,
a click takes them all off, another puts them all back. Only this one
is then All + that agent's chip, two clicks, with the same control as
the rows rather than a new idiom.

The same fix reaches every sibling picker that chooses agents before an
item is added: the market's skill install, the MCP server editor (add
and edit), pasting several servers, and the market's server install.
No new strings: All and its tooltips are already in every language.
The CSS sets All a little apart from the icons outside a row.
docs/subsystems/library.md says so.

Run:
- new internal/gui/tests/skill-install-agents-all.test.cjs: Chromium and
  WebKit, en/zh/zh-TW/ja/de at 1100px and 420px, with the reporter's
  repository: All lit at first, All -> none, Codex -> install posts
  agents ["codex"]; All puts every agent back; the server editor's All
  too. 28/28 pass; on the old library.js/css 0/28.
- the library's sibling GUI tests (by-agent, every-skill,
  group-skill-chips, library-*, market-have, market-featured-skill,
  pick-skills, project-servers, skill-install-skip,
  skill-name-many-agents, mcp-signin, import-all-skills) in both
  engines: all pass, except library-servers-bulk's known 2px flake
  (#1322), which fails the same way with this change reverted.
- screenshots of the picker in zh at 1100px and de at 420px.
No Go changed.
2026-10-11 01:45:47 +08:00