Commit Graph
9 Commits
Author SHA1 Message Date
yetone ff88ec264a sync: subscriptions whose sign-ins stay on this computer (Ethereal499 on X)
Sync's sign-ins can now leave chosen subscriptions out on one computer
(`signInsExcept`, provider ids; Ethereal499 on X keeps Claude's accounts
off other computers). On that computer:

- its accounts of those subscriptions never go up;
- the server's accounts of them are never merged in, so a removal or a
  new account on another computer changes nothing here;
- the server keeps them as they are for the computers that do sync them
  (syncOnce splits the remote set with SignIns.Except and puts the held
  part back with With after the merge, so the hash doesn't change);
- the preview and Restore count and restore none of them.

An id names both the built-in and its -plugin id. An old config has no
field and syncs everything as before. The setup text doesn't carry the
choice, since it belongs to one computer.

GUI: Settings > Sync > edit > Advanced, under "Sign-ins", a "Not synced"
row with a multi-select openProtoMenu of the subscriptions with an
account. The row shows only while the sign-ins tick is on. The strings
already existed in en, zh, zh-TW, ja and de. CLI: `sign-ins-except=`
on the WebDAV, S3 and GitHub setups ("none" clears it), and status
shows the excluded ids. docs/subsystems/sync-backup.md says it.

Tests:
- TestSignInsExcept (provider) and TestSyncSignInsExcept (davsync, two
  computers on a fake DAV).
- sync-signins-except.test.cjs: both engines, 1100 and 420px, all 5
  languages.

Broken by hand, each red and then restored:
- the Except in collect;
- the Except on the remote set before the merge;
- the Except in the preview;
- the With after the merge;
- the GUI form's post of signInsExcept.

Run:
- At ac4a4cf84 on mote: `go test -timeout 45m ./...`, 102 packages ok,
  exit 0.
- At ac4a4cf84, the whole GUI suite on mote. The first part ran at
  concurrency 6 under load 25 to 37, and mote rebooted mid-run (not
  this session's doing). The 410 files it never reached ran at
  concurrency 4. Reds fell in 125 files, none of them a sync-* file
  except s3-sync (see below).
- At the rebased head b781d0bcb on mote:
  - go test ./internal/davsync ./internal/provider ./internal/cli
    ./internal/gui: ok.
  - Every sync-*.test.cjs, webdav-settings-refresh and
    sync-signins-except: ok.
- gofmt -l: clean.
- On mica: go vet ./..., GOOS=linux go vet -tags nogui ./... and
  GOOS=windows go vet ./... ok, plus go build, GOOS=linux go build
  -tags nogui and GOOS=windows go build.

Red the same on origin/main 873b1f7d5, run there alone:
- s3-sync webkit en ("picking S3 must not scroll the page"), #3413 and
  #2448.
- i18n-keys (", with an image" in plugins/routing), #6877.

Not run: the full Go suite at the rebased head. Another session's full
suite held mote, and mica was full. The 125 GUI files red under load
were not each run alone on main.

Not tried: a real sync between two computers with real accounts.
2026-11-17 14:08:48 +08:00
yetone 459d668b35 sync: pick what syncs, preview a sync, undo the last one (#6428)
jinpwng (#6428, on X) syncs two computers and wants only Library and
memory to go between them: each keeps its own providers, settings and
models. They also want to see what a sync would change before it
applies, and to roll the last one back.

What syncs: providers, settings and profiles now have switches like
agents' models, library and memory (Config.Providers/Settings/Profiles,
*bool, nil = synced as before, so an existing setup syncs exactly what
it did). The sync form shows Providers (and its API keys), Settings and
Agents' models up front; Profiles, usage and sign-ins sit under
Advanced, closed unless one is set away from its default. The form
sends a part's choice only when it is or was off. A part left out
stays as it is here and on the server; turning it back on joins it
like a first sync (st.Off, rejoin). The sync's line says which parts
each computer keeps ("Stays as it is on each computer: ..."). The
setup text and the CLI carry it: magpie <webdav|s3|github> set
providers=no settings=no profiles=no.

Preview: davsync.Preview (plan.go) says, per part, what syncing now
would bring in, send up, or leave; library items and memory files by
name, sign-ins and plugins gone. Preview... in Settings > Sync shows it,
and Sync now from there runs SyncPreviewed(token): if the server or
this computer changed since, it says so and shows the new plan instead
of syncing something else. CLI: magpie <kind> preview.

Undo: a sync that brings parts in records them (st.Applied) and keeps
a sealed copy of this computer first (keepSealed, as Restore does).
Undo the last sync puts those parts back from that copy, on this
computer only (st.Local, so the next sync sends it up rather than
fetching the server's again). If one of them changed here since, it
asks first (409 changed, Undo anyway). CLI: magpie <kind> undo-sync
[anyway]. Restore's own Undo is unchanged.

docs/subsystems/sync-backup.md and the site's sync docs (en, zh, ja)
have a section on it. i18n: zh, zh-TW, ja, de.

Run (worktree at base 48e394146):
- go test -count=1 . ./internal/davsync ./internal/cli: ok (mote).
  Broken by hand, each went red: syncs() forced true (scope tests),
  rejoin's again forced false, UndoSync without the st.Local update.
- go test -count=1 ./internal/gui: TestCoreScriptBudget was over by
  85 bytes; the sync-left line moved into syncfiles.js, now ok.
- go vet ./internal/gui, GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok. gofmt -l: nothing.
- node --check app.js, syncfiles.js, sync-scope.test.cjs: ok.
- GUI (mica), every test file that opens Settings > Sync or calls
  davsync (22 files) plus i18n-keys, Chromium and WebKit, 1100 and
  420px, en/zh/zh-TW/ja/de: 453 of 454 pass. The red is s3-sync webkit
  en "picking S3 must not scroll the page" (0 !== 98), the same on
  origin/main 52c9880cb (#3413, #2448). An earlier run also had
  library-new-skill chromium en 420 red, the same on main (#6539).
  sync-scope.test.cjs is new: on the old code there is no Providers
  switch, Preview or Undo, so it fails at once.
- Rebased on origin/main 7eecbcc56 (app.js and i18n.js changed there):
  TestCoreScriptBudget, go test . ./internal/davsync, node --check, and
  i18n-keys, sync-scope, webdav-settings-refresh (both engines): ok.
- The full go test ./... was started through mote's suite lock when
  this was pushed; its result goes on #6428.

Not tried: a real WebDAV, S3 or GitHub server (the tests use fakes);
the real app on Linux WebKitGTK. "Save and sync" from the form, after a
preview, syncs without the preview's token check.
2026-11-13 21:09:44 +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 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 fad96ea0fe gui, cli: sync and backup say the synced settings use a subscription not signed in here, and that one not used here needs nothing (悠悠哥 on Discord)
悠悠哥 asked why the sync card said ChatGPT wasn't signed in. The line was
right (the synced settings carry ChatGPT's picks, and this computer has
no ChatGPT account; sync carries no sign-in) but didn't say why ChatGPT
was named or that it can be left alone. It now reads "Your synced
settings use {names}, which isn't signed in on this computer. Sync
carries settings, not sign-ins: to use it here, sign in in Providers →
Add a provider; if you don't, nothing needs doing." The backup import's
sibling says the same of the backup, in en, zh, zh-TW, ja and de, and
the CLI's `magpie webdav` status and `magpie backup import` lines say it
too. Which subscriptions are named is unchanged.

Run:
- sync-sign-in.test.cjs, now with zh-TW and widths 1100/900/440/420:
  chromium + webkit, 40/40; screenshots of zh at 420 looked at.
- go test ./internal/cli: ok. go test ./internal/gui: ok except
  TestMainWindowCorners killed at its 40s deadline (load average ~180),
  which is #1936; alone it passes (36s).
- gofmt -l clean; go vet darwin, windows, linux -tags nogui on cli.
Not tried: the real app with a real WebDAV sync.
2026-10-15 00:15:27 +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
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 23e764d0e0 cli: magpie's commands move from the root into internal/cli; the root keeps only main.go
The root held 89 .go files (30 commands, 59 tests). They move as they are
to internal/cli (package cli), with git mv so history follows them. The
only code change is main() becoming cli.Main(version): the root's new
main.go keeps `var version` in package main, so -ldflags "-X
main.version=…" in the Makefile, the Dockerfile and magpie-releases, and
every workflow, work unchanged. go-winres's rsrc_windows_*.syso still land
next to package main in the root.

Tests that read testdata by a root-relative path now go up one level
(../plugin/testdata/fake, ../sessions/testdata). Five subsystem doc links
point at internal/cli/.

Run:
- go build ./..., gofmt -l, go vet on darwin, linux and windows (nogui)
- builds with tags production, dev, "production nogui"; windows
  -H windowsgui; linux CGO_ENABLED=0
- make release-cli TARGETS="darwin/arm64 linux/amd64 windows/amd64
  android/arm64" VERSION=9.9.9-tidy: all four built, binary prints
  "magpie 9.9.9-tidy"
- docker build --build-arg VERSION=7.7.7-tidy: container prints
  "magpie 7.7.7-tidy"
- go test ./internal/cli (default and nogui): 152 tests, the same count
  as the root on main
- go test ./...: all packages pass (agent, gateway, library, provider
  timed out at 10m under other sessions' load and passed rerun alone
  with -timeout 40m; none of them changed)
- the built binary in a sandbox HOME: version, help, ls, providers,
  claude, and an unknown command's error
2026-10-12 20:40:22 +08:00