recovery

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package recovery manages durable recovery plans for restore operations.

Index

Constants

View Source
const SchemaVersion = 1

Variables

View Source
var (
	ErrBackupMissing = errors.New("recovery backup is missing")
)

Functions

func BackupMissingIsSafe

func BackupMissingIsSafe(plan *Plan) bool

func CurrentEvidence

func CurrentEvidence(repoRoot string, plan *Plan) (string, error)

func NewPlanID

func NewPlanID() string

func SetRestoreBackupCloneHookForTest

func SetRestoreBackupCloneHookForTest(hook func(src, dst string) error) func()

func SetWriteHookForTest

func SetWriteHookForTest(hook func(string, []byte, os.FileMode) error) func()

func SetWriteWorktreeConfigHookForTest

func SetWriteWorktreeConfigHookForTest(hook func(repoRoot, name string, cfg *model.WorktreeConfig) error) func()

func VerifyMissingBackupRecoveryPoint

func VerifyMissingBackupRecoveryPoint(repoRoot string, plan *Plan) error

Types

type Backup

type Backup struct {
	Path              string        `json:"path"`
	Scope             BackupScope   `json:"scope"`
	State             BackupState   `json:"state,omitempty"`
	TouchedPaths      []string      `json:"touched_paths,omitempty"`
	Entries           []BackupEntry `json:"entries,omitempty"`
	PayloadRolledBack bool          `json:"payload_rolled_back,omitempty"`
}

type BackupEntry

type BackupEntry struct {
	Path        string `json:"path"`
	HadOriginal bool   `json:"had_original"`
}

type BackupScope

type BackupScope string
const (
	BackupScopeWhole BackupScope = "whole"
	BackupScopePath  BackupScope = "path"
)

type BackupState

type BackupState string
const (
	BackupStatePending    BackupState = "pending"
	BackupStateRequired   BackupState = "required"
	BackupStateRolledBack BackupState = "rolled_back"
)

type CurrentState

type CurrentState struct {
	State    RecognizedState
	Evidence string
}

func RecognizeCurrentState

func RecognizeCurrentState(repoRoot string, plan *Plan) (CurrentState, error)

type Manager

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

func NewManager

func NewManager(repoRoot string) *Manager

func (*Manager) ActiveForWorkspace

func (m *Manager) ActiveForWorkspace(workspace string) ([]Plan, error)

func (*Manager) CreateActiveForRestore

func (m *Manager) CreateActiveForRestore(preview *restoreplan.Plan, backupPath string) (*Plan, error)

func (*Manager) List

func (m *Manager) List() ([]Plan, error)

func (*Manager) Load

func (m *Manager) Load(planID string) (*Plan, error)

func (*Manager) MarkResolved

func (m *Manager) MarkResolved(planID string) error

func (*Manager) RemoveBackup

func (m *Manager) RemoveBackup(plan *Plan) error

func (*Manager) RemoveBackupPath

func (m *Manager) RemoveBackupPath(plan *Plan, backupPath string) error

func (*Manager) RestoreBackup

func (m *Manager) RestoreBackup(plan *Plan) error

func (*Manager) Write

func (m *Manager) Write(plan *Plan) error

type Operation

type Operation string
const (
	OperationRestore     Operation = "restore"
	OperationRestorePath Operation = "restore_path"
)

type Phase

type Phase string
const (
	PhasePending        Phase = "pending"
	PhaseBackupRequired Phase = "backup_required"
	PhaseRestoreApplied Phase = "restore_applied"
	PhaseBackupRestored Phase = "backup_restored"
)

type Plan

type Plan struct {
	SchemaVersion           int                 `json:"schema_version"`
	RepoID                  string              `json:"repo_id"`
	PlanID                  string              `json:"plan_id"`
	Status                  Status              `json:"status"`
	Operation               Operation           `json:"operation"`
	RestorePlanID           string              `json:"restore_plan_id"`
	Workspace               string              `json:"workspace"`
	Folder                  string              `json:"folder"`
	SourceSavePoint         model.SnapshotID    `json:"source_save_point"`
	Path                    string              `json:"path,omitempty"`
	CreatedAt               time.Time           `json:"created_at"`
	UpdatedAt               time.Time           `json:"updated_at"`
	ResolvedAt              *time.Time          `json:"resolved_at,omitempty"`
	PreWorktreeState        WorktreeState       `json:"pre_worktree_state"`
	Backup                  Backup              `json:"backup"`
	Phase                   Phase               `json:"phase,omitempty"`
	PreRecoveryEvidence     string              `json:"pre_recovery_evidence,omitempty"`
	RecoveryEvidence        string              `json:"recovery_evidence,omitempty"`
	LastError               string              `json:"last_error,omitempty"`
	CompletedSteps          []string            `json:"completed_steps,omitempty"`
	PendingSteps            []string            `json:"pending_steps,omitempty"`
	RecommendedNextCommand  string              `json:"recommended_next_command"`
	CleanupProtectionPinIDs []string            `json:"cleanup_protection_pin_ids,omitempty"`
	CleanupProtectionPins   []model.Pin         `json:"cleanup_protection_pins,omitempty"`
	RestoreOptions          restoreplan.Options `json:"restore_options,omitempty"`
}

type RecognizedState

type RecognizedState string
const (
	RecognizedPlanEvidence          RecognizedState = "plan_evidence"
	RecognizedPreMutation           RecognizedState = "pre_mutation"
	RecognizedRestoreTarget         RecognizedState = "restore_target"
	RecognizedBackupPayloadRestored RecognizedState = "backup_payload_restored"
)

type Status

type Status string
const (
	StatusActive   Status = "active"
	StatusResolved Status = "resolved"
)

type VisiblePlanWriteUncertainError

type VisiblePlanWriteUncertainError struct {
	PlanID string
	Err    error
}

func (*VisiblePlanWriteUncertainError) Error

func (*VisiblePlanWriteUncertainError) Unwrap

type WorktreeState

type WorktreeState struct {
	Name             string            `json:"name"`
	RealPath         string            `json:"real_path,omitempty"`
	BaseSnapshotID   model.SnapshotID  `json:"base_snapshot_id,omitempty"`
	HeadSnapshotID   model.SnapshotID  `json:"head_snapshot_id,omitempty"`
	LatestSnapshotID model.SnapshotID  `json:"latest_snapshot_id,omitempty"`
	PathSources      model.PathSources `json:"path_sources,omitempty"`
	CreatedAt        time.Time         `json:"created_at,omitempty"`
}

func (WorktreeState) WorktreeConfig

func (s WorktreeState) WorktreeConfig() *model.WorktreeConfig

Jump to

Keyboard shortcuts

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