refactor-prototype
Refactor Prototype
Apply the refactor plan produced by the audit phase to the codebase in a single, autonomous agent session.
Your task
-
Read the audit JSON at the path provided in the Context section below (
audit_json_path). This file contains the refactor plan (e.g. goals, user stories, refactor items, and quality checks) fromnvst audit prototype. -
Understand the refactor plan — goals, recommended changes, any structured refactor items, and any specified quality checks or validation commands.
-
Apply all recommended code changes — implement each refactor item in the codebase. Follow project conventions and the existing architecture. Do not leave any planned change partially applied.
-
Run the quality checks defined in the refactor plan — for each quality check or command listed in the plan, run it and fix any issues until the checks pass. At minimum, ensure the project's typecheck (
bun run typecheck) and test suite (bun testwhen appropriate) succeed before finishing. -
Perform the full refactor autonomously — do not stop mid-way to ask the user what to do next or whether to continue. Use the refactor plan and the existing codebase as your source of truth, carry out the entire refactor in this single session, and only use interaction (if any) to report progress and final status.
-
Write a completion report artifact — after all refactor changes have been applied and quality checks have passed, write a markdown file named
it_{iteration}_refactor-report.mdinto the.agents/flow/directory at the project root. This file is the completion indicator used by downstream steps to verify that the refactor finished.The report must be in English and include, at minimum, the following top-level sections with meaningful content:
## Summary of changes— a concise summary of the key refactor changes you implemented.## Quality checks— which checks you ran (includingbun run typecheckandbun testwhen appropriate), their outcomes, and any important notes.## Deviations from refactor plan— describe any deviations from the original refactor plan in the audit JSON. If there were no deviations, explicitly writeNone.
UI / Frontend Refactor
Before applying refactor items, detect whether any item is a UI task.
- Consider it a UI task when the refactor item text, related user story description, or acceptance criteria contain keywords such as:
UI,interface,page,component,visual,button,form,layout,style, orfrontend. - If any refactor item is a UI task, apply these Impeccable skills in this exact order while executing the refactor:
polish— alignment, spacing, and consistency refinement.harden— edge cases, error states, and i18n resilience.optimize— performance improvements.normalize— design system consistency.
- Use these skills as guidance for the refactor you are already applying. Do not edit the Impeccable skill files themselves.
Context
You will receive:
iteration: current iteration (e.g.000026).audit_json_path: absolute path toit_{iteration}_audit.jsonin.agents/flow/. Read this file to get the refactor plan and quality checks.
Standalone Fallback
When iteration or audit_json_path are not injected as context variables, resolve them using the following lookup order before asking the user:
- Injected context variable — use directly if present.
state.json— read.agents/state.json(if it exists) to obtaincurrent_iteration.- Artifact files — using the resolved iteration, look for:
.agents/flow/it_{iteration}_audit.json(preferred) — use this as theaudit_json_path..agents/flow/it_{iteration}_audit.md(fallback) — use as the refactor plan source.
- Ask user — only if neither
state.jsonnor any audit artifact can be found, ask the user to provide the 6-digit iteration number (e.g.000037). Once known, retry step 3.
From the project root, you must use the following iteration artifacts under .agents/flow/ as your primary sources of truth:
.agents/flow/it_{iteration}_PRD.json— the approved PRD for this iteration (JSON source of truth)..agents/flow/it_{iteration}_progress.json— the prototype progress file that reflects what actually shipped.
Use the audit JSON as the single source of truth for what to refactor; then apply all changes and verify with the project's quality checks in this single run, finishing by writing the refactor completion report described above.