hook

package
v0.67.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 16 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 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 typed `/f10:status [id]`, 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 [token]` prints for a session, and
	// whether the model must take the turn: a question to relay, or a token
	// that names no task.
	StatusText func(ctx context.Context, session, token string) (string, bool)

	// Profile is the agent profile f10 started the cwd's branch with; the
	// zero profile for a session f10 did not start.
	Profile func(ctx context.Context, cwd string) agentctl.Profile

	// 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
	Model        string          `json:"model"`  // SessionStart, when the source carries one
	Transcript   string          `json:"transcript_path"`
}

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