approval

package
v0.99.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package approval implements chatagent auto approval mode helpers: mode parsing, Layer2 flagged detection, aux LLM review, and denial circuit breaker.

Index

Constants

View Source
const DefaultDenialThreshold = 3

DefaultDenialThreshold is the consecutive auto-path DENY count that trips the breaker.

View Source
const MaxArgsBytes = 4 * 1024

MaxArgsBytes caps tool argument JSON embedded in the reviewer prompt.

View Source
const MaxReasonChars = 200

MaxReasonChars caps sanitized reviewer reasons injected into tool errors.

View Source
const ReasonBreakerTripped = "approval circuit breaker: too many consecutive denials; stop retrying tools"

ReasonBreakerTripped is returned when the denial circuit breaker has latched.

Variables

This section is empty.

Functions

func FormatReviewUserPrompt

func FormatReviewUserPrompt(req ReviewRequest) string

FormatReviewUserPrompt builds the XML-isolated user prompt.

func IsReadonlyTool

func IsReadonlyTool(tool string) bool

IsReadonlyTool reports whether the tool is treated as side-effect free for auto mode.

func SanitizeReason

func SanitizeReason(reason string) string

SanitizeReason trims, strips instruction-like prefixes, and caps length.

Types

type Breaker

type Breaker struct {
	// contains filtered or unexported fields
}

Breaker counts consecutive auto-path denials within one run and latches when tripped.

func NewBreaker

func NewBreaker(threshold int) *Breaker

NewBreaker creates a run-scoped denial circuit breaker.

func (*Breaker) Count

func (b *Breaker) Count() int

Count returns the current consecutive denial count (tests and diagnostics).

func (*Breaker) RecordDenial

func (b *Breaker) RecordDenial() bool

RecordDenial increments the consecutive denial count and latches at threshold. It returns true when this call trips (or already tripped) the breaker.

func (*Breaker) Reset

func (b *Breaker) Reset()

Reset clears the consecutive denial count after a successful approve/execute. A tripped latch is not cleared within the same run.

func (*Breaker) Tripped

func (b *Breaker) Tripped() bool

Tripped reports whether the breaker has latched for this run.

type Completer

type Completer interface {
	Complete(ctx context.Context, systemPrompt, userPrompt string) (string, error)
}

Completer is the narrow LLM seam used by LLMReviewer.

type FlaggedResult

type FlaggedResult struct {
	Flagged bool
	Reason  string
}

FlaggedResult describes whether a tool call needs aux review.

func EvaluateFlagged

func EvaluateFlagged(req permission.Request) FlaggedResult

EvaluateFlagged returns whether a side-effect tool call should enter aux review.

type LLMReviewer

type LLMReviewer struct {
	Complete Completer
}

LLMReviewer calls an injected Completer with an XML-isolated prompt.

func (*LLMReviewer) Review

func (r *LLMReviewer) Review(ctx context.Context, req ReviewRequest) (ReviewResult, error)

Review runs the aux security classification.

type Mode

type Mode string

Mode selects which tool-approval pipeline chatagent uses for interactive runs.

const (
	// ModeManual is DCG → full permission → ConfirmGate (Always allowed).
	ModeManual Mode = "manual"
	// ModeAuto is DCG → deny-only → flagged → aux LLM → ConfirmGate on escalate only.
	ModeAuto Mode = "auto"
	// ModeOff is DCG → deny-only → allow (no ask, no aux LLM).
	ModeOff Mode = "off"
)

func ParseMode

func ParseMode(raw string) (Mode, error)

ParseMode validates and normalizes an approval mode string.

func (Mode) Valid

func (m Mode) Valid() bool

Valid reports whether m is a known mode.

type ReviewRequest

type ReviewRequest struct {
	ToolName      string
	Args          map[string]any
	FlaggedReason string
}

ReviewRequest is the isolated input for the auxiliary security reviewer.

type ReviewResult

type ReviewResult struct {
	Verdict Verdict
	Reason  string
}

ReviewResult is a parsed aux reviewer response.

func ParseReviewOutput

func ParseReviewOutput(raw string) (ReviewResult, error)

ParseReviewOutput parses and validates aux LLM JSON output.

type Reviewer

type Reviewer interface {
	Review(ctx context.Context, req ReviewRequest) (ReviewResult, error)
}

Reviewer classifies a flagged tool call as APPROVE, DENY, or ESCALATE.

type Verdict

type Verdict string

Verdict is the aux reviewer classification.

const (
	// VerdictApprove silently allows the tool call.
	VerdictApprove Verdict = "APPROVE"
	// VerdictDeny blocks the tool call and injects reason to the agent.
	VerdictDeny Verdict = "DENY"
	// VerdictEscalate asks a human via ConfirmGate.
	VerdictEscalate Verdict = "ESCALATE"
)

Jump to

Keyboard shortcuts

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