loop

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package loop provides the main orchestration for agent-to-agent pair programming.

Error Handling

This package distinguishes between critical and non-critical errors:

Critical errors cause the loop to fail and return immediately:

  • Agent execution failures (primary or secondary agent cannot execute)
  • Message draining failures (cannot retrieve messages from bridge)
  • MCP server startup failures
  • Agent startup failures

Non-critical errors are logged as warnings but allow the loop to continue:

  • Transcript logging failures (recording events to transcript.jsonl)
  • Run save failures (persisting manifest state)
  • State transition failures (updating internal state machine)
  • Signal logging failures (recording done/review signals)

This design ensures the core orchestration continues even if auxiliary persistence or logging operations fail, while stopping immediately on errors that would prevent meaningful progress.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InvalidTransitionError

type InvalidTransitionError struct {
	From State
	To   State
}

InvalidTransitionError is returned for invalid state transitions.

func (*InvalidTransitionError) Error

func (e *InvalidTransitionError) Error() string

type Loop

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

Loop orchestrates paired agent execution.

func New

func New(cfg *config.Config, r *run.Run, primary, secondary agent.Agent) *Loop

New creates a new loop with the given configuration and run.

func (*Loop) MCPServerAddr

func (l *Loop) MCPServerAddr() string

MCPServerAddr returns the MCP server address for agents to connect to.

func (*Loop) Resume

func (l *Loop) Resume(ctx context.Context) error

Resume continues a run from its current state.

func (*Loop) Run

func (l *Loop) Run(ctx context.Context) error

Run executes the main loop until completion or max iterations.

func (*Loop) Status

func (l *Loop) Status() *Status

Status returns the current loop status.

type Machine

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

Machine manages state transitions.

func NewMachine

func NewMachine() *Machine

NewMachine creates a new state machine starting in init state.

func (*Machine) Current

func (m *Machine) Current() State

Current returns the current state.

func (*Machine) History

func (m *Machine) History() []State

History returns the state transition history.

func (*Machine) IsTerminal

func (m *Machine) IsTerminal() bool

IsTerminal returns true if in a terminal state.

func (*Machine) Transition

func (m *Machine) Transition(newState State) error

Transition moves to a new state.

type SingleLoop

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

SingleLoop orchestrates a single agent execution.

func NewSingle

func NewSingle(cfg *config.Config, r *run.Run, a agent.Agent) *SingleLoop

NewSingle creates a new single-agent loop.

func (*SingleLoop) MCPServerAddr

func (l *SingleLoop) MCPServerAddr() string

MCPServerAddr returns the MCP server address for the agent to connect to.

func (*SingleLoop) Resume

func (l *SingleLoop) Resume(ctx context.Context) error

Resume continues a single-agent run from its current state.

func (*SingleLoop) Run

func (l *SingleLoop) Run(ctx context.Context) error

Run executes the single-agent loop until completion.

func (*SingleLoop) Status

func (l *SingleLoop) Status() *Status

Status returns the current loop status.

type State

type State string

State represents the loop state machine.

const (
	StateInit      State = "init"
	StateWorking   State = "working"
	StateReviewing State = "reviewing"
	StateComplete  State = "complete"
	StateFailed    State = "failed"
)

func FromRunState

func FromRunState(rs run.State) State

FromRunState converts run state to loop state.

func (State) ToRunState

func (s State) ToRunState() run.State

ToRunState converts loop state to run state.

type Status

type Status struct {
	State         State
	Iteration     int
	MaxIterations int
	RunID         int
	Elapsed       time.Duration
	BridgeStatus  *bridge.Status
}

Status contains loop status information.

Jump to

Keyboard shortcuts

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