feat(rewind): git working-tree checkpoints before Bash commands#121
Merged
Conversation
Extends checkpoint/rewind (§3.15.9) to cover Bash file mutations. Edit/Write
snapshot a known file path; a shell command's targets aren't known ahead of
time, so for Bash we capture a git working-tree checkpoint instead.
core (sessions/snapshots.ts):
- captureGitCheckpoint({cwd,reason,seq}) — records a commit-ish (`git stash
create`, or HEAD when the tree is clean) capturing the pre-command TRACKED
state. No-op (null) outside a git work tree / in a repo with no commits.
- Snapshot gains `kind: 'file' | 'git'` + `gitRef`. restoreSnapshot() now
branches: 'git' → `git checkout <ref> -- <files changed since>` (reverts the
tracked files the command touched); 'file' → blob write as before. Returns
the restored path list.
- SessionManager.gitCheckpoint() wraps it; exported from the package.
agent.ts: before executing a Bash tool (with a session), capture a pre-Bash
git checkpoint. Cheap — just a stash-create ref + a manifest line, no blob copy.
cli (/rewind): help mentions Bash checkpoints; `code`/`both` report the
reverted file count for git checkpoints.
Limitation (documented): untracked files a command creates aren't captured by
the checkpoint, so rewinding won't remove them.
Tests: +4 (snapshots.test.ts) against a real temp git repo — clean-tree
checkpoint + revert round-trip, capturing the *uncommitted* pre-command state
(not just HEAD) via stash-create, non-git dir → null, manifest round-trip.
Core suite 588 green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Extends checkpoint/rewind (
docs/DEVELOPMENT_PLAN.md§3.15.9) to cover Bash file mutations. Edit/Write snapshot a known file path; a shell command's targets aren't known ahead of time, so for Bash we capture a git working-tree checkpoint instead — the right tool for snapshotting an arbitrary set of changes.How it works
captureGitCheckpoint({cwd, reason, seq})records a commit-ish —git stash create(captures the current tracked working-tree state without touching anything), orHEADwhen the tree is clean. No-op (returnsnull) outside a git work tree or in a repo with no commits.Snapshotgainskind: 'file' | 'git'+gitRef.restoreSnapshot()branches:git→git checkout <ref> -- <files changed since the checkpoint>, reverting exactly the tracked files the command touched.file→ blob write (unchanged).Bashtool (with an active session), capture apre-Bashcheckpoint. Cheap — a stash-create ref + one manifest line, no blob copy./rewind: help text mentions Bash checkpoints;code/bothreport the reverted file count.Limitation (documented in code + commit)
Untracked files a command creates aren't captured by the checkpoint, so rewinding won't remove them. Tracked-file modifications/deletions are reverted.
Tests
+4 in
snapshots.test.ts, all against a real temp git repo:git stash create, not justHEAD— restoring returns the dirty-before-Bash content.null.listSnapshots).Core suite 588 green; CLI 78; full repo green via pre-commit.
🤖 Generated with Claude Code