hook

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 9 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 runs the agent's SessionStart, Stop and prompt hooks and its MCP headers helper. A hook never blocks by failing: any error, panic or answer later than Budget allows, with the cause on standard error.

Index

Constants

View Source
const Budget = 2 * time.Second

Budget is how long a hook takes at most, reading its input included.

Variables

This section is empty.

Functions

func MCPHeaders

func MCPHeaders(env func(string) string, out io.Writer, h harness.Set) int

MCPHeaders writes the headers the agent sends the loop's MCP server: the session's handle, from whichever manager set one. Claude Desktop leaves variables in a registration's headers unexpanded, and runs this helper in the session's environment. The daemon refuses a handle no session of the loop took, so an unclaimed one is sent too.

func Prompt

func Prompt(ctx context.Context, env func(string) string, in io.Reader, errw io.Writer, c Agent, h harness.Set, kind string) (code int)

Prompt tells the daemon the session took a prompt, so a close can tell whether the user typed in it. It prints nothing on standard output, which would enter the agent's context.

func SessionStart

func SessionStart(ctx context.Context, env func(string) string, in io.Reader, errw io.Writer, c Agent, h harness.Set, kind string) (code int)

SessionStart registers the session with the daemon. It prints nothing on standard output, which would enter the agent's context.

func Stop

func Stop(ctx context.Context, env func(string) string, in io.Reader, out, errw io.Writer, c Agent, h harness.Set, kind string) (code int)

Stop asks the daemon whether the session may stop, and blocks once per prompt when its turn owes a record.

Types

type Agent

type Agent interface {
	SessionStart(ctx context.Context, handle string, r api.SessionStartRequest) error
	Stop(ctx context.Context, handle string, r api.StopRequest) (api.StopAnswer, error)
	Prompt(ctx context.Context, handle string, r api.PromptRequest) error
}

Agent is the part of AgentAPI the hooks call.

Jump to

Keyboard shortcuts

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