Commit Graph
4492 Commits
Author SHA1 Message Date
yetone 552cdf8071 redact: a value the model spans from the delimiter before it is masked (#3591)
The model's span may start at the token before a value: the `":"` of
a JSON field, a CSV row's comma. A phone number in
{"phone":"+86 139 1234 5678"} came as `":"+86 139 1234 5678`, and in a
CSV row as `,+81 90-1234-5678`, which the PHONE check took for no
number, and it went as written. A name came as `"Wei Zhang"` and was
masked with its quotes, so the JSON lost them. modelSpans now trims
spaces and `"',;:` from both ends of a name's, a phone's, an
address's, an account's and an email's span; a secret's only spaces,
since a password may start or end with a quote.

Found by TestMaskEval: its 3 #3591 phones are no longer Known, and
"both" reads 33/34 masked, 0/40 wrongly (from 30/34).

Run: go test ./internal/redact and ./internal/pii ok; -run
'Mask|Redact|Privacy' ./internal/gui ./internal/gateway ok; go vet
darwin, linux, windows; gofmt -l clean.
Broken by hand: edge = isSpace for every kind: TestModelSpanLeavesDelimiters
red (both phones as written, the name's quotes gone) and TestMaskEval
red on the 3 phones.
Not tried: the full suite (internal/proc's #3567 is red on main), a
real request through the gateway with the model on.
2026-10-25 17:44:52 +08:00
yetone 033990e642 redact: the masking evaluation starts with nothing known
A value Mask masks is known from then on, and masked wherever it is
again (known.go), Preview's too. TestMaskEval ran after the tests that
masked hunter2pass, rina.k@fastmail.com and the like, so in the
package's full run what they masked was masked in its cases too, and
the rules' column was not the rules': with one test before it that
masked the eval's phones, rules read 19/34 for 16/34. Forget
(export_test.go) lets every value go before the cases.

180cfb565's body says 38 cases; there are 39.

Run: go test ./internal/redact (TestMaskEval in the full run and
alone: 16/34 rules either way) and ./internal/pii ok; go vet darwin,
linux, windows; gofmt -l clean.
Broken by hand: without Forget and with a test before it that masks
the eval's phones, rules read 19/34.
2026-10-25 17:44:52 +08:00
yetone a30aed0162 provider: the WorkBuddy mover tells two accounts of one nickname apart by uid
wakkana on Discord: WorkBuddy accounts with one display name collapse
into one, deduped by name (wbWho's nickname, addSideLogin's EqualFold).

Where that runs today: WorkBuddy's built-in sign-in is gone, so
addSideLogin no longer writes WorkBuddy accounts. A sign-in through the
plugin goes to the plugin host, whose settle already keeps two accounts
of one name with different uids apart and lets the same uid replace
itself (#413, TestPluginSameNameOtherUID, passes at this head). What was
left by name is the mover, for accounts not moved yet:
- wbLogins dropped WorkBuddy desktop's account when an account magpie
  signed in had the same nickname, whatever its uid (the generic "one of
  magpie's stands for the agent's own" rule). Now it stands for it only
  when the uid matches; one removed in magpie stays out.
- renewedSince matched by name, so the desktop's marker read as the
  other "Me" renewed and the move would never commit. Moving and
  movedAccount carry the vendor's id (WorkBuddy's uid), matched by it
  where both have one; the agent's own is never compared; putBack skips
  by plugin key, not name.
Other movers have no id set, so they match by name as before; their
built-ins name accounts by email or login. The live addSideLogin callers
(Copilot, Google, ChatGPT API) name accounts by login or email too.
Sibling plugin: zcode 0.1.29 (plugins 5c9b7a4) now gives a uid, its
min is raised in a separate commit.

Run on origin/main 1dfa28484 plus this change; rebased onto 180cfb565,
whose two commits touch only internal/redact and the GUI:
go test -timeout 45m -count=1 ./internal/provider ./internal/plugin: ok.
GOOS=linux and GOOS=windows go vet ./internal/provider, gofmt -l: clean.
Broken by hand: TestWorkBuddyMoverSameNameOtherUID is red with
workbuddy.go from HEAD (one account moved) and, separately, with
same() by name only (the other account read as renewed).
Not tried: a real move with two same-name WorkBuddy accounts. Accounts
the old built-in already collapsed are gone; nothing brings them back.
Not run: the whole suite.
2026-10-25 17:42:37 +08:00
yetone a093e9c3a5 claude: a Claude Code run holding over its memory budget is let go after its turn, its session resumed (#3256)
claudeRoom bounded how many Claude Code processes run, not how large
each one is. A run is kept for its conversation's next turn, turn after
turn, and on a service never restarted one grew for days: a
node-MainThread in magpie.service reached 8 GiB RSS on a 31 GiB host and
the OOM killer took the machine down (#3256).

Now each time a run's reply ends, its process tree's resident memory is
read (proc.Tree.RSS: /proc VmRSS on Linux, ps on macOS, the working sets
of its job's processes on Windows, so an npm claude.cmd's node counts)
and logged with its pid. Over the budget (an eighth of memLimit on
Linux, of the computer's memory elsewhere, 1 GiB at least, 4 GiB if
unknown), a whole turn's run is not kept idle: its session is shelved
and the next turn resumes it in a new Claude Code with --resume, told
only the new messages. A run parked on tool calls is let go past 1.5x
the budget (no session to shelve there; its results start a new run).
Each Claude Code also logs pid and model at start, and run time, how it
ended and peak RSS (ru_maxrss) at its end, so an OOM pid can be found in
magpie's log. Budget on the reporter's 31 GiB host: 3.9 GiB.

Run (worktree at 99de8e1ad + this change, macOS arm64):
- go test -timeout 45m ./internal/gateway -run
  'Claude|Subscription|Room|Park|Idle|Resume' -count=1: ok (60.5s).
- go test ./internal/proc -count=1: every test ok except
  TestNoCommandBypassesProc, red on origin/main since 75e78a5a0
  (internal/tui/keep.go, filed as #3567, not this change).
- New tests: TestClaudeOversizedRunIsLetGoAndResumes (injected RSS over
  budget: the run ends, the next turn runs --resume s<pid> and is not
  told a1 again), TestClaudeRunWithinBudgetIsKept,
  TestClaudeOversizedParkedRunIsLetGo, TestClaudeRunBudgetScalesWithMemory
  (31 GiB MemTotal -> an eighth; 2 GiB -> the 1 GiB floor), TestTreeRSS
  (a real sleep's RSS read; none once waited for).
- Broken by hand: with both checks turned off, the oversized idle and
  parked tests go red ("the oversized run to end", "a run over its
  budget was kept waiting on its tool calls").
- Real Claude Code 2.1.310 in a sandbox HOME and CLAUDE_CONFIG_DIR,
  stream-json like the bridge, against DeepSeek's Anthropic endpoint
  (deepseek-chat, real key, synthetic 40KB turns): RSS after turns
  1/10/20/30 = 192/244/223/233 MiB, peak 245 MiB over 30 turns and
  ~1.2 MB of conversation. oversized() on that real process with the
  budget 1 MiB under its RSS said over; with the real budget on this
  64 GiB Mac (8192 MiB) it said keep.
- gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet -tags
  nogui ./internal/proc ./internal/gateway clean.

Not tried: a real Claude subscription run through the bridge on Linux
until it crosses the budget (the retire path is shown with injected RSS
on the fake Claude Code, and the RSS read on a real one); the Windows
RSS reader and job listing on the Windows box (vet only); a Linux run of
the /proc reader (macOS reads through ps); the full ./internal/gateway
package.
2026-10-25 17:41:41 +08:00
yetone 59f02d42cb provider: the Qoder mover's min is 0.2.37, so a QwenWork personal account's usage shows what is left (plugins#385)
opencode-qoder-auth 0.2.37 (npm view --prefer-online: 0.2.37) reads a
QwenWork personal account's account-context quota, whose total and used
are null, as a balance of the credits left, with the daily, monthly and
long-term pools from /api/v1/adapter/user/wallets, as QwenWorkCN.app
1.2.1's own client reads them. 0.2.36 called every such account "the
account reports no credits".

Run: go test ./internal/provider -count=1 ok (141.6s); go vet
./internal/provider for darwin, linux and windows; gofmt -l clean.
2026-10-25 17:41:33 +08:00
yetone 180cfb565e redact: an evaluation of the masking, with the rules, the model and both
TestMaskEval scores 38 made-up texts of the kinds agents send (prose,
code, logs, tool results, JSON, CSV, Chinese) with 34 values to mask
and 40 to keep. The cases start from what users reported masked
wrongly (#3144, #3143, #3029, #3538, #3577, d3db461bb, 611b9e173,
#1977) and add the values masking is for. It logs, by kind, how many
each way masked of those to mask and, wrongly, of those to keep:
the rules alone, the local model as it said it, and both with the
checks on what the model found, and lists every value one way got
wrong.

What the real model said is recorded in testdata/eval-model.json, so
the test replays "both" with no model and no network, and fails when
a value comes out wrong, or a Known one right. MAGPIE_EVAL_CACHE
points it at a downloaded model to record again.

Baseline (privacy-filter q8, M4 Pro):
  rules  16/34 masked, 0/40 wrongly
  model  32/34 masked, 8/40 wrongly
  both   30/34 masked, 0/40 wrongly
The checks take all 8 of the model's wrong ones off. Of the 4 misses,
3 are phones the model found with the delimiter before them
(`":"+86 …`, `,+81 …`), which the PHONE check turns down (#3591),
and 1 is 刘洋, which the model doesn't find (#3592). Both are Known.

Run: MAGPIE_EVAL_CACHE=$HOME/.cache go test -run TestMaskEval -v
./internal/redact against the installed model (recorded); go test
./internal/redact ./internal/pii ok; go vet for darwin, linux,
windows; gofmt -l clean. internal/proc's TestNoCommandBypassesProc is
red, on origin/main too: internal/tui/keep.go (#3567).
Broken by hand: modelFits off: 4 keeps masked and the 3 #3591 phones
reported right, red. A case's text changed: red, the recording is
stale. Taking snakeWord, epochNumber or madeID's SECRET check off
alone stays green: the model makes neither mistake on these texts,
or a second check catches it.
Not tried: the model on Linux or Windows, or on the CPU.
2026-10-25 17:41:10 +08:00
yetone 5f17c5a38e gui: a request's tool results are orange in its context, not pink
The owner found the context map's colours a little off (10-25, the
Routing card). Tool results, often the biggest tile, took the palette's
pink, which at the map's 11% tint sinks to a maroon between violet,
sky and slate. Of the drafts shown (current, results orange, equal
lightness, stronger tint) the owner picked results orange.

--k-results is #fdba74 in dark mode and #ea580c in light, deep enough
there to stand apart from memory's amber (#f59e0b). Colorblind mode
keeps its palette's --c5, as every other part does. Nothing else
changes: the tint, edges, text mixes and the other parts' colours.

Run (darwin): go test ./internal/gui ok; GUI in chromium and webkit:
context-map 22/22, routing-context-fold 24/24, context-window 24/24.
Not run: the whole GUI suite; no screenshot of light mode in the app.
2026-10-25 17:32:25 +08:00
yetone 1dfa284840 usage: a plugin's row of text alone shows its text, not "· 100% left"
AutoClaw's 积分余额, Cline's balance, Cursor's Auto + Composer note and
the other plugin rows that are only words come to magpie as a window set
aside with a display and nothing counted (used 0, no amount, no limit).
Every surface read that used 0 as a share: the usage card said
"1,234 积分 · 100% left" (or "· 0% used") beside an empty meter, the
panel drew an empty ring, the TUI an empty bar, `magpie accounts` and
`magpie quota` "积分余额 0% (1,234 积分)", and the status line
"积分余额 0%".

provider: QuotaWindow.Text (json "text") marks such a row in
quotaOfPlugin: aside, a display, used/amount/limit all 0. Aside is
required: Cursor's On-demand "$0 / $20" isn't set aside and is a real
0%. QuotaSpan carries it to /api/quotas.
GUI (app.js): quotaText gives the display alone; the account row's
meter, the Usage page's track and the panel's rings leave the row out;
a panel card with only such rows shows their text on its line, as an
Unlimited card does. The tray's menu-bar text already skips aside rows.
TUI quotaCell, the CLI's quotaCell (accounts, quota) and statuslineCard
write the name and the text.

app.js stays under its budget (1,322,289, not raised; now 1,322,275):
to make room, the 8 copies of Math.max(0, Math.min(100, x)) are one
to100(x), and 8 one-line [..].filter(Boolean).join("\n") tooltips are
tipLines(..). Same results; the GUI files below cover those callers.

Readings cached before this release have no text flag and show as
before until the account is read again (a minute's cache, or Refresh).

Run, at this commit's tree (rebased on origin/main 9dc7d6eb8):
- internal/gui/tests/quota-text-row.test.cjs (new): a text row alone
  and beside a counted window, through accountQuota, panelQuotaCard,
  quotaWindows and quotaText; chromium and webkit, en and zh: 4 of 4.
- the GUI files the change reaches (quota*, usage*, panel*, tray*,
  profile*, plugin-plan, plugin-quota*, plugin-panels, api-key-usage,
  claude-usage, gateway-key-quotas, glm/opencode-go quota errors,
  routing-quota-left, gui-de/ja/zh-TW, i18n-keys; 114 files, both
  engines, 4 wide, load 130 to 200): 1433 of 1467. The reds, rerun
  alone here and with 9dc7d6eb8's own app.js: quota-count-wrap (webkit,
  #3404 #2228), usage-agents-hide (#3414 #2276), usage-checkin's Qoder
  tab (webkit, #2549), usage-fold (#3415 #2163) and usage-ledger's
  return-to-live (#3104) fail the same at both; api-key-usage failed
  once 4 wide and passes alone at both (#3589).
- go test -timeout 45m ./internal/gui/ ./internal/cli/ ./internal/tui/
  ./internal/provider/: ok (TestCoreScriptBudget included).
- gofmt -l internal/ clean; go vet on darwin, linux (nogui) and windows
  for provider, cli, tui (and gui on darwin): clean.
Broken by hand:
- app.js at HEAD under the new GUI test: red, quotaText gave
  "1,234 积分 · 0% used" / "1,234 积分 · 已用 0%".
- quotaOfPlugin's Text line removed: TestPluginTextRowIsText red.
- the CLI's quotaCell at HEAD: TestQuotaCell red ("积分余额 0% (1,234 积分)");
  statuslineCard at HEAD: red ("autoclaw-plugin 积分余额 0% 5h 40%").
- the TUI's quotaCell at HEAD: TestTextQuotaCell red
  ("积分余额 ░░░░░░░░ 1,234 积分 · 0% used").
Not tried: a real AutoClaw, Cline, Cursor, Factory or ZCode account in
the app (fixtures follow the plugins' own window shapes); the full
`go test ./...` and the whole GUI suite; the Linux and Windows apps.
2026-10-25 17:26:38 +08:00
yetone 99de8e1ad1 gui: the warm-up's whole-history reads hold Go to the memory it held when they began (#3493)
A cold build of the request index (after any update that changes
internal/usage) reads every session again and allocates ~1.2 GB to keep
~40 MB more. Even under GOGC 25 the heap overshot its goal into pages it
kept, so a cold start peaked ~70 MB over a warm one. underTightGC now also
sets a soft memory limit at what Go holds of the system's memory when its
read begins (total mapped less released), and puts the old limit back
after. A lower limit the user set is kept, and GOGC off gets none.

Real data, 15.7k sessions (sbpairs: copies of the real cache/config, the
real Claude Code and Codex session folders linked read-only), harness
TestZZWarm running warmSteps under sessions.Warm, phys_footprint_peak,
old = 9dc7d6eb8, alternated:
  cold (requests-v1.bin removed): old 313/308/320/323 MB, new 251/241/247/249
  warm: old 247/255/250, new 211/225/228
  at rest after: unchanged (old 186-200, new 174-190)
  user CPU, cold run: old 4.8-5.9 s, new 6.0-12.8 s (load 120-200 on the
  box, wall time the same: 2.8-4.9 s vs 3.0-5.9 s)
Fixed 220/200 MB limits were tried first: 200 doubled CPU; a limit relative
to what is held scales to other histories.

Run: go test -count=1 ./internal/gui ok (132s); the first full run had one
red, TestRestartHandsTheGatewayOver (handover, #3451, commented), green 3 of
3 alone. GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gui ok,
gofmt clean.
Broken by hand, TestUnderTightGCLimitsMemory red each time: no limit set;
a limit under GOGC off; the user's lower limit replaced.
Not tried: Windows with real sessions (the box has none); a history much
larger than 15.7k sessions.
2026-10-25 17:14:38 +08:00
yetone 54b198c5c1 gui: a plugin's page grows to its README on a spring, not in one jump
A plugin's page (Plugins › Discover) opens with a skeleton for its
README, and when the README came in the dialog took its new height in
one frame. Now detail()'s fill() measures the dialog, puts the README
in, re-centres it (holdModal), and animates height and top together
from the old box to the new on SPRING, the curve the dialog opened on
(570ms, 1.5% over), clipped while it grows; the README fades in over
it. Height and top move on one curve, so the dialog keeps the middle
in every frame. The same for the error note when npm or GitHub
doesn't answer. Reduced motion: no animation, as before.

Budget: the core 1,530,050 -> 1,530,631, the 581 bytes of fill(), the
Plugins page's own, no room added.

Run at this head (rebased on 9277c2567):
- modal-centred-late.test.cjs, a new test sampling every frame from
  the README's arrival: heights in between the two and centred within
  2px in each frame, at 820px and 560px (README taller than the
  window), Chromium and WebKit: 12/12. With the plugin GUI files
  (plugin-market, -github, -local, -git, -folder-path, -own-icon,
  -card-update): 80/80 at 9dc7d6eb8, before the rebase onto two
  commits that touch Codex's card and the masking page only.
- go test -run Budget ./internal/gui ok; gofmt -l clean.
- Frames seeked to 0/80/160/280/570ms and looked at.

Broken by hand: fill() returning before the animation turns the new
test red in both sizes ("grew over frames: [674,674,674,674]").

Not run: the whole GUI suite and go test ./... (only plugins.js and a
test changed); not tried in the real app on WebKitGTK or Windows.
2026-10-25 17:08:20 +08:00
yetone 9277c25673 masking: under the number, the flow's middle takes the card's width, and sits further from the chart
The owner's screenshot of Insights › 脱敏 with the band stacked: the
animation stayed narrow, as each of the flow's three columns kept a
third of the card, and it sat 16px under the chart.

Under 780px the names now take what they need (fit-content, up to 150px,
120px under 640px) and the middle the rest; the gap is 28px. Measured in
Chromium, the middle's width before → after: 760px window 386 → 452,
640px 189 → 365, 560px 162 → 285, 480px 135 → 205. 820px and up (the
flow beside the number) is unchanged.

Run: screenshots at 760, 640 and 560 in Chromium and WebKit, before and
after; GUI masking-records 52/52, privacy-usage-stats 4/4, mask-actions
20/20, i18n-keys 4/4, click-scroll 22/22; privacy-model 23/24 in that
run, beside a Go test run, and 24/24 three times alone after it (the
failing test's name wasn't kept); go test -tags nogui -run Budget
./internal/gui ok.
Not tried: the whole GUI suite; the real Linux app (WebKitGTK).
2026-10-25 17:05:38 +08:00
yetone 3ee37aea64 gui: Codex's card has no subagent-model or memories square beside its settings rows
Codex's sheet has "Codex subagent model" and "Codex memories model" as
named rows (renderCodexSubagentModel, renderCodexMemories), just under
the card, and the card also drew a square for each: the same setting
twice (the owner, 10-25, a screenshot of the notebook square beside the
memories row). The squares are no longer drawn for the Codex those rows
read (id "codex", not gateway mode); they are left out of the extras
count and of the extras toggle too. A Codex in WSL, which the rows don't
read, keeps its squares.

Tests: codex-memories and codex-subagent-model run the square on a WSL
Codex and check Codex's own card has none; codex-subagent-model picks
and resets through #codexSubagentModelRow; codex-memories-settings
resets through the row instead of the square.

Run: GUI codex-memories, codex-memories-settings, codex-subagent-model,
codex-subagents-lead, desktop-subagent-model, Chromium and WebKit, every
language and width they have: 82 of 82. Earlier run of these plus
codex-start-model-field, subagent-effort, agent-prefs, agent-tweak-fold,
gateway-mode and mobile-web at concurrency 4: only the expected square
reds plus two page.goto/click timeouts under load (codex-subagents-lead
webkit zh-TW 560, desktop-subagent-model webkit zh 1100), both green in
the 82-of-82 run. After the rebase on origin/main the change was trimmed (one sq helper
for the extras toggle and count) and the budgets raised to its size:
app.js 1,322,537, core 1,530,050, with no room added (TestCoreScriptBudget
ok). Rerun at that tree: codex-memories, codex-memories-settings,
codex-subagent-model, agent-tweak-fold, gateway-mode, 58 of 60; the two
reds are gateway-mode's masking tab, red the same on origin/main
9dc7d6eb8 run alone (#3586). Not run: the full GUI suite or go test ./....
2026-10-25 17:04:02 +08:00
yetone 9dc7d6eb84 usage: a large build's archives are held in a spill file as they are made (#3493)
A cold build (first start, or after an update that changes internal/usage)
kept every chunk's archive on the heap until save had written
requests-v1.bin and swapped them for the file's pages: 31MB for 15.7k
sessions, the largest thing a cold peak held over a warm start's.

Now a build that wants requestDiskLeast or more files written writes each
archive to requests-*.spill as the chunk is made, lets go of the heap copy,
and maps the file once the build is done (unlinked at once). save then
swaps the spill's pages for requests-v1.bin's as before: pagesRank orders
heap < spill < file, and keep and save take the later. A spill that can't
be written or mapped has each of its chunks made again from its source, so
none is left without an archive. Windows maps no file, so nothing changes
there.

Run, real data (15.7k Claude Code + Codex sessions, sandbox HOME, copies of
the call shards, requests-v1.bin removed before each run), the gui warm-up
harness alternating old (cbbf3163c) and new, 4 rounds each:
  phys_footprint_peak old 396 353 346 352 MB, new 319 322 329 329 MB
  peak live (gctrace) old 209-259 MB, new 188-205 MB
  at rest unchanged (184-205 MB), warm-up time in the same range.
  gctrace: cold max live after mark is now 187MB against warm's 173MB; what
  is left of the gap is allocation churn (1.2GB allocated in the cold
  build against 280MB warm), not held data.
go test ./internal/usage ./internal/gui ok; -race -count=3 of the disk and
spill tests ok; GOOS=linux and windows go vet -tags nogui ok; gofmt clean.
Broken by hand: no spill put -> TestRequestDiskBuildSpills red; done not
making a chunk again -> TestArchiveSpillFailedMadeAgain red; the spill
ranked as the file -> TestRequestDiskBuildSpills red after the save.
Not tried: Windows (no mapping, path unchanged), a disk that fills while
spilling (the made-again path is covered by the unit test only).
2026-10-25 16:56:02 +08:00
yetone e4809a150a redact: a key of digits only after 密钥为, token 是, apikey:… is masked; PIN码, 安全码, 授权码 join the names (CyberCaius on Discord)
"密钥为12231241" in Settings → Masking's 试一试 came back "这里没有需要脱敏的
内容". ee715c2e0's key rules (a CJK name for a key or token, or an English
one before 为/為/是/:) asked for letters in the value, so that
"RSA 密钥为 2048 位" stays; an all-digit key went as written. 密码/口令 took
digits already (714ab8e8b).

Now:
- After a key's name and 为, 為, 是, :, :, =, は or 는, a value of six digits
  or more is masked as SECRET, by the CJK names (密钥, 秘钥, 令牌, 金鑰, トークン,
  토큰…) and the English ones (token 为, apikey:, API Key 是, secret 為).
  Not when a unit follows it (位, 字节, 个, 次, 秒, 毫秒, 天, ms, byte…), with
  no 为/是/: between (密钥 12345678), or under six digits.
- New names: PIN码, PIN碼, PIN 码, 安全码, 安全碼, 暗証番号, 비번 for a password
  (any value of four or more, digits too, as 密码 has); 授权码, 授權碼 for a
  key; pin and pin code before 为/是/: in English (six digits or more, a
  word boundary first, so "spin 是 …" stays). The CJK names are matched in
  any case (pin码).

Left as they were (tested): RSA 密钥为 2048 位, 密钥为 12345, 令牌有效期是 86400,
令牌是 300000 毫秒, 密钥长度为 4096000 位, token 是 3600000 ms,
key 是 1048576 byte, 令牌桶容量为 100000, 密钥 55661237, pin 为 1934,
const token = 44102939;, {"token": 44102939}, maxTokens: 128000, and every
case of TestCJKPasswordMasked, TestCJKSecretNamesMasked and 511c4a765's
code tests (code_test.go).

Run at this head:
- go test ./internal/redact ./internal/pii ./internal/settings
  ./internal/otlp ./internal/sessions ./internal/gui -count=1: ok
- go test ./internal/gateway -run 'CJK|Mask|Redact|Privacy|PII|Secret': ok
- go test ./internal/redact -run 'CJK|Code' -count=3 -shuffle=on: ok
- gofmt -l, go vet, GOOS=windows go vet, GOOS=linux go vet -tags nogui
  ./internal/redact: clean
- Broken by hand: with the parent's redact.go, TestCJKDigitKeysMasked
  fails 19 of its 21 masked cases (密码为/口令: already masked).
- With Shape on, 密钥为12231241 goes as a made-up 8-hex key and comes back.

Not tried: the GUI try box in a running magpie (no GUI file changed), and
the full suite.
2026-10-25 16:55:06 +08:00
yetone 4b1994ad31 agent: AionUi, added through its add-provider link
seven7032 on Discord asked how to connect AionUi to magpie. AionUi
keeps its providers in its own SQLite database
(<userData>/aionui/aionui-backend.db, WAL mode), each key encrypted, so
there is no config file for magpie to write. The one supported way in
is its deeplink. AionUi 2.2.2's main process parses it
(parseDeepLinkUrl), and its renderer opens Settings -> Model with the
add form filled in, which the user confirms:

  aionui://add-provider?api_key=magpie-aionui&base_url=<gw>/v1&name=magpie&platform=custom

The AionUi row works the way Cindy's and Lody's do:
- Add magpie opens that link. /api/open allows the aionui://add-provider?
  prefix only. `magpie aionui add` opens it from the CLI.
- The key is agentKeyAt("aionui"), so it becomes the LAN key while
  sharing is on (added to TestPinnedGatewayKeyForEveryWriter).
- "custom" is AionUi's OpenAI-compatible platform. Its base URLs end in
  /v1, as its own OpenAI preset's does.
- Added reads providers.base_url for the gateway's address without
  touching the database (sessions.OpenUntouched, from the previous
  commit). A database that can't be read is unknown, never "not added".
  The last read is kept while the database and its log keep their size
  and time, for 15s at most, so the Agents poll doesn't copy a running
  AionUi's database every time.
- It is detected by userData/aionui (os.UserConfigDir()/AionUi on every
  OS).
- As with Cindy and Lody, the TUI leaves the row out (nothing to pick).

Tests:
- TestAionUiLink: the link's exact bytes.
- TestAionUiLinkParsedAs2_2_2: runs the link through
  testdata/aionui/deeplink-2.2.2.js, which is parseDeepLinkUrl copied
  byte for byte from 2.2.2's app.asar (out/main/index.js 50995-51021)
  plus the renderer's add-provider mapping and the form prefill. The
  result is action add-provider, route /settings/model, and the form gets
  platform custom, the /v1 base URL and the key.
- TestAionUiHas: a fixture database built from 2.2.2's real providers
  schema (taken from the database 2.2.2 made at first start). It covers
  none, another gateway, a row present only in the log of a running app,
  and a closed app, and checks that AionUi's folder is unchanged each
  time.
- TestAionUiUnreadableIsUnknown, TestAionUiStatusRereadsOnChange,
  TestAionUiDetect, TestAionUiImportRow (GUI: the row, unknown status,
  and /api/open refusing other aionui:// links).
- import-row.test.cjs gains the AionUi row (icon, known status in each
  language, the click opens the exact link, and it fits at 420px), in
  chromium and webkit across en, zh, zh-TW, ja and de. The same file
  now waits for the rows to settle before its alignment check: under
  load 105 one run caught Cindy's button mid-resize at 193.4px beside
  the picker's 194.4px. The old file passed 3/3 alone, so it is a
  timing assumption, not a layout bug.

Run at 18041fc5b (this change on origin/main 714ab8e8b):
- go test ./... -timeout 45m, through the suite lock: every package ok
  except internal/proc's TestNoCommandBypassesProc, red on
  internal/tui/keep.go:102 from 75e78a5a0 on main (#3567, which has a
  fix on skygunner's fork).
- gofmt -l clean; GOOS=linux go vet -tags nogui ./... and GOOS=windows
  go vet of agent, gui, cli and sessions clean.
- import-row.test.cjs: 20/20 in chromium and webkit.
- The whole GUI suite (make test-ui, 882 files) was still running at
  push, so it is not recorded here.
Rebased onto cbbf3163c, which changes GUI assets and api.go. At the
pushed head: go vet of the four packages is clean; go test
./internal/gui ok; the AionUi, Cindy and pinned-key agent tests are ok.
import-row.test.cjs at load ~210: one run had 19/20, and that run's
output wasn't kept, so I can't name the failing case. The next three
runs were 20/20.

Tried: magpie built at this commit with -tags nogui under a sandbox
HOME. `magpie aionui` printed "magpie aionui add  to add magpie" with
AionUi's folder and no database. With a copy of the real 2.2.2 database
holding one row at the gateway's /v1, it printed "magpie added".

Broken by hand:
- Dropping the aionui prefix from /api/open: TestAionUiImportRow red
  ("AionUi's link was not handed to the desktop").
- The reader put back to a plain mode=ro open: TestAionUiHas red
  ("AionUi's folder changed: aionui-backend.db ->
  aionui-backend.db,aionui-backend.db-shm,aionui-backend.db-wal").
Both were restored and are green.

Not tried: the add form, the saved row and gateway traffic. The
released AionUi 2.2.2 desktop app asks for an aionui.com sign-in before
any page, Settings included. That sign-in was not faked, and no
aionui.com account was available, so the link has never been opened in
a signed-in AionUi end to end. Also not tried: what AionUi saves for
platform custom when it is confirmed, AionUi's User-Agent (so none is
matched), and the aionui:// handler on Linux and Windows (Electron's
setAsDefaultProtocolClient, unverified there).
2026-10-25 16:49:29 +08:00
yetone c26a418d23 agent: an import app's status magpie can't read is unknown, not "not added"
Agent.Added now returns (added, known). Cindy's reader turned any
failure (a locked, corrupt or unreadable cindy-local-v1.db) into "Not
added", which told a user who had added magpie that they hadn't. Now
an unreadable database is unknown: /api/agents leaves `added` out and
the row shows the "confirm it there" hint, as it does for Lody. A
stopped WSL distro's app is unknown too, not "not added".

Cindy's database is also read without writing beside it. A mode=ro
open of a WAL database while Cindy was closed made cindy-local-v1.db-wal
and -shm in Cindy's own folder. It now goes through
sessions.OpenUntouched, which is what the Cursor reader already did
(immutable with no log, from a copy with one), moved out of
openCursorStore so both share it.

The CLI's list still offers `magpie cindy add` when the status is
unknown; it never said magpie was missing.

Run: go test ./internal/agent ./internal/sessions ./internal/cli ok;
go test ./internal/gui -run 'Import|Lody|Cindy|Agents' ok.

Broken by hand: Cindy's reader put back on the mode=ro open made
TestCindyHasClosedWALAndUnreadable red ("Cindy's folder changed:
cindy-local-v1.db -> cindy-local-v1.db,cindy-local-v1.db-shm,
cindy-local-v1.db-wal"); api.go ignoring `known` made
TestImportStatusUnreadableIsUnknown red. Both restored, both green.

Not tried: a real Cindy install; the read is tested on fixture
databases only.
2026-10-25 16:49:29 +08:00
yetone faa79ea2f5 redact: a Unix time the local model takes for a phone is not masked (#3577)
id.null (v0.1.1483) saw a tool result's "timestamp": 1792903687 go as
"timestamp": {{PHONE_c2ukh7gk}}. The PHONE rule needs eleven digits, so
the local model found it; v0.1.1457's check leaves a bare number alone
unless a cue is before it, but cues match inside words, and a log's
"tool_call" (or "telemetry") is "call" (or "tel").

A ten-digit time, or a thirteen-digit one in milliseconds, starting with
1 and nothing else, is now never a phone, cued or not: a North American
area code starts with 2 to 9, and a Chinese mobile is eleven digits.
The loose cues themselves are #3585.

Run: go test ./internal/redact ok; go vet darwin, linux, windows; gofmt
clean. Broken by hand: without the epochNumber check
TestModelPhoneKeepsUnixTime is red with the reporter's line masked.
Not tried: the real model on the reporter's whole tool result (their
screenshot only has the one line); the full Go suite.
2026-10-25 16:48:07 +08:00
yetone fc91e58ba4 redact: a bare JSON number ("timestamp": 17929036837) is not masked as a phone (id.null on Discord)
The 脱敏 before/after view showed a tool result holding a session file's
JSONL line, and its "timestamp": 17929036837 went as {{PHONE_…}}. The
PHONE rule is 1[3-9]\d{9} bounded by digits, so any 11-digit number
starting 13-19 is a CN mobile wherever it sits. A phone, a card or an ID
number in JSON is a string; a bare number there is a count, an id or a
time.

Now a personal kind's value that is all of a bare JSON number is left,
judged by where it sits and its form, not by the key's name: digits only,
after "key": (an object's value) or inside an array of numbers, with only
, } ] or the text's end after it. It sits beside the decimal check
(noDecimals, now noNumbers), so it holds for what the rules, the model
and values known before find alike. A BANK_CARD (Luhn-valid snowflake)
and an ID_CARD's digits as JSON numbers are left the same way.

Still masked (tested): "phone": "13800138000", ["13800138000"],
phone:13800138000, "call 13800138000, thanks", 我的号码 13800138000,谢谢,
"numbers 13900139000, 13800138000]" (no [ before), a phone inside a JSON
string's text, "card": "4111111111111111", and every case of
TestStandaloneNumbersStillMasked. "phone": 13800138000 as a number is
left too; that is the cost of not going by the key's name.

Run at this head:
- go test ./internal/redact ./internal/pii ./internal/settings
  ./internal/masking ./internal/otlp ./internal/sessions ./internal/gui
  -count=1: ok
- go test ./internal/gateway -run 'CJK|Mask|Redact|Privacy|PII|Secret': ok
- gofmt -l, go vet, GOOS=windows go vet, GOOS=linux go vet -tags nogui
  ./internal/redact: clean
- Broken by hand: with origin/main's redact.go, TestBareJSONNumberNotMasked
  fails 7 cases (the reporter's line, {"n": 13800138000}, a spread-out
  object, two arrays, the card and the ID number). The 10- and 13-digit
  epochs were not masked before either; they are in the test to stay so.

Not tried: the GUI before/after view in a running magpie, and the full suite.
2026-10-25 16:47:29 +08:00
yetone 0152f66966 provider: a Remote magpie's model list follows the other magpie's, fetched every 10m (6igsteven on Discord)
6igsteven (Discord, 10-24/10-25): GLM-5.3-Trial and GLM-5.3-Flash-Trial
are listed on the magpie that runs the ZCode plugin, and not on the
magpie that uses it as a Remote magpie. The trial entries come from the
ZCode plugin once it reads the account's gift (zcode 0.1.26), and the
other magpie's /v1/models lists them as it lists every catalog entry.
But a Remote magpie is a provider of keys: its list was fetched when it
was added and then only when Fetch models was pressed in its editor
(KeepListsFresh asks only providers with a RefreshEvery, FetchNew only
accounts). So anything listed there later (the trial models, a new
provider, plugin or routing group) never reached this magpie.

A Remote magpie with no RefreshEvery now has a 10m schedule
(RemoteMagpieEvery, RefreshSchedule), so KeepListsFresh refetches it
through the same Refetch as Fetch models. `magpie provider refresh-every
<id> off` on a Remote magpie is kept as "off" rather than "" so the
user's off isn't read as unset. CLI show/refresh-every print the
schedule in force. Other providers are unchanged: no schedule means
only when asked.

Run: TestRemoteMagpieListFollowsTheOtherMagpie (new) with
TestKeepListsFreshFetchesWhatIsDue, TestParseRefreshEvery,
TestSaveKeepsTheListsScheduleAndRules: ok, sandbox HOME, Go caches
pinned. Broken by hand: RefreshSchedule returning RefreshEvery alone
(the old behaviour) fails the new test with "asked [], want [office]";
restored, ok. gofmt -l clean.
Then, at this commit: go test ./internal/provider ./internal/cli ok
(140s, 58s); go vet ./... on darwin, GOOS=linux -tags nogui and
GOOS=windows ok; darwin, linux (nogui) and windows builds ok.
Not run: go test ./... - the machine's disk had under 1GB free
(other sessions' work) and load ~200, so a full suite would not fit.
Not tried: a real two-computer setup with a live ZCode gift. A Remote
magpie whose user curated its picks (left a listed model unpicked)
still doesn't take new models by itself (withNewlyListed, by design).
2026-10-25 16:30:48 +08:00
yetone c490165b14 gui: a menu of actions keeps no empty tick column, so its items line up with its heading
Sessions' "Continue in" menu (a screenshot from the owner) drew each
agent's logo and name about 21px right of its heading. The menu is a
list of actions with nothing ticked, but the shared menu reserved its
14px tick column anyway. The same happens in Usage's "Count this
client's calls as", Library's "Copy config…" and Routing's "Add a
condition".

app.css now hides .pm-tick in a menu with no ticked item and no
checkbox item. A choice menu (something ticked) and a multi-pick menu
(menuitemcheckbox, where a tick can appear later) keep the column. The
rule is CSS only: an app.js version put the core 209 bytes over its
budget, which is not raised for this.

Run at cbbf3163c + this:
- sessions-convert, usage-count-client, library-mcp-copy-config,
  purpose-filter, routing-purpose-state, routing-request-metrics: 46/46
  (Chromium and WebKit, every language the files run)
- go test ./internal/gui -run Budget: ok
- measured: the logo went from x=571 to 550, the heading's text start

Broken by hand: the old app.css fails sessions-convert's new "the logo
lines up with the heading (571 vs 550)" in Chromium and WebKit.

Not tried: the whole GUI suite (load ~270 and a nearly full disk on the
machine), and the real Linux (WebKitGTK) and Windows apps.
2026-10-25 16:30:29 +08:00
yetone cbbf3163cb usage: a cold build's chunks are of the file's pages once it is written (#3493)
A start that reads requests-v1.bin keeps each chunk's archive in the
file's mapped pages, not on the heap. A start that builds the chunks
(a cold one: no file, or one of another build) kept the archives it
encoded on the heap until the next start, after writing the very same
bytes to the file: 32-40MB for 15.7k sessions, and a resting heap
~50MB over a warm start's.

Once save has written the file, onDisk maps it and makes, for each
chunk whose archive is of the heap, a copy whose archive is the same
bytes of the mapping (checked equal). save swaps it in for the chunk
of the same serial: a read since has copied the chunk with a use of
its own, so the pointer it wrote is gone by then. A read that copied
the chunks before the swap and finishes after it keeps the mapped
archive (keep), or it would put the heap one back. Nothing changes
where no file is mapped (Windows).

diskUnmapped, the tests' hook, is an atomic.Pointer: a mapping's
cleanup reads it on its own goroutine while the next test sets it,
which -race -count=4 caught once the new test let go of mappings.

Run at this tree (67a137744 + this change):
- go test -count=1 -timeout 45m ./internal/usage/ ./internal/sessions/:
  ok. go test -run 'Warm|Session|Request|Usage' ./internal/gui/
  ./internal/gateway/: ok.
- go test -race -count=4 -run TestRequestDisk ./internal/usage/: ok,
  six times in a row.
- GOOS=linux and GOOS=windows go vet -tags nogui ./internal/usage/: ok;
  gofmt -l clean.
- TestRequestDiskBuiltChunksMapped holds the write while a second page
  copies the chunks and a third copies them before the write and keeps
  them after it. It went red (0 of 4 mapped) with the swap matched by
  pointer instead of serial, and with keep not carrying the mapping.
- The real warm-up (gui warmSteps in sessions.Warm) on a copy of the
  owner's ~/.claude and ~/.codex sessions, cold (requests-v1.bin
  removed), parent and change alternating, 3 runs each, measured 5s
  after the warm-up:
  - heap at rest: 200/200/198MB before, 154/148/152MB after;
  - phys_footprint at rest: 233/234/237MB before, 198/197/205MB after;
  - phys_footprint_peak: 361/396/347MB before, 335/367/378MB after,
    the same within noise (the build itself is unchanged).

Not tried: Windows (it maps no file, so it is unchanged there).
2026-10-25 16:19:18 +08:00
yetone 359da679db redact: 试一试 shows the made-up key when "keep key form" is on, short keys and named keys too
A user turned on 保留密钥格式 (v0.1.1497) and 试一试 still showed
{{SECRET_…}} for "用密钥 sk_abcdefg 部署可以吗". Three gaps:

- Preview wrote every value with tag, which never looked at Shape: a
  sibling v0.1.1497 missed. It now makes the same key shapeOf gives a
  real request, without storing it.
- shapeOf made up nothing under 16 characters, so sk_abcdefg stayed a
  placeholder even on a real request. Now 8 or more, with at least 6
  characters made up after the prefix.
- 密钥 OPENAI_API_KEY=sk_… is found with its name (the CJK key rule
  takes NAME=value as the value), and '=' isn't a key character, so it
  fell back to a placeholder. The name now stays as written and only
  the key after it is made up and remembered, so a reply naming the key
  alone is put back too.

Run: go test ./internal/redact ./internal/settings, -tags nogui
./internal/gui, ./internal/gateway -run 'Redact|Mask|Shape|Privacy' all
ok; go vet darwin, linux and windows (nogui); gofmt clean.
Broken by hand: Preview back to tag, minShape 16, the minRandom check
removed and splitName turned off each turn TestShapeShortAndPreview,
TestShapeKeepsAName or TestMaskingPreviewKeepsKeyForm red; storing the
whole NAME=value turns TestShapeKeepsAName's Restore red.
Not tried: the GUI suite (no front-end change) and a real model's reply
naming the made-up key; the full Go suite.
2026-10-25 16:16:27 +08:00
yetone 894ec96036 plugins: "More in Plugins" opens Discover, not the tab visited last (outloudvi on Discord)
On Providers, 「插件里还有更多」 / "More in Plugins" opened whichever
Plugins tab was visited last (Built-in, Installed). pluginQuery("")
returned early when the query was already empty, before it set the
tab to Discover. The early return is gone, so an empty query also
switches to Discover; a non-empty one already did.

plugins-more-discover.test.cjs visits Built-in, then Installed, in en
and zh, goes back to Providers and clicks the add sheet's More in
Plugins tile, expecting Discover with its cards and no Built-in list;
then the "look for a plugin" link with a search, expecting Discover
with that search.

Run:
- plugins-more-discover.test.cjs, chromium and webkit: 3 of 3 green.
- 61 GUI files the change can reach (plugin-*, plugins-*, builtins,
  deprecat*, add-sheet*, provider-search*, i18n-keys, nav-sub-unroll,
  mobile-web, market-have, sidebar-tab-top), both engines: 412 pass,
  1 fail each: builtins.test.cjs's sidebar list lacks the masking
  tab, red the same with the old plugins.js (#3498).
- go test ./internal/gui/ -count=1 (budgets included): ok but
  TestMainWindowCorners/macOS_15_SDK killed at load ~200 (#1936,
  #2645); alone it passes.
- At the rebased head (b28e5ffd8): the new test and i18n-keys green in
  both engines, go test -run Budget ok.
- No bytes added: core and app script budgets untouched.

Broken by hand: with the early return put back, the new test is red
in both engines (expected Discover, got Built-in; expected 发现, got
内置).

Not tried: the tray panel's link, which opens the main window through
window/main?view=plugins and still shows the last tab (#3579, a
sibling); the full Go suite (no suite-lock.sh on this machine).
2026-10-25 16:00:21 +08:00
yetone b28e5ffd81 gateway: an array with no items goes to Antigravity with items {}, and Google's schema 400 falls through (plugins#375)
gcq909893267 (plugins#375): Claude Desktop's own MCP tools __batch and
__guide declare an array property with no items ("batch":{"type":
"array"}). plainSchema passed it through, and Google turned the whole
turn away: 400 "GenerateContentRequest.tools[0].function_declarations
[17].parameters.properties[batch].items: missing field". The group's
next member was never asked.

- plainSchema (codeassist.go): every node it writes that is type array
  with no items gets items {}, which Google takes (the reporter's A/B:
  {} and {"type":"string"} both 200). Its walk is the one every nested
  place goes through (properties, items, anyOf/oneOf members, allOf,
  $ref into $defs/definitions, a type list with null), so the check at
  the end of a node covers all of them.
- Siblings: plainSchema is the only Gemini-side schema cleaner. Gemini
  CLI's Code Assist and Vertex AI / a custom Gemini API go through the
  same buildCodeAssistSent but send parametersJsonSchema, full JSON
  Schema, where an array with no items is valid; gemini.go's jsonSchema
  is the other direction (a Gemini client's schema read in). Left as
  they are.
- Fall-through: a 400 that points at a function declaration's
  parameters (function_declarations[N].parameters) is now in
  shapeWords, so shapeRefused/retryable read it as the request's shape
  on that vendor: the next member is asked once, and the member doesn't
  rest (Fail "shape", Rest nil), as OpenCode Go's "schema exceeds the
  maximum nesting depth" (#1870). Not resting is right: the account is
  fine and the same request fails the same on every Antigravity
  account; the reporter's same tools answered 200 on a non-antigravity
  member. A declaration's name or the contents are not matched. A
  shape refusal still tries the same provider's next account first, as
  every shape refusal does now; not changed here.

Tests (antigravity_array_items_test.go), fixtures from the reporter's
literal request and error line:
- TestAntigravityArrayGetsItems: the reproduction through
  buildCodeAssist(antigravity); both declarations carry items {}.
- TestPlainSchemaArraysAllHaveItems: nested arrays under each keyword
  get items {}, an array with items keeps them, a non-array gets none.
- TestGroupFailsOverGoogleSchema400: a group's first member answering
  Google's 400 hands it to the second, Fail shape, no rest; plus a
  shapeRefused table (Google's both wordings, the agent-facing wrapped
  form; a function name and contents error, and a 500, are not).

Run: go test ./internal/gateway/ -run 'CodeAssist|Codeassist|Gemini|
Schema|Antigravity|Shape|FailsOver|Fallback|Region|Retryable|Refus|
Vertex|Plain|Google' ok (307 tests, 31s); gofmt -l clean; go vet,
GOOS=linux go vet -tags nogui, GOOS=windows go vet on internal/gateway
clean.
Broken by hand: codeassist.go reverted, the first two tests FAIL
(declaration 0 parameters.properties.batch: {"type":"array"}); fallback.go
reverted, TestGroupFailsOverGoogleSchema400 FAILs (a 1, b 0).
Not tried: a real Antigravity account (the reporter's own A/B shows
items {} answers 200); the full go test ./... suite; Gemini CLI and
Vertex AI with an items-less array against the real APIs.
2026-10-25 15:56:16 +08:00
yetone 67a137744f sessions: a call shard is written in frames of 2048 calls (#3493)
writeCalls wrote a shard's whole state as one frame, whatever its
size. The largest Codex session on the test copy (52,500 calls) was one
8MB gob frame, and decoding it allocated ~100MB and held ~70MB at once,
which is most of the gap between a cold warm-up's memory peak and a
warm one's.

A write now splits its patches into frames of framePatches (2048).
Every frame but the last has More set, and each carries Calls, the
file's call count after the write, so loadCalls sizes its slice once.
A file whose last frame has More was cut off mid-write and reads as
nil, the same as a bad CRC. A shard read from a frame over
framePatches (the old format) is written again in frames once, at its
first load (loadKept), so existing caches shrink their peak too.

Run at this tree (04439c859 + this change):
- go test -count=1 -timeout 45m ./internal/sessions/ ./internal/usage/:
  ok; go test -run 'Warm|Session' ./internal/gui/: ok.
- GOOS=linux and GOOS=windows go vet -tags nogui ./internal/sessions/:
  ok; gofmt -l clean.
- TestCallsWrittenInFrames (frames 2048/2048/100, a file cut after the
  first frame reads nil, an old one-frame file loads and is rewritten)
  went red with each of: no More check, no rewrite, no Calls presize,
  no split.
- The real warm-up (gui warmSteps inside sessions.Warm) on a copy of
  the owner's ~/.claude and ~/.codex sessions, 15,719 shards / 118MB,
  alternating parent and change:
  - cold (requests-v1.bin removed): phys_footprint_peak 418/462/406/
    454MB before, 355/399/328MB after; allocated in step 2 ~1790MB
    before, ~1575MB after; step 2 2.2-4.9s before, 1.8-2.1s after.
  - the first run after the change, which rewrites the old shards:
    424MB peak, 2161MB allocated, 3.4s step 2 (once).
  - warm: peak 366/372MB before, 295/330MB after.

Not tried: Windows with real session data (the box has none).
2026-10-25 15:55:54 +08:00
yetone 3e400b6346 gui: the tray's refresh keeps its place in Chinese (#3569)
The tray card's own refresh was appended inside .pq-sub, a nowrap line
with overflow hidden and an ellipsis. In Chinese the deadline line
("重置于 … · 按此速度,预计 … 用完") is longer than the card, so the
ellipsis ate the refresh and its hitbox. English fits, so it was fine
(kekao on Discord, v0.1.1486). The error line had the same fault: an
error past its 2-line clamp clipped its refresh (de, a long ZCode error).

Now each tray line that carries a refresh (deadline, error, Unlimited)
is built by pqLine: the words sit in their own .pq-say span that
shortens with an ellipsis (or clamps to 2 lines for an error), and the
refresh is a flex: none item at their end. Nothing else moves; a closed
refresh is still 0 wide.

Run, at the worktree head on 4dfd88206:
- new internal/gui/tests/panel-refresh-long-line.test.cjs: en, zh,
  zh-TW, ja, de x 486/420/360px x Chromium and WebKit, 30/30 pass. For
  each card it hovers, checks the refresh is inside the card and is
  what elementFromPoint hits at its centre, clicks Codex's refresh and
  checks the POST. On the old assets (MAGPIE_QUOTA_ASSETS) 20/30 red,
  zh 420/360 in both engines and de 420's error refresh among them.
- 83 GUI files a tray card can reach (panel-*, quota-*, tray-*,
  codex-*, usage-card-refresh, usage-remote-*, gui-de/ja/zh-tw,
  i18n-keys, text-size, refresh-page and more): 996 tests, 993 pass.
  The 3 reds: quota-count-wrap's WebKit 1100px count is cut, on the
  old assets too (open as #2228 / #3404); tray-usages (ja) and
  usage-card-refresh (zh) timed out launching a browser at load ~155,
  and both files pass 16/16 and 100/100 when run again.
- go test ./internal/gui/ ok (TestCoreScriptBudget: app.js 1321987,
  under its 1321994 budget, not raised); gofmt -l clean.

Broken by hand: without `.pq-line > .quota-refresh { flex: none; }`
the new test is red in every language. A `min-width: 0` on .pq-say
was taken out: with it removed the test stayed green (overflow hidden
already gives a flex item a 0 minimum), so it guarded nothing.

Rebased on origin/main 492847818: TestCoreScriptBudget ok again (app.js
1322282), and the new test, panel-quota-refresh and i18n-keys 54/54.

Not tried: the real tray app on macOS/Windows/Linux (WebKitGTK); the
whole GUI suite (another session's suite held the machine).
2026-10-25 15:55:11 +08:00
yetone 492847818b provider: moved ZCode, Cursor, WorkBuddy and Qoder users get the plugins' latest fixes
Mover mins raised to the versions npm has at landing (npm view
--prefer-online): zcode 0.1.28 (plugins #369, #379), cursor 0.2.22
(#377), workbuddy/workbuddy-ai 0.1.34 (#337, #378, #346), qoder/qoder-cn
0.2.36 (#323, #378, QwenWork #319). keepMovedCurrent updates every moved
user's plugin to them.

Run: go test ./internal/provider/ ok (152s); gofmt -l clean.
Not tried: a real move or upgrade on a real account; the plugin fixes
themselves were reviewed and tested in the plugins repo, not against
the vendors' APIs.
2026-10-25 15:47:26 +08:00
yetone bea9f905d0 redact: a key can go as a made-up key of its own form, not a placeholder (Charles Cao on X)
Charles Cao on X (2114238140835844575) asked for a format-preserving
swap: sk_w3axCByTQgK1PxqPhfKTrJOLBqz6sbZv sent as another sk_ key of the
same shape and put back on the way home. With Mask secrets on, a key went
as {{API_KEY_xxxxxxxx}}, which a tool's check of the key's form fails
and a model may remark on.

Settings › Privacy has "Keep a key's form" under Mask secrets (shown only
while secrets are masked; off by default, so nothing changes for anyone
who doesn't turn it on). settings.RedactShape → redact.Options.Shape;
api.go keeps it when a page from before doesn't send it.

How (internal/redact/shape.go):
- Only a secret's kind, 16+ characters, all of [A-Za-z0-9-_.]. Personal
  data, the user's words and anything else still go as placeholders. A
  made-up key needs no JSON escaping.
- Prefix kept (sk-proj-, sk-ant-api03-, github_pat_, AKIA/ASIA, or up to
  4 letters plus - or _), same length, separators in place, and each
  other character a random one of the same class. A hex key stays hex
  of its case. Random from HMAC(placeholder key, kind+value), so it is
  the same every turn and a vendor's prompt cache still matches.
- Kept in values like a placeholder (makeRoom shared with placeholder),
  so masking records, Value(), signed-thinking re-masking (the put
  closure) and known-value re-masking work unchanged; kindOf reads it.
- restore() puts made-up keys back first, then placeholders.
  RestoreJSON no longer returns early when one is in the body;
  hasShapes copies nothing while none was made.
- A stream holds an event's end that may start a made-up key
  (partialTail → shapeTail), but never one inside a key that has come
  whole: a key ending in "s" is also the start of every sk_ key, and
  without that its end was held and the key went out unrestored (found
  as 1 in ~40 fresh processes; 0 of 150 after).
- apply() leaves a made-up key that came back unrestored alone
  (outsideShapes), as it does a placeholder.

Tests: shape_test.go — form kept (the reporter's key, hex, ghp_,
sk-proj-), same fake twice, Restore; off is placeholders; email/short/
odd values not shaped; MaskJSON then RestoreJSON with escaped tool
args; signed thinking re-masked to the same fake; no re-mask of a fake;
a stream split mid-key, after one character, and a key ending as one
starts. GUI: redact-shape.test.cjs (both engines, 5 languages, 1100 and
640px; row under Mask secrets, Off by default, one save with the rest
kept, no scroll, a later save keeps it; no row while secrets are off).
redact-words-any-case now finds Mask personal data by place after the
new row, not by index.

Broken by hand, each red: no restoreShapes (KeepsForm, JSON, Stream),
no shapeTail (Stream), no outsideShapes (JSON), no hasShapes (JSON),
put ignoring Shape (all three), shapeTail without the whole-key bound
(Stream).

Budgets: app.js 1,321,994 → 1,322,289 and the core 1,529,542 →
1,529,837, the row's 295 bytes, Settings' own row, no room added.

Doc: docs/subsystems/gateway-routing.md, a bullet beside the other
masking options.

Run at 4dfd88206 + this change (worktree key-shape):
- GUI (node --test, playwright 1.62.0, both engines): redact-shape
  22/22, redact-words-any-case 20/20, i18n-keys 4/4, privacy-model
  24/24, redact-kinds 22/22, mask-actions 20/20, masking-records
  52/52, provider-proxy 8/8, click-scroll 22/22.
- go test -tags nogui ./internal/gui ./internal/redact
  ./internal/settings: ok (internal/masking has no tests).
- TestShapeStream in 150 fresh processes: 0 red.
- Rebased on 04439c859: budget tests, internal/redact,
  internal/settings ok; gofmt clean; vet -tags nogui on darwin, linux
  and windows ok; i18n-keys 4/4.
- Earlier, at load ~40: account-discovery 22 red, red the same on
  origin/main defbb1a15, #3497 (ggbdpq has it); redact-rule-edit
  webkit zh-TW 420px red once, 3/3 alone, #3407.
- The full suite was not run before this push: it is queued behind
  other sessions' suites (one per machine).
Not tried: a real vendor turn with the setting on.
2026-10-25 15:35:52 +08:00
yetone 04439c8592 sessions: the warm-up lists the Codex rollouts once for all its reads (#3493)
The warm-up at start ran three reads within about two seconds: the
stats of every day, the stats of 30 days and the Requests page. Each
listed every Codex rollout again through codexFiles, about 12k lstat()s
and ~47 MB allocated a time. codexFiles now keeps its listing while
only the warm-up reads (quiet: inside Warm, no page asking) and for 10s
at most, the age statsFor's memo already answers with. Each caller gets
its own copy. A page asking meanwhile, and every read outside the
warm-up, lists fresh, and Warm drops the kept listing when it ends.

Measured on the owner's real sessions (sbpairs: Claude Code and Codex
history, warm index), the gui warm-up harness inside sessions.Warm, run
alternately with the parent b686a8dfe, three runs each:
  allocated through step 3: 990/826/811 MB -> 751/732/734 MB
  step 1 (stats of 30 days): 436/134/114 ms -> 65/57/57 ms
  peak live heap: 170/163/160 MB -> 157/153/153 MB
  phys_footprint_peak: 259/242/234 MB -> 233/250/250 MB (no change)
Step 2 and the whole warm-up time are within noise.

Run at this tree (b686a8dfe + this change):
  go test -count=1 -timeout 45m ./internal/sessions/  ok
  go test -count=1 -timeout 45m ./internal/usage/  one red,
    TestUsageReadAfterAppendHashesNothingOnAFineClock/whole-second_stamp,
    which is #3511/#3551; alone -count=5 it passes. That path never
    enters Warm, so it never takes the kept listing.
  go test -count=1 -run 'Warm|Session' ./internal/gui/  ok
  GOOS=linux and GOOS=windows go vet -tags nogui ./internal/sessions/, gofmt -l: clean
Broken by hand: codexFiles always listing fresh makes
TestWarmUpListsRolloutsOnce red ("warm-up listed again"); handing back the
kept slice itself instead of a copy makes it red ("a caller's change
reached the kept listing").
Not tried: Windows (the box is unreachable over ssh).
2026-10-25 15:29:58 +08:00
yetone ee715c2e0e redact: a key or token after 密钥, 令牌, 金鑰…, or apikey/token before 为/是/:, is masked (CyberCaius on Discord)
714ab8e8b masked a password after 密码/密碼/口令/パスワード/비밀번호. The reporter
came back with the rest of how a secret is sent in a Chinese chat: "密钥为 xxx",
"apikey 为 xxx", 密钥是, 秘钥, 私钥, 令牌, "token 是 xxx", "API Key 为 xxx". These
went to the vendor as written.

Now:
- A value after a CJK name for a key, secret or token is masked as SECRET:
  密钥, 密鑰, 秘钥, 秘鑰, 私钥, 私鑰, 金钥, 金鑰, 令牌, 权杖, 權杖, 秘密鍵, トークン,
  シークレット, APIキー, アクセスキー, 토큰, 비밀키, API 키. The value has letters and
  digits both, or is 16+ characters with a letter, so "RSA 密钥为 2048 位" stays.
- An English name (password, passwd, pwd, secret, token, api key, access key,
  private key, credential, key; DB_PASSWORD and access_token too) right before
  为, 為, 是 or a full-width colon is masked the same way. "token: x" with an
  ASCII colon stays the config rule's, as before.
- 为 and 為 join :, :, =, 是, は, 는 after any CJK name, so "密码为 hunter22" is
  masked too; 암호 (Korean) joins the password names.

Left as they were (tested): 请输入密钥, 请输入密钥:, 密钥管理, 忘记密钥了怎么办,
令牌桶算法, 私钥文件放在哪, 密钥:${API_KEY}, 密钥:****, token 是 ****,
apikey 为 ${OPENAI_API_KEY}, RSA 密钥为 2048 位, token 是 expired, 这个 key 是 value,
token 是 abc, key 是什么, API Key 为空, and every case of TestCJKPasswordMasked.

Cost: the English rule is run only near 为/為/是/: (fold, 24 bytes back,
260 ahead), and the CJK rules only near their names. Doing that showed that
matches() looked back for the line's start from every fold marker through
the whole text, which is quadratic on a one-line request body: with the
English rule folded on key/token, Mask over 1.5MB of dense text took 10.4s
(0.12s before). The line's start is now looked for no further back than
`back`, which is what the window used anyway. Benchmarked Mask on 156KB of
dense Chinese, of dense code+JSON, and on redact.go itself, against
origin/main: within noise of it on a box at load ~200 (zh 31-36ms vs 13-37ms,
code 72-84ms vs 55-72ms, src 12-14ms vs 24-36ms); benchmark not committed.

Run at this head:
- go test ./internal/redact ./internal/masking ./internal/otlp ./internal/pii
  ./internal/settings ./internal/sessions -count=1: ok
- go test ./internal/gateway -run 'CJK|Mask|Redact|Privacy' -count=1: ok
- gofmt -l, go vet ./internal/redact, GOOS=windows go vet ./internal/redact: clean
- Broken by hand: with origin/main's redact.go, TestCJKSecretNamesMasked fails
  16 of 19 masked cases and the JSON body case (账号密码 admin123 and 口令是 …
  were already masked). With the CJK rules' window back set to 0,
  "WiFi密码:20261025" and "admin密钥是k9j8h7g6f5" go unmasked (fixed with back 64).

Not tried: the GUI try box in a running magpie, and the full suite.
2026-10-25 15:27:39 +08:00
yetone b686a8dfec sessions: a call shard's frames are read into a buffer kept between shards (#3493)
A cold Requests build (the first start after an update that changed the
usage package's source, so the request chunks are made again) reads
every call shard, ~15.7k on the real data copy. Each frame was read
into a new byte slice and decoded into a new callFrame, so gob made a
new Patches and Strings slice for every one. loadCalls now takes a
frameBuffer from a pool. gob decodes a slice that has room in place,
and leaves a field of the zero value as the field was, so each patch
and string of the last frame is cleared before the next is decoded in.
Nothing read out points into the buffer: gob copies strings and byte
slices, and a patch's call is copied into the file's calls.

Measured on the real data copy (sbpairs), warm-up harness TestZZWarm,
requests-v1.bin removed before each run so every run is a cold build,
three runs each:
  allocated through step 3   2139/2214/2182 MB -> 2001/2041/2044 MB
  loadCalls (cum, step 2)    781 MB -> 583 MB
  peak footprint             374-441 MB -> 371-419 MB, within noise
Warm starts unchanged (step 2 ~690 MB either way).

Run at this head: go test ./internal/sessions ./internal/usage ok;
-race -count=2 of the LoadedCalls, CallCache, Shard and Frame tests ok;
GOOS=linux and windows go vet -tags nogui ./internal/sessions ok; gofmt
clean. TestLoadedCallsKeepNothingOfTheLastShard reads a shard with
tokens, a session and a compaction, then one with none, three times;
broken by hand (the patches not cleared) it fails.

Not tried: Linux and Windows real-data runs.
2026-10-25 15:18:40 +08:00
yetone ba301e98e2 usage: a page's passes over the chunks decode into buffers kept between them (#3493)
Each pass of a Requests page over every chunk (foldCodexRows, the
response pairs, visibleLocal, matchedBlocks, visit, partsOf, newest,
rowsOf) started a chunkRows with no buffers and grew its rows, strings,
shapes and decode buffer from nothing. A warm start's All page and
Codex's effort after it read the same rows pass after pass, ~30 MB a
pass. chunkRows now takes a rowBuffer from a pool, unpacks into it
(unpackReusing gets a dst chunk too, so the open chunk isn't allocated
each block), and gives it back on release, its strings cleared so no
row text is held.

Measured on the real data copy (sbpairs: 12k Codex rollouts and the
Claude projects), warm-up harness TestZZWarm, each binary run 3 times
in a row and the first run dropped (the chunk file is named by this
package's source, so alternating binaries rebuilds it):
  step 2 (QueryPage All) allocated   835 MB -> 666 MB
  allocated through step 3 (effort)  994 MB -> 820 MB
  unpackReusing in step 2            163 MB -> 34 MB
  peak footprint                     ~240 MB, unchanged

Run at this head (base defbb1a15): go test ./internal/usage
./internal/sessions ./internal/gui ok; -race -count=3 of the chunkRows,
Pack and Archive tests ok; GOOS=linux and windows go vet -tags nogui
./internal/usage ok; gofmt clean. TestChunkRowsReuseReadsEachBlock now
runs 4 passes, lent and not, in both orders, through one pool; broken
by hand (a reused rows slice cut to its cap, not the block's count) it
fails "pass 0 block 1: 0 rows, want 3".

Not tried: Linux and Windows real-data runs.
2026-10-25 15:10:47 +08:00
yetone be7f174677 gateway: a key out of a guessed quota is asked again after one refusal, and held a minute (zoecats)
zoecats (Discord #feedback, 10-25): a local aggregator answers 429
insufficient_quota "quota exhausted" for the moment it switches
upstreams, and the agent's retry and every request after it were
answered by magpie itself, "out of its allowance: not asked again
before …", Retry-After 900. v0.1.1488 (c6768f06f) let it through only
when the user unticks the provider's new "Rests" switch; by default it
was still held (checked on origin/main 4dfd88206 below). The owner's
zero-config rule wants it to just work.

Cause: quotaHeld (#1772) answers from the rest, without asking, as soon
as every key left rests out of its allowance or credit, from the first
refusal on, for as long as the rest: 15 minutes (quotaRest) or 30
(creditRest) that magpie guessed when the vendor named no time.

Now (Rest.first, Rest.askAt, Rest.asksAt), for a rest whose length
magpie guessed (creditRest, or quotaRest with no OwnQuotaRest):
- The key is held only once it was refused so twice in a row. The first
  refusal still rests it (the order passes it over for a ready
  candidate), but the next request, the agent's retry first, asks it
  again; served, its rest is cleared as before.
- Held, it is asked again a minute on (fallbackCooldown), once, and
  held again if refused.
- A time the vendor named (resets, Retry-After, a window) or the user
  set (quotaRest, QuotaResetAt) holds it from the first refusal to
  then, as before. A first version gave every refusal one more ask;
  the full gateway suite turned it down in TestClineFreeLimitLeaves-
  OtherModels and TestZhipuRestsUntilItsReset (a named reset asked
  again), so it is limited to the guess.
  #1772's keys out for the week are asked at most once a minute each
  while requests come, not on every request.
- soonestBack, the Retry-After a 429 without one gets, says when the
  first of them is asked again: none after a first refusal, about 60s
  for a guessed hold (was 900 or 1800). That narrows #3556 for a
  guessed hold; a vendor-named or user-set one is as before.
- A rate limit was already asked again (restLast, retries within the
  request) and is unchanged; the new test holds it there, Retry-After
  0 and every key resting included.
- The "Rests" switch (LimitRestOff) stays: unticked, nothing rests at
  all.
docs/subsystems/gateway-routing.md says so.

Run (worktree at origin/main 4dfd88206 plus this change):
- Reproduced first on the old code with tests:
  TestRetryAfterALimitIsAsked (new; 429 insufficient_quota, a usage
  limit with no reset, the same with Retry-After: 0, 402, every key of
  two; plus two rate-limit cases): the five limit cases red on
  4dfd88206 ("request 2 after the refusal: 429 … not asked again before
  14:34"), green now; the rate cases green on both.
  TestHeldLimitAskedAgainInAMinute (new) red on the old code (Retry-After
  900, not asked a minute on), green now. TestAllRestingAnswersFromRest,
  TestOwnQuotaRest and TestQuotaHeldOnlyForKeysOutOfAllowance changed to
  the new rule (each key asked once more, then held; held Retry-After
  about 60s; a user-set week held from the first refusal); red on the
  old code. TestRemoteMagpieRestsTheModel (#2077) asks Claude Code once
  more before its hold: the other magpie can't read "resets 8:10pm
  (America/Los_Angeles)", so its 15 minutes there are a guess.
- Broken by hand, each red, then restored: r.first always false ->
  TestRetryAfterALimitIsAsked's five limit cases; askAt never set ->
  TestHeldLimitAskedAgainInAMinute and TestAllRestingAnswersFromRest
  (Retry-After 900).
- Sandbox HOME, a nogui build of 4dfd88206 and of this tree, `serve` on
  127.0.0.1:3481 over a Python fake answering 429 insufficient_quota
  "quota exhausted" once, then 200: old: 429, then 429 "not asked again
  before 14:41", 429 again, Retry-After 900, 1 upstream POST. New: 429
  (no Retry-After), 200, 200, 3 upstream POSTs (rerun on the final tree). The fake refusing every
  time, new: 429, 429 Retry-After 60, then held "not asked again before
  14:27" Retry-After 60, 2 upstream POSTs.
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway/ at
  4dfd88206 plus this tree, through suite-lock (after the DSH run):
  ok 446.6s. The first full run, before the rule was limited to a
  guess, was red in the three tests named above.
- gofmt -l clean; go vet ./internal/gateway/ (darwin); GOOS=linux go
  vet -tags nogui ./...; GOOS=windows go vet -tags nogui
  ./internal/gateway/: ok.

Not tried: zoecats' own aggregator; a real vendor's out-of-credit key
(OpenAI insufficient_quota) to see the once-a-minute ask in use; the
GUI (no GUI file changed; the Routing page reads the same rests);
Windows box (Windows CI compiles the tests only).
2026-10-25 15:02:12 +08:00
yetone 714ab8e8bf redact: a password after 密码, 密碼, 口令, パスワード or 비밀번호 is masked (CyberCaius on Discord)
"密码:786kih" in Settings → Masking's try box came back "nothing to mask", and so
went to the vendor as written. The password rules only knew English field names
(password = …, as configs have them) and asked for 8+ characters of letters and
digits both, since code calls many things a password. Nothing in code is called
密码, so after a CJK name for a password any value of 4 or more is taken, digits
only too, after :, :, =, 是, は or 는, quoted or not. A sentence's closing stop
stays outside the value.

Left as they were: "请输入密码:", 密码:${DB_PASS}, 密码:****, 忘记密码了怎么办,
修改密码功能, and a value of 3 (密码:abc). English "password: abc12" with a short
value is unchanged; issue filed for it.

Run at this head:
- go test ./internal/redact ./internal/masking ./internal/otlp ./internal/pii
  ./internal/settings ./internal/sessions -count=1: ok (every package that
  imports redact but gateway and gui)
- go test ./internal/gateway -run 'CJK|Mask|Redact|Privacy': ok
- gofmt -l, go vet ./internal/redact: clean
- Broken by hand: with origin/main's redact.go, TestCJKPasswordMasked fails 7
  of 7 masked cases; green with the rule.

Not tried: the GUI try box in a running magpie, and the full suite.
2026-10-25 14:50:13 +08:00
yetone defbb1a159 gateway: a Chat reply's cache read reaches the agent in OpenAI's names (B3TT3R on Discord)
B3TT3R (Discord #feedback, 10-25): DeepSeek Harness on DS-v4.1-Flash showed
"缓存命中 0%" over 1.2M input, and dsh's message usage carried only
inputTokens, outputTokens and totalTokens.

dsh reaches magpie through @deepseek-ai/dsh-llm-pi-ai with api
openai-completions, so its usage comes from pi-ai 1.4.0's parseChunkUsage:
cacheRead = prompt_tokens_details.cached_tokens ?? prompt_cache_hit_tokens
?? cached_tokens ?? 0, and nothing of Anthropic's. dsh's mapUsage drops a
0. magpie's Chat passthrough sent the upstream's usage as it came, so when
a provider told the cache only in another vendor's names (a relay giving
Anthropic's cache_read_input_tokens, or DeepSeek's prompt_cache_hit_tokens
or Moonshot's top-level cached_tokens beside a 0 in prompt_tokens_details)
the gateway counted the hit in its own usage log while the agent saw none.

Now chatTidy (stream) and chatWhole (whole reply) tell such a usage in
OpenAI's names too: prompt_tokens_details.cached_tokens, cache_write_tokens
when a write was told, and prompt_tokens counting both, with total_tokens
moved by the same amount. Every field the upstream sent stays. A usage in
OpenAI's names alone is never decoded (mayMendUsage looks for the other
names first), and one that already agrees comes back byte for byte.
Translated routes (Responses, Messages, Gemini) and plugin replies already
build the usage from cUsage and needed nothing.

Not proven: which provider B3TT3R uses. "DS-v4.1-Flash" is not how magpie
names a dsh model, and DeepSeek's own API sends both names, which pi-ai
already read right through magpie (checked live below). So this fixes the
case where magpie is at fault; if B3TT3R is on DeepSeek's own key the
cause is elsewhere and the reply asks.

Run, at this head (rebased on 4dfd88206):
- go test -count=1 -timeout 45m ./internal/gateway/... : ok (457s)
- gofmt -l internal/gateway docs: empty
- GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet
  ./internal/gateway/: clean

Broken by hand: with chattidy.go from the parent,
TestAgentReadsCacheTokensOnEveryRoute fails for chat-anthropic-names,
chat-zero-details and chat-moonshot, each on chat whole and chat stream;
every translated route and the plugin route pass there as on the new code.
TestUsageRecordsCacheTokensOnEveryRoute (gateway's own count),
TestOpenAIUsageLeavesOpenAIsAlone, TestMayMendUsageOnlyOtherNames and
TestPluginAgentReadsCacheTokens pass on the new code.

Real use, sandbox HOMEs, real dsh 0.2.1-rc.2 headless, real DeepSeek
behind a local relay that rewrites usage into Anthropic's names: through
the parent's binary dsh's session log has usage
{"inputTokens":367,"outputTokens":97,"totalTokens":464}, the reporter's
shape; through this one {"inputTokens":367,...,"cacheReadTokens":5376},
then 5632 and 5888. Straight to DeepSeek's own API (no relay), through
this change, dsh read cacheReadTokens 5248 to 5888; the parent sends that
usage byte for byte, so it was read the same before (not run live).

Not tried: a real Moonshot or OpenRouter key; the dsh desktop app (same
llm-pi-ai provider); the -responses and -anthropic dsh routes with a real
relay (covered by the route tests only).
2026-10-25 14:41:03 +08:00
yetone 4dfd88206e agent: Lody on Linux is run with its import link, which xdg-open turned away (Atlas on Discord)
Atlas (Discord #help, 10-25, Linux): Lody was running, and adding it
from magpie said "failed to open uri". magpie handed the
lody://provider/import link to xdg-open, as every OS's opener.

Cause, shown with the real Lody 0.108.1 AppImage in an amd64 Ubuntu
24.04 container (Xvfb, no update-desktop-database, as on many
desktops): Lody writes ~/.local/share/applications/ai.lody.desktop.desktop
with MimeType x-scheme-handler/ai.lody.stable and x-scheme-handler/lody,
but runs `xdg-mime default` for ai.lody.stable only. lody:// then rests
on the desktop database cache, which nothing built, so
`xdg-open lody://...` answers "gio: lody://...: Operation not supported"
(rc 4) while ai.lody.stable:// opens. With update-desktop-database run,
both open. The same on GNOME and XFCE with a fake handler at that entry.

Fix: on Linux agent.OpenLody runs what xdg-open would have run, the
Exec line of Lody's own desktop entry (ai.lody.desktop, then
ai.lody.desktop.nightly, then dev.loro.lody.oss; $XDG_DATA_HOME before
$XDG_DATA_DIRS, the first file of a name decides), with %U as the link.
An entry whose program is gone, no entry, or a start that fails falls
back to the opener as before. macOS (Info.plist claims lody:) and
Windows (Lody registers lody itself) are unchanged. The GUI's
/api/open and `magpie lody add` both go through it.

Tests: TestOpenLodyRunsItsDesktopEntry and TestDesktopExec
(internal/agent), TestLodyImportRunsLodyOnLinux (internal/gui, Linux
only). The GUI test is red on the old providers.go in golang:1.26.8
docker ("the link went to xdg-open: lody://..."), green on this one.
TestLodyImportHandoff now sets XDG_DATA_HOME/XDG_DATA_DIRS to its
sandbox, and XDG_DATA_DIRS is in TestFolderVarsAreListed's notAnAgent
(the system's data folders; the first run of internal/agent was red on
it until then).

Not covered, and Lody's to change: magpie on a machine Lody Desktop
reaches as a remote (Atlas's later detail: Lody on their own computer
connected to the host magpie runs on). Lody 0.108.1 imports only into
the desktop's own machine (the renderer writes the configs with
machineId = its local machine and needs __LODY_ELECTRON__), and the
link's payload takes only kind/id/name/auth/endpoints with a loopback
gateway, so no link names another machine. Lody Desktop opened on that
host shares the agent's ~/.lody/machine-id, so the import lands on the
same machine; docs/subsystems/agent-wiring.md says so.

Run:
- real Lody 0.108.1 AppImage in docker: agent.OpenLody reached a
  running Lody (its log: "handleDeepLink accepted deep link {protocol
  'lody:', host 'provider', pathname '/import'}", "sending deep link to
  renderer") and a stopped one ("pending deep link sent to renderer
  after did-finish-load"); xdg-open on the same link: rc 4.
- golang:1.26.8 docker, -tags nogui: agent and gui Lody tests ok.
- macOS: HOME=<sandbox> go test -timeout 45m -count=1 ./internal/agent
  ./internal/gui ./internal/cli: gui ok (124.9s), cli ok (48.6s), agent
  FAIL on TestFolderVarsAreListed (XDG_DATA_DIRS, fixed here); agent
  again after the fix: ok (213.5s).
- rebased on origin/main c6768f06f (5 commits, providers.go among them): the
  Lody, DesktopExec and FolderVars tests of agent, gui and cli ok again.
- gofmt -l clean; GOOS=linux go vet -tags nogui ./... ok;
  GOOS=windows go vet ./internal/agent ./internal/gui ./internal/cli ok.

Not tried: a real GNOME/KDE session with a signed-in user, the .deb
install (its postinst runs update-desktop-database when present),
Nightly and OSS builds, KDE's kde-open, the web-mode page (location.href
still opens it there). No GUI asset changed, so no Playwright run; no
budget raised.
2026-10-25 14:13:38 +08:00
yetone c6768f06f6 providers: a provider of the user's can be set never to rest for a limit
zoecats (Discord #feedback, 10-25): a local aggregator answers "quota
exhausted" (429 insufficient_quota) for the moment it switches
upstreams, and magpie set its key aside for 30 minutes, answering every
request itself ("out of its allowance: not asked again before …").

A provider the user added now has, under the editor's Advanced fold,
"Set it aside when out of quota or rate limited" (Rests), ticked by
default, with a note. Unticked (provider.LimitRestOff, limitRestOff in
providers.json), restAfterMarked rests nothing, counts no failure and
sinks nothing for a refusal it reads as out of quota, credit or rate
limited, or any 429: by "off", and the next request is sent to it as
usual. restDrawer rests no image model of it either. A 401, a model not
served and a plain failure still rest it. The default is as before. The
editor offers it only to a provider the user added (custom); a Save that
leaves it out keeps it. A checkbox (tick), no native select; strings in
zh, zh-TW, ja and de. app.js's budget (and the core's) are raised by the
576 bytes the row adds, with no room, after the comment was cut.

Run on origin/main 75e78a5a0 plus these two commits:
- gofmt -l clean; node --check app.js, i18n.js; go vet ./... on darwin
  and GOOS=linux/windows -tags nogui: ok.
- go test -count=1 -timeout 45m ./internal/gateway/ ./internal/gui/
  ./internal/provider/ (suite lock): gateway ok 417.9s, provider ok
  114.4s, gui red only on TestCoreScriptBudget (741 over); after the
  trim and the raise, TestCoreScriptBudget, TestProviderSaveLimitRestOff
  and TestI18n* ok.
- GUI, chromium and webkit: provider-limit-rest (new; en, zh, zh-TW, ja,
  de at 1100 and 420), provider-insecure-tls, i18n-keys, fallback-more:
  128/128. Every provider*, every file opening Advanced, i18n-keys,
  routing-lifted-elsewhere, rest-try-now, rate-limited-sink (58 files):
  1053 of 1055 (on the pre-trim app.js, the trim only a comment and an
  unused class): providers-last-known webkit zh-TW (filed #3565) and
  tencent-access-key webkit en (#2733) red at load ~130; each passes
  alone in WebKit on this tree and on origin/main 5b2b3d3f5.
  After the trim: provider-limit-rest, i18n-keys, provider-insecure-tls
  124/124.
- Sandbox HOME, a dev build of this tree, fake upstream answering 429
  insufficient_quota "quota exhausted": by default the second request was
  magpie's own "not asked again before 13:17" (1 upstream hit). Saved
  limitRestOff:true through /api/provider/save and lifted the rest:
  three requests, three upstream hits, each the vendor's 429; then 429
  rate_limit_error: no rest on the key (each request still asked again
  after 1s, 2s, 4s within itself, as a lone candidate always is); the
  upstream back, 200 at once.

Broken by hand, each red, then restored:
- the check in restAfterMarked off: TestLimitRestOffKeepsAsking ("1
  rests set after the refusal, want none") and
  TestLimitRestOffRestsNothingForALimit ("rests 29m59s by credit").
- the save's keep-when-left-out branch removed: TestProviderSaveLimitRestOff
  ("a Save that left it out turned rests back on").
- app.js's save line removed: provider-limit-rest's first two tests red
  in webkit zh-TW 420.

Not tried: zoecats' own aggregator; the in-request retries on a rate
limit (1s, 2s, 4s) are left as they are, as they are not a rest.

Again after rebasing on origin/main 1b039a3c7 (which changed app.js,
client.js and gateway.go): gofmt, node --check, vet on three OSes ok;
go test ./internal/gui/ ok (the budgets set to this head's sizes);
go test -run 'TestTryNow|TestRenewed|TestLimitRestOff|TestRestCapOff|
TestOwnRestCap|Sink|Unrest|Rest' ./internal/gateway/ ok; GUI, both engines: provider-limit-rest,
i18n-keys, provider-insecure-tls, routing-lifted-elsewhere, rest-try-now,
rate-limited-sink, routing-model-rest, routing-rest-off, routing-rule-drag,
routing-rule-models, view-trackpad-coast, fallback-more: 272/272.
2026-10-25 14:00:59 +08:00
yetone 67361b54fb routing: Try now from the editor reaches the Routing page, and puts a sunk key back
zoecats (Discord #feedback, 10-25, v0.1.1477): a local aggregator answered
"quota exhausted" while it switched upstreams; Try now in the provider's
editor left Routing showing 429 until magpie restarted.

Cause, in three holders:
- The Routing page kept lifts in its own liftedAt, filled only by its own
  Try now. A lift from the editor (or anywhere else) never reached it, and
  the kept routes' snapshots went on drawing the rest. The trace now
  carries every rest lifted (TraceState.Lifted, from restingUntil.lifted,
  kept up to longestMonthly), Unrest/UnrestAll/renewed wake the long-poll
  (trace.lifted), and the page leaves out a rest, a sunk key and an
  Accounts and keys count that a lift came after.
- With Sink on, a rate-limited key stayed at the back of the order until
  restart: Unrest never cleared sunk. unsink(key) now does.
- The gate itself: checked on the old binary in a sandbox HOME (single key
  over a fake answering 429 insufficient_quota "quota exhausted"). magpie
  rests it 30 min and answers later requests itself ("out of its
  allowance: not asked again before …"); Try now with the editor's key
  lifted that and the next request reached the upstream (200), on
  /v1/chat/completions and /v1/messages, streaming and not. So the stuck
  state was the display and the sink, not quotaHeld.
  Left alone, filed: #3555 (Try now lifts nothing when another magpie
  serves the gateway, unrest 400) and #3556 (the held reply's
  Retry-After, 900s here, outlives the lift for an agent that honours it).

Run at this change on its first base, 42976f9a0:
- gofmt -l clean; node --check client.js; go vet ./... on darwin, and
  GOOS=linux/windows -tags nogui: ok.
- go test -count=1 -timeout 45m ./internal/gateway/ ./internal/gui/ (suite
  lock): ok 404.9s, ok 128.9s.
- GUI, chromium and webkit, 5 languages, narrow and wide where the files
  do: rest-try-now, rate-limited-sink, routing-model-rest,
  routing-wb-restricted, routing-lifted-elsewhere (new), routing-rest-off,
  i18n-keys: 132/132. routing-lifted-elsewhere 20/20 alone. Every
  routing*, panel-routing* and rest-* file (108
  files, 1406 tests): 48 red in 8 files. routing-rule-effort, routing-pause,
  routing-live-patch, routing-rule-remove, routing-intent-entry,
  routing-manual and routing-time are red the same on origin/main
  15f0d4cde (a detached worktree, no changes) and filed (#3408-#3411,
  #2174, #3094, #3096, #3465, #1612). routing-steady flakes in both
  engines on both trees: WebKit alone, interleaved, 3 runs each, base 1
  of 3 green, this tree 1 of 3; the last group is read while the editor
  still opens (#3412, #1804).
- Sandbox HOME, fixed binary, two keys: after the editor's unrest the
  trace carried lifted, the next request went to key A (200), and the live
  Routing page went from "rest: A m1 rate limited · back in 10 min … Try
  now" to no rest.

Again on origin/main 1b039a3c7 with the next commit (its body says
what): vet, ./internal/gui, the gateway's rest and Try now tests, and
the Routing GUI files above, ok.

Broken by hand, each red, then restored:
- no unsink: TestTryNowPutsASunkAccountBack fails (order stays b,a).
- no trace.lifted, or no liftSeq wake: TestTryNowToldToTheRoutingPage's
  waiting Trace times out.
- no Lifted in Trace: Lifted empty.
- no lift recorded in renewed/UnrestAll: both tests fail.
- old client.js: routing-lifted-elsewhere times out in both engines; only
  the sunk check removed: "key c still at the back"; only the acts check:
  "Accounts and keys still counts key a resting".

Not tried: zoecats' own aggregator and harness; two magpies at once
(#3555). The Sink help text still says "Kept until magpie restarts", left
as it is: a key whose rest has ended shows no Try now.
2026-10-25 14:00:59 +08:00
yetone 1b039a3c72 gui: a trackpad's coast after the lift is the reader's scroll, no longer put back (issenn on Discord)
issenn (v0.1.1472, macOS app): a page with a scrollbar wouldn't scroll by
trackpad. It shook fast and snapped back, and only dragging the bar
worked. Seen on Agents.

Cause: the scroll guard puts back any .view scroll that comes outside
a window the reader's own events open. A wheel opened 250ms. When the
fingers lift, WebKit on the Mac plays the coast itself, and the page
hears those scrolls with no wheel for each. Once the last wheel's 250ms
ran out, the guard put back every coast scroll. Each coast step moved
the page and each put-back moved it back, so it shook and came to rest
where the fingers lifted.

Fix: the wheel now starts the same chain a touch fling does (flings,
flingUntil). Each view scroll keeps the next one the reader's until the
coast rests, and a click still ends it (purposeUntil = flingUntil = 0).
A code scroll at rest is still put back. The code and the comment fit
the old app.js size; no budget raised.

Test: view-trackpad-coast.test.cjs, chromium and webkit, en and zh. It
does five trusted wheels, then a 1s coast the page plays each frame
with no wheel. The coast must reach its end, a code scroll at rest is
put back, and a click mid-coast stops the row under the pointer.
- On origin/main's app.js: red 6/6 ("lifted at 40, coast asked 166,
  left at 101/105").
- Broken by hand, flingUntil not reset by a click: red 6/6 ("the row
  was at 269 after the click, 140 once at rest").
- With the fix: 6/6.

Real WKWebView probe (a Swift app loading the GUI with synthetic
NSEvent scroll phases): with every momentum wheel delivered, old and new
both end at 277. With the wheels after the first 32 kept from the page,
standing in for the coast with no wheel, old ends at 249 and new at
277.

Run:
- click-scroll, view-scrollbar-drag, view-middle-autoscroll and
  view-trackpad-coast: 44/44.
- Whole GUI suite (internal/gui/tests/*.test.cjs, chromium and webkit,
  every language) through suite-lock: still running at push, no red in
  its first 30 minutes; a red it finds gets a follow-up commit and an issue.
- go test -tags nogui -run Budget ./internal/gui: ok, run again after
  the rebase.
- No Go changed, so no gofmt or vet.

Not tried: a real trackpad on the mac app. Synthetic NSEvents skip
WebKit's MomentumEventDispatcher, which swallows the system's momentum
and plays its own. That the page gets its coast with no wheel is the
best fit for the report, not something seen on issenn's hardware. Also
not tried: ProMotion 120Hz, and WebKitGTK and WebView2 with a real
touchpad.
2026-10-25 13:32:47 +08:00
yetone b5a78fd8b5 routing: a group's rules are dragged into order
monkeyin_92 on X: "希望可以上下拖动规则". Rules are checked top first, so
their order matters, and it could only be changed a place at a time from
each rule's ⋯ menu (Move up / Move down).

A rule's number is now its handle, as a model's number is in the same
editor (memberHandle): drag it up or down (the shared dragRows, which
the members, groups and agents use), or focus it and press Alt+↑/↓. The
rules are renumbered at once and the keyboard stays on the moved rule's
handle. The grip beside the number shows only on hover, while dragging,
or from the keyboard; the dragged rule is lifted with a card background
and shadow, no coloured border. Move up and Move down stay under ⋯ and
now go through the same moveRule. Saved as the group's rules in their
new order. "Move rule {n}" in zh, zh-TW, ja and de; the title reuses
"Drag to reorder · Alt+↑/↓ to move".

Run at this head:
- routing-rule-drag.test.cjs (new), chromium and webkit, en, zh, zh-TW,
  ja, de: 10 of 10. It checks the handles and their names, the grip hidden
  away from the row and shown on hover, a drag of rule 3 above rule 1
  with nothing opened by the drag's click, Alt+↓/↑ (past the end too)
  with focus kept, ⋯ Move down, the page not moved, and the saved rules'
  order with their conditions. Red on the parent (no .rt-rhandle): 10 of
  10 in the parent's full run.
- GUI: every routing-*.test.cjs plus i18n-keys, click-scroll and
  group-member-drag, both engines: 1321 pass, 55 red, all in files red the
  same on origin/main 42976f9a0 (routing-pause #3410, routing-intent-entry
  #3408, routing-rule-effort #3411, routing-rule-remove #3096/#3094,
  routing-manual #3409, routing-steady #3412/#1804, routing-live-patch
  #2174, routing-time #3465), but one routing-bodies case and one
  routing-intent-entry 440 case, which pass run alone (load ~40).
- Real run: built binary, sandbox HOME, magpie web on 127.0.0.1:3486;
  group Mix with rules "tokens >= 1 -> one/m, two/m" and
  "agent codex -> three/m". In headless Chromium dragged rule 2's number
  above rule 1, Save, reload: the editor and `magpie group rule mix` both
  list "agent codex -> three/m" first, the two-model rule second and
  whole.

Not tried: a real mouse or trackpad; touch; the WebKitGTK app on Linux;
Windows.

Rebased onto 5b2b3d3f5 (10 commits, gateway, gui and routing's
client.js among them) and run again at the rebased pair's head
68701dfe4: gofmt -l clean; GOOS=linux and windows vet -tags nogui of
provider, gateway, cli, tui clean; go test -tags nogui -timeout 45m
internal/provider (171s), cli, tui, gateway (422s), gui (budgets): all
ok; GUI routing-rule-drag, routing-rule-models, routing-compact,
i18n-keys, click-scroll, group-member-drag in both engines all pass;
routing-rule-remove red as on main (#3096, #3094).
2026-10-25 13:32:12 +08:00
yetone f99d27abc2 routing: a rule names several models, tried in order
monkeyin_92 on X: "can a rule take several models? Otherwise one rule
with several models is several rules." A rule now takes more than one
model (Rule.More after Rule.Use; `more` in the group's JSON, use=a,b
typed). They go first in that order: when the first fails or rests the
rule's next takes the request, ahead of the models the later matching
rules name and the group's others.

Every reader of Rule.Use goes through Uses/SetUses/MapUses/Without/Names
in grouprule.go:
- cleanRules: each must be the group's, each named once; a pause names one.
- gateway: ruleFor's turn hold, tool rounds and outgrown turns, compaction
  (the rule's first that takes the summary, the others in Small),
  ruleMembers/ruleOver/applyRule, nestedRules and ruleLed (the one a
  nested group's turn stays on), modelRuled, ruleEffort (useEffort asked
  of each), ThenUses (leaves out all of the rule's own). RuleHit.More is
  in the trace; Instead from More has Unready false, one from a later
  rule Unready true, as before.
- ruledEntry: what the group takes is what every one of them takes.
- provider rename, auto/ refs, groupfast, a member's removal (a rule
  goes with its last), ShareGroup and its import (one this magpie hasn't
  is left out of the rule).
- CLI `group rule add use=a,b` and its listing; `group models-=` keeps a
  rule's other models. The TUI shows them joined and keeps the rule when
  one is deleted.
- GUI (plugins/routing): a chip per model, a + for the next one, an ×
  on each while there is more than one, a chip picks another in its place
  (app menu, no native select); the card's tooltip and the trace's why
  ("…so c/mini, which the rule names after it, goes first"), nested too;
  en, zh, zh-TW, ja, de.

Old data: a rule of one model writes no `more`, so groups saved before
read and save unchanged (TestRuleMoreOnDisk). An older magpie reads `use`
alone: its requests go to the first model, the others are plain group
members in group order; if it saves the group, `more` is dropped.

Tests: TestRuleSeveralModelsInOrder, TestRuleEffortReachesTheRulesNextModel,
TestRuleCompactPassesOverTheRulesSmallModel (gateway); TestCleanRulesSeveralModels,
TestRuleMoreOnDisk, TestRuleWithout, TestParseRuleSeveralModels,
TestThenUsesLeavesOutTheRulesOwn, TestRuledEntrySeveralModels,
TestSharedGroupRuleSeveralModels, TestRuleMoreRenamedAndKept (provider);
TestGroupRuleSeveralModelsCmd (cli); TestGroupTakeOutKeepsARulesOtherModels
(tui); routing-rule-models.test.cjs. Broken by hand: ruleMembers on Use
alone turns the first two gateway tests red.

Run at this head:
- gofmt -l clean; go vet -tags nogui clean with GOOS=linux and GOOS=windows
  for provider, gateway, cli, tui.
- go test -tags nogui -timeout 45m: internal/provider, internal/cli,
  internal/tui ok; internal/gateway ok (384s); the new gateway tests
  again after; internal/gui budgets ok.
- GUI: every routing-*.test.cjs plus i18n-keys, click-scroll and
  group-member-drag, chromium and webkit (en, zh, zh-TW, ja, de where the
  file has them): 1319 pass, 57 red. routing-rule-models passes in both.
  The reds are in files that are red the same on origin/main 42976f9a0,
  run there just now: routing-pause (#3410), routing-intent-entry
  (#3408), routing-rule-effort (#3411), routing-rule-remove (#3096,
  #3094), routing-manual (#3409), routing-steady (#3412, #1804),
  routing-live-patch (#2174), routing-time (#3465). The other 10 reds are
  routing-rule-drag.test.cjs, which is the next commit's and not in this one.
- Real run, sandbox HOME, built binary: three fake OpenAI vendors, group
  Mix = three/m, one/m, two/m, rule `use=one/m,two/m tokens=1`. one/m
  answers 429: the request went one -> two (not three, the group's
  first); the next went straight to two, the trace saying
  instead=two/m with more=[two/m].

Not tried: a real vendor account; the TUI by hand; Windows and Linux
runs (vet only).

Rebased onto 5b2b3d3f5 (10 commits, gateway, gui and routing's
client.js among them) and run again at the rebased pair's head
68701dfe4: gofmt -l clean; GOOS=linux and windows vet -tags nogui of
provider, gateway, cli, tui clean; go test -tags nogui -timeout 45m
internal/provider (171s), cli, tui, gateway (422s), gui (budgets): all
ok; GUI routing-rule-drag, routing-rule-models, routing-compact,
i18n-keys, click-scroll, group-member-drag in both engines all pass;
routing-rule-remove red as on main (#3096, #3094).
2026-10-25 13:32:12 +08:00
yetone 5b2b3d3f50 providers: a switched-off provider says how to turn it on, after a sign-in too
Atlas (Discord) signed in to WorkBuddy AI with `magpie plugin login
workbuddy-ai`, and `magpie providers` then showed "○ switched off" with
nothing saying why or how to undo it. magpie never sets Provider.Off by
itself; only the user's own switch does, and a sign-in rightly keeps it.
So the setting stays as the user left it, and magpie now says how to
change it:

- `magpie plugin login <id>` and `magpie accounts add <id>` (plugin and
  built-in paths), finishing for a provider that is switched off, print
  "! <Name> is switched off in magpie, so agents aren't given its models
  · turn it on: magpie provider on <id>". One that can't be found says
  nothing (not known to be off).
- `magpie providers` puts "magpie provider on <id>" in the switched-off
  row's last, unpadded column, so the key column keeps its width.
- The TUI's Providers row notes "o switches it on" (its `o` key).
- The GUI row already shows a "Switched off" badge and its own switch,
  and the editor says how to switch it on: left alone.

Run, at this tree (base c9c28aa58):
- TestPluginLoginSaysItIsSwitchedOff (new), TestProvidersShowVertexCredentials
  and TestTUIAddsVertexWithItsProject (extended): red with the source
  changes reverted (no hint in the login output, providers row or TUI
  row), green with them.
- go test -timeout 45m ./internal/cli/... ./internal/provider/... ./internal/tui/...: ok (cli 45.8s, provider 120.1s, tui 21.8s)
- gofmt -l: clean. GOOS=linux go vet -tags nogui ./...: ok.
  GOOS=windows go vet of the three packages: ok. go build: ok.
- Real run in a sandbox HOME with the fake test plugin and real Bun:
  plugin login (on: no line), provider off, plugin login again (the
  line, still off), magpie providers (row shows the command), provider
  on (row back to "signed in", no hint).

Not tried: a real WorkBuddy AI account; the built-in (non-plugin)
`magpie accounts add` path's line has no test of its own (its sign-in
needs a vendor's OAuth); the TUI was checked through its test, not a
real terminal; the full ./... suite was not run.
2026-10-25 13:19:52 +08:00
yetone c9c28aa586 gui: a gateway key list that can't be read keeps saying so in its card, and one read before stays
Found beside HarriesChen's report: when /api/caller-keys failed,
loadGatewayKeys put the error straight into #gatewayKeys, and the page's
next redraw (renderGatewayKeys from renderGatewayView, the providers'
poll) wiped it, since it returns early while no list was read. A failed
re-read also replaced a list already shown with the error.

gatewayKeysErr now holds why a never-read list failed, and
renderGatewayKeys says it in the list's card (styled like the empty line
by the previous commit). A list read before stays, and the error goes to
the status line. A read that works clears it.

Run:
- gateway-keys-empty.test.cjs: the unreadable case (past a
  renderGatewayView redraw) and the read-before case, both engines: green;
  with keys.js from main both red (".none" never visible; the 3 keys gone).
  All 22+2 of the file green with the change.
- The whole GUI suite was still running at push time (see the previous
  commit); not in this record.

Not tried: a real failing gateway (only the fixture's 500).
2026-10-25 13:04:41 +08:00
yetone 5046e4fc84 gui: no gateway key yet is said muted and inset in its card, as Recent calls says none (HarriesChen on Discord)
HarriesChen (#feedback, 10-25), magpie web on an iPhone: under Gateway
keys, "No gateway keys yet" was drawn in the body's own text (14px, the
foreground colour) flush against the edges of its white card. The
`.none` line inside `#gatewayKeys > .accts` had no rule: `.accts` gives
its rows padding through `.acc`, and the empty line isn't one.

`#gatewayKeys .none` now takes the look of the same page's Recent calls
empty line: muted colour, 11.5px, line-height 1.45, inset 13px 14px in
the card. The page's other empty lines (Recent calls, Models' "No models
match") already had rules and are unchanged.

Run:
- Reproduced at 390x844, magpie web (bootPrefs web), Chromium and WebKit,
  light and dark: before, colour rgb(28,28,33) / rgb(237,237,241), 14px,
  padding 0; after, rgb(133,133,141) / rgb(139,139,148), 11.5px, 13px 14px,
  equal to #activity .none in each. Screenshots looked at.
- New gateway-keys-empty.test.cjs (390px, web, both engines, en, zh,
  zh-TW, ja, de, light and dark): 20/20 green; with app.css from main
  20/20 red (colour, size, inset). fixtures/caller-keys.cjs takes
  options.keys.
- go test -tags nogui ./internal/gui -run 'Budget|Asset|I18n|CSS': ok
  (no budget raised).
- The whole GUI suite (node --test --test-concurrency=2 tests/*.test.cjs,
  both engines) was started at 687c3645f's tree and was still running
  when this was pushed (owner: ship at once). Its result is not in this
  record.

Not tried: a real iPhone Safari; the Go suite (only CSS and GUI tests
change).
2026-10-25 13:04:41 +08:00
yetone 75e78a5a04 tui: quitting hands the gateway to magpie's service on Linux
zaidu259434 on X: "启动codex这些cli连接会失败,AI分析没自动启动magpie的网关".
With magpie installed inside WSL (or on a server over SSH), nothing
opens magpie at login, and XDG autostart doesn't run there. So once
`magpie tui` quit, the agents it had connected asked a gateway that was
gone.

When the terminal quits having served the gateway with an agent
connected, on Linux and where magpie doesn't open at login, keepGateway:
- starts magpie's service (magpie daemon) when it is installed;
- installs it when the user never removed it (daemon.Removed: Uninstall
  now leaves a daemon-removed mark, and Install clears it), so it starts
  with the system or the login from then on, and says how to remove it;
- otherwise (no systemd, which is WSL's default, or the user removed it)
  starts `magpie serve` in its own session, logging to magpie's cache,
  and says so. In WSL it also says how to turn systemd on.
macOS, Windows, nothing connected, or magpie opening at login: the same
"gateway stopped" note as before. Docs: gui-shell.

Run:
- TestKeepGatewayAsTheTerminalQuits covers each of those cases, and
  TestUninstallRecordsTheUsersNo checks the mark.
- go test -timeout 45m on the four packages, the same run as the
  previous commit's: all four ok (gateway 428s, agent 255s, tui 23s, daemon 16s), at 6874095b1 plus this change, before the rebase
- GOOS=linux and GOOS=windows go vet, and gofmt -l, are clean.
- Real run in the magpie-desktop distro (WSL2, systemd on): a Linux build
  from this tree started under setsid as serveInBackground does,
  answered 200, and still answered 200 with its pid alive 30s after its
  wsl.exe session ended. It was stopped afterwards.

Not tried:
- the interactive TUI quit itself in WSL (over ssh there is no terminal
  to drive it), so the message and the path it picks are covered by the
  unit test only;
- a real daemon.Install inside WSL (it writes a systemd user unit for the
  distro's user).
2026-10-25 12:42:20 +08:00
yetone a1c1b7053b gateway: WSL under NAT reaches the Windows gateway with sharing off
zaidu259434 on X (tweet 2114203077989527990): on Win11, Codex and the
other CLIs in WSL failed to connect to magpie. A distro in NAT
networking (WSL's default) reaches Windows at the address Windows has
on the WSL network (vEthernet (WSL), 172.17.32.1 on the test box), and
magpie wrote that address into the distro's agents. But the gateway
listened on 127.0.0.1 alone unless LAN sharing was on, so every request
from WSL timed out. Turning sharing on wasn't enough either: the WSL
adapter is in Windows' Public profile, and a Private-only allow rule
still keeps WSL out (reproduced on the box).

- gateway: while it listens on loopback alone, on Windows it also
  serves at each address on a vEthernet (WSL...) adapter (serveWSL,
  looked for again every 10s, since the VM brings its adapter up and
  down). A request there counts as this computer's only when it comes
  from that network to that address with the WSL key (fromWSL). The key
  is `wsl-` plus 48 hex in magpie's folder (wsl-key, 0600), with
  `-<agent>` after it optional. The request is then served as a
  loopback one with the token (asFromLoopback). Anything else there is
  judged as another machine's, so a Docker Desktop container on the
  same network gets 403.
- agent: WSL twins at that address get the WSL key (keyAt, agentKeyAt,
  ourKey and gatewayKey know it). Whether it answers is asked from
  inside the running distro (reachFrom, wslReach: curl, wget or bash's
  /dev/tcp), never from Windows, where the listener answers whatever the
  firewall keeps out. A distro that can't connect is shown the firewall
  rule that lets it in (Profile Any, vEthernet (WSL*), magpie.exe).
- The NAT notices no longer say it answers only while sharing is on (en,
  zh, zh-TW, ja, de).
- Docs: gateway-routing (WSL under NAT) and agent-wiring.

Run:
- TestWSLCallerServedWithSharingOff and TestServeWSLListensBesideLoopback
  (gateway), and TestWSLAgentsGetTheWSLKey and
  TestWSLReachAskedInsideTheDistro (agent). All four were red with the
  fix taken out: "403 magpie isn't shared on the local network",
  "answers = false", the token given at the WSL address, and no drift.
- go test -timeout 45m ./internal/gateway ./internal/agent ./internal/tui
  ./internal/daemon: all four ok (gateway 428s, agent 255s, tui 23s, daemon 16s), at 6874095b1 plus this change, before the rebase
- GUI, NODE_PATH playwright 1.62.0, both engines: i18n-keys,
  agent-notice-lang, agent-unreachable, wsl-agents-setting, gui-zh-tw,
  gui-ja and gui-de, 105 of 105 ok.
- gofmt -l is clean, and GOOS=linux and GOOS=windows go vet are clean on
  the four packages.
- Real run on the Windows 11 box: a magpie.exe from this tree ran
  `serve` in a sandbox HOME, with MAGPIE_ADDR=127.0.0.1:3446 and sharing
  off. It listened on 127.0.0.1:3446 and 172.17.32.1:3446. From the
  magpie-desktop distro (NAT):
  - With no firewall rule, a request timed out (000 at 5s), and the
    probe script said "no".
  - After adding the rule this change advises:
    - the probe said "ok";
    - the WSL key got 200 in 0.09s, and so did key-codex;
    - no key got 403 "magpie isn't shared on the local network";
    - Bearer magpie got 403.
  The rule and the process were removed afterwards.

Not tried:
- a real Codex turn from WSL through this (the sandbox had no provider);
- `wsl --shutdown` re-addressing the adapter (it isn't my box to shut
  down; the 10s re-listen is covered by the unit test only);
- mirrored networking, which is unchanged.

Not changed: the Windows firewall prompt. magpie listens there itself,
so Windows asks once, and Public has to be ticked; the unreachable
notice gives the command for when it wasn't.
2026-10-25 12:42:20 +08:00
yetone 15f0d4cdeb sessions: a Claude Code session goes on in Codex, and a Codex one in Claude Code
0xPlato on X asked for conversations to carry across agents, at least on
one machine. A session row's Continue in (换 Agent 继续) now offers Codex
for a Claude Code session and Claude Code for a Codex one, when the other
is installed. Picking it converts the session then: a new session in the
target's own store, which its own resume opens. Listing converts nothing.

- Claude Code to Codex: a rollout in CODEX_HOME/sessions/YYYY/MM/DD with
  session_meta (model_provider from config.toml now, no
  base_instructions, so Codex uses its own), response_items and the
  event_msg user/agent messages the TUI shows. Codex indexes it on
  resume itself.
- Codex to Claude Code: CLAUDE_CONFIG_DIR/projects/<cwd>/<uuid>.jsonl,
  lines chained by parentUuid, assistant model "<synthetic>" so usage
  counts no call for them.
- Carried: user and agent text, pasted images, shell calls natively
  (Bash and exec_command) with their output, other tools as the agent's
  text (name, input, result in fences, cut at 64 KiB). Dropped: thinking,
  reasoning, signatures, encrypted content, Claude Code's own and Codex's
  context messages. After a compaction only what replaced the history.
- The source is only read. The new file goes through temp, sync, rename
  and never over an existing path. Asking again for an unchanged file
  gives the same session (memo by path, target, size, mtime).
- POST /api/sessions/carry {agent, id, to, open}: copies the resume line,
  or with open (Mac app) opens it in the session terminal. The details
  pane's Continue in line converts from its copy button too.
- Read-only and WSL sessions get no offer. Pi, omp, OpenCode, Kimi,
  Cursor and the rest are not converted.

Run (worktree at 42976f9a0, rebased onto origin/main before push):
- Real use in a sandbox HOME (HOME, CLAUDE_CONFIG_DIR, CODEX_HOME under
  magpie-wt/carry-sb), real binaries Claude Code 2.1.310 and Codex
  0.162.1, through magpie's gateway:
  - Claude to Codex: a Claude session that ran Bash, Write, Read and Edit
    was converted. `codex exec resume <id>` answered what the dog was
    called, which command ran and what was added. `codex resume` showed
    the whole history in the TUI.
  - Codex to Claude: a Codex session with exec_command and apply_patch was
    converted. `claude -p --resume <id>` answered the colour, the commands
    and the function added. `claude --resume` showed the history in the
    TUI.
- Fixtures in internal/sessions/testdata/carry are those real sandbox
  files. Claude's attachment text (system prompt, instruction files) and
  api-request lines were taken out; the line chain is kept.
- go test -count=1 -timeout 45m ./internal/sessions/ ./internal/gui/:
  sessions ok (15.7s), gui ok (119s), size budgets among them.
- Broken by hand, each red: Codex context kept (environment_context
  carried), no convert offer (all four TestCarry* red), images dropped
  (TestCarryImagesAndCompaction red). sessions-convert.test.cjs is red
  in chromium on the old client.js.
- GUI (playwright 1.62.0, chromium and webkit): sessions-convert in en,
  zh, zh-TW, ja and de, every sessions-*.test.cjs, i18n-keys,
  click-scroll, gateway-conversations: 424 of 424 pass.
- gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
  GOOS=windows go vet ./...; go build.

Not tried: Windows and WSL with real binaries (WSL sessions get no
offer), images through the real binaries (round trip in tests only),
Open in session terminal on a real Terminal (the POST is tested, the
terminal path is the existing openTerminal), a Codex session compacted
by OpenAI (encrypted, not carried), and the full ./... suite.
2026-10-25 12:25:06 +08:00
yetoneandchiperman 6874095b15 gui: the sidebar's gateway line is drawn from boot.js, before the providers' read (#3429, chiperman)
After a refresh the sidebar's gateway line came in about 1.5s late: it
was drawn only by sideGwRead, which waits 1500ms before it reads
/api/providers. chiperman's commit (c1f457a1b) has boot.js carry where
this process's gateway listens, and app.js draw it at once. Ported with
changes:
- api.go puts sideGateway in boot.js only when this process serves the
  gateway (served.Load() != nil), with the URL from gateway.URL(), the
  one /api/providers reports, and marked boot. Another magpie serving
  the port: nothing is sent, and the providers read decides as before.
- app.js starts sideGwAt from boot.js, so the first layoutNav draws it;
  chiperman's separate renderSideGwBoot is folded into that. A value
  from boot.js is read again at 1500ms like before, so /api/providers
  has the last word: served is set before the listen succeeds, so a
  listen that failed, or a gateway stopped since, shows "Gateway
  stopped" then. Without the re-read the boot line could stay stale.
- app.js is 45 bytes under its budget, which is unchanged.
Not fixed here, and pre-existing on main: Settings' address Apply leaves
the line on the old port until a reload (#3531). Seen in real sandbox
apps on main (3483 -> 3486) and with this change (3481 -> 3485).

Tests: TestBootSaysWhereItsGatewayListens (gui) checks boot.js's
sideGateway for 127.0.0.1:3481 and for 0.0.0.0:3483 shown as 127.0.0.1,
and none when this process doesn't serve. sidebar.test.cjs gets the
line from boot.js before any providers read, and a new subtest: the
boot.js line for 3425 is read again and turns to "Gateway stopped" on
3490 once providers says so, with one read.

Run on origin/main 46c418832 at this commit:
- Real app at the pre-rebase c28576084 and origin/main beside it,
  sandbox HOME, `go build -tags dev`, MAGPIE_DEV_UI
  127.0.0.1:3482, gateway on 3481 (main's on 3483), both engines,
  load and two reloads each: main shows the line 1885-2015ms after
  load; this change 70-216ms. One providers read in each.
- gofmt -l: nothing. go vet (darwin) of gui/gateway/cli,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -count=1 -timeout 45m ./internal/gui/ ./internal/cli/
  ./internal/gateway/: ok (gui 133s, cli 39s, gateway 405s) (TestCoreScriptBudget among them).
- GUI, both engines: sidebar, refresh-page, gateway-port, mobile-web,
  compact-at, routing-kind: 64/76; the 12 reds are sidebar's page list
  missing Insights › Masking, red on origin/main too (#3498). With that
  list given "masking" for the run only, sidebar is 18/18.
- Broken by hand: sideGwAt = null fails 10 sidebar subtests ("the
  gateway's line from boot.js"); the old `!sideGwAt` guard fails the
  new subtest in both engines; `false &&` in api.go fails
  TestBootSaysWhereItsGatewayListens.
- Whole GUI suite at the pre-rebase pair c28576084: see the #3425
  commit before this one; every red file has an issue (#3557 and #3558
  filed for it, #3535 earlier).
- Not tried: Linux or Windows real app.

Co-authored-by: chiperman <34889778+chiperman@users.noreply.github.com>
2026-10-25 12:06:13 +08:00
yetoneandchiperman 00d44d6928 routing: Codex's composer predictions story says their model is picked in Codex's row on the Agents page (#3425, chiperman)
Routing's Kind description for composer_predictions still sent users to
Settings › General › Codex composer predictions. That setting moved to
Codex's row on the Agents page. chiperman's commit (5e372e168) fixed the
Routing text in five languages. It is ported here with their zh, zh-TW
and ja; the de wording is mine.

Grepping for other texts that still name the old Settings place for a
setting that moved into an agent's row found four more, now fixed:
- app.js compactField, the provider editor's "Compact at": empty follows
  Long conversations, now "in their settings on the Agents page (else in
  Settings)". The field's text is one string now, and the header comment
  no longer repeats it, so app.js stays inside its budget (unchanged).
- gateway sealedWayOut: "Codex subagents on any model" is in Codex's
  settings on magpie's Agents page, not "magpie's Settings".
- gateway codex_titles: "Codex composer predictions are off" and "Codex
  titles are off" answers name the same place.
- cli `magpie model` help text.
Each gateway message has a test that fails on the old wording, and the
GUI files assert the new place and the absence of the old one.

Run on origin/main 46c418832 with this commit and #3429's after it (the
pushed pair; the Go and GUI runs below were at the pair's head):
- gofmt -l: nothing. go vet (darwin) of gui/gateway/cli,
  GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -count=1 -timeout 45m ./internal/gui/ ./internal/cli/
  ./internal/gateway/: ok (gui 133s, cli 39s, gateway 405s)
- GUI, both engines: compact-at, routing-kind, mobile-web, sidebar,
  refresh-page, gateway-port: 64/76; the 12 reds are sidebar's page list
  missing Insights › Masking, red on origin/main too (#3498). With that
  list given "masking" for the run only, sidebar is 18/18.
- Broken by hand: the old app.js/i18n text makes compact-at fail on
  "says where Long conversations is"; the old Routing text makes
  routing-kind fail.
- Whole GUI suite (both engines, -concurrency 4) at the pre-rebase pair
  c28576084: 12,519 tests, 12,350 pass, 169 fail in 31 files. Each red
  file was run alone at that head and at origin/main 641b1217f. All are
  red on main too or pass alone, and each has an issue: the 30 files of
  #3527's list (#3497, #3498, #3488, #3523, #2648, #3479, #3099, #3402,
  #3404, #3500, #3408-#3415, #3094, #2174, #3091, #3104, #3406),
  gateway-caller-keys (#2572, #1671), plugin-github (red alone on main,
  #3218), mobile-web (passes against the commit's base; after the rebase
  it passes at this head), codex-resets-used (#3535),
  routing-busy-frames (#3557) and zhipu-team (#3558). signin-port-blocked's
  11 were ENOSPC from a full disk mid-run; 40/40 alone.
- Not tried: a real Codex session hitting the sealed-task or titles
  message; the text was read in the tests only.

Co-authored-by: chiperman <34889778+chiperman@users.noreply.github.com>
2026-10-25 12:06:13 +08:00
yetoneandEdward4226 46c4188327 gateway: Codex's access_programs goes to OpenAI alone, so OpenCode Go's DeepSeek and GLM answer (#3172)
csic21, HONGs23 and TimWongUp (#3172): a Codex subagent inherits
access_programs {"cyber":"standard"}, magpie relayed it to OpenCode Go,
and Go answered DeepSeek and GLM with 503 "Upstream request failed:
Endpoint is unavailable."; without the field, or with null, 200. Go's
Haiku took it.

Scope: Codex itself sends the field only with a ChatGPT sign-in, or an
API key on its provider named "openai" (codex-rs core/src/
cyber_access_program.rs, for_auth and for_provider; read at openai/codex
970111f6c). It comes to magpie because Codex thinks magpie is OpenAI,
the same reason forVendor takes OpenAI-only parts out (#292). So the
class is "only the upstreams Codex would send it to", not an OpenCode Go
rule: no other vendor has a Cyber program to read, and Go is the one
seen to refuse it. keepsAccessPrograms keeps it for a ChatGPT (Codex)
account, a host ending in openai.com, another magpie (IsRemoteMagpie,
whose own upstream decides) and a codexAsSent relay when Codex sent the
request. Every other Responses upstream, relayed or built (from Chat
too), plugins included, goes without it. A relay that fronts ChatGPT
loses it unless set codex=as-sent, as Codex with a custom provider
would send it none.

- forwardOnce takes it out before the user's extraBody is merged, so an
  access_programs the user wrote there still goes (Edward4226's branch
  did it after, which would override the user's own value).
- withoutTopMember (from Edward4226's branch, using longBody's spans on
  a long body) removes the member, every one of that name, the rest byte
  for byte; a body that isn't a valid object goes as it came. A
  bytes.Contains check first, so a body without it costs nothing.
- Chat and Messages builds never carried it (now tested).
- Docs: gateway-routing.md, providers-accounts.md, ir.go comment.

Run:
- TestAccessProgramsGoToOpenAIAlone (new; fakes by the gateway client's
  RoundTrip, no network): Go DeepSeek/GLM from Codex and from curl, null,
  Chat built as Responses, Zen, a relay, codexAsSent with and without
  Codex's headers, the user's extraBody, OpenAI (daybreak_blue, null,
  from Chat), another magpie, a Chat and a Messages upstream.
  TestWithoutTopMember (new). TestCodexAccessProgramsReachBackend,
  TestAccessProgramsNullKept, TestCodexAccountTakesExtraBody pass.
- Broken by hand, each red: no strip (9 cases: Go, Zen, relay, extraBody);
  IsRemoteMagpie out; openai.com out (3 OpenAI cases); codexAsSent out;
  codexAsSent without fromCodex; Codex account out
  (TestCodexAccessProgramsReachBackend red); strip moved after extraBody
  (the user's value lost).
- gofmt -l clean; go vet -tags nogui ./... for darwin, linux, windows.
- HOME=<scratch> go test -tags nogui -timeout 45m ./internal/gateway/:
  ok (414s), at 42976f9a0 plus this change.

Not tried: a real OpenCode Go account on this head (the reporters' and
Edward4226's real A/B runs show the field alone turns 503 into 200);
OpenCode Zen's DeepSeek with the field (now sent without it either way);
a real Codex collab_spawn end to end.

Co-authored-by: Edward4226 <Edward4226@users.noreply.github.com>
2026-10-25 11:55:16 +08:00