ast

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ast defines the Runefile abstract syntax tree produced by the parser and consumed by the analyzer, evaluator, scheduler, cache, and MCP server. Every node carries a token.Span so any diagnostic can point at precise source (Principle II).

Index

Constants

View Source
const (
	ExecSh     = "sh"
	ExecPython = "python"
	ExecNode   = "node"
	ExecAgent  = "agent"
)

Executor names for the built-in body languages. The empty string means the default shell executor; any other non-built-in string is a custom executor.

View Source
const (
	AttrPrivate          = "private"
	AttrConfirm          = "confirm"
	AttrGroup            = "group"
	AttrParallel         = "parallel"
	AttrLinux            = "linux"
	AttrMacos            = "macos"
	AttrWindows          = "windows"
	AttrUnix             = "unix"
	AttrNoCD             = "no-cd"
	AttrWorkingDirectory = "working-directory"
	AttrEnv              = "env"
	AttrDoc              = "doc"
	AttrScript           = "script"
	AttrCache            = "cache"
	AttrNetwork          = "network"         // sets MCP openWorldHint
	AttrNoExitMessage    = "no-exit-message" // suppress the trailing error banner
	AttrContext          = "context"         // project-health hook injected into agent context (spec 021)
	AttrParamDoc         = "param-doc"       // per-parameter description surfaced in agent tool schemas (spec 023)
	AttrReturns          = "returns"         // task outcome description surfaced to agents and listings (spec 023)
	AttrReadonly         = "readonly"        // claims read-only: sets MCP readOnlyHint
	AttrAgentAllow       = "agent-allow"     // limits the values an agent may run the task with (spec 050)
	AttrPlan             = "plan"            // the task makes a plan file that Rune stores (spec 051)
	AttrApplies          = "applies"         // the task applies the stored plan of the named plan task (spec 051)
)

Attribute kinds.

View Source
const (
	PlanFileVar   = "RUNE_PLAN_FILE"
	PlanIDVar     = "RUNE_PLAN_ID"
	PlanDigestVar = "RUNE_PLAN_DIGEST"
)

The variables Rune gives the body of a task that applies a plan (spec 051).

View Source
const (
	DefaultPlanExpiry = time.Hour
	MinPlanExpiry     = time.Minute
	MaxPlanExpiry     = 7 * 24 * time.Hour
)

The expiry of a stored plan: the default, and the range [plan(expires=...)] may set.

Variables

KnownAttributes is the canonical accepted attribute set, in documentation order. The language registry is checked against it (language's TestRegistryMatchesASTAttributes) and so is the parser's attribute switch (parser's TestParserKnowsAllASTAttributes), so neither can drift silently.

View Source
var SupportedConstraintKinds = []string{"string", "number", "boolean", "path", "raw", "enum"}

SupportedConstraintKinds lists the kind names accepted after `:` in a parameter annotation, in the order diagnostics cite them.

Functions

func Dump

func Dump(f *File) string

Dump renders a File as a stable, indented tree. It is used by golden AST tests and for ad-hoc debugging; it is deterministic (declaration order preserved).

func DumpExpr

func DumpExpr(e Expr) string

DumpExpr renders an expression in the same compact form Dump uses (exported for --dump JSON output).

func FormatAllow added in v0.10.0

func FormatAllow(preds []*AllowPredicate) string

FormatAllow renders [agent-allow] predicates in canonical source form, `env="staging", region="eu-west-1"`: the one renderer shared by the dumper and the formatter.

func IsDecimalNumber added in v0.7.0

func IsDecimalNumber(value string) bool

IsDecimalNumber reports whether value is a plain decimal number — integers and decimals with an optional exponent, the documented `:number` contract. It rejects the extra spellings strconv.ParseFloat tolerates (NaN, ±Inf, hex floats, digit-separating underscores), none of which a JSON `number` can carry, so the CLI, dependency, and MCP paths accept the same set. mcpserver mirrors this rule; TestParamCheckMatchesASTConstraint pins the two.

func PlanExpiry added in v0.10.0

func PlanExpiry(text string) (time.Duration, error)

PlanExpiry reads the expires argument of [plan]: a duration from MinPlanExpiry to MaxPlanExpiry, or DefaultPlanExpiry when text is empty.

func PlanPathError added in v0.10.0

func PlanPathError(p string) string

PlanPathError says why p cannot be a file or summary path of [plan], or "" when it can. The rule reads the text only, so one Runefile is valid or not on every host: filepath.IsAbs would accept C:/x on Linux and /x on Windows.

func SamePlanPath added in v0.10.0

func SamePlanPath(a, b string) bool

SamePlanPath reports whether two [plan] paths name one file.

Types

type AllowPredicate added in v0.10.0

type AllowPredicate struct {
	Name    string
	Value   string
	NameSp  token.Span
	ValueSp token.Span
}

AllowPredicate is one name="value" of an attribute. In [agent-allow] it is a parameter and the one value an agent run of the task may have for it (spec 050). In [plan] it is one argument (spec 051). The two spans let a diagnostic point at the part that is wrong.

type Assignment

type Assignment struct {
	Name string
	Expr Expr
	Sp   token.Span
}

Assignment is a module-level variable binding `NAME := EXPR`.

func (*Assignment) Span

func (a *Assignment) Span() token.Span

type Attribute

type Attribute struct {
	Kind       string
	Str        string // confirm prompt, group name, doc, script cmd, working-directory, env name
	Str2       string // env value
	Inputs     []Expr // cache(inputs=[...])
	Outputs    []Expr // cache(outputs=[...])
	HasOutputs bool
	Allow      []*AllowPredicate // named string arguments of agent-allow(...) and plan(...), in source order
	Sp         token.Span
}

Attribute is a `[name(args)]` annotation on a task. Most attributes carry a single string argument (Str); env carries two (Str, Str2); cache carries input/output glob lists; agent-allow and plan carry named string arguments.

func (*Attribute) Span

func (a *Attribute) Span() token.Span

type Binary

type Binary struct {
	Op    token.Kind // PLUS or SLASH
	Left  Expr
	Right Expr
	Sp    token.Span
}

Binary is a concatenation (+) or path-join (/) expression.

func (*Binary) Span

func (e *Binary) Span() token.Span

type BodyLine

type BodyLine struct {
	Raw             string
	NoEcho          bool // leading @
	ContinueOnError bool // leading -
	Sp              token.Span
}

BodyLine is one line of a task body, with leading-sigil flags stripped. Raw retains {{ ... }} interpolation placeholders for the evaluator.

func (*BodyLine) Span

func (b *BodyLine) Span() token.Span

type CondBranch

type CondBranch struct {
	Left   Expr
	Op     token.Kind // EQ, NEQ, MATCH
	Right  Expr
	Result Expr
}

CondBranch is one `if/else if` clause: Left Op Right { Result }.

type Conditional

type Conditional struct {
	Branches []CondBranch
	Else     Expr
	Sp       token.Span
}

Conditional is an if/else-if/else expression. It always has a final Else.

func (*Conditional) Span

func (e *Conditional) Span() token.Span

type Constraint added in v0.7.0

type Constraint struct {
	Kind     ConstraintKind
	KindName string   // as written; unknown names are the analyzer's to reject
	Values   []string // KindEnum only; ≥1 (parser), unique (analyzer), source order
	Sp       token.Span
}

Constraint is an author-declared value rule on one parameter, written inline as `name:kind` or `name:enum("v1","v2")`. Kind is resolved from KindName when the name is a known kind; an unknown KindName is a semantic error (RUNE2012), reported before anything executes, so Check never runs for one.

func (*Constraint) Check added in v0.7.0

func (c *Constraint) Check(value string) error

Check validates one bound value against the constraint. It is the single source of truth for every invocation path (spec 023 FR-005): CLI positional, MCP named, and dependency parenthesized arguments. The error text carries the accepted set; callers prefix the task, parameter, and offending value (FR-006). A nil constraint accepts anything.

func (*Constraint) Span added in v0.7.0

func (c *Constraint) Span() token.Span

func (*Constraint) String added in v0.7.0

func (c *Constraint) String() string

String renders the annotation in canonical source form, e.g. `:number` or `:enum("staging","prod")` — the one renderer shared by the formatter, the AST dumper, and editor signatures so the three can never drift.

type ConstraintKind added in v0.7.0

type ConstraintKind int

ConstraintKind classifies an inline parameter type annotation (spec 023).

const (
	KindString  ConstraintKind = iota // explicit spelling of the default
	KindNumber                        // integers and decimals (ParseFloat 64)
	KindBoolean                       // exactly "true" | "false"
	KindPath                          // non-empty string; role marker only
	KindEnum                          // closed set of static string literals
	KindRaw                           // any value, split into shell words on purpose (spec 030)
)

func ConstraintKindFromName added in v0.7.0

func ConstraintKindFromName(name string) (ConstraintKind, bool)

ConstraintKindFromName resolves a kind name (a contextual keyword, matched case-sensitively) to its ConstraintKind.

type DepCall

type DepCall struct {
	Name string // may be namespaced (mod::task)
	Args []Expr
	Sp   token.Span
}

DepCall is a dependency or post-hook invocation.

func (*DepCall) Span

func (d *DepCall) Span() token.Span

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

Expr is implemented by every expression node.

type File

type File struct {
	Path        string
	Settings    []*Setting
	Assignments []*Assignment
	Tasks       []*Task
	Imports     []*Import
	Mods        []*Mod
	Sp          token.Span
}

File is the root of one parsed Runefile. A project may be a tree of Files via import (spliced) and mod (namespaced).

func (*File) Span

func (f *File) Span() token.Span

type FuncCall

type FuncCall struct {
	Name string
	Args []Expr
	Sp   token.Span
}

FuncCall is a built-in function call.

func (*FuncCall) Span

func (e *FuncCall) Span() token.Span

type Import

type Import struct {
	Path     string // decoded string-literal path
	Optional bool   // import?
	Sp       token.Span
}

Import splices another file's definitions into the current namespace.

func (*Import) Span

func (i *Import) Span() token.Span

type Mod

type Mod struct {
	Name string
	Path string // optional explicit path; "" => derive from name
	Sp   token.Span
}

Mod loads another file as a child namespace addressable as name::task.

func (*Mod) Span

func (m *Mod) Span() token.Span

type Node

type Node interface {
	Span() token.Span
}

Node is implemented by every AST node.

type Param

type Param struct {
	Name       string
	Kind       ParamKind
	Default    Expr        // only for ParamDefaulted
	Constraint *Constraint // nil = unannotated (the pre-023 shape)
	Sp         token.Span
}

Param is a positional task parameter.

func (*Param) Span

func (p *Param) Span() token.Span

type ParamKind

type ParamKind int

ParamKind classifies a task parameter.

const (
	ParamRequired     ParamKind = iota // name
	ParamDefaulted                     // name=expr
	ParamVariadicPlus                  // +name (one or more)
	ParamVariadicStar                  // *name (zero or more)
)

type PlanSpec added in v0.10.0

type PlanSpec struct {
	File, Summary, Tool, Expires string
}

PlanSpec is what [plan(...)] says about the plan a task makes (spec 051). Expires is the text as written. PlanExpiry reads it.

type Setting

type Setting struct {
	Name  string
	Value Expr   // nil for the bare boolean form
	List  []Expr // populated for list-valued settings
	Bool  bool   // true for the bare form
	Sp    token.Span
}

Setting is a `set NAME [:= VALUE]` directive. The bare form (`set export`) is boolean true (Bool=true, Value=nil). List-valued settings (e.g. `set shell`) keep their elements in List.

func (*Setting) Span

func (s *Setting) Span() token.Span

type StringLit

type StringLit struct {
	Value string
	Sp    token.Span
}

StringLit is a decoded string literal.

func (*StringLit) Span

func (e *StringLit) Span() token.Span

type Task

type Task struct {
	Name       string
	Doc        string // from the preceding comment run or [doc("...")]
	Params     []*Param
	Executor   string // "" => default sh
	Deps       []*DepCall
	PostHooks  []*DepCall // run after, on success (&&)
	FailHooks  []*DepCall // run after, on failure (||)
	Attributes []*Attribute
	Body       []*BodyLine
	Sp         token.Span
}

Task is a named recipe.

func (*Task) AgentPolicy added in v0.10.0

func (t *Task) AgentPolicy() []*AllowPredicate

AgentPolicy returns the predicates an agent run of the task must meet, or nil when the task has no [agent-allow]. Only the first attribute counts: a second one is a static error (RUNE2019), and must never widen the first.

func (*Task) AppliesPlan added in v0.10.0

func (t *Task) AppliesPlan() string

AppliesPlan returns the plan task named by the task's first [applies], or "" when the task applies no plan.

func (*Task) Attr

func (t *Task) Attr(kind string) *Attribute

Attr returns the first attribute of the given kind, or nil.

func (*Task) AvailableOn added in v0.5.0

func (t *Task) AvailableOn(goos string) bool

AvailableOn reports whether the task may run on the given GOOS. A task with no OS attribute is available everywhere; multiple OS attributes combine as OR; "unix" matches every GOOS except "windows". This is the single availability rule shared by listing, completion, MCP exposure, root resolution, and dependency scheduling.

func (*Task) Edges added in v0.6.0

func (t *Task) Edges() []*DepCall

Edges returns every outgoing task reference of t: dependencies, && post- hooks, and || failure hooks — the single edge-set definition shared by dependency resolution, cycle detection, context closure walks, and editor navigation, so a new clause kind cannot be missed by one of them.

func (*Task) IsPrivate

func (t *Task) IsPrivate() bool

IsPrivate reports whether the task carries the [private] attribute or a name beginning with '_'.

func (*Task) OSFilters added in v0.5.0

func (t *Task) OSFilters() []string

OSFilters returns the task's OS attribute kinds in source order, or nil when the task is unrestricted.

func (*Task) ParamDoc added in v0.7.0

func (t *Task) ParamDoc(name string) string

ParamDoc returns the [param-doc("name","text")] description for the named parameter, or "" when the parameter carries none (spec 023 FR-014).

func (*Task) PlanSpec added in v0.10.0

func (t *Task) PlanSpec() *PlanSpec

PlanSpec returns the arguments of the task's first [plan], or nil. The analyzer rejects a second one, an unknown argument and a repeated one.

func (*Task) Returns added in v0.7.0

func (t *Task) Returns() string

Returns reports the task's [returns("...")] outcome description, or "" (spec 023 FR-009). Advisory only: Rune never compares task output to it.

func (*Task) Span

func (t *Task) Span() token.Span

type VarRef

type VarRef struct {
	Name string
	Sp   token.Span
}

VarRef is a bare name reference. Resolution (param vs module variable) is performed by the analyzer/evaluator; params shadow variables.

func (*VarRef) Span

func (e *VarRef) Span() token.Span

Jump to

Keyboard shortcuts

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