Documentation
¶
Overview ¶
Package goal implements an autonomous maker→verifier loop ("goal mode").
A Goal holds the loop's runtime state (objective, backstop budgets, counters). The bus wires a RunEnded reactor — the driver — that, when the maker stops, verifies the objective with a cheap separate model (see verify.go) and either ends the loop or relaunches the maker with feedback. The directive lives in the system prompt (see prompt.go) so it survives compaction; STATE.md is the durable, canonical brain.
Index ¶
- Constants
- Variables
- func GoalDirective(info Info) string
- func Verify(ctx context.Context, cfg VerifyConfig) (Verdict, VerifyStats, error)
- type Command
- type FlagSpec
- type Goal
- func (g *Goal) Active() bool
- func (g *Goal) AddSpent(cost float64) float64
- func (g *Goal) BeginIteration() int
- func (g *Goal) Enter(opts Options) error
- func (g *Goal) Exit() bool
- func (g *Goal) IncStalled() int
- func (g *Goal) Info() Info
- func (g *Goal) LastCommit() string
- func (g *Goal) PriorVerdicts() []IterationVerdict
- func (g *Goal) RecordVerdict(iteration int, satisfied bool, feedback string)
- func (g *Goal) ResetStalled()
- func (g *Goal) SetLastCommit(hash string)
- func (g *Goal) SetOnChange(fn func(active bool))
- func (g *Goal) Spent() float64
- type Info
- type IterationVerdict
- type Options
- type ProviderFactory
- type Verdict
- type VerifyConfig
- type VerifyStats
Constants ¶
const DefaultMaxStalled = 3
DefaultMaxStalled ends the loop after this many consecutive unsatisfied iterations (the spin-loop guard) unless the caller overrides it.
const DefaultStatePath = ".moa/goal/STATE.md"
DefaultStatePath is where STATE.md lives when the caller doesn't override it.
const ( // DefaultVerifierMaxBudget caps a single verifier run's spend (USD). Exported // so the driver can clamp it against the goal's remaining budget pool. DefaultVerifierMaxBudget = 0.50 )
Verifier guardrail defaults. The verifier is a read-only mini-agent: it reads the plan/state it's judging and checks a handful of requirements against the real repo, so it needs a few turns but must not run away.
const DefaultVerifierSpec = "haiku"
DefaultVerifierSpec is the cheap, fast model used to judge the objective.
const DefaultVerifyTimeout = 5 * time.Minute
DefaultVerifyTimeout bounds a whole verifier run (wall-clock, across all its tool-using turns). Callers may override it (see VerifyConfig.Timeout); 0 selects this default.
Variables ¶
var FlagsUsage = buildFlagsUsage()
FlagsUsage is a one-line hint of the accepted knobs, for help/palette text.
Functions ¶
func GoalDirective ¶
GoalDirective returns the system-prompt fragment injected while goal mode is active. It deliberately lives in the system prompt (not a user message) so it survives every compaction — that's what keeps the loop alive across context resets. STATE.md carries the durable, canonical progress.
func Verify ¶
func Verify(ctx context.Context, cfg VerifyConfig) (Verdict, VerifyStats, error)
Verify judges whether the objective is satisfied. In the default (agentic) mode it runs a read-only mini-agent that can read the plan/state and check requirements against the real repo before returning a verdict. In OneShot mode it makes a single tool-less call (legacy behaviour).
It returns the verdict, stats about what the run consumed (for budgeting), and an error only for genuine infrastructure failures — running out of turns/budget/time yields a not-satisfied verdict with feedback, NOT an error, so a healthy goal isn't paused just because the verifier was capped.
Types ¶
type Command ¶
type Command struct {
Objective string
CompactAt int // --compact N (soft compaction threshold, tokens)
VerifierSpec string // --verifier SPEC (model for the verifier)
MaxIterations int // --max N
MaxStalled int // --stalled N
Timeout time.Duration // --timeout DUR (e.g. 2h, 90m)
VerifyTimeout time.Duration // --verify-timeout DUR (total wall-clock per verifier run)
VerifyOneShot bool // --verify-oneshot (use the legacy tool-less verifier)
TotalBudget float64 // --budget USD (cumulative ceiling across iterations)
WorkDir string // --cwd DIR (execution/evaluation directory; "" = session CWD)
}
Command is the parsed form of a "/goal" command line: the objective plus any backstop overrides. Zero-value knobs mean "use the default".
func ParseCommand ¶
ParseCommand parses "<objective> [--max N] [--stalled N] [--timeout DUR] [--budget USD] [--verifier SPEC] [--verify-timeout DUR] [--compact N] [--cwd DIR]".
Flags are only recognized as a contiguous run of known-flag/value pairs at the tail of the input: scanning from the end, as long as the last remaining token is either a known "--flag=value" or a (known flag, non-flag value) pair it is consumed as a flag; the scan stops at the first token that doesn't match. Everything before that point — including unknown "--foo" tokens or known flags that end up separated from the tail — is preserved verbatim as the objective. An empty objective or an invalid flag value in the recognized tail is an error.
type FlagSpec ¶
type FlagSpec struct {
Name string // e.g. "--max"
Placeholder string // e.g. "N", "2h", "USD", "SPEC"
Desc string // short human description
Bool bool // true = valueless boolean flag (e.g. "--verify-oneshot")
}
FlagSpec describes one /goal flag for help text and autocompletion.
type Goal ¶
type Goal struct {
// contains filtered or unexported fields
}
Goal holds goal-mode runtime state. All exported methods are safe for concurrent use.
func (*Goal) AddSpent ¶
AddSpent adds a run's USD cost to the cumulative total and returns the new total. The driver calls it when the maker stops, before the budget backstop.
func (*Goal) BeginIteration ¶
BeginIteration increments and returns the iteration count. The driver calls it when the maker stops, before verifying.
func (*Goal) Enter ¶
Enter activates goal mode: it normalizes options, resets counters, computes the deadline, and creates the STATE.md scaffold if it doesn't already exist (an existing file is preserved — it's the brain). Fires onChange(true).
func (*Goal) Exit ¶
Exit deactivates goal mode. Returns true if it was active (this call turned it off), false if it was already off. Fires onChange(false) only on the active→inactive transition, so callers can make teardown idempotent.
func (*Goal) IncStalled ¶
IncStalled increments and returns the stalled counter (an unsatisfied iteration).
func (*Goal) LastCommit ¶
LastCommit returns the HEAD commit hash recorded at the previous iteration.
func (*Goal) PriorVerdicts ¶
func (g *Goal) PriorVerdicts() []IterationVerdict
PriorVerdicts returns a copy of the recorded iteration verdicts, oldest first, so the driver can summarise them for the verifier.
func (*Goal) RecordVerdict ¶
RecordVerdict appends a finished iteration's verdict to the goal's memory so the next verification can be reminded of what was previously judged unmet.
func (*Goal) ResetStalled ¶
func (g *Goal) ResetStalled()
ResetStalled clears the stalled counter (a satisfied iteration).
func (*Goal) SetLastCommit ¶
SetLastCommit records the HEAD commit hash for the next iteration's progress check. Guarded by the Goal mutex so the driver goroutine and EnterGoal don't race on it.
func (*Goal) SetOnChange ¶
SetOnChange registers a callback fired after every activation change.
type Info ¶
type Info struct {
Active bool
Objective string
StatePath string
WorkDir string // cwd of execution/evaluation; "" = session CWD (see goal.Options.WorkDir)
VerifierSpec string
Iteration int
Stalled int
MaxIterations int
MaxStalled int
Deadline time.Time
TotalBudget float64 // cumulative USD ceiling (0 = unlimited)
Spent float64 // cumulative USD spent so far
VerifyTimeout time.Duration // total wall-clock per verifier run (0 = default)
VerifyOneShot bool // use the legacy tool-less one-shot verifier
}
Info is an immutable snapshot for readers (UI, prompt builder, driver checks).
type IterationVerdict ¶
IterationVerdict is one past iteration's outcome, kept so the verifier can be reminded across iterations of what it previously judged unmet.
type Options ¶
type Options struct {
Objective string
StatePath string // default DefaultStatePath
WorkDir string // cwd of execution/evaluation; "" = session CWD
VerifierSpec string // model spec for the verifier; "" = DefaultVerifierSpec
MaxIterations int // 0 = unlimited
MaxStalled int // 0 = DefaultMaxStalled
Timeout time.Duration // 0 = no wall-clock deadline
TotalBudget float64 // cumulative USD ceiling across all iterations; 0 = unlimited
VerifyTimeout time.Duration // total wall-clock per verifier run; 0 = DefaultVerifyTimeout
VerifyOneShot bool // use the legacy tool-less one-shot verifier
}
Options configure a goal run.
type ProviderFactory ¶
ProviderFactory builds a provider for a given model. Callers pass the same factory they use elsewhere (it handles auth/OAuth refresh).
type VerifyConfig ¶
type VerifyConfig struct {
Factory ProviderFactory
VerifierSpec string // model spec; "" = DefaultVerifierSpec
Objective string // the goal objective (verbatim /goal text)
Evidence string // initial hint (diff + checks); NOT authoritative
PriorFeedback string // summary of earlier iterations' verdicts (memory); may be empty
StatePath string // path to the goal's STATE.md (shown to the verifier)
WorkDir string // read-only sandbox root for the verifier's tools
Timeout time.Duration // wall-clock TOTAL per run; 0 = DefaultVerifyTimeout
MaxTurns int // 0 = defaultVerifierMaxTurns
MaxBudget float64 // 0 = DefaultVerifierMaxBudget
OneShot bool // legacy tool-less one-shot mode
}
VerifyConfig configures a verifier run.