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
- Variables
- func Dump(f *File) string
- func DumpExpr(e Expr) string
- func FormatAllow(preds []*AllowPredicate) string
- func IsDecimalNumber(value string) bool
- func PlanExpiry(text string) (time.Duration, error)
- func PlanPathError(p string) string
- func SamePlanPath(a, b string) bool
- type AllowPredicate
- type Assignment
- type Attribute
- type Binary
- type BodyLine
- type CondBranch
- type Conditional
- type Constraint
- type ConstraintKind
- type DepCall
- type Expr
- type File
- type FuncCall
- type Import
- type Mod
- type Node
- type Param
- type ParamKind
- type PlanSpec
- type Setting
- type StringLit
- type Task
- func (t *Task) AgentPolicy() []*AllowPredicate
- func (t *Task) AppliesPlan() string
- func (t *Task) Attr(kind string) *Attribute
- func (t *Task) AvailableOn(goos string) bool
- func (t *Task) Edges() []*DepCall
- func (t *Task) IsPrivate() bool
- func (t *Task) OSFilters() []string
- func (t *Task) ParamDoc(name string) string
- func (t *Task) PlanSpec() *PlanSpec
- func (t *Task) Returns() string
- func (t *Task) Span() token.Span
- type VarRef
Constants ¶
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.
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.
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).
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 ¶
var KnownAttributes = []string{ AttrPrivate, AttrConfirm, AttrGroup, AttrParallel, AttrLinux, AttrMacos, AttrWindows, AttrUnix, AttrNoCD, AttrWorkingDirectory, AttrEnv, AttrDoc, AttrScript, AttrCache, AttrNetwork, AttrNoExitMessage, AttrContext, AttrParamDoc, AttrReturns, AttrReadonly, AttrAgentAllow, AttrPlan, AttrApplies, }
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.
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 ¶
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 ¶
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
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
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
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
SamePlanPath reports whether two [plan] paths name one file.
Types ¶
type AllowPredicate ¶ added in v0.10.0
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 ¶
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.
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.
type CondBranch ¶
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 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).
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.
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.
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.
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.
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
AppliesPlan returns the plan task named by the task's first [applies], or "" when the task applies no plan.
func (*Task) AvailableOn ¶ added in v0.5.0
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
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 ¶
IsPrivate reports whether the task carries the [private] attribute or a name beginning with '_'.
func (*Task) OSFilters ¶ added in v0.5.0
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
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
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.