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

hookapi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package hookapi defines the agent-neutral hook contract. Agent adapters translate each agent's native hook JSON into a HookEvent and translate the resulting Decision back; the steering core only ever sees these types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action is the steering verdict for a hook event.

const (
	ActionAllow Action = "allow" // explicitly permit the tool call
	ActionDeny  Action = "deny"  // block; Reason is shown to the model
	ActionAsk   Action = "ask"   // defer to the user (agent permitting)
	ActionNoop  Action = "noop"  // express no opinion; agent default applies
)

Actions.

func ParseAction

func ParseAction(s string) (Action, error)

ParseAction parses an action name case-insensitively.

type Agent

type Agent string

Agent identifies the AI coding agent that fired a hook.

const (
	AgentClaude   Agent = "claude"
	AgentCodex    Agent = "codex"
	AgentCursor   Agent = "cursor"
	AgentOpenCode Agent = "opencode"
)

Supported agents.

func AllAgents

func AllAgents() []Agent

AllAgents returns every supported agent in stable order.

func ParseAgent

func ParseAgent(s string) (Agent, error)

ParseAgent parses an agent name case-insensitively ("claude-code" is accepted as an alias for claude).

func (Agent) Valid

func (a Agent) Valid() bool

Valid reports whether a is a supported agent in canonical spelling.

type Decision

type Decision struct {
	Action Action `json:"action,omitempty"`
	// Reason is shown to the model, primarily on deny.
	Reason string `json:"reason,omitempty"`
	// AdditionalContext is injected into the model context (session start
	// summaries, read outlines).
	AdditionalContext string `json:"additional_context,omitempty"`
	// UserMessage is shown to the human only.
	UserMessage string `json:"user_message,omitempty"`
	// UpdatedInput optionally rewrites the tool input (agent permitting).
	UpdatedInput json.RawMessage `json:"updated_input,omitempty"`
}

Decision is the agent-neutral hook result. Adapters render it into each agent's native output (exit code, hookSpecificOutput, permission, ...).

func Allow

func Allow() Decision

Allow returns an allow decision.

func Ask

func Ask(reason string) Decision

Ask returns an ask decision with a reason.

func Deny

func Deny(reason string) Decision

Deny returns a deny decision with a reason for the model.

func Noop

func Noop() Decision

Noop returns a decision that expresses no opinion.

func (Decision) Blocks

func (d Decision) Blocks() bool

Blocks reports whether the decision prevents the tool call.

func (Decision) Effective

func (d Decision) Effective() Action

Effective returns the action, treating the zero value as noop.

func (Decision) WithContext

func (d Decision) WithContext(ctx string) Decision

WithContext returns a copy of d with AdditionalContext set.

func (Decision) WithUserMessage

func (d Decision) WithUserMessage(msg string) Decision

WithUserMessage returns a copy of d with UserMessage set.

type Event

type Event string

Event is a normalized hook lifecycle event.

const (
	EventSessionStart  Event = "session-start"
	EventSubagentStart Event = "subagent-start"
	EventPreToolUse    Event = "pre-tool-use"
	EventPostToolUse   Event = "post-tool-use"
	EventPreCompact    Event = "pre-compact"
	EventStop          Event = "stop"
)

Hook events. String values are the kebab-case CLI spelling used by `graphmaster hook <event>`.

func AllEvents

func AllEvents() []Event

AllEvents returns every event in stable order.

func ParseEvent

func ParseEvent(s string) (Event, error)

ParseEvent accepts the kebab-case, snake_case, PascalCase or camelCase spelling of an event. Agent-specific events (e.g. Cursor's afterFileEdit) must be mapped by the adapter first.

func (Event) IsToolEvent

func (e Event) IsToolEvent() bool

IsToolEvent reports whether the event carries a tool invocation.

func (Event) Valid

func (e Event) Valid() bool

Valid reports whether e is a known event in canonical spelling.

type HookEvent

type HookEvent struct {
	Agent     Agent  `json:"agent"`
	Event     Event  `json:"event"`
	SessionID string `json:"session_id,omitempty"`
	// AgentID identifies a subagent within the session; "" for the main agent.
	AgentID   string `json:"agent_id,omitempty"`
	AgentType string `json:"agent_type,omitempty"` // e.g. "Explore", "Plan"
	Tool      Tool   `json:"tool,omitempty"`
	Pattern   string `json:"pattern,omitempty"` // search pattern (grep)
	// Paths are the target files or directories, as given by the agent
	// (absolute or relative to CWD).
	Paths     []string        `json:"paths,omitempty"`
	Glob      string          `json:"glob,omitempty"`    // glob pattern or grep file filter
	Command   string          `json:"command,omitempty"` // shell command text
	CWD       string          `json:"cwd,omitempty"`
	ToolUseID string          `json:"tool_use_id,omitempty"`
	Raw       json.RawMessage `json:"raw,omitempty"` // original payload, for logging/dedupe
}

HookEvent is one agent-neutral hook invocation.

func (HookEvent) IsSubagent

func (e HookEvent) IsSubagent() bool

IsSubagent reports whether the event came from a subagent.

func (HookEvent) Validate

func (e HookEvent) Validate() error

Validate checks that the adapter produced a well-formed event.

type Tool

type Tool string

Tool is the normalized category of the tool an agent is invoking.

const (
	ToolGrep  Tool = "grep"  // content search (Claude Grep, Cursor Grep)
	ToolGlob  Tool = "glob"  // file-name search
	ToolRead  Tool = "read"  // file read
	ToolShell Tool = "shell" // shell command (Bash, Shell, beforeShellExecution)
	ToolPatch Tool = "patch" // multi-file patch (Codex apply_patch)
	ToolMCP   Tool = "mcp"   // MCP tool call
	ToolEdit  Tool = "edit"  // in-place file edit
	ToolWrite Tool = "write" // whole-file write
	ToolOther Tool = "other" // anything else
)

Tool categories.

func (Tool) IsMutation

func (t Tool) IsMutation() bool

IsMutation reports whether t modifies files (triggers a dirty hint).

func (Tool) IsSearch

func (t Tool) IsSearch() bool

IsSearch reports whether t is a direct code search the steering layer may redirect.

func (Tool) Valid

func (t Tool) Valid() bool

Valid reports whether t is a known tool category.

Jump to

Keyboard shortcuts

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