approvals

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

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 approvals implements Work's interactive mode: risky tool calls of an interactive run pause before they execute until the user approves, denies or answers them (agent BeforeToolHook; decisions are applied by the store when the resume run is created and by the agent when it starts).

Index

Constants

View Source
const DefaultRiskyToolPatterns = "create|send|update|delete|post|publish|write"

DefaultRiskyToolPatterns are APPROVAL_RISKY_TOOL_PATTERNS' default: the mutating verbs that make an MCP tool need approval (matched per name word).

View Source
const MismatchResult = "" /* 153-byte string literal not displayed */

MismatchResult is the tool result of an approved call whose arguments changed.

View Source
const PauseFailedResult = "Error: the approval request could not be recorded, so the action was not run. Try again later."

PauseFailedResult is the tool result when the approval could not be recorded (fail closed).

View Source
const TrustMCPDeniedResult = "Error: the project's MCP server was not approved and this run cannot ask the user (automatic mode), so it was not started. " +
	"Tell the user to run `harness trust mcp` for it."

TrustMCPDeniedResult is the result of the MCP-server approval tool where nobody can be asked.

View Source
const TrustMCPToolPrefix = "mcp_approve__"

TrustMCPToolPrefix starts the name of the tool that asks the user to approve a project's stdio MCP server (features/mcp); its approval preview describes the server instead of echoing the call's arguments.

Variables

View Source
var WorkAreas = []string{"/workspace/outputs/", "/workspace/.work/"}

WorkAreas are the sandbox directories written without approval.

Functions

func Gated

func Gated(mode, toolName string) bool

Gated reports whether a call of an interactive run must wait for approval.

func Interrupt

func Interrupt(a *store.Approval) *tools.Interrupt

Interrupt is the AG-UI interrupt of a pending approval.

func IsRisky

func IsRisky(toolName string) bool

IsRisky reports tools that need the user's approval in interactive mode: execute_command, write_file, edit_file and any tool whose name starts with delete/remove/move/rename — for MCP tools ({server}__{tool}) the tool part counts (Work's is_risky_tool). Every part after a "__" is a candidate, so a tool named "delete__all" (srv__delete__all) is risky too.

func IsTrustMCPTool

func IsTrustMCPTool(toolName string) bool

IsTrustMCPTool reports a tool name of that kind.

func Kind

func Kind(toolName string) string

Kind is the tool kind an approval with scope "run" covers (the normalized tool name).

func MatchesCall

func MatchesCall(a *store.Approval, tc ai.ToolCall) bool

MatchesCall reports whether an approval still describes a tool call (same tool, same arguments): an approve decision only runs a matching call.

func Preview

func Preview(arguments string) string

Preview is the canonical JSON of tool arguments (sorted keys, compact, no HTML escaping, numbers kept as written: Work's build_tool_input_preview). Invalid JSON is returned trimmed as is.

func PreviewMatches

func PreviewMatches(expected, current string) bool

PreviewMatches compares an approved preview with the current call's preview (Work's _preview_matches: empty expected matches, "..." is a truncated prefix).

func RegisterRisky

func RegisterRisky(names ...string)

RegisterRisky makes the named tools need approval in interactive runs, like the built-in risky ones (a host's own tools that act on the world). Call it at start-up, before runs.

Types

type Gate

type Gate struct {
	Store Store
	// RiskyToolPattern matches the words of MCP tool names that need approval
	// (APPROVAL_RISKY_TOOL_PATTERNS; nil: DefaultRiskyToolPatterns).
	RiskyToolPattern *regexp.Regexp
	// Resolver resolves symlinks before the work-area check (nil: lexical only).
	Resolver PathResolver
	// Describe is the approval preview of an MCP-server approval tool (TrustMCPToolPrefix; "" when it knows
	// no such tool: the call is then refused, never asked without saying what is approved).
	Describe func(toolName string) string
}

Gate is the agent's BeforeToolHook for interactive runs (harness v3 §7).

func (*Gate) Denial

func (g *Gate) Denial(ctx context.Context, run *store.Run, toolName, _ string) string

Denial implements agent.ToolDenier: the approval tool of a project's MCP server is refused unless the run is interactive (fail closed: an automatic or headless run never approves a program to run).

func (*Gate) Interactive

func (g *Gate) Interactive(ctx context.Context, run *store.Run) bool

Interactive reports whether the run is interactive now, i.e. its host answers approvals (a failed read of the mode counts as interactive, like NeedsApproval).

func (*Gate) NeedsApproval

func (g *Gate) NeedsApproval(ctx context.Context, run *store.Run, toolName, arguments string) bool

NeedsApproval implements agent.BeforeToolHook. In interactive mode it gates execute_command, writes/edits and deletes/moves of paths outside the work areas (/workspace/outputs/, /workspace/.work/: never asked), and MCP tools whose name has a mutating word (or starts with delete/remove/move/rename); a tool kind approved for the run (scope "run") is not asked again. The mode is the run's current one (switched mid-run by the user), not the one it started with; NeedsApproval has no side effects.

func (*Gate) Pause

func (g *Gate) Pause(ctx context.Context, run *store.Run, tc ai.ToolCall) (*tools.Interrupt, error)

Pause records the pending approval of a call and returns the interrupt that ends the run.

func (*Gate) Risky

func (g *Gate) Risky(ctx context.Context, run *store.Run, toolName, arguments string) bool

Risky implements agent.RiskJudge: NeedsApproval's rules as if the run were interactive (a tool kind approved for the run is still not risky). It reads no mode, so calls after a pending approval of the step keep waiting behind it after a switch to automatic.

type PathResolver

type PathResolver interface {
	RealPaths(ctx context.Context, run *store.Run, paths []string) ([]string, error)
}

PathResolver resolves the symlinks of absolute sandbox paths of a run's thread.

type SandboxResolver

type SandboxResolver struct{ Sandboxes sandbox.Manager }

SandboxResolver resolves paths with realpath in the thread's live sandbox. Without one (round 3, N5) the paths are their own real paths: the gate never starts a sandbox, and write_file/edit_file refuse to write through a symlink that a workspace restored into the new sandbox may hold (N6).

func (SandboxResolver) RealPaths

func (r SandboxResolver) RealPaths(ctx context.Context, run *store.Run, paths []string) ([]string, error)

RealPaths implements PathResolver.

type Store

type Store interface {
	CreateApproval(ctx context.Context, a *store.Approval) error
	// RunInteractionMode is the run's current mode: the user may switch it
	// while the run is active ("" is automatic).
	RunInteractionMode(ctx context.Context, runID string) (string, error)
}

Store is the persistence used by the gate.

Jump to

Keyboard shortcuts

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