Help us shape the future of Go! Take the 2026 Go Developer Survey

hooks

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecutePost

func ExecutePost(ctx context.Context, hooks []ToolHook, input ToolHookInput) []types.Message

Types

type PreExecutionResult

type PreExecutionResult struct {
	Stop          *ToolHookStop
	UpdatedInput  map[string]any
	Metadata      map[string]any
	ExtraMessages []types.Message
}

func ExecutePre

func ExecutePre(ctx context.Context, hooks []ToolHook, input ToolHookInput) PreExecutionResult

type Registry

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

Registry stores tool hooks and exposes stable pre/post stage views.

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Add

func (r *Registry) Add(hook ToolHook)

func (*Registry) ByStage

func (r *Registry) ByStage(stage ToolHookStage) []ToolHook

func (*Registry) Post

func (r *Registry) Post() []ToolHook

func (*Registry) Pre

func (r *Registry) Pre() []ToolHook

func (*Registry) Remove

func (r *Registry) Remove(id string) int

Remove drops every hook whose ID matches, so a caller can replace a previously-registered hook (e.g. re-resolving an updated configuration) without accumulating duplicate registrations across reloads. Returns the number of hooks removed.

type ToolHook

type ToolHook struct {
	Stage    ToolHookStage
	Priority int
	ID       string
	Execute  func(ctx context.Context, input ToolHookInput) ToolHookResult
}

ToolHook is a single pre- or post-tool-use hook.

type ToolHookInput

type ToolHookInput struct {
	ToolName  string
	ToolUseID string
	Input     map[string]any
	ToolCtx   tool.ToolUseContext
}

ToolHookInput is the data passed to a hook.

type ToolHookResult

type ToolHookResult struct {
	Stop *ToolHookStop

	UpdatedInput map[string]any

	Metadata map[string]any

	ExtraMessages []types.Message
}

ToolHookResult is the outcome of a single hook invocation.

type ToolHookStage

type ToolHookStage string

ToolHookStage identifies when a hook fires.

const (
	ToolHookStagePre  ToolHookStage = "pre"
	ToolHookStagePost ToolHookStage = "post"
)

type ToolHookStop

type ToolHookStop struct {
	Content string
	IsError bool
}

ToolHookStop carries the information emitted when a hook stops execution.

Jump to

Keyboard shortcuts

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