AgentSkillsCN

refactor-check-fix

以强制性验证为核心,系统性清理代码,确保所有问题均得到妥善处理。

SKILL.md
--- frontmatter
name: refactor-check-fix
description: Systematic code cleanup with MANDATORY verification. All issues must be fixed.

/refactor-check-fix [target]

Systematically refactor code. ALL identified issues must be fixed.

First: Activate Workflow

bash
mkdir -p .claude && echo '{"skill":"refactor-check","started":"'$(date -Iseconds)'"}' > .claude/active-workflow.json

Craft Standards (MANDATORY)

Refactor toward code a master craftsperson would be proud of.

The goal is code that looks like it was written by a skilled human engineer, not generated by AI.

AI Antipatterns to ELIMINATE

In addition to standard refactoring, actively hunt and remove:

  • Over-abstraction (factories/wrappers used only once → inline them)
  • Defensive paranoia (null checks where null is impossible → remove them)
  • Comment spam (// increment counter → delete it)
  • Speculative features (config options nobody uses → remove them)
  • Wrapper classes that add no value → unwrap them
  • Enterprise patterns in simple code → simplify ruthlessly

Human Craft to ACHIEVE

After refactoring, code should have:

  • Functions that do exactly one thing
  • Names so clear they don't need comments
  • No code a senior engineer would delete
  • Every abstraction justified by actual use

Test: Would someone reviewing this PR say "why is this here?" If yes, remove it.


⚠️ STRICT REQUIREMENTS - NO JUDGMENT CALLS

You MUST check for and FIX all of these issues. Not "consider" - FIX:

  1. FUNCTIONS > 30 LINES - Split them. No exceptions.
  2. FILES > 300 LINES - Split into focused modules. Create thin re-export index if needed.
  3. COMPLEXITY > 10 - Cyclomatic complexity too high. Flatten with early returns, extract helpers.
  4. VAGUE NAMES - Rename data/result/temp/item/info to meaningful names.
  5. DUPLICATE CODE - Extract to shared function. Run lens dedupe to find cross-file duplications.
  6. CROSS-FILE DUPLICATION - Same function in multiple files → extract to utils/.
  7. DEEP NESTING - Flatten with early returns.
  8. MAGIC NUMBERS/STRINGS - Extract to named constants.
  9. MISSING ERROR HANDLING - Add it.
  10. GOD FILES - Split files with multiple concerns.

FORBIDDEN (Phase will FAIL if detected):

  • Saying "could be improved" without fixing
  • Skipping issues because they're "minor"
  • Suggesting future refactorings instead of doing them
  • Leaving any identified issue unfixed
  • Tests failing after refactoring

Process

Step 0: Load Expert Guidance

Before starting, read these canon skills and apply their principles throughout:

Always load:

  1. .claude/skills/clarity/SKILL.md
  2. .claude/skills/simplicity/SKILL.md
  3. .claude/skills/design-patterns/SKILL.md
  4. .claude/skills/refactoring/SKILL.md

Load if applicable to target code:

  • Duplication patterns detected → also read .claude/skills/composition/SKILL.md

If a skill file doesn't exist (not installed in this project), skip it and continue. Reference loaded experts in your APPLIED output.

Step 0b: Learn From Past Mistakes

Read both lessons files if they exist:

  1. workflow-skills/phase-loop-lessons.md — universal patterns (ships with skills, applies to all projects)
  2. .claude/phase-loop-lessons.md — project-specific patterns (accumulated from this project's runs)

Add relevant lessons to your checklist of things to look for:

  • CODE_QUALITY entries → actively hunt for these patterns (e.g., dead exports, unused imports, redundant verification reads)
  • LOGIC entries → check for these bug patterns during refactoring (e.g., TOCTOU, missing validation)
  • AI_SMELL entries → look for single-use helpers to inline, JSDoc restating function names, impossible null checks, empty catch blocks

If a file doesn't exist, skip it and continue.

Step 1: Identify Issues

  1. Identify Issues - Find all code quality problems
  2. Fix Each One - Use Edit tool to fix
  3. Run Tests - Verify behavior preserved
  4. Report - Document what was fixed

REQUIRED Output Format

markdown
## Refactoring: [target]

ISSUES_IDENTIFIED:
- [file:line] [issue type] [description]
- [file:line] [issue type] [description]

REFACTORED:
- [file:line] [issue type] - FIXED: [what was done]
- [file:line] [issue type] - FIXED: [what was done]

ISSUES_REMAINING: 0 (must be zero)

REFACTOR_COUNT: N

TESTS_PASS: yes

APPLIED:
- [expert]: [decision]

REFACTOR_COMPLETE

Validation (Phase will FAIL if violated)

  • ISSUES_REMAINING > 0
  • TESTS_PASS: no
  • Issues identified but not in REFACTORED section
  • Any file > 300 lines after refactoring
  • Any function with cyclomatic complexity > 10 after refactoring

🛑 MANDATORY STOP

After refactoring:

  • DO NOT proceed to next phase
  • DO NOT continue with "let me also..."

Your turn ends here. Output REFACTOR_COMPLETE and STOP.