Artifact c09ed7f7226db203ee970cf72fb4091a36799891ed7bb24e0f28fa05702b1619:
- File docs/design/rewind.md — part of check-in [0204b3a2c9] at 2026-11-22 12:58:27 on branch rewind — rewind: note blob retention (user: dmestas, size: 3134) [annotate] [blame] [check-ins using]
Rewind: file history and restores
Status: built 2026-11-22 (ticket 29). Tier: core (src/filelog.c: the record and the restore) and
bundled (src/rewind.c: what to restore and when to refuse). Clock: durability. Record:
pic_file_change per write or edit and per restored file, pic_blob for kept bytes,
pic_restore per restore. Default: on, rewindMaxBytes 1 MiB.
What it is
Claude Code's checkpoints, over pic's journal: go back to before a user message and restore the conversation, the files, or both. The user-facing description is rewind; the commit points are in durability.
Core records and enforces
- Each write or edit call commits the file's prior state with its "started": exists or not, mode,
SHA3-256, and the bytes (content-addressed in
pic_blob, deflated by the sqlar rule) when no larger thanrewindMaxBytes; past it,pre_keptis 0 and the hash is still kept. The file is read before the transaction begins. A replay finds the row and keeps it: the first attempt saw the file before any write. The file's state after the call (hash, mode) commits with the result. - A restore is journaled whole before any file is touched: one
pic_restorerow and onepic_file_changeper file, holding the file as found (so an undo can put it back) and the state to restore. Applying it writes only a file still as found; a file already in the target state counts as restored, anything else is left (changed). Outcomes, the conversation fork it asked for (fork_at) anddonecommit in one transaction, so a crash leaves both or neither. A started restore is finished by whoever next takes the conversation's lease outside a transaction; open's recovery does, so the next pic of any kind finishes it.
The component decides
rewind.c picks the files (every write and edit on the conversation's path after the message),
the target of each (the earliest such call's pre-image), the refusals (the file is not what the
conversation last left there, counting its own restores; its earlier bytes were not kept; its call
never finished), and whether to go on past them (--force-partial, or a yes in the terminal). The
conversation half is pic_fork at the message's parent, as /fork does. Undo restores the
pre-images of the latest restore's restored files.
Decisions
- Esc Esc opens
/rewind, Claude Code's binding, where Pi opens/tree. Pi'sdoubleEscapeActionsetting is honoured withrewindadded, so a Pi user can taketreeback. - A new seam: rpc.c is core and may not call
rewind.c, sopic_rpc_hostcarries the components' commands (pic_rpc_command), filled by main.c. It is the command registry the stubs inci/tiers.stubsalready point at; the model, skill and template commands could move onto it. - Retention:
pic_blobis not pruned yet;pic prunecould drop bytes no conversation can rewind to (older than a setting), as it does for images. - Not tracked: bash,
!commands, and anything outside pic, as in Claude Code. Directories a write created are not removed.