feat(hooks): wire session_start, session_stop, user_prompt_submit#214
Merged
emal-avala merged 2 commits intomainfrom Apr 23, 2026
Merged
feat(hooks): wire session_start, session_stop, user_prompt_submit#214emal-avala merged 2 commits intomainfrom
emal-avala merged 2 commits intomainfrom
Conversation
Three hook events were declared in the config schema, listed by /hooks, and documented in the module header — but never actually called from the agent loop. Users configuring a session_start audit log, a session_stop cleanup script, or a user_prompt_submit redaction guard would have seen nothing happen at runtime. This wires all three: - UserPromptSubmit fires inside run_turn_with_sink, right after the user message is pushed to history and before PreTurn. Hooks get the full prompt text (not the 200-char preview PreTurn receives) so compliance audits / scanners see the real input. - SessionStart fires once per engine lifetime, after load_hooks. It receives session id, cwd, and active model in the JSON context, so hooks can tag logs or load per-project secrets. - SessionStop fires at every clean exit: the one-shot path (even on non-zero exit codes, by firing before std::process::exit), the REPL path after the loop returns, and the scheduled-executor one-shot path after the turn completes. Hook context includes turn count, total cost, and total tokens for summary reporting. Adds 4 async unit tests in hooks::tests using a shell hook that touches a temp file, verifying each of the three events dispatches correctly and that events don't cross-fire (SessionStop dispatch with only a SessionStart hook registered leaves the probe file empty).
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
The new hooks::tests module uses bash subprocesses to prove each event dispatches. On Windows CI, `bash` resolves to WSL, which isn't installed on the runner — the tests fail with a WSL install-distribution error. The Shell hook action itself invokes `bash -c` in production, so these tests exercise a code path that is fundamentally unix-only anyway. Gate the whole tests module on cfg(unix).
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
Three hook events — `SessionStart`, `SessionStop`, and `UserPromptSubmit` — are declared in the config schema, listed by `/hooks`, and documented in the module header, but were never actually fired from the agent loop. User-configured hooks for these events would silently never run.
This PR wires all three:
Also wires these for the scheduled-task executor so `agent schedule` one-shots get the same lifecycle as interactive sessions.
Test plan