@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
@@ -0,0 +1,1154 @@
1
+ import { envProfileId } from '../shared/env.js';
2
+ import { basename, join } from 'node:path';
3
+ import { existsSync, mkdirSync, statSync } from 'node:fs';
4
+ import { isDeepStrictEqual } from 'node:util';
5
+ import { CONFIG_FILE, STATE_FILE, CONDENSED_HISTORY_MODES, VERBOSITY_LEVELS, MOUSE_MODE_DEFAULTS, WHIP_MESSAGE_MODES, DEFAULT_WHIP_MESSAGES, defaultScopeConfig, defaultScopeState, defaultModelLaddersConfig, defaultKindsConfig, defaultRemoteCanvasConfig } from '../types.js';
6
+ import { BINDING_CATALOG, BINDING_IDS, isAttachPaneBinding } from './keybindings/catalog.js';
7
+ import { notFound } from './errors.js';
8
+ import { emitEvent } from './events/emit.js';
9
+ import { LEDGER_ENV } from './ledger/rates.js';
10
+ import { atomicWriteJson, readJsonIfExists, ensureDir } from './fs-utils.js';
11
+ import { scopeRoot, requireScopeRoot, findProjectScopeRoots, userScopeRoot } from './scope.js';
12
+ import { listInstalledPluginsInRoot } from './installed-plugins.js';
13
+ import { profileDir, listProfiles } from './profiles/manifest.js';
14
+ import { canonicalRoot } from './scoped-state/paths.js';
15
+ import { readCachedSettings, readCachedState, revisionOf, SettingsRevisionConflictError, writeSettings } from './scoped-state/person-store.js';
16
+ import { withExclusiveDirectoryLock } from './exclusive-lock.js';
17
+ import { SCOPE_CONFIG_KEYS } from './user-settings.js';
18
+ import { normalizeWorkingGerunds } from '../shared/working-activity.js';
19
+ import { mergePageComponentLayers, normalizePageComponents } from './human/page-catalog.js';
20
+ function configPathFor(root) {
21
+ return join(root, CONFIG_FILE);
22
+ }
23
+ function withConfigPathLock(path, run) {
24
+ // A project config write must fail if its root was removed, not recreate it.
25
+ return withExclusiveDirectoryLock(`${path}.lock`, () => run(path), { timeoutError: () => new Error(`timed out waiting for config lock: ${path}`) });
26
+ }
27
+ function statePathFor(root) {
28
+ return join(root, STATE_FILE);
29
+ }
30
+ export function configPath(scope) {
31
+ const root = scopeRoot(scope);
32
+ return root ? configPathFor(root) : null;
33
+ }
34
+ export function statePath(scope) {
35
+ const root = scopeRoot(scope);
36
+ return root ? statePathFor(root) : null;
37
+ }
38
+ function settingsOwnerForRoot(root) {
39
+ const canonical = canonicalRoot(root);
40
+ const userRoot = canonicalRoot(userScopeRoot());
41
+ if (canonical === userRoot)
42
+ return { key: 'user', kind: 'user', root: userRoot };
43
+ if (basename(canonical) === '.crouter')
44
+ return { key: 'project', kind: 'project', root: canonical };
45
+ for (const profile of listProfiles()) {
46
+ const profilePath = canonicalRoot(profileDir(profile.profileId));
47
+ if (canonical === profilePath)
48
+ return { key: `profile:${profile.profileId}`, kind: 'profile', root: profilePath, profileId: profile.profileId };
49
+ }
50
+ throw new Error(`settings root is not a recognized owner: ${root}`);
51
+ }
52
+ function readRawAtRoot(root) {
53
+ // Project configuration is a file; reading it must not touch the person's rows (or its lock directory) after the project disappears.
54
+ if (basename(root) === '.crouter') {
55
+ let canonical;
56
+ try {
57
+ canonical = canonicalRoot(root);
58
+ }
59
+ catch (error) {
60
+ if (error.code === 'ENOENT')
61
+ return null;
62
+ throw error;
63
+ }
64
+ if (canonical !== canonicalRoot(userScopeRoot()))
65
+ return readJsonIfExists(configPathFor(root));
66
+ }
67
+ return readCachedSettings(settingsOwnerForRoot(root).key).settings;
68
+ }
69
+ /** Replace a user or profile owner's settings through the one write algorithm: `compute` runs against the cached raw settings and
70
+ * runs again if the rows changed underneath it. */
71
+ async function mutatePersonSettings(key, mutate) {
72
+ let value;
73
+ await writeSettings((snapshot) => {
74
+ const current = snapshot.settings[key];
75
+ const result = mutate(structuredClone(current ?? {}));
76
+ value = result.value;
77
+ return [{ op: 'settings.replace', owner: key, raw: result.next, ifRevision: revisionOf(current) }];
78
+ });
79
+ return value;
80
+ }
81
+ async function writeRawAtRoot(root, raw) {
82
+ const owner = settingsOwnerForRoot(root);
83
+ if (owner.kind === 'project') {
84
+ withConfigPathLock(configPathFor(owner.root), (path) => atomicWriteJson(path, raw, { createParent: false }));
85
+ return;
86
+ }
87
+ await mutatePersonSettings(owner.key, () => ({ value: undefined, next: raw }));
88
+ }
89
+ async function mutateRawAtRoot(root, mutate) {
90
+ const owner = settingsOwnerForRoot(root);
91
+ if (owner.kind === 'project')
92
+ return withConfigPathLock(configPathFor(owner.root), (path) => { const result = mutate(readJsonIfExists(path) ?? {}); atomicWriteJson(path, result.next, { createParent: false }); return result.value; });
93
+ return await mutatePersonSettings(owner.key, mutate);
94
+ }
95
+ const brokerSnapshotState = globalThis;
96
+ const brokerSnapshotKey = Symbol.for('crtr.broker.config-snapshot');
97
+ export function installBrokerConfigSnapshot(snapshot) {
98
+ brokerSnapshotState[brokerSnapshotKey] = snapshot;
99
+ }
100
+ export function brokerConfigSnapshot() {
101
+ return brokerSnapshotState[brokerSnapshotKey];
102
+ }
103
+ export function readConfig(scope) {
104
+ const snapshot = brokerSnapshotState[brokerSnapshotKey];
105
+ if (snapshot) {
106
+ if (scope !== 'user')
107
+ throw new Error(`broker config snapshot has no ${scope} scope`);
108
+ return snapshot.user;
109
+ }
110
+ const root = scopeRoot(scope);
111
+ return root ? readConfigAtRoot(root) : defaultScopeConfig();
112
+ }
113
+ export function readConfigAtRoot(root) { const existing = readRawAtRoot(root); return existing ? mergeConfig(existing) : defaultScopeConfig(); }
114
+ function readProjectState(root) {
115
+ const raw = readJsonIfExists(statePathFor(root));
116
+ return { marketplaces: raw?.marketplaces ?? {}, plugins: raw?.plugins ?? {}, activeCanvas: raw?.activeCanvas ?? null, ...(raw?.last_self_check === undefined ? {} : { last_self_check: raw.last_self_check }) };
117
+ }
118
+ export function readState(scope) {
119
+ const root = scopeRoot(scope);
120
+ if (!root)
121
+ return defaultScopeState();
122
+ if (scope === 'project')
123
+ return existsSync(root) ? readProjectState(root) : defaultScopeState();
124
+ return readCachedState(settingsOwnerForRoot(root).key);
125
+ }
126
+ export class InvalidRawSettingsError extends Error {
127
+ constructor(cause) {
128
+ super(`settings cannot be merged: ${cause instanceof Error ? cause.message : String(cause)}`);
129
+ this.name = 'InvalidRawSettingsError';
130
+ }
131
+ }
132
+ function rawSettingsKeyForTarget(target) {
133
+ if (target.scope === 'user')
134
+ return 'user';
135
+ if (!listProfiles().some((profile) => profile.profileId === target.profileId)) {
136
+ throw notFound(`profile not found: ${target.profileId}`, { received: target.profileId, next: 'Run `crtr profile list` to see available profiles.' });
137
+ }
138
+ return `profile:${target.profileId}`;
139
+ }
140
+ export function readRawSettingsForTarget(target) {
141
+ return readCachedSettings(rawSettingsKeyForTarget(target));
142
+ }
143
+ export async function replaceRawSettingsForTarget(target, next, ifRevision) {
144
+ const key = rawSettingsKeyForTarget(target);
145
+ try {
146
+ mergeConfig(next);
147
+ }
148
+ catch (error) {
149
+ throw new InvalidRawSettingsError(error);
150
+ }
151
+ const before = readCachedSettings(key);
152
+ if (before.revision !== ifRevision)
153
+ throw new SettingsRevisionConflictError();
154
+ const after = await writeSettings((snapshot) => (revisionOf(snapshot.settings[key]) === ifRevision
155
+ ? [{ op: 'settings.replace', owner: key, raw: next, ifRevision }] : (() => { throw new SettingsRevisionConflictError(); })()));
156
+ const revision = revisionOf(after.settings[key]);
157
+ return { revision, changed: revision !== ifRevision };
158
+ }
159
+ export async function updateRawConfigAtomically(scope, mutate) { const root = requireScopeRoot(scope); return await mutateRawAtRoot(root, (latest) => { const next = mutate(latest); return { value: next, next }; }); }
160
+ export async function writeConfig(scope, config) { await writeRawAtRoot(requireScopeRoot(scope), config); }
161
+ export async function writeRawConfig(scope, config) { await writeRawAtRoot(requireScopeRoot(scope), config); }
162
+ function writeProjectState(root, state) { withConfigPathLock(statePathFor(root), (path) => atomicWriteJson(path, state, { createParent: false })); }
163
+ export async function writeState(scope, state) {
164
+ const root = requireScopeRoot(scope);
165
+ if (scope === 'project') {
166
+ writeProjectState(root, state);
167
+ return;
168
+ }
169
+ const key = settingsOwnerForRoot(root).key;
170
+ await writeSettings(() => [{ op: 'state.write', owner: key, state }]);
171
+ }
172
+ /** A project scope is a directory holding `config.json`; the user and profile scopes are the person's rows and need no directory setup. */
173
+ export async function ensureScopeInitialized(scope, root) {
174
+ if (scope !== 'project') {
175
+ ensureDir(root);
176
+ return;
177
+ }
178
+ try {
179
+ mkdirSync(root);
180
+ }
181
+ catch (error) {
182
+ if (error.code !== 'EEXIST' || !statSync(root).isDirectory())
183
+ throw error;
184
+ }
185
+ // A project config holds only what the project overrides. Seeding it with the full default document would make every default
186
+ // (kinds, display toggles, auto_update) a project-level override that silently shadows the user's own settings for every
187
+ // directory beneath it — reads default-fill missing keys from the running build, so a sparse file loses nothing.
188
+ if (readJsonIfExists(configPathFor(root)) === null)
189
+ await writeRawAtRoot(root, { schema_version: defaultScopeConfig().schema_version });
190
+ }
191
+ function normalizeKeybindings(raw) {
192
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
193
+ return {};
194
+ const out = {};
195
+ for (const [id, gestures] of Object.entries(raw)) {
196
+ if (Array.isArray(gestures) && gestures.every((gesture) => typeof gesture === 'string')) {
197
+ out[id] = [...gestures];
198
+ }
199
+ }
200
+ return out;
201
+ }
202
+ const ATTACH_PANE_BINDING_IDS = new Set(BINDING_CATALOG.filter(isAttachPaneBinding).map((definition) => definition.id));
203
+ /** Normalize the user-owned list of attach actions allowed to bridge through an
204
+ * occupied tmux root binding. Unknown and non-attach ids have no effect. */
205
+ export function normalizeTmuxPassthrough(raw) {
206
+ if (!Array.isArray(raw))
207
+ return [];
208
+ return [...new Set(raw.filter((id) => typeof id === 'string' && BINDING_IDS.has(id) && ATTACH_PANE_BINDING_IDS.has(id)))];
209
+ }
210
+ function mergeModelLadders(raw, base = defaultModelLaddersConfig()) {
211
+ const defaults = base;
212
+ if (raw === null || typeof raw !== 'object')
213
+ return defaults;
214
+ const r = raw;
215
+ const out = {
216
+ anthropic: { ...defaults.anthropic },
217
+ openai: { ...defaults.openai },
218
+ ...(defaults.defaultProvider !== undefined ? { defaultProvider: defaults.defaultProvider } : {}),
219
+ };
220
+ if (r.defaultProvider === 'anthropic' || r.defaultProvider === 'openai') {
221
+ out.defaultProvider = r.defaultProvider;
222
+ }
223
+ for (const provider of ['anthropic', 'openai']) {
224
+ const over = r[provider];
225
+ if (over === null || typeof over !== 'object')
226
+ continue;
227
+ for (const [strength, value] of Object.entries(over)) {
228
+ if ((strength === 'ultra' || strength === 'strong' || strength === 'medium' || strength === 'light') && typeof value === 'string') {
229
+ out[provider][strength] = value;
230
+ }
231
+ }
232
+ }
233
+ return out;
234
+ }
235
+ function validStrength(value) {
236
+ return value === 'ultra' || value === 'strong' || value === 'medium' || value === 'light';
237
+ }
238
+ const MODEL_STRENGTHS = ['ultra', 'strong', 'medium', 'light'];
239
+ function routeRecord() {
240
+ return Object.create(null);
241
+ }
242
+ function setRouteRecord(record, routeId, value) {
243
+ Object.defineProperty(record, routeId, { value, writable: true, enumerable: true, configurable: true });
244
+ }
245
+ function copyRouteRecord(record) {
246
+ const copy = routeRecord();
247
+ for (const [routeId, value] of Object.entries(record ?? {}))
248
+ setRouteRecord(copy, routeId, value);
249
+ return copy;
250
+ }
251
+ function routeInvalid(routeId, rule) {
252
+ emitEvent({ level: 'warn', event: 'config.model_routes.invalid', fields: { route_id: routeId, rule } });
253
+ }
254
+ /** Overlay raw route patches first so a higher scope may replace one cell of a
255
+ * complete lower route. Completeness belongs to the resulting effective route,
256
+ * never an individual raw scope patch. */
257
+ function mergeModelRoutePatches(raw, base = {}) {
258
+ const out = copyRouteRecord(base);
259
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
260
+ return out;
261
+ for (const [routeId, value] of Object.entries(raw)) {
262
+ if (routeId.trim() === '') {
263
+ routeInvalid(routeId, 'route id must be a non-empty string');
264
+ continue;
265
+ }
266
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
267
+ routeInvalid(routeId, 'route must be an object');
268
+ continue;
269
+ }
270
+ const patch = value;
271
+ const current = out[routeId];
272
+ const route = { ...current };
273
+ let rule;
274
+ for (const field of ['family', 'credentialSource', 'providerId']) {
275
+ const candidate = patch[field];
276
+ if (candidate === undefined)
277
+ continue;
278
+ if (typeof candidate !== 'string' || candidate.trim() === '') {
279
+ rule = `${field} must be a non-empty string`;
280
+ break;
281
+ }
282
+ route[field] = candidate;
283
+ }
284
+ if (rule === undefined && patch.models !== undefined) {
285
+ if (patch.models === null || typeof patch.models !== 'object' || Array.isArray(patch.models))
286
+ rule = 'models must be an object';
287
+ else {
288
+ const models = { ...current?.models };
289
+ for (const [strength, spec] of Object.entries(patch.models)) {
290
+ if (!validStrength(strength)) {
291
+ rule = `models.${strength} is not a model strength`;
292
+ break;
293
+ }
294
+ if (typeof spec !== 'string' || spec.trim() === '') {
295
+ rule = `models.${strength} must be a non-empty provider/id ref`;
296
+ break;
297
+ }
298
+ const slash = spec.indexOf('/');
299
+ if (slash <= 0 || slash === spec.length - 1) {
300
+ rule = `models.${strength} must be provider/id`;
301
+ break;
302
+ }
303
+ models[strength] = spec;
304
+ }
305
+ route.models = models;
306
+ }
307
+ }
308
+ if (rule === undefined && route.models !== undefined && route.providerId !== undefined) {
309
+ for (const [strength, spec] of Object.entries(route.models)) {
310
+ if (spec.slice(0, spec.indexOf('/')) !== route.providerId) {
311
+ rule = `models.${strength} provider prefix must equal providerId`;
312
+ break;
313
+ }
314
+ }
315
+ }
316
+ if (rule !== undefined) {
317
+ routeInvalid(routeId, rule);
318
+ continue;
319
+ }
320
+ setRouteRecord(out, routeId, route);
321
+ }
322
+ return out;
323
+ }
324
+ /** Resolve complete routes after every scope has overlaid its sparse raw patch.
325
+ * Sparse standalone routes are read for one compatibility release only: they
326
+ * retain their historical candidate behavior, emit a repair warning, and never
327
+ * gain invented cells. New writes cannot create them. */
328
+ function resolveModelRoutes(routes) {
329
+ const complete = routeRecord();
330
+ const legacy = routeRecord();
331
+ for (const [routeId, route] of Object.entries(routes)) {
332
+ if (route.family === undefined || route.credentialSource === undefined || route.providerId === undefined || route.models === undefined) {
333
+ routeInvalid(routeId, 'route must include family, credentialSource, providerId, and models');
334
+ continue;
335
+ }
336
+ const missing = MODEL_STRENGTHS.filter((strength) => route.models[strength] === undefined);
337
+ if (missing.length > 0) {
338
+ routeInvalid(routeId, `incomplete route; missing strengths: ${missing.join(', ')}`);
339
+ setRouteRecord(legacy, routeId, { family: route.family, credentialSource: route.credentialSource, providerId: route.providerId, models: route.models });
340
+ continue;
341
+ }
342
+ setRouteRecord(complete, routeId, {
343
+ family: route.family,
344
+ credentialSource: route.credentialSource,
345
+ providerId: route.providerId,
346
+ models: route.models,
347
+ });
348
+ }
349
+ return { complete, legacy };
350
+ }
351
+ function assertCompleteModelRoute(routeId, route) {
352
+ if (routeId.trim() === '')
353
+ throw new Error('model route id must be a non-empty string');
354
+ for (const field of ['family', 'credentialSource', 'providerId']) {
355
+ if (typeof route[field] !== 'string' || route[field].trim() === '')
356
+ throw new Error(`model route "${routeId}" ${field} must be a non-empty string`);
357
+ }
358
+ const missing = MODEL_STRENGTHS.filter((strength) => route.models?.[strength] === undefined);
359
+ if (missing.length > 0)
360
+ throw new Error(`model route "${routeId}" is incomplete; missing strengths: ${missing.join(', ')}`);
361
+ for (const strength of MODEL_STRENGTHS) {
362
+ const spec = route.models[strength];
363
+ if (typeof spec !== 'string' || spec.trim() === '')
364
+ throw new Error(`model route "${routeId}" models.${strength} must be a non-empty provider/id ref`);
365
+ const slash = spec.indexOf('/');
366
+ if (slash <= 0 || slash === spec.length - 1)
367
+ throw new Error(`model route "${routeId}" models.${strength} must be provider/id`);
368
+ if (spec.slice(0, slash) !== route.providerId)
369
+ throw new Error(`model route "${routeId}" models.${strength} provider prefix must equal providerId`);
370
+ }
371
+ }
372
+ function mergeModelRouting(raw, base) {
373
+ if (raw === undefined)
374
+ return base;
375
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
376
+ return base;
377
+ const value = raw;
378
+ const strings = (items) => Array.isArray(items) && items.every((item) => typeof item === 'string' && item.trim() !== '') ? [...items] : undefined;
379
+ const strengths = Array.isArray(value.strengthFallback) && value.strengthFallback.every((item) => validStrength(item)) ? [...value.strengthFallback] : undefined;
380
+ return {
381
+ ...(strings(value.credentialSourceOrder) !== undefined ? { credentialSourceOrder: strings(value.credentialSourceOrder) } : {}),
382
+ ...(strings(value.familyOrder) !== undefined ? { familyOrder: strings(value.familyOrder) } : {}),
383
+ ...(strengths !== undefined ? { strengthFallback: strengths } : {}),
384
+ };
385
+ }
386
+ /** True when `pattern` (a `spawnEnv.allow` entry) matches EVERY possible env
387
+ * var name — a bare `*`, or any run of nothing but `*` characters (`**`,
388
+ * `***`, …). This is the one glob shape that reopens the inherit-all hole
389
+ * the whole spawn-env boundary exists to close, so it is rejected loud
390
+ * rather than silently treated as literal or silently dropped (per
391
+ * `cto-rejects-fallback-hedges`: fix the config, don't hedge around it). */
392
+ function isInheritAllGlob(pattern) {
393
+ return pattern !== '' && pattern.replace(/\*/g, '') === '';
394
+ }
395
+ /** Merge a raw `spawnEnv.allow` list over `base` (defaulting to empty):
396
+ * additive/union, not override — each scope only ADDS a name/glob it
397
+ * explicitly admits across the broker spawn-env boundary (`buildBrokerEnv`),
398
+ * never removes a lower-precedence scope's entry. Non-string entries are
399
+ * dropped, never thrown, mirroring `mergeKinds`/`mergeModelLadders` — but an
400
+ * inherit-all glob (`isInheritAllGlob`) throws immediately at config read: it
401
+ * is not a shape any legitimate entry can mean, and silently accepting or
402
+ * dropping it would either reopen the leak or hide a config mistake. */
403
+ function mergeSpawnEnv(raw, base = []) {
404
+ const r = raw;
405
+ const extra = Array.isArray(r?.allow) ? r.allow.filter((v) => typeof v === 'string') : [];
406
+ for (const pattern of extra) {
407
+ if (isInheritAllGlob(pattern)) {
408
+ throw new Error(`spawnEnv.allow: "${pattern}" matches every env var name (inherit-all) — this is exactly the leak the spawn-env boundary closes. Name the specific vars/prefixes you actually need instead (e.g. "AWS_*", "GIT_ASKPASS").`);
409
+ }
410
+ }
411
+ return { allow: [...new Set([...base, ...extra])] };
412
+ }
413
+ /** Per-provider options, merged SHALLOWLY per provider id so a nearer scope
414
+ * that sets one option does not erase a sibling option from a farther scope. */
415
+ function mergeProviderOptions(raw, base = {}) {
416
+ const merged = {};
417
+ for (const [providerId, options] of Object.entries(base))
418
+ merged[providerId] = { ...options };
419
+ if (raw !== null && typeof raw === 'object') {
420
+ for (const [providerId, options] of Object.entries(raw)) {
421
+ if (options === null || typeof options !== 'object')
422
+ continue;
423
+ const next = { ...merged[providerId] };
424
+ const fastMode = options.fastMode;
425
+ if (typeof fastMode === 'boolean')
426
+ next.fastMode = fastMode;
427
+ merged[providerId] = next;
428
+ }
429
+ }
430
+ return merged;
431
+ }
432
+ /** The one bare-command-name rule, shared by the read path (`normalizeBin`)
433
+ * and the strict install gate (`invalidPluginBinReasons`): a name a shell can
434
+ * invoke verbatim and a filesystem can hold as a single symlink entry — no
435
+ * separator, no leading dot, no whitespace, no quoting ever required. */
436
+ const BIN_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
437
+ /** Bare names crouter owns on every node's PATH. A contribution may not take
438
+ * one: shadowing the CLI a node drives its own canvas with breaks the runtime
439
+ * contract rather than extending it. */
440
+ const RESERVED_BIN_NAMES = new Set(['crtr', 'crtrd']);
441
+ /** The one bare-command-name validator shared by `bin` and plugin `requires`.
442
+ * `bin` alone reserves crouter's own commands; a plugin may require any safe
443
+ * executable name because it does not contribute or shadow that command. */
444
+ function bareCommandNameIssue(name, field) {
445
+ if (field === 'bin' && RESERVED_BIN_NAMES.has(name))
446
+ return `${field}.${name} is reserved by crouter — pick another bare command name`;
447
+ if (!BIN_NAME_PATTERN.test(name))
448
+ return `${field}.${name} is not a safe bare command name (expected ${BIN_NAME_PATTERN.source})`;
449
+ return undefined;
450
+ }
451
+ /** Validate raw `bin` declaration shape without touching the filesystem.
452
+ * Install uses these findings as a hard gate for plugin manifests; scope
453
+ * resolution reports them through `crtr sys doctor` and continues. */
454
+ export function binDeclarationIssues(raw) {
455
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
456
+ return [{ name: 'bin', message: 'bin must be a JSON object mapping bare command name to a relative path' }];
457
+ }
458
+ const issues = [];
459
+ for (const [name, target] of Object.entries(raw)) {
460
+ const nameIssue = bareCommandNameIssue(name, 'bin');
461
+ if (nameIssue !== undefined)
462
+ issues.push({ name, message: nameIssue });
463
+ if (typeof target !== 'string' || target.trim() === '') {
464
+ issues.push({ name, message: `bin.${name} must be a non-empty relative path to an executable inside the contributor root` });
465
+ }
466
+ }
467
+ return issues;
468
+ }
469
+ /** Normalize one raw `bin` block (a scope `config.json`'s or a plugin
470
+ * manifest's) to name → root-relative path. Invalid entries never become
471
+ * commands; `binDeclarationIssues` keeps them visible to Doctor. */
472
+ export function normalizeBin(raw) {
473
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
474
+ return {};
475
+ const out = {};
476
+ for (const [name, target] of Object.entries(raw)) {
477
+ if (bareCommandNameIssue(name, 'bin') !== undefined)
478
+ continue;
479
+ if (typeof target !== 'string' || target.trim() === '')
480
+ continue;
481
+ out[name] = target;
482
+ }
483
+ return out;
484
+ }
485
+ const HUMAN_ACTION_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
486
+ /** Validate `humanActions` declaration shape without touching the filesystem.
487
+ * Filesystem checks happen only when resolving an action or running Doctor. */
488
+ export function humanActionDeclarationIssues(raw) {
489
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
490
+ return [{ name: 'humanActions', reason: 'humanActions must be a JSON object mapping action names to {argv, cwd}', block: true }];
491
+ }
492
+ const issues = [];
493
+ for (const [name, value] of Object.entries(raw)) {
494
+ const reasons = [];
495
+ if (!HUMAN_ACTION_NAME_PATTERN.test(name)) {
496
+ reasons.push(`action name must match ${HUMAN_ACTION_NAME_PATTERN.source}`);
497
+ }
498
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
499
+ reasons.push('action must be an object with argv and cwd');
500
+ }
501
+ else {
502
+ const action = value;
503
+ const extras = Object.keys(action).filter((key) => key !== 'argv' && key !== 'cwd');
504
+ if (extras.length > 0)
505
+ reasons.push(`action has unsupported field${extras.length === 1 ? '' : 's'}: ${extras.join(', ')}`);
506
+ if (!Array.isArray(action.argv) || action.argv.length === 0 || !action.argv.every((arg) => typeof arg === 'string' && arg.length > 0)) {
507
+ reasons.push('argv must be a non-empty array of non-empty strings');
508
+ }
509
+ if (typeof action.cwd !== 'string' || action.cwd.length === 0) {
510
+ reasons.push('cwd is required and must be a non-empty string');
511
+ }
512
+ }
513
+ if (reasons.length > 0)
514
+ issues.push({ name, reason: reasons.join('; ') });
515
+ }
516
+ return issues;
517
+ }
518
+ /** Normalize valid action declarations for scope-local config inspection.
519
+ * Invalid entries remain available through raw reads so resolution and Doctor
520
+ * can report them rather than silently treating them as absent. */
521
+ export function normalizeHumanActions(raw) {
522
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
523
+ return {};
524
+ const invalid = new Set(humanActionDeclarationIssues(raw).map((issue) => issue.name));
525
+ const out = {};
526
+ for (const [name, value] of Object.entries(raw)) {
527
+ if (invalid.has(name))
528
+ continue;
529
+ const action = value;
530
+ out[name] = { argv: [...action.argv], cwd: action.cwd };
531
+ }
532
+ return out;
533
+ }
534
+ /** STRICT install-time validation for a plugin-declared `bin` block. Target
535
+ * filesystem state is checked later by Doctor because it can change after
536
+ * install. */
537
+ export function invalidPluginBinReasons(raw) {
538
+ return binDeclarationIssues(raw).map((issue) => issue.message);
539
+ }
540
+ /** Normalize a plugin manifest's advisory executable requirements. Invalid
541
+ * declarations stay out of the read path; source installs reject them through
542
+ * `invalidPluginRequiresReasons`. */
543
+ export function normalizeRequires(raw) {
544
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
545
+ return {};
546
+ const out = {};
547
+ for (const [name, hint] of Object.entries(raw)) {
548
+ if (bareCommandNameIssue(name, 'requires') !== undefined)
549
+ continue;
550
+ if (typeof hint !== 'string' || hint.trim() === '' || /[\r\n]/.test(hint))
551
+ continue;
552
+ out[name] = hint;
553
+ }
554
+ return out;
555
+ }
556
+ /** STRICT install-time validation for a plugin's advisory `requires` block.
557
+ * A missing executable is advisory; only malformed declarations fail install. */
558
+ export function invalidPluginRequiresReasons(raw) {
559
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
560
+ return ['requires must be a JSON object mapping a bare executable name to a one-line install hint'];
561
+ }
562
+ const reasons = [];
563
+ for (const [name, hint] of Object.entries(raw)) {
564
+ const nameIssue = bareCommandNameIssue(name, 'requires');
565
+ if (nameIssue !== undefined)
566
+ reasons.push(nameIssue);
567
+ if (typeof hint !== 'string' || hint.trim() === '') {
568
+ reasons.push(`requires.${name} must be a non-empty one-line install hint`);
569
+ }
570
+ else if (/[\r\n]/.test(hint)) {
571
+ reasons.push(`requires.${name} must be a one-line install hint`);
572
+ }
573
+ }
574
+ return reasons;
575
+ }
576
+ /** Collect the valid `KindConfig` fields of one raw `kinds.<name>` entry —
577
+ * every field is optional here, `whenToUse` included; mistyped fields are
578
+ * dropped, never thrown (an invalid field in config.json must not break
579
+ * config parsing for every other kind — the loud gate is install time, see
580
+ * `invalidPluginKindsReasons`). Returns null when no valid field is present.
581
+ * Whether `whenToUse` is REQUIRED is `mergeKinds`'s call: only an entry that
582
+ * introduces a kind no lower layer defines needs one. */
583
+ function normalizeKindFields(raw) {
584
+ if (raw === null || typeof raw !== 'object')
585
+ return null;
586
+ const r = raw;
587
+ const out = {};
588
+ if (typeof r.whenToUse === 'string' && r.whenToUse.trim() !== '')
589
+ out.whenToUse = r.whenToUse;
590
+ if (typeof r.model === 'string' && r.model.trim() !== '')
591
+ out.model = r.model;
592
+ if (typeof r.orchestratorModel === 'string' && r.orchestratorModel.trim() !== '')
593
+ out.orchestratorModel = r.orchestratorModel;
594
+ const isStringArray = (v) => Array.isArray(v) && v.every((item) => typeof item === 'string');
595
+ if (isStringArray(r.tools))
596
+ out.tools = r.tools;
597
+ if (isStringArray(r.extensions))
598
+ out.extensions = r.extensions;
599
+ if (isStringArray(r.availableTo))
600
+ out.availableTo = r.availableTo;
601
+ return Object.keys(out).length > 0 ? out : null;
602
+ }
603
+ /** Merge a raw `kinds` block over `base` (defaulting to the builtin registry):
604
+ * invalid entries are dropped, never thrown. Mirrors `mergeModelLadders`'s
605
+ * layer-over-defaults shape so a config layer can add or override a single
606
+ * kind without restating the whole registry. One rule, no entry shapes:
607
+ * - A kind some lower layer already defines: the entry FIELD-MERGES over it
608
+ * — any subset of fields, `whenToUse` included, so overriding just the
609
+ * spawn-menu guidance of a builtin kind never strips its model tier
610
+ * (the sparse-override shape `persistDefaultKindModel` writes).
611
+ * - A NEW kind: the entry defines it and must carry `whenToUse` (a kind
612
+ * with no spawn-menu gloss is meaningless); dropped otherwise.
613
+ * Deliberately NOT expressible: wholly replacing a lower layer's kind — a
614
+ * field can be overridden but never removed by omission. */
615
+ function mergeKinds(raw, base = defaultKindsConfig()) {
616
+ const out = { ...base };
617
+ if (raw !== null && typeof raw === 'object') {
618
+ for (const [kind, value] of Object.entries(raw)) {
619
+ const fields = normalizeKindFields(value);
620
+ if (fields === null)
621
+ continue;
622
+ const existing = out[kind];
623
+ if (existing !== undefined) {
624
+ out[kind] = { ...existing, ...fields };
625
+ }
626
+ else if (fields.whenToUse !== undefined) {
627
+ out[kind] = fields;
628
+ }
629
+ }
630
+ }
631
+ return out;
632
+ }
633
+ /** The launch kinds of the plugins a cloud role's node has enabled in its app, by plugin name (`appLaunchKinds`). A cloud role holds no plugin
634
+ * directories, so when this is set the user scope layers these instead of listing a directory. The launch-config subprocess sets it from its request. */
635
+ let appPluginKinds;
636
+ export function setAppPluginKinds(kinds) { appPluginKinds = kinds; }
637
+ /** Layer the `kinds` contributions of every ENABLED plugin installed under
638
+ * `scopeRootPath` over `base`, plugin name-sorted for determinism (directory
639
+ * listing order is filesystem-dependent). Each plugin's block goes through
640
+ * the same `mergeKinds` a scope `config.json` does — full entries add or
641
+ * shadow, patches field-merge, invalid entries drop. Called by
642
+ * `readMergedLaunchConfig` BELOW the host scope's own raw `kinds`, so the
643
+ * scope's config.json always overrides its plugins. */
644
+ function layerPluginKinds(scope, scopeRootPath, base) {
645
+ if (scope === 'user' && appPluginKinds !== undefined) {
646
+ let out = base;
647
+ for (const name of Object.keys(appPluginKinds).sort((a, b) => a.localeCompare(b)))
648
+ out = mergeKinds(appPluginKinds[name], out);
649
+ return out;
650
+ }
651
+ if (scopeRootPath === null)
652
+ return base;
653
+ const plugins = listInstalledPluginsInRoot(scope, scopeRootPath)
654
+ .filter((p) => p.enabled && p.manifest.kinds !== undefined)
655
+ .sort((a, b) => a.name.localeCompare(b.name));
656
+ let out = base;
657
+ for (const plugin of plugins)
658
+ out = mergeKinds(plugin.manifest.kinds, out);
659
+ return out;
660
+ }
661
+ /** The ACTIVE page-component catalog every authoring, validation, daemon,
662
+ * inbox, and TUI consumer resolves: the user scope's own `page_components`
663
+ * entries plus the contributions of every ENABLED plugin installed under that
664
+ * same root, plugin name-sorted for determinism (directory listing order is
665
+ * filesystem-dependent). Installing, updating, or removing a plugin therefore
666
+ * adds, changes, or retires its components with no config edit.
667
+ *
668
+ * User scope only, deliberately: this catalog is read from the daemon, the
669
+ * CLI, and the inbox TUI, whose ambient cwds differ, and a page slot whose
670
+ * validity depended on which directory a process happened to start in would
671
+ * validate in one surface and fail in another. `page_components` has always
672
+ * been a user-scope block (`readConfig('user')`); its plugin channel keeps
673
+ * that boundary.
674
+ *
675
+ * Throws on a duplicate kind or derived JSX tag across sources, and on a
676
+ * plugin whose block is malformed — matching the existing catalog validation
677
+ * style, where a bad `page_components` block already fails config read rather
678
+ * than silently dropping a component the product expects to be authorable.
679
+ * Install-time validation (`invalidPageComponentsReasons`) is what keeps a
680
+ * malformed block from ever reaching this path. */
681
+ export function resolvePageComponents() {
682
+ const layers = [{ origin: 'config.json', components: readConfig('user').page_components }];
683
+ const root = scopeRoot('user');
684
+ if (root !== null) {
685
+ const plugins = listInstalledPluginsInRoot('user', root)
686
+ .filter((plugin) => plugin.enabled && plugin.manifest.page_components !== undefined)
687
+ .sort((a, b) => a.name.localeCompare(b.name));
688
+ for (const plugin of plugins) {
689
+ const label = `plugin "${plugin.name}" page_components`;
690
+ layers.push({ origin: `plugin "${plugin.name}"`, components: normalizePageComponents(plugin.manifest.page_components, label) });
691
+ }
692
+ }
693
+ return mergePageComponentLayers(layers);
694
+ }
695
+ const KIND_CONFIG_KEYS = new Set(['whenToUse', 'model', 'orchestratorModel', 'tools', 'extensions', 'availableTo']);
696
+ /** STRICT install-time validation for a plugin-declared `kinds` block —
697
+ * the loud counterpart to `mergeKinds`'s silent read-time dropping. Read
698
+ * paths must never throw on bad config, but an INSTALL delivering a bad
699
+ * block must fail the install, not ship a kind that silently never
700
+ * registers. Returns one human-readable reason per defect; empty = valid.
701
+ * Used by the archive-bundle validator (`command-plugins/bundle.ts`) on
702
+ * `bundle.json`'s optional `kinds` member. */
703
+ export function invalidPluginKindsReasons(raw) {
704
+ if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) {
705
+ return ['kinds must be a JSON object keyed by kind name'];
706
+ }
707
+ const reasons = [];
708
+ const isStringArray = (v) => Array.isArray(v) && v.every((item) => typeof item === 'string');
709
+ for (const [kind, value] of Object.entries(raw)) {
710
+ if (kind.trim() === '') {
711
+ reasons.push('kinds contains an empty kind name');
712
+ continue;
713
+ }
714
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
715
+ reasons.push(`kinds.${kind} must be a JSON object`);
716
+ continue;
717
+ }
718
+ const entry = value;
719
+ for (const key of Object.keys(entry)) {
720
+ if (!KIND_CONFIG_KEYS.has(key))
721
+ reasons.push(`kinds.${kind}.${key} is not a KindConfig field (expected one of: ${[...KIND_CONFIG_KEYS].join(', ')})`);
722
+ }
723
+ if (entry['whenToUse'] !== undefined && (typeof entry['whenToUse'] !== 'string' || entry['whenToUse'].trim() === '')) {
724
+ reasons.push(`kinds.${kind}.whenToUse must be a non-empty string`);
725
+ }
726
+ for (const field of ['model', 'orchestratorModel']) {
727
+ if (entry[field] !== undefined && (typeof entry[field] !== 'string' || entry[field].trim() === '')) {
728
+ reasons.push(`kinds.${kind}.${field} must be a non-empty string`);
729
+ }
730
+ }
731
+ for (const field of ['tools', 'extensions', 'availableTo']) {
732
+ if (entry[field] !== undefined && !isStringArray(entry[field])) {
733
+ reasons.push(`kinds.${kind}.${field} must be an array of strings`);
734
+ }
735
+ }
736
+ if (normalizeKindFields(value) === null) {
737
+ reasons.push(`kinds.${kind} has no valid KindConfig field — an entry must set at least one of: ${[...KIND_CONFIG_KEYS].join(', ')} (whenToUse is required when the kind exists in no lower layer)`);
738
+ }
739
+ }
740
+ return reasons;
741
+ }
742
+ /** Validate one raw `remoteCanvas.targets.<name>` entry, or drop it (return
743
+ * null) rather than throwing — same rule `normalizeKindFields` follows. A
744
+ * valid entry needs a non-empty `previewEndpoint` and `relayTokenRef`; the
745
+ * token itself is never stored here (see `RemoteCanvasTarget`). */
746
+ function normalizeRemoteCanvasTarget(raw) {
747
+ if (raw === null || typeof raw !== 'object')
748
+ return null;
749
+ const r = raw;
750
+ if (typeof r.previewEndpoint !== 'string' || r.previewEndpoint.trim() === '')
751
+ return null;
752
+ if (typeof r.relayTokenRef !== 'string' || r.relayTokenRef.trim() === '')
753
+ return null;
754
+ const out = { previewEndpoint: r.previewEndpoint, relayTokenRef: r.relayTokenRef };
755
+ if (typeof r.cpOrigin === 'string' && r.cpOrigin.trim() !== '')
756
+ out.cpOrigin = r.cpOrigin;
757
+ return out;
758
+ }
759
+ /** Merge a raw `remoteCanvas` block over the built-in defaults (no targets):
760
+ * each valid `targets.<name>` entry adds or shadows a target by name;
761
+ * invalid entries are dropped, never thrown. Mirrors `mergeKinds`'s
762
+ * layer-over-defaults shape. */
763
+ function mergeRemoteCanvas(raw, base = defaultRemoteCanvasConfig()) {
764
+ const out = { ...base.targets };
765
+ if (raw !== null && typeof raw === 'object') {
766
+ const r = raw;
767
+ if (r.targets !== null && typeof r.targets === 'object') {
768
+ for (const [name, value] of Object.entries(r.targets)) {
769
+ const normalized = normalizeRemoteCanvasTarget(value);
770
+ if (normalized !== null)
771
+ out[name] = normalized;
772
+ }
773
+ }
774
+ }
775
+ return { targets: out };
776
+ }
777
+ function normalizeMode(value, fallback) {
778
+ if (value === true)
779
+ return 'notify';
780
+ if (value === false)
781
+ return false;
782
+ if (value === 'notify' || value === 'apply')
783
+ return value;
784
+ return fallback;
785
+ }
786
+ function normalizePositiveInteger(value, fallback) {
787
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 1
788
+ ? value
789
+ : fallback;
790
+ }
791
+ function mergeBrokerThresholds(raw, defaults) {
792
+ const partial = raw !== null && typeof raw === 'object'
793
+ ? raw
794
+ : {};
795
+ const warning = normalizePositiveInteger(partial.warning, defaults.warning);
796
+ const automaticReviveCap = normalizePositiveInteger(partial.automaticReviveCap, defaults.automaticReviveCap);
797
+ return warning <= automaticReviveCap
798
+ ? { warning, automaticReviveCap }
799
+ : { ...defaults };
800
+ }
801
+ function mergeLifecycle(raw, defaults) {
802
+ const partial = raw !== null && typeof raw === 'object'
803
+ ? raw
804
+ : {};
805
+ return { unattendedParkMs: normalizePositiveInteger(partial.unattendedParkMs, defaults.unattendedParkMs) };
806
+ }
807
+ function normalizeWhipMessages(raw) {
808
+ if (!Array.isArray(raw))
809
+ return [...DEFAULT_WHIP_MESSAGES];
810
+ const messages = raw.filter((message) => typeof message === 'string' && message.trim() !== '').map((message) => message.trim());
811
+ return messages.length > 0 ? messages : [...DEFAULT_WHIP_MESSAGES];
812
+ }
813
+ function mergeApi(raw, defaults) {
814
+ if (raw === null || typeof raw !== 'object')
815
+ return { ...defaults };
816
+ const tcp = raw.tcp;
817
+ return { tcp: typeof tcp === 'string' ? tcp : defaults.tcp };
818
+ }
819
+ let ledgerKeyWarned = false;
820
+ function mergeConfig(partial) {
821
+ // The ledger's rates and switches moved from a stored `ledger` key to the deployment's `CRTR_LEDGER_*` variables; the stored key is no longer read.
822
+ if (!ledgerKeyWarned && partial['ledger'] !== undefined) {
823
+ ledgerKeyWarned = true;
824
+ emitEvent({ level: 'warn', event: 'config.ledger.ignored', fields: { variables: Object.values(LEDGER_ENV) } });
825
+ }
826
+ const defaults = defaultScopeConfig();
827
+ const schema_version = defaults.schema_version;
828
+ const marketplaces = partial.marketplaces === undefined ? {} : partial.marketplaces;
829
+ const plugins = partial.plugins === undefined ? {} : partial.plugins;
830
+ const au = partial.auto_update;
831
+ const rawInterval = au && typeof au.interval_hours === 'number' ? au.interval_hours : undefined;
832
+ const interval_hours = rawInterval !== undefined && Number.isFinite(rawInterval) && rawInterval >= 0
833
+ ? rawInterval
834
+ : defaults.auto_update.interval_hours;
835
+ const auto_update = {
836
+ crtr: normalizeMode(au?.crtr, defaults.auto_update.crtr),
837
+ content: normalizeMode(au?.content, defaults.auto_update.content),
838
+ interval_hours,
839
+ };
840
+ const rawMaxPanes = partial.max_panes_per_window;
841
+ const max_panes_per_window = normalizePositiveInteger(rawMaxPanes, defaults.max_panes_per_window);
842
+ const auto_open_child_viewers = typeof partial.auto_open_child_viewers === 'boolean'
843
+ ? partial.auto_open_child_viewers
844
+ : defaults.auto_open_child_viewers;
845
+ const brokerThresholds = mergeBrokerThresholds(partial.brokerThresholds, defaults.brokerThresholds);
846
+ const lifecycle = mergeLifecycle(partial.lifecycle, defaults.lifecycle);
847
+ const completion_bell = typeof partial.completion_bell === 'boolean' ? partial.completion_bell : defaults.completion_bell;
848
+ const working_gerunds = partial.working_gerunds === undefined
849
+ ? [...defaults.working_gerunds]
850
+ : normalizeWorkingGerunds(partial.working_gerunds);
851
+ const whip_mode = typeof partial.whip_mode === 'boolean' ? partial.whip_mode : defaults.whip_mode;
852
+ const page_components = normalizePageComponents(partial.page_components);
853
+ const page_surface = typeof partial.page_surface === 'boolean' ? partial.page_surface : defaults.page_surface;
854
+ const whip_messages = normalizeWhipMessages(partial.whip_messages);
855
+ const whip_message_mode = WHIP_MESSAGE_MODES.includes(partial.whip_message_mode)
856
+ ? partial.whip_message_mode
857
+ : defaults.whip_message_mode;
858
+ const mouse_mode_default = MOUSE_MODE_DEFAULTS.includes(partial.mouse_mode_default)
859
+ ? partial.mouse_mode_default
860
+ : defaults.mouse_mode_default;
861
+ const live_cycles = normalizePositiveInteger(partial.live_cycles, defaults.live_cycles);
862
+ const condensed_history = CONDENSED_HISTORY_MODES.includes(partial.condensed_history)
863
+ ? partial.condensed_history
864
+ : defaults.condensed_history;
865
+ const bash_tool_purpose = typeof partial.bash_tool_purpose === 'boolean' ? partial.bash_tool_purpose : defaults.bash_tool_purpose;
866
+ const verbosity = VERBOSITY_LEVELS.includes(partial.verbosity) ? partial.verbosity : defaults.verbosity;
867
+ const detailed_tool_recaps = typeof partial.detailed_tool_recaps === 'boolean' ? partial.detailed_tool_recaps : defaults.detailed_tool_recaps;
868
+ const document_port = Number.isInteger(partial.document_port) && partial.document_port >= 1 && partial.document_port <= 65535
869
+ ? partial.document_port : defaults.document_port;
870
+ const keybindings = normalizeKeybindings(partial.keybindings);
871
+ const tmux_passthrough = normalizeTmuxPassthrough(partial.tmux_passthrough);
872
+ const modelLadders = mergeModelLadders(partial.modelLadders);
873
+ const providerOptions = mergeProviderOptions(partial.providerOptions, defaults.providerOptions);
874
+ const routes = resolveModelRoutes(mergeModelRoutePatches(partial.modelRoutes));
875
+ const modelRoutes = routes.complete;
876
+ const modelRouting = mergeModelRouting(partial.modelRouting, undefined);
877
+ const kinds = mergeKinds(partial.kinds);
878
+ const remoteCanvas = mergeRemoteCanvas(partial.remoteCanvas);
879
+ const api = mergeApi(partial.api, defaults.api);
880
+ const paths = partial.paths;
881
+ if (paths?.user_files !== undefined && (typeof paths.user_files !== 'string' || !paths.user_files.startsWith('/'))) {
882
+ throw new Error('paths.user_files must be an absolute path');
883
+ }
884
+ const store = partial.store;
885
+ const runtime = partial.runtime;
886
+ if (runtime?.person_uids !== undefined && (!Array.isArray(runtime.person_uids)
887
+ || !runtime.person_uids.every((uid) => Number.isSafeInteger(uid) && uid >= 0))) {
888
+ throw new Error('runtime.person_uids must be an array of nonnegative integer uids');
889
+ }
890
+ const spawnEnv = mergeSpawnEnv(partial.spawnEnv, defaults.spawnEnv?.allow);
891
+ const bin = normalizeBin(partial.bin);
892
+ const humanActions = normalizeHumanActions(partial.humanActions);
893
+ return { bin, humanActions, schema_version, marketplaces, plugins, auto_update, max_panes_per_window, auto_open_child_viewers, brokerThresholds, lifecycle, completion_bell, working_gerunds, whip_mode, page_components, page_surface, whip_messages, whip_message_mode, mouse_mode_default, live_cycles, condensed_history, bash_tool_purpose, verbosity, detailed_tool_recaps, document_port, keybindings, tmux_passthrough, modelLadders, providerOptions, ...(Object.keys(modelRoutes).length > 0 ? { modelRoutes } : {}), ...(Object.keys(routes.legacy).length > 0 ? { legacyModelRoutes: routes.legacy } : {}), ...(modelRouting !== undefined ? { modelRouting } : {}), kinds, remoteCanvas, api, ...(paths ? { paths } : {}), ...(store ? { store } : {}), ...(runtime ? { runtime } : {}), spawnEnv };
894
+ }
895
+ /** Raw (un-defaulted) partial config for one scope, or null if the scope has
896
+ * no root or no config.json. Used by `readMergedLaunchConfig` to layer
897
+ * scopes onto each other WITHOUT each scope's own default-fill masking a
898
+ * lower-precedence scope's real customization (see that function's comment
899
+ * for why `readConfig(scope)`, which already defaults-fills, is unusable
900
+ * for cross-scope layering). */
901
+ export function readRawConfigAtRoot(root) {
902
+ return readRawAtRoot(root);
903
+ }
904
+ export function readRawScopeConfig(scope) {
905
+ const root = scopeRoot(scope);
906
+ return root ? readRawConfigAtRoot(root) : null;
907
+ }
908
+ /** Raw SQL-backed profile settings, or null when the profile is absent. */
909
+ function readRawProfileConfig(profileId) {
910
+ if (profileId === null || profileId === '')
911
+ return null;
912
+ try {
913
+ return readRawAtRoot(profileDir(profileId));
914
+ }
915
+ catch {
916
+ return null;
917
+ }
918
+ }
919
+ /** Raw partial configs for the whole project-scope STACK (`findProjectScopeRoots`
920
+ * — every ancestor `.crouter/`, widened by a selected profile's `projects`),
921
+ * ordered FARTHEST-first so `readMergedLaunchConfig` can layer them on last
922
+ * and have the NEAREST root win — mirroring the resolver's nearest-project-
923
+ * strongest replacement precedence. Walks from `targetCwd`/`targetProfileId`
924
+ * — the SCOPE THE CONFIG IS FOR, not necessarily the calling process's own
925
+ * ambient cwd/profile (see `readMergedLaunchConfig`). */
926
+ function readRawProjectScopeConfigs(targetCwd, targetProfileId) {
927
+ const nearestFirst = findProjectScopeRoots(targetCwd, targetProfileId);
928
+ const farthestFirst = [...nearestFirst].reverse();
929
+ // A root with no config.json still contributes: its installed plugins may
930
+ // declare kinds, so the ROOT rides along and `raw` stays null.
931
+ return farthestFirst.map((root) => ({ root, raw: readRawAtRoot(root) }));
932
+ }
933
+ /** Merge launch knobs (`kinds`, `modelLadders`) across scopes in
934
+ * project stack > profile > user > builtin precedence — the same precedence
935
+ * order used for memory resolution. For `kinds` only, each plugin-bearing
936
+ * scope (user, each project root) additionally layers its enabled plugins'
937
+ * manifest `kinds` blocks directly BELOW that scope's own raw config — see
938
+ * `layerPluginKinds`. A kind or ladder cell declared at a
939
+ * more-specific scope shadows the same key from a less-specific scope; the
940
+ * project STACK (`findProjectScopeRoots` — every ancestor `.crouter/`,
941
+ * widened by a selected profile's `projects`) layers nearest-root-strongest;
942
+ * a key no scope declares falls through to the builtin default registry
943
+ * (`defaultScopeConfig().kinds` / `.modelLadders`).
944
+ *
945
+ * Layers RAW (un-defaulted) partial config per scope, not `readConfig(scope)`
946
+ * — `readConfig` already fills in every default kind for a scope that
947
+ * customizes even one, so naively overlaying two already-defaulted
948
+ * `ScopeConfig.kinds` objects would let an untouched project-scope kind
949
+ * (silently defaulted) clobber a real user-scope customization of that same
950
+ * kind. Layering the raw partials avoids that.
951
+ *
952
+ * Callers (launch, kind registry) go through this function rather than
953
+ * `readConfig` directly, so `ScopeConfig.kinds`/`modelLadders`/tools/
954
+ * extensions/`availableTo` all honor the same profile + multi-project
955
+ * precedence.
956
+ *
957
+ * `targetCwd`/`targetProfileId` default to this PROCESS's own ambient cwd
958
+ * and `CRTR_PROFILE_ID` — correct for a caller resolving config for itself
959
+ * (front-door commands, kind listing). A caller resolving config on behalf
960
+ * of a DIFFERENT node (the broker spawn-env boundary or cron executor — both
961
+ * run inside the daemon, whose ambient cwd/profile is the daemon's own, not
962
+ * the target node's) MUST pass the target's own cwd/profile explicitly, or
963
+ * `spawnEnv.allow` resolves from the wrong scope entirely (the C-1
964
+ * follow-up fix this parameterization exists for). */
965
+ export function readMergedLaunchConfig(targetCwd = process.cwd(), targetProfileId = envProfileId() || null) {
966
+ const snapshot = brokerSnapshotState[brokerSnapshotKey];
967
+ if (snapshot)
968
+ return snapshot.launch;
969
+ const defaults = defaultScopeConfig();
970
+ const userRaw = readRawScopeConfig('user');
971
+ const profileRaw = readRawProfileConfig(targetProfileId);
972
+ const projectLayersFarthestFirst = readRawProjectScopeConfigs(targetCwd, targetProfileId);
973
+ // Kinds layer per scope as: that scope's enabled PLUGINS first, then the
974
+ // scope's own raw config — so a plugin can add or shadow a kind (registry
975
+ // entry in its manifest + gated persona docs in its memory tree) and the
976
+ // scope's config.json still overrides its plugins. Other launch knobs
977
+ // (ladders/routes/spawnEnv) have no plugin channel.
978
+ let kinds = mergeKinds(userRaw?.kinds, layerPluginKinds('user', scopeRoot('user'), defaults.kinds));
979
+ let modelLadders = mergeModelLadders(userRaw?.modelLadders, defaults.modelLadders);
980
+ let providerOptions = mergeProviderOptions(userRaw?.providerOptions, defaults.providerOptions);
981
+ let modelRoutePatches = mergeModelRoutePatches(userRaw?.modelRoutes);
982
+ let modelRouting = mergeModelRouting(userRaw?.modelRouting, undefined);
983
+ let spawnEnv = mergeSpawnEnv(userRaw?.spawnEnv, defaults.spawnEnv?.allow);
984
+ if (profileRaw !== null) {
985
+ kinds = mergeKinds(profileRaw.kinds, kinds);
986
+ modelLadders = mergeModelLadders(profileRaw.modelLadders, modelLadders);
987
+ providerOptions = mergeProviderOptions(profileRaw.providerOptions, providerOptions);
988
+ modelRoutePatches = mergeModelRoutePatches(profileRaw.modelRoutes, modelRoutePatches);
989
+ modelRouting = mergeModelRouting(profileRaw.modelRouting, modelRouting);
990
+ spawnEnv = mergeSpawnEnv(profileRaw.spawnEnv, spawnEnv.allow);
991
+ }
992
+ for (const { root, raw } of projectLayersFarthestFirst) {
993
+ kinds = mergeKinds(raw?.kinds, layerPluginKinds('project', root, kinds));
994
+ if (raw === null)
995
+ continue;
996
+ modelLadders = mergeModelLadders(raw.modelLadders, modelLadders);
997
+ providerOptions = mergeProviderOptions(raw.providerOptions, providerOptions);
998
+ modelRoutePatches = mergeModelRoutePatches(raw.modelRoutes, modelRoutePatches);
999
+ modelRouting = mergeModelRouting(raw.modelRouting, modelRouting);
1000
+ spawnEnv = mergeSpawnEnv(raw.spawnEnv, spawnEnv.allow);
1001
+ }
1002
+ const routes = resolveModelRoutes(modelRoutePatches);
1003
+ return {
1004
+ kinds,
1005
+ modelLadders,
1006
+ providerOptions,
1007
+ ...(Object.keys(routes.complete).length > 0 ? { modelRoutes: routes.complete } : {}),
1008
+ ...(Object.keys(routes.legacy).length > 0 ? { legacyModelRoutes: routes.legacy } : {}),
1009
+ ...(modelRouting !== undefined ? { modelRouting } : {}),
1010
+ spawnEnv,
1011
+ };
1012
+ }
1013
+ /** The effective `KindConfig` for one full kind string (top-level, e.g.
1014
+ * `developer`, or sub-kind, e.g. `audit/security`), across
1015
+ * project > user > builtin precedence. Returns `undefined` for a kind no
1016
+ * scope registers — existence is deliberately NOT validated here (kind
1017
+ * existence/launch-menu enumeration is a caller concern); this only
1018
+ * resolves the config for a kind the caller already knows about. */
1019
+ export function resolveKindConfig(kind) {
1020
+ return readMergedLaunchConfig().kinds[kind];
1021
+ }
1022
+ /** The sub-kinds available to spawn FROM a given top-level kind — every
1023
+ * registered sub-kind (full path contains `/`) whose `availableTo` (default:
1024
+ * its own top-level ancestor, e.g. `audit/security` defaults to
1025
+ * `['audit']`) includes `kind` or `'*'`. The single source both `sys
1026
+ * prompt-review --list`'s `subPersonas` metadata and the live sub-persona
1027
+ * spawn-menu splice (`core/substrate/delivery/render-boot.ts`) read, so the two can never
1028
+ * drift apart. Sorted by full kind name for stable rendering. */
1029
+ export function subKindsAvailableTo(kind) {
1030
+ const registry = readMergedLaunchConfig().kinds;
1031
+ const out = [];
1032
+ for (const [full, cfg] of Object.entries(registry)) {
1033
+ const slash = full.indexOf('/');
1034
+ if (slash === -1)
1035
+ continue;
1036
+ const topAncestor = full.slice(0, slash);
1037
+ const availableTo = cfg.availableTo ?? [topAncestor];
1038
+ if (!(availableTo.includes('*') || availableTo.includes(kind)))
1039
+ continue;
1040
+ out.push({ kind: full, whenToUse: cfg.whenToUse });
1041
+ }
1042
+ return out.sort((a, b) => a.kind.localeCompare(b.kind));
1043
+ }
1044
+ /** The SPARSE `modelLadders` to persist after a config mutation: the raw
1045
+ * on-disk sparse ladder (absent rungs stay absent) plus ONLY the specific
1046
+ * rungs / `defaultProvider` the mutation actually changed away from the
1047
+ * merged baseline. Untouched default rungs are never materialized -- they
1048
+ * hold concrete model ids that go stale across builds (the model-ladder freeze
1049
+ * bug). Returns undefined when nothing ladder-related is on disk and nothing
1050
+ * was touched, so the key is omitted from config.json entirely. This is what
1051
+ * makes a direct `sys config set modelLadders.<provider>.<strength>` persist
1052
+ * only the touched rung through the SAME central write path as every other
1053
+ * mutation, rather than a special case. */
1054
+ function sparseModelLaddersToPersist(rawLadders, baseline, mutated) {
1055
+ const out = { ...(rawLadders ?? {}) };
1056
+ if (out.anthropic !== undefined)
1057
+ out.anthropic = { ...out.anthropic };
1058
+ if (out.openai !== undefined)
1059
+ out.openai = { ...out.openai };
1060
+ if (mutated.defaultProvider !== baseline.defaultProvider && mutated.defaultProvider !== undefined) {
1061
+ out.defaultProvider = mutated.defaultProvider;
1062
+ }
1063
+ for (const provider of ['anthropic', 'openai']) {
1064
+ for (const strength of ['ultra', 'strong', 'medium', 'light']) {
1065
+ if (mutated[provider][strength] !== baseline[provider][strength]) {
1066
+ out[provider] = { ...(out[provider] ?? {}), [strength]: mutated[provider][strength] };
1067
+ }
1068
+ }
1069
+ }
1070
+ const hasContent = out.defaultProvider !== undefined || out.anthropic !== undefined || out.openai !== undefined;
1071
+ return hasContent ? out : undefined;
1072
+ }
1073
+ /** Apply `mutate` to a scope's MERGED config (so callers can read + write any
1074
+ * field), then persist only a RAW PARTIAL: every top-level key the mutation
1075
+ * left untouched keeps its exact on-disk raw value (absent stays absent, a
1076
+ * sparse override stays sparse), and only keys the mutation actually changed
1077
+ * are written. `modelLadders` gets sub-field-granular sparse handling via
1078
+ * `sparseModelLaddersToPersist`. Result: a fresh bootstrap or any unrelated
1079
+ * `sys config set` never freezes a full concrete `modelLadders` to disk,
1080
+ * and a direct ladder-rung set still persists only the touched rung -- all
1081
+ * through one lock-protected atomic update path. */
1082
+ async function mutateConfigAtRoot(root, mutate) {
1083
+ return await mutateRawAtRoot(root, (raw) => {
1084
+ const baseline = mergeConfig(raw);
1085
+ const cfg = mergeConfig(raw);
1086
+ mutate(cfg);
1087
+ const partial = { ...raw };
1088
+ for (const key of SCOPE_CONFIG_KEYS)
1089
+ if (key !== 'modelLadders' && !isDeepStrictEqual(cfg[key], baseline[key]))
1090
+ partial[key] = cfg[key];
1091
+ const ladders = sparseModelLaddersToPersist(raw.modelLadders, baseline.modelLadders, cfg.modelLadders);
1092
+ if (ladders !== undefined)
1093
+ partial.modelLadders = ladders;
1094
+ else
1095
+ delete partial.modelLadders;
1096
+ return { value: cfg, next: partial };
1097
+ });
1098
+ }
1099
+ /** Persist an EXPLICIT sparse `modelLadders` intent at one config root: the
1100
+ * patch's rungs (and `defaultProvider`) are merged over whatever sparse ladder
1101
+ * is already on disk, and every untouched rung stays absent so it keeps
1102
+ * re-deriving from the running build's registry.
1103
+ *
1104
+ * Ladder edits must come through here rather than `updateConfig`, because that
1105
+ * path infers what to persist by diffing the mutated config against the merged
1106
+ * baseline: setting a rung to the value that happens to be today's compiled
1107
+ * default produces an empty diff and silently persists nothing, so the choice
1108
+ * evaporates as soon as the default moves. Explicit intent is recorded as
1109
+ * written. Mirrors `persistDefaultKindModel`. */
1110
+ export async function persistModelLadders(root, patch) {
1111
+ await mutateRawAtRoot(root, (raw) => { const current = (raw.modelLadders ?? {}); const next = { ...current }; if (patch.defaultProvider !== undefined)
1112
+ next.defaultProvider = patch.defaultProvider; for (const provider of ['anthropic', 'openai'])
1113
+ if (patch[provider] !== undefined)
1114
+ next[provider] = { ...(current[provider] ?? {}), ...patch[provider] }; return { value: undefined, next: { ...raw, modelLadders: next } }; });
1115
+ }
1116
+ /** Persist one complete route at one exact config root. The route is the only
1117
+ * raw route entry touched; unrelated routes and local ladder defaults remain
1118
+ * absent. Pass `undefined` to remove this scope's entry, which resumes lower
1119
+ * scope inheritance rather than introducing a tombstone. */
1120
+ export async function persistModelRoute(root, routeId, route) {
1121
+ if (route !== undefined)
1122
+ assertCompleteModelRoute(routeId, route);
1123
+ else if (routeId.trim() === '')
1124
+ throw new Error('model route id must be a non-empty string');
1125
+ await mutateRawAtRoot(root, (raw) => { const routes = copyRouteRecord((raw.modelRoutes ?? {})); if (route === undefined)
1126
+ delete routes[routeId];
1127
+ else
1128
+ setRouteRecord(routes, routeId, { ...route, models: { ...route.models } }); const next = { ...raw }; if (Object.keys(routes).length === 0)
1129
+ delete next.modelRoutes;
1130
+ else
1131
+ next.modelRoutes = routes; return { value: undefined, next }; });
1132
+ }
1133
+ /** Mutate one exact config root. Setup uses this for profile and explicit
1134
+ * project targets that cannot be represented by the user/project Scope enum. */
1135
+ export async function updateConfigAtRoot(root, mutate) {
1136
+ return await mutateConfigAtRoot(root, mutate);
1137
+ }
1138
+ export async function updateConfig(scope, mutate) {
1139
+ return await updateConfigAtRoot(requireScopeRoot(scope), mutate);
1140
+ }
1141
+ /** Persist one sparse kind-model field at an exact config root. The sparse
1142
+ * patch keeps every unrelated kind and launch knob inherited from lower
1143
+ * scopes instead of freezing a materialized registry snapshot. */
1144
+ export async function persistDefaultKindModel(opts) {
1145
+ const field = opts.orchestrator === true ? 'orchestratorModel' : 'model';
1146
+ await mutateRawAtRoot(opts.root, (raw) => { const kinds = { ...(raw.kinds ?? {}), [opts.kind]: { ...(raw.kinds ?? {})[opts.kind], [field]: opts.model } }; return { value: undefined, next: { ...raw, kinds: kinds } }; });
1147
+ return { path: configPathFor(opts.root), field };
1148
+ }
1149
+ export async function updateState(scope, mutate) {
1150
+ const s = readState(scope);
1151
+ mutate(s);
1152
+ await writeState(scope, s);
1153
+ return s;
1154
+ }