agentleFS
CreativeActtechCreativeActtech/llm-skills/skills/example-skill/refactor-simplify/SKILL.md

refactor-simplify

Skill2 starsChanged 7 months agoMITView on GitHub

Reduce complexity, eliminate anti-patterns, and improve structural clarity in existing code. Use when requesting "clean up this", "make it more readable", or "reduce cyclomatic complexity". Do NOT use for feature additions, security hardening, or performance profiling without explicit refactoring scope.

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 7 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do NOT use for adding new business logic, fixing runtime bugs, or optimizing performance without structural cleanup

    line 21
  2. Distinctive:

    Do NOT use when the user explicitly requests "keep it as-is, just add comments"

    line 22
  3. Distinctive:

    IF deep nesting → extract guard clauses, early returns, or strategy patterns.

    line 30
  4. Distinctive:

    IF duplicated logic → extract reusable functions or utility modules.

    line 31
  5. Distinctive:

    IF large functions → decompose into single-responsibility units.

    line 32
  6. Distinctive:

    IF implicit state → make dependencies explicit via parameters or DI.

    line 33
  7. Very specific:

    Ensure refactored code produces identical outputs for identical inputs.

    line 39
  8. Distinctive:

    If the code is already well-structured and no meaningful simplification exists, respond with:

    line 61
  9. Very specific:

    If the user's request conflicts with framework conventions (e.g., forcing procedural style in OOP), warn: "⚠️ Proposed simplification …

    line 71

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Refactor & Simplify

Focused transformation workflow targeting readability, modularity, and long-term maintainability.

🎯 When to Use

  • User shares deeply nested, overly long, or highly coupled code
  • User asks to "simplify this", "extract methods", or "improve readability"
  • Code exhibits duplicated logic, magic numbers, or inconsistent naming
  • Do NOT use for adding new business logic, fixing runtime bugs, or optimizing performance without structural cleanup
  • Do NOT use when the user explicitly requests "keep it as-is, just add comments"

🧠 Core Workflow

Step 1 — Measure Complexity Identify high-complexity areas: functions > 30 lines, nesting > 3 levels, cyclomatic complexity > 10, or tightly coupled classes. Log exact metrics.

Step 2 — Apply Structural Simplification

  • IF deep nesting → extract guard clauses, early returns, or strategy patterns.
  • IF duplicated logic → extract reusable functions or utility modules.
  • IF large functions → decompose into single-responsibility units.
  • IF implicit state → make dependencies explicit via parameters or DI.

Step 3 — Enforce Consistency Standardize naming (variables, functions, classes), align formatting, remove dead code, and replace magic numbers/strings with named constants or enums.

Step 4 — Validate Behavioral Equivalence Ensure refactored code produces identical outputs for identical inputs. IF public interfaces must change → wrap in compatibility layer and explicitly mark @deprecated.

Step 5 — Output & Diff Return before/after comparison, list of applied transformations, and any required follow-up actions (e.g., updating call sites).

📋 Output Format

Section 1 — Refactor Report

{
  "status": "success | partial | error",
  "complexity_before": {"lines": 0, "nesting_depth": 0, "functions_extracted": 0},
  "complexity_after": {"lines": 0, "nesting_depth": 0, "functions_extracted": 0},
  "changes_applied": ["early_returns", "extract_method", "remove_duplication"],
  "breaking_changes": false
}

Section 2 — Refactored Code Provide the cleaned code block. Add // REFACTOR: or # REFACTOR: comments above modified sections. Keep structure flat and intent explicit.

⚠️ Fallback Behavior If the code is already well-structured and no meaningful simplification exists, respond with:

{
  "status": "partial",
  "message": "Code already meets modern readability standards. No structural refactoring required.",
  "suggestion": "Consider adding type annotations, documentation, or test coverage instead."
}

If the user's request conflicts with framework conventions (e.g., forcing procedural style in OOP), warn: "⚠️ Proposed simplification conflicts with detected framework paradigms. Proceed only if intentional."

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.