policy

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Overview

Package policy decides whether an agent may run an action without asking the user. It is the only place that maps an action's risk and the run's access level to allow, ask or deny; tools ask it instead of comparing levels themselves. What the agent can reach at all (registered tools, workspace roles, writable knowledge bases) is decided elsewhere and is not widened by anything here.

See docs/design/agent-permission-model.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Covers

func Covers(granted, r Risk) bool

Covers reports whether a grant approved for risk granted applies to a call of risk r: a grant never covers a riskier call than it was approved for.

func Grantable

func Grantable(a Action) bool

Grantable reports whether approving a during a run may be remembered for later calls of the same kind: only recoverable changes the workspace does not require approving every time.

func Offered

func Offered(level types.AssistantAccessLevel, risk Risk) bool

Offered reports whether an action of risk should be offered to the model at all under level. A read-only run is not shown changes it cannot make, nor anything whose risk is unknown.

func Pregrantable

func Pregrantable(a Action) bool

Pregrantable reports whether a standing grant, approved ahead of time for a specific resource, may cover a. Unlike Grantable this includes destructive actions, which only an automation's settings may pre-approve; Always still asks every time.

func Record

func Record(ctx context.Context, key string, a Action, r Rules, v Verdict)

Record logs a decision on anything but a read, so what an agent changed without asking, and on whose behalf, can be traced later. key names the action, e.g. an operation ID or "mcp:<service>/<tool>".

Types

type Action

type Action struct {
	Risk Risk
	// Always asks every time, whatever the level: a skill installation, or an
	// MCP tool the workspace marked as requiring approval.
	Always bool
}

Action is one call the agent wants to make.

type Risk

type Risk string

Risk classifies an action by its effect on user data.

const (
	// RiskRead has no side effects.
	RiskRead Risk = "read"
	// RiskProbe changes no data but does real work to answer: it connects to
	// an external service or runs a retrieval.
	RiskProbe Risk = "probe"
	// RiskWrite changes state in a recoverable way (reparse, status change).
	RiskWrite Risk = "write"
	// RiskDestructive removes data or cannot be undone.
	RiskDestructive Risk = "destructive"
)

func (Risk) Above

func (r Risk) Above(other Risk) bool

Above reports whether r is a higher risk than other. Every known risk is above an unknown or empty one.

func (Risk) Mutates

func (r Risk) Mutates() bool

Mutates reports whether the action changes data.

func (Risk) Valid

func (r Risk) Valid() bool

Valid reports whether r is a known risk.

type Rules

type Rules struct {
	// Level is the run's effective access level.
	Level types.AssistantAccessLevel
}

Rules are what the run allows.

type Verdict

type Verdict int

Verdict is the outcome of Decide.

const (
	// Allow runs the action without asking.
	Allow Verdict = iota
	// Ask runs the action only after the user approves it.
	Ask
	// Deny refuses the action: the run may not make it even with approval.
	Deny
)

func Decide

func Decide(a Action, r Rules) Verdict

Decide returns whether a may run under r. Mutations a read-only run must not make are kept from the model by Offered; one that still arrives is denied.

func (Verdict) String

func (v Verdict) String() string

String names v for logs.

Jump to

Keyboard shortcuts

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