Documentation
¶
Overview ¶
Package approval is the one policy that decides each tool call: whether it runs, waits for an approval, is refused, or whether the tool is not offered to the agent at all. The policy is tools.approval: rules, the first that matches a call deciding it, and a default for the calls no rule matches.
Index ¶
- Constants
- func Approved(ctx context.Context) bool
- func Describe(name string, tool any) (Tool, Info)
- func MCPHints(a MCPAnnotations, trusted bool) []string
- func MCPSource(server string) string
- func ModuleHints(network, externalWrites, costKnown bool) []string
- func ModuleSource(id string) string
- func WithApproved(ctx context.Context) context.Context
- type Action
- type Call
- type Decision
- type Described
- type Gate
- type Info
- type MCPAnnotations
- type Origin
- type Policy
- type Rule
- type Tool
Constants ¶
const ( HintReadOnly = "read_only" HintDestructive = "destructive" HintIdempotent = "idempotent" HintOpenWorld = "open_world" HintCostUnknown = "cost_unknown" HintNetwork = "network" HintExternalWrites = "external_writes" )
The hints a rule can match. MCP servers declare the first four as tool annotations, which count only from trusted servers (MCPHints); modules declare the last three as effects of a capability (ModuleHints).
const SourceBuiltin = "builtin"
SourceBuiltin is the source of Compa's own tools. MCP and module tools have the sources MCPSource and ModuleSource return.
Variables ¶
This section is empty.
Functions ¶
func Approved ¶
Approved reports whether ctx is that of a call the operator approved (WithApproved).
func Describe ¶
Describe returns the policy's view of the tool the agent sees as name, and its Info. A tool that does not implement Described is a builtin.
func MCPHints ¶
func MCPHints(a MCPAnnotations, trusted bool) []string
MCPHints returns the hints of an MCP tool whose server declares a for it. Left-out annotations take the MCP defaults: not read-only, destructive (unless read-only), not idempotent, open world. A server that is not trusted is not believed: its tools get the defaults whatever it declares.
func ModuleHints ¶
ModuleHints returns the hints of a module capability that declares these effects.
func ModuleSource ¶
ModuleSource returns the source of the capabilities of the module id.
Types ¶
type Action ¶
type Action string
Action is what the policy does with a call.
const ( // Allow runs the call. Allow Action = "allow" // Ask runs the call once it is approved: by a registered approver, or // else by the owner in chat. No answer denies it. Ask Action = "ask" // Deny refuses the call. Deny Action = "deny" // Hide does not offer the tool to the agent; a call of it is refused. Hide Action = "hide" )
type Call ¶
type Call struct {
Tool string
Arguments map[string]any
Origin Origin
// Job is the scheduled job the call runs for, named in the request.
Job string
// Channel and ChatID are the chat the call reports to.
Channel string
ChatID string
}
Call is a tool call made outside an agent turn, such as a scheduled command.
type Decision ¶
type Decision struct {
Action Action `json:"action"`
// Index is the position of the rule that decided in Policy.Rules, or -1
// when the default did.
Index int `json:"index"`
// Rule is the rule that decided; nil when the default did.
Rule *Rule `json:"rule,omitempty"`
}
Decision is the action for a call and the rule that chose it.
type Described ¶
type Described interface {
ApprovalInfo() Info
}
Described is implemented by the tools that are not Compa's own.
type Gate ¶
Gate decides the calls made outside an agent turn by the policy, asking when it says to. A nil error lets the call run; the error of a call that may not run says why.
type Info ¶
type Info struct {
// Source is MCPSource(server) or ModuleSource(id).
Source string `json:"source"`
// Name is the tool's own name at its source: the MCP tool's name, or the
// module capability's ID.
Name string `json:"name,omitempty"`
// Hints are what rules match: MCPHints or ModuleHints.
Hints []string `json:"hints,omitempty"`
// Trusted reports, for an MCP tool, whether its server is trusted.
Trusted bool `json:"trusted,omitempty"`
// Annotations are an MCP tool's annotations as its server declares them,
// trusted or not.
Annotations any `json:"annotations,omitempty"`
// Meta is an MCP tool's _meta.
Meta map[string]any `json:"meta,omitempty"`
// Effects are a module capability's declared effects.
Effects any `json:"effects,omitempty"`
}
Info is what a tool that is not Compa's own tells the policy and the approvers about itself.
type MCPAnnotations ¶
MCPAnnotations are the annotations an MCP server declares for a tool. A nil pointer is an annotation the server left out.
type Policy ¶
type Policy struct {
// Default decides the calls no rule matches; empty means allow.
Default Action `json:"default,omitempty"`
Rules []Rule `json:"rules"`
}
Policy is tools.approval.
func DefaultPolicy ¶
func DefaultPolicy() Policy
DefaultPolicy asks before a module capability that may cost money, reaches the network or writes outside the host runs, and before a skill is installed. Everything else is allowed.
func (Policy) Decide ¶
Decide returns the action for a call of tool from origin: that of the first rule matching it, or the default.
func (*Policy) UnmarshalJSON ¶
UnmarshalJSON sets the fields data holds and keeps the others, as config loading over the defaults needs. Rules that data holds replace p's rules: decoding them into p's would mix the fields of both.
type Rule ¶
type Rule struct {
// Tool matches the name the agent sees, such as "exec" or "mcp_github_*".
Tool string `json:"tool,omitempty"`
// Source matches the tool's source: "builtin", "mcp:<server>" or
// "module:<id>".
Source string `json:"source,omitempty"`
// Origin matches calls from any of these origins.
Origin []Origin `json:"origin,omitempty"`
// Hints matches tools that have any of these hints.
Hints []string `json:"hints,omitempty"`
Action Action `json:"action"`
}
Rule decides the calls that match every field it sets. In Tool and Source, '*' matches any run of characters and '?' any one character.