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 ¶
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 ¶
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.
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 ¶
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 ¶
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 ¶
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) ReadyNodes ¶
ReadyNodes returns nodes whose deps are all done, state waiting, plan not paused/cancelled. Parked and synthetic-parked nodes never appear.
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.