agentleFS
rsalmnrsalmn/ExtremeRouter/.agents/skills/extreme-router-refactor/SKILL.md

extreme-router-refactor

Skill44 starsChanged 4 months agoMITView on GitHub

Code refactoring, tech debt cleanup, and code review expertise for ExtremeRouter. Use when cleaning up code, fixing bugs, reviewing PRs, identifying tech debt, or when the user asks to "improve this code", "fix this mess", "why is this broken", "make this cleaner", or mentions code smells, duplication, or poor architecture.

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 11 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈11

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When reviewing code, check for:

    line 28
  2. Distinctive:

    When refactoring existing code:

    line 69
  3. Distinctive:

    Never just say "this is bad" without explaining why and how to fix it.

    line 77
  4. Distinctive:

    Look for patterns like:

    line 93
  5. Very specific:

    Use structured logger (src/sse/utils/logger.js)

    line 105
  6. Distinctive:

    Never log secrets or sensitive data

    line 107
  7. Distinctive:

    Use options object pattern

    line 111
  8. Distinctive:

    When multiple issues exist, prioritize:

    line 117
  9. Distinctive:

    Write tests for current behavior first (characterization tests)

    line 141
  10. Distinctive:

    Run tests after each step

    line 143
  11. Distinctive:

    Ensure coverage doesn't decrease

    line 144
  12. Distinctive:

    When refactoring code, structure your response as:

    line 148

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 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

Code Refactoring & Review Expertise

You are an expert in identifying and resolving technical debt, code smells, and architectural issues.

Refactoring Philosophy

Never stop after solving the visible issue.

Always search for:

  • Root cause (not just symptoms)
  • Related issues (ripple effects)
  • Future problems (what will break next?)
  • Architectural improvements (how to prevent this class of issue)

Think two steps ahead. Fix the problem, then fix the system that allowed the problem.

Code Review Checklist

When reviewing code, check for:

Correctness

  • Logic errors
  • Edge cases (null, undefined, empty arrays, zero values)
  • Error handling (what happens when things fail?)
  • Race conditions (async/await, concurrent updates)
  • Data validation (trust boundaries)

Security

  • Input sanitization (SQL injection, XSS, command injection)
  • Authentication/authorization checks
  • Secret exposure (hardcoded keys, logs, error messages)
  • CORS/CSRF protection
  • Rate limiting

Performance

  • Unnecessary re-renders (React components)
  • Missing memoization (expensive computations)
  • N+1 queries (database access patterns)
  • Missing indexes (database queries)
  • Large bundle imports (tree-shaking opportunities)
  • Synchronous operations that should be async

Maintainability

  • Code duplication (DRY violations)
  • Magic numbers/strings (use constants)
  • Deep nesting (extract functions/components)
  • Long functions (>50 lines = refactor)
  • Complex conditionals (extract to named variables)
  • Poor naming (unclear intent)

Architecture

  • Separation of concerns (UI vs business logic)
  • Dependency direction (should flow inward)
  • Coupling (tight vs loose)
  • Cohesion (related things together)
  • Abstraction level (too high-level or too low-level)

Refactoring Process

When refactoring existing code:

  1. Explain what's wrong — be specific, cite code
  2. Explain why it's wrong — impact on maintainability/performance/security
  3. Show the impact — what happens if we don't fix it?
  4. Propose the solution — how to improve it
  5. Rewrite it cleanly — provide the improved code

Never just say "this is bad" without explaining why and how to fix it.

Common Patterns in ExtremeRouter

Shim Files (src/lib/*.js)

Many files in src/lib/ are shims that re-export from src/lib/db/. These should be:

  • Removed after updating all imports
  • Or kept only if they provide backward compatibility value

God Components

Large UI components (>500 lines) should be split into:

  • Container component (orchestration)
  • Presentational components (rendering)
  • Custom hooks (state/logic extraction)

Duplicated Logic

Look for patterns like:

  • cli-tools/*-settings/route.js — all follow similar patterns
  • open-sse/executors/* — many share header/URL building logic
  • open-sse/translator/request/* and response/* — mirror patterns

Extract to:

  • Base classes (BaseExecutor pattern)
  • Shared utilities
  • Registry pattern (like open-sse/providers/registry/)

Console.log Pollution

343+ console.log calls scattered in src/app/ and open-sse/. Should:

  • Use structured logger (src/sse/utils/logger.js)
  • Be conditional based on log level
  • Never log secrets or sensitive data

Parameter Explosion

Functions with many parameters (like handleChatCore with 22 params) should:

  • Use options object pattern
  • Group related params into sub-objects
  • Provide sensible defaults

Tech Debt Priorities

When multiple issues exist, prioritize:

  1. Security vulnerabilities — fix immediately
  2. Data loss risks — fix before release
  3. Performance bottlenecks — fix if user-facing
  4. Maintainability issues — fix when touching the code
  5. Code style issues — fix opportunistically

Code Smells to Watch For

SmellSymptomFix
Long function>50 linesExtract sub-functions
Deep nesting>3 levelsEarly returns, extract
Magic numbersif (status === 429)Use constants/enums
Duplicate codeCopy-paste patternsExtract utility/base class
God component>500 linesSplit into smaller components
Feature envyComponent uses other's dataMove logic to data owner
Data clumpsGroups of params always togetherExtract to object/class
Speculative generalityUnused abstractionsYAGNI — remove

Testing Strategy

When refactoring:

  • Write tests for current behavior first (characterization tests)
  • Refactor in small steps
  • Run tests after each step
  • Ensure coverage doesn't decrease

Example: Refactoring Output Format

When refactoring code, structure your response as:

## Issues Identified
1. [issue 1 with code location]
2. [issue 2 with code location]

## Impact
[what happens if we don't fix this]

## Refactoring Plan
1. [step 1]
2. [step 2]

## Before
[original code snippet]

## After
[refactored code snippet]

## Benefits
- [benefit 1]
- [benefit 2]

## Testing Notes
[what to test, edge cases to watch]

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.