Help us shape the future of Go! Take the 2026 Go Developer Survey

hook

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package hook parses harness lifecycle-hook events (Claude Code / Codex) and maps them onto engine write operations. Parsing is tolerant: unknown fields are ignored so upstream schema drift never breaks the binary.

Index

Constants

View Source
const (
	PromptMaxRunes      = 2000
	ObservationMaxRunes = 500
)

Variables

This section is empty.

Functions

func MapToolActionClass

func MapToolActionClass(tool string) string

func WorkspaceFromCwd

func WorkspaceFromCwd(cwd string) string

WorkspaceFromCwd derives the memory workspace from the event's cwd by taking its base directory name (spec §2: cwd directory name).

Types

type Harness

type Harness = string

Harness names the event source; it lands in the OperationEvent Agent field. stdin JSON is identical across harnesses, so the caller passes it explicitly (CLI --harness flag, written by `ladym hook install`).

type Payload

type Payload struct {
	HookEventName  string         `json:"hook_event_name"`
	SessionID      string         `json:"session_id"`
	TranscriptPath string         `json:"transcript_path"`
	Cwd            string         `json:"cwd"`
	ToolName       string         `json:"tool_name"`
	ToolInput      map[string]any `json:"tool_input"`
	ToolResponse   any            `json:"tool_response"`
	Prompt         string         `json:"prompt"`
	Source         string         `json:"source"`
}

Payload is the tolerant parse of a hook event JSON document. The two harnesses use near-identical shapes, so one struct serves both.

func Parse

func Parse(data []byte) (*Payload, error)

Parse decodes a hook event document. Unknown fields are ignored.

func (*Payload) ToOperation

func (p *Payload) ToOperation(harness Harness) *engine.OperationEvent

ToOperation maps the payload onto an engine write. It returns nil when the event is outside the V1 set (spec §4.2): the CLI then exits 0 silently.

Jump to

Keyboard shortcuts

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