actionhook

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: AGPL-3.0 Imports: 10 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 actionhook defines Pilot's versioned before/after side-effect boundary. It is deliberately optional: a nil Hook means the application executes exactly as it did before governance was attached.

Index

Constants

View Source
const (
	MaxAttributes     = 32
	MaxAttributeValue = 256
)
View Source
const SchemaVersion uint16 = 1

Variables

This section is empty.

Functions

func HashMetadata

func HashMetadata(values map[string]string) string

HashMetadata creates the payload binding for actions whose policy context is entirely metadata. Length-prefixing and sorting prevent ambiguous joins.

Types

type BlockedError

type BlockedError struct {
	Outcome   decision.Outcome
	Reference DecisionReference
	Reasons   []string
}

BlockedError is returned by RequireUnconstrained when a valid preflight does not authorize the adapter to execute immediately.

func (*BlockedError) Error

func (err *BlockedError) Error() string

type DecisionReference

type DecisionReference struct {
	IntentID            string `json:"intent_id,omitempty"`
	DecisionID          string `json:"decision_id,omitempty"`
	ExchangeID          string `json:"exchange_id,omitempty"`
	PolicyRevision      uint64 `json:"policy_revision,omitempty"`
	ProviderID          string `json:"provider_id,omitempty"`
	ApprovalTransaction string `json:"approval_transaction_id,omitempty"`
	ApprovalExpiresAt   int64  `json:"approval_expires_at,omitempty"`
}

DecisionReference is safe to persist in an action trace. It contains no provider request body and no opaque adapter resume state.

type Envelope

type Envelope struct {
	Version     uint16            `json:"version"`
	ID          string            `json:"id"`
	Action      string            `json:"action"`
	Resource    string            `json:"resource"`
	PayloadHash string            `json:"payload_hash"`
	AdapterID   string            `json:"adapter_id"`
	CreatedAt   int64             `json:"created_at"`
	Attributes  map[string]string `json:"attributes,omitempty"`
	// FederatedContent is the complete request body submitted to Pilot's
	// hosted account ingress in managed mode. It is process-local hook input:
	// envelope JSON, traces, continuations, and receipts never serialize it.
	FederatedContent *decision.FederatedContent `json:"-"`
	// ResumeToken is adapter-local state used to find a durable continuation.
	// It is deliberately excluded from JSON and never sent to an evaluator.
	ResumeToken string `json:"-"`
}

Envelope is evaluated before an adapter performs a side effect. Ordinary local/observe hooks use only PayloadHash. A managed hosted-federation hook may additionally carry FederatedContent to Pilot's account ingress. Attributes remain typed call metadata rather than an alternative channel for content, secrets, local paths, or peer network addresses.

func NewEnvelope

func NewEnvelope(action, resource, payloadHash, adapterID string, attributes map[string]string, now time.Time) (Envelope, error)

func NewFederatedEnvelope

func NewFederatedEnvelope(action, resource, adapterID string, content decision.FederatedContent, attributes map[string]string, now time.Time) (Envelope, error)

func (Envelope) Validate

func (envelope Envelope) Validate() error

type Hook

type Hook interface {
	BeforeAction(context.Context, Envelope) (Preflight, error)
	AfterAction(context.Context, Envelope, Preflight, ObservedResult) error
}

Hook is the universal optional side-effect boundary. AfterAction is evidence-only: its failure must be surfaced to telemetry, but it cannot retroactively change or repeat the adapter side effect.

type ObservedResult

type ObservedResult struct {
	Status     ObservedStatus    `json:"status"`
	ObservedAt int64             `json:"observed_at"`
	ErrorCode  string            `json:"error_code,omitempty"`
	Attributes map[string]string `json:"attributes,omitempty"`
	// FederatedContent is an optional complete response or returned artifact
	// for the Pilot-hosted post-hook. Like request content, it is process-local
	// and is never serialized into traces or local receipts.
	FederatedContent *decision.FederatedContent `json:"-"`
}

ObservedResult records what actually happened after preflight. ErrorCode is a bounded category, never an arbitrary error string that could leak data.

func (ObservedResult) Validate

func (result ObservedResult) Validate() error

type ObservedStatus

type ObservedStatus string
const (
	StatusSucceeded       ObservedStatus = "succeeded"
	StatusFailed          ObservedStatus = "failed"
	StatusSkipped         ObservedStatus = "skipped"
	StatusDenied          ObservedStatus = "denied"
	StatusApprovalPending ObservedStatus = "approval_pending"
)

type Preflight

type Preflight struct {
	Outcome     decision.Outcome      `json:"outcome"`
	Reasons     []string              `json:"reasons,omitempty"`
	Constraints []decision.Constraint `json:"constraints,omitempty"`
	Reference   DecisionReference     `json:"reference,omitempty"`
	ObserveOnly bool                  `json:"observe_only,omitempty"`
	State       any                   `json:"-"`
}

Preflight is the hook's answer. State is process-local opaque state used by the same Hook during AfterAction; it is never serialized or accepted from a caller. ObserveOnly makes the result evidentiary and never blocking.

func (Preflight) RequireUnconstrained

func (preflight Preflight) RequireUnconstrained() error

RequireUnconstrained is the safe execution check for adapters that do not implement constraint operators. Observe-only hooks never block execution.

Jump to

Keyboard shortcuts

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