hooks

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractFilePath

func ExtractFilePath(toolName string, rawInput string) string

ExtractFilePath attempts to extract a file path from common tool argument patterns.

Types

type Hook

type Hook struct {
	Match        string `yaml:"match"`         // glob pattern to match tool names
	Command      string `yaml:"command"`       // shell command to run
	InjectOutput bool   `yaml:"inject_output"` // for post hooks: inject stdout into tool result
}

Hook represents a single pre or post tool-use hook.

type HookConfig

type HookConfig struct {
	PreToolUse  []Hook `yaml:"pre_tool_use"`
	PostToolUse []Hook `yaml:"post_tool_use"`
}

HookConfig holds all hooks from configuration.

type HookEnv

type HookEnv struct {
	ToolName   string
	FilePath   string // extracted from tool arguments when applicable
	WorkingDir string
	RawInput   string // raw JSON tool arguments
}

HookEnv holds environment variables available to hook commands.

type HookResult

type HookResult struct {
	Allowed bool   // false means block the tool execution (pre-hook only)
	Output  string // captured stdout (for inject_output)
	Err     error
}

HookResult is the result of running a hook.

func RunPostHooks

func RunPostHooks(hooks []Hook, env HookEnv) HookResult

RunPostHooks runs all matching post-tool-use hooks. Collects output from hooks with inject_output=true.

func RunPreHooks

func RunPreHooks(hooks []Hook, env HookEnv) HookResult

RunPreHooks runs all matching pre-tool-use hooks. Returns HookResult with Allowed=false if any hook blocks execution.

Jump to

Keyboard shortcuts

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