Commit Graph
6816 Commits
Author SHA1 Message Date
yetone ac4af58230 gateway: a LazyCat app is shared at its own domain, and a cgroup v2 container is known
mtoolstec on X runs magpie in LazyCat (懒猫微服) and, with "Share on
local network" on, Settings offered http://172.28.3.65:3425: the
container's own address, which nothing outside the box reaches, and no
hint that it was a container's.

LazyCat injects LAZYCAT_APP_DOMAIN (magpie.<box>.heiyu.space) into every
container of an app and serves the app there over HTTPS. The
magpie-lzcapp package sets MAGPIE_PUBLIC_URL=https://{{.S.AppDomain}}
through a manifest template, which only lzcos 1.3.8+ renders; unrendered,
url.Parse refuses the "{" host and publicURL() was "" (the log says
"ignoring invalid MAGPIE_PUBLIC_URL"). A hand-written manifest may not
set it at all. Then ContainerAddrs() needed inContainer(), which knew
only Docker's and Podman's marker files and a runtime's name in PID 1's
cgroup. Under cgroup v2 with a private cgroup namespace (Docker's
default since 20.10) /proc/1/cgroup is "0::/", and a runtime that writes
no marker file got past it, so the container's addresses were listed as
the computer's.

- publicURL() falls back to https://$LAZYCAT_APP_DOMAIN when
  MAGPIE_PUBLIC_URL is unset or invalid (a DNS name only; lower-cased).
  Everything built on PublicURL follows: LANURLs, PublicHost (the
  rebinding Host check), magpie web's links and trusted origin, the
  image MCP base, the CLI's advertised URL. InContainer() is true there
  too (updates go through the image).
- inContainer() also takes a container's init as PID 1 (magpie itself,
  as our image starts it; tini, docker-init, dumb-init, catatonit), and
  a cgroup namespace's root ("0::/") on an overlay root filesystem
  (/proc/1/mountinfo). Neither alone catches a host: a systemd host is
  in /init.scope even on a read-only overlay root, and an init without
  cgroups on ext4/btrfs is not overlay. hostNetwork is unchanged, so a
  container on the host's network still lists the host's addresses.

What the user sees: in LazyCat, "Share on local network" shows
https://magpie.<box>.heiyu.space (and the Gateway URL is that domain).
In any other cgroup v2 container on a bridge network without a marker
file, Settings shows the container hint to set MAGPIE_PUBLIC_URL.

Run:
- TestInContainer (13 fake roots: systemd host, systemd on overlayroot,
  cgroup-less init on btrfs, WSL, markers, cgroup v1, kubepods, cgroup v2
  on overlay, magpie/docker-init/tini as PID 1) and TestLazyCatPublicURL
  (LazyCat domain, mixed case, the unrendered template, MAGPIE_PUBLIC_URL
  winning, bad domains) pass on Linux (wsl-run, magpie-desktop).
- Broken by hand: with origin/main's lan.go both tests are red (4 and 4
  cases).
- Real systems: the WSL2 distro (systemd host, 0::/init.scope) reads
  inContainer=false. Docker 28.2.2 on xiaomi-gpu, debian:12-slim with
  /.dockerenv removed (cgroup "0::/", overlay root, PID 1 sh) reads
  inContainer=true hostNetwork=false; with --init (docker-init) true;
  with --network host inContainer=true hostNetwork=true, so it still
  isn't called a container's addresses.
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go
  vet ./..., and the darwin/linux nogui/windows builds pass on mote at
  the first base (ddd6c649b); after the rebase onto 7 newer main commits,
  go vet ./internal/..., linux and windows vet of gateway/gui/cli and the
  build pass on mote.
- Linux (wsl-run): internal/gateway ok (1230s) at the rebased head;
  internal/cli (1707s) and internal/gui (624s), -tags nogui, ok at the
  first base.
- Not run: the full ./... suite. It was queued on mote's suite.lock
  behind ~15 other sessions' runs for 46 minutes and I stopped it; CI
  runs it on this push. No GUI file changed.

Not tried: a real LazyCat box (none here); the env names and the
https domain are from developer.lazycat.cloud/advanced-envs and the
lazycat-contrib/magpie-lzcapp manifest.
- After a last rebase onto fdd38154b (6 commits in usage, library,
  providers, settings and docs; none in internal/gateway), nothing was
  run again.
2026-11-10 00:10:23 +08:00
yetone 3b550a99c7 providers: a sign-in kept to its link leads to the setting that kept it
With Settings › Privacy › Sign-in pages' "Open sign-in pages in the
browser" off, adding an account says "magpie didn't open the sign-in
page, as set in Settings" and gave no way to that setting (the
scattered settings audit after netube99 on X). That line now ends in a
Settings › link that opens Privacy and lights the row. The row stays
in Privacy: it is there for max2020's reason, a vendor seeing which
browser a user signs in from.

app.js's core budget is met by one comment cut beside it, no raise
(38 bytes over before the cut).

Run (mote, through mote-run, Chromium and WebKit): signin-link-only
(every language, both a link-only and an opened sign-in, which has no
link), video-gen-pick and i18n-keys, 78 of 78; TestCoreScriptBudget ok
after the cut.
Broken by hand: no link, signin-link-only red in Chromium.
Not tried: a real sign-in in the app; the whole GUI suite runs after
the last of these changes.
2026-11-10 00:01:15 +08:00
yetone cedacf1aea settings: Video generation's how-to leads to the Providers page
With no model that makes videos, Settings › Models › Images' Video
generation says to right-click a model in its provider's Model settings
and mark it a video model, on another page, with no way there (the
scattered settings audit after netube99 on X). The line now ends in a
Providers › link that opens that page. It is drawn in videogen.js, so
the core script doesn't grow.

Run (mote, through mote-run, Chromium and WebKit): video-gen-pick
(every language it covers, 1100 and 400), signin-link-only and
i18n-keys, 78 of 78; TestCoreScriptBudget and the I18n Go tests.
Broken by hand: no onclick, video-gen-pick red in Chromium.
Not tried: the real app's window; the whole GUI suite runs after the
last of these changes.
2026-11-10 00:01:15 +08:00
yetone 8607a7a029 library: a skill GitHub's limit left unchecked leads to the token's row
A skill check that ran into GitHub's 60-an-hour limit says "Add a
GitHub token in Settings → Network and sharing", in a status line that
fades and a tag's tooltip, and nothing there went to Settings (the
scattered settings audit after netube99 on X). The Not checked tag is
now a link when the limit was the one without a token: it opens
Settings › Network and sharing and lights the GitHub token's row. A
token's own limit has nothing to add there, so its tag stays plain.

github-token.test.cjs swaps its route between rounds with
unrouteAll({ behavior: "ignoreErrors" }): the click leaves Settings'
lazy files being served, and the old unroute made the next round's
handler fulfil a route already handled.

Run (mote, through mote-run): github-token.test.cjs, Chromium and
WebKit, en and zh, 8 of 8; github-token plus every
library-*.test.cjs before the route fix: 1211 pass, the one red that
route race.
Broken by hand: the tag never a link, 4 of 8 red (each limited case).
Not tried: the real app's window; the whole GUI suite runs after the
last of these changes.
2026-11-10 00:01:15 +08:00
yetone fc9ce34d86 usage: hashRows reuses its scratch, within sizes its rows exactly
Startup on a copy of the owner's real accounts (mote, GUI, network
blocked, acgui.sh) allocated ~3.5GB, and two usage functions were near
the top of it:

- hashRows built a fresh 32KB byte buffer and shape map for every chunk
  it hashed: 510MB of the startup's allocations. It now takes them from
  a sync.Pool and clears the map before use. The digest is the same
  byte for byte (checked against the old code on the same chunks).
- rowChunk.within appended into a nil slice, growing it step by step
  (292MB flat). It now counts the rows in range first, returns nil when
  there are none, and makes the slice at that size.

Measured, same real-account copy, t9 (main) against t10 (this):
  startup CPU      13.81s -> 9.77s
  allocated (3m)   3483MB -> 2768MB (hashRows 510MB -> gone,
                   within 427MB -> 244MB cumulative)
  footprint        179MB  -> 175MB

Tests: TestHashRowsReusesItsScratch hashes a chunk again after a bigger
one and must get the same digest, and must allocate under 16KB a call
(min of 5 batches, so other goroutines' allocations don't count). Old
heat_disk.go: red at 32768 bytes a chunk; dropping clear(shapes): red.
TestWithinSizesItsRows needs len = cap = 600 (old code: cap 646).

Run on mote at this tree: go test ./internal/usage -count=1 ok, -race
ok, gofmt clean, go vet darwin/linux/windows ok, gui tests ok earlier.
An earlier usage run went red on a test whose name was lost (the log was
cut by tail); four full runs since are green, and the likely cause, the
first byte check counting other goroutines, is what the min-of-5 fixes.
2026-11-09 23:56:13 +08:00
yetone 3a5e4b62d0 usage: TestRowTokensAndZoneKept compares the zone by name and offset
The test compared got.Time.Location() with its own *time.Location by
pointer. rowZones keeps the first zone it sees for a name and offset, so
under -count=3 the second run got the first run's location back and the
test went red on unchanged code. It now checks the zone's name and
offset (IST, +5:30), which is what rowZones promises.

Run on mote: go test ./internal/usage -count=1 ok; -run
TestRowTokensAndZoneKept -count=3 ok (red on the old test). Broken by
hand: writing the row with an "XST" zone turns it red.
2026-11-09 23:56:13 +08:00
yetone 92be1d779b usage: the allowances' head opens Settings › Allowances
The Usage page draws the allowances, but how they are shown (used or
left, the menu bar's figures) and their alerts are set in Settings ›
Allowances, and nothing on the page said so (the scattered settings
audit after netube99 on X). The allowances' head now has a Settings ›
link, as the Routing page has, that opens that tab and lights the
Allowance display row (now #quotaLeftRow). Wired in the usage plugin,
so the core script doesn't grow.

Run (mote, through mote-run, Chromium and WebKit, every language, 1100
and 420): settings-places, mobile-web (with an origin/main baseline;
the button is taken out until the baseline has it, as rtToSet is),
account-mask, quota-curve, i18n-keys: 89 of 89, twice. A first run had
one red whose name a tail cut off; the next two runs of the same files
were 89 of 89, so it is unnamed and not seen again.
Broken by hand: no onclick, settings-places 2 of 2 red (no row lit);
no #quotaLeftRow, 1 of 1 red.
At the pushed head (rebased on f37de8cc4, which changed plugin pages and
the core budget): Budget and I18n Go tests ok; settings-places,
i18n-keys, plugin-page 30 of 30.
Not tried: the real app's window; the whole GUI suite runs after the
last of these changes.
2026-11-09 23:44:16 +08:00
yetone f37de8cc4e provider: the saved Claude accounts' files are listed once per request
claudeCodePrice and claudeModelsOf listed claude-accounts/*/.claude.json
with filepath.Glob on every call, and each Claude model's price asks.
Building an agent's model list (the window's drift poll rebuilds it each
minute, buildClaudeVia and Pi's list) read the folder once per model. The
listing is now held while a request holds the catalog (heldOf, 1 s), so a
build lists it once; outside a hold it is listed afresh, as before.

Measured on mote, real-account copy, GUI page open in Playwright
Chromium, network blocked, 115 s CPU profile (acgui.sh), v0.1.3425-era
build vs this change:
- filepath.Glob: 50 ms -> gone; agent.buildModels 90 ms -> 50 ms
- total samples 320 ms -> 290 ms; footprint 197 MB -> 172 MB (one run each)

Test: TestClaudeCodeFilesListedOncePerHold saves a folder during a hold
and checks the hold's second listing is the first one (same array), and
that after the hold the new folder is seen. Broken by hand (the old
claudeCodeFiles): red, "listed again within one hold".

Run (mote): go test ./internal/provider ./internal/agent ok; go vet
native (provider, agent), GOOS=linux and GOOS=windows (provider) ok;
gofmt clean.
2026-11-09 23:25:19 +08:00
yetone 623e797fde plugin pages: read a day's usage and share a picture they drew
A plugin's page can now read one day's usage and share an image it
drew. This is for the day card (JungleyYeh on X asked for a "daily AI
statement"); the card itself is an optional community plugin,
@magpie-community/page-day-card.

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

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

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

Real use:
- A sandbox HOME with a copy of real usage, through the real GUI
  server, in Chromium and WebKit, light and dark, en/zh/zh-TW/ja/de, at
  420 and 1100 px. The card showed 87.9M tokens, $9.85 and 4076 calls
  with a 22-day streak.
- Picking an earlier day and WebKit's Copy ("Copied") worked, with no
  page errors.
- Not tried at push: Chromium's Copy (its headless clipboard was
  denied) and magpie web's Save as a captured download. A second real
  run that grants both was still queued on mote's suite lock.
- Clipboard: checked live on macOS (osascript) and Windows
  (PowerShell). Not tried live on Linux: WSLg had no display.
2026-11-09 23:19:14 +08:00
yetone bc8b01d603 claude: the short system prompt is set in the Claude Code editor, not Settings › Replies
The scattered settings audit after netube99 on X. Short Claude system
prompt and Claude Code's interactive mode changed only Claude
subscription runs, yet sat in Settings › Models › Replies, while the
Claude Code editor already had its own "Claude Code runs as" switch for
the second, whose card said "Switched here or in Settings › Models ›
Replies".

Both rows now go in a claudeRunList in the Claude editor (PROV_PREFS), so
Settings' search still finds them and Open goes to the editor. In the app
the editor's own "runs as" switch is the one shown, and the duplicate
interactive mode row is hidden by CSS; in magpie web as a gateway, where
that switch is disabled, the row shows (the list gets a gw class from
renderReplies: body.gateway-mode is set only on a change, not at boot).
provPrefsField lets Claude's run list through in gateway mode, without
the warm-ups, which are this computer's. The card and the "off" reason
no longer name Settings (zh, zh-TW, ja, de written with them), and the
bridge's subsystem page names the editor.

Run (mote, mote-run, origin/main ddd6c649b as BASE_REF):
- claude-lean-prompt-setting, claude-tui-setting, claude-mode,
  provider-prefs, settings-places, i18n-keys, bare-ids and mobile-web,
  both engines: 170 of 170.
- go test -run 'Budget|I18n|Strings' ./internal/gui: ok.

Broken by hand (chromium):
- both rows back in Replies: claude-lean-prompt-setting and
  provider-prefs 18 of 18 red;
- the editor's duplicate row not hidden: claude-tui-setting 8 of 8 red;
- no gw class in gateway mode: claude-tui-setting 8 of 8 red.

Not tried: the real app with a real Claude subscription.
2026-11-09 23:14:57 +08:00
yetone 8f72f95304 provider: a group's lookup copies the group found, not every group
FindGroup, FindGroupAlso and GroupFinder built every routing group with
groupsIn, which copies each group and its rules, to return one. The
window's 15-second /api/drift poll asks GroupFinder for each Pi model on
a group (piModelJSON), and the gateway asks once per request on a group.
They now read the groups held (sharedGroupsIn, heldFrom while Hold is
active) and copy only the group found and each group a member comes
through (cloneGroup), so what a caller gets is still its own to change.

Measured on mote with the real-account copy, GUI page open in Playwright
Chromium, network blocked, 2 minutes (acgui.sh):
- piModelJSON allocations: 10.6 MB -> 1.5 MB (v0.1.3420 vs this change)
- process CPU 0.39 s vs 0.43 s, footprint 187 vs 197 MB: within the run
  noise of the once-a-minute catalog rebuilds; the drop is in the profile.

Test: TestGroupFoundCopiesItselfAlone changes a found group, its member's
Via and EffortMap, and checks FindGroup, GroupFinder and Groups still see
the saved ones; then 50 looks must allocate less than 50 copies of every
group (100 groups with rules).
Broken by hand, each red:
- A: sharedGroupsIn -> groupsIn: looks 5384832 B >= copies 4796000 B
- B: no cloneGroup of the found group: index out of range (shared slice)
- C: no clone of a member's sub-group: "a change to a found group
  reached the next look"

Run (mote): go test ./internal/provider ./internal/agent ok;
go test ./internal/gateway -timeout 45m ok; go vet native, GOOS=linux,
GOOS=windows ok; gofmt -l clean.
Not tried: a gateway request through a group with a real account
(the path is the same FindGroup the test covers).
2026-11-09 23:08:13 +08:00
yetone a6e4cf7635 settings: what routing does sits under Models › Routing, and the Routing page opens it
The scattered settings audit after netube99 on X. Ask again after a
refusal, the Retry-After cap and the intent classifier's timeout were
under Models › Replies beside rows about a reply's content, and Busy
models last sat in Network and sharing, far from the routing it changes.
The four are now one Routing section under Models, after Replies, and the
Routing page's header has a Settings › button that opens Settings at that
section with its first row lit. The docs (reference.md, the site's
plugins page in en, zh and ja) name the new place.

Run (mote, mote-run):
- settings-places, retry-after-cap-setting, refusal-retries-setting,
  classify-timeout-setting, model-load, i18n-keys and bare-ids, both
  engines: all pass.
- mobile-web against origin/main fdabddeb4 (a git repo made in the copy
  from git archive, since mote-run carries no .git): 30 of 30. It now
  takes the new Settings › button out of the Routing page until main has
  it, as it does for other new rows.
- go test -run 'Budget|I18n|Strings' ./internal/gui: ok. gofmt clean.

Broken by hand:
- the three rows back in Replies and busyLoadRow left where it was:
  settings-places and retry-after-cap-setting 20 of 20 red (chromium);
- the Settings › button's click handler off: settings-places 10 of 10 red.

Not tried: the real app; the GUI suite beyond these files runs with the
rest of this audit's changes.
2026-11-09 22:42:58 +08:00
yetone 7d177985f6 settings › allowances: the alerts under an Alerts heading, and no empty Menu bar cost row in magpie web
The scattered settings audit after netube99 on X found Task done alert
filed among the allowances' display rows, with nothing saying why, and
magpie web drawing Menu bar cost as a row with no control (it has no
menu bar, and renderTrayUsage returns before filling it there).

- Allowance alert, Low balance alert, Reset reminder and Task done alert
  are now a list of their own under an "Alerts" heading (#alertHead,
  #alertList), after the display rows. Gateway mode hides the heading
  and the list, as it hid the four rows.
- #trayCostRow is app-only, as #trayUsageRow is.
- "Alerts" in zh, zh-TW, ja, de.

Run (mote, at this tree):
- settings-places (new), bare-ids, turn-done, usage-alert,
  reset-reminder, mask-alert, settings-search, i18n-keys:
  122 pass, 0 fail, both engines.
- go test -run "Budget|I18n" ./internal/gui: ok.
Broken by hand: without app-only, settings-places is red 10 of 10 on
"no Menu bar cost row in magpie web"; with the heading renamed, red 10
of 10.
Not tried: the real app; the row moves are markup only.
2026-11-09 22:42:58 +08:00
yetone ddd6c649b3 draw: a plugin's model that says it gives images alone is an image model
maonekone (Discord #feedback, 11-09): a plugin can't say which of its
models draw; magpie took a plugin's image model only by its name
(DrawsID and ImagesAPI words). Now a model the plugin lists with
modalities.output ["image"] (no text), on its openai-compatible API, is
listed among the drawers and drawn at the images API through the
plugin's fetch, whatever its name. A model that answers in text and
images still chats.

Run (mote): TestPluginDeclaredDrawerDraws red on the old code ("drawers
[]"); with only the listing change, red again (the draw went to chat
completions); green with both. go vet ./internal/gateway ok; go test
-run "Draw|Image|SenseNova|Loomy|Plugin" ./internal/gateway ok (74s).
Not tried: a real plugin declaring such a model; the full suite.

Reported-by: maonekone (Discord #feedback)
2026-11-09 22:39:41 +08:00
yetone 92e8edd7fc windows: magpie is listed in Installed apps, and its Uninstall puts every agent back
Jevik_AI on X uninstalled magpie and rebooted, and Codex's config.toml
still had openai_base_url = "http://127.0.0.1:3425/backend-api/codex";
Rk1ngggg asked whether an update cleans it. magpie's own uninstall
(Settings › About › Uninstall magpie, `magpie uninstall`) already
disconnects every agent and takes Codex's leftovers (#3866), but on
Windows magpie wasn't in Settings › Apps › Installed apps, so it was
removed the way Windows offers for a program it doesn't list: by
deleting the exe and folders, which runs no code.

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

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

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

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

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

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

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

Not tried: a screenshot of the running app (screencapture fails over
ssh); a model request through a gateway from the isolated app; Windows
and Linux (not offered there). Known: the Dock shows Claude's own icon
for the running isolated app, and Chrome pairing is off in a moved
userData folder.
2026-11-09 22:31:16 +08:00
yetone fdabddeb41 catalog: a list fetched again as it was tells no agent
The magpie serving the gateway fetches each signed-in account's list
again once it is 45 minutes old (KeepAccountsListed), and saveLive
called Touched after every save: Changed ran SyncCatalog, which built
and compared every agent's model lists, and Forget moved the stamp
dsh's rounds build magpie's models by, so they built them again too.
For a list that came back the same, all of it was for nothing.

Now saveLive compares what it is about to write with the file there,
but for the fetch time. The same list is written (the new time keeps
the next relist 45 minutes away) and its next read looks at the file
(filememo.Look, also under a request's hold); nothing else is told. A
list that differs in a model, a part (Sides) or what it was asked as
is told as before.

Measured on mote with a copy of the owner's real config and accounts,
network blocked, the claude account's list set 2h old so the relist
falls in the window (acidle.sh, alloc_space from 60s to 180s idle):
  v0.1.3416 (t5): 42.8 MB, SyncCatalog 27.7 MB, buildModels 8.9 MB
  first cut, Forget kept (t6): 28.8 MB, dsh rounds' buildModels 12.1 MB
  this (t7): 14.1 MB (4.7 MB of it the heap profile's own write),
    neither SyncCatalog nor buildModels in the profile; the claude
    list's fetched moved to the relist's time (06:18:52)
Without a relist due, idle was 7.8 MB before and after.

Test: TestLiveSavedAgainSameTellsNoAgent. Broken by hand: always
Touched (red: "changed 2, forgot 2; want 1, 1"), and no
filememo.Look (red: the held read keeps the old fetch time).

Run at this head on mote: go test -count=1 ./internal/catalog/
./internal/provider/ ./internal/agent/ ./internal/filememo/ ok; go vet
of internal/catalog native, GOOS=linux and GOOS=windows ok; gofmt -l
clean.

Not tried: an account whose list really changed in a running magpie
(the test covers a model, a window, a part and the asked version).
2026-11-09 22:26:48 +08:00
yetone be9dbce02c settings search: built-ins are found too, off or on, and Open goes to their row
A built-in's switch and the settings it keeps in Plugins › Built-in or on
its own page (Gateway's Recent calls at a time) were found by nothing in
Settings' search, and one switched off took its Settings tab and rows
with it, so searching "Observability" with it off said no setting
matched (the scattered settings audit after netube99 on X). The search
now lists, after Settings' own rows and under "Plugins › Built-in", each
built-in whose name, line or schema setting has the words, in the
language shown or English, one off saying Off. Open goes to Plugins ›
Built-in and lights that row, again when the list is drawn a second time
as the plugins are read.

The list is drawn by a lazy setfeats.js the first time a search runs,
and only when what it finds changes, as Settings' observer runs the
search again on each change under the view.

Run (mote, at f98e954ce's tree plus this): settings-search,
old-webkit, builtin-places, provider-prefs, i18n-keys: 170 pass, 0 fail,
Chromium and WebKit, every language; TestCoreScriptBudget ok. Broken by
hand: without the row's light, and with the match always false, the new
case went red in Chromium (7 pass, 2 fail each).
2026-11-09 22:11:00 +08:00
yetone 07a06617e1 quota: an early reset starts the Cycle chart though the card's reset has milliseconds
steven_4422 (Discord #feedback, 11-09): a weekly window refilled early at
Nov 9 02:00 kept its deadline, yet the Cycle trend began at Nov 4 10:40, the
vendor's own start. quotaCycle took the recorded early reset only when the
card's resetsAt equalled the last reading's exactly. History keeps whole
seconds and a vendor's deadline can drift a little between reads, so the
two rarely matched. Now a reset minutes apart counts as the same one.

Run (mote): new quotaCycle test red on the old code (actual
2026-11-04T10:40:00.437Z, the reporter's start), green after;
quota-curve.test.cjs 31/31; go test -run Budget ./internal/gui ok.
Not tried: the reporter's own account; the full GUI suite (mote's suite
lock queue is hours long).

Reported-by: steven_4422 (Discord #feedback)
2026-11-09 22:06:55 +08:00
yetone 89d8b4d5f9 settings search: a provider's settings are found only while that provider is added
Settings' search lists each provider's own settings (warm-ups, check-ins
and the like) as rows that open the provider's editor. It listed them
for every provider magpie knows, so a search for "warm up on reset"
offered ChatGPT and Claude to a user with neither, and Open did nothing
(the scattered settings audit after netube99 on X). A row now remembers
its providers and is left out while none is added, and a row whose
built-in plugin is off is left out as the others are.

Those rows are drawn by a lazy provlinks.js the first time a search
wants them, not on each Settings draw: app.js was 399 bytes over
TestCoreScriptBudget with the change, and is now 956 under its size at
the base, with the budget unchanged.

Run in the tree with this change and the rest of the audit's fixes
(mote, base cd0ba05c2): settings-search, provider-prefs, old-webkit,
i18n-keys, builtin-places: 168 pass, 0 fail, Chromium and WebKit;
TestCoreScriptBudget ok. Broken by hand: without the set-miss line the
new case was red with ['ChatGPT','Claude'].
2026-11-09 21:51:54 +08:00
yetone 4064c10362 routing groups: on while Routing is off, their Built-in row says their page went with it
Routing groups have no page of their own: theirs is on Routing. With
Routing off and Routing groups on, Plugins › Built-in showed the groups
switch on and nothing anywhere to set them, and the quick start's
routing step still counted groups alone (netube99 on X, and the
scattered settings audit after it). The groups row now says "Their page
is on Routing, which is off" with Turn on Routing, which flips Routing's
own switch on the same list, and the quick start's step leaves with
either one off.

The hook lives in a new plugins/routing/settings.js, loaded after app.js,
whose featWho it extends (plugin client files load before app.js; the
first try in client.js threw "featWho is not defined" in every test).

Run in the tree with this change and the rest of the audit's fixes
(mote, base cd0ba05c2): builtin-places, mask-alert, settings-search:
162 pass, 0 fail, Chromium and WebKit, every language, 1100 and 420
wide; i18n-keys pass. Broken by hand: the hook returning at once,
builtin-places' groups case went red in all 20 runs.
2026-11-09 21:51:53 +08:00
yetone 7cb437ee16 masking: its alert sits with its other settings, and its Built-in row says when nothing is masked
The Masking alert was the one masking setting on the Masking page, under
the request list, away from every other one in Settings › Privacy (and
in Settings › Usage before that, where nb5p looked for it). It is now
the first row of Privacy's "when a value is found" list, out in gateway
mode as before. The Masking page is the list of masked requests alone.

Masking turned on with no kind, no personal data and no word of the
user's masks nothing, and its Plugins › Built-in row said only where
its settings are. It now says "Nothing is masked yet" before the link
(the scattered settings audit after netube99 on X).

Run in the tree with this change and the rest of the audit's fixes
(mote, base cd0ba05c2): mask-alert, builtin-places, settings-search:
162 pass, 0 fail, Chromium and WebKit, every language, 1100 and 420
wide; i18n-keys pass. The builtin-places file committed here is the
one run minus the routing-groups case, which comes with its change.
2026-11-09 21:51:53 +08:00
yetone 17a94a1b00 gateway: its keys show for a web page listed in Settings, and Settings links to them
A web page listed under Settings › Network and sharing › Web pages that
may call magpie is refused without a gateway key, shared or not, and the
row says to use "a gateway key from Gateway". But the Gateway page drew
its keys only while Share on local network was on, so that user found a
line saying keys come with sharing and no way to make one (the scattered
settings audit after netube99 on X). The keys now show while sharing is
on or a web page is listed, the off line names web pages too, and the
Web pages row links to Gateway's keys once it has a page.

The guard in renderGatewayOwn's settings callback also redraws the whole
view only while its box is still in the page, as 5efe0e195 does for the
first draw.

Run in the tree with this change and the rest of the audit's fixes
(mote, base cd0ba05c2): gateway-keys-off, cors-origins,
gateway-own-settings, old-webkit, i18n-keys: pass in Chromium and
WebKit, every language, 1100 and 420 wide (72 of 72 for the first four).
Broken by hand: gwKeysShown limited to sharing alone, gateway-keys-off
went 20 pass / 20 fail.
2026-11-09 21:51:53 +08:00
yetone 88b541a25c images: every pointer names Settings › Models › Images, where the page is
The image models moved under Settings › Models, but the Library's Magpie
Image sheet, the MCP server's instructions to agents, the gateway's
"no image model" errors, the video tool's text and the docs still sent
users to "Settings › Images", a tab that no longer exists (the scattered
settings audit after netube99 on X). Every user-facing string now names
Settings › Models › Images in en, zh, zh-TW, ja and de, as do the site's
Qwen docs (en, zh, ja), llms-full.txt, the subsystem pages and comments.

Run in the tree with this change and the rest of the audit's fixes
(mote, base cd0ba05c2):
- go vet ./internal/gui ./internal/gateway ./internal/agent
  ./internal/provider ./internal/settingsapi: ok
- go test -run 'Image|Draw|Video|Hidden|Group|Settings' ./internal/gui
  ./internal/gateway ./internal/settingsapi: ok; ./internal/imagemcp,
  ./internal/library, ./internal/catalog: ok
- GUI: i18n-keys, i18n-en-no-cjk, image-models-hide,
  library-browser-setup: pass in Chromium and WebKit
- gofmt -l: nothing
Not tried: a real agent reading the new MCP instructions (text only).
2026-11-09 21:51:53 +08:00
yetone 4ddd01fe5b gateway page: its own settings draw nothing while the page isn't drawn
c9a1c557d's renderGatewayOwn, run again once settings are read, met a
window where the view was "gateway" but the page's template wasn't on
it, and threw on a null #gwOwn. old-webkit's "with Safari 15.0's
built-ins, the panel and the window draw every page" was red on main
from then on ("null is not an object (evaluating 'box.replaceChildren')").

Run on mote:
- old-webkit + gateway-own-settings on origin/main 8d80f6bc0 with only
  this line added: 26 pass, 0 fail. Without it (8d80f6bc0 as is):
  old-webkit 5 pass, 1 fail, the error above.
Not tried: the real app (the window has to switch views before the
settings read returns).
2026-11-09 21:51:53 +08:00
yetone dae104bfac capre: a length check, not an unrolled repeat, holds nine patterns
Go's regexp unrolls a bounded repeat into that many copies of its
class: [A-Za-z0-9.-]{0,254} (the session terminal's bundle id) was
89kB of program, kept from start to exit, and Codex's item-id refusal
`.{0,1000}?` 88kB. Measured one by one over magpie's 540 package-level
patterns (1.5MB in all), the nine largest bounded ones were ~440kB.

capre.MustCompile(expr, max) is the pattern with * or +, matching only
a string of max characters at most (rune count, so the (?i) Kelvin
sign and invalid bytes count as the regexp counted them). The nine:
settings' bundle id, library's name and agent id (now name@wsl:distro
cut in two), Anthropic tool names, the trace page's name and find,
access's MCP server, OpenClaw's profile and Codex's provider id. The
item-id refusal is a function: the tail within 1000 characters of a
head.

Run on mote (go1.26.8):
- go test ./internal/capre ./internal/access ./internal/settings
  ./internal/library ./internal/sessions ./internal/agent ./internal/gui
  . : ok; ./internal/gateway -run 'ItemID|Undeclared|ToolName|Refus': ok
- TestCappedMatchesBounded holds each old pattern against its new one
  over 14 units x 19 lengths (0..300, at each bound +-1); with the
  length check taken out it is red (1586 mismatches).
  TestItemIDRefusalAsTheRegexp holds the function against the old
  regexp at 998..1002 characters of x, é, 日, \xff, \n; with 1001 it is
  red. TestCappedIsSmall: 1304 bytes held, 49680 bounded.
- go vet native, GOOS=linux and GOOS=windows over the touched packages
  (gui natively: its Linux build needs cgo); gofmt -l clean.
- Real build, GODEBUG=inittrace=1: magpie's own inits allocate
  11.93MB -> 10.61MB.
- Idle on the real-account copy, 180s heap: regexp programs (sampled)
  4.54MB -> 3.01MB.

Not tried: the full ./... suite; the gateway package beyond the run
above.
2026-11-09 21:47:24 +08:00
yetone ffbc45eac5 usage: a breakdown row's second line wraps at every width, not cut at 180px
In a wide window a Usage breakdown row's name column is a fixed 180px
and the line under the name (the sign-in, calls, credits, failures,
TTFT, speed) was one line cut with an ellipsis there, so everything after
the provider was hidden. Only the narrow web layout let it wrap. It now
wraps at every width; the narrow rule that did the same is gone.

Reported-by: shusoyo (Discord #general, 11-09)

Run (mote): usage-stat-sub-wrap.test.cjs 8/8 (chromium, webkit; en, zh;
1440 and 1000px). Broken by hand: with the old app.css it is 0/8 ("the
line wraps, not cut").
2026-11-09 21:40:13 +08:00
yetone 8d80f6bc0a sessions: the kept stats and listing hold an untitled id once, not a map entry
keptStats and keptList noted every answer Codex's titles gave in a
map[id]string, to ask each again before the kept ranges are given out.
Nearly every id has no title, and the map held 3.12MB on an 18k-file
history. titleAnswers keeps the named ones in a map and the untitled ids
in a slice, sorted, without repeats or slack once settled; still() asks
each again as before. Both caches use it.

Run (mote, real-account copy, idle 180s, network blocked):
- statsKept.keptTitle.func4 3.12MB -> under the profile's cut;
  total inuse 107.40MB -> 104.23MB.
- TestStatsKeptBetweenPolls now also names a Codex thread after the
  ranges were kept and checks the title reaches them.
  TestTitleAnswersSettled checks repeats and slack go.
- Broken by hand (still() skipping untitled ids, settle not compacting):
  TestListKeptBetweenPolls, TestStatsKeptBetweenPolls and
  TestTitleAnswersSettled red; green on this code.
- go test ./internal/sessions/ ok; go vet darwin, linux, windows ok;
  gofmt clean.

Not tried: the full suite (only internal/sessions reads these caches).
2026-11-09 21:18:44 +08:00
yetone 67d06c24ea sessions: a file's state fits the 416-byte size class, not 448
A state was 424 bytes, so each one decodeCache and parseRead make took a
448-byte slot. HeadSize is the length of a head of headLen (256) bytes
at most; as an int32 beside CdRead it saves 8 bytes, and a state is 416,
32 bytes less held per session file (~0.58MB for 18k files).

Run (mote, real-account copy, idle 180s, network blocked):
- decodeCache's inuse 26.01MB -> 23MB, reflect.unsafe_New 15.51MB ->
  12MB. The profile samples every 512KB, so more than the ~0.58MB the
  size class accounts for is sampling, not this change.
- TestStateFitsItsSizeClass: green; red on the old int by hand ("a state
  is 424 bytes, over the 416-byte size class").
- go test ./internal/sessions/ ok; go vet darwin, linux, windows ok;
  gofmt clean. The cache's JSON keeps head_size as a number, so an old
  cache reads as before.

Not tried: the full suite (state is unexported, only internal/sessions
reads it).
2026-11-09 21:04:19 +08:00
yetone cd0ba05c21 sessions: each day's usage and active rows are made to size
statsOfRange grew every day's Usage and Active rows by append, and the
overview keeps three ranges (7, 30, every day), each holding the slack
of every doubling. The rows are now counted per date first and made at
their length.

Run (mote, real-account copy, idle 180s, network blocked):
- statsOfRange's own inuse 9.90MB -> 8.37MB (-1.54MB in the diff
  against the v0.1.3411 build's profile).
- TestStatsDayRowsHoldNoSlack: green; red on the old code by hand
  ("usage 5 of 8, active 5 of 8").
- go test ./internal/sessions/ ok; go vet darwin, linux, windows ok;
  gofmt clean.

Not tried: the full suite (one package changed, nothing outside it reads
the rows' capacity).
2026-11-09 20:50:24 +08:00
yetone 46a615fb24 edit: a config's kept parse holds none of the file's text and no slack
tomlFileOf keeps a config's parse while the file is unchanged. Each key's
text, prefix and suffix were slices of the file's string, so the whole
file stayed alive beside the parse (1.5 MB of the owner's Codex
config.toml, ~11k project tables). The tables and names were also grown
by append and kept with their room. What is kept is now copied out:
text cloned, the prefixes and suffixes a config repeats on every line
(`trust_level = `, ` # …`) interned once through unique, and the tables,
each table's keys and the names held at their exact length.

Run on mote at this head:
- go test ./internal/edit: ok
- GOOS=darwin/linux/windows go vet ./internal/edit: ok
- gofmt -l: clean
- Broken by hand: without keptKeys on the tables,
  TestTOMLFileKeepsNoFileText is red ("2996 keys' text is still a slice
  of the file's"); with slices.Clone for the tables it was red on their
  room (3000/3072).
- Real-account copy (~/r2278/acct), idle heap at 180s: edit.tomlFileOf
  7.14 MB -> 2.97 MB; heap total 89.4 MB (102-103 MB the run before);
  Footprint 151 MB.
2026-11-09 20:35:17 +08:00
yetone 195d79939e dirent: a listing's entry keeps its time as nanoseconds, 40 bytes not 56
Stat.Mod was a time.Time (24 bytes), so an Entry was 56 bytes. The
listings kept for a long history hold up to ~130k entries (keptEntries),
and on the owner's real cache they were the idle heap's 7.7 MB under
dirent.entry. Mod is now unix nanoseconds (int64) with ModTime() for the
three callers that want a time; getattrlistbulk's seconds and
nanoseconds are summed as time.Unix does. An Entry is now 40 bytes.

Run on mote at this head:
- go test ./internal/sessions ./internal/dirent: ok
- GOOS=darwin/linux/windows go vet ./internal/dirent ./internal/sessions:
  ok
- gofmt -l: clean
- Broken by hand: a 16-byte pad in Stat makes TestEntrySize red
  ("an Entry is 56 bytes, want 40").
- Real-account copy (~/r2278/acct), idle heap at 180s: dirent.Stats
  7.68 MB -> 4.20 MB (dirent.entry flat 5.68 -> 1.70 MB); Footprint
  148 MB.
2026-11-09 20:19:28 +08:00
yetone 331f4a1393 gui tests: a comment line doesn't say a plugin's words (#5332, #5327, #5426, #5482)
i18n-keys' "a plugin's words are its own" has been red on main since
73c98ebc2 and was filed four times with no owner. Each red was a Go
comment citing a word from the window: search_row_archive_test.go's
"(View routing, the …", trace.go's '"No session ID")' and
skills_shared_copy_test.go's "Use the library's sets …". A comment says
nothing to the window, so whole-line // comments in .go and .js are left
out of the scan. Words in code are still found.

Run on mote at this tree (on origin/main c9a1c557d):
- node --test i18n-keys.test.cjs: 4 pass, 0 fail (was 1 fail on
  e3f1efdaa, the same three words).
Broken by hand: a code line t("View routing") in app.js turns it red
("plugins/usage/i18n.js "View routing": internal/gui/assets/app.js says
it too").
2026-11-09 20:14:03 +08:00
yetone c9a1c557d0 plugins: every built-in's row leads to where it is used, and the Gateway page holds its own setting
netube99 on X: one feature's settings are spread over pages that don't
say where the rest are. Plugins › Built-in had six rows (Key limits,
Groups, Rotation, Warm-ups, Middleware, Tools) with no page and no link,
so a user who turned one on was left to find where it shows. And the
Gateway page's one setting, Recent calls at a time, was a form under its
row in Plugins › Built-in, two pages from the calls it is about.

- pluginrt.Manifest gets Opens: the window page a built-in without a page
  of its own is used on. budget → gateway (keys' limits), groups →
  groups, rotation and warmups → providers (a provider's editor),
  middleware and tools → plugins. builtinJSON sends it; featGo links to
  that page by its sidebar name, as for a page plugin.
- A plugin with a page draws its settings there, not under its row
  (renderBuiltins). The Gateway page draws its schema under Recent calls
  (renderGatewayOwn), saves through /api/plugins/builtin as before, and
  ends with a row "Port, allowed addresses and model ids" that opens
  Settings › Network and sharing at the gateway's rows (4 languages).

Tests:
- TestBuiltinSaysWhereItsSettingsAre holds SetAt, Page and Opens per
  built-in.
- builtins.test.cjs: no form in Built-in, and each Opens row's link says
  its page's sidebar name. Its row reached by the wheel now counts the
  window's bottom too, and frees a switch under the view's floating To
  the bottom button by wheeling toward the window's middle: the rows grew
  with their links, and WebKit de 420 left Usage's switch under it.
- gateway-own-settings.test.cjs (new): the setting under the calls,
  translated, 20, picking 50 posts {id: gateway, config: {callsPage: 50}},
  the row opens Settings › Network at #portList flashed; every language,
  Chromium and WebKit, 1100 and 420, nothing past the window.
- builtin-places.test.cjs: Library's row now leads to Library.

Run at this tree (on origin/main e3f1efdaa), on mote:
- gofmt -l: nothing. go vet ./internal/gui ./internal/pluginrt
  ./plugins/..., GOOS=linux go vet -tags nogui, GOOS=windows go vet: ok.
- go test -run 'TestBuiltin|TestCoreScriptBudget|Translat' ./internal/gui
  ./internal/pluginrt ./plugins/...: ok.
- node --test builtins builtin-places websearch-places gateway-own-settings
  gateway-keys-off i18n-en-no-cjk: 272 pass, 0 fail (both engines).
- i18n-keys: "a plugin's words are its own" red, the same on a clean
  origin/main e3f1efdaa (#5332, #5327, #5482, #5426); fixed next.
Broken by hand: without budget's Opens, TestBuiltinSaysWhereItsSettingsAre
fails (want "gateway"); without the renderGatewayOwn call,
gateway-own-settings is 0 of 10 in Chromium.
Not tried: the real app; the whole GUI suite (next, behind suite.lock).
2026-11-09 20:12:30 +08:00
yetone cdd99c5578 routing: a re: pattern with a lookahead saves and matches as its preview showed
maer8824 on Discord wrote "re:(?!.*flash).*glm.*" (glm but not flash) in
a routing group. The GUI's preview, which reads patterns with JS's
RegExp, matched the right models, but saving failed: Go's regexp has no
lookaround ("invalid or unsupported Perl syntax: (?!").

compilePattern now reads with Go's regexp first, as before, and only a
pattern Go can't read goes to regexp2 (already in go.sum; now required
directly), with a 100ms bound on one match. A pattern Go reads keeps
exactly the matches it had; one neither reads is still refused with
Go's error. Groups' patterns and providers' auto-include rules both
compile here, so both take it.

Run on mote at this head: go mod verify ok; go vet ./... ok;
GOOS=linux and GOOS=windows go vet ./internal/provider/ ok;
go test -count=1 ./internal/provider/ ok (133s).
Broken by hand: with groupmatch.go/autolist.go/go.mod reverted,
TestRegexpPatternLookahead fails 5 ways (the reporter's error among them).
Not tried: a real group saved in the GUI; the full suite follows the push.

Reported-by: maer8824 (Discord)
2026-11-09 20:06:22 +08:00
yetone e3f1efdaac usage: a message id's pairing key is 16 bytes, not 24
msgKeysOf keeps each chunk's message ids as hashes, with the row, for
every chunk a pairing reads. The key was two 64-bit hashes and an
int32, padded to 24 bytes. It is now a 64-bit and a 32-bit hash with
the row, 16 bytes: two of a long history's ~300k ids alike in all 96
bits is ~1e-18 likely.

Run on mote at this head:
- go test ./internal/usage: ok (28.8s)
- GOOS=darwin/linux/windows go vet ./internal/usage: ok
- gofmt -l: clean
- Broken by hand: with the second hash back at 64 bits,
  TestMsgKeySize is red (24 bytes).
- Real-account copy (~/r2278/acct), idle heap at 180s, v0.1.3404's
  tree vs this: appendMsgKeys 6.49 MB -> 3.69 MB, inuse 103.0 MB ->
  97.8 MB, Footprint 154 MB.
2026-11-09 19:58:17 +08:00
yetone cf24e59065 gui: the stats answer test builds Active's hours through JSON (#5806)
36ddd5761 made sessions.Active.Hours the unexported hours type, and
internal/gui's TestStatsAnswerWritesWhatEncodeDid still built it as
[]int64, so the package's tests didn't compile on main. The test now
reads its Active from JSON, as the cache gives it, so the hours still
go through MarshalJSON in both answers.

Run on mote at this head: go vet ./internal/gui/ ok;
go test -count=1 -run 'TestStatsAnswer|TestSameAnswer' ./internal/gui/ ok.
Not run: the full suite (follows after the push).

Fixes #5806
2026-11-09 19:57:10 +08:00
yetone 1f1d210156 quotas: a wallet's counted spend goes out on /v1/magpie/quotas too (#5770)
a06872dec gave each wallet window spent and spentSince. QuotaSpan didn't
carry them, so TestQuotaSpanCarriesEveryWindowField went red on main
(seen in the full suite run after the push). quotaReport now copies
both, so a status line or a script reading /v1/magpie/quotas sees what
magpie counted a wallet spending and since when.

Run on mote at this tree (lockf ~/suite.lock mote-run):
- go test ./internal/provider -count=1 -timeout 30m: ok (whole package)
- gofmt -l internal: clean
The rest of the full suite at a06872dec was green, except internal/gui,
which doesn't build since f8186c691/36ddd5761 (#5806, not this change).

Reported-by: 9won (Discord)
2026-11-09 19:42:51 +08:00
yetone a06872dec8 caps: a wallet window's spend is counted, so a cap holds it (#5770)
A window that tells only what is left (QuotaWindow.Balance: AStudio
0.2.0's 通用积分 and 星火积分, SuperMagic's points) read 0% used until
it was empty, so an account cap never tripped on it. 9won capped an
AStudio account at 4 and it spent over 1,000 credits past it.

magpie now counts what such a wallet spends (wallet_spend.go). Each
plugin reading's balance is set against the one before: a fall is
spent, a rise (top-up, daily grant) is not. The count runs over the
window's own period when it tells a reset, else the local day: a
wallet never renews, and a cap reached for good would switch the
account off with no time it comes back; the ask was "N a day". Spend
before a period's first reading, or across a gap between periods, is
unknown and not counted; spentSince says when counting began. The
counts are kept in wallet-spend.json beside providers.json, so a
restart doesn't lose them.

Every wallet window carries spent and spentSince. On an account with a
usage cap (WindowCaps.Holds) it also reads as amount spent of limit
(spent plus what is left), and used that share. A cap by share then
holds it in routing (allowanceOf takes the fields as they are) and on
the GUI row (capHeldOf reads used). So does 40cbdaa7e's amount cap,
which skipped a window with no total: 9won's "at most 300 a day" on a
wallet now holds (magpie provider account-cap ... --window 通用积分
--amount 300). An uncapped wallet is unchanged:
balance alone, routed by Allowance.Left. A cap just set is judged from
the next reading. holdsBounds leaves wallets out: there is no whole to
reckon "holds" from.

Tests, each red on the old code (broken by hand where they compile):
- TestPluginWalletCapHolds: real plugin host, fake plugin, wallet
  10,000 -> 9,500 on an account capped at 4. Used 5, CapHeld set, the
  uncapped account untouched. Red with the plugin_usage.go hook
  removed (Used 0, Spent nil).
- TestWalletSpendCounted: falls counted, top-ups not, a restart reads
  the count back, the next local day and a told reset start over
  (UTC+8 fixed zone), failed and share readings left alone.
- TestWalletCapHolds: account cap 4, the window's own cap 4, and an
  amount cap of 700 (not held at 650 spent, held at 750).
- TestWindowHoldsLeavesAWalletOut: red without the holdsBounds change
  (a wallet reckoned a 500-token whole).

Run on mote at this tree on f8186c691. Rebased under it after: 7000b23b8
(GUI files only) and 36ddd5761 (internal/sessions only) (lockf ~/suite.lock
mote-run):
- go test ./internal/provider -run 'Wallet|Cap|Amount' -count=1: ok
- go test ./internal/usage -run TestWindowHolds -count=1: ok
- gofmt -l .: clean
- go vet ./... for darwin and windows, and for linux with -tags nogui:
  ok
Pushed and tagged at once, per the owner's rule. The full go test ./...
-timeout 45m runs after the push and any red gets filed.

Not changed: the GUI. A wallet meter still shows "{n} left". A capped
one shows "At its cap" from used. The meter's Amount... item still
needs a total and a unit, so an uncapped wallet doesn't offer it yet
(follow-up). A Text window (a balance that isn't
a number) still can't be capped by share.

Reported-by: 9won (Discord)
2026-11-09 19:23:13 +08:00
yetone 36ddd57619 sessions: the overview's active hours keep only the hours with time
Each range statsFor keeps holds an Active for every day, agent and
folder, and each had a 24-int64 Hours (192 bytes), mostly zeros: 4.5 MB
of statsOfRange's 13.5 MB in the idle heap on the owner's real cache
(18,331 files). Active.Hours is now the same sparse hours a day keeps
(hour<<58|seconds), and the act sums in statsOfRange use it too. Its JSON
is the 24 numbers of seconds it was, which the Usage page's heatmap reads
(a.hours.forEach).

Run on mote at this head:
- go test ./internal/sessions: ok
- GOOS=darwin/linux/windows go vet ./internal/sessions: ok; gofmt clean
- TestStatsHoursAndSessions now reads the hours through JSON, as the
  page does. Broken by hand (ms not turned into seconds): red, "the 20th
  by hour: [... 180000]".
- Real-account copy (~/r2278/acct), idle heap at 180s: inuse 110.65 MB
  (v0.1.3402's tree) -> 100.21 MB at this head (sampled; 4.5 MB of it
  was the hours' own lists).
2026-11-09 19:22:48 +08:00
yetone 7000b23b88 gui: a reset's time is said by a formatter kept per language, not made each call (#5310)
resetClock and resetText called toLocaleTimeString/toLocaleDateString/
toLocaleString, which build a new Intl formatter on every call. The Usage
page says every account window's reset on each render, so 600 accounts
made thousands of formatters per render.

dateFmt(opts) in i18n.js keeps one Intl.DateTimeFormat per intlLang() and
options. resetText's past time gives toLocaleString's default
fields (year/month/day/hour/minute/second numeric) by name, which is
what toLocaleString uses when given no options.

Probe (mote, 600 accounts open, W=520, names wrapping, 8 renders,
median sync ms, before → after):
  WebKit   ~431 → ~377
  Chromium ~327 → ~279

Test: reset-clock-formats.test.cjs compares resetClock and resetText
with what the old toLocale*String code said word for word. It covers a
time every 5h from a week back to eight days ahead, in en, zh, zh-TW,
ja, de and then system (a language switch after the cache is warm),
Chromium and WebKit, in a Tokyo time zone with an en-GB system. 2/2
green.

Broken by hand: a cache key without the language is red in Chromium
(zh said "02/11/2026, 20:29:01" for "2026/11/2 20:29:01").

Run at this change on 74017e0b8 (mote): TestCoreScriptBudget ok. The
40 GUI files that say a reset time ("Resets", "Reset time",
"tomorrow", 重置) plus i18n-keys: 770 tests, 3 red. The reds are
codex-auto-reset webkit de 1100/420 (red the same at its base 40cfae5d3,
#4790) and i18n-keys 'a plugin's words are its own' (#5327 #5332 #5426
#5482).

Not tried: the other ~37 toLocale*String calls in app.js. They run once
per page or row, not once per account window.
2026-11-09 19:21:46 +08:00
yetone f8186c6915 sessions: a day keeps only the hours it has time in
A day's hours were a [24]int64 (192 bytes) whether or not it had any.
The owner's real cache has 18,331 files and 19,191 days; 13,406 days had
hours, but only 19,107 hours across them had any time, so ~2.6 MB of
zeros sat in the idle heap for good.

hours is now a sorted []uint64 of hour<<58|ms, one entry per hour with
time. Its JSON is still the 24-number array, so sessions.json reads and
writes as before; an all-zero array read back keeps one zero entry so
the day still counts as having hours.

Run on mote at this head:
- go test ./internal/sessions: ok
- GOOS=darwin/linux/windows go vet ./internal/sessions: ok
- gofmt -l: clean
- Broken by hand: without hours.MarshalJSON, TestHoursKeepTheCacheShape
  is red (the packed entries went out as raw numbers).
- Real-account copy (~/r2278/acct): idle heap at 180s, t1 (v0.1.3398's
  tree) vs this: inuse 112.94 MB -> 110.65 MB (-2.3 MB; the 2.6 MB
  estimate less sampling noise).
2026-11-09 19:16:55 +08:00
yetone 22ffd4db69 plugin: a provider's models come from the plugin that serves it
Two plugins can sign in to one provider id. On the owner's MacBook Air,
tianpeng-dev's opencode-doubao-work-auth 1.1.6 was installed before
@magpie-community/opencode-doubao-work-auth 0.1.2. Both name
doubao-work. The third party's config hook ran first and wrote
cfg.provider["doubao-work"] with models: {}. Ours writes its entry with
??=, so it added nothing. Ours served the id, being the last to name it,
but info() read the shared config.provider entry: the provider showed
the other plugin's name and api and 0 models.

The config hooks still share one config object. Before each hook runs,
every provider it signs in to is set to the user's own entry, or to
this plugin's entry from the last load, never to another plugin's.
What the hook leaves there is kept as that plugin's (ownConfig).
info() reads the serving plugin's entry (providerConfig), so Prefer
moves the name, api and models with the provider.

Run (mote, at c056b7c8c plus this change):
- go test ./internal/plugin/ ./internal/provider/ ./internal/gateway/
  -count=1 -timeout 45m: ok (plugin 136s, provider 159s, gateway 879s)
- GOOS=linux and GOOS=windows go vet ./internal/plugin/: ok
- gofmt -l: clean

Broken by hand:
- With host.js as at c056b7c8c,
  TestServingPluginsConfigIsTheProviders is red with the Air's case:
  served by mine, but named "Theirs", with theirs' api and no models.
- With info() alone back on config.provider[id], it is red after
  Prefer(theirs): theirs serves, but with mine's name and models.

Not tried: the Air itself, before the release reaches it.
2026-11-09 19:16:48 +08:00
yetone 7a2a05c7a3 routing: Accounts and keys keeps each provider's heading while it says the same
freefcw on X (11-09, v0.1.3373 and v0.1.3375): magpie at 32% CPU with
2,250 idle wakeups and its webviews at 80 to 223MB; lemonkillergame and
laincatx say the same of CPU and memory.

The Routing page draws Accounts and keys again each second while it is in
sight (countdown: its rests and resets count down). Each drawing made
every provider's heading anew, icon <img> included, and patch then kept
the old heading in the page. But an <img> asks for its picture as soon as
its src is set, in the page or not, and the app's icons go out no-cache
(revalidated), so every provider's icon was asked for again each second:
through the Wails asset server in the app (a read and a sha256 of the
file each time), and each a new SVG document in the webview (~0.6MB, #909).
Over `magpie web` on mote, a seeded HOME with five providers on Routing:
322 requests a minute, 155 of them icons every 30s; every other page asks
for 4 to 13 in 45s.

A heading is now kept per provider while its icon, name and routing mode
are the same, and a heading with its first row are a list of nodes, no
longer a box they were moved into: the move took a kept heading or keys
row out of the page each second, so patch never found it in place.

Measured on mote (M5 Pro, load 50 to 90 from other sessions), the
0.1.3377 build vs this one, `magpie web` in Playwright WebKit on
?view=routing, 60s, twice each:
- requests: 322 and 325 a minute -> 7 and 7 (icons: 31 each per 30s -> 0)
- magpie's CPU: 0.78% and 0.73% -> 0.32% and 0.32%
- magpie's RSS: 225-227MB both

Test: routing-acts-idle.test.cjs, in Chromium and WebKit, en, zh, zh-TW,
ja, de at 1100px and en at 420px: a resting key's countdown redraws the
list, and over 3.5s no icon is asked for again and each heading is the
node drawn before. 14/14 pass; with client.js before this change 0/14
(each heading is a new node). Its icon count alone passes on the old code
there, since page.route's replies are kept in the browser's memory cache;
the real server's requests are the numbers above.

Run on mote:
- every GUI file that opens Routing (181 files, both engines, at
  origin/main 9a00bfed1 + this): 3337 pass, 16 fail in 8 files. Run again
  alone, at this change and at origin/main ff7d84b9b: the same 11 fail in
  both (ctx-session-line, filed #5801; routing-context-fold #5586,
  routing-row-swap #3799, routing-story-shrinks #3954); provider-mask,
  routing-model-rest and usage-compact-counts pass alone in both.
- at the pushed head (on 74017e0b8): routing-acts-idle and routing-acts-calm
  36/36; at 193d171b6: routing-acts-idle, routing-acts-calm,
  routing-acts-compact pass; i18n-keys' "a plugin's words are its own" is
  red, the same at origin/main 0eac4e6aa (#5332, #5426, #5482).
- go test -tags nogui -run 'Budget|Size|Routing|Asset' ./internal/gui: ok.

Not run: the whole GUI suite (only the 181 Routing files) and the full Go
suite (no Go file changes). Not reproduced: freefcw's 32%; the heaviest
seeded HOME here idled at 0.3 to 1.7% and the live heavy-user instance on
the owner's Mac at 0.9%. In the real app on mote the Routing window idled
at 0.3% with no ticking (its window not in sight on a headless session),
so the app's own numbers before and after are not measured, only
`magpie web`'s.
2026-11-09 19:12:45 +08:00
yetone 74017e0b87 gui: a card of many accounts is laid out once a render, not once an account (#5310)
fitQuota stacks each window's counts and gives side-by-side names one
height. It ran group by group: clear the names' min-height, then read
their offsetTop. Every read after a write lays the card out again, so
one Usage render with N accounts in full laid the card out N times,
O(N²). With 600 accounts at 520px wide and the names wrapping (a long
window name), one render held WebKit's WebContent at 100% CPU: 1.7-2.3s
of script and 10-13s to the second frame after it. Chromium took
1.2-1.4s.

fitQuota now takes every group. It reads all the sizes first, then
writes the classes and clears the heights. It reads each name's row and
height in one pass, then sets the heights. packUsage's heights() passes
the card's groups in one call; the ResizeObserver path already passed a
set.

Probe (600 accounts, all open, W=520, wrapped names), on mote:
  WebKit:   0.5s sync, 0.7s to two frames (was 1.7-2.3s, 10-13s)
  Chromium: 0.45s (was 1.2-1.4s)
  Wide layout, both engines: 0.3-0.4s before and after.
Scrolling 600 accounts was smooth before and after (2 frames ~30ms).

Test: quota-fit-batched.test.cjs counts the layouts forced in one
render: a read of a layout getter while MutationObserver records are
pending. The count must be the same at 160 accounts as at 40 (+4 room
for a frame's observer). It also checks that every group was drawn, the
names' heights were written, and each group was evened. Chromium and
WebKit, en/zh/zh-TW/ja/de, 10/10 green.

Broken by hand: the test pointed at HEAD's app.js (MAGPIE_FIT_ASSETS)
is red 10/10: 243 forced layouts at 40 accounts, 963 at 160, both
engines.

Run (mote, load ~30; first at base 40cfae5d3 + this change):
- 161 GUI files that touch quota/usage/panel, both engines, every
  language they cover: 2832 tests, 34 red in 9 files.
- Those 9 files again, on this change and on base 40cfae5d3 alone: 25
  red with the change, 30 on base. Every red on the change is also red
  on base except provider-mask, which times out in a different language
  each run on both trees (#5109).
- The reds on base are filed: codex-auto-reset webkit de (#4790),
  mobile-web (#3952, #5013), tray-cell-click (#5215), usage-fold
  'most on one screen' (#4790, #3415), and panel-fold (#5796, filed now).
- i18n-keys 'a plugin's words are its own' is red (#5327, #5332,
  #5426, #5482).
- At the pushed head (this change on origin/main c056b7c8c):
  TestCoreScriptBudget ok. quota-fit-batched 10/10, and usage-agents-hide,
  usage-compact-counts, usage-fold, usage-ledger and usage-ledger-search
  run beside it: 32 red, the same 32 as at c056b7c8c alone
  (usage-agents-hide #2276 #3414, usage-ledger Requests #5048, usage-fold
  #4790 #3415).

Not tried: the real app with 600 real accounts. The fixture's accounts
are Claude windows with one long name. Another layer is not changed:
the first layout after the rebuild, resetClock's Intl formatters, and
building the DOM, ~45ms each at 600 accounts.
2026-11-09 19:08:52 +08:00
yetone fc8e98ba47 edit: Codex's thousands of [projects] tables are left out of the reads that don't want them (#2278)
Codex writes a [projects."…"] table for every project it is trusted in;
the owner's config.toml has 10,933 of them in 1.5 MB. go-toml's decoder
checks each table against its siblings one at a time, so every decode
of the file cost ~0.3s of CPU, and six readers decoded it again each
time Codex wrote it, plus a whole-file check before each write magpie
made to it.

- edit.TOMLWithout drops [projects…] tables in a single unstable.Parser
  pass. The agent's codexTopOf, sessions' readCodexConfig, provider's
  readCodexStoreSetting, library's rtk sandbox, hooks rekey and MCP
  entries read through it. None of them reads projects. A file that
  doesn't parse is passed through unchanged, so it still fails.
- validateTOML checks definitions with the rest of the file and the
  projects decoded apart, 128 projects to a decode. A bare [projects]
  table, a dotted projects.… key outside the tables, or any error
  decodes the whole file, so the error is the one it gives.

Run on mote (M5 Pro):
- BenchmarkCodexConfigDecode (10,933 projects): 283ms -> 7.6ms a decode.
- BenchmarkValidateCodexConfig: 52ms (the whole decode was 283ms).
- Startup CPU profile, first 70s, the real-account copy (the real
  1,524,099-byte config.toml): 2.76s -> 2.26s of samples; go-toml
  0.32s -> none sampled.
- go test ./internal/edit ./internal/sessions ./internal/provider
  ./internal/library ./internal/agent: all ok.
- go vet of the same five on darwin, GOOS=linux and GOOS=windows; gofmt -l clean.

Broken by hand:
- Decoding the batches into struct{} instead of a map:
  TestValidateTOMLDefinitionsInGroups went red ("a key twice", "a
  subtable then its key"), so the check keeps maps.

Not tried:
- the whole suite. Only the five packages that read the file were run.
- Now that projects is left out, a project table defined twice no longer
  fails these readers' decode. Codex itself refuses such a file.
2026-11-09 19:07:06 +08:00
yetone c056b7c8c3 provider: a Responses provider's turns may go over the Responses WebSocket (#5781)
A provider the user added with an http(s) Responses address can now send
its Responses turns over the Responses WebSocket that magpie already
speaks to chatgpt.com (codexSocket), with `socket=auto|on|off`:

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

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

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

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

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

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

Reported-by: matrix0487 (Discord)
Reported-by: faithleysath (#5781)
2026-11-09 18:57:29 +08:00
yetone 7cabf0da98 sessions: one place says which ids a ZCode request names, and drafts are one group (#5754)
On top of Flandern1211's cherry-picked fix (the commit before this one).
GatewayKeys gave the bare id of a ZCode session (sess_<id> in ZCode's
database, <id> in the gateway's record), but NativeIDs kept its own copy
of the keys: the management page still counted every ZCode session sent
through the gateway as a gateway-only session, its delete listed them,
and its search read them a second time. requestIDs is now the one place
that says which ids a request names a session by; GatewayKeys (Sessions
list, its spend, the stats' native set, viaOf, the manage search) and
NativeIDs (the manage page's count and delete) both read it.

ZCode runs a session started without a project in a folder it makes for
that session alone: <workspaceDirectory>/draft-<id> or <ms>-<uuid>, with
workspaceDirectory = ~/.zcode/workspace (read from ZCode 3.17.2's
out/host/index.js, downloaded from cdn-zcode.z.ai; never the live
~/.zcode). The reporter's group is renamed from "Scratch sessions" to
"Draft sessions" (草稿会话 / 草稿會話 / 下書きセッション /
Entwurfssitzungen), after ZCode's own word for them, with a GUI test of
its own. Comments no longer quote "Seen through the gateway", which
i18n-keys' plugin-words guard read as the core saying the word.

Run (mote, at this tree, rebased on 0eac4e6aa):
- gofmt -l: clean. go vet of sessions/gui/usage for darwin, linux
  (-tags nogui), windows; GOOS=linux -tags nogui and GOOS=windows
  go build: ok.
- go test -run 'ZCode|Gateway|Native|Manage|Merge|External'
  ./internal/sessions ./internal/usage ./internal/gui: ok.
- GUI, Chromium and WebKit: sessions-zcode-drafts (new, 5 languages x 2
  widths), sessions-folder-list, i18n-en-no-cjk: ok. i18n-keys' "a
  plugin's words are its own" is red at origin/main for three words not
  touched here, filed: #5332 (View routing), #5426 (No session ID),
  #5482 (Use the library's). The reporter's comments quoted "Seen
  through the gateway" and made a fourth; reworded.

Broken by hand:
- TestZCodeGatewayRowIsTheSessionItself on origin/main's raft.go,
  manage.go and external.go: red (keys lack zcode|main, fork_of_main,
  abc; NativeIDs lack them; 29 rows for 26 sessions).
- sessions-zcode-drafts on origin/main's Sessions client.js/i18n.js:
  red in every language and width.

Not tried:
- The full Go suite and the whole Sessions GUI set: queued behind other
  sessions on mote's suite lock; run after the push, reds filed.
- A real ZCode database: none on this machine; the reporter's own run
  over 1,105 sessions is in the issue.
- Windows/WSL GUI, and a ZCode data folder the user moved elsewhere
  (only ~/.zcode/workspace is matched).

Reported-by: flandern1211_58540 (Discord)
Refs #5754 (left open for the reporter)
2026-11-09 18:55:01 +08:00
Flandern1211 a39b63e886 sessions: a ZCode session is listed once, and its draft folders are one group
A ZCode request names its session by the id its database gives with a
prefix stripped (sess_…, a subagent's sess_subagent_agent_…: zcodeBareID,
which Titles already used for names), while GatewayKeys kept only the
prefixed id. MergeExternal therefore matched no native session for any
ZCode session sent through magpie's gateway, and each was a row under its
folder and again a row under "Seen through the gateway" with no files
behind it. On this computer's database (1,105 sessions, 3,536 gateway
records) that was 70 of 70 gateway rows: 38 top-level sessions, 9 forks,
23 subagents. A group already holds its forks' and subagents' files
(ocRoots), and assembleListed counts every file's calls in the row, so
each of the 70 counted the same calls a second time.

GatewayKeys now gives the bare id of a ZCode session and of its forks and
subagents; externalAdded reads GatewayKeys instead of keeping its own copy
of the keys in pairs; idInFile names ZCode, so subIDs collects the ids
their own rows give (their files are in the group, no row lists them
apart). The Sessions page draws a ZCode session whose folder ZCode made
for that one session (~/.zcode/workspace/<draft|time>-<uuid>, one for
each session started without a project) in one "Scratch sessions" group
after the projects: 42 of them here were 40 folders of one session under
Other folders, and they are no projects of the reader's. cwd, files and
usage are untouched; a row's tooltip gives the folder it ran in.

The list went from 1,286 rows to 1,216 over the same 1,213 native ones;
the 70 gateway rows had 34.3M input and 2.59M output tokens and $125.66
of the ledger's cost on top of the rows that already counted those calls.
A ZCode row now prices its own calls from the catalog like every other
agent's, and Usage keeps the ledger's figures.

Run:
- go test ./internal/sessions -run 'TestZCode' -count=1: ok.
- go test ./internal/gui -run 'Session|Gateway' -count=1: ok.
- go build ./...; go vet ./internal/sessions: ok.
- gofmt -l; git diff --check; node --check on client.js and i18n.js: clean.
- go test ./internal/sessions -count=1: the same failures as without this
  change (TestAgySessions, TestAgyRowOnly, TestAntigravityAppFolder,
  TestCCListingKeepsItsNames: path separators and allocation counts on
  this Windows box).
- go test ./internal/gui -count=1: the same failures as without this
  change (lody's %AppData%, pageservice's symlink privilege here).

Broken by hand:
- dropping the bare key puts the 70 rows back under Seen through the
  gateway (TestZCodeGatewayRowIsTheSessionItself fails);
- leaving ZCode out of idInFile keeps a fork's and a subagent's own rows
  as gateway rows while the group already counts their calls.

Not changed: the scratch group is worked out on the page (client.js), so
Usage's folder filter still lists the draft folders by their paths; the
group is ZCode's only, and other agents' per-session folders are left as
they were.
2026-11-09 18:49:15 +08:00
yetone 0eac4e6aa8 gui: the core is back in its script budget, the account-cap comments cut (#5795)
40cbdaa7e (a window's cap at an amount of its unit) added ~1.1KB to
app.js and, with what landed beside it, took the core's scripts to
1,535,556 bytes, over coreScriptBudget's 1,533,802, so
TestCoreScriptBudget was red on main.

No raise. The comments of the account rows, names and caps in app.js
(renameIn, accountNameButton, windowCapOf, capHeldOf, directNote,
windowCapMeter, the lanes pill, refreshLanes and a few beside them) are
cut down or out, 2,009 bytes: the core is 1,533,547 now. Only comment
lines change. The budget's comment records it.

Run at this head (origin/main 4da0aa027 plus this commit), on mote:
- go test ./internal/gui -run TestCoreScriptBudget -count=1: ok
- node --check app.js: ok; gofmt -l internal/gui: clean
- grep of the Go and GUI tests for the cut comments' text: no test
  reads them
Broken by hand: none needed; the sum of the core's scripts at
4da0aa027, worked out the way the test does, is 1,535,556, over.
Not tried: the GUI suite, since no code line changes.
2026-11-09 18:40:30 +08:00