Documentation
¶
Index ¶
- type EventType
- type Payload
- type Result
- type Runner
- func (r *Runner) Middleware() agentcore.ToolMiddleware
- func (r *Runner) RunNotification(_ context.Context, message string)
- func (r *Runner) RunPostCompact(ctx context.Context, reason string, tokensBefore, tokensAfter int)
- func (r *Runner) RunPostStopValidation(ctx context.Context) (failOutput string)
- func (r *Runner) RunPostToolUse(_ context.Context, toolName string, args, output json.RawMessage, isError bool)
- func (r *Runner) RunPreCompact(ctx context.Context, reason string, tokensBefore int)
- func (r *Runner) RunPreToolUse(ctx context.Context, toolName string, args json.RawMessage) error
- func (r *Runner) RunSessionEnd(ctx context.Context)
- func (r *Runner) RunSessionStart(ctx context.Context)
- func (r *Runner) RunTaskCompleted(ctx context.Context, previous, current TaskSnapshot) error
- func (r *Runner) RunTaskCreated(ctx context.Context, task TaskSnapshot) error
- func (r *Runner) RunUserPromptSubmit(ctx context.Context, prompt string) error
- type TaskSnapshot
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventType ¶
type EventType string
EventType identifies when a hook fires.
const ( PreToolUse EventType = "PreToolUse" PostToolUse EventType = "PostToolUse" Notification EventType = "Notification" PostStopValidation EventType = "PostStopValidation" TaskCreated EventType = "TaskCreated" TaskCompleted EventType = "TaskCompleted" SessionStart EventType = "SessionStart" SessionEnd EventType = "SessionEnd" PreCompact EventType = "PreCompact" PostCompact EventType = "PostCompact" UserPromptSubmit EventType = "UserPromptSubmit" )
type Payload ¶
type Payload struct {
Event EventType `json:"event"`
Tool string `json:"tool,omitempty"`
Args json.RawMessage `json:"args,omitempty"`
Output json.RawMessage `json:"output,omitempty"`
IsError bool `json:"is_error,omitempty"`
Message string `json:"message,omitempty"`
Task *TaskSnapshot `json:"task,omitempty"`
PreviousTask *TaskSnapshot `json:"previous_task,omitempty"`
StatusFrom string `json:"status_from,omitempty"`
StatusTo string `json:"status_to,omitempty"`
Prompt string `json:"prompt,omitempty"` // UserPromptSubmit
Reason string `json:"reason,omitempty"` // Pre/PostCompact
TokensBefore int `json:"tokens_before,omitempty"` // Pre/PostCompact
TokensAfter int `json:"tokens_after,omitempty"` // PostCompact
}
Payload is the JSON written to the hook command's stdin.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner manages and executes hooks.
func New ¶
func New(cfg config.HooksConfig, sessionID string, engine *approval.Engine, model agentcore.ChatModel) *Runner
New parses a HooksConfig and returns a Runner. Returns nil if no valid hooks are found. The model parameter is used for prompt-type hooks and may be nil.
func (*Runner) Middleware ¶
func (r *Runner) Middleware() agentcore.ToolMiddleware
Middleware returns a ToolMiddleware that runs PreToolUse and PostToolUse hooks around each tool execution.
func (*Runner) RunNotification ¶
RunNotification fires matching Notification hooks asynchronously. Uses a detached context so hooks survive parent cancellation.
func (*Runner) RunPostCompact ¶ added in v0.1.0
RunPostCompact fires PostCompact hooks asynchronously.
func (*Runner) RunPostStopValidation ¶ added in v0.1.0
RunPostStopValidation executes matching PostStopValidation hooks synchronously. Returns the combined stderr/error output of the first failing hook, or "" on success.
func (*Runner) RunPostToolUse ¶
func (r *Runner) RunPostToolUse(_ context.Context, toolName string, args, output json.RawMessage, isError bool)
RunPostToolUse fires matching PostToolUse hooks asynchronously. Uses a detached context so hooks survive parent cancellation.
func (*Runner) RunPreCompact ¶ added in v0.1.0
RunPreCompact fires PreCompact hooks asynchronously.
func (*Runner) RunPreToolUse ¶
RunPreToolUse executes all matching PreToolUse hooks. A blocking hook that exits non-zero or returns {"blocked":true} returns an error.
func (*Runner) RunSessionEnd ¶ added in v0.1.0
RunSessionEnd fires SessionEnd hooks asynchronously.
func (*Runner) RunSessionStart ¶ added in v0.1.0
RunSessionStart fires SessionStart hooks asynchronously.
func (*Runner) RunTaskCompleted ¶ added in v0.1.0
func (r *Runner) RunTaskCompleted(ctx context.Context, previous, current TaskSnapshot) error
RunTaskCompleted executes TaskCompleted hooks synchronously. Any hook error aborts the completion transition.
func (*Runner) RunTaskCreated ¶ added in v0.1.0
func (r *Runner) RunTaskCreated(ctx context.Context, task TaskSnapshot) error
RunTaskCreated executes TaskCreated hooks synchronously. Any hook error aborts the task creation so callers can roll back.
type TaskSnapshot ¶ added in v0.1.0
type TaskSnapshot struct {
ID string `json:"id"`
Subject string `json:"subject"`
Description string `json:"description,omitempty"`
ActiveForm string `json:"active_form,omitempty"`
Status string `json:"status"`
Owner string `json:"owner,omitempty"`
Blocks []string `json:"blocks,omitempty"`
BlockedBy []string `json:"blocked_by,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
TaskSnapshot is the task payload exposed to lifecycle hooks.