feat(snapshot): workspace snapshot and time-travel debugging#80
Merged
feat(snapshot): workspace snapshot and time-travel debugging#80
Conversation
d648d89 to
7c41425
Compare
- 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>
7c41425 to
8761b56
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds workspace snapshot capability so agents can capture and restore workspace state — enabling time-travel debugging and safe experimentation.
Changes
src/snapshot.rs—SnapshotStorewithcreate,list,diff,restoreoperations backed by systemtarsrc/config.rs—SnapshotConfig(opt-in, configurable dir/limits/patterns)src/main.rs—sparks snapshot create|list|diff <a> <b>|restore <id> [--apply]config.example.toml—[snapshot]sectionWorkflow
```
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
Pre-PR Checklist
cargo check -qpassescargo test -qpasses