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
- Variables
- func Gated(mode, toolName string) bool
- func Interrupt(a *store.Approval) *tools.Interrupt
- func IsRisky(toolName string) bool
- func IsTrustMCPTool(toolName string) bool
- func Kind(toolName string) string
- func MatchesCall(a *store.Approval, tc ai.ToolCall) bool
- func Preview(arguments string) string
- func PreviewMatches(expected, current string) bool
- func RegisterRisky(names ...string)
- type Gate
- func (g *Gate) Denial(ctx context.Context, run *store.Run, toolName, _ string) string
- func (g *Gate) Interactive(ctx context.Context, run *store.Run) bool
- func (g *Gate) NeedsApproval(ctx context.Context, run *store.Run, toolName, arguments string) bool
- func (g *Gate) Pause(ctx context.Context, run *store.Run, tc ai.ToolCall) (*tools.Interrupt, error)
- func (g *Gate) Risky(ctx context.Context, run *store.Run, toolName, arguments string) bool
- type PathResolver
- type SandboxResolver
- type Store
Constants ¶
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).
const MismatchResult = "" /* 153-byte string literal not displayed */
MismatchResult is the tool result of an approved call whose arguments changed.
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).
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.
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 ¶
var WorkAreas = []string{"/workspace/outputs/", "/workspace/.work/"}
WorkAreas are the sandbox directories written without approval.
Functions ¶
func IsRisky ¶
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 ¶
IsTrustMCPTool reports a tool name of that kind.
func MatchesCall ¶
MatchesCall reports whether an approval still describes a tool call (same tool, same arguments): an approve decision only runs a matching call.
func Preview ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Pause records the pending approval of a call and returns the interrupt that ends the run.
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 ¶
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).
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.