hook

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package hook defines nil-safe lifecycle callbacks for observability. Hooks only observe; they cannot veto execution (authorization is a separate rbac concern). The core never imports a logging library; x/otel implements these callbacks to emit spans and metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hooks

type Hooks struct {
	BeforeTool  func(ctx context.Context, name string, input json.RawMessage) context.Context
	AfterTool   func(ctx context.Context, name string, err error)
	OnError     func(ctx context.Context, err error)
	OnCostGate  func(ctx context.Context, plan cost.Plan, score cost.Score, decision string)
	OnAuthorize func(ctx context.Context, req rbac.Request, dec rbac.Decision)
}

Hooks holds optional lifecycle callbacks. Every Fire* method is nil-safe: a nil Hooks or nil field is a no-op.

func Join added in v0.1.6

func Join(hooks ...*Hooks) *Hooks

Join composes hooks so independent consumers (tracing, metrics, ...) can observe the same lifecycle. Callbacks run in argument order; BeforeTool threads the context through the chain. Nil entries are skipped.

func (*Hooks) FireAfterTool

func (h *Hooks) FireAfterTool(ctx context.Context, name string, err error)

FireAfterTool runs AfterTool if set.

func (*Hooks) FireAuthorize

func (h *Hooks) FireAuthorize(ctx context.Context, req rbac.Request, dec rbac.Decision)

FireAuthorize runs OnAuthorize if set.

func (*Hooks) FireBeforeTool

func (h *Hooks) FireBeforeTool(ctx context.Context, name string, input json.RawMessage) context.Context

FireBeforeTool runs BeforeTool or returns ctx unchanged.

func (*Hooks) FireCostGate

func (h *Hooks) FireCostGate(ctx context.Context, plan cost.Plan, score cost.Score, decision string)

FireCostGate runs OnCostGate if set. decision is "allow", "soft", or "hard".

func (*Hooks) FireOnError

func (h *Hooks) FireOnError(ctx context.Context, err error)

FireOnError runs OnError if set.

Jump to

Keyboard shortcuts

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