@cueloop/client 0.1.0-alpha.6 → 0.1.0-alpha.61

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 (161) hide show
  1. package/native/build-pty.sh +51 -0
  2. package/native/build.sh +82 -0
  3. package/native/darwin-arm64/libcuelooppty.dylib +0 -0
  4. package/native/darwin-arm64/libcueloopvt.dylib +0 -0
  5. package/native/src/pty.zig +193 -0
  6. package/native/src/shim.zig +114 -0
  7. package/package.json +37 -33
  8. package/src/App.appearance.test.tsx +51 -0
  9. package/src/App.autoclose.test.tsx +73 -47
  10. package/src/App.diff.test.tsx +169 -22
  11. package/src/App.export.test.tsx +49 -37
  12. package/src/App.plan-review.test.tsx +714 -0
  13. package/src/App.prototype.test.tsx +194 -0
  14. package/src/App.readonly.test.tsx +69 -35
  15. package/src/App.rendering.test.tsx +59 -31
  16. package/src/App.review-panel.test.tsx +143 -0
  17. package/src/App.submit-confirm.test.tsx +229 -0
  18. package/src/App.test.tsx +139 -68
  19. package/src/App.toast.test.tsx +77 -0
  20. package/src/App.tsx +0 -0
  21. package/src/App.walk.test.tsx +299 -0
  22. package/src/__snapshots__/view-plan.regression.test.ts.snap +100 -0
  23. package/src/app-key-state.ts +61 -0
  24. package/src/app-screens.tsx +270 -0
  25. package/src/app-view-model.ts +307 -0
  26. package/src/attribution.test.ts +31 -0
  27. package/src/attribution.ts +42 -0
  28. package/src/clipboard.test.ts +23 -0
  29. package/src/clipboard.ts +33 -0
  30. package/src/components/AnnotationCard.compose-rows.test.ts +49 -0
  31. package/src/components/AnnotationCard.stories.tsx +94 -0
  32. package/src/components/AnnotationCard.tsx +250 -0
  33. package/src/components/Breadcrumb.stories.tsx +19 -0
  34. package/src/components/Breadcrumb.tsx +45 -0
  35. package/src/components/CodeBlock.stories.tsx +42 -0
  36. package/src/components/CodeBlock.tsx +84 -0
  37. package/src/components/CompletionOverlay.stories.tsx +23 -0
  38. package/src/components/CompletionOverlay.tsx +60 -0
  39. package/src/components/ConfirmCard.stories.tsx +35 -0
  40. package/src/components/ConfirmCard.tsx +129 -0
  41. package/src/components/ConfirmDialog.stories.tsx +21 -0
  42. package/src/components/ConfirmDialog.tsx +66 -0
  43. package/src/components/DiffSheet.scroll.test.tsx +135 -0
  44. package/src/components/DiffSheet.stories.tsx +78 -0
  45. package/src/components/DiffSheet.syntax.test.tsx +65 -0
  46. package/src/components/DiffSheet.tsx +374 -0
  47. package/src/components/InboxList.stories.tsx +31 -0
  48. package/src/components/InboxList.tsx +64 -0
  49. package/src/components/KeybindsDialog.stories.tsx +31 -0
  50. package/src/components/KeybindsDialog.tsx +59 -0
  51. package/src/components/MarkerPopover.stories.tsx +58 -0
  52. package/src/components/MarkerPopover.tsx +109 -0
  53. package/src/components/MenuBar.stories.tsx +37 -0
  54. package/src/components/MenuBar.tsx +75 -0
  55. package/src/components/PlanSheet.stories.tsx +113 -0
  56. package/src/components/PlanSheet.tsx +422 -0
  57. package/src/components/PromptDialog.stories.tsx +36 -0
  58. package/src/components/PromptDialog.tsx +80 -0
  59. package/src/components/PrototypeSheet.stories.tsx +20 -0
  60. package/src/components/PrototypeSheet.tsx +450 -0
  61. package/src/components/ReviewPanel.stories.tsx +86 -0
  62. package/src/components/ReviewPanel.tsx +103 -0
  63. package/src/components/ReviewRail.stories.tsx +218 -0
  64. package/src/components/ReviewRail.tsx +318 -0
  65. package/src/components/SettingsDialog.stories.tsx +111 -0
  66. package/src/components/SettingsDialog.tsx +147 -0
  67. package/src/components/SettingsRows.stories.tsx +18 -0
  68. package/src/components/SettingsRows.tsx +112 -0
  69. package/src/components/Toast.stories.tsx +12 -0
  70. package/src/components/Toast.tsx +45 -0
  71. package/src/components/WalkWizard.stories.tsx +100 -0
  72. package/src/components/WalkWizard.tsx +152 -0
  73. package/src/components/__snapshots__/stories.test.tsx.snap +1857 -0
  74. package/src/components/agent-launcher.stories.tsx +26 -0
  75. package/src/components/agent-launcher.test.tsx +50 -0
  76. package/src/components/agent-launcher.tsx +149 -0
  77. package/src/components/diff-sheet-layout.test.ts +128 -0
  78. package/src/components/diff-sheet-layout.ts +184 -0
  79. package/src/components/plan-sheet-run-style.ts +90 -0
  80. package/src/components/primitives/Button.stories.tsx +32 -0
  81. package/src/components/primitives/Button.tsx +52 -0
  82. package/src/components/primitives/Card.stories.tsx +25 -0
  83. package/src/components/primitives/Card.tsx +60 -0
  84. package/src/components/primitives/Dialog.stories.tsx +24 -0
  85. package/src/components/primitives/Dialog.tsx +66 -0
  86. package/src/components/primitives/StatusBar.stories.tsx +11 -0
  87. package/src/components/primitives/StatusBar.tsx +23 -0
  88. package/src/components/primitives/Tabs.stories.tsx +29 -0
  89. package/src/components/primitives/Tabs.tsx +102 -0
  90. package/src/components/primitives/Toolbar.stories.tsx +17 -0
  91. package/src/components/primitives/Toolbar.tsx +14 -0
  92. package/src/components/primitives/frame.test.ts +12 -0
  93. package/src/components/primitives/frame.ts +14 -0
  94. package/src/components/quick-actions-editor.stories.tsx +54 -0
  95. package/src/components/quick-actions-editor.tsx +138 -0
  96. package/src/components/stories-app.tsx +124 -0
  97. package/src/components/stories.test.tsx +66 -0
  98. package/src/components/story-fixtures.ts +98 -0
  99. package/src/components/story.ts +75 -0
  100. package/src/components/syntax-highlight.ts +102 -0
  101. package/src/components/terminal-pane.test.tsx +40 -0
  102. package/src/components/terminal-pane.ts +193 -0
  103. package/src/components/theme-context.stories.tsx +46 -0
  104. package/src/components/theme-context.tsx +37 -0
  105. package/src/components/truncate-text.ts +7 -0
  106. package/src/config.test.ts +448 -31
  107. package/src/config.ts +339 -57
  108. package/src/diff-hunk-curate.test.ts +315 -0
  109. package/src/diff-hunk-curate.ts +253 -0
  110. package/src/diff-intraline.test.ts +165 -0
  111. package/src/diff-intraline.ts +146 -0
  112. package/src/diff-syntax.test.ts +96 -0
  113. package/src/diff-syntax.ts +176 -0
  114. package/src/editor.test.ts +149 -0
  115. package/src/editor.ts +135 -9
  116. package/src/ghostty-terminal.test.ts +84 -0
  117. package/src/ghostty-terminal.ts +176 -0
  118. package/src/herdr.test.ts +9 -34
  119. package/src/herdr.ts +17 -21
  120. package/src/index.ts +10 -0
  121. package/src/integrations.test.ts +41 -0
  122. package/src/integrations.ts +32 -0
  123. package/src/intent-dispatch.test.ts +499 -0
  124. package/src/intent-dispatch.ts +585 -0
  125. package/src/key-bindings.test.ts +156 -0
  126. package/src/key-bindings.ts +452 -0
  127. package/src/keymap.test.ts +635 -0
  128. package/src/keymap.ts +404 -0
  129. package/src/kitty-image.test.ts +66 -0
  130. package/src/kitty-image.ts +138 -0
  131. package/src/prototype-browser.test.ts +56 -0
  132. package/src/prototype-browser.ts +289 -0
  133. package/src/pty.test.ts +81 -0
  134. package/src/pty.ts +237 -0
  135. package/src/review-panel.test.ts +113 -0
  136. package/src/review-panel.ts +83 -0
  137. package/src/run.ts +16 -5
  138. package/src/serve.test.ts +25 -9
  139. package/src/serve.ts +19 -8
  140. package/src/session-controller.curate.test.ts +260 -0
  141. package/src/session-controller.share.test.ts +320 -0
  142. package/src/session-controller.ts +993 -0
  143. package/src/share.ts +120 -0
  144. package/src/test-support.test.ts +60 -0
  145. package/src/test-support.ts +197 -0
  146. package/src/theme-presets.test.ts +51 -0
  147. package/src/theme-presets.ts +187 -0
  148. package/src/theme.ts +64 -17
  149. package/src/use-settings-dialog.tsx +275 -0
  150. package/src/version.ts +5 -0
  151. package/src/view-diff.test.ts +22 -8
  152. package/src/view-diff.ts +39 -23
  153. package/src/view-plan.regression.test.ts +60 -0
  154. package/src/view-plan.test.ts +406 -0
  155. package/src/view-plan.ts +554 -0
  156. package/src/walk.test.ts +121 -0
  157. package/src/walk.ts +74 -0
  158. package/src/syntax.test.ts +0 -41
  159. package/src/syntax.ts +0 -88
  160. package/src/view.test.ts +0 -157
  161. package/src/view.ts +0 -0
@@ -0,0 +1,450 @@
1
+ /**
2
+ * Prototype review surface: renders the HTML screenshot into a reserved cell
3
+ * region via the kitty graphics protocol, and turns a click into a DOM-element
4
+ * selection, so the shared marker actions bar and compose card annotate an
5
+ * element rather than a text span. The image is painted directly (not through
6
+ * OpenTUI's ImageRenderable, which does not display in every terminal): the
7
+ * region's cells are never repainted, and the picture is re-placed after each
8
+ * frame so it survives OpenTUI's own draws.
9
+ */
10
+
11
+ import React, { useEffect, useRef, useState } from "react";
12
+ import type { BoxRenderable } from "@opentui/core";
13
+ import { useKeyboard, useRenderer } from "@opentui/react";
14
+ import type { Theme } from "../theme";
15
+ import { quickActionBody, type QuickAction } from "../config";
16
+ import { useComponentTheme } from "./theme-context";
17
+ import { FRAME_BORDER_STYLE } from "./primitives/frame";
18
+ import { MarkerPopover } from "./MarkerPopover";
19
+ import { AnnotationCard } from "./AnnotationCard";
20
+ import {
21
+ cssBoxToCell,
22
+ imageCellToCss,
23
+ prototypeRendererFactory,
24
+ type PrototypeElement,
25
+ type PrototypeRenderer,
26
+ type PrototypeViewport,
27
+ } from "../prototype-browser";
28
+ import {
29
+ deleteKittyImage,
30
+ placeKittyImage,
31
+ resolveTransmitMedium,
32
+ transmitKittyImage,
33
+ type CellRegion,
34
+ } from "../kitty-image";
35
+
36
+ export interface PrototypeSheetProps {
37
+ prototypePath: string;
38
+ quickActions: QuickAction[];
39
+ canComment: boolean;
40
+ onCommentElement: (element: PrototypeElement, body: string) => void;
41
+ /** Signals when the inline compose owns the keyboard, so the app suppresses
42
+ * its global keymap and the compose textarea receives the typed note. */
43
+ onComposingChange?: (active: boolean) => void;
44
+ /** True while an app overlay (menu, settings) covers the sheet; the image is
45
+ * removed so those overlays are not shown through the graphics layer. */
46
+ hidden?: boolean;
47
+ theme?: Theme;
48
+ }
49
+
50
+ type SheetStatus = "loading" | "ready" | "unsupported" | "error";
51
+
52
+ const POPOVER_ROWS = 3;
53
+ /** Compose-card width, so the floating composer reads like the plan/diff one
54
+ * instead of shrinking to its content. */
55
+ const COMPOSE_COLS = 46;
56
+ const PROTOTYPE_IMAGE_ID = 811;
57
+ /** Page pixels scrolled per wheel notch. */
58
+ const SCROLL_STEP = 240;
59
+ // The capture viewport width in CSS pixels; its height matches the region's
60
+ // cell aspect so the rendered image fills the box instead of letterboxing. The
61
+ // aspect comes from the terminal's reported cell pixels, falling back to a
62
+ // typical monospace ratio when the terminal never reports one.
63
+ const CAPTURE_WIDTH = 1280;
64
+ const FALLBACK_CELL_HEIGHT_OVER_WIDTH = 2.18;
65
+
66
+ function cellHeightOverWidth(renderer: {
67
+ resolution: { width: number; height: number } | null;
68
+ terminalWidth: number;
69
+ terminalHeight: number;
70
+ }): number {
71
+ const resolution = renderer.resolution;
72
+
73
+ if (!resolution || renderer.terminalWidth < 1 || renderer.terminalHeight < 1) {
74
+ return FALLBACK_CELL_HEIGHT_OVER_WIDTH;
75
+ }
76
+
77
+ return resolution.height / renderer.terminalHeight / (resolution.width / renderer.terminalWidth);
78
+ }
79
+
80
+ function regionOf(box: BoxRenderable | null): CellRegion | null {
81
+ if (!box || box.width < 1 || box.height < 1) return null;
82
+
83
+ return { column: box.x, row: box.y, columns: box.width, rows: box.height };
84
+ }
85
+
86
+ type CaptureRenderer = {
87
+ resolution: { width: number; height: number } | null;
88
+ terminalWidth: number;
89
+ terminalHeight: number;
90
+ };
91
+
92
+ /**
93
+ * Capture at the region's own pixel size when the terminal reports its cell
94
+ * pixels, so the terminal never downscales an oversized image (less Chromium
95
+ * raster and fewer bytes). Without a resolution report, fall back to a fixed
96
+ * width at 2x and derive the height from the cell aspect.
97
+ */
98
+ function captureConfig(
99
+ region: CellRegion,
100
+ renderer: CaptureRenderer,
101
+ ): { viewport: PrototypeViewport; deviceScaleFactor: number } {
102
+ const resolution = renderer.resolution;
103
+
104
+ if (resolution && renderer.terminalWidth >= 1 && renderer.terminalHeight >= 1) {
105
+ const cellWidth = resolution.width / renderer.terminalWidth;
106
+ const cellHeight = resolution.height / renderer.terminalHeight;
107
+
108
+ return {
109
+ viewport: {
110
+ width: Math.max(1, Math.round(region.columns * cellWidth)),
111
+ height: Math.max(1, Math.round(region.rows * cellHeight)),
112
+ },
113
+ deviceScaleFactor: 1,
114
+ };
115
+ }
116
+
117
+ return {
118
+ viewport: {
119
+ width: CAPTURE_WIDTH,
120
+ height: Math.round(
121
+ (CAPTURE_WIDTH * region.rows * cellHeightOverWidth(renderer)) / region.columns,
122
+ ),
123
+ },
124
+ deviceScaleFactor: 2,
125
+ };
126
+ }
127
+
128
+ function PrototypeSheetImpl({
129
+ prototypePath,
130
+ quickActions,
131
+ canComment,
132
+ onCommentElement,
133
+ onComposingChange,
134
+ hidden = false,
135
+ theme,
136
+ }: PrototypeSheetProps): React.ReactNode {
137
+ const tokens = useComponentTheme(theme);
138
+ const renderer = useRenderer();
139
+ const regionRef = useRef<BoxRenderable | null>(null);
140
+ const browserRef = useRef<PrototypeRenderer | null>(null);
141
+ const launchedRef = useRef(false);
142
+ const viewportRef = useRef<PrototypeViewport>({ width: CAPTURE_WIDTH, height: 800 });
143
+ const pngRef = useRef<Uint8Array | null>(null);
144
+ const transmittedRef = useRef<Uint8Array | null>(null);
145
+ const paintRef = useRef<() => void>(() => undefined);
146
+ const launchRef = useRef<() => void>(() => undefined);
147
+ const hiddenRef = useRef(hidden);
148
+
149
+ useEffect(() => {
150
+ hiddenRef.current = hidden;
151
+ });
152
+
153
+ const [status, setStatus] = useState<SheetStatus>("loading");
154
+ const [errorMessage, setErrorMessage] = useState<string>("");
155
+ const [selected, setSelected] = useState<PrototypeElement | null>(null);
156
+ const [overlayCell, setOverlayCell] = useState<{
157
+ left: number;
158
+ top: number;
159
+ regionColumns: number;
160
+ } | null>(null);
161
+ const [actionsOpen, setActionsOpen] = useState(false);
162
+ const [composing, setComposing] = useState(false);
163
+ const [draftText, setDraftText] = useState("");
164
+
165
+ const setPng = (png: Uint8Array): void => {
166
+ pngRef.current = png;
167
+ transmittedRef.current = null;
168
+ paintRef.current();
169
+ };
170
+
171
+ // Every frame: start the browser once layout is known, then keep the picture
172
+ // asserted over its cells. The kitty emission (transmit once, cheap re-place
173
+ // after) is skipped when the renderer has no raw writeOut channel (the test
174
+ // harness), but the launch trigger still runs.
175
+ useEffect(() => {
176
+ if (!renderer) return;
177
+ // writeOut is the renderer's raw output channel, ordered against its frame
178
+ // bytes; it is private, so reach it through one narrow cast
179
+ const rawWrite = (renderer as unknown as { writeOut?: (data: string) => void }).writeOut;
180
+ const write =
181
+ typeof rawWrite === "function" ? (chunk: string) => rawWrite.call(renderer, chunk) : null;
182
+ const medium = resolveTransmitMedium();
183
+ const paint = (): void => {
184
+ if (!write) return;
185
+ // an app overlay is covering the sheet: pull the image so it does not show
186
+ // through the overlay's cells, and re-transmit once the overlay closes
187
+ if (hiddenRef.current) {
188
+ if (transmittedRef.current !== null) {
189
+ deleteKittyImage(write, PROTOTYPE_IMAGE_ID);
190
+ transmittedRef.current = null;
191
+ }
192
+
193
+ return;
194
+ }
195
+ const region = regionOf(regionRef.current);
196
+ const png = pngRef.current;
197
+
198
+ if (!region || !png) return;
199
+ if (transmittedRef.current !== png) {
200
+ transmitKittyImage(write, png, region, PROTOTYPE_IMAGE_ID, medium);
201
+ transmittedRef.current = png;
202
+ } else {
203
+ placeKittyImage(write, region, PROTOTYPE_IMAGE_ID);
204
+ }
205
+ };
206
+
207
+ paintRef.current = paint;
208
+ const onFrame = (): void => {
209
+ launchRef.current();
210
+ paint();
211
+ };
212
+
213
+ renderer.on("frame", onFrame);
214
+
215
+ return () => {
216
+ renderer.off("frame", onFrame);
217
+ if (write) deleteKittyImage(write, PROTOTYPE_IMAGE_ID);
218
+ };
219
+ }, [renderer]);
220
+
221
+ useEffect(() => {
222
+ onComposingChange?.(composing);
223
+ }, [composing, onComposingChange]);
224
+
225
+ const unmountedRef = useRef(false);
226
+
227
+ useEffect(() => {
228
+ return () => {
229
+ unmountedRef.current = true;
230
+ void browserRef.current?.close();
231
+ };
232
+ }, []);
233
+
234
+ const launch = (): void => {
235
+ const region = regionOf(regionRef.current);
236
+ const caps = renderer?.capabilities;
237
+
238
+ if (launchedRef.current || !region) return;
239
+ if (caps && caps.kitty_graphics === false) {
240
+ setStatus("unsupported");
241
+
242
+ return;
243
+ }
244
+ launchedRef.current = true;
245
+ const capture = captureConfig(region, renderer!);
246
+
247
+ viewportRef.current = capture.viewport;
248
+ void (async () => {
249
+ try {
250
+ const browser = await prototypeRendererFactory()({
251
+ filePath: prototypePath,
252
+ viewport: capture.viewport,
253
+ deviceScaleFactor: capture.deviceScaleFactor,
254
+ });
255
+
256
+ // the sheet may have unmounted while Chromium was launching; close the
257
+ // late arrival instead of leaking the process
258
+ if (unmountedRef.current) {
259
+ void browser.close();
260
+
261
+ return;
262
+ }
263
+ browserRef.current = browser;
264
+ setPng(await browser.screenshot());
265
+ setStatus("ready");
266
+ } catch (error) {
267
+ setErrorMessage(error instanceof Error ? error.message : String(error));
268
+ setStatus("error");
269
+ }
270
+ })();
271
+ };
272
+
273
+ useEffect(() => {
274
+ launchRef.current = launch;
275
+ });
276
+
277
+ const refresh = async (): Promise<void> => {
278
+ const browser = browserRef.current;
279
+
280
+ if (browser) setPng(await browser.screenshot());
281
+ };
282
+
283
+ const clearSelection = (): void => {
284
+ setSelected(null);
285
+ setOverlayCell(null);
286
+ setActionsOpen(false);
287
+ setComposing(false);
288
+ setDraftText("");
289
+ };
290
+
291
+ // While the compose textarea owns the keyboard, the global keymap is
292
+ // suppressed, so escape-to-cancel is handled here - matching the plan
293
+ // composer, where escape closes the overlay.
294
+ useKeyboard((key) => {
295
+ if (composing && key.name === "escape") clearSelection();
296
+ });
297
+
298
+ const onRegionMouseDown = (event: { x: number; y: number }): void => {
299
+ const browser = browserRef.current;
300
+ const region = regionOf(regionRef.current);
301
+
302
+ if (status !== "ready" || !browser || !region) return;
303
+ const geometry = {
304
+ x: region.column,
305
+ y: region.row,
306
+ width: region.columns,
307
+ height: region.rows,
308
+ };
309
+ const cssPoint = imageCellToCss(event, geometry, viewportRef.current);
310
+
311
+ if (!cssPoint) return;
312
+ void (async () => {
313
+ const element = await browser.elementAt(cssPoint.x, cssPoint.y);
314
+
315
+ if (!element) return;
316
+ const cell = cssBoxToCell(element.box, geometry, viewportRef.current);
317
+ const topRaw = cell.row - geometry.y;
318
+
319
+ setSelected(element);
320
+ setOverlayCell({
321
+ left: Math.max(0, cell.column - geometry.x),
322
+ top: Math.max(0, topRaw < POPOVER_ROWS ? topRaw + 1 : topRaw - POPOVER_ROWS),
323
+ regionColumns: geometry.width,
324
+ });
325
+ setActionsOpen(false);
326
+ setComposing(false);
327
+ })().catch((error) => {
328
+ setErrorMessage(error instanceof Error ? error.message : String(error));
329
+ setStatus("error");
330
+ });
331
+ };
332
+
333
+ const onRegionScroll = (event: { scroll?: { direction: string } }): void => {
334
+ const browser = browserRef.current;
335
+
336
+ if (status !== "ready" || !browser) return;
337
+ const delta = event.scroll?.direction === "up" ? -SCROLL_STEP : SCROLL_STEP;
338
+
339
+ // a selection would drift once the page scrolls under it, so drop it
340
+ clearSelection();
341
+ void browser
342
+ .scrollBy(delta)
343
+ .then(() => refresh())
344
+ .catch(() => undefined);
345
+ };
346
+
347
+ const commit = (body: string): void => {
348
+ if (!canComment) return;
349
+ if (selected && body.trim()) onCommentElement(selected, body.trim());
350
+ clearSelection();
351
+ };
352
+
353
+ // the overlay carries an opaque fill so the popover and compose card read as
354
+ // solid cards over the image, matching the plan surface
355
+ const overlayStyle = {
356
+ position: "absolute" as const,
357
+ left: overlayCell?.left ?? 0,
358
+ top: Math.max(0, overlayCell?.top ?? 0),
359
+ flexDirection: "column" as const,
360
+ backgroundColor: tokens.elevated,
361
+ };
362
+ // keep the composer inside the region: never wider than the region, and
363
+ // clamped so it cannot run off either edge on a narrow preview
364
+ const regionColumns = overlayCell?.regionColumns ?? 0;
365
+ const composeWidth = regionColumns > 0 ? Math.min(COMPOSE_COLS, regionColumns) : COMPOSE_COLS;
366
+ const composeStyle = {
367
+ ...overlayStyle,
368
+ left: Math.max(0, Math.min(overlayStyle.left, regionColumns - composeWidth)),
369
+ width: composeWidth,
370
+ };
371
+
372
+ return (
373
+ <box
374
+ style={{
375
+ flexGrow: 1,
376
+ flexDirection: "column",
377
+ border: true,
378
+ borderStyle: FRAME_BORDER_STYLE,
379
+ borderColor: tokens.text,
380
+ }}
381
+ >
382
+ <box
383
+ ref={(instance: BoxRenderable | null) => {
384
+ regionRef.current = instance;
385
+ }}
386
+ style={{ flexGrow: 1 }}
387
+ onSizeChange={launch}
388
+ onMouseDown={onRegionMouseDown}
389
+ onMouseScroll={onRegionScroll}
390
+ />
391
+ {status !== "ready" ? (
392
+ <box style={{ position: "absolute", left: 2, top: 1 }}>
393
+ <text fg={tokens.textDim}>{statusLine(status, errorMessage)}</text>
394
+ </box>
395
+ ) : null}
396
+ {selected && !composing ? (
397
+ <box style={overlayStyle}>
398
+ <MarkerPopover
399
+ view={actionsOpen ? "actions" : "toolbar"}
400
+ actions={quickActions}
401
+ actionIndex={0}
402
+ canCut={false}
403
+ onComment={() => {
404
+ if (!canComment) return;
405
+ onComposingChange?.(true);
406
+ setComposing(true);
407
+ }}
408
+ onCut={() => undefined}
409
+ onOpenActions={() => setActionsOpen(true)}
410
+ onClose={clearSelection}
411
+ onPickAction={(index) => commit(quickActionBody(quickActions[index]!))}
412
+ onBack={() => setActionsOpen(false)}
413
+ theme={theme}
414
+ />
415
+ </box>
416
+ ) : null}
417
+ {selected && composing ? (
418
+ <box style={composeStyle}>
419
+ <AnnotationCard
420
+ kind="comment"
421
+ quote={selected.quote}
422
+ draft={{
423
+ text: draftText,
424
+ onInput: setDraftText,
425
+ onSave: () => commit(draftText),
426
+ onSubmit: () => commit(draftText),
427
+ onCancel: clearSelection,
428
+ }}
429
+ theme={theme}
430
+ />
431
+ </box>
432
+ ) : null}
433
+ </box>
434
+ );
435
+ }
436
+
437
+ /**
438
+ * Memoized so an unrelated App re-render (status ticks, a rail-width drag) does
439
+ * not re-render the sheet; the parent passes a stable onCommentElement so the
440
+ * shallow prop compare holds.
441
+ */
442
+ export const PrototypeSheet = React.memo(PrototypeSheetImpl);
443
+
444
+ function statusLine(status: SheetStatus, errorMessage: string): string {
445
+ if (status === "loading") return "rendering prototype…";
446
+ if (status === "unsupported")
447
+ return "prototype preview needs a graphics terminal (kitty or ghostty)";
448
+
449
+ return `prototype preview failed: ${errorMessage}`;
450
+ }
@@ -0,0 +1,86 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import { REVIEW_MAX_WIDTH, REVIEW_MIN_WIDTH } from "../review-panel";
4
+ import type { Story, StoryMeta } from "./story";
5
+ import { ReviewPanel } from "./ReviewPanel";
6
+ import { FIXTURE_ANNOTATIONS, fixturePlanSession } from "./story-fixtures";
7
+
8
+ export const meta: StoryMeta = { title: "ReviewPanel" };
9
+
10
+ const rail = {
11
+ session: fixturePlanSession(),
12
+ authorNames: {},
13
+ selectedId: FIXTURE_ANNOTATIONS[0]!.id,
14
+ resolvedIds: new Set(FIXTURE_ANNOTATIONS.map((annotation) => annotation.id)),
15
+ curationItems: [],
16
+ railTab: "review" as const,
17
+ pendingCount: 2,
18
+ cardEdit: null,
19
+ submitConfirm: null,
20
+ onTabChange: () => {},
21
+ onSelectCard: () => {},
22
+ onActivateCard: () => {},
23
+ onSelectCuration: () => {},
24
+ onUndoCuration: () => {},
25
+ onSubmitRequest: () => {},
26
+ onLaunchHarness: () => {},
27
+ };
28
+
29
+ const panelCallbacks = { onDividerGrab: () => {}, onToggle: () => {} };
30
+
31
+ /** The plan area to the left of the divider, so the layout reads in context. */
32
+ function PanelFrame({ children }: { children: React.ReactNode }): React.ReactNode {
33
+ return (
34
+ <box
35
+ style={{
36
+ flexDirection: "row",
37
+ width: "100%",
38
+ height: "100%",
39
+ backgroundColor: DARK.background,
40
+ }}
41
+ >
42
+ <box style={{ flexGrow: 1, paddingLeft: 1 }}>
43
+ <text fg={DARK.textMuted}>The plan takes the width the panel hands back.</text>
44
+ </box>
45
+ {children}
46
+ </box>
47
+ );
48
+ }
49
+
50
+ export const ExpandedNarrow: Story = {
51
+ render: () => (
52
+ <PanelFrame>
53
+ <ReviewPanel mode="expanded" width={REVIEW_MIN_WIDTH} rail={rail} {...panelCallbacks} />
54
+ </PanelFrame>
55
+ ),
56
+ size: { width: 80, height: 24 },
57
+ };
58
+
59
+ export const ExpandedWide: Story = {
60
+ render: () => (
61
+ <PanelFrame>
62
+ <ReviewPanel mode="expanded" width={REVIEW_MAX_WIDTH} rail={rail} {...panelCallbacks} />
63
+ </PanelFrame>
64
+ ),
65
+ expectedColors: [DARK.accent],
66
+ size: { width: 90, height: 24 },
67
+ };
68
+
69
+ export const Compact: Story = {
70
+ render: () => (
71
+ <PanelFrame>
72
+ <ReviewPanel mode="compact" width={34} rail={rail} {...panelCallbacks} />
73
+ </PanelFrame>
74
+ ),
75
+ expectedColors: [DARK.accent],
76
+ size: { width: 60, height: 24 },
77
+ };
78
+
79
+ export const Hidden: Story = {
80
+ render: () => (
81
+ <PanelFrame>
82
+ <ReviewPanel mode="hidden" width={34} rail={rail} {...panelCallbacks} />
83
+ </PanelFrame>
84
+ ),
85
+ size: { width: 60, height: 24 },
86
+ };
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The review surface's outer shell: the grabbable divider plus the rail in one
3
+ * of three modes - expanded (the full ReviewRail, resizable), compact (a narrow
4
+ * count + dots strip that hands width back to the plan), or hidden (nothing at
5
+ * all, no leftover tab). The keybinding cycles all three; the clickable chevron
6
+ * toggles expanded and compact only. App owns the width/mode state and the drag
7
+ * on the container; this file only reads them. The geometry (width clamp, the
8
+ * divider glyph column, the cycle) lives in review-panel.ts so this stays
9
+ * declarative.
10
+ */
11
+
12
+ import React from "react";
13
+ import type { Annotation } from "@cueloop/schema";
14
+ import type { Theme } from "../theme";
15
+ import { useComponentTheme } from "./theme-context";
16
+ import { ReviewRail, type ReviewRailHandle, type ReviewRailProps } from "./ReviewRail";
17
+ import { REVIEW_COMPACT_WIDTH, type ReviewPanelMode } from "../review-panel";
18
+
19
+ export interface ReviewPanelProps {
20
+ mode: ReviewPanelMode;
21
+ /** Expanded-rail width in columns (already clamped by the app). */
22
+ width: number;
23
+ /** Arm a divider drag; the app tracks the drag itself on the container. */
24
+ onDividerGrab: () => void;
25
+ /** Chevron click: expanded <-> compact (never hidden). */
26
+ onToggle: () => void;
27
+ /** The expanded ReviewRail's props; width and onCollapse are supplied here. */
28
+ rail: Omit<ReviewRailProps, "width" | "onCollapse" | "theme">;
29
+ railRef?: React.Ref<ReviewRailHandle>;
30
+ theme?: Theme;
31
+ }
32
+
33
+ /** An invisible, full-height grab column: the plan's right border is the seam. */
34
+ function ReviewDivider({ onGrab }: { onGrab: () => void }): React.ReactNode {
35
+ // childless: it stretches to the row height like the plan and rail beside it,
36
+ // so the three columns share one bottom edge. Invisible, but full-height grab.
37
+ return <box style={{ width: 1 }} onMouseDown={onGrab} />;
38
+ }
39
+
40
+ /** The compact strip: the card count, one kind-colored dot per card, and the
41
+ * `<` expand chevron, bottom-padded to sit at the same row as the expanded `>`. */
42
+ function CompactRail({
43
+ annotations,
44
+ onExpand,
45
+ theme,
46
+ }: {
47
+ annotations: Annotation[];
48
+ onExpand: () => void;
49
+ theme?: Theme;
50
+ }): React.ReactNode {
51
+ const tokens = useComponentTheme(theme);
52
+
53
+ return (
54
+ <box
55
+ style={{
56
+ width: REVIEW_COMPACT_WIDTH,
57
+ backgroundColor: tokens.panel,
58
+ flexDirection: "column",
59
+ paddingTop: 1,
60
+ paddingBottom: 1,
61
+ }}
62
+ >
63
+ <box style={{ alignItems: "center" }}>
64
+ <text fg={tokens.accent}>{String(annotations.length)}</text>
65
+ </box>
66
+ <box style={{ height: 1 }} />
67
+ <box style={{ flexDirection: "column", alignItems: "center" }}>
68
+ {annotations.map((annotation) => (
69
+ <text key={annotation.id} fg={tokens.accent}>
70
+ ●
71
+ </text>
72
+ ))}
73
+ </box>
74
+ <box style={{ flexGrow: 1 }} />
75
+ <box style={{ paddingLeft: 1 }} onMouseUp={onExpand}>
76
+ <text fg={tokens.textDim}>{"<"}</text>
77
+ </box>
78
+ </box>
79
+ );
80
+ }
81
+
82
+ export function ReviewPanel({
83
+ mode,
84
+ width,
85
+ onDividerGrab,
86
+ onToggle,
87
+ rail,
88
+ railRef,
89
+ theme,
90
+ }: ReviewPanelProps): React.ReactNode {
91
+ if (mode === "hidden") return null;
92
+
93
+ return (
94
+ <>
95
+ <ReviewDivider onGrab={onDividerGrab} />
96
+ {mode === "expanded" ? (
97
+ <ReviewRail ref={railRef} {...rail} width={width} onCollapse={onToggle} theme={theme} />
98
+ ) : (
99
+ <CompactRail annotations={rail.session.annotations} onExpand={onToggle} theme={theme} />
100
+ )}
101
+ </>
102
+ );
103
+ }