@north-light/cli 0.3.668 → 0.3.670

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