## Workflow

Every CAD generation request follows four stages in order:

Begin with Stage 1 — Goal Alignment.

### Stage 1 — Goal Alignment
Trigger: a new model request arrives and no approved `plans/<model_slug>/plan.md` exists for it.
Action: invoke skill `cad-goal-alignment`.
- Prefer `npm:@juicesharp/rpiv-ask-user-question` while concrete design requirements are still missing and UI support is available.
- Interview relentlessly to reach shared understanding before drafting `plans/<model_slug>/plan.md`.
- Walk the design tree branch-by-branch by asking one targeted question at a time and waiting for the answer before asking the next question.
- For each question, include a recommended answer to speed up decision-making and reveal tradeoffs early.
- If a question can be answered by inspecting repository context or prior workflow artifacts, inspect first instead of asking the user.
- Drive toward the core requirement buckets: user intent and context, dimensions and tolerances, material intent, parameterization, export requirements, and success criteria.
- Use recommended options, notes, and submit/review flow when they help the user make explicit decisions quickly.
- Use previews selectively for choices that are easier to compare visually, such as topology, geometry, export shape, or parameterization.
- Preserve custom-answer/chat escape hatches so structured questioning stays structured-first, not structured-only.
- If questionnaire UI is unavailable or the tool reports `no_ui`, fall back to normal prose clarification while keeping the same decision policy.
- Ask targeted follow-up questions only for blocking gaps. Carry non-blocking uncertainty into the synthesized plan as explicit open questions instead of guessing.
- Synthesize `plans/<model_slug>/plan.md` only after shared understanding is confirmed.
- Turn the final `plans/<model_slug>/plan.md` into a clean synthesis of decisions, constraints, and open questions instead of raw questionnaire transcripts.
Output: `plans/<model_slug>/plan.md` (goals, constraints, and open questions only; no build123d specifics).

Outside Stage 1, preserve the normal research, authoring, and review flow by default.
- Reuse `npm:@juicesharp/rpiv-ask-user-question` only when later-stage ambiguity blocks progress or materially changes artifact shape, constraints, interfaces, or outputs.
- Keep later-stage questionnaire use opportunistic and narrowly scoped to the blocking decision.
- If structured UI is unavailable or the tool reports `no_ui`, fall back to normal prose clarification and keep the same blocking-only decision policy.

### Stage 2 — Research
Trigger: `plans/<model_slug>/plan.md` is approved and implementation is requested.
Action: invoke skill `build123d-research`.
Output: research artifacts in `research/<model_slug>/`.

### Stage 3 — Script Authoring
Trigger: research artifacts exist for the current plan.
Action: invoke skill `cad-script-authoring`.
Output: model script in `models/<model_slug>/` + tests in `tests/<model_slug>/`.

### Stage 4 — Review Loop
Trigger: a model script exists, tests pass, and it has not been reviewed.
Action: invoke skill `cad-review-loop`.
- Final workflow completion requires one successful preview handoff after the reviewed delivery artifact is ready.
- Run the final preview handoff only after review fixes are committed and the delivery artifact is ready, not during exploratory spikes, scratch work, or intermediate runs.
- Use the live build123d result for that handoff via `primus preview models/<model_slug>/<name>.py`; the command attempts browser open, always prints the preview URL, and does not block on the viewer session after launch.
- Do not trigger the final preview handoff during exploratory spikes, scratch work, or intermediate runs.
- If preview launch fails, keep the final code and commit intact but report the workflow as incomplete until preview succeeds.
Output: reviewed, fixed, and committed final script plus exactly one successful preview handoff for final delivery.
