Expand description
Hook step-context: typestate + envelope.
§One-liner
Each mount point gets its own dedicated step type (typestate). The same step state
is consumed by two kinds of hooks — internal Rust hooks work directly with the strong
type and mutate fields; user-configured hooks observe the world through the JSON
envelope produced by HookStep::to_envelope and apply output back via
HookStep::apply_verdict. Equal capability, identical surface — only the medium
of expression differs.
§Two axioms
- Typestate: Instead of one large enum with a variant field, each mount point is
a concrete struct. The surface is locked at compile time;
Optionpresence/absence encodes “already produced / will produce” — filling a “will produce”Optionmeans short-circuit. - Call vs mutation asymmetry: Call-type steps (Generate / ToolApply / Permission)
fill an
Optionto skip; mutation-type steps (Compact / Ingest) degrade to veto/rewrite, without the “fill Option” path.
§Scope (Step 1)
This module delivers types + envelope + unit tests, with no mount points wired
in (call-site integration is a follow-up PR). Currently implements the base
infrastructure (HookControl / HookStep / envelope conventions) plus 3
representative steps: BeforeTurnEnd (fork control), BeforeToolApply (call-type
short-circuit), AfterGenerate (observation). The remaining 10 steps are mechanical
fill-ins of the same shape.
Structs§
- After
Compact after Compact: compression is complete. Injection / observation only.- After
Generate after Generate: the LLM call has returned. Observational — usage / stop / error are all present (non-Option), with no room to “fill in” outputs; to influence the next round, useBeforeTurnEnd. OnlyBreakand observation are meaningful.- After
Ingest after Ingest: input has been merged into history. Injection only.- After
Permission after Permission: authorization result is determined. Observation only.- After
Session Enter after session enter: the session scope has been entered. Allows injecting a system suffix or rejecting withBreak.- After
Tool Apply after ToolApply(per-tool): the tool has produced a result. Supports injection (appending totool_result) orBreak.- After
Tool Batch after ToolBatch: a full batch of parallel tools has finished. Can inject /Break(graceful).- After
Turn Enter after turn enter: the turn scope has been entered, but input for this round has not yet been consumed. Injection orBreakcan reject this turn.- Before
Compact before Compact: runs before compaction. Mutation type — short-circuit =Skip(vetoes this compaction), no “fill result”.- Before
Generate before Generate: runs before the LLM call. Call-site hook — can modify request fields, or setassistant_textto short-circuit (skip the real LLM call with a synthetic reply).- Before
Ingest before Ingest: called before ingesting the current turn’s input. Can rewrite the entire pending input orBreakto reject the turn.- Before
Permission before Permission: invoked before requesting user authorization. Currently only stubs observe — theresolvedfallback is not yet wired (policy remains the authority for allow/deny). Stub is in place for future use.- Before
Tool Apply - Entry point for call-type transformations, invoked before each
ToolApply. - Before
Turn End before turn-end: the turn’s only voluntary exit point. Defaults toBreak— “do nothing” = let it stop.- Synthetic
Tool Result - A synthetic tool result produced by a hook — setting
BeforeToolApply::resulteffectively “intercepts” the tool. - Tool
Batch Entry - A summary entry for a batch of parallel tool results (for envelope use).
Enums§
- Hook
Control - A hook’s instruction for control flow (axis two). Data injection (axis one) goes
through the step’s
&mutfields, not here. - Ingest
Source - The source of the input to be ingested in the current turn.
- Session
Source - The source of the session: new or resumed.
- Verdict
Error - Errors when parsing an envelope verdict.
Constants§
- ALL_
EVENT_ NAMES - The single source of truth for all mount-point
event_names (snake_case) — used by the config layer for event-name validation and by the CLI for bucket assembly.
Traits§
- Hook
Step - The step state for a mount point. Consumed by two kinds of hooks:
Functions§
- is_
known_ event - Whether an event name is a known mount point. The config layer uses this to fail-fast on misspelled event keys.
- run_
step_ pipeline - Applies a sequence of handler verdicts to the same step in declaration order,
producing the final
HookControl.