Snapshots (Undo / Redo)
Ulmi records every file mutation made by the agent so you can undo or redo individual changes without leaving the TUI.
The package is internal/snapshot and its
high-level entry point is snapshot.Manager.
What gets snapshotted
The write, edit, delete, and patch tools all integrate with the
snapshot manager. For every call:
- Capture — the pre-mutation state of the target file is read into a blob (a content-addressable byte sequence).
- Mutate — the tool performs its file change as usual.
- Record — a journal entry is appended with the path, op type, and the before-blob ID. The “after” state is captured as a fresh blob too, so redo can re-apply the change.
If the snapshot manager is missing or the file is outside the configured workspace, the tool falls back to plain mutation (no undo possible). The contract is best-effort: snapshot failures never block the tool from running.
Two backends
cas (default)
A simple content-addressable store on the local filesystem. Layout:
<root>/<session-id>/
├── objects/<sha256[:2]>/<sha256[2:]> # gzip-compressed blob
├── journal.jsonl # one Entry per line
└── cursor # current cursor as EntryIDNo external dependencies, fast, and easy to inspect with jq or the eye.
Implementation: internal/snapshot/cas.
shadowgit
Uses an isolated git repository per session (built on
go-git). Each mutation becomes a
commit; blobs are git objects keyed by their SHA1. Useful when you want a
familiar git log-style view of the changes.
Implementation:
internal/snapshot/shadowgit.
Switch backend via config:
snapshots:
backend: shadowgit # default: casBoth backends conform to the
snapshot.Backend interface and are
fully interchangeable.
Where snapshots live
~/.cache/ulmi/snapshots/<session-id>/ # default rootOverride with snapshots.path. Each session gets its own subdirectory so
you can clean up or back them up individually.
The default MaxFileSize is 10 MiB — files larger than this are skipped
silently with a warning. Files outside the workspace root are rejected
unless snapshots.allow_outside_workspace: true.
Using undo / redo
Inside the TUI:
| Combo | Action |
|---|---|
Ctrl+X U or /undo | Restore the file at the current cursor to its pre-mutation state and step the cursor backward. |
Ctrl+X R or /redo | Re-apply the next mutation forward of the cursor. |
Each operation prints a short summary plus a unified diff of the change
that was made. Diffs use the unified diff engine in
internal/diff.
If the snapshot store cannot be opened (permissions, disk), the TUI
shows a toast and /undo stays disabled. The factory lives in
internal/cli; the TUI only holds snapshot.OpenFunc.
A new mutation while the cursor is not at the latest entry truncates the redo stack (standard linear undo semantics).
CLI inspection
ulmi snapshot list # current cwd's startup session
ulmi snapshot list --session <id> # a specific saved session
ulmi snapshot list --limit 10Output is reverse-chronological:
SEQ TIME OP PATH
12 2026-05-06 12:42:01 edit internal/api/handler.go
11 2026-05-06 12:41:58 write internal/api/handler_test.go
10 2026-05-06 12:35:11 edit internal/auth/login.go
…Configuration
snapshots:
backend: cas # cas | shadowgit
path: "" # default: ~/.cache/ulmi/snapshots
max_file_size: 10485760 # 10 MiB
allow_outside_workspace: false
retention_days: 30retention_days is a hint; orphaned session directories older than this
will be removed in a future release. It does not yet affect runtime
behaviour.
Edge cases
- Files larger than
max_file_size— the capture step is skipped and a warning is logged. The mutation still happens; undo will simply not be available for that file. - Files outside the workspace — same as above unless
allow_outside_workspaceistrue. - Symlinks — the snapshot follows links and stores the target’s content, the same way the underlying tool reads / writes files.
- Binary files — handled transparently by both backends. Diff output may be empty when the diff engine cannot produce a useful text view.
Programmatic use
When invoking tools directly (e.g. tests, custom commands), inject a manager into the context:
ctx = snapshot.WithManager(ctx, mgr)
result := registry.Execute(ctx, callID, "edit", params)The mutation tools call snapshot.FromContext(ctx) to find it. See
internal/snapshot/context.go.