Documentation
¶
Overview ¶
Package outcome defines the sealed set of terminal outcomes for a loop. Using the positional Match function ensures exhaustiveness at compile time: adding a new outcome kind will require updating all call sites.
Type-switch is also possible for code that prefers it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Match ¶
func Match[R, T any]( o Outcome[R], completed func(Completed[R]) T, budgetExceeded func(BudgetExceeded[R]) T, stuck func(Stuck[R]) T, interrupted func(Interrupted[R]) T, policyDenied func(PolicyDenied[R]) T, failed func(Failed[R]) T, ) T
Match dispatches on the outcome type, calling the matching branch function. All six cases are required — a missing case is a compile error. This guarantees exhaustiveness without runtime type switches.
Usage:
message := outcome.Match(o,
func(c outcome.Completed[R]) string { return "done: " + fmt.Sprint(c.Result) },
func(b outcome.BudgetExceeded[R]) string { return "budget exceeded" },
func(s outcome.Stuck[R]) string { return "stuck: " + s.Reason },
func(i outcome.Interrupted[R]) string { return "paused, resume with " + i.Token },
func(p outcome.PolicyDenied[R]) string { return "denied: " + p.Capability },
func(f outcome.Failed[R]) string { return "error: " + f.Err.Error() },
)
Types ¶
type BudgetExceeded ¶
type BudgetExceeded[R any] struct { // Dimension identifies which budget axis was exhausted. Dimension budget.Dimension // Spend is the total accumulated spend at the point of exhaustion. Spend budget.Spend }
BudgetExceeded occurs when a budget limit is hit before completion. Which dimension was exhausted is recorded in Dimension. SP3 populates this fully; the type exists in SP1 to avoid import cycles.
type Completed ¶
type Completed[R any] struct { // Result is the value produced by the final action.Finish. Result R // Spend is the total resource consumption across all dimensions. Spend budget.Spend // Iterations is the total number of iterations executed. Iterations int }
Completed is the happy path: the loop finished with a result.
type Failed ¶
Failed occurs when the transition function returns an error, or an unrecoverable runtime error occurs.
type Interrupted ¶
Interrupted occurs when the loop was paused (AskHuman or explicit Interrupt call). Token is the LoopID, used as a resume token. Call loopkit.Resume(ctx, store, def, LoopID(token)) to continue.
type Outcome ¶
type Outcome[R any] interface { // contains filtered or unexported methods }
Outcome is the sealed interface for all terminal loop outcomes. Only types in this package implement it (unexported method).
type PolicyDenied ¶
type PolicyDenied[R any] struct { // Capability is the capability string that was denied (e.g., "fs:write:/etc"). Capability string // Tool is the tool that required the denied capability. Tool string }
PolicyDenied occurs when the policy engine denies an action. SP3 populates this fully; the type exists in SP1 to avoid import cycles.