---
name: gmd:codex-verify
description: Delegate code verification to Codex CLI as an independent second-opinion agent
argument-hint: "[phase number or description, e.g. '11' or 'auth refactor']"
allowed-tools:
  - Bash
  - Read
---
<objective>
Run Codex CLI as an independent verification agent against current code changes.
Codex reviews for bugs, security issues, incomplete implementations, and quality problems.
Present findings clearly; flag issues for fixing if critical ones are found.

This is used after GMD phase execution (or any significant code change) to get
a second-opinion review without consuming Claude's own context budget.
</objective>

<process>

## 1. Check for changes

```bash
git status --short
git diff --stat HEAD 2>/dev/null
```

If the working tree is clean (no uncommitted changes), run against the last commit instead:

```bash
git show --stat HEAD
```

## 2. Build context-aware prompt

Base prompt:
```
CODEX_PROMPT="Review the uncommitted changes in this repository. Check for: (1) bugs or logic errors, (2) security vulnerabilities (injection, auth bypass, secrets in code), (3) missing error handling, (4) incomplete or stub implementations, (5) code quality issues. Rate each finding CRITICAL / HIGH / MEDIUM / LOW. End with an overall PASS or FAIL verdict."
```

If $ARGUMENTS is provided (phase number or description), append:
```
CODEX_PROMPT="$CODEX_PROMPT Focus especially on work related to: $ARGUMENTS."
```

## 3. Run Codex verification

```bash
CODEX_OUT=$(mktemp /tmp/codex-verify-XXXXXX.txt)

codex exec \
  --full-auto \
  --ephemeral \
  --sandbox read-only \
  --output-last-message "$CODEX_OUT" \
  "$CODEX_PROMPT"

cat "$CODEX_OUT"
rm -f "$CODEX_OUT"
```

If `codex` is not found or exits non-zero, report the error and stop.

## 4. Present findings

- Print Codex's output verbatim under a `## Codex Verification Report` heading.
- Tally findings by severity.
- **If FAIL or any CRITICAL/HIGH findings:**
  - List each issue with its file reference.
  - Ask the user: "Codex found [N] issue(s). Fix before continuing? [y/n]"
  - If yes → diagnose each issue and prepare a targeted fix plan.
- **If PASS (no CRITICAL/HIGH):**
  - Confirm: "Codex review: PASSED. Proceeding."

</process>
