Skip to content

feat(findings): duplicate-type flags a local copy of an exported object type - #483

Merged
byronwall merged 3 commits into
claude/refs-clifrom
claude/duplicate-type
Nov 28, 2026
Merged

byronwall merged 3 commits into
claude/refs-clifrom
claude/duplicate-type

Conversation

@byronwall

@byronwall byronwall commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

srcly now reports a new finding, duplicate-type: a file that declares its own object type while another file exports a type with the same name and mostly the same fields. A change to the exported type does not reach the copy, and a cast like fetchDoc(id) as Promise<DocDetail> hides that from tsc. The finding names the exported type and how many fields match, so the fix is clear: import or derive the type, then delete the copy.

User impact: A new warning in findings: in srcly report's checks line, the findings queue, the file findings in the code viewer, and the findings counts. The UI itself does not change.

Why

In the Visual Notes cleanup probe (byronwall/visual-notes#361), a name-only scan of the symbol index found 59 type names declared in more than one file. Most were noise, such as 44 local Props and 40 exported RootProps. Ranking by field overlap by hand found the two real DocDetail copies. This rule does that ranking. It is step 2 of the cleanup loop in planning TASK-0017 (srcly-cleanup-loop.md). The probe also showed its second use: a rescan proves at product scope that the copies are gone and nothing new appeared.

How it decides

A non-exported top-level type X = { … } or interface X { … } is reported when another non-test file exports an object type X, and at least 3 of the copy's fields, and at least half of them, match that type by name and declared type. Type comparison ignores formatting and comments but keeps literal text, so "In Progress" is not "InProgress". Two-field shapes such as Point { x, y } stay out. So do same-named types whose fields differ in type, such as a layout TreeNode and the compare payload's TreeNode. The rule never claims two types are the same contract. Tests and .d.ts files are skipped.

Proof

The rule on Visual Notes main (d59937fe, 1,321 TS files, 1.1 s):

src/components/DocumentSidePanel.tsx:25 `DocDetail` copies the exported `DocDetail` in src/services/docs.queries.ts:10 (8 of its 8 fields have the same name and type). …
src/components/editor/ui/PromptsManagerModal.tsx:15 `Prompt` copies the exported `Prompt` in src/services/prompts/prompts.queries.ts:4 (6 of its 7 fields have the same name and type). …
src/routes/docs/[id].tsx:28 `DocDetail` copies the exported `DocDetail` in src/services/docs.queries.ts:10 (11 of its 11 fields have the same name and type). …
src/routes/embeddings/[id].tsx:68 `UmapRunSummary` copies the exported `UmapRunSummary` in src/services/umap/umap.queries.ts:7 (4 of its 4 fields have the same name and type). …
src/services/research/research.activity.ts:15 `Topic` copies the exported `Topic` in src/server/mcp/research-shared.ts:23 (3 of its 3 fields have the same name and type). …

On the visual-notes#361 branch, which removes the DocDetail copies, the same run gives 3 findings: the two DocDetail rows are gone and nothing new appears. srcly report lists the rule beside the others:

- Lint/type checks: ruff (srcly defaults): 0 findings, 0 errors; srcly TS rules: 146 findings, 0 errors; srcly reachability: 574 findings, 0 errors; srcly Solid rules: 0 findings, 0 errors; srcly await-in-loop: 94 findings, 0 errors; srcly duplicate types: 5 findings, 0 errors

Precision on other repos, every hit read by hand:

Repo TS files Findings Read as
Visual Notes main 1,321 5 5 real copies (above)
srcly (this branch) 689 6 6 real copies: 4 copies of EvidenceElement in engine/src/analysis/scope-adapters/, Rect in DependencyCanvas.tsx, Trace in survey-report.ts
explorEDA 869 1 1 real copy: Box in treemapLayout.ts

Before field types counted, srcly also flagged its layout TreeNode against the compare payload's TreeNode (3 of 6 names shared). That was a false positive, and the type check removed it.

I also checked recall on Visual Notes. 22 names have one exported declaration and at least one local one. For 10 of them, both sides are object types. The rule reports 4 of those 10 (DocDetail, Prompt, UmapRunSummary, Topic). It drops 6: Point (nine copies that share only x and y), and Bounds, Change, Placed, EmbeddingRun and Source, which have 0 or 1 matching fields. The other 12 names have no object-type pair (unions such as ChunkerMode, aliases, or one side not an object).

Tests: tests/test_duplicate_types.py (copies with quoted and optional keys, an interface exported through export { Run }, look-alikes that must stay quiet, literal types, both default-export forms, oversized files, timeout). tests/test_findings.py now lists the new tool. scripts/check.sh server passes.

Codex review (gpt-6.2-sol), round 1: PASS, no P0 or P1 in this diff. Its three P2s are fixed in this PR: literal types kept whole, export default Name counted as an export, and the scan's 2 MiB file cap plus a deadline check after parsing. The close step's three class tests are added.

Survey moves: pnpm survey-gate on the stack (base 54bf3bba → head 63b6f11d) moved only server: traces +2, outcome partial +2, stop frontier: external-code +30. No analysis code changed. The two new corpus modules, server/app/services/symbols/refs.py and server/app/services/findings/duplicate_types.py, add exported functions to the survey's export sample. Their traces stop where they call tree-sitter, pathlib and the symbol index.

Limits

  • Union and alias copies (type ChunkerMode = "a" | "b" declared twice) are not compared.
  • Two exported types with the same name are not reported. Both are public, so neither is a hidden copy.
  • The match is syntactic: NoteDoc and an alias of it count as different types.
  • Codex found three gaps in the symbol index behind srcly refs (layer 1). They predate this stack. refs misses import("…").Type inline type references. It loses callers when a module imports a type and re-exports it. It merges a type and a value that share a name. They are worth a follow-up, because refs is how an agent maps callers before it deletes a copy.

Stack: cleanup-loop helpers, layer 2 of 3

This slice: the duplicate-type finding.
Why it is its own layer: It changes analysis output and needed its own review and survey check. srcly refs below it is a read-only view of existing data.
Full story: #482

🤖 Generated with Claude Code

@byronwall
byronwall added this pull request to stack #484 November 28, 2026 03:30
@byronwall byronwall changed the title claude/duplicate type feat(findings): duplicate-type flags a local copy of an exported object type Nov 28, 2026
byronwall and others added 3 commits November 28, 2026 00:05
…ct type

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rt default, caps file size

From Codex review round 1 (P2s): compare type tokens instead of text with
all whitespace removed, count `export default Name` as an export, skip
files over the scan's size cap, and check the deadline after parsing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sees both default exports

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@byronwall
byronwall force-pushed the claude/duplicate-type branch from 63b6f11 to 085c068 Compare November 28, 2026 05:05
@byronwall
byronwall removed this pull request from stack #484 November 28, 2026 05:05
@byronwall
byronwall added this pull request to stack #480 November 28, 2026 05:05
@byronwall
byronwall merged commit 62bfe6c into main Nov 28, 2026
13 of 14 checks passed
@byronwall
byronwall deleted the claude/duplicate-type branch November 28, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant