Skip to content

feat: opt-in adversarial review + TDD enforcement gates - #933

Closed
fernandoxavier02 wants to merge 1 commit into
obra:mainfrom
fernandoxavier02:feat/adversarial-review-tdd-enforcement
Closed

fernandoxavier02 wants to merge 1 commit into
obra:mainfrom
fernandoxavier02:feat/adversarial-review-tdd-enforcement

Conversation

@fernandoxavier02

Copy link
Copy Markdown

Summary

  • Adds opt-in adversarial review with parallel specialized agents (security, edge-cases, architecture) that scale by task complexity
  • Adds TDD enforcement gate that verifies Red-Green-Refactor via git history inspection
  • Both gates are optional — user chooses before execution with 4 options (both, TDD only, adversarial only, neither)
  • Adversarial findings trigger an auto-fix loop (fix agent → re-review, max 3 iterations, then escalate to human)
  • Includes 42 structural integrity tests validating the entire system

Motivation

Long autonomous execution runs without intermediate adversarial review produce compounding errors — especially security vulnerabilities, unhandled edge cases, and architecture regressions. The current spec + quality review gates catch what was requested and whether it's clean, but not whether it's safe or robust.

TDD is recommended in the implementer prompt but never verified. This PR adds actual verification via git history analysis.

Changes

New files (5 adversarial agent prompts + 1 test suite)

File Purpose
tdd-verifier-prompt.md Inspects git log to verify Red-Green-Refactor cycle
adversarial-security-prompt.md Hunts injections, auth bypass, data leaks, race conditions
adversarial-edge-cases-prompt.md Probes boundary values, error paths, state corruption
adversarial-architecture-prompt.md Checks SOLID, DRY, coupling (HIGH complexity only)
adversarial-fix-prompt.md Targeted fix agent for CRITICAL/HIGH findings
tests/test_skill_integrity.py 42 tests validating structural integrity

Modified files

File Change
subagent-driven-development/SKILL.md Full adversarial flow with complexity classification, parallel dispatch, fix loop
executing-plans/SKILL.md Inline TDD + adversarial self-check (for environments without subagents)

Design Decisions

Opt-in, not opt-out: Extra gates cost tokens and time. Users should consciously choose the quality level they need. Asked once before execution, applied to all tasks.

Parallel dispatch: Adversarial agents run simultaneously (not sequentially) to minimize wall-clock time. A HIGH complexity task spawns 3 agents in one message.

Complexity-based scaling: LOW tasks (config, simple UI) get 1 reviewer. MEDIUM (APIs, business logic) get 2. HIGH (auth, payments, data mutations) get 3. You pay only for what the task needs.

Zero context isolation: Adversarial agents receive ZERO context from the implementation session. They see only the task spec and files changed. This prevents complacency bias.

Fix loop cap: Max 3 iterations of fix → re-review. On 3rd failure, escalate to human instead of looping forever. If 3 attempts can't fix it, it's a design problem.

Separate fix agent: A fresh agent (not the original implementer) applies fixes. This avoids cognitive bias toward the original approach.

Cost Impact

Configuration Subagents per task
No gates (d) 3 (unchanged)
TDD only (b) 4
Adversarial LOW (c) 4
Adversarial MEDIUM (c) 5
Both, HIGH, no findings (a) 7
Both, HIGH, with fixes (a) ~9 worst case

Test plan

  • 42 structural integrity tests pass (python -m unittest discover -s skills/subagent-driven-development/tests/ -v)
  • Manual test: run subagent-driven-development with option (a) on a multi-task plan
  • Manual test: verify adversarial agents spawn in parallel
  • Manual test: verify fix loop resolves findings and caps at 3 iterations
  • Manual test: verify option (d) produces identical behavior to current main

🤖 Generated with Claude Code

## Problem

Long execution runs without intermediate review produce compounding errors.
The current flow (implementer → spec review → quality review) catches spec
and quality issues, but misses security vulnerabilities, unhandled edge
cases, and architecture regressions. TDD compliance is recommended but
never verified.

## Solution

Add two optional quality gates to `subagent-driven-development` and
`executing-plans`, activated by user choice before execution begins:

### 1. TDD Enforcement Gate
- Dispatches a TDD verifier after implementer reports DONE
- Verifier inspects git history to confirm Red-Green-Refactor cycle
- Three outcomes: VERIFIED, PARTIAL (proceed with note), NOT FOLLOWED (blocker)

### 2. Adversarial Review Gate
- Spawns specialized adversarial agents IN PARALLEL after quality review passes
- Agent count scales with task complexity (LOW=1, MEDIUM=2, HIGH=3):
  - Security reviewer: injections, auth bypass, data leaks
  - Edge-case reviewer: boundary values, error paths, state corruption
  - Architecture reviewer: SOLID, DRY, coupling (HIGH complexity only)
- Zero context from implementation session (fresh eyes catch more)
- Auto-fix loop: fix agent → re-review, max 3 iterations, then escalate

### Opt-in UX
User is asked ONCE before execution with 4 options:
  (a) Both TDD + Adversarial
  (b) TDD only
  (c) Adversarial only
  (d) Neither (original fast mode)

## Files

New:
- `skills/subagent-driven-development/tdd-verifier-prompt.md`
- `skills/subagent-driven-development/adversarial-security-prompt.md`
- `skills/subagent-driven-development/adversarial-edge-cases-prompt.md`
- `skills/subagent-driven-development/adversarial-architecture-prompt.md`
- `skills/subagent-driven-development/adversarial-fix-prompt.md`
- `skills/subagent-driven-development/tests/test_skill_integrity.py` (42 tests)

Modified:
- `skills/subagent-driven-development/SKILL.md` — full adversarial flow
- `skills/executing-plans/SKILL.md` — inline TDD + adversarial self-check

## Testing

42 structural integrity tests validate: file existence, frontmatter,
cross-references, opt-in gates, complexity classification, adversarial
flow controls, prompt template structure, red flags, and cost documentation.

```
python -m unittest discover -s skills/subagent-driven-development/tests/ -v
Ran 42 tests in 0.019s — OK
```

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@obra

obra commented Mar 25, 2026

Copy link
Copy Markdown
Owner

I would encourage you to build your own Adversarial Review Skills plugin. As currently built, this isn't a great fit for superpowers.

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.

2 participants