Skip to content

feat(backups): automatic backup system with TUI restore flow#61

Open
davidarce wants to merge 2 commits intomainfrom
feature/manifest-backups
Open

feat(backups): automatic backup system with TUI restore flow#61
davidarce wants to merge 2 commits intomainfrom
feature/manifest-backups

Conversation

@davidarce
Copy link
Copy Markdown
Owner

Summary

  • Add an automatic backup system for devrune.yaml: every mutation (install / sync / upgrade / TUI manifest writes) creates a timestamped snapshot first, with FIFO rotation at 5 backups per project.
  • Provide a TUI Backups menu entry that lists snapshots newest-first, shows a unified diff against the current manifest, asks for confirmation, takes a pre-restore backup of the live state, replaces devrune.yaml atomically, and re-runs install to materialize artifacts.
  • Centralize all manifest writes through writeManifestSafe (backup + atomic rename) so no path can mutate devrune.yaml without first creating a recovery point.

Implementation highlights

  • internal/backup/atomic.goWriteFileAtomic (write to .tmp, Sync, os.Rename) for crash-safe writes.
  • internal/backup/backup.goCreateBackup / ListBackups with timestamped filenames, FIFO rotation, idempotent .gitignore management.
  • internal/diff/diff.go — minimal line-diff used by the restore preview screen (no external deps).
  • internal/cli/manifest_io.gowriteManifestSafe shared by init, sync, menu paths, advisor flows, and model selector.
  • internal/tui/steps/backups.go — full restore flow (list → empty state → diff → confirm → in-progress → success/error). Install failure surfaces an error and leaves the restored manifest on disk (no auto-revert).
  • Tests: atomicity, rotation, reentrancy, hook integration, restore flow with injectable installFn (847 new test lines across the four packages).

Test plan

  • go build ./... clean
  • go test ./internal/backup/... ./internal/diff/... ./internal/cli/... ./internal/tui/steps/... green
  • Manual smoke: devrune init creates .devrune/backups/, second init rotates the previous snapshot
  • Manual smoke: TUI Backups entry shows snapshots, diff preview matches, confirmation triggers pre-restore backup + re-install
  • Manual smoke: simulate disk-full on backup creation → operation aborts with clear error, devrune.yaml untouched

🤖 Generated with Claude Code

davidarce added 2 commits May 5, 2026 09:33
- Add atomic file writes (WriteFileAtomic) to prevent corruption on process kill
- Create timestamped backups before every manifest mutation (install/sync/upgrade)
- Maintain FIFO rotation with maximum 5 backups per project stored locally
- Implement TUI restore menu: list → diff preview → confirmation → auto-install
- Add writeManifestSafe helper to centralize all devrune.yaml write sites
- Ensure idempotent .gitignore management for backup directory
- Cover with tests for atomicity, rotation, reentrancy, and hook integration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant