Refactor Contract
- •Preserve externally observable behavior
- •Preserve public API contracts
- •Keep the scope focused on structural/code quality improvements, not feature work.
Workflow
- •Abort immediately if there is uncommitted changes to tracked files in the repo.
- •Analyze the user's instructions and current implementation and define refactor scope and non-goals before editing.
- •Record a baseline by running existing validation (at minimum tests; include lint, typecheck, and build when available). Abort if baseline validation fails.
- •If coverage is insufficient for risky areas, add or improve tests before major structural changes.
- •For each major refactor task, spawn an agent using
#runSubagent, and ensure you orchestrate them properly. - •You are encouraged to use parallel agents to speed up development, such as when refactoring the internals of several files.
- •Prompt each agent clearly and concisely, including repo-specific coding practices when applicable.
- •Make small, incremental changes that improve readability, maintainability, cohesion, and separation of concerns.
- •Typical refactor actions include:
- •Breaking large functions/classes into focused units.
- •Renaming identifiers for clarity.
- •Removing dead or redundant code.
- •Reducing coupling and simplifying control flow.
- •Re-run relevant validation after each meaningful change and stop if regressions appear.
- •Only create branches or commits when the user asks for git operations; do not commit failing code.
Validation Checklist
- •Targeted unit/integration tests for changed behavior paths pass.
- •Full test suite (or agreed subset) passes.
- •Lint, typecheck, and build pass when those checks exist in the repo.
- •Confirm no unintended behavior or API changes were introduced.
Completion Output
- •Brief summary of activites performed.