Documentation
¶
Index ¶
- func Execute(ctx context.Context, event EventType, data map[string]interface{}) error
- func ExecuteAsync(ctx context.Context, event EventType, data map[string]interface{})
- func LoadHooksDir(dir string) error
- func Register(h Hook)
- func RegisterDecisionHook(fn DecisionHookFn)
- func ResetDecisionHooks()
- type DecisionHookFn
- type EventType
- type Hook
- type HookDecision
- type Registry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecuteAsync ¶
ExecuteAsync runs hooks asynchronously on the global registry.
func RegisterDecisionHook ¶
func RegisterDecisionHook(fn DecisionHookFn)
RegisterDecisionHook adds a decision hook to the global list.
func ResetDecisionHooks ¶
func ResetDecisionHooks()
ResetDecisionHooks clears all registered decision hooks. Intended for testing.
Types ¶
type DecisionHookFn ¶
type DecisionHookFn func(event string, data map[string]interface{}) *HookDecision
DecisionHookFn is a function that inspects an event and optionally returns a decision. Returning nil means "no opinion" (proceed normally).
type EventType ¶
type EventType string
EventType represents a hook event.
const ( EventPreQuery EventType = "pre_query" EventPostQuery EventType = "post_query" EventPreTool EventType = "pre_tool" EventPostTool EventType = "post_tool" EventPreCompact EventType = "pre_compact" EventPostCompact EventType = "post_compact" EventFileChanged EventType = "file_changed" EventSessionStart EventType = "session_start" EventSessionEnd EventType = "session_end" EventPermissionAsk EventType = "permission_ask" EventError EventType = "error" )
type Hook ¶
type Hook struct {
Name string
Event EventType
Priority int // lower = earlier
Fn func(ctx context.Context, data map[string]interface{}) error
}
Hook is a registered hook function.
func BuiltinHooks ¶
func BuiltinHooks() []Hook
BuiltinHooks returns the default set of built-in hooks.
type HookDecision ¶
type HookDecision struct {
Action string `json:"action"` // "allow", "deny", "modify"
Reason string `json:"reason,omitempty"`
ModifiedInput json.RawMessage `json:"modified_input,omitempty"`
}
HookDecision represents the outcome of a decision hook.
func ExecuteDecisionHooks ¶
func ExecuteDecisionHooks(event string, data map[string]interface{}) *HookDecision
ExecuteDecisionHooks runs all registered decision hooks for the given event. It returns the first non-nil decision. If all hooks return nil, the result is nil (meaning no opinion, proceed normally).