hooks

package
v0.0.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventType

type EventType string

EventType identifies when a hook fires.

const (
	PreToolUse   EventType = "PreToolUse"
	PostToolUse  EventType = "PostToolUse"
	Notification EventType = "Notification"
)

type Payload

type Payload struct {
	Event   EventType       `json:"event"`
	Tool    string          `json:"tool,omitempty"`
	Args    json.RawMessage `json:"args,omitempty"`
	Output  json.RawMessage `json:"output,omitempty"`
	IsError bool            `json:"is_error,omitempty"`
	Message string          `json:"message,omitempty"`
}

Payload is the JSON written to the hook command's stdin.

type Result

type Result struct {
	Blocked bool   `json:"blocked"`
	Reason  string `json:"reason,omitempty"`
}

Result is the expected JSON structure from a blocking hook's stdout.

type Runner

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

Runner manages and executes hooks.

func New

func New(cfg config.HooksConfig, sessionID string, engine *approval.Engine) *Runner

New parses a HooksConfig and returns a Runner. Returns nil if no valid hooks are found.

func (*Runner) Middleware

func (r *Runner) Middleware() agentcore.ToolMiddleware

Middleware returns a ToolMiddleware that runs PreToolUse and PostToolUse hooks around each tool execution.

func (*Runner) RunNotification

func (r *Runner) RunNotification(_ context.Context, message string)

RunNotification fires matching Notification hooks asynchronously. Uses a detached context so hooks survive parent cancellation.

func (*Runner) RunPostToolUse

func (r *Runner) RunPostToolUse(_ context.Context, toolName string, args, output json.RawMessage, isError bool)

RunPostToolUse fires matching PostToolUse hooks asynchronously. Uses a detached context so hooks survive parent cancellation.

func (*Runner) RunPreToolUse

func (r *Runner) RunPreToolUse(ctx context.Context, toolName string, args json.RawMessage) error

RunPreToolUse executes all matching PreToolUse hooks. A blocking hook that exits non-zero or returns {"blocked":true} returns an error.

Jump to

Keyboard shortcuts

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