Files
magpie/docs/subsystems
yetone de1ba9f123 settings, gui: a masking rule can be edited in place, not only removed (nf1qaz2w on Discord)
nf1qaz2w on Discord: "自定义脱敏规则现在只有移除,能否增加一个编辑功能方便调整规则".
Settings → Privacy listed each custom masking rule with Remove only, so
changing a pattern meant removing it and typing it again at the end.

Each rule's row now has Edit beside Remove. Edit opens the rule in its own
row, where it stands, with its name, Prefix/Regex (the app's segs, no
<select>) and match filled in, laid out like the add row; a narrow window
puts the match, Save and Cancel on a line under the name and Prefix/Regex.
Save (or Enter) sends that one rule to the new POST
/api/settings/redact-rule with its index and its current value;
editRedactRule tidies and checks it with redact.CheckRules as an added rule
is, and refuses one that doesn't compile, matches the empty string, is left
with no prefix or pattern, repeats another rule, or is no longer at that
index (changed or removed meanwhile). A refusal is said in the row in red,
what was typed kept, and every rule stays as it was. Cancel or Escape
leaves the rule untouched and sends nothing. The gateway reads the rules
from settings per request (redactionOptions), so the edit masks the next
request. The two fixed refusals are translated (zh, zh-TW, ja, de); the
other strings (Edit, Save, Cancel, Name, Prefix, Regex) were already there.
docs/subsystems/gateway-routing.md now describes the user's own rules and
the edit.

Run:
- TestRedactRuleEdit (internal/gui): a valid edit is saved in place and
  redact.Mask with the saved rules follows it; a bad regex, a pattern that
  matches nothing, a short prefix, an empty rule, a duplicate, an index out
  of range, a negative one and a stale "was" are each refused with the
  reason, the rules unchanged. With api.go from before this change it fails:
  "edit: 404 404 page not found".
- internal/gui/tests/redact-rule-edit.test.cjs: Chromium and WebKit, en, zh,
  zh-TW, ja, de, 1100px and 420px (20 tests, all pass): Edit opens the rule
  in its place with its values, fields don't overlap and stay in the row,
  the page doesn't scroll sideways, no click moves the page, Cancel sends
  nothing, a refused regex is shown with the typed values kept, a good one
  is saved by Enter in the same place. With the old app.js it fails: no
  button.rule-edit (locator timeout). redact-rule-row.test.cjs and
  i18n-keys.test.cjs pass.
- Whole GUI suite in both engines, under heavy machine load: 5647 of 5667
  pass. Each failing file was run again alone: agent-expand-steady,
  azure-endpoint, balance-currencies, gateway-key-groups,
  library-desktop-skills, library-all, plain-names, purpose-filter and
  usage-ledger pass. skill-install-agents-all (chromium 420px "view:5,0")
  failed the same on the base commit and passes after rebasing onto
  afe0c59d. routing-keys-fold fails in webkit only under load; alone it
  passes 3x on this tree and on the base.
- After the rebase: redact-rule-edit, redact-rule-row, i18n-keys,
  skill-install-agents-all and click-scroll pass (79/79).
- gofmt -l, go vet, GOOS=linux and GOOS=windows go vet -tags nogui
  ./internal/gui: clean. go test -tags nogui ./... under a sandbox HOME:
  green (48 packages ok, no FAIL); after rebasing onto afe0c59d,
  ./internal/gui, ./internal/redact and ./internal/settings pass again.
2026-10-11 12:41:00 +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
Plugins that run on the gateway's requests and replies Gateway middleware
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
Tray, panel, window, magpie web and the page's JSON API GUI app shell

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.