drivestore

package
v0.64.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 14 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 drivestore keeps a drive durable: a record per drive under the storage root, and a lease per task. The lease keeps two drives, or a drive and `f10 finish`, from acting on one task at once.

Index

Constants

View Source
const (
	PhasePending   = "pending"   // not opened yet
	PhaseQueued    = "queued"    // held back by the drive's cap
	PhaseRunning   = "running"   // a skill in flight
	PhaseVerifying = "verifying" // the drive's own verify after a catchup
	PhaseRetrying  = "retrying"  // sending its action again after a failed attempt
	PhaseParked    = "parked"    // a skill waits for its base's code, or its branch on origin
	PhaseWaiting   = "waiting"   // finish waits for its base to be through, or the head's checks
	PhaseEnded     = "ended"     // its outcome is in
)

The phases a drive record names a task's standing by.

View Source
const Dir = "drives"

Dir is the drives directory under a storage root.

Variables

This section is empty.

Functions

func Create

func Create(root string, rec *Record) error

Create writes rec as the next numbered record, setting its number. The file is created exclusively, so two drives started at once get two.

func DriveKey

func DriveKey(n int) string

DriveKey is a drive's own lease, held for the life of its process.

func Fingerprint

func Fingerprint(target, conflicts, red string) string

Fingerprint is a catchup's progress state: the target it brings in, the conflicts it meets (path and blobs) and the verify command red after it. The head is left out, since a merge moves it without progress; an attempt with the fingerprint of the one before made none.

func Key

func Key(args []string) string

Key is the drive a command line names: its args as the record keeps them, joined and lowercased, so the same tasks and flags in the same order match whatever their case. A client sends it to the daemon, so its form stays.

func Path

func Path(root string, n int) string

Path is record n's file under the storage root.

Types

type Answer

type Answer struct {
	Task  string    `yaml:"task"`
	Skill string    `yaml:"skill,omitempty"`
	Text  string    `yaml:"text"`
	At    time.Time `yaml:"at"`
}

An Answer is one taken: by which task, at which skill, when.

type Catchup

type Catchup struct {
	Target string `yaml:"target"` // the sha the branch was caught up to
	Head   string `yaml:"head"`   // the branch's tip when the catchup went out
	// Origin is origin's copy of the branch then, what the push after the
	// catchup leases against; "" when origin lacked the branch
	Origin string    `yaml:"origin"`
	Base   string    `yaml:"base"` // the target's name in prose
	At     time.Time `yaml:"at"`
	// Failed is a catchup that did not end clean; the watcher sends another
	// only once the fingerprint moves
	Failed bool `yaml:"failed,omitempty"`
	// Fingerprint is the state a failed watcher catchup stopped at (see
	// Fingerprint): the watcher sends another only once it moves
	Fingerprint string `yaml:"fingerprint,omitempty"`
	// TargetRef is the target's remote-tracking ref, "" for a target recorded
	// nowhere; a push waits until the target is on it
	TargetRef string `yaml:"target_ref,omitempty"`
	// Spent is set once a push or a later skill made Origin stale, so it
	// leases nothing; a record without it still holds its lease
	Spent bool `yaml:"spent,omitempty"`
	// Integrated is set once this catchup rewrote the branch itself, after
	// Origin was read, so the lease stays sound on a resend
	Integrated bool `yaml:"integrated,omitempty"`
}

A Catchup is what a branch looked like when a catchup went out, kept by the drive on its task and by the watcher on its stored report, so both lease the push after it and judge a repeat the same way.

type Guard added in v0.62.0

type Guard struct {
	Entry string `yaml:"entry"`
	At    int    `yaml:"at,omitempty"`
}

A Guard is where ship's catchup guard stopped: the pipeline entry and its place from 1.

type HeldError

type HeldError struct {
	Key    string
	Holder Holder
}

A HeldError is a lease another process holds.

func (HeldError) Error

func (e HeldError) Error() string

type Holder

type Holder struct {
	PID   int
	Drive int  // 0 for `f10 finish` itself
	Watch bool // the daemon's watcher, finishing a task no drive owns
}

A Holder is who holds a lease, as its lock file names it.

func Probe

func Probe(root, key string) (Holder, bool)

Probe reports who holds key's lease, false when nobody does.

func (Holder) String

func (h Holder) String() string

String names the holder for a refusal: `drive 3 (pid 4242)`.

type Lease

type Lease = flock.Lease

A Lease is a held lock, released by Release or by the process ending.

func Acquire

func Acquire(root, key string, drive int) (*Lease, error)

Acquire takes key's lease for drive (0 for finish) under the storage root, without waiting on a holder: a held one is a HeldError naming it.

func AcquireAs

func AcquireAs(root, key string, h Holder) (*Lease, error)

AcquireAs takes key's lease as h, whose PID is always this process.

func Await

func Await(ctx context.Context, root, key string, h Holder, wait time.Duration) (*Lease, error)

Await takes key's lease as h, waiting while another process holds it, until ctx ends or wait passes; then the HeldError names the holder, beside ctx's error when ctx ended.

type Live

type Live struct {
	*Record

	Running bool
}

Live is a drive neither cancelled nor done, and whether its driver runs: holds the drive's lease. A stopped drive still lists its tasks.

func Active

func Active(root string) []Live

Active is every live drive under root, newest first; an unreadable drives dir lists none.

func ActiveOne

func ActiveOne(root string, n int) (Live, bool)

ActiveOne is drive n when it is live, false when it is done, cancelled or has no record.

type Outcome

type Outcome struct {
	Row  string `yaml:"row"`
	Code int    `yaml:"code"`
}

An Outcome is a task's row in the drive's report and its exit code.

type Record

type Record struct {
	Number    int        `yaml:"number"`
	Created   time.Time  `yaml:"created"`
	Args      []string   `yaml:"args"` // the command line, --answer, --every, --parallel and --foreground dropped
	Tasks     []Task     `yaml:"tasks"`
	Flow      string     `yaml:"flow,omitempty"`
	Agent     string     `yaml:"agent,omitempty"` // the run-wide --agent (or --model) as typed
	Cancelled *time.Time `yaml:"cancelled,omitempty"`
	Session   string     `yaml:"session,omitempty"` // the session that created it, "" from a plain terminal
	// Parallel is the cap on tasks running a skill at once, as the drive
	// took it; a rerun or a resume keeps it unless it passes --parallel
	Parallel int `yaml:"parallel,omitempty"`
	// Planned is the planning arguments the drive's command was agreed from
	// (drive plan), so the same planning call follows this drive
	Planned string `yaml:"planned,omitempty"`
	// Answers are given and not yet taken, by task id, "" for the bare one
	Answers  map[string]string `yaml:"answers,omitempty"`
	Answered []Answer          `yaml:"answered,omitempty"`
}

A Record is one drive, kept at <storage root>/drives/<n>.yaml: what it was started with, the answers given, and how each task ended.

func Find

func Find(root string, args []string) (*Record, error)

Find is the newest record started with args that is neither cancelled nor done, nil for none.

func FindPlanned added in v0.61.0

func FindPlanned(root, planned string) (*Record, error)

FindPlanned is the newest live record agreed from the planning arguments, nil for none.

func List

func List(root string) ([]*Record, error)

List is every record, newest first. One that will not parse is skipped.

func Read

func Read(root string, n int) (*Record, error)

Read reads record n.

func Update

func Update(root string, n int, change func(*Record)) (*Record, error)

Update applies change to record n under its own lock and writes it back through a rename, so a cancel and the drive's own writes never lose one another. It returns the record as written.

func (*Record) Done

func (r *Record) Done() bool

Done reports every task through with code 0: a drive with nothing left.

func (*Record) Key

func (r *Record) Key() string

Key is the drive this record is.

func (*Record) Task

func (r *Record) Task(id string) *Task

Task is the record's task with id, nil for none.

type Task

type Task struct {
	ID     string `yaml:"id"`               // as typed, a suffix included
	Agent  string `yaml:"agent,omitempty"`  // its own :profile as typed
	After  string `yaml:"after,omitempty"`  // the base its body's After: line named, as an id
	Skill  string `yaml:"skill,omitempty"`  // in flight, "" for none
	Queued bool   `yaml:"queued,omitempty"` // held back by the drive's cap; Phase says it too, for older readers
	// Phase is where the task stands: one of the Phase names, "" in a record
	// written before it was kept
	Phase   string   `yaml:"phase,omitempty"`
	Outcome *Outcome `yaml:"outcome,omitempty"`
	// Catchup is the catchup the drive last sent for the task, so a resumed
	// drive still leases its push; the repeat count stays in the drive's memory
	Catchup *Catchup `yaml:"catchup,omitempty"`
	// Checks is the head sha a waiting finish holds for, its checks still
	// running; "" while the phase waits on a base
	Checks string `yaml:"checks,omitempty"`
	// Guard is the stop ship's catchup guard left, as the drive read it, so
	// a catchup's turn that rewrites the run still resumes ship there
	Guard *Guard `yaml:"guard,omitempty"`
}

A Task is one task of a drive, as typed, and where it stands.

Jump to

Keyboard shortcuts

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