state

package
v0.66.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 19 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 state owns the run state: one `key value` file per session, keyed by session rather than by repo because two sessions over one checkout are two runs. The status line's renderer, `bin/f10-state.sh render`, reads the same format in bash on every refresh; the render parity test pins the two.

Index

Constants

View Source
const (
	LaunchStart = "start"
	LaunchDrive = "drive"
)

Launch kinds: a task `f10 start` opened, or a drive by its number.

View Source
const DefaultTTL = 24 * time.Hour

DefaultTTL is how long a run counts as live with nothing reporting.

View Source
const PipelineSep = " → "

PipelineSep joins a recorded pipeline's steps, as `pipelines:` strings spell them: a step name may hold spaces (`review (local)`).

View Source
const StopGuard = "guard"

StopGuard is the stop ship's catchup guard leaves: a conflict it marked the branch for, which a drive catches up before sending ship again.

View Source
const TurnCatchup = "catchup"

TurnCatchup is a catchup's turn: it integrates the branch and writes only its done signal, so a ship it runs between keeps the state it left.

View Source
const Upcoming = "upcoming"

Upcoming is a phase or step in the run's flow that the run has not reached: nothing running or waiting on it.

Variables

View Source
var ErrBusy = errors.New("state: the session is being written")

ErrBusy is a session lock another writer held for the whole wait.

View Source
var ErrPhaselessTurn = errors.New("a catchup turn writes no phase: `f10-state.sh done catchup` ends it")

ErrPhaselessTurn refuses a phase write inside a catchup's turn, where it would overwrite the ship state a drive reads.

View Source
var Phases = []string{"capture", "plan", "ship"}

Phases in the order the badge draws them.

View Source
var Statuses = []string{Upcoming, "running", "done", "failed", "partial", "skipped", "prior", "blocked"}

Statuses a phase can hold, in the order the usage text lists them.

Functions

func AppendLaunch added in v0.46.0

func AppendLaunch(dir, session string, l Launch) error

AppendLaunch adds one launch to session's list. One short line in one append write, so two parallel starts in a session never tear a line.

func AsksPath added in v0.58.0

func AsksPath(dir, session string) string

AsksPath marks the asks a session was told, so each is told once.

func BackgroundPath added in v0.58.0

func BackgroundPath(dir, session string) string

BackgroundPath marks background work a session's turn launched (a Bash command with run_in_background, or a Monitor). It is a file of its own, not a run field, because writing the run moves Updated, which a drive reads as a turn beginning.

func Clear added in v0.36.0

func Clear(dir, session string)

Clear drops a session's state file under the session's lock, so a writer mid-update cannot save the cleared run back. Absent is fine; a lock held past the wait still clears.

func Dir

func Dir() string

Dir is where state files live: F10_STATE_DIR, else the default.

func FileRoot added in v0.46.0

func FileRoot(dir, name string) string

FileRoot is the checkout a per-session file is about, an open wait taking its session's; "" for any other file, or a session with neither.

func Glyph added in v0.36.0

func Glyph(status string) string

Glyph is the status line's default shape for a status; the renderer's F10_STATE_GLYPHS override applies to the status line only.

func LaunchesPath added in v0.46.0

func LaunchesPath(dir, session string) string

LaunchesPath lists what a session launched, so a bare status in the main checkout can show it.

func LegacyStatus added in v0.58.0

func LegacyStatus(status string) string

LegacyStatus reads the name a not-reached phase had before it was Upcoming, still held by older run files, ledger claims and older callers.

func MarkBackground added in v0.58.0

func MarkBackground(dir, session string, b Background) error

MarkBackground writes the session's background mark over any before it.

func MarkPrompt added in v0.46.0

func MarkPrompt(dir, session, root string, at time.Time) error

MarkPrompt writes session's mark. It never touches the run file, so a session f10 does not run leaves no run behind.

func ModelPath added in v0.53.0

func ModelPath(dir, session string) string

ModelPath holds the model the session started on, from its SessionStart payload; lore reads it to name the agent behind an entry.

func OpensPhase added in v0.58.0

func OpensPhase(skill string) bool

OpensPhase reports whether the skill runs a phase (debug captures), so its run may be a task's before fetch names one.

func Path

func Path(dir, session string) string

Path sanitizes the session id as the renderer does, since it names a file.

func PromptedPath added in v0.46.0

func PromptedPath(dir, session string) string

PromptedPath is the mark a session's last prompt leaves: which checkout and when, so a drive can tell a turn that ran between two looks from one never taken.

func Prune added in v0.36.0

func Prune(dir string, now time.Time)

Prune drops the per-session files of long-dead sessions; .conventions is the marker f10-inject.sh writes.

func RootOf added in v0.46.0

func RootOf(ctx context.Context, cwd string) string

RootOf is the checkout root a cwd is in; outside git, the cwd itself.

func SaveUsage added in v0.61.0

func SaveUsage(dir, session string, u Usage) error

SaveUsage records the session's usage position.

func Session

func Session() string

Session is the override, else the id Claude Code exports into every Bash tool call; empty from a plain terminal. A hook names its session in the payload instead.

func SessionModel added in v0.53.0

func SessionModel(dir, session string) string

SessionModel is the model ModelPath recorded, "" when none was.

func SplitPipeline added in v0.42.0

func SplitPipeline(s string) []string

SplitPipeline reads a recorded pipeline back into its steps.

func StartedPath added in v0.36.0

func StartedPath(dir, session string) string

StartedPath marks when the session loaded the plugin, for doctor to compare with the install's update time.

func Stopped

func Stopped(status string) bool

Stopped reports whether the phase status is one a run halts on.

func TTL

func TTL() time.Duration

TTL is how long a run counts as live, from F10_STATE_TTL.

func Update added in v0.58.0

func Update(
	ctx context.Context,
	dir, session string,
	wait time.Duration,
	now time.Time,
	change func(r *Run, loaded bool) (bool, error),
) error

Update loads the session's run, applies change and saves it, all under the session's lock, so the hooks and f10 state, separate processes, never save a stale copy over each other. change reports whether to save; loaded says a file was read. A lock not taken within wait is ErrBusy.

func UsagePath added in v0.61.0

func UsagePath(dir, session string) string

UsagePath holds how far the hook has read the session's transcript for its usage.

func WaitPath added in v0.45.0

func WaitPath(dir, session string) string

WaitPath is the wait a session has open: what on and since when.

Types

type Background added in v0.58.0

type Background struct {
	At     time.Time `json:"at"`
	Parked bool      `json:"parked,omitempty"`
}

Background is the marker BackgroundPath holds. Parked is set once the launching turn ended with the work pending.

func PendingBackground added in v0.58.0

func PendingBackground(dir, session string) (Background, bool)

PendingBackground is the session's background mark, false for none.

type Launch added in v0.46.0

type Launch struct {
	Kind  string
	Value string // the task as typed for start, the drive's number for drive
}

A Launch is one thing a session set going: a start's task, or a drive.

func Launches added in v0.46.0

func Launches(dir, session string) ([]Launch, error)

Launches reads session's list in launch order, a malformed line or a repeat (a rerun start, a resumed drive) skipped. A missing file is none.

type Prompt added in v0.46.0

type Prompt struct {
	Session string
	Root    string
	At      time.Time
}

A Prompt is one session's mark: the checkout root and the prompt's time.

func LastPrompt added in v0.46.0

func LastPrompt(dir, root string) (Prompt, bool)

LastPrompt is the newest mark any session left in root, false for none.

type Run

type Run struct {
	Session string `json:"session"`
	Task    string `json:"task,omitempty"`
	URL     string `json:"url,omitempty"`
	Root    string `json:"root,omitempty"`  // checkout root the run is about
	Skill   string `json:"skill,omitempty"` // the skill that began the run
	Capture string `json:"capture"`
	Plan    string `json:"plan"`
	Ship    string `json:"ship"`
	Leaf    string `json:"leaf,omitempty"` // the pipeline step running, or stopped on
	// Leaf's place in Pipeline, counted from 1, so a step the pipeline
	// names twice (`judge`, `pr`) is told apart; 0 is unknown
	At    int    `json:"at,omitempty"`
	Final string `json:"final,omitempty"` // the ship pipeline's declared last step
	// the ship pipeline's steps as declared, in order, labels cut
	Pipeline []string `json:"pipeline,omitempty"`
	// Labels is each Pipeline entry's display name by index ("" for none);
	// nil when no entry has one. Nothing matches on it, only shows it
	Labels []string `json:"labels,omitempty"`
	Note   string   `json:"note,omitempty"` // why the run stopped
	Next   string   `json:"next,omitempty"` // what unblocks it
	Ask    string   `json:"ask,omitempty"`  // the question a driven run stopped on, options included
	// Wait is the base task a driven ship stopped for, its branch without
	// code yet: a drive parks the task and sends ship again once it has some
	Wait string `json:"wait,omitempty"`
	// Stop is the kind of stop a ship left, StopGuard for its catchup guard,
	// so a drive need not guess it from the stop's shape
	Stop string `json:"stop,omitempty"`
	// Done is the phaseless step (catchup) whose report is out, DoneAt when;
	// a reader compares DoneAt, since any later write moves Updated alone
	Done   string    `json:"done,omitempty"`
	DoneAt time.Time `json:"done_at,omitzero"`
	// Turn is a phaseless skill whose turn is in progress (catchup), which
	// may write no phase: the ship it runs between is not its own
	Turn    string    `json:"turn,omitempty"`
	Updated time.Time `json:"updated"`
}

A Run is one session's state file, read back; each phase holds a Statuses.

func Fresh added in v0.36.0

func Fresh(session string) *Run

Fresh is the run a session has before anything reported: every phase upcoming.

func List

func List(dir string, now time.Time, ttl time.Duration) ([]*Run, error)

List reads every live run in dir, newest first. A missing directory is an empty list: no run has ever reported on this machine.

func Load

func Load(path string) (*Run, error)

Load reads one state file. A missing file is os.ErrNotExist, unwrapped enough for errors.Is.

func LoadOrFresh added in v0.36.0

func LoadOrFresh(dir, session string) (*Run, bool)

LoadOrFresh reads the session's file, or starts a fresh run when there is none. The bool says whether a file was read.

func (*Run) Backstop added in v0.36.0

func (r *Run) Backstop() bool

Backstop is the Stop hook's promotion of a running phase, for the most dropped call: the final `set ship done`. Ship spans many turns, so it promotes only on the declared final step, or with no final or leaf known, overstating being the cheaper error. True when anything changed.

func (*Run) BeginTurn added in v0.62.0

func (r *Run) BeginTurn(skill string) bool

BeginTurn records skill's turn when it is phaseless; true when it was.

func (*Run) EndTurn added in v0.62.0

func (r *Run) EndTurn() bool

EndTurn retires a phaseless turn as it ends; true when one was in progress.

func (*Run) Entries added in v0.58.0

func (r *Run) Entries() flow.Flow

Entries is the pipeline with each entry's label: the state file keeps the two on separate lines.

func (*Run) FinalShown added in v0.56.0

func (r *Run) FinalShown() string

FinalShown is the final step as a person reads it: the last entry's label, else the step itself.

func (*Run) Furthest added in v0.58.0

func (r *Run) Furthest() string

Furthest is the last phase the run has left: its status is neither upcoming nor unset. A run that left none is at its first phase.

func (*Run) LabelAt added in v0.56.0

func (r *Run) LabelAt(at int) string

LabelAt is the label of the pipeline's at-th entry, counted from 1.

func (*Run) LeafShown added in v0.56.0

func (r *Run) LeafShown() string

LeafShown is the leaf as a person reads it: its entry's label, else the step itself. A leaf the pipeline does not hold (catchup) keeps the place of the entry it guards, so it never borrows that entry's label.

func (*Run) Live

func (r *Run) Live(now time.Time, ttl time.Duration) bool

Live reports whether the run was updated within ttl of now.

func (*Run) PhaseText

func (r *Run) PhaseText(phase string) string

PhaseText is the status with its step where one belongs to it: `running: implement`, `blocked at judge`. The leaf is a pipeline step, so only ship carries one, except plan's judge, which fetch runs before planning.

func (*Run) PlanWritten added in v0.36.0

func (r *Run) PlanWritten(task string)

PlanWritten is the plan step's output landing: plan done, unreported, and the file's name is the task id.

func (*Run) Save added in v0.36.0

func (r *Run) Save(ctx context.Context, dir string, now time.Time) error

Save writes the run as the status line's bash renderer reads it, through a temp file so the polling renderer never sees a torn file; values are flattened to one line, since a newline would start a new key.

func (*Run) Seed added in v0.36.0

func (r *Run) Seed(ctx context.Context, skill, args, cwd string) bool

Seed begins a run for a skill invocation. A chain over the task already held (plan, then ship) carries settled phases forward, or ship would show this session's plan as `skipped`; --help runs nothing and reports false, so the badge keeps the last real run.

func (*Run) Set added in v0.36.0

func (r *Run) Set(phase, status, leaf string) error

Set records a phase's status. A stop keeps the leaf, the argument else the last running one, since "blocked at judge" is the answer to "ship blocked"; running again retires the note, question and done signal, which a stop keeps for the driven catchup that wrote it before restoring.

func (*Run) SetAsk added in v0.36.0

func (r *Run) SetAsk(text string) error

SetAsk records the questionnaire a driven run stopped on, options included: no one is in its pane to answer.

func (*Run) SetDone added in v0.47.0

func (r *Run) SetDone(step string, now time.Time) error

SetDone records that a phaseless step (catchup) reported at now: the drive reads it as the step's end, and an idle agent without it stopped without reporting. It touches no phase, so the badge a ship run left stands.

func (*Run) SetFinal added in v0.36.0

func (r *Run) SetFinal(step string) error

SetFinal declares the ship pipeline's last step, for the Stop backstop: a turn ending on it is a dropped `set ship done`; mid-pipeline is a pause.

func (*Run) SetNote added in v0.36.0

func (r *Run) SetNote(reason, next string) error

SetNote records why a run stopped and what unblocks it.

func (*Run) SetPipeline added in v0.42.0

func (r *Run) SetPipeline(steps []string) error

SetPipeline declares the ship pipeline's steps, in order; its last is the final step.

func (*Run) SetStop added in v0.58.0

func (r *Run) SetStop(kind string) error

SetStop records the kind of stop a ship left; only StopGuard exists.

func (*Run) SetTask added in v0.36.0

func (r *Run) SetTask(id, url string) error

SetTask records the task the run is about. A tracker task id means the task predates this run, so an unreported capture becomes `prior`; `done` and `running` stay, since capture reports those itself.

func (*Run) SetWait added in v0.49.0

func (r *Run) SetWait(task string) error

SetWait records the base task a driven ship stopped for, its branch without code yet. Not an ask: no one is asked, and a drive waits on it.

func (*Run) Status

func (r *Run) Status(phase string) string

Status is the phase's status as recorded.

func (*Run) StoppedPhase added in v0.58.0

func (r *Run) StoppedPhase() (string, bool)

StoppedPhase is the last phase whose status is one a run halts on, and false when none is.

type Usage added in v0.61.0

type Usage struct {
	transcript.Position

	Ended bool `json:"ended,omitempty"`
}

Usage is how far the hook has counted a session's transcript, and whether the run it counted for is done: turns after it count for no task.

func LoadUsage added in v0.61.0

func LoadUsage(dir, session string) (Usage, bool)

LoadUsage is the usage UsagePath holds, false when none is recorded or it does not decode.

type UsageError added in v0.36.0

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

A UsageError is a typo in step prose (an unknown phase or status, a missing argument), so the command exits 2 rather than leave the badge frozen.

func (*UsageError) Error added in v0.36.0

func (e *UsageError) Error() string

type Wait added in v0.58.0

type Wait struct {
	Reason string `json:"reason"`
	Tool   string `json:"tool,omitempty"`
	UseID  string `json:"tool_use_id,omitempty"`
}

Wait is the marker WaitPath holds: the reason, and for a dialog, the tool and the tool call it is about.

func OpenWait added in v0.58.0

func OpenWait(dir, session string) (Wait, bool)

OpenWait is the wait the session has open, false for none.

Jump to

Keyboard shortcuts

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