Files
magpie/docs/subsystems
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
..
2026-11-10 03:25:44 +08:00

Subsystem design references

These pages describe current responsibilities, runtime paths, state, and contracts. Start with the subsystem relevant to your task, then follow its source links to verify the implementation you change.

Subsystem Reference
Built-in subscriptions moving to plugins Provider and plugin ownership
Built-in plugins: registry, lifecycle, plugins.yml, presets, settings schemas, the window's kernel (slots, error boundary, kit) Plugin runtime
Plugins that run on the gateway's requests and replies Gateway middleware
Tools that plugins give, offered to every agent as an MCP server Plugin tools
Plugins that await context recall and observe completed replies Asynchronous gateway request hooks
Claude subscription turns across Claude Code runs Claude subscription bridge
How the gateway picks a provider, key or account, and falls back Gateway routing and fallback
Gateway Session Aggregation Gateway Session Aggregation
Connecting an agent's config to the gateway, drift, disconnect, WSL twins Agent wiring
Providers, keys, subscription accounts, refresh and allowance Providers and accounts
Instructions, MCP servers, skills and RTK written into agents Library
One MCP server, magpie, given to every agent in place of the Library's servers MCP router
Memory shared by every agent: the memory MCP server, the digest in instructions, the Memory tab Memory
One skill, magpie-skills, listing the Library's skills in place of each agent's own Skill router
Tray, panel, window, magpie web and the page's JSON API GUI app shell
Encrypted backups and setup synchronization over WebDAV, S3 or GitHub Sync and backup

A subsystem can span several packages or repositories. Its reference describes the behavior those parts provide together; it does not need to list every function.

Maintain a reference

Update the owning reference in the same PR when a change alters a documented responsibility, interface, state transition, runtime path, compatibility rule, or failure behavior. An internal refactor that preserves these contracts does not require a prose change.

Keep each fact in one reference and link to it from agent instructions or other pages. Link to source files and named symbols rather than copying implementation details that change frequently. Explain field meanings and constraints that signatures alone do not express.

For a new reference, include the responsibilities and boundaries, source of truth, main runtime paths, state transitions, important constraints, and existing verification commands. Include failure and compatibility behavior where relevant. Document current behavior separately from proposed changes; the proposal belongs in its issue or PR.

Describe a PR's semantic changes

For each affected subsystem, explain the observable change with its trigger and before/after behavior. Include changes to interfaces, state, compatibility, and failure behavior when relevant. Link the affected reference, implementation, and verification evidence. State when a refactor preserves the documented behavior.

For example, a change to plugin adoption should explain which migration state and account condition trigger it, which implementation handles requests before and after adoption, and which test exercises that transition.

This is an author-provided explanation that a reviewer verifies against the diff and surrounding code. It is not an automatically proven compatibility verdict.

Review a change

  1. Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
  2. Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
  3. Check that changed contracts appear in the owning reference and that source links still resolve.
  4. Check that the cited tests or runtime evidence exercise the claimed behavior. Report checks that were not run.

A documentation update alone does not prove the implementation. Existing tests and runtime evidence remain necessary for behavior changes.