Add multi-layer enforcement stack and similarity detection - #9
Merged
Conversation
Expand hook coverage from PreToolUse-only to full 4-layer stack: - PostToolUse: validates output, detects secrets in writes, flags errors - SubagentStop: blocks agents from exiting without running tests - Stop: quality gate checking uncommitted changes, conflict markers, TODOs Add Groundhog Day detection to improve loop — stops when consecutive metric outputs are >90% similar, preventing wasted budget on identical failing approaches.
Use git diff --name-only -z with xargs -0 to safely handle filenames containing spaces, quotes, or special characters.
- stop-gate.sh: add -- to grep in xargs to prevent filename injection - post-validate.sh: single grep pass for error detection (was running twice) - post-validate.sh: canonicalize paths with realpath before repo-root check - similarity.go: remove redundant a==b check in short-string branch
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
post-validate.sh): validates Bash output for error signals (permission denied,segfault, etc.), detects hardcoded secrets (AWS/GitHub/OpenAI key patterns) in Edit/Write content, flags writes outside the repo rootsubagent-stop.sh): blocks agents from exiting without evidence they ran tests — checks for Go/Node/Python test runner output, completion promise strings (ALL_PASSING,ALL_DONE,RESEARCH_COMPLETE), and metric pass signalsstop-gate.sh): final quality gate that prompts before session end if there are uncommitted changes, merge conflict markers, or new TODO/FIXME in the diffimprove.go: stops the loop when 2+ consecutive metric outputs are >90% similar (bigram-based), preventing wasted budget on identical failing approachesMotivation
Inspired by Praetorian's deterministic AI orchestration architecture. The existing harness only used PreToolUse hooks (layer 5 of 8). This PR adds layers 6–8 (PostToolUse, SubagentStop, Stop) and a smarter loop termination heuristic.
Test plan
go vet ./...— cleangofmt— cleango test ./... -race -count=1— all 4 packages passlib.Similarity(identical, different, overlap, edge cases)Changelog
Features
Tests
libandloopspackages