Documentation
¶
Overview ¶
Package checkpoint keeps a copy of every file the agent is about to change, so a bad edit can be undone.
An agent that writes files and cannot undo is a frightening thing to leave running. Version control covers the case where the work is in a repository and was committed; this covers the other cases, which is most of them while work is actually happening.
Index ¶
- type ChangedSince
- type Checkpoint
- type Entry
- type RestoreResult
- type Store
- func (s *Store) Clear(sessionID string) error
- func (s *Store) Load(sessionID string) (*Checkpoint, error)
- func (s *Store) PreviewSince(sessionID, marker string) ([]ChangedSince, error)
- func (s *Store) Prune(olderThan time.Duration) (int, error)
- func (s *Store) RecordResult(sessionID, path, marker, resultHash string) error
- func (s *Store) Restore(sessionID string, paths []string) (*RestoreResult, error)
- func (s *Store) RestoreSince(sessionID, marker string, skipExternallyChanged bool) (*RestoreResult, error)
- func (s *Store) Save(sessionID, path, tool, marker string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChangedSince ¶
type ChangedSince struct {
Path string `json:"path"`
// ExternallyChanged is true when the file on disk no longer matches the last
// version the agent recorded — someone edited it outside this session, so a
// revert would clobber that. RestoreSince skips these when asked to.
ExternallyChanged bool `json:"externally_changed"`
// WillDelete is true when reverting means removing the file (it did not exist
// before the marker).
WillDelete bool `json:"will_delete"`
}
ChangedSince describes one file touched at or after a marker, for the edit-message preview.
type Checkpoint ¶
Checkpoint is everything one session changed, in order.
type Entry ¶
type Entry struct {
// Path is the file as it was addressed.
Path string `json:"path"`
// Blob is the stored copy, empty when the file did not exist yet.
Blob string `json:"blob,omitempty"`
// Existed distinguishes "was empty" from "was not there", which restore
// has to get right: the second means delete.
Existed bool `json:"existed"`
Mode uint32 `json:"mode"`
SavedAt time.Time `json:"saved_at"`
// Tool names what was about to touch it.
Tool string `json:"tool,omitempty"`
// Marker groups entries by the conversation turn that produced them — the id
// of the user message that opened the turn. It lets a rollback target "the
// state as of message X" rather than only the start of the whole session.
// Empty on entries written before markers existed (treated as oldest).
Marker string `json:"marker,omitempty"`
// ResultHash is the sha256 of what the agent WROTE to this path in this turn,
// recorded just after the write. It is how we tell later whether the file was
// edited outside the session: if the current file matches a ResultHash, the
// session produced that state; if it matches none, someone else changed it.
ResultHash string `json:"result_hash,omitempty"`
}
Entry is one saved file version.
type RestoreResult ¶
RestoreResult reports what a rollback did.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store writes checkpoints under a root directory.
func (*Store) Load ¶
func (s *Store) Load(sessionID string) (*Checkpoint, error)
Load reads a session's checkpoint.
func (*Store) PreviewSince ¶
func (s *Store) PreviewSince(sessionID, marker string) ([]ChangedSince, error)
PreviewSince lists the files changed at or after `marker`, flagging which were edited outside the session (so the caller can warn or skip them).
func (*Store) Prune ¶
Prune removes checkpoints older than the given age. Left alone these grow without bound, since every session that touched a file leaves one.
func (*Store) RecordResult ¶
RecordResult notes the hash of what the agent just wrote to a path, so a later rollback can tell whether the file was since edited outside the session. It appends a result-only entry (no blob), identified by ResultHash being set.
func (*Store) Restore ¶
func (s *Store) Restore(sessionID string, paths []string) (*RestoreResult, error)
Restore puts a session's files back the way they were. Files created during the session are deleted, because "back the way it was" means not existing.
Passing paths restores only those; passing none restores everything.
func (*Store) RestoreSince ¶
func (s *Store) RestoreSince(sessionID, marker string, skipExternallyChanged bool) (*RestoreResult, error)
RestoreSince reverts files touched at/after `marker` to their state just before it. When skipExternallyChanged is set, a file whose current contents no longer match the agent's last recorded write is left untouched.
func (*Store) Save ¶
Save copies a file before it is changed. It records at most one version per file per turn (marker): the first save within a turn is the file's state as that turn began. Across turns it keeps one snapshot each, so a rollback can return a file to how it was as of any given message.
marker is the id of the user message that opened the current turn; pass "" if unknown (those entries are treated as the oldest state).