pmx-canvas 0.1.15 → 0.1.17

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 (48) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/Readme.md +2 -2
  3. package/dist/canvas/global.css +25 -0
  4. package/dist/canvas/index.js +72 -72
  5. package/dist/types/client/canvas/AnnotationLayer.d.ts +4 -0
  6. package/dist/types/client/canvas/CanvasViewport.d.ts +4 -1
  7. package/dist/types/client/canvas/use-pan-zoom.d.ts +2 -1
  8. package/dist/types/client/icons.d.ts +4 -0
  9. package/dist/types/client/nodes/ContextNode.d.ts +11 -2
  10. package/dist/types/client/nodes/StatusNode.d.ts +1 -0
  11. package/dist/types/client/state/canvas-store.d.ts +22 -3
  12. package/dist/types/client/state/intent-bridge.d.ts +2 -0
  13. package/dist/types/client/types.d.ts +20 -0
  14. package/dist/types/mcp/canvas-access.d.ts +1 -0
  15. package/dist/types/server/canvas-serialization.d.ts +23 -1
  16. package/dist/types/server/canvas-state.d.ts +27 -1
  17. package/dist/types/server/index.d.ts +7 -2
  18. package/dist/types/server/mutation-history.d.ts +1 -1
  19. package/dist/types/server/spatial-analysis.d.ts +11 -2
  20. package/package.json +1 -1
  21. package/skills/pmx-canvas/SKILL.md +17 -0
  22. package/src/cli/agent.ts +6 -0
  23. package/src/client/App.tsx +60 -3
  24. package/src/client/canvas/AnnotationLayer.tsx +28 -0
  25. package/src/client/canvas/CanvasViewport.tsx +169 -10
  26. package/src/client/canvas/ContextPinBar.tsx +3 -1
  27. package/src/client/canvas/DockedNode.tsx +4 -3
  28. package/src/client/canvas/use-pan-zoom.ts +10 -5
  29. package/src/client/icons.tsx +22 -0
  30. package/src/client/nodes/ContextNode.tsx +128 -6
  31. package/src/client/nodes/StatusNode.tsx +16 -1
  32. package/src/client/nodes/StatusSummary.tsx +2 -1
  33. package/src/client/state/canvas-store.ts +65 -7
  34. package/src/client/state/intent-bridge.ts +5 -1
  35. package/src/client/state/sse-bridge.ts +36 -2
  36. package/src/client/theme/global.css +25 -0
  37. package/src/client/types.ts +17 -0
  38. package/src/mcp/canvas-access.ts +10 -0
  39. package/src/mcp/server.ts +35 -4
  40. package/src/server/canvas-schema.ts +25 -0
  41. package/src/server/canvas-serialization.ts +69 -1
  42. package/src/server/canvas-state.ts +74 -2
  43. package/src/server/diagram-presets.ts +54 -19
  44. package/src/server/index.ts +20 -3
  45. package/src/server/mutation-history.ts +2 -0
  46. package/src/server/server.ts +101 -3
  47. package/src/server/spatial-analysis.ts +46 -1
  48. package/src/shared/semantic-attention.ts +4 -2
@@ -20,16 +20,20 @@ import {
20
20
  draggingEdge,
21
21
  edges,
22
22
  expandedNodeId,
23
+ annotations,
23
24
  nodes,
24
25
  selectNodes,
25
26
  setViewport,
26
27
  viewport,
28
+ createAnnotationFromClient,
29
+ removeAnnotationFromClient,
27
30
  } from '../state/canvas-store';
28
31
  import { createEdgeFromClient, createNodeFromClient } from '../state/intent-bridge';
29
- import type { CanvasNodeState } from '../types';
32
+ import type { CanvasAnnotation, CanvasNodeState } from '../types';
30
33
  import { FocusFieldLayer } from './FocusFieldLayer';
31
34
  import { CanvasNode } from './CanvasNode';
32
35
  import { EdgeLayer } from './EdgeLayer';
36
+ import { AnnotationLayer } from './AnnotationLayer';
33
37
  import { activeGuides } from './snap-guides';
34
38
  import { usePanZoom } from './use-pan-zoom';
35
39
 
@@ -70,6 +74,45 @@ function renderNodeContent(node: CanvasNodeState) {
70
74
  }
71
75
  }
72
76
 
77
+ function distanceToSegment(
78
+ point: { x: number; y: number },
79
+ start: { x: number; y: number },
80
+ end: { x: number; y: number },
81
+ ): number {
82
+ const dx = end.x - start.x;
83
+ const dy = end.y - start.y;
84
+ const lengthSquared = dx * dx + dy * dy;
85
+ if (lengthSquared === 0) return Math.hypot(point.x - start.x, point.y - start.y);
86
+ const t = Math.max(0, Math.min(1, ((point.x - start.x) * dx + (point.y - start.y) * dy) / lengthSquared));
87
+ return Math.hypot(point.x - (start.x + t * dx), point.y - (start.y + t * dy));
88
+ }
89
+
90
+ function findAnnotationAtPoint(
91
+ annotationList: CanvasAnnotation[],
92
+ point: { x: number; y: number },
93
+ hitRadius: number,
94
+ ): CanvasAnnotation | null {
95
+ for (let i = annotationList.length - 1; i >= 0; i--) {
96
+ const annotation = annotationList[i];
97
+ if (!annotation) continue;
98
+ const pad = hitRadius + annotation.width;
99
+ if (
100
+ point.x < annotation.bounds.x - pad ||
101
+ point.x > annotation.bounds.x + annotation.bounds.width + pad ||
102
+ point.y < annotation.bounds.y - pad ||
103
+ point.y > annotation.bounds.y + annotation.bounds.height + pad
104
+ ) continue;
105
+ for (let index = 1; index < annotation.points.length; index++) {
106
+ const start = annotation.points[index - 1];
107
+ const end = annotation.points[index];
108
+ if (start && end && distanceToSegment(point, start, end) <= hitRadius + annotation.width / 2) {
109
+ return annotation;
110
+ }
111
+ }
112
+ }
113
+ return null;
114
+ }
115
+
73
116
  interface LassoRect {
74
117
  startX: number;
75
118
  startY: number;
@@ -77,9 +120,27 @@ interface LassoRect {
77
120
  currentY: number;
78
121
  }
79
122
 
123
+ interface AnnotationDraft {
124
+ id: string;
125
+ type: 'freehand';
126
+ points: Array<{ x: number; y: number }>;
127
+ bounds: { x: number; y: number; width: number; height: number };
128
+ color: string;
129
+ width: number;
130
+ createdAt: string;
131
+ }
132
+
133
+ const ANNOTATION_COLOR = 'currentColor';
134
+ const ANNOTATION_WIDTH = 4;
135
+ const ERASER_HIT_RADIUS = 14;
136
+
137
+ type AnnotationTool = 'pen' | 'eraser' | null;
138
+
80
139
  interface CanvasViewportProps {
81
140
  onNodeContextMenu?: (e: MouseEvent, nodeId: string) => void;
82
141
  onCanvasContextMenu?: (e: MouseEvent, canvasX: number, canvasY: number) => void;
142
+ annotationMode?: boolean;
143
+ annotationTool?: AnnotationTool;
83
144
  }
84
145
 
85
146
  const IMAGE_EXTS = new Set(['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'bmp', 'ico', 'avif']);
@@ -165,10 +226,13 @@ export function getRenderableWorldNodes(
165
226
  return worldNodes;
166
227
  }
167
228
 
168
- export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: CanvasViewportProps) {
229
+ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu, annotationMode = false, annotationTool = null }: CanvasViewportProps) {
169
230
  const v = viewport.value;
170
231
  const isLassoing = useRef(false);
232
+ const isAnnotating = useRef(false);
233
+ const annotationPoints = useRef<Array<{ x: number; y: number }>>([]);
171
234
  const [lasso, setLasso] = useState<LassoRect | null>(null);
235
+ const [draftAnnotation, setDraftAnnotation] = useState<AnnotationDraft | null>(null);
172
236
  const [dropActive, setDropActive] = useState(false);
173
237
  const dropCounter = useRef(0);
174
238
  // Ref mirrors lasso state so pointer handlers always read the latest value
@@ -177,15 +241,16 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
177
241
 
178
242
  const containerRef = usePanZoom({
179
243
  viewport,
244
+ disabled: annotationMode,
180
245
  onViewportChange: (next) => {
181
246
  // Don't pan while lassoing — usePanZoom's pointerdown still fires
182
247
  // (native listener) before our Preact handler can stopPropagation.
183
- if (isLassoing.current) return;
248
+ if (isLassoing.current || annotationMode) return;
184
249
  cancelViewportAnimation();
185
250
  setViewport(next);
186
251
  },
187
252
  onViewportCommit: (next) => {
188
- if (isLassoing.current) return;
253
+ if (isLassoing.current || annotationMode) return;
189
254
  cancelViewportAnimation();
190
255
  commitViewport(next);
191
256
  },
@@ -222,7 +287,53 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
222
287
  const handlePointerDown = useCallback(
223
288
  (e: PointerEvent) => {
224
289
  const container = containerRef.current;
225
- if (!container || e.target !== container) return;
290
+ if (!container) return;
291
+
292
+ if (annotationTool === 'eraser') {
293
+ const target = e.target instanceof Element ? e.target : null;
294
+ if (target?.closest('.hud-layer, .snapshot-panel, .context-menu, .command-palette')) return;
295
+ e.preventDefault();
296
+ e.stopPropagation();
297
+ const rect = container.getBoundingClientRect();
298
+ const vp = viewport.value;
299
+ const point = {
300
+ x: (e.clientX - rect.left - vp.x) / vp.scale,
301
+ y: (e.clientY - rect.top - vp.y) / vp.scale,
302
+ };
303
+ const hit = findAnnotationAtPoint(Array.from(annotations.value.values()), point, ERASER_HIT_RADIUS / vp.scale);
304
+ if (hit) void removeAnnotationFromClient(hit.id);
305
+ return;
306
+ }
307
+
308
+ if (annotationTool === 'pen') {
309
+ const target = e.target instanceof Element ? e.target : null;
310
+ if (target?.closest('.hud-layer, .snapshot-panel, .context-menu, .command-palette')) return;
311
+ e.preventDefault();
312
+ e.stopPropagation();
313
+ activeNodeId.value = null;
314
+ clearSelection();
315
+ isAnnotating.current = true;
316
+ const rect = container.getBoundingClientRect();
317
+ const vp = viewport.value;
318
+ const point = {
319
+ x: (e.clientX - rect.left - vp.x) / vp.scale,
320
+ y: (e.clientY - rect.top - vp.y) / vp.scale,
321
+ };
322
+ annotationPoints.current = [point];
323
+ setDraftAnnotation({
324
+ id: 'draft-annotation',
325
+ type: 'freehand',
326
+ points: [point],
327
+ bounds: { x: 0, y: 0, width: 0, height: 0 },
328
+ color: ANNOTATION_COLOR,
329
+ width: ANNOTATION_WIDTH,
330
+ createdAt: '',
331
+ });
332
+ container.setPointerCapture(e.pointerId);
333
+ return;
334
+ }
335
+
336
+ if (e.target !== container) return;
226
337
 
227
338
  if (!e.shiftKey) {
228
339
  if (!lassoRef.current) {
@@ -243,11 +354,27 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
243
354
  setLasso(initial);
244
355
  container.setPointerCapture(e.pointerId);
245
356
  },
246
- [containerRef],
357
+ [annotationTool, containerRef],
247
358
  );
248
359
 
249
360
  const handlePointerMove = useCallback(
250
361
  (e: PointerEvent) => {
362
+ if (isAnnotating.current) {
363
+ const container = containerRef.current;
364
+ if (!container) return;
365
+ const rect = container.getBoundingClientRect();
366
+ const vp = viewport.value;
367
+ const point = {
368
+ x: (e.clientX - rect.left - vp.x) / vp.scale,
369
+ y: (e.clientY - rect.top - vp.y) / vp.scale,
370
+ };
371
+ const previous = annotationPoints.current.at(-1);
372
+ if (previous && Math.hypot(point.x - previous.x, point.y - previous.y) < 2) return;
373
+ annotationPoints.current = [...annotationPoints.current, point];
374
+ setDraftAnnotation((draft) => draft ? { ...draft, points: annotationPoints.current } : null);
375
+ return;
376
+ }
377
+
251
378
  if (!isLassoing.current || !lassoRef.current) return;
252
379
  const rect = containerRef.current?.getBoundingClientRect();
253
380
  if (!rect) return;
@@ -262,7 +389,22 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
262
389
  [containerRef],
263
390
  );
264
391
 
265
- const handlePointerUp = useCallback(() => {
392
+ const handlePointerUp = useCallback((e: PointerEvent) => {
393
+ if (isAnnotating.current) {
394
+ isAnnotating.current = false;
395
+ const points = annotationPoints.current;
396
+ annotationPoints.current = [];
397
+ setDraftAnnotation(null);
398
+ if (points.length >= 2) {
399
+ void createAnnotationFromClient({ points, color: ANNOTATION_COLOR, width: ANNOTATION_WIDTH });
400
+ }
401
+ const container = containerRef.current;
402
+ if (container?.hasPointerCapture(e.pointerId)) {
403
+ container.releasePointerCapture(e.pointerId);
404
+ }
405
+ return;
406
+ }
407
+
266
408
  const current = lassoRef.current;
267
409
  if (!isLassoing.current || !current) return;
268
410
  isLassoing.current = false;
@@ -306,6 +448,14 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
306
448
  setLasso(null);
307
449
  }, []);
308
450
 
451
+ useEffect(() => {
452
+ if (annotationMode) return;
453
+ if (!isAnnotating.current && !draftAnnotation) return;
454
+ isAnnotating.current = false;
455
+ annotationPoints.current = [];
456
+ setDraftAnnotation(null);
457
+ }, [annotationMode, draftAnnotation]);
458
+
309
459
  // ── Drag-to-connect: track cursor in world space, hit-test on drop ──
310
460
  useEffect(() => {
311
461
  function handleMove(e: PointerEvent) {
@@ -359,6 +509,7 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
359
509
  // ── Double-click on background → create new markdown node ──
360
510
  const handleDblClick = useCallback(
361
511
  (e: MouseEvent) => {
512
+ if (annotationMode) return;
362
513
  const container = containerRef.current;
363
514
  if (!container || e.target !== container) return;
364
515
  const rect = container.getBoundingClientRect();
@@ -377,11 +528,12 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
377
528
  height: nodeH,
378
529
  });
379
530
  },
380
- [containerRef],
531
+ [annotationMode, containerRef],
381
532
  );
382
533
 
383
534
  const handleContextMenu = useCallback(
384
535
  (e: MouseEvent) => {
536
+ if (annotationMode) return;
385
537
  if (!onCanvasContextMenu) return;
386
538
 
387
539
  const container = containerRef.current;
@@ -396,7 +548,7 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
396
548
  const canvasY = (e.clientY - rect.top - v.y) / v.scale;
397
549
  onCanvasContextMenu(e, canvasX, canvasY);
398
550
  },
399
- [containerRef, onCanvasContextMenu],
551
+ [annotationMode, containerRef, onCanvasContextMenu],
400
552
  );
401
553
 
402
554
  // ── Drag-and-drop files from filesystem ──
@@ -543,7 +695,11 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
543
695
  height: '100%',
544
696
  position: 'relative',
545
697
  overflow: 'hidden',
546
- cursor: draggingEdge.value ? 'crosshair' : isLassoing.current ? 'crosshair' : 'grab',
698
+ cursor: annotationTool === 'eraser'
699
+ ? 'cell'
700
+ : annotationMode || draggingEdge.value || isLassoing.current
701
+ ? 'crosshair'
702
+ : 'grab',
547
703
  }}
548
704
  >
549
705
  {/* D4: CSS matrix(a,b,c,d,tx,ty) — scale uniformly (a=d=scale, b=c=0)
@@ -561,6 +717,8 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
561
717
  >
562
718
  <FocusFieldLayer />
563
719
  <EdgeLayer nodes={nodes} edges={edges} />
720
+ <AnnotationLayer annotations={Array.from(annotations.value.values())} />
721
+ {draftAnnotation && draftAnnotation.points.length >= 2 && <AnnotationLayer annotations={[draftAnnotation]} />}
564
722
  {worldNodes.map((node) => (
565
723
  <CanvasNode key={node.id} node={node} onContextMenu={onNodeContextMenu}>
566
724
  {renderNodeContent(node)}
@@ -579,6 +737,7 @@ export function CanvasViewport({ onNodeContextMenu, onCanvasContextMenu }: Canva
579
737
  </svg>
580
738
  )}
581
739
  </div>
740
+ {annotationMode && <div class={`annotation-capture-layer${annotationTool === 'eraser' ? ' erasing' : ''}`} aria-hidden="true" />}
582
741
  {lassoStyle && <div class="lasso-rect" style={lassoStyle} />}
583
742
  {dropActive && (
584
743
  <div class="drop-zone-overlay">
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  clearContextPins,
3
3
  contextPinnedNodeIds,
4
+ hasOpenDockedContextPanel,
4
5
  } from '../state/canvas-store';
6
+ import { attentionHistoryOpen } from '../state/attention-store';
5
7
 
6
8
  export function ContextPinBar() {
7
9
  const count = contextPinnedNodeIds.value.size;
8
- if (count === 0) return null;
10
+ if (count === 0 || attentionHistoryOpen.value || hasOpenDockedContextPanel.value) return null;
9
11
 
10
12
  return (
11
13
  <div class="context-pin-bar">
@@ -3,7 +3,7 @@ import { LedgerNode } from '../nodes/LedgerNode';
3
3
  import { StatusNode } from '../nodes/StatusNode';
4
4
  import { StatusSummary } from '../nodes/StatusSummary';
5
5
  import { attentionHistoryOpen, closeAttentionHistory } from '../state/attention-store';
6
- import { toggleCollapsed, undockNode } from '../state/canvas-store';
6
+ import { getContextPinnedNodes, toggleCollapsed, undockNode } from '../state/canvas-store';
7
7
  import { TYPE_LABELS } from '../types';
8
8
  import type { CanvasNodeState } from '../types';
9
9
 
@@ -27,7 +27,8 @@ function getContextItemCount(node: CanvasNodeState): number {
27
27
  }
28
28
 
29
29
  function ContextDockedNode({ node }: { node: CanvasNodeState }) {
30
- const count = getContextItemCount(node);
30
+ const pinnedNodes = getContextPinnedNodes();
31
+ const count = pinnedNodes.length > 0 ? pinnedNodes.length : getContextItemCount(node);
31
32
  const hasItems = count > 0;
32
33
  const collapsed = node.collapsed === true;
33
34
 
@@ -117,7 +118,7 @@ function ContextDockedNode({ node }: { node: CanvasNodeState }) {
117
118
  </div>
118
119
  </div>
119
120
  <div class="context-dock-body">
120
- <ContextNode node={node} />
121
+ <ContextNode node={node} pinnedNodes={pinnedNodes} />
121
122
  </div>
122
123
  </aside>
123
124
  );
@@ -14,6 +14,7 @@ interface PanZoomOptions {
14
14
  viewport: Signal<ViewportState>;
15
15
  onViewportChange: (v: ViewportState) => void;
16
16
  onViewportCommit: (v: ViewportState) => void;
17
+ disabled?: boolean;
17
18
  }
18
19
 
19
20
  /**
@@ -23,7 +24,7 @@ interface PanZoomOptions {
23
24
  * - Pointer drag on background: pan
24
25
  * - Pinch (touch): zoom
25
26
  */
26
- export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: PanZoomOptions) {
27
+ export function usePanZoom({ viewport, onViewportChange, onViewportCommit, disabled = false }: PanZoomOptions) {
27
28
  const containerRef = useRef<HTMLDivElement>(null);
28
29
  const isPanning = useRef(false);
29
30
  const lastPointer = useRef({ x: 0, y: 0 });
@@ -42,6 +43,7 @@ export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: Pan
42
43
 
43
44
  const handleWheel = useCallback(
44
45
  (e: WheelEvent) => {
46
+ if (disabled) return;
45
47
  e.preventDefault();
46
48
  const v = viewport.value;
47
49
 
@@ -74,21 +76,23 @@ export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: Pan
74
76
  scheduleViewportCommit(next);
75
77
  }
76
78
  },
77
- [viewport, onViewportChange, scheduleViewportCommit],
79
+ [disabled, viewport, onViewportChange, scheduleViewportCommit],
78
80
  );
79
81
 
80
82
  const handlePointerDown = useCallback((e: PointerEvent) => {
83
+ if (disabled) return;
81
84
  // Only pan when clicking the canvas background (not nodes)
82
85
  const container = containerRef.current;
83
86
  if (!container || e.target !== container) return;
84
87
  isPanning.current = true;
85
88
  lastPointer.current = { x: e.clientX, y: e.clientY };
86
89
  container.setPointerCapture(e.pointerId);
87
- }, []);
90
+ }, [disabled]);
88
91
 
89
92
  const handlePointerMove = useCallback(
90
93
  (e: PointerEvent) => {
91
94
  if (!isPanning.current) return;
95
+ if (disabled) return;
92
96
  const dx = e.clientX - lastPointer.current.x;
93
97
  const dy = e.clientY - lastPointer.current.y;
94
98
  lastPointer.current = { x: e.clientX, y: e.clientY };
@@ -96,7 +100,7 @@ export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: Pan
96
100
  const v = viewport.value;
97
101
  onViewportChange({ x: v.x + dx, y: v.y + dy, scale: v.scale });
98
102
  },
99
- [viewport, onViewportChange],
103
+ [disabled, viewport, onViewportChange],
100
104
  );
101
105
 
102
106
  const handlePointerUp = useCallback(() => {
@@ -109,6 +113,7 @@ export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: Pan
109
113
  // Touch pinch
110
114
  const handleTouchMove = useCallback(
111
115
  (e: TouchEvent) => {
116
+ if (disabled) return;
112
117
  if (e.touches.length !== 2) {
113
118
  lastPinchDist.current = 0;
114
119
  return;
@@ -142,7 +147,7 @@ export function usePanZoom({ viewport, onViewportChange, onViewportCommit }: Pan
142
147
  }
143
148
  lastPinchDist.current = dist;
144
149
  },
145
- [viewport, onViewportChange, scheduleViewportCommit],
150
+ [disabled, viewport, onViewportChange, scheduleViewportCommit],
146
151
  );
147
152
 
148
153
  const handleTouchEnd = useCallback(() => {
@@ -117,6 +117,28 @@ export function IconMoon(p: IconProps): JSX.Element {
117
117
  );
118
118
  }
119
119
 
120
+ /** Pen stroke — canvas annotation mode */
121
+ export function IconPen(p: IconProps): JSX.Element {
122
+ return (
123
+ <Icon {...p}>
124
+ <path d="M3 13l2.8-.7L13 5.1 10.9 3 3.7 10.2 3 13Z" />
125
+ <path d="M9.8 4.1l2.1 2.1" />
126
+ <path d="M2.5 14h11" />
127
+ </Icon>
128
+ );
129
+ }
130
+
131
+ /** Eraser — remove canvas annotations */
132
+ export function IconEraser(p: IconProps): JSX.Element {
133
+ return (
134
+ <Icon {...p}>
135
+ <path d="M3 10.5 8.5 5a2 2 0 0 1 2.8 0l1.7 1.7a2 2 0 0 1 0 2.8L8.5 14H5.8L3 11.2Z" />
136
+ <path d="M7.5 6 12 10.5" />
137
+ <path d="M8.5 14H14" />
138
+ </Icon>
139
+ );
140
+ }
141
+
120
142
  /** Camera — snapshots */
121
143
  export function IconSnapshot(p: IconProps): JSX.Element {
122
144
  return (
@@ -1,5 +1,5 @@
1
1
  import { openWorkbenchFile } from '../state/intent-bridge';
2
- import type { CanvasNodeState } from '../types';
2
+ import { TYPE_LABELS, type CanvasNodeState } from '../types';
3
3
 
4
4
  interface ContextCard {
5
5
  key?: string;
@@ -30,6 +30,14 @@ export interface ContextNodeFallbackDisplay {
30
30
  path: string;
31
31
  }
32
32
 
33
+ export interface PinnedContextDisplay {
34
+ id: string;
35
+ title: string;
36
+ summary: string;
37
+ kind: string;
38
+ path: string;
39
+ }
40
+
33
41
  export function normalizeContextCardDisplay(card: ContextCard): ContextCardDisplay {
34
42
  const title = card.title || card.label || card.key || 'Context';
35
43
  const summary = card.summary?.trim() || 'Available in startup context.';
@@ -90,6 +98,24 @@ export function normalizeContextNodeFallback(
90
98
  };
91
99
  }
92
100
 
101
+ export function normalizePinnedContextDisplay(node: CanvasNodeState): PinnedContextDisplay {
102
+ const title = asTrimmedString(node.data.title) || node.id;
103
+ const summary =
104
+ asTrimmedString(node.data.content) ||
105
+ asTrimmedString(node.data.excerpt) ||
106
+ asTrimmedString(node.data.description) ||
107
+ asTrimmedString(node.data.pageTitle) ||
108
+ '';
109
+ const path = asTrimmedString(node.data.path) || asTrimmedString(node.data.url);
110
+ return {
111
+ id: node.id,
112
+ title,
113
+ summary,
114
+ kind: TYPE_LABELS[node.type] ?? node.type,
115
+ path,
116
+ };
117
+ }
118
+
93
119
  function formatTokens(n: number | null): string {
94
120
  if (n === null || !Number.isFinite(n) || n < 0) return '0';
95
121
  if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}m`;
@@ -107,9 +133,12 @@ function usageBarColor(utilization: number): string {
107
133
  export function ContextNode({
108
134
  node,
109
135
  expanded = false,
110
- }: { node: CanvasNodeState; expanded?: boolean }) {
136
+ pinnedNodes = [],
137
+ }: { node: CanvasNodeState; expanded?: boolean; pinnedNodes?: CanvasNodeState[] }) {
111
138
  const cards = (node.data.cards as ContextCard[]) ?? [];
112
139
  const auxTabs = (node.data.auxTabs as Array<{ id: string; url: string; reason?: string }>) ?? [];
140
+ const pinnedContext = pinnedNodes.map(normalizePinnedContextDisplay);
141
+ const hasPinnedContext = pinnedContext.length > 0;
113
142
  const currentTokens =
114
143
  typeof node.data.currentTokens === 'number' ? node.data.currentTokens : null;
115
144
  const tokenLimit = typeof node.data.tokenLimit === 'number' ? node.data.tokenLimit : null;
@@ -120,7 +149,9 @@ export function ContextNode({
120
149
  utilization !== null ? Math.max(0, Math.min(100, Math.round(utilization * 100))) : null;
121
150
  const barColor = usageBarColor(utilization ?? 0);
122
151
  const fallback =
123
- cards.length === 0 && auxTabs.length === 0 ? normalizeContextNodeFallback(node.data) : null;
152
+ !hasPinnedContext && cards.length === 0 && auxTabs.length === 0
153
+ ? normalizeContextNodeFallback(node.data)
154
+ : null;
124
155
 
125
156
  const openCard = async (card: ContextCard): Promise<void> => {
126
157
  const path = typeof card.path === 'string' ? card.path.trim() : '';
@@ -181,7 +212,98 @@ export function ContextNode({
181
212
  </div>
182
213
  )}
183
214
 
184
- {cards.length > 0 && (
215
+ {hasPinnedContext && (
216
+ <div>
217
+ <div
218
+ style={{
219
+ fontSize: '10px',
220
+ fontWeight: 600,
221
+ color: 'var(--c-muted)',
222
+ textTransform: 'uppercase',
223
+ letterSpacing: '0.04em',
224
+ marginBottom: '6px',
225
+ }}
226
+ >
227
+ Pinned Context ({pinnedContext.length})
228
+ </div>
229
+ {pinnedContext.map((display) => (
230
+ <div
231
+ key={display.id}
232
+ style={{
233
+ padding: '6px 8px',
234
+ background: 'var(--c-surface-subtle)',
235
+ borderRadius: '6px',
236
+ marginBottom: '4px',
237
+ borderLeft: '2px solid var(--c-accent)',
238
+ }}
239
+ >
240
+ <div style={{ fontWeight: 600, color: 'var(--c-text)', marginBottom: '2px' }}>
241
+ {display.title}
242
+ </div>
243
+ {display.summary && (
244
+ <div
245
+ style={{
246
+ color: 'var(--c-muted)',
247
+ fontSize: '10px',
248
+ lineHeight: 1.45,
249
+ marginBottom: '4px',
250
+ whiteSpace: 'pre-wrap',
251
+ }}
252
+ >
253
+ {display.summary}
254
+ </div>
255
+ )}
256
+ <div style={{ display: 'flex', gap: '4px', flexWrap: 'wrap', marginTop: '4px' }}>
257
+ <span
258
+ style={{
259
+ fontSize: '9px',
260
+ padding: '1px 4px',
261
+ background: 'var(--c-surface-hover)',
262
+ color: 'var(--c-text-soft)',
263
+ borderRadius: '3px',
264
+ display: 'inline-block',
265
+ }}
266
+ >
267
+ {display.kind}
268
+ </span>
269
+ </div>
270
+ {display.path && (
271
+ <div style={{ marginTop: '6px' }}>
272
+ <div
273
+ style={{
274
+ color: 'var(--c-dim)',
275
+ fontSize: '10px',
276
+ wordBreak: 'break-all',
277
+ marginBottom: '6px',
278
+ }}
279
+ >
280
+ {display.path}
281
+ </div>
282
+ {display.path.startsWith('/') && (
283
+ <button
284
+ type="button"
285
+ onClick={() => void openWorkbenchFile(display.path)}
286
+ style={{
287
+ padding: '4px 8px',
288
+ fontSize: '10px',
289
+ background: 'var(--c-accent-12)',
290
+ border: '1px solid var(--c-accent-25)',
291
+ borderRadius: '4px',
292
+ color: 'var(--c-text-soft)',
293
+ cursor: 'pointer',
294
+ }}
295
+ >
296
+ Open in canvas
297
+ </button>
298
+ )}
299
+ </div>
300
+ )}
301
+ </div>
302
+ ))}
303
+ </div>
304
+ )}
305
+
306
+ {!hasPinnedContext && cards.length > 0 && (
185
307
  <div>
186
308
  <div
187
309
  style={{
@@ -305,7 +427,7 @@ export function ContextNode({
305
427
  </div>
306
428
  )}
307
429
 
308
- {auxTabs.length > 0 && (
430
+ {!hasPinnedContext && auxTabs.length > 0 && (
309
431
  <div>
310
432
  <div
311
433
  style={{
@@ -404,7 +526,7 @@ export function ContextNode({
404
526
  </div>
405
527
  )}
406
528
 
407
- {!fallback && cards.length === 0 && auxTabs.length === 0 && (
529
+ {!hasPinnedContext && !fallback && cards.length === 0 && auxTabs.length === 0 && (
408
530
  <div style={{ color: 'var(--c-dim)', fontStyle: 'italic' }}>No context loaded</div>
409
531
  )}
410
532
  </div>
@@ -1,8 +1,23 @@
1
1
  import { PHASE_COLORS } from '../theme/tokens';
2
2
  import type { CanvasNodeState } from '../types';
3
3
 
4
+ export function getStatusDisplayPhase(node: CanvasNodeState): string {
5
+ const phase = typeof node.data.phase === 'string' && node.data.phase.trim().length > 0
6
+ ? node.data.phase.trim()
7
+ : '';
8
+ if (phase) return phase;
9
+ const content = typeof node.data.content === 'string' && node.data.content.trim().length > 0
10
+ ? node.data.content.trim()
11
+ : '';
12
+ if (content) return content;
13
+ const status = typeof node.data.status === 'string' && node.data.status.trim().length > 0
14
+ ? node.data.status.trim()
15
+ : '';
16
+ return status || 'idle';
17
+ }
18
+
4
19
  export function StatusNode({ node }: { node: CanvasNodeState }) {
5
- const phase = (node.data.phase as string) || 'idle';
20
+ const phase = getStatusDisplayPhase(node);
6
21
  const detail = (node.data.detail as string) || '';
7
22
  const message = (node.data.message as string) || '';
8
23
  const level = (node.data.level as string) || 'ok';
@@ -1,8 +1,9 @@
1
1
  import { PHASE_COLORS } from '../theme/tokens';
2
2
  import type { CanvasNodeState } from '../types';
3
+ import { getStatusDisplayPhase } from './StatusNode';
3
4
 
4
5
  export function StatusSummary({ node }: { node: CanvasNodeState }) {
5
- const phase = (node.data.phase as string) || 'idle';
6
+ const phase = getStatusDisplayPhase(node);
6
7
  const activeTool = node.data.activeTool as string | null;
7
8
  const subagent = node.data.subagent as { state: string; name: string } | undefined;
8
9
  const phaseColor = PHASE_COLORS[phase] ?? 'var(--c-muted)';