From ef0c65aa17b7a89d883f3102d06df20fd5c36736 Mon Sep 17 00:00:00 2001 From: Nikola Chetelyazov Date: Mon, 13 Apr 2026 09:47:16 +0300 Subject: [PATCH] refactor: deduplicate import and call edges via edgeKeys set addImportEdge and addCallEdge previously pushed edges unconditionally, allowing duplicate relationships if multiple agents reported the same import or call. A shared edgeKeys set keyed on type|source|target silently skips any edge that has already been recorded. --- .../packages/core/src/analyzer/graph-builder.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts b/understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts index d77155b..e2dd645 100644 --- a/understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts +++ b/understand-anything-plugin/packages/core/src/analyzer/graph-builder.ts @@ -127,6 +127,7 @@ export class GraphBuilder { private readonly edges: GraphEdge[] = []; private readonly languages = new Set(); private readonly nodeIds = new Set(); + private readonly edgeKeys = new Set(); private readonly projectName: string; private readonly gitHash: string; @@ -235,6 +236,9 @@ export class GraphBuilder { } addImportEdge(fromFile: string, toFile: string): void { + const key = `imports|file:${fromFile}|file:${toFile}`; + if (this.edgeKeys.has(key)) return; + this.edgeKeys.add(key); this.edges.push({ source: `file:${fromFile}`, target: `file:${toFile}`, @@ -250,6 +254,9 @@ export class GraphBuilder { calleeFile: string, calleeFunc: string, ): void { + const key = `calls|function:${callerFile}:${callerFunc}|function:${calleeFile}:${calleeFunc}`; + if (this.edgeKeys.has(key)) return; + this.edgeKeys.add(key); this.edges.push({ source: `function:${callerFile}:${callerFunc}`, target: `function:${calleeFile}:${calleeFunc}`,