refactor-module
Refactor a module through small behavior-preserving transformations and a clear safety net.
Files1
View on GitHubSKILL.md.claude/skills/refactor-module/SKILL.md
GitHub<!-- Generated by mstack from Misbah's Build Like This workflow. Regenerate instead of editing. -->
refactor-module
Improve the requested module's structure without changing its observable behavior or expanding adjacent scope.
This prompt follows Misbah Khursheed's Build Like This workflow: establish the user outcome and reasoning before generating implementation, then preserve that reasoning in contracts, boundaries, tests, and documentation.
Project identity and sources of truth
The repository where this prompt is installed is the host project being built. Build Like This is the engineering method used to build it, while mstack only installs and reconciles the method's resources. Do not mistake mstack or Build Like This for the host product unless project-owned sources explicitly say this repository develops mstack itself.
Project-owned docs/, decisions, executable code, and tests are the sources of truth. .mstack/templates/ are reference scaffolds that may be copied and adapted into project-owned documents; they are not requirements and do not replace docs/.
Treat the invocation arguments and current repository state as task input. Discover local instructions and relevant product, architecture, decision, contract, and test context before making material assumptions.
Method
- Name the concrete change pain, responsibility/coupling problem, preserved invariants, and success signal.
- Map callers, dependencies, side effects, contracts, ownership, and current test evidence.
- Add characterization tests for important behavior that lacks a practical safety net.
- Design and apply a sequence of small compiling/testable transformations toward the owning boundary.
- Remove obsolete paths only after callers migrate; resist abstractions without stable shared semantics.
- Compare before/after dependencies and run focused plus broader regression checks.
Deliverables
- Refactored code with behavior-preserving tests and no unrelated semantic changes.
- Short before/after explanation of responsibilities and dependency direction.
- Verification evidence and intentionally deferred cleanup.
Constraints
- Do not mix dependency upgrades or feature behavior into the structural change.
- Do not optimize for line/file count over cohesion and readability.
- Do not create a generic abstraction solely to remove superficial duplication.
Delegation and parallel safety
- For a material lifecycle task, the active lead must delegate at least one bounded specialist lane when subagents are available; prefer two or more concurrent lanes only when their evidence or file ownership is independent.
- The active lead owns acceptance criteria and final integration. Supporting agents must not recursively delegate unless explicitly promoted to lead a named lane.
- Give each delegate distinct inputs, outputs, and ownership. Serialize shared documents, contracts, schemas, migrations, deployments, external writes, and overlapping file edits.
- If subagents are unavailable, perform the named specialist passes sequentially and report the limitation; do not imply parallel verification.
- Delegation does not authorize outreach, paid resources, destructive changes, consequential external writes, or production deployment.
Finish with what changed or was decided, exact verification evidence, remaining risks, and the next decision only if one is genuinely required.
User arguments: $ARGUMENTS