Commit Graph
183 Commits
Author SHA1 Message Date
yetone fdf5e2c65f cli: claude-tui-helper ends on a signal its own way, not of magpie's handler
magpie's process-wide handler (endProbesOnSignal) re-raises SIGTERM. In
claude-tui-helper it killed the helper (exit -15) before the shim's own
handler could stop its Claude Code and remove what it wrote, so a run the
gateway aborted left them behind. The helper's command now lets go of
those signals (leaveSignals) before claudetui.Run.

Run: go test ./internal/claudetui ./internal/cli on mote (macOS) and in
WSL magpie-desktop (-tags nogui), ok; go vet ./..., GOOS=linux go vet
-tags nogui ./..., GOOS=windows go vet ./..., go build on mote, ok.
Broken by hand: without leaveSignals, SIGTERM to a real helper in the
sandbox gateway exited -15 and left its temp folder; with it, exit 1 and
the folder removed (termimg.py).
Not tried: SIGHUP from a closed terminal.
2026-10-31 05:00:39 +08:00
yetone e647a1fd54 plugins: an npm registry of the user's own is used for installs and lookups (timwangdev on X)
timwangdev asked on X for plugins to take a custom npm registry. Zero-config
first: Registry() (internal/plugin/registry.go) takes, in order, the one set
in magpie (settings npmRegistry: `magpie plugin registry <url>|default`, or
Plugins › Discover's new npm registry row), BUN_CONFIG_REGISTRY /
NPM_CONFIG_REGISTRY / npm_config_registry in magpie's environment, then the
login shell's (cached probe only, proc.LoginEnvKnown, never waits on a
shell), install.registry in the plugins folder's or the user's .bunfig.toml,
registry= in the plugins folder's or ~/.npmrc, then the 国内镜像 switch's
npmmirror, then npm's own. The switch no longer puts npmmirror over a
registry the user named: before, bun was handed BUN_CONFIG_REGISTRY=npmmirror
whenever it was on, over the user's .npmrc. bun is told the registry only
where it wouldn't find it itself (magpie's setting, the shell's, the
switch's). magpie's own npm questions (latest version for the market,
Update and the hourly check, README, search) go to the same registry, a
package's @scope:registry= to that scope's, with the .npmrc's
//host/path/:_authToken (${VAR} expanded, longest prefix) sent to that host
alone, dropped on a redirect to another host, never logged or shown.
Download counts stay npm's. Only http(s) with a host, no userinfo, query
or fragment is taken; anything else is refused and not saved, and a bad
value hand-written into settings.json is passed over. /api/plugins says
which registry is in use and where it came from.

The GUI row is in registry.js, imported when Discover draws it, so the
core script budget isn't raised (plugins.js is 292 bytes smaller than
before, one long comment there condensed).

Left out: bunfig [install.scopes] for magpie's own lookups (bun reads them
for installs), .npmrc _auth and username/password, NPM_CONFIG_USERCONFIG
and npm's global npmrc, and internal/agent/cliupdate.go's agent CLI update
lookups, which still ask npm's own.

Run (mote and wsl-run). First at this change on 2ac423f4f:
- go test ./internal/plugin/ ./internal/source/ ./internal/gui/
  ./internal/proc/ ./internal/cli/ ./internal/settings/ -timeout 45m:
  plugin, source, cli, settings ok. gui: only the real-window AppKit tests
  killed at their deadline on mote (dock, panel, titlebar, tray; #2645,
  #4125), TestCoreScriptBudget and TestSettingsSaveKeepsWhatItDoesNotSend
  green after the fixes in this commit. proc: TestNoCommandBypassesProc red
  on origin/main itself (internal/claudetui/tui.go:183), filed as #4491.
- gofmt -l internal: clean. GOOS=linux go vet -tags nogui ./... and
  GOOS=windows go vet ./...: ok.
- GUI (wsl-run, magpie-desktop): plugin-registry.test.cjs in Chromium and
  WebKit, 5 languages each, 980px and 380px; i18n-keys, old-webkit and
  plugin-market (WebKit): 19/19 pass. On mote the browser runs timed out
  launching (#4125).
Again at this tree rebased on fa5e86cf2 (upstream changed app.js and
i18n.js): go build ./...; go test ./internal/gui/ ./internal/cli/
./internal/plugin/ ./internal/settings/: cli, plugin, settings ok, gui only
the same ten AppKit window tests killed on mote (#2645, #4125), the core
budget green; gofmt clean; plugin-registry (Chromium, WebKit), i18n-keys
and old-webkit on WSL: 22/22 pass.
Rebased once more on 45de2ddb9 (app.js and i18n.js again): gofmt clean,
go vet of gui and plugin ok, TestCoreScriptBudget and
TestSettingsSaveKeepsWhatItDoesNotSend ok, i18n-keys 4/4.

Broken by hand, each red, then restored:
- A: old registryEnv (npmmirror whenever the switch is on):
  TestBunTakesTheUsersRegistry red.
- B: lookups always to npm's own: TestLookupsAskTheUsersRegistry red.
- C: no URL check: TestSetRegistryRefusesWhatIsntOne red.
- D: the switch before the user's registry: Precedence, BunTakes and
  Lookups red.
- E: no token sent: Lookups red.
- F: scopes ignored: Lookups red.

Not tried: a real private registry (Verdaccio, GitHub Packages, Nexus) with
a real token; a real bun install through one; Windows (the login shell
probe is a no-op there, so only env, bunfig and .npmrc apply).
2026-10-31 04:24:59 +08:00
yetone 45de2ddb96 provider: a provider the user counts free goes first under Free first (jiabubu on Discord)
jiabubu asked on Discord #help for a way to mark a provider, model or key
as free, so that Free first routing spends it first. Their example is
ModelScope, which has a free daily quota. Until now routes.Seat.Free
came only from the vendor catalog's Free flag, and there was no way for
the user to set it.

Provider.CountFree ("Free for me" in the provider editor's Advanced fold,
`magpie provider set <id> free=yes|no` in the CLI) makes FreeModel true
for every model of that provider. Routing therefore treats it like a
vendor's free model: Free first uses it before paid ones, and Cheapest
first weighs it at nothing, because PriceAt, which only routing reads,
returns 0 for a free model. Prices shown (ListPrice and the model list)
and the costs Usage counts (EffectivePrice) are unchanged. The mark says
what to spend first, not what a call cost, and a quota that runs out
still bills at the listed price. Key and account (subscription)
providers both carry it, through withPicks, the account literal and the
copy merge.

Tests:
- internal/gateway TestFreeFirstSpendsTheProviderTheUserCountsFree:
  - a Free first group [paidv/m, mine/m] sends its first call to mine
    once mine is marked, and the trace row says Free;
  - EffectivePrice is still the listed 3/15;
  - Cheapest picks mine first;
  - unmarked, paidv goes first again.
- internal/gui TestProviderSaveKeepsCountFree: the preset and typed-in
  providers save the mark and clear it, and /api/providers reports it.
- internal/cli TestProviderSetFree: free=yes and free=no work; the value
  shows in `provider <id>`; free=maybe, an empty value and --help are
  refused and change nothing.
- GUI internal/gui/tests/provider-count-free.test.cjs covers the
  ModelScope preset, a custom provider saved with the mark, and a Codex
  account. It runs chromium and webkit, in en, zh, zh-TW, ja and de, at
  widths 900 and 440. It checks the Advanced fold, the check and save
  POST bodies, that the row fits with no sideways scroll, and that each
  string has a translation in I18N.

Core script budget: rebased on fa5e86cf2, the core's scripts came to
1,538,236 bytes, 880 over coreScriptBudget, which TestCoreScriptBudget
caught. The budget is not raised. countFreeField's comment and five
long comments on the editor's helpers (proxyPicker, concurrencyField,
priceRateField, pluginOptionsField) are cut down, so app.js ends 212
bytes smaller than before this change.

Run (mote via mote-run, at this change's tree on base 8ee75adbf):
- go test of internal/gateway (-run FreeFirst|InOrder), internal/gui,
  internal/cli and internal/provider: ok.
- GUI test: chromium 30/30 on mote. WebKit could not launch on mote at
  all at the time (a bare webkit.launch probe timed out at 60s, and
  other sessions' WebKit launches were stuck there too). WebKit was run
  on Linux instead (wsl-run, magpie-desktop): 30/30.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./... and
  GOOS=windows go vet ./... ok; go build for darwin, linux (nogui) and
  windows ok.
- At the pushed head (rebased on fa5e86cf2, comments cut): go test of
  internal/gui, internal/cli, internal/provider and internal/gateway
  -run FreeFirst|CountFree ok (internal/gui was red only on
  TestCoreScriptBudget before the cut); node --check app.js ok; the GUI
  test in chromium 30/30.
- The full Go suite (go test -tags nogui -timeout 45m ./...) is still
  running on mote at ship time, per the owner's ship-at-once rule. Any
  red it finds gets a follow-up commit. The whole GUI suite was not run:
  mote's WebKit cannot launch and the Linux box was running other
  sessions' GUI suites.

Broken by hand:
- With the CountFree line taken out of FreeModel, all three Go tests
  went red, e.g. 'Free first went to "paidv" (free false) first'.
- With `pr.CountFree = in.CountFree` taken out of the preset save
  branch, TestProviderSaveKeepsCountFree went red ("the preset's mark
  wasn't kept").

Not tried:
- A real ModelScope account; the tests use fake upstreams.
- A per-model mark (optional in the request); the mark is
  provider-wide.
- The TUI editor (the CLI setter covers the terminal).
2026-10-31 04:21:21 +08:00
yetone 333e7f573b gateway: gateway keys are dragged into the order you want, kept with the keys (alextjy on Discord)
alextjy asked on Discord whether gateway keys can be reordered. They
could not: the Gateway page listed them in the order caller-keys.json
held them, and nothing changed that order.

- access: a "move-key" action puts one key at a place in the list,
  under the same file lock as every other key change. Nothing else
  about the key changes, and the sharing key's mirror in settings is
  left alone (its pointer would otherwise land on another key).
- GUI: the Gateway page's key rows are dragged the way search APIs'
  rows are (shared dragRows, a grip shown on hover only, Alt+Up/Down,
  the existing "Drag to reorder" title). A refused move puts the list
  back from the server. New strings in zh, zh-TW, ja and de.
- CLI: `magpie gateway-key move <id> <place>` (from 1); list already
  prints the stored order.
- Usage > Requests: the key filter lists keys in the user's order,
  removed keys after. The Overview stays a ranking by use.

Run (worktree at 14b451c11, then rebased on origin/main):
- gofmt -l clean; go vet (darwin) on access, cli, usageapi, gui;
  GOOS=linux -tags nogui and GOOS=windows go vet on access, cli,
  usageapi (mote).
- go test access, cli, usageapi: ok (mote). internal/gui: every test
  ok except the real-window AppKit tests #4125 lists
  (TestCoveredWindowStaysUp, TestPanelCloseHidesIt and 7 more), killed
  at their deadlines with pboard not running on mote.
- Broken by hand: with move-key removed, TestMoveKeyKeepsOrder,
  TestGatewayKeyCLIMove and TestLedgerKeyFilterInKeyOrder go red; with
  the mirror exclusion removed and the filter left unsorted,
  TestMoveKeyKeepsOrder ("the sharing key's mirror moved") and
  TestLedgerKeyFilterInKeyOrder go red.
- GUI (WSL): gateway-key-arrange 20/20 (chromium and webkit; en, zh,
  zh-TW, ja, de; 1100 and 420px). Red by hand: no arrange (20 red),
  grip always shown (chromium 10/10 red), drop commits nothing (webkit
  10/10 red).
- GUI (WSL), the 68 files the change can reach (every caller-keys
  fixture user, gateway-*, search-*, usage-ledger*, i18n-keys, gui-ja,
  gui-de, gui-zh-tw, key-page, phone-rows, api-key-*): 900/923. The
  reds were run again at origin/main 43966a53f and fail the same there
  (api-key-theme webkit, gateway-key-limit webkit, gateway-key-models
  webkit, search-first, usage-ledger-open-settled, usage-ledger-ttft,
  usage-ledger), each filed: #3307, #3523, #4081, #3795, #4262,
  #3104/#1876, and #4489 (usage-ledger-ttft, new). phone-rows,
  search-keys and connect-snippet-shell reds of the first run passed
  when run again at the head. usage-ledger's "zh: request routing
  links" went red once at the head (Usage view position on return) and
  passed in the first run.

At the rebased head (on 2ac423f4f): TestCoreScriptBudget and the
other Budget/I18n/Asset tests in internal/gui ok (mote);
gateway-key-arrange, i18n-keys and gateway-caller-keys 27/28 in WSL.
The red is gateway-caller-keys webkit en "wider than 560 right after
the resize" (#3797, red alone on main). A probe of that file, printing
the page width and any element past it, read 560/560 with nothing
wider in both engines, in two runs beside the arrange file.

Not tried: dragging in the real app (WebKitGTK, WKWebView, WebView2),
the full Go suite (started after the push).
2026-10-31 03:48:27 +08:00
yetone 43966a53fb claude: a subscription's run is Claude Code's interactive mode, -p only as the fallback
The owner (10-31): a Claude subscription ran `claude -p`, whose
requests Anthropic labels sdk-cli and counts at about twice the
interactive mode's cli (anthropics/claude-code#97074). Running the real
interactive Claude Code is what its terms describe and uses the plan as
a person does. Wanted inside magpie, on by default, with a way off.

`magpie claude-tui-helper <claude> <-p args>` (internal/claudetui)
stands where `claude -p` stood and speaks the same stream-json. It
turns the -p arguments into the interactive mode's (no -p, no
--dangerously-skip-permissions: --permission-mode default with only
mcp__magpie, and the WebSearch -p was given, allowed; --no-chrome;
--session-id or the --resume given), starts Claude Code in a
pseudo-terminal of its own (no tmux), pastes each message into its
prompt and presses Enter, and tells the session's transcript back as
-p's lines: whole assistant messages, an API error as the turn's error
result with its rate_limit_info, turn_duration as the result. Nothing
sets CLAUDE_CODE_ENTRYPOINT, and the user's ~/.claude and
~/.claude.json are never written. The folder-trust question is
answered only for magpie's own folder or a saved account's config
directory (MAGPIE_CLAUDE_TUI_TRUST).

A Claude Code that doesn't start or show its prompt in 45s becomes
`claude -p` on the same pid, its input still unread, so the turn is
answered all the same; that is remembered for 30 minutes
(<cache>/magpie/claude-tui-broken). An untrusted folder goes to -p
without the mark.

claudeTUI keeps -p for Windows and WSL, Settings › Models › Replies ›
Claude Code's interactive mode Off (claudePrintMode), safeguards,
client cache marks, a JSON schema, images and a first message over
400KB. A TUI run ends instead of taking an image turn, a rewind or an
effort change, and letGo doesn't take one back. The gateway's tests
run with claudeTUIRuns off: their binary has no claude-tui-helper.
docs/subsystems/claude-subscription-bridge.md has the section.

The core's scripts grow 725 bytes with the setting's row;
coreScriptBudget is raised to the exact size, 1,537,356, with no room
added.

Run (rebased on f2eb56c6b and its budget fix):
- mote: go vet of claudetui, gateway, cli, settings on darwin;
  GOOS=windows of claudetui, gateway, cli; GOOS=linux of claudetui,
  gateway; gofmt -l clean.
- mote: go test ./internal/claudetui: TestShimTurnsInteractive (a fake
  interactive Claude Code in the PTY: two turns, a /help pasted as
  words, the arguments it was given), TestShimFallsBackToPrint (failed
  start marks broken; untrusted folder doesn't), TestShimTrustsWhenTold,
  TestPasteable, TestTranslatorAPIError.
- mote: go test ./internal/gateway -run TestClaudeTUIChosen (plain,
  off, WSL, safeguards, cache marks, schema, image, long prompt),
  TestClaudeLean*, TestCleanClaudeEnv.
- mote: go test -timeout 45m ./internal/claudetui ./internal/cli
  ./internal/settings ./internal/gateway: all ok (gateway 524s).
  go test -run Budget ./internal/gui: ok after the raise below.
- Linux (magpie-desktop): go test ./internal/claudetui ok natively,
  the PTY's Linux ioctls among it. GOOS=linux go vet -tags nogui of
  cli, gateway, claudetui, settings ok.
- Linux box, Playwright 1.62, chromium and webkit: claude-tui-setting
  16/16, claude-lean-prompt-setting 16/16, i18n-keys 4/4, mobile-web
  30/30 against 74f1df869's tree. mote's WebKit didn't launch (other
  sessions' GUI suites, running 11-16h, held ~108 WebKit processes),
  so the GUI ran there instead.
- Real Claude Code 2.1.314 on a real Claude account's magpie config dir,
  haiku, through the built helper with the bridge's exact -p arguments
  (an MCP server named magpie with one tool, --tools "",
  --system-prompt-file, --thinking disabled, --effort low,
  --thinking-display): the tool was called without a permission prompt
  and its answer used; the system prompt's end token in every reply;
  a second turn on the same run; a later run with --resume remembered
  the first. All 18 transcript rows say "entrypoint":"cli". Startup to
  init 0.7–1.5s, a haiku turn 1.4–4s. Two messages sent at once are
  one turn, as Claude Code queues them.

Broken by hand:
- each claudeTUI condition taken out in turn (WSL, safeguards, cache
  marks, schema, images, the setting, the 400KB bound): its case red.
  The WSL case first passed with the check gone (its claudeCLI had no
  path); given one, it is red without it.
- the trust check taken out of ready(): TestShimTrustsWhenTold red
  (the run went to -p).

Not tried: a turn through a running gateway into the helper on a real
account (a sandbox HOME would copy the sign-in into a new keychain item
and refresh it apart from the live one); a ~400KB paste; Linux with a
real Claude Code; an API error from the real service (the translator
is tested on its rows). The full go test ./... did not run (mote was held by those suites);
the four packages this touches ran whole.
2026-10-31 03:20:45 +08:00
yetone b62fa332f3 provider: Send requests unmasked for subscriptions and plugin providers too (isee1_1)
isee1_1 on Discord uses a community translation plugin as a provider and
asked why "Send requests unmasked" (请求不脱敏) isn't offered for it.
698da36f3 (lc) left a signed-in account, a plugin's provider and another
magpie out because the switch was then for local addresses only, and none
of those is local. 380032cda (AcMilan) made it the user's word at any
address, with a caution while on for one not local, but kept the
exclusion. Nothing still stands behind it for a subscription or a plugin:
the setting lives with the account's model picks, and every route reads
SkipsRedaction. Another magpie stays excluded, as it masks on its own side.

- provider.SkipsRedaction: an account (subscription or plugin) skips when
  set; another magpie never. Save keeps Unredacted in the picks record,
  withPicks applies it (AlsoOn accounts too).
- gateway: serve, count_tokens, embeddings, Jev and the plugin's fetch
  already go by unredactedRoute (every fallback and group member must be
  set too). The Codex relay on a ChatGPT sign-in masked always: it now
  sends the turn whole when the Codex subscription is set
  (codexRouteUnmasked; only for the ChatGPT backend, not the Codex API
  key route), codexMaskRoute stands aside then, and ChatGPT web search
  (alphaSearchOn) goes unmasked only when every provider it is on is set.
  Speech and video stay masked whatever the switch (maskTextHits), as
  before, for every provider.
- GUI: the editor's Redaction row is shared (unmaskRow); a subscription
  or plugin provider has it too, its caution naming the provider while
  on, since its vendor is never local; saved with the account's body.
  Another magpie has none. No new strings; app.js stays in its budget.
- CLI help/show text, gateway-routing.md and the masking docs (en, zh,
  ja) say so.

Run (mote, through mote-run):
- go test ./internal/provider ./internal/cli: ok
- go test -timeout 45m ./internal/gateway: ok (676s)
- go test -run 'Budget|Redact|Unmask|I18n' ./internal/gui: ok
  (TestCoreScriptBudget at +45 bytes)
- GOOS=linux go vet ./internal/gateway ./internal/provider, GOOS=windows
  go vet ./internal/gateway ./internal/provider ./internal/cli: clean
  (GOOS=linux vet of internal/cli fails in wails without cgo, as on main)
- node --test provider-unmasked (chromium): 36/36; i18n-keys: 4/4.
  WebKit on mote can't launch (#4125); WebKit ran through wsl-run:
  the whole file in chromium and webkit, 72/72. At 440 in Linux WebKit
  the list's sticky foot covers the last row (another magpie's), so the
  test clicks that row as an event (#4484).
- gofmt -l: clean

Broken by hand:
- SkipsRedaction's account branch back to false: TestSkipsRedaction
  (an account, a plugin's provider), TestPluginProviderUnmaskedSwitch/set
  and TestCodexSignInUnmaskedSwitch/set go red.
- Unredacted dropped from Save's account whitelist: the plugin test's
  "saved as" goes red.
- codexRouteUnmasked forced off: TestCodexSignInUnmaskedSwitch/set red.
The unset and falls-back-to-a-vendor cases stay masked in each.

Not tried: a real plugin provider or a real Codex/Claude account with
the switch on (fakes only: the fake bun plugin and a fake ChatGPT
backend); the Claude bridge path; the full Go and GUI suites run after
the push.
2026-10-31 02:56:49 +08:00
yetone 7bc602236b library: the MCP hub is called the MCP router
The owner asked why it was a "hub". Composio calls the same thing a Tool
Router; "router" says what it does (one server that routes each call to
the right one), and "gateway" is taken by magpie's LLM gateway. Only
the words change: MCP router / MCP 路由 / MCP 路由 / MCP ルーター /
MCP-Router, "Router address", and the CLI's `magpie library mcp router
on|off`, where `hub` still works. The URL /mcp/magpie/hub, the mcpHub
setting, the servers/hub API and the Go names stay, so nothing a user
or an agent config holds changes. docs/subsystems/mcp-hub.md moves to
mcp-router.md and the pages that link it follow.

#4382's new words follow too: "Through the MCP router", "Not through
the router" and their hints in every language, and the CLI's
`magpie library mcp router <name> shared|direct` (`hub` works there
too; library_hub_test.go says router for direct, hub for shared).

Run at e2583df31 (this stack on 86fef947e), on mote: gofmt -l clean;
go vet for darwin, linux (-tags nogui) and windows; go build ./...;
go test -tags nogui ./... -timeout 45m, 81 packages ok, 0 FAIL;
library, gateway, imagemcp, sessions, cli and gui again alone, ok;
site's node --test, 49 of 49. GUI on xiaomi-gpu (Windows; mote's
browsers crashed under other sessions' suites): library-*, image*,
mcp-hub-direct, i18n-keys, list-sort and plugin-tools, both engines and
every language, 1055 of 1056: i18n-keys found "{name} is given to each
agent directly" dropped from the library's strings in the rebase. Put
back in the first commit; at the pushed head i18n-keys, mcp-hub-direct
and library-mcp-hub are 48 of 48. That is the only difference from
e2583df31.
Broken by hand at e2583df31: imagemcp ignoring magpie/roots fails
TestHubCallSavesInTheCallersProject; the router asking anything but
roots/list fails TestHubAsksTheAgentItsRoots and TestHubRootsUnasked;
inHub leaving magpie-image out fails TestHubGivesMagpieImage.
The CLI's TestProviderAddressMovesALocalServer red at -count=3 was
the same on origin/main 380032cda and is fixed in 65c792410.
Rebased once more onto 2570efb5f, which changed library-mcp-hub,
list-sort, mcp-hub-direct and gateway-routing.md. Run at the pushed
head: go build; gateway, library, cli and imagemcp tests ok; the GUI
budget tests ok; on xiaomi-gpu i18n-keys, mcp-hub-direct,
library-mcp-hub and list-sort, 51 of 54. The three reds were WebKit
420px library-mcp-hub cases with no Connect sheet after a reload.
origin/main d77da5bff goes red the same way (de 420px, 9 of 11). In a
second run of library-mcp-hub on WebKit at this head, 11 of 11 passed.
Filed as #4483.
2026-10-31 02:49:08 +08:00
yetone a45a0f1c5d signin: Settings can keep sign-in pages out of the default browser (max2020)
max2020 on Discord signs in from a separate, fingerprint browser so the
vendor never sees their default one. Every waiting sign-in already shows
its link with Copy link (since 52c8e838d), but magpie still opened the
page in the default browser first.

Settings › Privacy › Sign-in pages › "Open sign-in pages in the browser",
On by default, so nothing changes unless it is turned off. Off
(settings.SignInLinkOnly) opens nothing: /api/signin and
/api/plugin-signin go through openSignIn, which skips the open and
answers linkOnly; a web tab skips window.open on linkOnly, after an
install step too; the box says the page wasn't opened and its button
reads Open, not Open again. `magpie accounts add` and a plugin's
command-line login print the link without opening it. A plugin whose own
CLI opens the page (Grok Build on macOS and Windows, opened) still does.

Callbacks, by flow: Claude Code's login, Codex (localhost:1455), ChatGPT
API, Gemini/Antigravity and localhost plugins come back to this machine,
so another browser on it finishes them, and the pasted final address
covers one whose proxy keeps it off loopback. Copilot, Grok and other
device-code flows work from any browser.

Run:
- TestSignInLinkOnlyOpensNothing (new; built-in and plugin sign-in, the
  setting on and off) with TestPluginSignIn*, TestSettingsSave*,
  TestCoreScriptBudget and TestI18n* on mote: ok. Budget holds with no
  raise (app.js 1,313,244 of 1,315,316).
- signin-link-only.test.cjs (new; every language, Chromium and WebKit,
  900 and 360px), signin-link and account-discovery on WSL: 42/42 and
  the neighbours green.
- Full Go suite on WSL (go test -timeout 45m ./...): every package ok
  except internal/agent's TestInstalledVersion, TestGrokInstalled,
  TestOmpDetectedWithPiDir and TestZedAppPath, red the same on
  origin/main 387e8572a there (#4033, #3548); root, internal/cli and
  internal/gui need gtk4 there and were run with -tags nogui: ok.
- gofmt; go vet darwin, GOOS=linux -tags nogui, GOOS=windows: clean.
- The whole GUI suite (both engines) is still running on mote at push
  time; reds it shows that aren't on file get issues.

Broken by hand: openSignIn ignoring the setting made the Go test red
("built-in: kept to its link, its page was opened 1 times"); dropping
startSignIn's linkOnly check made the GUI test red ("no page opened",
12 of 42).

Not tried: a real vendor sign-in from a fingerprint browser; Grok on
macOS/Windows still opens its own page; MCP server sign-ins unchanged.
2026-10-31 01:02:24 +08:00
yetone 3b5dccd527 accounts: a plugin account goes by its usage's name, not its id (#4416)
A Huawei Cloud CodeArts account is kept by its accountId, an IAM id
(iam::<domain>:user:<name>), and every list showed that id while its
quota card showed the masked phone the plugin's usage() names it by.
Display only: an account now reads as the name the user gave it, else
the `user` its plugin's last usage read gave (PluginUserOf: the
in-memory read, else quotas.json), else its id. The id stays the key
everything is kept by; nothing stored changes or migrates. A read that
fails keeps the last good name; nothing read yet is the id, never blank.

One rule in provider (AccountShown, AccountShownOf, AccountLabelOf),
used by every list: cards' Alias (Usage page, tray panel,
/v1/magpie/quotas, magpie quota), magpie accounts, magpie providers,
the TUI's Providers rows and quota titles, usageapi's Account filter,
the quota alert. The GUI gets it as /api/providers' accountUsers
(accountShownOf in app.js): the editor's account rows (the id in the
tooltip), the per-account proxy lines, Routing's userShown, the
Providers search, Hide accounts. app.js's account lookups share one
helper, so the core stays in its budget (1,536,561 of 1,536,586), with
no room added.

Run:
- go test ./... -timeout 45m on mote at 2f5a3f1c0 + this change: all ok
  but internal/agent TestPiModelsAskedOnTheirNativeAPI (fixed on main
  by 7474a86f1, green there; this is rebased onto it),
  internal/update TestRelaunchOpenTriedAgain (#3881, green alone x3),
  and internal/gui's real-window AppKit tests (TestPanelCloseHidesIt,
  TestMainWindowCorners, TestTrayCellClickReleasedPanel red the same
  on origin/main 99ad38b7c; #2645, #4125, #1936).
- go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet of the
  touched packages; gofmt -l clean.
- TestPluginAccountShownByItsUsageUser (new, real plugin host and fake
  plugin): id before a read, phone after, phone after a restart from
  quotas.json, phone kept over a failed read, own name wins, id when
  nothing is known. Red on the old code.
- GUI on the Linux box (mote's Chromium segfaults on these pages on
  origin/main too, #4125): account-plugin-user (new),
  routing-account-name (extended) and account-alias, Chromium and
  WebKit, every language, 34/34; the new checks red on the old code;
  the whole suite (make test-ui on the Linux box) was still running at
  push: 417 files in, 5 reds, none on a page this changes
  (account-models' row-moved check in WebKit, 81 vs 79px, and
  agent-models-all-hidden), not yet compared with origin/main; any
  that are new get an issue once it ends.
- At the rebased head (3bce283df): go test of provider, cli, tui,
  usageapi, plugin, agent -run TestPi, gui -run
  Budget|Provider|Quota|Account: all ok. Core scripts 1,535,513 of
  1,536,586.

Broken by hand: dropping the quotas.json fallback turns the test red
at "after a restart".

Not tried: a real Huawei CodeArts account (none here). A plugin whose
windows are all model pools isn't kept in quotas.json, so after a
restart it shows its id until its first read.
2026-10-31 01:01:49 +08:00
yetone 0621e70fb9 routing: leave a provider out of the groups magpie finds
chenxiang0010 on Discord asked to keep a provider or a model out of the
auto-created routing groups. A model could already be kept out (remove
its found group; magpie keeps it removed), but a provider could only be
turned off per group or everywhere. Now Routing -> Groups, under "Find
groups on their own", has "Leave out a provider..." (app menu, saved
when it closes) and `magpie group auto skip <provider>...|none`. The
providers chosen (providers.json autoGroupSkip) join no found group; a
group the user made or changed keeps them, a found group left with one
provider goes away, and a request for it is served by AutoStandIn from
a provider still in, and agents on it are reseated (agent.Reseat). A
rename carries the id along. en, zh, zh-TW, ja, de.

Run at 383947fce (this change on origin/main 2ff75161d):
- go test -timeout 45m ./... on mote: 80 packages ok; internal/gui red
  only in its real-window AppKit tests (TestDockJoinLeadsCommandTab,
  TestPanelCloseHidesIt, TestMainWindowCorners, ...), which fail the same
  on fresh origin/main 2f65a33aa on mote (#4125, #2645).
- gofmt -l clean; go vet ./... on Windows (win-run) clean; on Linux
  (wsl-run) clean with -tags nogui (the WSL distro has no gtk4).
- GUI: group-found-skip (new) and group-found-off, all five languages,
  1100px and 390px, Chromium and WebKit on Linux (wsl-run): 24/24. On
  mote every WebKit launch times out (#4125), Chromium 12/12 there.
- The routing files the full run flagged (concurrency 6) rerun alone on
  wsl-run, here and at fresh origin/main 380032cda: click-scroll's
  WebKit case and group-morph's WebKit 420px cases fail the same on
  origin/main. group-duplicate's de case was mine: the found groups'
  new "Anbieter ausnehmen..." line made German taller than the test's
  420x1200 window, which it assumes needs no scroll; it now uses 1400
  and passes 10/10 in both engines.
- Whole GUI suite on wsl-run, concurrency 6: still running at push time
  (5092 ok, 170 not ok so far, mostly in files this change doesn't load:
  account-*, agent-*, connect-*, gui-de/gui-ja's "{agent}" placeholder
  string). They are compared against origin/main after the push.

Broken by hand: foundGroups without unskipped -> TestAutoGroupSkip and
TestGroupsSkip red. Test calls before the fix to groupCmd's args ->
TestGroupAutoSkip red.

Not tried: the real app with real providers; a model-level skip (a
model is kept out by removing its found group, as before).
2026-10-31 00:57:21 +08:00
yetone 65c7924108 cli: TestProviderAddressMovesALocalServer adds LM Studio in a folder of its own
The test added lmstudio in the package's shared config folder, so a
second run (-count=2 and up) found it there, added "LM Studio 2"
instead, and read the old provider back at localhost🔢 red on
origin/main 380032cda at -count=3, runs 2 and 3. It now gets its own
HOME, USERPROFILE, XDG_CONFIG_HOME and XDG_CACHE_HOME, as the other
provider tests in the package do. HOME alone was tried first and stays
red: the config folder comes from XDG_CONFIG_HOME, which testenv sets
for the whole package.

Run at this head, on mote: go test ./internal/cli -count=2 ok (53.8s);
-run TestProviderAddressMovesALocalServer -count=5 ok; gofmt -l clean.
2026-10-31 00:53:27 +08:00
yetone 380032cda1 providers: Send requests unmasked is the user's switch at any address, with a caution while on for one not local (AcMilan)
AcMilan (Discord) runs a vLLM at http://llm.corp.lan:8000, and the
editor never offered "Send requests unmasked": the switch showed only
for a localhost, *.local or private-IP address. Asked, he said the
choice should be the user's for each provider.

provider.SkipsRedaction is now: Unredacted, no signed-in account, not
another magpie, and at least one address. Nothing is looked up on the
request path. The editor shows the row for every provider but an
account or remote magpie. While it is ticked, an amber caution under it
names an address not on this computer or the local network (awayHost).
A name of the user's own DNS is asked about, only while ticked, through
POST /api/local-hosts (provider.LocalHost -> netproxy.LocalName: every
address loopback, private or link-local, 400ms lookup, kept 1 minute).
That answer only words the caution. CLI help and `provider show` say
the same. The 'away' i18n line is in zh, zh-TW, ja and de. To stay
inside the core script budget, a few nearby editor comments were cut
down (no raise).

Run (logs in the worktree's logs/):
- Full Go suite on mote at base 024393fbb (go test ./... -timeout 45m).
  Every package is ok except internal/gui. Its reds are the AppKit
  window tests (#4125, #2645, #1936, #3949, #3178) and
  TestRestartHandsTheGatewayOver (#4167), plus TestCoreScriptBudget,
  which was mine and is fixed. At the pushed head (rebased on
  995f84a0f): the gui, provider, netproxy, gateway and cli tests for
  this area, with TestCoreScriptBudget and TestI18n: ok.
- GOOS=linux go vet -tags nogui ./internal/... and GOOS=windows go vet
  on the touched packages: ok. gofmt -l is clean.
- provider-unmasked.test.cjs and decide-endpoint-label.test.cjs: 34/34
  in Chromium and 34/34 in WebKit (Linux, wsl-run), on the final app.js.
- The 155 GUI files that open a provider editor, both engines (WebKit
  on Linux, Chromium on mote). Each file red there was rerun on Linux
  beside the base 024393fbb. The one red this change caused was
  decide-endpoint-label: a /api/local-hosts fetch cut off by navigation
  showed as a console error. That is why names are now asked only while
  the switch is on. The rest are red on the base too and have issues
  (#4431 and others). mote's browsers were crashing (#4125), so
  Chromium was compared on Linux.

Broken by hand:
- The old local-only gate put back in SkipsRedaction: TestSkipsRedaction
  (lan name, vendor, public IP, own proxy) and
  TestLANNameUnredactedProvider went red.
- awayHost returning "": 12 caution tests went red.
- The "only while on" guard removed: 4 "nothing is asked while the
  switch is off" tests went red.

Not tried: a real LAN DNS server, or AcMilan's own setup; WebKit on
macOS (mote's WebKit can't launch, #4125); the Windows app; the whole
GUI suite beyond the provider-editor files.
2026-10-31 00:44:59 +08:00
yetone 995f84a0f9 codex: how early an expiring reset is used is a setting
A Codex reset card that would run out unused was spent 30 minutes before
it expired, a fixed resetExpiryLead. Now the lead is codexResetLead in
settings.json (minutes, 15 to 1440). Unset, out of range or unreadable
reads as 30m, never 0, and magpie never writes it unless the user does.

- settings: CodexResetLead and Settings.ResetLead(); the menu's values
  are 15m, 30m (default), 1h, 2h, 3h, 6h, 12h, 24h.
- provider: the spend (expiringResetSpent) and routing
  (Allowance.Restarts, through nextResetLook) read the same resetLead(),
  so they still agree (#717, #718). The "near" look cadence follows it:
  lead + 30m, at least 1h, so a look lands inside a long lead.
- GUI: Settings > Usage, under the Codex auto-use rows, a row "Codex:
  how early before one expires" with an app menu (no <select>), and the
  sub text says spending earlier loses what the windows have left. The
  four "before it expires" strings say the chosen lead. POST
  /api/settings/codex-reset-lead; the general save keeps the field.
  en, zh, zh-TW, ja, de.
- CLI: magpie quota auto-reset lead [30m|3h|<minutes>|default].
- app.js budget: the auto-use rows moved out to lazy autoresetown.js
  (painted in the same draw once loaded), so app.js and the core script
  stay under their budgets with no raise. The button sizes to its widest
  label (a grid of every label), so picking one never rewraps the row.

Run (all on mote through mote-run):
- go vet: darwin, GOOS=linux -tags nogui, GOOS=windows; nogui build.
- go test -tags nogui -timeout 45m ./... at 3955adccf (this change
  before the paint and sizer fixes, which touch only GUI assets): 81 ok.
  go test ./internal/gui at this head: ok.
- GUI, Chromium: codex-reset-lead, codex-auto-reset,
  codex-auto-reset-settings, segs-press-redraw, i18n-keys: 62/62.
  WebKit: every case of those files failed at browserType.launch
  (180s timeout) before a page loaded, both runs; mote's browser
  launches hang under #4125 (load ~26), so WebKit is not run.
- Rebased onto f7f2d75f2 (old-webkit's lazy list now has traywindows.js
  too): go build ./..., go vet -tags nogui ./internal/..., go test
  internal/gui (budgets included), cli, settings, gateway: ok. provider:
  ok but TestQuotaSpanCarriesEveryWindowField, red on main since
  7d4a63148 (#4457, fixed in ccbefe2a2). GUI old-webkit, i18n-keys,
  codex-reset-lead in Chromium: pass.
- Rebased again onto 62a1dcdd7 (clean): go test internal/gui (budgets)
  and internal/provider: ok; i18n-keys and Chromium codex-reset-lead
  12/12 pass; old-webkit 9/10, its Safari 15.0 case a WebKit launch
  timeout (#4125).

Broken by hand, each went red:
- resetLead() pinned to 30m: all 3 provider tests.
- resetExpiryNear pinned to 1h: the long-lead look test.
- ResetLead's range check turned into m == 0: TestResetLeadUnreadIsDefault.
- GUI resetLeadMinutes returning 30: codex-reset-lead in every language.
- The button without the sizer: de at 420px, "no click moved the page".

Not tried: a real Codex account spending a card at a non-default lead;
Windows and Linux runs (vet only). The whole GUI suite in Chromium on
mote has ~45 tests in 31 files crash with "browser has been closed" on
untouched origin/main c84c3e1c0 too (reducedMotion files, #4458).
2026-10-31 00:41:29 +08:00
yetone b889ffe813 library: a server can stay each agent's own entry with the MCP hub on (#4382)
cuipengcx90's #4382, Option A's first step (nifengfanpan asked on
Discord): with the MCP hub on, every Library server went behind magpie's
one entry, so a server that reads its project from the folder it starts
in, or keeps a session's state, resolved the wrong repository or shared
state across agents. A server now has a hub policy, Server.Hub ("hub" in
library.json): "" (shared, the default, so nothing changes for existing
users; "shared" is saved as "") or "direct". A direct server is left out
of the hub through inHub, the test that already keeps magpie's own image
server out, so each agent given it keeps its own entry written as with
the hub off, beside the hub's entry for the rest. An agent whose every
server is direct gets no hub entry. The hub neither lists nor runs a
direct server, at /mcp/magpie/hub either, and hubPrune ends one it held.
Switching goes through change(), so the agents are written again at once
and the entry from the other policy is removed. An unknown policy is an
error.

- GUI: with the hub on, the server editor has a "Through the MCP hub"
  switch (role=switch, not a <select>; not shown with the hub off or for
  the image server), a direct server's row has a "Not through the hub"
  tag, and the hub's line and the Connect sheet name the direct servers
  with the image server as given directly. Strings are in zh, zh-TW, ja
  and de ("MCP 聚合" as the core uses it).
- CLI: magpie library mcp hub <name> shared|direct (ServerHub), and
  magpie library marks a direct server.
- TUI: an edit keeps the policy.
- Not done: Option B (per-roots/project backends behind the hub, keying
  hubPool by roots). It is left for later; #4382 stays open for it.

Run:
- TestHubDirectServer (internal/library) and the extended
  TestLibraryMCPHub (internal/cli) on mote. Broken by hand: inHub back to
  !isSelf(s) makes TestHubDirectServer red ("codex with the hub on:
  [magpie], want [index magpie]").
- Real configs in a sandbox HOME on mote (fake claude on PATH, the real
  binary built from this tree): mcp add index + web for claude and codex,
  hub on, hub index direct, shared, then both direct. The direct index
  entry was in .claude.json and .codex/config.toml beside magpie's; with
  every server direct both files were byte-for-byte as with the hub off
  (json.tool diff and diff); shared again removed the index entry.
- Full Go suite (-tags nogui -timeout 45m ./...) on mote at this tree
  rebased on origin/main 72ed121fd: 81 packages ok. Before the rebase
  the only red was TestQuotaSpanCarriesEveryWindowField (#4457, fixed by
  ccbefe2a2). GOOS=linux and GOOS=windows go vet clean, gofmt clean.
- GUI on WSL (magpie-desktop; mote's GUI is broken, #4125), both engines,
  every language: the new mcp-hub-direct.test.cjs (1100 and 390 wide,
  hub on and off), library-mcp-hub, mcp-local-server, i18n-keys: 88 pass.
  Broken by hand: not sending hub in the save makes mcp-hub-direct red
  (11 of 11 in chromium).
- The 54 library/mcp/i18n GUI files at --test-concurrency=4 on WSL at load
  ~160: 978 of 988 pass. Red: library-chip-fan (webkit, fan positions),
  library-mcp-tools (chromium ja 420, "the click scrolled the page") and
  mcp-oauth-app (chromium de 390). None of them touch the hub switch or
  the editor's new field. They are being rerun alone, here and on
  origin/main, after this push; a red that only this change has is fixed
  next, and a red on main too is filed.

Not tried: the whole GUI suite (1028 files); a real cwd-sensitive
server in a real agent session; the live app window.
2026-10-31 00:34:45 +08:00
yetone 4f2d5fc7e0 routing: a group can put its cheapest member first, by each one's price at that hour
liyuanzheng (#general) and lam_em (#feedback) both asked for the same
thing. Off-peak, DeepSeek's own API should come first for deepseek-flash.
At DeepSeek's peak (weekdays 01-04 and 06-10 UTC, billed 2x since
v0.1.2173), another provider should come first, Ollama say. A schedule
editor would make the user copy DeepSeek's hours into magpie. Instead,
a group gets one more routing, "Cheapest first" (`cheap`). Each request
sorts the members by what they cost right then: input + output price per
million, at the peak rate when it is peak hours. A tie goes to the lower
cache-read price. Free models count as 0. A member with no known price
keeps its listed place after the priced ones. Prices come from the same
priceOf the usage ledger bills with, so the user's own ModelPrices,
list prices and maker prices all count, and so does a provider's rate
windows.

- routes: Seat carries Priced/Cost/CacheCost; Strategy.ByPrice; Cheapest
  is a stable sort, so equal prices keep the user's order.
- gateway: weighRouted prices each seat at priceClock() (time.Now; a test
  holds it) through the new provider.PriceAt. The trace's Weighed row
  gets a price (input/output/cacheRead/peak) so Routing can say why.
- It is a group's alone, like Manual. A provider saved with it drops it,
  and `magpie provider set … routing=cheap` refuses it. Groups take it in
  the GUI menu (one more item, no new controls), the TUI and
  `magpie group set <id> routing=cheap` (aliases cheapest, price, cost).
- Routing's mode line says why the first one is first, e.g. "Cheapest
  first: deepseek-v4-flash costs least on ollama-cloud now — $0.150 in,
  $0.600 out a million tokens.", with peak and unpriced variants.
  en/zh/zh-TW/ja/de.
- Docs: gateway-routing, plugin-runtime, reference (it also points at
  Time window and Pause rules for a fixed schedule) and the site's start
  pages (en/zh/ja).

Run, at f7f2d75f2 (this change rebased onto it):
- Red on the old code: TestCheapestFirstGroupFollowsPeakHours (deepseek
  vs ollama with ModelPrices, priceClock held at 14:00 UTC off-peak and
  02:00 UTC peak) and TestCheapestOrdersByPriceNow did not compile
  without Cheapest. TestCheapestFirstIsAGroupsOnly checks that a provider
  drops it and a group keeps it.
- Broken by hand: without `pr = pr.In(at)` the gateway test is red ("at
  DeepSeek's peak ... went to deepseek"). With Cheapest returning the
  order unchanged, both the routes test and the gateway test are red.
  Both were restored.
- Full Go suite on mote (-count=1 -timeout 45m ./..., log kept): every
  package ok except two. internal/provider had
  TestQuotaSpanCarriesEveryWindowField, which is red on origin/main (#4457,
  fixed since in ccbefe2a2). internal/gui had ten AppKit window tests
  killed at their 20-40s deadlines (TestPanelCloseHidesIt,
  TestMainWindowCorners and others). Three of them are red the same way
  on a fresh origin/main f7f2d75f2 copy, under #2645/#4125 (mote has
  several GUI suites running). After the rebase, go vet and the Cheapest,
  SpeedFirstGroup, ParseRouting, ApplyGroupPairs and ProviderRouting tests
  are ok. go vet darwin, GOOS=linux -tags nogui and GOOS=windows are ok,
  and gofmt is clean.
- GUI on WSL (Linux, chromium + webkit): routing-cheapest-first (new,
  3 scenes x en/zh/zh-TW/ja/de x 2 engines), routing-group-strategy,
  builtins, i18n-keys and routing-speed-first gave 95 of 96. The one red,
  routing-group-strategy "webkit en light ... the pick moved nothing", is
  a wheel-scroll timing red. It fails 3 of 3 on origin/main and 1 of 3 here
  (#4459). Core-script budget ok (app.js +9 bytes).
- The whole GUI suite (1025 files) was started on WSL at this tree and
  was still running when this was pushed, at load ~160.

Not tried: real DeepSeek or Ollama accounts, and a real request during
DeepSeek's peak hours. Ollama Cloud's price here is the catalog's, not
checked against a bill.
2026-10-30 23:59:31 +08:00
yetone d99e213f5b codex: an account switch restarts nothing while Codex's provider takes no ChatGPT account
danzi002 on Discord: with requires_openai_auth = false on Codex's provider,
switching the Codex account in magpie still restarted the Codex app's
app-server and said the app and daemon were left on the old account.

Codex's provider with no requires_openai_auth = true goes by no ChatGPT
account: codex-rs ModelProviderInfo::account_state answers no account, and
resolve_provider_auth sends the table's key, never auth.json. So which
account auth.json holds is nothing a running Codex uses.

- provider.CodexNoAccount (set to agent.codexNoAccount): the config's top
  model_provider is not openai, has a [model_providers] table, and the table
  doesn't say requires_openai_auth = true. A profile, the built-in provider,
  no table or an unreadable config count as false (may use the account).
- codexAppStep forgets a switch (and a spent switch) while it holds, so the
  app-server is left running; a route change still restarts it.
- CodexAppStale / CodexDaemonStale say nothing, and `magpie accounts`'
  switch line says nothing needs restarting.
- Kept: route-change restarts (model_provider, openai_base_url,
  model_catalog_json, base_url, catalog hash: read only as the app-server
  starts) and the daemon's model-list restarts; and switch restarts when
  magpie writes requires_openai_auth = true (ChatGPT sign-in with room).

Run (mote-run; full suite at this change on e0ad48641):
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., go build for darwin/linux(nogui)/windows: ok.
- go test -tags nogui -timeout 45m ./...: 81 packages ok, no FAIL.
- New tests: TestCodexNoAccountSwitchRestartsNothing (provider),
  TestCodexNoAccountFollowsRequiresOpenAIAuth and
  TestCodexNoAccountOfEachConfig (agent).
- Broken by hand: codexNoAccount returning false in provider made
  TestCodexNoAccountSwitchRestartsNothing red (ended the app-servers);
  agent's codexNoAccount returning false made both agent tests red.
- Real codex-cli 0.165.0 in a sandbox CODEX_HOME with a provider table at
  requires_openai_auth = false: app-server account/read and getAuthStatus
  answered no account before and after auth.json was switched from a@x to
  b@x, and `codex exec` against a loopback capture server sent
  `Authorization: Bearer <the table's key>` with no chatgpt-account-id for
  both accounts.

After rebasing onto origin/main (2 commits: gateway desktop probe,
usage purposes): go vet ./... and go test of internal/agent, provider,
cli, usage and gateway at the pushed head: ok.

Not tried: the real Codex desktop app (macOS or the Windows MSIX) through
a switch; a daemon with live sessions through a switch; the GUI suite
(no GUI asset changed; the switch notice reads CodexAppStale).
2026-10-30 21:01:09 +08:00
yetone 0804f2d97d search: Tencent Cloud's Yuanbao Search (wsa) is a built-in search API (plugins#509)
chenjiangzi asked for Tencent Cloud's WSA SearchPro (元宝搜索). It is added
as vendor "wsa", following Doubao Search (dca3e2d71), from Tencent's
own docs:
- API-key method (cloud.tencent.com/document/product/1806/130615):
  POST https://api.wsa.cloud.tencent.com/SearchPro with
  Authorization: Bearer <key> and a JSON body {"Query", "Cnt": 10}.
  Keys come from console.cloud.tencent.com/wsapi/index (KeysURL).
- SearchPro (121811): Response.Pages is an array of JSON strings, each
  with title, url, date, passage and content. The text is passage, or
  content when passage is empty or only the title. Tags are stripped.
- Errors (121818/121820, 130615): HTTP 200 with Response.Error{Code,
  Message}. AuthFailure*, UnauthorizedOperation and ResourceNotFound are
  turned away (403); ResourceUnavailable (欠费), LimitExceeded and
  ResourceInsufficient are out of credit (402); RequestLimitExceeded* is
  rate limited (429); others are plain errors, with the key masked.

The fixtures in testdata are the docs' two example replies. 130615's is
shown with its quotes escaped twice, which isn't JSON; they were
unescaped once and nothing else changed. The GUI's picker is built from
SearchVendors, so no GUI file changes. README (en, zh), the CLI help and
gateway-routing.md name it.

Run on mote (mote-run), at the rebased head:
- go test -run 'SearchAPI|WSASearch|Volcengine|Search' ./internal/gateway/
  ./internal/gui/
  ./internal/provider/ ./internal/cli/: ok
- go vet -tags nogui darwin/linux/windows: ok; gofmt -l clean
- GUI (no GUI file changes; the picker reads SearchVendors):
  search-api.test.cjs in Chromium 4/4 ok. Its WebKit cases and
  searcher-pick timed out at browserType.launch (180s) on mote,
  where ~57 WebKit pw_run launches from several sessions hang. Not
  a result about this change; WebKit not run.

Broken by hand, each made TestWSASearchAPI red: the wsaSearchError call
removed, and Cnt dropped from the body.

Not tried: the real API. No WSA key was available, so the request,
reply and error mapping rest on Tencent's docs only. The full go test
./... is to follow.
2026-10-30 14:56:01 +08:00
yetone acbd6b11ab search: a search API's URL given with the path magpie adds is its base, never …/search/search (plugins#509)
chenjiangzi set Tavily's url to https://api.tavily.com/search, and magpie
appended /search again. Each vendor now names the paths magpie puts after
its base (SearchVendor.Paths). A url that already ends in one of them,
with or without a trailing slash and in any case, is cut back to its base.
This happens when it is saved (SetSearchAPI) and again when it is read
(SearchAPI.Base), so an entry saved before this change works too, and so
does Tavily's quota URL built on the same base. Every vendor is covered:
tavily, brave, exa, firecrawl, you (both paths), deepseek, volcengine,
searxng, and wsa in the next commit. A path of the user's own
(/my-search) is left alone. The url= help and gateway-routing.md say so.

Run on mote (mote-run), at the rebased head:
- go test -run 'SearchAPI|WSASearch|Volcengine|Search' ./internal/gateway/
  ./internal/gui/
  ./internal/provider/ ./internal/cli/: ok
- go vet -tags nogui for darwin, GOOS=linux and GOOS=windows on
  provider, gateway, cli (and gui on darwin): ok; gofmt -l clean
- GUI (no GUI file changes; the picker reads SearchVendors):
  search-api.test.cjs in Chromium 4/4 ok. Its WebKit cases and
  searcher-pick timed out at browserType.launch (180s) on mote,
  where ~57 WebKit pw_run launches from several sessions hang. Not
  a result about this change; WebKit not run.

Broken by hand: ownBase returning the URL unchanged made
TestSearchAPIBaseURLWithItsPath red ("asked /relay/tavily/search/search,
want /relay/tavily/search").

Not tried: a real Tavily request; the full go test ./... (to follow).
2026-10-30 14:56:00 +08:00
yetone 70a0c387cb agent: a provider named magpie written by hand is the user's, not connected (JFunfunfun on X)
Pi set up by hand on a provider of its own named magpie (magpie/<model>
at the gateway) read as connected in magpie: every catalog change wrote
magpie's list over that provider, RenameProvider rewrote its refs, Drift
offered Reconnect, and Disconnect took the provider out.

0911a65e7 (yyddbds, MiMo) already holds a ListOnly agent's sync until
it is Wired; that still let a hand-written config that names a magpie
model (JFunfunfun's Pi) read as Wired. Both gates now apply.
Its test's last case said a magpie model picked by hand on MiMo's own
magpie provider connects it; that is JFunfunfun's case, so it now
stays the user's until connected in magpie (listonly_test.go, and the
doc's ListOnly line says so).

An agent whose magpie is a provider of its own config (Spelled, not
Native) is now connected only when magpie set it up (setUp): a field in
applied.json, the new applied.Kept that Keep leaves instead of deleting
the record, or the <id>.connect.was stash Connect has written since
10-03. Otherwise (handWired) it isn't Wired, has no Drift, and
SyncCatalog, RenameProvider and renameRefs skip it; Disconnect is a
no-op as it is for any unwired agent. Connecting it in magpie takes it
on as before; Disconnect after that skips putting back "was" values
that were themselves magpie's (dsh errored on them). RenameLegacy
records the dial/ -> magpie/ values it writes, and moveEfforts (the
Cursor/Antigravity effort ids, at start-up) leaves a hand-written
magpie/<ref> alone. Aside keeps its own
key-based ownership. OpenCode's own-gateway-provider test now connects
through Apply as `magpie opencode` does.

Run (on mote, at this head, rebased on f2c6831a3): go test -tags nogui
-count=1 ./internal/agent ./internal/cli ./internal/library
./internal/gui; go vet darwin/linux/windows of internal/agent and
internal/cli; gofmt -l. internal/agent again after the ListOnly test
change: ok. Pushed on ceef9e943, whose five commits since touch usage,
sessions, library, provider movers and gui only.
New tests: TestPiHandWiredMagpieProviderIsTheirs (pi's literal
settings.json/models.json in a sandbox HOME, files byte-identical after
SyncCatalog, RenameProvider and Disconnect), TestPiConnectedBefore-
StaysConnected (applied record, gone model, connect.was, applied then
Keep), TestHandWiredMagpieProviderSiblings (29 Spelled agents). All fail
on the old code.
Tests that wrote a connected agent's files by hand (Pi, OpenCode,
Hermes, omp, dsh, the Kilo plugin, Cursor efforts, and the cli's
save-then-sync test) now also mark it as Connect leaves it
(setUpInMagpie, the connect.was stash); without it they read as
hand-written, which is what this change is about.

Broken by hand, each red: the Sync gate, the rename gates, the Drift
gate, Keep deleting the record, the was-skip in Disconnect, the
moveEfforts gate (TestMoveCursorEfforts' hand-wired case).

Not tried: a real pi binary against the gateway. Users connected
between 09-23 and 10-03 who pressed Keep (record deleted before this)
read as not connected; one Connect brings them back and pi keeps
working meanwhile. Agents without Spelled (Claude Code, Codex, Gemini
and others) decide by their own checks and are unchanged.
2026-10-30 14:45:56 +08:00
yetone f2c6831a31 gateway: a read-only gateway key reads quotas and usage and uses nothing (Steven on Discord)
Steven's ESP32 desk display polls magpie (Docker, on his LAN) every 15s
on GET /v1/magpie/quotas and /v1/magpie/usage and never sends a model
request. Only a key held to nothing was told the usage summary, so the
key kept in the device's flash had to be one that could spend every
account.

A gateway key can now be read-only (access.Key.ReadOnly):
- `magpie gateway-key add <name> --read-only`, `magpie gateway-key access
  <id> [read-only|full]` (`gateway-key --help` lists it; `list` has an
  ACCESS column), and "Make read-only" / "Give full access" in the key's
  menu in Gateway -> Gateway keys, with a "Read only" tag on its row.
- readOnlyGuard (internal/gateway/readonly.go), after callerGuard and
  before withCaller/keyLimited, judges the pattern ServeMux.Handler routes
  the request to. A read-only key is answered GET /, /v1, the quotas,
  their history and cards, the usage summary and its requests, its limit
  and the concurrency. Every other route is refused with 403
  gateway_key_read_only: every model route, count_tokens, the Responses
  WebSocket's upgrade, every MCP server, Codex's and Gemini's backends,
  /v1/models and the Ollama routes, the catch-all, the trace and route,
  debug profiles, and every write (usage ingest, quotas refresh). It is
  default deny, so a route added later is refused until it is classified.
- The key is held to nothing else, so heldKey leaves it alone: it reads the
  usage summary and every account's quotas, as a key held to nothing does.
  None of those routes holds a key's secret.
- The sharing key can't be made read-only, since magpie gives it to its own
  agents (LANSecret). Update refuses it, and the GUI item is off with why.

Older versions: a magpie from before this commit doesn't know `readOnly`
and treats such a key as a full one, so downgrading magpie widens the key.

Tests:
- TestReadOnlyKeyEveryRoute (internal/gateway/readonly_test.go) takes the
  patterns from the router itself (routes() records each HandleFunc). It
  fails when a pattern is in neither readOnlyRoutes nor its refused list.
  It sends every refused pattern, by each method it takes, from
  192.168.1.9 and from loopback, plus a WebSocket upgrade and an unclean
  chat path, and expects 403 gateway_key_read_only with the upstream never
  reached. It checks that every allowed route answers, that no body holds
  any key's secret or the upstream key, that the usage summary names the
  other key's use, and that a full key and a key made full again still
  reach the model.
- TestReadOnlyKey (access) covers add-key and access-key on and off,
  Authenticate, List, and the sharing key refused.
- TestGatewayKeyCLIReadOnly covers --read-only before and after the name
  and beside --key, access, the list column, bad values, and --help.
- gateway-key-readonly.test.cjs runs Chromium and WebKit, 1100 and 420px,
  in en/zh/zh-TW/ja/de. It covers the tag, both menu items and what they
  post, the status line, the sharing key's item off with its why, no
  scroll on click, no sideways scroll, no select, and no left stripe.
  gateway-card.test.cjs now expects the menu's 4th item.
- TestClientPathCoversHandler takes the patterns from routes() instead of
  parsing Handler's source, which moved into routes().

Broken by hand:
- readOnlyGuard passing everything: TestReadOnlyKeyEveryRoute red (103
  lines, /v1/models 200 onward).
- A new `POST /v1/new-thing` route in routes(): red, "in neither
  readOnlyRoutes nor readOnlyRefused".
- The GUI item not off for the sharing key: gateway-key-readonly red 10 of
  10 in Chromium.

Run at the pushed head (on origin/main 0911a65e7), on mote: TestReadOnly*,
TestHeldKey*, TestClientPathCoversHandler, TestGatewayKey*, TestCaller*
in access, cli and gateway ok; TestCoreScriptBudget ok; on Linux
(wsl-run, both engines) gateway-key-readonly, gateway-card, i18n-keys,
gateway-caller-keys and gateway-key-quotas 68/68.

Full Go suite on mote (macOS) at the same change on origin/main
dca3e2d71 (94630237d), -timeout 45m: 78 packages ok; internal/gateway
red only on the four TestAntigravityTurned* and
TestCodexSpentGrokFailingIsTold (red the same at origin/main, #4362);
internal/gui red only on ten AppKit window tests that hit their 30s
bar while mote's launchd throttled every app launch (#4125).

Run on mote (macOS) on origin/main dca3e2d71:
- go test ./internal/access ./internal/cli ./internal/gateway: access ok;
  cli red only on TestLibraryMCPHub's TempDir cleanup (#4140); gateway
  red only on the four TestAntigravityTurned* and
  TestCodexSpentGrokFailingIsTold, red the same at origin/main (#4362).
  TestReadOnly*, TestHeldKey*, TestClientPathCoversHandler,
  TestGatewayKeyCLIReadOnly pass.
- TestCoreScriptBudget ok (no budget raised). gofmt clean; go vet
  darwin (access, cli, gateway), GOOS=windows ./... and GOOS=linux
  -tags nogui ./... clean.
- GUI, earlier at 807048470 on mote: gateway-key-readonly,
  gateway-key-quotas, i18n-keys, gateway-card, api-key-theme,
  gateway-connect-keys and gateway-caller-keys 34/34 in both engines.
  At this tree mote's WebKit hung at launch for every test (#4125), so
  the 43 gateway-*/key-*/api-key-*/caller-*/menu-*/i18n-* files ran on
  Linux (wsl-run, both engines): 501 of 514. The reds in api-key-theme,
  gateway-key-limit, gateway-key-models, key-replace and menu-input-scroll
  are red the same at origin/main e8d42c02d (#4120, #3523, #4081, #4126,
  #3402); gateway-keys-empty's WebKit wait was red 1 in ~13 runs here and
  0 in 4 at main, filed as #4383 (this change doesn't touch its path).
- Full Go suite on Linux (wsl-run, at 807048470 with this change): reds
  only where Linux can't build the GUI (no gtk4/webkitgtk) and in
  internal/agent's install tests (#4033) and the gateway reds above,
  each red the same at origin/main dca3e2d71; plus
  TestClientPathCoversHandler, which parsed Handler's source and is now
  read from routes() (fixed here).

Not tried: a real ESP32 or Docker magpie; a remote client against a
running gateway (only httptest through lanGuard/Handler); the Windows
test runs (vet only); the whole GUI suite (mote's WebKit hung, #4125).
2026-10-30 14:33:01 +08:00
yetone 0911a65e7d agent: a catalog sync leaves a magpie provider the user wrote alone while the agent isn't connected
yyddbds on Discord: in Xiaomi MiMo they added a custom provider pointing
at magpie and picked a few models by hand. MiMo's switch on the Agents
page was off, yet after an update the provider held every one of
magpie's models. SyncCatalog runs at each start and update and on every
catalog change, and MiMo Code's Sync (openCodeLike) brought any
provider.magpie block up to the catalog whether magpie wrote it or not.
magpie's default went over a list the user set.

An Agent whose Sync does nothing but keep a block of magpie's name up
to the catalog is now ListOnly, and SyncCatalog runs it only while the
agent is Wired, which is what the Agents page's switch shows. The same
sync was in every sibling, so ListOnly is on all of them: openCodeLike
(OpenCode, MiMo Code and their WSL forms), piLikeKeyed (Pi and forks),
Goose, Crush, Air, AtomCode, Command Code, Droid, Fx, jcode, Kimi,
MiniMax, Mothx, omp, OpenChamber, OpenClaw, OpenPencil, Penguin, Qwen
Code and T3 Code. Left out on purpose: Codex, Claude, Grok and Hermes,
whose Syncs also repair while not connected (Hermes keeps its bots'
magpie provider current) and have their own gates.

Trade-off: a list magpie wrote while connected doesn't follow the
catalog while the agent runs a model of its own (switch off); it does
again once a model of magpie's is picked. Users whose list was already
written over: magpie keeps no copy of the old list, so it stays full;
from this release on it is left alone, and they trim it once by hand
(or connect the agent in magpie and use its model list's Pick).

Tests: TestCatalogSyncLeavesAHandWrittenMagpieBlock (MiMo, Pi and Crush
with a hand-written magpie block stay byte for byte; connected, MiMo's
list follows the catalog; disconnected and written by hand again, left
alone; a magpie model picked in MiMo, followed again).
TestListOnlyAgentsReadConnected: every ListOnly agent magpie connects
reads as Wired (n >= 15), so none of them loses catalog updates.
Fixtures of TestSyncCatalogRewritesAgentLists,
TestModelNameAndLevelsReachAgentFiles, TestSuffixModesReachAgentFiles
and TestPiKeepsTheirKeysInMagpiesProvider, and internal/cli's
TestSaveAnswersBeforeTheAgentsSync (its Pi settings were {}), now have
Pi connected (settings.json defaultProvider magpie), as a block magpie
wrote implies.
docs/subsystems/agent-wiring.md says the rule.

Run (mote, sandbox HOME via the tests' syncHome/codexHome):
- old code + the new test: red (MiMo, Pi, Crush written over; after
  Disconnect written over).
- broken by hand: ListOnly dropped from openCodeLike: red on MiMo
  (lines 52, 82); the Wired gate in SyncCatalog replaced with true: red
  on all three.
- go test -tags nogui -count=1 ./internal/agent: ok.
- gofmt -l clean; go vet ./... for darwin, GOOS=linux and GOOS=windows:
  ok.
- full suite, go test -tags nogui -count=1 -timeout 45m ./... at base
  3bebc3839 (logs kept in the worktree): every package ok but
  internal/cli (TestSaveAnswersBeforeTheAgentsSync, mine, fixture fixed
  above, then ok alone) and internal/gateway: TestAntigravityTurned*,
  TestAntigravityTurnsCodexsGPT5ThreadAwayOnce and
  TestCodexSpentGrokFailingIsTold, red the same on a fresh origin/main
  b26fa0903 copy, filed as #4362.
- rebased on e8d42c02d: vet (darwin, linux, windows) of internal/agent and
  internal/cli, and go test of internal/agent, internal/cli,
  internal/library and internal/gui: all ok. Pushed on 764a032f6,
  whose three commits since touch gateway, usage, provider and chat only.

Not tried: the real Xiaomi MiMo desktop app (the fixture is the OpenCode
shape MiMo Code writes; whether the reporter's provider id is literally
"magpie" is unconfirmed: a provider of another id was never touched).
Lists already written over are not restored.
2026-10-30 14:25:38 +08:00
yetone dca3e2d716 search: Doubao Search (Volcengine) as a search API (CyberCaius on Discord)
CyberCaius asked on Discord #help (10-30) for Volcengine's Doubao search
under Settings › Models › Search APIs, or a custom API address. Volcengine's
Doubao Search Custom (豆包搜索 Custom版, once 联网搜索 / 融合信息搜索,
docs.volcengine.com/docs/networked-search/networked-search, the same page
as volcengine.com/docs/87772/2272953) can now be added with its API key:

- provider.SearchVendors: volcengine, "Doubao Search (Volcengine)", at
  https://open.feedcoopapi.com, keys at
  console.volcengine.com/search-infinity/api-key, after DeepSeek. The GUI
  takes its vendors from SearchVendors, so it shows in the Search API
  picker with its Get a key link and base URL field; no GUI file changes.
- askSearchAPI: POST /search_api/web_search, Bearer key (the default, as
  the docs and volcengine/mcp-server's askecho_search_infinity send it),
  body {Query, SearchType: "web", Count: searchHits, Filter: {NeedUrl:
  true}}. The query is cut to the 100 characters the docs allow. NeedUrl
  leaves out its 火山如意 cards, which have no URL to cite.
- readVolcSearch reads Result.WebResults: Summary as the page's text (the
  docs recommend it for models; Content is the whole page, Snippet
  ~200 chars "only for list display"), Snippet when there is no Summary,
  PublishTime as the page's age, a 1970-01-01 time (its image example's
  stand-in) as none, and a result with no Url left out.
- volcSearchError: its errors are in ResponseMetadata.Error, a code the
  docs list, and the docs don't say the HTTP status, so the code decides:
  10401/10403/10409 rest the key as turned away (403), 10406/10408/
  10410/10412 (free searches spent with none paid, no plan, plan spent)
  as out of credit (402), 700429 as rate limited (429). Any other code is
  a plain error, a 200 carrying one included. The key is masked in the
  error as for every vendor.
- A custom address: every search API already takes a base URL (#1580,
  the field under the key in Settings, url= in the CLI), so an endpoint
  that answers as Tavily, SearXNG, Brave, Exa, Firecrawl, You.com,
  DeepSeek or now Doubao Search does can be set there. There is no common
  format across the vendors (each has its own path, body and reply), so
  no separate "custom" vendor was added.
- Siblings: CLI usage (main.go, search_cli.go's api list and empty-state
  hint), README.md, README.zh-CN.md, gateway-routing.md's path list and
  refusal paragraph.

The test's reply is the docs' own web-search response example, byte for
byte (testdata/volcengine_web_search.json); its error replies are the
docs' error example with its "// 该字段为错误码" note taken out (not JSON).
Not tried against the real API: no Volcengine search key in this run.

Run (worktree on origin/main c941e0877, then rebased on d31710c71):
- TestVolcengineSearchAPI (new): red on the old code (no such vendor).
  Broken by hand six ways, each red with its own message: Summary not read
  (Snippet's text), volcSearchError not called (200 10403 read as "no
  Result in it"), query not cut (150 characters went), NeedUrl dropped
  (body {"Filter":{}}), 1970 age kept, 10412 not mapped (plain error, not
  a refusal). Restored: ok.
- go test -run Search ./internal/gateway/, go test ./internal/provider/
  ./internal/cli/: ok, before and after the rebase.
- gofmt -l internal: nothing. go vet -tags nogui ./... on darwin,
  GOOS=linux, GOOS=windows: ok.
- Not run before the push: the full go test ./... . mote had three other
  sessions' full suites running at load 140-230; it runs after the push
  and its result goes on the report.
2026-10-30 13:28:45 +08:00
yetone e887139e7a providers: Best in family serves the newest model of each family a provider lists
Steven on Discord #feedback asked for a provider to serve only the newest
model of each family, so a newer one (Opus 5.6) takes the old one's place
without re-picking.

The provider editor's Models control gets a fourth option, beside
Vendor's list / Picked only / Usage only: Best in family. It is also on the
CLI as `magpie provider models <id> best`. With nothing picked, the provider
serves only the newest model of each family in the vendor's list, up to 24.
A family is the id with its version numbers taken out
(catalog.FamilyOf/BestInFamily in internal/catalog/family.go). A dated
snapshot counts as its alias, and sizes and suffixes (mini, flash, -fast,
-thinking) stay part of the name. Provider.Exposed applies it, and so does
Codex's native list (CodexNativePicked). A provider/model a request names
explicitly is still served, since resolve doesn't go through Exposed. A pick,
Select none or Usage only clears the flag (normalize), and a providers.json
without bestInFamily reads as before, so every existing mode is unchanged.
The editor draws the family's newest as dashed (m.best) before saving. Every
language has the wording (zh, zh-TW, ja, de). The design reference is
docs/subsystems/providers-accounts.md (Model picks).

Tests: family_test.go is a table of real ids, including the models.dev Claude
list in testdata (no network). There are also best_in_family_test.go
(provider), TestProviderModelsBest (cli), provider_save_best_test.go (gui
save keeps/clears), codex_best_in_family_test.go (gateway) and
provider-best-in-family.test.cjs (5 languages x chromium/webkit x 1100/420).

Broken by hand: with the BestInFamily filter in Exposed and in
CodexNativePicked turned off, the 4 new Go tests went red.

Budget: after the rebase app.js went over appScriptBudget. Comments were cut
and the tooltip and hint merged into one string, so app.js is 1,311,399 of
1,311,735. Neither budget was raised.

Run at this head, on origin/main 1027db408, via mote-run (macOS 27):
- gofmt -l clean; go vet clean for darwin, linux -tags nogui and windows
  (at base 05a6087e1, the same Go diff).
- go test -count=1 ./internal/catalog ./internal/provider ./internal/cli
  ./internal/gateway: ok.
- go test ./internal/gui: everything except TestMainWindowCorners/macOS_26_SDK
  (red on macOS 27, #3949; not this change).
- node --test: provider-best-in-family, provider-none-picked,
  provider-picked-only-shows-picks, i18n-keys, gui-de, gui-ja, gui-zh-tw,
  context-map and gateway-key-models, 113 tests, 108 pass. The 5 reds are
  context-map 420px "two tiles overlap" (#3488, #4304) and gateway-key-models
  webkit en (#4304). Both fail the same way on a clean origin/main 1027db408
  checkout run alone (8 of 30 red there).
- The earlier wider GUI run (38 provider/routing files, concurrency 3) had
  the same red files on origin/main deb0b8da7 as at this change's head:
  model-chip-steady, models-works-only, provider-fetch-again and the others
  in #4304. Three with no issue were filed: #4320 (recovered-file),
  #4321 (tencent-cloud), #4322 (warm-now).

Not tried: no real account or real magpie app; the editor was checked
through Playwright screenshots only. Families are read off the id alone, so
a vendor whose ids don't put the version in numbers (or orders them
oddly, e.g. grok-4.20 against grok-4.7 compared numerically) may group
or rank unexpectedly. Bedrock's -v1:0 counts as version digits.
2026-10-30 04:48:17 +08:00
yetone 4054251865 library: an MCP server can be kept to this computer, never synced
huhuy72219405 on X: "能不能把不同设备的mcp区分一下,有些mcp属于本地的,
同步之后其他设备不应该读取到". A server in Library > MCP now has a
"This computer only" switch in its editor (Server.Local; CLI
`magpie library mcp add ... --local` and `magpie library mcp local
<name> on|off`; the TUI keeps it on edit and marks the row).

- Collect leaves local servers out (carriedServers), so neither a sync
  nor a backup file takes one to another computer. Turning a shared
  server local takes it out of what is carried, so the other computers
  drop it at their next sync; the flag itself is never carried.
- Put (sync, join, Restore, Undo, backup file) keeps every local
  server, with its agents, and clears Local on what comes in.
- Another computer's server by a local server's name goes to
  Library.Away: given to no agent, not in the hub, carried on as it
  came, so a push from here never removes it from the computers that
  have it. settleAway (every change) promotes it once the name is gone
  here, and drops it once the name is shared here again.
- The hub serves local servers like any other (it runs here);
  subagents aren't carried, so one naming a local server keeps it.

Docs: docs/subsystems/library.md, docs/subsystems/sync-backup.md.

Run at f5dd4e142 + this change; after rebasing on d3898ca8d (gui/provider only, then 2a1ef15ba, routing), vet, the five new Go tests, mcp-local-server and i18n-keys again, ok:
- mote: gofmt -l clean; go vet of library/backup/davsync/cli/tui;
  GOOS=linux and GOOS=windows go vet -tags nogui of the same; go test
  of TestLocalServerNotCarried, TestPutKeepsLocalServer,
  TestPutSameNameAsLocal (library), TestRestoreKeepsLocalServer
  (backup), TestLocalServerThroughSync (davsync, two computers through
  the fake S3) ok.
- mote GUI, Chromium and WebKit: mcp-local-server.test.cjs (new; every
  language, 1100 and 390 wide, switch saves local true/false, row tag,
  no sideways scroll), i18n-keys, mcp-editor-cancel,
  mcp-startup-timeout, every library-mcp-*, mcp-oauth-app, mcp-signin*,
  library-items, library-servers-bulk, library-subagents,
  library-pick-remove, library-env-refs, library-zed-mcp,
  library-loading: all pass (126 of 126 in the last batch).
- Full Go suite, -tags nogui -timeout 45m, on the Linux box (wsl-run;
  mote had another session's full suite running): every package ok
  but internal/agent, whose TestInstalledVersion, TestGrokInstalled,
  TestOmpDetectedWithPiDir and TestZedAppPath fail the same at
  origin/main 9b4d0bda8 on that box; all four are #4033.
- Real CLI in a sandbox HOME on mote: mcp add --local, local on/off,
  `magpie library` shows "this computer only", library.json has
  "local": true; an unknown name and a bad value are refused.

Broken by hand: putServers not keeping local servers turned
TestPutKeepsLocalServer, TestPutSameNameAsLocal,
TestRestoreKeepsLocalServer and TestLocalServerThroughSync red;
carriedServers carrying local servers turned TestLocalServerNotCarried,
TestPutSameNameAsLocal, TestRestoreKeepsLocalServer and
TestLocalServerThroughSync red.

Not tried: a sync between two real computers; the real GUI app (the
Playwright run fakes the API); the full Go suite on macOS or Windows.
2026-10-30 02:31:08 +08:00
yetone 05a6087e1f access: a key with accounts and no model may use only its accounts' providers' models
Linka on Discord (#feedback): in a gateway key's "Models this key can
use", ticking only an account and no model let the key list and use
every model of every provider.

Cause: Key.Models empty meant "every model", and Key.Accounts (#905)
held only the providers it names, so every other provider stayed open.

Change: access.HeldModels gives a key with accounts and no models the
models "<provider>/*" of each account's provider. Authenticate builds
the Identity with it, so every route's existing model gate narrows:
/v1/models, /v1beta/models, chat, responses, messages, Gemini,
count_tokens, embeddings, images, the Codex backend path, System One,
groups and fallbacks. A key that lists models is unchanged (#905: its
accounts still hold only the providers they name); a key with neither
is unchanged. The CLI's MODELS column and `gateway-key models` say so,
and the GUI editor's hint, the "not used" notes on providers no model
or account reaches, and the save status follow (en, zh, zh-TW, ja, de).

Tests:
- TestGatewayKeyAccountsOnlyHoldTheModels: each route above is 403 for
  the accounts-only key and no upstream call reaches the other
  provider, the decider or the image provider; its own provider, a
  group of it and a key that also lists models work. Red on the old
  code on every route (list showed spare/m2, chat/count_tokens/
  embeddings/systemone 200).
- TestHeldModels (access).
- gateway-key-accounts.test.cjs: hint, notes and status; 4/4 red on
  the old assets, green on the new.
- TestGatewayKeyAccountsListModels / SystemOne / OfANamedProvider and
  TestHeldKeyToldItsOwnQuotas now encode the new rule (the held key is
  told only its own provider's quotas).

Run on mote: gofmt -l clean; go vet darwin, linux -tags nogui, windows
on access, cli, gateway, gui ok; go test -timeout 45m ./internal/access
./internal/cli ./internal/gui ./internal/gateway: ok except gui's
TestMainWindowCorners/macOS_26_SDK (#3949, not this change) and
gateway's TestHeldKeyToldItsOwnQuotas, updated and rerun ok. After the
rebase on 1f03d7546 the key tests ran again ok. GUI: gateway-key*,
i18n-keys, gui-de, gui-ja, gui-zh-tw in Chromium and WebKit: 131 pass.

Not tried: a plugin-served provider (same model gate), a real
account, Windows and Linux test runs (vet only).
2026-10-30 01:25:57 +08:00
yetone af8f3a9399 sessions: a new install reads no agent's session history until the user allows it (RustCats on X)
RustCats on X: a fresh magpie showed every agent's session history on
the Sessions page before anyone agreed to it, and asked for a per-agent
choice instead.

- sessions.Reads(agent) (internal/sessions/access.go) is the one gate,
  from settings.SessionReads {Asked, All, Agents}. Every lister asks it,
  the aggregators (allFiles, callFilesWith, callSourcesWith,
  traceLineFiles, wslFiles, DesktopDataDirs) filter by it again, and
  readers of an already-listed session (TranscriptOf, ContentOf,
  SearchSession, SubagentTranscript, CarryOver, ReadCallSource) return
  ErrNotRead, so a cache from before a switch was turned off goes no
  further. The Sessions list, stats, /api/sessions/overview, the call and
  trace indexes, Usage's agent-file calls and the Codex/Pi title readers
  all pass it.
- SettleReads decides once and saves: an install with sessions.json or
  a calls-v* cache read sessions before and keeps all on; a fresh one
  reads none, not asked. A saved value is never replaced; save, sync and
  restore keep it (KeepOwn); only SetSessionReads writes it. An
  unwritable settings.json reads nothing this run.
- GUI: GET/POST /api/sessions/reads. While not asked, the Sessions page
  shows a consent card: each agent found (by a stat of its folder only)
  with a switch, Allow selected and Allow all. Settings > Privacy >
  Agents' session history has "Agents found later" and a row per agent.
  Strings in en, zh, zh-TW, ja, de.
- CLI: magpie sessions read [on|off all|<agent>...]; magpie sessions
  says on stderr when nothing is allowed yet; the TUI's empty Sessions
  page says how.

Read either way, because none of it lists or shows a session: the
gateway's own usage ledger, its projections and the conversations it
recorded (magpie's own records, so usage and cost keep working); the
agents' config and sign-in files; Claude Code's and Codex's
history.jsonl last-used time and a session file's mtime for a quota's
first use; Codex's newest rollout's last line before magpie restarts
Codex (codexTurnOpen).

Tests: TestFreshInstallReadsNoAgentUntilAllowed,
TestSettleReadsKeepsWhatWasThere, TestSessionReadsRoutes,
TestSessionsRead, TestSessionsNotAskedSaysHow, sessions-reads.test.cjs
(26 cases: consent and Settings in 5 languages, Chromium and WebKit,
390 to 900 wide).

Run on mote:
- full Go suite (gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui,
  GOOS=windows go vet, go build, go test -timeout 45m ./...) at this
  change on 8c63c5b78: 79 packages ok; internal/gui red on
  TestSettingsSaveKeepsWhatItDoesNotSend (mine: SessionReads is written
  by SetSessionReads only, the test now sets it so; green after) and
  TestMainWindowCorners (the same on origin/main c1da9ccda, #3949).
- whole GUI suite (make test-ui, concurrency 2) at this change on
  8c63c5b78: 14985 tests, 276 failed in 44 files. Mine: i18n-keys
  (comments named "Allow all"/"Allow selected"; lowercased) and
  account-discovery (read the last Privacy heading; now the one above
  its list); both green after. The 44 files again on origin/main
  c1da9ccda: 36 red there too (#4304, with #3218, #3412, #3414, #3795,
  #4120, #4125). stays-strict green alone; gateway-key-models webkit red
  1 of 3 alone on main too; plugin-github de 440 red on main (#3218).
- at the pushed head (rebased on cd10dfbe6): go build ./...; go test
  internal/sessions, settings, cli, tui ok; internal/gui
  TestSettingsSave*, TestSessionReads*, TestSessions* ok; i18n-keys,
  account-discovery, sessions-reads: 62 pass, 0 fail.

Broken by hand:
- the aggregator filter off with the leaf gates on: green (the leaf
  gates hold); both off: TestFreshInstall red on List, Agents, Calls,
  CallSources, traces, stats, TranscriptOf and Search.
- consentApplies=false and Settings' old save({all}) without the rows:
  all 13 Chromium cases of sessions-reads red.
- sessNothing's hint removed: TestSessionsNotAskedSaysHow red.

Real binary in a sandbox HOME on mote (removed after): a fresh
`magpie sessions` is empty with the hint on stderr; `sessions read`
says not asked, claude off; `read --help` prints usage and saves
nothing; `read on claude` lists the one session; `read off all`
empties it again.

Not tried: the GUI and real app on Windows and Linux; WSL agents in the
consent list (WSL distros are not looked into; Allow all covers them);
a fresh install of a signed release build.
2026-10-29 23:56:05 +08:00
yetone fd5c631cbe image mcp: generate_image and generate_video take the model to use (XYenon)
XYenon on Discord asked whether an agent can pick the model magpie's
image/video MCP draws with. Both tools now take an optional `model`,
as provider/model:

- The schema lists the models that may be asked (the Settings default
  first, then each on provider's OfferedDrawers or Videomakers), only
  those the calling gateway key may use. Up to 40 of them form an enum;
  past that, the description names three.
- Left out, the Settings default is used, as before.
- A bare id only one provider has, a ChatGPT account's other GPT Image
  name (ListedDrawer), or a newer family model (drawsFamily,
  grokVideoFamily) is accepted. Anything else is a tool error naming the
  models the key may use, and nothing is drawn. It never falls back.
- The chosen model goes into the images/videos request's `model`, so
  the APIs' own key check (keyHolds, keyModelError, #882) refuses one
  the key may not use: the same check /v1/images makes.
- The stdio Magpie Image server copies the gateway's `model` property
  from its tools/list, and asks the hidden JSON-RPC method
  magpie/media_model which model a call means. An older gateway
  (-32601) passes the model through as named.
- `magpie tool generate_image --model ...` works through the schema;
  the usage text says so.

Docs: gateway-routing.md (image MCP section), reference.md.

Run (mote, via mote-run, at this tree):
- gofmt -l: clean.
- go vet ./... for darwin, GOOS=linux -tags nogui, GOOS=windows: ok.
- go test -count=1 -timeout 45m ./internal/gateway/ ./internal/imagemcp/
  ./internal/cli/: ok.
Broken by hand: with `req["model"] = ref` dropped in imageMCPDraw and
imageMCPFilm, TestImageMCPDrawsWithTheModelAsked,
TestImageMCPModelHeldToTheKey and TestImageMCPVideoModelAsked go red
(the default was drawn instead); restored, they pass.
Not tried: a real vendor account. The fakes are easeled's art provider
and the fake Grok. GUI files not run: no GUI file changed.
2026-10-29 22:16:56 +08:00
yetone 3ce2a9819f library: RTK for agents in WSL, with the distro's own rtk (lex on Discord)
lex: Claude Code and other agents in WSL couldn't use the RTK of magpie
on Windows. rtkAgents looked an agent up in rtkSpecs by its whole id, so
claude@wsl:Ubuntu never matched and WSL agents weren't on the RTK page at
all. Even matched, the specs read this machine's home, and Windows' rtk.exe
is no command inside the distro, where the hook runs.

Now an agent is looked up by its kind (rtkKind). One in WSL:
- has its files read and written under the distro's home as magpie opens
  it (rtkClaudeDir, rtkCodexDir, rtkHome), with blocked/version checks
  against the distro's rtk and OpenCode;
- uses the distro's own rtk: rtkDistroOf asks the distro (wsl.exe -d <d>
  -e sh -lc) where rtk is on its shells' PATH, else in ~/.local/bin or
  ~/.cargo/bin (offPath), kept 15s; ReadRTK lists one RTKDistro per distro;
- switching on runs that rtk there (rtk init -g ..., its folder on PATH);
- Install RTK in WSL <distro> (POST /api/library/rtk/install {distro},
  magpie library rtk install <distro>) runs RTK's own Linux installer in
  the distro (curl, or wget).
A distro that isn't running is never started (#3896): its agents are
listed asleep with the switch off, and switching or installing says to
start it. The page has a card per distro (install, off-PATH, asleep) and
uses the distro's rtk for each WSL row's tags and switch; strings in zh,
zh-TW, ja and de. The install route now refuses a body it can't read
instead of installing on this computer.

Run:
- mote (macOS 27), at origin/main ec8fe29b8 plus this: gofmt -l clean;
  go vet darwin, GOOS=linux -tags nogui, GOOS=windows for internal/library,
  internal/gui, internal/cli: ok. go test ./internal/library ./internal/cli
  ok; ./internal/gui: TestMainWindowCorners/macOS_26_SDK red (#3949, open,
  mote's macOS 27), everything else ok; -run Library ok after the route
  change. node --test library-*.test.cjs + i18n-keys in Chromium and WebKit:
  828 tests, 3 red, all library-row-remove (#3099, open; 1 of 2 runs alone
  is red the same); library-rtk-*.test.cjs + i18n-keys at the pushed base:
  180 pass. New library-rtk-wsl.test.cjs: en, zh, zh-TW, ja, de at 980 and
  380px, both engines.
- New TestRTKWSL / TestRTKWSLAsleep (fake wsl.exe runs the real probe
  script with sh, the distro's home as HOME). Broken by hand: the old
  rtkSpecs[a.ID] lookup makes TestRTKWSL red (claude@wsl not on the page).
  Also ok on Windows (win-run) and Linux (wsl-run), -run 'RTK|WSL'.
- Real WSL, xiaomi-gpu with magpie-desktop (Ubuntu 24.04): from Windows,
  through real wsl.exe and the exact rtkWSLScript/rtkWSLProbe/rtkInitWSL
  strings, with HOME set to a throwaway folder in the distro: RTK's
  installer put rtk 1.1.0 in ~/.local/bin, the probe found it (on:0, not
  on that bare PATH), rtk init -g --auto-patch wrote "rtk hook claude" into
  ~/.claude/settings.json, and sp.has read it back over
  \\wsl.localhost\magpie-desktop\.... ReadRTK on Windows lists
  claude@wsl, codex@wsl and pi@wsl:magpie-desktop with an install offered.

Not tried: a real Claude Code session in WSL running a command through
the hook; the install and switch in the distro's real home (only the
throwaway HOME); the real GUI window on Windows; OpenCode, Gemini, agy,
Hermes, OMP in WSL (same code path, not run for real).
2026-10-29 19:58:40 +08:00
yetone c1da9ccda3 library: a stopped WSL distro's agents are listed, and a tick for one is written there once it runs (cybercaius on Discord)
cybercaius: with WSL not started, the Library's MCP page didn't list the
agents in the distro at all, and nothing ticked for them could be kept.
A stopped distro's agents are no targets (#3896: opening their files
starts the distro), so they fell off the page.

While a distro runs, each agent's places and what its MCP file takes are
kept in wsl.json (keepShape, agent.WSLKeep, key library:<kind>). While it
is stopped, Read lists its agents from that (asleepView, asleep: <distro>)
with the library's ticks; one magpie never saw is listed only on rows that
name it, as unseen, its chip disabled and kept by every click (keptOf). A
tick on a stopped agent is kept in library.json (Takes accepts a known
shape, serversAgents judges it by shape.reaches); nothing is opened or run
in the distro. Woken, from KeepLinked's 30s loop, syncs once a distro the
library names goes from stopped to running (wsl.exe -l --running starts
nothing). The page greys a stopped agent's chip and says why in its
tooltip and one line per distro; the MCP hub leaves them out. The CLI says
the same on stderr (AsleepIn). en, zh, zh-TW, ja, de.

Run at this tree (20695ad8b before this message; on adc618bbf):
- mote: gofmt -l clean; go vet -tags nogui for darwin, GOOS=windows and
  GOOS=linux on internal/library, internal/agent, internal/cli; go test
  -tags nogui -timeout 45m ./internal/library ./internal/agent
  ./internal/cli: ok (internal/gui ok too at the 96a703a59 base).
- WSL magpie-desktop: library-wsl-asleep, i18n-keys, library-gone-agents,
  library-items and library-mcp-hub, Chromium and WebKit: 88/88. At the
  96a703a59 base every library-*, mcp-*, skill-* file and i18n-keys:
  1148 of 1164; the reds were library-chip-fan (WebKit),
  library-mcp-tools (chromium ja 420), library-items and
  skill-group-shared (WebKit) beside another session's full GUI suite.
  Alone, library-items and skill-group-shared pass, and chip-fan and
  mcp-tools are red the same on an origin/main 96a703a59 copy (#4120,
  commented).

Broken by hand: asleepView returning nothing made TestWSLStoppedListedAndQueued
("a stopped distro's Codex isn't listed") and TestWSLStoppedUnseen red;
Woken never syncing made TestWSLStoppedListedAndQueued red ("no sync once
the distro ran"); keptOf without unseen made library-wsl-asleep red in
all 10 Chromium cases (Pi's tick dropped by a click on Claude Code).

Rebased onto fa2332976 (gateway, provider and Codex effort commits, nothing
in internal/library, internal/agent/wsl or the Library page) before the
push: go vet of the three packages and go test -run TestWSL
./internal/library ok there; the full packages ran at adc618bbf.

Not tried: a real distro stopped and started. magpie-desktop was running
another session's full GUI suite, which stopping it would have killed, and
the other distros are other people's. The tests use FakeWSL, which counts
every wsl.exe -d command run in the stopped distro (none). Not changed:
the Instructions, Hooks and Subagents pages still leave a stopped
distro's agents out (#4182, #4237, #4238).
2026-10-29 18:34:44 +08:00
yetone 96a703a591 uninstall: magpie uninstall and Settings › Uninstall magpie put every agent back before magpie's files go
Jevik_AI on X (Windows, portable magpie) deleted magpie's folders by hand.
~/.codex/config.toml kept openai_base_url on 127.0.0.1:3425, and every
Codex turn then failed with a 502, with nothing left that knew why.
Deleting magpie's files never puts an agent back, so there is now an
uninstall that does.

- internal/uninstall: Run goes in this order. System removes the
  background service, opening at login, the Start menu shortcut
  (shortcut.Remove, with its App Paths key), the magpie:// links and the
  privacy model's helper. Agents ends Codex's account failover, then runs
  each connected agent's own Disconnect, or its offline disconnect for an
  app that is closed. That is the same code as the Agents page, so a value
  the user changed by hand since Connect stays theirs (e7f21dba5 for
  Codex). It then ports Codex's rollouts and restarts the Codex app's
  app-server (provider.RestartCodexAppWhenIdle, which says whether one was left on
  the old config). Data deletes magpie's folders, but keeps the Library's
  folder while it holds skills, servers or hooks the user's agents use.
  The executable is left where the user put it.
- `magpie uninstall [--yes]`: refuses while another magpie runs, and
  says which one. On a terminal it lists what goes and asks [y/N]; with
  no terminal, only --yes does it.
- Settings › About › Uninstall magpie: POST /api/uninstall runs System
  and Agents. If anything failed, nothing else is removed and the sheet
  offers Try again. Otherwise POST /api/uninstall/finish starts a
  detached `magpie uninstall --data-after <pid>` (Setsid on unix,
  DETACHED_PROCESS on Windows) and the app quits; the files go once it
  has ended, since WebView2 holds its folder open until then. A Codex app
  still on the old config is named before quitting. magpie web refuses
  both routes. Strings go through t() in all five languages.
- --data-after refuses a pid that is no process (0, negative, its own):
  kill(0) counts as alive, and a run given 0 waited out its 2 minutes.

Not done, and why:
- No restore on quit. Quitting keeps agents on magpie by design: the
  service or the next start serves them.
- No Apps & Features entry or Windows uninstall hook. A portable copy
  registers nothing with Windows, and an uninstaller that ran without
  magpie's own disconnect would leave the configs as they are. The
  `# magpie:` note above each line magpie writes (previous commit) is the
  recovery path for a copy deleted by hand.

Run at this head (db75663a0's tree, on 5d24bc6cc), on mote:
- gofmt -l clean; go vet ./... on darwin (-tags nogui), GOOS=windows and
  GOOS=linux -tags nogui: ok.
- go test -tags nogui -count=1 -timeout 45m on ., internal/uninstall,
  cli, gui (TestCoreScriptBudget included), provider, shortcut, edit,
  agent and proc: all ok.
- GUI at this head: mote was at load 100-120 with other sessions' GUI
  runs. Chromium crashed (SIGBUS) mid-file in settings-search and
  settings-sections after their en cases passed, WebKit failed to launch
  within 180s in s3-sync, settings-search and settings-sections, and
  fonts and title-bar-tools went red on unstable elements (#2984 has
  fonts under load). uninstall-settings had not reported when this was
  pushed.
- At the earlier base b3580c72c, on this machine: the full suite
  (-timeout 45m), red only on #3884, #3632 (both since fixed on main) and
  the core budget, which main's later move of Web search out (#4133) has
  room for now. GUI: 104 Settings and i18n files in chromium and webkit,
  uninstall-settings and i18n-keys green in both; the reds were #3797,
  #3876 and the load reds above.

Tried for real, in a sandbox HOME: `magpie uninstall` end to end with
Codex connected and a sandbox Codex app running (config.toml back
without magpie's lines, magpie's data gone, the exe kept, the app's
app-server restarted onto the restored config); codex-cli 0.162.1
reading the noted config.toml. Other agents were covered by tests only.
Not tried: the GUI's Uninstall in a real app window, a real
--data-after run waiting on a live app's pid, and the Windows box.

Broken by hand: --data-after's pid guard removed ->
TestUninstallDataAfterNeedsAProcess red (0, -1 and its own pid
accepted); restored, green.

At the pushed head (rebased on 51f66fe8b; the uninstall call adapted to
EndCodexFailover's (bool, error) on the way), on mote:
- gofmt clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ok;
  go build ./... ok.
- go test -timeout 45m: internal/uninstall, edit, shortcut, cli, agent,
  provider ok; internal/gui red only on TestMainWindowCorners/macOS_26_SDK
  (#3949, macOS 27).
- GUI: uninstall-settings and i18n-keys, 30 pass 0 fail.
- WSL (magpie-desktop, CGO_ENABLED=0): uninstall, edit, shortcut,
  provider ok; agent red on TestGrokInstalled, TestOmpDetectedWithPiDir,
  TestZedAppPath, the same at origin/main 51f66fe8b (#4033, #3548).
2026-10-29 17:47:30 +08:00
yetone 0c4e3455ee agents: a line magpie writes into a TOML, YAML or env config has a note above it saying so
Jevik_AI on X deleted magpie's folders by hand. Codex's config.toml kept
openai_base_url = "http://127.0.0.1:3425/backend-api/codex", with nothing
in the file naming magpie, and every Codex turn failed with a 502.

Each line magpie writes that points at the gateway, or at magpie's model
list, now gets a comment line of its own just above it:

  # magpie: Codex on magpie's local gateway; Disconnect in magpie or
  #   `magpie uninstall` undoes it, or delete this line and the model line
  model_provider = "magpie"

- Only a line the write adds or changes, or one that had a note, gets one.
  A line of the user's own that magpie leaves alone gets none.
- The note is never on the value's line. Grok App's providers.rs reads the
  rest of a line as the value, and an end-of-line comment broke
  TestGrokApp in a first try.
- Every write takes the notes out and puts back the ones still needed, so
  a note goes with its line and Disconnect leaves none.
- No note in JSON. A YAML note that would change what the file reads as
  isn't added.
- Wired in run (agent.MarkWritten); tests leave edit.Mark nil so their
  exact bytes stay.

Run at this commit's tree (worktree, sandbox HOME, private GOCACHE):
- gofmt -l clean; go vet darwin, GOOS=windows, GOOS=linux -tags nogui ok.
- go test -tags nogui -run Mark ./internal/edit ./internal/agent: ok.
- ./internal/agent and ./internal/edit whole with edit.Mark forced on for
  every test (a snapshot with lineNote set in agent's TestMain): edit ok;
  agent fails only TestDshRouteKeepsTheAPIPickedInDsh and
  TestDshSearchThroughGateway, which compare exact bytes and see the note
  line. With Mark unset (as shipped) they pass.
- Real Codex: built magpie from this tree, `magpie codex fakeai/fake-1` in
  a sandbox HOME. config.toml got the three notes above model_provider,
  model_catalog_json and openai_base_url; `codex mcp list` and `codex
  features list` (codex-cli 0.162.1) read it, rc 0, and Python's tomllib
  reads the same values. `magpie codex default` took them out.
- Broken by hand: a note on every line, not only changed ones ->
  TestMarkTOML and TestMarkOnlyWhatMagpieWrites red.

- The notes' line filter is withoutNotes, unexported: an exported
  Unmarked put a word the routing plugin translates into a Go file, and
  i18n-keys' "a plugin's words are its own" went red on it. It passes
  now.

Full suite: run with the uninstall commit that follows, recorded there.
2026-10-29 17:42:35 +08:00
yetone 4534561f6b codex: a thread open when magpie quits goes on through a relay, not a 503
idkatbro on X: a Codex session started while magpie was open keeps
failing after magpie quits with "unexpected status 503 Service
Unavailable: Unknown error, url:
http://127.0.0.1:3425/backend-api/codex/responses", until magpie is
opened again.

Cause: Codex signed in to ChatGPT, with more of its accounts on in
magpie, gets openai_base_url = the gateway's /backend-api/codex
(failover). At quit EndCodexFailover takes it out of config.toml, but
a thread already open, in the Codex app and its app-server above all,
keeps the base URL it started with. Every turn after went to a closed
port. With a system or env proxy in between, the proxy answers 503
with an empty body, which Codex shows as "Unknown error"; without one
Codex says "Connection refused" and reconnects. Reproduced on mote
with codex 0.162.1 and a proxy answering 503 for the closed port.
Masking plays no part: it runs only in the gateway, is opt-in, and its
own 503 carries a readable message.

Fix: when quit really ends failover (EndCodexFailover now says so),
the gateway is on loopback, and Codex processes run
(provider.CodexPIDs), magpie starts a detached `magpie codex-relay`
(internal/codexrelay). It waits up to 60s for the gateway's port, then
passes /backend-api/codex/* on to the ChatGPT backend with the same
transforms the gateway applies to Codex's own turns, signed by the
caller's own Authorization; it adds no credential
(gateway.CodexRelay).
- Refused with a readable 400 (Codex retries a 5xx five times over):
  a magpie model, a turn naming one of magpie's Codex accounts, and a
  turn masking would have masked, which is never sent unmasked.
- 403 for any Origin (null too) or a non-loopback Host, as corsGuard.
- Any other path gets 503 "magpie isn't running", never readable as
  magpie by ServedBy.
- It ends once every Codex process it was left for is gone and
  nothing is in flight.
- The next magpie (GUI or `magpie serve`) calls codexrelay.Leave
  first: a POST with the token from a 0600 state file. The relay
  closes its listener at once, so the port is free when Leave returns,
  and finishes its streams (up to 30 minutes). No running turn is cut.

Run (at 6df7dc287 on origin/main 4d9058a98, on mote):
- go vet of the six touched packages; gofmt -l clean.
- go test ./internal/codexrelay and the CodexRelay, CodexFailover,
  CodexProxy, RelayOpenCodex and CodexPIDs tests: ok.
- codexrelay tests on Windows (win-run) and Linux (wsl-run,
  magpie-desktop): ok.
- Windows smoke of the real binary (nogui build): `codex-relay`
  answers / with the readable 503, stays while its watched process
  lives, ends after it.
- Real codex 0.162.1 e2e on mote, sandbox CODEX_HOME, API-key sign-in,
  fake upstream: the relay waited out a port held 2s, then turn 1
  completed (RELAYED-OK); a turn on openrouter/kimi-k2 showed the
  refusal's message; turn 2 was mid-stream when Leave ran, the port
  was free at once, the turn completed, and the relay ended.
- GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./... and a
  Windows build: ok.
- Full suite, go test -count=1 -timeout 45m ./... on mote: every
  package ok but internal/gui, where 10 real-window AppKit tests
  (dock, panel, tray, titlebar, covered window, plugin page) are
  killed at their 20-80s bars. The same 10 fail the same way at
  origin/main 4d9058a98 on mote, run alone: mote's AppKit hang, #4125
  (and #2645, #1936). None of them touches the quit path changed here.
- Rebased on origin/main 1198cff60 to push. Still running there when
  pushed: go vet ./..., Windows and Linux vet of the touched packages,
  and go test of codexrelay, gateway, agent, provider and cli. A red
  it shows gets its own issue.

Broken by hand, each red, then restored:
- Leave without ln.Close(), with a 1s delay before Shutdown injected:
  "the port isn't free after Leave" (with ln.Close: green).
- No pid watch: "relay outlived the Codex it was left for".
- Leave without the token check: an empty token got 204.
- No Origin/Host guard: Origin null got 200.
- No masking refusal, no magpie-model refusal: 200, sent upstream.
- An empty 503 at "/": TestCodexRelayIsNotMagpie red.
- RelayOpenCodex starting nothing: "no relay for the open Codex".
- EndCodexFailover never saying ended: TestCodexFailoverEndsWithMagpie.
- CodexPIDs missing "codex": the Codex app and CLI not found.

Not tried:
- the real Codex desktop app, and a real ChatGPT account. With a fake
  ChatGPT token codex 0.162.1 stops at its own "workspace routing
  discovery" against chatgpt.com before sending a turn, so the
  ChatGPT path is covered by unit tests only;
- a Codex in a WSL distro, and a connected (not failover) Codex: both
  left as they were;
- a magpie that ends without quitting (killed, crashed): still leaves
  failover in place and no relay;
- the relay's memory use as the full binary.
2026-10-29 17:13:05 +08:00
yetone da8039368f library: skills kept in ~/.agents/skills can be handed over to the library, and then turned off per agent
tnt1223 on Discord asked for the skills in ~/.agents/skills to move into
magpie's library folder and be managed there ("统一移入 magpie 的资源库文件
夹,交给 magpie 管理"), since a skill there can't be turned off for one agent
("不能决定某个 skill 是否自由开启"). Codex, Gemini CLI and the other readers
of that folder read it themselves, whatever the library ticks. Goose, Kimi
Code and Cindy use it as their own folder.

HandOverSkills (POST /api/library/skills/hand-over with names) does the
hand-over only when the user asks for it:
- A folder kept in ~/.agents/skills moves into library/skills/<name>
  (moveIn). It is renamed, or, across disks, copied. A copy has to read
  back the same (sameTree) before the original is set aside with the
  backups. On any failure the folder stays where it was and the library's
  link stays as it was.
- An entry there that only links to a folder elsewhere is removed, and
  the library links straight to that folder. The folder itself stays.
- The user's own links to the skill in agents' folders are removed too,
  since they would point at nothing. The library gives those agents its
  own link.
- Every agent here that read the skill there (readsSharedHere, plus the
  agent of each such link) is ticked. So each agent keeps the skill, now
  from the library, until the user unticks it or turns it off here.
- A skill found there that isn't in the library yet is imported first.
- A name that can't be handed over is listed in Result.Unmoved, and the
  other names are handed over all the same.
HandBackSkill moves the folder back and links the library to it again.

"Kept there" is now sharedEntry: the skill's own entry in the shared
folder, by its name, or, for a library link into it under another
folder's name, by that folder's name. Everything that read the old
by-name check follows it:
- SkillView.Always, plus the new Shared and SharedElsewhere fields;
- syncSkills' in-shared check;
- the shared folder's own target, which no longer gets a second link
  beside such an entry. TestSharedUnderAnotherName covers this, and it
  fails without the guard.

Where:
- GUI, Library > Skills: a row kept there has "Manage in magpie"
  ("交给 magpie 管理") in its source line. With more than one such row,
  the skills heading has "Manage {n} in magpie". Each asks first, in the
  page, and says:
  - where the folder goes, or that only the link goes;
  - which agents keep the skill, ticked;
  - how to put it back.
  Cancel sends nothing. The strings are in en, zh, zh-TW, ja and de.
- CLI: `magpie library skill hand-over <name…>|--all` and
  `magpie library skill hand-back <name>`.

Existing users: nothing changes until they click. A library.json gains
no new key.

Run (mote, at 58e926e5d/d4b7c0586 rebased on 3142a5559 unless said):
- gofmt -l: clean.
- go vet on darwin, GOOS=linux -tags nogui and GOOS=windows, for
  library, cli and gui. GOOS=linux and GOOS=windows builds.
- go test -tags nogui ./... -timeout 45m, at the pre-rebase base
  a14f5c9c9: 76 packages ok. The one red was internal/gui's
  TestCoreScriptBudget (1531446 > 1530861), which is red on main since
  a4e929212 (#4133). This change adds no core script.
- Windows (win-run, xiaomi-gpu): TestHandOver*, TestSharedUnderAnotherName
  and TestSharedAgentsSkills pass. TestHandOverFailureKeepsOriginal
  skips there, because a read-only folder can still be written.
- GUI: skill-handover.test.cjs in Chromium and WebKit, at 860 and 400px,
  in five languages, plus the heading's all-at-once case. It ran with the
  library skill files and i18n-keys: 84/84.
- Whole GUI suite, on the Windows box (mote was running another
  session's full suite). Nine reds, all in pages this change doesn't
  touch:
  - webkit: agents' sign-ins read, or not at all;
  - disconnect previews use the full body width (chromium and webkit,
    en and zh);
  - webkit zh: an agent's model list;
  - webkit en/ja 1100: an agent's own settings are in its opened row;
  - webkit: a token on a new custom provider with no Balance URL.
  These are NOT yet compared with main. The local disk filled up before
  the run's summary could be read.

- At the head rebased on 4d9058a98 (WSL magpie-desktop): go vet
  -tags nogui on library and cli; TestHandOver*,
  TestSharedUnderAnotherName, TestSharedAgentsSkills and
  TestLibrarySkillHandOver pass; skill-handover and i18n-keys pass 28/28.
  i18n-keys was red there first: the hand-over tooltip "Move these {n}
  out of ~/.agents/skills…" said the usage plugin's word "{n} out".
  It now reads "Move these {n} from ~/.agents/skills…".

Broken by hand:
- Without the ticking, the HandOver tests fail.
- Without syncSkills' guard, TestSharedUnderAnotherName fails ("goose
  was given it twice").
(At 400px the first layout squeezed the path to nothing. The button
now shrinks first, and the test checks the path's width. That check
wasn't run against the old CSS.)

Not covered:
- Another computer whose skill is still in its own ~/.agents/skills gets
  the library's copy from a sync, beside its own, until it is handed over
  there too.
- The skills CLI's lock (npx skills update) may put the entry back.
- No hand-back button in the GUI; the sheet names the CLI command.
- Tried in a sandbox HOME only, never on a real ~/.agents.
2026-10-29 15:52:42 +08:00
yetone 628ac36fc9 agents: Add magpie says when nothing here opens the app's import link (sungt)
sungt (Discord #feedback, Windows, magpie 0.1.1976, Cindy 0.1.119, Cindy
open): on the Agents page Cindy's 添加 magpie "spins, no response".

What magpie got wrong: Cindy, AionUi and Lody take magpie only through
their import link, which magpie hands to rundll32 / open / xdg-open and
never waits on. A link nothing opens did nothing, the button never awaited
/api/open nor caught its error, and `magpie cindy add` printed "opened"
whatever happened.

- agent.OpenAppLink asks the system, without opening anything, whether
  something opens the link's scheme: Windows' HKCR\<scheme> (what
  Electron's setAsDefaultProtocolClient writes) and then the user's
  UrlAssociations UserChoice; macOS Launch Services (cgo builds); Linux
  `xdg-mime query default`. Only "none", or a registered program whose
  full path is gone, refuses the link (NoLinkHandlerError); anything
  unknown hands it over as before.
- /api/open (Cindy, AionUi, Lody after OpenLody) answers
  code no_link_handler with app, exe and said, an i18n.js key from
  linkSaid that api() puts through t() as it does bunSaid's.
- The import button now waits for /api/open and shows the result: "Sent
  to {name}: confirm adding magpie there", or the reason in the
  reader's language.
- The CLI's add returns the same error.

This is not verified as sungt's cause. Cindy was open, and Cindy
registers cindy:// at every start, so the check most likely passes on
their machine. If so, the spinner is Cindy's own import dialog
(previewProviderImport / fetching magpie's /v1/models). Cindy 0.1.119
wasn't available here. We still need Cindy's log around "received deep
link" from sungt.

Run (worktree at origin/main 536a98316, mote unless said):
- go test -tags nogui -count=1 ./internal/agent ./internal/gui
  ./internal/cli: agent ok, cli ok. gui is red only on
  TestCoreScriptBudget, #4133, which is red on origin/main
  (1531446 > 1530861, from a4e929212's context.js). This change adds 85
  bytes to app.js (1311673, under app.js's own 1311735) and makes the
  total 1531531. No budget was raised.
- node --test, chromium and webkit, every language: import-row,
  i18n-keys, plugin-bun-unstartable, agent-connect-no-models and
  agent-connect-all-hidden (api()'s error paths). Result: 84 pass, 0 fail.
- Windows (win-run): TestCommandProgram, TestOpenAppLinkSaysNothingOpensIt,
  TestSystemLinkHandlerNoSuchScheme (real registry lookup) and
  TestFolderVarsAreListed all pass. Earlier in this work:
  - rundll32 handed magpie's 719-char Cindy link byte for byte to a
    registered handler;
  - a temporary HKCU scheme was read as found, then as gone once its exe
    was deleted, and the key was removed afterwards.
- Linux (wsl-run, magpie-desktop, real xdg-mime): the same applink tests
  pass.
- macOS (mote): Launch Services finds https and mailto, and finds no
  handler for cindy, lody, aionui or a random scheme.
- gofmt -l is clean. go vet passes for GOOS=linux -tags nogui, for
  GOOS=windows, and with CGO_ENABLED=0 for internal/agent.

Red on the old code, each wiring reverted by hand:
- providers.go: TestImportLinkNothingOpens is red (204, link handed over).
- cli main.go: TestImportAddSaysNothingOpensIt is red (nil error, link
  handed to the browser).
- importButton: import-row is red (status "" where the Sent/err line was
  wanted).

Not tried:
- Cindy 0.1.119, or any real Cindy, on Windows.
- A real app whose registered exe was deleted.
- The full go test ./... and the whole GUI suite. mote was running
  another session's full suites, and there is one suite per machine.
2026-10-29 09:24:31 +08:00
yetone 0e2739743b codex: a reset set to go when the week runs out is spent before the credits
tongzhenbao on X: a Codex Pro account with "when its week runs out" on,
its week at 0% left, one reset held until 11-06 (after the week's own
reset on 11-03) and Use credits on. Overnight ~10k credits went and the
reset stayed; the card said "not auto-used" beside the switch on.

Cause: the week's auto-use ran only on a vendor refusal. autoReset in
routing needs a 429 usage_limit_reached on the last candidate, and the
relay's autoResetSignedIn the same on its 429. An account let spend its
credits is never refused for its week: ChatGPT answers on the credits,
and routing never benches it (full() and onCredits). So the week's reset
could only ever be spent with credits off.

Decision (product call delegated): a reset is free, credits cost money,
so a reset the user set to go when the week runs out goes before any
credits. resetBeforeCredits runs before a try is sent to a Codex account
on its credits whose last reading has its week used up, with the week's
switch on; AutoUseCodexReset reads the week again and keeps one a week
at most, so a second time in the same week goes on the credits. Hooked
in the routing loop and in codexUpstreamOn (the relay, signed-in or an
account). With no reset held, or the week's switch off, nothing changes.

The card's summary: with only the week's switch on it now says "auto-used
when the week runs out" (zh 周额度用完时自动使用), not "not auto-used",
with its title in all five languages. CLI help and auto-reset messages
say "or before its credits are spent". gateway-routing.md names it.

Siblings: the expiring switch already spends regardless of credits
(usedUp ignores them); the credits-off path (planned.held) is unchanged.

Run (mote, through mote-run, at this tree):
- go test ./internal/gateway -run 'TestCodexResetBeforeCredits|TestCodexAutoReset|TestCodexCredits|TestCodexNoCredits': ok
- broken by hand: gateway.go and codex_backend.go at origin/main:
  TestCodexResetBeforeCredits/relayed and /routed red (200, spent ""),
  the two negative cases green
- node --test codex-auto-reset, i18n-keys, codex-auto-reset-settings,
  codex-resets-used, panel-options-fold, quota-curve: 96/96 (chromium +
  webkit, en/zh/zh-TW/ja/de); codex-auto-reset red with origin/main's
  app.js ("· not auto-used")
- full suite, before the rebase onto 300b7eee0: wsl-run go test -timeout
  45m ./... ok for internal/gateway, provider, settings, tui and the rest;
  root, cli and gui don't build in WSL (no gtk4/webkitgtk-6.0), and
  internal/agent's fake-binary tests (TestInstalledVersion and four more)
  fail there with "Invalid argument"; on mote those packages are ok
  (., cli 49s, agent 179s)
- at the pushed head 7b6a0675f (on 300b7eee0), on mote: internal/gui,
  provider and cli; provider and cli ok, gui ok except TestMainWindowCorners,
  red the same on a clean 300b7eee0 copy on mote (macOS 27), #3949;
  TestCoreScriptBudget ok with no raise (app.js 1,311,588 of 1,311,735,
  after shortening resetsWords' change); the focused gateway tests and the
  six GUI files above again, ok and 96/96
Not tried: a real account with credits and a held reset at 0% week; the
owner's accounts have no reset at 0% to spend.
2026-10-29 08:17:12 +08:00
yetone b4267de595 gateway: a provider's fallback can be a routing group, routed as the group
01huadalang on Discord: "还有备用模型增加路由组的选择,现在只能选模型". A
provider's Fallback list held models only; a "group/<id>" entry resolved
to the group's first member alone. Now such an entry is served through the
group, as a request to the group would be:

- plan → planPaused: a fallback naming a group (provider.FallbackGroup,
  the group as routed, Live) hands its members to planLevel
  (planFallbackGroup): the group's own routing, its sink and asides, and
  its pause rules (serve passes provider.PausedOut for the agent's folder).
  Its trace rows are marked Fallback with the group in Via.
- No loop, each provider/model once a round: a member that is the primary,
  a model named earlier, or another fallback group's member is left out
  where it comes second. Groups have no fallbacks of their own and a
  member's fallbacks are not followed, so nothing leads back. A group that
  is gone or off is passed over, as a model none serves is.
- Every sibling that reads p.Fallback now reads a group's members through
  provider.FallbackModels: redaction (unredactedRoute: an unmasked
  provider with a fallback group holding a remote model is masked),
  careful accounts (carefulOf), native compaction, Codex's own turns
  (codexFallsBack) and Claude's auto-mode review (claudeReviewed, which
  moves from provider.Resolve to ResolveRoute, as the gateway reads
  fallbacks).
- CLI: `magpie provider fallback` already took group/<id> (Resolve knows
  groups); its usage and error now say so. Pinned by
  TestFallbackCmdTakesGroup.
- GUI: the provider editor's Fallback picker lists the routing groups
  (providers.gateway.groups) beside the models as chips with the Routing
  fan and a muted "routing group" tell; a picked group's row has the same
  fan and tell, and a gone one says "No routing group {id} now; it is
  skipped". A filter matches a group's name, id and its members'
  providers. New strings in zh, zh-TW, ja and de.
- app.js budget raised 187 bytes on main (1,311,922; core 1,531,060), the core's
  own editor, no room added; the addition was cut from ~900 bytes first.
- docs/subsystems/gateway-routing.md: the Candidates row says all this.

Not done: a fallback group's turn rules (ruleFor/ruleOver, which can ask
a classifier) are not applied. The plan is made before the primary is
tried, so they would cost a classifier call on every request the primary
answers. Its routing order, sink and pause rules are applied.

Run (at f6e7214af; after the rebase, the last bullet):
- gofmt -l: clean. mote: go build ./...; go vet on the touched packages;
  GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...: ok.
- mote: go test -timeout 45m ./...: every package ok except internal/gui:
  TestCoreScriptBudget (fixed above, then ok) and ten AppKit window tests
  (TestDockJoinLeadsCommandTab, TestPanelCloseHidesIt, TestMainWindowCorners
  …) killed at their 30s bars while four other sessions' GUI suites held
  mote at load 70-110. Run alone, all ten
  pass (TestDockJoinLeadsCommandTab skips) except TestMainWindowCorners,
  red at base f6e7214af too (#3949); the load kills are #2645.
- GUI: the whole suite (962 files, node --test --test-concurrency=8) on the
  Linux box (WSL magpie-desktop, chromium + webkit): 14,217
  tests, 305 red in 99 files. Those 99 files rerun at base f6e7214af: 156
  red; at this head: 159; the ~20 that differ either way are flakes (the
  head-only ones, key-replace and vertex-editor, rerun twice on each: the
  same reds at base). Filed as #4120.
  fallback-group.test.cjs (new), fallback-more and i18n-keys: ok in
  chromium and webkit on mote and on Linux.
  After the app.js cut, at the final head: the three files 12 of 12 on
  Linux; webkit ok on mote, chromium there failed only at browser launch
  under load.
- Broken by hand, each red, then restored:
  - the group branch in planPaused off: all five gateway group tests red
    (TestFallbackToGroupServedByMember is red on the old code: only the
    first member was tried).
  - the dedup off: TestFallbackGroupWithThePrimaryTriesItOnce and
    TestFallbackGroupSharedModelTriedOnce red.
  - the pause filter off: TestFallbackGroupPauseHolds red.
  - redact.go from origin/main: TestFallbackGroupKeepsMasking red.
  - the GUI's group list off: fallback-group.test.cjs red in all four
    (chromium/webkit × en/zh).
- After the rebase onto 0daf36332 (18 commits, gateway.go among them;
  the budget test conflicted, kept main's and measured again): gofmt -l
  clean; mote: go build ./..., vet of the touched packages, linux and
  windows vet ok; go test internal/provider, internal/cli, internal/agent
  ok, and internal/gateway and internal/gui -run with Fallback, Redact,
  Unredacted, Careful, Compaction, CodexFalls, Budget, Rest and Probe ok; fallback-group, fallback-more, i18n-keys
  and rest-probed 52 of 52 on Linux.

Not tried: a real request through a real group fallback with real
accounts (the tests use fake upstreams); the Windows GUI; the TUI has no
fallback editor.
2026-10-29 05:19:28 +08:00
yetone a0ba8e1f2e grok: each model's context_window follows Long conversations, and one set by hand stays through a sync (uk.jent)
uk.jent (Discord #feedback) reported that magpie writes every Grok Build model's context_window as the model's whole window. They wanted about 300K without editing dozens of models, and they lost hand edits on each sync, because SetTOMLTables replaces the [model."magpie/..."] tables whole.

Grok Build now uses Long conversations, the mechanism Codex and Claude Code already use. grokWindow gives:
- min(window, Compact) when the model or provider has its own threshold;
- otherwise settings.Working(window): 272K by default on longer windows, the typed size, or the whole window with Full context.

What magpie wrote is stashed under grok:<path>:windows, and grokOwnWindow uses it to tell a hand edit apart:
- A value that differs from what magpie last wrote is the user's, and it stays.
- In a config written before the record, a value other than the model's whole window is the user's.
- Disconnect forgets the record.

The agent sheet's Long conversations row now shows for Grok Build (AGENT_PREFS). Its texts, the provider editor's hint, the Context tab's note and `magpie model compact` now name Grok Build, in en/zh/zh-TW/ja/de. setCompact and setAsync now share prefWrite. That dedupe keeps app.js under its budget, which is not raised.

Behaviour change: a Grok Build model whose window is over 272K now gets 272K by default, as Codex does, unless Full context is on.

Run on mote, at this head (c893c2229, rebased on fe05f0a72):
- gofmt -l: 0 files.
- go vet ./internal/{agent,gui,cli,settings}: darwin, plus GOOS=linux and GOOS=windows with -tags nogui. All ok.
- go test -tags nogui -timeout 45m ./internal/agent ./internal/gui ./internal/cli ./internal/settings: all ok.
- GUI agent-prefs, compact-at, compact-one-value, context-tune, context-window, gateway-mode, i18n-keys, settings-general: 202/202 in Chromium and WebKit. The new cases cover Grok's sheet in five languages at 1100 and 440, and in the 360 panel.
- At the pre-rebase head, 104 GUI files the change can reach: 1590/1622.
  - 29 of the reds were browserType.launch timeouts at load 85. Run again one at a time, every one passed, and so did usage-fold.
  - context-map's WebKit 420px "two tiles overlap" is red on origin/main fe05f0a72 too, run alone. It is recorded on #3488.

Broken by hand:
- With the keep logic removed, TestGrokKeepsAWindowSetByHand and TestGrokKeepsAWindowSetBeforeTheRecord go red ("pro 1000000 (set by hand to 300000)").
- With grokWindow returning the whole window, TestGrokKeepsAWindowSetBeforeTheRecord and TestGrokWindowFollowsLongConversations go red ("compact at 300K: pro 1000000").

Not tried:
- A real Grok binary reading the written config. Grok 1.0.67's own help documents model.<id>.context_window as driving auto-compact.
- Linux/WSL and Windows runs. Only cross-OS vet was run.
- Grok App still writes the whole window, and neither agent writes the context_windows choice list: #4117.
2026-10-29 04:43:22 +08:00
yetone fe05f0a721 library: a skill can be turned off on this computer alone, and a sync neither carries that nor turns it on
hanslin1666 on Discord (#general 1565016936344191096) wanted a library
skill off on one computer only ("只在这台电脑上关掉"). The only way to do
that was to untick its agents, and the ticks are what a sync carries, so
every other computer lost it too. A sync from a computer that had it on
also gave it back here.

Skill.OffHere (library.json "offHere", omitempty) turns a skill off on
this computer. No agent here gets it, whatever Agents says. Every reader
that gives a skill to an agent now asks gives():
- syncSkills, including the shared ~/.agents/skills check;
- desktop_skills.go;
- skill_changed.go;
- skill_edits.go;
- behind;
- Targets.
Agents stays what a sync carries, and the page shows those chips faded.

Collect never carries OffHere, so turning a skill off changes no part a
sync uploads. Put keeps this computer's OffHere for a skill it puts, so
a sync from a computer that has it on (or that gives it to more agents)
leaves it off here.

Where to turn it off:
- GUI: a power button on the skill row (aria-pressed). When off, an
  "Off on this computer" tag sits on its own line under the name; it
  says why and turns the skill on when clicked.
- CLI: `magpie library skill off-here|on-here <name>`.
- TUI: the row says the skill is off.
The strings are in en, zh, zh-TW, ja and de.

Existing users: nothing changes. An older library.json has no offHere,
so every skill stays on, and a skill that was never turned off writes no
key (TestSkillOffHereOldLibraryIsOn).

Not covered:
- a project's skills;
- a library skill whose own folder is inside ~/.agents/skills, which
  agents read in place;
- a skill another computer removes (the flag goes with it).
The skill's files in the library folder still update while it is off.

Docs: docs/subsystems/library.md and sync-backup.md.

Run at the parent aeacc6358 (rebased on origin/main), on mote:
- gofmt -l: clean.
- go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go
  vet ./...; go build ./...: ok.
- go test -tags nogui -timeout 45m ./internal/library ./internal/davsync
  ./internal/cli ./internal/tui ./internal/gui ./internal/backup: all ok.
- GUI, Chromium and WebKit:
  - skill-off-here: 22/22 (en, zh, zh-TW, ja, de at 860 and 400px).
  - i18n-keys, gui-ja, gui-de, gui-zh-tw, library-items, library-mcp-hub,
    library-all and library-toggle-status: green. The first try timed out
    in browserType.launch (mote at load ~60); run again one file at a
    time, they passed.
  - library-row-remove: Chromium red in the hooks part, 2 or 3 of 11
    each run. It is red the same way on origin/main aeacc6358, 3 of 3
    runs there too (#3099); this change doesn't touch hook rows.
- Before the rebase, at e5e2aa58e plus this change: the 98 GUI files
  that reach the library page (1350 tests). 68 reds, nearly all
  browserType.launch timeouts under load; run again one file at a time,
  all passed except mobile-web's "desktop matches origin/main"
  subtests. Those need .git, which mote-run doesn't copy.

Then rebased onto ec3dad75a, which changes no library file. At this
pushed head: go build ./..., go vet of library and gui, the gui Budget
tests, and i18n-keys plus skill-off-here in both engines (26/26), all
ok.

Broken by hand (restored afterwards):
- Put dropping OffHere:
  - TestSkillOffHereStaysHere:96 failed: "a sync from a computer with it
    on gave pdf to an agent here again".
  - TestSkillOffHereThroughSync:108 failed: "a sync from A, with pdf on,
    gave it to an agent on B again".
- gives() ignoring OffHere: TestSkillOffHereStaysHere:74 failed: "off
  here, claude still has pdf".
- The GUI test fails on the old code, which has no button.

Not tried:
- no real WebDAV or GitHub backend (the sync test uses the fake S3);
- no real app run with real agents;
- no Windows or Linux test runs (only GOOS=windows and GOOS=linux vet);
- not the whole GUI suite, only the 98 files that reach the library page,
  the i18n checks and gui-ja, gui-de and gui-zh-tw.
2026-10-29 04:23:33 +08:00
yetone ec3dad75ae provider, gateway, gui, cli: Claude's accounts can be kept to Claude Code's own sign-in, magpie serving nothing on them (myduso)
myduso on Discord asked for an exclusive mode on Claude's subscription:
switch the credentials locally and proxy no traffic, since Claude Code
is used on its own and the SDK run magpie's bridge makes spends more of
the allowance than the interactive client.

The switch-only setting Codex has (#1907) now also takes claude. On it,
Provider.KeptToAgent is true and On() false, so the gateway, catalog,
groups, fallbacks, search, draw and embeddings serve nothing on the
Claude accounts, and a request naming them is refused 404 saying they
are kept to Claude Code's own sign-in and how to undo it (switchedOff).
Switching Claude Code's sign-in when an account is used up, and reading
usage, go on: both are gated by leftAlone on the raw Off, which this
doesn't set. Groups magpie found keep their Claude members
(heldOffEntries). Nothing is sent as Claude Code: magpie only writes and
restores Claude Code's own credentials as it already did.

GUI: the tick under Claude's accounts, shown with one account too, drawn
by the block Codex's tick had (one block now, its strings picked by
agent). app.js stays under its budget with no raise (1,311,711 of
1,311,735). CLI: magpie accounts switch-only <codex|claude> [on|off].
Docs: reference.md, subsystems/providers-accounts.md.

Run on mote at this tree on 06950fbbb; then rebased on aeacc6358 (two
app.js comments shorter) and go test -run TestCoreScriptBudget ./internal/gui
run again at the pushed head: ok.
- gofmt -l internal: clean. GOOS=linux go vet -tags nogui ./internal/...
  and GOOS=windows go vet ./internal/...: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/provider
  ./internal/gateway ./internal/cli ./internal/gui: all ok.
- node --test (Chromium + WebKit, every language the file covers):
  claude-switch-only (new), switch-only, keep-login, i18n-keys, gui-ja,
  gui-de, gui-zh-tw: 85 of 93 in one run beside other sessions' full GUI
  suites (load 23-73); the 8 reds (claude-switch-only chromium en/zh,
  gui-de and gui-ja in both engines) were not captured, and those files
  then passed alone twice (35 of 35 each run).
- Earlier, at ecbd694a2 (on ddf31ca30): internal/agent ok; add-sheet,
  api-key-usage pass; account-models and account-proxy 40/40 alone after
  8 browserType.launch timeouts at load 40-70 from other sessions.

Broken by hand, watched red:
- On() without the KeptToAgent term: TestClaudeSwitchOnlyServesNothing-
  AndStillSwitches and TestClaudeKeptToClaudeCodeServesNothing fail (the
  gateway ran Claude Code through the bridge, 200).
- SetSwitchOnly refusing claude: both fail.
- app.js without the claude branch: claude-switch-only 16/16 red in
  Chromium, switch-only (Codex) 16/16 green.

Not tried: real Claude accounts or a real Claude Code (the switch itself
is the existing path, tested with a fake claude in a sandbox HOME); the
whole GUI suite (only the files that open Claude's or a provider's
editor, plus the i18n ones); Linux and Windows test runs (vet only).
2026-10-29 04:15:56 +08:00
yetone e0ea15b8e8 library: an MCP hub, one magpie server in place of every library server (#2679)
With Library → MCP → "MCP hub" on (off by default), each agent that takes
an MCP server over HTTP is given one entry, magpie, at
/mcp/magpie/hub/<agent>, in place of the library servers ticked for it.
magpie runs those servers itself, once for every agent: a command starts
on its first call and ends after 10 idle minutes, a URL server is reached
with its headers and MCP sign-in. Tools are <server>__<tool>; a tool off
in the library is neither listed nor run. Any other app connects at
/mcp/magpie/hub, which serves every library server. Both are guarded as
/mcp/magpie/tools is (local or a gateway key, no foreign page, 4 MiB,
the key's limit per call). An agent that reaches no server over HTTP
(Claude Desktop), has a magpie entry of its own, or sits beside a library
server called magpie keeps each server's own entry, and the page says why.
Off gives every agent its servers back and ends every process the hub
started.

GUI: a switch under the MCP list, a line of what it serves, the address,
and a Connect… sheet. The sheet lists every agent magpie detects that
takes MCP (not a fixed four), each with where it stands; one given none of
the hub's servers has a Connect that ticks it for every server it can
reach (servers/agents-all), so it gets the entry, and the sheet stays
open. Then any other app: Cursor (when it isn't a detected agent), VS
Code, Other, with the JSON and, in the app, "Add to …" through the app's
own install link built in Go (servers/hub-open; the page never sends a
link). CLI: magpie library mcp hub on|off. Design: docs/subsystems/mcp-hub.md.

With #3885 (62045475b): with the hub on, Codex is given the one magpie
URL entry, and the servers behind it never reach runVia, which takes a
command server only; with the hub off Codex gets /mcp/run/<name> as before.
Rebased onto it; the one conflict was both commits declaring base in
syncMCP.

Run:
- At 62045475b + this (the pushed tree), on mote: gofmt -l, go vet,
  GOOS=windows go vet, GOOS=linux go vet -tags nogui clean; go test
  -timeout 45m internal/library (108s), gateway (510s), cli (50s) ok.
  The GUI files and internal/gui weren't run again: 62045475b touches
  neither, and the rebase changed nothing in them.
- At ddf31ca30 + this: go test -timeout 45m for
  internal/library, gateway, cli and gui on mote; gofmt -l; go vet,
  GOOS=windows go vet, GOOS=linux go vet -tags nogui; win-run of
  library-mcp-hub and i18n-keys (both engines, en zh zh-TW ja de, 420px).
  gofmt and the three vets clean; library, gateway (554s) and cli ok;
  gui ok but TestMainWindowCorners, red the same on origin/main ddf31ca30
  on mote (#3949); GUI 26 of 26 pass.
- Earlier base (582bd8036, before TestHubConnectAnAgent and the oneport
  consts): full go test ./... on mote, every package ok but gateway's
  TestClientPathCoversHandler (fixed here: HubMCPPath, HubMCPAll and
  {agent} added to its consts; passes) and internal/gui's AppKit tests.
  Of those, TestMainWindowCorners fails the same on origin/main ddf31ca30
  on mote's macOS 27 (#3949); the other six (dock, panel, plugin page,
  right-to-left) passed rerun alone at load ~95 (#2645).
- win-run of every library-*, gui-*, i18n*, click-scroll and menu-scroll
  GUI file: 49 files, 839 tests, 839 pass.
- Real use in WSL (magpie-desktop), sandbox HOME, real echo MCP server:
  hub on, Cursor given servers → ~/.cursor/mcp.json holds only magpie at
  /mcp/magpie/hub/cursor; initialize, tools/list (echo__echo) and two
  calls ran on one server pid; a foreign Origin got 403; hub off → the
  echo process ended, tools [].

Broken by hand: Connect button removed → 6 GUI cases red; the old row
wrap rule → 6 red (icon on its own line at 420px); EveryServerAgents
call removed from TestHubConnectAnAgent → red (hub "").

Not run: the whole GUI suite (~960 files); Windows agents (VS Code, Cursor
on Windows) against a real hub; an "Add to Cursor" click in the real app
(the link is built and tested, the app's own confirm wasn't driven).
2026-10-29 03:17:58 +08:00
yetone df9376592d routing: a group's member may offer several reasoning levels for the agent to pick among
Garydesu on X: "能不能让路由组里的模型设置多个可选推理强度,现在只能选一个或者整个
路由组的". A member was one fixed `:effort` or followed the group's levels.

A member's suffix may now join several levels with "+",
`provider/model:low+xhigh`, kept lowest first, each once. provider.MemberLevels
splits it into Member.Levels and leaves Effort empty, so the member isn't
fixed; one level is a fixed effort as before. The whole stays the member's
id, so rules, fast, off, weights, share and the CLI key it as any member.
The gateway fits the agent's ask to the member's own levels (groupLevels
returns the candidate's levels first; ofMember, the quiet check and the
trace see them), and the group lists them to agents (buildGroupEntries),
intersected with the other members' as usual. In the Routing page's group
editor the member's reasoning menu has "Several levels…", a menu that stays
open with each level ticked or not; a fixed level picked from the first menu
replaces the old one as before. i18n in zh, zh-TW, ja, de; CLI help and
docs/subsystems/gateway-routing.md say it.

Run on mote (mote-run). Rebased on efb55b5c9 (past e1721d640, which
changed the group editor) and run again there: provider, gateway, cli ok;
gofmt clean; GUI group-member-levels, group-member-fast,
group-member-weight, group-from-model-add and i18n-keys 53 of 54, the red
being i18n-keys' "masking…" from e296211b8, red on main (#4053). Linux
and Windows vet were clean at 7fe98c2af. Earlier, at the first base:
- go test -tags nogui -timeout 45m ./internal/provider ./internal/gateway
  ./internal/cli ./internal/tui ./internal/gui: all ok (gateway 525s).
  internal/cli again after the help wording below: ok.
- gofmt -l: nothing.
- GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go vet
  ./...: clean (darwin prints cgo warnings only).
- Whole GUI suite (node --test "internal/gui/tests/*.test.cjs", both
  engines, load 140 at its peak): 13,931 tests, 119 red in 31 files. One
  was this change: i18n-keys' "a plugin's words are its own", because the
  CLI help said "the agent picks among them" too; reworded the help, and
  i18n-keys passes. The other 30 files, run alone at --test-concurrency=4
  at this tree and at its parent e8c7dddcb: the same files red on both
  (97 and 100 cases, the routing-rule ones a random subset each run, all
  waiting on clicks), each with an open issue (#3527 lists the pattern;
  segs-press-redraw #3922, routing-story-shrinks #3954).
  group-from-model-add, account-*, login-import and signin-* pass alone.
- group-member-levels.test.cjs: 30 of 30 (5 languages, both engines,
  1100px and 420px); group-member-fast.test.cjs 4 of 4.

Broken by hand:
- groupLevels without the member's levels: TestMemberSeveralLevelsFollowAgent
  red (asked high, sent high, not xhigh).
- buildGroupEntries without the member's levels: TestMemberSeveralLevels red
  (offered all four, not low and xhigh).
- main's routing client.js: group-member-levels red 3 of 3 (chromium en).

Not tried: a real agent picking among a member's levels against a real
vendor; the TUI (its reasoning toggle cycles a "low+high" member back to
following the group, unchanged code).
2026-10-28 18:52:39 +08:00
yetone e8c7dddcb4 notices: the release carries the third-party licence notices
The owner asked for the licence notices in the release package (moejs
alpha.11 compiles Intl's data in, which carries its own notices).
THIRD_PARTY_NOTICES is embedded in the binary (main.go, //go:embed) and
handed to internal/notices; `magpie licenses` prints it, GET /api/notices
serves it, and Settings › About has an Open-source licenses row that
opens it in a dialog, in every language. `make app` copies the file into
the .app's Resources too. The core's scripts are 1,527,245 bytes, their
budget raised to it with no room added; app.js stays under its own.

Run at this head (rebased on origin/main):
- win-run (Windows 11): go vet -tags nogui . ./internal/notices
  ./internal/cli; go test TestNoticesFollowMoejs (.), ./internal/cli,
  TestCoreScriptBudget (./internal/gui): ok.
- wsl-run (Ubuntu 24.04): go vet -tags nogui ./..., go build -tags
  nogui: ok.
Run at the pre-rebase head 14e2d13fb, on mote (macOS):
- gofmt; make app's copy byte-identical to the file; `magpie licenses`
  output equal to the file; GOOS=linux/windows vet and build;
  go test . ./internal/cli: ok. ./internal/gui: only
  TestMainWindowCorners red, the same on origin/main (#3949).
- about-notices.test.cjs: chromium and webkit, en zh zh-TW ja de, 1100
  and 420px: all ok.
Broken by hand: TestNoticesFollowMoejs red with the embedded file cut.
Not run: the GUI suite at this head. The rebase met main's cancelAsk
helper where showNotices sat, and the dialog's Done now uses it (the
same stopPropagation + closeConfirmAsk). The whole GUI suite at
14e2d13fb was cut off when mote went down at load ~50: the files it
reached outside About had reds, most of them 180s browser-launch
timeouts, the rest passing in other languages or the other engine; they
are run again once mote is back, and any that stay red are filed.
2026-10-28 16:40:03 +08:00
yetone 08b02cf18c providers: a pool stops at its caps and reads usage again near them (plugins#349)
What was adopted on magpie-community/plugins#349 (1939869736luosi): one
place, in the GUI and the CLI, for a subscription's account pool, and an
opt-in conservative mode.

- Stop at the caps (Provider.CapStop, off by default): once every account
  in use is held at its cap, the request is answered 429 rather than going
  on to the provider's fallbacks (plan returns restLast). Off, as before.
- Check usage again near a cap (Provider.CapCareful, off by default,
  internal/gateway/cap_careful.go): before planning, a capped account's
  usage is read again when its reading is over 15s old within 5 points of
  a cap, or over 5m old at all; the request waits at most 10s, and a
  failed account is asked again at most every 15s. An account whose usage
  was never read, whose last read failed, or whose reading is still that
  old is then held as one at its cap is (capHold "unread", traced as
  Weighed.Unread, named in the 429 with "--careful off"). Generic: it
  goes by provider.UsageRead/ReadUsageNow, so every subscription that
  reports usage windows (Codex, Claude, plugins) gets it.
- provider: usedCache records each account's read state; a failed read
  keeps the last good reading's time. ReadUsageNow no longer reports
  false when the read had already finished on the first ask.
- GUI: under the provider's account list, once an account has a cap (or
  either is on), two ticks for the above, and a note naming the accounts
  in use with no cap ("used to 100% of each window"). Accounts, order and
  caps stay where they were in that list. zh, zh-TW, ja, de added.
  app.js 1,309,658 within its 1,310,460 budget, unraised: addRow and a
  per-row forgetOf replace 3 add-button and 5 Remove-button builds.
- CLI: magpie provider pool <id> [--accounts a,b,…] [--cap percent|off]
  [--stop on|off] [--careful on|off] shows and sets the whole pool.
- docs: gateway-routing.md and providers-accounts.md.

Run (mote, before the rebase at 8bade6c5e + this change):
- go test -tags nogui -timeout 45m ./...: exit 0, 76 packages ok, no
  FAIL (log grepped).
- GOOS=linux and GOOS=windows go vet of cli, gateway, provider, gui: ok.
- pool-ends.test.cjs: 32/32, Chromium and WebKit, en zh ja de, 1100 and
  420 wide.
- The 81 GUI files whose fixtures have accounts or caps, plus i18n*,
  6 at a time at load ~130: 76 pass. i18n-keys is red on the base too
  (#3897). account-mask (#3951), account-alias (#2984),
  signin-closes-sheet and signin-again timed out under load and pass
  run again, as on the base; signin-again filed as #3960.
- Real plugin host: TestPluginCarefulPool runs the fake plugin under Bun
  as Factory with two accounts capped at 90%: a failing usage call gives
  429 with nothing sent upstream while careful is on, the last reading
  is used with it off, a good read sends to A again, and with both at
  their caps the fallback serves unless Stop is on.
- CLI binary in a sandbox HOME on mote: unknown provider, a bad --stop
  value and no id each refuse and change nothing.
At the rebased head (0a7633136 + this): gofmt -l
clean, go build ./..., the new Go tests and the budget tests, and
pool-ends.test.cjs 32/32.

Broken by hand, each seen red, then restored:
- the CapStop line in plan: TestCapStopSkipsTheFallbacks and
  TestPluginCarefulPool red;
- the careful hold in capHeld: the three careful tests and
  TestPluginCarefulPool red;
- careful always on: TestCarefulOffByDefault red;
- readCareful not called: the failed, never-read, stale and re-read
  subtests red;
- a failed read not keeping the good time, or not counted as failed,
  and ReadUsageNow's early return forced false: TestUsageReadAndReadAgain
  red;
- the ticks' onchange emptied: pool-ends.test.cjs 16 of 16 red.

Not tried: a real Factory or any real account (fake plugin only); the
whole GUI suite (932 files, ~5h at this load), only the 81 files that
reach the account list; Linux WebKitGTK and Windows; the 15s/5m/5-point
figures against a real vendor's usage endpoint latency.
2026-10-28 09:29:44 +08:00
yetone 8bade6c5e2 provider: a plugin's usage window can be a prepaid wallet's balance (#3950)
SuperMagic's accounts (mycf_711's magicrew plugin) are prepaid wallets of
points with no total. A plugin can now send a usage window as
{name, balance: 6291, unit: "积分"} with no used or limit.

- host.js passes a finite balance on (at least 0), anything else as null.
  plugin.UsageWindow.Balance and provider.QuotaWindow.Balance are *float64.
- quotaOfPlugin keeps the figure and does not make the window Text or
  Aside, so routing knows the account with no Used invented. allowanceOf
  copies it into Limit.Balance; an empty wallet counts as used up.
  Allowance.Left(model) is the least balance of the windows that count
  the model.
- weighRouted fills routes.Seat.Left and Seat.LeftIn (the account's
  provider and unit). Smart, pace and usage (least used) put the seat
  with more left first where they would otherwise tie (byLeft), only
  when every seat with a balance shares one LeftIn: balances in two
  units or two providers are never compared. Tiers still come first.
- The Usage card, the Routing page (Weighed.Balance: the small row's
  text, no bar, a why sentence, the account list), magpie accounts and
  the status line show the figure, "6,291 积分 left", never a share.
- Docs: provider-plugins (new section), gateway-routing,
  providers-accounts, plugin-runtime, host.js typings and the site's
  plugins page (en, zh, ja).

Run, at base f13aafa87, on mote:
- go test -tags nogui -timeout 45m ./...: 72 packages ok; red were
  TestQuotaSpanCarriesEveryWindowField (this change's: its fixture now
  sets Balance, green after), and on the unchanged base too
  TestWSLColdPlaceOpensNothing (#3924), TestFetchAsksASharedBaseOnce and
  two siblings (#3854), TestTUIFetchesSubscriptionModels (#3919), all
  fixed on main since and run again after the rebase; and
  TestPluginStreamsPastTheBudgetWait (#3946), green alone on both.
- GOOS=linux and GOOS=windows go vet -tags nogui ./internal/..., go
  build ./..., gofmt -l: clean.
- New tests: TestPluginWalletBalanceIsAReading, TestAllowanceLeftIsTheLeastBalance,
  TestPluginHostPassesABalanceOn (through real Bun and host.js),
  TestWalletsGoByWhatTheyHaveLeft, TestWalletLeftWithinItsTier,
  TestWalletWithMoreLeftGoesFirst, TestQuotaCell's balance cases;
  usage-wallet-balance.test.cjs and routing-wallet-balance.test.cjs,
  34 of 34 in Chromium and WebKit, en zh zh-TW ja de, 1100/900/420/390px.
- GUI: every quota*, usage*, panel*, routing*, i18n* and tray* file (220
  files, 2928 tests), concurrency 4: 130 red, in 21 files. Those 21 files
  run again on an unchanged base copy and on this change, concurrency 2:
  the same 19 files red on both (126 and 131), the differing subtests
  being routing-rule-remove / rules-line / intent-entry flaps that go
  both ways. Each is filed (#3679, #2115, #3410, #3404, #3411, #3897,
  #1905, #3096, #3593, #3408, #3409, #3799, #3789, #3412, #3947, #3415,
  #3414, #1345); routing-story-shrinks had none and is #3954.

After rebasing on origin/main 833f51adc, on mote: Linux and Windows vet,
go build, gofmt clean; go test -tags nogui of internal/routes, provider,
gateway, cli, plugin, gui (the script budgets), agent and tui: all ok;
the two wallet GUI files and i18n-keys: 37 of 38, the red being
i18n-keys' "Runs as" (#3897, not this change).

Broken by hand, each red then restored: quotaReport's Balance copy
removed (TestQuotaSpanCarriesEveryWindowField red); byLeft always nil (routes and
gateway tests red); host.js's balance line removed (host test red);
quotaOfPlugin's balance copy removed (provider tests red); app.js and
client.js at base (both GUI files 34 of 34 red, "0% used" / "已用 0%").

Not tried: a real SuperMagic account or the magicrew plugin (it isn't
in the community repo; it needs to send balance), Windows and Linux
GUI apps, and the WebKitGTK app.
2026-10-28 08:28:56 +08:00
yetone e056779a67 gui: the app serves its page to a browser, behind its key (Settings › Browser access)
jiakun_zhao on X ran `magpie web` in a terminal beside the desktop app,
to manage it through a Cloudflare tunnel. Settings › Network and sharing ›
Browser access now has the app serve the same page itself: Off, This
computer (127.0.0.1, for a tunnel or SSH forward) or Local network.

Access is magpie web's, unchanged: the key in the link is traded for the
cookie (webGuard), the allow list holds, and the gateway's client routes
on the page's port need a gateway key (onePort). A rebound Host and
Origin: null get no cookie. There is no way to serve it without the key.
The key and choice live in web-page.json (0600) beside settings.json, so
a sync never carries them. GET/POST /api/web-page are the app windows'
alone: a browser on the page can't read the key or turn the page off. A
busy port (magpie web, the magpie before an update) is tried every 4s;
`magpie web` on the same port opens the app's link instead.

Run at d43b7c40d (this change on ef155a5ca), then rebased onto the four
newer main commits, which touch gateway, usage, proc and library only:
- gofmt -l internal/gui internal/cli: nothing. go vet, GOOS=linux go vet
  -tags nogui and GOOS=windows go vet of internal/gui and internal/cli:
  clean. go build: ok.
- go test -timeout 45m ./internal/gui/ ./internal/cli/: ok (180s, 70s).
- GUI, alone: browser-access.test.cjs and model-test-one.test.cjs pass in
  both engines; i18n-keys 23 of 24, its red is #3897 ("Runs as" from
  7f827b3b0), not this change. agent-stale-copies.test.cjs 80 of 80 at
  8d343a811 (this change before the rebase).
- Full GUI suite at 8d343a811: cut short. The disk filled (708MB free):
  browsers failed to launch with ENOSPC in agent-stale-copies, which then
  passed 80 of 80 alone, and node ended with exit 7 before the rest of
  the files ran. There is no full GUI record for this change.

Not tried: a real Cloudflare tunnel to the page, and Local network from
another machine.
2026-10-27 18:58:16 +08:00
yetone add927e604 codex: the Codex app beside the ChatGPT sign-in lists magpie's models too
laddieyao (Discord #general, 10-27): with Codex joined to magpie beside
its ChatGPT sign-in, the Codex desktop app's model picker showed OpenAI's
GPT models alone, while the Codex CLI listed magpie's. The /models
request does reach magpie's gateway and its answer holds magpie's
models. ChatGPT.app 26.1013's picker then narrows app-server model/list
to the models a Statsig config (107580212, use_hidden_models /
available_models) names, while Codex is on its built-in provider, unless
Codex reads its list from a file (model_catalog_json,
hasConfiguredModelCatalog) or names a provider of its own. The CLI has
no such filter.

Where the Codex app is installed (codexReaders has an "app"), and only
joined/beside the sign-in (not magpie as Codex's provider, not account
failover alone), magpie writes the list it hands Codex at
/backend-api/codex/models to ~/.codex/magpie-desktop-models.json and
names it with model_catalog_json. Codex is still on its built-in
provider. With a catalog named Codex asks for no list, so magpie asks
the backend itself, with Codex's live sign-in (provider.CodexLiveList):
its entries go in verbatim, base_instructions and all, merged as the
gateway merges them (codexMerged, factored out of codexModels: picked,
hidden, window, V1, AutoReview edits), magpie's models after them.

- A list not known (not asked yet, or the backend failing) is unknown:
  the file as it was stays, never an empty list; a key naming a file
  that is gone goes, as Codex loads no config then.
- Written via temp+rename at Join, set, settle and every Sync (so a
  change of magpie's models, picks or hidden models rewrites it, as
  SyncCatalog runs on them); the backend list is asked again hourly
  (5 min after a failure) and a change syncs again.
- A model_catalog_json of the user's own stands; none is written beside.
- magpie API, the app gone, or unwire take the key and the file out;
  unroute never restores the desk file as the user's catalog.
- connectinfo counts the file, so a running app on an old list reads
  as needing a restart.
- CLI-only machines: unchanged, the live /models path as before.

Run:
- Real account, sandbox HOME (copy of auth.json, chatgpt Pro; live
  ~/.codex untouched): Join wrote model_catalog_json and the file with
  the real backend's 10 entries (gpt-6.1-sol ... codex-auto-review, each
  with base_instructions) plus relay/claude-opus-5.5 and
  relay/claude-sonnet-4-5. Then the real app-server bundled in
  ChatGPT.app (codex 0.163.0-alpha.10.2, CODEX_HOME sandbox, base URL
  pointed at a dead port) model/list returned all 12, relay models
  visible, and config/read showed model_catalog_json set, which is what
  the app's picker checks to skip its filter.
- New tests: TestCodexDesktopListBesideSignIn, ...CLIOnly,
  ...KeepsTheirs (internal/agent), TestCodexDesktopCatalog
  (internal/gateway).
- Broken by hand, each went red: deskList a no-op (all three agent
  tests), the user's-own branch removed (KeepsTheirs), the gone-file
  branch removed (KeepsTheirs), the keep-last-good rule broken in
  codexDeskRefresh (TestCodexDesktopCatalog).
- go test -tags nogui -timeout 45m ./internal/agent ./internal/gateway
  ./internal/provider ./internal/cli at bc0a99bb6 (on 68bbcc01c):
  agent, gateway, cli ok; provider red on TestUnreadLogins...
  (synctest crash, #3632) and three TestFetch* tests (#3854), both red
  the same at origin/main 68bbcc01c / 5a3292354 run alone, both filed.
- Rebased over e7f21dba5 (Disconnect keeps a hand-set catalog): the
  conflict in unroute merged (the desk key counts as no catalog of the
  user's), and -run 'CodexDesktop|Disconnect|Unwire|Catalog'
  ./internal/agent ok. The packages' run at the final head could not
  build: the machine's disk was full (other sessions).
- gofmt -l clean; go vet ./... on darwin, GOOS=linux, GOOS=windows ok.

Not tried: clicking the real desktop app's picker (the app-server
answer and config were checked, not the GUI); the Windows Store app
(its readers get no version but count as the app; not run there); a
backend list change rewriting the file while the app runs (the app
needs reopening to read a new file, which connectinfo's restart notice
covers).
2026-10-27 18:38:27 +08:00
yetone ca8a6f346a agent: a renamed routing group moves its agents, and the Codex app reloads a changed catalog
lucis0116 on X: renaming a provider or a group in magpie didn't reach
every agent.

Display names already reached the agents' files: store and SaveGroup
drop the catalog, and SyncCatalog writes the new "<model> · <name>" and
"<group> · routing group" labels into Codex's model_catalog_json, Claude
Code's picker, OpenCode and Pi (checked in a sandbox HOME). Two gaps
were left:

- A routing group given another id (Routing page, `magpie groups
  rename`, TUI) left every agent on group/<old>, which magpie no longer
  has. The CLI even said "agents set to group/from need group/to now".
  agent.RenameGroup now moves each agent field on group/<old> to
  group/<new>, spelled as the agent spells it. It goes through
  renameRefs, the move RenameProvider already made, now shared by both,
  then SyncCatalog. The GUI, CLI and TUI call it in place of
  provider.RenameGroup.
- The Codex app's own app-server reads model_catalog_json only as it
  starts, and KeepCodexAppOnItsProvider restarts it only when
  codexAppRoute changes. The route named the catalog's path, not what
  the file holds, so a renamed provider or group, or a model added,
  stayed on the old list until the user quit the app. The route now
  carries a hash of the catalog's bytes (codexCatalogTag, read again
  only when the file's size or time changes). The restart goes through
  the existing idle gate: no Codex request in flight, 10s idle, no turn
  open. A write of the same bytes is no change.

Run, in a sandbox HOME only:
- TestRenameGroupMovesTheAgentsOnIt (new): Codex, Claude Code, OpenCode
  and Pi on group/smart, renamed to clever: each said moved and each
  file on group/clever, none naming group/smart.
- TestCodexAppRouteFollowsTheCatalog (new): the route changes when a
  renamed provider rewrites the catalog, and stays put when the same
  bytes are written again.
- Broken by hand: RenameGroup's match turned off makes the first test
  red (no agent moved, every file on group/smart). The catalog line
  dropped from codexAppRoute makes the second red ("a provider renamed
  left the Codex app's route as it was").
- At aded9beea (base ad3833512): go test -tags nogui -timeout 45m
  ./internal/agent ./internal/cli ./internal/gui ./internal/tui
  ./internal/provider -count=1: cli, gui and tui ok. agent red on
  TestFolderVarsAreListed (#3884, red on main since e4552cca9) and
  TestCodexDisconnectStaysWithAccountsOn/login=api, which passed 3 of 3
  alone and isn't on this path (filed #3891). provider crashed in
  TestUnreadLoginsWriteErrorsKeepCredentials with "close of synctest
  channel from outside bubble" in filememo.Forget (#3632, open on main).
- Rebased on 56de2d192 (a312bf3e3 adds a switched account's app-server
  to the same stale set; no overlap): go test -tags nogui -count=1
  ./internal/agent -run 'Rename|CodexApp|Sync|Group|Codex|Hermes' ok
  at this head; ./internal/provider -run
  'CodexApp|Group' ok at a312bf3e3 + this change. The disk was full (other sessions' suites), so the
  whole of each package wasn't run again at this head.
- GUI: group-id-dots, group-morph, agent-model-groups and i18n-keys,
  32 of 32. No GUI script changed, and the GUI tests answer the API in
  memory.
- gofmt -l clean. go vet -tags nogui on agent, cli, gui and tui for
  darwin, linux and windows: ok.

Not covered:
- Claude Desktop reads the gateway's model list only as it starts. It
  still needs its Restart button (AppBehind) after a rename, as after
  any other catalog change.
- Pi, omp and StepCode enabledModels: RenameRefs renames magpie/<old>/
  provider entries only. A group's magpie/group/<old> entry goes as
  scope-gone, and the pick of group/<new> is added again. Not checked
  entry by entry.
- Codex signed in beside magpie (models_cache.json aged by the catalog
  tag) was not run again here.
- No real Codex app restart was watched. The reporter's agent isn't
  named.
2026-10-27 18:22:29 +08:00
yetone 7f827b3b0b claude: magpie claude-code runs lists the Claude Code processes and says what they are
@Candydidi3 on X: with Opus in Claude Code, "magpie里拉起很多子进程". On a
Claude account each conversation is answered by a real Claude Code
(`claude -p`) with magpie's MCP helper (`magpie claude-mcp-helper`) as its
child. Claude Code's parallel subagents are conversations of their own,
so a session that starts N of them has N pairs running. idleMost (6)
pairs are kept for an hour so the next turn reads the prompt cache, and
runs waiting on tool calls stay up to 30 minutes. On macOS and Windows
nothing bounds the total unless the user sets `magpie claude-code runs N`.
A task manager names them "2.1.311" (Claude Code's binary is named by its
version) and "magpie", and nothing told the user what they were.

No leak was found. With the bridge's fakes, 12 concurrent conversations
left 6 runs when they ended their turns, 12 when they were parked on
tool calls and never answered (bounded by the 30-minute timer), and 0
right after they were cancelled. Real Claude Code 2.1.311, run with the
bridge's args, exits within 0.1s of stdin EOF and when its parent is
killed, and its helper exits with it.

So nothing about which processes run changes. They become visible
instead:
- GET /v1/magpie/claude-runs (claude_runs.go) lists each run with its pid,
  model, account, state (answering, idle for its next turn, or waiting on
  tools), since when, when magpie lets it go, and its RSS, plus
  claudeRoom's live count. It is loopback only, refused like the heap
  profile, and served no-store.
- `magpie claude-code runs` prints that list under the bound and says
  what the processes are and how long they are kept.
- runs record when they started, when the current turn began, and the
  timer's deadline (endIn wraps every timer.Reset). The literal 30-minute
  timeouts become runTimeout.

Tests:
- TestClaudeRunsNamesEachProcess: idle, tools and answering runs are
  listed with the pids that are alive, and dropped once they end; every
  caller profileCallersRefused lists is refused. It went red with the
  route taken out (404), and with the guard off 3 callers got the list.
- TestClaudeCodeRunsListsTheProcesses covers the CLI's lines and the case
  with no magpie running. The existing CLI test now stubs the gateway, so
  it never asks the live magpie on :3425.
- oneport_test knows ClaudeRunsPath.

Real run (10-27): a sandbox HOME with a made-up Claude sign-in in its own
CLAUDE_CONFIG_DIR (no keychain item was written for it), `magpie serve`
on 127.0.0.1:47820, and a `claude` wrapper that exec'd real Claude Code
2.1.311 against a mock Anthropic API. 8 concurrent subagent-like
requests left 6 Claude Code, each with its helper. `magpie claude-code
runs` listed the same 6 pids ps showed, idle, ends in 59m, about 160 MB
each. SIGTERM to the sandbox serve ended all 12 within a second.

Run (go1.26.8, -tags nogui, private GOCACHE):
- At 184b4b8ba (this change on origin/main 5a3292354): gofmt clean; vet
  for darwin, linux and windows; `go test -count=1 -timeout 45m` of
  internal/cli ok (88s) and internal/gateway FAIL (1079s). Of the 118
  tests that failed, 117 failed on "no space left on device" (other
  sessions filled the disk to 0 bytes free mid-run), and
  TestHistoryKeepsDaysAndDropsOld failed because its big writes were cut
  short. All 118 run again with -count=1: ok (153s). The history test
  -count=3: ok.
- At this commit, rebased on origin/main 56de2d192 (Kiro's and Qoder's
  mins, plugin options, Codex app-server restarts and Hermes, none of it in these
  files): gofmt clean; vet for darwin, linux and windows; `go build
  -tags nogui .`; TestClaudeRunsNamesEachProcess, TestClientPathCoversHandler
  and TestClaudeCodeRuns* ok. The GUI build and a full gateway run there
  didn't fit on the disk (about 500 MB free).
Not run: the full ./... suite, Windows or Linux, a real Anthropic account,
and the GUI suite (no GUI change).
2026-10-27 18:22:01 +08:00
yetone e4552cca9f library: a cargo RTK upgrades on Windows, and says why when it can't
新v学员 (Discord #feedback, 10-27): upgrading an RTK installed with cargo
failed silently on Windows. Four causes, each fixed:

- No cargo on magpie's PATH (magpie started before Rust was installed,
  or from a shortcut whose PATH rustup never touched): rtkUpgrader gave
  no upgrade, so Upgrade was greyed with only a tooltip, which a click
  never shows. Now the cargo rustup put beside rtk is run by its path;
  with no cargo anywhere, the card (and the CLI) says it was installed
  with cargo, to install Rust from rustup.rs or run the command shown
  (RTKView.NoUpgrade, Manual), and UpgradeRTK's error says the same.
- CARGO_HOME (D:\Rust\.cargo is common) moved cargo's folder: an rtk
  there wasn't cargo's to magpie. cargoBins reads it, for finding rtk
  and for the upgrade; on Windows the folder matches whatever its case.
- cargo install --git built rtk-ai/rtk's default branch, develop, whose
  Cargo.toml says 0.49.0 while v1.1.0 is out from master: the upgrade
  left rtk as it was, or older, on every OS. It now names --branch
  master, as rtk's own installation guide does.
- Windows refuses cargo's move over a running rtk.exe ("failed to move
  … (os error 5)", exit 101, after the whole build), and an agent runs
  rtk for every command. On that refusal the rtk is renamed aside
  (rtk.exe.old-<pid>, which Windows allows), a copy put in its place,
  and cargo run again; its build is kept in magpie's CARGO_TARGET_DIR,
  so the retry builds nothing. Old copies are removed on the next
  upgrade.

A failed cargo now says its first error with the cause, and what to do
for the common ones (rtk in use, link.exe/dlltool missing, GitHub
unreachable), not its last three lines, which only said the build
failed and where its files were left.

Run:
- Real Windows (10.0.0.132, sandbox CARGO_HOME/RUSTUP_HOME/USERPROFILE,
  rustup + cargo 1.99.1, removed after): plain cargo install over a
  running rtk.exe fails with "拒绝访问。 (os error 5)" exit 101; a
  Windows build of this package's tests (GOOS=windows go test -c, a
  scratch test calling ReadRTK/UpgradeRTK, not committed) with no cargo
  anywhere gave NoUpgrade "cargo" and the new error; with cargo only
  beside rtk (not on PATH) and the old rtk.exe running, UpgradeRTK
  built rtk-ai/rtk master and went 1.0.0 -> 1.1.0 in 3m26s, the running
  rtk kept running, rtk.exe.old-<pid> was left and removed once it
  exited. The build used the gnullvm toolchain with llvm-mingw; the
  gnu toolchain failed with "error calling dlltool" and lld's missing
  -lgcc_eh, which is the output the tests use.
- New tests (rtk_cargo_test.go) and the updated
  TestRTKUpgradeCargoNamesThePackage are red on origin/main
  (32ea16c5a): no upgrader without cargo on PATH, the generic error,
  the last-three-lines message, no --branch. The Windows paths are
  forced through rtkOnWindows.
- go test ./internal/library ./internal/cli ./internal/gui (sandbox
  HOME): ok. gofmt -l clean; go vet ./..., GOOS=linux go vet -tags
  nogui ./..., GOOS=windows go vet ./...: clean.
- GUI, chromium and webkit: library-rtk-*.test.cjs and i18n-keys (136
  pass), the new card test in en, zh, zh-TW, ja, de at 440px; then
  every library*.test.cjs file (736 pass, 0 fail).
- Rebased on origin/main 68bbcc01c (none of these files changed
  since 32ea16c5a): the three packages ok again, gofmt and vet clean.

Not tried: the MSVC toolchain (the box has no Visual Studio Build
Tools), so the link.exe hint is from cargo's known message, not seen
here; an rtk installed with non-default features is upgraded with the
default ones; CARGO_HOME is read from magpie's own environment only.
2026-10-27 17:08:57 +08:00
yetone 2afacd7d18 windows: a terminal waits for magpie, through a magpie.com beside the app (#3737)
The Windows app is linked with -H windowsgui so a double click opens no
console, and PowerShell and cmd don't wait for a GUI program. The prompt
came back before magpie printed, and `magpie plugin login`'s password
keys went to the shell as well as to magpie (tom047784 / TomXPRIME on
Discord, 10-27; the handle error in the same report was 9298d2a).

A shell looks for `magpie` by PATHEXT, which lists .COM before .EXE. So
magpie now writes magpie.com beside the app. It is a 1.9MB console program
(internal/update/launcher), built and embedded by `make release-windows`
(the comlauncher tag). The shell waits for it. It runs the app with its own
std handles, passes MAGPIE_COM=1, waits, and exits with the app's code. The
app keeps those handles and borrows the console for the streams Windows
dropped (a GUI child gets no console handles), so redirection, pipes and
hidden prompts work. A command that opens the window (none, app, gui, tray,
panel, -Embedding, magpie: links) is started DETACHED, and the shell isn't
held. A double click and the Start menu still open magpie.exe.

Why this, and not a console-subsystem copy or a magpie-cli.exe: the
running process is still magpie.exe, so autostart, shortcuts, relaunch and
every os.Executable() use are unchanged. There is no new release asset (still
16), and magpie-releases needs no change. The trailer names the app, so a
download kept as magpie-windows-amd64.exe is run by its own name.

Where it is written:
- Settings › Command line's Add (cliPlace) writes it instead of magpie.cmd
  in a build that carries it.
- A terminal command run as magpie.exe writes it when the folder is on PATH
  or has a magpie.com or magpie.cmd, so existing users get it on their next
  `magpie <cmd>`.
- The app's start (placeExe) writes it again when the bytes differ, so an
  update brings it along.
- A running magpie.com is moved aside and cleared on the next run.
- A copy beside a magpie.exe leaves `magpie` to it (comOwner).
- The Command line row reads magpie.com as this app, with "(which runs
  magpie.exe)".

Run, at 2e165fe9d (main since then touches none of these files):
- gofmt -l: clean
- go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...
- go build for darwin, linux -tags nogui and windows
- make release-windows: amd64 and arm64 are PE subsystem 2 (GUI), as before
- go test -tags nogui -count=1 -timeout 45m ./internal/update/...
  ./internal/cli/ ./internal/gui/ ./internal/proc/: all ok
- cli-path.test.cjs in chromium and webkit (11 + 11 pass); i18n-keys,
  gui-zh-tw, gui-ja, gui-de pass
- The Windows box, with GOOS=windows test binaries: launcher's TestArgsOf,
  TestOpensWindow and TestTargetName pass; update's TestWriteCom,
  TestComOwner, TestEnsureCompanion, TestFindCLIPrefersCom and
  TestCLIShim pass. TestComMagicIsTheLaunchers reads the source, so it
  can't run from a copied binary there; it passes on macOS.
- The Windows box, sandbox HOME, release build, interactive ConPTY over
  ssh -tt with typed keys:
  - Old v0.1.1675 in PowerShell 7.5.4: the prompt comes back before
    "magpie 0.1.1675", $LASTEXITCODE is empty, `> out.txt` is empty, and
    backup's passphrase is split between the shell and magpie.
  - New build in PowerShell 7.5.4: the first `magpie` as magpie.exe wrote
    magpie.com, and Get-Command then resolves it. `magpie version` prints
    before the next line, with exit 0. A bad command gives 1. `> out.txt`
    holds the version. backup reads "Passphrase for the backup:" and
    "Again:" typed. restore reads "Passphrase:" typed. A piped passphrase
    is read (wrong passphrase, exit 1).
  - New build in cmd: `where` lists magpie.com first. The same version,
    ERRORLEVEL 0 and 1, and typed backup and restore passphrases work.
    Ctrl+C at a prompt ends it with 0xC000013A and leaves no magpie.exe.
  - The update: an older magpie.com in place was moved aside and rewritten
    by the first command of the new build, and the .old was gone after the
    next one.

Broken by hand, red:
- writeCom always rewriting: TestWriteCom
- EnsureCompanion ignoring PATH: TestEnsureCompanion
- comOwner always true: TestComOwner
- app.js's old shim-only condition: the "magpie.com is said to run the app"
  case in en and zh

Not tried:
- A real double click or the Start menu on the box. magpie.exe is still
  GUI-subsystem and is what they open, but no window was opened there. The
  sandbox app would share the gateway's port with the box's own magpie.
- Windows Terminal itself; the ConPTY ssh -tt gives is what it uses.
- The arm64 build on a real ARM machine.
- The full go test ./... at this head. Another session's agent and
  gateway suite was running on the machine (load ~115), so only the
  touched packages and internal/proc ran.
2026-10-27 12:08:16 +08:00