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

Method getDominantFile

src/db/queries.ts:904–932  ·  view source on GitHub ↗

* Find the file that holds the densest concentration of the project's * internal call graph — the "core" file. Used by context-builder to * boost ranking of symbols in that file's directory (so e.g. sinatra * queries surface `lib/sinatra/base.rb`'s `route!` instead of * `sinatra-contrib/

()

Source from the content-addressed store, hash-verified

902 * boosting a test file's directory would be a misfire.
903 */
904 getDominantFile(): { filePath: string; edgeCount: number; nextEdgeCount: number } | null {
905 if (!this.stmts.getDominantFile) {
906 // Pull top 20 candidates; we then filter out test/generated files
907 // in code (regex-grade matching that SQL LIKE can't express). The
908 // generated-file filter is critical — without it, etcd's
909 // `api/etcdserverpb/rpc.pb.go` (1916 in-file edges, generated
910 // protobuf stub) outranks the real `server/etcdserver/server.go`
911 // (470 edges) by 4×, and the boost would push the agent toward
912 // generated code.
913 this.stmts.getDominantFile = this.db.prepare(`
914 SELECT n.file_path AS file_path, COUNT(*) AS edge_count
915 FROM edges e
916 JOIN nodes n ON e.source = n.id
917 JOIN nodes m ON e.target = m.id
918 WHERE n.file_path = m.file_path
919 GROUP BY n.file_path
920 ORDER BY edge_count DESC
921 LIMIT 20
922 `);
923 }
924 const rows = this.stmts.getDominantFile.all() as Array<{ file_path: string; edge_count: number }>;
925 const filtered = rows.filter(r => !isLowValueFile(r.file_path));
926 if (filtered.length === 0 || filtered[0]!.edge_count < 20) return null;
927 return {
928 filePath: filtered[0]!.file_path,
929 edgeCount: filtered[0]!.edge_count,
930 nextEdgeCount: filtered[1]?.edge_count ?? 0,
931 };
932 }
933
934 /**
935 * Find the file that holds the densest concentration of the project's

Callers 1

findRelevantContextMethod · 0.80

Calls 3

isLowValueFileFunction · 0.85
prepareMethod · 0.65
allMethod · 0.65

Tested by

no test coverage detected