@cueloop/client 0.1.0-alpha.8 → 0.1.0-alpha.9

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.
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@cueloop/client",
3
- "version": "0.1.0-alpha.8",
3
+ "version": "0.1.0-alpha.9",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./src/index.ts"
8
8
  },
9
9
  "dependencies": {
10
- "@cueloop/daemon": "0.1.0-alpha.8",
11
- "@cueloop/extension-api": "0.1.0-alpha.8",
12
- "@cueloop/integration-obsidian": "0.1.0-alpha.8",
13
- "@cueloop/schema": "0.1.0-alpha.8",
10
+ "@cueloop/daemon": "0.1.0-alpha.9",
11
+ "@cueloop/extension-api": "0.1.0-alpha.9",
12
+ "@cueloop/integration-obsidian": "0.1.0-alpha.9",
13
+ "@cueloop/schema": "0.1.0-alpha.9",
14
14
  "@opentui/core": "^0.4.3",
15
15
  "@opentui/react": "^0.4.3",
16
16
  "@opentui/ssh": "0.4.5",
@@ -0,0 +1,259 @@
1
+ /**
2
+ * The plan review surface v2 (#71): native selection feeds the annotation
3
+ * quote, the inline compose box keeps its anchor painted, the rail edits what
4
+ * the document selects, and edit-exit reconciliation orphans annotations
5
+ * whose passage was removed. Char-frame + styled-span assertions over the
6
+ * real App and a real in-process daemon.
7
+ */
8
+
9
+ import { afterEach, beforeEach, describe, expect, test } from "bun:test";
10
+ import { mkdtempSync, rmSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
13
+ import React from "react";
14
+ import { testRender } from "@opentui/react/test-utils";
15
+ import { DaemonServer } from "@cueloop/daemon";
16
+ import type { ReviewSession } from "@cueloop/schema";
17
+ import { App } from "./App";
18
+ import { DARK as T } from "./theme";
19
+
20
+ const PLAN = `# Migration Plan
21
+
22
+ ## Context
23
+
24
+ The daemon persists sessions to disk atomically.
25
+
26
+ ## Steps
27
+
28
+ - move the store
29
+ - add recovery
30
+ `;
31
+
32
+ let home: string;
33
+ let server: DaemonServer;
34
+ let session: ReviewSession;
35
+
36
+ beforeEach(() => {
37
+ home = mkdtempSync(join(tmpdir(), "cueloop-plan-review-"));
38
+ server = new DaemonServer({ home, idleExitMs: 0 });
39
+ server.start();
40
+ session = server.core.sessionCreate({
41
+ workspace: { repoRoot: "/repo", branch: "main" },
42
+ artifact: { type: "plan", content: PLAN, meta: { title: "Migration Plan", planPath: "plan.md", agent: "agent/worker-3" } },
43
+ });
44
+ });
45
+ afterEach(() => {
46
+ server.stop();
47
+ rmSync(home, { recursive: true, force: true });
48
+ });
49
+
50
+ async function renderApp() {
51
+ const setup = await testRender(<App home={home} sessionId={session.id} />, {
52
+ width: 120,
53
+ height: 32,
54
+ });
55
+ for (let attempt = 0; attempt < 40 && !setup.captureCharFrame().includes("cueloop"); attempt++) {
56
+ await Bun.sleep(25);
57
+ await setup.renderOnce();
58
+ }
59
+ await setup.renderOnce();
60
+ return setup;
61
+ }
62
+
63
+ type Setup = Awaited<ReturnType<typeof renderApp>>;
64
+
65
+ async function press(setup: Setup, k: string): Promise<void> {
66
+ if (k === "enter") setup.mockInput.pressKey("RETURN");
67
+ else if (k === "escape") {
68
+ setup.mockInput.pressKey("ESCAPE");
69
+ // a bare ESC byte is an ambiguous sequence prefix; the parser settles late
70
+ await Bun.sleep(120);
71
+ } else await type(setup, k);
72
+ await Bun.sleep(15);
73
+ await setup.renderOnce();
74
+ }
75
+
76
+ async function type(setup: Setup, text: string): Promise<void> {
77
+ await setup.mockInput.typeText(text);
78
+ await Bun.sleep(15);
79
+ await setup.renderOnce();
80
+ }
81
+
82
+ /**
83
+ * Background colors (hex) of every styled span containing the needle - the
84
+ * document highlight and the rail's quote excerpt can both match.
85
+ */
86
+ function backgroundsOf(setup: Setup, needle: string): string[] {
87
+ const backgrounds: string[] = [];
88
+ for (const line of setup.captureSpans().lines) {
89
+ for (const span of line.spans) {
90
+ if (!span.text.includes(needle)) continue;
91
+ const [red, green, blue] = span.bg.toInts();
92
+ backgrounds.push("#" + [red, green, blue].map((part) => part.toString(16).padStart(2, "0")).join(""));
93
+ }
94
+ }
95
+ return backgrounds;
96
+ }
97
+
98
+ /** Move the cursor to "The daemon persists sessions to disk atomically." */
99
+ async function toContextParagraph(setup: Setup): Promise<void> {
100
+ await press(setup, "j");
101
+ await press(setup, "j");
102
+ }
103
+
104
+ describe("selection feeds the annotation quote", () => {
105
+ test("v anchors, l extends, c composes with the char-precise quote", async () => {
106
+ const setup = await renderApp();
107
+ await toContextParagraph(setup);
108
+ await press(setup, "v");
109
+ await press(setup, "l"); // "The daemon"
110
+ await press(setup, "c");
111
+ expect(setup.captureCharFrame()).toContain('comment on "The daemon"');
112
+ await type(setup, "Which daemon?");
113
+ await press(setup, "enter");
114
+ await Bun.sleep(80);
115
+ await setup.renderOnce();
116
+ const stored = server.core.sessionGet(session.id);
117
+ expect(stored.annotations.length).toBe(1);
118
+ expect(stored.annotations[0]!.anchor.quote).toBe("The daemon");
119
+ });
120
+
121
+ test("a mouse drag over the text becomes the compose quote", async () => {
122
+ const setup = await renderApp();
123
+ const lines = setup.captureCharFrame().split("\n");
124
+ const row = lines.findIndex((line) => line.includes("persists sessions"));
125
+ const startColumn = lines[row]!.indexOf("persists");
126
+ expect(row).toBeGreaterThan(-1);
127
+ // the drag's end cell is exclusive: release one past the last character
128
+ await setup.mockMouse.drag(startColumn, row, startColumn + "persists sessions".length, row);
129
+ await setup.renderOnce();
130
+ await press(setup, "c");
131
+ expect(setup.captureCharFrame()).toContain('comment on "persists sessions"');
132
+ await type(setup, "sessions plural?");
133
+ await press(setup, "enter");
134
+ await Bun.sleep(80);
135
+ const stored = server.core.sessionGet(session.id);
136
+ expect(stored.annotations[0]!.anchor.quote).toBe("persists sessions");
137
+ });
138
+ });
139
+
140
+ describe("inline compose keeps the anchor painted", () => {
141
+ test("the selection stays painted while composing; cancel un-paints; save converts to the comment highlight", async () => {
142
+ const setup = await renderApp();
143
+ await toContextParagraph(setup);
144
+ await press(setup, "v");
145
+ await press(setup, "l");
146
+ await press(setup, "c");
147
+ // compose open: the anchor is painted selection-style
148
+ expect(setup.captureCharFrame()).toContain("Save ⏎");
149
+ expect(setup.captureCharFrame()).toContain("Cancel esc");
150
+ expect(backgroundsOf(setup, "The daemon")).toContain(T.accent);
151
+ // cancel un-paints
152
+ await press(setup, "escape");
153
+ expect(setup.captureCharFrame()).not.toContain('comment on "');
154
+ expect(backgroundsOf(setup, "The daemon")).not.toContain(T.accent);
155
+ // save converts the paint to the kind-colored annotation highlight
156
+ await press(setup, "c");
157
+ await type(setup, "Which daemon?");
158
+ await press(setup, "enter");
159
+ await Bun.sleep(80);
160
+ await setup.renderOnce();
161
+ // the whole cursor block is the anchor here; check the highlight landed
162
+ const stored = server.core.sessionGet(session.id);
163
+ expect(stored.annotations.length).toBe(1);
164
+ expect(backgroundsOf(setup, stored.annotations[0]!.anchor.quote.slice(0, 20))).toContain(T.markCommentBg);
165
+ });
166
+ });
167
+
168
+ describe("the document selects, the rail edits", () => {
169
+ test("e edits the selected card in place; enter saves through the controller", async () => {
170
+ const setup = await renderApp();
171
+ await toContextParagraph(setup);
172
+ await press(setup, "c");
173
+ await type(setup, "Needs a citation.");
174
+ await press(setup, "enter");
175
+ await Bun.sleep(80);
176
+ await setup.renderOnce();
177
+ expect(setup.captureCharFrame()).toContain("COMMENT · pending");
178
+ // the saved card is selected; e turns its body into an input in place
179
+ await press(setup, "e");
180
+ await type(setup, " And a link.");
181
+ await press(setup, "enter");
182
+ await Bun.sleep(80);
183
+ await setup.renderOnce();
184
+ const stored = server.core.sessionGet(session.id);
185
+ expect(stored.annotations.length).toBe(1);
186
+ expect(stored.annotations[0]!.body).toBe("Needs a citation. And a link.");
187
+ });
188
+
189
+ test("x deletes the selected card and un-paints the document highlight", async () => {
190
+ const setup = await renderApp();
191
+ await toContextParagraph(setup);
192
+ await press(setup, "c");
193
+ await type(setup, "Delete me.");
194
+ await press(setup, "enter");
195
+ await Bun.sleep(80);
196
+ await setup.renderOnce();
197
+ expect(server.core.sessionGet(session.id).annotations.length).toBe(1);
198
+ expect(backgroundsOf(setup, "persists sessions")).toContain(T.markCommentBg);
199
+ await press(setup, "x");
200
+ await Bun.sleep(80);
201
+ await setup.renderOnce();
202
+ expect(server.core.sessionGet(session.id).annotations.length).toBe(0);
203
+ expect(setup.captureCharFrame()).not.toContain("COMMENT · pending");
204
+ expect(backgroundsOf(setup, "persists sessions")).not.toContain(T.markCommentBg);
205
+ });
206
+ });
207
+
208
+ describe("sheet header", () => {
209
+ test("shows the submitting agent, the revision, and the Edit word-button", async () => {
210
+ const setup = await renderApp();
211
+ const frame = setup.captureCharFrame();
212
+ expect(frame).toContain("submitted by agent/worker-3 · revision 1");
213
+ expect(frame).toContain("Edit");
214
+ });
215
+
216
+ test("the Agent tab shows the submitter, status, and revision", async () => {
217
+ const setup = await renderApp();
218
+ const lines = setup.captureCharFrame().split("\n");
219
+ const tabRow = lines.findIndex((line) => line.includes("Review (0)"));
220
+ const tabColumn = lines[tabRow]!.indexOf("Agent");
221
+ await setup.mockMouse.click(tabColumn + 1, tabRow);
222
+ await setup.renderOnce();
223
+ const frame = setup.captureCharFrame();
224
+ expect(frame).toContain("agent/worker-3");
225
+ expect(frame).toContain("status: pending");
226
+ expect(frame).toContain("revision 1");
227
+ });
228
+ });
229
+
230
+ describe("edit-exit reconciliation", () => {
231
+ test("an edit that removes an anchored passage orphans the annotation and shows the banner", async () => {
232
+ const script = join(home, "fake-editor.sh");
233
+ await Bun.write(script, `#!/bin/sh\nsed -i '' '/^The daemon persists/d' "$1"\n`);
234
+ Bun.spawnSync(["chmod", "+x", script]);
235
+ process.env.CUELOOP_EDITOR = script;
236
+ try {
237
+ const setup = await renderApp();
238
+ await toContextParagraph(setup);
239
+ await press(setup, "c");
240
+ await type(setup, "Anchor me to the doomed passage.");
241
+ await press(setup, "enter");
242
+ await Bun.sleep(80);
243
+ await setup.renderOnce();
244
+ expect(setup.captureCharFrame()).toContain("· pending");
245
+ // deselect the card so e reaches the editor hand-off, then edit
246
+ await press(setup, "escape");
247
+ await press(setup, "e");
248
+ await Bun.sleep(150);
249
+ await setup.renderOnce();
250
+ const frame = setup.captureCharFrame();
251
+ expect(frame).toContain("1 annotation no longer match - the passage was removed.");
252
+ expect(frame).toContain("· ORPHANED");
253
+ // the annotation is NOT deleted: the feedback serializer handles orphans
254
+ expect(server.core.sessionGet(session.id).annotations.length).toBe(1);
255
+ } finally {
256
+ delete process.env.CUELOOP_EDITOR;
257
+ }
258
+ });
259
+ });
package/src/App.test.tsx CHANGED
@@ -86,7 +86,7 @@ describe("plan rendering", () => {
86
86
  expect(frame).toContain("Context");
87
87
  expect(frame).toContain("persists sessions to disk atomically");
88
88
  expect(frame).toContain("- move the store");
89
- expect(frame).toContain("REVIEW (0)");
89
+ expect(frame).toContain("Review (0)");
90
90
  expect(frame).toContain("Submit review (0)");
91
91
  });
92
92
  });
@@ -108,7 +108,7 @@ describe("keyboard grammar", () => {
108
108
  await press(setup, "j");
109
109
  await press(setup, "c");
110
110
  await setup.renderOnce();
111
- expect(setup.captureCharFrame()).toContain("COMMENT ON");
111
+ expect(setup.captureCharFrame()).toContain('comment on "The daemon');
112
112
  await type(setup, "Define atomically.");
113
113
  await press(setup, "enter");
114
114
  await Bun.sleep(80);