runtime

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitCodeSuccess      = 0
	ExitCodeError        = 1
	ExitCodeRejected     = 2
	ExitCodeTestFailure  = 3
	ExitCodeConfigError  = 4
	ExitCodeRollbackFail = 5
	ExitCodeTimeout      = 6
	ExitCodeBudget       = 7
)

HeadlessExitCodes for headless mode

Variables

This section is empty.

Functions

func IsHeadlessMode

func IsHeadlessMode() bool

IsHeadlessMode checks if the program should run in headless mode

Types

type ApprovalConfig

type ApprovalConfig struct {
	Policy        ApprovalPolicy
	Timeout       time.Duration
	TimeoutAction TimeoutAction
}

ApprovalConfig holds approval-specific configuration.

func DefaultApprovalConfig

func DefaultApprovalConfig() ApprovalConfig

DefaultApprovalConfig returns sensible defaults.

type ApprovalDecision

type ApprovalDecision struct {
	AgentID   string    `json:"agent_id"`
	Tool      string    `json:"tool"`
	Approved  bool      `json:"approved"`
	Timestamp time.Time `json:"timestamp"`
}

ApprovalDecision records a single approval/rejection decision

type ApprovalManager

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

ApprovalManager handles concurrent approval requests with request-ID keyed routing.

func NewApprovalManager

func NewApprovalManager(cfg ApprovalConfig) *ApprovalManager

NewApprovalManager creates a new approval manager with the given configuration.

func (*ApprovalManager) CancelAll

func (am *ApprovalManager) CancelAll(ctx context.Context)

CancelAll cancels all pending approval requests by closing their response channels.

func (*ApprovalManager) PendingCount

func (am *ApprovalManager) PendingCount() int

PendingCount returns the number of pending approval requests.

func (*ApprovalManager) ReqCh

func (am *ApprovalManager) ReqCh() <-chan types.ApprovalRequest

ReqCh returns the channel for receiving approval requests.

func (*ApprovalManager) RequestApproval

func (am *ApprovalManager) RequestApproval(ctx context.Context, agentID types.AgentID, approvalType string, prompt string, reqContext map[string]any) (bool, error)

RequestApproval sends an approval request and waits for a response. It handles headless policies, timeouts, and concurrent requests safely.

func (*ApprovalManager) Respond

func (am *ApprovalManager) Respond(resp types.ApprovalResponse) error

Respond routes an approval response to the correct pending request.

type ApprovalPolicy

type ApprovalPolicy string

ApprovalPolicy defines how headless mode handles approval requests.

const (
	// PolicyInteractive requires user interaction (TUI modal).
	PolicyInteractive ApprovalPolicy = "interactive"
	// PolicyAutoApprove automatically approves all requests.
	PolicyAutoApprove ApprovalPolicy = "auto-approve"
	// PolicyReject automatically rejects all requests.
	PolicyReject ApprovalPolicy = "reject"
	// PolicyAllow allows without explicit approval (less strict than auto-approve).
	PolicyAllow ApprovalPolicy = "allow"
)

type DiffMsg

type DiffMsg struct {
	Content string
}

type EventMsg

type EventMsg struct {
	Event string
}

type HeadlessExecutor

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

HeadlessExecutor runs tasks without TUI

func NewHeadlessExecutor

func NewHeadlessExecutor(cfg *config.Config, workspace string) (*HeadlessExecutor, error)

NewHeadlessExecutor creates a new headless executor with the given workspace.

func (*HeadlessExecutor) ExecuteTask

func (he *HeadlessExecutor) ExecuteTask(task string) (string, int, error)

ExecuteTask runs a task in headless mode and returns JSON result

func (*HeadlessExecutor) Shutdown

func (he *HeadlessExecutor) Shutdown()

Shutdown stops the runtime and cleans up goroutines.

type ProviderInfoMsg added in v1.2.0

type ProviderInfoMsg struct {
	ActiveProvider  string        `json:"active_provider"`
	PreferredModel  string        `json:"preferred_model"`
	FallbackChain   []string      `json:"fallback_chain"`
	LastError       string        `json:"last_error,omitempty"`
	LastErrorClass  string        `json:"last_error_class,omitempty"`
	Latency         time.Duration `json:"latency"`
	InputTokens     int           `json:"input_tokens"`
	OutputTokens    int           `json:"output_tokens"`
	TotalCostUSD    float64       `json:"total_cost_usd"`
	BudgetUSD       float64       `json:"budget_usd"`
	BudgetRemaining float64       `json:"budget_remaining"`
}

ProviderInfoMsg sends current provider/routing state to the TUI.

type RetryTelemetry

type RetryTelemetry struct {
	TotalAttempts int            `json:"total_attempts"`
	PhaseRetries  map[string]int `json:"phase_retries"`
}

RetryTelemetry tracks retry attempts

type RollbackReport

type RollbackReport struct {
	Attempted bool   `json:"attempted"`
	Success   bool   `json:"success"`
	Error     string `json:"error,omitempty"`
}

RollbackReport records rollback attempt details

type TaskFinalState

type TaskFinalState string

TaskFinalState represents the final state of a task.

const (
	TaskFinalStateCompleted TaskFinalState = "completed"
	TaskFinalStateFailed    TaskFinalState = "failed"
	TaskFinalStateCancelled TaskFinalState = "cancelled"
	TaskFinalStateTimeout   TaskFinalState = "timeout"
	TaskFinalStateRejected  TaskFinalState = "rejected"
)

type TaskResult

type TaskResult struct {
	SchemaVersion     string             `json:"schema_version"`
	Version           string             `json:"version"`
	TaskID            string             `json:"task_id"`
	Status            string             `json:"status"`
	FinalState        TaskFinalState     `json:"final_state"`
	FailureReason     string             `json:"failure_reason,omitempty"`
	Retries           int                `json:"retries"`
	TouchedFiles      []string           `json:"touched_files"`
	TestResult        string             `json:"test_result,omitempty"`
	ReviewResult      string             `json:"review_result,omitempty"`
	ApprovalDecisions []ApprovalDecision `json:"approval_decisions,omitempty"`
	RollbackReport    *RollbackReport    `json:"rollback_report,omitempty"`
	TokenUsage        TokenUsageInfo     `json:"token_usage"`
	RetryTelemetry    RetryTelemetry     `json:"retry_telemetry"`
	Cost              float64            `json:"cost"`
	BudgetExceeded    bool               `json:"budget_exceeded"`
	RollbackAvailable bool               `json:"rollback_available"`
	Error             string             `json:"error,omitempty"`
	DurationSecs      float64            `json:"duration_seconds"`
	ExitCode          int                `json:"exit_code"`
}

TaskResult represents the result of a headless task execution

type TeamRuntime

type TeamRuntime struct {
	Bus             *bus.Bus
	StateManager    *state.StateManager
	EventLog        *state.EventLog
	Agents          map[types.AgentID]*agent.Agent
	Roles           map[types.AgentID]agent.MessageHandler
	LLMClient       llm.Client
	ToolRegistry    *tools.Registry
	Config          *config.Config
	FileQueue       *tools.FileQueue
	ApprovalManager *ApprovalManager
	SafetyPolicy    *safety.SafetyPolicy
	UIMessageCh     chan tea.Msg

	// Task-level deadline tracking
	TaskDeadline time.Duration
	// Max wall-clock runtime
	MaxRuntime time.Duration

	StateDir string
	// contains filtered or unexported fields
}

func InitializeRuntime

func InitializeRuntime(cfg *config.Config, mode string, workspace string, useMock bool) (*TeamRuntime, error)

InitializeRuntime creates and initializes a TeamRuntime for the given mode. Mode must be either "tui" or "headless". workspace is the base directory for tool operations and checkpoint storage. useMock forces the mock LLM client regardless of config.

func NewTeamRuntime

func NewTeamRuntime(cfg *config.Config) *TeamRuntime

func (*TeamRuntime) Context

func (rt *TeamRuntime) Context() context.Context

func (*TeamRuntime) CreateAgent

func (rt *TeamRuntime) CreateAgent(id types.AgentID, role string) (*agent.Agent, agent.MessageHandler, error)

func (*TeamRuntime) ExecuteAction

func (rt *TeamRuntime) ExecuteAction(agentID types.AgentID, action types.Action) error

func (*TeamRuntime) GetLiaison

func (rt *TeamRuntime) GetLiaison() *roles.Liaison

func (*TeamRuntime) GetPolicyHistory added in v0.10.0

func (rt *TeamRuntime) GetPolicyHistory(taskID string) []safety.PolicyEvent

func (*TeamRuntime) LoadCheckpoint

func (rt *TeamRuntime) LoadCheckpoint(dir string) error

func (*TeamRuntime) RecordEvent

func (rt *TeamRuntime) RecordEvent(eventType state.EventType, taskID uuid.UUID, agentID types.AgentID, correlationID string, data map[string]any)

func (*TeamRuntime) RecordEventWithDuration added in v0.10.0

func (rt *TeamRuntime) RecordEventWithDuration(eventType state.EventType, taskID uuid.UUID, agentID types.AgentID, correlationID string, durationMs int64, data map[string]any)

func (*TeamRuntime) RecordPolicyEvent added in v0.10.0

func (rt *TeamRuntime) RecordPolicyEvent(decision *safety.SafetyDecision)

func (*TeamRuntime) RequestApproval

func (rt *TeamRuntime) RequestApproval(ctx context.Context, agentID types.AgentID, approvalType string, prompt string, reqContext map[string]any) (bool, error)

func (*TeamRuntime) SaveCheckpoint

func (rt *TeamRuntime) SaveCheckpoint(dir string) error

func (*TeamRuntime) SendProviderInfo added in v1.2.0

func (rt *TeamRuntime) SendProviderInfo(info ProviderInfoMsg)

SendProviderInfo pushes current provider state to the TUI channel.

func (*TeamRuntime) SendTelemetry added in v1.2.0

func (rt *TeamRuntime) SendTelemetry(records []TelemetryRecord)

SendTelemetry pushes telemetry records to the TUI channel.

func (*TeamRuntime) Services

func (rt *TeamRuntime) Services() *roles.Services

func (*TeamRuntime) SpawnAgent

func (rt *TeamRuntime) SpawnAgent(parent *agent.Agent, role string) (*agent.Agent, error)

func (*TeamRuntime) StartAgent

func (rt *TeamRuntime) StartAgent(a *agent.Agent)

func (*TeamRuntime) Stop

func (rt *TeamRuntime) Stop()

type TelemetryMsg added in v1.2.0

type TelemetryMsg struct {
	Records []TelemetryRecord `json:"records"`
}

TelemetryMsg sends aggregated telemetry to the TUI.

type TelemetryRecord added in v1.2.0

type TelemetryRecord struct {
	Provider     string        `json:"provider"`
	Model        string        `json:"model"`
	Latency      time.Duration `json:"latency"`
	InputTokens  int           `json:"input_tokens"`
	OutputTokens int           `json:"output_tokens"`
	CostUSD      float64       `json:"cost_usd"`
	Success      bool          `json:"success"`
	FailureClass string        `json:"failure_class,omitempty"`
	Timestamp    time.Time     `json:"timestamp"`
}

TelemetryRecord is a runtime-local telemetry entry sent to the TUI.

type TestOutputMsg

type TestOutputMsg struct {
	Output  string
	Summary string
}

type TimeoutAction

type TimeoutAction string

TimeoutAction defines what happens when an approval request times out.

const (
	// TimeoutReject rejects the request on timeout.
	TimeoutReject TimeoutAction = "reject"
	// TimeoutAllow allows the request on timeout.
	TimeoutAllow TimeoutAction = "allow"
	// TimeoutFail returns an error on timeout (fail closed).
	TimeoutFail TimeoutAction = "fail"
)

type TokenUsageInfo

type TokenUsageInfo struct {
	InputTokens  int `json:"input_tokens"`
	OutputTokens int `json:"output_tokens"`
	TotalTokens  int `json:"total_tokens"`
}

TokenUsageInfo tracks LLM token consumption

Jump to

Keyboard shortcuts

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