@cueloop/client 0.1.0-alpha.6 → 0.1.0-alpha.8
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 +5 -5
- package/src/App.tsx +0 -0
- package/src/keymap.test.ts +263 -0
- package/src/keymap.ts +167 -0
- package/src/session-controller.ts +345 -0
- package/src/view.test.ts +6 -6
- package/src/view.ts +0 -0
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cueloop/client",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.8",
|
|
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.
|
|
11
|
-
"@cueloop/extension-api": "0.1.0-alpha.
|
|
12
|
-
"@cueloop/integration-obsidian": "0.1.0-alpha.
|
|
13
|
-
"@cueloop/schema": "0.1.0-alpha.
|
|
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",
|
|
14
14
|
"@opentui/core": "^0.4.3",
|
|
15
15
|
"@opentui/react": "^0.4.3",
|
|
16
16
|
"@opentui/ssh": "0.4.5",
|
package/src/App.tsx
CHANGED
|
Binary file
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keyboard grammar as data: every mode x key produces a known intent
|
|
3
|
+
* list, the read-only rule is one gate, and plan and diff reviews share one
|
|
4
|
+
* path for annotation navigation, deletion, and submit.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, expect, test } from "bun:test";
|
|
8
|
+
import { DEFAULT_KEYS } from "./config";
|
|
9
|
+
import { reduceKey, type Intent, type KeyState } from "./keymap";
|
|
10
|
+
|
|
11
|
+
function state(patch: Partial<KeyState> = {}): KeyState {
|
|
12
|
+
return {
|
|
13
|
+
keys: DEFAULT_KEYS,
|
|
14
|
+
readOnly: false,
|
|
15
|
+
overlay: "none",
|
|
16
|
+
view: "plan",
|
|
17
|
+
spanMode: false,
|
|
18
|
+
resolved: false,
|
|
19
|
+
hasInboxItems: true,
|
|
20
|
+
annotationCount: 1,
|
|
21
|
+
hasFocusedAnnotation: true,
|
|
22
|
+
cursorAnnotatable: true,
|
|
23
|
+
...patch,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function key(name: string, shift = false): { name: string; shift: boolean } {
|
|
28
|
+
return { name, shift };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe("compose overlay", () => {
|
|
32
|
+
const s = state({ overlay: "compose" });
|
|
33
|
+
const table: [string, Intent[]][] = [
|
|
34
|
+
["escape", [{ t: "closeOverlay" }]],
|
|
35
|
+
["return", [{ t: "saveCompose" }]],
|
|
36
|
+
["enter", [{ t: "saveCompose" }]],
|
|
37
|
+
["left", []],
|
|
38
|
+
["right", []],
|
|
39
|
+
["j", []],
|
|
40
|
+
["q", []],
|
|
41
|
+
];
|
|
42
|
+
for (const [name, expected] of table) {
|
|
43
|
+
test(`${name} -> ${JSON.stringify(expected)}`, () => {
|
|
44
|
+
expect(reduceKey(s, key(name))).toEqual(expected);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("submit overlay", () => {
|
|
50
|
+
const s = state({ overlay: "submit" });
|
|
51
|
+
const table: [string, Intent[]][] = [
|
|
52
|
+
["escape", [{ t: "closeOverlay" }]],
|
|
53
|
+
["return", [{ t: "submitVerdict" }]],
|
|
54
|
+
["enter", [{ t: "submitVerdict" }]],
|
|
55
|
+
["left", [{ t: "cycleVerdict", dir: -1 }]],
|
|
56
|
+
["right", [{ t: "cycleVerdict", dir: 1 }]],
|
|
57
|
+
["j", []],
|
|
58
|
+
["q", []],
|
|
59
|
+
];
|
|
60
|
+
for (const [name, expected] of table) {
|
|
61
|
+
test(`${name} -> ${JSON.stringify(expected)}`, () => {
|
|
62
|
+
expect(reduceKey(s, key(name))).toEqual(expected);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("completion overlay", () => {
|
|
68
|
+
const prompt = state({ overlay: "completion-prompt" });
|
|
69
|
+
const counting = state({ overlay: "completion-counting" });
|
|
70
|
+
const table: [KeyState, string, Intent[]][] = [
|
|
71
|
+
[prompt, "return", [{ t: "finishReview" }]],
|
|
72
|
+
[prompt, "enter", [{ t: "finishReview" }]],
|
|
73
|
+
[prompt, "q", [{ t: "finishReview" }]],
|
|
74
|
+
[prompt, "a", [{ t: "optInAutoClose" }]],
|
|
75
|
+
[prompt, "escape", [{ t: "dismissCompletion" }]],
|
|
76
|
+
[prompt, "j", []],
|
|
77
|
+
[counting, "return", [{ t: "finishReview" }]],
|
|
78
|
+
[counting, "q", [{ t: "finishReview" }]],
|
|
79
|
+
[counting, "a", []],
|
|
80
|
+
[counting, "escape", [{ t: "dismissCompletion" }]],
|
|
81
|
+
];
|
|
82
|
+
for (const [s, name, expected] of table) {
|
|
83
|
+
test(`${s.overlay} ${name} -> ${JSON.stringify(expected)}`, () => {
|
|
84
|
+
expect(reduceKey(s, key(name))).toEqual(expected);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe("inbox mode", () => {
|
|
90
|
+
const s = state({ view: "inbox" });
|
|
91
|
+
const table: [string, Intent[]][] = [
|
|
92
|
+
["j", [{ t: "inboxMove", to: "down" }]],
|
|
93
|
+
["down", [{ t: "inboxMove", to: "down" }]],
|
|
94
|
+
["k", [{ t: "inboxMove", to: "up" }]],
|
|
95
|
+
["up", [{ t: "inboxMove", to: "up" }]],
|
|
96
|
+
["return", [{ t: "openSession" }]],
|
|
97
|
+
["enter", [{ t: "openSession" }]],
|
|
98
|
+
["q", [{ t: "exit" }]],
|
|
99
|
+
["c", []],
|
|
100
|
+
["escape", []],
|
|
101
|
+
];
|
|
102
|
+
for (const [name, expected] of table) {
|
|
103
|
+
test(`${name} -> ${JSON.stringify(expected)}`, () => {
|
|
104
|
+
expect(reduceKey(s, key(name))).toEqual(expected);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
test("an empty inbox swallows every non-quit key", () => {
|
|
109
|
+
const empty = state({ view: "inbox", hasInboxItems: false });
|
|
110
|
+
for (const name of ["j", "k", "down", "up", "return", "enter"]) {
|
|
111
|
+
expect(reduceKey(empty, key(name))).toEqual([]);
|
|
112
|
+
}
|
|
113
|
+
expect(reduceKey(empty, key("q"))).toEqual([{ t: "exit" }]);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("plan normal mode", () => {
|
|
118
|
+
const s = state();
|
|
119
|
+
const table: [string, boolean, Intent[]][] = [
|
|
120
|
+
["j", false, [{ t: "move", to: "down" }]],
|
|
121
|
+
["down", false, [{ t: "move", to: "down" }]],
|
|
122
|
+
["k", false, [{ t: "move", to: "up" }]],
|
|
123
|
+
["up", false, [{ t: "move", to: "up" }]],
|
|
124
|
+
["g", false, [{ t: "move", to: "top" }]],
|
|
125
|
+
["g", true, [{ t: "move", to: "bottom" }]],
|
|
126
|
+
["v", false, [{ t: "startSpan" }]],
|
|
127
|
+
["c", false, [{ t: "openCompose", kind: "comment", from: "cursor" }]],
|
|
128
|
+
["s", false, [{ t: "openCompose", kind: "suggestion", from: "cursor" }]],
|
|
129
|
+
["x", false, [{ t: "cut" }]],
|
|
130
|
+
["e", false, [{ t: "edit" }]],
|
|
131
|
+
["n", false, [{ t: "nextAnn" }]],
|
|
132
|
+
["p", false, [{ t: "prevAnn" }]],
|
|
133
|
+
["backspace", false, [{ t: "removeAnnotation" }]],
|
|
134
|
+
["return", false, [{ t: "openSubmit" }]],
|
|
135
|
+
["q", false, [{ t: "exit" }]],
|
|
136
|
+
["escape", false, []],
|
|
137
|
+
["z", false, []],
|
|
138
|
+
];
|
|
139
|
+
for (const [name, shift, expected] of table) {
|
|
140
|
+
test(`${shift ? "shift+" : ""}${name} -> ${JSON.stringify(expected)}`, () => {
|
|
141
|
+
expect(reduceKey(s, key(name, shift))).toEqual(expected);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
test("resolved sessions guard the mutating verbs", () => {
|
|
146
|
+
const r = state({ resolved: true });
|
|
147
|
+
for (const name of ["c", "s", "x", "e"]) {
|
|
148
|
+
expect(reduceKey(r, key(name))).toEqual([{ t: "status", msg: "review submitted - read-only" }]);
|
|
149
|
+
}
|
|
150
|
+
expect(reduceKey(r, key("return"))).toEqual([]);
|
|
151
|
+
expect(reduceKey(r, key("backspace"))).toEqual([]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("cut text cannot host a comment or a span", () => {
|
|
155
|
+
const cut = state({ cursorAnnotatable: false });
|
|
156
|
+
expect(reduceKey(cut, key("c"))).toEqual([{ t: "status", msg: "text is cut - restore it first" }]);
|
|
157
|
+
expect(reduceKey(cut, key("s"))).toEqual([{ t: "status", msg: "text is cut - restore it first" }]);
|
|
158
|
+
expect(reduceKey(cut, key("v"))).toEqual([]);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("annotation navigation without annotations reports, delete without focus is silent", () => {
|
|
162
|
+
const none = state({ annotationCount: 0, hasFocusedAnnotation: false });
|
|
163
|
+
expect(reduceKey(none, key("n"))).toEqual([{ t: "status", msg: "no annotations" }]);
|
|
164
|
+
expect(reduceKey(none, key("p"))).toEqual([{ t: "status", msg: "no annotations" }]);
|
|
165
|
+
expect(reduceKey(none, key("backspace"))).toEqual([]);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("span mode", () => {
|
|
170
|
+
const s = state({ spanMode: true });
|
|
171
|
+
const table: [string, Intent[]][] = [
|
|
172
|
+
["l", [{ t: "spanKey", name: "l" }]],
|
|
173
|
+
["h", [{ t: "spanKey", name: "h" }]],
|
|
174
|
+
["w", [{ t: "spanKey", name: "w" }]],
|
|
175
|
+
["b", [{ t: "spanKey", name: "b" }]],
|
|
176
|
+
["$", [{ t: "spanKey", name: "$" }]],
|
|
177
|
+
["0", [{ t: "spanKey", name: "0" }]],
|
|
178
|
+
["c", [{ t: "openCompose", kind: "comment", from: "span" }]],
|
|
179
|
+
["s", [{ t: "openCompose", kind: "suggestion", from: "span" }]],
|
|
180
|
+
["escape", [{ t: "closeOverlay" }]],
|
|
181
|
+
["q", [{ t: "exit" }]],
|
|
182
|
+
["j", []],
|
|
183
|
+
];
|
|
184
|
+
for (const [name, expected] of table) {
|
|
185
|
+
test(`${name} -> ${JSON.stringify(expected)}`, () => {
|
|
186
|
+
expect(reduceKey(s, key(name))).toEqual(expected);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe("diff mode", () => {
|
|
192
|
+
const s = state({ view: "diff" });
|
|
193
|
+
const table: [string, Intent[]][] = [
|
|
194
|
+
["j", [{ t: "move", to: "down" }]],
|
|
195
|
+
["k", [{ t: "move", to: "up" }]],
|
|
196
|
+
["g", [{ t: "move", to: "top" }]],
|
|
197
|
+
["c", [{ t: "openCompose", kind: "comment", from: "cursor" }]],
|
|
198
|
+
["n", [{ t: "nextAnn" }]],
|
|
199
|
+
["p", [{ t: "prevAnn" }]],
|
|
200
|
+
["backspace", [{ t: "removeAnnotation" }]],
|
|
201
|
+
["return", [{ t: "openSubmit" }]],
|
|
202
|
+
["v", [{ t: "status", msg: "plan-only verb - diff review uses c on a line" }]],
|
|
203
|
+
["x", [{ t: "status", msg: "plan-only verb - diff review uses c on a line" }]],
|
|
204
|
+
["e", [{ t: "status", msg: "plan-only verb - diff review uses c on a line" }]],
|
|
205
|
+
["s", [{ t: "status", msg: "plan-only verb - diff review uses c on a line" }]],
|
|
206
|
+
["q", [{ t: "exit" }]],
|
|
207
|
+
];
|
|
208
|
+
for (const [name, expected] of table) {
|
|
209
|
+
test(`${name} -> ${JSON.stringify(expected)}`, () => {
|
|
210
|
+
expect(reduceKey(s, key(name))).toEqual(expected);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
test("comment guards: resolved first, then non-code rows", () => {
|
|
215
|
+
expect(reduceKey(state({ view: "diff", resolved: true }), key("c"))).toEqual([
|
|
216
|
+
{ t: "status", msg: "review submitted - read-only" },
|
|
217
|
+
]);
|
|
218
|
+
expect(reduceKey(state({ view: "diff", cursorAnnotatable: false }), key("c"))).toEqual([
|
|
219
|
+
{ t: "status", msg: "move to a code line to comment" },
|
|
220
|
+
]);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe("duplicated-branch collapse", () => {
|
|
225
|
+
test("plan and diff produce the same intents for annotation nav, delete, and submit", () => {
|
|
226
|
+
for (const patch of [
|
|
227
|
+
{},
|
|
228
|
+
{ annotationCount: 0, hasFocusedAnnotation: false },
|
|
229
|
+
{ resolved: true },
|
|
230
|
+
] as Partial<KeyState>[]) {
|
|
231
|
+
for (const name of ["n", "p", "backspace", "return"]) {
|
|
232
|
+
const plan = reduceKey(state(patch), key(name));
|
|
233
|
+
const diff = reduceKey(state({ ...patch, view: "diff" }), key(name));
|
|
234
|
+
expect(diff).toEqual(plan);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe("read-only filter", () => {
|
|
241
|
+
test("every mutating key answers observer - read-only, in plan and diff", () => {
|
|
242
|
+
for (const view of ["plan", "diff"] as const) {
|
|
243
|
+
const s = state({ view, readOnly: true });
|
|
244
|
+
for (const name of ["c", "s", "x", "e", "backspace", "return", "enter"]) {
|
|
245
|
+
expect(reduceKey(s, key(name))).toEqual([{ t: "status", msg: "observer - read-only" }]);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("navigation and annotation focus still work for observers", () => {
|
|
251
|
+
const s = state({ readOnly: true });
|
|
252
|
+
expect(reduceKey(s, key("j"))).toEqual([{ t: "move", to: "down" }]);
|
|
253
|
+
expect(reduceKey(s, key("n"))).toEqual([{ t: "nextAnn" }]);
|
|
254
|
+
expect(reduceKey(s, key("q"))).toEqual([{ t: "exit" }]);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test("span-mode c/s are gated by key name even under a rebound keymap", () => {
|
|
258
|
+
const rebound = { ...DEFAULT_KEYS, comment: ["m"], suggest: ["t"] };
|
|
259
|
+
const s = state({ spanMode: true, readOnly: true, keys: rebound });
|
|
260
|
+
expect(reduceKey(s, key("c"))).toEqual([{ t: "status", msg: "observer - read-only" }]);
|
|
261
|
+
expect(reduceKey(s, key("s"))).toEqual([{ t: "status", msg: "observer - read-only" }]);
|
|
262
|
+
});
|
|
263
|
+
});
|
package/src/keymap.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keyboard grammar as a pure reducer (#70): view state in, intents out.
|
|
3
|
+
* App builds a KeyState per key event, calls reduceKey, and dispatches the
|
|
4
|
+
* intents to controller verbs and view-state setters - no branch bodies live
|
|
5
|
+
* in the key handler. Diff and plan reviews share one path for annotation
|
|
6
|
+
* navigation, deletion, and submit; the read-only rule is one gate here.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { actionFor } from "./config";
|
|
10
|
+
|
|
11
|
+
export type Intent =
|
|
12
|
+
| { t: "exit" }
|
|
13
|
+
| { t: "status"; msg: string }
|
|
14
|
+
| { t: "move"; to: "down" | "up" | "top" | "bottom" }
|
|
15
|
+
| { t: "inboxMove"; to: "down" | "up" }
|
|
16
|
+
| { t: "openSession" }
|
|
17
|
+
| { t: "startSpan" }
|
|
18
|
+
| { t: "spanKey"; name: string }
|
|
19
|
+
| { t: "openCompose"; kind: "comment" | "suggestion"; from: "cursor" | "span" }
|
|
20
|
+
| { t: "openSubmit" }
|
|
21
|
+
| { t: "cut" }
|
|
22
|
+
| { t: "edit" }
|
|
23
|
+
| { t: "nextAnn" }
|
|
24
|
+
| { t: "prevAnn" }
|
|
25
|
+
| { t: "removeAnnotation" }
|
|
26
|
+
| { t: "closeOverlay" }
|
|
27
|
+
| { t: "saveCompose" }
|
|
28
|
+
| { t: "submitVerdict" }
|
|
29
|
+
| { t: "cycleVerdict"; dir: -1 | 1 }
|
|
30
|
+
| { t: "finishReview" }
|
|
31
|
+
| { t: "optInAutoClose" }
|
|
32
|
+
| { t: "dismissCompletion" };
|
|
33
|
+
|
|
34
|
+
export interface KeyInput {
|
|
35
|
+
name: string;
|
|
36
|
+
shift: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface KeyState {
|
|
40
|
+
/** Loaded keymap (config.ts): action -> key combos. */
|
|
41
|
+
keys: Record<string, string[]>;
|
|
42
|
+
readOnly: boolean;
|
|
43
|
+
/** Layer that owns keys before the grammar runs. */
|
|
44
|
+
overlay: "none" | "compose" | "submit" | "completion-prompt" | "completion-counting";
|
|
45
|
+
view: "inbox" | "plan" | "diff";
|
|
46
|
+
/** Plan-only span selection sub-mode. */
|
|
47
|
+
spanMode: boolean;
|
|
48
|
+
resolved: boolean;
|
|
49
|
+
hasInboxItems: boolean;
|
|
50
|
+
annotationCount: number;
|
|
51
|
+
hasFocusedAnnotation: boolean;
|
|
52
|
+
/** Cursor sits on annotatable text: a work block (plan) or a code row (diff). */
|
|
53
|
+
cursorAnnotatable: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Verbs that write session state; an observer never reaches their handlers. */
|
|
57
|
+
const MUTATING_ACTIONS = new Set(["comment", "suggest", "cut", "edit", "delete_annotation", "submit"]);
|
|
58
|
+
|
|
59
|
+
const SPAN_KEYS = ["l", "h", "w", "b", "$", "0"];
|
|
60
|
+
|
|
61
|
+
function status(msg: string): Intent[] {
|
|
62
|
+
return [{ t: "status", msg }];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function reduceKey(state: KeyState, key: KeyInput): Intent[] {
|
|
66
|
+
const name = key.name;
|
|
67
|
+
// compose/submit overlays own the keys via focused inputs; only escape,
|
|
68
|
+
// return, and verdict arrows route through the grammar
|
|
69
|
+
if (state.overlay === "compose" || state.overlay === "submit") {
|
|
70
|
+
if (name === "escape") return [{ t: "closeOverlay" }];
|
|
71
|
+
if (name === "return" || name === "enter") {
|
|
72
|
+
return [state.overlay === "compose" ? { t: "saveCompose" } : { t: "submitVerdict" }];
|
|
73
|
+
}
|
|
74
|
+
if (state.overlay === "submit" && (name === "left" || name === "right")) {
|
|
75
|
+
return [{ t: "cycleVerdict", dir: name === "left" ? -1 : 1 }];
|
|
76
|
+
}
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
if (state.overlay === "completion-prompt" || state.overlay === "completion-counting") {
|
|
80
|
+
if (name === "return" || name === "enter" || name === "q") return [{ t: "finishReview" }];
|
|
81
|
+
if (name === "a" && state.overlay === "completion-prompt") return [{ t: "optInAutoClose" }];
|
|
82
|
+
if (name === "escape") return [{ t: "dismissCompletion" }];
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
const action = actionFor(state.keys, name, key.shift);
|
|
86
|
+
if (action === "quit") return [{ t: "exit" }];
|
|
87
|
+
// the ONE read-only rule: any mutating attempt answers instead of acting
|
|
88
|
+
// (span-mode c/s are hardwired keys, so they gate by name as well)
|
|
89
|
+
const mutating = MUTATING_ACTIONS.has(action ?? "") || (state.spanMode && (name === "c" || name === "s"));
|
|
90
|
+
if (state.readOnly && mutating) return status("observer - read-only");
|
|
91
|
+
|
|
92
|
+
if (state.view === "inbox") return inboxGrammar(state, name);
|
|
93
|
+
if (state.view === "diff") return diffGrammar(state, action);
|
|
94
|
+
if (state.spanMode) return spanGrammar(name);
|
|
95
|
+
return planGrammar(state, action);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function inboxGrammar(state: KeyState, name: string): Intent[] {
|
|
99
|
+
if (!state.hasInboxItems) return [];
|
|
100
|
+
if (name === "j" || name === "down") return [{ t: "inboxMove", to: "down" }];
|
|
101
|
+
if (name === "k" || name === "up") return [{ t: "inboxMove", to: "up" }];
|
|
102
|
+
if (name === "return" || name === "enter") return [{ t: "openSession" }];
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function diffGrammar(state: KeyState, action: string | undefined): Intent[] {
|
|
107
|
+
const nav = navIntent(action);
|
|
108
|
+
if (nav) return nav;
|
|
109
|
+
if (action === "comment") {
|
|
110
|
+
if (state.resolved) return status("review submitted - read-only");
|
|
111
|
+
if (!state.cursorAnnotatable) return status("move to a code line to comment");
|
|
112
|
+
return [{ t: "openCompose", kind: "comment", from: "cursor" }];
|
|
113
|
+
}
|
|
114
|
+
const shared = annotationCluster(state, action);
|
|
115
|
+
if (shared) return shared;
|
|
116
|
+
if (action === "span" || action === "cut" || action === "edit" || action === "suggest") {
|
|
117
|
+
return status("plan-only verb - diff review uses c on a line");
|
|
118
|
+
}
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function spanGrammar(name: string): Intent[] {
|
|
123
|
+
if (name === "escape") return [{ t: "closeOverlay" }];
|
|
124
|
+
if (SPAN_KEYS.includes(name)) return [{ t: "spanKey", name }];
|
|
125
|
+
if (name === "c" || name === "s") {
|
|
126
|
+
return [{ t: "openCompose", kind: name === "s" ? "suggestion" : "comment", from: "span" }];
|
|
127
|
+
}
|
|
128
|
+
return [];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function planGrammar(state: KeyState, action: string | undefined): Intent[] {
|
|
132
|
+
const nav = navIntent(action);
|
|
133
|
+
if (nav) return nav;
|
|
134
|
+
if (action === "span") return state.cursorAnnotatable ? [{ t: "startSpan" }] : [];
|
|
135
|
+
if (action === "comment" || action === "suggest") {
|
|
136
|
+
if (state.resolved) return status("review submitted - read-only");
|
|
137
|
+
if (!state.cursorAnnotatable) return status("text is cut - restore it first");
|
|
138
|
+
return [{ t: "openCompose", kind: action === "suggest" ? "suggestion" : "comment", from: "cursor" }];
|
|
139
|
+
}
|
|
140
|
+
if (action === "cut" || action === "edit") {
|
|
141
|
+
if (state.resolved) return status("review submitted - read-only");
|
|
142
|
+
return [{ t: action }];
|
|
143
|
+
}
|
|
144
|
+
return annotationCluster(state, action) ?? [];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Cursor movement is the same intent everywhere; views clamp their own bounds. */
|
|
148
|
+
function navIntent(action: string | undefined): Intent[] | null {
|
|
149
|
+
if (action === "down" || action === "up" || action === "top" || action === "bottom") {
|
|
150
|
+
return [{ t: "move", to: action }];
|
|
151
|
+
}
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Annotation navigation, deletion, and submit: one path for plan and diff. */
|
|
156
|
+
function annotationCluster(state: KeyState, action: string | undefined): Intent[] | null {
|
|
157
|
+
if (action === "next_annotation" || action === "prev_annotation") {
|
|
158
|
+
if (!state.annotationCount) return status("no annotations");
|
|
159
|
+
return [{ t: action === "next_annotation" ? "nextAnn" : "prevAnn" }];
|
|
160
|
+
}
|
|
161
|
+
if (action === "delete_annotation") {
|
|
162
|
+
if (state.resolved || !state.hasFocusedAnnotation) return [];
|
|
163
|
+
return [{ t: "removeAnnotation" }];
|
|
164
|
+
}
|
|
165
|
+
if (action === "submit") return state.resolved ? [] : [{ t: "openSubmit" }];
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The review-session controller (#70): every daemon round-trip and mutation
|
|
3
|
+
* verb behind one React-free object. It owns connect/autostart/subscribe,
|
|
4
|
+
* the session/inbox/status/error snapshot, optimistic apply, the mutation
|
|
5
|
+
* verbs (cut/edit/annotate/submit/...), and the post-submit completion
|
|
6
|
+
* lifecycle including the notes-vault export and the herdr return-focus.
|
|
7
|
+
* App subscribes to snapshots and keeps only view state.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { DaemonClient } from "@cueloop/daemon/client";
|
|
11
|
+
import {
|
|
12
|
+
cutBlock,
|
|
13
|
+
makeAnchor,
|
|
14
|
+
newAnnotationId,
|
|
15
|
+
restoreBlock,
|
|
16
|
+
restoreLine,
|
|
17
|
+
type ReviewSession,
|
|
18
|
+
type VerdictKind,
|
|
19
|
+
} from "@cueloop/schema";
|
|
20
|
+
import { Registry, type Exporter } from "@cueloop/extension-api";
|
|
21
|
+
import { createObsidianExtension, shouldExport, type ObsidianConfig } from "@cueloop/integration-obsidian";
|
|
22
|
+
import { buildDisplay, nextWorkBlock, type DisplayBlock } from "./view";
|
|
23
|
+
import { diffRowAnchor, diffRows, type DiffRow } from "./view-diff";
|
|
24
|
+
import { editInEditor } from "./editor";
|
|
25
|
+
import { focusHerdrPane, returnPaneFor } from "./herdr";
|
|
26
|
+
import { persistAutoClose, type AutoClose, type CueloopConfig } from "./config";
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Post-submit lifecycle (a review pane should hand you back to the agent,
|
|
30
|
+
* not linger): idle → prompt (auto-close off: offer the choice) or
|
|
31
|
+
* counting (configured delay) → exit. esc dismisses to the resolved view.
|
|
32
|
+
*/
|
|
33
|
+
export type Completion =
|
|
34
|
+
| { phase: "idle" }
|
|
35
|
+
| { phase: "prompt" }
|
|
36
|
+
| { phase: "counting"; remaining: number }
|
|
37
|
+
| { phase: "dismissed" };
|
|
38
|
+
|
|
39
|
+
export interface ControllerSnapshot {
|
|
40
|
+
session: ReviewSession | null;
|
|
41
|
+
inbox: ReviewSession[] | null;
|
|
42
|
+
status: string;
|
|
43
|
+
error: string | null;
|
|
44
|
+
completion: Completion;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ReviewControllerOptions {
|
|
48
|
+
home?: string;
|
|
49
|
+
sessionId?: string;
|
|
50
|
+
/** Observer mode: stored for the key reducer's read-only gate. */
|
|
51
|
+
readOnly?: boolean;
|
|
52
|
+
onExit?: (code: number) => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ReviewController {
|
|
56
|
+
readonly readOnly: boolean;
|
|
57
|
+
/** Snapshot listeners (stable identity - safe for useSyncExternalStore). */
|
|
58
|
+
subscribe(listener: () => void): () => void;
|
|
59
|
+
getSnapshot(): ControllerSnapshot;
|
|
60
|
+
/** Dial the daemon (autostart), subscribe to events, fetch session or inbox. */
|
|
61
|
+
connect(): void;
|
|
62
|
+
close(): void;
|
|
63
|
+
/** Loaded config parts the controller acts on: auto-close and exporters. */
|
|
64
|
+
applyConfig(cfg: CueloopConfig): void;
|
|
65
|
+
setStatus(msg: string): void;
|
|
66
|
+
/** Derived projections, cached per session identity. */
|
|
67
|
+
display(): DisplayBlock[];
|
|
68
|
+
rows(): DiffRow[];
|
|
69
|
+
working(): string;
|
|
70
|
+
/** Open a session from the inbox. */
|
|
71
|
+
open(id: string): void;
|
|
72
|
+
/** Cut the block under the cursor, or restore a cut one. */
|
|
73
|
+
cut(dispIdx: number): void;
|
|
74
|
+
/** The $EDITOR hand-off on the working copy. */
|
|
75
|
+
edit(): void;
|
|
76
|
+
/** Anchor and store an annotation; both plan and diff anchor constructions. */
|
|
77
|
+
annotate(kind: "comment" | "suggestion", dispIdx: number, start: number, end: number, body: string): void;
|
|
78
|
+
removeAnnotation(id: string): void;
|
|
79
|
+
setWorkingCopy(content: string | undefined): void;
|
|
80
|
+
/** Resolve the review, run the export, start the completion hand-back. */
|
|
81
|
+
submit(verdict: VerdictKind, summary: string): void;
|
|
82
|
+
/** Close the review and, inside herdr, bounce focus back to the agent. */
|
|
83
|
+
finishReview(): void;
|
|
84
|
+
dismissCompletion(): void;
|
|
85
|
+
/** From the completion prompt: persist auto-close and start the countdown. */
|
|
86
|
+
optInAutoClose(): void;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function createReviewController(opts: ReviewControllerOptions): ReviewController {
|
|
90
|
+
return new Controller(opts);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
class Controller implements ReviewController {
|
|
94
|
+
readonly readOnly: boolean;
|
|
95
|
+
private client: DaemonClient | null = null;
|
|
96
|
+
private closed = false;
|
|
97
|
+
private snap: ControllerSnapshot = {
|
|
98
|
+
session: null,
|
|
99
|
+
inbox: null,
|
|
100
|
+
status: "",
|
|
101
|
+
error: null,
|
|
102
|
+
completion: { phase: "idle" },
|
|
103
|
+
};
|
|
104
|
+
private listeners = new Set<() => void>();
|
|
105
|
+
private autoClose: AutoClose = "off";
|
|
106
|
+
private obsidian: ObsidianConfig | null = null;
|
|
107
|
+
private exporters = new Map<string, Exporter>();
|
|
108
|
+
private countdown: ReturnType<typeof setTimeout> | undefined;
|
|
109
|
+
/** Projections keyed by session identity so renders reuse one computation. */
|
|
110
|
+
private derivedFor: ReviewSession | null = null;
|
|
111
|
+
private derived: { display: DisplayBlock[]; rows: DiffRow[] } = { display: [], rows: [] };
|
|
112
|
+
|
|
113
|
+
constructor(private readonly opts: ReviewControllerOptions) {
|
|
114
|
+
this.readOnly = opts.readOnly ?? false;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
subscribe = (listener: () => void): (() => void) => {
|
|
118
|
+
this.listeners.add(listener);
|
|
119
|
+
return () => this.listeners.delete(listener);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
getSnapshot = (): ControllerSnapshot => this.snap;
|
|
123
|
+
|
|
124
|
+
private update(patch: Partial<ControllerSnapshot>): void {
|
|
125
|
+
this.snap = { ...this.snap, ...patch };
|
|
126
|
+
for (const l of this.listeners) l();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
connect(): void {
|
|
130
|
+
void (async () => {
|
|
131
|
+
try {
|
|
132
|
+
const client = await DaemonClient.connect({ home: this.opts.home, autostart: true });
|
|
133
|
+
if (this.closed) return void client.close();
|
|
134
|
+
this.client = client;
|
|
135
|
+
client.onEvent((e) => {
|
|
136
|
+
// another controller/observer changed state: re-fetch
|
|
137
|
+
const s = this.snap.session;
|
|
138
|
+
if (s && e.sessionId === s.id) void this.refreshSession(s.id);
|
|
139
|
+
if (!this.opts.sessionId) void this.refreshInbox();
|
|
140
|
+
});
|
|
141
|
+
await client.subscribe();
|
|
142
|
+
if (this.opts.sessionId) {
|
|
143
|
+
this.update({ session: await client.sessionGet(this.opts.sessionId) });
|
|
144
|
+
} else {
|
|
145
|
+
this.update({ inbox: await client.sessionList({ status: "pending" }) });
|
|
146
|
+
}
|
|
147
|
+
} catch (err) {
|
|
148
|
+
this.update({ error: err instanceof Error ? err.message : String(err) });
|
|
149
|
+
}
|
|
150
|
+
})();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
close(): void {
|
|
154
|
+
this.closed = true;
|
|
155
|
+
clearTimeout(this.countdown);
|
|
156
|
+
this.client?.close();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
applyConfig(cfg: CueloopConfig): void {
|
|
160
|
+
this.autoClose = cfg.ui.autoClose;
|
|
161
|
+
this.obsidian = cfg.integrations.obsidian;
|
|
162
|
+
// bundled integrations register through the public extension API
|
|
163
|
+
const registry = new Registry();
|
|
164
|
+
void registry.load("obsidian", createObsidianExtension(cfg.integrations.obsidian)).then((rec) => {
|
|
165
|
+
this.exporters = rec.exporters;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
setStatus(msg: string): void {
|
|
170
|
+
this.update({ status: msg });
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ── derived projections ─────────────────────
|
|
174
|
+
private ensureDerived(): void {
|
|
175
|
+
const s = this.snap.session;
|
|
176
|
+
if (this.derivedFor === s) return;
|
|
177
|
+
this.derivedFor = s;
|
|
178
|
+
this.derived = {
|
|
179
|
+
display: s ? buildDisplay(s.artifact.content, s.workingCopy) : [],
|
|
180
|
+
rows: s && s.artifact.type === "diff" ? diffRows(s.artifact.content) : [],
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
display(): DisplayBlock[] {
|
|
185
|
+
this.ensureDerived();
|
|
186
|
+
return this.derived.display;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
rows(): DiffRow[] {
|
|
190
|
+
this.ensureDerived();
|
|
191
|
+
return this.derived.rows;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
working(): string {
|
|
195
|
+
const s = this.snap.session;
|
|
196
|
+
return s ? (s.workingCopy ?? s.artifact.content) : "";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
private async refreshSession(id: string): Promise<void> {
|
|
200
|
+
if (this.client) this.update({ session: await this.client.sessionGet(id) });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private async refreshInbox(): Promise<void> {
|
|
204
|
+
if (this.client) this.update({ inbox: await this.client.sessionList({ status: "pending" }) });
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Optimistic apply: the daemon response is the next session snapshot. */
|
|
208
|
+
private apply(p: Promise<ReviewSession>): void {
|
|
209
|
+
p.then((session) => this.update({ session })).catch((e: unknown) =>
|
|
210
|
+
this.setStatus(String(e instanceof Error ? e.message : e)),
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// ── verbs ───────────────────────────────────
|
|
215
|
+
open(id: string): void {
|
|
216
|
+
const cached = this.snap.inbox?.find((s) => s.id === id);
|
|
217
|
+
if (cached) this.update({ session: cached });
|
|
218
|
+
else void this.refreshSession(id);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
cut(dispIdx: number): void {
|
|
222
|
+
const session = this.snap.session;
|
|
223
|
+
if (!session || session.status === "resolved") return;
|
|
224
|
+
const d = this.display()[dispIdx];
|
|
225
|
+
if (!d) return;
|
|
226
|
+
const working = this.working();
|
|
227
|
+
if (d.type === "del") {
|
|
228
|
+
const line = restoreLine(nextWorkBlock(this.display(), dispIdx), working.split("\n").length);
|
|
229
|
+
// restoreBlock returns undefined when the block structure round-trips
|
|
230
|
+
// to the submitted revision - the working copy is gone
|
|
231
|
+
const restored = restoreBlock(session.artifact.content, working, d.base!, line);
|
|
232
|
+
this.setWorkingCopy(restored);
|
|
233
|
+
this.setStatus("cut restored");
|
|
234
|
+
} else if (d.work) {
|
|
235
|
+
this.setWorkingCopy(cutBlock(working, d.work));
|
|
236
|
+
this.setStatus("block cut - it serializes into the diff");
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
edit(): void {
|
|
241
|
+
const session = this.snap.session;
|
|
242
|
+
if (!session || session.status === "resolved") return;
|
|
243
|
+
try {
|
|
244
|
+
const result = editInEditor(this.working(), "plan.md");
|
|
245
|
+
if (result.changed) {
|
|
246
|
+
this.setWorkingCopy(result.content);
|
|
247
|
+
this.setStatus("edits tracked - one diff");
|
|
248
|
+
} else this.setStatus("no changes");
|
|
249
|
+
} catch (err) {
|
|
250
|
+
this.setStatus(err instanceof Error ? err.message : String(err));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
annotate(kind: "comment" | "suggestion", dispIdx: number, start: number, end: number, body: string): void {
|
|
255
|
+
const session = this.snap.session;
|
|
256
|
+
if (!session) return;
|
|
257
|
+
let anchor;
|
|
258
|
+
if (session.artifact.type === "diff") {
|
|
259
|
+
anchor = { ...diffRowAnchor(this.rows(), dispIdx), blockIndex: dispIdx };
|
|
260
|
+
} else {
|
|
261
|
+
const display = this.display();
|
|
262
|
+
const workBlocks = display.filter((d) => d.work).map((d) => d.work!);
|
|
263
|
+
const workIdx = display.slice(0, dispIdx + 1).filter((d) => d.work).length - 1;
|
|
264
|
+
anchor = makeAnchor(workBlocks, workIdx, start, end);
|
|
265
|
+
}
|
|
266
|
+
this.apply(
|
|
267
|
+
this.client!.sessionAnnotate(session.id, {
|
|
268
|
+
id: newAnnotationId(),
|
|
269
|
+
kind,
|
|
270
|
+
anchor,
|
|
271
|
+
body,
|
|
272
|
+
}),
|
|
273
|
+
);
|
|
274
|
+
this.setStatus(kind === "suggestion" ? "suggestion added - the agent applies it" : "comment added");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
removeAnnotation(id: string): void {
|
|
278
|
+
const session = this.snap.session;
|
|
279
|
+
if (!session) return;
|
|
280
|
+
this.apply(this.client!.sessionRemoveAnnotation(session.id, id));
|
|
281
|
+
this.setStatus("annotation deleted");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
setWorkingCopy(content: string | undefined): void {
|
|
285
|
+
const session = this.snap.session;
|
|
286
|
+
if (!session) return;
|
|
287
|
+
this.apply(this.client!.sessionSetWorkingCopy(session.id, content));
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
submit(verdict: VerdictKind, summary: string): void {
|
|
291
|
+
const session = this.snap.session;
|
|
292
|
+
if (!session) return;
|
|
293
|
+
this.client!.sessionResolve(session.id, verdict, summary)
|
|
294
|
+
.then((resolved) => {
|
|
295
|
+
this.update({ session: resolved, status: `review submitted - ${verdict.replace("_", " ")}` });
|
|
296
|
+
// notes-vault export: guarded by config, default is manual (no-op)
|
|
297
|
+
const obsidian = this.obsidian;
|
|
298
|
+
const exporter = this.exporters.get("obsidian");
|
|
299
|
+
if (obsidian && exporter && shouldExport(obsidian.exportOn, verdict)) {
|
|
300
|
+
void exporter(resolved).then((r) => {
|
|
301
|
+
this.setStatus(r.success && r.path ? `exported to ${r.path}` : `export failed: ${r.error ?? "unknown"}`);
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
// hand the reviewer back to the agent: prompt or count down per config;
|
|
305
|
+
// inside herdr with a known return pane, closing is the default
|
|
306
|
+
const delay = this.autoClose;
|
|
307
|
+
const returns = returnPaneFor(resolved.artifact.meta.herdrPane) !== undefined;
|
|
308
|
+
if (delay === 0) this.finishReview();
|
|
309
|
+
else if (typeof delay === "number") this.startCounting(delay);
|
|
310
|
+
else if (returns) this.startCounting(3);
|
|
311
|
+
else this.update({ completion: { phase: "prompt" } });
|
|
312
|
+
})
|
|
313
|
+
.catch((e: unknown) => this.setStatus(String(e instanceof Error ? e.message : e)));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ── completion hand-back ────────────────────
|
|
317
|
+
private startCounting(remaining: number): void {
|
|
318
|
+
if (remaining <= 0) return this.finishReview();
|
|
319
|
+
this.update({ completion: { phase: "counting", remaining } });
|
|
320
|
+
this.countdown = setTimeout(() => this.startCounting(remaining - 1), 1000);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
finishReview(): void {
|
|
324
|
+
clearTimeout(this.countdown);
|
|
325
|
+
const pane = returnPaneFor(this.snap.session?.artifact.meta.herdrPane);
|
|
326
|
+
if (pane) focusHerdrPane(pane);
|
|
327
|
+
this.opts.onExit?.(0);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
dismissCompletion(): void {
|
|
331
|
+
clearTimeout(this.countdown);
|
|
332
|
+
this.update({ completion: { phase: "dismissed" } });
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
optInAutoClose(): void {
|
|
336
|
+
// opt in: close in 3s from now on, persisted to the user config
|
|
337
|
+
try {
|
|
338
|
+
persistAutoClose(3);
|
|
339
|
+
} catch {
|
|
340
|
+
// a read-only config dir must not block closing the review
|
|
341
|
+
}
|
|
342
|
+
this.autoClose = 3;
|
|
343
|
+
this.startCounting(3);
|
|
344
|
+
}
|
|
345
|
+
}
|
package/src/view.test.ts
CHANGED
|
@@ -2,17 +2,15 @@ import { describe, expect, test } from "bun:test";
|
|
|
2
2
|
import {
|
|
3
3
|
blockRuns,
|
|
4
4
|
buildDisplay,
|
|
5
|
-
cutBlock,
|
|
6
5
|
displayText,
|
|
7
6
|
marksByDisplay,
|
|
7
|
+
nextWorkBlock,
|
|
8
8
|
overlayMarks,
|
|
9
|
-
restoreBlock,
|
|
10
|
-
restoreLine,
|
|
11
9
|
spanKey,
|
|
12
10
|
startSpan,
|
|
13
11
|
wrapRuns,
|
|
14
12
|
} from "./view";
|
|
15
|
-
import { parseBlocks, type Annotation } from "@cueloop/schema";
|
|
13
|
+
import { cutBlock, parseBlocks, restoreBlock, restoreLine, type Annotation } from "@cueloop/schema";
|
|
16
14
|
|
|
17
15
|
const BASE = `# Plan
|
|
18
16
|
|
|
@@ -150,8 +148,10 @@ describe("cut / restore round-trip", () => {
|
|
|
150
148
|
expect(cut).not.toContain("second item");
|
|
151
149
|
const display = buildDisplay(BASE, cut);
|
|
152
150
|
const delIdx = display.findIndex((d) => d.type === "del");
|
|
153
|
-
const line = restoreLine(display, delIdx, cut.split("\n").length);
|
|
154
|
-
|
|
151
|
+
const line = restoreLine(nextWorkBlock(display, delIdx), cut.split("\n").length);
|
|
152
|
+
// undefined = the working copy round-tripped back to the submitted revision
|
|
153
|
+
const restored = restoreBlock(BASE, cut, li, line);
|
|
154
|
+
expect(restored).toBeUndefined();
|
|
155
155
|
expect(buildDisplay(BASE, restored).every((d) => d.type === "same")).toBe(true);
|
|
156
156
|
});
|
|
157
157
|
});
|
package/src/view.ts
CHANGED
|
Binary file
|