Skip to content

feat(snapshot): workspace snapshot and time-travel debugging#80

Merged
Enreign merged 2 commits intomainfrom
feat/workspace-snapshots
Mar 18, 2026
Merged

feat(snapshot): workspace snapshot and time-travel debugging#80
Enreign merged 2 commits intomainfrom
feat/workspace-snapshots

Conversation

@Enreign
Copy link
Copy Markdown
Collaborator

@Enreign Enreign commented Mar 16, 2026

Description

Adds workspace snapshot capability so agents can capture and restore workspace state — enabling time-travel debugging and safe experimentation.

Changes

  • src/snapshot.rsSnapshotStore with create, list, diff, restore operations backed by system tar
  • src/config.rsSnapshotConfig (opt-in, configurable dir/limits/patterns)
  • src/main.rssparks snapshot create|list|diff <a> <b>|restore <id> [--apply]
  • config.example.toml[snapshot] section

Workflow

```
sparks snapshot create --label "before-refactor"

... agent makes changes ...

sparks snapshot list
sparks snapshot diff abc123 def456 # see what changed
sparks snapshot restore abc123 # dry-run
sparks snapshot restore abc123 --apply # actually restore
```

Type of Change

  • New feature

Pre-PR Checklist

  • cargo check -q passes
  • cargo test -q passes

@Enreign Enreign force-pushed the feat/workspace-snapshots branch from d648d89 to 7c41425 Compare March 18, 2026 22:08
Enreign and others added 2 commits March 18, 2026 23:10
- SnapshotStore: create, list, diff, restore workspace snapshots as tar.gz
- SnapshotConfig: enabled (opt-in), snapshot_dir, max_snapshots, max_workspace_mb,
  include/exclude glob patterns (target/, .git/, .worktrees/ excluded by default)
- CLI: 'sparks snapshot create|list|diff <a> <b>|restore <id> [--apply]'
- Snapshots stored in ~/.sparks/snapshots/ with JSON metadata sidecars
- Auto-prune: keeps only max_snapshots most recent (default: 20)
- Workspace size guard: skip snapshot if workspace > max_workspace_mb (default: 50MB)
- Diff uses 'diff -rq' between extracted archives for file-level change summary
- Restore is dry-run by default; requires --apply flag to actually overwrite
- 4 unit tests for metadata, size formatting, config defaults, empty list

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Fix diff() leaking tmp_a when extract_snapshot(tmp_b) fails; clean up
  both temp dirs on any early-return error path.
- Fix meta_path_for(): replace broken .with_extension("").with_extension("json")
  (which produced abc.tar.json) with a helper that strips the full .tar.gz
  compound extension, producing the correct abc.json sidecar name.
- Add restore() workspace-root safety guard: canonicalize the path and
  refuse to extract into "/" or other dangerously shallow paths.
- Increase snapshot ID display from 8 to 12 hex chars throughout (list,
  diff header, create, restore) so users can always find a unique prefix
  to disambiguate when two IDs share the same first 8 characters.
- Rename snapshot_store_list_empty_dir test to _nonexistent_dir (dir was
  never created); add a true empty-dir variant that does create the dir.
- Add meta_path_strips_tar_gz_correctly unit test.
- Add snapshot_default_excludes_target_and_git unit test.
- Add create_tar_command_includes_exclude_flags structural test.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Enreign Enreign force-pushed the feat/workspace-snapshots branch from 7c41425 to 8761b56 Compare March 18, 2026 22:10
@Enreign Enreign merged commit 6c8dc8a into main Mar 18, 2026
4 checks passed
@Enreign Enreign deleted the feat/workspace-snapshots branch March 18, 2026 22:11
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