Undo agent changes

Roll back the working tree and conversation history when the agent makes a mess.

What /undo does

Cantrip snapshots your charm's working tree into a hidden git repository immediately before each user turn enters the conversation loop. /undo restores that snapshot and strips the user's last message plus every assistant and tool message that followed it from the conversation history.

Two affordances matter here:

/undo stacks. Run it twice to walk back two user turns; run it three times for three. Each step restores files and truncates conversation messages.

Re-applying with /redo

/redo un-does the most recent /undo — it restores both the working-tree state and the messages that were sliced off.

Two important details:

Turning snapshots off

Snapshotting commits the entire charm working tree (minus gitignored paths and the .cantrip/ session store) before every user turn. For most charms this is sub-second. For a charm that vendors a large dependency tree it can stutter.

Two equivalent escape hatches:

$ cantrip --no-snapshots /path/to/my-charm
$ CANTRIP_SNAPSHOTS=false cantrip /path/to/my-charm

When snapshots are off, /undo and /redo print a clear "snapshots disabled" message rather than silently doing nothing. Re-enable per session by relaunching without the flag, or set CANTRIP_SNAPSHOTS=true to override an inherited environment.

What /undo does not do