risk

package
v0.167.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoApprove

func AutoApprove(threshold Level, toolRisk Level) bool

AutoApprove returns whether a tool at the given risk level should auto-execute.

func Register added in v0.9.0

func Register(tool string, level Level)

Register publishes a risk level for tool at runtime. Used by mcpfed to classify federated MCP tools after their annotations are read at startup. A second Register call for the same tool overrides the previous level — the most recent assertion wins.

Invalid levels (outside [Low, Critical]) are rejected. AutoApprove is `toolRisk <= threshold`, so a stored Level(-1) would silently auto-approve at any non-negative threshold and bypass the confirm gate — exactly the property the registry exists to defend. The reject-vs-clamp choice matches Classify's fail-safe: an unregistered tool falls through to High, the safe default, rather than to whatever a typo'd caller passed.

func Unregister added in v0.9.0

func Unregister(tool string)

Unregister removes a runtime entry. Falls through to the static toolLevels map and ultimately the High default. Used in tests to keep the runtime overlay clean between cases.

func WantsDiff added in v0.13.0

func WantsDiff(level Level) bool

WantsDiff reports whether tools at the given level should have a unified-diff preview attached to their confirmation request. Today only Medium qualifies: High/Critical already require explicit approval and the operator usually wants to read the params box, not scroll a diff. Medium is the tier where the previous prompt asked "approve this write?" with no insight into what would change — the diff plugs that gap.

Types

type Level

type Level int
const (
	Low      Level = iota // Read-only, informational
	Medium                // Writes data, emulates signals
	High                  // Transmits RF, writes to tags, executes scripts
	Critical              // Attacks, brute force, destructive operations
)

func Classify

func Classify(tool string) Level

Classify returns the risk level for a given tool name. The runtime overlay is consulted first; otherwise the static toolLevels map; otherwise High (the safe default — an unknown capability is gated behind a confirmation rather than silently auto-approved).

func ClassifyExplicit

func ClassifyExplicit(tool string) (Level, bool)

ClassifyExplicit returns the registered risk level and true if the tool has an explicit classification (either from the runtime overlay or the static map), or (High, false) if the tool fell through to the safe default. Used by the agent-package coverage test to detect drift between the tool catalogue and this registry.

func (Level) String

func (l Level) String() string

Jump to

Keyboard shortcuts

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