hook

package
v0.40.0 Latest Latest
Warning

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

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

Documentation

Overview

Package hook is f10's one entry point for Claude Code hook events: a skill starting seeds the run's badge, a Bash call or a file write becomes typed observations, Stop backs up the most-dropped badge call, and SessionStart keeps the status line wired and the state directory small.

Nothing here fails a run: a payload it cannot read, a state file it cannot write, an observer that errors - each 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
	// StatusText is what `f10 status` prints for a session.
	StatusText func(ctx context.Context, session string) string

	// 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
	ToolInput    json.RawMessage `json:"tool_input"`
	ToolResponse json.RawMessage `json:"tool_response"`
}

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