snapshots

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package snapshots implements pre-edit file rollback per docs/design.md §8.4.

Before any tool that mutates files, the agent calls Take(sessionID, stepIdx, paths). Each affected file is copied into:

.deepseek/snapshots/<sessionID>/<stepIdx>/<base64-of-relpath>

/undo restores the most-recent step's snapshots; /undo N restores N steps. Prune trims to the most recent K sessions.

Snapshots never include directories — only files we observe being touched by name. Bash commands hand AffectedPaths==nil to the agent, so destructive bash is handled by the Duet validator and the permission prompt, not by pre-snapshot.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager owns the on-disk snapshot directory tree. Construct with New.

All exported mutating operations (Take/Undo/Prune) hold mu so concurrent callers cannot interleave reads of the step-dir listing with removals.

func New

func New(rootOverride string) *Manager

New returns a Manager rooted at .deepseek/snapshots under cwd. Passing a non-empty rootOverride is for tests.

func (*Manager) HasSnapshots

func (m *Manager) HasSnapshots(sessionID string) bool

HasSnapshots reports whether the session has any unconsumed snapshots.

func (*Manager) Prune

func (m *Manager) Prune(keepSessionIDs []string) (int, error)

Prune removes snapshot dirs for sessions not in `keepSessionIDs`. Typical usage: keep the most recent 30 session IDs from the store.

func (*Manager) Take

func (m *Manager) Take(sessionID string, stepIdx int, paths []string) (int, error)

Take snapshots each existing path in `paths` into the session/step directory. Missing files are recorded as "absent" tombstones so /undo knows to remove them when reverting.

Returns the number of snapshots actually written.

func (*Manager) Undo

func (m *Manager) Undo(sessionID string, n int) (int, error)

Undo restores the most recent N step snapshots for a session, in reverse chronological order. Returns the number of files restored.

Jump to

Keyboard shortcuts

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