@cueloop/client 0.1.0-alpha.3 → 0.1.0-alpha.30

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 (105) hide show
  1. package/package.json +17 -11
  2. package/src/App.autoclose.test.tsx +133 -0
  3. package/src/App.diff.test.tsx +27 -20
  4. package/src/App.export.test.tsx +19 -28
  5. package/src/App.plan-review.test.tsx +507 -0
  6. package/src/App.readonly.test.tsx +26 -27
  7. package/src/App.rendering.test.tsx +119 -0
  8. package/src/App.review-panel.test.tsx +123 -0
  9. package/src/App.submit-confirm.test.tsx +216 -0
  10. package/src/App.test.tsx +83 -64
  11. package/src/App.tsx +0 -0
  12. package/src/App.walk.test.tsx +265 -0
  13. package/src/attribution.test.ts +31 -0
  14. package/src/attribution.ts +32 -0
  15. package/src/clipboard.test.ts +23 -0
  16. package/src/clipboard.ts +26 -0
  17. package/src/components/AnnotationCard.compose-rows.test.ts +49 -0
  18. package/src/components/AnnotationCard.stories.tsx +75 -0
  19. package/src/components/AnnotationCard.tsx +208 -0
  20. package/src/components/Breadcrumb.stories.tsx +19 -0
  21. package/src/components/Breadcrumb.tsx +38 -0
  22. package/src/components/CodeBlock.stories.tsx +25 -0
  23. package/src/components/CodeBlock.tsx +68 -0
  24. package/src/components/CompletionOverlay.stories.tsx +23 -0
  25. package/src/components/CompletionOverlay.tsx +49 -0
  26. package/src/components/ComposeBar.stories.tsx +18 -0
  27. package/src/components/ComposeBar.tsx +54 -0
  28. package/src/components/ConfirmCard.stories.tsx +37 -0
  29. package/src/components/ConfirmCard.tsx +117 -0
  30. package/src/components/ConfirmDialog.stories.tsx +21 -0
  31. package/src/components/ConfirmDialog.tsx +56 -0
  32. package/src/components/DiffSheet.stories.tsx +44 -0
  33. package/src/components/DiffSheet.tsx +243 -0
  34. package/src/components/InboxList.stories.tsx +18 -0
  35. package/src/components/InboxList.tsx +55 -0
  36. package/src/components/PlanSheet.stories.tsx +81 -0
  37. package/src/components/PlanSheet.tsx +329 -0
  38. package/src/components/PromptDialog.stories.tsx +36 -0
  39. package/src/components/PromptDialog.tsx +62 -0
  40. package/src/components/ReviewPanel.stories.tsx +87 -0
  41. package/src/components/ReviewPanel.tsx +116 -0
  42. package/src/components/ReviewRail.stories.tsx +107 -0
  43. package/src/components/ReviewRail.tsx +180 -0
  44. package/src/components/SettingsDialog.stories.tsx +63 -0
  45. package/src/components/SettingsDialog.tsx +132 -0
  46. package/src/components/SettingsRows.stories.tsx +18 -0
  47. package/src/components/SettingsRows.tsx +92 -0
  48. package/src/components/WalkWizard.stories.tsx +89 -0
  49. package/src/components/WalkWizard.tsx +146 -0
  50. package/src/components/__snapshots__/stories.test.tsx.snap +1519 -0
  51. package/src/components/primitives/Button.stories.tsx +32 -0
  52. package/src/components/primitives/Button.tsx +44 -0
  53. package/src/components/primitives/Card.stories.tsx +25 -0
  54. package/src/components/primitives/Card.tsx +59 -0
  55. package/src/components/primitives/Dialog.stories.tsx +24 -0
  56. package/src/components/primitives/Dialog.tsx +53 -0
  57. package/src/components/primitives/StatusBar.stories.tsx +11 -0
  58. package/src/components/primitives/StatusBar.tsx +22 -0
  59. package/src/components/primitives/Tabs.stories.tsx +29 -0
  60. package/src/components/primitives/Tabs.tsx +97 -0
  61. package/src/components/primitives/Toolbar.stories.tsx +17 -0
  62. package/src/components/primitives/Toolbar.tsx +14 -0
  63. package/src/components/primitives/frame.test.ts +12 -0
  64. package/src/components/primitives/frame.ts +14 -0
  65. package/src/components/stories-app.tsx +95 -0
  66. package/src/components/stories.test.tsx +56 -0
  67. package/src/components/story-fixtures.ts +90 -0
  68. package/src/components/story.ts +66 -0
  69. package/src/components/syntax-highlight.ts +57 -0
  70. package/src/components/theme-context.stories.tsx +41 -0
  71. package/src/components/theme-context.tsx +30 -0
  72. package/src/components/truncate-text.ts +6 -0
  73. package/src/config.test.ts +196 -30
  74. package/src/config.ts +128 -16
  75. package/src/editor.test.ts +134 -0
  76. package/src/editor.ts +101 -13
  77. package/src/herdr.test.ts +41 -0
  78. package/src/herdr.ts +21 -0
  79. package/src/index.ts +2 -0
  80. package/src/integrations.test.ts +41 -0
  81. package/src/integrations.ts +28 -0
  82. package/src/intent-dispatch.test.ts +308 -0
  83. package/src/intent-dispatch.ts +295 -0
  84. package/src/key-bindings.test.ts +142 -0
  85. package/src/key-bindings.ts +363 -0
  86. package/src/keymap.test.ts +477 -0
  87. package/src/keymap.ts +272 -0
  88. package/src/review-panel.test.ts +111 -0
  89. package/src/review-panel.ts +76 -0
  90. package/src/run.ts +9 -5
  91. package/src/serve.test.ts +13 -6
  92. package/src/serve.ts +7 -7
  93. package/src/session-controller.share.test.ts +248 -0
  94. package/src/session-controller.ts +607 -0
  95. package/src/share.ts +80 -0
  96. package/src/test-support.ts +87 -0
  97. package/src/theme.ts +23 -1
  98. package/src/view-diff.test.ts +19 -8
  99. package/src/view-diff.ts +22 -22
  100. package/src/view-plan.test.ts +260 -0
  101. package/src/view-plan.ts +365 -0
  102. package/src/walk.test.ts +116 -0
  103. package/src/walk.ts +65 -0
  104. package/src/view.test.ts +0 -157
  105. package/src/view.ts +0 -0
@@ -0,0 +1,117 @@
1
+ /**
2
+ * The Submit button expanded into a bordered confirm card at the rail bottom:
3
+ * honest counts, the verdict selector (arrow keys or click), the optional
4
+ * summary, and plain word-buttons - key hints live in the status line only.
5
+ * The bordered height derives from the content rows through Card, so layout
6
+ * and render never drift.
7
+ */
8
+
9
+ import React from "react";
10
+ import type { VerdictKind } from "@cueloop/schema";
11
+ import type { Theme } from "../theme";
12
+ import { useComponentTheme } from "./theme-context";
13
+ import { Card } from "./primitives/Card";
14
+ import { Button } from "./primitives/Button";
15
+ import { Toolbar } from "./primitives/Toolbar";
16
+
17
+ export const VERDICTS: VerdictKind[] = ["comment", "approve", "request_changes"];
18
+
19
+ /** Selector words in the confirm card - one word per verdict. */
20
+ export const VERDICT_LABEL: Record<VerdictKind, string> = {
21
+ comment: "Comment",
22
+ approve: "Approve",
23
+ request_changes: "Changes",
24
+ };
25
+
26
+ export interface ConfirmCardProps {
27
+ verdict: VerdictKind;
28
+ summary: string;
29
+ annotationCount: number;
30
+ blockingCount: number;
31
+ /**
32
+ * The guided walk's honest coverage line for diff sessions, e.g.
33
+ * "2/3 files viewed". Undefined = no walk data, the row does not render.
34
+ */
35
+ viewedSummary?: string;
36
+ onInput: (summary: string) => void;
37
+ onSelectVerdict: (verdict: VerdictKind) => void;
38
+ onSubmit: () => void;
39
+ onCancel: () => void;
40
+ theme?: Theme;
41
+ }
42
+
43
+ /** Counts, spacer, 1-row verdict selector, spacer, summary input, spacer, buttons. */
44
+ const CONFIRM_CONTENT_ROWS = 7;
45
+
46
+ export function verdictColor(verdict: VerdictKind, tokens: Theme): string {
47
+ return verdict === "approve" ? tokens.green : verdict === "request_changes" ? tokens.red : tokens.blue;
48
+ }
49
+
50
+ /**
51
+ * The verdict selector: one row of pressable words, matching the reading
52
+ * direction of a choice between three peers. Selection stays controlled by
53
+ * the grammar (←/→ cycle the verdict); a click selects directly. The
54
+ * selected verdict wears brackets and its color.
55
+ */
56
+ function VerdictSelector({
57
+ verdict,
58
+ onSelectVerdict,
59
+ theme,
60
+ }: {
61
+ verdict: VerdictKind;
62
+ onSelectVerdict: (verdict: VerdictKind) => void;
63
+ theme?: Theme;
64
+ }): React.ReactNode {
65
+ const tokens = useComponentTheme(theme);
66
+ return (
67
+ <box style={{ flexDirection: "row", height: 1 }}>
68
+ {VERDICTS.map((candidate) => (
69
+ <box key={candidate} style={{ paddingRight: 1 }} onMouseUp={() => onSelectVerdict(candidate)}>
70
+ <text fg={candidate === verdict ? verdictColor(candidate, tokens) : tokens.textDim}>
71
+ {candidate === verdict ? `[${VERDICT_LABEL[candidate]}]` : ` ${VERDICT_LABEL[candidate]} `}
72
+ </text>
73
+ </box>
74
+ ))}
75
+ </box>
76
+ );
77
+ }
78
+
79
+ export function ConfirmCard({
80
+ verdict,
81
+ summary,
82
+ annotationCount,
83
+ blockingCount,
84
+ viewedSummary,
85
+ onInput,
86
+ onSelectVerdict,
87
+ onSubmit,
88
+ onCancel,
89
+ theme,
90
+ }: ConfirmCardProps): React.ReactNode {
91
+ const tokens = useComponentTheme(theme);
92
+ return (
93
+ <Card
94
+ title=" submit review "
95
+ contentRows={CONFIRM_CONTENT_ROWS + (viewedSummary !== undefined ? 1 : 0)}
96
+ borderColor={tokens.accent}
97
+ marginRight={1}
98
+ theme={theme}
99
+ >
100
+ <text fg={tokens.textDim}>{`${annotationCount} annotations · ${blockingCount} blocking`}</text>
101
+ {viewedSummary !== undefined ? <text fg={tokens.textDim}>{viewedSummary}</text> : null}
102
+ <box style={{ height: 1 }} />
103
+ <VerdictSelector verdict={verdict} onSelectVerdict={onSelectVerdict} theme={theme} />
104
+ <box style={{ height: 1 }} />
105
+ <input focused value={summary} onInput={onInput} placeholder="summary for the agent (optional)" />
106
+ <box style={{ height: 1 }} />
107
+ <Toolbar>
108
+ <Button variant="solid" marginRight={2} onPress={onSubmit} theme={theme}>
109
+ {" Submit "}
110
+ </Button>
111
+ <Button onPress={onCancel} theme={theme}>
112
+ {" Cancel "}
113
+ </Button>
114
+ </Toolbar>
115
+ </Card>
116
+ );
117
+ }
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { ConfirmDialog } from "./ConfirmDialog";
5
+
6
+ export const meta: StoryMeta = { title: "ConfirmDialog" };
7
+
8
+ const callbacks = { onConfirm: () => {}, onCancel: () => {} };
9
+
10
+ export const DeletePlan: Story = {
11
+ render: () => (
12
+ <ConfirmDialog
13
+ isOpen
14
+ title=" Delete plan "
15
+ message={'Delete "Auth rollout"? This removes the plan and its review.'}
16
+ {...callbacks}
17
+ />
18
+ ),
19
+ expectedColors: [DARK.backdrop, DARK.panel, DARK.accent],
20
+ size: { width: 64, height: 16 },
21
+ };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * A centered yes/no confirmation on the shared Dialog overlay. Presentational:
3
+ * the key grammar (⏎ confirm, esc cancel) is driven by the reducer; the buttons
4
+ * carry the same intents for the mouse. Used for destructive actions like the
5
+ * inbox delete.
6
+ */
7
+
8
+ import React from "react";
9
+ import { useTerminalDimensions } from "@opentui/react";
10
+ import type { Theme } from "../theme";
11
+ import { useComponentTheme } from "./theme-context";
12
+ import { Dialog } from "./primitives/Dialog";
13
+ import { Button } from "./primitives/Button";
14
+ import { Toolbar } from "./primitives/Toolbar";
15
+
16
+ export interface ConfirmDialogProps {
17
+ isOpen: boolean;
18
+ title?: string;
19
+ message: string;
20
+ confirmLabel?: string;
21
+ cancelLabel?: string;
22
+ onConfirm: () => void;
23
+ onCancel: () => void;
24
+ theme?: Theme;
25
+ }
26
+
27
+ export function ConfirmDialog({
28
+ isOpen,
29
+ title,
30
+ message,
31
+ confirmLabel = "Delete",
32
+ cancelLabel = "Cancel",
33
+ onConfirm,
34
+ onCancel,
35
+ theme,
36
+ }: ConfirmDialogProps): React.ReactNode {
37
+ const tokens = useComponentTheme(theme);
38
+ const { width: terminalWidth } = useTerminalDimensions();
39
+ if (!isOpen) return null;
40
+ return (
41
+ <Dialog isOpen title={title} width={Math.min(54, terminalWidth - 6)} height={7} theme={theme}>
42
+ <box style={{ flexDirection: "column", flexGrow: 1, paddingLeft: 1, paddingRight: 1, paddingTop: 1 }}>
43
+ <text fg={tokens.text}>{message}</text>
44
+ <box style={{ flexGrow: 1 }} />
45
+ <Toolbar>
46
+ <Button variant="solid" onPress={onConfirm} theme={theme}>
47
+ {` ${confirmLabel} ⏎ `}
48
+ </Button>
49
+ <Button onPress={onCancel} theme={theme}>
50
+ {` ${cancelLabel} esc `}
51
+ </Button>
52
+ </Toolbar>
53
+ </box>
54
+ </Dialog>
55
+ );
56
+ }
@@ -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 { truncateToSingleLine } from "./truncate-text";
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.kind === "file" || row.kind === "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.kind === "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.kind === "add" ? "+" : row.kind === "del" ? "-" : " ";
136
+ const foreground = row.kind === "add" ? tokens.insFg : row.kind === "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
+ ◆ {truncateToSingleLine(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.kind === "ctx" || row.kind === "add" || row.kind === "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.kind === "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,55 @@
1
+ /**
2
+ * The pending-review inbox: a cursor-driven session list. Selection stays with
3
+ * the keyboard grammar; the list only renders the snapshot. The selected row
4
+ * carries a [delete] word-button (click, or `d` in the grammar) that asks the
5
+ * caller to confirm removal.
6
+ */
7
+
8
+ import React from "react";
9
+ import type { ReviewSession } from "@cueloop/schema";
10
+ import type { Theme } from "../theme";
11
+ import { useComponentTheme } from "./theme-context";
12
+ import { StatusBar } from "./primitives/StatusBar";
13
+ import { Button } from "./primitives/Button";
14
+
15
+ export interface InboxListProps {
16
+ inbox: ReviewSession[];
17
+ cursor: number;
18
+ /** Ask to delete a plan (the selected row's [delete] button). */
19
+ onRequestDelete?: (id: string, title: string) => void;
20
+ theme?: Theme;
21
+ }
22
+
23
+ export function InboxList({ inbox, cursor, onRequestDelete, theme }: InboxListProps): React.ReactNode {
24
+ const tokens = useComponentTheme(theme);
25
+ return (
26
+ <box style={{ flexDirection: "column", width: "100%", height: "100%", backgroundColor: tokens.bg, padding: 1 }}>
27
+ <text fg={tokens.accent}>cueloop · inbox ({inbox.length} pending)</text>
28
+ <text> </text>
29
+ {inbox.length === 0 ? (
30
+ <text fg={tokens.textDim}>nothing waiting for review</text>
31
+ ) : (
32
+ inbox.map((session, index) => {
33
+ const selected = index === cursor;
34
+ const title = session.artifact.meta.title ?? session.id;
35
+ return (
36
+ <box key={session.id} style={{ flexDirection: "row", backgroundColor: selected ? tokens.cursorBg : undefined }}>
37
+ <text fg={selected ? tokens.text : tokens.textMuted}>
38
+ {selected ? "▸ " : " "}
39
+ {title} · {session.workspace.branch} · {session.artifact.type}
40
+ </text>
41
+ <box style={{ flexGrow: 1 }} />
42
+ {selected && onRequestDelete ? (
43
+ <Button onPress={() => onRequestDelete(session.id, title)} theme={theme}>
44
+ {" [delete] "}
45
+ </Button>
46
+ ) : null}
47
+ </box>
48
+ );
49
+ })
50
+ )}
51
+ <box style={{ flexGrow: 1 }} />
52
+ <StatusBar theme={theme}>j/k move · ⏎ open · d delete · q quit</StatusBar>
53
+ </box>
54
+ );
55
+ }
@@ -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: () => {}, onShareRequest: () => {}, canEdit: true };
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={{ displayIndex: 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={{ displayIndex: 2, start: 0, end: 10 }}
53
+ compose={{
54
+ kind: "comment",
55
+ displayIndex: 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
+ };