@cueloop/client 0.1.0-alpha.7 → 0.1.0-alpha.71

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 (248) 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 +39 -32
  8. package/src/App.appearance.test.tsx +53 -0
  9. package/src/App.autoclose.test.tsx +76 -50
  10. package/src/App.diff.test.tsx +156 -42
  11. package/src/App.export.test.tsx +58 -40
  12. package/src/App.plan-review.test.tsx +363 -0
  13. package/src/App.prototype-markdown.test.tsx +92 -0
  14. package/src/App.prototype.test.tsx +176 -0
  15. package/src/App.readonly.test.tsx +128 -67
  16. package/src/App.rendering.test.tsx +61 -35
  17. package/src/App.submit-confirm.test.tsx +191 -0
  18. package/src/App.test.tsx +310 -114
  19. package/src/App.toast.test.tsx +89 -0
  20. package/src/App.tsx +1043 -798
  21. package/src/App.walk.test.tsx +298 -0
  22. package/src/App.workbench.test.tsx +495 -0
  23. package/src/__snapshots__/view-plan.regression.test.ts.snap +100 -0
  24. package/src/annotation-palette.ts +61 -0
  25. package/src/app-key-state.ts +61 -0
  26. package/src/app-screens.tsx +432 -0
  27. package/src/app-view-model.ts +159 -0
  28. package/src/attribution.test.ts +31 -0
  29. package/src/attribution.ts +42 -0
  30. package/src/clipboard.test.ts +23 -0
  31. package/src/clipboard.ts +33 -0
  32. package/src/components/AnnotatableFileView.stories.tsx +42 -0
  33. package/src/components/AnnotatableFileView.test.tsx +102 -0
  34. package/src/components/AnnotatableFileView.tsx +126 -0
  35. package/src/components/AnnotationCards.stories.tsx +87 -0
  36. package/src/components/AnnotationCards.tsx +303 -0
  37. package/src/components/AppHeader.stories.tsx +50 -0
  38. package/src/components/AppHeader.tsx +83 -0
  39. package/src/components/AppShell.stories.tsx +89 -0
  40. package/src/components/AppShell.tsx +290 -0
  41. package/src/components/AppShell.zoom.test.tsx +135 -0
  42. package/src/components/BareWorkbenchFileView.stories.tsx +27 -0
  43. package/src/components/BareWorkbenchFileView.tsx +64 -0
  44. package/src/components/Breadcrumb.stories.tsx +19 -0
  45. package/src/components/Breadcrumb.tsx +45 -0
  46. package/src/components/ChangesColumn.stories.tsx +39 -0
  47. package/src/components/ChangesColumn.tsx +171 -0
  48. package/src/components/CodeBlock.stories.tsx +42 -0
  49. package/src/components/CodeBlock.tsx +84 -0
  50. package/src/components/CompletionOverlay.stories.tsx +23 -0
  51. package/src/components/CompletionOverlay.tsx +60 -0
  52. package/src/components/ConfirmCard.stories.tsx +35 -0
  53. package/src/components/ConfirmCard.tsx +128 -0
  54. package/src/components/ConfirmDialog.stories.tsx +21 -0
  55. package/src/components/ConfirmDialog.tsx +66 -0
  56. package/src/components/DiffContentView.scroll.test.tsx +121 -0
  57. package/src/components/DiffContentView.split.test.tsx +140 -0
  58. package/src/components/DiffContentView.stories.tsx +80 -0
  59. package/src/components/DiffContentView.syntax.test.tsx +82 -0
  60. package/src/components/DiffContentView.tsx +859 -0
  61. package/src/components/DiscussionMarkerRail.stories.tsx +54 -0
  62. package/src/components/DiscussionMarkerRail.tsx +181 -0
  63. package/src/components/EditorGrid.stories.tsx +59 -0
  64. package/src/components/EditorGrid.tabs.test.tsx +118 -0
  65. package/src/components/EditorGrid.tsx +368 -0
  66. package/src/components/EditorGrid.zoom.test.tsx +68 -0
  67. package/src/components/FileContentsView.stories.tsx +16 -0
  68. package/src/components/FileContentsView.test.tsx +29 -0
  69. package/src/components/FileContentsView.tsx +98 -0
  70. package/src/components/KeybindsDialog.stories.tsx +31 -0
  71. package/src/components/KeybindsDialog.tsx +103 -0
  72. package/src/components/MenuBar.stories.tsx +28 -0
  73. package/src/components/MenuBar.tsx +44 -0
  74. package/src/components/OverlayScrollbar.stories.tsx +33 -0
  75. package/src/components/OverlayScrollbar.test.tsx +139 -0
  76. package/src/components/OverlayScrollbar.tsx +129 -0
  77. package/src/components/PaneGrid.stories.tsx +84 -0
  78. package/src/components/PaneGrid.tsx +128 -0
  79. package/src/components/PanelColumn.stories.tsx +25 -0
  80. package/src/components/PanelColumn.tsx +95 -0
  81. package/src/components/ProjectTreeView.stories.tsx +25 -0
  82. package/src/components/ProjectTreeView.test.tsx +32 -0
  83. package/src/components/ProjectTreeView.tsx +83 -0
  84. package/src/components/PromptDialog.stories.tsx +36 -0
  85. package/src/components/PromptDialog.tsx +87 -0
  86. package/src/components/PrototypeContentView.stories.tsx +19 -0
  87. package/src/components/PrototypeContentView.tsx +446 -0
  88. package/src/components/RootOverlay.stories.tsx +44 -0
  89. package/src/components/RootOverlay.tsx +35 -0
  90. package/src/components/ScrollArea.stories.tsx +20 -0
  91. package/src/components/ScrollArea.tsx +44 -0
  92. package/src/components/SettingsDialog.stories.tsx +117 -0
  93. package/src/components/SettingsDialog.tsx +195 -0
  94. package/src/components/SettingsRows.stories.tsx +18 -0
  95. package/src/components/SettingsRows.tsx +112 -0
  96. package/src/components/ShellHeader.stories.tsx +50 -0
  97. package/src/components/ShellHeader.tsx +137 -0
  98. package/src/components/ThreadFooter.stories.tsx +30 -0
  99. package/src/components/ThreadFooter.test.tsx +31 -0
  100. package/src/components/ThreadFooter.tsx +54 -0
  101. package/src/components/ThreadTree.stories.tsx +46 -0
  102. package/src/components/ThreadTree.tsx +219 -0
  103. package/src/components/ThreadView.selection.test.tsx +812 -0
  104. package/src/components/ThreadView.slash.test.tsx +158 -0
  105. package/src/components/ThreadView.stories.tsx +26 -0
  106. package/src/components/ThreadView.tsx +330 -0
  107. package/src/components/ThreadsSidebar.stories.tsx +36 -0
  108. package/src/components/ThreadsSidebar.tsx +71 -0
  109. package/src/components/Toast.stories.tsx +12 -0
  110. package/src/components/Toast.tsx +45 -0
  111. package/src/components/Tooltip.stories.tsx +26 -0
  112. package/src/components/Tooltip.tsx +72 -0
  113. package/src/components/TreePane.stories.tsx +106 -0
  114. package/src/components/TreePane.tsx +157 -0
  115. package/src/components/WalkWizard.stories.tsx +100 -0
  116. package/src/components/WalkWizard.tsx +152 -0
  117. package/src/components/WelcomePlayground.stories.tsx +12 -0
  118. package/src/components/WelcomePlayground.test.tsx +47 -0
  119. package/src/components/WelcomePlayground.tsx +140 -0
  120. package/src/components/__snapshots__/stories.test.tsx.snap +1845 -0
  121. package/src/components/agent-launcher.stories.tsx +26 -0
  122. package/src/components/agent-launcher.test.tsx +50 -0
  123. package/src/components/agent-launcher.tsx +149 -0
  124. package/src/components/diff-content-view-layout.test.ts +198 -0
  125. package/src/components/diff-content-view-layout.ts +84 -0
  126. package/src/components/editor-grid.test.ts +86 -0
  127. package/src/components/editor-grid.ts +138 -0
  128. package/src/components/fade-title.test.ts +49 -0
  129. package/src/components/fade-title.ts +61 -0
  130. package/src/components/file-tree.test.ts +60 -0
  131. package/src/components/file-tree.ts +112 -0
  132. package/src/components/pages/Workspace.stories.tsx +181 -0
  133. package/src/components/primitives/Button.stories.tsx +32 -0
  134. package/src/components/primitives/Button.tsx +52 -0
  135. package/src/components/primitives/Card.stories.tsx +25 -0
  136. package/src/components/primitives/Card.tsx +60 -0
  137. package/src/components/primitives/Dialog.stories.tsx +24 -0
  138. package/src/components/primitives/Dialog.tsx +66 -0
  139. package/src/components/primitives/IconButton.stories.tsx +36 -0
  140. package/src/components/primitives/IconButton.tsx +62 -0
  141. package/src/components/primitives/StatusBar.stories.tsx +11 -0
  142. package/src/components/primitives/StatusBar.tsx +23 -0
  143. package/src/components/primitives/Tabs.stories.tsx +29 -0
  144. package/src/components/primitives/Tabs.tsx +102 -0
  145. package/src/components/primitives/Toolbar.stories.tsx +17 -0
  146. package/src/components/primitives/Toolbar.tsx +14 -0
  147. package/src/components/primitives/Tree.stories.tsx +124 -0
  148. package/src/components/primitives/Tree.tsx +96 -0
  149. package/src/components/primitives/frame.test.ts +12 -0
  150. package/src/components/primitives/frame.ts +14 -0
  151. package/src/components/primitives/icons.ts +61 -0
  152. package/src/components/primitives/tree-model.test.ts +99 -0
  153. package/src/components/primitives/tree-model.ts +137 -0
  154. package/src/components/quick-actions-editor.stories.tsx +54 -0
  155. package/src/components/quick-actions-editor.test.tsx +49 -0
  156. package/src/components/quick-actions-editor.tsx +150 -0
  157. package/src/components/session-tree.test.ts +134 -0
  158. package/src/components/session-tree.ts +108 -0
  159. package/src/components/stories-app.tsx +184 -0
  160. package/src/components/stories.test.tsx +66 -0
  161. package/src/components/story-fixtures.ts +102 -0
  162. package/src/components/story-tree.test.ts +100 -0
  163. package/src/components/story.ts +142 -0
  164. package/src/components/syntax-highlight.ts +110 -0
  165. package/src/components/terminal-pane.test.tsx +40 -0
  166. package/src/components/terminal-pane.ts +199 -0
  167. package/src/components/theme-context.stories.tsx +46 -0
  168. package/src/components/theme-context.tsx +37 -0
  169. package/src/components/truncate-text.ts +7 -0
  170. package/src/config.test.ts +461 -31
  171. package/src/config.ts +389 -57
  172. package/src/diff-fold.test.ts +78 -0
  173. package/src/diff-fold.ts +126 -0
  174. package/src/diff-hunk-curate.test.ts +315 -0
  175. package/src/diff-hunk-curate.ts +153 -0
  176. package/src/diff-intraline.test.ts +165 -0
  177. package/src/diff-intraline.ts +146 -0
  178. package/src/diff-syntax.test.ts +112 -0
  179. package/src/diff-syntax.ts +179 -0
  180. package/src/discussions.ts +79 -0
  181. package/src/editor.test.ts +149 -0
  182. package/src/editor.ts +139 -9
  183. package/src/ghostty-terminal.test.ts +85 -0
  184. package/src/ghostty-terminal.ts +199 -0
  185. package/src/herdr.test.ts +9 -34
  186. package/src/herdr.ts +25 -21
  187. package/src/index.ts +11 -0
  188. package/src/integrations.test.ts +41 -0
  189. package/src/integrations.ts +32 -0
  190. package/src/intent-dispatch.test.ts +698 -0
  191. package/src/intent-dispatch.ts +700 -0
  192. package/src/key-bindings.test.ts +156 -0
  193. package/src/key-bindings.ts +465 -0
  194. package/src/keymap.test.ts +611 -0
  195. package/src/keymap.ts +410 -0
  196. package/src/kitty-image.test.ts +66 -0
  197. package/src/kitty-image.ts +138 -0
  198. package/src/mark-runs.ts +120 -0
  199. package/src/prototype-browser.test.ts +56 -0
  200. package/src/prototype-browser.ts +307 -0
  201. package/src/prototype-pixels.tsx +35 -0
  202. package/src/pty.test.ts +81 -0
  203. package/src/pty.ts +245 -0
  204. package/src/ready-signal.test.ts +85 -0
  205. package/src/ready-signal.ts +52 -0
  206. package/src/run.ts +30 -9
  207. package/src/serve.test.ts +24 -12
  208. package/src/serve.ts +20 -9
  209. package/src/share.ts +215 -0
  210. package/src/skills.test.ts +74 -0
  211. package/src/skills.ts +68 -0
  212. package/src/slash-palette.test.ts +54 -0
  213. package/src/slash-palette.ts +104 -0
  214. package/src/split-diff.test.ts +110 -0
  215. package/src/split-diff.ts +149 -0
  216. package/src/test-support.test.ts +264 -0
  217. package/src/test-support.ts +355 -0
  218. package/src/theme-presets.test.ts +51 -0
  219. package/src/theme-presets.ts +214 -0
  220. package/src/theme.ts +84 -19
  221. package/src/thread-chords.test.ts +170 -0
  222. package/src/thread-chords.ts +169 -0
  223. package/src/thread-controller.curate.test.ts +438 -0
  224. package/src/thread-controller.live-diff.test.ts +199 -0
  225. package/src/thread-controller.share.test.ts +472 -0
  226. package/src/thread-controller.tree.test.ts +255 -0
  227. package/src/thread-controller.ts +1509 -0
  228. package/src/thread-selection.test.ts +210 -0
  229. package/src/thread-selection.ts +243 -0
  230. package/src/tree-view.test.ts +128 -0
  231. package/src/tree-view.ts +148 -0
  232. package/src/use-annotation-surface.tsx +851 -0
  233. package/src/use-changes-workbench.ts +153 -0
  234. package/src/use-frame-measure.ts +38 -0
  235. package/src/use-settings-dialog.tsx +274 -0
  236. package/src/use-terminal-virtualizer.ts +233 -0
  237. package/src/version.ts +5 -0
  238. package/src/view-diff.test.ts +66 -9
  239. package/src/view-diff.ts +231 -23
  240. package/src/view-plan.regression.test.ts +60 -0
  241. package/src/view-plan.test.ts +406 -0
  242. package/src/view-plan.ts +570 -0
  243. package/src/walk.test.ts +121 -0
  244. package/src/walk.ts +74 -0
  245. package/src/syntax.test.ts +0 -41
  246. package/src/syntax.ts +0 -88
  247. package/src/view.test.ts +0 -157
  248. package/src/view.ts +0 -312
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Attribution labels for annotations. An annotation's `author` is an identity
3
+ * id (an SSH fingerprint today). The rail resolves it against the share's
4
+ * participant registry and the planner's local rename overrides; ADR 0006.
5
+ */
6
+
7
+ import type { Identity } from "@cueloop/schema";
8
+
9
+ const FINGERPRINT_PREFIX = "SHA256:";
10
+
11
+ /** Shown for a known participant who chose not to give a name. */
12
+ export const ANONYMOUS_LABEL = "-- anonymous --";
13
+
14
+ /** A short, stable handle from a raw author id when no name is known. */
15
+ export function shortHandle(authorId: string): string {
16
+ const base = authorId.startsWith(FINGERPRINT_PREFIX)
17
+ ? authorId.slice(FINGERPRINT_PREFIX.length)
18
+ : authorId;
19
+
20
+ return base.slice(0, 8) || authorId;
21
+ }
22
+
23
+ /**
24
+ * The rail label for an author id: a local rename wins, then the collaborator's
25
+ * own name, then anonymous for a known-but-unnamed participant, then a short
26
+ * handle for an id we hold no identity for.
27
+ */
28
+ export function resolveDisplayName(
29
+ authorId: string,
30
+ participants: Identity[] | undefined,
31
+ overrides: Record<string, string>,
32
+ ): string {
33
+ const override = overrides[authorId];
34
+
35
+ if (override) return override;
36
+ const identity = participants?.find((participant) => participant.id === authorId);
37
+
38
+ if (identity?.name) return identity.name;
39
+ if (identity) return ANONYMOUS_LABEL;
40
+
41
+ return shortHandle(authorId);
42
+ }
@@ -0,0 +1,23 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { clipboardCommands } from "./clipboard";
3
+
4
+ describe(clipboardCommands, () => {
5
+ test("uses pbcopy on macOS", () => {
6
+ // Assert
7
+ expect(clipboardCommands("darwin")).toEqual([["pbcopy"]]);
8
+ });
9
+
10
+ test("uses clip.exe on Windows", () => {
11
+ // Assert
12
+ expect(clipboardCommands("win32")).toEqual([["clip.exe"]]);
13
+ });
14
+
15
+ test("prefers wayland, then X11 tools on Linux", () => {
16
+ // Act
17
+ const commands = clipboardCommands("linux");
18
+
19
+ // Assert
20
+ expect(commands[0]).toEqual(["wl-copy"]);
21
+ expect(commands.map((command) => command[0])).toEqual(["wl-copy", "xclip", "xsel"]);
22
+ });
23
+ });
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Best-effort system clipboard. Each platform has its own tool; we try them in
3
+ * order and report whether one worked, so the caller can fall back to printing
4
+ * the line (the over-SSH case, where no clipboard tool exists). Mirrors how
5
+ * herdr confirms a copy.
6
+ */
7
+
8
+ /** The clipboard-write commands to try, most-preferred first, for this platform. */
9
+ export function clipboardCommands(platform: NodeJS.Platform = process.platform): string[][] {
10
+ if (platform === "darwin") return [["pbcopy"]];
11
+ if (platform === "win32") return [["clip.exe"]];
12
+
13
+ return [["wl-copy"], ["xclip", "-selection", "clipboard"], ["xsel", "--clipboard", "--input"]];
14
+ }
15
+
16
+ /** Copy `text` to the clipboard; false when no tool is available or all fail. */
17
+ export async function copyToClipboard(text: string): Promise<boolean> {
18
+ for (const command of clipboardCommands()) {
19
+ try {
20
+ const proc = Bun.spawn(command, {
21
+ stdin: Buffer.from(text),
22
+ stdout: "ignore",
23
+ stderr: "ignore",
24
+ });
25
+
26
+ if ((await proc.exited) === 0) return true;
27
+ } catch {
28
+ // tool not installed - try the next one
29
+ }
30
+ }
31
+
32
+ return false;
33
+ }
@@ -0,0 +1,42 @@
1
+ import React from "react";
2
+ import { SCHEMA_VERSION, type Thread } from "@cueloop/schema";
3
+ import { DARK } from "../theme";
4
+ import type { Story, StoryMeta } from "./story";
5
+ import { AnnotatableFileView } from "./AnnotatableFileView";
6
+
7
+ export const meta: StoryMeta = { title: "Surfaces/AnnotatableFileView" };
8
+
9
+ const SAMPLE = `export function add(a: number, b: number): number {\n return a + b;\n}\n`;
10
+
11
+ const SESSION: Thread = {
12
+ schemaVersion: SCHEMA_VERSION,
13
+ id: "ses_story",
14
+ workspace: { repoRoot: "/repo", branch: "main" },
15
+ artifact: { type: "plan", content: "# Plan\n", meta: {} },
16
+ revisions: [{ revision: 1, content: "# Plan\n", submittedAt: "2026-01-01T00:00:00Z" }],
17
+ annotations: [],
18
+ verdict: null,
19
+ status: "pending",
20
+ createdAt: "2026-01-01T00:00:00Z",
21
+ };
22
+
23
+ const noop = (): void => {};
24
+
25
+ export const Loaded: Story = {
26
+ render: () => (
27
+ <AnnotatableFileView
28
+ path="src/add.ts"
29
+ loadContents={() => Promise.resolve(SAMPLE)}
30
+ session={SESSION}
31
+ quickActions={[]}
32
+ observer={false}
33
+ onAddComment={noop}
34
+ onReply={noop}
35
+ onUpdateAnnotation={noop}
36
+ onExit={noop}
37
+ theme={DARK}
38
+ />
39
+ ),
40
+ expectedColors: [DARK.textDim],
41
+ size: { width: 60, height: 12 },
42
+ };
@@ -0,0 +1,102 @@
1
+ /**
2
+ * A project file is its own annotation surface: selecting a line and typing leaves a comment whose
3
+ * anchor quotes that file line, handed up as an Anchor the app persists with a file target.
4
+ */
5
+
6
+ import { describe, expect, mock, test } from "bun:test";
7
+ import { testRender } from "@opentui/react/test-utils";
8
+ import React from "react";
9
+ import { SCHEMA_VERSION, type Anchor, type Thread } from "@cueloop/schema";
10
+ import { AnnotatableFileView } from "./AnnotatableFileView";
11
+ import { DARK } from "../theme";
12
+ import { dragText, typeText, pressKey, waitForText } from "../test-support";
13
+
14
+ const SAMPLE = "export function add(a: number, b: number) {\n return a + b;\n}\n";
15
+
16
+ function planSession(): Thread {
17
+ return {
18
+ schemaVersion: SCHEMA_VERSION,
19
+ id: "ses_plan",
20
+ workspace: { repoRoot: "/repo", branch: "main" },
21
+ artifact: { type: "plan", content: "# Plan\n", meta: {} },
22
+ revisions: [{ revision: 1, content: "# Plan\n", submittedAt: "2026-01-01T00:00:00Z" }],
23
+ annotations: [],
24
+ verdict: null,
25
+ status: "pending",
26
+ createdAt: "2026-01-01T00:00:00Z",
27
+ };
28
+ }
29
+
30
+ const noop = (): void => {};
31
+
32
+ describe("AnnotatableFileView", () => {
33
+ test("commenting a file line hands up an anchor that quotes the line", async () => {
34
+ const onAddComment = mock((_anchor: Anchor, _body: string) => {});
35
+ const setup = await testRender(
36
+ <AnnotatableFileView
37
+ path="src/add.ts"
38
+ loadContents={() => Promise.resolve(SAMPLE)}
39
+ session={planSession()}
40
+ quickActions={[]}
41
+ observer={false}
42
+ onAddComment={onAddComment}
43
+ onReply={noop}
44
+ onUpdateAnnotation={noop}
45
+ onExit={noop}
46
+ theme={DARK}
47
+ />,
48
+ { width: 64, height: 12 },
49
+ );
50
+
51
+ // Act - select the middle line, type a comment, send it
52
+ await waitForText(setup, "return a + b");
53
+ await dragText(setup, "return a + b", "return a + b", "return a + b".length);
54
+ await typeText(setup, "why not reduce?");
55
+ await pressKey(setup, "RETURN", { meta: true });
56
+
57
+ // Assert - the surface built an anchor quoting the file line and handed it up with the body
58
+ expect(onAddComment).toHaveBeenCalled();
59
+ const [anchor, body] = onAddComment.mock.calls[0]!;
60
+ expect(anchor.quote).toContain("return a + b");
61
+ expect(body).toContain("why not reduce?");
62
+
63
+ setup.renderer.destroy();
64
+ });
65
+
66
+ test("a head-side (deleted-line) note never rebinds onto the current file", async () => {
67
+ const session = planSession();
68
+ // a note left on the removed side of this file: the worktree view must not show it
69
+ session.annotations = [
70
+ {
71
+ id: "h1",
72
+ kind: "comment",
73
+ anchor: { quote: "return a + b", prefix: "", suffix: "" },
74
+ target: { kind: "file", path: "src/add.ts", rev: "head" },
75
+ body: "deleted-side note",
76
+ createdAt: "2026-01-01T00:00:00Z",
77
+ },
78
+ ];
79
+ const setup = await testRender(
80
+ <AnnotatableFileView
81
+ path="src/add.ts"
82
+ loadContents={() => Promise.resolve(SAMPLE)}
83
+ session={session}
84
+ quickActions={[]}
85
+ observer={false}
86
+ onAddComment={noop}
87
+ onReply={noop}
88
+ onUpdateAnnotation={noop}
89
+ onExit={noop}
90
+ theme={DARK}
91
+ />,
92
+ { width: 64, height: 12 },
93
+ );
94
+
95
+ await waitForText(setup, "return a + b");
96
+
97
+ // Assert - the current file shows, but the head-side note is not attached to it
98
+ expect(setup.captureCharFrame()).not.toContain("deleted-side note");
99
+
100
+ setup.renderer.destroy();
101
+ });
102
+ });
@@ -0,0 +1,126 @@
1
+ // A project file shown as its own annotatable surface: the file's lines render through the diff
2
+ // sheet as context rows (one line-number gutter, no +/- sign), so selecting text leaves a comment
3
+ // anchored to the file exactly as a plan or diff comment is. Used where a review session exists to
4
+ // hold the notes; the bare-launch welcome shell uses the read-only FileContentsView instead.
5
+
6
+ import React, { useEffect, useRef, useState } from "react";
7
+ import { makeAnchor, annotationTarget, type Anchor, type Thread } from "@cueloop/schema";
8
+ import type { Theme } from "../theme";
9
+ import type { QuickAction } from "../config";
10
+ import { useComponentTheme } from "./theme-context";
11
+ import { DiffContentView } from "./DiffContentView";
12
+ import { diffRowBlocks, fileContentsRows, marksByRows } from "../view-diff";
13
+
14
+ export interface AnnotatableFileViewProps {
15
+ path: string;
16
+ loadContents: (path: string) => Promise<string | null>;
17
+ session: Thread;
18
+ quickActions: QuickAction[];
19
+ observer: boolean;
20
+ resolved?: boolean;
21
+ suspended?: boolean;
22
+ focusedAnnotationId?: string;
23
+ onFocusAnnotation?: (annotationId: string | undefined) => void;
24
+ onComposingChange?: (composing: boolean) => void;
25
+ onCursorChange?: (rowIndex: number) => void;
26
+ onObserverBlocked?: (reason: "observer" | "resolved") => void;
27
+ /** Persist a comment on this file; the view built the anchor against the file's own lines. */
28
+ onAddComment: (anchor: Anchor, body: string) => void;
29
+ onReply: (rootAnnotationId: string, body: string) => void;
30
+ onUpdateAnnotation: (id: string, body: string) => void;
31
+ onExit: () => void;
32
+ theme?: Theme;
33
+ }
34
+
35
+ /** A finished read for a specific path; `lines` is null when the file could not be read. */
36
+ interface FileLoad {
37
+ path: string;
38
+ lines: string[] | null;
39
+ }
40
+
41
+ export function AnnotatableFileView(props: AnnotatableFileViewProps): React.ReactNode {
42
+ const tokens = useComponentTheme(props.theme);
43
+ const [loaded, setLoaded] = useState<FileLoad | null>(null);
44
+ const loadRef = useRef(props.loadContents);
45
+ useEffect(() => {
46
+ loadRef.current = props.loadContents;
47
+ });
48
+
49
+ useEffect(() => {
50
+ let alive = true;
51
+ void loadRef.current(props.path).then(
52
+ (contents) => {
53
+ if (alive)
54
+ setLoaded({ path: props.path, lines: contents === null ? null : contents.split("\n") });
55
+ },
56
+ () => {
57
+ if (alive) setLoaded({ path: props.path, lines: null });
58
+ },
59
+ );
60
+
61
+ return () => {
62
+ alive = false;
63
+ };
64
+ }, [props.path]);
65
+
66
+ if (loaded === null || loaded.path !== props.path) {
67
+ return (
68
+ <box style={{ flexGrow: 1, paddingLeft: 1, paddingTop: 1 }}>
69
+ <text fg={tokens.textDim}>loading...</text>
70
+ </box>
71
+ );
72
+ }
73
+ if (loaded.lines === null) {
74
+ return (
75
+ <box
76
+ style={{ flexGrow: 1, alignItems: "center", justifyContent: "center", paddingBottom: 2 }}
77
+ >
78
+ <text fg={tokens.textDim}>File deleted</text>
79
+ </box>
80
+ );
81
+ }
82
+
83
+ const rows = fileContentsRows(props.path, loaded.lines.join("\n"));
84
+ // the file's worktree notes: these rows are the current file, so a head-side (deleted-line) note
85
+ // must stay orphaned here rather than rebind to similar surviving text
86
+ const fileNotes = props.session.annotations.filter((annotation) => {
87
+ const target = annotationTarget(annotation);
88
+
89
+ return target.kind === "file" && target.path === props.path && target.rev === "worktree";
90
+ });
91
+
92
+ return (
93
+ <DiffContentView
94
+ rows={rows}
95
+ session={props.session}
96
+ marks={marksByRows(fileNotes, rows, props.focusedAnnotationId)}
97
+ quickActions={props.quickActions}
98
+ observer={props.observer}
99
+ commentsEnabled
100
+ resolved={props.resolved}
101
+ suspended={props.suspended}
102
+ fileView
103
+ onComposingChange={props.onComposingChange}
104
+ onObserverBlocked={props.onObserverBlocked}
105
+ onCursorChange={props.onCursorChange}
106
+ focusedAnnotationId={props.focusedAnnotationId}
107
+ onFocusAnnotation={props.onFocusAnnotation}
108
+ onAnnotate={(span, body) =>
109
+ props.onAddComment(
110
+ makeAnchor(
111
+ diffRowBlocks(rows),
112
+ span.start.blockIndex,
113
+ span.start.char,
114
+ span.end.char,
115
+ span.end.blockIndex,
116
+ ),
117
+ body,
118
+ )
119
+ }
120
+ onReply={props.onReply}
121
+ onUpdateAnnotation={props.onUpdateAnnotation}
122
+ onExit={props.onExit}
123
+ theme={props.theme}
124
+ />
125
+ );
126
+ }
@@ -0,0 +1,87 @@
1
+ import React from "react";
2
+ import type { Annotation } from "@cueloop/schema";
3
+ import { DARK } from "../theme";
4
+ import { annotationPaletteFor } from "../annotation-palette";
5
+ import { slashItemsFrom } from "../slash-palette";
6
+ import { DEFAULT_QUICK_ACTIONS } from "../config";
7
+ import type { Story, StoryMeta } from "./story";
8
+ import { CommentRow, ComposerPalette, DiscussionCard } from "./AnnotationCards";
9
+
10
+ export const meta: StoryMeta = { title: "Chrome/AnnotationCards" };
11
+
12
+ const palette = annotationPaletteFor(DARK);
13
+
14
+ function annotation(id: string, body: string, author?: string): Annotation {
15
+ const comment: Annotation = {
16
+ id,
17
+ kind: "comment",
18
+ anchor: { quote: "the daemon", prefix: "", suffix: "" },
19
+ body,
20
+ createdAt: "2026-09-07T10:00:00.000Z",
21
+ };
22
+
23
+ if (author !== undefined) comment.author = author;
24
+
25
+ return comment;
26
+ }
27
+
28
+ // A two-voice discussion: the owner's comment then a collaborator's reply, each
29
+ // segment wearing its own accent edge.
30
+ export const TwoVoices: Story = {
31
+ render: () => (
32
+ <DiscussionCard
33
+ tokens={DARK}
34
+ segments={[
35
+ {
36
+ color: palette.cardEdge,
37
+ node: <CommentRow annotation={annotation("a", "Which daemon?")} tokens={DARK} />,
38
+ },
39
+ {
40
+ color: DARK.text,
41
+ node: (
42
+ <CommentRow
43
+ annotation={annotation("b", "The one the CLI spawns.", "fp:collab")}
44
+ tokens={DARK}
45
+ />
46
+ ),
47
+ },
48
+ ]}
49
+ />
50
+ ),
51
+ expectedColors: [palette.cardEdge, DARK.text],
52
+ size: { width: 60, height: 8 },
53
+ };
54
+
55
+ export const FocusedCard: Story = {
56
+ render: () => (
57
+ <DiscussionCard
58
+ focused
59
+ tokens={DARK}
60
+ segments={[
61
+ {
62
+ color: palette.cardEdge,
63
+ node: (
64
+ <CommentRow annotation={annotation("a", "Needs an eviction story.")} tokens={DARK} />
65
+ ),
66
+ },
67
+ ]}
68
+ />
69
+ ),
70
+ expectedColors: [DARK.text],
71
+ size: { width: 60, height: 6 },
72
+ };
73
+
74
+ // The palette a leading "/" opens under the composer, with the second item selected.
75
+ export const SlashPaletteOpen: Story = {
76
+ render: () => (
77
+ <ComposerPalette
78
+ slashActive
79
+ slashItems={slashItemsFrom(DEFAULT_QUICK_ACTIONS)}
80
+ slashIndex={1}
81
+ inline={null}
82
+ tokens={DARK}
83
+ />
84
+ ),
85
+ expectedColors: [DARK.accent, DARK.textDim],
86
+ size: { width: 90, height: 8 },
87
+ };