goals

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 27 Imported by: 1 module, 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

Index

Constants

View Source
const (
	DefaultJudgeTimeout   = 30.0
	DefaultJudgeMaxTokens = 4096

	DefaultMaxConsecutiveParseFailures     = 3
	DefaultMaxConsecutiveTransportFailures = 5
)
View Source
const (
	DefaultGoalMaxTurns       = 20
	DefaultGateTimeoutSeconds = 300
	DefaultGateMaxRetries     = 3
)
View Source
const (
	GoalAlreadySeenKick = "[Goal set] Continue with the goal you were just given; there is no need to re-read it."
)
View Source
const UserPausedReason = "user-paused"

Pause reason of a goal the user paused without naming one

Variables

This section is empty.

Functions

func ClearGoal

func ClearGoal(ctx context.Context, sessionID string)

Marks the stored goal cleared, keeping the row for audit

func ClearSessionDBCache

func ClearSessionDBCache()

Empties the per home session database cache the way tests reset the module level dict

func CountActiveDelegations

func CountActiveDelegations(sessionID string) (count int)

Live async delegation batches the session spawned, zero for no session or a registry failure

func EnglishGoalRender

func EnglishGoalRender(key, def string, values map[string]any) string

English rendering that fills the default template and ignores the key

func GatherBackgroundProcesses

func GatherBackgroundProcesses(ctx context.Context, taskID, ownerTaskID string) (running []map[string]any)

Running process registry sessions for the judge, only those the owner task spawned when one is named

func GoalKickPrompt

func GoalKickPrompt(goal string, lastUserMessage any) string

Goal text, or the already seen pointer when the last user message is essentially that text

func GoalMetaKey

func GoalMetaKey(sessionID string) string

func IsGoalControl

func IsGoalControl(arg string) bool

True when the command controls an existing goal rather than replacing it

func LastUserMessageContent

func LastUserMessageContent(history any) any

Content of the newest user message of a chat history, empty text when there is none

func LastUserMessageFromDB

func LastUserMessageFromDB(ctx context.Context, sessionID string) (content any)

Newest user message of a session from the session store, empty text on any failure

func MigrateGoalToSession

func MigrateGoalToSession(ctx context.Context, oldSessionID, newSessionID, reason string) bool

Copies a live goal onto the continuation session and archives the parent row, true when migrated

func RunGate

func RunGate(ctx context.Context, gate GoalGate, cwd string) (passed bool, exitCode int64, outputTail string, interrupted error)

Shell run of one gate giving pass, exit code and output tail, a timeout as minus one

func SaveGoal

func SaveGoal(ctx context.Context, sessionID string, st *GoalState)

Persists a goal to the session database, warning when the database is unavailable

func SessionDB

func SessionDB(ctx context.Context) *state.DB

Cached registry database of the home in effect, never opened inline on a running loop, nil on failure

func WarnDroppedWrite

func WarnDroppedWrite(manager, kind, sessionID string)

Warns that a state write was dropped because the session database is unavailable

Types

type GoalCommandOptions

type GoalCommandOptions struct {
	AuthorizeGate   func() string
	LastUserMessage any
	Render          GoalRender
	Progress        func(string)
}

Optional inputs of one goal command, a nil render meaning English

type GoalCommandResult

type GoalCommandResult struct {
	Output       string
	Prompt       *string
	Kickoff      bool
	ClearPending string
	Error        bool
}

Outcome of one goal command, the prompt nil when no turn should follow

func DispatchGoalCommand

func DispatchGoalCommand(m Manager, arg string, o GoalCommandOptions) (GoalCommandResult, error)

Applies one goal command to the manager, the goal errors rendered as an invalid goal result

type GoalContract

type GoalContract struct {
	Outcome      string
	Verification string
	Constraints  string
	Boundaries   string
	StopWhen     string
}

Optional structured completion contract whose empty fields are omitted everywhere

func DraftContract

func DraftContract(ctx context.Context, objective string, timeout *float64) *GoalContract

Completion contract drafted from a plain objective through the goal_judge task, nil when unavailable or unparseable

func GoalContractFromDict

func GoalContractFromDict(data any) GoalContract

Contract of a stored dict with each field stringified and stripped, empty for a non dict

func ParseContract

func ParseContract(text string) (string, GoalContract)

Headline and contract of goal text whose field lines such as verify or done when fill the contract

func (GoalContract) IsEmpty

func (c GoalContract) IsEmpty() bool

True when every field is blank after stripping

func (GoalContract) RenderBlock

func (c GoalContract) RenderBlock() string

Labelled lines of the non empty fields, empty for an empty contract

func (GoalContract) ToDict

func (c GoalContract) ToDict() *pyjson.Object

Ordered dict of every field keyed by its name

type GoalDecision

type GoalDecision struct {
	Status             any
	ShouldContinue     bool
	ContinuationPrompt *string
	Verdict            string
	Reason             string
	Message            string
}

What the goal loop does after a turn, the status nil when the session has no goal

func (GoalDecision) ToDict

func (d GoalDecision) ToDict() *pyjson.Object

Decision fields as an ordered JSON object

type GoalGate

type GoalGate struct {
	Command        string
	TimeoutSeconds int64
	MaxRetries     int64
	Attempts       int64
	LastExitCode   *int64
	LastOutputTail string
}

Deterministic shell command that must pass before a goal can be done

func GoalGateFromDict

func GoalGateFromDict(data any) (GoalGate, error)

Gate of a stored dict with Python int and str coercion, a blank gate for a non dict

func NewGoalGate

func NewGoalGate(command string) GoalGate

Gate for command with the default timeout and retry budget

func (GoalGate) ToDict

func (g GoalGate) ToDict() *pyjson.Object

Ordered dict of every gate field

type GoalLoopOptions

type GoalLoopOptions struct {
	TaskID        string
	GoalText      string
	RunTurn       func(prompt string) (any, error)
	TaskStatus    func() (*string, error)
	Block         func(reason string) error
	MaxTurns      int
	FirstResponse string
	Log           func(string)
}

Inputs of the kanban worker goal loop, a turn budget below one meaning twenty

type GoalLoopResult

type GoalLoopResult struct {
	Outcome   string
	TurnsUsed int
	Reason    string
}

How the kanban worker goal loop ended

func RunKanbanGoalLoop

func RunKanbanGoalLoop(ctx context.Context, o GoalLoopOptions) (GoalLoopResult, error)

Drives a kanban worker until it ends its task, the judge blocks it, or the budget runs out

type GoalManager

type GoalManager struct {
	SessionID       string
	DefaultMaxTurns int64
	// contains filtered or unexported fields
}

Per session goal state and the continuation decisions the CLI and the gateway act on

func NewGoalManager

func NewGoalManager(ctx context.Context, sessionID string, defaultMaxTurns int64) *GoalManager

Manager of a session's goal loaded from the session store, a zero default meaning twenty turns

func (*GoalManager) AddGate

func (m *GoalManager) AddGate(command string, timeoutSeconds, maxRetries int64) (GoalGate, error)

Appends a quality gate command, zero timeout or retries taking the defaults

func (*GoalManager) AddSubgoal

func (m *GoalManager) AddSubgoal(text string) (string, error)

Appends a user criterion and returns it, a RuntimeError without a goal and a ValueError for empty text

func (*GoalManager) Clear

func (m *GoalManager) Clear()

Marks the goal cleared in the store and drops it from the manager

func (*GoalManager) ClearGates

func (m *GoalManager) ClearGates() (int, error)

Removes every gate and returns how many there were

func (*GoalManager) ClearSubgoals

func (m *GoalManager) ClearSubgoals() (int, error)

Removes every subgoal and returns how many there were

func (*GoalManager) Context

func (m *GoalManager) Context() context.Context

Context the manager reads the store and calls the judge under

func (*GoalManager) EvaluateAfterTurn

func (m *GoalManager) EvaluateAfterTurn(lastResponse string, backgroundProcesses []map[string]any, activeDelegations int) (GoalDecision, error)

Runs the gates and the judge after a turn, updates the state and returns what the loop does next

func (*GoalManager) HasContract

func (m *GoalManager) HasContract() bool

True when the goal carries a completion contract

func (*GoalManager) HasGoal

func (m *GoalManager) HasGoal() bool

True when the goal is active or paused

func (*GoalManager) IsActive

func (m *GoalManager) IsActive() bool

True when the goal is active

func (*GoalManager) IsWaiting

func (m *GoalManager) IsWaiting() bool

True while a barrier is set and unmet, a met or overlong barrier cleared on the way

func (*GoalManager) MarkDone

func (m *GoalManager) MarkDone(reason string)

Marks the goal done with the reason as its last verdict

func (*GoalManager) NextContinuationPrompt

func (m *GoalManager) NextContinuationPrompt() *string

User role message that continues an active goal, the contract first and subgoals folded in, nil when not active

func (*GoalManager) Pause

func (m *GoalManager) Pause(reason string) *GoalState

Pauses the goal and lifts any wait barrier, nil when the session has no goal

func (*GoalManager) Refresh

func (m *GoalManager) Refresh()

Reads the state again from the session store

func (*GoalManager) RemoveGate

func (m *GoalManager) RemoveGate(index1Based int64) (string, error)

Removes a gate by its one based index and returns its command

func (*GoalManager) RemoveSubgoal

func (m *GoalManager) RemoveSubgoal(index1Based int64) (string, error)

Removes a subgoal by its one based index and returns its text

func (*GoalManager) RenderContract

func (m *GoalManager) RenderContract() string

Completion contract block for the goal show and draft commands, a hint when there is none

func (*GoalManager) RenderGates

func (m *GoalManager) RenderGates() string

Numbered gates with their last result for the gate command

func (*GoalManager) RenderSubgoals

func (m *GoalManager) RenderSubgoals() string

Numbered subgoals for the subgoal command, a hint when there are none

func (*GoalManager) Resume

func (m *GoalManager) Resume(resetBudget bool) *GoalState

Reactivates the goal with no wait barrier, resetting the turn budget when asked

func (*GoalManager) Session

func (m *GoalManager) Session() string

Session id the manager is bound to

func (*GoalManager) Set

func (m *GoalManager) Set(goal string, maxTurns int64, contract *GoalContract) (*GoalState, error)

Starts a fresh active goal, a zero turn budget taking the manager default, a ValueError for empty text

func (*GoalManager) SetContract

func (m *GoalManager) SetContract(contract GoalContract) *GoalState

Attaches or replaces the completion contract, nil when the session has no goal

func (*GoalManager) State

func (m *GoalManager) State() *GoalState

Current goal state, nil when the session has none

func (*GoalManager) StatusLine

func (m *GoalManager) StatusLine() string

One line describing the goal, its budget and any wait barrier

func (*GoalManager) StopWaiting

func (m *GoalManager) StopWaiting() bool

Clears any wait barrier, true when one was set

func (*GoalManager) WaitForSeconds

func (m *GoalManager) WaitForSeconds(seconds int64, reason string, onDelegations int64) (*GoalState, error)

Parks the loop for seconds, lifting early once fewer than onDelegations batches are live

func (*GoalManager) WaitOn

func (m *GoalManager) WaitOn(pid int64, reason string) (*GoalState, error)

Parks the loop until a background pid exits, a ValueError for a dead or invalid pid

func (*GoalManager) WaitOnSession

func (m *GoalManager) WaitOnSession(sessionID, reason string) (*GoalState, error)

Parks the loop on a process registry session's own trigger, its exit or a watch pattern match

type GoalRender

type GoalRender func(key, def string, values map[string]any) string

Renders a user facing goal message from its translation key, English default and values

type GoalState

type GoalState struct {
	Goal                         any
	Status                       any
	TurnsUsed                    int64
	MaxTurns                     int64
	CreatedAt                    float64
	LastTurnAt                   float64
	LastVerdict                  any
	LastReason                   any
	PausedReason                 any
	ConsecutiveParseFailures     int64
	ConsecutiveTransportFailures int64
	Subgoals                     []string
	WaitingOnPID                 *int64
	WaitingOnSession             *string
	WaitingUntil                 float64
	WaitingOnDelegations         int64
	WaitingReason                any
	WaitingSince                 float64
	Contract                     GoalContract
	Gates                        []GoalGate
}

Serializable goal state stored per session, uncoerced fields keeping their stored JSON value

func GoalStateFromJSON

func GoalStateFromJSON(raw string) (*GoalState, error)

Goal state of a stored row with the Python coercions, legacy rows filling defaults

func LoadGoal

func LoadGoal(ctx context.Context, sessionID string) *GoalState

Stored goal of a session, nil when absent, unreadable or unparseable

func NewGoalState

func NewGoalState(goal any) *GoalState

Active goal with the dataclass defaults

func (*GoalState) ClearWait

func (s *GoalState) ClearWait()

Lifts every wait barrier

func (*GoalState) HasContract

func (s *GoalState) HasContract() bool

True when a non empty contract is attached

func (*GoalState) RenderSubgoalsBlock

func (s *GoalState) RenderSubgoalsBlock() string

Numbered subgoal lines, empty when there are no subgoals

func (*GoalState) ToJSON

func (s *GoalState) ToJSON() (string, error)

JSON of every field in declaration order with non ASCII kept

type JudgeOptions

type JudgeOptions struct {
	Timeout             *float64
	Subgoals            []string
	BackgroundProcesses []map[string]any
	Contract            *GoalContract
	ActiveDelegations   int
}

Optional inputs of one judge call

type JudgeResult

type JudgeResult struct {
	Verdict         string
	Reason          string
	ParseFailed     bool
	Wait            map[string]any
	TransportFailed bool
}

Outcome of one judge call, the verdict being done, blocked, continue, wait or skipped

func JudgeGoal

func JudgeGoal(ctx context.Context, goal, lastResponse string, o JudgeOptions) JudgeResult

Asks the auxiliary model whether the goal is satisfied, failing open to continue on any transport error

type Manager

type Manager interface {
	Session() string
	Context() context.Context
	Refresh()
	State() *GoalState
	IsActive() bool
	HasGoal() bool
	HasContract() bool
	StatusLine() string
	RenderSubgoals() string
	RenderGates() string
	RenderContract() string
	NextContinuationPrompt() *string
	Set(goal string, maxTurns int64, contract *GoalContract) (*GoalState, error)
	Pause(reason string) *GoalState
	Resume(resetBudget bool) *GoalState
	Clear()
	MarkDone(reason string)
	AddSubgoal(text string) (string, error)
	RemoveSubgoal(index1Based int64) (string, error)
	ClearSubgoals() (int, error)
	AddGate(command string, timeoutSeconds, maxRetries int64) (GoalGate, error)
	RemoveGate(index1Based int64) (string, error)
	ClearGates() (int, error)
	WaitOn(pid int64, reason string) (*GoalState, error)
	WaitOnSession(sessionID, reason string) (*GoalState, error)
	WaitForSeconds(seconds int64, reason string, onDelegations int64) (*GoalState, error)
	StopWaiting() bool
	IsWaiting() bool
	EvaluateAfterTurn(lastResponse string, backgroundProcesses []map[string]any, activeDelegations int) (GoalDecision, error)
}

Calls of a goal manager the goal command and the CLI make, answered in process or by the gateway

Jump to

Keyboard shortcuts

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