hooks

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteHookCommand

func ExecuteHookCommand(workingDir string, hookCmd config.HookCommand) error

ExecuteHookCommand executes a single hook command (moved from api package)

func ExecuteRepoHookCommands

func ExecuteRepoHookCommands(hc *HookContext, workingDir string) error

ExecuteRepoHookCommands executes on_stop commands from grove.yml

func HandleExitPlanMode

func HandleExitPlanMode(ctx *HookContext, data PostToolUseInput) error

HandleExitPlanMode processes ExitPlanMode tool events and saves plans to grove-flow

func HandlePlanEdit

func HandlePlanEdit(ctx *HookContext, data PostToolUseInput) error

HandlePlanEdit processes Edit tool events on Claude plan files and syncs to grove-flow This captures incremental edits to plans, not just the final ExitPlanMode event

func RunNotificationHook

func RunNotificationHook()

func RunPostToolUseHook

func RunPostToolUseHook()

func RunPreToolUseHook

func RunPreToolUseHook()

func RunStopHook

func RunStopHook()

func RunSubagentStopHook

func RunSubagentStopHook()

Types

type BaseHookInput

type BaseHookInput struct {
	SessionID      string `json:"session_id"`
	TranscriptPath string `json:"transcript_path,omitempty"`
	HookEventName  string `json:"hook_event_name"`
	// Current transcript position (if available)
	CurrentUUID string `json:"current_uuid,omitempty"`
	ParentUUID  string `json:"parent_uuid,omitempty"`
}

BaseHookInput contains fields common to all hooks

type HookBlockingError

type HookBlockingError struct {
	Message string
}

HookBlockingError represents an error that should block the session from stopping

func (*HookBlockingError) Error

func (e *HookBlockingError) Error() string

type HookContext

type HookContext struct {
	Input     BaseHookInput
	RawInput  []byte
	Storage   interfaces.SessionStorer
	StartTime time.Time
	Config    *NotificationsConfig
}

func NewHookContext

func NewHookContext() (*HookContext, error)

NewHookContext creates a new hook context with local storage

func (*HookContext) EnsureSessionExists

func (hc *HookContext) EnsureSessionExists(sessionID string, transcriptPath string) error

EnsureSessionExists creates a session if it doesn't exist

func (*HookContext) GetSession

func (hc *HookContext) GetSession(sessionID string) (*models.Session, error)

GetSession retrieves a session from local storage

func (*HookContext) LogEvent

func (hc *HookContext) LogEvent(eventType models.EventType, data map[string]any) error

LogEvent logs an event to local storage

type NotificationInput

type NotificationInput struct {
	SessionID              string `json:"session_id"`
	TranscriptPath         string `json:"transcript_path"`
	HookEventName          string `json:"hook_event_name"`
	Type                   string `json:"type"`
	Message                string `json:"message"`
	Level                  string `json:"level"` // info, warning, error
	SystemNotificationSent bool   `json:"system_notification_sent"`
	CurrentUUID            string `json:"current_uuid,omitempty"`
	ParentUUID             string `json:"parent_uuid,omitempty"`
}

type NotificationsConfig

type NotificationsConfig struct {
	Ntfy struct {
		Enabled bool
		URL     string
		Topic   string
	}
	System struct {
		Levels []string
	}
}

HookContext provides common functionality for all hooks NotificationsConfig is a placeholder for notification configuration

type PlanPreservationConfig

type PlanPreservationConfig struct {
	Enabled       bool   `yaml:"enabled" json:"enabled"`
	TargetPlanDir string `yaml:"target_plan_dir" json:"target_plan_dir"` // Optional: override auto-detection
	JobType       string `yaml:"job_type" json:"job_type"`               // Default: "file"
	TitlePrefix   string `yaml:"title_prefix" json:"title_prefix"`       // Optional prefix for title
	KebabCase     bool   `yaml:"kebab_case" json:"kebab_case"`           // Use kebab-case titles (default: true)
	AddDependsOn  string `yaml:"add_depends_on" json:"add_depends_on"`   // Optional: job to depend on
	NotifyOnSave  bool   `yaml:"notify_on_save" json:"notify_on_save"`   // Send notification when plan is saved
}

PlanPreservationConfig holds configuration for auto-saving plans

func DefaultPlanPreservationConfig

func DefaultPlanPreservationConfig() *PlanPreservationConfig

DefaultPlanPreservationConfig returns the default configuration

type PostToolUseInput

type PostToolUseInput struct {
	SessionID      string  `json:"session_id"`
	TranscriptPath string  `json:"transcript_path"`
	HookEventName  string  `json:"hook_event_name"`
	ToolName       string  `json:"tool_name"`
	ToolInput      any     `json:"tool_input"`
	ToolResponse   any     `json:"tool_response"`
	ToolOutput     any     `json:"tool_output"` // Legacy field
	ToolDurationMs int64   `json:"tool_duration_ms"`
	ToolError      *string `json:"tool_error"`
	ToolUseID      string  `json:"tool_use_id,omitempty"`
	CurrentUUID    string  `json:"current_uuid,omitempty"`
	ParentUUID     string  `json:"parent_uuid,omitempty"`
}

type PreToolUseInput

type PreToolUseInput struct {
	SessionID      string         `json:"session_id"`
	TranscriptPath string         `json:"transcript_path"`
	HookEventName  string         `json:"hook_event_name"`
	ToolName       string         `json:"tool_name"`
	ToolInput      map[string]any `json:"tool_input"`
	CurrentUUID    string         `json:"current_uuid,omitempty"`
	ParentUUID     string         `json:"parent_uuid,omitempty"`
}

type PreToolUseResponse

type PreToolUseResponse struct {
	Approved bool   `json:"approved"`
	Message  string `json:"message,omitempty"`
}

type StopInput

type StopInput struct {
	SessionID      string `json:"session_id"`
	TranscriptPath string `json:"transcript_path"`
	HookEventName  string `json:"hook_event_name"`
	ExitReason     string `json:"exit_reason"`
	DurationMs     int64  `json:"duration_ms"`
	CurrentUUID    string `json:"current_uuid,omitempty"`
	ParentUUID     string `json:"parent_uuid,omitempty"`
	Cwd            string `json:"cwd,omitempty"`
}

type SubagentStopInput

type SubagentStopInput struct {
	SessionID      string  `json:"session_id"`
	TranscriptPath string  `json:"transcript_path"`
	HookEventName  string  `json:"hook_event_name"`
	SubagentID     string  `json:"subagent_id"`
	SubagentTask   string  `json:"subagent_task"`
	DurationMs     int64   `json:"duration_ms"`
	Status         string  `json:"status"`
	Result         any     `json:"result"`
	Error          *string `json:"error"`
	CurrentUUID    string  `json:"current_uuid,omitempty"`
	ParentUUID     string  `json:"parent_uuid,omitempty"`
}

Jump to

Keyboard shortcuts

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