@atolis-hq/corum 0.1.27 → 0.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -359,15 +359,22 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
359
359
  for (const node of targetGraph.nodesById.values()) {
360
360
  if (GRAPH_EXCLUDED_TEMPLATES.has(node.template))
361
361
  continue;
362
+ const ownership = getNavigationOwnership(targetGraph, node);
362
363
  nodes.push({
363
364
  id: node.id,
364
365
  template: node.template,
365
366
  component: node.component,
366
367
  state: node.state,
367
368
  stability: node.stability,
369
+ parentId: ownership?.parentId ?? null,
368
370
  });
369
371
  }
370
372
  const nodeIds = new Set(nodes.map(n => n.id));
373
+ // Clear parentId when the parent itself was excluded from the graph
374
+ for (const n of nodes) {
375
+ if (n.parentId && !nodeIds.has(n.parentId))
376
+ n.parentId = null;
377
+ }
371
378
  const edges = [];
372
379
  for (const edgeList of targetGraph.edgesByFrom.values()) {
373
380
  for (const edge of edgeList) {
@@ -384,6 +391,39 @@ export function createApp(graph, reloadEvents = createReloadEvents(), source, mu
384
391
  res.status(500).json({ error: String(err) });
385
392
  }
386
393
  });
394
+ app.get('/api/stats', async (req, res) => {
395
+ let targetGraph = graph;
396
+ if (typeof req.query.ref === 'string' && multiCache) {
397
+ targetGraph = await getGraphForRef(req.query.ref, multiCache, graph);
398
+ }
399
+ const components = new Set();
400
+ for (const node of targetGraph.nodesById.values()) {
401
+ if (node.component)
402
+ components.add(node.component);
403
+ }
404
+ const nodesWithEdges = new Set();
405
+ const edgesByType = {
406
+ triggers: 0, produces: 0, reads: 0, calls: 0, implements: 0, 'maps-to': 0, 'derived-from': 0,
407
+ };
408
+ for (const edgeList of targetGraph.edgesByFrom.values()) {
409
+ for (const edge of edgeList) {
410
+ if (!GRAPH_SEMANTIC_EDGE_TYPES.has(edge.type))
411
+ continue;
412
+ edgesByType[edge.type]++;
413
+ nodesWithEdges.add(edge.from);
414
+ nodesWithEdges.add(edge.to);
415
+ }
416
+ }
417
+ const orphanNodeCount = [...targetGraph.nodesById.keys()]
418
+ .filter(id => !nodesWithEdges.has(id)).length;
419
+ res.json({
420
+ nodeCount: targetGraph.nodesById.size,
421
+ componentCount: components.size,
422
+ orphanNodeCount,
423
+ edgesByType,
424
+ diagnosticCount: targetGraph.diagnostics.length,
425
+ });
426
+ });
387
427
  app.get('/api/cluster', async (req, res) => {
388
428
  const nodeId = typeof req.query.nodeId === 'string' ? req.query.nodeId : undefined;
389
429
  if (!nodeId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/corum",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
package/web/app.jsx CHANGED
@@ -494,8 +494,189 @@ function BranchBar({ branches, branchResults, viewingRef, overlayRefs, overlayMo
494
494
  );
495
495
  }
496
496
 
497
- function DashboardPage() {
498
- return <div className="content"><h1>Dashboard</h1></div>;
497
+ function HeroCard({ value, label }) {
498
+ return (
499
+ <div className="hero-card">
500
+ <div className="hero-number">{value}</div>
501
+ <div className="hero-label">{label}</div>
502
+ </div>
503
+ );
504
+ }
505
+
506
+ function DashboardPage({ nodes, templates, gitMode, viewingRef, branches, branchResults }) {
507
+ const [stats, setStats] = useState(null);
508
+ const [branchDiff, setBranchDiff] = useState(null);
509
+
510
+ const defaultBranchRef = branches.find(b => b.isDefault)?.ref ?? null;
511
+ const isOnNonDefaultBranch = gitMode && viewingRef && defaultBranchRef && viewingRef !== defaultBranchRef;
512
+
513
+ useEffect(() => {
514
+ const refParam = viewingRef ? `?ref=${encodeURIComponent(viewingRef)}` : '';
515
+ fetch(`/api/stats${refParam}`)
516
+ .then(res => res.ok ? res.json() : Promise.reject(res.status))
517
+ .then(setStats)
518
+ .catch(() => setStats(null));
519
+ }, [viewingRef]);
520
+
521
+ useEffect(() => {
522
+ if (!isOnNonDefaultBranch) { setBranchDiff(null); return; }
523
+ fetch(`/api/overlay/${encodeURIComponent(viewingRef)}`)
524
+ .then(res => res.ok ? res.json() : Promise.reject(res.status))
525
+ .then(data => {
526
+ const added = (data.nodes || []).filter(n => n.ghostState === 'local').length;
527
+ const removed = (data.nodes || []).filter(n => n.ghostState === 'default-only').length;
528
+ setBranchDiff({ added, removed, defaultBranch: defaultBranchRef });
529
+ })
530
+ .catch(() => setBranchDiff(null));
531
+ }, [isOnNonDefaultBranch, viewingRef, defaultBranchRef]);
532
+
533
+ const componentCount = new Set(nodes.map(n => n.component).filter(Boolean)).size;
534
+ const nodeCount = nodes.length;
535
+ const totalEdges = stats ? Object.values(stats.edgesByType).reduce((a, b) => a + b, 0) : '…';
536
+
537
+ const templateMap = new Map(templates.map(t => [t.name, t]));
538
+
539
+ const nodesByTemplate = [...nodes.reduce((acc, node) => {
540
+ acc.set(node.template, (acc.get(node.template) ?? 0) + 1);
541
+ return acc;
542
+ }, new Map()).entries()].sort((a, b) => b[1] - a[1]);
543
+
544
+ const nodesByState = [...nodes.reduce((acc, node) => {
545
+ acc.set(node.state, (acc.get(node.state) ?? 0) + 1);
546
+ return acc;
547
+ }, new Map()).entries()].sort((a, b) => b[1] - a[1]);
548
+
549
+ const nodesByStability = [...nodes.reduce((acc, node) => {
550
+ acc.set(node.stability, (acc.get(node.stability) ?? 0) + 1);
551
+ return acc;
552
+ }, new Map()).entries()].sort((a, b) => b[1] - a[1]);
553
+
554
+ const edgeRows = stats
555
+ ? Object.entries(stats.edgesByType).filter(([, count]) => count > 0).sort((a, b) => b[1] - a[1])
556
+ : [];
557
+
558
+ return (
559
+ <div className="content">
560
+ <div className="dashboard-hero">
561
+ <HeroCard value={componentCount} label="Components" />
562
+ <HeroCard value={nodeCount} label="Nodes" />
563
+ <HeroCard value={totalEdges} label="Edges" />
564
+ <HeroCard value={stats ? stats.orphanNodeCount : '…'} label="Orphan Nodes" />
565
+ </div>
566
+
567
+ {branchDiff && (
568
+ <div className="branch-diff-callout">
569
+ <span className="branch-diff-branch">⎇ {viewingRef}</span>
570
+ <span className="branch-diff-label">vs {branchDiff.defaultBranch}</span>
571
+ {branchDiff.added > 0 && <span className="branch-diff-added">+{branchDiff.added} added</span>}
572
+ {branchDiff.removed > 0 && <span className="branch-diff-removed">−{branchDiff.removed} removed</span>}
573
+ {branchDiff.added === 0 && branchDiff.removed === 0 && (
574
+ <span className="branch-diff-label">No changes</span>
575
+ )}
576
+ </div>
577
+ )}
578
+
579
+ <div className="dashboard-grid">
580
+ <div className="dashboard-panel">
581
+ <div className="card-head">Nodes by Type</div>
582
+ <div className="card-body" style={{ padding: '12px 16px' }}>
583
+ {nodesByTemplate.map(([name, count]) => {
584
+ const tmpl = templateMap.get(name);
585
+ const colour = tmpl?.ui?.colour ?? 'var(--ink-4)';
586
+ return (
587
+ <div key={name} className="stat-row">
588
+ <span className="stat-row-label">
589
+ <span className="stat-colour-dot" style={{ background: colour }} />
590
+ {tmpl?.ui?.displayName ?? name}
591
+ </span>
592
+ <span className="stat-row-value">{count}</span>
593
+ </div>
594
+ );
595
+ })}
596
+ </div>
597
+ </div>
598
+
599
+ <div className="dashboard-panel">
600
+ <div className="card-head">State Distribution</div>
601
+ <div className="card-body" style={{ padding: '12px 16px' }}>
602
+ {nodesByState.map(([state, count]) => (
603
+ <div key={state} className="stat-row">
604
+ <span className="stat-row-label"><StateTag state={state} /></span>
605
+ <span className="stat-row-value">{count}</span>
606
+ </div>
607
+ ))}
608
+ </div>
609
+ </div>
610
+
611
+ <div className="dashboard-panel">
612
+ <div className="card-head">Edge Types</div>
613
+ <div className="card-body" style={{ padding: '12px 16px' }}>
614
+ {stats === null && <div className="label-sm">Loading…</div>}
615
+ {stats !== null && edgeRows.length === 0 && <div className="label-sm">No semantic edges.</div>}
616
+ {edgeRows.map(([type, count]) => (
617
+ <div key={type} className="stat-row">
618
+ <span className="stat-row-label">
619
+ <span className="tag" style={EDGE_TYPE_STYLES[type] ?? {}}>{type}</span>
620
+ </span>
621
+ <span className="stat-row-value">{count}</span>
622
+ </div>
623
+ ))}
624
+ </div>
625
+ </div>
626
+
627
+ <div className="dashboard-panel">
628
+ <div className="card-head">Stability</div>
629
+ <div className="card-body" style={{ padding: '12px 16px' }}>
630
+ {nodesByStability.map(([stability, count]) => (
631
+ <div key={stability} className="stat-row">
632
+ <span className="stat-row-label"><StabilityTag stability={stability} /></span>
633
+ <span className="stat-row-value">{count}</span>
634
+ </div>
635
+ ))}
636
+ </div>
637
+ </div>
638
+
639
+ <div className="dashboard-panel">
640
+ <div className="card-head">Diagnostics</div>
641
+ <div className="card-body" style={{ padding: '12px 16px' }}>
642
+ {stats === null && <div className="label-sm">Loading…</div>}
643
+ {stats !== null && stats.diagnosticCount > 0 && (
644
+ <span style={{ color: 'var(--warn)' }}>
645
+ {stats.diagnosticCount} load warning{stats.diagnosticCount !== 1 ? 's' : ''}
646
+ </span>
647
+ )}
648
+ {stats !== null && stats.diagnosticCount === 0 && (
649
+ <span style={{ color: 'var(--ok)' }}>No issues</span>
650
+ )}
651
+ </div>
652
+ </div>
653
+
654
+ {gitMode && (
655
+ <div className="dashboard-panel">
656
+ <div className="card-head">Branch Health</div>
657
+ <div className="card-body" style={{ padding: '12px 16px' }}>
658
+ {branchResults.map(result => (
659
+ <div key={result.ref} className="stat-row">
660
+ <span className="stat-row-label">
661
+ <Icon
662
+ name={result.status === 'loaded' ? 'circle-check' : 'circle-xmark'}
663
+ size={12}
664
+ />
665
+ <span>{result.ref}</span>
666
+ </span>
667
+ {result.status === 'failed' && (
668
+ <span className="label-sm" style={{ color: 'var(--warn)', maxWidth: 200, textAlign: 'right' }}>
669
+ {result.diagnostics?.[0]?.message ?? result.error ?? 'failed'}
670
+ </span>
671
+ )}
672
+ </div>
673
+ ))}
674
+ </div>
675
+ </div>
676
+ )}
677
+ </div>
678
+ </div>
679
+ );
499
680
  }
500
681
 
501
682
  function ComponentsPage() {
@@ -900,7 +1081,16 @@ function App() {
900
1081
  } else if (error) {
901
1082
  page = <div className="content"><p style={{ color: 'var(--warn)' }}>Error loading graph: {error}</p></div>;
902
1083
  } else if (route.pathname === '/dashboard' || route.pathname === '/') {
903
- page = <DashboardPage />;
1084
+ page = (
1085
+ <DashboardPage
1086
+ nodes={nodes}
1087
+ templates={templates}
1088
+ gitMode={gitMode}
1089
+ viewingRef={viewingRef}
1090
+ branches={branches}
1091
+ branchResults={branchResults}
1092
+ />
1093
+ );
904
1094
  } else if (route.pathname === '/components') {
905
1095
  page = <ComponentsPage />;
906
1096
  } else if (route.pathname === '/node') {
@@ -41,24 +41,59 @@ function buildComponentMap(nodes, edges) {
41
41
  function buildFocusGraph(focalNodeId, nodes, edges, depth) {
42
42
  const nodeById = new Map(nodes.map(n => [n.id, n]));
43
43
  const visited = new Set([focalNodeId]);
44
- const queue = [{ id: focalNodeId, d: 0 }];
45
44
 
46
- while (queue.length > 0) {
47
- const { id, d } = queue.shift();
48
- if (d >= depth) continue;
45
+ // All depths use directed two-pass BFS (downstream + upstream separately).
46
+ // Undirected BFS lets upstream nodes "switch direction" and pull in sibling
47
+ // chains — nodes that share an ancestor or descendant but are not in the
48
+ // focal node's own lineage.
49
+ //
50
+ // parentId is an upstream relationship: an owned operation has no semantic
51
+ // edges of its own, so climbing to the parent aggregate is the only way to
52
+ // reach the edges that connect it to the wider graph. parentId traversal
53
+ // belongs in the upstream pass only; adding it to the downstream pass would
54
+ // re-introduce the same sideways crawl via the aggregate's other children.
55
+
56
+ const downQueue = [{ id: focalNodeId, d: 0 }];
57
+ while (downQueue.length > 0) {
58
+ const item = downQueue.shift();
59
+ const id = item.id;
60
+ if (item.d >= depth) continue;
61
+ for (const edge of edges) {
62
+ if (edge.from === id && !visited.has(edge.to) && nodeById.has(edge.to)) {
63
+ visited.add(edge.to);
64
+ downQueue.push({ id: edge.to, d: item.d + 1 });
65
+ }
66
+ }
67
+ }
68
+
69
+ const upQueue = [{ id: focalNodeId, d: 0 }];
70
+ while (upQueue.length > 0) {
71
+ const item = upQueue.shift();
72
+ const id = item.id;
73
+ if (item.d >= depth) continue;
49
74
  for (const edge of edges) {
50
- let neighborId = null;
51
- if (edge.from === id) neighborId = edge.to;
52
- else if (edge.to === id) neighborId = edge.from;
53
- if (!neighborId || visited.has(neighborId) || !nodeById.has(neighborId)) continue;
54
- visited.add(neighborId);
55
- queue.push({ id: neighborId, d: d + 1 });
75
+ if (edge.to === id && !visited.has(edge.from) && nodeById.has(edge.from)) {
76
+ visited.add(edge.from);
77
+ upQueue.push({ id: edge.from, d: item.d + 1 });
78
+ }
79
+ }
80
+ const pid = nodeById.get(id)?.parentId;
81
+ if (pid && !visited.has(pid) && nodeById.has(pid)) {
82
+ visited.add(pid);
83
+ upQueue.push({ id: pid, d: item.d + 1 });
56
84
  }
57
85
  }
58
86
 
87
+ const visibleEdges = edges.filter(e => visited.has(e.from) && visited.has(e.to));
88
+ const visibleNodeIds = new Set([focalNodeId]);
89
+ for (const edge of visibleEdges) {
90
+ visibleNodeIds.add(edge.from);
91
+ visibleNodeIds.add(edge.to);
92
+ }
93
+
59
94
  return {
60
- nodes: [...visited].map(id => nodeById.get(id)).filter(Boolean),
61
- edges: edges.filter(e => visited.has(e.from) && visited.has(e.to)),
95
+ nodes: [...visibleNodeIds].map(id => nodeById.get(id)).filter(Boolean),
96
+ edges: visibleEdges,
62
97
  };
63
98
  }
64
99
 
@@ -51,6 +51,66 @@ const { buildComponentMap, buildFocusGraph, applyEdgeTypeFilter, getDisplayName
51
51
  assert(focusAll.nodes.length === 4, 'buildFocusGraph depth=Infinity: includes all reachable nodes');
52
52
  assert(focusAll.edges.length === 3, 'buildFocusGraph depth=Infinity: includes all reachable edges');
53
53
 
54
+ // buildFocusGraph - depth Infinity directed lineage (no sideways crawl)
55
+ // ordersApi → order and ordersApi → paymentsApi → payment
56
+ // Focusing on payment: upstream = {paymentsApi, ordersApi}, downstream = {}
57
+ // order must NOT appear — it's downstream of ordersApi but not in payment's lineage
58
+ const focusPayment = buildFocusGraph('payments.DomainModel.payment', nodes, edges, Infinity);
59
+ assert(focusPayment.nodes.length === 3, 'buildFocusGraph depth=Infinity directed: excludes sideways nodes');
60
+ assert(!focusPayment.nodes.some(n => n.id === 'orders.DomainModel.order'), 'buildFocusGraph depth=Infinity directed: sibling branch excluded');
61
+ assert(focusPayment.nodes.some(n => n.id === 'orders.RestAPI.ordersApi'), 'buildFocusGraph depth=Infinity directed: upstream root included');
62
+
63
+ // buildFocusGraph - directed BFS + parentId traversal (upstream pass only)
64
+ // op --produces--> event (op is upstream of event)
65
+ // op.parentId = agg
66
+ // agg --reads--> tgt (tgt is sideways — downstream of agg only)
67
+ //
68
+ // From event, upstream directed BFS: event ← op (d=1) ← agg (d=2 via parentId).
69
+ // tgt must NOT appear at any depth: only reachable via a downstream edge from agg,
70
+ // which the upstream pass never follows.
71
+ const parentNodes = [
72
+ { id: 'b.Event.e', template: 'DomainEvent', component: 'b', state: 'agreed', stability: 'stable', parentId: null },
73
+ { id: 'z.DomainModel.root', template: 'DomainModel', component: 'z', state: 'agreed', stability: 'stable', parentId: null },
74
+ { id: 'a.DomainModel.agg', template: 'DomainModel', component: 'a', state: 'agreed', stability: 'stable', parentId: null },
75
+ { id: 'a.DomainModel.agg.operations.op', template: 'DomainOperation', component: 'a', state: 'agreed', stability: 'stable', parentId: 'a.DomainModel.agg' },
76
+ { id: 'c.DomainModel.tgt', template: 'DomainModel', component: 'c', state: 'agreed', stability: 'stable', parentId: null },
77
+ ];
78
+ const parentEdges = [
79
+ { id: 'p1', from: 'a.DomainModel.agg.operations.op', to: 'b.Event.e', type: 'produces' },
80
+ { id: 'p0', from: 'z.DomainModel.root', to: 'a.DomainModel.agg', type: 'reads' },
81
+ { id: 'p2', from: 'a.DomainModel.agg', to: 'c.DomainModel.tgt', type: 'reads' },
82
+ ];
83
+ const fp1 = buildFocusGraph('b.Event.e', parentNodes, parentEdges, 1);
84
+ assert(fp1.nodes.some(n => n.id === 'a.DomainModel.agg.operations.op'), 'parentId: depth=1 includes producing op (upstream)');
85
+ assert(!fp1.nodes.some(n => n.id === 'a.DomainModel.agg'), 'parentId: depth=1 does not yet include aggregate');
86
+ const fp2 = buildFocusGraph('b.Event.e', parentNodes, parentEdges, 2);
87
+ assert(!fp2.nodes.some(n => n.id === 'a.DomainModel.agg'), 'parentId: depth=2 prunes aggregate when it has no surviving semantic edge');
88
+ assert(!fp2.nodes.some(n => n.id === 'c.DomainModel.tgt'), 'parentId: depth=2 excludes sideways tgt');
89
+ const fp3 = buildFocusGraph('b.Event.e', parentNodes, parentEdges, 3);
90
+ assert(fp3.nodes.some(n => n.id === 'z.DomainModel.root'), 'parentId: depth=3 still uses aggregate traversal to reach upstream root');
91
+ assert(!fp3.nodes.some(n => n.id === 'c.DomainModel.tgt'), 'parentId: depth=3 still excludes sideways tgt (directed)');
92
+
93
+ // buildFocusGraph - Infinity keeps the same upstream parentId traversal
94
+ const fpInf = buildFocusGraph('b.Event.e', parentNodes, parentEdges, Infinity);
95
+ assert(fpInf.nodes.some(n => n.id === 'a.DomainModel.agg.operations.op'), 'parentId: Infinity follows semantic edges to op');
96
+ assert(fpInf.nodes.some(n => n.id === 'z.DomainModel.root'), 'parentId: Infinity climbs through parent aggregate to upstream root');
97
+ assert(fpInf.nodes.some(n => n.id === 'a.DomainModel.agg'), 'parentId: Infinity keeps aggregate once it participates in a surviving semantic edge');
98
+ assert(!fpInf.nodes.some(n => n.id === 'c.DomainModel.tgt'), 'parentId: Infinity still excludes aggregate sideways connections');
99
+
100
+ // buildFocusGraph - climbed parent without a surviving semantic edge is pruned
101
+ const orphanParentNodes = [
102
+ { id: 'payruns.DomainEvent.finalised', template: 'DomainEvent', component: 'payruns', state: 'agreed', stability: 'stable', parentId: null },
103
+ { id: 'payruns.DomainModel.PayRunAggregate', template: 'DomainModel', component: 'payruns', state: 'agreed', stability: 'stable', parentId: null },
104
+ { id: 'payruns.DomainModel.PayRunAggregate.operations.Finalise', template: 'DomainOperation', component: 'payruns', state: 'agreed', stability: 'stable', parentId: 'payruns.DomainModel.PayRunAggregate' },
105
+ ];
106
+ const orphanParentEdges = [
107
+ { id: 'o1', from: 'payruns.DomainModel.PayRunAggregate.operations.Finalise', to: 'payruns.DomainEvent.finalised', type: 'produces' },
108
+ ];
109
+ const orphanParentFocus = buildFocusGraph('payruns.DomainEvent.finalised', orphanParentNodes, orphanParentEdges, 2);
110
+ assert(orphanParentFocus.nodes.some(n => n.id === 'payruns.DomainModel.PayRunAggregate.operations.Finalise'), 'prune orphan parent: producing op remains visible');
111
+ assert(!orphanParentFocus.nodes.some(n => n.id === 'payruns.DomainModel.PayRunAggregate'), 'prune orphan parent: aggregate without surviving edge is omitted');
112
+ assert(orphanParentFocus.edges.length === 1, 'prune orphan parent: semantic edge remains intact');
113
+
54
114
  // applyEdgeTypeFilter
55
115
  const filtered = applyEdgeTypeFilter(edges, new Set(['reads']));
56
116
  assert(filtered.length === 2, 'applyEdgeTypeFilter: keeps only matching type');
package/web/graph.jsx CHANGED
@@ -30,9 +30,10 @@ const EDGE_PILL_STYLES = {
30
30
  };
31
31
 
32
32
  const ALL_EDGE_TYPES = ['triggers', 'produces', 'reads', 'calls', 'implements', 'maps-to', 'derived-from'];
33
+ const DEPTH_STEPS = [1, 2, 3, 4, 5, Infinity];
33
34
 
34
35
  const NODE_W = 210;
35
- const NODE_H = 88;
36
+ const NODE_H = 100;
36
37
  const COMP_W = 180;
37
38
  const COMP_H = 72;
38
39
 
@@ -81,6 +82,7 @@ function buildRFNodesForNodes(graphNodes, templateMap, onNodeClick, viewingRef)
81
82
  return graphNodes.map(n => {
82
83
  const tmpl = templateMap.get(n.template);
83
84
  const colour = tmpl?.ui?.colour ?? 'var(--ink-4)';
85
+ const parentLabel = n.parentId ? getDisplayName(n.parentId) : null;
84
86
  return {
85
87
  id: n.id,
86
88
  type: 'nodeCard',
@@ -95,6 +97,7 @@ function buildRFNodesForNodes(graphNodes, templateMap, onNodeClick, viewingRef)
95
97
  stability: n.stability,
96
98
  onClick: () => onNodeClick(n.id),
97
99
  viewingRef,
100
+ parentLabel,
98
101
  },
99
102
  };
100
103
  });
@@ -121,18 +124,23 @@ function NodeCardNode({ data }) {
121
124
  const colour = data.colour ?? 'var(--ink-4)';
122
125
  return (
123
126
  <div className="graph-node-card" onClick={data.onClick}>
127
+ {data.parentLabel && (
128
+ <div className="graph-node-card-owner">{data.parentLabel}</div>
129
+ )}
124
130
  <RF.Handle type="target" position={RF.Position.Left} style={{ opacity: 0 }} />
125
131
  <div className="graph-node-card-bar" style={{ background: colour }} />
126
- <div className="graph-node-card-header">
127
- <TemplateBadge name={data.templateLabel} colour={colour} />
128
- <StateTag state={data.state} />
129
- </div>
130
132
  <div className="graph-node-card-body">
131
- <div className="graph-node-card-name" title={data.nodeId}>{data.label}</div>
132
- <div className="graph-node-card-component">{data.component}</div>
133
+ <div className="graph-node-card-text">
134
+ <div className="graph-node-card-name" title={data.nodeId}>{data.label}</div>
135
+ <div className="graph-node-card-component">{data.component}</div>
136
+ </div>
137
+ <div className="graph-node-card-type">
138
+ <TemplateBadge name={data.templateLabel} colour={colour} />
139
+ </div>
133
140
  </div>
134
141
  <div className="graph-node-card-footer">
135
142
  <StabilityTag stability={data.stability} />
143
+ <StateTag state={data.state} />
136
144
  <button
137
145
  className="graph-node-card-link"
138
146
  title="View node details"
@@ -212,16 +220,18 @@ function GraphToolbar({ visibleEdgeTypes, onToggleEdgeType, showMinimap, onToggl
212
220
  <div className="graph-toolbar-sep" />
213
221
  {level === 'focus' && (
214
222
  <>
215
- <div className="graph-depth-seg">
216
- {[['1', 1], ['2', 2], ['∞', Infinity]].map(([label, val]) => (
217
- <button
218
- key={label}
219
- className={`graph-depth-item${depth === val ? ' active' : ''}`}
220
- onClick={() => onDepth(val)}
221
- >
222
- {label}
223
- </button>
224
- ))}
223
+ <div className="graph-depth-ctrl">
224
+ <button
225
+ className="graph-depth-btn"
226
+ onClick={() => onDepth(DEPTH_STEPS[DEPTH_STEPS.indexOf(depth) - 1])}
227
+ disabled={depth === DEPTH_STEPS[0]}
228
+ >−</button>
229
+ <span className="graph-depth-val">{depth === Infinity ? '∞' : depth}</span>
230
+ <button
231
+ className="graph-depth-btn"
232
+ onClick={() => onDepth(DEPTH_STEPS[DEPTH_STEPS.indexOf(depth) + 1])}
233
+ disabled={depth === DEPTH_STEPS[DEPTH_STEPS.length - 1]}
234
+ >+</button>
225
235
  </div>
226
236
  <div className="graph-focus-search" ref={searchRef}>
227
237
  <input
@@ -260,8 +270,11 @@ function GraphView({ route, viewingRef, templates }) {
260
270
  const [error, setError] = useState(null);
261
271
  const [visibleEdgeTypes, setVisibleEdgeTypes] = useState(loadVisibleEdgeTypes);
262
272
  const [showMinimap, setShowMinimap] = useState(false);
263
- const [depth, setDepth] = useState(1);
273
+ const [depth, setDepth] = useState(2);
264
274
  const [layoutKey, setLayoutKey] = useState(0);
275
+ const [reactFlowInstance, setReactFlowInstance] = useState(null);
276
+ const pendingViewportRef = useRef(null);
277
+ const lastFocusedNodeIdRef = useRef(null);
265
278
  const [rfNodes, setRfNodes, onNodesChange] = useNodesState([]);
266
279
  const [rfEdges, setRfEdges, onEdgesChange] = useEdgesState([]);
267
280
 
@@ -323,6 +336,7 @@ function GraphView({ route, viewingRef, templates }) {
323
336
 
324
337
  useEffect(() => {
325
338
  if (level !== 'component' || !level1) return;
339
+ pendingViewportRef.current = { type: 'full' };
326
340
  setRfNodes(level1.rfN);
327
341
  setRfEdges(level1.rfE);
328
342
  }, [level, level1]);
@@ -354,10 +368,16 @@ function GraphView({ route, viewingRef, templates }) {
354
368
 
355
369
  useEffect(() => {
356
370
  if (level !== 'interior' || !level2) return;
371
+ pendingViewportRef.current = { type: 'full' };
357
372
  setRfNodes(level2.rfN);
358
373
  setRfEdges(level2.rfE);
359
374
  }, [level, level2]);
360
375
 
376
+ useEffect(() => {
377
+ if (level === 'focus') return;
378
+ lastFocusedNodeIdRef.current = null;
379
+ }, [level]);
380
+
361
381
  // Level 3: node focus
362
382
  const level3 = useMemo(() => {
363
383
  if (!graphData || !focalNodeId) return null;
@@ -380,9 +400,45 @@ function GraphView({ route, viewingRef, templates }) {
380
400
 
381
401
  useEffect(() => {
382
402
  if (level !== 'focus' || !level3) return;
403
+ const focalChanged = lastFocusedNodeIdRef.current !== focalNodeId;
404
+ if (focalChanged) {
405
+ pendingViewportRef.current = { type: 'focus', nodeId: focalNodeId };
406
+ }
407
+ lastFocusedNodeIdRef.current = focalNodeId;
383
408
  setRfNodes(level3.rfN);
384
409
  setRfEdges(level3.rfE);
385
- }, [level, level3]);
410
+ }, [level, level3, focalNodeId]);
411
+
412
+ useEffect(() => {
413
+ if (!reactFlowInstance || !rfNodes.length) return;
414
+ let frameId = null;
415
+ function fitPendingViewport() {
416
+ const pending = pendingViewportRef.current;
417
+ if (!pending) return;
418
+ if (pending.type === 'focus' && !rfNodes.some(node => node.id === pending.nodeId)) return;
419
+ if (pending.type === 'focus') {
420
+ const measuredNode = reactFlowInstance.getNode(pending.nodeId);
421
+ if (!measuredNode?.width || !measuredNode?.height) {
422
+ frameId = requestAnimationFrame(fitPendingViewport);
423
+ return;
424
+ }
425
+ reactFlowInstance.fitView({
426
+ duration: 0,
427
+ padding: 0.2,
428
+ });
429
+ } else {
430
+ reactFlowInstance.fitView({
431
+ duration: 0,
432
+ padding: 0.2,
433
+ });
434
+ }
435
+ pendingViewportRef.current = null;
436
+ }
437
+ frameId = requestAnimationFrame(fitPendingViewport);
438
+ return () => {
439
+ if (frameId !== null) cancelAnimationFrame(frameId);
440
+ };
441
+ }, [reactFlowInstance, rfNodes, rfEdges]);
386
442
 
387
443
  function handleToggleEdgeType(type) {
388
444
  setVisibleEdgeTypes(prev => {
@@ -425,6 +481,7 @@ function GraphView({ route, viewingRef, templates }) {
425
481
  edges={rfEdges}
426
482
  onNodesChange={onNodesChange}
427
483
  onEdgesChange={onEdgesChange}
484
+ onInit={setReactFlowInstance}
428
485
  nodeTypes={nodeTypes}
429
486
  fitView
430
487
  proOptions={{ hideAttribution: true }}
package/web/style.css CHANGED
@@ -1077,28 +1077,38 @@ button {
1077
1077
  .graph-toolbar-btn:hover { background: var(--paper-2); }
1078
1078
  .graph-toolbar-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
1079
1079
 
1080
- .graph-depth-seg {
1080
+ .graph-depth-ctrl {
1081
1081
  display: flex;
1082
- gap: 1px;
1083
- background: var(--rule);
1084
- border-radius: 4px;
1082
+ align-items: center;
1083
+ border: 1px solid var(--rule-2);
1084
+ border-radius: var(--radius);
1085
1085
  overflow: hidden;
1086
1086
  }
1087
1087
 
1088
- .graph-depth-item {
1089
- padding: 3px 8px;
1090
- background: var(--paper);
1091
- color: var(--ink-2);
1088
+ .graph-depth-btn {
1089
+ padding: 2px 7px;
1090
+ font-size: 14px;
1091
+ line-height: 1;
1092
1092
  cursor: pointer;
1093
- font: inherit;
1094
- font-size: 11px;
1093
+ background: none;
1095
1094
  border: none;
1095
+ color: var(--ink-3);
1096
+ font: inherit;
1096
1097
  }
1097
1098
 
1098
- .graph-depth-item.active {
1099
- background: var(--accent);
1100
- color: #fff;
1099
+ .graph-depth-btn:hover:not(:disabled) { color: var(--ink); background: var(--paper-2); }
1100
+ .graph-depth-btn:disabled { opacity: 0.3; cursor: not-allowed; }
1101
+
1102
+ .graph-depth-val {
1103
+ min-width: 22px;
1104
+ text-align: center;
1105
+ font-size: 11px;
1101
1106
  font-weight: 600;
1107
+ color: var(--ink);
1108
+ border-left: 1px solid var(--rule-2);
1109
+ border-right: 1px solid var(--rule-2);
1110
+ padding: 2px 4px;
1111
+ user-select: none;
1102
1112
  }
1103
1113
 
1104
1114
  .graph-focus-search {
@@ -1258,23 +1268,33 @@ button {
1258
1268
  border-radius: var(--radius) 0 0 var(--radius);
1259
1269
  }
1260
1270
 
1261
- .graph-node-card-header {
1262
- display: flex;
1263
- align-items: center;
1264
- gap: 5px;
1265
- padding: 6px 8px 4px 10px;
1266
- }
1271
+ .graph-node-card-body { padding: 8px 8px 4px 10px; }
1267
1272
 
1268
- .graph-node-card-body { padding: 2px 8px 4px 10px; }
1273
+ .graph-node-card-text {
1274
+ min-height: calc((1.25em * 2) + 12px);
1275
+ }
1269
1276
 
1270
1277
  .graph-node-card-name {
1271
1278
  font-weight: 600;
1272
1279
  font-size: 13px;
1273
1280
  color: var(--ink);
1281
+ white-space: normal;
1282
+ overflow: visible;
1283
+ text-overflow: clip;
1284
+ line-height: 1.25;
1285
+ overflow-wrap: anywhere;
1286
+ }
1287
+
1288
+ .graph-node-card-owner {
1289
+ position: absolute;
1290
+ top: -16px;
1291
+ left: 8px;
1292
+ font-size: 10px;
1293
+ font-weight: 500;
1294
+ color: var(--ink-3);
1274
1295
  white-space: nowrap;
1275
- overflow: hidden;
1276
- text-overflow: ellipsis;
1277
- max-width: 180px;
1296
+ pointer-events: none;
1297
+ line-height: 1;
1278
1298
  }
1279
1299
 
1280
1300
  .graph-node-card-component {
@@ -1286,16 +1306,21 @@ button {
1286
1306
  text-overflow: ellipsis;
1287
1307
  }
1288
1308
 
1309
+ .graph-node-card-type {
1310
+ margin-top: 6px;
1311
+ }
1312
+
1289
1313
  .graph-node-card-footer {
1290
1314
  display: flex;
1291
1315
  align-items: center;
1292
- justify-content: space-between;
1316
+ gap: 6px;
1293
1317
  padding: 3px 8px 5px 10px;
1294
1318
  border-top: 1px solid var(--rule);
1295
1319
  margin-top: 3px;
1296
1320
  }
1297
1321
 
1298
1322
  .graph-node-card-link {
1323
+ margin-left: auto;
1299
1324
  color: var(--ink-4);
1300
1325
  cursor: pointer;
1301
1326
  font-size: 11px;
@@ -1358,28 +1383,6 @@ button {
1358
1383
  flex-shrink: 0;
1359
1384
  }
1360
1385
 
1361
- /* Depth segmented control */
1362
- .graph-depth-seg {
1363
- display: flex;
1364
- border: 1px solid var(--rule-2);
1365
- border-radius: var(--radius);
1366
- overflow: hidden;
1367
- }
1368
-
1369
- .graph-depth-item {
1370
- padding: 3px 10px;
1371
- font-size: 11px;
1372
- font-weight: 500;
1373
- cursor: pointer;
1374
- background: none;
1375
- border: none;
1376
- border-right: 1px solid var(--rule-2);
1377
- color: var(--ink-3);
1378
- font: inherit;
1379
- }
1380
-
1381
- .graph-depth-item:last-child { border-right: none; }
1382
- .graph-depth-item.active { background: var(--paper-3); color: var(--ink); }
1383
1386
 
1384
1387
  /* Toolbar buttons */
1385
1388
  .graph-toolbar-btn {
@@ -1454,3 +1457,112 @@ button {
1454
1457
  }
1455
1458
 
1456
1459
  .graph-nav-link:hover { color: var(--ink-2); }
1460
+
1461
+ /* ── Dashboard ────────────────────────────────────── */
1462
+
1463
+ .dashboard-hero {
1464
+ display: flex;
1465
+ gap: 16px;
1466
+ margin-bottom: 24px;
1467
+ }
1468
+
1469
+ .hero-card {
1470
+ flex: 1;
1471
+ background: var(--paper-2);
1472
+ border: 1px solid var(--rule);
1473
+ border-radius: var(--radius);
1474
+ padding: 20px 24px;
1475
+ }
1476
+
1477
+ .hero-number {
1478
+ font-size: 32px;
1479
+ font-weight: 700;
1480
+ line-height: 1;
1481
+ color: var(--ink);
1482
+ margin-bottom: 6px;
1483
+ font-family: 'Space Grotesk', system-ui, sans-serif;
1484
+ }
1485
+
1486
+ .hero-label {
1487
+ font-size: 11px;
1488
+ font-weight: 600;
1489
+ text-transform: uppercase;
1490
+ letter-spacing: 0.1em;
1491
+ color: var(--ink-3);
1492
+ }
1493
+
1494
+ .branch-diff-callout {
1495
+ display: flex;
1496
+ align-items: center;
1497
+ gap: 12px;
1498
+ padding: 10px 16px;
1499
+ background: var(--paper-2);
1500
+ border: 1px solid var(--rule);
1501
+ border-radius: var(--radius);
1502
+ margin-bottom: 24px;
1503
+ font-size: 12px;
1504
+ }
1505
+
1506
+ .branch-diff-branch {
1507
+ font-family: 'JetBrains Mono', ui-monospace, monospace;
1508
+ font-size: 11px;
1509
+ color: var(--ink-2);
1510
+ }
1511
+
1512
+ .branch-diff-label {
1513
+ color: var(--ink-3);
1514
+ font-size: 11px;
1515
+ }
1516
+
1517
+ .branch-diff-added {
1518
+ color: var(--ok);
1519
+ font-weight: 600;
1520
+ }
1521
+
1522
+ .branch-diff-removed {
1523
+ color: var(--warn);
1524
+ font-weight: 600;
1525
+ }
1526
+
1527
+ .dashboard-grid {
1528
+ display: grid;
1529
+ grid-template-columns: 1fr 1fr;
1530
+ gap: 16px;
1531
+ }
1532
+
1533
+ .dashboard-panel {
1534
+ overflow: hidden;
1535
+ border: 1px solid var(--rule-2);
1536
+ border-radius: 8px;
1537
+ background: var(--paper);
1538
+ }
1539
+
1540
+ .stat-row {
1541
+ display: flex;
1542
+ align-items: center;
1543
+ justify-content: space-between;
1544
+ gap: 8px;
1545
+ padding: 4px 0;
1546
+ }
1547
+
1548
+ .stat-row-label {
1549
+ display: flex;
1550
+ align-items: center;
1551
+ gap: 8px;
1552
+ color: var(--ink-2);
1553
+ font-size: 12px;
1554
+ }
1555
+
1556
+ .stat-row-value {
1557
+ font-weight: 600;
1558
+ font-size: 13px;
1559
+ color: var(--ink);
1560
+ flex-shrink: 0;
1561
+ }
1562
+
1563
+ .stat-colour-dot {
1564
+ width: 8px;
1565
+ height: 8px;
1566
+ border-radius: 50%;
1567
+ flex-shrink: 0;
1568
+ }