@north-light/cli 0.3.668 → 0.3.669

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 (1130) 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/deliver-live.js +1 -1
  82. package/dist/core/runtime/resume-root.d.ts +1 -0
  83. package/dist/core/runtime/resume-root.js +7 -7
  84. package/dist/core/runtime/runner/machine/call.js +2 -2
  85. package/dist/core/runtime/runner/machine/executor.d.ts +1 -1
  86. package/dist/core/runtime/runner/machine/ops.d.ts +11 -1
  87. package/dist/core/runtime/runner/machine/ops.js +1 -1
  88. package/dist/core/scope.js +1 -1
  89. package/dist/core/scoped-state/db.js +2 -2
  90. package/dist/core/scoped-state/legacy-profiles.js +2 -1
  91. package/dist/core/scoped-state/person-rows.js +6 -3
  92. package/dist/core/scoped-state/schema.d.ts +4 -0
  93. package/dist/core/scoped-state/schema.js +5 -4
  94. package/dist/core/substrate/delivery/deliver.js +2 -2
  95. package/dist/core/substrate/delivery/plan.js +2 -3
  96. package/dist/core/substrate/subject.js +1 -1
  97. package/dist/daemon/api/canvas-host.d.ts +1 -0
  98. package/dist/daemon/api/canvas-host.js +1 -1
  99. package/dist/daemon/api/document-page.js +5 -5
  100. package/dist/daemon/api/handlers/broker-ops.js +1 -1
  101. package/dist/daemon/api/handlers/delivery.js +1 -1
  102. package/dist/daemon/api/handlers/docs.d.ts +1 -12
  103. package/dist/daemon/api/handlers/docs.js +2 -2
  104. package/dist/daemon/api/handlers/memory.js +1 -1
  105. package/dist/daemon/api/handlers/objects.js +1 -1
  106. package/dist/daemon/api/handlers/profiles.d.ts +1 -1
  107. package/dist/daemon/api/handlers/profiles.js +1 -1
  108. package/dist/daemon/api/handlers/repo-import.d.ts +2 -0
  109. package/dist/daemon/api/handlers/repo-import.js +2 -0
  110. package/dist/daemon/api/handlers/reviews.js +1 -1
  111. package/dist/daemon/api/handlers/shares.js +1 -1
  112. package/dist/daemon/api/operations.js +1 -1
  113. package/dist/daemon/api/reader.js +1 -1
  114. package/dist/daemon/api/repo-plugin.d.ts +12 -0
  115. package/dist/daemon/api/repo-plugin.js +1 -0
  116. package/dist/daemon/api/server.js +1 -1
  117. package/dist/daemon/boot-migrations.js +1 -1
  118. package/dist/daemon/crtrd.js +13 -13
  119. package/dist/daemon/due-sources.d.ts +1 -1
  120. package/dist/daemon/due-sources.js +1 -1
  121. package/dist/daemon/due.js +7 -7
  122. package/dist/daemon/machine-daemon.js +1 -1
  123. package/dist/daemon/reconcilers/group-invite-expiry.d.ts +9 -0
  124. package/dist/daemon/reconcilers/group-invite-expiry.js +1 -0
  125. package/dist/daemon/review/finish.js +1 -1
  126. package/dist/migrations/004-canvas-documents/index.js +2 -2
  127. package/dist/pi-extensions/canvas-structured-output.js +6 -6
  128. package/docs/concepts/documents.md +1 -1
  129. package/package.json +10 -2
  130. package/packages/crouter-api/dist/api/client.js +1585 -0
  131. package/packages/crouter-api/dist/api/command-manifest/index.js +4 -0
  132. package/packages/crouter-api/dist/api/command-manifest/manifest.js +332 -0
  133. package/packages/crouter-api/dist/api/command-manifest/object-kinds.js +100 -0
  134. package/packages/crouter-api/dist/api/command-manifest/result.js +166 -0
  135. package/packages/crouter-api/dist/api/command-manifest/schema.js +934 -0
  136. package/packages/crouter-api/dist/api/contract.js +57 -0
  137. package/packages/crouter-api/dist/api/dto/analytics.js +3 -0
  138. package/packages/crouter-api/dist/api/dto/attach.js +13 -0
  139. package/packages/crouter-api/dist/api/dto/bash-jobs.js +11 -0
  140. package/packages/crouter-api/dist/api/dto/bash.js +1 -0
  141. package/packages/crouter-api/dist/api/dto/broker-ops.js +6 -0
  142. package/packages/crouter-api/dist/api/dto/broker-signals.js +1 -0
  143. package/packages/crouter-api/dist/api/dto/broker.js +20 -0
  144. package/packages/crouter-api/dist/api/dto/canvas.js +2 -0
  145. package/packages/crouter-api/dist/api/dto/charges.js +4 -0
  146. package/packages/crouter-api/dist/api/dto/chat-inventory.js +11 -0
  147. package/packages/crouter-api/dist/api/dto/common.js +15 -0
  148. package/packages/crouter-api/dist/api/dto/config.js +3 -0
  149. package/packages/crouter-api/dist/api/dto/crons.js +10 -0
  150. package/packages/crouter-api/dist/api/dto/custom-objects.js +1 -0
  151. package/packages/crouter-api/dist/api/dto/delivery.js +7 -0
  152. package/packages/crouter-api/dist/api/dto/docs.js +8 -0
  153. package/packages/crouter-api/dist/api/dto/environments.js +2 -0
  154. package/packages/crouter-api/dist/api/dto/exec.js +1 -0
  155. package/packages/crouter-api/dist/api/dto/execution-start.js +2 -0
  156. package/packages/crouter-api/dist/api/dto/files.js +1 -0
  157. package/packages/crouter-api/dist/api/dto/focus.js +10 -0
  158. package/packages/crouter-api/dist/api/dto/grants.js +1 -0
  159. package/packages/crouter-api/dist/api/dto/health.js +2 -0
  160. package/packages/crouter-api/dist/api/dto/human-requests.js +4 -0
  161. package/packages/crouter-api/dist/api/dto/human.js +4 -0
  162. package/packages/crouter-api/dist/api/dto/imports.js +2 -0
  163. package/packages/crouter-api/dist/api/dto/inbox.js +4 -0
  164. package/packages/crouter-api/dist/api/dto/lifecycle.js +3 -0
  165. package/packages/crouter-api/dist/api/dto/limits.js +2 -0
  166. package/packages/crouter-api/dist/api/dto/mail.js +1 -0
  167. package/packages/crouter-api/dist/api/dto/messages.js +2 -0
  168. package/packages/crouter-api/dist/api/dto/model-config.js +1 -0
  169. package/packages/crouter-api/dist/api/dto/modelauth.js +4 -0
  170. package/packages/crouter-api/dist/api/dto/node-events.js +4 -0
  171. package/packages/crouter-api/dist/api/dto/node-outcomes.js +2 -0
  172. package/packages/crouter-api/dist/api/dto/node-records.js +5 -0
  173. package/packages/crouter-api/dist/api/dto/nodes.js +3 -0
  174. package/packages/crouter-api/dist/api/dto/objects.js +5 -0
  175. package/packages/crouter-api/dist/api/dto/permissions.js +5 -0
  176. package/packages/crouter-api/dist/api/dto/plugins.js +5 -0
  177. package/packages/crouter-api/dist/api/dto/profiles.js +8 -0
  178. package/packages/crouter-api/dist/api/dto/recovery.js +1 -0
  179. package/packages/crouter-api/dist/api/dto/repo-import.js +5 -0
  180. package/packages/crouter-api/dist/api/dto/reports.js +2 -0
  181. package/packages/crouter-api/dist/api/dto/review-comments.js +5 -0
  182. package/packages/crouter-api/dist/api/dto/reviews.js +5 -0
  183. package/packages/crouter-api/dist/api/dto/run-events.js +6 -0
  184. package/packages/crouter-api/dist/api/dto/settings.js +4 -0
  185. package/packages/crouter-api/dist/api/dto/structured-requests.js +5 -0
  186. package/packages/crouter-api/dist/api/dto/subscriptions.js +2 -0
  187. package/packages/crouter-api/dist/api/dto/usage.js +1 -0
  188. package/packages/crouter-api/dist/api/dto/worktree.js +6 -0
  189. package/packages/crouter-api/dist/api/error-codes.js +86 -0
  190. package/packages/crouter-api/dist/api/errors.js +72 -0
  191. package/packages/crouter-api/dist/api/index.js +55 -0
  192. package/packages/crouter-api/dist/api/long-poll.js +67 -0
  193. package/packages/crouter-api/dist/api/node-transport.js +105 -0
  194. package/packages/crouter-api/dist/api/plugin-manifest-schema.js +23 -0
  195. package/packages/crouter-api/dist/api/routes.js +233 -0
  196. package/packages/crouter-api/dist/api/runtime-version.js +50 -0
  197. package/packages/crouter-api/dist/build-root.js +411 -0
  198. package/packages/crouter-api/dist/clients/attach/ansi-cells.js +137 -0
  199. package/packages/crouter-api/dist/clients/attach/chrome/bash-jobs.js +34 -0
  200. package/packages/crouter-api/dist/clients/attach/chrome/canvas-panels.js +267 -0
  201. package/packages/crouter-api/dist/clients/attach/chrome/completion-bell.js +89 -0
  202. package/packages/crouter-api/dist/clients/attach/chrome/cron-wait.js +34 -0
  203. package/packages/crouter-api/dist/clients/attach/chrome/git-info.js +44 -0
  204. package/packages/crouter-api/dist/clients/attach/chrome/header.js +30 -0
  205. package/packages/crouter-api/dist/clients/attach/chrome/inbox-strip.js +219 -0
  206. package/packages/crouter-api/dist/clients/attach/chrome/key-hint.js +16 -0
  207. package/packages/crouter-api/dist/clients/attach/chrome/object-wait.js +24 -0
  208. package/packages/crouter-api/dist/clients/attach/chrome/recap.js +19 -0
  209. package/packages/crouter-api/dist/clients/attach/chrome/review-wait.js +22 -0
  210. package/packages/crouter-api/dist/clients/attach/chrome/roster.js +293 -0
  211. package/packages/crouter-api/dist/clients/attach/chrome/status-line.js +127 -0
  212. package/packages/crouter-api/dist/clients/attach/chrome/ticket-panel.js +261 -0
  213. package/packages/crouter-api/dist/clients/attach/chrome/widgets.js +51 -0
  214. package/packages/crouter-api/dist/clients/attach/command.js +107 -0
  215. package/packages/crouter-api/dist/clients/attach/config.js +275 -0
  216. package/packages/crouter-api/dist/clients/attach/input/capabilities.js +112 -0
  217. package/packages/crouter-api/dist/clients/attach/input/clipboard-image.js +237 -0
  218. package/packages/crouter-api/dist/clients/attach/input/completion-frecency.js +141 -0
  219. package/packages/crouter-api/dist/clients/attach/input/controller.js +383 -0
  220. package/packages/crouter-api/dist/clients/attach/input/overlay-owner.js +199 -0
  221. package/packages/crouter-api/dist/clients/attach/input/ref-autocomplete.js +176 -0
  222. package/packages/crouter-api/dist/clients/attach/input/titled-editor.js +859 -0
  223. package/packages/crouter-api/dist/clients/attach/overlays/auth.js +247 -0
  224. package/packages/crouter-api/dist/clients/attach/overlays/dialogs.js +102 -0
  225. package/packages/crouter-api/dist/clients/attach/overlays/file-review.js +146 -0
  226. package/packages/crouter-api/dist/clients/attach/overlays/graph.js +725 -0
  227. package/packages/crouter-api/dist/clients/attach/overlays/help.js +214 -0
  228. package/packages/crouter-api/dist/clients/attach/overlays/mcp.js +302 -0
  229. package/packages/crouter-api/dist/clients/attach/overlays/pickers.js +163 -0
  230. package/packages/crouter-api/dist/clients/attach/render/activity-slot.js +13 -0
  231. package/packages/crouter-api/dist/clients/attach/render/assistant-message.js +56 -0
  232. package/packages/crouter-api/dist/clients/attach/render/card-presentation.js +232 -0
  233. package/packages/crouter-api/dist/clients/attach/render/chat-view.js +2091 -0
  234. package/packages/crouter-api/dist/clients/attach/render/condensed-history.js +60 -0
  235. package/packages/crouter-api/dist/clients/attach/render/context-message.js +63 -0
  236. package/packages/crouter-api/dist/clients/attach/render/crtr-output.js +721 -0
  237. package/packages/crouter-api/dist/clients/attach/render/diagram.js +111 -0
  238. package/packages/crouter-api/dist/clients/attach/render/doc-links.js +78 -0
  239. package/packages/crouter-api/dist/clients/attach/render/edit-diff.js +304 -0
  240. package/packages/crouter-api/dist/clients/attach/render/glyph-codepoints.js +42 -0
  241. package/packages/crouter-api/dist/clients/attach/render/group-activity.js +276 -0
  242. package/packages/crouter-api/dist/clients/attach/render/group-recap.js +146 -0
  243. package/packages/crouter-api/dist/clients/attach/render/markdown-source.js +279 -0
  244. package/packages/crouter-api/dist/clients/attach/render/measured-container.js +322 -0
  245. package/packages/crouter-api/dist/clients/attach/render/page-block.js +187 -0
  246. package/packages/crouter-api/dist/clients/attach/render/scroll-animation.js +80 -0
  247. package/packages/crouter-api/dist/clients/attach/render/tool-calls.js +350 -0
  248. package/packages/crouter-api/dist/clients/attach/render/transcript-copy.js +81 -0
  249. package/packages/crouter-api/dist/clients/attach/render/transcript-search.js +152 -0
  250. package/packages/crouter-api/dist/clients/attach/render/viewport.js +184 -0
  251. package/packages/crouter-api/dist/clients/attach/session/banner.js +33 -0
  252. package/packages/crouter-api/dist/clients/attach/session/bindings.js +72 -0
  253. package/packages/crouter-api/dist/clients/attach/session/chrome-refresh.js +154 -0
  254. package/packages/crouter-api/dist/clients/attach/session/connection.js +204 -0
  255. package/packages/crouter-api/dist/clients/attach/session/context.js +16 -0
  256. package/packages/crouter-api/dist/clients/attach/session/document-links.js +48 -0
  257. package/packages/crouter-api/dist/clients/attach/session/editor-frame.js +142 -0
  258. package/packages/crouter-api/dist/clients/attach/session/editor-inventory.js +156 -0
  259. package/packages/crouter-api/dist/clients/attach/session/file-links.js +73 -0
  260. package/packages/crouter-api/dist/clients/attach/session/focus-events.js +12 -0
  261. package/packages/crouter-api/dist/clients/attach/session/frame.js +214 -0
  262. package/packages/crouter-api/dist/clients/attach/session/frames.js +203 -0
  263. package/packages/crouter-api/dist/clients/attach/session/identity.js +26 -0
  264. package/packages/crouter-api/dist/clients/attach/session/input-wiring.js +150 -0
  265. package/packages/crouter-api/dist/clients/attach/session/invariant.js +15 -0
  266. package/packages/crouter-api/dist/clients/attach/session/keys.js +77 -0
  267. package/packages/crouter-api/dist/clients/attach/session/layout.js +59 -0
  268. package/packages/crouter-api/dist/clients/attach/session/mouse.js +78 -0
  269. package/packages/crouter-api/dist/clients/attach/session/pane-focus.js +42 -0
  270. package/packages/crouter-api/dist/clients/attach/session/pane-tag.js +112 -0
  271. package/packages/crouter-api/dist/clients/attach/session/pi-assets.js +24 -0
  272. package/packages/crouter-api/dist/clients/attach/session/pi-oauth-flows.js +21 -0
  273. package/packages/crouter-api/dist/clients/attach/session/profile-files.js +208 -0
  274. package/packages/crouter-api/dist/clients/attach/session/readonly-popup.js +25 -0
  275. package/packages/crouter-api/dist/clients/attach/session/reconnect.js +195 -0
  276. package/packages/crouter-api/dist/clients/attach/session/selection.js +108 -0
  277. package/packages/crouter-api/dist/clients/attach/session/state-sync.js +67 -0
  278. package/packages/crouter-api/dist/clients/attach/session/surface-frame.js +73 -0
  279. package/packages/crouter-api/dist/clients/attach/session/surface-host.js +256 -0
  280. package/packages/crouter-api/dist/clients/attach/session/teardown.js +94 -0
  281. package/packages/crouter-api/dist/clients/attach/session/transcript-search.js +151 -0
  282. package/packages/crouter-api/dist/clients/attach/session/whip-achievements.js +145 -0
  283. package/packages/crouter-api/dist/clients/attach/session/whip.js +362 -0
  284. package/packages/crouter-api/dist/clients/attach/slash/dispatch.js +747 -0
  285. package/packages/crouter-api/dist/clients/attach/slash/prompt-preview.js +121 -0
  286. package/packages/crouter-api/dist/clients/attach/viewer.js +881 -0
  287. package/packages/crouter-api/dist/clients/conversation/projection.js +324 -0
  288. package/packages/crouter-api/dist/clients/conversation/submit.js +51 -0
  289. package/packages/crouter-api/dist/clients/dashboard/app.js +439 -0
  290. package/packages/crouter-api/dist/clients/dashboard/model.js +77 -0
  291. package/packages/crouter-api/dist/clients/dashboard/render.js +148 -0
  292. package/packages/crouter-api/dist/clients/inbox/controller.js +791 -0
  293. package/packages/crouter-api/dist/clients/inbox/dto-adapt.js +93 -0
  294. package/packages/crouter-api/dist/clients/inbox/layout.js +9 -0
  295. package/packages/crouter-api/dist/clients/inbox/page-adapter.js +56 -0
  296. package/packages/crouter-api/dist/clients/inbox/resolve.js +35 -0
  297. package/packages/crouter-api/dist/clients/inbox/review/anchors.js +89 -0
  298. package/packages/crouter-api/dist/clients/inbox/review/comments-client.js +103 -0
  299. package/packages/crouter-api/dist/clients/inbox/review/companion-pane.js +109 -0
  300. package/packages/crouter-api/dist/clients/inbox/review/document-surface.js +1268 -0
  301. package/packages/crouter-api/dist/clients/inbox/review/frame.js +309 -0
  302. package/packages/crouter-api/dist/clients/inbox/review/keys.js +133 -0
  303. package/packages/crouter-api/dist/clients/inbox/review/launch.js +170 -0
  304. package/packages/crouter-api/dist/clients/inbox/review/live-source.js +160 -0
  305. package/packages/crouter-api/dist/clients/inbox/review/nvim.js +43 -0
  306. package/packages/crouter-api/dist/clients/inbox/review/remap.js +157 -0
  307. package/packages/crouter-api/dist/clients/inbox/review/review-client.js +123 -0
  308. package/packages/crouter-api/dist/clients/inbox/review/roundtrip.js +41 -0
  309. package/packages/crouter-api/dist/clients/inbox/review/state.js +315 -0
  310. package/packages/crouter-api/dist/clients/inbox/review-adapter.js +43 -0
  311. package/packages/crouter-api/dist/clients/inbox/surface.js +190 -0
  312. package/packages/crouter-api/dist/clients/inbox/tui/ansi.js +321 -0
  313. package/packages/crouter-api/dist/clients/inbox/tui/input.js +392 -0
  314. package/packages/crouter-api/dist/clients/inbox/tui/keys.js +104 -0
  315. package/packages/crouter-api/dist/clients/inbox/tui/page-body.js +69 -0
  316. package/packages/crouter-api/dist/clients/inbox/tui/panel.js +92 -0
  317. package/packages/crouter-api/dist/clients/inbox/tui/render.js +389 -0
  318. package/packages/crouter-api/dist/clients/inbox/tui/slots.js +134 -0
  319. package/packages/crouter-api/dist/clients/inbox/tui/types.js +1 -0
  320. package/packages/crouter-api/dist/clients/inbox/tui.js +91 -0
  321. package/packages/crouter-api/dist/clients/surfaces/host.js +1 -0
  322. package/packages/crouter-api/dist/commands/api-client.js +438 -0
  323. package/packages/crouter-api/dist/commands/attention.js +215 -0
  324. package/packages/crouter-api/dist/commands/canvas/edges.js +41 -0
  325. package/packages/crouter-api/dist/commands/canvas/list.js +79 -0
  326. package/packages/crouter-api/dist/commands/canvas/read.js +95 -0
  327. package/packages/crouter-api/dist/commands/canvas/search.js +49 -0
  328. package/packages/crouter-api/dist/commands/canvas/share.js +80 -0
  329. package/packages/crouter-api/dist/commands/canvas/unwatch.js +42 -0
  330. package/packages/crouter-api/dist/commands/canvas/watch.js +63 -0
  331. package/packages/crouter-api/dist/commands/canvas-analytics/chart.js +124 -0
  332. package/packages/crouter-api/dist/commands/canvas-analytics/drilldown.js +96 -0
  333. package/packages/crouter-api/dist/commands/canvas-analytics/format.js +106 -0
  334. package/packages/crouter-api/dist/commands/canvas-analytics/graph-detail.js +307 -0
  335. package/packages/crouter-api/dist/commands/canvas-analytics/graphs.js +365 -0
  336. package/packages/crouter-api/dist/commands/canvas-analytics/memory.js +211 -0
  337. package/packages/crouter-api/dist/commands/canvas-analytics/overview.js +189 -0
  338. package/packages/crouter-api/dist/commands/canvas-analytics/shell.js +416 -0
  339. package/packages/crouter-api/dist/commands/canvas-analytics/time.js +228 -0
  340. package/packages/crouter-api/dist/commands/canvas-analytics/usage.js +305 -0
  341. package/packages/crouter-api/dist/commands/canvas-analytics/view.js +102 -0
  342. package/packages/crouter-api/dist/commands/canvas-analytics.js +28 -0
  343. package/packages/crouter-api/dist/commands/canvas-browse.js +71 -0
  344. package/packages/crouter-api/dist/commands/canvas-config.js +192 -0
  345. package/packages/crouter-api/dist/commands/canvas-history/grep.js +85 -0
  346. package/packages/crouter-api/dist/commands/canvas-history/read.js +48 -0
  347. package/packages/crouter-api/dist/commands/canvas-history/search.js +99 -0
  348. package/packages/crouter-api/dist/commands/canvas-history/shared.js +135 -0
  349. package/packages/crouter-api/dist/commands/canvas-history/stats.js +68 -0
  350. package/packages/crouter-api/dist/commands/canvas-history.js +29 -0
  351. package/packages/crouter-api/dist/commands/canvas-issue.js +148 -0
  352. package/packages/crouter-api/dist/commands/canvas-prune.js +111 -0
  353. package/packages/crouter-api/dist/commands/canvas-roster.js +69 -0
  354. package/packages/crouter-api/dist/commands/canvas-snapshot.js +34 -0
  355. package/packages/crouter-api/dist/commands/canvas-use.js +61 -0
  356. package/packages/crouter-api/dist/commands/canvas.js +57 -0
  357. package/packages/crouter-api/dist/commands/chord.js +242 -0
  358. package/packages/crouter-api/dist/commands/cron.js +541 -0
  359. package/packages/crouter-api/dist/commands/custom-object/ack.js +30 -0
  360. package/packages/crouter-api/dist/commands/custom-object/publish.js +39 -0
  361. package/packages/crouter-api/dist/commands/custom-object/receive.js +69 -0
  362. package/packages/crouter-api/dist/commands/custom-object/register.js +69 -0
  363. package/packages/crouter-api/dist/commands/custom-object/shared.js +14 -0
  364. package/packages/crouter-api/dist/commands/custom-object/unregister.js +26 -0
  365. package/packages/crouter-api/dist/commands/custom-object.js +21 -0
  366. package/packages/crouter-api/dist/commands/dashboard.js +86 -0
  367. package/packages/crouter-api/dist/commands/doc/delete.js +30 -0
  368. package/packages/crouter-api/dist/commands/doc/edit.js +83 -0
  369. package/packages/crouter-api/dist/commands/doc/history.js +38 -0
  370. package/packages/crouter-api/dist/commands/doc/lint.js +36 -0
  371. package/packages/crouter-api/dist/commands/doc/list.js +19 -0
  372. package/packages/crouter-api/dist/commands/doc/move.js +37 -0
  373. package/packages/crouter-api/dist/commands/doc/read.js +19 -0
  374. package/packages/crouter-api/dist/commands/doc/replace-blocks.js +40 -0
  375. package/packages/crouter-api/dist/commands/doc/shared.js +156 -0
  376. package/packages/crouter-api/dist/commands/doc/write.js +53 -0
  377. package/packages/crouter-api/dist/commands/doc.js +27 -0
  378. package/packages/crouter-api/dist/commands/human/components.js +78 -0
  379. package/packages/crouter-api/dist/commands/human/feedback.js +112 -0
  380. package/packages/crouter-api/dist/commands/human/prompts.js +326 -0
  381. package/packages/crouter-api/dist/commands/human/queue.js +191 -0
  382. package/packages/crouter-api/dist/commands/human/request.js +266 -0
  383. package/packages/crouter-api/dist/commands/human/review.js +288 -0
  384. package/packages/crouter-api/dist/commands/human/shared.js +67 -0
  385. package/packages/crouter-api/dist/commands/human.js +63 -0
  386. package/packages/crouter-api/dist/commands/node/bash.js +395 -0
  387. package/packages/crouter-api/dist/commands/node/create.js +363 -0
  388. package/packages/crouter-api/dist/commands/node/inspect.js +288 -0
  389. package/packages/crouter-api/dist/commands/node/lifecycle.js +577 -0
  390. package/packages/crouter-api/dist/commands/node/message.js +170 -0
  391. package/packages/crouter-api/dist/commands/node/outcome.js +133 -0
  392. package/packages/crouter-api/dist/commands/node/pyramid.js +79 -0
  393. package/packages/crouter-api/dist/commands/node/subscription.js +78 -0
  394. package/packages/crouter-api/dist/commands/node/wait.js +165 -0
  395. package/packages/crouter-api/dist/commands/node-context.js +145 -0
  396. package/packages/crouter-api/dist/commands/node-lifecycle-revive.js +224 -0
  397. package/packages/crouter-api/dist/commands/node-snapshot.js +37 -0
  398. package/packages/crouter-api/dist/commands/node-transcript.js +59 -0
  399. package/packages/crouter-api/dist/commands/node-worktree.js +138 -0
  400. package/packages/crouter-api/dist/commands/node.js +29 -0
  401. package/packages/crouter-api/dist/commands/person-settings.js +23 -0
  402. package/packages/crouter-api/dist/commands/pkg/app-installs.js +125 -0
  403. package/packages/crouter-api/dist/commands/pkg/browse/actions.js +198 -0
  404. package/packages/crouter-api/dist/commands/pkg/browse/catalog.js +461 -0
  405. package/packages/crouter-api/dist/commands/pkg/browse/command-view.js +217 -0
  406. package/packages/crouter-api/dist/commands/pkg/browse/detail-panel.js +402 -0
  407. package/packages/crouter-api/dist/commands/pkg/browse/doc-view.js +84 -0
  408. package/packages/crouter-api/dist/commands/pkg/browse/list-panel.js +168 -0
  409. package/packages/crouter-api/dist/commands/pkg/browse/model.js +36 -0
  410. package/packages/crouter-api/dist/commands/pkg/browse/shell.js +640 -0
  411. package/packages/crouter-api/dist/commands/pkg/browse.js +27 -0
  412. package/packages/crouter-api/dist/commands/pkg/market-inspect.js +145 -0
  413. package/packages/crouter-api/dist/commands/pkg/market-manage.js +340 -0
  414. package/packages/crouter-api/dist/commands/pkg/market.js +14 -0
  415. package/packages/crouter-api/dist/commands/pkg/plugin-env.js +65 -0
  416. package/packages/crouter-api/dist/commands/pkg/plugin-inspect.js +178 -0
  417. package/packages/crouter-api/dist/commands/pkg/plugin-manage.js +1039 -0
  418. package/packages/crouter-api/dist/commands/pkg/plugin.js +14 -0
  419. package/packages/crouter-api/dist/commands/pkg/shared.js +62 -0
  420. package/packages/crouter-api/dist/commands/pkg.js +21 -0
  421. package/packages/crouter-api/dist/commands/profile/daemon-profiles.js +38 -0
  422. package/packages/crouter-api/dist/commands/profile/default.js +183 -0
  423. package/packages/crouter-api/dist/commands/profile/delete.js +66 -0
  424. package/packages/crouter-api/dist/commands/profile/env.js +188 -0
  425. package/packages/crouter-api/dist/commands/profile/environment.js +88 -0
  426. package/packages/crouter-api/dist/commands/profile/kind.js +27 -0
  427. package/packages/crouter-api/dist/commands/profile/list.js +45 -0
  428. package/packages/crouter-api/dist/commands/profile/meta.js +65 -0
  429. package/packages/crouter-api/dist/commands/profile/new.js +107 -0
  430. package/packages/crouter-api/dist/commands/profile/pause.js +59 -0
  431. package/packages/crouter-api/dist/commands/profile/project.js +146 -0
  432. package/packages/crouter-api/dist/commands/profile/rename.js +41 -0
  433. package/packages/crouter-api/dist/commands/profile/show.js +55 -0
  434. package/packages/crouter-api/dist/commands/profile.js +36 -0
  435. package/packages/crouter-api/dist/commands/push.js +357 -0
  436. package/packages/crouter-api/dist/commands/revive.js +183 -0
  437. package/packages/crouter-api/dist/commands/surface/node/cycle.js +83 -0
  438. package/packages/crouter-api/dist/commands/surface/node/focus.js +60 -0
  439. package/packages/crouter-api/dist/commands/surface/node/id.js +38 -0
  440. package/packages/crouter-api/dist/commands/surface/node/pin.js +42 -0
  441. package/packages/crouter-api/dist/commands/surface/node/placement.js +49 -0
  442. package/packages/crouter-api/dist/commands/surface-dashboard.js +138 -0
  443. package/packages/crouter-api/dist/commands/surface-edit.js +157 -0
  444. package/packages/crouter-api/dist/commands/surface-inbox.js +98 -0
  445. package/packages/crouter-api/dist/commands/surface-inspect.js +41 -0
  446. package/packages/crouter-api/dist/commands/surface-node.js +19 -0
  447. package/packages/crouter-api/dist/commands/surface-reload.js +129 -0
  448. package/packages/crouter-api/dist/commands/surface-tmux-spread.js +214 -0
  449. package/packages/crouter-api/dist/commands/surface.js +29 -0
  450. package/packages/crouter-api/dist/commands/sys/branch.js +19 -0
  451. package/packages/crouter-api/dist/commands/sys/config.js +353 -0
  452. package/packages/crouter-api/dist/commands/sys/connect.js +185 -0
  453. package/packages/crouter-api/dist/commands/sys/context/admin/actions.js +89 -0
  454. package/packages/crouter-api/dist/commands/sys/context/admin/detail-panel.js +233 -0
  455. package/packages/crouter-api/dist/commands/sys/context/admin/docs-panel.js +185 -0
  456. package/packages/crouter-api/dist/commands/sys/context/admin/list-view.js +170 -0
  457. package/packages/crouter-api/dist/commands/sys/context/admin/model.js +179 -0
  458. package/packages/crouter-api/dist/commands/sys/context/admin/rail-panel.js +229 -0
  459. package/packages/crouter-api/dist/commands/sys/context/admin/read-view.js +172 -0
  460. package/packages/crouter-api/dist/commands/sys/context/admin/shell.js +870 -0
  461. package/packages/crouter-api/dist/commands/sys/context/admin.js +148 -0
  462. package/packages/crouter-api/dist/commands/sys/context/doc.js +126 -0
  463. package/packages/crouter-api/dist/commands/sys/context/expose.js +66 -0
  464. package/packages/crouter-api/dist/commands/sys/context/prompt-review.js +244 -0
  465. package/packages/crouter-api/dist/commands/sys/context/resolve.js +326 -0
  466. package/packages/crouter-api/dist/commands/sys/context/sysprompt.js +95 -0
  467. package/packages/crouter-api/dist/commands/sys/context.js +21 -0
  468. package/packages/crouter-api/dist/commands/sys/daemon.js +351 -0
  469. package/packages/crouter-api/dist/commands/sys/db.js +69 -0
  470. package/packages/crouter-api/dist/commands/sys/desktop.js +201 -0
  471. package/packages/crouter-api/dist/commands/sys/doctor.js +633 -0
  472. package/packages/crouter-api/dist/commands/sys/env.js +39 -0
  473. package/packages/crouter-api/dist/commands/sys/feedback.js +228 -0
  474. package/packages/crouter-api/dist/commands/sys/import/move.js +393 -0
  475. package/packages/crouter-api/dist/commands/sys/import/resume.js +23 -0
  476. package/packages/crouter-api/dist/commands/sys/import/start.js +92 -0
  477. package/packages/crouter-api/dist/commands/sys/join.js +85 -0
  478. package/packages/crouter-api/dist/commands/sys/limits.js +133 -0
  479. package/packages/crouter-api/dist/commands/sys/logs.js +129 -0
  480. package/packages/crouter-api/dist/commands/sys/machine/rotate.js +49 -0
  481. package/packages/crouter-api/dist/commands/sys/migrate.js +79 -0
  482. package/packages/crouter-api/dist/commands/sys/panels/broker-limits-panel.js +110 -0
  483. package/packages/crouter-api/dist/commands/sys/panels/dependencies-panel.js +80 -0
  484. package/packages/crouter-api/dist/commands/sys/panels/keybindings-panel.js +703 -0
  485. package/packages/crouter-api/dist/commands/sys/panels/models-panel.js +1160 -0
  486. package/packages/crouter-api/dist/commands/sys/panels/plugin-env-panel.js +70 -0
  487. package/packages/crouter-api/dist/commands/sys/panels/plugins-panel.js +87 -0
  488. package/packages/crouter-api/dist/commands/sys/panels/prefs-panel.js +97 -0
  489. package/packages/crouter-api/dist/commands/sys/panels/profiles-panel.js +656 -0
  490. package/packages/crouter-api/dist/commands/sys/panels/provider-panel.js +534 -0
  491. package/packages/crouter-api/dist/commands/sys/panels/terminal-panel.js +67 -0
  492. package/packages/crouter-api/dist/commands/sys/provider-login.js +99 -0
  493. package/packages/crouter-api/dist/commands/sys/repo-docs.js +96 -0
  494. package/packages/crouter-api/dist/commands/sys/retry-delivery.js +33 -0
  495. package/packages/crouter-api/dist/commands/sys/settings-shell.js +400 -0
  496. package/packages/crouter-api/dist/commands/sys/settings.js +46 -0
  497. package/packages/crouter-api/dist/commands/sys/setup-core.js +890 -0
  498. package/packages/crouter-api/dist/commands/sys/setup-settings-runner.js +15 -0
  499. package/packages/crouter-api/dist/commands/sys/setup-wizard.js +351 -0
  500. package/packages/crouter-api/dist/commands/sys/setup.js +41 -0
  501. package/packages/crouter-api/dist/commands/sys/shared.js +81 -0
  502. package/packages/crouter-api/dist/commands/sys/signin.js +149 -0
  503. package/packages/crouter-api/dist/commands/sys/spaces.js +22 -0
  504. package/packages/crouter-api/dist/commands/sys/spend.js +144 -0
  505. package/packages/crouter-api/dist/commands/sys/support/prepare.js +239 -0
  506. package/packages/crouter-api/dist/commands/sys/support/submit.js +524 -0
  507. package/packages/crouter-api/dist/commands/sys/support.js +18 -0
  508. package/packages/crouter-api/dist/commands/sys/sync-deps.js +445 -0
  509. package/packages/crouter-api/dist/commands/sys/sync-project-guidance.js +320 -0
  510. package/packages/crouter-api/dist/commands/sys/sync-shared.js +139 -0
  511. package/packages/crouter-api/dist/commands/sys/sync-skills.js +297 -0
  512. package/packages/crouter-api/dist/commands/sys/sync.js +17 -0
  513. package/packages/crouter-api/dist/commands/sys/terminal-option.js +542 -0
  514. package/packages/crouter-api/dist/commands/sys/tutorial/branch.js +15 -0
  515. package/packages/crouter-api/dist/commands/sys/tutorial/lessons.js +107 -0
  516. package/packages/crouter-api/dist/commands/sys/tutorial/scenario.js +431 -0
  517. package/packages/crouter-api/dist/commands/sys/tutorial/tracks.js +96 -0
  518. package/packages/crouter-api/dist/commands/sys/update.js +157 -0
  519. package/packages/crouter-api/dist/commands/sys/worktrees.js +53 -0
  520. package/packages/crouter-api/dist/commands/sys.js +32 -0
  521. package/packages/crouter-api/dist/core/activity-signal.js +38 -0
  522. package/packages/crouter-api/dist/core/asset-root.js +18 -0
  523. package/packages/crouter-api/dist/core/async-array.js +48 -0
  524. package/packages/crouter-api/dist/core/auth-file.js +89 -0
  525. package/packages/crouter-api/dist/core/auth-interaction.js +94 -0
  526. package/packages/crouter-api/dist/core/bash-guard.js +527 -0
  527. package/packages/crouter-api/dist/core/bash-job-supervisor.js +157 -0
  528. package/packages/crouter-api/dist/core/bash-jobs.js +460 -0
  529. package/packages/crouter-api/dist/core/blobs/directory.js +264 -0
  530. package/packages/crouter-api/dist/core/blobs/fault.js +6 -0
  531. package/packages/crouter-api/dist/core/blobs/index.js +30 -0
  532. package/packages/crouter-api/dist/core/blobs/r2.js +169 -0
  533. package/packages/crouter-api/dist/core/broker-client/client.js +184 -0
  534. package/packages/crouter-api/dist/core/broker-client/index.js +14 -0
  535. package/packages/crouter-api/dist/core/broker-client/transport-relay.js +186 -0
  536. package/packages/crouter-api/dist/core/broker-client/transport-socket.js +187 -0
  537. package/packages/crouter-api/dist/core/broker-client/transport.js +40 -0
  538. package/packages/crouter-api/dist/core/canvas/app-run.js +4 -0
  539. package/packages/crouter-api/dist/core/canvas/attention.js +47 -0
  540. package/packages/crouter-api/dist/core/canvas/boot-id.js +26 -0
  541. package/packages/crouter-api/dist/core/canvas/browse/app.js +1050 -0
  542. package/packages/crouter-api/dist/core/canvas/browse/model.js +477 -0
  543. package/packages/crouter-api/dist/core/canvas/browse/pins.js +29 -0
  544. package/packages/crouter-api/dist/core/canvas/browse/render.js +1058 -0
  545. package/packages/crouter-api/dist/core/canvas/canvas.js +1225 -0
  546. package/packages/crouter-api/dist/core/canvas/crons.js +541 -0
  547. package/packages/crouter-api/dist/core/canvas/daemon-actions.js +98 -0
  548. package/packages/crouter-api/dist/core/canvas/db.js +429 -0
  549. package/packages/crouter-api/dist/core/canvas/deliveries.js +398 -0
  550. package/packages/crouter-api/dist/core/canvas/delivery-contract.js +30 -0
  551. package/packages/crouter-api/dist/core/canvas/executions.js +279 -0
  552. package/packages/crouter-api/dist/core/canvas/extensions.js +90 -0
  553. package/packages/crouter-api/dist/core/canvas/focuses.js +82 -0
  554. package/packages/crouter-api/dist/core/canvas/history.js +480 -0
  555. package/packages/crouter-api/dist/core/canvas/index.js +16 -0
  556. package/packages/crouter-api/dist/core/canvas/install-id.js +64 -0
  557. package/packages/crouter-api/dist/core/canvas/labels.js +43 -0
  558. package/packages/crouter-api/dist/core/canvas/legacy-person.js +4 -0
  559. package/packages/crouter-api/dist/core/canvas/memory-reads.js +37 -0
  560. package/packages/crouter-api/dist/core/canvas/meta-file.js +89 -0
  561. package/packages/crouter-api/dist/core/canvas/nav-render.js +224 -0
  562. package/packages/crouter-api/dist/core/canvas/node-agent-paths.js +30 -0
  563. package/packages/crouter-api/dist/core/canvas/node-order.js +37 -0
  564. package/packages/crouter-api/dist/core/canvas/node-recap.js +62 -0
  565. package/packages/crouter-api/dist/core/canvas/node-tokens.js +53 -0
  566. package/packages/crouter-api/dist/core/canvas/outcome-actions.js +71 -0
  567. package/packages/crouter-api/dist/core/canvas/paths.js +167 -0
  568. package/packages/crouter-api/dist/core/canvas/person-state.js +41 -0
  569. package/packages/crouter-api/dist/core/canvas/person.js +251 -0
  570. package/packages/crouter-api/dist/core/canvas/pid.js +977 -0
  571. package/packages/crouter-api/dist/core/canvas/reconciler-leases.js +40 -0
  572. package/packages/crouter-api/dist/core/canvas/recovery.js +715 -0
  573. package/packages/crouter-api/dist/core/canvas/remote-canvas-source.js +290 -0
  574. package/packages/crouter-api/dist/core/canvas/remote-transport.js +57 -0
  575. package/packages/crouter-api/dist/core/canvas/render-source.js +518 -0
  576. package/packages/crouter-api/dist/core/canvas/schema-chain.js +110 -0
  577. package/packages/crouter-api/dist/core/canvas/schema-version.js +58 -0
  578. package/packages/crouter-api/dist/core/canvas/sessions.js +128 -0
  579. package/packages/crouter-api/dist/core/canvas/source.js +57 -0
  580. package/packages/crouter-api/dist/core/canvas/status-glyph.js +132 -0
  581. package/packages/crouter-api/dist/core/canvas/structured-requests.js +176 -0
  582. package/packages/crouter-api/dist/core/canvas/telemetry.js +35 -0
  583. package/packages/crouter-api/dist/core/canvas/tree.js +128 -0
  584. package/packages/crouter-api/dist/core/canvas/types.js +6 -0
  585. package/packages/crouter-api/dist/core/canvas/waits.js +113 -0
  586. package/packages/crouter-api/dist/core/canvas/worktrees.js +97 -0
  587. package/packages/crouter-api/dist/core/checkout-identities.js +88 -0
  588. package/packages/crouter-api/dist/core/clipboard-text.js +57 -0
  589. package/packages/crouter-api/dist/core/command-hooks/artifact.js +145 -0
  590. package/packages/crouter-api/dist/core/command-hooks/catalog.js +38 -0
  591. package/packages/crouter-api/dist/core/command-hooks/compose.js +101 -0
  592. package/packages/crouter-api/dist/core/command-hooks/discovery.js +246 -0
  593. package/packages/crouter-api/dist/core/command-hooks/help.js +18 -0
  594. package/packages/crouter-api/dist/core/command-hooks/lifecycle-catalog.js +9 -0
  595. package/packages/crouter-api/dist/core/command-hooks/lifecycle-create.js +51 -0
  596. package/packages/crouter-api/dist/core/command-hooks/report.js +28 -0
  597. package/packages/crouter-api/dist/core/command-hooks/schema.js +157 -0
  598. package/packages/crouter-api/dist/core/command-hooks/transport/exec-invoke.js +315 -0
  599. package/packages/crouter-api/dist/core/command-hooks/transport/exec-lifecycle.js +248 -0
  600. package/packages/crouter-api/dist/core/command-hooks/transport/plan.js +30 -0
  601. package/packages/crouter-api/dist/core/command-manifests/registry.js +118 -0
  602. package/packages/crouter-api/dist/core/command-plugins/bundle.js +604 -0
  603. package/packages/crouter-api/dist/core/command-plugins/caller-header.js +15 -0
  604. package/packages/crouter-api/dist/core/command-plugins/compose.js +243 -0
  605. package/packages/crouter-api/dist/core/command-plugins/discovery.js +240 -0
  606. package/packages/crouter-api/dist/core/command-plugins/endpoint.js +60 -0
  607. package/packages/crouter-api/dist/core/command-plugins/extensions.js +166 -0
  608. package/packages/crouter-api/dist/core/command-plugins/help-addenda.js +55 -0
  609. package/packages/crouter-api/dist/core/command-plugins/presence.js +36 -0
  610. package/packages/crouter-api/dist/core/command-plugins/transport/exec-invoke.js +138 -0
  611. package/packages/crouter-api/dist/core/command-plugins/transport/http-fetch.js +68 -0
  612. package/packages/crouter-api/dist/core/command-plugins/transport/http-invoke.js +333 -0
  613. package/packages/crouter-api/dist/core/command-plugins/transport/http-plan.js +349 -0
  614. package/packages/crouter-api/dist/core/command-plugins/transport/sign.js +115 -0
  615. package/packages/crouter-api/dist/core/command.js +848 -0
  616. package/packages/crouter-api/dist/core/config.js +1154 -0
  617. package/packages/crouter-api/dist/core/conversation-store/client.js +111 -0
  618. package/packages/crouter-api/dist/core/conversation-store/index.js +62 -0
  619. package/packages/crouter-api/dist/core/conversation-store/patch.js +192 -0
  620. package/packages/crouter-api/dist/core/conversation-store/repair.js +84 -0
  621. package/packages/crouter-api/dist/core/conversation-store/row-store.js +365 -0
  622. package/packages/crouter-api/dist/core/directory/issuer.js +15 -0
  623. package/packages/crouter-api/dist/core/directory/join-lock.js +61 -0
  624. package/packages/crouter-api/dist/core/directory/join.js +218 -0
  625. package/packages/crouter-api/dist/core/directory/person-credential.js +220 -0
  626. package/packages/crouter-api/dist/core/directory/reach.js +19 -0
  627. package/packages/crouter-api/dist/core/document-lines.js +6 -0
  628. package/packages/crouter-api/dist/core/editor-resolver.js +77 -0
  629. package/packages/crouter-api/dist/core/env-name.js +25 -0
  630. package/packages/crouter-api/dist/core/environment-recipe.js +59 -0
  631. package/packages/crouter-api/dist/core/environments.js +59 -0
  632. package/packages/crouter-api/dist/core/errors.js +90 -0
  633. package/packages/crouter-api/dist/core/events/emit.js +44 -0
  634. package/packages/crouter-api/dist/core/events/envelope.js +84 -0
  635. package/packages/crouter-api/dist/core/events/errors.js +69 -0
  636. package/packages/crouter-api/dist/core/events/operation-id.js +24 -0
  637. package/packages/crouter-api/dist/core/events/outbound.js +92 -0
  638. package/packages/crouter-api/dist/core/events/read.js +625 -0
  639. package/packages/crouter-api/dist/core/events/serialize.js +199 -0
  640. package/packages/crouter-api/dist/core/events/source.js +31 -0
  641. package/packages/crouter-api/dist/core/events/types.js +11 -0
  642. package/packages/crouter-api/dist/core/exclusive-lock.js +197 -0
  643. package/packages/crouter-api/dist/core/fault-classifier.js +101 -0
  644. package/packages/crouter-api/dist/core/feed/feed.js +190 -0
  645. package/packages/crouter-api/dist/core/feed/inbox.js +93 -0
  646. package/packages/crouter-api/dist/core/feed/messages.js +219 -0
  647. package/packages/crouter-api/dist/core/feed/reports.js +58 -0
  648. package/packages/crouter-api/dist/core/frontmatter.js +35 -0
  649. package/packages/crouter-api/dist/core/fs-utils.js +263 -0
  650. package/packages/crouter-api/dist/core/git.js +103 -0
  651. package/packages/crouter-api/dist/core/grants/cover.js +66 -0
  652. package/packages/crouter-api/dist/core/grants/hosted-endpoint.js +70 -0
  653. package/packages/crouter-api/dist/core/grants/local.js +26 -0
  654. package/packages/crouter-api/dist/core/grants/mirror.js +464 -0
  655. package/packages/crouter-api/dist/core/grants/on-sync.js +163 -0
  656. package/packages/crouter-api/dist/core/grants/sandboxes.js +24 -0
  657. package/packages/crouter-api/dist/core/grants/sync.js +216 -0
  658. package/packages/crouter-api/dist/core/grants/terminal.js +25 -0
  659. package/packages/crouter-api/dist/core/graph/access.js +37 -0
  660. package/packages/crouter-api/dist/core/graph/bodies.js +68 -0
  661. package/packages/crouter-api/dist/core/graph/custom.js +298 -0
  662. package/packages/crouter-api/dist/core/graph/deletion.js +115 -0
  663. package/packages/crouter-api/dist/core/graph/documents.js +675 -0
  664. package/packages/crouter-api/dist/core/graph/edges.js +83 -0
  665. package/packages/crouter-api/dist/core/graph/events.js +432 -0
  666. package/packages/crouter-api/dist/core/graph/exposures.js +164 -0
  667. package/packages/crouter-api/dist/core/graph/jobs.js +184 -0
  668. package/packages/crouter-api/dist/core/graph/kinds/action.js +20 -0
  669. package/packages/crouter-api/dist/core/graph/kinds/custom.js +25 -0
  670. package/packages/crouter-api/dist/core/graph/kinds/document.js +132 -0
  671. package/packages/crouter-api/dist/core/graph/kinds/dto.js +20 -0
  672. package/packages/crouter-api/dist/core/graph/kinds/environment.js +21 -0
  673. package/packages/crouter-api/dist/core/graph/kinds/job.js +24 -0
  674. package/packages/crouter-api/dist/core/graph/kinds/kind.js +15 -0
  675. package/packages/crouter-api/dist/core/graph/kinds/live-read.js +11 -0
  676. package/packages/crouter-api/dist/core/graph/kinds/node.js +87 -0
  677. package/packages/crouter-api/dist/core/graph/kinds/owner.js +26 -0
  678. package/packages/crouter-api/dist/core/graph/kinds/registry.js +58 -0
  679. package/packages/crouter-api/dist/core/graph/kinds/render.js +17 -0
  680. package/packages/crouter-api/dist/core/graph/names.js +239 -0
  681. package/packages/crouter-api/dist/core/graph/objects.js +292 -0
  682. package/packages/crouter-api/dist/core/graph/package-docs.js +148 -0
  683. package/packages/crouter-api/dist/core/graph/package-files.js +146 -0
  684. package/packages/crouter-api/dist/core/graph/package-publish.js +158 -0
  685. package/packages/crouter-api/dist/core/graph/package-reconcile.js +99 -0
  686. package/packages/crouter-api/dist/core/graph/reader.js +284 -0
  687. package/packages/crouter-api/dist/core/graph/receiver-url.js +83 -0
  688. package/packages/crouter-api/dist/core/graph/receivers.js +66 -0
  689. package/packages/crouter-api/dist/core/graph/repo-sync/identity.js +147 -0
  690. package/packages/crouter-api/dist/core/graph/repo-sync/repos.js +94 -0
  691. package/packages/crouter-api/dist/core/graph/rules.js +144 -0
  692. package/packages/crouter-api/dist/core/graph/types.js +10 -0
  693. package/packages/crouter-api/dist/core/graph/watches.js +223 -0
  694. package/packages/crouter-api/dist/core/help.js +445 -0
  695. package/packages/crouter-api/dist/core/human/action-binding.js +41 -0
  696. package/packages/crouter-api/dist/core/human/answer-text.js +100 -0
  697. package/packages/crouter-api/dist/core/human/answer.js +119 -0
  698. package/packages/crouter-api/dist/core/human/completion.js +27 -0
  699. package/packages/crouter-api/dist/core/human/component-docs.js +442 -0
  700. package/packages/crouter-api/dist/core/human/convention.js +75 -0
  701. package/packages/crouter-api/dist/core/human/feedback-companion.js +92 -0
  702. package/packages/crouter-api/dist/core/human/feedback.js +88 -0
  703. package/packages/crouter-api/dist/core/human/page-authoring.js +19 -0
  704. package/packages/crouter-api/dist/core/human/page-catalog.js +172 -0
  705. package/packages/crouter-api/dist/core/human/page-errors.js +14 -0
  706. package/packages/crouter-api/dist/core/human/page-eval.js +125 -0
  707. package/packages/crouter-api/dist/core/human/page-html-markdown.js +260 -0
  708. package/packages/crouter-api/dist/core/human/page-markdown.js +295 -0
  709. package/packages/crouter-api/dist/core/human/page-schema.js +381 -0
  710. package/packages/crouter-api/dist/core/human/page.js +251 -0
  711. package/packages/crouter-api/dist/core/human/request-files.js +54 -0
  712. package/packages/crouter-api/dist/core/human/requests.js +647 -0
  713. package/packages/crouter-api/dist/core/human/root.js +11 -0
  714. package/packages/crouter-api/dist/core/human/summary.js +5 -0
  715. package/packages/crouter-api/dist/core/human/tickets.js +175 -0
  716. package/packages/crouter-api/dist/core/human/types.js +1 -0
  717. package/packages/crouter-api/dist/core/human/visible-paths.js +74 -0
  718. package/packages/crouter-api/dist/core/human-actions.js +101 -0
  719. package/packages/crouter-api/dist/core/import/bundle/blob-keys.js +25 -0
  720. package/packages/crouter-api/dist/core/import/bundle/layout.js +111 -0
  721. package/packages/crouter-api/dist/core/import/export/archive.js +22 -0
  722. package/packages/crouter-api/dist/core/import/export/cloud.js +164 -0
  723. package/packages/crouter-api/dist/core/import/export/dump.js +245 -0
  724. package/packages/crouter-api/dist/core/import/export/files.js +169 -0
  725. package/packages/crouter-api/dist/core/import/export/inline.js +15 -0
  726. package/packages/crouter-api/dist/core/import/export/source.js +5 -0
  727. package/packages/crouter-api/dist/core/import/export/stores.js +73 -0
  728. package/packages/crouter-api/dist/core/import/load/catalog.js +70 -0
  729. package/packages/crouter-api/dist/core/import/load/copy.js +132 -0
  730. package/packages/crouter-api/dist/core/import/load/prepare.js +211 -0
  731. package/packages/crouter-api/dist/core/import/load/rewrite.js +310 -0
  732. package/packages/crouter-api/dist/core/import/load/stage.js +99 -0
  733. package/packages/crouter-api/dist/core/inspector/chrome.js +14 -0
  734. package/packages/crouter-api/dist/core/inspector/contract.js +1 -0
  735. package/packages/crouter-api/dist/core/inspector/core.js +296 -0
  736. package/packages/crouter-api/dist/core/inspector/host.js +538 -0
  737. package/packages/crouter-api/dist/core/inspector/model.js +225 -0
  738. package/packages/crouter-api/dist/core/inspector/text.js +45 -0
  739. package/packages/crouter-api/dist/core/inspector/transport.js +36 -0
  740. package/packages/crouter-api/dist/core/inspector/tui.js +295 -0
  741. package/packages/crouter-api/dist/core/installed-plugins.js +82 -0
  742. package/packages/crouter-api/dist/core/io.js +470 -0
  743. package/packages/crouter-api/dist/core/keybindings/attach-control.js +42 -0
  744. package/packages/crouter-api/dist/core/keybindings/background-bash.js +33 -0
  745. package/packages/crouter-api/dist/core/keybindings/catalog.js +288 -0
  746. package/packages/crouter-api/dist/core/keybindings/inbox.js +25 -0
  747. package/packages/crouter-api/dist/core/keybindings/index.js +7 -0
  748. package/packages/crouter-api/dist/core/keybindings/match.js +146 -0
  749. package/packages/crouter-api/dist/core/keybindings/persistence.js +49 -0
  750. package/packages/crouter-api/dist/core/keybindings/resolve.js +348 -0
  751. package/packages/crouter-api/dist/core/keybindings/types.js +1 -0
  752. package/packages/crouter-api/dist/core/layout-migrate/index.js +523 -0
  753. package/packages/crouter-api/dist/core/layout-migrate/paths.js +118 -0
  754. package/packages/crouter-api/dist/core/layout-migrate/stored-paths.js +424 -0
  755. package/packages/crouter-api/dist/core/layout-migrate/stores.js +543 -0
  756. package/packages/crouter-api/dist/core/layout.js +143 -0
  757. package/packages/crouter-api/dist/core/ledger/account.js +13 -0
  758. package/packages/crouter-api/dist/core/ledger/charges.js +44 -0
  759. package/packages/crouter-api/dist/core/ledger/check.js +40 -0
  760. package/packages/crouter-api/dist/core/ledger/chunks.js +43 -0
  761. package/packages/crouter-api/dist/core/ledger/index.js +10 -0
  762. package/packages/crouter-api/dist/core/ledger/infra-allowance.js +31 -0
  763. package/packages/crouter-api/dist/core/ledger/limits.js +35 -0
  764. package/packages/crouter-api/dist/core/ledger/months.js +19 -0
  765. package/packages/crouter-api/dist/core/ledger/payer.js +14 -0
  766. package/packages/crouter-api/dist/core/ledger/rates.js +64 -0
  767. package/packages/crouter-api/dist/core/ledger/read.js +194 -0
  768. package/packages/crouter-api/dist/core/ledger/totals.js +34 -0
  769. package/packages/crouter-api/dist/core/ledger/types.js +2 -0
  770. package/packages/crouter-api/dist/core/llm/app-rungs.js +64 -0
  771. package/packages/crouter-api/dist/core/llm/body-limits.js +7 -0
  772. package/packages/crouter-api/dist/core/llm/owner-candidates.js +79 -0
  773. package/packages/crouter-api/dist/core/llm/refusal.js +22 -0
  774. package/packages/crouter-api/dist/core/llm/run.js +558 -0
  775. package/packages/crouter-api/dist/core/locked-file.js +121 -0
  776. package/packages/crouter-api/dist/core/log.js +91 -0
  777. package/packages/crouter-api/dist/core/managed-providers.js +61 -0
  778. package/packages/crouter-api/dist/core/manifest-stale.js +39 -0
  779. package/packages/crouter-api/dist/core/manifest.js +37 -0
  780. package/packages/crouter-api/dist/core/model-auth/api-credential-store.js +49 -0
  781. package/packages/crouter-api/dist/core/model-auth/daemon-login.js +156 -0
  782. package/packages/crouter-api/dist/core/model-auth/readiness.js +83 -0
  783. package/packages/crouter-api/dist/core/model-routes-pool.js +57 -0
  784. package/packages/crouter-api/dist/core/model-routes.js +212 -0
  785. package/packages/crouter-api/dist/core/northlight/previews.js +87 -0
  786. package/packages/crouter-api/dist/core/nvim-launch.js +45 -0
  787. package/packages/crouter-api/dist/core/output.js +99 -0
  788. package/packages/crouter-api/dist/core/packages/eligibility.js +34 -0
  789. package/packages/crouter-api/dist/core/packages/launch-kinds.js +20 -0
  790. package/packages/crouter-api/dist/core/packages/source-url.js +17 -0
  791. package/packages/crouter-api/dist/core/pagination.js +88 -0
  792. package/packages/crouter-api/dist/core/peer/client.js +168 -0
  793. package/packages/crouter-api/dist/core/peer/directory.js +193 -0
  794. package/packages/crouter-api/dist/core/peer/envelope.js +98 -0
  795. package/packages/crouter-api/dist/core/peer/names.js +8 -0
  796. package/packages/crouter-api/dist/core/peer/outbox-store.js +84 -0
  797. package/packages/crouter-api/dist/core/peer/receiver.js +54 -0
  798. package/packages/crouter-api/dist/core/peer/stubs.js +208 -0
  799. package/packages/crouter-api/dist/core/peer/token.js +30 -0
  800. package/packages/crouter-api/dist/core/peer/version.js +23 -0
  801. package/packages/crouter-api/dist/core/permissions/builtin.js +29 -0
  802. package/packages/crouter-api/dist/core/permissions/ceiling.js +332 -0
  803. package/packages/crouter-api/dist/core/permissions/compile.js +175 -0
  804. package/packages/crouter-api/dist/core/permissions/errors.js +13 -0
  805. package/packages/crouter-api/dist/core/permissions/evaluator.js +98 -0
  806. package/packages/crouter-api/dist/core/permissions/facts.js +102 -0
  807. package/packages/crouter-api/dist/core/permissions/schema-parser.js +151 -0
  808. package/packages/crouter-api/dist/core/permissions/schemas.js +83 -0
  809. package/packages/crouter-api/dist/core/permissions/sql.js +31 -0
  810. package/packages/crouter-api/dist/core/plugin-app.js +58 -0
  811. package/packages/crouter-api/dist/core/plugin-env.js +30 -0
  812. package/packages/crouter-api/dist/core/plugin-extensions.js +191 -0
  813. package/packages/crouter-api/dist/core/plugin-objects-manifest.js +86 -0
  814. package/packages/crouter-api/dist/core/plugin-quarantine.js +70 -0
  815. package/packages/crouter-api/dist/core/plugin-swap-lock.js +31 -0
  816. package/packages/crouter-api/dist/core/pool-credential-store.js +116 -0
  817. package/packages/crouter-api/dist/core/predicate.js +191 -0
  818. package/packages/crouter-api/dist/core/preview-registry.js +403 -0
  819. package/packages/crouter-api/dist/core/preview-result-path.js +26 -0
  820. package/packages/crouter-api/dist/core/profiles/default-binding.js +29 -0
  821. package/packages/crouter-api/dist/core/profiles/deletion-reservation.js +42 -0
  822. package/packages/crouter-api/dist/core/profiles/fuzzy-match.js +92 -0
  823. package/packages/crouter-api/dist/core/profiles/manifest.js +574 -0
  824. package/packages/crouter-api/dist/core/profiles/select.js +740 -0
  825. package/packages/crouter-api/dist/core/provider-credential.js +17 -0
  826. package/packages/crouter-api/dist/core/provider-error-recognition.js +82 -0
  827. package/packages/crouter-api/dist/core/provider-failure.js +157 -0
  828. package/packages/crouter-api/dist/core/provider-management.js +9 -0
  829. package/packages/crouter-api/dist/core/providers/approval.js +146 -0
  830. package/packages/crouter-api/dist/core/providers/audit.js +52 -0
  831. package/packages/crouter-api/dist/core/providers/bundles.js +643 -0
  832. package/packages/crouter-api/dist/core/providers/call.js +497 -0
  833. package/packages/crouter-api/dist/core/providers/description.js +1 -0
  834. package/packages/crouter-api/dist/core/providers/device-libs.js +202 -0
  835. package/packages/crouter-api/dist/core/providers/device.js +95 -0
  836. package/packages/crouter-api/dist/core/providers/errors.js +136 -0
  837. package/packages/crouter-api/dist/core/providers/files.js +390 -0
  838. package/packages/crouter-api/dist/core/providers/inflight.js +14 -0
  839. package/packages/crouter-api/dist/core/providers/mint.js +219 -0
  840. package/packages/crouter-api/dist/core/providers/receipts.js +61 -0
  841. package/packages/crouter-api/dist/core/providers/request.js +173 -0
  842. package/packages/crouter-api/dist/core/providers/roots.js +118 -0
  843. package/packages/crouter-api/dist/core/providers/token-cache.js +203 -0
  844. package/packages/crouter-api/dist/core/rate-limit-scope.js +64 -0
  845. package/packages/crouter-api/dist/core/remote-canvas-target.js +30 -0
  846. package/packages/crouter-api/dist/core/render.js +146 -0
  847. package/packages/crouter-api/dist/core/resolver.js +111 -0
  848. package/packages/crouter-api/dist/core/review/comments.js +296 -0
  849. package/packages/crouter-api/dist/core/review/companion.js +211 -0
  850. package/packages/crouter-api/dist/core/review/signal.js +12 -0
  851. package/packages/crouter-api/dist/core/review/store.js +178 -0
  852. package/packages/crouter-api/dist/core/review/types.js +23 -0
  853. package/packages/crouter-api/dist/core/runs/activity.js +57 -0
  854. package/packages/crouter-api/dist/core/runs/events.js +179 -0
  855. package/packages/crouter-api/dist/core/runs/initial-input.js +27 -0
  856. package/packages/crouter-api/dist/core/runs/operations.js +793 -0
  857. package/packages/crouter-api/dist/core/runs/questions.js +151 -0
  858. package/packages/crouter-api/dist/core/runtime/banner.js +53 -0
  859. package/packages/crouter-api/dist/core/runtime/bearings-render.js +273 -0
  860. package/packages/crouter-api/dist/core/runtime/bearings.js +199 -0
  861. package/packages/crouter-api/dist/core/runtime/bin-contributions.js +186 -0
  862. package/packages/crouter-api/dist/core/runtime/blaxel-environment.js +17 -0
  863. package/packages/crouter-api/dist/core/runtime/branded-host.js +485 -0
  864. package/packages/crouter-api/dist/core/runtime/broker/attachments-fetch.js +20 -0
  865. package/packages/crouter-api/dist/core/runtime/broker/bash-job-launch.js +66 -0
  866. package/packages/crouter-api/dist/core/runtime/broker/daemon-ops.js +232 -0
  867. package/packages/crouter-api/dist/core/runtime/broker/model-adapter.js +431 -0
  868. package/packages/crouter-api/dist/core/runtime/broker/node-token.js +16 -0
  869. package/packages/crouter-api/dist/core/runtime/broker/read-ops.js +173 -0
  870. package/packages/crouter-api/dist/core/runtime/broker/signal-stream.js +149 -0
  871. package/packages/crouter-api/dist/core/runtime/broker/turn-cause.js +44 -0
  872. package/packages/crouter-api/dist/core/runtime/broker-protocol.js +152 -0
  873. package/packages/crouter-api/dist/core/runtime/broker-request.js +86 -0
  874. package/packages/crouter-api/dist/core/runtime/broker-sdk.js +130 -0
  875. package/packages/crouter-api/dist/core/runtime/canvas-extensions.js +100 -0
  876. package/packages/crouter-api/dist/core/runtime/close.js +266 -0
  877. package/packages/crouter-api/dist/core/runtime/command-expansion.js +104 -0
  878. package/packages/crouter-api/dist/core/runtime/command-surface.js +117 -0
  879. package/packages/crouter-api/dist/core/runtime/crtr-theme.js +146 -0
  880. package/packages/crouter-api/dist/core/runtime/deliver-live.js +84 -0
  881. package/packages/crouter-api/dist/core/runtime/fault-recovery.js +83 -0
  882. package/packages/crouter-api/dist/core/runtime/fault.js +17 -0
  883. package/packages/crouter-api/dist/core/runtime/fleet.js +75 -0
  884. package/packages/crouter-api/dist/core/runtime/focus-viewer.js +151 -0
  885. package/packages/crouter-api/dist/core/runtime/front-door-env.js +16 -0
  886. package/packages/crouter-api/dist/core/runtime/headless-pi.js +176 -0
  887. package/packages/crouter-api/dist/core/runtime/host.js +701 -0
  888. package/packages/crouter-api/dist/core/runtime/interactive-deliver.js +51 -0
  889. package/packages/crouter-api/dist/core/runtime/invocation.js +10 -0
  890. package/packages/crouter-api/dist/core/runtime/kickoff.js +263 -0
  891. package/packages/crouter-api/dist/core/runtime/launch-prompt.js +13 -0
  892. package/packages/crouter-api/dist/core/runtime/launch-target.js +87 -0
  893. package/packages/crouter-api/dist/core/runtime/launch.js +505 -0
  894. package/packages/crouter-api/dist/core/runtime/ledger.js +55 -0
  895. package/packages/crouter-api/dist/core/runtime/lifecycle.js +283 -0
  896. package/packages/crouter-api/dist/core/runtime/managed-provider-cooling.js +62 -0
  897. package/packages/crouter-api/dist/core/runtime/memory-admission.js +68 -0
  898. package/packages/crouter-api/dist/core/runtime/model-registry.js +13 -0
  899. package/packages/crouter-api/dist/core/runtime/model-selection.js +135 -0
  900. package/packages/crouter-api/dist/core/runtime/model-swap.js +75 -0
  901. package/packages/crouter-api/dist/core/runtime/naming.js +300 -0
  902. package/packages/crouter-api/dist/core/runtime/nerd-font.js +162 -0
  903. package/packages/crouter-api/dist/core/runtime/nodes.js +506 -0
  904. package/packages/crouter-api/dist/core/runtime/outcome-document.js +86 -0
  905. package/packages/crouter-api/dist/core/runtime/output-result.js +32 -0
  906. package/packages/crouter-api/dist/core/runtime/output-schema-refs.js +100 -0
  907. package/packages/crouter-api/dist/core/runtime/package-health.js +100 -0
  908. package/packages/crouter-api/dist/core/runtime/persona.js +54 -0
  909. package/packages/crouter-api/dist/core/runtime/pi-cli.js +65 -0
  910. package/packages/crouter-api/dist/core/runtime/pi-vendored.js +63 -0
  911. package/packages/crouter-api/dist/core/runtime/placement-tmux.js +81 -0
  912. package/packages/crouter-api/dist/core/runtime/placement.js +418 -0
  913. package/packages/crouter-api/dist/core/runtime/progress-bar.js +50 -0
  914. package/packages/crouter-api/dist/core/runtime/provider-credential-gate.js +48 -0
  915. package/packages/crouter-api/dist/core/runtime/recovery-hold.js +46 -0
  916. package/packages/crouter-api/dist/core/runtime/reopen.js +160 -0
  917. package/packages/crouter-api/dist/core/runtime/revive.js +748 -0
  918. package/packages/crouter-api/dist/core/runtime/roadmap.js +86 -0
  919. package/packages/crouter-api/dist/core/runtime/runner/blaxel/client.js +140 -0
  920. package/packages/crouter-api/dist/core/runtime/runner/blaxel/image-build.js +233 -0
  921. package/packages/crouter-api/dist/core/runtime/runner/delete-sandboxes.js +24 -0
  922. package/packages/crouter-api/dist/core/runtime/runner/index.js +37 -0
  923. package/packages/crouter-api/dist/core/runtime/runner/machine/call.js +94 -0
  924. package/packages/crouter-api/dist/core/runtime/runner/machine/environment.js +7 -0
  925. package/packages/crouter-api/dist/core/runtime/runner/machine/ops.js +42 -0
  926. package/packages/crouter-api/dist/core/runtime/runner/machine/runner.js +90 -0
  927. package/packages/crouter-api/dist/core/runtime/runner/process.js +70 -0
  928. package/packages/crouter-api/dist/core/runtime/runner/types.js +16 -0
  929. package/packages/crouter-api/dist/core/runtime/session-branch.js +16 -0
  930. package/packages/crouter-api/dist/core/runtime/session-cycles.js +110 -0
  931. package/packages/crouter-api/dist/core/runtime/session-list-cache.js +302 -0
  932. package/packages/crouter-api/dist/core/runtime/session-visibility.js +99 -0
  933. package/packages/crouter-api/dist/core/runtime/setup-marker.js +46 -0
  934. package/packages/crouter-api/dist/core/runtime/situational-context.js +54 -0
  935. package/packages/crouter-api/dist/core/runtime/situational-live.js +41 -0
  936. package/packages/crouter-api/dist/core/runtime/spawn-env-rows.js +15 -0
  937. package/packages/crouter-api/dist/core/runtime/spawn-env.js +260 -0
  938. package/packages/crouter-api/dist/core/runtime/spawn.js +717 -0
  939. package/packages/crouter-api/dist/core/runtime/stamp/protocol.js +113 -0
  940. package/packages/crouter-api/dist/core/runtime/start-check.js +43 -0
  941. package/packages/crouter-api/dist/core/runtime/stop-guard.js +150 -0
  942. package/packages/crouter-api/dist/core/runtime/structured-output.js +112 -0
  943. package/packages/crouter-api/dist/core/runtime/surface-bg.js +85 -0
  944. package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +743 -0
  945. package/packages/crouter-api/dist/core/runtime/tmux-chrome.js +5 -0
  946. package/packages/crouter-api/dist/core/runtime/tmux-driver.js +713 -0
  947. package/packages/crouter-api/dist/core/runtime/unsandboxed.js +18 -0
  948. package/packages/crouter-api/dist/core/runtime/view-socket.js +195 -0
  949. package/packages/crouter-api/dist/core/runtime/warm-pool.js +479 -0
  950. package/packages/crouter-api/dist/core/scope.js +184 -0
  951. package/packages/crouter-api/dist/core/scoped-state/db.js +271 -0
  952. package/packages/crouter-api/dist/core/scoped-state/legacy-profiles.js +65 -0
  953. package/packages/crouter-api/dist/core/scoped-state/migrate.js +332 -0
  954. package/packages/crouter-api/dist/core/scoped-state/paths.js +27 -0
  955. package/packages/crouter-api/dist/core/scoped-state/person-rows.js +185 -0
  956. package/packages/crouter-api/dist/core/scoped-state/person-store.js +116 -0
  957. package/packages/crouter-api/dist/core/scoped-state/schema.js +52 -0
  958. package/packages/crouter-api/dist/core/scopes.js +48 -0
  959. package/packages/crouter-api/dist/core/secrets/env-rows.js +40 -0
  960. package/packages/crouter-api/dist/core/secrets/environment-owner.js +31 -0
  961. package/packages/crouter-api/dist/core/secrets/environment-secrets.js +14 -0
  962. package/packages/crouter-api/dist/core/secrets/index.js +2 -0
  963. package/packages/crouter-api/dist/core/secrets/key.js +33 -0
  964. package/packages/crouter-api/dist/core/secrets/seal.js +43 -0
  965. package/packages/crouter-api/dist/core/secrets.js +147 -0
  966. package/packages/crouter-api/dist/core/self-update.js +77 -0
  967. package/packages/crouter-api/dist/core/session-model/session-state.js +180 -0
  968. package/packages/crouter-api/dist/core/shell-segments.js +169 -0
  969. package/packages/crouter-api/dist/core/spaces/cache-env.js +15 -0
  970. package/packages/crouter-api/dist/core/spaces/file-root.js +68 -0
  971. package/packages/crouter-api/dist/core/spaces/mounts.js +126 -0
  972. package/packages/crouter-api/dist/core/spaces/open-beneath.js +581 -0
  973. package/packages/crouter-api/dist/core/spaces/permissions.js +77 -0
  974. package/packages/crouter-api/dist/core/spaces/process.js +172 -0
  975. package/packages/crouter-api/dist/core/spaces/runtime-home.js +8 -0
  976. package/packages/crouter-api/dist/core/spaces/space.js +58 -0
  977. package/packages/crouter-api/dist/core/spaces/stop.js +138 -0
  978. package/packages/crouter-api/dist/core/spaces/users.js +43 -0
  979. package/packages/crouter-api/dist/core/sqlite-statements.js +17 -0
  980. package/packages/crouter-api/dist/core/statements.js +81 -0
  981. package/packages/crouter-api/dist/core/storage/attachments.js +141 -0
  982. package/packages/crouter-api/dist/core/storage/caller-file.js +84 -0
  983. package/packages/crouter-api/dist/core/storage/client.js +220 -0
  984. package/packages/crouter-api/dist/core/storage/media-types.js +22 -0
  985. package/packages/crouter-api/dist/core/storage/purge.js +55 -0
  986. package/packages/crouter-api/dist/core/storage/tables.js +129 -0
  987. package/packages/crouter-api/dist/core/subscription-state.js +449 -0
  988. package/packages/crouter-api/dist/core/substrate/delivery/corpus.js +206 -0
  989. package/packages/crouter-api/dist/core/substrate/delivery/deliver.js +336 -0
  990. package/packages/crouter-api/dist/core/substrate/delivery/listings.js +75 -0
  991. package/packages/crouter-api/dist/core/substrate/delivery/match.js +146 -0
  992. package/packages/crouter-api/dist/core/substrate/delivery/plan.js +130 -0
  993. package/packages/crouter-api/dist/core/substrate/delivery/render-boot.js +330 -0
  994. package/packages/crouter-api/dist/core/substrate/delivery/render-event.js +186 -0
  995. package/packages/crouter-api/dist/core/substrate/delivery/sub-persona-menu.js +24 -0
  996. package/packages/crouter-api/dist/core/substrate/delivery/types.js +1 -0
  997. package/packages/crouter-api/dist/core/substrate/gate-explain.js +397 -0
  998. package/packages/crouter-api/dist/core/substrate/schema.js +81 -0
  999. package/packages/crouter-api/dist/core/substrate/subject-fields.js +39 -0
  1000. package/packages/crouter-api/dist/core/substrate/subject.js +60 -0
  1001. package/packages/crouter-api/dist/core/termrender/code-doc.js +92 -0
  1002. package/packages/crouter-api/dist/core/termrender/display.js +56 -0
  1003. package/packages/crouter-api/dist/core/termrender/termrender.js +719 -0
  1004. package/packages/crouter-api/dist/core/termrender/version.js +1 -0
  1005. package/packages/crouter-api/dist/core/timing.js +94 -0
  1006. package/packages/crouter-api/dist/core/tui/draw.js +378 -0
  1007. package/packages/crouter-api/dist/core/tui/fuzzy.js +38 -0
  1008. package/packages/crouter-api/dist/core/tui/markdown.js +407 -0
  1009. package/packages/crouter-api/dist/core/tui/page-host.js +74 -0
  1010. package/packages/crouter-api/dist/core/tui/panel.js +142 -0
  1011. package/packages/crouter-api/dist/core/tui/terminal.js +100 -0
  1012. package/packages/crouter-api/dist/core/user-settings.js +478 -0
  1013. package/packages/crouter-api/dist/core/wake.js +296 -0
  1014. package/packages/crouter-api/dist/core/worktree-close.js +251 -0
  1015. package/packages/crouter-api/dist/core/worktree-containment.js +48 -0
  1016. package/packages/crouter-api/dist/core/worktree-landing.js +56 -0
  1017. package/packages/crouter-api/dist/core/worktree-machine.js +92 -0
  1018. package/packages/crouter-api/dist/core/worktree-mutation-async.js +385 -0
  1019. package/packages/crouter-api/dist/core/worktree-remove.js +84 -0
  1020. package/packages/crouter-api/dist/core/worktree.js +909 -0
  1021. package/packages/crouter-api/dist/daemon/api/deferred-head.js +117 -0
  1022. package/packages/crouter-api/dist/daemon/api/environment-of.js +64 -0
  1023. package/packages/crouter-api/dist/daemon/api/handlers/bash-jobs.js +341 -0
  1024. package/packages/crouter-api/dist/daemon/api/handlers/broker-recovery.js +266 -0
  1025. package/packages/crouter-api/dist/daemon/api/handlers/git-credential.js +64 -0
  1026. package/packages/crouter-api/dist/daemon/api/handlers/providers.js +284 -0
  1027. package/packages/crouter-api/dist/daemon/api/handlers/validate.js +58 -0
  1028. package/packages/crouter-api/dist/daemon/api/map.js +768 -0
  1029. package/packages/crouter-api/dist/daemon/api/operations.js +316 -0
  1030. package/packages/crouter-api/dist/daemon/api/principal.js +147 -0
  1031. package/packages/crouter-api/dist/daemon/api/reader.js +125 -0
  1032. package/packages/crouter-api/dist/daemon/api/router.js +542 -0
  1033. package/packages/crouter-api/dist/daemon/api/sync-notice.js +46 -0
  1034. package/packages/crouter-api/dist/daemon/api/viewer-presence.js +100 -0
  1035. package/packages/crouter-api/dist/daemon/broker-signals/bus.js +203 -0
  1036. package/packages/crouter-api/dist/daemon/companion-retire.js +44 -0
  1037. package/packages/crouter-api/dist/daemon/control.js +22 -0
  1038. package/packages/crouter-api/dist/daemon/cron/authority.js +101 -0
  1039. package/packages/crouter-api/dist/daemon/cron/live-runs.js +66 -0
  1040. package/packages/crouter-api/dist/daemon/cron/run-socket.js +170 -0
  1041. package/packages/crouter-api/dist/daemon/drain.js +76 -0
  1042. package/packages/crouter-api/dist/daemon/http-dispatcher.js +37 -0
  1043. package/packages/crouter-api/dist/daemon/human/finish.js +178 -0
  1044. package/packages/crouter-api/dist/daemon/human/settle.js +103 -0
  1045. package/packages/crouter-api/dist/daemon/machine-link/config.js +63 -0
  1046. package/packages/crouter-api/dist/daemon/machine-link/credential.js +24 -0
  1047. package/packages/crouter-api/dist/daemon/machine-link/forward.js +181 -0
  1048. package/packages/crouter-api/dist/daemon/machine-link/frames.js +29 -0
  1049. package/packages/crouter-api/dist/daemon/machine-link/holder.js +317 -0
  1050. package/packages/crouter-api/dist/daemon/machine-link/move-notify.js +15 -0
  1051. package/packages/crouter-api/dist/daemon/manage.js +736 -0
  1052. package/packages/crouter-api/dist/daemon/park-activity.js +33 -0
  1053. package/packages/crouter-api/dist/daemon/park-pending.js +76 -0
  1054. package/packages/crouter-api/dist/daemon/pidfile.js +37 -0
  1055. package/packages/crouter-api/dist/daemon/postgres/binary.js +193 -0
  1056. package/packages/crouter-api/dist/daemon/postgres/cluster.js +111 -0
  1057. package/packages/crouter-api/dist/daemon/postgres/pins.js +16 -0
  1058. package/packages/crouter-api/dist/daemon/postgres/supervisor.js +177 -0
  1059. package/packages/crouter-api/dist/daemon/readiness.js +37 -0
  1060. package/packages/crouter-api/dist/daemon/reconcilers/broker-supervision.js +846 -0
  1061. package/packages/crouter-api/dist/daemon/reconcilers/ledger-sandbox.js +249 -0
  1062. package/packages/crouter-api/dist/daemon/reconcilers/live-obligation.js +125 -0
  1063. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/launch-failure.js +8 -0
  1064. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/node-person.js +40 -0
  1065. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +151 -0
  1066. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/respawn-policy.js +59 -0
  1067. package/packages/crouter-api/dist/daemon/reconcilers/recipe-image.js +196 -0
  1068. package/packages/crouter-api/dist/daemon/reconcilers/throttled-lane.js +63 -0
  1069. package/packages/crouter-api/dist/daemon/runs/append-section.js +135 -0
  1070. package/packages/crouter-api/dist/daemon/runs/observer.js +441 -0
  1071. package/packages/crouter-api/dist/daemon/runs/view-transport.js +81 -0
  1072. package/packages/crouter-api/dist/daemon/startup-policy.js +1 -0
  1073. package/packages/crouter-api/dist/daemon/structured-requests/sidecar.js +5 -0
  1074. package/packages/crouter-api/dist/hook-authoring.js +447 -0
  1075. package/packages/crouter-api/dist/hook-process.js +34 -0
  1076. package/packages/crouter-api/dist/launcher/client.js +52 -0
  1077. package/packages/crouter-api/dist/launcher/limits/policy.js +142 -0
  1078. package/packages/crouter-api/dist/launcher/limits/settings.js +94 -0
  1079. package/packages/crouter-api/dist/launcher/spec.js +10 -0
  1080. package/packages/crouter-api/dist/migrations/004-canvas-documents/apply.js +113 -0
  1081. package/packages/crouter-api/dist/migrations/004-canvas-documents/fields.js +52 -0
  1082. package/packages/crouter-api/dist/migrations/004-canvas-documents/index.js +89 -0
  1083. package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/discover.js +251 -0
  1084. package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/history.js +37 -0
  1085. package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/nested.js +37 -0
  1086. package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/parse.js +24 -0
  1087. package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/types.js +3 -0
  1088. package/packages/crouter-api/dist/migrations/004-canvas-documents/plan.js +410 -0
  1089. package/packages/crouter-api/dist/migrations/004-canvas-documents/pointers.js +95 -0
  1090. package/packages/crouter-api/dist/migrations/activation.js +46 -0
  1091. package/packages/crouter-api/dist/native/linux.js +20 -0
  1092. package/packages/crouter-api/dist/shared/crtr-version.js +18 -0
  1093. package/packages/crouter-api/dist/shared/env.js +335 -0
  1094. package/packages/crouter-api/dist/shared/generated-context.js +240 -0
  1095. package/packages/crouter-api/dist/shared/inbox-entry-body.js +124 -0
  1096. package/packages/crouter-api/dist/shared/inline-ref-grammar.js +99 -0
  1097. package/packages/crouter-api/dist/shared/predicates.js +4 -0
  1098. package/packages/crouter-api/dist/shared/shell-quote.js +5 -0
  1099. package/packages/crouter-api/dist/shared/strip-cd-prefix.js +13 -0
  1100. package/packages/crouter-api/dist/shared/tool-groups.js +64 -0
  1101. package/packages/crouter-api/dist/shared/traceparent.js +28 -0
  1102. package/packages/crouter-api/dist/shared/turn-replies.js +71 -0
  1103. package/packages/crouter-api/dist/shared/working-activity.js +27 -0
  1104. package/packages/crouter-api/dist/types.js +193 -0
  1105. package/packages/crouter-api/package.json +49 -0
  1106. package/packages/crouter-identity/package.json +1 -1
  1107. package/packages/crouter-plugin/dist/approval.js +12 -0
  1108. package/packages/crouter-plugin/dist/bundle.js +203 -0
  1109. package/packages/crouter-plugin/dist/caller.js +23 -0
  1110. package/packages/crouter-plugin/dist/client/index.js +338 -0
  1111. package/packages/crouter-plugin/dist/compare.js +314 -0
  1112. package/packages/crouter-plugin/dist/define.js +531 -0
  1113. package/packages/crouter-plugin/dist/errors.js +150 -0
  1114. package/packages/crouter-plugin/dist/fields.js +83 -0
  1115. package/packages/crouter-plugin/dist/index.js +15 -0
  1116. package/packages/crouter-plugin/dist/manifest.js +111 -0
  1117. package/packages/crouter-plugin/dist/node.js +153 -0
  1118. package/packages/crouter-plugin/dist/params.js +85 -0
  1119. package/packages/crouter-plugin/dist/receipts.js +234 -0
  1120. package/packages/crouter-plugin/dist/serve.js +630 -0
  1121. package/packages/crouter-plugin/dist/verify.js +84 -0
  1122. package/packages/crouter-plugin/dist/watchable.js +14 -0
  1123. package/packages/crouter-plugin/package.json +42 -0
  1124. package/runtime.lock.json +14 -13
  1125. package/dist/core/graph/repo-sync/index.d.ts +0 -4
  1126. package/dist/core/graph/repo-sync/index.js +0 -1
  1127. package/dist/core/graph/repo-sync/mirror.d.ts +0 -30
  1128. package/dist/core/graph/repo-sync/mirror.js +0 -6
  1129. package/dist/core/graph/repo-sync/sync.d.ts +0 -40
  1130. package/dist/core/graph/repo-sync/sync.js +0 -2
@@ -1,11 +1,11 @@
1
- var j=Object.defineProperty;var s=(n,e)=>j(n,"name",{value:e,configurable:!0});import{readFileSync as D}from"node:fs";import{join as x,extname as O}from"node:path";import{fileURLToPath as P}from"node:url";import{withCanvasWrite as p}from"../../core/canvas/db.js";import{ApiError as R}from"../../api/errors.js";import{get as v}from"../../core/graph/bodies.js";import{canChange as E,isShipped as A}from"../../core/graph/access.js";import{documentRecord as T,editDocument as B,heads as $,withCurrentNames as _}from"../../core/graph/documents.js";import{getById as g}from"../../core/graph/objects.js";import{subscribeDocumentEvents as F}from"../../core/graph/events.js";import{emitEvent as I}from"../../core/events/emit.js";import{checkoutsForCwd as J}from"../../core/graph/repo-sync/repos.js";import{canonicalName as L,repoChange as U,syncChanged as W}from"./handlers/docs.js";import{escapeHtml as h}from"./vendor-signin.js";import{readerFor as b,resolveRef as G,warmDocumentWatchers as z}from"./reader.js";import{mergeDocumentLines as M}from"./document-merge.js";import{crtrVersion as V}from"../../shared/crtr-version.js";const X="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'",C={class:"person"},w=encodeURIComponent(V()),S=P(new URL("../../../dist/",import.meta.url));function we(n){n.setHeader("Content-Security-Policy",X),n.setHeader("X-Content-Type-Options","nosniff")}s(we,"setPageHeaders");function u(n,e,t,o){n.writeHead(e,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),n.end(JSON.stringify({error:{code:t,message:o}}))}s(u,"error");function ve(n,e){for(const t of(n??"").split(";")){const o=t.indexOf("=");if(o!==-1&&t.slice(0,o).trim()===e)return t.slice(o+1).trim()}}s(ve,"cookieValue");function H(n,e,t){n.writeHead(e,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),n.end(JSON.stringify(t))}s(H,"json");function Z(n,e,t,o){n.writeHead(e,{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}),n.end(`<!doctype html><html><head><meta charset="utf-8"><title>${h(t)}</title><link rel="icon" href="data:,"></head><body style="font-family:system-ui,sans-serif;max-width:40rem;margin:4rem auto;padding:0 1rem"><h1>${h(t)}</h1><p>${o}</p></body></html>`)}s(Z,"messagePage");function _e(n,e){Z(n,404,"Document not found",`No document you can read is named <code>${h(e)}</code>.`)}s(_e,"documentNotFound");function ge(n,e,t){n.writeHead(200,{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}),n.end(`<!doctype html><html><head><meta charset="utf-8"><title>${h(t.name)}</title><link rel="icon" href="data:,"><link rel="stylesheet" href="/assets/${w}/editor.css"></head><body><div id="app" data-ref="${h(e)}"></div><script type="module" src="/assets/${w}/editor.js"><\/script></body></html>`)}s(ge,"documentShell");async function N(n){return await p(async e=>{const t=await g(e,n.id);if(!t||t.deleted_at||t.type!=="document")return null;const o=await b(e,{principal:C}),a=await T(e,t),r=await $(e,t),i=await L(e,t),c=r.length===1&&await E(e,o,t);return{id:t.id,name:i,revision:a.revision,heads_key:a.heads_key,body:r.length===1?await _(e,t,await v(e,r[0].body_hash)):"",editable:c,...c?{}:{readonly_reason:r.length!==1?`has ${r.length} heads and needs a merge`:await A(e,t)?"shipped by a plugin":"you cannot change this document"}}})}s(N,"snapshot");async function k(n){return await p(async e=>{const t=await b(e,{principal:C});try{const o=await G(e,t,n);return"deleted"in o||"remote"in o||o.type!=="document"?null:o}catch(o){if(o instanceof R&&o.code==="not_found")return null;throw o}})}s(k,"resolveDocument");async function q(n){return await p(async e=>{const t=await g(e,n);return!t||t.type!=="document"||t.deleted_at!==null})}s(q,"isDeleted");async function K(n){const e=[];let t=0;for await(const o of n){if(t+=o.length,t>2e6)throw new Error("request body exceeds 2 MB");e.push(o)}return JSON.parse(Buffer.concat(e).toString("utf8"))}s(K,"requestBody");async function Q(n){await z(n.id);const e=await p(async t=>{const o=await b(t,{principal:C}),a=await g(t,n.id);if(!a||a.type!=="document"||a.deleted_at)return{status:404,value:{error:{code:"not_found",message:"document not found"}}};const r=await T(t,a),i=await $(t,a);if(i.length!==1||!await E(t,o,a))return{status:403,value:{error:{code:"forbidden",message:"document is read-only"}}};const c=await _(t,a,await v(t,i[0].body_hash)),f=await t.prepareUncached("SELECT body_hash FROM revisions WHERE document = ? AND rev_id = ?").get(a.id,n.base_heads_key);if(!f||await _(t,a,await v(t,f.body_hash))!==n.base_body)return{status:409,value:{saved:!1,conflict:{revision:r.revision,heads_key:r.heads_key,current_body:c,your_body:n.body}}};const y=n.base_heads_key!==r.heads_key,l=y?M(n.base_body,n.body,c):n.body;if(l===null)return{status:409,value:{saved:!1,conflict:{revision:r.revision,heads_key:r.heads_key,current_body:c,your_body:n.body}}};const d=await B(t,o,a,{body:l},n.rationale?.trim()||"edited by the person in the browser",r.heads_key,{},async m=>await J(t,m));return"stale"in d?{status:409,value:{saved:!1,conflict:{revision:d.stale.revision,heads_key:d.stale.heads_key,current_body:c,your_body:n.body}}}:{status:200,value:{saved:!0,revision:d.revision,heads_key:d.heads_key,body:l,merged:y},change:await U(t,o,[a])}});return e.change&&await W(e.change),e}s(Q,"save");async function be(n,e,t,o){if(n.method==="GET"&&t.pathname==="/api/doc"){const a=t.searchParams.get("ref"),r=a?await k(a):null,i=r&&await N(r);return i?H(e,200,{...i,ref:a}):u(e,404,"not_found","document not found"),!0}if(n.method==="POST"&&t.pathname==="/api/save"){const a=await K(n);if(!a||typeof a!="object"||Array.isArray(a))return u(e,400,"invalid_request","invalid save body"),!0;const r=a;if(typeof r.id!="string"||typeof r.base_heads_key!="string"||typeof r.base_body!="string"||typeof r.body!="string"||r.rationale!==void 0&&typeof r.rationale!="string")return u(e,400,"invalid_request","invalid save body"),!0;const i=await Q(r);return H(e,i.status,i.value),!0}if(n.method==="GET"&&t.pathname==="/api/events"){const a=t.searchParams.get("id");if(!a||!await k(a))return u(e,404,"not_found","document not found"),!0;e.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-store",Connection:"keep-alive","X-Accel-Buffering":"no"}),e.write(`: connected
1
+ var D=Object.defineProperty;var i=(n,e)=>D(n,"name",{value:e,configurable:!0});import{readFileSync as O}from"node:fs";import{join as x,extname as P}from"node:path";import{fileURLToPath as R}from"node:url";import{withCanvasWrite as p}from"../../core/canvas/db.js";import{ApiError as A}from"../../api/errors.js";import{get as v}from"../../core/graph/bodies.js";import{canChange as E,isShipped as B}from"../../core/graph/access.js";import{documentRecord as T,editDocument as F,heads as $,withCurrentNames as _}from"../../core/graph/documents.js";import{getById as g}from"../../core/graph/objects.js";import{subscribeDocumentEvents as I}from"../../core/graph/events.js";import{emitEvent as J}from"../../core/events/emit.js";import{checkoutsForCwd as L}from"../../core/graph/repo-sync/repos.js";import{canonicalName as U}from"./handlers/docs.js";import{escapeHtml as y}from"./vendor-signin.js";import{readerFor as b,resolveRef as W,warmDocumentWatchers as G}from"./reader.js";import{mergeDocumentLines as z}from"./document-merge.js";import{crtrVersion as M}from"../../shared/crtr-version.js";const V="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'",C={class:"person"},w=encodeURIComponent(M()),S=R(new URL("../../../dist/",import.meta.url));function pe(n){n.setHeader("Content-Security-Policy",V),n.setHeader("X-Content-Type-Options","nosniff")}i(pe,"setPageHeaders");function u(n,e,t,r){n.writeHead(e,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),n.end(JSON.stringify({error:{code:t,message:r}}))}i(u,"error");function we(n,e){for(const t of(n??"").split(";")){const r=t.indexOf("=");if(r!==-1&&t.slice(0,r).trim()===e)return t.slice(r+1).trim()}}i(we,"cookieValue");function H(n,e,t){n.writeHead(e,{"Content-Type":"application/json; charset=utf-8","Cache-Control":"no-store"}),n.end(JSON.stringify(t))}i(H,"json");function X(n,e,t,r){n.writeHead(e,{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}),n.end(`<!doctype html><html><head><meta charset="utf-8"><title>${y(t)}</title><link rel="icon" href="data:,"></head><body style="font-family:system-ui,sans-serif;max-width:40rem;margin:4rem auto;padding:0 1rem"><h1>${y(t)}</h1><p>${r}</p></body></html>`)}i(X,"messagePage");function ve(n,e){X(n,404,"Document not found",`No document you can read is named <code>${y(e)}</code>.`)}i(ve,"documentNotFound");function _e(n,e,t){n.writeHead(200,{"Content-Type":"text/html; charset=utf-8","Cache-Control":"no-store"}),n.end(`<!doctype html><html><head><meta charset="utf-8"><title>${y(t.name)}</title><link rel="icon" href="data:,"><link rel="stylesheet" href="/assets/${w}/editor.css"></head><body><div id="app" data-ref="${y(e)}"></div><script type="module" src="/assets/${w}/editor.js"><\/script></body></html>`)}i(_e,"documentShell");async function N(n){return await p(async e=>{const t=await g(e,n.id);if(!t||t.deleted_at||t.type!=="document")return null;const r=await b(e,{principal:C}),a=await T(e,t),o=await $(e,t),s=await U(e,t),c=o.length===1&&await E(e,r,t);return{id:t.id,name:s,revision:a.revision,heads_key:a.heads_key,body:o.length===1?await _(e,t,await v(e,o[0].body_hash)):"",editable:c,...c?{}:{readonly_reason:o.length!==1?`has ${o.length} heads and needs a merge`:await B(e,t)?"shipped by a plugin":"you cannot change this document"}}})}i(N,"snapshot");async function k(n){return await p(async e=>{const t=await b(e,{principal:C});try{const r=await W(e,t,n);return"deleted"in r||"remote"in r||r.type!=="document"?null:r}catch(r){if(r instanceof A&&r.code==="not_found")return null;throw r}})}i(k,"resolveDocument");async function Z(n){return await p(async e=>{const t=await g(e,n);return!t||t.type!=="document"||t.deleted_at!==null})}i(Z,"isDeleted");async function q(n){const e=[];let t=0;for await(const r of n){if(t+=r.length,t>2e6)throw new Error("request body exceeds 2 MB");e.push(r)}return JSON.parse(Buffer.concat(e).toString("utf8"))}i(q,"requestBody");async function K(n){return await G(n.id),await p(async t=>{const r=await b(t,{principal:C}),a=await g(t,n.id);if(!a||a.type!=="document"||a.deleted_at)return{status:404,value:{error:{code:"not_found",message:"document not found"}}};const o=await T(t,a),s=await $(t,a);if(s.length!==1||!await E(t,r,a))return{status:403,value:{error:{code:"forbidden",message:"document is read-only"}}};const c=await _(t,a,await v(t,s[0].body_hash)),f=await t.prepareUncached("SELECT body_hash FROM revisions WHERE document = ? AND rev_id = ?").get(a.id,n.base_heads_key);if(!f||await _(t,a,await v(t,f.body_hash))!==n.base_body)return{status:409,value:{saved:!1,conflict:{revision:o.revision,heads_key:o.heads_key,current_body:c,your_body:n.body}}};const h=n.base_heads_key!==o.heads_key,l=h?z(n.base_body,n.body,c):n.body;if(l===null)return{status:409,value:{saved:!1,conflict:{revision:o.revision,heads_key:o.heads_key,current_body:c,your_body:n.body}}};const d=await F(t,r,a,{body:l},n.rationale?.trim()||"edited by the person in the browser",o.heads_key,{},async(m,j)=>await L(t,m,j));return"stale"in d?{status:409,value:{saved:!1,conflict:{revision:d.stale.revision,heads_key:d.stale.heads_key,current_body:c,your_body:n.body}}}:{status:200,value:{saved:!0,revision:d.revision,heads_key:d.heads_key,body:l,merged:h}}})}i(K,"save");async function ge(n,e,t,r){if(n.method==="GET"&&t.pathname==="/api/doc"){const a=t.searchParams.get("ref"),o=a?await k(a):null,s=o&&await N(o);return s?H(e,200,{...s,ref:a}):u(e,404,"not_found","document not found"),!0}if(n.method==="POST"&&t.pathname==="/api/save"){const a=await q(n);if(!a||typeof a!="object"||Array.isArray(a))return u(e,400,"invalid_request","invalid save body"),!0;const o=a;if(typeof o.id!="string"||typeof o.base_heads_key!="string"||typeof o.base_body!="string"||typeof o.body!="string"||o.rationale!==void 0&&typeof o.rationale!="string")return u(e,400,"invalid_request","invalid save body"),!0;const s=await K(o);return H(e,s.status,s.value),!0}if(n.method==="GET"&&t.pathname==="/api/events"){const a=t.searchParams.get("id");if(!a||!await k(a))return u(e,404,"not_found","document not found"),!0;e.writeHead(200,{"Content-Type":"text/event-stream","Cache-Control":"no-store",Connection:"keep-alive","X-Accel-Buffering":"no"}),e.write(`: connected
2
2
 
3
- `);const r=s(async()=>{const d=await k(a),m=d&&await N(d);if(!e.writableEnded){if(m){e.write(`event: edited
3
+ `);const o=i(async()=>{const d=await k(a),m=d&&await N(d);if(!e.writableEnded){if(m){e.write(`event: edited
4
4
  data: ${JSON.stringify({revision:m.revision,heads_key:m.heads_key})}
5
5
 
6
- `);return}await q(a)&&e.write(`event: deleted
6
+ `);return}await Z(a)&&e.write(`event: deleted
7
7
  data: {}
8
8
 
9
- `),e.end()}},"notify");let i=!1,c=!1;const f=s(()=>{if(i){c=!0;return}i=!0,o(r).catch(d=>{I({level:"error",event:"daemon.document_events.notify_failed",error:d}),e.end()}).finally(()=>{i=!1,c&&!e.writableEnded&&(c=!1,f())})},"wake"),y=await F(a,f),l=setInterval(()=>{e.writableEnded||e.write(`: keepalive
9
+ `),e.end()}},"notify");let s=!1,c=!1;const f=i(()=>{if(s){c=!0;return}s=!0,r(o).catch(d=>{J({level:"error",event:"daemon.document_events.notify_failed",error:d}),e.end()}).finally(()=>{s=!1,c&&!e.writableEnded&&(c=!1,f())})},"wake"),h=await I(a,f),l=setInterval(()=>{e.writableEnded||e.write(`: keepalive
10
10
 
11
- `)},3e4);return e.on("close",()=>{clearInterval(l),y()}),!0}if(n.method==="GET"&&t.pathname.startsWith(`/assets/${w}/`)){const a=t.pathname.slice(`/assets/${w}/`.length);if(!/^[a-zA-Z0-9_.-]+$/.test(a))return u(e,404,"not_found","asset not found"),!0;const r=a==="mermaid.js"?x(S,"clients/attach/assets/mermaid.min.js"):x(S,"doc-editor",a);try{const i=D(r);e.writeHead(200,{"Content-Type":O(a)===".css"?"text/css; charset=utf-8":"text/javascript; charset=utf-8","Cache-Control":"public, max-age=31536000, immutable"}),e.end(i)}catch(i){if(i.code==="ENOENT")u(e,404,"not_found","asset not found");else throw i}return!0}return!1}s(be,"serveDocumentApi");export{ve as cookieValue,_e as documentNotFound,ge as documentShell,u as error,Z as messagePage,k as resolveDocument,be as serveDocumentApi,we as setPageHeaders};
11
+ `)},3e4);return e.on("close",()=>{clearInterval(l),h()}),!0}if(n.method==="GET"&&t.pathname.startsWith(`/assets/${w}/`)){const a=t.pathname.slice(`/assets/${w}/`.length);if(!/^[a-zA-Z0-9_.-]+$/.test(a))return u(e,404,"not_found","asset not found"),!0;const o=a==="mermaid.js"?x(S,"clients/attach/assets/mermaid.min.js"):x(S,"doc-editor",a);try{const s=O(o);e.writeHead(200,{"Content-Type":P(a)===".css"?"text/css; charset=utf-8":"text/javascript; charset=utf-8","Cache-Control":"public, max-age=31536000, immutable"}),e.end(s)}catch(s){if(s.code==="ENOENT")u(e,404,"not_found","asset not found");else throw s}return!0}return!1}i(ge,"serveDocumentApi");export{we as cookieValue,ve as documentNotFound,_e as documentShell,u as error,X as messagePage,k as resolveDocument,ge as serveDocumentApi,pe as setPageHeaders};
@@ -1 +1 @@
1
- var Y=Object.defineProperty;var a=(t,e)=>Y(t,"name",{value:e,configurable:!0});import{canonicalSessionFile as K,findNodeBySessionFile as z,getNode as v,getNodes as Q,isWarmSpare as X,recordLaunch as Z,recordRespawnAttempt as I,recordSettledTurn as q,setPresence as x,subscriptionsOf as ee,updateNode as _,updateNodeTelemetry as te}from"../../../core/canvas/canvas.js";import{liveExecutionForNode as S,recordExecutionIdle as ne,recordExecutionPid as ie}from"../../../core/canvas/executions.js";import{bindSession as re,readLiveSession as oe,transferSession as ae}from"../../../core/canvas/sessions.js";import{isSafeNodeId as se}from"../../../core/canvas/paths.js";import{isPidAlive as ce}from"../../../core/canvas/pid.js";import{editorLabel as P}from"../../../core/canvas/labels.js";import{assembleNodeSubject as de}from"../../../core/substrate/subject.js";import{openDb as B,withCanvasWrite as m}from"../../../core/canvas/db.js";import{runningJobs as le}from"../../../core/graph/jobs.js";import{notFound as R,usage as l}from"../../../core/errors.js";import{hasUnseenWakeMail as F,releaseExecutionMail as ue}from"../../../core/canvas/deliveries.js";import{clearYieldMessage as pe}from"../../../core/runtime/kickoff.js";import{readRoadmap as fe}from"../../../core/runtime/roadmap.js";import{forkSourceNode as me}from"../../../core/runtime/nodes.js";import{transition as k}from"../../../core/runtime/lifecycle.js";import{confirmViewer as N,probeViewer as T,tearDownNode as C}from"../../../core/runtime/placement.js";import{hasAttachedBrokerViewers as we}from"../viewer-presence.js";import{evaluateStop as ye}from"../../../core/runtime/stop-guard.js";import{readOutputRequest as L}from"../../../core/runtime/output-result.js";import{clearFault as b,readFault as he,recordFault as be}from"../../../core/canvas/recovery.js";import{updateModelRecipe as _e}from"../../../core/runtime/model-swap.js";import{completeCompanionRequestedSubmit as ke}from"../../review/finish.js";import{emitEvent as D}from"../../../core/events/emit.js";import{consumePendingPark as ge,recordPendingParkActivity as ve}from"../../park-pending.js";import{shouldParkAfterSummary as xe}from"../../park-activity.js";import{ownerOnly as Se}from"../router.js";import{situationalContextEnvelope as Pe}from"../../../core/runtime/situational-context.js";import{recoveryState as Re,requireCurrentExecution as p}from"./broker-recovery.js";import{runAttachments as Oe}from"./node-records.js";import{readerForNode as Ee,warmNodeRepos as Ae}from"../../../core/graph/reader.js";import{noteNodeBooting as Be}from"../../../core/graph/repo-sync/index.js";import{checkoutsForCwd as Fe}from"../../../core/graph/repo-sync/repos.js";import{deliver as O}from"../../../core/substrate/delivery/deliver.js";import{ensureRunObserver as Ne}from"../../runs/observer.js";import{parseNodeTelemetryRecord as Te,writeNodeTelemetryRecord as Ce}from"./telemetry-record.js";import{mapAsync as Le}from"../../../core/async-array.js";import{crtrVersion as M}from"../../../shared/crtr-version.js";import{buildPiArgv as De}from"../../../core/runtime/launch.js";import{brokerLaunchJson as Me}from"../../../core/runtime/host.js";import{CYCLE_APPLIED_ENV as Ve,cycleCompatible as $e}from"../../../core/runtime/launch-recipe.js";import{buildReviveKickoff as je,drainBearings as Ue}from"../../../core/runtime/kickoff.js";import{clearNodeLedger as We}from"../../../core/runtime/ledger.js";import{runNodeStartHooks as He}from"../../../core/runtime/revive.js";import{consumeDeadlineOnWake as Je}from"../../../core/feed/messages.js";import{encodeKickoffOrigin as Ge}from"../../../core/runtime/stamp/protocol.js";import{ApiError as Ye}from"../../../api/errors.js";function f(t,e){if(typeof t!="object"||t===null||Array.isArray(t))throw l(`${e} requires a JSON body`);return t}a(f,"objectBody");function V(t){const e=f(t,"broker session-bound");if(typeof e.executionId!="string"||e.executionId==="")throw l("executionId must be a non-empty string");if(typeof e.piSessionId!="string"||e.piSessionId==="")throw l("piSessionId must be a non-empty string");if(e.sessionFile!==null&&typeof e.sessionFile!="string")throw l("sessionFile must be a string or null");if(!Number.isSafeInteger(e.pid)||e.pid<=0)throw l("pid must be a positive safe integer");if(e.reason!==null&&typeof e.reason!="string")throw l("reason must be a string or null");if(!Array.isArray(e.reviewBoundaryIds)||!e.reviewBoundaryIds.every(n=>typeof n=="string"))throw l("reviewBoundaryIds must be an array of strings");return e}a(V,"parseSessionBoundBody");function Ke(t){const e=f(t,"broker settle");if(typeof e.stopReason!="string")throw l("stopReason must be a string");for(const n of["pushedFinal"])if(typeof e[n]!="boolean")throw l(`${n} must be a boolean`);return e}a(Ke,"parseSettleBody");function ze(t){const e=f(t,"broker cycle");if(typeof e.brokerVersion!="string"||e.brokerVersion==="")throw l("brokerVersion must be a non-empty string");return e}a(ze,"parseCycleBody");function Qe(t){const e=f(t,"broker park-complete");if(e.outcome!=="completed"&&e.outcome!=="failed")throw l("outcome must be completed or failed");return e}a(Qe,"parseParkCompleteBody");function Xe(t){const e=f(t,"broker telemetry");if(typeof e.expected_execution_id!="string"||e.expected_execution_id==="")throw l("expected_execution_id must be a non-empty string");const n=Te(e);return{...n,expected_execution_id:e.expected_execution_id,updated_at:new Date(n.updated_at).toISOString()}}a(Xe,"parseTelemetryBody");function Ze(t){const e=f(t,"broker model");if(typeof e.spec!="string"||e.spec.trim()==="")throw l("spec must be a non-empty string");const n=e.intent;if(n!==void 0){const r=n!==null&&typeof n=="object"?n:void 0;if(r===void 0||typeof r.family!="string"||r.family===""||!["ultra","strong","medium","light"].includes(r.strength))throw l("intent must be { family, strength } with strength ultra|strong|medium|light when present")}if(typeof e.userSelected!="boolean")throw l("userSelected must be a boolean");return e}a(Ze,"parseModelCommitBody");async function w(t){const e=await v(t);if(e===null)throw R(`unknown node: ${t}`,{received:t});return e}a(w,"requireNode");async function g(t){return{node_id:t.node_id,grantee:t.grantee,name:t.name,...t.description===void 0?{}:{description:t.description},...t.title===void 0?{}:{title:t.title},...t.icon===void 0?{}:{icon:t.icon},kind:t.kind,mode:t.mode,lifecycle:t.lifecycle,status:t.status,cwd:t.cwd,parent:t.parent??null,fork_from:t.fork_from??null,profile_id:t.profile_id??null,...t.managed_worktree===void 0?{}:{managed_worktree:t.managed_worktree===null?null:{state:t.managed_worktree.state,...t.managed_worktree.cleanup===void 0?{}:{cleanup:t.managed_worktree.cleanup},path:t.managed_worktree.path,branch:t.managed_worktree.branch,base_ref:t.managed_worktree.base_ref,base_sha:t.managed_worktree.base_sha}},...t.review_binding===void 0?{}:{review_binding:t.review_binding??null},intent:t.intent??null,...t.persona_ack===void 0?{}:{persona_ack:t.persona_ack},created:t.created}}a(g,"extensionNode");async function $(t){const e=await w(t),n=[],r=new Set([t]);let i=e.parent??null;for(;i!==null&&i!==""&&!r.has(i);){r.add(i);const d=await v(i);if(d===null)break;n.unshift(await g(d)),i=d.parent??null}const s=await Le((await Q((await ee(t)).map(d=>d.node_id))).filter(d=>d.kind!=="human").sort((d,h)=>d.status===h.status?0:d.status==="active"?-1:h.status==="active"?1:0),g),o=typeof e.fork_source_file=="string"?await me(e.fork_source_file):null,c=await de(t);if(c===null)throw R(`unknown node: ${t}`,{received:t});return{node:await g(e),warm_spare:await X(t),situational_card:await Pe(t),ancestors:n,children:s,fork_source:o===null?null:await g(o),subject:c,roadmap:await fe(t)}}a($,"extensionState");function E(t,e){return t?.kind===e.kind&&t?.mode===e.mode&&t?.lifecycle===e.lifecycle}a(E,"samePersona");function Ie(t){const e=f(t,"broker generated-name");if(e.kind!=="initial"&&e.kind!=="recap")throw l("kind must be initial or recap");if(typeof e.description!="string"||typeof e.title!="string"||typeof e.icon!="string")throw l("description, title, and icon must be strings");if(e.kind==="initial")return e;const n=e.expected;if(typeof n!="object"||n===null||Array.isArray(n)||["name","description","title","icon","kind"].some(r=>typeof n[r]!="string"))throw l("recap expected must contain name, description, title, icon, and kind strings");return e}a(Ie,"parseGeneratedNameBody");function qe(t){const e=f(t,"broker persona-ack"),n=a(r=>{const i=e[r];if(typeof i!="object"||i===null||Array.isArray(i)||typeof i.kind!="string"||i.mode!=="base"&&i.mode!=="orchestrator"||i.lifecycle!=="terminal"&&i.lifecycle!=="resident")throw l(`${r} must be a persona state`);return i},"parse");return{expected_execution_id:e.expected_execution_id,from:n("from"),to:n("to")}}a(qe,"parsePersonaAckBody");async function j(t,e){const n=e.sessionFile===null?null:K(e.sessionFile);return await m(async r=>{await r.prepareUncached("SELECT 1 FROM nodes WHERE node_id = ? FOR UPDATE").get(t);const i=await w(t);if(await ie(e.executionId,t,e.pid)==="shutdown")return{action:"shutdown"};const s=i.review_binding?.review_id;if(s!==void 0&&!e.reviewBoundaryIds.includes(s))return{action:"shutdown"};if(e.reason==="new"&&i.parent==null)return{action:"relaunch_root"};if(e.reason!=="new"&&i.fork_from!=null&&i.pi_session_id==null&&n===null)return{action:"shutdown"};const o=n===null?null:await z(n);if(o!==null&&o.node_id!==t){if(ce(o.pi_pid))return await be(t,{link:"daemon\u2192node",op:"session-file-ownership",kind:"protocol",retry:{disposition:"fatal"},message:`refusing to bind ${n}: it is owned by live node ${o.node_id}`}),{action:"shutdown"};const c=await oe(o.node_id);if(c===null||await ae({fromNodeId:o.node_id,fromBindingId:c.bindingId,toNodeId:t,executionId:e.executionId,sessionId:e.piSessionId,transcriptPath:n})!=="transferred")return{action:"shutdown"}}else if(await re(t,{executionId:e.executionId,sessionId:e.piSessionId,transcriptPath:n})==="shutdown")return{action:"shutdown"};return e.reason!=="new"&&(await pe(t),i.intent==="refresh"&&await k(t,"revive")),{action:"none"}})}a(j,"commitSessionBound");async function et(t){return{status:200,body:await j(t.params.id,V(t.body))}}a(et,"handleSessionBound");function tt(t){const e=V(t);if(e.bearings!=="fresh"&&e.bearings!=="inherited"&&e.bearings!=="present")throw l("bearings must be fresh, inherited or present");return e}a(tt,"parseCycleStartBody");async function nt(t,e,n,r){const i=e.warm_spare||r,s=!i&&n!=="present";return s&&await Be(t),await Ae(await B(),t),await m(async o=>{const c=await Ee(o,t,async y=>await Fe(o,y)),d=await O(o,c,{activity:"names"}),h=s?await O(o,c,{activity:"boot",...n==="inherited"?{inherited:!0}:{}}):void 0,u=i?void 0:await O(o,c,{activity:"system-prompt"});return{names:{refs:d.refs,names:d.names},...h===void 0?{}:{boot:{content:h.content,...h.inherited===!0?{inherited:!0}:{}}},...u===void 0?{}:{system_prompt:u.content}}})}a(nt,"startupDelivery");async function it(t){const e=t.params.id,n=tt(t.body),r=await w(e),i=r.review_binding?.review_id,s=i!==void 0&&!n.reviewBoundaryIds.includes(i),o=s||r.cycle_pending===!0||r.intent==="refresh"||r.pi_session_id==null;if(o)await p(e,n.executionId);else{const{action:u}=await j(e,n);if(u!=="none")return{status:200,body:{action:u}}}const c=await $(e),d=await nt(e,c,n.bearings,s);if(d.boot!==void 0){const u={kind:c.node.kind,mode:c.node.mode,lifecycle:c.node.lifecycle},y=c.node.persona_ack,A=y===void 0?u:{kind:y.kind??c.node.kind,mode:y.mode,lifecycle:y.lifecycle};E(A,u)||await G(e,A,u)}return{status:200,body:{action:"none",...o?{bind_pending:!0}:{},state:c,...d,recovery:await Re(e),attachments:(await Oe(e)).map(({path:u,sha256:y})=>({path:u,sha256:y})),structured_request:await L(e)}}}a(it,"handleCycleStart");async function U(t,e){return e.live!==null||await we(t)||await F(t)}a(U,"isHeldAwake");async function W(t,e){return(await S(t))?.runner==="blaxel"&&!await U(t,e)&&(await le(await B(),t)).length===0}a(W,"residentBlaxelCanIdle");function H(t){return t.inPlaceCycle===!0?{action:"new_cycle"}:{action:"shutdown"}}a(H,"refreshDirective");async function rt(t,e,n){const r=await v(t);if(r===null){if(e.pushedFinal)return{directive:{action:"shutdown"},closePane:!1};throw R(`unknown node: ${t}`,{received:t})}if(await q(t,new Date().toISOString()),(e.stopReason==="stop"||e.stopReason==="length")&&await I(t,{failures:0,notBefore:null}),e.stopReason==="quit"){let c=!1;return(r.status==="active"||r.status==="idle")&&r.intent===null&&(await k(t,"finish"),await b(t),await x(t,{pane:null,tmux_session:null,window:null}),c=!0),{directive:{action:"shutdown"},closePane:c}}if(e.stopReason!=="stop"&&e.stopReason!=="length")return await b(t,{link:"daemon\u2192node"}),r.intent==="refresh"?{directive:H(e),closePane:!1}:e.stopReason==="error"&&e.faultSettled===!0&&(await he(t))?.retry.disposition==="fatal"&&await L(t)===null&&await W(t,n)?{directive:{action:"stay_resident"},closePane:!1}:{directive:{action:"stay_dormant"},closePane:!1};const i={pushedFinal:e.pushedFinal};if(i.pushedFinal||r.status==="done")return await b(t),await x(t,{pane:null,tmux_session:null,window:null}),{directive:{action:"shutdown"},closePane:!0};if(r.intent==="refresh")return await b(t),{directive:H(e),closePane:!1};const s=await ye(t,i);if(await b(t),s.action==="reprompt")return{directive:{action:"reprompt",prompt:s.message},closePane:!1};if(s.reason==="finished")return{directive:await F(t)?{action:"stay_dormant"}:{action:"shutdown"},closePane:!1};const o=await U(t,n);return(await S(t))?.runner==="blaxel"?{directive:await W(t,n)?{action:"stay_resident"}:{action:"stay_dormant"},closePane:!1}:s.reason!=="awaiting"&&s.reason!=="scheduled"?{directive:{action:"stay_dormant"},closePane:!1}:o?{directive:{action:"stay_dormant"},closePane:!1}:(await k(t,"release"),{directive:{action:"shutdown"},closePane:!1})}a(rt,"settleBroker");async function ot(t){const e=t.params.id,n=ze(t.body);await p(e,n.expected_execution_id);const r=await w(e);if(r.intent!=="refresh")throw new Ye(409,"not_yielding",`${e} has no pending yield`);const i=await S(e),s=De(r);return n.brokerVersion===M()&&(i.release===null||i.release===M())&&$e(i.launchJson,await Me(e,s,r.cwd))?{status:200,body:await at(e,r,i.executionId,s.env)}:{status:200,body:{action:"restart"}}}a(ot,"handleCycle");async function at(t,e,n,r){e.cycles=(e.cycles??0)+1,await ue(t,n);const i=await Ue(e,n),s=await je(e,i);await We(t),await He(t,e,!1),await Je(t),await b(t,{preserveEpisode:!0}),await Z(t,new Date().toISOString()),await _(t,{cycles:e.cycles,cycle_pending:!0});const o={};for(const c of Ve)r[c]!==void 0&&(o[c]=r[c]);return o.CRTR_CYCLES=String(e.cycles),{action:"cycle",cycle:e.cycles,prompt:s,origin:Ge({type:"runtime",kind:"revive",cycle:e.cycles}),messageIds:e.run_id?i.unreadMessageIds??[]:[],env:o,...e.launch?.model!==void 0?{model:e.launch.model}:{},modelExact:e.launch?.modelExact===!0,editorLabel:P(e)}}a(at,"startCycleRecord");async function st(t){const e=t.params.id,n=f(t.body,"broker idle");return await p(e,n.expected_execution_id),await ne(n.expected_execution_id),{status:204}}a(st,"handleIdle");async function ct(t){const e=t.params.id,n=Ke(t.body);await p(e,n.expected_execution_id);const r=await T(e),{directive:i,closePane:s}=await m(async()=>await rt(e,n,await N(r)));return s&&await C(e),i.action!=="reprompt"&&ke(e).catch(o=>D({level:"error",event:"api.broker_ops.companion_submit_failed",node_id:e,error:o})),{status:200,body:i}}a(ct,"handleSettle");async function dt(t){const e=t.params.id,n=Qe(t.body);await p(e,n.expected_execution_id);const r=await T(e),i=await m(async()=>{const s=await ge(e);if(s===void 0)return{action:"stay_dormant"};const o=await w(e);return await xe(e,o,s,await N(r))?(await b(e),await k(e,"park"),await x(e,{pane:null,tmux_session:null,window:null}),D({level:n.outcome==="completed"?"info":"warn",event:"broker.park.complete",...se(e)?{node_id:e}:{},outcome:n.outcome==="completed"?"succeeded":"failed"}),{action:"shutdown"}):{action:"stay_dormant"}});return i.action==="shutdown"&&await C(e),{status:200,body:i}}a(dt,"handleParkComplete");async function lt(t){const e=t.params.id;return await p(e,f(t.body,"broker park-activity").expected_execution_id),{status:200,body:await m(async()=>({activity:await ve(e)?"recorded":"none"}))}}a(lt,"handleParkActivity");async function ut(t){const e=t.params.id,n=Xe(t.body);return await p(e,n.expected_execution_id),await m(async()=>{await te(e,{tokensIn:n.tokens_in,contextTokens:n.context_tokens,lastActivity:n.last_activity,updatedAt:n.updated_at}),Ce(e,n)}),{status:204}}a(ut,"handleTelemetry");async function pt(t){const e=t.params.id,n=Ze(t.body);return await p(e,n.expected_execution_id),{status:200,body:{modelOverride:(await m(async()=>await _e(await w(e),n.spec,n.intent,n.userSelected))).model_override}}}a(pt,"handleModelCommit");let J=!0;function ln(t){J=t}a(ln,"setRequestsStartRunObservers");async function ft(t){const e=t.params.id,n=await w(e);return n.run_id&&J&&await Ne(e,n.run_id),{status:200,body:await $(e)}}a(ft,"handleExtensionState");async function mt(t){const e=t.params.id,n=Ie(t.body);return await p(e,n.expected_execution_id),{status:200,body:await m(async i=>{await i.prepareUncached("SELECT 1 FROM nodes WHERE node_id = ? FOR UPDATE").get(e);const s=await w(e);if(n.kind==="initial"){if((s.description??"").trim()!=="")return{applied:!1};const d=await _(e,{description:n.description,...n.title.trim()===""?{}:{title:n.title},...n.icon.trim()===""?{}:{icon:n.icon}});return{applied:!0,editorLabel:P(d),description:d.description??"",title:d.title??"",icon:d.icon??""}}const o=n.expected;if(s.name!==o.name||(s.description??"")!==o.description||(s.title??"")!==o.title||(s.icon??"")!==o.icon||s.kind!==o.kind)return{applied:!1};const c=await _(e,{description:n.description,title:n.title.trim()===""?void 0:n.title,icon:n.icon.trim()===""?void 0:n.icon});return{applied:!0,editorLabel:P(c),description:c.description??"",title:c.title??"",icon:c.icon??""}})}}a(mt,"handleGeneratedName");async function wt(t){const e=t.params.id,n=qe(t.body);return await p(e,n.expected_execution_id),{status:200,body:{applied:await G(e,n.from,n.to)}}}a(wt,"handlePersonaAck");async function G(t,e,n){return await m(async r=>{await r.prepareUncached("SELECT 1 FROM nodes WHERE node_id = ? FOR UPDATE").get(t);const i=await w(t),s={kind:i.kind,mode:i.mode,lifecycle:i.lifecycle},o=i.persona_ack,c=o===void 0?s:{kind:o.kind??i.kind,mode:o.mode,lifecycle:o.lifecycle};return!E(s,n)||!E(c,e)?!1:(await _(t,{persona_ack:n}),!0)})}a(G,"applyPersonaAck");const un=Se([{method:"POST",pattern:"/v1/nodes/:id/broker/session-bound",handler:et},{method:"POST",pattern:"/v1/nodes/:id/broker/cycle-start",handler:it},{method:"POST",pattern:"/v1/nodes/:id/broker/settle",handler:ct},{method:"POST",pattern:"/v1/nodes/:id/broker/cycle",handler:ot},{method:"POST",pattern:"/v1/nodes/:id/broker/idle",handler:st},{method:"POST",pattern:"/v1/nodes/:id/broker/park-complete",handler:dt},{method:"POST",pattern:"/v1/nodes/:id/broker/park-activity",handler:lt},{method:"POST",pattern:"/v1/nodes/:id/broker/telemetry",handler:ut},{method:"POST",pattern:"/v1/nodes/:id/broker/model",handler:pt},{method:"GET",pattern:"/v1/nodes/:id/broker/extension-state",handler:ft},{method:"POST",pattern:"/v1/nodes/:id/broker/generated-name",handler:mt},{method:"POST",pattern:"/v1/nodes/:id/broker/persona-ack",handler:wt}]);export{un as brokerOperationRoutes,g as extensionNode,ln as setRequestsStartRunObservers};
1
+ var Y=Object.defineProperty;var a=(t,e)=>Y(t,"name",{value:e,configurable:!0});import{canonicalSessionFile as K,findNodeBySessionFile as z,getNode as x,getNodes as I,isWarmSpare as Q,recordLaunch as X,recordRespawnAttempt as Z,recordSettledTurn as q,setPresence as S,subscriptionsOf as ee,updateNode as k,updateNodeTelemetry as te}from"../../../core/canvas/canvas.js";import{liveExecutionForNode as P,recordExecutionIdle as ne,recordExecutionPid as ie}from"../../../core/canvas/executions.js";import{bindSession as re,readLiveSession as oe,transferSession as ae}from"../../../core/canvas/sessions.js";import{isSafeNodeId as se}from"../../../core/canvas/paths.js";import{isPidAlive as ce}from"../../../core/canvas/pid.js";import{editorLabel as R}from"../../../core/canvas/labels.js";import{assembleNodeSubject as de}from"../../../core/substrate/subject.js";import{openDb as F,withCanvasWrite as m}from"../../../core/canvas/db.js";import{runningJobs as le}from"../../../core/graph/jobs.js";import{notFound as O,usage as l}from"../../../core/errors.js";import{hasUnseenWakeMail as T,releaseExecutionMail as ue}from"../../../core/canvas/deliveries.js";import{clearYieldMessage as pe}from"../../../core/runtime/kickoff.js";import{readRoadmap as fe}from"../../../core/runtime/roadmap.js";import{forkSourceNode as me}from"../../../core/runtime/nodes.js";import{transition as g}from"../../../core/runtime/lifecycle.js";import{confirmViewer as B,probeViewer as C,tearDownNode as N}from"../../../core/runtime/placement.js";import{hasAttachedBrokerViewers as we}from"../viewer-presence.js";import{evaluateStop as ye}from"../../../core/runtime/stop-guard.js";import{readOutputRequest as L}from"../../../core/runtime/output-result.js";import{clearFault as b,readFault as he,recordFault as be}from"../../../core/canvas/recovery.js";import{updateModelRecipe as _e}from"../../../core/runtime/model-swap.js";import{completeCompanionRequestedSubmit as ke}from"../../review/finish.js";import{emitEvent as D}from"../../../core/events/emit.js";import{consumePendingPark as ge,recordPendingParkActivity as ve}from"../../park-pending.js";import{shouldParkAfterSummary as xe}from"../../park-activity.js";import{ownerOnly as Se}from"../router.js";import{situationalContextEnvelope as Pe}from"../../../core/runtime/situational-context.js";import{recoveryState as Re,requireCurrentExecution as p}from"./broker-recovery.js";import{runAttachments as Oe}from"./node-records.js";import{readerForNode as Ee,warmNodeRepos as Ae}from"../../../core/graph/reader.js";import{checkoutsForCwd as Fe}from"../../../core/graph/repo-sync/repos.js";import{deliver as E}from"../../../core/substrate/delivery/deliver.js";import{ensureRunObserver as Te}from"../../runs/observer.js";import{parseNodeTelemetryRecord as Be,writeNodeTelemetryRecord as Ce}from"./telemetry-record.js";import{mapAsync as Ne}from"../../../core/async-array.js";import{crtrVersion as M}from"../../../shared/crtr-version.js";import{buildPiArgv as Le}from"../../../core/runtime/launch.js";import{brokerLaunchJson as De}from"../../../core/runtime/host.js";import{CYCLE_APPLIED_ENV as Me,cycleCompatible as Ve}from"../../../core/runtime/launch-recipe.js";import{buildReviveKickoff as $e,drainBearings as je}from"../../../core/runtime/kickoff.js";import{clearNodeLedger as Ue}from"../../../core/runtime/ledger.js";import{runNodeStartHooks as We}from"../../../core/runtime/revive.js";import{consumeDeadlineOnWake as He}from"../../../core/feed/messages.js";import{encodeKickoffOrigin as Je}from"../../../core/runtime/stamp/protocol.js";import{ApiError as Ge}from"../../../api/errors.js";function f(t,e){if(typeof t!="object"||t===null||Array.isArray(t))throw l(`${e} requires a JSON body`);return t}a(f,"objectBody");function V(t){const e=f(t,"broker session-bound");if(typeof e.executionId!="string"||e.executionId==="")throw l("executionId must be a non-empty string");if(typeof e.piSessionId!="string"||e.piSessionId==="")throw l("piSessionId must be a non-empty string");if(e.sessionFile!==null&&typeof e.sessionFile!="string")throw l("sessionFile must be a string or null");if(!Number.isSafeInteger(e.pid)||e.pid<=0)throw l("pid must be a positive safe integer");if(e.reason!==null&&typeof e.reason!="string")throw l("reason must be a string or null");if(!Array.isArray(e.reviewBoundaryIds)||!e.reviewBoundaryIds.every(n=>typeof n=="string"))throw l("reviewBoundaryIds must be an array of strings");return e}a(V,"parseSessionBoundBody");function Ye(t){const e=f(t,"broker settle");if(typeof e.stopReason!="string")throw l("stopReason must be a string");for(const n of["pushedFinal"])if(typeof e[n]!="boolean")throw l(`${n} must be a boolean`);return e}a(Ye,"parseSettleBody");function Ke(t){const e=f(t,"broker cycle");if(typeof e.brokerVersion!="string"||e.brokerVersion==="")throw l("brokerVersion must be a non-empty string");return e}a(Ke,"parseCycleBody");function ze(t){const e=f(t,"broker park-complete");if(e.outcome!=="completed"&&e.outcome!=="failed")throw l("outcome must be completed or failed");return e}a(ze,"parseParkCompleteBody");function Ie(t){const e=f(t,"broker telemetry");if(typeof e.expected_execution_id!="string"||e.expected_execution_id==="")throw l("expected_execution_id must be a non-empty string");const n=Be(e);return{...n,expected_execution_id:e.expected_execution_id,updated_at:new Date(n.updated_at).toISOString()}}a(Ie,"parseTelemetryBody");function Qe(t){const e=f(t,"broker model");if(typeof e.spec!="string"||e.spec.trim()==="")throw l("spec must be a non-empty string");const n=e.intent;if(n!==void 0){const r=n!==null&&typeof n=="object"?n:void 0;if(r===void 0||typeof r.family!="string"||r.family===""||!["ultra","strong","medium","light"].includes(r.strength))throw l("intent must be { family, strength } with strength ultra|strong|medium|light when present")}if(typeof e.userSelected!="boolean")throw l("userSelected must be a boolean");return e}a(Qe,"parseModelCommitBody");async function w(t){const e=await x(t);if(e===null)throw O(`unknown node: ${t}`,{received:t});return e}a(w,"requireNode");async function v(t){return{node_id:t.node_id,grantee:t.grantee,name:t.name,...t.description===void 0?{}:{description:t.description},...t.title===void 0?{}:{title:t.title},...t.icon===void 0?{}:{icon:t.icon},kind:t.kind,mode:t.mode,lifecycle:t.lifecycle,status:t.status,cwd:t.cwd,parent:t.parent??null,fork_from:t.fork_from??null,profile_id:t.profile_id??null,...t.managed_worktree===void 0?{}:{managed_worktree:t.managed_worktree===null?null:{state:t.managed_worktree.state,...t.managed_worktree.cleanup===void 0?{}:{cleanup:t.managed_worktree.cleanup},path:t.managed_worktree.path,branch:t.managed_worktree.branch,base_ref:t.managed_worktree.base_ref,base_sha:t.managed_worktree.base_sha}},...t.review_binding===void 0?{}:{review_binding:t.review_binding??null},intent:t.intent??null,...t.persona_ack===void 0?{}:{persona_ack:t.persona_ack},created:t.created}}a(v,"extensionNode");async function $(t){const e=await w(t),n=[],r=new Set([t]);let i=e.parent??null;for(;i!==null&&i!==""&&!r.has(i);){r.add(i);const d=await x(i);if(d===null)break;n.unshift(await v(d)),i=d.parent??null}const s=await Ne((await I((await ee(t)).map(d=>d.node_id))).filter(d=>d.kind!=="human").sort((d,h)=>d.status===h.status?0:d.status==="active"?-1:h.status==="active"?1:0),v),o=typeof e.fork_source_file=="string"?await me(e.fork_source_file):null,c=await de(t);if(c===null)throw O(`unknown node: ${t}`,{received:t});return{node:await v(e),warm_spare:await Q(t),situational_card:await Pe(t),ancestors:n,children:s,fork_source:o===null?null:await v(o),subject:c,roadmap:await fe(t)}}a($,"extensionState");function A(t,e){return t?.kind===e.kind&&t?.mode===e.mode&&t?.lifecycle===e.lifecycle}a(A,"samePersona");function Xe(t){const e=f(t,"broker generated-name");if(e.kind!=="initial"&&e.kind!=="recap")throw l("kind must be initial or recap");if(typeof e.description!="string"||typeof e.title!="string"||typeof e.icon!="string")throw l("description, title, and icon must be strings");if(e.kind==="initial")return e;const n=e.expected;if(typeof n!="object"||n===null||Array.isArray(n)||["name","description","title","icon","kind"].some(r=>typeof n[r]!="string"))throw l("recap expected must contain name, description, title, icon, and kind strings");return e}a(Xe,"parseGeneratedNameBody");function Ze(t){const e=f(t,"broker persona-ack"),n=a(r=>{const i=e[r];if(typeof i!="object"||i===null||Array.isArray(i)||typeof i.kind!="string"||i.mode!=="base"&&i.mode!=="orchestrator"||i.lifecycle!=="terminal"&&i.lifecycle!=="resident")throw l(`${r} must be a persona state`);return i},"parse");return{expected_execution_id:e.expected_execution_id,from:n("from"),to:n("to")}}a(Ze,"parsePersonaAckBody");async function j(t,e){const n=e.sessionFile===null?null:K(e.sessionFile);return await m(async r=>{await r.prepareUncached("SELECT 1 FROM nodes WHERE node_id = ? FOR UPDATE").get(t);const i=await w(t);if(await ie(e.executionId,t,e.pid)==="shutdown")return{action:"shutdown"};const s=i.review_binding?.review_id;if(s!==void 0&&!e.reviewBoundaryIds.includes(s))return{action:"shutdown"};if(e.reason==="new"&&i.parent==null)return{action:"relaunch_root"};if(e.reason!=="new"&&i.fork_from!=null&&i.pi_session_id==null&&n===null)return{action:"shutdown"};const o=n===null?null:await z(n);if(o!==null&&o.node_id!==t){if(ce(o.pi_pid))return await be(t,{link:"daemon\u2192node",op:"session-file-ownership",kind:"protocol",retry:{disposition:"fatal"},message:`refusing to bind ${n}: it is owned by live node ${o.node_id}`}),{action:"shutdown"};const c=await oe(o.node_id);if(c===null||await ae({fromNodeId:o.node_id,fromBindingId:c.bindingId,toNodeId:t,executionId:e.executionId,sessionId:e.piSessionId,transcriptPath:n})!=="transferred")return{action:"shutdown"}}else if(await re(t,{executionId:e.executionId,sessionId:e.piSessionId,transcriptPath:n})==="shutdown")return{action:"shutdown"};return e.reason!=="new"&&(await pe(t),i.intent==="refresh"&&await g(t,"revive")),{action:"none"}})}a(j,"commitSessionBound");async function qe(t){return{status:200,body:await j(t.params.id,V(t.body))}}a(qe,"handleSessionBound");function et(t){const e=V(t);if(e.bearings!=="fresh"&&e.bearings!=="inherited"&&e.bearings!=="present")throw l("bearings must be fresh, inherited or present");return e}a(et,"parseCycleStartBody");async function tt(t,e,n,r){const i=e.warm_spare||r,s=!i&&n!=="present";return await Ae(await F(),t),await m(async o=>{const c=await Ee(o,t,async(y,_)=>await Fe(o,y,_)),d=await E(o,c,{activity:"names"}),h=s?await E(o,c,{activity:"boot",...n==="inherited"?{inherited:!0}:{}}):void 0,u=i?void 0:await E(o,c,{activity:"system-prompt"});return{names:{refs:d.refs,names:d.names},...h===void 0?{}:{boot:{content:h.content,...h.inherited===!0?{inherited:!0}:{}}},...u===void 0?{}:{system_prompt:u.content}}})}a(tt,"startupDelivery");async function nt(t){const e=t.params.id,n=et(t.body),r=await w(e),i=r.review_binding?.review_id,s=i!==void 0&&!n.reviewBoundaryIds.includes(i),o=s||r.cycle_pending===!0||r.intent==="refresh"||r.pi_session_id==null;if(o)await p(e,n.executionId);else{const{action:u}=await j(e,n);if(u!=="none")return{status:200,body:{action:u}}}const c=await $(e),d=await tt(e,c,n.bearings,s);if(d.boot!==void 0){const u={kind:c.node.kind,mode:c.node.mode,lifecycle:c.node.lifecycle},y=c.node.persona_ack,_=y===void 0?u:{kind:y.kind??c.node.kind,mode:y.mode,lifecycle:y.lifecycle};A(_,u)||await G(e,_,u)}return{status:200,body:{action:"none",...o?{bind_pending:!0}:{},state:c,...d,recovery:await Re(e),attachments:(await Oe(e)).map(({path:u,sha256:y})=>({path:u,sha256:y})),structured_request:await L(e)}}}a(nt,"handleCycleStart");async function U(t,e){return e.live!==null||await we(t)||await T(t)}a(U,"isHeldAwake");async function W(t,e){return(await P(t))?.runner==="blaxel"&&!await U(t,e)&&(await le(await F(),t)).length===0}a(W,"residentBlaxelCanIdle");function H(t){return t.inPlaceCycle===!0?{action:"new_cycle"}:{action:"shutdown"}}a(H,"refreshDirective");async function it(t,e,n){const r=await x(t);if(r===null){if(e.pushedFinal)return{directive:{action:"shutdown"},closePane:!1};throw O(`unknown node: ${t}`,{received:t})}if(await q(t,new Date().toISOString()),(e.stopReason==="stop"||e.stopReason==="length")&&await Z(t,{failures:0,notBefore:null}),e.stopReason==="quit"){let c=!1;return(r.status==="active"||r.status==="idle")&&r.intent===null&&(await g(t,"finish"),await b(t),await S(t,{pane:null,tmux_session:null,window:null}),c=!0),{directive:{action:"shutdown"},closePane:c}}if(e.stopReason!=="stop"&&e.stopReason!=="length")return await b(t,{link:"daemon\u2192node"}),r.intent==="refresh"?{directive:H(e),closePane:!1}:e.stopReason==="error"&&e.faultSettled===!0&&(await he(t))?.retry.disposition==="fatal"&&await L(t)===null&&await W(t,n)?{directive:{action:"stay_resident"},closePane:!1}:{directive:{action:"stay_dormant"},closePane:!1};const i={pushedFinal:e.pushedFinal};if(i.pushedFinal||r.status==="done")return await b(t),await S(t,{pane:null,tmux_session:null,window:null}),{directive:{action:"shutdown"},closePane:!0};if(r.intent==="refresh")return await b(t),{directive:H(e),closePane:!1};const s=await ye(t,i);if(await b(t),s.action==="reprompt")return{directive:{action:"reprompt",prompt:s.message},closePane:!1};if(s.reason==="finished")return{directive:await T(t)?{action:"stay_dormant"}:{action:"shutdown"},closePane:!1};const o=await U(t,n);return(await P(t))?.runner==="blaxel"?{directive:await W(t,n)?{action:"stay_resident"}:{action:"stay_dormant"},closePane:!1}:s.reason!=="awaiting"&&s.reason!=="scheduled"?{directive:{action:"stay_dormant"},closePane:!1}:o?{directive:{action:"stay_dormant"},closePane:!1}:(await g(t,"release"),{directive:{action:"shutdown"},closePane:!1})}a(it,"settleBroker");async function rt(t){const e=t.params.id,n=Ke(t.body);await p(e,n.expected_execution_id);const r=await w(e);if(r.intent!=="refresh")throw new Ge(409,"not_yielding",`${e} has no pending yield`);const i=await P(e),s=Le(r);return n.brokerVersion===M()&&(i.release===null||i.release===M())&&Ve(i.launchJson,await De(e,s,r.cwd))?{status:200,body:await ot(e,r,i.executionId,s.env)}:{status:200,body:{action:"restart"}}}a(rt,"handleCycle");async function ot(t,e,n,r){e.cycles=(e.cycles??0)+1,await ue(t,n);const i=await je(e,n),s=await $e(e,i);await Ue(t),await We(t,e,!1),await He(t),await b(t,{preserveEpisode:!0}),await X(t,new Date().toISOString()),await k(t,{cycles:e.cycles,cycle_pending:!0});const o={};for(const c of Me)r[c]!==void 0&&(o[c]=r[c]);return o.CRTR_CYCLES=String(e.cycles),{action:"cycle",cycle:e.cycles,prompt:s,origin:Je({type:"runtime",kind:"revive",cycle:e.cycles}),messageIds:e.run_id?i.unreadMessageIds??[]:[],env:o,...e.launch?.model!==void 0?{model:e.launch.model}:{},modelExact:e.launch?.modelExact===!0,editorLabel:R(e)}}a(ot,"startCycleRecord");async function at(t){const e=t.params.id,n=f(t.body,"broker idle");return await p(e,n.expected_execution_id),await ne(n.expected_execution_id),{status:204}}a(at,"handleIdle");async function st(t){const e=t.params.id,n=Ye(t.body);await p(e,n.expected_execution_id);const r=await C(e),{directive:i,closePane:s}=await m(async()=>await it(e,n,await B(r)));return s&&await N(e),i.action!=="reprompt"&&ke(e).catch(o=>D({level:"error",event:"api.broker_ops.companion_submit_failed",node_id:e,error:o})),{status:200,body:i}}a(st,"handleSettle");async function ct(t){const e=t.params.id,n=ze(t.body);await p(e,n.expected_execution_id);const r=await C(e),i=await m(async()=>{const s=await ge(e);if(s===void 0)return{action:"stay_dormant"};const o=await w(e);return await xe(e,o,s,await B(r))?(await b(e),await g(e,"park"),await S(e,{pane:null,tmux_session:null,window:null}),D({level:n.outcome==="completed"?"info":"warn",event:"broker.park.complete",...se(e)?{node_id:e}:{},outcome:n.outcome==="completed"?"succeeded":"failed"}),{action:"shutdown"}):{action:"stay_dormant"}});return i.action==="shutdown"&&await N(e),{status:200,body:i}}a(ct,"handleParkComplete");async function dt(t){const e=t.params.id;return await p(e,f(t.body,"broker park-activity").expected_execution_id),{status:200,body:await m(async()=>({activity:await ve(e)?"recorded":"none"}))}}a(dt,"handleParkActivity");async function lt(t){const e=t.params.id,n=Ie(t.body);return await p(e,n.expected_execution_id),await m(async()=>{await te(e,{tokensIn:n.tokens_in,contextTokens:n.context_tokens,lastActivity:n.last_activity,updatedAt:n.updated_at}),Ce(e,n)}),{status:204}}a(lt,"handleTelemetry");async function ut(t){const e=t.params.id,n=Qe(t.body);return await p(e,n.expected_execution_id),{status:200,body:{modelOverride:(await m(async()=>await _e(await w(e),n.spec,n.intent,n.userSelected))).model_override}}}a(ut,"handleModelCommit");let J=!0;function cn(t){J=t}a(cn,"setRequestsStartRunObservers");async function pt(t){const e=t.params.id,n=await w(e);return n.run_id&&J&&await Te(e,n.run_id),{status:200,body:await $(e)}}a(pt,"handleExtensionState");async function ft(t){const e=t.params.id,n=Xe(t.body);return await p(e,n.expected_execution_id),{status:200,body:await m(async i=>{await i.prepareUncached("SELECT 1 FROM nodes WHERE node_id = ? FOR UPDATE").get(e);const s=await w(e);if(n.kind==="initial"){if((s.description??"").trim()!=="")return{applied:!1};const d=await k(e,{description:n.description,...n.title.trim()===""?{}:{title:n.title},...n.icon.trim()===""?{}:{icon:n.icon}});return{applied:!0,editorLabel:R(d),description:d.description??"",title:d.title??"",icon:d.icon??""}}const o=n.expected;if(s.name!==o.name||(s.description??"")!==o.description||(s.title??"")!==o.title||(s.icon??"")!==o.icon||s.kind!==o.kind)return{applied:!1};const c=await k(e,{description:n.description,title:n.title.trim()===""?void 0:n.title,icon:n.icon.trim()===""?void 0:n.icon});return{applied:!0,editorLabel:R(c),description:c.description??"",title:c.title??"",icon:c.icon??""}})}}a(ft,"handleGeneratedName");async function mt(t){const e=t.params.id,n=Ze(t.body);return await p(e,n.expected_execution_id),{status:200,body:{applied:await G(e,n.from,n.to)}}}a(mt,"handlePersonaAck");async function G(t,e,n){return await m(async r=>{await r.prepareUncached("SELECT 1 FROM nodes WHERE node_id = ? FOR UPDATE").get(t);const i=await w(t),s={kind:i.kind,mode:i.mode,lifecycle:i.lifecycle},o=i.persona_ack,c=o===void 0?s:{kind:o.kind??i.kind,mode:o.mode,lifecycle:o.lifecycle};return!A(s,n)||!A(c,e)?!1:(await k(t,{persona_ack:n}),!0)})}a(G,"applyPersonaAck");const dn=Se([{method:"POST",pattern:"/v1/nodes/:id/broker/session-bound",handler:qe},{method:"POST",pattern:"/v1/nodes/:id/broker/cycle-start",handler:nt},{method:"POST",pattern:"/v1/nodes/:id/broker/settle",handler:st},{method:"POST",pattern:"/v1/nodes/:id/broker/cycle",handler:rt},{method:"POST",pattern:"/v1/nodes/:id/broker/idle",handler:at},{method:"POST",pattern:"/v1/nodes/:id/broker/park-complete",handler:ct},{method:"POST",pattern:"/v1/nodes/:id/broker/park-activity",handler:dt},{method:"POST",pattern:"/v1/nodes/:id/broker/telemetry",handler:lt},{method:"POST",pattern:"/v1/nodes/:id/broker/model",handler:ut},{method:"GET",pattern:"/v1/nodes/:id/broker/extension-state",handler:pt},{method:"POST",pattern:"/v1/nodes/:id/broker/generated-name",handler:ft},{method:"POST",pattern:"/v1/nodes/:id/broker/persona-ack",handler:mt}]);export{dn as brokerOperationRoutes,v as extensionNode,cn as setRequestsStartRunObservers};
@@ -1 +1 @@
1
- var _=Object.defineProperty;var c=(e,t)=>_(e,"name",{value:t,configurable:!0});import{ApiError as n}from"../../../api/errors.js";import{openDb as j,withCanvasWrite as f}from"../../../core/canvas/db.js";import{readerForNode as l,warmNodeRepos as k}from"../../../core/graph/reader.js";import{noteNodeBooting as A}from"../../../core/graph/repo-sync/index.js";import{checkoutsForCwd as h,warmCheckoutIdentities as N}from"../../../core/graph/repo-sync/repos.js";import{DRY_RUN_ONLY as q,deliver as C,hypotheticalFrom as R,hypotheticalReader as D,inspect as p}from"../../../core/substrate/delivery/deliver.js";import{actsAsPerson as I}from"../router.js";import{requireCurrentExecution as w}from"./broker-recovery.js";const O=["boot","system-prompt","compact","persona","file-read","command","pre-command","slash-command","names",...q];function m(e){if(typeof e!="object"||e===null||Array.isArray(e))throw new n(400,"usage","delivery requires a JSON body");const t=e;if(!O.includes(t.activity))throw new n(400,"usage",`invalid delivery activity: ${String(t.activity)}`);if(t.subject!==void 0&&typeof t.subject!="string")throw new n(400,"usage","delivery subject must be a string");return t}c(m,"parse");function b(e){if(!I(e.principal)&&e.principal.class!=="broker")throw new n(403,"permission_error","a delivery dry run is available to a person or a node only")}c(b,"requirePerson");function S(e){if(typeof e!="object"||e===null||Array.isArray(e))throw new n(400,"usage","hypothetical must be an object");const t=c((o,s)=>{if(o!==void 0){if(typeof o!="string"||o==="")throw new n(400,"usage",`hypothetical.${s} must be a non-empty string`);return o}},"str"),i=t(e.cwd,"cwd");if(i!==void 0&&!i.startsWith("/"))throw new n(400,"usage","hypothetical.cwd must be an absolute path");if(e.mode!==void 0&&e.mode!=="base"&&e.mode!=="orchestrator")throw new n(400,"usage","hypothetical.mode must be base or orchestrator");if(e.lifecycle!==void 0&&e.lifecycle!=="terminal"&&e.lifecycle!=="resident")throw new n(400,"usage","hypothetical.lifecycle must be terminal or resident");if(e.has_manager!==void 0&&typeof e.has_manager!="boolean")throw new n(400,"usage","hypothetical.has_manager must be a boolean");if(e.depth!==void 0&&(!Number.isInteger(e.depth)||e.depth<0))throw new n(400,"usage","hypothetical.depth must be a non-negative integer");const r={};i!==void 0&&(r.cwd=i),e.profile!==void 0&&(r.profile=e.profile===null?null:t(e.profile,"profile"));const u=t(e.grantee,"grantee");u!==void 0&&(r.grantee=u);const a=t(e.kind,"kind");return a!==void 0&&(r.kind=a),e.mode!==void 0&&(r.mode=e.mode),e.lifecycle!==void 0&&(r.lifecycle=e.lifecycle),e.has_manager!==void 0&&(r.hasManager=e.has_manager),e.depth!==void 0&&(r.depth=e.depth),r}c(S,"hypotheticalOf");async function y(e,t){e!==void 0&&await k(await j(),e),t&&await N(t)}c(y,"warmDeliveryCwds");async function P(e){b(e);const t=m(e.body);if(t.node!==void 0&&typeof t.node!="string")throw new n(400,"usage","node must be a node id");const i={activity:t.activity,...t.subject!==void 0?{subject:t.subject}:{}};await y(t.node,t.hypothetical?.cwd);const{result:r,plan:u}=await f(async a=>{if(t.hypothetical===void 0){if(t.node===void 0)throw new n(400,"usage","a delivery dry run names a node, a hypothetical node, or both");return await p(a,await l(a,t.node,async v=>await h(a,v)),i,t.subject_override)}const o=S(t.hypothetical),s=t.node!==void 0?await R(t.node,o):{...o,cwd:o.cwd??""};if(s.cwd==="")throw new n(400,"usage","a hypothetical node needs a cwd");const{reader:d,subject:g}=await D(a,s);return await p(a,d,i,t.subject_override,g)},{rollback:!0});return{status:200,body:{...r,plan:u}}}c(P,"handleDryRun");async function T(e){const t=e.params.id,i=m(e.body),r={activity:i.activity,...i.subject!==void 0?{subject:i.subject}:{},...i.inherited===!0?{inherited:!0}:{}};if(i.dry_run===!0){b(e),await y(t);const{result:a,plan:o}=await f(async s=>await p(s,await l(s,t,async d=>await h(s,d)),r,i.subject_override),{rollback:!0});return{status:200,body:{...a,plan:o}}}if(e.principal.class==="broker"&&e.principal.node!==t)throw new n(403,"permission_error","delivery is performed by the node's own broker");return await w(t,i.expected_execution_id),i.activity==="boot"&&(await A(t),await w(t,i.expected_execution_id)),await y(t),{status:200,body:await f(async a=>await C(a,await l(a,t,async o=>await h(a,o)),r))}}c(T,"handleDelivery");const U=[{method:"POST",pattern:"/v1/nodes/:id/delivery",handler:T},{method:"POST",pattern:"/v1/delivery/dry-run",handler:P}];export{U as deliveryRoutes};
1
+ var _=Object.defineProperty;var c=(e,i)=>_(e,"name",{value:i,configurable:!0});import{ApiError as r}from"../../../api/errors.js";import{dirname as k}from"node:path";import{openDb as A,withCanvasWrite as l}from"../../../core/canvas/db.js";import{readerForNode as h,warmNodeDirs as m,warmNodeRepos as N}from"../../../core/graph/reader.js";import{checkoutsForCwd as p}from"../../../core/graph/repo-sync/repos.js";import{DRY_RUN_ONLY as q,deliver as D,hypotheticalFrom as R,hypotheticalReader as C,inspect as y}from"../../../core/substrate/delivery/deliver.js";import{actsAsPerson as O}from"../router.js";import{requireCurrentExecution as S}from"./broker-recovery.js";const P=["boot","system-prompt","compact","persona","file-read","command","pre-command","slash-command","names",...q];function b(e){if(typeof e!="object"||e===null||Array.isArray(e))throw new r(400,"usage","delivery requires a JSON body");const i=e;if(!P.includes(i.activity))throw new r(400,"usage",`invalid delivery activity: ${String(i.activity)}`);if(i.subject!==void 0&&typeof i.subject!="string")throw new r(400,"usage","delivery subject must be a string");return i}c(b,"parse");function g(e){if(!O(e.principal)&&e.principal.class!=="broker")throw new r(403,"permission_error","a delivery dry run is available to a person or a node only")}c(g,"requirePerson");function T(e){if(typeof e!="object"||e===null||Array.isArray(e))throw new r(400,"usage","hypothetical must be an object");const i=c((o,s)=>{if(o!==void 0){if(typeof o!="string"||o==="")throw new r(400,"usage",`hypothetical.${s} must be a non-empty string`);return o}},"str"),n=i(e.cwd,"cwd");if(n!==void 0&&!n.startsWith("/"))throw new r(400,"usage","hypothetical.cwd must be an absolute path");if(e.mode!==void 0&&e.mode!=="base"&&e.mode!=="orchestrator")throw new r(400,"usage","hypothetical.mode must be base or orchestrator");if(e.lifecycle!==void 0&&e.lifecycle!=="terminal"&&e.lifecycle!=="resident")throw new r(400,"usage","hypothetical.lifecycle must be terminal or resident");if(e.has_manager!==void 0&&typeof e.has_manager!="boolean")throw new r(400,"usage","hypothetical.has_manager must be a boolean");if(e.depth!==void 0&&(!Number.isInteger(e.depth)||e.depth<0))throw new r(400,"usage","hypothetical.depth must be a non-negative integer");const t={};n!==void 0&&(t.cwd=n),e.profile!==void 0&&(t.profile=e.profile===null?null:i(e.profile,"profile"));const d=i(e.grantee,"grantee");d!==void 0&&(t.grantee=d);const a=i(e.kind,"kind");return a!==void 0&&(t.kind=a),e.mode!==void 0&&(t.mode=e.mode),e.lifecycle!==void 0&&(t.lifecycle=e.lifecycle),e.has_manager!==void 0&&(t.hasManager=e.has_manager),e.depth!==void 0&&(t.depth=e.depth),t}c(T,"hypotheticalOf");async function w(e,i,n){const t=await A();e!==void 0&&await N(t,e),i&&await m(t,e,[i]),n!==void 0&&n.startsWith("/")&&await m(t,e,[k(n)])}c(w,"warmDeliveryCwds");async function E(e){g(e);const i=b(e.body);if(i.node!==void 0&&typeof i.node!="string")throw new r(400,"usage","node must be a node id");const n={activity:i.activity,...i.subject!==void 0?{subject:i.subject}:{}};await w(i.node,i.hypothetical?.cwd,i.activity==="file-read"?i.subject:void 0);const{result:t,plan:d}=await l(async a=>{if(i.hypothetical===void 0){if(i.node===void 0)throw new r(400,"usage","a delivery dry run names a node, a hypothetical node, or both");return await y(a,await h(a,i.node,async(v,j)=>await p(a,v,j)),n,i.subject_override)}const o=T(i.hypothetical),s=i.node!==void 0?await R(i.node,o):{...o,cwd:o.cwd??""};if(s.cwd==="")throw new r(400,"usage","a hypothetical node needs a cwd");const{reader:u,subject:f}=await C(a,s);return await y(a,u,n,i.subject_override,f)},{rollback:!0});return{status:200,body:{...t,plan:d}}}c(E,"handleDryRun");async function F(e){const i=e.params.id,n=b(e.body),t={activity:n.activity,...n.subject!==void 0?{subject:n.subject}:{},...n.inherited===!0?{inherited:!0}:{}};if(n.dry_run===!0){g(e),await w(i,void 0,n.activity==="file-read"?n.subject:void 0);const{result:a,plan:o}=await l(async s=>await y(s,await h(s,i,async(u,f)=>await p(s,u,f)),t,n.subject_override),{rollback:!0});return{status:200,body:{...a,plan:o}}}if(e.principal.class==="broker"&&e.principal.node!==i)throw new r(403,"permission_error","delivery is performed by the node's own broker");return await S(i,n.expected_execution_id),await w(i,void 0,n.activity==="file-read"?n.subject:void 0),{status:200,body:await l(async a=>await D(a,await h(a,i,async(o,s)=>await p(a,o,s)),t))}}c(F,"handleDelivery");const z=[{method:"POST",pattern:"/v1/nodes/:id/delivery",handler:F},{method:"POST",pattern:"/v1/delivery/dry-run",handler:E}];export{z as deliveryRoutes};
@@ -1,16 +1,5 @@
1
1
  import { type CanvasDb } from '../../../core/canvas/db.js';
2
- import type { ObjectRow, Reader } from '../../../core/graph/types.js';
2
+ import type { ObjectRow } from '../../../core/graph/types.js';
3
3
  import type { RouteTable } from '../router.js';
4
4
  export declare function canonicalName(db: CanvasDb, o: ObjectRow): Promise<string>;
5
- /** A committed change to a repo-owned document starts that repo's sync. */
6
- export interface RepoChange {
7
- repos: ObjectRow[];
8
- dirs: string[];
9
- }
10
- /** The repos among `owners` and the directories that may hold a checkout of them (the caller's cwd,
11
- * a node's own else the request's, and the checkouts its view reaches), captured inside the write
12
- * transaction and acted on after it commits. */
13
- export declare function repoChange(db: CanvasDb, reader: Reader, owners: ObjectRow[], requestCwd?: string): Promise<RepoChange>;
14
- /** The change is committed; a sync that cannot start is reported as an event, never as a failed write. */
15
- export declare function syncChanged(change: RepoChange): Promise<void>;
16
5
  export declare const docRoutes: RouteTable;
@@ -1,3 +1,3 @@
1
- var de=Object.defineProperty;var u=(n,e)=>de(n,"name",{value:e,configurable:!0});import{ApiError as A}from"../../../api/errors.js";import{DOC_KINDS as V,DOC_UNSET_FIELDS as x}from"../../../api/dto/docs.js";import{PRIVACY_LEVELS_DTO as G}from"../../../api/dto/objects.js";import{openDb as ue,withCanvasWrite as O}from"../../../core/canvas/db.js";import{CrtrError as fe}from"../../../core/errors.js";import{emitEvent as le}from"../../../core/events/emit.js";import{canChange as me,spaceOf as pe}from"../../../core/graph/access.js";import{get as K,getMany as X}from"../../../core/graph/bodies.js";import{deleteDocument as he,documentRecord as C,editDocument as we,heads as H,history as ye,linksIn as z,moveDocument as ge,readBase as _e,setDocumentRecord as ve,withCurrentNames as be,writeDocument as Ee}from"../../../core/graph/documents.js";import{resolveName as J}from"../../../core/graph/names.js";import{getById as T}from"../../../core/graph/objects.js";import{noteRepoDocumentsChanged as ke}from"../../../core/graph/repo-sync/index.js";import{checkoutsForCwd as Ae}from"../../../core/graph/repo-sync/repos.js";import{lintRules as Oe,rulesOf as Y}from"../../../core/graph/rules.js";import{unifiedDiff as $e}from"../../../core/graph/diff.js";import{ownerForGrantee as je}from"../../../core/graph/objects.js";import{stubOf as Re}from"../../../core/peer/stubs.js";import{forwarding as De}from"../../peer/forward.js";import{resolvedLocally as Ne}from"./objects.js";import{ownerFromFlag as q,readerFor as $,resolveRef as Z,warmReaderRepos as j}from"../reader.js";import{appCaller as Q,asApiError as Se,requireOwnNamespace as Ce}from"./schemas.js";import{filterAsync as Te,flatMapAsync as Ie}from"../../../core/async-array.js";function y(n,e,t,o,a={}){return new A(n,e,t,{...a,error:e,message:t,next:o})}u(y,"refuse");const k=u((n,e)=>new A(400,"invalid_request",n,e),"invalid");function I(n){const e=n.body;if(e===void 0)return{};if(typeof e!="object"||e===null||Array.isArray(e))throw k("the request body must be a JSON object");return e}u(I,"bodyOf");const F=u(async n=>async e=>await Ae(n,e),"reposFnFor");function L(n,e){if(n instanceof fe){const t=n.details;if(n.code==="read_first")throw y(409,"read_first",n.message,`Read it first with \`crtr canvas read ${e?.id??"<ref>"}\`, then rerun the edit.`,t??{});if(n.code==="conflict")throw new A(409,"name_taken",n.message,t);if(n.code==="forbidden")throw typeof t?.next=="string"?y(403,"forbidden",n.message,t.next,t):new A(403,"forbidden",n.message,t);if(n.code==="scope_missing")throw y(403,"scope_missing",n.message,`Launch the run with \`${String(t?.scope)}\` in its scopes list.`,t??{});if(t?.rule==="repo-public-only")throw y(422,"repo_documents_are_public",n.message,'Own it as `user` and add a rule with `if: {"repo": "<handle>"}` so it loads only in that repo.')}throw Se(n)}u(L,"mapGraphError");async function P(n,e,t){const o=await Z(n,e,decodeURIComponent(t));if("remote"in o)throw y(404,"not_found",te(o.remote),"Check the name with `crtr canvas search`.");if("deleted"in o)throw new A(404,"not_found",`${o.deleted.name} is deleted`,{id:o.deleted.id,deleted:!0});if(o.type!=="document")throw k(`${t} is a ${o.type}, not a document`);return o}u(P,"refDocument");async function ee(n){const{stub:e}=await Ne(decodeURIComponent(n.params.ref),n);if(e===null)return;const t=await Re(await ue(),e);if(t.object.type!=="document")return;const o=await De.current.label(t.home_machine);throw y(404,"not_here",`this document lives on runtime ${o.name}; edit it (or read its history) from a node there`,`Run the command from a node on ${o.name}.`,{id:t.object.id,home_machine:o.id})}u(ee,"refuseRemoteDocument");function te(n){return`no object named ${n} on this runtime; it may be on another runtime, or the name may be misspelled`}u(te,"remoteMessage");async function Fe(n,e){const t=e.owner===null?null:await T(n,e.owner);return t?t.type==="node"?t.id:t.name:""}u(Fe,"ownerHandle");async function N(n,e){const t=await Fe(n,e);return t?`${t}/${e.name}`:e.name}u(N,"canonicalName");async function Le(n,e){const t=e.owner===null?null:await T(n,e.owner),o=t?{id:t.id,type:t.type,handle:t.type==="node"?t.id:t.name}:null;return{id:e.id,type:e.type,kind:e.kind,owner:o,privacy:e.privacy,name:e.name,preview:e.preview??"",created_at:e.created_at,deleted_at:e.deleted_at,...e.type==="document"?{schema_type:e.schema_type??null}:{}}}u(Le,"objectDTO");async function Me(n,e){const t=e.owner===null?null:await T(n,e.owner);return t?.type==="repo"?t:null}u(Me,"repoOwner");async function M(n,e,t,o){const a=[...new Map(await Ie(t,async f=>{const r=await Me(n,f);return r?[[r.id,r]]:[]})).values()],c=e.class==="node"?e.cwd:o,s=e.class==="node"?[...e.checkouts,...e.projectCheckouts].map(f=>f.root):[];return{repos:a,dirs:[...new Set([...c!==void 0?[c]:[],...s])]}}u(M,"repoChange");async function W(n){for(const e of n.repos)try{await ke(e,n.dirs)}catch(t){le({level:"warn",event:"repo_sync.failed",outcome:"failed",error:t,fields:{repo:e.name,step:"export",reason:t instanceof Error?t.message:String(t)}})}}u(W,"syncChanged");const ne=/^[A-Za-z0-9_-]+(\/[A-Za-z0-9_-]+)*$/;function We(n,e){if(n===void 0)return;if(!Array.isArray(n)){e.push("`rules` must be a list");return}const t=n.map(a=>{if(typeof a!="object"||a===null||Array.isArray(a))return a;const{match_frontmatter:c,...s}=a;return"matchFrontmatter"in s?{...s,match_frontmatter:s.matchFrontmatter}:c===void 0?s:{...s,matchFrontmatter:c}}),o=Oe(t);if(o){e.push(o.replaceAll("matchFrontmatter","match_frontmatter"));return}return t}u(We,"rulesFromDTO");function oe(n,e){const t={},o=u(r=>{const d=n[r];if(d!==void 0){if(typeof d!="string"){e.push(`\`${r}\` must be a string`);return}return d}},"str"),a=o("preview");a!==void 0&&(a.trim()===""||/[\r\n]/.test(a)?e.push("`preview` must be one non-empty line"):t.preview=a);const c=o("summary");c!==void 0&&(t.summary=c);const s=o("why_it_exists");if(s!==void 0&&(t.whyItExists=s),n.privacy!==void 0&&(G.includes(n.privacy)?t.privacy=n.privacy:e.push(`\`privacy\` must be one of ${G.join(", ")}`)),n.unlisted!==void 0&&(typeof n.unlisted!="boolean"?e.push("`unlisted` must be a boolean"):t.unlisted=n.unlisted),n.lint_ignore!==void 0){const r=n.lint_ignore;!Array.isArray(r)||r.some(d=>typeof d!="string")?e.push("`lint_ignore` must be a list of strings"):t.lintIgnore=r}if(n.extensions!==void 0){const r=n.extensions;typeof r!="object"||r===null||Array.isArray(r)||Object.values(r).some(d=>typeof d!="object"||d===null||Array.isArray(d))?e.push("`extensions` must map each plugin to an object of fields"):t.extensions=r}const f=We(n.rules,e);return f!==void 0&&(t.rules=f),t}u(oe,"fieldsFrom");function ie(n){if(n.length>0)throw k(n.join("; "),{errors:n})}u(ie,"failOn");async function re(n,e,t,o){const a=await Te(z(t),async c=>"remote"in await J(n,e,c));return{...o.length>0?{unresolved_links:o}:{},...a.length>0?{remote_links:a}:{}}}u(re,"linkReport");async function B(n,e,t){if(t?.includes("unreached")||e.schema_type!=null||e.owner===null)return!1;const o=await T(n,e.owner);return!o||o.type==="node"||(await Y(n,e)).length>0?!1:await n.prepare(`SELECT 1 FROM edges e JOIN objects s ON s.id = e.src
1
+ var ae=Object.defineProperty;var u=(n,e)=>ae(n,"name",{value:e,configurable:!0});import{ApiError as E}from"../../../api/errors.js";import{DOC_KINDS as H,DOC_UNSET_FIELDS as q}from"../../../api/dto/docs.js";import{PRIVACY_LEVELS_DTO as P}from"../../../api/dto/objects.js";import{openDb as se,withCanvasWrite as k}from"../../../core/canvas/db.js";import{CrtrError as ce}from"../../../core/errors.js";import{canChange as de,spaceOf as ue}from"../../../core/graph/access.js";import{get as U,getMany as V}from"../../../core/graph/bodies.js";import{deleteDocument as fe,documentRecord as N,editDocument as le,heads as L,history as me,linksIn as G,moveDocument as pe,readBase as he,setDocumentRecord as we,withCurrentNames as ye,writeDocument as ge}from"../../../core/graph/documents.js";import{resolveName as K}from"../../../core/graph/names.js";import{getById as M}from"../../../core/graph/objects.js";import{checkoutsForCwd as _e}from"../../../core/graph/repo-sync/repos.js";import{lintRules as ve,rulesOf as X}from"../../../core/graph/rules.js";import{unifiedDiff as be}from"../../../core/graph/diff.js";import{ownerForGrantee as Ee}from"../../../core/graph/objects.js";import{stubOf as ke}from"../../../core/peer/stubs.js";import{forwarding as Ae}from"../../peer/forward.js";import{resolvedLocally as Oe}from"./objects.js";import{ownerFromFlag as W,readerFor as A,resolveRef as z,warmReaderRepos as O}from"../reader.js";import{appCaller as J,asApiError as $e,requireOwnNamespace as je}from"./schemas.js";import{filterAsync as Re}from"../../../core/async-array.js";function y(n,e,t,o,r={}){return new E(n,e,t,{...r,error:e,message:t,next:o})}u(y,"refuse");const b=u((n,e)=>new E(400,"invalid_request",n,e),"invalid");function S(n){const e=n.body;if(e===void 0)return{};if(typeof e!="object"||e===null||Array.isArray(e))throw b("the request body must be a JSON object");return e}u(S,"bodyOf");const T=u(async n=>async(e,t)=>await _e(n,e,t),"reposFnFor");function I(n,e){if(n instanceof ce){const t=n.details;if(n.code==="read_first")throw y(409,"read_first",n.message,`Read it first with \`crtr canvas read ${e?.id??"<ref>"}\`, then rerun the edit.`,t??{});if(n.code==="conflict")throw new E(409,"name_taken",n.message,t);if(n.code==="forbidden")throw typeof t?.next=="string"?y(403,"forbidden",n.message,t.next,t):new E(403,"forbidden",n.message,t);if(n.code==="scope_missing")throw y(403,"scope_missing",n.message,`Launch the run with \`${String(t?.scope)}\` in its scopes list.`,t??{});if(t?.rule==="repo-public-only")throw y(422,"repo_documents_are_public",n.message,'Own it as `user` and add a rule with `if: {"repo": "<handle>"}` so it loads only in that repo.')}throw $e(n)}u(I,"mapGraphError");async function B(n,e,t){const o=await z(n,e,decodeURIComponent(t));if("remote"in o)throw y(404,"not_found",Z(o.remote),"Check the name with `crtr canvas search`.");if("deleted"in o)throw new E(404,"not_found",`${o.deleted.name} is deleted`,{id:o.deleted.id,deleted:!0});if(o.type!=="document")throw b(`${t} is a ${o.type}, not a document`);return o}u(B,"refDocument");async function Y(n){const{stub:e}=await Oe(decodeURIComponent(n.params.ref),n);if(e===null)return;const t=await ke(await se(),e);if(t.object.type!=="document")return;const o=await Ae.current.label(t.home_machine);throw y(404,"not_here",`this document lives on runtime ${o.name}; edit it (or read its history) from a node there`,`Run the command from a node on ${o.name}.`,{id:t.object.id,home_machine:o.id})}u(Y,"refuseRemoteDocument");function Z(n){return`no object named ${n} on this runtime; it may be on another runtime, or the name may be misspelled`}u(Z,"remoteMessage");async function De(n,e){const t=e.owner===null?null:await M(n,e.owner);return t?t.type==="node"?t.id:t.name:""}u(De,"ownerHandle");async function R(n,e){const t=await De(n,e);return t?`${t}/${e.name}`:e.name}u(R,"canonicalName");async function Ne(n,e){const t=e.owner===null?null:await M(n,e.owner),o=t?{id:t.id,type:t.type,handle:t.type==="node"?t.id:t.name}:null;return{id:e.id,type:e.type,kind:e.kind,owner:o,privacy:e.privacy,name:e.name,preview:e.preview??"",created_at:e.created_at,deleted_at:e.deleted_at,...e.type==="document"?{schema_type:e.schema_type??null}:{}}}u(Ne,"objectDTO");const x=/^[A-Za-z0-9_-]+(\/[A-Za-z0-9_-]+)*$/;function Se(n,e){if(n===void 0)return;if(!Array.isArray(n)){e.push("`rules` must be a list");return}const t=n.map(r=>{if(typeof r!="object"||r===null||Array.isArray(r))return r;const{match_frontmatter:c,...a}=r;return"matchFrontmatter"in a?{...a,match_frontmatter:a.matchFrontmatter}:c===void 0?a:{...a,matchFrontmatter:c}}),o=ve(t);if(o){e.push(o.replaceAll("matchFrontmatter","match_frontmatter"));return}return t}u(Se,"rulesFromDTO");function Q(n,e){const t={},o=u(s=>{const d=n[s];if(d!==void 0){if(typeof d!="string"){e.push(`\`${s}\` must be a string`);return}return d}},"str"),r=o("preview");r!==void 0&&(r.trim()===""||/[\r\n]/.test(r)?e.push("`preview` must be one non-empty line"):t.preview=r);const c=o("summary");c!==void 0&&(t.summary=c);const a=o("why_it_exists");if(a!==void 0&&(t.whyItExists=a),n.privacy!==void 0&&(P.includes(n.privacy)?t.privacy=n.privacy:e.push(`\`privacy\` must be one of ${P.join(", ")}`)),n.unlisted!==void 0&&(typeof n.unlisted!="boolean"?e.push("`unlisted` must be a boolean"):t.unlisted=n.unlisted),n.lint_ignore!==void 0){const s=n.lint_ignore;!Array.isArray(s)||s.some(d=>typeof d!="string")?e.push("`lint_ignore` must be a list of strings"):t.lintIgnore=s}if(n.extensions!==void 0){const s=n.extensions;typeof s!="object"||s===null||Array.isArray(s)||Object.values(s).some(d=>typeof d!="object"||d===null||Array.isArray(d))?e.push("`extensions` must map each plugin to an object of fields"):t.extensions=s}const m=Se(n.rules,e);return m!==void 0&&(t.rules=m),t}u(Q,"fieldsFrom");function ee(n){if(n.length>0)throw b(n.join("; "),{errors:n})}u(ee,"failOn");async function te(n,e,t,o){const r=await Re(G(t),async c=>"remote"in await K(n,e,c));return{...o.length>0?{unresolved_links:o}:{},...r.length>0?{remote_links:r}:{}}}u(te,"linkReport");async function C(n,e,t){if(t?.includes("unreached")||e.schema_type!=null||e.owner===null)return!1;const o=await M(n,e.owner);return!o||o.type==="node"||(await X(n,e)).length>0?!1:await n.prepare(`SELECT 1 FROM edges e JOIN objects s ON s.id = e.src
2
2
  WHERE e.type = 'links-to' AND e.dst = ? AND e.src != e.dst AND s.deleted_at IS NULL
3
- AND EXISTS (SELECT 1 FROM rules r WHERE r.object = s.id) LIMIT 1`).get(e.id)===void 0}u(B,"unreached");const Be="no rule delivers this document and no document with a rule links to it, so no agent will be routed to it; give it a rule, link it from a document that loads, or accept it with lint-ignore `unreached`";async function He(n){const e=I(n),t=[],o=e.name;(typeof o!="string"||!ne.test(o))&&t.push("`name` must be segments of letters, digits, `_` or `-` joined by `/`"),typeof e.body!="string"&&t.push("`body` must be a string"),typeof e.preview!="string"&&t.push("`preview` is required");const a=e.kind??"knowledge";V.includes(a)||t.push(a==="report"?"reports are written only by `crtr push`":`\`kind\` must be one of ${V.join(", ")}`);const c=oe(e,t);e.cwd!==void 0&&typeof e.cwd!="string"&&t.push("`cwd` must be a string");const s=e.schema_type;s!==void 0&&typeof s!="string"&&t.push("`schema_type` must be a string");const f=e.relations;f!==void 0&&(!Array.isArray(f)||f.some(i=>typeof i!="object"||i===null||typeof i.relation!="string"||typeof i.subject!="string"))&&t.push("`relations` must be a list of {relation, subject} strings"),ie(t);const r=e;await j(n.principal,r.cwd);const{dto:d,change:l}=await O(async i=>{const m=await $(i,n);r.schema_type!==void 0?await Ce(i,Q(n).app,r.schema_type):r.relations!==void 0&&Q(n);const p=r.owner==="user"&&m.class==="app"&&m.sub!==void 0?await je(i,m.sub.startsWith("user:")?m.sub:`user:${m.sub}`):await q(i,m,r.owner,r.cwd);try{const{object:w,unresolved:g}=await Ee(i,m,{...c,owner:p,name:r.name,kind:a,preview:c.preview,privacy:c.privacy??"public",...r.schema_type!==void 0?{schemaType:r.schema_type}:{},...r.relations!==void 0?{relations:r.relations}:{}},r.body,await F(i));return{dto:{id:w.id,name:await N(i,w),...await re(i,m,r.body,g),...await B(i,w,c.lintIgnore??null)?{unreached:!0}:{}},change:await M(i,m,[w],r.cwd)}}catch(w){L(w)}});return await W(l),d}u(He,"write");function qe(n,e){let t=n;e.forEach(({old:o,new:a},c)=>{const s=o===""?-1:t.indexOf(o);if(s<0)throw y(422,"replace_no_match",`replace[${c}]: old text not found in the revision you read`,"Copy the old text exactly from your last read and rerun.",{index:c});if(t.indexOf(o,s+1)>=0)throw y(422,"replace_ambiguous",`replace[${c}]: old text occurs more than once`,"Include more surrounding text so the old text matches once, and rerun.",{index:c});t=t.slice(0,s)+a+t.slice(s+o.length)})}u(qe,"checkReplacements");async function Pe(n){const e=I(n),t=[],o=e.body!==void 0,a=e.replace!==void 0;o&&a&&t.push("give `body` or `replace`, not both"),o&&typeof e.body!="string"&&t.push("`body` must be a string");const c=e.replace;a&&(!Array.isArray(c)||c.length===0||c.some(i=>typeof i!="object"||i===null||typeof i.old!="string"||typeof i.new!="string"))&&t.push("`replace` must be a non-empty list of {old, new} strings"),(typeof e.rationale!="string"||e.rationale.trim()==="")&&t.push("`rationale` is required"),e.verbatim!==void 0&&typeof e.verbatim!="boolean"&&t.push("`verbatim` must be a boolean"),e.base!==void 0&&(typeof e.base!="string"||e.base==="")&&t.push("`base` must be a non-empty heads key"),e.base!==void 0&&!o&&!a&&t.push("`base` applies only to a `body` or `replace` edit");const s=oe(e,t),f=e.unset??[];if(!Array.isArray(f)||f.some(i=>!x.includes(i)))t.push(`\`unset\` takes only ${x.join(", ")}`);else for(const i of f)i==="summary"&&(s.summary=null),i==="why_it_exists"&&(s.whyItExists=null),i==="unlisted"&&(s.unlisted=!1),i==="lint_ignore"&&(s.lintIgnore=null),i==="extensions"&&(s.extensions=null),i==="rules"&&(s.rules=[]);t.length===0&&!o&&!a&&Object.keys(s).length===0&&t.push("nothing to change: give `body`, `replace`, or a field"),ie(t);const r=e;await ee(n),await j(n.principal);const{dto:d,synced:l}=await O(async i=>{const m=await $(i,n),p=await P(i,m,n.params.ref),w=await N(i,p),g=await M(i,m,[p]);try{if(!o&&!a){await ve(i,m,p,s,r.rationale);const E=await C(i,p);return{dto:{id:p.id,name:w,revision:E.revision,...await B(i,p,E.lint_ignore)?{unreached:!0}:{}},synced:g}}const _=r.base??await _e(i,m,p);if(a&&_!==null){const E=await C(i,p),U=await H(i,p);E.source_path===null&&E.heads_key===_&&U.length===1&&qe(await be(i,p,await K(i,U[0].body_hash)),r.replace)}const D=r.verbatim===!0,S=o?{body:r.body,verbatim:D}:{replace:r.replace,verbatim:D},v=await we(i,m,p,S,r.rationale,_,s,await F(i));if("stale"in v)throw y(409,"stale_revision",`${w} changed after your read; it is now at revision ${v.stale.revision}`,`Read it again with \`crtr canvas read ${w}\`, then redo your change on the current text.`,{stale:v.stale});const h=await K(i,(await H(i,p))[0].body_hash),b=await C(i,p);return{dto:{id:p.id,name:w,revision:v.revision,...await re(i,m,h,v.unresolved),...await B(i,p,b.lint_ignore)?{unreached:!0}:{}},synced:g}}catch(_){L(_,p)}});return await W(l),d}u(Pe,"edit");async function Ue(n){const e=I(n);if(e.new_name===void 0&&e.owner===void 0)throw k("give a new name, an owner, or both");if(e.new_name!==void 0&&(typeof e.new_name!="string"||!ne.test(e.new_name)))throw k("`new_name` must be segments of letters, digits, `_` or `-` joined by `/`");await j(n.principal,e.cwd);const{dto:t,change:o}=await O(async a=>{const c=await $(a,n),s=await P(a,c,n.params.ref),f=e.owner===void 0?void 0:await q(a,c,e.owner,e.cwd);try{const r=await ge(a,c,s,{...e.new_name!==void 0?{name:e.new_name}:{},...f?{owner:f}:{}},await F(a));return{dto:{id:r.id,name:await N(a,r)},change:await M(a,c,[s,r],e.cwd)}}catch(r){L(r,s)}});return await W(o),t}u(Ue,"move");async function Ve(n){await j(n.principal);const{dto:e,change:t}=await O(async o=>{const a=await $(o,n),c=await P(o,a,n.params.ref),s=await N(o,c),f=await M(o,a,[c]);try{await he(o,a,c,await F(o))}catch(r){L(r,c)}return{dto:{id:c.id,name:s},change:f}});return await W(t),e}u(Ve,"remove");async function xe(n){const e=n.query.get("diff"),t=e===null?void 0:Number(e);if(t!==void 0&&!(Number.isInteger(t)&&t>0))throw k("`diff` must be a revision number");return await ee(n),await j(n.principal),await O(async o=>{const a=await $(o,n),c=await Z(o,a,decodeURIComponent(n.params.ref));if("remote"in c)throw y(404,"not_found",te(c.remote),"Check the name with `crtr canvas search`.");const s="deleted"in c?c.deleted:c;if(s.type!=="document")throw k(`${s.name} is a ${s.type}, not a document`);const f=await ye(o,a,s),r={object:await Le(o,s),revisions:f.map(d=>({rev_id:d.rev_id,number:d.number,author_id:d.author,rationale:d.rationale,verbatim:d.verbatim,created_at:d.created_at,parents:d.parents,acting_app:d.acting_app,acting_for:d.acting_for}))};if(t!==void 0){const d=f.find(m=>m.number===t);if(!d)throw new A(404,"not_found",`${s.name} has no revision ${t}`);const l=d.parents[0]===void 0?void 0:f.find(m=>m.rev_id===d.parents[0]),i=await X(o,l?[l.body_hash,d.body_hash]:[d.body_hash]);r.diff=$e(l?i.get(l.body_hash):"",i.get(d.body_hash))}return r})}u(xe,"revisionHistory");const ae=1e3,se=1e3,ce=3e3,Ge=/^When\b.+\bbecause\b.+/,Ke=u(n=>{const e=n.trim();return e===""?0:e.split(/\s+/).length},"words");function Xe(n,e){if(n.some(o=>o.on==="boot"&&o.deliver==="content")&&e>ae)return`body is ${e} words, over the ${ae}-word cap for a boot rule at content (the whole body enters every node's context). Keep the core here and move separate subjects into [[linked]] documents.`;const t=[...new Set(n.filter(o=>o.on!=="boot"&&o.deliver==="content").map(o=>o.on))];return t.length>0&&e>se?`body is ${e} words, over the ${se}-word cap for a content rule on ${t.join("/")}. Keep the core here and move separate subjects into [[linked]] documents.`:n.some(o=>o.on==="boot"&&o.deliver==="preview")&&e>ce?`body is ${e} words, over the ${ce}-word cap for a boot rule at preview. Keep the core here and move separate subjects into [[linked]] documents.`:null}u(Xe,"lengthFinding");async function ze(n){const e=I(n);return await j(n.principal,e.cwd),await O(async t=>{const o=await $(t,n),a=e.owner===void 0?null:await q(t,o,e.owner,e.cwd),c=await t.prepare("SELECT * FROM objects WHERE type = 'document' AND deleted_at IS NULL AND home_machine IS NULL AND kind != 'report' ORDER BY name").all(),s=[],f=new Map,r=[];for(const l of c)a&&l.owner!==a.id||await me(t,o,l)&&r.push({doc:l,head:(await H(t,l))[0]});const d=await X(t,r.flatMap(l=>l.head?[l.head.body_hash]:[]));for(const{doc:l,head:i}of r){const m=await C(t,l),p=new Set(m.lint_ignore??[]),w=await N(t,l),g=u((h,b,E)=>{p.has(h)||s.push({name:w,severity:b,rule:h,message:E})},"add"),_=await Y(t,l),D=i?d.get(i.body_hash):"",S=Xe(_,Ke(D));S&&g("length","error",S),_.some(h=>h.deliver==="preview")&&!Ge.test(l.preview??"")&&g("preview-shape","error",`a rule delivers this document at preview, so the preview must read "When <situation in the reader's work>, read this because <what the reader gains>"`);const v=new Set((await t.prepare("SELECT written_as FROM edges WHERE type = 'links-to' AND src = ?").all(l.id)).map(h=>h.written_as));for(const h of z(D)){if(v.has(h))continue;const b=await J(t,o,h);"remote"in b||"object"in b||"deleted"in b||g("links","warning",`[[${h}]] names no object in your view`)}if(await B(t,l,m.lint_ignore)&&g("unreached","warning",Be),_.some(h=>h.on==="workspace-open"&&h.deliver==="content")){const h=await pe(t,l);h.type==="repo"&&!p.has("workspace-open")&&f.set(h.name,[...f.get(h.name)??[],w])}}for(const[l,i]of f)if(!(i.length<2))for(const m of i)s.push({name:m,severity:"warning",rule:"workspace-open",message:`repo ${l} has ${i.length} documents delivered at content on workspace-open (${i.join(", ")}); keep one and link the rest from it`});return{findings:s}})}u(ze,"lint");const R=u((n,e=200)=>async t=>({status:e,body:await n(t)}),"ok"),_t=[{method:"POST",pattern:"/v1/docs",handler:R(He,201)},{method:"PATCH",pattern:"/v1/docs/:ref",handler:R(Pe)},{method:"POST",pattern:"/v1/docs/:ref/move",handler:R(Ue)},{method:"DELETE",pattern:"/v1/docs/:ref",handler:R(Ve)},{method:"GET",pattern:"/v1/docs/:ref/history",handler:R(xe)},{method:"POST",pattern:"/v1/docs/lint",handler:R(ze)}];export{N as canonicalName,_t as docRoutes,M as repoChange,W as syncChanged};
3
+ AND EXISTS (SELECT 1 FROM rules r WHERE r.object = s.id) LIMIT 1`).get(e.id)===void 0}u(C,"unreached");const Te="no rule delivers this document and no document with a rule links to it, so no agent will be routed to it; give it a rule, link it from a document that loads, or accept it with lint-ignore `unreached`";async function Ie(n){const e=S(n),t=[],o=e.name;(typeof o!="string"||!x.test(o))&&t.push("`name` must be segments of letters, digits, `_` or `-` joined by `/`"),typeof e.body!="string"&&t.push("`body` must be a string"),typeof e.preview!="string"&&t.push("`preview` is required");const r=e.kind??"knowledge";H.includes(r)||t.push(r==="report"?"reports are written only by `crtr push`":`\`kind\` must be one of ${H.join(", ")}`);const c=Q(e,t);e.cwd!==void 0&&typeof e.cwd!="string"&&t.push("`cwd` must be a string");const a=e.schema_type;a!==void 0&&typeof a!="string"&&t.push("`schema_type` must be a string");const m=e.relations;m!==void 0&&(!Array.isArray(m)||m.some(i=>typeof i!="object"||i===null||typeof i.relation!="string"||typeof i.subject!="string"))&&t.push("`relations` must be a list of {relation, subject} strings"),ee(t);const s=e;return await O(n.principal,s.cwd),await k(async i=>{const l=await A(i,n);s.schema_type!==void 0?await je(i,J(n).app,s.schema_type):s.relations!==void 0&&J(n);const f=s.owner==="user"&&l.class==="app"&&l.sub!==void 0?await Ee(i,l.sub.startsWith("user:")?l.sub:`user:${l.sub}`):await W(i,l,s.owner,s.cwd);try{const{object:h,unresolved:w}=await ge(i,l,{...c,owner:f,name:s.name,kind:r,preview:c.preview,privacy:c.privacy??"public",...s.schema_type!==void 0?{schemaType:s.schema_type}:{},...s.relations!==void 0?{relations:s.relations}:{}},s.body,await T(i));return{id:h.id,name:await R(i,h),...await te(i,l,s.body,w),...await C(i,h,c.lintIgnore??null)?{unreached:!0}:{}}}catch(h){I(h)}})}u(Ie,"write");function Ce(n,e){let t=n;e.forEach(({old:o,new:r},c)=>{const a=o===""?-1:t.indexOf(o);if(a<0)throw y(422,"replace_no_match",`replace[${c}]: old text not found in the revision you read`,"Copy the old text exactly from your last read and rerun.",{index:c});if(t.indexOf(o,a+1)>=0)throw y(422,"replace_ambiguous",`replace[${c}]: old text occurs more than once`,"Include more surrounding text so the old text matches once, and rerun.",{index:c});t=t.slice(0,a)+r+t.slice(a+o.length)})}u(Ce,"checkReplacements");async function Fe(n){const e=S(n),t=[],o=e.body!==void 0,r=e.replace!==void 0;o&&r&&t.push("give `body` or `replace`, not both"),o&&typeof e.body!="string"&&t.push("`body` must be a string");const c=e.replace;r&&(!Array.isArray(c)||c.length===0||c.some(i=>typeof i!="object"||i===null||typeof i.old!="string"||typeof i.new!="string"))&&t.push("`replace` must be a non-empty list of {old, new} strings"),(typeof e.rationale!="string"||e.rationale.trim()==="")&&t.push("`rationale` is required"),e.verbatim!==void 0&&typeof e.verbatim!="boolean"&&t.push("`verbatim` must be a boolean"),e.base!==void 0&&(typeof e.base!="string"||e.base==="")&&t.push("`base` must be a non-empty heads key"),e.base!==void 0&&!o&&!r&&t.push("`base` applies only to a `body` or `replace` edit");const a=Q(e,t),m=e.unset??[];if(!Array.isArray(m)||m.some(i=>!q.includes(i)))t.push(`\`unset\` takes only ${q.join(", ")}`);else for(const i of m)i==="summary"&&(a.summary=null),i==="why_it_exists"&&(a.whyItExists=null),i==="unlisted"&&(a.unlisted=!1),i==="lint_ignore"&&(a.lintIgnore=null),i==="extensions"&&(a.extensions=null),i==="rules"&&(a.rules=[]);t.length===0&&!o&&!r&&Object.keys(a).length===0&&t.push("nothing to change: give `body`, `replace`, or a field"),ee(t);const s=e;return await Y(n),await O(n.principal),await k(async i=>{const l=await A(i,n),f=await B(i,l,n.params.ref),h=await R(i,f);try{if(!o&&!r){await we(i,l,f,a,s.rationale);const p=await N(i,f);return{id:f.id,name:h,revision:p.revision,...await C(i,f,p.lint_ignore)?{unreached:!0}:{}}}const w=s.base??await he(i,l,f);if(r&&w!==null){const p=await N(i,f),_=await L(i,f);p.source_path===null&&p.heads_key===w&&_.length===1&&Ce(await ye(i,f,await U(i,_[0].body_hash)),s.replace)}const v=s.verbatim===!0,j=o?{body:s.body,verbatim:v}:{replace:s.replace,verbatim:v},g=await le(i,l,f,j,s.rationale,w,a,await T(i));if("stale"in g)throw y(409,"stale_revision",`${h} changed after your read; it is now at revision ${g.stale.revision}`,`Read it again with \`crtr canvas read ${h}\`, then redo your change on the current text.`,{stale:g.stale});const D=await U(i,(await L(i,f))[0].body_hash),F=await N(i,f);return{id:f.id,name:h,revision:g.revision,...await te(i,l,D,g.unresolved),...await C(i,f,F.lint_ignore)?{unreached:!0}:{}}}catch(w){I(w,f)}})}u(Fe,"edit");async function Le(n){const e=S(n);if(e.new_name===void 0&&e.owner===void 0)throw b("give a new name, an owner, or both");if(e.new_name!==void 0&&(typeof e.new_name!="string"||!x.test(e.new_name)))throw b("`new_name` must be segments of letters, digits, `_` or `-` joined by `/`");return await O(n.principal,e.cwd),await k(async o=>{const r=await A(o,n),c=await B(o,r,n.params.ref),a=e.owner===void 0?void 0:await W(o,r,e.owner,e.cwd);try{const m=await pe(o,r,c,{...e.new_name!==void 0?{name:e.new_name}:{},...a?{owner:a}:{}},await T(o));return{id:m.id,name:await R(o,m)}}catch(m){I(m,c)}})}u(Le,"move");async function Me(n){return await O(n.principal),await k(async t=>{const o=await A(t,n),r=await B(t,o,n.params.ref),c=await R(t,r);try{await fe(t,o,r,await T(t))}catch(a){I(a,r)}return{id:r.id,name:c}})}u(Me,"remove");async function We(n){const e=n.query.get("diff"),t=e===null?void 0:Number(e);if(t!==void 0&&!(Number.isInteger(t)&&t>0))throw b("`diff` must be a revision number");return await Y(n),await O(n.principal),await k(async o=>{const r=await A(o,n),c=await z(o,r,decodeURIComponent(n.params.ref));if("remote"in c)throw y(404,"not_found",Z(c.remote),"Check the name with `crtr canvas search`.");const a="deleted"in c?c.deleted:c;if(a.type!=="document")throw b(`${a.name} is a ${a.type}, not a document`);const m=await me(o,r,a),s={object:await Ne(o,a),revisions:m.map(d=>({rev_id:d.rev_id,number:d.number,author_id:d.author,rationale:d.rationale,verbatim:d.verbatim,created_at:d.created_at,parents:d.parents,acting_app:d.acting_app,acting_for:d.acting_for}))};if(t!==void 0){const d=m.find(f=>f.number===t);if(!d)throw new E(404,"not_found",`${a.name} has no revision ${t}`);const i=d.parents[0]===void 0?void 0:m.find(f=>f.rev_id===d.parents[0]),l=await V(o,i?[i.body_hash,d.body_hash]:[d.body_hash]);s.diff=be(i?l.get(i.body_hash):"",l.get(d.body_hash))}return s})}u(We,"revisionHistory");const ne=1e3,oe=1e3,ie=3e3,Be=/^When\b.+\bbecause\b.+/,He=u(n=>{const e=n.trim();return e===""?0:e.split(/\s+/).length},"words");function qe(n,e){if(n.some(o=>o.on==="boot"&&o.deliver==="content")&&e>ne)return`body is ${e} words, over the ${ne}-word cap for a boot rule at content (the whole body enters every node's context). Keep the core here and move separate subjects into [[linked]] documents.`;const t=[...new Set(n.filter(o=>o.on!=="boot"&&o.deliver==="content").map(o=>o.on))];return t.length>0&&e>oe?`body is ${e} words, over the ${oe}-word cap for a content rule on ${t.join("/")}. Keep the core here and move separate subjects into [[linked]] documents.`:n.some(o=>o.on==="boot"&&o.deliver==="preview")&&e>ie?`body is ${e} words, over the ${ie}-word cap for a boot rule at preview. Keep the core here and move separate subjects into [[linked]] documents.`:null}u(qe,"lengthFinding");async function Pe(n){const e=S(n);return await O(n.principal,e.cwd),await k(async t=>{const o=await A(t,n),r=e.owner===void 0?null:await W(t,o,e.owner,e.cwd),c=await t.prepare("SELECT * FROM objects WHERE type = 'document' AND deleted_at IS NULL AND home_machine IS NULL AND kind != 'report' ORDER BY name").all(),a=[],m=new Map,s=[];for(const i of c)r&&i.owner!==r.id||await de(t,o,i)&&s.push({doc:i,head:(await L(t,i))[0]});const d=await V(t,s.flatMap(i=>i.head?[i.head.body_hash]:[]));for(const{doc:i,head:l}of s){const f=await N(t,i),h=new Set(f.lint_ignore??[]),w=await R(t,i),v=u((p,_,re)=>{h.has(p)||a.push({name:w,severity:_,rule:p,message:re})},"add"),j=await X(t,i),g=l?d.get(l.body_hash):"",D=qe(j,He(g));D&&v("length","error",D),j.some(p=>p.deliver==="preview")&&!Be.test(i.preview??"")&&v("preview-shape","error",`a rule delivers this document at preview, so the preview must read "When <situation in the reader's work>, read this because <what the reader gains>"`);const F=new Set((await t.prepare("SELECT written_as FROM edges WHERE type = 'links-to' AND src = ?").all(i.id)).map(p=>p.written_as));for(const p of G(g)){if(F.has(p))continue;const _=await K(t,o,p);"remote"in _||"object"in _||"deleted"in _||v("links","warning",`[[${p}]] names no object in your view`)}if(await C(t,i,f.lint_ignore)&&v("unreached","warning",Te),j.some(p=>p.on==="workspace-open"&&p.deliver==="content")){const p=await ue(t,i);p.type==="repo"&&!h.has("workspace-open")&&m.set(p.name,[...m.get(p.name)??[],w])}}for(const[i,l]of m)if(!(l.length<2))for(const f of l)a.push({name:f,severity:"warning",rule:"workspace-open",message:`repo ${i} has ${l.length} documents delivered at content on workspace-open (${l.join(", ")}); keep one and link the rest from it`});return{findings:a}})}u(Pe,"lint");const $=u((n,e=200)=>async t=>({status:e,body:await n(t)}),"ok"),ut=[{method:"POST",pattern:"/v1/docs",handler:$(Ie,201)},{method:"PATCH",pattern:"/v1/docs/:ref",handler:$(Fe)},{method:"POST",pattern:"/v1/docs/:ref/move",handler:$(Le)},{method:"DELETE",pattern:"/v1/docs/:ref",handler:$(Me)},{method:"GET",pattern:"/v1/docs/:ref/history",handler:$(We)},{method:"POST",pattern:"/v1/docs/lint",handler:$(Pe)}];export{R as canonicalName,ut as docRoutes};
@@ -1,4 +1,4 @@
1
- var x=Object.defineProperty;var r=(e,t)=>x(e,"name",{value:t,configurable:!0});import{createHash as T}from"node:crypto";import{withCanvasWrite as g}from"../../../core/canvas/db.js";import{canRead as k}from"../../../core/graph/access.js";import{permits as M}from"../../../core/permissions/evaluator.js";import{get as b}from"../../../core/graph/bodies.js";import{ownerForGrantee as C}from"../../../core/graph/objects.js";import{readerFor as F}from"../../../core/graph/reader.js";import{checkoutsForCwd as H}from"../../../core/graph/repo-sync/repos.js";import{RunError as h}from"../../../core/runs/operations.js";import{mapAsync as j}from"../../../core/async-array.js";import{personId as B}from"../../../core/canvas/person.js";const ut=new Set(["memory.list","memory.get"]),W=1024*1024,w=/^[A-Za-z0-9_-]+(\/[A-Za-z0-9_-]+)*$/,N=["knowledge","preference"],i=r((e,t)=>new h(400,"invalid_request",e,t),"invalid"),O=r(()=>new h(404,"not_found","no memory document by that name"),"notFound");function _(e){const t=e.get("store");if(t===null)throw i("store is required","store");if(t!=="user")throw i('store must be "user"',"store")}r(_,"store");function J(e){const t=e.get("kind");if(t===null)return null;if(!N.includes(t))throw i("kind must be knowledge or preference","kind");return t}r(J,"kindOf");function Y(e){const t=e.get("limit");if(t===null)return 50;if(!/^(0|[1-9]\d*)$/.test(t)||Number(t)<1||Number(t)>100)throw i("limit must be an integer from 1 to 100","limit");return Number(t)}r(Y,"limitOf");function U(e,t){return T("sha256").update(JSON.stringify(["user",e,t])).digest("base64url").slice(0,16)}r(U,"filterHash");function $(e,t){return Buffer.from(JSON.stringify({n:e,f:t}),"utf8").toString("base64url")}r($,"encodeCursor");function z(e,t){if(e===null)return null;try{if(!/^[A-Za-z0-9_-]+$/.test(e))throw new Error("not base64url");const n=JSON.parse(Buffer.from(e,"base64url").toString("utf8"));if(typeof n.n=="string"&&w.test(n.n)&&n.f===t)return n.n}catch{}throw i("cursor is not the next_cursor of a previous page with the same store, path and kind","cursor")}r(z,"decodeCursor");async function R(e){return await C(e,B())}r(R,"personObject");async function v(e,t){return await F(e,t,async n=>await H(e,n))}r(v,"graphReader");async function S(e,t){const n=await e.prepare(`SELECT r.body_hash, r.created_at FROM revisions r WHERE r.document = ?
1
+ var x=Object.defineProperty;var r=(e,t)=>x(e,"name",{value:t,configurable:!0});import{createHash as T}from"node:crypto";import{withCanvasWrite as g}from"../../../core/canvas/db.js";import{canRead as k}from"../../../core/graph/access.js";import{permits as M}from"../../../core/permissions/evaluator.js";import{get as b}from"../../../core/graph/bodies.js";import{ownerForGrantee as C}from"../../../core/graph/objects.js";import{readerFor as F}from"../../../core/graph/reader.js";import{checkoutsForCwd as H}from"../../../core/graph/repo-sync/repos.js";import{RunError as h}from"../../../core/runs/operations.js";import{mapAsync as j}from"../../../core/async-array.js";import{personId as B}from"../../../core/canvas/person.js";const ut=new Set(["memory.list","memory.get"]),W=1024*1024,w=/^[A-Za-z0-9_-]+(\/[A-Za-z0-9_-]+)*$/,N=["knowledge","preference"],i=r((e,t)=>new h(400,"invalid_request",e,t),"invalid"),O=r(()=>new h(404,"not_found","no memory document by that name"),"notFound");function _(e){const t=e.get("store");if(t===null)throw i("store is required","store");if(t!=="user")throw i('store must be "user"',"store")}r(_,"store");function J(e){const t=e.get("kind");if(t===null)return null;if(!N.includes(t))throw i("kind must be knowledge or preference","kind");return t}r(J,"kindOf");function Y(e){const t=e.get("limit");if(t===null)return 50;if(!/^(0|[1-9]\d*)$/.test(t)||Number(t)<1||Number(t)>100)throw i("limit must be an integer from 1 to 100","limit");return Number(t)}r(Y,"limitOf");function U(e,t){return T("sha256").update(JSON.stringify(["user",e,t])).digest("base64url").slice(0,16)}r(U,"filterHash");function $(e,t){return Buffer.from(JSON.stringify({n:e,f:t}),"utf8").toString("base64url")}r($,"encodeCursor");function z(e,t){if(e===null)return null;try{if(!/^[A-Za-z0-9_-]+$/.test(e))throw new Error("not base64url");const n=JSON.parse(Buffer.from(e,"base64url").toString("utf8"));if(typeof n.n=="string"&&w.test(n.n)&&n.f===t)return n.n}catch{}throw i("cursor is not the next_cursor of a previous page with the same store, path and kind","cursor")}r(z,"decodeCursor");async function R(e){return await C(e,B())}r(R,"personObject");async function v(e,t){return await F(e,t,async(n,o)=>await H(e,n,o))}r(v,"graphReader");async function S(e,t){const n=await e.prepare(`SELECT r.body_hash, r.created_at FROM revisions r WHERE r.document = ?
2
2
  AND NOT EXISTS (SELECT 1 FROM revision_parents p WHERE p.parent = r.rev_id) ORDER BY r.number DESC, r.rev_id LIMIT 1`).get(t.id),o=await e.prepare("SELECT created_at, author FROM revisions WHERE document = ? ORDER BY number, created_at LIMIT 1").get(t.id);if(!n||!o)throw O();return{head:n,first:o}}r(S,"revisions");async function A(e,t){const{head:n,first:o}=await S(e,t),a=t.name.lastIndexOf("/");return{name:t.name,folder:a<0?"":t.name.slice(0,a),kind:t.kind,preview:t.preview,summary:t.summary,privacy:t.privacy,revision:t.revision,created_at:o.created_at,updated_at:n.created_at}}r(A,"item");async function G(e,t){return t===null?null:(await e.prepare(`SELECT i.external_id FROM objects a LEFT JOIN nodes n ON n.node_id = a.id
3
3
  JOIN identities i ON i.object = CASE WHEN a.type = 'node' THEN n.app ELSE a.id END AND i.scheme = 'app'
4
4
  WHERE a.id = ?`).get(t))?.external_id??null}r(G,"granteeOf");function Z(e,t){if(e.length<=t)return e;let n=t;for(;n>0&&(e[n]&192)===128;)n--;return e.subarray(0,n)}r(Z,"utf8Prefix");async function P(e,t){_(t);const n=t.get("path");if(n!==null&&!w.test(n))throw i("path must be name segments of letters, digits, `_` or `-` joined by `/`","path");const o=J(t),a=Y(t),d=U(n,o),s=z(t.get("cursor"),d);return await g(async u=>{const l=await v(u,e),c=await R(u),m=n===null?null:`${n}/`,f=o===null?N:[o],y=await M(u,l,"read"),E=await u.prepareUncached(`SELECT o.*, d.summary, d.revision, d.source_path FROM objects o JOIN documents d ON d.object = o.id
@@ -1,3 +1,3 @@
1
- var Fe=Object.defineProperty;var l=(e,t)=>Fe(e,"name",{value:t,configurable:!0});import{ApiError as y}from"../../../api/errors.js";import{PRIVACY_LEVELS_DTO as Ae}from"../../../api/dto/objects.js";import{openDb as N,withCanvasWrite as v}from"../../../core/canvas/db.js";import{actorOf as ae}from"../../../core/graph/documents.js";import{readerForObject as C,readerFor as We}from"../../../core/graph/reader.js";import{resolveName as Le,stubsNamed as Pe,unwrapRef as ie}from"../../../core/graph/names.js";import{canRead as D,holdsObjectsScope as Ce,spaceOf as De}from"../../../core/graph/access.js";import{customReachable as Me,mayActAs as re}from"../../../core/graph/custom.js";import{customObjectRef as oe,authorizeCustom as se,fenceArgv as J}from"./custom-objects.js";import{edgesOf as Ge}from"../../../core/graph/edges.js";import{publish as B}from"../../../core/graph/events.js";import{objectDTO as Ue}from"../../../core/graph/kinds/dto.js";import{isKind as He,kindNames as ze,kindOf as K}from"../../../core/graph/kinds/registry.js";import{listObjects as Ve,searchObjects as ue}from"../../../core/graph/objects.js";import{checkoutsForCwd as Je}from"../../../core/graph/repo-sync/repos.js";import{recordWatch as M,unwatch as Be,watchersOf as Ke,watchesOf as Ze}from"../../../core/graph/watches.js";import{armObjectWaitForWatch as G,settleObjectWaitForUnwatch as Qe}from"../../../core/graph/object-waits.js";import{readerFor as T,resolveRef as Z,warmReaderRepos as R}from"../reader.js";import{readDelegationFor as ce,runReadLeaf as Ye}from"../../plugin-objects/read-leaf.js";import{invalidRequest as U,isRecord as q}from"./validate.js";import{callerNode as le,callerStub as Q,forwardNamed as Xe,forwardVerb as fe,originates as de,queryWithoutMachine as H,relayError as z,remoteStub as xe,unknownError as we,forwarding as P,withMachine as Y}from"../../peer/forward.js";import{getById as I}from"../../../core/graph/objects.js";import{ensureNodeStub as et,isStub as X,stubOf as tt,withKindDecl as $}from"../../../core/peer/stubs.js";import{isUnreachable as nt}from"../../../core/peer/client.js";import{normalizeMachineId as F}from"../../../core/peer/directory.js";import{mapAsync as at}from"../../../core/async-array.js";const A=l(async e=>async t=>await Je(e,t),"reposFnFor");async function g(e,t){return{...await Ue(e,t),...t.type==="document"?{schema_type:t.schema_type??null}:{}}}l(g,"objectDTO");async function it(e,t){const n=t.filter(r=>r.type==="document").map(r=>r.id),a=new Map;if(n.length===0)return a;const i=await e.prepareUncached(`SELECT object, extensions_json FROM documents WHERE object IN (${n.map(()=>"?").join(", ")})`).all(...n);for(const r of i)r.extensions_json!==null&&a.set(r.object,JSON.parse(r.extensions_json));return a}l(it,"extensionsOf");async function me(e,t){const n=await it(e,t);return await at(t,async a=>({...await g(e,a),...await(await K(e,a.type)).listItem?.(e,a),...a.type==="document"?{extensions:n.get(a.id)??{}}:{}}))}l(me,"listItems");function rt(e){return`no object named ${e} on this runtime; it may be on another runtime, or the name may be misspelled`}l(rt,"remoteMessage");async function pe(e,t,n){try{return await S(e,t,n)}catch(a){if(a instanceof y&&a.code==="not_found"&&!a.details?.deleted)return null;throw a}}l(pe,"ownerFilter");async function S(e,t,n){const a=await Z(e,t,n);if("remote"in a)throw new y(404,"not_found",rt(a.remote),{next:"Check the name with `crtr canvas search`."});if("deleted"in a)throw new y(404,"not_found",`${a.deleted.name} is deleted`,{id:a.deleted.id,deleted:!0});return a}l(S,"liveRef");const O=l(e=>decodeURIComponent(e.params.ref),"refParam"),he=l(e=>{const t=ie(e),n=t.indexOf("/");return n>0?t.slice(0,n):t},"idOf");async function ye(e){const t=await I(await N(),he(e));return t!==null&&await X(await N(),t)?t.id:null}l(ye,"stubIdOf");async function ot(e,t){const n=await ye(e);return n!==null?{stub:n,hit:!0}:(await R(t.principal),await v(async a=>{try{const i=await T(a,t),r=l(async()=>{const s=await Pe(a,i,e);if(s.length>1)throw new y(409,"ambiguous_name",`'${e}' names more than one remote object`,{candidates:s.map(c=>c.id),next:"Read one by its object id."});return{stub:s[0]?.id??null,hit:!1}},"named");let o;try{o=await Z(a,i,e)}catch(s){if(s instanceof y&&s.code==="not_found")return await r();throw s}if("remote"in o)return await r();if("deleted"in o){const s=await r();return s.stub===null?{stub:null,hit:!0}:s}return{stub:await X(a,o)?o.id:null,hit:!0}}catch(i){if(i instanceof y&&i.code==="ambiguous_name")throw i;return{stub:null,hit:!1}}}))}l(ot,"resolvedLocally");async function x(e,t,n){const a=await ot(t,e);if(a.stub!==null)return fe(e,a.stub,n);if(a.hit||!de(e.principal))return{kind:"local"};const i=await fe(e,he(t),n);return i.kind==="local"&&ie(t).includes("/")?Xe(e,n,{method:"GET",path:V(t),query:H(e)}):i}l(x,"forwardRef");const V=l(e=>`/v1/objects/${encodeURIComponent(e)}`,"objectPath");async function be(e,t,n,a,i){const r=t?.object;!r?.id||!r.type||await v(async o=>{const s=await le(o,e);if(s===null)return;const c=await xe(o,r.id,r.type,n,{kind:r.kind??null,name:r.name??r.id,...r.preview===void 0?{}:{preview:r.preview},owner:r.owner??null,...r.kind_decl===void 0?{}:{kind_decl:r.kind_decl},...r.privacy===void 0?{}:{privacy:r.privacy}});await M(o,s,c,a,i===void 0?{}:{patterns:i}),a==="ask"&&await G(o,s,c)})}l(be,"watchRemote");async function st(e){const t=O(e),n=["1","true"].includes(e.query.get("fields")??""),a=await x(e,t,{method:"GET",path:V(t),query:H(e)});if(a.kind==="unknown")return{state:"unknown",ref:t,unreachable:a.unreachable};if(a.kind==="remote"){if(a.status>=400)throw z(a.status,a.body);return await be(e,a.body,a.machine.id,"read"),Y(a.body,a.machine)}const i=l(async s=>{const c=await Q(s,e);return c===null?await T(s,e):await C(s,c,await A(s))},"readerOf");await R(e.principal);const r=await v(async s=>{const c=await i(s),u=await Z(s,c,t);if("remote"in u)return{state:"remote",remote:u.remote};if("deleted"in u)return{state:"deleted",deleted:await g(s,u.deleted)};const f=await ce(s,u);if(f!==null)return{delegate:f,hitId:u.id};const{data:w,text:b}=await(await K(s,u.type)).read(s,c,u,{fields:n,reposFn:await A(s)});return{state:"object",type:u.type,object:await $(s,u,await g(s,u)),text:b,data:w}});if(!("delegate"in r))return r;const o=await Ye(r.delegate,e.principal);return await R(e.principal),await v(async s=>{const c=await i(s),u=await I(s,r.hitId);if(u===null)throw new y(404,"not_found","object not found");if(u.deleted_at!==null)return{state:"deleted",deleted:await g(s,u)};if(!await D(s,c,u))throw new y(404,"not_found","object not found");const{data:f,text:w}=await(await K(s,u.type)).read(s,c,u,{fields:n,reposFn:await A(s)});return await ce(s,u)===null?{state:"object",type:u.type,object:await $(s,u,await g(s,u)),text:w,data:f}:{state:"object",type:u.type,object:await $(s,u,await g(s,u)),text:"markdown"in o?o.markdown:`${w}
1
+ var Fe=Object.defineProperty;var l=(e,t)=>Fe(e,"name",{value:t,configurable:!0});import{ApiError as y}from"../../../api/errors.js";import{PRIVACY_LEVELS_DTO as Ae}from"../../../api/dto/objects.js";import{openDb as N,withCanvasWrite as v}from"../../../core/canvas/db.js";import{actorOf as ae}from"../../../core/graph/documents.js";import{readerForObject as C,readerFor as We}from"../../../core/graph/reader.js";import{resolveName as Le,stubsNamed as Pe,unwrapRef as ie}from"../../../core/graph/names.js";import{canRead as D,holdsObjectsScope as Ce,spaceOf as De}from"../../../core/graph/access.js";import{customReachable as Me,mayActAs as re}from"../../../core/graph/custom.js";import{customObjectRef as oe,authorizeCustom as se,fenceArgv as J}from"./custom-objects.js";import{edgesOf as Ge}from"../../../core/graph/edges.js";import{publish as B}from"../../../core/graph/events.js";import{objectDTO as Ue}from"../../../core/graph/kinds/dto.js";import{isKind as He,kindNames as ze,kindOf as K}from"../../../core/graph/kinds/registry.js";import{listObjects as Ve,searchObjects as ue}from"../../../core/graph/objects.js";import{checkoutsForCwd as Je}from"../../../core/graph/repo-sync/repos.js";import{recordWatch as M,unwatch as Be,watchersOf as Ke,watchesOf as Ze}from"../../../core/graph/watches.js";import{armObjectWaitForWatch as G,settleObjectWaitForUnwatch as Qe}from"../../../core/graph/object-waits.js";import{readerFor as T,resolveRef as Z,warmReaderRepos as R}from"../reader.js";import{readDelegationFor as ce,runReadLeaf as Ye}from"../../plugin-objects/read-leaf.js";import{invalidRequest as U,isRecord as q}from"./validate.js";import{callerNode as le,callerStub as Q,forwardNamed as Xe,forwardVerb as fe,originates as de,queryWithoutMachine as H,relayError as z,remoteStub as xe,unknownError as we,forwarding as P,withMachine as Y}from"../../peer/forward.js";import{getById as I}from"../../../core/graph/objects.js";import{ensureNodeStub as et,isStub as X,stubOf as tt,withKindDecl as $}from"../../../core/peer/stubs.js";import{isUnreachable as nt}from"../../../core/peer/client.js";import{normalizeMachineId as F}from"../../../core/peer/directory.js";import{mapAsync as at}from"../../../core/async-array.js";const A=l(async e=>async(t,n)=>await Je(e,t,n),"reposFnFor");async function g(e,t){return{...await Ue(e,t),...t.type==="document"?{schema_type:t.schema_type??null}:{}}}l(g,"objectDTO");async function it(e,t){const n=t.filter(r=>r.type==="document").map(r=>r.id),a=new Map;if(n.length===0)return a;const i=await e.prepareUncached(`SELECT object, extensions_json FROM documents WHERE object IN (${n.map(()=>"?").join(", ")})`).all(...n);for(const r of i)r.extensions_json!==null&&a.set(r.object,JSON.parse(r.extensions_json));return a}l(it,"extensionsOf");async function me(e,t){const n=await it(e,t);return await at(t,async a=>({...await g(e,a),...await(await K(e,a.type)).listItem?.(e,a),...a.type==="document"?{extensions:n.get(a.id)??{}}:{}}))}l(me,"listItems");function rt(e){return`no object named ${e} on this runtime; it may be on another runtime, or the name may be misspelled`}l(rt,"remoteMessage");async function pe(e,t,n){try{return await S(e,t,n)}catch(a){if(a instanceof y&&a.code==="not_found"&&!a.details?.deleted)return null;throw a}}l(pe,"ownerFilter");async function S(e,t,n){const a=await Z(e,t,n);if("remote"in a)throw new y(404,"not_found",rt(a.remote),{next:"Check the name with `crtr canvas search`."});if("deleted"in a)throw new y(404,"not_found",`${a.deleted.name} is deleted`,{id:a.deleted.id,deleted:!0});return a}l(S,"liveRef");const O=l(e=>decodeURIComponent(e.params.ref),"refParam"),he=l(e=>{const t=ie(e),n=t.indexOf("/");return n>0?t.slice(0,n):t},"idOf");async function ye(e){const t=await I(await N(),he(e));return t!==null&&await X(await N(),t)?t.id:null}l(ye,"stubIdOf");async function ot(e,t){const n=await ye(e);return n!==null?{stub:n,hit:!0}:(await R(t.principal),await v(async a=>{try{const i=await T(a,t),r=l(async()=>{const s=await Pe(a,i,e);if(s.length>1)throw new y(409,"ambiguous_name",`'${e}' names more than one remote object`,{candidates:s.map(c=>c.id),next:"Read one by its object id."});return{stub:s[0]?.id??null,hit:!1}},"named");let o;try{o=await Z(a,i,e)}catch(s){if(s instanceof y&&s.code==="not_found")return await r();throw s}if("remote"in o)return await r();if("deleted"in o){const s=await r();return s.stub===null?{stub:null,hit:!0}:s}return{stub:await X(a,o)?o.id:null,hit:!0}}catch(i){if(i instanceof y&&i.code==="ambiguous_name")throw i;return{stub:null,hit:!1}}}))}l(ot,"resolvedLocally");async function x(e,t,n){const a=await ot(t,e);if(a.stub!==null)return fe(e,a.stub,n);if(a.hit||!de(e.principal))return{kind:"local"};const i=await fe(e,he(t),n);return i.kind==="local"&&ie(t).includes("/")?Xe(e,n,{method:"GET",path:V(t),query:H(e)}):i}l(x,"forwardRef");const V=l(e=>`/v1/objects/${encodeURIComponent(e)}`,"objectPath");async function be(e,t,n,a,i){const r=t?.object;!r?.id||!r.type||await v(async o=>{const s=await le(o,e);if(s===null)return;const c=await xe(o,r.id,r.type,n,{kind:r.kind??null,name:r.name??r.id,...r.preview===void 0?{}:{preview:r.preview},owner:r.owner??null,...r.kind_decl===void 0?{}:{kind_decl:r.kind_decl},...r.privacy===void 0?{}:{privacy:r.privacy}});await M(o,s,c,a,i===void 0?{}:{patterns:i}),a==="ask"&&await G(o,s,c)})}l(be,"watchRemote");async function st(e){const t=O(e),n=["1","true"].includes(e.query.get("fields")??""),a=await x(e,t,{method:"GET",path:V(t),query:H(e)});if(a.kind==="unknown")return{state:"unknown",ref:t,unreachable:a.unreachable};if(a.kind==="remote"){if(a.status>=400)throw z(a.status,a.body);return await be(e,a.body,a.machine.id,"read"),Y(a.body,a.machine)}const i=l(async s=>{const c=await Q(s,e);return c===null?await T(s,e):await C(s,c,await A(s))},"readerOf");await R(e.principal);const r=await v(async s=>{const c=await i(s),u=await Z(s,c,t);if("remote"in u)return{state:"remote",remote:u.remote};if("deleted"in u)return{state:"deleted",deleted:await g(s,u.deleted)};const f=await ce(s,u);if(f!==null)return{delegate:f,hitId:u.id};const{data:w,text:b}=await(await K(s,u.type)).read(s,c,u,{fields:n,reposFn:await A(s)});return{state:"object",type:u.type,object:await $(s,u,await g(s,u)),text:b,data:w}});if(!("delegate"in r))return r;const o=await Ye(r.delegate,e.principal);return await R(e.principal),await v(async s=>{const c=await i(s),u=await I(s,r.hitId);if(u===null)throw new y(404,"not_found","object not found");if(u.deleted_at!==null)return{state:"deleted",deleted:await g(s,u)};if(!await D(s,c,u))throw new y(404,"not_found","object not found");const{data:f,text:w}=await(await K(s,u.type)).read(s,c,u,{fields:n,reposFn:await A(s)});return await ce(s,u)===null?{state:"object",type:u.type,object:await $(s,u,await g(s,u)),text:w,data:f}:{state:"object",type:u.type,object:await $(s,u,await g(s,u)),text:"markdown"in o?o.markdown:`${w}
2
2
  content unavailable: ${o.unavailable}`,data:{...f,content:"markdown"in o?"live":"unavailable"}}})}l(st,"read");function ee(e,t,n,a){if(e!=null){if(!n.includes(e)){a.push({field:t,problem:`must be one of ${n.join(", ")}`,received:e});return}return e}}l(ee,"oneOf");async function ge(e,t,n){if(t!=null){if(typeof t!="string"||!await He(e,t)){n.push({field:"type",problem:`must be a kind: one of ${(await ze(e)).join(", ")}`,received:t});return}return t}}l(ge,"kindName");function je(e,t,n,a){if(e==null)return a;const i=Number(e);return!Number.isInteger(i)||i<1||i>100?(n.push({field:t,problem:"must be an integer from 1 to 100",received:e}),a):i}l(je,"limitOf");function _e(e,t){if(e==null)return;let n=e;if(typeof e=="string")try{n=JSON.parse(e)}catch{n=null}if(!q(n)||Object.values(n).some(a=>!q(a))){t.push({field:"extensions",problem:'must be an object of objects, e.g. {"firstlight":{"state":"active"}}',received:e});return}return n}l(_e,"extensionsParam");function ke(e,t){if(e!=null){if(typeof e!="string"||e===""){t.push({field:"schema_type",problem:"must be a non-empty string",received:e});return}return e}}l(ke,"schemaTypeParam");async function ve(e){const t=e.query,n=[],a=await ge(await N(),t.get("type"),n),i=ee(t.get("privacy"),"privacy",Ae,n),r=je(t.get("limit"),"limit",n,50),o=t.get("cursor");o!==null&&!/^\d+$/.test(o)&&n.push({field:"cursor",problem:"is not a cursor from a previous page",received:o});const s=t.get("deleted");s!==null&&!["0","1","true","false"].includes(s)&&n.push({field:"deleted",problem:"must be true or false",received:s});const c=t.get("shared");c!==null&&!["0","1","true","false"].includes(c)&&n.push({field:"shared",problem:"must be true or false",received:c});const u=_e(t.get("extensions"),n),f=ke(t.get("schema_type"),n);return n.length>0&&U("object list request",n),await R(e.principal),await v(async w=>{const b=await T(w,e),j={...a?{type:a}:{},...i?{privacy:i}:{},...t.get("kind")!==null?{kind:t.get("kind")}:{},...s==="1"||s==="true"?{deleted:!0}:{},...c==="1"||c==="true"?{shared:!0}:{},...u?{extensions:u}:{},...f?{schemaType:f}:{},...t.get("name")!==null?{namePrefix:t.get("name")}:{}},k=t.get("owner");if(k!==null){const m=await pe(w,b,k);if(m===null)return{items:[],next_cursor:null};j.owner=m}const p=await Ve(w,b,j,{limit:r,after_seq:o===null?0:Number(o)}),d=p.at(-1);return{items:await me(w,p),next_cursor:p.length===r&&d?String(d.seq):null}})}l(ve,"listLocal");const ut={ms:3e4},ct="self",te=l((e,t)=>e.map(n=>({...n,machine:t})),"labelItems");async function Oe(e,t,n,a){const i=P.current;try{const r=await i.call(t.id,{method:"GET",path:"/v1/objects",query:n},await i.envelope(e.principal),a);if(nt(r))return{state:"unreachable",items:[],next:null};if(r.status===426)return{state:"too_old",items:[],next:null};const o=r.body;return r.status!==200||!Array.isArray(o?.items)?{state:"unreachable",items:[],next:null}:{state:"ok",items:te(o.items,t),next:o.next_cursor??null}}catch{return{state:"unreachable",items:[],next:null}}}l(Oe,"remotePage");async function lt(e){const t=new Promise(n=>e.addEventListener("abort",()=>n(null),{once:!0}));return Promise.race([P.current.machines().catch(()=>null),t])}l(lt,"machinesWithin");async function ft(e){const t=e.query.get("machine");if(!de(e.principal)||!P.current.joined()||t===ct)return await ve(Ee(e));const a=P.current.self(),i=t!==null&&F(t)!==a,r=i?null:await ve(Ee(e)),o=new AbortController,s=setTimeout(()=>o.abort(),ut.ms);s.unref?.();try{const c=await lt(o.signal);if(c===null){if(i)throw new y(503,"runtime_unreachable",`The directory did not answer, so ${F(t)} cannot be listed.`,{machine:F(t)});return r}const u=l(d=>({id:d,name:c.find(m=>m.machine_id===d)?.name??d}),"labelOf"),f=u(a),w=c.filter(d=>d.machine_id!==a&&d.kind!=="device"),b=H(e);if(t!==null){if(!i)return{items:te(r.items,f),next_cursor:r.next_cursor,machines:[{machine_id:a,name:f.name,state:"ok",more:r.next_cursor!==null}]};const d=F(t);if(!w.some(L=>L.machine_id===d))throw new y(404,"not_found",`no machine ${d} on your account`,{machine:d});const m=await Oe(e,u(d),b,o.signal);return{items:m.items,next_cursor:m.next,machines:[{machine_id:d,name:u(d).name,state:m.state,more:m.next!==null}]}}const{cursor:j,...k}=b,p=await Promise.all(w.map(d=>Oe(e,u(d.machine_id),k,o.signal)));return{items:[...te(r.items,f),...p.flatMap(d=>d.items)],next_cursor:r.next_cursor,machines:[{machine_id:a,name:f.name,state:"ok",more:r.next_cursor!==null},...w.map((d,m)=>({machine_id:d.machine_id,name:d.name,state:p[m].state,more:p[m].next!==null}))]}}finally{clearTimeout(s)}}l(ft,"list");function Ee(e){const t=new URLSearchParams(e.query);return t.delete("machine"),{...e,query:t}}l(Ee,"withoutMachine");async function dt(e){const t=[],n=q(e.body)?e.body:{};q(e.body)||t.push({field:"body",problem:"must be an object",received:e.body});const a=n.text;(typeof a!="string"||a.trim()==="")&&t.push({field:"text",problem:"is required",received:a});const i=n.grep;if(i!==void 0)if(typeof i!="string")t.push({field:"grep",problem:"must be a regular expression string",received:i});else try{new RegExp(i)}catch(h){t.push({field:"grep",problem:`is not a valid regular expression: ${h.message}`,received:i})}n.body!==void 0&&typeof n.body!="boolean"&&t.push({field:"body",problem:"must be a boolean",received:n.body});const r=await ge(await N(),n.type,t);n.kind!==void 0&&typeof n.kind!="string"&&t.push({field:"kind",problem:"must be a string",received:n.kind}),n.owner!==void 0&&typeof n.owner!="string"&&t.push({field:"owner",problem:"must be a string",received:n.owner});const o=je(n.limit,"limit",t,50),s=_e(n.extensions,t),c=ke(n.schema_type,t);t.length>0&&U("object search request",t),await R(e.principal);const u=await v(async h=>{const _=await T(h,e),$e=typeof n.owner=="string"?await pe(h,_,n.owner):null;return{reader:_,owner:$e}}),{reader:f,owner:w}=u;if(typeof n.owner=="string"&&w===null)return{items:[]};const b={...s?{extensions:s}:{},...c?{schemaType:c}:{},...r?{type:r}:{},...typeof n.kind=="string"?{kind:n.kind}:{},...w?{owner:w}:{}},j=await N(),k=await ue(j,f,{text:a,body:n.body===!0||typeof i=="string",...b}),p=new Set(k.map(h=>h.object.id)),m=(typeof i=="string"?(await ue(j,f,{text:i,grep:!0,...b})).filter(h=>p.has(h.object.id)):k).slice(0,o),L=await me(j,m.map(h=>h.object));return{items:m.map((h,_)=>({object:L[_],...h.line!==void 0?{matches:[{line:h.line,text:h.text??""}]}:{}}))}}l(dt,"search");const Te=["interrupt","steer","after-turn","next-turn"],wt=/^(\*|>|[A-Za-z0-9_-]+)(\.(\*|>|[A-Za-z0-9_-]+))*$/;function mt(e,t){if(e!==void 0){if(!Array.isArray(e)||e.length===0||e.some(n=>typeof n!="string"||!wt.test(n)||n.includes(">")&&!n.endsWith(">"))){t.push({field:"patterns",problem:"must be a non-empty list of event patterns (dot-separated words, `*` for one word, a final `>` for the rest)",received:e});return}return e}}l(mt,"patternsOf");function pt(e,t){if(e===void 0)return;if(!q(e)||Object.keys(e).length===0){t.push({field:"config",problem:"must map levels 1-10 to a delivery",received:e});return}const n=[];for(const[a,i]of Object.entries(e)){const r=Number(a);!Number.isInteger(r)||r<1||r>10?t.push({field:`config.${a}`,problem:"level must be an integer from 1 to 10"}):Te.includes(i)?n.push({threshold:r,delivery:i}):t.push({field:`config.${a}`,problem:`delivery must be one of ${Te.join(", ")}`,received:i})}return n.sort((a,i)=>i.threshold-a.threshold)}l(pt,"configOf");async function Re(e){const t=await ye(e);if(t!==null)throw new y(400,"invalid_request",`${t} lives on another machine; an explicit watcher cannot watch it from here`,{id:t})}l(Re,"refuseStubWatch");async function ne(e,t){const n=await I(e,t)??await(async()=>{const a=await Le(e,await We(e,{class:"person"},async()=>[]),t);return"object"in a?a.object:null})();return n===null||n.deleted_at!==null||!(n.type.includes(".")||n.type==="node")?null:n}l(ne,"findWatcher");const E=l(()=>{throw new y(404,"not_found","watcher not found")},"watcherNotFound");async function qe(e,t,n){if(typeof t!="string"||n===void 0||n===null)return null;if(typeof n!="string")throw new y(400,"invalid_request","invalid watcher_machine");if(await ne(e,t)!==null)return null;const a=P.current;let i;try{i=await a.machines()}catch{throw new y(503,"runtime_unreachable","The directory did not answer, so the watcher machine cannot be checked.")}const r=F(n);return(r===a.self()||!i.some(o=>F(o.machine_id)===r))&&E(),r}l(qe,"remoteWatcherMachine");async function Ne(e,t,n,a){if(t.publishToken||t.principal.class==="anonymous")return E();const i=await T(e,t);if(i.class==="person")return E();let r;try{r=await S(e,i,a)}catch{return E()}const o=r.owner===null?null:await I(e,r.owner);return o===null||!await re(e,i,o)||!await Ce(e,i,"link",n)||(await De(e,n)).id===i.app.id&&!(await D(e,i,n)&&await D(e,await C(e,n),r))?E():(await J(e,t,n),{actor:i.app,object:r})}l(Ne,"linkWatcher");async function Ie(e,t,n){if(t.publishToken)return!0;if(t.principal.class==="anonymous"||!n.type.includes("."))return!1;const a=await T(e,t),i=n.owner===null?null:await I(e,n.owner);return i!==null&&await re(e,a,i)&&await Me(e,a,n)}l(Ie,"ownsWatcher");async function ht(e){const t=O(e),n=q(e.body)?e.body:{};if(typeof n.watcher=="string"&&await Re(t),typeof n.watcher!="string"){const i=await x(e,t,{method:"POST",path:`${V(t)}/watch`,body:e.body});if(i.kind==="unknown")throw we(t,i.unreachable);if(i.kind==="remote"){if(i.status>=400)throw z(i.status,i.body);const r=i.body.patterns;return await be(e,i.body,i.machine.id,"ask",r),Y(i.body,i.machine)}}const a=await qe(await N(),n.watcher,n.watcher_machine);return await yt(e,a)}l(ht,"watch");async function yt(e,t=null){const n=[],a=e.body===void 0?{}:q(e.body)?e.body:(n.push({field:"body",problem:"must be an object"}),{}),i=mt(a.patterns,n),r=pt(a.config,n);return a.filter!==void 0&&!q(a.filter)&&n.push({field:"filter",problem:"must be an object",received:a.filter}),a.watcher!==void 0&&typeof a.watcher!="string"&&n.push({field:"watcher",problem:"must be a custom-object ref",received:a.watcher}),a.watcher_machine!==void 0&&typeof a.watcher_machine!="string"&&n.push({field:"watcher_machine",problem:"must be a machine id",received:a.watcher_machine}),n.length>0&&U("watch request",n),await R(e.principal),await v(async o=>{const s=typeof a.watcher=="string";if((e.publishToken||e.principal.class==="anonymous")&&!s)throw new y(404,"not_found","watcher not found");const c=i??[">"],u={patterns:c,...r?{config:r}:{},...a.filter!==void 0?{filter:a.filter}:{}};if(s){const j=a.watcher,k=t===null?null:await bt(o,e,j,t),p=k??(e.publishToken?await oe(o,j):await ne(o,j));if(p===null)return E();if(k===null&&await Ie(o,e,p)){const L=await se(o,e,p);await J(o,e,p);const h=await C(o,p),_=await S(o,h,O(e));if(!await D(o,h,_))throw new y(404,"not_found","object not found");return await M(o,p,_,"act",u),await G(o,p,_),await B(o,{event:"watched",object:_,actor:L,attrs:{}},await A(o)),{object:await $(o,_,await g(o,_)),patterns:c}}const{actor:d,object:m}=await Ne(o,e,p,O(e));return await M(o,p,m,"act",{...u,linkApp:d}),await G(o,p,m),await B(o,{event:"watched",object:m,actor:d,attrs:{}},await A(o)),{object:await $(o,m,await g(o,m)),patterns:c}}const f=await T(o,e),w=await Q(o,e)??ae(f),b=await S(o,f,O(e));return await M(o,w,b,"ask",u),await G(o,w,b),await B(o,{event:"watched",object:b,actor:w,attrs:{}},await A(o)),{object:await $(o,b,await g(o,b)),patterns:c}})}l(yt,"watchLocal");async function bt(e,t,n,a){return t.publishToken||t.principal.class==="anonymous"?E():await et(e,n,a)}l(bt,"ensureNodeStubFor");async function Se(e,t,n,a){const i=l(async()=>(await e.prepare(`SELECT count(*) AS n FROM watch_subscriptions s JOIN watches w ON w.watch_id = s.watch
3
3
  WHERE w.watcher = ? AND w.object = ?`).get(t.id,n.id)).n,"count"),r=await i();await Be(e,t,n,a??void 0);const o=await i();return o===0&&await Qe(e,t,n),{object:await g(e,n),removed:r-o}}l(Se,"dropWatch");async function gt(e){const t=O(e);if(e.query.get("watcher")&&await Re(t),!e.query.get("watcher")){const a=await x(e,t,{method:"DELETE",path:`${V(t)}/watch`,query:H(e)});if(a.kind==="unknown")throw we(t,a.unreachable);if(a.kind==="remote"){const i=a.status===404?a.body.error?.details:void 0,r=i?.deleted===!0?i.id:void 0;if(a.status>=400&&r===void 0)throw z(a.status,a.body);const o=r??a.body.object?.id,s=await v(async c=>{const u=await le(c,e),f=o===void 0?null:await I(c,o);return u===null||f===null||!await X(c,f)?null:await Se(c,u,f,e.query.get("pattern"))});if(r!==void 0){if(s===null)throw z(a.status,a.body);return{...s,machine:a.machine}}return Y(a.body,a.machine)}}const n=await qe(await N(),e.query.get("watcher")??void 0,e.query.get("watcher_machine")??void 0);return await jt(e,n)}l(gt,"unwatchRoute");async function jt(e,t=null){const n=e.query.get("pattern"),a=e.query.get("watcher");return await R(e.principal),await v(async i=>{if((e.publishToken||e.principal.class==="anonymous")&&!a)throw new y(404,"not_found","watcher not found");const r=l(async(c,u)=>await Se(i,c,u,n),"drop");if(a){const c=t===null?null:await(async()=>{const f=await I(i,a);return f!==null&&await tt(i,f)!==null?f:null})();if(t!==null&&c===null)return E();const u=c??(e.publishToken?await oe(i,a):await ne(i,a));return u===null?E():c===null&&await Ie(i,e,u)?(await se(i,e,u),await J(i,e,u),await r(u,await S(i,await C(i,u),O(e)))):await r(u,(await Ne(i,e,u,O(e))).object)}const o=await T(i,e),s=await Q(i,e)??ae(o);return await r(s,await S(i,o,O(e)))})}l(jt,"unwatchLocal");async function _t(e){const t=[],n=ee(e.query.get("type"),"type",["acted-on","links-to","watches"],t),a=ee(e.query.get("direction"),"direction",["out","in"],t);return t.length>0&&U("edges request",t),await R(e.principal),await v(async i=>{const r=await T(i,e),o=await S(i,r,O(e)),s=[];if(n!=="watches")for(const c of await Ge(i,r,o,{...n?{type:n}:{},direction:a??"both"}))s.push({type:c.type,src:await g(i,c.src),dst:await g(i,c.dst),...c.written_as?{written_as:c.written_as}:{}});if(n===void 0||n==="watches"){const c=[...a!=="in"?await Ze(i,r,o):[],...a!=="out"?await Ke(i,r,o):[]];for(const u of c)s.push({type:"watches",src:await g(i,u.watcher),dst:await g(i,u.object)})}return{items:s}})}l(_t,"edges");const W=l(e=>async t=>({status:200,body:await e(t)}),"ok"),Zt=[{method:"POST",pattern:"/v1/objects/search",handler:W(dt)},{method:"GET",pattern:"/v1/objects/:ref/edges",handler:W(_t)},{method:"POST",pattern:"/v1/objects/:ref/watch",handler:W(ht)},{method:"DELETE",pattern:"/v1/objects/:ref/watch",handler:W(gt)},{method:"GET",pattern:"/v1/objects/:ref",handler:W(st)},{method:"GET",pattern:"/v1/objects",handler:W(ft)}];export{ut as listBudget,Zt as objectRoutes,ot as resolvedLocally};
@@ -6,7 +6,7 @@ import { type RequestContext, type RouteTable } from '../router.js';
6
6
  * anything is written when another live profile object holds the handle; a manifest failure then
7
7
  * rolls the object rename back. */
8
8
  export declare function renameProfileAndHandle(profileId: string, name: string): Promise<ProfileEntry>;
9
- /** Add a project path; each repo enclosing it starts at `preview` unless the profile already limits that
9
+ /** Add a project path; the repo it names starts at `preview` unless the profile already limits that
10
10
  * handle (bare or `repo:`-typed). Repos are identified before the manifest changes, so a failed lookup adds nothing. */
11
11
  export declare function addProjectWithDefaultLimit(profileId: string, limits: Readonly<Record<string, string>>, path: string): Promise<void>;
12
12
  /** One visible profile by exact id or unique name; a miss or an invisible profile is 404. */
@@ -1 +1 @@
1
- var N=Object.defineProperty;var o=(t,e)=>N(t,"name",{value:e,configurable:!0});import{openDb as L}from"../../../core/canvas/db.js";import{assertLaunchKind as v}from"../../../core/runtime/launch-target.js";import{listNodesByProfile as h,shiftProfileNodeDeadlines as M}from"../../../core/canvas/canvas.js";import{liveExecutionForNode as S}from"../../../core/canvas/executions.js";import{shiftJobDeadlines as F}from"../../../core/graph/jobs.js";import{boundFleet as V}from"../../../core/runtime/fleet.js";import{recordedPidLiveness as $}from"../../../core/canvas/pid.js";import{withCanvasWrite as y}from"../../../core/canvas/db.js";import{reposForCwd as C,warmCheckoutIdentities as G}from"../../../core/graph/repo-sync/repos.js";import{renameProfileObject as K}from"../../../core/graph/objects.js";import{usage as d}from"../../../core/errors.js";import{ApiError as l}from"../../../api/errors.js";import{scopeAllowed as I}from"../../../core/scopes.js";import{validateEnvVarName as U}from"../../../core/env-name.js";import{listProfileEnvNames as B,removeProfileEnvVar as H,setProfileEnvVar as W}from"../../../core/profiles/env-store.js";import{isDeploymentName as J,listAppEnvNames as Y,removeAppEnvVar as z,setAppEnvVar as Q}from"../../../core/profiles/app-env-store.js";import{addProfileProject as X,assertDeliveryLimits as Z,setProfileDeliveryLimit as T,assertProfileProjects as _,createProfile as b,ensureRootProfile as x,listProfiles as u,loadProfileManifest as P,pauseProfile as ee,removeProfileProject as te,renameProfile as ae,resumeProfile as re,setProfileDefaultKind as ie,updateProfileMetadata as ne}from"../../../core/profiles/manifest.js";import{requestProfileDeletion as oe}from"../../profile-delete.js";import{brokerSignalBus as se}from"../../broker-signals/bus.js";import{toProfileDTO as de}from"../map.js";import{isCloudRole as le,personId as fe}from"../../../core/canvas/person-state.js";import{resolveRecipeRepositories as pe,repositoriesByProfile as A}from"../../../core/environment-repos.js";import{machineEnvironmentId as me}from"../../../core/environments.js";import{actsAsPerson as E,appOf as g,resolvedScopes as ue}from"../router.js";const D="root",ce=4096;function w(t,e=[]){return{...de(t),environment_id:t.manifest.environment_id??me(),repositories:e}}o(w,"toProfileDTO");async function f(t){return w(t,(await A()).get(t.profileId)??[])}o(f,"toProfileDTOWithRepositories");function c(t){return g(t.principal)??"app:terminal"}o(c,"callerApp");function k(t,e,r=null){if(u().some(a=>a.manifest.name===e&&a.profileId!==r&&(a.manifest.grantee??"app:terminal")===t))throw new l(400,"invalid_request",`${t} already has a profile named ${e}`)}o(k,"assertNameFree");async function p(t,e){const r=await R(t,e),a=r.manifest.grantee??"app:terminal";if(t.principal.class!=="person"&&!E(t.principal)&&a!==g(t.principal))throw new l(403,"permission_error",`profile ${r.profileId} belongs to ${a}; only that app changes it`);return r}o(p,"requireOwnProfile");async function we(t){const e=t.body??{};if(typeof e.name!="string"||e.name.trim()==="")throw d("a profile name is required",{field:"name"});e.projects!==void 0&&_(e.projects);const r=c(t),a=e.name.trim();k(r,a),e.default_kind!==void 0&&await v(e.default_kind,process.cwd(),null);const i=e.repositories??[];if(!Array.isArray(i)||i.some(m=>typeof m!="string"))throw d("repositories must be an array of owner/name strings",{field:"repositories"});if(i.length===0){const m=await b(a,e.projects??[],{defaultKind:e.default_kind,metadata:e.metadata,grantee:r});return{status:201,body:w(m)}}if(!le())throw new l(400,"invalid_request","repositories make a cloud dev profile; this role runs profiles on the machine, so use a project directory instead");if(e.projects!==void 0&&e.projects.length>0)throw new l(400,"invalid_request","a profile with repositories stores no project paths; pass repositories or projects, not both");const n=await pe(fe(),i),s=await b(a,[],{defaultKind:e.default_kind,metadata:e.metadata,grantee:r,memoryMb:ce,recipe:{repositories:n,setup_script:null,pi_packages:null}});return{status:201,body:await f(s)}}o(we,"handleCreate");async function ve(t,e){const r=e.trim();if(r==="")throw d("profile name must not be empty");return await y(async a=>(await K(a,t,r),await ae(t,r)))}o(ve,"renameProfileAndHandle");async function he(t,e,r){await G(r);const a=await y(async i=>(await C(i,r)).map(n=>n.name));await X(t,r);for(const i of a)e[i]===void 0&&e[`repo:${i}`]===void 0&&await T(t,i,"preview")}o(he,"addProjectWithDefaultLimit");async function ye(t){const{profileId:e,manifest:r}=await p(t,t.params.name),a=t.body??{};return a.name!==void 0&&k(r.grantee??"app:terminal",a.name.trim(),e),a.default_kind!==void 0&&await v(a.default_kind,process.cwd(),e),a.add_project!==void 0&&_([a.add_project]),a.set_delivery_limit!==void 0&&Z({[a.set_delivery_limit.owner]:a.set_delivery_limit.level}),a.name!==void 0&&await ve(e,a.name),a.default_kind!==void 0&&await ie(e,a.default_kind),a.add_project!==void 0&&await he(e,r.delivery_limits??{},a.add_project.path),a.set_delivery_limit!==void 0&&await T(e,a.set_delivery_limit.owner,a.set_delivery_limit.level),a.remove_project!==void 0&&await te(e,a.remove_project),{status:200,body:await f(P(e))}}o(ye,"handleUpdate");async function _e(t){const{profileId:e}=await p(t,t.params.name);return{status:200,body:{profile_id:e,names:await B(e)}}}o(_e,"handleEnvList");function j(t){const e=t.params.var,r=U(e);if(!r.isValid)throw d(`invalid env var name: ${r.errors.join("; ")}`,{field:"name",received:e});return e}o(j,"requireEnvVarName");function O(t){const e=j(t);if(J(e)&&!E(t.principal))throw new l(403,"permission_error",`${e} is deployment-wide; only a person changes it`);return e}o(O,"requireSelfEnvVarName");async function be(t){const{profileId:e}=await p(t,t.params.name),r=j(t),{value:a}=t.body??{};if(typeof a!="string"||a==="")throw d("a non-empty env value is required",{field:"value"});return{status:200,body:{profile_id:e,changed:await W(e,r,a)}}}o(be,"handleEnvSet");async function Pe(t){const{profileId:e}=await p(t,t.params.name),r=j(t);return{status:200,body:{profile_id:e,changed:await H(e,r)}}}o(Pe,"handleEnvRemove");async function Ee(t){const e=t.params.name,r=t.body??{};r.projects!==void 0&&_(r.projects);const a=c(t);if(e===D&&a==="app:terminal")return{status:200,body:await f(await x())};if(e===D)throw new l(403,"permission_error","root belongs to the terminal app");const i=u().find(s=>s.manifest.name===e&&(s.manifest.grantee??"app:terminal")===a);if(i!==void 0)return{status:200,body:await f(i)};r.default_kind!==void 0&&await v(r.default_kind,process.cwd(),null);const n=await b(e,r.projects??[],{defaultKind:r.default_kind,metadata:r.metadata,grantee:a});return{status:200,body:w(n)}}o(Ee,"handleEnsure");async function ge(t){const e=await p(t,t.params.name),r=t.body??{};if(typeof r!="object"||r===null||Array.isArray(r))throw d("profile metadata body must be an object",{field:"body"});const a=r,i=a.unset===void 0?[]:a.unset;if(!Array.isArray(i)||i.some(m=>typeof m!="string"))throw d("profile metadata `unset` must be an array of strings",{field:"unset"});const n=a.set===void 0?{}:a.set,s=await ne(e.profileId,n,i);return{status:200,body:await f(s)}}o(ge,"handleSetMetadata");async function je(t){const e=P(t.params.name),r=await ee(e.profileId),a=(await h(e.profileId)).filter(n=>n.status==="active"||n.status==="idle");if(a.length===0)return{status:200,body:{profile_id:e.profileId,paused_at:r.manifest.paused_at}};const i=V();for(const n of a){const s=i.get(n.node_id);if(s!==void 0){await i.interruptForProfilePause(n.node_id,s.pid);continue}n.pi_pid!=null&&$(n.pi_pid,n.pi_pid_identity)==="alive"&&await i.interruptForProfilePause(n.node_id,n.pi_pid)}return{status:200,body:{profile_id:e.profileId,paused_at:r.manifest.paused_at}}}o(je,"handlePause");async function Ie(t){const e=P(t.params.name),r=await re(e.profileId);for(const a of await h(e.profileId))(a.status==="active"||a.status==="idle"||await S(a.node_id)!==null)&&se.markMail(a.node_id);if(r.pausedAt!==null){const a=Date.parse(r.pausedAt);if(!Number.isNaN(a)){const i=Math.max(0,Date.now()-a);await M(e.profileId,i);for(const n of await h(e.profileId))n.status!=="dead"&&await y(s=>F(s,n.node_id,i))}}return{status:200,body:{profile_id:e.profileId,paused_at:r.manifest.paused_at}}}o(Ie,"handleResume");async function q(t){const e=t.principal;if(E(e))return u();if(e.class==="person"&&e.sub!==void 0){const a=await L(),i=new Set((await a.prepare("SELECT id FROM profiles WHERE person = ?").all(e.sub)).map(n=>n.id));return u().filter(({profileId:n})=>i.has(n))}const r=await ue(e);return u().filter(({profileId:a,manifest:i})=>{const n=i.grantee??"app:terminal";if(n===g(e))return!0;const s=`crtr:memory:rw:${n}:profile:${a}`;return I(r,s)&&(e.class!=="broker"||I(e.scopes,s))})}o(q,"visibleProfiles");async function R(t,e){const r=await q(t),a=r.find(({profileId:n})=>n===e),i=a?[a]:r.filter(({manifest:n})=>n.name===e);if(i.length===0)throw new l(404,"not_found","profile not found");if(i.length>1)throw new l(400,"ambiguous","profile name matches multiple visible profiles; use an exact id");return i[0]}o(R,"requireUsableProfile");async function Te(t){const e=await A();return{status:200,body:(await q(t)).map(r=>w(r,e.get(r.profileId)??[]))}}o(Te,"handleList");async function Ae(t){return{status:200,body:await f(await R(t,t.params.name))}}o(Ae,"handleGet");async function De(t){return oe((await p(t,t.params.name)).profileId,t.body)}o(De,"handleDelete");const et=[{method:"GET",pattern:"/v1/apps/self/env",handler:o(async t=>({status:200,body:{names:await Y(c(t))}}),"handler")},{method:"PUT",pattern:"/v1/apps/self/env/:var",handler:o(async t=>{const e=O(t),{value:r}=t.body??{};if(typeof r!="string"||!r)throw d("a non-empty env value is required",{field:"value"});return{status:200,body:{changed:await Q(c(t),e,r)}}},"handler")},{method:"DELETE",pattern:"/v1/apps/self/env/:var",handler:o(async t=>({status:200,body:{changed:await z(c(t),O(t))}}),"handler")},{method:"PUT",pattern:"/v1/profiles/:name",handler:Ee},{method:"POST",pattern:"/v1/profiles/:name/pause",ownerOnly:!0,handler:je},{method:"POST",pattern:"/v1/profiles/:name/resume",ownerOnly:!0,handler:Ie},{method:"PATCH",pattern:"/v1/profiles/:name/metadata",handler:ge},{method:"POST",pattern:"/v1/profiles",handler:we},{method:"PATCH",pattern:"/v1/profiles/:name",handler:ye},{method:"GET",pattern:"/v1/profiles/:name/env",handler:_e},{method:"PUT",pattern:"/v1/profiles/:name/env/:var",handler:be},{method:"DELETE",pattern:"/v1/profiles/:name/env/:var",handler:Pe},{method:"DELETE",pattern:"/v1/profiles/:name",handler:De},{method:"GET",pattern:"/v1/profiles",handler:Te},{method:"GET",pattern:"/v1/profiles/:name",handler:Ae}];export{he as addProjectWithDefaultLimit,et as profileRoutes,ve as renameProfileAndHandle,R as requireUsableProfile};
1
+ var L=Object.defineProperty;var o=(t,e)=>L(t,"name",{value:e,configurable:!0});import{openDb as N}from"../../../core/canvas/db.js";import{assertLaunchKind as v}from"../../../core/runtime/launch-target.js";import{listNodesByProfile as y,shiftProfileNodeDeadlines as M}from"../../../core/canvas/canvas.js";import{liveExecutionForNode as $}from"../../../core/canvas/executions.js";import{shiftJobDeadlines as F}from"../../../core/graph/jobs.js";import{boundFleet as S}from"../../../core/runtime/fleet.js";import{recordedPidLiveness as V}from"../../../core/canvas/pid.js";import{withCanvasWrite as w}from"../../../core/canvas/db.js";import{readerFor as C}from"../reader.js";import{canRead as B}from"../../../core/graph/access.js";import{ownersByHandle as G}from"../../../core/graph/names.js";import{reposForCwd as H,warmCheckoutIdentities as K}from"../../../core/graph/repo-sync/repos.js";import{renameProfileObject as U}from"../../../core/graph/objects.js";import{usage as d}from"../../../core/errors.js";import{ApiError as p}from"../../../api/errors.js";import{scopeAllowed as I}from"../../../core/scopes.js";import{validateEnvVarName as W}from"../../../core/env-name.js";import{listProfileEnvNames as J,removeProfileEnvVar as Y,setProfileEnvVar as z}from"../../../core/profiles/env-store.js";import{isDeploymentName as Q,listAppEnvNames as X,removeAppEnvVar as Z,setAppEnvVar as x}from"../../../core/profiles/app-env-store.js";import{addProfileProject as ee,addProfileRepo as te,assertDeliveryLimits as ae,setProfileDeliveryLimit as _,assertProfileProjects as b,createProfile as P,ensureRootProfile as re,listProfiles as u,loadProfileManifest as E,pauseProfile as ie,removeProfileProject as ne,renameProfile as oe,resumeProfile as se,setProfileDefaultKind as de,updateProfileMetadata as pe}from"../../../core/profiles/manifest.js";import{requestProfileDeletion as fe}from"../../profile-delete.js";import{brokerSignalBus as le}from"../../broker-signals/bus.js";import{toProfileDTO as me}from"../map.js";import{isCloudRole as ue,personId as ce}from"../../../core/canvas/person-state.js";import{resolveRecipeRepositories as we,repositoriesByProfile as T}from"../../../core/environment-repos.js";import{machineEnvironmentId as he}from"../../../core/environments.js";import{actsAsPerson as g,appOf as j,resolvedScopes as ve}from"../router.js";const A="root",ye=4096;function h(t,e=[]){return{...me(t),environment_id:t.manifest.environment_id??he(),repositories:e}}o(h,"toProfileDTO");async function l(t){return h(t,(await T()).get(t.profileId)??[])}o(l,"toProfileDTOWithRepositories");function c(t){return j(t.principal)??"app:terminal"}o(c,"callerApp");function k(t,e,r=null){if(u().some(a=>a.manifest.name===e&&a.profileId!==r&&(a.manifest.grantee??"app:terminal")===t))throw new p(400,"invalid_request",`${t} already has a profile named ${e}`)}o(k,"assertNameFree");async function m(t,e){const r=await q(t,e),a=r.manifest.grantee??"app:terminal";if(t.principal.class!=="person"&&!g(t.principal)&&a!==j(t.principal))throw new p(403,"permission_error",`profile ${r.profileId} belongs to ${a}; only that app changes it`);return r}o(m,"requireOwnProfile");async function _e(t){const e=t.body??{};if(typeof e.name!="string"||e.name.trim()==="")throw d("a profile name is required",{field:"name"});e.projects!==void 0&&b(e.projects);const r=c(t),a=e.name.trim();k(r,a),e.default_kind!==void 0&&await v(e.default_kind,process.cwd(),null);const i=e.repositories??[];if(!Array.isArray(i)||i.some(f=>typeof f!="string"))throw d("repositories must be an array of owner/name strings",{field:"repositories"});if(i.length===0){const f=await P(a,e.projects??[],{defaultKind:e.default_kind,metadata:e.metadata,grantee:r});return{status:201,body:h(f)}}if(!ue())throw new p(400,"invalid_request","repositories make a cloud dev profile; this role runs profiles on the machine, so use a project directory instead");if(e.projects!==void 0&&e.projects.length>0)throw new p(400,"invalid_request","a profile with repositories stores no project paths; pass repositories or projects, not both");const n=await we(ce(),i),s=await P(a,[],{defaultKind:e.default_kind,metadata:e.metadata,grantee:r,memoryMb:ye,recipe:{repositories:n,setup_script:null,pi_packages:null}});return{status:201,body:await l(s)}}o(_e,"handleCreate");async function be(t,e){const r=e.trim();if(r==="")throw d("profile name must not be empty");return await w(async a=>(await U(a,t,r),await oe(t,r)))}o(be,"renameProfileAndHandle");async function Pe(t,e,r){await K(r);const i=(await w(async n=>await H(n,r)))[0];await ee(t,r,i?.id),i!==void 0&&e[i.name]===void 0&&e[`repo:${i.name}`]===void 0&&await _(t,i.name,"preview")}o(Pe,"addProjectWithDefaultLimit");async function Ee(t,e,r,a){const i=await w(async n=>{const s=await C(n,t);for(const f of await G(n,a,"repo"))if(await B(n,s,f))return f;return null});if(i===null)throw new p(404,"not_found",`no repo you can read is named ${a}`);await te(e,i.id),r[i.name]===void 0&&r[`repo:${i.name}`]===void 0&&await _(e,i.name,"preview")}o(Ee,"addRepoWithDefaultLimit");async function ge(t){const{profileId:e,manifest:r}=await m(t,t.params.name),a=t.body??{};if(a.name!==void 0&&k(r.grantee??"app:terminal",a.name.trim(),e),a.default_kind!==void 0&&await v(a.default_kind,process.cwd(),e),a.add_project!==void 0&&(b([a.add_project]),a.add_project.path===void 0==(a.add_project.repo===void 0)))throw d("add_project takes exactly one of path and repo",{field:"add_project"});return a.set_delivery_limit!==void 0&&ae({[a.set_delivery_limit.owner]:a.set_delivery_limit.level}),a.name!==void 0&&await be(e,a.name),a.default_kind!==void 0&&await de(e,a.default_kind),a.add_project?.path!==void 0?await Pe(e,r.delivery_limits??{},a.add_project.path):a.add_project?.repo!==void 0&&await Ee(t,e,r.delivery_limits??{},a.add_project.repo),a.set_delivery_limit!==void 0&&await _(e,a.set_delivery_limit.owner,a.set_delivery_limit.level),a.remove_project!==void 0&&await ne(e,a.remove_project),{status:200,body:await l(E(e))}}o(ge,"handleUpdate");async function je(t){const{profileId:e}=await m(t,t.params.name);return{status:200,body:{profile_id:e,names:await J(e)}}}o(je,"handleEnvList");function D(t){const e=t.params.var,r=W(e);if(!r.isValid)throw d(`invalid env var name: ${r.errors.join("; ")}`,{field:"name",received:e});return e}o(D,"requireEnvVarName");function O(t){const e=D(t);if(Q(e)&&!g(t.principal))throw new p(403,"permission_error",`${e} is deployment-wide; only a person changes it`);return e}o(O,"requireSelfEnvVarName");async function De(t){const{profileId:e}=await m(t,t.params.name),r=D(t),{value:a}=t.body??{};if(typeof a!="string"||a==="")throw d("a non-empty env value is required",{field:"value"});return{status:200,body:{profile_id:e,changed:await z(e,r,a)}}}o(De,"handleEnvSet");async function Ie(t){const{profileId:e}=await m(t,t.params.name),r=D(t);return{status:200,body:{profile_id:e,changed:await Y(e,r)}}}o(Ie,"handleEnvRemove");async function Te(t){const e=t.params.name,r=t.body??{};r.projects!==void 0&&b(r.projects);const a=c(t);if(e===A&&a==="app:terminal")return{status:200,body:await l(await re())};if(e===A)throw new p(403,"permission_error","root belongs to the terminal app");const i=u().find(s=>s.manifest.name===e&&(s.manifest.grantee??"app:terminal")===a);if(i!==void 0)return{status:200,body:await l(i)};r.default_kind!==void 0&&await v(r.default_kind,process.cwd(),null);const n=await P(e,r.projects??[],{defaultKind:r.default_kind,metadata:r.metadata,grantee:a});return{status:200,body:h(n)}}o(Te,"handleEnsure");async function Ae(t){const e=await m(t,t.params.name),r=t.body??{};if(typeof r!="object"||r===null||Array.isArray(r))throw d("profile metadata body must be an object",{field:"body"});const a=r,i=a.unset===void 0?[]:a.unset;if(!Array.isArray(i)||i.some(f=>typeof f!="string"))throw d("profile metadata `unset` must be an array of strings",{field:"unset"});const n=a.set===void 0?{}:a.set,s=await pe(e.profileId,n,i);return{status:200,body:await l(s)}}o(Ae,"handleSetMetadata");async function ke(t){const e=E(t.params.name),r=await ie(e.profileId),a=(await y(e.profileId)).filter(n=>n.status==="active"||n.status==="idle");if(a.length===0)return{status:200,body:{profile_id:e.profileId,paused_at:r.manifest.paused_at}};const i=S();for(const n of a){const s=i.get(n.node_id);if(s!==void 0){await i.interruptForProfilePause(n.node_id,s.pid);continue}n.pi_pid!=null&&V(n.pi_pid,n.pi_pid_identity)==="alive"&&await i.interruptForProfilePause(n.node_id,n.pi_pid)}return{status:200,body:{profile_id:e.profileId,paused_at:r.manifest.paused_at}}}o(ke,"handlePause");async function Oe(t){const e=E(t.params.name),r=await se(e.profileId);for(const a of await y(e.profileId))(a.status==="active"||a.status==="idle"||await $(a.node_id)!==null)&&le.markMail(a.node_id);if(r.pausedAt!==null){const a=Date.parse(r.pausedAt);if(!Number.isNaN(a)){const i=Math.max(0,Date.now()-a);await M(e.profileId,i);for(const n of await y(e.profileId))n.status!=="dead"&&await w(s=>F(s,n.node_id,i))}}return{status:200,body:{profile_id:e.profileId,paused_at:r.manifest.paused_at}}}o(Oe,"handleResume");async function R(t){const e=t.principal;if(g(e))return u();if(e.class==="person"&&e.sub!==void 0){const a=await N(),i=new Set((await a.prepare("SELECT id FROM profiles WHERE person = ?").all(e.sub)).map(n=>n.id));return u().filter(({profileId:n})=>i.has(n))}const r=await ve(e);return u().filter(({profileId:a,manifest:i})=>{const n=i.grantee??"app:terminal";if(n===j(e))return!0;const s=`crtr:memory:rw:${n}:profile:${a}`;return I(r,s)&&(e.class!=="broker"||I(e.scopes,s))})}o(R,"visibleProfiles");async function q(t,e){const r=await R(t),a=r.find(({profileId:n})=>n===e),i=a?[a]:r.filter(({manifest:n})=>n.name===e);if(i.length===0)throw new p(404,"not_found","profile not found");if(i.length>1)throw new p(400,"ambiguous","profile name matches multiple visible profiles; use an exact id");return i[0]}o(q,"requireUsableProfile");async function Re(t){const e=await T();return{status:200,body:(await R(t)).map(r=>h(r,e.get(r.profileId)??[]))}}o(Re,"handleList");async function qe(t){return{status:200,body:await l(await q(t,t.params.name))}}o(qe,"handleGet");async function Le(t){return fe((await m(t,t.params.name)).profileId,t.body)}o(Le,"handleDelete");const dt=[{method:"GET",pattern:"/v1/apps/self/env",handler:o(async t=>({status:200,body:{names:await X(c(t))}}),"handler")},{method:"PUT",pattern:"/v1/apps/self/env/:var",handler:o(async t=>{const e=O(t),{value:r}=t.body??{};if(typeof r!="string"||!r)throw d("a non-empty env value is required",{field:"value"});return{status:200,body:{changed:await x(c(t),e,r)}}},"handler")},{method:"DELETE",pattern:"/v1/apps/self/env/:var",handler:o(async t=>({status:200,body:{changed:await Z(c(t),O(t))}}),"handler")},{method:"PUT",pattern:"/v1/profiles/:name",handler:Te},{method:"POST",pattern:"/v1/profiles/:name/pause",ownerOnly:!0,handler:ke},{method:"POST",pattern:"/v1/profiles/:name/resume",ownerOnly:!0,handler:Oe},{method:"PATCH",pattern:"/v1/profiles/:name/metadata",handler:Ae},{method:"POST",pattern:"/v1/profiles",handler:_e},{method:"PATCH",pattern:"/v1/profiles/:name",handler:ge},{method:"GET",pattern:"/v1/profiles/:name/env",handler:je},{method:"PUT",pattern:"/v1/profiles/:name/env/:var",handler:De},{method:"DELETE",pattern:"/v1/profiles/:name/env/:var",handler:Ie},{method:"DELETE",pattern:"/v1/profiles/:name",handler:Le},{method:"GET",pattern:"/v1/profiles",handler:Re},{method:"GET",pattern:"/v1/profiles/:name",handler:qe}];export{Pe as addProjectWithDefaultLimit,dt as profileRoutes,be as renameProfileAndHandle,q as requireUsableProfile};
@@ -0,0 +1,2 @@
1
+ import type { RouteTable } from '../router.js';
2
+ export declare const repoImportRoutes: RouteTable;
@@ -0,0 +1,2 @@
1
+ var N=Object.defineProperty;var l=(e,o)=>N(e,"name",{value:o,configurable:!0});import{randomUUID as b}from"node:crypto";import{ApiError as s}from"../../../api/errors.js";import{withCanvasWrite as v}from"../../../core/canvas/db.js";import{parseFrontmatterGeneric as I}from"../../../core/frontmatter.js";import{importTree as L}from"../../../core/graph/repo-sync/exchange.js";import{parseDoc as D}from"../../../core/graph/repo-sync/ref-format.js";import{check as g}from"../../../core/permissions/evaluator.js";import{documentFields as O}from"../../../migrations/004-canvas-documents/fields.js";import{hashOf as R}from"../../../core/graph/bodies.js";import{renameRepoObject as k}from"../../../core/graph/objects.js";import{asApiError as $}from"./schemas.js";import{readerFor as E}from"../reader.js";const U=/^[A-Za-z0-9_-]+(\/[A-Za-z0-9_-]+)*$/;async function j(e){if(e.principal.class!=="person")throw new s(403,"forbidden","the import is run by the person");const o=e.body;if(!o||typeof o.tree!="object"||o.tree===null)throw new s(400,"invalid_request","`tree` must map file paths to text");const i=decodeURIComponent(e.params.repo);return await v(async r=>{const a=await r.prepare("SELECT * FROM objects WHERE type = 'repo' AND name = ? AND deleted_at IS NULL AND home_machine IS NULL").get(i);if(!a)throw new s(404,"not_found",`no repo named '${i}'`);const f=await E(r,e);if(!await g(r,f,"edit",a.id))throw new s(403,"forbidden",`you may not edit repo ${i}`);const u=new Map(Object.entries(o.tree)),h=new Set;for(const[t,m]of u){const n=D(t,m);n.ok&&h.add(n.doc.name)}for(const t of await r.prepare("SELECT name FROM objects WHERE type = 'document' AND owner = ?").all(a.id))h.add(t.name);const y=[],d=[];for(const t of o.legacy??[]){if(!U.test(t.name)){d.push({name:t.name,reason:"not a valid document name"});continue}if(h.has(t.name)){d.push({name:t.name,reason:"already on the ref or in the canvas"});continue}let m;try{m=I(t.text)}catch(p){d.push({name:t.name,reason:`unreadable frontmatter: ${p.message}`});continue}const n=O(m.data,m.body,{missingPrivacy:"public"});if(n.privacy!=="public"){d.push({name:t.name,reason:"private; a repo holds only public documents"});continue}const w=new Date().toISOString(),_=b(),A={id:_,name:t.name,kind:n.kind==="preference"?"preference":"knowledge",privacy:"public",preview:n.preview,summary:n.summary,why_it_exists:n.whyItExists,unlisted:n.unlisted,lint_ignore:n.lintIgnore,extensions:n.extensions,created_at:w,deleted_at:null,rules:n.rules.map((p,S)=>({position:S,on:p.on,match:p.match??null,match_frontmatter:p.matchFrontmatter??null,if:p.if??null,deliver:p.deliver})),revisions:[{rev_id:b(),number:1,parents:[],body:m.body,body_hash:R(m.body),author:null,rationale:"imported from legacy files",created_at:w,links:[]}]};u.set(`docs/${_}.json`,`${JSON.stringify(A)}
2
+ `),y.push(t.name)}const c=await L(r,a,new Map,u);return{repo:a.id,created:c.created,revisions:c.revisions,deleted:c.deleted,needs_merge:c.needsMerge,refused:c.refused,legacy_imported:y,legacy_skipped:d}})}l(j,"run");async function F(e){if(e.principal.class!=="person")throw new s(403,"forbidden","the rename is run by the person");const o=e.body?.to;if(typeof o!="string"||!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(o))throw new s(400,"invalid_request","`to` must be a handle");const i=decodeURIComponent(e.params.repo);try{return await v(async r=>{const a=await r.prepare("SELECT * FROM objects WHERE type = 'repo' AND name = ? AND deleted_at IS NULL AND home_machine IS NULL").get(i);if(!a)throw new s(404,"not_found",`no repo named '${i}'`);if(!await g(r,await E(r,e),"share",a.id))throw new s(403,"forbidden",`only the owner of repo ${i} may rename it`);const f=await k(r,i,o);return{id:a.id,name:o,renamed:f}})}catch(r){throw $(r)}}l(F,"rename");const K=[{method:"POST",pattern:"/v1/repos/:repo/rename",handler:l(async e=>({status:200,body:await F(e)}),"handler")},{method:"POST",pattern:"/v1/repos/:repo/import",maxBodyBytes:256*1024*1024,handler:l(async e=>({status:200,body:await j(e)}),"handler")}];export{K as repoImportRoutes};