policy

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowCommand

func AllowCommand(profile Profile, risk CommandRisk, interactive bool) error

AllowCommand decides whether a slash command can run under current policy profile.

Types

type AuditEntry

type AuditEntry struct {
	Time    time.Time
	Profile Profile
	Tool    string
	Args    map[string]any
	Allow   bool
	Reason  string // empty when allowed
}

AuditEntry is the data passed to an optional audit hook.

type CommandRisk

type CommandRisk string

CommandRisk describes slash-command risk level.

const (
	RiskLow    CommandRisk = "low"
	RiskMedium CommandRisk = "medium"
	RiskHigh   CommandRisk = "high"
)

type Config

type Config struct {
	Profile         Profile
	Workspace       string
	Interactive     bool
	OnAudit         func(AuditEntry) // nil = no auditing
	AllowedCommands []string         // pre-loaded from project config
}

Config configures the policy engine.

type ConfirmFunc added in v0.0.2

type ConfirmFunc func(ctx context.Context, req PermitRequest) (PermitDecision, error)

ConfirmFunc blocks until the user makes a permission decision.

type Engine

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

Engine validates tool calls before execution.

func New

func New(cfg Config) *Engine

New creates a policy engine.

func (*Engine) Permission

func (e *Engine) Permission(ctx context.Context, call agentcore.ToolCall) error

Permission validates one tool call.

func (*Engine) SetConfirmFn added in v0.0.2

func (e *Engine) SetConfirmFn(fn ConfirmFunc)

SetConfirmFn sets the interactive confirmation callback. Called by the TUI layer after the tea.Program is created.

func (*Engine) SetPersistFn added in v0.0.2

func (e *Engine) SetPersistFn(fn func(cmd string) error)

SetPersistFn sets the callback to persist "always allow" commands to project config.

type PermitDecision added in v0.0.2

type PermitDecision int

PermitDecision is the user's response to an interactive permission prompt.

const (
	PermitDeny         PermitDecision = iota
	PermitAllowOnce                   // allow this invocation only
	PermitAllowSession                // allow for the rest of the session
	PermitAllowAlways                 // persist to project config
)

type PermitRequest added in v0.0.2

type PermitRequest struct {
	Tool    string // e.g. "bash"
	Command string // full command text
	Reason  string // e.g. "dangerous command: sudo"
}

PermitRequest describes the operation awaiting user approval.

type Profile

type Profile string

Profile controls how strict the permission policy is.

const (
	ProfileOff      Profile = "off"
	ProfileBalanced Profile = "balanced"
	ProfileStrict   Profile = "strict"
)

Jump to

Keyboard shortcuts

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