feat: Add edge recovery to restore connectivity after node trimming in context building

Addresses cases where BFS with multiple entry points leaves most nodes disconnected after trimming. Discovers edges between already-selected nodes using specific relationship types (calls, extends, implements, references, overrides) to recover inter-node connectivity that would otherwise be lost during the node selection process.
This commit is contained in:
Colby McHenry
2026-04-06 16:08:42 -05:00
parent f668b2cd1c
commit d9e973cffc
2 changed files with 49 additions and 11 deletions
+20
View File
@@ -859,6 +859,26 @@ export class QueryBuilder {
return rows.map(rowToEdge);
}
/**
* Find all edges where both source and target are in the given node set.
* Useful for recovering inter-node connectivity after BFS.
*/
findEdgesBetweenNodes(nodeIds: string[], kinds?: EdgeKind[]): Edge[] {
if (nodeIds.length === 0) return [];
const idsJson = JSON.stringify(nodeIds);
let sql = `SELECT * FROM edges WHERE source IN (SELECT value FROM json_each(?)) AND target IN (SELECT value FROM json_each(?))`;
const params: string[] = [idsJson, idsJson];
if (kinds && kinds.length > 0) {
sql += ` AND kind IN (${kinds.map(() => '?').join(',')})`;
params.push(...kinds);
}
const rows = this.db.prepare(sql).all(...params) as EdgeRow[];
return rows.map(rowToEdge);
}
// ===========================================================================
// File Operations
// ===========================================================================