approval

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package approval holds the types shared by the tool-approval wrapper and the tools that know which of their calls need a human decision.

The package deliberately has no dependency on the tools package so that both built-in tools (including tools/custom) and front-ends can use it.

Index

Constants

View Source
const (
	ModeOff       = "off"       // never ask
	ModeDangerous = "dangerous" // ask only for calls a tool flags as mutating (default)
	ModeAll       = "all"       // ask before every tool call
)

Approval modes, configured with settings.approval.mode.

View Source
const (
	AllowOnce    = "允许本次"
	AllowSession = "本会话允许"
	Deny         = "拒绝"
)

Answers a front-end offers for an approval request.

Variables

This section is empty.

Functions

This section is empty.

Types

type Classifier

type Classifier interface {
	ApprovalRequest(arguments string) (Request, bool)
}

Classifier is implemented by tools that can tell whether a specific call is dangerous. The bool result is true when the call mutates state, runs code or otherwise deserves confirmation.

type Policy

type Policy struct {
	Mode   string
	Allow  map[string]bool // tools that never need approval
	Always map[string]bool // tools that always need approval
}

Policy is the resolved approval configuration.

func (Policy) ModeOrDefault

func (p Policy) ModeOrDefault() string

ModeOrDefault returns the configured mode, defaulting to ModeDangerous so a tool that can run commands or write files asks before doing so.

func (Policy) NeedsApproval

func (p Policy) NeedsApproval(name, arguments string, classifier Classifier) (Request, bool)

NeedsApproval decides whether a call must be confirmed and builds the request shown to the user.

type Request

type Request struct {
	Tool    string `json:"tool"`
	Summary string `json:"summary"`          // one-line description of the action
	Detail  string `json:"detail,omitempty"` // raw tool arguments, for context
}

Request describes one tool call that is waiting for the user's decision.

Jump to

Keyboard shortcuts

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