Documentation
¶
Overview ¶
Package hook implements `codex-router hook`, the optional Codex command hook (UserPromptSubmit, Stop) that prints a systemMessage when the route changed since the previous turn. It reads the control snapshot and never emits additionalContext.
Index ¶
Constants ¶
const MessagePrefix = "router: "
MessagePrefix starts every line; Codex renders it as "↳ Hook · router: …".
Variables ¶
var Timeout = 200 * time.Millisecond
Timeout bounds the whole hook run, registry lookup and socket included. It is a var so tests can widen it for slow hosts or shorten it for stalls.
Functions ¶
func Message ¶
Message returns the switch line for the hook's turn, or "" when there is none: no decision for the turn yet, no earlier turn, or the same route. With no turn id in the input, the thread's latest turn is used.
func Run ¶
Run reads one hook input from stdin, finds the endpoint that routes its thread, asks it for that thread's snapshot and writes {"systemMessage": ...} when the turn's route differs from the previous turn's, else {}. The endpoint is the control socket named by control.EnvSocket (read through getenv; set by the launcher), else the registry endpoint of the hook's Codex home that lists the thread (plain codex). No endpoint, unreadable input or a slow stdin, registry or router all print {} within Timeout and return nil: a hook must never block Codex.