@north-light/cli 0.3.764 → 0.3.766

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 (969) hide show
  1. package/dist/api/contract.d.ts +1 -1
  2. package/dist/api/contract.js +1 -1
  3. package/dist/api/index.d.ts +0 -1
  4. package/dist/api/index.js +1 -1
  5. package/dist/builtin-memory/internal/nodes-and-canvas.md +7 -8
  6. package/dist/builtin-memory/internal/storage-tiers.md +5 -4
  7. package/dist/builtin-memory/northlight-apps/guides/test-your-app.md +1 -1
  8. package/dist/clients/attach/viewer.js +437 -437
  9. package/dist/commands/sys/signin.d.ts +2 -0
  10. package/dist/commands/sys/signin.js +4 -2
  11. package/dist/commands/sys.js +1 -1
  12. package/dist/core/canvas/db.js +4 -4
  13. package/dist/core/directory/issuer.d.ts +1 -1
  14. package/dist/core/grants/shadow.js +1 -1
  15. package/dist/core/graph/documents.js +1 -1
  16. package/dist/daemon/api/handlers/app-environments.d.ts +1 -0
  17. package/dist/daemon/api/handlers/app-environments.js +1 -1
  18. package/dist/daemon/api/handlers/environments.d.ts +1 -0
  19. package/dist/daemon/api/handlers/environments.js +1 -1
  20. package/dist/daemon/api/operations.js +1 -1
  21. package/dist/daemon/api/server.d.ts +1 -0
  22. package/dist/daemon/api/server.js +1 -1
  23. package/dist/daemon/cron/passes.d.ts +0 -2
  24. package/dist/daemon/cron-run.js +2 -2
  25. package/dist/daemon/crtrd-cli.js +1 -1
  26. package/dist/daemon/crtrd.d.ts +5 -5
  27. package/dist/daemon/crtrd.js +7 -19
  28. package/dist/daemon/due-sources.d.ts +1 -1
  29. package/dist/daemon/due-sources.js +1 -1
  30. package/dist/daemon/due.js +4 -4
  31. package/dist/daemon/machine-link/holder.js +5 -5
  32. package/dist/daemon/manage.d.ts +0 -12
  33. package/dist/daemon/manage.js +3 -3
  34. package/dist/daemon/postgres/index.d.ts +1 -1
  35. package/dist/daemon/postgres/index.js +1 -1
  36. package/dist/daemon/postgres/supervisor.d.ts +0 -62
  37. package/dist/daemon/postgres/supervisor.js +1 -2
  38. package/dist/daemon/reconcilers/broker-supervision.d.ts +0 -2
  39. package/dist/daemon/reconcilers/broker-supervision.js +1 -1
  40. package/dist/daemon/reconcilers/controller-death.d.ts +0 -2
  41. package/dist/daemon/reconcilers/controller-death.js +1 -1
  42. package/dist/daemon/reconcilers/cron-lane.d.ts +0 -1
  43. package/dist/daemon/reconcilers/cron-lane.js +1 -1
  44. package/dist/daemon/reconcilers/live-obligation.d.ts +1 -6
  45. package/dist/daemon/reconcilers/live-obligation.js +1 -1
  46. package/dist/daemon/reconcilers/node-deadline.d.ts +1 -2
  47. package/dist/daemon/reconcilers/node-deadline.js +1 -1
  48. package/dist/daemon/reconcilers/storage-maintenance.d.ts +0 -2
  49. package/dist/daemon/reconcilers/storage-maintenance.js +1 -1
  50. package/dist/daemon/reconcilers/structured-request-lane.d.ts +1 -2
  51. package/dist/daemon/reconcilers/structured-request-lane.js +1 -1
  52. package/docs/apps/guides/test-your-app.md +1 -1
  53. package/docs/ci-runner.md +3 -3
  54. package/package.json +3 -3
  55. package/packages/crouter-api/dist/api/contract.js +1 -1
  56. package/packages/crouter-api/dist/api/index.js +0 -1
  57. package/packages/crouter-api/dist/daemon/manage.js +0 -12
  58. package/packages/crouter-api/package.json +1 -1
  59. package/packages/crouter-identity/package.json +1 -1
  60. package/packages/crouter-plugin/package.json +3 -3
  61. package/runtime.lock.json +14 -14
  62. package/dist/api/dto/imports.d.ts +0 -156
  63. package/dist/api/dto/imports.js +0 -0
  64. package/dist/commands/sys/import/move.d.ts +0 -29
  65. package/dist/commands/sys/import/move.js +0 -6
  66. package/dist/commands/sys/import/resume.d.ts +0 -1
  67. package/dist/commands/sys/import/resume.js +0 -1
  68. package/dist/commands/sys/import/start.d.ts +0 -1
  69. package/dist/commands/sys/import/start.js +0 -1
  70. package/dist/core/canvas/daemon-owner.d.ts +0 -75
  71. package/dist/core/canvas/daemon-owner.js +0 -1
  72. package/dist/core/import/bundle/blob-keys.d.ts +0 -12
  73. package/dist/core/import/bundle/blob-keys.js +0 -1
  74. package/dist/core/import/bundle/layout.d.ts +0 -89
  75. package/dist/core/import/bundle/layout.js +0 -4
  76. package/dist/core/import/export/archive.d.ts +0 -11
  77. package/dist/core/import/export/archive.js +0 -1
  78. package/dist/core/import/export/cloud.d.ts +0 -41
  79. package/dist/core/import/export/cloud.js +0 -1
  80. package/dist/core/import/export/dump.d.ts +0 -34
  81. package/dist/core/import/export/dump.js +0 -4
  82. package/dist/core/import/export/files.d.ts +0 -23
  83. package/dist/core/import/export/files.js +0 -1
  84. package/dist/core/import/export/inline.d.ts +0 -3
  85. package/dist/core/import/export/inline.js +0 -1
  86. package/dist/core/import/export/source.d.ts +0 -2
  87. package/dist/core/import/export/source.js +0 -1
  88. package/dist/core/import/export/stores.d.ts +0 -9
  89. package/dist/core/import/export/stores.js +0 -4
  90. package/dist/core/import/load/bind.d.ts +0 -42
  91. package/dist/core/import/load/bind.js +0 -20
  92. package/dist/core/import/load/blobs.d.ts +0 -27
  93. package/dist/core/import/load/blobs.js +0 -1
  94. package/dist/core/import/load/catalog.d.ts +0 -39
  95. package/dist/core/import/load/catalog.js +0 -9
  96. package/dist/core/import/load/copy.d.ts +0 -29
  97. package/dist/core/import/load/copy.js +0 -11
  98. package/dist/core/import/load/keys.d.ts +0 -5
  99. package/dist/core/import/load/keys.js +0 -8
  100. package/dist/core/import/load/open-grants.d.ts +0 -1
  101. package/dist/core/import/load/open-grants.js +0 -1
  102. package/dist/core/import/load/path-map.d.ts +0 -7
  103. package/dist/core/import/load/path-map.js +0 -1
  104. package/dist/core/import/load/prepare.d.ts +0 -70
  105. package/dist/core/import/load/prepare.js +0 -14
  106. package/dist/core/import/load/publish-plugins.d.ts +0 -10
  107. package/dist/core/import/load/publish-plugins.js +0 -1
  108. package/dist/core/import/load/rewrite.d.ts +0 -54
  109. package/dist/core/import/load/rewrite.js +0 -15
  110. package/dist/core/import/load/rollback.d.ts +0 -3
  111. package/dist/core/import/load/rollback.js +0 -7
  112. package/dist/core/import/load/run.d.ts +0 -26
  113. package/dist/core/import/load/run.js +0 -2
  114. package/dist/core/import/load/stage.d.ts +0 -15
  115. package/dist/core/import/load/stage.js +0 -1
  116. package/dist/core/import/load/stores.d.ts +0 -32
  117. package/dist/core/import/load/stores.js +0 -2
  118. package/dist/core/import/load/verify.d.ts +0 -4
  119. package/dist/core/import/load/verify.js +0 -13
  120. package/dist/daemon/api/handlers/imports.d.ts +0 -2
  121. package/dist/daemon/api/handlers/imports.js +0 -1
  122. package/dist/daemon/api/handlers/machine-credential.d.ts +0 -2
  123. package/dist/daemon/api/handlers/machine-credential.js +0 -1
  124. package/dist/daemon/api/import-auth.d.ts +0 -6
  125. package/dist/daemon/api/import-auth.js +0 -1
  126. package/dist/daemon/import-dump-run.d.ts +0 -1
  127. package/dist/daemon/import-dump-run.js +0 -5
  128. package/dist/daemon/reconcilers/import-lane.d.ts +0 -17
  129. package/dist/daemon/reconcilers/import-lane.js +0 -1
  130. package/packages/crouter-api/dist/api/dto/imports.js +0 -2
  131. package/packages/crouter-api/dist/build-root.js +0 -402
  132. package/packages/crouter-api/dist/clients/attach/ansi-cells.js +0 -137
  133. package/packages/crouter-api/dist/clients/attach/chrome/bash-jobs.js +0 -34
  134. package/packages/crouter-api/dist/clients/attach/chrome/canvas-panels.js +0 -285
  135. package/packages/crouter-api/dist/clients/attach/chrome/completion-bell.js +0 -89
  136. package/packages/crouter-api/dist/clients/attach/chrome/cron-wait.js +0 -34
  137. package/packages/crouter-api/dist/clients/attach/chrome/header.js +0 -30
  138. package/packages/crouter-api/dist/clients/attach/chrome/inbox-strip.js +0 -221
  139. package/packages/crouter-api/dist/clients/attach/chrome/key-hint.js +0 -16
  140. package/packages/crouter-api/dist/clients/attach/chrome/object-wait.js +0 -24
  141. package/packages/crouter-api/dist/clients/attach/chrome/recap.js +0 -19
  142. package/packages/crouter-api/dist/clients/attach/chrome/review-wait.js +0 -22
  143. package/packages/crouter-api/dist/clients/attach/chrome/roster.js +0 -283
  144. package/packages/crouter-api/dist/clients/attach/chrome/run-facts.js +0 -76
  145. package/packages/crouter-api/dist/clients/attach/chrome/status-line.js +0 -122
  146. package/packages/crouter-api/dist/clients/attach/chrome/ticket-panel.js +0 -261
  147. package/packages/crouter-api/dist/clients/attach/chrome/widgets.js +0 -60
  148. package/packages/crouter-api/dist/clients/attach/command.js +0 -107
  149. package/packages/crouter-api/dist/clients/attach/config.js +0 -280
  150. package/packages/crouter-api/dist/clients/attach/input/capabilities.js +0 -114
  151. package/packages/crouter-api/dist/clients/attach/input/clipboard-image.js +0 -237
  152. package/packages/crouter-api/dist/clients/attach/input/completion-frecency.js +0 -141
  153. package/packages/crouter-api/dist/clients/attach/input/controller.js +0 -432
  154. package/packages/crouter-api/dist/clients/attach/input/local-files.js +0 -113
  155. package/packages/crouter-api/dist/clients/attach/input/overlay-owner.js +0 -192
  156. package/packages/crouter-api/dist/clients/attach/input/ref-autocomplete.js +0 -176
  157. package/packages/crouter-api/dist/clients/attach/input/titled-editor.js +0 -859
  158. package/packages/crouter-api/dist/clients/attach/overlays/auth.js +0 -247
  159. package/packages/crouter-api/dist/clients/attach/overlays/dialogs.js +0 -102
  160. package/packages/crouter-api/dist/clients/attach/overlays/graph.js +0 -743
  161. package/packages/crouter-api/dist/clients/attach/overlays/help.js +0 -214
  162. package/packages/crouter-api/dist/clients/attach/overlays/mcp.js +0 -302
  163. package/packages/crouter-api/dist/clients/attach/overlays/pickers.js +0 -163
  164. package/packages/crouter-api/dist/clients/attach/render/activity-slot.js +0 -13
  165. package/packages/crouter-api/dist/clients/attach/render/assistant-message.js +0 -56
  166. package/packages/crouter-api/dist/clients/attach/render/card-presentation.js +0 -232
  167. package/packages/crouter-api/dist/clients/attach/render/chat-view.js +0 -1956
  168. package/packages/crouter-api/dist/clients/attach/render/context-message.js +0 -63
  169. package/packages/crouter-api/dist/clients/attach/render/crtr-output.js +0 -721
  170. package/packages/crouter-api/dist/clients/attach/render/diagram.js +0 -111
  171. package/packages/crouter-api/dist/clients/attach/render/doc-links.js +0 -78
  172. package/packages/crouter-api/dist/clients/attach/render/edit-diff.js +0 -304
  173. package/packages/crouter-api/dist/clients/attach/render/glyph-codepoints.js +0 -42
  174. package/packages/crouter-api/dist/clients/attach/render/group-activity.js +0 -276
  175. package/packages/crouter-api/dist/clients/attach/render/group-recap.js +0 -146
  176. package/packages/crouter-api/dist/clients/attach/render/markdown-source.js +0 -279
  177. package/packages/crouter-api/dist/clients/attach/render/measured-container.js +0 -322
  178. package/packages/crouter-api/dist/clients/attach/render/page-block.js +0 -187
  179. package/packages/crouter-api/dist/clients/attach/render/scroll-animation.js +0 -80
  180. package/packages/crouter-api/dist/clients/attach/render/tool-calls.js +0 -350
  181. package/packages/crouter-api/dist/clients/attach/render/transcript-copy.js +0 -81
  182. package/packages/crouter-api/dist/clients/attach/render/transcript-search.js +0 -152
  183. package/packages/crouter-api/dist/clients/attach/render/viewport.js +0 -184
  184. package/packages/crouter-api/dist/clients/attach/session/banner.js +0 -33
  185. package/packages/crouter-api/dist/clients/attach/session/bindings.js +0 -72
  186. package/packages/crouter-api/dist/clients/attach/session/chrome-refresh.js +0 -169
  187. package/packages/crouter-api/dist/clients/attach/session/connection.js +0 -185
  188. package/packages/crouter-api/dist/clients/attach/session/context.js +0 -16
  189. package/packages/crouter-api/dist/clients/attach/session/document-links.js +0 -48
  190. package/packages/crouter-api/dist/clients/attach/session/editor-frame.js +0 -161
  191. package/packages/crouter-api/dist/clients/attach/session/editor-inventory.js +0 -156
  192. package/packages/crouter-api/dist/clients/attach/session/file-links.js +0 -73
  193. package/packages/crouter-api/dist/clients/attach/session/focus-events.js +0 -12
  194. package/packages/crouter-api/dist/clients/attach/session/frame.js +0 -214
  195. package/packages/crouter-api/dist/clients/attach/session/frames.js +0 -203
  196. package/packages/crouter-api/dist/clients/attach/session/identity.js +0 -27
  197. package/packages/crouter-api/dist/clients/attach/session/input-wiring.js +0 -153
  198. package/packages/crouter-api/dist/clients/attach/session/invariant.js +0 -15
  199. package/packages/crouter-api/dist/clients/attach/session/keys.js +0 -84
  200. package/packages/crouter-api/dist/clients/attach/session/layout-record.js +0 -52
  201. package/packages/crouter-api/dist/clients/attach/session/layout.js +0 -59
  202. package/packages/crouter-api/dist/clients/attach/session/mouse.js +0 -78
  203. package/packages/crouter-api/dist/clients/attach/session/pane-focus.js +0 -42
  204. package/packages/crouter-api/dist/clients/attach/session/pane-tag.js +0 -118
  205. package/packages/crouter-api/dist/clients/attach/session/pi-assets.js +0 -24
  206. package/packages/crouter-api/dist/clients/attach/session/pi-oauth-flows.js +0 -21
  207. package/packages/crouter-api/dist/clients/attach/session/profile-files.js +0 -208
  208. package/packages/crouter-api/dist/clients/attach/session/readonly-popup.js +0 -25
  209. package/packages/crouter-api/dist/clients/attach/session/reconnect.js +0 -237
  210. package/packages/crouter-api/dist/clients/attach/session/selection.js +0 -108
  211. package/packages/crouter-api/dist/clients/attach/session/state-sync.js +0 -67
  212. package/packages/crouter-api/dist/clients/attach/session/surface-frame.js +0 -73
  213. package/packages/crouter-api/dist/clients/attach/session/surface-host.js +0 -239
  214. package/packages/crouter-api/dist/clients/attach/session/teardown.js +0 -102
  215. package/packages/crouter-api/dist/clients/attach/session/transcript-search.js +0 -151
  216. package/packages/crouter-api/dist/clients/attach/session/whip-achievements.js +0 -145
  217. package/packages/crouter-api/dist/clients/attach/session/whip.js +0 -362
  218. package/packages/crouter-api/dist/clients/attach/slash/dispatch.js +0 -759
  219. package/packages/crouter-api/dist/clients/attach/slash/prompt-preview.js +0 -121
  220. package/packages/crouter-api/dist/clients/attach/slash/recover.js +0 -133
  221. package/packages/crouter-api/dist/clients/attach/viewer.js +0 -1026
  222. package/packages/crouter-api/dist/clients/conversation/projection.js +0 -324
  223. package/packages/crouter-api/dist/clients/conversation/submit.js +0 -51
  224. package/packages/crouter-api/dist/clients/dashboard/app.js +0 -439
  225. package/packages/crouter-api/dist/clients/dashboard/model.js +0 -77
  226. package/packages/crouter-api/dist/clients/dashboard/render.js +0 -148
  227. package/packages/crouter-api/dist/clients/editor-roundtrip.js +0 -41
  228. package/packages/crouter-api/dist/clients/inbox/controller.js +0 -772
  229. package/packages/crouter-api/dist/clients/inbox/dto-adapt.js +0 -94
  230. package/packages/crouter-api/dist/clients/inbox/layout.js +0 -9
  231. package/packages/crouter-api/dist/clients/inbox/page-adapter.js +0 -56
  232. package/packages/crouter-api/dist/clients/inbox/resolve.js +0 -35
  233. package/packages/crouter-api/dist/clients/inbox/surface.js +0 -190
  234. package/packages/crouter-api/dist/clients/inbox/tui/ansi.js +0 -321
  235. package/packages/crouter-api/dist/clients/inbox/tui/input.js +0 -392
  236. package/packages/crouter-api/dist/clients/inbox/tui/keys.js +0 -104
  237. package/packages/crouter-api/dist/clients/inbox/tui/page-body.js +0 -62
  238. package/packages/crouter-api/dist/clients/inbox/tui/panel.js +0 -92
  239. package/packages/crouter-api/dist/clients/inbox/tui/render.js +0 -382
  240. package/packages/crouter-api/dist/clients/inbox/tui/slots.js +0 -134
  241. package/packages/crouter-api/dist/clients/inbox/tui/types.js +0 -1
  242. package/packages/crouter-api/dist/clients/inbox/tui.js +0 -91
  243. package/packages/crouter-api/dist/clients/open-browser.js +0 -6
  244. package/packages/crouter-api/dist/clients/surfaces/host.js +0 -1
  245. package/packages/crouter-api/dist/commands/api-client.js +0 -432
  246. package/packages/crouter-api/dist/commands/attention.js +0 -215
  247. package/packages/crouter-api/dist/commands/canvas/edges.js +0 -41
  248. package/packages/crouter-api/dist/commands/canvas/list.js +0 -81
  249. package/packages/crouter-api/dist/commands/canvas/read.js +0 -97
  250. package/packages/crouter-api/dist/commands/canvas/search.js +0 -51
  251. package/packages/crouter-api/dist/commands/canvas/share.js +0 -80
  252. package/packages/crouter-api/dist/commands/canvas/unwatch.js +0 -42
  253. package/packages/crouter-api/dist/commands/canvas/watch.js +0 -63
  254. package/packages/crouter-api/dist/commands/canvas-analytics/chart.js +0 -124
  255. package/packages/crouter-api/dist/commands/canvas-analytics/drilldown.js +0 -96
  256. package/packages/crouter-api/dist/commands/canvas-analytics/format.js +0 -106
  257. package/packages/crouter-api/dist/commands/canvas-analytics/graph-detail.js +0 -307
  258. package/packages/crouter-api/dist/commands/canvas-analytics/graphs.js +0 -365
  259. package/packages/crouter-api/dist/commands/canvas-analytics/memory.js +0 -211
  260. package/packages/crouter-api/dist/commands/canvas-analytics/overview.js +0 -189
  261. package/packages/crouter-api/dist/commands/canvas-analytics/shell.js +0 -416
  262. package/packages/crouter-api/dist/commands/canvas-analytics/time.js +0 -228
  263. package/packages/crouter-api/dist/commands/canvas-analytics/usage.js +0 -305
  264. package/packages/crouter-api/dist/commands/canvas-analytics/view.js +0 -102
  265. package/packages/crouter-api/dist/commands/canvas-analytics.js +0 -28
  266. package/packages/crouter-api/dist/commands/canvas-browse.js +0 -71
  267. package/packages/crouter-api/dist/commands/canvas-config.js +0 -192
  268. package/packages/crouter-api/dist/commands/canvas-history/grep.js +0 -85
  269. package/packages/crouter-api/dist/commands/canvas-history/read.js +0 -48
  270. package/packages/crouter-api/dist/commands/canvas-history/search.js +0 -99
  271. package/packages/crouter-api/dist/commands/canvas-history/shared.js +0 -135
  272. package/packages/crouter-api/dist/commands/canvas-history/stats.js +0 -68
  273. package/packages/crouter-api/dist/commands/canvas-history.js +0 -29
  274. package/packages/crouter-api/dist/commands/canvas-issue.js +0 -148
  275. package/packages/crouter-api/dist/commands/canvas-prune.js +0 -111
  276. package/packages/crouter-api/dist/commands/canvas-roster.js +0 -69
  277. package/packages/crouter-api/dist/commands/canvas-snapshot.js +0 -34
  278. package/packages/crouter-api/dist/commands/canvas-use.js +0 -61
  279. package/packages/crouter-api/dist/commands/canvas.js +0 -57
  280. package/packages/crouter-api/dist/commands/chord.js +0 -242
  281. package/packages/crouter-api/dist/commands/cron.js +0 -541
  282. package/packages/crouter-api/dist/commands/custom-object/ack.js +0 -30
  283. package/packages/crouter-api/dist/commands/custom-object/publish.js +0 -39
  284. package/packages/crouter-api/dist/commands/custom-object/receive.js +0 -69
  285. package/packages/crouter-api/dist/commands/custom-object/register.js +0 -69
  286. package/packages/crouter-api/dist/commands/custom-object/shared.js +0 -14
  287. package/packages/crouter-api/dist/commands/custom-object/unregister.js +0 -26
  288. package/packages/crouter-api/dist/commands/custom-object.js +0 -21
  289. package/packages/crouter-api/dist/commands/dashboard.js +0 -86
  290. package/packages/crouter-api/dist/commands/doc/delete.js +0 -30
  291. package/packages/crouter-api/dist/commands/doc/edit.js +0 -83
  292. package/packages/crouter-api/dist/commands/doc/history.js +0 -38
  293. package/packages/crouter-api/dist/commands/doc/lint.js +0 -36
  294. package/packages/crouter-api/dist/commands/doc/list.js +0 -19
  295. package/packages/crouter-api/dist/commands/doc/move.js +0 -37
  296. package/packages/crouter-api/dist/commands/doc/read.js +0 -19
  297. package/packages/crouter-api/dist/commands/doc/replace-blocks.js +0 -40
  298. package/packages/crouter-api/dist/commands/doc/shared.js +0 -156
  299. package/packages/crouter-api/dist/commands/doc/write.js +0 -53
  300. package/packages/crouter-api/dist/commands/doc.js +0 -27
  301. package/packages/crouter-api/dist/commands/human/components.js +0 -78
  302. package/packages/crouter-api/dist/commands/human/feedback.js +0 -112
  303. package/packages/crouter-api/dist/commands/human/prompts.js +0 -319
  304. package/packages/crouter-api/dist/commands/human/queue.js +0 -191
  305. package/packages/crouter-api/dist/commands/human/request.js +0 -269
  306. package/packages/crouter-api/dist/commands/human/review.js +0 -287
  307. package/packages/crouter-api/dist/commands/human/shared.js +0 -67
  308. package/packages/crouter-api/dist/commands/human.js +0 -63
  309. package/packages/crouter-api/dist/commands/node/bash.js +0 -398
  310. package/packages/crouter-api/dist/commands/node/create.js +0 -363
  311. package/packages/crouter-api/dist/commands/node/inspect.js +0 -305
  312. package/packages/crouter-api/dist/commands/node/lifecycle.js +0 -577
  313. package/packages/crouter-api/dist/commands/node/message.js +0 -170
  314. package/packages/crouter-api/dist/commands/node/outcome.js +0 -133
  315. package/packages/crouter-api/dist/commands/node/pyramid.js +0 -79
  316. package/packages/crouter-api/dist/commands/node/subscription.js +0 -78
  317. package/packages/crouter-api/dist/commands/node/wait.js +0 -157
  318. package/packages/crouter-api/dist/commands/node-context.js +0 -145
  319. package/packages/crouter-api/dist/commands/node-lifecycle-revive.js +0 -222
  320. package/packages/crouter-api/dist/commands/node-snapshot.js +0 -37
  321. package/packages/crouter-api/dist/commands/node-transcript.js +0 -59
  322. package/packages/crouter-api/dist/commands/node-worktree.js +0 -134
  323. package/packages/crouter-api/dist/commands/node.js +0 -29
  324. package/packages/crouter-api/dist/commands/person-settings.js +0 -30
  325. package/packages/crouter-api/dist/commands/pkg/app-installs.js +0 -125
  326. package/packages/crouter-api/dist/commands/pkg/browse/actions.js +0 -198
  327. package/packages/crouter-api/dist/commands/pkg/browse/catalog.js +0 -461
  328. package/packages/crouter-api/dist/commands/pkg/browse/command-view.js +0 -217
  329. package/packages/crouter-api/dist/commands/pkg/browse/detail-panel.js +0 -402
  330. package/packages/crouter-api/dist/commands/pkg/browse/doc-view.js +0 -84
  331. package/packages/crouter-api/dist/commands/pkg/browse/list-panel.js +0 -168
  332. package/packages/crouter-api/dist/commands/pkg/browse/model.js +0 -36
  333. package/packages/crouter-api/dist/commands/pkg/browse/shell.js +0 -640
  334. package/packages/crouter-api/dist/commands/pkg/browse.js +0 -27
  335. package/packages/crouter-api/dist/commands/pkg/market-inspect.js +0 -145
  336. package/packages/crouter-api/dist/commands/pkg/market-manage.js +0 -343
  337. package/packages/crouter-api/dist/commands/pkg/market.js +0 -14
  338. package/packages/crouter-api/dist/commands/pkg/plugin-env.js +0 -65
  339. package/packages/crouter-api/dist/commands/pkg/plugin-inspect.js +0 -178
  340. package/packages/crouter-api/dist/commands/pkg/plugin-manage.js +0 -1040
  341. package/packages/crouter-api/dist/commands/pkg/plugin.js +0 -14
  342. package/packages/crouter-api/dist/commands/pkg/shared.js +0 -62
  343. package/packages/crouter-api/dist/commands/pkg.js +0 -21
  344. package/packages/crouter-api/dist/commands/profile/daemon-profiles.js +0 -38
  345. package/packages/crouter-api/dist/commands/profile/default.js +0 -183
  346. package/packages/crouter-api/dist/commands/profile/delete.js +0 -66
  347. package/packages/crouter-api/dist/commands/profile/env.js +0 -188
  348. package/packages/crouter-api/dist/commands/profile/environment.js +0 -111
  349. package/packages/crouter-api/dist/commands/profile/kind.js +0 -27
  350. package/packages/crouter-api/dist/commands/profile/list.js +0 -45
  351. package/packages/crouter-api/dist/commands/profile/meta.js +0 -65
  352. package/packages/crouter-api/dist/commands/profile/new.js +0 -107
  353. package/packages/crouter-api/dist/commands/profile/pause.js +0 -59
  354. package/packages/crouter-api/dist/commands/profile/project.js +0 -147
  355. package/packages/crouter-api/dist/commands/profile/rename.js +0 -41
  356. package/packages/crouter-api/dist/commands/profile/show.js +0 -55
  357. package/packages/crouter-api/dist/commands/profile.js +0 -36
  358. package/packages/crouter-api/dist/commands/push.js +0 -357
  359. package/packages/crouter-api/dist/commands/revive.js +0 -183
  360. package/packages/crouter-api/dist/commands/surface/node/cycle.js +0 -83
  361. package/packages/crouter-api/dist/commands/surface/node/focus.js +0 -60
  362. package/packages/crouter-api/dist/commands/surface/node/id.js +0 -38
  363. package/packages/crouter-api/dist/commands/surface/node/pin.js +0 -42
  364. package/packages/crouter-api/dist/commands/surface/node/placement.js +0 -49
  365. package/packages/crouter-api/dist/commands/surface-dashboard.js +0 -138
  366. package/packages/crouter-api/dist/commands/surface-edit.js +0 -157
  367. package/packages/crouter-api/dist/commands/surface-inbox.js +0 -98
  368. package/packages/crouter-api/dist/commands/surface-inspect.js +0 -41
  369. package/packages/crouter-api/dist/commands/surface-node.js +0 -19
  370. package/packages/crouter-api/dist/commands/surface-tmux-spread.js +0 -214
  371. package/packages/crouter-api/dist/commands/surface.js +0 -28
  372. package/packages/crouter-api/dist/commands/sys/branch.js +0 -19
  373. package/packages/crouter-api/dist/commands/sys/config.js +0 -353
  374. package/packages/crouter-api/dist/commands/sys/context/admin/actions.js +0 -89
  375. package/packages/crouter-api/dist/commands/sys/context/admin/detail-panel.js +0 -233
  376. package/packages/crouter-api/dist/commands/sys/context/admin/docs-panel.js +0 -185
  377. package/packages/crouter-api/dist/commands/sys/context/admin/list-view.js +0 -170
  378. package/packages/crouter-api/dist/commands/sys/context/admin/model.js +0 -179
  379. package/packages/crouter-api/dist/commands/sys/context/admin/rail-panel.js +0 -229
  380. package/packages/crouter-api/dist/commands/sys/context/admin/read-view.js +0 -172
  381. package/packages/crouter-api/dist/commands/sys/context/admin/shell.js +0 -870
  382. package/packages/crouter-api/dist/commands/sys/context/admin.js +0 -148
  383. package/packages/crouter-api/dist/commands/sys/context/doc.js +0 -126
  384. package/packages/crouter-api/dist/commands/sys/context/expose.js +0 -66
  385. package/packages/crouter-api/dist/commands/sys/context/prompt-review.js +0 -244
  386. package/packages/crouter-api/dist/commands/sys/context/resolve.js +0 -326
  387. package/packages/crouter-api/dist/commands/sys/context/sysprompt.js +0 -95
  388. package/packages/crouter-api/dist/commands/sys/context.js +0 -21
  389. package/packages/crouter-api/dist/commands/sys/daemon.js +0 -354
  390. package/packages/crouter-api/dist/commands/sys/desktop.js +0 -201
  391. package/packages/crouter-api/dist/commands/sys/doctor.js +0 -650
  392. package/packages/crouter-api/dist/commands/sys/env.js +0 -39
  393. package/packages/crouter-api/dist/commands/sys/feedback.js +0 -238
  394. package/packages/crouter-api/dist/commands/sys/import/move.js +0 -205
  395. package/packages/crouter-api/dist/commands/sys/import/resume.js +0 -23
  396. package/packages/crouter-api/dist/commands/sys/import/start.js +0 -57
  397. package/packages/crouter-api/dist/commands/sys/join.js +0 -53
  398. package/packages/crouter-api/dist/commands/sys/limits.js +0 -133
  399. package/packages/crouter-api/dist/commands/sys/logs.js +0 -129
  400. package/packages/crouter-api/dist/commands/sys/machine/rotate.js +0 -49
  401. package/packages/crouter-api/dist/commands/sys/panels/broker-limits-panel.js +0 -110
  402. package/packages/crouter-api/dist/commands/sys/panels/dependencies-panel.js +0 -80
  403. package/packages/crouter-api/dist/commands/sys/panels/keybindings-panel.js +0 -703
  404. package/packages/crouter-api/dist/commands/sys/panels/models-panel.js +0 -1160
  405. package/packages/crouter-api/dist/commands/sys/panels/plugin-env-panel.js +0 -70
  406. package/packages/crouter-api/dist/commands/sys/panels/plugins-panel.js +0 -87
  407. package/packages/crouter-api/dist/commands/sys/panels/prefs-panel.js +0 -97
  408. package/packages/crouter-api/dist/commands/sys/panels/profiles-panel.js +0 -656
  409. package/packages/crouter-api/dist/commands/sys/panels/provider-panel.js +0 -534
  410. package/packages/crouter-api/dist/commands/sys/panels/terminal-panel.js +0 -67
  411. package/packages/crouter-api/dist/commands/sys/provider-login.js +0 -99
  412. package/packages/crouter-api/dist/commands/sys/retry-delivery.js +0 -33
  413. package/packages/crouter-api/dist/commands/sys/settings-shell.js +0 -400
  414. package/packages/crouter-api/dist/commands/sys/settings.js +0 -46
  415. package/packages/crouter-api/dist/commands/sys/setup-core.js +0 -882
  416. package/packages/crouter-api/dist/commands/sys/setup-settings-runner.js +0 -15
  417. package/packages/crouter-api/dist/commands/sys/setup-wizard.js +0 -351
  418. package/packages/crouter-api/dist/commands/sys/setup.js +0 -41
  419. package/packages/crouter-api/dist/commands/sys/shared.js +0 -81
  420. package/packages/crouter-api/dist/commands/sys/signin.js +0 -169
  421. package/packages/crouter-api/dist/commands/sys/spaces.js +0 -22
  422. package/packages/crouter-api/dist/commands/sys/spend.js +0 -144
  423. package/packages/crouter-api/dist/commands/sys/support/prepare.js +0 -239
  424. package/packages/crouter-api/dist/commands/sys/support/submit.js +0 -524
  425. package/packages/crouter-api/dist/commands/sys/support.js +0 -18
  426. package/packages/crouter-api/dist/commands/sys/sync-deps.js +0 -445
  427. package/packages/crouter-api/dist/commands/sys/sync-project-guidance.js +0 -320
  428. package/packages/crouter-api/dist/commands/sys/sync-shared.js +0 -139
  429. package/packages/crouter-api/dist/commands/sys/sync-skills.js +0 -297
  430. package/packages/crouter-api/dist/commands/sys/sync.js +0 -17
  431. package/packages/crouter-api/dist/commands/sys/terminal-option.js +0 -542
  432. package/packages/crouter-api/dist/commands/sys/tutorial/branch.js +0 -15
  433. package/packages/crouter-api/dist/commands/sys/tutorial/lessons.js +0 -107
  434. package/packages/crouter-api/dist/commands/sys/tutorial/scenario.js +0 -432
  435. package/packages/crouter-api/dist/commands/sys/tutorial/tracks.js +0 -96
  436. package/packages/crouter-api/dist/commands/sys/update.js +0 -158
  437. package/packages/crouter-api/dist/commands/sys/worktrees.js +0 -53
  438. package/packages/crouter-api/dist/commands/sys.js +0 -28
  439. package/packages/crouter-api/dist/core/activity-signal.js +0 -38
  440. package/packages/crouter-api/dist/core/async-array.js +0 -48
  441. package/packages/crouter-api/dist/core/auth-file.js +0 -89
  442. package/packages/crouter-api/dist/core/auth-interaction.js +0 -94
  443. package/packages/crouter-api/dist/core/bash-guard.js +0 -527
  444. package/packages/crouter-api/dist/core/bash-job-supervisor.js +0 -170
  445. package/packages/crouter-api/dist/core/bash-jobs.js +0 -460
  446. package/packages/crouter-api/dist/core/blobs/directory.js +0 -264
  447. package/packages/crouter-api/dist/core/blobs/fault.js +0 -6
  448. package/packages/crouter-api/dist/core/blobs/index.js +0 -30
  449. package/packages/crouter-api/dist/core/blobs/r2.js +0 -169
  450. package/packages/crouter-api/dist/core/broker-client/client.js +0 -186
  451. package/packages/crouter-api/dist/core/broker-client/index.js +0 -14
  452. package/packages/crouter-api/dist/core/broker-client/transport-relay.js +0 -256
  453. package/packages/crouter-api/dist/core/broker-client/transport-socket.js +0 -187
  454. package/packages/crouter-api/dist/core/broker-client/transport.js +0 -40
  455. package/packages/crouter-api/dist/core/canvas/app-run.js +0 -4
  456. package/packages/crouter-api/dist/core/canvas/attention.js +0 -47
  457. package/packages/crouter-api/dist/core/canvas/browse/app.js +0 -1050
  458. package/packages/crouter-api/dist/core/canvas/browse/model.js +0 -477
  459. package/packages/crouter-api/dist/core/canvas/browse/pins.js +0 -29
  460. package/packages/crouter-api/dist/core/canvas/browse/render.js +0 -1058
  461. package/packages/crouter-api/dist/core/canvas/canvas.js +0 -1260
  462. package/packages/crouter-api/dist/core/canvas/crons.js +0 -557
  463. package/packages/crouter-api/dist/core/canvas/daemon-actions.js +0 -99
  464. package/packages/crouter-api/dist/core/canvas/db.js +0 -442
  465. package/packages/crouter-api/dist/core/canvas/deliveries.js +0 -402
  466. package/packages/crouter-api/dist/core/canvas/delivery-contract.js +0 -30
  467. package/packages/crouter-api/dist/core/canvas/executions.js +0 -270
  468. package/packages/crouter-api/dist/core/canvas/extensions.js +0 -90
  469. package/packages/crouter-api/dist/core/canvas/focuses.js +0 -82
  470. package/packages/crouter-api/dist/core/canvas/history.js +0 -480
  471. package/packages/crouter-api/dist/core/canvas/index.js +0 -16
  472. package/packages/crouter-api/dist/core/canvas/install-id.js +0 -64
  473. package/packages/crouter-api/dist/core/canvas/labels.js +0 -43
  474. package/packages/crouter-api/dist/core/canvas/legacy-person.js +0 -4
  475. package/packages/crouter-api/dist/core/canvas/memory-reads.js +0 -37
  476. package/packages/crouter-api/dist/core/canvas/meta-file.js +0 -89
  477. package/packages/crouter-api/dist/core/canvas/nav-render.js +0 -224
  478. package/packages/crouter-api/dist/core/canvas/node-agent-paths.js +0 -30
  479. package/packages/crouter-api/dist/core/canvas/node-order.js +0 -37
  480. package/packages/crouter-api/dist/core/canvas/node-recap.js +0 -62
  481. package/packages/crouter-api/dist/core/canvas/node-tokens.js +0 -53
  482. package/packages/crouter-api/dist/core/canvas/outcome-actions.js +0 -71
  483. package/packages/crouter-api/dist/core/canvas/person.js +0 -239
  484. package/packages/crouter-api/dist/core/canvas/reconciler-leases.js +0 -44
  485. package/packages/crouter-api/dist/core/canvas/recovery.js +0 -715
  486. package/packages/crouter-api/dist/core/canvas/remote-canvas-source.js +0 -290
  487. package/packages/crouter-api/dist/core/canvas/remote-transport.js +0 -57
  488. package/packages/crouter-api/dist/core/canvas/render-source.js +0 -518
  489. package/packages/crouter-api/dist/core/canvas/schema-chain.js +0 -110
  490. package/packages/crouter-api/dist/core/canvas/schema-version.js +0 -58
  491. package/packages/crouter-api/dist/core/canvas/sessions.js +0 -128
  492. package/packages/crouter-api/dist/core/canvas/source.js +0 -57
  493. package/packages/crouter-api/dist/core/canvas/status-glyph.js +0 -147
  494. package/packages/crouter-api/dist/core/canvas/structured-requests.js +0 -176
  495. package/packages/crouter-api/dist/core/canvas/telemetry.js +0 -35
  496. package/packages/crouter-api/dist/core/canvas/tree.js +0 -150
  497. package/packages/crouter-api/dist/core/canvas/types.js +0 -6
  498. package/packages/crouter-api/dist/core/canvas/waits.js +0 -113
  499. package/packages/crouter-api/dist/core/canvas/worktrees.js +0 -97
  500. package/packages/crouter-api/dist/core/checkout-identities.js +0 -107
  501. package/packages/crouter-api/dist/core/clipboard-text.js +0 -57
  502. package/packages/crouter-api/dist/core/command-hooks/artifact.js +0 -145
  503. package/packages/crouter-api/dist/core/command-hooks/catalog.js +0 -38
  504. package/packages/crouter-api/dist/core/command-hooks/compose.js +0 -101
  505. package/packages/crouter-api/dist/core/command-hooks/discovery.js +0 -246
  506. package/packages/crouter-api/dist/core/command-hooks/help.js +0 -18
  507. package/packages/crouter-api/dist/core/command-hooks/lifecycle-catalog.js +0 -9
  508. package/packages/crouter-api/dist/core/command-hooks/lifecycle-create.js +0 -51
  509. package/packages/crouter-api/dist/core/command-hooks/report.js +0 -28
  510. package/packages/crouter-api/dist/core/command-hooks/schema.js +0 -157
  511. package/packages/crouter-api/dist/core/command-hooks/transport/exec-invoke.js +0 -315
  512. package/packages/crouter-api/dist/core/command-hooks/transport/exec-lifecycle.js +0 -248
  513. package/packages/crouter-api/dist/core/command-hooks/transport/plan.js +0 -30
  514. package/packages/crouter-api/dist/core/command-manifests/registry.js +0 -118
  515. package/packages/crouter-api/dist/core/command-plugins/caller-header.js +0 -15
  516. package/packages/crouter-api/dist/core/command-plugins/compose.js +0 -263
  517. package/packages/crouter-api/dist/core/command-plugins/discovery.js +0 -240
  518. package/packages/crouter-api/dist/core/command-plugins/extensions.js +0 -166
  519. package/packages/crouter-api/dist/core/command-plugins/help-addenda.js +0 -55
  520. package/packages/crouter-api/dist/core/command-plugins/presence.js +0 -36
  521. package/packages/crouter-api/dist/core/command-plugins/transport/exec-invoke.js +0 -138
  522. package/packages/crouter-api/dist/core/command-plugins/transport/http-fetch.js +0 -68
  523. package/packages/crouter-api/dist/core/command-plugins/transport/http-invoke.js +0 -333
  524. package/packages/crouter-api/dist/core/command-plugins/transport/http-plan.js +0 -349
  525. package/packages/crouter-api/dist/core/command-plugins/transport/sign.js +0 -115
  526. package/packages/crouter-api/dist/core/command.js +0 -896
  527. package/packages/crouter-api/dist/core/conversation-store/row-store.js +0 -420
  528. package/packages/crouter-api/dist/core/directory/issuer.js +0 -15
  529. package/packages/crouter-api/dist/core/directory/person-credential.js +0 -237
  530. package/packages/crouter-api/dist/core/directory/reach.js +0 -19
  531. package/packages/crouter-api/dist/core/document-lines.js +0 -6
  532. package/packages/crouter-api/dist/core/editor-resolver.js +0 -77
  533. package/packages/crouter-api/dist/core/environment-recipe.js +0 -62
  534. package/packages/crouter-api/dist/core/environment-starter-script.js +0 -64
  535. package/packages/crouter-api/dist/core/environments.js +0 -24
  536. package/packages/crouter-api/dist/core/events/outbound.js +0 -92
  537. package/packages/crouter-api/dist/core/events/read.js +0 -625
  538. package/packages/crouter-api/dist/core/fault-classifier.js +0 -101
  539. package/packages/crouter-api/dist/core/feed/feed.js +0 -190
  540. package/packages/crouter-api/dist/core/feed/inbox.js +0 -93
  541. package/packages/crouter-api/dist/core/feed/messages.js +0 -234
  542. package/packages/crouter-api/dist/core/feed/reports.js +0 -58
  543. package/packages/crouter-api/dist/core/frontmatter.js +0 -35
  544. package/packages/crouter-api/dist/core/git.js +0 -103
  545. package/packages/crouter-api/dist/core/grants/cover.js +0 -66
  546. package/packages/crouter-api/dist/core/grants/hosted-endpoint.js +0 -70
  547. package/packages/crouter-api/dist/core/grants/local.js +0 -26
  548. package/packages/crouter-api/dist/core/grants/mirror.js +0 -506
  549. package/packages/crouter-api/dist/core/grants/on-sync.js +0 -163
  550. package/packages/crouter-api/dist/core/grants/owner.js +0 -21
  551. package/packages/crouter-api/dist/core/grants/shadow.js +0 -128
  552. package/packages/crouter-api/dist/core/grants/sync.js +0 -220
  553. package/packages/crouter-api/dist/core/grants/terminal.js +0 -25
  554. package/packages/crouter-api/dist/core/graph/access.js +0 -37
  555. package/packages/crouter-api/dist/core/graph/bodies.js +0 -68
  556. package/packages/crouter-api/dist/core/graph/custom.js +0 -298
  557. package/packages/crouter-api/dist/core/graph/deletion.js +0 -115
  558. package/packages/crouter-api/dist/core/graph/documents.js +0 -663
  559. package/packages/crouter-api/dist/core/graph/edges.js +0 -83
  560. package/packages/crouter-api/dist/core/graph/events.js +0 -432
  561. package/packages/crouter-api/dist/core/graph/exposures.js +0 -164
  562. package/packages/crouter-api/dist/core/graph/jobs.js +0 -184
  563. package/packages/crouter-api/dist/core/graph/kinds/action.js +0 -20
  564. package/packages/crouter-api/dist/core/graph/kinds/custom.js +0 -23
  565. package/packages/crouter-api/dist/core/graph/kinds/document.js +0 -115
  566. package/packages/crouter-api/dist/core/graph/kinds/dto.js +0 -20
  567. package/packages/crouter-api/dist/core/graph/kinds/environment.js +0 -19
  568. package/packages/crouter-api/dist/core/graph/kinds/job.js +0 -22
  569. package/packages/crouter-api/dist/core/graph/kinds/kind.js +0 -15
  570. package/packages/crouter-api/dist/core/graph/kinds/node.js +0 -85
  571. package/packages/crouter-api/dist/core/graph/kinds/owner.js +0 -24
  572. package/packages/crouter-api/dist/core/graph/kinds/registry.js +0 -58
  573. package/packages/crouter-api/dist/core/graph/kinds/render.js +0 -17
  574. package/packages/crouter-api/dist/core/graph/names.js +0 -225
  575. package/packages/crouter-api/dist/core/graph/objects.js +0 -277
  576. package/packages/crouter-api/dist/core/graph/package-docs.js +0 -153
  577. package/packages/crouter-api/dist/core/graph/package-files.js +0 -146
  578. package/packages/crouter-api/dist/core/graph/package-publish.js +0 -165
  579. package/packages/crouter-api/dist/core/graph/package-reconcile.js +0 -99
  580. package/packages/crouter-api/dist/core/graph/reader.js +0 -315
  581. package/packages/crouter-api/dist/core/graph/receiver-url.js +0 -83
  582. package/packages/crouter-api/dist/core/graph/receivers.js +0 -66
  583. package/packages/crouter-api/dist/core/graph/repo-sync/identity.js +0 -147
  584. package/packages/crouter-api/dist/core/graph/repo-sync/repos.js +0 -134
  585. package/packages/crouter-api/dist/core/graph/rules.js +0 -144
  586. package/packages/crouter-api/dist/core/graph/types.js +0 -10
  587. package/packages/crouter-api/dist/core/graph/watches.js +0 -223
  588. package/packages/crouter-api/dist/core/human/action-binding.js +0 -41
  589. package/packages/crouter-api/dist/core/human/answer-text.js +0 -100
  590. package/packages/crouter-api/dist/core/human/answer.js +0 -119
  591. package/packages/crouter-api/dist/core/human/completion.js +0 -27
  592. package/packages/crouter-api/dist/core/human/component-docs.js +0 -442
  593. package/packages/crouter-api/dist/core/human/convention.js +0 -75
  594. package/packages/crouter-api/dist/core/human/feedback-companion.js +0 -92
  595. package/packages/crouter-api/dist/core/human/feedback.js +0 -88
  596. package/packages/crouter-api/dist/core/human/page-authoring.js +0 -19
  597. package/packages/crouter-api/dist/core/human/page-errors.js +0 -14
  598. package/packages/crouter-api/dist/core/human/page-eval.js +0 -125
  599. package/packages/crouter-api/dist/core/human/page-html-markdown.js +0 -260
  600. package/packages/crouter-api/dist/core/human/page-markdown.js +0 -291
  601. package/packages/crouter-api/dist/core/human/page-schema.js +0 -381
  602. package/packages/crouter-api/dist/core/human/page.js +0 -251
  603. package/packages/crouter-api/dist/core/human/request-files.js +0 -54
  604. package/packages/crouter-api/dist/core/human/requests.js +0 -647
  605. package/packages/crouter-api/dist/core/human/root.js +0 -11
  606. package/packages/crouter-api/dist/core/human/summary.js +0 -5
  607. package/packages/crouter-api/dist/core/human/tickets.js +0 -166
  608. package/packages/crouter-api/dist/core/human/types.js +0 -1
  609. package/packages/crouter-api/dist/core/human/visible-paths.js +0 -74
  610. package/packages/crouter-api/dist/core/human-actions.js +0 -101
  611. package/packages/crouter-api/dist/core/import/bundle/blob-keys.js +0 -25
  612. package/packages/crouter-api/dist/core/import/bundle/layout.js +0 -111
  613. package/packages/crouter-api/dist/core/import/export/archive.js +0 -22
  614. package/packages/crouter-api/dist/core/import/export/cloud.js +0 -175
  615. package/packages/crouter-api/dist/core/import/export/dump.js +0 -245
  616. package/packages/crouter-api/dist/core/import/export/files.js +0 -169
  617. package/packages/crouter-api/dist/core/import/export/inline.js +0 -15
  618. package/packages/crouter-api/dist/core/import/export/source.js +0 -5
  619. package/packages/crouter-api/dist/core/import/export/stores.js +0 -73
  620. package/packages/crouter-api/dist/core/import/load/catalog.js +0 -70
  621. package/packages/crouter-api/dist/core/import/load/copy.js +0 -173
  622. package/packages/crouter-api/dist/core/import/load/keys.js +0 -77
  623. package/packages/crouter-api/dist/core/import/load/prepare.js +0 -262
  624. package/packages/crouter-api/dist/core/import/load/rewrite.js +0 -314
  625. package/packages/crouter-api/dist/core/import/load/stage.js +0 -99
  626. package/packages/crouter-api/dist/core/inspector/chrome.js +0 -14
  627. package/packages/crouter-api/dist/core/inspector/contract.js +0 -1
  628. package/packages/crouter-api/dist/core/inspector/core.js +0 -296
  629. package/packages/crouter-api/dist/core/inspector/host.js +0 -538
  630. package/packages/crouter-api/dist/core/inspector/model.js +0 -225
  631. package/packages/crouter-api/dist/core/inspector/text.js +0 -45
  632. package/packages/crouter-api/dist/core/inspector/transport.js +0 -36
  633. package/packages/crouter-api/dist/core/inspector/tui.js +0 -295
  634. package/packages/crouter-api/dist/core/keybindings/background-bash.js +0 -33
  635. package/packages/crouter-api/dist/core/keybindings/inbox.js +0 -25
  636. package/packages/crouter-api/dist/core/keybindings/index.js +0 -7
  637. package/packages/crouter-api/dist/core/keybindings/match.js +0 -146
  638. package/packages/crouter-api/dist/core/keybindings/persistence.js +0 -47
  639. package/packages/crouter-api/dist/core/keybindings/resolve.js +0 -348
  640. package/packages/crouter-api/dist/core/ledger/account.js +0 -13
  641. package/packages/crouter-api/dist/core/ledger/charges.js +0 -44
  642. package/packages/crouter-api/dist/core/ledger/check.js +0 -40
  643. package/packages/crouter-api/dist/core/ledger/chunks.js +0 -47
  644. package/packages/crouter-api/dist/core/ledger/environment-payer.js +0 -15
  645. package/packages/crouter-api/dist/core/ledger/index.js +0 -11
  646. package/packages/crouter-api/dist/core/ledger/infra-allowance.js +0 -31
  647. package/packages/crouter-api/dist/core/ledger/limits.js +0 -35
  648. package/packages/crouter-api/dist/core/ledger/months.js +0 -19
  649. package/packages/crouter-api/dist/core/ledger/payer.js +0 -23
  650. package/packages/crouter-api/dist/core/ledger/read.js +0 -211
  651. package/packages/crouter-api/dist/core/ledger/totals.js +0 -34
  652. package/packages/crouter-api/dist/core/ledger/types.js +0 -2
  653. package/packages/crouter-api/dist/core/llm/app-rungs.js +0 -64
  654. package/packages/crouter-api/dist/core/llm/body-limits.js +0 -7
  655. package/packages/crouter-api/dist/core/llm/owner-candidates.js +0 -79
  656. package/packages/crouter-api/dist/core/llm/refusal.js +0 -22
  657. package/packages/crouter-api/dist/core/llm/run.js +0 -571
  658. package/packages/crouter-api/dist/core/logged-step-timings.js +0 -52
  659. package/packages/crouter-api/dist/core/manifest-stale.js +0 -39
  660. package/packages/crouter-api/dist/core/model-auth/api-credential-store.js +0 -49
  661. package/packages/crouter-api/dist/core/model-auth/daemon-login.js +0 -156
  662. package/packages/crouter-api/dist/core/model-auth/readiness.js +0 -83
  663. package/packages/crouter-api/dist/core/model-routes-pool.js +0 -57
  664. package/packages/crouter-api/dist/core/model-routes.js +0 -212
  665. package/packages/crouter-api/dist/core/northlight/previews.js +0 -87
  666. package/packages/crouter-api/dist/core/nvim-launch.js +0 -45
  667. package/packages/crouter-api/dist/core/output.js +0 -99
  668. package/packages/crouter-api/dist/core/packages/eligibility.js +0 -34
  669. package/packages/crouter-api/dist/core/packages/launch-kinds.js +0 -20
  670. package/packages/crouter-api/dist/core/packages/source-url.js +0 -17
  671. package/packages/crouter-api/dist/core/pagination.js +0 -88
  672. package/packages/crouter-api/dist/core/peer/client.js +0 -168
  673. package/packages/crouter-api/dist/core/peer/directory.js +0 -193
  674. package/packages/crouter-api/dist/core/peer/envelope.js +0 -99
  675. package/packages/crouter-api/dist/core/peer/names.js +0 -8
  676. package/packages/crouter-api/dist/core/peer/outbox-store.js +0 -84
  677. package/packages/crouter-api/dist/core/peer/receiver.js +0 -54
  678. package/packages/crouter-api/dist/core/peer/stubs.js +0 -212
  679. package/packages/crouter-api/dist/core/peer/token.js +0 -30
  680. package/packages/crouter-api/dist/core/peer/version.js +0 -23
  681. package/packages/crouter-api/dist/core/permissions/builtin.js +0 -29
  682. package/packages/crouter-api/dist/core/permissions/ceiling.js +0 -345
  683. package/packages/crouter-api/dist/core/permissions/compile.js +0 -175
  684. package/packages/crouter-api/dist/core/permissions/errors.js +0 -13
  685. package/packages/crouter-api/dist/core/permissions/evaluator.js +0 -139
  686. package/packages/crouter-api/dist/core/permissions/facts.js +0 -102
  687. package/packages/crouter-api/dist/core/permissions/schema-parser.js +0 -151
  688. package/packages/crouter-api/dist/core/permissions/schemas.js +0 -83
  689. package/packages/crouter-api/dist/core/permissions/sql.js +0 -31
  690. package/packages/crouter-api/dist/core/plugin-app.js +0 -58
  691. package/packages/crouter-api/dist/core/plugin-quarantine.js +0 -70
  692. package/packages/crouter-api/dist/core/pool-credential-store.js +0 -135
  693. package/packages/crouter-api/dist/core/predicate.js +0 -191
  694. package/packages/crouter-api/dist/core/preview-registry.js +0 -399
  695. package/packages/crouter-api/dist/core/profiles/default-binding.js +0 -29
  696. package/packages/crouter-api/dist/core/profiles/deletion-reservation.js +0 -42
  697. package/packages/crouter-api/dist/core/profiles/select.js +0 -750
  698. package/packages/crouter-api/dist/core/provider-credential.js +0 -17
  699. package/packages/crouter-api/dist/core/provider-error-recognition.js +0 -82
  700. package/packages/crouter-api/dist/core/provider-failure.js +0 -166
  701. package/packages/crouter-api/dist/core/provider-management.js +0 -9
  702. package/packages/crouter-api/dist/core/providers/approval.js +0 -146
  703. package/packages/crouter-api/dist/core/providers/audit.js +0 -52
  704. package/packages/crouter-api/dist/core/providers/bundles.js +0 -643
  705. package/packages/crouter-api/dist/core/providers/call.js +0 -503
  706. package/packages/crouter-api/dist/core/providers/description.js +0 -1
  707. package/packages/crouter-api/dist/core/providers/device-libs.js +0 -202
  708. package/packages/crouter-api/dist/core/providers/device.js +0 -95
  709. package/packages/crouter-api/dist/core/providers/errors.js +0 -137
  710. package/packages/crouter-api/dist/core/providers/files.js +0 -461
  711. package/packages/crouter-api/dist/core/providers/inflight.js +0 -14
  712. package/packages/crouter-api/dist/core/providers/mint.js +0 -248
  713. package/packages/crouter-api/dist/core/providers/receipts.js +0 -50
  714. package/packages/crouter-api/dist/core/providers/request.js +0 -173
  715. package/packages/crouter-api/dist/core/providers/roots.js +0 -118
  716. package/packages/crouter-api/dist/core/providers/token-cache.js +0 -203
  717. package/packages/crouter-api/dist/core/remote-canvas-target.js +0 -30
  718. package/packages/crouter-api/dist/core/review/anchors.js +0 -91
  719. package/packages/crouter-api/dist/core/review/comments.js +0 -277
  720. package/packages/crouter-api/dist/core/review/companion.js +0 -207
  721. package/packages/crouter-api/dist/core/review/document.js +0 -71
  722. package/packages/crouter-api/dist/core/review/project.js +0 -46
  723. package/packages/crouter-api/dist/core/review/store.js +0 -178
  724. package/packages/crouter-api/dist/core/review/types.js +0 -23
  725. package/packages/crouter-api/dist/core/runs/activity.js +0 -57
  726. package/packages/crouter-api/dist/core/runs/events.js +0 -179
  727. package/packages/crouter-api/dist/core/runs/initial-input.js +0 -27
  728. package/packages/crouter-api/dist/core/runs/node-sub.js +0 -10
  729. package/packages/crouter-api/dist/core/runs/operations.js +0 -800
  730. package/packages/crouter-api/dist/core/runs/questions.js +0 -151
  731. package/packages/crouter-api/dist/core/runtime/banner.js +0 -53
  732. package/packages/crouter-api/dist/core/runtime/bearings-render.js +0 -284
  733. package/packages/crouter-api/dist/core/runtime/bearings.js +0 -208
  734. package/packages/crouter-api/dist/core/runtime/bin-contributions.js +0 -186
  735. package/packages/crouter-api/dist/core/runtime/blaxel-environment.js +0 -17
  736. package/packages/crouter-api/dist/core/runtime/broker/bash-job-launch.js +0 -65
  737. package/packages/crouter-api/dist/core/runtime/broker/model-adapter.js +0 -453
  738. package/packages/crouter-api/dist/core/runtime/broker/read-ops.js +0 -174
  739. package/packages/crouter-api/dist/core/runtime/broker/turn-cause.js +0 -44
  740. package/packages/crouter-api/dist/core/runtime/broker-ownership.js +0 -6
  741. package/packages/crouter-api/dist/core/runtime/broker-protocol.js +0 -166
  742. package/packages/crouter-api/dist/core/runtime/broker-request.js +0 -86
  743. package/packages/crouter-api/dist/core/runtime/broker-sdk.js +0 -130
  744. package/packages/crouter-api/dist/core/runtime/broker-wedge.js +0 -97
  745. package/packages/crouter-api/dist/core/runtime/canvas-extensions.js +0 -100
  746. package/packages/crouter-api/dist/core/runtime/close.js +0 -266
  747. package/packages/crouter-api/dist/core/runtime/command-expansion.js +0 -104
  748. package/packages/crouter-api/dist/core/runtime/command-surface.js +0 -117
  749. package/packages/crouter-api/dist/core/runtime/crtr-theme.js +0 -146
  750. package/packages/crouter-api/dist/core/runtime/deliver-live.js +0 -85
  751. package/packages/crouter-api/dist/core/runtime/fault-recovery.js +0 -72
  752. package/packages/crouter-api/dist/core/runtime/fault.js +0 -17
  753. package/packages/crouter-api/dist/core/runtime/fleet.js +0 -75
  754. package/packages/crouter-api/dist/core/runtime/focus-viewer.js +0 -151
  755. package/packages/crouter-api/dist/core/runtime/front-door-env.js +0 -16
  756. package/packages/crouter-api/dist/core/runtime/headless-pi.js +0 -176
  757. package/packages/crouter-api/dist/core/runtime/host.js +0 -717
  758. package/packages/crouter-api/dist/core/runtime/interactive-deliver.js +0 -51
  759. package/packages/crouter-api/dist/core/runtime/invocation.js +0 -10
  760. package/packages/crouter-api/dist/core/runtime/kickoff.js +0 -263
  761. package/packages/crouter-api/dist/core/runtime/launch-prompt.js +0 -13
  762. package/packages/crouter-api/dist/core/runtime/launch-recipe.js +0 -45
  763. package/packages/crouter-api/dist/core/runtime/launch-target.js +0 -87
  764. package/packages/crouter-api/dist/core/runtime/launch.js +0 -505
  765. package/packages/crouter-api/dist/core/runtime/ledger.js +0 -55
  766. package/packages/crouter-api/dist/core/runtime/lifecycle.js +0 -286
  767. package/packages/crouter-api/dist/core/runtime/managed-provider-cooling.js +0 -62
  768. package/packages/crouter-api/dist/core/runtime/memory-admission.js +0 -68
  769. package/packages/crouter-api/dist/core/runtime/model-registry.js +0 -13
  770. package/packages/crouter-api/dist/core/runtime/model-selection.js +0 -135
  771. package/packages/crouter-api/dist/core/runtime/model-swap.js +0 -76
  772. package/packages/crouter-api/dist/core/runtime/naming.js +0 -300
  773. package/packages/crouter-api/dist/core/runtime/nerd-font.js +0 -162
  774. package/packages/crouter-api/dist/core/runtime/nodes.js +0 -506
  775. package/packages/crouter-api/dist/core/runtime/outcome-document.js +0 -86
  776. package/packages/crouter-api/dist/core/runtime/output-result.js +0 -32
  777. package/packages/crouter-api/dist/core/runtime/output-schema-refs.js +0 -100
  778. package/packages/crouter-api/dist/core/runtime/package-health.js +0 -100
  779. package/packages/crouter-api/dist/core/runtime/persona.js +0 -54
  780. package/packages/crouter-api/dist/core/runtime/pi-cli.js +0 -65
  781. package/packages/crouter-api/dist/core/runtime/pi-vendored.js +0 -63
  782. package/packages/crouter-api/dist/core/runtime/placement-tmux.js +0 -81
  783. package/packages/crouter-api/dist/core/runtime/placement.js +0 -418
  784. package/packages/crouter-api/dist/core/runtime/progress-bar.js +0 -50
  785. package/packages/crouter-api/dist/core/runtime/provider-credential-gate.js +0 -48
  786. package/packages/crouter-api/dist/core/runtime/recovery-hold.js +0 -46
  787. package/packages/crouter-api/dist/core/runtime/reopen.js +0 -165
  788. package/packages/crouter-api/dist/core/runtime/revive-all.js +0 -108
  789. package/packages/crouter-api/dist/core/runtime/revive.js +0 -762
  790. package/packages/crouter-api/dist/core/runtime/roadmap.js +0 -86
  791. package/packages/crouter-api/dist/core/runtime/runner/blaxel/client.js +0 -150
  792. package/packages/crouter-api/dist/core/runtime/runner/blaxel/image-build.js +0 -280
  793. package/packages/crouter-api/dist/core/runtime/runner/blaxel/release-image.js +0 -97
  794. package/packages/crouter-api/dist/core/runtime/runner/blaxel/runner.js +0 -214
  795. package/packages/crouter-api/dist/core/runtime/runner/delete-sandboxes.js +0 -88
  796. package/packages/crouter-api/dist/core/runtime/runner/index.js +0 -37
  797. package/packages/crouter-api/dist/core/runtime/runner/machine/call.js +0 -110
  798. package/packages/crouter-api/dist/core/runtime/runner/machine/environment.js +0 -7
  799. package/packages/crouter-api/dist/core/runtime/runner/machine/executor.js +0 -235
  800. package/packages/crouter-api/dist/core/runtime/runner/machine/ops.js +0 -37
  801. package/packages/crouter-api/dist/core/runtime/runner/machine/runner.js +0 -72
  802. package/packages/crouter-api/dist/core/runtime/runner/process.js +0 -70
  803. package/packages/crouter-api/dist/core/runtime/runner/types.js +0 -16
  804. package/packages/crouter-api/dist/core/runtime/session-branch.js +0 -16
  805. package/packages/crouter-api/dist/core/runtime/session-cycles.js +0 -144
  806. package/packages/crouter-api/dist/core/runtime/session-list-cache.js +0 -302
  807. package/packages/crouter-api/dist/core/runtime/session-visibility.js +0 -99
  808. package/packages/crouter-api/dist/core/runtime/setup-marker.js +0 -46
  809. package/packages/crouter-api/dist/core/runtime/situational-context.js +0 -54
  810. package/packages/crouter-api/dist/core/runtime/situational-live.js +0 -41
  811. package/packages/crouter-api/dist/core/runtime/spawn-env-rows.js +0 -15
  812. package/packages/crouter-api/dist/core/runtime/spawn-env.js +0 -260
  813. package/packages/crouter-api/dist/core/runtime/spawn.js +0 -867
  814. package/packages/crouter-api/dist/core/runtime/stamp/protocol.js +0 -113
  815. package/packages/crouter-api/dist/core/runtime/start-check.js +0 -43
  816. package/packages/crouter-api/dist/core/runtime/stop-guard.js +0 -150
  817. package/packages/crouter-api/dist/core/runtime/stop-signals.js +0 -46
  818. package/packages/crouter-api/dist/core/runtime/structured-output.js +0 -112
  819. package/packages/crouter-api/dist/core/runtime/surface-bg.js +0 -85
  820. package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +0 -738
  821. package/packages/crouter-api/dist/core/runtime/tmux-chrome.js +0 -5
  822. package/packages/crouter-api/dist/core/runtime/tmux-driver.js +0 -706
  823. package/packages/crouter-api/dist/core/runtime/unsandboxed.js +0 -18
  824. package/packages/crouter-api/dist/core/runtime/view-socket.js +0 -195
  825. package/packages/crouter-api/dist/core/runtime/warm-pool.js +0 -479
  826. package/packages/crouter-api/dist/core/scoped-state/person-rows.js +0 -185
  827. package/packages/crouter-api/dist/core/scopes.js +0 -48
  828. package/packages/crouter-api/dist/core/secrets/blaxel-launch.js +0 -104
  829. package/packages/crouter-api/dist/core/secrets/env-rows.js +0 -40
  830. package/packages/crouter-api/dist/core/secrets/environment-owner.js +0 -31
  831. package/packages/crouter-api/dist/core/secrets/environment-secrets.js +0 -14
  832. package/packages/crouter-api/dist/core/secrets/index.js +0 -2
  833. package/packages/crouter-api/dist/core/secrets/key.js +0 -33
  834. package/packages/crouter-api/dist/core/secrets/seal.js +0 -43
  835. package/packages/crouter-api/dist/core/secrets.js +0 -137
  836. package/packages/crouter-api/dist/core/self-update.js +0 -77
  837. package/packages/crouter-api/dist/core/session-model/session-state.js +0 -180
  838. package/packages/crouter-api/dist/core/shell-segments.js +0 -169
  839. package/packages/crouter-api/dist/core/spaces/cache-env.js +0 -15
  840. package/packages/crouter-api/dist/core/spaces/file-root.js +0 -68
  841. package/packages/crouter-api/dist/core/spaces/mounts.js +0 -126
  842. package/packages/crouter-api/dist/core/spaces/permissions.js +0 -83
  843. package/packages/crouter-api/dist/core/spaces/process.js +0 -175
  844. package/packages/crouter-api/dist/core/spaces/runtime-home.js +0 -8
  845. package/packages/crouter-api/dist/core/spaces/space.js +0 -58
  846. package/packages/crouter-api/dist/core/spaces/stop.js +0 -138
  847. package/packages/crouter-api/dist/core/spaces/users.js +0 -43
  848. package/packages/crouter-api/dist/core/sqlite-statements.js +0 -17
  849. package/packages/crouter-api/dist/core/statements.js +0 -81
  850. package/packages/crouter-api/dist/core/step-timings.js +0 -63
  851. package/packages/crouter-api/dist/core/storage/attachments.js +0 -141
  852. package/packages/crouter-api/dist/core/storage/caller-file.js +0 -84
  853. package/packages/crouter-api/dist/core/storage/client.js +0 -220
  854. package/packages/crouter-api/dist/core/storage/media-types.js +0 -22
  855. package/packages/crouter-api/dist/core/storage/node-transfer.js +0 -100
  856. package/packages/crouter-api/dist/core/storage/purge.js +0 -55
  857. package/packages/crouter-api/dist/core/storage/tables.js +0 -129
  858. package/packages/crouter-api/dist/core/subscription-state.js +0 -470
  859. package/packages/crouter-api/dist/core/substrate/delivery/corpus.js +0 -239
  860. package/packages/crouter-api/dist/core/substrate/delivery/deliver.js +0 -370
  861. package/packages/crouter-api/dist/core/substrate/delivery/listings.js +0 -75
  862. package/packages/crouter-api/dist/core/substrate/delivery/match.js +0 -146
  863. package/packages/crouter-api/dist/core/substrate/delivery/plan.js +0 -132
  864. package/packages/crouter-api/dist/core/substrate/delivery/render-boot.js +0 -330
  865. package/packages/crouter-api/dist/core/substrate/delivery/render-event.js +0 -186
  866. package/packages/crouter-api/dist/core/substrate/delivery/sub-persona-menu.js +0 -24
  867. package/packages/crouter-api/dist/core/substrate/delivery/types.js +0 -1
  868. package/packages/crouter-api/dist/core/substrate/gate-explain.js +0 -397
  869. package/packages/crouter-api/dist/core/substrate/schema.js +0 -81
  870. package/packages/crouter-api/dist/core/substrate/subject-fields.js +0 -39
  871. package/packages/crouter-api/dist/core/substrate/subject.js +0 -60
  872. package/packages/crouter-api/dist/core/termrender/display.js +0 -56
  873. package/packages/crouter-api/dist/core/termrender/termrender.js +0 -719
  874. package/packages/crouter-api/dist/core/termrender/version.js +0 -1
  875. package/packages/crouter-api/dist/core/timing.js +0 -108
  876. package/packages/crouter-api/dist/core/tui/draw.js +0 -378
  877. package/packages/crouter-api/dist/core/tui/fuzzy.js +0 -38
  878. package/packages/crouter-api/dist/core/tui/markdown.js +0 -407
  879. package/packages/crouter-api/dist/core/tui/page-host.js +0 -74
  880. package/packages/crouter-api/dist/core/tui/panel.js +0 -142
  881. package/packages/crouter-api/dist/core/tui/terminal.js +0 -100
  882. package/packages/crouter-api/dist/core/wake.js +0 -296
  883. package/packages/crouter-api/dist/core/worktree-close.js +0 -205
  884. package/packages/crouter-api/dist/core/worktree-containment.js +0 -48
  885. package/packages/crouter-api/dist/core/worktree-landing.js +0 -8
  886. package/packages/crouter-api/dist/core/worktree-machine.js +0 -112
  887. package/packages/crouter-api/dist/core/worktree-mutation-async.js +0 -393
  888. package/packages/crouter-api/dist/core/worktree-remove.js +0 -84
  889. package/packages/crouter-api/dist/core/worktree-scripts.js +0 -72
  890. package/packages/crouter-api/dist/core/worktree-sweep.js +0 -448
  891. package/packages/crouter-api/dist/core/worktree.js +0 -844
  892. package/packages/crouter-api/dist/daemon/api/deferred-head.js +0 -117
  893. package/packages/crouter-api/dist/daemon/api/environment-of.js +0 -67
  894. package/packages/crouter-api/dist/daemon/api/handlers/bash-jobs.js +0 -352
  895. package/packages/crouter-api/dist/daemon/api/handlers/broker-ops.js +0 -705
  896. package/packages/crouter-api/dist/daemon/api/handlers/broker-recovery.js +0 -266
  897. package/packages/crouter-api/dist/daemon/api/handlers/execution-start.js +0 -120
  898. package/packages/crouter-api/dist/daemon/api/handlers/git-credential.js +0 -76
  899. package/packages/crouter-api/dist/daemon/api/handlers/node-records.js +0 -113
  900. package/packages/crouter-api/dist/daemon/api/handlers/providers.js +0 -290
  901. package/packages/crouter-api/dist/daemon/api/handlers/telemetry-record.js +0 -34
  902. package/packages/crouter-api/dist/daemon/api/handlers/validate.js +0 -58
  903. package/packages/crouter-api/dist/daemon/api/map.js +0 -750
  904. package/packages/crouter-api/dist/daemon/api/operations.js +0 -325
  905. package/packages/crouter-api/dist/daemon/api/principal.js +0 -166
  906. package/packages/crouter-api/dist/daemon/api/reader.js +0 -133
  907. package/packages/crouter-api/dist/daemon/api/router.js +0 -568
  908. package/packages/crouter-api/dist/daemon/api/sync-notice.js +0 -46
  909. package/packages/crouter-api/dist/daemon/api/viewer-presence.js +0 -100
  910. package/packages/crouter-api/dist/daemon/companion-retire.js +0 -44
  911. package/packages/crouter-api/dist/daemon/control.js +0 -22
  912. package/packages/crouter-api/dist/daemon/cron/armed-context.js +0 -140
  913. package/packages/crouter-api/dist/daemon/cron/authority.js +0 -101
  914. package/packages/crouter-api/dist/daemon/cron/capture.js +0 -50
  915. package/packages/crouter-api/dist/daemon/cron/closed.js +0 -108
  916. package/packages/crouter-api/dist/daemon/cron/disposition.js +0 -63
  917. package/packages/crouter-api/dist/daemon/cron/ended.js +0 -91
  918. package/packages/crouter-api/dist/daemon/cron/escalation.js +0 -136
  919. package/packages/crouter-api/dist/daemon/cron/held.js +0 -20
  920. package/packages/crouter-api/dist/daemon/cron/live-runs.js +0 -65
  921. package/packages/crouter-api/dist/daemon/cron/machine-fire.js +0 -240
  922. package/packages/crouter-api/dist/daemon/cron/narrowed.js +0 -34
  923. package/packages/crouter-api/dist/daemon/cron/recurrence.js +0 -38
  924. package/packages/crouter-api/dist/daemon/cron/run-socket.js +0 -170
  925. package/packages/crouter-api/dist/daemon/cron/run-token.js +0 -37
  926. package/packages/crouter-api/dist/daemon/cron/settle.js +0 -78
  927. package/packages/crouter-api/dist/daemon/cron/sinks.js +0 -70
  928. package/packages/crouter-api/dist/daemon/drain.js +0 -76
  929. package/packages/crouter-api/dist/daemon/http-dispatcher.js +0 -37
  930. package/packages/crouter-api/dist/daemon/human/finish.js +0 -179
  931. package/packages/crouter-api/dist/daemon/human/settle.js +0 -98
  932. package/packages/crouter-api/dist/daemon/machine-link/credential.js +0 -24
  933. package/packages/crouter-api/dist/daemon/machine-link/forward.js +0 -201
  934. package/packages/crouter-api/dist/daemon/machine-link/frames.js +0 -33
  935. package/packages/crouter-api/dist/daemon/machine-link/holder.js +0 -395
  936. package/packages/crouter-api/dist/daemon/park-activity.js +0 -33
  937. package/packages/crouter-api/dist/daemon/park-pending.js +0 -76
  938. package/packages/crouter-api/dist/daemon/postgres/binary.js +0 -193
  939. package/packages/crouter-api/dist/daemon/postgres/cluster.js +0 -111
  940. package/packages/crouter-api/dist/daemon/postgres/pins.js +0 -16
  941. package/packages/crouter-api/dist/daemon/postgres/supervisor.js +0 -177
  942. package/packages/crouter-api/dist/daemon/readiness.js +0 -37
  943. package/packages/crouter-api/dist/daemon/reconcilers/broker-supervision.js +0 -746
  944. package/packages/crouter-api/dist/daemon/reconcilers/ledger-sandbox.js +0 -249
  945. package/packages/crouter-api/dist/daemon/reconcilers/live-obligation.js +0 -125
  946. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/launch-failure.js +0 -8
  947. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/node-person.js +0 -40
  948. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +0 -166
  949. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/respawn-policy.js +0 -59
  950. package/packages/crouter-api/dist/daemon/reconcilers/recipe-image.js +0 -204
  951. package/packages/crouter-api/dist/daemon/reconcilers/throttled-lane.js +0 -63
  952. package/packages/crouter-api/dist/daemon/review/companion.js +0 -29
  953. package/packages/crouter-api/dist/daemon/review/deliver.js +0 -14
  954. package/packages/crouter-api/dist/daemon/review/finish.js +0 -149
  955. package/packages/crouter-api/dist/daemon/runs/append-section.js +0 -129
  956. package/packages/crouter-api/dist/daemon/runs/observer.js +0 -440
  957. package/packages/crouter-api/dist/daemon/runs/view-transport.js +0 -81
  958. package/packages/crouter-api/dist/daemon/structured-requests/sidecar.js +0 -5
  959. package/packages/crouter-api/dist/hook-authoring.js +0 -447
  960. package/packages/crouter-api/dist/hook-process.js +0 -34
  961. package/packages/crouter-api/dist/launcher/limits/settings.js +0 -94
  962. package/packages/crouter-api/dist/migrations/004-canvas-documents/fields.js +0 -52
  963. package/packages/crouter-api/dist/shared/git-status.js +0 -44
  964. package/packages/crouter-api/dist/shared/inline-ref-grammar.js +0 -99
  965. package/packages/crouter-api/dist/shared/shell-quote.js +0 -5
  966. package/packages/crouter-api/dist/shared/strip-cd-prefix.js +0 -13
  967. package/packages/crouter-api/dist/shared/tool-groups.js +0 -64
  968. package/packages/crouter-api/dist/shared/traceparent.js +0 -28
  969. package/packages/crouter-api/dist/shared/turn-replies.js +0 -66
@@ -1,1260 +0,0 @@
1
- // The canvas data-access layer. Nodes, their sessions, executions, and managed
2
- // worktrees are SQL-authoritative. Node directories hold only artifacts.
3
- import { parsePrincipal } from '@north-light/identity';
4
- import { loadExactProfileManifest } from '../profiles/manifest.js';
5
- import { envNodeId } from '../../shared/env.js';
6
- import { lstatSync, realpathSync, rmdirSync, rmSync, statSync } from 'node:fs';
7
- import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
8
- import { removeTreeBeneath } from '../spaces/open-beneath.js';
9
- import { emitEvent } from '../events/emit.js';
10
- import { deleteNodeSandboxes } from '../runtime/runner/delete-sandboxes.js';
11
- import { withCanvasWrite, openDb } from './db.js';
12
- import { conversationStore, ConversationNotFoundError } from '../conversation-store/index.js';
13
- import { hasUnseenWakeMail, UNSEEN_WAKE_MAIL_SQL } from './deliveries.js';
14
- import { isAppRun } from './app-run.js';
15
- import { registerOutcomeAction } from './outcome-actions.js';
16
- import { publish } from '../graph/events.js';
17
- import { nodeObject } from '../graph/objects.js';
18
- import { findNodeBySessionFileSql } from './sessions.js';
19
- import { hydrateFault } from './recovery.js';
20
- import { hasUnreconciledWorktree, openWorktree, readWorktree, worktreeFromRow } from './worktrees.js';
21
- import { isPidAlive, isPidPresent, recordedPidLiveness } from './pid.js';
22
- import { isCloudRole } from './person-state.js';
23
- import { ensureHome, jobDir, nodeDir, nodeRunDir } from './paths.js';
24
- import { appForNode, ensureNodeDirs, nodeAgentDir } from './node-agent-paths.js';
25
- import { appSpace } from '../layout.js';
26
- import { createObject, getById, ownerForGrantee, setObjectKind, setObjectName } from '../graph/objects.js';
27
- import { profileObject } from '../graph/reader.js';
28
- import { writeActsFor } from '../permissions/facts.js';
29
- import { CrtrError } from '../errors.js';
30
- import { deleteNodeWithOwned } from '../graph/deletion.js';
31
- import { SUBTREE_ALL_IDS_SQL, SUBTREE_IDS_SQL } from './tree.js';
32
- import { filterAsync, mapAsync } from '../async-array.js';
33
- function jsonValue(value, field) {
34
- if (value === undefined || value === null)
35
- return null;
36
- const encoded = JSON.stringify(value);
37
- if (encoded === undefined)
38
- throw new TypeError(`${field} must be JSON-serializable`);
39
- return encoded;
40
- }
41
- export async function assertRunNotDeleting(db, runId) {
42
- if ((await db.prepare('SELECT deleting_at FROM nodes WHERE node_id = ?').get(runId))?.deleting_at)
43
- throw new Error('run is deleting');
44
- }
45
- /** The profile's object (made on first use), or null when the profile has no stored manifest to name one from, or belongs to another app than
46
- * `app`: a run an app starts in another app's profile stays under its own app, so the app that started it (and its person) reads it. */
47
- async function profileObjectFor(db, profileId, app, grantee) {
48
- try {
49
- if ((loadExactProfileManifest(profileId).manifest.grantee ?? 'app:terminal') !== grantee)
50
- return null;
51
- return await profileObject(db, profileId, app);
52
- }
53
- catch (e) {
54
- if (e instanceof CrtrError && e.code === 'not_found')
55
- return null;
56
- throw e;
57
- }
58
- }
59
- async function seedRow(meta, db) {
60
- const app = await ownerForGrantee(db, meta.grantee ?? 'app:terminal');
61
- // The node sits under its profile's object when it has one; otherwise directly under its app.
62
- const profile = meta.profile_id ? await profileObjectFor(db, meta.profile_id, app, meta.grantee ?? 'app:terminal') : null;
63
- await createObject(db, { id: meta.node_id, type: 'node', kind: meta.kind, owner: (profile ?? app).id, privacy: 'public', name: meta.name, preview: '' });
64
- // A node directly under an app is readable by the person it was made for.
65
- if (profile === null && meta.sub && parsePrincipal(meta.sub)?.kind === 'user')
66
- await writeActsFor(db, meta.node_id, meta.sub);
67
- await db.prepare(`INSERT INTO nodes (node_id, description, title, icon, cycles, mode, lifecycle, cwd, host_kind, profile_id, parent, spawned_by, creator, fork_from, fork_source_file, created, passive_default, cycle_pending, model_override, persona_ack_json, review_binding_json, launch_config_json, scopes_json, isolated, status, intent, final_report, finalized_at, deadline_at, "window", tmux_session, pane, sub, grant_id, client_id, metadata_json, run_id, event_cursor, deleting_at, caused_by, app) VALUES (${Array(41).fill('?').join(', ')})`)
68
- .run(meta.node_id, meta.description ?? null, meta.title ?? null, meta.icon ?? null, meta.cycles ?? null, meta.mode, meta.lifecycle, meta.cwd, meta.host_kind ?? null, meta.profile_id ?? null, meta.parent ?? null, meta.spawned_by ?? null, meta.creator ?? null, meta.fork_from ?? null, meta.fork_source_file ?? null, meta.created, meta.passive_default === true ? 1 : 0, meta.cycle_pending === true ? 1 : 0, meta.model_override ?? null, jsonValue(meta.persona_ack, 'persona_ack'), jsonValue(meta.review_binding, 'review_binding'), jsonValue(meta.launch, 'launch'), jsonValue(meta.scopes, 'scopes'), meta.isolated === true ? 1 : 0, meta.status ?? 'active', meta.intent ?? null, meta.final_report ?? null, meta.finalized_at ?? null, meta.deadline_at ?? null, meta.window ?? null, meta.tmux_session ?? null, meta.pane ?? null, meta.sub ?? null, meta.grant_id ?? null, meta.client_id ?? null, meta.metadata_json ?? null, meta.run_id ?? null, meta.event_cursor ?? null, meta.deleting_at ?? null, meta.caused_by ?? null, app.id);
69
- }
70
- /** The `node_rows` view projects the active fault's columns under a `fault_`
71
- * prefix; strip it and hydrate through the same mapper `readFault` uses. */
72
- function faultFrom(r) {
73
- if (r['fault_id'] == null)
74
- return null;
75
- const columns = Object.entries(r).filter(([key]) => key.startsWith('fault_')).map(([key, value]) => [key === 'fault_id' ? key : key.slice('fault_'.length), value]);
76
- return hydrateFault(Object.fromEntries(columns));
77
- }
78
- /** `node_rows` joins the turn columns from the node's execution that has not exited, so both are null without one. */
79
- const turnOpen = (r) => r['turn_open_at'] != null && r['turn_closed_at'] == null;
80
- /** Whether the engine behind an open turn is alive. A cloud role never hosts a broker (it runs on a Mac or in a sandbox),
81
- * so a pid probe on this host always fails there and the execution row is the only liveness record. */
82
- const engineLive = (pidPresentHere) => pidPresentHere || isCloudRole();
83
- /** The `node_rows` columns `rowFrom` reads. Whole-table scans select these, never `*`: the view also carries each node's
84
- * initial prompt, launch config and tool summaries (about 60 KB per finished node in prod), which no `NodeRow` holds. */
85
- const NODE_ROW_COLUMNS = `node_id, name, description, cycles, kind, mode, lifecycle, status, cwd, host_kind, profile_id, scopes_json, isolated,
86
- grantee, sub, grant_id, client_id, metadata_json, run_id, event_cursor, last_activity_at, caused_by, last_turn_error_json, deleting_at,
87
- parent, created, intent, cycle_pending, frozen_at, respawn_failures, respawn_not_before, launched_at, last_settled_at, terminal_reason,
88
- final_report, finalized_at, outcome_kind, outcome_reason, outcome_at, outcome_revision, outcome_detail_json, deadline_at,
89
- telemetry_tokens_in, telemetry_context_tokens, telemetry_last_activity, telemetry_updated_at, pi_pid, pi_pid_identity,
90
- "window", tmux_session, pane, turn_open_at, turn_closed_at,
91
- fault_id, fault_link, fault_op, fault_kind, fault_message, fault_since, fault_operation_id, fault_anchor_entry_id,
92
- fault_retry_disposition, fault_retry_by, fault_retry_attempt, fault_retry_max, fault_retry_next_at, fault_provider_error_json`;
93
- function rowFrom(r) {
94
- const node = {
95
- node_id: r['node_id'],
96
- name: r['name'],
97
- description: r['description'] ?? undefined,
98
- cycles: r['cycles'] ?? undefined,
99
- kind: r['kind'],
100
- mode: r['mode'],
101
- lifecycle: r['lifecycle'],
102
- status: r['status'],
103
- cwd: r['cwd'],
104
- host_kind: r['host_kind'] ?? null,
105
- profile_id: r['profile_id'] ?? null,
106
- scopes: r['scopes_json'] == null ? null : JSON.parse(r['scopes_json']),
107
- isolated: r['isolated'] === 1,
108
- grantee: r['grantee'],
109
- sub: r['sub'] ?? null,
110
- grant_id: r['grant_id'] ?? null,
111
- client_id: r['client_id'] ?? null,
112
- metadata_json: r['metadata_json'] ?? null,
113
- run_id: r['run_id'] ?? null,
114
- event_cursor: r['event_cursor'] ?? null,
115
- last_activity_at: r['last_activity_at'] ?? null,
116
- caused_by: r['caused_by'] ?? null,
117
- last_turn_error_json: r['last_turn_error_json'] ?? null,
118
- deleting_at: r['deleting_at'] ?? null,
119
- parent: r['parent'] ?? null,
120
- created: r['created'],
121
- intent: r['intent'] ?? null,
122
- cycle_pending: r['cycle_pending'] === 1,
123
- frozen_at: r['frozen_at'] ?? null,
124
- respawn_failures: r['respawn_failures'] ?? 0,
125
- respawn_not_before: r['respawn_not_before'] ?? null,
126
- launched_at: r['launched_at'] ?? null,
127
- last_settled_at: r['last_settled_at'] ?? null,
128
- terminal_reason: r['terminal_reason'] ?? null,
129
- final_report: r['final_report'] ?? null,
130
- finalized_at: r['finalized_at'] ?? null,
131
- outcome_kind: r['outcome_kind'] ?? null,
132
- outcome_reason: r['outcome_reason'] ?? null,
133
- outcome_at: r['outcome_at'] ?? null,
134
- outcome_revision: r['outcome_revision'] ?? 0,
135
- outcome_detail_json: r['outcome_detail_json'] ?? null,
136
- deadline_at: r['deadline_at'] ?? null,
137
- telemetry_tokens_in: r['telemetry_tokens_in'] ?? null,
138
- telemetry_context_tokens: r['telemetry_context_tokens'] ?? null,
139
- telemetry_last_activity: r['telemetry_last_activity'] ?? null,
140
- telemetry_updated_at: r['telemetry_updated_at'] ?? null,
141
- pi_pid: r['pi_pid'] ?? null,
142
- pi_pid_identity: r['pi_pid_identity'] ?? null,
143
- window: r['window'] ?? null,
144
- tmux_session: r['tmux_session'] ?? null,
145
- pane: r['pane'] ?? null,
146
- fault: null,
147
- streaming: false,
148
- };
149
- const pidAlive = isPidPresent(node.pi_pid);
150
- const fault = faultFrom(r);
151
- node.fault = fault?.link === 'pi→provider' && fault.retry.by === 'daemon' && fault.retry.disposition === 'auto' && !pidAlive
152
- ? null
153
- : fault;
154
- node.streaming = turnOpen(r) && engineLive(pidAlive);
155
- return node;
156
- }
157
- async function metaFrom(r, worktree) {
158
- worktree ??= await readWorktree(r['node_id']);
159
- return {
160
- ...rowFrom(r),
161
- title: r['title'] ?? undefined,
162
- icon: r['icon'] ?? undefined,
163
- spawned_by: r['spawned_by'] ?? null,
164
- creator: r['creator'] ?? null,
165
- fork_from: r['fork_from'] ?? null,
166
- fork_source_file: r['fork_source_file'] ?? null,
167
- passive_default: r['passive_default'] === 1,
168
- model_override: r['model_override'] ?? null,
169
- scopes: r['scopes_json'] == null ? null : JSON.parse(r['scopes_json']),
170
- persona_ack: r['persona_ack_json'] == null ? undefined : JSON.parse(r['persona_ack_json']),
171
- review_binding: r['review_binding_json'] == null ? undefined : JSON.parse(r['review_binding_json']),
172
- launch: r['launch_config_json'] == null ? undefined : JSON.parse(r['launch_config_json']),
173
- pi_session_id: r['pi_session_id'] ?? null,
174
- pi_session_file: r['pi_session_file'] ?? null,
175
- ...(worktree === null ? {} : { managed_worktree: worktree }),
176
- };
177
- }
178
- // Nodes
179
- /** Create a SQL-authoritative node, then ensure its artifact directories exist. */
180
- export async function createNode(meta, opts = {}) {
181
- ensureHome();
182
- await withCanvasWrite(async (db) => {
183
- await seedRow(meta, db);
184
- if (meta.managed_worktree !== undefined && meta.managed_worktree !== null)
185
- await openWorktree(meta.node_id, meta.managed_worktree, db);
186
- if (opts.outcomeDelivery !== undefined)
187
- await registerOutcomeAction(db, meta.node_id, opts.outcomeDelivery);
188
- await opts.withinCreate?.(db, meta);
189
- });
190
- await ensureNodeDirs(meta.node_id);
191
- return await getNode(meta.node_id);
192
- }
193
- /** The canonical node record, hydrated from SQL. Null if unknown. */
194
- export async function getNode(nodeId) {
195
- const row = await (await openDb()).prepare('SELECT * FROM node_rows WHERE node_id = ?').get(nodeId);
196
- if (row === undefined)
197
- return null;
198
- return await metaFrom(row);
199
- }
200
- /** The canonical node records for `nodeIds` in the order given, read with their worktrees in one query. Unknown ids are skipped. */
201
- export async function getNodes(nodeIds) {
202
- if (nodeIds.length === 0)
203
- return [];
204
- const worktreeProjection = WORKTREE_COLUMNS.map((column) => `w.${column} AS worktree_${column}`).join(', ');
205
- const rows = await (await openDb())
206
- .prepareUncached(`SELECT n.*, ${worktreeProjection} FROM node_rows n LEFT JOIN worktrees w ON w.node_id = n.node_id WHERE n.node_id IN (${nodeIds.map(() => '?').join(',')})`)
207
- .all(...nodeIds);
208
- const byId = new Map(rows.map((row) => [row['node_id'], row]));
209
- return await mapAsync(nodeIds.map((id) => byId.get(id)).filter((row) => row !== undefined), async (row) => await metaFrom(row, worktreeFromProjection(row)));
210
- }
211
- const CREATE_REQUEST_TTL_MS = 24 * 60 * 60 * 1000;
212
- function createRequestRecord(row) {
213
- return { requestKey: row.request_key, nodeId: row.node_id, state: row.state };
214
- }
215
- export async function findCreateRequest(requestKey) {
216
- const existing = await (await openDb()).prepareUncached('SELECT request_key, node_id, state FROM create_requests WHERE request_key = ?').get(requestKey);
217
- return existing === undefined ? null : createRequestRecord(existing);
218
- }
219
- /** Reserve an idempotency key before creation. A null node id means the request
220
- * has not yet selected a cold-birth identity or claimed a warm spare. */
221
- export async function reserveCreateRequest(requestKey) {
222
- return await withCanvasWrite(async (db) => {
223
- const now = Date.now();
224
- await db.prepareUncached('DELETE FROM create_requests WHERE expires_at <= ?').run(now);
225
- // One atomic claim: a concurrent reservation of the same key (another process) waits on the first insert, does nothing,
226
- // and then reads the row that won.
227
- await db.prepareUncached("INSERT INTO create_requests (request_key, node_id, expires_at, state) VALUES (?, NULL, ?, 'reserved') ON CONFLICT (request_key) DO NOTHING")
228
- .run(requestKey, now + CREATE_REQUEST_TTL_MS);
229
- const winner = await db.prepareUncached('SELECT request_key, node_id, state FROM create_requests WHERE request_key = ?').get(requestKey);
230
- return createRequestRecord(winner);
231
- });
232
- }
233
- /** Delete keys past their recovery window; returns how many were removed. */
234
- export async function pruneExpiredCreateRequests(now = Date.now()) {
235
- return Number((await (await openDb()).prepareUncached('DELETE FROM create_requests WHERE expires_at <= ?').run(now)).changes);
236
- }
237
- /** Bind a reserved key to the node it created (state `complete`). The mapping is
238
- * durable so a retry after a daemon handover returns the original node. */
239
- export async function recordCreateRequestNode(requestKey, nodeId) {
240
- await (await openDb()).prepareUncached("UPDATE create_requests SET node_id = ?, state = 'complete' WHERE request_key = ?").run(nodeId, requestKey);
241
- }
242
- /** Reserve a cold-birth node id for a key (state stays `reserved`) so a retry
243
- * after a daemon restart resumes the same identity instead of minting another.
244
- * Only the first caller binds: two API processes holding one unbound key race
245
- * here, and each gets back the id the key actually names. */
246
- export async function reserveCreateRequestNode(requestKey, nodeId, owner) {
247
- const db = await openDb();
248
- await db.prepareUncached("UPDATE create_requests SET node_id = ?, state = 'reserved', lease_owner = ?, lease_expires_at = ? WHERE request_key = ? AND node_id IS NULL")
249
- .run(nodeId, owner, Date.now() + CREATE_LEASE_MS, requestKey);
250
- const bound = await db.prepareUncached('SELECT node_id FROM create_requests WHERE request_key = ?').get(requestKey);
251
- return bound?.node_id ?? null;
252
- }
253
- /** How long a create's lease lasts without renewal; its owner renews it every {@link CREATE_LEASE_RENEW_MS}. */
254
- export const CREATE_LEASE_MS = 30_000;
255
- export const CREATE_LEASE_RENEW_MS = 10_000;
256
- /** Take over a bound, unfinished create whose owner's lease has lapsed (or never existed). True when `owner` now holds it. */
257
- export async function claimCreateLease(requestKey, nodeId, owner) {
258
- const now = Date.now();
259
- const result = await (await openDb()).prepareUncached("UPDATE create_requests SET lease_owner = ?, lease_expires_at = ? WHERE request_key = ? AND node_id = ? AND state = 'reserved' AND (lease_expires_at IS NULL OR lease_expires_at <= ?)")
260
- .run(owner, now + CREATE_LEASE_MS, requestKey, nodeId, now);
261
- return Number(result.changes) > 0;
262
- }
263
- /** Extend the lease while `owner` still holds it. */
264
- export async function renewCreateLease(requestKey, owner) {
265
- await (await openDb()).prepareUncached('UPDATE create_requests SET lease_expires_at = ? WHERE request_key = ? AND lease_owner = ?')
266
- .run(Date.now() + CREATE_LEASE_MS, requestKey, owner);
267
- }
268
- /** Whether another owner's lease on the key is still unexpired. */
269
- export async function createLeaseLive(requestKey) {
270
- const row = await (await openDb()).prepareUncached('SELECT lease_expires_at FROM create_requests WHERE request_key = ?').get(requestKey);
271
- return row?.lease_expires_at != null && Number(row.lease_expires_at) > Date.now();
272
- }
273
- export async function completeCreateRequest(requestKey, nodeId) {
274
- await (await openDb()).prepareUncached("UPDATE create_requests SET state = 'complete' WHERE request_key = ? AND node_id = ?").run(requestKey, nodeId);
275
- }
276
- /** Forget an unserved reservation after a pre-birth failure. A record that
277
- * names a durable node is never removed by this path. */
278
- export async function abandonCreateRequest(requestKey, nodeId) {
279
- await withCanvasWrite(async (db) => {
280
- if (nodeId === null) {
281
- await db.prepareUncached('DELETE FROM create_requests WHERE request_key = ? AND node_id IS NULL').run(requestKey);
282
- return;
283
- }
284
- await db.prepareUncached('DELETE FROM create_requests WHERE request_key = ? AND node_id = ?').run(requestKey, nodeId);
285
- });
286
- }
287
- export function canonicalSessionFile(sessionFile) {
288
- return resolve(sessionFile);
289
- }
290
- /** Resolve the crouter node that owns one exact Pi session file. */
291
- export async function findNodeBySessionFile(sessionFile) {
292
- const nodeId = await findNodeBySessionFileSql(sessionFile);
293
- return nodeId === null ? null : await getNode(nodeId);
294
- }
295
- /** The indexed row (from the db) — cheap for queries that don't need full meta. */
296
- export async function getRow(nodeId) {
297
- const r = await (await openDb()).prepare('SELECT * FROM node_rows WHERE node_id = ?').get(nodeId);
298
- return r ? rowFrom(r) : null;
299
- }
300
- /** The node row whose durable LOCATION pane is `pane`, or null. Lets placement
301
- * resolve "who sits in this pane" by the first-class `%pane_id` handle (e.g.
302
- * to adopt a caller's pane as a focus). pane is not UNIQUE in the schema, but a
303
- * live pane backs at most one node, so this returns the single match. */
304
- export async function getRowByPane(pane) {
305
- const r = await (await openDb()).prepare('SELECT * FROM node_rows WHERE pane = ?').get(pane);
306
- return r ? rowFrom(r) : null;
307
- }
308
- /** Nodes whose persisted spawn deadline has elapsed and that remain live work. */
309
- export async function dueNodeDeadlines(nowIso) {
310
- return (await (await openDb()).prepare(`SELECT * FROM node_rows
311
- WHERE deadline_at IS NOT NULL AND outcome_at IS NULL
312
- AND deadline_at <= ? AND status IN ('active','idle') AND kind != 'human'
313
- ORDER BY deadline_at, created, node_id`).all(nowIso)).map(rowFrom);
314
- }
315
- /** Write a claimed warm spare's deadline before it is handed to its caller. */
316
- export async function setNodeDeadline(nodeId, deadlineAt) {
317
- return Number((await (await openDb()).prepare('UPDATE nodes SET deadline_at = ? WHERE node_id = ?').run(deadlineAt, nodeId)).changes) === 1;
318
- }
319
- /** Shift active/idle profile deadlines by a completed profile pause duration. */
320
- export async function shiftProfileNodeDeadlines(profileId, pauseDurationMs) {
321
- if (!Number.isFinite(pauseDurationMs) || pauseDurationMs <= 0)
322
- return 0;
323
- return await withCanvasWrite(async (db) => {
324
- const rows = await db.prepare(`SELECT node_id, deadline_at FROM nodes
325
- WHERE profile_id = ? AND deadline_at IS NOT NULL AND status IN ('active', 'idle')`).all(profileId);
326
- const update = db.prepare('UPDATE nodes SET deadline_at = ? WHERE node_id = ? AND deadline_at = ?');
327
- let shifted = 0;
328
- for (const row of rows) {
329
- const at = Date.parse(row.deadline_at);
330
- if (Number.isNaN(at))
331
- continue;
332
- shifted += Number((await update.run(new Date(at + pauseDurationMs).toISOString(), row.node_id, row.deadline_at)).changes);
333
- }
334
- return shifted;
335
- });
336
- }
337
- function sqlInput(value, field) {
338
- if (value === null || value === undefined)
339
- return null;
340
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint' || value instanceof Uint8Array)
341
- return value;
342
- throw new TypeError(`${field} must be a SQLite scalar`);
343
- }
344
- /** Update node identity/configuration columns. Sessions and worktrees have named stores. */
345
- export async function updateNode(nodeId, patch) {
346
- const fields = [];
347
- const add = (key, column = key) => {
348
- if (Object.prototype.hasOwnProperty.call(patch, key))
349
- fields.push([column, sqlInput(patch[key], key)]);
350
- };
351
- add('description');
352
- add('title');
353
- add('icon');
354
- add('cycles');
355
- add('mode');
356
- add('lifecycle');
357
- add('cwd');
358
- add('host_kind');
359
- add('profile_id');
360
- add('parent');
361
- add('spawned_by');
362
- add('creator');
363
- add('fork_from');
364
- add('fork_source_file');
365
- add('model_override');
366
- if (Object.prototype.hasOwnProperty.call(patch, 'passive_default'))
367
- fields.push(['passive_default', patch.passive_default === true ? 1 : 0]);
368
- if (Object.prototype.hasOwnProperty.call(patch, 'cycle_pending'))
369
- fields.push(['cycle_pending', patch.cycle_pending === true ? 1 : 0]);
370
- if (Object.prototype.hasOwnProperty.call(patch, 'persona_ack'))
371
- fields.push(['persona_ack_json', jsonValue(patch.persona_ack, 'persona_ack')]);
372
- if (Object.prototype.hasOwnProperty.call(patch, 'review_binding'))
373
- fields.push(['review_binding_json', jsonValue(patch.review_binding, 'review_binding')]);
374
- // Isolation is fixed at birth; updateNode must never weaken it.
375
- if (Object.prototype.hasOwnProperty.call(patch, 'isolated'))
376
- throw new TypeError('isolated cannot change after node creation');
377
- if (Object.prototype.hasOwnProperty.call(patch, 'scopes'))
378
- fields.push(['scopes_json', jsonValue(patch.scopes, 'scopes')]);
379
- if (Object.prototype.hasOwnProperty.call(patch, 'launch'))
380
- fields.push(['launch_config_json', jsonValue(patch.launch, 'launch')]);
381
- const has = (key) => Object.prototype.hasOwnProperty.call(patch, key);
382
- await withCanvasWrite(async (db) => {
383
- const object = await getById(db, nodeId);
384
- if (object === null || object.type !== 'node')
385
- throw new Error(`unknown node: ${nodeId}`);
386
- if (has('name'))
387
- await setObjectName(db, object, sqlInput(patch.name, 'name'));
388
- if (has('kind'))
389
- await setObjectKind(db, object, sqlInput(patch.kind, 'kind'));
390
- if (fields.length === 0)
391
- return;
392
- // A profile change moves the node under the new profile's object, or back under its app when it has none.
393
- if (has('profile_id')) {
394
- const app = await db.prepare('SELECT app FROM nodes WHERE node_id = ?').get(nodeId);
395
- const appObject = app?.app ? await getById(db, app.app) : null;
396
- if (appObject) {
397
- const profile = patch.profile_id ? await profileObjectFor(db, patch.profile_id, appObject, `app:${appObject.name}`) : null;
398
- await db.prepare('UPDATE objects SET owner = ? WHERE id = ?').run((profile ?? appObject).id, nodeId);
399
- const sub = (await db.prepare('SELECT sub FROM nodes WHERE node_id = ?').get(nodeId)).sub;
400
- if (profile === null && sub)
401
- await writeActsFor(db, nodeId, sub);
402
- }
403
- }
404
- const result = await db.prepareUncached(`UPDATE nodes SET ${fields.map(([column]) => `${column} = ?`).join(', ')} WHERE node_id = ?`).run(...fields.map(([, value]) => value), nodeId);
405
- if (result.changes !== 1)
406
- throw new Error(`unknown node: ${nodeId}`);
407
- });
408
- return await getNode(nodeId);
409
- }
410
- // Atomic runtime setters — each one a single-statement UPDATE on the WAL'd row,
411
- // the authoritative store for live state. No read-modify-write, so concurrent
412
- // writers of DIFFERENT fields (the daemon stamping pi_pid while a node flips
413
- // status) can never clobber each other: WAL serializes the two statements.
414
- // `"window"` is quoted defensively — it is a SQLite keyword.
415
- /** Set a node's status. Atomic single-column write. */
416
- export async function setStatus(nodeId, status) {
417
- await (await openDb()).prepare('UPDATE nodes SET status = ? WHERE node_id = ?').run(status, nodeId);
418
- }
419
- /** Set a node's exit intent. Atomic single-column write. */
420
- export async function setIntent(nodeId, intent) {
421
- await (await openDb()).prepare('UPDATE nodes SET intent = ? WHERE node_id = ?').run(intent ?? null, nodeId);
422
- }
423
- /** Atomically write status and/or intent, gated on an optional from-status set
424
- * and/or on the row carrying no committed final_report. The lifecycle state
425
- * machine (runtime/lifecycle.ts) is the one caller: it owns the legality
426
- * table and the unknown-node/illegal-move/already-finalized-cancel branching,
427
- * this only performs the single conditional UPDATE it needs. A PRESENT key in
428
- * `fields` (even `intent: null`) writes that column; an ABSENT key leaves it
429
- * unchanged. Returns the row-changed count so the caller can distinguish "no
430
- * such node", "gate failed", and "already applied" without a second query. */
431
- export async function transitionStatusIntent(nodeId, fields, opts = {}) {
432
- // Keep the ordinary lifecycle write exactly as its pre-outcome form: one
433
- // conditional UPDATE and no transaction boundary.
434
- if (opts.outcome === undefined) {
435
- const assignments = [];
436
- const values = [];
437
- if (Object.prototype.hasOwnProperty.call(fields, 'status')) {
438
- assignments.push('status = ?');
439
- values.push(fields.status ?? null);
440
- }
441
- if (Object.prototype.hasOwnProperty.call(fields, 'intent')) {
442
- assignments.push('intent = ?');
443
- values.push(fields.intent ?? null);
444
- }
445
- if (Object.prototype.hasOwnProperty.call(fields, 'terminal_reason')) {
446
- assignments.push('terminal_reason = ?');
447
- values.push(fields.terminal_reason ?? null);
448
- }
449
- const predicates = ['node_id = ?'];
450
- values.push(nodeId);
451
- if (opts.fromStatuses !== undefined) {
452
- predicates.push(`status IN (${opts.fromStatuses.map(() => '?').join(', ')})`);
453
- values.push(...opts.fromStatuses);
454
- }
455
- if (opts.requireNoFinalReport === true)
456
- predicates.push('final_report IS NULL');
457
- const result = await (await openDb())
458
- .prepareUncached(`UPDATE nodes SET ${assignments.join(', ')} WHERE ${predicates.join(' AND ')}`)
459
- .run(...values);
460
- return Number(result.changes);
461
- }
462
- const outcome = opts.outcome;
463
- return await withCanvasWrite(async (db) => {
464
- const assignments = [];
465
- const values = [];
466
- if (Object.prototype.hasOwnProperty.call(fields, 'status')) {
467
- assignments.push('status = ?');
468
- values.push(fields.status ?? null);
469
- }
470
- if (Object.prototype.hasOwnProperty.call(fields, 'intent')) {
471
- assignments.push('intent = ?');
472
- values.push(fields.intent ?? null);
473
- }
474
- if (Object.prototype.hasOwnProperty.call(fields, 'terminal_reason')) {
475
- assignments.push('terminal_reason = ?');
476
- values.push(fields.terminal_reason ?? null);
477
- }
478
- const outcomeValue = (value, column) => outcome.supersede === true ? '?' : `CASE WHEN outcome_at IS NULL THEN ? ELSE ${column} END`;
479
- assignments.push(`outcome_kind = ${outcomeValue(outcome.kind, 'outcome_kind')}`, `outcome_reason = ${outcomeValue(outcome.reason, 'outcome_reason')}`, `outcome_detail_json = ${outcomeValue(outcome.detailJson, 'outcome_detail_json')}`, `outcome_revision = ${outcome.supersede === true ? 'outcome_revision + 1' : 'CASE WHEN outcome_at IS NULL THEN outcome_revision + 1 ELSE outcome_revision END'}`, `outcome_at = ${outcomeValue(outcome.at, 'outcome_at')}`);
480
- values.push(outcome.kind, outcome.reason, outcome.detailJson, outcome.at);
481
- const predicates = ['node_id = ?'];
482
- values.push(nodeId);
483
- if (opts.fromStatuses !== undefined) {
484
- predicates.push(`status IN (${opts.fromStatuses.map(() => '?').join(', ')})`);
485
- values.push(...opts.fromStatuses);
486
- }
487
- if (opts.requireNoFinalReport === true)
488
- predicates.push('final_report IS NULL');
489
- const result = await db.prepareUncached(`UPDATE nodes SET ${assignments.join(', ')} WHERE ${predicates.join(' AND ')}`).run(...values);
490
- if (Number(result.changes) === 0)
491
- return 0;
492
- const latched = await db.prepare('SELECT outcome_at FROM nodes WHERE node_id = ?').get(nodeId);
493
- if ((outcome.supersede === true || latched.outcome_at === outcome.at) && outcome.documentJson !== null && outcome.documentJson !== undefined) {
494
- await publish(db, { event: 'outcome', object: await nodeObject(db, nodeId), actor: null,
495
- attrs: { revision: Number((await db.prepare('SELECT outcome_revision FROM nodes WHERE node_id = ?').get(nodeId)).outcome_revision) },
496
- messageBody: JSON.parse(outcome.documentJson) });
497
- }
498
- return Number(result.changes);
499
- });
500
- }
501
- /** Read a node's committed-final latch pointer. Pure read, no side effect. */
502
- export async function getFinalReport(nodeId) {
503
- const row = await (await openDb()).prepare('SELECT final_report FROM nodes WHERE node_id = ?').get(nodeId);
504
- return row?.final_report ?? null;
505
- }
506
- /** CAS-clear a node's finalization latch (final_report + finalized_at) —
507
- * retract-pointer-only. Gated on the exact final_report value the caller
508
- * observed via getFinalReport, so a concurrent clear/refinalize can never be
509
- * clobbered. Returns true iff the CAS matched and cleared. */
510
- export async function clearFinalReportIfMatches(nodeId, expectedFinalReport) {
511
- const result = await (await openDb()).prepare('UPDATE nodes SET final_report = NULL, finalized_at = NULL WHERE node_id = ? AND final_report = ?')
512
- .run(nodeId, expectedFinalReport);
513
- return result.changes > 0;
514
- }
515
- /** Set a node's tmux presence in one atomic write: the durable LOCATION anchor
516
- * `pane` (the `%pane_id`) plus its derived cache (`tmux_session` + `window`).
517
- * All three move together — `pane` joins the others inside the single UPDATE so
518
- * a move never half-writes the location. `pane` is optional: a caller that does
519
- * not yet track it (every caller, until the placement layer lands) writes null,
520
- * which is harmless because nothing reads `pane` yet. */
521
- export async function setPresence(nodeId, presence) {
522
- await (await openDb()).prepare('UPDATE nodes SET tmux_session = ?, "window" = ?, pane = ? WHERE node_id = ?')
523
- .run(presence.tmux_session ?? null, presence.window ?? null, presence.pane ?? null, nodeId);
524
- }
525
- export async function recordLaunch(nodeId, at) {
526
- await (await openDb()).prepare('UPDATE nodes SET launched_at = ?, frozen_at = NULL, respawn_not_before = NULL WHERE node_id = ?')
527
- .run(at, nodeId);
528
- }
529
- export async function recordSettledTurn(nodeId, at) {
530
- await (await openDb()).prepare('UPDATE nodes SET last_settled_at = ? WHERE node_id = ?').run(at, nodeId);
531
- }
532
- export async function setFrozen(nodeId, at) {
533
- await (await openDb()).prepare('UPDATE nodes SET frozen_at = ? WHERE node_id = ?').run(at, nodeId);
534
- }
535
- export async function clearFrozen(nodeId) {
536
- await (await openDb()).prepare('UPDATE nodes SET frozen_at = NULL WHERE node_id = ?').run(nodeId);
537
- }
538
- export async function recordRespawnAttempt(nodeId, attempt) {
539
- await (await openDb()).prepare('UPDATE nodes SET respawn_failures = ?, respawn_not_before = ? WHERE node_id = ?')
540
- .run(attempt.failures, attempt.notBefore, nodeId);
541
- }
542
- /** The one clause that hides unclaimed warm-pool spares from every listing.
543
- * A spare is a real node with a booted broker, but nobody has been handed it
544
- * yet — surfacing it would put a phantom empty conversation in the user's
545
- * sidebar. Claiming deletes the marker, which is what makes the node visible. */
546
- const NOT_A_SPARE = 'node_id NOT IN (SELECT node_id FROM warm_pool)';
547
- /** Every hydrated node whose durable profile identity equals `profileId`.
548
- * Unlike `listNodes`, this includes unclaimed warm-pool spares: profile
549
- * deletion owns every matching row, whether or not it is user-visible. */
550
- const WORKTREE_COLUMNS = [
551
- 'state', 'cleanup_state', 'path', 'branch', 'repo_root', 'base_ref', 'base_sha', 'created_at', 'closed_at',
552
- 'next_attempt_at', 'attempts', 'quarantined', 'sweep_reason', 'sweep_detail', 'sweep_last_at', 'sweep_observed_json',
553
- 'abandoned_json', 'land_intent_json', 'disposal_json',
554
- ];
555
- function worktreeFromProjection(r) {
556
- if (r['worktree_state'] === null)
557
- return null;
558
- return worktreeFromRow(Object.fromEntries(WORKTREE_COLUMNS.map((column) => [column, r[`worktree_${column}`]])));
559
- }
560
- export async function listNodesByProfile(profileId) {
561
- const worktreeProjection = WORKTREE_COLUMNS.map((column) => `w.${column} AS worktree_${column}`).join(', ');
562
- const rows = await (await openDb())
563
- .prepareUncached(`SELECT n.*, ${worktreeProjection} FROM node_rows n LEFT JOIN worktrees w ON w.node_id = n.node_id WHERE n.profile_id = ? ORDER BY n.created`)
564
- .all(profileId);
565
- return (await mapAsync(rows, async (row) => await metaFrom(row, worktreeFromProjection(row))));
566
- }
567
- /** Browse's first frame: select only fields its rows/tree use. Keep the fault and
568
- * turn columns for rowFrom's live fault/streaming semantics, but never hydrate
569
- * outcomes, placement, metadata or the (often large) telemetry activity text. */
570
- export async function browseNodes() {
571
- const db = await openDb();
572
- const rows = await db.prepare(`SELECT
573
- node_id, name, description, kind, mode, lifecycle, status, cwd, profile_id,
574
- grantee, parent, created, frozen_at, terminal_reason, final_report,
575
- telemetry_tokens_in, telemetry_updated_at, pi_pid, turn_open_at, turn_closed_at,
576
- fault_id, fault_link, fault_op, fault_kind, fault_message, fault_since,
577
- fault_operation_id, fault_anchor_entry_id, fault_retry_disposition,
578
- fault_retry_by, fault_retry_attempt, fault_retry_max, fault_retry_next_at,
579
- fault_provider_error_json
580
- FROM node_rows WHERE ${NOT_A_SPARE} ORDER BY created`).all();
581
- return rows.map(rowFrom);
582
- }
583
- /** All rows, optionally filtered by status and terminal execution traces. Unclaimed warm spares are excluded. */
584
- export async function updateNodeTelemetry(nodeId, telemetry) {
585
- await (await openDb()).prepare(`UPDATE nodes
586
- SET telemetry_tokens_in = ?,
587
- telemetry_context_tokens = COALESCE(?, telemetry_context_tokens),
588
- telemetry_last_activity = COALESCE(?, telemetry_last_activity),
589
- telemetry_updated_at = ?
590
- WHERE node_id = ?
591
- AND (telemetry_updated_at IS NULL OR telemetry_updated_at < ?)`).run(telemetry.tokensIn, telemetry.contextTokens, telemetry.lastActivity, telemetry.updatedAt, nodeId, telemetry.updatedAt);
592
- }
593
- /** Stored fields the attach graph displays, plus the two live execution cues it
594
- * needs. This keeps the interactive graph off the full node-summary projection
595
- * and its unused runtime, outcome, and placement fields. */
596
- export async function graphNodes(ids) {
597
- const db = await openDb();
598
- const sql = `SELECT
599
- node_id, name, description, cycles, kind, status, frozen_at,
600
- telemetry_context_tokens, telemetry_last_activity,
601
- pi_pid, turn_open_at, turn_closed_at,
602
- fault_id, fault_link, fault_op, fault_kind, fault_message, fault_since,
603
- fault_operation_id, fault_anchor_entry_id, fault_retry_disposition,
604
- fault_retry_by, fault_retry_attempt, fault_retry_max, fault_retry_next_at,
605
- fault_provider_error_json
606
- FROM node_rows WHERE ${NOT_A_SPARE}${ids === undefined ? '' : ' AND node_id = ANY(?::text[])'} ORDER BY created`;
607
- const rows = (ids === undefined
608
- ? await db.prepare(sql).all()
609
- : await db.prepareUncached(sql).all([...ids]));
610
- return rows.map((row) => {
611
- const pid = row['pi_pid'] ?? null;
612
- const pidAlive = isPidPresent(pid);
613
- const fault = faultFrom(row);
614
- return {
615
- node_id: row['node_id'],
616
- name: row['name'],
617
- description: row['description'] ?? null,
618
- cycles: row['cycles'] ?? null,
619
- kind: row['kind'],
620
- status: row['status'],
621
- frozen_at: row['frozen_at'] ?? null,
622
- pi_pid: pid,
623
- telemetry_context_tokens: row['telemetry_context_tokens'] ?? null,
624
- telemetry_last_activity: row['telemetry_last_activity'] ?? null,
625
- fault: fault?.link === 'pi→provider' && fault.retry.by === 'daemon' && fault.retry.disposition === 'auto' && !pidAlive
626
- ? null
627
- : fault,
628
- streaming: turnOpen(row) && engineLive(pidAlive),
629
- };
630
- });
631
- }
632
- export async function listNodes(filter) {
633
- const clauses = [NOT_A_SPARE];
634
- const params = [];
635
- if (filter?.under !== undefined) {
636
- if (filter.underInclusive === true) {
637
- clauses.push(`(node_id IN (${SUBTREE_ALL_IDS_SQL}) OR node_id = ?)`);
638
- params.push(filter.under, filter.under, filter.under);
639
- }
640
- else {
641
- clauses.push(`node_id IN (${SUBTREE_IDS_SQL})`);
642
- params.push(filter.under, filter.under);
643
- }
644
- }
645
- if (filter?.lifecycle !== undefined) {
646
- clauses.push('lifecycle = ?');
647
- params.push(filter.lifecycle);
648
- }
649
- if (filter?.kind !== undefined) {
650
- clauses.push('kind = ?');
651
- params.push(filter.kind);
652
- }
653
- if (filter?.mode !== undefined) {
654
- clauses.push('mode = ?');
655
- params.push(filter.mode);
656
- }
657
- if (filter?.profileId !== undefined) {
658
- clauses.push('profile_id = ?');
659
- params.push(filter.profileId);
660
- }
661
- if (filter?.profilePrefix !== undefined) {
662
- clauses.push(`profile_id LIKE ? ESCAPE '\\'`);
663
- params.push(`${filter.profilePrefix.replace(/[\\%_]/g, (c) => `\\${c}`)}%`);
664
- }
665
- if (filter?.parent !== undefined) {
666
- clauses.push('parent = ?');
667
- params.push(filter.parent);
668
- }
669
- if (filter?.topLevel === true)
670
- clauses.push('parent IS NULL');
671
- if (filter?.hanging === true)
672
- clauses.push('parent IS NOT NULL AND parent NOT IN (SELECT node_id FROM node_rows)');
673
- if (filter?.status !== undefined) {
674
- const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
675
- clauses.push(`status IN (${statuses.map(() => '?').join(',')})`);
676
- params.push(...statuses);
677
- }
678
- if (filter?.withRecordedPid === true)
679
- clauses.push('pi_pid IS NOT NULL');
680
- if (filter?.withRecordedPidOrFrozen === true)
681
- clauses.push('(pi_pid IS NOT NULL OR frozen_at IS NOT NULL)');
682
- const rows = await (await openDb())
683
- .prepareUncached(`SELECT ${NODE_ROW_COLUMNS} FROM node_rows WHERE ${clauses.join(' AND ')} ORDER BY created`)
684
- .all(...params);
685
- return rows.map(rowFrom);
686
- }
687
- // idx_nodes_terminal_placement_created (a partial index on placement presence)
688
- // keeps this from enumerating every terminal row on old-heavy canvases.
689
- export const terminalPlacementResidueSql = `SELECT
690
- node_id, created, launched_at, last_settled_at, finalized_at,
691
- outcome_at, last_activity_at, pane, "window", tmux_session
692
- FROM nodes
693
- WHERE ${NOT_A_SPARE}
694
- AND status IN ('done', 'canceled', 'dead')
695
- AND (pane IS NOT NULL OR "window" IS NOT NULL OR tmux_session IS NOT NULL)
696
- ORDER BY created`;
697
- export async function listTerminalPlacementResidue() {
698
- return await (await openDb()).prepare(terminalPlacementResidueSql)
699
- .all();
700
- }
701
- /** The daemon's complete supervision set. Live rows participate regardless of
702
- * PID; terminal rows participate only while they retain a PID or freeze mark. */
703
- // Materialize and deduplicate IDs first: the view must use node PK lookups,
704
- // never enumerate its outer historical terminal-status range. The frozen branch
705
- // matches the partial index idx_nodes_supervision_frozen.
706
- export const nodesForSupervisionSql = `WITH candidates AS MATERIALIZED (
707
- SELECT node_id FROM nodes WHERE status IN ('active', 'idle')
708
- UNION
709
- SELECT node_id FROM nodes
710
- WHERE frozen_at IS NOT NULL AND status IN ('done', 'canceled', 'dead')
711
- UNION
712
- SELECT node_id FROM executions
713
- WHERE state != 'exited' AND state = 'running' AND pid IS NOT NULL
714
- )
715
- SELECT ${NODE_ROW_COLUMNS.split(',').map((c) => `v.${c.trim()}`).join(', ')} FROM candidates c CROSS JOIN node_rows v
716
- WHERE v.node_id = c.node_id
717
- AND v.node_id NOT IN (SELECT node_id FROM warm_pool)
718
- AND v.kind != 'human'
719
- AND (v.status IN ('active', 'idle') OR (v.status IN ('done', 'canceled', 'dead') AND (v.pi_pid IS NOT NULL OR v.frozen_at IS NOT NULL)))
720
- ORDER BY v.created`;
721
- export async function listNodesForSupervision() {
722
- const rows = await (await openDb()).prepare(nodesForSupervisionSql)
723
- .all();
724
- return rows.map(rowFrom);
725
- }
726
- /** A parked resident the runtime may reopen when wake mail reaches it: `done` +
727
- * `intent='parked'`, resident, no final latch, and not being deleted. Finalized,
728
- * canceled, dead, terminal-lifecycle and deleting nodes are never reopened by mail.
729
- * The SQL form of `isParkedResident` (runtime/lifecycle.ts), which must change with it; `n` is a `nodes` row. */
730
- export const PARKED_RESIDENT_SQL = (n) => `(${n}.status = 'done' AND ${n}.intent = 'parked' AND ${n}.lifecycle = 'resident' AND ${n}.final_report IS NULL AND ${n}.deleting_at IS NULL)`;
731
- /** A node the runtime can still bring back to life, so its cwd must keep existing: a live row
732
- * (`active`/`idle`), a parked resident the lifecycle tick reopens when wake mail arrives
733
- * (`PARKED_RESIDENT_SQL`), or a terminal row with no final latch that still carries a frozen
734
- * mark, which the tick thaws (`node-lifecycle/tick.ts` `classifyRow`). `n` is a `nodes` row. */
735
- export const RESUMABLE_NODE_SQL = (n) => `(${n}.status IN ('active', 'idle') OR ${PARKED_RESIDENT_SQL(n)} OR (${n}.status IN ('done', 'canceled', 'dead') AND ${n}.frozen_at IS NOT NULL AND ${n}.final_report IS NULL))`;
736
- /** Every resumable node (`RESUMABLE_NODE_SQL`) other than `ownerId`, with the cwd it will run in. */
737
- export async function resumableNodeCwds(ownerId) {
738
- return await (await openDb()).prepare(`SELECT node_id, cwd FROM nodes WHERE ${RESUMABLE_NODE_SQL('nodes')} AND node_id != ?`).all(ownerId);
739
- }
740
- /** Parked residents with unseen wake mail (`UNSEEN_WAKE_MAIL_SQL`), which nothing else
741
- * launches: the lifecycle tick reopens them. Each parked resident seeks its own mail
742
- * through `deliveries_destination`. */
743
- export async function listParkedResidentsWithWakeMail() {
744
- const rows = await (await openDb()).prepare(`SELECT v.* FROM node_rows v
745
- WHERE ${PARKED_RESIDENT_SQL('v')}
746
- AND EXISTS (SELECT 1 FROM deliveries d WHERE d.destination_id = v.node_id AND ${UNSEEN_WAKE_MAIL_SQL('d')}) AND v.kind != 'human' AND v.node_id NOT IN (SELECT node_id FROM warm_pool)
747
- ORDER BY v.created`).all();
748
- return rows.map(rowFrom);
749
- }
750
- // Warm pool — spare booted roots awaiting a `prefer_warm` claim (see
751
- // `runtime/warm-pool.ts` for the recipe key and the mint/refill policy).
752
- /** Mark an already-spawned node as an unclaimed spare for `recipeKey`. Hides it
753
- * from every listing until it is claimed. */
754
- export async function registerWarmSpare(nodeId, recipeKey) {
755
- await (await openDb()).prepare('INSERT INTO warm_pool (node_id, recipe_key, created) VALUES (?, ?, ?) ON CONFLICT (node_id) DO UPDATE SET recipe_key = excluded.recipe_key, created = excluded.created')
756
- .run(nodeId, recipeKey, new Date().toISOString());
757
- }
758
- /** Take a parked spare OUT of the pool without claiming it — the reaper's
759
- * first move. Returns false when the marker was already gone (a concurrent
760
- * claim won it), which is the reaper's signal to leave that node alone: it is
761
- * somebody's live conversation now, not a spare. Deleting the marker under the
762
- * write lock is exactly what `claimWarmSpare` does, so the two can never both
763
- * succeed on the same node. */
764
- export async function unregisterWarmSpare(nodeId) {
765
- return (await (await openDb()).prepare('DELETE FROM warm_pool WHERE node_id = ?').run(nodeId)).changes > 0;
766
- }
767
- async function warmSpareRowsFor(db, recipeKey) {
768
- const sql = `SELECT w.node_id AS node_id, w.recipe_key AS recipe_key, w.created AS created,
769
- n.status AS status, n.pi_pid AS pi_pid, n.pi_pid_identity AS pi_pid_identity
770
- FROM warm_pool w JOIN node_rows n ON n.node_id = w.node_id` +
771
- (recipeKey === undefined ? '' : ' WHERE w.recipe_key = ?') +
772
- ' ORDER BY w.created';
773
- const rows = (recipeKey === undefined ? await db.prepareUncached(sql).all() : await db.prepareUncached(sql).all(recipeKey));
774
- return rows.map((r) => ({
775
- node_id: r['node_id'],
776
- recipe_key: r['recipe_key'],
777
- created: r['created'],
778
- status: r['status'],
779
- pi_pid: r['pi_pid'] ?? null,
780
- pi_pid_identity: r['pi_pid_identity'] ?? null,
781
- }));
782
- }
783
- /** Every parked spare, oldest first — what the reaper (`runtime/warm-pool.ts`
784
- * `reapStaleSpares`) sweeps. Deliberately NOT filtered by liveness: judging a
785
- * spare is the caller's job. */
786
- export async function listWarmSpares() {
787
- return await warmSpareRowsFor(await openDb());
788
- }
789
- /** True while `nodeId` is an UNCLAIMED spare — nobody owns this conversation
790
- * yet. `registerWarmSpare` runs the instant the row exists and BEFORE the
791
- * broker launch, and a claim deletes the marker atomically, so this is a
792
- * reliable read from inside the booting engine (the context-intro extension
793
- * asks it at `session_start` to withhold bearings that would otherwise assert
794
- * the spare's placeholder persona instead of its eventual claimant's). */
795
- export async function isWarmSpare(nodeId) {
796
- const row = await (await openDb()).prepare('SELECT 1 FROM warm_pool WHERE node_id = ?').get(nodeId);
797
- return row !== undefined;
798
- }
799
- /** A spare is claimable only when its broker is CONFIRMED alive. Status alone
800
- * is not enough: a broker torn down by a daemon handover leaves the row at
801
- * `active`/`idle` with a dead pid, and handing that out would answer a create
802
- * with a node that has no engine behind it. The probe is identity-aware, so a
803
- * recycled pid never reads as alive; `indeterminate` (probe failed) is treated
804
- * as not-claimable — a cold spawn is cheap, a broken node is not. */
805
- function spareIsClaimable(row) {
806
- if (row.status !== 'active' && row.status !== 'idle')
807
- return false;
808
- return recordedPidLiveness(row.pi_pid, row.pi_pid_identity) === 'alive';
809
- }
810
- /** Hand out the oldest CLAIMABLE spare matching `recipeKey`, or null when the
811
- * pool has none. The select+delete run inside ONE canvas write-lock
812
- * transaction, so two concurrent creates can never be handed the same spare.
813
- * A spare whose broker is gone is skipped here and reaped by
814
- * `reapStaleSpares` — nothing ever resumes a spare (the daemon's row query
815
- * hides them), so a dead spare is garbage, not a parked one.
816
- *
817
- * The claim also restamps the row's `created` to `created` — birth time is a
818
- * spare's MINT time, and consumers sort conversations on it, so an hour-old
819
- * spare must not sort as an hour-old conversation. This is the one sanctioned
820
- * write of `created` after birth. */
821
- export async function claimWarmSpare(recipeKey, created, opts = {}) {
822
- return await withCanvasWrite(async (db) => {
823
- const row = (await warmSpareRowsFor(db, recipeKey)).find(spareIsClaimable);
824
- if (row === undefined)
825
- return null;
826
- // Bind the key to the spare in the same transaction that takes it, so a
827
- // retry after a handover finishes this spare rather than claiming a second.
828
- if (opts.requestKey !== undefined) {
829
- const bound = await db.prepareUncached("UPDATE create_requests SET node_id = ?, state = 'warm_claimed' WHERE request_key = ? AND node_id IS NULL").run(row.node_id, opts.requestKey);
830
- if (bound.changes === 0)
831
- return null;
832
- }
833
- const res = await db.prepare('DELETE FROM warm_pool WHERE node_id = ?').run(row.node_id);
834
- if (res.changes === 0)
835
- return null;
836
- await db.prepare('UPDATE nodes SET created = ?, deadline_at = ? WHERE node_id = ?')
837
- .run(created, opts.deadlineAt ?? null, row.node_id);
838
- if (opts.outcomeDelivery !== undefined)
839
- await registerOutcomeAction(db, row.node_id, opts.outcomeDelivery);
840
- return row.node_id;
841
- });
842
- }
843
- /** How many CLAIMABLE spares are parked for `recipeKey` (the depth check a
844
- * refill reads before minting). Uses the same liveness test as the claim, so a
845
- * spare the claim would skip can never hold the pool at depth 1 and starve
846
- * every later create of a warm start. */
847
- export async function warmSpareCount(recipeKey) {
848
- return (await warmSpareRowsFor(await openDb(), recipeKey)).filter(spareIsClaimable).length;
849
- }
850
- /** Direct children of `id`, oldest first — an indexed point query
851
- * (`idx_nodes_parent`) instead of a full-table `listNodes()` scan. */
852
- export async function childrenOf(id) {
853
- return (await (await openDb()).prepare('SELECT node_id FROM nodes WHERE parent = ? ORDER BY created')
854
- .all(id)).map((r) => r.node_id);
855
- }
856
- /** Every node's lean roster row (only those in `ids` when given), oldest first — a single scan indexed by
857
- * `idx_nodes_created`, with no per-row hydration or N+1 query. */
858
- export async function rosterNodes(ids) {
859
- return (await (await openDb())
860
- .prepareUncached(`SELECT node_id, name, kind, mode, lifecycle, status, cwd, host_kind, parent, created, description
861
- FROM node_rows WHERE ${NOT_A_SPARE}${ids === undefined ? '' : ' AND node_id = ANY(?::text[])'} ORDER BY created`)
862
- .all(...(ids === undefined ? [] : [[...ids]]))).map((r) => ({
863
- node_id: r['node_id'],
864
- name: r['name'],
865
- kind: r['kind'],
866
- mode: r['mode'],
867
- lifecycle: r['lifecycle'],
868
- status: r['status'],
869
- cwd: r['cwd'],
870
- host_kind: r['host_kind'] ?? null,
871
- parent: r['parent'] ?? null,
872
- created: r['created'],
873
- description: r['description'] ?? null,
874
- }));
875
- }
876
- /** Resumable ROOT conversations pinned to `cwd`, most-recently-created first.
877
- * A "root" is the top of a spine (`parent IS NULL`) that is a real
878
- * conversation (not a `kind:'human'` ask) and still resumable (`active`/`idle`,
879
- * never a `done`/`dead`/`canceled` node). This backs the front-door
880
- * `crtr -c`/`-r` resume: cwd is the key (the Claude-Code mental model — "my
881
- * last session HERE"), so it never teleports across projects. */
882
- export async function listResumableRoots(cwd) {
883
- const rows = await (await openDb())
884
- .prepareUncached(`SELECT * FROM node_rows
885
- WHERE parent IS NULL AND kind != 'human'
886
- AND status IN ('active','idle') AND cwd = ?
887
- AND ${NOT_A_SPARE}
888
- ORDER BY created DESC`)
889
- .all(cwd);
890
- return rows.map(rowFrom);
891
- }
892
- export * from './tree.js';
893
- /** Close the TOCTOU between checking a target has a natural cycle ahead
894
- * of it and the write that depends on that (for example, a deferred inbox
895
- * append). Fresh-reads `nodeId`'s
896
- * (status, final_report, frozen_at) and either runs `body` (a write) or short-circuits
897
- * with a `'terminal'`/`'missing'` outcome — the read takes the node row
898
- * `FOR UPDATE` and holds it through `body`'s write in the same transaction, so
899
- * a concurrent finish/cancel/finalization/deletion either commits entirely
900
- * before this reads (observed here, `body` never runs) or waits on the row
901
- * until `body` commits — never in the gap a separate check-then-write left
902
- * open. Pass the shared `hasNoNaturalCycle` predicate rather than
903
- * a bespoke one so the two never drift.
904
- *
905
- * A dangling `nodeId` — the row deleted after the
906
- * caller's own selection but before this guard's fresh read — MUST NEVER run
907
- * `body`. Reporting `'missing'` distinctly from `'terminal'` (rather than
908
- * folding it into either the terminal branch or a fabricated "safe" empty
909
- * snapshot) keeps the two failure shapes from being conflated: a terminal
910
- * target has a real `status`/`final_report` to report and its own
911
- * `deferred_no_natural_cycle`-style rejection, while a missing target has
912
- * nothing to report and belongs to the caller's own not-found contract. */
913
- export async function withFreshTerminalGuard(nodeId, isTerminal, body) {
914
- return await withCanvasWrite(async (db) => {
915
- const row = await db.prepare('SELECT status, final_report, frozen_at FROM nodes WHERE node_id = ? FOR UPDATE')
916
- .get(nodeId);
917
- if (row === undefined) {
918
- return { kind: 'missing' };
919
- }
920
- if (isTerminal(row)) {
921
- return { kind: 'terminal', status: row.status, final_report: row.final_report };
922
- }
923
- return { kind: 'ran', result: await body() };
924
- });
925
- }
926
- /** True when this node's identity is still required to own a managed checkout.
927
- *
928
- * Ownership outlives the OPEN state. A closed record whose cleanup is still
929
- * pending names a checkout and a branch that are physically still there, and
930
- * this node record is the only proof of who they belong to — deleting it turns
931
- * a retained residual into an ownerless orphan the daemon sweep can never
932
- * safely reclaim, because it must never guess at a worktree it cannot prove it
933
- * created. So prune may take this node only once cleanup is COMPLETE. A
934
- * historical closed record written before the cleanup field existed carries no
935
- * such proof and counts as incomplete.
936
- *
937
- * An abandoned record is deliberately NOT protected: abandon already removed
938
- * the checkout and retains its branch for a person on purpose, so there is no
939
- * residual for the sweep to own. */
940
- async function hasUnreconciledManagedWorktree(nodeId) {
941
- return await hasUnreconciledWorktree(nodeId);
942
- }
943
- /** Whether a row may be removed by an automatic collection sweep. */
944
- export async function isCollectible(row, opts = {}) {
945
- if (!['done', 'dead', 'canceled'].includes(row.status)
946
- || row.pi_pid !== null
947
- || row.frozen_at !== null
948
- || await hasUnreconciledManagedWorktree(row.node_id)
949
- || row.node_id === envNodeId()
950
- // App runs (e.g. chat conversations) are deleted only through the runs API.
951
- || isAppRun(row))
952
- return false;
953
- return opts.pastTtl === true || !['crashed', 'stranded', null].includes(row.terminal_reason ?? null);
954
- }
955
- async function nodeConversationIds(nodeIds) {
956
- if (nodeIds.length === 0)
957
- return [];
958
- const placeholders = nodeIds.map(() => '?').join(',');
959
- const rows = await (await openDb()).prepareUncached(`SELECT s.session_id, s.transcript_path, s.node_id, n.grantee FROM sessions s JOIN node_rows n ON n.node_id = s.node_id WHERE s.node_id IN (${placeholders}) AND s.session_id IS NOT NULL ORDER BY s.created_at, s.seq`).all(...nodeIds);
960
- return [...new Map(rows.map((row) => [row.session_id, { id: row.session_id, path: row.transcript_path, dir: join(appSpace(row.grantee).conversations, row.node_id) }])).values()];
961
- }
962
- /** Delete conversations nothing still needs: no sessions row names them, and no fork
963
- * that has not launched yet (a node with no sessions row) replays them as its source.
964
- * Runs after the owner's rows are gone, so the store can no longer resolve a path: each file is
965
- * removed by the path read before. */
966
- async function deleteNodeConversations(conversations) {
967
- const db = await openDb();
968
- const referenced = db.prepare('SELECT 1 FROM sessions WHERE session_id = ? LIMIT 1');
969
- const pendingFork = db.prepare(`SELECT 1 FROM nodes n WHERE n.fork_source_file LIKE '%\\_' || ? || '.jsonl' ESCAPE '\\'
970
- AND NOT EXISTS (SELECT 1 FROM sessions s WHERE s.node_id = n.node_id) LIMIT 1`);
971
- for (const { id, path, dir } of conversations) {
972
- if (await referenced.get(id) !== undefined || await pendingFork.get(id) !== undefined)
973
- continue;
974
- // A legacy transcript file goes too, but only from beneath the node's own conversations directory.
975
- const file = path !== null && lstatSync(path, { throwIfNoEntry: false }) !== undefined && isBeneath(dir, path) ? path : undefined;
976
- try {
977
- await conversationStore().delete(id, file);
978
- }
979
- catch (error) {
980
- if (!(error instanceof ConversationNotFoundError))
981
- throw error;
982
- }
983
- }
984
- }
985
- /** A node chooses the transcript path it binds, so only a file beneath the deleting
986
- * node's own conversations directory (no link in the way) is ever removed. */
987
- function isBeneath(dir, path) {
988
- try {
989
- const rel = relative(realpathSync(dir), join(realpathSync(dirname(path)), basename(path)));
990
- return rel !== '' && rel !== '..' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
991
- }
992
- catch (error) {
993
- if (error.code === 'ENOENT')
994
- return false;
995
- throw error;
996
- }
997
- }
998
- /** Delete one node and what it owns, in the caller's transaction; false when it is already gone. */
999
- async function deleteNodeObject(db, nodeId) {
1000
- const node = await getById(db, nodeId);
1001
- if (node === null || node.deleted_at !== null)
1002
- return false;
1003
- await deleteNodeWithOwned(db, node);
1004
- return true;
1005
- }
1006
- export async function nodeFiles(nodeId) {
1007
- return { nodeId, app: await getNode(nodeId) === null ? null : await appForNode(nodeId) };
1008
- }
1009
- /** Remove the trees an app can write into (the node's agent folder and run
1010
- * folder) without following any link inside them (R18G). Synchronous even on
1011
- * the retention sweep: a plain recursive rm would follow an app-planted link. */
1012
- async function removeNodeAppTrees({ nodeId, app }) {
1013
- if (app !== null)
1014
- removeTreeBeneath(appSpace(app).nodes, await nodeAgentDir(nodeId, app));
1015
- removeTreeBeneath(dirname(nodeRunDir(nodeId)), nodeRunDir(nodeId));
1016
- }
1017
- /** The daemon-owned directories a deleted node owned, removed whole with a plain rm. */
1018
- function nodeOwnedDirs({ nodeId }) {
1019
- return [nodeDir(nodeId)];
1020
- }
1021
- /** A conversation another node still references keeps its file, and so its
1022
- * conversations directory: remove it only when empty. */
1023
- function removeNodeConversationDir({ nodeId, app }) {
1024
- if (app === null)
1025
- return;
1026
- try {
1027
- rmdirSync(join(appSpace(app).conversations, nodeId));
1028
- }
1029
- catch (error) {
1030
- if (!['ENOENT', 'ENOTEMPTY'].includes(error.code ?? ''))
1031
- throw error;
1032
- }
1033
- }
1034
- /** Remove every directory a deleted node owned. A conversation another node
1035
- * still references keeps its file, and so its conversations directory. */
1036
- export async function removeNodeFiles(files) {
1037
- await removeNodeAppTrees(files);
1038
- for (const dir of nodeOwnedDirs(files))
1039
- rmSync(dir, { recursive: true, force: true });
1040
- removeNodeConversationDir(files);
1041
- }
1042
- /** A node's sandboxes are deleted before its rows: the rows name them, so a row gone first leaves a billed sandbox no one can find.
1043
- * A sandbox that cannot be deleted throws with the rows still in place, for the caller's next attempt. */
1044
- async function requireSandboxesDeleted(nodeIds) {
1045
- const failed = await deleteNodeSandboxes(nodeIds);
1046
- if (failed.length > 0)
1047
- throw new Error(`the sandbox of node(s) ${failed.join(', ')} could not be deleted; the node rows are kept`);
1048
- }
1049
- /** Delete ONE node with what it owns ({@link deleteNodeWithOwned}) and remove its on-disk `nodes/<id>/` dir. The single-node
1050
- * analogue of {@link pruneNodes}, for IMMEDIATE reaping — e.g. an empty node the
1051
- * user closed or detached from. An open managed worktree is never deleted: its
1052
- * node retains the ownership needed for `node worktree close`. Pure persisted-state
1053
- * removal: the caller MUST have already torn down the broker engine +
1054
- * viewer (this does not signal any process). The node row and its FK-coupled
1055
- * state are removed in one canvas write boundary. Best-effort dir removal
1056
- * follows the commit. */
1057
- export async function deleteNode(nodeId) {
1058
- if (await hasUnreconciledManagedWorktree(nodeId))
1059
- return { deleted: false };
1060
- await requireSandboxesDeleted([nodeId]);
1061
- const files = await nodeFiles(nodeId);
1062
- const conversations = await nodeConversationIds([nodeId]);
1063
- const result = await withCanvasWrite(async (db) => {
1064
- await deleteNodeObject(db, nodeId);
1065
- return { deleted: true };
1066
- });
1067
- await deleteNodeConversations(conversations);
1068
- await removeNodeFiles(files);
1069
- return result;
1070
- }
1071
- /** Hard-delete a validated set of nodes in one row transaction, then remove
1072
- * their directories. The caller must tear down engines and viewers first. */
1073
- export async function deleteNodes(nodeIds) {
1074
- const ids = [...new Set(nodeIds)];
1075
- if (ids.length === 0)
1076
- return [];
1077
- const blocked = (await filterAsync(ids, hasUnreconciledManagedWorktree));
1078
- if (blocked.length > 0) {
1079
- throw new Error(`refusing to delete nodes with unreconciled managed worktrees: ${blocked.join(', ')}`);
1080
- }
1081
- await requireSandboxesDeleted(ids);
1082
- const files = (await mapAsync(ids, nodeFiles));
1083
- const conversations = await nodeConversationIds(ids);
1084
- const placeholders = ids.map(() => '?').join(',');
1085
- const existing = (await (await openDb())
1086
- .prepareUncached(`SELECT node_id FROM nodes WHERE node_id IN (${placeholders}) ORDER BY created`)
1087
- .all(...ids)).map(({ node_id }) => node_id);
1088
- const deleted = (await filterAsync(existing, async (id) => await withCanvasWrite(async (db) => await deleteNodeObject(db, id))));
1089
- await deleteNodeConversations(conversations);
1090
- for (const id of deleted) {
1091
- const node = files[ids.indexOf(id)];
1092
- await eachNodeBestEffort(node, async () => await removeNodeFiles(node));
1093
- }
1094
- return deleted;
1095
- }
1096
- /** Retention sweep: remove TERMINAL nodes (status dead | done | canceled) whose
1097
- * last activity ({@link lastActivityMs}) is older than `ttlDays`, bounding the
1098
- * otherwise-unbounded growth of node rows + dirs. Only {@link isCollectible}
1099
- * rows qualify, and never one `held` claims. Each node is deleted with what it
1100
- * owns ({@link deleteNodeWithOwned}); the on-disk `nodes/<id>/` dir is removed too.
1101
- *
1102
- * With `includeStale`, ALSO prunes nominally-live (active | idle) nodes past the
1103
- * TTL whose process is provably gone and that nothing will bring back: no live
1104
- * `pi_pid`, not sleeping until a wake (`idle-release`), no unseen wake mail,
1105
- * not frozen, not in respawn backoff, not an app run, not held, and never the CALLER
1106
- * ($CRTR_NODE_ID). Without the flag, active | idle are NEVER touched.
1107
- *
1108
- * Each node's rows change in its own transaction. Dir removals follow after COMMIT — the fs isn't transactional, and by then
1109
- * the rows are gone, so a re-run never re-finds a half-deleted node. `dryRun`
1110
- * reports the candidate set and deletes NOTHING. */
1111
- export async function pruneNodes(opts) {
1112
- const dryRun = opts.dryRun ?? false;
1113
- const includeStale = opts.includeStale ?? false;
1114
- const cutoffMs = Date.now() - opts.ttlDays * 86_400_000;
1115
- // `created` is a lower bound on last activity, so it is a sound SQL prefilter.
1116
- const cutoff = new Date(cutoffMs).toISOString();
1117
- const selfId = envNodeId() ?? '';
1118
- const db = await openDb();
1119
- const quiet = (row) => lastActivityMs(row) < cutoffMs;
1120
- const toPruned = (row) => ({ node_id: row.node_id, status: row.status, created: row.created });
1121
- const watchedOwners = await ownersOfWatchedDocuments();
1122
- const terminal = (await filterAsync((await db.prepare(`SELECT ${NODE_ROW_COLUMNS} FROM node_rows
1123
- WHERE status IN ('dead', 'done', 'canceled') AND created < ?
1124
- ORDER BY created`)
1125
- .all(cutoff))
1126
- .map(rowFrom), async (row) => await isCollectible(row, { pastTtl: true }) && quiet(row) && !watchedOwners.has(row.node_id) && !await opts.held(row.node_id)))
1127
- .map(toPruned);
1128
- const stale = !includeStale ? [] : (await filterAsync((await db.prepare(`SELECT ${NODE_ROW_COLUMNS} FROM node_rows
1129
- WHERE status IN ('active', 'idle') AND created < ?
1130
- ORDER BY created`)
1131
- .all(cutoff))
1132
- .map(rowFrom), async (row) => row.node_id !== selfId
1133
- && !isPidAlive(row.pi_pid ?? null)
1134
- && (row.frozen_at ?? null) === null
1135
- && (row.respawn_not_before ?? null) === null
1136
- && row.intent !== 'idle-release'
1137
- && !isAppRun(row)
1138
- && !await hasUnseenWakeMail(row.node_id)
1139
- && !await hasUnreconciledManagedWorktree(row.node_id)
1140
- && quiet(row)
1141
- && !await opts.held(row.node_id)))
1142
- .map(toPruned);
1143
- const candidates = await retainRunRootsWithMembers([...terminal, ...stale]);
1144
- if (dryRun || candidates.length === 0)
1145
- return { pruned: candidates, dryRun };
1146
- return { pruned: await deletePrunedNodes(candidates, opts.removeDirs), dryRun };
1147
- }
1148
- /** Nodes that own a live document some other live object still watches. Deleting such a node deletes the document under
1149
- * that watcher (only a link from a live document keeps one), so the sweep leaves the node until the watcher ends. A
1150
- * watcher is live when it is not a node (a profile, an app, a person) or is a node that is active or idle; a finished
1151
- * node's watches end with it. */
1152
- async function ownersOfWatchedDocuments() {
1153
- const rows = await (await openDb()).prepare(`SELECT DISTINCT d.owner AS owner FROM watches w
1154
- JOIN objects d ON d.id = w.object AND d.type = 'document' AND d.deleted_at IS NULL
1155
- JOIN objects o ON o.id = w.watcher AND o.deleted_at IS NULL
1156
- LEFT JOIN nodes n ON n.node_id = w.watcher
1157
- WHERE w.watcher != d.owner AND d.owner IS NOT NULL AND (n.node_id IS NULL OR n.status IN ('active', 'idle'))`)
1158
- .all();
1159
- return new Set(rows.map((r) => r.owner));
1160
- }
1161
- /** A run's nodes all carry the root's `run_id`, and the run observer and every
1162
- * run-event append read the root's row. A sweep therefore never deletes a run
1163
- * root while a node of its run survives: a member can be retained alone (its
1164
- * managed worktree is unreconciled, `held` claims it, it is still live), and
1165
- * deleting the root under it leaves a `run_id` that points at nothing. The
1166
- * root goes on a later sweep, once its last member has. */
1167
- async function retainRunRootsWithMembers(candidates) {
1168
- const db = await openDb();
1169
- const members = db.prepare('SELECT node_id FROM nodes WHERE run_id = ? AND node_id != ?');
1170
- const sweeping = new Set(candidates.map((c) => c.node_id));
1171
- return (await filterAsync(candidates, async (c) => (await members.all(c.node_id, c.node_id)).every((m) => sweeping.has(m.node_id))));
1172
- }
1173
- /** Delete a set of pruned nodes, each with what it owns in its own transaction, followed by best-effort
1174
- * on-disk `nodes/<id>/` removal. Shared by TTL and count pruning so their
1175
- * delete semantics never drift. `removeDirs` replaces the synchronous removal
1176
- * (the daemon passes an async one so a large sweep never blocks its tick). */
1177
- async function deletePrunedNodes(swept, removeDirs) {
1178
- // A node whose sandbox could not be deleted keeps its rows, so the next sweep finds it again, and a run root
1179
- // never goes while such a member of its run survives. Returns the nodes actually deleted.
1180
- const stuck = new Set(await deleteNodeSandboxes(swept.map((c) => c.node_id)));
1181
- const candidates = stuck.size === 0 ? swept : await retainRunRootsWithMembers(swept.filter((c) => !stuck.has(c.node_id)));
1182
- if (candidates.length === 0)
1183
- return [];
1184
- const files = (await mapAsync(candidates, async (c) => await nodeFiles(c.node_id)));
1185
- const conversations = await nodeConversationIds(candidates.map((c) => c.node_id));
1186
- for (const c of candidates)
1187
- await withCanvasWrite(async (db) => await deleteNodeObject(db, c.node_id));
1188
- await deleteNodeConversations(conversations);
1189
- if (removeDirs !== undefined) {
1190
- for (const node of files) {
1191
- await eachNodeBestEffort(node, async () => {
1192
- await removeNodeAppTrees(node);
1193
- removeNodeConversationDir(node);
1194
- });
1195
- }
1196
- removeDirs(files.flatMap(nodeOwnedDirs));
1197
- return candidates;
1198
- }
1199
- for (const node of files)
1200
- await eachNodeBestEffort(node, async () => await removeNodeFiles(node));
1201
- return candidates;
1202
- }
1203
- /** The rows are already gone, so one node's refused or failed removal is
1204
- * logged and the batch continues: nothing finds these directories later. */
1205
- async function eachNodeBestEffort(node, remove) {
1206
- try {
1207
- await remove();
1208
- }
1209
- catch (error) {
1210
- emitEvent({ level: 'error', event: 'canvas.node_files.remove_failed', error, fields: { node_id: node.nodeId } });
1211
- }
1212
- }
1213
- /** A node's most recent activity (epoch ms): the latest of its lifecycle
1214
- * timestamps (created, launched, settled, finalized, outcome, last run event)
1215
- * and the mtime of `job/telemetry.json`, which every turn_end rewrites. 0 when
1216
- * none is readable. The single clock every retention decision uses. Never throws. */
1217
- export function lastActivityMs(row) {
1218
- let latest = 0;
1219
- for (const value of [row.created, row.launched_at, row.last_settled_at, row.finalized_at, row.outcome_at, row.last_activity_at]) {
1220
- if (value === null || value === undefined)
1221
- continue;
1222
- const t = Date.parse(value);
1223
- if (Number.isFinite(t) && t > latest)
1224
- latest = t;
1225
- }
1226
- try {
1227
- const st = statSync(join(jobDir(row.node_id), 'telemetry.json'), { throwIfNoEntry: false });
1228
- if (st !== undefined && st.mtimeMs > latest)
1229
- latest = st.mtimeMs;
1230
- }
1231
- catch {
1232
- /* telemetry is disposable */
1233
- }
1234
- return latest;
1235
- }
1236
- /** Count-based retention sweep: keep every row that is not collectible or that
1237
- * `held` claims, plus the most recently active collectible rows up to
1238
- * `maxNodes` in total, so the real retained floor is `max(maxNodes,
1239
- * retainedCount)`. Bounds the growth the TTL sweep can't (a canvas that never
1240
- * crosses the TTL still grows without limit). Recency is {@link lastActivityMs}.
1241
- *
1242
- * Mirrors {@link pruneNodes} exactly for the delete (shared `deletePrunedNodes`:
1243
- * transactioned row sweep + FK edge cascade + best-effort dir removal). `dryRun`
1244
- * reports the candidate set and deletes NOTHING. */
1245
- export async function pruneToLimit(opts) {
1246
- const dryRun = opts.dryRun ?? false;
1247
- const rows = await listNodes();
1248
- const collectible = (await filterAsync(rows, async (row) => await isCollectible(row) && !await opts.held(row.node_id)));
1249
- const retainedCount = rows.length - collectible.length;
1250
- const keep = Math.max(0, opts.maxNodes - retainedCount);
1251
- const unfiltered = collectible
1252
- .map((row) => ({ row, recency: lastActivityMs(row) }))
1253
- .sort((a, b) => b.recency - a.recency)
1254
- .slice(keep)
1255
- .map(({ row }) => ({ node_id: row.node_id, status: row.status, created: row.created }));
1256
- const candidates = await retainRunRootsWithMembers(unfiltered);
1257
- if (dryRun || candidates.length === 0)
1258
- return { pruned: candidates, dryRun };
1259
- return { pruned: await deletePrunedNodes(candidates), dryRun };
1260
- }