@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
@@ -16,11 +16,11 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
16
16
  * injection, onNodeClick) adapted to the subsystem model — read-only.
17
17
  */
18
18
  import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
19
- import { ReactFlow, ReactFlowProvider, useReactFlow, useViewport, applyNodeChanges, } from '@xyflow/react';
19
+ import { ReactFlow, ReactFlowProvider, useReactFlow, useStore, useViewport, getViewportForBounds, applyNodeChanges, } from '@xyflow/react';
20
20
  import { useTheme } from '@principal-ade/industry-theme';
21
21
  import { SUBSYSTEM_MODEL_DESCRIPTION_MAX } from '@principal-ai/subsystems-core';
22
22
  import { ArrowDown, ArrowRight, Boxes, Files, Route, Unlink, X } from 'lucide-react';
23
- import { buildSubsystemGraph, componentPackageKey, deriveGraphEdges, buildBoundaryLayoutGroups, cardFramesForAliases, isCardFrame, isConstructsOnlyModel, packageColor, moduleGroupNodeId, processGroupNodeId, isTrailMechanism, edgeColor, MECHANISM_DESCRIPTIONS, subsystemGraphLayoutKey, trailStepGraphEdgeId, unroutedEdgeIds, } from './model';
23
+ import { buildSubsystemGraph, componentPackageKey, deriveGraphEdges, buildBoundaryLayoutGroups, cardFramesForAliases, isCardFrame, isConstructsOnlyModel, packageColor, moduleGroupNodeId, processGroupNodeId, isTrailMechanism, edgeColor, HOST_PROPOSAL_COLOR, MECHANISM_DESCRIPTIONS, subsystemGraphLayoutKey, trailStepGraphEdgeId, unroutedEdgeIds, } from './model';
24
24
  import { ConstructsCatalog } from './ConstructsCatalog';
25
25
  import { ContainersPanel } from './ContainersPanel';
26
26
  import { technologyBrand } from './techIcons';
@@ -39,7 +39,8 @@ import { GraphWithSidebar } from './GraphWithSidebar';
39
39
  import { ShareButton } from './ShareButton';
40
40
  import { DescriptionOverlay } from './DescriptionOverlay';
41
41
  import { DescriptionPreview } from './DescriptionPreview';
42
- import { TrailsPanel, TRAIL_PLAY_PAUSE_MS, TRAIL_HOVER_PREVIEW_MS } from './TrailsPanel';
42
+ import { TrailsPanel, TRAIL_PLAY_PAUSE_MS, TRAIL_HOVER_PREVIEW_MS, } from './TrailsPanel';
43
+ import { emphasisKey, variationStepNumber } from './stepEmphasis';
43
44
  import { EDGE_LABEL_WIDTH, EDGE_LABEL_HEIGHT, EDGE_LABEL_FONT_SIZE, EDGE_LABEL_CLOUD_PATH, EDGE_LABEL_CLOUD_EXTRA_TOP, } from '../utils/edgeLabel';
44
45
  import { graphGeometryBounds } from '../utils/elkLayout';
45
46
  /** Identifiers a token could match to name this component as a construct. */
@@ -179,9 +180,13 @@ const TrailDrawerContent = memo(function TrailDrawerContent({ render, trail, ste
179
180
  onVisibleStepChange,
180
181
  }) }));
181
182
  });
182
- 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, 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 }) {
183
+ 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 }) {
183
184
  const { theme } = useTheme();
184
- const { fitView, fitBounds } = useReactFlow();
185
+ const { fitView, fitBounds, setViewport } = useReactFlow();
186
+ const flowWidth = useStore((state) => state.width);
187
+ const flowHeight = useStore((state) => state.height);
188
+ const minZoom = useStore((state) => state.minZoom);
189
+ const maxZoom = useStore((state) => state.maxZoom);
185
190
  const [descriptionOpen, setDescriptionOpen] = useState(false);
186
191
  const rawDescription = description?.trim();
187
192
  // The host caps the authored description; trim defensively for other hosts.
@@ -197,12 +202,157 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
197
202
  // Restored once per mount from `localStorage` (see `readViewState`). Each
198
203
  // graph is its own tab/mount, so `persistKey` is stable for a mount.
199
204
  const persisted = useMemo(() => readViewState(persistKey), [persistKey]);
200
- const graphEdges = useMemo(() => deriveGraphEdges({ trails }), [trails]);
205
+ // Host-local before/after links. The graph keeps the unchanged step in its
206
+ // layout and camera bounds, while the sidebar still renders only live steps.
207
+ const ghostLinksByTrail = useMemo(() => {
208
+ const map = new Map();
209
+ for (const link of stepHistory ?? []) {
210
+ const list = map.get(link.trailId) ?? [];
211
+ list.push(link);
212
+ map.set(link.trailId, list);
213
+ }
214
+ return map;
215
+ }, [stepHistory]);
216
+ const proposedEdgeId = proposedStep
217
+ ? trailStepGraphEdgeId(proposedStep.step)
218
+ : null;
219
+ const proposedEdgeIds = useMemo(() => new Set(proposedEdgeId ? [proposedEdgeId] : []), [proposedEdgeId]);
220
+ // The staged step is a variation of the step it would replace, not the next
221
+ // sequential step. Share that label with the panel and the canvas edge.
222
+ const proposedStepLabel = proposedStep
223
+ ? variationStepNumber(proposedStep.stepIndex + 1)
224
+ : null;
225
+ const proposedStepNumberLabels = useMemo(() => proposedStep && proposedStepLabel
226
+ ? new Map([
227
+ [emphasisKey(proposedStep.trailId, proposedStep.step), proposedStepLabel],
228
+ ])
229
+ : undefined, [proposedStep, proposedStepLabel]);
230
+ const panelStepNumberLabels = useMemo(() => {
231
+ if (!hostStepNumberLabels)
232
+ return proposedStepNumberLabels;
233
+ if (!proposedStepNumberLabels)
234
+ return hostStepNumberLabels;
235
+ return new Map([...proposedStepNumberLabels, ...hostStepNumberLabels]);
236
+ }, [hostStepNumberLabels, proposedStepNumberLabels]);
237
+ const ghostEdgeIds = useMemo(() => {
238
+ const ids = new Set();
239
+ for (const links of ghostLinksByTrail.values()) {
240
+ for (const link of links)
241
+ ids.add(trailStepGraphEdgeId(link.previous));
242
+ }
243
+ return ids;
244
+ }, [ghostLinksByTrail]);
245
+ // Both accepted history and a staged proposal join the layout and the camera
246
+ // bounds. The sidebar still renders only the live `trails` prop.
247
+ const linkedEdgeIdsByTrail = useMemo(() => {
248
+ const map = new Map();
249
+ const add = (trailId, id) => {
250
+ const ids = map.get(trailId) ?? new Set();
251
+ ids.add(id);
252
+ map.set(trailId, ids);
253
+ };
254
+ for (const [trailId, links] of ghostLinksByTrail) {
255
+ for (const link of links)
256
+ add(trailId, trailStepGraphEdgeId(link.previous));
257
+ }
258
+ if (proposedStep) {
259
+ if (proposedEdgeId)
260
+ add(proposedStep.trailId, proposedEdgeId);
261
+ // The step being varied stays in focus beside its staged replacement,
262
+ // whichever of the two the guide currently points at.
263
+ const sourceStep = trails
264
+ ?.find((t) => t.id === proposedStep.trailId)
265
+ ?.steps[proposedStep.stepIndex];
266
+ if (sourceStep)
267
+ add(proposedStep.trailId, trailStepGraphEdgeId(sourceStep));
268
+ }
269
+ return map;
270
+ }, [ghostLinksByTrail, proposedStep, proposedEdgeId, trails]);
271
+ const layoutTrails = useMemo(() => {
272
+ let merged = trails ?? [];
273
+ if (stepHistory?.length) {
274
+ merged = merged.map((tl) => {
275
+ const links = ghostLinksByTrail.get(tl.id);
276
+ if (!links?.length)
277
+ return tl;
278
+ const steps = [...tl.steps];
279
+ // Descending order keeps earlier original indices stable when several
280
+ // steps of one trail were changed or removed in the same proposal.
281
+ for (const link of [...links].sort((a, b) => b.stepIndex - a.stepIndex)) {
282
+ // The accepted variation can already be a live row beside its
283
+ // original; never duplicate the previous step in the layout.
284
+ const previousKey = trailStepGraphEdgeId(link.previous);
285
+ if (steps.some((step) => trailStepGraphEdgeId(step) === previousKey)) {
286
+ continue;
287
+ }
288
+ const at = link.kind === 'changed'
289
+ ? Math.min(link.stepIndex + 1, steps.length)
290
+ : Math.min(link.stepIndex, steps.length);
291
+ steps.splice(at, 0, link.previous);
292
+ }
293
+ return { ...tl, steps };
294
+ });
295
+ }
296
+ if (proposedStep) {
297
+ merged = merged.map((tl) => {
298
+ if (tl.id !== proposedStep.trailId)
299
+ return tl;
300
+ const steps = [...tl.steps];
301
+ steps.splice(Math.min(proposedStep.stepIndex + 1, steps.length), 0, proposedStep.step);
302
+ return { ...tl, steps };
303
+ });
304
+ }
305
+ return merged;
306
+ }, [trails, stepHistory, ghostLinksByTrail, proposedStep]);
307
+ // Every step in a host-declared variation group stays in the focused set,
308
+ // even though the guide only names one of them as its active step. Indexes
309
+ // are resolved against `layoutTrails`, which also carries the staged step.
310
+ const variationEdgeIdsByTrail = useMemo(() => {
311
+ const map = new Map();
312
+ if (!focusedVariationStepIndexes)
313
+ return map;
314
+ for (const [trailId, indexes] of focusedVariationStepIndexes) {
315
+ const tl = layoutTrails.find((t) => t.id === trailId);
316
+ if (!tl)
317
+ continue;
318
+ const ids = new Set();
319
+ for (const index of indexes) {
320
+ const step = tl.steps[index];
321
+ if (step)
322
+ ids.add(trailStepGraphEdgeId(step));
323
+ }
324
+ if (ids.size > 0)
325
+ map.set(trailId, ids);
326
+ }
327
+ return map;
328
+ }, [focusedVariationStepIndexes, layoutTrails]);
329
+ const graphEdges = useMemo(() => deriveGraphEdges({ trails: layoutTrails }), [layoutTrails]);
201
330
  const [built, setBuilt] = useState({
202
331
  nodes: [],
203
332
  edges: [],
204
333
  absoluteRects: new Map(),
205
334
  });
335
+ // React Flow's `fitBounds` always centres the bounds. A host may need the
336
+ // diagram deliberately lower (e.g. to leave room for status chrome over the
337
+ // canvas), so recompute the same viewport and shift only its screen-space y.
338
+ const fitBoundsWithBias = useCallback((bounds, options) => {
339
+ if (!focusVerticalBiasPx ||
340
+ flowWidth <= 0 ||
341
+ flowHeight <= 0) {
342
+ void fitBounds(bounds, options);
343
+ return;
344
+ }
345
+ const viewport = getViewportForBounds(bounds, flowWidth, flowHeight, minZoom, maxZoom, options.padding);
346
+ void setViewport({ ...viewport, y: viewport.y + focusVerticalBiasPx }, { duration: options.duration });
347
+ }, [
348
+ fitBounds,
349
+ setViewport,
350
+ flowWidth,
351
+ flowHeight,
352
+ minZoom,
353
+ maxZoom,
354
+ focusVerticalBiasPx,
355
+ ]);
206
356
  const fitGraphContents = useCallback((duration = 300) => {
207
357
  const edges = built.edges.map((edge) => {
208
358
  const data = edge.data;
@@ -224,8 +374,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
224
374
  });
225
375
  return;
226
376
  }
227
- fitBounds(bounds, { padding: 0.1, duration });
228
- }, [built.absoluteRects, built.edges, fitBounds, fitView]);
377
+ fitBoundsWithBias(bounds, { padding: 0.1, duration });
378
+ }, [built.absoluteRects, built.edges, fitBoundsWithBias, fitView]);
229
379
  const [layoutReady, setLayoutReady] = useState(false);
230
380
  const transparentCanvas = canvasBackground === 'transparent';
231
381
  // Host notifications. Refs keep the callbacks out of effect deps so an
@@ -276,6 +426,10 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
276
426
  const flipFadeTimerRef = useRef(null);
277
427
  /** Set when a layout flip starts; the camera refits once layout lands. */
278
428
  const refitAfterLayoutRef = useRef(false);
429
+ /** A host-driven step focus owns the camera across frame-layout flips. */
430
+ const stepFocusActiveRef = useRef(false);
431
+ const focusEdgeIdsRef = useRef(null);
432
+ const fitFocusBoundsRef = useRef(() => { });
279
433
  /** Solo layout: only this trail's components and edges are laid out. */
280
434
  const [layoutTrailId, setLayoutTrailId] = useState(null);
281
435
  const [committedTrailId, setCommittedTrailId] = useState(null);
@@ -439,11 +593,25 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
439
593
  // Keyed on `built` as well as `layoutReady`: whichever of the two passes
440
594
  // lands last is the one that has the final positions.
441
595
  useEffect(() => {
442
- if (!layoutReady || !refitAfterLayoutRef.current)
596
+ if (!layoutReady)
443
597
  return;
598
+ // A staged proposal changes the graph's content without changing the
599
+ // layout flip keys, so the camera must re-fit whenever the new layout
600
+ // lands — not only for an animated direction/frame flip. While a step is
601
+ // focused, its edge group owns the camera; never fall back to a
602
+ // whole-graph fit here.
603
+ const shouldRefitFocus = focusEdgeIdsRef.current != null;
604
+ const shouldRefitGraph = refitAfterLayoutRef.current;
444
605
  refitAfterLayoutRef.current = false;
606
+ if (!shouldRefitFocus && !shouldRefitGraph)
607
+ return;
445
608
  requestAnimationFrame(() => {
446
- fitGraphContents(LAYOUT_FLIP_NODE_MS);
609
+ if (shouldRefitFocus && focusEdgeIdsRef.current) {
610
+ fitFocusBoundsRef.current(focusEdgeIdsRef.current);
611
+ }
612
+ else {
613
+ fitGraphContents(LAYOUT_FLIP_NODE_MS);
614
+ }
447
615
  });
448
616
  }, [built, layoutReady, fitGraphContents]);
449
617
  // Persist the choice so a model reopens the way it was left.
@@ -697,11 +865,14 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
697
865
  // edge fade like every other layout flip.
698
866
  const layoutDoc = useMemo(() => {
699
867
  if (!committedTrailId)
700
- return { components, trails };
701
- const trail = (trails ?? []).find((t) => t.id === committedTrailId);
868
+ return { components, trails: layoutTrails };
869
+ const trail = (layoutTrails ?? []).find((t) => t.id === committedTrailId);
702
870
  if (!trail)
703
871
  return { components, trails };
704
- const aliases = new Set();
872
+ // Host-local removal ghosts stay in the layout even when their steps are
873
+ // gone; otherwise accepting a removal would make the node vanish from a
874
+ // solo-focused flow instead of leaving the dim record the user asked for.
875
+ const aliases = new Set(removedComponentAliases);
705
876
  for (const step of trail.steps) {
706
877
  aliases.add(step.from);
707
878
  aliases.add(step.to);
@@ -710,7 +881,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
710
881
  components: components.filter((c) => aliases.has(c.alias)),
711
882
  trails: [trail],
712
883
  };
713
- }, [components, trails, committedTrailId]);
884
+ }, [components, layoutTrails, committedTrailId, removedComponentAliases]);
714
885
  const layoutRelations = committedTrailId ? undefined : graphifyRelations;
715
886
  const layoutKey = useMemo(() => subsystemGraphLayoutKey({
716
887
  components: layoutDoc.components,
@@ -1167,22 +1338,45 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1167
1338
  // Edge ids in trail focus (an active flow's edge set, or a single
1168
1339
  // step's edge). Used to frame the camera. `null` = no trail focus.
1169
1340
  const focusEdgeIds = useMemo(() => {
1341
+ const withLinked = (trailId, ids) => {
1342
+ for (const id of linkedEdgeIdsByTrail.get(trailId) ?? [])
1343
+ ids.add(id);
1344
+ // All variations of the focused step are one focus group: the camera and
1345
+ // dimming must treat them as a single set, not just the active step.
1346
+ for (const id of variationEdgeIdsByTrail.get(trailId) ?? [])
1347
+ ids.add(id);
1348
+ return ids;
1349
+ };
1170
1350
  if (autoPlayFocus) {
1171
1351
  const tl = trails?.find((t) => t.id === autoPlayFocus.trailId);
1172
1352
  const step = tl?.steps[autoPlayFocus.stepIndex];
1173
- return step ? new Set([trailStepGraphEdgeId(step)]) : null;
1353
+ return step
1354
+ ? withLinked(autoPlayFocus.trailId, new Set([trailStepGraphEdgeId(step)]))
1355
+ : null;
1174
1356
  }
1175
- if (focusedTrailId == null || !trails)
1357
+ if (focusedTrailId == null)
1176
1358
  return null;
1177
- const tl = trails.find((t) => t.id === focusedTrailId);
1359
+ // Host focus indexes can point at a staged step that exists only in the
1360
+ // layout trails, so resolve them there rather than in the live `trails`.
1361
+ const tl = layoutTrails.find((t) => t.id === focusedTrailId);
1178
1362
  if (!tl)
1179
1363
  return null;
1180
1364
  if (focusedStepIndex != null) {
1181
1365
  const step = tl.steps[focusedStepIndex];
1182
- return step ? new Set([trailStepGraphEdgeId(step)]) : null;
1183
- }
1184
- return new Set(tl.steps.map((s) => trailStepGraphEdgeId(s)));
1185
- }, [trails, focusedTrailId, focusedStepIndex, autoPlayFocus]);
1366
+ return step
1367
+ ? withLinked(focusedTrailId, new Set([trailStepGraphEdgeId(step)]))
1368
+ : null;
1369
+ }
1370
+ return withLinked(focusedTrailId, new Set(tl.steps.map((s) => trailStepGraphEdgeId(s))));
1371
+ }, [trails, layoutTrails, focusedTrailId, focusedStepIndex, autoPlayFocus, linkedEdgeIdsByTrail, variationEdgeIdsByTrail]);
1372
+ // Keep these refs current during render, not in a later effect: the
1373
+ // post-layout refit effect is declared above and must see the focus that
1374
+ // triggered this layout swap, or it falls back to a whole-graph fit.
1375
+ stepFocusActiveRef.current =
1376
+ autoPlayFocus == null &&
1377
+ focusedTrailId != null &&
1378
+ focusedStepIndex != null;
1379
+ focusEdgeIdsRef.current = focusEdgeIds;
1186
1380
  // 1-based step numbers per edge of the active flow (focused or
1187
1381
  // hover/autoplay-highlighted). An edge can appear in more than one step.
1188
1382
  const selectedFlowStepNos = useMemo(() => {
@@ -1210,9 +1404,11 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1210
1404
  continue;
1211
1405
  for (const s of tl.steps)
1212
1406
  ids.add(trailStepGraphEdgeId(s));
1407
+ for (const id of linkedEdgeIdsByTrail.get(tl.id) ?? [])
1408
+ ids.add(id);
1213
1409
  }
1214
1410
  return ids.size > 0 ? ids : null;
1215
- }, [trails, expandedTrails]);
1411
+ }, [trails, expandedTrails, linkedEdgeIdsByTrail]);
1216
1412
  const endpointsOf = (edgeIds) => {
1217
1413
  if (!edgeIds)
1218
1414
  return null;
@@ -1232,12 +1428,18 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1232
1428
  const tl = trails.find((t) => t.id === hoveredTrailStep.trailId);
1233
1429
  if (!tl)
1234
1430
  return null;
1431
+ const ghosts = linkedEdgeIdsByTrail.get(hoveredTrailStep.trailId) ?? [];
1235
1432
  if (hoveredTrailStep.stepIndex == null) {
1236
- return new Set(tl.steps.map((s) => trailStepGraphEdgeId(s)));
1433
+ return new Set([
1434
+ ...tl.steps.map((s) => trailStepGraphEdgeId(s)),
1435
+ ...ghosts,
1436
+ ]);
1237
1437
  }
1238
1438
  const step = tl.steps[hoveredTrailStep.stepIndex];
1239
- return step ? new Set([trailStepGraphEdgeId(step)]) : null;
1240
- }, [trails, hoveredTrailStep]);
1439
+ return step
1440
+ ? new Set([trailStepGraphEdgeId(step), ...ghosts])
1441
+ : null;
1442
+ }, [trails, hoveredTrailStep, linkedEdgeIdsByTrail]);
1241
1443
  // While hovering with a *step* already selected, brighten the union of
1242
1444
  // selected + hovered participants. Whole-flow focus (or no focus) keeps
1243
1445
  // the old hover-replace preview so a step hover still dims the rest.
@@ -1368,6 +1570,12 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1368
1570
  };
1369
1571
  }
1370
1572
  const comp = n.data?.component;
1573
+ const proposed = comp?.alias != null &&
1574
+ proposedComponentAliases?.has(comp.alias) === true;
1575
+ const working = comp?.alias != null &&
1576
+ workingComponentAliases?.has(comp.alias) === true;
1577
+ const removed = comp?.alias != null &&
1578
+ removedComponentAliases?.has(comp.alias) === true;
1371
1579
  const fileMatch = fileMatchForNode(comp?.file, openFile, focusNodeIds?.has(n.id) === true);
1372
1580
  // Bases selection on the focused step, not the hover preview, so
1373
1581
  // hovering doesn't strip the frame's `isSelected`.
@@ -1375,7 +1583,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1375
1583
  // `brightNodeIds` (the focused step's endpoints) is a spotlight member as
1376
1584
  // well as a bright set — see the group branch above.
1377
1585
  const dimSource = previewNodeIds ?? brightNodeIds ?? issueFocusNodeIds;
1378
- const { hidden, dimmed } = flowNodeVisibility({
1586
+ const flowVisibility = flowNodeVisibility({
1379
1587
  inOpened: openedNodeIds?.has(n.id) === true,
1380
1588
  inSelected: brightNodeIds?.has(n.id) === true,
1381
1589
  inSpotlight: dimSource?.has(n.id) === true || (hoverTrailAliases?.has(n.id) === true),
@@ -1383,12 +1591,22 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1383
1591
  anySelected: brightNodeIds != null,
1384
1592
  anySpotlight: dimSource != null || hoverTrailAliases != null,
1385
1593
  });
1594
+ // A removed ghost is never hidden by flow focus — the whole point is to
1595
+ // keep it visible as a dim record of what the agent took out.
1596
+ const hidden = removed ? false : flowVisibility.hidden;
1597
+ const dimmed = removed ? true : flowVisibility.dimmed;
1386
1598
  // Component findings key by alias, boundary findings by region node id.
1387
1599
  // The two id spaces are disjoint (`module:` / `process:` are prefixed), so
1388
1600
  // one lookup covers both node kinds.
1389
1601
  const issueBadge = issueBadgeByAlias.get(n.id) ?? regionIssueByNodeId.get(n.id);
1390
- if (fileMatch === undefined && !isSelected && !dimmed && !issueBadge) {
1391
- const { fileMatch: _f, isSelected: _s, dimmed: _d, ...rest } = n.data;
1602
+ if (fileMatch === undefined &&
1603
+ !isSelected &&
1604
+ !dimmed &&
1605
+ !issueBadge &&
1606
+ !proposed &&
1607
+ !working &&
1608
+ !removed) {
1609
+ const { fileMatch: _f, isSelected: _s, dimmed: _d, proposed: _p, working: _w, removed: _r, ...rest } = n.data;
1392
1610
  return { ...n, hidden, data: rest };
1393
1611
  }
1394
1612
  return {
@@ -1399,22 +1617,32 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1399
1617
  ...(fileMatch !== undefined && { fileMatch }),
1400
1618
  ...(isSelected && { isSelected }),
1401
1619
  ...(dimmed && { dimmed: true }),
1620
+ ...(proposed && { proposed: true }),
1621
+ ...(working && { working: true }),
1622
+ ...(removed && { removed: true }),
1402
1623
  ...(issueBadge && { issue: issueBadge }),
1403
1624
  },
1404
1625
  };
1405
1626
  });
1406
- }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, hoverTrailAliases, aliasToComponent, issueFocusNodeIds, issueBadgeByAlias, regionIssueByNodeId, boundaryColors, toggleCollapsed]);
1627
+ }, [xyflowNodesBase, openFile, selected, focusNodeIds, openedNodeIds, brightNodeIds, previewNodeIds, hoverTrailAliases, aliasToComponent, issueFocusNodeIds, issueBadgeByAlias, regionIssueByNodeId, boundaryColors, proposedComponentAliases, workingComponentAliases, removedComponentAliases, toggleCollapsed]);
1407
1628
  const baseNodesKey = useMemo(() => nodes.map((n) => n.id).sort().join(','), [nodes]);
1408
1629
  const baseEdgesKey = useMemo(() => convertedEdges.map((e) => e.id).sort().join(','), [convertedEdges]);
1409
1630
  const dispEdges = useMemo(() => {
1410
- const paint = (e, dimmed) => {
1631
+ const paint = (e, dimmed, proposed) => {
1411
1632
  const markerEnd = e.markerEnd;
1412
- const nextMarker = dimmed && markerEnd && typeof markerEnd === 'object' && typeof markerEnd.color === 'string'
1413
- ? { ...markerEnd, color: hexWithAlpha(markerEnd.color, EDGE_DIM_ALPHA) }
1633
+ const nextMarker = markerEnd && typeof markerEnd === 'object' && typeof markerEnd.color === 'string'
1634
+ ? {
1635
+ ...markerEnd,
1636
+ color: proposed
1637
+ ? HOST_PROPOSAL_COLOR
1638
+ : dimmed
1639
+ ? hexWithAlpha(markerEnd.color, EDGE_DIM_ALPHA)
1640
+ : markerEnd.color,
1641
+ }
1414
1642
  : markerEnd;
1415
1643
  return {
1416
1644
  ...e,
1417
- data: { ...e.data, dimmed },
1645
+ data: { ...e.data, dimmed, proposed },
1418
1646
  markerEnd: nextMarker,
1419
1647
  };
1420
1648
  };
@@ -1432,6 +1660,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1432
1660
  const inSet = (set, e) => set != null && edgeMatches(set, e);
1433
1661
  if (openedEdgeIds || focusEdgeIds || previewEdgeIds || issueFocusEdgeIds) {
1434
1662
  return baseEdges.map((e) => {
1663
+ const ghost = ghostEdgeIds.has(e.id);
1664
+ const proposed = !ghost && proposedEdgeIds.has(e.id);
1435
1665
  const vis = flowElementVisibility({
1436
1666
  inOpened: inSet(openedEdgeIds, e),
1437
1667
  inSelected: inSet(focusEdgeIds, e),
@@ -1439,19 +1669,39 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1439
1669
  anySelected: focusEdgeIds != null,
1440
1670
  });
1441
1671
  const dimSource = previewEdgeIds ?? issueFocusEdgeIds;
1442
- const dimmed = dimSource ? vis.hidden || !inSet(dimSource, e) : vis.dimmed;
1672
+ const dimmed = dimSource
1673
+ ? vis.hidden || !inSet(dimSource, e)
1674
+ : vis.dimmed || ghost;
1443
1675
  const hidden = vis.hidden || !edgeInView(e);
1444
- return { ...paint(e, dimmed), hidden };
1676
+ return {
1677
+ ...paint(e, dimmed, proposed),
1678
+ data: { ...e.data, dimmed, ghost, proposed },
1679
+ hidden,
1680
+ };
1445
1681
  });
1446
1682
  }
1447
1683
  if (selectedEdgeId) {
1448
- return baseEdges.map((e) => ({
1449
- ...paint(e, e.id !== selectedEdgeId),
1450
- hidden: !edgeInView(e),
1451
- }));
1684
+ return baseEdges.map((e) => {
1685
+ const ghost = ghostEdgeIds.has(e.id);
1686
+ const proposed = !ghost && proposedEdgeIds.has(e.id);
1687
+ const dimmed = e.id !== selectedEdgeId || ghost;
1688
+ return {
1689
+ ...paint(e, dimmed, proposed),
1690
+ data: { ...e.data, dimmed, ghost, proposed },
1691
+ hidden: !edgeInView(e),
1692
+ };
1693
+ });
1452
1694
  }
1453
- return baseEdges.map((e) => ({ ...e, hidden: !edgeInView(e) }));
1454
- }, [baseEdges, selectedEdgeId, openedEdgeIds, focusEdgeIds, previewEdgeIds, issueFocusEdgeIds, resolvedEdgeView]);
1695
+ return baseEdges.map((e) => {
1696
+ const ghost = ghostEdgeIds.has(e.id);
1697
+ const proposed = !ghost && proposedEdgeIds.has(e.id);
1698
+ return {
1699
+ ...paint(e, ghost, proposed),
1700
+ data: { ...e.data, dimmed: ghost, ghost, proposed },
1701
+ hidden: !edgeInView(e),
1702
+ };
1703
+ });
1704
+ }, [baseEdges, selectedEdgeId, openedEdgeIds, focusEdgeIds, previewEdgeIds, issueFocusEdgeIds, resolvedEdgeView, ghostEdgeIds, proposedEdgeIds]);
1455
1705
  // Gated on layoutReady so the pre-reveal Pass 1 swap never flashes a count.
1456
1706
  const unroutedIds = useMemo(() => (layoutReady ? unroutedEdgeIds(dispEdges) : []), [dispEdges, layoutReady]);
1457
1707
  const onNodesChange = useCallback((changes) => {
@@ -1475,8 +1725,9 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1475
1725
  const onEdgesChange = useCallback((_changes) => dispEdges, [dispEdges]);
1476
1726
  useEffect(() => {
1477
1727
  // A layout flip runs its own camera refit when the new layout lands. This
1478
- // mount/edit fit would otherwise fire mid-flip and fight it.
1479
- if (layoutFlipping)
1728
+ // mount/edit fit would otherwise fire mid-flip and fight it. A focused
1729
+ // step also owns the camera — a frame flip must not restore whole-graph fit.
1730
+ if (layoutFlipping || stepFocusActiveRef.current)
1480
1731
  return;
1481
1732
  const t = setTimeout(() => {
1482
1733
  fitGraphContents(200);
@@ -1688,17 +1939,20 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1688
1939
  width: Math.max(1, maxX - minX),
1689
1940
  height: Math.max(1, maxY - minY),
1690
1941
  };
1691
- fitBounds(bounds, {
1942
+ fitBoundsWithBias(bounds, {
1692
1943
  padding: 0.15,
1693
1944
  duration: trailFocusDurationMs,
1694
1945
  });
1695
1946
  }, [
1696
1947
  baseEdges,
1697
1948
  built.absoluteRects,
1698
- fitBounds,
1949
+ fitBoundsWithBias,
1699
1950
  zoomOnTrailFocus,
1700
1951
  trailFocusDurationMs,
1701
1952
  ]);
1953
+ useEffect(() => {
1954
+ fitFocusBoundsRef.current = fitFocusBounds;
1955
+ }, [fitFocusBounds]);
1702
1956
  // A node's laid-out rect in absolute flow coords. `absoluteRects` is the
1703
1957
  // authority; the fallback covers an unparented group node, whose `position` is
1704
1958
  // already absolute. Nested groups are parent-relative, so they are skipped
@@ -1738,13 +1992,13 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1738
1992
  }
1739
1993
  if (!Number.isFinite(minX) || !Number.isFinite(minY))
1740
1994
  return;
1741
- fitBounds({
1995
+ fitBoundsWithBias({
1742
1996
  x: minX,
1743
1997
  y: minY,
1744
1998
  width: Math.max(1, maxX - minX),
1745
1999
  height: Math.max(1, maxY - minY),
1746
2000
  }, { padding, duration: trailFocusDurationMs });
1747
- }, [rectForNode, fitBounds, trailFocusDurationMs]);
2001
+ }, [rectForNode, fitBoundsWithBias, trailFocusDurationMs]);
1748
2002
  // The Containers list: every card frame in the laid-out graph, parents before
1749
2003
  // their children, with the colour the canvas draws it in. Rows keep the
1750
2004
  // grouping's declaration order — the layout moves closed cards after open
@@ -1806,10 +2060,11 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1806
2060
  // frame the flow on the canvas. Selection state is cleared — the graph now
1807
2061
  // reads as the narrative. No drawer: the code view only opens on a step
1808
2062
  // click. A stale trail drawer (from a previously focused flow's step)
1809
- // closes; an explicitly opened file drawer stays.
2063
+ // closes; an explicitly opened file drawer stays unless a host asks for
2064
+ // file-free focus (e.g. a walkthrough step that only selects the trail).
1810
2065
  // In `dim` mode: clear step highlight and leave the full graph visible
1811
2066
  // (no zoom / hide) — matching "step away from a hovered step".
1812
- const focusTrailEdges = useCallback((tl) => {
2067
+ const focusTrailEdges = useCallback((tl, closeFile = false) => {
1813
2068
  setSelected(null);
1814
2069
  setSelectedEdgeId(null);
1815
2070
  setHoveredTrailStep(null);
@@ -1826,9 +2081,35 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1826
2081
  setFocusedStepIndex(null);
1827
2082
  setFocusedTrailId(tl.id);
1828
2083
  onTrailSelect?.({ trailId: tl.id });
1829
- fitFocusBounds(new Set(tl.steps.map((s) => trailStepGraphEdgeId(s))));
1830
- setDrawerTarget((prev) => (prev?.kind === 'trail' ? null : prev));
1831
- }, [fitFocusBounds, trailStepMode, onTrailSelect, onSidebarTrailChange]);
2084
+ const edgeIds = new Set([
2085
+ ...tl.steps.map((s) => trailStepGraphEdgeId(s)),
2086
+ ...(linkedEdgeIdsByTrail.get(tl.id) ?? []),
2087
+ ]);
2088
+ const drawerWillClose = drawerOpenRef.current && (closeFile || drawerTarget?.kind === 'trail');
2089
+ setDrawerTarget((prev) => closeFile || prev?.kind === 'trail' ? null : prev);
2090
+ if (pendingFocusFitRef.current != null) {
2091
+ window.clearTimeout(pendingFocusFitRef.current);
2092
+ pendingFocusFitRef.current = null;
2093
+ }
2094
+ if (drawerWillClose) {
2095
+ // Wait for the canvas to reclaim the drawer's height, or the fit uses
2096
+ // the temporarily shortened viewport and settles too far off-centre.
2097
+ pendingFocusFitRef.current = window.setTimeout(() => {
2098
+ pendingFocusFitRef.current = null;
2099
+ requestAnimationFrame(() => fitFocusBounds(edgeIds));
2100
+ }, FILE_DRAWER_HEIGHT_MS + 20);
2101
+ }
2102
+ else {
2103
+ fitFocusBounds(edgeIds);
2104
+ }
2105
+ }, [
2106
+ fitFocusBounds,
2107
+ trailStepMode,
2108
+ onTrailSelect,
2109
+ onSidebarTrailChange,
2110
+ drawerTarget,
2111
+ linkedEdgeIdsByTrail,
2112
+ ]);
1832
2113
  const clearTrailFocus = useCallback(() => {
1833
2114
  if (pendingFocusFitRef.current != null) {
1834
2115
  window.clearTimeout(pendingFocusFitRef.current);
@@ -1877,10 +2158,12 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1877
2158
  }, [initialTrailId, layoutReady, trails, focusTrailEdges]);
1878
2159
  // Focus a single step's edge on the canvas and open/scroll the trail
1879
2160
  // drawer to that step's snippet. Clicking the already-focused step clears
1880
- // step focus and returns to whole-flow (high-level) framing.
2161
+ // step focus and returns to whole-flow (high-level) framing. Host-driven
2162
+ // re-fits pass `allowToggle: false` so a newly linked before/after edge
2163
+ // cannot be mistaken for a second click on the same step.
1881
2164
  // In `dim` mode: only dim non-participants (same as hovering a step) —
1882
2165
  // no camera move, no drawer, no hide.
1883
- const focusTrailStep = useCallback((tl, stepIndex) => {
2166
+ const focusTrailStep = useCallback((tl, stepIndex, showFile = true, options) => {
1884
2167
  const step = tl.steps[stepIndex];
1885
2168
  if (!step)
1886
2169
  return;
@@ -1894,29 +2177,43 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1894
2177
  onTrailSelect?.(null);
1895
2178
  return;
1896
2179
  }
2180
+ // Opening the focused step's containing frames is what makes an
2181
+ // intra-process edge (e.g. api → store) renderable at all. Without this,
2182
+ // host-driven step focus can only frame cross-boundary hops.
2183
+ setExpandedTrails(new Set([tl.id]));
2184
+ setLayoutTrailId(tl.id);
1897
2185
  // Toggle: clicking the selected step unselects it (back to whole flow).
1898
2186
  onSidebarTrailChange(tl.id);
1899
- if (focusedTrailId === tl.id && focusedStepIndex === stepIndex) {
2187
+ if ((options?.allowToggle ?? true) &&
2188
+ focusedTrailId === tl.id &&
2189
+ focusedStepIndex === stepIndex) {
1900
2190
  setFocusedStepIndex(null);
1901
2191
  // Pointer is still over the row — keep hover preview so dimming doesn't
1902
2192
  // flash off until mouseleave.
1903
2193
  setHoveredTrailStep({ trailId: tl.id, stepIndex });
1904
- setDrawerTarget((prev) => (prev?.kind === 'trail' ? null : prev));
2194
+ setDrawerTarget((prev) => !showFile ? null : prev?.kind === 'trail' ? null : prev);
1905
2195
  if (pendingFocusFitRef.current != null) {
1906
2196
  window.clearTimeout(pendingFocusFitRef.current);
1907
2197
  pendingFocusFitRef.current = null;
1908
2198
  }
1909
- fitFocusBounds(new Set(tl.steps.map((s) => trailStepGraphEdgeId(s))));
2199
+ fitFocusBounds(new Set([
2200
+ ...tl.steps.map((s) => trailStepGraphEdgeId(s)),
2201
+ ...(linkedEdgeIdsByTrail.get(tl.id) ?? []),
2202
+ ...(variationEdgeIdsByTrail.get(tl.id) ?? []),
2203
+ ]));
1910
2204
  return;
1911
2205
  }
1912
2206
  setFocusedStepIndex(stepIndex);
1913
2207
  setFocusedTrailId(tl.id);
1914
2208
  setHoveredTrailStep(null);
1915
2209
  onTrailSelect?.({ trailId: tl.id, stepIndices: [stepIndex] });
1916
- // Open the drawer before fitting. If it was closed, wait for its height
1917
- // transition so fitView uses the reduced canvas — not full height.
2210
+ // The drawer changes the usable canvas height, so wait for its height
2211
+ // transition whenever we open or close it — not just when opening.
1918
2212
  const drawerWasOpen = drawerOpenRef.current;
1919
- if (renderTrailViewer) {
2213
+ if (!showFile) {
2214
+ setDrawerTarget(null);
2215
+ }
2216
+ else if (renderTrailViewer) {
1920
2217
  setDrawerTarget({
1921
2218
  kind: 'trail',
1922
2219
  trailId: tl.id,
@@ -1931,12 +2228,16 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1931
2228
  endLine: step.span?.endLine,
1932
2229
  });
1933
2230
  }
1934
- const edgeIds = new Set([trailStepGraphEdgeId(step)]);
2231
+ const edgeIds = new Set([
2232
+ trailStepGraphEdgeId(step),
2233
+ ...(linkedEdgeIdsByTrail.get(tl.id) ?? []),
2234
+ ...(variationEdgeIdsByTrail.get(tl.id) ?? []),
2235
+ ]);
1935
2236
  if (pendingFocusFitRef.current != null) {
1936
2237
  window.clearTimeout(pendingFocusFitRef.current);
1937
2238
  pendingFocusFitRef.current = null;
1938
2239
  }
1939
- if (drawerWasOpen) {
2240
+ if (drawerWasOpen === showFile) {
1940
2241
  fitFocusBounds(edgeIds);
1941
2242
  }
1942
2243
  else {
@@ -1953,6 +2254,66 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
1953
2254
  trailStepMode,
1954
2255
  onTrailSelect,
1955
2256
  onSidebarTrailChange,
2257
+ linkedEdgeIdsByTrail,
2258
+ variationEdgeIdsByTrail,
2259
+ ]);
2260
+ // Host-controlled trail focus for agent-driven walkthroughs. Unlike
2261
+ // `initialTrailId`, this is repeatable. A `stepIndex` focuses one step;
2262
+ // omitting it frames the whole trail. `showFile: false` selects without
2263
+ // opening the file/trail drawer. `undefined` leaves graph-owned focus alone;
2264
+ // `null` hands control back to the graph.
2265
+ const appliedFocusedTrailStepRef = useRef(null);
2266
+ useEffect(() => {
2267
+ if (focusedTrailStep === undefined)
2268
+ return;
2269
+ if (focusedTrailStep === null) {
2270
+ if (appliedFocusedTrailStepRef.current == null)
2271
+ return;
2272
+ appliedFocusedTrailStepRef.current = null;
2273
+ clearTrailFocus();
2274
+ return;
2275
+ }
2276
+ const { trailId, stepIndex } = focusedTrailStep;
2277
+ const showFile = focusedTrailStep.showFile ?? stepIndex != null;
2278
+ // A step's before/after links can arrive after the step itself (an agent
2279
+ // proposes, then commits). Include them in the key so the same focus is
2280
+ // re-fit when the staged or previous state joins the layout.
2281
+ const linkedKey = Array.from(linkedEdgeIdsByTrail.get(trailId) ?? [])
2282
+ .sort()
2283
+ .join(',');
2284
+ const variationKey = Array.from(focusedVariationStepIndexes?.get(trailId) ?? [])
2285
+ .sort((a, b) => a - b)
2286
+ .join(',');
2287
+ const key = `${trailId}:${stepIndex ?? 'trail'}:${showFile ? 'file' : 'nofile'}:${linkedKey}:${variationKey}`;
2288
+ if (appliedFocusedTrailStepRef.current === key)
2289
+ return;
2290
+ if (!layoutReady || !trails?.length)
2291
+ return;
2292
+ // A guide step may point at a staged variation that only exists in the
2293
+ // layout trails; resolve focus there so it never silently falls back to
2294
+ // the step it replaces.
2295
+ const tl = layoutTrails.find((t) => t.id === trailId);
2296
+ if (!tl)
2297
+ return;
2298
+ if (stepIndex != null && !tl.steps[stepIndex])
2299
+ return;
2300
+ appliedFocusedTrailStepRef.current = key;
2301
+ if (stepIndex == null) {
2302
+ focusTrailEdges(tl, !showFile);
2303
+ }
2304
+ else {
2305
+ focusTrailStep(tl, stepIndex, showFile, { allowToggle: false });
2306
+ }
2307
+ }, [
2308
+ focusedTrailStep,
2309
+ layoutReady,
2310
+ trails,
2311
+ focusTrailEdges,
2312
+ focusTrailStep,
2313
+ clearTrailFocus,
2314
+ linkedEdgeIdsByTrail,
2315
+ focusedVariationStepIndexes,
2316
+ layoutTrails,
1956
2317
  ]);
1957
2318
  useEffect(() => {
1958
2319
  return () => {
@@ -2322,7 +2683,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2322
2683
  if (e.hidden)
2323
2684
  return false;
2324
2685
  const d = e?.data;
2325
- return !d?.dimmed;
2686
+ return !d?.dimmed || d?.ghost || d?.proposed;
2326
2687
  })
2327
2688
  .map((e) => {
2328
2689
  const d = e.data;
@@ -2332,6 +2693,8 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2332
2693
  mechanism: d?.mechanism ?? 'uses',
2333
2694
  provenance: d?.provenance,
2334
2695
  dimmed: d?.dimmed === true,
2696
+ ghost: d?.ghost === true,
2697
+ proposed: d?.proposed === true,
2335
2698
  midX: d?.labelX ?? 0,
2336
2699
  midY: d?.labelY ?? 0,
2337
2700
  pathLength: d?.pathLength ?? 0,
@@ -2380,7 +2743,22 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2380
2743
  if (file)
2381
2744
  onOpenDeclarationFile(file);
2382
2745
  } })) : null;
2383
- const trailNavigation = trails && trails.length > 0 ? (_jsx(TrailsPanel, { drilldown: trailStepMode !== 'dim', trails: trails, expandedTrails: expandedTrails, focusedTrailId: sidebarTrail?.id ?? focusedTrailId, focusedStepIndex: !sidebarTrail || focusedTrailId === sidebarTrail.id ? focusedStepIndex : null, detailContent: sidebarPanel, hoveredTrailStep: hoveredTrailStep, onToggleCollapsed: toggleTrailCollapsed, onFocusFlow: focusTrailEdges, onClearFocus: clearTrailFocus, onFocusStep: focusTrailStep, onHoverStep: (tl, i) => {
2746
+ // The staged variation is a graph-layout row only. In the panel it has no
2747
+ // row, so its index would highlight the next real step instead.
2748
+ const panelFocusedVariationStepIndexes = useMemo(() => {
2749
+ if (!focusedVariationStepIndexes || !proposedStep) {
2750
+ return focusedVariationStepIndexes;
2751
+ }
2752
+ const stagedIndex = proposedStep.stepIndex + 1;
2753
+ const map = new Map();
2754
+ for (const [trailId, indexes] of focusedVariationStepIndexes) {
2755
+ const panelIndexes = new Set([...indexes].filter((index) => trailId !== proposedStep.trailId || index !== stagedIndex));
2756
+ if (panelIndexes.size)
2757
+ map.set(trailId, panelIndexes);
2758
+ }
2759
+ return map;
2760
+ }, [focusedVariationStepIndexes, proposedStep]);
2761
+ const trailNavigation = trails && trails.length > 0 ? (_jsx(TrailsPanel, { drilldown: trailStepMode !== 'dim', trails: trails, expandedTrails: expandedTrails, focusedTrailId: sidebarTrail?.id ?? focusedTrailId, focusedStepIndex: !sidebarTrail || focusedTrailId === sidebarTrail.id ? focusedStepIndex : null, proposedTrailIds: proposedTrailIds, proposedStepKeys: proposedStepKeys, focusedVariationStepIndexes: panelFocusedVariationStepIndexes, stepNumberLabels: panelStepNumberLabels, stepChange: stepChange, detailContent: sidebarPanel, hoveredTrailStep: hoveredTrailStep, onToggleCollapsed: toggleTrailCollapsed, onFocusFlow: focusTrailEdges, onClearFocus: clearTrailFocus, onFocusStep: focusTrailStep, onHoverStep: (tl, i) => {
2384
2762
  cancelPendingHoverLeave();
2385
2763
  setHoveredTrailStep({ trailId: tl.id, stepIndex: i });
2386
2764
  onTrailStepHover?.({ trailId: tl.id, stepIndex: i });
@@ -2440,7 +2818,9 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2440
2818
  }, children: edgeLabels.map((lbl) => {
2441
2819
  const mechanism = lbl.mechanism;
2442
2820
  const isGraphify = lbl.provenance === 'graphify';
2443
- const color = edgeColor({ mechanism, provenance: lbl.provenance });
2821
+ const color = lbl.proposed
2822
+ ? HOST_PROPOSAL_COLOR
2823
+ : edgeColor({ mechanism, provenance: lbl.provenance });
2444
2824
  // Label chrome stays the crisp rounded box for every edge — graphify
2445
2825
  // provenance is carried by hue (GRAPHIFY_RELATION_COLOR), the dashed
2446
2826
  // stroke, and the tooltip, NOT by the "ambiguous" cloud silhouette
@@ -2453,9 +2833,13 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2453
2833
  : undefined;
2454
2834
  const screenX = lbl.midX * viewport.zoom + viewport.x;
2455
2835
  const screenY = lbl.midY * viewport.zoom + viewport.y;
2456
- const text = lbl.stepNos?.length
2457
- ? `${lbl.stepNos.map((n) => `${n}:`).join(' ')} ${lbl.mechanism}`
2458
- : lbl.mechanism;
2836
+ const text = lbl.ghost
2837
+ ? `was ${lbl.mechanism}`
2838
+ : lbl.proposed
2839
+ ? `${proposedStepLabel ? `${proposedStepLabel}: ` : ''}${lbl.mechanism}`
2840
+ : lbl.stepNos?.length
2841
+ ? `${lbl.stepNos.map((n) => `${n}:`).join(' ')} ${lbl.mechanism}`
2842
+ : lbl.mechanism;
2459
2843
  return (_jsxs("div", { "data-edge-label": lbl.id, title: labelTitle, onClick: (e) => {
2460
2844
  e.stopPropagation();
2461
2845
  selectEdge(lbl.id);
@@ -2477,7 +2861,7 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2477
2861
  padding: '7px 8px',
2478
2862
  cursor: 'pointer',
2479
2863
  pointerEvents: 'auto',
2480
- opacity: lbl.dimmed ? 0.15 : 1,
2864
+ opacity: lbl.ghost ? 0.5 : lbl.proposed ? 1 : lbl.dimmed ? 0.15 : 1,
2481
2865
  }, children: [verifiable ? (_jsx("span", { "aria-hidden": true, style: {
2482
2866
  position: 'absolute',
2483
2867
  inset: 0,
@@ -2806,7 +3190,7 @@ export function SubsystemComponentGraph(props) {
2806
3190
  minHeight: 0,
2807
3191
  display: 'flex',
2808
3192
  flexDirection: 'column',
2809
- }, children: [!constructsOnly && !props.hideSidebar && (_jsxs("header", { style: {
3193
+ }, children: [!constructsOnly && !props.hideSidebar && !props.hideHeader && (_jsxs("header", { style: {
2810
3194
  flexShrink: 0,
2811
3195
  display: 'flex',
2812
3196
  alignItems: 'center',