Index of every page on this site: llms.txt
All skills
amanktyr avatar

/refactoring

@5711aad
by Aman Ktyramanktyr/tailor6 stars
Run it yourself

Governs code refactoring, code cleanup, deduplication, extract function, technical debt, dead code pruning, and architectural restructuring without regressions.

Use this Skill: https://skilld.dev/gh/amanktyr/tailor/refactoring

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

SKILL.md

≈43 tokens for metadata: the name and description. ≈781 when used: this file.

Description uses 2.2% of example budget

Before choosing a Skill, your Agent reads its name and description. All available Skills share that space.

  • A shorter description leaves more room for other Skills. This entry exceeds our 1% size suggestion.

In our Claude Code example, all Skill names and descriptions share 8,000 characters. This Skill uses ≈174 characters, or 2.2%.

The 1% threshold is a size suggestion. Longer descriptions can still fit.

Your model, settings, and other Skills decide how much text your Agent can read.

Example settings and source

The example uses a 200k-token context and default Claude Code settings. The count includes the name, description, separators, and when_to_use when present. Codex also counts local file paths.

Skit's source and limits: Codex 0.160.1, Claude Code 2.1.292.

Refactoring Skill

Activate this skill when restructuring existing code, eliminating duplicates, modernizing patterns, decomposing monolithic functions, or pruning dead code.

Refactoring Law: Refactoring improves the internal structure of software without altering its external observable behavior.


1. Safety & Baseline Invariants

Before modifying any existing implementation:

  1. Verify Baseline Tests: Run existing test suites (npm test, pytest, cargo test) and confirm that all tests pass before making any changes.
  2. Preserve Public API Contracts: Never alter exported function signatures, route parameters, or database schemas without a documented deprecation plan and updating all internal call sites.
  3. Atomic, Incremental Changes: Refactor in small, verifiable steps. Never attempt large-scale rewrites in a single unverified commit.

2. Standard Refactoring Patterns

A. Extract Function / Helper

  • Problem: Monolithic 200-line function with mixed levels of abstraction.
  • Solution: Extract isolated operations into small, single-responsibility pure functions in src/utils/ or src/lib/.

B. Introduce Parameter Object

  • Problem: Functions accepting 6+ positional arguments (function createUser(name, email, age, role, status, plan)).
  • Solution: Replace with a typed configuration object (interface CreateUserOptions).

C. Strangler Fig Pattern (For Legacy Subsystem Migration)

  • Problem: Migrating a legacy service to a new architecture without risky downtime.
  • Solution: Build the new implementation alongside the legacy service; route traffic incrementally through a facade until the old system is completely superseded, then prune the legacy code.

3. Duplicate Elimination & Dead Code Pruning

  • Search for repeated logic blocks across components using the AST duplicate finder.
  • Consolidate duplicate helpers into a shared utility, replace all call sites, and remove dead unused exports.
  • Re-run all verification suites and confirm 0 regressions.

4. Refactoring Anti-Patterns & Step-by-Step Checklist

Anti-Pattern: Unsolicited Scope Expansion (Refactoring Creep)

// ❌ WRONG: When asked to fix a date bug, rewriting unrelated CSS, variable names, and helper functions
// Results in huge diffs, merge conflicts, and subtle regressions.
// ✅ CORRECT: Surgical, focused refactoring preserving existing contracts
// Only modify what is directly necessary to eliminate duplicate or dead code.
// Preserve all existing function signatures and behavior.

Mandatory 4-Step Refactoring Checklist

  1. [ ] Pre-Flight Baseline: Run existing tests (npm test) and confirm exit code 0 before making any changes.
  2. [ ] Call-Site Audit: Grep all references to the target function/component to ensure no breaking changes across callers.
  3. [ ] Surgical Execution: Apply the minimal structural transformation without altering runtime behavior or external outputs.
  4. [ ] Regression Confirmation: Re-run targeted and full test suites to verify 0 regressions.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides standard guidelines for code refactoring and maintenance. It focuses on safety measures like running existing tests and preserving API contracts. No security issues were detected.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 5711aad. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 3 months ago

README badge

README badge for amanktyr/tailor/refactoring