loop

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 40 Imported by: ? modules, 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 (
	LoopEventStageCompleted     = event.LoopEventStageCompleted
	LoopEventStageFailed        = event.LoopEventStageFailed
	LoopEventOrderCompleted     = event.LoopEventOrderCompleted
	LoopEventOrderFailed        = event.LoopEventOrderFailed
	LoopEventOrderDropped       = event.LoopEventOrderDropped
	LoopEventOrderRequeued      = event.LoopEventOrderRequeued
	LoopEventWorktreeMerged     = event.LoopEventWorktreeMerged
	LoopEventMergeConflict      = event.LoopEventMergeConflict
	LoopEventScheduleCompleted  = event.LoopEventScheduleCompleted
	LoopEventRegistryRebuilt    = event.LoopEventRegistryRebuilt
	LoopEventSyncDegraded       = event.LoopEventSyncDegraded
	LoopEventBootstrapCompleted = event.LoopEventBootstrapCompleted
	LoopEventBootstrapExhausted = event.LoopEventBootstrapExhausted
	LoopEventPromotionFailed    = event.LoopEventPromotionFailed
)

Re-export loop event types for in-package use.

View Source
const (
	StageStatusPending   = orderx.StageStatusPending
	StageStatusActive    = orderx.StageStatusActive
	StageStatusMerging   = orderx.StageStatusMerging
	StageStatusCompleted = orderx.StageStatusCompleted
	StageStatusFailed    = orderx.StageStatusFailed
	StageStatusCancelled = orderx.StageStatusCancelled
)

Re-export orderx status constants for in-package use.

View Source
const (
	OrderStatusActive    = orderx.OrderStatusActive
	OrderStatusCompleted = orderx.OrderStatusCompleted
	OrderStatusFailed    = orderx.OrderStatusFailed
)

Variables

This section is empty.

Functions

func RepairTaskSkill

func RepairTaskSkill() string

RepairTaskSkill returns the skill name for runtime repair sessions.

func ScheduleTaskKey

func ScheduleTaskKey() string

ScheduleTaskKey returns the canonical steer target for the scheduler.

Types

type AdapterRunner

type AdapterRunner interface {
	Run(ctx context.Context, adapterName, action string, options adapter.RunOptions) (string, error)
}

type AgentMistakeEnvelope

type AgentMistakeEnvelope struct {
	FailureClass    failure.FailureClass          `json:"failure_class"`
	Owner           failure.FailureOwner          `json:"owner"`
	Scope           failure.FailureScope          `json:"scope"`
	Recoverability  failure.FailureRecoverability `json:"recoverability"`
	SchedulerReason SchedulerMistakeReason        `json:"scheduler_reason,omitempty"`
	CookReason      CookMistakeReason             `json:"cook_reason,omitempty"`
	OrderID         string                        `json:"order_id,omitempty"`
	StageIndex      *int                          `json:"stage_index,omitempty"`
}

AgentMistakeEnvelope captures agent ownership classification for failures that are not backend invariant/runtime faults.

type AgentStartFailureClass

type AgentStartFailureClass string

AgentStartFailureClass classifies session start attempts by retry behavior.

const (
	AgentStartFailureClassFallback      AgentStartFailureClass = "fallback"
	AgentStartFailureClassUnrecoverable AgentStartFailureClass = "unrecoverable"
)

type BootstrapExhaustedPayload

type BootstrapExhaustedPayload struct {
	Reason  string                `json:"reason"`
	Failure *EventFailureMetadata `json:"failure,omitempty"`
}

type ControlAck

type ControlAck struct {
	ID      string             `json:"id"`
	Action  string             `json:"action"`
	Status  string             `json:"status"`
	Message string             `json:"message,omitempty"`
	Failure *ControlAckFailure `json:"failure,omitempty"`
	At      time.Time          `json:"at"`
}

type ControlAckFailure

type ControlAckFailure struct {
	FailureProjection
}

ControlAckFailure is projected into control acknowledgement rows when a command fails.

type ControlCommand

type ControlCommand struct {
	ID       string    `json:"id"`
	Action   string    `json:"action"`
	OrderID  string    `json:"order_id,omitempty"`
	Name     string    `json:"name,omitempty"`
	Target   string    `json:"target,omitempty"`
	Prompt   string    `json:"prompt,omitempty"`
	Value    string    `json:"value,omitempty"`
	TaskKey  string    `json:"task_key,omitempty"`
	Provider string    `json:"provider,omitempty"`
	Model    string    `json:"model,omitempty"`
	Skill    string    `json:"skill,omitempty"`
	At       time.Time `json:"at,omitempty"`
}

type CookMistakeReason

type CookMistakeReason string

CookMistakeReason identifies cook-agent owned mistakes.

const (
	CookMistakeReasonQualityRejected CookMistakeReason = "quality_rejected"
	CookMistakeReasonReviewRejected  CookMistakeReason = "review_rejected"
	CookMistakeReasonRequestChanges  CookMistakeReason = "request_changes"
)

type CookSummary

type CookSummary struct {
	SessionID    string    `json:"session_id"`
	OrderID      string    `json:"order_id"`
	TaskKey      string    `json:"task_key,omitempty"`
	Skill        string    `json:"skill,omitempty"`
	Runtime      string    `json:"runtime,omitempty"`
	Provider     string    `json:"provider,omitempty"`
	Model        string    `json:"model,omitempty"`
	WorktreeName string    `json:"worktree_name,omitempty"`
	StartedAt    time.Time `json:"started_at"`
	DisplayName  string    `json:"display_name,omitempty"`
	Status       string    `json:"status"`
	TotalCostUSD float64   `json:"total_cost_usd"`
}

type CycleFailureClass

type CycleFailureClass string

CycleFailureClass classifies loop-cycle failure behavior.

const (
	CycleFailureClassSystemHard      CycleFailureClass = "system-hard"
	CycleFailureClassOrderHard       CycleFailureClass = "order-hard"
	CycleFailureClassDegradeContinue CycleFailureClass = "degrade-continue"
)

type Dependencies

type Dependencies struct {
	Runtimes       map[string]loopruntime.Runtime
	Worktree       WorktreeManager
	Adapter        AdapterRunner
	Mise           MiseBuilder
	Monitor        Monitor
	Registry       taskreg.Registry
	EventSink      dispatcher.SessionEventSink
	Logger         *slog.Logger
	Now            func() time.Time
	OrdersFile     string
	OrdersNextFile string
	StatusFile     string
}

type DispatchFailureEnvelope

type DispatchFailureEnvelope struct {
	Class          AgentStartFailureClass
	FailureClass   failure.FailureClass
	Recoverability failure.FailureRecoverability
	Runtime        string
	Message        string
	Cause          error
}

DispatchFailureEnvelope wraps a start failure with explicit recoverability.

func (DispatchFailureEnvelope) Error

func (e DispatchFailureEnvelope) Error() string

func (DispatchFailureEnvelope) Unwrap

func (e DispatchFailureEnvelope) Unwrap() error

type EventFailureMetadata

type EventFailureMetadata struct {
	FailureProjection
	CycleClass CycleFailureClass `json:"cycle_class,omitempty"`
	OrderClass OrderFailureClass `json:"order_class,omitempty"`
}

EventFailureMetadata is projected into loop event payloads for failure events. It carries canonical failure class/recoverability plus loop-local cycle/order classification.

type FailureProjection

type FailureProjection struct {
	Class          failure.FailureClass          `json:"class"`
	Recoverability failure.FailureRecoverability `json:"recoverability"`
	Owner          failure.FailureOwner          `json:"owner,omitempty"`
	Scope          failure.FailureScope          `json:"scope,omitempty"`
}

FailureProjection is the canonical failure classification payload projected into control acknowledgements and loop event payloads.

type Loop

type Loop struct {

	// Test hooks — nil in production. These allow tests to simulate crashes
	// at specific points in the state-persistence pipeline.
	TestFlushBarrier      func() // called between file writes in flushState()
	TestControlAckBarrier func() // called between command processing and ack write in processControlCommands()
	// contains filtered or unexported fields
}

func New

func New(projectDir, noodleBin string, cfg config.Config, deps Dependencies) *Loop

func (*Loop) Cycle

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

func (*Loop) Run

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

func (*Loop) Shutdown

func (l *Loop) Shutdown()

Shutdown kills all active agent sessions. Called during process exit.

func (*Loop) State

func (l *Loop) State() LoopState

type LoopFailureEnvelope

type LoopFailureEnvelope struct {
	Path           string
	Class          CycleFailureClass
	Recoverability failure.FailureRecoverability
	OrderClass     OrderFailureClass
	AgentMistake   *AgentMistakeEnvelope
	OrderID        string
	StageIndex     int
	Message        string
	Cause          error
}

LoopFailureEnvelope wraps loop failures with explicit cycle classification.

func (LoopFailureEnvelope) Error

func (e LoopFailureEnvelope) Error() string

func (LoopFailureEnvelope) Unwrap

func (e LoopFailureEnvelope) Unwrap() error

type LoopState

type LoopState struct {
	UpdatedAt          time.Time           `json:"updated_at"`
	Orders             []Order             `json:"orders"`
	ActiveCooks        []CookSummary       `json:"active_cooks"`
	PendingReviews     []PendingReviewItem `json:"pending_reviews"`
	PendingReviewCount int                 `json:"pending_review_count"`
	RecentHistory      []mise.HistoryItem  `json:"recent_history"`
	Status             string              `json:"status"`
	ActiveSummary      mise.ActiveSummary  `json:"active_summary"`
	ActiveOrderIDs     []string            `json:"active_order_ids"`
	TotalCostUSD       float64             `json:"total_cost_usd"`
	MaxConcurrency     int                 `json:"max_concurrency"`
	Mode               string              `json:"mode"`
	ModeEpoch          uint64              `json:"mode_epoch"`
	ActionNeeded       []string            `json:"action_needed"`
}

type MergeConflictPayload

type MergeConflictPayload struct {
	OrderID      string `json:"order_id"`
	StageIndex   int    `json:"stage_index"`
	WorktreeName string `json:"worktree_name"`
}

type MergeQueue

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

func NewMergeQueue

func NewMergeQueue(parent context.Context, mergeFn func(context.Context, MergeRequest) error) *MergeQueue

func (*MergeQueue) Close

func (q *MergeQueue) Close()

func (*MergeQueue) DrainResults

func (q *MergeQueue) DrainResults() []MergeResult

func (*MergeQueue) Enqueue

func (q *MergeQueue) Enqueue(req MergeRequest)

func (*MergeQueue) InFlight

func (q *MergeQueue) InFlight() int

func (*MergeQueue) Pending

func (q *MergeQueue) Pending() int

type MergeRequest

type MergeRequest struct {
	Cook *cookHandle
}

type MergeResult

type MergeResult struct {
	Cook *cookHandle
	Err  error
}

type MiseBuilder

type MiseBuilder interface {
	Build(ctx context.Context, activeSummary mise.ActiveSummary, recentHistory []mise.HistoryItem) (mise.Brief, []string, bool, error)
}

type Monitor

type Monitor interface {
	RunOnce(ctx context.Context) ([]monitor.SessionMeta, error)
}

type Order

type Order = orderx.Order

type OrderCompletedPayload

type OrderCompletedPayload struct {
	OrderID string `json:"order_id"`
}

type OrderDroppedPayload

type OrderDroppedPayload struct {
	OrderID string `json:"order_id"`
	Reason  string `json:"reason"`
}

type OrderFailedPayload

type OrderFailedPayload struct {
	OrderID      string                `json:"order_id"`
	Reason       string                `json:"reason"`
	AgentMistake *AgentMistakeEnvelope `json:"agent_mistake,omitempty"`
	Failure      *EventFailureMetadata `json:"failure,omitempty"`
}

type OrderFailureClass

type OrderFailureClass string

OrderFailureClass classifies terminal order-level outcomes.

const (
	OrderFailureClassStageTerminal OrderFailureClass = "stage-terminal"
	OrderFailureClassOrderTerminal OrderFailureClass = "order-terminal"
)

type OrderRequeuedPayload

type OrderRequeuedPayload struct {
	OrderID string `json:"order_id"`
}

type OrdersFile

type OrdersFile = orderx.OrdersFile

func ApplyOrderRoutingDefaults

func ApplyOrderRoutingDefaults(of OrdersFile, reg taskreg.Registry, cfg config.Config) (OrdersFile, bool)

ApplyOrderRoutingDefaults delegates to orderx.

func NormalizeAndValidateOrders

func NormalizeAndValidateOrders(of OrdersFile, reg taskreg.Registry, cfg config.Config) (OrdersFile, bool, error)

NormalizeAndValidateOrders delegates to orderx.

type PendingReviewItem

type PendingReviewItem struct {
	OrderID      string   `json:"order_id"`
	StageIndex   int      `json:"stage_index"`
	TaskKey      string   `json:"task_key,omitempty"`
	Title        string   `json:"title,omitempty"`
	Prompt       string   `json:"prompt,omitempty"`
	Provider     string   `json:"provider,omitempty"`
	Model        string   `json:"model,omitempty"`
	Runtime      string   `json:"runtime,omitempty"`
	Skill        string   `json:"skill,omitempty"`
	Plan         []string `json:"plan,omitempty"`
	Rationale    string   `json:"rationale,omitempty"`
	WorktreeName string   `json:"worktree_name"`
	WorktreePath string   `json:"worktree_path"`
	SessionID    string   `json:"session_id,omitempty"`
	Reason       string   `json:"reason,omitempty"`
}

func ReadPendingReview

func ReadPendingReview(runtimeDir string) ([]PendingReviewItem, error)

type PromotionFailedPayload

type PromotionFailedPayload struct {
	Reason       string                `json:"reason"`
	AgentMistake *AgentMistakeEnvelope `json:"agent_mistake,omitempty"`
	Failure      *EventFailureMetadata `json:"failure,omitempty"`
}

type RegistryDiff

type RegistryDiff struct {
	Added   []string
	Removed []string
}

RegistryDiff captures what changed between two registry snapshots.

type RegistryRebuiltPayload

type RegistryRebuiltPayload struct {
	Added   []string `json:"added,omitempty"`
	Removed []string `json:"removed,omitempty"`
}

type RuntimeFallbackOutcome

type RuntimeFallbackOutcome struct {
	Class            AgentStartFailureClass
	FailureClass     failure.FailureClass
	Recoverability   failure.FailureRecoverability
	RequestedRuntime string
	SelectedRuntime  string
	Message          string
	Cause            error
}

RuntimeFallbackOutcome records a successful runtime fallback dispatch path.

type ScheduleCompletedPayload

type ScheduleCompletedPayload struct {
	SessionID string `json:"session_id"`
}

type SchedulerMistakeReason

type SchedulerMistakeReason string

SchedulerMistakeReason identifies scheduler-agent owned mistakes.

const (
	SchedulerMistakeReasonOrdersNextRejected SchedulerMistakeReason = "orders_next_rejected"
)

type Stage

type Stage = orderx.Stage

Type aliases — orderx is canonical.

type StageCompletedPayload

type StageCompletedPayload struct {
	OrderID    string  `json:"order_id"`
	StageIndex int     `json:"stage_index"`
	TaskKey    string  `json:"task_key"`
	SessionID  *string `json:"session_id,omitempty"`
	Message    *string `json:"message,omitempty"`
}

type StageFailedPayload

type StageFailedPayload struct {
	OrderID      string                `json:"order_id"`
	StageIndex   int                   `json:"stage_index"`
	Reason       string                `json:"reason"`
	SessionID    *string               `json:"session_id,omitempty"`
	AgentMistake *AgentMistakeEnvelope `json:"agent_mistake,omitempty"`
	Failure      *EventFailureMetadata `json:"failure,omitempty"`
}

type StageResult

type StageResult struct {
	OrderID      string
	StageIndex   int
	Attempt      int
	Status       StageResultStatus
	SessionID    string
	Generation   uint64
	IsSchedule   bool
	IsBootstrap  bool
	WorktreeName string
	WorktreePath string
	Error        error
	CompletedAt  time.Time
}

type StageResultStatus

type StageResultStatus string
const (
	StageResultCompleted StageResultStatus = "completed"
	StageResultFailed    StageResultStatus = "failed"
	StageResultCancelled StageResultStatus = "cancelled"
)

type State

type State string
const (
	StateRunning  State = "running"
	StatePaused   State = "paused"
	StateDraining State = "draining"
	StateIdle     State = "idle"
)

type SyncDegradedPayload

type SyncDegradedPayload struct {
	Reason  string                `json:"reason"`
	Failure *EventFailureMetadata `json:"failure,omitempty"`
}

type TaskType

type TaskType = taskreg.TaskType

TaskType is the canonical registry entry for a Noodle task/session type.

type WorktreeManager

type WorktreeManager interface {
	Create(name string, opts ...worktree.CreateOpts) error
	Merge(name string, opts ...worktree.MergeOpts) error
	MergeRemoteBranch(branch string) error
	Cleanup(name string, opts ...worktree.CleanupOpts) error
	HasUnmergedCommits(name string) (bool, error)
}

type WorktreeMergedPayload

type WorktreeMergedPayload struct {
	OrderID      string `json:"order_id"`
	StageIndex   int    `json:"stage_index"`
	WorktreeName string `json:"worktree_name"`
}

Jump to

Keyboard shortcuts

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