Review-gated red-team / blue-team hardening loop for the opsentry hooks.
- Attacker (headless Claude) generates 10 novel PreToolUse payloads per round, avoiding duplicates from earlier rounds.
- Split 80/20 into training and held-out sets. The defender never sees the held-out attacks — they exist to detect regex overfit.
- Run each attack through every hook in a workdir copy. Count how many bypass.
- Defender (headless Claude) receives hook sources + bypassing training
attacks and returns a unified diff plus new
run_testlines. - Apply the diff to the workdir, re-run the existing
test.sh(must stay green) plus training and held-out attacks. Log results. - Stop after 3 rounds or when two consecutive rounds produce zero bypasses.
- Never modifies
opsentry/claude/hooks/— all edits land inredteam-loop/workdir/claude/hooks/. - Never runs git — no commits, branches, or PRs. You review and apply.
- Never runs
test.shagainst the real hooks — the workdir copy is isolated.
claudeCLI on PATH (headless-pmode)jq,python3,patch
bash run_loop.sh
Each invocation creates a fresh rounds/<timestamp>/ directory.
rounds/<session>/
├── SUMMARY.md # top-level table
└── round-N/
├── attacks.json # full batch from attacker
├── training.json # 80% the defender sees
├── heldout.json # 20% held out (overfit check)
├── train_pre.json # which attacks blocked before defender
├── train_post.json # which blocked after patch applied
├── heldout_pre.json
├── heldout_post.json
├── patch.diff # defender's proposed diff
├── new_tests.sh # proposed run_test lines
├── tests.txt # existing test.sh output on patched hooks
├── attacker_raw.txt
└── defender_raw.txt
cd ~/Desktop/repos/agentguard/opsentry/claude/hooks
patch -p0 < ~/Desktop/repos/agentguard/redteam-loop/rounds/<session>/round-N/patch.diff
# then eyeball new_tests.sh and append lines you want to opsentry/test.sh
bash ~/Desktop/repos/agentguard/opsentry/test.sh
heldout_blockedsubstantially lower thantraining_blocked= regex overfit. Reject the patch or widen the approach.existing tests P/Fmust match baseline (currently 169 / 0). Any regression means the patch broke an allow case.- Monotonic decrease in
unblocked preacross rounds = real hardening; plateau near zero = attacker exhausted.