Skip to content

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

chore(dashboard): address Task 2 + 3 review minors

Lum1104a2b8f2781057
diff --git a/understand-anything-plugin/packages/dashboard/src/utils/__tests__/containers.test.ts b/understand-anything-plugin/packages/dashboard/src/utils/__tests__/containers.test.ts
index 058039db..b5d6d407 100644
--- a/understand-anything-plugin/packages/dashboard/src/utils/__tests__/containers.test.ts
+++ b/understand-anything-plugin/packages/dashboard/src/utils/__tests__/containers.test.ts
@@ -10,6 +10,7 @@ function node(id: string, filePath?: string): GraphNode {
filePath,
summary: "",
complexity: "simple",
+ tags: [],
} as GraphNode;
}
@@ -113,13 +114,18 @@ describe("deriveContainers — community fallback", () => {
}
});
- it("falls back when one folder holds > 60%", () => {
+ it("falls back when one folder holds > 70%", () => {
const nodes = [
...Array.from({ length: 8 }, (_, i) => node(`big${i}`, `big/file${i}.go`)),
node("a", "small1/a.go"),
node("b", "small2/b.go"),
];
- const { containers } = deriveContainers(nodes, []);
- expect(containers.every((c) => c.strategy === "community")).toBe(true);
+ const { containers, ungrouped } = deriveContainers(nodes, []);
+ // Folder strategy would have produced a 'big' container with 8 children.
+ // Community fallback (no edges) gives each node its own community → all
+ // single-child → all suppressed. The non-vacuous evidence the fallback
+ // path was taken: NO folder-strategy 'big' container survives.
+ expect(containers.find((c) => c.strategy === "folder" && c.name === "big")).toBeUndefined();
+ expect(ungrouped.length).toBe(10);
});
});
diff --git a/understand-anything-plugin/packages/dashboard/src/utils/containers.ts b/understand-anything-plugin/packages/dashboard/src/utils/containers.ts
index fc2a902e..dd885219 100644
--- a/understand-anything-plugin/packages/dashboard/src/utils/containers.ts
+++ b/understand-anything-plugin/packages/dashboard/src/utils/containers.ts
@@ -56,8 +56,12 @@ function groupByFolder(
const lcp = commonPrefix(withPath.map((n) => n.filePath!));
const groups = new Map<string, string[]>();
const rooted: string[] = [];
- for (const n of withPath) {
- const stripped = n.filePath!.slice(lcp.length);
+ for (const n of nodes) {
+ if (!n.filePath) {
+ rooted.push(n.id);
+ continue;
+ }
+ const stripped = n.filePath.slice(lcp.length);
if (!stripped.includes("/")) {
rooted.push(n.id);
continue;
@@ -67,9 +71,6 @@ function groupByFolder(
arr.push(n.id);
groups.set(seg, arr);
}
- for (const n of nodes) {
- if (!n.filePath) rooted.push(n.id);
- }
return { groups, rooted };
}
@@ -114,7 +115,9 @@ export function deriveContainers(
const sorted = [...byCommunity.entries()].sort((a, b) => a[0] - b[0]);
containers = sorted.map(([cid, ids], i) => ({
id: `container:cluster-${cid}`,
- name: `Cluster ${String.fromCharCode(65 + i)}`,
+ // A-Z for the first 26, then numeric. Avoids `String.fromCharCode(65+i)`
+ // wrapping into `[`, `\`, `]` ... once the cluster count exceeds 26.
+ name: i < 26 ? `Cluster ${String.fromCharCode(65 + i)}` : `Cluster ${i + 1}`,
nodeIds: ids,
strategy: "community" as const,
}));
diff --git a/understand-anything-plugin/packages/dashboard/src/utils/louvain.ts b/understand-anything-plugin/packages/dashboard/src/utils/louvain.ts
index e865fec4..df18fb4a 100644
--- a/understand-anything-plugin/packages/dashboard/src/utils/louvain.ts
+++ b/understand-anything-plugin/packages/dashboard/src/utils/louvain.ts
@@ -5,8 +5,14 @@ import type { GraphEdge } from "@understand-anything/core/types";
/**
* Run Louvain community detection over the provided node set and the
* subset of edges whose endpoints are both in the set. Returns a map of
- * nodeId → communityId. Disconnected nodes get unique community ids so
- * they don't collapse into a single cluster.
+ * nodeId → communityId.
+ *
+ * graphology-communities-louvain v2 already gives each disconnected node
+ * its own community id, but the contract isn't documented. The
+ * post-Louvain reassignment loop below is defensive: if a future version
+ * starts returning -1 (or omits a node, which the `?? -1` catches) for
+ * unmatched nodes, we'll still hand back unique ids rather than letting
+ * them collapse into a single cluster.
*/
export function detectCommunities(
nodeIds: string[],
@@ -27,7 +33,9 @@ export function detectCommunities(
for (const id of nodeIds) {
map.set(id, result[id] ?? -1);
}
- // Reassign disconnected nodes (community -1) to unique ids past the max
+ // Defensive: reassign any -1 sentinels to unique ids past the max.
+ // See the JSDoc on detectCommunities for why this is kept despite the
+ // current library already producing unique ids for disconnected nodes.
let next =
Math.max(...Array.from(map.values()).filter((v) => v >= 0), -1) + 1;
for (const [id, c] of map) {