@north-light/cli 0.3.707 → 0.3.709

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 (278) hide show
  1. package/dist/api/client.d.ts +1 -2
  2. package/dist/api/client.js +3 -3
  3. package/dist/api/contract.d.ts +1 -1
  4. package/dist/api/contract.js +1 -1
  5. package/dist/api/dto/crons.d.ts +3 -0
  6. package/dist/api/dto/human.d.ts +9 -6
  7. package/dist/api/dto/inbox.d.ts +2 -0
  8. package/dist/api/dto/review-comments.d.ts +12 -35
  9. package/dist/api/dto/reviews.d.ts +3 -10
  10. package/dist/api/routes.d.ts +0 -1
  11. package/dist/api/routes.js +1 -1
  12. package/dist/builtin-memory/05-kinds/review/companion/00-base.md +2 -2
  13. package/dist/builtin-memory/crouter-sdk/release-notes.md +6 -0
  14. package/dist/clients/attach/chrome/canvas-panels.d.ts +1 -1
  15. package/dist/clients/attach/chrome/canvas-panels.js +1 -1
  16. package/dist/clients/attach/chrome/inbox-strip.js +1 -1
  17. package/dist/clients/attach/chrome/roster.js +6 -6
  18. package/dist/clients/attach/chrome/status-line.d.ts +1 -1
  19. package/dist/clients/attach/chrome/status-line.js +1 -1
  20. package/dist/clients/attach/chrome/ticket-panel.js +1 -1
  21. package/dist/clients/attach/input/capabilities.js +1 -1
  22. package/dist/clients/attach/input/controller.d.ts +4 -1
  23. package/dist/clients/attach/input/controller.js +3 -3
  24. package/dist/clients/attach/input/overlay-owner.d.ts +0 -1
  25. package/dist/clients/attach/input/overlay-owner.js +1 -1
  26. package/dist/clients/attach/overlays/graph.d.ts +3 -2
  27. package/dist/clients/attach/overlays/graph.js +1 -1
  28. package/dist/clients/attach/render/chat-view.d.ts +2 -0
  29. package/dist/clients/attach/render/chat-view.js +1 -1
  30. package/dist/clients/attach/render/doc-links.d.ts +1 -1
  31. package/dist/clients/attach/session/chrome-refresh.js +1 -1
  32. package/dist/clients/attach/session/connection.d.ts +10 -9
  33. package/dist/clients/attach/session/connection.js +1 -1
  34. package/dist/clients/attach/session/context.d.ts +1 -1
  35. package/dist/clients/attach/session/document-links.d.ts +1 -1
  36. package/dist/clients/attach/session/document-links.js +1 -1
  37. package/dist/clients/attach/session/identity.d.ts +2 -0
  38. package/dist/clients/attach/session/identity.js +1 -1
  39. package/dist/clients/attach/session/input-wiring.d.ts +2 -0
  40. package/dist/clients/attach/session/input-wiring.js +1 -1
  41. package/dist/clients/attach/session/keys.d.ts +2 -2
  42. package/dist/clients/attach/session/keys.js +1 -1
  43. package/dist/clients/attach/session/pane-tag.d.ts +3 -1
  44. package/dist/clients/attach/session/pane-tag.js +1 -1
  45. package/dist/clients/attach/session/reconnect.js +1 -1
  46. package/dist/clients/attach/session/surface-host.d.ts +0 -5
  47. package/dist/clients/attach/session/surface-host.js +1 -1
  48. package/dist/clients/attach/session/teardown.d.ts +2 -2
  49. package/dist/clients/attach/session/teardown.js +9 -7
  50. package/dist/clients/attach/viewer.d.ts +7 -5
  51. package/dist/clients/attach/viewer.js +571 -584
  52. package/dist/clients/editor-roundtrip.js +3 -0
  53. package/dist/clients/inbox/controller.d.ts +1 -6
  54. package/dist/clients/inbox/controller.js +1 -1
  55. package/dist/clients/inbox/dto-adapt.js +1 -1
  56. package/dist/clients/inbox/tui/page-body.js +1 -1
  57. package/dist/clients/inbox/tui/render.js +2 -2
  58. package/dist/clients/open-browser.d.ts +2 -0
  59. package/dist/clients/open-browser.js +1 -0
  60. package/dist/clients/surfaces/host.d.ts +0 -6
  61. package/dist/commands/human/review.js +1 -1
  62. package/dist/commands/node/wait.js +2 -6
  63. package/dist/commands/sys/context/admin/shell.js +1 -1
  64. package/dist/core/broker-client/client.d.ts +6 -3
  65. package/dist/core/broker-client/client.js +1 -1
  66. package/dist/core/canvas/crons.d.ts +11 -1
  67. package/dist/core/canvas/crons.js +14 -14
  68. package/dist/core/canvas/executions.js +1 -1
  69. package/dist/core/canvas/schema-pg/025-review-anchors.sql +19 -0
  70. package/dist/core/canvas/schema-pg/026-cron-deadline-body.sql +9 -0
  71. package/dist/core/canvas/schema-pg/027-cron-fires.sql +4 -0
  72. package/dist/core/canvas/schema-version.d.ts +1 -1
  73. package/dist/core/canvas/schema-version.js +1 -1
  74. package/dist/core/command.js +5 -5
  75. package/dist/core/feed/messages.d.ts +5 -0
  76. package/dist/core/feed/messages.js +5 -5
  77. package/dist/core/human/page-markdown.js +10 -12
  78. package/dist/core/human/tickets.js +1 -1
  79. package/dist/core/human/types.d.ts +4 -6
  80. package/dist/core/keybindings/attach-control.d.ts +0 -3
  81. package/dist/core/keybindings/attach-control.js +1 -1
  82. package/dist/core/keybindings/catalog.d.ts +1 -1
  83. package/dist/core/keybindings/catalog.js +1 -1
  84. package/dist/core/review/anchors.d.ts +28 -0
  85. package/dist/core/review/anchors.js +6 -0
  86. package/dist/core/review/comments.d.ts +2 -2
  87. package/dist/core/review/comments.js +7 -8
  88. package/dist/core/review/companion.d.ts +2 -1
  89. package/dist/core/review/companion.js +1 -1
  90. package/dist/core/review/document.d.ts +4 -17
  91. package/dist/core/review/document.js +1 -2
  92. package/dist/core/review/fork.js +2 -4
  93. package/dist/core/review/project.d.ts +1 -1
  94. package/dist/core/review/project.js +2 -2
  95. package/dist/core/review/realize.js +1 -1
  96. package/dist/core/review/stage.d.ts +2 -9
  97. package/dist/core/review/stage.js +1 -1
  98. package/dist/core/review/types.d.ts +16 -12
  99. package/dist/core/review/types.js +1 -1
  100. package/dist/core/runtime/bearings.js +4 -4
  101. package/dist/core/runtime/boot-root.js +4 -4
  102. package/dist/core/runtime/broker-cli.js +3 -3
  103. package/dist/core/runtime/broker-extension-render.js +1 -1
  104. package/dist/core/runtime/lifecycle.js +2 -2
  105. package/dist/core/runtime/revive.js +2 -2
  106. package/dist/core/runtime/runner/blaxel/client.d.ts +4 -0
  107. package/dist/core/runtime/runner/blaxel/client.js +1 -1
  108. package/dist/core/runtime/runner/blaxel/runner.d.ts +2 -3
  109. package/dist/core/runtime/runner/blaxel/runner.js +3 -3
  110. package/dist/core/runtime/runner/delete-sandboxes.d.ts +5 -0
  111. package/dist/core/runtime/runner/delete-sandboxes.js +6 -1
  112. package/dist/core/runtime/runner/types.d.ts +19 -3
  113. package/dist/core/runtime/tmux-bindings.js +3 -3
  114. package/dist/daemon/api/bridge.d.ts +5 -0
  115. package/dist/daemon/api/bridge.js +3 -3
  116. package/dist/daemon/api/canvas-host.js +1 -1
  117. package/dist/daemon/api/document-page.d.ts +12 -1
  118. package/dist/daemon/api/document-page.js +6 -6
  119. package/dist/daemon/api/handlers/crons.d.ts +2 -0
  120. package/dist/daemon/api/handlers/crons.js +1 -1
  121. package/dist/daemon/api/handlers/inbox.js +1 -1
  122. package/dist/daemon/api/handlers/nodes.js +1 -1
  123. package/dist/daemon/api/handlers/review-comments.js +1 -1
  124. package/dist/daemon/api/handlers/reviews.js +1 -1
  125. package/dist/daemon/api/map.js +2 -2
  126. package/dist/daemon/api/operations.js +1 -1
  127. package/dist/daemon/api/review-page.d.ts +3 -0
  128. package/dist/daemon/api/review-page.js +13 -0
  129. package/dist/daemon/broker-memory-cap.d.ts +9 -0
  130. package/dist/daemon/broker-memory-cap.js +2 -0
  131. package/dist/daemon/broker-signals/bus.d.ts +1 -1
  132. package/dist/daemon/broker-signals/bus.js +1 -1
  133. package/dist/daemon/cron/ended.d.ts +3 -0
  134. package/dist/daemon/cron/ended.js +2 -2
  135. package/dist/daemon/cron/lease-recovery.js +1 -1
  136. package/dist/daemon/cron/machine-fire.d.ts +9 -2
  137. package/dist/daemon/cron/machine-fire.js +1 -1
  138. package/dist/daemon/cron/passes.js +1 -1
  139. package/dist/daemon/cron-run.js +2 -2
  140. package/dist/daemon/crtrd.js +14 -14
  141. package/dist/daemon/machine-daemon.js +1 -1
  142. package/dist/daemon/machine-link/client.js +1 -1
  143. package/dist/daemon/reconcilers/fault-retry-backstop.js +1 -1
  144. package/dist/daemon/reconcilers/idle-sandbox.d.ts +1 -1
  145. package/dist/daemon/reconcilers/idle-sandbox.js +2 -2
  146. package/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +2 -2
  147. package/dist/daemon/review/comment-notify.js +2 -2
  148. package/dist/daemon/review/deliver.d.ts +2 -2
  149. package/dist/daemon/review/deliver.js +6 -2
  150. package/dist/daemon/review/finish.js +1 -1
  151. package/dist/doc-editor/Geist-Variable.woff2 +0 -0
  152. package/dist/doc-editor/GeistMono-Variable.woff2 +0 -0
  153. package/dist/doc-editor/editor.css +1 -1
  154. package/dist/doc-editor/review.css +2 -0
  155. package/dist/doc-editor/review.js +149 -0
  156. package/dist/pi-extensions/canvas-review-boundary.js +3 -3
  157. package/docs/sdk/release-notes.md +6 -0
  158. package/package.json +13 -4
  159. package/packages/crouter-api/dist/api/client.js +0 -3
  160. package/packages/crouter-api/dist/api/contract.js +1 -1
  161. package/packages/crouter-api/dist/api/routes.js +0 -1
  162. package/packages/crouter-api/dist/clients/attach/chrome/canvas-panels.js +3 -3
  163. package/packages/crouter-api/dist/clients/attach/chrome/inbox-strip.js +5 -5
  164. package/packages/crouter-api/dist/clients/attach/chrome/roster.js +17 -28
  165. package/packages/crouter-api/dist/clients/attach/chrome/status-line.js +2 -7
  166. package/packages/crouter-api/dist/clients/attach/chrome/ticket-panel.js +1 -1
  167. package/packages/crouter-api/dist/clients/attach/input/capabilities.js +2 -1
  168. package/packages/crouter-api/dist/clients/attach/input/controller.js +17 -3
  169. package/packages/crouter-api/dist/clients/attach/input/overlay-owner.js +0 -7
  170. package/packages/crouter-api/dist/clients/attach/overlays/graph.js +4 -3
  171. package/packages/crouter-api/dist/clients/attach/render/chat-view.js +9 -0
  172. package/packages/crouter-api/dist/clients/attach/session/chrome-refresh.js +6 -3
  173. package/packages/crouter-api/dist/clients/attach/session/connection.js +53 -53
  174. package/packages/crouter-api/dist/clients/attach/session/document-links.js +1 -1
  175. package/packages/crouter-api/dist/clients/attach/session/identity.js +1 -0
  176. package/packages/crouter-api/dist/clients/attach/session/input-wiring.js +4 -3
  177. package/packages/crouter-api/dist/clients/attach/session/keys.js +11 -5
  178. package/packages/crouter-api/dist/clients/attach/session/pane-tag.js +7 -1
  179. package/packages/crouter-api/dist/clients/attach/session/reconnect.js +3 -3
  180. package/packages/crouter-api/dist/clients/attach/session/surface-host.js +0 -17
  181. package/packages/crouter-api/dist/clients/attach/session/teardown.js +7 -4
  182. package/packages/crouter-api/dist/clients/attach/viewer.js +77 -67
  183. package/packages/crouter-api/dist/clients/{inbox/review/roundtrip.js → editor-roundtrip.js} +1 -1
  184. package/packages/crouter-api/dist/clients/inbox/controller.js +12 -31
  185. package/packages/crouter-api/dist/clients/inbox/dto-adapt.js +1 -0
  186. package/packages/crouter-api/dist/clients/inbox/tui/page-body.js +0 -7
  187. package/packages/crouter-api/dist/clients/inbox/tui/render.js +0 -7
  188. package/packages/crouter-api/dist/clients/open-browser.js +6 -0
  189. package/packages/crouter-api/dist/commands/human/review.js +17 -18
  190. package/packages/crouter-api/dist/commands/node/wait.js +2 -10
  191. package/packages/crouter-api/dist/commands/sys/context/admin/shell.js +1 -1
  192. package/packages/crouter-api/dist/core/broker-client/client.js +20 -10
  193. package/packages/crouter-api/dist/core/canvas/crons.js +26 -10
  194. package/packages/crouter-api/dist/core/canvas/executions.js +7 -2
  195. package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
  196. package/packages/crouter-api/dist/core/command.js +3 -0
  197. package/packages/crouter-api/dist/core/feed/messages.js +15 -0
  198. package/packages/crouter-api/dist/core/human/page-markdown.js +2 -6
  199. package/packages/crouter-api/dist/core/human/tickets.js +2 -11
  200. package/packages/crouter-api/dist/core/keybindings/attach-control.js +0 -1
  201. package/packages/crouter-api/dist/core/keybindings/catalog.js +1 -3
  202. package/packages/crouter-api/dist/core/review/anchors.js +91 -0
  203. package/packages/crouter-api/dist/core/review/comments.js +27 -46
  204. package/packages/crouter-api/dist/core/review/companion.js +5 -9
  205. package/packages/crouter-api/dist/core/review/document.js +17 -89
  206. package/packages/crouter-api/dist/core/review/project.js +2 -1
  207. package/packages/crouter-api/dist/core/review/types.js +2 -2
  208. package/packages/crouter-api/dist/core/runtime/bearings.js +2 -2
  209. package/packages/crouter-api/dist/core/runtime/lifecycle.js +3 -0
  210. package/packages/crouter-api/dist/core/runtime/revive.js +5 -25
  211. package/packages/crouter-api/dist/core/runtime/runner/blaxel/client.js +15 -8
  212. package/packages/crouter-api/dist/core/runtime/runner/blaxel/runner.js +60 -19
  213. package/packages/crouter-api/dist/core/runtime/runner/delete-sandboxes.js +18 -2
  214. package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +0 -5
  215. package/packages/crouter-api/dist/daemon/api/map.js +2 -6
  216. package/packages/crouter-api/dist/daemon/api/operations.js +2 -2
  217. package/packages/crouter-api/dist/daemon/broker-signals/bus.js +1 -1
  218. package/packages/crouter-api/dist/daemon/cron/ended.js +22 -11
  219. package/packages/crouter-api/dist/daemon/cron/machine-fire.js +69 -6
  220. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +2 -2
  221. package/packages/crouter-api/dist/daemon/review/deliver.js +4 -3
  222. package/packages/crouter-api/dist/daemon/review/finish.js +26 -47
  223. package/packages/crouter-api/package.json +1 -1
  224. package/packages/crouter-identity/package.json +1 -1
  225. package/packages/crouter-plugin/package.json +3 -3
  226. package/runtime.lock.json +1740 -505
  227. package/dist/clients/attach/overlays/file-review.d.ts +0 -10
  228. package/dist/clients/attach/overlays/file-review.js +0 -2
  229. package/dist/clients/inbox/review/anchors.d.ts +0 -41
  230. package/dist/clients/inbox/review/anchors.js +0 -1
  231. package/dist/clients/inbox/review/comments-client.d.ts +0 -74
  232. package/dist/clients/inbox/review/comments-client.js +0 -1
  233. package/dist/clients/inbox/review/companion-pane.d.ts +0 -47
  234. package/dist/clients/inbox/review/companion-pane.js +0 -1
  235. package/dist/clients/inbox/review/document-surface.d.ts +0 -212
  236. package/dist/clients/inbox/review/document-surface.js +0 -2
  237. package/dist/clients/inbox/review/frame.d.ts +0 -57
  238. package/dist/clients/inbox/review/frame.js +0 -1
  239. package/dist/clients/inbox/review/keys.d.ts +0 -69
  240. package/dist/clients/inbox/review/keys.js +0 -1
  241. package/dist/clients/inbox/review/launch.d.ts +0 -16
  242. package/dist/clients/inbox/review/launch.js +0 -1
  243. package/dist/clients/inbox/review/live-source.d.ts +0 -24
  244. package/dist/clients/inbox/review/live-source.js +0 -1
  245. package/dist/clients/inbox/review/nvim.d.ts +0 -15
  246. package/dist/clients/inbox/review/nvim.js +0 -1
  247. package/dist/clients/inbox/review/remap.d.ts +0 -51
  248. package/dist/clients/inbox/review/remap.js +0 -1
  249. package/dist/clients/inbox/review/review-client.d.ts +0 -43
  250. package/dist/clients/inbox/review/review-client.js +0 -1
  251. package/dist/clients/inbox/review/roundtrip.js +0 -3
  252. package/dist/clients/inbox/review/state.d.ts +0 -153
  253. package/dist/clients/inbox/review/state.js +0 -4
  254. package/dist/clients/inbox/review-adapter.d.ts +0 -17
  255. package/dist/clients/inbox/review-adapter.js +0 -1
  256. package/dist/core/review/remap.d.ts +0 -24
  257. package/dist/core/review/remap.js +0 -19
  258. package/dist/core/review/signal.d.ts +0 -5
  259. package/dist/core/review/signal.js +0 -1
  260. package/dist/core/runtime/starting-screen.d.ts +0 -12
  261. package/dist/core/runtime/starting-screen.js +0 -9
  262. package/packages/crouter-api/dist/clients/attach/overlays/file-review.js +0 -146
  263. package/packages/crouter-api/dist/clients/inbox/review/anchors.js +0 -89
  264. package/packages/crouter-api/dist/clients/inbox/review/comments-client.js +0 -103
  265. package/packages/crouter-api/dist/clients/inbox/review/companion-pane.js +0 -109
  266. package/packages/crouter-api/dist/clients/inbox/review/document-surface.js +0 -1268
  267. package/packages/crouter-api/dist/clients/inbox/review/frame.js +0 -309
  268. package/packages/crouter-api/dist/clients/inbox/review/keys.js +0 -133
  269. package/packages/crouter-api/dist/clients/inbox/review/launch.js +0 -170
  270. package/packages/crouter-api/dist/clients/inbox/review/live-source.js +0 -160
  271. package/packages/crouter-api/dist/clients/inbox/review/nvim.js +0 -43
  272. package/packages/crouter-api/dist/clients/inbox/review/remap.js +0 -157
  273. package/packages/crouter-api/dist/clients/inbox/review/review-client.js +0 -125
  274. package/packages/crouter-api/dist/clients/inbox/review/state.js +0 -315
  275. package/packages/crouter-api/dist/clients/inbox/review-adapter.js +0 -43
  276. package/packages/crouter-api/dist/core/review/signal.js +0 -12
  277. package/packages/crouter-api/dist/core/termrender/code-doc.js +0 -92
  278. /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
- }