Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
feat(graph-ui): type-in node budget with live loading progress
Martin Vogel9969253bdc60
diff --git a/graph-ui/src/components/GraphLoader.tsx b/graph-ui/src/components/GraphLoader.tsxnew file mode 100644index 000000000..0d9154b17--- /dev/null+++ b/graph-ui/src/components/GraphLoader.tsx@@ -0,0 +1,84 @@+import type { LoadProgress } from "../hooks/useGraphData";++/* Small constellation whose nodes pulse and whose edges draw themselves in a+ * staggered loop — a miniature of the graph being loaded. Pure SVG/CSS+ * (keyframes in globals.css) so it costs nothing while the real payload+ * streams in, and it degrades to a static constellation under+ * prefers-reduced-motion. */++const LOADER_NODES: Array<{ cx: number; cy: number; r: number; delay: string }> = [+ { cx: 60, cy: 18, r: 5, delay: "0s" },+ { cx: 22, cy: 42, r: 4, delay: "0.35s" },+ { cx: 98, cy: 40, r: 4, delay: "0.7s" },+ { cx: 42, cy: 78, r: 4.5, delay: "1.05s" },+ { cx: 84, cy: 82, r: 3.5, delay: "1.4s" },+ { cx: 60, cy: 52, r: 6, delay: "0.15s" },+ { cx: 14, cy: 88, r: 3, delay: "1.75s" },+];++const LOADER_EDGES: Array<{ x1: number; y1: number; x2: number; y2: number; delay: string }> = [+ { x1: 60, y1: 18, x2: 60, y2: 52, delay: "0s" },+ { x1: 22, y1: 42, x2: 60, y2: 52, delay: "0.3s" },+ { x1: 98, y1: 40, x2: 60, y2: 52, delay: "0.6s" },+ { x1: 42, y1: 78, x2: 60, y2: 52, delay: "0.9s" },+ { x1: 84, y1: 82, x2: 60, y2: 52, delay: "1.2s" },+ { x1: 42, y1: 78, x2: 14, y2: 88, delay: "1.5s" },+ { x1: 22, y1: 42, x2: 60, y2: 18, delay: "1.8s" },+];++function formatMegabytes(bytes: number): string {+ return (bytes / (1024 * 1024)).toFixed(1);+}++interface GraphLoaderProps {+ nodeBudget: number;+ progress: LoadProgress;+}++export function GraphLoader({ nodeBudget, progress }: GraphLoaderProps) {+ const receiving = progress.receivedBytes > 0;+ return (+ <div className="text-center" role="status" aria-live="polite">+ <svg+ width="120"+ height="104"+ viewBox="0 0 120 104"+ className="mx-auto"+ aria-hidden="true"+ >+ {LOADER_EDGES.map((e, i) => (+ <line+ key={`e${i}`}+ x1={e.x1}+ y1={e.y1}+ x2={e.x2}+ y2={e.y2}+ className="graph-loader-edge"+ style={{ animationDelay: e.delay }}+ />+ ))}+ {LOADER_NODES.map((n, i) => (+ <circle+ key={`n${i}`}+ cx={n.cx}+ cy={n.cy}+ r={n.r}+ className="graph-loader-node"+ style={{ animationDelay: n.delay }}+ />+ ))}+ </svg>+ <p className="text-white/50 text-sm mt-4">+ {receiving ? "Receiving graph" : "Computing layout"} — up to{" "}+ {nodeBudget.toLocaleString("en-US")} nodes+ </p>+ <p className="text-cyan-300/60 text-xs font-mono mt-1 h-4">+ {receiving+ ? progress.totalBytes+ ? `${formatMegabytes(progress.receivedBytes)} of ${formatMegabytes(progress.totalBytes)} MB`+ : `${formatMegabytes(progress.receivedBytes)} MB received`+ : " "}+ </p>+ </div>+ );+}diff --git a/graph-ui/src/components/GraphTab.test.ts b/graph-ui/src/components/GraphTab.test.tsindex 6056eeef0..0e68e76d9 100644--- a/graph-ui/src/components/GraphTab.test.ts+++ b/graph-ui/src/components/GraphTab.test.ts@@ -20,7 +20,7 @@ describe("formatGraphLimitNotice", () => {} satisfies GraphData;expect(formatGraphLimitNotice(data)).toBe(- "Showing 2,000 of 43,729 nodes. Use filters to narrow.",+ "Showing 2,000 of 43,729 nodes (0 edges). Raise the node budget or use filters.",);});diff --git a/graph-ui/src/components/GraphTab.tsx b/graph-ui/src/components/GraphTab.tsxindex 8d267ca03..dde3650f5 100644--- a/graph-ui/src/components/GraphTab.tsx+++ b/graph-ui/src/components/GraphTab.tsx@@ -1,6 +1,13 @@import { useEffect, useState, useCallback, useMemo } from "react";import { Button } from "@/components/ui/button";-import { useGraphData } from "../hooks/useGraphData";+import {+ useGraphData,+ clampNodeBudget,+ GRAPH_RENDER_NODE_LIMIT,+ GRAPH_NODE_BUDGET_STEP,+ GRAPH_NODE_BUDGET_MAX,+} from "../hooks/useGraphData";+import { GraphLoader } from "./GraphLoader";import {GraphScene,computeCameraTarget,@@ -26,17 +33,32 @@ function saveWidth(key: string, value: number) {try { localStorage.setItem(key, String(Math.round(value))); } catch { /* ignore */ }}+/* Persist the node budget per project */+function budgetKey(project: string): string {+ return `cbm-node-budget:${project}`;+}+function loadNodeBudget(project: string): number {+ try {+ const v = localStorage.getItem(budgetKey(project));+ if (v) return clampNodeBudget(parseInt(v, 10));+ } catch { /* ignore */ }+ return GRAPH_RENDER_NODE_LIMIT;+}+function saveNodeBudget(project: string, value: number) {+ try { localStorage.setItem(budgetKey(project), String(value)); } catch { /* ignore */ }+}+interface GraphTabProps {project: string | null;}export function formatGraphLimitNotice(data: GraphData | null): string | null {if (!data || data.total_nodes <= data.nodes.length) return null;- return `Showing ${data.nodes.length.toLocaleString("en-US")} of ${data.total_nodes.toLocaleString("en-US")} nodes. Use filters to narrow.`;+ return `Showing ${data.nodes.length.toLocaleString("en-US")} of ${data.total_nodes.toLocaleString("en-US")} nodes (${data.edges.length.toLocaleString("en-US")} edges). Raise the node budget or use filters.`;}export function GraphTab({ project }: GraphTabProps) {- const { data, loading, error, fetchOverview } = useGraphData();+ const { data, loading, error, progress, fetchOverview } = useGraphData();const [highlightedIds, setHighlightedIds] = useState<Set<number> | null>(null);const [selectedPath, setSelectedPath] = useState<string | null>(null);const [selectedNode, setSelectedNode] = useState<GraphNode | null>(null);@@ -47,6 +69,22 @@ export function GraphTab({ project }: GraphTabProps) {const [rightWidth, setRightWidth] = useState(() => loadWidth("cbm-right-w", 280));const limitNotice = formatGraphLimitNotice(data);+ /* Node budget — keyed to its project so switching projects re-reads the+ * persisted value and triggers exactly one fetch. */+ const [budget, setBudget] = useState<{ project: string | null; value: number }>(+ { project: null, value: GRAPH_RENDER_NODE_LIMIT },+ );+ const [budgetDraft, setBudgetDraft] = useState(String(GRAPH_RENDER_NODE_LIMIT));++ const commitBudget = useCallback(() => {+ const parsed = clampNodeBudget(parseInt(budgetDraft, 10));+ setBudgetDraft(String(parsed));+ if (project && parsed !== budget.value) {+ saveNodeBudget(project, parsed);+ setBudget({ project, value: parsed });+ }+ }, [budgetDraft, project, budget.value]);+/* Filter state — all enabled by default */const [enabledLabels, setEnabledLabels] = useState<Set<string>>(new Set());const [enabledEdgeTypes, setEnabledEdgeTypes] = useState<Set<string>>(new Set());@@ -121,13 +159,23 @@ export function GraphTab({ project }: GraphTabProps) {hideTests,]);+ /* Re-read the persisted budget when the project changes… */useEffect(() => {if (project) {- fetchOverview(project);+ const value = loadNodeBudget(project);+ setBudget({ project, value });+ setBudgetDraft(String(value));+ }+ }, [project]);++ /* …and fetch only once budget and project agree (one fetch per change). */+ useEffect(() => {+ if (project && budget.project === project) {+ fetchOverview(project, budget.value);setHighlightedIds(null);setSelectedPath(null);}- }, [project, fetchOverview]);+ }, [project, budget, fetchOverview]);/* Fetch git remote metadata for GitHub deep-links */useEffect(() => {@@ -236,10 +284,7 @@ export function GraphTab({ project }: GraphTabProps) {if (loading) {return (<div className="flex items-center justify-center h-full">- <div className="text-center">- <div className="w-8 h-8 border-2 border-cyan-400/30 border-t-cyan-400 rounded-full animate-spin mx-auto mb-3" />- <p className="text-white/40 text-sm">Computing layout...</p>- </div>+ <GraphLoader nodeBudget={budget.value} progress={progress} /></div>);}@@ -355,7 +400,7 @@ export function GraphTab({ project }: GraphTabProps) {)}</div>- <div className="absolute top-4 right-4 flex gap-2">+ <div className="absolute top-4 right-4 flex gap-2 items-center">{highlightedIds && (<Buttonsize="sm"@@ -369,6 +414,32 @@ export function GraphTab({ project }: GraphTabProps) {Clear selection</Button>)}+ <div className="flex items-center gap-1.5 h-8 px-2 rounded-md border border-border/50 bg-[#0b1920]/80 backdrop-blur-sm">+ <label+ htmlFor="node-budget"+ className="text-[10px] uppercase tracking-wider text-white/40"+ >+ Nodes+ </label>+ <input+ id="node-budget"+ type="number"+ min={GRAPH_NODE_BUDGET_STEP}+ max={GRAPH_NODE_BUDGET_MAX}+ step={GRAPH_NODE_BUDGET_STEP}+ value={budgetDraft}+ onChange={(e) => setBudgetDraft(e.target.value)}+ onBlur={commitBudget}+ onKeyDown={(e) => {+ if (e.key === "Enter") {+ e.currentTarget.blur();+ }+ }}+ className="w-24 bg-transparent text-right text-xs font-mono text-cyan-200/90 outline-none [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"+ aria-label="Node budget: how many nodes to load"+ title="How many nodes to load (5,000 steps, edges between loaded nodes follow automatically)"+ />+ </div><Buttonvariant="outline"size="sm"@@ -377,7 +448,7 @@ export function GraphTab({ project }: GraphTabProps) {setSelectedPath(null);setSelectedNode(null);setCameraTarget(null);- fetchOverview(project);+ fetchOverview(project, budget.value);}}>Refreshdiff --git a/graph-ui/src/components/NodeCloud.tsx b/graph-ui/src/components/NodeCloud.tsxindex e5465b8f2..60b9aea5a 100644--- a/graph-ui/src/components/NodeCloud.tsx+++ b/graph-ui/src/components/NodeCloud.tsx@@ -1,5 +1,5 @@-import { useMemo, useRef } from "react";-import { useFrame } from "@react-three/fiber";+import { useEffect, useMemo, useRef } from "react";+import { useThree } from "@react-three/fiber";import * as THREE from "three";import type { GraphNode } from "../lib/types";@@ -11,46 +11,166 @@ interface NodeCloudProps {opacity?: number;}-export function NodeCloud({+/* Above this count instanced spheres stop paying off (vertex + matrix cost)+ * and the cloud switches to point sprites — one position per node. */+const POINT_MODE_THRESHOLD = 75000;++/* Sphere tessellation by node count: nobody can tell a 12-segment sphere from+ * a 32-segment one at 25k nodes, but the GPU can. */+function sphereDetail(count: number): [number, number, number] {+ if (count <= 8000) return [1, 32, 24];+ if (count <= 25000) return [1, 16, 12];+ return [1, 10, 7];+}++function nodeColor(+ node: GraphNode,+ highlightedIds: Set<number> | null,+ opacity: number,+ tempColor: THREE.Color,+): [number, number, number] {+ const hasHighlight = highlightedIds && highlightedIds.size > 0;+ tempColor.set(node.color);+ if (hasHighlight && !highlightedIds.has(node.id)) {+ tempColor.multiplyScalar(0.15);+ } else {+ /* Boost above 1.0 so bloom picks up the excess as glow corona.+ * Hotter stars (white/blue) get a stronger boost = brighter halo. */+ const brightness = (tempColor.r + tempColor.g + tempColor.b) / 3;+ const boost = 1.2 + brightness * 0.8; /* 1.2x for red, 2.0x for white */+ tempColor.multiplyScalar(boost);+ }+ return [tempColor.r * opacity, tempColor.g * opacity, tempColor.b * opacity];+}++/* Round, soft-edged sprite for point mode (module-level lazy singleton). */+let pointSprite: THREE.CanvasTexture | null = null;+function getPointSprite(): THREE.CanvasTexture {+ if (pointSprite) return pointSprite;+ const size = 64;+ const canvas = document.createElement("canvas");+ canvas.width = size;+ canvas.height = size;+ const ctx = canvas.getContext("2d")!;+ const gradient = ctx.createRadialGradient(+ size / 2, size / 2, 0,+ size / 2, size / 2, size / 2,+ );+ gradient.addColorStop(0, "rgba(255,255,255,1)");+ gradient.addColorStop(0.5, "rgba(255,255,255,0.9)");+ gradient.addColorStop(1, "rgba(255,255,255,0)");+ ctx.fillStyle = gradient;+ ctx.fillRect(0, 0, size, size);+ pointSprite = new THREE.CanvasTexture(canvas);+ return pointSprite;+}++/* ── Point-sprite mode for very large clouds ──────────────────── */++function NodePoints({nodes,highlightedIds,onHover,onClick,- opacity = 1.0,-}: NodeCloudProps) {+ opacity,+}: Required<NodeCloudProps>) {+ const { raycaster } = useThree();++ /* Widen the raycast threshold while points are on screen */+ useEffect(() => {+ const prev = raycaster.params.Points?.threshold ?? 1;+ raycaster.params.Points = { threshold: 3 };+ return () => {+ raycaster.params.Points = { threshold: prev };+ };+ }, [raycaster]);++ const { positions, colors } = useMemo(() => {+ const positions = new Float32Array(nodes.length * 3);+ const colors = new Float32Array(nodes.length * 3);+ const tempColor = new THREE.Color();+ for (let i = 0; i < nodes.length; i++) {+ const n = nodes[i];+ positions[i * 3] = n.x;+ positions[i * 3 + 1] = n.y;+ positions[i * 3 + 2] = n.z;+ const [r, g, b] = nodeColor(n, highlightedIds, opacity, tempColor);+ colors[i * 3] = r;+ colors[i * 3 + 1] = g;+ colors[i * 3 + 2] = b;+ }+ return { positions, colors };+ }, [nodes, highlightedIds, opacity]);++ return (+ <points+ /* Remount when the buffer size changes so stale attributes never linger */+ key={nodes.length}+ onPointerOver={(e) => {+ e.stopPropagation();+ if (e.index !== undefined && e.index < nodes.length) {+ onHover(nodes[e.index]);+ }+ }}+ onPointerOut={() => onHover(null)}+ onClick={(e) => {+ e.stopPropagation();+ if (e.index !== undefined && e.index < nodes.length) {+ onClick(nodes[e.index]);+ }+ }}+ >+ <bufferGeometry>+ <bufferAttribute attach="attributes-position" args={[positions, 3]} />+ <bufferAttribute attach="attributes-color" args={[colors, 3]} />+ </bufferGeometry>+ <pointsMaterial+ vertexColors+ size={4}+ sizeAttenuation+ map={getPointSprite()}+ alphaTest={0.35}+ transparent+ toneMapped={false}+ />+ </points>+ );+}++/* ── Instanced-sphere mode (default) ──────────────────────────── */++function NodeSpheres({+ nodes,+ highlightedIds,+ onHover,+ onClick,+ opacity,+}: Required<NodeCloudProps>) {const meshRef = useRef<THREE.InstancedMesh>(null);const tempObj = useMemo(() => new THREE.Object3D(), []);const tempColor = useMemo(() => new THREE.Color(), []);+ const detail = sphereDetail(nodes.length);/* Build instance color attributes — dim non-highlighted nodes */const colors = useMemo(() => {const arr = new Float32Array(nodes.length * 3);- const hasHighlight = highlightedIds && highlightedIds.size > 0;-for (let i = 0; i < nodes.length; i++) {- tempColor.set(nodes[i].color);- if (hasHighlight && !highlightedIds.has(nodes[i].id)) {- tempColor.multiplyScalar(0.15);- } else {- /* Boost above 1.0 so bloom picks up the excess as glow corona.- * Hotter stars (white/blue) get a stronger boost = brighter halo. */- const brightness = (tempColor.r + tempColor.g + tempColor.b) / 3;- const boost = 1.2 + brightness * 0.8; /* 1.2x for red, 2.0x for white */- tempColor.multiplyScalar(boost);- }- arr[i * 3] = tempColor.r * opacity;- arr[i * 3 + 1] = tempColor.g * opacity;- arr[i * 3 + 2] = tempColor.b * opacity;+ const [r, g, b] = nodeColor(nodes[i], highlightedIds, opacity, tempColor);+ arr[i * 3] = r;+ arr[i * 3 + 1] = g;+ arr[i * 3 + 2] = b;}return arr;}, [nodes, highlightedIds, tempColor, opacity]);- useFrame(() => {+ /* Node positions are static (the layout is server-computed), so instance+ * matrices only change with the node set or the highlight — never rebuild+ * them per frame. */+ useEffect(() => {const mesh = meshRef.current;if (!mesh) return;const hasHighlight = highlightedIds && highlightedIds.size > 0;-for (let i = 0; i < nodes.length; i++) {const n = nodes[i];tempObj.position.set(n.x, n.y, n.z);@@ -62,10 +182,12 @@ export function NodeCloud({}mesh.instanceMatrix.needsUpdate = true;mesh.computeBoundingSphere();- });+ }, [nodes, highlightedIds, tempObj]);return (<instancedMesh+ /* Remount when the instance count changes so buffers are re-sized */+ key={nodes.length}ref={meshRef}args={[undefined, undefined, nodes.length]}frustumCulled={false}@@ -83,7 +205,7 @@ export function NodeCloud({}}}>- <sphereGeometry args={[1, 32, 24]} />+ <sphereGeometry args={detail} /><meshBasicMaterial vertexColors toneMapped={false} /><instancedBufferAttributeattach="geometry-attributes-color"@@ -92,3 +214,32 @@ export function NodeCloud({</instancedMesh>);}++export function NodeCloud({+ nodes,+ highlightedIds,+ onHover,+ onClick,+ opacity = 1.0,+}: NodeCloudProps) {+ if (nodes.length > POINT_MODE_THRESHOLD) {+ return (+ <NodePoints+ nodes={nodes}+ highlightedIds={highlightedIds}+ onHover={onHover}+ onClick={onClick}+ opacity={opacity}+ />+ );+ }+ return (+ <NodeSpheres+ nodes={nodes}+ highlightedIds={highlightedIds}+ onHover={onHover}+ onClick={onClick}+ opacity={opacity}+ />+ );+}diff --git a/graph-ui/src/hooks/useGraphData.test.ts b/graph-ui/src/hooks/useGraphData.test.tsindex 7edb76248..514561250 100644--- a/graph-ui/src/hooks/useGraphData.test.ts+++ b/graph-ui/src/hooks/useGraphData.test.ts@@ -1,12 +1,18 @@import { afterEach, describe, expect, it, vi } from "vitest";-import { fetchLayout, GRAPH_RENDER_NODE_LIMIT } from "./useGraphData";+import {+ fetchLayout,+ clampNodeBudget,+ GRAPH_RENDER_NODE_LIMIT,+ GRAPH_NODE_BUDGET_STEP,+ GRAPH_NODE_BUDGET_MAX,+} from "./useGraphData";describe("fetchLayout", () => {afterEach(() => {vi.unstubAllGlobals();});- it("uses the safe graph render cap by default", async () => {+ it("uses the default node budget when none is given", async () => {const fetchMock = vi.fn(async () => ({ok: true,json: async () => ({ nodes: [], edges: [], total_nodes: 0 }),@@ -15,12 +21,76 @@ describe("fetchLayout", () => {await fetchLayout("large-project");- expect(GRAPH_RENDER_NODE_LIMIT).toBe(2000);+ expect(GRAPH_RENDER_NODE_LIMIT).toBe(5000);expect(fetchMock).toHaveBeenCalledTimes(1);const calls = fetchMock.mock.calls as unknown as Array<[string]>;const [url] = calls[0];expect(url).toBe(- "/api/layout?project=large-project&max_nodes=2000",+ "/api/layout?project=large-project&max_nodes=5000",);});++ it("passes an explicit node budget through to the layout endpoint", async () => {+ const fetchMock = vi.fn(async () => ({+ ok: true,+ json: async () => ({ nodes: [], edges: [], total_nodes: 0 }),+ }));+ vi.stubGlobal("fetch", fetchMock);++ await fetchLayout("large-project", 250000);++ const calls = fetchMock.mock.calls as unknown as Array<[string]>;+ const [url] = calls[0];+ expect(url).toBe(+ "/api/layout?project=large-project&max_nodes=250000",+ );+ });++ it("reports streaming progress while the body downloads", async () => {+ const payload = new TextEncoder().encode(+ JSON.stringify({ nodes: [], edges: [], total_nodes: 7 }),+ );+ const half = Math.floor(payload.length / 2);+ const chunks = [payload.slice(0, half), payload.slice(half)];+ let read = 0;+ const fetchMock = vi.fn(async () => ({+ ok: true,+ headers: new Headers({ "content-length": String(payload.length) }),+ body: {+ getReader: () => ({+ read: async () =>+ read < chunks.length+ ? { done: false, value: chunks[read++] }+ : { done: true, value: undefined },+ }),+ },+ json: async () => {+ throw new Error("json() must not be used when streaming");+ },+ }));+ vi.stubGlobal("fetch", fetchMock);++ const seen: number[] = [];+ const result = await fetchLayout("p", 5000, (p) => {+ seen.push(p.receivedBytes);+ expect(p.totalBytes).toBe(payload.length);+ });++ expect(result.total_nodes).toBe(7);+ expect(seen).toEqual([half, payload.length]);+ });+});++describe("clampNodeBudget", () => {+ it("snaps to 5k steps within the 5k..10M range", () => {+ expect(GRAPH_NODE_BUDGET_STEP).toBe(5000);+ expect(GRAPH_NODE_BUDGET_MAX).toBe(10_000_000);+ expect(clampNodeBudget(5000)).toBe(5000);+ expect(clampNodeBudget(12345)).toBe(10000);+ expect(clampNodeBudget(12501)).toBe(15000);+ expect(clampNodeBudget(0)).toBe(5000);+ expect(clampNodeBudget(-500)).toBe(5000);+ expect(clampNodeBudget(99_999_999)).toBe(10_000_000);+ expect(clampNodeBudget(Number.NaN)).toBe(GRAPH_RENDER_NODE_LIMIT);+ });});diff --git a/graph-ui/src/hooks/useGraphData.ts b/graph-ui/src/hooks/useGraphData.tsindex 5705555fa..c51b81d3e 100644--- a/graph-ui/src/hooks/useGraphData.ts+++ b/graph-ui/src/hooks/useGraphData.ts@@ -1,19 +1,41 @@import { useCallback, useState } from "react";import type { GraphData } from "../lib/types";+export interface LoadProgress {+ receivedBytes: number;+ totalBytes: number | null;+}+interface UseGraphDataResult {data: GraphData | null;loading: boolean;error: string | null;- fetchOverview: (project: string) => void;+ progress: LoadProgress;+ fetchOverview: (project: string, maxNodes?: number) => void;fetchDetail: (project: string, centerNode: string) => void;}-export const GRAPH_RENDER_NODE_LIMIT = 2000;+/* Node budget: how many nodes the layout endpoint is asked for. The default+ * keeps first paint fast; the user can raise it in 5k steps up to the hard+ * ceiling (mirrors HARD_MAX_NODES in src/ui/layout3d.c). Edges always follow+ * the budget — the server returns every edge between the loaded nodes. */+export const GRAPH_RENDER_NODE_LIMIT = 5000;+export const GRAPH_NODE_BUDGET_STEP = 5000;+export const GRAPH_NODE_BUDGET_MAX = 10_000_000;++export function clampNodeBudget(value: number): number {+ if (!Number.isFinite(value)) return GRAPH_RENDER_NODE_LIMIT;+ const stepped =+ Math.round(value / GRAPH_NODE_BUDGET_STEP) * GRAPH_NODE_BUDGET_STEP;+ if (stepped < GRAPH_NODE_BUDGET_STEP) return GRAPH_NODE_BUDGET_STEP;+ if (stepped > GRAPH_NODE_BUDGET_MAX) return GRAPH_NODE_BUDGET_MAX;+ return stepped;+}export async function fetchLayout(project: string,maxNodes = GRAPH_RENDER_NODE_LIMIT,+ onProgress?: (progress: LoadProgress) => void,): Promise<GraphData> {const params = new URLSearchParams({ project, max_nodes: String(maxNodes) });const res = await fetch(`/api/layout?${params}`);@@ -23,34 +45,68 @@ export async function fetchLayout(throw new Error(body.error ?? `HTTP ${res.status}`);}- return res.json();+ /* Stream the body when possible so large budgets show live download+ * progress instead of a silent stall. */+ if (!res.body || !onProgress) {+ return res.json();+ }++ const lengthHeader = res.headers.get("content-length");+ const totalBytes = lengthHeader ? parseInt(lengthHeader, 10) || null : null;+ const reader = res.body.getReader();+ const chunks: Uint8Array[] = [];+ let receivedBytes = 0;++ for (;;) {+ const { done, value } = await reader.read();+ if (done) break;+ chunks.push(value);+ receivedBytes += value.length;+ onProgress({ receivedBytes, totalBytes });+ }++ const merged = new Uint8Array(receivedBytes);+ let offset = 0;+ for (const chunk of chunks) {+ merged.set(chunk, offset);+ offset += chunk.length;+ }+ return JSON.parse(new TextDecoder().decode(merged));}+const NO_PROGRESS: LoadProgress = { receivedBytes: 0, totalBytes: null };+export function useGraphData(): UseGraphDataResult {const [data, setData] = useState<GraphData | null>(null);const [loading, setLoading] = useState(false);const [error, setError] = useState<string | null>(null);+ const [progress, setProgress] = useState<LoadProgress>(NO_PROGRESS);- const fetchOverview = useCallback(async (project: string) => {- setLoading(true);- setError(null);- try {- const result = await fetchLayout(project);- setData(result);- } catch (e) {- setError(e instanceof Error ? e.message : "Failed to fetch layout");- } finally {- setLoading(false);- }- }, []);+ const fetchOverview = useCallback(+ async (project: string, maxNodes?: number) => {+ setLoading(true);+ setError(null);+ setProgress(NO_PROGRESS);+ try {+ const result = await fetchLayout(project, maxNodes, setProgress);+ setData(result);+ } catch (e) {+ setError(e instanceof Error ? e.message : "Failed to fetch layout");+ } finally {+ setLoading(false);+ }+ },+ [],+ );const fetchDetail = useCallback(async (project: string, _centerNode: string) => {setLoading(true);setError(null);+ setProgress(NO_PROGRESS);try {/* TODO: detail level with center_node filtering */- const result = await fetchLayout(project);+ const result = await fetchLayout(project, undefined, setProgress);setData(result);} catch (e) {setError(e instanceof Error ? e.message : "Failed to fetch layout");@@ -61,5 +117,5 @@ export function useGraphData(): UseGraphDataResult {[],);- return { data, loading, error, fetchOverview, fetchDetail };+ return { data, loading, error, progress, fetchOverview, fetchDetail };}diff --git a/graph-ui/src/styles/globals.css b/graph-ui/src/styles/globals.cssindex c65bd70ab..5c401e336 100644--- a/graph-ui/src/styles/globals.css+++ b/graph-ui/src/styles/globals.css@@ -37,3 +37,42 @@ html, body, #root {-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;}++/* ── Graph loading constellation ─────────────────────────────── */++.graph-loader-node {+ fill: #22d3ee;+ animation: graph-loader-pulse 2.1s ease-in-out infinite;+ transform-box: fill-box;+ transform-origin: center;+}++.graph-loader-edge {+ stroke: #22d3ee;+ stroke-opacity: 0.35;+ stroke-width: 1.2;+ stroke-dasharray: 90;+ stroke-dashoffset: 90;+ animation: graph-loader-draw 2.1s ease-in-out infinite;+}++@keyframes graph-loader-pulse {+ 0%, 100% { opacity: 0.25; transform: scale(0.8); }+ 35% { opacity: 1; transform: scale(1.15); }+ 70% { opacity: 0.45; transform: scale(0.95); }+}++@keyframes graph-loader-draw {+ 0% { stroke-dashoffset: 90; stroke-opacity: 0; }+ 40% { stroke-dashoffset: 0; stroke-opacity: 0.5; }+ 80%, 100% { stroke-dashoffset: 0; stroke-opacity: 0.15; }+}++@media (prefers-reduced-motion: reduce) {+ .graph-loader-node,+ .graph-loader-edge {+ animation: none;+ }+ .graph-loader-node { opacity: 0.8; }+ .graph-loader-edge { stroke-dashoffset: 0; stroke-opacity: 0.35; }+}