Documentation
¶
Overview ¶
Package capdecl is the declaration of what a stack can do for a run: a named capability, what a caller reads about it, and the input it takes. A program a run grant covers calls a capability by name (`cap://<name>`, chassis/server/capgw); the run's `_grant` stack decides the call; the stack that DECLARES the name runs it, from its start (or from the scope the declaration names).
A stack declares a capability as one small YAML file under the reserved CAPS/ subtree, beside SANDBOXES/ and OUTLETS/:
OPS/<stack>/CAPS/<name>.yaml
The file deploys with `txco apply` as a stack_files row (inline on a single node, fingerprint + CAS on the fleet — the SANDBOXES/ treatment) and is validated at apply. A SANDBOXES/ declaration says what a run MAY call; a CAPS/ declaration says who answers. A tenant's catalogue is the declarations of its active stacks: `txco://caps/list`, `txco caps list`.
This file is the leaf layer: the reserved-path vocabulary, with no dependency on stores, so the CLI, the admin producer and the control-event applier can import it cheaply.
Index ¶
- Constants
- Variables
- func CheckEntry(d *Decl, scopes map[int]bool) error
- func CheckEntryAs(kind string, d *Decl, scopes map[int]bool) error
- func DeclPath(name string) string
- func IsCapPath(p string) bool
- func Missing(fields map[string]Field, doc string) []string
- func Name(p string) string
- func ToolName(name string) string
- func ValidInput(s string) bool
- type Decl
- type Field
- type InputField
- type TypeList
Constants ¶
const ( // MaxInputs bounds the inputs one capability names; MaxOutputs the // outputs it promises. MaxInputs = 32 MaxOutputs = 32 // MaxDescription bounds the capability's description: it is what a // model reads to decide whether to call, so it is longer than a note. MaxDescription = 2048 // MaxInputDescription bounds one input's or output's description. MaxInputDescription = 512 // MaxTimeout bounds the declared timeout, in milliseconds. The inlet's // own ceiling still applies; a declaration can only shorten the wait. MaxTimeout = 3600000 )
Ceilings on one declaration.
const ( EffectRead = "read" EffectWrite = "write" )
The two things a declaration's `effect` may say.
const ( Dir = "CAPS" DeclExt = ".yaml" )
Reserved top-level directory and the declaration extension.
const MaxFieldDepth = 3
MaxFieldDepth bounds how deep `fields` and `items` may nest.
const MaxToolName = 64
MaxToolName is the longest name a model-facing tool may have: what the providers accept.
Variables ¶
var ErrNotDeclared = errors.New("cap: not declared")
ErrNotDeclared: no active stack of the tenant has a CAPS/<name>.yaml.
Functions ¶
func CheckEntry ¶
CheckEntry reports whether the declaration's entry names a scope the stack has. scopes is the set of scope numbers of the declaring stack. No entry is the stack's start, which any stack with a scope has.
func CheckEntryAs ¶ added in v0.2.48
CheckEntryAs is CheckEntry with the declaration named as the caller's.
func Missing ¶ added in v0.2.48
Missing is the sorted list of the required fields that doc, a JSON object, lacks: absent, or present as null, unless the field's type allows null (`type: [string, "null"]`), in which case an explicit null is a value. An empty list means doc has every field the declaration requires; it says nothing else about their shape, which is a schema check's (InputSchema with jsonschemax).
func Name ¶
Name returns the capability a declaration path belongs to: "CAPS/local.web.fetch.yaml" → "local.web.fetch". It returns "" when the path is not under CAPS/, is nested, has the wrong extension, or names an invalid capability — the same shape validateStackFilePath enforces at upload. A capability name holds dots, so the extension is trimmed off the end rather than cut at the first dot.
func ToolName ¶ added in v0.2.59
ToolName is the model-facing name of the capability called name: the capability's name with every `.` as `_`, which every provider accepts. A name that would pass 64 characters keeps its first 55, then `_` and 8 hex digits of its SHA-256, so it stays deterministic. Two capabilities can derive one tool name (`web.search` and `web_search`); lint, activation and the catalogue refuse that.
func ValidInput ¶
ValidInput reports whether s may name an input or an output.
Types ¶
type Decl ¶
type Decl struct {
Description string `yaml:"description"`
Entry int `yaml:"entry"`
Input map[string]Field `yaml:"input"`
Output map[string]Field `yaml:"output"`
Timeout int `yaml:"timeout"`
Effect string `yaml:"effect"`
// contains filtered or unexported fields
}
Decl is one CAPS/<name>.yaml: who answers a capability, what it takes and what it answers. The file's existence is the declaration — the stack that holds it answers the capability — and every key is optional. Only what the chassis reads is declared here; a key it does not read is a deploy error, not a promise.
description: Send a message by email. # what a caller reads
input: # what the call carries
to:
description: the recipient's address
required: true
subject: {}
output: # what the answer carries
mid:
description: the message id
required: true
timeout: 60000 # ms; shortens the wait
entry: 7000 # see below
A call ENTERS THE STACK AT ITS START, `<stack>/0`, like every other inlet's run (`_cron/0`, `_mail/0`): the stack's scopes run in order and their WHENs pick the call up (`@src == "cap"`, `@cap.name`). `entry` is for a stack that does other work too and wants a capability's run to begin further in: it names the scope of THIS stack the run starts from.
The same shape declares an ENTRY a call may name (CALLS/<name>.yaml, chassis/calldecl): there `input` is checked before the callee runs and `output` after it ends. On a capability, `output` is checked the same way when the answer comes; `input` is what a caller reads, and the stack's own rules decide what a call without it gets.
`effect` says what a call of the capability does to the world outside the run that makes it: `read` or `write`. It is what a caller that makes several calls needs to know before it decides how to make them, and it is a PROMISE of the stack's, not something the chassis checks:
read the call can run beside other calls, and it can run again. It
changes nothing a second call, or a neighbour's call, would see:
no record written, nothing sent, nothing marked as seen.
write anything else. A capability that keeps only one of the two
promises of `read` is a write.
Absent, the declaration says nothing, and the catalogue reports nothing: what silence means is the reader's to decide (a careful one reads it as write). The chassis itself reads the key nowhere: every call is decided and run the same whichever it says. A call entry (CALLS/) is not a tool and takes no `effect` (calldecl refuses it).
Parsed strictly: an unknown key is a deploy error, not a silent ignore.
func ParseDeclAs ¶ added in v0.2.48
ParseDeclAs is ParseDecl with the declaration named as the caller's: a call entry's errors say "call declaration".
func (*Decl) InputSchema ¶ added in v0.2.59
func (d *Decl) InputSchema() json.RawMessage
InputSchema is the declaration's input as a JSON Schema object: one property per field, the required ones listed, unknown keys refused. An untyped field is `{description}` and accepts any value, so a declaration written before types existed yields a valid schema with no edit. The catalogue hands this to a model as a tool's parameters.
func (*Decl) OutputSchema ¶ added in v0.2.59
func (d *Decl) OutputSchema() json.RawMessage
OutputSchema is the declaration's output in the same shape.
func (*Decl) Returns ¶ added in v0.2.48
Returns is the sorted list of the outputs the capability names.
func (*Decl) Stage ¶
Stage is where a call enters: "<stack>/<entry>", the shape a stage jump takes (processor.StagePartsRE) — "<stack>/0", the stack's start, when no entry is declared.
func (*Decl) TimeoutDuration ¶
TimeoutDuration is the declared timeout; zero means the inlet's ceiling.
type Field ¶ added in v0.2.48
type Field struct {
Description string `yaml:"description" json:"description,omitempty"`
Required bool `yaml:"required" json:"required,omitempty"`
Type TypeList `yaml:"type" json:"type,omitempty"`
Enum []any `yaml:"enum" json:"enum,omitempty"`
Default any `yaml:"default" json:"default,omitempty"`
Minimum *float64 `yaml:"minimum" json:"minimum,omitempty"`
Maximum *float64 `yaml:"maximum" json:"maximum,omitempty"`
MinLength *int `yaml:"min_length" json:"min_length,omitempty"`
MaxLength *int `yaml:"max_length" json:"max_length,omitempty"`
Pattern string `yaml:"pattern" json:"pattern,omitempty"`
Items *Field `yaml:"items" json:"items,omitempty"`
Fields map[string]Field `yaml:"fields" json:"fields,omitempty"`
Schema map[string]any `yaml:"schema" json:"schema,omitempty"`
}
Field is one input a capability takes, or one output it answers with: what a caller reads (the description), whether a call must carry it, and optionally its shape, with the keys JSON Schema uses (field.go). A field with no typed key accepts any value.
query:
type: string # or [string, "null"] for a value that may be null
max_length: 500
description: a few words
required: true
count:
type: integer
minimum: 1
maximum: 20
default: 10 # an annotation: what the stack assumes; never filled in
tags:
type: array
items: {type: string}
options:
type: object
fields: {verbose: {type: boolean}}
part:
schema: {anyOf: [{type: integer}, {type: string, enum: [last]}]} # raw JSON Schema, alone
type InputField ¶
type InputField = Field
InputField is the name Field had when a declaration named inputs only.
type TypeList ¶ added in v0.2.59
type TypeList []string
TypeList is a field's `type`: one JSON Schema type name, or a list of them (`[string, "null"]` for a field that may be explicitly null). It reads a YAML scalar or sequence, and writes JSON as a string when it holds one name and as an array otherwise, which is what a schema wants.
func (TypeList) MarshalJSON ¶ added in v0.2.59
MarshalJSON writes one name as a string and several as an array.
func (*TypeList) UnmarshalJSON ¶ added in v0.2.59
UnmarshalJSON reads what MarshalJSON writes.