worker

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package worker implements the Worker lifecycle state machine (FSM).

A Worker ties together the worktree manager, Smith (Claude) spawner, prompt builder, and state database to manage the full lifecycle:

pending → running → reviewing → done
                  ↘ failed
                  ↘ timeout

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActiveCount

func ActiveCount(db *state.DB, anvilName string) (int, error)

ActiveCount returns the number of active workers for an anvil from the state DB.

func CanSpawn

func CanSpawn(db *state.DB, anvilName string, maxSmiths int) (bool, error)

CanSpawn checks if a new worker can be spawned for the given anvil, respecting the max_smiths limit. Only dispatch pipeline workers count; lifecycle workers (cifix, reviewfix) are excluded.

func CanSpawnGlobal

func CanSpawnGlobal(db *state.DB, maxTotal int) (bool, error)

CanSpawnGlobal checks if a new worker can be spawned globally, respecting the max_total_smiths limit. Only dispatch pipeline workers count; lifecycle workers (cifix, reviewfix) are excluded.

func DispatchActiveCount

func DispatchActiveCount(db *state.DB, anvilName string) (int, error)

DispatchActiveCount returns the number of active dispatch pipeline workers for an anvil, excluding lifecycle workers (cifix, reviewfix). This is the correct value to compare against max_smiths.

func DispatchTotalActiveCount

func DispatchTotalActiveCount(db *state.DB) (int, error)

DispatchTotalActiveCount returns the total number of active dispatch pipeline workers across all anvils, excluding lifecycle workers (cifix, reviewfix). This is the correct value to compare against max_total_smiths.

func TotalActiveCount

func TotalActiveCount(db *state.DB) (int, error)

TotalActiveCount returns the total number of active workers across all anvils.

Types

type Params

type Params struct {
	DB              *state.DB
	WorktreeManager *worktree.Manager
	PromptBuilder   *prompt.Builder
	AnvilName       string
	AnvilConfig     config.AnvilConfig
	Bead            poller.Bead
	ExtraFlags      []string
}

Params holds the dependencies needed to create a Worker.

type Worker

type Worker struct {
	// ID is a unique identifier for this worker session.
	ID string
	// Bead is the bead being worked on.
	Bead poller.Bead
	// AnvilName is the name of the anvil this bead belongs to.
	AnvilName string
	// AnvilConfig is the anvil configuration.
	AnvilConfig config.AnvilConfig
	// Status is the current lifecycle state.
	Status state.WorkerStatus
	// contains filtered or unexported fields
}

Worker represents a single bead being worked on by a Smith.

func New

func New(p Params) (*Worker, error)

New creates a new Worker in the pending state and records it in the state DB.

func (*Worker) Cancel

func (w *Worker) Cancel()

Cancel stops a running worker.

func (*Worker) Run

func (w *Worker) Run(ctx context.Context, extraFlags []string) (*smith.Result, error)

Run executes the full worker lifecycle:

  1. Create worktree
  2. Build prompt
  3. Spawn Smith process
  4. Wait for completion
  5. Teardown worktree

The returned Result comes from the Smith process. Run transitions the worker through: pending → running → done/failed.

Jump to

Keyboard shortcuts

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