ktg-plugin-marketplace/plugins/ms-ai-architect/scripts/kb-update/lib
Kjell Tore Guttormsen d46f7a3459 feat(ms-ai-architect): add lib/backup with sentinel-guarded rollback [skip-docs]
Foundation lib for v1.12.0 cron rewrite skill-tree backup/restore.
Zero dependencies. Uses fs.cpSync (recursive + preserveTimestamps) without
dereference (Node 22.17.x regression) and without filter (Windows symlink-
type bug).

- backupDir(srcDir, backupRoot, opts) → {backupPath, retentionDays, restore()}
- Backup-id format YYYY-MM-DDTHH-MM-SS (filesystem-safe; no colons)
- .backup-meta.json sentinel written as first action inside backupPath
- restore() writes .rollback-in-progress at backupRoot BEFORE rmSync+cpSync
  so a crashed restore leaves the sentinel for the next run to detect
- detectStaleRollback(backupRoot) — boolean predicate over sentinel
- cleanupOldBackups(backupRoot, retentionDays) — 3-step age resolution:
  meta.created_at → dir mtime → skip-with-warning (never delete a dir
  whose age cannot be established)

12/12 tests pass: timestamp format, content round-trip, sentinel lifecycle,
retention, mtime fallback, unparseable-meta skip, missing-root no-op.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-05 10:50:10 +02:00
..
atomic-write.mjs feat(ms-ai-architect): add lib/atomic-write for crash-safe state files [skip-docs] 2026-05-05 10:32:13 +02:00
backup.mjs feat(ms-ai-architect): add lib/backup with sentinel-guarded rollback [skip-docs] 2026-05-05 10:50:10 +02:00
cost-estimat.mjs feat(ms-ai-architect): add lib/cost-estimat heuristic for API-key budget [skip-docs] 2026-05-05 10:34:37 +02:00
cross-platform-paths.mjs feat(ms-ai-architect): add lib/cross-platform-paths for cache/log/state/backup dirs [skip-docs] 2026-05-05 10:30:31 +02:00
lock-file.mjs feat(ms-ai-architect): add lib/lock-file with PID+mtime stale detection [skip-docs] 2026-05-05 10:47:05 +02:00
registry-io.mjs feat(ms-ai-architect): sitemap-based KB change detection system 2026-04-09 21:19:51 +02:00
sitemap-stream.mjs feat(ms-ai-architect): sitemap-based KB change detection system 2026-04-09 21:19:51 +02:00
url-normalize.mjs feat(ms-ai-architect): sitemap-based KB change detection system 2026-04-09 21:19:51 +02:00