capabilities

package
v0.0.0-...-53bd38a Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 0 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 capabilities defines capability interfaces that protocol extensions implement to participate in framework services like content inspection, session bucketing, and summarization. The package is deliberately dependency-free — parser plugins and consumer plugins (guardrails) both import it without importing each other, so no implicit coupling forms between producers and consumers of a capability.

Capability interfaces are checked by consumers via type assertion. A protocol extension that doesn't implement one simply isn't offered that capability; guardrails skip it.

Index

Constants

View Source
const (
	RoleUser       = "user"
	RoleAssistant  = "assistant"
	RoleSystem     = "system"
	RoleTool       = "tool"
	RoleToolArgs   = "tool_args"
	RoleToolResult = "tool_result"
)

Standard Role values. Parsers reference these instead of string literals so spelling is compiler-checked. Guardrails may compare against either the constant or a string literal — the over-the-wire representation is the same.

  • RoleUser: end-user input, human-authored.
  • RoleAssistant: model or agent output.
  • RoleSystem: system prompt or instructions to the model.
  • RoleTool: the name of a tool being invoked.
  • RoleToolArgs: an argument value passed to a tool invocation.
  • RoleToolResult: content returned from a tool invocation.

The vocabulary is open. A protocol that invents a role outside this list is valid; guardrails that don't recognize a role treat it per their own policy (typically: scan anyway, or skip).

Variables

This section is empty.

Functions

This section is empty.

Types

type ClaimsCarrier

type ClaimsCarrier interface {
	// Issuer is the token issuer (`iss`), or "" when not applicable.
	Issuer() string

	// Audience is the token audience list (`aud`), or nil.
	Audience() []string

	// AuthMethod names how the caller authenticated — "jwt", "mtls",
	// "spiffe", etc. Drives policies that branch on authentication
	// strength. "" when the producer can't classify it.
	AuthMethod() string

	// Claims returns a curated, string-valued claim set safe to forward
	// into policy context and observability surfaces. Producers pick the
	// keys (conventionally "issuer", "audience", "exp"); they MUST NOT
	// dump the full raw claim map, which may contain secrets or PII.
	// Values are strings, so they reach policy engines (CPEX's
	// SubjectExtension.Claims, OPA input) without lossy coercion.
	Claims() map[string]string
}

ClaimsCarrier is an optional capability interface a pipeline.Identity may implement to expose richer claim data than the minimal pipeline.Identity surface (Subject / ClientID / Scopes).

It exists so consumers that want issuer / audience / auth-method / curated claims — chiefly the cpex plugin building a policy-input document — can read them without growing pipeline.Identity (which stays deliberately minimal so any auth shape can satisfy it). Mirrors the ContentSource pattern: consumers type-assert to this interface and simply skip the enrichment when the concrete identity doesn't implement it.

if cc, ok := pctx.Identity.(capabilities.ClaimsCarrier); ok {
    authMethod = cc.AuthMethod()
    claims     = cc.Claims()
}

Producers (e.g. jwt-validation's claims adapter) curate what Claims returns — a small, safe-to-forward set (issuer, audience, expiry), NOT the full raw claim map. The session API and CPEX traces both surface this data, so producers must keep it free of secrets.

type ContentSource

type ContentSource interface {
	// Fragments returns every inspectable text fragment on the current
	// request or response phase, in document order. Returns nil or an
	// empty slice when there's nothing to inspect at this phase.
	// Fragments with empty Text are filtered by the producer.
	Fragments() []Fragment
}

ContentSource is implemented by protocol extensions whose payload contains user-visible text that guardrails might inspect — PII scrubbing, jailbreak detection, content classification, credential leakage scanning, and similar content-oriented checks.

Usage on the consumer side:

for _, src := range pctx.ContentSources() {
    for _, f := range src.Fragments() {
        if f.Role == capabilities.RoleUser {
            scan(f.Text)
        }
    }
}

The guardrail does not import any parser package — it knows only this contract. When a new protocol ships with a Fragments implementation, existing guardrails pick it up automatically.

Protocols that carry no inspectable text (control-plane RPCs like MCP initialize, binary protocols, identity-only auth messages) simply do not implement this interface.

type Fragment

type Fragment struct {
	// Role identifies who produced the text. Use the standard values
	// below when the semantic fit is clear; protocols that don't fit
	// any standard value may emit their own role strings.
	Role string

	// Text is the raw text content. Never empty — producers filter
	// empty fragments before returning.
	Text string
}

Fragment is one inspectable piece of text, tagged with the role that produced it.

The struct may grow additional fields in future versions (e.g., a Path locator for violation citations, or a Kind hint for format-aware scanners). Use **named-field initialization** when constructing literals — `Fragment{Role: ..., Text: ...}` rather than `Fragment{"user", "..."}` — so existing call sites and tests remain unaffected when fields are added. Tests that compare `[]Fragment` literals with reflect.DeepEqual should likewise rely on named fields so new zero-valued fields compare equal without test churn.

Jump to

Keyboard shortcuts

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