approval

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package approval implements approval policies, matching packages/core/approval (M27).

Policies are allow-all, deny-all, ask-dangerous, and ask-dangerous-tool-edit. Resolution applies preset, user, then session overrides; the nearest scope wins and Source records the effective layer for auditing. Approval grants apply to one tool call only: subsequent calls must ask again. Evaluate supplies the Allow/Deny/Ask decision consumed by PreToolDecision (M22).

User Questions handles prompts. Injecting the preset-to-policy mapping avoids a dependency cycle between approval and presets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DangerFunc

type DangerFunc func(tool string) bool

DangerClass classifies tools for the ask-dangerous policies.

type Decision

type Decision int

Decision is the three-state tool pre-execution decision used by M22.

const (
	DecideAllow Decision = iota
	DecideDeny
	DecideAsk
)

The three possible decisions.

func (Decision) String

func (d Decision) String() string

String returns the human-readable decision.

type EffSource

type EffSource string

EffSource identifies the layer supplying the effective policy.

const (
	SourcePreset  EffSource = "preset"
	SourceUser    EffSource = "user"
	SourceSession EffSource = "session"
)

type Effective

type Effective struct {
	Policy Policy    `json:"policy"`
	Source EffSource `json:"source"`
}

Effective holds a resolved policy and its audit source.

type Policy

type Policy string

Policy identifies an approval policy.

const (
	PolicyAllowAll         Policy = "allow-all"
	PolicyDenyAll          Policy = "deny-all"
	PolicyAskDangerous     Policy = "ask-dangerous"
	PolicyAskDangerousEdit Policy = "ask-dangerous-tool-edit"
)

Approval policies, aligned with pkg/session.ApprovalPolicy.

type PresetPolice

type PresetPolice func(preset string) (Policy, bool)

PresetPolice maps a preset name to a policy; false selects the fallback.

type Request

type Request struct {
	// Tool is the tool name.
	Tool string
	// CallID uniquely identifies the invocation covered by a one-time approval.
	CallID string
	// Preset selects the preset-layer policy.
	Preset string
	// SessionID selects the session override; empty means no override.
	SessionID string
	// DangerousOverride supplies classification; nil uses the built-in list.
	DangerousOverride DangerFunc
}

Request describes approval for one tool invocation.

type Service

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

Service implements ctx.approval.

func New

func New(preset PresetPolice, uq *userq.Service) *Service

New creates the approval service with an injected preset mapping and question service. PresetPolice resolves the preset layer at runtime, outside scope.

func (*Service) AskCount

func (s *Service) AskCount() int

AskCount returns the total prompt count for assertions.

func (*Service) ClearSessionPolicy

func (s *Service) ClearSessionPolicy(sessionID string)

ClearSessionPolicy removes a session override.

func (*Service) Evaluate

func (s *Service) Evaluate(req Request) (Decision, error)

Evaluate returns an allow, deny, or ask decision for one tool call. Allow-all permits and deny-all rejects. The ask-dangerous policies prompt through User Questions for dangerous tools and allow other tools. User approval permits only this call; the next invocation must ask again.

func (*Service) Resolve

func (s *Service) Resolve(preset string, sessionID string) Effective

Resolve applies preset, user, then session policies; session has priority.

func (*Service) SetDangerous

func (s *Service) SetDangerous(m map[string]bool)

SetDangerous replaces the dangerous-tool list.

func (*Service) SetSessionPolicy

func (s *Service) SetSessionPolicy(sessionID string, p Policy)

SetSessionPolicy sets the highest-priority session override (source=session).

func (*Service) SetUserPolicy

func (s *Service) SetUserPolicy(p Policy)

SetUserPolicy sets the user-layer override (source=user).

func (*Service) SetUserPolicyByKey

func (s *Service) SetUserPolicyByKey(userKey string, p Policy)

SetUserPolicyByKey sets the policy override for a user.

Jump to

Keyboard shortcuts

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