Help us shape the future of Go! Take the 2026 Go Developer Survey

snapshot

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package snapshot captures and restores the files under a working directory for opt-in workspace snapshots (--snapshots) and --rewind.

A store lives at <root>/.tinyagent/snapshots. File contents are kept once each, by SHA-256, under objects/; each snapshot is a manifest under manifests/ listing every captured path with its type, permission bits and content hash. Nothing is ever deleted automatically.

Index

Constants

View Source
const DefaultMaxFileBytes = 2 << 20

DefaultMaxFileBytes is the default max_file_bytes (2 MiB).

View Source
const StoreDir = ".tinyagent/snapshots"

StoreDir is the store's location relative to the working directory.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	// Op is "M" (modified: restored to the snapshot), "A" (added since:
	// removed) or "D" (deleted since: recreated).
	Op   string
	Path string
	// contains filtered or unexported fields
}

Change is one difference between the working directory and a snapshot.

type Entry

type Entry struct {
	Path   string `json:"path"` // slash-separated, relative to the root
	Type   string `json:"type"` // "file" or "symlink"
	Mode   uint32 `json:"mode,omitempty"`
	Hash   string `json:"sha256,omitempty"`
	Size   int64  `json:"size,omitempty"`
	Target string `json:"target,omitempty"` // symlink target
}

Entry is one captured path.

type Manifest

type Manifest struct {
	Version      int     `json:"version"`
	ID           string  `json:"id"`
	Root         string  `json:"root"`
	Kind         string  `json:"kind"`
	Step         int     `json:"step"`
	Time         string  `json:"time"`
	MaxFileBytes int64   `json:"max_file_bytes"`
	Entries      []Entry `json:"entries"`
	// Dirs lists every captured directory (without the root itself).
	Dirs []string `json:"dirs,omitempty"`
	// Ignored lists the gitignored paths left out (an ignored directory
	// once); Large lists the files over MaxFileBytes; Excluded lists the
	// configured exclusions (trajectory and event log files). A rewind never
	// removes any of them.
	Ignored  []string `json:"ignored,omitempty"`
	Large    []string `json:"large,omitempty"`
	Excluded []string `json:"excluded,omitempty"`
}

Manifest is one snapshot.

type Options

type Options struct {
	// MaxFileBytes is the largest file captured; 0 means DefaultMaxFileBytes.
	MaxFileBytes int64
	// Exclude lists absolute paths never captured (a directory excludes
	// everything under it): the trajectory and the
	// event log database. A trajectory's .tinyagent-*.json save temps and
	// a database's -wal, -shm and -journal files are excluded with them.
	Exclude []string
}

Options configures a store.

type Plan

type Plan struct {
	Changes []Change
	// contains filtered or unexported fields
}

Plan lists what restoring target would change, sorted by path.

func (*Plan) Counts

func (p *Plan) Counts() (m, a, d int)

Counts returns how many paths are modified, added and deleted.

type Result

type Result struct {
	Restored []string
	// NotRestored lists the path that failed first and every planned path
	// after it; the restore stops at the first failure.
	NotRestored []string
	Err         error
}

Result reports a restore.

type Store

type Store struct {
	Root string // canonical working directory
	Dir  string // the store directory
	// contains filtered or unexported fields
}

Store reads and writes one store.

func Open

func Open(root string, opts Options) (*Store, error)

Open creates (or reuses) the store under root.

func OpenExisting

func OpenExisting(root, dir string, opts Options) (*Store, error)

OpenExisting opens the store at dir for root without creating anything.

func (*Store) Apply

func (s *Store) Apply(plan *Plan) Result

Apply carries out plan: removals first, then directories, then writes. It stops at the first failure.

func (*Store) Current

func (s *Store) Current() (*Manifest, error)

Current scans the working directory without storing anything.

func (*Store) Load

func (s *Store) Load(id string) (*Manifest, error)

Load reads a manifest, checking it belongs to this root and that every object it needs is present.

func (*Store) PlanRestore

func (s *Store) PlanRestore(target *Manifest) (*Plan, error)

PlanRestore compares the working directory with target. Paths target left out (gitignored, oversized or excluded) are never touched.

func (*Store) Take

func (s *Store) Take(kind string, step int) (trajectory.Snapshot, error)

Take captures the working directory and returns its trajectory record.

Jump to

Keyboard shortcuts

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