Hooks #
Hooks let managed extensions answer turn events.
hook.gleam defines the events and merge
rules. The runtime exposes the composed hook to turns and kernel
calls.
Events #
Prompted carries user text before a turn's first model call. Calling carries
a tool call before execution. Called carries the call, output, and start and
finish times. Outer model calls report refusals through Called. An inner
Python call refused before execution raises without that follow-up report.
Stopping carries the reply and the number of times hooks have held the turn
open. See hook.Event and hook.Call,
the model loop, and
Python reporting.
Combining verdicts #
A Verdict can block, replace call arguments, add context or notes, or halt the
turn. hook.ask calls every hook in order.
The first block, argument replacement, and halt each win in the final verdict.
Each hook's replacement updates the event passed to the next hook, even if an
earlier replacement already won. Context and notes accumulate. A crashed hook
adds a note and otherwise proceeds.
hook.route handles kernel inner-call reports and returns a halt as a refusal.
Outer notes are published to the user by
the model loop.
Python reporting prints inner notes and
context into cell output, making both model-visible.
Synchronous host reporting has a 30-second wait in
host_now. Asynchronous reporting waits on
its host reply without that deadline. Ordinary reporting errors fail open. Inner
output is capped at 65,536 Python string characters, not bytes.
Command hooks #
The hooks extension
reads $ALBEDO_HOME/hooks.json and maps events to UserPromptSubmit,
PreToolUse, PostToolUse, and Stop. Inner run, files.edit, and
files.write calls are named Bash, Edit, and Write for matchers.
albedo_hook_command.py runs matching
command hooks with JSON on stdin. The default timeout is 600 seconds. Exit
status 2 blocks. Other failures and invalid output fail open with a note.
Commands run in separate process groups, which the helper kills after completion
or timeout. The helper merges results in configuration order and limits
additional context. Command hooks are therefore not a fail-closed security
boundary.
Commands use the session workspace when it exists as a directory, otherwise the helper's inherited working directory. The daemon launcher stops waiting for the entire helper after 660 seconds. The helper's normal cleanup path does not establish what happens to command descendants if the helper itself dies.