Skip to content

Add to undo the last applied diff #67

Description

@that-github-user

Problem

thinktank apply patches the working tree directly. If the applied changes break something or the user changes their mind, there is no thinktank rollback — the user must manually run git checkout or git restore . and figure out which files were changed.

This is especially painful when:

  • The diff touches many files
  • The user already staged other changes they don't want to lose
  • They applied agent 2 but now want to try agent 3 instead

Proposed Solution

Before applying a diff, save a restore point:

  • Record the list of files to be patched
  • Store the pre-apply state of each file in .thinktank/restore-<timestamp>.json

Add a thinktank rollback command:

$ thinktank rollback
Restoring 4 files to pre-apply state...
  ✓ src/parser.ts
  ✓ src/index.ts
  ✓ tests/parser.test.ts
  ✓ package.json
Rollback complete. Working tree restored to state before last apply.

Only the most recent apply is tracked (not a full undo stack). Rollback is only available until the next apply or run.

Acceptance Criteria

  • apply saves a restore snapshot to .thinktank/restore-<timestamp>.json before patching
  • thinktank rollback restores patched files to their pre-apply content
  • If no restore point exists, rollback prints a clear error: "No restore point found. Nothing to roll back."
  • Rollback works even if the user has made additional edits after apply (only files touched by apply are restored)
  • Restore point file is excluded from .gitignore entries (already covered by .thinktank/)
  • --preview mode does not create a restore point (no changes were made)
  • Restore file is included in the existing 0o600 permission policy

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions