workflow

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package workflow loads YAML workflow templates and turns them into concrete issue/dep/label plans.

A template is a declarative description of a multi-step process. `Load` parses YAML; `MakePlan` produces an instantiation plan from a template and a set of variable bindings; the CLI layer writes the plan to the store.

Index

Constants

View Source
const TemplatesSubdir = "templates"

TemplatesSubdir is the directory name under a clu project dir where workflow YAML files live. The CLI and HTTP servers both resolve their templates dir via TemplatesPath so a future move (e.g. to .clu/workflows/) only changes one constant.

Variables

This section is empty.

Functions

func Interpolate

func Interpolate(s string, vars map[string]string) (string, error)

Interpolate substitutes {{var}} placeholders in s. An unknown var name is an error.

func TemplatesPath

func TemplatesPath(projectDir string) string

TemplatesPath returns the templates directory for a project at `projectDir`. Centralises the join so call sites stop hardcoding the literal.

Types

type LoadError

type LoadError struct {
	File string
	Err  error
}

LoadError pairs a template file that failed to load with the underlying error. LoadDir returns these alongside the healthy templates so one bad file doesn't block listing or running the rest.

func LoadDir

func LoadDir(dir string) (map[string]Template, []LoadError, error)

LoadDir loads all *.yaml/*.yml files from dir, keyed by template name. Missing dir returns an empty map (no error). Per-file failures (parse errors, missing @-referenced spec files, duplicate names) are returned as a separate []LoadError — the caller decides whether to surface them; the healthy templates are still usable for `template ls`, `template show <other>`, `run <other>`.

This shape exists because a single broken template used to abort every template command. With a checked-in workflow dir shared across a team that meant one person's bad commit broke the tool for everyone.

func (LoadError) Error

func (e LoadError) Error() string

func (LoadError) Unwrap

func (e LoadError) Unwrap() error

type ParentSpec

type ParentSpec struct {
	Title       string
	Description string // = interpolated spec (may be empty)
}

ParentSpec describes the root issue of a run.

type Plan

type Plan struct {
	TemplateName string
	Vars         map[string]string
	Spec         string // interpolated; the shared-context block (may be empty)
	Parent       ParentSpec
	Steps        []StepSpec
}

Plan is the abstract result of applying a Template to a set of vars. It is pure — no IDs allocated, no DB writes performed. The CLI layer walks the plan, calls store.Create per step, and writes deps/labels/KV.

func MakePlan

func MakePlan(t Template, in map[string]string) (Plan, error)

MakePlan validates the template, resolves vars, interpolates titles, and produces a Plan. It does not touch any external state.

type Step

type Step struct {
	ID    string `yaml:"id"`
	Title string `yaml:"title"`
	// Description is per-step instructions — acceptance criteria, the
	// specific job, any references downstream agents will need.
	// {{var}} interpolation applies. The template's spec is prepended
	// at instantiation so each step issue is self-contained.
	Description string   `yaml:"description,omitempty"`
	Type        string   `yaml:"type,omitempty"`
	Priority    *int     `yaml:"priority,omitempty"`
	Needs       []string `yaml:"needs,omitempty"`
	Agent       string   `yaml:"agent,omitempty"` // pre-assigns the step to an agent lane
	Wait        *Wait    `yaml:"wait,omitempty"`
}

Step is one step in a workflow.

type StepSpec

type StepSpec struct {
	StepID      string // template step id (e.g. "build")
	Title       string // interpolated
	Description string // interpolated; spec + "\n\n---\n\n" + per-step desc, when set
	Type        string // "task" or "checkpoint"
	Priority    int
	Needs       []string // step ids, not issue ids
	Agent       string   // pre-assigned agent lane; "" = unassigned
	Wait        *Wait    // checkpoint config; nil for tasks
	IsLeaf      bool     // no other step needs this one — parent depends on it
}

StepSpec describes one step in a Plan.

type Template

type Template struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description,omitempty"`
	// Spec is shared context prepended to every step's description on
	// instantiation. Inline string, or @<path> to load from a file
	// relative to the template (so a 50-line scaffold-spec.md can live
	// next to the template). {{var}} placeholders interpolate.
	Spec  string         `yaml:"spec,omitempty"`
	Vars  map[string]Var `yaml:"vars,omitempty"`
	Steps []Step         `yaml:"steps"`
}

Template is a parsed workflow definition.

func Load

func Load(path string) (Template, error)

Load reads and parses a template file. If `spec:` starts with @, the rest is treated as a path (resolved relative to the template file) and its contents replace the @-string. Useful for keeping long shared-context blocks in a sibling markdown file.

func (Template) ResolveVars

func (t Template) ResolveVars(in map[string]string) (map[string]string, error)

ResolveVars validates caller-supplied values against the template's declared vars. Returns the merged map (defaults applied).

func (Template) Validate

func (t Template) Validate() error

Validate runs structural checks.

type Var

type Var struct {
	Required bool   `yaml:"required,omitempty"`
	Default  string `yaml:"default,omitempty"`
	Pattern  string `yaml:"pattern,omitempty"`
	// Label is a short human-readable name for the variable. Used by
	// the interactive prompt today; future surfaces (docs, GUI, JSON
	// schemas) will reuse the same string. Defaults to the var name
	// when empty.
	Label string `yaml:"label,omitempty"`
}

Var is a single variable declaration.

type Wait

type Wait struct {
	Manual   bool     `yaml:"manual,omitempty"`
	Approval []string `yaml:"approval,omitempty"`
}

Wait describes the blocking condition for a checkpoint step.

Jump to

Keyboard shortcuts

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