Documentation
¶
Overview ¶
Package permissions is the safety layer of the local/coding profile: rules (allow / ask / deny) and modes decide, before a tool call runs, whether it is executed, needs the user's approval or is refused. It plugs into the agent as a BeforeToolHook (approvals reuse the AG-UI interrupt and resume flow) and knows how to read shell commands well enough to judge every simple command of a line.
Index ¶
- func DeniedMessage(d Decision) string
- func ToolClass(tool string) string
- type Action
- type Decision
- type File
- type Hook
- func (h *Hook) Denial(ctx context.Context, run *store.Run, toolName, arguments string) string
- func (h *Hook) NeedsApproval(ctx context.Context, run *store.Run, toolName, arguments string) bool
- func (h *Hook) Pause(ctx context.Context, run *store.Run, tc ai.ToolCall) (*tools.Interrupt, error)
- func (h *Hook) Risky(ctx context.Context, run *store.Run, toolName, arguments string) bool
- type Mode
- type Options
- type Parsed
- type Policy
- type Redirect
- type Rule
- type Simple
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeniedMessage ¶
DeniedMessage is the tool result of a refused call.
Types ¶
type Decision ¶
type Decision struct {
Action Action
// Reason says why, for the user and the model.
Reason string
// Rule is the user rule that decided, if any.
Rule string
// Hard decisions (built-in catastrophic denials) cannot be allowed by a rule.
Hard bool
// Once: approving the call approves the tool for the rest of the run.
Once bool
// ReadOnly: the call was judged read-only (what readonly mode allows).
ReadOnly bool
}
Decision is the outcome for a tool call.
type File ¶
type File struct {
Mode string `yaml:"mode"`
Allow []string `yaml:"allow"`
Ask []string `yaml:"ask"`
Deny []string `yaml:"deny"`
}
File is the YAML form of a permissions file (.har/permissions.yml).
type Hook ¶
Hook is the agent's BeforeToolHook for the local/coding profile. Calls the policy allows run at once; calls it asks about pause the run with a normal approval interrupt (resumed by the approval decision); calls it denies are refused with a clear tool error (it implements agent.ToolDenier). Tools the policy has no opinion on go to Inner, the interactive-mode approval gate.
func (*Hook) NeedsApproval ¶
NeedsApproval implements agent.BeforeToolHook.
type Mode ¶
type Mode string
Mode is how strictly calls are gated (AGENT_PERMISSIONS).
const ( // ModeAsk applies the rules and defaults: what is not known safe is asked. ModeAsk Mode = "ask" // ModeAutoEdit is ask, but edits are free everywhere (still not .git internals or secrets). ModeAutoEdit Mode = "auto-edit" // ModeYolo never asks; deny rules still apply. ModeYolo Mode = "yolo" // ModeYoloUnsafe never asks and ignores deny rules too. ModeYoloUnsafe Mode = "yolo-unsafe" // ModeReadOnly refuses edits and every command that is not read-only. ModeReadOnly Mode = "readonly" )
type Options ¶
type Options struct {
// Workspace is the host directory the agent works in (its /workspace).
Workspace string
// Mode is AGENT_PERMISSIONS ("" lets the files decide, then ask).
Mode string
// Allow, Ask and Deny are extra rules from the environment
// (AGENT_PERMISSIONS_ALLOW|ASK|DENY: entries separated by newlines or ";;").
Allow, Ask, Deny string
// AskTools are globs on tool names that are asked about, once per run, unless a rule says otherwise
// (the tools of MCP servers that start local programs: "name__*").
AskTools []string
// Files are read in order when they exist; earlier files have priority for
// the mode. Default: <workspace>/.har/permissions.yml, then
// ~/.har/permissions.yml.
Files []string
// Home is the user's home directory (default os.UserHomeDir).
Home string
// Trusted says the project is trusted (config.TrustFile): its permissions file may then add allow rules
// and loosen the mode. Otherwise only the default workspace file is affected: its allow rules are ignored
// and its mode only counts when it is as strict as the one already in force. Files given explicitly in
// Files are the caller's own and are always honoured.
Trusted bool
}
Options builds a Policy.
type Parsed ¶
type Parsed struct {
// Commands are all simple commands, including those inside $(...), backticks,
// subshells, bash -c strings and pipelines.
Commands []Simple
// Pipelines are the texts of the multi-command pipelines ("curl x | sh"),
// by Pipeline index of their commands (single commands have none).
Pipelines map[int]string
// Incomplete: the line could not be parsed with confidence (unbalanced quote,
// too deep nesting). Callers must treat it as unknown.
Incomplete bool
}
Parsed is the result of splitting a shell line.
func Parse ¶
Parse splits a shell command line into the simple commands it would run. It is a conservative approximation of bash, enough to judge each command: it understands quotes, escapes, ; && || | & newlines, subshells and groups, $(...) and backticks (also inside double quotes), heredocs, redirections, env prefixes and the wrappers sudo, env, nohup, time, nice, timeout, xargs, command, exec, eval and `sh -c '…'`.
type Policy ¶
type Policy struct {
Mode Mode
Rules []Rule
Workspace string // host directory of /workspace ("" if unknown)
Home string
Files []string // permission files that were read
// Ignored says what an untrusted project's permissions file asked for and was not honoured.
Ignored []string
// AskTools: tools (name globs) that ask, once per run, when no rule matches them.
AskTools []string
}
Policy decides tool calls.
type Redirect ¶
Redirect is a file redirection of a command (> >> >|, &>); input redirections and descriptor duplications (2>&1) are not kept.
type Rule ¶
type Rule struct {
Action Action
Kind string
Tool string // kindTool: glob on the tool name
Pattern string
Source string // where it came from, for messages
}
Rule is one allow, ask or deny rule.
func ParseRule ¶
ParseRule reads a rule entry of the config file:
execute_command(git push*) Bash(git push*) and a bare "git push*" mean the same write_file(**/.env) Edit(...), Write(...), edit_file(...): paths of write_file and edit_file write_file the whole tool (also execute_command / Bash) mcp__github__create*(*) any other tool: its name, and a glob on its JSON arguments
type Simple ¶
type Simple struct {
// Words are the program and its arguments, after env prefixes and wrappers
// (sudo, env, nohup, time, timeout, xargs, bash -c …) are removed.
Words []string
// Raw is the original text of the words (before wrappers were removed).
Raw string
// Env are the leading NAME=value assignments.
Env []string
// Elevated: run through sudo/doas.
Elevated bool
// Dynamic: some arguments come from a pipe (xargs), so their values are unknown.
Dynamic bool
// Dyn marks words (by index in Words) that contain a variable or command
// substitution, whose value is unknown.
Dyn map[int]bool
// Redirects are the output redirections.
Redirects []Redirect
// Pipeline identifies the pipeline of the line this command is part of.
Pipeline int
}
Simple is one simple command of a shell line, as far as it can be judged without running the shell.