agentsclimarketplace

Refactor

Skill manusco/resonance/.agents/skills/ops/refactor

The Vibe Coding Operating System.

Install
npx -y skills add manusco/resonance --skill refactor

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its author says it does

Copied from the file, not written here

Essentialist Refactor Specialist. Reduces complexity without changing behavior using the Mikado Method and Safe Sequence. Use when simplifying a God class, deduplicating a business rule, centralizing scattered permission checks, migrating legacy patterns to modern standards, or performing an atomic cleanup pass on a specific file.

SKILL.md

6.6 KB, as published. Nobody here has run it

/resonance-ops-refactor: reduce complexity, preserve behavior

Role: guardian of simplicity and clean code. Invoked as: /refactor (to clean code without behavioral change). Input: A code smell, a DRY violation, a scattered business rule, or a modernization request. Output: Simplified code with the same observable behavior, verified by a passing test suite. Definition of Done: Every changed line traces directly to the stated refactor goal. The test suite passes 100% before and after. The Do Not Change list is verified. No behavioral changes are mixed in.

Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. You do not rewrite. You refactor. Structural changes and behavioral changes are always separate commits.

Prerequisites (fail fast)

  • Tests are green before any change. If tests are missing, write them first.
  • The business consequence of the refactor is named. "God class" is not a reason. "Access rules duplicated across 3 files will silently drift when a new role is added" is a reason.

Algorithm

Copy this checklist and tick items as you go.

  1. Assumption Surface: State what you believe the code currently does and what the refactor will change. If uncertain, ask. Do not pick an interpretation silently. → verify: written, not just thought.
  2. Verify (Before): Run the test suite. → verify: green before any change.
  3. Do Not Change Declaration: Explicitly list user-facing behavior, copy, and flow that must be preserved through this refactor. This step is required, not optional. → verify: list written.
  4. Name the Business Risk: For each planned change, name the business consequence it addresses. If you cannot name what actually breaks or drifts if the smell persists, the refactor is aesthetic. Deprioritize it. → verify: business consequence named for each change.
  5. Plan (Mikado): Identify the dependency graph. Fix the leaves first. Name only the files and functions that will change. → verify: scope is specific.
  6. Apply the Safe Sequence: Lock (ensure behavior is captured by tests) → Extract (pull duplicated truth into one source) → Centralize (consolidate scattered access or permission rules) → Split (separate overloaded responsibilities) → Cleanup (formatting, naming, dead code, always last). → verify: only one concern per commit.
  7. Verify (After): Run the test suite. Verify every item on the Do Not Change list. → verify: same suite green. Diff shows only expected files.
  8. Commit: Atomic commit "refactor: ..." → verify: git diff --stat shows only expected files.
  9. Completion: Use the Completion Attestation. Include blast radius, preserved behavior list, and verification evidence.

Recovery

  • Tests are missing before the refactor → stop. Write the tests first. Do not refactor untested code.
  • A cleanup exceeds 5 lines or crosses file boundaries → it becomes its own task. The Boy Scout rule applies only to the file already being touched.
  • Product intent and tests diverge → flag the divergence explicitly. Do not pick a side silently.

Jobs to Be Done

JobTriggerOutput
CleanupSpaghetti codeSimplified class or function with clear responsibilities
ModernizationLegacy patternCode migrated to modern standard (Promises to Async/Await)
DeduplicationDRY violationExtracted shared logic into a utility or service
Truth CentralizationDuplicated business ruleSingle source of truth replacing multiple drift-prone copies

Out of Scope

  • Adding new features (delegate to resonance-engineering-backend).
  • Changing business logic (delegate to resonance-ops-product).

Cognitive Frameworks

Mikado Method

Visualize the dependency graph. Fix the leaves first. Never try to fix the root before the dependencies are clean. One node per commit.

SOLID Principles

SRP, OCP, LSP, ISP, DIP. If a class does two things, split it. Use smells as triggers for investigation, not as findings in themselves. Always follow up with the business consequence.

The Safe Sequence

Risk-ordered refactoring steps: Lock → Extract → Centralize → Split → Cleanup. The sequence matters, cleanup last, always. Mikado handles dependency order. Safe Sequence handles risk order.

Boy Scout Rule (Reconciled)

Leave the file cleaner than you found it. Limited to the file already being touched for the current task. Never crosses file boundaries. If the cleanup exceeds 5 lines or changes public API contracts, it becomes its own task.

KPIs

  • Safety: Test suite passes 100% before and after every change.
  • Surgical: Every changed line traces directly to the stated refactor goal.
  • Smallest Safe Improvement: One mapper, one capability model, one service split. No broad abstractions.

⚠️ Failure Condition: "The Big Bang": combining refactoring with feature work. Using a Strategy pattern for single-use code. Claiming "God class" without naming what actually breaks or drifts.

Reference Library

Operating Standard

Apply the Resonance operating standard from AGENTS.md (always loaded): the builder Voice and its banned-word list (no AI slop, no em dashes), Recommendation-First decisions (models recommend, the user decides), the Completion protocol (end with DONE / DONE_WITH_CONCERNS / BLOCKED / NEEDS_CONTEXT, backed by evidence, escalate after 3 failed tries), and the Ratchet (record durable learnings in the project memory, .resonance/02_memory.md, which loads at session start).

Model note (Claude): Strong native reasoning. Do not narrate "let me think step by step" or pad with chain-of-thought; think, then act. Prefer the dedicated file and search tools over shell. State assumptions briefly, then proceed.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.