refactor(hooks): strip hardcoded audit subagent from TurnEnd, add @@INJECT protocol#2337
Open
m8f1m8f1 wants to merge 13 commits into
Open
refactor(hooks): strip hardcoded audit subagent from TurnEnd, add @@INJECT protocol#2337m8f1m8f1 wants to merge 13 commits into
m8f1m8f1 wants to merge 13 commits into
Conversation
added 13 commits
May 29, 2026 17:26
- runTurnEndAudit(): spawns read-only subagent with 20s timeout - AUDIT_SUBAGENT_SYSTEM_PROMPT with DO NOT modify hard constraint - AUDIT_SUBAGENT_READ_ONLY_TOOLS: 6 read-only tools - AbortSignal.any() combines turn abort + timeout - appendAndPersist audit report as user role on block - Empty assistantContent and aborted turn early-exit guards - 5 new loop-level tests covering 3-strike guard, block-continue, fallback - V-TE-01~05 fixes: feedback injection, counter reset, timeout 30s to 10s - BLOCKING_EVENTS exported for test consumption - V-TE-05 automated type synchronization tests
- quittingRef prevents multiple process.exit calls - beforeQuit error does not prevent process.exit - null transcriptRef does not crash
- Move SessionStart from constructor fire-and-forget to step() await - _sessionStartExecuted guard ensures single execution - Hook stdout appended to prefix.system via replaceSystem() - Empty stdout or no hook = zero overhead - 4 new tests: injection, once-only, empty-stdout, no-hook
- Audit finding: catch block only logged to console, user could not see the error - Now yields a warning event so the UI surfaces the failure
- Defense-in-depth: cap each hook stdout fragment at 4096 chars - Prevents system prompt bloat from misbehaving hooks
- Remove AUDIT_SUBAGENT_SYSTEM_PROMPT, AUDIT_SUBAGENT_READ_ONLY_TOOLS - Remove runTurnEndAudit() method - Remove spawnSubagent import - Add @@INJECT/@@warn protocol parsing for user-defined feedback - TurnEnd hooks now control injection behavior via stdout protocol - Update tests to cover @@INJECT/@@warn instead of audit subagent TurnEnd is now a pure hook gate same mechanism as Claude Code Stop hook.
5 tasks
Author
|
@esengine This PR supersedes #2156. Based on your feedback about the audit subagent being outside the scope of a hook mechanism, we've stripped it entirely. TurnEnd is now a pure hook gate with @@INJECT/@@warn stdout protocol — hook scripts decide what checks to run and what feedback to inject; the gate only provides block/pass + protocol parsing. The PR body has been updated with the full event table and usage examples. No rush — whenever the release batch lands. |
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.
Closes #2155 — supersedes #2156
What
Extend Reasonix hook system from 4 lifecycle events to 10, covering the full AI Agent lifecycle. This PR also refactors TurnEnd from a hardcoded audit-subagent gate into a pure hook mechanism with @@INJECT/@@warn stdout protocol — providing the interface, not the business logic.
All hook events (4 existing + 6 new)
Key features
SessionStart — context injection (Claude Code parity)
SessionStart hook stdout is injected into the system prompt, achieving Claude Code parity. Users write their own scripts to inject cross-session recovery, project briefs, etc. Empty stdout or no hook = zero overhead.
TurnEnd — pure hook gate with @@INJECT/@@warn protocol
TurnEnd fires when the agent finishes its response and is about to end the turn. It is in BLOCKING_EVENTS:
The @@INJECT/@@warn stdout protocol lets hook scripts communicate back:
This replaced the previously hardcoded audit subagent. TurnEnd now provides the mechanism only — users write their own scripts to decide what checks to run and what feedback to inject.
Example hook script:
Safety mechanisms
Backward compatibility
Changes (9 files)
Refactor note
Supersedes #2156 which had a hardcoded audit subagent. Based on review feedback, hooks should not embed business logic. Replaced with @@INJECT/@@warn protocol.
Checklist