Documentation
¶
Overview ¶
Package contextvars provides a registry of the special "context variables" injected into scafctl CEL and Go-template evaluation (e.g. _, __self, __item, __plan, __execution, __actions, __cwd, __params, __error, and the Go-template __file* path parts).
No other tool in scafctl enumerates these injected variables or the phase in which each is available: list_cel_functions returns functions, and the solution schema describes shape, not the runtime evaluation environment. This package backs the MCP list_context_variables tool; the "context-variables" concept in pkg/concepts documents the same knowledge in prose and points clients at this tool (it does not import this package).
The canonical variable names are pinned to the celexp.Var* constants where they exist, so the registry cannot silently drift from the names the engine actually injects. The phase/availability metadata is authored here because the engine constants do not carry it.
Index ¶
Constants ¶
const ( // PhaseResolve is a resolver's resolve phase (provider inputs and when). PhaseResolve = "resolve" // PhaseTransform is a resolver's transform phase. PhaseTransform = "transform" // PhaseValidate is a resolver's validate phase. PhaseValidate = "validate" // PhaseForEach is a forEach iteration (resolve or transform). PhaseForEach = "forEach" // PhaseAction is an action's when conditions and inputs. PhaseAction = "action" // PhaseStateBackend is a state backend's input expressions. PhaseStateBackend = "state-backend" // PhaseError is a failure context (continueOnError conditions, error messages). PhaseError = "error" // PhaseTemplateFile is Go-template file generation (directory/render-tree/ // write-tree outputPath rendering). PhaseTemplateFile = "template-file" )
Phase identifiers describe where in evaluation a context variable is available. They are stable strings suitable for filtering (e.g. via the MCP list_context_variables tool's "phase" argument).
const ( // LangCEL means the variable is available in CEL expressions. LangCEL = "cel" // LangTemplate means the variable is available in Go templates. LangTemplate = "go-template" )
Language identifies the expression language a variable applies to.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ContextVariable ¶
type ContextVariable struct {
// Name is the canonical injected variable name, without any accessor
// syntax (e.g. "__self", "__filePath"). In Go templates it is accessed
// with a leading dot ({{ .__filePath }}); in CEL it is used bare (__self).
Name string `json:"name" yaml:"name"`
// Languages lists the expression languages the variable is available in
// (cel, go-template, or both). Most scafctl context variables are injected
// into both CEL evaluation and Go-template data; a few (the __file* path
// parts) are Go-template only.
Languages []string `json:"languages" yaml:"languages"`
// Phases lists the evaluation phases in which the variable is available.
Phases []string `json:"phases" yaml:"phases"`
// Description explains what the variable contains and how to use it.
Description string `json:"description" yaml:"description"`
// Example is a short expression demonstrating the variable.
Example string `json:"example,omitempty" yaml:"example,omitempty"`
}
ContextVariable describes a single injected evaluation variable.
func ByPhase ¶
func ByPhase(phase string) []ContextVariable
ByPhase returns all context variables available in the given phase, sorted by language then name. An unknown phase yields an empty slice. Returned values are deep-copied, so callers cannot mutate the package registry.
func Get ¶
func Get(name string) (ContextVariable, bool)
Get returns a context variable by exact name. The second return value is false if no variable with that name exists. The returned value is deep-copied, so mutating its slices cannot corrupt the package registry.
func List ¶
func List() []ContextVariable
List returns all context variables sorted by language then name. Returned values are deep-copied, so callers cannot mutate the package registry.