goal

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
const DefaultMaxStalled = 3

DefaultMaxStalled ends the loop after this many consecutive unsatisfied iterations (the spin-loop guard) unless the caller overrides it.

View Source
const DefaultStatePath = ".moa/goal/STATE.md"

DefaultStatePath is where STATE.md lives when the caller doesn't override it.

View Source
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.

View Source
const DefaultVerifierSpec = "haiku"

DefaultVerifierSpec is the cheap, fast model used to judge the objective.

View Source
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

View Source
var FlagsUsage = buildFlagsUsage()

FlagsUsage is a one-line hint of the accepted knobs, for help/palette text.

Functions

func GoalDirective

func GoalDirective(info Info) string

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

func ParseCommand(args string) (Command, error)

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.

func Flags

func Flags() []FlagSpec

Flags returns the declarative list of accepted /goal flags. It is the single source of truth consumed by ParseCommand (known-flag set), FlagsUsage, and the web/TUI 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 New

func New() *Goal

New creates an inactive Goal.

func (*Goal) Active

func (g *Goal) Active() bool

Active reports whether goal mode is on.

func (*Goal) AddSpent

func (g *Goal) AddSpent(cost float64) float64

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

func (g *Goal) BeginIteration() int

BeginIteration increments and returns the iteration count. The driver calls it when the maker stops, before verifying.

func (*Goal) Enter

func (g *Goal) Enter(opts Options) error

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

func (g *Goal) Exit() bool

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

func (g *Goal) IncStalled() int

IncStalled increments and returns the stalled counter (an unsatisfied iteration).

func (*Goal) Info

func (g *Goal) Info() Info

Info returns a snapshot of the current state.

func (*Goal) LastCommit

func (g *Goal) LastCommit() string

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

func (g *Goal) RecordVerdict(iteration int, satisfied bool, feedback string)

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

func (g *Goal) SetLastCommit(hash string)

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

func (g *Goal) SetOnChange(fn func(active bool))

SetOnChange registers a callback fired after every activation change.

func (*Goal) Spent

func (g *Goal) Spent() float64

Spent returns the cumulative USD spent across iterations.

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

type IterationVerdict struct {
	Iteration int
	Satisfied bool
	Feedback  string
}

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

type ProviderFactory func(core.Model) (core.Provider, error)

ProviderFactory builds a provider for a given model. Callers pass the same factory they use elsewhere (it handles auth/OAuth refresh).

type Verdict

type Verdict struct {
	Satisfied bool   `json:"satisfied"`
	Feedback  string `json:"feedback"`
}

Verdict is the verifier's decision.

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.

type VerifyStats

type VerifyStats struct {
	CostUSD float64
	Usage   *core.Usage
	Turns   int
}

VerifyStats reports what a verifier run consumed, so the driver can charge it against the goal budget.

Jump to

Keyboard shortcuts

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