Documentation
¶
Overview ¶
Package checkpoint provides scrollback capture with compression for checkpoints.
Package checkpoint provides checkpoint/restore functionality for NTM sessions. Checkpoints capture the complete state of a session including git state, pane scrollback, and session layout for later restoration.
Index ¶
- Constants
- Variables
- func GenerateID(name string) string
- func VerifyAll(storage *Storage, sessionName string) (map[string]*IntegrityResult, error)
- type AssignmentSnapshot
- type AutoCheckpointConfig
- type AutoCheckpointOptions
- type AutoCheckpointReason
- type AutoCheckpointer
- func (a *AutoCheckpointer) Create(opts AutoCheckpointOptions) (*Checkpoint, error)
- func (a *AutoCheckpointer) GetLastAutoCheckpoint(sessionName string) (*Checkpoint, error)
- func (a *AutoCheckpointer) ListAutoCheckpoints(sessionName string) ([]*Checkpoint, error)
- func (a *AutoCheckpointer) TimeSinceLastAutoCheckpoint(sessionName string) time.Duration
- type AutoEvent
- type AutoEventType
- type BVSnapshot
- type BackgroundWorker
- type Capturer
- func (c *Capturer) Create(sessionName, name string, opts ...CheckpointOption) (*Checkpoint, error)
- func (c *Capturer) FindByPattern(sessionName, pattern string) ([]*Checkpoint, error)
- func (c *Capturer) GetByIndex(sessionName string, index int) (*Checkpoint, error)
- func (c *Capturer) GetLatest(sessionName string) (*Checkpoint, error)
- func (c *Capturer) List(sessionName string) ([]*Checkpoint, error)
- func (c *Capturer) ParseCheckpointRef(sessionName, ref string) (*Checkpoint, error)
- type Checkpoint
- func (c *Checkpoint) Age() time.Duration
- func (c *Checkpoint) GenerateManifest(storage *Storage) (*FileManifest, error)
- func (c *Checkpoint) HasGitPatch() bool
- func (c *Checkpoint) QuickCheck(storage *Storage) error
- func (c *Checkpoint) Summary() string
- func (c *Checkpoint) Verify(storage *Storage) *IntegrityResult
- func (c *Checkpoint) VerifyManifest(storage *Storage, manifest *FileManifest) *IntegrityResult
- type CheckpointOption
- func WithAssignments(capture bool) CheckpointOption
- func WithBVSnapshot(capture bool) CheckpointOption
- func WithDescription(desc string) CheckpointOption
- func WithGitCapture(capture bool) CheckpointOption
- func WithScrollbackCompress(compress bool) CheckpointOption
- func WithScrollbackLines(lines int) CheckpointOption
- func WithScrollbackMaxSizeMB(sizeMB int) CheckpointOption
- type ExportFormat
- type ExportManifest
- type ExportOptions
- type FileManifest
- type GitChange
- type GitState
- type ImportOptions
- type IncrementalChanges
- type IncrementalCheckpoint
- type IncrementalCreator
- type IncrementalResolver
- type IntegrityResult
- type ManifestEntry
- type PaneChange
- type PaneState
- type RestoreOptions
- type RestoreResult
- type Restorer
- func (r *Restorer) Restore(sessionName, checkpointID string, opts RestoreOptions) (*RestoreResult, error)
- func (r *Restorer) RestoreFromCheckpoint(cp *Checkpoint, opts RestoreOptions) (*RestoreResult, error)
- func (r *Restorer) RestoreLatest(sessionName string, opts RestoreOptions) (*RestoreResult, error)
- func (r *Restorer) ValidateCheckpoint(cp *Checkpoint, opts RestoreOptions) []string
- type ScrollbackCapture
- type ScrollbackConfig
- type SessionChange
- type SessionState
- type Storage
- func (s *Storage) CheckpointDir(sessionName, checkpointID string) string
- func (s *Storage) Delete(sessionName, checkpointID string) error
- func (s *Storage) Exists(sessionName, checkpointID string) bool
- func (s *Storage) Export(sessionName, checkpointID string, destPath string, opts ExportOptions) (*ExportManifest, error)
- func (s *Storage) GetLatest(sessionName string) (*Checkpoint, error)
- func (s *Storage) GitPatchPath(sessionName, checkpointID string) string
- func (s *Storage) Import(archivePath string, opts ImportOptions) (*Checkpoint, error)
- func (s *Storage) List(sessionName string) ([]*Checkpoint, error)
- func (s *Storage) ListAll() ([]*Checkpoint, error)
- func (s *Storage) Load(sessionName, checkpointID string) (*Checkpoint, error)
- func (s *Storage) LoadCompressedScrollback(sessionName, checkpointID, paneID string) (string, error)
- func (s *Storage) LoadGitPatch(sessionName, checkpointID string) (string, error)
- func (s *Storage) LoadScrollback(sessionName, checkpointID string, paneID string) (string, error)
- func (s *Storage) PanesDirPath(sessionName, checkpointID string) string
- func (s *Storage) Save(cp *Checkpoint) error
- func (s *Storage) SaveCompressedScrollback(sessionName, checkpointID, paneID string, data []byte) (string, error)
- func (s *Storage) SaveGitPatch(sessionName, checkpointID, patch string) error
- func (s *Storage) SaveGitStatus(sessionName, checkpointID, status string) error
- func (s *Storage) SaveScrollback(sessionName, checkpointID string, paneID string, content string) (string, error)
- type WorkerRegistry
- func (r *WorkerRegistry) GetWorker(sessionName string) *BackgroundWorker
- func (r *WorkerRegistry) SendEvent(sessionName string, event AutoEvent)
- func (r *WorkerRegistry) StartWorker(ctx context.Context, sessionName string, config AutoCheckpointConfig)
- func (r *WorkerRegistry) StopAll()
- func (r *WorkerRegistry) StopWorker(sessionName string)
Constants ¶
const ( // IncrementalVersion is the current incremental checkpoint format version IncrementalVersion = 1 // IncrementalMetadataFile is the filename for incremental checkpoint metadata IncrementalMetadataFile = "incremental.json" // IncrementalPatchFile is the filename for git diff from base IncrementalPatchFile = "incremental.patch" // DiffPanesDir is the subdirectory for pane scrollback diffs DiffPanesDir = "pane_diffs" )
const ( // DefaultCheckpointDir is the default directory for checkpoints DefaultCheckpointDir = ".local/share/ntm/checkpoints" // MetadataFile is the name of the checkpoint metadata file MetadataFile = "metadata.json" // SessionFile is the name of the session state file SessionFile = "session.json" // GitPatchFile is the name of the git diff patch file GitPatchFile = "git.patch" // GitStatusFile is the name of the git status file GitStatusFile = "git-status.txt" // PanesDir is the subdirectory for pane scrollback captures PanesDir = "panes" )
const (
// AutoCheckpointPrefix is the prefix for auto-generated checkpoint names
AutoCheckpointPrefix = "auto"
)
const CurrentVersion = 1
CurrentVersion is the current checkpoint format version.
const MaxGitOutputBytes = 10 * 1024 * 1024
MaxGitOutputBytes limits the size of git command output to prevent OOM. 10MB is sufficient for most status/diff operations while preventing abuse.
const MinVersion = 1
MinVersion is the minimum supported checkpoint format version.
Variables ¶
var ( ErrSessionExists = errors.New("session already exists (use Force option to override)") ErrDirectoryNotFound = errors.New("checkpoint working directory not found") ErrNoAgentsToRestore = errors.New("checkpoint contains no agents to restore") )
Restore errors
Functions ¶
func GenerateID ¶
GenerateID creates a unique checkpoint ID from timestamp and name.
Types ¶
type AssignmentSnapshot ¶
type AssignmentSnapshot struct {
// BeadID is the assigned bead identifier
BeadID string `json:"bead_id"`
// BeadTitle is the bead title for display
BeadTitle string `json:"bead_title"`
// Pane is the pane index where the agent is working
Pane int `json:"pane"`
// AgentType is the agent type (cc, cod, gmi)
AgentType string `json:"agent_type"`
// AgentName is the Agent Mail name if registered
AgentName string `json:"agent_name,omitempty"`
// Status is the assignment status (assigned, working, completed, failed)
Status string `json:"status"`
// AssignedAt is when the bead was assigned
AssignedAt time.Time `json:"assigned_at"`
}
AssignmentSnapshot captures bead assignment state for checkpointing. This is a simplified view of assignment.Assignment for checkpoint storage.
type AutoCheckpointConfig ¶
type AutoCheckpointConfig struct {
Enabled bool // Master toggle
IntervalMinutes int // Periodic checkpoint interval (0 = disabled)
MaxCheckpoints int // Max auto-checkpoints per session
OnRotation bool // Checkpoint before rotation
OnError bool // Checkpoint on error
ScrollbackLines int // Lines of scrollback to capture
IncludeGit bool // Capture git state
}
AutoCheckpointConfig configures the background auto-checkpoint worker
type AutoCheckpointOptions ¶
type AutoCheckpointOptions struct {
SessionName string
Reason AutoCheckpointReason
Description string // Additional context
ScrollbackLines int
IncludeGit bool
MaxCheckpoints int // Max auto-checkpoints to keep (rotation)
}
AutoCheckpointOptions configures auto-checkpoint creation
type AutoCheckpointReason ¶
type AutoCheckpointReason string
AutoCheckpointReason describes why an auto-checkpoint was triggered
const ( ReasonBroadcast AutoCheckpointReason = "broadcast" // Before sending to all agents ReasonAddAgents AutoCheckpointReason = "add_agents" // Before adding many agents ReasonSpawn AutoCheckpointReason = "spawn" // After spawning session ReasonRiskyOp AutoCheckpointReason = "risky_op" // Before other risky operation ReasonInterval AutoCheckpointReason = "interval" // Periodic interval checkpoint ReasonRotation AutoCheckpointReason = "rotation" // Before context rotation ReasonError AutoCheckpointReason = "error" // On agent error )
type AutoCheckpointer ¶
type AutoCheckpointer struct {
// contains filtered or unexported fields
}
AutoCheckpointer handles automatic checkpoint creation with rotation
func NewAutoCheckpointer ¶
func NewAutoCheckpointer() *AutoCheckpointer
NewAutoCheckpointer creates a new auto-checkpointer
func (*AutoCheckpointer) Create ¶
func (a *AutoCheckpointer) Create(opts AutoCheckpointOptions) (*Checkpoint, error)
Create creates an auto-checkpoint with the given options It returns the created checkpoint and any error encountered
func (*AutoCheckpointer) GetLastAutoCheckpoint ¶
func (a *AutoCheckpointer) GetLastAutoCheckpoint(sessionName string) (*Checkpoint, error)
GetLastAutoCheckpoint returns the most recent auto-checkpoint for a session
func (*AutoCheckpointer) ListAutoCheckpoints ¶
func (a *AutoCheckpointer) ListAutoCheckpoints(sessionName string) ([]*Checkpoint, error)
ListAutoCheckpoints returns all auto-checkpoints for a session
func (*AutoCheckpointer) TimeSinceLastAutoCheckpoint ¶
func (a *AutoCheckpointer) TimeSinceLastAutoCheckpoint(sessionName string) time.Duration
TimeSinceLastAutoCheckpoint returns the duration since the last auto-checkpoint Returns 0 if no auto-checkpoint exists
type AutoEvent ¶
type AutoEvent struct {
Type AutoEventType
SessionName string
AgentID string // Which agent triggered the event
Description string // Additional context
}
AutoEvent represents an event that can trigger an auto-checkpoint
type AutoEventType ¶
type AutoEventType int
AutoEventType describes the type of event that triggered an auto-checkpoint
const ( EventRotation AutoEventType = iota // Context rotation is about to happen EventError // Agent error detected )
type BVSnapshot ¶
type BVSnapshot struct {
// OpenCount is the number of open beads
OpenCount int `json:"open_count"`
// ActionableCount is beads ready for work (unblocked)
ActionableCount int `json:"actionable_count"`
// BlockedCount is beads blocked by dependencies
BlockedCount int `json:"blocked_count"`
// InProgressCount is beads currently being worked
InProgressCount int `json:"in_progress_count"`
// TopPicks contains IDs of top recommended beads
TopPicks []string `json:"top_picks,omitempty"`
// CapturedAt is when the BV snapshot was taken
CapturedAt time.Time `json:"captured_at"`
}
BVSnapshot captures BV triage state at checkpoint time.
type BackgroundWorker ¶
type BackgroundWorker struct {
// contains filtered or unexported fields
}
BackgroundWorker runs automatic checkpoints in the background based on interval and event triggers.
func NewBackgroundWorker ¶
func NewBackgroundWorker(sessionName string, config AutoCheckpointConfig) *BackgroundWorker
NewBackgroundWorker creates a new background checkpoint worker.
func (*BackgroundWorker) SendEvent ¶
func (w *BackgroundWorker) SendEvent(event AutoEvent)
SendEvent sends an event to the worker to potentially trigger a checkpoint.
func (*BackgroundWorker) Start ¶
func (w *BackgroundWorker) Start(ctx context.Context)
Start begins the background checkpoint worker. It will run until Stop is called or the context is cancelled.
func (*BackgroundWorker) Stats ¶
func (w *BackgroundWorker) Stats() (checkpointCount int, lastCheckpoint time.Time, lastError error)
Stats returns statistics about the worker.
func (*BackgroundWorker) Stop ¶
func (w *BackgroundWorker) Stop()
Stop stops the background checkpoint worker gracefully.
type Capturer ¶
type Capturer struct {
// contains filtered or unexported fields
}
Capturer handles capturing session state for checkpoints.
func NewCapturer ¶
func NewCapturer() *Capturer
NewCapturer creates a new Capturer with the default storage.
func NewCapturerWithStorage ¶
NewCapturerWithStorage creates a Capturer with a custom storage.
func (*Capturer) Create ¶
func (c *Capturer) Create(sessionName, name string, opts ...CheckpointOption) (*Checkpoint, error)
Create creates a new checkpoint for the given session.
func (*Capturer) FindByPattern ¶
func (c *Capturer) FindByPattern(sessionName, pattern string) ([]*Checkpoint, error)
FindByPattern finds checkpoints matching a pattern (prefix match or exact).
func (*Capturer) GetByIndex ¶
func (c *Capturer) GetByIndex(sessionName string, index int) (*Checkpoint, error)
GetByIndex returns the Nth most recent checkpoint (1-indexed, 1 = latest).
func (*Capturer) GetLatest ¶
func (c *Capturer) GetLatest(sessionName string) (*Checkpoint, error)
GetLatest returns the most recent checkpoint for a session.
func (*Capturer) List ¶
func (c *Capturer) List(sessionName string) ([]*Checkpoint, error)
List returns all checkpoints for a session.
func (*Capturer) ParseCheckpointRef ¶
func (c *Capturer) ParseCheckpointRef(sessionName, ref string) (*Checkpoint, error)
ParseCheckpointRef parses a checkpoint reference which can be: - A checkpoint ID (timestamp-name) - A checkpoint name - "~N" for Nth most recent (e.g., "~1" = latest, "~2" = second latest) - "last" or "latest" for the most recent
type Checkpoint ¶
type Checkpoint struct {
// Version is the checkpoint format version (for compatibility)
Version int `json:"version"`
// ID is the unique identifier (timestamp-based)
ID string `json:"id"`
// Name is the user-provided checkpoint name
Name string `json:"name"`
// Description is an optional user description
Description string `json:"description,omitempty"`
// SessionName is the tmux session this checkpoint belongs to
SessionName string `json:"session_name"`
// WorkingDir is the working directory at checkpoint time
WorkingDir string `json:"working_dir"`
// CreatedAt is when the checkpoint was created
CreatedAt time.Time `json:"created_at"`
// Session contains the captured session state
Session SessionState `json:"session"`
// Git contains the captured git state
Git GitState `json:"git,omitempty"`
// PaneCount is the number of panes captured
PaneCount int `json:"pane_count"`
// Assignments contains bead-to-agent assignment state at checkpoint time (bd-32ck)
// This field is optional for backward compatibility with older checkpoints.
Assignments []AssignmentSnapshot `json:"assignments,omitempty"`
// BVSummary contains BV triage summary at checkpoint time (bd-32ck)
// This field is optional for backward compatibility with older checkpoints.
BVSummary *BVSnapshot `json:"bv_summary,omitempty"`
}
Checkpoint represents a saved session state.
func (*Checkpoint) Age ¶
func (c *Checkpoint) Age() time.Duration
Age returns how long ago the checkpoint was created.
func (*Checkpoint) GenerateManifest ¶
func (c *Checkpoint) GenerateManifest(storage *Storage) (*FileManifest, error)
GenerateManifest creates a manifest with checksums for all checkpoint files.
func (*Checkpoint) HasGitPatch ¶
func (c *Checkpoint) HasGitPatch() bool
HasGitPatch returns true if a git patch file exists.
func (*Checkpoint) QuickCheck ¶
func (c *Checkpoint) QuickCheck(storage *Storage) error
QuickCheck performs a fast validation without reading file contents.
func (*Checkpoint) Summary ¶
func (c *Checkpoint) Summary() string
Summary returns a brief summary of the checkpoint.
func (*Checkpoint) Verify ¶
func (c *Checkpoint) Verify(storage *Storage) *IntegrityResult
Verify performs all integrity checks on a checkpoint.
func (*Checkpoint) VerifyManifest ¶
func (c *Checkpoint) VerifyManifest(storage *Storage, manifest *FileManifest) *IntegrityResult
VerifyManifest checks that all files match the manifest checksums.
type CheckpointOption ¶
type CheckpointOption func(*checkpointOptions)
CheckpointOption configures checkpoint creation.
func WithAssignments ¶
func WithAssignments(capture bool) CheckpointOption
WithAssignments enables/disables capturing bead-to-agent assignments (bd-32ck).
func WithBVSnapshot ¶
func WithBVSnapshot(capture bool) CheckpointOption
WithBVSnapshot enables/disables capturing BV triage summary (bd-32ck).
func WithDescription ¶
func WithDescription(desc string) CheckpointOption
WithDescription sets the checkpoint description.
func WithGitCapture ¶
func WithGitCapture(capture bool) CheckpointOption
WithGitCapture enables/disables git state capture.
func WithScrollbackCompress ¶
func WithScrollbackCompress(compress bool) CheckpointOption
WithScrollbackCompress enables/disables gzip compression for scrollback.
func WithScrollbackLines ¶
func WithScrollbackLines(lines int) CheckpointOption
WithScrollbackLines sets the number of scrollback lines to capture.
func WithScrollbackMaxSizeMB ¶
func WithScrollbackMaxSizeMB(sizeMB int) CheckpointOption
WithScrollbackMaxSizeMB sets the maximum compressed scrollback size in MB. Scrollback larger than this will be skipped. 0 = no limit.
type ExportFormat ¶
type ExportFormat string
ExportFormat specifies the archive format for export.
const ( FormatTarGz ExportFormat = "tar.gz" FormatZip ExportFormat = "zip" )
type ExportManifest ¶
type ExportManifest struct {
Version int `json:"version"`
ExportedAt time.Time `json:"exported_at"`
SessionName string `json:"session_name"`
CheckpointID string `json:"checkpoint_id"`
CheckpointName string `json:"checkpoint_name"`
OriginalPath string `json:"original_path"`
Files []ManifestEntry `json:"files"`
Checksums map[string]string `json:"checksums"`
}
ExportManifest contains metadata about an exported checkpoint.
type ExportOptions ¶
type ExportOptions struct {
// Format specifies the archive format (default: tar.gz)
Format ExportFormat
// RedactSecrets removes potential secrets from scrollback
RedactSecrets bool
// RewritePaths makes paths portable across machines
RewritePaths bool
// IncludeScrollback includes scrollback files in export
IncludeScrollback bool
// IncludeGitPatch includes git patch file in export
IncludeGitPatch bool
}
ExportOptions configures checkpoint export.
func DefaultExportOptions ¶
func DefaultExportOptions() ExportOptions
DefaultExportOptions returns sensible defaults for export.
type FileManifest ¶
type FileManifest struct {
// Files maps relative paths to SHA256 hex hashes.
Files map[string]string `json:"files"`
// CreatedAt is when the manifest was generated.
CreatedAt string `json:"created_at,omitempty"`
}
FileManifest contains checksums for all checkpoint files.
type GitChange ¶
type GitChange struct {
// FromCommit is the base checkpoint's commit
FromCommit string `json:"from_commit"`
// ToCommit is the current commit
ToCommit string `json:"to_commit"`
// Branch may have changed
Branch string `json:"branch,omitempty"`
// PatchFile is the relative path to the incremental patch
PatchFile string `json:"patch_file,omitempty"`
// IsDirty indicates uncommitted changes
IsDirty bool `json:"is_dirty"`
// StagedCount changed
StagedCount int `json:"staged_count"`
// UnstagedCount changed
UnstagedCount int `json:"unstaged_count"`
// UntrackedCount changed
UntrackedCount int `json:"untracked_count"`
}
GitChange represents changes to git state since the base checkpoint.
type GitState ¶
type GitState struct {
// Branch is the current branch name
Branch string `json:"branch"`
// Commit is the current HEAD commit SHA
Commit string `json:"commit"`
// IsDirty indicates uncommitted changes exist
IsDirty bool `json:"is_dirty"`
// PatchFile is the relative path to the git diff patch
PatchFile string `json:"patch_file,omitempty"`
// StagedCount is the number of staged files
StagedCount int `json:"staged_count"`
// UnstagedCount is the number of modified but unstaged files
UnstagedCount int `json:"unstaged_count"`
// UntrackedCount is the number of untracked files
UntrackedCount int `json:"untracked_count"`
}
GitState captures the git repository state at checkpoint time.
type ImportOptions ¶
type ImportOptions struct {
// TargetSession overrides the session name on import
TargetSession string
// TargetDir overrides the working directory on import
TargetDir string
// VerifyChecksums validates file integrity on import
VerifyChecksums bool
// AllowOverwrite permits overwriting existing checkpoints
AllowOverwrite bool
}
ImportOptions configures checkpoint import.
func DefaultImportOptions ¶
func DefaultImportOptions() ImportOptions
DefaultImportOptions returns sensible defaults for import.
type IncrementalChanges ¶
type IncrementalChanges struct {
// PaneChanges maps pane ID to its changes
PaneChanges map[string]PaneChange `json:"pane_changes,omitempty"`
// GitChange holds changes to git state
GitChange *GitChange `json:"git_change,omitempty"`
// SessionChange holds changes to session layout
SessionChange *SessionChange `json:"session_change,omitempty"`
}
IncrementalChanges holds all the changed data since the base checkpoint.
type IncrementalCheckpoint ¶
type IncrementalCheckpoint struct {
// Version is the incremental checkpoint format version
Version int `json:"version"`
// ID is the unique identifier for this incremental
ID string `json:"id"`
// SessionName is the tmux session this belongs to
SessionName string `json:"session_name"`
// BaseCheckpointID is the ID of the full checkpoint this is based on
BaseCheckpointID string `json:"base_checkpoint_id"`
// BaseTimestamp is when the base checkpoint was created
BaseTimestamp time.Time `json:"base_timestamp"`
// CreatedAt is when this incremental was created
CreatedAt time.Time `json:"created_at"`
// Description is an optional description
Description string `json:"description,omitempty"`
// Changes holds the differential data
Changes IncrementalChanges `json:"changes"`
}
IncrementalCheckpoint represents a differential checkpoint that stores only changes from a base checkpoint. This saves storage space for frequent checkpoints.
func (*IncrementalCheckpoint) StorageSavings ¶
func (inc *IncrementalCheckpoint) StorageSavings(storage *Storage) (savedBytes int64, percentSaved float64, err error)
StorageSavings calculates the approximate storage savings of an incremental checkpoint.
type IncrementalCreator ¶
type IncrementalCreator struct {
// contains filtered or unexported fields
}
IncrementalCreator creates incremental checkpoints from a base.
func NewIncrementalCreator ¶
func NewIncrementalCreator() *IncrementalCreator
NewIncrementalCreator creates a new incremental checkpoint creator.
func NewIncrementalCreatorWithStorage ¶
func NewIncrementalCreatorWithStorage(storage *Storage) *IncrementalCreator
NewIncrementalCreatorWithStorage creates an incremental creator with custom storage.
func (*IncrementalCreator) Create ¶
func (ic *IncrementalCreator) Create(sessionName, name string, baseCheckpointID string) (*IncrementalCheckpoint, error)
Create creates an incremental checkpoint based on the given base checkpoint. It computes the diff between the current session state and the base checkpoint.
type IncrementalResolver ¶
type IncrementalResolver struct {
// contains filtered or unexported fields
}
IncrementalResolver resolves an incremental checkpoint to a full checkpoint.
func NewIncrementalResolver ¶
func NewIncrementalResolver() *IncrementalResolver
NewIncrementalResolver creates a new resolver.
func NewIncrementalResolverWithStorage ¶
func NewIncrementalResolverWithStorage(storage *Storage) *IncrementalResolver
NewIncrementalResolverWithStorage creates a resolver with custom storage.
func (*IncrementalResolver) ChainResolve ¶
func (ir *IncrementalResolver) ChainResolve(sessionName, incrementalID string) (*Checkpoint, error)
ChainResolve resolves a chain of incremental checkpoints. Given an incremental that may be based on another incremental (not a full checkpoint), this function walks the chain back to find the base full checkpoint and applies all incrementals in order.
func (*IncrementalResolver) ListIncrementals ¶
func (ir *IncrementalResolver) ListIncrementals(sessionName string) ([]*IncrementalCheckpoint, error)
ListIncrementals returns all incremental checkpoints for a session.
func (*IncrementalResolver) Resolve ¶
func (ir *IncrementalResolver) Resolve(sessionName, incrementalID string) (*Checkpoint, error)
Resolve applies an incremental checkpoint to its base to produce a full checkpoint.
type IntegrityResult ¶
type IntegrityResult struct {
// Valid is true if all checks passed.
Valid bool `json:"valid"`
// SchemaValid indicates if the schema is valid.
SchemaValid bool `json:"schema_valid"`
// FilesPresent indicates if all referenced files exist.
FilesPresent bool `json:"files_present"`
// ChecksumsValid indicates if all checksums match (if manifest exists).
ChecksumsValid bool `json:"checksums_valid"`
// ConsistencyValid indicates if internal consistency checks pass.
ConsistencyValid bool `json:"consistency_valid"`
// Errors contains any validation errors.
Errors []string `json:"errors,omitempty"`
// Warnings contains non-fatal issues.
Warnings []string `json:"warnings,omitempty"`
// Details contains detailed check results.
Details map[string]string `json:"details,omitempty"`
// Manifest contains file checksums for verification.
Manifest *FileManifest `json:"manifest,omitempty"`
}
IntegrityResult contains the results of checkpoint verification.
type ManifestEntry ¶
type ManifestEntry struct {
Path string `json:"path"`
Size int64 `json:"size"`
Checksum string `json:"checksum"`
}
ManifestEntry describes a file in the export.
type PaneChange ¶
type PaneChange struct {
// NewLines is the number of new lines added since base
NewLines int `json:"new_lines"`
// DiffFile is the relative path to the scrollback diff file
DiffFile string `json:"diff_file,omitempty"`
// DiffContent is the new scrollback content (lines after base)
DiffContent string `json:"-"` // Not serialized, held in memory during processing
// Compressed is the compressed diff content
Compressed []byte `json:"-"`
// AgentType may have changed
AgentType string `json:"agent_type,omitempty"`
// Title may have changed
Title string `json:"title,omitempty"`
// Removed indicates pane was removed
Removed bool `json:"removed,omitempty"`
// Added indicates pane is new (not in base)
Added bool `json:"added,omitempty"`
}
PaneChange represents changes to a single pane since the base checkpoint.
type PaneState ¶
type PaneState struct {
// Index is the pane index in the session
Index int `json:"index"`
// ID is the tmux pane ID (e.g., "%0")
ID string `json:"id"`
// Title is the pane title
Title string `json:"title"`
// AgentType is the detected agent type ("cc", "cod", "gmi", "user")
AgentType string `json:"agent_type"`
// Command is the running command
Command string `json:"command,omitempty"`
// Width is the pane width in columns
Width int `json:"width"`
// Height is the pane height in rows
Height int `json:"height"`
// ScrollbackFile is the relative path to scrollback capture
ScrollbackFile string `json:"scrollback_file,omitempty"`
// ScrollbackLines is the number of lines captured
ScrollbackLines int `json:"scrollback_lines"`
}
PaneState captures the state of a single pane.
func FromTmuxPane ¶
FromTmuxPane converts a tmux.Pane to PaneState.
type RestoreOptions ¶
type RestoreOptions struct {
// Force kills any existing session with the same name
Force bool
// SkipGitCheck skips warning about git state mismatch
SkipGitCheck bool
// InjectContext sends scrollback/summary to agents after spawning
InjectContext bool
// DryRun shows what would be done without making changes
DryRun bool
// CustomDirectory overrides the checkpoint's working directory
CustomDirectory string
// ScrollbackLines is how many lines of scrollback to inject (0 = all captured)
ScrollbackLines int
}
RestoreOptions configures how a checkpoint is restored.
type RestoreResult ¶
type RestoreResult struct {
// SessionName is the restored session name
SessionName string
// PanesRestored is the number of panes created
PanesRestored int
// ContextInjected indicates if scrollback was sent to agents
ContextInjected bool
// Warnings contains non-fatal issues encountered
Warnings []string
// DryRun indicates this was a simulation
DryRun bool
}
RestoreResult contains details about what was restored.
type Restorer ¶
type Restorer struct {
// contains filtered or unexported fields
}
Restorer handles checkpoint restoration.
func NewRestorer ¶
func NewRestorer() *Restorer
NewRestorer creates a new Restorer with default storage.
func NewRestorerWithStorage ¶
NewRestorerWithStorage creates a Restorer with custom storage.
func (*Restorer) Restore ¶
func (r *Restorer) Restore(sessionName, checkpointID string, opts RestoreOptions) (*RestoreResult, error)
Restore restores a session from a checkpoint.
func (*Restorer) RestoreFromCheckpoint ¶
func (r *Restorer) RestoreFromCheckpoint(cp *Checkpoint, opts RestoreOptions) (*RestoreResult, error)
RestoreFromCheckpoint restores a session from a loaded checkpoint.
func (*Restorer) RestoreLatest ¶
func (r *Restorer) RestoreLatest(sessionName string, opts RestoreOptions) (*RestoreResult, error)
RestoreLatest restores the most recent checkpoint for a session.
func (*Restorer) ValidateCheckpoint ¶
func (r *Restorer) ValidateCheckpoint(cp *Checkpoint, opts RestoreOptions) []string
ValidateCheckpoint checks if a checkpoint can be restored.
type ScrollbackCapture ¶
type ScrollbackCapture struct {
// PaneID is the tmux pane identifier
PaneID string
// Lines is the number of lines captured
Lines int
// Content is the raw scrollback content
Content string
// Compressed is the gzip-compressed content
Compressed []byte
// Size is the size of the compressed content in bytes
Size int64
// Skipped indicates if capture was skipped (e.g., due to size limits)
Skipped bool
// SkipReason explains why capture was skipped
SkipReason string
}
ScrollbackCapture holds the captured scrollback data for a pane.
func CaptureScrollback ¶
func CaptureScrollback(session, paneID string, config ScrollbackConfig) (*ScrollbackCapture, error)
CaptureScrollback captures scrollback from a tmux pane with optional compression.
func CaptureScrollbackContext ¶
func CaptureScrollbackContext(ctx context.Context, session, paneID string, config ScrollbackConfig) (*ScrollbackCapture, error)
CaptureScrollbackContext captures scrollback with context for cancellation.
type ScrollbackConfig ¶
type ScrollbackConfig struct {
// Lines is the number of lines to capture (default 5000)
Lines int
// Compress enables gzip compression (default true)
Compress bool
// MaxSizeMB is the maximum size in megabytes (0 = no limit)
MaxSizeMB int
// Timeout is the capture timeout (default 30s)
Timeout time.Duration
}
ScrollbackConfig holds configuration for scrollback capture.
func DefaultScrollbackConfig ¶
func DefaultScrollbackConfig() ScrollbackConfig
DefaultScrollbackConfig returns the default scrollback configuration.
type SessionChange ¶
type SessionChange struct {
// Layout changed
Layout string `json:"layout,omitempty"`
// ActivePaneIndex changed
ActivePaneIndex int `json:"active_pane_index,omitempty"`
// PaneCount changed
PaneCount int `json:"pane_count,omitempty"`
}
SessionChange represents changes to session layout.
type SessionState ¶
type SessionState struct {
// Panes contains info about each pane in the session
Panes []PaneState `json:"panes"`
// Layout is the tmux layout string for restoration
Layout string `json:"layout,omitempty"`
// ActivePaneIndex is the currently selected pane
ActivePaneIndex int `json:"active_pane_index"`
}
SessionState captures the tmux session layout and agents.
type Storage ¶
type Storage struct {
// BaseDir is the base directory for all checkpoints
BaseDir string
}
Storage manages checkpoint storage on disk.
func NewStorage ¶
func NewStorage() *Storage
NewStorage creates a new Storage with the default directory. Falls back to /tmp if the user's home directory cannot be determined.
func NewStorageWithDir ¶
NewStorageWithDir creates a Storage with a custom directory.
func (*Storage) CheckpointDir ¶
CheckpointDir returns the directory path for a specific checkpoint.
func (*Storage) Export ¶
func (s *Storage) Export(sessionName, checkpointID string, destPath string, opts ExportOptions) (*ExportManifest, error)
Export creates a portable archive of a checkpoint.
func (*Storage) GetLatest ¶
func (s *Storage) GetLatest(sessionName string) (*Checkpoint, error)
GetLatest returns the most recent checkpoint for a session.
func (*Storage) GitPatchPath ¶
GitPatchPath returns the file path for the git patch.
func (*Storage) Import ¶
func (s *Storage) Import(archivePath string, opts ImportOptions) (*Checkpoint, error)
Import loads a checkpoint from an exported archive.
func (*Storage) List ¶
func (s *Storage) List(sessionName string) ([]*Checkpoint, error)
List returns all checkpoints for a session, sorted by creation time (newest first).
func (*Storage) ListAll ¶
func (s *Storage) ListAll() ([]*Checkpoint, error)
ListAll returns all checkpoints across all sessions.
func (*Storage) Load ¶
func (s *Storage) Load(sessionName, checkpointID string) (*Checkpoint, error)
Load reads a checkpoint from disk.
func (*Storage) LoadCompressedScrollback ¶
func (s *Storage) LoadCompressedScrollback(sessionName, checkpointID, paneID string) (string, error)
LoadCompressedScrollback reads and decompresses scrollback from a file.
func (*Storage) LoadGitPatch ¶
LoadGitPatch reads the git diff patch from the checkpoint.
func (*Storage) LoadScrollback ¶
LoadScrollback reads pane scrollback from a file.
func (*Storage) PanesDirPath ¶
PanesDir returns the panes subdirectory for a checkpoint.
func (*Storage) Save ¶
func (s *Storage) Save(cp *Checkpoint) error
Save writes a checkpoint to disk.
func (*Storage) SaveCompressedScrollback ¶
func (s *Storage) SaveCompressedScrollback(sessionName, checkpointID, paneID string, data []byte) (string, error)
SaveCompressedScrollback saves compressed scrollback to a file.
func (*Storage) SaveGitPatch ¶
SaveGitPatch writes the git diff patch to the checkpoint.
func (*Storage) SaveGitStatus ¶
SaveGitStatus writes the git status output to the checkpoint.
type WorkerRegistry ¶
type WorkerRegistry struct {
// contains filtered or unexported fields
}
WorkerRegistry manages background workers for multiple sessions.
func NewWorkerRegistry ¶
func NewWorkerRegistry() *WorkerRegistry
NewWorkerRegistry creates a new worker registry.
func (*WorkerRegistry) GetWorker ¶
func (r *WorkerRegistry) GetWorker(sessionName string) *BackgroundWorker
GetWorker returns the worker for a session, or nil if not found.
func (*WorkerRegistry) SendEvent ¶
func (r *WorkerRegistry) SendEvent(sessionName string, event AutoEvent)
SendEvent sends an event to the worker for a specific session. Does nothing if no worker exists for the session.
func (*WorkerRegistry) StartWorker ¶
func (r *WorkerRegistry) StartWorker(ctx context.Context, sessionName string, config AutoCheckpointConfig)
StartWorker starts a background worker for a session. If a worker already exists for the session, it is stopped first.
func (*WorkerRegistry) StopAll ¶
func (r *WorkerRegistry) StopAll()
StopAll stops all background workers.
func (*WorkerRegistry) StopWorker ¶
func (r *WorkerRegistry) StopWorker(sessionName string)
StopWorker stops the background worker for a session.