@cueloop/client 0.1.0-alpha.10 → 0.1.0-alpha.12

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 (66) hide show
  1. package/package.json +10 -10
  2. package/src/App.autoclose.test.tsx +24 -35
  3. package/src/App.diff.test.tsx +5 -18
  4. package/src/App.export.test.tsx +8 -21
  5. package/src/App.plan-review.test.tsx +21 -52
  6. package/src/App.readonly.test.tsx +3 -18
  7. package/src/App.rendering.test.tsx +5 -13
  8. package/src/App.submit-confirm.test.tsx +7 -25
  9. package/src/App.test.tsx +13 -52
  10. package/src/App.tsx +197 -910
  11. package/src/components/AnnotationCard.stories.tsx +75 -0
  12. package/src/components/AnnotationCard.tsx +136 -0
  13. package/src/components/Breadcrumb.stories.tsx +19 -0
  14. package/src/components/Breadcrumb.tsx +38 -0
  15. package/src/components/CodeBlock.stories.tsx +25 -0
  16. package/src/components/CodeBlock.tsx +68 -0
  17. package/src/components/CompletionOverlay.stories.tsx +23 -0
  18. package/src/components/CompletionOverlay.tsx +50 -0
  19. package/src/components/ComposeBar.stories.tsx +18 -0
  20. package/src/components/ComposeBar.tsx +54 -0
  21. package/src/components/ConfirmCard.stories.tsx +22 -0
  22. package/src/components/ConfirmCard.tsx +130 -0
  23. package/src/components/DiffSheet.stories.tsx +44 -0
  24. package/src/components/DiffSheet.tsx +243 -0
  25. package/src/components/InboxList.stories.tsx +18 -0
  26. package/src/components/InboxList.tsx +42 -0
  27. package/src/components/PlanSheet.stories.tsx +81 -0
  28. package/src/components/PlanSheet.tsx +309 -0
  29. package/src/components/ReviewRail.stories.tsx +103 -0
  30. package/src/components/ReviewRail.tsx +158 -0
  31. package/src/components/SettingsDialog.stories.tsx +63 -0
  32. package/src/components/SettingsDialog.tsx +132 -0
  33. package/src/components/SettingsRows.stories.tsx +18 -0
  34. package/src/components/SettingsRows.tsx +92 -0
  35. package/src/components/__snapshots__/stories.test.tsx.snap +1189 -0
  36. package/src/components/format.ts +6 -0
  37. package/src/components/primitives/Button.stories.tsx +32 -0
  38. package/src/components/primitives/Button.tsx +44 -0
  39. package/src/components/primitives/Card.stories.tsx +25 -0
  40. package/src/components/primitives/Card.tsx +58 -0
  41. package/src/components/primitives/Dialog.stories.tsx +24 -0
  42. package/src/components/primitives/Dialog.tsx +52 -0
  43. package/src/components/primitives/StatusBar.stories.tsx +11 -0
  44. package/src/components/primitives/StatusBar.tsx +22 -0
  45. package/src/components/primitives/Tabs.stories.tsx +29 -0
  46. package/src/components/primitives/Tabs.tsx +97 -0
  47. package/src/components/primitives/Toolbar.stories.tsx +17 -0
  48. package/src/components/primitives/Toolbar.tsx +14 -0
  49. package/src/components/stories-app.tsx +94 -0
  50. package/src/components/stories.test.tsx +51 -0
  51. package/src/components/story-fixtures.ts +90 -0
  52. package/src/components/story.ts +66 -0
  53. package/src/components/syntax-highlight.ts +57 -0
  54. package/src/components/theme-context.stories.tsx +41 -0
  55. package/src/components/theme-context.tsx +30 -0
  56. package/src/key-bindings.test.ts +103 -0
  57. package/src/key-bindings.ts +332 -0
  58. package/src/keymap.ts +8 -2
  59. package/src/run.ts +3 -1
  60. package/src/session-controller.ts +28 -7
  61. package/src/test-support.ts +87 -0
  62. package/src/theme.ts +3 -0
  63. package/src/view.test.ts +35 -13
  64. package/src/view.ts +41 -64
  65. package/src/syntax.test.ts +0 -41
  66. package/src/syntax.ts +0 -88
@@ -0,0 +1,44 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { DiffSheet } from "./DiffSheet";
5
+ import { FIXTURE_PATCH, fixtureDiffRows } from "./story-fixtures";
6
+
7
+ export const meta: StoryMeta = { title: "DiffSheet" };
8
+
9
+ export const SignedRows: Story = {
10
+ render: () => <DiffSheet rows={fixtureDiffRows()} cursor={0} annotations={[]} />,
11
+ expectedColors: [DARK.insFg, DARK.delFg],
12
+ size: { width: 90, height: 16 },
13
+ };
14
+
15
+ export const CursorOnAddedLine: Story = {
16
+ render: () => <DiffSheet rows={fixtureDiffRows()} cursor={4} annotations={[]} />,
17
+ expectedColors: [DARK.cursorBg],
18
+ size: { width: 90, height: 16 },
19
+ };
20
+
21
+ export const AnnotatedLine: Story = {
22
+ render: () => (
23
+ <DiffSheet
24
+ rows={fixtureDiffRows()}
25
+ cursor={0}
26
+ annotations={[
27
+ {
28
+ id: "a_story_diff",
29
+ kind: "comment",
30
+ anchor: {
31
+ // diff anchors quote the row text verbatim, trailing newline included
32
+ quote: FIXTURE_PATCH.split("\n").find((line) => line.startsWith("+ "))!.slice(1) + "\n",
33
+ prefix: "",
34
+ suffix: "",
35
+ },
36
+ body: "Map needs an eviction story.",
37
+ createdAt: "2026-01-01T00:00:00Z",
38
+ },
39
+ ]}
40
+ />
41
+ ),
42
+ expectedColors: [DARK.markCommentBg],
43
+ size: { width: 90, height: 16 },
44
+ };
@@ -0,0 +1,243 @@
1
+ /**
2
+ * The diff review sheet: every row of the patch renders (no window cap)
3
+ * inside a scrollbox, with file headers, hunk headers, and contiguous line
4
+ * chunks. Line chunks draw through the native line-number gutter - custom
5
+ * numbers per row (old numbers on deletions), the cursor as a gutter sign,
6
+ * and annotation markers as line signs. Chunks split after an annotated row
7
+ * so the annotation body renders directly under its line.
8
+ */
9
+
10
+ import React, { useEffect, useMemo, useRef } from "react";
11
+ import type { LineNumberRenderable, LineSign, ScrollBoxRenderable } from "@opentui/core";
12
+ import type { Annotation } from "@cueloop/schema";
13
+ import type { DiffRow } from "../view-diff";
14
+ import type { Theme } from "../theme";
15
+ import { useComponentTheme } from "./theme-context";
16
+ import { truncate } from "./format";
17
+
18
+ export interface DiffSheetProps {
19
+ rows: DiffRow[];
20
+ cursor: number;
21
+ annotations: Annotation[];
22
+ focusedAnnotationId?: string;
23
+ theme?: Theme;
24
+ }
25
+
26
+ type DiffSegment =
27
+ | { kind: "header"; rowIndex: number; row: DiffRow }
28
+ | { kind: "chunk"; firstRowIndex: number; rows: DiffRow[]; annotation: Annotation | null };
29
+
30
+ /** Row text carries the patch's trailing newline; rendering strips it. */
31
+ function rowLine(row: DiffRow): string {
32
+ return row.text.replace(/\n$/, "");
33
+ }
34
+
35
+ /** Chunks split after an annotated row so its card can sit directly below. */
36
+ function segmentRows(rows: DiffRow[], annotatedByRow: Map<number, Annotation>): DiffSegment[] {
37
+ const segments: DiffSegment[] = [];
38
+ let chunk: DiffRow[] = [];
39
+ let chunkStart = 0;
40
+ const closeChunk = (annotation: Annotation | null): void => {
41
+ if (chunk.length) segments.push({ kind: "chunk", firstRowIndex: chunkStart, rows: chunk, annotation });
42
+ chunk = [];
43
+ };
44
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
45
+ const row = rows[rowIndex]!;
46
+ if (row.t === "file" || row.t === "hunk") {
47
+ closeChunk(null);
48
+ segments.push({ kind: "header", rowIndex, row });
49
+ chunkStart = rowIndex + 1;
50
+ continue;
51
+ }
52
+ if (!chunk.length) chunkStart = rowIndex;
53
+ chunk.push(row);
54
+ const annotation = annotatedByRow.get(rowIndex);
55
+ if (annotation) {
56
+ closeChunk(annotation);
57
+ chunkStart = rowIndex + 1;
58
+ }
59
+ }
60
+ closeChunk(null);
61
+ return segments;
62
+ }
63
+
64
+ function DiffChunk({
65
+ segment,
66
+ cursor,
67
+ focusedAnnotationId,
68
+ theme,
69
+ }: {
70
+ segment: Extract<DiffSegment, { kind: "chunk" }>;
71
+ cursor: number;
72
+ focusedAnnotationId?: string;
73
+ theme?: Theme;
74
+ }): React.ReactNode {
75
+ const tokens = useComponentTheme(theme);
76
+ const gutterRef = useRef<LineNumberRenderable | null>(null);
77
+ const cursorInChunk = cursor - segment.firstRowIndex;
78
+
79
+ const lineNumbers = useMemo(() => {
80
+ const numbers = new Map<number, number>();
81
+ segment.rows.forEach((row, lineIndex) => {
82
+ const gutterNumber = row.t === "del" ? row.oldLine : row.newLine;
83
+ if (gutterNumber !== undefined) numbers.set(lineIndex, gutterNumber);
84
+ });
85
+ return numbers;
86
+ }, [segment]);
87
+
88
+ const lineSigns = useMemo(() => {
89
+ const signs = new Map<number, LineSign>();
90
+ if (cursorInChunk >= 0 && cursorInChunk < segment.rows.length) {
91
+ signs.set(cursorInChunk, { before: "▎", beforeColor: tokens.accent });
92
+ }
93
+ if (segment.annotation) {
94
+ signs.set(segment.rows.length - 1, { after: "◆", afterColor: tokens.accent });
95
+ }
96
+ return signs;
97
+ }, [segment, cursorInChunk, tokens]);
98
+
99
+ const lineColors = useMemo(() => {
100
+ // the renderable's config parser requires the gutter key to be present
101
+ const colors = new Map<number, { gutter: string | undefined; content: string }>();
102
+ if (segment.annotation) {
103
+ colors.set(segment.rows.length - 1, { gutter: undefined, content: tokens.markCommentBg });
104
+ }
105
+ if (cursorInChunk >= 0 && cursorInChunk < segment.rows.length) {
106
+ colors.set(cursorInChunk, { gutter: tokens.cursorBg, content: tokens.cursorBg });
107
+ }
108
+ return colors;
109
+ }, [segment, cursorInChunk, tokens]);
110
+
111
+ // gutter state flows through the imperative surface: the renderable keeps
112
+ // no prop setters for these maps, so updates land via effects
113
+ useEffect(() => {
114
+ const gutter = gutterRef.current;
115
+ if (!gutter) return;
116
+ gutter.setLineNumbers(lineNumbers);
117
+ gutter.setLineSigns(lineSigns);
118
+ gutter.clearAllLineColors();
119
+ for (const [line, colorConfig] of lineColors) gutter.setLineColor(line, colorConfig);
120
+ }, [lineNumbers, lineSigns, lineColors]);
121
+
122
+ return (
123
+ <box style={{ flexDirection: "column" }}>
124
+ <line-number
125
+ ref={gutterRef}
126
+ fg={tokens.textDim}
127
+ bg={tokens.bg}
128
+ minWidth={4}
129
+ paddingRight={1}
130
+ lineNumbers={lineNumbers}
131
+ lineSigns={lineSigns}
132
+ >
133
+ <text style={{ wrapMode: "none" }} selectable={false}>
134
+ {segment.rows.map((row, lineIndex) => {
135
+ const sign = row.t === "add" ? "+" : row.t === "del" ? "-" : " ";
136
+ const foreground = row.t === "add" ? tokens.insFg : row.t === "del" ? tokens.delFg : tokens.textMuted;
137
+ const isCursorRow = lineIndex === cursorInChunk;
138
+ const isAnnotatedRow = segment.annotation !== null && lineIndex === segment.rows.length - 1;
139
+ return (
140
+ <span
141
+ key={lineIndex}
142
+ fg={foreground}
143
+ bg={isCursorRow ? tokens.cursorBg : isAnnotatedRow ? tokens.markCommentBg : undefined}
144
+ >
145
+ {(lineIndex > 0 ? "\n" : "") + sign + rowLine(row)}
146
+ </span>
147
+ );
148
+ })}
149
+ </text>
150
+ </line-number>
151
+ {segment.annotation ? (
152
+ <text>
153
+ <span fg={tokens.textDim}>{" "}</span>
154
+ <span fg={segment.annotation.id === focusedAnnotationId ? tokens.text : tokens.accent}>
155
+ ◆ {truncate(segment.annotation.body, 70)}
156
+ </span>
157
+ </text>
158
+ ) : null}
159
+ </box>
160
+ );
161
+ }
162
+
163
+ export function DiffSheet({ rows, cursor, annotations, focusedAnnotationId, theme }: DiffSheetProps): React.ReactNode {
164
+ const tokens = useComponentTheme(theme);
165
+ const scrollRef = useRef<ScrollBoxRenderable | null>(null);
166
+
167
+ const annotatedByRow = useMemo(() => {
168
+ const byRow = new Map<number, Annotation>();
169
+ for (const annotation of annotations) {
170
+ const rowIndex = rows.findIndex(
171
+ (row) => row.text === annotation.anchor.quote && (row.t === "ctx" || row.t === "add" || row.t === "del"),
172
+ );
173
+ if (rowIndex !== -1) byRow.set(rowIndex, annotation);
174
+ }
175
+ return byRow;
176
+ }, [rows, annotations]);
177
+
178
+ const segments = useMemo(() => segmentRows(rows, annotatedByRow), [rows, annotatedByRow]);
179
+
180
+ // content y offset per row index, for cursor-following scroll
181
+ const rowOffsets = useMemo(() => {
182
+ const offsets: number[] = [];
183
+ let contentY = 0;
184
+ for (const segment of segments) {
185
+ if (segment.kind === "header") {
186
+ offsets[segment.rowIndex] = contentY;
187
+ contentY += 1;
188
+ } else {
189
+ segment.rows.forEach((_, lineIndex) => {
190
+ offsets[segment.firstRowIndex + lineIndex] = contentY + lineIndex;
191
+ });
192
+ contentY += segment.rows.length + (segment.annotation ? 1 : 0);
193
+ }
194
+ }
195
+ return offsets;
196
+ }, [segments]);
197
+
198
+ useEffect(() => {
199
+ const scrollbox = scrollRef.current;
200
+ const cursorOffset = rowOffsets[cursor];
201
+ if (!scrollbox || cursorOffset === undefined) return;
202
+ const viewportHeight = Math.max(1, scrollbox.height);
203
+ if (cursorOffset < scrollbox.scrollTop + 2) {
204
+ scrollbox.scrollTo({ x: 0, y: Math.max(0, cursorOffset - 2) });
205
+ } else if (cursorOffset > scrollbox.scrollTop + viewportHeight - 3) {
206
+ scrollbox.scrollTo({ x: 0, y: cursorOffset - viewportHeight + 3 });
207
+ }
208
+ }, [cursor, rowOffsets]);
209
+
210
+ return (
211
+ <box style={{ flexGrow: 1, flexDirection: "column", paddingLeft: 1, paddingTop: 1 }}>
212
+ <scrollbox ref={scrollRef} style={{ flexGrow: 1 }} focused={false}>
213
+ {segments.map((segment, segmentIndex) => {
214
+ if (segment.kind === "header") {
215
+ const isCursor = segment.rowIndex === cursor;
216
+ if (segment.row.t === "file") {
217
+ return (
218
+ <text key={segmentIndex} fg={tokens.text} bg={isCursor ? tokens.cursorBg : tokens.panel}>
219
+ {isCursor ? "▎" : " "}■ {rowLine(segment.row)}
220
+ </text>
221
+ );
222
+ }
223
+ return (
224
+ <text key={segmentIndex} fg={tokens.blue} bg={isCursor ? tokens.cursorBg : undefined}>
225
+ {isCursor ? "▎" : " "}
226
+ {rowLine(segment.row)}
227
+ </text>
228
+ );
229
+ }
230
+ return (
231
+ <DiffChunk
232
+ key={segmentIndex}
233
+ segment={segment}
234
+ cursor={cursor}
235
+ focusedAnnotationId={focusedAnnotationId}
236
+ theme={theme}
237
+ />
238
+ );
239
+ })}
240
+ </scrollbox>
241
+ </box>
242
+ );
243
+ }
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { InboxList } from "./InboxList";
5
+ import { fixtureDiffSession, fixturePlanSession } from "./story-fixtures";
6
+
7
+ export const meta: StoryMeta = { title: "InboxList" };
8
+
9
+ export const TwoPending: Story = {
10
+ render: () => <InboxList inbox={[fixturePlanSession(), fixtureDiffSession()]} cursor={0} />,
11
+ expectedColors: [DARK.accent, DARK.cursorBg],
12
+ size: { width: 80, height: 12 },
13
+ };
14
+
15
+ export const Empty: Story = {
16
+ render: () => <InboxList inbox={[]} cursor={0} />,
17
+ size: { width: 80, height: 8 },
18
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The pending-review inbox: a cursor-driven session list. Selection stays
3
+ * with the keyboard grammar; the list only renders the snapshot.
4
+ */
5
+
6
+ import React from "react";
7
+ import type { ReviewSession } from "@cueloop/schema";
8
+ import type { Theme } from "../theme";
9
+ import { useComponentTheme } from "./theme-context";
10
+ import { StatusBar } from "./primitives/StatusBar";
11
+
12
+ export interface InboxListProps {
13
+ inbox: ReviewSession[];
14
+ cursor: number;
15
+ theme?: Theme;
16
+ }
17
+
18
+ export function InboxList({ inbox, cursor, theme }: InboxListProps): React.ReactNode {
19
+ const tokens = useComponentTheme(theme);
20
+ return (
21
+ <box style={{ flexDirection: "column", width: "100%", height: "100%", backgroundColor: tokens.bg, padding: 1 }}>
22
+ <text fg={tokens.accent}>cueloop · inbox ({inbox.length} pending)</text>
23
+ <text> </text>
24
+ {inbox.length === 0 ? (
25
+ <text fg={tokens.textDim}>nothing waiting for review</text>
26
+ ) : (
27
+ inbox.map((session, index) => (
28
+ <text
29
+ key={session.id}
30
+ fg={index === cursor ? tokens.text : tokens.textMuted}
31
+ bg={index === cursor ? tokens.cursorBg : undefined}
32
+ >
33
+ {index === cursor ? "▸ " : " "}
34
+ {session.artifact.meta.title ?? session.id} · {session.workspace.branch} · {session.artifact.type}
35
+ </text>
36
+ ))
37
+ )}
38
+ <box style={{ flexGrow: 1 }} />
39
+ <StatusBar theme={theme}>j/k move · ⏎ open · q quit</StatusBar>
40
+ </box>
41
+ );
42
+ }
@@ -0,0 +1,81 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { PlanSheet } from "./PlanSheet";
5
+ import { fixtureDisplay, fixtureMarks, fixturePlanSession } from "./story-fixtures";
6
+
7
+ export const meta: StoryMeta = { title: "PlanSheet" };
8
+
9
+ const callbacks = { onLineActivate: () => {}, onEditRequest: () => {} };
10
+
11
+ export const AnnotatedPlan: Story = {
12
+ render: () => (
13
+ <PlanSheet
14
+ session={fixturePlanSession()}
15
+ display={fixtureDisplay()}
16
+ marks={fixtureMarks()}
17
+ cursor={2}
18
+ activeSpan={null}
19
+ compose={null}
20
+ editOrphanCount={0}
21
+ {...callbacks}
22
+ />
23
+ ),
24
+ expectedColors: [DARK.markCommentBg, DARK.markSuggestionBg, DARK.cursorBg],
25
+ size: { width: 90, height: 28 },
26
+ };
27
+
28
+ export const SpanSelection: Story = {
29
+ render: () => (
30
+ <PlanSheet
31
+ session={fixturePlanSession({ annotations: [] })}
32
+ display={fixtureDisplay()}
33
+ marks={new Map()}
34
+ cursor={2}
35
+ activeSpan={{ dispIdx: 2, start: 0, end: 10 }}
36
+ compose={null}
37
+ editOrphanCount={0}
38
+ {...callbacks}
39
+ />
40
+ ),
41
+ expectedColors: [DARK.accent],
42
+ size: { width: 90, height: 28 },
43
+ };
44
+
45
+ export const InlineCompose: Story = {
46
+ render: () => (
47
+ <PlanSheet
48
+ session={fixturePlanSession({ annotations: [] })}
49
+ display={fixtureDisplay()}
50
+ marks={new Map()}
51
+ cursor={2}
52
+ activeSpan={{ dispIdx: 2, start: 0, end: 10 }}
53
+ compose={{
54
+ kind: "comment",
55
+ dispIdx: 2,
56
+ quote: "The daemon",
57
+ draft: { text: "Which daemon?", onInput: () => {}, onSave: () => {}, onCancel: () => {} },
58
+ }}
59
+ editOrphanCount={0}
60
+ {...callbacks}
61
+ />
62
+ ),
63
+ size: { width: 90, height: 30 },
64
+ };
65
+
66
+ export const OrphanBanner: Story = {
67
+ render: () => (
68
+ <PlanSheet
69
+ session={fixturePlanSession()}
70
+ display={fixtureDisplay()}
71
+ marks={new Map()}
72
+ cursor={0}
73
+ activeSpan={null}
74
+ compose={null}
75
+ editOrphanCount={1}
76
+ {...callbacks}
77
+ />
78
+ ),
79
+ expectedColors: [DARK.red],
80
+ size: { width: 90, height: 28 },
81
+ };