Documentation
¶
Overview ¶
Package hooks dispatches user-configured shell commands on ctm lifecycle events (attach, new, yolo, safe, kill).
The contract is deliberately narrow: hooks are shell strings, one per named event, declared in config.json under "hooks". Each hook runs synchronously with a configurable timeout (default 5 s) and receives the session context via CTM_* environment variables. A hook that errors or times out logs a WARN-level diagnostic but never blocks or rolls back the action that fired it — hooks are side-channel notifications, not gates.
To run something in the background, the user writes a trailing `&` or spawns a backgrounded process from the hook command.
Index ¶
Constants ¶
const ( EventOnAttach = "on_attach" EventOnNew = "on_new" EventOnYolo = "on_yolo" EventOnSafe = "on_safe" EventOnKill = "on_kill" )
Supported event names. Unknown events in config log a warning at startup but are never invoked — see IsKnownEvent.
const DefaultTimeout = 5 * time.Second
DefaultTimeout is the per-hook wall-clock ceiling. 5 s is short enough to stay out of the interactive path's latency budget but long enough for a curl or a git commit.
Variables ¶
This section is empty.
Functions ¶
func IsKnownEvent ¶
IsKnownEvent reports whether name is in the documented event set.
func Run ¶
Run executes the hook command bound to event (via hooks map from config). If event has no entry, Run is a silent no-op. The hook is invoked through "sh -c" so users can use pipes, redirects, and env expansion. Timeout defaults to DefaultTimeout; pass <=0 to use it.
Returns nil on success and a non-nil error on any failure (timeout, non-zero exit, command not found). Callers in ctm's command path should swallow — a failing hook must never block the action that triggered it. Internal WARN-level slog lines make the failure observable via --log-level=info or --verbose.
Types ¶
type Context ¶
type Context struct {
SessionName string
SessionUUID string
SessionMode string
SessionWorkdir string
}
Context is the per-invocation data passed into hooks as environment variables. Any zero-valued field is translated to an empty env var — hooks must tolerate missing data rather than crash on it.