checkpoints

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 29 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 checkpoints keeps snapshots of the projects the agent changes, in one shadow git store per profile beside the projects themselves: a ref of snapshots for each project, taken before the agent writes, edits or deletes its files, restored by /rollback keeping the edits the user made since, and kept within a count per project and a size for the store

Index

Constants

View Source
const NotEnabled = "Checkpoints are off. Turn on Save in /settings under Tools › Checkpoints."

Said when snapshots are off for a session

Variables

This section is empty.

Functions

func Base

func Base(cfg *config.Config) string

Folder of the profile's checkpoints

func Pick

func Pick(hashes []string, reference string) (string, error)

Hash of the snapshot a reference names among the hashes Snapshots gave: its number among them, counted from one, or a hash as it is

func Refusal

func Refusal(backend terminal.Backend) string

Why snapshots taken on this machine don't serve the terminal backend, empty when they do: its files are a container's or another machine's

Types

type Archive

type Archive struct {
	Name     string
	Bytes    int64
	Modified time.Time
}

One archive of what the folder held before the store was made

type Cleared

type Cleared struct {
	Deleted int
	Freed   int64
	Errors  int
}

What clearing the archives did

type Diff

type Diff struct {
	Stat  string
	Patch string
	// Snapshot a session diff compares with, its oldest kept
	Baseline string
	// Nothing changed
	Empty bool
}

Changes between a snapshot and the files now

type Entry

type Entry struct {
	Hash   string
	Short  string
	When   time.Time
	Reason string
	// What it changed against the snapshot before it
	Files, Insertions, Deletions int
}

One snapshot of a project

type ProjectStatus

type ProjectStatus struct {
	Hash    string
	Workdir string
	// Its folder is there now
	Exists  bool
	Created time.Time
	Touched time.Time
	Commits int
}

One project of the store as its status shows it

type PruneOptions

type PruneOptions struct {
	// Projects not snapshotted for this long go, none for zero
	Retention time.Duration
	// Projects whose folder is gone go
	Orphans bool
	// Megabytes the store is brought within, none for zero
	MaxTotalMB int
	// Projects, by hash, whose folder being gone lets them go; nil lets every one
	Allow map[string]bool
}

What a cleanup took

type Pruned

type Pruned struct {
	Scanned int
	Orphans int
	Stale   int
	Errors  int
	Freed   int64
}

What a cleanup scanned, deleted and freed

func AutoPrune

func AutoPrune(cfg *config.Config) (bool, Pruned, error)

Prunes at most once in the interval the settings set, claiming it in the marker before it runs, never deleting a project whose folder is gone: whether it ran, and what it took

type Restored

type Restored struct {
	// Short hash of the snapshot and why it was taken
	To     string
	Reason string
	// Project, and the file asked for alone
	Directory string
	File      string
	// The restore went by what the agent wrote, keeping the files the user changed since
	Safe bool
	// Files a safe restore put back, the ones the user changed since that it kept, the ones too large for snapshots it left, and those
	// it could not delete
	Files         []string
	Edits         []string
	Oversize      []string
	FailedDeletes []string
}

What a restore did

type Scope

type Scope struct {
	*Store
	Directory string
	Refusal   string
	// Profile whose settings and store these are
	Profile string
}

Checkpoints as one session sees them: its profile's store, the project its folder lies in, and why snapshots taken on this machine don't serve its terminal backend, empty when they do

func For

func For(cfg *config.Config, directory string, host *terminal.Terminal) *Scope

Checkpoints of a session of the profile working in the folder, with the terminal backend the profile picked

type Status

type Status struct {
	Base string
	// The checkpoint folder is there
	Exists      bool
	StoreBytes  int64
	LegacyBytes int64
	TotalBytes  int64
	Projects    []ProjectStatus
	Archives    []Archive
	// Note naming the way out when snapshots are on and the folder is at or above the store's size, empty otherwise
	Footprint string
}

What the profile's checkpoints take: the store, its projects and the archives

type Store

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

Checkpoints of one profile: its shadow store and the limits its settings set

func Open

func Open(cfg *config.Config) *Store

Checkpoints of the profile the settings are of

func (*Store) Changed

func (s *Store) Changed(dir string, since time.Time) []string

Files of the project that differ from the snapshot a span starting at the time began from: changed and deleted ones and new ones, read through a throwaway index so nothing of the store is written; none when snapshots are off, none was taken in the span or git fails

func (*Store) Clear

func (s *Store) Clear() (int64, error)

Deletes the whole checkpoint folder, store and archives, under the store lock: the bytes it freed

func (*Store) ClearLegacy

func (s *Store) ClearLegacy() Cleared

Deletes every archive of what the folder held before the store was made, under the store lock

func (*Store) Diff

func (s *Store) Diff(ctx context.Context, dir, sha string) (*Diff, error)

What changed in the project since the snapshot, its files and its lines, the store lock held. The steps that read stop once the context ends, which it then answers; the project's index, once filled with its files, is always put back as its last snapshot has it

func (*Store) Enabled

func (s *Store) Enabled() bool

Whether the settings ask for snapshots

func (*Store) Holding

func (s *Store) Holding(path string) (string, bool)

Folder of the deepest project the store keeps snapshots of that holds the path, false for a path no project of it holds: where a snapshot taken before the path is deleted brings it back from

func (*Store) List

func (s *Store) List(ctx context.Context, dir string) []Entry

Snapshots of the project in the folder, newest first, as many as are kept, each with what it changed against the one before it: one run of git lists them all with their changes. Should that run fail, they are listed alone and each is measured by a run of its own. Its runs stop once the context ends, which then lists none

func (*Store) Project

func (s *Store) Project(path string) string

Folder whose snapshots a path belongs to: the deepest project of the store holding it, else the nearest folder above it with a project marker below the home folder and its parents, else its own folder

func (*Store) Prune

func (s *Store) Prune(o PruneOptions) (Pruned, error)

Deletes the projects whose folder is gone and those not snapshotted for the retention, old archives, then collects the store's garbage and brings it within its size, under the store lock

func (*Store) Record

func (s *Store) Record(path string)

Notes what the agent just left in a file, the file gone for one it deleted, so a safe restore tells the agent's writes from the edits the user made since. Never fails the call it comes after: a failure is logged

func (*Store) RecordSince

func (s *Store) RecordSince(workdir, sha string)

Notes every file of the project that changed since the snapshot as written by the agent, for a command that changed files it can't name, such as rm or mv in a shell: a safe restore then puts them back rather than keeping them as the user's edits

func (*Store) Rekey

func (s *Store) Rekey(oldRoot, newRoot string) (int, error)

Moves the projects that lay in the old folder of a renamed profile, now in its new one, to the keys of where they are now: their snapshots, metadata and agent write ledgers. A project whose new key already holds snapshots that do not continue its own is left and told; how many moved

func (*Store) Resolve

func (s *Store) Resolve(ctx context.Context, dir, reference string) (string, error)

Hash of the snapshot a reference names: its number in the listing, counted from one, or a hash as it is. Only a number lists the snapshots, and only their hashes

func (*Store) Restore

func (s *Store) Restore(dir, sha, file string, safe bool) (*Restored, error)

Puts the project, or one file of it, back as the snapshot has it, the store lock held. A safe restore of the whole project puts back only the files the agent wrote, keeping those the user changed since. A snapshot of the files as they are is taken first

func (*Store) SessionDiff

func (s *Store) SessionDiff(dir string) (*Diff, error)

Everything that changed in the project since its oldest kept snapshot, empty before the first

func (*Store) SessionDiffContext

func (s *Store) SessionDiffContext(ctx context.Context, dir string) (*Diff, error)

Everything that changed in the project since its oldest kept snapshot, as SessionDiff tells it, its steps that read stopped once the context ends, which it then answers

func (*Store) Snapshots

func (s *Store) Snapshots(ctx context.Context, dir string) []string

Hashes of the snapshots of the project in the folder, newest first, as many as are kept: those List lists, from one run of git that measures none of them; none once the context ended

func (*Store) Status

func (s *Store) Status(ctx context.Context) Status

Sizes of the store and the archives, every project with its count of snapshots, and the note of a store at or above its size: the sizes from one walk of the checkpoint folder, the counts several side by side and stopped once the context ends

func (*Store) Take

func (s *Store) Take(workdir, reason string) string

Snapshots the project, unless it is the root or the home folder, too big, or unchanged since its last snapshot: the snapshot its files are as of now, the one taken or the last when nothing changed since, empty when there is none. Never fails the call it comes before: a failure is logged

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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