checkpoint

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package checkpoint provides mid-execution checkpointing for PM mode. Before each task starts, a checkpoint.json is written so that an interrupted run can resume from where it stopped rather than restarting or skipping.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear(workDir string) error

Clear removes the checkpoint file. Silently succeeds if no file exists.

func Exists

func Exists(workDir string) bool

Exists reports whether a checkpoint file is present.

func HashOutput

func HashOutput(s string) string

HashOutput returns the SHA-256 hex digest of s, or "" for empty strings.

func Path

func Path(workDir string) string

Path returns the absolute path to the checkpoint file under workDir.

func Save

func Save(workDir string, cp *Checkpoint) error

Save writes the checkpoint atomically (stage in a sibling .tmp file, fsync, then rename into place). The fsync closes a window where a power loss between WriteFile and Rename could leave the rename target pointing at zero-length data on some filesystems.

func SaveHistoryEntry

func SaveHistoryEntry(workDir string, cp *Checkpoint) error

SaveHistoryEntry appends a timestamped checkpoint entry for a task. Files are named <unix-nano>.json inside .cloop/task-checkpoints/task-<id>/.

The write is atomic — staged in a sibling .tmp file, fsynced, then renamed into place. Without this, a crash mid-write would leave a truncated JSON file that ListHistory silently skips on the next load, dropping the progress record permanently.

Types

type Checkpoint

type Checkpoint struct {
	TaskID            int       `json:"task_id"`
	TaskTitle         string    `json:"task_title"`
	StepNumber        int       `json:"step_number"`
	AccumulatedOutput string    `json:"accumulated_output,omitempty"`
	StartTimestamp    time.Time `json:"start_timestamp"`
	Provider          string    `json:"provider,omitempty"`
	// Metadata for checkpoint-diff
	Event        string    `json:"event,omitempty"`         // "start", "complete", "fail", "skip"
	Status       string    `json:"status,omitempty"`        // task status at checkpoint time
	OutputHash   string    `json:"output_hash,omitempty"`   // SHA-256 hex of AccumulatedOutput
	OutputLength int       `json:"output_length,omitempty"` // len(AccumulatedOutput)
	TokenCount   int       `json:"token_count,omitempty"`   // total tokens used so far
	ElapsedSec   float64   `json:"elapsed_sec,omitempty"`   // seconds since task start
	Timestamp    time.Time `json:"timestamp,omitempty"`     // wall-clock time of this entry
}

Checkpoint holds the mid-execution state for a single in-progress task.

func Load

func Load(workDir string) (*Checkpoint, error)

Load reads the checkpoint file. Returns (nil, nil) if no file exists.

On parse failure (zero-byte file, schema drift from an older binary, manual edit gone wrong) the corrupt file is quarantined aside as checkpoint.json.corrupt-<unix> and (nil, nil) is returned. Losing the in-progress checkpoint is preferable to refusing to start a new run — and the user has the bytes preserved next to it for forensics.

func LoadHistoryEntry

func LoadHistoryEntry(workDir string, taskID int, id string) (*Checkpoint, error)

LoadHistoryEntry loads a single checkpoint history entry by its ID.

type HistoryEntry

type HistoryEntry struct {
	ID         string // the unix-nano filename stem
	Checkpoint *Checkpoint
}

HistoryEntry wraps a Checkpoint with its on-disk ID.

func ListHistory

func ListHistory(workDir string, taskID int) ([]*HistoryEntry, error)

ListHistory returns all checkpoint history entries for a task, sorted oldest-first.

Jump to

Keyboard shortcuts

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