snapshot

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package snapshot checkpoints the workspace for /undo in a shadow git repo outside the project, with the workspace as its work tree. Snapshots are whole-workspace trees, so they capture changes from any source (tools, bash, manual edits) and never touch the user's own .git.

Index

Constants

This section is empty.

Variables

View Source
var ErrSnapshotExpired = errors.New("the checkpoint has expired (checkpoints are reclaimed after 7 days) and can no longer be restored")

ErrSnapshotExpired means gc pruned the snapshot. The expired entry is already dropped from the stack.

View Source
var ErrTrackerClosed = errors.New("snapshot tracker closed")

Functions

This section is empty.

Types

type Tracker

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

Tracker records one snapshot per turn: Track runs at each turn boundary and Undo reverts the most recent turn's file changes.

func New

func New(gitDir, workTree, statePath string) *Tracker

New loads the undo stack from statePath, so it survives a restart.

func (*Tracker) Close

func (t *Tracker) Close()

Close waits for the background gc, so cleanup and shutdown don't race it.

func (*Tracker) DiffTop

func (t *Tracker) DiffTop() (string, error)

DiffTop returns a numstat diff of what /undo would roll back.

func (*Tracker) Rebind

func (t *Tracker) Rebind(gitDir, workTree, statePath string)

Rebind switches to another workspace when the conversation enters or leaves a worktree. gc runs once per process, so a worktree's shadow repo is normally not collected; it is removed with the worktree.

func (*Tracker) Redo

func (t *Tracker) Redo() (changed []string, ok bool, err error)

Redo returns ok=false when there is nothing to redo. Redo snapshots live only in memory, so they are too recent for gc to prune.

func (*Tracker) Track

func (t *Tracker) Track() (bool, error)

Track returns false when the workspace is unchanged since the last snapshot. Callers ignore its error so a snapshot failure never blocks a turn.

func (*Tracker) Undo

func (t *Tracker) Undo() (changed []string, ok bool, err error)

Undo returns ok=false when there is nothing to undo.

Jump to

Keyboard shortcuts

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