@north-light/crouter 0.3.353 → 0.3.355

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 (626) hide show
  1. package/dist/api/client.d.ts +35 -25
  2. package/dist/api/client.js +2 -2
  3. package/dist/api/dto/broker-ops.d.ts +2 -36
  4. package/dist/api/dto/canvas.d.ts +8 -13
  5. package/dist/api/dto/config.d.ts +4 -0
  6. package/dist/api/dto/delivery.d.ts +61 -0
  7. package/dist/api/dto/docs.d.ts +135 -0
  8. package/dist/api/dto/docs.js +1 -0
  9. package/dist/api/dto/health.d.ts +26 -79
  10. package/dist/api/dto/node-outcomes.d.ts +1 -3
  11. package/dist/api/dto/nodes.d.ts +5 -26
  12. package/dist/api/dto/objects.d.ts +168 -0
  13. package/dist/api/dto/objects.js +1 -0
  14. package/dist/api/dto/profiles.d.ts +14 -8
  15. package/dist/api/dto/reports.d.ts +9 -7
  16. package/dist/api/dto/reviews.d.ts +11 -3
  17. package/dist/api/dto/worktree.d.ts +1 -1
  18. package/dist/api/index.d.ts +0 -1
  19. package/dist/api/index.js +1 -1
  20. package/dist/api/routes.d.ts +14 -12
  21. package/dist/api/routes.js +1 -1
  22. package/dist/build-root.js +1 -1
  23. package/dist/builtin-memory/00-runtime-base/00-authoring.md +10 -5
  24. package/dist/builtin-memory/02-turn-lifecycle/02-resident.md +1 -0
  25. package/dist/builtin-memory/04-orchestration-kernel.md +10 -31
  26. package/dist/builtin-memory/05-kinds/advisor/01-orchestrator.md +1 -1
  27. package/dist/builtin-memory/05-kinds/explore/00-base.md +2 -2
  28. package/dist/builtin-memory/05-kinds/explore/01-orchestrator.md +2 -2
  29. package/dist/builtin-memory/crouter-concepts/INDEX.md +2 -2
  30. package/dist/builtin-memory/crouter-concepts/lifecycle-and-wakes.md +1 -1
  31. package/dist/builtin-memory/crouter-concepts/memory.md +15 -15
  32. package/dist/builtin-memory/crouter-concepts/nodes-and-the-canvas.md +1 -1
  33. package/dist/builtin-memory/crouter-concepts/profiles-kinds-and-modes.md +5 -5
  34. package/dist/builtin-memory/crouter-concepts/scopes-and-trust.md +1 -1
  35. package/dist/builtin-memory/crouter-concepts/why-a-daemon.md +1 -1
  36. package/dist/builtin-memory/crouter-sdk/INDEX.md +2 -2
  37. package/dist/builtin-memory/crouter-sdk/README.md +5 -6
  38. package/dist/builtin-memory/crouter-sdk/errors.md +0 -13
  39. package/dist/builtin-memory/crouter-sdk/guides/README.md +0 -1
  40. package/dist/builtin-memory/crouter-sdk/guides/event-driven-assistant.md +2 -2
  41. package/dist/builtin-memory/crouter-sdk/nodes.md +0 -2
  42. package/dist/builtin-memory/crouter-sdk/resources.md +0 -1
  43. package/dist/builtin-memory/explore/exploration-doc.md +4 -4
  44. package/dist/builtin-memory/insights/capture.md +6 -6
  45. package/dist/builtin-memory/insights/init.md +14 -14
  46. package/dist/builtin-memory/internal/INDEX.md +4 -4
  47. package/dist/builtin-memory/internal/agent-shaping.md +20 -20
  48. package/dist/builtin-memory/internal/examples/imessage-assistant.md +2 -2
  49. package/dist/builtin-memory/internal/marketplaces.md +2 -2
  50. package/dist/builtin-memory/internal/memory-loading.md +31 -30
  51. package/dist/builtin-memory/internal/nodes-and-canvas.md +1 -1
  52. package/dist/builtin-memory/internal/plugins.md +16 -14
  53. package/dist/builtin-memory/internal/storage-tiers.md +4 -4
  54. package/dist/builtin-memory/memory-read-orientation.md +1 -1
  55. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/memory-slash-commands.ts +32 -40
  56. package/dist/clients/attach/input/controller.js +1 -1
  57. package/dist/clients/attach/input/ref-autocomplete.js +1 -1
  58. package/dist/clients/attach/input/titled-editor.js +1 -1
  59. package/dist/clients/attach/overlays/file-review.d.ts +1 -0
  60. package/dist/clients/attach/overlays/file-review.js +2 -2
  61. package/dist/clients/attach/render/chat-view.d.ts +6 -0
  62. package/dist/clients/attach/render/chat-view.js +2 -2
  63. package/dist/clients/attach/render/crtr-output.d.ts +1 -2
  64. package/dist/clients/attach/render/crtr-output.js +17 -17
  65. package/dist/clients/attach/render/doc-links.d.ts +34 -0
  66. package/dist/clients/attach/render/doc-links.js +1 -0
  67. package/dist/clients/attach/render/group-activity.d.ts +8 -8
  68. package/dist/clients/attach/render/group-activity.js +2 -2
  69. package/dist/clients/attach/render/group-recap.js +1 -1
  70. package/dist/clients/attach/render/markdown-source.js +5 -5
  71. package/dist/clients/attach/render/tool-calls.d.ts +1 -1
  72. package/dist/clients/attach/session/doc-materialize.d.ts +53 -0
  73. package/dist/clients/attach/session/doc-materialize.js +3 -0
  74. package/dist/clients/attach/session/document-links.d.ts +21 -0
  75. package/dist/clients/attach/session/document-links.js +1 -0
  76. package/dist/clients/attach/session/file-links.d.ts +2 -0
  77. package/dist/clients/attach/session/file-links.js +1 -1
  78. package/dist/clients/attach/session/profile-files.js +1 -1
  79. package/dist/clients/attach/slash/dispatch.js +1 -1
  80. package/dist/clients/attach/viewer.js +816 -1561
  81. package/dist/clients/inbox/review/review-client.d.ts +5 -1
  82. package/dist/clients/inbox/review/review-client.js +1 -1
  83. package/dist/commands/api-client.d.ts +2 -0
  84. package/dist/commands/api-client.js +3 -3
  85. package/dist/commands/canvas/edges.d.ts +2 -0
  86. package/dist/commands/canvas/edges.js +2 -0
  87. package/dist/commands/canvas/list.d.ts +4 -0
  88. package/dist/commands/canvas/list.js +3 -0
  89. package/dist/commands/canvas/read.d.ts +8 -0
  90. package/dist/commands/canvas/read.js +5 -0
  91. package/dist/commands/canvas/search.d.ts +2 -0
  92. package/dist/commands/canvas/search.js +3 -0
  93. package/dist/commands/canvas/unwatch.d.ts +2 -0
  94. package/dist/commands/canvas/unwatch.js +1 -0
  95. package/dist/commands/canvas/watch.d.ts +3 -0
  96. package/dist/commands/canvas/watch.js +1 -0
  97. package/dist/commands/canvas-analytics.js +1 -1
  98. package/dist/commands/canvas-history/grep.js +4 -4
  99. package/dist/commands/canvas-history/read.js +2 -2
  100. package/dist/commands/canvas-history/search.js +7 -7
  101. package/dist/commands/canvas-history/shared.d.ts +0 -1
  102. package/dist/commands/canvas-history/shared.js +1 -1
  103. package/dist/commands/canvas-history/stats.js +2 -2
  104. package/dist/commands/canvas-history.js +1 -1
  105. package/dist/commands/canvas.js +1 -1
  106. package/dist/commands/doc/delete.d.ts +2 -0
  107. package/dist/commands/doc/delete.js +1 -0
  108. package/dist/commands/doc/edit.d.ts +2 -0
  109. package/dist/commands/doc/edit.js +1 -0
  110. package/dist/commands/doc/history.d.ts +2 -0
  111. package/dist/commands/doc/history.js +2 -0
  112. package/dist/commands/doc/lint.d.ts +2 -0
  113. package/dist/commands/doc/lint.js +2 -0
  114. package/dist/commands/doc/list.d.ts +2 -0
  115. package/dist/commands/doc/list.js +1 -0
  116. package/dist/commands/doc/move.d.ts +2 -0
  117. package/dist/commands/doc/move.js +1 -0
  118. package/dist/commands/doc/read.d.ts +2 -0
  119. package/dist/commands/doc/read.js +1 -0
  120. package/dist/commands/doc/shared.d.ts +25 -0
  121. package/dist/commands/doc/shared.js +2 -0
  122. package/dist/commands/doc/write.d.ts +2 -0
  123. package/dist/commands/doc/write.js +1 -0
  124. package/dist/commands/{memory.d.ts → doc.d.ts} +1 -1
  125. package/dist/commands/doc.js +1 -0
  126. package/dist/commands/human/review.js +1 -1
  127. package/dist/commands/node/bash.js +2 -2
  128. package/dist/commands/node/create.js +1 -1
  129. package/dist/commands/node/inspect.js +10 -10
  130. package/dist/commands/node/lifecycle.js +2 -2
  131. package/dist/commands/node/outcome.js +1 -1
  132. package/dist/commands/node/subscription.js +1 -1
  133. package/dist/commands/node-context.js +2 -2
  134. package/dist/commands/pkg/browse/catalog.js +1 -1
  135. package/dist/commands/pkg/browse/doc-view.js +1 -1
  136. package/dist/commands/pkg/browse/model.d.ts +9 -17
  137. package/dist/commands/pkg/plugin-inspect.js +1 -1
  138. package/dist/commands/pkg/plugin-manage.d.ts +4 -8
  139. package/dist/commands/pkg/plugin-manage.js +15 -17
  140. package/dist/commands/profile/list.js +1 -1
  141. package/dist/commands/profile/new.js +1 -1
  142. package/dist/commands/profile/project.js +1 -1
  143. package/dist/commands/profile/show.js +1 -1
  144. package/dist/commands/push.js +3 -3
  145. package/dist/commands/sys/config.js +1 -1
  146. package/dist/commands/sys/context/admin/actions.d.ts +18 -43
  147. package/dist/commands/sys/context/admin/actions.js +1 -2
  148. package/dist/commands/sys/context/admin/detail-panel.d.ts +17 -25
  149. package/dist/commands/sys/context/admin/detail-panel.js +2 -1
  150. package/dist/commands/sys/context/admin/docs-panel.d.ts +7 -6
  151. package/dist/commands/sys/context/admin/docs-panel.js +1 -1
  152. package/dist/commands/sys/context/admin/list-view.d.ts +12 -12
  153. package/dist/commands/sys/context/admin/list-view.js +1 -1
  154. package/dist/commands/sys/context/admin/model.d.ts +96 -69
  155. package/dist/commands/sys/context/admin/model.js +1 -1
  156. package/dist/commands/sys/context/admin/rail-panel.d.ts +7 -5
  157. package/dist/commands/sys/context/admin/rail-panel.js +1 -1
  158. package/dist/commands/sys/context/admin/read-view.d.ts +10 -14
  159. package/dist/commands/sys/context/admin/read-view.js +1 -2
  160. package/dist/commands/sys/context/admin/shell.d.ts +26 -31
  161. package/dist/commands/sys/context/admin/shell.js +1 -1
  162. package/dist/commands/sys/context/admin.js +2 -2
  163. package/dist/commands/sys/context/doc.js +2 -3
  164. package/dist/commands/sys/context/expose.js +2 -2
  165. package/dist/commands/sys/context/prompt-review.js +4 -4
  166. package/dist/commands/sys/context/resolve.d.ts +92 -65
  167. package/dist/commands/sys/context/resolve.js +7 -9
  168. package/dist/commands/sys/context.js +1 -1
  169. package/dist/commands/sys/doctor.js +1 -1
  170. package/dist/commands/sys/migrate.js +1 -1
  171. package/dist/commands/sys/panels/profiles-panel.d.ts +3 -1
  172. package/dist/commands/sys/panels/profiles-panel.js +1 -1
  173. package/dist/commands/sys/sync-deps.d.ts +6 -11
  174. package/dist/commands/sys/sync-deps.js +7 -8
  175. package/dist/commands/sys/sync-project-guidance.js +5 -4
  176. package/dist/commands/sys/sync-shared.d.ts +41 -4
  177. package/dist/commands/sys/sync-shared.js +1 -1
  178. package/dist/commands/sys/sync-skills.js +2 -2
  179. package/dist/commands/sys/sync.js +1 -1
  180. package/dist/core/bash-job-supervisor.d.ts +2 -3
  181. package/dist/core/bash-job-supervisor.js +3 -3
  182. package/dist/core/bash-jobs.d.ts +0 -5
  183. package/dist/core/bash-jobs.js +7 -7
  184. package/dist/core/bootstrap.js +2 -2
  185. package/dist/core/canvas/canvas.d.ts +6 -50
  186. package/dist/core/canvas/canvas.js +16 -21
  187. package/dist/core/canvas/db.d.ts +4 -1
  188. package/dist/core/canvas/db.js +2 -2
  189. package/dist/core/canvas/history.d.ts +11 -39
  190. package/dist/core/canvas/history.js +9 -20
  191. package/dist/core/canvas/install-id.d.ts +2 -2
  192. package/dist/core/canvas/install-id.js +1 -1
  193. package/dist/core/canvas/memory-reads.d.ts +5 -0
  194. package/dist/core/canvas/memory-reads.js +1 -1
  195. package/dist/core/canvas/migrations.js +215 -41
  196. package/dist/core/canvas/node-agent-paths.js +1 -1
  197. package/dist/core/canvas/node-tokens.js +1 -1
  198. package/dist/core/canvas/paths.d.ts +0 -4
  199. package/dist/core/canvas/paths.js +1 -1
  200. package/dist/core/canvas/remote-canvas-source.d.ts +0 -1
  201. package/dist/core/canvas/remote-canvas-source.js +1 -1
  202. package/dist/core/canvas/render-source.d.ts +9 -6
  203. package/dist/core/canvas/render-source.js +6 -6
  204. package/dist/core/canvas/sessions.js +2 -2
  205. package/dist/core/canvas/source.d.ts +6 -0
  206. package/dist/core/canvas/tree.d.ts +29 -0
  207. package/dist/core/canvas/tree.js +12 -0
  208. package/dist/core/canvas/types.d.ts +0 -20
  209. package/dist/core/command-plugins/bundle.js +1 -1
  210. package/dist/core/config.d.ts +1 -1
  211. package/dist/core/conversation-store/listener.js +4 -2
  212. package/dist/core/feed/feed.d.ts +9 -7
  213. package/dist/core/feed/feed.js +3 -7
  214. package/dist/core/feed/inbox.d.ts +3 -5
  215. package/dist/core/feed/inbox.js +1 -10
  216. package/dist/core/feed/messages.d.ts +33 -6
  217. package/dist/core/feed/messages.js +10 -7
  218. package/dist/core/feed/reports.d.ts +10 -0
  219. package/dist/core/feed/reports.js +2 -0
  220. package/dist/core/grants/remove.js +1 -1
  221. package/dist/core/graph/access.d.ts +24 -0
  222. package/dist/core/graph/access.js +8 -0
  223. package/dist/core/graph/bodies.d.ts +6 -0
  224. package/dist/core/graph/bodies.js +1 -0
  225. package/dist/core/graph/deletion.d.ts +10 -0
  226. package/dist/core/graph/deletion.js +5 -0
  227. package/dist/core/graph/diff.d.ts +4 -0
  228. package/dist/core/graph/diff.js +4 -0
  229. package/dist/core/graph/documents.d.ts +167 -0
  230. package/dist/core/graph/documents.js +10 -0
  231. package/dist/core/graph/edges.d.ts +25 -0
  232. package/dist/core/graph/edges.js +1 -0
  233. package/dist/core/graph/events.d.ts +26 -0
  234. package/dist/core/graph/events.js +7 -0
  235. package/dist/core/graph/exposures.d.ts +53 -0
  236. package/dist/core/graph/exposures.js +4 -0
  237. package/dist/core/graph/jobs.d.ts +31 -0
  238. package/dist/core/graph/jobs.js +2 -0
  239. package/dist/core/graph/names.d.ts +30 -0
  240. package/dist/core/graph/names.js +3 -0
  241. package/dist/core/graph/objects.d.ts +55 -0
  242. package/dist/core/graph/objects.js +9 -0
  243. package/dist/core/graph/package-docs.d.ts +31 -0
  244. package/dist/core/graph/package-docs.js +5 -0
  245. package/dist/core/graph/package-files.d.ts +20 -0
  246. package/dist/core/graph/package-files.js +2 -0
  247. package/dist/core/graph/reader.d.ts +21 -0
  248. package/dist/core/graph/reader.js +3 -0
  249. package/dist/core/graph/repo-sync/exchange.d.ts +34 -0
  250. package/dist/core/graph/repo-sync/exchange.js +2 -0
  251. package/dist/core/graph/repo-sync/identity.d.ts +30 -0
  252. package/dist/core/graph/repo-sync/identity.js +1 -0
  253. package/dist/core/graph/repo-sync/index.d.ts +4 -0
  254. package/dist/core/graph/repo-sync/index.js +1 -0
  255. package/dist/core/graph/repo-sync/mirror.d.ts +30 -0
  256. package/dist/core/graph/repo-sync/mirror.js +6 -0
  257. package/dist/core/graph/repo-sync/ref-format.d.ts +76 -0
  258. package/dist/core/graph/repo-sync/ref-format.js +2 -0
  259. package/dist/core/graph/repo-sync/repos.d.ts +17 -0
  260. package/dist/core/graph/repo-sync/repos.js +3 -0
  261. package/dist/core/graph/repo-sync/sync.d.ts +42 -0
  262. package/dist/core/graph/repo-sync/sync.js +2 -0
  263. package/dist/core/graph/rules.d.ts +26 -0
  264. package/dist/core/graph/rules.js +3 -0
  265. package/dist/core/graph/spaces/app.d.ts +3 -0
  266. package/dist/core/graph/spaces/app.js +1 -0
  267. package/dist/core/graph/spaces/index.d.ts +19 -0
  268. package/dist/core/graph/spaces/index.js +1 -0
  269. package/dist/core/graph/spaces/person.d.ts +5 -0
  270. package/dist/core/graph/spaces/person.js +2 -0
  271. package/dist/core/graph/spaces/repo.d.ts +4 -0
  272. package/dist/core/graph/spaces/repo.js +1 -0
  273. package/dist/core/graph/types.d.ts +75 -0
  274. package/dist/core/graph/types.js +1 -0
  275. package/dist/core/graph/watches.d.ts +62 -0
  276. package/dist/core/graph/watches.js +18 -0
  277. package/dist/core/human/feedback-companion.js +1 -1
  278. package/dist/core/human/requests.d.ts +3 -1
  279. package/dist/core/human/requests.js +6 -6
  280. package/dist/core/inspector/model.js +2 -2
  281. package/dist/core/io.js +5 -5
  282. package/dist/core/layout-migrate/index.d.ts +24 -1
  283. package/dist/core/layout-migrate/index.js +4 -4
  284. package/dist/core/layout-migrate/paths.d.ts +4 -0
  285. package/dist/core/layout-migrate/paths.js +1 -1
  286. package/dist/core/layout-migrate/stored-paths.d.ts +7 -0
  287. package/dist/core/layout-migrate/stored-paths.js +11 -11
  288. package/dist/core/layout-migrate/stores.d.ts +19 -6
  289. package/dist/core/layout-migrate/stores.js +3 -4
  290. package/dist/core/manifest.d.ts +0 -2
  291. package/dist/core/manifest.js +1 -1
  292. package/dist/core/{memory/extensions.d.ts → plugin-extensions.d.ts} +9 -10
  293. package/dist/core/plugin-extensions.js +1 -0
  294. package/dist/core/preview-registry.d.ts +1 -1
  295. package/dist/core/preview-registry.js +3 -2
  296. package/dist/core/profiles/manifest.d.ts +7 -7
  297. package/dist/core/profiles/manifest.js +1 -1
  298. package/dist/core/profiles/select.js +3 -3
  299. package/dist/core/review/birth.js +1 -1
  300. package/dist/core/review/companion.js +1 -1
  301. package/dist/core/review/stage.d.ts +12 -1
  302. package/dist/core/review/stage.js +1 -1
  303. package/dist/core/review/store.d.ts +2 -0
  304. package/dist/core/review/store.js +1 -1
  305. package/dist/core/review/types.d.ts +7 -1
  306. package/dist/core/runs/events.js +1 -1
  307. package/dist/core/runs/operations.js +5 -5
  308. package/dist/core/runs/questions.js +2 -2
  309. package/dist/core/runtime/bearings-render.d.ts +13 -7
  310. package/dist/core/runtime/bearings-render.js +12 -12
  311. package/dist/core/runtime/bearings.d.ts +8 -18
  312. package/dist/core/runtime/bearings.js +7 -7
  313. package/dist/core/runtime/broker/daemon-ops.d.ts +7 -12
  314. package/dist/core/runtime/broker/daemon-ops.js +1 -1
  315. package/dist/core/runtime/broker/fault-retry.d.ts +2 -0
  316. package/dist/core/runtime/broker/fault-retry.js +1 -1
  317. package/dist/core/runtime/broker/frame-dispatch.d.ts +1 -1
  318. package/dist/core/runtime/broker/frame-memory-refs.d.ts +7 -2
  319. package/dist/core/runtime/broker/frame-memory-refs.js +1 -1
  320. package/dist/core/runtime/broker/inbox.d.ts +1 -4
  321. package/dist/core/runtime/broker/inbox.js +1 -10
  322. package/dist/core/runtime/broker/rebind.js +1 -1
  323. package/dist/core/runtime/broker/retry-card-elision.d.ts +7 -0
  324. package/dist/core/runtime/broker/retry-card-elision.js +1 -0
  325. package/dist/core/runtime/broker-extension-render.d.ts +0 -13
  326. package/dist/core/runtime/broker-extension-render.js +2 -4
  327. package/dist/core/runtime/broker-persona-guidance.js +3 -3
  328. package/dist/core/runtime/broker-protocol.d.ts +1 -1
  329. package/dist/core/runtime/broker.js +1 -1
  330. package/dist/core/runtime/close.d.ts +9 -4
  331. package/dist/core/runtime/close.js +1 -1
  332. package/dist/core/runtime/deliver-live.js +1 -1
  333. package/dist/core/runtime/kickoff.js +17 -19
  334. package/dist/core/runtime/launch-target.d.ts +7 -0
  335. package/dist/core/runtime/launch-target.js +1 -1
  336. package/dist/core/runtime/ledger.d.ts +10 -0
  337. package/dist/core/runtime/ledger.js +3 -0
  338. package/dist/core/runtime/lifecycle.js +2 -2
  339. package/dist/core/runtime/nodes.d.ts +10 -2
  340. package/dist/core/runtime/nodes.js +1 -1
  341. package/dist/core/runtime/outcome-document.d.ts +2 -2
  342. package/dist/core/runtime/outcome-document.js +1 -1
  343. package/dist/core/runtime/persona.js +2 -2
  344. package/dist/core/runtime/placement.js +1 -1
  345. package/dist/core/runtime/promote.d.ts +2 -2
  346. package/dist/core/runtime/promote.js +1 -1
  347. package/dist/core/runtime/prospective-inventory-cli.js +2 -2
  348. package/dist/core/runtime/recycle.js +1 -1
  349. package/dist/core/runtime/reopen.js +1 -1
  350. package/dist/core/runtime/revive.js +2 -2
  351. package/dist/core/runtime/roadmap.d.ts +20 -9
  352. package/dist/core/runtime/roadmap.js +10 -6
  353. package/dist/core/runtime/spawn-env.js +1 -1
  354. package/dist/core/runtime/spawn.d.ts +5 -3
  355. package/dist/core/runtime/spawn.js +2 -2
  356. package/dist/core/runtime/structured-output.d.ts +3 -1
  357. package/dist/core/runtime/structured-output.js +4 -4
  358. package/dist/core/scope.d.ts +1 -32
  359. package/dist/core/scope.js +1 -1
  360. package/dist/core/scoped-state/db.js +2 -1
  361. package/dist/core/scoped-state/migrate.js +2 -2
  362. package/dist/core/scoped-state/profiles.d.ts +11 -0
  363. package/dist/core/scoped-state/profiles.js +1 -1
  364. package/dist/core/scoped-state/schema.d.ts +1 -1
  365. package/dist/core/scoped-state/schema.js +7 -5
  366. package/dist/core/spaces/permissions.d.ts +0 -14
  367. package/dist/core/spaces/permissions.js +1 -1
  368. package/dist/core/spaces/stop.d.ts +13 -0
  369. package/dist/core/spaces/stop.js +2 -2
  370. package/dist/core/storage/tables.d.ts +1 -1
  371. package/dist/core/substrate/delivery/corpus.d.ts +21 -0
  372. package/dist/core/substrate/delivery/corpus.js +3 -0
  373. package/dist/core/substrate/delivery/deliver.d.ts +76 -0
  374. package/dist/core/substrate/delivery/deliver.js +6 -0
  375. package/dist/core/substrate/delivery/listings.d.ts +30 -0
  376. package/dist/core/substrate/delivery/listings.js +7 -0
  377. package/dist/core/substrate/delivery/match.d.ts +28 -0
  378. package/dist/core/substrate/delivery/match.js +1 -0
  379. package/dist/core/substrate/delivery/plan.d.ts +67 -0
  380. package/dist/core/substrate/delivery/plan.js +3 -0
  381. package/dist/core/substrate/delivery/render-boot.d.ts +20 -0
  382. package/dist/core/substrate/delivery/render-boot.js +54 -0
  383. package/dist/core/substrate/delivery/render-event.d.ts +54 -0
  384. package/dist/core/substrate/delivery/render-event.js +8 -0
  385. package/dist/core/substrate/delivery/sub-persona-menu.d.ts +2 -0
  386. package/dist/core/substrate/delivery/sub-persona-menu.js +6 -0
  387. package/dist/core/substrate/delivery/types.d.ts +30 -0
  388. package/dist/core/substrate/delivery/types.js +0 -0
  389. package/dist/core/substrate/gate-explain.d.ts +0 -13
  390. package/dist/core/substrate/gate-explain.js +1 -1
  391. package/dist/core/substrate/schema.d.ts +11 -139
  392. package/dist/core/substrate/schema.js +1 -1
  393. package/dist/core/substrate/subject-fields.d.ts +3 -0
  394. package/dist/core/substrate/subject.d.ts +2 -1
  395. package/dist/core/substrate/subject.js +1 -1
  396. package/dist/daemon/api/handlers/app-profiles.js +1 -1
  397. package/dist/daemon/api/handlers/bash-jobs.js +1 -2
  398. package/dist/daemon/api/handlers/broker-ops.js +1 -1
  399. package/dist/daemon/api/handlers/canvas.js +5 -5
  400. package/dist/daemon/api/handlers/daemon.js +1 -1
  401. package/dist/daemon/api/handlers/delivery.d.ts +2 -0
  402. package/dist/daemon/api/handlers/delivery.js +1 -0
  403. package/dist/daemon/api/handlers/{memory.d.ts → docs.d.ts} +1 -1
  404. package/dist/daemon/api/handlers/docs.js +1 -0
  405. package/dist/daemon/api/handlers/hook-exec.js +1 -1
  406. package/dist/daemon/api/handlers/messages.js +2 -2
  407. package/dist/daemon/api/handlers/node-records.js +2 -2
  408. package/dist/daemon/api/handlers/nodes.js +1 -1
  409. package/dist/daemon/api/handlers/objects.d.ts +2 -0
  410. package/dist/daemon/api/handlers/objects.js +5 -0
  411. package/dist/daemon/api/handlers/package-docs.d.ts +2 -0
  412. package/dist/daemon/api/handlers/package-docs.js +1 -0
  413. package/dist/daemon/api/handlers/profiles.js +1 -1
  414. package/dist/daemon/api/handlers/reports.d.ts +2 -2
  415. package/dist/daemon/api/handlers/reports.js +4 -4
  416. package/dist/daemon/api/handlers/reviews.d.ts +4 -1
  417. package/dist/daemon/api/handlers/reviews.js +1 -1
  418. package/dist/daemon/api/map.d.ts +2 -2
  419. package/dist/daemon/api/map.js +2 -2
  420. package/dist/daemon/api/operations.d.ts +1 -1
  421. package/dist/daemon/api/operations.js +1 -1
  422. package/dist/daemon/api/reader.d.ts +17 -0
  423. package/dist/daemon/api/reader.js +1 -0
  424. package/dist/daemon/api/server.js +1 -1
  425. package/dist/daemon/control.d.ts +2 -3
  426. package/dist/daemon/crtrd.js +8 -6
  427. package/dist/daemon/fleet.js +4 -4
  428. package/dist/daemon/reconcilers/bash-deadline.d.ts +11 -1
  429. package/dist/daemon/reconcilers/bash-deadline.js +2 -1
  430. package/dist/daemon/reconcilers/broker-supervision.js +4 -4
  431. package/dist/daemon/reconcilers/live-obligation.js +1 -1
  432. package/dist/daemon/reconcilers/node-deadline.js +1 -1
  433. package/dist/daemon/reconcilers/node-lifecycle/freeze-lane.js +1 -1
  434. package/dist/daemon/reconcilers/storage-maintenance.d.ts +1 -0
  435. package/dist/daemon/reconcilers/storage-maintenance.js +1 -1
  436. package/dist/daemon/review/deliver.js +2 -2
  437. package/dist/daemon/review/finish.js +1 -1
  438. package/dist/hook-authoring.d.ts +0 -1
  439. package/dist/hook-authoring.js +3 -3
  440. package/dist/migrations/004-canvas-documents/apply.d.ts +10 -0
  441. package/dist/migrations/004-canvas-documents/apply.js +1 -0
  442. package/dist/migrations/004-canvas-documents/fields.d.ts +24 -0
  443. package/dist/migrations/004-canvas-documents/fields.js +2 -0
  444. package/dist/migrations/004-canvas-documents/index.d.ts +16 -0
  445. package/dist/migrations/004-canvas-documents/index.js +2 -0
  446. package/dist/migrations/004-canvas-documents/legacy/discover.d.ts +16 -0
  447. package/dist/migrations/004-canvas-documents/legacy/discover.js +1 -0
  448. package/dist/migrations/004-canvas-documents/legacy/history.d.ts +5 -0
  449. package/dist/migrations/004-canvas-documents/legacy/history.js +2 -0
  450. package/dist/migrations/004-canvas-documents/legacy/nested.d.ts +7 -0
  451. package/dist/migrations/004-canvas-documents/legacy/nested.js +1 -0
  452. package/dist/migrations/004-canvas-documents/legacy/parse.d.ts +14 -0
  453. package/dist/migrations/004-canvas-documents/legacy/parse.js +1 -0
  454. package/dist/migrations/004-canvas-documents/legacy/types.d.ts +91 -0
  455. package/dist/migrations/004-canvas-documents/legacy/types.js +0 -0
  456. package/dist/migrations/004-canvas-documents/legacy-edges.d.ts +6 -0
  457. package/dist/migrations/004-canvas-documents/legacy-edges.js +18 -0
  458. package/dist/migrations/004-canvas-documents/plan.d.ts +102 -0
  459. package/dist/migrations/004-canvas-documents/plan.js +3 -0
  460. package/dist/migrations/004-canvas-documents/pointers.d.ts +23 -0
  461. package/dist/migrations/004-canvas-documents/pointers.js +4 -0
  462. package/dist/migrations/activation.d.ts +9 -18
  463. package/dist/migrations/activation.js +2 -2
  464. package/dist/pi-extensions/broker-local.d.ts +2 -2
  465. package/dist/pi-extensions/broker-local.js +2 -2
  466. package/dist/pi-extensions/canvas-bash-valve.js +5 -4
  467. package/dist/pi-extensions/canvas-context-intro.js +2 -2
  468. package/dist/pi-extensions/canvas-doc-substrate.d.ts +0 -1
  469. package/dist/pi-extensions/canvas-doc-substrate.js +6 -6
  470. package/dist/pi-extensions/canvas-inbox-watcher.js +2 -2
  471. package/dist/pi-extensions/canvas-passive-context.js +1 -1
  472. package/dist/pi-extensions/canvas-recap.js +2 -2
  473. package/dist/pi-extensions/canvas-stophook.d.ts +1 -1
  474. package/dist/pi-extensions/canvas-stophook.js +1 -1
  475. package/dist/prompts/review.js +3 -3
  476. package/dist/shared/env.d.ts +5 -0
  477. package/dist/shared/env.js +1 -1
  478. package/dist/shared/generated-context.js +2 -10
  479. package/dist/shared/inbox-entry-body.d.ts +22 -0
  480. package/dist/shared/inbox-entry-body.js +10 -0
  481. package/dist/{core/memory → shared}/inline-ref-guidance.d.ts +2 -2
  482. package/dist/shared/inline-ref-guidance.js +2 -0
  483. package/dist/types.d.ts +3 -1
  484. package/docs/cli/memory-and-preferences.md +12 -14
  485. package/docs/concepts/README.md +1 -1
  486. package/docs/concepts/lifecycle-and-wakes.md +1 -1
  487. package/docs/concepts/memory.md +15 -15
  488. package/docs/concepts/nodes-and-the-canvas.md +1 -1
  489. package/docs/concepts/profiles-kinds-and-modes.md +5 -5
  490. package/docs/concepts/scopes-and-trust.md +1 -1
  491. package/docs/concepts/why-a-daemon.md +1 -1
  492. package/docs/sdk/README.md +5 -6
  493. package/docs/sdk/errors.md +0 -13
  494. package/docs/sdk/guides/README.md +0 -1
  495. package/docs/sdk/nodes.md +0 -2
  496. package/docs/sdk/resources.md +0 -1
  497. package/package.json +2 -2
  498. package/packages/crouter-identity/package.json +1 -1
  499. package/runtime.lock.json +11 -11
  500. package/scripts/lib/isolation-env.mjs +8 -2
  501. package/dist/api/dto/memory.d.ts +0 -171
  502. package/dist/api/dto/memory.js +0 -1
  503. package/dist/builtin-memory/crouter-sdk/guides/app-memory.md +0 -73
  504. package/dist/builtin-memory/crouter-sdk/memory.md +0 -87
  505. package/dist/commands/broker-permissions.d.ts +0 -2
  506. package/dist/commands/broker-permissions.js +0 -1
  507. package/dist/commands/memory/client.d.ts +0 -11
  508. package/dist/commands/memory/client.js +0 -1
  509. package/dist/commands/memory/delete.d.ts +0 -1
  510. package/dist/commands/memory/delete.js +0 -1
  511. package/dist/commands/memory/edit.d.ts +0 -1
  512. package/dist/commands/memory/edit.js +0 -21
  513. package/dist/commands/memory/find.d.ts +0 -1
  514. package/dist/commands/memory/find.js +0 -1
  515. package/dist/commands/memory/history.d.ts +0 -1
  516. package/dist/commands/memory/history.js +0 -5
  517. package/dist/commands/memory/lint.d.ts +0 -1
  518. package/dist/commands/memory/lint.js +0 -1
  519. package/dist/commands/memory/list.d.ts +0 -1
  520. package/dist/commands/memory/list.js +0 -1
  521. package/dist/commands/memory/move.d.ts +0 -1
  522. package/dist/commands/memory/move.js +0 -1
  523. package/dist/commands/memory/origin.d.ts +0 -1
  524. package/dist/commands/memory/origin.js +0 -1
  525. package/dist/commands/memory/read.d.ts +0 -1
  526. package/dist/commands/memory/read.js +0 -6
  527. package/dist/commands/memory/shared.d.ts +0 -22
  528. package/dist/commands/memory/shared.js +0 -1
  529. package/dist/commands/memory/write.d.ts +0 -1
  530. package/dist/commands/memory/write.js +0 -13
  531. package/dist/commands/memory.js +0 -1
  532. package/dist/commands/node-inspect-artifacts.d.ts +0 -1
  533. package/dist/commands/node-inspect-artifacts.js +0 -8
  534. package/dist/core/help/memory-extensions.d.ts +0 -3
  535. package/dist/core/help/memory-extensions.js +0 -2
  536. package/dist/core/memory/cli-selector.d.ts +0 -13
  537. package/dist/core/memory/cli-selector.js +0 -1
  538. package/dist/core/memory/doc-link-grammar.d.ts +0 -20
  539. package/dist/core/memory/doc-link-grammar.js +0 -2
  540. package/dist/core/memory/extensions.js +0 -1
  541. package/dist/core/memory/history.d.ts +0 -87
  542. package/dist/core/memory/history.js +0 -6
  543. package/dist/core/memory/identity.d.ts +0 -65
  544. package/dist/core/memory/identity.js +0 -1
  545. package/dist/core/memory/inline-ref-guidance.js +0 -2
  546. package/dist/core/memory/inline-ref-inventory.d.ts +0 -9
  547. package/dist/core/memory/inline-ref-inventory.js +0 -1
  548. package/dist/core/memory/lint.d.ts +0 -163
  549. package/dist/core/memory/lint.js +0 -2
  550. package/dist/core/memory/mutation-domain.d.ts +0 -113
  551. package/dist/core/memory/mutation-domain.js +0 -12
  552. package/dist/core/memory/mutations.d.ts +0 -74
  553. package/dist/core/memory/mutations.js +0 -1
  554. package/dist/core/memory/project-namespace.d.ts +0 -31
  555. package/dist/core/memory/project-namespace.js +0 -2
  556. package/dist/core/memory/repository-association.d.ts +0 -31
  557. package/dist/core/memory/repository-association.js +0 -1
  558. package/dist/core/memory/service.d.ts +0 -145
  559. package/dist/core/memory/service.js +0 -2
  560. package/dist/core/memory/tree.d.ts +0 -39
  561. package/dist/core/memory/tree.js +0 -1
  562. package/dist/core/memory-resolver.d.ts +0 -280
  563. package/dist/core/memory-resolver.js +0 -2
  564. package/dist/core/nested-stores.d.ts +0 -18
  565. package/dist/core/nested-stores.js +0 -1
  566. package/dist/core/runtime/memory.d.ts +0 -3
  567. package/dist/core/runtime/memory.js +0 -1
  568. package/dist/core/substrate/frontmatter-validation.d.ts +0 -11
  569. package/dist/core/substrate/frontmatter-validation.js +0 -1
  570. package/dist/core/substrate/gate.d.ts +0 -16
  571. package/dist/core/substrate/gate.js +0 -1
  572. package/dist/core/substrate/index.d.ts +0 -18
  573. package/dist/core/substrate/index.js +0 -1
  574. package/dist/core/substrate/injected-store.d.ts +0 -75
  575. package/dist/core/substrate/injected-store.js +0 -2
  576. package/dist/core/substrate/listings.d.ts +0 -28
  577. package/dist/core/substrate/listings.js +0 -1
  578. package/dist/core/substrate/memory-events.d.ts +0 -6
  579. package/dist/core/substrate/memory-events.js +0 -1
  580. package/dist/core/substrate/on-read-node.d.ts +0 -6
  581. package/dist/core/substrate/on-read-node.js +0 -1
  582. package/dist/core/substrate/on-read.d.ts +0 -101
  583. package/dist/core/substrate/on-read.js +0 -9
  584. package/dist/core/substrate/plan.d.ts +0 -94
  585. package/dist/core/substrate/plan.js +0 -1
  586. package/dist/core/substrate/render-node.d.ts +0 -12
  587. package/dist/core/substrate/render-node.js +0 -1
  588. package/dist/core/substrate/render.d.ts +0 -41
  589. package/dist/core/substrate/render.js +0 -65
  590. package/dist/core/substrate/session-cache.d.ts +0 -27
  591. package/dist/core/substrate/session-cache.js +0 -1
  592. package/dist/core/substrate/surface-match.d.ts +0 -73
  593. package/dist/core/substrate/surface-match.js +0 -1
  594. package/dist/daemon/api/handlers/memory.js +0 -5
  595. package/dist/migrations/001-surfaces-frontmatter.d.ts +0 -2
  596. package/dist/migrations/001-surfaces-frontmatter.js +0 -1
  597. package/dist/migrations/002-profile-project-memory.d.ts +0 -2
  598. package/dist/migrations/002-profile-project-memory.js +0 -1
  599. package/dist/migrations/003-repository-root-memory-identity/front-door.d.ts +0 -26
  600. package/dist/migrations/003-repository-root-memory-identity/front-door.js +0 -11
  601. package/dist/migrations/003-repository-root-memory-identity/index.d.ts +0 -2
  602. package/dist/migrations/003-repository-root-memory-identity/index.js +0 -5
  603. package/dist/migrations/003-repository-root-memory-identity/references.d.ts +0 -95
  604. package/dist/migrations/003-repository-root-memory-identity/references.js +0 -5
  605. package/dist/migrations/003-repository-root-memory-identity/repository-facts.d.ts +0 -39
  606. package/dist/migrations/003-repository-root-memory-identity/repository-facts.js +0 -3
  607. package/dist/migrations/convergent.d.ts +0 -43
  608. package/dist/migrations/convergent.js +0 -2
  609. package/dist/migrations/corpus.d.ts +0 -75
  610. package/dist/migrations/corpus.js +0 -3
  611. package/dist/migrations/frontmatter-splice.d.ts +0 -15
  612. package/dist/migrations/frontmatter-splice.js +0 -8
  613. package/dist/migrations/profile-manifests.d.ts +0 -30
  614. package/dist/migrations/profile-manifests.js +0 -2
  615. package/dist/migrations/registry.d.ts +0 -7
  616. package/dist/migrations/registry.js +0 -1
  617. package/dist/migrations/runner.d.ts +0 -43
  618. package/dist/migrations/runner.js +0 -1
  619. package/dist/migrations/types.d.ts +0 -211
  620. package/dist/shared/birth-announcement.d.ts +0 -12
  621. package/dist/shared/birth-announcement.js +0 -1
  622. package/docs/sdk/guides/app-memory.md +0 -22
  623. package/docs/sdk/memory.md +0 -85
  624. /package/dist/{migrations/types.js → api/dto/delivery.js} +0 -0
  625. /package/dist/{core/memory → shared}/inline-ref-grammar.d.ts +0 -0
  626. /package/dist/{core/memory → shared}/inline-ref-grammar.js +0 -0
@@ -1,96 +1,123 @@
1
- import { type DeliveryPlan, type DeliveryRecord } from '../../../../core/substrate/plan.js';
2
- import { type EffectiveDeliveryRecord } from '../resolve.js';
3
- import { type Rung, type SurfaceEntry, type SurfaceEvent } from '../../../../core/substrate/schema.js';
4
- import { type NodeConfigSubject } from '../../../../core/substrate/subject-fields.js';
5
- import { type MemoryTarget } from '../../../../core/memory-resolver.js';
6
- /** The state an agent-engineer dials. Every axis feeds either the gate subject
7
- * or the store/cap resolution, and changing one re-plans every event. */
1
+ import type { DeliveryRuleDTO } from '../../../../api/dto/docs.js';
2
+ import type { NodeConfigSubject } from '../../../../core/substrate/subject-fields.js';
3
+ import { type ContextSnapshot, type PlanRecord, type PlanRule, type PlannedEvent } from '../resolve.js';
4
+ /** The state an agent-engineer dials. Every axis feeds either the rule `if`
5
+ * subject or the reader (cwd → repos, profile → limits), and changing one
6
+ * re-plans every activity. */
8
7
  export interface Snapshot {
9
8
  kind: string;
10
9
  mode: 'base' | 'orchestrator';
11
10
  lifecycle: 'terminal' | 'resident';
12
11
  hasManager: boolean;
12
+ /** Profile id; null for no profile. */
13
13
  profileId: string | null;
14
14
  cwd: string;
15
+ /** The live node the page opened on, or null. */
15
16
  nodeId: string | null;
16
17
  grantee?: string;
17
18
  depth: number;
18
- event: SurfaceEvent;
19
- /** `read` payload — the file that was read. */
19
+ event: PlannedEvent;
20
+ /** `file-read` payload — the file that was read. */
20
21
  file: string;
21
- /** `memory-read` payload — the canonical name the read resolved to. */
22
+ /** `document-read` payload — the document read. */
22
23
  docName: string;
23
24
  /** `command` / `pre-command` payload. */
24
25
  command: string;
26
+ /** The live node's own cwd and profile: while the snapshot keeps both, the
27
+ * dry run reads the node itself, so its own documents stay in view. */
28
+ seed: {
29
+ cwd: string;
30
+ profileId: string | null;
31
+ } | null;
25
32
  }
26
- export declare function subjectOf(snapshot: Snapshot): NodeConfigSubject;
27
- export declare function targetOf(snapshot: Snapshot): MemoryTarget;
28
- /** Which payload axis an event reads, so the rail offers exactly the one field
29
- * that can make the current event match anything. */
30
- export declare function payloadAxisFor(event: SurfaceEvent): 'file' | 'docName' | 'command' | null;
31
- /** Every plan for one snapshot, computed on demand.
32
- *
33
- * Each event's corpus is its own — workspace-open sees project stores only,
34
- * boot orders node-local documents last, read pulls in the stores enclosing
35
- * the read file — so a shared corpus would report a delivery the runtime would
36
- * never make. The planner therefore loads per event, and this cache keeps the
37
- * page responsive by resolving the focused event first and warming the rest
38
- * one macrotask at a time. */
33
+ /** One profile the rail can cycle through. */
34
+ export interface ProfileChoice {
35
+ id: string;
36
+ name: string;
37
+ }
38
+ /** A rule as the dry run returns it: the row fields over JSON. */
39
+ export interface AdminRule extends PlanRule {
40
+ position?: number;
41
+ }
42
+ /** The delivery document as the dry run serializes it (bodies are not carried). */
43
+ export interface AdminDoc {
44
+ object: {
45
+ id: string;
46
+ type: string;
47
+ name: string;
48
+ };
49
+ owner: {
50
+ id: string;
51
+ type: string;
52
+ name: string;
53
+ };
54
+ ownerHandle: string;
55
+ ownNode: boolean;
56
+ /** A package document: an installed plugin's or crtr's own, read-only here. */
57
+ shipped: boolean;
58
+ kind: 'knowledge' | 'preference';
59
+ name: string;
60
+ displayName: string;
61
+ preview: string;
62
+ unlisted: boolean;
63
+ rules: AdminRule[];
64
+ }
65
+ export type AdminRecord = Omit<PlanRecord, 'doc' | 'shadowedBy'> & {
66
+ doc: AdminDoc;
67
+ shadowedBy: AdminDoc | null;
68
+ };
69
+ export interface AdminPlan {
70
+ subject: NodeConfigSubject | null;
71
+ docs: AdminRecord[];
72
+ }
73
+ /** Which payload axis an activity reads, so the rail offers exactly the one
74
+ * field that can make the current activity match anything. */
75
+ export declare function payloadAxisFor(event: PlannedEvent): 'file' | 'docName' | 'command' | null;
76
+ /** The dry-run request a snapshot stands for: the live node as it is (the
77
+ * subject axes as overrides) while cwd and profile are still the node's own,
78
+ * else a node that does not exist, started from the live node when there is one. */
79
+ export declare function contextSnapshotOf(snapshot: Snapshot): ContextSnapshot;
80
+ /** Every activity's plan for one snapshot, fetched from the daemon. The
81
+ * focused activity is asked for first and the rest follow; a plan that lands
82
+ * after the snapshot changed is dropped. */
39
83
  export declare class PlanSet {
40
84
  private snapshot;
85
+ private readonly onChange;
41
86
  private readonly plans;
42
- private warming;
43
- constructor(snapshot: Snapshot);
87
+ /** Plans read for the current documents; a plan outside it is stale and is
88
+ * shown only until its replacement lands. */
89
+ private readonly fresh;
90
+ private readonly pending;
91
+ private generation;
92
+ /** The last dry run's refusal, shown in place of the list. */
93
+ error: string | undefined;
94
+ constructor(snapshot: Snapshot, onChange: () => void);
44
95
  setSnapshot(snapshot: Snapshot): void;
45
- /** Drop every plan — after a snapshot change, or after a mutation rewrote a
46
- * document the corpus was read from. */
96
+ /** Drop every plan — the snapshot changed, so none of them describes it. */
47
97
  invalidate(): void;
98
+ /** Re-read every plan after a write changed a document they were read from,
99
+ * keeping the old plans on screen until each replacement lands. */
100
+ refresh(): void;
48
101
  dispose(): void;
49
- /** The plan for one event, computing it now. */
50
- plan(event: SurfaceEvent): DeliveryPlan & {
51
- docs: EffectiveDeliveryRecord[];
52
- };
53
- /** The plan for one event only if it is already computed — what the rail's
54
- * EVENTS counts read, so an unwarmed event draws `…` instead of stalling the
55
- * frame on five extra corpus loads. */
56
- peek(event: SurfaceEvent): (DeliveryPlan & {
57
- docs: EffectiveDeliveryRecord[];
58
- }) | undefined;
59
- /** Compute one pending event per macrotask, calling back after each so the
60
- * rail's counts fill in row by row. */
61
- warm(onProgress: () => void): void;
62
- private payload;
102
+ peek(event: PlannedEvent): AdminPlan | undefined;
103
+ /** Fetch the focused activity, then every other one. */
104
+ warm(first: PlannedEvent): void;
105
+ private fetch;
63
106
  }
64
- /** What one document does in one event. */
107
+ /** What one document does in one activity. */
65
108
  export type DeliveryState = 'delivers' | 'capped' | 'gated' | 'shadowed' | 'silent';
66
- export declare function deliveryStateOf(record: DeliveryRecord | undefined): DeliveryState;
67
- /** The word the list prints for one document's state, and the tone it prints it
68
- * in. The vocabulary is the one the author already writes in frontmatter
69
- * (`at: content`), so the column needs no legend: a delivery names the rung it
70
- * arrives at, warning-toned when the profile ceiling trimmed it below what the
71
- * entry authored. A document that does not load renders nothing at all unless
72
- * its silence has a name the page can act on — `gated` or `shadowed`. */
73
- export declare function stateLabel(record: DeliveryRecord | undefined, state: DeliveryState): {
109
+ export declare function deliveryStateOf(record: AdminRecord | undefined): DeliveryState;
110
+ /** The word the list prints for one document's state, and its tone. A delivery
111
+ * names the level it arrives at, warning-toned when the profile limit lowered
112
+ * it; a document that does not load prints nothing unless its silence has a
113
+ * name the page can act on — `gated` or `shadowed`. */
114
+ export declare function stateLabel(record: AdminRecord | undefined, state: DeliveryState): {
74
115
  text: string;
75
116
  tone: 'success' | 'warning' | 'muted';
76
117
  };
77
- export declare function nextRung(rung: Rung, delta: number): Rung;
78
- /** A parsed entry back in the shape `memory edit --surface` accepts. The parsed
79
- * form always carries `match` as a list and spells its frontmatter key
80
- * `matchFrontmatter`; `coerceSurface` wants a bare string for a single glob
81
- * and the hyphenated key, and rejects anything else. */
82
- export declare function surfaceEntryToFlag(entry: SurfaceEntry): string;
83
- /** One authored entry as a single readable row. */
84
- export declare function describeSurfaceEntry(entry: SurfaceEntry): string;
118
+ export declare const DELIVER_LEVELS: ("name" | "preview" | "content")[];
119
+ /** A rule back in the shape `PATCH /v1/docs/:ref` takes. */
120
+ export declare function ruleToDTO(rule: AdminRule): DeliveryRuleDTO;
121
+ /** One rule as a single readable row. */
122
+ export declare function describeRule(rule: AdminRule): string;
85
123
  export declare function plural(count: number, one: string, many: string): string;
86
- /** What one document would cost at each rung, in approximate tokens. The
87
- * renderers decide the payload: `content` emits the body, `preview` emits the
88
- * catalog entry plus the routing line, `name` emits the entry alone. The
89
- * estimate is characters ÷ 4 — it ranks documents correctly and totals
90
- * approximately, and every place it renders says so. */
91
- export type RungCosts = Record<Rung, number>;
92
- export declare function rungCostsOf(record: DeliveryRecord): RungCosts;
93
- /** What this document actually spends in the event the record belongs to. */
94
- export declare function deliveredCost(record: DeliveryRecord | undefined): number;
95
- /** Approximate tokens in at most six columns, always marked as an estimate. */
96
- export declare function formatCost(count: number): string;
@@ -1 +1 @@
1
- var l=Object.defineProperty;var n=(e,t)=>l(e,"name",{value:t,configurable:!0});import{resolve as p}from"node:path";import{realpathOrSelf as g}from"../../../../core/fs-utils.js";import{planDelivery as w}from"../../../../core/substrate/plan.js";import{assembleEventAccounting as x,effectivePlan as F}from"../resolve.js";import{RUNGS as o,SURFACE_EVENTS as R,previewLine as S,rungRank as s}from"../../../../core/substrate/schema.js";import{effectiveScopes as N,scopeForCwd as $,profileNameFor as v}from"../../../../core/substrate/subject-fields.js";import{resolveMemoryDocForTarget as O}from"../../../../core/memory-resolver.js";function b(e){return{kind:e.kind,mode:e.mode,lifecycle:e.lifecycle,hasManager:e.hasManager,cwd:e.cwd,scope:$(e.cwd),orchestration:{depth:e.depth},profile:v(e.profileId),scopes:N(null)}}n(b,"subjectOf");function m(e){return{cwd:e.cwd,profileId:e.profileId,nodeId:e.nodeId,grantee:e.grantee}}n(m,"targetOf");function A(e){return e==="read"?"file":e==="memory-read"?"docName":e==="command"||e==="pre-command"?"command":null}n(A,"payloadAxisFor");class J{static{n(this,"PlanSet")}snapshot;plans=new Map;warming;constructor(t){this.snapshot=t}setSnapshot(t){this.snapshot=t,this.invalidate()}invalidate(){this.plans.clear(),this.warming!==void 0&&(clearTimeout(this.warming),this.warming=void 0)}dispose(){this.warming!==void 0&&clearTimeout(this.warming),this.warming=void 0}plan(t){const i=this.plans.get(t);if(i!==void 0)return i;const a=b(this.snapshot),u=m(this.snapshot),r=this.payload(t),c=w(a,u,t,r),h=x({subject:a,target:u,nodeMissing:!1},t,r),f=F(c,h.accounting.deliveries,r);return this.plans.set(t,f),f}peek(t){return this.plans.get(t)}warm(t){if(this.warming!==void 0)return;const i=R.find(a=>!this.plans.has(a));i!==void 0&&(this.warming=setTimeout(()=>{this.warming=void 0,this.plan(i),t(),this.warm(t)},0))}payload(t){return t==="read"?this.snapshot.file===""?{}:{absoluteFile:p(this.snapshot.cwd,this.snapshot.file)}:t==="memory-read"?this.snapshot.docName===""?{}:{resolvedCanonicalName:this.snapshot.docName,resolvedDocPath:k(this.snapshot.docName,m(this.snapshot))}:t==="command"||t==="pre-command"?this.snapshot.command===""?{}:{command:this.snapshot.command}:{}}}function k(e,t){try{return g(O(e,t).path)}catch{return""}}n(k,"resolvedDocRealpath");function P(e){return e===void 0?"silent":e.docGate.pass?e.shadowedBy!==null?"shadowed":e.finalRung!=="none"?s(e.finalRung)<s(e.authoredRung)?"capped":"delivers":e.authoredRung!=="none"?"capped":e.entryGate!==null&&!e.entryGate.pass?"gated":"silent":"gated"}n(P,"deliveryStateOf");function L(e,t){return t==="gated"?{text:"gated",tone:"muted"}:t==="shadowed"?{text:"shadowed",tone:"muted"}:e===void 0||e.finalRung==="none"?{text:"",tone:"muted"}:{text:e.finalRung,tone:t==="capped"?"warning":"success"}}n(L,"stateLabel");function U(e,t){const i=(s(e)+t+o.length)%o.length;return o[i]}n(U,"nextRung");function _(e){const t=e.match===void 0||e.match.length===0?void 0:e.match.length===1?e.match[0]:e.match;return JSON.stringify({on:e.on,...t===void 0?{}:{match:t},...e.matchFrontmatter===void 0?{}:{"match-frontmatter":e.matchFrontmatter},...e.gate===void 0?{}:{gate:e.gate},at:e.at})}n(_,"surfaceEntryToFlag");function B(e){const t=[e.on];return e.match!==void 0&&e.match.length>0&&t.push(e.match.join(" | ")),e.matchFrontmatter!==void 0&&t.push(`fm ${JSON.stringify(e.matchFrontmatter)}`),e.gate!==void 0&&t.push(`gate ${JSON.stringify(e.gate)}`),`${t.join(" ")} \u2192 ${e.at}`}n(B,"describeSurfaceEntry");function V(e,t,i){return`${e} ${e===1?t:i}`}n(V,"plural");function M(e){const t=e.name.length,i=S(e.doc).length;return{none:0,name:d(t),preview:d(t+i),content:d(e.doc.body.length)}}n(M,"rungCostsOf");function q(e){return e===void 0?0:M(e)[e.finalRung]}n(q,"deliveredCost");function d(e){return Math.ceil(e/4)}n(d,"tokens");function z(e){return e<=0?"":e<1e3?`~${e}`:e<1e4?`~${(e/1e3).toFixed(1)}k`:`~${Math.round(e/1e3)}k`}n(z,"formatCost");export{J as PlanSet,q as deliveredCost,P as deliveryStateOf,B as describeSurfaceEntry,z as formatCost,U as nextRung,A as payloadAxisFor,V as plural,M as rungCostsOf,L as stateLabel,b as subjectOf,_ as surfaceEntryToFlag,m as targetOf};
1
+ var a=Object.defineProperty;var i=(e,n)=>a(e,"name",{value:n,configurable:!0});import{resolve as f}from"node:path";import{RUNGS as o,rungRank as r}from"../../../../core/substrate/schema.js";import{PLANNED_EVENTS as u,dryRun as c}from"../resolve.js";function x(e){return e==="file-read"?"file":e==="document-read"?"docName":e==="command"||e==="pre-command"?"command":null}i(x,"payloadAxisFor");function h(e){const n={kind:e.kind,mode:e.mode,lifecycle:e.lifecycle,hasManager:e.hasManager,orchestration:{depth:e.depth}},t=e.seed;if(e.nodeId!==null&&t!==null&&t.cwd===e.cwd&&t.profileId===e.profileId)return{nodeId:e.nodeId,hypothetical:null,override:n,nodeMissing:!1};const d={cwd:e.cwd,profile:e.profileId,...e.grantee===void 0?{}:{grantee:e.grantee},kind:e.kind,mode:e.mode,lifecycle:e.lifecycle,has_manager:e.hasManager,depth:e.depth};return{nodeId:e.nodeId,hypothetical:d,override:{},nodeMissing:!1}}i(h,"contextSnapshotOf");function s(e,n){if(n==="file-read")return e.file===""?void 0:f(e.cwd,e.file);if(n==="document-read")return e.docName===""?void 0:e.docName;if(n==="command"||n==="pre-command")return e.command===""?void 0:e.command}i(s,"payloadOf");class w{static{i(this,"PlanSet")}snapshot;onChange;plans=new Map;fresh=new Set;pending=new Set;generation=0;error;constructor(n,t){this.snapshot=n,this.onChange=t}setSnapshot(n){this.snapshot=n,this.invalidate()}invalidate(){this.plans.clear(),this.refresh()}refresh(){this.generation+=1,this.fresh.clear(),this.pending.clear(),this.error=void 0}dispose(){this.generation+=1}peek(n){return this.plans.get(n)}warm(n){this.fetch(n);for(const t of u)this.fetch(t)}fetch(n){if(this.fresh.has(n)||this.pending.has(n))return;this.pending.add(n);const t=this.generation;c(h(this.snapshot),n,s(this.snapshot,n)).then(({plan:d})=>{t===this.generation&&(this.pending.delete(n),this.plans.set(n,{subject:d.subject,docs:d.docs}),this.fresh.add(n),this.onChange())},d=>{t===this.generation&&(this.pending.delete(n),this.plans.set(n,{subject:null,docs:[]}),this.fresh.add(n),this.error=d instanceof Error?d.message:String(d),this.onChange())})}}function y(e){return e===void 0?"silent":e.shadowedBy!==null?"shadowed":e.finalRung!=="none"?r(e.finalRung)<r(e.authoredRung)?"capped":"delivers":e.authoredRung!=="none"?"capped":e.matchedRule===null&&e.ruleGate!==null&&!e.ruleGate.pass?"gated":"silent"}i(y,"deliveryStateOf");function R(e,n){return n==="gated"?{text:"gated",tone:"muted"}:n==="shadowed"?{text:"shadowed",tone:"muted"}:e===void 0||e.finalRung==="none"?{text:"",tone:"muted"}:{text:e.finalRung,tone:n==="capped"?"warning":"success"}}i(R,"stateLabel");const S=o.filter(e=>e!=="none");function I(e){return{on:e.on,...e.match===void 0?{}:{match:e.match},...e.matchFrontmatter===void 0?{}:{match_frontmatter:e.matchFrontmatter},...e.if===void 0?{}:{if:e.if},deliver:e.deliver}}i(I,"ruleToDTO");function N(e){const n=[e.on];return e.match!==void 0&&e.match.length>0&&n.push(e.match.join(" | ")),e.matchFrontmatter!==void 0&&n.push(`fm ${JSON.stringify(e.matchFrontmatter)}`),e.if!==void 0&&n.push(`if ${JSON.stringify(e.if)}`),`${n.join(" ")} \u2192 ${e.deliver}`}i(N,"describeRule");function E(e,n,t){return`${e} ${e===1?n:t}`}i(E,"plural");export{S as DELIVER_LEVELS,w as PlanSet,h as contextSnapshotOf,y as deliveryStateOf,N as describeRule,x as payloadAxisFor,E as plural,I as ruleToDTO,R as stateLabel};
@@ -1,6 +1,7 @@
1
- import { type SurfaceEvent } from '../../../../core/substrate/schema.js';
2
- import { type Snapshot } from './model.js';
3
- import type { Filters } from './list-view.js';
1
+ import { type PlannedEvent } from '../resolve.js';
2
+ import { type ProfileChoice, type Snapshot } from './model.js';
3
+ import { type Filters } from './list-view.js';
4
+ type SurfaceEvent = PlannedEvent;
4
5
  export type AxisId = 'event' | 'payload' | 'kind' | 'mode' | 'lifecycle' | 'manager' | 'depth' | 'profile' | 'cwd';
5
6
  export interface Axis {
6
7
  id: AxisId;
@@ -31,12 +32,12 @@ export declare function axesOf(snapshot: Snapshot, profileName: string): Axis[];
31
32
  export declare function payloadRowOf(snapshot: Snapshot): Axis | undefined;
32
33
  /** Cycle one enum axis, returning the changed snapshot. A typed axis is never
33
34
  * cycled — the shell opens a field for it instead. */
34
- export declare function cycleAxis(snapshot: Snapshot, id: AxisId, delta: number): Snapshot;
35
+ export declare function cycleAxis(snapshot: Snapshot, id: AxisId, delta: number, profiles?: readonly ProfileChoice[]): Snapshot;
35
36
  /** Apply a typed axis's submitted value. */
36
37
  export declare function setTypedAxis(snapshot: Snapshot, id: AxisId, value: string): Snapshot;
37
38
  /** The value a typed axis's field is seeded with. */
38
39
  export declare function typedAxisValue(snapshot: Snapshot, id: AxisId): string;
39
- /** One surface event as the rail states it: how many documents it delivers, and
40
+ /** One activity as the rail states it: how many documents it delivers, and
40
41
  * whether it is the one the page is planning. `delivers` is undefined while
41
42
  * that event's plan is still warming. */
42
43
  export interface EventRow {
@@ -80,3 +81,4 @@ export declare function renderRail(opts: {
80
81
  matched: number;
81
82
  total: number;
82
83
  }): string[];
84
+ export {};
@@ -1 +1 @@
1
- var _=Object.defineProperty;var c=(e,t)=>_(e,"name",{value:t,configurable:!0});import{truncateToWidth as k}from"@earendil-works/pi-tui";import{padAnsi as p,theme as s}from"../../../../core/tui/panel.js";import{tildify as C}from"../../../../core/fs-utils.js";import{KINDS as q,RUNGS as L,SURFACE_EVENTS as D}from"../../../../core/substrate/schema.js";import{listProfiles as G}from"../../../../core/profiles/manifest.js";import{payloadAxisFor as b}from"./model.js";const K=["any",...L.filter(e=>e!=="none"),"silent"],U=["any","project","user","profile","builtin","node"],V=["any",...q],B=["any","delivering","gated","shadowed","no-entry"];function X(e){return[{id:"rung",label:"rung",value:e.rung,typed:!1},{id:"origin",label:"origin",value:e.origin,typed:!1},{id:"kind",label:"doc kind",value:e.kind,typed:!1},{id:"state",label:"state",value:e.state,typed:!1},{id:"query",label:"search",value:e.query===""?"any":e.query,typed:!0}]}c(X,"facetsOf");function Y(e,t,r){const i=c((n,a)=>{const y=n.indexOf(a);return n[(Math.max(0,y)+r+n.length)%n.length]},"step");switch(t){case"rung":return{...e,rung:i(K,e.rung)};case"origin":return{...e,origin:i(U,e.origin)};case"kind":return{...e,kind:i(V,e.kind)};case"state":return{...e,state:i(B,e.state)};case"query":return e}}c(Y,"cycleFacet");function Z(e,t){return[{id:"kind",label:"kind",value:e.kind,typed:!0},{id:"mode",label:"mode",value:e.mode,typed:!1},{id:"lifecycle",label:"lifecycle",value:e.lifecycle,typed:!1},{id:"manager",label:"manager",value:e.hasManager?"yes":"no",typed:!1},{id:"depth",label:"depth",value:String(e.depth),typed:!1},{id:"profile",label:"profile",value:t,typed:!1},{id:"cwd",label:"cwd",value:C(e.cwd),typed:!0}]}c(Z,"axesOf");function w(e){const t=b(e.event);if(t===null)return;const r=t==="file"?e.file:t==="docName"?e.docName:e.command;return{id:"payload",label:t==="file"?"file":t==="docName"?"doc":"command",value:r===""?"(none \u2014 nothing matches)":r,typed:!0}}c(w,"payloadRowOf");function ee(e,t,r){const i=c((n,a)=>{const y=n.indexOf(a);return n[(Math.max(0,y)+r+n.length)%n.length]},"step");switch(t){case"event":return{...e,event:i(D,e.event)};case"mode":{const n=i(["base","orchestrator"],e.mode);return{...e,mode:n,lifecycle:n==="orchestrator"?"resident":"terminal"}}case"lifecycle":return{...e,lifecycle:i(["terminal","resident"],e.lifecycle)};case"manager":return{...e,hasManager:!e.hasManager};case"depth":return{...e,depth:Math.max(0,e.depth+r)};case"profile":{const n=[null,...G().map(a=>a.profileId)];return{...e,profileId:i(n,e.profileId)}}default:return e}}c(ee,"cycleAxis");function ne(e,t,r){const i=r.trim();if(t==="kind")return i===""?e:{...e,kind:i};if(t==="cwd")return i===""?e:{...e,cwd:i};if(t!=="payload")return e;const n=b(e.event);return n==="file"?{...e,file:i}:n==="docName"?{...e,docName:i}:n==="command"?{...e,command:i}:e}c(ne,"setTypedAxis");function te(e,t){if(t==="kind")return e.kind;if(t==="cwd")return e.cwd;const r=b(e.event);return r==="file"?e.file:r==="docName"?e.docName:r==="command"?e.command:""}c(te,"typedAxisValue");const M=10;function ie(e){return e.kind==="event"?`event:${e.event.event}`:e.kind==="axis"?`axis:${e.axis.id}`:`facet:${e.facet.id}`}c(ie,"railRowKey");function de(e){return e===void 0?"documents":e.kind==="event"?"dial":e.kind==="axis"?e.axis.typed?"edit":"documents":e.facet.typed?"edit":"documents"}c(de,"railEnter");function re(e,t,r,i){const n=[];for(const a of e)n.push({kind:"event",event:a}),a.dialled&&t!==void 0&&n.push({kind:"axis",axis:t,indent:!0});for(const a of r)n.push({kind:"axis",axis:a,indent:!1});for(const a of i)n.push({kind:"facet",facet:a});return n}c(re,"railRowsOf");function ce(e){const{rows:t,index:r,width:i,height:n,focused:a,matched:y,total:T}=e,u=[];let $=0;const S=c((d,l,o,m,f)=>{d===r&&($=u.length),d===r&&a?u.push(s.bg("selectedBg",p(o,i))):d===r||l?u.push(`${s.fg("accent","\u258C")}${p(s.fg("accent",f),i-1)}`):u.push(p(m,i))},"push"),N=c((d,l,o,m)=>{const f=Math.max(1,M-m),x=Math.max(1,i-M-2),g=`${" ".repeat(m)}${p(k(l,f),f)}`,h=k(o,x);S(d,!1,` ${g} ${h}`,` ${s.fg("dim",g)} ${h}`,`${g} ${h}`)},"labelled"),R=c((d,l)=>{const o=l.delivers===void 0?"\u2026":String(l.delivers),m=l.delivers===void 0||l.delivers===0?"dim":"success",f=Math.max(1,i-2-o.length),x=p(k(l.event,f),f),g=s.fg(m,o);S(d,l.dialled,` ${x} ${g}`,` ${s.fg("dim",x)} ${g}`,`${x} ${o}`)},"evented"),I=c(d=>d.kind==="facet"?"filters":d.kind==="event"||d.indent?"events":"snapshot","sectionOf"),O={events:" EVENTS",snapshot:" SNAPSHOT",filters:` FILTERS \xB7 ${y} of ${T}`};let E;t.forEach((d,l)=>{const o=I(d);o!==E&&(u.length>0&&u.push(""),u.push(s.fg("dim",O[o]),""),E=o),d.kind==="event"?R(l,d.event):d.kind==="axis"?N(l,d.axis.label,d.axis.value,d.indent?2:0):N(l,d.facet.label,d.facet.value,0)});const F=Math.max(0,u.length-n),A=Math.min(Math.max(0,$-Math.floor(n/2)),F),v=u.slice(A,A+n);for(;v.length<n;)v.push("");return v}c(ce,"renderRail");export{Z as axesOf,ee as cycleAxis,Y as cycleFacet,X as facetsOf,w as payloadRowOf,de as railEnter,ie as railRowKey,re as railRowsOf,ce as renderRail,ne as setTypedAxis,te as typedAxisValue};
1
+ var _=Object.defineProperty;var c=(e,n)=>_(e,"name",{value:n,configurable:!0});import{resolve as L}from"node:path";import{truncateToWidth as $}from"@earendil-works/pi-tui";import{padAnsi as v,theme as s}from"../../../../core/tui/panel.js";import{tildify as q}from"../../../../core/fs-utils.js";import{KINDS as C,RUNGS as D}from"../../../../core/substrate/schema.js";import{PLANNED_EVENTS as P}from"../resolve.js";import{payloadAxisFor as b}from"./model.js";import{OWNER_TYPES as G}from"./list-view.js";const K=["any",...D.filter(e=>e!=="none"),"silent"],V=["any",...G],W=["any",...C],B=["any","delivering","gated","shadowed","no-rule"];function w(e){return[{id:"rung",label:"rung",value:e.rung,typed:!1},{id:"origin",label:"owner",value:e.origin,typed:!1},{id:"kind",label:"doc kind",value:e.kind,typed:!1},{id:"state",label:"state",value:e.state,typed:!1},{id:"query",label:"search",value:e.query===""?"any":e.query,typed:!0}]}c(w,"facetsOf");function ee(e,n,a){const i=c((t,r)=>{const f=t.indexOf(r);return t[(Math.max(0,f)+a+t.length)%t.length]},"step");switch(n){case"rung":return{...e,rung:i(K,e.rung)};case"origin":return{...e,origin:i(V,e.origin)};case"kind":return{...e,kind:i(W,e.kind)};case"state":return{...e,state:i(B,e.state)};case"query":return e}}c(ee,"cycleFacet");function ne(e,n){return[{id:"kind",label:"kind",value:e.kind,typed:!0},{id:"mode",label:"mode",value:e.mode,typed:!1},{id:"lifecycle",label:"lifecycle",value:e.lifecycle,typed:!1},{id:"manager",label:"manager",value:e.hasManager?"yes":"no",typed:!1},{id:"depth",label:"depth",value:String(e.depth),typed:!1},{id:"profile",label:"profile",value:n,typed:!1},{id:"cwd",label:"cwd",value:q(e.cwd),typed:!0}]}c(ne,"axesOf");function te(e){const n=b(e.event);if(n===null)return;const a=n==="file"?e.file:n==="docName"?e.docName:e.command;return{id:"payload",label:n==="file"?"file":n==="docName"?"doc":"command",value:a===""?"(none \u2014 nothing matches)":a,typed:!0}}c(te,"payloadRowOf");function ie(e,n,a,i=[]){const t=c((r,f)=>{const p=r.indexOf(f);return r[(Math.max(0,p)+a+r.length)%r.length]},"step");switch(n){case"event":return{...e,event:t(P,e.event)};case"mode":{const r=t(["base","orchestrator"],e.mode);return{...e,mode:r,lifecycle:r==="orchestrator"?"resident":"terminal"}}case"lifecycle":return{...e,lifecycle:t(["terminal","resident"],e.lifecycle)};case"manager":return{...e,hasManager:!e.hasManager};case"depth":return{...e,depth:Math.max(0,e.depth+a)};case"profile":{const r=[null,...i.map(f=>f.id)];return{...e,profileId:t(r,e.profileId)}}default:return e}}c(ie,"cycleAxis");function de(e,n,a){const i=a.trim();if(n==="kind")return i===""?e:{...e,kind:i};if(n==="cwd")return i===""?e:{...e,cwd:L(i)};if(n!=="payload")return e;const t=b(e.event);return t==="file"?{...e,file:i}:t==="docName"?{...e,docName:i}:t==="command"?{...e,command:i}:e}c(de,"setTypedAxis");function re(e,n){if(n==="kind")return e.kind;if(n==="cwd")return e.cwd;const a=b(e.event);return a==="file"?e.file:a==="docName"?e.docName:a==="command"?e.command:""}c(re,"typedAxisValue");const M=10;function ae(e){return e.kind==="event"?`event:${e.event.event}`:e.kind==="axis"?`axis:${e.axis.id}`:`facet:${e.facet.id}`}c(ae,"railRowKey");function ce(e){return e===void 0?"documents":e.kind==="event"?"dial":e.kind==="axis"?e.axis.typed?"edit":"documents":e.facet.typed?"edit":"documents"}c(ce,"railEnter");function le(e,n,a,i){const t=[];for(const r of e)t.push({kind:"event",event:r}),r.dialled&&n!==void 0&&t.push({kind:"axis",axis:n,indent:!0});for(const r of a)t.push({kind:"axis",axis:r,indent:!1});for(const r of i)t.push({kind:"facet",facet:r});return t}c(le,"railRowsOf");function oe(e){const{rows:n,index:a,width:i,height:t,focused:r,matched:f,total:p}=e,u=[];let N=0;const E=c((d,l,o,g,m)=>{d===a&&(N=u.length),d===a&&r?u.push(s.bg("selectedBg",v(o,i))):d===a||l?u.push(`${s.fg("accent","\u258C")}${v(s.fg("accent",m),i-1)}`):u.push(v(g,i))},"push"),S=c((d,l,o,g)=>{const m=Math.max(1,M-g),y=Math.max(1,i-M-2),x=`${" ".repeat(g)}${v($(l,m),m)}`,k=$(o,y);E(d,!1,` ${x} ${k}`,` ${s.fg("dim",x)} ${k}`,`${x} ${k}`)},"labelled"),O=c((d,l)=>{const o=l.delivers===void 0?"\u2026":String(l.delivers),g=l.delivers===void 0||l.delivers===0?"dim":"success",m=Math.max(1,i-2-o.length),y=v($(l.event,m),m),x=s.fg(g,o);E(d,l.dialled,` ${y} ${x}`,` ${s.fg("dim",y)} ${x}`,`${y} ${o}`)},"evented"),R=c(d=>d.kind==="facet"?"filters":d.kind==="event"||d.indent?"events":"snapshot","sectionOf"),I={events:" EVENTS",snapshot:" SNAPSHOT",filters:` FILTERS \xB7 ${f} of ${p}`};let T;n.forEach((d,l)=>{const o=R(d);o!==T&&(u.length>0&&u.push(""),u.push(s.fg("dim",I[o]),""),T=o),d.kind==="event"?O(l,d.event):d.kind==="axis"?S(l,d.axis.label,d.axis.value,d.indent?2:0):S(l,d.facet.label,d.facet.value,0)});const F=Math.max(0,u.length-t),A=Math.min(Math.max(0,N-Math.floor(t/2)),F),h=u.slice(A,A+t);for(;h.length<t;)h.push("");return h}c(oe,"renderRail");export{ne as axesOf,ie as cycleAxis,ee as cycleFacet,w as facetsOf,te as payloadRowOf,ce as railEnter,ae as railRowKey,le as railRowsOf,oe as renderRail,de as setTypedAxis,re as typedAxisValue};
@@ -1,31 +1,27 @@
1
- import { type Rung, type SurfaceEvent } from '../../../../core/substrate/schema.js';
2
- import type { EffectiveDeliveryRecord } from '../resolve.js';
1
+ import { type PlannedEvent } from '../resolve.js';
3
2
  import type { NodeConfigSubject } from '../../../../core/substrate/subject-fields.js';
4
- /** The profile project entry whose `memory` rung ceilings this document's
5
- * store, or null when no project governs it. */
6
- export interface CapOwner {
7
- path: string;
8
- memory: Rung;
9
- }
3
+ import { type AdminRecord } from './model.js';
4
+ type SurfaceEvent = PlannedEvent;
10
5
  /** What the read face needs beyond the record: the event it is judged against,
11
6
  * the sibling events' records, and the two facts the shell resolves. */
12
7
  export interface DossierContext {
13
8
  event: SurfaceEvent;
14
- records: Map<SurfaceEvent, EffectiveDeliveryRecord>;
15
- capOwner: CapOwner | null;
9
+ records: Map<SurfaceEvent, AdminRecord>;
16
10
  readOnly: boolean;
11
+ /** The body, once the reader opened it — the plan carries none. */
12
+ body: string | undefined;
17
13
  /** The configuration every record here was planned against — what a failed
18
14
  * gate is explained against. Null when there is no node config at all. */
19
15
  subject: NodeConfigSubject | null;
20
16
  }
21
17
  /** The resting card, and — when `bodyOpen` — the document's own text beneath
22
18
  * it in place of the affordance line that names it. */
23
- export declare function renderDossierRead(record: EffectiveDeliveryRecord, context: DossierContext, width: number, bodyOpen: boolean): string[];
19
+ export declare function renderDossierRead(record: AdminRecord, context: DossierContext, width: number, bodyOpen: boolean): string[];
24
20
  /** Identity and routing — what the edit face keeps overhead of its field list,
25
21
  * because they are the context a field is being edited against. */
26
- export declare function renderDossierHeader(record: EffectiveDeliveryRecord, context: DossierContext, width: number): string[];
22
+ export declare function renderDossierHeader(record: AdminRecord, context: DossierContext, width: number): string[];
27
23
  /** Does it load here, what does it cost, and — only when there is one — what
28
24
  * interfered. The three questions the old verdict, cost table and event grid
29
25
  * each answered a piece of. */
30
- export declare function renderDossierDelivery(record: EffectiveDeliveryRecord, context: DossierContext, width: number): string[];
31
- export declare function bodyLineCount(body: string): number;
26
+ export declare function renderDossierDelivery(record: AdminRecord, context: DossierContext, width: number): string[];
27
+ export {};
@@ -1,2 +1 @@
1
- var B=Object.defineProperty;var f=(n,e)=>B(n,"name",{value:e,configurable:!0});import{getMarkdownTheme as G}from"@earendil-works/pi-coding-agent";import{Markdown as H,visibleWidth as g,wrapTextWithAnsi as W}from"@earendil-works/pi-tui";import{theme as a,wrapText as F}from"../../../../core/tui/panel.js";import{SURFACE_EVENTS as U,rungRank as D}from"../../../../core/substrate/schema.js";import{allMismatches as L,CLAUSE_SEPARATOR as j,explainRecordGate as I,formatClause as P}from"../../../../core/substrate/gate-explain.js";import{formatCost as N,plural as x,rungCostsOf as Y}from"./model.js";const V="\u2298",p=" ";function an(n,e,t,s){const u=Math.max(1,t-p.length),i=q(n,e,t);i.push(...J(n,e,t));const h=n.doc.shortForm.trim();h!==""&&i.push("",a.fg("dim",`${p}SHORT FORM`),...r(l(h,u)));const c=K(n.doc.body);return s?(i.push(""),i.push(...r(new H(n.doc.body,0,0,G()).render(u)))):c===0?i.push("",...R("no body \u2014 this document is its routing line",t)):i.push("",...R(`enter read the body \u2014 ${x(c,"line","lines")}`,t)),i}f(an,"renderDossierRead");function R(n,e){const t=Math.max(1,e-p.length);return g(n)<=t?[`${p}${a.fg("dim",n)}`]:r(l(n,t)).map(s=>a.fg("dim",s))}f(R,"dim");function q(n,e,t){const s=Math.max(1,t-p.length),u=z(n,e,s);u.push("",a.fg("dim",`${p}READ WHEN`));const i=n.doc.whenAndWhyToRead.trim();return u.push(...i===""?[a.fg("dim",`${p}Not declared.`)]:r(l(i,s))),u}f(q,"renderDossierHeader");function z(n,e,t){const s=`${n.kind} \xB7 ${n.scope}${n.nodeLocal?" \xB7 node-local":""}${e.readOnly?` ${V}`:""}`,u=l(n.name,t),i=u.map($=>`${p}${a.fg("accent",a.bold($))}`),h=u[u.length-1]??"",c=t-g(h)-g(s);return c>=2?(i[i.length-1]=`${p}${a.fg("accent",a.bold(h))}${" ".repeat(c)}${a.fg("dim",s)}`,i):(i.push(...l(s,t).map($=>`${p}${" ".repeat(Math.max(0,t-g($)))}${a.fg("dim",$)}`)),i)}f(z,"identityLines");function J(n,e,t){const s=Math.max(1,t-p.length),u=Y(n),i=n.finalRung!=="none",h=D(n.cappedRung)<D(n.authoredRung),c=i?n.finalRung:"nothing",$=i?` \xB7 ${N(u[n.finalRung])||"~0"} of ${N(u.content)||"~0"}`:"",O=i?h?"warning":"success":"dim",E=`${e.event} \u2192 `,v=`${c}${$}`,m=[""];g(E)+g(v)<=s?m.push(`${p}${a.fg("dim",E)}${a.fg(O,c)}${a.fg("dim",$)}`):(m.push(...r(l(E,s)).map(o=>a.fg("dim",o))),m.push(...r(l(v,s)).map(o=>a.fg(O,o))));const w=f(o=>{m.push(...r(l(o,s)).map(d=>a.fg("warning",d)))},"warn");let A=!1;const C=f((o,d)=>{const M=o==="doc"?n.docGate:n.entryGate;if(M===null||M.pass)return[];const y=I(n,o,e.subject);if(y.length===0)return A=!0,w(`${d} fails: ${M.reason}`),y;w(L(y)?`${d} fails`:`${d} never matches`);for(const S of y)m.push(...Q(P(S),s).map(_=>a.fg("warning",_)));return y},"gateBlock"),k=[...C("doc","gate"),...C("entry","entry gate")];!A&&L(k)&&m.push(...R("dial the snapshot at left to load it here",t)),n.matchedEntry===null&&n.authoredEntries.length>0&&m.push(...r(l(`${x(n.authoredEntries.length,"entry","entries")} for this event, none matched`,s)).map(o=>a.fg("dim",o))),h&&w(e.capOwner===null?`capped to ${n.cappedRung} by a profile ceiling on this store`:`capped to ${n.cappedRung} by the ${e.capOwner.memory} ceiling on ${e.capOwner.path}`),n.deliveryCause!==void 0&&m.push(...R(n.deliveryCause,t)),n.shadowedBy!==null&&m.push(...r(l(`shadowed by the ${n.shadowedBy.scope} copy at ${n.shadowedBy.path}`,s)).map(o=>a.fg("muted",o)));const T=U.filter(o=>o!==e.event).map(o=>({event:o,held:e.records.get(o)})).filter(o=>o.held!==void 0&&o.held.finalRung!=="none").map(o=>`${o.event} \u2192 ${o.held.finalRung}`);return T.length>0&&m.push(...r(l(`also ${T.join(" \xB7 ")}`,s)).map(o=>a.fg("dim",o))),m}f(J,"renderDossierDelivery");function K(n){const e=n.replace(/\n+$/,"");return e===""?0:e.split(`
2
- `).length}f(K,"bodyLineCount");function r(n){return n.map(e=>`${p}${e}`)}f(r,"indent");const b=`${p} `;function Q(n,e){const t=Math.max(1,e-2);if(g(n)<=t)return[`${b}${n}`];const s=n.indexOf(j);return s===-1?l(n,t).map(u=>`${b}${u}`):[...l(n.slice(0,s),t).map(u=>`${b}${u}`),...l(n.slice(s+1),Math.max(1,t-2)).map(u=>`${b} ${u}`)]}f(Q,"clauseRows");function l(n,e){const t=n.trim();return t===""?[]:t.split(/\s+/).some(s=>g(s)>e)?W(t,e):F(t,e)}f(l,"wrapped");export{K as bodyLineCount,J as renderDossierDelivery,q as renderDossierHeader,an as renderDossierRead};
1
+ var T=Object.defineProperty;var r=(e,s)=>T(e,"name",{value:s,configurable:!0});import{getMarkdownTheme as A}from"@earendil-works/pi-coding-agent";import{Markdown as L,visibleWidth as g,wrapTextWithAnsi as x}from"@earendil-works/pi-tui";import{theme as i,wrapText as k}from"../../../../core/tui/panel.js";import{rungRank as M}from"../../../../core/substrate/schema.js";import{PLANNED_EVENTS as H}from"../resolve.js";import{CLAUSE_SEPARATOR as O,explainGate as _,formatClause as P}from"../../../../core/substrate/gate-explain.js";import{ownerTypeOf as S}from"./list-view.js";import{plural as j}from"./model.js";const B="\u2298",l=" ";function X(e,s,n,t){const o=Math.max(1,n-l.length),u=C(e,s,n);u.push(...I(e,s,n));const p=s.body;return t&&p!==void 0?(u.push(""),u.push(...d(new L(p,0,0,A()).render(o)))):t?u.push("",...v("reading the body\u2026",n)):u.push("",...v("enter read the body",n)),u}r(X,"renderDossierRead");function v(e,s){const n=Math.max(1,s-l.length);return g(e)<=n?[`${l}${i.fg("dim",e)}`]:d(f(e,n)).map(t=>i.fg("dim",t))}r(v,"dim");function C(e,s,n){const t=Math.max(1,n-l.length),o=G(e,s,t);o.push("",i.fg("dim",`${l}PREVIEW`));const u=e.doc.preview.trim();return o.push(...u===""?[i.fg("dim",`${l}Not declared.`)]:d(f(u,t))),o}r(C,"renderDossierHeader");function G(e,s,n){const t=`${e.doc.kind} \xB7 ${S(e)} ${e.doc.ownerHandle}${e.doc.unlisted?" \xB7 unlisted":""}${s.readOnly?` ${B}`:""}`,o=f(e.doc.displayName,n),u=o.map(h=>`${l}${i.fg("accent",i.bold(h))}`),p=o[o.length-1]??"",$=n-g(p)-g(t);return $>=2?(u[u.length-1]=`${l}${i.fg("accent",i.bold(p))}${" ".repeat($)}${i.fg("dim",t)}`,u):(u.push(...f(t,n).map(h=>`${l}${" ".repeat(Math.max(0,n-g(h)))}${i.fg("dim",h)}`)),u)}r(G,"identityLines");function I(e,s,n){const t=Math.max(1,n-l.length),o=e.finalRung!=="none",u=M(e.cappedRung)<M(e.authoredRung),p=o?e.finalRung:"nothing",$=o?u?"warning":"success":"dim",h=`${s.event} \u2192 `,m=[""];g(h)+g(p)<=t?m.push(`${l}${i.fg("dim",h)}${i.fg($,p)}`):(m.push(...d(f(h,t)).map(a=>i.fg("dim",a))),m.push(...d(f(p,t)).map(a=>i.fg($,a))));const w=r(a=>{m.push(...d(f(a,t)).map(c=>i.fg("warning",c)))},"warn"),b=e.ruleGate;if(e.matchedRule===null&&b!==null&&!b.pass){const a=e.authoredRules.find(R=>!R.gate.pass)?.rule.if,c=a===void 0||s.subject===null?[]:_(a,s.subject);if(c.length===0)w(`rule if fails: ${b.reason}`);else{const R=c.every(E=>E.failure==="mismatch");w(R?"rule if fails":"rule if never matches");for(const E of c)m.push(...W(P(E),t).map(D=>i.fg("warning",D)));R&&m.push(...v("dial the snapshot at left to load it here",n))}}else e.matchedRule===null&&e.authoredRules.length>0&&m.push(...d(f(`${j(e.authoredRules.length,"rule","rules")} for this activity, none matched`,t)).map(a=>i.fg("dim",a)));u&&w(`limited to ${e.cappedRung} by the profile\u2019s delivery limit for ${e.doc.ownerHandle} (authored ${e.authoredRung})`),e.shadowedBy!==null&&m.push(...d(f(`shadowed by ${e.shadowedBy.ownerHandle}/${e.shadowedBy.name}`,t)).map(a=>i.fg("muted",a)));const N=H.filter(a=>a!==s.event).map(a=>({event:a,held:s.records.get(a)})).filter(a=>a.held!==void 0&&a.held.finalRung!=="none").map(a=>`${a.event} \u2192 ${a.held.finalRung}`);return N.length>0&&m.push(...d(f(`also ${N.join(" \xB7 ")}`,t)).map(a=>i.fg("dim",a))),m}r(I,"renderDossierDelivery");function d(e){return e.map(s=>`${l}${s}`)}r(d,"indent");const y=`${l} `;function W(e,s){const n=Math.max(1,s-2);if(g(e)<=n)return[`${y}${e}`];const t=e.indexOf(O);return t===-1?f(e,n).map(o=>`${y}${o}`):[...f(e.slice(0,t),n).map(o=>`${y}${o}`),...f(e.slice(t+1),Math.max(1,n-2)).map(o=>`${y} ${o}`)]}r(W,"clauseRows");function f(e,s){const n=e.trim();return n===""?[]:n.split(/\s+/).some(t=>g(t)>s)?x(n,s):k(n,s)}r(f,"wrapped");export{I as renderDossierDelivery,C as renderDossierHeader,X as renderDossierRead};
@@ -1,16 +1,15 @@
1
1
  import { type Component, type Focusable, type TUI } from '@earendil-works/pi-tui';
2
2
  import { type BindingId, type BindingResolution } from '../../../../core/keybindings/index.js';
3
- import { type CapChange } from './actions.js';
4
- import { type Snapshot } from './model.js';
3
+ import { type ProfileChoice, type Snapshot } from './model.js';
5
4
  export interface AdminResult {
6
5
  edited: string[];
7
- capChanges: CapChange[];
8
6
  }
9
7
  export declare class ContextAdminShell implements Component, Focusable {
10
8
  private readonly tui;
11
9
  private readonly terminalRows;
12
10
  private readonly bindings;
13
11
  private readonly suspendForChild;
12
+ private readonly profiles;
14
13
  private snapshot;
15
14
  private plans;
16
15
  private zone;
@@ -25,11 +24,12 @@ export declare class ContextAdminShell implements Component, Focusable {
25
24
  private notice;
26
25
  private busy;
27
26
  private readonly edited;
28
- private readonly capChanges;
27
+ /** Bodies the reader opened, by object id — the plan carries none. */
28
+ private readonly bodies;
29
29
  private _focused;
30
30
  onCancel?: () => void;
31
31
  onSubmit?: (result: AdminResult) => void;
32
- constructor(seed: Snapshot, tui: TUI, terminalRows: () => number, bindings: BindingResolution<BindingId>, suspendForChild: () => () => void);
32
+ constructor(seed: Snapshot, tui: TUI, terminalRows: () => number, bindings: BindingResolution<BindingId>, suspendForChild: () => () => void, profiles: readonly ProfileChoice[]);
33
33
  set focused(value: boolean);
34
34
  get focused(): boolean;
35
35
  /** Required by `Component`. Nothing is cached between frames: a plan can land
@@ -39,6 +39,7 @@ export declare class ContextAdminShell implements Component, Focusable {
39
39
  /** Recompute the focused event's plan, refresh the panels from it, and let
40
40
  * the remaining events fill in behind it. */
41
41
  private rebuild;
42
+ private refreshRows;
42
43
  /** A filter never re-plans: it is a question about the plan already computed,
43
44
  * which is what keeps a facet change instant on a corpus this size. */
44
45
  private setFilters;
@@ -66,6 +67,7 @@ export declare class ContextAdminShell implements Component, Focusable {
66
67
  /** The rail's rows: the events, then the snapshot axes, then the filter
67
68
  * facets, so one cursor and one gesture drive all three sections. */
68
69
  private railRows;
70
+ private profileName;
69
71
  private handleRail;
70
72
  private handleDocs;
71
73
  private openSearch;
@@ -73,20 +75,20 @@ export declare class ContextAdminShell implements Component, Focusable {
73
75
  * modal over the rows it is selecting. */
74
76
  private handleSearch;
75
77
  private handleDetail;
76
- /** Put the focused document's path on the clipboard, so a reader who spotted
77
- * the document that is misbehaving can open, grep, or pass it along without
78
- * retyping it off the screen. The clipboard carries the absolute path, which
79
- * is what survives being pasted into another command; the notice collapses
80
- * it against home, which is only read. */
81
- private yankPath;
78
+ /** Put the focused document's object id on the clipboard, so a reader who
79
+ * spotted the document that is misbehaving can read, edit, or pass it along
80
+ * (`crtr canvas read <id>`) without retyping it off the screen. */
81
+ private yankId;
82
82
  /** The resting face: reading, and the two gestures that leave it. */
83
83
  private handleRead;
84
+ /** Open the body in place, fetching it the first time it is opened. */
85
+ private openBody;
84
86
  /** The field list. Every write gesture is resolved before it is started, so a
85
87
  * read-only document refuses at the keypress rather than after a modal. */
86
88
  private handleEdit;
87
89
  /** The write one edit-face key starts, or undefined when the key writes
88
90
  * nothing. `document` marks the writes a read-only document refuses — the
89
- * profile ceiling is not one of them; it lives in the profile manifest. */
91
+ * delivery limit is not one of them; it lives on the profile. */
90
92
  private writeGesture;
91
93
  /** The refusal a read-only document owes the write just attempted, carried by
92
94
  * the same footer channel every other write outcome uses. */
@@ -96,23 +98,20 @@ export declare class ContextAdminShell implements Component, Focusable {
96
98
  private activate;
97
99
  private get record();
98
100
  private apply;
99
- private cycleEntryRung;
100
- private removeEntry;
101
- /** Event, then match, then rung — the three fields a valid entry needs, asked
102
- * in the order the schema reads them. */
103
- private composeEntry;
104
- private editGate;
105
- private flip;
106
- private editRouting;
107
- private editShortForm;
101
+ private cycleRuleLevel;
102
+ private removeRule;
103
+ /** Activity, then match, then level — the three fields a valid rule needs,
104
+ * asked in the order the rule reads them. */
105
+ private composeRule;
106
+ private flipUnlisted;
107
+ private editPreview;
108
108
  /** The one write that leaves the page: the terminal goes to $EDITOR and comes
109
- * back repainted, and the buffer that returns is saved through `memory edit`
110
- * like every other field here. */
109
+ * back repainted, and the buffer that returns is saved through the same
110
+ * route `crtr doc edit` uses. */
111
111
  private editBody;
112
112
  private editMove;
113
- /** The ceiling belongs to the profile project entry that governs the store,
114
- * not to the document, so this write is offered only when one exists. */
115
- private editCap;
113
+ /** Delivery limits belong to the profile, per owner — not to the document. */
114
+ private explainLimit;
116
115
  private openAxisField;
117
116
  private close;
118
117
  private handleModal;
@@ -122,9 +121,5 @@ export declare class ContextAdminShell implements Component, Focusable {
122
121
  * opens its dossier. */
123
122
  private docsGesture;
124
123
  render(width: number): string[];
125
- /** What the delivering documents spend on this event. An estimate, and a
126
- * floor on the rendered prompt: boot wraps these documents in its own intro
127
- * prose and catalog tree. */
128
- private costMeta;
129
124
  }
130
- export declare function runContextAdmin(seed: Snapshot): Promise<AdminResult | undefined>;
125
+ export declare function runContextAdmin(seed: Snapshot, profiles: readonly ProfileChoice[]): Promise<AdminResult | undefined>;
@@ -1 +1 @@
1
- var O=Object.defineProperty;var h=(a,e)=>O(a,"name",{value:e,configurable:!0});import{Input as _,matchesKey as i,truncateToWidth as v,visibleWidth as b}from"@earendil-works/pi-tui";import{formatGesture as G,matchesPiTuiInput as q}from"../../../../core/keybindings/index.js";import{writeClipboardTextEverywhere as T}from"../../../../core/clipboard-text.js";import{shortPath as W}from"../../../../core/inspector/model.js";import{runTuiPage as N}from"../../../../core/tui/page-host.js";import{PAGE_CHROME_ROWS as U,columns as x,framed as j,pageFrame as H,theme as d}from"../../../../core/tui/panel.js";import{RUNGS as R,SURFACE_EVENTS as g,SURFACE_RUNGS as y}from"../../../../core/substrate/schema.js";import{profileNameFor as P}from"../../../../core/substrate/subject-fields.js";import{editBufferInEditor as B}from"../../../../clients/inbox/review/roundtrip.js";import{capOwnerFor as k,moveDoc as L,readBody as V,readOnlyReason as I,toggleFlag as J,writeBody as K,writeCap as X,writeGate as Y,writeRoutingLine as Q,writeShortForm as Z,writeSurfaces as w}from"./actions.js";import{axesOf as ee,cycleAxis as $,cycleFacet as te,facetsOf as se,payloadRowOf as ie,railEnter as M,railRowKey as S,railRowsOf as ne,renderRail as re,setTypedAxis as oe,typedAxisValue as he}from"./rail-panel.js";import{ContextDetailPanel as le}from"./detail-panel.js";import{ContextDocsPanel as de,buildRows as D}from"./docs-panel.js";import{NO_FILTERS as ce,costTotals as ae}from"./list-view.js";import{PlanSet as ue,formatCost as C,plural as E}from"./model.js";const u=26,fe=86,pe=112,F=6,me=48,ge=100,ye=.45;function be(a){const e=Math.max(1,a-u-F);return Math.max(me,Math.min(ge,Math.floor(e*ye)))}h(be,"docsWidthFor");class xe{static{h(this,"ContextAdminShell")}tui;terminalRows;bindings;suspendForChild;snapshot;plans;zone="rail";railIndex=0;filters=ce;rows=[];searching=!1;docs;detail=new le;modal;notice;busy;edited=new Set;capChanges=[];_focused=!1;onCancel;onSubmit;constructor(e,t,s,n,r){this.tui=t,this.terminalRows=s,this.bindings=n,this.suspendForChild=r,this.snapshot=e,this.plans=new ue(e),this.docs=new de(()=>this.tui.requestRender()),this.rebuild()}set focused(e){this._focused=e}get focused(){return this._focused}invalidate(){}dispose(){this.plans.dispose()}rebuild(){this.plans.plan(this.snapshot.event),this.rows=D(this.plans,this.snapshot.event),this.docs.setRows(this.rows,this.snapshot.event),this.syncDetail(),this.plans.warm(()=>{this.rows=D(this.plans,this.snapshot.event),this.docs.setRows(this.rows,this.snapshot.event),this.syncDetail(),this.tui.requestRender()})}setFilters(e){this.filters=e,this.docs.setFilters(e),this.syncDetail()}syncDetail(){const e=this.docs.selected,t=e===void 0?null:k(e.anchor,this.snapshot.profileId),s=e===void 0?null:I(e.anchor,this.snapshot.profileId);this.detail.setContext(e,this.snapshot.event,t,s,this.plans.plan(this.snapshot.event).subject)}setSnapshot(e){const t=this.railRows()[this.railIndex];this.snapshot=e,this.plans.setSnapshot(e),this.notice=void 0,this.rebuild(),this.holdRail(t)}holdRail(e){if(e===void 0)return;const t=this.railRows(),s=S(e),n=t.findIndex(r=>S(r)===s);this.railIndex=Math.max(0,n>=0?n:t.findIndex(r=>r.kind==="event"&&r.event.dialled))}matches(e,t){return q(this.bindings,e,t,(s,n)=>i(s,n))}label(e,t){const s=this.bindings.gestures(e);return s.length===0?t:G(s[0].split(" > ").pop())}isDown(e){return i(e,"j")||i(e,"down")||this.matches("crtr.setup.list-down",e)}isUp(e){return i(e,"k")||i(e,"up")||this.matches("crtr.setup.list-up",e)}isDescend(e){return i(e,"l")||i(e,"right")||i(e,"enter")||this.matches("crtr.setup.advance",e)}isAscend(e){return i(e,"h")||i(e,"left")}cyclesEvent(e){const t=i(e,"right")||i(e,"left");return i(e,"tab")||!t&&this.matches("crtr.setup.tab-next",e)?1:i(e,"shift+tab")||!t&&this.matches("crtr.setup.tab-previous",e)?-1:0}handleInput(e){if(this.busy!==void 0)return;if(this.modal!==void 0){this.handleModal(e);return}if(this.searching){this.handleSearch(e);return}const t=this.cyclesEvent(e);if(t!==0){this.setSnapshot($(this.snapshot,"event",t));return}if(!(this.zone==="detail"&&!this.detail.editing&&i(e,"ctrl+d"))&&(i(e,"q")||this.matches("crtr.setup.cancel",e))){this.close();return}this.zone==="rail"?this.handleRail(e):this.zone==="docs"?this.handleDocs(e):this.handleDetail(e)}eventRows(){return g.map(e=>{const t=this.plans.peek(e);return{event:e,delivers:t===void 0?void 0:t.docs.filter(s=>s.finalRung!=="none").length,dialled:e===this.snapshot.event}})}railRows(){return ne(this.eventRows(),ie(this.snapshot),ee(this.snapshot,P(this.snapshot.profileId)??"none"),se(this.filters))}handleRail(e){const t=this.railRows();this.railIndex=Math.max(0,Math.min(this.railIndex,t.length-1));const s=t[this.railIndex],n=h(o=>{s!==void 0&&(s.kind==="event"?this.setSnapshot({...this.snapshot,event:s.event.event}):s.kind==="axis"?s.axis.typed?this.openAxisField(s.axis.id,s.axis.label):this.setSnapshot($(this.snapshot,s.axis.id,o)):s.facet.typed?this.openSearch():this.setFilters(te(this.filters,s.facet.id,o)))},"change"),r=M(s);this.isDown(e)?this.railIndex=Math.min(t.length-1,this.railIndex+1):this.isUp(e)?this.railIndex=Math.max(0,this.railIndex-1):i(e,"space")||this.matches("crtr.setup.toggle",e)?n(1):this.isDescend(e)?i(e,"enter")&&r!=="documents"?n(1):this.zone="docs":i(e,"escape")&&this.close()}handleDocs(e){e==="/"||i(e,"/")?this.openSearch():i(e,"y")?this.yankPath():this.isDown(e)?(this.docs.move(1),this.syncDetail()):this.isUp(e)?(this.docs.move(-1),this.syncDetail()):i(e,"space")||this.matches("crtr.setup.toggle",e)?(this.docs.toggleGroup(),this.syncDetail()):this.isDescend(e)?this.docs.onGroup?(this.docs.toggleGroup(),this.syncDetail()):this.docs.selected!==void 0&&(this.zone="detail"):i(e,"escape")&&this.filters.query!==""?this.setFilters({...this.filters,query:""}):(this.isAscend(e)||i(e,"escape"))&&(this.zone="rail")}openSearch(){this.searching=!0,this.zone="docs",this.tui.requestRender()}handleSearch(e){i(e,"escape")?(this.searching=!1,this.setFilters({...this.filters,query:""})):i(e,"enter")?this.searching=!1:i(e,"backspace")?this.setFilters({...this.filters,query:this.filters.query.slice(0,-1)}):e.length===1&&e.charCodeAt(0)>=32&&this.setFilters({...this.filters,query:this.filters.query+e}),this.tui.requestRender()}handleDetail(e){i(e,"y")?this.yankPath():this.detail.editing?this.handleEdit(e):this.handleRead(e)}yankPath(){const e=this.docs.selected;if(e===void 0)return;const{system:t,tmux:s}=T(e.key);this.notice=t||s?{text:`Copied ${W(e.key)}${t?"":" to the tmux buffer"}`,ok:!0}:{text:"No clipboard tool available \u2014 nothing copied",ok:!1},this.tui.requestRender()}handleRead(e){this.isDown(e)?this.detail.move(1):this.isUp(e)?this.detail.move(-1):i(e,"ctrl+d")?this.detail.page(1):i(e,"ctrl+u")?this.detail.page(-1):e==="G"||i(e,"shift+g")?this.detail.jump("bottom"):e==="g"||i(e,"g")?this.detail.jump("top"):e==="e"||i(e,"e")?this.detail.edit():this.isDescend(e)?this.detail.openBody():(this.isAscend(e)||i(e,"escape"))&&(this.detail.back()||(this.zone="docs"))}handleEdit(e){if(this.isDown(e)){this.detail.move(1);return}if(this.isUp(e)){this.detail.move(-1);return}if(this.isAscend(e)||i(e,"escape")){this.detail.back();return}const t=this.writeGesture(e);t!==void 0&&(t.document&&this.refusesWrite()||t.start())}writeGesture(e){const t=h(s=>({start:s,document:!0}),"doc");if(i(e,"enter")||i(e,"space")||this.matches("crtr.setup.toggle",e)){const s=this.detail.selected;return s===void 0?void 0:s.kind==="cap"?{start:h(()=>this.editCap(),"start"),document:!1}:t(()=>this.activate())}if(i(e,"m"))return{start:h(()=>this.editCap(),"start"),document:!1};if(i(e,"b"))return t(()=>this.editBody());if(i(e,"x"))return t(()=>this.removeEntry());if(i(e,"e"))return t(()=>this.composeEntry());if(i(e,"g"))return t(()=>this.editGate());if(i(e,"u"))return t(()=>this.flip("unlisted"));if(i(e,"s"))return t(()=>this.flip("slash"));if(i(e,"r"))return t(()=>this.editMove());if(i(e,"w"))return t(()=>this.editRouting());if(i(e,"f"))return t(()=>this.editShortForm())}refusesWrite(){const e=this.record;if(e===void 0)return!1;const t=I(e,this.snapshot.profileId);return t===null?!1:(this.notice={text:t,ok:!1},this.tui.requestRender(),!0)}activate(){const e=this.detail.selected;if(e!==void 0)switch(e.kind){case"entry":return this.cycleEntryRung(e.at);case"add-entry":return this.composeEntry();case"gate":return this.editGate();case"unlisted":return this.flip("unlisted");case"slash":return this.flip("slash");case"routing":return this.editRouting();case"short-form":return this.editShortForm();case"body":return this.editBody();case"cap":return this.editCap();case"move":return this.editMove()}}get record(){return this.docs.selected?.anchor}apply(e){this.busy="writing\u2026",this.tui.requestRender(),e.then(t=>{this.busy=void 0,this.notice={text:t.message,ok:t.ok},t.ok&&(t.name!==void 0&&this.edited.add(t.name),this.plans.invalidate(),this.rebuild()),this.tui.requestRender()})}cycleEntryRung(e){const t=this.record,s=t?.doc.surfaces[e];if(t===void 0||s===void 0)return;const n=y[(y.indexOf(s.at)+1)%y.length],r=t.doc.surfaces.map((o,l)=>l===e?{...o,at:n}:o);this.apply(w(t,this.snapshot.profileId,r,`${t.name} now delivers at "${n}" on ${s.on}.`))}removeEntry(){const e=this.record,t=this.detail.selectedEntry;if(e===void 0||t===void 0){this.notice={text:"Select a surface entry to remove.",ok:!1};return}const s=e.doc.surfaces[t],n=e.doc.surfaces.filter((r,o)=>o!==t);this.modal={kind:"confirm",title:"Remove surface entry",message:`${e.name} will stop delivering on ${s.on} at "${s.at}".`,submit:h(()=>this.apply(w(e,this.snapshot.profileId,n,`Removed the ${s.on} entry from ${e.name}.`)),"submit")}}composeEntry(){const e=this.record;e!==void 0&&(this.modal={kind:"choice",title:"New entry \u2014 event",options:[...g],index:g.indexOf(this.snapshot.event),submit:h(t=>{const s=t,n=s!=="boot"&&s!=="workspace-open",r=h(o=>{this.modal={kind:"choice",title:"New entry \u2014 rung",options:[...y],index:0,submit:h(l=>{this.modal=void 0;const m={on:s,...o===""?{}:{match:[o]},at:l};this.apply(w(e,this.snapshot.profileId,[...e.doc.surfaces,m],`${e.name} now delivers on ${s} at "${l}".`))},"submit")}},"chooseRung");if(!n){r("");return}this.modal={kind:"field",title:`New entry \u2014 ${s} match`,hint:s==="read"?"absolute path glob, or ./ for this document\u2019s own directory":"glob over the event\u2019s namespace",input:f(""),submit:h(o=>{const l=o.trim();if(l===""){this.modal=void 0,this.notice={text:`A ${s} entry needs a match glob.`,ok:!1};return}r(l)},"submit")}},"submit")})}editGate(){const e=this.record;e!==void 0&&(this.modal={kind:"field",title:"Document gate",hint:"YAML or JSON predicate over the node config \u2014 empty clears it",input:f(e.doc.gate===void 0?"":JSON.stringify(e.doc.gate)),submit:h(t=>{this.modal=void 0,this.apply(Y(e,this.snapshot.profileId,t))},"submit")})}flip(e){const t=this.record;t!==void 0&&this.apply(J(t,this.snapshot.profileId,e))}editRouting(){const e=this.record;e!==void 0&&(this.modal={kind:"field",title:"Routing line",hint:"When <circumstance>, this <kind> should be read because <payoff>",input:f(e.doc.whenAndWhyToRead),submit:h(t=>{this.modal=void 0,this.apply(Q(e,this.snapshot.profileId,t))},"submit")})}editShortForm(){const e=this.record;e!==void 0&&(this.modal={kind:"field",title:"Short form",hint:"human-facing abbreviation for listings \u2014 empty clears it",input:f(e.doc.shortForm),submit:h(t=>{this.modal=void 0,this.apply(Z(e,this.snapshot.profileId,t))},"submit")})}editBody(){const e=this.record;if(e===void 0)return;let t;try{t=V(e)}catch(r){this.notice={text:r instanceof Error?r.message:String(r),ok:!1};return}const s=this.suspendForChild();let n;try{n=B(t)}finally{s()}if(n.error!==void 0){this.notice={text:n.error,ok:!1};return}if(n.text===t){this.notice={text:`${e.name} came back unchanged \u2014 nothing written.`,ok:!1};return}this.apply(K(e,this.snapshot.profileId,n.text))}editMove(){const e=this.record;e!==void 0&&(this.modal={kind:"field",title:"Move or rename",hint:"the new canonical name inside this document\u2019s own store",input:f(e.name),submit:h(t=>{this.modal=void 0,this.apply(L(e,this.snapshot.profileId,t))},"submit")})}editCap(){const e=this.record,t=this.snapshot.profileId;if(e===void 0)return;const s=t===null?null:k(e,t);if(s===null||t===null){this.notice={text:"No profile project governs this store \u2014 its ceiling is neutral and not editable here.",ok:!1};return}this.modal={kind:"choice",title:`Ceiling for ${s.path}`,options:[...R],index:Math.max(0,R.indexOf(s.memory)),submit:h(n=>{this.modal=void 0;const r=X(t,s.path,n);if(this.notice={text:r.message,ok:r.ok},r.change!==void 0){const o=this.capChanges.findIndex(l=>l.path===r.change.path);o>=0?this.capChanges[o]=r.change:this.capChanges.push(r.change),this.plans.invalidate(),this.rebuild()}},"submit")}}openAxisField(e,t){this.modal={kind:"field",title:t,hint:e==="cwd"?"absolute directory the project stores resolve from":"value the planner should match against",input:f(he(this.snapshot,e)),submit:h(s=>{this.modal=void 0,this.setSnapshot(oe(this.snapshot,e,s))},"submit")}}close(){if(this.edited.size===0&&this.capChanges.length===0){this.onCancel?.();return}this.onSubmit?.({edited:[...this.edited],capChanges:[...this.capChanges]})}handleModal(e){const t=this.modal;if(t!==void 0){if(i(e,"escape")){this.modal=void 0;return}if(t.kind==="choice"){this.isDown(e)?t.index=Math.min(t.options.length-1,t.index+1):this.isUp(e)?t.index=Math.max(0,t.index-1):i(e,"enter")&&t.submit(t.options[t.index]);return}if(t.kind==="confirm"){i(e,"y")||i(e,"enter")?(this.modal=void 0,t.submit()):i(e,"n")&&(this.modal=void 0);return}i(e,"enter")?t.submit(t.input.getValue()):t.input.handleInput(e)}}renderModal(e,t){const s=this.modal;if(s===void 0)return[];let n;s.kind==="choice"?n=[d.fg("accent",d.bold(s.title)),"",...s.options.map((o,l)=>`${l===s.index?d.fg("accent","\u25B6"):" "} ${o}`)]:s.kind==="confirm"?n=[d.fg("warning",d.bold(s.title)),"",...ve(s.message,Math.max(1,e-6))]:n=[d.fg("accent",d.bold(s.title)),d.fg("dim",s.hint),"",s.input.render(Math.max(1,e-6))[0]??""];const r=j(n,e);for(;r.length<t;)r.push("");return r.slice(0,t)}footer(e,t){if(this.busy!==void 0)return d.fg("warning",this.busy);if(this.modal?.kind==="choice")return d.fg("dim","j/k choose \xB7 enter apply \xB7 esc cancel");if(this.modal?.kind==="confirm")return d.fg("dim","y/enter confirm \xB7 n/esc cancel");if(this.modal?.kind==="field")return d.fg("dim","type \xB7 enter apply \xB7 esc cancel");if(this.searching)return d.fg("dim","type to search names \xB7 enter keep \xB7 esc clear");if(this.notice!==void 0)return d.fg(this.notice.ok?"success":"warning",v(this.notice.text,e));const s=`${this.label("crtr.setup.list-down","j")}/${this.label("crtr.setup.list-up","k")}`,n=this.zone==="rail"?`${s} row \xB7 ${we(t)}`:this.zone==="docs"?`${s} row \xB7 ${this.docsGesture()} \xB7 / search \xB7 y path`:this.detail.editing?`${s} field \xB7 enter edit \xB7 e add \xB7 x remove \xB7 g gate \xB7 b body \xB7 u unlisted \xB7 s slash \xB7 m cap \xB7 r rename \xB7 y path \xB7 esc read`:this.detail.bodyOpen?`${s} scroll \xB7 ctrl-d/u page \xB7 g/G ends \xB7 y path \xB7 esc collapse`:`${s} scroll \xB7 enter body \xB7 e edit \xB7 y path \xB7 esc list`,r=`${this.label("crtr.setup.tab-next","tab")} event \xB7 ${this.label("crtr.setup.cancel","q")} close`,o=e-b(n)-b(r);return o>=2?`${d.fg("dim",n)}${" ".repeat(o)}${d.fg("dim",r)}`:d.fg("dim",v(`${n} \xB7 ${this.label("crtr.setup.cancel","q")} close`,e))}docsGesture(){return this.docs.onGroup?"space/enter open":"enter dossier"}render(e){const t=this.terminalRows(),s=Math.max(1,t-U),n=e>=fe,r=this.railRows();this.railIndex=Math.max(0,Math.min(this.railIndex,r.length-1));const o=h(c=>re({rows:r,index:this.railIndex,width:c,height:s,focused:this.zone==="rail",matched:this.docs.visibleCount,total:this.rows.length}),"rail");let l;if(e>=pe){const c=be(e),p=Math.max(1,e-u-c-F),z=x(this.docs.render(c,s,this.zone==="docs"),c,this.modal===void 0?this.detail.render(p,s,this.zone==="detail"):this.renderModal(p,s),p);l=x(o(u),u,z,e-u-3)}else if(n){const c=e-u-3,p=this.modal!==void 0?this.renderModal(c,s):this.zone==="detail"?this.detail.render(c,s,!0):this.docs.render(c,s,this.zone==="docs");l=x(o(u),u,p,c)}else this.modal!==void 0?l=this.renderModal(e,s):this.zone==="rail"?l=o(e):this.zone==="detail"?l=this.detail.render(e,s,!0):l=this.docs.render(e,s,!0);const m=g.filter(c=>this.plans.peek(c)===void 0).length,A=[this.snapshot.event,this.costMeta(),m>0?`${E(m,"event","events")} planning`:"all events planned",this.edited.size>0?`${E(this.edited.size,"doc","docs")} edited`:""].filter(c=>c!=="").join(" \xB7 ");return H({width:e,height:t,title:"crouter context",meta:A,body:l,footer:this.footer(e,r[this.railIndex])})}costMeta(){const{total:e,byRung:t}=ae(this.rows,this.snapshot.event);if(e===0)return"no documents delivered";const s=["content","preview","name"].filter(n=>t[n]>0).map(n=>`${C(t[n]).replace("~","")} ${n}`).join(" \xB7 ");return`docs load ${C(e)} \u2014 ${s}`}}function we(a){switch(M(a)){case"dial":return"space/enter dial \xB7 l documents";case"edit":return"space/enter edit \xB7 l documents";default:return"space change \xB7 enter documents"}}h(we,"railGesture");function f(a){const e=new _;return e.setValue(a),e.handleInput(""),e.focused=!0,e}h(f,"seeded");function ve(a,e){const t=[];let s="";for(const n of a.trim().split(/\s+/)){const r=s===""?n:`${s} ${n}`;b(r)<=e?s=r:(s!==""&&t.push(s),s=n)}return s!==""&&t.push(s),t}h(ve,"wrap");async function Te(a){return N(({tui:e,terminal:t,bindings:s,suspendForChild:n},r)=>{const o=new xe(a,e,()=>t.rows,s,n);return o.onCancel=r.cancel,o.onSubmit=r.submit,o})}h(Te,"runContextAdmin");export{xe as ContextAdminShell,Te as runContextAdmin};
1
+ var z=Object.defineProperty;var l=(u,e)=>z(u,"name",{value:e,configurable:!0});import{Input as A,matchesKey as s,truncateToWidth as b,visibleWidth as w}from"@earendil-works/pi-tui";import{formatGesture as C,matchesPiTuiInput as N}from"../../../../core/keybindings/index.js";import{writeClipboardTextEverywhere as T}from"../../../../core/clipboard-text.js";import{runTuiPage as O}from"../../../../core/tui/page-host.js";import{PAGE_CHROME_ROWS as F,columns as x,framed as W,pageFrame as L,theme as h}from"../../../../core/tui/panel.js";import{editBufferInEditor as G}from"../../../../clients/inbox/review/roundtrip.js";import{PLANNED_EVENTS as m}from"../resolve.js";import{moveDoc as H,readBody as k,readOnlyReason as I,toggleUnlisted as P,writeBody as B,writePreview as U,writeRules as v}from"./actions.js";import{axesOf as j,cycleAxis as $,cycleFacet as V,facetsOf as K,payloadRowOf as X,railEnter as D,railRowKey as M,railRowsOf as J,renderRail as Q,setTypedAxis as Y,typedAxisValue as Z}from"./rail-panel.js";import{ContextDetailPanel as ee}from"./detail-panel.js";import{ContextDocsPanel as te,buildRows as ie}from"./docs-panel.js";import{NO_FILTERS as se}from"./list-view.js";import{DELIVER_LEVELS as g,PlanSet as ne,describeRule as re,plural as S}from"./model.js";function oe(u){return u!=="boot"&&u!=="workspace-open"}l(oe,"needsMatch");const le={boot:"","workspace-open":"","file-read":"absolute path glob, or ./ for this document\u2019s own directory","document-read":"document name glob",command:"command-path glob, e.g. node new","pre-command":"command-path glob, e.g. node new","slash-command":"slash command name glob"},a=26,de=86,he=112,q=6,ce=48,ue=100,ae=.45;function fe(u){const e=Math.max(1,u-a-q);return Math.max(ce,Math.min(ue,Math.floor(e*ae)))}l(fe,"docsWidthFor");class pe{static{l(this,"ContextAdminShell")}tui;terminalRows;bindings;suspendForChild;profiles;snapshot;plans;zone="rail";railIndex=0;filters=se;rows=[];searching=!1;docs;detail=new ee;modal;notice;busy;edited=new Set;bodies=new Map;_focused=!1;onCancel;onSubmit;constructor(e,t,i,n,r,o){this.tui=t,this.terminalRows=i,this.bindings=n,this.suspendForChild=r,this.profiles=o,this.snapshot=e,this.plans=new ne(e,()=>{this.refreshRows(),this.tui.requestRender()}),this.docs=new te(()=>this.tui.requestRender()),this.rebuild()}set focused(e){this._focused=e}get focused(){return this._focused}invalidate(){}dispose(){this.plans.dispose()}rebuild(){this.refreshRows(),this.plans.warm(this.snapshot.event)}refreshRows(){this.rows=ie(this.plans,this.snapshot.event),this.docs.setRows(this.rows,this.snapshot.event),this.syncDetail()}setFilters(e){this.filters=e,this.docs.setFilters(e),this.syncDetail()}syncDetail(){const e=this.docs.selected,t=e===void 0?null:I(e.anchor),i=this.plans.peek(this.snapshot.event)?.subject??null;this.detail.setContext(e,this.snapshot.event,t,i,e===void 0?void 0:this.bodies.get(e.key))}setSnapshot(e){const t=this.railRows()[this.railIndex];this.snapshot=e,this.plans.setSnapshot(e),this.notice=void 0,this.rebuild(),this.holdRail(t)}holdRail(e){if(e===void 0)return;const t=this.railRows(),i=M(e),n=t.findIndex(r=>M(r)===i);this.railIndex=Math.max(0,n>=0?n:t.findIndex(r=>r.kind==="event"&&r.event.dialled))}matches(e,t){return N(this.bindings,e,t,(i,n)=>s(i,n))}label(e,t){const i=this.bindings.gestures(e);return i.length===0?t:C(i[0].split(" > ").pop())}isDown(e){return s(e,"j")||s(e,"down")||this.matches("crtr.setup.list-down",e)}isUp(e){return s(e,"k")||s(e,"up")||this.matches("crtr.setup.list-up",e)}isDescend(e){return s(e,"l")||s(e,"right")||s(e,"enter")||this.matches("crtr.setup.advance",e)}isAscend(e){return s(e,"h")||s(e,"left")}cyclesEvent(e){const t=s(e,"right")||s(e,"left");return s(e,"tab")||!t&&this.matches("crtr.setup.tab-next",e)?1:s(e,"shift+tab")||!t&&this.matches("crtr.setup.tab-previous",e)?-1:0}handleInput(e){if(this.busy!==void 0)return;if(this.modal!==void 0){this.handleModal(e);return}if(this.searching){this.handleSearch(e);return}const t=this.cyclesEvent(e);if(t!==0){this.setSnapshot($(this.snapshot,"event",t,this.profiles));return}if(!(this.zone==="detail"&&!this.detail.editing&&s(e,"ctrl+d"))&&(s(e,"q")||this.matches("crtr.setup.cancel",e))){this.close();return}this.zone==="rail"?this.handleRail(e):this.zone==="docs"?this.handleDocs(e):this.handleDetail(e)}eventRows(){return m.map(e=>{const t=this.plans.peek(e);return{event:e,delivers:t===void 0?void 0:t.docs.filter(i=>i.finalRung!=="none").length,dialled:e===this.snapshot.event}})}railRows(){return J(this.eventRows(),X(this.snapshot),j(this.snapshot,this.profileName()),K(this.filters))}profileName(){const e=this.snapshot.profileId;return e===null?"none":this.profiles.find(t=>t.id===e)?.name??e}handleRail(e){const t=this.railRows();this.railIndex=Math.max(0,Math.min(this.railIndex,t.length-1));const i=t[this.railIndex],n=l(o=>{i!==void 0&&(i.kind==="event"?this.setSnapshot({...this.snapshot,event:i.event.event}):i.kind==="axis"?i.axis.typed?this.openAxisField(i.axis.id,i.axis.label):this.setSnapshot($(this.snapshot,i.axis.id,o,this.profiles)):i.facet.typed?this.openSearch():this.setFilters(V(this.filters,i.facet.id,o)))},"change"),r=D(i);this.isDown(e)?this.railIndex=Math.min(t.length-1,this.railIndex+1):this.isUp(e)?this.railIndex=Math.max(0,this.railIndex-1):s(e,"space")||this.matches("crtr.setup.toggle",e)?n(1):this.isDescend(e)?s(e,"enter")&&r!=="documents"?n(1):this.zone="docs":s(e,"escape")&&this.close()}handleDocs(e){e==="/"||s(e,"/")?this.openSearch():s(e,"y")?this.yankId():this.isDown(e)?(this.docs.move(1),this.syncDetail()):this.isUp(e)?(this.docs.move(-1),this.syncDetail()):s(e,"space")||this.matches("crtr.setup.toggle",e)?(this.docs.toggleGroup(),this.syncDetail()):this.isDescend(e)?this.docs.onGroup?(this.docs.toggleGroup(),this.syncDetail()):this.docs.selected!==void 0&&(this.zone="detail"):s(e,"escape")&&this.filters.query!==""?this.setFilters({...this.filters,query:""}):(this.isAscend(e)||s(e,"escape"))&&(this.zone="rail")}openSearch(){this.searching=!0,this.zone="docs",this.tui.requestRender()}handleSearch(e){s(e,"escape")?(this.searching=!1,this.setFilters({...this.filters,query:""})):s(e,"enter")?this.searching=!1:s(e,"backspace")?this.setFilters({...this.filters,query:this.filters.query.slice(0,-1)}):e.length===1&&e.charCodeAt(0)>=32&&this.setFilters({...this.filters,query:this.filters.query+e}),this.tui.requestRender()}handleDetail(e){s(e,"y")?this.yankId():this.detail.editing?this.handleEdit(e):this.handleRead(e)}yankId(){const e=this.docs.selected;if(e===void 0)return;const{system:t,tmux:i}=T(e.key);this.notice=t||i?{text:`Copied ${e.key}${t?"":" to the tmux buffer"}`,ok:!0}:{text:"No clipboard tool available \u2014 nothing copied",ok:!1},this.tui.requestRender()}handleRead(e){this.isDown(e)?this.detail.move(1):this.isUp(e)?this.detail.move(-1):s(e,"ctrl+d")?this.detail.page(1):s(e,"ctrl+u")?this.detail.page(-1):e==="G"||s(e,"shift+g")?this.detail.jump("bottom"):e==="g"||s(e,"g")?this.detail.jump("top"):e==="e"||s(e,"e")?this.detail.edit():this.isDescend(e)?this.openBody():(this.isAscend(e)||s(e,"escape"))&&(this.detail.back()||(this.zone="docs"))}openBody(){const e=this.docs.selected;if(e===void 0||!this.detail.openBody()||this.bodies.has(e.key))return;const t=e.key;k(e.anchor.doc).then(i=>{this.bodies.set(t,i),this.syncDetail(),this.tui.requestRender()},i=>{this.notice={text:i instanceof Error?i.message:String(i),ok:!1},this.detail.back(),this.tui.requestRender()})}handleEdit(e){if(this.isDown(e)){this.detail.move(1);return}if(this.isUp(e)){this.detail.move(-1);return}if(this.isAscend(e)||s(e,"escape")){this.detail.back();return}const t=this.writeGesture(e);t!==void 0&&(t.document&&this.refusesWrite()||t.start())}writeGesture(e){const t=l(i=>({start:i,document:!0}),"doc");if(s(e,"enter")||s(e,"space")||this.matches("crtr.setup.toggle",e))return this.detail.selected===void 0?void 0:t(()=>this.activate());if(s(e,"m"))return{start:l(()=>this.explainLimit(),"start"),document:!1};if(s(e,"b"))return t(()=>this.editBody());if(s(e,"x"))return t(()=>this.removeRule());if(s(e,"e"))return t(()=>this.composeRule());if(s(e,"u"))return t(()=>this.flipUnlisted());if(s(e,"r"))return t(()=>this.editMove());if(s(e,"w"))return t(()=>this.editPreview())}refusesWrite(){const e=this.record;if(e===void 0)return!1;const t=I(e);return t===null?!1:(this.notice={text:t,ok:!1},this.tui.requestRender(),!0)}activate(){const e=this.detail.selected;if(e!==void 0)switch(e.kind){case"rule":return this.cycleRuleLevel(e.at);case"add-rule":return this.composeRule();case"preview":return this.editPreview();case"unlisted":return this.flipUnlisted();case"body":return this.editBody();case"move":return this.editMove()}}get record(){return this.docs.selected?.anchor}apply(e){this.busy="writing\u2026",this.tui.requestRender(),e.then(t=>{this.busy=void 0,this.notice={text:t.message,ok:t.ok},t.ok&&(t.name!==void 0&&this.edited.add(t.name),this.bodies.clear(),this.plans.refresh(),this.rebuild()),this.tui.requestRender()})}cycleRuleLevel(e){const t=this.record,i=t?.doc.rules[e];if(t===void 0||i===void 0)return;const r=g[(g.indexOf(i.deliver)+1)%g.length],o=t.doc.rules.map((d,p)=>p===e?{...d,deliver:r}:d);this.apply(v(t,o,`${t.doc.displayName} now delivers ${r} on ${i.on}.`))}removeRule(){const e=this.record,t=this.detail.selectedRule;if(e===void 0||t===void 0){this.notice={text:"Select a delivery rule to remove.",ok:!1};return}const i=e.doc.rules[t],n=e.doc.rules.filter((r,o)=>o!==t);this.modal={kind:"confirm",title:"Remove delivery rule",message:`${e.doc.displayName} will stop delivering on ${i.on} (${re(i)}).`,submit:l(()=>this.apply(v(e,n,`Removed the ${i.on} rule from ${e.doc.displayName}.`)),"submit")}}composeRule(){const e=this.record;e!==void 0&&(this.modal={kind:"choice",title:"New rule \u2014 activity",options:[...m],index:m.indexOf(this.snapshot.event),submit:l(t=>{const i=t,n=l(r=>{this.modal={kind:"choice",title:"New rule \u2014 deliver",options:[...g],index:0,submit:l(o=>{this.modal=void 0;const d={on:i,...r===""?{}:{match:[r]},deliver:o};this.apply(v(e,[...e.doc.rules,d],`${e.doc.displayName} now delivers ${o} on ${i}.`))},"submit")}},"chooseLevel");if(!oe(i)){n("");return}this.modal={kind:"field",title:`New rule \u2014 ${i} match`,hint:le[i],input:y(""),submit:l(r=>{const o=r.trim();if(o===""){this.modal=void 0,this.notice={text:`A ${i} rule needs a match glob.`,ok:!1};return}n(o)},"submit")}},"submit")})}flipUnlisted(){const e=this.record;e!==void 0&&this.apply(P(e))}editPreview(){const e=this.record;e!==void 0&&(this.modal={kind:"field",title:"Preview",hint:"the one line a reader decides to open the document on",input:y(e.doc.preview),submit:l(t=>{this.modal=void 0,this.apply(U(e,t))},"submit")})}editBody(){const e=this.record;e!==void 0&&(this.busy="reading the body\u2026",this.tui.requestRender(),k(e.doc).then(t=>{this.busy=void 0;const i=this.suspendForChild();let n;try{n=G(t)}finally{i()}if(n.error!==void 0)this.notice={text:n.error,ok:!1};else if(n.text===t)this.notice={text:`${e.doc.displayName} came back unchanged \u2014 nothing written.`,ok:!1};else{this.apply(B(e,n.text));return}this.tui.requestRender()},t=>{this.busy=void 0,this.notice={text:t instanceof Error?t.message:String(t),ok:!1},this.tui.requestRender()}))}editMove(){const e=this.record;e!==void 0&&(this.modal={kind:"field",title:"Rename",hint:"the new name under this document\u2019s own owner",input:y(e.doc.displayName),submit:l(t=>{this.modal=void 0,this.apply(H(e,t))},"submit")})}explainLimit(){this.notice={text:"Delivery limits are per owner on the profile; set one with `crtr profile project limit`.",ok:!1},this.tui.requestRender()}openAxisField(e,t){this.modal={kind:"field",title:t,hint:e==="cwd"?"absolute directory the project stores resolve from":"value the planner should match against",input:y(Z(this.snapshot,e)),submit:l(i=>{this.modal=void 0,this.setSnapshot(Y(this.snapshot,e,i))},"submit")}}close(){if(this.edited.size===0){this.onCancel?.();return}this.onSubmit?.({edited:[...this.edited]})}handleModal(e){const t=this.modal;if(t!==void 0){if(s(e,"escape")){this.modal=void 0;return}if(t.kind==="choice"){this.isDown(e)?t.index=Math.min(t.options.length-1,t.index+1):this.isUp(e)?t.index=Math.max(0,t.index-1):s(e,"enter")&&t.submit(t.options[t.index]);return}if(t.kind==="confirm"){s(e,"y")||s(e,"enter")?(this.modal=void 0,t.submit()):s(e,"n")&&(this.modal=void 0);return}s(e,"enter")?t.submit(t.input.getValue()):t.input.handleInput(e)}}renderModal(e,t){const i=this.modal;if(i===void 0)return[];let n;i.kind==="choice"?n=[h.fg("accent",h.bold(i.title)),"",...i.options.map((o,d)=>`${d===i.index?h.fg("accent","\u25B6"):" "} ${o}`)]:i.kind==="confirm"?n=[h.fg("warning",h.bold(i.title)),"",...ge(i.message,Math.max(1,e-6))]:n=[h.fg("accent",h.bold(i.title)),h.fg("dim",i.hint),"",i.input.render(Math.max(1,e-6))[0]??""];const r=W(n,e);for(;r.length<t;)r.push("");return r.slice(0,t)}footer(e,t){if(this.busy!==void 0)return h.fg("warning",this.busy);if(this.modal?.kind==="choice")return h.fg("dim","j/k choose \xB7 enter apply \xB7 esc cancel");if(this.modal?.kind==="confirm")return h.fg("dim","y/enter confirm \xB7 n/esc cancel");if(this.modal?.kind==="field")return h.fg("dim","type \xB7 enter apply \xB7 esc cancel");if(this.searching)return h.fg("dim","type to search names \xB7 enter keep \xB7 esc clear");if(this.notice===void 0&&this.plans.error!==void 0)return h.fg("warning",b(`dry run refused: ${this.plans.error}`,e));if(this.notice!==void 0)return h.fg(this.notice.ok?"success":"warning",b(this.notice.text,e));const i=`${this.label("crtr.setup.list-down","j")}/${this.label("crtr.setup.list-up","k")}`,n=this.zone==="rail"?`${i} row \xB7 ${me(t)}`:this.zone==="docs"?`${i} row \xB7 ${this.docsGesture()} \xB7 / search \xB7 y id`:this.detail.editing?`${i} field \xB7 enter edit \xB7 e add \xB7 x remove \xB7 w preview \xB7 b body \xB7 u unlisted \xB7 m limit \xB7 r rename \xB7 y id \xB7 esc read`:this.detail.bodyOpen?`${i} scroll \xB7 ctrl-d/u page \xB7 g/G ends \xB7 y id \xB7 esc collapse`:`${i} scroll \xB7 enter body \xB7 e edit \xB7 y id \xB7 esc list`,r=`${this.label("crtr.setup.tab-next","tab")} event \xB7 ${this.label("crtr.setup.cancel","q")} close`,o=e-w(n)-w(r);return o>=2?`${h.fg("dim",n)}${" ".repeat(o)}${h.fg("dim",r)}`:h.fg("dim",b(`${n} \xB7 ${this.label("crtr.setup.cancel","q")} close`,e))}docsGesture(){return this.docs.onGroup?"space/enter open":"enter dossier"}render(e){const t=this.terminalRows(),i=Math.max(1,t-F),n=e>=de,r=this.railRows();this.railIndex=Math.max(0,Math.min(this.railIndex,r.length-1));const o=l(c=>Q({rows:r,index:this.railIndex,width:c,height:i,focused:this.zone==="rail",matched:this.docs.visibleCount,total:this.rows.length}),"rail");let d;if(e>=he){const c=fe(e),f=Math.max(1,e-a-c-q),_=x(this.docs.render(c,i,this.zone==="docs"),c,this.modal===void 0?this.detail.render(f,i,this.zone==="detail"):this.renderModal(f,i),f);d=x(o(a),a,_,e-a-3)}else if(n){const c=e-a-3,f=this.modal!==void 0?this.renderModal(c,i):this.zone==="detail"?this.detail.render(c,i,!0):this.docs.render(c,i,this.zone==="docs");d=x(o(a),a,f,c)}else this.modal!==void 0?d=this.renderModal(e,i):this.zone==="rail"?d=o(e):this.zone==="detail"?d=this.detail.render(e,i,!0):d=this.docs.render(e,i,!0);const p=m.filter(c=>this.plans.peek(c)===void 0).length,R=this.plans.peek(this.snapshot.event)?.docs.filter(c=>c.finalRung!=="none").length,E=[this.snapshot.event,R===void 0?"":`${R} delivered`,p>0?`${S(p,"event","events")} planning`:"all events planned",this.edited.size>0?`${S(this.edited.size,"doc","docs")} edited`:""].filter(c=>c!=="").join(" \xB7 ");return L({width:e,height:t,title:"crouter context",meta:E,body:d,footer:this.footer(e,r[this.railIndex])})}}function me(u){switch(D(u)){case"dial":return"space/enter dial \xB7 l documents";case"edit":return"space/enter edit \xB7 l documents";default:return"space change \xB7 enter documents"}}l(me,"railGesture");function y(u){const e=new A;return e.setValue(u),e.handleInput(""),e.focused=!0,e}l(y,"seeded");function ge(u,e){const t=[];let i="";for(const n of u.trim().split(/\s+/)){const r=i===""?n:`${i} ${n}`;w(r)<=e?i=r:(i!==""&&t.push(i),i=n)}return i!==""&&t.push(i),t}l(ge,"wrap");async function _e(u,e){return O(({tui:t,terminal:i,bindings:n,suspendForChild:r},o)=>{const d=new pe(u,t,()=>i.rows,n,r,e);return d.onCancel=o.cancel,d.onSubmit=o.submit,d})}l(_e,"runContextAdmin");export{pe as ContextAdminShell,_e as runContextAdmin};