关于 deslop
deslop 是用于检查代码中疑似 AI 生成冗余内容的技能,面向代码维护者。它按确定性和严重程度整理发现,并支持报告与自动修复流程。
主要功能
- 01按确定性分级代码问题
- 02扫描全仓库或变更文件
- 03支持 quick、normal、deep 分析
- 04输出结构化 JSON 结果
- 05识别可自动修复项
适用场景
- 01检查当前分支变更中的问题
- 02定位调试语句和占位文本
- 03审查疑似死代码与空 catch
- 04为修复流程筛选高确定性发现
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ agent-sh/ agentsys --skill deslop安装后在 Claude Code 中输入/deslop确认已加载。
详细介绍
deslop
通过基于置信度的发现和自动修复,清除代码中的 AI 垃圾内容。
解析参数
const args = '$ARGUMENTS'.split(' ').filter(Boolean);
const mode = args.find(a => ['report', 'apply'].includes(a)) || 'report';
const scope = args.find(a => a.startsWith('--scope='))?.split('=')[1] || 'all';
const thoroughness = args.find(a => a.startsWith('--thoroughness='))?.split('=')[1] || 'normal';
输入
参数:[report|apply] [--scope=<path>|all|diff] [--thoroughness=quick|normal|deep]
- 模式:
report(默认)或apply - 范围:要扫描的内容
all(默认):整个代码库diff:仅扫描当前分支中已更改的文件<path>:指定目录或文件
- 彻底程度:分析深度(默认:
normal)quick:仅使用正则表达式模式normal:+ 多轮分析器deep:+ 可用时使用 CLI 工具(jscpd、madge)
检测流水线
阶段 1:运行检测脚本
检测脚本相对于此技能的路径为 ../../scripts/detect.js。
运行检测(使用相对于技能目录的路径):
# Scripts are at plugin root: ../../scripts/ from skills/deslop/
node ../../scripts/detect.js . --thoroughness normal --compact --max 50
对于 diff 范围(仅扫描已更改的文件):
BASE=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' || echo "main")
# Use newline-separated list to safely handle filenames with special chars
git diff --name-only origin/${BASE}..HEAD | \
xargs -d '\n' node ../../scripts/detect.js --thoroughness normal --compact
注意:相对路径 ../../scripts/detect.js 从 skills/deslop/ 向上导航至包含 scripts/ 的插件根目录。
阶段 2:Repo-Map 增强(可选)
如果存在 repo-map,可通过基于 AST 的分析增强检测:
// Use relative path from skill directory to plugin lib
// Path: skills/deslop/ -> ../../lib/repo-map
const repoMap = require('../../lib/repo-map');
if (repoMap.exists(basePath)) {
const map = repoMap.load(basePath);
const usageIndex = repoMap.buildUsageIndex(map);
// Find orphaned infrastructure with HIGH certainty
const orphaned = repoMap.findOrphanedInfrastructure(map, usageIndex);
for (const item of orphaned) {
findings.push({
file: item.file,
line: item.line,
pattern: 'orphaned-infrastructure',
message: `${item.name} (${item.type}) is never used`,
certainty: 'HIGH',
severity: 'high',
autoFix: false
});
}
// Find unused exports
const unusedExports = repoMap.findUnusedExports(map, usageIndex);
for (const item of unusedExports) {
findings.push({
file: item.file,
line: item.line,
pattern: 'unused-export',
message: `Export '${item.name}' is never imported`,
certainty: item.certainty,
severity: 'medium',
autoFix: false
});
}
}
阶段 3:汇总并确定优先级
按以下顺序对发现项排序:
- 置信度:HIGH 优先于 MEDIUM,MEDIUM 优先于 LOW
- 严重程度:high 优先于 medium,medium 优先于 low
- 修复复杂度:可自动修复的优先于需要手动修复的
阶段 4:返回结构化结果
技能返回结构化 JSON,不会应用修复(由编排器处理)。
输出格式
标记之间的 JSON 结构:
=== DESLOP_RESULT ===
{
"mode": "report|apply",
"scope": "all|diff|path",
"filesScanned": N,
"findings": [
{
"file": "src/api.js",
"line": 42,
"pattern": "debug-statement",
"message": "console.log found",
"certainty": "HIGH",
"severity": "medium",
"autoFix": true,
"fixType": "remove-line"
}
],
"fixes": [
{
"file": "src/api.js",
"line": 42,
"fixType": "remove-line",
"pattern": "debug-statement"
}
],
"summary": {
"high": N,
"medium": N,
"low": N,
"autoFixable": N
}
}
=== END_RESULT ===
置信度级别
| 级别 | 含义 | 操作 |
|---|---|---|
| HIGH | 确定是垃圾内容,可安全自动修复 | 通过 simple-fixer 自动修复 |
| MEDIUM | 很可能是垃圾内容,需要验证 | 先审查 |
| LOW | 可能是垃圾内容,取决于上下文 | 仅标记 |
模式类别
高置信度(可自动修复)
debug-statement:console.log、console.debug、print、println!debug-import:未使用的调试/日志记录导入placeholder-text:"Lorem ipsum"、"TODO: implement"empty-catch:没有注释的空 catch 块trailing-whitespace:行尾空白mixed-indentation:混用制表符和空格
中置信度(需要审查)
excessive-comments:注释/代码比例 > 2:1doc-code-ratio:JSDoc 长度超过函数体的 3 倍stub-function:仅返回占位值dead-code:return/throw 之后存在无法到达的代码infrastructure-without-impl:创建了数据库客户端但从未使用
低置信度(仅标记)
over-engineering:文件/导出比例 > 20xbuzzword-inflation:提出的主张没有证据支持shotgun-surgery:文件经常一起更改
修复类型
| 修复类型 | 操作 | 模式 |
|---|---|---|
remove-line | 删除行 | debug-statement、debug-import |
add-comment | 添加说明 | empty-catch |
remove-block | 删除代码块 | 带有 TODO 的 stub-function |
错误处理
- Git 不可用:跳过依赖 Git 的检查
- 范围无效:在 JSON 中返回错误
- 解析错误:跳过该文件,继续扫描
集成
此技能由以下项目调用:
deslop-agent用于/deslop命令/next-task的第 8 阶段(评审前检查),使用scope=diff
编排器会启动 simple-fixer 来应用 HIGH 置信度修复。
评论
支持 Markdown