@principal-ai/subsystems-react 0.56.36 → 0.56.38

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.
@@ -446,6 +446,19 @@ export interface SubsystemComponentGraphProps {
446
446
  * a step row, and fall back to the focused trail on leave.
447
447
  */
448
448
  onTrailStepHover?: (ref: { trailId: string; stepIndex: number } | null) => void;
449
+ /**
450
+ * Reports the trail under the pointer in the Trails panel — its header row or
451
+ * one of its steps — and `null` when the pointer leaves. Unlike
452
+ * `onTrailStepHover`, a whole-flow hover is reported too.
453
+ */
454
+ onTrailHover?: (trailId: string | null) => void;
455
+ /**
456
+ * Host-driven emphasis, the way hovering a trail does it: these trails' edges
457
+ * and components stay bright and everything else dims, and the Trails panel
458
+ * dims the other rows. It never moves the camera or changes selection, and
459
+ * the graph's own trail hover wins while it lasts. Empty or absent = none.
460
+ */
461
+ highlightedTrailIds?: ReadonlySet<string>;
449
462
  /**
450
463
  * Called with the next trail order after a drag in the sidebar's
451
464
  * flows panel. When set, each row grows a drag grip and a drop emits the
@@ -863,7 +876,7 @@ interface InnerProps extends SubsystemComponentGraphProps {
863
876
  onSidebarTrailChange: (trailId: string | null) => void;
864
877
  }
865
878
 
866
- function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirection: layoutDirectionProp, defaultLayoutDirection = 'horizontal', onLayoutDirectionChange, hideLayoutToggle = false, refocusOnLayoutFlip = true, initialTrailId, onTrailSelect, focusedTrailStep, proposedTrailIds, proposedStepKeys, stepChange, stepNumberLabels: hostStepNumberLabels, stepHistory, proposedStep, focusedVariationStepIndexes, proposedComponentAliases, workingComponentAliases, removedComponentAliases, 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, focusVerticalBiasPx = 0, graphTitle, showTrailTitle = false, description, notes, 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, containersActive, hideDrawer = false, persistKey, liveEvents, agentsPanel }: InnerProps) {
879
+ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirection: layoutDirectionProp, defaultLayoutDirection = 'horizontal', onLayoutDirectionChange, hideLayoutToggle = false, refocusOnLayoutFlip = true, initialTrailId, onTrailSelect, focusedTrailStep, proposedTrailIds, proposedStepKeys, stepChange, stepNumberLabels: hostStepNumberLabels, stepHistory, proposedStep, focusedVariationStepIndexes, proposedComponentAliases, workingComponentAliases, removedComponentAliases, onTrailStepHover, onTrailHover, highlightedTrailIds, 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, focusVerticalBiasPx = 0, graphTitle, showTrailTitle = false, description, notes, 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, containersActive, hideDrawer = false, persistKey, liveEvents, agentsPanel }: InnerProps) {
867
880
  const { theme } = useTheme();
868
881
  const { fitView, fitBounds, setViewport } = useReactFlow();
869
882
  const flowWidth = useStore((state) => state.width);
@@ -2266,6 +2279,37 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2266
2279
  }
2267
2280
  return ids.size > 0 ? ids : null;
2268
2281
  }, [trails, hoveredTrailStep]);
2282
+ // Host-driven emphasis (`highlightedTrailIds`): the same bright set a trail hover
2283
+ // builds, but for several trails and without the camera following it.
2284
+ const externalHighlightEdgeIds = useMemo(() => {
2285
+ if (!highlightedTrailIds || highlightedTrailIds.size === 0 || !trails) return null;
2286
+ const ids = new Set<string>();
2287
+ for (const tl of trails) {
2288
+ if (!highlightedTrailIds.has(tl.id)) continue;
2289
+ for (const s of tl.steps) ids.add(trailStepGraphEdgeId(s));
2290
+ for (const g of linkedEdgeIdsByTrail.get(tl.id) ?? []) ids.add(g);
2291
+ }
2292
+ return ids.size > 0 ? ids : null;
2293
+ }, [trails, highlightedTrailIds, linkedEdgeIdsByTrail]);
2294
+ const externalHighlightNodeIds = useMemo(
2295
+ () => endpointsOf(externalHighlightEdgeIds),
2296
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2297
+ [baseEdges, externalHighlightEdgeIds],
2298
+ );
2299
+ const externalHighlightAliases = useMemo(() => {
2300
+ if (!highlightedTrailIds || highlightedTrailIds.size === 0 || !trails) return null;
2301
+ const ids = new Set<string>();
2302
+ for (const tl of trails) {
2303
+ if (!highlightedTrailIds.has(tl.id)) continue;
2304
+ for (const s of tl.steps) {
2305
+ ids.add(s.from);
2306
+ ids.add(s.to);
2307
+ }
2308
+ }
2309
+ return ids.size > 0 ? ids : null;
2310
+ }, [trails, highlightedTrailIds]);
2311
+ /** A real trail hover wins over the host's emphasis while it lasts. */
2312
+ const spotlightAliases = hoverTrailAliases ?? externalHighlightAliases;
2269
2313
  const aliasToComponent = useMemo(
2270
2314
  () => new Map(components.map((c) => [c.alias, c])),
2271
2315
  [components],
@@ -2314,14 +2358,14 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2314
2358
  // spotlight member as well as a bright set: without an expanded flow
2315
2359
  // there is no opened set, so dimming has to be driven from the
2316
2360
  // participants or nothing outside the focused step would dim.
2317
- const dimSource = previewNodeIds ?? brightNodeIds ?? issueFocusNodeIds;
2361
+ const dimSource = previewNodeIds ?? externalHighlightNodeIds ?? brightNodeIds ?? issueFocusNodeIds;
2318
2362
  // Hover keeps a container bright when any of its contents is in the
2319
2363
  // hovered trail — read off component membership so nesting is
2320
2364
  // transitive and internally-folded trails still count.
2321
- const touchesHover = regionTouchesTrailAliases(region, hoverTrailAliases, aliasToComponent);
2365
+ const touchesHover = regionTouchesTrailAliases(region, spotlightAliases, aliasToComponent);
2322
2366
  const inSpotlight =
2323
2367
  memberAliases.some((alias) => dimSource?.has(alias) === true) || touchesHover;
2324
- const anySpotlight = dimSource != null || hoverTrailAliases != null;
2368
+ const anySpotlight = dimSource != null || spotlightAliases != null;
2325
2369
  const { hidden, dimmed } = flowNodeVisibility({
2326
2370
  inOpened: memberAliases.some((alias) => openedNodeIds?.has(alias) === true),
2327
2371
  inSelected: memberAliases.some((alias) => brightNodeIds?.has(alias) === true),
@@ -2365,14 +2409,14 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2365
2409
  const isSelected = selected?.alias !== undefined && comp?.alias === selected.alias;
2366
2410
  // `brightNodeIds` (the focused step's endpoints) is a spotlight member as
2367
2411
  // well as a bright set — see the group branch above.
2368
- const dimSource = previewNodeIds ?? brightNodeIds ?? issueFocusNodeIds;
2412
+ const dimSource = previewNodeIds ?? externalHighlightNodeIds ?? brightNodeIds ?? issueFocusNodeIds;
2369
2413
  const flowVisibility = flowNodeVisibility({
2370
2414
  inOpened: openedNodeIds?.has(n.id) === true,
2371
2415
  inSelected: brightNodeIds?.has(n.id) === true,
2372
- inSpotlight: dimSource?.has(n.id) === true || (hoverTrailAliases?.has(n.id) === true),
2416
+ inSpotlight: dimSource?.has(n.id) === true || (spotlightAliases?.has(n.id) === true),
2373
2417
  anyOpened: openedNodeIds != null,
2374
2418
  anySelected: brightNodeIds != null,
2375
- anySpotlight: dimSource != null || hoverTrailAliases != null,
2419
+ anySpotlight: dimSource != null || spotlightAliases != null,
2376
2420
  });
2377
2421
  // A removed ghost is never hidden by flow focus — the whole point is to
2378
2422
  // keep it visible as a dim record of what the agent took out.
@@ -2410,7 +2454,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2410
2454
  },
2411
2455
  };
2412
2456
  });
2413
- }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, hoverTrailAliases, aliasToComponent, issueFocusNodeIds, issueBadgeByAlias, regionIssueByNodeId, boundaryColors, proposedComponentAliases, workingComponentAliases, removedComponentAliases, toggleCollapsed]);
2457
+ }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, externalHighlightNodeIds, spotlightAliases, aliasToComponent, issueFocusNodeIds, issueBadgeByAlias, regionIssueByNodeId, boundaryColors, proposedComponentAliases, workingComponentAliases, removedComponentAliases, toggleCollapsed]);
2414
2458
 
2415
2459
  const baseNodesKey = useMemo(() => nodes.map((n) => n.id).sort().join(','), [nodes]);
2416
2460
  const baseEdgesKey = useMemo(
@@ -2453,7 +2497,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2453
2497
  };
2454
2498
  const inSet = (set: ReadonlySet<string> | null | undefined, e: Edge): boolean =>
2455
2499
  set != null && edgeMatches(set, e);
2456
- if (openedEdgeIds || focusEdgeIds || previewEdgeIds || issueFocusEdgeIds) {
2500
+ if (openedEdgeIds || focusEdgeIds || previewEdgeIds || externalHighlightEdgeIds || issueFocusEdgeIds) {
2457
2501
  return baseEdges.map((e) => {
2458
2502
  const ghost = ghostEdgeIds.has(e.id);
2459
2503
  const proposed = !ghost && proposedEdgeIds.has(e.id);
@@ -2463,7 +2507,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2463
2507
  anyOpened: openedEdgeIds != null,
2464
2508
  anySelected: focusEdgeIds != null,
2465
2509
  });
2466
- const dimSource = previewEdgeIds ?? issueFocusEdgeIds;
2510
+ const dimSource = previewEdgeIds ?? externalHighlightEdgeIds ?? issueFocusEdgeIds;
2467
2511
  const dimmed = dimSource
2468
2512
  ? vis.hidden || !inSet(dimSource, e)
2469
2513
  : vis.dimmed || ghost;
@@ -2496,7 +2540,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2496
2540
  hidden: !edgeInView(e),
2497
2541
  };
2498
2542
  });
2499
- }, [baseEdges, selectedEdgeId, openedEdgeIds, focusEdgeIds, previewEdgeIds, issueFocusEdgeIds, resolvedEdgeView, ghostEdgeIds, proposedEdgeIds]);
2543
+ }, [baseEdges, selectedEdgeId, openedEdgeIds, focusEdgeIds, previewEdgeIds, externalHighlightEdgeIds, issueFocusEdgeIds, resolvedEdgeView, ghostEdgeIds, proposedEdgeIds]);
2500
2544
 
2501
2545
  // Gated on layoutReady so the pre-reveal Pass 1 swap never flashes a count.
2502
2546
  const unroutedIds = useMemo(
@@ -3008,7 +3052,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
3008
3052
  setSelectedEdgeId(null);
3009
3053
  setHoveredTrailStep(null);
3010
3054
  onTrailStepHover?.(null);
3011
- }, [filesActive, clearTrailFocus, onTrailStepHover, sidebarTrail]);
3055
+ onTrailHover?.(null);
3056
+ }, [filesActive, clearTrailFocus, onTrailStepHover, onTrailHover, sidebarTrail]);
3012
3057
 
3013
3058
  // Host deep-link: opening the graph from a trail row selects that
3014
3059
  // flow — expand its steps and focus its edges.
@@ -3746,6 +3791,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
3746
3791
  focusedTrailId={sidebarTrail?.id ?? focusedTrailId}
3747
3792
  focusedStepIndex={!sidebarTrail || focusedTrailId === sidebarTrail.id ? focusedStepIndex : null}
3748
3793
  proposedTrailIds={proposedTrailIds}
3794
+ highlightedTrailIds={highlightedTrailIds}
3749
3795
  proposedStepKeys={proposedStepKeys}
3750
3796
  focusedVariationStepIndexes={panelFocusedVariationStepIndexes}
3751
3797
  stepNumberLabels={panelStepNumberLabels}
@@ -3760,15 +3806,18 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
3760
3806
  cancelPendingHoverLeave();
3761
3807
  setHoveredTrailStep({ trailId: tl.id, stepIndex: i });
3762
3808
  onTrailStepHover?.({ trailId: tl.id, stepIndex: i });
3809
+ onTrailHover?.(tl.id);
3763
3810
  }}
3764
3811
  onHoverFlow={(tl) => {
3765
3812
  cancelPendingHoverLeave();
3766
3813
  setHoveredTrailStep({ trailId: tl.id, stepIndex: null });
3767
3814
  onTrailStepHover?.(null);
3815
+ onTrailHover?.(tl.id);
3768
3816
  }}
3769
3817
  onLeaveStep={() => {
3770
3818
  scheduleHoverLeave(hoveredTrailStep);
3771
3819
  onTrailStepHover?.(null);
3820
+ onTrailHover?.(null);
3772
3821
  }}
3773
3822
  onReorder={onReorderTrails}
3774
3823
  componentByAlias={componentByAlias}
@@ -523,3 +523,35 @@ describe('TrailsPanel step emphasis', () => {
523
523
  expect(queryByTitle('Key step')).toBeNull();
524
524
  });
525
525
  });
526
+
527
+ describe('TrailsPanel host emphasis', () => {
528
+ /** Opacity of the row that contains `el`: the nearest ancestor that sets one. */
529
+ function rowOpacity(el: HTMLElement): string {
530
+ let node: HTMLElement | null = el;
531
+ while (node && node.style.opacity === '') node = node.parentElement;
532
+ return node?.style.opacity ?? '';
533
+ }
534
+
535
+ test('rows outside highlightedTrailIds recede; highlighted rows stay full', () => {
536
+ const { getByText } = renderPanel({
537
+ trails: [trails[0]!, usesTrail],
538
+ expandedTrails: new Set(),
539
+ highlightedTrailIds: new Set(['auth-flow']),
540
+ });
541
+ expect(rowOpacity(getByText('Auth flow'))).toBe('1');
542
+ expect(rowOpacity(getByText('Uses flow'))).toBe('0.35');
543
+ });
544
+
545
+ test('an empty or absent set highlights nothing, so no row recedes', () => {
546
+ for (const highlightedTrailIds of [new Set<string>(), undefined]) {
547
+ const { getByText, unmount } = renderPanel({
548
+ trails: [trails[0]!, usesTrail],
549
+ expandedTrails: new Set(),
550
+ highlightedTrailIds,
551
+ });
552
+ expect(rowOpacity(getByText('Auth flow'))).toBe('1');
553
+ expect(rowOpacity(getByText('Uses flow'))).toBe('1');
554
+ unmount();
555
+ }
556
+ });
557
+ });
@@ -791,6 +791,11 @@ export interface TrailsPanelProps {
791
791
  detailContent?: ReactNode;
792
792
  /** Host-local trails awaiting confirmation; their icons use proposal color. */
793
793
  proposedTrailIds?: Set<string>;
794
+ /**
795
+ * Host-driven emphasis: when set (and non-empty), rows for trails outside it
796
+ * recede. Rows are never hidden or reordered.
797
+ */
798
+ highlightedTrailIds?: ReadonlySet<string>;
794
799
  /** Host-local steps awaiting confirmation, keyed by `emphasisKey`. */
795
800
  proposedStepKeys?: Set<string>;
796
801
  /** Step indexes that belong to one focused variation group, by trail id. */
@@ -828,6 +833,7 @@ export function TrailsPanel({
828
833
  drilldown = false,
829
834
  detailContent,
830
835
  proposedTrailIds,
836
+ highlightedTrailIds,
831
837
  proposedStepKeys,
832
838
  focusedVariationStepIndexes,
833
839
  stepNumberLabels,
@@ -947,7 +953,11 @@ export function TrailsPanel({
947
953
  onDrop={reorderable ? handleDrop : undefined}
948
954
  style={{
949
955
  position: 'relative',
950
- opacity: isDragging ? 0.45 : 1,
956
+ opacity: isDragging
957
+ ? 0.45
958
+ : highlightedTrailIds && highlightedTrailIds.size > 0 && !highlightedTrailIds.has(tl.id)
959
+ ? 0.35
960
+ : 1,
951
961
  transition: 'opacity 120ms ease',
952
962
  }}
953
963
  >