Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateHookConfig ¶
func ValidateHookConfig(config *HookConfig) error
ValidateHookConfig validates the entire hook configuration
Types ¶
type CommonInput ¶
type CommonInput struct {
SessionID string `json:"session_id"` // Unique session identifier
TranscriptPath string `json:"transcript_path"` // Path to transcript file (if enabled)
CWD string `json:"cwd"` // Current working directory
HookEventName HookEvent `json:"hook_event_name"` // The hook event type
Timestamp int64 `json:"timestamp"` // Unix timestamp when hook fired
Model string `json:"model"` // AI model being used
Interactive bool `json:"interactive"` // Whether in interactive mode
}
CommonInput contains fields common to all hook inputs
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor handles hook execution
func NewExecutor ¶
func NewExecutor(config *HookConfig, sessionID, transcriptPath string) *Executor
NewExecutor creates a new hook executor
func (*Executor) ExecuteHooks ¶
func (e *Executor) ExecuteHooks(ctx context.Context, event HookEvent, input interface{}) (*HookOutput, error)
ExecuteHooks runs all matching hooks for an event
func (*Executor) PopulateCommonFields ¶
func (e *Executor) PopulateCommonFields(event HookEvent) CommonInput
PopulateCommonFields fills in the common fields for any hook input
func (*Executor) SetInteractive ¶
SetInteractive sets whether we're in interactive mode
type HookConfig ¶
type HookConfig struct {
Hooks map[HookEvent][]HookMatcher `yaml:"hooks" json:"hooks"`
}
HookConfig represents the complete hooks configuration
func LoadHooksConfig ¶
func LoadHooksConfig(customPaths ...string) (*HookConfig, error)
LoadHooksConfig loads and merges hook configurations from multiple sources
type HookEntry ¶
type HookEntry struct {
Type string `yaml:"type" json:"type"`
Command string `yaml:"command" json:"command"`
Timeout int `yaml:"timeout,omitempty" json:"timeout,omitempty"`
}
HookEntry defines a single hook command
type HookEvent ¶
type HookEvent string
HookEvent represents a point in MCPHost's lifecycle where hooks can be executed
const ( // PreToolUse fires before any tool execution PreToolUse HookEvent = "PreToolUse" // PostToolUse fires after tool execution completes PostToolUse HookEvent = "PostToolUse" // UserPromptSubmit fires when user submits a prompt UserPromptSubmit HookEvent = "UserPromptSubmit" // Stop fires when the main agent finishes responding Stop HookEvent = "Stop" )
func (HookEvent) RequiresMatcher ¶
RequiresMatcher returns true if the event uses tool matchers
type HookMatcher ¶
type HookMatcher struct {
Matcher string `yaml:"matcher,omitempty" json:"matcher,omitempty"`
Merge string `yaml:"_merge,omitempty" json:"_merge,omitempty"`
Hooks []HookEntry `yaml:"hooks" json:"hooks"`
}
HookMatcher matches specific tools and defines hooks to execute
type HookOutput ¶
type HookOutput struct {
Continue *bool `json:"continue,omitempty"`
StopReason string `json:"stopReason,omitempty"`
SuppressOutput bool `json:"suppressOutput,omitempty"`
Decision string `json:"decision,omitempty"` // "approve", "block", or ""
Reason string `json:"reason,omitempty"`
}
HookOutput represents the JSON output from a hook
type PostToolUseInput ¶
type PostToolUseInput struct {
CommonInput
ToolName string `json:"tool_name"`
ToolInput json.RawMessage `json:"tool_input"`
ToolResponse json.RawMessage `json:"tool_response"`
}
PostToolUseInput is passed to PostToolUse hooks
type PreToolUseInput ¶
type PreToolUseInput struct {
CommonInput
ToolName string `json:"tool_name"`
ToolInput json.RawMessage `json:"tool_input"`
}
PreToolUseInput is passed to PreToolUse hooks
type StopInput ¶
type StopInput struct {
CommonInput
StopHookActive bool `json:"stop_hook_active"`
Response string `json:"response"` // The agent's final response
StopReason string `json:"stop_reason"` // "completed", "cancelled", "error"
Meta json.RawMessage `json:"meta,omitempty"` // Additional metadata (e.g., token usage, model info)
}
StopInput is passed to Stop hooks
type UserPromptSubmitInput ¶
type UserPromptSubmitInput struct {
CommonInput
Prompt string `json:"prompt"`
}
UserPromptSubmitInput is passed to UserPromptSubmit hooks