hook

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 10 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 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

View Source
const MessagePrefix = "router: "

MessagePrefix starts every line; Codex renders it as "↳ Hook · router: …".

Variables

View Source
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

func Message(s route.Snapshot, in Input) string

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

func Run(stdin io.Reader, stdout io.Writer, getenv func(string) string) error

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.

Types

type Input

type Input struct {
	SessionID string `json:"session_id"`
	TurnID    string `json:"turn_id"`
}

Input is the subset of the Codex hook stdin the hook reads.

type Output

type Output struct {
	SystemMessage string `json:"systemMessage,omitempty"`
}

Output is the hook's stdout. Only systemMessage is ever set.

Jump to

Keyboard shortcuts

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