Documentation
¶
Overview ¶
Package permission mediates tool execution approvals between the agent loop and the frontend. Three modes: yolo (auto-approve all), ask (auto-approve reads, confirm writes), auto (AI decides, with user-provided rules).
Index ¶
- func GenerateAllowPattern(toolName string, args map[string]any) string
- func IsDangerousCommand(cmd string) bool
- func PopApprovedFeedback(args map[string]any) string
- type Config
- type Decision
- type Evaluator
- type Gate
- func (g *Gate) AddAllow(pattern string)
- func (g *Gate) AddRule(rule string)
- func (g *Gate) AllowPatterns() []string
- func (g *Gate) Check(ctx context.Context, name string, args map[string]any) *core.ToolCallDecision
- func (g *Gate) Mode() Mode
- func (g *Gate) Requests() <-chan Request
- func (g *Gate) Rules() []string
- func (g *Gate) SetMode(mode Mode)
- func (g *Gate) SnapshotConfig() Config
- type Mode
- type Request
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateAllowPattern ¶
GenerateAllowPattern creates an allow pattern for the "always allow" shortcut. For bash, generates "Bash(firstWord:*)" from the command. For other tools, generates just the tool name.
func IsDangerousCommand ¶
IsDangerousCommand reports whether cmd downloads and executes remote code. See dangerousPatterns for the exact shapes and the heuristic-not-sandbox caveat.
func PopApprovedFeedback ¶
PopApprovedFeedback removes and returns a permission feedback note (if any) injected by askUser on approved decisions.
Types ¶
type Config ¶
type Config struct {
Allow []string // glob patterns: "Bash(npm:*)", "edit"
Deny []string // glob patterns always denied
Rules []string // natural language rules for auto mode
Evaluator *Evaluator // AI evaluator (nil in ask mode)
Headless bool // Deny instead of blocking when user approval needed (headless/CLI mode).
}
Config holds the gate's initial settings from merged config files.
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator uses a lightweight LLM to decide whether a tool call is safe.
func NewEvaluator ¶
NewEvaluator creates an evaluator with the given provider and model.
func (*Evaluator) Evaluate ¶
func (e *Evaluator) Evaluate(ctx context.Context, toolName string, args map[string]any, rules []string) Decision
Evaluate asks the LLM whether the tool call should be approved, denied, or escalated to the user. Rules are natural language instructions that guide the decision.
type Gate ¶
type Gate struct {
// contains filtered or unexported fields
}
Gate mediates tool permissions. Created once, shared between agent and frontend.
func (*Gate) AllowPatterns ¶
Allow returns the current allow patterns.
func (*Gate) Check ¶
Check decides whether a tool call may proceed. May block waiting for user approval. Returns nil to approve, or a blocking ToolCallDecision to reject. Called from the agent loop goroutine.
ask mode: deny globs → readOnly → allow globs → ask user auto mode: deny globs → readOnly → AI evaluator (rules) → ask user (fallback)
func (*Gate) SnapshotConfig ¶
SnapshotConfig returns a Config snapshot of the current gate state. Useful for preserving config when reconstructing a gate after yolo mode.