state

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 10 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 persists the Assist/Delivery operating mode (PRD §7) in .orchestrator/state.json, machine-local and gitignored. A missing file means Assist; a file that cannot be read, parsed, or recognized is an error so callers fail closed (PRD §15).

Index

Constants

View Source
const Path = ".orchestrator/state.json"

Path is the repo-relative location of the state file.

View Source
const SchemaVersion = 3

SchemaVersion is the state-file schema this build reads and writes. v3 adds the PR B per-issue lifecycle fields (Issue.Decision, DependsOn, Wave, LastReviewVerdict) and Run.StoppedReason. There is no migration from earlier versions: Load fails closed on a version mismatch with the `orch abort` remediation, and no real run persists across builds, so an out-of-version file on disk is a test artifact.

Variables

This section is empty.

Functions

func CheckConsistent

func CheckConsistent(st *State, owner *lockfile.Owner) error

CheckConsistent verifies the invariant that delivery mode and the Delivery lock exist together and describe the same run. st and owner come from Load and lockfile.Inspect.

func CompleteDelivery

func CompleteDelivery(repoRoot string) error

CompleteDelivery returns a finished Delivery run to Assist and releases the lock (PRD §7 auto-return). Unlike Abort it is not a repair path: it requires a consistent delivery state owned by a matching lock and fails closed otherwise, so a caller cannot complete over a broken or already-assist state. Ordering matches EnterDelivery/Abort — state first, lock second — so a crash between the two leaves an orphaned lock that denies new runs (fail closed) until `orch abort` clears it.

func Save

func Save(repoRoot string, st *State) error

Save persists st under repoRoot: it stamps UpdatedAt, validates (the same check Load applies on read), then writes atomically. It is the incremental-persistence primitive the run engine calls after every Delivery sub-step (PRD §23), so a crash leaves the state file matching the last completed step.

Types

type AbortResult

type AbortResult struct {
	// PriorRun is the delivery run the state file recorded, if any.
	PriorRun *Run
	// LockOwner is the readable owner of a released lock, if any.
	LockOwner *lockfile.Owner
	// LockCleared reports that a lock file (readable or not) was removed.
	LockCleared bool
	// StateReset reports that an unreadable or inconsistent state file
	// was overwritten with assist.
	StateReset bool
}

AbortResult describes what Abort found and did.

func Abort

func Abort(repoRoot string) (*AbortResult, error)

Abort returns the repository to Assist and releases the Delivery lock (PRD §15). It is the explicit human recovery path, so it also clears corrupt state files and orphaned or unreadable locks, and it is idempotent. It never touches branches or worktrees. Ordering matters for crash safety: state first, lock second — see EnterDelivery.

type Attempt

type Attempt struct {
	Role      manifest.Role      `json:"role"`
	Selection manifest.Selection `json:"selection"`
	Failed    bool               `json:"failed"`
	Reason    string             `json:"reason,omitempty"`
}

Attempt mirrors routing.Attempt in persistable form, so an issue's escalation history (routing.History) survives an orch restart (PR B; this package imports manifest, not routing, to stay off the routing policy dependency edge).

type Decision

type Decision struct {
	Role               manifest.Role      `json:"role"`
	Executor           manifest.Selection `json:"executor"`
	Reviewer           manifest.Selection `json:"reviewer"`
	ReviewerDowngraded bool               `json:"reviewer_downgraded"`
	Rationale          string             `json:"rationale"`
}

Decision mirrors routing.Decision in persistable form: the current routing chosen for an issue, set at activation and updated by escalate. Like Attempt it keeps this package off the routing policy dependency edge — state imports manifest, never routing, and the run engine converts between the two.

type Issue

type Issue struct {
	PlanID string `json:"plan_id"`
	Title  string `json:"title"`
	Phase  Phase  `json:"phase"`
	Number int    `json:"number,omitempty"`
	URL    string `json:"url,omitempty"`
	// Branch is the feature branch name. Worktree is the worktree
	// directory as a repo-relative slash path.
	Branch   string `json:"branch,omitempty"`
	Worktree string `json:"worktree,omitempty"`

	// DependsOn (plan ids) and Wave are copied from the plan at
	// EnterDelivery so dispatch can enforce dependencies — every
	// DependsOn issue merged or cleaned — without re-taking the plan.
	DependsOn []string `json:"depends_on,omitempty"`
	Wave      int      `json:"wave,omitempty"`

	// Decision is the current routing for the issue, set at activation
	// and updated by escalate. Required from the dispatched phase onward.
	Decision *Decision `json:"decision,omitempty"`

	// PR B lifecycle fields.
	PRNumber        int    `json:"pr_number,omitempty"`
	PRURL           string `json:"pr_url,omitempty"`
	ApprovedHeadOID string `json:"approved_head_oid,omitempty"`
	ReviewCycles    int    `json:"review_cycles,omitempty"`
	// LastReviewVerdict is "", "approve", or "request-changes": the gate
	// merge-report checks without parsing bodies.
	LastReviewVerdict string    `json:"last_review_verdict,omitempty"`
	BlockedReason     string    `json:"blocked_reason,omitempty"`
	Attempts          []Attempt `json:"attempts,omitempty"`
}

Issue is one plan issue's persisted Delivery state.

type Mode

type Mode string

Mode is the operating mode (PRD §7).

const (
	ModeAssist   Mode = "assist"
	ModeDelivery Mode = "delivery"
)

type Phase

type Phase string

Phase is one issue's position in the Delivery lifecycle (PRD §12). The set is closed. Activation (PR A) writes Planned, IssueCreated, and WorktreeReady; the per-issue lifecycle verbs (PR B) drive the rest. PhaseCleaned is terminal.

const (
	// PhasePlanned is an issue's state immediately after EnterDelivery,
	// before its GitHub issue exists.
	PhasePlanned Phase = "planned"
	// PhaseIssueCreated marks a created GitHub issue, before its
	// branch/worktree exist.
	PhaseIssueCreated Phase = "issue-created"
	// PhaseWorktreeReady marks a created branch and worktree, ready for
	// dispatch.
	PhaseWorktreeReady Phase = "worktree-ready"

	// PhaseDispatched marks an issue handed to an executor (branch
	// fast-forwarded, status in-progress).
	PhaseDispatched Phase = "dispatched"
	// PhasePROpen marks an opened pull request awaiting review.
	PhasePROpen Phase = "pr-open"
	// PhaseInReview marks an issue in a review cycle.
	PhaseInReview Phase = "in-review"
	// PhaseAwaitingMerge marks an approved PR pinned to its head OID,
	// waiting at the human merge gate.
	PhaseAwaitingMerge Phase = "awaiting-merge"
	// PhaseMerged marks a merged PR with its issue closed.
	PhaseMerged Phase = "merged"
	// PhaseCleaned is terminal: remote branch, worktree, and local
	// branch removed.
	PhaseCleaned Phase = "cleaned"
	// PhaseAbandoned marks an issue closed without merging; its branch
	// and worktree are preserved until cleanup.
	PhaseAbandoned Phase = "abandoned"
	// PhaseBlocked marks an issue awaiting human action; recovery is
	// `orch resume` or `orch abort`.
	PhaseBlocked Phase = "blocked"
)

func (Phase) Valid

func (p Phase) Valid() bool

Valid reports whether p is a member of the closed Phase set.

type PlanRef

type PlanRef struct {
	Title          string    `json:"title"`
	Digest         string    `json:"digest"`
	ApprovedBy     string    `json:"approved_by"`
	ApprovedAt     time.Time `json:"approved_at"`
	ConfigRevision string    `json:"config_revision"`
}

PlanRef records the approved plan an active Delivery run was entered from (PRD §8). The engine cannot verify a human; this is the adapter's assertion, kept for the audit trail.

type Run

type Run struct {
	ID        string    `json:"id"`
	Host      string    `json:"host"` // "claude" or "codex"
	StartedAt time.Time `json:"started_at"`
	Plan      PlanRef   `json:"plan"`
	Issues    []Issue   `json:"issues"`
	// StoppedReason is non-empty when a secret block stopped the whole
	// run (PRD §16): every mutating verb but block itself then fails
	// closed until `orch abort` or `orch resume` (with its explicit
	// resume-stopped-run statement).
	StoppedReason string `json:"stopped_reason,omitempty"`
}

Run describes the active Delivery run.

type State

type State struct {
	SchemaVersion int       `json:"schema_version"`
	Mode          Mode      `json:"mode"`
	Run           *Run      `json:"run,omitempty"` // non-nil iff Mode is delivery
	UpdatedAt     time.Time `json:"updated_at"`
}

State is the persisted operating state.

func EnterDelivery

func EnterDelivery(repoRoot, host string, plan PlanRef, issues []Issue) (*State, error)

EnterDelivery acquires the cross-host Delivery lock and records a new delivery run over plan and issues. Ordering matters for crash safety: lock first, state second — a crash between the two leaves an orphaned lock, which denies every new run (fail closed) until `orch abort` clears it. The reverse order could leave delivery state without a lock, letting a second host acquire.

issues must all be at PhasePlanned and in the order the run engine wants them processed (wave order); plan.Digest must be non-empty (EnterDelivery does not recompute it — the caller has already validated the plan and its approval).

func Load

func Load(repoRoot string) (*State, error)

Load reads the state under repoRoot. A missing file is Assist, not an error. Anything unreadable or inconsistent is an error naming the file so the caller can deny and the human can act.

Jump to

Keyboard shortcuts

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