workflow

package
v1.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package workflow provides workflow template definitions and coordination for multi-agent patterns.

Package workflow provides workflow template definitions and coordination for multi-agent patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinNames

func BuiltinNames() []string

BuiltinNames returns the names of all builtin workflow templates.

func ProfileToAgentType

func ProfileToAgentType(profile string) string

ProfileToAgentType maps a workflow profile name to an agent type. Known mappings:

  • "claude", "cc", "claude-code" → "cc"
  • "codex", "cod", "codex-cli" → "cod"
  • "gemini", "gmi", "gemini-cli" → "gmi"
  • Other profiles default to "cc" (Claude Code)

func SourceDescription

func SourceDescription(source string) string

SourceDescription returns a human-readable description of the source.

Types

type CoordinationType

type CoordinationType string

CoordinationType specifies how agents coordinate in a workflow.

const (
	// CoordPingPong alternates work between agents.
	CoordPingPong CoordinationType = "ping-pong"
	// CoordPipeline sequences work through stages.
	CoordPipeline CoordinationType = "pipeline"
	// CoordParallel runs agents simultaneously.
	CoordParallel CoordinationType = "parallel"
	// CoordReviewGate requires approval before proceeding.
	CoordReviewGate CoordinationType = "review-gate"
)

func (CoordinationType) IsValid

func (c CoordinationType) IsValid() bool

IsValid checks if the coordination type is valid.

type ErrorAction

type ErrorAction string

ErrorAction specifies what to do when an error occurs.

const (
	ErrorActionRestartAgent ErrorAction = "restart_agent"
	ErrorActionPause        ErrorAction = "pause"
	ErrorActionSkipStage    ErrorAction = "skip_stage"
	ErrorActionAbort        ErrorAction = "abort"
	ErrorActionNotify       ErrorAction = "notify"
)

type ErrorConfig

type ErrorConfig struct {
	OnAgentCrash        ErrorAction `toml:"on_agent_crash,omitempty"`
	OnAgentError        ErrorAction `toml:"on_agent_error,omitempty"`
	OnTimeout           ErrorAction `toml:"on_timeout,omitempty"`
	StageTimeoutMinutes int         `toml:"stage_timeout_minutes,omitempty"`
	MaxRetriesPerStage  int         `toml:"max_retries_per_stage,omitempty"`
}

ErrorConfig defines error handling behavior for a workflow.

func (*ErrorConfig) Validate

func (e *ErrorConfig) Validate() error

Validate checks that the error config is valid.

type FlowConfig

type FlowConfig struct {
	Initial             string       `toml:"initial"`
	Stages              []string     `toml:"stages,omitempty"`
	Transitions         []Transition `toml:"transitions"`
	RequireApproval     bool         `toml:"require_approval,omitempty"`
	ApprovalMode        string       `toml:"approval_mode,omitempty"` // any, all, quorum
	Quorum              int          `toml:"quorum,omitempty"`
	ParallelWithinStage bool         `toml:"parallel_within_stage,omitempty"`
}

FlowConfig defines the state machine for workflow progression.

func (*FlowConfig) Validate

func (f *FlowConfig) Validate(coordType CoordinationType) error

Validate checks that the flow config is valid.

type Loader

type Loader struct {
	// UserConfigDir is the user config directory (default: ~/.config/ntm)
	UserConfigDir string
	// ProjectDir is the current project directory (for .ntm/workflows/)
	ProjectDir string
}

Loader loads workflow templates from multiple sources with proper precedence.

func NewLoader

func NewLoader() *Loader

NewLoader creates a new workflow template loader with default paths.

func (*Loader) Get

func (l *Loader) Get(name string) (*WorkflowTemplate, error)

Get returns a workflow template by name, or nil if not found.

func (*Loader) LoadAll

func (l *Loader) LoadAll() ([]WorkflowTemplate, error)

LoadAll loads workflow templates from all sources with proper precedence. Order: builtin < user (~/.config/ntm/workflows/) < project (.ntm/workflows/) Later sources override earlier ones by name.

type SetupPrompt

type SetupPrompt struct {
	Key        string `toml:"key"`
	Question   string `toml:"question"`
	Default    string `toml:"default,omitempty"`
	Validation string `toml:"validation,omitempty"` // regex pattern
	Required   bool   `toml:"required,omitempty"`
}

SetupPrompt defines a question to ask when starting a workflow.

func (*SetupPrompt) Validate

func (p *SetupPrompt) Validate() error

Validate checks that the setup prompt is valid.

type Transition

type Transition struct {
	From    string  `toml:"from"`
	To      string  `toml:"to"`
	Trigger Trigger `toml:"trigger"`
}

Transition defines a state change in the workflow.

func (*Transition) Validate

func (t *Transition) Validate() error

Validate checks that the transition is valid.

type Trigger

type Trigger struct {
	Type        TriggerType `toml:"type"`
	Pattern     string      `toml:"pattern,omitempty"`      // For file/agent_says triggers
	Command     string      `toml:"command,omitempty"`      // For command triggers
	Role        string      `toml:"role,omitempty"`         // For agent-specific triggers
	Label       string      `toml:"label,omitempty"`        // For manual triggers
	Minutes     int         `toml:"minutes,omitempty"`      // For time-based triggers
	IdleMinutes int         `toml:"idle_minutes,omitempty"` // For idle triggers
}

Trigger defines when a transition should occur.

func (*Trigger) Validate

func (t *Trigger) Validate() error

Validate checks that the trigger is valid.

type TriggerType

type TriggerType string

TriggerType specifies the kind of trigger for a transition.

const (
	TriggerFileCreated    TriggerType = "file_created"
	TriggerFileModified   TriggerType = "file_modified"
	TriggerCommandSuccess TriggerType = "command_success"
	TriggerCommandFailure TriggerType = "command_failure"
	TriggerAgentSays      TriggerType = "agent_says"
	TriggerAllAgentsIdle  TriggerType = "all_agents_idle"
	TriggerManual         TriggerType = "manual"
	TriggerTimeElapsed    TriggerType = "time_elapsed"
)

func (TriggerType) IsValid

func (t TriggerType) IsValid() bool

IsValid checks if the trigger type is valid.

type WorkflowAgent

type WorkflowAgent struct {
	Profile     string `toml:"profile"`
	Role        string `toml:"role"`
	Count       int    `toml:"count,omitempty"`
	Description string `toml:"description,omitempty"`
}

WorkflowAgent defines an agent role within a workflow.

func (*WorkflowAgent) Validate

func (a *WorkflowAgent) Validate() error

Validate checks that the workflow agent is valid.

type WorkflowTemplate

type WorkflowTemplate struct {
	Name          string            `toml:"name"`
	Description   string            `toml:"description"`
	Agents        []WorkflowAgent   `toml:"agents"`
	Coordination  CoordinationType  `toml:"coordination"`
	Flow          *FlowConfig       `toml:"flow,omitempty"`
	Routing       map[string]string `toml:"routing,omitempty"`
	Prompts       []SetupPrompt     `toml:"prompts,omitempty"`
	ErrorHandling *ErrorConfig      `toml:"error_handling,omitempty"`
	Source        string            `toml:"-"` // "builtin", "user", "project" - set at load time
}

WorkflowTemplate defines a multi-agent workflow pattern.

func ParseAndValidateWorkflow

func ParseAndValidateWorkflow(content string) (*WorkflowTemplate, error)

ParseAndValidateWorkflow parses and validates a workflow template.

func ParseWorkflow

func ParseWorkflow(content string) (*WorkflowTemplate, error)

ParseWorkflow parses a single workflow template from TOML content.

func ParseWorkflows

func ParseWorkflows(content string) ([]WorkflowTemplate, error)

ParseWorkflows parses workflow templates from TOML content.

func (*WorkflowTemplate) AgentCounts

func (t *WorkflowTemplate) AgentCounts() map[string]int

AgentCounts returns a map of agent type to count based on template agents. This enables integration with the spawn command.

func (*WorkflowTemplate) GetAgentCount

func (t *WorkflowTemplate) GetAgentCount() int

GetAgentCount returns the total number of agent instances in the workflow.

func (*WorkflowTemplate) GetAgentsByRole

func (t *WorkflowTemplate) GetAgentsByRole(role string) []WorkflowAgent

GetAgentsByRole returns all agents with the specified role.

func (*WorkflowTemplate) GetRoles

func (t *WorkflowTemplate) GetRoles() []string

GetRoles returns a list of all unique roles in the workflow.

func (*WorkflowTemplate) String

func (t *WorkflowTemplate) String() string

String returns a human-readable summary of the workflow.

func (*WorkflowTemplate) Validate

func (t *WorkflowTemplate) Validate() error

Validate checks that the workflow template is valid.

type WorkflowsFile

type WorkflowsFile struct {
	Workflows []WorkflowTemplate `toml:"workflows"`
}

WorkflowsFile represents a TOML file containing workflow templates.

Jump to

Keyboard shortcuts

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