AgentSkillsCN

refactor-cleaner

在重构代码、优化包体积与提升性能,或在正式发布前,安全地查找并移除冗余代码、未使用的导出项、文件及依赖项,并尽可能降低风险。建议分批小规模地实施变更,并通过构建与测试加以验证。

SKILL.md
--- frontmatter
name: refactor-cleaner
description: Find and safely remove dead code, unused exports/files/dependencies, and consolidate duplicates with minimal risk. Use during refactors, bundle-size/performance cleanups, or before releases; apply changes in small batches and verify with build/tests.

Refactor Cleaner

Goal

  • Reduce codebase surface area safely: delete unused code, dependencies, exports, and files; consolidate duplicates; keep behavior unchanged.

Workflow

  1. Define scope and safety constraints (what is allowed to change, public API boundaries, and time budget).
  2. Collect evidence before deleting:
    • Search usages with fast text search.
    • Run dead-code detectors and linters when available.
  3. Classify findings by risk:
    • Safe: clearly unused internal exports, unreachable code, unused dependencies.
    • Careful: dynamic imports, reflection, config-driven usage, string-based lookups.
    • Risky: public APIs, plugin hooks, framework conventions, runtime-only references.
  4. Apply changes in small batches:
    • Remove one category at a time (deps → exports → files → duplicates).
    • Run build/typecheck/tests after each batch.
  5. Record deletions:
    • Append a concise entry to the project's deletion log if it exists; otherwise, summarize removals in the final output.
  6. Stop and ask when evidence is ambiguous.

Output

  • Summarize what was removed and why.
  • Call out any risky candidates that need human confirmation.
  • List verification steps and results (build/test commands run).

Reference

  • Read references/refactor-cleaner.md for detailed commands, checklists, and templates.