parse

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package parse decodes and validates workflow.yaml bodies. Pure in-memory transforms over the types defined in `workflow` root pkg — no filesystem, no engine, no executors.

Use Parse to turn a byte slice into a Workflow + a synthesized ID, then Validate to gather every static problem (errors that block load + warnings that don't) before handing the workflow to engine or service layers.

Index

Constants

This section is empty.

Variables

View Source
var IDRe = regexp.MustCompile(`^[a-z0-9-]+$`)

IDRe is the canonical id pattern. Folder names and trigger path templates must match.

View Source
var IdentRe = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)

IdentRe is the Go-template identifier pattern. Used for node ids, trigger ids, and labels — anything that will appear as a key in `{{.Node.<key>.…}}`. Letters/digits/underscore, must start with letter or underscore. Dashes are banned so the template parser doesn't choke with "bad character U+002D".

View Source
var NodeIDRe = regexp.MustCompile(`^[a-z0-9_-]+$`)

NodeIDRe accepts id charset plus underscore. Underscore is allowed because palette node-type names (e.g. `session_init`, `dataset_query`) are reused as the seeded ID on drop — rejecting `_` here would force every Go const to dual-spell as `session-init` solely for the validator. Folder names still use IDRe (hyphen-only).

Functions

func BfsReachable

func BfsReachable(g workflow.Graph, roots map[string]bool) map[string]bool

BfsReachable returns the set of node IDs reachable from any root.

func DetectCycle

func DetectCycle(g workflow.Graph) []string

DetectCycle returns the IDs of nodes participating in a cycle, or nil if the graph is acyclic. Uses Kahn's topological sort.

func Marshal

func Marshal(w workflow.Workflow) ([]byte, error)

Marshal serializes a Workflow back to YAML.

func Parse

func Parse(id string, data []byte) (workflow.Workflow, error)

Parse decodes a workflow.yaml body. The folder name is the authoritative ID — it overwrites whatever `id:` happens to be in the YAML so renaming a folder always wins over a stale value. The returned workflow has not yet been validated; call Validate after.

func ValidateID

func ValidateID(id string) error

ValidateID rejects names that would break path math.

func ValidateLabel

func ValidateLabel(label string) error

ValidateLabel rejects bad labels. Same rule as ValidateNodeID since labels are how operators reference nodes in templates.

func ValidateNodeID

func ValidateNodeID(id string) error

ValidateNodeID rejects bad node IDs. Strict identifier rule — must work as a Go-template path segment in `{{.Node.<id>.…}}`.

Types

type Error

type Error struct {
	Path    string
	Message string
}

Error is returned by Parse with a path-style locator for the offending field so callers (UI, MCP) can surface "yaml: graph.edges[2]: ...".

func (Error) Error

func (e Error) Error() string

type Result

type Result struct {
	Errors   []Error
	Warnings []Error
}

Result is the aggregate of static checks performed by Validate. Ok() == true means no Errors (Warnings always allowed). Implements error so callers can `if err := r.AsError(); err != nil`.

func Validate

func Validate(w workflow.Workflow) *Result

Validate checks the workflow body. Always returns a non-nil result; inspect Errors and Warnings.

func (*Result) Error

func (r *Result) Error() string

func (*Result) Ok

func (r *Result) Ok() bool

Ok reports whether validation found zero errors (warnings are fine).

Jump to

Keyboard shortcuts

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