goal

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package goal powers the "/goal" completion-condition feature: an agent loop that keeps running turns until a fast model judges a user-specified condition met. This file holds pure state + bookkeeping; no llm import.

Index

Constants

View Source
const (
	DefaultMaxTurns  = 25
	DefaultMaxTokens = 2_000_000
)
View Source
const (
	AchievedPrefix = "✓ goal achieved: "
	StoppedPrefix  = "goal: stopped ("
)

Verdict markers the headless goal loop and TUI print when a goal run ends. The bench harness classifies a run by matching these prefixes in captured output, so the exact strings are a contract: change them here and every emit/parse site follows from the same const.

Variables

This section is empty.

Functions

func Continuation

func Continuation(condition, reason string) string

Continuation is the synthetic user message injected to keep the agent working when the goal is not yet met.

func IsClearWord

func IsClearWord(s string) bool

IsClearWord reports whether a /goal subcommand word means clear.

func RecoverContinuation

func RecoverContinuation(condition, reason string) string

RecoverContinuation is injected after a turn that bailed because the model wedged — repeating a failing call or emitting a malformed envelope. Reframes the goal with an explicit "stop repeating, fill every required argument or switch tools" nudge so the next turn starts a fresh loop instead of the loop dying on a transient generation failure.

Types

type Caps

type Caps struct {
	MaxTurns  int
	MaxTokens int
}

Caps bounds an auto-loop. Zero fields fall back to the package defaults.

type State

type State struct {
	Condition     string
	Active        bool
	StartedAt     time.Time
	Turns         int // auto-loop turns since set
	TokenBaseline int // cumulative session tokens at set time
	LastReason    string
	Caps          Caps
}

State holds an active goal. Zero value = inactive.

func (*State) CapsExceeded

func (s *State) CapsExceeded(curCumTokens int) (bool, string)

CapsExceeded reports whether turns or token-spend passed the caps. reason is a short human string, empty when within bounds.

func (*State) Clear

func (s *State) Clear()

Clear zeroes everything; Active becomes false.

func (*State) Set

func (s *State) Set(cond string, tokenBaseline int, now time.Time)

Set activates a goal, resetting counters and timestamps. tokenBaseline is the cumulative session token count at set time so spend can be measured forward.

func (*State) StatLine

func (s *State) StatLine(curCumTokens int) string

StatLine is a compact one-line status-bar indicator, e.g. "goal: fix the build · t3 · 12k".

func (*State) Status

func (s *State) Status(curCumTokens int, now time.Time) string

Status is the multi-line "/goal show" block.

func (*State) Tick

func (s *State) Tick()

Tick records one auto-loop turn.

func (*State) TokensSpent

func (s *State) TokensSpent(curCumTokens int) int

TokensSpent reports tokens consumed since the goal was set, floored at 0.

type Verdict

type Verdict struct {
	Met    bool
	Reason string
}

Verdict is the fast model's judgement on whether a goal condition is met.

func Evaluate

func Evaluate(ctx context.Context, p llm.Provider, model, condition string, recent []types.Message) (Verdict, error)

Evaluate asks a fast model whether condition is demonstrably met based on the recent conversation. Single cheap side call, no tools. On any provider/parse error it returns Verdict{Met:false, ...} and the error.

Jump to

Keyboard shortcuts

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