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

Method computeDominantFile

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

Source from the content-addressed store, hash-verified

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