feat(tools): add PhaseGate hook and ReflectionDigest#1029
Open
fabiendostie wants to merge 1 commit intodanielmiessler:mainfrom
Open
feat(tools): add PhaseGate hook and ReflectionDigest#1029fabiendostie wants to merge 1 commit intodanielmiessler:mainfrom
fabiendostie wants to merge 1 commit intodanielmiessler:mainfrom
Conversation
…ment Two tools that address the top failure patterns identified from analyzing 49 Algorithm reflections: **PhaseGate.hook.ts** — Claude Code PostToolUse hook that enforces Algorithm gates via PRD evidence checking. Warns (never blocks) when transitioning to THINK without ENVIRONMENT check or BUILD without VALIDATE entry. Moves enforcement from advisory text to structural code. **ReflectionDigest.ts** — CLI tool that reads algorithm-reflections.jsonl, clusters failure patterns by keyword, identifies missed capabilities, and generates ranked heuristic rules. Closes the reflection-to-action loop so past failures drive behavioral change in future sessions. Background: Analysis of 49 reflections + 40 papers (2025-2026) revealed that PAI's advisory gates fail because the AI rationalizes past them. The top patterns: build-before-validate (31%), phantom capabilities (25%), env assumptions (17%). These tools address the root cause: enforcement must be structural (hooks), not textual (instructions). Co-Authored-By: Claude Opus 4.6 and Fabien Dostie
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
Two self-contained tools that address the top failure patterns from analyzing 49 Algorithm reflections:
PhaseGate.hook.ts — Claude Code PostToolUse hook that warns when transitioning to THINK without
ENVIRONMENT:check or BUILD withoutVALIDATE:entry in the PRD's## Decisionssection. Warning mode only — never blocks. Moves gate enforcement from text instructions (which the AI can rationalize past) to code hooks (which it cannot).ReflectionDigest.ts — CLI tool (
bun ReflectionDigest.ts) that readsalgorithm-reflections.jsonl, clusters failure patterns, identifies missed capabilities, and generates ranked heuristic rules. Closes the reflection-to-action loop so past failures drive behavioral change in future sessions.Why these exist
Analysis of 49 Algorithm reflections + 40 research papers (2025-2026) revealed a fundamental architectural weakness: advisory gates don't constrain a generative model. The Algorithm has 8 gates labeled "HARD GATE" or "MANDATORY," but they're text instructions the AI reads and can skip. The top recurring failure patterns:
PhaseGate moves the top 2 gates to code enforcement. ReflectionDigest ensures reflections become actionable heuristics instead of write-only logs.
Files changed
Tools/PhaseGate.hook.ts— Self-contained hook (no lib/ dependencies)Tools/ReflectionDigest.ts— Self-contained CLI tool (no lib/ dependencies)Tools/README.md— Updated with documentation for both toolsTest plan
bun Tools/PhaseGate.hook.tswith a PRD that hasphase: buildbut noVALIDATE:in Decisions → should print warning to stderrbun Tools/PhaseGate.hook.tswith a PRD that hasVALIDATE:in Decisions → should pass silentlybun Tools/ReflectionDigest.ts --dry-runwith existing reflections JSONL → should print digest{"continue": true}/ exit code 0Co-Authored-By: Claude Opus 4.6 and Fabien Dostie