checkpoint

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

type Checkpoint struct {
	SessionID string  `json:"session_id"`
	Entries   []Entry `json:"entries"`
}

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

type RestoreResult struct {
	Restored []string
	Deleted  []string
	Failed   map[string]string
}

RestoreResult reports what a rollback did.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store writes checkpoints under a root directory.

func NewStore

func NewStore(dir string) *Store

NewStore builds a store rooted at dir.

func (*Store) Clear

func (s *Store) Clear(sessionID string) error

Clear forgets a session's checkpoint.

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

func (s *Store) Prune(olderThan time.Duration) (int, error)

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

func (s *Store) RecordResult(sessionID, path, marker, resultHash string) error

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

func (s *Store) Save(sessionID, path, tool, marker string) error

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL