feat(ui): dead code and islands — what nothing reaches, and everything that could still reach it (CG-59)

A Dead code screen and a mark on the Map, both drawn from one derivation in
src/graph/dead-code.ts so a second surface can never disagree with the first.

The SQL half is four lines — no incoming edge but `contains`. It returns ~2 500
candidates on this repository and the shipped list is 20; everything in between
is the feature. A candidate is dropped the moment there is any reason to believe
something outside the graph reaches it: exported symbols and header
declarations, test and generated files, abstract and interface members, anything
carrying a `decorates` edge, overrides of an ancestor's member, names the
language calls by itself, vendored directories, files nothing in the index
reaches (those are islands, and the Map says so instead), names the resolver
failed to resolve somewhere, and names shared with a symbol that IS referenced —
the mis-resolution that leaves a used method with a self-edge and its twin with
nothing. The last rule is the only one that is not a graph query: before a claim
is made, the declaring file and every file that reaches it are read and the
identifier counted, which is what catches the references the extractor never
recorded (`this.handleMessage.bind(this)`, a call inside an object literal, a
shorthand property).

Every subtraction is counted and printed under the list with the scale it came
from, and the caveat line above it never collapses: the claim is "no static
reference in the index", not "unused".

On the Map a module nothing depends on keeps its stroke and says so in its count
line, and tool-generated files and modules recede to ink-4 there, in the map's
file list, in search results and on the file screen.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Colby McHenryandClaude Opus 5 committed 2026-08-27 07:57:00 -05:00
1 parent 2a0c6dc58f
commit 56dfdb0655
32 files changed
+2800 -39

No files matched your search

+41
View File
@@ -1405,6 +1405,47 @@ export class CodeGraph {
return this.queries.countOutgoingEdges(ids);
}
/**
* Symbols nothing in the index points at, by kind — the candidate set the
* dead code report (`src/graph/dead-code.ts`) applies its exclusions to.
*
* Every edge kind except `contains` counts as a reference, so a method is
* not "reached" by the class that holds it. An unreferenced symbol is not
* yet a dead one: see {@link buildDeadCodeReport}.
*/
getUnreferencedNodes(
kinds: readonly Node['kind'][],
limit: number
): Array<{ node: Node; generated: boolean }> {
return this.queries.getUnreferencedNodes(kinds, limit);
}
/**
* Which of the given names are carried by more than one symbol, at least one
* of which something references — the names a "nothing reaches this" claim
* must not be made about, because the resolver may have picked the twin.
*/
getAmbiguousReferencedNames(names: Iterable<string>): Set<string> {
return this.queries.getAmbiguousReferencedNames(names);
}
/**
* Which of the given languages this index records an export marker for. A
* language with none has no "reachable from outside" signal at all.
*/
getLanguagesWithExports(languages: Iterable<string>): Set<string> {
return this.queries.getLanguagesWithExports(languages);
}
/**
* Which of the given names the index holds an unresolved reference to — the
* resolver saw the name and could not decide what it meant. A symbol with
* such a name can never be called unreferenced.
*/
getUnresolvedNamesAmong(names: Iterable<string>): Set<string> {
return this.queries.getUnresolvedNamesAmong(names);
}
/**
* The symbols with the most distinct dependents, most first — the index's
* hubs. Distinct dependents, not edges: a helper called forty times from one