Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2b6a00d
fix: scope codegraph batch complexity targets to file paths
carlos-alm Jul 5, 2026
b28051a
fix: exclude parameters and interface/type members from dead-role cla…
carlos-alm Jul 5, 2026
17fbcba
fix: credit import-type usages as exports consumers
carlos-alm Jul 5, 2026
26918bb
fix: prevent fn-impact/query crash when -f/--file is passed
carlos-alm Jul 5, 2026
be6432c
fix: correct exported-symbol detection for literal and object-literal…
carlos-alm Jul 5, 2026
4ead840
fix: exclude primitive type keywords from ast --kind string matching
carlos-alm Jul 5, 2026
f6326bf
fix: resolve call edges through renamed import specifiers
carlos-alm Jul 5, 2026
590f560
fix: couple file_hashes updates with edge regeneration in incremental…
carlos-alm Jul 5, 2026
d3ea4a4
fix: compare signature-change diffs using new-file line ranges
carlos-alm Jul 5, 2026
c306812
feat: add environment doctor check for stale native binary and missin…
carlos-alm Jul 5, 2026
8bb5893
fix: eliminate non-deterministic ordering in community detection
carlos-alm Jul 6, 2026
46037b1
fix: sync update-graph.sh hook extension allowlist with EXTENSIONS
carlos-alm Jul 6, 2026
6a84cf9
fix: recompute directory structure metrics for affected directories o…
carlos-alm Jul 6, 2026
8d936d1
refactor: register hardcoded execFileSync/execSync maxBuffer values i…
carlos-alm Jul 6, 2026
11c84be
fix: gate blast-radius check on newly introduced risk, not pre-existi…
carlos-alm Jul 6, 2026
963301a
fix: gate identifier-argument dynamic call edges on callback-acceptin…
carlos-alm Jul 6, 2026
3e8035d
fix: gate Array.from's callback arg by position, not just callee name
carlos-alm Jul 6, 2026
879635e
fix: scope reexportedSymbols to actually-named re-export specifiers
carlos-alm Jul 6, 2026
0fe9fc3
fix: stop CFG block/edge count from overriding AST-derived cyclomatic…
carlos-alm Jul 6, 2026
ccf3c19
fix: backfill edges.technique for incrementally-inserted calls edges
carlos-alm Jul 6, 2026
d5b1162
fix: wrap remote embedding JSON parse failure in EngineError
carlos-alm Jul 6, 2026
8971017
refactor: extract shared platform-default-path helper in config.ts
carlos-alm Jul 6, 2026
056c5e4
refactor: decompose loadConfig and related high-effort functions in c…
carlos-alm Jul 6, 2026
0738171
refactor: decompose findDbPath and openRepo in db/connection.ts (docs…
carlos-alm Jul 6, 2026
6f2423c
refactor: dedupe busy/locked error detection into isBusyOrLockedError
carlos-alm Jul 6, 2026
4c02378
fix: log statSync failures in findDbPath instead of silently swallowi…
carlos-alm Jul 6, 2026
0698e16
test: add direct unit coverage for closeDbPair/closeDbPairDeferred/cl…
carlos-alm Jul 6, 2026
4ac3b99
fix: correct blast-radius/fn-impact computation for line-shifted decl…
carlos-alm Jul 6, 2026
6767f09
feat: wire points-to solver max-iterations cap through DEFAULTS.analy…
carlos-alm Jul 6, 2026
5f6f30a
refactor: route console.log calls in domain/search through logger
carlos-alm Jul 6, 2026
b479318
refactor: reduce cyclomatic complexity of computeDeltaModularityDirected
carlos-alm Jul 6, 2026
c39ac40
refactor: unify impact-level rendering format between audit and fn-im…
carlos-alm Jul 6, 2026
067674f
refactor: dedupe computeSavings via pct helper and persist partial to…
carlos-alm Jul 6, 2026
f6807b4
fix: add main.rs driver to rust dynamic tracer fixture
carlos-alm Jul 6, 2026
1c07a54
fix: scope diff file-header detection to between-hunk positions
carlos-alm Jul 6, 2026
bf82aa2
fix: update titan-grind's dead-symbol script for current roles --json…
carlos-alm Jul 6, 2026
cd02d27
fix: thread configured busyTimeoutMs through remaining read-only quer…
carlos-alm Jul 6, 2026
980b5dc
fix: resolve computed string-literal keys in object-literal extractio…
carlos-alm Jul 6, 2026
4a873a3
fix: add same-class bare-call fallback to incremental rebuild path (d…
carlos-alm Jul 6, 2026
8f3348a
fix: unify Object.defineProperty accessor fallback kind-filtering bet…
carlos-alm Jul 6, 2026
acf804c
refactor: share chunked statement-cache primitive between builder and…
carlos-alm Jul 6, 2026
986c851
refactor: cache prepared statements in applyEdgeTechniquesAfterNative…
carlos-alm Jul 6, 2026
71e9174
fix: replace fixed-depth directory-proximity check with symmetric dis…
carlos-alm Jul 6, 2026
d2935cc
refactor: remove unreachable Partition delta-computation interface me…
carlos-alm Jul 6, 2026
6515186
fix: emit reference edges for function identifiers used as object-lit…
carlos-alm Jul 6, 2026
30c491a
refactor: unify call-ref and tests rendering format between audit and…
carlos-alm Jul 6, 2026
9db911b
fix: classify destructured bindings as constant, not function (docs c…
carlos-alm Jul 6, 2026
70559fc
refactor: adopt timeMedian in remaining benchmark timing loops
carlos-alm Jul 6, 2026
822e0eb
refactor: decompose runPerfBenchmarks in token-benchmark.ts
carlos-alm Jul 6, 2026
fcdfe7d
fix: attribute liveness to Lua functions assigned to global/builtin i…
carlos-alm Jul 6, 2026
ee6362c
refactor: extract shared sedi() helper for tracer scripts
carlos-alm Jul 6, 2026
d4e6212
fix: restore reflection dynamicKind for .call/.apply/.bind (docs chec…
carlos-alm Jul 6, 2026
aec5d2b
fix: restrict entry-role classification to function/method-kind symbo…
carlos-alm Jul 6, 2026
8ad73c9
fix: resolve merge conflicts with main
carlos-alm Jul 8, 2026
5e2d671
fix: make RoleClassificationNode.kind required (#1919)
carlos-alm Jul 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions crates/codegraph-core/src/graph/classifiers/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,20 @@ fn classify_node(
}

if fan_in == 0 && is_exported {
return "entry";
// Exported, zero fan-in. A genuine entry point (CLI command handler,
// exported API function called from outside the codebase, ESM loader
// hook, MCP tool handler, etc.) is always a function or method. Every
// other exported kind (interface/type/constant/class) is a live,
// intentional part of the public surface — but a data shape or config
// value, not something invoked from outside the codebase — so it's
// `leaf`: never `dead-*` (#1583) and never `entry` (#1780), regardless
// of whether the file has other active siblings. Mirrors JS
// `classifyNodeRole`.
return if kind == "function" || kind == "method" {
"entry"
} else {
"leaf"
};
}

// Test-only: has callers but all are in test files
Expand Down Expand Up @@ -403,6 +416,15 @@ pub(crate) fn do_classify_full(conn: &Connection) -> rusqlite::Result<RoleSummar
// (e.g. index.ts re-exports from internal.ts which re-exports from core.ts).
// Then: any symbol whose file is a reexport target of a prod-reachable barrel
// is considered exported (prevents false dead-code classification).
//
// `method` is excluded (#1780): a `reexports` edge only ever concerns
// top-level module bindings (functions, classes, types, constants, ...) —
// a class/interface method can never be an independently re-exportable
// binding on its own, so inheriting "exported" status from a co-located
// top-level re-export is a category error. Without this exclusion, e.g. an
// abstract base class's zero-fan-in method declarations were promoted to
// `entry` merely because some other symbol in the same file was re-exported
// through a barrel.
{
let sql = format!(
"WITH RECURSIVE prod_reachable(file_id) AS (
Expand All @@ -426,7 +448,7 @@ pub(crate) fn do_classify_full(conn: &Connection) -> rusqlite::Result<RoleSummar
WHERE e.kind = 'reexports'
AND e.source_id IN (SELECT file_id FROM prod_reachable)
)
AND n.kind NOT IN ('file', 'directory', 'parameter', 'property')",
AND n.kind NOT IN ('file', 'directory', 'parameter', 'property', 'method')",
test_file_filter_col("src.file")
);
let mut stmt = tx.prepare(&sql)?;
Expand Down Expand Up @@ -950,6 +972,8 @@ pub(crate) fn do_classify_incremental(
// (typically 1-3 files), then answer "is this specific barrel
// production-reachable" with a backward-scoped check instead of the
// whole-graph forward closure (see `is_barrel_prod_reachable`).
//
// `method` is excluded (#1780) — see the full-classify path for rationale.
{
let barrels = find_direct_reexport_barrels(&tx, &affected_ph, &all_affected)?;
let mut reachable_barrels: Vec<&str> = Vec::with_capacity(barrels.len());
Expand All @@ -969,7 +993,7 @@ pub(crate) fn do_classify_incremental(
JOIN edges e ON e.target_id = f.id
JOIN nodes b ON e.source_id = b.id
WHERE e.kind = 'reexports' AND b.file IN ({barrel_ph})
AND n.kind NOT IN ('file', 'directory', 'parameter', 'property')
AND n.kind NOT IN ('file', 'directory', 'parameter', 'property', 'method')
AND n.file IN ({affected_ph})"
);
let mut stmt = tx.prepare(&sql)?;
Expand Down
15 changes: 13 additions & 2 deletions src/features/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,15 @@ function classifyNodeRolesFull(db: BetterSqlite3Database, emptySummary: RoleSumm

// Mark symbols as exported when their files are targets of reexports edges
// from production-reachable barrels (traces through multi-level chains) (#837)
//
// `method` is excluded (#1780): a `reexports` edge only ever concerns
// top-level module bindings (functions, classes, types, constants, ...) — a
// class/interface method can never be an independently re-exportable
// binding on its own, so inheriting "exported" status from a co-located
// top-level re-export is a category error. Without this exclusion, e.g. an
// abstract base class's zero-fan-in method declarations were promoted to
// `entry` merely because some other symbol in the same file was re-exported
// through a barrel.
const reexportExported = db
.prepare(
`WITH RECURSIVE prod_reachable(file_id) AS (
Expand All @@ -852,7 +861,7 @@ function classifyNodeRolesFull(db: BetterSqlite3Database, emptySummary: RoleSumm
WHERE e.kind = 'reexports'
AND e.source_id IN (SELECT file_id FROM prod_reachable)
)
AND n.kind NOT IN ('file', 'directory', 'parameter', 'property')`,
AND n.kind NOT IN ('file', 'directory', 'parameter', 'property', 'method')`,
)
.all() as { id: number }[];
for (const r of reexportExported) exportedIds.add(r.id);
Expand Down Expand Up @@ -1127,6 +1136,8 @@ function classifyNodeRolesIncremental(
// 1-3 files), then answer "is this specific barrel production-reachable"
// with a backward-scoped check instead of the whole-graph forward closure
// (see `isBarrelProdReachable`).
//
// `method` is excluded (#1780) — see classifyNodeRolesFull for rationale.
const reexportBarrels = findDirectReexportBarrels(db, allAffectedFiles);
const reachableBarrels = reexportBarrels.filter((b) => isBarrelProdReachable(db, b));
if (reachableBarrels.length > 0) {
Expand All @@ -1139,7 +1150,7 @@ function classifyNodeRolesIncremental(
JOIN edges e ON e.target_id = f.id
JOIN nodes b ON e.source_id = b.id
WHERE e.kind = 'reexports' AND b.file IN (${barrelPlaceholders})
AND n.kind NOT IN ('file', 'directory', 'parameter', 'property')
AND n.kind NOT IN ('file', 'directory', 'parameter', 'property', 'method')
AND n.file IN (${placeholders})`,
)
.all(...reachableBarrels, ...allAffectedFiles) as { id: number }[];
Expand Down
18 changes: 16 additions & 2 deletions src/graph/classifiers/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
* `isTypeDeclarationMember` and classified `leaf` unconditionally — they can
* never gain inbound call edges by construction, so call-graph reachability
* doesn't apply to them either (#1723).
*
* `entry` requires `kind IN ('function', 'method')` (plus the framework-prefix/
* Commander-dispatch shortcuts, which are already kind-appropriate by
* construction). An exported interface/type/constant/class with zero fan-in is
* a data-shape declaration or config value — never invoked from outside the
* codebase — so it can't be a real entry point; it's classified `leaf` instead
* of inheriting `entry` merely from being exported (#1780).
*/

import type { DeadSubRole, Role } from '../../types.js';
Expand Down Expand Up @@ -149,7 +156,7 @@ export function median(sorted: number[]): number {
export interface RoleClassificationNode {
id: string;
name: string;
kind?: string;
kind: string;
file?: string;
fanIn: number;
fanOut: number;
Expand Down Expand Up @@ -281,7 +288,14 @@ function classifyNodeRole(
}
return classifyUnreferencedNode(node);
}
return 'entry';
// Exported, zero fan-in. A genuine entry point (CLI command handler, exported
// API function called from outside the codebase, ESM loader hook, MCP tool
// handler, etc.) is always a function or method. Every other exported kind
// (interface/type/constant/class) is a live, intentional part of the public
// surface — but a data shape or config value, not something invoked from
// outside the codebase — so it's `leaf`: never `dead-*` (#1583) and never
// `entry` (#1780), regardless of whether the file has other active siblings.
return node.kind === 'function' || node.kind === 'method' ? 'entry' : 'leaf';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 kind is optional but the new branch silently returns 'leaf' when it is undefined

RoleClassificationNode.kind is typed as kind?: string (line 159), yet the new ternary node.kind === 'function' || node.kind === 'method' returns 'leaf' whenever kind is undefined. Before this change the same branch always returned 'entry'. Any caller that constructs an exported, zero-fan-in RoleClassificationNode without supplying kind — perfectly valid per the public interface — will silently get 'leaf' instead of the previous 'entry'. The updated unit test exposed this gap by adding kind: 'function' to the fixture that previously omitted it. Since all production DB queries already select n.kind, the safest fix is to make kind required in the interface, closing the contract gap without changing runtime behavior.

Fix in Claude Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — made kind required on RoleClassificationNode in 5e2d6718. Verified all 3 production callers already supply it via a clean tsc build (no new type errors), and buildClassifierInput in structure.ts already declared its own internal return type as kind: string non-optional, so this just closes the gap in the public interface to match reality.

}

const hasProdFanIn = typeof node.productionFanIn === 'number';
Expand Down
142 changes: 140 additions & 2 deletions tests/graph/classifiers/roles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ describe('classifyRoles', () => {
expect(classifyRoles([]).size).toBe(0);
});

it('classifies entry nodes (no fan-in, exported)', () => {
const nodes = [{ id: '1', name: 'init', fanIn: 0, fanOut: 3, isExported: true }];
it('classifies entry nodes (no fan-in, exported, function kind)', () => {
const nodes = [
{ id: '1', name: 'init', kind: 'function', fanIn: 0, fanOut: 3, isExported: true },
];
const roles = classifyRoles(nodes);
expect(roles.get('1')).toBe('entry');
});
Expand Down Expand Up @@ -628,4 +630,140 @@ describe('classifyRoles', () => {
const roles = classifyRoles(nodes);
expect(roles.get('2')).toBe('dead-unresolved');
});

// ── entry role requires function/method kind (#1780) ───────────────

it('classifies an exported interface with zero fan-in as leaf, not entry', () => {
// Mirrors the #1780 repro: `interface ParsedUserConfig { ... }` in
// src/infrastructure/config.ts. Even if the symbol were exported, an
// interface is a data-shape declaration, never a callable entry point.
const nodes = [
{
id: '1',
name: 'ParsedUserConfig',
kind: 'interface',
file: 'src/infrastructure/config.ts',
fanIn: 0,
fanOut: 0,
isExported: true,
},
];
const roles = classifyRoles(nodes);
expect(roles.get('1')).toBe('leaf');
});

it('classifies an exported constant with zero fan-in as leaf, not entry', () => {
// Mirrors the #1780 repro: module-level `const BUILD_HASH_KEYS = [...]`.
// A constant can never be an invoked entry point regardless of export status.
const nodes = [
{
id: '1',
name: 'BUILD_HASH_KEYS',
kind: 'constant',
file: 'src/infrastructure/config.ts',
fanIn: 0,
fanOut: 0,
isExported: true,
},
];
const roles = classifyRoles(nodes);
expect(roles.get('1')).toBe('leaf');
});

it('classifies an exported class with zero fan-in as leaf, not entry', () => {
// A class declaration itself is instantiated via `new`, not "invoked" the
// way a CLI command handler or API function is — not a real entry point.
const nodes = [
{
id: '1',
name: 'Widget',
kind: 'class',
file: 'src/widget.ts',
fanIn: 0,
fanOut: 0,
isExported: true,
},
];
const roles = classifyRoles(nodes);
expect(roles.get('1')).toBe('leaf');
});

it('classifies an exported type alias with zero fan-in as leaf, not entry', () => {
const nodes = [
{
id: '1',
name: 'WorkspaceEntry',
kind: 'type',
file: 'src/infrastructure/config.ts',
fanIn: 0,
fanOut: 0,
isExported: true,
},
];
const roles = classifyRoles(nodes);
expect(roles.get('1')).toBe('leaf');
});

it('still classifies an exported function with zero fan-in as entry (no over-correction)', () => {
// Genuine entry points (CLI handlers, MCP tool handlers, ESM loader hooks)
// are, by definition, called from outside the codebase, so zero in-repo
// fan-in is expected and correct for them — the fix must not lose this.
const nodes = [
{
id: '1',
name: 'handler',
kind: 'function',
file: 'src/mcp/tools/audit.ts',
fanIn: 0,
fanOut: 4,
isExported: true,
},
];
const roles = classifyRoles(nodes);
expect(roles.get('1')).toBe('entry');
});

it('still classifies an exported method with zero fan-in as entry (no over-correction)', () => {
const nodes = [
{
id: '1',
name: 'run',
kind: 'method',
file: 'src/cli/commands/custom.ts',
fanIn: 0,
fanOut: 2,
isExported: true,
},
];
const roles = classifyRoles(nodes);
expect(roles.get('1')).toBe('entry');
});

it('classifies a non-exported interface with zero fan-in the same as an exported one (leaf, active siblings)', () => {
// Whether or not the interface itself is exported, it's still not a
// callable entry point — both must land on the same non-entry path.
const nodes = [
{
id: '1',
name: 'ConsentResolutionResult',
kind: 'interface',
file: 'src/infrastructure/config.ts',
fanIn: 0,
fanOut: 0,
isExported: false,
hasActiveFileSiblings: true,
},
{
id: '2',
name: 'loadConfig',
kind: 'function',
file: 'src/infrastructure/config.ts',
fanIn: 5,
fanOut: 3,
isExported: true,
},
];
const roles = classifyRoles(nodes);
expect(roles.get('1')).toBe('leaf');
});
});
17 changes: 17 additions & 0 deletions tests/integration/roles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ describe('barrel re-export role classification', () => {
const _helperFn = insertNode(db, 'helperFn', 'function', 'src/inspect.ts', 30);
const _appMain = insertNode(db, 'appMain', 'function', 'src/app.ts', 1);
const testFn = insertNode(db, 'testQueryName', 'function', 'tests/inspect.test.ts', 1);
// A class-method-kind member (e.g. an abstract base-class method) in the same
// re-exported file, with no callers and no outgoing calls (#1780).
const _abstractHelper = insertNode(db, 'abstractHelper', 'method', 'src/inspect.ts', 50);

// Barrel re-exports inspect.ts
insertEdge(db, fBarrel, fInspect, 'reexports');
Expand Down Expand Up @@ -156,6 +159,20 @@ describe('barrel re-export role classification', () => {
// With fanIn=0 and isExported=true → entry (exported but uncalled)
expect(helperResult!.role).toBe('entry');
});

test('method-kind member in a re-exported file does not inherit exported status (#1780)', () => {
// A `reexports` edge only ever concerns top-level module bindings — a class
// method can never be an independently re-exportable binding on its own, so
// it must not inherit "exported" status merely because a sibling top-level
// symbol (helperFn/queryName) in the same file is re-exported through the
// barrel. Before the fix, this method landed on `entry` the same way
// `helperFn` incorrectly did; it must now fall through to normal dead-code
// classification instead (no callers, no outgoing calls → dead-unresolved).
const data = rolesData(barrelDbPath);
const methodResult = data.symbols.find((s) => s.name === 'abstractHelper');
expect(methodResult).toBeDefined();
expect(methodResult!.role).toBe('dead-unresolved');
});
});

// ─── Multi-level barrel re-export chain (#837) ───────────────────────
Expand Down
Loading
Loading