hooks

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

internal/hooks/hooks.go 钩子系统:preToolUse / postToolUse 事件

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventType

type EventType string

EventType 钩子事件类型

const (
	EventPreToolUse  EventType = "preToolUse"
	EventPostToolUse EventType = "postToolUse"
)

type HookDef

type HookDef struct {
	Match   string `json:"match"`   // 匹配的工具名(空表示匹配所有)
	Command string `json:"command"` // 要执行的 shell 命令
}

HookDef 单个钩子定义

type HooksConfig

type HooksConfig struct {
	PreToolUse  []HookDef `json:"preToolUse,omitempty"`
	PostToolUse []HookDef `json:"postToolUse,omitempty"`
}

HooksConfig 钩子配置(从 settings.json 读取)

func LoadConfig

func LoadConfig(settingsPath string) HooksConfig

LoadConfig 从 settings.json 加载钩子配置

type Manager

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

Manager 钩子管理器

func NewManager

func NewManager(config HooksConfig) *Manager

NewManager 创建钩子管理器

func (*Manager) HasHooks

func (m *Manager) HasHooks() bool

HasHooks 检查是否配置了任何钩子

func (*Manager) ListString

func (m *Manager) ListString() string

ListString 返回钩子列表的格式化字符串

func (*Manager) RunPostToolUse

func (m *Manager) RunPostToolUse(ctx context.Context, toolName, toolOutput string, isError bool)

RunPostToolUse 执行 postToolUse 钩子

func (*Manager) RunPreToolUse

func (m *Manager) RunPreToolUse(ctx context.Context, toolName, toolInput string) (bool, error)

RunPreToolUse 执行 preToolUse 钩子 返回 false 表示应阻止工具执行

Jump to

Keyboard shortcuts

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