Files
magpie/docs/subsystems
yetone c24915f04e library: LiveAgent in the MCP and Skills pickers (zero2sin)
LiveAgent was missing from the Library's MCP and Skill agent pickers
(zero2sin on Discord #feedback). It is now a target, written in its own
engine's formats, read from K-brain 507f560 (the one LiveAgent af89ea7
pins), not guessed:

- MCP: <data dir>/config.json.live-mcp.json (cmd/kn/backend.go,
  internal/mcp/live.go LiveSettings): {"servers":[{"id","enabled",
  "transport":"stdio"|"http","command","args","env" | "url","headers",
  ...}],"selected":[...]}. Streamable HTTP only, so SSE is refused.
  ${NAME} in env and headers resolves as K-brain's secret refs
  (internal/config/secret.go). The user's servers and their
  description/enabled/cwd/timeoutMs/policy/auth/... are kept; untouched
  servers are written back byte for byte (json.RawMessage). A non-empty
  selected gets magpie's server added (or it would have no tools) and
  taken out on remove, never the last one. With no file yet, K-brain
  reads config.json's "mcp" object (settingsFromConfigs), so the first
  write carries those servers over the way K-brain's own first save
  does. A new file is 0600 like K-brain's. A file K-brain itself could
  not parse is not written over.
- Skills: <data dir>/skills, as copies (Target.Copy): K-brain refuses a
  link in a skill's path (safePath) and ScanDetailed walks past one. A
  skill there loads only when picked in skills-settings.json
  global.selected (Manager.Effective), so syncLiveAgentPicks picks each
  copy magpie makes once (Applied.Picked), never again after the user
  unpicks it, and unpicks it when the copy goes. Names K-brain refuses
  (validManagedName) are never put in selected, since its next save
  would fail on them. Its built-in skills-creator/skills-installer are
  not offered for import.
- Not added: instructions (K-brain's brain.md is its own memory file).
  A server written while LiveAgent runs is seen at its next start (the
  app holds the list in memory and saves it whole).

Run (mote-run, at base 326e72f4c):
- go test -run LiveAgent ./internal/library/: 7 tests ok
- go test ./internal/library/... ./internal/agent/ ./internal/gui/:
  library ok, agent ok, gui FAIL only TestMainWindowCorners/macOS_26_SDK
  (#3949, macOS 27 on mote, no library code)
- GOOS=linux and GOOS=windows go vet ./internal/library/: clean;
  gofmt -l: clean
- node --test of 100 GUI files (library-*, *skill*, *mcp*, i18n-keys)
  in chromium and webkit: 1941 of 1946 pass. Red: i18n-keys "a plugin's
  words are its own" (two Go test files elsewhere say a plugin's word)
  and found-skill-pick-remove "en at 420px" in both engines; this change
  touches no GUI file.
- Rebased on origin/main 125fd93ec and run again there:
  go test ./internal/library/ ok; found-skill-pick-remove and i18n-keys
  red the same (en at 420px both engines; "a plugin's words are its
  own"), and red the same on a clean origin/main 125fd93ec worktree:
  filed as #5013 and #5327/#5332.

Broken by hand, each red: Copy=false (TestLiveAgentTarget,
TestLiveAgentSkills: a link); no syncLiveAgentPicks call (nothing
picked); re-picking every sync (TestLiveAgentSkills: xlsx picked again
after the user unpicked it); no built-in skip (found lists
skills-creator); no selected append (TestLiveAgentMCP); no config.json
seeding (TestLiveAgentMCPFromConfig); no chmod (0644); no name check
(TestLiveAgentSkillsNewSettings: My_Skill picked).

Not tried: a real LiveAgent app reading the written files (no LiveAgent
on mote or here); Windows and Linux test runs (vet only).
2026-11-06 00:26:59 +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
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.