feat(hooks): add PreTurn and PostTurn lifecycle hook events (roadmap 7.28)#185
Merged
emal-avala merged 1 commit intomainfrom Apr 23, 2026
Merged
feat(hooks): add PreTurn and PostTurn lifecycle hook events (roadmap 7.28)#185emal-avala merged 1 commit intomainfrom
emal-avala merged 1 commit intomainfrom
Conversation
…7.28) Adds two new HookEvent variants: - PreTurn: fires after user input is in history, before the LLM is called. Context payload includes turn number and user-input preview. - PostTurn: fires on successful turn completion (no tool_use in the assistant's response). NOT fired on cancel or error paths — hooks shouldn't have to guard against 'did the turn actually succeed?'. Both events integrate with the existing HookRegistry::run_hooks machinery — configured via `[[hooks]]` in settings.toml with `event = "pre_turn"` or `event = "post_turn"`. Shell and HTTP actions both work. Context JSON is passed through HookRegistry::run_hooks's third parameter — the existing shell/http hook actions don't consume it today, but the wiring is in place for when they do (e.g. writing it to stdin or a query-string).
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes roadmap item 7.28. Adds two new
HookEventvariants:PreTurn— fires after user input is in history, before the LLM is called. Context payload: turn number + user-input preview (first 200 chars).PostTurn— fires on successful turn completion (notool_usein the assistant's response). Not fired on cancel or error — hooks shouldn't have to guard against 'did the turn actually succeed?'.Configure via
[[hooks]]insettings.tomlwithevent = "pre_turn"orevent = "post_turn". Shell and HTTP action types both work out of the box.Why
PreToolUse / PostToolUse hooks exist, but there's no way to run something once per agent turn. Common asks:
/proc/meminfoper turn (perf regression bisection)Turn-level hooks close that gap.
Behavior
PreTurnfires afterpush_message(user_msg), beforeenable_caching/ API call. Fires once perrun_turn_with_sinkinvocation regardless of how many internal tool iterations happen.PostTurnfires only at the happy-path exit (no tool_use). The max-turns / cancel / error / overflow paths are deliberately not hooked — those aren't 'a turn completed'.Context JSON carries
turn+user_input_previewfor PreTurn,turn+total_turnsfor PostTurn. Shell/HTTP actions don't consume context today — wiring is in place for when they do.Test plan
cargo fmt --allcleancargo checkpassescargo clippy --all-targets -- -D warningscleancargo test -p agent-code-lib --lib config::schema::tests::hook_event— 7 variants round-trip (5 existing + 2 new)[[hooks]] event = "post_turn" action = { type = "shell", command = "echo done >> /tmp/turns.log" }→ log line per successful turn