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
- func Base(cfg *config.Config) string
- func Pick(hashes []string, reference string) (string, error)
- func Refusal(backend terminal.Backend) string
- type Archive
- type Cleared
- type Diff
- type Entry
- type ProjectStatus
- type PruneOptions
- type Pruned
- type Restore
- type Restored
- type Scope
- type Status
- type Store
- func (s *Store) Changed(dir string, since time.Time) []string
- func (s *Store) Clear() (int64, error)
- func (s *Store) ClearLegacy() Cleared
- func (s *Store) Diff(ctx context.Context, dir, sha string) (*Diff, error)
- func (s *Store) Enabled() bool
- func (s *Store) Holding(path string) (string, bool)
- func (s *Store) List(ctx context.Context, dir string) []Entry
- func (s *Store) Primed(workdir string) bool
- func (s *Store) Project(path string) string
- func (s *Store) Prune(o PruneOptions) (Pruned, error)
- func (s *Store) Record(path string)
- func (s *Store) RecordSince(workdir, sha string)
- func (s *Store) Rekey(oldRoot, newRoot string) (int, error)
- func (s *Store) Resolve(ctx context.Context, dir, reference string) (string, error)
- func (s *Store) Restore(dir, sha, file string, safe bool) (*Restored, error)
- func (s *Store) SessionDiff(dir string) (*Diff, error)
- func (s *Store) SessionDiffContext(ctx context.Context, dir string) (*Diff, error)
- func (s *Store) Snapshots(ctx context.Context, dir string) []string
- func (s *Store) Status(ctx context.Context) Status
- func (s *Store) Take(workdir, reason string) string
Constants ¶
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 ¶
Types ¶
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 Restore ¶
type Restore struct {
// Folder put back, as the settings write it, and the checkpoint it went back to
Folder string `json:"folder"`
To string `json:"to"`
// File of the folder put back alone, empty for more; files a safe restore put back, relative to the folder, none when every file of
// the folder went back
File string `json:"file,omitempty"`
Files []string `json:"files,omitempty"`
// When it was made
At time.Time `json:"at"`
}
A restore of checkpoint files into a folder, as every session working there learns of it
func RestoredSince ¶
Restores into the folder, or into a folder it lies in or that lies in it, made after the time given, oldest first
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
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 (*Store) Changed ¶
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 ¶
Deletes the whole checkpoint folder, store and archives, under the store lock: the bytes it freed
func (*Store) ClearLegacy ¶
Deletes every archive of what the folder held before the store was made, under the store lock
func (*Store) Diff ¶
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) Holding ¶
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 ¶
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) Primed ¶
Primed reports whether the project's index exists, which makes its next snapshot incremental.
func (*Store) Project ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Everything that changed in the project since its oldest kept snapshot, empty before the first
func (*Store) SessionDiffContext ¶
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 ¶
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 ¶
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 ¶
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