recovery

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package recovery stores retry recipes and recovery state for failed runs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllScenarioNames

func AllScenarioNames() []string

Types

type AttemptOptions

type AttemptOptions struct {
	FailureSummary  string
	FailedStepIndex *int
	Now             time.Time
}

type AttemptReport

type AttemptReport struct {
	Kind   string      `json:"kind"`
	Recipe Recipe      `json:"recipe"`
	Entry  LedgerEntry `json:"entry"`
	Result Result      `json:"result"`
	Events []Event     `json:"events"`
}

type AttemptState

type AttemptState string
const (
	StateQueued    AttemptState = "queued"
	StateRunning   AttemptState = "running"
	StateSucceeded AttemptState = "succeeded"
	StateFailed    AttemptState = "failed"
	StateExhausted AttemptState = "exhausted"
)

type CommandResult

type CommandResult struct {
	Step   Step         `json:"step"`
	State  AttemptState `json:"state"`
	Result string       `json:"result"`
}

type EscalationPolicy

type EscalationPolicy string
const (
	EscalationAlertHuman     EscalationPolicy = "alert_human"
	EscalationLogAndContinue EscalationPolicy = "log_and_continue"
	EscalationAbort          EscalationPolicy = "abort"
)

type Event

type Event struct {
	Type      string       `json:"type"`
	Scenario  Scenario     `json:"scenario"`
	RecipeID  string       `json:"recipe_id"`
	State     AttemptState `json:"state,omitempty"`
	Result    *Result      `json:"result,omitempty"`
	CreatedAt time.Time    `json:"created_at"`
}

type LedgerEntry

type LedgerEntry struct {
	RecipeID           string          `json:"recipe_id"`
	AttemptType        string          `json:"attempt_type"`
	Trigger            Scenario        `json:"trigger"`
	AttemptCount       int             `json:"attempt_count"`
	RetryLimit         int             `json:"retry_limit"`
	AttemptsRemaining  int             `json:"attempts_remaining"`
	State              AttemptState    `json:"state"`
	StartedAt          *time.Time      `json:"started_at,omitempty"`
	FinishedAt         *time.Time      `json:"finished_at,omitempty"`
	CommandResults     []CommandResult `json:"command_results,omitempty"`
	Result             *Result         `json:"result,omitempty"`
	LastFailureSummary string          `json:"last_failure_summary,omitempty"`
	EscalationReason   string          `json:"escalation_reason,omitempty"`
	UpdatedAt          time.Time       `json:"updated_at"`
}

type Recipe

type Recipe struct {
	ID               string           `json:"id"`
	Scenario         Scenario         `json:"scenario"`
	Steps            []Step           `json:"steps"`
	MaxAttempts      int              `json:"max_attempts"`
	EscalationPolicy EscalationPolicy `json:"escalation_policy"`
}

func RecipeFor

func RecipeFor(scenario Scenario) (Recipe, error)

type Result

type Result struct {
	Kind       ResultKind `json:"kind"`
	StepsTaken int        `json:"steps_taken,omitempty"`
	Recovered  []Step     `json:"recovered,omitempty"`
	Remaining  []Step     `json:"remaining,omitempty"`
	Reason     string     `json:"reason,omitempty"`
}

type ResultKind

type ResultKind string
const (
	ResultRecovered          ResultKind = "recovered"
	ResultPartialRecovery    ResultKind = "partial_recovery"
	ResultEscalationRequired ResultKind = "escalation_required"
)

type Scenario

type Scenario string
const (
	ScenarioTrustPromptUnresolved   Scenario = "trust_prompt_unresolved"
	ScenarioPromptDeliveredToShell  Scenario = "prompt_delivered_to_shell"
	ScenarioStaleBranch             Scenario = "stale_branch"
	ScenarioCompileRedAfterRefactor Scenario = "compile_red_after_refactor"
	ScenarioMCPHandshakeFailure     Scenario = "mcp_handshake_failure"
	ScenarioPartialPluginStartup    Scenario = "partial_plugin_startup"
	ScenarioProviderFailure         Scenario = "provider_failure"
)

func AllScenarios

func AllScenarios() []Scenario

func ParseScenario

func ParseScenario(value string) (Scenario, error)

func ScenarioFromStartupClassification

func ScenarioFromStartupClassification(classification string) (Scenario, bool)

type StatusReport

type StatusReport struct {
	Scenario           Scenario     `json:"scenario"`
	Attempted          bool         `json:"attempted"`
	State              AttemptState `json:"state,omitempty"`
	AttemptCount       int          `json:"attempt_count"`
	RetryLimit         int          `json:"retry_limit,omitempty"`
	AttemptsRemaining  int          `json:"attempts_remaining,omitempty"`
	EscalationReason   string       `json:"escalation_reason,omitempty"`
	LastFailureSummary string       `json:"last_failure_summary,omitempty"`
}

type Step

type Step struct {
	Kind      StepKind       `json:"kind"`
	TimeoutMS int            `json:"timeout_ms,omitempty"`
	Name      string         `json:"name,omitempty"`
	Reason    string         `json:"reason,omitempty"`
	Metadata  map[string]any `json:"metadata,omitempty"`
}

type StepKind

type StepKind string
const (
	StepAcceptTrustPrompt StepKind = "accept_trust_prompt"
	StepRedirectPrompt    StepKind = "redirect_prompt_to_agent"
	StepMergeForward      StepKind = "merge_forward_branch"
	StepCleanBuild        StepKind = "clean_build"
	StepRetryMCPHandshake StepKind = "retry_mcp_handshake"
	StepRestartPlugin     StepKind = "restart_plugin"
	StepRestartWorker     StepKind = "restart_worker"
	StepEscalateToHuman   StepKind = "escalate_to_human"
)

type Store

type Store struct {
	ConfigHome string
}

func NewStore

func NewStore(configHome string) Store

func (Store) Attempt

func (s Store) Attempt(scenario Scenario, opts AttemptOptions) (AttemptReport, error)

func (Store) List

func (s Store) List() ([]LedgerEntry, error)

func (Store) Status

func (s Store) Status(scenario Scenario) (StatusReport, error)

Jump to

Keyboard shortcuts

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