Skip to content

/wbRefactor — Exhaustive Simulation () ​

/wbRefactor is the surgeon. Its job is structural surgery on a specific file — change the shape of the code (decomposition, rename, extraction, pattern application) without changing what it does. The boundary that defines the command: behavior under tests stays identical; structure under reading changes.

Read this if you want to know why /wbRefactor has no flags, what counts as "behavior-preserving," and where refactor ends and /wbClean (cleanup) or /wbWork (feature change) begins.


1. Role & target ​

AspectBehavior
RoleThe Surgeon — structural transformation of one file or one tightly-coupled set of files.
TargetA specific file path; optionally a comma-separated set of files that will be transformed together atomically.
Cell scopeNone directly. /wbRefactor does not mutate plan cells; the work it does should usually correspond to a plan row that /wbWork calls into.
Side effects allowedEditing the targeted file(s); running existing tests to confirm behavior preservation.
Side effects forbiddenAdding new functionality; expanding scope to "while I'm here" cleanup; touching files outside the explicit target list.

The "no scope creep" rule is what separates /wbRefactor from /wbClean. A surgeon doesn't decide mid-operation to also fix the patient's posture. If the refactor surfaces an unrelated mess, the agent names it (logs it as a candidate plan row) but does not act on it.


2. Argument resolution matrix ​

FormExampleWhat /wbRefactor does
Single fileCommand: /wbRefactor core2/packages/wb-core/src/WBC.jsSurgical transformation of one file. Most common shape.
Comma-separatedCommand: /wbRefactor src/WBC.js,src/WBCSlot.jsAtomic transformation of two tightly-coupled files. Both succeed or both revert.
Free-text intentCommand: /wbRefactor "extract the parser from WBC.js"Refused. Refactor is target-required. Intent without a file target is a planning conversation, not a refactor.
DirectoryCommand: /wbRefactor core2/packages/wb-core/src/Refused. Refactor is file-level by design.

The directory refusal is intentional. A "refactor everything in this directory" command is really a planning operation that should produce multiple plan rows, each refactoring a specific file. /wbRefactor keeps its scope narrow on purpose.


3. Flag matrix ​

/wbRefactor has no flags. The lack of flags is the design statement: every refactor is behavior-preserving on a specific target. There is no profile to choose, no severity to filter, no mode to toggle. The only question is "which file?" — and that's an argument, not a flag.

What you might wantWhat to use instead
Refactor and fix lint warnings/wbRefactor first, /wbClean after. Two commits, two clean intentions.
Refactor and add a feature/wbWork --id="<row>" against a plan row that says so. Don't bundle.
Refactor that the tests don't coverAsk the question first. /wbRefactor against untested code is dangerous; the agent will warn but proceed if explicitly told to.
Multi-file transformationComma-separated target. Atomic.

4. Pipelines (the agent-native scenarios) ​

📋/wbRefactor Exhaustive Simulation
The deferred WBC.js decomposition (when the architecture conversation has happened)/wbRefactor core2/packages/wb-core/src/WBC.js
> /wbRefactor core2/packages/wb-core/src/WBC.js
[SYSTEM] Target: core2/packages/wb-core/src/WBC.js
[SCAN] Reading file (412 lines, 8 exports)...
[TEST] Running existing tests against this file...
core2/packages/wb-core/tests/WBC.spec.js: 14 passed.
[BASELINE] Test baseline captured. Refactor must preserve.
[ANALYZE] Identifying surgical decomposition candidates:
- Lines 14-89: parser logic (could become WBCParser.js)
- Lines 91-178: orchestrator (stays in WBC.js)
- Lines 180-302: render delegate (could become WBCRenderer.js)
- Lines 304-412: state machine (could become WBCState.js)
[REFACTOR PROPOSAL]
Split into 4 files:
- src/WBC.js: orchestrator (slim, ~90 lines)
- src/WBCParser.js: parser (~75 lines)
- src/WBCRenderer.js: render delegate (~120 lines)
- src/WBCState.js: state machine (~110 lines)
[CONFIRM] Proceed with this decomposition? [y/N] > y
[EDIT] Writing 4 files...
Updating imports in 6 consumer files (no behavior change)...
[TEST] Re-running existing tests...
core2/packages/wb-core/tests/WBC.spec.js: 14 passed.
core2/packages/wb-core/tests/*.spec.js: 28 passed (other suites).
[OK] Behavior preserved. Refactor complete.
[NOTE] No new functionality added. No tests added or removed.
Plan row 3's Done is for /wbWork to mark, not /wbRefactor.
⚠️ Note: The active plan in this workspace defers row 3 (WBC.js decomposition) pending architectural discussion. *After* that discussion happens and a clear shape emerges, `/wbRefactor` is the right tool to execute it:

💠 Pipeline The deferred WBC.js decomposition (when the architecture conversation has happened) ​

The active plan in this workspace defers row 3 (WBC.js decomposition) pending architectural discussion. After that discussion happens and a clear shape emerges, /wbRefactor is the right tool to execute it:

💠 Pipeline The atomic two-file rename ​

A function moved from one file to another, and both files need to be edited together to preserve the import graph:

💠 Pipeline The "refactor surfaces a separate problem" path ​

Mid-refactor, the agent notices something unrelated:


5. Edge cases & refusals ​

TriggerWhat /wbRefactor does
No targetHalt. ❌ /wbRefactor needs a file or comma-separated file list.
Directory targetHalt. ❌ Refactor is file-level. Use /wbPlan to break a directory into rows.
Free-text intentHalt. ❌ Refactor needs a target file, not just intent.
Target file has no test coverageWarn explicitly. Asks user to confirm proceeding. Auto-rollback isn't possible without a baseline.
Multi-file target where some files don't existHalt. Atomic refactor refuses partial targets.
Tests fail after refactorAuto-revert all edits. Reports which test failed. The atomic guarantee is the safety.
User asks to add a feature mid-refactorRefuse. Suggests /wbWork --id="<row>" against a plan row, not bundling into the refactor.
Refactor surfaces unrelated issuesLogs them as follow-ups with suggested next commands. Does not act.

The pattern: /wbRefactor is behavior-preserving by contract. No flags, file-level only, atomic across multi-file targets, auto-reverts on test failure, refuses to expand scope. The only question it answers is "can the same behavior be expressed with a clearer structure?" Anything else is a different command.