---
name: cad-review-loop
description: >
  Run review/fix cycles on a generated CAD script until no major issues remain.
  Spawn a reviewer subagent, apply fixes, and repeat if needed. Use after
  a model script is authored and tests pass.
---

# CAD Review Loop

## Purpose

Catch bugs, requirement mismatches, and maintainability issues before final delivery.

## Procedure

1. Confirm `models/<model_slug>/<name>.py` exists and tests pass.
2. Spawn `cad-reviewer`:
   ```
   subagent({
     agent: "cad-reviewer",
     task: "Review models/<model_slug>/<name>.py against plans/<model_slug>/plan.md. Pytest output is attached below: <paste pytest -v output>. Check for: runtime errors, requirement mismatches, parameter validation gaps, fragile geometry assumptions, build123d API misuse, missing edge cases, and maintainability issues. Reference research/<model_slug>/implementation-brief.md for API correctness.",
     context: "fork",
     output: "reviews/<model_slug>/review-1.md"
   })
   ```
3. Read the reviewer's output.
4. If issues are flagged:
   - Fix each issue in `models/<model_slug>/<name>.py`.
   - Update tests if needed.
   - Re-run tests.
   - Commit fixes.
   - Optionally run one more review pass if edits were substantial.
5. If no major issues remain:
   - Ensure the final review fixes are committed.
   - Run `primus preview models/<model_slug>/<name>.py` after review is complete and the final commit exists.
   - This preview handoff is final-delivery only. Do not run it during exploratory spikes, scratch work, or intermediate review passes.
   - `primus preview` launches the live `ocp-vscode` browser handoff from managed Python, always prints the preview URL, and does not wait for the browser session to end.
   - If preview handoff fails, keep the reviewed code and commit intact while reporting the workflow as incomplete until preview succeeds.
   - Do not loop retries automatically in the same turn; stop after reporting the incomplete preview handoff.
6. Save review log to `reviews/<model_slug>/review-<n>.md` (increment for subsequent passes).

## Review Termination Criteria

- No hard errors or API misuse.
- All `plans/<model_slug>/plan.md` requirements addressed.
- Tests pass.
- Parameters are properly validated.
- Code is readable and maintainable.

## Workflow Completion

- Review termination criteria are met.
- Final preview handoff succeeds once after the reviewed delivery artifact is ready.
