task

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusPending    = "pending"
	StatusProcessing = "processing"
	StatusCompleted  = "completed"
	StatusFailed     = "failed"
)

Status constants for task tracking.

Variables

This section is empty.

Functions

func TopologicalSort

func TopologicalSort(graph *DependencyGraph, beadList []beads.Bead) ([]beads.Bead, error)

TopologicalSort returns beads in dependency order (dependencies before dependents).

Types

type BeadComplexity

type BeadComplexity struct {
	BeadID          string
	ComplexityScore int // 1-10 scale
	EstimatedTokens int
}

BeadComplexity holds complexity information for a single bead.

type ComplexityEstimator

type ComplexityEstimator interface {
	// Estimate returns a complexity score (1-10) and estimated context tokens for a bead.
	Estimate(ctx context.Context, bead beads.Bead) (score int, tokens int, err error)
}

ComplexityEstimator estimates the complexity of a bead.

type ComplexityEstimatorMock

type ComplexityEstimatorMock struct {
	// EstimateFunc mocks the Estimate method.
	EstimateFunc func(ctx context.Context, bead beads.Bead) (int, int, error)
	// contains filtered or unexported fields
}

ComplexityEstimatorMock is a mock implementation of ComplexityEstimator.

func TestSomethingThatUsesComplexityEstimator(t *testing.T) {

	// make and configure a mocked ComplexityEstimator
	mockedComplexityEstimator := &ComplexityEstimatorMock{
		EstimateFunc: func(ctx context.Context, bead beads.Bead) (int, int, error) {
			panic("mock out the Estimate method")
		},
	}

	// use mockedComplexityEstimator in code that requires ComplexityEstimator
	// and then make assertions.

}

func (*ComplexityEstimatorMock) Estimate

func (mock *ComplexityEstimatorMock) Estimate(ctx context.Context, bead beads.Bead) (int, int, error)

Estimate calls EstimateFunc.

func (*ComplexityEstimatorMock) EstimateCalls

func (mock *ComplexityEstimatorMock) EstimateCalls() []struct {
	Ctx  context.Context
	Bead beads.Bead
}

EstimateCalls gets all the calls that were made to Estimate. Check the length with:

len(mockedComplexityEstimator.EstimateCalls())

type DefaultPlanner

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

DefaultPlanner implements the Planner interface using bin-packing.

func NewDefaultPlanner

func NewDefaultPlanner(estimator ComplexityEstimator) *DefaultPlanner

NewDefaultPlanner creates a new planner with the given complexity estimator.

func (*DefaultPlanner) Plan

func (p *DefaultPlanner) Plan(
	ctx context.Context,
	beadList []beads.Bead,
	dependencies map[string][]beads.Dependency,
	budget int,
) ([]Task, error)

Plan creates task assignments from beads using bin-packing algorithm. The budget represents the target tokens per task (e.g., 120000 for 120K tokens).

type DependencyGraph

type DependencyGraph struct {
	// DependsOn maps bead ID to IDs it depends on
	DependsOn map[string][]string
	// Dependents maps bead ID to IDs that depend on it (renamed from BlockedBy)
	Dependents map[string][]string
}

DependencyGraph represents bead dependencies.

func BuildDependencyGraph

func BuildDependencyGraph(
	beadList []beads.Bead,
	dependencies map[string][]beads.Dependency,
) *DependencyGraph

BuildDependencyGraph creates a dependency graph from beads and their dependencies.

type EstimationResult

type EstimationResult struct {
	AllCached   bool     // True if all beads already had cached estimates
	TaskSpawned bool     // True if an estimation task was spawned
	TaskID      string   // The estimation task ID if spawned
	UncachedIDs []string // IDs of beads that need estimation
}

EstimationResult contains the result of an estimation attempt.

type LLMEstimator

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

LLMEstimator uses Claude Code via estimate tasks to estimate bead complexity.

func NewLLMEstimator

func NewLLMEstimator(database *db.DB, workDir, projectName, workID string) *LLMEstimator

NewLLMEstimator creates a new LLM-based complexity estimator.

func (*LLMEstimator) Estimate

func (e *LLMEstimator) Estimate(ctx context.Context, bead beads.Bead) (score int, tokens int, err error)

Estimate returns a complexity score (1-10) and estimated context tokens for a bead. Results are cached based on the description hash. Returns (0, 0, nil) if the bead needs estimation but an estimation task was spawned.

func (*LLMEstimator) EstimateBatch

func (e *LLMEstimator) EstimateBatch(ctx context.Context, beadList []beads.Bead, forceEstimate bool) (*EstimationResult, error)

EstimateBatch spawns an estimation task for beads without cached complexity. This function is non-blocking - it spawns the task and returns immediately. Returns EstimationResult indicating whether all beads are cached or if a task was spawned.

type Planner

type Planner interface {
	// Plan analyzes beads and creates task assignments based on token budget.
	// The budget represents the target tokens per task (e.g., 120000 for 120K tokens).
	// Returns a list of tasks with beads grouped to respect dependencies and fit within budget.
	Plan(
		ctx context.Context,
		beadList []beads.Bead,
		dependencies map[string][]beads.Dependency,
		budget int,
	) ([]Task, error)
}

Planner creates task groupings from a list of beads.

type PlannerMock

type PlannerMock struct {
	// PlanFunc mocks the Plan method.
	PlanFunc func(ctx context.Context, beadList []beads.Bead, dependencies map[string][]beads.Dependency, budget int) ([]Task, error)
	// contains filtered or unexported fields
}

PlannerMock is a mock implementation of Planner.

func TestSomethingThatUsesPlanner(t *testing.T) {

	// make and configure a mocked Planner
	mockedPlanner := &PlannerMock{
		PlanFunc: func(ctx context.Context, beadList []beads.Bead, dependencies map[string][]beads.Dependency, budget int) ([]Task, error) {
			panic("mock out the Plan method")
		},
	}

	// use mockedPlanner in code that requires Planner
	// and then make assertions.

}

func (*PlannerMock) Plan

func (mock *PlannerMock) Plan(ctx context.Context, beadList []beads.Bead, dependencies map[string][]beads.Dependency, budget int) ([]Task, error)

Plan calls PlanFunc.

func (*PlannerMock) PlanCalls

func (mock *PlannerMock) PlanCalls() []struct {
	Ctx          context.Context
	BeadList     []beads.Bead
	Dependencies map[string][]beads.Dependency
	Budget       int
}

PlanCalls gets all the calls that were made to Plan. Check the length with:

len(mockedPlanner.PlanCalls())

type Task

type Task struct {
	ID              string       // Unique task identifier
	BeadIDs         []string     // IDs of beads in this task
	Beads           []beads.Bead // Full bead information
	Complexity      int          // Sum of bead complexity scores
	EstimatedTokens int          // Sum of estimated tokens for all beads
	Status          string       // pending, processing, completed, failed
}

Task represents a virtual task - a group of beads to be processed together.

Jump to

Keyboard shortcuts

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