Commit Graph
281 Commits
Author SHA1 Message Date
yetone 623e797fde plugin pages: read a day's usage and share a picture they drew
A plugin's page can now read one day's usage and share an image it
drew. This is for the day card (JungleyYeh on X asked for a "daily AI
statement"); the card itself is an optional community plugin,
@magpie-community/page-day-card.

- A page that asks for the "usage:day" read gets that day as
  magpie.read("usage:day", {date, tz}): totals, each agent and its
  models, the streak and the average active day (usageapi/day.go,
  gui/pageday.go). The Plugins page names the read before it is granted.
- magpie.image.copy(png) and magpie.image.save(png, name) share a PNG
  of at most 16 MB. In the window they go through
  POST /api/plugin-pages/image (pageimage.go): copy puts the picture on
  the clipboard (clipimage.go: osascript PNGf on macOS, PowerShell
  PNG + Bitmap on Windows, wl-copy or xclip on Linux), and save writes
  it to Downloads under a name made safe. In magpie web, the browser
  saves or copies the picture itself.
- The window's side, pageshare.js, is imported the first time a page
  shares a picture. The core grows by its one call only, paid for by
  comments cut, so the budget is not raised.

Tests:
- New: TestDayOf, TestPluginPageReadsADay, TestPluginPageSharesAPicture,
  TestPageImageName and TestClipImageCommand. plugin-page.test.cjs
  covers the bridge, both engines and a refused SVG.

What was run (mote):
- gofmt, plus go vet on darwin, linux and windows: clean.
- Full go test ./... at the pre-rebase base: 369 packages ok, 3 FAILs.
  - TestEveryRouteHasACommandOrIsNamed and TestCoreScriptBudget were
    this change's own reds. The new route now has a parity entry, and
    the share code moved into lazy pageshare.js with no raise.
  - TestGatewayModeStatsNameTheGatewaySessions is #5690, the red in the
    first hour of the day (it ran at 00:32).
- GUI suite (affected and plugin files, both engines): 1160 of 1179
  passed. Every red is filed and none touches this change:
  - i18n-keys "a plugin's words are its own": #5332, #5426, #5482.
  - page-width-steady: #5013.
  - plugin-card-update in WebKit: #3079.
  - plugin-move-unserved "Try again": #4410.
- At this head, after the rebase on bc8b01d60:
  - gofmt clean; go vet ./internal/... on darwin, linux (nogui) and
    windows ok.
  - internal/usageapi, internal/plugin and internal/cli ok.
  - internal/gui: TestCoreScriptBudget, the TestPluginPage* tests and
    the TestPageImage/TestClipImage tests pass.
  - plugin-page and old-webkit (both engines): 12 of 12.

Real use:
- A sandbox HOME with a copy of real usage, through the real GUI
  server, in Chromium and WebKit, light and dark, en/zh/zh-TW/ja/de, at
  420 and 1100 px. The card showed 87.9M tokens, $9.85 and 4076 calls
  with a 22-day streak.
- Picking an earlier day and WebKit's Copy ("Copied") worked, with no
  page errors.
- Not tried at push: Chromium's Copy (its headless clipboard was
  denied) and magpie web's Save as a captured download. A second real
  run that grants both was still queued on mote's suite lock.
- Clipboard: checked live on macOS (osascript) and Windows
  (PowerShell). Not tried live on Linux: WSLg had no display.
2026-11-09 23:19:14 +08:00
yetone 92e8edd7fc windows: magpie is listed in Installed apps, and its Uninstall puts every agent back
Jevik_AI on X uninstalled magpie and rebooted, and Codex's config.toml
still had openai_base_url = "http://127.0.0.1:3425/backend-api/codex";
Rk1ngggg asked whether an update cleans it. magpie's own uninstall
(Settings › About › Uninstall magpie, `magpie uninstall`) already
disconnects every agent and takes Codex's leftovers (#3866), but on
Windows magpie wasn't in Settings › Apps › Installed apps, so it was
removed the way Windows offers for a program it doesn't list: by
deleting the exe and folders, which runs no code.

shortcut.Ensure now writes
HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall\magpie
(DisplayName, DisplayIcon, Publisher, InstallLocation, UninstallString,
URLInfoAbout, NoModify, NoRepair) at every installed start, beside App
Paths, and Remove (uninstall's System step) takes it out the same way:
only while it names this exe, or an exe that is gone. Its Uninstall
runs `magpie.exe uninstall --window` (shortcut.UninstallArgs). magpie.exe
has no console, where the terminal's `magpie uninstall` would refuse
for want of one to ask on, so those exact args open the app's window
(or forward to the running app, OnSecondInstanceLaunch) on Settings ›
About with Uninstall magpie's question asked (uninstallView,
?uninstall=1). It asks once: a redraw of Settings doesn't ask again,
and Cancel removes nothing. magpie web opened at that link asks
nothing. Deleting the app by hand still runs no code (macOS
drag-to-Trash included); agent-wiring.md says so.

Run on mote at the pushed head (rebased onto be9dbce02):
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok. go build, GOOS=linux go build -tags
  nogui, GOOS=windows go build: ok.
- go test -tags nogui ./internal/gui ./internal/cli ./internal/shortcut
  ./internal/uninstall: ok (TestCoreScriptBudget included).
- uninstall-settings.test.cjs and i18n-keys.test.cjs: 40 of 40
  (chromium and webkit; the new Installed-apps cases in en and zh at
  1100 and 420).
At d3f40bedd, the same change on c7ebb6f8d, under suite.lock:
- go test -tags nogui -timeout 45m ./...: ok, every package.
- The whole GUI suite (--test-concurrency=4): 22518 of 22800; the 282
  reds are in 53 files the change doesn't reach (model-chip-steady 40,
  usage-agents-hide 22, zero-priced-free 20, provider-fetch-again 14,
  ...), the full-suite reds of #5475; the numbers are on that issue.
  Their run at c7ebb6f8d alone is queued behind other sessions' suites.
- The first full run found the core scripts 147 bytes over
  TestCoreScriptBudget; the page's part was cut to one line (the
  budget is not raised).
On xiaomi-gpu (win-run): go test ./internal/shortcut, incl.
TestInstalledAppsEntry on the real HKCU registry under a test key: ok.

Broken by hand, each red:
- registerAppPath not calling registerUninstall: TestInstalledAppsEntry
  (UninstallString = "") on Windows.
- main.go not taking UninstallArgs to the window:
  TestInstalledAppsUninstallOpensTheWindow (unknown "--window").
- app.js not asking on ?uninstall=1: 4 of 4 Installed-apps GUI cases.
- app.js asking without its once guard (params.delete): the same 4
  ("asked again").

Not tried: a real Settings › Apps › Uninstall click on Windows with an
installed magpie (the test box's install belongs to other sessions); the
second-instance forward (OnSecondInstanceLaunch) has no test of its own.
2026-11-09 22:33:31 +08:00
yetone 39569d5604 claude desktop: an optional Claude Magpie app beside your own Claude (#5671)
baranwang on X asked to keep Claude Desktop's own (1P, Anthropic) sign-in
while using magpie. Turning on "Separate app" in Claude Desktop's row on
the Agents page (or `magpie claude-desktop launcher add`) moves magpie's
3P wiring into ~/Library/Application Support/Claude-Magpie-3p and adds
~/Applications/Claude Magpie.app. That launcher opens Claude.app with
--user-data-dir on that folder, so it runs side by side with the user's
own Claude.app. Its icon is Claude's icon with a magpie badge. Off is the
default, and turning it off (`launcher remove`) moves the wiring back
and removes the app. It is macOS only: Desktop's packaged app strips
CLAUDE_USER_DATA_DIR, and on Windows it hardcodes LOCALAPPDATA\Claude-3p.
The folder ends in -3p because Desktop adds -3p to any other name.
Restarting the isolated app ends only its own process (pkill on its
--user-data-dir) and opens the launcher again.

Run at 1b25cda26 (this change on origin/main be9dbce02); rebased onto
fdabddeb4 (catalog only), then go build ./..., vet and the budget and
launcher tests again: ok. All
on mote:
- gofmt -l clean; go vet ./internal/...; GOOS=linux go vet -tags nogui
  and GOOS=windows go vet on agent, cli, desktopiso, desktopdir, gui.
- go test (whole packages) desktopiso, desktopdir, settings, settingsapi,
  proc: ok. -run Isolated|TestDesktopInstance|TestAddStartsDesktopOnTheFolder|
  TestScript|TestAddLeavesTheirs|ClaudeDesktop|Restart in agent;
  TestClaudeDesktopLauncher|TestEveryRouteHasACommandOrIsNamed|Help in cli;
  TestCoreScriptBudget|TestSettingsSaveKeepsWhatItDoesNotSend|Budget|Desktop
  in gui and gateway: ok.
- An earlier full `go test ./...` at fef23255f had four reds, all from
  this change and fixed here: the route without a command (now in
  notYet), settings_keep's DesktopIsolated, os/exec instead of proc, and
  the core script budget (paid by sharing the switch helper with the
  largest-window line and cutting comments; no raise). A second full run
  of the touched packages queued ~7h on mote's suite lock behind other
  sessions and was stopped; the targeted runs above replace it.
- GUI on mote, both engines: desktop-isolated (new; en, zh, zh-TW, ja,
  de; 1100 and 640; aria-checked, posts, status text, no scroll, no
  select, absent without `isolated`), desktop-longest, click-scroll,
  plain-names, i18n-keys: ok. page-width-steady, panel-fold and
  zero-priced-free are red, the same 33 tests at origin/main be9dbce02
  (diffed): #4541/#5013, #5796, #5262. i18n-keys' "a plugin's words are
  its own" is red on main too (#5332).
- Whole GUI suite on WSL at an older head: 400 of 22778 red across
  ~100 files of other pages, in line with #5559 (478 of 21666 on main
  there). Not rerun on mote.

Real use, on mote in a sandbox HOME with Claude.app 4.23118 linked in:
`claude-desktop magpie`, then `launcher add`, moved the wiring to
Claude-Magpie-3p (deploymentMode 3p, mcpServers and locale carried).
Opening Claude Magpie.app started Claude with
--user-data-dir=.../Claude-Magpie-3p; it wrote configLibrary and
model-catalog there (3P mode) and no -3p-3p folder. A second, 1P Claude
ran beside it on its own sandbox folder. Opening the launcher again
kept one instance; the pkill pattern matched only the isolated pid; both
quit on SIGTERM. `launcher remove` put the wiring back and removed the
app.

Broken by hand: a folder without -3p (Desktop made -3p-3p), the
CLAUDE_USER_DATA_DIR env route (ignored by the packaged app), os/exec in
the quit (TestNoCommandBypassesProc red).

Not tried: a screenshot of the running app (screencapture fails over
ssh); a model request through a gateway from the isolated app; Windows
and Linux (not offered there). Known: the Dock shows Claude's own icon
for the running isolated app, and Chrome pairing is off in a moved
userData folder.
2026-11-09 22:31:16 +08:00
yetone c056b7c8c3 provider: a Responses provider's turns may go over the Responses WebSocket (#5781)
A provider the user added with an http(s) Responses address can now send
its Responses turns over the Responses WebSocket that magpie already
speaks to chatgpt.com (codexSocket), with `socket=auto|on|off`:

- off, or absent: today's behaviour exactly. Provider.Via hides any
  socket value an outer context carried, so such a provider never dials.
- auto: tries the socket, falls back to HTTP when the handshake is
  refused or the socket ends before the reply, and speaks HTTP to a host
  for 10 minutes once it refused the handshake (codexShun).
- on: the same fallback, but never shuns; the socket is tried each turn.

Provider.Via puts the provider's Responses host and path in the request's
context (withSocket); codexSocket's gate is provider.SocketTurn, which
takes a ChatGPT turn as before, or a POST to that host at
<Responses>/responses. The rest is the ChatGPT leg's: the kept socket and
its delta (codexKeepKey now also hashes the scheme, X-Api-Key and
Api-Key), the error frames, 1009 handling. A provider's reply with no
Content-Type is marked text/event-stream, since it is read as one.
Routing, keys, limits, usage and masking are unchanged: only the
transport under the request differs.

Set with `magpie provider set <id> socket=auto|on|off` (refused on a
provider with an account, no http(s) Responses address, or Vertex,
TakesSocket), saved in providers.json as "socket", shown by `provider
show`, and in the editor's Advanced as a WebSocket tick beside HTTP
version (ticked saves auto, keeps a CLI's on, unticked saves off; shown
only while the Responses address is http(s) and there is no account).
docs/subsystems/providers-accounts.md describes it.

app.js pays for its rows by three long comments cut to one line
(renderMove, the vendors' status pages, header rows): the core's scripts
are 478 bytes smaller than on 0eac4e6aa (1,533,069 of 1,533,802); no
budget raised.

Run on mote at this change on origin/main 0eac4e6aa (since then main
added a39b63e88 and 7cabf0da9, internal/sessions only):
- gofmt -l clean; go vet (darwin) of provider, gateway, cli, gui, clean.
- go test -tags nogui ./internal/gui ./internal/cli: ok;
  ./internal/provider -run TestSocket: ok.
- go test ./internal/gateway -run 'TestResponsesProvider|TestCodexSocket|
  TestCodexKept|TestCodexTurn|TestHTTP1|TestInsecureTLS': ok. The new
  tests use an httptest WebSocket upstream: a turn over the socket, a
  provider without the field never dialling (and one on the same host
  with it), a refused handshake shunned on auto and tried again on on, a
  socket closed before the first event going over HTTP, the kept
  socket's delta on the next turn, and the reply being a stream.
- node --test provider-socket (new; chromium and webkit, en zh zh-TW ja
  de, 1100 and 420 wide), provider-http1, provider-insecure-tls,
  i18n-en-no-cjk: pass. i18n-keys' "a plugin's words are its own" is
  red for three words in files this doesn't touch, filed as #5327/#5332,
  #5426 and #5482.
- One rebase earlier (on 2a48974e8, the same change): GOOS=linux (nogui)
  and GOOS=windows go vet of the four packages clean, and the whole of
  ./internal/provider ok.
- Broken by hand, each red then green: SocketTurn codex-only (all six
  gateway tests red); a path-suffix gate in place of the context
  (WithoutSocketNeverDials, TestSocketTurn red); the never-shun case
  removed (RefusedOnTriesAgain red); the Content-Type line removed
  (ReplyIsAStream red).

Not tried: a real Responses upstream speaking the WebSocket (no network
in tests); the keep key's X-Api-Key/Api-Key separation has no test of
its own; the editor in the Linux app's WebKitGTK; the full suite (run
after the push).

Reported-by: matrix0487 (Discord)
Reported-by: faithleysath (#5781)
2026-11-09 18:57:29 +08:00
yetone 40cbdaa7e8 provider: an account's window can be capped at a fixed amount of its unit
A window magpie reads with a total and a unit (a day's 1000 credits, a
plan's requests) can now be capped at an amount of that unit, not only
a share: 9won_25273 asked to stop an account at 300 of its day's credits.

- AccountWindowAmounts keeps it per account and window (capId). An
  amount and a window's own share replace each other.
- WindowCaps.limitShare turns it into a share of the total for the mark
  and NearCap. CapHeld and capReached hold the account once the window's
  count reaches the amount (past), and rest it as the percentage cap
  does: the next account takes the request. cappedError and the trace
  say "has used 300 credits ... past its cap of 300".
- A reading with no total ignores the amount; the account's share
  applies.
- GUI: the window meter's menu has one more item, Amount..., typed in
  place (provider/windowcap with amount). It shows only on a window
  with a unit and total. Strings in zh, zh-TW, ja, de.
- CLI: magpie provider account-cap <id> <account> --window <name>
  --amount <n|off>.

Usage outside magpie counts: every cap reads the vendor's own count, so
what the account spent in the vendor's app or on another machine counts
from the next reading on. magpie can only hold back its own requests.

Run, at this head on Linux (wsl-run, magpie-desktop):
- gofmt -l: clean; go vet ./... for linux (-tags nogui) and windows: ok (darwin
  vet needs cgo, so it runs with the full suite on mote afterwards)
- go test -run 'Lang|ToolLoop|LoopGuard|Cap|Amount' ./internal/gateway
  ./internal/provider ./internal/cli: ok (TestWindowAmountCapHeld,
  TestSetWindowAmount, TestWindowAmountHoldsTheAccount, the CLI cases)
- GUI window-cap, window-cap-pool, account-cap in chromium and webkit,
  420 and 1100 wide, en zh zh-TW ja de: 78 of 78 in each engine. An
  earlier webkit run lost the amount test's page once ("Target page,
  context or browser has been closed"); it passed in 2 more full-file
  runs and 60 of 60 alone
- i18n-keys: only "a plugin's words are its own" red, words that aren't
  this change's (#5332, #5426, #5482)
Broken by hand: limitShare ignoring amounts (of < 0): TestWindowAmountCapHeld
and TestWindowAmountHoldsTheAccount go red.
Not tried: the full go test ./... at this head (queued on mote, runs
after); a real account at an amount cap.
iFlytek: 9won's 讯飞 overshoot isn't covered. Loomy's daily window sends
used as a count and amount as what is left (plugins#889); AStudio's
wallets tell a balance only, which no cap can hold (#5770).

Reported-by: 9won_25273 (Discord)
2026-11-09 18:19:02 +08:00
yetone b475004d52 library: Pi's extensions and packages, switched and copied between Pis
leokon3 runs Pi on Windows and in WSL and asked for magpie's Library to
manage Pi's extensions and packages. A new "Pi packages" tab in the
Library lists each Pi here (this computer's and each WSL distro's), with
the extensions and packages it loads, read by Pi's own rules
(@earendil-works/pi-coding-agent 1.4.0). Each has a switch, written as
`pi config` writes it, and a "Copy to…" menu for the other running Pis.

- A package is copied as its settings.json entry; Pi installs it itself
  when it next starts. node_modules is never copied. A local package, and
  one the other Pi already has by Pi's identity (npm name, git host/path),
  is refused.
- An extension file or folder is copied as files, without node_modules,
  .git or symlinks, never over one of the same name. The page says to run
  npm install there when it has dependencies.
- A package that already picks some parts (filtered in `pi config`) shows
  its switch disabled. A settings.json that can't be parsed lists nothing
  and is never written; a stopped distro is never started; every write is
  backed up first.
- GET/POST /api/library/pi, POST /api/library/pi/copy (notYet in the CLI
  parity list, stage 3: the library).

Run at 29d63e2dd (this tree on origin/main c7ebb6f8d; rebased after onto
608c1543e, which changes only internal/gateway), on mote:
- gofmt -l clean; go vet -tags nogui for darwin, linux and windows on
  internal/library and internal/gui: ok.
- go test -tags nogui ./internal/library ./internal/gui ./internal/cli:
  ok, ok, ok.
- A real pi 1.4.0 (npm) in a sandbox HOME and PI_CODING_AGENT_DIR, through
  an uncommitted pireal test: pi -p loads hello.ts (a marker file), the
  switch turns it off (no marker) and on again; a todo folder copied from
  a second Pi's dir is loaded by the real pi; npm:pi-web-access@0.47.0
  copied as a settings entry was installed by pi itself into
  <agentDir>/npm/node_modules and read back as installed v0.47.0; switched
  off, `pi list` still lists it and magpie reads it off.
- GUI, 70 files (library-*, i18n-*, gui-* and the Library's neighbours),
  both engines: 1503 of 1515 pass. The 12 reds are the same on origin/main
  c7ebb6f8d: page-width-steady's 11 (run there alone, 11 of 20 red; #5013)
  and i18n-keys "a plugin's words are its own" for "Use the library's",
  "No session ID" and "View routing" (#5482, #5426, #5332).
  library-pi-extensions runs en, zh, zh-TW, ja and de at 980 and 380px.
On Windows (win-run): go vet with and without the pireal tag ok; go test
-run TestPi ./internal/library ok.

Broken by hand: the first run named the tab "Pi extensions", which a
comment in internal/provider/discovery.go says too, and i18n-keys went
red for it; library-loading went red for the new tab next to RTK while a
Pi is here; and TestEveryRouteHasACommandOrIsNamed went red for the three
routes. All three were fixed and pass in the run above.

Not tried: a real copy between a WSL Pi and the Windows Pi (the WSL side
is covered by the unit tests' fake distro only), the full go test ./...,
and the whole GUI suite.

Reported-by: leokon3 (Discord)
2026-11-09 16:33:28 +08:00
yetone 608c1543e8 gateway: a bare model name goes to the asking agent's own subscription first
freefcw on X: Codex, started by Mirasim, asked for gpt-6-astra by its bare
name. Its own ChatGPT subscription serves it, but magpie sent it to Devin
through the group it found (auto-gpt-6-astra, soonest renewal first).
With found groups off it still went to another vendor: Resolve takes the
first provider in the Providers order, AutoStandIn and agent.Reseat did
the same.

Now:
- A bare model id the asking agent's own subscription in magpie serves (a
  provider whose Account.Agent is the agent: Codex's ChatGPT accounts,
  Claude's for Claude Code, Copilot's) goes there, found groups on or off
  (gateway ownFirst, provider.OwnRoute). count_tokens counts it there too.
- Kept as they were: a group the user made or changed by that name; a found
  group magpie set one of the agent's fields to (agent.SetToGroup over the
  applied record, #750's bare spelling included, wired as
  gateway.SetToGroup); a gateway key held to some models; ids with a
  provider in them and group refs; clients magpie doesn't know as an agent.
- Found groups off: a bare id several providers serve, none of them the
  agent's own, is refused for an agent that has a subscription of its own
  in magpie, with a 400 naming the provider/model ids and
  "magpie group auto on" (provider.OffSpread). Off, magpie picks no vendor.
- AutoStandInFor and Reseat's sameModel prefer the agent's own
  subscription for a found group that is gone.

Docs: gateway-routing.md's Model resolution row and the bare-ids section.

Run (mote, at this tree on c7ebb6f8d):
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/provider
  ./internal/agent ./internal/cli ./internal/gateway: all ok.

Broken by hand, each red:
- ownFirst off in serve (and AutoStandIn back):
  TestBareNameGoesToTheAgentsOwnSubscription went to the relay with groups
  on, and again with groups off alone (the reporter's two cases).
- OffSpread check off: TestBareNameOnSeveralVendorsRefusedWhileGroupsOff
  answered 200 from the relay.
- SetToGroup check off: TestBareNameOfAGroupSetOnTheAgentStaysTheGroups.
- The user's-group and own-entry checks off: TestOwnRoute, TestOffSpread.

Not run at this head: the full ./... suite (mote's suite.lock had five
suites queued); it runs under the lock after the push, any red filed.
Not tried: a real Codex with a real Devin plugin account; Reseat's own
preference has no test of its own (needs a fetched Codex account in the
agent package's sandbox).

Reported-by: freefcw (X)
2026-11-09 16:28:02 +08:00
yetone 8544d5fdb5 settings: Download source says usemagpie.ai first, GitHub when it fails
Since v0.1.3345 an update's files come from usemagpie.ai (R2) and go to
github.com only when that fails; a mirror stands in for github.com only.
Settings › About › Download source still showed "GitHub", said updates
come from GitHub, and its button "Use GitHub" (zh 恢复官方) read as
switching back to GitHub. Now it shows usemagpie.ai, says GitHub (or the
mirror) is the fallback, and the button is Remove mirror (不用镜像), in
en, zh, zh-TW, ja and de. `magpie update mirror` says the same.

Run on mote (update-mirror, i18n-en-no-cjk, i18n-keys and cli vet again at the rebased head: ok but #5332):
- update-mirror, i18n-keys, i18n-en-no-cjk and every GUI file that opens
  About (19 files), chromium + webkit: update-mirror and i18n-en-no-cjk ok.
  The reds, rerun one file at a time:
  - i18n-keys "a plugin's words are its own" and segs-press-redraw
    "clicks its new self once": red the same at origin/main 26e9c9566,
    filed as #5332/#5426/#5482 and #4566/#3922.
  - lan-docker, public-url-default: red at load ~400, 62/62 ok at load 36.
  - about-*, cli-path, settings-sections, statusline-remote,
    uninstall-settings: ok alone (red only at load 278 to 400).
- go test ./internal/cli ok, go vet ./internal/cli ok, gofmt clean.
Broken by hand: the new update-mirror test run against origin/main's
app.js and i18n.js: 0 of 10 pass.
Not tried: the real app's About page; the whole GUI suite.
2026-11-09 09:36:33 +08:00
yetone 2a64b4bcb7 library: a skill router, one magpie-skills skill listing an agent's skills
Like the MCP router, for skills. With the Skills tab's new "Skill
router" switch on (off by default), each agent's skills folder gets
one skill of magpie's, magpie-skills, in place of a link of each skill
ticked for it. Its SKILL.md lists them, each with its description and
the path of its SKILL.md, and the agent reads that file when a task
fits. An agent then carries one skill's description in its prompt
however many the Library gives it.

- The entry is a link to <settings dir>/skill-router/<hash of the
  folder>/, which holds SKILL.md and a hidden .skills/<name> link of
  each listed skill (hidden, so Codex, OpenCode and Pi don't find a
  skill twice). Its description stays within 1024 bytes (Codex's
  limit), cut on a whole character.
- Every skill is listed unless it is kept direct (a button on the
  skill, or `magpie library skill router <name> direct`; carried by a
  sync), is only for the user to type (disable-model-invocation), is
  in ~/.agents/skills, is blocked, or the agent has its own by that
  name. Those keep their own links.
- An agent whose folder can't take it keeps every link, and the page
  says why: given copies, a live agent picking its own, the shared
  ~/.agents/skills, a Library skill called magpie-skills, or a
  magpie-skills of the user's (never written over).
- Claude Code 2.1.316 asks before reading outside its project, its
  skills folder too, so magpie adds Read rules for the entry and the
  folders behind it to permissions.allow, records them, and takes out
  only its own when they go (as permissions.deny does).
- The switch is this computer's alone; `magpie library skill router
  on|off` sets it from the CLI.
- Sessions count a routed read of .skills/<name>/SKILL.md as <name>
  (Claude Code, Alma, Droid), and calling up magpie-skills itself as no
  skill, so a use counts once.
- docs/subsystems/skill-router.md, with a row in the index.

Run at this tree (rebased on origin/main 8f74442e4), on mote unless
named:
- go test -tags nogui ./internal/library ./internal/sessions -count=1: ok
- go test -tags nogui ./internal/cli ./internal/gui: ok at bca122bf9;
  ./internal/gui again at 8f74442e4 (app.js changed there): ok
- node --test of every library-*, *skill*, i18n* and gui-* GUI file
  (96 files), in the Linux VM (wsl-run): mote's browsers didn't start
  while another session's simulators ran. 1678 pass, 11 fail at
  bca122bf9, every red also red on origin/main and filed: library-all
  WebKit (#4967), skill-where WebKit 400px (#5154), i18n-keys' plugin
  words (below), and library-own-folder under load, fixed here. The
  files this change touches, add-partners-shine and i18n-keys again
  at 8f74442e4: 111 pass, i18n-keys the 1 red.
- The router's row under the skill list moved four GUI tests'
  footing, fixed in the tests: remove-all-skills counted it as a skill
  (now rows of lists other than a hub's, as list-sort does);
  found-skill-pick-remove and library-pick-remove's reach only wheeled
  down from above the target, so a Select pushed under the sticky tabs
  or below the fold was never reached (now toward it, over the list,
  and the scroll at rest before the click, WebKit's settled a pixel
  late); library-own-folder's Playwright click scrolled the now
  taller page under load (now a click where the button is). Each red
  on the branch before, 22/22 or 14/14 after, twice.
- skill-router.test.cjs: 22/22 (chromium and webkit, 1100 and 420px,
  en zh zh-TW ja de)
- go vet -tags nogui, GOOS=linux and GOOS=windows: ok
- win-run (xiaomi-gpu) go test ./internal/library: ok but
  TestGoneAgentListedToTakeOut and TestCheckMixedServerEachSide, red the
  same at origin/main 6b0b7a96e and filed in #4115 (run at that
  base; nothing in internal/library has changed on main since). The
  router tests' expected rules were /C:/…; Claude Code's form is
  //c/… (claudePath), which the code wrote, so the tests now ask
  claudePath too.
- Broken by hand: routable returning true is red in TestSkillRouter (a
  skill for the user to type is listed); with the routerSkill check
  out of the sessions reader, TestClaudeRoutedSkillCounted is red.
- Real Codex 0.165.0, sandbox HOME, through the live gateway with no
  sign-in copied: a binary built from this change at 6b0b7a96e ran `library skill
  hand-over`, `skill agents secret-word codex` and `skill router on`;
  `codex exec "What is the project's secret word?"` read
  magpie-skills/SKILL.md, then .skills/secret-word/SKILL.md at the path
  given, and answered PELICAN-7319. `router off` put the skill's link
  back and removed the router's folder.
- Real Claude Code 2.1.316, sandbox HOME, through the live gateway on
  auto/gpt-5.6-luna: that binary wrote the router and two
  Read rules into settings.json (the user's "model" kept). "Check your
  skills for one that fits, then greet me." ran Skill magpie-skills,
  then Read .skills/greet-user/SKILL.md without asking, and answered
  with the skill's words. Without the rules that Read was refused
  (tried earlier with hand-written settings). Not tried on the Claude
  subscription route with this binary: there the live gateway drops a
  skill's body, which the gateway commit before this one fixes.

Known: Alma reads Claude Code's and Codex's folders too, so it may find
several magpie-skills (#5722, not tried with a real Alma).
i18n-keys is red on 3 keys that aren't this change's, the same
on origin/main (#5327, #5332, #5482, #5426).
2026-11-09 08:38:02 +08:00
yetone d1f8d8aae7 agent: Cherry Studio adds magpie through its providers link (plugins#865)
Cherry Studio (CherryHQ) shows on the Agents page, and with
`magpie cherrystudio`, on macOS, Windows and Linux. Its row is the link
its main process takes, cherrystudio://providers/api-keys?v=1&data=, with
the gateway at <gw>/v1 as an OpenAI-compatible provider named magpie and
the named key agentKeyAt("cherrystudio"). Cherry Studio asks the user to
confirm it. magpie writes nothing into its store. "Added" is read
untouched from its 2.x database (Data/cherrystudio.sqlite, user_provider),
in the default userData and every one boot-config.json moved it to. A
database or boot-config that can't be read, or a 1.x userData (Local
Storage, no database), is unknown. The data is standard base64, because
Cherry Studio swaps raw + and / before parsing and back after. /api/open
lets that link through. aionui's database status is generalized into
dbStatus{has} so both apps share it. Icon: Cherry Studio's own logo, not
cherryin-color (a different product).

Run (mote, at this change on origin/main c66cdbea9; then rebased on
0f04dca6e and run again: vet of agent/gui/cli, Windows vet of agent/gui,
and the Cherry, AionUi, gateway-key and import-link tests, ok):
- gofmt -l clean; go vet ./internal/agent ./internal/gui ./internal/cli;
  GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...
- go test -tags nogui -count=1 ./internal/agent ./internal/gui
  ./internal/cli: agent and cli ok; gui ok but TestCoreScriptBudget, red the
  same on a clean c66cdbea9 (#4526, 1533856 > 1533802)
- node --test import-row.test.cjs i18n-keys.test.cjs: import-row 20/20,
  chromium and webkit, en/zh/zh-TW/ja/de, and 420px wide; i18n-keys red
  only on "a plugin's words are its own", the same on clean c66cdbea9
  (#5332, #5426, #5482). No new strings.
- TestCherryStudioLinkParsedAs2_1_10 runs the link through 2.1.10's own
  parser (copied into testdata) and the renderer's zod checks, with
  gateways whose base64 spells + and /.
- Real try on mote (macOS 27.2, arm64): released Cherry Studio 2.1.10 in a
  sandbox HOME and --user-data-dir, with a sandbox magpie of this tree on
  127.0.0.1:3561 and a fake upstream. `magpie cherrystudio add` opened the
  dialog with base URL http://127.0.0.1:3561/v1 and the key
  magpie-cherrystudio. Add saved it, turned off as every Cherry provider
  is. `magpie cherrystudio` then said added, read while the app ran (WAL).
  Sync models listed fake/fake-1 from the gateway, and adding it turned
  the provider on. A chat got the fake upstream's reply, and magpie usage
  counted it as Cherry Studio's. A link sent while the first-run welcome
  page was up showed no dialog; after "set up later" it did.

Broken by hand, each red, then restored:
- URL-safe base64: TestCherryStudioLinkParsedAs2_1_10 (baseUrl decoded as
  /x~>/v1 and /xy\x7f?/v1)
- no closing quote/slash on the address match: TestCherryStudioHas
  (another port's provider counted)
- the /api/open prefix dropped: TestCherryStudioImportRow
- Cherry Studio dropped from /api/open's app case:
  TestImportLinkNothingOpens

Not tried: a real run on Windows or Linux (detection is unit tests
only); Cherry Studio 1.x, which reads as unknown; a real vendor upstream
(the try used a fake). Full suite not run at push.

Reported-by: mysterysqwq
2026-11-08 19:09:21 +08:00
yetone 8bba91e65a cli: GET /api/context/session is the window's own (TestEveryRouteHasACommandOrIsNamed)
f418edffc added the route for a session's context, request by request,
in its detail view, beside /api/context/reply, and left the parity test
red on main. It is named W like reply.

Run on mote: go test -run 'TestEveryRouteHasACommandOrIsNamed|Import'
./internal/cli ok; the full ./internal/cli run at the parent was red on
exactly this route.
2026-11-08 18:37:41 +08:00
yetone b0926e81a2 import: a link can say where its key's balance is read (balance=, balance_path=, balance_method=)
A relay's "Add to magpie" link can now name the URL that tells a key its
balance, where the amount sits in the reply, and GET or POST. magpie
takes it only on the host of one of the link's own base URLs, over
https, with no userinfo or fragment, so a link can't send the key
anywhere its requests don't already go; anything else refuses the whole
link. balance_path or balance_method without balance is an error. No
header or token is taken from a link: an account-wide token is worth
more than a key, and a URL stays in browser history.

- provider.ParseImport: linkBalance checks and sets BalanceURL,
  BalancePath and BalanceMethod.
- CLI: the import preview shows the balance URL and doesn't ask it
  before yes (showProviderAsking).
- GUI: the import dialog shows method, URL and field (.imp-bal).
- Docs: docs/import in en, zh and ja (table rows, a note on headers,
  the builder's three fields with the same host check, a security
  bullet); docs/reference.md's parameter table.

Run on mote at this tree (rebased on 8fa3c60f8):
- go test -count=1 ./internal/provider ./internal/gui: ok
  (TestParseImportBalance, TestCoreScriptBudget in it).
- go test ./internal/cli: ok but TestEveryRouteHasACommandOrIsNamed,
  red on main since f418edffc (GET /api/context/session); fixed in the
  next commit, and ok there with -run 'TestEveryRoute…|Import'
  (TestImportPreviewAsksNoBalance).
- GUI import-link-balance, import-link-gemini, i18n-keys: 43/44. The
  red is i18n-keys "a plugin's words are its own", the same three
  strings on an origin/main 8fa3c60f8 copy (#5327, #5426, #5482).
- GOOS=linux go vet -tags nogui and GOOS=windows go vet of provider,
  cli, gui: ok. gofmt -l: clean.

Not tried: a real link with balance= imported into the app and read
against a real relay's balance endpoint.
2026-11-08 18:37:41 +08:00
yetone e215d335a6 gateway: a gateway key can cap its requests at once; the rest wait their turn
young02036 on Discord: a provider can be given a concurrency, so why
can't a gateway key? A key now has an optional MaxConcurrency, from 1
to 1000. Left unset (every key today), nothing changes.

- access: Key and Change get MaxConcurrency, and Identity carries it, the
  issuer's cap included. The concurrency-key action refuses a value
  below 0 or above 1000.
- gateway (key_slots.go): every route that asks a model is held to the
  key's cap, however the request came (loopback, LAN, a Remote magpie, a
  Responses socket's turn). One request too many waits in the key's
  queue in arrival order. It shows as "slot" in Active, and its wait goes
  into the try's Queued. A request whose agent goes away while it waits
  leaves the queue and sends nothing. A stream holds its slot until it
  ends. serve's routes (chat, responses, messages, ollama, gemini, the
  Codex backend) wait inside the try, after keepQueued, so a streaming
  agent gets keepalives while it waits. The other model routes (images,
  embeddings, rerank, audio, videos, search, decisions, native) wait
  before their handler runs. forward and codexUpstreamOn take the slot
  too, so nothing reaches a vendor without one. A key issued under
  another waits for its own slot, then for its issuer's.
  /v1/magpie/concurrency lists each capped key under "keys", and counts
  its waiters in "waiting". A key's limit (key_limit) reports the cap.
  Not held, as a provider's MaxConcurrency doesn't hold them: GET,
  HEAD, OPTIONS, count_tokens, :countTokens and MCP.
  TestKeySlotEveryRoute fails when a route is judged neither held nor
  free.
- cli: magpie gateway-key concurrency <id> [<n>|off]. It refuses 0, a
  negative, over 1000, a fraction, a word, --help or an extra argument
  with its usage.
- gui: the key row gets a badge in the provider concurrency badge's
  style. It opens the app's menu with No limit, 1/2/3/5/10 and Other…,
  and Other… takes a number typed in place. A value that isn't a whole
  number up to 1000 is refused and nothing is sent. Browser and
  read-only keys have no badge. Strings are in en, zh, zh-TW, ja and
  de. An unset badge, which a hover shows, gives way before the masked
  key (flex-shrink 8). Without that, at 420px in en and de, the extra
  badge squeezed the key until its copy button slid under the pointer
  that came to drag the row, and gateway-key-arrange went red.
- docs/subsystems/gateway-routing.md describes it.

Run (on mote, at this tree on origin/main 0f8c3d867; rebased onto 627fd1a3b,
which touches none of these files, and the budgets were run again):
- go test -timeout 45m ./internal/access ./internal/gateway ./internal/cli
  ./internal/gui: access, gateway (839s) and cli ok. gui had one red,
  TestGatewayModeStatsNameTheGatewaySessions, run at 00:40 PST: its
  record an hour back falls on yesterday in a day's first hour. It
  passes from 01:09, so it is unrelated; filed as #5690. The Budget/Size
  tests were run again after the CSS change: ok.
- gofmt -l: clean. go vet for darwin, plus GOOS=linux and GOOS=windows
  (-tags nogui), on those packages: ok.
- GUI (node --test, Chromium and WebKit, 1100 and 420 wide, en, zh,
  zh-TW, ja and de): every file that loads the gateway keys (59) plus
  i18n-keys and i18n-en-no-cjk. The reds left are the same on
  origin/main and already filed: gateway-key-models en (#5233, #4081),
  i18n-keys "a plugin's words are its own" (#5332), phone-connect-menu
  at 420 (#4706, #4707). After the flex-shrink fix:
  gateway-connect-keys, gateway-key-arrange, -concurrency, -mcp,
  -own-rotate and -quotas passed 104/104 in both engines, against
  84/84 on base.
- The tests:
  - TestKeyConcurrency, over LAN with cap 2: 2 of 3 requests reach the
    vendor and the third is shown as "slot". Another key isn't held. A
    cancelled waiter leaves the queue and never reaches the vendor. The
    third goes once one ends, every lane is given back, and its Queued
    is at least 40ms.
  - TestKeyConcurrencyKeepsStreamAlive: a waiting stream gets 200 and
    keepalives.
  - TestKeyConcurrencyEager: on embeddings an issued key waits on its
    parent's lane, a cancelled waiter leaves, never more than 1 runs at
    once, and a GET takes no slot.
- A real `serve` in a sandbox HOME (built from this tree, MAGPIE_ADDR
  127.0.0.1:38612) against a fake slow SSE upstream. Steps: `provider
  add fake url=…`, `gateway-key add`, `gateway-key concurrency <id> 1`,
  then three concurrent keyed streams. /v1/magpie/concurrency showed the
  key at busy 1, waiting 2, limit 1 (two in "slot"). The upstream's
  most at once was 1, and it saw 3 requests one after another (200s at
  1.9s, 3.7s and 5.5s, each with [DONE]). Afterwards "keys" was empty.
  `concurrency <id> 2000` exited 1 with its usage.

Broken by hand (each went red, then restored):
- keySlot returns nil: TestKeyConcurrency ("timed out waiting for c
  queued") and KeepsStreamAlive.
- The issuer's lane skipped: TestKeyConcurrencyEager.
- The eager take skipped: TestKeyConcurrencyEager.
- The CLI's bounds check removed: "accepted [concurrency id 0]".
- The GUI's bounds check removed: gateway-key-concurrency.
- Without the flex-shrink line: gateway-key-arrange chromium/webkit en
  and de 420px.

Not tried / not done:
- Full suite not run at push (neither `go test ./...` nor the whole GUI
  suite).
- Not tried with a real vendor account or a second computer on the LAN.
  The LAN path is covered by TestKeyConcurrency's lanServer.
- The key's badge shows the cap, not live running or waiting counts.
  /v1/magpie/concurrency has those.

Reported-by: young02036 (Discord)
2026-11-08 17:52:09 +08:00
yetone 37df73b1bb balance: a key holds several credits that expire, each added and removed on its own
tenacious_eagle_96548 (Discord, 11-08) has two promotional credits on one
key, one ending tomorrow and one the day after. v0.1.3305 kept one grant
per key, and its form showed the date only after Enter or a blur, with no
button to confirm.

- OwnBalance.Expiring is now a list (`expirings`, up to 20). Spending
  goes to the grant that ends soonest first (ties by when it was typed),
  and each grant drops out at its day. A write prunes ended grants.
- The pill and the menu say "Expires in N days" per grant, amber from 7
  days. The menu has a Remove item per grant, "Add credit that
  expires…" and "No credit that expires" to clear them all.
- The form shows the amount and the last day together, the day filled in
  30 days ahead, with an Add button; Enter adds, Escape cancels, a bad
  amount or a past day is refused in place. The app's own menu, no
  native select, no stripes. A pill with two or more grants wraps at a
  grant on a narrow row (a class, not :has(), for Safari before 15.4).
- CLI: `--expiring amount@day` can be given several times, `--expiring
  off` clears all, `--expiring-remove [amount@]day` removes one. --help
  prints usage; a day that isn't a date, or is past, is refused.
- /api/provider/keyexpiring adds `{expiring:{amount,until}}`, removes
  `{expiring:{at,until},remove:true}`, clears `{expiring:null}`.

Old data: a v0.1.3305 single `expiring` grant is read as the first grant
and saved as `expirings` on the next write, for every user. An older
magpie reading the new file sees no grants (the balance itself stays).

Run on mote at 1d5b5dc2d plus this change:
- go test -run 'Budget|Balance|Expir|KeyOwn' ./internal/gui
  ./internal/provider ./internal/cli: ok (TestCoreScriptBudget passes,
  not raised). gofmt -l clean. GOOS=linux go vet -tags nogui and
  GOOS=windows go vet on provider, cli, gui: ok.
- GUI (Chromium + WebKit, 900/400px, en zh zh-TW ja de):
  key-balance-expiring, key-own-balance, key-balance-card,
  key-row-steady, key-row-chips-fit, account-rows-fit, old-webkit,
  i18n-en-no-cjk, balance-parts, balance-quota-left: 203/203. A broader
  run (key-*, balance-*, i18n-keys, panel-balance-order) had reds that
  are red on origin/main 04ed05733 too: i18n-keys "a plugin's words are
  its own" (#5332, #5482, #5426) and key-replace WebKit 420px (#4126).
- Real app on mote, sandbox HOME, `serve --web`: the CLI set ¥40 plus
  ¥5 to tomorrow and ¥8 to the day after and printed about ¥53.00 left;
  providers.json has `expirings`. --help, `5@yesterday` and removing a
  credit the key doesn't have each answered as above. In Chromium (en)
  and WebKit (zh) at 900 and 400px: the pill, the menu, the form (day
  2026-12-07), Add ¥3 by Enter, then Remove ¥3 from the menu, each
  checked by text and screenshot.

After a rebase on 437580535, on mote: the same go test
-run (TestCoreScriptBudget included): ok; key-balance-expiring,
old-webkit, key-own-balance: 46/46. Rebased again on 8f6298fb5 (Go
only, no asset changed): the go test -run plus Signin: ok.

Broken by hand, each went red: sorting grants by when typed
(TestTypedBalanceGrantsSoonestFirst); no migration in UnmarshalJSON
(TestTypedBalanceOneGrantMigrated); no Enter handler (GUI en 900); no
wrap rule (GUI en 400, row past the window's edge); Remove sending the
first grant (GUI, at/until mismatch).

Not tried: Full suite: not run at push. No real vendor account (the
grants are typed by the user). The Linux and Windows desktop apps.

Reported-by: tenacious_eagle_96548 (Discord)
2026-11-08 15:27:14 +08:00
yetone c736906b17 providers: part of a key's typed balance may expire on a day
tenacious_eagle_96548 (Discord, #general): some vendors split a balance
into money that stays and credit good until a date. A key's balance typed
by hand can now carry that part (`expiring`: {amount, until, at}, in the
balance's currency, until = the last day it counts).

- Spending order: the expiring part is spent first, as DeepSeek spends
  its granted balance before money topped up. It takes the spend from its
  `at` up to its end (midnight after `until`, local time) or now; only
  what it took after `From` comes off the rest, so a refill or typing the
  balance again doesn't count it twice.
- Left is the whole balance. From its end the remainder counts no more,
  and unspent credit is gone.
- Typing the balance again keeps the part in the same currency and drops
  it in the other, where its amount would mean another sum.
- A balance saved before has no part and reads exactly as it did
  (TestTypedBalanceSavedBeforeExpiring).
- Set from the pill's menu: "Credit that expires…" asks the amount, then
  the last day (a day gone by, or the other currency's sign, refused);
  "No credit that expires" takes it off. GUI route provider/keyexpiring;
  CLI `magpie provider key-balance <id> <key> --expiring amount@yyyy-mm-dd|off`.
- Shown: the pill "≈$100.00 left · $30.00 expires in 30 days", the Usage
  page and panel line "Expires in 30 days ≈$30.00", amber from 7 days;
  TUI and `magpie quota` "($30.00 until Dec 7)". New strings in zh,
  zh-TW, ja and de.

Run (mote):
- go test of internal/provider, internal/gui, internal/cli (with
  TestCoreScriptBudget: the days' lines in app.js are paid for by five
  balance comments cut there, no raise; core 1,533,559 of 1,533,802); the new tests
  again with TZ=UTC and TZ=Pacific/Kiritimati (every clock held);
  gofmt -l clean; GOOS=linux and GOOS=windows go vet of those packages.
- GUI: key-balance-expiring.test.cjs 20/20 (chromium and webkit, 400px,
  en/zh/zh-TW/ja/de), with every balance-*, key-*, i18n-* file: 768
  pass, 6 red, each red the same alone on origin/main 691a10446:
  i18n-keys "a plugin's words are its own" (#5327) and key-replace's
  five webkit 420px cases (#4126, numbers added there).
- A real sandbox (own HOME, -tags nogui binary, ports 3591/3592): set
  $70 + $30 until +30d and ¥40 + ¥5 for +3d through the CLI, then
  through the pill's menu in the real page (¥8 for +6d, then removed);
  a past date shows the part no longer counting; retyping in USD dropped
  the CNY part; `magpie quota` shows the split. No page errors.

Broken by hand, each red:
- Go (TestTypedBalanceExpires): part not spent first; end taken in UTC
  (red under Kiritimati); part kept after its end; part kept across a
  currency change.
- GUI (key-balance-expiring): no soon class; soon only from 2 days; a
  past day accepted; the other currency's sign accepted.

Not tried: a real vendor's spend priced against the part; the GUI on
Windows or Linux. The full Go and GUI suites were queued on mote's
suite lock behind other sessions' and had not run when this was pushed.

Reported-by: tenacious_eagle_96548
2026-11-08 13:39:32 +08:00
yetone 7880a00ac6 models: a model of a key's provider can be asked on System One
axelburks on Discord: a relay serves its decision model under a name of
its own (an Ark endpoint id). A key's provider with a System One URL
beside a conversation URL can set a model's API to decide (System One
in Model settings' API row, its chip's right-click, or `magpie model
api <pid/model> decide`). The model is then a decision model there:
asked on System One by its own name, offered to routing groups, kept
out of the conversation models, and a turn for it is refused with 400
before the vendor is asked. Auto gives it back. A provider with no
System One URL, with that URL alone, an account, a remote magpie and
Vertex refuse it, saying why. Chat routing (apisAmong) ignores decide.

Broken by hand: removing the decideSet check in DecidesModel turns
TestModelSetToSystemOneIsADecisionModel and
TestModelSetToSystemOneAskedThere red.

Run, on this stack over origin/main 0fc3455e2 (mote's suite lock had
hours of queue, so the suites ran on WSL magpie-desktop under flock):
- go test -timeout 45m ./internal/{provider,gateway,gui,cli,settings,fx}
  on WSL, ok; ./internal/codexcat on mote, ok; gofmt -l clean;
  go vet on mac, GOOS=linux -tags nogui and GOOS=windows on mote, ok;
  TestCoreScriptBudget ok (paid by cutting comments, no raise).
- GUI, both engines, every language, on WSL at the pushed head and at
  0fc3455e2: every touched test file plus the provider-editor files a
  first run found red. No red at head that isn't red at 0fc3455e2. The
  shared reds have issues: i18n-keys #5332, model-chip-steady #4388,
  model-copy-id #4621, models-works-only #4391, plugin-move-unserved
  #4392, provider-fetch-again #5232, provider-levels-save #4394,
  provider-levels-scroll #4395, provider-models-rest #4396,
  provider-picks-stay #4397, provider-typed #4673, remote-magpie #4398,
  zero-priced-free #5262, model-reasonless (webkit de) #4100,
  name-suffix-no-names #1937.
- Rebased on origin/main 4ab1191bc (gateway.go moved under it) and run
  again at the pushed head: gateway and provider ok on WSL, gofmt,
  vet (mac, linux nogui, windows) and the budget ok, i18n-keys,
  model-headers and routing-groups-back with only #5332's red.
Not run at push: the whole GUI suite (1277 files).

Not tried: a real relay's System One endpoint; fake vendors only.

Reported-by: axelburks (Discord)
2026-11-08 11:28:54 +08:00
yetone 7a6211d047 providers: a model's own headers, in Model settings
axelburks on Discord: a vendor routes one model by a header of its own.
A key's provider (built-in or custom) can give each model headers
(settings.ModelHeaders["pid/model"]). They go on that provider's
requests for that model alone, after the provider's headers and after
auth: a name both have is sent once, as the model's, so a user's value
is never overridden by the provider's or magpie's key header. The
gateway names the model (provider.WithModel) on every route that asks
one: chat on each API, translated and streamed, count_tokens, System
One's decision, embeddings, images, videos and the model test. A
fallback provider serving the same model id gets its own headers only.
Accounts and plugins carry their sign-in's headers and take none.

The editor's "Name, price and reasoning level" panel is now "Model
settings" (every language), with + Add header per model, staged and
made with the Save; Restore default takes them away.
The rows being typed are kept out of the draft's
compare, so an untouched editor still closes without asking.

Broken by hand: dropping WithModel from gateway.go turns
TestModelHeadersReachTheirModelOnEveryRoute red; dropping the provider
id check in modelOf turns TestModelHeadersStayWithTheirProvider red.

Run, on this stack over origin/main 0fc3455e2 (mote's suite lock had
hours of queue, so the suites ran on WSL magpie-desktop under flock):
- go test -timeout 45m ./internal/{provider,gateway,gui,cli,settings,fx}
  on WSL, ok; ./internal/codexcat on mote, ok; gofmt -l clean;
  go vet on mac, GOOS=linux -tags nogui and GOOS=windows on mote, ok;
  TestCoreScriptBudget ok (paid by cutting comments, no raise).
- GUI, both engines, every language, on WSL at the pushed head and at
  0fc3455e2: every touched test file plus the provider-editor files a
  first run found red. No red at head that isn't red at 0fc3455e2. The
  shared reds have issues: i18n-keys #5332, model-chip-steady #4388,
  model-copy-id #4621, models-works-only #4391, plugin-move-unserved
  #4392, provider-fetch-again #5232, provider-levels-save #4394,
  provider-levels-scroll #4395, provider-models-rest #4396,
  provider-picks-stay #4397, provider-typed #4673, remote-magpie #4398,
  zero-priced-free #5262, model-reasonless (webkit de) #4100,
  name-suffix-no-names #1937.
- Rebased on origin/main 4ab1191bc (gateway.go moved under it) and run
  again at the pushed head: gateway and provider ok on WSL, gofmt,
  vet (mac, linux nogui, windows) and the budget ok, i18n-keys,
  model-headers and routing-groups-back with only #5332's red.
Not run at push: the whole GUI suite (1277 files).

Not tried: a real vendor that routes by header (Ark); fake vendors only.

Reported-by: axelburks (Discord)
2026-11-08 11:28:54 +08:00
yetone ae58ec9b44 providers: a key's provider can have its model list off
axelburks on Discord: Ark's pay-as-you-go list names models that can't
be asked for, and each one is asked by an endpoint id the user made. A
key's provider can now have its list off (Provider.ListOff): nothing
asks its vendor for a list (Fetch, Refetch, List, RefreshLists, a test,
a new key's prefill, a resting key's probe), a list fetched before and
models.dev's are not read, and only the ids added by hand are served.
The editor shows it as "Fetch the model list", ticked by default;
unticked, Fetch models and Forget go. A save that doesn't name listOff
keeps it. CLI: `magpie provider set <id> list=off`. Accounts and plugins
list as their sign-in does, so they don't take it.

Broken by hand: ListAsks returning false for a list-off provider turns
TestListOffAsksNoListAndServesTheIDsAdded red; dropping the keep in the
save turns TestProviderSaveListOff red.

Run, on this stack over origin/main 0fc3455e2 (mote's suite lock had
hours of queue, so the suites ran on WSL magpie-desktop under flock):
- go test -timeout 45m ./internal/{provider,gateway,gui,cli,settings,fx}
  on WSL, ok; ./internal/codexcat on mote, ok; gofmt -l clean;
  go vet on mac, GOOS=linux -tags nogui and GOOS=windows on mote, ok;
  TestCoreScriptBudget ok (paid by cutting comments, no raise).
- GUI, both engines, every language, on WSL at the pushed head and at
  0fc3455e2: every touched test file plus the provider-editor files a
  first run found red. No red at head that isn't red at 0fc3455e2. The
  shared reds have issues: i18n-keys #5332, model-chip-steady #4388,
  model-copy-id #4621, models-works-only #4391, plugin-move-unserved
  #4392, provider-fetch-again #5232, provider-levels-save #4394,
  provider-levels-scroll #4395, provider-models-rest #4396,
  provider-picks-stay #4397, provider-typed #4673, remote-magpie #4398,
  zero-priced-free #5262, model-reasonless (webkit de) #4100,
  name-suffix-no-names #1937.
- Rebased on origin/main 4ab1191bc (gateway.go moved under it) and run
  again at the pushed head: gateway and provider ok on WSL, gofmt,
  vet (mac, linux nogui, windows) and the budget ok, i18n-keys,
  model-headers and routing-groups-back with only #5332's red.
Not run at push: the whole GUI suite (1277 files).

Not tried: a real Ark account; the switch was checked against fake
vendors only.

Reported-by: axelburks (Discord)
2026-11-08 11:28:54 +08:00
yetone cdf734757a agent: OpenMausBot gets magpie's models back, and a Restart for a list it hasn't read
maxleebeta (Discord #feedback, 11-08) picked Antigravity's models in
magpie, and OpenMausBot's model search didn't find them. magpie wrote them
correctly: a sandbox with an Antigravity sign-in lists
antigravity/gemini-3.8-flash[1m] and the others in config.json. OpenMausBot
loses them in three ways, each reproduced on the real app:

- it reads config.json once, at start, so a list magpie writes while it
  runs never reaches its picker;
- a change to any engine in its Settings writes back every engine as it
  held them since it started, so magpie's newer list is replaced by the
  old one;
- an edit of magpie's engine there (updateClaudeEndpoint) keeps only the
  model picked.

Nothing in magpie wrote the list again: a sync runs on a catalog change,
or when magpie starts.

- KeepOpenMausBotListed (gateway.WhileServing, every 30s) writes magpie's
  list again when the file lists other models (ombListStale). The model
  picked in OpenMausBot (ANTHROPIC_MODEL) and its other engines stay. It
  isn't a Check drift: that reads as unwired, and a port change rewires
  only agents without one.
- OpenMausBot gets a Restart on its Agents row (restartApps: OpenMausBot.app,
  OpenMausBot.exe; appReads: ombPart = gateway, first model, list, not the
  key), so one running on an older list is offered a reopen. Its own save
  of the same engine after it starts doesn't count.

The same gap in NewMax, LiveAgent, OpenPencil, OpenBot, Pencil and ZCode
is #5662.

Run (mote, at this tree rebased on origin/main 00198b26e; 06324e99e,
rebased onto since, changes comments and docs only):
- go test ./internal/agent ./internal/cli ./internal/claudecode . : ok
- go vet ./internal/agent ./internal/cli on darwin, GOOS=linux -tags
  nogui and GOOS=windows: ok; gofmt -l: clean
- TestOpenMausBotListWrittenAgain and TestOpenMausBotRestartOnMac, new
- Broken by hand: ombListStale always false turns
  TestOpenMausBotListWrittenAgain red (written back, edited there, the
  loop); dropping restartApps' entry turns TestOpenMausBotRestartOnMac
  and TestRestartAppsOnWindows red.
- Real OpenMausBot 0.1.145 on mote (the app's server under
  ELECTRON_RUN_AS_NODE, sandbox HOME and OMB_DATA_DIR, own port):
  /api/instances kept the start list after a model was added to the
  file; an icon PATCH on its other engine wrote the old list back over
  it; PATCH /api/instances/magpie/claude-endpoint left ["relay/gpt-5.5"].

Not tried: the full go test ./... (mote's suite.lock had six full runs
queued); the Restart on a real Windows OpenMausBot (OpenMausBot.exe is
electron-builder's default name, not seen on the box); magpie's own
keep loop against the real app (the tests cover the file it writes).

Reported-by: maxleebeta (Discord)
2026-11-08 10:55:49 +08:00
yetone 0fc3455e2a providers: a key's typed balance may be in yuan and refill each month or week
tenacious_eagle_96548 asked, after v0.1.3281's typed balance, to type it
in RMB and to have it refill (e.g. $10 a month, on the 1st).

- A balance may be typed in yuan ("¥100", "100元", or a bare number while
  Settings shows costs in CNY). What magpie counts spent stays in USD and
  is turned into yuan at fx.Known(): the rate internal/fx last fetched
  (cached 12h, fetched again in the background, never on a request).
  fx.Known never returns fx.Fallback, so with no rate fetched and
  something spent, what is left is unknown (left null; the card says
  why), not a guess.
- An optional refill: monthly on day 1-31 (past a month's end, its last
  day) or weekly on a weekday, at midnight in the user's local time.
  Nothing is stored on a refill: the spend counts from the last boundary
  after the balance was typed. Typing the amount again keeps the refill.
- GUI: the pill's menu gains Refills each month… (a day, in place),
  Refills each week… (the app's menu of weekdays) and Never refills;
  provider/keybalancerefill; keyownbalance takes currency cny. CLI:
  magpie provider key-balance <id> <key> [usd|¥cny|off]
  [--refill monthly[:day]|weekly[:mon…sun]|off]. Strings in zh, zh-TW,
  ja, de. docs/subsystems/providers-accounts.md updated.

Run on mote at this tree (base origin/main 350599a0f):
- go test -tags nogui -count=1 -timeout 45m ./internal/fx ./internal/provider
  ./internal/cli ./internal/gui ./internal/usage: all ok (suite lock).
- GOOS=linux go vet -tags nogui ./... ok; GOOS=windows go vet ./... ok;
  gofmt -l clean.
- key-own-balance.test.cjs 20/20 (chromium + webkit, en zh zh-TW ja de,
  900 and 400px): yuan typed posts currency cny, monthly day (40
  refused), weekly Friday, never. i18n-keys, i18n-en-no-cjk, old-webkit ok.
- Broken by hand, each red: Known returning Fallback
  (TestKnownIsNeverAGuess); refill days taken in UTC
  (TestTypedBalanceRefills, TestRefillDays); refill dropped on retype
  (TestTypedBalanceRefills).
- Full GUI suite still running at push: 3502 ok, 6 red so far, none in a
  file this touches: webkit By weight; webkit de 1100/420 Codex resets
  used by themselves; chromium en named caller keys; chromium zh-TW 420
  a key's several limits; webkit en gateway key held to its models.
  They are run on origin/main next and filed if red there.

Not tried: a live rate fetch (tests stay offline), the real app window,
WebKitGTK.

Reported-by: tenacious_eagle_96548 (Discord)
2026-11-08 09:03:00 +08:00
yetone d32a7a70cb remote magpie: once magpie updates, the Remote magpies it uses update too
nnlrl_75403 on Discord: a magpie used as another's Remote magpie stayed on
its old version after the local one updated, and had to be updated by
hand on the other computer. Now nothing needs setting up:

- provider.KeepRemotesUpdated (started by the app's updater and by
  magpie serve) runs UpdateRemotes 30 s after start and hourly. A
  released build with automatic updates on reads each Remote magpie's
  version (GET /v1) and, when it is older, asks it through
  POST /v1/magpie/update?version=<v> with the provider's key, at most
  once in six hours per version. Off here, or a dev build: nothing asked.
- The remote updates as its own automatic update would: the app
  downloads and restarts once idle (updater.updateAsked → download,
  waitIdle); magpie serve puts the latest in where it runs from, one at
  a time, never elevated, and serveFollow restarts into it. Automatic
  updates or downloads off there: it answers "off" and stays.
- A copy that can't replace itself says why: a container (docker pull
  ghcr.io/yetone/magpie:latest), a package manager's (its command), a
  folder it can't write, a build from source. A magpie from before the
  route answers 404 ("too old"), a read-only or held key is "refused".
  The provider's row on the Providers page adds a short status to its
  line ("updating to v…" for 30 min, or "can't update itself" etc.),
  with the reason and the command in its tooltip. en/zh/zh-TW/ja/de.
- The route replaces the program, so it takes the Codex reset's
  admission: another machine only while shared, never a browser page,
  an enabled key with full access from loopback too (401 without one),
  read-only 403 gateway_key_read_only, held 403 gateway_key_held. It is
  in readOnlyRefused and the CORS route list.

App.js stays under TestCoreScriptBudget by cutting two comments; the
budget is not raised.

Run (on mote, at the tree committed here):
- gofmt -l internal/: clean. go vet of gateway, gui, cli, provider for
  darwin, GOOS=linux and GOOS=windows: ok.
- go test -count=1 ./internal/gui ./internal/cli ./internal/provider
  ./internal/gateway: gui and cli ok but for #5644's two settings tests
  (red on main since 6b7ee4a98, owned); provider and gateway were
  still running at the push, and go in the full run after it.
- Rebased on origin/main c7c05dcf2, again: gofmt, vet, the new tests,
  ReadOnlyKeyEveryRoute, CORS, TestCoreScriptBudget (not raised) and
  both GUI files 32 of 32: ok.
- New: TestRemoteUpdateNeedsAFullKey (no key from loopback, Origin null,
  an app scheme, *.localhost, a rebound Host, a foreign page with and
  without the full key, another machine with none or a wrong key,
  read-only and held keys, then not shared; the updater is never
  called until a full key asks, from LAN and loopback),
  TestRemoteMagpieAskedToFollow (UpdateRemotes against a real gateway:
  dev build, same and newer remote, NoAutoUpdate here, asked once per
  version, container answer kept, read-only key refused, a 404 magpie
  "old"), TestUpdateAskedByAnotherMagpie, TestRemoteUpdateNote,
  TestServeUpdateAsked.
- GUI: remote-update.test.cjs (new) and remote-self.test.cjs, Chromium
  and WebKit, 1100 and 420 wide, en/zh/ja/de: 32 of 32 ok, with every
  key checked in zh, zh-TW, ja and de. i18n-en-no-cjk ok. i18n-keys'
  "a plugin's words are its own" is red, the same on origin/main
  f8525323d (#5327/#5332, #5426, #5482); its other cases ok.

Broken by hand, each red, then put back: the handler's key check
(loopback without a key got 200 updating), its held-key check, the
route itself (404 = the old code), asking a remote that is current,
ignoring NoAutoUpdate here, asking again for the same version, the
app ignoring automatic updates off, the app never waiting to restart,
serve's single flight (2 downloads), serve's container answer.
The handler's own Origin and not-shared checks stay green when removed:
corsGuard and lanGuard refuse those first; they are kept as the Codex
reset keeps them.

Not tried: a real update of a real remote (a Docker magpie and an app
on another Mac) end to end; Windows and Linux runs of the new tests
(vet only); the full suite (run after the push).

Reported-by: nnlrl_75403
2026-11-08 03:13:15 +08:00
yetone c7c05dcf2b settings: the routing groups' defaults are kept through a Settings save and known to be saved by the Routing page's own route
6b7ee4a98 added groupSink, groupFirstToken and groupPatience to settings
and to settingsapi.Keys. Two guards went red on main (#5644):

- TestSettingsSaveKeepsWhatItDoesNotSend wants every setting the Settings
  page doesn't send set in the test and kept by POST /api/settings. Merge
  already keeps the three (6b7ee4a98 added that); the test never set
  them, so it couldn't check it. It sets them now (true, 30, 120), as it
  does BusyLoad.
- TestSettingsCLISetsWhatTheWindowSaves wants every key `magpie settings`
  sets to be one a page sends POST /api/settings. The Routing groups
  page saves these three through POST /api/groups/defaults
  (settings.SetGroupDefaults), and the page itself names `magpie
  settings set` as the other way to set them. The CLI path is real, so
  the keys stay in settingsapi.Keys. The test now has ownRoute: a key a
  page saves through a route of its own, with the call and the body key
  it sends it as, and it fails when no page's call sends that key any
  more, or when ownRoute names a key the CLI can't set.

Siblings: 6b7ee4a98 added no other settings key. provider.Group's new
NoSink and FirstTokenWait have no CLI side to miss: `magpie group set`
has no sink, first-token or patience option before or after it.

Run on mote at origin/main f8525323d:
- Before the change, the two tests: red with the 3+3 lines of #5644.
  After: ok.
- Broken by hand: Merge not keeping groupPatience made
  TestSettingsSaveKeepsWhatItDoesNotSend red ("GroupPatience: 0 ... was
  120"); client.js's groups/defaults call without patience made
  TestSettingsCLISetsWhatTheWindowSaves red. Restored.
- Real CLI, a built magpie in a sandbox HOME: `settings set` groupPatience
  120, groupSink true, groupFirstToken 45 were saved to settings.json and
  listed; groupPatience 999 was refused with nothing changed.
- go test -tags nogui ./internal/cli ./internal/gui: ok.
- gofmt -l: clean. GOOS=linux go vet -tags nogui ./... and GOOS=windows
  go vet ./...: clean.

Not run: the full suite and the GUI (Playwright) suite; no page script
changed.

Fixes #5644
2026-11-08 03:02:54 +08:00
yetone f8525323dd providers: a key with no balance URL takes a balance typed by hand, counted down by magpie's own usage
Some API-key providers tell no balance magpie can read (no Balance URL,
no relay query found), so their keys showed none. Now the user types what
the vendor's page says is left, on the key's row in the provider editor
(Set balance) or with `magpie provider key-balance <id> [key [usd|off]]`.
The key's card shows that less what magpie's usage priced the calls it
sent on the key since it was typed (usage.KeySpent, the spend caps'
count), marked as an estimate: "≈$12.50", the pill "≈$12.50 left", its
title saying what was typed, when, and what was counted since. Typing it
again counts from then; No balance takes it off.

A balance the vendor tells always wins: a provider with a Balance URL, a
plan source, Cline's or OpenCode Zen's card takes none typed, and a relay
whose query is found shows its own; when the probe finds none
(errNoBalance) the typed one is shown. A typed balance stays saved as the
user left it: the editor's save keeps it, a key's replaced value carries
it. An estimate is never kept in the balance history and tells routing
nothing (the routing allowances cache is left alone).

keybalance.js is loaded by keyspend.js (itself loaded when the editor
draws a key) for a provider that takes one, so app.js and the core's
script budget are unchanged. Words in zh, zh-TW, ja and de.

Run at this tree (mote):
- go vet ./... (darwin), GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... at base 46b10af87; at this tree go vet of
  gui, provider, cli and usage;
- go test -tags nogui -count=1 ./internal/gui ./internal/provider
  ./internal/cli ./internal/usage: provider and usage ok; gui and cli
  red only on #5644 below; TestCoreScriptBudget ok (1,533,747, as main)
- the provider tests under -race -count=3;
- GUI: key-own-balance (new: Chromium and WebKit, en zh zh-TW ja de,
  900 and 400px, 20/20), key-spend-cap, old-webkit, i18n-keys, gui-de,
  gui-ja, gui-zh-tw, balance-found, key-balance-card, i18n-en-no-cjk:
  104 pass, 1 fail, i18n-keys "a plugin's words are its own", red the
  same on origin/main 7a2946caf (#5327, #5332, #5482, #5426).

Broken by hand, each went red:
- estimates kept in the balance history: TestTypedBalanceCountsDown;
- no fallback to the typed balance on errNoBalance:
  TestToldBalanceWinsOverTyped;
- the editor's save dropping KeyOwnBalances: TestKeyOwnBalanceRoutes.

Red on main, not this change: TestSettingsSaveKeepsWhatItDoesNotSend
and TestSettingsCLISetsWhatTheWindowSaves (groupSink, groupFirstToken,
groupPatience from 6b7ee4a98), filed as #5644.

Not tried: a real relay account with no balance URL (the cost counted is
magpie's own estimate, so a vendor pricing differently drifts until the
balance is typed again); the full Go and GUI suites before the push (run
after it, under the suite lock); the GUI in the real Windows and Linux
apps; routing does not use the estimate.

Reported-by: tenacious_eagle (Discord)
2026-11-08 02:54:25 +08:00
yetone 710f0290cc masking: a masked value in a request opens Copy and Never mask
yew_fence on Discord: in Insights › Masking's diff of a request, a false
positive can't be copied or put on the allow-list from there. Now a
masked value in the request's text, as written here or as the vendor got
it, opens the app's row menu (right-click on a value card under it):

- Copy copies what the value was, through /api/copy (it is the user's
  own value, shown on this computer only).
- Never mask posts the placeholder to the new POST /api/masking/allow.
  The server asks the masker for the value it stood for (so only a value
  masking masked can be added), reads settings with LoadChecked (an
  unreadable file is not written over), appends it to RedactAllow, the
  list Settings › Privacy's Never mask saves, and Save trims it and keeps
  one copy. allows() runs after the span memos, so the next request
  sends it as written. Off, with why, for a value already on the list and
  for one of the user's own Masked words. A value from before a restart
  is not in memory and opens nothing.

Strings in plugins/redact/i18n.js for zh, zh-TW, ja and de. settings
parity maps the route as S2.

Run on mote at this tree rebased on 578053d6a (pushed on cde3bc9fa; dca338f3a
and cde3bc9fa change internal/gateway and one mover min only):
- go test ./internal/gui ./internal/cli ./internal/settings ./internal/redact: ok,
  but for internal/gui's TestPanelHiddenByWailsMarksPageOutOfSight (#5322,
  "marked=false" as filed) while another session's suite ran on mote; alone
  it passes 3 of 3 here and 2 of 2 at 578053d6a
  (TestMaskingAllowFromRecord new: 404 for an unknown placeholder, GET
  refused, added once, the next TextHits sends it unmasked)
- go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet on internal/gui
  and internal/cli: ok (all of ./... before the rebase); gofmt -l clean
- node --test mask-value-menu (new; Chromium and WebKit, en/zh/zh-TW/ja/de,
  1100 and 640px, plus the before-a-restart case), mask-actions,
  masking-records, masking-demo, masking-demo-unblurred, mask-alert,
  redact-words-import, i18n-en-no-cjk, i18n-keys: 235 of 236, the one red
  below
- i18n-keys: its "a plugin's words are its own" is red for three keys
  that aren't this change's, filed as #5332/#5327, #5482 and #5426; no
  key of this change is listed.

Broken by hand: the route without its append, TestMaskingAllowFromRecord
red ("allow [build-01], saved [build-01]"); maskInk without maskActsOn,
mask-value-menu red.

Not tried: the real app with a live masked request; the whole GUI suite
(1266 files; the new call is made only on a click in this page, and every
file that opens the masking page was run).

Reported-by: yew_fence
2026-11-07 23:27:42 +08:00
yetone c8eb7b3877 search: a search API's keys are a list, each switched off, moved and removed on its own
Web search took one key per API in one field (辰林鸭~ on Discord: only one
Tavily key). Settings › Models › Web search now lists an API's keys under
it as a provider's accounts are: each masked on its own row with a tick
(off / on), Show, Copy and Remove; several pasted at once (commas,
semicolons, lines), the reply saying how many were new and how many it
had; the order changed by dragging or Alt+↑/↓. A resting key says why and
until when on its row ("asked last until 14:05: rate limited"), from the
gateway's rest (SearchKeyRest, SearchQuota.Ref); rotation on 401/403,
402/432/433 and 429 (#1477) is unchanged.

provider.SearchAPI keeps Key as the keys on, comma-joined, so the gateway
and an older magpie never ask one switched off; keyList is written only
while a key is off. A Key that differs from the list (an older magpie, a
sync) wins, its keys on in its order, the list's off keys after. The last
key on can't be switched off or removed. The GUI names a key by
SearchKeyRef (a hash): POST /api/settings/search-keys (add, ref+on,
ref+remove, arrange) and /api/settings/search-key with ref. Saving an API
with no key keeps its keys, off ones too. Backup and WebDAV sync carry
the off keys, or leave them out with the rest. `magpie search` says
"+N off". docs/subsystems/gateway-routing.md has "The keys as a list".

Run (mote, at this tree, base 3441035a2):
- go test -count=1 ./internal/gui ./internal/provider ./internal/backup
  ./internal/davsync ./internal/cli: ok but gui's
  TestPanelHiddenByWailsMarksPageOutOfSight (#5322, mote, untouched) and
  cli's TestEveryRouteHasACommandOrIsNamed, then fixed (search-keys named
  S2) and run again: ok. ./internal/gateway search tests ok earlier.
- node --test search-key-list, search-keys, search-api, search-signs-in,
  search-order: 84/84, Chromium and WebKit, en/zh/zh-TW/ja/de, 1100 and
  420px (search-api/order at their own widths). i18n-keys: only "a
  plugin's words are its own" red, as on main (#5332, #5426, #5482).
- go build ./..., go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok. gofmt -l: clean.

Broken by hand, each red then restored:
- SetSearchAPI drops KeyList: provider and gui tests red.
- backup clears Key only / davsync merges Key only: their tests red.
- off keys still put in Key: provider, gui, backup and gateway red.
- the whole key in /api/state: TestSearchKeyListFromSettings red.
- no last-key-on check: TestSearchKeyList red.
- settings.js at HEAD: search-key-list.test.cjs red.

Not tried: a real Tavily account with several keys (the vendor is faked;
no test reaches the network); the real app window (the GUI ran in
Playwright only); Windows and Linux runs of the tests (vet only). The
full Go and GUI suites run after the push, under mote's suite lock.

Reported-by: 辰林鸭~ (Discord)
2026-11-07 21:21:48 +08:00
yetone abe7b00631 gateway: a key+URL provider is sent the agent's own User-Agent by default, through a remote magpie too
nb5p runs a gateway of their own behind magpie and saw nearly every
request arrive as "magpie/<version>". The agent's User-Agent now goes
on as the agent sent it, wherever magpie isn't itself the client.

What each path sends now:
- Key+URL providers (official vendor keys and custom OpenAI/Anthropic
  compatible ones), on chat, Anthropic, Responses, Gemini,
  count_tokens, embeddings, images and videos: the agent's User-Agent,
  as sent. Before, this was the opt-in passUserAgent (#1851) and the
  default was magpie's. The opt-out is magpieUserAgent:
  `magpie provider set <id> user-agent=magpie`, or untick "Send the
  agent's own User-Agent" in the editor. passUserAgent is no longer a
  field, so a file that set it true reads the same as the new default.
  A provider someone turned back off after opting in can't be told
  apart from one never touched, and now sends the agent's too.
- When the agent sent no User-Agent, and on magpie's own requests
  (classifier magpie-router/1, vision, search, the image tool, model
  lists): magpie's, unchanged.
- A header.User-Agent the user set: still wins over both.
- Subscription accounts (Claude, Codex, Copilot, Google, ZCode…),
  plugins, and OpenCode/Cline/Kilo: unchanged. Their signing sets the
  official client's UA (provider.PassesUserAgent still refuses an
  Account or OwnClient).
- Claude Code and Codex header copies: unchanged.
- Remote magpie: the near magpie still asks as magpie/<v>, because the
  far end trusts X-Magpie-Agent/Via only from that. It now adds
  X-Magpie-User-Agent (passOnUA, on forwardOnce, embeddings, draw and
  video; the classifier's decision request names none). The far end
  takes it only from a magpie/ request (callerFrom) and strips it on
  arrival (withCaller). agentUA/callerUA then hand it to userAgentFor,
  so the far vendor sees the agent's. A client that writes the header
  itself, straight to a magpie, is ignored. magpie's own UAs are never
  relayed (magpiesOwn).

Vendor check: invalid-key requests with magpie/, claude-cli, a Chrome
UA and pi's went to Anthropic, OpenAI, Gemini, DeepSeek, Moonshot, Kimi
For Coding, Zhipu, OpenRouter, xAI, DashScope, MiniMax, Volcengine Ark,
Groq and Mistral. Every vendor gave the same auth error for every UA,
so no edge-level UA gating was seen. Kimi For Coding's agent allow-list
sits behind a valid key, which wasn't tried.

Run (mote):
- go test -run 'UserAgent|RemoteMagpie|ZCode|Blocked' ./internal/gateway: ok
- go test ./internal/provider ./internal/cli ./internal/gui: ok
- node --test provider-user-agent, provider-native-compaction and
  i18n-keys (chromium and webkit; en/zh/zh-TW/ja/de; 900 and 440 wide):
  123 of 124 pass. The red is i18n-keys "a plugin's words are its own"
  (plugins' words said in files this change doesn't touch), already
  filed as #5327/#5332, #5426 and #5482.
- gofmt -l clean; go vet; GOOS=linux -tags nogui and GOOS=windows vet:
  ok at the rebased head (on f13d5f16f). Targeted gateway, provider,
  cli and gui packages (UserAgent|RemoteMagpie|ZCode|Blocked|Budget)
  ok there too; whole packages ran at the pre-rebase base 4461957b9.

Broken by hand:
- PassesUserAgent back to opt-in: TestUserAgentPassedOn/default,
  TestUserAgentFor, TestRemoteMagpieRelaysUserAgent, TestPassesUserAgent
  and TestProviderUserAgentPair go red.
- agentUA's relay off, or passOnUA a no-op: TestRemoteMagpieRelaysUserAgent
  goes red; the far vendor is asked as magpie/dev.
- withCaller's Del(X-Magpie-User-Agent) removed: stays green. Nothing
  copies incoming headers to a vendor today, so the Del only guards
  against that.

Not tried: a real remote magpie on two machines, a real valid-key vendor
request, and nb5p's own gateway.

Reported-by: nb5p on Discord
2026-11-07 17:44:31 +08:00
yetone da548b4548 codex: a reset about to expire can be used from 3 minutes before, or after any minutes typed (Custom…)
shangyuan0818 asked again, and the coordinator agreed: magpie runs the
whole time, a reset's expiry is known to the second, and a user who is
worried can pick a long lead. So the menu ends with Custom…, and the
floor is now what the gateway needs, not 15 or 5 minutes.

- settings: CodexResetLeadLeast 5 -> 3; the presets start at 3. The CLI
  (magpie quota reset-lead) and settings/codex-reset-lead check the same
  constant. Saved values stay valid: everything from 5 to 1440 still is.
- Why 3: since v0.1.3204 the loop wakes at the lead's start (timer, at
  most 1s late), a try is bounded by the pass's 2 minutes, and a failure
  in the last 15 minutes is tried again a minute after it began, at once
  when that has passed. At 3 minutes a try hung to its bound ends at
  T-0:57 and a retry starts at T-0:56. At 2 minutes a hung try leaves no
  retry before expiry.
- GUI (autoresetown.js): Custom…, the menu's last item, puts a field of
  minutes where the button was, at the button's size, so the row doesn't
  rewrap. Enter or leaving it saves. Escape keeps the lead. A number
  outside 3 to 1440 is shown as an error and not written. A redraw
  leaves the field alone while it is open. It uses the app menu and no
  native select. There is one new string, in all five languages.

Tests:
- TestShortLeadSpentInTime: at the least lead, for four phases, the
  reset is spent at T-3:00, and after a 2-minute hung try plus a 30s
  retry it is spent before expiry.
- TestQuotaResetLeadCmd: 3m is taken and 2m is refused.
- codex-reset-lead.test.cjs: 12 items, picking 3 min, and Custom… in
  every language at 1100 and 420. Typing 7 and pressing Enter posts 7.
  Typing 2 is said and not posted. Escape posts nothing, and leaving the
  field posts 12. Opening the field moves no page.

Run on mote at this tree:
- go test of the reset-lead, short-lead, reset-loop, expiring and
  quota-reset tests in provider, cli and settings: ok.
- go vet: darwin, linux -tags nogui and windows on provider, settings
  and cli, plus darwin on gui: ok.
- go test ./internal/gui: TestCoreScriptBudget ok with no raise (the
  field lives in the lazy autoresetown.js). TestMainWindowCorners is red,
  as in #3949.
- GUI codex-reset-lead, codex-auto-reset-settings and i18n-keys in
  Chromium and WebKit: 49/50. The red is i18n-keys "a plugin's words are
  its own", filed as #5327, #5332, #5426 and #5482. Before the last
  comment trims, codex-reset-lead, codex-auto-reset-settings and
  providers-reset-use passed 86/86.

Broken by hand, each red:
- Floor at 2: the least-lead hung case goes red (one try, no retry), and
  so does the CLI (2m taken).
- Floor at 5: the CLI refuses 3m.
- The GUI range check removed: "2 isn't posted".
- Escape saving: "Escape posts nothing".
- The field at its own size (76x27) instead of the button's: WebKit ja
  and de at 1100 move the page 1px.

Not tried: a real ChatGPT reset spent at 3 minutes, since none of my
accounts has a reset about to expire. The redraw guard has no test of
its own, because a click elsewhere blurs the field and saves first.

Reported-by: shangyuan0818 (Discord)
2026-11-07 06:39:39 +08:00
yetone e484b4ff26 update: a slow download still moving is never ended by a total time; Bun, Claude Code and pf-serve too
#5572: since 80a47abba a silent download is broken off after 30s and
tried again, but the update's download still had a 10-minute total
(the update client's Timeout, the GUI run's ctx, `magpie update`'s ctx).
A download under ~140 KB/s, still receiving bytes, failed the 83 MB
Windows exe at 10 minutes part way. The stall timer is what ends a dead
one now; nothing ends one that is still moving.

- internal/update: fetch downloads through fileClient, the client without
  its Timeout. The feed and notes keep the 10-minute client. fetch's stall
  timer runs from the ask to the last byte, so a server that never answers
  still ends at stallAfter (30s), and download's retries stay bounded
  (len(retryWaits)+1 = 6 tries), so a connection that keeps going silent
  ends in about 4 minutes.
- internal/gui (Mac Stage, Windows/Linux StageBinary): run's 10 minutes
  (checkWait, a var for tests) bound only LatestIn; the download runs
  under a ctx with no deadline.
- internal/cli `magpie update` (Mac Stage, Windows/Linux ReplaceBinary):
  the same split.
- Siblings with the same fixed cap:
  - new internal/stall: Start(ctx, after) gives a ctx that ends with
    ErrStalled once `after` goes by with no byte read through w.Reader.
  - Bun (internal/plugin getURLOnce): watched with a 60s stall;
    KeepBunUpdated's 10-minute ctx around CheckBun is gone.
  - Claude Code (internal/claudecode downloadOnce, ~200 MB): watched with
    a 60s stall; keepOnce's 30-minute ctx around install is gone.
  - pf-serve (internal/pii upgrade): its 10-minute ctx is gone; get
    already had a 60s stall and the client a 60s header timeout, as the
    model's download (no total) does.
- Left as they are: plugin installs and npm updates (KeepUpdated's 10
  minutes) run `bun install`, whose network is Bun's own, small tarballs;
  rtk (5 min client), skills (2 min client), skilltree and market reads
  are small files; Grok CLI install has no cap of its own (its caller's
  ctx). None of them carries a large download behind a wall-clock total.

Run on mote (mote-run), at 49f207c78 + this change; the targeted
set again after rebasing on d4a221f79 (ok):
- go test ./internal/stall ./internal/update ./internal/claudecode
  ./internal/pii -run 'Stall|Slow|Silen|TestDownload|TestInstall|TestKeep';
  go test ./internal/plugin -run Bun; go test ./internal/gui -run
  TestUpdate: ok
- new: TestSlowButMovingIsReadWhole, TestSilenceIsAStall (no answer, part
  way), TestDownloadSlowButMovingOutlastsTheClientTimeout (client Timeout
  300ms, body ~1.2s: one try, no retry), TestUpdateSlowDownloadOutlastsTheCheckBound
  (checkWait 200ms, body ~600ms: ready), TestDownloadThatGoesSilentIsAStall
  (claudecode), TestBunDownloadThatGoesSilentIsAStall. The silent server
  after its retries stays covered by TestDownloadStallEveryTimeSaysSo
  (6 tries, errStalled).
- go test -race -count=3 ./internal/stall ./internal/update -run
  'Stall|Slow|Silen': ok
- win-run (Windows 11): ./internal/stall ./internal/update
  ./internal/claudecode ./internal/plugin with the same -run, and
  ./internal/gui -run 'TestUpdateSlowDownload|TestUpdateDownloadSaysStepAndSpeed': ok
- wsl-run (Ubuntu 24.04), -tags nogui: the same packages and ./internal/gui
  -run TestUpdate: ok
- gofmt -l; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build; GOOS=linux go build -tags nogui;
  GOOS=windows go build: clean
- Full suite: run after the push under the suite lock.

Broken by hand: fetch back on `client` fails
TestDownloadSlowButMovingOutlastsTheClientTimeout ("broke off ...
Client.Timeout or context cancellation while reading body"); the GUI's
download back under the check's ctx fails
TestUpdateSlowDownloadOutlastsTheCheckBound (state error, "context
deadline exceeded"); stall's reader not putting the timer off fails
TestSlowButMovingIsReadWhole (50 of 120 bytes); Bun's and Claude Code's
downloads unwatched fail their silent tests at the 20s bound ("context
deadline exceeded").

Not tried: a real update over a slow or throttled link, on any OS; a real
Bun or Claude Code download over one. The Mac's unpack and signature
check now run with no deadline (they had the 10 minutes before).

Fixes #5572
2026-11-07 06:09:42 +08:00
yetone d4a221f79c codex: a reset about to expire can be used 5 or 10 minutes before it does
shangyuan0818 on Discord asked for leads under 15 minutes (1, 3, 5, 10, or
free seconds) for Codex's auto-use of the reset about to expire, to use
more of the windows first. The shortest was 15m because the gateway only
looked every 5 minutes after a pass ended (a pass is bounded at 2
minutes), so the gap between looks could reach ~7 minutes. With a 5-minute
lead, the reset could run out before any look landed inside it.

- provider: a look lands on the lead's start (nextResetLook takes the
  sooner of +5m and until-lead), and the loop sleeps until the soonest look
  due among the accounts its pass went over (expiringResets.wake: 5m at
  most, 1s at least; an account the pass skipped wakes nothing). A read or
  spend that fails inside the lead in the last 15 minutes is tried again
  in 1 minute (retryResetLook), not 5; a long lead failing earlier keeps
  the 5-minute cadence. A retry that came due while a hung pass ran is
  made at once.
- settings: CodexResetLeadLeast 15 -> 5; choices 5m, 10m, 15m, 30m (default),
  1h ... 24h. Saved values from 15 to 1440 stay valid; the default is
  unchanged.
- GUI (app.js RESET_LEADS, resetLeadMinutes) and CLI (magpie quota
  auto-reset lead) follow the same range. No new strings ("{n} min"
  already exists). Still the app menu, no seconds field.

Why 5 and not 3 or 1: in the worst case a try hangs to the pass's 2-minute
bound. At 5m: try at T-5:00, hung until T-2:57, retried at T-2:56, so two
tries before expiry (four when ChatGPT refuses at once). At 3m a hung try
leaves no retry. At 1m one try cannot even run to its own bound, and
local-vs-server clock skew eats the rest.

Run (mote, via mote-run, at base 49f207c78):
- go test -run 'Reset|Expir|Lead' ./internal/provider ./internal/settings
  ./internal/cli: ok. New: TestShortLeadSpentInTime (5m lead at four loop
  phases: spent at T-5 within 5s; a 2-minute hung try then a retry before
  T-1m; four quick failures, all before expiry; a 7m CLI lead lands on
  T-7; a 6h lead failing all along makes 70 to 90 tries, not ~360),
  TestResetLoopWakesForTheSoonestLook.
- go vet: darwin (provider, settings, cli, gui), GOOS=linux -tags nogui,
  GOOS=windows. go test ./internal/settings ./internal/settingsapi: ok.
  ./internal/gui: ok but TestMainWindowCorners/macOS_26_SDK (#3949) and
  TestPanelHiddenByWailsMarksPageOutOfSight (#5322), AppKit window tests
  red on mote's macOS 27, both filed; the size budgets pass.
- GUI: codex-reset-lead.test.cjs (now also picks 5 min and checks the
  10-item menu), codex-auto-reset-settings, i18n-keys; Chromium and
  WebKit, en/zh/zh-TW/ja/de, 1100 and 420 px: 49/50. The one red is
  i18n-keys "a plugin's words are its own", red on main and filed
  (#5327, #5332, #5426, #5482); nothing here touches those files.

Broken by hand, each went red:
- the look not landing on the lead's start: TestShortLeadSpentInTime's
  7m case (spent 4m59s before).
- wake fixed at 5m: TestShortLeadSpentInTime, TestResetLoopWakes...
- the 1-minute retry turned into nextResetLook: the hung-try case.
- CodexResetLeadLeast back at 15: TestShortLeadSpentInTime,
  TestQuotaResetLeadCmd.

Not tried: a real Codex account spending a card at a 5m lead; a Mac
asleep across the lead (no lead can help there, same as before); the
3-minute delay after start is unchanged, so a magpie started within the
lead spends at its first pass; Windows and Linux runs (vet only).

Reported-by: shangyuan0818 (Discord)
2026-11-07 06:07:03 +08:00
yetone 9ed0f1fa49 agents: Claude Code's prompt cache lifetime is picked in its settings
Linka (Discord) asked to set Claude Code's prompt cache TTL from magpie.
Until now only Usage › Context's "Tuned for you" card wrote it, and that
card offers nothing when the value is already the cheapest it found.

Claude Code's opened row and settings sheet now have two rows under its
own Long conversations: "Prompt cache · main conversation" and "Prompt
cache · subagents". Each opens the app menu with Claude Code's default,
5 min and 1 hour. They write the keys the card writes, promptCacheTtl and
subagentPromptCacheTtl in Claude Code's settings.json
(agent.ClaudeCacheSet, POST /api/settings/claude-cache). Default takes
the key out. A pick is the user's own: it forgets the card's stash, so
the card's Undo leaves it. A variable that comes before the setting
(FORCE_PROMPT_CACHING_5M, CLAUDE_CODE_PROMPT_CACHE_TTL,
CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL, in settings.json's env or
magpie's own) disables the row and names the variable, and the route
refuses it, so a value the user set by hand is never written over.

The names were checked in Claude Code 2.1.316's binary. Its resolver
checks FORCE_PROMPT_CACHING_5M, then the env var, then the setting
(enum "5m"/"1h"), then an agent's experimental.cacheTtl, then
ENABLE_PROMPT_CACHING_1H. With nothing set, the main conversation gets
1h on a subscription within its limits and subagents get 5m.

Run (mote, at this tree on 2ce44dc28):
- go test -count=1 -run 'TestClaudeCache|TestTune' ./internal/agent
  ./internal/gui: ok; go test ./internal/cli: ok (route parity).
- node --test claude-cache.test.cjs: 8/8 (Chromium and WebKit, en and
  zh, 900 and 420px), with agent-compact, i18n-*, gui-ja/zh-tw/de,
  old-webkit, agent-details-ready and context-tune: ok.
- Whole GUI suite on the Linux VM (wsl-run, concurrency 4), still
  running at commit: 74 files red there, mostly WebKitGTK. Of those
  only codex-memories-settings reaches Claude Code's settings: it
  counted Claude Code's rows as Long conversations alone, and now
  leaves out the two cache rows and checks they are there (18/18 on
  mote). desktop-subagent-model, account-eye, allow-ips and builtins
  pass alone on mote. codex-auto-reset (webkit de, #4790) and
  i18n-keys (#5327, #5332, #5426, #5482) fail the same way at
  origin/main f0620db63 on mote.
- go test ./internal/gui ./internal/agent ./internal/tune: agent and
  tune ok; gui red only in TestMainWindowCorners/macOS_26_SDK (#3949).
- gofmt -l: clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., go build ./...: ok.

Broken by hand:
- Without forget, TestClaudeCacheSet fails ("the pick is the user's,
  not the card's").
- Without the lock check, it fails ("set under
  CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL").
- With default leaving the key, TestClaudeCacheSet and
  TestClaudeCacheRoute fail.
- Without the rows in agentcompact.js, claude-cache.test.cjs fails 8/8.
  Without the same-pick check, it fails on the extra post.
- The first GUI run was red in WebKit at 420px: Playwright's own
  scroll to an off-screen button was taken as the page scrolling. The
  test now wheels the rows into sight as a reader does, and checks they
  came into view.

Not tried: a real Claude Code session reading the picked value (only
the settings.json it reads was checked); the live ~/.claude was never
touched.

Reported-by: Linka
2026-11-07 05:16:53 +08:00
yetoneandmdwsk88 30a0bfe889 gateway, provider, cli: search APIs marked mix are asked together, their pages merged (#2845)
A search asked the search APIs in order and gave the model the first
one's pages. On #2845's 80-query benchmark no single API was best on
both sets. The deduplicated union of two or three APIs' pages scored
higher than the best single API and lost no query (60-query set: 108 to
114-117 of 120, sign test p <= 0.03).

Off by default. When two or more search APIs are marked mix
(SearchAPI.Mix), they are asked first, at once (askSearchAPIsTogether).
Each uses its own keys and timeouts, as when it is asked alone
(askSearchAPIKeys). Their pages go to the model in turn: each API's
first page in the saved order, then each one's second. A page an
earlier API already gave is left out by its address (pageKey). One
that fails or finds nothing leaves the others' pages. When none finds
anything, the APIs not mixed are asked in order. With fewer than two
mixed APIs on and ready, a search runs in order as before. No text
says which API found a page, so what a vendor sees reads as before.

MixSearchAPIs marks the vendors named (two or more, set up, each once)
and clears the rest; none clears all. SetSearchAPI keeps the mark, as
it keeps off, since Settings sends an edit without it. Backup copies
the whole entry, so the mark carries over. CLI: magpie search mix
<api>,<api>, magpie search mix off, and magpie search lists a mixed
one as mix. docs/subsystems/gateway-routing.md has a section on it.

Ported from mdwsk88's 2966cce77 and reviewed line by line. What
changed from it:
- The cap follows the search's count (#5545, the commit before this):
  searchMixMost is 2 x the count a search asks for, at most 20
  (searchHitsMost). The default stays 12 pages, as in the patch.
  TestSearchAPIsMixedCapped is a table over count settings and named
  counts.
- The CLI keeps both search count and search mix.
- No Settings toggle. The mode stays CLI-only, by the UI-restraint
  rule; the docs say so.

Run (mote-run):
- go test -count=1 -run "Search|Mix" ./internal/gateway/: ok; -race
  -run "TestSearchAPIsMixed|TestMixSearchAPIs": ok.
- go test ./internal/provider/ ./internal/backup/: ok; ./internal/cli/
  -run "TestSearchCLI|TestEveryRoute": ok.

Broken by hand: with apiSearch's mixed branch turned off,
TestSearchAPIsMixedAskedTogether fails (only the first API's pages)
and TestSearchAPIsMixedCapped fails ("count set 0, named 0: 6 pages,
want 12"). Restored, both pass.

Not tried: a real search with two vendors' live keys. The tests use
fake search APIs.

Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
Reported-by: mdwsk88 (dawei on Discord)
2026-11-07 04:03:01 +08:00
yetoneandmdwsk88 4e0e8e7933 gateway, settings, gui, cli: the results a search is answered with can be set, 1 to 20 (#5545)
Claude Code's WebSearch and Codex's web_search never name a count, so
magpie answered every such search with searchHits, 6 pages (#5545,
mdwsk88: more pages for research-heavy work, fewer to save context).

settings.SearchCount holds the count. 0 means the default, 6
(SearchCountDefault), and the most is 20 (SearchCountMost), the most
Brave and Tavily return. Save refuses a value out of range, so nothing
is written. Settings.SearchPages reads it. The gateway's searchCount
falls back to it when a search names no count. The web_search MCP tool
still answers a named count with that count, and its schema's default
says the count set. It reaches every search API (Brave, Tavily, Exa,
You, the plugins' searchers), as a named count already did.

- Settings › Models › Web search: "Results per search", segments 3, 6,
  10, 15 and 20, plus a count set by hand in settings.json.
  POST /api/settings/search-count sets it alone. settingsapi.Apply
  keeps it as it keeps search-all, so a save of the Settings form
  doesn't put it back.
- CLI: magpie search count says the count; magpie search count <n>
  sets it; magpie search count default puts 6 back. A bad value is
  refused and nothing is written.
- docs/subsystems/gateway-routing.md says it.
- New strings are in zh, zh-TW, ja and de.

Run at this tree (mote-run, macOS):
- go test -count=1: internal/settings, settingsapi, cli, gateway
  (TestSearchMCPCount, TestSearchCountReachesEveryAPI,
  TestSearchCountSetting), and gui (TestSettingsSearchCountSetOnItsOwn, and
  TestSettingsSaveKeepsWhatItDoesNotSend with SearchCount set): ok.
  internal/gateway whole: ok with -timeout 45m (847s). internal/gui
  whole: ok but TestMainWindowCorners/macOS_26_SDK (#3949, mote is on
  macOS 27).
  The first cli run was red on TestEveryRouteHasACommandOrIsNamed:
  the new route had no CLI entry. cliForRoute maps it to search count
  now.
- Broken by hand: searchCount returning searchHits again makes
  TestSearchCountSetting fail ("set 11: a search naming no count asks
  for 6, want 11"). Restored, it passes.
- GUI: node --test --test-concurrency=4 over routing-*, usage-*,
  ledger-*, panel-*, call-*, search-*, searcher-*, settings-*, i18n-*
  and gui-* (Chromium and WebKit; the files cover en, zh, zh-TW, ja
  and de), with #2398 and #5545 in one tree: 4961 of 5016 ok. The 55
  reds are in 12 files. i18n-keys' "a plugin's words are its own"
  names other files' strings (#5327, #5426, #5482). The other 11 files
  were run alone at dc49feca9 (this tree without either change) and at
  this tree: 52 and 51 reds, the same tests. The one apart is
  usage-focus-steady, which flakes (#3501). Each is filed: #5392,
  #3414, #5048, #3799, #3415, #3954, #4627, #4628, #5223, #1529.
  routing-canceled-row.test.cjs: 10 of 10. With the .rt-req.gone rule
  taken out, its dot is the answered green rgb(24, 154, 88) and it
  fails. Restored, it passes.
- Not tried: a real Claude Code WebSearch through this tree with a live
  search API key. The tests use fake search APIs.

Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
Reported-by: mdwsk88 (dawei on Discord)
2026-11-07 04:03:01 +08:00
yetone d55881730d gateway: a key can be held to some MCP servers and tools
wakaka on Discord (#help, 11-06) asked for gateway keys limited to some
MCP servers and tools, as keys already are to models (#882).

A key's MCP list (caller-keys.json "mcp") holds entries "server" (every
tool of it) or "server/tool"; "-" alone is no MCP server; an empty list
is every server, as before. A key issued under another is held to its
issuer's list too.

Every MCP route checks it:
- magpie's own servers (web search, vision, image, Magpie Browser, plugin
  tools) through serveMCP: initialize/tools/list/tools/call are refused
  or filtered per server and tool, and /v1/magpie/key-limits names "mcp";
- the Library hub ("magpie"): only the backing servers and tools the key
  may use are listed, and a call by name or by fallback is refused;
- /mcp/<name> and /mcp/run/<name>: the server is refused, tools/list is
  filtered in JSON and SSE replies, tools/call refused; a reply the
  filter can't read (an encoded body) is a 502, never passed through.

GUI: "MCP servers" in the key row's menu opens the app's own picker (no
native select) with All, No MCP server, each server and its tools (GET
/api/caller-keys/mcp lists magpie's own servers and the Library's). A
key held to some shows a badge saying which, that opens the same list;
a free key shows nothing more in its row, on hover either. A hover badge
was tried first: it pushed the row past 560px (gateway-caller-keys) and
squeezed the masked key under a drag at 420px (gateway-key-arrange).
CLI: magpie gateway-key mcp <id> github fs/read_file | none | all.
zh, zh-TW, ja, de strings; docs/reference.md and the gateway-routing and
library subsystem pages.

Not covered: a model's own built-in web search (a vendor tool, not MCP).

GET /api/caller-keys/mcp is named in the CLI parity test's notYet (its
list is what `magpie gateway-key mcp` takes; TestEveryRouteHasACommandOrIsNamed
caught it at the rebased head).

Run on mote (mote-run), at the pushed head:
- go test ./internal/access ./internal/cli ./internal/gui
  ./internal/library ./internal/gateway at a9c40186d (this change on
  2ce44dc28): ok except internal/gui's TestMainWindowCorners/macOS_26_SDK
  (#3949, the same message on macOS 27). After the rebase onto a9667daad
  (no file in common): TestCoreScriptBudget, TestCallerKey*,
  TestEveryRoute*, TestGatewayKey*, TestKeyMCP*, internal/access and
  go vet ./internal/... at d36f89224's tree: ok.
- gateway-caller-keys chromium en reads wider than 560px 4 of 6 runs
  alone on this branch and 4 of 6 on origin/main a9667daad: #3797,
  recorded there.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./...: clean; darwin, linux (nogui) and windows builds ok; gofmt -l
  clean.
- GUI: gateway-key-mcp.test.cjs in chromium and webkit, widths 1100 and
  420, en/zh/zh-TW/ja/de: 20/20. Every gateway-key*, gateway-keys* and
  i18n* file in both engines: ok except gateway-key-models en (red on
  origin/main ecc26a339 too, #4081/#5233) and i18n-keys "a plugin's words
  are its own" (red on main, #5332).
- The whole GUI suite (both engines, every language) with the hover
  badge: 91 reds in 25 files. Rerun alone on this branch and on
  origin/main 54dc257f1: only gateway-caller-keys (560px sideways),
  gateway-key-readonly, models-fold and models-select-all-api were red
  on the branch alone; the badge moved into the row menu for the first
  two. After it, every gateway-key*, gateway-caller-keys, gateway-card,
  gateway-connect-keys, api-key-theme and i18n* file passes in both
  engines, except i18n-keys "a plugin's words are its own" (red on main,
  #5332, none of the three strings are this change's) and 1 of 20
  models-select-all-api "the click scrolled" (#4389; models-fold is
  #4071). The rest are red on origin/main too and each has an issue:
  account-weight #4644, codex-auto-reset #2360, header-centre #3479,
  images-codex-one #4618, key-replace #4126, menu-input-scroll #3402,
  mobile-web #3952, model-chip-steady #4388, model-copy-id #4621,
  models-works-only #4391, nav-timeout #4787, omarchy #4624,
  page-width-steady #5013, phone-connect-menu #4706/#4707,
  plugin-move-unserved #4392.

Broken by hand, each went red: the serveMCP server gate, call check and
list filter, the own-server list filter and key-limits "mcp"
(TestKeyMCPOwnServer); hubTools, hubServersOf, the hubToolNamed
fallback and hubMCPRun (TestKeyMCPHub); /mcp/run (TestKeyMCPRun); the
/mcp/<name> guard and filter (TestKeyMCPProxy); the GUI's "No MCP
server" being exclusive (gateway-key-mcp).
gateway-key-readonly chromium 420 ja was red with the hover badge (the
sibling run, the whole suite and its rerun; green on origin/main) and
passes with the badge in the row menu.

Not tried: a real Library server through a live gateway, the hub with a
real agent, and running on Windows or Linux (vet and build only).

Reported-by: wakaka
2026-11-07 03:21:57 +08:00
yetone 8cbaeecae9 providers: errors=pass sends a vendor's error to the agent as it came, asked once
ne9ko9 on Discord wants errors handled explicitly, not by inference, and
a mode that passes them straight through. A custom or API-key provider
(no account, an endpoint of its own, not a subscription) now takes
`passErrors` in its config: "magpie handles" (the default, unchanged) or
"Pass through". Nothing sets it but the user, and an edit that doesn't
send it keeps the saved value.

With it on, for that provider:
- no rewriting: on the client's own API, upstream's status,
  Content-Type and bytes go out (passError); on another API, the
  client's shape is built with the vendor's own type, message and raw
  code and param (a numeric code stays a number). Retry-After and
  *ratelimit* headers go with it;
- no too-long inference, no busy words, no 413 hint, no policy
  rewording (settle never runs: the try is passing);
- no gateway retry: forward()'s Retries loop, refit, firstWait, the
  loop's re-asks, reloop, empties retry and streamTranslated's
  cont.again all stop;
- no fallback and no rest: the candidate loop's one choke point,
  newHoldWriter(…, !pass && …), lets the try pass, so nothing after it
  is tried, and restAfterMarked answers By "off".
magpie's own file-id re-ask (dsRetryGone) still runs, as it fixes
magpie's own upload, not the vendor's answer.

CLI: `magpie provider set <id> errors=pass|magpie`; a bad value is
refused and keeps the old one; an account is refused. `provider show`
says "errors pass".
GUI: Edit → Advanced → Errors, a quiet app-menu picker (openProtoMenu,
no native select) with "magpie handles" and "Pass through", shown only
where takesPassErrors; zh, zh-TW, ja, de. It is drawn by passerrors.js,
imported when the editor draws the row (old-webkit's lazy list names
it), and app.js pays for its few lines by two comments cut, so app.js
is smaller than before and TestCoreScriptBudget's numbers are unchanged.

Tests:
- internal/gateway/pass_errors_test.go: TestPassErrorsAskedOnce (503,
  429, 404 with numeric codes, alone and as a group's first member:
  exact bytes and status, asked once, the second member never asked,
  no rest), TestPassErrorsNotInferred (a too-long 400 byte-for-byte),
  TestPassErrorsOtherAPI (Anthropic 403 code 20031 to a Chat client,
  streamed and not).
- internal/provider/pass_errors_test.go, internal/cli/errors_cli_test.go.
- internal/gui/tests/provider-pass-errors.test.cjs: every language,
  1100 and 420 wide, Chromium and WebKit.

Run, through mote-run at this commit:
- go test -count=1 -timeout 45m ./internal/gateway ./internal/provider
  ./internal/cli ./internal/gui (at the parent 19c45d5d4's tree): gateway,
  provider, cli ok; gui red only in TestMainWindowCorners/macOS_26_SDK,
  mote's macOS 27 (#3949). TestCoreScriptBudget ok.
- Rebased on 2f660ca86: go vet of the four packages, the PassErrors,
  Budget, SameAPI and Errors tests and provider-pass-errors (60/60)
  again at this commit: ok.
- GUI on mote: provider-pass-errors 60/60 (both engines), old-webkit
  and provider-pass-errors under BROWSER=webkit 36/36; i18n-keys red
  only in "a plugin's words are its own" (#5332, #5426, #5482).
- The whole GUI suite on Linux (wsl-run, magpie-desktop, --test-
  concurrency=4): 21188 of 21666, 478 red. The 15 provider-editor files
  among the reds (vertex-editor, zero-priced-free, provider-fetch-again,
  provider-picks-stay, model-chip-steady and ten more) were run at this
  commit and at origin/main 2f660ca86 without it: 128 of 236 red on
  both, the same tests. The rest are in files this commit doesn't
  reach.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./...: ok. gofmt -l clean.
- Full suite: run after the push under the suite lock.

Broken by hand: every PassesErrors() gate set to false: AskedOnce,
NotInferred and OtherAPI red (rewritten body, b asked, rested). The GUI
test on the old code: 0/60.

Not tried: a real vendor account or relay with errors=pass; Windows and
Linux hardware (vet only).

Reported-by: ne9ko9 (Discord)
2026-11-07 00:42:21 +08:00
yetone e1eeeed734 browser: the extension's key connects Magpie Browser and nothing else; own needs this computer; a key turned off closes its browser
483b131ef wrote a full-access gateway key ("Magpie Browser") into the
extension zip in Downloads. Anyone with a copy of the zip could use every
model, MCP server and stat, and, with own = key == OwnBrowserKey(), could
connect from another machine as this computer's own browser and receive
this computer's agents' browser calls (page data out, prompt injection
in). A keyed WebSocket also stayed open after its key was turned off.

- access: Key.Browser / Identity.Browser. A browser key is also ReadOnly
  (so a magpie from before reads it as read-only) and never issues keys.
  access-key and issuer-key refuse it. ScopeBrowser(id) holds an existing
  key to the browser with the same secret; the sharing key is never
  scoped. Current(who) says whether a key Check took is still on by the
  same secret (Identity carries the secret's SHA-256, set on the legacy
  sharing-key fallback too, so a legacy caller's identity is the same
  before and after its migration).
- gateway readOnlyGuard, the one place every route passes after the key
  is known: a browser key gets 403 gateway_key_browser_only on every
  pattern except GET /v1/magpie/browser/extension.
- own: the key must be OwnBrowserKey() and the request local(r)
  (loopback peer, not proxied, not the page port).
- browserConn keeps its key's identity. call() refuses a connection whose
  key is no longer Current, and a 5s watcher closes it (1008).
- gui browserKey: a new key is made Browser; the recorded key is reused
  only once ScopeBrowser holds it.
- GUI key row: "Browser only" tag (zh, zh-TW, ja, de), no access toggle.
  CLI prints "browser" access. agent gatewayTakes skips a browser key.

Old data: an existing "Magpie Browser" key (OwnBrowserKey) is rescoped in
place, same id and secret, when the gateway starts (ScopeOwnBrowserKey)
and again on the next extension download. Installed extensions keep
connecting with no reinstall. Every copy of an old zip loses models, MCP,
stats and writes, and from another machine it is no longer this
computer's browser. A user who downgrades reads the key as read-only.
Keys a user made themselves are untouched.

Regression, filed as #5529: Magpie in Docker with the host's Chrome
reaches the container from 172.17.0.1, not loopback, so its agents no
longer get the host's browser as their own. #5529 proposes pairing in
its place. docs/reference.md and site docker pages (en, zh, ja) say so.

Docs: docs/subsystems/gateway-routing.md (browser key), library.md
(Download), docs/reference.md (Docker), site/public/docs{,/zh,/ja}/docker.html.

Run on mote at origin/main 2000ae439 + this change:
- gofmt -l internal cmd: empty.
- go vet darwin, GOOS=windows, GOOS=linux -tags nogui over access,
  gateway, gui, agent, cli: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway
  ./internal/gui ./internal/access ./internal/library ./internal/agent
  ./internal/cli: all ok except access's
  TestLegacyLANFallbackBeforeMigration, red from this change (the legacy
  fallback had no secret sum). Fixed here, then ./internal/access in full:
  ok.
- GUI, 21 files (gateway-key-*, i18n-*, library-browser-*), chromium and
  webkit, every language: 332 of 334. The 2 reds fail the same on
  origin/main 6f5d48ea0 run alone: i18n-keys "a plugin's words are its
  own" (#5332, #5426, #5482) and gateway-key-models' 560px width check
  (#4081, commented).

Rebased onto 6f5d48ea0 (remote_prove: a new POST /v1/magpie/prove route
and edits to readonly.go and gateway.go, so not a -run rerun): gofmt -l
empty, vet on all three ok, go test -count=1 ./internal/gateway
./internal/access ok, ./internal/gui -run Browser ok. A browser key gets
403 on the prove route too (TestBrowserKeyEveryRoute walks every pattern).

Broken by hand, each red on mote:
- guard off: TestBrowserKeyEveryRoute (/v1/ 200, /v1/models read_only
  not browser_only).
- no migrate: TestBrowserKeyEveryRoute (/v1/models 200).
- own without local(r): TestOwnBrowserKeyIsThisComputers.
- no watcher: TestBrowserKeyOffClosesItsBrowser (stayed connected).
- no Current check in call(): TestBrowserKeyOffClosesItsBrowser.
- Current ignoring the secret: TestCurrent.
- gui reuse without ScopeBrowser / new key without Browser:
  TestBrowserExtensionDownload (both).

Not tried: a real Chrome with the real extension, a real Docker
container, a real old key in a live HOME, the TUI. No CLI test for the
"browser" access word. Tests reach no network (httptest, loopback only).
2026-11-06 22:11:02 +08:00
yetone 1f439ecc5e gateway keys: a limit can count only some models or providers (zola_xynb)
zola_xynb on X asked for a cap per model or per provider under one
gateway key. A key limit can now name models (access.Limit.Models,
"<provider>/<model>" or "<provider>/*"), so one key can have, for
example, a month of $20 on openai/* next to a month for the whole key.
Limits without models still cover the whole key, as before.

- budget: sums are kept per window and scope, and count a ledger row only
  when its provider/model matches (any of the model's ids). reserve holds
  a request to a scoped limit only when the model it names is served
  there. windowsOf keeps every scope's sums, so the ledger is not read
  again on each request.
- gateway: keyLimited puts the key's spent scopes on the caller
  (withSpent), count_tokens included. A direct request for a spent model
  gets a 429 with Retry-After and no X-Magpie-Limit-Reset, so a remote
  magpie rests only that model. A routing group, a provider's fallback
  and embedding/image/video/decision groups skip spent members
  (groupKeeps, allowedCandidates) and get a 429 only when none is left.
  System One, count_tokens and magpie's own calls for the key are held
  too. Model lists are unchanged. A refusal turned away before routing
  now records its ErrType in the ledger.
- CLI: magpie gateway-key limit <id> add month --cost 20 --model openai/*
  (--model repeatable, --models a,b).
- GUI: the key limit editor has a Models field that opens the app menu
  (multi-pick: All models, every model of a provider, each model). It has
  no <select> and no new screen. The badge, line and tabs name the models.
  Strings are in every language.
- docs: reference.md and subsystems/gateway-routing.md.

Run at d52725d32 (this change on 4ef47b3f4), on mote:
- go test ./... -timeout 45m, under the shared lock, with the log kept
  whole: every package ok except three reds outside this change. None of
  the three touches what changed:
  - TestClosedBeforeSentEveryTimeSaysWhy (#5031, passes alone 3/3)
  - TestMainWindowCorners/macOS_26_SDK (#3949, red alone on macOS 27)
  - TestMoveToPlugin TempDir cleanup (filed #5524, passes alone 2/2)
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./..., go build ./...: ok. gofmt -l: nothing.
- GUI, chromium + webkit: gateway-key-*.test.cjs, gateway-keys-*,
  i18n-keys, i18n-en-no-cjk and usage-remote-key-limits passed 244/246.
  The new gateway-key-model-limit runs in every language at 1100 and
  420px. The two reds also fail on origin/main 3cbb7e042:
  - gateway-key-models en at 560px (#4081, #4616, #5233)
  - i18n-keys "a plugin's words are its own" (#5327, #5332, #5426, #5482)

Broken by hand; each one turned the named tests red:
- groupKeeps' spent skip removed: ItsModelsAlone and MediaGroups.
- modelAllowed's spent check removed: ItsModelsAlone and AFallback.
- withSpent on count_tokens removed: ItsModelsAlone.
- the scoped refusal sending X-Magpie-Limit-Reset: ItsModelsAlone and
  SystemOne.
- sums counting every model: ItsModelsAlone, TestScopedLimitCountsItsModels
  and TestScopedBesideTheWholeKey.
- embeddings' keyGroupRefusal back to keyModelRefusal: MediaGroups.
- the turned-away row's ErrType dropped: ItsModelsAlone.
- keyHolds not holding for Spent: ItsModelsAlone, AFallback and
  MediaGroups.
- decide.go's 429 back to a 403 stayed green. keyLimited's reserve
  refuses a direct decider first, so that line is a second guard.

Not tried:
- a real vendor account or a real remote magpie.
- the Codex backend path and a video group: they go through the same
  keyLimited/groupKeeps code, but no test of their own.
- the whole GUI suite: only the files above.
- Windows and Linux test runs: vet only.
2026-11-06 20:47:21 +08:00
yetone 4ef47b3f4d cli: the browser extension's download is named in the route parity list
483b131ef added POST /api/library/browser/extension and gave it no CLI
command or notYet entry, so TestEveryRouteHasACommandOrIsNamed went red.
It sits with the other Magpie Browser routes under the library stage.

Run on mote: go test -run TestEveryRouteHasACommandOrIsNamed
./internal/cli/ ok (red before this, in the full suite at 483b131ef).
The rest of that full suite run (go test -timeout 45m ./...) passed: 85
packages ok, plus internal/gui's TestMainWindowCorners/macOS_26_SDK, red
on mote's macOS 27 and already filed as #3949.
2026-11-06 20:24:53 +08:00
yetone f9e6061b85 claude: claude-magpie runs Claude Code through magpie, a plain claude left on the user's account
baranwang on X (11-06): `claude` stays on the user's own Claude account,
`claude-magpie` goes through magpie, and nothing is switched back and
forth.

`claude-magpie` runs `magpie claude run [args…]`. That writes a settings
file of magpie's own, <config>/claude-launch/settings.json, connected as
Connect connects Claude Code (the gateway, its key, the shared LAN key when
sharing is on, the model, the tiers) and starts
`claude --settings <file> args…`. Claude Code puts a --settings file's env
and model over the user's settings.json, a claude.ai sign-in and the
shell's variables (tried on 2.1.318), so ~/.claude/settings.json is never
rewritten. ANTHROPIC_API_KEY and the cloud switches (Bedrock, Vertex…) are
blanked in the file, so neither the user's file nor the shell can take a
request past magpie. The file is the agent `claude#launch`, listed nowhere:
the Agents page, Check and Notice see only the user's file. It is set again
when the gateway moved or its key changed.

- /model in a claude-magpie session saves to the user's settings.json
  (Claude Code never writes a --settings file). After the session a magpie
  model picked there moves into the launch file, for the next claude-magpie,
  and the user's file gets its model back. A Claude alias (sonnet) stays.
- Claude Code's own one-time `opus` -> `opus[1m]` rewrite of the user's
  file (migration_opus_to_opus1m), which the launch file's 1M opus tier sets
  off, is undone the same way. Found in the end-to-end run below.
- claude runs as a child so that can happen: on Unix a stopped child stops
  magpie too (^Z, fg; proc.WaitFollowingStops reaps it with WUNTRACED, as
  cmd.Wait can't see a stop), and claude's exit code is magpie's. On Windows magpie
  ignores Ctrl+C while claude has it.
- The command: a launcher beside the `magpie` command. Settings › Command
  line (AddCLI) writes it; `magpie claude launcher [add|remove]` adds it for
  a command put there before. It is a `#!/bin/sh` exec of magpie's stable
  path, or on Windows a .cmd running "%~dp0magpie". A file by that name
  without "written by magpie" is never written over.
- Docs: agent-wiring.md, and the start page in en/zh/ja.

Run at this commit (rebased on origin/main 218b38c59):
- mote: gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build for darwin, linux (nogui), windows;
  go test ./... -timeout 45m: 85 packages ok; red only
  TestMainWindowCorners (#3949) and TestRenewLoginsKeepsClaudeReading
  (#5481), both red alone on origin/main b020ae102. The run before at
  f22a9ae61 also had proc's TestEveryStartedCommandIsWaited red on this
  change's own Wait4 loop, fixed here by moving it into proc.
- Windows (xiaomi-gpu): go test ./internal/update ./internal/cli: cli ok;
  update red only in TestPackagedByDpkg, red the same on origin/main
  f47390bf3, filed as #4603.
- Real Claude Code 2.1.318 in WSL (magpie-desktop), sandbox HOME, a built
  magpie (`serve` on its own port), a fake Anthropic upstream:
  - `magpie claude run -p "say hi"`: PONG, exit 0; upstream got
    claude-opus-4-6 with the provider's key. A user settings.json with its
    own ANTHROPIC_API_KEY and "model": "opus" kept both values.
  - Interactive in tmux under bash -i: `/model fakeco/glm-4.6` then /exit:
    the user's file is back on opus, the launch file on fakeco/glm-4.6.
    ^Z stops both magpie and claude (T), fg resumes both.
  - `magpie claude launcher add` wrote ~/bin/claude-magpie, and running it
    answered PONG.
- Real Claude Code 2.1.281 on Windows: claude-magpie.cmd beside a built
  magpie.exe, `claude-magpie --version` printed the version through
  `claude --settings <launch file>`, exit 0.

Broken by hand, each red: the blanks dropped; the launch dir override; the
stale-address check; ClaudeLaunchAfter returning early; the opus[1m]
rewrite check; WaitFollowingStops answering 0 for a signal; "$@" turned into $* in the launcher; the model mark check;
AddCLI's launcher loop; --settings dropped from the args; the restore call
dropped.

Not tried: macOS with a real Claude Code (the Unix path ran in WSL only);
Windows interactive (Ctrl+C, /model restore); a real Claude subscription or
API key upstream (a fake upstream only). Known limits: a session that ends
by a crash or kill skips the restore; managed settings (policy) outrank
--settings; magpie has to be running (claude-magpie warns when it isn't);
Claude Code itself reformats the user's settings.json when it runs its
opus migration, values kept.
2026-11-06 17:31:04 +08:00
yetoneandggbdpq 7e5a54147f gateway: a routing group's intent sureness is its own, intent-sure= (#5101)
Jev's sure of an intent had to reach jevSure, a fixed 0.4, for every
group. zminds measured 39 of 237 turns in one day (16.5%) refused at sure
0.153 to 0.395, and those turns went by the group's routing as if it had
no intent rules. A group can now set its own threshold: intentSure, from
0 (take Jev's likeliest intent however unsure) to 1. Missing keeps 0.4.

readJev keeps Jev's likeliest intent, its sure and Topic (an answer of
intents rather than levels). ruleFor applies the group's own sure through
intentOf, so two groups sharing one classifier and its cached answer each
judge it at their own. "none of these" is never an intent, at 0 too.
Levels and effort are as before.

Set from a terminal: magpie group set <group> intent-sure=0.25, empty to
unset. SaveGroup and the CLI refuse a value outside 0 to 1, NaN too: the
patch's `v < 0 || v > 1` let intent-sure=NaN through the CLI, which
SaveGroup then failed on as "json: unsupported value". cloneGroups copies
the new pointer, since TestCloneGroupsSharesNothing went red on it.

Changed from ggbdpq's patch on #5101:
- The group editor's "Intent sure" row is left out. Its hints were long
  secondary text, it showed for every classifier when only Jev answers
  with a sure, and it had no GUI test. The Routing page instead carries
  intentSure through each save it makes of a group (the editor's Save,
  the routing menu, the manual pick), so a value set from the CLI isn't
  wiped by the next GUI save.
- Its i18n strings and site/public/docs/intent.html are left out. A
  site/ change waits for the maintainer (docs/contributors.md). The site
  diff was documentation text only: a paragraph id="sure", a sentence
  in "Match the rules" and one table row. It had no links or scripts.
- docs/subsystems/gateway-routing.md has a bullet for IntentSure.

Run on mote (mote-run):
- gofmt -l internal/: clean.
- go vet -tags nogui, also with GOOS=linux and GOOS=windows, on
  internal/gateway, internal/cli and internal/provider: clean.
- go test -tags nogui -run 'TestGroupIntentSure|TestJev|Rule|Classif|Decide'
  ./internal/gateway: ok.
- -run 'Group|Apply' ./internal/cli: ok.
- -run 'Group|Save|Clone' ./internal/provider: ok.
- go test -run Budget ./internal/gui: ok.
- node --test group-intent-sure (new), routing-group-strategy and
  group-first-token, in Chromium and WebKit: 42 pass, 0 fail.
- i18n-keys has one red, "a plugin's words are its own". It fails the
  same on origin/main b712adb84 and is filed as #5327, #5332 and #5426.
  i18n-en-no-cjk: ok.

Broken by hand, each red, then restored:
- sureNeeded always returns 0.4: TestGroupIntentSureThreshold,
  ZeroTakesTheArgmax and IsPerGroup FAIL.
- The patch's `< 0 || > 1` checks put back: TestGroupIntentSurePairs
  FAILs on "NaN" and "nan"; TestGroupIntentSureRange FAILs on NaN.
- The cloneGroups copy removed: TestCloneGroupsSharesNothing FAILs.
- The editor's Save sending intentSure null: group-intent-sure FAILs 4/4
  ("the editor's Save keeps it").
- The routing menu's pick sending null: it FAILs 4/4 ("a routing pick
  keeps it").

Not tried: a real Jev account with a group at 0.25; the full suite.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 10:44:24 +08:00
yetone 8fbf8e0af6 gateway: DeepSeek's own API gets an agent's images once, by file id, not on every turn (#5407)
DeepSeek's API is stateless, so every turn re-sent every inline image in
the history. Now, on api.deepseek.com only (never a relay or another
base), for a model with "flash" in its name (deepseek-flash sees images;
deepseek-v4-pro reads them as "[Unsupported Image]"), each base64 data:
image goes up once through POST /files (purpose=user_data, expires_after
a day) with the candidate's own key, and later turns name it by file id:
- Chat: {"type":"file","file_id":…} (flat, as DeepSeek's vision guide);
- Responses: input_image with file_id in place of image_url;
- Anthropic: source {"type":"file","file_id":…} plus anthropic-beta
  files-api-2025-04-14.
Shapes checked against api-docs.deepseek.com files_api, vision,
responses_api and anthropic_api. The Anthropic guide names the "file"
source type and the beta; the field name file_id is Anthropic's Files
API's, which DeepSeek says it follows. Not confirmed with a real call.

Ids are kept per key hash + image sha256 in deepseek-files.json beside
providers.json (temp+rename, unparseable file moved to .bad), reuploaded
with under an hour left. One upload per image and key however many
requests want it; a request waits at most 8s for its uploads, and what
isn't up goes inline this turn. A failed upload leaves the image inline
and rests that key's uploads for 10 minutes. A 4xx naming a file-api id
or a missing/expired file forgets the ids, uploads again and asks once
more; refused again, the request goes inline. detail:low stays inline.
`magpie provider set <id> image-files=off` turns it off (kept on GUI
save). Doc: docs/subsystems/gateway-routing.md.

Run (mote, at this tree on 498b6419f):
- go test -run 'DeepSeek|DsFileGone' ./internal/gateway: ok; -race -count=3 ok
- go test ./internal/gateway ./internal/provider ./internal/cli: ok
- go test ./internal/gui: TestMainWindowCorners/macOS_26_SDK red, the
  known macOS 27 red on mote (#3949); nothing in gui's code path changed
  but a kept field on save
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows ok;
  go build ./... and GOOS=linux -tags nogui ok

Broken by hand, each red: host check removed (InlineElsewhere), switch
ignored (ImageFilesOff), singleflight off (FilesOneUpload), breaker off
(UploadFailsInline), key left out of the cache key (FilesPerKey and
others), beta not added (ImagesByFile/anthropic), retry off
(FileGoneUploadsAgain), store not read from disk (FilesKeptOnDisk), the
flash check removed (InlineElsewhere), the 8s wait cap removed
(UploadSlowGoesInline).

Not tried: a real DeepSeek key (none available in the sandbox), so the
exact refusal text for a gone file and the Anthropic file_id field are
unconfirmed against the live API. Not covered: a custom_tool_call_output's
images (walkImages doesn't read it); files aren't deleted (they expire in
a day).
2026-11-06 02:46:46 +08:00
yetone 9d143eacab uninstall: install.sh --uninstall disconnects every agent first, a deleted magpie too
whimsical_wolf_15477 (Discord): after uninstalling magpie, Codex didn't go
back to its own config. `install.sh --uninstall` deleted the magpie command
and app and left every agent wired to a gateway that no longer runs: Codex
kept openai_base_url (or model_provider = "magpie" and model_catalog_json)
pointing at 127.0.0.1. A magpie deleted by hand undid nothing either, and
`--purge` refused with no magpie left to run.

- `magpie uninstall --keep-data` (uninstall.KeepData): every agent
  disconnected and its own values put back from stash.json, the service,
  autostart, shortcut, scheme and helpers removed, magpie's settings,
  providers and usage kept.
- install.sh --uninstall runs `magpie uninstall --yes --keep-data` (--purge:
  `--yes`) before deleting anything, and stops if it fails. With no magpie
  of its own (deleted by hand) but magpie's config left, it fetches the
  newest release into a temporary folder, checks its sha256, runs that, and
  deletes it after. An older magpie without --keep-data gets the newest one
  for this too. A magpie on PATH that the script didn't install is left to
  its own `magpie uninstall`, and said so.
- MAGPIE_UNINSTALL_SCRIPT=1: under the script magpie doesn't ask to delete
  a path that the script deletes next.
- docs (en/zh/ja start.html #uninstall) and READMEs: what the line does,
  that it works for a magpie already deleted, and Codex's lines by hand.

Run (WSL magpie-desktop; mote's disk is full, nothing run or deleted there):
- go test -tags nogui -run "Uninstall|Help|TestKeepData" ./internal/cli/
  ./internal/uninstall/: ok. node --test site/install.test.mjs: all pass.
- The new install tests against the old install.sh: 5 red. Broken by hand
  (--keep-data case removed, Data() back in KeepData): TestUninstallKeepData
  and TestKeepData red.
- Real e2e: magpie built from this tree, Codex wired in a sandbox HOME
  (not signed in, and ChatGPT signed in), magpie installed and deleted by
  hand; install.sh --uninstall with a local feed. config.toml's diff before
  wiring vs after is the [model_providers.magpie] table only (kept on
  purpose for threads started on magpie); model, effort, openai_base_url,
  model_provider and model_catalog_json are the user's again; settings kept.
- gofmt -l clean; go vet GOOS=windows/darwin/linux (nogui) for the two
  packages; sh -n and dash -n install.sh.

Not tried: macOS's zip path for a deleted magpie run for real (tests cover
it with fakes), Termux, Windows (no install.sh there; docs say download
magpie again and use Settings › Uninstall). The full internal/cli package
timed out at 10m under WSL load in providers_unreadable_cli_test (not
touched here); see the full suite record.
2026-11-05 12:52:46 +08:00
yetone 47d5839397 library: sync and backup files carry the hooks
VincentChan on Discord (v0.1.3005) said part of the Library doesn't reach
his other computer through sync. Checked kind by kind what the library part
of a bundle carries: instructions (each set's text, a linked set's file text,
the agents ticked, each agent's own addition), MCP servers, skills and
subagents all go. Hooks didn't: library.Bundle had no field for them, so a
hook made on one computer never reached the other, by WebDAV/S3/GitHub sync
or a backup file.

- library.Bundle.Hooks (*[]*Hook): name, description, event, matcher,
  command, timeout, agents ticked. Collect always sets it, empty too.
  Applied.Hooks (the entries magpie wrote into each agent here) stays out:
  each computer writes them on the sync Put runs, beside the user's own
  hooks, and records its own entries, so an entry the user edited there
  stays theirs.
- Put replaces the hooks with the bundle's, so one taken out on one
  computer goes from the others. A nil list (a bundle from a magpie before
  this) keeps this computer's.
- check refuses a hook with no name, no command, or named twice. The event
  and agents are carried as they come: an event a newer magpie knows is a
  problem on the agent here, not a refused library.
- davsync: an empty list hashes as before the field, so upgrading with no
  hooks syncs nothing.
- The CLI's backup line counts hooks; the GUI's sync/export/import ticks
  say "instructions, MCP servers, skills, hooks and subagents" in every
  language.
- library.md and sync-backup.md updated, and they now name what stays
  this computer's own: projects, skill groups, CopySkills/SkillHow,
  SharedSkills, MCPHub.

Instructions: two sandbox computers through the fake DAV server carried a
named set and a change to it, a set linked to ~/.agents/AGENTS.md and a
hand edit of that file, both computers having their own text first, an
agent's own addition, and an agent installed after the first sync. All
reached the second computer's CLAUDE.md/AGENTS.md (exploration tests, not
kept). So no instructions change here; what VincentChan saw is not
reproduced yet.

Run (worktree at 0e55a7593; origin/main bf60ea596's two commits touch
none of these files):
- mote: go test -tags nogui ./internal/backup ./internal/davsync
  ./internal/cli ./internal/library ok; go vet -tags nogui for darwin,
  GOOS=linux and GOOS=windows on the four packages ok; gofmt -l clean;
  go test ./internal/gui -run 'TestCoreScriptBudget|Words|I18n|Builtins' ok
- GUI (wsl-run, Linux): i18n-keys, github-sync, s3-sync, sync-*,
  webdav-settings-refresh, library-backups-top, gui-de, gui-ja, gui-zh-tw:
  187/187

Broken by hand: with Collect not setting Hooks, Put ignoring them and the
hash not dropping an empty list (the old code), TestCarryHooks,
TestCarryOldBundleKeepsHooks, TestCarryNewerHooks,
TestBackupFileCarriesHooks, TestSyncHooks and TestNoHooksHashAsBefore
went red.

Not tried: a real WebDAV/S3/GitHub remote between two real computers;
Windows and Linux runs of the Go packages.
2026-11-05 11:29:20 +08:00
yetone 234903cb23 cli: magpie model api sets the API a model is asked on, as the editor's picker does (yew_fence_931206)
A relay with many models behind one key can now have each model's API
set from a script, not only in the provider editor's Names, prices &
levels ("API this model is asked on"):

  magpie model api <provider/model>... chat|responses|anthropic|gemini|auto
  magpie model api <provider/model>... --reset      (auto)
  magpie model api <provider/model>                 what it is asked on
  magpie model apis [<provider>]                    the settings; with a
                                                    provider, every model

It saves through provider.SetModelPrefs, the editor's Save, into
settings' modelAPIs, so a running gateway reads it on the next request
and the agents' model lists are told once. Choices are those the editor
offers (modelAPIs in app.js): the APIs the provider has a URL for, when
it has two or more; Vertex AI none. --help anywhere prints the usage. A
flag in place of a model, an unknown API, a model the provider doesn't
list, or an API it has no URL for is refused; several models are all
checked before any is written. A saved setting for a model the vendor
no longer lists can still be reset. Documented in docs/reference.md
("The API a model is asked on") and the gateway-routing page.

Run (mote, via mote-run, at this tree on 0e55a7593):
- go test -count=1 ./internal/cli/: ok (46.7s)
- TestModelAPICmd, TestModelAPIReachesTheRunningGateway: PASS. The
  second starts gateway.New().Handler() first, asks relay/mixed (chat
  completions), sets anthropic through the CLI, and the next request
  goes to /v1/messages; after --reset back to chat.
- gofmt -l: nothing; go vet, GOOS=linux go vet -tags nogui,
  GOOS=windows go vet of ./internal/cli; go build, GOOS=linux build
  -tags nogui, GOOS=windows build: ok.

Broken by hand:
- the model/api(s) cases taken out of modelCmd: both tests FAIL
  (unknown command "apis" / "api").
- each model written as it is checked instead of all checked first:
  TestModelAPICmd FAIL "a refused command wrote:
  map[relay/claude-y:anthropic relay/gpt-x:chat relay/mixed:chat]".

Not tried: a real relay account; the reporter's provider. The full
suite runs after the push.
2026-11-05 11:05:38 +08:00
yetone 8e97e26d67 providers: WorkBuddy's sign-in warns that Tencent may ban the account first
NancyTom on X (11-04): WorkBuddy accounts used from DeepSeek Harness
through magpie were banned, the international build's (WorkBuddy AI)
most; repliers saw the same. Changing DSH's prompt isn't a fix: the
plugin already rewords DSH's opener and moves the system prompt into
the first user turn (REFUSED.md), and the bans came anyway. So magpie
says it before an account is added, as it does for Claude, Zed, Qoder,
Factory, MiMo and Command Code.

- app.js: WorkBuddy and WorkBuddy AI carry risk with WORKBUDDY_RISK.
  A moved subscription (every user's now) gets it through subOf, so
  the plugin's sign-in waits behind "Sign in anyway" too.
- i18n.js: zh, zh-TW, ja, de.
- CLI: `magpie accounts add workbuddy|workbuddy-ai` asks the same
  (provider.WorkBuddyRisk, the window's words; a GUI test checks the
  two are equal).
- Core script budget: no raise; the SUBS header comment was cut down.

Run (mote, at 823e7c250 + this change):
- node --test workbuddy-risk (new), i18n-keys, i18n-en-no-cjk,
  commandcode-risk, zed-sub, claude-risk, qoder-cn-tile: 51 pass, 0 fail,
  chromium and webkit, en and zh.
- 83 GUI files matching add-|sub|risk|workbuddy|plugin-sign|move|
  deprecat|signin|i18n: 1166 pass, 20 fail at load ~60. Alone:
  signin-closes-sheet passes; found-skill-pick-remove (#5013),
  plugin-move-unserved (#4410) and routing-rule-remove (#5088) red
  alone the same way on a fresh origin/main e3ed21c7a (18 fail there).
- go test ./internal/cli ./internal/provider ok; -run Budget
  ./internal/gui ok; go vet cli+provider darwin and windows, provider
  linux ok (cli's linux vet needs GTK's cgo, not on mote or WSL).
- gofmt -l clean.
- Rebased on 9d0c9b41e (app.js changed under it, #5139): -run
  Budget|Risk ./internal/gui ./internal/cli ./internal/provider ok, and
  workbuddy-risk, i18n-keys, i18n-en-no-cjk, qoder-cn-tile, claude-risk
  39 pass, 0 fail at the pushed head.

Broken by hand: risk taken off both entries, workbuddy-risk went pass 1,
fail 14 (the built-in tiles and the moved plugin's sign-in each asked
the backend at once); the text-equality case stayed green, as it should.

Not run: the whole GUI suite (another session's full GUI suite was on
mote). Not tried: a real WorkBuddy sign-in; nothing here touches the
plugin or what is sent to Tencent.
2026-11-04 23:58:53 +08:00
yetone 9d0c9b41ea serve: follow an update put in where it runs from; a replaced magpie.real is magpie
acezan on Discord (Linux 5.15, 0.1.2959 to 0.1.2960): `magpie web` as a
system unit updated /root/.local/bin/magpie.real, and the user unit's
`magpie serve` (`magpie daemon install`) ran on for good from "magpie.real
(deleted)". The panel said an older magpie served the gateway, and its
"close it here" then said the port holder "isn't magpie" and left it.

Why serve stayed old: the app and `magpie web` follow the program they
started from (gui's followReplaced) and restart into an update; plain
`magpie serve` had no such look, and answered `magpie update`'s restart
ask (gateway.RestartPath) "unsupported". Nothing else can restart it
reliably: a system unit doesn't reach the user's `systemctl --user`, and
on a Mac the launch agent's serve (#4335) is the same serve. So serve now
looks itself (internal/cli/serve_follow.go): every 5s it checks its
program with update.Replaced; once replaced, it waits until the gateway
is idle (nothing in flight, 10s since the last end, as gui's idle rule;
after an hour, nothing in flight is enough), ends the plugin hosts and
runs the new program in its own place (update.Reexec: exec in place on
Unix, same PID, so systemd and launchd keep tracking it; a new process
on Windows). The restart ask now answers restarting/waiting/current. A
build that isn't a release never does it.

Why "not magpie": proc.IsMagpie judged the file name, and "magpie.real"
(the program the installer's wrapper script runs) didn't match. It now
trims ".real". And proc.RunsMagpie, used by the takeover and the port
check, also reads Go's build info of the running program (on Linux
through /proc/<pid>/exe, which still reads after the file is replaced)
and calls it magpie when its main package is github.com/yetone/magpie.
A process that isn't magpie is still never ended (the existing
"other-server" case passes unchanged).

Tests, each red on the old code:
- cli TestServeRestartsIntoAnUpdate: a copy of the test binary named
  magpie.real runs `serve` on a free port; a script renamed over it is
  run in its place with the same pid and args, and the old port stops
  answering. Old code: "serve ran on as the old version" after 40s.
- cli TestServeFollowWaitsForIdle: current / waiting / tool-chain gap /
  waitMost with a request in flight / idle / non-release.
- gui TestGatewayFixQuitsAReplacedMagpieReal: a fake older gateway named
  magpie.real, its file removed after start, is quit and the gateway
  served here. Old code: {OK:false Reason:not-magpie}, acezan's case.
- proc TestIsMagpie magpie.real case; TestRunsMagpieByItsBuild: a copy
  named server.real, its file removed, is told by its build (Linux
  /proc/<pid>/exe), and is not magpie with the real main path.

Run: the targeted tests above on Linux (wsl-run, magpie-desktop, -tags
nogui) and macOS (mote-run), all pass. Broken by hand on Linux: dropped
the ".real" trim, made RunsMagpie only IsMagpie, and set serve's follow
to nil; all four new tests went red (output above), restored after.
gofmt -l clean; go vet (darwin, GOOS=linux -tags nogui, GOOS=windows)
and builds on mote.

Not tried: a real systemd user unit or launch agent with a real update;
the Windows restart path (Reexec starts a new process) beyond vet; the
macOS TCC part of #4335 (this restarts the launch agent's serve into the
new bundle path only if that path is where it started from). #4335 stays
open, and ggbdpq's daemon.RestartReplaced patch there is not applied.
2026-11-04 23:55:14 +08:00
yetone 00d8aac596 routing: Free quota by expiry spends the soonest-lapsing free quota first (wowbbs)
wowbbs (and shamen_xiaohong) keep check-in free accounts in one group:
WorkBuddy CN x2, MiniMax Code, TraeCode CN and Qoder CN. They asked that
the group spend the free quota that lapses soonest first, go on to the next
when one is used up or has lapsed, and use a paid account only when no free
quota is left.

This adds `expiring` (provider.FreeExpiring, routes.FreeExpiring). It is a
group's only, picked in the Routing page's group menu, with
`magpie group set <g> routing=expiring` or in the TUI. Nothing changes for a
group or provider that doesn't pick it. A provider keeps refusing it, as it
refuses `cheap`.

- routes: Seat.FreePlan and Strategy.ByPlan. FreeExpiring has three tiers:
  - free seats (Free, a model at no cost, or FreePlan) by Expires, the
    earliest of the window renewals and Lapse, to the hour; an unknown
    expiry goes last and ties keep their listed order;
  - then the paid seats, as Smart orders them;
  - then the spent and resting seats, by when they come back.
- provider.FreePlan reads an account's plan word: free, trial, 免费, 试用,
  体验, 體驗.
- gateway: weighRouted fills FreePlan when the strategy asks. The trace's
  Weighed rows gain `expires`, so the Routing page's story can say "its free
  quota is lost soonest, in 1d 2h". There are also lines for "a free one with
  no expiry told" and "no free quota left, so the paid one".
- GUI: an option in the group menu, the mode line, the story lines, and
  i18n in zh, zh-TW, ja and de. app.js only adds `expiring` to ROTATION,
  paid for by a shorter comment beside it, so the core is 11 bytes smaller
  than at its base.
- docs: gateway-routing.md (order of keys and accounts) and
  plugin-runtime.md (Seat and Strategies).

Plugins whose usage doesn't say when their free quota lapses got issues
rather than edits:
- magpie-community/plugins#718: Trae sums its packs; the soonest end comes
  from any pack, spent or past, and there is no runsOutAt.
- magpie-community/plugins#719: Qoder's plan is the raw userType
  personal_standard, which doesn't read as free, and its add-on, shared and
  dedicated pools have no expiry.
WorkBuddy (Free plan, resetsAt and runsOutAt) and MiniMax (Free, runsOutAt
on credits) already report what this needs.

Run, all on mote via mote-run at this tree (base 0ee424e3e):
- gofmt -l internal plugins: empty. go build ./....
- go vet of routes, gateway, provider, cli and tui; the same with
  GOOS=linux -tags nogui and with GOOS=windows.
- go test ./internal/routes ./plugins/rotation ./internal/tui: ok.
- provider -run TestFreePlan|Group|Routing: ok.
- cli -run Routing|Group: ok.
- gateway -run TestGroupSpendsFreeQuota|Wallet|Free|Cheapest|Routing|Weigh: ok.
- internal/gui -run Budget|Size: TestCoreScriptBudget is red, already red
  at the base (1,534,154 > 1,533,802, #5139). This change takes the core
  down 11 bytes and doesn't raise the budget.
- GUI, node --test in chromium and webkit, en, zh, zh-TW, ja and de, wide
  and 420px:
  - routing-free-expiring (new), routing-group-strategy, routing-cheapest-first,
    i18n-keys, builtins, group-member-free and provider-count-free: 176 of
    176 pass;
  - every routing-*.test.cjs: 2,478 of 2,520 pass. The 42 reds are in ten
    files (routing-rule-remove, rule-drag, rules-line, rule-models,
    row-swap, steady, order-unknown, steps-cap, story-shrinks and
    keys-fold). Run alone at this tree they give 27 reds, and at the base
    0ee424e3e 25, the same tests. They are filed as #5088, #4585, #3096,
    #3789, #3799, #4627, #4628 and #4629.

Again after rebasing on origin/main 0e804be29: gofmt; vet of routes,
gateway and provider; the same Go tests: ok. routing-free-expiring,
routing-group-strategy and i18n-keys: 62 of 62 pass. The core is 1,534,034
here, against main's 1,534,045.

Red on the old code: TestGroupSpendsFreeQuotaSoonestToExpireFirst at
0ee424e3e gives "pro,wb1,wb2,mm,qoder" where it wants
"mm,wb2,qoder,wb1,pro".

Broken by hand: with FreePlan never set, the gateway test gives
"pro,mm,wb2,qoder,wb1" (red). routing-free-expiring.test.cjs reads strings
that exist only with this change. routing-group-strategy's two menu counts
(11) went red with the new option, and they now count 12.

Not tried: no real account of any vendor. WorkBuddy, MiniMax, Trae and
Qoder check-in accounts were not routed live. The order was tested on
fabricated allowances shaped as their plugins report them. The full
`go test ./...` runs after the push.
2026-11-04 17:11:55 +08:00
yetone 6b47bce670 cli: magpie model compact <agent> sets an agent's own Long conversations
3eb2bda4f added POST /api/settings/agent-compact with no command, and
internal/cli's TestEveryRouteHasACommandOrIsNamed went red in the full
suite run after the push (settings_parity_test.go:437). Rather than
park the route in notYet, the command it names is here:

  magpie model compact <codex|claude|grok>            says the agent's
  magpie model compact <agent> every|off|<size>       sets it

every takes the agent's own away (it follows the value for every
agent), off is Full window, a size such as 300k compacts there; another
word is refused and nothing is written. A first word that isn't one of
settings.CompactAgents goes to the command as before (on|off|<size>).
cliForRoute names it; the usage text and agent-wiring.md say it.

Run at this tree (3eb2bda4f + this), on mote: go vet ./internal/cli,
GOOS=windows go vet ./internal/cli, go test ./internal/cli: ok.
TestModelCompactAgentCmd broken by hand (the command setting the shared
value instead): red, "codex 300000, claude 300000".
Not tried: the command against a real agent's files (catalog.Changed is
nil in the test, as in TestModelCompactCmd).
2026-11-04 16:35:16 +08:00
yetone 75e30625f5 plugin: a command that serves no pages moves a page's service off the app's port (#5187)
MYCF711 (#5187, Windows, 0.1.2901): magpie plugin update run while the
app runs hung with no output. Its host loads every plugin, and
page-chat's service waits for port 3477, which the app's host holds:
each CLI command that starts a host waited ~6s on it, then kept trying
the port every second in the background, so it could take 3477 from
the app's host when that restarted after the update.

Now magpie run with a command that serves no pages (anything but the
app, tray, tui, web, serve, a bare magpie or a magpie: link opened in
the app; servesPages) sets plugin.ServePages(false), and its host hands
a plugin whose magpie.page.service names an option a free port of its
own in that option (hostOptions). The plugin's other parts load at once
and the app's port is left alone. plugins.json is not changed, and a
service no option moves is started as before. The class, not
page-chat: any plugin page service declared with an option.

Run, at base 0ee424e3e plus this change:
- mote: go vet ./internal/plugin ./internal/cli (darwin), GOOS=linux go
  vet -tags nogui and GOOS=windows go vet of both, GOOS=linux nogui and
  GOOS=windows builds, go test -count=1 ./internal/plugin ./internal/cli:
  ok (280s, 65s). gofmt -l clean.
- Broken by hand: hostOptions handing options unchanged makes
  TestHostServingNoPagesLeavesHeldPort red (the load "didn't finish in
  10s") and TestHostOptionsMoveOnlyTheService red; servesPages returning
  true makes TestServesPages red on daemon, autostart, providers.
- Windows (xiaomi-gpu, win-run): the new tests and TestServesPages ok.
  Sandbox with page-chat and the reporter's git plugin
  (KevinFX-code/magpie-wps-lingxi), nogui builds:
  - 3477 held by bun, magpie plugin update: 13.9s before (page-chat
    "被占着" then "每秒试一次"), 10.6s after (page-chat "listening on
    127.0.0.1:51493").
  - beside magpie serve's host on 3477: 13.98s before, 12.4s after;
    serve's host keeps 3477.

Not tried / not reproduced: the reporter's literal no-output hang. Before
this change, update finished on 0.1.2909 in every setup tried (nogui
CLI with 3477 held, beside nogui serve, beside the release GUI exe in
the interactive session: 6-20s), so this removes the wait and the
port contention seen, not a hang reproduced. Not tried on Linux or the
macOS app.
2026-11-04 16:25:02 +08:00
yetone 90bf96a23d search: a plugin can give a web search API (its search hook)
treeman on Discord #help asked for web search to be pluggable so users can
add search vendors. A plugin's `search` hook, {search: {<id>: {name, keysURL?,
keyOptional?, url?, execute({query, count, key, url}, ctx)}}}, adds an API to
Settings > Models > Web search as `<plugin>:<id>`. It is added, keyed, ordered,
switched off and removed like Tavily or Brave. The built-in APIs stay built in.

How: host.js collects the hook's entries (id [a-z0-9-], an execute) into
Loaded.Searches and runs one with the `search` op (timeout from ctx, an error
with a numeric status comes back as a refusal). The host notes them in
plugin-searches.json (internal/plugin/search.go); provider.AllSearchVendors
adds the noted ones of plugins that are on to SearchVendors, so Ready, check,
the CLI and the GUI list see them. askSearchAPI hands a plugin vendor to
askPluginSearch below askSearchAPIKeys, so keys, rest on 401/402/403/429,
order, the masked query and the request-log row are the built-ins' own.

Run (mote, on this tree, whose base df7c94bdf was just fetched):
- go test -timeout 45m ./internal/plugin ./internal/provider ./internal/gateway
  ./internal/cli: ok.
- go vet native; GOOS=windows go vet plugin, provider, gateway, cli: ok;
  GOOS=linux go vet plugin, provider, gateway: ok. gofmt -l: empty.
- internal/gui: TestCoreScriptBudget and TestMainWindowCorners fail in a
  full run. This change touches no script (only api.go's loop), so the
  budget red is the base's (re-checked after the rebase, below);
  TestMainWindowCorners is AppKit on mote (macOS 27).
Broken by hand: skipping off plugins in NotedSearches turns TestPluginSearch
red; the refusal mapping removed turns TestPluginSearchAPI red.
Not tried: a real plugin against a real vendor's API; the GUI JS suite (no
GUI script changed); a Linux or Windows window; site/public/docs (en, zh, ja)
do not describe the hook yet. A plugin just added is listed once the host has
loaded it; RestoreSearchAPIs drops a plugin's entry on a machine without it.
The community README has the template (magpie-community/plugins 3ec42d4).

Reported by treeman.
2026-11-04 08:37:21 +08:00
yetone 452c28a78c cli: GET /api/context/reply is named as the window's own (#5026)
TestEveryRouteHasACommandOrIsNamed was red on main: the route came in with
0872bc2a0 and nothing named it. It is the reply half of the Context page's
detail view, served beside GET /api/context/text, which is already in
notYet as W (the window's own); it gets the same entry. #4826
(POST /api/usage/checkin-account) was already named in 8abdf53a8 and
passes.

Run on mote at the pushed head: go test -tags nogui -count=1 ./internal/cli
ok; GOOS=linux and GOOS=windows go vet -tags nogui ./internal/cli ok;
gofmt -l clean. Broken by hand: with the line removed the test is red with
the issue's message. Test-only change. Not tried: other packages (no code
outside the test table changed).
2026-11-04 06:50:38 +08:00