permissions

package
v1.168.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 2 modules, 1 package

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

Overview

Package permissions provides tool permission checking based on configurable Allow/Ask/Deny patterns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlwaysAllowLabel added in v1.168.0

func AlwaysAllowLabel(pattern string) string

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

func BuildPermissionPattern(ctx context.Context, toolCall tools.ToolCall) string

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

func CommandAllowCoversCall(toolName string, allowPatterns []string, args map[string]any) bool

CommandAllowCoversCall checks strict grants: simple commands and literal word boundaries.

func PatternLabel added in v1.168.0

func PatternLabel(pattern string) string

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

func ScopedPermissionPattern(ctx context.Context, toolCall tools.ToolCall) string

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 FromAgentsIgnore(startDir string) *Checker

func FromAgentsIgnorePatterns added in v1.168.0

func FromAgentsIgnorePatterns(patterns []string) *Checker

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

func Merge(checkers ...*Checker) *Checker

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

func NewCheckerFromRules(allow, ask, deny []string) *Checker

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

func (c *Checker) AllowPatterns() []string

AllowPatterns returns the list of allow patterns.

func (*Checker) AskPatterns

func (c *Checker) AskPatterns() []string

AskPatterns returns the list of ask patterns.

func (*Checker) Check

func (c *Checker) Check(toolName string) Decision

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

func (c *Checker) CheckWithArgs(toolName string, args map[string]any) Decision

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

func (c *Checker) DenyPatterns() []string

DenyPatterns returns the list of deny patterns.

func (*Checker) IsEmpty

func (c *Checker) IsEmpty() bool

IsEmpty returns true if no permissions are configured

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
)

func (Decision) String

func (d Decision) String() string

String returns a human-readable representation of the decision

type Shadow added in v1.167.0

type Shadow struct {
	Ask   string
	Allow string
}

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).

Jump to

Keyboard shortcuts

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