Documentation
¶
Overview ¶
Package checkpoints keeps per-conversation snapshots of a working folder in a shadow git repository (one per tab and folder, under the runtime's data folder) and returns the folder to one of them. The repositories, their refs, commit messages and the rewind log are laid out exactly as the previous runtime laid them out, so either runtime reads what the other wrote.
Index ¶
- Constants
- Variables
- func IsSafeRelPath(rel string) bool
- func IsTurnEnd(prev, next string) bool
- func ValidID(id string) bool
- func ValidTabID(id string) bool
- type API
- type Checkpoint
- type Diff
- type Hooks
- type Limits
- type Param
- type Request
- type RewindResult
- type Scope
- type Skipped
- type Store
- type TextAnswer
Constants ¶
const ( KindTurn = "turn" KindBeforeRewind = "before-rewind" )
const ( Throttled = "throttled" TooManyFiles = "too-many-files" GitFailed = "git-failed" )
Snapshot outcomes besides success.
const ( NotFound = "not-found" SnapshotFailed = "snapshot-failed" Busy = "busy" )
Rewind outcomes besides success.
Variables ¶
var DefaultLimits = Limits{ MaxFileBytes: 5 * 1024 * 1024, MaxFiles: 20_000, MaxCheckpoints: 30, MinIntervalMs: 3000, MaxDiffBytes: 600_000, GitTimeout: 30 * time.Second, }
Functions ¶
func IsSafeRelPath ¶
IsSafeRelPath: a relative path with no empty, ".", ".." or ".git" part.
func ValidTabID ¶
ValidTabID is the previous runtime's check of a tab id.
Types ¶
type API ¶
type API struct {
Store *Store
// Tab is an agent tab: its tmux session and the agent's state; ok false when there is no such agent tab.
Tab func(tabID string) (session, cliState string, ok bool)
// Cwd is a tmux session's working folder, "" when unknown.
Cwd func(session string) string
}
API is the checkpoints route of the platform's pages, past the API's own checks (a caller with a page session): GET ?tabId lists a conversation's snapshots and rewinds, GET ?tabId&id is the diff from the working folder to one, POST {tabId, id} returns the working folder to it. The folder is the tab's own, never a parameter.
type Checkpoint ¶
Checkpoint is one snapshot: its id ("<ms>-<kind>[-<n>]"), when it was taken, its tree and how many files it holds.
func (Checkpoint) View ¶
func (c Checkpoint) View() *jsvalue.Object
View is a checkpoint as the API shows it.
type Hooks ¶
type Hooks struct {
// IsBusy is asked once the snapshot before the rewind exists and before anything is written: true stops it.
IsBusy func() bool
// BeforeApply runs once the rewind is decided; BeforeReplace right before a file is replaced or deleted.
BeforeApply func()
BeforeReplace func(rel string)
}
Hooks are the moments a rewind asks about or lets a test act in.
type Param ¶
Param is a request value as the previous runtime's handler saw it: absent, or any JSON value (a query parameter is a string, a repeated one an array).
type RewindResult ¶
type RewindResult struct {
Reason string
Before Checkpoint
Changed []string
Skipped []Skipped
}
RewindResult is a rewind done (Reason "") or refused.
func (*RewindResult) JSON ¶
func (r *RewindResult) JSON() *jsvalue.Object
JSON is the answer to a done rewind.
type Scope ¶
Scope is one tab's folder and its shadow repository.
func (*Scope) DiffTo ¶
DiffTo compares the working folder with a snapshot; nil when there is no such snapshot. It writes nothing to the working folder (the shadow index is refreshed).
func (*Scope) List ¶
func (sc *Scope) List() ([]Checkpoint, error)
List is the checkpoints, the newest first.
func (*Scope) Rewind ¶
func (sc *Scope) Rewind(id string, hooks Hooks) (RewindResult, error)
Rewind returns the working folder to a snapshot. The current state is snapshotted first (no rewind without it), only files both states know are written, and a file that changed in the meantime is skipped.
type Skipped ¶
type Skipped struct {
Path, Reason string
// Blob holds the content found in a file that turned out to have changed, kept in the shadow repository.
Blob string
}
Skipped is a file the rewind left alone, and why.
type Store ¶
type Store struct {
// Dir holds the repositories (<data>/checkpoints).
Dir string
Home string
// Namespace names the refs (refs/<ns>/checkpoints/, refs/<ns>/saved/) and the commits' author (<ns>@localhost).
Namespace string
// TmpTag marks the files a rewind stages beside the ones it replaces (<file>.<tag>-<hex>.tmp).
TmpTag string
// Pool shares one object store between the repositories of a working folder (pool.go).
Pool bool
Limits *Limits
// Now is the clock in milliseconds; nil for the real one.
Now func() int64
}
Store is where the shadow repositories live and how they are named.
func (*Store) Scope ¶
Scope is the shadow repository of a tab's folder: the folder resolved, never the root or the home folder.
func (*Store) SnapshotTurnEnd ¶
SnapshotTurnEnd snapshots a tab's folder once its agent's turn ended; a failure is logged and never reaches the agent.
type TextAnswer ¶
type TextAnswer string
TextAnswer is a plain-text answer (the dispatcher's own failure).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package scripttest replays the scripted cases the previous runtime's modules ran (the golden files of the checkpoint store and of the routes over git): the same file and git actions in a temporary folder, and the same dumps of a working folder and a shadow repository, so a Go test compares like with like.
|
Package scripttest replays the scripted cases the previous runtime's modules ran (the golden files of the checkpoint store and of the routes over git): the same file and git actions in a temporary folder, and the same dumps of a working folder and a shadow repository, so a Go test compares like with like. |