# first review prompt
# this prompt is used for the first (comprehensive) review pass in phase 2
# launches 5 parallel agents for thorough code review
#
# available variables:
#   {{PLAN_FILE}} - path to the plan file being executed
#   {{PROGRESS_FILE}} - path to the progress log (task execution + previous reviews)
#   {{GOAL}} - human-readable goal description
#   {{DEFAULT_BRANCH}} - default branch name (main, master, trunk, etc.)
#   {{agent:<name>}} - expands to Task tool instructions for the named agent
#
# agents are defined in ~/.config/ralphex/agents/ (user) or pkg/config/defaults/agents/ (builtin)

Code review of: {{GOAL}}

Progress log: {{PROGRESS_FILE}} (contains task execution and previous review iterations)

## Step 1: Get Branch Context

Run both commands to understand what was done:
- `git log {{DEFAULT_BRANCH}}..HEAD --oneline` - see commit history (what was implemented)
- `git diff {{DEFAULT_BRANCH}}...HEAD` - see actual code changes

## Step 2: Launch ALL 5 Review Agents IN PARALLEL

All Task tool calls MUST be in the same message for parallel foreground execution.
Do NOT use run_in_background. Foreground agents run in parallel and block until all complete — no TaskOutput polling needed.

CRITICAL: Do NOT proceed to Step 3 until ALL 5 agents have returned results.

Agents to launch:
{{agent:quality}}
{{agent:implementation}}
{{agent:testing}}
{{agent:simplification}}
{{agent:documentation}}

Each agent prompt should be short — do NOT paste the diff into it. Instead, instruct each agent to:
1. Run `git diff {{DEFAULT_BRANCH}}...HEAD` and `git diff --stat {{DEFAULT_BRANCH}}...HEAD` to get the changes
2. Read the actual source files to review code in full context
3. Report problems only - no positive observations

## Step 3: Collect, Verify, and Fix Findings

After agents complete:

### 3.1 Collect and Deduplicate
- Merge findings from all agents
- Same file:line + same issue → merge
- Cross-agent duplicates → merge, note both sources

### 3.2 Verify EVERY Finding (CRITICAL)
For EACH issue (bugs, test gaps, smells, over-engineering, error handling, docs, etc.):
1. Read actual code at file:line
2. Check full context (20-30 lines around)
3. Verify issue is real, not a false positive
4. Check for existing mitigations

Classify as:
- CONFIRMED: Real issue, fix it
- FALSE POSITIVE: Doesn't exist or already mitigated - discard

IMPORTANT: Pre-existing issues (linter errors, failed tests) should also be fixed.
Do NOT reject issues just because they existed before this branch - fix them anyway.

### 3.3 Fix All Confirmed Issues
1. Fix all CONFIRMED issues (all types: bugs, tests, smells, docs, etc.)
2. Run tests and linter to verify fixes - ALL tests must pass, ALL linter issues resolved
3. Commit fixes: `git commit -m "fix: address code review findings"`

## Step 4: Signal Completion

SIGNAL LOGIC - READ CAREFULLY:

IMPORTANT: Do not decide on a signal path until you have completed Steps 1-3 in full — all agents finished, all results collected, all findings verified and acted on.

REVIEW_DONE means "this iteration found ZERO issues" - NOT "I finished fixing issues".

Path A - NO confirmed issues found:
- You reviewed the code and found nothing to fix
- Output: <<<RALPHEX:REVIEW_DONE>>>

Path B - Issues found AND fixed:
- You found issues, fixed them, and committed
- STOP HERE. Do NOT output any signal. Do NOT output REVIEW_DONE.
- The external loop will run another review iteration to verify your fixes.
- Your fixes might have introduced new issues - another iteration must check.

Path C - Issues found but cannot fix:
- Output: <<<RALPHEX:TASK_FAILED>>>

OUTPUT FORMAT: No markdown formatting (no **bold**, `code`, # headers). Plain text and - lists are fine.
