@north-light/cli 0.3.706 → 0.3.708
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/dist/api/client.d.ts +1 -2
- package/dist/api/client.js +3 -3
- package/dist/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/api/dto/human.d.ts +9 -6
- package/dist/api/dto/inbox.d.ts +2 -0
- package/dist/api/dto/review-comments.d.ts +12 -35
- package/dist/api/dto/reviews.d.ts +3 -10
- package/dist/api/routes.d.ts +0 -1
- package/dist/api/routes.js +1 -1
- package/dist/builtin-memory/05-kinds/review/companion/00-base.md +2 -2
- package/dist/builtin-memory/crouter-sdk/release-notes.md +6 -0
- package/dist/clients/attach/chrome/canvas-panels.d.ts +1 -1
- package/dist/clients/attach/chrome/canvas-panels.js +1 -1
- package/dist/clients/attach/chrome/roster.js +6 -6
- package/dist/clients/attach/chrome/status-line.js +1 -1
- package/dist/clients/attach/chrome/ticket-panel.js +1 -1
- package/dist/clients/attach/input/controller.d.ts +0 -1
- package/dist/clients/attach/input/controller.js +3 -3
- package/dist/clients/attach/input/overlay-owner.d.ts +0 -1
- package/dist/clients/attach/input/overlay-owner.js +1 -1
- package/dist/clients/attach/session/keys.d.ts +0 -2
- package/dist/clients/attach/session/keys.js +1 -1
- package/dist/clients/attach/session/surface-host.d.ts +0 -5
- package/dist/clients/attach/session/surface-host.js +1 -1
- package/dist/clients/attach/viewer.js +545 -560
- package/dist/clients/editor-roundtrip.js +3 -0
- package/dist/clients/inbox/controller.d.ts +1 -6
- package/dist/clients/inbox/controller.js +1 -1
- package/dist/clients/inbox/dto-adapt.js +1 -1
- package/dist/clients/inbox/tui/page-body.js +1 -1
- package/dist/clients/inbox/tui/render.js +2 -2
- package/dist/clients/open-browser.d.ts +2 -0
- package/dist/clients/open-browser.js +1 -0
- package/dist/clients/surfaces/host.d.ts +0 -6
- package/dist/commands/human/review.js +1 -1
- package/dist/commands/sys/context/admin/shell.js +1 -1
- package/dist/core/canvas/schema-pg/025-review-anchors.sql +19 -0
- package/dist/core/canvas/schema-version.d.ts +1 -1
- package/dist/core/canvas/schema-version.js +1 -1
- package/dist/core/human/page-markdown.js +10 -12
- package/dist/core/human/tickets.js +1 -1
- package/dist/core/human/types.d.ts +4 -6
- package/dist/core/keybindings/attach-control.d.ts +0 -3
- package/dist/core/keybindings/attach-control.js +1 -1
- package/dist/core/keybindings/catalog.d.ts +1 -1
- package/dist/core/keybindings/catalog.js +1 -1
- package/dist/core/review/anchors.d.ts +28 -0
- package/dist/core/review/anchors.js +6 -0
- package/dist/core/review/comments.d.ts +2 -2
- package/dist/core/review/comments.js +7 -8
- package/dist/core/review/companion.d.ts +2 -1
- package/dist/core/review/companion.js +1 -1
- package/dist/core/review/document.d.ts +4 -17
- package/dist/core/review/document.js +1 -2
- package/dist/core/review/fork.js +2 -4
- package/dist/core/review/project.d.ts +1 -1
- package/dist/core/review/project.js +2 -2
- package/dist/core/review/realize.js +1 -1
- package/dist/core/review/stage.d.ts +2 -9
- package/dist/core/review/stage.js +1 -1
- package/dist/core/review/types.d.ts +16 -12
- package/dist/core/review/types.js +1 -1
- package/dist/core/runtime/broker/turn-replies.d.ts +1 -3
- package/dist/core/runtime/broker-cli.js +3 -3
- package/dist/core/runtime/broker-extension-render.js +1 -1
- package/dist/core/runtime/tmux-bindings.js +3 -3
- package/dist/daemon/api/canvas-host.js +1 -1
- package/dist/daemon/api/document-page.d.ts +12 -1
- package/dist/daemon/api/document-page.js +6 -6
- package/dist/daemon/api/handlers/inbox.js +1 -1
- package/dist/daemon/api/handlers/review-comments.js +1 -1
- package/dist/daemon/api/handlers/reviews.js +1 -1
- package/dist/daemon/api/map.js +2 -2
- package/dist/daemon/api/review-page.d.ts +3 -0
- package/dist/daemon/api/review-page.js +13 -0
- package/dist/daemon/broker-memory-cap.d.ts +9 -0
- package/dist/daemon/broker-memory-cap.js +2 -0
- package/dist/daemon/broker-signals/bus.d.ts +1 -1
- package/dist/daemon/broker-signals/bus.js +1 -1
- package/dist/daemon/crtrd.js +14 -14
- package/dist/daemon/machine-daemon.js +1 -1
- package/dist/daemon/review/comment-notify.js +2 -2
- package/dist/daemon/review/deliver.d.ts +2 -2
- package/dist/daemon/review/deliver.js +6 -2
- package/dist/daemon/review/finish.js +1 -1
- package/dist/doc-editor/Geist-Variable.woff2 +0 -0
- package/dist/doc-editor/GeistMono-Variable.woff2 +0 -0
- package/dist/doc-editor/editor.css +1 -1
- package/dist/doc-editor/review.css +2 -0
- package/dist/doc-editor/review.js +149 -0
- package/dist/pi-extensions/canvas-review-boundary.js +3 -3
- package/dist/shared/turn-replies.d.ts +3 -3
- package/dist/shared/turn-replies.js +3 -3
- package/docs/sdk/release-notes.md +6 -0
- package/package.json +13 -4
- package/packages/crouter-api/dist/api/client.js +0 -3
- package/packages/crouter-api/dist/api/contract.js +1 -1
- package/packages/crouter-api/dist/api/routes.js +0 -1
- package/packages/crouter-api/dist/clients/attach/chrome/canvas-panels.js +3 -3
- package/packages/crouter-api/dist/clients/attach/chrome/roster.js +9 -20
- package/packages/crouter-api/dist/clients/attach/chrome/status-line.js +1 -6
- package/packages/crouter-api/dist/clients/attach/chrome/ticket-panel.js +1 -1
- package/packages/crouter-api/dist/clients/attach/input/controller.js +0 -3
- package/packages/crouter-api/dist/clients/attach/input/overlay-owner.js +0 -7
- package/packages/crouter-api/dist/clients/attach/session/keys.js +0 -1
- package/packages/crouter-api/dist/clients/attach/session/surface-host.js +0 -17
- package/packages/crouter-api/dist/clients/attach/viewer.js +0 -37
- package/packages/crouter-api/dist/clients/{inbox/review/roundtrip.js → editor-roundtrip.js} +1 -1
- package/packages/crouter-api/dist/clients/inbox/controller.js +12 -31
- package/packages/crouter-api/dist/clients/inbox/dto-adapt.js +1 -0
- package/packages/crouter-api/dist/clients/inbox/tui/page-body.js +0 -7
- package/packages/crouter-api/dist/clients/inbox/tui/render.js +0 -7
- package/packages/crouter-api/dist/clients/open-browser.js +6 -0
- package/packages/crouter-api/dist/commands/human/review.js +17 -18
- package/packages/crouter-api/dist/commands/sys/context/admin/shell.js +1 -1
- package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
- package/packages/crouter-api/dist/core/human/page-markdown.js +2 -6
- package/packages/crouter-api/dist/core/human/tickets.js +2 -11
- package/packages/crouter-api/dist/core/keybindings/attach-control.js +0 -1
- package/packages/crouter-api/dist/core/keybindings/catalog.js +1 -3
- package/packages/crouter-api/dist/core/review/anchors.js +91 -0
- package/packages/crouter-api/dist/core/review/comments.js +27 -46
- package/packages/crouter-api/dist/core/review/companion.js +5 -9
- package/packages/crouter-api/dist/core/review/document.js +17 -89
- package/packages/crouter-api/dist/core/review/project.js +2 -1
- package/packages/crouter-api/dist/core/review/types.js +2 -2
- package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +0 -5
- package/packages/crouter-api/dist/daemon/api/map.js +2 -6
- package/packages/crouter-api/dist/daemon/broker-signals/bus.js +1 -1
- package/packages/crouter-api/dist/daemon/review/deliver.js +4 -3
- package/packages/crouter-api/dist/daemon/review/finish.js +26 -47
- package/packages/crouter-api/dist/shared/turn-replies.js +9 -14
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +1740 -505
- package/dist/clients/attach/overlays/file-review.d.ts +0 -10
- package/dist/clients/attach/overlays/file-review.js +0 -2
- package/dist/clients/inbox/review/anchors.d.ts +0 -41
- package/dist/clients/inbox/review/anchors.js +0 -1
- package/dist/clients/inbox/review/comments-client.d.ts +0 -74
- package/dist/clients/inbox/review/comments-client.js +0 -1
- package/dist/clients/inbox/review/companion-pane.d.ts +0 -47
- package/dist/clients/inbox/review/companion-pane.js +0 -1
- package/dist/clients/inbox/review/document-surface.d.ts +0 -212
- package/dist/clients/inbox/review/document-surface.js +0 -2
- package/dist/clients/inbox/review/frame.d.ts +0 -57
- package/dist/clients/inbox/review/frame.js +0 -1
- package/dist/clients/inbox/review/keys.d.ts +0 -69
- package/dist/clients/inbox/review/keys.js +0 -1
- package/dist/clients/inbox/review/launch.d.ts +0 -16
- package/dist/clients/inbox/review/launch.js +0 -1
- package/dist/clients/inbox/review/live-source.d.ts +0 -24
- package/dist/clients/inbox/review/live-source.js +0 -1
- package/dist/clients/inbox/review/nvim.d.ts +0 -15
- package/dist/clients/inbox/review/nvim.js +0 -1
- package/dist/clients/inbox/review/remap.d.ts +0 -51
- package/dist/clients/inbox/review/remap.js +0 -1
- package/dist/clients/inbox/review/review-client.d.ts +0 -43
- package/dist/clients/inbox/review/review-client.js +0 -1
- package/dist/clients/inbox/review/roundtrip.js +0 -3
- package/dist/clients/inbox/review/state.d.ts +0 -153
- package/dist/clients/inbox/review/state.js +0 -4
- package/dist/clients/inbox/review-adapter.d.ts +0 -17
- package/dist/clients/inbox/review-adapter.js +0 -1
- package/dist/core/review/remap.d.ts +0 -24
- package/dist/core/review/remap.js +0 -19
- package/dist/core/review/signal.d.ts +0 -5
- package/dist/core/review/signal.js +0 -1
- package/packages/crouter-api/dist/clients/attach/overlays/file-review.js +0 -146
- package/packages/crouter-api/dist/clients/inbox/review/anchors.js +0 -89
- package/packages/crouter-api/dist/clients/inbox/review/comments-client.js +0 -103
- package/packages/crouter-api/dist/clients/inbox/review/companion-pane.js +0 -109
- package/packages/crouter-api/dist/clients/inbox/review/document-surface.js +0 -1268
- package/packages/crouter-api/dist/clients/inbox/review/frame.js +0 -309
- package/packages/crouter-api/dist/clients/inbox/review/keys.js +0 -133
- package/packages/crouter-api/dist/clients/inbox/review/launch.js +0 -170
- package/packages/crouter-api/dist/clients/inbox/review/live-source.js +0 -160
- package/packages/crouter-api/dist/clients/inbox/review/nvim.js +0 -43
- package/packages/crouter-api/dist/clients/inbox/review/remap.js +0 -157
- package/packages/crouter-api/dist/clients/inbox/review/review-client.js +0 -125
- package/packages/crouter-api/dist/clients/inbox/review/state.js +0 -315
- package/packages/crouter-api/dist/clients/inbox/review-adapter.js +0 -43
- package/packages/crouter-api/dist/core/review/signal.js +0 -12
- package/packages/crouter-api/dist/core/termrender/code-doc.js +0 -92
- /package/dist/clients/{inbox/review/roundtrip.d.ts → editor-roundtrip.d.ts} +0 -0
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { readFileSync, statSync, watch } from 'node:fs';
|
|
3
|
-
import { basename, dirname } from 'node:path';
|
|
4
|
-
import { documentLines } from '../../../core/document-lines.js';
|
|
5
|
-
import { checkReviewableFile } from '../../../core/human/visible-paths.js';
|
|
6
|
-
/** The trailing delay used to collapse an editor's write/rename burst. */
|
|
7
|
-
export const COALESCE_MS = 120;
|
|
8
|
-
function hashText(text) {
|
|
9
|
-
return createHash('sha256').update(text, 'utf8').digest('hex');
|
|
10
|
-
}
|
|
11
|
-
function staleReasonFromCheck(reason) {
|
|
12
|
-
if (reason.includes('UTF-8'))
|
|
13
|
-
return 'binary';
|
|
14
|
-
if (reason.includes('too large') || reason.includes('too long'))
|
|
15
|
-
return 'too-large';
|
|
16
|
-
return 'unreadable';
|
|
17
|
-
}
|
|
18
|
-
function readSource(absFile) {
|
|
19
|
-
try {
|
|
20
|
-
const stat = statSync(absFile);
|
|
21
|
-
if (!stat.isFile())
|
|
22
|
-
return { status: 'stale', reason: 'missing' };
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
return {
|
|
26
|
-
status: 'stale',
|
|
27
|
-
reason: error.code === 'ENOENT' ? 'missing' : 'unreadable',
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const check = checkReviewableFile(absFile);
|
|
31
|
-
if (!check.ok) {
|
|
32
|
-
if (check.reason === 'not a file')
|
|
33
|
-
return { status: 'stale', reason: 'unreadable' };
|
|
34
|
-
return { status: 'stale', reason: staleReasonFromCheck(check.reason) };
|
|
35
|
-
}
|
|
36
|
-
try {
|
|
37
|
-
const text = readFileSync(absFile, 'utf8');
|
|
38
|
-
return {
|
|
39
|
-
status: 'live',
|
|
40
|
-
text,
|
|
41
|
-
sha256: hashText(text),
|
|
42
|
-
loadedAt: new Date().toISOString(),
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return { status: 'stale', reason: 'unreadable' };
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function initialSnapshot(absFile) {
|
|
50
|
-
const result = readSource(absFile);
|
|
51
|
-
if (result.status === 'stale') {
|
|
52
|
-
throw new Error(`Unable to open live source ${absFile}: ${result.reason}`);
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
text: result.text,
|
|
56
|
-
lines: documentLines(result.text),
|
|
57
|
-
revision: 0,
|
|
58
|
-
status: 'live',
|
|
59
|
-
sha256: result.sha256,
|
|
60
|
-
loadedAt: result.loadedAt,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/** Watch the containing directory so atomic replacement of the file remains live. */
|
|
64
|
-
export function openLiveSource(absFile) {
|
|
65
|
-
let snapshot = initialSnapshot(absFile);
|
|
66
|
-
const openedText = snapshot.text;
|
|
67
|
-
const listeners = new Set();
|
|
68
|
-
const target = basename(absFile);
|
|
69
|
-
let watcher;
|
|
70
|
-
let timer;
|
|
71
|
-
let closed = false;
|
|
72
|
-
const refreshNow = () => {
|
|
73
|
-
if (closed)
|
|
74
|
-
return;
|
|
75
|
-
const result = readSource(absFile);
|
|
76
|
-
const previous = snapshot;
|
|
77
|
-
if (result.status === 'stale') {
|
|
78
|
-
const next = {
|
|
79
|
-
...previous,
|
|
80
|
-
status: 'stale',
|
|
81
|
-
staleReason: result.reason,
|
|
82
|
-
};
|
|
83
|
-
snapshot = next;
|
|
84
|
-
if (previous.status === next.status)
|
|
85
|
-
return;
|
|
86
|
-
for (const listener of listeners) {
|
|
87
|
-
if (!closed)
|
|
88
|
-
listener(next, previous);
|
|
89
|
-
}
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const textChanged = result.text !== previous.text;
|
|
93
|
-
const statusChanged = previous.status !== 'live';
|
|
94
|
-
const next = {
|
|
95
|
-
text: result.text,
|
|
96
|
-
lines: textChanged ? documentLines(result.text) : previous.lines,
|
|
97
|
-
revision: previous.revision + (textChanged ? 1 : 0),
|
|
98
|
-
status: 'live',
|
|
99
|
-
sha256: result.sha256,
|
|
100
|
-
loadedAt: textChanged || statusChanged ? result.loadedAt : previous.loadedAt,
|
|
101
|
-
};
|
|
102
|
-
snapshot = next;
|
|
103
|
-
if (!textChanged && !statusChanged)
|
|
104
|
-
return;
|
|
105
|
-
for (const listener of listeners) {
|
|
106
|
-
if (!closed)
|
|
107
|
-
listener(next, previous);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const scheduleRefresh = () => {
|
|
111
|
-
if (closed)
|
|
112
|
-
return;
|
|
113
|
-
if (timer !== undefined)
|
|
114
|
-
clearTimeout(timer);
|
|
115
|
-
timer = setTimeout(() => {
|
|
116
|
-
timer = undefined;
|
|
117
|
-
if (!closed)
|
|
118
|
-
refreshNow();
|
|
119
|
-
}, COALESCE_MS);
|
|
120
|
-
};
|
|
121
|
-
try {
|
|
122
|
-
watcher = watch(dirname(absFile), (_event, filename) => {
|
|
123
|
-
if (!closed && filename !== null && String(filename) === target)
|
|
124
|
-
scheduleRefresh();
|
|
125
|
-
});
|
|
126
|
-
watcher.on('error', () => {
|
|
127
|
-
// The next explicit refresh remains authoritative; a directory watcher
|
|
128
|
-
// error must not terminate the viewer process.
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
catch {
|
|
132
|
-
// A source that was readable at open remains usable through refreshNow().
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
current: () => snapshot,
|
|
136
|
-
openText: () => openedText,
|
|
137
|
-
onChange: (fn) => {
|
|
138
|
-
if (!closed)
|
|
139
|
-
listeners.add(fn);
|
|
140
|
-
},
|
|
141
|
-
refreshNow,
|
|
142
|
-
close: () => {
|
|
143
|
-
if (closed)
|
|
144
|
-
return;
|
|
145
|
-
closed = true;
|
|
146
|
-
if (timer !== undefined) {
|
|
147
|
-
clearTimeout(timer);
|
|
148
|
-
timer = undefined;
|
|
149
|
-
}
|
|
150
|
-
listeners.clear();
|
|
151
|
-
try {
|
|
152
|
-
watcher?.close();
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
// Teardown is best effort when the watcher has already failed.
|
|
156
|
-
}
|
|
157
|
-
watcher = undefined;
|
|
158
|
-
},
|
|
159
|
-
};
|
|
160
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { spawnSync } from 'node:child_process';
|
|
2
|
-
import { announceFallbackEditor, editorBasename, isViFamilyEditor, NO_EDITOR_MESSAGE, resolveEditor } from '../../../core/editor-resolver.js';
|
|
3
|
-
/**
|
|
4
|
-
* Open the reviewed file in the user's configured editor, optionally at a specific line.
|
|
5
|
-
* Resolves $VISUAL, then $EDITOR, then the first installed of nano/pico/micro/nvim/vim/vi.
|
|
6
|
-
* The configured value may be a shell fragment such as "code --wait" — it runs whole
|
|
7
|
-
* through /bin/sh, exactly like the comment-compose round-trip editor.
|
|
8
|
-
* For vi-family editors (nvim, vim, vi, view), passes the line with the +line syntax.
|
|
9
|
-
* For other editors, opens the file without line positioning.
|
|
10
|
-
*
|
|
11
|
-
* @param absFile - Absolute path to the file to edit
|
|
12
|
-
* @param line - 1-based line number (only used for vi-family editors)
|
|
13
|
-
* @returns An object with an optional `error` property if the editor launch or execution failed
|
|
14
|
-
*/
|
|
15
|
-
export function openReviewedFileInEditor(absFile, line) {
|
|
16
|
-
const resolved = resolveEditor();
|
|
17
|
-
if (resolved === null)
|
|
18
|
-
return { error: NO_EDITOR_MESSAGE };
|
|
19
|
-
const editor = resolved.command;
|
|
20
|
-
// vi-family editors take the line as +N; nano takes +N too.
|
|
21
|
-
const lineArg = isViFamilyEditor(editor) || editorBasename(editor) === 'nano' ? ` "+${line}"` : '';
|
|
22
|
-
try {
|
|
23
|
-
announceFallbackEditor(resolved);
|
|
24
|
-
const result = spawnSync('/bin/sh', ['-c', `${editor}${lineArg} "$1"`, 'sh', absFile], { stdio: 'inherit' });
|
|
25
|
-
if (result.error) {
|
|
26
|
-
return { error: `$EDITOR ("${editor}") failed to launch: ${result.error.message}` };
|
|
27
|
-
}
|
|
28
|
-
if (result.signal !== null) {
|
|
29
|
-
return { error: `$EDITOR ("${editor}") was killed by signal ${result.signal}` };
|
|
30
|
-
}
|
|
31
|
-
if (result.status === 127 || result.status === 126) {
|
|
32
|
-
return { error: `$EDITOR ("${editor}") failed to launch (shell exit ${result.status}) — check $VISUAL/$EDITOR` };
|
|
33
|
-
}
|
|
34
|
-
if (result.status !== 0) {
|
|
35
|
-
return { error: `$EDITOR ("${editor}") exited with code ${result.status}` };
|
|
36
|
-
}
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
catch (err) {
|
|
40
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
41
|
-
return { error: message };
|
|
42
|
-
}
|
|
43
|
-
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Line-based range remapping with whole-line LCS.
|
|
3
|
-
*
|
|
4
|
-
* Normalizes lines, trims common prefix/suffix, applies monotone LCS to the
|
|
5
|
-
* middle section, and builds a stable mapping from old→new line numbers.
|
|
6
|
-
* Remapped ranges become detached when no line survives, shifted when partly
|
|
7
|
-
* deleted, or kept when both endpoints are unmoved.
|
|
8
|
-
*/
|
|
9
|
-
/** Normalize a line for comparison: collapse whitespace and trim. */
|
|
10
|
-
function normalizeLine(line) {
|
|
11
|
-
return line.replace(/\s+/g, ' ').trim();
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Build a monotone line-number mapping from old→new using LCS.
|
|
15
|
-
*
|
|
16
|
-
* - Normalizes all lines using D14: `line.replace(/\s+/g, ' ').trim()`
|
|
17
|
-
* - Trims common prefix and suffix before LCS
|
|
18
|
-
* - Applies whole-line LCS to the middle section
|
|
19
|
-
* - Returns a map where `get(oldLine)` is the new line number or undefined
|
|
20
|
-
*/
|
|
21
|
-
export function buildLineMap(oldLines, newLines) {
|
|
22
|
-
// Normalize all lines once
|
|
23
|
-
const oldNorm = oldLines.map(normalizeLine);
|
|
24
|
-
const newNorm = newLines.map(normalizeLine);
|
|
25
|
-
// Find common prefix length
|
|
26
|
-
let prefixLen = 0;
|
|
27
|
-
const minPrefix = Math.min(oldNorm.length, newNorm.length);
|
|
28
|
-
while (prefixLen < minPrefix &&
|
|
29
|
-
oldNorm[prefixLen] === newNorm[prefixLen]) {
|
|
30
|
-
prefixLen++;
|
|
31
|
-
}
|
|
32
|
-
// Find common suffix length
|
|
33
|
-
let suffixLen = 0;
|
|
34
|
-
const minSuffix = Math.min(oldNorm.length - prefixLen, newNorm.length - prefixLen);
|
|
35
|
-
while (suffixLen < minSuffix &&
|
|
36
|
-
oldNorm[oldNorm.length - 1 - suffixLen] ===
|
|
37
|
-
newNorm[newNorm.length - 1 - suffixLen]) {
|
|
38
|
-
suffixLen++;
|
|
39
|
-
}
|
|
40
|
-
// Extract middle sections for LCS
|
|
41
|
-
const oldMiddleEnd = oldNorm.length - suffixLen;
|
|
42
|
-
const newMiddleEnd = newNorm.length - suffixLen;
|
|
43
|
-
const oldMiddle = oldNorm.slice(prefixLen, oldMiddleEnd);
|
|
44
|
-
const newMiddle = newNorm.slice(prefixLen, newMiddleEnd);
|
|
45
|
-
// Compute LCS on the middle section
|
|
46
|
-
const lcsMap = computeLCS(oldMiddle, newMiddle);
|
|
47
|
-
// Build the final map: prefix + lcsMap + suffix
|
|
48
|
-
const map = new Map();
|
|
49
|
-
// Common prefix: identity mapping
|
|
50
|
-
for (let i = 0; i < prefixLen; i++) {
|
|
51
|
-
map.set(i, i);
|
|
52
|
-
}
|
|
53
|
-
// Middle section from LCS
|
|
54
|
-
lcsMap.forEach((newIdx, oldIdx) => {
|
|
55
|
-
map.set(prefixLen + oldIdx, prefixLen + newIdx);
|
|
56
|
-
});
|
|
57
|
-
// Common suffix: offset identity mapping
|
|
58
|
-
for (let i = 0; i < suffixLen; i++) {
|
|
59
|
-
const oldLine = oldMiddleEnd + i;
|
|
60
|
-
const newLine = newMiddleEnd + i;
|
|
61
|
-
map.set(oldLine, newLine);
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
get(oldLine) {
|
|
65
|
-
return map.get(oldLine);
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Compute LCS (Longest Common Subsequence) as a monotone mapping of old→new indices.
|
|
71
|
-
* Uses dynamic programming to find matching lines and returns only the matching pairs.
|
|
72
|
-
*
|
|
73
|
-
* For optimal whole-line matching, we want the longest common subsequence
|
|
74
|
-
* of line indices, preserving the relative order in both sequences.
|
|
75
|
-
*/
|
|
76
|
-
function computeLCS(oldLines, newLines) {
|
|
77
|
-
const m = oldLines.length;
|
|
78
|
-
const n = newLines.length;
|
|
79
|
-
if (m === 0 || n === 0) {
|
|
80
|
-
return new Map();
|
|
81
|
-
}
|
|
82
|
-
// DP table: dp[i][j] = length of LCS for oldLines[0..i-1] and newLines[0..j-1]
|
|
83
|
-
const dp = Array(m + 1)
|
|
84
|
-
.fill(null)
|
|
85
|
-
.map(() => Array(n + 1).fill(0));
|
|
86
|
-
for (let i = 1; i <= m; i++) {
|
|
87
|
-
for (let j = 1; j <= n; j++) {
|
|
88
|
-
if (oldLines[i - 1] === newLines[j - 1]) {
|
|
89
|
-
dp[i][j] = dp[i - 1][j - 1] + 1;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// Backtrack to find the LCS and build the mapping
|
|
97
|
-
const matches = new Map();
|
|
98
|
-
let i = m;
|
|
99
|
-
let j = n;
|
|
100
|
-
while (i > 0 && j > 0) {
|
|
101
|
-
if (oldLines[i - 1] === newLines[j - 1]) {
|
|
102
|
-
// Match found
|
|
103
|
-
matches.set(i - 1, j - 1);
|
|
104
|
-
i--;
|
|
105
|
-
j--;
|
|
106
|
-
}
|
|
107
|
-
else if (dp[i - 1][j] > dp[i][j - 1]) {
|
|
108
|
-
// oldLines[i-1] was deleted
|
|
109
|
-
i--;
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
// newLines[j-1] was inserted
|
|
113
|
-
j--;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return matches;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Remap a range [line, endLine) using the built LineMap.
|
|
120
|
-
*
|
|
121
|
-
* Returns:
|
|
122
|
-
* - `kept`: both endpoints are unmoved
|
|
123
|
-
* - `shifted`: the range is partially deleted; maps to the min/max of survivors
|
|
124
|
-
* - `detached`: no lines from the range survived
|
|
125
|
-
*/
|
|
126
|
-
export function remapRange(map, range) {
|
|
127
|
-
const oldStart = range.line;
|
|
128
|
-
const oldEnd = range.endLine;
|
|
129
|
-
// Collect all surviving line numbers in the old range
|
|
130
|
-
let minNew;
|
|
131
|
-
let maxNew;
|
|
132
|
-
for (let oldLine = oldStart; oldLine < oldEnd; oldLine++) {
|
|
133
|
-
const newLine = map.get(oldLine);
|
|
134
|
-
if (newLine !== undefined) {
|
|
135
|
-
if (minNew === undefined || newLine < minNew) {
|
|
136
|
-
minNew = newLine;
|
|
137
|
-
}
|
|
138
|
-
if (maxNew === undefined || newLine > maxNew) {
|
|
139
|
-
maxNew = newLine;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (minNew === undefined) {
|
|
144
|
-
return { kind: 'detached' };
|
|
145
|
-
}
|
|
146
|
-
// Check if both endpoints were preserved in their exact positions
|
|
147
|
-
const startSurvived = map.get(oldStart);
|
|
148
|
-
const endSurvived = map.get(oldEnd - 1);
|
|
149
|
-
if (startSurvived === oldStart && endSurvived === oldEnd - 1) {
|
|
150
|
-
return { kind: 'kept', line: startSurvived, endLine: endSurvived + 1 };
|
|
151
|
-
}
|
|
152
|
-
return {
|
|
153
|
-
kind: 'shifted',
|
|
154
|
-
line: minNew,
|
|
155
|
-
endLine: maxNew + 1,
|
|
156
|
-
};
|
|
157
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { ApiError } from '../../../api/errors.js';
|
|
3
|
-
import { filesCrossByUpload, uploadNodeFile } from '../../../core/storage/node-transfer.js';
|
|
4
|
-
import { cliClient } from '../../../commands/api-client.js';
|
|
5
|
-
import { createCommentAuthority } from './comments-client.js';
|
|
6
|
-
export class ReviewTerminalError extends Error {
|
|
7
|
-
state;
|
|
8
|
-
resultPath;
|
|
9
|
-
reason;
|
|
10
|
-
constructor(state, detail) {
|
|
11
|
-
if (state === 'approved') {
|
|
12
|
-
if (detail === undefined || detail === '')
|
|
13
|
-
throw new Error('approved review omitted its canonical result path');
|
|
14
|
-
super(`review is already approved; see ${detail}`);
|
|
15
|
-
this.resultPath = detail;
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
super(detail === undefined || detail === '' ? 'review is already canceled' : `review is already canceled: ${detail}`);
|
|
19
|
-
if (detail !== undefined && detail !== '')
|
|
20
|
-
this.reason = detail;
|
|
21
|
-
}
|
|
22
|
-
this.name = 'ReviewTerminalError';
|
|
23
|
-
this.state = state;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/** The terminal's complete daemon seam for review lifecycle and comment operations. */
|
|
27
|
-
export function createReviewClient(opts = {}) {
|
|
28
|
-
const request = async (operation) => {
|
|
29
|
-
try {
|
|
30
|
-
return await operation();
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
const notice = terminalConflictNotice(error);
|
|
34
|
-
if (notice !== undefined)
|
|
35
|
-
opts.onTerminalConflict?.(notice);
|
|
36
|
-
throw error;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
return {
|
|
40
|
-
async byId(reviewId) {
|
|
41
|
-
const review = await request(() => cliClient().getReview(reviewId));
|
|
42
|
-
return await resolveReview(review, review.companion_node_id, request);
|
|
43
|
-
},
|
|
44
|
-
async createInline(p) {
|
|
45
|
-
const uploadId = 'file' in p && filesCrossByUpload() ? await uploadNodeFile(p.file) : undefined;
|
|
46
|
-
const review = await request(() => cliClient().createReview({
|
|
47
|
-
origin_kind: 'inline',
|
|
48
|
-
origin_node_id: p.originNodeId,
|
|
49
|
-
...('file' in p ? (uploadId !== undefined ? { file_upload_id: uploadId } : { file: p.file }) : { document: p.document }),
|
|
50
|
-
idempotency_key: randomUUID(),
|
|
51
|
-
}));
|
|
52
|
-
return await resolveReview(review, review.companion_node_id, request);
|
|
53
|
-
},
|
|
54
|
-
comments(reviewId) {
|
|
55
|
-
return createCommentAuthority(reviewId, request);
|
|
56
|
-
},
|
|
57
|
-
async submit(reviewId) {
|
|
58
|
-
const submitted = await request(() => cliClient().submitReview(reviewId));
|
|
59
|
-
if (submitted.outcome === 'awaiting_companion')
|
|
60
|
-
return { outcome: 'awaiting_companion' };
|
|
61
|
-
return {
|
|
62
|
-
outcome: 'approved',
|
|
63
|
-
changed: requireChanged(submitted.review),
|
|
64
|
-
resultPath: requireResultPath(submitted.review),
|
|
65
|
-
};
|
|
66
|
-
},
|
|
67
|
-
async cancel(reviewId, reason) {
|
|
68
|
-
// The recipient surface: closing a review here is a dismissal, never the
|
|
69
|
-
// requester withdrawing it.
|
|
70
|
-
await request(() => cliClient().cancelReview(reviewId, { reason, actor: 'human', disposition: 'dismissed' }));
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
async function resolveReview(review, companionNodeId, request) {
|
|
75
|
-
if (review.state !== 'open')
|
|
76
|
-
throw terminalError(review);
|
|
77
|
-
const companion = await request(() => cliClient().getNode(companionNodeId));
|
|
78
|
-
return {
|
|
79
|
-
reviewId: review.review_id,
|
|
80
|
-
companionNodeId,
|
|
81
|
-
file: review.file,
|
|
82
|
-
cwd: companion.cwd,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function terminalError(review) {
|
|
86
|
-
if (review.state !== 'approved' && review.state !== 'canceled') {
|
|
87
|
-
throw new Error(`terminal review ${review.review_id} has invalid state ${review.state}`);
|
|
88
|
-
}
|
|
89
|
-
return review.state === 'approved'
|
|
90
|
-
? new ReviewTerminalError('approved', requireResultPath(review))
|
|
91
|
-
: new ReviewTerminalError('canceled', review.cancel_reason);
|
|
92
|
-
}
|
|
93
|
-
function requireChanged(review) {
|
|
94
|
-
if (typeof review.changed !== 'boolean') {
|
|
95
|
-
throw new Error(`approved review ${review.review_id} omitted its changed disposition`);
|
|
96
|
-
}
|
|
97
|
-
return review.changed;
|
|
98
|
-
}
|
|
99
|
-
function requireResultPath(review) {
|
|
100
|
-
if (typeof review.result_path !== 'string' || review.result_path === '') {
|
|
101
|
-
throw new Error(`terminal review ${review.review_id} omitted its canonical result path`);
|
|
102
|
-
}
|
|
103
|
-
return review.result_path;
|
|
104
|
-
}
|
|
105
|
-
export function terminalRefusalNotice(error) {
|
|
106
|
-
if (error.state === 'approved')
|
|
107
|
-
return `This review was already approved. Result: ${error.resultPath ?? 'unknown'}`;
|
|
108
|
-
return error.reason === undefined || error.reason === '' ? 'This review was canceled.' : `This review was canceled: ${error.reason}`;
|
|
109
|
-
}
|
|
110
|
-
export function terminalConflictNotice(error) {
|
|
111
|
-
if (!(error instanceof ApiError) || error.status !== 409 || error.code !== 'review_terminal_conflict')
|
|
112
|
-
return undefined;
|
|
113
|
-
const review = error.details?.review;
|
|
114
|
-
if (review === undefined)
|
|
115
|
-
return undefined;
|
|
116
|
-
if (review.state === 'approved')
|
|
117
|
-
return review.result_path === undefined
|
|
118
|
-
? 'This review was already approved by someone else.'
|
|
119
|
-
: `This review was already approved by someone else. Result: ${review.result_path}`;
|
|
120
|
-
if (review.state === 'canceled')
|
|
121
|
-
return review.cancel_reason === undefined || review.cancel_reason === ''
|
|
122
|
-
? 'This review was canceled before this submission landed.'
|
|
123
|
-
: `This review was canceled before this submission landed: ${review.cancel_reason}`;
|
|
124
|
-
return undefined;
|
|
125
|
-
}
|