mcpbeat Sign in

Nw Refactor Agent Skill

Applies the Refactoring Priority Premise (RPP) levels L1-L6 for systematic code refactoring. Use when improving code quality through structured refactoring passes.

1k tokens
context cost
the whole folder, loaded on every use
1
files
instructions only
0
copies elsewhere
how many repositories repackaged it
588
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/nWave-ai/nWave --skill nw-refactor

The instruction itself

14 sections, as written by the author

NW-REFACTOR: Systematic Code Refactoring

Wave: CROSS_WAVE

Agent: Crafty (nw-software-crafter)

Command: *refactor

Overview

Applies the Refactoring Priority Premise (RPP) — 6-level hierarchy L1 Readability|L2 Complexity|L3 Responsibilities|L4 Abstractions|L5 Design Patterns|L6 SOLID++. For complex multi-class refactorings, agent applies Mikado Method internally.

Execution Model — Batch-Then-Verify (default, unconditional)

/nw-refactor runs batch-then-verify by default, regardless of test-suite speed:

  • Cascade governs PLANNING ORDER only — analyze and plan lower levels before higher (L2 transformations build on L1, L3 on L2, etc.). The cascade is a planning discipline, not a test-gating sequence.
  • Edits applied as one coherent batch — apply all planned L1-L6 transformations in a single editing session. NO interleaved test runs between levels.
  • Run the test suite exactly ONCE, at the very end, after all L1-L6 edits.
  • If RED after the batch: diagnose the breakage and fix the production code. Do NOT modify tests to make them pass. A test that must change to pass means either (a) the refactor altered observable behavior — revert that transformation — or (b) the test encoded an implementation detail rather than behavior — flag this to the user explicitly before touching it. Tests changing during a refactor is a signal, not a step.

Legacy incremental variant (opt-in only): the nw-progressive-refactoring skill documents the incremental L1→test→L2→test cycle. It is NOT the default — use it only when explicitly requested. Anchor: feedback_refactor_batch_when_test_suite_slow_2026_05_19 (the prior "only batch when suite slow" conditional is removed — batch is now unconditional).

Context Files Required

  • src/\* - Production codebase
  • tests/\* - Test codebase

Agent Invocation

@nw-software-crafter

Execute \*refactor for {target-class-or-module}.

Context Files:

  • src/\*
  • tests/\*

Configuration:

  • level: 3 # Shorthand: --from=1 --to=3 (RPP range)
  • from: 1 # Start RPP level (default: 1)
  • to: 3 # End RPP level (default: same as level)
  • scope: module # file/module/project
  • method: extract # extract/inline/rename/move
  • mikado_planning: false # Use Mikado Method for complex refactorings

Progress Tracking

The invoked agent MUST create a task list from its workflow phases at the start of execution using TaskCreate. Each phase becomes a task with the gate condition as completion criterion. Mark tasks in_progress when starting each phase and completed when the gate passes. This gives the user real-time visibility into progress.

Success Criteria

  • [ ] Code quality metrics improved (measured before/after)
  • [ ] L1-L6 transformations planned in cascade order, applied as one batch
  • [ ] Test suite run exactly once, at the end — GREEN
  • [ ] If RED after batch: production code fixed (tests NOT modified to pass)
  • [ ] Technical debt reduced measurably

Next Wave

Handoff To: {invoking-agent-returns-to-workflow}

Deliverables: Refactored codebase with quality improvements

Examples

Example 1: Module-level readability refactor

/nw-refactor src/auth/token_manager.py --level=2 --scope=module

Crafty applies RPP L1-L2: rename ambiguous variables|extract magic numbers into constants|remove dead code (L1), then simplify conditionals|extract long methods (L2).

Example 2: SOLID-level design refactor

/nw-refactor src/billing/ --level=6 --scope=module --mikado_planning=true

Crafty uses Mikado Method for multi-class refactoring, applies dependency inversion|interface segregation across billing module.

Example 3: RPP range sweep (L1-L3)

/nw-refactor src/des/domain/ --from=1 --to=3 --scope=module

Sweeps L1 readability|L2 complexity|L3 responsibility smells. Cascade governs planning order (analyze L1 before L2 before L3); edits applied as one batch; suite run once at the end.

Example 4: Targeted single-level refactor

/nw-refactor src/des/cli/verify.py --level=3 --scope=file

Targets L3 responsibility smells only (Large Class, Feature Envy, Shotgun Surgery). Assumes L1-L2 already clean.

Expected Outputs

src/*                              (refactored production code)
tests/*                            (refactored test code)
docs/refactoring/
  refactoring-log.md
  quality-metrics.md

Other skills for the same job

different authors, same section of the catalogue
Receiving Code Review
by ZhanlinCui
×7

Use when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation

2k tokens
Requesting Code Review
by ZhanlinCui
×6

Use when completing tasks, implementing major features, or before merging to verify work meets requirements

2k tokens
Git Commit
by github
vendor ×3

Execute git commit with conventional commit message analysis, intelligent staging, and message generation. Use when user asks to commit changes, create a git commit, or mentions "/commit". Supports: (1) Auto-detecting type and scope from changes, (2) Generating conventional commit messages from diff, (3) Interactive commit with optional type/scope/description overrides, (4) Intelligent file staging for logical grouping

799 tokens
Github Code Review
by ComeOnOliver
×3

Comprehensive GitHub code review with AI-powered swarm coordination

13k tokens
Karpathy Guidelines
by hyyhf
×3

Behavioral guidelines to reduce common LLM coding mistakes. Use when writing, reviewing, or refactoring code to avoid overcomplication, make surgical changes, surface assumptions, and define verifiable success criteria.

629 tokens
Code Reviewer
by google-gemini
vendor ×2

Use this skill to review code. It supports both local changes (staged or working tree) and remote Pull Requests (by ID or URL). It focuses on correctness, maintainability, and adherence to project standards.

795 tokens
Agent MD Refactor
by softaworks
×2

Refactor bloated AGENTS.md, CLAUDE.md, or similar agent instruction files to follow progressive disclosure principles. Splits monolithic files into organized, linked documentation.

4k tokens
Commit Work
by softaworks
×2

Create high-quality git commits: review/stage intended changes, split into logical commits, and write clear commit messages (including Conventional Commits). Use when the user asks to commit, craft a commit message, stage changes, or split work into multiple commits.

2k tokens

How to use it

Copy the folder

Take nwave-ai/nw-refactor from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.