outcome

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

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

type Failed[R any] struct {
	// Err is the error that caused the loop to fail.
	Err error
}

Failed occurs when the transition function returns an error, or an unrecoverable runtime error occurs.

type Interrupted

type Interrupted[R any] struct {
	// Token is the LoopID string to use with Resume.
	Token string
}

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.

type Stuck

type Stuck[R any] struct {
	// Reason is a human-readable explanation of why the loop was stuck.
	Reason string
}

Stuck occurs when the convergence monitor detects no progress (repeated tool signatures, unchanged state hash, depth ceiling, etc.).

Jump to

Keyboard shortcuts

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