hooks

package
v1.1.68 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package hooks implements shell hook scripts for serve channels. Hooks are external scripts called before/after tool execution, communicating via JSON on stdin/stdout.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager manages pre/post tool call hooks.

func NewManager

func NewManager(preToolCall, postToolCall string) *Manager

NewManager creates a hooks manager.

func (*Manager) HasPostHook

func (m *Manager) HasPostHook() bool

HasPostHook returns true if a post_tool_call hook is configured.

func (*Manager) HasPreHook

func (m *Manager) HasPreHook() bool

HasPreHook returns true if a pre_tool_call hook is configured.

func (*Manager) PostToolCall

func (m *Manager) PostToolCall(ctx context.Context, tool string, args map[string]any, result, errMsg, platform, userID string)

PostToolCall runs the post_tool_call hook (fire-and-forget).

func (*Manager) PreToolCall

func (m *Manager) PreToolCall(ctx context.Context, tool string, args map[string]any, platform, userID string) (bool, string, error)

PreToolCall runs the pre_tool_call hook. Returns (allow, reason, error). If no hook is configured, returns (true, "", nil).

type PostToolCallRequest

type PostToolCallRequest struct {
	Hook     string         `json:"hook"`
	Tool     string         `json:"tool"`
	Args     map[string]any `json:"args"`
	Result   string         `json:"result"`
	Error    string         `json:"error,omitempty"`
	Platform string         `json:"platform"`
	UserID   string         `json:"user_id"`
}

PostToolCallRequest is sent to the post_tool_call script via stdin.

type PreToolCallRequest

type PreToolCallRequest struct {
	Hook     string         `json:"hook"`
	Tool     string         `json:"tool"`
	Args     map[string]any `json:"args"`
	Platform string         `json:"platform"`
	UserID   string         `json:"user_id"`
}

PreToolCallRequest is sent to the pre_tool_call script via stdin.

type PreToolCallResponse

type PreToolCallResponse struct {
	Action string `json:"action"` // "allow" or "block"
	Reason string `json:"reason,omitempty"`
}

PreToolCallResponse is read from the pre_tool_call script via stdout.

Jump to

Keyboard shortcuts

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