Skip to main content

Module hook

Module hook 

Source
Expand description

The hook: every harness’s events, one canonical, Claude-shaped event each (session_id, cwd, prompt, tool_name, tool_input, error, last_assistant_message, transcript_path, stop_hook_active), answered Claude-shaped ({“decision”:“block”,“reason”} at stop, hookSpecificOutput with context at a prompt or tool call); adapters translate both ways (harness/). What differs per harness comes from its Harness: capabilities, the turn’s work and the drone’s last message, never its name.

main routes and records presence; dispatch has one function per event. Hooks always fail open: any error lets the drone continue untouched.

Functions§

dispatch
One hook event, canonical already (harness normalise), for the drone h runs: what borg answers (Claude-shaped), or None. One function per event.
judge_session
The session-end judge (0.7.5), run by borg learn --session before it learns (main.rs learn_cmd): one model call over every delivery of session (any channel) whose latest delivery no verdict settled yet (none came, or only unclear, consequence_remains or missing ones, its tries spent or not), with the whole session’s work in view (session_work), through the same records as a check’s judge (record_verdicts, at outcome.rs AT_END) and the state lines #borg-judged, then END_JUDGED: what it judged settles there, and borg learn then settles the rest as asked_not_corrected with its reason (unjudged). Its call is counted as a model_call with why judge. Nothing runs, and nothing is written, without learning (BORG_LEARN=off), without a runner for the consequence model (BORG_PREDICT_MODEL=off, none installed), with nothing open, or while a live check holds the session’s lock past its staleness (it judges them itself). A failed call is no try (#borg-unjudged … why=failed). Returns how many lessons it judged.
live_check
borg check (live.rs): one check of the session’s work so far, in the background. Takes the session’s lock (or leaves: a check runs), decides again under it, then runs the stop’s check on this turn so far: its asks wait in the .queued file as a live <ids> line when it graded a 3, which a stop asks while they wait as its own block would have, else as a live-next <ids> line, which no stop asks (Verdict::Ask); the free lessons as at the stop. It writes no #borg-asked (that happens at delivery, ask_live) and no #borg-skip (that closes a stop’s turn): a gate skip is #borg-live-skip. The mark records the changes a completed check covered.
main
borg hook <harness> <event>, the event on stdin: routes the repo to its collective (an off repo leaves no trace), records presence, then answers through steering, the experts and dispatch, with the messages from other sessions (msg.rs). An unknown harness, like any failure here, lets the drone continue untouched.
stripped
Whether the judge sees question lesson of check without the drone’s <id>: applies|skip: a fair coin from blake3 over both, so a retry strips alike and a replay knows it (outcome.rs stripped; a test predicts a judge prompt by it). Method: a random half, to measure what the declaration adds to a verdict.