fix: guard SubagentStop hook to only fire during active workflows#27
fix: guard SubagentStop hook to only fire during active workflows#27
Conversation
The prompt-type SubagentStop hook fired unconditionally on every subagent stop, wasting tokens on workflow enforcement when no /next-task workflow was running. Observed: 136K tokens and 19 minutes wasted on a single exploration agent. Switch to a command-type hook with a Node.js guard script that checks for an active flow.json before outputting the enforcement prompt. Uses Node instead of bash for cross-platform support (Windows + Unix). Closes agent-sh/agentsys#325
There was a problem hiding this comment.
Code Review
This pull request replaces the static subagent-stop hook with a dynamic Node.js guard script, subagent-stop-guard.js, which injects workflow enforcement prompts only when a workflow is actively in progress. It also introduces a comprehensive test suite for the guard script and adds a test execution script to package.json. The review feedback recommends simplifying the state directory path resolution by utilizing existing library helpers and adding a fallback value for the workflow phase in the generated prompt to prevent 'undefined' output.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 66951f0517
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Summary
prompttype to guardedcommandtypesubagent-stop-guard.js- a Node.js script that checks for activeflow.jsonbefore injecting the workflow enforcement promptProblem
The
prompttype SubagentStop hook fired on every subagent stop across the entire session, not just during/next-taskworkflows. An exploration agent wasted 136K tokens and 19 minutes processing gate logic before returning "All gates blocked."Fix
The guard script reads
{stateDir}/flow.jsonusing the existing platform-aware state directory detection. It only outputs the enforcement prompt to stderr whenstatus === 'in_progress'andphase !== 'complete'. Otherwise it exits silently (no-op).Closes agent-sh/agentsys#325
Test plan
/next-taskworkflow, verify enforcement prompt still appears between phases