receipt

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 16 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 receipt is the preview gate's record (iss-2611281623098395): a verb that moves, rewrites or deletes a record or a transcript runs for real only after a dry run of the same call, over the same state, within Bound.

The dry run writes a receipt keyed on the call (the command and its arguments) and holding a digest of the state it read: the checkout's HEAD, when the verb acts on one, and the bytes of every path its plan touches. The real run plans again first, so a refusal the plan meets is the same refusal either way, then consumes the receipt for its call: one that is missing, older than Bound, or whose state no longer matches the state the real run reads refuses the run before anything is written. The receipt is removed when it is consumed, so one dry run admits one real run.

The receipts live in the checkout's local tier (LocalRelDir), or in abcd's home (HomeLeaf) for a verb that acts on no checkout, such as `history discard --root-sha` or `--pending`. The bound is the decision recorded with the gate: long enough to read a plan and run it, short enough that a plan is not acted on after the session that read it has moved on.

The package is transport-free: it writes no output, and its refusal is an error the front door renders.

Index

Constants

View Source
const Bound = 30 * time.Minute

Bound is how long a dry run's receipt admits the real run.

View Source
const BoundText = "30 minutes"

BoundText is Bound as a refusal and the docs say it.

View Source
const HomeLeaf = "dry-runs"

HomeLeaf is the home store, below abcd's home.

View Source
const LocalRelDir = localtier.RelDir + "/dry-runs"

LocalRelDir is the checkout store, below the repository root.

Variables

This section is empty.

Functions

func Consume

func Consume(s Store, c Call, st State) error

Consume admits the real run of c over st: it finds the receipt the dry run of c wrote, refuses one older than Bound or written over another state, and removes it. A refusal is a *Refusal carrying refusal.DryRunRequired. Two real runs racing for one receipt are settled by the removal: the one whose removal finds the receipt gone is refused as if it had none.

Types

type Call

type Call struct {
	Command string   `json:"command"`
	Args    []string `json:"args"`
}

Call is one invocation as the gate keys it: the command path below the root, then the positional arguments, then every flag the caller set as --name=value in name order, the output and dry-run flags left out.

type PathState

type PathState struct {
	Path   string `json:"path"`
	Digest string `json:"digest"`
}

PathState is one touched path and the digest of what stood there.

type Reason

type Reason string

Reason is why a real run found no receipt to stand on.

const (
	// Missing is no dry run of this call on record.
	Missing Reason = "missing"
	// Stale is a dry run of this call older than Bound.
	Stale Reason = "stale"
	// Mismatch is a dry run of this call over a state that has changed since.
	Mismatch Reason = "mismatch"
	// Future is a dry run of this call dated more than a minute ahead of the
	// clock, whose age the gate cannot judge.
	Future Reason = "future"
)

type Receipt

type Receipt struct {
	SchemaVersion int         `json:"schema_version"`
	Command       string      `json:"command"`
	Call          string      `json:"call"`
	State         string      `json:"state"`
	Head          string      `json:"head,omitempty"`
	Paths         []PathState `json:"paths"`
	At            time.Time   `json:"at"`
}

Receipt is one dry run's record.

func Record

func Record(s Store, c Call, st State) (Receipt, error)

Record writes the receipt a dry run of c over st leaves, replacing an earlier one for the same call, and returns it.

type Refusal

type Refusal struct {
	Reason  Reason
	Age     time.Duration
	Changed []string
}

Refusal is a real run the gate refused. Changed names what moved under a mismatched receipt: "HEAD", or each touched path whose bytes differ or that one of the two runs touches and the other does not.

func (*Refusal) Error

func (r *Refusal) Error() string

type State

type State struct {
	Head  string      `json:"head,omitempty"`
	Paths []PathState `json:"paths"`
}

State is what a run read: the checkout's HEAD (empty for a verb that acts on no checkout, or a branch with no commit) and each touched path.

func Items

func Items(head string, items map[string]string) State

Items is the state of a plan that acts on things other than files — the worktrees a prune removes, the branches a sweep deletes on origin: head, and each item by the name a refusal shows, with the digest of what the run judged of it, in name order. A thing the dry run would act on and the real run would not, or the reverse, differs as a path does.

func Observe

func Observe(head string, targets []Target) State

Observe reads the state a plan acts on: head, and the digest of each target, in the order of their Show names, each named once.

type Store

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

Store is where receipts are kept: a checkout's local tier, or abcd's home.

func Checkout

func Checkout(repoRoot string) Store

Checkout is the store in repoRoot's local tier.

func Home

func Home() (Store, error)

Home is the store in abcd's home, for a verb that acts on no checkout.

func (Store) Display

func (s Store) Display() string

Display names the store as a message shows it, with no absolute path.

type Target

type Target struct {
	Show string
	Abs  string
}

Target is one path a plan touches: Show is how the plan names it (repo-relative, or ~/-relative), Abs where it is read.

func Targets

func Targets(base, home string, paths []string) []Target

Targets names where each planned path is read: a ~/ path under home, an absolute one as it stands, any other under base, the root the plan's paths are relative to.

Jump to

Keyboard shortcuts

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