recovery

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildFallbackQuery

func BuildFallbackQuery(rc RecoveryContext) string

func ComputeFingerprint

func ComputeFingerprint(ctx RecoveryContext) string

func HydratePlanForEvent

func HydratePlanForEvent(eventID string, rc RecoveryContext, replay Replay, plan *RecoveryPlan)

func ResetRuntimeState

func ResetRuntimeState()

func SummarizeArgs

func SummarizeArgs(args map[string]any) map[string]any

Types

type AgentRoute

type AgentRoute struct {
	Required bool               `json:"required"`
	Target   string             `json:"target,omitempty"`
	Executor string             `json:"executor,omitempty"`
	Reasons  []string           `json:"reasons"`
	Payload  *AgentRoutePayload `json:"payload,omitempty"`
}

type AgentRoutePayload

type AgentRoutePayload struct {
	EventID       string          `json:"event_id"`
	Context       RecoveryContext `json:"context"`
	Replay        Replay          `json:"replay"`
	RawError      string          `json:"raw_error"`
	Category      string          `json:"category"`
	DecisionOwner DecisionOwner   `json:"decision_owner,omitempty"`
	Confidence    float64         `json:"confidence"`
	ShouldRetry   bool            `json:"should_retry"`
	ShouldStop    bool            `json:"should_stop"`
	SafeActions   []string        `json:"safe_actions"`
	DocActions    []DocAction     `json:"doc_actions,omitempty"`
	KBHits        []KBHit         `json:"kb_hits"`
	DocSearch     DocSearch       `json:"doc_search"`
	HumanActions  []string        `json:"human_actions"`
	DecisionHints DecisionHints   `json:"decision_hints"`
	Evidence      []string        `json:"evidence"`
	RuleHints     RuleHints       `json:"rule_hints"`
	ProbeResults  []ProbeResult   `json:"probe_results,omitempty"`
}

type AgentTask

type AgentTask struct {
	Goal                string   `json:"goal"`
	Why                 string   `json:"why"`
	MustReadRefs        []string `json:"must_read_refs,omitempty"`
	AllowedActions      []string `json:"allowed_actions,omitempty"`
	ForbiddenActions    []string `json:"forbidden_actions,omitempty"`
	StopConditions      []string `json:"stop_conditions,omitempty"`
	FinalizeRequirement string   `json:"finalize_requirement,omitempty"`
}

type CaptureInput

type CaptureInput struct {
	CommandPath   []string
	ServerID      string
	ToolName      string
	OperationKind OperationKind
	Args          map[string]any
	Argv          []string
	RawErr        error
	WrappedErr    error
}

type DecisionHints

type DecisionHints struct {
	Retryable            bool `json:"retryable"`
	PermissionSensitive  bool `json:"permission_sensitive"`
	AuthRelated          bool `json:"auth_related"`
	ResourceStateRelated bool `json:"resource_state_related"`
}

type DecisionOwner

type DecisionOwner string
const (
	DecisionOwnerBuiltinRule DecisionOwner = "builtin_rule"
	DecisionOwnerAgent       DecisionOwner = "agent"
)

type DocAction

type DocAction struct {
	Action      string `json:"action"`
	Reason      string `json:"reason,omitempty"`
	SourceTitle string `json:"source_title,omitempty"`
	SourceURL   string `json:"source_url,omitempty"`
}

type DocSearch

type DocSearch struct {
	Provider    string          `json:"provider,omitempty"`
	Query       string          `json:"query,omitempty"`
	Page        int             `json:"page,omitempty"`
	Size        int             `json:"size,omitempty"`
	CurrentPage int             `json:"current_page,omitempty"`
	TotalCount  int             `json:"total_count,omitempty"`
	HasMore     bool            `json:"has_more"`
	Status      string          `json:"status,omitempty"`
	Error       string          `json:"error,omitempty"`
	Request     *ToolCallRecord `json:"request,omitempty"`
	Response    *ToolResponse   `json:"response,omitempty"`
	Items       []DocSearchItem `json:"items,omitempty"`
}

type DocSearchItem

type DocSearchItem struct {
	Title string `json:"title"`
	URL   string `json:"url,omitempty"`
	Desc  string `json:"desc,omitempty"`
}

type Executor

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

func NewExecutor

func NewExecutor(planner *Planner, invoker ToolInvoker) *Executor

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, last LastError) RecoveryBundle

type FinalizeHint

type FinalizeHint struct {
	Required            bool     `json:"required"`
	Command             string   `json:"command,omitempty"`
	ExecutionFileFields []string `json:"execution_file_fields,omitempty"`
	AllowedOutcomes     []string `json:"allowed_outcomes,omitempty"`
}

type KBHit

type KBHit struct {
	Source  string  `json:"source"`
	Title   string  `json:"title"`
	URL     string  `json:"url,omitempty"`
	Snippet string  `json:"snippet,omitempty"`
	Score   float64 `json:"score,omitempty"`
}

type KnowledgeRetrieval

type KnowledgeRetrieval struct {
	KBHits    []KBHit   `json:"kb_hits"`
	DocSearch DocSearch `json:"doc_search"`
}

type KnowledgeRetriever

type KnowledgeRetriever interface {
	Search(ctx context.Context, query string, rc RecoveryContext) (KnowledgeRetrieval, error)
}

type LastError

type LastError struct {
	EventID    string          `json:"event_id"`
	RecordedAt string          `json:"recorded_at"`
	Context    RecoveryContext `json:"context"`
	Replay     Replay          `json:"replay,omitempty"`
}

func LatestCapture

func LatestCapture() *LastError

type OperationKind

type OperationKind string
const (
	OperationRead    OperationKind = "read"
	OperationWrite   OperationKind = "write"
	OperationUnknown OperationKind = "unknown"
)

func InferOperationKind

func InferOperationKind(toolName string) OperationKind

type PlanOptions

type PlanOptions struct {
	EventID         string
	EnableDocSearch bool
}

type Planner

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

func NewPlanner

func NewPlanner(retriever KnowledgeRetriever) *Planner

func (*Planner) Plan

func (*Planner) PlanWithOptions

func (p *Planner) PlanWithOptions(ctx context.Context, rc RecoveryContext, opts PlanOptions) RecoveryPlan

type Probe

type Probe func(ctx context.Context, invoker ToolInvoker, rc RecoveryContext, replay Replay, plan RecoveryPlan) *ProbeResult

type ProbeResult

type ProbeResult struct {
	Name        string         `json:"name"`
	Status      string         `json:"status"`
	ServerID    string         `json:"server_id,omitempty"`
	ToolName    string         `json:"tool_name,omitempty"`
	ArgsSummary map[string]any `json:"args_summary,omitempty"`
	Summary     string         `json:"summary,omitempty"`
	Output      any            `json:"output,omitempty"`
	Error       string         `json:"error,omitempty"`
}

type RecoveryAttempt

type RecoveryAttempt struct {
	CommandSummary string `json:"command_summary,omitempty"`
	Result         string `json:"result,omitempty"`
	ErrorSummary   string `json:"error_summary,omitempty"`
	Source         string `json:"source,omitempty"`
}

type RecoveryBundle

type RecoveryBundle struct {
	Status        string          `json:"status"`
	EventID       string          `json:"event_id"`
	Context       RecoveryContext `json:"context"`
	Replay        Replay          `json:"replay"`
	Plan          RecoveryPlan    `json:"plan"`
	DocSearch     DocSearch       `json:"doc_search"`
	KBHits        []KBHit         `json:"kb_hits,omitempty"`
	DocActions    []DocAction     `json:"doc_actions,omitempty"`
	HumanActions  []string        `json:"human_actions,omitempty"`
	ProbeResults  []ProbeResult   `json:"probe_results,omitempty"`
	AgentTask     AgentTask       `json:"agent_task"`
	FinalizeHint  FinalizeHint    `json:"finalize_hint"`
	AnalysisError string          `json:"analysis_error,omitempty"`
}

type RecoveryContext

type RecoveryContext struct {
	CommandPath   []string       `json:"command_path"`
	ServerID      string         `json:"server_id,omitempty"`
	ToolName      string         `json:"tool_name,omitempty"`
	OperationKind OperationKind  `json:"operation_kind"`
	CLIErrorCode  string         `json:"cli_error_code,omitempty"`
	RawError      string         `json:"raw_error"`
	CallStage     string         `json:"call_stage,omitempty"`
	HTTPStatus    int            `json:"http_status,omitempty"`
	RetryAfter    string         `json:"retry_after,omitempty"`
	TraceID       string         `json:"trace_id,omitempty"`
	RequestID     string         `json:"request_id,omitempty"`
	ArgsSummary   map[string]any `json:"args_summary,omitempty"`
	Fingerprint   string         `json:"fingerprint"`
}

func BuildContext

func BuildContext(input CaptureInput) RecoveryContext

type RecoveryEvent

type RecoveryEvent struct {
	EventID    string             `json:"event_id"`
	Phase      string             `json:"phase"`
	RecordedAt string             `json:"recorded_at"`
	Context    *RecoveryContext   `json:"context,omitempty"`
	Replay     *Replay            `json:"replay,omitempty"`
	Plan       *RecoveryPlan      `json:"plan,omitempty"`
	Bundle     *RecoveryBundle    `json:"bundle,omitempty"`
	Execution  *RecoveryExecution `json:"execution,omitempty"`
	Outcome    string             `json:"outcome,omitempty"`
}

type RecoveryExecution

type RecoveryExecution struct {
	Actions      []string          `json:"actions,omitempty"`
	Attempts     []RecoveryAttempt `json:"attempts,omitempty"`
	Result       string            `json:"result,omitempty"`
	ErrorSummary string            `json:"error_summary,omitempty"`
}

type RecoveryPlan

type RecoveryPlan struct {
	Category      string        `json:"category"`
	DecisionOwner DecisionOwner `json:"decision_owner,omitempty"`
	Confidence    float64       `json:"confidence"`
	AutoActions   []string      `json:"auto_actions"`
	SafeActions   []string      `json:"safe_actions"`
	DocActions    []DocAction   `json:"doc_actions,omitempty"`
	DocSearch     DocSearch     `json:"doc_search"`
	DecisionHints DecisionHints `json:"decision_hints"`
	HumanActions  []string      `json:"human_actions"`
	Evidence      []string      `json:"evidence"`
	KBHits        []KBHit       `json:"kb_hits"`
	ShouldRetry   bool          `json:"should_retry"`
	ShouldStop    bool          `json:"should_stop"`
	RuleHints     RuleHints     `json:"rule_hints"`
	AgentRoute    AgentRoute    `json:"agent_route"`
}

type Replay

type Replay struct {
	ServerID        string         `json:"server_id,omitempty"`
	ToolName        string         `json:"tool_name,omitempty"`
	OperationKind   OperationKind  `json:"operation_kind"`
	ToolArgs        map[string]any `json:"tool_args,omitempty"`
	RedactedArgv    []string       `json:"redacted_argv,omitempty"`
	RedactedCommand string         `json:"redacted_command,omitempty"`
}

func BuildReplay

func BuildReplay(input CaptureInput) Replay

type RuleHints

type RuleHints struct {
	Category      string        `json:"category"`
	DecisionOwner DecisionOwner `json:"decision_owner,omitempty"`
	Confidence    float64       `json:"confidence"`
	SafeActions   []string      `json:"safe_actions"`
	HumanActions  []string      `json:"human_actions"`
	Evidence      []string      `json:"evidence"`
	ShouldRetry   bool          `json:"should_retry"`
	ShouldStop    bool          `json:"should_stop"`
}

type Store

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

func NewStore

func NewStore(configDir string) *Store

func (*Store) Capture

func (s *Store) Capture(ctx RecoveryContext, replay ...Replay) (*LastError, error)

func (*Store) Enabled

func (s *Store) Enabled() bool

func (*Store) Finalize

func (s *Store) Finalize(eventID, outcome string, exec *RecoveryExecution) error

func (*Store) LoadErrorByEvent

func (s *Store) LoadErrorByEvent(eventID string) (*LastError, error)

func (*Store) LoadLastError

func (s *Store) LoadLastError() (*LastError, error)

func (*Store) SaveAnalysis

func (s *Store) SaveAnalysis(eventID string, plan RecoveryPlan, bundle RecoveryBundle) error

func (*Store) SavePlan

func (s *Store) SavePlan(eventID string, plan RecoveryPlan) error

type ToolCallRecord

type ToolCallRecord struct {
	ServerID  string         `json:"server_id,omitempty"`
	ToolName  string         `json:"tool_name,omitempty"`
	Arguments map[string]any `json:"arguments,omitempty"`
}

type ToolInvoker

type ToolInvoker interface {
	CallToolDirect(ctx context.Context, serverID, toolName string, args map[string]any) (*transport.ToolCallResult, error)
}

type ToolResponse

type ToolResponse struct {
	IsError bool                `json:"is_error,omitempty"`
	Content []ToolResponseBlock `json:"content,omitempty"`
}

type ToolResponseBlock

type ToolResponseBlock struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

Jump to

Keyboard shortcuts

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