@cueloop/client 0.1.0-alpha.5 → 0.1.0-alpha.51

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 (152) 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 +36 -31
  8. package/src/App.autoclose.test.tsx +137 -0
  9. package/src/App.diff.test.tsx +158 -22
  10. package/src/App.export.test.tsx +44 -37
  11. package/src/App.plan-review.test.tsx +672 -0
  12. package/src/App.prototype.test.tsx +155 -0
  13. package/src/App.readonly.test.tsx +60 -36
  14. package/src/App.rendering.test.tsx +132 -0
  15. package/src/App.review-panel.test.tsx +136 -0
  16. package/src/App.submit-confirm.test.tsx +218 -0
  17. package/src/App.test.tsx +128 -69
  18. package/src/App.toast.test.tsx +75 -0
  19. package/src/App.tsx +0 -0
  20. package/src/App.walk.test.tsx +289 -0
  21. package/src/__snapshots__/view-plan.regression.test.ts.snap +100 -0
  22. package/src/attribution.test.ts +31 -0
  23. package/src/attribution.ts +38 -0
  24. package/src/clipboard.test.ts +23 -0
  25. package/src/clipboard.ts +30 -0
  26. package/src/components/AnnotationCard.compose-rows.test.ts +49 -0
  27. package/src/components/AnnotationCard.stories.tsx +94 -0
  28. package/src/components/AnnotationCard.tsx +241 -0
  29. package/src/components/Breadcrumb.stories.tsx +19 -0
  30. package/src/components/Breadcrumb.tsx +44 -0
  31. package/src/components/CodeBlock.stories.tsx +42 -0
  32. package/src/components/CodeBlock.tsx +83 -0
  33. package/src/components/CompletionOverlay.stories.tsx +23 -0
  34. package/src/components/CompletionOverlay.tsx +59 -0
  35. package/src/components/ConfirmCard.stories.tsx +35 -0
  36. package/src/components/ConfirmCard.tsx +127 -0
  37. package/src/components/ConfirmDialog.stories.tsx +21 -0
  38. package/src/components/ConfirmDialog.tsx +64 -0
  39. package/src/components/DiffSheet.scroll.test.tsx +123 -0
  40. package/src/components/DiffSheet.stories.tsx +78 -0
  41. package/src/components/DiffSheet.syntax.test.tsx +62 -0
  42. package/src/components/DiffSheet.tsx +355 -0
  43. package/src/components/InboxList.stories.tsx +31 -0
  44. package/src/components/InboxList.tsx +62 -0
  45. package/src/components/KeybindsDialog.stories.tsx +31 -0
  46. package/src/components/KeybindsDialog.tsx +58 -0
  47. package/src/components/MarkerPopover.stories.tsx +58 -0
  48. package/src/components/MarkerPopover.tsx +108 -0
  49. package/src/components/MenuBar.stories.tsx +37 -0
  50. package/src/components/MenuBar.tsx +74 -0
  51. package/src/components/PlanSheet.stories.tsx +113 -0
  52. package/src/components/PlanSheet.tsx +456 -0
  53. package/src/components/PromptDialog.stories.tsx +36 -0
  54. package/src/components/PromptDialog.tsx +78 -0
  55. package/src/components/PrototypeSheet.stories.tsx +20 -0
  56. package/src/components/PrototypeSheet.tsx +358 -0
  57. package/src/components/ReviewPanel.stories.tsx +86 -0
  58. package/src/components/ReviewPanel.tsx +101 -0
  59. package/src/components/ReviewRail.stories.tsx +218 -0
  60. package/src/components/ReviewRail.tsx +317 -0
  61. package/src/components/SettingsDialog.stories.tsx +111 -0
  62. package/src/components/SettingsDialog.tsx +141 -0
  63. package/src/components/SettingsRows.stories.tsx +18 -0
  64. package/src/components/SettingsRows.tsx +108 -0
  65. package/src/components/Toast.stories.tsx +12 -0
  66. package/src/components/Toast.tsx +44 -0
  67. package/src/components/WalkWizard.stories.tsx +100 -0
  68. package/src/components/WalkWizard.tsx +152 -0
  69. package/src/components/__snapshots__/stories.test.tsx.snap +1857 -0
  70. package/src/components/agent-launcher.stories.tsx +26 -0
  71. package/src/components/agent-launcher.test.tsx +49 -0
  72. package/src/components/agent-launcher.tsx +147 -0
  73. package/src/components/diff-sheet-layout.test.ts +127 -0
  74. package/src/components/diff-sheet-layout.ts +167 -0
  75. package/src/components/primitives/Button.stories.tsx +32 -0
  76. package/src/components/primitives/Button.tsx +51 -0
  77. package/src/components/primitives/Card.stories.tsx +25 -0
  78. package/src/components/primitives/Card.tsx +59 -0
  79. package/src/components/primitives/Dialog.stories.tsx +24 -0
  80. package/src/components/primitives/Dialog.tsx +64 -0
  81. package/src/components/primitives/StatusBar.stories.tsx +11 -0
  82. package/src/components/primitives/StatusBar.tsx +22 -0
  83. package/src/components/primitives/Tabs.stories.tsx +29 -0
  84. package/src/components/primitives/Tabs.tsx +98 -0
  85. package/src/components/primitives/Toolbar.stories.tsx +17 -0
  86. package/src/components/primitives/Toolbar.tsx +14 -0
  87. package/src/components/primitives/frame.test.ts +12 -0
  88. package/src/components/primitives/frame.ts +14 -0
  89. package/src/components/quick-actions-editor.stories.tsx +54 -0
  90. package/src/components/quick-actions-editor.tsx +136 -0
  91. package/src/components/stories-app.tsx +123 -0
  92. package/src/components/stories.test.tsx +62 -0
  93. package/src/components/story-fixtures.ts +98 -0
  94. package/src/components/story.ts +69 -0
  95. package/src/components/syntax-highlight.ts +92 -0
  96. package/src/components/terminal-pane.test.tsx +40 -0
  97. package/src/components/terminal-pane.ts +181 -0
  98. package/src/components/theme-context.stories.tsx +46 -0
  99. package/src/components/theme-context.tsx +36 -0
  100. package/src/components/truncate-text.ts +6 -0
  101. package/src/config.test.ts +430 -31
  102. package/src/config.ts +304 -26
  103. package/src/diff-hunk-curate.test.ts +315 -0
  104. package/src/diff-hunk-curate.ts +233 -0
  105. package/src/diff-intraline.test.ts +164 -0
  106. package/src/diff-intraline.ts +132 -0
  107. package/src/diff-syntax.test.ts +96 -0
  108. package/src/diff-syntax.ts +154 -0
  109. package/src/editor.test.ts +143 -0
  110. package/src/editor.ts +123 -9
  111. package/src/ghostty-terminal.test.ts +82 -0
  112. package/src/ghostty-terminal.ts +168 -0
  113. package/src/herdr.test.ts +41 -0
  114. package/src/herdr.ts +27 -0
  115. package/src/index.ts +10 -0
  116. package/src/integrations.test.ts +41 -0
  117. package/src/integrations.ts +30 -0
  118. package/src/intent-dispatch.test.ts +493 -0
  119. package/src/intent-dispatch.ts +428 -0
  120. package/src/key-bindings.test.ts +152 -0
  121. package/src/key-bindings.ts +430 -0
  122. package/src/keymap.test.ts +622 -0
  123. package/src/keymap.ts +339 -0
  124. package/src/kitty-image.test.ts +20 -0
  125. package/src/kitty-image.ts +75 -0
  126. package/src/prototype-browser.test.ts +55 -0
  127. package/src/prototype-browser.ts +243 -0
  128. package/src/pty.test.ts +78 -0
  129. package/src/pty.ts +222 -0
  130. package/src/review-panel.test.ts +113 -0
  131. package/src/review-panel.ts +83 -0
  132. package/src/run.ts +9 -5
  133. package/src/serve.test.ts +24 -9
  134. package/src/serve.ts +7 -7
  135. package/src/session-controller.curate.test.ts +253 -0
  136. package/src/session-controller.share.test.ts +309 -0
  137. package/src/session-controller.ts +914 -0
  138. package/src/share.ts +113 -0
  139. package/src/test-support.test.ts +55 -0
  140. package/src/test-support.ts +187 -0
  141. package/src/theme-presets.ts +168 -0
  142. package/src/theme.ts +38 -17
  143. package/src/version.ts +5 -0
  144. package/src/view-diff.test.ts +19 -8
  145. package/src/view-diff.ts +34 -23
  146. package/src/view-plan.regression.test.ts +60 -0
  147. package/src/view-plan.test.ts +399 -0
  148. package/src/view-plan.ts +495 -0
  149. package/src/walk.test.ts +121 -0
  150. package/src/walk.ts +70 -0
  151. package/src/view.test.ts +0 -157
  152. package/src/view.ts +0 -0
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Pure geometry and state for the resizable review panel. The panel shows the
3
+ * review rail in one of three modes and the expanded rail resizes within a
4
+ * clamp; App owns the React state and the mouse wiring, this module owns the
5
+ * arithmetic so the layout math stays unit-tested and out of the JSX. Bounds
6
+ * and the compact width carry over verbatim from the approved prototype.
7
+ */
8
+
9
+ /** Expanded (full rail), compact (count + dots strip), or hidden (nothing). */
10
+ export type ReviewPanelMode = "expanded" | "compact" | "hidden";
11
+
12
+ /** Expanded-rail width bounds, in terminal columns. */
13
+ export const REVIEW_MIN_WIDTH = 24;
14
+ export const REVIEW_MAX_WIDTH = 50;
15
+ export const REVIEW_DEFAULT_WIDTH = 34;
16
+ /**
17
+ * Columns the plan/diff column keeps for itself: the expanded rail yields past
18
+ * this so a narrow terminal (or a wide persisted width) can never crowd the
19
+ * plan out to nothing - the whole reason the panel is resizable. On terminals
20
+ * wide enough for the full 50-col rail this bound never binds.
21
+ */
22
+ export const REVIEW_PLAN_MIN_WIDTH = 30;
23
+ /** The compact strip is a fixed narrow column: count on top, one dot per card. */
24
+ export const REVIEW_COMPACT_WIDTH = 6;
25
+ /** Keyboard resize step, in columns, for the widen/narrow keys. */
26
+ export const REVIEW_RESIZE_STEP = 2;
27
+
28
+ /** Round a desired width to a whole column and clamp it to the bounds. */
29
+ export function clampWidth(
30
+ desiredWidth: number,
31
+ min = REVIEW_MIN_WIDTH,
32
+ max = REVIEW_MAX_WIDTH,
33
+ ): number {
34
+ return Math.max(min, Math.min(max, Math.round(desiredWidth)));
35
+ }
36
+
37
+ /**
38
+ * The widest the expanded rail may be on a given terminal, reserving the plan
39
+ * its minimum and one column for the divider. Never drops below REVIEW_MIN_WIDTH
40
+ * (an extremely narrow terminal is the auto-collapse case, handled elsewhere).
41
+ */
42
+ export function maxWidthForTerminal(terminalWidth: number): number {
43
+ return Math.max(
44
+ REVIEW_MIN_WIDTH,
45
+ Math.min(REVIEW_MAX_WIDTH, terminalWidth - REVIEW_PLAN_MIN_WIDTH - 1),
46
+ );
47
+ }
48
+
49
+ /** Clamp a desired rail width to the bounds AND the terminal, so the plan keeps its room. */
50
+ export function resolveReviewWidth(desiredWidth: number, terminalWidth: number): number {
51
+ return clampWidth(desiredWidth, REVIEW_MIN_WIDTH, maxWidthForTerminal(terminalWidth));
52
+ }
53
+
54
+ /** The keybinding cycle: expanded -> compact -> hidden -> expanded. */
55
+ export function cycleReviewPanelMode(mode: ReviewPanelMode): ReviewPanelMode {
56
+ return mode === "expanded" ? "compact" : mode === "compact" ? "hidden" : "expanded";
57
+ }
58
+
59
+ /**
60
+ * The clickable chevron toggles only between expanded and compact - hidden is
61
+ * reachable by keybinding alone, so it never leaves a leftover tab behind. A
62
+ * toggle from hidden still opens the panel rather than doing nothing.
63
+ */
64
+ export function toggleReviewPanelMode(mode: ReviewPanelMode): ReviewPanelMode {
65
+ return mode === "expanded" ? "compact" : "expanded";
66
+ }
67
+
68
+ /**
69
+ * Rail width from an absolute mouse column while dragging the divider: the rail
70
+ * spans from the mouse column to the terminal's right edge, then clamps.
71
+ */
72
+ export function widthFromMouseColumn(mouseColumn: number, terminalWidth: number): number {
73
+ return resolveReviewWidth(terminalWidth - mouseColumn, terminalWidth);
74
+ }
75
+
76
+ /**
77
+ * The divider is a single-column stack of vertical glyphs (a text block, not a
78
+ * bordered box - a one-column box with a border renders a full box). One glyph
79
+ * per row, at least one so the column never collapses.
80
+ */
81
+ export function reviewRowsToDivider(rows: number): string {
82
+ return Array.from({ length: Math.max(1, rows) }, () => "│").join("\n");
83
+ }
package/src/run.ts CHANGED
@@ -10,17 +10,21 @@ export interface RunClientOptions {
10
10
  home?: string;
11
11
  }
12
12
 
13
- export async function runClient(opts: RunClientOptions): Promise<number> {
14
- const renderer = await createCliRenderer();
13
+ export async function runClient(options: RunClientOptions): Promise<number> {
14
+ // mouse movement reporting makes multiplexers forward drags to the app,
15
+ // so the renderer's native selection is the drag driver
16
+ const renderer = await createCliRenderer({ enableMouseMovement: true });
15
17
  return new Promise<number>((resolve) => {
16
18
  createRoot(renderer).render(
17
19
  React.createElement(App, {
18
- home: opts.home,
19
- sessionId: opts.sessionId,
20
+ home: options.home,
21
+ sessionId: options.sessionId,
20
22
  onExit: (code: number) => {
21
23
  renderer.destroy();
22
24
  resolve(code);
23
- process.exit(code);
25
+ // one microtask between destroy and exit lets the renderer flush
26
+ // its terminal-restore sequences before the process dies
27
+ queueMicrotask(() => process.exit(code));
24
28
  },
25
29
  }),
26
30
  );
package/src/serve.test.ts CHANGED
@@ -38,7 +38,11 @@ afterEach(async () => {
38
38
  });
39
39
 
40
40
  /** Connect, open a PTY shell, resolve with the bytes seen until `until` matches. */
41
- function sshCapture(port: number, until: (s: string) => boolean, timeoutMs = 8000): Promise<string> {
41
+ function sshCapture(
42
+ port: number,
43
+ until: (frame: string) => boolean,
44
+ timeoutMs = 8000,
45
+ ): Promise<string> {
42
46
  return new Promise((resolve, reject) => {
43
47
  const conn = new Client();
44
48
  let out = "";
@@ -48,15 +52,16 @@ function sshCapture(port: number, until: (s: string) => boolean, timeoutMs = 800
48
52
  done = true;
49
53
  clearTimeout(timer);
50
54
  conn.end();
51
- err ? reject(err) : resolve(out);
55
+ if (err) reject(err);
56
+ else resolve(out);
52
57
  };
53
58
  const timer = setTimeout(() => finish(new Error(`timed out; captured:\n${out}`)), timeoutMs);
54
59
  conn
55
60
  .on("ready", () => {
56
61
  conn.shell({ term: "xterm-256color", cols: 100, rows: 30 }, (err, stream) => {
57
62
  if (err) return finish(err);
58
- stream.on("data", (d: Buffer) => {
59
- out += d.toString("utf8");
63
+ stream.on("data", (chunk: Buffer) => {
64
+ out += chunk.toString("utf8");
60
65
  if (until(out)) finish();
61
66
  });
62
67
  stream.on("close", () => finish(new Error(`stream closed early; captured:\n${out}`)));
@@ -70,6 +75,7 @@ function sshCapture(port: number, until: (s: string) => boolean, timeoutMs = 800
70
75
 
71
76
  describe("cueloop serve", () => {
72
77
  test("listens on localhost, persists a host key under CUELOOP_HOME/ssh", () => {
78
+ // Assert
73
79
  expect(handle.host).toBe("127.0.0.1");
74
80
  expect(handle.port).toBeGreaterThan(0);
75
81
  expect(handle.fingerprints.length).toBe(1);
@@ -78,18 +84,27 @@ describe("cueloop serve", () => {
78
84
  });
79
85
 
80
86
  test("an anonymous ssh client gets the observer TUI for the session", async () => {
81
- const bytes = await sshCapture(handle.port, (s) => s.includes("Rollout Plan") && s.includes("observer"));
87
+ // Act
88
+ const bytes = await sshCapture(
89
+ handle.port,
90
+ (frame) => frame.includes("Rollout Plan") && frame.includes("observer"),
91
+ );
92
+
93
+ // Assert
82
94
  expect(bytes).toContain("cueloop");
83
95
  expect(bytes).toContain("Rollout Plan");
84
- // observer chrome, not the controller's mutating hint bar
85
- expect(bytes).toContain("observer - read-only");
96
+ // observer chrome: the header badge marks the read-only session
97
+ expect(bytes).toContain("observer");
86
98
  });
87
99
 
88
100
  test("two observers can watch at once", async () => {
101
+ // Act
89
102
  const [a, b] = await Promise.all([
90
- sshCapture(handle.port, (s) => s.includes("Rollout Plan")),
91
- sshCapture(handle.port, (s) => s.includes("Rollout Plan")),
103
+ sshCapture(handle.port, (frame) => frame.includes("Rollout Plan")),
104
+ sshCapture(handle.port, (frame) => frame.includes("Rollout Plan")),
92
105
  ]);
106
+
107
+ // Assert
93
108
  expect(a).toContain("Rollout Plan");
94
109
  expect(b).toContain("Rollout Plan");
95
110
  });
package/src/serve.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * SSH-served TUI (#22 share path): `cueloop serve` lets teammates join a
2
+ * SSH-served TUI: `cueloop serve` lets teammates join a
3
3
  * review session over plain ssh. Every SSH connection renders <App> in
4
4
  * observer mode (readOnly) against the same local daemon; the one writable
5
5
  * controller stays the local owner's own `cueloop` TUI.
@@ -44,8 +44,8 @@ export interface ServeHandle {
44
44
  close(): Promise<void>;
45
45
  }
46
46
 
47
- export async function serveClient(opts: ServeOptions = {}): Promise<ServeHandle> {
48
- const home = opts.home ?? cueloopHome();
47
+ export async function serveClient(options: ServeOptions = {}): Promise<ServeHandle> {
48
+ const home = options.home ?? cueloopHome();
49
49
  const sshDir = join(home, "ssh");
50
50
  mkdirSync(sshDir, { recursive: true, mode: 0o700 });
51
51
 
@@ -53,15 +53,15 @@ export async function serveClient(opts: ServeOptions = {}): Promise<ServeHandle>
53
53
  // password-less by design; see the trust model in the module comment
54
54
  auth: "open",
55
55
  hostKey: { path: join(sshDir, "host_key") },
56
- startupBanner: opts.banner ?? true,
56
+ startupBanner: options.banner ?? true,
57
57
  idleTimeout: "2h",
58
- onError: opts.onError,
58
+ onError: options.onError,
59
59
  }).serve((session) => {
60
60
  const root = createRoot(session.renderer);
61
61
  root.render(
62
62
  React.createElement(App, {
63
63
  home,
64
- sessionId: opts.sessionId,
64
+ sessionId: options.sessionId,
65
65
  readOnly: true,
66
66
  // q disconnects only this observer, never the server
67
67
  onExit: () => session.end(),
@@ -70,6 +70,6 @@ export async function serveClient(opts: ServeOptions = {}): Promise<ServeHandle>
70
70
  session.onClose(() => root.unmount());
71
71
  });
72
72
 
73
- const info = await server.listen(opts.port ?? 2222, opts.host ?? "127.0.0.1");
73
+ const info = await server.listen(options.port ?? 2222, options.host ?? "127.0.0.1");
74
74
  return { ...info, close: () => server.close() };
75
75
  }
@@ -0,0 +1,253 @@
1
+ import { describe, expect, mock, test } from "bun:test";
2
+ import { SCHEMA_VERSION, type DiffFileContents, type ReviewSession } from "@cueloop/schema";
3
+ import type { SessionClient } from "@cueloop/daemon/client";
4
+ import { createReviewController } from "./session-controller";
5
+
6
+ const PATCH = `diff --git a/src/store.ts b/src/store.ts
7
+ index 111..222 100644
8
+ --- a/src/store.ts
9
+ +++ b/src/store.ts
10
+ @@ -1,4 +1,4 @@
11
+ export class Store {
12
+ - private items = [];
13
+ + private items = new Map();
14
+ }
15
+ `;
16
+
17
+ const FILES: DiffFileContents[] = [
18
+ {
19
+ path: "src/store.ts",
20
+ oldContents: "export class Store {\n private items = [];\n}\n",
21
+ newContents: "export class Store {\n private items = new Map();\n}\n",
22
+ status: "modified",
23
+ },
24
+ ];
25
+
26
+ function diffSession(files?: DiffFileContents[]): ReviewSession {
27
+ return {
28
+ schemaVersion: SCHEMA_VERSION,
29
+ id: "ses_diff",
30
+ workspace: { repoRoot: "/repo", branch: "main" },
31
+ artifact: { type: "diff", content: PATCH, meta: {}, files },
32
+ revisions: [{ revision: 1, content: PATCH, submittedAt: "2026-01-01T00:00:00.000Z" }],
33
+ annotations: [],
34
+ verdict: null,
35
+ status: "pending",
36
+ createdAt: "2026-01-01T00:00:00.000Z",
37
+ };
38
+ }
39
+
40
+ /** A fake client that records the working copy the controller writes. */
41
+ function fakeClient(session: ReviewSession, sink: { workingCopy?: string }): SessionClient {
42
+ return {
43
+ onEvent: () => () => {},
44
+ subscribe: async () => {},
45
+ sessionGet: async () => session,
46
+ sessionList: async () => [session],
47
+ sessionSetWorkingCopy: mock(async (_id: string, content: string | undefined) => {
48
+ sink.workingCopy = content;
49
+ return { ...session, workingCopy: content };
50
+ }),
51
+ close: () => {},
52
+ } as unknown as SessionClient;
53
+ }
54
+
55
+ const tick = () => new Promise((resolve) => setTimeout(resolve, 0));
56
+
57
+ async function connected(session: ReviewSession) {
58
+ const sink: { workingCopy?: string } = {};
59
+ const client = fakeClient(session, sink);
60
+ const controller = createReviewController({
61
+ sessionId: session.id,
62
+ openClient: async () => client,
63
+ });
64
+ controller.connect();
65
+ await tick();
66
+ return { controller, client, sink };
67
+ }
68
+
69
+ // rows for PATCH: file(0), hunk(1), ctx(2), del(3), add(4), ctx(5)
70
+ describe("diff hunk curation", () => {
71
+ test("rejecting the only change writes an empty curated working copy", async () => {
72
+ // Arrange
73
+ const { controller, sink } = await connected(diffSession(FILES));
74
+
75
+ // Act - reject the change on the added line
76
+ controller.toggleRejectChange(4);
77
+ await tick();
78
+
79
+ // Assert
80
+ expect(controller.getSnapshot().status).toContain("change rejected");
81
+ expect(sink.workingCopy).toBe("");
82
+ });
83
+
84
+ test("both the deletion and addition rows of the change dim", async () => {
85
+ // Arrange
86
+ const { controller } = await connected(diffSession(FILES));
87
+
88
+ // Act
89
+ controller.toggleRejectChange(4);
90
+ await tick();
91
+
92
+ // Assert - the change spans the del row and the add row
93
+ expect([...controller.rejectedRows()].sort((a, b) => a - b)).toEqual([3, 4]);
94
+ });
95
+
96
+ test("toggling the same change twice restores the full diff", async () => {
97
+ // Arrange
98
+ const { controller, sink } = await connected(diffSession(FILES));
99
+
100
+ // Act - reject then restore
101
+ controller.toggleRejectChange(4);
102
+ await tick();
103
+ controller.toggleRejectChange(4);
104
+ await tick();
105
+
106
+ // Assert - no decisions left, so the working copy reverts to undefined
107
+ expect(controller.getSnapshot().status).toContain("change restored");
108
+ expect(sink.workingCopy).toBeUndefined();
109
+ expect(controller.rejectedRows().size).toBe(0);
110
+ });
111
+
112
+ test("whole-hunk reject drops the hunk from the working copy", async () => {
113
+ // Arrange
114
+ const { controller, sink } = await connected(diffSession(FILES));
115
+
116
+ // Act - reject the whole hunk from any of its rows
117
+ controller.toggleRejectHunk(3);
118
+ await tick();
119
+
120
+ // Assert - the single hunk is the whole diff, so nothing remains
121
+ expect(controller.getSnapshot().status).toContain("hunk rejected");
122
+ expect(sink.workingCopy).toBe("");
123
+ });
124
+
125
+ test("a rejected change becomes a removal card with a source, id, and preview", async () => {
126
+ // Arrange
127
+ const { controller } = await connected(diffSession(FILES));
128
+
129
+ // Act
130
+ controller.toggleRejectChange(4);
131
+ await tick();
132
+
133
+ // Assert - one item: diff source, revealing the change's row, both lines previewed
134
+ const items = controller.curationItems();
135
+ expect(items.length).toBe(1);
136
+ expect(items[0]!.source).toBe("diff");
137
+ expect(items[0]!.id).toBe("diff:src/store.ts#0#1");
138
+ expect(items[0]!.revealIndex).toBe(3);
139
+ expect(items[0]!.preview).toEqual([
140
+ "- private items = [];",
141
+ "+ private items = new Map();",
142
+ ]);
143
+ });
144
+
145
+ test("a rejected hunk becomes a removal card with the whole-hunk id", async () => {
146
+ // Arrange
147
+ const { controller } = await connected(diffSession(FILES));
148
+
149
+ // Act
150
+ controller.toggleRejectHunk(3);
151
+ await tick();
152
+
153
+ // Assert - the whole hunk, id diff:path#hunk#hunk
154
+ const items = controller.curationItems();
155
+ expect(items.length).toBe(1);
156
+ expect(items[0]!.source).toBe("diff");
157
+ expect(items[0]!.id).toBe("diff:src/store.ts#0#hunk");
158
+ });
159
+
160
+ test("restoreCuration drops the diff removal and reverts the working copy", async () => {
161
+ // Arrange - one change rejected
162
+ const { controller, sink } = await connected(diffSession(FILES));
163
+ controller.toggleRejectChange(4);
164
+ await tick();
165
+ const [item] = controller.curationItems();
166
+
167
+ // Act
168
+ controller.restoreCuration(item!.id);
169
+ await tick();
170
+
171
+ // Assert - the list empties and the working copy reverts to the full diff
172
+ expect(controller.getSnapshot().status).toContain("removal restored");
173
+ expect(controller.curationItems().length).toBe(0);
174
+ expect(sink.workingCopy).toBeUndefined();
175
+ expect(controller.rejectedRows().size).toBe(0);
176
+ });
177
+
178
+ test("restoreCuration ignores an unknown id", async () => {
179
+ // Arrange - one change rejected
180
+ const { controller } = await connected(diffSession(FILES));
181
+ controller.toggleRejectChange(4);
182
+ await tick();
183
+
184
+ // Act
185
+ controller.restoreCuration("diff:nope#0#0");
186
+ await tick();
187
+
188
+ // Assert - the item stays
189
+ expect(controller.curationItems().length).toBe(1);
190
+ });
191
+
192
+ test("curation is disabled without full file contents", async () => {
193
+ // Arrange - a legacy diff with no artifact.files
194
+ const { controller, sink } = await connected(diffSession(undefined));
195
+
196
+ // Act
197
+ controller.toggleRejectChange(4);
198
+ await tick();
199
+
200
+ // Assert
201
+ expect(controller.getSnapshot().status).toContain("hunk curation needs full file contents");
202
+ expect(sink.workingCopy).toBeUndefined();
203
+ });
204
+ });
205
+
206
+ const PLAN_CONTENT = "# Title\n\nFirst paragraph.\n\nSecond paragraph.\n";
207
+ // the working copy with the "Second paragraph." block cut out
208
+ const PLAN_CUT = "# Title\n\nFirst paragraph.\n";
209
+
210
+ function planSession(workingCopy?: string): ReviewSession {
211
+ return {
212
+ schemaVersion: SCHEMA_VERSION,
213
+ id: "ses_plan",
214
+ workspace: { repoRoot: "/repo", branch: "main" },
215
+ artifact: { type: "plan", content: PLAN_CONTENT, meta: {} },
216
+ revisions: [{ revision: 1, content: PLAN_CONTENT, submittedAt: "2026-01-01T00:00:00.000Z" }],
217
+ annotations: [],
218
+ verdict: null,
219
+ status: "pending",
220
+ createdAt: "2026-01-01T00:00:00.000Z",
221
+ workingCopy,
222
+ };
223
+ }
224
+
225
+ describe("plan cut removals", () => {
226
+ test("a cut block becomes a plan removal card previewing its content", async () => {
227
+ // Arrange - a plan whose working copy dropped the second paragraph
228
+ const { controller } = await connected(planSession(PLAN_CUT));
229
+
230
+ // Act
231
+ const items = controller.curationItems();
232
+
233
+ // Assert - one plan-source removal, keyed on the base line range, content previewed
234
+ expect(items.length).toBe(1);
235
+ expect(items[0]!.source).toBe("plan");
236
+ expect(items[0]!.id).toBe("plan:4-4");
237
+ expect(items[0]!.preview).toEqual(["Second paragraph."]);
238
+ });
239
+
240
+ test("restoreCuration re-inserts the cut block and returns to pristine", async () => {
241
+ // Arrange
242
+ const { controller, sink } = await connected(planSession(PLAN_CUT));
243
+ const [item] = controller.curationItems();
244
+
245
+ // Act
246
+ controller.restoreCuration(item!.id);
247
+ await tick();
248
+
249
+ // Assert - restoring the only cut round-trips to the submitted revision
250
+ expect(controller.getSnapshot().status).toContain("removal restored");
251
+ expect(sink.workingCopy).toBeUndefined();
252
+ });
253
+ });