code-slop-cleanup
Strip AI slop from a branch diff before PR — judge each hunk against the surrounding file's conventions, remove without changing behavior, re-run tests. Removal only: hunting bugs → code-reviewing; structural improvement → refactoring; repo-wide audit → technical-debt-review; pruning tests → test-suite-design.
- License 许可
- MIT
- 最近更新
- 2026-11-12
- Stars
- ★ 1
- Forks
- 1
01 前言 Front Matter
- name
- code-slop-cleanup
- description
- Strip AI slop from a branch diff before PR — judge each hunk against the surrounding file's conventions, remove without changing behavior, re-run tests. Removal only: hunting bugs → code-reviewing; structural improvement → refactoring; repo-wide audit → technical-debt-review; pruning tests → test-suite-design.
- when_to_use
- Triggers: deslop, AI slop, slop cleanup, tighten this diff, remove AI artifacts, clean the diff before PR, debug leftovers, stray PLAN.md, obvious comments, unnecessary try/catch, backwards-compat shim nobody asked for, diff hygiene.
02 资源文件 2
- 参考文档evals/evals.json8.2 KB
- 参考文档references/slop-patterns.md9.9 KB
03 SKILL.md 正文
Code Slop Cleanup
Strip the residue AI-assisted coding leaves in a branch — obvious comments, defensive theater, debug leftovers, stray files, hedging shims — so the diff that reaches review contains only the change itself. Runs after implementation, before git-workflow/code-reviewing. This pass removes; it never redesigns.
⛔ The Iron Law
Remove only what you can prove is slop — never change behavior. If a removal could change behavior, keep the code and flag it instead.
Slop cleanup that deletes a load-bearing check trades clutter for a bug — a strictly worse codebase. When in doubt, the code stays and the doubt goes in the report.
Workflow
Step 1: Scope the Diff
Start from the branch state vs the default branch: git diff <base>...HEAD --stat
(main, or master in older repos).
Run the full git diff <base>...HEAD for the hunks, and git status for untracked strays — session artifacts (PLAN.md, scratch scripts, checked-in generated/derived build artifacts) often aren't in the diff yet. Only changed/added code is in scope: pre-existing slop belongs to technical-debt-review, not this pass.
"Make the branch presentable" is two jobs; this is one of them. What the diff should
contain is this pass. How the work is arranged — squashing a thrash of wip commits,
rewriting messages, drafting the PR description — is git-workflow. Do the removals and
hand the history over; a tidy diff spread across fourteen meaningless commits is still not
reviewable, and rearranging commits does not delete a debug log.
Step 2: Judge Each Hunk Against Its Surroundings
Slop is relative — the same construct is correct in one place and slop in another. For each candidate, read the surrounding file and ask: is this abnormal for this file's conventions and this codepath's trust level? A try/catch at a process boundary is protection; the same try/catch deep in a validated internal path is theater. See references/slop-patterns.md for the full catalog with per-pattern "when it's NOT slop" columns.
Step 3: Classify by Severity
- High: debug leftovers, silent-failure handlers, stray working files
- Medium: defensive theater on trusted paths, generic TODOs, unrequested backwards-compat shims, duplication of existing helpers
- Medium: also unanchored internal terminology (
Phase 2,CP1.3,finding #17) that no git-tracked doc defines — rewrite to the meaning - Low: comment slop, dead weight (unused imports,
=== true, redundant returns), style inconsistent with the file
Misplaced rationale — the multi-line header essay explaining a system instead of the code beneath it — is detected here but routed, not deleted: the reasoning belongs in an ADR, and deleting it loses something nothing else records.
Step 4: Strip — Deletions Only, Production Code Only
Apply removals highest severity first. Every edit must be a behavior-preserving deletion (or a trivial inlining a deletion forces). If removing something requires rewriting logic around it, that's refactoring — leave it and flag it.
The two test rules:
- A test failing after a production-code removal is the oracle saying the removal changed behavior. Revert the removal. Never edit the test.
- Slop inside test files (redundant tests, trivial asserts, mock-testing) is flagged and routed to
test-suite-design— never deleted here. A test's value can't be judged from the diff alone.
Step 5: Re-Run the Tests
Run the project's test suite fresh and read the output (verification-before-completion). Green is the proof the removals were behavior-preserving; a failure means Step 4's rule 1 applies to the offending removal.
Step 6: Report the Tightened Diff
Show what was removed, grouped by category with counts, plus a flagged-not-removed list: anything kept under the Iron Law's doubt clause, test-file slop routed to test-suite-design, suspected bugs routed to code-reviewing/bug-investigating.
Prevention: Reuse Before Write
The biggest slop category — duplication — is created at generation time and only caught (expensively) at review time, because a single diff hunk hides the copies that already exist elsewhere. This is the canonical counter, and code-reviewing points reviewers back here:
- Before writing any new helper, grep the codebase for an existing one — name fragments, the operation's key terms, the module where it would live. AI assistants generate what looks plausible instead of searching for what exists; searching first is the cheap counter.
- Before writing the third near-copy of a block, extract the seam instead. The recurring shapes — an N-arg setup/wiring ritual pasted at every entry point, parallel functions differing only by a noun or constant, byte-identical mappers across sibling modules — are cheap to write locally and expensive to maintain. The moment you're about to paste-and-tweak, that's the signal to factor.
Boundaries — What This Skill Never Does
- Never adds code — no new abstractions, no "while I'm here" improvements.
- Found a bug? Flag it and route to
code-reviewing/bug-investigating. Fixing bugs mid-cleanup makes both the cleanup and the fix unreviewable. - Structural cleanup →
refactoring. Most slop cleanup is a micro-refactor, and the two chain naturally: strip slop first, then refactor what remains — but extraction, moving, and re-abstraction are the refactoring skill's discipline (test-protected, one transformation at a time). - Whole-repo slop →
technical-debt-reviewwith its slop debt categories.
Rationalizations to Reject
| Excuse | Reality |
|---|---|
| "This check might catch something someday" | If nothing upstream can produce that state, it's theater — and it hides the real bugs by normalizing noise. |
| "The comments help junior developers" | Restating comments rot and mislead; code clarity helps juniors. Keep why-comments, cut what-comments. |
| "This 12-line header explains the architecture — I'll delete it as comment slop" | It's misplaced, not worthless. Deleting it destroys reasoning nothing else records. Flag it for the ADR and leave the code alone. |
| "Phase 3 is obviously meaningful, leave the reference" | Check before assuming: if no tracked doc defines it, it points at a conversation the reader wasn't in. Rewrite it to what it means. |
| "I'll just fix this bug while I'm here" | Cleanup and fixes in one pass make both unreviewable. Flag it, route it, finish the cleanup. |
| "Strip it all — defensive code is slop" | A boundary check is not slop. Over-removal breaks behavior, the one thing this pass must never do. |
| "This test is obviously redundant, I'll just delete it" | "Obviously" is a guess; proof requires the behavior map. Route to test-suite-design. |
Red Flags — Stop and Revert
- You modified a conditional's logic instead of deleting something.
- A test failed and you're editing the test.
- You deleted a test.
- You removed validation at a public, API, or user-input boundary.
- You added anything.
Cross-Skill References
refactoring— structural improvement after the slop is gone; this skill deletes, that one reshapescode-reviewing— the review this pass prepares the diff for; bugs found here route theretest-suite-design— pruning test-file slop with behavior-map prooftechnical-debt-review— repo-scoped slop audit (type/config/doc-drift debt)git-workflow— the pre-PR self-review this pass feeds intoverification-before-completion— the fresh-test-run gate behind Step 5
04 同仓库更多 Skills
writing-skills
Use when authoring, editing, or reviewing a skill in this library — a new SKILL.md, one that under-triggers, or hardening an existing one. Covers description and listing-budget rules, frontmatter, progressive disclosure, the 3-eval rule, and pressure-testing against rationalizations.
working-agreement
Define and validate how a multi-session project is run — where plans, status and decisions live, session routines, new work, milestone close. README/CONTRIBUTING → project-documentation.
verification-before-completion
Evidence gate before any claim that work is done, fixed, passing, or deployed. Route here when a message declares the work finished or asks to commit, push, merge, ship, or close it out, including a brief sign-off, and before git-workflow or release-management act on it. Writing the commit message or PR text itself → git-workflow.
ui-ux-design
Design user experiences from an engineer's perspective — user flows, wireframes, interaction patterns, responsive strategy, navigation, loading/error/empty states. Triggers: design the UI, user flow, wireframe, how should this screen look, loading state, error state, empty state, responsive design, navigation, page layout, form design, mockup.
threat-modeling
Design-time security analysis of a system or feature before it's built — trust boundaries, attack surface, STRIDE per element, abuse cases, prioritized mitigations that become security requirements. Triggers: threat model, STRIDE, trust boundary, attack surface, what could go wrong security-wise, security design review, abuse case, secure this design, security requirements. Reviewing EXISTING code/config for vulnerabilities → security-audit; use this skill while the design is still on the whiteboard.
test-suite-design
Design comprehensive test suites for existing code — strategy across unit/integration/e2e, fixtures, factories, helpers. Triggers: add tests, write tests for, increase coverage, test this module, testing strategy, test plan, what tests do I need, test infrastructure, test helpers, this has no tests. Not for TDD — use tdd-workflow.