Documentation
¶
Overview ¶
Package permissions provides tool permission checking based on configurable Allow/Ask/Deny patterns.
Index ¶
- func AlwaysAllowLabel(pattern string) string
- func BuildPermissionPattern(ctx context.Context, toolCall tools.ToolCall) string
- func CommandAllowCoversCall(toolName string, allowPatterns []string, args map[string]any) bool
- func PatternLabel(pattern string) string
- func ScopedPermissionPattern(ctx context.Context, toolCall tools.ToolCall) string
- type Checker
- type Decision
- type Shadow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AlwaysAllowLabel ¶ added in v1.168.0
AlwaysAllowLabel is the descriptive label of the "always allow" option for a pattern from BuildPermissionPattern: the command pattern for shell ("always allow ls*"), the tool name otherwise. Whitespace runs are collapsed: a newline would split the label's help row across physical lines, breaking the one-line-per-row contract click hit-testing relies on, and an interior double space would read like the separator between options.
func BuildPermissionPattern ¶ added in v1.168.0
BuildPermissionPattern creates the permission pattern granted by the "always allow" decision. For command tools (shell, run_background_job) it extracts the first word of the command and creates a pattern like "shell:cmd=ls*" matching all invocations of that command; for other tools it returns the tool name.
func CommandAllowCoversCall ¶ added in v1.161.0
CommandAllowCoversCall checks strict grants: simple commands and literal word boundaries.
func PatternLabel ¶ added in v1.168.0
PatternLabel is the display form of a pattern from BuildPermissionPattern: the command pattern for shell ("ls*"), the tool name otherwise.
func ScopedPermissionPattern ¶ added in v1.168.0
ScopedPermissionPattern is BuildPermissionPattern for a grant stored without showing the user the resulting rule. It returns "" for a command tool call whose pattern is not limited to one command (no command word, or a glob or separator in it): the matcher reads those as allowing every command.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker evaluates tool permissions based on configured patterns
func FromAgentsIgnore ¶ added in v1.112.0
func FromAgentsIgnorePatterns ¶ added in v1.168.0
FromAgentsIgnorePatterns derives advisory deny rules from already-loaded .agentsignore lines so display stays in sync with the runtime's matcher snapshot.
func Merge ¶ added in v1.37.0
Merge returns a new Checker that combines the patterns from all provided checkers. Nil or empty checkers are skipped. The merged checker evaluates all deny patterns first, then all allow patterns, then all ask patterns.
func NewChecker ¶
func NewChecker(cfg *latest.PermissionsConfig) *Checker
NewChecker creates a new permission checker from config
func NewCheckerFromRules ¶ added in v1.104.0
NewCheckerFromRules builds a Checker directly from allow/ask/deny pattern slices, for callers that hold the rules outside a latest.PermissionsConfig (e.g. session-scoped permissions whose config type lives in the session package). Semantics are identical to NewChecker.
func (*Checker) AllowPatterns ¶
AllowPatterns returns the list of allow patterns.
func (*Checker) AskPatterns ¶
AskPatterns returns the list of ask patterns.
func (*Checker) Check ¶
Check evaluates the permission for a given tool name without arguments. This is a convenience method that calls CheckWithArgs with nil arguments. Evaluation order: Deny (checked first), then Allow, then Ask (default)
func (*Checker) CheckWithArgs ¶
CheckWithArgs evaluates the permission for a given tool name and its arguments. Evaluation order: Deny (checked first), then Allow, then Ask (explicit), then Ask (default).
The toolName can be a simple name like "shell" or a qualified name like "mcp:github:create_issue".
Patterns support:
- Simple tool names: "shell", "read_*"
- Argument matching: "shell:cmd=ls*" matches shell tool with cmd argument starting with "ls" For command-tool allow rules, literal trailing-* prefixes require a simple command and word boundary.
- Multiple arguments: "shell:cmd=ls*:cwd=/home/*" matches both conditions
- Glob patterns in both tool names and argument values
Returns ForceAsk when an explicit ask pattern matches. ForceAsk means the tool must always be confirmed, even when it would normally be auto-approved (e.g. read-only tools). Note that --yolo mode takes precedence over ForceAsk.
func (*Checker) DenyPatterns ¶
DenyPatterns returns the list of deny patterns.
type Decision ¶
type Decision int
Decision represents the permission decision for a tool call
const ( // Ask means the tool requires user approval (default behavior) Ask Decision = iota // Allow means the tool is auto-approved without user confirmation Allow // Deny means the tool is rejected and should not be executed Deny // ForceAsk means an explicit ask pattern matched; the tool must be // confirmed even if it would normally be auto-approved (e.g. read-only). ForceAsk )
type Shadow ¶ added in v1.167.0
Shadow reports an ask rule that a matching allow rule silences: the checker evaluates allow before ask, so the ask rule never prompts for any call the allow rule covers.
func ShadowedAskPatterns ¶ added in v1.167.0
func ShadowedAskPatterns(cfg *latest.PermissionsConfig) []Shadow
ShadowedAskPatterns returns the ask rules whose every matching call is also matched by an allow rule, so the ask rule can never prompt. Detection is conservative: it only reports a shadow when coverage is provable with the glob vocabulary the checker uses —
- an unconditional allow pattern ("*") covers every ask rule;
- otherwise the allow rule must carry no argument conditions and its tool glob must match the ask rule's tool name (an ask tool that is itself a glob is skipped: its match set cannot be proven covered);
- argument-scoped allow rules are never reported: matchAnyAllow routes command patterns through commandAllowMatches, which enforces a command-word boundary for literal trailing-star prefixes that the ask matcher does not, so such an ask can still prompt for calls the allow does not cover (e.g. "shell:cmd=ls*" allows ls, not lsof).