hook

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package hook is f10's one entry point for Claude Code hook events: they seed the run's badge, become typed observations and record the run's waits on the user. Nothing here fails a run: a payload, state file or observer that errors is dropped and the hook exits 0.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dispatch

func Dispatch(ctx context.Context, raw []byte, env *Env) []byte

Dispatch handles one hook event and returns what the hook prints on stdout: a verdict for a bare `/f10:status`, nothing otherwise.

Types

type Env

type Env struct {
	StateDir   string
	Home       string
	PluginRoot string // where bin/f10-state.sh, the status-line renderer, lives
	Debug      bool   // F10_STATE_DEBUG: append every payload to hooks.log
	Now        func() time.Time

	// StorageRoot is the checkout's storage root for a cwd, in-repo or
	// out-of-tree; empty when it cannot tell.
	StorageRoot func(ctx context.Context, cwd string) string
	// TaskID is the tracker task id a created issue's url names, in the
	// project's id format; empty when it cannot tell.
	TaskID func(ctx context.Context, cwd, url string) string
	// PromptTyped is told of every prompt submitted, with the session's
	// cwd: one typed in an asking agent's pane answers its ask.
	PromptTyped func(ctx context.Context, cwd, prompt string)
	// StatusText is what `f10 status` prints for a session, and whether it
	// holds a question to relay, which needs a model turn.
	StatusText func(ctx context.Context, session string) (string, bool)

	// Observers receive every observation after the badge has applied it.
	Observers []observe.Observer
}

Env is everything a hook reaches outside its payload, so a test can point it at a temp directory and stub what needs a real project.

type Payload

type Payload struct {
	Event        string          `json:"hook_event_name"`
	Session      string          `json:"session_id"`
	Cwd          string          `json:"cwd"`
	Source       string          `json:"source"`       // SessionStart: startup, resume, clear, compact
	CommandName  string          `json:"command_name"` // UserPromptExpansion
	CommandArgs  string          `json:"command_args"`
	ToolName     string          `json:"tool_name"` // PreToolUse, PostToolUse, PostToolUseFailure, PermissionRequest
	ToolUseID    string          `json:"tool_use_id"`
	ToolInput    json.RawMessage `json:"tool_input"`
	ToolResponse json.RawMessage `json:"tool_response"`
	Prompt       string          `json:"prompt"` // UserPromptSubmit
}

Payload is the part of a hook event's JSON the arms read, decoded once.

Jump to

Keyboard shortcuts

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