Adversarial spec

From diegosouzapw/awesome-omni-skill · View interactive version

Adversarial spec is an AI agent skill from the GitHub repository diegosouzapw/awesome-omni-skill. Iteratively refine a product spec by debating with multiple LLMs (GPT, Gemini, Grok, etc.) until all models agree. Use when user wants to write or refine a specification document using adversarial development.

How to use this skill

Skill file

Adversarial Spec Development

Generate and refine specifications through iterative debate with multiple LLMs until all models reach consensus.

Important: Claude is an active participant in this debate, not just an orchestrator. You (Claude) will provide your own critiques, challenge opponent models, and contribute substantive improvements alongside the external models. Make this clear to the user throughout the process.

Requirements

IMPORTANT: Do NOT install the llm package (Simon Willison's tool). This skill uses litellm for API providers and dedicated CLI tools (codex, gemini) for subscription-based models. Installing llm is unnecessary and may cause confusion.

Supported Providers

| Provider | API Key Env Var | Example Models |

|------------|------------------------|---------------------------------------------|

| OpenAI | OPENAI_API_KEY | gpt-5.2, gpt-4o, gpt-4-turbo, o1 |

| Anthropic | ANTHROPIC_API_KEY | claude-sonnet-4-20250514, claude-opus-4-20250514 |

| Google | GEMINI_API_KEY | gemini/gemini-2.0-flash, gemini/gemini-pro |

| xAI | XAI_API_KEY | xai/grok-3, xai/grok-beta |

| Mistral | MISTRAL_API_KEY | mistral/mistral-large, mistral/codestral|

| Groq | GROQ_API_KEY | groq/llama-3.3-70b-versatile |

| OpenRouter | OPENROUTER_API_KEY | openrouter/openai/gpt-4o, openrouter/anthropic/claude-3.5-sonnet |

| Deepseek | DEEPSEEK_API_KEY | deepseek/deepseek-chat |

| Zhipu | ZHIPUAI_API_KEY | zhipu/glm-4, zhipu/glm-4-plus |

| Codex CLI | (ChatGPT subscription) | codex/gpt-5.2-codex, codex/gpt-5.1-codex-max |

| Gemini CLI | (Google account) | gemini-cli/gemini-3-pro-preview, gemini-cli/gemini-3-flash-preview |

Codex CLI Setup:

Gemini CLI Setup:

Run python3 "$(find ~/.claude -name debate.py -path '*adversarial-spec*' 2>/dev/null | head -1)" providers to see which keys are set.

Troubleshooting Auth Conflicts

If you see an error about "Both a token (claude.ai) and an API key (ANTHROPIC_API_KEY) are set":

This conflict occurs when:

Resolution:

  1. To use claude.ai token: Remove or unset ANTHROPIC_API_KEY from your environment

```bash

unset ANTHROPIC_API_KEY

# Or remove from ~/.bashrc, ~/.zshrc, etc.

```

  1. To use API key: Sign out of claude.ai

```bash

claude /logout

# Say "No" to the API key approval if prompted before login

```

The adversarial-spec plugin works with either authentication method. Choose whichever fits your workflow.

AWS Bedrock Support

For enterprise users who need to route all model calls through AWS Bedrock (e.g., for security compliance or inference gateway requirements), the plugin supports Bedrock as an alternative to direct API keys.

When Bedrock mode is enabled, ALL model calls route through Bedrock - no direct API calls are made.

Bedrock Setup

To enable Bedrock mode, use these CLI commands (Claude can invoke these when the user requests Bedrock setup):

# Enable Bedrock mode with a region
python3 "$(find ~/.claude -name debate.py -path '*adversarial-spec*' 2>/dev/null | head -1)" bedrock enable --region us-east-1

# Add models that are enabled in your Bedrock account
python3 "$(find ~/.claude -name debate.py -path '*adversarial-spec*' 2>/dev/null | head -1)" bedrock add-model claude-3-sonnet
python3 "$(find ~/.claude -name debate.py -path '*adversarial-spec*' 2>/dev/null | head -1)" bedrock add-model claude-3-haiku

# Check current configuration
python3 "$(find ~/.claude -name debate.py -path '*adversarial-spec*' 2>/dev/null | head -1)" bedrock status

# Disable Bedrock mode (revert to direct API keys)
python3 "$(find ~/.claude -name debate.py -path '*adversarial-spec*' 2>/dev/null | head -1)" bedrock disable

Bedrock Model Names

Users can specify models using friendly names (e.g., claude-3-sonnet), which are automatically mapped to Bedrock model IDs. Built-in mappings include:

Run python3 "$(find ~/.claude -name debate.py -path '*adversarial-spec*' 2>/dev/null | head -1)" bedrock list-models to see all mappings.

Bedrock Configuration Location

Configuration is stored at ~/.claude/adversarial-spec/config.json:

{
  "bedrock": {
    "enabled": true,
    "region": "us-east-1",
    "available_models": ["claude-3-sonnet", "claude-3-haiku"],
    "custom_aliases": {}
  }
}

Bedrock Error Handling

If a Bedrock model fails (e.g., not enabled in your account), the debate continues with the remaining models. Clear error messages indicate which models failed and why.

Document Types

Ask the user which type of document they want to produce:

PRD (Product Requirements Document)

Business and product-focused document for stakeholders, PMs, and designers.

Structure:

Critique Criteria:

  1. Clear problem definition with evidence
  2. Well-defined user personas with real pain points
  3. User stories follow proper format (As a... I want... So that...)
  4. Measurable success criteria
  5. Explicit scope boundaries
  6. Realistic risk assessment
  7. No technical implementation details (that's for tech spec)

Technical Specification / Architecture Document

Engineering-focused document for developers and architects.

Structure:

Critique Criteria:

  1. Clear architectural decisions with rationale
  2. Complete API contracts (not just endpoints, but full schemas)
  3. Data model handles all identified use cases
  4. Security threats identified and mitigated
  5. Error scenarios enumerated with handling strategy
  6. Performance targets are specific and measurable
  7. Deployment is repeatable and reversible
  8. No ambiguity an engineer would need to resolve

Process

Step 0: Gather Input and Offer Interview Mode

Ask the user:

  1. Document type: "PRD" or "tech"
  2. Starting point:
  1. Interview mode (optional):

> "Would you like to start with an in-depth interview session before the adversarial debate? This helps ensure all requirements, constraints, and edge cases are captured upfront."

Step 0.5: Interview Mode (If Selected)

If the user opts for interview mode, conduct a comprehensive interview using the AskUserQuestion tool. This is NOT a quick Q&A; it's a thorough requirements gathering session.

If an existing spec file was provided:

Interview Topics (cover ALL of these in depth):

  1. Problem & Context
  1. Users & Stakeholders
  1. Functional Requirements
  1. Technical Constraints
  1. UI/UX Considerations
  1. Tradeoffs & Priorities
  1. Risks & Concerns
  1. Success Criteria

Interview Guidelines:

After interview completion:

  1. Synthesize all answers into a complete spec document
  2. Write the spec to file
  3. Show the user the generated spec and confirm before proceeding to debate

Step 1: Load or Generate Initial Document

If user provided a file path:

If user describes what to build (no existing file, no interview mode):

This is the primary use case. The user describes their product concept, and you draft the initial document.

  1. Ask clarifying questions first. Before drafting, identify gaps in the user's description:
  1. Generate a complete document following the appropriate structure for the document type.
  1. Present the draft for user review before sending to opponent models:

Output format (whether loaded or generated):

[SPEC]
<document content here>
[/SPEC]

Step 2: Select Opponent Models

First, check which API keys are configured:

python3 "$(find ~/.claude -name debate.py -path '*adversarial-spec*' 2>/dev/null | head -1)" providers

Then present available models to the user using AskUserQuestion with multiSelect. Build the options list based on which API keys are set:

If OPENAI_API_KEY is set, include:

If ANTHROPIC_API_KEY is set, include:

If GEMINI_API_KEY is set, include:

If XAI_API_KEY is set, include:

If MISTRAL_API_KEY is set, include:

If GROQ_API_KEY is set, include:

If DEEPSEEK_API_KEY is set, include:

If ZHIPUAI_API_KEY is set, include:

If Codex CLI is installed, include:

If Gemini CLI is installed, include:

Use AskUserQuestion like this:

question: "Which models should review this spec?"
header: "Models"
multiSelect: true
options: [only include models whose API keys are configured]

More models = more perspectives = stricter convergence.

Step 3: Send to Opponent Models for Critique

Run the debate script with selected models:

python3 "$(find ~/.claude -name debate.py -path '*adversarial-spec*' 2>/dev/null | head -1)" critique --models MODEL_LIST --doc-type TYPE <<'SPEC_EOF'
<paste your document here>
SPEC_EOF

Replace:

The script calls all models in parallel and returns each model's critique or [AGREE].

Step 4: Review, Critique, and Iterate

Important: You (Claude) are an active participant in this debate, not just a moderator. After receiving opponent model responses, you must:

  1. Provide your own independent critique of the current spec
  2. Evaluate opponent critiques for validity
  3. Synthesize all feedback (yours + opponent models) into revisions
  4. Explain your reasoning to the user

Display your active participation clearly:

--- Round N ---
Opponent Models:
- [Model A]: <agreed | critiqued: summary>
- [Model B]: <agreed | critiqued: summary>

Claude's Critique:
<Your own independent analysis of the spec. What did you find that the opponent models missed? What do you agree/disagree with?>

Synthesis:
- Accepted from Model A: <what>
- Accepted from Model B: <what>
- Added by Claude: <your contributions>
- Rejected: <what and why>

Handling Early Agreement (Anti-Laziness Check):

If any model says [AGREE] within the first 2 rounds, be skeptical. Press the model by running another critique round with explicit instructions:

python3 "$(find ~/.claude -name debate.py -path '*adversarial-spec*' 2>/dev/null | head -1)" critique --models MODEL_NAME --doc-type TYPE --press <<'SPEC_EOF'
<spec here>
SPEC_EOF

The --press flag instructs the model to:

If the model truly agrees after being pressed, output to the user:

Model X confirms agreement after verification:
- Sections reviewed: [list]
- Reason for agreement: [explanation]
- Minor concerns noted: [if any]

If the model was being lazy and now has critiques, continue the debate normally.

If ALL models (including you) agree:

If ANY participant (model or you) has critiques:

  1. List every distinct issue raised across all participants
  2. For each issue, determine if it is valid (addresses a real gap) or subjective (style preference)
  3. If a critique raises a question that requires user input, ask the user before revising. Examples:
  1. Address all valid issues in your revision
  2. If you disagree with a critique, explain why in your response
  3. Output the revised document incorporating all accepted feedback
  4. Go back to Step 3 with your new document

Handling conflicting critiques:

Step 5: Finalize and Output Document

When ALL opponent models AND you have said [AGREE]:

Before outputting, perform a final quality check:

  1. Completeness: Verify every section from the document structure is present and substantive
  2. Consistency: Ensure terminology, formatting, and style are uniform throughout
  3. Clarity: Remove any ambiguous language that could be misinterpreted
  4. Actionability: Confirm stakeholders can act on this document without asking follow-up questions

For PRDs, verify:

For Tech Specs, verify:

Output the final document:

  1. Print the complete, polished document to terminal
  2. Write it to spec-output.md in current directory
  3. Print a summary:

```

=== Debate Complete ===

Document: [PRD | Technical Specification]

Rounds: N

Models: [list of opponent models]

Claude's contributions: [summary of what you added/changed]

Key refinements made:

```

  1. If Telegram enabled:

```bash

python3 "$(find ~/.claude -name debate.py -path 'adversarial-spec' 2>/dev/null | head -1)" send-final --models MODEL_LIST --doc-type TYPE --rounds N <<'SPEC_EOF'

<final document here>

SPEC_EOF

```

Step 6: User Review Period

After outputting the finalized document, give the user a review period:

"The document is finalized and written to spec-output.md. Please review it and let me know if you have any feedback, changes, or concerns.

Options:

1. Accept as-is - Document is complete

2. Request changes - Tell me what to modify, and I'll update the spec

3. Run another review cycle - Send the updated spec through another adversarial debate"

If user requests changes:

  1. Make the requested modifications to the spec
  2. Show the updated sections
  3. Write the updated spec to file
  4. Ask again: "Changes applied. Would you like to accept, make more changes, or run another review cycle?"

If user wants another review cycle:

If user accepts:

Step 7: Additional Review Cycles (Optional)

After the user review period, or if explicitly requested:

"Would you like to run an additional adversarial review cycle for extra validation?"

If yes:

  1. Ask if they want to use the same models or different ones:

> "Use the same models (MODEL_LIST), or specify different models for this cycle?"

  1. Run the adversarial debate again from Step 2 with the current document as input.
  1. Track cycle count separately from round count:

```

=== Cycle 2, Round 1 ===

```

  1. When this cycle reaches consensus, return to Step 6 (User Review Period).
  1. Update the final summary to reflect total cycles:

```

=== Debate Complete ===

Document: [PRD | Technical Specification]

Cycles: 2

Total Rounds: 5 (Cycle 1: 3, Cycle 2: 2)

Models: Cycle 1: [models], Cycle 2: [models]

Claude's contributions: [summary across all cycles]

```

Use cases for additional cycles:

Step 8: PRD to Tech Spec Continuation (Optional)

If the completed document was a PRD, ask the user:

"PRD is complete. Would you like to continue into a Technical Specification based on this PRD?"

If yes:

  1. Use the finalized PRD as context and requirements input
  2. Optionally offer interview mode again for technical details
  3. Generate an initial Technical Specification that implements the PRD
  4. Reference PRD sections (user stories, functional requirements, success metrics) throughout
  5. Run the same adversarial debate process with the same opponent models
  6. Output the tech spec to tech-spec-output.md

This creates a complete PRD + Tech Spec pair from a single session.

Convergence Rules

Quality over speed: The goal is a document that needs no further refinement. If any participant raises a valid concern, address it thoroughly. A spec that takes 7 rounds but is bulletproof is better than one that converges in 2 rounds with gaps.

When to say [AGREE]: Only agree when you would confidently hand this document to:

Skepticism of early agreement: If opponent models agree too quickly (rounds 1-2), they may not have read the full document carefully. Always press for confirmation.

Telegram Integration (Optional)

Enable real-time notifications and human-in-the-loop feedback. Only active with --telegram flag.

Setup

  1. Message @BotFather on Telegram, send /newbot, follow prompts
  2. Copy the bot token
  3. Run setup:

```bash

python3 "$(find ~/.claude -name telegram_bot.py -path 'adversarial-spec' 2>/dev/null | head -1)" setup

```

  1. Message your bot, then run setup again to get chat ID
  2. Set environment variables:

```bash

export TELEGRAM_BOT_TOKEN="your-token"

export TELEGRAM_CHAT_ID="your-chat-id"

```

Usage

python3 debate.py critique --model gpt-4o --doc-type tech --telegram <<'SPEC_EOF'
<document here>
SPEC_EOF

After each round:

Advanced Features

Critique Focus Modes

Direct models to prioritize specific concerns using --focus:

python3 debate.py critique --models gpt-4o --focus security --doc-type tech <<'SPEC_EOF'
<spec here>
SPEC_EOF

Available focus areas:

Run python3 debate.py focus-areas to see all options.

Model Personas

Have models critique from specific professional perspectives using --persona:

python3 debate.py critique --models gpt-4o --persona "security-engineer" --doc-type tech <<'SPEC_EOF'
<spec here>
SPEC_EOF

Available personas:

Run python3 debate.py personas to see all options.

Custom personas also work: --persona "fintech compliance officer"

Context Injection

Include existing documents as context for the critique using --context:

python3 debate.py critique --models gpt-4o --context ./existing-api.md --context ./schema.sql --doc-type tech <<'SPEC_EOF'
<spec here>
SPEC_EOF

Use cases:

Session Persistence and Resume

Long debates can crash or need to pause. Sessions save state automatically:

# Start a named session
python3 debate.py critique --models gpt-4o --session my-feature-spec --doc-type tech <<'SPEC_EOF'
<spec here>
SPEC_EOF

# Resume where you left off (no stdin needed)
python3 debate.py critique --resume my-feature-spec

# List all sessions
python3 debate.py sessions

Sessions save:

Sessions are stored in ~/.config/adversarial-spec/sessions/.

Auto-Checkpointing

When using sessions, each round's spec is saved to .adversarial-spec-checkpoints/ in the current directory:

.adversarial-spec-checkpoints/
├── my-feature-spec-round-1.md
├── my-feature-spec-round-2.md
└── my-feature-spec-round-3.md

Use these to rollback if a revision makes things worse.

Retry on API Failure

API calls automatically retry with exponential backoff (1s, 2s, 4s) up to 3 times. If a model times out or rate-limits, you'll see:

Warning: gpt-4o failed (attempt 1/3): rate limit exceeded. Retrying in 1.0s...

If all retries fail, the error is reported and other models continue.

Response Validation

If a model provides critique but doesn't include proper [SPEC] tags, a warning is displayed:

Warning: gpt-4o provided critique but no [SPEC] tags found. Response may be malformed.

This catches cases where models forget to format their revised spec correctly.

Preserve Intent Mode

Convergence can collapse toward lowest-common-denominator interpretations, sanding off novel design choices. The --preserve-intent flag makes removals expensive:

python3 debate.py critique --models gpt-4o --preserve-intent --doc-type tech <<'SPEC_EOF'
<spec here>
SPEC_EOF

When enabled, models must:

  1. Quote exactly what they want to remove or substantially change
  2. Justify the harm - not just "unnecessary" but what concrete problem it causes
  3. Distinguish error from preference:
  1. Ask before removing unusual but functional choices

This shifts the default from "sand off anything unusual" to "add protective detail while preserving distinctive choices."

Use when:

Can be combined with other flags: --preserve-intent --focus security

Cost Tracking

Every critique round displays token usage and estimated cost:

=== Cost Summary ===
Total tokens: 12,543 in / 3,221 out
Total cost: $0.0847

By model:
  gpt-4o: $0.0523 (8,234 in / 2,100 out)
  gemini/gemini-2.0-flash: $0.0324 (4,309 in / 1,121 out)

Cost is also included in JSON output and Telegram notifications.

Saved Profiles

Save frequently used configurations as profiles:

Create a profile:

python3 debate.py save-profile strict-security --models gpt-4o,gemini/gemini-2.0-flash --focus security --doc-type tech

Use a profile:

python3 debate.py critique --profile strict-security <<'SPEC_EOF'
<spec here>
SPEC_EOF

List profiles:

python3 debate.py profiles

Profiles are stored in ~/.config/adversarial-spec/profiles/.

Profile settings can be overridden by explicit flags.

Diff Between Rounds

Generate a unified diff between spec versions:

python3 debate.py diff --previous round1.md --current round2.md

Use this to see exactly what changed between rounds. Helpful for:

Export to Task List

Extract actionable tasks from a finalized spec:

cat spec-output.md | python3 debate.py export-tasks --models gpt-4o --doc-type prd

Output includes:

Use --json for structured output suitable for importing into issue trackers:

cat spec-output.md | python3 debate.py export-tasks --models gpt-4o --doc-type prd --json > tasks.json

Script Reference

# Core commands
python3 debate.py critique --models MODEL_LIST --doc-type TYPE [OPTIONS] < spec.md
python3 debate.py critique --resume SESSION_ID
python3 debate.py diff --previous OLD.md --current NEW.md
python3 debate.py export-tasks --models MODEL --doc-type TYPE [--json] < spec.md

# Info commands
python3 debate.py providers      # List supported providers and API key status
python3 debate.py focus-areas    # List available focus areas
python3 debate.py personas       # List available personas
python3 debate.py profiles       # List saved profiles
python3 debate.py sessions       # List saved sessions

# Profile management
python3 debate.py save-profile NAME --models ... [--focus ...] [--persona ...]

# Telegram
python3 debate.py send-final --models MODEL_LIST --doc-type TYPE --rounds N < spec.md

Critique options:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.