mcpField
D
deslop

deslop

github.com/agent-sh开发1.0k90 次安装今天更新
代码仓库

关于 deslop

deslop 是用于检查代码中疑似 AI 生成冗余内容的技能,面向代码维护者。它按确定性和严重程度整理发现,并支持报告与自动修复流程。

主要功能

  1. 01按确定性分级代码问题
  2. 02扫描全仓库或变更文件
  3. 03支持 quick、normal、deep 分析
  4. 04输出结构化 JSON 结果
  5. 05识别可自动修复项

适用场景

  1. 01检查当前分支变更中的问题
  2. 02定位调试语句和占位文本
  3. 03审查疑似死代码与空 catch
  4. 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:汇总并确定优先级

按以下顺序对发现项排序:

  1. 置信度:HIGH 优先于 MEDIUM,MEDIUM 优先于 LOW
  2. 严重程度:high 优先于 medium,medium 优先于 low
  3. 修复复杂度:可自动修复的优先于需要手动修复的
阶段 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:1
  • doc-code-ratio:JSDoc 长度超过函数体的 3 倍
  • stub-function:仅返回占位值
  • dead-code:return/throw 之后存在无法到达的代码
  • infrastructure-without-impl:创建了数据库客户端但从未使用
低置信度(仅标记)
  • over-engineering:文件/导出比例 > 20x
  • buzzword-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