Documentation
¶
Overview ¶
Package checkpoint is fairpeer's snapshot-based edit safety net. Before a writer tool changes a file, the agent records the file's pre-edit content here, keyed to the current user turn; a frontend can then rewind the workspace (and, via the controller, the conversation) to an earlier turn.
It is deliberately git-free (like Claude Code's rewind): snapshots live beside the session, never touch the user's git, and work in a non-git directory. Only edit-tool changes are tracked — bash side effects are not (a shell command's targets can't be known in advance), which is why the capture hook only fires for tools that can Preview their change.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Checkpoint ¶
type Checkpoint struct {
Turn int `json:"turn"`
Time time.Time `json:"time"`
Prompt string `json:"prompt"`
MsgIndex int `json:"msgIndex"`
Files []FileSnap `json:"files"`
}
Checkpoint anchors the pre-edit state of every distinct file touched during one user turn. MsgIndex is len(Session.Messages) at the turn's start — the conversation-rewind boundary — persisted so a resumed session can rewind the conversation and fork, not just the code.
type FileSnap ¶
type FileSnap struct {
Path string `json:"path"`
Content *string `json:"content"`
Encoding *fileenc.Kind `json:"encoding,omitempty"`
}
FileSnap is one file's state at the moment it was first touched in a turn. Content == nil means the file did not exist then, so a restore deletes it.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store holds a session's checkpoints in memory and, when dir is set, persists one JSON file per turn under it (cheap delete, corruption-isolated). All methods are safe for concurrent use — the agent snapshots from tool goroutines.
func New ¶
New returns a store for the given checkpoint dir and workspace root, loading any checkpoints already persisted under dir. A "" dir disables persistence (the store still works in memory for the session).
func (*Store) Begin ¶
Begin opens a checkpoint for a new user turn, finalizing the previous one. The prompt labels it in the picker; msgIndex is the conversation-rewind boundary.
func (*Store) Bounds ¶
Bounds returns turn → MsgIndex over all checkpoints (persisted + current), so the controller can rebuild its conversation-rewind boundaries after loading a resumed session's checkpoints from disk.
func (*Store) NextTurn ¶
NextTurn returns the turn number a new checkpoint should take: one past the highest existing turn (0 when empty), so a resumed session keeps numbering without colliding with checkpoints loaded from disk.
func (*Store) RestoreCode ¶
RestoreCode reverts the workspace to its state at the start of turn `fromTurn`: for every file touched in turn fromTurn or later, it writes back that file's earliest recorded content (or deletes it when the earliest snapshot was nil). Returns the paths written and deleted.