// =========================================================================== // polish — architecture-review → blueprint (iterate, per review phase) → // implement → validate → code-review → (blueprint loop) | commit // For a large architecture review that can't be planned in one pass: // plan each review phase sequentially, each plan building on the // ones before it, then implement/validate/review the lot. // =========================================================================== import { acts, defineWorkflow, gitCommitOutcome, handleToString, type PromptFn, produces, } from "@juicesharp/rpiv-workflow/registration"; import { IMPLEMENT_PLANS_FANOUT, latestPlans, REVIEW_PHASE_ITERATE } from "../built-ins/index.ts"; import { codeReviewGate } from "./shared.ts"; /** * Hand the single validate session EVERY plan from the latest blueprint pass * (`latestPlans`). The runner's default rolling-primary — and a plain * `reads: ["plans"]`, which only reads `.at(-1)` — would point validate at the * LAST plan alone, leaving earlier phases unvalidated. A `prompt` stage owns * its whole message, so the `/skill:validate` prefix is explicit. */ const VALIDATE_PLANS_PROMPT: PromptFn = ({ state, cwd }) => { const paths = latestPlans(state, cwd) .flatMap((o) => o.artifacts) .filter((a) => a.handle.kind === "fs") .map((a) => handleToString(a.handle)); return `/skill:validate ${paths.join(" ")}`; }; const polishWorkflow = defineWorkflow({ name: "polish", description: "Architecture-review-driven polish: review → per-phase blueprint (sequential, accumulating) → implement → validate → code-review → commit. Best when a large architecture review can't be planned in one pass and each phase's plan must build on the ones before it.", start: "architecture-review", stages: { "architecture-review": produces(), blueprint: produces({ loop: REVIEW_PHASE_ITERATE }), implement: acts({ loop: IMPLEMENT_PLANS_FANOUT, reads: ["plans"] }), validate: produces({ prompt: VALIDATE_PLANS_PROMPT }), "code-review": produces(), commit: acts({ outcome: gitCommitOutcome }), }, edges: { "architecture-review": "blueprint", blueprint: "implement", implement: "validate", validate: "code-review", // Backward edge: code-review → blueprint re-plans (implement needs a plan). // The iterate stage re-runs over every review phase; bounded by the // runner's default maxBackwardJumps (3 → up to 4 review iterations) // under the absolute per-stage maxLaps ceiling (default 8; both // budgets fresh per invocation — a resume re-opens the loop). "code-review": codeReviewGate(), commit: "stop", }, }); export { polishWorkflow };