> Agent-ready spec from Diff of the Day (2026-12-04, idea 4). Give this file to your coding agent (Claude Code, Codex, Cursor) and ask it to build the P0 requirements first.

# Spec: Duplication distance report

## Problem Statement
DHH argues that DRY is a human pattern that agent-era frameworks can drop. Kent Beck replies that DRY fights coupling, and coupling costs grow fast. Vlad Khononov adds that duplication inside one module is cheap, while duplication spread across the system forces an agent to load much more code. Teams argue about this without data on where their own duplicates live.

## Goals
- Find duplicated code blocks in one repository.
- Measure how far apart the copies are (same file, same module, different modules).
- Rank clone groups by spread and size so that the risky ones come first.
- Run on a 100,000-line repository in under 3 minutes.

## Non-Goals
- Removing duplication automatically: a person decides whether a clone is fine.
- Judging the DRY debate: the report shows data, not a verdict.
- Every language at once: start with one language the team uses.

## User Stories
- As a tech lead, I want to see clone groups that cross module borders so that I can decide which to merge.
- As a developer using agents, I want to know if agent-written code adds spread-out copies so that I can steer it.
- Edge case: generated code and vendored files create huge clone groups; the tool skips paths listed in an ignore file.

## Requirements
### P0
- [ ] Detect clone groups of at least N lines (default 10) with token-based matching. Accept: a test repository with 3 planted clones finds all 3.
- [ ] Compute spread per group: files, top-level modules, and directory distance. Accept: each group shows these numbers.
- [ ] Write a ranked Markdown report. Accept: groups that cross modules appear first.
### P1
- [ ] Compare two git revisions and show new clone groups. Accept: a branch that adds a copy shows one new group.
- [ ] Ignore file for generated and vendored paths. Accept: ignored paths never appear.
### P2
- [ ] Tag clone groups whose lines came from commits by a coding agent (by commit trailer or author). Accept: the tag shows when the trailer is present.

## Success Metrics
- The report finds at least 90% of planted clones in tests.
- The team reviews the top 10 groups and acts on at least 3.
- Cross-module groups do not grow over the next month.

## Open Questions
- Which module boundary counts: top-level folder, package, or service?
- What clone size is worth reporting for this codebase?

## Timeline
- One evening: clone detection on one language, spread numbers and the report.

## Agent Instructions
- Stack: Python 3 with a tokenizer for the target language, or wrap an existing clone detector and add the spread numbers.
- Build order: tokenizer, clone groups, spread, report, revision diff.
- Safety: read-only on the repository; no network access needed.
- Done when: all P0 acceptance checks pass on the test repository and one real repository.

## Sources
- DHH on X, https://x.com/dhh/status/2128158222552809729
- Kent Beck on X, https://x.com/KentBeck/status/2128518141399666873
- Vlad Khononov on X, https://x.com/vladikk/status/2128284261388001554
