Commit Graph
93 Commits
Author SHA1 Message Date
yetone 58fb070953 settings: named proxies, chosen as inherit, direct or a saved one anywhere a proxy is (@tsingchao on X)
Settings > Network keeps named proxies (name, address, optional login)
with a Test that says reachable and the latency. Everywhere a proxy can be
chosen (global, plugin downloads, a provider, a key, a Claude account) now
has a Saved mode beside the others; the value is "@<id>". Addresses typed
before are read exactly as before, nothing is migrated or overridden.
netproxy.Parse/Resolve/Redact/EnvWith/Dispatch resolve a reference at the
lowest layer, so a proxy edited once reaches the gateway, usage reads,
sign-ins and the plugin host at the next request; Claude Code's
settings.json env (a snapshot) is rewritten by provider.ProxyEdited.
A reference this computer lacks fails closed (DeadProxy), says the proxy's
name in the request error and as "Proxy missing: {name}" on the provider
row, and never goes direct. The password lives in settings.json (0600), is
never read back by the page, logged, or put in Settings sync. The list
rides with the providers part of a sync (Bundle.Proxies, MergeProxies by
id, passwords only with keys). A proxy in use can't be deleted (409).
The saved list's page code is in proxies.js, loaded when Settings draws it;
app.js grew by Saved-mode helpers only, paid for by 16 long comments cut
(core budget unchanged, no raise).

Run (mote refused ssh all session, so Go and GUI went through win-run on
xiaomi-gpu, Windows 11; gofmt and darwin/linux-nogui/windows go vet were
clean on mote before it went down, at the pre-sync tree):
- go test settings, netproxy, backup, settingsapi, davsync: ok on Windows
  (earlier on mote: also gui, provider, plugin with real Bun, gateway).
- saved-proxies.test.cjs 20 of 20 (chromium+webkit, en zh zh-TW ja de,
  420px) twice more on Windows; provider-proxy-missing.test.cjs 20 of 20.
  One webkit de 420px run of saved-proxies failed once under 4-way
  concurrency and passed 3 of 3 alone; not reproduced.
- TestCoreScriptBudget ok after the move (it was 3.4KB over before).
Red on this tree and on origin/main alike (Windows run, not mine):
settings TestSharedCheckedReadsOnceAndKnowsUnknown; provider
Codex keychain/Git tests; plugin TestHostRunsAsMagpieBun, TestPiPackage;
gui TestGatewayHeldByAContainer and others; old-webkit "compat.js is the
first" (headerpresets.js) and ":has() (Safari 15.4)" on origin/main 245f07b19.
Broken by hand: restore skipping Proxies (TestSavedProxiesTravelWithProviders
red), Parse returning nil for a dangling ref (netproxy tests red), the
Proxy-missing badge disabled (provider-proxy-missing 0 of 20), and the Claude
env snapshot failing open (found by reading, test added).
Not tried: real vendors, the real Claude Code, a real two-computer sync, the
macOS suite and the whole GUI suite on this final tree (mote down; the whole
suite ran to test ~3700 on the earlier tree with reds owned by others).
A proxy missing whose sender never had it is named by its id.
2026-11-11 12:26:43 +08:00
yetone 71c4ef2d07 gui: Bark push target for every alert, and a daily spend summary (EV_John_Liu on X)
Settings > Usage has a Bark row: a server (default https://api.day.app, or
a self-hosted one) and the device key, then Test and Remove. Every alert
that goes through notifier.sendAs (allowance, balance, reset reminder, task
done, masking, sign-in) is also pushed to Bark when a key is set, whether or
not the system lets this computer notify. A second row, once a key is set,
turns on a daily summary at a time of day: today's cost and request count,
and each window or balance near its cap (the Allowance alert's share, else
80%), capped at 8 lines. It is pushed once a day (a restart does not resend;
a failed push is retried every 15 minutes; one more than 6 hours late is
left), in the page's language (en, zh, zh-TW, ja, de).

The device key is a key: the page only gets barkKeySet, never the key; it has
its own route (POST /api/settings/bark, key omitted keeps it, "" removes it),
a Settings save carries it (settingsapi.Merge), and a backup or sync without
keys leaves it out and keeps this machine's. No log line or error names it
(the Bark client replaces it with "..." in what the server or client says).
bark.js is a lazy module so app.js (budget) gains one line.

Run (mote, at the pushed tree before the rebase onto 6d7862769):
- go test ./internal/bark ./internal/settings ./internal/settingsapi
  ./internal/backup ./internal/davsync ./internal/provider: ok.
- go test -run 'Bark|AlertsGoTo|GitHubToken' ./internal/gui: ok. go vet
  darwin, GOOS=linux -tags nogui and GOOS=windows over gui, bark, settings:
  clean. gofmt -l: clean.
- GUI: bark.test.cjs (5 languages x 900/380px x chromium/webkit), i18n-keys,
  i18n-en-no-cjk, usage-alert: pass. Whole GUI suite started; reds so far are
  in account/agent/checkin tests that do not touch Settings or Bark, filed
  separately after this tag; old-webkit's Safari 15.0 :has() is #5919.
- All against fake servers; nothing reaches the network.
Broken by hand, each went red: no barkPush in sendAs
(TestAlertsGoToBark), BarkKeySet forced true / key shown (TestBarkSettingAndTest),
no same-day check in the daily step (TestBarkDailyStep).
Not tried: a real Bark device or the real api.day.app; win-run and wsl-run
(vet only for those OSes); a self-hosted Bark server.
2026-11-11 03:41:37 +08:00
yetone 281a7e024f sync: a computer can follow the server, taking its setup and sending none (Ramon317317 on X)
Ramon317317 asked for a main profile: one computer the others take their
setup from, so they never drift apart. Sync merged both ways only;
Restore is a one-time pull and an agent's own fields cover agents only.

A computer can now be set to follow the server (Settings -> Sync -> This
computer: Both ways / Follows the server; /api/davsync/follow-server;
`magpie webdav|s3|github follow on|off`). It is chosen per computer and
kept in sync.json (Config.FollowServer, kept by Configure like AutoEvery).
A following computer:
- takes every changed part from the file, whichever side is newer;
- never writes the file: no push, no merged sign-in, no rebuild of a
  damaged file;
- keeps a change made on it in the sync folder, as a join does, and the
  notice says it was replaced because this computer follows the server
  (Notice.Followed; GUI and CLI);
- still keeps an unset part on the server from emptying its own, and own
  agent fields and agents only here;
- refuses to follow a server with no file yet, sending nothing.
The computer followed stays two-way; nothing changes for anyone who
doesn't pick it. Usage sharing is unchanged. docs/subsystems/sync-backup.md
says so.

app.js stays inside the core script budget (TestCoreScriptBudget) with
no raise: renderSync's comments are cut down to pay for the row.

Run (mote, at this head):
- go build ./...; go vet ./... (darwin), GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./...; gofmt -l clean.
- go test ./internal/davsync ./internal/cli ./internal/gui: ok (cli
  with the route guard fix committed beside this one).
  TestFollowServer (empty server, join, own change replaced and kept,
  both changed, unchanged sync, Configure keeps it, back to both ways)
  and TestFollowServerSendsNoSignIn are new.
- GUI (node --test, Chromium and WebKit): sync-follow-server (new; en and
  zh, 900px and 400px: name, sub, picked segment, the post, the notice,
  no scroll, no overflow, no select, re-pick posts nothing), plus
  sync-auto-restore, sync-note-show, sync-own-fields, sync-not-backup,
  sync-other-kind, sync-signins, sync-spin, i18n-keys, i18n-en-no-cjk,
  gui-zh-tw, gui-ja, gui-de: all pass.

Broken by hand:
- push guard removed: TestFollowServerSendsNoSignIn red ("sent its
  sign-in: 1 puts").
- follow branch off: TestFollowServer red ("b's own change stayed:
  [deepseek=k1 kimi=kb2]").
- the row's click not posting: sync-follow-server red, 8 of 8.

Not tried: a real WebDAV, S3 or GitHub server (fake servers only); two
real computers; Windows run of the tests (vet only). The full suite starts
after the tag.
2026-11-10 15:43:41 +08:00
yetone 9e51c5c2a8 gateway keys: account groups a key may use or keep out (LeiWang_2000 on X)
LeiWang_2000 asked for account groups, so a gateway key can be limited to
a group of accounts, or keep a group out, instead of picking accounts one
by one (on top of v0.1.3504's "Keep accounts out").

An account group is a named set of accounts of any providers, kept in
account-groups.json beside caller-keys.json (access.AccountGroup). A key's
account list names one as "@<id>" (use only its accounts) or "!@<id>"
(every account but its). identityOf expands the groups of the key and of
its issuer on every request, so every route that reads the Identity
(AllowsAccount, HeldModels, the routes' model checks) holds to the group
as it is now: a membership change reaches every key naming it at once, and
an account signed out since matches nothing. Fails closed: a group gone,
or a used group with no account, holds the key to nothing
(heldToNothing); unreadable groups refuse a key naming one and leave other
keys alone. A group a key names can't be removed (the error names the
keys); ReplaceAccount moves a rotated key in the groups too. Groups are
backed up and synced (WebDAV) with the gateway keys. A magpie older than
the mark reads "@<id>" as an account of no provider and fails closed.

CLI: `magpie gateway-key groups add|set|rename|remove`, and
`gateway-key accounts <id> @Work` / `!@Work`.
GUI: an "Account groups" editor (modal, rows of name + accounts picked in
the app menu) from the keys' header; the key's account menus list the
groups as options; the badge says "Work" / "Not Work". No layout change to
the rows.

Tests:
- internal/access TestAccountGroupHoldsAKey / ...AnIssuedKey: save rules,
  name->id, used+kept-out refused, held/kept-out allows and models, a
  change reaching both keys, rotate, remove refused, empty group, groups
  gone, unreadable groups.
- internal/gateway TestGatewayKeyAccountGroupsKeyedRoutes: a held and a
  kept-out key on 7 routes, flipped by a group change, and nothing asked
  once the group is gone.
- internal/cli TestGatewayKeyAccountGroupsCLI.
- GUI gateway-key-account-groups.test.cjs: 5 languages x chromium/webkit
  x 1100/440.

Broken by hand (each red, then restored):
- identityOf not expanding groups: access test red, gateway test 403.
- a gone/empty held group not becoming heldToNothing: access test red
  ("held to an empty group"), gateway test asked kA with the group gone.

Run on mote at this tree: gofmt -l clean; go vet darwin (touched
packages), GOOS=linux -tags nogui ./..., GOOS=windows ./... clean;
go test -count=1 access, cli, gui (size budgets included), backup,
davsync, gateway: all ok;
GUI: every gateway-*.test.cjs plus i18n-keys, i18n-en-no-cjk, key-page,
plugin-kernel, readable-focus, chromium + webkit: 571 of 574 at
--test-concurrency=6. The 3 reds: gateway-caller-keys and
gateway-key-models chromium en (the 560px read, red on main too, fixed in
the next commit), and gateway-key-groups zh once, 12 of 12 alone (#1974).
Rebased on c4a542466 (regexps made lazy across 157 files): gofmt, darwin
vet, go test of the root (lazyre guard), access, gui, backup, and the
cli and gateway account-group, key and parity tests again: all ok.

Not tried: a real account's requests through a group-held key (fixture
providers only), the Windows box, the real Linux app.
2026-11-10 13:12:52 +08:00
yetone e4197144a8 perf: every package's package-level regexps compile on first use
v0.1.3516 made gateway's and redact's patterns lazy. The other 299
package-level regexp.MustCompile calls, in 148 files across agent,
provider, gui, library, codexcat, sessions, usage, plugin and the rest,
now go through lazyre.New too, so a launch that never reaches them
(`magpie statusline`, run by Claude Code on every message) doesn't
compile them. Fields, maps and params that held them are *lazyre.RE.

Measured on mote (M5 Pro), sandbox HOME, v0.1.3516-equivalent build
(t42) against this one (t43):
- GODEBUG=inittrace=1 sum: 7.39 MB / 69,837 allocs -> 4.62 MB / 46,765
- `magpie statusline`, 3 runs each: instructions retired ~212M -> ~176M,
  peak memory footprint 19.2-19.4 MB -> 16.8-17.0 MB

Run: go vet ./... (darwin) ok; GOOS=windows go vet on each of the 30
changed packages ok; GOOS=linux go vet ok except ., internal/cli and
internal/gui, which stop in wails v3's cgo files when cross-compiled
(the same at main). New TestAllLazyPatternsCompile at the root compiles
all 574 registered patterns (ok), so a bad pattern fails a test rather
than a first use.
Not run before push: the changed packages' own test suites; they run
on mote after it.
2026-11-10 12:54:39 +08:00
yetoneandggbdpq f411bd304c davsync: a part the server file holds nothing in never empties a joining computer (#5642)
Three computers syncing the Library alone: the main one's providers and
routing groups were gone minutes after it joined. An empty computer had
written the folder's file first, and a join takes the remote setup whole,
so its empty providers, groups, settings and library cleared what the
joining computer had (mirror, displaced copy kept in the sync folder).

On a join (no last sync on record), a part the server file holds nothing
of its own in (unset: no providers or groups, the default settings, no
profiles, an empty library) is the folder never having had one, not a
removal: a computer with that part set up keeps it and sends it up.
After the join an emptied part is a removal and spreads as before. The
check is on content, not a hash of an empty bundle: a fresh computer
writes the default settings and an empty-but-present library, which a
nil-bundle hash misses. Agents (which agents a computer has) are left
as they were.

Not changed: providers, settings and profiles still have no tick of
their own; with the Library ticked alone they still sync. A tick per
category is a feature of its own, not this fix.

Run:
- TestSyncEmptyFirstKeepsLaterSetups (new): red with the new case
  disabled ("a after joining's providers: []"), green with it; it walks
  b-empty-first, a joining with a provider, a group, a theme and an MCP
  server, b taking them (key kept on a), a keeping them, and a removal
  after the join reaching b.
- go test -tags nogui ./internal/davsync/ ./internal/library/ on mote.
- gofmt -l on the changed files: nothing.

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

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

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

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

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

Reported-by: 辰林鸭~ (Discord)
2026-11-07 21:21:48 +08:00
yetoneandggbdpq 0f0484c515 davsync: a WebDAV server that breaks on a conditional read is read without one (123pan, #4993)
After the first sync, magpie reads the backup with the version last seen
(If-None-Match, or If-Modified-Since on a server without ETags) so an
unchanged file costs a 304, not a download. 123pan answers that GET 500
after about 30 seconds (the reporter's curl: a plain GET 200, HEAD 200
with a valid ETag, GET with If-None-Match 500), and every sync failed
with "reading magpie.magpie-backup from the WebDAV server: HTTP 500".

A conditional read answered 5xx is now asked again without the
conditions, and the version is marked NoCondRead (kept in the sync
state), so that server is not asked with a condition again. The ETag the
plain read returns is still sent as If-Match on the write, so a write
from another computer in between is still refused as changed. A plain
read that fails is reported as before.

Changed from the contributor's patch: the mark is set on every version
a plain read returns, not only on the fallback read's. In the patch a
sync that read plainly saved an unmarked version, so every second sync
sent the condition again and waited 30s for the 500. The sync test now
runs three more syncs and checks no condition is sent, and checks that
the merged write carries the plain read's ETag as If-Match.

Run (mote): go test -tags nogui ./internal/davsync/ (ok, 56s);
go vet -tags nogui ./internal/davsync/; gofmt -l (empty).
Broken by hand: with the fallback disabled, both new tests fail with the
reporter's own error ("reading magpie.magpie-backup from the WebDAV
server: HTTP 500"); with the contributor's version of get,
TestSync123panConditionalRead fails ("3 conditional GETs after more
syncs, want 1").
Not tried: a real 123pan account (the fake answers as the reporter's
curl showed); whether 123pan honours If-Match on PUT (writes were never
reached in the report).

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-06 10:06:51 +08:00
yetone 1826c4bd99 providers: a Remote magpie that is this magpie says so and is left out, unless kept (hanslin1666)
B uses A through a Remote magpie provider, and sync carries that
provider to A, where it points at A. Each of its models was one of A's
own, listed again beside it and taken by A's found groups, and a request
through it passed through A's gateway twice.

A fetch of a Remote magpie's list now reads its models' magpie_via: when
the magpie that listed them (the last entry) is this magpie's own
catalog.Self, remote-self.json keeps the provider id and the address it
answered at (noteSelf). Another lister, or a list with no via, takes
the record away; an empty list or a failed fetch changes nothing; a
provider moved to another address is not self until a fetch there says
so. The file is this computer's own, never in a backup or sync.

Such a provider is left out (SelfLeftOut in On, SwitchedOff and
remoteMagpies): not in /v1/models, the catalog or a found group. A
request naming one of its models, an agent's pick synced from B, is
served here with the remote's id taken off (ThroughSelf in Resolve and
ResolveRoute), once through the gateway. A 404 for it says why and how
to keep it.

The Providers row shows "This magpie" (greyed while left out), with the
reason as its title; the editor has a note and a "Use it anyway" tick
(KeepSelf, POST /api/provider/keepself). KeepSelf belongs to the user
and to this computer: Mirror and Restore keep the local value (false for
a provider new here), davsync's hashes blank it, and a provider save
keeps it. Strings in en, zh, zh-TW, ja, de.

Docs: providers-accounts.md (two magpies row), sync-backup.md (what
stays on each computer).

Run at this tree on origin/main 4e85cac01:
- gofmt -l: nothing. app.js 1,309,132 bytes (budget 1,316,874).
- mote: go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet of
  provider, gateway, gui, davsync, catalog: ok.
- mote: go test catalog, davsync ok; gui red only in
  TestMainWindowCorners/macOS_26_SDK (#3949, macOS 27); provider and
  gateway did not build there (mote's disk full, "no space left on
  device"), so they were run on:
- Linux (WSL magpie-desktop): go test -tags nogui provider, gateway,
  gui, davsync: all ok.
- Windows (xiaomi-gpu): go test -run 'RemoteSelf|KeepSelf|RemoteMagpie|
  Mirror|KeepLogin' provider, gateway, davsync: ok.
- mote: remote-self.test.cjs 16 of 16 (chromium and webkit, 1100 and
  420, en zh ja de), before the rebase; the rebase touched no line of it.

Broken by hand, each red, then restored:
- noteSelf a no-op: TestRemoteSelfRecord and
  TestRemoteMagpieThatIsThisOneIsLeftOut red.
- ThroughSelf a no-op: the gateway test red (404 for rem/own/m1).
- On() without SelfLeftOut: the gateway test red (listed, 2 passes).
- davsync hashes without the KeepSelf blank: TestKeepSelfIsNoChange red.
- Mirror without keeping KeepSelf: TestMirrorKeepsKeepSelf red.
- The row's badge removed: remote-self.test.cjs red (chromium 1100 en).
- The tick's onchange a no-op: remote-self.test.cjs red (webkit 420 zh).

Not tried: two real computers syncing each other (the case is built in
one process: the gateway test's Remote magpie is its own gateway);
the Linux and Windows apps' webviews; the whole GUI suite (mote's disk is full);
remote-self.test.cjs again after the rebase.
2026-11-05 12:37:30 +08:00
yetone 47d5839397 library: sync and backup files carry the hooks
VincentChan on Discord (v0.1.3005) said part of the Library doesn't reach
his other computer through sync. Checked kind by kind what the library part
of a bundle carries: instructions (each set's text, a linked set's file text,
the agents ticked, each agent's own addition), MCP servers, skills and
subagents all go. Hooks didn't: library.Bundle had no field for them, so a
hook made on one computer never reached the other, by WebDAV/S3/GitHub sync
or a backup file.

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

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

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

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

Not tried: a real WebDAV/S3/GitHub remote between two real computers;
Windows and Linux runs of the Go packages.
2026-11-05 11:29:20 +08:00
yetone 900ae0fa51 backup, sync: sign-ins go too when picked, sealed, never over a later renewal
qianxunji (#feedback) and curtinp118 on Discord: a VPS restored from a
backup, or a new computer joining sync, had to sign in to every
subscription again. Sign-ins (subscription accounts in logins.json,
Codex's auth.json, plugins' sign-ins in plugin-auth.json) can now go too,
in each place only when picked; all are off by default, so an upgrade
carries nothing new.

- Sync (WebDAV, S3, GitHub): a "Sign-ins" tick in the form, with a line
  saying anyone with the passphrase and the server's file can use the
  accounts, and that an account on two computers can be signed out on one
  when the other renews it. CLI: `magpie webdav|s3|github set sign-ins=yes`.
- Export: "With the sign-ins", off; ticked, the passphrase hint says the
  file holds them. CLI: `magpie backup --sign-ins`.
- Import: "Bring in the sign-ins too, when the file has them", on. CLI:
  `magpie restore --no-sign-ins` leaves them out.
- Back up by itself: "Sign-ins in backups", Off/On. On asks for a
  passphrase (twice) that seals the sign-ins alone (the rest of an
  automatic backup stays unsealed, as before); it is kept in
  autobackup.json (0600), never sent in the view. A backup whose sign-ins
  another passphrase sealed restores without them and says so.

What goes (provider.CollectSignIns, plugin.CarriedAuth): magpie's own
copies only, not an agent's own account, an agent-home row, a hidden or
plugin: row, or a retired built-in. Each record is keyed by agent +
email + org (or the account key); ids two rows share go on neither side.

Restore/import (RestoreSignIns) adds what is missing and updates only
when the incoming copy was renewed later; nothing here is removed.
Before writing over a row it counts every row that could be the same
account (same login, same refresh token, same id): none adds, several
keeps all, one is kept when it isn't magpie's own copy, is held, or is
the agent's live account. Codex's auth.json is written temp-and-rename,
0600, only where Codex is signed out.

Sync merges per record against the last sync's hashes (MergeSignIns):
the later renewal wins; a removal crosses only when the other side still
had it as of the last sync; ApplySignIns re-checks each row's hash
before writing so a renewal in between is kept. A computer with the tick
off sends none, so others remove nothing for it; turning it off, a
Restore, or a replaced server file clears the last-sync record.

Export's and Import's forms moved out of app.js into syncfiles.js,
imported when one opens (as autobackup.js is), so the core is 3.2KB
under its budget with no raise (app.js 3.2KB smaller than before).

docs/subsystems/sync-backup.md has a "Sign-ins, when picked" section;
subscription_signin_test.go's header now says it pins the default.

Run at the pushed head (678d28cba on origin/main bc10a6198):
- wsl-run go test -tags nogui -timeout 45m: backup, davsync, plugin, gui
  ok (TestCoreScriptBudget in it). provider: one red,
  TestCancelledPluginSignInSavesNothing, the late sign-in saved after
  Cancel. It is green 20 of 20 alone, at this head and at origin/main
  alike, and this change adds only new files there whose tests run after
  it; filed as #5047. cli there hung in proc.lookStamp's os.Stat on WSL
  at load 100, so it ran again on mote: one red,
  TestEveryRouteHasACommandOrIsNamed (GET /api/context/reply, #5026),
  the same at origin/main. gateway -run TestCompactionOverByteCapEveryTime
  ok (#4862 on mote's full run). TestMainWindowCorners on mote: red the
  same at origin/main (#3949).
- GUI, on mote: the 16 files that open Sync, plus i18n-keys and
  old-webkit, Chromium and WebKit, every language: 255 of 294 pass. The 39
  reds are segs-press-redraw's searchAllRow (#4566), s3-sync in WebKit
  (#2448) and usage-agents-hide (#3414). The same files at origin/main
  bc10a6198 give the same 39 pass and 39 fail. sync-signins, auto-backup,
  sync-sign-in, i18n-keys and old-webkit alone on WSL: 92/92.
- The whole GUI suite on WSL, stopped at 737 of its tests (1162 files,
  load ~100 there): 9 reds, all WebKit, none in a Sync file:
  account-eye (#4244, #5052), add-button (#4792), account-plugin-user
  and agent-expand-steady. The last two pass at this head and at
  origin/main on mote. The rest of the suite was not run.
- gofmt -l: clean. go vet: darwin (internal/gui, internal/cli),
  GOOS=linux and GOOS=windows -tags nogui for backup, davsync, provider,
  plugin, cli, gui: ok.
- win-run and wsl-run: go test -tags nogui -run
  'SignIns|Carries|AutoBackupSignIns' ./internal/provider
  ./internal/backup ./internal/davsync: ok on Windows 11 and Ubuntu 24.04.
- sync-signins.test.cjs: 20/20, Chromium and WebKit, 1100 and 420px,
  en/zh/zh-TW/ja/de, no horizontal overflow, no page errors.

Then rebased on origin/main 5ee5274bd (12 commits; davsync.go, app.js and
i18n.js merged with no conflict) and run again at the pushed head on mote:
gofmt clean; go test -run 'TestCoreScriptBudget|SignIns|Carries|
AutoBackup|Sync' for gui, davsync, backup and provider: ok; sync-signins,
auto-backup, sync-sign-in, i18n-keys, old-webkit: 92/92.

Broken by hand, each red, then restored:
- RestoreSignIns writing an older token over a newer one:
  TestRestoreSignInsNeverWritesAnOlderTokenOver red.
- The ambiguous-account guard has two layers (more than one match, and
  a single match with another record id); with only the first removed
  the test stayed green, with both removed
  TestRestoreSignInsLeavesAnAmbiguousAccount went red.
- MergeSignIns removing a row renewed here: TestMergeSignInsRemovedOnlyWhenTheOtherSideRemovedIt
  red.
- Codex auth.json written over a signed-in Codex:
  TestRestoreSignInsSignsCodexInOnlyWhereSignedOut red.
- ApplySignIns not re-checking the hash: TestApplySignInsKeepsWhatChangedSinceTheMerge
  red.
- davsync forgetting the last-sync record (st.SignIns = nil):
  TestSyncSignIns red.
- GUI: Export's tick on by default, and auto backup's On posting with
  no passphrase: sync-signins.test.cjs red for each.

Not tried: real accounts carried to a real VPS or second computer (all
Go tests use testenv homes, fake DAV and fake tokens; the Keychain is
never reached); a real vendor's refresh after a carried sign-in, and how
each vendor treats one refresh token used from two machines; the CLI
flags against a sandbox HOME (covered by the cli package's tests only);
auto backup's sign-ins have no CLI switch.
2026-11-03 17:24:19 +08:00
yetone 1dead5dc7b provider: magpie's own Codex account switches leave the Codex app running unless Restart the app is ticked (atom0964)
atom0964 on Discord (#help) has two ChatGPT Plus accounts in magpie, with
Codex always signed in to the first and Only switch Codex's sign-in both
off, on Smart routing. The Codex desktop app kept restarting by itself.
They tried several combinations of the ticks and it still did.

Why: with both off, SwitchWhenSpent signs Codex in to the next account at
98% and back to the first below 90%. Each switch was noted for the Codex
app (codexAppSpentSwitch), and KeepCodexAppOnItsProvider ended its
app-server once no turn ran; the ChatGPT app shows that as an error and
relaunches (#4550). With Codex kept on the first account there is no
switch, but the used-up takeover (magpie made Codex's provider for a
used-up account and given back once it has room; f37742e14 only limits
it to when another account can serve, which two accounts always can)
changed Codex's route, and that ended it too. So every combination
restarted the app.

What changed:
- Provider.RestartApp (restartApp), off by default, set by
  provider/restartapp (SetRestartApp, Codex only). This computer's own,
  like KeepLogin: Mirror keeps it and davsync's hash leaves it out.
- switchLoginBy(agent, user, byMagpie): SwitchWhenSpent marks its
  switch magpie's own (codexApp.auto). In codexAppStep, a change that is
  magpie's own (its switch, the takeover in or out, the first look at an
  app on a used-up account) ends nothing unless RestartApp is on; it
  logs why and the app follows once restarted. The switch notice's
  Restart, the Agents row's Restart, and uninstall are unchanged.
- Still restarted: a switch the user makes (Switch, the Agents row, the
  CLI), a Connect or Disconnect, failover written or taken out (any
  route change while the takeover state is unchanged), and a user's
  switch pending when magpie's comes.
- GUI: under Codex's accounts, with more than one on (or the tick set),
  "Restart the Codex app when magpie switches its account", with a tip
  and toasts in en, zh, zh-TW, ja and de. app.js paid for it with five
  account-row comments cut; TestCoreScriptBudget is not raised.
- docs/subsystems/agent-wiring.md says which changes restart the app.

Known edge: a takeover flip in the same 3s tick as a Connect is taken
as the Connect's (restarted), since the route changed by the user.

Run at the pushed head (on mote, rebased on b967b1620; then rebased on 2a19043af, a Library change touching none of these files, with the core budget checked again: 160 bytes under):
- gofmt -l clean; GOOS=linux (-tags nogui) and GOOS=windows go vet of
  provider, gui, davsync clean.
- go test -count=1 -timeout 45m ./internal/provider ./internal/davsync
  ./internal/backup: ok. ./internal/gui: ok except
  TestMainWindowCorners/macOS_26_SDK, red alone on origin/main 694f4a6d6
  too (#3949). ./internal/cli: ok except TestEveryRouteHasACommandOrIsNamed
  on GET /api/context/reply (#5026).
- GUI (chromium + webkit, 1100 and 420 wide, en/zh/ja/de):
  restart-app (new), switch-only, claude-switch-only, keep-login,
  codex-accounts-via, account-arrange, i18n-keys: 110/110 and 94/94.
  account-arrange's webkit case went red once in a 5-file run on an
  aborted /api/lanes request; it passes alone on origin/main and at
  this head.

Broken by hand:
- codexAppStep's guard turned off: TestCodexAppLeftRunningForMagpiesOwnChanges
  and TestCodexAppFirstLookLeftRunning go red (ended [60]).
- SwitchWhenSpent marking its switch as the user's: TestCodexSwitchedWhenUsedUp
  goes red ("magpie's own switch is counted the user's").

Not tried: a real ChatGPT desktop app on a real used-up account (the
app-server end is stubbed as before); Windows, where the app is quit and
reopened (CodexAppReopen runs only after an end, so leaving it running
skips it too); no CLI command for the tick (switch-only has none either).
2026-11-03 16:34:30 +08:00
ggbdpq cc22efebb7 davsync: a 403 on the write names the folder it went to, and a full quota (#4927)
The error for a write the server refused, with the address's folder
listing fine, said the account couldn't write in that folder (/dav) -
but the write went to magpie's own folder inside it, and the listing
never proved anything about writing. On 坚果云 (Nutstore) the refusal
is usually the free tier's upload quota used up, which answers 403 on
a PUT with everything else fine (#4927), so the old text sent the user
to check a thing they can't check.

The error now looks at magpie's own folder first: there, the server
refused to change files in it, and the text says so and mentions the
quota; missing, the server refused to have magpie make it, and the
text says to make the folder by hand, or put an existing folder in
the address.

Review, changed from ggbdpq's patch: the folder is named with
path.Join(dir, folder). The patch's dir+"/"+folder said "//magpie"
for an address with no folder of its own (dir "/"). The test now
covers that address too. Broken by hand at the reviewed head:
dir+"/"+folder back, TestDAVWriteRefused red; dav.go reverted to its
parent, red; restored, green.

Run at the pushed tree (this stack of nine on origin/main 3c2dceb34),
on mote (macOS arm64, Go 1.26.8):
- go test -count=1 -timeout 45m ./internal/catalog/...
  ./internal/plugin/... ./internal/davsync/... ./internal/gateway/...:
  catalog, plugin and davsync ok; gateway red on one test only,
  TestCodexPoolSaysTheClientsVersion, the open #4807 (another test's
  Codex identity reaches it in a full package run). It passes run
  alone at this tree, 3 of 3.
- go vet ./... (darwin); GOOS=linux and GOOS=windows go vet -tags
  nogui ./...: ok. gofmt -l on every tracked .go file: clean.
- The hand breaks above ran on this stack before its rebase onto
  3c2dceb34. That commit changed member.go only, nothing these tests
  reach.
Not tried: the GUI suite, since no GUI file changed. Windows and Linux
test runs (the Claude bridge tests use a shell fake and skip on
Windows). No real vendor, Claude Code or network was used; every
case runs against fakes.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-03 07:43:18 +08:00
yetone 2ab9235711 agents: an agent's picks can be kept to this computer, as an MCP server can
chenxiang0010 on Discord: 「agent当前选择的模型可不可以像mcp那样 只对当前设备生效」.
Sync carries every agent's picks (model, effort...) between computers;
an MCP server has an opt-in "This computer only" that sync and backup
files never carry. Agents now have the same: the row's menu (right-click
or ...) has This computer only, off by default, so an upgrade changes no
pick on any computer.

- settings: AgentsHere, this computer's own (KeepOwn), and kept by a save
  of the Settings page (settingsapi.Apply), which doesn't send it.
- davsync: each kept agent adds "<id>.*" to the own set (withHere, isOwn),
  so a sync neither pushes its fields nor brings the server's; a Restore
  from the server leaves them. sync-state.json records the list as of the
  last sync (Here): hashes before a sync use it and after use the current
  list, so turning it on or off is no change on either side, and a changed
  list forces the sync past its early returns. Turned off, the next pick
  goes up again. Other agents still sync both ways; the implicit own
  fields (hayden4608) are unchanged.
- backup.Restore skips a kept agent in a backup file.
- gui: POST /api/agents/here; the row says "This computer only" beside
  the version (hidden in the tray panel and in a narrow row), menu ticks.
  Core words moved from the library plugin's i18n into core i18n
  (zh/zh-TW/ja/de). Comments in renderAgents cut to pay for it under the
  core budget (no raise).
- cli: the route is named under stage 3 (no command yet).
- docs/subsystems/sync-backup.md describes it.

Run on mote, at the base eb8b840dd (Go and the GUI files below) and again
at this head's base for internal/gui (core budget) and agent-here,
i18n-keys, agent-menu-label:
- go test -tags nogui ./internal/davsync ./internal/settings
  ./internal/backup ./internal/gui ./internal/settingsapi: ok
- go test ./internal/cli: ok but TestEveryRouteHasACommandOrIsNamed,
  red on main for POST /api/usage/checkin-account alone (#4826)
- GOOS=linux and GOOS=windows go vet ./...: ok; gofmt -l: clean
- GUI, chromium + webkit: agent-here (en/zh/zh-TW/ja/de x 1100/640/360),
  i18n-keys, sync-own-fields, mcp-local-server, agent-menu-label:
  90/90 ok
- the whole GUI suite: cut off at test 3783 by a session restart; the
  rest (key-* on) is still running at push. Reds seen so far, under
  three GUI suites at once on mote, none in an agent file: account-eye,
  balance-fix (Sub2API, /api/user/self), codex-auto-reset, context-map,
  editor-advanced-align; being checked at main and filed there.

Broken by hand, each red then restored:
- hereOf returns nil: TestAgentHereThroughSync "B's kept picks went up"
- backup.Restore's kept skip off: "B after a backup file"
- KeepOwn line dropped: TestAgentsHereIsThisComputers "another
  computer's kept agents came in"
- TestSettingsSaveKeepsWhatItDoesNotSend went red on this change before
  settingsapi kept AgentsHere (a Settings save would have dropped it).

Not tried: a real two-computer sync with real accounts; no CLI/TUI
command for the flag; Settings -> Sync doesn't list kept agents; WSL
agent ids (codex@wsl:...) only through the key format.
2026-11-03 02:27:20 +08:00
yetoneanderlinerd 1cb4d43013 profiles: a saved profile renames, in its details, the TUI and magpie rename (#2721, erlinerd)
erlinerd's patch on #2721 (profile.Rename, /api/state profile/rename,
a Rename button in the details), reviewed against main and adapted:

- profile.Rename trims both names, refuses an empty, taken or missing
  name and leaves profiles.json as it was, renames by case only
  (home -> Home), and keeps what the profile holds.
- GUI: Rename turns the details' name into a field. Enter renames
  through profileAction, so the chip is renamed at once, pending, and
  rolled back with the error if magpie refuses; the details stay open
  under the new name, with In use kept. Escape or a click away puts
  the name back. The field lives in profilerename.js, imported on
  press, so the core script stays under its budget (no raise; 50 bytes
  under after comments in app.js were cut). While the field is open
  In use, Apply and Rename hide so a 360px panel's field has room.
- TUI: ctrl+e on a profile renames it on the name line.
- CLI: `magpie rename <old> <new>`; a flag is never taken for a name.
- WebDAV: a rename syncs as the old name gone and the new one in
  (davsync test).

Run on mote at 47672f11c (on 70b96126e), and again after rebasing on
52195b6b0 (backup), as 3b279fdee:
- go test ./internal/profile ./internal/cli ./internal/gui ./internal/tui
  ./internal/davsync: ok except TestEveryRouteHasACommandOrIsNamed
  (#4826) and TestMainWindowCorners (#3949), both red on origin/main
  07f4d46c5 too. gofmt clean; GOOS=linux (-tags nogui) and
  GOOS=windows go vet ok.
- GUI, chromium and webkit: profile-rename (en, zh, zh-TW, ja, de;
  900x560 window and 360x420 panel), panel-profiles, profile-confirm,
  profile-in-use, profile-details, hermes-profiles,
  view-wheel-after-click, i18n-keys, gui-de, gui-ja, gui-zh-tw,
  editor-roomy: 219 pass, 0 fail. After the rebase: profile, cli,
  gui, tui and vet again (same two reds only, core budget ok), and the
  GUI files above with auto-backup in place of editor-roomy: 161 pass.
  Then rebased over ea51526b6 (gateway, plugin, provider only; no
  file of this change, no GUI asset) without another run.

Broken by hand, each red, then restored:
- Rename comparing names with EqualFold: TestRename red (case-only).
- Dropping the CLI's "-" check: TestRenameCommand red.
- Dropping `profileOpen = to`: profile-rename 22 of 22 red, both engines.

Not tried: the real app on Linux (WebKitGTK) or Windows; a rename
synced over a real WebDAV server.

Co-authored-by: erlinerd <erlinerd@outlook.com>
2026-11-02 18:37:25 +08:00
ggbdpqandyetone 3ed3605ba0 netproxy: a global proxy switch drops the idle connections of the sync and the icon fetch (#4824)
ggbdpq's patch (gua2100 on Discord), reviewed and landed with test
changes.

What changed
- netproxy.Watch gives the dispatch's per-request check for a moved
  global proxy (#4523) to transports magpie keeps for itself. The sync
  (davsync) uses http.DefaultTransport, so when one of its requests
  finds the proxy moved, it now drops the idle connections itself.
  Before this, only a DefaultClient request dropped them, and a backup
  kept going through the old proxy's HTTP/2 connection.
- FetchIcon now closes the pool of the client that only the fetch used.
  Nothing closed it before.
- Review changes: the davsync test restores settings.json afterwards,
  and the icon test's wait for idle is bounded at 20s, not 2s, to leave
  room under load.

Run at the pushed head (on mote, base 4d55a0a02)
- go test -race passes for netproxy, davsync and provider's touched
  tests.
- go test -tags nogui -count=1 -timeout 45m ./... passes every package
  except two reds already filed and not touched here:
  - internal/cli TestEveryRouteHasACommandOrIsNamed (#4826, red on main
    since e87140242);
  - internal/gateway TestCodexPoolSaysTheClientsVersion (#4807, another
    test's Codex identity, passes alone).
- gofmt -l is clean. go vet ./... passes for darwin, for GOOS=linux
  (-tags nogui) and for GOOS=windows, and so do the linux and windows
  builds.

Broken by hand
- With stall.go's move check off, TestGlobalSwitchDialsTheSyncThroughTheNewProxy
  is red: "1 connections through A, 0 through B".
- With FetchIcon's CloseIdleConnections removed,
  TestFetchIconLeavesNoIdleConnection is red: "the fetch's connection is
  still idle".
- With Watch never reporting a move, TestGlobalSwitchDropsTheOldProxyConnections
  and TestWatchSeesTheGlobalProxyMove are red.

Not tried: a real proxy switch with a real WebDAV/S3 target or icon
host, or Windows/Linux at run time (vet and build only).

Co-authored-by: yetone <yetoneful@gmail.com>
2026-11-02 09:11:30 +08:00
ggbdpq a73df419d8 davsync: a GitHub blob POST on a slow but live line is no longer cut off at 30 s
What changed: the stall watchdog saw a request as one whose body may
outlast the whole metadata limit only by method (GET, PUT), and gave every
other request a flat 30 s (#657's rule held for WebDAV and S3, whose
remaining requests move a few KB at most). GitHub's uploads ride a POST:
each blob POST hauls up to 16 MiB of file as about 21 MB of base64, and a
flat 30 s needs 550 KB/s to get one part through (#4576: on a slower line
the sync failed on the same POST at every attempt, automatic, at start and
manual, and never recovered -- the usage day file froze in the morning
while the machine kept working). A request hauling a big body (64 KiB or
more) now gets the same moving-aware budget as a PUT: the watchdog is put
back each time bytes move, and after the body is all handed over the
answer gets 60 s on top of as long as the write took. The metadata
requests (the GitHub tree, commit and ref POSTs and PATCH, WebDAV
PROPFIND/MKCOL/MOVE/DELETE -- kilobytes at most) keep their 30 s in all.

Run: TestGitHubSlowBlobUploadIsNotCutShort (a 272 KB base64 body through a
line at 320 KB/s, watchdogs shortened to 1 s/300 ms) fails on the old code
with "the server didn't answer in 300ms (POST)", the shape of #4576's
error, and passes now; TestGitHubSmallPostKeepsTheLimit pins the small
POSTs to the old limit either way. go test -tags nogui ./internal/davsync,
vet and builds for darwin, GOOS=linux and GOOS=windows pass. Not tried
against a real slow line to GitHub.

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-02 05:38:10 +08:00
yetone da275848b6 tray: Windows shows a card's number in its icon (Benjaminliang_1 on X)
Windows' notification area shows no text beside an icon, so with a card
in the tray the icon itself is now the first card's figure: the first
row of the first card whose first row is a percentage, used or left as
Allowance display has it, its digits alone (trayIconFigure). It is drawn
in Segoe UI Semibold (Go's bold if the font can't be read) at
SM_CXSMICON, white on a dark taskbar, near black on a light one, as tall
as fits, centred by its ink, three digits narrowed into the square
(trayNumberIcon). It is drawn again when the figure, the icon size or
the taskbar theme changes (SystemThemeChanged wakes the loop); the
tooltip still lists every card. A balance or magpie's totals are
skipped; with no such card, or no cards at all, the icon is the bird as
before. Settings > Usage > Tray icon number (settings.TrayNoNumber,
Windows only, on by default, kept per computer) keeps the bird when off;
Menu bar windows is now shown on Windows too, since it picks the row
the number comes from. The number row sits after Menu bar cost, so the
bird > pace > cost order the other tests pin holds. Linux and the Mac
are unchanged. New words in zh, zh-TW, ja and de. app.js stays in the
core budget with one comment shortened, no raise.

Run at this commit on origin/main ec104b862 (traywindows.js merged with
94f6f6092's trayExtra pills; its "not on Windows" note dropped), mote:
gofmt -l empty; go vet and GOOS=windows go vet of gui and settings ok;
go test -count=1 -timeout 45m ./internal/settings ./internal/davsync
ok; ./internal/gui red only on TestMainWindowCorners (#3949),
TestCoreScriptBudget ok. GUI tray-windows, tray-cost, quota-pace,
i18n-keys, tray-bird, tray-logos, tray-usages, quit-ask: 140 pass,
0 fail. win-run on xiaomi-gpu: TestTrayNumberIcon and
TestTrayIconFigure ok. At c0477aa72 the same GUI set once had
quota-pace webkit "On moved the page" (439 !== 120), a late wheel
(#4784); green twice after, and quota-pace alone 3 of 3 green there
and on c0477aa72 itself.

Run before on the same change over origin/main 9d08993c8, mote:
- gofmt -l on gui/settings/davsync: empty; go vet ./internal/gui
  ./internal/settings and GOOS=windows go vet: ok.
- go test -count=1 -timeout 45m ./internal/gui ./internal/settings
  ./internal/davsync: settings ok, davsync ok; gui red only on
  TestMainWindowCorners/macOS_26_SDK (#3949) and TestCoreScriptBudget
  (5 bytes over after the rebase), which is green after the comment
  trim, rerun with TestTrayNumberIcon and TestTrayIconFigure: ok.
- GUI (both engines): tray-windows, tray-cost, quota-pace: 56 pass,
  0 fail. Earlier at this tree: tray-bird, tray-logos, tray-usages,
  i18n-keys green; quota-pace webkit de 420 red once, from a late wheel
  scroll (#4784), green on the rerun; segs-press-redraw red on
  searchAllRow, the same on a clean origin/main 9d08993c8 copy (#4566).
- A 184-file GUI run (the files touching Settings, the tray or i18n,
  before the rebase) under mote load 40-90: 3095 pass, 224 fail. My
  files' reds there (tray-cost: the number row was between pace and
  cost) are fixed above. The rest are in files this change doesn't
  reach (account-alias, model chips, menu-input-scroll, mobile-web,
  omarchy, plugin-github, key-replace, context-map and others; #4600
  lists several). Each was not compared on main one by one.
Windows (win-run on xiaomi-gpu, real Segoe UI): TestTrayNumberIcon and
TestTrayIconFigure ok.
Real Windows 11 run: a production build in a portable sandbox (own
data\, USERPROFILE/APPDATA/LOCALAPPDATA redirected, gateway on a free
port, a fake remote magpie serving one Claude card). The dark taskbar
showed a white "42", then a narrowed "100" when the card read 100%,
and the bird with trayNoNumber set. Only my processes, tasks and
NotifyIconSettings entry were removed afterwards.

Broken by hand: trayIconFigure always "" turns TestTrayIconFigure red
(6 cases); the dark and light colours swapped turn TestTrayNumberIcon
red; the old advance-width centring turns it red too.

Not tried: a light taskbar on the real box (it would change the user's
theme; covered by the test only), hovering the tooltip (screen locked),
other DPIs on real hardware, Windows on ARM64. Linux's code is
unchanged and was not run.
2026-11-01 21:31:55 +08:00
yetone 1576ccdbbc davsync: the sync setup is read once a request, not on every Providers poll
/api/providers asks archiveState, which asks davsync.S3Bucket and so
Load, on every poll, and Load opened sync.json each time, most often a
file that isn't there. In a profile of 200 lists against a copy of the
owner's real config it was 0.19s of 4.07s.

Load now reads the file's bytes through filememo (once until it
changes, remembered missing while a request holds it) and unmarshals a
Config of its own for each caller. Configure and Restore write through
edit.WriteAtomic, which forgets already; Off removes the file and now
calls filememo.Forget too, so sync turned off in a request is off for
the next Load in it.

Run (on mote unless named):
- go test -count=1 ./internal/davsync ok (36.9s); ./internal/gui red on
  TestMainWindowCorners only (macOS 27 on mote, #3949); GOOS=linux and
  windows go vet ./internal/davsync ok; gofmt clean (here).
- New TestLoadReadOnceARequest, -count=3 ok: 20 loads in one held
  request read once, a caller's change stays its own, and Off is seen
  at once. Broken by hand: Load reading the file each time -> "read 20
  times, want 1"; no Forget in Off -> "still on after Off".
- Here, 200 GET /api/providers on the sandbox with the real config
  copy (offline, proxy :9): davsync.Load 0.19s -> gone from the
  profile; total CPU within this machine's noise (4.53s -> 4.62s).
- Then rebased onto 8d8df0639 (nothing in internal/davsync or filememo); not rerun.

Not run: the full ./... suite; a real WebDAV or S3 sync (the write
paths are unchanged).
2026-11-01 13:46:44 +08:00
yetone a511b11d8b sync: an agent's model set back on a computer after a sync stays that computer's (hayden4608)
hayden4608 on Discord syncs two computers through GitHub, both with
Codex, and wants each one's Codex default model kept apart. Until now
the agents part carried every agent field ("codex.model", effort,
provider...) as one set: A's pick went up, B's sync brought it over B's,
B's pick went up again and A's next sync took it back. The two
computers fought, and the only way out was turning "agents' models"
off for every agent.

Now a sync that brings an agent field over this computer's value
records what it brought (Brought) and what it wrote over (Replaced,
only when that was picked here, not itself brought). If the user then
sets the field back to the value the sync replaced, the field is this
computer's own (Own): it leaves the hashes, a sync no longer brings it,
and a push keeps the server's value, so the other computer is not
changed either. Every other new pick is an ordinary pick and still goes
both ways, so a computer that changes the model for everyone (and
TestSyncAgentDefaults' reset) still reaches the rest. Nothing to set
up: the user's own act on this computer decides it, and a synced value
never overrides it again.

Settings > Sync lists the kept fields in one row ("Kept on this
computer: Codex model ...") with a "Follow the others" button
(davsync/follow), which brings the server's values on the next sync and
ends the keeping. Restore brings everything and ends it too. The row is
drawn only while sync and agents' models are on and something is kept;
plain row and button, no new layout. app.js grew 623 bytes; the budgets
are raised by that with a note.

Tests:
- internal/davsync/own_model_test.go TestOwnModelStaysOnEachComputer:
  two sandbox HOMEs (CODEX_HOME per computer) on the GitHub fixture.
  A picks a1, B joins and gets it, B picks b1 (goes up), A gets b1, A
  sets a1 back (own; the server keeps b1), B picks b2 + effort +
  provider (A gets effort and provider, keeps a1), A picks a2 and a
  Claude model (both go up, B gets them), A follows (gets b2), B's b3
  reaches A. TestNewPicksStillGoBothWays: alternating new picks always
  reach the other computer.
- internal/gui/tests/sync-own-fields.test.cjs: the row in en, zh,
  zh-TW, ja, de at 420px, no overflow, Follow posts once and the row
  goes, no scroll; no row without own fields or with agents off.

Broken by hand, each red: noticeOwn off (own_model_test:122); any pick
after a sync counts as own (TestSyncAgentDefaults and own test:106);
keepServersOwn off (:166); the bring ignoring Own (:146); withoutOwn
off in the hashes (:143, a notice); Follow off (:182).

Run at this head (rebased on 47173f593) on mote:
gofmt -l internal/davsync internal/gui clean; go vet ./..., GOOS=linux
go vet -tags nogui ./..., GOOS=windows go vet ./... ok; go test
./internal/davsync ok, ./internal/backup ok, ./internal/gui ok but
TestSettingsSaveKeepsWhatItDoesNotSend (#4514, red on main) and the
eleven real-window AppKit tests (dock, panel, tray, corners), which
time out on mote at origin/main 47173f593 too (#4125, #2645);
-run 'Budget|Sync|Backup|Settings' passes TestCoreScriptBudget.
GUI (node --test): sync-own-fields, sync-note-show, github-sync,
s3-sync, sync-other-kind, sync-not-backup, sync-auto-restore,
sync-usage-error, i18n-keys. Chromium on mote: all pass but
sync-not-backup and sync-usage-error, whose chromium.launch({channel:
"chromium"}) segfaults on mote at origin/main 47173f593 too; on the
WSL box (magpie-desktop) they pass, 25 of 25 with sync-own-fields.
WebKit on mote hangs on launch for every file, untouched ones too; on
WSL all nine files ran: 49 of 52, the reds being i18n-keys' "a
plugin's words are its own" (#4524, red on main) and the first
page.goto of sync-own-fields and sync-note-show at 5s under nine
files at once, which pass run alone (9 of 9).
Red on main and not from this change: TestSettingsSaveKeepsWhatItDoesNotSend
(#4514), i18n-keys "Unmarked" (#4524).

Not tried: a real GitHub repo and a real Codex on two computers; the
CLI has no follow command (only the GUI and Restore end the keeping);
Undo after a Restore doesn't bring Own back.
2026-10-31 18:01:04 +08:00
yetone 07a3312c53 library: sync and backup files carry the subagents
xixi_Sean_ on X asked why Sync leaves the Library's subagents out. There
was no reason: the library part of a bundle now carries them.

- library.Bundle.Subagents (*[]*Subagent): name, description, prompt,
  the skills and MCP servers named, the agents ticked. Collect always
  sets it, empty too. Applied.Subagents (which files magpie wrote here
  and their hashes) stays out: each computer writes the files into its
  own agents on the sync Put runs and records its own, so a file the
  user edited there, or one of theirs by the same name, stays theirs.
- Put replaces the subagents with the bundle's, so one taken out on one
  computer goes from the others. A nil list (a bundle from a magpie
  before this) is unknown and keeps this computer's.
- check refuses a subagent whose name isn't one (it is a file name in
  every agent) or comes twice; agent ids are carried as they come, so a
  newer magpie's tick for an agent this one can't give subagents to
  stays and writes nothing here.
- davsync: an empty list hashes as before the field, so upgrading with
  no subagents syncs nothing.
- backup files go through the same Collect/Put; the CLI's backup line
  counts subagents. The GUI's sync/export/import ticks say "instructions,
  MCP servers, skills and subagents" in every language.
- webdav-settings-refresh's "Agents" tick locator also matched the
  library tick's "subagents": it now asks for "Agents' models".
- library.md and sync-backup.md updated. Hooks still aren't carried.

Run (rebased on 0bf5adb11; Go runs at e0c57ffe2, same diff):
- mote: go test -tags nogui ./internal/backup ./internal/davsync
  ./internal/cli ok; ./internal/library -run 'TestCarry|TestSubagent|
  TestLocalServer|TestPutKeeps|TestPutSame|TestRestoreKeeps' ok
- wsl-run (Linux): ./internal/library ./internal/backup ./internal/davsync
  whole packages ok
- win-run (Windows): the same three, -run 'Subagent|TestCarry|TestLibrary|
  TestSyncLibrary' ok
- go vet -tags nogui for darwin, GOOS=linux and GOOS=windows on the four
  packages ok; gofmt -l clean
- GUI (wsl-run, Chromium + WebKit, every language): i18n-keys,
  github-sync, s3-sync, sync-auto-restore, sync-not-backup,
  sync-other-kind, sync-sign-in, sync-spin, sync-usage-error,
  webdav-settings-refresh, library-backups-top, gui-de, gui-ja,
  gui-zh-tw, settings-search, settings-sections: 170/173, then
  webdav-settings-refresh green after the locator fix. The one red left,
  i18n-keys "a plugin's words are its own" ("Unmarked" in
  plugins/routing/i18n.js), is on main already: #4524.
  mote ran five other GUI suites at load 18, where every WebKit
  github-sync case timed out at launch, so the GUI run moved to Linux.

Broken by hand: with Collect not setting Subagents and Put ignoring
them, TestCarrySubagents, TestCarrySubagentKeepsUsersFiles,
TestCarryNewerSubagents, TestBackupFileCarriesSubagents,
TestSyncSubagents and TestNoSubagentsHashAsBefore went red; with Put
treating a missing list as empty, TestCarryOldBundleKeepsSubagents and
TestBackupFileCarriesSubagents went red.

Not tried: a real WebDAV/S3/GitHub remote between two real computers;
the fake DAV server carries it between two sandbox HOMEs.
2026-10-31 13:14:16 +08:00
yetone 7d4a631480 tray: pick which of a subscription's windows the menu bar shows (StrikingRaw on X)
Claude Pro's menu bar card drew its 5-hour and 7-day windows as two
small stacked numbers, and the user wanted one of them alone. Settings ›
Usage › Menu bar windows (under Allowances in the menu bar) lists a pill
per ticked subscription with two or more windows ("Claude Code · All
windows"), opening the app's menu: All windows, then each window. The
choice is settings.TrayWindows, by provider id (every account of it, the
in-use "|*" card too) and by window kind from the span ("5h", "1d", "7d",
"month", "15m", "name:<name>" when the span is unknown), so a vendor
reordering windows changes nothing. Unset shows every window as before;
a pick whose windows are all gone shows every window again, never an
empty card. Only the bar's rows and the Linux label are filtered; the
tooltip still says every window. One row draws at mpRowFont's 11pt
single-row size. Hidden on Windows (its tray shows no text). Per
computer through KeepOwn. The GUI learns kinds from trayKind on
/api/usage/quotas (withTrayKinds; model and aside windows get none). The
row's code is a lazily imported traywindows.js, so the core script
budget is not raised (app.js +4 lines for the call and the prefs keep).

Run:
- mote (macOS): go test -run 'TrayWindow|TrayUsage|WithTrayKinds|
  CoreScriptBudget|AppScript|TrayImage' ./internal/gui/ ok;
  ./internal/settings/ ok; davsync TestSync ok. TestTrayImageOneWindow
  draws through AppKit: Claude's card one line ("42%"), both windows two;
  the PNGs were looked at.
- mote: gofmt -l empty; 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.
- magpie-desktop (Linux VM), --test-concurrency=1, BROWSER=chromium and
  webkit: tray-windows (en, zh, zh-TW, ja, de; picking All; hidden on
  Windows / single-window / no cards; 360px narrow), i18n-keys,
  old-webkit, tray-usages, tray-logos, tray-cost, quota-pace: 43/43 each.
After rebasing on ec5571d6f: the focused Go run above, davsync and vet of
the touched packages ok on mote; tray-windows, i18n-keys, old-webkit,
tray-usages 27/27 in chromium and webkit on the Linux VM.
Broken by hand: the row filter in trayCardText off -> TestTrayWindowsPicked
and TestTrayImageOneWindow red; trayWindows out of prefsKeep ->
tray-windows.test.cjs red in every language. Restored, green.
Not run: the full Go suite (owner: ship each verified fix at once; mote
was at load 20-27 under another session's full GUI suite) and the whole
GUI suite. The GUI ran on the Linux VM because mote's browsers crash or
hang under that load (#4125; TestTrayCellClickReleasedPanel is red the
same way on origin/main c84c3e1c0 there).
Not tried: the live app's real menu bar with a signed-in Claude account
(the AppKit drawer was exercised in-process instead); Linux tray label
on a real desktop.
2026-10-30 23:14:08 +08:00
JoeyWu-tech 93970cae48 davsync: the newer-change tests date this computer's change as finely as the other's push (#3420)
When both sides changed a part, the newer stays: this computer's
change wins when changed(p), the part's file time here, is After
remote.Created, the other computer's push, taken with time.Now(). A
file's time comes from the kernel's clock, which moves in ticks (4 ms
at HZ=250 on this Linux box) and is behind time.Now() by up to a tick
or two: of 20,000 files written right after a time.Now(), 19,954 to
20,000 had a modification time before it, by up to 8 ms.

TestSync ("…and the newer one stays") and
TestSyncTeraCloudStillSeesOtherWrites save this computer's change a
few ms after the other's push and expect it to be the newer. A save
inside the push's tick reads as the older, and the other's copy
replaces it:
  davsync_test.go:309: newer here: &{... Here:[settings] There:[] ...}
  teracloud_test.go:303: a wrote over b's providers without seeing
    them: &{... Here:[providers] There:[] ...}
TestSync was red so in 3 of my full suites (10-19, 10-20, 10-23).
Alone on b437e4ad, -count=100: TestSync red 13 times,
TestSyncTeraCloudStillSeesOtherWrites 21. With the gap from the push's
Created to the saved file's time logged, every red run had a gap of
0 or less (down to -1.9 ms and -3.2 ms), and no green one did.

Each test now dates its change to time.Now(), the clock the push's
Created comes from, right after the save (os.Chtimes, as TestSync
already dates its older change an hour back). The rule itself is
unchanged: a change inside a tick of another computer's push is as
good as at the same moment, and two computers' clocks differ by more.

What was run (tree 77adaa75, on b437e4ad):
  the tick injected, on b437e4ad: the save dated 1 ms before the
  push's Created. -count=20 of both tests: red 20 of 20 each, at
  davsync_test.go's newer-here check and teracloud_test.go's
  wrote-over check
  with this change, -count=200 of both: ok
  broken by hand, with this change:
    davsync.go's both-changed case never taking this computer's:
      davsync_test.go:316: newer here: ... Here:[settings] There:[]
      teracloud_test.go:310: a wrote over b's providers without
        seeing them: ... Here:[providers] There:[]
    always taking it:
      davsync_test.go:294: older here: ... Here:[] There:[settings]
  gofmt -l internal/davsync: nothing
  GOOS=linux, darwin, windows go vet -tags nogui ./internal/davsync:
  exit 0
  full suite, go test -tags nogui -count=1 -timeout 45m ./...
  (go1.26.8, 467 s): 62 packages ok, internal/davsync among them. 16
  reds in 7 packages, none in a file this change touches:
    internal/agent TestInstalledVersion, TestHowInstalled,
    TestOmpDetectedWithPiDir, TestCursorFolderFromTheEditorIsNotTheCLI,
    TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
    TestQoderSettingsFromAnIDEPluginIsNotTheCLI and TestZedAppPath:
    proc.Look keeps "not found" for a tool written in the tick of its
    folder's last change (#3141).
    internal/agent TestReasonixCLIRequiresSupportedNativeVersion and
    TestReasonixCLIRecoversAfterProbeTimeout: their fixture build under
    /tmp meets a /tmp/.git that isn't a repository of this user's
    ("error obtaining VCS status: exit status 128").
    internal/claudebridge TestCallbackGoesPastTheAgentsProxy,
    internal/gateway TestClaudeToolCallbackOnANonLoopbackAddress,
    internal/gui TestGatewayHeldByAContainer and
    TestGatewayFixQuitsOnlyAMagpie: the processes this run started had
    their outgoing connections sent through a proxy (graftcp).
    internal/edit TestWriteAtomicReadOnlyHardLink and internal/testenv
    TestProgram: umask 077 here; the fixtures' own modes go through it
    (0444 is written as 0400).
    internal/netproxy TestBunProxyLoginWithReservedCharacters: Bun
    1.3.11 on PATH names port 80 in the request line (#3397).
Not tried: macOS, Windows.

Landed by yetone in a batch of Coffemon's patches from the issues.
What was run, go1.26.8, on origin/main cc81ad4ea, then again at
70a0c387c (gofmt, the three vets, the changed tests, umask 077):
- mote (macOS 27): gofmt -l clean; go vet, GOOS=linux go vet -tags
  nogui and GOOS=windows go vet ./...: ok. edit and testenv at umask
  077; agent, provider, library and gateway with an empty .git above
  TMPDIR; davsync, imagemcp, plugin, library, edit, testenv whole; the
  changed tests in agent, provider, gateway and gui; the timing tests
  -count=10 (gateway, davsync, imagemcp) and -count=5 (agent): all ok.
  TestCoreScriptBudget ok: core 1,536,751 of 1,537,034, app.js
  1,312,975 of 1,315,316, no budget raised.
- Red on the old code: on origin/main, TestWriteAtomicReadOnlyHardLink
  at umask 077 and two Reasonix tests under an empty .git; on Linux
  (wsl-run) TestProgram at umask 077 with the old program.go. With
  each fix's code taken back to main's, the Gemini imageConfig tests,
  TestPluginToldWhereTheAgentWorks, TestSkillRepoTraced,
  TestTaggedHooksAlone, TestMainURL/TestMainView and update-auto,
  plugin-github-hooks, plugins-more-discover, plugin-namesake were
  red. Broken by hand: claudeKeyed always true (both
  OwnEndpointNeverAsked tests red), claudeAsk a no-op
  (TestClaudeFirstWriteAsksTheProxy red), GitAt taking any .git folder
  (the three TestGitOnDisk tests red).
- GUI: 123 files (plugins*, update-*, panel/tray/start/context, i18n,
  gui-zh-tw/ja/de and every file that evals app.js parts) in WebKit on
  Linux (wsl-run). 11 files had reds (click-scroll, panel-fold,
  plugin-card-update, plugin-github, plugin-move*, segs-glide,
  tray-totals, update-*), and run again side by side they fail the
  same on origin/main d80d75f30 (79 pass, 26 fail here; 78 and 27
  there). They are click-scroll guards ("the click must not scroll
  the page"), varying by language from run to run (#4385).
  copilot-ghe's route-after-close red is #1949, seen on main 244d80e23
  too. In Chromium on mote, Chromium segfaulted partway through files
  (#4125): context-map, context-scroll-end and context-tune fail the
  same on origin/main 0911a65e7, so the batch's own files
  (plugin-namesake, update-auto, plugins-more-discover,
  plugin-github-hooks) ran in Chromium on Linux: 62 of 62.
- Full suite (go test -tags nogui -count=1 -timeout 45m ./..., mote)
  at 472a0608f (on 70a0c387c): every package ok but internal/gateway,
  whose five reds were #4362's (Antigravity turned-away and
  TestCodexSpentGrokFailingIsTold), fixed on main in d80d75f30. After
  the rebase on 244d80e23 the five pass, and gofmt, the three vets
  and the targeted runs above were run again: ok. In Linux the
  sign-in, copilot, plugin-github*, plugins-more-discover,
  plugin-namesake, plugin-gateway, update-auto, quota-refresh-order
  and i18n files ran in both engines: 475 pass, 4 fail (copilot-ghe
  #1949, plugin-github's click scroll, both red on main too).
- Rebased again on c7171a256, over its budget fix e94bf7a08: gofmt, vet of
  gui, gateway, provider and plugin, TestCoreScriptBudget (core
  1,536,265 of 1,536,586 with the batch's last commit, statusTErr and settingsErr), the Gemini,
  GitOnDisk and plugin tests, and in Linux both engines i18n-keys,
  update-mirror, plugin-namesake, plugins-more-discover,
  plugin-github-hooks and update-auto (138 of 138): ok.
Not tried: the whole GUI suite (mote's WebKit wouldn't launch and its
Chromium segfaulted, #4125); macOS WebKit; the real app's window.
2026-10-30 15:53:22 +08:00
JoeyWu-tech d5d72a82af imagemcp, davsync: slow-download tests leave room for growing the download's buffer (#3419)
TestFourKImageByURLIsSaved, TestStalledDownloadSaysWhereTheImageIs and
TestSlowTransferIsNotCutShort shorten a download watchdog to 1 s or
300 ms. Each watchdog is put back when bytes come, and the time it
counts includes this process storing them: FetchImage's buf.Write, and
the GET's io.ReadAll, which in Go 1.26 fills fresh chunks half the size
of what has come. At the real 60 s that is nothing. At 1 s and 300 ms
these went red here, beside a full suite on a Linux box, with the line
never stopped:
  big_image_test.go:153: after 4.096s: image 1 was drawn but couldn't
    be downloaded (nothing came for 1s, after 4.2 MB)
  big_image_test.go:207: image 1 ... (nothing came for 300ms, after
    8.2 MB), the 4K image that comes in full
  big_image_test.go:207: image 1 ... (nothing came for 300ms, after
    0.0 MB), the same
  stall_test.go:180: slow download: the server sent and took nothing
    for 1s (GET): the line or the server stopped (twice)
A probe beside a full suite wrote 256 KB pieces into a bytes.Buffer up
to 10 MB, as FetchImage does. Of 262,440 writes, 20 were held over
300 ms: 19 grew the buffer from 8 to 16 MB (up to 1.3 s), and one was a
fresh buffer's first write (2.7 s). A goroutine sleeping 10 ms beside
them woke at most 57 ms late, so the time went into the memory, not
into waiting to run. A second probe touched fresh memory: 16 MB was
held up to 454 ms, 4 MB up to 278 ms, 1 MB and 256 KB at most 1 ms.

Now:
- TestFourKImageByURLIsSaved: the stall is 5 s (was 1 s), and the 4K
  image comes in 256 KB pieces 200 ms apart (was 100 ms), about 8 s,
  so the download still outlasts the stall that plays #1576's 2-minute
  cap. The check that it was the slow one is now "longer than the
  stall" (was 3 s).
- TestStalledDownloadSaysWhereTheImageIs: the stall is 1 s (was
  300 ms), the stuck server sends 1 MB before it stops (was 3 MB), and
  the image that comes in full is the small png the other tests serve
  (was the 9.8 MB 4K one, whose buffer the 8.2 MB red was growing).
- TestSlowTransferIsNotCutShort: the backup is 2 MB at 512 KB/s, 64 KB
  every 125 ms (was 24 MB at 6.4 MB/s), still about 4 s each way under
  the same 1 s watchdog; the largest fresh chunk the read back fills is
  then under 1 MB.

What was run (tree 8e4ecb44, on b437e4ad):
  -count=10 of the three tests: ok (TestFourKImageByURLIsSaved 8.2 s on
  average, TestStalledDownloadSaysWhereTheImageIs 2.0 s,
  TestSlowTransferIsNotCutShort 9.9 s)
  broken by hand, with this change:
    FetchImage's stall not put back when bytes come (a 5 s cap on the
    whole download):
      big_image_test.go:157: after 5.003s: image 1 was drawn but
      couldn't be downloaded (nothing came for 5s, after 6.2 MB)
    FetchImage's stall never ending a download (the stopped one is
    kept until its server gives up, and saved):
      big_image_test.go:209: <nil>: Generated with ..., saved to: ...
    davsync's watchdog not put back when bytes move:
      stall_test.go:177: slow upload: ... the server sent and took
      nothing for 1s (PUT)
    no room once the PUT's body is all handed over (allSent):
      stall_test.go:177: the same
  gofmt -l internal/imagemcp internal/davsync: nothing
  GOOS=linux, darwin, windows go vet -tags nogui ./internal/imagemcp
  ./internal/davsync: exit 0
  full suite, go test -tags nogui -count=1 -timeout 45m ./...
  (go1.26.8, 469 s): 62 packages ok, internal/imagemcp and
  internal/davsync among them. 13 reds in 7 packages, none in a file
  this change touches:
    internal/agent TestInstalledVersion, TestOmpDetectedWithPiDir,
    TestCopilotFolderFromAnIDEPluginIsNotTheCLI and
    TestQoderSettingsFromAnIDEPluginIsNotTheCLI: proc.Look keeps "not
    found" for a tool written in the tick of its folder's last change
    (#3141).
    internal/agent TestReasonixCLIRequiresSupportedNativeVersion and
    TestReasonixCLIRecoversAfterProbeTimeout: their fixture build under
    /tmp meets a /tmp/.git that isn't a repository of this user's
    ("error obtaining VCS status: exit status 128").
    internal/claudebridge TestCallbackGoesPastTheAgentsProxy,
    internal/gateway TestClaudeToolCallbackOnANonLoopbackAddress,
    internal/gui TestGatewayHeldByAContainer and
    TestGatewayFixQuitsOnlyAMagpie: the processes this run started had
    their outgoing connections sent through a proxy (graftcp).
    internal/edit TestWriteAtomicReadOnlyHardLink and internal/testenv
    TestProgram: umask 077 here; the fixtures' own modes go through it
    (0444 is written as 0400).
    internal/netproxy TestBunProxyLoginWithReservedCharacters: Bun
    1.3.11 on PATH names port 80 in the request line (#3397).

Not changed:
  - The watchdogs. At their real 60 s a buffer's growth is far inside
    them; only a test's shortened one meets it.
  - pii's TestFetchStall (200 ms): its watchdog times a fresh 256 KB
    buffer and one read of 1000 bytes, at most 1 ms in the probe. Not
    seen red here.
  - davsync's TestStalledTransferFailsPromptly and
    TestMetadataRequestHasALimit (300 ms): a stall that comes early
    still passes them, since they check that a stall is told, and soon.
  - A pause like the 2.7 s one would still trip the 1 s watchdogs of
    TestStalledDownloadSaysWhereTheImageIs and
    TestSlowTransferIsNotCutShort. It came once in the probe's 7.5
    minutes.
Not tried: macOS, Windows.

Landed by yetone in a batch of Coffemon's patches from the issues.
What was run, go1.26.8, on origin/main cc81ad4ea, then again at
70a0c387c (gofmt, the three vets, the changed tests, umask 077):
- mote (macOS 27): gofmt -l clean; go vet, GOOS=linux go vet -tags
  nogui and GOOS=windows go vet ./...: ok. edit and testenv at umask
  077; agent, provider, library and gateway with an empty .git above
  TMPDIR; davsync, imagemcp, plugin, library, edit, testenv whole; the
  changed tests in agent, provider, gateway and gui; the timing tests
  -count=10 (gateway, davsync, imagemcp) and -count=5 (agent): all ok.
  TestCoreScriptBudget ok: core 1,536,751 of 1,537,034, app.js
  1,312,975 of 1,315,316, no budget raised.
- Red on the old code: on origin/main, TestWriteAtomicReadOnlyHardLink
  at umask 077 and two Reasonix tests under an empty .git; on Linux
  (wsl-run) TestProgram at umask 077 with the old program.go. With
  each fix's code taken back to main's, the Gemini imageConfig tests,
  TestPluginToldWhereTheAgentWorks, TestSkillRepoTraced,
  TestTaggedHooksAlone, TestMainURL/TestMainView and update-auto,
  plugin-github-hooks, plugins-more-discover, plugin-namesake were
  red. Broken by hand: claudeKeyed always true (both
  OwnEndpointNeverAsked tests red), claudeAsk a no-op
  (TestClaudeFirstWriteAsksTheProxy red), GitAt taking any .git folder
  (the three TestGitOnDisk tests red).
- GUI: 123 files (plugins*, update-*, panel/tray/start/context, i18n,
  gui-zh-tw/ja/de and every file that evals app.js parts) in WebKit on
  Linux (wsl-run). 11 files had reds (click-scroll, panel-fold,
  plugin-card-update, plugin-github, plugin-move*, segs-glide,
  tray-totals, update-*), and run again side by side they fail the
  same on origin/main d80d75f30 (79 pass, 26 fail here; 78 and 27
  there). They are click-scroll guards ("the click must not scroll
  the page"), varying by language from run to run (#4385).
  copilot-ghe's route-after-close red is #1949, seen on main 244d80e23
  too. In Chromium on mote, Chromium segfaulted partway through files
  (#4125): context-map, context-scroll-end and context-tune fail the
  same on origin/main 0911a65e7, so the batch's own files
  (plugin-namesake, update-auto, plugins-more-discover,
  plugin-github-hooks) ran in Chromium on Linux: 62 of 62.
- Full suite (go test -tags nogui -count=1 -timeout 45m ./..., mote)
  at 472a0608f (on 70a0c387c): every package ok but internal/gateway,
  whose five reds were #4362's (Antigravity turned-away and
  TestCodexSpentGrokFailingIsTold), fixed on main in d80d75f30. After
  the rebase on 244d80e23 the five pass, and gofmt, the three vets
  and the targeted runs above were run again: ok. In Linux the
  sign-in, copilot, plugin-github*, plugins-more-discover,
  plugin-namesake, plugin-gateway, update-auto, quota-refresh-order
  and i18n files ran in both engines: 475 pass, 4 fail (copilot-ghe
  #1949, plugin-github's click scroll, both red on main too).
- Rebased again on c7171a256, over its budget fix e94bf7a08: gofmt, vet of
  gui, gateway, provider and plugin, TestCoreScriptBudget (core
  1,536,265 of 1,536,586 with the batch's last commit, statusTErr and settingsErr), the Gemini,
  GitOnDisk and plugin tests, and in Linux both engines i18n-keys,
  update-mirror, plugin-namesake, plugins-more-discover,
  plugin-github-hooks and update-auto (138 of 138): ok.
Not tried: the whole GUI suite (mote's WebKit wouldn't launch and its
Chromium segfaulted, #4125); macOS WebKit; the real app's window.
2026-10-30 15:53:22 +08:00
yetone 4054251865 library: an MCP server can be kept to this computer, never synced
huhuy72219405 on X: "能不能把不同设备的mcp区分一下,有些mcp属于本地的,
同步之后其他设备不应该读取到". A server in Library > MCP now has a
"This computer only" switch in its editor (Server.Local; CLI
`magpie library mcp add ... --local` and `magpie library mcp local
<name> on|off`; the TUI keeps it on edit and marks the row).

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

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

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

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

Not tried: a sync between two real computers; the real GUI app (the
Playwright run fakes the API); the full Go suite on macOS or Windows.
2026-10-30 02:31:08 +08:00
yetone fe05f0a721 library: a skill can be turned off on this computer alone, and a sync neither carries that nor turns it on
hanslin1666 on Discord (#general 1565016936344191096) wanted a library
skill off on one computer only ("只在这台电脑上关掉"). The only way to do
that was to untick its agents, and the ticks are what a sync carries, so
every other computer lost it too. A sync from a computer that had it on
also gave it back here.

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

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

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

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

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

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

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

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

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

Not tried:
- no real WebDAV or GitHub backend (the sync test uses the fake S3);
- no real app run with real agents;
- no Windows or Linux test runs (only GOOS=windows and GOOS=linux vet);
- not the whole GUI suite, only the 98 files that reach the library page,
  the i18n checks and gui-ja, gui-de and gui-zh-tw.
2026-10-29 04:23:33 +08:00
yetone 5ed6669cec sync: the account an agent is kept signed in to stays each computer's own
YsiCing on X: with only the library and usage ticked, the default account
of a subscription with several followed the other computer: a personal one
at home, a work one at the office, set again every day. The providers part
always syncs, and provider.Mirror took the other computer's Provider whole,
KeepLogin, KeepLoginAs and SwitchOnly with it.

Mirror now keeps this computer's three for a provider it has, and a new one
comes without KeepLoginAs (an account signed in over there). davsync's
hashes blank the three, so changing which account is kept uploads nothing
and two computers that differ only in it don't trade the part. The sign-ins
themselves (logins.json) were never synced. A backup Restore is left as it
is: it is asked for, and brings the backup's choice.

Run on mote at this tree: go test -count=1 ./internal/provider
./internal/davsync ./internal/backup ok; go vet for darwin, linux and
windows on both packages ok. Broken by hand: with backup.go and davsync.go
reverted, TestMirrorKeepsKeepLogin and TestKeepLoginIsNoChange both fail.
Not tried: two real computers syncing through a real WebDAV folder.
2026-10-28 11:56:55 +08:00
yetone a1e91e5002 davsync: S3's If-Match/If-None-Match go outside the signature, so a kept ETag no longer turns a working key into 403 (CyberCaius on Discord)
CyberCaius on Discord: S3 backup works, then every sync fails with
"the S3 server refused the access key ID or secret (HTTP 403
SignatureDoesNotMatch)", and edits to the S3 settings "won't save".
The keys work in other S3 clients, and switching to WebDAV and back
to S3 fixes it until the next time.

Cause: the SigV4 signer signs every header on the request, and
7ab91961d's conditional requests added If-None-Match (GET, the ETag
kept in sync-state.json) and If-Match (PUT). SigV4 needs only host
and x-amz-* signed. A server, or a proxy in front of it, that checks
the signature over a condition as it reads it back rather than as it
arrived refuses a signed one with SignatureDoesNotMatch. The first
sync has no ETag kept, so it passes; from the second on every sync is
conditional and refused. WebDAV and back changes stateKey, so the
state starts again with no ETag and one sync works. "Won't save" is
the same 403: /api/davsync/save writes the settings and then syncs,
and the form stays open with the sync's error.

Fix: sendTo signs every header except if-*, and sets the conditions
after signing. The docs page says so.

Test: TestS3ConditionsOutsideTheSignature, where the fake S3 rereads
an If-* header without its quotes before checking the signature. It
syncs three times, saves a second provider and syncs again, and
checks that the conditional GET and PUT reached the server.
On the old s3.go it fails with the reporter's text:
  s3_test.go:612: sync 2: the S3 server refused the access key ID or
  secret (HTTP 403 SignatureDoesNotMatch)

Run at this head (base e5dd86965), sandbox HOME, caches pinned:
- gofmt -l: clean. go vet (darwin), GOOS=linux go vet -tags nogui and
  GOOS=windows go vet on internal/davsync; builds for darwin, linux
  nogui and windows: ok.
- go test -tags nogui -count=1 ./internal/davsync ./internal/cli
  ./internal/gui (each package that imports davsync): davsync and cli
  ok. gui had one red, TestRestartHandsTheGatewayOver ("9 of 10
  requests during the restart answered", connection reset). That is
  #3451, at load 50; it passes 3 of 3 alone. Commented on #3451.
- No full ./... suite: other sessions were running full suites on
  this machine (gateway, agent).

Not tried: the reporter's own S3 vendor, which isn't known yet.
2026-10-26 15:08:14 +08:00
yetone a6efe07cd7 davsync: a GitHub backup too large for one request goes up in parts (Zhang-Wei, Discord)
Zhang-Wei (Discord, v0.1.1327) saw every GitHub sync fail with "GitHub
sync: HTTP 422: Sorry, your input was too large to process. Consider
creating the blob in a local clone of the repository and then pushing it
to GitHub." Their exported backup is 50.8 MB; with the library's sync off
it works. 93b87d000 sends a backup as one base64 blob in one POST
/git/blobs, so 50.8 MB is about 68 MB of request body. GitHub documents
100 MB per blob (on read) but no request size for creating one; a 19 MB
file's Contents PUT (about 25 MB of body) did go through.

A backup over 16 MiB (githubPart) now goes up in parts, in the same one
commit: magpie.magpie-backup.parts/1, /2, ... beside it, and at the
backup's own path a short list (format magpie-backup, version 2, split
github-parts, total size, each part's blob SHA and size). The version is
the list's blob SHA, and the list names each part by blob SHA, so one
version pins one whole set. get() reads the list, downloads each part by
that SHA (as large single files already were), checks each part's git
blob SHA and the sizes, and returns the backup whole; a list that doesn't
add up or a part that isn't the one named is an error. A write removes
the parts the list at the head named and the new backup doesn't use, in
the same commit (only paths known to be there, so the tree never names a
missing path). Blobs already sent are kept across a non-fast-forward
retry. The errChanged check at the head, the ref update without force and
the three rebuilds are unchanged. Backups up to 16 MiB stay one file; the
64 MiB total (four parts) stays, the bound the library's skill budget is
sized for. An empty repository's first backup in parts skips the Contents
API and follows the README note commit.

Why parts, not compression: the sealed bundle is uncompressed JSON with
skill files base64 inside, so compressing would shrink it, but that is a
backup format change for every backend and every export, every other
computer would need the new magpie even for WebDAV and S3, and it still
bounds nothing on GitHub's side. Parts keep the format and touch GitHub
only.

Older magpies: the list opens in backup.Open (unchanged since efbe5660b)
as format magpie-backup with no kdf and version 2, so it says "this backup
was made by a newer magpie; update magpie to open it" and stops: not
ErrCorrupt or ErrNotBackup, so no rebuild over it and no replace offered.
A backup in one file, from any magpie, still reads.

Library: nothing found that shouldn't be carried, so no second commit.
readSkills already skips .git and caps skill files at 32 MiB (about
57 MiB sealed). The skills on this machine (~/.claude/skills, 64 skills,
43 MB; ~/.agents/skills) hold no node_modules, __pycache__ or .venv; the
large files are real assets (images). Leaving node_modules out could break
a skill that ships its dependencies. Zhang-Wei's folders weren't seen.

Tests (fixture only, no network): the fixture refuses a blob POST over
24 MiB with GitHub's text, and serves any blob by SHA. New in
github_parts_test.go: TestGitHubSplitBackup (50.8 MB in four parts, one
commit, byte for byte back, errNotModified, stale put errChanged, then
two parts and back to one file with no part left),
TestGitHubOneFileBackupStillReads (old small and 30 MB single files read;
parts replace one), TestGitHubPartsOlderMagpie, TestGitHubPartsDamaged,
TestGitHubPartsBranchMovedMeanwhile, TestGitHubEmptyRepositoryPartsBackup
and TestGitHubSyncLargeLibrary (a ~38 MB instruction text syncs to a
second computer through Now). TestGitHubLargeBackup now uses 15 MB, to
keep covering one blob over the Contents API's limit.
docs/subsystems/sync-backup.md says how parts work and names the tests.

Record, at base origin/main e435b8867 plus this change (Go 1.26.8,
GOMODCACHE/GOCACHE pinned):
- gofmt -l internal/davsync: nothing. go vet ./... (darwin): clean.
  GOOS=linux go vet -tags nogui ./internal/davsync/...,
  GOOS=windows go vet ./internal/davsync/...: clean.
- go test -tags nogui -count=1 ./internal/davsync/... ./internal/settings/...
  ./internal/cli/... ./internal/backup/... ./internal/library/...: all ok
  (davsync 58s, settings 30s, cli 47s, backup 8s, library 127s).

Red on the old github.go (new tests, a shim for the new names): every new
test fails, the split ones with the reporter's 422 text, OlderMagpie with
"not a magpie backup" (the old code wrote the backup as is).

Broken by hand on the new code, each red:
- stale parts kept: TestGitHubSplitBackup
- part SHA not checked: TestGitHubPartsDamaged/a_part_changed
- blobs sent again on retry: PartsBranchMovedMeanwhile/another_file
- version check at the head skipped: SplitBackup, PartsBranchMoved/
  the_backup, and the older Remote, LargeBackup, BranchMoved tests
- no split (threshold at 64 MiB): SplitBackup, OneFileBackupStillReads,
  PartsOlderMagpie, PartsDamaged
- sizes not added up: PartsDamaged/sizes
- list's format "magpie-backup-parts": PartsOlderMagpie
- empty repository tries the Contents API first: EmptyRepositoryPartsBackup
- list's version 1: OlderMagpie still passes, since old Open also stops
  on the missing kdf; version 2 is a second guard, not the only one.

Not tried: the real GitHub API (no test repository here); the 16 MiB part
is chosen under the largest body seen accepted, not a documented limit.
The full go test ./... and internal/gui's tests were not run: the disk had
under 500 MB free. -race not run; no goroutine was added.
2026-10-23 10:35:44 +08:00
yetone 93b87d0004 davsync: a GitHub backup too large for the Contents API goes up as a blob (Zhang-Wei, Discord)
Zhang-Wei (Discord, v0.1.1318, 102 skills) saw every sync fail with
"GitHub sync: HTTP 422: Sorry, the file is too large to be processed"
on magpie/magpie.magpie-backup; the last backup that went up was about
19 MB. The Contents API's PUT refuses files well under the 100 MB a blob
can hold.

A repository with commits is now written through the Git Data API:
the ref's head, the file's version at that head (it must still be the one
sync read, or errChanged), a base64 blob, a tree on the head's tree, a
commit with the head as its parent, and a ref update without force. Still
one commit per write or removal, and the version is the blob SHA as
before. A ref update that is not a fast-forward is built again on the new
head (the blob is kept), up to three times, then errChanged; if the new
head changed the backup it is errChanged at once, so another computer's
backup goes through the normal merge. A branch deleted meanwhile is an
error, not created. Usage files and their removal take the same path.

An empty repository has no head to build on, so its first write still
goes through the Contents API (one commit, unchanged). If that is refused
as too large (422 "too large" or 413), a short README.md in magpie's
folder makes the first commit and the backup follows as the second.

Reading was already right for large files: the object media type gives
encoding "none" over 1 MB and bytes() downloads by blob SHA; the new
test covers it at 21 MB.

The fixture now serves the Git Data API (blobs, commits, trees, a
fast-forward-only ref update) and refuses a Contents PUT over
contentsLimit with GitHub's 422 text. docs/subsystems/sync-backup.md says
how writes go and names the new tests.

Record for this push: 13 commits on origin/main ca4a1cde0, head tree
539c84e92. Go 1.26.8, sandbox HOME, GOMODCACHE/GOCACHE pinned. The full Go
run and vet were at tree d6393dfc8, the same Go code as this head: only
app.js comments (cut under the core script budget) and one ja string
changed after it.
- gofmt -l: nothing. go build ./...; go vet ./... (darwin), GOOS=linux
  go vet -tags nogui ./..., GOOS=windows go vet ./...: clean.
- go test -timeout 45m ./..., through tee, one suite on the machine:
  68 packages ok. The one red was internal/gui's
  TestCoreScriptBudget: app.js 1,335,314 > 1,335,000, since main grew
  app.js under the stack. The autoscroll commit's own comments were cut
  (to 1,334,629) rather than the budget raised, and go test -count=1
  ./internal/gui is ok at this head (113s). Packages the run took from
  Go's test cache had the same inputs.
- GUI: the 18 files this stack touches or names, both engines,
  202 of 204 pass (tree 068acf128, this push less the last commit). The
  two reds: gui-ja, red on main since c2636b7b5 and fixed by this push's
  last commit (gui-ja and i18n-keys 6 of 6 there), and usage-fold's
  chromium "several accounts" (#2163, red on main the same way).
- internal/davsync and internal/cli ok, the GitHub large-backup tests and
  TestGitHubCmd among them.
- s3-sync.test.cjs (WebKit en) is red alone on main too: #2448, the
  header over the form's tick. This commit doesn't touch the GUI.
  The whole GUI suite ran at 1c1fc7183 (this stack's first 12 commits on
  0ddcf28a1): 11713 of 11769 pass. Each of the 21 red files was then run
  alone at the stack and at origin/main 8278fd9b0. Eight are red the same
  way on main: plugin-card-update (#3079), quota-count-wrap and
  quota-name-translated (#2228), s3-sync (#2448), usage-agents-hide
  (#2276), usage-checkin (#3091), usage-fold's chromium "several
  accounts" (#2163), usage-ledger (#3104). The other 13 pass alone on both
  and were red only under that run's load (50 to 335): currency #3101,
  plugin-github #3218, provider-fetch-again #3292, rest-try-now #2564,
  routing-auto-reset #3293, routing-keys-fold #1612, routing-steady #1804,
  routing-wb-restricted #1905, sessions-folder-delete #2218,
  sessions-manage #3294, switch-only #3295, text-size #1866, usage-pack
  #3296.

Red on the old github.go (the new tests with the old code):
TestGitHubLargeBackup and TestGitHubEmptyRepositoryLargeBackup fail with
"HTTP 422: Sorry, the file is too large to be processed", TestGitHubRemote
too at its 1.26 MB put, and TestGitHubBranchMovedMeanwhile's three
subtests fail.

Broken by hand on the new code, each red:
- version check at the head skipped: TestGitHubRemote, LargeBackup's
  stale put, BranchMovedMeanwhile/the_backup
- no rebuild on a non-fast-forward: BranchMovedMeanwhile/another_file
  and /the_backup
- large read by base64 only: TestGitHubRemote, TestGitHubLargeBackup
- no README initialization: TestGitHubEmptyRepositoryLargeBackup (409)

Not tried against the real
GitHub API: the fixture follows GitHub's documented Git Data API, and
GitHub's exact Contents API size limit is not documented.
2026-10-23 01:58:00 +08:00
yetone 5ca37ef86b tray: Settings › Menu bar cost off shows magpie's today and 7-day totals as tokens alone, in the menu bar and its tooltip (BussanQ on Discord)
BussanQ asked for the menu bar's today card with the token count only.
A new Settings › Usage › Menu bar row, "Menu bar cost" (On by default,
segs, every OS, shown with or without cards since the no-card tooltip
says the cost too), saves settings.TrayNoCost. Off, trayMoney drops a
total's cost and its count of unpriced calls before trayTotalCard and
trayIdleTip see it, so the macOS cells and title, and the tooltip on
macOS, Windows and Linux, say the tokens and requests alone. A relay's
or subscription's balance card is money itself and stays. TrayNoCost is
per computer (KeepOwn, beside the other Tray* fields), and a change
redraws the tray (api.go). Translated in zh, zh-TW, ja and de.

Run:
- TestTrayNoCost (internal/gui): broken by hand (trayMoney a no-op) it
  fails with label "Σ47M · $128 | Σ6.3M · $3.40+", want tokens alone,
  plus the tooltip and idle tooltip.
- TestSync (internal/davsync) now sets TrayNoCost on one computer; with
  TrayNoCost left out of KeepOwn it fails "b's menu bar: … TrayNoCost:true".
- tray-cost.test.cjs: Chromium + WebKit, en/zh/zh-TW/ja/de, widths 1100
  and 420, Mac/Windows/Linux and no cards: 22/22 pass. With trayNoCost
  dropped from the prefs it fails "a save of another setting keeps the
  cost off". Also green: i18n-keys, tray-bird, tray-logos, tray-totals,
  tray-usages, tray-usage-redraw, quota-pace, tray-inuse.
- gofmt -l clean; go vet ./... and -tags nogui for GOOS=darwin, linux,
  windows clean.
- go test ./internal/tune ./internal/gui ./internal/settings ./internal/davsync
  green at this head, rebased on origin/main 95e7c6bcc.

Full suite: SUITE_LINE
2026-10-15 23:08:00 +08:00
yetone 758a4084ee sync: LAN sharing stays as each computer has it, so turning it on at home no longer turns it on at work (Lullaby on Discord)
Settings.KeepOwn now keeps LAN (sharing on the local network), AllowIPs
(the addresses let in to it) and SessionTerminal (the Mac app a session
resumes in) from this computer whenever a sync, a join, a Restore, an Undo
or a backup file brings settings in. davsync's hashes blanks the same
fields, so flipping sharing is no change to push. A backup restored onto a
new computer leaves sharing off there: it opens the gateway to the
network, so it is turned on by hand, like the port and proxy.

The default sharing key is not per computer. It lives in the gateway-key
store, which rides the settings part with LANKey and LANKeyID, so every
computer holds the same key, and a second computer turning sharing on
takes up that key instead of making another one (configureLAN finds it by
LANKeyID or k.LAN).

Audit of Settings, what stays synced and why:
- already own: Window/WindowMaximised, UIFont/CodeFont, Proxy, Port,
  Dock/DockWindow, Lightweight, KeepAwake/KeepAwakeDisplay, Tray*,
  GatewayMode, NoWSLAgents, QuotaReads, NoAccountDiscovery,
  GatewayConversations.
- made own now: LAN, AllowIPs (the address list belongs to the network
  this computer is on), SessionTerminal (another Mac may not have the
  app).
- not in Settings: launch at login (internal/autostart, the OS's own
  setting) and the listen address (MAGPIE_ADDR, plus Port). Remote access
  through Tailscale etc. goes through those.
- still synced: CORSOrigins (pages and extensions the user uses, and each
  still needs a gateway key), OTel, Redact*, update settings
  (NoAutoUpdate, AutoRestart, UpdateMirror, ChinaMirror), alerts, model
  and agent choices, Theme/Lang/TextSize. These are the user's
  preferences, not facts about one machine.

Older magpie versions still take LAN from the bundle. Only new clients
ignore it.

Docs: sync-backup.md gets a "What stays on each computer" section, and
gateway-routing.md says AllowIPs is per computer. README and site docs
don't list what sync carries, and no GUI string does either, so they are
unchanged.

Run, on origin/main 95e7c6bcc + this change:
- gofmt -l internal/settings internal/davsync: nothing printed
- GOOS=darwin/linux/windows go vet -tags nogui on settings, davsync,
  backup, access, gui: exit 0 each
- go test -tags nogui settings, davsync, backup, access, gui: all ok
- before the rebase, on 226222118: go vet ./..., GOOS=linux go vet
  -tags nogui ./..., GOOS=windows go vet ./..., go build, GOOS=linux
  go build -tags nogui, GOOS=windows go build: all ok
Full suite: SUITE_LINE

Broken by hand: with the three KeepOwn lines removed,
TestLANSharingStaysOnItsComputer fails ("work after joining: sharing on
the local network is true, want false", the same after a restore, "turning
sharing off at home pushed 1 times", "home after work turned sharing on:
... true, want false", plus the AllowIPs and SessionTerminal ones), and
TestLANSharingIsNoChange fails ("sharing on the local network changes the
settings part's hash"). With LAN alone dropped from KeepOwn, the LAN
checks and the hash test fail and the others pass. Restoring the change
turns both green.

Not tried: two real computers syncing through a real WebDAV, S3 or GitHub
folder. The test uses two sandbox homes and a fake WebDAV server.
2026-10-15 23:08:00 +08:00
yetone 707fbb249d backup: a settings.json that can't be read stops a backup, an export and a sync, not carried as the defaults to every other computer (#2269, JasonBuildAI)
Collect read settings with settings.Load, which stands the defaults in
for a file that is there but can't be read, or doesn't parse with no
good .bak. A sync then pushed those defaults as "changed here", and
every other computer brought them in over its own theme, language,
text size, allow list and per-model settings; an export carried them
too. Collect now reads through settings.LoadChecked and stops with its
error, as it does for providers.json (9c54a560). The sync ends before
anything is sealed or pushed, and its status shows the error; the CLI
and the GUI's export show it. A missing or empty file is unchanged.

Sibling: library.Collect read any failed stat of library.json as "no
library"; only a missing file is that now, any other error stops the
backup. plugins.json (provider.Carried -> plugin.list) still reads as
no plugins when unreadable; bringing that in never removes a plugin,
so it is filed separately rather than changed here.

What was run:
- TestCollectStopsOnUnreadableSettings (new, internal/backup) and
  TestSyncStopsOnUnreadableSettings (new, internal/davsync: two
  computers on a fake WebDAV, a's file cut short with no .bak; a's sync
  errs with no PUT, the status says so, the server keeps a's settings,
  b keeps its own). Both FAIL on the old backup.go ("Collect read a
  settings.json that can't be read as settings: <nil> &{Theme:system
  ..." and "a synced a broken settings.json") and PASS on the new, on
  macOS and on the Windows box (cross-compiled binaries, sandbox home).
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows
  clean.
- go test -p 4 -timeout 40m ./... on macOS (origin/main 69d7ee33a plus
  these three commits, load average 15-27 from other suites): every
  package ok but internal/gateway, where TestMaxRPMTooLongIs429With
  RetryAfter got 200 (the window had passed under load; #1791, open,
  gateway untouched here). -run TestMaxRPM -count=3 passes on this
  tree.
- After rebasing on origin/main 226222118 (which touched
  internal/library): go vet darwin, GOOS=linux -tags nogui and
  GOOS=windows clean; go test ./internal/update ./internal/pluginrt
  ./internal/backup ./internal/davsync ./internal/library
  ./internal/settings ok (library under -timeout 40m, 550 s at load
  average ~60).
Not tried: a settings.json held open by another Windows program, or a
real WebDAV/S3/GitHub server.
2026-10-15 10:10:18 +08:00
yetoneandggbdpq 58651568b3 agent, sessions, provider: a state file that doesn't parse is kept aside, not written over as empty (#2263, ggbdpq)
applied.json, wsl.json and sessions-wsl.json were read as empty when they
didn't parse, and the next save wrote that emptiness over them. What
magpie had applied to each agent, the WSL distros and the WSL session
listing were lost with no copy. stash.json already kept a bad file aside
as .bad-<time>. Each of these now does the same through one helper,
lastgood.KeepUnparsed, instead of a copy per file:
- It does nothing when the file is missing or empty.
- When the file doesn't unmarshal into the reader's own type
  (lastgood.Into[T]), it copies the file aside (KeepBad).
- It stops the write when the copy can't be kept.

This also fixes the issue's claim about stash.json. Stash judged a file
with json.Valid, so `[]`, which a map reader takes as empty, was written
over unkept. Its failed copy was only logged, and the write went ahead
anyway. Both are fixed (TestUnreadStashArrayKeptAside), and
gateway-hidden.json uses the same helper.

Siblings found by going through every single-file JSON reader that takes
a bad file as empty and then writes it whole:
- stepfun-auth
- login-returns
- quota-history
- balance-history
- credits-daily
- Claude Desktop tiers
- plugin updates
- usage's computer id
- davsync's sync state

Each now keeps a bad copy. Caches that are rebuilt from the vendor are
left alone; docs/subsystems/providers-accounts.md lists them.

Run:
- gofmt -l, go vet (darwin -tags nogui, GOOS=linux -tags nogui,
  GOOS=windows): clean.
- go test -tags nogui -p 4 -timeout 40m ./... with the other three
  commits of this push: see the last one's body.

Broken by hand: on the code before this, these fail:
- the issue's applied_keep_test.go and wsl_keep_test.go
- TestUnreadStashArrayKeptAside
- TestUnreadStateKeptAside (10 subtests)
- the gateway, usage, davsync and plugin _keep tests
TestKeepUnparsed and TestKeepUnparsedFailsWhenItCantBeKept cover the
helper.

I dropped a test, "not written when it can't be kept", for stash. It passed
on the old code too, because a read-only folder also stops the atomic
write.

Not tried: a real WSL distro.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-15 09:36:26 +08:00
yetoneandggbdpq e413512d8e library: an agent whose CLI is gone (only its config folder left) is no Library write target, and nothing it already has is removed (#2254, ggbdpq)
After an agent is uninstalled, the Agents page shows "CLI not found"
(d0fcb8bc), but Library still offered it for skills, MCP servers, shared
instructions and rtk, and a sync wrote into a folder nothing reads.

- library.Targets() leaves out an agent whose CLI is missing
  (agent.CLIMissing: false for WSL, plugin and detect agents), so sync,
  the read view, market, instructions, skills and found servers all
  drop it at their one upstream.
- Takes() refuses a gone agent by name, so `library mcp add ...
  agents=hermes` says "Hermes Agent's CLI isn't installed here; nothing
  reads its MCP servers until it is installed again" instead of "every
  agent already has it".
- The guards that must still see a gone agent's files (projects'
  notGlobal for skills and MCP, instructions' own-file check) read
  everyTarget(), so a set kept in the agent's own file is still refused.
- rtk: a gone agent isn't offered rtk; one that still has the hook is
  listed so the hook can be taken out.
- Nothing a user wrote is removed: sync acts per target, so a gone
  agent's skills, servers and AGENTS.md stay as they are, and the client
  keeps agent ids it doesn't show.

Run:
- Sandbox HOME, real binaries: old wrote mcp_servers into a gone
  ~/.hermes/config.yaml; new refuses with the message above, exit 1.
- New tests TestTargetsLeaveGoneAgentsOut, TestGoneAgentKeepsWhatItHas,
  TestRTKLeavesGoneAgentsOut; each broken by hand (Targets check,
  Takes refusal, everyTarget in instructions, rtk gate) goes red.
- go test -tags nogui ./internal/library ./internal/tui ./internal/cli
  ./internal/gui: ok. Fixtures that relied on a gone CLI now place one
  (holdCLI, TestRTKHermesHome, TestRTKOffPath), and so do profile's
  and davsync's sandboxes, whose library syncs to claude and codex
  (TestOldProfiles, TestProfileCarriesLibrary, TestSyncLibrary went red
  in the full run without them).
- gofmt -l clean; go vet -tags nogui darwin/linux/windows clean.
- go test -tags nogui -p 4 ./... at the pushed head: see the last
  commit of this push.

Not tried: the real GUI with an uninstalled agent on a live machine.

Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-10-15 06:07:43 +08:00
yetone 3a7d0314a9 usage: a window's Pace as a number on its card, and in the menu bar when asked (fflake33)
fflake33 on Discord asked for the pace as a figure, "+12%" or "−8%"
against an even pace through the window, on the Usage cards and in the
menu bar.

- provider: QuotaWindow.Pace(readAt, now) is the share used (0-100) less
  the share of the window gone by, from Bounds (reset less span; a
  month's window a calendar month); none for an unlimited window, one
  whose span or reset isn't known, or outside it. WithWindowStarts sets
  startsAt on copies of the cards for the GUI (the caches' cards are
  left alone); /api/usage/quotas and its refresh send it.
- Usage page: "Pace +20%" on the reset line after the wait (quotaPace,
  paceLine), its sign turned with the meter in Left mode, amber while
  more is used than an even pace would have, what it means in its
  tooltip. Past cycles and windows with no known start show none.
- Menu bar: Settings > Menu bar pace (settings.TrayPace, off by default;
  hidden on Windows, whose tray shows no text) puts " +12%" beside each
  figure ("42% −14%", at most 10 runes, trayRowMax) and "pace −14%" in
  the tooltip. KeepOwn keeps it device-local like the other tray
  settings; the Settings save keeps it (prefsKeep).
- Strings in en, zh, zh-TW, ja, de. gui-shell.md says it.

Run:
- go test -tags nogui ./internal/provider ./internal/gui ./internal/settings
  ./internal/usage: ok; ./internal/davsync: ok (now covers TrayPace;
  red with TrayPace taken out of KeepOwn). go test ./internal/gui -run
  Tray (darwin, with the tray image tests): ok.
- New TestWindowPace, TestWithWindowStarts (input not mutated),
  TestTrayUsagePace (off unchanged, used and left, rows, tooltip).
- quota-pace.test.cjs, chromium and webkit: 4 pass; cards in en, zh,
  zh-TW, ja, de at 1100 and 420px, used and left, amber, tooltips, no
  sideways scroll, a click moves nothing; the Settings row in all five
  at both widths, On posts trayPace, a currency save keeps it, no
  scroll; hidden with no card and on Windows, shown on Linux. Red with
  paceLine not called, with trayPace out of prefsKeep, and with the
  Left-mode sign not turned.
- gui-de, gui-ja, gui-zh-tw, i18n-keys: 12 pass; tray-bird 6, quota-holds
  2, quota-read-at 4 pass.
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows clean.
Not tried: the real menu bar on a Mac or Linux tray.
2026-10-14 13:02:48 +08:00
ggbdpq eb22f6355a davsync: a computer joining a sync folder keeps the gateway keys the folder's store has never seen (#1737, #1714, ggbdpq)
The gateway-key store rides the settings part, and a first sync brings
a part changed only on the server in whole. So a computer with its own
gateway keys that joined a folder another computer had set up first had
every key replaced by the folder's store (8ugMak1r on #1714 got them
back only from the -this-computer copy in the sync folder). On the first
sync, before the settings are brought in, the keys this computer holds
that the store has neither by id nor by value are added to the store
brought in; that merged store is restored here and pushed for the
others. A key the folder holds wins; the LAN default key follows the
folder's settings as before. After the join a key missing from a store
this computer has seen is a removal, as before.

ggbdpq's patch (a9605c8a), cherry-picked unchanged.

Run (reviewer): TestGatewayKeysJoinKeepsUnseenKeys fails on the old
davsync.go (the joining computer's keys are gone, the pushed store holds
only the folder's default key, computer B never gets A's key) and passes
with it, -race -count=3; TestGatewayKeysJoinWithoutStoreKeepsKeys passes
on both. go test ./internal/davsync/... ok. Not tried against a real
WebDAV server.
2026-10-14 04:59:10 +08:00
yetone b8e23db45a backup, davsync: an import or a sync installs the plugins and names the subscriptions to sign in to (yapechan)
yapechan on Discord (Windows, Synology WebDAV): after an import or a WebDAV
sync no providers showed on the other computer; adding the same provider by
hand made the synced settings and usage apply. No error, a restart didn't
help.

Cause. A backup and a sync carry providers.json as stored. For a
subscription that is its model picks and settings alone (no endpoint, no
key), and sign-ins are never carried by design; allProviders lists such an
entry only once an account is signed in here. plugins.json was not carried
at all, so a provider served by a plugin (every moved subscription, any
plugin provider) had nothing to come from on the other side. The import
said "N added" and "Needs a key: , " (the picks entries have no name and no
key), and the sync said nothing. API-key providers do come over: tried with
a nogui build in two sandbox HOMEs (DeepSeek, a custom relay, Kimi Code all
listed after `magpie restore`). No Windows-only path issue found.

What changed:
- provider.Carried(keys): the plugins added from npm or git, on/off and
  their options (without keys, options whose names look like a key are left
  out, as secret headers are). Folder plugins and plugin-auth.json stay.
- backup.Bundle.Plugins (nil from an older magpie). Restore installs the
  ones not here through provider.AddPlugins (plugin.Add, then Off and
  Options, then HandOver once); it never removes or changes one already
  here. A failed install is reported, not a failed restore.
- Result.SignIn / provider.NotSignedIn: the subscriptions brought with no
  account here. NeedKey no longer lists picks-only entries (provider.OnlyPicks).
- davsync: the providers part's hash covers the plugins (unchanged for a
  setup without any), take/bring carry them, bring installs (logged on
  failure), and Status().SignIn names what to sign in to.
- CLI restore and `magpie webdav`/`s3` status print both; the GUI's import
  result and the sync row show them (en, zh, zh-TW, ja, de).
- docs/reference.md says what a backup carries now.

Run:
- go test -tags nogui ./internal/provider ./internal/backup ./internal/davsync
  ./internal/cli ./internal/gui in a sandbox HOME.
- New tests fail with the change broken by hand: TestPluginsCarried
  (installed-skip and the HandOver guard), TestNotSignedIn,
  TestRestorePluginsAndSignIn ("Needs a key: [ Acme]" without OnlyPicks),
  TestSyncPluginsAndSignIn (bring not installing, Status not naming),
  sync-sign-in.test.cjs (the lines removed).
- sync-sign-in.test.cjs: Chromium and WebKit, en/zh/ja/de, 900 and 440px,
  16/16; it also caught subNames throwing while providers was still null.
  sync-*.test.cjs, s3-sync, i18n-keys, gui-ja, gui-de pass.
- gofmt -l, go vet, GOOS=linux and GOOS=windows go vet -tags nogui on the
  touched packages.
Not tried: a real plugin install from a real sync (the installs are stubbed
in tests); a real Synology server.
2026-10-13 15:52:17 +08:00
yetone f82aba090b davsync, gui, cli: GitHub sync refuses a repository that isn't private (#1130)
The sealed setup is committed on every sync, so a public repository would
hand anyone every version of it, the whole history, to try passphrases on
offline. prepare now reads the repository's "private" field and refuses
before writing when it is false or missing, naming the repository and what
to do. The form's hint, the CLI usage and docs/reference.md say the
repository must be private; sync-backup.md lists the rule and its
verification command now points at ./internal/cli.

Run: go test -tags nogui ./internal/davsync/ and the cli tests
(TestGitHubCmd|TestWebdavCmd|TestS3Cmd|Help) green;
TestGitHubPublicRepositoryRefused goes red with the check removed. GUI:
github-sync, s3-sync, webdav-settings-refresh, sync-other-kind,
sync-not-backup, i18n-keys, gui-zh-tw, gui-ja, gui-de in Chromium and
WebKit, 72/72. Not tried against the real GitHub API.
2026-10-13 15:25:10 +08:00
yetone cdfe7629a5 davsync: GitHub sync's "not a magpie backup" advice names the file where it is, not under magpie/magpie/ (#1130)
fileWhere passed folder+"/"+file to g.at, which already puts the file under
the configured folder and magpie/, so the recovery advice told the user to
look at <folder>/magpie/magpie/sync.json, a file that isn't there. It now
passes the file alone.

Run: go test -tags nogui ./internal/davsync/ (green). TestGitHubNotBackup's
new assertion goes red with the old path put back.
2026-10-13 15:25:07 +08:00
bingqilinweimaotai 1af326806f sync: magpie's setup syncs to an encrypted file in a GitHub repository, beside WebDAV and S3 (#1130)
A third sync kind: github://owner/repo[/folder] keeps the same sealed
backup WebDAV and S3 keep, as <folder>/magpie/magpie.magpie-backup in a
repository the user already has, written through GitHub's Contents API
with a fine-grained token of its own (Contents read and write), kept in
sync.json apart from the library's GitHub token. The token goes only to
api.github.com: a redirect anywhere else is refused, and the passphrase
may not equal it. Each update is a commit; an empty repository is
initialised by the first backup. Settings › Sync gets a GitHub kind with
Repository, Branch, Folder and token; magpie github mirrors magpie s3.
Inactive servers of every kind are kept in Config.Servers (Other stays
for older clients).

Squashed from yetone/magpie#1130 at 6b5b1c693e1a3a23e177b4d376f3f7f70f3bc23d
onto main. Merge resolutions: the CLI moved to internal/cli since the PR
was cut, so github_cli_test.go moved there (package cli) and the github
command, its help line and `magpie help github` were wired in
internal/cli/main.go and help_cli.go; README's Sync row kept main's
links and took the PR's wording; i18n.js zh-TW kept both sides.
2026-10-13 15:25:06 +08:00
yetone 8792ee063d provider: a Volcengine or Tencent access key is kept through sync, restore, a stale editor and a copy, and a plan card without one says what to give (#1821, Edward4226)
The reporter's Volcengine Agent Plan card vanished: providers.json had
lost accessKeyID/secretAccessKey, and volcPlanQuotas skipped a provider
without them before building any card, so nothing said why.

Writers that dropped the access key, fixed at the cause:
- Sync and restore (Mirror, Restore, davsync take) kept this machine's
  access key and balance token only when the incoming provider had no
  key at all. A magpie before v0.1.1142 (aa82288f), or one the access
  key was never given on, sends the same key with no access key, and
  that replaced it here and on the server. KeepSecrets now keeps them
  when the incoming has the same key and none of its own; another key is
  another account and still brings its own (TestBackupBalanceToken
  unchanged). A keyless copy also keeps this machine's secret headers,
  which withoutKeys strips and nothing put back. The secret-name regex
  moves to provider.SecretHeader; backup.Secret delegates to it.
- The GUI save kept the access key ID only when the field was left out;
  the editor always sends it, so an editor opened before the key was
  given saved "" over it (the Secret was kept). Blank now keeps it; only
  clearAccessKey drops it.
- AddCopy skipped the Secret when the copy's form sent the source's ID.
- read() and validProviders didn't strip a UTF-8 BOM (lastgood.JSON
  does): a BOM'd providers.json fell back to its .bak, an older
  generation.
Import's replace mode replaces providers on purpose and is unchanged.

The Usage page: a plan endpoint (Volcengine Coding/Agent Plan, Tencent
Token Plan Enterprise) whose providers have no access key is a card
with no windows, an error naming AccessKey ID and Secret (SecretId and
SecretKey for Tencent), needsAccessKey, and an "Open settings" button to
the provider's editor; one card per plan, none when another provider on
the plan has the key. Strings in en, zh, zh-TW, ja, de.

Run:
- go test ./internal/provider ./internal/davsync ./internal/backup
  ./internal/gui -count=1, twice, green (private GOCACHE, sandbox HOME).
- Broke each by hand and saw red: KeepSecrets same-key keep
  (TestSyncKeepsAccessKey, TestTakeKeepsAccessKey), header keep, BOM
  strip (TestProvidersFileWithBOM), GUI blank-ID keep
  (TestProviderSaveKeepsVolcengineSecret), AddCopy
  (TestAddCopyKeepsAccessKeySecret), the Volcengine missing card
  (TestPlanCardWithoutAccessKey).
- GUI: usage-access-key-card 20/20 (chromium + webkit, 5 languages, 900
  and 420px; red with the button removed and with the ja string
  changed); i18n-keys, volc-access-key, tencent-access-key,
  tencent-cloud, quota-balance-error, usage-card-refresh,
  usage-remote-cards green.
- gofmt -l clean; go vet darwin, linux -tags nogui, windows clean for
  provider, davsync, backup, gui, cli.

Not verified: which writer dropped the reporter's key is inferred from
their 10-10 to 10-11 snapshots, not reproduced on their machine (most
likely sync from another computer). Not tried against real Volcengine or
Tencent accounts. The tray panel shows the error text with no button.
2026-10-12 23:45:06 +08:00
yetone 0d58ec8dcb davsync: a write a server without conditional PUTs let another go over is merged again at the next sync (#1776)
On an S3 server that refuses If-Match (Aliyun OSS answers 400
NotImplemented), put falls back to HEAD then an unconditional PUT. Two
computers writing in the moment between both pass the HEAD, both are
told they wrote, and the later file is kept. Worse, the loser's next sync
then took the winner's file as having seen its own: its st.Remote was the
file it wrote, so its changed parts looked unchanged here and changed
there, and the old parts were brought in over its own changes. The edit
was lost on the server and on the computer that made it.

- version.Blind marks a write the server didn't check (s3.go's fallback).
- state.Blind keeps, for such a write, the file's sum and the remote and
  local part hashes from before it. The next sync that reads another
  file than that one merges from before the write. What this computer
  changed counts as changed again and goes back up beside the other's.
  A 304 or the same file clears it. Restore and Upload clear it.
- docs/reference.md says what happens on such a server.

No compare-and-swap exists on OSS, so the race itself isn't closed: the
other computer's file is kept for up to one sync interval (3 minutes)
before this computer's change is merged back. The reporter's AppendObject
journal would close it but needs every computer upgraded and OSS-only
signing. If the other computer saw this one's write and then changed the
same part again, the next sync can't tell that from a write that went
over it. It counts the part as changed on both sides: the newer stays,
the other is saved, and a notice says so. Nothing is lost.

Run:
- TestS3BlindWriteGoneOverIsMergedAgain (fake S3 with no conditional
  writes, two computers): A renames a provider and B sets the theme, B's
  PUT goes over A's, then A's next sync puts both on the server with no
  conflict notice, B brings in the rename, and nothing more is written.
  With the reset taken out (broken by hand), it fails: "A's rename here
  after its next sync: \"DeepSeek\"".
- go test ./internal/davsync whole.

Not tried against real Aliyun OSS: the fake answers conditional PUTs the
way the reporter quotes OSS (NotImplemented).
2026-10-12 19:38:15 +08:00
yetone 206dc085be provider: a magpie run from a terminal that only lists accounts no longer writes logins.json, and every change to it is made under a lock the gateway holds too, so a token the gateway just refreshed is never written back over (#1674, FaintGhost)
Every CLI command that reached Logins() (magpie ls, providers, sessions,
usage) ran rememberLogins, whose 30-second throttle (loginsSeenAt) lives
in the process, so in a new process it never held: each run moved Seen on
for the signed-in Codex and Claude accounts and wrote logins.json back.
loginsMu was an in-process mutex, so that read-modify-write could
interleave with the gateway's renewSavedLogin: the CLI reads, the gateway
writes a refreshed sign-in, the CLI writes what it read. Codex/OpenAI
refresh tokens are single use, so the account would be signed out.

- rememberLogins writes nothing when the only change is Seen and the saved
  Seen is less than seenEvery (10 minutes) old (onlySeenMoved, comparing
  with what was read, IDs and order normalised as writeLogins writes them;
  sortLogins is split out of writeLogins for that).
- internal/filelock (new): davsync's TryLock/Unlock (flock; LockFileEx on
  Windows) moved here and davsync uses it; Lock(path, wait) and
  filelock.Mutex, a sync.Mutex that also holds the OS lock on a lock file.
  A lock another magpie holds is waited for up to filelock.Wait (10s),
  then gone on without, as before, so a stuck magpie never hangs others.
- loginsMu is a filelock.Mutex on logins.json.lock, so all 107 existing
  Lock sites (every writeLogins is under one) are cross-process with no
  change at the call sites. Taking it calls filememo.Look (new), so the
  read under it isn't a parse filememo.Hold kept from before another
  magpie's write. savedTokenMu holds logins.json.renew.lock the same way:
  two magpies never refresh one saved account at once.
- Siblings: caller-keys.json (access.mu: magpie keys from the CLI vs the
  window; a lost revoke would bring a key back) and mcp-signins.json
  (mcpauth.fileMu, plus mcp-signins.json.renew.lock around renew, since
  library's MCP check renews from the CLI too) get the same lock.
  plugin-auth.json already has one (plugin-auth.json.lock, shared with
  host.js). Not covered: providers.json (33 store sites with no
  in-process lock either; user-entered keys, nothing refreshed there),
  migrations.json/settings.json (no credentials), and the agents' own
  files (~/.codex/auth.json etc.: the agent itself writes them without
  any lock of ours, so a magpie-only lock can't make them safe).

Tests:
- TestReadOnlyRunLeavesLogins: Codex and Claude signed in, Seen a minute
  old, file time set back; three "new processes" of Logins("")/codex/
  claude/All() leave logins.json's bytes and mtime as they were. Seen an
  hour old is written; Codex's own refresh is written at once.
- TestLoginsKeepAnotherMagpiesWrite: between this process's read and write
  (beforeLoginsWrite hook) a second test process (TestLoginsOtherMagpie,
  os.Args[0] -test.run) renews the saved work@ account's refresh token;
  both the renewed token and this process's change are in the file.
- TestLoginsReadAfreshUnderLock: with filememo.Hold held, a write
  filememo never heard of is seen by a read under loginsMu.
- TestLockAcrossProcesses (filelock): a holder subprocess makes Lock wait
  and give up after its wait; killed, the lock is free; a Mutex holds it.

Broken by hand: onlySeenMoved bypassed -> TestReadOnlyRunLeavesLogins
FAIL "a run that only listed the accounts wrote logins.json"; the file
lock taken out of filelock.Mutex.Lock -> TestLoginsKeepAnotherMagpiesWrite
FAIL "the other magpie's renewed sign-in was written over"; Locked hook
emptied -> TestLoginsReadAfreshUnderLock FAIL. Each restored, green.

Ran: gofmt -l (nothing); go vet ./..., GOOS=linux go vet -tags nogui
./..., GOOS=windows go vet ./...; go build, GOOS=linux go build -tags
nogui, GOOS=windows go build; go test -tags nogui -count=1 ./... under a
temp HOME with pinned caches: all ok but internal/provider, whose
TestReadOnlyRunLeavesLogins failed at that point from its own fixture
(two rewrites of one size given the same mtime read as unchanged by
filememo); fixed in the test, then internal/provider, access, mcpauth,
filememo, filelock and davsync -count=1 all ok, and the three new provider
tests -race -count=10 ok.

Not tried: the reporter's Linux arm64 box with a real systemd gateway and
real Codex accounts; Windows (LockFileEx path) only vetted and built, not
run on the Windows box.
2026-10-12 05:20:26 +08:00
YAYOI27andClaude aa82288fb6 usage: Volcengine Ark's Coding Plan and Agent Plan windows, read with the account's access key (#1427, yayoinoyume)
Ark tells a Coding Plan's or Agent Plan's 5-hour, weekly and monthly
windows only to the account's control plane (GetCodingPlanUsage,
GetAFPUsage on open.volcengineapi.com), signed with the account's
AccessKey ID and Secret, never to the plan's inference key. An Ark
provider's editor now takes that access key, and the Usage page shows the
plan's windows as a card.

From yayoinoyume's feat/volcengine-usage, reviewed and reworked:
- Signing is volc-sdk-golang's (base/sign.go GetSignRequest, 06f9ef66):
  signed headers sorted (content-type;host;x-content-sha256;x-date), only
  Action and Version in the query. The branch signed them unsorted and put
  Region in the query. TestVolcSignMatchesSDK pins two signatures the SDK
  made.
- The card is in PlanQuotas beside the Step Plan's (its cache, last
  reading, refresh and `magpie quota wait`), not in the subscription
  cards. One per access key and plan.
- The plan is the endpoint's: /api/coding asks GetCodingPlanUsage,
  /api/plan GetAFPUsage, pay-as-you-go none, in the host's region. The
  branch asked both and showed whichever answered.
- Dropped guessed reply fields; the Coding Plan reply is the one
  pi-ark-usage, dsh-ark-quota and ArkCodingPlanUsage read. AFP buckets are
  read in the forms dsh-ark-quota and arkcli read (Used of Quota or Total,
  or Percent), plus Tier; none was seen from a real account.
- An Ark provider is known by its host, not the preset id, so a copy or a
  custom provider takes the key too.
- The Secret is never sent to the page (accessKey {id, secretSet}); a
  blank Secret keeps it, a save without the ID keeps both, Remove
  (clearAccessKey) drops both, an ID with no Secret is refused.
- The pair goes where keys go: AddCopy, Restore, Mirror, backups and
  davsync carry it only with keys (withoutKeys), and a keyless restore or
  sync keeps this machine's. CLI: access.key, access.secret.
- A changed access key drops the cached cards (ForgetPlanQuotas).
- UI strings in zh, zh-TW, ja and de.

Nothing was tried against the real Volcengine API: there was no access
key. A local fake checked the real request PlanQuotas makes against
volc-sdk-golang's own GetSignRequest (both actions, two regions); it
lives outside the repo, so go.mod is unchanged.

Run: gofmt -l; go vet (darwin), GOOS=linux and GOOS=windows go vet
-tags nogui on provider, gui, backup, davsync and the root; go test
-tags nogui ./internal/provider ./internal/gui ./internal/backup
./internal/davsync . under a temp HOME; node --test
volc-access-key, zhipu-team, gui-ja, gui-de, i18n-keys in Chromium and
WebKit. Fail without the change: TestVolcSignMatchesSDK (unsorted
headers), TestAddCopy, TestBackupBalanceToken, TestNoKeys,
TestTakeBalanceToken, TestSyncBalanceToken (pair not carried),
TestProviderSaveKeepsVolcengineSecret (blank Secret dropped),
volc-access-key (Remove not posted).

Co-authored-by: YAYOI27 <111715843+yayoinoyume@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-10-09 23:25:04 +08:00
yetone be2037285a davsync, gui: a server file that isn't a backup is said as what it is, and can be replaced by this computer's setup (JasonLeeForOnly on Discord)
JasonLeeForOnly's WebDAV sync failed with only "not a magpie backup" for
several versions, and nothing on the page got past it. A WebDAV GET of the
backup can come back as a body that isn't the file in several ways; each is
now reproduced with an httptest server that answers the way the real one
does:

Unpacked (WebDAV and S3): gzip with or without Content-Encoding (a proxy
that drops the header), x-gzip, zstd with or without the header, deflate
(zlib or raw), and a header that says gzip over a plain body. Bodies are
told by magic number; a backup is JSON, so either magic is never the file.
Brotli (br) can't be unpacked and is said as itself, with what to turn off.

Said, with no upload offered: an HTML page answered with 200 (Nextcloud
login after a redirect, Cloudflare Access, an AList/OpenList web app, an
rclone directory listing, a captive portal), with its <title> and the
host/path a redirect ended at (query, fragment and user dropped), and
where the WebDAV address is for 坚果云 and Nextcloud; an XML answer, by its
root element.

Said, with Upload as the way out: an empty (0-byte) file, a backup cut
short or damaged (the automatic rebuild is unchanged and still goes first
when its rules allow), another app's file ("format": "…"), other JSON,
and any other file by its content type. Messages carry the size, kind and a
page title only, never the file's contents.

backup.Open now tells ErrNotBackup (doesn't begin like a backup) from
ErrCorrupt (begins like one, cut short). The status carries the kind as
serverFile; Settings › Sync and backup says it in the reader's language,
wraps it whole, and shows "Upload this computer's setup" only when the file
may be replaced. davsync.Upload (POST /api/davsync/upload, `magpie webdav
upload`, `magpie s3 upload`) asks first in the GUI, re-reads the file,
refuses a backup this computer opens, one sealed with another passphrase,
a newer magpie's, a page and an XML answer, keeps the server's copy in the
sync folder (0600, newest 5) and writes nothing if that fails, then writes
with If-Match on the version read. New strings in en, zh, zh-TW, ja, de.

Verified: internal/davsync/not_backup_test.go (TestReadCompressedBackup,
TestReadBrotliSaid, TestServerAnswerSaid, TestCutBackupSaidAndUploaded,
TestS3ReadCompressedObject; Upload-only parts stripped to compile) fails
on e4a90aa6 for every compressed case but "gzip said", Brotli, every
server-answer case, the cut case and S3 gzip, and passes here. Dropping
the Replace check in Upload turns the page/XML cases red ("Upload wrote
over a page"). gofmt -l clean; go vet darwin, GOOS=linux and GOOS=windows
-tags nogui on ., davsync, backup, gui; full go test -tags nogui ./... ok;
-race on davsync and backup ok. GUI: sync-not-backup.test.cjs (en, zh,
zh-TW, ja, de; 900 and 440px), sync-*, s3-sync, gui-de, gui-ja, gui-zh-tw,
click-scroll in Chromium and WebKit, 81 pass. Not tried against a real
WebDAV server or on the Windows box; the reporter's server is unknown.

Note: 2018882e on main carries this subject by mistake (another session read a shared message file); it holds only GTK DPI code. This commit is the actual WebDAV change.
2026-10-09 12:14:26 +08:00
yetone b37a082c48 davsync: WebDAV sync reads the backup uncompressed, so its ETag matches the write after it (#1362, laiquziru: TeraCloud synced once, then every sync said "the file on the server changed meanwhile")
What: dav.get sends Accept-Encoding: identity, and unpacks a body a server
gzips anyway (Go only unpacks what it asked gzip for itself).

Why: Go's client asks for gzip on every GET. InfiniCLOUD's (TeraCloud's)
WebDAV is Apache mod_dav_fs, whose PUT answers with no ETag (mod_dav.c's
dav_created: "### insert an ETag header?"), so the sync after the first
reads the file in full and pushes over the ETag that read gave. Apache's
mod_deflate (DeflateAlterETag AddSuffix, the default) gives the gzip copy
"<etag>-gzip", which no If-Match on the file matches: every write after the
first was 412, the retry read the same -gzip tag, and the state left the
local change pending, so every sync after failed. A read asked for as it
is gets the file's own ETag. nginx-style proxies that weaken the ETag
(W/"...") on gzip are covered by the same change.

TeraCloud behaviour assumed: seen without an account on 2026-10-09 against
https://domi.teracloud.jp: OPTIONS /dav/ says Server: Apache and
DAV: <http://apache.org/dav/propset/fs/1>; GET / with Accept-Encoding: gzip
gives ETag "fb-5d88268abcf08-gzip" + Content-Encoding: gzip, without it
"fb-5d88268abcf08"; GET with If-Match the -gzip tag is 412, with the plain
tag 200. Not seen: that mod_deflate compresses files under /dav/ (needs an
account). The fake (apacheDAV in teracloud_test.go) does: no ETag on PUT,
gzip + "-gzip" ETag on a GET that accepts gzip, If-Match strong against
the file's own ETag.

Real conflict detection is unchanged: If-Match is still sent with the
version read; TestSyncTeraCloudStillSeesOtherWrites lands another
computer's write between a's read and write on the same fake and checks
the 412, the merge over it, and b's file kept aside.

Run:
- new tests fail on the old code: without identity,
  TestSyncTeraCloudGzipETag "sync 2 after the first: the file on the
  server changed meanwhile (2 writes refused, 2 reads sent gzip)"; with
  If-Match dropped, TestSyncTeraCloudStillSeesOtherWrites "write over a
  replaced version: <nil>, want errChanged"; without the unpack,
  TestDAVGetGzipAnyway reads gzip bytes. All pass restored.
- sandbox HOME, pinned caches: go test -race -tags nogui ./internal/davsync/
  ./internal/gui/ . ok; -race -count=5 on the davsync sync/conditional/
  short-write/Nutstore tests ok
- gofmt -l clean; go vet (darwin, darwin nogui, linux nogui, windows) of
  internal/davsync; go build darwin, linux nogui, windows
Not run: a real TeraCloud account.
2026-10-09 09:46:37 +08:00
yetone 10f7b4aa3f davsync, gui: a WebDAV server whose HEAD says Content-Length: 0 no longer fails every shared usage day as "kept 0 of 6869 bytes", and a usage share that failed is its own red line under the sync status (#1259, mzcinf on 坚果云)
After each PUT, check read the file's size from a HEAD and called anything
shorter a cut write. On 坚果云 every usage write failed that way with 0
bytes kept, three tries each; the 0 can only have come from the HEAD's
Content-Length, since a 6869-byte body that the PUT sends with its
Content-Length (not chunked) isn't cut by a dropping network three times
running. A HEAD that says short is now asked again of PROPFIND (Depth 0)
getcontentlength, the size WebDAV clients of 坚果云 read. The write counts
as kept when that size is whole. When PROPFIND gives no size, the HEAD's
stands. A real cut write is still told as cut, with the bytes PROPFIND
says were kept. The extra request is made only after a short HEAD, so
坚果云's request limit isn't spent on servers whose HEAD is right. The
backup's own PUT goes through the same check, so a 坚果云 user whose
setup changes would have hit the same error on the main sync.

Settings > Sync put "Couldn't share usage: …" in the same grey line as
"Synced · host", so it read as part of a sync that went fine. It is now a
line of its own under the status, in red, wrapped whole at 440px. The CLI
already printed it on its own line.

Verified: TestNutstoreHeadSaysNoLength and TestNutstoreBackupWrite use a
fake 坚果云: HEAD Content-Length: 0, real getcontentlength on PROPFIND,
409 for a read in a missing folder, a chunked PUT refused. Whole writes
sync with no usage error, and each write goes once with one HEAD and one
PROPFIND. A tunnel that keeps half is still told as cut, with the half it kept.
On the old dav.go all three fail ("the WebDAV server kept 0 of 536 bytes
of magpie.magpie-backup", "kept 0 of 6869"). TestDAVShortWrite and
TestUsageSharedShortWrite/TestUsageSyncShortWrite pass unchanged.
sync-usage-error.test.cjs runs in Chromium and WebKit, en/zh/ja/de, at
900 and 440px, and fails on the old app.js ("the status line carries no
usage error: 14:46 已同步 · dav.jianguoyun.com · 用量未能共享:…"). The
sync-*, s3-sync, usage-computers, gui-ja, gui-de, gui-zh-tw, i18n-keys
and click-scroll tests pass, 78/78. go test -tags nogui -count=1
./internal/davsync ./internal/gui pass under a temp HOME. go vet passes
on darwin, GOOS=linux and GOOS=windows. Not tried against a real 坚果云
account: that its HEAD answers 0 is inferred from the error, and that its
PROPFIND gives the real size is how its other WebDAV clients read sizes,
neither seen here.
2026-10-08 14:52:11 +08:00
Alex be1ce5d4d2 davsync: incomplete S3 listings keep cached usage days (#1243)
Reject truncated listings with missing or repeated tokens and listings that exceed the page limit. On the old code the regression reports successful partial listings and shareWith removes a cached day. Focused tests pass in a temporary HOME.
2026-10-08 11:52:26 +08:00
yetoneandClaude Opus 5.5 30a8ce2915 davsync tests: TestSlowTransferIsNotCutShort's watchdog is a second, not 300 ms, over ~24 MB each way
A line that never stops is all this test sends, so a 300 ms watchdog only
catches the runner itself pausing: red on macOS in run 37693090857 at
7.99s, near the end of the GET, where a full run takes 7.23s and 8 runs
under 3x CPU oversubscription here all passed. The server's 40 ms gap is
still 25x inside the watchdog, the PUT's tail is still twice it, and with
allSent's extension taken out the test still fails ("took nothing for 1s
(PUT)").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 06:21:51 +08:00