{"modulePath":"github.com/memcode-ai/memcode","version":"v0.56.16","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package checkpoint\n\nPackage checkpoint stores per-turn PRE-IMAGES of files the agent edits, so a bad run can be rewound without touching git: before edit\\_file mutates a file, its current bytes (or its absence) are snapshotted under .memcode/checkpoints/\\\u003csession\u003e/\\\u003cseq\u003e/. Rewinding to turn N restores every touched file to its earliest pre-image from turns N..latest — the state the tree had before turn N ran. Shadow copies only: git stays untouched, and changes made OUTSIDE the agent's edit tool (bash, the user's editor) are not captured — this is the agent-edit undo, not a filesystem time machine.\n\n## Types\n\n```go\ntype Checkpoint struct {\n\t// contains filtered or unexported fields\n}\n```\nCheckpoint is an open checkpoint accumulating snapshots for the current turn.\n\n```go\nfunc (cp *Checkpoint) Empty() bool\n```\nEmpty reports whether the checkpoint captured nothing (no edits this turn).\n\n```go\nfunc (cp *Checkpoint) Snapshot(relPath string)\n```\nSnapshot records path's current state (bytes or absence) once per checkpoint. relPath may be absolute (it is normalized against the root). Best-effort: snapshot failures never block the edit itself.\n\n```go\ntype File struct {\n\tPath    string `json:\"path\"`    // repo-relative\n\tExisted bool   `json:\"existed\"` // false → the edit CREATED it (rewind deletes it)\n}\n```\nFile is one snapshotted pre-image.\n\n```go\ntype Log struct {\n\t// contains filtered or unexported fields\n}\n```\nLog is one session's checkpoint store.\n\n```go\nfunc New(root, sessionID string) *Log\n```\nNew opens (or creates) the checkpoint log for a session.\n\n```go\nfunc (l *Log) Begin(label string) *Checkpoint\n```\nBegin opens a checkpoint for one turn. Nothing is written until the first Snapshot, so turns that never edit cost nothing. Prunes old checkpoints.\n\n```go\nfunc (l *Log) List() []Manifest\n```\nList returns this session's checkpoints that captured edits, oldest first.\n\n```go\nfunc (l *Log) Restore(seq int) ([]string, error)\n```\nRestore rewinds the tree to BEFORE checkpoint seq: every file touched from seq onward is restored to its earliest pre-image (created files are deleted), and the consumed checkpoints are dropped. Returns the restored file list.\n\n```go\ntype Manifest struct {\n\tSeq   int       `json:\"seq\"`\n\tLabel string    `json:\"label\"` // the user turn that caused the edits, trimmed\n\tAt    time.Time `json:\"at\"`\n\tFiles []File    `json:\"files\"`\n}\n```\nManifest describes one checkpoint (one turn that edited files).\n\n","path":"github.com/memcode-ai/memcode/internal/checkpoint","name":"checkpoint","synopsis":"Package checkpoint stores per-turn PRE-IMAGES of files the agent edits, so a bad run can be rewound without touching git: before edit_file mutates a file, its current bytes (or its absence) are snapshotted under .memcode/checkpoints/\u003csession\u003e/\u003cseq\u003e/.","isRedistributable":true}
