Skip to content

Add multi-layer enforcement stack and similarity detection - #9

Merged
5uck1ess merged 3 commits into
mainfrom
feature/enforcement-stack
Apr 3, 2026
Merged

Add multi-layer enforcement stack and similarity detection#9
5uck1ess merged 3 commits into
mainfrom
feature/enforcement-stack

Conversation

@5uck1ess

@5uck1ess 5uck1ess commented Apr 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • PostToolUse hook (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 root
  • SubagentStop hook (subagent-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 signals
  • Stop hook (stop-gate.sh): final quality gate that prompts before session end if there are uncommitted changes, merge conflict markers, or new TODO/FIXME in the diff
  • Groundhog Day detection in improve.go: stops the loop when 2+ consecutive metric outputs are >90% similar (bigram-based), preventing wasted budget on identical failing approaches
  • hooks.json expanded from PreToolUse-only to full 4-layer enforcement stack

Motivation

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 ./... — clean
  • gofmt — clean
  • go test ./... -race -count=1 — all 4 packages pass
  • 7 new tests for lib.Similarity (identical, different, overlap, edge cases)
  • 2 new tests for similarity-based loop termination (similar output stops early; different output falls through to consecutive failures)

Changelog

Features

  • PostToolUse validation hook (error signals, secret detection, out-of-repo writes)
  • SubagentStop verification hook (test evidence required before agent exit)
  • Stop quality gate hook (uncommitted changes, conflict markers, TODOs)
  • Groundhog Day detection in improve loop (>90% bigram similarity threshold)

Tests

  • 9 new tests across lib and loops packages

5uck1ess added 3 commits April 3, 2026 12:39
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
@5uck1ess
5uck1ess merged commit 89035dd into main Apr 3, 2026
1 check passed
@5uck1ess
5uck1ess deleted the feature/enforcement-stack branch April 3, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant