@cueloop/client 0.1.0-alpha.2 → 0.1.0-alpha.20

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 (84) hide show
  1. package/package.json +17 -11
  2. package/src/App.autoclose.test.tsx +109 -0
  3. package/src/App.diff.test.tsx +5 -18
  4. package/src/App.export.test.tsx +8 -13
  5. package/src/App.plan-review.test.tsx +232 -0
  6. package/src/App.readonly.test.tsx +6 -21
  7. package/src/App.rendering.test.tsx +100 -0
  8. package/src/App.submit-confirm.test.tsx +165 -0
  9. package/src/App.test.tsx +20 -58
  10. package/src/App.tsx +0 -0
  11. package/src/App.walk.test.tsx +208 -0
  12. package/src/components/AnnotationCard.stories.tsx +75 -0
  13. package/src/components/AnnotationCard.tsx +136 -0
  14. package/src/components/Breadcrumb.stories.tsx +19 -0
  15. package/src/components/Breadcrumb.tsx +38 -0
  16. package/src/components/CodeBlock.stories.tsx +25 -0
  17. package/src/components/CodeBlock.tsx +68 -0
  18. package/src/components/CompletionOverlay.stories.tsx +23 -0
  19. package/src/components/CompletionOverlay.tsx +49 -0
  20. package/src/components/ComposeBar.stories.tsx +18 -0
  21. package/src/components/ComposeBar.tsx +54 -0
  22. package/src/components/ConfirmCard.stories.tsx +37 -0
  23. package/src/components/ConfirmCard.tsx +117 -0
  24. package/src/components/DiffSheet.stories.tsx +44 -0
  25. package/src/components/DiffSheet.tsx +243 -0
  26. package/src/components/InboxList.stories.tsx +18 -0
  27. package/src/components/InboxList.tsx +42 -0
  28. package/src/components/PlanSheet.stories.tsx +81 -0
  29. package/src/components/PlanSheet.tsx +309 -0
  30. package/src/components/ReviewRail.stories.tsx +103 -0
  31. package/src/components/ReviewRail.tsx +158 -0
  32. package/src/components/SettingsDialog.stories.tsx +63 -0
  33. package/src/components/SettingsDialog.tsx +132 -0
  34. package/src/components/SettingsRows.stories.tsx +18 -0
  35. package/src/components/SettingsRows.tsx +92 -0
  36. package/src/components/WalkWizard.stories.tsx +89 -0
  37. package/src/components/WalkWizard.tsx +146 -0
  38. package/src/components/__snapshots__/stories.test.tsx.snap +1319 -0
  39. package/src/components/primitives/Button.stories.tsx +32 -0
  40. package/src/components/primitives/Button.tsx +44 -0
  41. package/src/components/primitives/Card.stories.tsx +25 -0
  42. package/src/components/primitives/Card.tsx +58 -0
  43. package/src/components/primitives/Dialog.stories.tsx +24 -0
  44. package/src/components/primitives/Dialog.tsx +52 -0
  45. package/src/components/primitives/StatusBar.stories.tsx +11 -0
  46. package/src/components/primitives/StatusBar.tsx +22 -0
  47. package/src/components/primitives/Tabs.stories.tsx +29 -0
  48. package/src/components/primitives/Tabs.tsx +97 -0
  49. package/src/components/primitives/Toolbar.stories.tsx +17 -0
  50. package/src/components/primitives/Toolbar.tsx +14 -0
  51. package/src/components/stories-app.tsx +94 -0
  52. package/src/components/stories.test.tsx +51 -0
  53. package/src/components/story-fixtures.ts +90 -0
  54. package/src/components/story.ts +66 -0
  55. package/src/components/syntax-highlight.ts +57 -0
  56. package/src/components/theme-context.stories.tsx +41 -0
  57. package/src/components/theme-context.tsx +30 -0
  58. package/src/components/truncate-text.ts +6 -0
  59. package/src/config.test.ts +54 -29
  60. package/src/config.ts +53 -13
  61. package/src/editor.test.ts +110 -0
  62. package/src/editor.ts +101 -13
  63. package/src/herdr.test.ts +37 -0
  64. package/src/herdr.ts +21 -0
  65. package/src/integrations.test.ts +29 -0
  66. package/src/integrations.ts +28 -0
  67. package/src/key-bindings.test.ts +120 -0
  68. package/src/key-bindings.ts +353 -0
  69. package/src/keymap.test.ts +307 -0
  70. package/src/keymap.ts +204 -0
  71. package/src/run.ts +9 -5
  72. package/src/serve.test.ts +6 -6
  73. package/src/serve.ts +7 -7
  74. package/src/session-controller.ts +496 -0
  75. package/src/test-support.ts +87 -0
  76. package/src/theme.ts +23 -1
  77. package/src/view-diff.test.ts +8 -8
  78. package/src/view-diff.ts +22 -22
  79. package/src/view-plan.test.ts +179 -0
  80. package/src/view-plan.ts +362 -0
  81. package/src/walk.test.ts +110 -0
  82. package/src/walk.ts +65 -0
  83. package/src/view.test.ts +0 -157
  84. package/src/view.ts +0 -0
@@ -0,0 +1,136 @@
1
+ /**
2
+ * One annotation component in three modes: a draft composer (bordered card
3
+ * inline in the document flow), a saved rail card, and the rail card editing
4
+ * its body in place. Compose, saved, and re-edit share this rendering path,
5
+ * so the kind-color and quote treatment can never drift between them.
6
+ *
7
+ * Bodies are multiline: the composer is a textarea (wrap, undo/redo,
8
+ * shift+⏎ for a new line) while plain ⏎ stays the save key.
9
+ */
10
+
11
+ import React, { useEffect, useRef } from "react";
12
+ import type { KeyBinding, TextareaRenderable } from "@opentui/core";
13
+ import type { Theme } from "../theme";
14
+ import { useComponentTheme } from "./theme-context";
15
+ import { Card } from "./primitives/Card";
16
+ import { Button } from "./primitives/Button";
17
+ import { Toolbar } from "./primitives/Toolbar";
18
+ import { truncateToSingleLine } from "./truncate-text";
19
+
20
+ export interface AnnotationDraft {
21
+ text: string;
22
+ onInput: (text: string) => void;
23
+ onSave: () => void;
24
+ onCancel: () => void;
25
+ }
26
+
27
+ export interface AnnotationSaved {
28
+ body: string;
29
+ isSelected: boolean;
30
+ isOrphan: boolean;
31
+ isBlocking: boolean;
32
+ /** Non-null while the card body is being rewritten in place. */
33
+ editing: AnnotationDraft | null;
34
+ onPress: () => void;
35
+ }
36
+
37
+ export interface AnnotationCardProps {
38
+ id?: string;
39
+ kind: string;
40
+ quote: string;
41
+ draft?: AnnotationDraft;
42
+ saved?: AnnotationSaved;
43
+ theme?: Theme;
44
+ }
45
+
46
+ /** ⏎ saves (the grammar owns it); shift+⏎ makes the body multiline. */
47
+ const COMPOSE_KEY_BINDINGS: KeyBinding[] = [
48
+ { name: "return", action: "submit" },
49
+ { name: "return", shift: true, action: "newline" },
50
+ ];
51
+
52
+ function editorRows(text: string): number {
53
+ return Math.min(4, Math.max(1, text.split("\n").length));
54
+ }
55
+
56
+ function DraftEditor({ draft, theme }: { draft: AnnotationDraft; theme?: Theme }): React.ReactNode {
57
+ const tokens = useComponentTheme(theme);
58
+ const editorRef = useRef<TextareaRenderable | null>(null);
59
+ // re-edit opens with the caret after the existing body, like a text field
60
+ const initialTextLength = useRef(draft.text.length);
61
+ useEffect(() => {
62
+ const editor = editorRef.current;
63
+ if (editor) editor.cursorOffset = initialTextLength.current;
64
+ }, []);
65
+ return (
66
+ <>
67
+ <textarea
68
+ ref={editorRef}
69
+ focused
70
+ initialValue={draft.text}
71
+ placeholder="write a note..."
72
+ keyBindings={COMPOSE_KEY_BINDINGS}
73
+ onContentChange={() => {
74
+ const editor = editorRef.current;
75
+ if (editor) draft.onInput(editor.plainText);
76
+ }}
77
+ style={{
78
+ height: editorRows(draft.text),
79
+ backgroundColor: tokens.elevated,
80
+ focusedBackgroundColor: tokens.elevated,
81
+ textColor: tokens.text,
82
+ focusedTextColor: tokens.text,
83
+ }}
84
+ />
85
+ <Toolbar>
86
+ <Button variant="solid" marginRight={2} onPress={draft.onSave} theme={theme}>
87
+ {" Save ⏎ "}
88
+ </Button>
89
+ <Button onPress={draft.onCancel} theme={theme}>
90
+ {" Cancel esc "}
91
+ </Button>
92
+ </Toolbar>
93
+ </>
94
+ );
95
+ }
96
+
97
+ export function AnnotationCard({ id, kind, quote, draft, saved, theme }: AnnotationCardProps): React.ReactNode {
98
+ const tokens = useComponentTheme(theme);
99
+ const kindColor = kind === "suggestion" ? tokens.green : tokens.accent;
100
+ if (draft) {
101
+ const verb = kind === "suggestion" ? "suggest replacement for" : "comment on";
102
+ return (
103
+ <Card
104
+ title={` ${verb} "${truncateToSingleLine(quote, 40)}" `}
105
+ contentRows={editorRows(draft.text) + 1}
106
+ borderColor={kindColor}
107
+ marginLeft={2}
108
+ marginRight={2}
109
+ theme={theme}
110
+ >
111
+ <DraftEditor draft={draft} theme={theme} />
112
+ </Card>
113
+ );
114
+ }
115
+ const card = saved!;
116
+ return (
117
+ <box
118
+ id={id}
119
+ style={{ flexDirection: "column", marginBottom: 1, backgroundColor: card.isSelected ? tokens.elevated : undefined }}
120
+ onMouseUp={card.onPress}
121
+ >
122
+ <text fg={card.isSelected ? tokens.text : kindColor}>
123
+ {card.isSelected ? "▸ " : " "}
124
+ {kind.toUpperCase()}
125
+ {card.isBlocking ? <span fg={tokens.red}> · BLOCKING</span> : null}
126
+ <span fg={tokens.textDim}>{card.isOrphan ? " · ORPHANED" : " · pending"}</span>
127
+ </text>
128
+ <text fg={tokens.textDim}> "{truncateToSingleLine(quote, 26)}"</text>
129
+ {card.editing ? (
130
+ <DraftEditor draft={card.editing} theme={theme} />
131
+ ) : (
132
+ <text fg={card.isOrphan ? tokens.textDim : tokens.textMuted}> {truncateToSingleLine(card.body, 28)}</text>
133
+ )}
134
+ </box>
135
+ );
136
+ }
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { Breadcrumb } from "./Breadcrumb";
5
+
6
+ export const meta: StoryMeta = { title: "Breadcrumb" };
7
+
8
+ export const SessionHeader: Story = {
9
+ render: () => (
10
+ <Breadcrumb
11
+ items={[
12
+ { label: "cueloop", tone: "accent" },
13
+ { label: "Migration Plan · rev 2", tone: "dim" },
14
+ { label: "resolved: approve", tone: "green" },
15
+ ]}
16
+ />
17
+ ),
18
+ expectedColors: [DARK.accent, DARK.green, DARK.panel],
19
+ };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * One-row breadcrumb trail: toned segments joined by " · " on the panel
3
+ * surface. The app header is a breadcrumb (product · artifact · revision)
4
+ * followed by state badges; each item picks a semantic tone.
5
+ */
6
+
7
+ import React from "react";
8
+ import type { Theme } from "../theme";
9
+ import { useComponentTheme } from "./theme-context";
10
+
11
+ export type BreadcrumbTone = "accent" | "dim" | "text" | "green";
12
+
13
+ export interface BreadcrumbItem {
14
+ label: string;
15
+ tone?: BreadcrumbTone;
16
+ }
17
+
18
+ export interface BreadcrumbProps {
19
+ items: BreadcrumbItem[];
20
+ theme?: Theme;
21
+ }
22
+
23
+ export function Breadcrumb({ items, theme }: BreadcrumbProps): React.ReactNode {
24
+ const tokens = useComponentTheme(theme);
25
+ const toneColor = (tone?: BreadcrumbTone): string =>
26
+ tone === "accent" ? tokens.accent : tone === "green" ? tokens.green : tone === "text" ? tokens.text : tokens.textDim;
27
+ return (
28
+ <box style={{ height: 1, backgroundColor: tokens.panel, paddingLeft: 1, flexDirection: "row" }}>
29
+ <text fg={tokens.text}>
30
+ {items.map((item, index) => (
31
+ <span key={index} fg={toneColor(item.tone)}>
32
+ {index === 0 ? item.label : ` · ${item.label}`}
33
+ </span>
34
+ ))}
35
+ </text>
36
+ </box>
37
+ );
38
+ }
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { CodeBlock } from "./CodeBlock";
5
+
6
+ export const meta: StoryMeta = { title: "CodeBlock" };
7
+
8
+ const SNIPPET = `export function gate(full: number) {
9
+ // threshold
10
+ return full < 0.6 ? "blocked" : "clear";
11
+ }`;
12
+
13
+ export const Typescript: Story = {
14
+ render: () => <CodeBlock language="ts" content={SNIPPET} />,
15
+ expectedColors: [DARK.elevated],
16
+ };
17
+
18
+ export const CursorAnnotatedEdited: Story = {
19
+ render: () => <CodeBlock language="ts" content={SNIPPET} isCursor isAnnotated changeTag="edited" marginTop={1} />,
20
+ expectedColors: [DARK.accent],
21
+ };
22
+
23
+ export const UnknownLanguage: Story = {
24
+ render: () => <CodeBlock language="brainfog" content={"plain verbatim lines\n with indentation"} />,
25
+ };
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Fenced code block: verbatim lines in a contained elevated box, highlighted
3
+ * by the native code renderable (tree-sitter). Unstyled text draws first, so
4
+ * the content never flashes empty while highlights resolve; unknown languages
5
+ * stay unstyled.
6
+ */
7
+
8
+ import React from "react";
9
+ import type { Theme } from "../theme";
10
+ import { useComponentTheme } from "./theme-context";
11
+ import { filetypeFor, syntaxStyleFor } from "./syntax-highlight";
12
+
13
+ export interface CodeBlockProps {
14
+ id?: string;
15
+ /** Markdown fence info string ("tsx", "python", ...). */
16
+ language?: string;
17
+ content: string;
18
+ isCursor?: boolean;
19
+ /** Vertical rhythm above the block. */
20
+ marginTop?: number;
21
+ isAnnotated?: boolean;
22
+ /** Working-copy change tag rendered after the language label. */
23
+ changeTag?: "cut" | "new" | "edited";
24
+ theme?: Theme;
25
+ }
26
+
27
+ export function CodeBlock({
28
+ id,
29
+ language,
30
+ content,
31
+ isCursor = false,
32
+ marginTop = 0,
33
+ isAnnotated = false,
34
+ changeTag,
35
+ theme,
36
+ }: CodeBlockProps): React.ReactNode {
37
+ const tokens = useComponentTheme(theme);
38
+ const tagColor = changeTag === "cut" ? tokens.red : changeTag === "new" ? tokens.green : tokens.accent;
39
+ return (
40
+ <box id={id} style={{ flexDirection: "column", marginTop }}>
41
+ <text>
42
+ <span fg={isCursor ? tokens.accent : tokens.textDim}>{isCursor ? "▎ " : " "}</span>
43
+ <span fg={tokens.textDim}>{language ?? "code"}</span>
44
+ {isAnnotated ? <span fg={tokens.accent}> ◆</span> : null}
45
+ {changeTag ? <span fg={tagColor}> [{changeTag}]</span> : null}
46
+ </text>
47
+ <box
48
+ style={{
49
+ flexDirection: "column",
50
+ backgroundColor: tokens.elevated,
51
+ paddingLeft: 2,
52
+ paddingRight: 2,
53
+ paddingTop: 1,
54
+ paddingBottom: 1,
55
+ marginLeft: 2,
56
+ }}
57
+ >
58
+ <code
59
+ content={content}
60
+ filetype={filetypeFor(language)}
61
+ syntaxStyle={syntaxStyleFor(tokens)}
62
+ selectable={false}
63
+ style={{ wrapMode: "none", fg: tokens.textMuted, bg: tokens.elevated }}
64
+ />
65
+ </box>
66
+ </box>
67
+ );
68
+ }
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { CompletionOverlay } from "./CompletionOverlay";
5
+
6
+ export const meta: StoryMeta = { title: "CompletionOverlay" };
7
+
8
+ export const ApprovedPrompt: Story = {
9
+ render: () => <CompletionOverlay verdict="approve" completion={{ phase: "prompt" }} status="" />,
10
+ expectedColors: [DARK.green],
11
+ };
12
+
13
+ export const FeedbackCounting: Story = {
14
+ render: () => (
15
+ <CompletionOverlay
16
+ verdict="request_changes"
17
+ completion={{ phase: "counting", remaining: 3 }}
18
+ status="exported to vault/cueloop/plan.md"
19
+ returnsTo="agent/worker-3"
20
+ />
21
+ ),
22
+ expectedColors: [DARK.accent],
23
+ };
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Post-submit hand-back overlay: the agent is unblocked, the reviewer either
3
+ * closes now, opts into auto-close, or dismisses back to the resolved view.
4
+ * The latest status line (e.g. the vault-export path) stays visible here.
5
+ */
6
+
7
+ import React from "react";
8
+ import type { VerdictKind } from "@cueloop/schema";
9
+ import type { Theme } from "../theme";
10
+ import { useComponentTheme } from "./theme-context";
11
+
12
+ export interface CompletionOverlayProps {
13
+ verdict: VerdictKind;
14
+ completion: { phase: "prompt" } | { phase: "counting"; remaining: number };
15
+ /** Latest status line (e.g. the vault-export path) stays visible here. */
16
+ status: string;
17
+ /** Where focus goes on close (the agent's pane), when known. */
18
+ returnsTo?: string;
19
+ theme?: Theme;
20
+ }
21
+
22
+ export function CompletionOverlay({ verdict, completion, status, returnsTo, theme }: CompletionOverlayProps): React.ReactNode {
23
+ const tokens = useComponentTheme(theme);
24
+ const approved = verdict === "approve";
25
+ return (
26
+ <box
27
+ style={{
28
+ width: "100%",
29
+ height: "100%",
30
+ backgroundColor: tokens.bg,
31
+ flexDirection: "column",
32
+ justifyContent: "center",
33
+ alignItems: "center",
34
+ }}
35
+ >
36
+ <text fg={approved ? tokens.green : tokens.accent}>{approved ? "review approved" : "feedback sent"}</text>
37
+ <text> </text>
38
+ <text fg={tokens.text}>The agent has your {approved ? "approval" : "feedback"} and is unblocked.</text>
39
+ {returnsTo ? <text fg={tokens.textDim}>returning to {returnsTo} on close</text> : null}
40
+ {status ? <text fg={tokens.textDim}>{status}</text> : null}
41
+ <text> </text>
42
+ <text fg={tokens.textDim}>
43
+ close [return]
44
+ {completion.phase === "counting" ? ` · closing in ${completion.remaining}s` : ""}
45
+ {" · return to plan [esc] · always [a]"}
46
+ </text>
47
+ </box>
48
+ );
49
+ }
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { ComposeBar } from "./ComposeBar";
5
+
6
+ export const meta: StoryMeta = { title: "ComposeBar" };
7
+
8
+ export const CommentOnLine: Story = {
9
+ render: () => (
10
+ <ComposeBar kind="comment" quote=" private items = new Map();" text="Map needs an eviction story." onInput={() => {}} />
11
+ ),
12
+ expectedColors: [DARK.accent, DARK.elevated],
13
+ };
14
+
15
+ export const SuggestionOnLine: Story = {
16
+ render: () => <ComposeBar kind="suggestion" quote="export class Store {" text="" onInput={() => {}} />,
17
+ expectedColors: [DARK.green],
18
+ };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Bottom compose bar - the diff view composes annotation bodies here. The
3
+ * editor is the same multiline textarea contract as the inline composer:
4
+ * ⏎ saves through the grammar, shift+⏎ adds a line.
5
+ */
6
+
7
+ import React, { useRef } from "react";
8
+ import type { KeyBinding, TextareaRenderable } from "@opentui/core";
9
+ import type { Theme } from "../theme";
10
+ import { useComponentTheme } from "./theme-context";
11
+ import { truncateToSingleLine } from "./truncate-text";
12
+
13
+ export interface ComposeBarProps {
14
+ kind: "comment" | "suggestion";
15
+ quote: string;
16
+ text: string;
17
+ onInput: (text: string) => void;
18
+ theme?: Theme;
19
+ }
20
+
21
+ const COMPOSE_KEY_BINDINGS: KeyBinding[] = [
22
+ { name: "return", action: "submit" },
23
+ { name: "return", shift: true, action: "newline" },
24
+ ];
25
+
26
+ export function ComposeBar({ kind, quote, text, onInput, theme }: ComposeBarProps): React.ReactNode {
27
+ const tokens = useComponentTheme(theme);
28
+ const editorRef = useRef<TextareaRenderable | null>(null);
29
+ const editorRows = Math.min(4, Math.max(1, text.split("\n").length));
30
+ return (
31
+ <box style={{ height: 1 + editorRows, backgroundColor: tokens.elevated, flexDirection: "column", paddingLeft: 1 }}>
32
+ <text fg={kind === "suggestion" ? tokens.green : tokens.accent}>
33
+ {kind === "suggestion" ? "SUGGEST REPLACEMENT FOR" : "COMMENT ON"} “{truncateToSingleLine(quote, 60)}” · ⏎ save · esc cancel
34
+ </text>
35
+ <textarea
36
+ ref={editorRef}
37
+ focused
38
+ initialValue=""
39
+ keyBindings={COMPOSE_KEY_BINDINGS}
40
+ onContentChange={() => {
41
+ const editor = editorRef.current;
42
+ if (editor) onInput(editor.plainText);
43
+ }}
44
+ style={{
45
+ height: editorRows,
46
+ backgroundColor: tokens.elevated,
47
+ focusedBackgroundColor: tokens.elevated,
48
+ textColor: tokens.text,
49
+ focusedTextColor: tokens.text,
50
+ }}
51
+ />
52
+ </box>
53
+ );
54
+ }
@@ -0,0 +1,37 @@
1
+ import React from "react";
2
+ import { DARK } from "../theme";
3
+ import type { Story, StoryMeta } from "./story";
4
+ import { ConfirmCard } from "./ConfirmCard";
5
+
6
+ export const meta: StoryMeta = { title: "ConfirmCard" };
7
+
8
+ const callbacks = { onInput: () => {}, onSelectVerdict: () => {}, onSubmit: () => {}, onCancel: () => {} };
9
+
10
+ export const ApproveDefault: Story = {
11
+ render: () => <ConfirmCard verdict="approve" summary="" annotationCount={0} blockingCount={0} {...callbacks} />,
12
+ expectedColors: [DARK.green, DARK.accent],
13
+ size: { width: 40, height: 14 },
14
+ };
15
+
16
+ export const RequestChanges: Story = {
17
+ render: () => (
18
+ <ConfirmCard verdict="request_changes" summary="Tighten the steps." annotationCount={3} blockingCount={1} {...callbacks} />
19
+ ),
20
+ expectedColors: [DARK.red],
21
+ size: { width: 40, height: 14 },
22
+ };
23
+
24
+ export const WithViewedSummary: Story = {
25
+ render: () => (
26
+ <ConfirmCard
27
+ verdict="approve"
28
+ summary=""
29
+ annotationCount={1}
30
+ blockingCount={0}
31
+ viewedSummary="2/3 files viewed"
32
+ {...callbacks}
33
+ />
34
+ ),
35
+ expectedColors: [DARK.green, DARK.textDim],
36
+ size: { width: 40, height: 14 },
37
+ };
@@ -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,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
+ };