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.
TypeScript antigravity-skillsbusiness-knowledgeclaude-codeclaude-skillscodebase-analysiscodexcodex-skillsdeveloper-tools-ai-agentgemini-cli-skillskarpathy-llm-wikiknowledge-baseknowledge-graphmemoryopencode-skillspi-agentunderstandcodevibe-coding
Merge branch 'main' into pr44/improve-dashboard-ux
Lum11043cdc2ac71bc4
diff --cc understand-anything-plugin/packages/dashboard/src/components/GraphView.tsxindex f57ec8f3,561feff1..4f7350a1--- a/understand-anything-plugin/packages/dashboard/src/components/GraphView.tsx+++ b/understand-anything-plugin/packages/dashboard/src/components/GraphView.tsx@@@ -15,36 -15,24 +15,37 @@@ import "@xyflow/react/dist/style.css"import CustomNode from "./CustomNode";import type { CustomFlowNode } from "./CustomNode";+import LayerClusterNode from "./LayerClusterNode";+import type { LayerClusterFlowNode } from "./LayerClusterNode";+import PortalNode from "./PortalNode";+import type { PortalFlowNode } from "./PortalNode";+import Breadcrumb from "./Breadcrumb";import { useDashboardStore } from "../store";+ import { useTheme } from "../themes/index.ts";-import { applyDagreLayout, applyDagreLayoutAsync, NODE_WIDTH, NODE_HEIGHT } from "../utils/layout";--const LAYER_PADDING = 40;+import {+ applyDagreLayout,+ NODE_WIDTH,+ NODE_HEIGHT,+ LAYER_CLUSTER_WIDTH,+ LAYER_CLUSTER_HEIGHT,+ PORTAL_NODE_WIDTH,+ PORTAL_NODE_HEIGHT,+} from "../utils/layout";+import {+ aggregateLayerEdges,+ computePortals,+ findCrossLayerFileNodes,+} from "../utils/edgeAggregation";-/**- * Node count above which layout runs in a Web Worker- * to avoid blocking the main thread.- */-const ASYNC_LAYOUT_THRESHOLD = 200;+const nodeTypes = {+ custom: CustomNode,+ "layer-cluster": LayerClusterNode,+ portal: PortalNode,+};-const nodeTypes = { custom: CustomNode };+// ── Helper components that must live inside <ReactFlow> ────────────────-/**- * Inner component that pans/zooms to tour-highlighted nodes.- * Must be rendered inside <ReactFlow> so useReactFlow() works.- */+/** Pans/zooms to tour-highlighted nodes. */function TourFitView() {const tourHighlightedNodeIds = useDashboardStore((s) => s.tourHighlightedNodeIds);const { fitView } = useReactFlow();@@@ -202,256 -317,91 +203,257 @@@ function useLayerDetailGraph()const handleNodeSelect = useCallback((nodeId: string) => {selectNode(nodeId);- openCodeViewer(nodeId);},- [selectNode, openCodeViewer],+ [selectNode],);- // ── Topology memo: only recomputes when graph structure changes ──- // Does NOT depend on selectedNodeId, tourHighlightedNodeIds, or searchResults.- const { topoNodes, topoEdges, needsAsyncLayout } = useMemo(() => {- if (!graph) {- return { topoNodes: [] as CustomFlowNode[], topoEdges: [] as Edge[], needsAsyncLayout: false };+ return useMemo(() => {+ if (!graph || !activeLayerId)+ return { nodes: [] as Node[], edges: [] as Edge[] };++ const activeLayer = graph.layers.find((l) => l.id === activeLayerId);+ if (!activeLayer) return { nodes: [] as Node[], edges: [] as Edge[] };++ const layerNodeIds = new Set(activeLayer.nodeIds);++ let filteredGraphNodes = graph.nodes.filter(+ (n) => layerNodeIds.has(n.id) && n.type === "file",+ );++ if (persona === "non-technical") {+ filteredGraphNodes = filteredGraphNodes.filter(+ (n) => n.type === "concept" || n.type === "module" || n.type === "file",+ );}- const { flowNodes, flowEdges } = buildTopologyData(- graph, persona, diffMode, changedNodeIds, affectedNodeIds,- handleNodeSelect,++ let filteredNodeIds = new Set(filteredGraphNodes.map((n) => n.id));++ let filteredGraphEdges = graph.edges.filter(+ (e) => filteredNodeIds.has(e.source) && filteredNodeIds.has(e.target),);- return { topoNodes: flowNodes, topoEdges: flowEdges, needsAsyncLayout: flowNodes.length > ASYNC_LAYOUT_THRESHOLD };- }, [graph, persona, handleNodeSelect, diffMode, changedNodeIds, affectedNodeIds]);- // ── Laid-out nodes from the last completed layout pass ──- // Stored in a ref so layout results persist across visual-state changes.- const laidOutRef = useRef<{ initialNodes: (CustomFlowNode | Node)[]; initialEdges: Edge[] } | null>(null);+ // Focus mode: 1-hop neighborhood within the layer+ if (focusNodeId && filteredNodeIds.has(focusNodeId)) {+ const focusNeighborIds = new Set<string>([focusNodeId]);+ for (const edge of filteredGraphEdges) {+ if (edge.source === focusNodeId) focusNeighborIds.add(edge.target);+ if (edge.target === focusNodeId) focusNeighborIds.add(edge.source);+ }+ filteredGraphNodes = filteredGraphNodes.filter((n) =>+ focusNeighborIds.has(n.id),+ );+ filteredNodeIds = new Set(filteredGraphNodes.map((n) => n.id));+ filteredGraphEdges = filteredGraphEdges.filter(+ (e) => filteredNodeIds.has(e.source) && filteredNodeIds.has(e.target),+ );+ }- // ── Sync layout: for small graphs, run dagre on the main thread ──- const syncResult = useMemo(() => {- if (!graph || needsAsyncLayout || topoNodes.length === 0) return null;- const laid = applyDagreLayout(topoNodes, topoEdges);- const layers = graph.layers ?? [];- return applyLayerGroups(laid.nodes as CustomFlowNode[], laid.edges, layers, showLayers);- }, [graph, topoNodes, topoEdges, needsAsyncLayout, showLayers]);+ // Neighbor set for selection highlighting+ const neighborNodeIds = new Set<string>();+ if (selectedNodeId) {+ for (const edge of filteredGraphEdges) {+ if (edge.source === selectedNodeId) neighborNodeIds.add(edge.target);+ if (edge.target === selectedNodeId) neighborNodeIds.add(edge.source);+ }+ neighborNodeIds.add(selectedNodeId);+ }- // Keep laidOutRef in sync with sync layout results- if (syncResult) {- laidOutRef.current = syncResult;- }+ const flowNodes: CustomFlowNode[] = filteredGraphNodes.map((node) => {+ const matchResult = searchResults.find((r) => r.nodeId === node.id);+ const hasSelection = !!selectedNodeId;+ return {+ id: node.id,+ type: "custom" as const,+ position: { x: 0, y: 0 },+ data: {+ label: node.name ?? node.filePath?.split("/").pop() ?? node.id,+ nodeType: node.type,+ summary: node.summary,+ complexity: node.complexity,+ isHighlighted: !!matchResult,+ searchScore: matchResult?.score,+ isSelected: selectedNodeId === node.id,+ isTourHighlighted: tourHighlightedNodeIds.includes(node.id),+ isDiffChanged: diffMode && changedNodeIds.has(node.id),+ isDiffAffected: diffMode && affectedNodeIds.has(node.id),+ isDiffFaded:+ diffMode &&+ !changedNodeIds.has(node.id) &&+ !affectedNodeIds.has(node.id),+ isNeighbor:+ hasSelection &&+ neighborNodeIds.has(node.id) &&+ selectedNodeId !== node.id,+ isSelectionFaded: hasSelection && !neighborNodeIds.has(node.id),+ onNodeClick: handleNodeSelect,+ },+ };+ });- // ── Visual memo: cheap overlay of selection/highlight/search state ──- const visualNodes = useMemo(() => {- const base = laidOutRef.current;- if (!base) return [] as (CustomFlowNode | Node)[];- return applyVisualState(base.initialNodes, selectedNodeId, tourHighlightedNodeIds, searchResults);- }, [laidOutRef.current, selectedNodeId, tourHighlightedNodeIds, searchResults]);+ const diffNodeIds = diffMode+ ? new Set([...changedNodeIds, ...affectedNodeIds])+ : new Set<string>();+ const flowEdges: Edge[] = filteredGraphEdges.map((edge, i) => {+ const sourceInDiff = diffMode && diffNodeIds.has(edge.source);+ const targetInDiff = diffMode && diffNodeIds.has(edge.target);+ const isImpacted = diffMode && (sourceInDiff || targetInDiff);++ const isSelectedEdge =+ !!selectedNodeId &&+ (edge.source === selectedNodeId || edge.target === selectedNodeId);+ const hasSelection = !!selectedNodeId;++ let edgeStyle: React.CSSProperties;+ let edgeLabelStyle: React.CSSProperties;+ let edgeAnimated: boolean;++ if (isImpacted) {+ edgeStyle = {+ stroke:+ sourceInDiff && targetInDiff+ ? "rgba(224, 82, 82, 0.7)"+ : "rgba(212, 160, 48, 0.5)",+ strokeWidth: 2.5,+ };+ edgeLabelStyle = { fill: "#a39787", fontSize: 10 };+ edgeAnimated = true;+ } else if (diffMode) {+ edgeStyle = { stroke: "rgba(212,165,116,0.08)", strokeWidth: 1 };+ edgeLabelStyle = { fill: "rgba(163,151,135,0.3)", fontSize: 10 };+ edgeAnimated = false;+ } else if (isSelectedEdge) {+ edgeStyle = { stroke: "rgba(212,165,116,0.8)", strokeWidth: 2.5 };+ edgeLabelStyle = { fill: "#d4a574", fontSize: 11, fontWeight: 600 };+ edgeAnimated = true;+ } else if (hasSelection) {+ edgeStyle = { stroke: "rgba(212,165,116,0.08)", strokeWidth: 1 };+ edgeLabelStyle = { fill: "rgba(163,151,135,0.2)", fontSize: 10 };+ edgeAnimated = false;+ } else {+ edgeStyle = { stroke: "rgba(212,165,116,0.3)", strokeWidth: 1.5 };+ edgeLabelStyle = { fill: "#a39787", fontSize: 10 };+ edgeAnimated = edge.type === "calls";+ }++ return {+ id: `e-${i}`,+ source: edge.source,+ target: edge.target,+ label: edge.type,+ animated: edgeAnimated,+ style: edgeStyle,+ labelStyle: edgeLabelStyle,+ };+ });- const [nodes, setNodes, onNodesChange] = useNodesState(visualNodes);- const [edges, setEdges, onEdgesChange] = useEdgesState(laidOutRef.current?.initialEdges ?? []);+ // Portal nodes for connected external layers+ const portals = computePortals(graph, activeLayerId);+ const layerIndexMap = new Map(graph.layers.map((l, i) => [l.id, i]));- // ── Push sync layout + visual state to ReactFlow ──- useEffect(() => {- if (syncResult) {- const withVisual = applyVisualState(syncResult.initialNodes, selectedNodeId, tourHighlightedNodeIds, searchResults);- setNodes(withVisual);- setEdges(syncResult.initialEdges);+ const portalNodes: PortalFlowNode[] = portals.map((portal) => ({+ id: `portal:${portal.layerId}`,+ type: "portal" as const,+ position: { x: 0, y: 0 },+ data: {+ targetLayerId: portal.layerId,+ targetLayerName: portal.layerName,+ connectionCount: portal.connectionCount,+ layerColorIndex: layerIndexMap.get(portal.layerId) ?? 0,+ onNavigate: drillIntoLayer,+ },+ }));++ const portalEdges: Edge[] = [];+ let portalEdgeIdx = flowEdges.length;+ for (const portal of portals) {+ const crossFiles = findCrossLayerFileNodes(+ graph,+ activeLayerId,+ portal.layerId,+ );+ for (const fileId of crossFiles) {+ if (filteredNodeIds.has(fileId)) {+ portalEdges.push({+ id: `e-${portalEdgeIdx++}`,+ source: fileId,+ target: `portal:${portal.layerId}`,+ style: { stroke: "rgba(212,165,116,0.2)", strokeWidth: 1, strokeDasharray: "4 4" },+ animated: false,+ });+ }+ }}- }, [syncResult, selectedNodeId, tourHighlightedNodeIds, searchResults, setNodes, setEdges]);- // ── Push visual-only changes (no relayout) ──- useEffect(() => {- if (laidOutRef.current && !layouting) {- const withVisual = applyVisualState(laidOutRef.current.initialNodes, selectedNodeId, tourHighlightedNodeIds, searchResults);- setNodes(withVisual);+ const allFlowNodes: Node[] = [+ ...(flowNodes as unknown as Node[]),+ ...(portalNodes as unknown as Node[]),+ ];+ const allFlowEdges = [...flowEdges, ...portalEdges];++ const dims = new Map<string, { width: number; height: number }>();+ for (const n of flowNodes) {+ dims.set(n.id, { width: NODE_WIDTH, height: NODE_HEIGHT });+ }+ for (const n of portalNodes) {+ dims.set(n.id, { width: PORTAL_NODE_WIDTH, height: PORTAL_NODE_HEIGHT });}- }, [selectedNodeId, tourHighlightedNodeIds, searchResults, setNodes, layouting]);- // ── Async layout: for large graphs, run dagre in a Web Worker ──+ const laid = applyDagreLayout(allFlowNodes, allFlowEdges, "TB", dims);+ return { nodes: laid.nodes, edges: laid.edges };+ }, [+ graph,+ activeLayerId,+ selectedNodeId,+ searchResults,+ tourHighlightedNodeIds,+ persona,+ handleNodeSelect,+ diffMode,+ changedNodeIds,+ affectedNodeIds,+ focusNodeId,+ drillIntoLayer,+ ]);+}++// ── Main inner component (must be inside ReactFlowProvider) ────────────++function GraphViewInner() {+ const graph = useDashboardStore((s) => s.graph);+ const navigationLevel = useDashboardStore((s) => s.navigationLevel);+ const activeLayerId = useDashboardStore((s) => s.activeLayerId);+ const selectNode = useDashboardStore((s) => s.selectNode);+ const drillIntoLayer = useDashboardStore((s) => s.drillIntoLayer);+ const focusNodeId = useDashboardStore((s) => s.focusNodeId);+ const setFocusNode = useDashboardStore((s) => s.setFocusNode);++ const { preset } = useTheme();++ const overviewGraph = useOverviewGraph();+ const detailGraph = useLayerDetailGraph();++ const { nodes: initialNodes, edges: initialEdges } =+ navigationLevel === "overview" ? overviewGraph : detailGraph;++ const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);+ const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges);++ const { fitView } = useReactFlow();+useEffect(() => {- if (!graph || !needsAsyncLayout || topoNodes.length === 0) return;-- let cancelled = false;- setLayouting(true);-- applyDagreLayoutAsync(topoNodes, topoEdges).then((laid) => {- if (cancelled) return;- const layers = graph.layers ?? [];- const result = applyLayerGroups(laid.nodes as CustomFlowNode[], laid.edges, layers, showLayers);- laidOutRef.current = result;- const withVisual = applyVisualState(result.initialNodes, selectedNodeId, tourHighlightedNodeIds, searchResults);- setNodes(withVisual);- setEdges(result.initialEdges);- setLayouting(false);- }).catch(() => {- if (cancelled) return;- setLayouting(false);- });+ setNodes(initialNodes);+ }, [initialNodes, setNodes]);++ useEffect(() => {+ setEdges(initialEdges);+ }, [initialEdges, setEdges]);- return () => { cancelled = true; setLayouting(false); };- }, [graph, topoNodes, topoEdges, needsAsyncLayout, showLayers, setNodes, setEdges]);+ // Fit view on level/layer transitions+ useEffect(() => {+ const timer = setTimeout(() => {+ fitView({ duration: 400, padding: 0.2 });+ }, 50);+ return () => clearTimeout(timer);+ }, [navigationLevel, activeLayerId, fitView]);const onNodeClick = useCallback((_: React.MouseEvent, node: { id: string }) => {