@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
@@ -2,7 +2,9 @@ import { createHash } from 'node:crypto';
2
2
  import { statSync } from 'node:fs';
3
3
  import { isBlobRequestPath, readRequestFileIfPresent } from '../human/request-files.js';
4
4
  import { documentLines } from '../document-lines.js';
5
- import { COMMENT_QUOTE_MAX, ReviewOperationError, } from './types.js';
5
+ import { ReviewOperationError } from './types.js';
6
+ import { get as getBody } from '../graph/bodies.js';
7
+ import { documentById, heads } from '../graph/documents.js';
6
8
  const REVIEW_SOURCE_MAX_BYTES = 2 * 1024 * 1024;
7
9
  function sourceUnreadable(file, phase, reason) {
8
10
  throw new ReviewOperationError('source_unreadable', 'review source is unreadable', { phase, reason, file });
@@ -49,95 +51,21 @@ export async function readReviewSource(file, phase = 'submit') {
49
51
  lines: documentLines(text),
50
52
  };
51
53
  }
52
- async function requireDocumentSource(review, expected_doc_hash) {
53
- const source = await readReviewSource(review.file, 'comment');
54
- if (source.sha256 !== expected_doc_hash) {
55
- throw new ReviewOperationError('stale_document', 'review document changed since it was rendered', {
56
- reason: 'document_changed',
57
- expected_sha256: expected_doc_hash,
58
- actual_sha256: source.sha256,
59
- });
54
+ /** The review's live text: a document review reads the document's current head, a file review its snapshot. */
55
+ export async function currentReviewText(db, review) {
56
+ if (review.document_id !== null) {
57
+ const head = (await heads(db, await documentById(db, review.document_id)))[0];
58
+ const body = head === undefined ? null : await getBody(db, head.body_hash);
59
+ if (body === null)
60
+ throw new ReviewOperationError('source_unreadable', 'review document has no body', { phase: 'comment', reason: 'missing', file: review.file });
61
+ return body;
60
62
  }
61
- if (source.sha256 !== review.anchor_base_sha256) {
62
- throw new ReviewOperationError('stale_document', 'review comment ranges have not been remapped to the current document', {
63
- reason: 'anchor_base_stale',
64
- expected_sha256: review.anchor_base_sha256,
65
- actual_sha256: source.sha256,
66
- });
67
- }
68
- return source;
69
- }
70
- /** Require both the caller's rendered source and the persisted range coordinate base to be current. */
71
- export async function requireCurrentDocument(review, expected_doc_hash) {
72
- return requireDocumentSource(review, expected_doc_hash);
63
+ return new TextDecoder().decode((await readReviewSource(review.file, 'comment')).bytes);
73
64
  }
74
- /** Verify a create-time source precondition from the review row held by the caller's canvas write transaction. */
75
- export async function requireCurrentDocumentLocked(db, review_id, expected_doc_hash) {
76
- const review = await db.prepare("SELECT file, anchor_base_sha256 FROM human_requests WHERE request_id = ? AND kind = 'review' AND state = 'open'").get(review_id);
77
- if (review === undefined) {
65
+ /** Same as {@link currentReviewText}, for the review row held by the caller's canvas write transaction. */
66
+ export async function currentReviewTextLocked(db, review_id) {
67
+ const review = await db.prepare("SELECT file, document_id FROM human_requests WHERE request_id = ? AND kind = 'review' AND state = 'open'").get(review_id);
68
+ if (review === undefined)
78
69
  throw new ReviewOperationError('unknown_review', 'review was not found', { received: review_id });
79
- }
80
- return requireDocumentSource(review, expected_doc_hash);
81
- }
82
- /** Reject malformed ranges rather than normalizing them into a different anchor. */
83
- export function validateAnchorShape(anchor) {
84
- const violations = [];
85
- const hasStart = anchor.col_start !== undefined;
86
- const hasEnd = anchor.col_end !== undefined;
87
- if (!Number.isSafeInteger(anchor.line) || anchor.line < 1)
88
- violations.push('line must be a positive integer');
89
- if (!Number.isSafeInteger(anchor.end_line) || anchor.end_line < 1)
90
- violations.push('end_line must be a positive integer');
91
- if (Number.isSafeInteger(anchor.line) && Number.isSafeInteger(anchor.end_line) && anchor.end_line < anchor.line) {
92
- violations.push('end_line must be greater than or equal to line');
93
- }
94
- if (hasStart !== hasEnd)
95
- violations.push('col_start and col_end must be provided together');
96
- if (hasStart && (!Number.isSafeInteger(anchor.col_start) || anchor.col_start < 0))
97
- violations.push('col_start must be a non-negative integer');
98
- if (hasEnd && (!Number.isSafeInteger(anchor.col_end) || anchor.col_end < 0))
99
- violations.push('col_end must be a non-negative integer');
100
- if (hasStart
101
- && hasEnd
102
- && anchor.line === anchor.end_line
103
- && Number.isSafeInteger(anchor.col_start)
104
- && Number.isSafeInteger(anchor.col_end)
105
- && anchor.col_end <= anchor.col_start) {
106
- violations.push('col_end must be greater than col_start for a single-line anchor');
107
- }
108
- if (anchor.quote !== undefined && typeof anchor.quote !== 'string')
109
- violations.push('quote must be a string');
110
- if (typeof anchor.quote === 'string' && Buffer.byteLength(anchor.quote, 'utf8') > COMMENT_QUOTE_MAX) {
111
- violations.push(`quote exceeds ${COMMENT_QUOTE_MAX} bytes`);
112
- }
113
- if (violations.length > 0) {
114
- throw new ReviewOperationError('invalid_anchor', 'comment anchor is invalid', { violations });
115
- }
116
- }
117
- function isUtf8Boundary(bytes, offset) {
118
- return offset === bytes.length || (bytes[offset] & 0xc0) !== 0x80;
119
- }
120
- /** Capture the full source range used to render an anchor, without silently clamping it. */
121
- export function captureAnchorText(lines, anchor) {
122
- validateAnchorShape(anchor);
123
- if (anchor.line > lines.length || anchor.end_line > lines.length) {
124
- throw new ReviewOperationError('anchor_out_of_range', 'comment anchor exceeds the reviewed document', {
125
- line_count: lines.length,
126
- requested: { line: anchor.line, end_line: anchor.end_line },
127
- });
128
- }
129
- if (anchor.col_start !== undefined && anchor.col_end !== undefined) {
130
- const startLine = Buffer.from(lines[anchor.line - 1], 'utf8');
131
- const endLine = Buffer.from(lines[anchor.end_line - 1], 'utf8');
132
- if (anchor.col_start > startLine.length
133
- || anchor.col_end > endLine.length
134
- || !isUtf8Boundary(startLine, anchor.col_start)
135
- || !isUtf8Boundary(endLine, anchor.col_end)) {
136
- throw new ReviewOperationError('anchor_out_of_range', 'comment anchor columns exceed the reviewed document', {
137
- line_count: lines.length,
138
- requested: { line: anchor.line, end_line: anchor.end_line },
139
- });
140
- }
141
- }
142
- return lines.slice(anchor.line - 1, anchor.end_line).join('\n');
70
+ return currentReviewText(db, review);
143
71
  }
@@ -2,10 +2,11 @@ import { atomicWriteJson } from '../human/convention.js';
2
2
  import { isCloudRole } from '../canvas/person.js';
3
3
  import { writeRequestFile } from '../human/request-files.js';
4
4
  /** Build the immutable approval result from the review row and one comment snapshot. */
5
- export function buildReviewResult(review, snapshot, approvedSha256, at) {
5
+ export function buildReviewResult(review, snapshot, approvedSha256, at, document) {
6
6
  return {
7
7
  schema: 'humanloop.review-response/v1',
8
8
  review_id: review.review_id,
9
+ document,
9
10
  file: review.file,
10
11
  submitted: true,
11
12
  approved: true,
@@ -5,8 +5,8 @@
5
5
  */
6
6
  /** Limits */
7
7
  export const COMMENT_TEXT_MAX = 8_000;
8
- export const COMMENT_QUOTE_MAX = 4_000;
9
- export const COMMENT_LINE_TEXT_MAX = 8_000;
8
+ export const COMMENT_QUOTE_MAX = 2_000;
9
+ export const ANCHOR_CONTEXT_MAX = 32;
10
10
  export const LIVE_COMMENTS_MAX = 500;
11
11
  export const COMMENT_EVENTS_PAGE_DEFAULT = 200;
12
12
  export const COMMENT_EVENTS_PAGE_MAX = 1_000;
@@ -10,7 +10,7 @@
10
10
  //
11
11
  // persona.ts / broker-persona-guidance.ts deliver orchestratorContextNote() when a base node
12
12
  // becomes an orchestrator after birth.
13
- import { getNode, fullName, isSafeNodeId, subscriptionsOf, } from '../canvas/index.js';
13
+ import { getNode, latestExecutionForNode, fullName, isSafeNodeId, subscriptionsOf, } from '../canvas/index.js';
14
14
  import { cadenceDisplay } from '../wake.js';
15
15
  import { renderKnowledge, renderWorkspaceOpen } from '../substrate/delivery/render-boot.js';
16
16
  import { situationalContextEnvelope } from './situational-context.js';
@@ -183,7 +183,7 @@ async function bearingsShell(nodeId, knowledge, workspaceContext) {
183
183
  // nested card inside the outer envelope. Never routed through the visible
184
184
  // chat/digest path. '' when nothing was ever set.
185
185
  const situational = await situationalContextEnvelope(nodeId) ?? '';
186
- const projectCtx = node?.cwd !== undefined ? buildProjectContextBlock(node.cwd) : '';
186
+ const projectCtx = node?.cwd !== undefined && (await latestExecutionForNode(nodeId))?.runner === 'process' ? buildProjectContextBlock(node.cwd) : ''; // reads this host
187
187
  return [bearings.join('\n'), knowledge, workspaceContext, situational, projectCtx]
188
188
  .filter((s) => s !== '')
189
189
  .join('\n');
@@ -37,6 +37,7 @@ import { join } from 'node:path';
37
37
  import { BROKER_RELEASED_MARKER, BROKER_RELAY_GENERATION, nodeRunDir } from '../canvas/paths.js';
38
38
  import { openBeneath, writeFileBeneath, isAbsentOrRefused } from '../spaces/open-beneath.js';
39
39
  import { emitEvent } from '../events/emit.js';
40
+ import { deleteSandboxOfEndedNode } from './runner/delete-sandboxes.js';
40
41
  import { composeNodeOutcomeDocument } from './outcome-document.js';
41
42
  import { afterCommit, withCanvasWrite } from '../canvas/db.js';
42
43
  import { nodeObject } from '../graph/objects.js';
@@ -224,6 +225,8 @@ export async function transition(nodeId, event, opts) {
224
225
  runStructuredRequestEffects(transitionResult.settlement.row);
225
226
  if (event === 'finish' || event === 'park' || event === 'cancel')
226
227
  await cancelCronsOnWake(nodeId);
228
+ if (event === 'finish' || event === 'cancel' || event === 'crash')
229
+ deleteSandboxOfEndedNode(nodeId);
227
230
  return await getNode(nodeId);
228
231
  }
229
232
  /** The last relay generation published when it bound. Missing means no replacement has bound yet. */
@@ -253,32 +253,12 @@ async function decideReviveAsCaller(nodeId, opts, wakeParked) {
253
253
  if (await blaxelEnvironmentOf(meta.profile_id ?? null) !== null)
254
254
  await checkBilledWake(meta);
255
255
  }
256
- if (await fleet.has(nodeId)) {
257
- // The node is already running, but the ROW may still say terminal: a reopen
258
- // or a retask lands on a live broker, and only this transition puts the row
259
- // back where its liveness already is. Both specs accept any prior status,
260
- // so this is a no-op for a row that is already active.
261
- await transition(nodeId, meta.intent === 'refresh' ? 'refresh-launch' : 'revive');
262
- return {
263
- parked: false,
264
- result: {
265
- window: null,
266
- session: meta.tmux_session ?? null,
267
- resumed: false,
268
- outcome: 'already-live',
269
- },
270
- };
271
- }
272
256
  if (await fleet.isClaimed(nodeId)) {
273
- return {
274
- parked: false,
275
- result: {
276
- window: null,
277
- session: meta.tmux_session ?? null,
278
- resumed: false,
279
- outcome: 'already-live',
280
- },
281
- };
257
+ // A running broker's ROW may still say terminal: a reopen or a retask lands on a live broker, and only this transition puts the
258
+ // row back where its liveness already is. Both specs accept any prior status, so this is a no-op for a row already active.
259
+ if (await fleet.has(nodeId))
260
+ await transition(nodeId, meta.intent === 'refresh' ? 'refresh-launch' : 'revive');
261
+ return { parked: false, result: { window: null, session: meta.tmux_session ?? null, resumed: false, outcome: 'already-live' } };
282
262
  }
283
263
  // Focus may establish a viewport without establishing an engine. This exact
284
264
  // row has no final latch and no fleet owner; returning before reservation is
@@ -31,7 +31,7 @@ function toInfo(raw) {
31
31
  const url = raw.metadata.url;
32
32
  if (!url)
33
33
  throw new Error(`Blaxel sandbox ${raw.metadata.name} has no url`);
34
- return { name: raw.metadata.name, url, state: raw.state ?? null, status: raw.status ?? null };
34
+ return { name: raw.metadata.name, url, state: raw.state ?? null, status: raw.status ?? null, image: raw.spec?.runtime?.image ?? null };
35
35
  }
36
36
  /**
37
37
  * The code and message of an error body. The sandbox gateway nests them (`{"error":{"code":"WORKLOAD_UNAVAILABLE","message":...}}`);
@@ -79,15 +79,22 @@ export function createBlaxelClient(config) {
79
79
  config,
80
80
  async createSandbox(spec) {
81
81
  const ports = [...(spec.ports ?? [])].map((p) => ({ name: p.name, target: p.target, protocol: 'HTTP' }));
82
- const body = { metadata: { name: spec.name }, spec: { runtime: { image: spec.image, memory: spec.memoryMb, ...(ports.length > 0 ? { ports } : {}) }, region: config.region } };
83
- const { status, json } = await call(`${control}/sandboxes`, 'POST', body, [409]);
84
- if (status === 409) {
82
+ const body = { metadata: { name: spec.name }, spec: { runtime: { image: spec.image, memory: spec.memoryMb, ...(ports.length > 0 ? { ports } : {}) }, region: config.region,
83
+ // For a node that never finishes and a delete that failed. A process call into the sandbox restarts the idle time.
84
+ lifecycle: { expirationPolicies: [{ type: 'ttl-idle', value: '7d', action: 'delete' }] } } };
85
+ // A name held by a sandbox still being deleted (getSandbox reads DELETING/TERMINATED as null) frees once Blaxel removes it.
86
+ const deadline = Date.now() + (config.deletingWaitMs ?? 60_000);
87
+ for (;;) {
88
+ const { status, json } = await call(`${control}/sandboxes`, 'POST', body, [409]);
89
+ if (status !== 409)
90
+ return { ...toInfo(json), created: true };
85
91
  const existing = await this.getSandbox(spec.name);
86
- if (existing === null)
87
- throw new Error(`Blaxel sandbox ${spec.name} reported as existing but cannot be read`);
88
- return { ...existing, created: false };
92
+ if (existing !== null)
93
+ return { ...existing, created: false };
94
+ if (Date.now() >= deadline)
95
+ throw new Error(`Blaxel sandbox ${spec.name} is still being deleted; its name did not free in time`);
96
+ await new Promise((resolve) => setTimeout(resolve, 1000));
89
97
  }
90
- return { ...toInfo(json), created: true };
91
98
  },
92
99
  async getSandbox(name) {
93
100
  const { status, json } = await call(`${control}/sandboxes/${encodeName(name)}`, 'GET', undefined, [404]);
@@ -1,12 +1,11 @@
1
1
  // src/core/runtime/runner/blaxel/runner.ts — the Blaxel runner (design-fleet, Components: Runner; C-A2).
2
2
  //
3
- // One sandbox per node attempt (`executions.sandbox_name`, `<node id>-<attempt>`), one process per execution
3
+ // One sandbox per node, named by the node id and reused at every start, one process per execution
4
4
  // named `broker-<execution id>`. That process runs the bootstrap, which installs the release and runs
5
5
  // `crtr-sandbox-start`; the start script stays as the broker's parent. The runner never reads the sandbox's
6
6
  // own status as the freeze signal: a frozen broker reads `running` from the process status. It reads the
7
7
  // sandbox `state` (STANDBY while frozen; reading it does not wake the sandbox) only in `sandboxState`, for
8
8
  // the freeze measurement. The process status goes through the sandbox and so wakes it: `status` of an idle execution never asks.
9
- import { openDb } from '../../../canvas/db.js';
10
9
  import { mintExecutionToken } from '../../../canvas/node-tokens.js';
11
10
  import { BlaxelApiError, isWorkloadUnavailable } from './client.js';
12
11
  /** The broker listens here inside the sandbox; the private preview forwards it (`wss://<preview>/view`). */
@@ -21,13 +20,12 @@ export const FAILURE_LINE = /^crtr-sandbox-start: failed (\S+)/m;
21
20
  /** How much of a failed process's output `status` carries: enough for the boot phase lines and the error that ended the start. */
22
21
  const FAILURE_OUTPUT_CHARS = 2000;
23
22
  export const brokerProcessName = (executionId) => `broker-${executionId}`;
24
- export const sandboxNameFor = (execution) => execution.sandboxName ?? `${execution.nodeId}-${execution.attempt}`;
25
- /** Every execution of a node that ran in a sandbox has one, named by `sandboxNameFor`: `start` creates it under that name and nothing
26
- * writes `executions.sandbox_name`, so the column is null on every row and the name is `<node id>-<attempt>`. */
27
- async function defaultSandboxNames(nodeId) {
28
- const rows = await (await openDb()).prepare("SELECT execution_id, attempt, sandbox_name FROM executions WHERE node_id = ? AND runner = 'blaxel'").all(nodeId);
29
- return [...new Set(rows.map((row) => sandboxNameFor({ executionId: row.execution_id, nodeId, attempt: Number(row.attempt), sandboxName: row.sandbox_name })))];
30
- }
23
+ export const sandboxNameFor = (nodeId) => nodeId;
24
+ export const cronProcessName = (runId) => `cron-${runId}`;
25
+ const CRON_POLL_MS = 2_000;
26
+ /** The user and release `bin` of `scripts/sandbox-bootstrap.sh` (`RUN_USER`, `$ROOT/current`). */
27
+ const RUN_USER = 'crtr';
28
+ const RELEASE_BIN = '/opt/crtr/current/bin';
31
29
  function failureOf(process) {
32
30
  const text = `${process.logs}\n${process.stderr}\n${process.stdout}`;
33
31
  const output = (process.stderr || process.logs || process.stdout || '').trim().slice(-FAILURE_OUTPUT_CHARS);
@@ -38,7 +36,7 @@ export function createBlaxelRunner(deps) {
38
36
  const stopGraceMs = (deps.stopGraceS ?? 10) * 1000;
39
37
  const previewTokens = new Map();
40
38
  async function sandboxOf(execution) {
41
- return await client.getSandbox(sandboxNameFor(execution));
39
+ return await client.getSandbox(sandboxNameFor(execution.nodeId));
42
40
  }
43
41
  /** Stops any broker of the execution still in the sandbox (SIGTERM, then SIGKILL after the grace) and reports whether none is left. */
44
42
  async function brokerGone(sandbox, executionId) {
@@ -53,9 +51,15 @@ export function createBlaxelRunner(deps) {
53
51
  kind: 'blaxel',
54
52
  async start(input) {
55
53
  const context = await deps.launchContext(input);
56
- const name = sandboxNameFor(input);
57
- // "Name taken" means a previous attempt created it: the client adopts it.
58
- const sandbox = await client.createSandbox({ name, image: context.image, memoryMb: context.memoryMb, ports: [{ name: VIEW_PREVIEW, target: BROKER_VIEW_PORT }] });
54
+ const name = sandboxNameFor(input.nodeId);
55
+ const spec = { name, image: context.image, memoryMb: context.memoryMb, ports: [{ name: VIEW_PREVIEW, target: BROKER_VIEW_PORT }] };
56
+ // "Name taken" means an earlier start created it: the client adopts it, files and all. One on an older image is replaced.
57
+ let sandbox = await client.createSandbox(spec);
58
+ if (sandbox.image !== context.image) {
59
+ await client.deleteSandbox(name);
60
+ previewTokens.delete(name);
61
+ sandbox = await client.createSandbox(spec);
62
+ }
59
63
  const process = brokerProcessName(input.executionId);
60
64
  // A repeated call (a reconciler whose lease was taken) finds the process and adopts it: no second token.
61
65
  const existing = await client.getProcess(sandbox, process);
@@ -141,14 +145,11 @@ export function createBlaxelRunner(deps) {
141
145
  }
142
146
  },
143
147
  async delete(nodeId) {
144
- for (const name of await (deps.sandboxNamesForNode ?? defaultSandboxNames)(nodeId))
145
- await client.deleteSandbox(name);
146
- },
147
- async deleteExecution(execution) {
148
- await client.deleteSandbox(sandboxNameFor(execution));
148
+ await client.deleteSandbox(sandboxNameFor(nodeId));
149
+ previewTokens.delete(sandboxNameFor(nodeId));
149
150
  },
150
151
  async viewerAddress(execution) {
151
- const name = sandboxNameFor(execution);
152
+ const name = sandboxNameFor(execution.nodeId);
152
153
  const cached = previewTokens.get(name);
153
154
  if (cached && cached.expiresAt - Date.now() > 5 * 60_000)
154
155
  return viewer(cached.url, cached.token);
@@ -158,6 +159,46 @@ export function createBlaxelRunner(deps) {
158
159
  previewTokens.set(name, { url, token, expiresAt: expires.getTime() });
159
160
  return viewer(url, token);
160
161
  },
162
+ async cronRun(nodeId, run) {
163
+ const sandbox = await client.getSandbox(sandboxNameFor(nodeId));
164
+ if (sandbox === null)
165
+ throw new Error(`node ${nodeId} has no sandbox, so the cron cannot run; the scheduler never starts a node to get one`);
166
+ const name = cronProcessName(run.runId);
167
+ // A sandbox process runs as root; the command runs as the node's user, as the broker does (sandbox-bootstrap.sh), with the release's `crtr` on PATH.
168
+ const command = `exec nsenter -S "$(id -u ${RUN_USER})" -G "$(id -g ${RUN_USER})" bash -c "$CRTR_CRON_COMMAND"`;
169
+ const env = { ...run.env, CRTR_CRON_COMMAND: run.command, PATH: `${RELEASE_BIN}:/usr/local/bin:/usr/bin:/bin` };
170
+ // The process name fences the run id: a resend or a recovering control plane reads the first start instead of running the command again.
171
+ let process = await client.getProcess(sandbox, name)
172
+ ?? await client.startProcess(sandbox, { name, command, workingDir: run.cwd, env, waitForCompletion: false });
173
+ // Counted from the fire's start, so a recovered run does not get a fresh timeout.
174
+ const deadline = run.startedAtMs + run.timeoutS * 1000;
175
+ while (process.status === 'running') {
176
+ if (Date.now() >= deadline) {
177
+ await client.killProcess(sandbox, name);
178
+ return { exitCode: null, timedOut: true, stdout: process.stdout, stderr: process.stderr };
179
+ }
180
+ await new Promise((resolve) => setTimeout(resolve, CRON_POLL_MS));
181
+ // A failed read (a 5xx, a dropped connection) is retried until the deadline: the process is still running in the sandbox.
182
+ let read;
183
+ try {
184
+ read = await client.getProcess(sandbox, name);
185
+ }
186
+ catch {
187
+ continue;
188
+ }
189
+ if (read === null)
190
+ return { exitCode: null, timedOut: false, stdout: process.stdout, stderr: process.stderr, error: `process ${name} is gone from the sandbox, so its outcome is unknown` };
191
+ process = read;
192
+ }
193
+ if (process.status === 'completed' || process.status === 'failed')
194
+ return { exitCode: process.exitCode, timedOut: false, stdout: process.stdout, stderr: process.stderr };
195
+ return { exitCode: null, timedOut: false, stdout: process.stdout, stderr: process.stderr, error: `process ${name} was ${process.status} from outside the run` };
196
+ },
197
+ async cronCancel(nodeId, runId) {
198
+ const sandbox = await client.getSandbox(sandboxNameFor(nodeId));
199
+ if (sandbox !== null)
200
+ await client.killProcess(sandbox, cronProcessName(runId));
201
+ },
161
202
  /** The sandbox `state` (`STANDBY` while frozen), read without waking it. Null when the sandbox is gone. Measurement only. */
162
203
  async sandboxState(execution) {
163
204
  return (await sandboxOf(execution))?.state ?? null;
@@ -1,7 +1,7 @@
1
- // A node's sandboxes go before its rows do. The executions rows are what name them (`<node id>-<attempt>`) and they cascade away with
1
+ // A node's sandboxes go before its rows do. The executions rows are what show a node ran in one and they cascade away with
2
2
  // the node, so a node row deleted first leaves a running, billed sandbox that nothing can find again (design-fleet, Runner: `delete(node)`
3
3
  // on the Blaxel runner deletes the sandbox). Every path that deletes node rows calls this first.
4
- import { openDb } from '../../canvas/db.js';
4
+ import { afterCommit, openDb, withCanvasWrite } from '../../canvas/db.js';
5
5
  import { emitEvent } from '../../events/emit.js';
6
6
  /** Delete the sandboxes of the nodes that ran in one. Returns the ids whose sandboxes could not all be deleted: the caller keeps
7
7
  * those nodes' rows, which are what the next removal sweep or retention pass finds them by. A repeat is harmless. */
@@ -22,3 +22,19 @@ export async function deleteNodeSandboxes(nodeIds) {
22
22
  }
23
23
  return failed;
24
24
  }
25
+ /** A node that finished, was canceled or died keeps its sandbox only while a broker still runs in it or a standing cron is anchored to it
26
+ * (its fires run there). Called after each of those ends; a failure is left to the sandbox's idle expiry. A parked node is not ended:
27
+ * wake mail reopens it in the same sandbox. The check and the DELETE run holding the node row's lock, which `beginExecution` also
28
+ * takes, so no new execution can start in the sandbox between them. */
29
+ export function deleteSandboxOfEndedNode(nodeId) {
30
+ afterCommit(() => void withCanvasWrite(async (db) => {
31
+ const ended = await db.prepare(`SELECT 1 AS ended FROM nodes n WHERE n.node_id = ?
32
+ AND EXISTS (SELECT 1 FROM executions x WHERE x.node_id = n.node_id AND x.runner = 'blaxel')
33
+ AND (n.status IN ('canceled', 'dead') OR (n.status = 'done' AND n.intent IS DISTINCT FROM 'parked'))
34
+ AND NOT EXISTS (SELECT 1 FROM executions x WHERE x.node_id = n.node_id AND x.state != 'exited')
35
+ AND NOT EXISTS (SELECT 1 FROM crons c WHERE c.anchor_node = n.node_id AND c.cancel_on_wake = 0)
36
+ FOR UPDATE OF n`).get(nodeId);
37
+ if (ended !== undefined)
38
+ await (await import('./index.js')).runnerForExecution('blaxel').delete(nodeId);
39
+ }).catch((error) => { emitEvent({ level: 'error', event: 'canvas.node_sandbox.delete_failed', node_id: nodeId, error }); }));
40
+ }
@@ -26,10 +26,6 @@ const LEAF_MENU_ACTIONS = {
26
26
  'crtr.tmux.menu.detach': { description: 'demote + close viewer', action: { kind: 'direct', run: 'node lifecycle demote --pane {pane} --detach' } },
27
27
  'crtr.tmux.menu.close-subtree': { description: 'close agent + subtree', action: { kind: 'direct', run: 'node lifecycle close --pane {pane}' } },
28
28
  'crtr.tmux.menu.background-bash': { description: 'background running bash', action: { kind: 'direct', run: 'node bash background --pane {pane}' } },
29
- // M-S-r, not M-R: with extended-keys csi-u tmux encodes M-R as alt+uppercase-R
30
- // WITHOUT the shift modifier bit, which pi-tui's `alt+shift+r` matcher rejects;
31
- // M-S-r carries shift+alt and lands as the same chord the keyboard produces.
32
- 'crtr.tmux.menu.file-review': { description: 'review a file', action: { kind: 'raw-keys', keys: 'M-S-r' } },
33
29
  'crtr.tmux.menu.metadata': { description: 'metadata', action: { kind: 'keys', keys: '/node-metadata' } },
34
30
  'crtr.tmux.menu.more-detail': { description: 'more detail', action: { kind: 'keys', keys: '/more-detail' } },
35
31
  'crtr.tmux.menu.less-detail': { description: 'less detail', action: { kind: 'keys', keys: '/less-detail' } },
@@ -300,7 +296,6 @@ function menuItems(bindings, entries) {
300
296
  addGroup('Current node', boundItems([
301
297
  'crtr.tmux.menu.attach',
302
298
  'crtr.tmux.menu.background-bash',
303
- 'crtr.tmux.menu.file-review',
304
299
  'crtr.tmux.menu.pin',
305
300
  'crtr.tmux.menu.copy-id',
306
301
  'crtr.tmux.menu.reload-viewer',
@@ -497,9 +497,6 @@ export function toReviewCommentDTO(comment) {
497
497
  revision: comment.revision,
498
498
  text: comment.text,
499
499
  anchor: { ...comment.anchor },
500
- anchor_state: comment.anchor_state,
501
- anchor_line_text: comment.anchor_line_text,
502
- anchor_doc_hash: comment.anchor_doc_hash,
503
500
  author: {
504
501
  kind: comment.author.kind,
505
502
  ...(comment.author.node_id === null ? {} : { node_id: comment.author.node_id }),
@@ -556,6 +553,7 @@ export function toReviewCommentEventDTO(event) {
556
553
  /** Project the immutable snake_case review result to the existing camelCase feedback wire shape. */
557
554
  export function toFeedbackResultDTO(result) {
558
555
  const dto = {
556
+ document: result.document,
559
557
  file: result.file,
560
558
  submitted: result.submitted,
561
559
  approved: result.approved,
@@ -596,12 +594,10 @@ export const REVIEW_ERROR_MAP = Object.freeze({
596
594
  unknown_comment: { status: 404, code: 'unknown_comment' },
597
595
  comment_deleted: { status: 409, code: 'comment_deleted' },
598
596
  invalid_anchor: { status: 400, code: 'invalid_anchor' },
599
- anchor_out_of_range: { status: 400, code: 'anchor_out_of_range' },
597
+ quote_not_found: { status: 409, code: 'quote_not_found' },
600
598
  text_too_long: { status: 400, code: 'text_too_long' },
601
599
  comment_limit_reached: { status: 409, code: 'comment_limit_reached' },
602
600
  stale_comment: { status: 409, code: 'stale_comment' },
603
- range_batch_incomplete: { status: 409, code: 'range_batch_incomplete' },
604
- range_batch_stale: { status: 409, code: 'range_batch_stale' },
605
601
  });
606
602
  /** The single error-mapping function (spec §8). Projects any thrown value into
607
603
  * `{ status, code }`:
@@ -154,7 +154,7 @@ export const OPERATIONS = [
154
154
  { name: 'model_auth.cancel', method: 'POST', path: '/v1/model-auth/flows/:flow_id/cancel', classes: ['person', 'broker'], resource: 'none' },
155
155
  { name: 'model_auth.get', method: 'GET', path: '/v1/model-auth/flows/:flow_id', classes: ['person', 'broker'], resource: 'none' },
156
156
  { name: 'nodes.post.85', method: 'POST', path: '/v1/nodes', classes: ['person', 'broker', 'cron'], resource: 'node-own', scope: 'crtr:act' },
157
- { name: 'nodes.get.86', method: 'GET', path: '/v1/nodes', classes: ['person', 'broker'], resource: 'nodes-list' },
157
+ { name: 'nodes.get.86', method: 'GET', path: '/v1/nodes', classes: ['person', 'broker', 'cron'], resource: 'nodes-list' },
158
158
  { name: 'nodes.post.87', method: 'POST', path: '/v1/nodes/revive-all', classes: ['person', 'broker'], resource: 'none' },
159
159
  { name: 'nodes.get.88', method: 'GET', path: '/v1/nodes/:id', classes: ['person', 'broker', 'cron', 'forwarded'], resource: 'node-read' },
160
160
  { name: 'nodes.get.89', method: 'GET', path: '/v1/nodes/:id/snapshot', classes: ['person', 'broker', 'cron'], resource: 'node-read' },
@@ -193,7 +193,7 @@ export const OPERATIONS = [
193
193
  { name: 'profile.env.list', method: 'GET', path: '/v1/profiles/:name/env', classes: ['person', 'app', 'broker'], resource: 'profile' },
194
194
  { name: 'profile.env.set', method: 'PUT', path: '/v1/profiles/:name/env/:var', classes: ['person', 'app', 'broker'], resource: 'profile' },
195
195
  { name: 'profile.env.remove', method: 'DELETE', path: '/v1/profiles/:name/env/:var', classes: ['person', 'app', 'broker'], resource: 'profile' },
196
- { name: 'profile.environment.get', method: 'GET', path: '/v1/profiles/:name/environment', classes: ['person', 'broker'], resource: 'profile' },
196
+ { name: 'profile.environment.get', method: 'GET', path: '/v1/profiles/:name/environment', classes: ['person', 'broker', 'cron'], resource: 'profile' },
197
197
  { name: 'profile.environment.set', method: 'PUT', path: '/v1/profiles/:name/environment', classes: ['person'], resource: 'profile' },
198
198
  { name: 'profiles.delete.116', method: 'DELETE', path: '/v1/profiles/:name', classes: ['person', 'app', 'broker'], resource: 'profile' },
199
199
  { name: 'profile.list', method: 'GET', path: '/v1/profiles', classes: ['person', 'app', 'broker'], resource: 'profile', stage: 'chat' },
@@ -27,7 +27,7 @@ export function cachedBrokerNodeFields(node) {
27
27
  * exited (the lane processes run that node's lifecycle pass). `document` carries a document object id: it was edited or
28
28
  * deleted, and a browser document stream re-reads it. The writers fire them (the
29
29
  * schema's triggers, or the unit that owns the writer); the bus only delivers. */
30
- export const BROKER_SIGNAL_KINDS = ['mail', 'node', 'grant', 'run_event', 'report', 'structured_request', 'queue', 'spend_limits', 'environment_image', 'fault_retry', 'settings', 'machine', 'machine_call', 'document', 'execution_exit'];
30
+ export const BROKER_SIGNAL_KINDS = ['mail', 'node', 'grant', 'run_event', 'report', 'structured_request', 'queue', 'spend_limits', 'environment_image', 'fault_retry', 'settings', 'machine', 'machine_call', 'document', 'review', 'execution_exit'];
31
31
  const KNOWN_KINDS = new Set(BROKER_SIGNAL_KINDS);
32
32
  /** Hints, not delivery state: a rolled-back write may mark an id. The consumer always re-reads durable state. Pending
33
33
  * marks are bounded by distinct (kind, id) pairs and delivered once per flush. */
@@ -7,24 +7,27 @@ import { CRON_RUN_RING, cancelCron, listCronRuns, parseCronSink } from '../../co
7
7
  import { hasNoNaturalCycle } from '../../core/runtime/revive-all.js';
8
8
  import { isParked } from '../../core/runtime/lifecycle.js';
9
9
  import { enqueueNodeMail } from '../../core/feed/messages.js';
10
+ import { emitEvent } from '../../core/events/emit.js';
10
11
  import { cadenceDisplay } from '../../core/wake.js';
11
- import { machineEnvironmentOfCron, queueCronCancel } from './machine-fire.js';
12
+ import { cronEnvironment, queueCronCancel } from './machine-fire.js';
13
+ import { runnerForEnvironment } from '../../core/runtime/runner/index.js';
12
14
  const SENT = /^delivered: /;
13
15
  const EMPTY_OK = (r) => r.exit_code === 0 && (r.stdout_head ?? '') === '';
14
16
  /** Real runs only: the overlap pass writes a marker row that is not a run. */
15
17
  function realRuns(runs) {
16
18
  return runs.filter((r) => r.exit_code !== null || !(r.delivered ?? '').startsWith('skipped'));
17
19
  }
18
- function endedMessage(c, end, runs) {
20
+ function endedMessage(c, end, runs, toSink) {
19
21
  const real = realRuns(runs);
20
22
  // The run log keeps the last CRON_RUN_RING rows, so a full ring means the true count is unknown.
21
23
  const full = runs.length >= CRON_RUN_RING;
22
24
  const lastSent = real.find((r) => SENT.test(r.delivered ?? ''));
23
25
  const cause = end.kind === 'expired'
24
26
  ? `expired at ${c.expires_at} and was deleted${c.held ? ' while held by exit 75; the pending occurrence never fired' : ''}`
25
- : `was canceled by ${end.by} and deleted`;
27
+ : end.kind === 'max_fires' ? `reached its maximum of ${end.max} fires and was deleted`
28
+ : `was canceled by ${end.by} and deleted`;
26
29
  const lines = [
27
- `Cron "${c.name}" (${c.cron_id}, ${c.recur != null ? cadenceDisplay(c.recur) : 'one-shot'}) ${cause}. It was delivering to you, so nothing will wake you from it any more.`,
30
+ `Cron "${c.name}" (${c.cron_id}, ${c.recur != null ? cadenceDisplay(c.recur) : 'one-shot'}) ${cause}. ${toSink ? 'It was delivering to you, so nothing will wake you from it any more.' : 'It was anchored on you.'}`,
28
31
  '',
29
32
  `- runs made: ${full ? `at least ${real.length} (the run log keeps the last ${CRON_RUN_RING} entries)` : real.length}`,
30
33
  lastSent !== undefined
@@ -39,7 +42,7 @@ function endedMessage(c, end, runs) {
39
42
  if (real.length > 0 && real.every(EMPTY_OK)) {
40
43
  lines.push('', 'Every recorded run exited 0 with empty stdout, so the check may have been failing without saying so. A pipeline exits with its last stage, so `probe 2>&1 | grep … | jq …` hides a failed probe unless the command starts with `set -o pipefail`.');
41
44
  }
42
- return { label: `⏰ cron ${c.name} ${end.kind === 'expired' ? 'expired' : 'canceled'}`, body: lines.join('\n') };
45
+ return { label: `⏰ cron ${c.name} ${end.kind === 'canceled' ? 'canceled' : end.kind === 'max_fires' ? 'ended' : 'expired'}`, body: lines.join('\n') };
43
46
  }
44
47
  /** enqueueNodeMail throws for a node whose run root is being deleted; a throw would roll back the delete and stall the whole due pass. */
45
48
  async function runIsDeleting(node) {
@@ -55,21 +58,29 @@ export async function canTakeMail(node) {
55
58
  * that can still take mail: gone, deleting, or finalized with no wake ahead. */
56
59
  export async function endCron(c, end, options) {
57
60
  const sink = parseCronSink(c.sink);
58
- const target = sink?.kind === 'node' ? await getNode(sink.node) : null;
61
+ // A cron that used all its fires tells its anchor, whatever its output sink (NL-1110); every other end tells the node sink.
62
+ const targetId = end?.kind === 'max_fires' && c.anchor_node !== null ? c.anchor_node : sink?.kind === 'node' ? sink.node : null;
63
+ const target = targetId !== null ? await getNode(targetId) : null;
59
64
  const notify = end !== null && target !== null && await canTakeMail(target);
60
- // A run on a machine is not a local process the delete can signal: owe the machine a cancel of that run id. It is delivered when the link is up
65
+ // A run on a machine or in a sandbox is not a local process the delete can signal. A machine is owed a cancel of that run id, delivered when the link is up
61
66
  // (at once, or on reconnect), including for a `cron.run` the machine never received.
62
67
  if (c.run_state === 'running' && c.run_execution_id !== null && options?.preserveRunningProcess !== true) {
63
- const machine = await machineEnvironmentOfCron(c);
64
- if (machine !== null)
65
- await queueCronCancel(machine, c.run_execution_id);
68
+ const environment = await cronEnvironment(c);
69
+ if (environment?.kind === 'machine')
70
+ await queueCronCancel(environment.id, c.run_execution_id);
71
+ // A sandbox process is killed now; a Blaxel failure is logged and the delete goes ahead (the run timeout or recovery ends the process).
72
+ if (environment?.kind === 'blaxel' && c.anchor_node != null) {
73
+ await runnerForEnvironment('blaxel').cronCancel?.(c.anchor_node, c.run_execution_id).catch((error) => {
74
+ emitEvent({ level: 'error', event: 'cron.sandbox.cancel_failed', error, fields: { cron_id: c.cron_id, run_id: c.run_execution_id } });
75
+ });
76
+ }
66
77
  }
67
78
  return await withCanvasWrite(async () => {
68
79
  const runs = notify ? await listCronRuns(c.cron_id) : [];
69
80
  if (!await cancelCron(c.cron_id, options))
70
81
  return false;
71
82
  if (notify) {
72
- const { label, body } = endedMessage(c, end, runs);
83
+ const { label, body } = endedMessage(c, end, runs, sink?.kind === 'node' && sink.node === target.node_id);
73
84
  await enqueueNodeMail(target.node_id, {
74
85
  kind: 'message', label, senderNodeId: null, bodyJson: { body }, urgency: 'normal', wake: 1,
75
86
  idempotencyKey: `cron-ended:${c.cron_id}`,