/wbRefactor — Command Hub
/wbRefactor is the WB-Labs structural surgeon. It analyzes code structure and executes targeted improvements — extracting functions, splitting files, removing dead code, modernizing syntax — while preserving external behavior exactly. Unlike /wbDebug which fixes broken code, /wbRefactor improves working code without changing what it does.
🎯 Strategic Position
/wbRefactor exists because the default failure mode of cleanup is "while I'm here" scope creep. The command enforces a strict contract: public signatures, error behavior, observable side effects, and performance characteristics are preserved; only internal structure changes. It should only run when an audit has flagged structural debt, tests exist and pass, and no debug reports are open on the target.
- After an audit flags structural debt — the audit-refactor-test-audit bracketing sequence.
- One file at a time — entire package refactors in one go are dangerous. Split into file-level operations.
- In the polish phase — not during feature work, not in response to a bug.
🛠️ Operating Modes
| Mode | Trigger | Output |
|---|---|---|
| Refactor | /wbRefactor <file-or-folder> | Structural transformation with a before/after comparison report |
| Self-correct | /wbRefactor <previous_output_file> | Verifies and repairs a prior refactor report in place |
✅ What a useful refactor report contains
- A before/after comparison — what structural changes were made, with file references.
- An explicit statement that the external API remains identical — props, emits, error behavior preserved.
- A list of what was preserved — public signatures, error behavior, side effects, performance.
- A list of what was changed — internal structure, naming, dead code, formatting.
- The verification command — typically
/wbTest <target>to confirm tests still pass.
🚫 What it cannot do
| Not this | Use instead |
|---|---|
| Fix broken code or investigate bugs | /wbDebug |
| Add new features | Describe the feature directly |
| Clean dead code without behavior context | /wbClean |
| Rename a function used across the monorepo | /wbPlan — coordinate the blast radius |
| Convert Vuetify components to wbc-ui2 | /wbToWBC |
📚 Reading Order
- ELI5 — the one-paragraph mental model.
- Practical — step-by-step on a real project.
- Expert — architecture, edge cases, and when NOT to use.
- Examples — annotated transcripts from actual sessions.
- Exhaustive simulation · Live demo.
🔗 Related
wbRefactor.md— the command reference this hub orients you around./wbAudit— the mandatory before-and-after gate for any refactor./wbDebug— fix bugs; do not refactor buggy code./wbToWBC— specialized Vuetify-to-wbc-ui2 migration./wbTest— confirm behavior parity after refactor./wbNext— ranked next action after refactor.
Quick Reference
/wbRefactor <file-or-folder> # restructure, preserve behavior← Home · Commands · Install | wb-flow on npm · flow.wbc-ui.com · wi-bg.com
