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:
@@ -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
|
||||
// ===========================================================================
|
||||
|
||||
Reference in New Issue
Block a user