capability

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT, MIT Imports: 11 Imported by: ? 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 capability supplies host-neutral capability descriptors, exact-match scope narrowing and safe typed application failures. Hosts own identity, policy, approval and operation implementations. Catalog discovery grants no permission. Transport adapters must enforce current authority before effects.

Index

Constants

View Source
const (
	ReadonlyQuery    = "readonly.query"
	ContextSource    = "context.source"
	DurableAgentWake = "durable_agent.wake"
	ReflexSeed       = "reflex.seed"
	MCPReach         = "mcp.reach"
	StorageRead      = "storage.read"
	StorageWrite     = "storage.write"
	SecretsRead      = "secrets.read"
	EgressRequest    = "egress.request"
	EventsPublish    = "events.publish"
	LogWrite         = "log.write"
)
View Source
const ContractVersion = 1

ContractVersion versions the explicit grant contract, independently of the subprocess protocol and each capability descriptor's schema version.

View Source
const HostRPCErrorCode = -32010
View Source
const MaxSafeInteger uint64 = 9007199254740991

MaxSafeInteger is the maximum generation representable exactly by Go and JS.

Variables

This section is empty.

Functions

func CheckNarrowing

func CheckNarrowing(name string, previous, next Scope) error

CheckNarrowing rejects an attempted widening by capability name. New empty dimensions carry no authority; positive new limits/identifiers are denied.

Types

type Catalog

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

Catalog publishes a host-selected subset and private copies of extensions. Extensions cannot shadow a shared name, even when that name is unsupported.

func NewCatalog

func NewCatalog(supported []string, extensions []Descriptor) (*Catalog, error)

func (*Catalog) Lookup

func (c *Catalog) Lookup(name string, version int) (Descriptor, error)

type Code

type Code string

Code is a stable application failure classification.

const (
	InvalidRequest        Code = "invalid_request"
	Unauthenticated       Code = "unauthenticated"
	CapabilityDenied      Code = "capability_denied"
	ScopeDenied           Code = "scope_denied"
	UnsupportedCapability Code = "unsupported_capability"
	TargetUnavailable     Code = "target_unavailable"
	BudgetExceeded        Code = "budget_exceeded"
	RateLimited           Code = "rate_limited"
	Cancelled             Code = "cancelled"
	DeadlineExceeded      Code = "deadline_exceeded"
	UnknownOutcome        Code = "unknown_outcome"
	InternalError         Code = "internal_error"
	Conflict              Code = "conflict"
)

type Descriptor

type Descriptor struct {
	Name          string      `json:"name"`
	SchemaVersion int         `json:"schema_version"`
	ScopeSchema   ScopeSchema `json:"scope_schema"`
	Description   string      `json:"description"`
	EffectCeiling Effect      `json:"effect_ceiling"`
	Operations    []string    `json:"operations"`
	Proposed      bool        `json:"proposed"`
}

Descriptor defines semantics; it does not grant authority or install a handler. Proposed marks reverse-service entries pending catalog ratification.

func SharedDescriptors

func SharedDescriptors() []Descriptor

SharedDescriptors returns independent copies of the seed and proposed catalogs. Hosts opt into a supported subset; presence here is not permission.

func (Descriptor) ValidateScope

func (d Descriptor) ValidateScope(version int, s Scope) error

ValidateScope rejects unknown versions, dimensions, effects and operations.

type Effect

type Effect string
const (
	Read        Effect = "read"
	Write       Effect = "write"
	Destructive Effect = "destructive"
)

type EffectState

type EffectState string

EffectState distinguishes authorization refusal from an ambiguous mutation.

const (
	NotStarted   EffectState = "not_started"
	NotCommitted EffectState = "not_committed"
	Committed    EffectState = "committed"
	Unknown      EffectState = "unknown"
)

type Error

type Error struct {
	Code        Code          `json:"code"`
	Capability  string        `json:"capability,omitempty"`
	RequestID   RequestID     `json:"request_id,omitempty"`
	EffectState EffectState   `json:"effect_state"`
	Detail      FailureDetail `json:"detail,omitempty"`
}

Error contains only safe classification metadata. Adapters must not copy internal error messages, arguments or credentials into wire errors.

func (*Error) Error

func (e *Error) Error() string

func (*Error) RPCData

func (e *Error) RPCData() (RPCErrorData, error)

RPCData validates classification and the positive profile correlation ID. Adapters must copy the enclosing request ID; equality with that envelope is checked by the transport, which owns the envelope.

func (*Error) Validate

func (e *Error) Validate() error

Validate checks classification metadata before RPC correlation is attached. Zero RequestID is allowed for internal planning/admission errors; RPCData requires a positive ID before serialization. Missing state is unknown.

type FailureDetail

type FailureDetail string

FailureDetail is a closed machine-readable refinement, never raw diagnostics.

const (
	StaleBinding   FailureDetail = "stale_binding"
	CallbackCycle  FailureDetail = "callback_cycle"
	DepthExceeded  FailureDetail = "depth_exceeded"
	ParentInvalid  FailureDetail = "parent_invalid"
	ParentTerminal FailureDetail = "parent_terminal"
)

type Grant

type Grant struct {
	GrantID         string          `json:"grant_id"`
	Name            string          `json:"name"`
	SchemaVersion   uint32          `json:"schema_version"`
	Scope           json.RawMessage `json:"scope"`
	HostInstance    string          `json:"host_instance"`
	OwnerID         string          `json:"owner_id"`
	OwnerGeneration uint64          `json:"owner_generation"`
	Audience        string          `json:"audience"`
	IssuedAt        string          `json:"issued_at"`
	ExpiresAt       string          `json:"expires_at"`
	PolicyRevision  string          `json:"policy_revision"`
}

Grant is discovery data, not proof of permission at execution time. The host normalizes Scope under its descriptor and enforces current policy separately. Identifiers and timestamps are preserved without normalization.

func (Grant) MarshalJSON

func (g Grant) MarshalJSON() ([]byte, error)

func (*Grant) UnmarshalJSON

func (g *Grant) UnmarshalJSON(data []byte) error

func (Grant) Validate

func (g Grant) Validate() error

Validate checks shape, tuple, JSON syntax and timestamp ordering only. It does not check current expiry, descriptor support, audience policy or authorization.

type GrantSet

type GrantSet []Grant

GrantSet encodes nil and empty sets as [], and refuses null on decode.

func (GrantSet) Clone

func (s GrantSet) Clone() GrantSet

Clone returns a detached discovery snapshot; it confers no authority.

func (GrantSet) MarshalJSON

func (s GrantSet) MarshalJSON() ([]byte, error)

func (*GrantSet) UnmarshalJSON

func (s *GrantSet) UnmarshalJSON(data []byte) error

func (GrantSet) Validate

func (s GrantSet) Validate() error

func (GrantSet) ValidateForRuntime

func (s GrantSet) ValidateForRuntime(r RuntimeIdentity) error

ValidateForRuntime checks the single canonical tuple, including an empty set.

func (GrantSet) ValidateRenewal

func (s GrantSet) ValidateRenewal(next GrantSet, owner RuntimeIdentity, now time.Time) error

ValidateRenewal checks an unchanged, still-live authority set. Timestamps are the only mutable fields. It does not authenticate a host or approve policy; the host must revalidate both before sending and after receiving an ack. Scope bytes and grant order are retained exactly, including host extensions.

type GrantValidationError

type GrantValidationError struct{ Field, Reason string }

GrantValidationError classifies a structural failure without including the rejected value, which may contain sensitive scope or identity data.

func (*GrantValidationError) Error

func (e *GrantValidationError) Error() string

type RPCErrorData

type RPCErrorData struct {
	Contract    string        `json:"contract"`
	Code        Code          `json:"code"`
	RequestID   RequestID     `json:"request_id"`
	EffectState EffectState   `json:"effect_state"`
	Retryable   bool          `json:"retryable"`
	Detail      FailureDetail `json:"detail,omitempty"`
}

RPCErrorData is the protocol-2 host application error payload. All errors prohibit automatic retry, including unknown outcomes and idempotent hints.

type RequestID

type RequestID uint64

RequestID is a positive JavaScript-safe integer for host-rpc/1 correlation. It is distinct from the broader ID vocabulary in base JSON-RPC. Zero denotes an internal error without RPC correlation and cannot appear on the wire.

func (RequestID) MarshalJSON

func (id RequestID) MarshalJSON() ([]byte, error)

func (*RequestID) UnmarshalJSON

func (id *RequestID) UnmarshalJSON(data []byte) error

func (RequestID) Validate

func (id RequestID) Validate() error

type RuntimeIdentity

type RuntimeIdentity struct {
	HostInstance    string `json:"host_instance"`
	OwnerID         string `json:"owner_id"`
	OwnerGeneration uint64 `json:"owner_generation"`
}

RuntimeIdentity is the host-issued incarnation tuple. It is distinct from a manifest's server.runtime execution engine and from a verified caller identity.

func (RuntimeIdentity) MarshalJSON

func (r RuntimeIdentity) MarshalJSON() ([]byte, error)

func (*RuntimeIdentity) UnmarshalJSON

func (r *RuntimeIdentity) UnmarshalJSON(data []byte) error

func (RuntimeIdentity) Validate

func (r RuntimeIdentity) Validate() error

type Scope

type Scope struct {
	Allowlists map[string][]string `json:"allowlists"`
	Limits     map[string]int64    `json:"limits"`
}

Scope is a normalized authority envelope, not a wire grant. Each allowlist contains exact identifiers, never patterns. A missing/empty list or missing/ zero budget conveys no authority. Limits are nonnegative ceilings, in units defined by the descriptor. Hosts must encode related identifiers (such as server/tool pairs) in one dimension rather than creating a Cartesian product.

func Intersect

func Intersect(name string, requested, supported, approved, policy Scope) (Scope, error)

Intersect computes requested ∩ supported ∩ approved ∩ policy. All inputs must already use the same descriptor version; missing constraints deny. The result owns its maps and slices and never aliases an input.

func (Scope) Allows

func (s Scope) Allows(dimension, value string) bool

Allows matches one exact identifier in a dimension.

func (Scope) Validate

func (s Scope) Validate(name string) error

Validate rejects malformed authority. Wildcards require a separate reviewed schema; this exact-match envelope deliberately cannot express them.

func (Scope) Within

func (s Scope) Within(dimension string, amount int64) bool

Within checks a nonnegative amount against an explicitly present ceiling.

type ScopeSchema

type ScopeSchema struct {
	Allowlists []string `json:"allowlists"`
	Limits     []string `json:"limits"`
}

ScopeSchema closes the vocabulary of exact-match dimensions and numeric ceilings. All named dimensions/limits must be present, including explicit empty lists/zero limits for denial. Units are documented in package docs.

Directories

Path Synopsis
hosttest
Package hosttest runs behavioral capability conformance through a host's actual admission, dispatcher, lifecycle and non-plugin bridge adapters.
Package hosttest runs behavioral capability conformance through a host's actual admission, dispatcher, lifecycle and non-plugin bridge adapters.

Jump to

Keyboard shortcuts

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