From b78daa27fb0a0444781817e0ba7f004ec37b4abe Mon Sep 17 00:00:00 2001 From: Cd1s <135119404+Cd1s@users.noreply.github.com> Date: Sat, 26 Sep 2026 00:31:55 +0700 Subject: [PATCH] Change history: config-level diff in every plan, a record of every apply, rollback N as a normal change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part 1 of #12 (risk levels and automatic confirm follow). - `mr plan` / `mr apply` / the web UI's apply dialog show what changes in config terms ("~ wifi.radios[phy1].htmode: HE80 → HE160", "+ firewall.forwards[web]", secrets only as "(changed)"), against gen/applied.yaml + gen/applied-secrets (bookkeeping the plan writes and a rollback restores). `-v`: each generated file's diff, secret values masked. - Every apply records a revision next to its snapshot: rev, time, origin, comment (`mr apply -m`, web UI field), version, the diff and the result. `mr history`; `system.history` (default 20). - `mr rollback N` / 回滚到此前: the config from before change #N applied as a new change (verify + confirm window), the web UI password kept. - Web UI 变更历史 page; tests; mock data. Part of #12 --- docs/MODULES.md | 7 +- docs/modules/sys.md | 5 +- mr/api.go | 133 ++++- mr/apply.go | 83 ++- mr/apply_test.go | 8 +- mr/history.go | 569 +++++++++++++++++++++ mr/history_test.go | 189 +++++++ mr/main.go | 28 +- mr/mod_sys.go | 5 + mr/mod_sys_backup.go | 3 +- rootfs/www/index.html | 1 + rootfs/www/ui/core.js | 44 +- skills/mini-router/SKILL.md | 5 +- tools/mock/fixtures/history.diff.post.json | 1 + tools/mock/fixtures/history.json | 19 +- tools/mock/mockapi.py | 9 +- 16 files changed, 1031 insertions(+), 78 deletions(-) create mode 100644 mr/history.go create mode 100644 mr/history_test.go create mode 100644 tools/mock/fixtures/history.diff.post.json diff --git a/docs/MODULES.md b/docs/MODULES.md index e810d32..481bdd7 100644 --- a/docs/MODULES.md +++ b/docs/MODULES.md @@ -51,7 +51,12 @@ Register exactly one `Module` in `init()`: - `Secrets(c)` — names of every secret this module's config references (so the UI can show 已设置). Rollback (failed/unconfirmed apply, `mr rollback`) restores files, restarts their services and -reconciles the default runlevel with the restored config (`reconcileRunlevel`). From the snapshot until the +reconciles the default runlevel with the restored config (`reconcileRunlevel`). Every apply records a revision +(`history.go`): `.json` next to its snapshot with rev, time, origin, comment, the config-level diff +(from `gen/applied.yaml` + `gen/applied-secrets`, bookkeeping files the plan writes and a rollback restores; secrets +only as "(changed)") and the result (applying → applied | pending → confirmed | rolled back: why); `mr rollback N` +and the web UI's 回滚到此前 apply the config from before change N as a new change (the web UI password stays the +current one). From the snapshot until the change is accepted (the apply ends without `--confirm`, or `mr confirm`) the marker `/etc/mini-router/confirm-pending` (JSON: snapshot, state applying | pending | reverting, deadline, origin) is on flash: if the router goes down in that window, the next boot restores the snapshot before any service starts diff --git a/docs/modules/sys.md b/docs/modules/sys.md index 861f3fb..36b7f69 100644 --- a/docs/modules/sys.md +++ b/docs/modules/sys.md @@ -32,6 +32,7 @@ system: ntp_server: false # also answer NTP (udp/123) — only the LAN zone gets through the firewall sysctl: {net.ipv4.tcp_congestion_control: bbr} # added to / overriding 90-mini-router.conf zram: true # zram swap (1/4 of RAM, zstd); also MGLRU min_ttl_ms=1000: OOM kill instead of thrashing + history: 20 # config snapshots / change records kept (5-200) services: tailscale: {enabled: true, port: 41641} # tailscaled --port; the same UDP port is opened on the WANs @@ -152,7 +153,7 @@ load; output and exit code go to `/run/mini-router/fw-run.{log,rc}`. directories) rejects the whole archive. 2. Secrets: the backup's are laid over the current ones; `webui_password` always stays the current one. 3. List files that differ are saved first as `