@principal-ai/subsystems-react 0.56.34 → 0.56.36

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 (43) hide show
  1. package/dist/subsystem/SubsystemComponentGraph.d.ts +106 -2
  2. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  3. package/dist/subsystem/SubsystemComponentGraph.js +454 -70
  4. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  5. package/dist/subsystem/TrailStepsNav.d.ts +4 -2
  6. package/dist/subsystem/TrailStepsNav.d.ts.map +1 -1
  7. package/dist/subsystem/TrailStepsNav.js +14 -4
  8. package/dist/subsystem/TrailStepsNav.js.map +1 -1
  9. package/dist/subsystem/TrailsPanel.d.ts +18 -2
  10. package/dist/subsystem/TrailsPanel.d.ts.map +1 -1
  11. package/dist/subsystem/TrailsPanel.js +40 -18
  12. package/dist/subsystem/TrailsPanel.js.map +1 -1
  13. package/dist/subsystem/model.d.ts +27 -6
  14. package/dist/subsystem/model.d.ts.map +1 -1
  15. package/dist/subsystem/model.js +48 -45
  16. package/dist/subsystem/model.js.map +1 -1
  17. package/dist/subsystem/nodeIconography.d.ts +25 -0
  18. package/dist/subsystem/nodeIconography.d.ts.map +1 -0
  19. package/dist/subsystem/nodeIconography.js +55 -0
  20. package/dist/subsystem/nodeIconography.js.map +1 -0
  21. package/dist/subsystem/nodes.d.ts +4 -3
  22. package/dist/subsystem/nodes.d.ts.map +1 -1
  23. package/dist/subsystem/nodes.js +149 -153
  24. package/dist/subsystem/nodes.js.map +1 -1
  25. package/dist/subsystem/stepEmphasis.d.ts +5 -0
  26. package/dist/subsystem/stepEmphasis.d.ts.map +1 -1
  27. package/dist/subsystem/stepEmphasis.js +7 -0
  28. package/dist/subsystem/stepEmphasis.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/stories/Canvases/Subsystem/AgentDrivenWalkthrough.stories.tsx +2079 -0
  31. package/src/stories/Canvases/Subsystem/Deprecated.stories.tsx +1 -1
  32. package/src/stories/Canvases/Subsystem/NodeAnatomy.stories.tsx +17 -21
  33. package/src/stories/Canvases/Subsystem/NodeIconography.stories.tsx +960 -0
  34. package/src/stories/Canvases/Subsystem/Spotlights.stories.tsx +1 -1
  35. package/src/subsystem/SubsystemComponentGraph.tsx +609 -70
  36. package/src/subsystem/TrailStepsNav.tsx +16 -4
  37. package/src/subsystem/TrailsPanel.tsx +86 -12
  38. package/src/subsystem/model.test.ts +17 -13
  39. package/src/subsystem/model.ts +66 -48
  40. package/src/subsystem/nodeIconography.ts +88 -0
  41. package/src/subsystem/nodes.component.test.tsx +177 -0
  42. package/src/subsystem/nodes.tsx +256 -174
  43. package/src/subsystem/stepEmphasis.ts +8 -0
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useState } from 'react';
2
2
  import type { CSSProperties, ReactNode } from 'react';
3
3
  import { ChevronRight, Route, X } from 'lucide-react';
4
4
  import { useTheme } from '@principal-ade/industry-theme';
5
- import type { SubsystemTrail } from './model';
5
+ import { HOST_PROPOSAL_COLOR, type SubsystemTrail } from './model';
6
6
  import {
7
7
  trailStepDisplay,
8
8
  type TrailComponentLabels,
@@ -56,6 +56,8 @@ export interface TrailStepsNavProps {
56
56
  renderSteps?: (trail: SubsystemTrail) => ReactNode;
57
57
  /** Replace the step body without replacing the selected trail's header. */
58
58
  detailContent?: ReactNode;
59
+ /** Host-local trails awaiting confirmation; their header icon uses proposal color. */
60
+ proposedTrailIds?: Set<string>;
59
61
  }
60
62
 
61
63
  const PANE: CSSProperties = {
@@ -83,6 +85,7 @@ export function TrailStepsNav({
83
85
  listContent,
84
86
  renderSteps,
85
87
  detailContent,
88
+ proposedTrailIds,
86
89
  }: TrailStepsNavProps) {
87
90
  const { theme } = useTheme();
88
91
  const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
@@ -113,6 +116,9 @@ export function TrailStepsNav({
113
116
  const timer = setTimeout(() => setDisplayedTrail(null), transitionMs);
114
117
  return () => clearTimeout(timer);
115
118
  }, [focused, transitionMs]);
119
+ const proposed = displayedTrail
120
+ ? (proposedTrailIds?.has(displayedTrail.id) ?? false)
121
+ : false;
116
122
 
117
123
  // A focused trail (from the graph side) always lands on the step pane.
118
124
  const leaveList = useCallback(() => {
@@ -234,9 +240,15 @@ export function TrailStepsNav({
234
240
  size={14}
235
241
  strokeWidth={2}
236
242
  aria-hidden
237
- // The focused trail: the icon stays primary, matching the row's
238
- // hover colour in the list it came from.
239
- style={{ flexShrink: 0, marginTop: 3, color: theme.colors.primary }}
243
+ // A proposed trail keeps the proposal colour here too, matching
244
+ // its row icon in the list it came from.
245
+ style={{
246
+ flexShrink: 0,
247
+ marginTop: 3,
248
+ color: proposed
249
+ ? HOST_PROPOSAL_COLOR
250
+ : theme.colors.primary,
251
+ }}
240
252
  />
241
253
  {/* The title is the back affordance too: clicking it goes back to
242
254
  the list, like the trailing close. */}
@@ -19,7 +19,9 @@ import {
19
19
  reorderTargetIndex,
20
20
  reorderTrails,
21
21
  trailStepGraphEdgeId,
22
+ HOST_PROPOSAL_COLOR,
22
23
  type SubsystemTrail,
24
+ type SubsystemTrailStep,
23
25
  } from './model';
24
26
  import { buildStepBrief } from './trailBrief';
25
27
  import { emphasisKey, type StepEmphasisMap } from './stepEmphasis';
@@ -45,6 +47,13 @@ const EMPHASIS_COLOR = '#f5a524';
45
47
  */
46
48
  export const TRAIL_HOVER_PREVIEW_MS = 150;
47
49
 
50
+ /** Host-local before/after view retained when a step replacement is accepted. */
51
+ export interface TrailsStepChange {
52
+ trailId: string;
53
+ stepIndex: number;
54
+ previous: SubsystemTrailStep;
55
+ }
56
+
48
57
  /** How long a step's number shows its "copied" checkmark (ms). */
49
58
  export const STEP_COPY_FEEDBACK_MS = 2000;
50
59
 
@@ -85,6 +94,11 @@ function TrailFlow({
85
94
  onRemoveStepEmphasis,
86
95
  componentByAlias,
87
96
  hideHeader = false,
97
+ proposed = false,
98
+ proposedStepKeys,
99
+ focusedVariationStepIndexes,
100
+ stepNumberLabels,
101
+ stepChange,
88
102
  }: {
89
103
  trail: SubsystemTrail;
90
104
  collapsed: boolean;
@@ -125,8 +139,19 @@ function TrailFlow({
125
139
  componentByAlias?: TrailComponentLabels;
126
140
  /** The shared drill-down navigation supplies the trail header. */
127
141
  hideHeader?: boolean;
142
+ /** Host-local proposal: colour the flow icon without changing the title. */
143
+ proposed?: boolean;
144
+ /** Host-local proposed steps, keyed by `emphasisKey(trailId, step)`. */
145
+ proposedStepKeys?: Set<string>;
146
+ /** Step indexes that belong to one focused variation group in this flow. */
147
+ focusedVariationStepIndexes?: ReadonlySet<number>;
148
+ /** Display labels overriding the default `i + 1`, keyed by `emphasisKey`. */
149
+ stepNumberLabels?: ReadonlyMap<string, string>;
150
+ /** Host-local before/after view for an accepted step replacement. */
151
+ stepChange?: TrailsStepChange | null;
128
152
  }) {
129
153
  const { theme } = useTheme();
154
+ const proposalColor = HOST_PROPOSAL_COLOR;
130
155
  const muted = theme.colors.textMuted ?? theme.colors.textSecondary;
131
156
  const hoverBg = theme.colors.background;
132
157
  const wholeFlowActive = active !== null && active.stepIndex === null;
@@ -329,7 +354,11 @@ function TrailFlow({
329
354
  style={{
330
355
  flexShrink: 0,
331
356
  marginTop: 3,
332
- color: headerHover || (!collapsed && wholeFlowActive) ? theme.colors.primary : muted,
357
+ color: proposed
358
+ ? proposalColor
359
+ : headerHover || (!collapsed && wholeFlowActive)
360
+ ? theme.colors.primary
361
+ : muted,
333
362
  }}
334
363
  />
335
364
  <span
@@ -508,10 +537,23 @@ function TrailFlow({
508
537
  }}
509
538
  >
510
539
  {trail.steps.map((step, i) => {
511
- const stepActive = active !== null && active.stepIndex === i;
540
+ // A staged variation and the step it would replace are focused as
541
+ // one group, even though the host only names one active step.
542
+ const stepActive =
543
+ (active !== null && active.stepIndex === i) ||
544
+ (focusedVariationStepIndexes?.has(i) ?? false);
512
545
  const copied = copiedStep === i;
513
- const record = stepEmphasis?.get(emphasisKey(trail.id, step));
546
+ const stepKey = emphasisKey(trail.id, step);
547
+ const record = stepEmphasis?.get(stepKey);
548
+ const stepProposed = proposed || (proposedStepKeys?.has(stepKey) ?? false);
549
+ const stepNumber = stepNumberLabels?.get(stepKey) ?? String(i + 1);
514
550
  const display = trailStepDisplay(step, componentByAlias);
551
+ // The original step keeps its row after acceptance; only its
552
+ // annotation is greyed. Its `2a` variation stays beside it.
553
+ const previousStep =
554
+ stepChange?.trailId === trail.id && stepChange.stepIndex === i
555
+ ? stepChange.previous
556
+ : null;
515
557
  // Calls nest; uses/data steps sit at their anchor frame's depth.
516
558
  const stackDepth = buildTrailStack(
517
559
  trail,
@@ -579,16 +621,18 @@ function TrailFlow({
579
621
  fontSize: theme.fontSizes[0],
580
622
  fontFamily: theme.fonts.monospace,
581
623
  fontWeight: record ? 700 : undefined,
582
- color: copied
583
- ? theme.colors.primary
584
- : record
585
- ? EMPHASIS_COLOR
586
- : stepActive
587
- ? theme.colors.text
588
- : muted,
624
+ color: stepProposed
625
+ ? proposalColor
626
+ : copied
627
+ ? theme.colors.primary
628
+ : record
629
+ ? EMPHASIS_COLOR
630
+ : stepActive
631
+ ? theme.colors.text
632
+ : muted,
589
633
  }}
590
634
  >
591
- {copied ? <Check size={12} strokeWidth={2} aria-hidden /> : i + 1}
635
+ {copied ? <Check size={12} strokeWidth={2} aria-hidden /> : stepNumber}
592
636
  </span>
593
637
  <span
594
638
  style={{
@@ -608,7 +652,11 @@ function TrailFlow({
608
652
  overflowWrap: 'anywhere',
609
653
  fontSize: theme.fontSizes[1],
610
654
  fontFamily: theme.fonts.monospace,
611
- color: theme.colors.primary,
655
+ color: previousStep
656
+ ? muted
657
+ : stepProposed
658
+ ? proposalColor
659
+ : theme.colors.primary,
612
660
  lineHeight: 1.35,
613
661
  }}
614
662
  >
@@ -741,6 +789,16 @@ export interface TrailsPanelProps {
741
789
  drilldown?: boolean;
742
790
  /** Files or issues for the selected trail, beneath its shared header. */
743
791
  detailContent?: ReactNode;
792
+ /** Host-local trails awaiting confirmation; their icons use proposal color. */
793
+ proposedTrailIds?: Set<string>;
794
+ /** Host-local steps awaiting confirmation, keyed by `emphasisKey`. */
795
+ proposedStepKeys?: Set<string>;
796
+ /** Step indexes that belong to one focused variation group, by trail id. */
797
+ focusedVariationStepIndexes?: ReadonlyMap<string, ReadonlySet<number>>;
798
+ /** Display labels overriding the default `i + 1`, keyed by `emphasisKey`. */
799
+ stepNumberLabels?: ReadonlyMap<string, string>;
800
+ /** Host-local before/after view for an accepted step replacement. */
801
+ stepChange?: TrailsStepChange | null;
744
802
  }
745
803
 
746
804
  /**
@@ -769,6 +827,11 @@ export function TrailsPanel({
769
827
  componentByAlias,
770
828
  drilldown = false,
771
829
  detailContent,
830
+ proposedTrailIds,
831
+ proposedStepKeys,
832
+ focusedVariationStepIndexes,
833
+ stepNumberLabels,
834
+ stepChange,
772
835
  }: TrailsPanelProps) {
773
836
  const { theme } = useTheme();
774
837
  // Reordering is offered only while every row is collapsed: the compact list
@@ -956,6 +1019,11 @@ export function TrailsPanel({
956
1019
  }
957
1020
  stepEmphasis={stepEmphasis}
958
1021
  onRemoveStepEmphasis={onRemoveStepEmphasis}
1022
+ proposed={proposedTrailIds?.has(tl.id) ?? false}
1023
+ proposedStepKeys={proposedStepKeys}
1024
+ focusedVariationStepIndexes={focusedVariationStepIndexes?.get(tl.id)}
1025
+ stepNumberLabels={stepNumberLabels}
1026
+ stepChange={stepChange}
959
1027
  />
960
1028
  </div>
961
1029
  );
@@ -980,6 +1048,7 @@ export function TrailsPanel({
980
1048
  componentByAlias={componentByAlias}
981
1049
  listContent={list}
982
1050
  detailContent={detailContent}
1051
+ proposedTrailIds={proposedTrailIds}
983
1052
  renderSteps={(trail) => (
984
1053
  <TrailFlow
985
1054
  key={trail.id}
@@ -1004,6 +1073,11 @@ export function TrailsPanel({
1004
1073
  componentByAlias={componentByAlias}
1005
1074
  stepEmphasis={stepEmphasis}
1006
1075
  onRemoveStepEmphasis={onRemoveStepEmphasis}
1076
+ proposed={proposedTrailIds?.has(trail.id) ?? false}
1077
+ proposedStepKeys={proposedStepKeys}
1078
+ focusedVariationStepIndexes={focusedVariationStepIndexes?.get(trail.id)}
1079
+ stepNumberLabels={stepNumberLabels}
1080
+ stepChange={stepChange}
1007
1081
  />
1008
1082
  )}
1009
1083
  />
@@ -36,7 +36,7 @@ import {
36
36
  rightBadgeLabel,
37
37
  nodeMinWidthForBadges,
38
38
  estimateBadgeLabelWidth,
39
- BADGE_EDGE_INSET,
39
+ COMPONENT_NODE_HEIGHT,
40
40
  formatPurl,
41
41
  packageColor,
42
42
  subsystemGraphLayoutKey,
@@ -86,6 +86,7 @@ describe('subsystem graph model', () => {
86
86
  const components = nodes.filter((n) => n.type === 'subsystem-component');
87
87
  expect(components).toHaveLength(comps.length);
88
88
  expect(components.every((n) => n.type === 'subsystem-component')).toBe(true);
89
+ expect(components.every((n) => n.height === COMPONENT_NODE_HEIGHT)).toBe(true);
89
90
  });
90
91
 
91
92
  test('converts edges with directed markers', () => {
@@ -193,7 +194,7 @@ describe('subsystem graph model', () => {
193
194
  ).toBe('Person');
194
195
  expect(
195
196
  constructBadgeLabel({ construct: 'custom_entity' }),
196
- ).toBe('custom_entity');
197
+ ).toBe('custom entity');
197
198
  });
198
199
 
199
200
  test('constructBadgeColor uses React brand only for framework stereotype badges', () => {
@@ -205,16 +206,16 @@ describe('subsystem graph model', () => {
205
206
  expect(constructBadgeColor({ framework: 'vue', stereotype: 'component' })).toBeNull();
206
207
  });
207
208
 
208
- test('nodeMinWidthForBadges widens for long construct badges and role pairs', () => {
209
+ test('nodeMinWidthForBadges sizes primary and secondary rows independently', () => {
209
210
  const plain = nodeMinWidthForBadges({ construct: 'function' });
210
- expect(plain).toBe(150);
211
+ expect(plain).toBe(200);
211
212
 
212
213
  const stereotype = nodeMinWidthForBadges({
213
214
  construct: 'function',
214
215
  framework: 'react',
215
216
  stereotype: 'component',
216
217
  });
217
- expect(stereotype).toBeGreaterThan(150);
218
+ expect(stereotype).toBeGreaterThan(plain);
218
219
 
219
220
  const withRole = nodeMinWidthForBadges({
220
221
  construct: 'function',
@@ -222,14 +223,17 @@ describe('subsystem graph model', () => {
222
223
  stereotype: 'component',
223
224
  role: 'entry',
224
225
  });
225
- expect(withRole).toBeGreaterThan(stereotype);
226
-
227
- // The pair floor must leave a real gap between the left and right badge,
228
- // over and above both insets — regression: the node border was omitted from
229
- // the floor, and the char width was underestimated, so the two badges met.
230
- const left = estimateBadgeLabelWidth(constructBadgeLabel({ construct: 'function' }));
231
- const right = estimateBadgeLabelWidth(rightBadgeLabel({ role: 'entry' })!);
232
- expect(withRole).toBeGreaterThan(left + right + 2 * BADGE_EDGE_INSET);
226
+ // The secondary role chip is narrower than the React primary row, so it
227
+ // must not widen the node merely by being present.
228
+ expect(withRole).toBe(stereotype);
229
+
230
+ const withSecondaryCluster = nodeMinWidthForBadges({
231
+ construct: 'store',
232
+ role: 'service',
233
+ declaration: { kind: 'store', storage: 'memory', properties: [] },
234
+ });
235
+ expect(withSecondaryCluster).toBeGreaterThan(plain);
236
+ expect(estimateBadgeLabelWidth('MEMORY')).toBeGreaterThan(estimateBadgeLabelWidth('DB'));
233
237
  });
234
238
 
235
239
  test('rightBadgeLabel reports the role', () => {
@@ -1241,6 +1241,12 @@ export interface SubsystemGraphNodeData extends Record<string, unknown> {
1241
1241
  fileMatch?: boolean;
1242
1242
  /** True while this node is on an opened-but-unselected flow. */
1243
1243
  dimmed?: boolean;
1244
+ /** Host-local proposal: the component box is awaiting confirmation. */
1245
+ proposed?: boolean;
1246
+ /** Host-local working indicator: the agent is working on this component. */
1247
+ working?: boolean;
1248
+ /** Host-local removal ghost: the component was removed but stays dimmed in place. */
1249
+ removed?: boolean;
1244
1250
  /** Diagnostics badge — see `SubsystemNodeIssue`. Absent when no findings. */
1245
1251
  issue?: SubsystemNodeIssue;
1246
1252
  /**
@@ -1340,6 +1346,12 @@ export interface SubsystemGraphEdgeData extends Record<string, unknown> {
1340
1346
  /** True while another edge is selected — render this edge (and its label)
1341
1347
  * dimmed to focus the selected relationship. */
1342
1348
  dimmed?: boolean;
1349
+ /** Host-local previous state of a changed/removed step. Still laid out and
1350
+ * focused with its replacement, but rendered as a dim dashed ghost. */
1351
+ ghost?: boolean;
1352
+ /** Host-local step change awaiting confirmation. Laid out and focused with
1353
+ * the existing step, but rendered as a proposal-colored dashed edge. */
1354
+ proposed?: boolean;
1343
1355
  /**
1344
1356
  * How many edges this line stands for, when a collapsed frame rolled them up
1345
1357
  * (one line per source/target/mechanism). Absent on an ordinary edge.
@@ -1400,6 +1412,14 @@ export const MECHANISM_COLOR: Record<SubsystemEdgeMechanism, string> = {
1400
1412
  'registers-into': '#ff6b35', // orange
1401
1413
  };
1402
1414
 
1415
+ /**
1416
+ * Host-local proposal chrome. A proposal is agent/UI state, not a mechanism,
1417
+ * so it must not borrow a mechanism or warning hue. This is a deeper standard
1418
+ * purple: clear of `writes` orange (the old collision), and darker than the
1419
+ * light `produces` violet so the two still separate at a glance.
1420
+ */
1421
+ export const HOST_PROPOSAL_COLOR = '#9333ea';
1422
+
1403
1423
  export const MECHANISM_STYLE: Record<SubsystemEdgeMechanism, 'solid' | 'dashed' | 'dotted'> = {
1404
1424
  calls: 'solid',
1405
1425
  uses: 'solid',
@@ -1736,7 +1756,11 @@ export function constructBadgeLabel(component: {
1736
1756
  return component.entityKind;
1737
1757
  }
1738
1758
  const constructLabel =
1739
- component.construct === 'type_alias' ? 'type alias' : component.construct;
1759
+ component.construct === 'type_alias'
1760
+ ? 'type alias'
1761
+ : component.construct === 'custom_entity'
1762
+ ? 'custom entity'
1763
+ : component.construct;
1740
1764
  if (component.stereotype && component.framework) {
1741
1765
  return `${component.framework} · ${component.stereotype}`;
1742
1766
  }
@@ -1758,37 +1782,33 @@ export function constructBadgeColor(component: {
1758
1782
  }
1759
1783
 
1760
1784
  /** Default CSS floor for component nodes (padding aside). */
1761
- export const NODE_CSS_MIN_WIDTH = 150;
1762
- /** Inset of each top badge from the node edge (`left` / `right` style). */
1785
+ export const NODE_CSS_MIN_WIDTH = 200;
1786
+ /** @deprecated Retained for deep-import compatibility; the new layout uses inline rows. */
1763
1787
  export const BADGE_EDGE_INSET = 5;
1764
- /** Minimum gap between left construct badge and right role badge. */
1765
- const BADGE_PAIR_GAP = 8;
1766
- /**
1767
- * Node border thickness reserved on each side of the badge span. Top badges are
1768
- * positioned from the padding edge (inside the border), so a `left: 5px` badge
1769
- * starts `border + inset` from the border-box edge. Reserve the widest border
1770
- * (4px when selected / file-matched) so the pair gap survives selection.
1771
- */
1772
- const BADGE_NODE_BORDER = 4;
1773
- /** Badge box chrome: padding 8+8 + border 2+2. */
1774
- const BADGE_BOX_CHROME = 20;
1775
- /**
1776
- * Approx monospace uppercase advance incl. letter-spacing. Badge font is
1777
- * 13.2px; Fira Code / SF Mono / Courier all sit at ~0.6em (7.9px) plus 0.5px
1778
- * tracking ≈ 8.4px. Rounded up so estimates never undershoot — an undershoot
1779
- * eats into BADGE_PAIR_GAP and lets the left/right badges touch.
1780
- */
1788
+ /** Measured component-node height: primary icon row, name, and optional identity. */
1789
+ export const COMPONENT_NODE_HEIGHT = 96;
1790
+ /** Horizontal padding (16px per side) plus the widest border (4px). */
1791
+ const NODE_HORIZONTAL_CHROME = 36;
1792
+ /** Primary icon slot and the gap before its inline label. */
1793
+ const PRIMARY_ICON_SLOT = 24;
1794
+ const PRIMARY_LABEL_GAP = 6;
1795
+ /** Secondary icon, label gap, and box chrome (padding + border). */
1796
+ const SECONDARY_ICON_SIZE = 14;
1797
+ const SECONDARY_LABEL_GAP = 5;
1798
+ const SECONDARY_BOX_CHROME = 20;
1799
+ const SECONDARY_BADGE_GAP = 6;
1800
+ /** Approx monospace uppercase advance incl. letter-spacing. */
1781
1801
  const BADGE_CHAR_WIDTH = 8.5;
1782
1802
 
1783
- /** Estimated rendered width of a top tab badge label. */
1803
+ /** Estimated rendered width of a secondary text badge, including its box. */
1784
1804
  export function estimateBadgeLabelWidth(label: string): number {
1785
- return (label?.length ?? 0) * BADGE_CHAR_WIDTH + BADGE_BOX_CHROME;
1805
+ return (label?.length ?? 0) * BADGE_CHAR_WIDTH + SECONDARY_BOX_CHROME;
1786
1806
  }
1787
1807
 
1788
1808
  /**
1789
- * Minimum node width so top badges stay on one line and (when both are
1790
- * present) don't overlap — badges are absolutely positioned, so they don't
1791
- * contribute to layout unless we widen the node explicitly.
1809
+ * Minimum node width for the new icon-plus-label layout. The primary row and
1810
+ * secondary cluster are on different edges, so their widths are independent
1811
+ * constraints rather than one combined left/right pair.
1792
1812
  */
1793
1813
  export function nodeMinWidthForBadges(component: {
1794
1814
  construct: SubsystemComponentConstruct;
@@ -1799,30 +1819,28 @@ export function nodeMinWidthForBadges(component: {
1799
1819
  entityKind?: string;
1800
1820
  declaration?: AnyComponentDetail;
1801
1821
  }): number {
1802
- const left = estimateBadgeLabelWidth(constructBadgeLabel(component));
1803
- const rightBadges = [
1822
+ const primaryLabel = constructBadgeLabel(component);
1823
+ const primaryTextWidth = Math.max(0, estimateBadgeLabelWidth(primaryLabel) - SECONDARY_BOX_CHROME);
1824
+ const primaryWidth = PRIMARY_ICON_SLOT + PRIMARY_LABEL_GAP + primaryTextWidth;
1825
+ const secondaryLabels = [
1804
1826
  storageBadgeLabel(component),
1805
1827
  rightBadgeLabel(component),
1806
1828
  deprecatedBadgeLabel(component),
1807
- ].filter((l): l is string => l != null);
1808
- if (rightBadges.length === 0) {
1809
- return Math.max(
1810
- NODE_CSS_MIN_WIDTH,
1811
- BADGE_NODE_BORDER + BADGE_EDGE_INSET + left + BADGE_EDGE_INSET + BADGE_NODE_BORDER,
1812
- );
1813
- }
1814
- const right = rightBadges
1815
- .map(estimateBadgeLabelWidth)
1816
- .reduce((acc, w) => acc + BADGE_PAIR_GAP + w);
1829
+ ].filter((label): label is string => label != null);
1830
+ const secondaryWidth = secondaryLabels.reduce(
1831
+ (width, label) =>
1832
+ width +
1833
+ SECONDARY_BADGE_GAP +
1834
+ SECONDARY_ICON_SIZE +
1835
+ SECONDARY_LABEL_GAP +
1836
+ Math.max(0, estimateBadgeLabelWidth(label) - SECONDARY_BOX_CHROME) +
1837
+ SECONDARY_BOX_CHROME,
1838
+ 0,
1839
+ );
1817
1840
  return Math.max(
1818
1841
  NODE_CSS_MIN_WIDTH,
1819
- BADGE_NODE_BORDER +
1820
- BADGE_EDGE_INSET +
1821
- left +
1822
- BADGE_PAIR_GAP +
1823
- right +
1824
- BADGE_EDGE_INSET +
1825
- BADGE_NODE_BORDER,
1842
+ primaryWidth + NODE_HORIZONTAL_CHROME,
1843
+ secondaryWidth + NODE_HORIZONTAL_CHROME,
1826
1844
  );
1827
1845
  }
1828
1846
 
@@ -1872,10 +1890,10 @@ export function convertSubsystemToNodes(
1872
1890
  .sort((a, b) => b.length - a.length)[0];
1873
1891
  const cap = maxNodeWidth ?? 300;
1874
1892
  const textWidth = Math.min(cap, Math.max(60, (text?.length ?? 10) * 8));
1875
- // Account for CSS minWidth (incl. top badges) and padding/border so ELK's
1876
- // port positions match the actual rendered node boundaries.
1893
+ // Account for the primary icon row, secondary badge cluster, and the
1894
+ // node's horizontal padding/border so ELK ports match rendered bounds.
1877
1895
  const cssMinWidth = nodeMinWidthForBadges(c);
1878
- const cssPadding = 20; // horizontal padding (left + right)
1896
+ const cssPadding = 32; // 16px horizontal padding per side
1879
1897
  const cssBorder = 4; // 2px border each side
1880
1898
  const rawWidth = Math.max(cssMinWidth, textWidth + cssPadding + cssBorder);
1881
1899
  const nodeWidth = Math.max(cssMinWidth, Math.min(cap, rawWidth));
@@ -1892,7 +1910,7 @@ export function convertSubsystemToNodes(
1892
1910
  ...(parentId ? { parentId } : {}),
1893
1911
  position: { x: PAD + col * COL_W, y: cursorY + row * ROW_H },
1894
1912
  width: nodeWidth,
1895
- height: 84,
1913
+ height: COMPONENT_NODE_HEIGHT,
1896
1914
  data: { component: c },
1897
1915
  });
1898
1916
  });
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Shared icon vocabulary for subsystem component nodes.
3
+ *
4
+ * Primary icons identify what a node is. Secondary icons identify orthogonal
5
+ * facts (role, storage backing, deprecation), and state icons identify
6
+ * host-local lifecycle markers. Keeping the mappings here prevents the canvas,
7
+ * stories, and tests from drifting apart.
8
+ */
9
+
10
+ import {
11
+ Archive,
12
+ Bot,
13
+ Database,
14
+ HardDrive,
15
+ Layers3,
16
+ List,
17
+ LogIn,
18
+ MemoryStick,
19
+ Network,
20
+ Server,
21
+ SquareFunction,
22
+ Type,
23
+ Unplug,
24
+ UserRound,
25
+ Workflow,
26
+ createLucideIcon,
27
+ type LucideIcon,
28
+ } from 'lucide-react';
29
+ import type {
30
+ SubsystemComponentConstruct,
31
+ SubsystemComponentRole,
32
+ } from './model';
33
+
34
+ /** The curled standalone `f` from Lucide's SquareFunction, without its box. */
35
+ export const FunctionLetter = createLucideIcon('FunctionLetter', [
36
+ ['path', { d: 'M9 17c2 0 2.8-1 2.8-2.8V10c0-2 1-3.3 3.2-3', key: 'f-stem' }],
37
+ ['path', { d: 'M9 11.2h5.7', key: 'f-crossbar' }],
38
+ ]);
39
+
40
+ /** A class declaration: an outlined box with a `C`. */
41
+ export const ClassGlyph = createLucideIcon('ClassGlyph', [
42
+ ['rect', { x: '3', y: '3', width: '18', height: '18', rx: '2', key: 'class-box' }],
43
+ ['path', { d: 'M16 7.5a5.5 5.5 0 1 0 0 9', key: 'class-c' }],
44
+ ]);
45
+
46
+ export const CONSTRUCT_ICON: Record<SubsystemComponentConstruct, LucideIcon> = {
47
+ function: FunctionLetter,
48
+ class: ClassGlyph,
49
+ method: SquareFunction,
50
+ interface: Unplug,
51
+ type_alias: Type,
52
+ enum: List,
53
+ store: Layers3,
54
+ external: Network,
55
+ custom_entity: UserRound,
56
+ };
57
+
58
+ const ENTITY_ICON: Record<string, LucideIcon> = {
59
+ person: UserRound,
60
+ agent: Bot,
61
+ service: Server,
62
+ queue: List,
63
+ };
64
+
65
+ /** Custom entities use their authored kind when it has a known glyph. */
66
+ export function iconForComponent(component: {
67
+ construct: SubsystemComponentConstruct;
68
+ entityKind?: string;
69
+ }): LucideIcon {
70
+ if (component.construct !== 'custom_entity') {
71
+ return CONSTRUCT_ICON[component.construct];
72
+ }
73
+ const kind = component.entityKind?.trim().toLowerCase() ?? '';
74
+ return ENTITY_ICON[kind] ?? CONSTRUCT_ICON.custom_entity;
75
+ }
76
+
77
+ export const ROLE_ICON: Record<SubsystemComponentRole, LucideIcon> = {
78
+ entry: LogIn,
79
+ service: Workflow,
80
+ };
81
+
82
+ export const STORAGE_ICON: Record<string, LucideIcon> = {
83
+ memory: MemoryStick,
84
+ disk: HardDrive,
85
+ external: Database,
86
+ };
87
+
88
+ export const DEPRECATED_ICON = Archive;