Skip to main content

Module undo

Module undo 

Source
Expand description

Undo stack for file mutations. Undo stack for file mutations.

Snapshots file contents before Write/Edit/Delete tool execution. Each turn’s mutations are grouped into a single undo entry.

§How it works

  1. Before any file mutation, the current file contents are snapshotted
  2. All mutations in a single turn are grouped into one undo entry
  3. /undo restores all files from the most recent entry
  4. Stack depth is unlimited — undo as many turns as needed

§What gets tracked

  • Write: snapshots the file if it existed (for overwrite), or marks as “created”
  • Edit: snapshots the file before the edit
  • Delete: snapshots the file contents before deletion

Git checkpointing provides a separate safety net via git stash-style snapshots before each turn. /undo is faster (in-memory) but git checkpoints survive process crashes.

Structs§

UndoEntry
A snapshot of file states before a turn’s mutations.
UndoStack
Stack of undo entries, one per turn.

Functions§

extract_file_path
Extract the target file path from tool arguments.
is_mutating_tool
Check if a tool name is a file-mutating tool that should be snapshotted.