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
- func MCPHeaders(env func(string) string, out io.Writer, h harness.Set) int
- func Prompt(ctx context.Context, env func(string) string, in io.Reader, errw io.Writer, ...) (code int)
- func SessionStart(ctx context.Context, env func(string) string, in io.Reader, errw io.Writer, ...) (code int)
- func Stop(ctx context.Context, env func(string) string, in io.Reader, ...) (code int)
- type Agent
Constants ¶
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 ¶
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.
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.