dedup-sweep
Skill1 starsChanged 13 days agoMITView on GitHub
Detect clone families, decide, execute gated merges.
In this repository10 other files it gives its agents.
- agent-regressionSkill
- dead-code-sweepSkill
- hermes-cron-stuck-job-recoverySkill
- live-probeSkill
- measure-firstSkill
- probe-firstSkill
- prose-hygieneSkill
- repo-organizeSkill
- verbose-code-trimSkill
- verification-gatesSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 29
Before refactors: shrink the duplication surface first
- Distinctive: line 33
Don't use for: intentional parallel structures (e.g., per-platform variants kept deliberately — record them as KEEP with the reason).
- Very specific: line 63
One family per commit: After each: baseline-verified test run (verification-gates Gate 2) and lint on touched files.
- Distinctive: line 69
Completion criterion: every family has a decision + reason in the inventory.
- Distinctive: line 80
The abstraction that ate the codebase: if a "shared" helper needs 5+ flags to serve its family, the code wasn't duplicates — un-merge it.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Dedup Sweep
Detect duplicate and near-duplicate code ("clones"), group them into families, decide per family — merge or keep, with reasons — then execute the merges with regression gates. Two-phase discipline: analysis and execution are separate steps with different failure modes; never merge them. A typo in an inventory must never become a bad code edit.
Adapts the clone-family model of niuma996/code-hygiene-skills
(find-duplication, MIT) — detect/decide/execute with drift classification —
and wires in this library's verification gates at the execution step.
When to Use
- Copy-pasted helpers, try/catch wrappers, structurally similar functions
- Before refactors: shrink the duplication surface first
- Review comments like "this is the same as X"
- Post-feature: the third time similar code appears, sweep
Don't use for: intentional parallel structures (e.g., per-platform variants kept deliberately — record them as KEEP with the reason).
Procedure
Phase 1 — DETECT (inventory only; no edits):
- Scan — LLM-driven anchor-grep by default (read the code, find same-shape blocks); tool-assisted when token-precision is needed (jscpd/copydetect/pmd-cpd for exact clones, lizard for complexity).
- Group into clone families — every row: files+lines, the family's common shape, and drift classification: none (identical) / minor (whitespace, names) / structural (same intent, diverged bodies).
- Assign priority: P0 identical ≥10 lines zero drift (safe mechanical merge) → P3 similar-intent-different-implementation (usually KEEP).
- Stop. The inventory is the deliverable of phase 1. No edits yet.
Phase 2 — DECIDE (per family, reasons recorded):
- Pick a strategy per family: extract shared helper / parameterize /
delete the dead copy / keep all (with reason). The decision rule:
- drift none + both live → extract helper
- drift minor → extract + parameterize the deltas
- drift structural → usually keep; forcing a shared abstraction of diverged code creates worse coupling than the duplication
- Check the blast radius for each merge: callers of every copy, tests covering each site, public-API exposure.
Phase 3 — EXECUTE (gated):
- One family per commit. After each: baseline-verified test run
(
verification-gatesGate 2) and lint on touched files. - Post-merge sweep the new shared module: stale comments on the old
copies' remnants, dead tests for removed variants
(
dead-code-sweep).
Completion criterion: every family has a decision + reason in the inventory; merged families each have a green post-merge run; no KEEP family was merged "while we were in there."
Pitfalls
- Premature DRY: two things that look alike but evolve for different reasons (platform variants, deliberate duplication per "AHA vs rules of three") belong to KEEP. Wrong merges couple them forever.
- Merge-by-inventory-typo: phase separation exists because inventories carry errors. Re-verify each family's lines before executing.
- The abstraction that ate the codebase: if a "shared" helper needs 5+ flags to serve its family, the code wasn't duplicates — un-merge it.
- Structural drift forced into a mold: P3 families stay P3. Extracting a common interface for diverged implementations is a redesign, not a dedup.
Verification
Runnable check: the full-repo test suite before and after the sweep, plus a duplicate-count re-scan:
jscpd --min-tokens 70 --reporters console . | tail -2 # before AND afterExpected: suite green both sides (delta = zero); the after-scan's clone count is materially below the before-scan for the P0/P1 families merged.
Evidence to capture: both scan outputs, the per-family decision table, and the per-commit test runs.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

