feat(backup): add S2.6 daily profile backup (fixes #50)

One liveness-gated snapshot pass per launch, chained after provisioning:
gateway.pid pid-liveness + ps scan (skip while the engine runs), 24 h
age check, curated recursive copy (credentials and SQLite sidecars in;
logs/caches/locks out), atomic temp+rename install, keep last 7.
Restore stays manual copy-back in v1 — Help > Open Backup Folder and
a RESTORE.md written beside the snapshots.

[Generated by AI]
This commit is contained in:
AlexKucera committed 2026-09-30 11:24:58 +02:00
1 parent f21d3a6844
commit e5b7203906
11 files changed
+593 -5

No files matched your search

@@ -0,0 +1,61 @@
# M0: Profile backup — daily snapshot pass (S2.6)
> **Date:** 2026-09-25
> **Type:** issue
> **Reference:** [#50 Build: implement daily profile backup pass](https://git.babylondreams.de/AlexKucera/museion/issues/50) (map [#15](https://git.babylondreams.de/AlexKucera/museion/issues/15))
## Goal
Land the #15 map's build ticket: the mentor's accumulated state survives profile corruption or a bad update. On qualifying launches Museion copies the whole museion profile to a timestamped snapshot under `~/Library/Application Support/Museion/Backups/`, keeping the last 7 — liveness-gated, credentials included, restore = manual Finder copy-back in v1.
## What Was Done
- `Museion/ProfileBackup.swift` (new) — `ProfileBackup` (nonisolated enum, EngineProbe/Provisioner pattern): one pass = liveness gate → age check → curated recursive copy → temp+rename atomic install → prune past 7. `BackupModel` (@MainActor @Observable) app-scoped via `AppGateState.backup`, runs off-main, guards stacking.
- `Museion/ContentView.swift` — `onEnginePass` chains `provisioning.runPass` then `backup.runPass` (a failed provision doesn't skip the backup; sequencing avoids racing the per-skill seed renames).
- `Museion/MuseionApp.swift` — `AppGateState.backup`; Help menu → Open Backup Folder (`NSWorkspace.open` on the Backups root).
- `RESTORE.md` written once into the Backups root at first snapshot — manual copy-back instructions travel with the snapshots.
- `MuseionTests/ProfileBackupTests.swift` (new) — 8 tests, injected roots/clock/psScan.
- `PRD.md` G4 + S2.6 amended (curated-exclusions wording per the map's charting decision); `Museion/AGENTS.md` backup section; `MuseionTests/AGENTS.md` test-pattern note.
## Decisions & Rationale
| Decision | Rationale |
|----------|-----------|
| Plain `contentsOfDirectory` recursion for the copy, not `FileManager.enumerator` | Enumerator yields fstab-resolved paths (/var → /private/var), so substring rel-path arithmetic silently produced garbage; `skipDescendants()` on a file entry also eats following siblings. The plain walk has no path math and no traps — smaller and correct. |
| `psScan` injectable, default real `ps ax` pipeline via `EngineProbe.execute` | Tests must not depend on whether a dev machine happens to run the real engine (`hermes acp -p museion` would make every CI/dev run skip). Map decision preserved in production default. |
| Snapshot layout `<stamp>/museion/<contents>` | The folder name travels with the snapshot so restore is literally one Finder copy-back — `RESTORE.md` documents exactly that shape. |
| `RESTORE.md` as static text written into the Backups root, not a bundled help-book resource | It must sit beside the snapshots it describes even when the app that wrote them is gone (corruption scenario = the app may be reinstalling). |
| Sequencing as caller's await chain, not a polling wait inside BackupModel | `await provisioning.runPass(); await backup.runPass()` — one line, no timer hack, failure-independent (#15 decision). |
| gateway.pid parsed as JSON (`pid` key), not bare integer | Probed the real file: it's a JSON line `{"pid":…, "hermes_home":"…"}`. The map's "parse pid" assumed integer; JSON parse is the verified reality. |
## Gotchas & Fixes
| Problem | Root Cause | Fix |
|---------|------------|-----|
| Snapshot's `museion/` dir empty — all credential assertions failed | `skipDescendants()` called on excluded *file* entries skipped subsequent siblings; separately, enumerator's resolved paths broke `dropFirst(source.count)` rel-path math across the /var symlink | Replaced the whole enumerator approach with plain recursive `contentsOfDirectory` + name-based exclusion |
| Tests failed on missing `state.db` at snapshot root | Copy landed profile contents directly at `<stamp>/`, not `<stamp>/museion/` | Create `museion/` payload dir inside the temp snapshot before copying |
| Test-target build error "Argument 'timeZone' must precede 'year'" | `DateComponents` memberwise init has a fixed argument order | Built components via property assignment |
| SwiftFormat reformatted `prototypes/GateUIPrototype.swift` (untouched file) | Blanket `swiftformat .` | Reverted via git checkout — drive-by formatting isn't part of this ticket |
## Files Changed
| File | Change Summary |
|------|---------------|
| `Museion/ProfileBackup.swift` | New — backup pass, liveness gate, curated copy, retention, RESTORE.md |
| `Museion/ContentView.swift` | onEnginePass chains backup after provisioning |
| `Museion/MuseionApp.swift` | AppGateState.backup; Help → Open Backup Folder |
| `MuseionTests/ProfileBackupTests.swift` | New — 8 tests: liveness branches, exclusions, credentials, age, retention, failure |
| `PRD.md` | G4 + S2.6 amended to curated-exclusions wording |
| `Museion/AGENTS.md` | New "Profile backup" section (DOX) |
| `MuseionTests/AGENTS.md` | ProfileBackupTests pattern note |
| `AGENTS.md` | GitNexus counter refresh (965 symbols) + this log's window row |
## Open Items & Next Steps
- [x] All four #15 acceptance criteria test-pinned (daily cadence, complete-of-what-matters copy, last-7 retention, manual-restore docs; snapshots user-local by construction — Backups root is in Application Support, never the project).
- [ ] First real snapshot happens at next qualifying launch (engine idle, newest >24 h) — verify `~/Library/Application Support/Museion/Backups/` then.
- [ ] Map #15 closeout: resolution comment + Decisions-so-far pointer (blocked on forge-write authorization).
---
*Log written by write-log skill*
+1
View File
@@ -5,6 +5,7 @@ Complete history of session logs in this directory, newest first. One-line summa
<!-- write-log: full-index -->
| Date | Type | File | Summary |
|------|------|------|---------|
| 2026-09-25 | issue | [20260925-issue50-profile-backup-s2-6_log.md](20260925-issue50-profile-backup-s2-6_log.md) | #50 S2.6 daily profile backup: liveness gate, curated copy, retention 7, RESTORE.md — 8 tests green |
| 2026-09-16 | issue | [20260916-issue14-acp-bridge-s2-2_log.md](20260916-issue14-acp-bridge-s2-2_log.md) | #14 M0 ACP bridge: NDJSON JSON-RPC client, mentor pane, fix-card round-trip, crash restart — 37 tests green |
| 2026-09-05 | issue | [20260905-issue48-provisioning-failure-alert-retry-ux_log.md](20260905-issue48-provisioning-failure-alert-retry-ux_log.md) | #48 shipped: failure card with retry/Not-Now, traversal guard, temp sweep — 30 tests green |
| 2026-09-03 | issue | [20260903-issue42-engine-gate-s2-1_log.md](20260903-issue42-engine-gate-s2-1_log.md) | Engine gate S2.1 shipped: six-path probe, blocking sheet, state.json, About mirror — 12 tests green |