loop

package
v0.3.34 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FailureMessage

func FailureMessage(results []gate.Result) string

FailureMessage renders the bounded prompt injected after real auto-gate failures. It asks the agent to fix the work, never to mutate quest state.

func MisconfiguredLines

func MisconfiguredLines(results []gate.Result) []string

MisconfiguredLines renders console-only diagnostics for broken checks.

Types

type CheckRunner

type CheckRunner func(context.Context) ([]gate.Result, error)

CheckRunner runs one auto-gate iteration.

type Clock

type Clock interface {
	Now() time.Time
	After(time.Duration) <-chan time.Time
}

Clock is injected so the engine owns no global clock.

type Config

type Config struct {
	MaxIters       int
	MaxWall        time.Duration
	StuckAfter     int
	BlockedTimeout time.Duration
}

Config holds the loop stop conditions. Zero values disable that ceiling.

type Engine

type Engine struct {
	Check  CheckRunner
	Inject Injector
	Events <-chan Event
	Clock  Clock
	Config Config

	OnIteration func(Iteration)
	OnBlocked   func()
	// OnChecking fires on each done-edge just before the auto gates run, so a
	// caller can surface the "checking" phase while a check is in flight.
	OnChecking func()
}

Engine is the pure quest loop core. All side effects are supplied by collaborators; it does not touch tmux, the filesystem, quest status, or gates.

func (Engine) Run

func (e Engine) Run(ctx context.Context) Outcome

Run watches the injected event source, runs checks on done edges, injects real failures, and stops on green, misconfiguration, budget, stuck, blocked timeout, or context cancellation.

type Event

type Event struct {
	Kind EventKind
}

Event is a turn-end or pause signal supplied by a watcher.

type EventKind

type EventKind string

EventKind is an observed agent-state transition relevant to the loop.

const (
	EventDone    EventKind = "done"
	EventBlocked EventKind = "blocked"
)

type Injector

type Injector func(context.Context, string) error

Injector relays one real auto-gate failure message back to the agent.

type Iteration

type Iteration struct {
	Number  int
	Results []gate.Result
	Verdict Verdict
}

Iteration is emitted after each check run for console/UI reporting.

type Outcome

type Outcome struct {
	Kind        OutcomeKind
	Reason      StopReason
	Iterations  int
	LastResults []gate.Result
	Err         error
}

Outcome describes why the engine stopped.

type OutcomeKind

type OutcomeKind string

OutcomeKind is the terminal result of a loop run.

const (
	OutcomeGreen         OutcomeKind = "green"
	OutcomeMisconfigured OutcomeKind = "misconfigured"
	OutcomeStopped       OutcomeKind = "stopped"
	OutcomeError         OutcomeKind = "error"
)

type StateWatcher

type StateWatcher struct {
	// contains filtered or unexported fields
}

StateWatcher polls one session's state.json for primary-pane done and blocked edges. It is intentionally decoupled from the engine and command wiring.

func NewStateWatcher

func NewStateWatcher(stateRoot, sessionID string, interval time.Duration) StateWatcher

NewStateWatcher returns a poll watcher rooted at stateRoot.

func (StateWatcher) Events

func (w StateWatcher) Events(ctx context.Context) <-chan Event

Events starts polling until ctx is canceled. A cold state.json establishes the initial high-water mark; only strictly newer done/blocked edges are emitted.

type StopReason

type StopReason string

StopReason explains an OutcomeStopped result.

const (
	StopBudget         StopReason = "budget"
	StopStuck          StopReason = "stuck"
	StopBlockedTimeout StopReason = "blocked_timeout"
	StopCanceled       StopReason = "canceled"
	StopEventSource    StopReason = "event_source_closed"
)

type Verdict

type Verdict string

Verdict is the per-check classification from gate results.

const (
	VerdictGreen         Verdict = "green"
	VerdictFail          Verdict = "fail"
	VerdictMisconfigured Verdict = "misconfigured"
)

func Classify

func Classify(results []gate.Result) Verdict

Classify collapses one check result slice into the loop's iteration verdict.

Jump to

Keyboard shortcuts

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