MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / computeDominantFile

Method computeDominantFile

src/db/queries.ts:1443–1477  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1441 }
1442
1443 private computeDominantFile(): { filePath: string; edgeCount: number; nextEdgeCount: number } | null {
1444 if (!this.stmts.getDominantFile) {
1445 // Every file ranked; test/generated files are then filtered out in
1446 // code (regex-grade matching that SQL LIKE can't express). The
1447 // generated-file filter is critical — without it, etcd's
1448 // `api/etcdserverpb/rpc.pb.go` (1916 in-file edges, generated
1449 // protobuf stub) outranks the real `server/etcdserver/server.go`
1450 // (470 edges) by 4×, and the boost would push the agent toward
1451 // generated code.
1452 // Edges-first and tie-broken by path on purpose: see DOMINANT_FILE_SQL (#2571).
1453 this.stmts.getDominantFile = this.db.prepare(DOMINANT_FILE_SQL);
1454 }
1455 const rows = this.stmts.getDominantFile.all() as Array<{ file_path: string; edge_count: number }>;
1456 // The first two files the filter keeps, in rank order: the dominant file
1457 // and its runner-up. Filtering a 20-row window instead returned null once
1458 // 20 test files outranked the real code, and an understated runner-up
1459 // (0) once 19 did, which passes the caller's "3x the next file" test for
1460 // a file that is not dominant at all (#2578).
1461 const kept: Array<{ file_path: string; edge_count: number }> = [];
1462 for (let i = 0; i < rows.length && kept.length < 2; i += DOMINANT_FILE_BATCH) {
1463 const batch = rows.slice(i, i + DOMINANT_FILE_BATCH);
1464 const generated = this.getGeneratedPathsAmong(batch.map(r => r.file_path));
1465 for (const r of batch) {
1466 if (isLowValueFile(r.file_path, generated)) continue;
1467 kept.push(r);
1468 if (kept.length === 2) break;
1469 }
1470 }
1471 if (kept.length === 0 || kept[0]!.edge_count < 20) return null;
1472 return {
1473 filePath: kept[0]!.file_path,
1474 edgeCount: kept[0]!.edge_count,
1475 nextEdgeCount: kept[1]?.edge_count ?? 0,
1476 };
1477 }
1478
1479 /**
1480 * Find the file that holds the densest concentration of the project's

Callers 1

getDominantFileMethod · 0.95

Calls 6

isLowValueFileFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
prepareMethod · 0.65
allMethod · 0.65

Tested by

no test coverage detected