hookd

package
v0.23.3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hookd receives Claude Code hook payloads from the caprock-hook shim on POST /v1/hook, normalizes them into events, and hands them to the recorder. Unknown events and fields are logged and ignored, never fatal.

Index

Constants

View Source
const MaxBody = 4 << 20

MaxBody bounds a hook payload. tool_response can be large; 4 MiB is generous.

Variables

View Source
var ErrNoSession = errors.New("hook payload without session_id")

ErrNoSession marks payloads without a session_id — nothing to attach them to.

View Source
var ErrUnknownEvent = errors.New("unknown hook event")

ErrUnknownEvent marks hook_event_name values hookd does not consume.

Functions

func Normalize

func Normalize(raw []byte, now time.Time) (*event.Event, rollup.SessionInfo, error)

Normalize converts a raw hook payload into an Event plus what it reveals about the session. The event's Payload is the raw body verbatim.

Types

type Handler

type Handler struct {
	Token    string
	Recorder Recorder
	Log      *slog.Logger
	Now      func() time.Time
	// OnAccepted is called after a successful record (loop detector hook-in).
	OnAccepted func(res rollup.Result)
	// Decide answers Stop events (Phase 2). nil ⇒ empty 204 reply.
	Decide func(ctx context.Context, p Payload) []byte
}

Handler serves POST /v1/hook.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the contract: bearer-token gated, 204 on success, 401 on bad token, 400 on unparsable body, 200 with a JSON body only for Stop decisions (Phase 2). Unknown events return 204 (ignored, logged).

type Payload

type Payload struct {
	SessionID      string          `json:"session_id"`
	PromptID       string          `json:"prompt_id"`
	TranscriptPath string          `json:"transcript_path"`
	Cwd            string          `json:"cwd"`
	HookEventName  string          `json:"hook_event_name"`
	PermissionMode string          `json:"permission_mode"`
	AgentID        string          `json:"agent_id"`
	AgentType      string          `json:"agent_type"`
	ToolName       string          `json:"tool_name"`
	ToolInput      json.RawMessage `json:"tool_input"`
	ToolUseID      string          `json:"tool_use_id"`
	Prompt         string          `json:"prompt"`
	StopReason     string          `json:"stop_reason"`
	Source         string          `json:"source"`  // SessionStart
	Model          string          `json:"model"`   // SessionStart (optional)
	Trigger        string          `json:"trigger"` // PreCompact
	Error          string          `json:"error"`   // StopFailure / PostToolUseFailure
}

Payload is the subset of hook JSON that hookd reads. The raw body is stored untouched as the event payload, so nothing here limits what the UI can show.

type Recorder

type Recorder interface {
	Record(ctx context.Context, ev *event.Event, info rollup.SessionInfo) (rollup.Result, error)
}

Recorder is what hookd needs from rollup (interface for tests).

Jump to

Keyboard shortcuts

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