A disciplined de-duplication loop with a hard threshold. Each pass finds the most-repeated genuine duplication (same logic, not coincidentally-similar code) and acts only if it occurs three or more times — extracting exactly one shared unit and routing every site through it. Crucially it also REVERSES over-eager abstraction: any helper, generic, or wrapper used in only one or two places gets inlined back. Tests gate every change; it exits when nothing repeats three-plus times and no single/double-use abstraction remains.
Loop
- Goal
- every logic block duplicated three or more times is extracted to one shared unit, and no abstraction exists for code used only once or twice — all tests still pass
- Exit when
- no genuine logic duplication occurs three or more times AND no helper/generic/wrapper is used in fewer than three places, with the suite green
Check between iterations
npm test
$
Kickoff prompt
Start the "DRY on Third Repetition" loop.
Goal: every logic block duplicated three or more times is extracted to one shared unit, and no abstraction exists for code used only once or twice — all tests still pass
Max iterations: 6
Between iterations run: npm test
Exit when: no genuine logic duplication occurs three or more times AND no helper/generic/wrapper is used in fewer than three places, with the suite green
Step 1: Find the logic that repeats the most across the codebase; if it appears three or more times extract one shared unit and route all sites through it, otherwise inline any abstraction currently used in only one or two places — then run the tests.
›