Public: anyone can read this; the crew can change it.
Duplication report: near-duplicate functions and tests clustered into one shape #14654
The report runs, its top clusters are listed below with the measured duplication rate, and one cluster is folded: the fixed-sleep polling loop. The tests that cover the change pass (a 46-file run, then the dupes, gate and honesty suites); I did not run the whole suite.
stopped closed without shipping deploy ca8f3cd
The report runs, its top clusters are listed below with the measured duplication rate, and one cluster is folded: the fixed-sleep polling loop. The tests that cover the change pass (a 46-file run, then the dupes, gate and honesty suites); I did not run the whole suite.
What changed
- Report:
bun scripts/dupes.tsreads every function and test body undersrc/andtest/as a shape (scripts/dupes_shape.ts: names, strings and numbers taken out). It clusters three or more that are near-duplicates and prints each cluster with the shape its members all hold. It takes about 10 s. - Threshold:
THRESHOLDis 0.55, the best F1 over 41 pairs I labeled from this repo (scripts/dupes-pairs.json,--tune), not the paper's 0.71. 0.55 gives precision 0.64 and recall 0.58 on those pairs, so treat it as a first tuning.test/dupes.test.tsholds the constant to the best-scoring threshold. - Measured rate: 41,891 functions and tests of 40 tokens or more. 441 clusters hold 1,974 of them (4.7%). One implementation each would save about 133k tokens, 2.0% of function tokens. This is close to fallow's 2.13% on the same tree. Nested bodies count in each unit, so the denominator is generous.
- Top clusters:
- 16 copies of the
boothelper intui-*tests (176 shared tokens). - 30 MCP
tool/call/mcphelpers in tests (77 shared tokens). - 18
*-timingpage tests (128 shared tokens). - 15
*-fittests, "no inline width…" (145 shared tokens). - 18 more MCP
callhelpers (95 shared tokens). - 9
src/tui/screens/*screens (packScreenand its siblings, 173 shared tokens). - 8
asUser/webfetch helpers (161 shared tokens).
- 16 copies of the
- Folded: The largest fixed-sleep shape was
for (let i = 0; i < N && cond; i++) await Bun.sleep(M), 70 copies across 46 tests. They now callwaitForintest/helpers/poll.ts, which waits the same interval for the same total time and, like the loop, does not throw.pollUntilnow sits on it.test-honesty-allow.jsondropped by the 70 waits (the committed allowance is 493 files). The 46 changed files pass: 453 pass, 1 skip. - Gate note:
dupesNoteinscripts/gate.tsnames an existing function when a pull adds one at or over the threshold. It is a note only. It skips test bodies, since sibling tests read alike by design. It reads the whole tree, about 10 s, and only when the diff adds a function. On this pull it flagged my own test'sgithelper as 0.75 liketest/both-doors-refusal.test.ts#run. I left that duplicate in place. - Refactor:
gate.tswrote the base-ref lookup out eleven times. It is now onebaseRef. - Docs:
AGENTS.mdsays how to run the report and when to usewaitFor.
fallow, run once and read-only, off the checks path
- Dupes: 762 clone groups, 2.13% of tokens. The report agrees on the shape of the duplication, so I ported nothing from it.
- Dead code: 2,365 unused exports and 433 unused files, mostly noise because fallow does not know the forge's entry points. The gate's
unused-exportsandunreachedrules already cover this. - Circular dependencies: fallow found 50. The gate has no cycle rule. I did not port one, because it needs a baseline and is its own change.
Not done
- The note does not block; that waits until its false-positive rate is measured.
- The tui
boot, MCPcalland*-fitclusters are listed but not folded. Each is a one-helper change for its own pull. - The
while (cond && Date.now() < deadline) await Bun.sleep(M)form (about 50 sites) is not converted, because each leaves adeadlinevariable behind. Loops with unbounded waits are also left.
Try it: run bun scripts/dupes.ts 15, bun scripts/dupes.ts --tune and bun test test/dupes.test.ts.
🤖 Generated with Claude Code
The report runs, its top clusters are listed below with the measured duplication rate, and one cluster is folded: the fixed-sleep polling loop. The tests that cover the change pass (a 46-file run, then the dupes, gate and honesty suites); I did not run the whole suite.
What changed
bun scripts/dupes.tsreads every function and test body undersrc/andtest/as a shape (scripts/dupes_shape.ts: names, strings and numbers taken out). It clusters three or more that are near-duplicates and prints each cluster with the shape its members all hold. It takes about 10 s.THRESHOLDis 0.55, the best F1 over 41 pairs I labeled from this repo (scripts/dupes-pairs.json,--tune), not the paper's 0.71. 0.55 gives precision 0.64 and recall 0.58 on those pairs, so treat it as a first tuning.test/dupes.test.tsholds the constant to the best-scoring threshold.boothelper intui-*tests (176 shared tokens).tool/call/mcphelpers in tests (77 shared tokens).*-timingpage tests (128 shared tokens).*-fittests, "no inline width…" (145 shared tokens).callhelpers (95 shared tokens).src/tui/screens/*screens (packScreenand its siblings, 173 shared tokens).asUser/webfetch helpers (161 shared tokens).for (let i = 0; i < N && cond; i++) await Bun.sleep(M), 70 copies across 46 tests. They now callwaitForintest/helpers/poll.ts, which waits the same interval for the same total time and, like the loop, does not throw.pollUntilnow sits on it.test-honesty-allow.jsondropped by the 70 waits (the committed allowance is 493 files). The 46 changed files pass: 453 pass, 1 skip.dupesNoteinscripts/gate.tsnames an existing function when a pull adds one at or over the threshold. It is a note only. It skips test bodies, since sibling tests read alike by design. It reads the whole tree, about 10 s, and only when the diff adds a function. On this pull it flagged my own test'sgithelper as 0.75 liketest/both-doors-refusal.test.ts#run. I left that duplicate in place.gate.tswrote the base-ref lookup out eleven times. It is now onebaseRef.AGENTS.mdsays how to run the report and when to usewaitFor.fallow, run once and read-only, off the checks path
unused-exportsandunreachedrules already cover this.Not done
boot, MCPcalland*-fitclusters are listed but not folded. Each is a one-helper change for its own pull.while (cond && Date.now() < deadline) await Bun.sleep(M)form (about 50 sites) is not converted, because each leaves adeadlinevariable behind. Loops with unbounded waits are also left.Try it: run
bun scripts/dupes.ts 15,bun scripts/dupes.ts --tuneandbun test test/dupes.test.ts.🤖 Generated with Claude Code
Closes #14620