/sb:refactor

Specialized structural refactoring workflow — plan the change, execute without behavior drift, verify parity, then run the full review, verify, secure, and ship gate sequence.

Overview

/sb:refactor is the Silver Bullet orchestrator for structural code changes that preserve behavior — module extraction, dependency inversion, naming cleanup, dead-code removal, and architecture realignment without new features. It maps to catalog entity WF-SILVER-REFACTOR (specialized type) in the v0.53.0 APO catalog.

Refactor skips upfront clarify/specify atoms because behavior is frozen — the risk is in blast radius of structural moves, not requirements ambiguity. After execution, it runs the same post-execution gate sequence as feature work.

Standard composition:

AF-PLAN → AF-EXECUTE → AF-VERIFY → AF-REVIEW-REQUEST → AF-REVIEW → AF-REVIEW-TRIAGE → AF-VERIFY → AF-SECURE → AF-VALIDATE → AF-QUALITY-GATE → AF-BRANCH-FINISH → AF-COMPLETION-AUDIT → AF-SHIP

The post-execution sequence is the catalog's review, verify, secure, and ship gates — expanded as atomic flows above, not a separate user-facing workflow name. See Post-Execution Sequencing.

ℹ
Behavior must not change. If the request adds features, changes APIs, or alters user-visible behavior, route to /sb:feature instead. Refactor assumes existing tests are the parity contract.

When to Use

Entry trigger signals for /sb:refactor and refactor:

  • Module extraction, package reorganization, or layer boundary cleanup
  • Rename sweeps, dead-code removal, or dependency graph simplification
  • Pattern migration (callbacks → async/await, class → functional) with parity tests
  • Technical debt paydown that touches multiple files but adds no features

Catalog Composition

PhaseAtomic flowsOutcome
Pre-executionAF-PLAN → AF-EXECUTE → AF-VERIFYRefactor plan, structural changes, parity verification
Review gatesAF-REVIEW-REQUEST → AF-REVIEW → AF-REVIEW-TRIAGEArtifact review, triage, and fix loop
Ship gatesAF-VERIFY → AF-SECURE → AF-VALIDATE → AF-QUALITY-GATE → AF-BRANCH-FINISH → AF-COMPLETION-AUDIT → AF-SHIPFinal verification, security, quality gate, branch hygiene, ship

Post-Execution Gates

After AF-EXECUTE completes, the refactor workflow expands into the canonical post-execution gate chain shared with /sb:feature and /sb:bugfix:

  • Review gates — AF-REVIEW-REQUEST, AF-REVIEW, AF-REVIEW-TRIAGE for structural change review
  • Verify gate — AF-VERIFY confirms full test suite and no behavior regression
  • Secure gate — AF-SECURE for security-sensitive structural moves (auth paths, crypto, input handling)
  • Ship gates — AF-VALIDATE, pre-ship AF-QUALITY-GATE, AF-BRANCH-FINISH, AF-COMPLETION-AUDIT, AF-SHIP

AF-UI-QUALITY inserts only when runtime evidence shows UI deliverables in scope.

Example Invocation

/sb:refactor Extract the billing module from monolith core into packages/billing with no API changes

Silver Bullet routes to WF-SILVER-REFACTOR. Planning documents module boundaries and migration steps. Execution moves code with import updates. Initial verify confirms test parity. Review gates examine structural diff. Ship gates pass and the refactor merges.