@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,1585 @@
1
+ // CrtrClient — the typed fetch client over crtrd's API.
2
+ //
3
+ // The root entry is browser-safe: Node's unix-socket fetch implementation and
4
+ // local path resolution live exclusively in `api/node-transport.ts`.
5
+ import { ApiError, isErrorBody } from './errors.js';
6
+ import { routes } from './routes.js';
7
+ import { isSafeNodeId } from './dto/common.js';
8
+ import { isSafeBashJobId } from './dto/bash-jobs.js';
9
+ import { isSafeCronId, } from './dto/crons.js';
10
+ const DEFAULT_TIMEOUT_MS = 30_000;
11
+ /** The daemon's own wait for a revived broker's view endpoint (attach handler's MACHINE_VIEW_WAIT_MS), on top of the revive. */
12
+ const ATTACH_VIEW_WAIT_MS = 30_000;
13
+ const LOCAL_SOCKET_FETCH = Symbol.for('@north-light/api/local-socket-fetch');
14
+ /** Default bounded window to wait for `/healthz` to come up after
15
+ * `onColdSocket`, when the caller does not pass `coldStartPollWindowMs`. */
16
+ const HEALTHZ_POLL_WINDOW_MS = 10_000;
17
+ const HEALTHZ_POLL_INTERVAL_MS = 200;
18
+ /** One strict wall-clock availability window shared by local API clients and
19
+ * daemon management. Each probe gets only the budget remaining at its start. */
20
+ export async function waitForDaemonAvailability({ windowMs, probe, initialError, pollIntervalMs = HEALTHZ_POLL_INTERVAL_MS, retry = () => true, now = Date.now, sleep = sleepMs, }) {
21
+ const deadline = now() + windowMs;
22
+ let lastError = initialError;
23
+ for (;;) {
24
+ const remaining = deadline - now();
25
+ if (remaining <= 0)
26
+ throw lastError ?? new Error('crtrd availability window expired without a probe failure');
27
+ try {
28
+ await probe(remaining);
29
+ return;
30
+ }
31
+ catch (error) {
32
+ lastError = error;
33
+ if (!retry(error))
34
+ throw error;
35
+ }
36
+ const afterProbe = deadline - now();
37
+ if (afterProbe <= 0)
38
+ throw lastError;
39
+ await sleep(Math.min(pollIntervalMs, afterProbe));
40
+ }
41
+ }
42
+ /** The one error a call raises when its deadline passes (or a wait would pass it): status 504, code `deadline_exceeded`,
43
+ * `details: { deadline_at, reason, retry_after_s? }`. */
44
+ /** The longest delay a timer accepts (2^31-1 ms, about 24.8 days); a longer deadline would fire at once. */
45
+ export const MAX_TIMER_MS = 2_147_483_647;
46
+ export function deadlineExceeded(deadlineAt, reason = 'elapsed', retryAfterS) {
47
+ const message = reason === 'retry_after'
48
+ ? `the server asked to retry after ${retryAfterS}s, which is later than the call's deadline (${new Date(deadlineAt).toISOString()}); not waiting`
49
+ : `the call's deadline (${new Date(deadlineAt).toISOString()}) passed`;
50
+ return new ApiError(504, 'deadline_exceeded', message, {
51
+ deadline_at: deadlineAt, reason, ...(retryAfterS === undefined ? {} : { retry_after_s: retryAfterS }),
52
+ });
53
+ }
54
+ const budgetExhausted = (deadlineAt) => deadlineExceeded(deadlineAt ?? Date.now());
55
+ export class CrtrClient {
56
+ baseUrl;
57
+ fetch;
58
+ headers;
59
+ autostart;
60
+ timeoutMs;
61
+ maxRetries;
62
+ localSocketTransport;
63
+ onColdSocket;
64
+ coldStartDiagnostic;
65
+ coldStartFailure;
66
+ availabilityFailure;
67
+ coldStartPollWindowMs;
68
+ /** Set when the last availability wait ended on a daemon startup failure, whose message already says why. */
69
+ startupFailureReported = false;
70
+ /** Guards against invoking the daemon-start hook more than once per client. */
71
+ coldStartAttempted = false;
72
+ constructor(opts) {
73
+ if (opts.baseUrl === '')
74
+ throw new TypeError('CrtrClient requires baseUrl');
75
+ this.baseUrl = new URL(opts.baseUrl);
76
+ this.fetch = opts.fetch ?? globalThis.fetch;
77
+ this.headers = { ...opts.headers };
78
+ this.autostart = opts.autostart ?? false;
79
+ this.timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
80
+ this.maxRetries = opts.maxRetries ?? 2;
81
+ this.localSocketTransport = this.fetch[LOCAL_SOCKET_FETCH] === true;
82
+ if (opts.onColdSocket !== undefined)
83
+ this.onColdSocket = opts.onColdSocket;
84
+ if (opts.coldStartDiagnostic !== undefined)
85
+ this.coldStartDiagnostic = opts.coldStartDiagnostic;
86
+ if (opts.coldStartFailure !== undefined)
87
+ this.coldStartFailure = opts.coldStartFailure;
88
+ if (opts.availabilityFailure !== undefined)
89
+ this.availabilityFailure = opts.availabilityFailure;
90
+ this.coldStartPollWindowMs = opts.coldStartPollWindowMs ?? HEALTHZ_POLL_WINDOW_MS;
91
+ }
92
+ // Health / status
93
+ healthz() {
94
+ return this.request('GET', routes.healthz());
95
+ }
96
+ /** One `/healthz` observation without cold-socket recovery. Availability
97
+ * waiters own retry policy and pass their remaining wall-clock budget here. */
98
+ async probeHealthz(timeoutMs) {
99
+ const response = await this.transport('GET', routes.healthz(), undefined, { timeout: timeoutMs });
100
+ // A restricted daemon is alive and deliberately answers its health DTO with
101
+ // 503. Preserve that state for daemon startup management instead of treating
102
+ // the expected non-2xx status as a generic API failure.
103
+ if (response.status === 503) {
104
+ try {
105
+ const health = await response.clone().json();
106
+ if (typeof health.startup_blocked === 'string')
107
+ return health;
108
+ }
109
+ catch {
110
+ // `parse` below reports malformed/non-health 503 responses normally.
111
+ }
112
+ }
113
+ return parse(response);
114
+ }
115
+ /** `GET /v1/ready`: 200 ready, 503 not yet; both answer a `ReadyDTO`. */
116
+ async ready() {
117
+ const response = await this.transport('GET', routes.ready(), undefined, {});
118
+ if (response.status === 503) {
119
+ try {
120
+ const body = await response.clone().json();
121
+ if (body.ready === false)
122
+ return body;
123
+ }
124
+ catch { /* `parse` reports a malformed 503 normally */ }
125
+ }
126
+ return parse(response);
127
+ }
128
+ status() {
129
+ return this.request('GET', routes.status());
130
+ }
131
+ /** Busy and next-due state, the truth behind sandbox sleep and wake. */
132
+ due() {
133
+ return this.request('GET', routes.due());
134
+ }
135
+ /** Ask the daemon to replace itself with a successor running the currently
136
+ * selected runtime generation. Answers before the handover starts, so a
137
+ * caller living inside a node the handover will tear down still gets a
138
+ * settled result. */
139
+ restartDaemon() {
140
+ return this.request('POST', routes.daemonRestart());
141
+ }
142
+ /** Pause the daemon for an import (see {@link DaemonDrainDTO}); with `settle_limit_ms` waits for turns to settle. */
143
+ drainDaemon(req = {}) {
144
+ const wait = req.settle_limit_ms ?? 0;
145
+ return this.request('POST', routes.daemonDrain(), req, { timeout: wait + this.timeoutMs });
146
+ }
147
+ endDaemonDrain() {
148
+ return this.request('DELETE', routes.daemonDrain());
149
+ }
150
+ admitDaemon() {
151
+ return this.request('POST', routes.daemonAdmit());
152
+ }
153
+ migrateState(req) {
154
+ return this.request('POST', routes.daemonMigrate(), req);
155
+ }
156
+ // Nodes
157
+ appendNodeLog(id, req) {
158
+ return this.request('POST', routes.nodeLog(this.nodePath(id)), req);
159
+ }
160
+ async putNodeTelemetry(id, req) {
161
+ await this.request('PUT', routes.nodeTelemetry(this.nodePath(id)), req);
162
+ }
163
+ async putNodeSummaries(id, req) {
164
+ await this.request('PUT', routes.nodeSummaries(this.nodePath(id)), req);
165
+ }
166
+ async putNodeRecap(id, req) {
167
+ await this.request('PUT', routes.nodeRecap(this.nodePath(id)), req);
168
+ }
169
+ readNodeInboxReport(id, ref, executionId) {
170
+ return this.request('GET', withQuery(routes.nodeInboxReport(this.nodePath(id)), { ref, execution_id: executionId }));
171
+ }
172
+ listNodeAttachments(id) {
173
+ return this.request('GET', routes.nodeAttachments(this.nodePath(id)));
174
+ }
175
+ /** The bytes of one of the run's attachments (`GET /v1/nodes/:id/attachments/:sha256`). */
176
+ async readNodeAttachment(id, sha256) {
177
+ const response = await this.send('GET', routes.nodeAttachment(this.nodePath(id), sha256));
178
+ if (!response.ok)
179
+ await parse(response);
180
+ return new Uint8Array(await response.arrayBuffer());
181
+ }
182
+ createNodeFile(id, req) {
183
+ return this.request('POST', routes.nodeFiles(this.nodePath(id)), req);
184
+ }
185
+ completeNodeFile(id, fileId) {
186
+ return this.request('POST', routes.nodeFileComplete(this.nodePath(id), fileId));
187
+ }
188
+ readNodePassiveMessage(id, ref) {
189
+ return this.request('GET', withQuery(routes.nodePassiveMessage(this.nodePath(id)), { ref }));
190
+ }
191
+ nodePushedFinal(id, req) {
192
+ return this.request('POST', routes.nodePushedFinal(this.nodePath(id)), req);
193
+ }
194
+ createNode(req) {
195
+ return this.request('POST', routes.nodes(), req);
196
+ }
197
+ /** List canvas nodes with composable row filters. `include: 'activity'` adds
198
+ * latest/canonical reports and pending-human counts in the same response. */
199
+ listNodes(q) {
200
+ return this.request('GET', withQuery(routes.nodes(), q));
201
+ }
202
+ getNode(id) {
203
+ return this.request('GET', routes.node(this.nodePath(id)));
204
+ }
205
+ /** Read a node outcome, optionally awaiting it for at most 25 seconds. This
206
+ * is a GET so the client can safely replay it across daemon handover. */
207
+ getNodeOutcome(id, { waitSeconds } = {}) {
208
+ if (waitSeconds !== undefined && (!Number.isInteger(waitSeconds) || waitSeconds < 0 || waitSeconds > 25)) {
209
+ throw new RangeError('waitSeconds must be an integer between 0 and 25');
210
+ }
211
+ return this.request('GET', withQuery(routes.nodeOutcome(this.nodePath(id)), { wait: waitSeconds }), undefined, { timeout: (waitSeconds ?? 0) * 1_000 + this.timeoutMs });
212
+ }
213
+ /** Open the raw server-sent event response for a node. The caller owns SSE
214
+ * parsing and must consume or cancel the response body. Streams deliberately
215
+ * have no client wall-clock timeout. */
216
+ getNodeEvents(id, query = {}, options = {}) {
217
+ if (query.after !== undefined && (!Number.isSafeInteger(query.after) || query.after < 0)) {
218
+ throw new RangeError('after must be a non-negative safe integer');
219
+ }
220
+ return this.transport('GET', withQuery(routes.nodeEvents(this.nodePath(id)), query), undefined, {
221
+ ...options,
222
+ headers: { accept: 'text/event-stream', ...(options.headers ?? {}) },
223
+ timeout: 0,
224
+ });
225
+ }
226
+ /** Parsed NDJSON hints, consumed eagerly and line by line. The caller must
227
+ * cancel with `signal` when done; no wall-clock timeout applies to the stream. */
228
+ async *getBrokerSignals(id, executionId, options = {}) {
229
+ const response = await this.send('GET', withQuery(routes.nodeBrokerSignals(this.nodePath(id)), { execution_id: executionId }), undefined, {
230
+ ...options, headers: { accept: 'application/x-ndjson', ...(options.headers ?? {}) }, timeout: 0,
231
+ });
232
+ if (!response.ok) {
233
+ await parse(response);
234
+ return;
235
+ }
236
+ if (response.body === null)
237
+ throw new ApiError(response.status, 'invalid_response', 'broker signal stream has no body');
238
+ const reader = response.body.getReader();
239
+ const decoder = new TextDecoder();
240
+ let buffer = '';
241
+ try {
242
+ while (true) {
243
+ const { done, value } = await reader.read();
244
+ if (done)
245
+ break;
246
+ buffer += decoder.decode(value, { stream: true });
247
+ let newline;
248
+ while ((newline = buffer.indexOf('\n')) !== -1) {
249
+ const line = buffer.slice(0, newline);
250
+ buffer = buffer.slice(newline + 1);
251
+ if (line !== '')
252
+ yield JSON.parse(line);
253
+ }
254
+ }
255
+ buffer += decoder.decode();
256
+ if (buffer.trim() !== '')
257
+ throw new ApiError(502, 'invalid_response', 'broker signal stream ended mid-line');
258
+ }
259
+ finally {
260
+ await reader.cancel().catch(() => { });
261
+ }
262
+ }
263
+ // Structured requests
264
+ createStructuredRequest(req, options) {
265
+ // A synchronous admission is one held exchange. Replaying a POST after a
266
+ // reset can create work the caller has already stopped waiting for, and
267
+ // cold-socket recovery consumes its fixed end-to-end budget.
268
+ if (req.mode === 'sync')
269
+ return this.sendOnce('POST', '/v1/structured-requests', req, options);
270
+ return this.request('POST', '/v1/structured-requests', req, options);
271
+ }
272
+ getStructuredRequest(requestId, { wait = 0, budgetMs } = {}) {
273
+ if (!Number.isInteger(wait) || wait < 0 || wait > 25) {
274
+ throw new RangeError('wait must be an integer between 0 and 25');
275
+ }
276
+ return this.request('GET', withQuery(`/v1/structured-requests/${this.requestPath(requestId)}`, { wait }), undefined, { budgetMs });
277
+ }
278
+ cancelStructuredRequest(requestId, options) {
279
+ return this.request('POST', `/v1/structured-requests/${this.requestPath(requestId)}/cancel`, {}, options);
280
+ }
281
+ /** Register or replace an armed target for terminal-outcome delivery. */
282
+ registerOutcomeDelivery(id, req) {
283
+ return this.request('PUT', routes.nodeOutcomeDelivery(this.nodePath(id)), req);
284
+ }
285
+ getOutcomeDelivery(id) {
286
+ return this.request('GET', routes.nodeOutcomeDelivery(this.nodePath(id)));
287
+ }
288
+ /** Disarm an unsettled outcome-delivery registration. */
289
+ async disarmOutcomeDelivery(id) {
290
+ await this.request('DELETE', routes.nodeOutcomeDelivery(this.nodePath(id)));
291
+ }
292
+ listBashJobs(id) {
293
+ return this.request('GET', routes.nodeJobs(this.nodePath(id)));
294
+ }
295
+ /** The job's output from the blob store, last bytes or lines (see `BashJobOutputQuery`). */
296
+ readBashJobOutput(id, jobId, query = {}) {
297
+ const params = new URLSearchParams();
298
+ if (query.tail_lines !== undefined)
299
+ params.set('tail_lines', String(query.tail_lines));
300
+ if (query.max_bytes !== undefined)
301
+ params.set('max_bytes', String(query.max_bytes));
302
+ const suffix = params.size === 0 ? '' : `?${params.toString()}`;
303
+ return this.request('GET', `${routes.nodeJobOutput(this.nodePath(id), this.jobPath(jobId))}${suffix}`);
304
+ }
305
+ stopBashJob(id, jobId) {
306
+ return this.request('DELETE', routes.nodeJob(this.nodePath(id), this.jobPath(jobId)));
307
+ }
308
+ /** Claim, quiet or re-arm one running job (see `JobPatchRequest`). */
309
+ async patchBashJob(id, jobId, request) {
310
+ await this.request('PATCH', routes.nodeJob(this.nodePath(id), this.jobPath(jobId)), request);
311
+ }
312
+ /** The broker's report on a job it runs. */
313
+ async reportBashJob(id, jobId, request) {
314
+ await this.request('POST', routes.nodeJobReport(this.nodePath(id), this.jobPath(jobId)), request);
315
+ }
316
+ sendMessage(id, req) {
317
+ return this.request('POST', routes.nodeMessages(this.nodePath(id)), req);
318
+ }
319
+ /** First-class interrupt (the human Esc): cancels pending undelivered
320
+ * human-send inbox entries, then aborts a live in-flight turn. NEVER
321
+ * revives a dormant target. */
322
+ interruptNode(id) {
323
+ return this.request('POST', routes.nodeInterrupt(this.nodePath(id)), {});
324
+ }
325
+ pushReport(id, req) {
326
+ return this.request('POST', routes.nodeReports(this.nodePath(id)), req);
327
+ }
328
+ submitResult(id, req) {
329
+ return this.request('POST', routes.nodeResult(this.nodePath(id)), req);
330
+ }
331
+ forkNode(id) {
332
+ return this.request('POST', routes.nodeFork(this.nodePath(id)), {});
333
+ }
334
+ reviveNode(id, req) {
335
+ return this.request('POST', routes.nodeRevive(this.nodePath(id)), req ?? {});
336
+ }
337
+ relaunchRoot(id) {
338
+ return this.request('POST', routes.nodeRelaunchRoot(this.nodePath(id)), {});
339
+ }
340
+ bindBrokerSession(id, req) {
341
+ return this.request('POST', routes.nodeBrokerSessionBound(this.nodePath(id)), req);
342
+ }
343
+ cycleStartBroker(id, req, opts) {
344
+ return this.request('POST', routes.nodeBrokerCycleStart(this.nodePath(id)), req, opts);
345
+ }
346
+ settleBroker(id, req) {
347
+ return this.request('POST', routes.nodeBrokerSettle(this.nodePath(id)), req);
348
+ }
349
+ startBrokerCycle(id, req) {
350
+ return this.request('POST', routes.nodeBrokerCycle(this.nodePath(id)), req);
351
+ }
352
+ async postBrokerIdle(id, req) {
353
+ await this.request('POST', routes.nodeBrokerIdle(this.nodePath(id)), req);
354
+ }
355
+ completeBrokerPark(id, req) {
356
+ return this.request('POST', routes.nodeBrokerParkComplete(this.nodePath(id)), req);
357
+ }
358
+ recordBrokerParkActivity(id, req) {
359
+ return this.request('POST', routes.nodeBrokerParkActivity(this.nodePath(id)), req);
360
+ }
361
+ async recordBrokerTelemetry(id, req) {
362
+ await this.request('POST', routes.nodeBrokerTelemetry(this.nodePath(id)), req);
363
+ }
364
+ claimNodeMail(id, req) {
365
+ return this.request('POST', routes.nodeMailClaim(this.nodePath(id)), req);
366
+ }
367
+ acknowledgeNodeMail(id, req) {
368
+ return this.request('POST', routes.nodeMailAcknowledge(this.nodePath(id)), req);
369
+ }
370
+ recordBrokerTurn(id, req) {
371
+ return this.request('POST', routes.brokerTurn(this.nodePath(id)), req);
372
+ }
373
+ mutateBrokerProviderRetry(id, req) {
374
+ return this.request('POST', routes.brokerProviderRetry(this.nodePath(id)), req);
375
+ }
376
+ mutateBrokerFault(id, req) {
377
+ return this.request('POST', routes.brokerFault(this.nodePath(id)), req);
378
+ }
379
+ getBrokerRecovery(id, expectedExecutionId) {
380
+ return this.request('GET', `${routes.brokerRecovery(this.nodePath(id))}?expected_execution_id=${encodeURIComponent(expectedExecutionId)}`);
381
+ }
382
+ recordNodeFault(id, req) {
383
+ return this.request('POST', routes.nodeFault(this.nodePath(id)), req);
384
+ }
385
+ clearNodeFault(id, opts = {}) {
386
+ const query = new URLSearchParams();
387
+ if (opts.link !== undefined)
388
+ query.set('link', opts.link);
389
+ if (opts.preserve_episode !== undefined)
390
+ query.set('preserve_episode', String(opts.preserve_episode));
391
+ const suffix = query.size === 0 ? '' : `?${query.toString()}`;
392
+ return this.request('DELETE', `${routes.nodeFault(this.nodePath(id))}${suffix}`);
393
+ }
394
+ commitBrokerModel(id, req) {
395
+ return this.request('POST', routes.nodeBrokerModel(this.nodePath(id)), req);
396
+ }
397
+ /** The sandbox's start bundle for an execution of the calling node. */
398
+ executionStart(executionId) {
399
+ return this.request('GET', routes.executionStart(executionId));
400
+ }
401
+ /** The calling node's imported files are unpacked in its sandbox (sets `import_node_files.unpacked_at`). */
402
+ executionImportUnpacked(executionId) {
403
+ return this.request('POST', routes.executionImportUnpacked(executionId), {});
404
+ }
405
+ /** A GitHub token limited to the environment's recipe repositories, for the calling node's environment. */
406
+ gitCredential(environmentId, req) {
407
+ return this.request('POST', routes.environmentGitCredential(environmentId), req);
408
+ }
409
+ brokerExtensionState(id) {
410
+ return this.request('GET', routes.nodeBrokerExtensionState(this.nodePath(id)));
411
+ }
412
+ brokerStructuredRequest(id) {
413
+ return this.request('GET', routes.nodeBrokerStructuredRequest(this.nodePath(id)));
414
+ }
415
+ captureBrokerGoal(id, req) {
416
+ return this.request('POST', routes.nodeBrokerGoal(this.nodePath(id)), req);
417
+ }
418
+ commitBrokerGeneratedName(id, req) {
419
+ return this.request('POST', routes.nodeBrokerGeneratedName(this.nodePath(id)), req);
420
+ }
421
+ commitBrokerPersonaAck(id, req) {
422
+ return this.request('POST', routes.nodeBrokerPersonaAck(this.nodePath(id)), req);
423
+ }
424
+ closeNode(id, req) {
425
+ return this.request('POST', routes.nodeClose(this.nodePath(id)), req ?? {});
426
+ }
427
+ async markNodeRead(id) {
428
+ await this.request('POST', routes.nodeRead(this.nodePath(id)), {});
429
+ }
430
+ recycleNode(id) {
431
+ return this.request('POST', routes.nodeRecycle(this.nodePath(id)), {});
432
+ }
433
+ demoteNode(id) {
434
+ return this.request('POST', routes.nodeDemote(this.nodePath(id)), {});
435
+ }
436
+ promoteNode(id, req) {
437
+ return this.request('POST', routes.nodePromote(this.nodePath(id)), req);
438
+ }
439
+ yieldNode(id, req) {
440
+ return this.request('POST', routes.nodeYield(this.nodePath(id)), req);
441
+ }
442
+ waitNode(id, req) {
443
+ return this.request('POST', routes.nodeWait(this.nodePath(id)), req);
444
+ }
445
+ listKinds() {
446
+ return this.request('GET', routes.kinds());
447
+ }
448
+ /** A model change may first wait up to 30 s for a starting broker's view
449
+ * socket and then 15 s for its ack, so it gets that budget on top. */
450
+ patchConfig(id, patch) {
451
+ return this.request('PATCH', routes.nodeConfig(this.nodePath(id)), patch, patch.model !== undefined ? { timeout: 45_000 + this.timeoutMs } : undefined);
452
+ }
453
+ /** Land + close the node's managed git worktree (spec §6.2). Server-side
454
+ * because it interleaves a canvas WRITE with a git land transaction and
455
+ * crtrd is the repo host (same principle as spawnChild's creation git). */
456
+ closeWorktree(id) {
457
+ return this.request('POST', routes.nodeWorktreeClose(this.nodePath(id)), {});
458
+ }
459
+ abandonWorktree(id, req) {
460
+ return this.request('POST', routes.nodeWorktreeAbandon(this.nodePath(id)), req);
461
+ }
462
+ /** Re-queue a permanently failed push delivery or daemon action with a fresh attempt budget. */
463
+ retryDelivery(deliveryId) {
464
+ return this.request('POST', routes.deliveryRetry(deliveryId), {});
465
+ }
466
+ listQuarantinedWorktrees() {
467
+ return this.request('GET', routes.quarantinedWorktrees());
468
+ }
469
+ /** Effective per-app memory and disk caps and whether this host enforces them. */
470
+ showLimits() {
471
+ return this.request('GET', routes.limits());
472
+ }
473
+ setAppLimits(app, req) {
474
+ return this.request('PUT', routes.limitsApp(app), req);
475
+ }
476
+ removeAppLimits(app, fields) {
477
+ return this.request('DELETE', withQuery(routes.limitsApp(app), { fields: fields.join(',') }));
478
+ }
479
+ /** One page of this runtime's charge rows for a month, or the rows under a reference, with the month's totals; pass `next` back as `after`. */
480
+ listCharges(query = {}) {
481
+ return this.request('GET', withQuery(routes.charges(), query));
482
+ }
483
+ listSpendLimits() {
484
+ return this.request('GET', routes.spendLimits());
485
+ }
486
+ setSpendLimit(id, req) {
487
+ return this.request('PUT', routes.spendLimit(id), req);
488
+ }
489
+ removeSpendLimit(id) {
490
+ return this.request('DELETE', routes.spendLimit(id));
491
+ }
492
+ /** Every space on the runtime with its size. */
493
+ listSpaces() {
494
+ return this.request('GET', routes.spaces());
495
+ }
496
+ subscribe(id, req) {
497
+ return this.request('POST', routes.nodeSubscriptions(this.nodePath(id)), req);
498
+ }
499
+ // Focuses (viewer registry)
500
+ // The tmux verbs that open/move/close a viewer pane run LOCALLY in the
501
+ // caller's session (placement-tmux); only the canvas.db focus rows route here.
502
+ // Reads GC lazily server-side, so a returned row is always live; a `null` body
503
+ // is the normal "no viewer" answer, not a 404.
504
+ listFocuses() {
505
+ return this.request('GET', routes.focuses());
506
+ }
507
+ focusOf(nodeId) {
508
+ return this.request('GET', withQuery(routes.focusByNode(), { node_id: nodeId }));
509
+ }
510
+ focusByPane(pane) {
511
+ return this.request('GET', withQuery(routes.focusByPane(), { pane }));
512
+ }
513
+ registerFocus(req) {
514
+ return this.request('POST', routes.focuses(), req);
515
+ }
516
+ async setFocusPane(focusId, req) {
517
+ await this.request('PATCH', routes.focus(focusId), req);
518
+ }
519
+ async closeFocus(focusId) {
520
+ await this.request('DELETE', routes.focus(focusId));
521
+ }
522
+ async unsubscribe(id, target) {
523
+ await this.request('DELETE', routes.nodeSubscription(this.nodePath(id), this.nodePath(target)));
524
+ }
525
+ /** Arm one cron (`POST /v1/crons`) — the server mints the cron_id. */
526
+ armCron(req) {
527
+ return this.request('POST', routes.crons(), req);
528
+ }
529
+ /** Crons visible to the caller (`GET /v1/crons`). With `q.profile` that is
530
+ * that profile's crons plus every global one; omit it only for a
531
+ * canvas-home-wide provenance read ("which crons did node X arm"). */
532
+ listCrons(q) {
533
+ return this.request('GET', withQuery(routes.crons(), q));
534
+ }
535
+ /** One cron with its run-log ring (`GET /v1/crons/:cronId`). */
536
+ showCron(cronId, q) {
537
+ return this.request('GET', withQuery(routes.cron(this.cronPath(cronId)), q));
538
+ }
539
+ /** Pause one cron (`POST /v1/crons/:cronId/pause`) — stops firing, keeps config+history. */
540
+ pauseCron(cronId, q) {
541
+ return this.request('POST', withQuery(routes.cronPause(this.cronPath(cronId)), q), {});
542
+ }
543
+ /** Resume one paused cron (`POST /v1/crons/:cronId/resume`). */
544
+ resumeCron(cronId, q) {
545
+ return this.request('POST', withQuery(routes.cronResume(this.cronPath(cronId)), q), {});
546
+ }
547
+ /** Run one cron NOW, out of band (`POST /v1/crons/:cronId/run`) — synchronous:
548
+ * resolves with the settled run record after the subprocess closes. Does not
549
+ * advance the schedule or consume a one-shot; never escalates. */
550
+ runCron(cronId, q) {
551
+ return this.request('POST', withQuery(routes.cronRun(this.cronPath(cronId)), q), {});
552
+ }
553
+ /** Cancel one cron (`DELETE /v1/crons/:cronId`, idempotent). */
554
+ async cancelCron(cronId, q) {
555
+ await this.request('DELETE', withQuery(routes.cron(this.cronPath(cronId)), q));
556
+ }
557
+ /** Bare eligibility poke (`POST /v1/crons/poke`): re-dues every held active
558
+ * cron now — "something changed; re-check now". Canvas-wide, label-free,
559
+ * idempotent, and free when nothing is held. */
560
+ pokeCrons() {
561
+ return this.request('POST', routes.cronsPoke(), {});
562
+ }
563
+ ensureAttach(id, req) {
564
+ // The server revives, then waits up to ATTACH_VIEW_WAIT_MS for the broker's view endpoint; the client must outlast both.
565
+ return this.request('POST', routes.nodeAttach(this.nodePath(id)), req ?? {}, { timeout: ATTACH_VIEW_WAIT_MS + this.timeoutMs });
566
+ }
567
+ // Reads / feed
568
+ getReports(id, q) {
569
+ return this.request('GET', withQuery(routes.nodeReports(this.nodePath(id)), q));
570
+ }
571
+ getTranscript(id, q) {
572
+ return this.request('GET', withQuery(routes.nodeTranscript(this.nodePath(id)), q));
573
+ }
574
+ getSnapshot(id) {
575
+ return this.request('GET', routes.nodeSnapshot(this.nodePath(id)));
576
+ }
577
+ /** The node-config subject substrate gates evaluate against. */
578
+ nodeSubject(id) {
579
+ return this.request('GET', routes.nodeSubject(this.nodePath(id)));
580
+ }
581
+ getNodeMessages(id, q) {
582
+ return this.request('GET', withQuery(routes.nodeMessages(this.nodePath(id)), q));
583
+ }
584
+ /** The node's conversation exactly as it ran — raw `.jsonl` bytes plus the
585
+ * assembled system prompt. For exports; `getSnapshot` is for renderers. */
586
+ getSession(id) {
587
+ return this.request('GET', routes.nodeSession(this.nodePath(id)));
588
+ }
589
+ /** What a non-terminal chat surface may offer for this node: the chat-capable
590
+ * slash commands its live engine registered, and the memory documents an
591
+ * inline `/name` token resolves to. Never revives — a node whose broker is
592
+ * not live answers `broker_live: false` with empty arrays. */
593
+ getChatInventory(id) {
594
+ return this.request('GET', routes.nodeChatInventory(this.nodePath(id)));
595
+ }
596
+ getProspectiveChatInventory(q) {
597
+ return this.request('GET', withQuery(routes.prospectiveChatInventory(), q));
598
+ }
599
+ getContext(id) {
600
+ return this.request('GET', routes.nodeContext(this.nodePath(id)));
601
+ }
602
+ // Host file read
603
+ /** Read an absolute host path (capped, `truncated` when clipped). */
604
+ peekFile(path, encoding, options) {
605
+ return this.request('GET', withQuery(routes.filePeek(), { path, encoding }), undefined, options);
606
+ }
607
+ writeFile(path, content, encoding, options) {
608
+ return this.request('POST', routes.fileWrite(), { path, content, encoding }, options);
609
+ }
610
+ listFiles(path, limit, options) {
611
+ return this.request('GET', withQuery(routes.fileList(), { path, limit }), undefined, options);
612
+ }
613
+ runBash(params, options) {
614
+ return this.request('POST', routes.bash(), params, options);
615
+ }
616
+ // Canvas objects and documents
617
+ /** `crtr canvas` shared verbs. A ref is a name (with or without `[[ ]]`) or a raw object id. */
618
+ objects = {
619
+ read: (ref, query) => this.request('GET', withQuery(routes.object(ref), query)),
620
+ list: (query) => this.request('GET', withQuery(routes.objects(), query)),
621
+ search: (request) => this.request('POST', routes.objectsSearch(), request),
622
+ watch: (ref, request = {}) => this.request('POST', routes.objectWatch(ref), request),
623
+ unwatch: (ref, query) => this.request('DELETE', withQuery(routes.objectWatch(ref), query)),
624
+ edges: (ref, query) => this.request('GET', withQuery(routes.objectEdges(ref), query)),
625
+ };
626
+ /** `crtr doc` write verbs. */
627
+ /** One-time cutover: upload a repo's ref tree (and legacy files) into its repo object. */
628
+ importRepoDocs(repo, request) {
629
+ return this.request('POST', routes.repoImport(repo), request);
630
+ }
631
+ renameRepo(repo, to) {
632
+ return this.request('POST', routes.repoRename(repo), { to });
633
+ }
634
+ docs = {
635
+ write: (request) => this.request('POST', routes.docs(), request),
636
+ edit: (ref, request) => this.request('PATCH', routes.doc(ref), request),
637
+ move: (ref, request) => this.request('POST', routes.docMove(ref), request),
638
+ delete: (ref) => this.request('DELETE', routes.doc(ref)),
639
+ history: (ref, query) => this.request('GET', withQuery(routes.docHistory(ref), query)),
640
+ lint: (request = {}) => this.request('POST', routes.docsLint(), request),
641
+ };
642
+ /** Package (builtin and plugin) documents. */
643
+ documents = {
644
+ browserAccess: () => this.request('GET', routes.documentsBrowserAccess()),
645
+ /** `plugins` names the installs a cloud role resolves (a taken name then answers `409 name_taken`); omitted, it resolves all of the app's. */
646
+ reconcilePackages: (opts) => this.request('POST', routes.documentsReconcilePackages(), opts),
647
+ };
648
+ /** A plugin's `crtr_app_` credential and the headers crtrd adds to its local HTTP calls. */
649
+ plugins = {
650
+ appToken: (name) => this.request('GET', routes.pluginAppToken(name)),
651
+ callHeaders: (name, request) => this.request('POST', routes.pluginCallHeaders(name), request),
652
+ };
653
+ /** The broker's delivery of one node activity. */
654
+ nodeDelivery(id, request) {
655
+ return this.request('POST', routes.nodeDelivery(this.nodePath(id)), request);
656
+ }
657
+ /** A person's dry run of one delivery activity, for a live or hypothetical node. Writes nothing. */
658
+ deliveryDryRun(request) {
659
+ return this.request('POST', routes.deliveryDryRun(), request);
660
+ }
661
+ /** Record a backgrounded bash command as a job object. */
662
+ recordBackgroundedJob(id, jobId, request) {
663
+ return this.request('POST', routes.nodeJobBackground(this.nodePath(id), this.jobPath(jobId)), request);
664
+ }
665
+ // Profiles
666
+ /** Create-or-return by name. Supplied `projects` are shape-checked even when
667
+ * the profile already exists; their directories are only required to exist
668
+ * when this call creates the profile. */
669
+ ensureProfile(name, req) {
670
+ return this.request('PUT', routes.profile(name), req ?? {});
671
+ }
672
+ /** Create a profile of the caller's app; a name it already holds is refused. */
673
+ createProfile(req) {
674
+ return this.request('POST', routes.profiles(), req);
675
+ }
676
+ listProfiles() {
677
+ return this.request('GET', routes.profiles());
678
+ }
679
+ /** Rename, set the default kind, or add or remove one project. */
680
+ updateProfile(name, req) {
681
+ return this.request('PATCH', routes.profile(name), req);
682
+ }
683
+ listAppEnv() {
684
+ return this.request('GET', routes.appEnv());
685
+ }
686
+ setAppEnv(variable, value) {
687
+ return this.request('PUT', routes.appEnvVar(variable), { value });
688
+ }
689
+ removeAppEnv(variable) {
690
+ return this.request('DELETE', routes.appEnvVar(variable));
691
+ }
692
+ listProfileEnv(name) {
693
+ return this.request('GET', routes.profileEnv(name));
694
+ }
695
+ setProfileEnv(name, variable, value) {
696
+ return this.request('PUT', routes.profileEnvVar(name, variable), { value });
697
+ }
698
+ removeProfileEnv(name, variable) {
699
+ return this.request('DELETE', routes.profileEnvVar(name, variable));
700
+ }
701
+ /** A profile's cloud environment: recipe, memory and image state. */
702
+ getProfileEnvironment(name) {
703
+ return this.request('GET', routes.profileEnvironment(name));
704
+ }
705
+ /** Change a profile's cloud environment recipe or memory; a field left out keeps its value. */
706
+ setProfileEnvironment(name, req) {
707
+ return this.request('PUT', routes.profileEnvironment(name), req);
708
+ }
709
+ getProfile(name) {
710
+ return this.request('GET', routes.profile(name));
711
+ }
712
+ pauseProfile(name) {
713
+ return this.request('POST', routes.profilePause(name), {});
714
+ }
715
+ resumeProfile(name) {
716
+ return this.request('POST', routes.profileResume(name), {});
717
+ }
718
+ /** Merge and remove entries in a profile's metadata map. */
719
+ updateProfileMetadata(name, req) {
720
+ return this.request('PATCH', routes.profileMetadata(name), req);
721
+ }
722
+ /** Force-delete or detach one profile by exact id or unique name. */
723
+ deleteProfile(name, req) {
724
+ return this.request('DELETE', routes.profile(name), req);
725
+ }
726
+ // Person settings
727
+ getSettings() {
728
+ return this.request('GET', routes.settings());
729
+ }
730
+ putSettings(req) {
731
+ return this.request('PUT', routes.settings(), req);
732
+ }
733
+ // Model auth
734
+ listModelAuth() {
735
+ return this.request('GET', routes.modelAuths());
736
+ }
737
+ getModelAuthReadiness(query) {
738
+ return this.request('GET', withQuery(routes.modelAuthReadiness(), query));
739
+ }
740
+ installCredential(provider, req) {
741
+ return this.request('PUT', routes.modelAuth(provider), req);
742
+ }
743
+ removeCredential(provider) {
744
+ return this.request('DELETE', routes.modelAuth(provider));
745
+ }
746
+ /** Rename a managed account and/or make it the preferred (first) one; answers the provider's sanitized status. */
747
+ patchModelAuthAccount(provider, label, req) {
748
+ return this.request('PATCH', routes.modelAuthAccount(provider, label), req);
749
+ }
750
+ /** Remove one managed account; the provider's other accounts stay. */
751
+ removeModelAuthAccount(provider, label) {
752
+ return this.request('DELETE', routes.modelAuthAccount(provider, label));
753
+ }
754
+ /** `model_auth.start` — the daemon runs the vendor OAuth; the caller only shows `url`. */
755
+ startModelAuth(req) {
756
+ return this.request('POST', routes.modelAuthFlows(), req, { timeout: 30_000 + this.timeoutMs });
757
+ }
758
+ /** `model_auth.complete` — hand the daemon the code the vendor showed. */
759
+ completeModelAuth(flowId, req) {
760
+ return this.request('POST', routes.modelAuthFlowComplete(flowId), req, { timeout: 35_000 + this.timeoutMs });
761
+ }
762
+ /** `model_auth.cancel` — end an in-flight flow the person gave up on; it writes nothing. */
763
+ cancelModelAuth(flowId) {
764
+ return this.request('POST', routes.modelAuthFlowCancel(flowId), {});
765
+ }
766
+ /** A flow's state; `waitSeconds` (1-25) long-polls until it leaves `pending`. */
767
+ getModelAuthFlow(flowId, waitSeconds) {
768
+ return this.request('GET', withQuery(routes.modelAuthFlow(flowId), { wait: waitSeconds }), undefined, { timeout: (waitSeconds ?? 0) * 1_000 + this.timeoutMs });
769
+ }
770
+ // Daemon-owned document reviews and comments
771
+ createReview(req) {
772
+ return this.request('POST', routes.humanReviews(), req);
773
+ }
774
+ listReviews(query) {
775
+ return this.request('GET', withQuery(routes.humanReviews(), query));
776
+ }
777
+ getReview(reviewId) {
778
+ return this.request('GET', routes.humanReview(this.reviewPath(reviewId)));
779
+ }
780
+ submitReview(reviewId) {
781
+ return this.request('POST', routes.humanReviewSubmit(this.reviewPath(reviewId)), {});
782
+ }
783
+ cancelReview(reviewId, req = {}) {
784
+ return this.request('POST', routes.humanReviewCancel(this.reviewPath(reviewId)), req);
785
+ }
786
+ getReviewDocumentBase(reviewId) {
787
+ return this.request('GET', routes.humanReviewDocument(this.reviewPath(reviewId)));
788
+ }
789
+ createReviewComment(reviewId, req) {
790
+ const path = reviewId === undefined ? 'self' : this.reviewPath(reviewId);
791
+ return this.request('POST', routes.humanReviewComments(path), req);
792
+ }
793
+ listReviewComments(reviewId, query) {
794
+ const path = reviewId === undefined ? 'self' : this.reviewPath(reviewId);
795
+ return this.request('GET', withQuery(routes.humanReviewComments(path), query));
796
+ }
797
+ readReviewCommentEvents(reviewId, query) {
798
+ return this.request('GET', withQuery(routes.humanReviewCommentEvents(this.reviewPath(reviewId)), query));
799
+ }
800
+ updateReviewCommentRanges(reviewId, req) {
801
+ return this.request('POST', routes.humanReviewCommentRanges(this.reviewPath(reviewId)), req);
802
+ }
803
+ getReviewComment(commentId) {
804
+ return this.request('GET', routes.humanComment(this.commentPath(commentId)));
805
+ }
806
+ editReviewComment(commentId, req) {
807
+ return this.request('POST', routes.humanCommentEdit(this.commentPath(commentId)), req);
808
+ }
809
+ resolveReviewComment(commentId, req = {}) {
810
+ return this.request('POST', routes.humanCommentResolve(this.commentPath(commentId)), req);
811
+ }
812
+ reopenReviewComment(commentId, req = {}) {
813
+ return this.request('POST', routes.humanCommentReopen(this.commentPath(commentId)), req);
814
+ }
815
+ deleteReviewComment(commentId, req = {}) {
816
+ return this.request('POST', routes.humanCommentDelete(this.commentPath(commentId)), req);
817
+ }
818
+ forkReviewComment(commentId) {
819
+ return this.request('POST', routes.humanCommentFork(this.commentPath(commentId)), {});
820
+ }
821
+ // ---- Humanloop inbox (Northlight crouter-inbox v1, inbox-contract.md §A) --
822
+ /** Pending page/review tickets across every available crouter-owned
823
+ * humanloop root. */
824
+ listHumanInbox() {
825
+ return this.request('GET', routes.humanInbox());
826
+ }
827
+ /** Read one page ticket by its opaque ticket id (pending, resolved, or canceled). */
828
+ getHumanInboxPage(ticketId) {
829
+ return this.request('GET', routes.humanInboxTicket(this.ticketId(ticketId)));
830
+ }
831
+ /** All page tickets, oldest first (pending, resolved, or canceled) —
832
+ * home-wide, or narrowed to one raising node when `nodeId` is given, and to
833
+ * one ticket state when `opts.state` is given. */
834
+ getInboxHistory(nodeId, opts = {}) {
835
+ if (nodeId !== undefined && (typeof nodeId !== 'string' || nodeId === '')) {
836
+ throw new TypeError(`invalid node id: ${JSON.stringify(nodeId)}`);
837
+ }
838
+ return this.request('GET', withQuery(routes.humanInbox() + '/history', { node_id: nodeId, state: opts.state }));
839
+ }
840
+ /** Submit responses for a page ticket. Single-assignment server-side: a competing
841
+ * resolution races to `ticket_already_resolved`. */
842
+ respondHumanInboxPage(ticketId, request) {
843
+ return this.request('POST', routes.humanInboxRespond(this.ticketId(ticketId)), request);
844
+ }
845
+ /** Autosave partial page work. Omitted slots are permitted in progress updates. */
846
+ postInboxProgress(ticketId, responses) {
847
+ return this.request('POST', routes.humanInboxProgress(this.ticketId(ticketId)), { responses });
848
+ }
849
+ /** Get the published response for a resolved page ticket. 404 if pending or canceled. */
850
+ getInboxResponse(ticketId) {
851
+ return this.request('GET', routes.humanInboxResponse(this.ticketId(ticketId)));
852
+ }
853
+ /** Cancel a ticket (terminal response, never deletion). */
854
+ cancelHumanInboxTicket(ticketId, request) {
855
+ return this.request('POST', routes.humanInboxCancel(this.ticketId(ticketId)), request ?? {});
856
+ }
857
+ // Durable programmatic human requests
858
+ /** Create one durable human request. The minted `request_id` identifies the
859
+ * request; inbox presentation has its own ticket id. An unresolvable
860
+ * `action.name` is rejected before the page is published, leaving no inbox
861
+ * row behind. */
862
+ createHumanRequest(request) {
863
+ return this.request('POST', routes.humanRequests(), request);
864
+ }
865
+ /** Product page components registered on the runtime (config + enabled plugins). */
866
+ listPageComponents() {
867
+ return this.request('GET', routes.humanComponents());
868
+ }
869
+ /** Read one request: its current state, its answer when answered, and the
870
+ * delivery state of its completion action when it bound one. */
871
+ getHumanRequest(requestId) {
872
+ return this.request('GET', routes.humanRequest(this.requestPath(requestId)));
873
+ }
874
+ /** Revise a pending request's page in place. Identity, provenance, and the
875
+ * frozen action binding are preserved; a settled request refuses. */
876
+ replaceHumanRequest(requestId, request) {
877
+ return this.request('POST', routes.humanRequestReplace(this.requestPath(requestId)), request);
878
+ }
879
+ /** Settle a request `answered` programmatically. Races a human answer to the
880
+ * same first-writer-wins result. */
881
+ respondHumanRequest(requestId, request) {
882
+ return this.request('POST', routes.humanRequestRespond(this.requestPath(requestId)), request);
883
+ }
884
+ /** The recipient surface closing a request without answering. */
885
+ dismissHumanRequest(requestId, request = {}) {
886
+ return this.request('POST', routes.humanRequestDismiss(this.requestPath(requestId)), request);
887
+ }
888
+ /** The requester withdrawing its own request. */
889
+ cancelHumanRequest(requestId, request = {}) {
890
+ return this.request('POST', routes.humanRequestCancel(this.requestPath(requestId)), request);
891
+ }
892
+ /** Resolve one page feedback comment — the bound companion's report that it
893
+ * has been dealt with. `nodeId` names the caller; the daemon refuses any
894
+ * node but the ticket's companion. Terminal for the comment; appends no
895
+ * chat turn. */
896
+ resolvePageFeedbackComment(ticketId, commentId, nodeId) {
897
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(commentId)) {
898
+ throw new TypeError(`invalid feedback comment id: ${JSON.stringify(commentId)}`);
899
+ }
900
+ return this.request('POST', routes.humanInboxFeedbackResolve(this.ticketId(ticketId), commentId), { node_id: nodeId });
901
+ }
902
+ // Canvas reads / maintenance
903
+ /** Composed client-side from `GET /v1/nodes` + `GET /v1/status` (spec §6.3 —
904
+ * the dashboard is absorbed into those two reads; there is no single route).
905
+ * `generated_at` is the client-side capture instant of the composition. */
906
+ async dashboard(q) {
907
+ const listQuery = q?.under !== undefined ? { under: q.under } : undefined;
908
+ const [nodes, status] = await Promise.all([this.listNodes(listQuery), this.status()]);
909
+ return { nodes, counts: status.node_counts, generated_at: new Date().toISOString() };
910
+ }
911
+ attention() {
912
+ return this.request('GET', routes.canvasAttention());
913
+ }
914
+ /** Per-node pending-ticket counts for a bounded viewer slice. */
915
+ attentionCounts(node_ids) {
916
+ const body = { node_ids };
917
+ return this.request('POST', routes.canvasAttentionCounts(), body);
918
+ }
919
+ /** Ranked/filtered content search over the per-cwd episodic corpus
920
+ * (`crtr canvas history search`). Optional query: ranked when present,
921
+ * recency browse when omitted. POST-bodied — the query carries arrays and
922
+ * free text; the whole search executes server-side (spec §6.3). */
923
+ historySearch(q) {
924
+ return this.request('POST', routes.canvasHistorySearch(), q);
925
+ }
926
+ /** Required-pattern line-hit search over the per-cwd episodic corpus
927
+ * (`crtr canvas history grep`). Distinct stable schema from `historySearch`
928
+ * — POST-bodied for the same reasons. */
929
+ historyGrep(q) {
930
+ return this.request('POST', routes.canvasHistoryGrep(), q);
931
+ }
932
+ /** Resolve one `<node-id>:<relpath>` history ref to its full body
933
+ * (`crtr canvas history read`). */
934
+ historyRead(q) {
935
+ return this.request('GET', withQuery(routes.canvasHistoryRead(), q));
936
+ }
937
+ /** Grouped-count projection over the per-cwd episodic corpus
938
+ * (`crtr canvas history stats`). Same filters as search/grep, aggregate
939
+ * result instead of a hit page — POST-bodied for the same reasons. */
940
+ historyStats(q) {
941
+ return this.request('POST', routes.canvasHistoryStats(), q);
942
+ }
943
+ /** The machine-readable browser canvas roster (`crtr canvas snapshot`) —
944
+ * distinct from the per-node `getSnapshot`. */
945
+ canvasSnapshot() {
946
+ return this.request('GET', routes.canvasSnapshot());
947
+ }
948
+ /** The Analytics page model (`GET /v1/canvas/analytics`). The
949
+ * daemon scans transcripts for the window: a cold 7d scan of ~2 GB of
950
+ * transcripts measured 10 s, and with scan workers capped at 4 a queued
951
+ * request waits about one scan more. 60 s is 3x that worst case; past it the
952
+ * page shows the error instead of computing forever. */
953
+ analytics(q) {
954
+ return this.request('GET', withQuery(routes.canvasAnalytics(), q), undefined, { timeout: 60_000 });
955
+ }
956
+ /** Record memory reads/loads for one node (`POST /v1/nodes/:id/memory-reads`). */
957
+ async recordMemoryReads(nodeId, body) {
958
+ await this.request('POST', routes.nodeMemoryReads(this.nodePath(nodeId)), body);
959
+ }
960
+ /** The lean, set-based topology roster (`GET /v1/canvas/roster`) — exactly
961
+ * two indexed queries server-side, no per-row enrichment. The recurring
962
+ * poll target for attach/browser topology; use `canvasSnapshot` for the
963
+ * enriched on-demand view. */
964
+ liveRoots(q = {}) {
965
+ return this.request('GET', withQuery(routes.canvasLiveRoots(), q));
966
+ }
967
+ canvasRoster() {
968
+ return this.request('GET', routes.canvasRoster());
969
+ }
970
+ /** Explicitly compressed browse snapshot; the Node-only canvas source
971
+ * decompresses it because socketFetch does not interpret content-encoding. */
972
+ async canvasBrowseCompressed() {
973
+ const response = await this.send('GET', routes.canvasBrowse());
974
+ if (!response.ok)
975
+ await parse(response); // retain the normal structured API error
976
+ return new Uint8Array(await response.arrayBuffer());
977
+ }
978
+ /** The lean attach-graph projection: display rows, topology, and focus state
979
+ * in one daemon-owned read rather than the full node-summary list. */
980
+ canvasGraph() {
981
+ return this.request('GET', routes.canvasGraph());
982
+ }
983
+ prune(req) {
984
+ return this.request('POST', routes.canvasPrune(), req);
985
+ }
986
+ // Escape hatch
987
+ /** Raw request for routes not yet method-wrapped. Applies the same
988
+ * autostart + retry + error-mapping semantics. */
989
+ async request(method, path, body, opts) {
990
+ try {
991
+ // The deadline is fixed once here so the headers, the retries and the reading of the body share it.
992
+ const resolved = opts === undefined ? undefined : this.resolveBudget(opts);
993
+ const response = await this.send(method, path, body, resolved);
994
+ return await parse(response, resolved?.deadlineAt);
995
+ }
996
+ catch (error) {
997
+ throw withUnknownOutcome(method, toTransportApiError(error, opts?.signal));
998
+ }
999
+ }
1000
+ /** Open a live response with the normal cold-socket and retry policy, without consuming its body. */
1001
+ async rawResponse(method, path, opts) {
1002
+ try {
1003
+ return await this.send(method, path, undefined, opts);
1004
+ }
1005
+ catch (error) {
1006
+ throw toTransportApiError(error, opts?.signal);
1007
+ }
1008
+ }
1009
+ /** The unparsed request: cold-socket and interrupted-response recovery, plus
1010
+ * the §7 retry policy (connection errors and 429/5xx on GET/HEAD/DELETE
1011
+ * only — POST/PATCH are never replayed once a request has actually been
1012
+ * sent). No JSON parse; every wrapper goes through here. */
1013
+ async send(method, path, body, callOpts = {}) {
1014
+ const opts = this.resolveBudget(callOpts);
1015
+ const idempotent = method === 'GET' || method === 'HEAD' || method === 'DELETE';
1016
+ const maxRetries = opts.maxRetries ?? this.maxRetries;
1017
+ // A hosted runtime being created or replaced answers reads with a refusal that never reached it; wait for it inside this allowance.
1018
+ const replacementWaitEndsAt = Math.min(opts.deadlineAt ?? Infinity, Date.now() + HOSTED_REPLACEMENT_WAIT_MS);
1019
+ for (let attempt = 0;; attempt++) {
1020
+ let response;
1021
+ try {
1022
+ response = await this.transport(method, path, body, opts);
1023
+ }
1024
+ catch (err) {
1025
+ if (this.isColdSocketError(err) || this.isInterruptedSocketError(err)) {
1026
+ const released = this.availabilityFailure?.();
1027
+ if (released !== undefined)
1028
+ throw released;
1029
+ }
1030
+ if (this.isColdSocketError(err)) {
1031
+ try {
1032
+ await this.handleColdSocket(err, opts.deadlineAt);
1033
+ response = await this.transport(method, path, body, opts);
1034
+ }
1035
+ catch (recoveryError) {
1036
+ // The caller's deadline, not the last probe failure, is why the call stopped when it has passed.
1037
+ if (opts.deadlineAt !== undefined && Date.now() >= opts.deadlineAt && !isAbortError(recoveryError, opts.signal))
1038
+ throw deadlineExceeded(opts.deadlineAt);
1039
+ throw toTransportApiError(recoveryError, opts.signal);
1040
+ }
1041
+ }
1042
+ else if (this.isInterruptedSocketError(err) && this.localSocketTransport && (!idempotent || attempt < maxRetries)) {
1043
+ return await this.rideOutInterruptedRequest(method, path, body, opts);
1044
+ }
1045
+ else if (idempotent && attempt < maxRetries && !isAbortError(err, opts.signal) && (!this.localSocketTransport || !this.isInterruptedSocketError(err))) {
1046
+ await sleepWithin(retryDelayMs(attempt + 1), opts);
1047
+ continue;
1048
+ }
1049
+ else {
1050
+ throw toTransportApiError(err, opts.signal);
1051
+ }
1052
+ }
1053
+ if (isRead(method) && maxRetries > 0 && response.status === 503 && await isRefusedBeforeForwarding(response, opts.deadlineAt)) {
1054
+ const delayMs = Math.max(250, (retryAfterHeaderS(response) ?? 0) * 1_000) + Math.random() * 250;
1055
+ // Out of allowance: the refusal itself is the answer, so the caller sees its cause.
1056
+ if (Date.now() + delayMs >= replacementWaitEndsAt)
1057
+ return response;
1058
+ await drainResponseBody(response, opts.deadlineAt);
1059
+ await sleepWithin(delayMs, { signal: opts.signal });
1060
+ continue;
1061
+ }
1062
+ if (idempotent && attempt < maxRetries && isRetryableStatus(response.status)) {
1063
+ await drainResponseBody(response, opts.deadlineAt);
1064
+ await sleepWithin(retryDelayMs(attempt + 1), opts, retryAfterHeaderS(response));
1065
+ continue;
1066
+ }
1067
+ return response;
1068
+ }
1069
+ }
1070
+ // internals
1071
+ resolveBudget(opts) {
1072
+ const { budgetMs, deadlineAt, ...rest } = opts;
1073
+ if (budgetMs === undefined && deadlineAt === undefined)
1074
+ return rest;
1075
+ if (budgetMs !== undefined && (!Number.isFinite(budgetMs) || budgetMs <= 0 || budgetMs > MAX_TIMER_MS))
1076
+ throw new RangeError(`budgetMs must be a positive finite number of at most ${MAX_TIMER_MS}`);
1077
+ if (deadlineAt !== undefined && (!Number.isFinite(deadlineAt) || deadlineAt - Date.now() > MAX_TIMER_MS))
1078
+ throw new RangeError(`deadlineAt must be a finite epoch-millisecond instant at most ${MAX_TIMER_MS} ms from now`);
1079
+ return { ...rest, deadlineAt: Math.min(deadlineAt ?? Infinity, budgetMs === undefined ? Infinity : Date.now() + budgetMs) };
1080
+ }
1081
+ async awaitWithinBudget(promise, deadlineAt) {
1082
+ if (deadlineAt === undefined)
1083
+ return promise;
1084
+ const remainingMs = deadlineAt - Date.now();
1085
+ if (remainingMs <= 0)
1086
+ throw budgetExhausted(deadlineAt);
1087
+ let timer;
1088
+ try {
1089
+ return await Promise.race([
1090
+ promise,
1091
+ new Promise((_resolve, reject) => { timer = setTimeout(() => reject(budgetExhausted(deadlineAt)), remainingMs); }),
1092
+ ]);
1093
+ }
1094
+ finally {
1095
+ if (timer !== undefined)
1096
+ clearTimeout(timer);
1097
+ }
1098
+ }
1099
+ /** One transport attempt, deliberately without retry, cold-socket, or interrupted-response recovery. */
1100
+ async sendOnce(method, path, body, callOpts = {}) {
1101
+ const opts = this.resolveBudget(callOpts);
1102
+ try {
1103
+ return await parse(await this.transport(method, path, body, opts));
1104
+ }
1105
+ catch (error) {
1106
+ throw toTransportApiError(error, opts.signal);
1107
+ }
1108
+ }
1109
+ nodePath(id) {
1110
+ if (!isSafeNodeId(id)) {
1111
+ throw new ApiError(400, 'invalid_node_id', `invalid node id: ${JSON.stringify(id)}`);
1112
+ }
1113
+ return id;
1114
+ }
1115
+ /** Validate a background job id before route construction. Job ids arrive
1116
+ * from the daemon's file-backed roster and must remain one path segment. */
1117
+ jobPath(id) {
1118
+ if (!isSafeBashJobId(id)) {
1119
+ throw new ApiError(400, 'invalid_job_id', `invalid background job id: ${JSON.stringify(id)}`);
1120
+ }
1121
+ return id;
1122
+ }
1123
+ /** Validate a cron id before route construction — `routes.ts` interpolates
1124
+ * it raw, so a value carrying `/`, whitespace or `?` would corrupt the
1125
+ * request line rather than 404 cleanly. Mirrors `nodePath`. */
1126
+ cronPath(id) {
1127
+ if (!isSafeCronId(id)) {
1128
+ throw new ApiError(400, 'invalid_cron_id', `invalid cron id: ${JSON.stringify(id)}`);
1129
+ }
1130
+ return id;
1131
+ }
1132
+ /** Validate a request id before route construction. Requests use the daemon's
1133
+ * node-id-shaped identifiers, while inbox presentation uses a separate ticket
1134
+ * id. A malformed request id is a server-rejectable request. */
1135
+ requestPath(id) {
1136
+ if (!isSafeNodeId(id)) {
1137
+ throw new ApiError(400, 'invalid_request_id', `invalid request id: ${JSON.stringify(id)}`);
1138
+ }
1139
+ return id;
1140
+ }
1141
+ /** Validate an opaque inbox ticket id before route construction. A local
1142
+ * shape violation is a caller bug, not a server-rejectable request — throws
1143
+ * `TypeError` (matching the existing safe-segment discipline of a local
1144
+ * precondition, distinct from `nodePath`'s `ApiError` because that one IS a
1145
+ * request the server could plausibly receive and reject itself). */
1146
+ ticketId(id) {
1147
+ if (!/^[a-f0-9]{64}$/.test(id)) {
1148
+ throw new TypeError(`invalid inbox ticket id: ${JSON.stringify(id)}`);
1149
+ }
1150
+ return id;
1151
+ }
1152
+ /** Validate a review id before route construction (D-A6). Reviews are minted
1153
+ * and addressed like node ids, but arrive from agent argv, so a malformed
1154
+ * one is a plausible request the server would also reject — `ApiError`,
1155
+ * not `TypeError`, matching `nodePath`. */
1156
+ reviewPath(id) {
1157
+ if (!isSafeNodeId(id)) {
1158
+ throw new ApiError(400, 'invalid_review_id', `invalid review id: ${JSON.stringify(id)}`);
1159
+ }
1160
+ return id;
1161
+ }
1162
+ /** Validate a comment id before route construction (D-A6). Comment ids are
1163
+ * daemon-minted 32-char lowercase hex, but — like `reviewPath` — arrive from
1164
+ * agent argv, so a bad one is a plausible request the server would also
1165
+ * reject, not a caller-bug `TypeError` like `ticketId`. */
1166
+ commentPath(id) {
1167
+ if (!/^[a-f0-9]{32}$/.test(id)) {
1168
+ throw new ApiError(400, 'invalid_comment_id', `invalid comment id: ${JSON.stringify(id)}`);
1169
+ }
1170
+ return id;
1171
+ }
1172
+ /** The one fetch path (§1). Resolves as soon as headers arrive — the body
1173
+ * stays an unread `ReadableStream` on the returned `Response`, so a caller
1174
+ * that wants to stream (SSE, later) never waits on a buffered body. */
1175
+ transport(method, path, body, opts = {}) {
1176
+ const remainingBudgetMs = opts.deadlineAt === undefined ? undefined : opts.deadlineAt - Date.now();
1177
+ if (remainingBudgetMs !== undefined && remainingBudgetMs <= 0)
1178
+ return Promise.reject(budgetExhausted(opts.deadlineAt));
1179
+ const payload = body === undefined ? undefined : JSON.stringify(body);
1180
+ const headers = { accept: 'application/json', ...this.headers, ...opts.headers };
1181
+ if (payload !== undefined)
1182
+ headers['content-type'] = 'application/json';
1183
+ const baseTimeoutMs = opts.timeout ?? this.timeoutMs;
1184
+ const timeoutMs = remainingBudgetMs === undefined
1185
+ ? baseTimeoutMs
1186
+ : baseTimeoutMs > 0 ? Math.min(baseTimeoutMs, remainingBudgetMs) : remainingBudgetMs;
1187
+ const controller = new AbortController();
1188
+ // The deadline, not the per-attempt timeout, ended this attempt when it was the nearer of the two.
1189
+ const deadlineEnds = remainingBudgetMs !== undefined && (baseTimeoutMs <= 0 || remainingBudgetMs <= baseTimeoutMs);
1190
+ const timer = timeoutMs > 0
1191
+ ? setTimeout(() => controller.abort(deadlineEnds ? budgetExhausted(opts.deadlineAt) : new DOMException('request timed out', 'TimeoutError')), timeoutMs)
1192
+ : undefined;
1193
+ const externalSignal = opts.signal;
1194
+ const onExternalAbort = () => controller.abort(externalSignal?.reason);
1195
+ if (externalSignal !== undefined) {
1196
+ if (externalSignal.aborted)
1197
+ controller.abort(externalSignal.reason);
1198
+ else
1199
+ externalSignal.addEventListener('abort', onExternalAbort, { once: true });
1200
+ }
1201
+ const finish = () => {
1202
+ if (timer !== undefined)
1203
+ clearTimeout(timer);
1204
+ externalSignal?.removeEventListener('abort', onExternalAbort);
1205
+ };
1206
+ return abortable(this.fetch(new URL(path, this.baseUrl), { method, headers, body: payload, signal: controller.signal }), controller.signal)
1207
+ .then((response) => this.retainRequestLifetime(response, finish, () => controller.signal.aborted ? controller.signal.reason : undefined), (error) => {
1208
+ finish();
1209
+ throw error;
1210
+ });
1211
+ }
1212
+ retainRequestLifetime(response, finish, abortReason) {
1213
+ if (response.body === null) {
1214
+ finish();
1215
+ return response;
1216
+ }
1217
+ const reader = response.body.getReader();
1218
+ let finished = false;
1219
+ const close = () => {
1220
+ if (finished)
1221
+ return;
1222
+ finished = true;
1223
+ finish();
1224
+ };
1225
+ const body = new ReadableStream({
1226
+ async pull(controller) {
1227
+ try {
1228
+ const { done, value } = await reader.read();
1229
+ if (done) {
1230
+ close();
1231
+ controller.close();
1232
+ }
1233
+ else {
1234
+ controller.enqueue(value);
1235
+ }
1236
+ }
1237
+ catch (error) {
1238
+ close();
1239
+ controller.error(abortReason() ?? error);
1240
+ }
1241
+ },
1242
+ async cancel(reason) {
1243
+ close();
1244
+ await reader.cancel(reason);
1245
+ },
1246
+ });
1247
+ return new Response(body, { status: response.status, statusText: response.statusText, headers: response.headers });
1248
+ }
1249
+ isColdSocketError(err) {
1250
+ const code = transportErrorCode(err);
1251
+ return code === 'ECONNREFUSED' || code === 'ENOENT' || code === 'ENOTSOCK';
1252
+ }
1253
+ /** A connection torn down MID-request (Node's "socket hang up" / a broken
1254
+ * pipe). It establishes only that the response was interrupted, not why. */
1255
+ isInterruptedSocketError(err) {
1256
+ const code = transportErrorCode(err);
1257
+ return code === 'ECONNRESET' || code === 'EPIPE';
1258
+ }
1259
+ /** Wait for the local API after an interrupted response. GET/HEAD can retry
1260
+ * because they are idempotent. A mutation may already have been applied, so
1261
+ * it never replays. */
1262
+ async rideOutInterruptedRequest(method, path, body, opts = {}) {
1263
+ try {
1264
+ await this.awaitAvailability(undefined, opts.deadlineAt);
1265
+ }
1266
+ catch (error) {
1267
+ throw toTransportApiError(error, opts.signal);
1268
+ }
1269
+ if (method !== 'GET' && method !== 'HEAD') {
1270
+ throw new ApiError(503, 'daemon_request_interrupted', `crtrd connection ended before this ${method} response; the request may or may not have been applied.`);
1271
+ }
1272
+ try {
1273
+ return await this.transport(method, path, body, opts);
1274
+ }
1275
+ catch (err) {
1276
+ throw toTransportApiError(err, opts.signal);
1277
+ }
1278
+ }
1279
+ async awaitAvailability(initialError, deadlineAt) {
1280
+ const remainingBudgetMs = deadlineAt === undefined ? undefined : deadlineAt - Date.now();
1281
+ if (remainingBudgetMs !== undefined && remainingBudgetMs <= 0)
1282
+ throw budgetExhausted(deadlineAt);
1283
+ let startupFailure;
1284
+ let releaseFailure;
1285
+ try {
1286
+ await waitForDaemonAvailability({
1287
+ windowMs: Math.min(this.coldStartPollWindowMs, remainingBudgetMs ?? this.coldStartPollWindowMs),
1288
+ initialError,
1289
+ retry: (error) => error !== startupFailure && error !== releaseFailure,
1290
+ probe: async (timeoutMs) => {
1291
+ const unavailable = this.availabilityFailure?.();
1292
+ if (unavailable !== undefined) {
1293
+ releaseFailure = unavailable;
1294
+ throw unavailable;
1295
+ }
1296
+ const failure = this.coldStartFailure?.();
1297
+ if (failure !== undefined) {
1298
+ startupFailure = new ApiError(503, 'daemon_unavailable', `crtrd failed to start: ${failure}`);
1299
+ throw startupFailure;
1300
+ }
1301
+ const response = await this.transport('GET', routes.healthz(), undefined, { timeout: timeoutMs });
1302
+ if (response.status >= 200 && response.status < 300) {
1303
+ await drainResponseBody(response);
1304
+ return;
1305
+ }
1306
+ const text = await response.text();
1307
+ try {
1308
+ const health = JSON.parse(text);
1309
+ if (typeof health.startup_blocked === 'string')
1310
+ return;
1311
+ }
1312
+ catch {
1313
+ // The normal unavailable error below carries the response body.
1314
+ }
1315
+ throw new ApiError(response.status, 'daemon_health_unavailable', `crtrd health check returned HTTP ${response.status}: ${text.slice(0, 500)}`);
1316
+ },
1317
+ });
1318
+ }
1319
+ catch (error) {
1320
+ if (error === startupFailure)
1321
+ this.startupFailureReported = true;
1322
+ throw error;
1323
+ }
1324
+ }
1325
+ /** Optionally start the daemon, then observe availability before retrying the
1326
+ * request. Waiting is independent from permission to spawn: externally
1327
+ * managed daemons still get the same bounded readiness window. */
1328
+ async handleColdSocket(initialError, deadlineAt) {
1329
+ const startedHere = this.autostart && this.onColdSocket !== undefined && !this.coldStartAttempted;
1330
+ if (startedHere) {
1331
+ this.coldStartAttempted = true;
1332
+ await this.awaitWithinBudget(this.onColdSocket(), deadlineAt);
1333
+ }
1334
+ try {
1335
+ await this.awaitAvailability(initialError, deadlineAt);
1336
+ }
1337
+ catch (error) {
1338
+ if (startedHere && !this.startupFailureReported) {
1339
+ const diagnostic = safeColdStartDiagnostic(this.coldStartDiagnostic);
1340
+ if (diagnostic !== undefined) {
1341
+ const transportError = toTransportApiError(error);
1342
+ throw new ApiError(transportError.status, transportError.code, `${transportError.message}\n${diagnostic}`);
1343
+ }
1344
+ }
1345
+ throw error;
1346
+ }
1347
+ }
1348
+ }
1349
+ /** Append defined query params to a path. Kept in the client (not `routes.ts`,
1350
+ * which stays logic-free). Undefined/null values are skipped. */
1351
+ function withQuery(base, query) {
1352
+ if (query === undefined)
1353
+ return base;
1354
+ const params = new URLSearchParams();
1355
+ for (const [key, value] of Object.entries(query)) {
1356
+ if (value !== undefined && value !== null)
1357
+ params.set(key, String(value));
1358
+ }
1359
+ const qs = params.toString();
1360
+ return qs === '' ? base : `${base}?${qs}`;
1361
+ }
1362
+ /** Parse a response into `T` — the first (and here, only) read of its body —
1363
+ * or throw `ApiError` on non-2xx. A 204/empty body yields `undefined`
1364
+ * (callers that type `void`/optional handle it). */
1365
+ async function parse(res, deadlineAt) {
1366
+ const ok = res.status >= 200 && res.status < 300;
1367
+ const trimmed = (await readTextWithin(res, deadlineAt)).trim();
1368
+ let payload;
1369
+ if (trimmed !== '') {
1370
+ try {
1371
+ payload = JSON.parse(trimmed);
1372
+ }
1373
+ catch {
1374
+ if (ok)
1375
+ return undefined;
1376
+ throw new ApiError(res.status, 'invalid_response', trimmed.slice(0, 500), undefined, res.headers);
1377
+ }
1378
+ }
1379
+ if (ok)
1380
+ return payload;
1381
+ if (isErrorBody(payload)) {
1382
+ throw new ApiError(res.status, payload.error.code, payload.error.message, payload.error.details, res.headers, payload.error);
1383
+ }
1384
+ throw new ApiError(res.status, 'internal', `request failed with status ${res.status}`, undefined, res.headers);
1385
+ }
1386
+ /** How long a read waits for a hosted runtime that is being created or replaced. */
1387
+ const HOSTED_REPLACEMENT_WAIT_MS = 60_000;
1388
+ /** Only reads are replayed after a refusal; a write is never retried on this state. */
1389
+ function isRead(method) {
1390
+ return method === 'GET' || method === 'HEAD';
1391
+ }
1392
+ /** True when the response is the hosting router's 503 for a runtime that provisioning is creating or replacing
1393
+ * (`details.forwarded === false`): the request reached no runtime, so replaying it cannot run anything twice.
1394
+ * Reads a clone, so the caller still gets the body of the response it is handed. */
1395
+ async function isRefusedBeforeForwarding(response, deadlineAt) {
1396
+ try {
1397
+ // A router refusal is a few hundred bytes; anything declared larger, or a body that stalls, is not one.
1398
+ if (Number(response.headers.get('content-length') ?? 0) > 8_192)
1399
+ return false;
1400
+ const text = await readTextWithin(response.clone(), Math.min(deadlineAt ?? Infinity, Date.now() + 5_000));
1401
+ const error = JSON.parse(text).error;
1402
+ return error?.origin === 'router' && error.details?.forwarded === false
1403
+ && (error.details.runtime_state === 'creating' || error.details.runtime_state === 'recovering');
1404
+ }
1405
+ catch {
1406
+ return false;
1407
+ }
1408
+ }
1409
+ /** `429`/`5xx` are the only statuses the §7 retry policy replays. */
1410
+ function isRetryableStatus(status) {
1411
+ return status === 429 || status >= 500;
1412
+ }
1413
+ /** A response abandoned mid-retry must have its stream drained, or the
1414
+ * underlying connection (and, over a unix socket, the daemon's handler) is
1415
+ * held open by a reader that will never arrive. */
1416
+ async function drainResponseBody(res, deadlineAt) {
1417
+ const cancelled = (async () => {
1418
+ try {
1419
+ await res.body?.cancel();
1420
+ }
1421
+ catch {
1422
+ // Best-effort — the response is being discarded either way.
1423
+ }
1424
+ })();
1425
+ // A body whose cancel never settles must not hold the call past its deadline: stop waiting for it then.
1426
+ if (deadlineAt === undefined)
1427
+ return cancelled;
1428
+ let timer;
1429
+ try {
1430
+ await Promise.race([cancelled, new Promise((resolve) => { timer = setTimeout(resolve, Math.max(0, deadlineAt - Date.now())); })]);
1431
+ }
1432
+ finally {
1433
+ if (timer !== undefined)
1434
+ clearTimeout(timer);
1435
+ }
1436
+ }
1437
+ /** The response body as text, or `deadline_exceeded` once `deadlineAt` passes first (the body is then cancelled
1438
+ * without waiting for it). A transport that sends headers and then stalls cannot hold the call past its deadline. */
1439
+ async function readTextWithin(res, deadlineAt) {
1440
+ if (deadlineAt === undefined)
1441
+ return res.text();
1442
+ const remaining = deadlineAt - Date.now();
1443
+ const reading = res.text();
1444
+ reading.catch(() => { });
1445
+ if (remaining <= 0) {
1446
+ void res.body?.cancel().catch(() => { });
1447
+ throw deadlineExceeded(deadlineAt);
1448
+ }
1449
+ let timer;
1450
+ try {
1451
+ return await Promise.race([
1452
+ reading,
1453
+ new Promise((_resolve, reject) => { timer = setTimeout(() => { void res.body?.cancel().catch(() => { }); reject(deadlineExceeded(deadlineAt)); }, remaining); }),
1454
+ ]);
1455
+ }
1456
+ finally {
1457
+ if (timer !== undefined)
1458
+ clearTimeout(timer);
1459
+ }
1460
+ }
1461
+ /** Exponential backoff for the §7 retry policy: 250ms, 500ms, 1s, capped at 2s. */
1462
+ function retryDelayMs(attempt) {
1463
+ return Math.min(2_000, 250 * 2 ** (attempt - 1));
1464
+ }
1465
+ /** The underlying `errno`-style code beneath a fetch failure. Native `fetch`
1466
+ * wraps a connection error as `TypeError('fetch failed', { cause })`; the
1467
+ * Node-only socket `fetch` (`api/node-transport.ts`) preserves the same
1468
+ * shape so both transports classify identically here. */
1469
+ function transportErrorCode(err) {
1470
+ if (typeof err !== 'object' || err === null)
1471
+ return undefined;
1472
+ const direct = err.code;
1473
+ if (typeof direct === 'string')
1474
+ return direct;
1475
+ const cause = err.cause;
1476
+ if (typeof cause === 'object' && cause !== null) {
1477
+ const causeCode = cause.code;
1478
+ if (typeof causeCode === 'string')
1479
+ return causeCode;
1480
+ }
1481
+ return undefined;
1482
+ }
1483
+ /** True when a transport throw is the caller's OWN abort, as opposed to the
1484
+ * client's internal per-request timeout — an aborted request must never be
1485
+ * retried, whichever reason fired. */
1486
+ function isAbortError(err, signal) {
1487
+ if (signal?.aborted)
1488
+ return true;
1489
+ return err instanceof DOMException && (err.name === 'AbortError' || err.name === 'TimeoutError');
1490
+ }
1491
+ /** Map a transport-layer throw (never an HTTP status) to an `ApiError`. A
1492
+ * connection refusal here means the daemon is unreachable and autostart could
1493
+ * not recover it. */
1494
+ function toTransportApiError(err, signal) {
1495
+ if (signal?.aborted) {
1496
+ return new ApiError(0, 'request_aborted', 'request aborted by caller signal');
1497
+ }
1498
+ if (err instanceof ApiError)
1499
+ return err;
1500
+ if (err instanceof DOMException && err.name === 'TimeoutError') {
1501
+ return new ApiError(504, 'request_timeout', `crtrd request timed out: ${err.message}`);
1502
+ }
1503
+ if (err instanceof DOMException && err.name === 'AbortError') {
1504
+ return new ApiError(0, 'request_aborted', 'request aborted by caller signal');
1505
+ }
1506
+ const code = transportErrorCode(err);
1507
+ const message = err instanceof Error ? err.message : String(err);
1508
+ if (code === 'ECONNREFUSED' || code === 'ENOENT' || code === 'ENOTSOCK') {
1509
+ return new ApiError(503, 'daemon_unavailable', `crtrd is not reachable: ${message}`);
1510
+ }
1511
+ if (code === 'ETIMEDOUT') {
1512
+ // A per-request timeout against a REACHABLE daemon is not "crtrd not running"
1513
+ // (§8 reserves daemon_unavailable for unreachable/autostart-failed).
1514
+ return new ApiError(504, 'request_timeout', `crtrd request timed out: ${message}`);
1515
+ }
1516
+ return new ApiError(503, 'transport_error', message);
1517
+ }
1518
+ /** A mutation that timed out waiting for its answer was sent and never replayed, so the daemon may have committed it. The
1519
+ * error says so, and `details.outcome` lets the CLI tell the caller to check state before retrying. */
1520
+ function withUnknownOutcome(method, error) {
1521
+ if (method === 'GET' || method === 'HEAD' || error.status !== 504 || error.code !== 'request_timeout')
1522
+ return error;
1523
+ return new ApiError(error.status, error.code, `${error.message}; the ${method} request was sent, so it may or may not have been applied`, { outcome: 'unknown' }, error.headers);
1524
+ }
1525
+ /** The `Retry-After` header as seconds (delta-seconds form only), else undefined. */
1526
+ function retryAfterHeaderS(response) {
1527
+ const seconds = Number(response.headers.get('retry-after'));
1528
+ return Number.isFinite(seconds) && seconds > 0 ? seconds : undefined;
1529
+ }
1530
+ /** One retry wait inside a call's deadline. A server-requested wait (`retryAfterS`) is honored only against a deadline:
1531
+ * when it would not finish before the deadline the call fails now with `deadline_exceeded` (`reason: 'retry_after'`)
1532
+ * instead of sleeping past it; a call without a deadline keeps the plain backoff. The sleep ends early, with the same
1533
+ * error, if the caller aborts. */
1534
+ export async function sleepWithin(backoffMs, opts, retryAfterS, cause) {
1535
+ const { deadlineAt, signal } = opts;
1536
+ if (signal?.aborted)
1537
+ throw new ApiError(0, 'request_aborted', 'request aborted by caller signal');
1538
+ const requestedMs = deadlineAt !== undefined && retryAfterS !== undefined ? retryAfterS * 1_000 : undefined;
1539
+ const waitMs = Math.max(backoffMs, requestedMs ?? 0);
1540
+ if (deadlineAt !== undefined && Date.now() + waitMs >= deadlineAt) {
1541
+ const error = deadlineExceeded(deadlineAt, requestedMs !== undefined && requestedMs >= backoffMs ? 'retry_after' : 'elapsed', requestedMs === undefined ? undefined : retryAfterS);
1542
+ if (cause !== undefined)
1543
+ Object.defineProperty(error, 'cause', { value: cause, configurable: true, writable: true });
1544
+ throw error;
1545
+ }
1546
+ if (signal === undefined)
1547
+ return sleepMs(waitMs);
1548
+ await new Promise((resolve, reject) => {
1549
+ const onAbort = () => { clearTimeout(timer); signal.removeEventListener('abort', onAbort); reject(new ApiError(0, 'request_aborted', 'request aborted by caller signal')); };
1550
+ const timer = setTimeout(() => { signal.removeEventListener('abort', onAbort); resolve(); }, waitMs);
1551
+ signal.addEventListener('abort', onAbort, { once: true });
1552
+ });
1553
+ }
1554
+ /** `pending`, or its rejection with the signal's reason once the signal aborts first. A transport that ignores its
1555
+ * signal (a custom `fetch`) therefore still ends at the call's deadline; a response that arrives after the abort is
1556
+ * discarded and its body cancelled. */
1557
+ function abortable(pending, signal) {
1558
+ return new Promise((resolve, reject) => {
1559
+ const onAbort = () => reject(signal.reason);
1560
+ if (signal.aborted)
1561
+ onAbort();
1562
+ else
1563
+ signal.addEventListener('abort', onAbort, { once: true });
1564
+ pending.then((response) => {
1565
+ signal.removeEventListener('abort', onAbort);
1566
+ if (signal.aborted)
1567
+ void response.body?.cancel().catch(() => { });
1568
+ else
1569
+ resolve(response);
1570
+ }, (error) => { signal.removeEventListener('abort', onAbort); reject(error); });
1571
+ });
1572
+ }
1573
+ function sleepMs(ms) {
1574
+ return new Promise((resolve) => setTimeout(resolve, ms));
1575
+ }
1576
+ export function safeColdStartDiagnostic(hook) {
1577
+ if (hook === undefined)
1578
+ return undefined;
1579
+ try {
1580
+ return hook();
1581
+ }
1582
+ catch {
1583
+ return undefined;
1584
+ }
1585
+ }