formula

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package formula provides parsing and validation for formula.toml files.

Formulas define structured workflows that can be executed by agents. There are four types of formulas:

  • convoy: Parallel execution of legs with synthesis
  • workflow: Sequential steps with dependencies
  • expansion: Template-based step generation
  • aspect: Multi-aspect parallel analysis (like convoy but for analysis)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProvisionFormulas

func ProvisionFormulas(beadsPath string) (int, error)

ProvisionFormulas creates the .beads/formulas/ directory with embedded formulas. This ensures new installations have the standard formula library. If a formula already exists, it is skipped (no overwrite). Returns the number of formulas provisioned.

Types

type Aspect

type Aspect struct {
	ID          string `toml:"id"`
	Title       string `toml:"title"`
	Focus       string `toml:"focus"`
	Description string `toml:"description"`
}

Aspect represents a parallel analysis aspect in an aspect formula.

type Formula

type Formula struct {
	// Common fields
	Name        string      `toml:"formula"`
	Description string      `toml:"description"`
	Type        FormulaType `toml:"type"`
	Version     int         `toml:"version"`

	// Convoy-specific
	Inputs    map[string]Input  `toml:"inputs"`
	Prompts   map[string]string `toml:"prompts"`
	Output    *Output           `toml:"output"`
	Legs      []Leg             `toml:"legs"`
	Synthesis *Synthesis        `toml:"synthesis"`

	// Workflow-specific
	Steps []Step         `toml:"steps"`
	Vars  map[string]Var `toml:"vars"`

	// Expansion-specific
	Template []Template `toml:"template"`

	// Aspect-specific (similar to convoy but for analysis)
	Aspects []Aspect `toml:"aspects"`
}

Formula represents a parsed formula.toml file.

func Parse

func Parse(data []byte) (*Formula, error)

Parse parses formula.toml content from bytes.

func ParseFile

func ParseFile(path string) (*Formula, error)

ParseFile reads and parses a formula.toml file.

func (*Formula) GetAllIDs

func (f *Formula) GetAllIDs() []string

GetAllIDs returns all step/leg/template/aspect IDs in the formula.

func (*Formula) GetAspect

func (f *Formula) GetAspect(id string) *Aspect

GetAspect returns an aspect by ID, or nil if not found.

func (*Formula) GetDependencies

func (f *Formula) GetDependencies(id string) []string

GetDependencies returns the ordered dependencies for a step/template. For convoy formulas, legs are parallel so this returns an empty slice. For workflow and expansion formulas, this returns the Needs field.

func (*Formula) GetLeg

func (f *Formula) GetLeg(id string) *Leg

GetLeg returns a leg by ID, or nil if not found.

func (*Formula) GetStep

func (f *Formula) GetStep(id string) *Step

GetStep returns a step by ID, or nil if not found.

func (*Formula) GetTemplate

func (f *Formula) GetTemplate(id string) *Template

GetTemplate returns a template by ID, or nil if not found.

func (*Formula) ReadySteps

func (f *Formula) ReadySteps(completed map[string]bool) []string

ReadySteps returns steps that have no unmet dependencies. completed is a set of step IDs that have been completed.

func (*Formula) TopologicalSort

func (f *Formula) TopologicalSort() ([]string, error)

TopologicalSort returns steps in dependency order (dependencies before dependents). Only applicable to workflow and expansion formulas. Returns an error if there are cycles.

func (*Formula) Validate

func (f *Formula) Validate() error

Validate checks that the formula has all required fields and valid structure.

type FormulaType

type FormulaType string

FormulaType represents the type of formula.

const (
	// TypeConvoy is a convoy formula with parallel legs and synthesis.
	TypeConvoy FormulaType = "convoy"
	// TypeWorkflow is a workflow formula with sequential steps.
	TypeWorkflow FormulaType = "workflow"
	// TypeExpansion is an expansion formula with template-based steps.
	TypeExpansion FormulaType = "expansion"
	// TypeAspect is an aspect-based formula for multi-aspect parallel analysis.
	TypeAspect FormulaType = "aspect"
)

func (FormulaType) IsValid

func (t FormulaType) IsValid() bool

IsValid returns true if the formula type is recognized.

type Input

type Input struct {
	Description    string   `toml:"description"`
	Type           string   `toml:"type"`
	Required       bool     `toml:"required"`
	RequiredUnless []string `toml:"required_unless"`
	Default        string   `toml:"default"`
}

Input represents an input parameter for a formula.

type Leg

type Leg struct {
	ID          string `toml:"id"`
	Title       string `toml:"title"`
	Focus       string `toml:"focus"`
	Description string `toml:"description"`
}

Leg represents a parallel execution unit in a convoy formula.

type Output

type Output struct {
	Directory  string `toml:"directory"`
	LegPattern string `toml:"leg_pattern"`
	Synthesis  string `toml:"synthesis"`
}

Output configures where formula outputs are written.

type Step

type Step struct {
	ID          string   `toml:"id"`
	Title       string   `toml:"title"`
	Description string   `toml:"description"`
	Needs       []string `toml:"needs"`
}

Step represents a sequential step in a workflow formula.

type Synthesis

type Synthesis struct {
	Title       string   `toml:"title"`
	Description string   `toml:"description"`
	DependsOn   []string `toml:"depends_on"`
}

Synthesis represents the synthesis step that combines leg outputs.

type Template

type Template struct {
	ID          string   `toml:"id"`
	Title       string   `toml:"title"`
	Description string   `toml:"description"`
	Needs       []string `toml:"needs"`
}

Template represents a template step in an expansion formula.

type Var

type Var struct {
	Description string `toml:"description"`
	Required    bool   `toml:"required"`
	Default     string `toml:"default"`
}

Var represents a variable definition for formulas.

Jump to

Keyboard shortcuts

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