@principal-ai/subsystems-react 0.56.17 → 0.56.19

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 (32) hide show
  1. package/dist/pierre/PierreFileView.js +2 -2
  2. package/dist/pierre/PierreFileView.js.map +1 -1
  3. package/dist/pierre/PierreSnippetView.js +2 -2
  4. package/dist/pierre/PierreSnippetView.js.map +1 -1
  5. package/dist/pierre/PierreTrailCodeView.d.ts.map +1 -1
  6. package/dist/pierre/PierreTrailCodeView.js +3 -2
  7. package/dist/pierre/PierreTrailCodeView.js.map +1 -1
  8. package/dist/pierre/pierreBackground.d.ts +4 -2
  9. package/dist/pierre/pierreBackground.d.ts.map +1 -1
  10. package/dist/pierre/pierreBackground.js +4 -3
  11. package/dist/pierre/pierreBackground.js.map +1 -1
  12. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  13. package/dist/subsystem/SubsystemComponentGraph.js +24 -2
  14. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  15. package/dist/subsystem/model.d.ts +13 -0
  16. package/dist/subsystem/model.d.ts.map +1 -1
  17. package/dist/subsystem/model.js +34 -0
  18. package/dist/subsystem/model.js.map +1 -1
  19. package/dist/utils/elkLayout.d.ts +2 -1
  20. package/dist/utils/elkLayout.d.ts.map +1 -1
  21. package/dist/utils/elkLayout.js +18 -13
  22. package/dist/utils/elkLayout.js.map +1 -1
  23. package/package.json +2 -2
  24. package/src/pierre/PierreFileView.tsx +2 -2
  25. package/src/pierre/PierreSnippetView.tsx +2 -2
  26. package/src/pierre/PierreTrailCodeView.tsx +3 -2
  27. package/src/pierre/pierreBackground.test.ts +46 -0
  28. package/src/pierre/pierreBackground.ts +6 -1
  29. package/src/subsystem/SubsystemComponentGraph.tsx +27 -2
  30. package/src/subsystem/model.test.ts +35 -0
  31. package/src/subsystem/model.ts +42 -0
  32. package/src/utils/elkLayout.ts +21 -13
@@ -0,0 +1,46 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import {
3
+ buildBackgroundCSS,
4
+ buildPierreOptions,
5
+ PIERRE_BASE_OPTIONS,
6
+ } from './pierreBackground';
7
+
8
+ describe('Pierre chrome colors', () => {
9
+ test.each([
10
+ { background: '#181818', text: '#eeeeee', textSecondary: '#999999' },
11
+ { background: '#ffffff', text: '#222222', textSecondary: '#666666' },
12
+ ])('uses host colors without replacing syntax foregrounds (%j)', (colors) => {
13
+ const options = buildPierreOptions(
14
+ colors.background,
15
+ { color: colors.text },
16
+ colors.textSecondary,
17
+ );
18
+ const css = 'unsafeCSS' in options ? options.unsafeCSS : '';
19
+
20
+ expect(css).toContain(`--diffs-light-bg: ${colors.background};`);
21
+ expect(css).toContain(`--diffs-dark-bg: ${colors.background};`);
22
+ expect(css).toContain(`--diffs-fg-number-override: ${colors.textSecondary};`);
23
+ expect(css).toContain(`[data-diffs-header] {\n color: ${colors.text};`);
24
+ expect(css).not.toContain('--diffs-light:');
25
+ expect(css).not.toContain('--diffs-dark:');
26
+ expect(css).not.toContain('--diffs-fg:');
27
+ });
28
+
29
+ test('keeps Pierre number colors when no override is supplied', () => {
30
+ expect(buildBackgroundCSS('#181818')).not.toContain('--diffs-fg-number-override');
31
+ expect(buildPierreOptions()).toBe(PIERRE_BASE_OPTIONS);
32
+ });
33
+
34
+ test('preserves header layout overrides alongside colors', () => {
35
+ const css = buildBackgroundCSS(
36
+ '#181818',
37
+ { background: '#222222', color: '#eeeeee', fontSize: '12px', lineHeight: '1.15', padding: '2px 8px' },
38
+ '#999999',
39
+ );
40
+
41
+ expect(css).toContain('background: #222222;');
42
+ expect(css).toContain('font-size: 12px;');
43
+ expect(css).toContain('line-height: 1.15;');
44
+ expect(css).toContain('padding: 2px 8px;');
45
+ });
46
+ });
@@ -22,6 +22,8 @@ export const PIERRE_BASE_OPTIONS = {
22
22
 
23
23
  /** Chrome overrides for the per-file header (`[data-diffs-header]`). */
24
24
  export interface PierreHeaderStyle {
25
+ /** Foreground for the header path and icon. */
26
+ color?: string;
25
27
  /** Fill behind the header row. */
26
28
  background?: string;
27
29
  /** Rule under the header row. */
@@ -58,6 +60,7 @@ export interface PierreHeaderStyle {
58
60
  export function buildBackgroundCSS(
59
61
  background: string,
60
62
  header?: PierreHeaderStyle,
63
+ lineNumberColor?: string,
61
64
  ): string {
62
65
  const headerDeclarations = header
63
66
  ? Object.entries(header)
@@ -69,6 +72,7 @@ export function buildBackgroundCSS(
69
72
  :host {
70
73
  --diffs-light-bg: ${background};
71
74
  --diffs-dark-bg: ${background};
75
+ ${lineNumberColor ? `--diffs-fg-number-override: ${lineNumberColor};` : ''}
72
76
  background: ${background} !important;
73
77
  }
74
78
  ${
@@ -88,10 +92,11 @@ function kebab(property: string): string {
88
92
  export function buildPierreOptions(
89
93
  background?: string,
90
94
  header?: PierreHeaderStyle,
95
+ lineNumberColor?: string,
91
96
  ) {
92
97
  if (!background) return PIERRE_BASE_OPTIONS;
93
98
  return {
94
99
  ...PIERRE_BASE_OPTIONS,
95
- unsafeCSS: buildBackgroundCSS(background, header),
100
+ unsafeCSS: buildBackgroundCSS(background, header, lineNumberColor),
96
101
  };
97
102
  }
@@ -91,7 +91,7 @@ import { FileDrawer, FILE_DRAWER_HEIGHT_MS } from './FileDrawer';
91
91
  import { GraphWithSidebar } from './GraphWithSidebar';
92
92
  import { DescriptionOverlay } from './DescriptionOverlay';
93
93
  import type { GraphSidebarTab } from './GraphSidebar';
94
- import { TrailsPanel, TRAIL_PLAY_PAUSE_MS } from './TrailsPanel';
94
+ import { TrailsPanel, TRAIL_PLAY_PAUSE_MS, TRAIL_HOVER_PREVIEW_MS } from './TrailsPanel';
95
95
  import type { StepEmphasisMap } from './stepEmphasis';
96
96
  import {
97
97
  EDGE_LABEL_WIDTH,
@@ -815,6 +815,29 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
815
815
  trailId: string;
816
816
  stepIndex: number | null;
817
817
  } | null>(null);
818
+ // Each trail row delays its hover preview by TRAIL_HOVER_PREVIEW_MS but
819
+ // reports mouseleave at once, so crossing from one row to the next would
820
+ // clear the preview and flash the whole graph bright before the next row's
821
+ // preview lands. The clear waits the same beat and is dropped if any newer
822
+ // preview (hover, focus, autoplay) has replaced the one being left.
823
+ const hoverLeaveTimerRef = useRef<number | null>(null);
824
+ const cancelPendingHoverLeave = useCallback(() => {
825
+ if (hoverLeaveTimerRef.current != null) {
826
+ window.clearTimeout(hoverLeaveTimerRef.current);
827
+ hoverLeaveTimerRef.current = null;
828
+ }
829
+ }, []);
830
+ const scheduleHoverLeave = useCallback(
831
+ (leaving: typeof hoveredTrailStep) => {
832
+ cancelPendingHoverLeave();
833
+ hoverLeaveTimerRef.current = window.setTimeout(() => {
834
+ hoverLeaveTimerRef.current = null;
835
+ setHoveredTrailStep((prev) => (prev === leaving ? null : prev));
836
+ }, TRAIL_HOVER_PREVIEW_MS);
837
+ },
838
+ [cancelPendingHoverLeave],
839
+ );
840
+ useEffect(() => () => cancelPendingHoverLeave(), [cancelPendingHoverLeave]);
818
841
  // Diagnostics area tab: issues list vs the Maintain agent pipeline.
819
842
  const [diagnosticsTab, setDiagnosticsTab] = useState<'issues' | 'agents'>(
820
843
  () => persisted.diagnosticsTab ?? 'issues',
@@ -2821,15 +2844,17 @@ function Inner({ components, trails, graphifyRelations, orderByLine, layoutDirec
2821
2844
  onClearFocus={clearTrailFocus}
2822
2845
  onFocusStep={focusTrailStep}
2823
2846
  onHoverStep={(tl, i) => {
2847
+ cancelPendingHoverLeave();
2824
2848
  setHoveredTrailStep({ trailId: tl.id, stepIndex: i });
2825
2849
  onTrailStepHover?.({ trailId: tl.id, stepIndex: i });
2826
2850
  }}
2827
2851
  onHoverFlow={(tl) => {
2852
+ cancelPendingHoverLeave();
2828
2853
  setHoveredTrailStep({ trailId: tl.id, stepIndex: null });
2829
2854
  onTrailStepHover?.(null);
2830
2855
  }}
2831
2856
  onLeaveStep={() => {
2832
- setHoveredTrailStep(null);
2857
+ scheduleHoverLeave(hoveredTrailStep);
2833
2858
  onTrailStepHover?.(null);
2834
2859
  }}
2835
2860
  onReorder={onReorderTrails}
@@ -43,6 +43,7 @@ import {
43
43
  describeConstructBreakdown,
44
44
  reorderTrails,
45
45
  reorderTargetIndex,
46
+ trailLayoutOrder,
46
47
  } from './model';
47
48
  import type { SubsystemComponent, SubsystemComponentEdge, SubsystemTrail } from './model';
48
49
 
@@ -1123,6 +1124,40 @@ describe('reorderTrails', () => {
1123
1124
  });
1124
1125
  });
1125
1126
 
1127
+ describe('trailLayoutOrder', () => {
1128
+ const trails: SubsystemTrail[] = [
1129
+ {
1130
+ id: 't1',
1131
+ title: 'T1',
1132
+ steps: [
1133
+ { from: 'c', to: 'd', mechanism: 'call' },
1134
+ { from: 'd', to: 'a', mechanism: 'call' },
1135
+ ],
1136
+ },
1137
+ { id: 't2', title: 'T2', steps: [{ from: 'b', to: 'ext', mechanism: 'http' }] },
1138
+ ];
1139
+
1140
+ test('ranks aliases by first appearance across trails, then the rest in given order', () => {
1141
+ const order = trailLayoutOrder(trails, ['a', 'b', 'c', 'd', 'e', 'external:ext']);
1142
+ expect([...order.entries()]).toEqual([
1143
+ ['c', 0],
1144
+ ['d', 1],
1145
+ ['a', 2],
1146
+ ['b', 3],
1147
+ ['external:ext', 4],
1148
+ ['e', 5],
1149
+ ]);
1150
+ });
1151
+
1152
+ test('skips trail aliases the graph does not draw and keeps ranks dense', () => {
1153
+ const order = trailLayoutOrder(trails, ['a', 'd']);
1154
+ expect([...order.entries()]).toEqual([['d', 0], ['a', 1]]);
1155
+ });
1156
+
1157
+ test('no trails: plain given order', () => {
1158
+ expect([...trailLayoutOrder(undefined, ['y', 'x']).entries()]).toEqual([['y', 0], ['x', 1]]);
1159
+ });
1160
+ });
1126
1161
  describe('reorderTargetIndex', () => {
1127
1162
  // Boundaries are the n+1 gaps between rows: 0 is above row 0, n is below
1128
1163
  // the last row. Dragging row `from` to boundary `b` lands it at b, minus one
@@ -1144,6 +1144,12 @@ export interface SubsystemGraphNodeData extends Record<string, unknown> {
1144
1144
  dimmed?: boolean;
1145
1145
  /** Diagnostics badge — see `SubsystemNodeIssue`. Absent when no findings. */
1146
1146
  issue?: SubsystemNodeIssue;
1147
+ /**
1148
+ * Preferred rank among same-layer nodes (lower = earlier along the cross
1149
+ * axis). Set by the layout from trail order; ELK may still deviate to avoid
1150
+ * crossings.
1151
+ */
1152
+ layoutOrder?: number;
1147
1153
  }
1148
1154
 
1149
1155
  /**
@@ -1801,6 +1807,33 @@ export function convertSubsystemToGroups(
1801
1807
  }));
1802
1808
  }
1803
1809
 
1810
+ /**
1811
+ * Rank node ids for same-layer ordering: every alias in first-appearance order
1812
+ * across the trails' steps (`from` before `to`, trail by trail), then any
1813
+ * remaining id in the order given. Ids the trails name but the graph lacks are
1814
+ * skipped so ranks stay dense.
1815
+ */
1816
+ export function trailLayoutOrder(
1817
+ trails: readonly SubsystemTrail[] | undefined,
1818
+ nodeIds: readonly string[],
1819
+ ): Map<string, number> {
1820
+ const known = new Set(nodeIds);
1821
+ const order = new Map<string, number>();
1822
+ const rank = (alias: string) => {
1823
+ // A target that is not a component is drawn as an `external:` stub.
1824
+ const id = known.has(alias) ? alias : `external:${alias}`;
1825
+ if (known.has(id) && !order.has(id)) order.set(id, order.size);
1826
+ };
1827
+ for (const trail of trails ?? []) {
1828
+ for (const step of trail.steps) {
1829
+ rank(step.from);
1830
+ rank(step.to);
1831
+ }
1832
+ }
1833
+ for (const id of nodeIds) rank(id);
1834
+ return order;
1835
+ }
1836
+
1804
1837
  /**
1805
1838
  * Convert a subsystem graph document into React Flow edges. Edges whose target
1806
1839
  * is an external label (not a component alias) point at a synthetic stub so the
@@ -2028,6 +2061,15 @@ export async function buildSubsystemGraph(
2028
2061
  }
2029
2062
  }
2030
2063
 
2064
+ // Same-layer order follows the trails: a component ranks by the first step
2065
+ // that mentions it, so a trail reads top-to-bottom (or left-to-right) as it
2066
+ // fans out. Components no trail touches follow in declaration order.
2067
+ const order = trailLayoutOrder(doc.trails, nodes.map((n) => n.id));
2068
+ for (const n of nodes) {
2069
+ const rank = order.get(n.id);
2070
+ if (rank !== undefined) (n.data as SubsystemGraphNodeData).layoutOrder = rank;
2071
+ }
2072
+
2031
2073
  // ELK auto-layout: nested compound parents (process → module → leaves).
2032
2074
  let placedNodes = nodes;
2033
2075
  let labelPositions = new Map<string, { x: number; y: number }>();
@@ -103,7 +103,8 @@ export interface ElkLayoutOptions {
103
103
  /**
104
104
  * Order same-layer nodes by their source line (ascending) instead of leaving
105
105
  * it to the crossing-minimizer. Nodes must carry a `data.component.line`
106
- * (used when set; nodes without one keep ELK's neutral ordering). Off by
106
+ * (used when set; nodes without one keep ELK's neutral ordering). A
107
+ * `data.layoutOrder` number on a node always wins over the line. Off by
107
108
  * default — the generic layered layout is tuned for crossings, and line order
108
109
  * only makes sense for graphs that model a source region top-to-bottom.
109
110
  * @default false
@@ -503,8 +504,8 @@ export function getElkOptions(options: ElkLayoutOptions): LayoutOptions {
503
504
  const baseOptions: LayoutOptions = {
504
505
  'elk.algorithm': 'layered',
505
506
  'elk.direction': direction,
506
- // Keep same-layer ordering stable (not reversed / randomized) so a
507
- // line-ordered rewrite or ELK's own ordering is predictable.
507
+ // Honour per-node `elk.position` hints (see `computeElkLayout`) as the
508
+ // preferred same-layer order; the sweep may still deviate to cut crossings.
508
509
  'elk.layered.crossingMinimization.semiInteractive': 'true',
509
510
  // Spacing
510
511
  'elk.spacing.nodeNode': String(nodeSpacing),
@@ -530,9 +531,7 @@ export function getElkOptions(options: ElkLayoutOptions): LayoutOptions {
530
531
  'elk.layered.thoroughness': '50',
531
532
  };
532
533
 
533
- // Model order (position hints) so a per-node `data.line` can drive same-layer
534
- // ordering. ELK honours the `y` of each node as a position hint against the
535
- // model order.
534
+ // Line order also wants model order respected where positions tie.
536
535
  if (orderByLine) {
537
536
  baseOptions['elk.layered.fixedAlignment'] = 'NONE';
538
537
  baseOptions['elk.layered.considerModelOrder.strategy'] = 'NODES_AND_EDGES';
@@ -807,12 +806,20 @@ export async function computeElkLayout(
807
806
  const nd = node.data as { component?: { layer?: number }; layer?: number } | undefined;
808
807
  layer = nd?.layer ?? nd?.component?.layer;
809
808
 
810
- // Optional source-line ordering: seed each node's `y` hint from its line so
811
- // ELK's model-order placement puts lower lines further down within a layer.
812
- let y = node.position.y;
813
- if (orderByLine) {
814
- const line = (node.data as { component?: { line?: number } } | undefined)?.component?.line;
815
- if (typeof line === 'number') y = line;
809
+ // Same-layer order hint. Semi-interactive crossing minimization reads the
810
+ // `elk.position` PROPERTY, not the node's x/y coordinates, so a hint only
811
+ // takes effect when written there. `data.layoutOrder` is an explicit rank
812
+ // from the caller; `orderByLine` falls back to the component's line. Nodes
813
+ // with neither get no property and keep ELK's own ordering. The same value
814
+ // goes on both axes so the hint reads the same whichever axis the layout
815
+ // direction makes the in-layer one.
816
+ let orderHint: number | undefined;
817
+ const hintData = node.data as
818
+ | { layoutOrder?: number; component?: { line?: number } }
819
+ | undefined;
820
+ if (typeof hintData?.layoutOrder === 'number') orderHint = hintData.layoutOrder;
821
+ else if (orderByLine && typeof hintData?.component?.line === 'number') {
822
+ orderHint = hintData.component.line;
816
823
  }
817
824
 
818
825
  return {
@@ -820,11 +827,12 @@ export async function computeElkLayout(
820
827
  width,
821
828
  height,
822
829
  x: node.position.x,
823
- y,
830
+ y: node.position.y,
824
831
  // Add ports on each side for edge connections
825
832
  ports: cardinalPorts(node.id),
826
833
  properties: {
827
834
  'portConstraints': 'FIXED_SIDE',
835
+ ...(orderHint !== undefined ? { 'elk.position': `(${orderHint},${orderHint})` } : {}),
828
836
  ...(layer !== undefined ? { 'layering.layer': String(layer) } : {}),
829
837
  ...(partitionByNode ? { partition: String(partitionByNode.get(node.id) ?? 0) } : {}),
830
838
  },