# second review prompt
# this prompt is used for the final review pass in phase 4
# focuses on critical/major issues only, uses 2 agents
#
# 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 the executor-appropriate agent invocation
#                      (Task tool for claude, spawn_agent for codex)
#
# agents are defined in ~/.config/ralphex/agents/ (user) or pkg/config/defaults/agents/ (builtin)

Second code review pass 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 Review Agents IN PARALLEL

CRITICAL: Both agent invocations MUST be issued in a single message for true parallel execution.
These agents are fully independent — no shared state, no dependencies between them, no ordering requirements.
Under claude executor: do NOT use run_in_background. Foreground Task tool calls in the same message run in parallel and block until both complete — no TaskOutput polling needed.
Under codex executor: do NOT serialize spawn_agent calls; emit them both in one response and then call wait_agent on the full set.

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

CRITICAL: Do NOT embed code or diffs in agent prompts. Keep prompts short — the agent expansions below tell each agent to run git commands themselves. Embedding large diffs into agent prompts causes slow parallel launch and burns tokens.

{{agent:quality}}
{{agent:implementation}}

Focus only on critical and major issues. Ignore style/minor issues.

## Step 3: Verify and Evaluate Findings

### 3.1 Verify Each Finding
For each issue reported:
1. Read actual code at file:line
2. Verify issue is real (not false positive)
3. Check if it's truly critical/major severity

### 3.2 Act on Verified Findings

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.

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.

IMPORTANT: A signal marker is irreversible. The moment you write one it takes effect, and you cannot retract it by explaining afterwards that you did not mean it. If you emit a marker it MUST be the final non-empty line of your output, with nothing after it. While you are still reasoning about which path applies, emit nothing.

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

Path A - NO issues found in this iteration:
- You reviewed the code and found nothing critical/major to fix
- End your output with: <<<RALPHEX:REVIEW_DONE>>>

Path B - Issues found AND fixed:
1. Fix verified critical/major issues only
2. Run tests and linter - ALL tests must pass, ALL linter issues resolved
3. Commit fixes: `git commit -m "fix: address code review findings"`
4. End your output with a plain-text summary of what you fixed. Emit NO marker at all - not REVIEW_DONE, not TASK_FAILED.
   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:
- This is only for issues you were UNABLE to fix. If you fixed and committed anything this iteration, you are on Path B - describe the remaining issues in plain text and let the next iteration handle them.
- End your output with: <<<RALPHEX:TASK_FAILED>>>

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