workflow

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package workflow provides a generic workflow intermediate representation (IR) for modeling directed acyclic graphs (DAGs) of work items with dependencies.

This package is designed to be domain-agnostic and could be extracted as a standalone library for general workflow orchestration.

Key concepts:

  • Workflow: A named DAG with phases and nodes
  • Phase: A logical grouping/stage in the workflow
  • Node: A work item with dependencies, status, and metadata
  • Status: The state of a node (pending, in_progress, completed, blocked)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder provides a fluent API for constructing workflows.

func NewBuilder

func NewBuilder(name string) *Builder

NewBuilder creates a new workflow builder.

func (*Builder) Build

func (b *Builder) Build() (*Workflow, error)

Build finalizes and validates the workflow.

func (*Builder) Description

func (b *Builder) Description(desc string) *Builder

Description sets the workflow description.

func (*Builder) MustBuild

func (b *Builder) MustBuild() *Workflow

MustBuild finalizes the workflow and panics on error.

func (*Builder) Node

func (b *Builder) Node(id, name string) *NodeBuilder

Node adds a node to the current phase.

func (*Builder) Phase

func (b *Builder) Phase(id, name string, order int) *Builder

Phase adds a phase and sets it as current for subsequent nodes.

func (*Builder) PhaseWithDescription

func (b *Builder) PhaseWithDescription(id, name, desc string, order int) *Builder

PhaseWithDescription adds a phase with description.

type DOTRenderer

type DOTRenderer struct {
	// RankDir: TB, LR, BT, RL
	RankDir string
	// ShowStatus includes status indicators
	ShowStatus bool
	// Cluster groups nodes by phase
	Cluster bool
}

DOTRenderer renders workflows as Graphviz DOT diagrams.

func NewDOTRenderer

func NewDOTRenderer() *DOTRenderer

NewDOTRenderer creates a DOT renderer with defaults.

func (*DOTRenderer) Render

func (r *DOTRenderer) Render(w *Workflow) string

Render generates a Graphviz DOT diagram.

type JSONRenderer

type JSONRenderer struct {
	Indent bool
}

JSONRenderer renders workflows as JSON.

func (*JSONRenderer) Render

func (r *JSONRenderer) Render(w *Workflow) string

Render generates JSON representation.

type MermaidRenderer

type MermaidRenderer struct {
	// Direction: TB (top-bottom), LR (left-right), BT, RL
	Direction string
	// ShowStatus includes status indicators
	ShowStatus bool
	// ShowPhases groups nodes by phase
	ShowPhases bool
}

MermaidRenderer renders workflows as Mermaid flowchart diagrams.

func NewMermaidRenderer

func NewMermaidRenderer() *MermaidRenderer

NewMermaidRenderer creates a Mermaid renderer with defaults.

func (*MermaidRenderer) Render

func (r *MermaidRenderer) Render(w *Workflow) string

Render generates a Mermaid flowchart.

type Node

type Node struct {
	// ID uniquely identifies the node
	ID string `json:"id" yaml:"id"`

	// Name is the display name
	Name string `json:"name" yaml:"name"`

	// Description provides context
	Description string `json:"description,omitempty" yaml:"description,omitempty"`

	// Type categorizes the node (domain-specific, e.g., "source", "gtm", "technical")
	Type NodeType `json:"type,omitempty" yaml:"type,omitempty"`

	// Phase is the phase ID this node belongs to
	Phase string `json:"phase" yaml:"phase"`

	// DependsOn lists node IDs that must complete before this node can start
	DependsOn []string `json:"depends_on,omitempty" yaml:"depends_on,omitempty"`

	// Status is the current state of the node
	Status Status `json:"status" yaml:"status"`

	// Automated indicates if this node is machine-generated vs human-authored
	Automated bool `json:"automated,omitempty" yaml:"automated,omitempty"`

	// Metadata holds domain-specific data
	Metadata map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}

Node represents a single work item in the workflow.

type NodeBuilder

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

NodeBuilder provides a fluent API for constructing nodes.

func (*NodeBuilder) Add

func (nb *NodeBuilder) Add() *Builder

Add finalizes the node and adds it to the workflow.

func (*NodeBuilder) Automated

func (nb *NodeBuilder) Automated() *NodeBuilder

Automated marks the node as machine-generated.

func (*NodeBuilder) DependsOn

func (nb *NodeBuilder) DependsOn(deps ...string) *NodeBuilder

DependsOn sets the node dependencies.

func (*NodeBuilder) Description

func (nb *NodeBuilder) Description(desc string) *NodeBuilder

Description sets the node description.

func (*NodeBuilder) Metadata

func (nb *NodeBuilder) Metadata(key string, value any) *NodeBuilder

Metadata sets a metadata key-value pair.

func (*NodeBuilder) Status

func (nb *NodeBuilder) Status(s Status) *NodeBuilder

Status sets the initial status.

func (*NodeBuilder) Type

func (nb *NodeBuilder) Type(t NodeType) *NodeBuilder

Type sets the node type.

type NodeType

type NodeType string

NodeType categorizes nodes for grouping and visualization.

type Phase

type Phase struct {
	// ID uniquely identifies the phase
	ID string `json:"id" yaml:"id"`

	// Name is the display name
	Name string `json:"name" yaml:"name"`

	// Description provides context
	Description string `json:"description,omitempty" yaml:"description,omitempty"`

	// Order determines phase sequence (lower = earlier)
	Order int `json:"order" yaml:"order"`

	// Nodes lists the node IDs in this phase
	Nodes []string `json:"nodes" yaml:"nodes"`
}

Phase represents a logical stage in the workflow.

type Renderer

type Renderer interface {
	Render(w *Workflow) string
}

Renderer generates visual representations of workflows.

type Status

type Status string

Status represents the state of a workflow node.

const (
	StatusPending    Status = "pending"     // Not started, dependencies not met
	StatusReady      Status = "ready"       // Dependencies met, ready to start
	StatusInProgress Status = "in_progress" // Work in progress
	StatusCompleted  Status = "completed"   // Successfully completed
	StatusBlocked    Status = "blocked"     // Blocked by failed dependency
	StatusSkipped    Status = "skipped"     // Intentionally skipped
)

type Workflow

type Workflow struct {
	// Name identifies the workflow (e.g., "aws-working-backwards", "big-tech-product")
	Name string `json:"name" yaml:"name"`

	// Description provides human-readable context
	Description string `json:"description,omitempty" yaml:"description,omitempty"`

	// Phases define logical groupings/stages in order
	Phases []Phase `json:"phases" yaml:"phases"`

	// Nodes are the work items in the workflow
	Nodes map[string]*Node `json:"nodes" yaml:"nodes"`
}

Workflow represents a directed acyclic graph of work items.

func New

func New(name string) *Workflow

New creates a new empty workflow.

func (*Workflow) AddNode

func (w *Workflow) AddNode(node *Node) error

AddNode adds a node to the workflow.

func (*Workflow) AddPhase

func (w *Workflow) AddPhase(id, name string, order int) *Phase

AddPhase adds a phase to the workflow.

func (*Workflow) Clone

func (w *Workflow) Clone() *Workflow

Clone creates a deep copy of the workflow.

func (*Workflow) Dependencies

func (w *Workflow) Dependencies(nodeID string) []*Node

Dependencies returns the direct dependencies of a node.

func (*Workflow) Dependents

func (w *Workflow) Dependents(nodeID string) []*Node

Dependents returns nodes that depend on the given node.

func (*Workflow) GetNode

func (w *Workflow) GetNode(id string) (*Node, bool)

GetNode returns a node by ID.

func (*Workflow) IsReady

func (w *Workflow) IsReady(nodeID string) bool

IsReady returns true if all dependencies of a node are completed.

func (*Workflow) NodesByPhase

func (w *Workflow) NodesByPhase() []struct {
	Phase Phase
	Nodes []*Node
}

NodesByPhase returns nodes grouped by phase in order.

func (*Workflow) Progress

func (w *Workflow) Progress() (completed, total int, percent float64)

Progress returns completion statistics.

func (*Workflow) ReadyNodes

func (w *Workflow) ReadyNodes() []*Node

ReadyNodes returns all nodes that are ready to start.

func (*Workflow) TopologicalSort

func (w *Workflow) TopologicalSort() ([]*Node, error)

TopologicalSort returns nodes in dependency order.

func (*Workflow) UpdateStatus

func (w *Workflow) UpdateStatus(nodeID string, status Status) error

UpdateStatus updates a node's status and returns affected nodes.

func (*Workflow) Validate

func (w *Workflow) Validate() error

Validate checks the workflow for errors.

Directories

Path Synopsis
Package specworkflow adapts the generic workflow package for visionspec.
Package specworkflow adapts the generic workflow package for visionspec.

Jump to

Keyboard shortcuts

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