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

hooks

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package hooks reads the hook calls of vendor agent CLIs and edits their hook config files. It does not import the visor.

Index

Constants

View Source
const MaxPayload = 1 << 20

MaxPayload is the largest hook payload, in bytes.

View Source
const Version = 1

Version is the shape of the hook command. Increase it when the command changes, so that Status reports outdated.

Variables

View Source
var (
	ErrUnsupported = errors.New("hooks: harness has no hook support")
	ErrPayload     = errors.New("hooks: bad payload")
)

Errors.

View Source
var ErrCommand = errors.New("hooks: bad hook command")

ErrCommand means that the hook command is not usable.

Functions

func ConfigPath

func ConfigPath(harness, dir string) (string, error)

ConfigPath gives the hook config file in the vendor home dir.

func Names

func Names() []string

Names lists the harnesses with hook support, sorted.

func Supported

func Supported(harness string) bool

Supported reports whether the harness has hook support.

Types

type Ask

type Ask string

Ask tells what a request asks the user.

const (
	AskPermission Ask = "permission"
	AskQuestion   Ask = "question"
)

Asks.

type Event

type Event struct {
	Harness string
	// Name is the vendor event name.
	Name string
	Kind Kind
	// VendorID is the vendor session id.
	VendorID   string
	Cwd        string
	Transcript string
	Prompt     string
	Tool       string
	ToolUseID  string
	ToolInput  json.RawMessage
	// Ask is set on a request.
	Ask Ask
	// Question and Options are the first question of a question tool.
	Question string
	Options  []string
	// Message is the last assistant message of a stop.
	Message     string
	Interrupted bool
	// Error is set on a stop that failed.
	Error string
}

Event is one hook call in a neutral form.

func Parse

func Parse(harness string, data []byte) (Event, bool, error)

Parse reads one hook payload of a harness. ok is false for an event that does not change a session, for example a subagent tool or a compact restart.

func (Event) InputText

func (e Event) InputText() string

InputText gives a short text of the tool input: the command or the path when there is one, else the compact JSON.

type Installer

type Installer struct {
	// contains filtered or unexported fields
}

Installer adds and removes the hook entries of one visor in the vendor hook configs. It keeps the other entries and the rest of each file.

func NewInstaller

func NewInstaller(tag string, argv []string) (*Installer, error)

NewInstaller takes the hook command before the harness name, with an absolute program path first, and a tag that names the visor.

func (*Installer) Command

func (i *Installer) Command(harness string) string

Command is the hook command line for a harness. It reads stdin and does nothing when the program is gone.

func (*Installer) Install

func (i *Installer) Install(harness, dir string) error

Install adds or updates the hook entries of the harness in the vendor home dir.

func (*Installer) Remove

func (i *Installer) Remove(harness, dir string) error

Remove takes out only the hook entries of this visor.

func (*Installer) Status

func (i *Installer) Status(harness, dir string) (State, error)

Status gives the hook state of the harness in the vendor home dir.

type Kind

type Kind string

Kind is the neutral kind of a hook event.

const (
	KindSessionStart Kind = "session_start"
	KindPrompt       Kind = "prompt"
	// KindTool is a tool that starts. The turn runs.
	KindTool     Kind = "tool"
	KindToolDone Kind = "tool_done"
	// KindRequest is a permission or a question with its details.
	KindRequest Kind = "request"
	// KindAttention means that the harness waits for the user, with no
	// details.
	KindAttention  Kind = "attention"
	KindStop       Kind = "stop"
	KindSessionEnd Kind = "session_end"
)

Event kinds.

type State

type State string

State is the hook state of one harness in one vendor home.

const (
	StateInstalled State = "installed"
	StateMissing   State = "missing"
	StateOutdated  State = "outdated"
	// StateUntrusted means that the vendor runs the hooks only after the user
	// trusts them in the vendor CLI.
	StateUntrusted State = "untrusted"
)

Hook states.

Jump to

Keyboard shortcuts

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