deslop
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeslop
Deslop
Clean AI slop out of the code a branch changed, and leave behavior unchanged. Use it before every commit, and on , "deslop it", "clean the diff", or "strip the slop". It cleans code only. The unslop skill owns prose, and the no-comments skill owns the comment review.
/deslop清除分支所改代码中的 AI 冗余代码,并保持行为不变。在每次提交前使用;也适用于 、、 或 。它仅清理代码。unslop skill 负责文案,no-comments skill 负责注释审查。
/deslop"deslop it""clean the diff""strip the slop"Scope
范围
Use the caller's files or diff. Otherwise diff against the branch this one builds on, including the working tree and untracked files (): the pull request's base when one is open (, with from origin's fetch URL), else the branch it was cut from ( or ), else . On a stacked branch, would pull the parent's commits into the diff. Edit only inside the hunks the branch added or changed. Read whatever the rules need to judge them: callers, types, existing helpers, and the rest of the file. Slop you notice elsewhere goes in the report and stays untouched.
git status --shortgh pr view <branch> -R <host>/<owner>/<repo> --json baseRefName<host>/<owner>/<repo>git branch -vvgit reflog show <branch>mainmain使用调用者提供的文件或 diff。否则,与当前分支所基于的分支比较 diff,其中包括 working tree 和 untracked files():如果存在 open pull request,则使用其 base branch(,其中 来自 origin 的 fetch URL);否则使用创建当前分支时所在的源分支( 或 );再否则使用 。在 stacked branch 上,以 为基准会把父分支的提交也纳入 diff。仅编辑当前分支新增或修改的 hunk。为依据规则作出判断,读取所需内容:调用方、类型、已有 helper 以及文件的其余部分。在其他位置发现的 AI 冗余代码应写入报告,并保持不动。
git status --shortgh pr view <branch> -R <host>/<owner>/<repo> --json baseRefName<host>/<owner>/<repo>git branch -vvgit reflog show <branch>mainmainProcess
流程
- Read the diff hunk by hunk and name the task each hunk serves. A hunk that serves none is rule 17.
- Apply the rules below in order. Make the smallest edit. Delete before you rewrite.
- Stop at a cut that needs a new shape, such as a type, a helper, or a state model. Flag it for the Refactoring playbook. Deslop never adds abstraction to remove slop.
- Prove behavior unchanged on the real artifact. Run the tests the diff touches and the type check. A test that must change to pass means behavior changed. Revert that cut.
- Hand what remains to the neighbors. A comment that rules 1 to 3 do not settle needs the comment review before you report. Use the no-comments skill on those comments. If its review changes code, run step 4 again. Then use the unslop skill on names, messages, and kept comments.
- Report in the format below.
- 逐个读取 diff hunk,并说明每个 hunk 所服务的任务。没有任何用途的 hunk 适用规则 17。
- 按顺序应用以下规则。进行最小幅度的改动。优先删除,而不是重写。
- 当某项清理需要新的结构,例如 type、helper 或 state model 时停止。将其标记给 Refactoring playbook。Deslop 绝不通过新增 abstraction 来清除 AI 冗余代码。
- 在实际产物上证明行为未发生变化。运行 diff 涉及的测试和类型检查。如果某个测试必须修改才能通过,就说明行为发生了变化。撤销该改动。
- 将剩余事项交给相邻 skill 处理。规则 1 至 3 无法裁定的注释,应在报告前进行注释审查。对这些注释使用 no-comments skill。如果其审查修改了代码,再次执行步骤 4。然后对名称、消息文本和保留的注释使用 unslop skill。
- 按以下格式报告。
Rules
规则
Rule numbers are stable ids that other skills cite. A removed rule leaves a gap. Each rule names the target, its tell, and the fix.
规则编号是其他 skill 会引用的稳定 ID。删除一条规则会留下编号空缺。每条规则都指明处理目标、识别特征和修复方式。
Comments
注释
- Narrating comments. The comment restates the line below it or names a phase (,
// increment count). Delete it.// Phase 1: add cards - Commented-out code and removal markers. Code behind comment markers, or a note. Delete it.
// removed - Keep list. License headers. Non-obvious behavior forced by an external dependency, platform, vendor, or protocol you cannot reshape. . Doc comments that define a public API contract. Issue or RFC links that explain a constraint code cannot express. A kept comment is still prose, so step 5 sends it to the unslop skill.
prettier-ignore
- 叙述性注释。 注释重复下一行代码,或仅用于标示阶段(、
// increment count)。删除。// Phase 1: add cards - 注释掉的代码和删除标记。 注释标记后的代码,或 之类的说明。删除。
// removed - 保留清单。 许可证头。由无法改变形态的外部依赖、平台、供应商或协议强制要求、且并不显而易见的行为。。定义 public API 契约的文档注释。解释代码无法表达之约束的 issue 或 RFC 链接。保留的注释仍属于文案,因此步骤 5 会将其交给 unslop skill。
prettier-ignore
Guards
守卫
- Guard on an impossible state. A null check on a value the types or the boundary never leave null, on an already narrowed type, a length check on a tuple, a default for an argument every caller passes. Delete it. Trust the type.
instanceof - Defensive wrapping on a trusted path. A or a fallback around an internal call that cannot fail the way the handler expects, or a handler that swallows the error. Remove the wrapper, or let it throw. A silent fallback that hides an unclear invariant is rule 4, and the report names the invariant.
try/catch - Repeated validation. A check that re-parses or re-validates data the boundary already parsed. Delete the inner copy.
A guard at a system boundary (user input, network, file, environment, external API) stays. A guard a test demands stays, and the test is the proof.
- 针对不可能状态的 guard。 对类型或系统边界保证不会为 null 的值做 null check,对已完成类型收窄的值执行 ,对 tuple 做 length check,或为每个调用方都会传入的参数设置 default。删除。信任类型。
instanceof - 可信路径上的防御性包装。 对内部调用使用 或 fallback,而该调用不可能以处理器预期的方式失败;或处理器吞掉错误。移除包装,或让错误抛出。静默 fallback 隐藏了不明确的不变量时,适用规则 4,并在报告中指出该不变量。
try/catch - 重复验证。 再次解析或验证边界已解析的数据。删除内部副本。
位于 system boundary(用户输入、网络、文件、环境、外部 API)的 guard 应保留。测试要求的 guard 也应保留,而该测试就是证明。
Dead paths
无效路径
- Compatibility shims. An old path kept beside the new one, an alias or re-export kept "for callers" with no caller, a deprecation notice for code this branch replaced. Delete a shim with no caller. When every caller sits inside the branch's hunks, migrate them and delete the shim in the same change. A shim with a caller outside those hunks stays, and the report names it, because migrating that caller would edit outside Scope.
- Unused parameters, exports, and flags. A parameter nothing passes, an export nothing imports, an option with one value, a flag with one reachable branch, a branch marked temporary. Delete it.
- Debug residue. Debug logs and prints, tagged or not, throwaway prototypes, variant switchers. Delete them.
A symbol on the package's public surface (an entry-point export, a documented API) stays even with no caller in the repository, because its callers live outside it. Delete it only when the task removes it from the public API. Otherwise list it under "Did not touch".
- 兼容 shim。 新路径旁仍保留旧路径;为 保留却无调用方的 alias 或 re-export;针对本分支已替换代码的 deprecation notice。删除没有调用方的 shim。当所有调用方都位于本分支的 hunk 中时,在同一次改动中迁移它们并删除 shim。位于这些 hunk 之外、且仍有调用方依赖的 shim 应保留,并在报告中指出,因为迁移该调用方会编辑范围之外的内容。
"for callers" - 未使用的参数、export 和 flag。 没有任何调用方传入的参数,没有任何模块 import 的 export,只有一种取值的 option,只有一条可达分支的 flag,标记为临时的 branch。删除。
- 调试残留。 调试日志和打印输出,无论是否带 tag;一次性 prototype;用于切换实现变体的 switcher。删除。
package 的 public surface 上的 symbol(entry-point export、documented API)即使仓库内没有调用方也应保留,因为其调用方位于仓库之外。只有当任务将其从 public API 中移除时才可删除。否则,将其列在 下。
"Did not touch"Types
类型
- Checker silencers. A cast to or
any, anunknownassertion, or a suppression comment whose only job is to make the type checker pass. Fix the type or delete the cast.as
- 类型检查抑制手段。 转换为 或
any的 cast、unknownassertion,或唯一作用是让 type checker 通过的 suppression comment。修复 type,或删除 cast。as
Shape
结构
- One-caller wrappers. A function, helper, or adapter with one caller that passes its arguments through. Inline it.
- Speculative generality. An abstraction, parameter, hook, or seam with one implementation and no second use in the task. Inline it back until a real need shows.
- Re-implemented helpers. Code that does what a helper in the codebase already does. Call the existing one.
- Nesting an early return flattens. A guard clause whose body is the rest of the function. Return early and dedent.
- Copy-paste with variation. The same shape twice inside the diff with small differences. Extract only when the codebase already names the shared shape. Otherwise three similar lines stay.
- Structure the diff cannot fix. A new conditional bolted onto an unrelated flow, a one-off boolean or nullable mode, repeated conditionals on one shape. Flag it for the Refactoring playbook under principle-model-the-domain. Do not fix it here.
- 仅有一个调用方的 wrapper。 只有一个调用方、且该调用方会原样透传参数的 function、helper 或 adapter。将其内联。
- 推测性泛化。 在当前任务中只有一种 implementation、且没有第二处用途的 abstraction、parameter、hook 或 seam。先将其恢复为内联实现,直到出现真实需求。
- 重复实现的 helper。 代码实现了 codebase 中已有 helper 的功能。调用已有 helper。
- 可通过提前返回变平的嵌套。 guard clause 的函数体包含函数余下全部逻辑。提前 return,并减少一层缩进。
- 带差异的复制粘贴。 diff 中两次出现相同结构,仅有少量差异。只有当 codebase 已经为该共享结构给出名称时才进行提取。否则,即使只有三行相似代码也保持原样。
- diff 无法修复的结构。 硬接到无关 flow 上的新 conditional、一次性的 boolean 或 nullable mode、针对同一结构反复出现的 conditional。依据 principle-model-the-domain 标记给 Refactoring playbook。不要在此修复。
Scope
范围
- Unrelated edits. Formatting churn, renames, import reorders, or syntax modernizing in code the task did not need to touch. Revert the hunks git can restore: those committed on the branch, and those you wrote this session. An uncommitted hunk you did not write stays, and the report names it, because reverting it would destroy work no commit holds. shows the committed hunks and
git diff <base>...HEADthe uncommitted ones. Revert hunk by hunk, never by restoring a whole file, so an uncommitted hunk in the same file survives. To revert a committed hunk, edit its lines back by hand, or reverse only that hunk taken fromgit diff HEAD. Reversing that whole diff also undoes the file's task work, andgit diff <base>...HEAD -- <file>also carries the file's uncommitted hunks.git diff <base> -- <file> - A behavior change inside cleanup. A hunk that changes what the code does under a cleanup label. Split it out and name it in the report.
- Style against the file. A pattern the surrounding file does not use. Match the file.
- 无关编辑。 任务不需要触及的代码中的格式变动、重命名、import 重排或语法现代化。撤销 git 能够恢复的 hunk:分支上已提交的 hunk,以及你在本次会话中编写的 hunk。不是由你编写的未提交 hunk 应保持不动,并在报告中指出,因为撤销它会破坏未被任何提交保存的工作。显示已提交的 hunk,
git diff <base>...HEAD显示未提交的 hunk。逐个 hunk 撤销,绝不通过恢复整个文件来撤销,以免同一文件中的未提交 hunk 丢失。要撤销已提交的 hunk,手动将这些行改回原样,或只反转git diff HEAD中该 hunk。反转整个 diff 也会撤销该文件的任务改动,而git diff <base>...HEAD -- <file>还会带上该文件的未提交 hunk。git diff <base> -- <file> - 清理过程中发生行为变更。 以清理名义改变了代码实际行为的 hunk。将其拆分出来,并在报告中指出。
- 与文件风格不一致。 周边文件未采用的 pattern。与文件保持一致。
Report
报告
One to three sentences, then:
- Counts by rule id, and the files touched.
- Hunks reverted under rule 17, and the uncommitted unrelated hunks left in place.
- Flags handed to the Refactoring playbook (step 3, rule 16).
- The comments step 5 gave the no-comments skill, and what it did with each.
- A "Did not touch" list of slop outside the scope.
- The test and type-check commands with their results.
CREDITS.md先用一至三句话说明,然后列出:
- 按 rule ID 统计的数量,以及涉及的文件。
- 依据规则 17 撤销的 hunk,以及保留原样的未提交无关 hunk。
- 移交给 Refactoring playbook 的标记项(步骤 3、规则 16)。
- 步骤 5 交给 no-comments skill 的注释,以及它对每条注释所做的处理。
- 范围之外未触碰的 AI 冗余代码清单,列在 下。
"Did not touch" - 测试和类型检查命令及其结果。
CREDITS.md