policy

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package policy decides whether a tool call may run (SPEC §3.7 step 2, T5). It is pure.

The API's mode is a ceiling. A per-tool override can always tighten a decision (confirm, deny) but can never lift a tool above what the mode allows: under read-only, writes are denied even with "allow"; under confirm-writes they still need confirmation.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("invalid policy value")

ErrInvalid is returned for an unknown mode or override.

Functions

func Lists

func Lists(safety model.Safety, mode Mode) bool

Lists reports whether a tool should be offered to the model at all under mode: it is listed when the mode could allow or confirm it.

Types

type Decision

type Decision int

Decision is the outcome of Check.

const (
	Allow Decision = iota + 1
	Confirm
	Deny
)

Decisions, from least to most restrictive.

func (Decision) String

func (d Decision) String() string

type Limiter

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

Limiter is a token bucket: a burst of N calls, refilled at N per period.

func NewLimiter

func NewLimiter(r Rate, now func() time.Time) *Limiter

NewLimiter starts a full bucket. now is the clock (time.Now if nil).

func (*Limiter) Allow

func (l *Limiter) Allow() (ok bool, retryAfter time.Duration)

Allow takes one call from the budget. When there is none, it reports how long until there will be.

func (*Limiter) Rate

func (l *Limiter) Rate() Rate

Rate is the limiter's budget.

type Mode

type Mode string

Mode is an API-wide policy.

const (
	ReadOnly      Mode = "read-only"
	ConfirmWrites Mode = "confirm-writes"
	Full          Mode = "full"
)

Policy modes. ReadOnly is the default.

func ParseMode

func ParseMode(s string) (Mode, error)

ParseMode parses a mode name.

type Override

type Override string

Override is a per-tool policy.

const (
	None            Override = ""
	OverrideAllow   Override = "allow"
	OverrideConfirm Override = "confirm"
	OverrideDeny    Override = "deny"
)

Per-tool overrides.

func ParseOverride

func ParseOverride(s string) (Override, error)

ParseOverride parses a per-tool override ("" means none).

type Rate

type Rate struct {
	N   int
	Per time.Duration
}

Rate is a call budget: N calls per Per (SPEC §9 item 5).

func ParseRate

func ParseRate(s string) (Rate, error)

ParseRate parses N/sec, N/min or N/hour with N > 0.

func (Rate) String

func (r Rate) String() string

type Result

type Result struct {
	Decision Decision
	Reason   string
}

Result is a decision and, unless it is Allow, why.

func Check

func Check(safety model.Safety, mode Mode, override Override) Result

Check decides a call to a tool with the given safety. Unknown modes and overrides fail closed.

Jump to

Keyboard shortcuts

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