ast

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

MarshalFile / UnmarshalFile provide JSON serialization and deserialization for File types, converting Go iota-based enums to human-readable string representations.

Package ast defines the Abstract Syntax Tree for the iterion DSL V1.

Index

Constants

View Source
const (
	MCPTransportUnknown = types.MCPTransportUnknown
	MCPTransportStdio   = types.MCPTransportStdio
	MCPTransportHTTP    = types.MCPTransportHTTP
	MCPTransportSSE     = types.MCPTransportSSE
)
View Source
const (
	FieldTypeString      = types.FieldTypeString
	FieldTypeBool        = types.FieldTypeBool
	FieldTypeInt         = types.FieldTypeInt
	FieldTypeFloat       = types.FieldTypeFloat
	FieldTypeJSON        = types.FieldTypeJSON
	FieldTypeStringArray = types.FieldTypeStringArray
)
View Source
const (
	SessionFresh         = types.SessionFresh
	SessionInherit       = types.SessionInherit
	SessionArtifactsOnly = types.SessionArtifactsOnly
	SessionFork          = types.SessionFork
)
View Source
const (
	RouterFanOutAll  = types.RouterFanOutAll
	RouterCondition  = types.RouterCondition
	RouterRoundRobin = types.RouterRoundRobin
	RouterLLM        = types.RouterLLM
)
View Source
const (
	AwaitNone       = types.AwaitNone
	AwaitWaitAll    = types.AwaitWaitAll
	AwaitBestEffort = types.AwaitBestEffort
)
View Source
const (
	InteractionNone       = types.InteractionNone
	InteractionHuman      = types.InteractionHuman
	InteractionLLM        = types.InteractionLLM
	InteractionLLMOrHuman = types.InteractionLLMOrHuman
)

Variables

View Source
var ReservedTargets = map[string]bool{
	"done": true,
	"fail": true,
}

ReservedTargets are node names that cannot be declared — they are implicit terminal nodes used as edge targets.

Functions

func MarshalFile

func MarshalFile(f *File) ([]byte, error)

Marshal converts an File to JSON with human-readable string enums. Span fields are omitted from the output.

Types

type AgentDecl

type AgentDecl struct {
	Name              string
	Model             string // string literal, may contain ${...} env refs
	Backend           string // execution backend name (e.g. "claude_code"); when set, bypasses direct LLM API
	MCP               *MCPConfigDecl
	Input             string           // schema reference name
	Output            string           // schema reference name
	Publish           string           // persistent artifact name (empty if not set)
	System            string           // prompt reference name
	User              string           // prompt reference name
	Session           SessionMode      // defaults to SessionFresh
	Tools             []string         // tool capability names
	ToolPolicy        []string         // per-node tool policy patterns (nil = inherit workflow)
	ToolMaxSteps      int              // max tool-use iterations (0 = not set)
	MaxTokens         int              // max output tokens per LLM call (0 = inherit backend default)
	ReasoningEffort   string           // reasoning effort level: "low", "medium", "high", "xhigh", "max"
	Readonly          bool             // when true, node is not considered mutating for workspace safety
	Interaction       InteractionMode  // interaction handling (default none for agents)
	InteractionPrompt string           // prompt reference guiding LLM for llm_or_human decisions
	InteractionModel  string           // model for llm/llm_or_human modes (fallback to Model)
	Await             AwaitMode        // convergence strategy (none/wait_all/best_effort)
	Compaction        *CompactionBlock // per-node compaction overrides (nil = inherit workflow)
	Span              Span
}

AgentDecl represents an `agent <name>:` node declaration.

type AwaitMode

type AwaitMode = types.AwaitMode

AwaitMode represents the convergence strategy when a node receives inputs from multiple parallel branches.

type BudgetBlock

type BudgetBlock struct {
	MaxParallelBranches int     // 0 = not set
	MaxDuration         string  // e.g. "60m", empty = not set
	MaxCostUSD          float64 // 0 = not set
	MaxTokens           int     // 0 = not set
	MaxIterations       int     // 0 = not set
	Span                Span
}

BudgetBlock represents execution limits for a workflow.

type Comment

type Comment struct {
	Text string
	Span Span
}

type CompactionBlock

type CompactionBlock struct {
	Threshold      *float64 // ratio of model context window (0 < t <= 1); nil = inherit
	PreserveRecent *int     // recent messages kept verbatim (>= 1); nil = inherit
	Span           Span
}

CompactionBlock configures session compaction. Both fields use a "0/nil means inherit" convention so workflow-level defaults fall through to node-level overrides which fall through to env / built-in defaults.

type ComputeDecl

type ComputeDecl struct {
	Name   string
	Input  string         // optional input schema reference name
	Output string         // schema reference name (defines the output fields)
	Expr   []*ComputeExpr // ordered list of field-name → expression-source pairs
	Await  AwaitMode      // convergence strategy (none/wait_all/best_effort)
	Span   Span
}

ComputeDecl represents a `compute <name>:` node that evaluates a set of expressions over `vars`/`input`/`outputs`/`artifacts`/`loop`/`run` to produce a structured output. Used for streak detection, boolean ANDs, counters, etc., without invoking an LLM or shelling out.

type ComputeExpr

type ComputeExpr struct {
	Key  string
	Expr string // raw expression source (parsed at compile time)
	Span Span
}

ComputeExpr is one entry inside a `compute` node's `expr:` block: `<key>: "<expression>"`.

type Edge

type Edge struct {
	From string       // source node name
	To   string       // target node name (can be "done" or "fail")
	When *WhenClause  // optional condition
	Loop *LoopClause  // optional loop tracking
	With []*WithEntry // optional data mappings
	Span Span
}

Edge represents a directed transition: `src -> dst [when ...] [as ...] [with {...}]`.

type FieldType

type FieldType = types.FieldType

FieldType enumerates the V1 schema field types.

type File

type File struct {
	Vars       *VarsBlock       // top-level vars (optional, at most one)
	MCPServers []*MCPServerDecl // top-level reusable MCP server declarations
	Prompts    []*PromptDecl    // prompt declarations
	Schemas    []*SchemaDecl    // schema declarations
	Agents     []*AgentDecl     // agent node declarations
	Judges     []*JudgeDecl     // judge node declarations
	Routers    []*RouterDecl    // router node declarations
	Humans     []*HumanDecl     // human node declarations
	Tools      []*ToolNodeDecl  // tool node declarations (direct execution, no LLM)
	Computes   []*ComputeDecl   // deterministic compute node declarations (no LLM, no shell)
	Workflows  []*WorkflowDecl  // workflow declarations
	Comments   []*Comment       // top-level comments (## ...)
	Span       Span
}

File is the root AST node representing an entire .iter source file.

func UnmarshalFile

func UnmarshalFile(data []byte) (*File, error)

Unmarshal converts JSON (produced by Marshal) back to an File.

func (*File) AllMCPServerNames

func (f *File) AllMCPServerNames() []string

AllMCPServerNames returns the names of all top-level MCP server declarations.

func (*File) AllNodeNames

func (f *File) AllNodeNames() []string

AllNodeNames returns the names of all declared nodes across all types. Useful for validation (duplicate detection, edge target resolution).

func (*File) AllPromptNames

func (f *File) AllPromptNames() []string

AllPromptNames returns the names of all declared prompts.

func (*File) AllSchemaNames

func (f *File) AllSchemaNames() []string

AllSchemaNames returns the names of all declared schemas.

type HumanDecl

type HumanDecl struct {
	Name              string
	Input             string          // schema reference name
	Output            string          // schema reference name
	Publish           string          // persistent artifact name
	Instructions      string          // prompt reference name
	Interaction       InteractionMode // defaults to InteractionHuman (replaces Mode)
	InteractionPrompt string          // prompt reference guiding LLM for llm_or_human decisions
	InteractionModel  string          // model for llm/llm_or_human modes (fallback to Model)
	MinAnswers        int             // minimum human answers required
	Model             string          // model identifier (required for llm / llm_or_human)
	System            string          // prompt reference for LLM system prompt
	Await             AwaitMode       // convergence strategy (none/wait_all/best_effort)
	Span              Span
}

HumanDecl represents a `human <name>:` node declaration.

type InteractionMode

type InteractionMode = types.InteractionMode

InteractionMode controls how a node handles user interaction requests. It is available on agent, judge, and human nodes.

type JudgeDecl

type JudgeDecl struct {
	Name              string
	Model             string
	Backend           string // execution backend name; when set, bypasses direct LLM API
	MCP               *MCPConfigDecl
	Input             string
	Output            string
	Publish           string
	System            string
	User              string
	Session           SessionMode
	Tools             []string // usually empty for judges, but allowed
	ToolPolicy        []string // per-node tool policy patterns (nil = inherit workflow)
	ToolMaxSteps      int
	MaxTokens         int              // max output tokens per LLM call (0 = inherit backend default)
	ReasoningEffort   string           // reasoning effort level: "low", "medium", "high", "xhigh", "max"
	Readonly          bool             // when true, node is not considered mutating for workspace safety
	Interaction       InteractionMode  // interaction handling (default none for judges)
	InteractionPrompt string           // prompt reference guiding LLM for llm_or_human decisions
	InteractionModel  string           // model for llm/llm_or_human modes (fallback to Model)
	Await             AwaitMode        // convergence strategy (none/wait_all/best_effort)
	Compaction        *CompactionBlock // per-node compaction overrides (nil = inherit workflow)
	Span              Span
}

JudgeDecl represents a `judge <name>:` node declaration. Structurally identical to AgentDecl; semantically a judge produces verdicts and typically does not use tools.

type Literal

type Literal struct {
	Kind     LiteralKind
	Raw      string  // raw text as written in source
	StrVal   string  // if LitString
	IntVal   int64   // if LitInt
	FloatVal float64 // if LitFloat
	BoolVal  bool    // if LitBool
}

Literal represents a default value in a var declaration.

type LiteralKind

type LiteralKind int

LiteralKind distinguishes literal value types.

const (
	LitString LiteralKind = iota
	LitInt
	LitFloat
	LitBool
)

type LoopClause

type LoopClause struct {
	Name          string // loop name (e.g. "refine_loop", "full_recipe_loop")
	MaxIterations int    // upper bound
	Span          Span
}

LoopClause represents `as <loop_name>(<max_iterations>)` on an edge.

type MCPAuthDecl

type MCPAuthDecl struct {
	Type      string
	AuthURL   string
	TokenURL  string
	RevokeURL string
	ClientID  string
	Scopes    []string
	Span      Span
}

MCPAuthDecl represents an `auth:` block under an `mcp_server`. Only the OAuth2 authorization-code + PKCE flow is currently wired; Type is "oauth2".

type MCPConfigDecl

type MCPConfigDecl struct {
	AutoloadProject *bool
	Inherit         *bool
	Servers         []string
	Disable         []string
	Span            Span
}

MCPConfigDecl represents a workflow-level or node-level `mcp:` block. Workflow blocks use AutoloadProject; node blocks use Inherit.

type MCPServerDecl

type MCPServerDecl struct {
	Name      string
	Transport MCPTransport
	Command   string
	Args      []string
	URL       string
	Auth      *MCPAuthDecl
	Span      Span
}

MCPServerDecl represents a top-level `mcp_server <name>:` declaration.

type MCPTransport

type MCPTransport = types.MCPTransport

MCPTransport identifies the transport used by an MCP server.

type Pos

type Pos struct {
	File   string // source file name
	Line   int    // 1-based line number
	Column int    // 1-based column number
}

Pos represents a position in a source file.

type PromptDecl

type PromptDecl struct {
	Name string
	Body string // raw text, may contain {{...}} template expressions
	Span Span
}

PromptDecl represents `prompt <name>:` followed by template text.

type RouterDecl

type RouterDecl struct {
	Name            string
	Mode            RouterMode
	Model           string // only for mode: llm
	Backend         string // execution backend name, only for mode: llm
	System          string // prompt ref, only for mode: llm
	User            string // prompt ref, only for mode: llm
	Multi           bool   // multi-route selection, only for mode: llm
	ReasoningEffort string // reasoning effort level: "low", "medium", "high", "xhigh", "max" (only for mode: llm)
	Span            Span
}

RouterDecl represents a `router <name>:` node declaration. Routers are fan-out sources and do not support the Await field (convergence is only meaningful on target nodes: agent, judge, human, tool).

type RouterMode

type RouterMode = types.RouterMode

RouterMode represents the routing strategy.

type SchemaDecl

type SchemaDecl struct {
	Name   string
	Fields []*SchemaField
	Span   Span
}

SchemaDecl represents `schema <name>:` followed by field definitions.

type SchemaField

type SchemaField struct {
	Name       string
	Type       FieldType
	EnumValues []string // non-nil only if enum constraint present
	Span       Span
}

SchemaField is a single field in a schema: `name: type [enum: ...]`.

type SessionMode

type SessionMode = types.SessionMode

SessionMode represents the LLM session context strategy.

type Span

type Span struct {
	Start Pos
	End   Pos
}

Span represents a range in a source file.

type ToolNodeDecl

type ToolNodeDecl struct {
	Name    string
	Command string    // command to execute, may contain ${...} env refs and {{...}} template refs
	Input   string    // optional input schema reference name
	Output  string    // schema reference name
	Await   AwaitMode // convergence strategy (none/wait_all/best_effort)
	Span    Span
}

ToolNodeDecl represents a `tool <name>:` node that executes a command directly without an LLM call.

type TypeExpr

type TypeExpr int

TypeExpr enumerates the V1 variable/field types.

const (
	TypeString TypeExpr = iota
	TypeBool
	TypeInt
	TypeFloat
	TypeJSON
	TypeStringArray
)

func (TypeExpr) String

func (te TypeExpr) String() string

type VarField

type VarField struct {
	Name    string
	Type    TypeExpr
	Default *Literal // nil if no default
	Span    Span
}

VarField is a single variable declaration: `name: type [= default]`.

type VarsBlock

type VarsBlock struct {
	Fields []*VarField
	Span   Span
}

VarsBlock represents a top-level or workflow-level `vars:` block.

type WhenClause

type WhenClause struct {
	Condition string // condition identifier (e.g. "approved"); empty when Expr set
	Negated   bool   // true if `when not <condition>`; ignored when Expr set
	Expr      string // raw expression source (e.g. "a && b == 1"); empty when using simple form
	Span      Span
}

WhenClause represents a `when [not] <condition>` or `when <expression>` on an edge. When Expr is non-empty, it is the raw expression source and supersedes Condition/Negated. The simple boolean-field form remains supported for ergonomics; the expression form unlocks compound conditions like `when approved && loop.l.previous_output.approved`.

type WithEntry

type WithEntry struct {
	Key   string // target input field name
	Value string // template string, e.g. "{{outputs.context_builder}}"
	Span  Span
}

WithEntry is a single key-value mapping inside a `with { ... }` block.

type WorkflowDecl

type WorkflowDecl struct {
	Name           string
	Vars           *VarsBlock       // workflow-level variable declarations
	Entry          string           // entry node name
	DefaultBackend string           // workflow-level default backend (empty = not set)
	ToolPolicy     []string         // workflow-level tool policy patterns (nil = open)
	MCP            *MCPConfigDecl   // workflow-level MCP activation/filtering
	Budget         *BudgetBlock     // execution limits (optional)
	Compaction     *CompactionBlock // session compaction defaults for all nodes (optional)
	Interaction    *InteractionMode // workflow-level default interaction mode (nil = not set)
	Worktree       string           // "auto" creates a per-run git worktree; "" or "none" runs in-place
	Edges          []*Edge          // directed edges between nodes
	Span           Span
}

WorkflowDecl represents a `workflow <name>:` declaration.

Jump to

Keyboard shortcuts

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