autoapprove

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package autoapprove provides an AI-powered evaluator for tool approval decisions. Instead of showing the manual confirmation overlay, it sends the action and reason to a Haiku-class model and returns the model's approve/deny decision along with a short rationale.

The evaluator makes a single-turn API call with no tool use. The model responds with a JSON object containing "approved" (bool) and "rationale" (string). Malformed responses are treated as denials so that a parsing failure never silently permits a dangerous action.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Evaluate

func Evaluate(ctx context.Context, apiKey, systemPrompt, command, reason string, evaluatorModel model.ID, opts ...client.Option) (bool, string, error)

Evaluate sends the action subject (command or URL) and reason to the configured evaluator model and returns its approval decision. systemPrompt is the evaluator instructions for the action category (supplied by the requesting tool's approval descriptor). evaluatorModel selects which model performs the evaluation; callers should default it to a Haiku-class model since these calls are small and elicit a short, structured response, so a larger model adds no benefit. Returns (false, rationale, nil) on a clean denial; (false, "", err) on an API or parse error so the caller can treat any error as a denial with logging. opts configures additional transport options (e.g. client.WithProviderPreferences).

func EvaluateWithGenerationOptions added in v0.6.0

func EvaluateWithGenerationOptions(ctx context.Context, apiKey, systemPrompt, command, reason string, evaluatorModel model.ID, gen model.GenerationOptions, opts ...client.Option) (approved bool, rationale string, err error)

EvaluateWithGenerationOptions evaluates with the configured reasoning intent.

func WithTelemetry added in v0.6.0

func WithTelemetry(ctx context.Context, correlation Correlation, observe Observer) context.Context

WithTelemetry scopes immutable correlation to one evaluation context.

Types

type Correlation added in v0.6.0

type Correlation struct {
	EvaluationID string `json:"evaluation_id"`
	SessionID    string `json:"session_id"`
	ToolName     string `json:"tool_name"`
	Variant      string `json:"variant,omitempty"`
	Subagent     bool   `json:"subagent"`
	AgentID      string `json:"agent_id,omitempty"`
}

Correlation is copied into each event; it never changes shared logger state.

type EvaluationError added in v0.6.0

type EvaluationError struct {
	Category       string
	Attempts       int
	RequestedModel model.ID
	ServedModel    model.ID
	Completion     *client.CompletionMetadata
	Routing        *client.Routing
	Transport      *client.TransportDiagnostics
	// contains filtered or unexported fields
}

EvaluationError reports a failed evaluation without retaining sensitive text.

func (*EvaluationError) Error added in v0.6.0

func (e *EvaluationError) Error() string

func (*EvaluationError) Unwrap added in v0.6.0

func (e *EvaluationError) Unwrap() error

type Observer added in v0.6.0

type Observer func(eventType string, facts map[string]any)

Observer receives only allowlisted facts, never request or response text.

func LogObserver added in v0.6.0

func LogObserver(log *logger.Logger) Observer

LogObserver uses the logger's atomic JSONL write path.

Source Files

  • autoapprove.go
  • classification.go
  • recovery.go
  • telemetry.go

Jump to

Keyboard shortcuts

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