@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
@@ -6,15 +6,16 @@
6
6
  // command again. A scheduled fire whose machine has no live link at its due time is not claimed at all and stays due. A fire that was
7
7
  // claimed stays owed under its run id across an outage of any length: it is sent again until the machine answers, and a control plane
8
8
  // that crashed after claiming picks the same run id up from the cron row (`resumeMachineFire`) instead of calling the run crashed.
9
- import { randomUUID } from 'node:crypto';
9
+ import { createHash, randomUUID } from 'node:crypto';
10
+ import { join } from 'node:path';
10
11
  import { setTimeout as delay } from 'node:timers/promises';
11
12
  import { openDb } from '../../core/canvas/db.js';
12
13
  import { isCloudRole } from '../../core/canvas/person.js';
13
14
  import { withCanvasWrite } from '../../core/canvas/db.js';
14
15
  import { getNode } from '../../core/canvas/canvas.js';
16
+ import { runnerForEnvironment } from '../../core/runtime/runner/index.js';
15
17
  import { callMachine } from '../../core/runtime/runner/machine/call.js';
16
18
  import { machineEnvironmentOfNode } from '../../core/runtime/runner/machine/runner.js';
17
- import { machineEnvironmentOfProfile } from '../../core/runtime/runner/machine/environment.js';
18
19
  import { MachineCallFailedError, MachineLostError, MachineOfflineError } from '../../core/runtime/runner/machine/ops.js';
19
20
  import { environmentSecrets } from '../../core/secrets/environment-secrets.js';
20
21
  import { profileInApp } from '../../core/secrets/environment-owner.js';
@@ -22,18 +23,20 @@ import { getCron } from '../../core/canvas/crons.js';
22
23
  import { emitEvent } from '../../core/events/emit.js';
23
24
  import { runTokenFor } from './run-token.js';
24
25
  import { parseArmedEnv } from './armed-context.js';
25
- import { CRON_OUTPUT_HEAD_BYTES } from './capture.js';
26
+ import { CRON_OUTPUT_HEAD_BYTES, formatCronOutputHead } from './capture.js';
26
27
  import { settleClosedRun, settleUnspawnedRun } from './closed.js';
27
28
  import { clearLiveRun, registerLiveRun } from './live-runs.js';
28
29
  import { advanceRecurrence } from './recurrence.js';
29
30
  /** Seconds past the run's timeout a send waits for its answer. */
30
31
  const ANSWER_SLACK_S = 15;
31
32
  const RESEND_EVERY_MS = 2_000;
32
- /** The machine environment a cron runs on, or null when it runs here (a Mac's own daemon, a cron with no profile, a Blaxel profile). */
33
- export async function machineEnvironmentOfCron(c) {
33
+ /** Where a cron runs off this process: its profile's machine or Blaxel environment on a cloud role, or null when it runs here (a Mac's own
34
+ * daemon, a local runtime, a cron with no profile). */
35
+ export async function cronEnvironment(c) {
34
36
  if (!isCloudRole() || c.profile == null)
35
37
  return null;
36
- return await machineEnvironmentOfProfile(c.profile);
38
+ const row = await (await openDb()).prepare('SELECT e.object AS id, e.kind AS kind FROM profiles p JOIN environments e ON e.object = p.environment_id WHERE p.id = ?').get(c.profile);
39
+ return row ?? null;
37
40
  }
38
41
  export async function machineLinkLive(environmentId) {
39
42
  return (await (await openDb()).prepare('SELECT 1 AS live FROM machine_links WHERE environment = ? AND lease_expires_at > ?').get(environmentId, new Date().toISOString())) !== undefined;
@@ -175,3 +178,63 @@ async function driveFire(c, fire, prepared, admit) {
175
178
  clearLiveRun(c.cron_id, runId);
176
179
  }
177
180
  }
181
+ /** Where a hosted node's files sit inside its sandbox: `CRTR_HOME` and the `apps/<app>/{home,nodes/<id>/context}` layout of scripts/sandbox-start.mjs. */
182
+ const SANDBOX_CRTR_HOME = '/var/lib/crtr';
183
+ /** Fire `c` in its anchor node's sandbox through the Blaxel runner and settle the run. The same run id names the sandbox process, so a
184
+ * control plane that recovers the run (`resume`) reads the first start instead of running the command again. */
185
+ export async function fireInSandbox(c, fire, admit, resume = false) {
186
+ const { runId, outOfBand, startedAtIso, startedAtMs } = fire;
187
+ let env;
188
+ let runner;
189
+ try {
190
+ runner = runnerForEnvironment('blaxel');
191
+ if (runner.cronRun === undefined || runner.cronCancel === undefined)
192
+ throw new Error('the registered Blaxel runner cannot run crons');
193
+ const apiUrl = process.env['CRTR_PUBLIC_API_URL'];
194
+ if (!apiUrl)
195
+ throw new Error('CRTR_PUBLIC_API_URL is not set, so a sandbox cron could not reach the API');
196
+ if (c.anchor_node == null)
197
+ throw new Error('a hosted cron runs in its anchor node\'s sandbox, and this cron has no anchor node');
198
+ if (c.isolated)
199
+ throw new Error('an isolated cron needs a root launcher, which a sandbox does not have');
200
+ const prepared = await prepareRun(c, runId);
201
+ const anchor = prepared.contextAnchor;
202
+ env = { ...prepared.env, CRTR_API_URL: apiUrl, HOME: join(SANDBOX_CRTR_HOME, 'apps', c.grantee.replace(/^app:/, ''), 'home'),
203
+ ...(anchor !== null ? { CRTR_CONTEXT_DIR: join(SANDBOX_CRTR_HOME, 'apps', anchor.grantee.replace(/^app:/, ''), 'nodes', anchor.node, 'context') } : {}) };
204
+ // A recovered run's slot may already have moved past this start; advancing again is a no-op then.
205
+ if (!outOfBand && c.recur != null && (!resume || Date.parse(c.fire_at) <= startedAtMs)) {
206
+ const recurrenceError = await advanceRecurrence(c, startedAtMs);
207
+ if (recurrenceError !== null)
208
+ throw recurrenceError;
209
+ }
210
+ }
211
+ catch (err) {
212
+ return await settleUnspawnedRun(c, fire, 'run could not be armed', err);
213
+ }
214
+ const anchorNode = c.anchor_node;
215
+ const live = { runId, replaced: false, selfCanceled: false, kill: () => {
216
+ void runner.cronCancel(anchorNode, runId).catch((error) => {
217
+ emitEvent({ level: 'error', event: 'cron.sandbox.cancel_failed', error, fields: { cron_id: c.cron_id, run_id: runId } });
218
+ });
219
+ } };
220
+ registerLiveRun(c.cron_id, live);
221
+ admit();
222
+ try {
223
+ let result;
224
+ try {
225
+ result = await runner.cronRun(anchorNode, { runId, command: c.command, cwd: c.cwd, env, timeoutS: c.run_timeout_s, startedAtMs });
226
+ }
227
+ catch (err) {
228
+ return await settleUnspawnedRun(c, fire, 'run failed in the sandbox', err);
229
+ }
230
+ const head = (text) => text.length > CRON_OUTPUT_HEAD_BYTES ? formatCronOutputHead(text.slice(0, CRON_OUTPUT_HEAD_BYTES), true) : text;
231
+ return await settleClosedRun(c, {
232
+ runId, outOfBand, startedAtIso, startedAtMs, finishedAtMs: Date.now(), code: result.exitCode, timedOut: result.timedOut, processError: result.error === undefined ? null : new Error(result.error),
233
+ stdoutHead: head(result.stdout), stderrHead: head(result.stderr), stdoutSha256: createHash('sha256').update(result.stdout).digest('hex'),
234
+ wasReplaced: live.replaced, wasSelfCanceled: live.selfCanceled,
235
+ });
236
+ }
237
+ finally {
238
+ clearLiveRun(c.cron_id, runId);
239
+ }
240
+ }
@@ -150,8 +150,8 @@ export async function recoverLaunching(nodeId, now) {
150
150
  await publishNotice(nodeId, 'notice.crash', wake, { reason: 'child-crashed', child: nodeId });
151
151
  }
152
152
  }
153
- // The failed attempt's sandbox is of no further use (a retry creates its own), so it goes last, once the verdict is recorded.
154
- await runner.deleteExecution?.(execution);
153
+ // The failed launch's sandbox is not reused: the next start creates the node's sandbox afresh. It goes last, once the verdict is recorded.
154
+ await runner.delete(execution.nodeId);
155
155
  return true;
156
156
  }
157
157
  // gone: the next wake is attempt + 1, and the lane does not count it as a respawn failure.
@@ -1,13 +1,14 @@
1
1
  /** Render the immutable approval fact as plain prose. It is delivered as an
2
2
  * inbox entry, so the inbox card is its envelope — a nested `<runtime>` card
3
3
  * here would reach the model escaped and the attached view as raw markup. */
4
- export function renderApprovalMessage(review, resultPath) {
4
+ export function renderApprovalMessage(review, resultPath, comments = []) {
5
5
  const summary = review.document_name !== null
6
6
  ? review.changed
7
- ? `The user reviewed and approved \`${review.document_name}\`. Their edits are saved as a new revision; re-read it with \`crtr canvas read ${review.document_name}\` before continuing. Review conversation: node \`${review.companion_node_id}\`.`
7
+ ? `The user reviewed and approved \`${review.document_name}\`. Their edits are saved in the document; re-read it with \`crtr canvas read ${review.document_name}\` before continuing. Review conversation: node \`${review.companion_node_id}\`.`
8
8
  : `The user reviewed and approved \`${review.document_name}\`. The document was not modified.`
9
9
  : review.changed
10
10
  ? `The user reviewed and approved \`${review.file}\`. The document changed during review; re-read it before continuing. Review conversation: node \`${review.companion_node_id}\`.`
11
11
  : `The user reviewed and approved \`${review.file}\`. The document was not modified.`;
12
- return `${summary}\n\nDurable review result: ${resultPath}`;
12
+ const notes = comments.length === 0 ? '' : `\n\nComments:\n${comments.map((c) => `- ${c.resolved ? '[resolved] ' : ''}"${c.quote}"${c.detached === true ? ' (text no longer in the document)' : ''}: ${c.comment}`).join('\n')}`;
13
+ return `${summary}${notes}\n\nDurable review result: ${resultPath}`;
13
14
  }
@@ -1,13 +1,11 @@
1
1
  import { withCanvasWrite } from '../../core/canvas/db.js';
2
- import { get as getBody } from '../../core/graph/bodies.js';
3
- import { documentById, editDocument, heads } from '../../core/graph/documents.js';
4
- import { readerFor } from '../../core/graph/reader.js';
2
+ import { createHash } from 'node:crypto';
3
+ import { documentById, heads } from '../../core/graph/documents.js';
5
4
  import { warmDocumentWatchers } from '../api/reader.js';
6
- import { checkoutsForCwd } from '../../core/graph/repo-sync/repos.js';
7
- import { snapshotCommentsLocked } from '../../core/review/comments.js';
8
- import { readReviewSource } from '../../core/review/document.js';
5
+ import { signalReviewChange, snapshotCommentsLocked } from '../../core/review/comments.js';
6
+ import { currentReviewText } from '../../core/review/document.js';
7
+ import { renderedText, resolveAnchor } from '../../core/review/anchors.js';
9
8
  import { projectReviewCancellation, projectReviewResult, buildReviewResult } from '../../core/review/project.js';
10
- import { signalReviewActivity } from '../../core/review/signal.js';
11
9
  import { clearReviewSubmit, getReview, getReviewByCompanion, requestReviewSubmit, requireVisibleReview } from '../../core/review/store.js';
12
10
  import { ReviewOperationError } from '../../core/review/types.js';
13
11
  import { settleHumanRequest } from '../human/settle.js';
@@ -32,11 +30,11 @@ function effects(result) {
32
30
  }
33
31
  /** A runtime notice, not the person's words: `human-answer` would make attached
34
32
  * views render this body as a message the person typed. */
35
- function approvalNotification(review) {
33
+ function approvalNotification(review, result) {
36
34
  return {
37
35
  label: 'review approved by the user',
38
36
  disposition: null,
39
- body_json: { review_id: review.review_id, result_path: resultPath(review), body: renderApprovalMessage(review, resultPath(review)) },
37
+ body_json: { review_id: review.review_id, result_path: resultPath(review), body: renderApprovalMessage(review, resultPath(review), result.comments) },
40
38
  };
41
39
  }
42
40
  function cancellationNotification(review, reason, disposition) {
@@ -47,39 +45,11 @@ function cancellationNotification(review, reason, disposition) {
47
45
  body_json: { review_id: review.review_id, disposition, body: dismissed ? `The review of \`${review.document_name ?? review.file}\` was dismissed without approval.` : `The review of \`${review.document_name ?? review.file}\` was canceled${reason === '' ? '' : ` — ${reason}`}.` },
48
46
  };
49
47
  }
50
- /**
51
- * A document review's edits become a new revision, authored by the person, made from the heads
52
- * the review was snapshotted from. The document moving meanwhile refuses the save as
53
- * `stale_revision`; the same text already at the single head (a concurrent submit of this
54
- * review won) counts as saved.
55
- */
56
- async function saveReviewedDocument(db, review, text) {
57
- if (review.document_id === null || review.document_base === null)
58
- return;
59
- const reposFn = async (cwd, person) => await checkoutsForCwd(db, cwd, person);
60
- const doc = await documentById(db, review.document_id);
61
- const reader = await readerFor(db, { class: 'person' }, reposFn);
62
- const saved = await editDocument(db, reader, doc, { body: text }, `edited in review ${review.review_id}`, review.document_base, {}, reposFn);
63
- if (!('stale' in saved))
64
- return;
65
- const current = await heads(db, doc);
66
- if (current.length === 1 && await getBody(db, current[0].body_hash) === text)
67
- return;
68
- throw new ReviewOperationError('stale_revision', `${review.document_name ?? doc.name} changed since the review began; the reviewed text was not saved`, {
69
- review_id: review.review_id,
70
- document: review.document_name ?? doc.name,
71
- base: review.document_base,
72
- heads_key: saved.stale.heads_key,
73
- revision: saved.stale.revision,
74
- next: `Read the current revision with \`crtr canvas read ${doc.id}\`, then start a new review of it.`,
75
- });
76
- }
77
48
  async function approveReview(initial) {
78
49
  if (initial.state === 'canceled')
79
50
  return terminalConflict(initial, 'submit');
80
51
  if (initial.state === 'approved')
81
52
  return { outcome: 'already_settled', record: initial, result: approvedResult(initial) };
82
- const source = await readReviewSource(initial.file, 'submit');
83
53
  if (initial.document_id !== null)
84
54
  await warmDocumentWatchers(initial.document_id); // git lookups before the write opens
85
55
  const { result, resultJson } = await withCanvasWrite(async (db) => {
@@ -88,33 +58,43 @@ async function approveReview(initial) {
88
58
  return terminalConflict(review, 'submit');
89
59
  if (review.state === 'approved')
90
60
  return { result: approvedResult(review), resultJson: review.result_json };
61
+ const text = await currentReviewText(db, review);
62
+ const approvedSha256 = createHash('sha256').update(text).digest('hex');
91
63
  const snapshot = await snapshotCommentsLocked(db, review.review_id);
92
- const result = buildReviewResult(review, snapshot, source.sha256, now());
93
- if (result.changed)
94
- await saveReviewedDocument(db, review, new TextDecoder('utf-8').decode(source.bytes));
64
+ const quotes = renderedText(text);
65
+ for (const comment of snapshot.comments)
66
+ comment.detached = resolveAnchor(quotes, { quote: comment.quote, prefix: '', suffix: '', offset: 0 }) === null;
67
+ let document = null;
68
+ if (review.document_id !== null) {
69
+ const doc = await documentById(db, review.document_id);
70
+ document = { id: doc.id, name: review.document_name ?? doc.name, base_revision: review.document_base, approved_revision: (await heads(db, doc)).map((h) => h.rev_id).sort().join(',') };
71
+ }
72
+ const result = buildReviewResult(review, snapshot, approvedSha256, now(), document);
95
73
  return { result, resultJson: JSON.stringify(result) };
96
74
  });
97
75
  const settled = await settleHumanRequest({
98
76
  request_id: initial.review_id,
99
77
  outcome: 'approved',
100
78
  result_json: resultJson,
101
- notification: approvalNotification({ ...initial, changed: result.changed }),
79
+ notification: approvalNotification({ ...initial, changed: result.changed }, result),
102
80
  post_commit: effects(result),
103
81
  });
104
82
  if (settled.outcome === 'settled')
105
- signalReviewActivity();
83
+ await signalReview(initial.review_id);
106
84
  const record = await requireVisibleReview(initial.review_id);
107
85
  if (settled.outcome === 'already_settled' && record.state !== 'approved')
108
86
  return terminalConflict(record, 'submit');
109
87
  return { outcome: settled.outcome, record, result: settled.outcome === 'settled' ? result : approvedResult(record) };
110
88
  }
89
+ /** Announce a review change committed by the settle or store step just before. */
90
+ const signalReview = (reviewId) => withCanvasWrite((db) => signalReviewChange(db, reviewId));
111
91
  export async function submitReviewApproval(reviewId) {
112
92
  const review = await requireVisibleReview(reviewId);
113
93
  if (review.state === 'canceled')
114
94
  return terminalConflict(review, 'submit');
115
95
  if (review.state === 'open' && await companionStillWorking(review.companion_node_id)) {
116
96
  if (await requestReviewSubmit(reviewId, now()))
117
- signalReviewActivity();
97
+ await signalReview(reviewId);
118
98
  return { outcome: 'awaiting_companion', record: await requireVisibleReview(reviewId) };
119
99
  }
120
100
  return approveReview(review);
@@ -131,10 +111,9 @@ export async function completeRequestedSubmit(reviewId, opts) {
131
111
  return await approveReview(review);
132
112
  }
133
113
  catch (error) {
134
- // A refused save leaves the review open with no submit pending, rather than retried every tick.
135
- if (error instanceof ReviewOperationError && error.code === 'stale_revision') {
114
+ if (error instanceof ReviewOperationError && error.code === 'source_unreadable') {
136
115
  await clearReviewSubmit(reviewId);
137
- signalReviewActivity();
116
+ await signalReview(reviewId);
138
117
  }
139
118
  throw error;
140
119
  }
@@ -162,7 +141,7 @@ export async function cancelReview(reviewId, args = {}) {
162
141
  },
163
142
  });
164
143
  if (settled.outcome === 'settled')
165
- signalReviewActivity();
144
+ await signalReview(reviewId);
166
145
  const record = await requireVisibleReview(reviewId);
167
146
  if (settled.outcome === 'already_settled' && record.state === 'approved')
168
147
  return terminalConflict(record, 'cancel');
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.707",
3
+ "version": "0.3.709",
4
4
  "description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/api/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/identity",
3
- "version": "0.3.707",
3
+ "version": "0.3.709",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/plugin",
3
- "version": "0.3.707",
3
+ "version": "0.3.709",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
28
28
  },
29
29
  "dependencies": {
30
- "@north-light/api": "0.3.707",
31
- "@north-light/identity": "0.3.707"
30
+ "@north-light/api": "0.3.709",
31
+ "@north-light/identity": "0.3.709"
32
32
  },
33
33
  "license": "UNLICENSED",
34
34
  "publishConfig": {