intent

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 35 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 intent loads intent manifests from the bundled profile and the user's layers into one registry; import it as intentload.

Index

Constants

View Source
const ActionsFile = "actions.toml"

ActionsFile is the profile file that words the built-in actions.

View Source
const DefaultChanged = "The head moved since the question: re-check what changed before acting on the answer."

DefaultChanged is resume.changed when a manifest leaves it out: the generic sentence of resume.md.tmpl.

View Source
const DefaultsFile = "defaults.toml"

DefaultsFile is the profile file of the manifests' defaults, read from the bundled profile and then each layer, a later layer's key winning.

View Source
const WhyName = "manifest.why"

The names the manifest's other inline templates are parsed under in an intent's template set.

Variables

View Source
var ActionFuncs = template.FuncMap{"join": strings.Join, "name": func() string { return brand.Name }, "command": func() string { return brand.Command }}

ActionFuncs are the functions action texts may call.

View Source
var ActionsSchema []byte

ActionsSchema is the JSON Schema of actions.toml, for editors.

View Source
var ConfigSchema []byte

ConfigSchema is the JSON Schema of config.json, for editors.

View Source
var Schema []byte

Schema is the JSON Schema of intent.toml, for editors (Taplo's #:schema directive).

View Source
var WorkflowSchema []byte

WorkflowSchema is the JSON Schema of workflow.toml, for editors.

Functions

func ActionFactMap

func ActionFactMap(get func(name string) any) map[string]any

ActionFactMap nests dotted action facts into the map action texts execute over: {"pr": {"slug": ...}, "row": {"question": ...}}.

func ActionText added in v0.2.0

func ActionText(path, src string, sample map[string]any) (*template.Template, error)

ActionText parses an action text named path and executes it once over sample, so a text that cannot render fails at load.

func DraftActionFactMap added in v0.2.0

func DraftActionFactMap(get func(name string) any) map[string]any

DraftActionFactMap is ActionFactMap for the texts of a draft's actions.

func HeadlineName

func HeadlineName(i int) string

HeadlineName is the name a headline text is parsed under in an intent's template set: "headline.resumed", "headline.new[0]", ...

func Load

func Load(layers []profile.Layer, bundled fs.FS, base *template.Template, check TemplateCheck) (*Loaded, Problems)

Load reads intents/ of the bundled FS and of each directory layer; check may be nil. The partials under partials/ of each directory layer are parsed over base's; one that does not parse, or that a problem names, is left out and the bundled partials load instead. Layers with an empty Dir are skipped: the bundled intents come from bundled only. A user directory named as a bundled intent overrides its files one by one; when the result does not load, the bundled intent stays and the problems name the user's files.

func NestFacts added in v0.2.0

func NestFacts(env expr.Env, get func(name string) any) map[string]any

NestFacts nests the dotted facts of env into the map an inline template executes over, {"pr": {"slug": ...}}, each read by get; a fact get has no value for reads as its type's zero value.

func OverlayDraftApproval added in v0.2.0

func OverlayDraftApproval(base *draft.Policy, o ApprovalOverlay, env expr.Env) (draft.Policy, error)

OverlayDraftApproval is base, a workflow's draft policy (nil: wait), with o laid over it, o's rules compiled over env. The merged policy is validated.

func OverlayRunApproval added in v0.2.0

func OverlayRunApproval(a workflow.Approval, o ApprovalOverlay, env expr.Env) (workflow.Approval, error)

OverlayRunApproval is a, a workflow's run approval, with o laid over it, o's rules compiled over env, the workflow's facts. The merged approval is validated, and a releasing rule of o may not read an untrusted fact.

func RefusalText added in v0.2.0

func RefusalText(i int) string

RefusalText is the ActionTexts key of the why of refusal i.

func RefuseWhyName added in v0.2.0

func RefuseWhyName(i int) string

RefuseWhyName is the name refuse[i].why is parsed under.

func SampleActionFacts

func SampleActionFacts() map[string]any

SampleActionFacts is the action fact map with every fact set, for checking texts.

func SampleDraftActionFacts added in v0.2.0

func SampleDraftActionFacts() map[string]any

SampleDraftActionFacts is SampleActionFacts for a draft's actions.

func TurnEnv added in v0.2.0

func TurnEnv(d dintent.Def) expr.Env

TurnEnv is the env an intent's turn predicates and inline texts read: the turn slot's facts and its inputs, turn.stage only with the stage dimension.

Types

type ActionPrograms added in v0.2.0

type ActionPrograms struct {
	When    *expr.Program
	Primary *expr.Program
	Refuse  []RefusalProgram
	// ActionTexts are note, warning, confirm and each refusal's why
	// ("refuse[<i>].why"), over the action fact map.
	ActionTexts map[string]*template.Template
}

ActionPrograms are an intent's compiled [action] predicates and texts.

type ApprovalOverlay added in v0.2.0

type ApprovalOverlay struct {
	Mode   string
	Window *time.Duration
	Rules  []RuleOverlay
}

ApprovalOverlay is the configuration's approval block of a workflow, laid over its manifest's field by field: a set Mode or Window replaces that field, and non-nil Rules replace the rules, an empty list clearing them. A Mode other than delay drops the manifest's window, which JSON cannot unset.

type BuiltinAction added in v0.2.0

type BuiltinAction struct {
	Label, Summary string
	Input          struct{ Label, Help string }
	// Texts are note, warning, confirm and why, parsed; a text the table
	// leaves empty is absent.
	Texts map[string]*template.Template
}

BuiltinAction is a built-in action's texts, from its actions.toml table.

func (BuiltinAction) Render added in v0.2.0

func (a BuiltinAction) Render(name string, facts map[string]any) (string, error)

Render is text name of a over facts, "" when a has none.

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache reloads when the newest mtime under the user layer's intents/ and blocks changes; safe for concurrent use.

func NewCache

func NewCache(layers func() []profile.Layer, bundled fs.FS, base *template.Template, check TemplateCheck, opts CacheOptions) *Cache

func (*Cache) Get

func (c *Cache) Get() *Loaded

type CacheOptions

type CacheOptions struct {
	// Recheck is how long a stamp is trusted before the layers are walked again.
	Recheck time.Duration
	// Now is the clock; time.Now when nil.
	Now func() time.Time
	// LoadTree reads the profile tree of a Loaded; profile.Load when nil.
	LoadTree func([]profile.Layer, *dintent.Registry, []dintent.Name) (profile.Tree, error)
	// OnReload is called, holding no lock, after Get replaces the loaded registry with a changed one; the first load is not a reload.
	OnReload func()
}

CacheOptions tune a Cache; the zero value rechecks the stamp on every Get.

type Loaded

type Loaded struct {
	Registry  *dintent.Registry
	Templates map[dintent.Name]*template.Template // body on a clone of base, missingkey=error
	Programs  map[dintent.Name]Programs
	Problems  Problems                  // user intents that did not load, and overrides read as bundled
	Broken    map[dintent.Name]Problems // user intents that failed, keyed by directory name
	Reverted  map[dintent.Name]Problems // bundled intents read without the user's override, which does not load
	// Warnings are what the loaded intents and workflows declare that loads
	// but is deprecated.
	Warnings Problems

	Workflows       []workflow.Workflow // by order, then name; a user workflow that failed is not here
	BrokenWorkflows map[string]Problems // user workflows that failed, keyed by directory name
	// RevertedWorkflows are bundled workflows read without the user's override, which does not load.
	RevertedWorkflows map[string]Problems

	// Actions are the built-in actions' texts from actions.toml, by catalog id.
	Actions map[string]BuiltinAction
	// EmptyRefusal is what a [[refuse]] case whose why renders empty says,
	// from defaults.toml.
	EmptyRefusal string
	// contains filtered or unexported fields
}

func (*Loaded) BrokenNames

func (l *Loaded) BrokenNames() []dintent.Name

BrokenNames is the kinds whose blocks are skipped, sorted: the user intents that did not load, and the kinds whose blocks need what a reverted override declared.

func (*Loaded) Refusal added in v0.2.0

func (l *Loaded) Refusal(name dintent.Name, facts map[string]any) (string, error)

Refusal is the why of the intent name's first refusal whose when holds over facts, the unit's workflow facts, never empty when one holds; "" when none holds.

func (*Loaded) Rules

func (l *Loaded) Rules(intent string) (dintent.RecordRules, error)

Rules is intent's record rules; for a broken user intent the error carries its first problem.

func (*Loaded) Tree

func (l *Loaded) Tree() (profile.Tree, error)

Tree is the profile's blocks as of this load, read on the first call and kept; an unreadable block is the error every call returns.

func (*Loaded) Why added in v0.2.0

func (l *Loaded) Why(name dintent.Name, facts map[string]any) (string, error)

Why renders the why of the intent name over facts, the unit's workflow facts; "" for an intent without one.

type Problem

type Problem struct {
	File      string
	Line, Col int
	Field     string // "inputs.self_review.persist", "action.enabled"
	Msg       string
	Snippet   string // a predicate problem's expression and caret line; Error leaves it out
}

type Problems

type Problems []Problem

func (Problems) Error

func (p Problems) Error() string

Error is the problems sorted, one "file:line:col: field: msg" per line; a problem with no line (a whole directory) reads "dir: msg".

func (Problems) Sorted

func (p Problems) Sorted() Problems

Sorted is the problems by file, line, column, field and message.

type Programs

type Programs struct {
	Records  *expr.Program
	Headline []*expr.Program // per Headline.New case; nil for the unconditional last case
	Also     []*expr.Program
	// Refuse are the refusals' when, per Refuse of the definition.
	Refuse []*expr.Program
	Action ActionPrograms
}

type RefusalProgram added in v0.2.0

type RefusalProgram struct {
	When *expr.Program
}

RefusalProgram is an [[action.refuse]] case's compiled when.

type RuleOverlay added in v0.2.0

type RuleOverlay struct {
	When, Mode string
	Window     time.Duration
}

RuleOverlay is one rule of an ApprovalOverlay.

type TemplateCheck

type TemplateCheck func(d dintent.Def, t *template.Template) []Problem

TemplateCheck renders a manifest's templates against real samples; internal/turn provides it.

Directories

Path Synopsis
Package builtin is the Go vocabulary manifests name: builtins by slot, reserved names and keys, and the facts predicates read.
Package builtin is the Go vocabulary manifests name: builtins by slot, reserved names and keys, and the facts predicates read.
cmd/factsdoc command
Command factsdoc prints the facts reference page: the intents' facts and the workflow facts, each grouped by slot, the draft approval facts, the workflow steps, then the draft effects.
Command factsdoc prints the facts reference page: the intents' facts and the workflow facts, each grouped by slot, the draft approval facts, the workflow steps, then the draft effects.
cmd/grammardoc command
Command grammardoc writes what the grammar table derives: the JSON schemas of the profile files and the configuration, the generated tables of the manifest and configuration reference pages, and the language page.
Command grammardoc writes what the grammar table derives: the JSON schemas of the profile files and the configuration, the generated tables of the manifest and configuration reference pages, and the language page.
Package expr compiles and evaluates the predicates of intent and workflow manifests: CEL expressions (cel-go) over typed facts, checked at load.
Package expr compiles and evaluates the predicates of intent and workflow manifests: CEL expressions (cel-go) over typed facts, checked at load.

Jump to

Keyboard shortcuts

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