plans

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 12 Imported by: ? 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 plans is the dispatch-time envelope around a craftbrain.Plan: the accept transform (park cycles/blocked nodes, pin crafts to a roster, route feeder recipients, insert synthetic cross-station transfers) and the flock-guarded on-disk PlanRun state that Executor B advances tick by tick.

Index

Constants

View Source
const MaxNodeRetries = 2

MaxNodeRetries is how many times a node's task may fail before it parks (needs an operator retry via Control.RetryNodes).

Variables

This section is empty.

Functions

func SaveRun

func SaveRun(dir string, pr *PlanRun) error

SaveRun atomically writes pr to <dir>/<plan-id>.state.json, guarded by an exclusive flock on a sidecar .lock file (mirrors pkg/rescue/queue.go's withLock mechanics: the lock file is never renamed, so the lock identity stays stable across writers).

Types

type Control

type Control struct {
	Pause      bool     `json:"pause,omitempty"`
	Cancel     bool     `json:"cancel,omitempty"`
	RaiseCap   int      `json:"raise_cap,omitempty"`   // new absolute cap; 0 = unchanged
	RetryNodes []string `json:"retry_nodes,omitempty"` // node ids to reset from parked(failed)
}

Control carries operator-issued mutations for the next tick to apply.

type Manifest

type Manifest struct {
	PlanID       string   `json:"plan_id"`
	BudgetCap    int      `json:"budget_cap"`
	MineItems    []string `json:"mine_items,omitempty"` // leaves tagged mine at dispatch
	Assembly     string   `json:"assembly"`             // any_docked_station resolved to this base
	DispatchedAt string   `json:"dispatched_at"`
}

Manifest is the dispatch-time envelope around a craftbrain plan.

type NodeRun

type NodeRun struct {
	Node        craftbrain.Node `json:"node"`
	State       NodeState       `json:"state"`
	Park        ParkReason      `json:"park,omitempty"`
	ParkDetail  string          `json:"park_detail,omitempty"`
	Agent       string          `json:"agent,omitempty"`     // pin (crafts + synthetic xfers) or assignee
	Recipient   string          `json:"recipient,omitempty"` // consumer's pinned agent for feeder nodes
	DoneQty     int             `json:"done_qty"`
	Retries     int             `json:"retries"`
	Synthetic   bool            `json:"synthetic,omitempty"`
	SpentActual int             `json:"spent_actual"` // fees/buys actually paid
}

NodeRun is one plan node's executor-side lifecycle wrapper.

type NodeState

type NodeState string

NodeState is a NodeRun's position in the executor's per-node lifecycle.

const (
	NodeWaiting    NodeState = "waiting"    // deps not yet done
	NodeDispatched NodeState = "dispatched" // task in the store (assigned or running)
	NodeDone       NodeState = "done"
	NodeParked     NodeState = "parked"
)

type ParkReason

type ParkReason string

ParkReason explains why a NodeRun is parked instead of progressing.

const (
	ParkCycle         ParkReason = "cycle"
	ParkBlocked       ParkReason = "blocked"
	ParkNeedsOperator ParkReason = "needs_operator"
	ParkOverBudget    ParkReason = "over_budget"
	ParkFailed        ParkReason = "failed"
	ParkReplan        ParkReason = "replan"
)

type PlanRun

type PlanRun struct {
	Manifest    Manifest   `json:"manifest"`
	Nodes       []*NodeRun `json:"nodes"` // plan order + synthetic xfers appended
	Spent       int        `json:"spent"`
	Status      string     `json:"status"` // running | paused | done | partial | cancelled
	Control     Control    `json:"control"`
	Diagnostics []string   `json:"diagnostics,omitempty"`
}

PlanRun is the full on-disk executor state for one dispatched plan.

func LoadAllRuns

func LoadAllRuns(dir string) ([]*PlanRun, []error)

LoadAllRuns globs <dir>/*.state.json and loads each. Corrupt files are never silently skipped: they are collected as errors alongside the runs that did parse, so the caller can log them without losing the good runs.

func LoadRun

func LoadRun(path string) (*PlanRun, error)

LoadRun reads and parses one plan-run state file, under the same flock discipline as SaveRun.

func NewRun

func NewRun(qf QueueFile, roster []RosterAgent) *PlanRun

NewRun applies the accept transform: park cycle/blocked nodes, pin craft nodes round-robin over roster, set Recipient on feeder nodes, insert synthetic xfer nodes for cross-station craft->craft edges.

func (*PlanRun) ItemProgress

func (pr *PlanRun) ItemProgress() map[string]Progress

ItemProgress sums done vs total qty per item over mine/buy/haul/craft nodes. Synthetic nodes are included (they are real work); KindBlocked nodes are skipped.

func (*PlanRun) NodeByID

func (pr *PlanRun) NodeByID(id string) *NodeRun

NodeByID returns the NodeRun with the given node id, or nil if absent.

func (*PlanRun) ReadyNodes

func (pr *PlanRun) ReadyNodes() []*NodeRun

ReadyNodes returns nodes whose deps are all done, state waiting, plan not paused/cancelled. Parked and synthetic-parked nodes never appear.

func (*PlanRun) Recompute

func (pr *PlanRun) Recompute()

Recompute derives PlanRun.Status: "cancelled" if Control.Cancel; "paused" if Control.Pause; "done" when every node is done; "partial" when nothing is waiting/dispatched but parked nodes remain; otherwise "running".

type Progress

type Progress struct{ Done, Total int }

Progress is a done-vs-total quantity rollup for one item across all mine/buy/haul/craft nodes that produce it.

type QueueFile

type QueueFile struct {
	Manifest Manifest        `json:"manifest"`
	Plan     craftbrain.Plan `json:"plan"`
}

QueueFile is the JSON dropped into the craft-queue dir by play_as dispatch.

type RosterAgent

type RosterAgent struct {
	AgentID string `yaml:"agent_id" json:"agent_id"`
	Station string `yaml:"station" json:"station"`
}

RosterAgent is one craft-capable agent available to pin plan nodes to.

type Runner

type Runner struct {
	QueueDir string
	StateDir string
	Store    *tasks.Store
	Handoff  *handoff.Queue
	Roster   []RosterAgent     // craft fleet (pin targets)
	Managed  map[string]string // holder agent_id -> its home station (marketbot roster)
	Logger   *log.Logger
	// contains filtered or unexported fields
}

Runner drives all plan runs one Tick at a time. Construct once in cmd/overmind. Tick is single-threaded — it is called from the overmind main select loop and never spawns goroutines of its own.

func (*Runner) Tick

func (r *Runner) Tick()

Tick advances every loaded plan run by one step: intake queue files, sync node states from the task store, retry/park failed nodes, gate and dispatch ready nodes (handoff-first, then budget), apply operator Control, and persist. Runs are processed in plan-id order for determinism.

Jump to

Keyboard shortcuts

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