Documentation
¶
Overview ¶
Decides whether a tool call may run, asking a person when the rules do not settle it
Index ¶
- Constants
- Variables
- func AgentFrom(ctx context.Context) string
- func ReadOnlyOf(r *tool.Registry) func(string) bool
- func WithAgent(ctx context.Context, name string) context.Context
- type Answer
- type Approver
- type Asker
- type Bypasser
- type Decision
- type Denied
- type Explainer
- type Extractor
- type Gate
- type Guard
- type Keyer
- type Lookup
- type Memory
- type Mode
- type ModeSwitch
- type Policy
- type Request
- type Rule
- type RuleSet
- type Rules
- func (p *Rules) Decide(call protocol.ToolCall) Decision
- func (p *Rules) Explain(call protocol.ToolCall) (Decision, string)
- func (p *Rules) Key(call protocol.ToolCall) string
- func (p *Rules) Reset(sets ...RuleSet) error
- func (p *Rules) Rules(decision Decision) []string
- func (p *Rules) Set() RuleSet
- func (p *Rules) SubjectsOf(call protocol.ToolCall) []Subject
- type Subject
- type Subjecter
- type Verdict
Constants ¶
const ( KindPlain = "plain" KindCommand = "command" KindPath = "path" KindDomain = "domain" )
Kinds of subject a pattern is matched against
Variables ¶
var DefaultEdits = []string{"Write", "Edit"}
Tools AcceptEdits lets through without asking
var DefaultSubjects = map[string]Extractor{ "Shell": Shell("command"), "ShellOutput": Strings("job_id"), "KillShell": Strings("job_id"), "Read": Paths("file_path"), "Write": Paths("file_path"), "Edit": Paths("file_path"), "Glob": Paths("path"), "Grep": Paths("path"), "WebFetch": URLs("url"), }
Extractors for the tools icebath ships, every other tool matched over its string arguments
Functions ¶
func ReadOnlyOf ¶
Reports read only tools out of a registry by their annotations
Types ¶
type Answer ¶
type Answer struct {
Allowed bool
// Who decided, person or memory
By string
// What the person chose when a person decided
Verdict Verdict
Reason string
}
Outcome of an approval with who settled it
type Bypasser ¶
type Bypasser interface {
Bypassing() bool
}
Policy that can be switched off, every call then running with nothing consulted
type Decision ¶
type Decision string
type Extractor ¶
type Extractor func(args json.RawMessage) []Subject
Draws subjects from the arguments of one tool
type Gate ¶
type Gate struct {
Policy Policy
Approver Approver
// Describes tools on approval requests when set
Tools Lookup
// Called with every request handed to the approver
OnAsk func(Request)
// Called with the answer or error the approver gave
OnAnswer func(Request, Answer, error)
}
Policy and approver together, asking for everything without a policy and denying every ask without an approver
type Guard ¶
type Guard struct {
// Consulted first, asking for everything when nil
Base Policy
// Registry whose annotations are read, every tool counting as destructive and open world when nil
Tools *tool.Registry
}
Policy raising an allow the base reached by default to ask for tools annotated destructive or open world
type Memory ¶
type Memory struct {
Ask Asker
// Groups calls that share one remembered answer, the request key or tool name when nil
Key func(call protocol.ToolCall) string
// contains filtered or unexported fields
}
Approver that remembers always and never answers under a key derived from the call
type Mode ¶
type Mode string
const ( // Base policy decides everything ModeDefault Mode = "default" // Read only tools follow the base policy and every other tool is denied ModePlan Mode = "plan" // File editing tools run without asking unless the base policy denies them ModeAcceptEdits Mode = "acceptEdits" // Every call runs with no rule, guard, memory or hook permission consulted ModeBypass Mode = "bypassPermissions" )
type ModeSwitch ¶
type ModeSwitch struct {
// Consulted when the mode defers, asking for everything when nil
Base Policy
// Reports whether a tool only reads
ReadOnly func(name string) bool
// contains filtered or unexported fields
}
Policy whose mode may be changed while runs are in flight
func Compose ¶
func Compose(start Mode, rules Policy, tools *tool.Registry) *ModeSwitch
Standard stack, a switchable mode over a guard over the rules, with the guard respecting explicit rules
func (*ModeSwitch) Bypassing ¶
func (s *ModeSwitch) Bypassing() bool
Reports whether every call runs with nothing consulted
type Request ¶
type Request struct {
Call protocol.ToolCall
// Agent that wants to run the call
Agent string
// Why the gate is asking rather than deciding
Reason string
// Rule text an always or never answer will remember
Key string
Subjects []Subject
// Definition of the tool when the gate knows its registry
Tool *protocol.Tool
Hints tool.Annotations
}
Everything a person needs to decide one call
type RuleSet ¶
type RuleSet struct {
Allow []string `json:"allow,omitempty"`
Deny []string `json:"deny,omitempty"`
Ask []string `json:"ask,omitempty"`
}
Lists of rules by decision, the shape of a permissions block
func LoadRulesFile ¶
type Rules ¶
type Rules struct {
// Answer when no rule settles a call, Ask when empty
Default Decision
// Base of relative path patterns and paths, the process working directory when empty
Dir string
// Current directory consulted ahead of Dir on every match so a moving shell is followed
DirFunc func() string
// contains filtered or unexported fields
}
Policy answering deny for any denied subject, ask for any asked one and allow when every subject is allowed
func (*Rules) Reset ¶
Swaps every rule for the sets compiled in order, keeping the old rules when one is malformed
type Subject ¶
type Subject struct {
// What the text is, such as command, path, domain or plain
Kind string
Text string
// Runs commands the line does not spell out, through substitution, eval or source, so no allow pattern can vouch for it
Unsafe bool
// Whole command line that only a wildcard free pattern may match
Exact bool
}
One thing a call operates on, drawn from its arguments
func AllStrings ¶
func AllStrings(args json.RawMessage) []Subject
Plain subjects for every top level string argument in key order
func SplitCommand ¶
Subjects for the simple commands of a line as the shell parses it, one unsafe subject for a line that does not parse