plugins/code-cleanup/skills/code-cleanup-skill/SKILL.md
清理项目中的未引用模块、未使用组件与死代码。支持 JS/TS、Python、Go、Java、PHP、Ruby、Rust、C/C++ 等多语言项目。只要用户提到"代码清理""未引用""未使用组件""死代码""瘦身项目""删除无用文件""清理历史备份文件(copy/bf/old)",都应优先使用本 Skill。即使用户没有明确说"Skill",但目标是识别或清理无用代码,也应触发。
npx skillsauth add protagonistss/ithinku-plugins code-cleanup-skillInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
用于在任何项目中执行"安全优先"的清理分析,输出可执行的候选变更而不是直接删除文件。
当前以 JS/TS/Vue 工程导入场景 为主,其他语言为 best-effort 检测;若无法精确解析,会在报告中输出 warning:
| 语言 | 扩展名 | 检测的 import 模式 |
|------|--------|-------------------|
| JS/TS | .js .ts .jsx .tsx .vue | 相对 import/require/dynamic import/re-export,tsconfig/jsconfig 的 baseUrl/paths,常见 Vite/Webpack alias |
| Python | .py | 相对 from .x import y,以及常见 src/ / package 布局下的绝对导入 |
| Go | .go | import(best-effort) |
| Java | .java | import(best-effort) |
| PHP | .php | require/include/use(best-effort) |
| Ruby | .rb | require/require_relative/load(best-effort) |
| Rust | .rs | use/mod(best-effort) |
| C/C++ | .c .cpp .h .hpp | #include(best-effort) |
patch-candidates 模式:生成候选,不直接删除git ls-files 获取文件列表,原生支持所有 .gitignore 规则(包含父级目录中的规则)。os.walk 遍历,直接跳过 node_modules、.idea、.vscode 等巨大干扰目录。.gitignore:回退模式下会自动向上查找并解析各层级 .gitignore 规则。.skill-workspace/)必须严格生成在用户当前的终端执行路径 (CWD) 下,严禁擅自回退到项目的物理根目录。scan-dirs 未命中、未识别到入口点或依赖图未建立,会在 JSON/Markdown/HTML 中追加 analysis_warnings.claude-plugin/、hooks/、examples/、evals/、scripts/tests/所有扫描行为通过配置文件控制。脚本采用**“就近原则”**加载配置(优先级从高到低):
--keep-list 等参数。.code-cleanup/ 文件夹(推荐用于全局安装场景)。.cursor/skills/code-cleanup-skill/config/。config/ 目录。| 配置文件 | 用途 |
|---------|------|
| scan-dirs.txt | 扫描哪些目录、类别名、关键词策略 |
| ext-list.txt | 哪些扩展名参与扫描 |
| keep-list.txt | 白名单,始终保留的文件 |
如用户未给参数,使用默认值:
target_dirs:
- <auto-detect from current workspace>
mode: patch-candidates
safety:
allow_direct_delete: false
require_confirmation: true
说明:若不传 --targets,脚本会按当前工作空间自动扫描(--project-root 对应目录);当 scan-dirs 一个都未命中时,会自动回退到通用代码扫描,并在报告中显式标注 warning。
必须遵循以下严格的三阶段闭环,确保清理过程可视化、安全授权、彻底清理且成果可度量。
analyze_cleanup_candidates.py 扫描当前工作空间。
before.json。project_stats 展示项目“健康分”与规模。render_cleanup_report.py 生成工业风报告。
cleanup-report.html。python3 -c "import pathlib; [p.rmdir() for p in sorted(pathlib.Path('.').rglob('*'), reverse=True) if p.is_dir() and not any(p.iterdir()) and '.git' not in str(p) and 'node_modules' not in str(p)]"after.json。--previous before.json 参数。
cleanup-report.html (核心)
cleanup-report.md
deletion-candidates.json
patch-plan.md
deletion-candidates.json 结构:
{
"generated_at": "ISO_DATE",
"project_root": "ABS_PATH",
"project_type": "application | library | plugin_repository | plugin_package | generic",
"analysis_warnings": [],
"summary": {
"high": 0,
"medium": 0,
"low": 0
},
"project_stats": {
"total_files_scanned": 1500,
"total_size_bytes": 1024000,
"unused_files_count": 12,
"unused_size_bytes": 51200,
"health_score": 95
},
"candidates": [
{
"path": "src/page/example/example.js",
"category": "unused_page",
"risk_level": "high",
"evidence": [
"未在其他源码文件中找到对 `example` 的直接引用"
],
"file_size_bytes": 4096,
"suggested_action": "delete_after_confirm"
}
]
}
medium优先使用同目录脚本:
scripts/analyze_cleanup_candidates.py
--keep-list 白名单(默认读取 config/keep-list.txt)--ext-list 扩展名配置(默认读取 config/ext-list.txt)--scan-dirs 目录配置(默认读取 config/scan-dirs.txt)scripts/render_cleanup_report.py
cleanup-report.md 与 patch-plan.md⚠️ 重要提示:以下模板中的
$PWD必须由 Agent 动态替换为用户当前对话所在的实际终端工作路径。
# 生成扫描 JSON (before.json)
python3 plugins/code-cleanup/skills/code-cleanup-skill/scripts/analyze_cleanup_candidates.py \
--project-root . \
--keep-list plugins/code-cleanup/skills/code-cleanup-skill/config/keep-list.txt \
--output $PWD/.skill-workspace/code-cleanup/latest/before.json
# 生成可视化报告
python3 plugins/code-cleanup/skills/code-cleanup-skill/scripts/render_cleanup_report.py \
--input $PWD/.skill-workspace/code-cleanup/latest/before.json \
--output-dir $PWD/.skill-workspace/code-cleanup/latest
说明:此模式仅用于兼容本地 Cursor Skill 工作流,不是 Claude 插件发布必需步骤。
python3 .cursor/skills/code-cleanup-skill/scripts/analyze_cleanup_candidates.py \
--project-root . \
--keep-list .cursor/skills/code-cleanup-skill/config/keep-list.txt \
--output $PWD/.cursor/skills/code-cleanup-skill-workspace/latest/before.json
python3 .cursor/skills/code-cleanup-skill/scripts/render_cleanup_report.py \
--input $PWD/.cursor/skills/code-cleanup-skill-workspace/latest/before.json \
--output-dir $PWD/.cursor/skills/code-cleanup-skill-workspace/latest
在给用户反馈时,优先给:
示例:
development
Vue 3 开发最佳实践指南 - Composition API、Script Setup、Pinia、TypeScript 集成及性能优化。 当用户说"Vue 3组件"、"Composition API"、"script setup"、"Pinia"、"Vue 3项目"、"ref reactive"、"defineProps defineEmits"、"Composable"、"Vue 3优化"时使用此技能。 涵盖:Script Setup 与 Composition API、响应式数据选择(ref vs reactive)、组件通信(Props/Emits/v-model/Slots)、Composables 设计模式、Pinia Setup Store、性能优化(v-memo、shallowRef、KeepAlive)。 提供 TypeScript 代码示例、反模式对照表、迁移指南和示例文件引用。
development
Vue 2 维护与开发最佳实践指南 - Options API、Vuex 及向 Vue 3 迁移准备。 当用户说"Vue 2组件"、"Options API"、"Vuex"、"Vue 2项目"、"Vue 2迁移"、"Vue mixin"、"Vue 2最佳实践"时使用此技能。 涵盖:Options API 规范(选项顺序、props 验证)、Vuex 模块化(namespaced modules)、逻辑复用(避免 mixin,使用工具函数)、迁移准备(停止使用 Filters、引入 Composition API 插件)。 提供 Vue 2 代码示例、反模式警告和迁移建议。
development
核心设计能力 - 提供配色、布局、组件样式生成及反模式检查。 当用户说"设计UI"、"生成样式"、"页面布局"、"CSS样式"、"组件设计"、"配色方案"、"设计系统"、"前端样式"、"响应式设计"、"动画效果"时使用此技能。 支持多种设计风格:Neo-Brutalism、Glassmorphism、Editorial、Cyberpunk。 提供配色方案、布局生成、组件样式、微交互动效、响应式网格。拒绝"AI廉价感",追求大胆、独特、细节丰富的设计。 重要特性:提供反模式检查,避免泛滥的渐变、无聊的阴影、默认圆角等平庸设计。
content-media
无障碍设计审查与修复能力。 当用户说"无障碍"、"a11y"、"WCAG"、"键盘导航"、"屏幕阅读器"、"颜色对比度"、"ARIA"、"可访问性"、"辅助功能"、"盲人友好"时使用此技能。 基于 WCAG 2.1 标准,检测图片 Alt 文本缺失、表单 Label 关联、键盘可访问性、颜色对比度不足、ARIA 属性误用等问题。 提供修复代码示例:语义化标签、焦点管理、焦点陷阱、屏幕阅读器支持。输出合规性检查报告和修复建议。