capdecl

package
v0.2.64 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MPL-2.0 Imports: 16 Imported by: 1 module, 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 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

View Source
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.

View Source
const (
	EffectRead  = "read"
	EffectWrite = "write"
)

The two things a declaration's `effect` may say.

View Source
const (
	Dir     = "CAPS"
	DeclExt = ".yaml"
)

Reserved top-level directory and the declaration extension.

View Source
const MaxFieldDepth = 3

MaxFieldDepth bounds how deep `fields` and `items` may nest.

View Source
const MaxToolName = 64

MaxToolName is the longest name a model-facing tool may have: what the providers accept.

Variables

View Source
var ErrNotDeclared = errors.New("cap: not declared")

ErrNotDeclared: no active stack of the tenant has a CAPS/<name>.yaml.

Functions

func CheckEntry

func CheckEntry(d *Decl, scopes map[int]bool) error

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

func CheckEntryAs(kind string, d *Decl, scopes map[int]bool) error

CheckEntryAs is CheckEntry with the declaration named as the caller's.

func DeclPath

func DeclPath(name string) string

DeclPath is the stack_files path of a capability's declaration.

func IsCapPath

func IsCapPath(p string) bool

IsCapPath reports whether a stack_files path lives under CAPS/.

func Missing added in v0.2.48

func Missing(fields map[string]Field, doc string) []string

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

func Name(p string) string

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

func ToolName(name string) string

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

func ValidInput(s string) bool

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 ParseDecl

func ParseDecl(data []byte) (*Decl, error)

ParseDecl strictly decodes and validates a capability declaration.

func ParseDeclAs added in v0.2.48

func ParseDeclAs(kind string, data []byte) (*Decl, error)

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) Params

func (d *Decl) Params() []string

Params is the sorted list of the inputs the capability names.

func (*Decl) Returns added in v0.2.48

func (d *Decl) Returns() []string

Returns is the sorted list of the outputs the capability names.

func (*Decl) Stage

func (d *Decl) Stage(stack string) string

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

func (d *Decl) TimeoutDuration() time.Duration

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

func (Field) Typed added in v0.2.59

func (f Field) Typed() bool

Typed reports whether the field says anything about its value's shape. An untyped field accepts anything.

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) Has added in v0.2.59

func (t TypeList) Has(typ string) bool

Has reports whether the list names typ.

func (TypeList) MarshalJSON added in v0.2.59

func (t TypeList) MarshalJSON() ([]byte, error)

MarshalJSON writes one name as a string and several as an array.

func (*TypeList) UnmarshalJSON added in v0.2.59

func (t *TypeList) UnmarshalJSON(b []byte) error

UnmarshalJSON reads what MarshalJSON writes.

func (*TypeList) UnmarshalYAML added in v0.2.59

func (t *TypeList) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML reads a scalar or a sequence of scalars. It is the only custom YAML decoder in a declaration: yaml.v3 loses KnownFields inside one, so Field itself stays a plain struct.

Jump to

Keyboard shortcuts

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