agentdecl

package
v1.0.0-rc.16 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 31 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

Index

Constants

View Source
const (
	MacroRoundsUsed         = "{{rounds_used}}"
	MacroRecoveryRoundsUsed = "{{recovery_rounds_used}}"
	MacroMainRounds         = "{{main_rounds}}"
	MacroRecoveryRounds     = "{{recovery_rounds}}"
)
View Source
const (
	AxisFilesRead       = "files.read"
	AxisFilesWrite      = "files.write"
	AxisShell           = "shell"
	AxisNetworkRead     = "network.read"
	AxisNetworkWrite    = "network.write"
	AxisEventsFire      = "events.fire"
	AxisEventsSubscribe = "events.subscribe"
	AxisMissionsFire    = "missions.fire"
	AxisMissionsAnswer  = "missions.answer"
)
View Source
const AgentFilename = "agent.md"
View Source
const ChainSchemaURL = "https://contenox.com/schema/task-chain.schema.json"
View Source
const CompiledChainPrefix = "agent-"
View Source
const ConfigFilename = "agents.toml"
View Source
const EnvelopeSection = "envelopes"
View Source
const FailureFilename = "failure.md"
View Source
const FieldMCPServers = "mcpServers"
View Source
const FieldRemoteTools = "remoteTools"
View Source
const GeneratedDirName = hitlservice.GeneratedPolicyDir
View Source
const NativeSourceDir = "agents"
View Source
const PolicySchemaURL = "https://contenox.com/schema/hitl-policy-v1.schema.json"
View Source
const PreseedStateFilename = ".preseed-state.json"
View Source
const RecoveryFilename = "recovery.md"
View Source
const RoleSubagent = RoleMission
View Source
const SkillDirName = "skills"
View Source
const SkillsMacro = "{{skills}}"
View Source
const SyncStateFilename = ".sync-state.json"
View Source
const ToolsInheritAll = "*"
View Source
const TreeDialect = DialectClaudeCode

Variables

View Source
var ErrNoEnvelope = errors.New("agentdecl: no such envelope")
View Source
var ForeignSourceDirs = []string{
	path.Join(".claude", "agents"),
	path.Join(".agents", "agents"),
}
View Source
var Preseeded = []struct {
	RelPath string
	Source  string
	Content func() string
}{
	{ConfigFilename, "agents.toml", func() string { return string(shippedConfig) }},
	{path.Join(NativeSourceDir, "README.md"), "preseed/README.md", func() string { return preseedReadme }},
	{path.Join(NativeSourceDir, "reviewer.md"), "preseed/reviewer.md", func() string { return preseedReviewer }},
	{path.Join(NativeSourceDir, "researcher.md"), "preseed/researcher.md", func() string { return preseedResearcher }},
	{path.Join(NativeSourceDir, "run.md"), "preseed/run.md", func() string { return preseedRun }},
	{path.Join(NativeSourceDir, "chat.md"), "preseed/chat.md", func() string { return preseedChat }},
	{path.Join(NativeSourceDir, "planner.md"), "preseed/planner.md", func() string { return preseedPlanner }},
}
View Source
var ReservedNames = map[string]bool{}

Functions

func AgentsDir

func AgentsDir(home string) string

AgentsDir is the folder the app edits: <home>/agents.

func Bootstrap

func Bootstrap(ctx context.Context, home string, cfg Config) (PreseedResult, []SyncResult, error)

func BootstrapFor

func BootstrapFor(ctx context.Context, home, project string, cfg Config) (PreseedResult, []SyncResult, error)

BootstrapFor is Bootstrap with a project root: its `.contenox/agents/` and other tools' agent folders are compiled beside the home's, and a project agents.toml layers over the home one. An empty project means home only.

func ChainFileFor

func ChainFileFor(chainID string) string

func CompileLock

func CompileLock(home string) (release func(), err error)

func CompileShippedAgent

func CompileShippedAgent(cfg Config, name string) (*taskengine.TaskChainDefinition, error)

func CompileShippedTree

func CompileShippedTree(cfg Config) (*taskengine.TaskChainDefinition, error)

func ConfigProblems

func ConfigProblems(texts ...string) []string

func ConfigSectionNames

func ConfigSectionNames() []string

func DeleteLayerItem

func DeleteLayerItem(raw, section, name string) (string, bool, error)

func DeleteLayerSection

func DeleteLayerSection(raw, section string) (string, bool, error)

func EffectiveSection

func EffectiveSection(cfg Config, section string) (any, error)

func EmitChain

func EmitChain(ir *AgentIR, cfg Config) (*taskengine.TaskChainDefinition, error)

func EmitPolicy

func EmitPolicy(ir *AgentIR, cfg Config) (*hitlservice.Policy, error)

func EmitTree

func EmitTree(root *AgentTree, cfg Config) (*taskengine.TaskChainDefinition, error)

func EnvelopeName

func EnvelopeName(s string) (string, bool)

func EnvelopePolicyFile

func EnvelopePolicyFile(name string) string

func LayerItem

func LayerItem(raw, section, name string) (any, bool, error)

func LayerRevision

func LayerRevision(raw string) string

func LayerSection

func LayerSection(raw, section string) (any, bool, error)

func LockLayerWrites

func LockLayerWrites() func()

func MergePatch

func MergePatch(target, patch any) any

func NewConfigProblems

func NewConfigProblems(before, after []string) []string

func ParseConfigLayer

func ParseConfigLayer(raw string) (map[string]any, error)

func PatchLayerItem

func PatchLayerItem(raw, section, name string, patch any) (string, error)

func PatchLayerSection

func PatchLayerSection(raw, section string, patch any) (string, error)

func PolicyFileFor

func PolicyFileFor(stem string) string

func PolicyForAgent

func PolicyForAgent(ctx context.Context, generatedDir Root, agentName string) (string, bool)

PolicyForAgent reports the generated policy of the declaration whose scoped name ends in agentName — a declaration read from another product's directory carries that product's prefix, so an exact match is not enough.

func PolicyForChain

func PolicyForChain(ctx context.Context, generatedDir Root, chainFile string) (string, bool)

PolicyForChain reports the generated policy file an agent's compiled chain was emitted with, so a caller that knows the chain (a mission naming a declared agent, say) can bound itself by that agent's own posture instead of a global default. The name is the file under the generated root.

func RenderEnvelopePolicy

func RenderEnvelopePolicy(cfg Config, name, source string) ([]byte, error)

func RenderSkillInventory

func RenderSkillInventory(skills []Skill) string

func RenderWorkspaceEnvelopes

func RenderWorkspaceEnvelopes(ctx context.Context, home, workspaceRoot string) ([]string, error)

func RetireStaleEnvelopePolicies

func RetireStaleEnvelopePolicies(generatedDir string, keep []string) ([]string, error)

func SetLayerItem

func SetLayerItem(raw, section, name string, value any) (string, error)

func SetLayerSection

func SetLayerSection(raw, section string, value any) (string, error)

func SyncEnvelopePolicy

func SyncEnvelopePolicy(ctx context.Context, cfg Config, name string, generatedDir Root, source string) (string, bool, error)

func ToolPatternRef

func ToolPatternRef(pattern string) (tools, tool string, err error)

func ToolSets

func ToolSets(connected []string) []string

func TreeSignature

func TreeSignature(home string) string

TreeSignature changes whenever a declaration or agents.toml changes, so a watcher can tell "something moved" without parsing anything.

func WorkspacePolicyDir

func WorkspacePolicyDir(home, workspaceID string) string

func WriteConfigLayer

func WriteConfigLayer(path, raw string) error

Types

type AgentFileStatus

type AgentFileStatus struct {
	Path     string    `json:"path"`
	State    string    `json:"state"`
	Problems []Problem `json:"problems,omitempty"`
}

AgentFileStatus is one declaration source as the app sees it: where it is, whether it is still the shipped copy, and what the last compile said about it.

func AgentFiles

func AgentFiles(home string) ([]AgentFileStatus, error)

AgentFiles lists every declaration under <home>/agents with its state and the problems the last compile reported for it. States: shipped (byte-identical to the file this build ships), edited (a shipped file the user changed), user (everything else).

type AgentIR

type AgentIR struct {
	Source         Source               `json:"source"`
	Name           string               `json:"name"`
	Description    string               `json:"description"`
	SystemPrompt   string               `json:"system_prompt"`
	Model          Model                `json:"model"`
	Tools          Tools                `json:"tools"`
	MCPServers     []string             `json:"mcp_servers,omitempty"`
	DeclaredMCP    []DeclaredMCPServer  `json:"declared_mcp,omitempty"`
	DeclaredRemote []DeclaredRemoteTool `json:"declared_remote,omitempty"`
	Role           Role                 `json:"role"`
	Posture        Posture              `json:"posture"`
	Category       string               `json:"category,omitempty"`
	Icon           string               `json:"icon,omitempty"`
	Think          string               `json:"think,omitempty"`
	DefaultBranch  string               `json:"default_branch,omitempty"`
	Temperature    *float32             `json:"temperature,omitempty"`
	Budgets        Budgets              `json:"budgets"`
	Unmapped       []Unmapped           `json:"unmapped,omitempty"`
}

func Parse

func Parse(path string, data []byte, cfg Config) (*AgentIR, error)

func ParseAntigravity

func ParseAntigravity(path string, data []byte, cfg Config) (*AgentIR, error)

func ParseAs

func ParseAs(dialect Dialect, path string, data []byte, cfg Config) (*AgentIR, error)

func ParseClaudeCode

func ParseClaudeCode(path string, data []byte, cfg Config) (*AgentIR, error)

func (*AgentIR) AddUnmapped

func (ir *AgentIR) AddUnmapped(field, value, reason string)

func (*AgentIR) DeclaredToolsetNames

func (ir *AgentIR) DeclaredToolsetNames(agentID string) []string

func (*AgentIR) RunsAsSubagent

func (ir *AgentIR) RunsAsSubagent() bool

func (*AgentIR) ScopedName

func (ir *AgentIR) ScopedName(scopeWithDialect bool) string

type AgentTree

type AgentTree struct {
	Name     string
	Agent    *AgentIR
	Recovery *AgentIR
	Children []*AgentTree
	Default  string
	Failure  *AgentIR
}

func LoadTree

func LoadTree(ctx context.Context, dir Root, cfg Config) (*AgentTree, error)

func (*AgentTree) IsRouter

func (t *AgentTree) IsRouter() bool

func (*AgentTree) Labels

func (t *AgentTree) Labels() []string

func (*AgentTree) MergedIR

func (t *AgentTree) MergedIR() *AgentIR

type AttentionDefaults

type AttentionDefaults struct {
	AllowAgentAnswers   bool `toml:"allow_agent_answers"`
	MaxAgentAnswers     int  `toml:"max_agent_answers"`
	AllowAgentApprovals bool `toml:"allow_agent_approvals"`
	MaxAgentApprovals   int  `toml:"max_agent_approvals"`
}

type AxisGrant

type AxisGrant struct {
	Grant           string
	DenyPaths       []string
	ApprovePaths    []string
	Blacklist       []string
	Substitution    string
	PrefixAllowlist []string
	AskAlways       []string
	DenyHosts       []string
	Timeout         time.Duration
	OnTimeout       string
}

type Budgets

type Budgets struct {
	MaxTurns *int `json:"max_turns,omitempty"`
}

type ChainDefaults

type ChainDefaults struct {
	TokenLimit     int64                 `toml:"token_limit"`
	MaxTokens      string                `toml:"max_tokens"`
	Think          string                `toml:"think"`
	MainRounds     int                   `toml:"main_rounds"`
	RecoveryRounds int                   `toml:"recovery_rounds"`
	RetryOnFailure int                   `toml:"retry_on_failure"`
	Shift          bool                  `toml:"shift"`
	RetryPolicy    *llmretry.RetryPolicy `toml:"retry_policy"`
}

type ComputeDefaults

type ComputeDefaults struct {
	MaxToolCalls     int      `toml:"max_tool_calls"`
	MaxTokens        int      `toml:"max_tokens"`
	OnExhausted      string   `toml:"on_exhausted"`
	MaxTurns         int      `toml:"max_turns"`
	ModelAllowlist   []string `toml:"model_allowlist"`
	BackendAllowlist []string `toml:"backend_allowlist"`
}

type Config

type Config struct {
	Version       int                          `toml:"version"`
	Chain         ChainDefaults                `toml:"chain"`
	Routing       RoutingDefaults              `toml:"routing"`
	ToolsPolicies map[string]map[string]string `toml:"tools_policies"`
	Policy        PolicyDefaults               `toml:"policy"`
	Naming        NamingDefaults               `toml:"naming"`
	Tools         map[string]string            `toml:"tools"`
	Models        map[string]string            `toml:"models"`
	Envelopes     map[string]map[string]any    `toml:"envelopes"`
	Agents        map[string]map[string]any    `toml:"agents"`
}

func ConfigFromTexts

func ConfigFromTexts(texts ...string) (Config, error)

func Load

func Load(ctx context.Context, roots ...Root) (Config, error)

func Shipped

func Shipped() (Config, error)

func (Config) EnvelopeNames

func (cfg Config) EnvelopeNames() []string

func (Config) For

func (cfg Config) For(agent string) (Config, error)

func (Config) MapModel

func (c Config) MapModel(name string) (provider, id string, ok bool)

func (Config) MapTools

func (c Config) MapTools(names []string) ([]string, []Unmapped, error)

func (Config) ParseEnvelope

func (cfg Config) ParseEnvelope(name string) (Envelope, error)

func (Config) PostureEnvelope

func (cfg Config) PostureEnvelope(p Posture) (Envelope, error)

func (Config) ResolveEnvelope

func (cfg Config) ResolveEnvelope(name string) (Envelope, error)

func (Config) UnknownAgents

func (cfg Config) UnknownAgents(known map[string]bool) []string

func (Config) Validate

func (cfg Config) Validate() error

type ConfigLayer

type ConfigLayer struct {
	Path     string
	Raw      string
	Exists   bool
	Revision string
}

func ReadConfigLayer

func ReadConfigLayer(path string) (ConfigLayer, error)

type DeclaredMCPServer

type DeclaredMCPServer struct {
	Declared   string            `json:"declared"`
	Transport  string            `json:"transport"`
	Command    string            `json:"command,omitempty"`
	Args       []string          `json:"args,omitempty"`
	URL        string            `json:"url,omitempty"`
	Headers    map[string]string `json:"headers,omitempty"`
	AuthEnvKey string            `json:"auth_env_key,omitempty"`
	AuthType   string            `json:"auth_type,omitempty"`
}

type DeclaredRemoteTool

type DeclaredRemoteTool struct {
	Declared    string            `json:"declared"`
	EndpointURL string            `json:"endpoint_url"`
	SpecURL     string            `json:"spec_url,omitempty"`
	TimeoutMs   int               `json:"timeout_ms,omitempty"`
	Headers     map[string]string `json:"headers,omitempty"`
}

type Dialect

type Dialect string
const (
	DialectClaudeCode  Dialect = "claude-code"
	DialectAntigravity Dialect = "antigravity"
	DialectCopilot     Dialect = "copilot"
	DialectOpenCode    Dialect = "opencode"
	DialectCursor      Dialect = "cursor"
)

func DetectDialect

func DetectDialect(path string, data []byte) (Dialect, error)

type Envelope

type Envelope struct {
	Name            string
	Extends         string
	Description     string
	DefaultAction   AxisGrant
	Axes            map[string]AxisGrant
	Tools           map[string]AxisGrant
	Compute         map[string]any
	Attention       map[string]any
	TrustedBinaries map[string]any
	AlwaysDeny      []StandingRule
	AlwaysAllow     []StandingRule
}

type ErrAmbiguousDialect

type ErrAmbiguousDialect struct{ Path string }

func (*ErrAmbiguousDialect) Error

func (e *ErrAmbiguousDialect) Error() string

type ErrMissingField

type ErrMissingField struct {
	Path  string
	Field string
}

func (*ErrMissingField) Error

func (e *ErrMissingField) Error() string

type ErrNoFrontmatter

type ErrNoFrontmatter struct{ Path string }

func (*ErrNoFrontmatter) Error

func (e *ErrNoFrontmatter) Error() string

type ErrUnknownTool

type ErrUnknownTool struct {
	Tools []string
}

func (*ErrUnknownTool) Error

func (e *ErrUnknownTool) Error() string

type ErrUnsafePosture

type ErrUnsafePosture struct {
	Name    string
	Dialect Dialect
}

func (*ErrUnsafePosture) Error

func (e *ErrUnsafePosture) Error() string

type Model

type Model struct {
	Raw      string `json:"raw"`
	Provider string `json:"provider,omitempty"`
	ID       string `json:"id,omitempty"`
}

type NamingDefaults

type NamingDefaults struct {
	ScopeWithDialect bool `toml:"scope_with_dialect"`
}

type PolicyDefaults

type PolicyDefaults struct {
	DefaultAction string                   `toml:"default_action"`
	Compute       ComputeDefaults          `toml:"compute"`
	Attention     AttentionDefaults        `toml:"attention"`
	AlwaysDeny    []StandingRule           `toml:"always_deny"`
	AlwaysAllow   []StandingRule           `toml:"always_allow"`
	Postures      map[string]PostureGrants `toml:"postures"`
}

type Posture

type Posture string
const (
	PostureReadOnly  Posture = "read_only"
	PostureAskAlways Posture = "ask_always"
	PostureAutoEdit  Posture = "auto_edit"
	PostureUnsafe    Posture = "unsafe"
)

func ParsePosture

func ParsePosture(raw string) (Posture, error)

type PostureGrants

type PostureGrants struct {
	LocalFSRead  string `toml:"local_fs_read"`
	LocalFSWrite string `toml:"local_fs_write"`
	LocalShell   string `toml:"local_shell"`
}

type PreseedResult

type PreseedResult struct {
	Created    []string
	Updated    []string
	Edited     []string
	Unrecorded []string
}

func Preseed

func Preseed(ctx context.Context, contenoxDir Root) (PreseedResult, error)

type PreseedSource

type PreseedSource struct {
	Rel    string
	Source string
}

func PreseedSources

func PreseedSources() ([]PreseedSource, error)

type Problem

type Problem struct {
	Source string `json:"source"`
	Name   string `json:"name,omitempty"`
	Action string `json:"action"`
	Reason string `json:"reason,omitempty"`
	Field  string `json:"field,omitempty"`
}

Problem is one thing a sync or render pass could not do. The boot keeps the latest list so the app can show a broken declaration instead of only logging it: refused, ignored, or a field the declaration named and this build does not carry.

func LastProblems

func LastProblems() []Problem

LastProblems reports what the most recent bootstrap could not act on.

type Role

type Role string
const (
	RolePrimary Role = "primary"
	RoleMission Role = "mission"
	RoleBoth    Role = "both"
)

type Root

type Root struct {
	Key   string
	FS    vfs.Files
	Local bool
}

func LocalRoot

func LocalRoot(dir string) (Root, error)

func (Root) Base

func (r Root) Base() string

func (Root) Child

func (r Root) Child(rel string) (Root, error)

func (Root) Path

func (r Root) Path(rel string) string

type RoutingDefaults

type RoutingDefaults struct {
	Model          string `toml:"model"`
	Provider       string `toml:"provider"`
	PinModel       bool   `toml:"pin_model"`
	RouterModel    string `toml:"router_model"`
	RouterProvider string `toml:"router_provider"`
	AltModel       string `toml:"alt_model"`
	AltProvider    string `toml:"alt_provider"`
}

type SectionKind

type SectionKind string
const (
	SectionNamed     SectionKind = "named"
	SectionFlat      SectionKind = "flat"
	SectionSingleton SectionKind = "singleton"
)

func SectionKindOf

func SectionKindOf(section string) (SectionKind, bool)

type Skill

type Skill struct {
	Name        string
	Description string
	Path        string
}

func DiscoverSkills

func DiscoverSkills(ctx context.Context, contenoxDirs []Root, workspaceRoot string) []Skill

type Source

type Source struct {
	Dialect  Dialect `json:"dialect"`
	SpecDate string  `json:"spec_date"`
	Path     string  `json:"path"`
	SHA256   string  `json:"sha256"`
}

type SourceDir

type SourceDir struct {
	Root
	Native bool
}

func DiscoverSourceDirs

func DiscoverSourceDirs(ctx context.Context, contenoxDirs []Root, workspaceRoots []Root) []SourceDir

type StandingRule

type StandingRule struct {
	Tools     string `toml:"tools"`
	Tool      string `toml:"tool"`
	WhenKey   string `toml:"when_key"`
	WhenOp    string `toml:"when_op"`
	WhenValue string `toml:"when_value"`
}

type SyncOption

type SyncOption func(*syncOptions)

func WithSkills

func WithSkills(skills []Skill) SyncOption

type SyncResult

type SyncResult struct {
	Source   string
	Name     string
	Dialect  Dialect
	Action   WriteAction
	Reason   string
	Unmapped []Unmapped
	MCP      []DeclaredMCPServer
	Remote   []DeclaredRemoteTool
}

func Sync

func Sync(ctx context.Context, sourceDirs []SourceDir, generated Root, cfg Config, opts ...SyncOption) ([]SyncResult, error)

type Tools

type Tools struct {
	Allow   []string `json:"allow,omitempty"`
	Deny    []string `json:"deny,omitempty"`
	Inherit bool     `json:"inherit,omitempty"`
}

type TranspiledEnvelope

type TranspiledEnvelope struct {
	Policy *hitlservice.Policy
	Notes  []string
}

func TranspileEnvelope

func TranspileEnvelope(env Envelope) (TranspiledEnvelope, error)

type Unmapped

type Unmapped struct {
	Field  string `json:"field"`
	Value  string `json:"value,omitempty"`
	Reason string `json:"reason"`
}

type WriteAction

type WriteAction string
const (
	ActionCreated   WriteAction = "created"
	ActionUpdated   WriteAction = "updated"
	ActionUnchanged WriteAction = "unchanged"
	ActionRefused   WriteAction = "refused"
	ActionIgnored   WriteAction = "ignored"
)

Jump to

Keyboard shortcuts

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