workflow

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package workflow implements the state-machine workflow engine: Definition, State, Transition, GuardFunc, and Engine.Execute — all enforced through the shared perm.Engine (no bespoke permission path).

See TAD §8 and PRD §19.3 for the full specification. Implemented in Phase 4.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Definition

type Definition struct {
	DocType      string
	States       []State
	Transitions  []Transition
	OnTransition map[string]Handler // keyed by destination State.Name
}

Definition declares the states, transitions, and handlers for a DocType workflow. See TAD §8.

type Engine

type Engine interface {
	Register(def Definition) error
	AvailableTransitions(ctx context.Context, docType, currentState string) []Transition
	Execute(ctx context.Context, docType, id, action string) error
	// DocTypes lists every DocType with a registered workflow definition.
	// Consumed by the agent ToolRegistry at compile time to emit exactly one
	// execute_action_{doctype} tool per workflowed DocType (TAD §10.1 step 6).
	DocTypes() []string
}

Engine manages workflow registration, transition discovery, and execution. See TAD §8.

func NewEngine

func NewEngine(db dal.Database, reg schema.Registry, permEngine perm.Engine, eventBus event.Bus, auditLog audit.Log) Engine

NewEngine constructs a workflow Engine.

type GuardFunc

type GuardFunc func(ctx context.Context, doc map[string]any) error

GuardFunc returns an error if the transition condition is not met.

type Handler

type Handler func(ctx context.Context, doc map[string]any) error

Handler is a callback invoked after a transition completes.

type State

type State struct {
	Name  string
	Style string // UI hint only: "gray" | "yellow" | "green" | "red" | a hex color
}

State defines a workflow state.

type Transition

type Transition struct {
	From         string
	To           string
	Action       string // verb surfaced as a UI button label and an agent enum value
	AllowedRoles []string
	Guard        GuardFunc // optional; evaluated after the AllowedRoles check
}

Transition defines a valid state change, allowed roles, and optional guard.

Jump to

Keyboard shortcuts

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