Skill v1.0.0
currentAutomated scan100/100version: "1.0.0" name: phase-agent-allowlist description: "How to restrict phase-running/phase-complete transitions in brain.json hooks to top-level orchestration agents only, preventing nested sub-agents from corrupting the phase state machine." user-invocable: false
When to use
When the dark-factory hooks track phases (e.g., planning-running, planning-complete) AND the system invokes Agent or Skill tool calls at multiple nesting depths (e.g., feature-agent calls repair-agent calls a helper agent).
Without an allowlist, every Agent tool call — including deeply nested ones — triggers a phase transition. A nested agent completion can flip a phase to complete before the actual top-level agent responsible for that phase has finished, breaking the state machine.
Steps
- Define the allowlist as a pipe-delimited regex string in both
pre-tool-use-hook.shandpost-tool-use-hook.sh:
``bash PHASE_AGENTS="feature-agent|debugger-agent|repair-agent|code-review-orchestrator-agent|update-documentation-agent|skill-update-agent|pr-agent" ` List only the top-level orchestration agents — the ones that map 1:1 to phases in brain.json`.
- In
pre-tool-use-hook.sh, extract the agent name from the tool input and gate the phase-running block:
```bash PHASE_AGENT_NAME="" if [ "$TOOL_NAME" = "Agent" ]; then PHASE_AGENT_NAME=$(printf '%s' "$TOOL_INPUT" | jq -r '.tool_input.subagent_type // ""') fi
if [[ "$PHASE_AGENT_NAME" =~ ^($PHASE_AGENTS)$ ]]; then # set phase *-running = true else echo "pre-tool-use-hook | set-phase-running | skipped (agent=${PHASE_AGENT_NAME} not a phase agent)" >&2 fi ```
- In
post-tool-use-hook.sh, extract the metrics key (which equals the agent/skill name) and gate the phase-complete block:
``bash if [[ "$METRICS_KEY" =~ ^($PHASE_AGENTS)$ ]]; then # set phase *-running = false, *-complete = true else echo "post-tool-use-hook | set-phase-complete | skipped (agent=${METRICS_KEY} not a phase agent)" >&2 fi ` This block must be nested inside the if [ "$TOOL_NAME" = "Agent" ] || [ "$TOOL_NAME" = "Skill" ] block so METRICS_KEY` is already resolved.
- Metrics accumulation (elapsed_ms, tokens, runs) is NOT gated — it runs for all agents and skills at all depths. Only phase transitions are restricted.
- When adding a new top-level orchestration agent, add its
subagent_typevalue to thePHASE_AGENTSstring in both hook scripts simultaneously. Forgetting one will cause the pre-hook to start a phase but the post-hook to never complete it.
Notes
- The
METRICS_KEYin the post-hook is derived fromtool_input.subagent_typefor Agent calls andtool_input.namefor Skill calls. Phase agents are alwaysAgenttype, so the Skill branch never triggers phase transitions by design. - Use
^($PHASE_AGENTS)$(anchored regex) to prevent partial matches (e.g.,repair-agent-helperaccidentally matchingrepair-agent). - The allowlist lives in the hook scripts, not in brain.json, because it describes the hook's own behavior, not task state.
- If a phase agent is retried (called more than once), the pre-hook will attempt to advance to the next unstarted phase on the retry. Ensure retry logic in the orchestrator accounts for this, or make the phase advance idempotent.