@principal-ai/subsystems-react 0.56.20 → 0.56.22

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.
Files changed (54) hide show
  1. package/dist/index.d.ts +4 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/subsystem/C4Graph.d.ts +2 -69
  6. package/dist/subsystem/C4Graph.d.ts.map +1 -1
  7. package/dist/subsystem/C4Graph.js +8 -154
  8. package/dist/subsystem/C4Graph.js.map +1 -1
  9. package/dist/subsystem/C4NodeCard.d.ts +1 -47
  10. package/dist/subsystem/C4NodeCard.d.ts.map +1 -1
  11. package/dist/subsystem/C4NodeCard.js +6 -141
  12. package/dist/subsystem/C4NodeCard.js.map +1 -1
  13. package/dist/subsystem/ContainersPanel.d.ts +33 -0
  14. package/dist/subsystem/ContainersPanel.d.ts.map +1 -0
  15. package/dist/subsystem/ContainersPanel.js +116 -0
  16. package/dist/subsystem/ContainersPanel.js.map +1 -0
  17. package/dist/subsystem/SubsystemComponentGraph.d.ts +27 -1
  18. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  19. package/dist/subsystem/SubsystemComponentGraph.js +147 -21
  20. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  21. package/dist/subsystem/containerCard.d.ts +132 -0
  22. package/dist/subsystem/containerCard.d.ts.map +1 -0
  23. package/dist/subsystem/containerCard.js +167 -0
  24. package/dist/subsystem/containerCard.js.map +1 -0
  25. package/dist/subsystem/graphChrome.d.ts +11 -8
  26. package/dist/subsystem/graphChrome.d.ts.map +1 -1
  27. package/dist/subsystem/graphChrome.js +11 -9
  28. package/dist/subsystem/graphChrome.js.map +1 -1
  29. package/dist/subsystem/graphMorph.d.ts +142 -0
  30. package/dist/subsystem/graphMorph.d.ts.map +1 -0
  31. package/dist/subsystem/graphMorph.js +177 -0
  32. package/dist/subsystem/graphMorph.js.map +1 -0
  33. package/dist/subsystem/model.d.ts +89 -0
  34. package/dist/subsystem/model.d.ts.map +1 -1
  35. package/dist/subsystem/model.js +224 -15
  36. package/dist/subsystem/model.js.map +1 -1
  37. package/dist/subsystem/nodes.d.ts +9 -3
  38. package/dist/subsystem/nodes.d.ts.map +1 -1
  39. package/dist/subsystem/nodes.js +134 -82
  40. package/dist/subsystem/nodes.js.map +1 -1
  41. package/package.json +1 -1
  42. package/src/index.ts +5 -0
  43. package/src/stories/Canvases/Subsystem/ContainerFrames.stories.tsx +132 -0
  44. package/src/subsystem/C4Graph.tsx +20 -180
  45. package/src/subsystem/C4NodeCard.tsx +34 -202
  46. package/src/subsystem/ContainersPanel.tsx +239 -0
  47. package/src/subsystem/SubsystemComponentGraph.tsx +232 -25
  48. package/src/subsystem/containerCard.tsx +264 -0
  49. package/src/subsystem/graphChrome.tsx +11 -9
  50. package/src/subsystem/graphMorph.tsx +212 -0
  51. package/src/subsystem/model.collapse.test.ts +128 -0
  52. package/src/subsystem/model.ts +306 -16
  53. package/src/subsystem/nodes.group.test.tsx +125 -16
  54. package/src/subsystem/nodes.tsx +201 -91
@@ -32,12 +32,15 @@ import {
32
32
  applyNodeChanges,
33
33
  } from '@xyflow/react';
34
34
  import { useTheme } from '@principal-ade/industry-theme';
35
- import { ArrowDown, ArrowRight, Files, Route, Unlink, X } from 'lucide-react';
35
+ import { ArrowDown, ArrowRight, Boxes, Files, Route, Unlink, X } from 'lucide-react';
36
36
  import { IndustryMarkdownSlide } from 'themed-markdown';
37
37
  import {
38
38
  buildSubsystemGraph,
39
39
  deriveGraphEdges,
40
+ buildBoundaryLayoutGroups,
41
+ isCardFrame,
40
42
  isConstructsOnlyModel,
43
+ packageColor,
41
44
  moduleGroupNodeId,
42
45
  processGroupNodeId,
43
46
  isTrailMechanism,
@@ -52,11 +55,16 @@ import {
52
55
  type SubsystemEdgeView,
53
56
  type SubsystemLayoutDirection,
54
57
  type SubsystemGraphifyRelation,
58
+ type SubsystemGroupNodeData,
55
59
  type SubsystemNodeIssue,
60
+ type SubsystemProcessRegion,
61
+ type SubsystemRegionDetails,
56
62
  type SubsystemRegionIssue,
57
63
  type SubsystemTrail,
58
64
  } from './model';
59
65
  import { ConstructsCatalog } from './ConstructsCatalog';
66
+ import { ContainersPanel, type ContainerListItem } from './ContainersPanel';
67
+ import { technologyBrand } from './techIcons';
60
68
  import type { SubsystemOpenFileOptions } from './sourceSpan';
61
69
  import {
62
70
  SubsystemAgentsPanel,
@@ -161,6 +169,9 @@ interface PersistedViewState {
161
169
  diagnosticsTab?: 'issues' | 'agents';
162
170
  /** Flow direction chosen with the canvas toggle, restored on the next visit. */
163
171
  layoutDirection?: SubsystemLayoutDirection;
172
+ /** Whether card frames default to closed, and the frames toggled away from that default. */
173
+ framesCollapsed?: boolean;
174
+ toggledFrames?: string[];
164
175
  }
165
176
 
166
177
  const VIEW_STATE_PREFIX = 'principal.subsystems.viewState.';
@@ -192,6 +203,16 @@ function writeViewState(
192
203
  }
193
204
  }
194
205
 
206
+ /**
207
+ * Whether an edge is one of `set`. A line a collapsed frame rolled up stands in
208
+ * for each edge it absorbed, so it matches when any of those ids is in the set.
209
+ */
210
+ function edgeMatches(set: ReadonlySet<string>, e: Edge): boolean {
211
+ if (set.has(e.id)) return true;
212
+ const ids = (e.data as { rolledUpIds?: string[] } | undefined)?.rolledUpIds;
213
+ return ids?.some((id) => set.has(id)) === true;
214
+ }
215
+
195
216
  /** Screen-space rectangle of a component node, relative to the graph canvas box. */
196
217
  export interface SubsystemNodeRect {
197
218
  alias: string;
@@ -358,6 +379,12 @@ export interface SubsystemComponentGraphProps {
358
379
  autoPlayTrails?: boolean;
359
380
  /** Pause between autoplay steps in ms. @default 2500 */
360
381
  trailAutoPlayIntervalMs?: number;
382
+ /**
383
+ * Fires each time `autoPlayTrails` advances to a step, and with `null` when
384
+ * autoplay stops. Lets a host mirror the step highlight (dimming) in its own
385
+ * chrome around the graph.
386
+ */
387
+ onAutoPlayStep?: (ref: { trailId: string; stepIndex: number } | null) => void;
361
388
  /**
362
389
  * When false, focusing a trail/step does not call `fitView`.
363
390
  * @default true
@@ -540,6 +567,23 @@ export interface SubsystemComponentGraphProps {
540
567
  * membership are unchanged. See `BoundaryFrameOptions.codeProcessKeys`.
541
568
  */
542
569
  codeProcessKeys?: ReadonlySet<string>;
570
+ /**
571
+ * C4 facts for boundary regions, keyed by region key (the `process` value
572
+ * or the package purl key): technology, description, container sort. A
573
+ * process or package frame draws them in its header the way a C4 container
574
+ * card does — hosts pass what their accepted C4 container states. Regions
575
+ * not named here derive a technology from their members' `framework`.
576
+ * See `BoundaryFrameOptions.regionDetails`.
577
+ */
578
+ regionDetails?: Readonly<Record<string, SubsystemRegionDetails>>;
579
+ /**
580
+ * Whether process / package frames start closed: drawn as a container card
581
+ * with its members folded away and their lines rolled up onto it, the way a
582
+ * C4 container view reads. The user opens frames from the card, by
583
+ * double-click, or from the Containers list; a `persistKey` remembers the
584
+ * result. Default true; pass `false` to start with every frame laid out.
585
+ */
586
+ defaultFramesCollapsed?: boolean;
543
587
  }
544
588
 
545
589
  const nodeTypes: NodeTypes = {
@@ -649,11 +693,12 @@ const TrailDrawerContent = memo(function TrailDrawerContent({
649
693
  interface InnerProps extends SubsystemComponentGraphProps {
650
694
  measured: { w: number; h: number } | null;
651
695
  filesActive: boolean;
696
+ containersActive: boolean;
652
697
  sidebarScope: TrailSidebarScope;
653
698
  onSidebarTrailChange: (trailId: string | null) => void;
654
699
  }
655
700
 
656
- function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirection: layoutDirectionProp, defaultLayoutDirection = 'horizontal', onLayoutDirectionChange, hideLayoutToggle = false, refocusOnLayoutFlip = true, initialTrailId, onTrailSelect, onTrailStepHover, onReorderTrails, stepEmphasis, onRemoveStepEmphasis, onSelect, onEdgeSelect, measured: _measured, maxNodeWidth, showEdgeLabels, showSingletonFrames = true, moduleNesting, edgeView, hideSidebar, trailStepMode = 'focus', autoPlayTrails = false, trailAutoPlayIntervalMs = TRAIL_PLAY_PAUSE_MS, zoomOnTrailFocus = true, trailFocusDurationMs = 300, graphTitle, showTrailTitle = false, description, canvasOverlay, interactive = true, canvasBackground = 'theme', onLayoutReady, onNodeRects, sidebarExtra, sidebarAfterDescription, issues, showIssues, filesActive, sidebarScope, onSidebarTrailChange, focusIssueCategory, laneStatus, onSelectIssue, onApplyIssueFix, onHoverIssue, renderFileViewer, renderTrailViewer, onFileSelect, componentVerification, onInspectSymbol, boundaryColors, codeProcessKeys, hideDrawer = false, persistKey, liveEvents, agentsPanel }: InnerProps) {
701
+ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirection: layoutDirectionProp, defaultLayoutDirection = 'horizontal', onLayoutDirectionChange, hideLayoutToggle = false, refocusOnLayoutFlip = true, initialTrailId, onTrailSelect, onTrailStepHover, onReorderTrails, stepEmphasis, onRemoveStepEmphasis, onSelect, onEdgeSelect, measured: _measured, maxNodeWidth, showEdgeLabels, showSingletonFrames = true, moduleNesting, edgeView, hideSidebar, trailStepMode = 'focus', autoPlayTrails = false, trailAutoPlayIntervalMs = TRAIL_PLAY_PAUSE_MS, onAutoPlayStep, zoomOnTrailFocus = true, trailFocusDurationMs = 300, graphTitle, showTrailTitle = false, description, canvasOverlay, interactive = true, canvasBackground = 'theme', onLayoutReady, onNodeRects, sidebarExtra, sidebarAfterDescription, issues, showIssues, filesActive, sidebarScope, onSidebarTrailChange, focusIssueCategory, laneStatus, onSelectIssue, onApplyIssueFix, onHoverIssue, renderFileViewer, renderTrailViewer, onFileSelect, componentVerification, onInspectSymbol, boundaryColors, codeProcessKeys, regionDetails, defaultFramesCollapsed = true, containersActive, hideDrawer = false, persistKey, liveEvents, agentsPanel }: InnerProps) {
657
702
  const { theme } = useTheme();
658
703
  const { fitView, fitBounds } = useReactFlow();
659
704
  const [descriptionOpen, setDescriptionOpen] = useState(false);
@@ -683,6 +728,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
683
728
  onLayoutReadyRef.current = onLayoutReady;
684
729
  const onNodeRectsRef = useRef(onNodeRects);
685
730
  onNodeRectsRef.current = onNodeRects;
731
+ const onAutoPlayStepRef = useRef(onAutoPlayStep);
732
+ onAutoPlayStepRef.current = onAutoPlayStep;
686
733
  useEffect(() => {
687
734
  if (layoutReady) onLayoutReadyRef.current?.();
688
735
  }, [layoutReady]);
@@ -728,6 +775,38 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
728
775
  const [layoutTrailId, setLayoutTrailId] = useState<string | null>(null);
729
776
  const [committedTrailId, setCommittedTrailId] = useState<string | null>(null);
730
777
 
778
+ // Closed container cards. A frame folds its members away and rolls their
779
+ // lines up onto the card; opening it again lays the members back out. Each
780
+ // toggle is a layout flip like a direction change: ELK re-runs behind the
781
+ // edge fade while the frames slide to their new slots.
782
+ // Stored as a default plus exceptions so "close all" needs no knowledge of
783
+ // which frames the layout will produce: `framesCollapsed` is the default
784
+ // every card frame takes, `toggledGroupIds` the frames flipped away from it.
785
+ const [framesCollapsed, setFramesCollapsed] = useState<boolean>(
786
+ () => persisted.framesCollapsed ?? defaultFramesCollapsed,
787
+ );
788
+ const [toggledGroupIds, setToggledGroupIds] = useState<ReadonlySet<string>>(
789
+ () => new Set(persisted.toggledFrames ?? []),
790
+ );
791
+ const [committedCollapsed, setCommittedCollapsed] = useState<{
792
+ framesCollapsed: boolean;
793
+ toggled: ReadonlySet<string>;
794
+ }>({ framesCollapsed, toggled: toggledGroupIds });
795
+ const toggleCollapsed = useCallback((groupId: string) => {
796
+ setToggledGroupIds((prev) => {
797
+ const next = new Set(prev);
798
+ if (next.has(groupId)) next.delete(groupId);
799
+ else next.add(groupId);
800
+ return next;
801
+ });
802
+ }, []);
803
+ const setAllFramesCollapsed = useCallback((collapsed: boolean) => {
804
+ setFramesCollapsed(collapsed);
805
+ setToggledGroupIds(new Set());
806
+ }, []);
807
+ const collapsedKey = `${framesCollapsed ? 'closed' : 'open'}:${Array.from(toggledGroupIds).sort().join(',')}`;
808
+ const committedCollapsedKey = `${committedCollapsed.framesCollapsed ? 'closed' : 'open'}:${Array.from(committedCollapsed.toggled).sort().join(',')}`;
809
+
731
810
  const changeLayoutDirection = useCallback(
732
811
  (next: SubsystemLayoutDirection) => {
733
812
  if (next === requestedDirection) return;
@@ -745,8 +824,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
745
824
  }
746
825
  }, [trails, layoutTrailId]);
747
826
 
748
- const requestedLayoutKey = `${requestedDirection}|${layoutTrailId ?? ''}`;
749
- const committedLayoutKey = `${committedDirection}|${committedTrailId ?? ''}`;
827
+ const requestedLayoutKey = `${requestedDirection}|${layoutTrailId ?? ''}|${collapsedKey}`;
828
+ const committedLayoutKey = `${committedDirection}|${committedTrailId ?? ''}|${committedCollapsedKey}`;
750
829
 
751
830
  // Beat 1: request → fade the edges out, then commit the direction / focus
752
831
  // (which re-runs ELK). Reduced-motion users get the new layout immediately.
@@ -773,6 +852,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
773
852
  if (reduceMotion) {
774
853
  setCommittedDirection(requestedDirection);
775
854
  setCommittedTrailId(layoutTrailId);
855
+ setCommittedCollapsed({ framesCollapsed, toggled: toggledGroupIds });
776
856
  return;
777
857
  }
778
858
  flipSawPendingLayoutRef.current = false;
@@ -781,6 +861,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
781
861
  flipFadeTimerRef.current = null;
782
862
  setCommittedDirection(requestedDirection);
783
863
  setCommittedTrailId(layoutTrailId);
864
+ setCommittedCollapsed({ framesCollapsed, toggled: toggledGroupIds });
784
865
  }, LAYOUT_FLIP_EDGE_MS);
785
866
  return () => {
786
867
  if (flipFadeTimerRef.current != null) {
@@ -794,6 +875,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
794
875
  refocusOnLayoutFlip,
795
876
  requestedDirection,
796
877
  layoutTrailId,
878
+ framesCollapsed,
879
+ toggledGroupIds,
797
880
  ]);
798
881
 
799
882
  // Beat 3: the committed layout has settled → the node slide is over, fade
@@ -835,6 +918,10 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
835
918
  if (!persistKey) return;
836
919
  writeViewState(persistKey, { layoutDirection: requestedDirection });
837
920
  }, [persistKey, requestedDirection]);
921
+ useEffect(() => {
922
+ if (!persistKey) return;
923
+ writeViewState(persistKey, { framesCollapsed, toggledFrames: Array.from(toggledGroupIds) });
924
+ }, [persistKey, framesCollapsed, toggledGroupIds]);
838
925
 
839
926
  // Safety net: never leave the canvas edge-less if a layout pass stalls
840
927
  // (measurement never lands, ELK hangs). The edges come back; the layout
@@ -1111,13 +1198,15 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1111
1198
  components: layoutDoc.components,
1112
1199
  trails: layoutDoc.trails,
1113
1200
  graphifyRelations: layoutRelations,
1114
- }),
1115
- [layoutDoc, layoutRelations],
1201
+ }) + `|collapsed:${committedCollapsedKey}`,
1202
+ [layoutDoc, layoutRelations, committedCollapsedKey],
1116
1203
  );
1117
1204
  const layoutDocRef = useRef(layoutDoc);
1118
1205
  const layoutRelationsRef = useRef(layoutRelations);
1206
+ const committedCollapsedRef = useRef(committedCollapsed);
1119
1207
  layoutDocRef.current = layoutDoc;
1120
1208
  layoutRelationsRef.current = layoutRelations;
1209
+ committedCollapsedRef.current = committedCollapsed;
1121
1210
 
1122
1211
  // Track measured dimensions from React Flow's dimension changes.
1123
1212
  // These arrive as { type: 'dimensions', id, dimensions } in onNodesChange.
@@ -1144,6 +1233,9 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1144
1233
  orderByLine,
1145
1234
  layoutDirection: committedDirection,
1146
1235
  codeProcessKeys,
1236
+ regionDetails,
1237
+ collapsedGroupIds: committedCollapsedRef.current.toggled,
1238
+ cardFramesCollapsed: committedCollapsedRef.current.framesCollapsed,
1147
1239
  })
1148
1240
  .then(({ nodes, edges: e, absoluteRects }) => {
1149
1241
  if (!alive) return;
@@ -1193,7 +1285,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1193
1285
  const gen = ++pass2GenRef.current;
1194
1286
  void buildSubsystemGraph(
1195
1287
  layoutDoc,
1196
- { maxNodeWidth, showEdgeLabels, measuredWidths, measuredHeights, showSingletonFrames, moduleNesting, graphifyRelations: layoutRelations, orderByLine, layoutDirection: committedDirection, codeProcessKeys },
1288
+ { maxNodeWidth, showEdgeLabels, measuredWidths, measuredHeights, showSingletonFrames, moduleNesting, graphifyRelations: layoutRelations, orderByLine, layoutDirection: committedDirection, codeProcessKeys, regionDetails, collapsedGroupIds: committedCollapsed.toggled, cardFramesCollapsed: committedCollapsed.framesCollapsed },
1197
1289
  )
1198
1290
  .then(({ nodes, edges: e, absoluteRects }) => {
1199
1291
  if (gen !== pass2GenRef.current) return;
@@ -1206,7 +1298,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1206
1298
  // Reveal Pass 1 layout rather than leaving the cover up forever.
1207
1299
  setLayoutReady(true);
1208
1300
  });
1209
- }, [built.nodes, layoutDoc, layoutRelations, orderByLine, maxNodeWidth, showEdgeLabels, moduleNesting, committedDirection]);
1301
+ }, [built.nodes, layoutDoc, layoutRelations, orderByLine, maxNodeWidth, showEdgeLabels, moduleNesting, committedDirection, committedCollapsed]);
1210
1302
 
1211
1303
  // After Pass 1 commits, try Pass 2 immediately with retained measurements.
1212
1304
  // Same-id live updates often get no new React Flow `dimensions` events, so
@@ -1639,7 +1731,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1639
1731
  if (!edgeIds) return null;
1640
1732
  const ids = new Set<string>();
1641
1733
  for (const e of baseEdges) {
1642
- if (!edgeIds.has(e.id)) continue;
1734
+ if (!edgeMatches(edgeIds, e)) continue;
1643
1735
  ids.add(e.source);
1644
1736
  ids.add(e.target);
1645
1737
  }
@@ -1717,8 +1809,10 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1717
1809
  // Boundary frames follow their members: hidden when no member is
1718
1810
  // visible, dimmed when members are dimmed. Never selectable.
1719
1811
  if (n.type === 'subsystem-group') {
1720
- const region = (n.data as { region?: { key?: string; memberAliases?: string[] } } | undefined)?.region;
1721
- const memberAliases = region?.memberAliases ?? [];
1812
+ const region = (n.data as { region?: SubsystemProcessRegion } | undefined)?.region;
1813
+ // A collapsed card is an edge endpoint in its own right, so its own id
1814
+ // joins its members' when deciding whether the frame is on an open flow.
1815
+ const memberAliases = [n.id, ...(region?.memberAliases ?? [])];
1722
1816
  // `brightNodeIds` is the focused step's endpoints. It has to be a
1723
1817
  // spotlight member as well as a bright set: without an expanded flow
1724
1818
  // there is no opened set, so dimming has to be driven from the
@@ -1747,6 +1841,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1747
1841
  ...(color != null && { color }),
1748
1842
  ...(dimmed && { dimmed: true }),
1749
1843
  ...(regionIssue && { issue: regionIssue }),
1844
+ ...(region && isCardFrame(region) && { onToggleCollapse: () => toggleCollapsed(n.id) }),
1750
1845
  },
1751
1846
  };
1752
1847
  }
@@ -1787,7 +1882,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1787
1882
  },
1788
1883
  };
1789
1884
  });
1790
- }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, issueFocusNodeIds, issueBadgeByAlias, regionIssueByNodeId, boundaryColors]);
1885
+ }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, issueFocusNodeIds, issueBadgeByAlias, regionIssueByNodeId, boundaryColors, toggleCollapsed]);
1791
1886
 
1792
1887
  const baseNodesKey = useMemo(() => nodes.map((n) => n.id).sort().join(','), [nodes]);
1793
1888
  const baseEdgesKey = useMemo(
@@ -1821,16 +1916,18 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1821
1916
  }
1822
1917
  return isTrailMechanism(mechanism);
1823
1918
  };
1919
+ const inSet = (set: ReadonlySet<string> | null | undefined, e: Edge): boolean =>
1920
+ set != null && edgeMatches(set, e);
1824
1921
  if (openedEdgeIds || focusEdgeIds || previewEdgeIds || issueFocusEdgeIds) {
1825
1922
  return baseEdges.map((e) => {
1826
1923
  const vis = flowElementVisibility({
1827
- inOpened: openedEdgeIds?.has(e.id) === true,
1828
- inSelected: focusEdgeIds?.has(e.id) === true,
1924
+ inOpened: inSet(openedEdgeIds, e),
1925
+ inSelected: inSet(focusEdgeIds, e),
1829
1926
  anyOpened: openedEdgeIds != null,
1830
1927
  anySelected: focusEdgeIds != null,
1831
1928
  });
1832
1929
  const dimSource = previewEdgeIds ?? issueFocusEdgeIds;
1833
- const dimmed = dimSource ? vis.hidden || !dimSource.has(e.id) : vis.dimmed;
1930
+ const dimmed = dimSource ? vis.hidden || !inSet(dimSource, e) : vis.dimmed;
1834
1931
  const hidden = vis.hidden || !edgeInView(e);
1835
1932
  return { ...paint(e, dimmed), hidden };
1836
1933
  });
@@ -1980,8 +2077,14 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1980
2077
  // Boundary frame → frame its members on the canvas; double-click again to
1981
2078
  // zoom back out. User-initiated, so it ignores the trail zoom gate.
1982
2079
  if (node.type === 'subsystem-group') {
1983
- const key =
1984
- (node.data as { region?: { key?: string } } | undefined)?.region?.key;
2080
+ const region = (node.data as { region?: SubsystemProcessRegion } | undefined)?.region;
2081
+ // Card frames (process / package) grow and shrink on double-click, the
2082
+ // way a C4 container does; module frames keep the zoom-to-frame.
2083
+ if (region && isCardFrame(region)) {
2084
+ toggleCollapsed(node.id);
2085
+ return;
2086
+ }
2087
+ const key = region?.key;
1985
2088
  if (!key) return;
1986
2089
  if (focusedBoundaryKey === key) {
1987
2090
  setFocusedBoundaryKey(null);
@@ -2075,7 +2178,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2075
2178
  const nodeIds = new Set<string>();
2076
2179
  const points: { x: number; y: number }[] = [];
2077
2180
  for (const e of baseEdges) {
2078
- if (!ids.has(e.id)) continue;
2181
+ if (!edgeMatches(ids, e)) continue;
2079
2182
  nodeIds.add(e.source);
2080
2183
  nodeIds.add(e.target);
2081
2184
  const pts = (e.data as { elkPathPoints?: { x: number; y: number }[] } | undefined)
@@ -2188,6 +2291,67 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2188
2291
  [rectForNode, fitBounds, trailFocusDurationMs],
2189
2292
  );
2190
2293
 
2294
+ // The Containers list: every card frame in the laid-out graph, parents before
2295
+ // their children, with the colour the canvas draws it in. Rows keep the
2296
+ // grouping's declaration order — the layout moves closed cards after open
2297
+ // frames, and a row must not jump when its frame is toggled.
2298
+ const containerOrder = useMemo(() => {
2299
+ const ids = buildBoundaryLayoutGroups(
2300
+ { components },
2301
+ { showSingletonFrames, moduleNesting, codeProcessKeys },
2302
+ ).map((g) => g.id);
2303
+ return new Map(ids.map((id, i) => [id, i]));
2304
+ }, [components, showSingletonFrames, moduleNesting, codeProcessKeys]);
2305
+ const containerItems = useMemo((): ContainerListItem[] => {
2306
+ const frames = built.nodes
2307
+ .filter(
2308
+ (n): n is typeof n & { data: SubsystemGroupNodeData } =>
2309
+ n.type === 'subsystem-group' &&
2310
+ isCardFrame((n.data as SubsystemGroupNodeData).region),
2311
+ )
2312
+ .sort(
2313
+ (a, b) =>
2314
+ (containerOrder.get(a.id) ?? Number.MAX_SAFE_INTEGER) -
2315
+ (containerOrder.get(b.id) ?? Number.MAX_SAFE_INTEGER),
2316
+ );
2317
+ const byId = new Map(frames.map((n) => [n.id, n]));
2318
+ const children = new Map<string | undefined, typeof frames>();
2319
+ for (const n of frames) {
2320
+ const parent = n.parentId && byId.has(n.parentId) ? n.parentId : undefined;
2321
+ const list = children.get(parent) ?? [];
2322
+ list.push(n);
2323
+ children.set(parent, list);
2324
+ }
2325
+ const out: ContainerListItem[] = [];
2326
+ const walk = (parent: string | undefined, depth: number) => {
2327
+ for (const n of children.get(parent) ?? []) {
2328
+ const region = n.data.region;
2329
+ out.push({
2330
+ id: n.id,
2331
+ region,
2332
+ collapsed: n.data.collapsed === true,
2333
+ depth,
2334
+ color:
2335
+ boundaryColors?.[region.key] ??
2336
+ technologyBrand(region.technology)?.color ??
2337
+ packageColor(region.key),
2338
+ });
2339
+ walk(n.id, depth + 1);
2340
+ }
2341
+ };
2342
+ walk(undefined, 0);
2343
+ return out;
2344
+ }, [built.nodes, boundaryColors, containerOrder]);
2345
+ const focusContainer = useCallback(
2346
+ (id: string) => {
2347
+ const item = containerItems.find((c) => c.id === id);
2348
+ if (!item) return;
2349
+ setFocusedBoundaryKey(item.region.key);
2350
+ requestAnimationFrame(() => fitNodeRects(new Set([id]), 0.25));
2351
+ },
2352
+ [containerItems, fitNodeRects],
2353
+ );
2354
+
2191
2355
  // Zoom back out to the full diagram after the last expanded trail
2192
2356
  // closes (visibility restores non-flow nodes that were hidden).
2193
2357
  const fitOverview = useCallback(() => {
@@ -2448,6 +2612,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2448
2612
  setFocusedStepIndex(null);
2449
2613
  setHoveredTrailStep({ trailId: tl.id, stepIndex: stepIdx });
2450
2614
  }
2615
+ onAutoPlayStepRef.current?.({ trailId: tl.id, stepIndex: stepIdx });
2451
2616
  stepIdx += 1;
2452
2617
  if (stepIdx >= tl.steps.length) {
2453
2618
  stepIdx = 0;
@@ -2464,6 +2629,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2464
2629
  setFocusedTrailId(null);
2465
2630
  setFocusedStepIndex(null);
2466
2631
  setAutoPlayFocus(null);
2632
+ onAutoPlayStepRef.current?.(null);
2467
2633
  };
2468
2634
  return cleanup;
2469
2635
  }, [
@@ -2770,7 +2936,12 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2770
2936
  midX: d?.labelX ?? 0,
2771
2937
  midY: d?.labelY ?? 0,
2772
2938
  pathLength: d?.pathLength ?? 0,
2773
- stepNos: selectedFlowStepNos?.get(e.id),
2939
+ // A rolled-up line numbers every step it absorbed.
2940
+ stepNos: selectedFlowStepNos
2941
+ ? [e.id, ...((d as { rolledUpIds?: string[] } | undefined)?.rolledUpIds ?? [])]
2942
+ .flatMap((id) => selectedFlowStepNos.get(id) ?? [])
2943
+ .sort((a, b) => a - b)
2944
+ : undefined,
2774
2945
  stepIssue,
2775
2946
  };
2776
2947
  });
@@ -2804,9 +2975,9 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2804
2975
  // the same facts the sidebar renders.
2805
2976
  const sidebarVisible =
2806
2977
  !hideSidebar &&
2807
- (description || filesActive || issuesActive || sidebarExtra || sidebarAfterDescription ||
2978
+ (description || filesActive || containersActive || issuesActive || sidebarExtra || sidebarAfterDescription ||
2808
2979
  hasTrails);
2809
- const sidebarBodyVisible = hasTrails || filesActive || issuesActive;
2980
+ const sidebarBodyVisible = hasTrails || filesActive || containersActive || issuesActive;
2810
2981
  const sidebarTabs: GraphSidebarTab[] | undefined = issuesActive && !sidebarTrail
2811
2982
  ? agentsPanel
2812
2983
  ? [
@@ -2881,6 +3052,15 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2881
3052
  onExpandedCategoriesChange={handleExpandedCategoriesChange}
2882
3053
  />
2883
3054
  )
3055
+ ) : containersActive ? (
3056
+ <ContainersPanel
3057
+ containers={containerItems}
3058
+ activeId={containerItems.find((c) => c.region.key === focusedBoundaryKey)?.id ?? null}
3059
+ onFocus={focusContainer}
3060
+ onToggle={toggleCollapsed}
3061
+ onOpenAll={() => setAllFramesCollapsed(false)}
3062
+ onCloseAll={() => setAllFramesCollapsed(true)}
3063
+ />
2884
3064
  ) : filesActive ? treePaths.entries.length === 0 ? (
2885
3065
  <div style={{ padding: 16, color: theme.colors.textSecondary }}>No files for this trail.</div>
2886
3066
  ) : (
@@ -3543,6 +3723,17 @@ export function SubsystemComponentGraph(props: SubsystemComponentGraphProps) {
3543
3723
  [props.components, props.trails, props.issues, sidebarTrailId],
3544
3724
  );
3545
3725
  const fileCount = sidebarScope.treePaths.entries.length;
3726
+ // Card frames the layout will draw — the same grouping `buildSubsystemGraph`
3727
+ // runs, so the count matches the canvas.
3728
+ const containerCount = useMemo(
3729
+ () =>
3730
+ buildBoundaryLayoutGroups(
3731
+ { components: props.components },
3732
+ { showSingletonFrames: props.showSingletonFrames ?? true, moduleNesting: props.moduleNesting, codeProcessKeys: props.codeProcessKeys },
3733
+ ).filter((g) => isCardFrame(g.region)).length,
3734
+ [props.components, props.showSingletonFrames, props.moduleNesting, props.codeProcessKeys],
3735
+ );
3736
+ const [containersOpen, setContainersOpen] = useState(false);
3546
3737
  const trailViewLabel = sidebarScope.trail ? 'Trail' : 'Trails';
3547
3738
  const trailCount = props.trails?.length ?? 0;
3548
3739
  const hasFiles = fileCount > 0 || sidebarScope.trail != null;
@@ -3566,9 +3757,11 @@ export function SubsystemComponentGraph(props: SubsystemComponentGraphProps) {
3566
3757
  const issuesRequested = props.showIssues ?? diagnosticsOpen;
3567
3758
  const issuesActive = hasIssues && issuesRequested;
3568
3759
  const filesActive = filesOpen && hasFiles && !issuesActive;
3569
- const selectSidebarView = (view: 'trails' | 'files' | 'issues') => {
3760
+ const containersActive = containersOpen && containerCount > 0 && !issuesActive && !filesActive;
3761
+ const selectSidebarView = (view: 'trails' | 'files' | 'containers' | 'issues') => {
3570
3762
  const nextIssuesActive = view === 'issues';
3571
3763
  setFilesOpen(view === 'files');
3764
+ setContainersOpen(view === 'containers');
3572
3765
  if (nextIssuesActive !== issuesRequested) {
3573
3766
  if (props.showIssues === undefined) setDiagnosticsOpen(nextIssuesActive);
3574
3767
  props.diagnostic?.onToggle?.();
@@ -3669,12 +3862,26 @@ export function SubsystemComponentGraph(props: SubsystemComponentGraphProps) {
3669
3862
  borderRadius: 6,
3670
3863
  }}
3671
3864
  >
3865
+ {containerCount > 0 && (
3866
+ <button
3867
+ type="button"
3868
+ aria-label={`Containers (${containerCount} ${containerCount === 1 ? 'container' : 'containers'})`}
3869
+ title="Show containers"
3870
+ aria-pressed={containersActive}
3871
+ onClick={() => selectSidebarView('containers')}
3872
+ style={viewButtonStyle(containersActive)}
3873
+ >
3874
+ <Boxes size={14} aria-hidden />
3875
+ <span>Containers</span>
3876
+ <span style={{ fontWeight: 600, marginLeft: 4 }}>{containerCount}</span>
3877
+ </button>
3878
+ )}
3672
3879
  <button
3673
3880
  type="button"
3674
3881
  aria-label={sidebarScope.trail ? 'Trail' : `Trails (${trailCount} ${trailCount === 1 ? 'trail' : 'trails'})`}
3675
- aria-pressed={!filesActive && !issuesActive}
3882
+ aria-pressed={!filesActive && !containersActive && !issuesActive}
3676
3883
  onClick={() => selectSidebarView('trails')}
3677
- style={viewButtonStyle(!filesActive && !issuesActive)}
3884
+ style={viewButtonStyle(!filesActive && !containersActive && !issuesActive)}
3678
3885
  >
3679
3886
  <Route size={14} aria-hidden />
3680
3887
  <span>{trailViewLabel}</span>
@@ -3727,7 +3934,7 @@ export function SubsystemComponentGraph(props: SubsystemComponentGraphProps) {
3727
3934
  />
3728
3935
  ) : (
3729
3936
  <ReactFlowProvider>
3730
- <Inner {...props} showIssues={issuesActive} filesActive={filesActive} measured={size}
3937
+ <Inner {...props} showIssues={issuesActive} filesActive={filesActive} containersActive={containersActive} measured={size}
3731
3938
  sidebarScope={sidebarScope} onSidebarTrailChange={setSidebarTrailId} />
3732
3939
  </ReactFlowProvider>
3733
3940
  )}