run

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package run provides run management and state persistence.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListAllRepos

func ListAllRepos(paths *config.Paths) ([]string, error)

ListAllRepos returns all repository IDs with runs.

Types

type EntryType

type EntryType string

EntryType represents the type of transcript entry.

const (
	EntryTypeStart     EntryType = "start"
	EntryTypeIteration EntryType = "iteration"
	EntryTypeMessage   EntryType = "message"
	EntryTypeExecute   EntryType = "execute"
	EntryTypeResult    EntryType = "result"
	EntryTypeSignal    EntryType = "signal"
	EntryTypeState     EntryType = "state"
	EntryTypeError     EntryType = "error"
	EntryTypeEnd       EntryType = "end"
)

type Manager

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

Manager handles run lifecycle and persistence.

func NewManager

func NewManager(paths *config.Paths, repoPath string) *Manager

NewManager creates a new run manager.

func (*Manager) Create

func (m *Manager) Create(prompt string, cfg *config.Config) (*Run, error)

Create creates a new run.

func (*Manager) FindBySessionID

func (m *Manager) FindBySessionID(sessionID string) (*Run, error)

FindBySessionID finds a run by agent session ID.

func (*Manager) List

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

List returns all run IDs for the repository.

func (*Manager) ListActive

func (m *Manager) ListActive() ([]*Manifest, error)

ListActive returns all active (non-complete) runs.

func (*Manager) Load

func (m *Manager) Load(runID int) (*Run, error)

Load loads an existing run by ID.

type Manifest

type Manifest struct {
	// ID is the run identifier.
	ID int `json:"id"`

	// RepoPath is the path to the repository.
	RepoPath string `json:"repo_path"`

	// RepoID is the hashed repository identifier.
	RepoID string `json:"repo_id"`

	// Prompt is the initial task prompt.
	Prompt string `json:"prompt"`

	// State is the current run state.
	State State `json:"state"`

	// PrimaryAgent is the main worker agent.
	PrimaryAgent string `json:"primary_agent"`

	// ReviewMode is the review configuration.
	ReviewMode string `json:"review_mode"`

	// MaxIterations is the iteration limit.
	MaxIterations int `json:"max_iterations"`

	// CurrentIteration is the current iteration number.
	CurrentIteration int `json:"current_iteration"`

	// ClaudeSessionID is Claude's session ID for resume.
	ClaudeSessionID string `json:"claude_session_id,omitempty"`

	// CodexSessionID is Codex's session ID for resume.
	CodexSessionID string `json:"codex_session_id,omitempty"`

	// WorktreePath is the git worktree path if enabled.
	WorktreePath string `json:"worktree_path,omitempty"`

	// TmuxSession is the tmux session name if enabled.
	TmuxSession string `json:"tmux_session,omitempty"`

	// ProofCommand is the proof/verification command.
	ProofCommand string `json:"proof_command,omitempty"`

	// DoneSignal is the custom done signal.
	DoneSignal string `json:"done_signal"`

	// CreatedAt is when the run was created.
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt is when the run was last updated.
	UpdatedAt time.Time `json:"updated_at"`

	// CompletedAt is when the run completed.
	CompletedAt *time.Time `json:"completed_at,omitempty"`

	// Error contains any error message.
	Error string `json:"error,omitempty"`

	// Metadata contains additional key-value data.
	Metadata map[string]any `json:"metadata,omitempty"`
}

Manifest contains metadata about a run.

func LoadManifest

func LoadManifest(path string) (*Manifest, error)

LoadManifest loads a manifest from a file.

func LoadManifestByPath

func LoadManifestByPath(runDir string) (*Manifest, error)

LoadManifestByPath loads a manifest directly from a directory path.

func NewManifest

func NewManifest(id int, repoPath, repoID, prompt string) *Manifest

NewManifest creates a new manifest with default values.

func (*Manifest) IncrementIteration

func (m *Manifest) IncrementIteration()

IncrementIteration increments the iteration counter.

func (*Manifest) IsComplete

func (m *Manifest) IsComplete() bool

IsComplete returns true if the run has finished.

func (*Manifest) IsSingleAgent

func (m *Manifest) IsSingleAgent() bool

IsSingleAgent returns true if running in single-agent mode.

func (*Manifest) Save

func (m *Manifest) Save(path string) error

Save writes the manifest to a file.

func (*Manifest) SetState

func (m *Manifest) SetState(state State)

SetState updates the state and timestamp.

type Run

type Run struct {
	Manifest   *Manifest
	Transcript *Transcript
	Bridge     *bridge.Bridge
	// contains filtered or unexported fields
}

Run represents an active run with all its resources.

func (*Run) Close

func (r *Run) Close() error

Close closes the run's resources.

func (*Run) Dir

func (r *Run) Dir() string

Dir returns the run's directory path.

func (*Run) Save

func (r *Run) Save() error

Save saves the run's manifest.

type State

type State string

State represents the current state of a run.

const (
	StateSubmitted State = "submitted"
	StateWorking   State = "working"
	StateReviewing State = "reviewing"
	StateCompleted State = "completed"
	StateFailed    State = "failed"
	StateCancelled State = "cancelled"
)

type Transcript

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

Transcript manages the audit log for a run.

func NewTranscript

func NewTranscript(path string, runID int) *Transcript

NewTranscript creates a new transcript for the given path.

func (*Transcript) Append

func (t *Transcript) Append(entry *TranscriptEntry) error

Append adds an entry to the transcript.

func (*Transcript) LogEnd

func (t *Transcript) LogEnd(state State, totalDuration time.Duration) error

LogEnd logs the end of a run.

func (*Transcript) LogError

func (t *Transcript) LogError(agent string, iteration int, err error) error

LogError logs an error.

func (*Transcript) LogExecute

func (t *Transcript) LogExecute(agent string, iteration int, prompt string) error

LogExecute logs an execution request to an agent.

func (*Transcript) LogIteration

func (t *Transcript) LogIteration(iteration int) error

LogIteration logs the start of an iteration.

func (*Transcript) LogResult

func (t *Transcript) LogResult(agent string, iteration int, result string, duration time.Duration) error

LogResult logs a result from an agent.

func (*Transcript) LogSignal

func (t *Transcript) LogSignal(agent string, iteration int, signal string) error

LogSignal logs a signal (DONE, PASS, FAIL).

func (*Transcript) LogStart

func (t *Transcript) LogStart(prompt string, metadata map[string]any) error

LogStart logs the start of a run.

func (*Transcript) LogState

func (t *Transcript) LogState(state State) error

LogState logs a state transition.

func (*Transcript) Path

func (t *Transcript) Path() string

Path returns the transcript file path.

func (*Transcript) ReadAll

func (t *Transcript) ReadAll() ([]*TranscriptEntry, error)

ReadAll reads all entries from the transcript.

type TranscriptEntry

type TranscriptEntry struct {
	// Type categorizes the entry.
	Type EntryType `json:"type"`

	// Timestamp is when the entry was created.
	Timestamp time.Time `json:"timestamp"`

	// RunID is the run identifier.
	RunID int `json:"run_id"`

	// Iteration is the loop iteration number.
	Iteration int `json:"iteration,omitempty"`

	// Agent is the agent name (if applicable).
	Agent string `json:"agent,omitempty"`

	// State is the run state (for state entries).
	State State `json:"state,omitempty"`

	// Content is the main content (message, prompt, result, etc.).
	Content string `json:"content,omitempty"`

	// Signal is the signal value (DONE, PASS, FAIL).
	Signal string `json:"signal,omitempty"`

	// Error is the error message (for error entries).
	Error string `json:"error,omitempty"`

	// Duration is the elapsed time (for result entries).
	Duration time.Duration `json:"duration,omitempty"`

	// Metadata contains additional data.
	Metadata map[string]any `json:"metadata,omitempty"`
}

TranscriptEntry represents a single entry in the audit log.

Jump to

Keyboard shortcuts

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