Deduplicate
Find near-duplicates with tree-sitter semantic similarity, then refactor to remove redundancy.
Process
- Scope:
- Changed files (default) —
{"op": "get changes"}fromgit - Specific files — user-named
- Whole codebase — broad sweep
- Check tree-sitter index:
{"op": "get status"}— must be ready before detection.
- Detect:
treesitterop: "find duplicates"on scoped files. For each cluster note: what's duplicated, severity, refactor opportunity (extract function, module, trait).
- Refactor (if requested, not just analysis):
- Extract shared logic
- Replace duplicates with calls
- Run tests after each extraction
- Follow TDD — if no test covers it, write one
- Track on kanban for clusters needing human decision:
```json
{"op": "init board"}
{"op": "add tag", "id": "duplicate", "name": "Duplicate Code", "color": "ff8800", "description": "Near-duplicate code needing refactoring"}
{"op": "add task", "title": "<concise description>", "description": "<files and lines>\n\n<what's duplicated>\n\n<suggested refactoring>", "tags": ["duplicate"]}
```
- Summarize: clusters by severity, refactors done, kanban tasks created, next-step recommendation.
Rules
- Report only actionable duplication. Ignore test fixtures, generated code, trait-impl boilerplate, single-line matches.
- Prefer the smallest extraction; don't over-abstract.
- Note dependency implications when duplicates cross crates/packages.
- Kanban is the single source of truth — no TodoWrite/TaskCreate.