@principal-ai/subsystems-react 0.38.0 → 0.39.0

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/graphify/consolidated.d.ts +8 -0
  2. package/dist/graphify/consolidated.d.ts.map +1 -1
  3. package/dist/graphify/construct.d.ts +18 -0
  4. package/dist/graphify/construct.d.ts.map +1 -1
  5. package/dist/graphify/construct.js +23 -0
  6. package/dist/graphify/construct.js.map +1 -1
  7. package/dist/graphify/index.d.ts +2 -2
  8. package/dist/graphify/index.d.ts.map +1 -1
  9. package/dist/graphify/index.js +1 -1
  10. package/dist/graphify/index.js.map +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -1
  14. package/dist/index.js.map +1 -1
  15. package/dist/subsystem/IssueList.d.ts +49 -3
  16. package/dist/subsystem/IssueList.d.ts.map +1 -1
  17. package/dist/subsystem/IssueList.js +180 -79
  18. package/dist/subsystem/IssueList.js.map +1 -1
  19. package/dist/subsystem/SubsystemComponentGraph.d.ts +9 -1
  20. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  21. package/dist/subsystem/SubsystemComponentGraph.js +461 -12
  22. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  23. package/dist/subsystem/formatDeclaration.js +19 -5
  24. package/dist/subsystem/formatDeclaration.js.map +1 -1
  25. package/dist/subsystem/model.d.ts +38 -0
  26. package/dist/subsystem/model.d.ts.map +1 -1
  27. package/dist/subsystem/model.js.map +1 -1
  28. package/dist/subsystem/nodes.d.ts.map +1 -1
  29. package/dist/subsystem/nodes.js +124 -67
  30. package/dist/subsystem/nodes.js.map +1 -1
  31. package/dist/subsystem/symbolRefs.d.ts.map +1 -1
  32. package/dist/subsystem/symbolRefs.js +2 -0
  33. package/dist/subsystem/symbolRefs.js.map +1 -1
  34. package/package.json +3 -3
  35. package/src/graphify/consolidated.ts +8 -0
  36. package/src/graphify/construct.test.ts +61 -1
  37. package/src/graphify/construct.ts +33 -0
  38. package/src/graphify/index.ts +6 -1
  39. package/src/index.ts +1 -0
  40. package/src/stories/Subsystem/ComponentGraph/IssueOverlay.stories.tsx +625 -0
  41. package/src/stories/Subsystem/ComponentGraph/Issues.stories.tsx +7 -1
  42. package/src/stories/Subsystem/ComponentGraph/NodeAnatomy.stories.tsx +40 -73
  43. package/src/stories/Subsystem/ComponentGraph/StoreValueType.stories.tsx +261 -0
  44. package/src/stories/Subsystem/StoreValueTypeDeclaration.stories.tsx +182 -0
  45. package/src/subsystem/IssueList.focus.test.tsx +113 -0
  46. package/src/subsystem/IssueList.icon.test.tsx +95 -0
  47. package/src/subsystem/IssueList.tsx +267 -111
  48. package/src/subsystem/SubsystemComponentGraph.tsx +530 -12
  49. package/src/subsystem/formatDeclaration.test.ts +64 -0
  50. package/src/subsystem/formatDeclaration.ts +20 -5
  51. package/src/subsystem/model.ts +46 -0
  52. package/src/subsystem/nodes.group.test.tsx +52 -0
  53. package/src/subsystem/nodes.tsx +102 -2
  54. package/src/subsystem/symbolRefs.ts +2 -0
@@ -38,6 +38,7 @@ import {
38
38
  buildSubsystemGraph,
39
39
  deriveGraphEdges,
40
40
  isConstructsOnlyModel,
41
+ moduleGroupNodeId,
41
42
  isRelationMechanism,
42
43
  isWalkthroughMechanism,
43
44
  edgeColor,
@@ -49,6 +50,8 @@ import {
49
50
  type SubsystemEdgeProvenance,
50
51
  type SubsystemEdgeView,
51
52
  type SubsystemGraphifyRelation,
53
+ type SubsystemNodeIssue,
54
+ type SubsystemRegionIssue,
52
55
  type SubsystemRelation,
53
56
  type SubsystemWalkthrough,
54
57
  } from './model';
@@ -59,6 +62,11 @@ import { SubsystemComponentNode, SubsystemGroupNode, SubsystemEdge, SUBSYSTEM_CA
59
62
  import { SubsystemDiagnosticToggle, type SubsystemDiagnostic } from './DiagnosticToggle';
60
63
  import {
61
64
  SubsystemIssueList,
65
+ issueCategory,
66
+ issueKindOrder,
67
+ issueRung,
68
+ ISSUE_KIND_ICON,
69
+ ISSUE_RUNG_ORDER,
62
70
  type SubsystemIssue,
63
71
  type SubsystemIssueCategory,
64
72
  } from './IssueList';
@@ -315,7 +323,15 @@ export interface SubsystemComponentGraphProps {
315
323
  * plain issues view expands everything.
316
324
  */
317
325
  focusIssueCategory?: SubsystemIssueCategory;
318
- /** Click an issue — focus its target on the graph / open detail. */
326
+ /**
327
+ * Click an issue. The graph first focuses the target on the canvas itself —
328
+ * a component target is selected and framed (any edge / walkthrough focus
329
+ * that would hide it is cleared), a relation target frames its edge, and a
330
+ * module target frames that boundary frame — then this fires so the host can
331
+ * open its own detail. Collapsing the card again reverses that (deselect +
332
+ * zoom out). Other target kinds (flow / repo) have no node to frame and just
333
+ * forward here.
334
+ */
319
335
  onSelectIssue?: (issue: SubsystemIssue) => void;
320
336
  /** Apply an issue's deterministic fix. */
321
337
  onApplyIssueFix?: (issue: SubsystemIssue) => void;
@@ -544,6 +560,13 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
544
560
  const [sidebarView, setSidebarView] = useState<'files' | 'walkthroughs'>(() =>
545
561
  walkthroughs?.length ? 'walkthroughs' : 'files',
546
562
  );
563
+ // Temporary edge-vocabulary override. Focusing a relation finding whose edge
564
+ // belongs to the *other* vocabulary flips the canvas so the edge is actually
565
+ // visible; it reverts when the focus is undone (see `unfocusIssueTarget`) or
566
+ // when the diagnostics list closes. Null = use the host-pinned / tab view.
567
+ const [edgeViewOverride, setEdgeViewOverride] = useState<SubsystemEdgeView | null>(
568
+ null,
569
+ );
547
570
  // One edge vocabulary at a time. When the caller doesn't pick, the sidebar's
548
571
  // Files / Walkthroughs tab picks: Files draws topology relation edges,
549
572
  // Walkthroughs draws runtime hop edges. Without visible tabs (no walkthroughs,
@@ -551,6 +574,7 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
551
574
  // to walkthrough edges rather than empty, everything else to relations.
552
575
  const sidebarTabsVisible = !hideSidebar && (walkthroughs?.length ?? 0) > 0;
553
576
  const resolvedEdgeView: SubsystemEdgeView =
577
+ edgeViewOverride ??
554
578
  edgeView ??
555
579
  (sidebarTabsVisible
556
580
  ? (sidebarView === 'walkthroughs' ? 'walkthroughs' : 'relations')
@@ -640,6 +664,11 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
640
664
  // closure over the effect deps) can toggle without a stale value.
641
665
  const selectedRef = useRef<SubsystemComponent | null>(null);
642
666
  selectedRef.current = selected;
667
+ // The module frame an issue card framed. A module target selects no node and
668
+ // no edge, so nothing else records that focus — without this the canvas has
669
+ // no way to tell a module focus it still owns from one a later click took
670
+ // over, and the camera would stay parked on the region forever.
671
+ const issueModuleFocusRef = useRef<string | null>(null);
643
672
  // Ref mirror of the open file drawer target for tree-click toggle.
644
673
  const openFileRef = useRef<{ file: string; startLine?: number } | null>(null);
645
674
  const openFile =
@@ -926,16 +955,273 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
926
955
  const xyflowNodesBase = nodes as Node[];
927
956
  const baseEdges = convertedEdges as Edge[];
928
957
 
958
+ // Resolve an issue's component target to the matching node. `id` is the
959
+ // stable alias; `label` may be an alias, name, or symbol. Non-component
960
+ // targets (relation / module / flow / repo) have no single node → null.
961
+ const issueComponent = useCallback(
962
+ (issue: SubsystemIssue): SubsystemComponent | null => {
963
+ const target = issue.target;
964
+ if (target?.kind !== 'component') return null;
965
+ return (
966
+ components.find(
967
+ (c) =>
968
+ (target.id != null && c.alias === target.id) ||
969
+ c.alias === target.label ||
970
+ c.name === target.label ||
971
+ c.symbol === target.label,
972
+ ) ?? null
973
+ );
974
+ },
975
+ [components],
976
+ );
977
+
978
+ // Resolve a `relation` issue target to the display edge it flags. The target
979
+ // names the two endpoints (`from → to`); match an edge joining both, in
980
+ // either direction, preferring the target's `detail` mechanism when it names
981
+ // one. Null when no display edge matches.
982
+ const issueEdge = useCallback(
983
+ (issue: SubsystemIssue): Edge | null => {
984
+ const target = issue.target;
985
+ if (target?.kind !== 'relation') return null;
986
+ const parts = `${target.id ?? ''} → ${target.label}`
987
+ .split('→')
988
+ .map((p) => p.replace(/\(\)$/, '').trim())
989
+ .filter(Boolean);
990
+ const joins = (e: Edge): boolean =>
991
+ parts.includes(e.source) && parts.includes(e.target);
992
+ const matches = baseEdges.filter(joins);
993
+ const byMechanism = target.detail
994
+ ? matches.filter(
995
+ (e) =>
996
+ (e.data as { mechanism?: string } | undefined)?.mechanism ===
997
+ target.detail,
998
+ )
999
+ : matches;
1000
+ return byMechanism[0] ?? matches[0] ?? null;
1001
+ },
1002
+ [baseEdges],
1003
+ );
1004
+
1005
+ // A `module` issue target names a boundary frame, so focusing the card frames
1006
+ // that region on the canvas. Null when the target names no frame (a singleton
1007
+ // dropped from the layout, or a region key nothing declares).
1008
+ const issueModuleNodeId = useCallback(
1009
+ (issue: SubsystemIssue): string | null => {
1010
+ const target = issue.target;
1011
+ if (target?.kind !== 'module') return null;
1012
+ const key = target.id ?? target.label;
1013
+ if (!components.some((c) => c.module?.trim() === key)) return null;
1014
+ return moduleGroupNodeId(key);
1015
+ },
1016
+ [components],
1017
+ );
1018
+
1019
+ // A `step` issue target names ONE step of a walkthrough — the walkthrough id in
1020
+ // `id`, the 0-based step position in `stepIndex`. Validated against the loaded
1021
+ // walkthroughs so a finding left over from an edited flow resolves to null
1022
+ // rather than framing whatever now happens to sit at that index.
1023
+ const issueStep = useCallback(
1024
+ (
1025
+ issue: SubsystemIssue,
1026
+ ): { walkthrough: SubsystemWalkthrough; stepIndex: number } | null => {
1027
+ const target = issue.target;
1028
+ if (target?.kind !== 'step') return null;
1029
+ if (target.id == null || target.stepIndex == null) return null;
1030
+ const walkthrough = walkthroughs?.find((t) => t.id === target.id);
1031
+ if (!walkthrough?.steps[target.stepIndex]) return null;
1032
+ return { walkthrough, stepIndex: target.stepIndex };
1033
+ },
1034
+ [walkthroughs],
1035
+ );
1036
+
1037
+ // Per-node diagnostics badge: fold each component-targeted finding that maps
1038
+ // to a verification rung into one badge per node — worst severity wins, the
1039
+ // chip shows the earliest failing rung, and the count tallies the findings.
1040
+ const issueBadgeByAlias = useMemo(() => {
1041
+ const map = new Map<string, SubsystemNodeIssue>();
1042
+ if (!issues?.length) return map;
1043
+ for (const issue of issues) {
1044
+ const rung = issueRung(issue.kind);
1045
+ if (!rung) continue;
1046
+ const comp = issueComponent(issue);
1047
+ if (!comp) continue;
1048
+ const prev = map.get(comp.alias);
1049
+ map.set(comp.alias, {
1050
+ severity:
1051
+ prev?.severity === 'error' || issue.severity === 'error'
1052
+ ? 'error'
1053
+ : 'info',
1054
+ rung:
1055
+ prev != null && ISSUE_RUNG_ORDER[prev.rung] <= ISSUE_RUNG_ORDER[rung]
1056
+ ? prev.rung
1057
+ : rung,
1058
+ count: (prev?.count ?? 0) + 1,
1059
+ });
1060
+ }
1061
+ return map;
1062
+ }, [issues, issueComponent]);
1063
+
1064
+ // Per-frame diagnostics badge: the same fold, but for findings about a
1065
+ // BOUNDARY rather than a construct. Keyed by the region's React Flow node id.
1066
+ // Only kinds with a dedicated frame icon qualify (`ISSUE_KIND_ICON`) — a
1067
+ // finding with no icon of its own has nothing to badge the frame with, and
1068
+ // borrowing its layer's icon would imply the frame is at fault for it.
1069
+ const regionIssueByNodeId = useMemo(() => {
1070
+ const map = new Map<string, SubsystemRegionIssue>();
1071
+ if (!issues?.length) return map;
1072
+ for (const issue of issues) {
1073
+ const target = issue.target;
1074
+ if (target?.kind !== 'module' || !ISSUE_KIND_ICON[issue.kind]) continue;
1075
+ const id = moduleGroupNodeId(target.id ?? target.label);
1076
+ const prev = map.get(id);
1077
+ map.set(id, {
1078
+ severity:
1079
+ prev?.severity === 'error' || issue.severity === 'error' ? 'error' : 'info',
1080
+ kind:
1081
+ prev != null && issueKindOrder(prev.kind) <= issueKindOrder(issue.kind)
1082
+ ? prev.kind
1083
+ : issue.kind,
1084
+ count: (prev?.count ?? 0) + 1,
1085
+ });
1086
+ }
1087
+ return map;
1088
+ }, [issues]);
1089
+
1090
+ // Expanded verification layers in the diagnostics list. When any layer with
1091
+ // findings is expanded, the canvas dims everything that layer does not
1092
+ // implicate (see `issueFocus`). The list publishes this through
1093
+ // `onExpandedCategoriesChange`; empty while every layer is collapsed.
1094
+ const [expandedIssueCategories, setExpandedIssueCategories] = useState<
1095
+ SubsystemIssueCategory[]
1096
+ >([]);
1097
+ // Stable setter — the list re-emits on mount and on every toggle, so compare
1098
+ // before storing to avoid churn (and to keep the list effect's dep stable).
1099
+ const handleExpandedCategoriesChange = useCallback(
1100
+ (cats: SubsystemIssueCategory[]) => {
1101
+ setExpandedIssueCategories((prev) =>
1102
+ prev.length === cats.length && prev.every((c, i) => c === cats[i])
1103
+ ? prev
1104
+ : cats,
1105
+ );
1106
+ },
1107
+ [],
1108
+ );
1109
+
1110
+ // Resolve a component name / symbol / alias reference to a component alias.
1111
+ const resolveAlias = useCallback(
1112
+ (ref: string): string | null => {
1113
+ const clean = ref.replace(/\(\)$/, '').trim();
1114
+ const c = components.find(
1115
+ (x) =>
1116
+ x.alias === clean ||
1117
+ x.name === clean ||
1118
+ (x.symbol != null && x.symbol.replace(/\(\)$/, '') === clean),
1119
+ );
1120
+ return c?.alias ?? null;
1121
+ },
1122
+ [components],
1123
+ );
1124
+
1125
+ // Graph elements implicated by the expanded layers' findings — the bright set
1126
+ // the canvas keeps while everything else dims. Derived from each finding's
1127
+ // target:
1128
+ // component → that node
1129
+ // relation → the edge it flags (+ its two endpoint nodes)
1130
+ // module → every component in that module
1131
+ // walkthrough → the flow's nodes + its hop edges
1132
+ // repo → every component of that repo
1133
+ // graph → whole-graph finding; implicates nothing specific
1134
+ // Returns null when nothing is expanded, no expanded layer has findings, or
1135
+ // the findings implicate nothing — so no dimming is applied.
1136
+ const issueFocus = useMemo(() => {
1137
+ if (!issues?.length || expandedIssueCategories.length === 0) return null;
1138
+ const active = new Set(expandedIssueCategories);
1139
+ const activeIssues = issues.filter((i) => active.has(issueCategory(i)));
1140
+ if (activeIssues.length === 0) return null;
1141
+ const nodeIds = new Set<string>();
1142
+ const edgeIds = new Set<string>();
1143
+ for (const issue of activeIssues) {
1144
+ const t = issue.target;
1145
+ if (!t) continue; // whole-graph finding — no specific element
1146
+ if (t.kind === 'component') {
1147
+ const a = resolveAlias(t.id ?? t.label);
1148
+ if (a) nodeIds.add(a);
1149
+ } else if (t.kind === 'relation') {
1150
+ // The target names the two endpoints (`from → to`); light the edge and
1151
+ // its endpoints. Falls back to endpoints alone if no edge matches.
1152
+ const edge = issueEdge(issue);
1153
+ if (edge) {
1154
+ edgeIds.add(edge.id);
1155
+ nodeIds.add(edge.source);
1156
+ nodeIds.add(edge.target);
1157
+ } else {
1158
+ for (const part of `${t.id ?? ''} → ${t.label}`.split('→')) {
1159
+ const a = resolveAlias(part);
1160
+ if (a) nodeIds.add(a);
1161
+ }
1162
+ }
1163
+ } else if (t.kind === 'module') {
1164
+ const key = t.id ?? t.label;
1165
+ const prefix = `${key.replace(/\/$/, '')}/`;
1166
+ for (const c of components) {
1167
+ if (
1168
+ c.module === key ||
1169
+ c.file === key ||
1170
+ (c.file !== '' && c.file.endsWith(key)) ||
1171
+ c.file.startsWith(prefix)
1172
+ ) {
1173
+ nodeIds.add(c.alias);
1174
+ }
1175
+ }
1176
+ } else if (t.kind === 'walkthrough') {
1177
+ const wt = (walkthroughs ?? []).find(
1178
+ (w) => w.id === t.id || w.title === t.label,
1179
+ );
1180
+ if (wt) {
1181
+ for (const s of wt.steps) {
1182
+ nodeIds.add(s.from);
1183
+ nodeIds.add(s.to);
1184
+ edgeIds.add(walkthroughStepGraphEdgeId(s));
1185
+ }
1186
+ }
1187
+ } else if (t.kind === 'repo') {
1188
+ const key = t.id ?? t.label;
1189
+ for (const c of components) {
1190
+ if (c.purl === key) nodeIds.add(c.alias);
1191
+ }
1192
+ }
1193
+ }
1194
+ if (nodeIds.size === 0 && edgeIds.size === 0) return null;
1195
+ // An edge whose endpoints both sit in the bright set stays lit too, so a
1196
+ // focused cluster doesn't read as isolated nodes.
1197
+ for (const e of baseEdges) {
1198
+ if (nodeIds.has(e.source) && nodeIds.has(e.target)) edgeIds.add(e.id);
1199
+ }
1200
+ return { nodeIds, edgeIds };
1201
+ }, [issues, expandedIssueCategories, components, walkthroughs, baseEdges, resolveAlias, issueEdge]);
1202
+ const issueFocusNodeIds = issueFocus?.nodeIds ?? null;
1203
+ const issueFocusEdgeIds = issueFocus?.edgeIds ?? null;
1204
+
929
1205
  // When an edge is selected, dim every other edge + its label to focus it.
930
1206
  const [selectedEdgeId, setSelectedEdgeId] = useState<string | null>(null);
931
1207
  // Ref mirror so `selectEdge` (a useCallback over early deps) can toggle
932
1208
  // without a stale closure value.
933
1209
  const selectedEdgeIdRef = useRef<string | null>(null);
934
1210
  selectedEdgeIdRef.current = selectedEdgeId;
1211
+ // Ref mirrors of the focused step, so `unfocusIssueTarget` (a useCallback
1212
+ // over early deps) can tell a step focus it still owns from one the user has
1213
+ // since moved elsewhere in the walkthrough panel.
1214
+ const focusedStepRef = useRef<{ walkthroughId: string; stepIndex: number } | null>(
1215
+ null,
1216
+ );
1217
+ focusedStepRef.current =
1218
+ focusedWalkthroughId != null && focusedStepIndex != null
1219
+ ? { walkthroughId: focusedWalkthroughId, stepIndex: focusedStepIndex }
1220
+ : null;
1221
+
935
1222
  // Edge ids in walkthrough focus (an active flow's edge set, or a single
936
1223
  // step's edge). Used to frame the camera. `null` = no walkthrough focus.
937
- const focusEdgeIds = useMemo(() => {
938
- if (autoPlayFocus) {
1224
+ const focusEdgeIds = useMemo(() => { if (autoPlayFocus) {
939
1225
  const tl = walkthroughs?.find((t) => t.id === autoPlayFocus.walkthroughId);
940
1226
  const step = tl?.steps[autoPlayFocus.stepIndex];
941
1227
  return step ? new Set([walkthroughStepGraphEdgeId(step)]) : null;
@@ -1070,12 +1356,22 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1070
1356
  anyOpened: openedNodeIds != null,
1071
1357
  anySelected: brightNodeIds != null || previewNodeIds != null,
1072
1358
  });
1073
- const dimmed = previewNodeIds
1074
- ? vis.hidden || !memberAliases.some((alias) => previewNodeIds.has(alias))
1359
+ // `brightNodeIds` is the focused step's endpoints. It has to be a dim
1360
+ // source, not just a bright set: without an expanded flow,
1361
+ // `flowElementVisibility` reports non-participants as *hidden*, and the
1362
+ // noOpenedFlow escape below discards that — leaving them neither hidden
1363
+ // nor dimmed. Naming the participants as the dim source dims everything
1364
+ // outside the focused step however the flow got focused.
1365
+ const dimSource = previewNodeIds ?? brightNodeIds ?? issueFocusNodeIds;
1366
+ const dimmed = dimSource
1367
+ ? vis.hidden || !memberAliases.some((alias) => dimSource.has(alias))
1075
1368
  : vis.dimmed;
1076
1369
  const hidden = noOpenedFlow ? false : vis.hidden;
1077
1370
  // Host override wins over the library's derived frame color.
1078
1371
  const color = region?.key != null ? boundaryColors?.[region.key] : undefined;
1372
+ // Boundary findings badge the FRAME, not a member — a region's shape is
1373
+ // the fault, so no leaf construct carries it.
1374
+ const regionIssue = regionIssueByNodeId.get(n.id);
1079
1375
  return {
1080
1376
  ...n,
1081
1377
  hidden,
@@ -1084,6 +1380,7 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1084
1380
  ...(n.data as object),
1085
1381
  ...(color != null && { color }),
1086
1382
  ...(dimmed && { dimmed: true }),
1383
+ ...(regionIssue && { issue: regionIssue }),
1087
1384
  },
1088
1385
  };
1089
1386
  }
@@ -1100,9 +1397,17 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1100
1397
  anyOpened: openedNodeIds != null,
1101
1398
  anySelected: brightNodeIds != null || previewNodeIds != null,
1102
1399
  });
1103
- const dimmed = previewNodeIds ? (vis.hidden || !previewNodeIds.has(n.id)) : vis.dimmed;
1400
+ // `brightNodeIds` (the focused step's endpoints) is a dim source as well
1401
+ // as a bright set — see the group branch above.
1402
+ const dimSource = previewNodeIds ?? brightNodeIds ?? issueFocusNodeIds;
1403
+ const dimmed = dimSource ? (vis.hidden || !dimSource.has(n.id)) : vis.dimmed;
1104
1404
  const hidden = noOpenedFlow ? false : vis.hidden;
1105
- if (fileMatch === undefined && !isSelected && !dimmed) {
1405
+ // Component findings key by alias, boundary findings by region node id.
1406
+ // The two id spaces are disjoint (`module:` / `process:` are prefixed), so
1407
+ // one lookup covers both node kinds.
1408
+ const issueBadge =
1409
+ issueBadgeByAlias.get(n.id) ?? regionIssueByNodeId.get(n.id);
1410
+ if (fileMatch === undefined && !isSelected && !dimmed && !issueBadge) {
1106
1411
  const { fileMatch: _f, isSelected: _s, dimmed: _d, ...rest } = n.data as Record<string, unknown>;
1107
1412
  return { ...n, hidden, data: rest };
1108
1413
  }
@@ -1114,10 +1419,11 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1114
1419
  ...(fileMatch !== undefined && { fileMatch }),
1115
1420
  ...(isSelected && { isSelected }),
1116
1421
  ...(dimmed && { dimmed: true }),
1422
+ ...(issueBadge && { issue: issueBadge }),
1117
1423
  },
1118
1424
  };
1119
1425
  });
1120
- }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, boundaryColors]);
1426
+ }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, issueFocusNodeIds, issueBadgeByAlias, regionIssueByNodeId, boundaryColors]);
1121
1427
 
1122
1428
  const baseNodesKey = useMemo(() => nodes.map((n) => n.id).sort().join(','), [nodes]);
1123
1429
  const baseEdgesKey = useMemo(
@@ -1151,7 +1457,7 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1151
1457
  }
1152
1458
  return isWalkthroughMechanism(mechanism);
1153
1459
  };
1154
- if (openedEdgeIds || focusEdgeIds || previewEdgeIds) {
1460
+ if (openedEdgeIds || focusEdgeIds || previewEdgeIds || issueFocusEdgeIds) {
1155
1461
  return baseEdges.map((e) => {
1156
1462
  const vis = flowElementVisibility({
1157
1463
  inOpened: openedEdgeIds?.has(e.id) === true,
@@ -1159,7 +1465,8 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1159
1465
  anyOpened: openedEdgeIds != null,
1160
1466
  anySelected: focusEdgeIds != null,
1161
1467
  });
1162
- const dimmed = previewEdgeIds ? vis.hidden || !previewEdgeIds.has(e.id) : vis.dimmed;
1468
+ const dimSource = previewEdgeIds ?? issueFocusEdgeIds;
1469
+ const dimmed = dimSource ? vis.hidden || !dimSource.has(e.id) : vis.dimmed;
1163
1470
  const hidden = vis.hidden || !edgeInView(e);
1164
1471
  return { ...paint(e, dimmed), hidden };
1165
1472
  });
@@ -1171,7 +1478,7 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1171
1478
  }));
1172
1479
  }
1173
1480
  return baseEdges.map((e) => ({ ...e, hidden: !edgeInView(e) }));
1174
- }, [baseEdges, selectedEdgeId, openedEdgeIds, focusEdgeIds, previewEdgeIds, resolvedEdgeView]);
1481
+ }, [baseEdges, selectedEdgeId, openedEdgeIds, focusEdgeIds, previewEdgeIds, issueFocusEdgeIds, resolvedEdgeView]);
1175
1482
 
1176
1483
  const onNodesChange = useCallback(
1177
1484
  (changes: NodeChange[]) => {
@@ -1225,6 +1532,7 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1225
1532
  return;
1226
1533
  }
1227
1534
  setSelected(comp);
1535
+ issueModuleFocusRef.current = null;
1228
1536
  if (comp.alias) onSelect?.(comp.alias);
1229
1537
  }
1230
1538
  },
@@ -1244,6 +1552,8 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1244
1552
  setSelectedEdgeId(null);
1245
1553
  setFocusedWalkthroughId(null);
1246
1554
  setFocusedStepIndex(null);
1555
+ setEdgeViewOverride(null);
1556
+ issueModuleFocusRef.current = null;
1247
1557
  }, []);
1248
1558
 
1249
1559
  // Sidebar file trees — one per repo on multi-repo graphs, each under its
@@ -1263,6 +1573,14 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1263
1573
  );
1264
1574
  const controlledIssues = showIssues !== undefined;
1265
1575
  const issuesActive = controlledIssues ? showIssues : diagnosticsOpen;
1576
+ // Layer focus only applies while the diagnostics list is on screen — closing
1577
+ // it clears any dimming the expanded layers were driving.
1578
+ useEffect(() => {
1579
+ if (!issuesActive) {
1580
+ setExpandedIssueCategories([]);
1581
+ setEdgeViewOverride(null);
1582
+ }
1583
+ }, [issuesActive]);
1266
1584
  const toggleIssues = () => {
1267
1585
  if (!controlledIssues) setDiagnosticsOpen((v) => !v);
1268
1586
  diagnostic?.onToggle?.();
@@ -1463,6 +1781,66 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1463
1781
  ],
1464
1782
  );
1465
1783
 
1784
+ // A node's laid-out rect in absolute flow coords. `absoluteRects` is the
1785
+ // authority; the fallback covers an unparented group node, whose `position` is
1786
+ // already absolute. Nested groups are parent-relative, so they are skipped
1787
+ // rather than mis-boxed.
1788
+ const rectForNode = useCallback(
1789
+ (id: string): { x: number; y: number; width: number; height: number } | undefined => {
1790
+ const r = built.absoluteRects.get(id);
1791
+ if (r) return r;
1792
+ const n = built.nodes.find((x) => x.id === id) as
1793
+ | {
1794
+ position?: { x: number; y: number };
1795
+ width?: number;
1796
+ height?: number;
1797
+ parentId?: string;
1798
+ }
1799
+ | undefined;
1800
+ if (!n?.position || n.parentId) return undefined;
1801
+ return {
1802
+ x: n.position.x,
1803
+ y: n.position.y,
1804
+ width: n.width ?? 0,
1805
+ height: n.height ?? 0,
1806
+ };
1807
+ },
1808
+ [built.absoluteRects, built.nodes],
1809
+ );
1810
+
1811
+ // Frame a set of nodes by their laid-out rects. Unlike `fitFocusBounds` this
1812
+ // takes node ids, so it works for boundary frames too — React Flow's own
1813
+ // `fitView({ nodes })` can't be relied on for group nodes here, and the rects
1814
+ // are already in absolute flow coords (grouped child `position`s are
1815
+ // parent-relative and would skew the box).
1816
+ const fitNodeRects = useCallback(
1817
+ (ids: ReadonlySet<string>, padding: number) => {
1818
+ let minX = Infinity;
1819
+ let minY = Infinity;
1820
+ let maxX = -Infinity;
1821
+ let maxY = -Infinity;
1822
+ for (const id of ids) {
1823
+ const r = rectForNode(id);
1824
+ if (!r) continue;
1825
+ minX = Math.min(minX, r.x);
1826
+ minY = Math.min(minY, r.y);
1827
+ maxX = Math.max(maxX, r.x + r.width);
1828
+ maxY = Math.max(maxY, r.y + r.height);
1829
+ }
1830
+ if (!Number.isFinite(minX) || !Number.isFinite(minY)) return;
1831
+ fitBounds(
1832
+ {
1833
+ x: minX,
1834
+ y: minY,
1835
+ width: Math.max(1, maxX - minX),
1836
+ height: Math.max(1, maxY - minY),
1837
+ },
1838
+ { padding, duration: walkthroughFocusDurationMs },
1839
+ );
1840
+ },
1841
+ [rectForNode, fitBounds, walkthroughFocusDurationMs],
1842
+ );
1843
+
1466
1844
  // Zoom back out to the full diagram after the last expanded walkthrough
1467
1845
  // closes (visibility restores non-flow nodes that were hidden).
1468
1846
  const fitOverview = useCallback(() => {
@@ -1841,6 +2219,144 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
1841
2219
  [components, onSelect],
1842
2220
  );
1843
2221
 
2222
+ // Issue click → select + frame the target on the canvas. Component targets
2223
+ // frame their node; relation targets frame their edge (endpoints + the routed
2224
+ // line); other kinds (module / flow / repo) have no single element and just
2225
+ // forward. Selections / focus that would hide the target are cleared first,
2226
+ // then the camera flies to it on the next frame. The host's `onSelectIssue`
2227
+ // still fires afterwards for its own detail.
2228
+ const focusIssueTarget = useCallback(
2229
+ (issue: SubsystemIssue) => {
2230
+ const comp = issueComponent(issue);
2231
+ const edge = comp ? null : issueEdge(issue);
2232
+ const step = comp || edge ? null : issueStep(issue);
2233
+ if (comp) {
2234
+ setSelected(comp);
2235
+ setSelectedEdgeId(null);
2236
+ setFocusedWalkthroughId(null);
2237
+ setFocusedStepIndex(null);
2238
+ setHoveredWalkthroughStep(null);
2239
+ issueModuleFocusRef.current = null;
2240
+ onSelect?.(comp.alias);
2241
+ requestAnimationFrame(() => {
2242
+ fitView({
2243
+ nodes: [{ id: comp.alias }],
2244
+ padding: 0.4,
2245
+ duration: 300,
2246
+ minZoom: 0.05,
2247
+ maxZoom: 1.5,
2248
+ });
2249
+ });
2250
+ } else if (edge) {
2251
+ setSelected(null);
2252
+ setFocusedWalkthroughId(null);
2253
+ setFocusedStepIndex(null);
2254
+ setHoveredWalkthroughStep(null);
2255
+ setSelectedEdgeId(edge.id);
2256
+ issueModuleFocusRef.current = null;
2257
+ // Flip to the vocabulary this edge belongs to, so a hop flagged in the
2258
+ // relations view (or vice versa) is actually drawn while focused.
2259
+ const d = edge.data as
2260
+ | { mechanism?: string; provenance?: SubsystemEdgeProvenance }
2261
+ | undefined;
2262
+ const mechanism = d?.mechanism ?? 'uses';
2263
+ setEdgeViewOverride(
2264
+ d?.provenance === 'graphify' || isRelationMechanism(mechanism)
2265
+ ? 'relations'
2266
+ : 'walkthroughs',
2267
+ );
2268
+ requestAnimationFrame(() => {
2269
+ fitFocusBounds(new Set([edge.id]));
2270
+ });
2271
+ } else if (step) {
2272
+ // A step finding focuses the step itself, through the same entry point
2273
+ // the walkthrough panel uses — so the drawer, the step numbering, the
2274
+ // dim-mode hover preview, and the camera all behave identically whether
2275
+ // the step was reached from the panel or from a diagnostics card.
2276
+ issueModuleFocusRef.current = null;
2277
+ focusWalkthroughStep(step.walkthrough, step.stepIndex);
2278
+ } else {
2279
+ // Nothing selectable — but a module target names a boundary frame, so
2280
+ // frame that region.
2281
+ const moduleNodeId = issueModuleNodeId(issue);
2282
+ if (moduleNodeId) {
2283
+ setSelected(null);
2284
+ setSelectedEdgeId(null);
2285
+ setFocusedWalkthroughId(null);
2286
+ setFocusedStepIndex(null);
2287
+ setHoveredWalkthroughStep(null);
2288
+ issueModuleFocusRef.current = moduleNodeId;
2289
+ requestAnimationFrame(() => {
2290
+ fitNodeRects(new Set([moduleNodeId]), 0.4);
2291
+ });
2292
+ }
2293
+ }
2294
+ onSelectIssue?.(issue);
2295
+ },
2296
+ [
2297
+ issueComponent,
2298
+ issueEdge,
2299
+ issueStep,
2300
+ issueModuleNodeId,
2301
+ focusWalkthroughStep,
2302
+ onSelect,
2303
+ onSelectIssue,
2304
+ fitView,
2305
+ fitFocusBounds,
2306
+ fitNodeRects,
2307
+ ],
2308
+ );
2309
+
2310
+ // Collapsing the issue card again undoes the focus: drop the node / edge
2311
+ // selection (only when it is still this issue's target — another card may
2312
+ // have taken it over) and zoom back out to the whole graph. A module target
2313
+ // frames a region rather than selecting anything, so its ownership lives in
2314
+ // `issueModuleFocusRef`; without this branch a module focus never unwinds and
2315
+ // the camera never zooms back out.
2316
+ const unfocusIssueTarget = useCallback(
2317
+ (issue: SubsystemIssue) => {
2318
+ const comp = issueComponent(issue);
2319
+ if (comp) {
2320
+ if (selectedRef.current?.alias !== comp.alias) return;
2321
+ setSelected(null);
2322
+ setSelectedEdgeId(null);
2323
+ } else {
2324
+ const edge = issueEdge(issue);
2325
+ const step = edge ? null : issueStep(issue);
2326
+ const moduleNodeId = edge || step ? null : issueModuleNodeId(issue);
2327
+ if (edge) {
2328
+ if (selectedEdgeIdRef.current !== edge.id) return;
2329
+ setSelectedEdgeId(null);
2330
+ setEdgeViewOverride(null);
2331
+ } else if (step) {
2332
+ // Only unwind a step focus this card still owns. A dim-mode graph
2333
+ // keeps its step focus in hover state instead (owned by the pointer,
2334
+ // not the card), and correctly leaves that alone here.
2335
+ const owned = focusedStepRef.current;
2336
+ if (
2337
+ owned?.walkthroughId !== step.walkthrough.id ||
2338
+ owned?.stepIndex !== step.stepIndex
2339
+ ) {
2340
+ return;
2341
+ }
2342
+ setFocusedWalkthroughId(null);
2343
+ setFocusedStepIndex(null);
2344
+ setDrawerTarget((prev) => (prev?.kind === 'walkthrough' ? null : prev));
2345
+ } else if (moduleNodeId) {
2346
+ // Only unwind framing this card still owns.
2347
+ if (issueModuleFocusRef.current !== moduleNodeId) return;
2348
+ issueModuleFocusRef.current = null;
2349
+ } else {
2350
+ return;
2351
+ }
2352
+ }
2353
+ requestAnimationFrame(() => {
2354
+ fitView({ padding: 0.1, duration: 300, minZoom: 0.05, maxZoom: 2 });
2355
+ });
2356
+ },
2357
+ [issueComponent, issueEdge, issueStep, issueModuleNodeId, fitView],
2358
+ );
2359
+
1844
2360
  // Construct tokens inside a walkthrough snippet. A step's line is an edge
1845
2361
  // between its `from`/`to` components, so a token naming either of those
1846
2362
  // constructs should navigate to that construct's declaration. Index the
@@ -2096,9 +2612,11 @@ function Inner({ components, relations, walkthroughs, graphifyRelations, orderBy
2096
2612
  <SubsystemIssueList
2097
2613
  issues={issues ?? []}
2098
2614
  focusCategory={focusIssueCategory}
2099
- onSelectIssue={onSelectIssue}
2615
+ onSelectIssue={focusIssueTarget}
2616
+ onDeselectIssue={unfocusIssueTarget}
2100
2617
  onApplyFix={onApplyIssueFix}
2101
2618
  onHoverIssue={onHoverIssue}
2619
+ onExpandedCategoriesChange={handleExpandedCategoriesChange}
2102
2620
  />
2103
2621
  ) : (
2104
2622
  <>