@north-light/crouter 0.3.352 → 0.3.354

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 (616) 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 +133 -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 +167 -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 +9 -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/04-orchestration-kernel.md +7 -7
  25. package/dist/builtin-memory/05-kinds/advisor/01-orchestrator.md +1 -1
  26. package/dist/builtin-memory/05-kinds/explore/00-base.md +2 -2
  27. package/dist/builtin-memory/05-kinds/explore/01-orchestrator.md +2 -2
  28. package/dist/builtin-memory/crouter-concepts/INDEX.md +2 -2
  29. package/dist/builtin-memory/crouter-concepts/lifecycle-and-wakes.md +1 -1
  30. package/dist/builtin-memory/crouter-concepts/memory.md +15 -15
  31. package/dist/builtin-memory/crouter-concepts/nodes-and-the-canvas.md +1 -1
  32. package/dist/builtin-memory/crouter-concepts/profiles-kinds-and-modes.md +5 -5
  33. package/dist/builtin-memory/crouter-concepts/scopes-and-trust.md +1 -1
  34. package/dist/builtin-memory/crouter-concepts/why-a-daemon.md +1 -1
  35. package/dist/builtin-memory/crouter-sdk/INDEX.md +2 -2
  36. package/dist/builtin-memory/crouter-sdk/README.md +5 -6
  37. package/dist/builtin-memory/crouter-sdk/errors.md +0 -13
  38. package/dist/builtin-memory/crouter-sdk/guides/README.md +0 -1
  39. package/dist/builtin-memory/crouter-sdk/guides/event-driven-assistant.md +2 -2
  40. package/dist/builtin-memory/crouter-sdk/nodes.md +0 -2
  41. package/dist/builtin-memory/crouter-sdk/resources.md +0 -1
  42. package/dist/builtin-memory/explore/exploration-doc.md +4 -4
  43. package/dist/builtin-memory/insights/capture.md +6 -6
  44. package/dist/builtin-memory/insights/init.md +14 -14
  45. package/dist/builtin-memory/internal/INDEX.md +4 -4
  46. package/dist/builtin-memory/internal/agent-shaping.md +20 -20
  47. package/dist/builtin-memory/internal/examples/imessage-assistant.md +2 -2
  48. package/dist/builtin-memory/internal/marketplaces.md +2 -2
  49. package/dist/builtin-memory/internal/memory-loading.md +31 -30
  50. package/dist/builtin-memory/internal/nodes-and-canvas.md +1 -1
  51. package/dist/builtin-memory/internal/plugins.md +16 -14
  52. package/dist/builtin-memory/internal/storage-tiers.md +4 -4
  53. package/dist/builtin-memory/memory-read-orientation.md +1 -1
  54. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/memory-slash-commands.ts +32 -40
  55. package/dist/clients/attach/input/controller.js +1 -1
  56. package/dist/clients/attach/input/ref-autocomplete.js +1 -1
  57. package/dist/clients/attach/input/titled-editor.js +1 -1
  58. package/dist/clients/attach/render/chat-view.js +1 -1
  59. package/dist/clients/attach/render/crtr-output.d.ts +1 -2
  60. package/dist/clients/attach/render/crtr-output.js +17 -17
  61. package/dist/clients/attach/render/group-activity.d.ts +8 -8
  62. package/dist/clients/attach/render/group-activity.js +2 -2
  63. package/dist/clients/attach/render/group-recap.js +1 -1
  64. package/dist/clients/attach/render/tool-calls.d.ts +1 -1
  65. package/dist/clients/attach/session/profile-files.js +1 -1
  66. package/dist/clients/attach/slash/dispatch.js +1 -1
  67. package/dist/clients/attach/viewer.js +806 -1553
  68. package/dist/commands/api-client.d.ts +2 -0
  69. package/dist/commands/api-client.js +3 -3
  70. package/dist/commands/canvas/edges.d.ts +2 -0
  71. package/dist/commands/canvas/edges.js +2 -0
  72. package/dist/commands/canvas/list.d.ts +4 -0
  73. package/dist/commands/canvas/list.js +3 -0
  74. package/dist/commands/canvas/read.d.ts +8 -0
  75. package/dist/commands/canvas/read.js +5 -0
  76. package/dist/commands/canvas/search.d.ts +2 -0
  77. package/dist/commands/canvas/search.js +3 -0
  78. package/dist/commands/canvas/unwatch.d.ts +2 -0
  79. package/dist/commands/canvas/unwatch.js +1 -0
  80. package/dist/commands/canvas/watch.d.ts +3 -0
  81. package/dist/commands/canvas/watch.js +1 -0
  82. package/dist/commands/canvas-analytics.js +1 -1
  83. package/dist/commands/canvas-history/grep.js +4 -4
  84. package/dist/commands/canvas-history/read.js +2 -2
  85. package/dist/commands/canvas-history/search.js +7 -7
  86. package/dist/commands/canvas-history/shared.d.ts +0 -1
  87. package/dist/commands/canvas-history/shared.js +1 -1
  88. package/dist/commands/canvas-history/stats.js +2 -2
  89. package/dist/commands/canvas-history.js +1 -1
  90. package/dist/commands/canvas.js +1 -1
  91. package/dist/commands/doc/delete.d.ts +2 -0
  92. package/dist/commands/doc/delete.js +1 -0
  93. package/dist/commands/doc/edit.d.ts +2 -0
  94. package/dist/commands/doc/edit.js +1 -0
  95. package/dist/commands/doc/history.d.ts +2 -0
  96. package/dist/commands/doc/history.js +2 -0
  97. package/dist/commands/doc/lint.d.ts +2 -0
  98. package/dist/commands/doc/lint.js +2 -0
  99. package/dist/commands/doc/list.d.ts +2 -0
  100. package/dist/commands/doc/list.js +1 -0
  101. package/dist/commands/doc/move.d.ts +2 -0
  102. package/dist/commands/doc/move.js +1 -0
  103. package/dist/commands/doc/read.d.ts +2 -0
  104. package/dist/commands/doc/read.js +1 -0
  105. package/dist/commands/doc/shared.d.ts +25 -0
  106. package/dist/commands/doc/shared.js +2 -0
  107. package/dist/commands/doc/write.d.ts +2 -0
  108. package/dist/commands/doc/write.js +1 -0
  109. package/dist/commands/{memory.d.ts → doc.d.ts} +1 -1
  110. package/dist/commands/doc.js +1 -0
  111. package/dist/commands/human/review.js +1 -1
  112. package/dist/commands/node/bash.js +2 -2
  113. package/dist/commands/node/create.js +1 -1
  114. package/dist/commands/node/inspect.js +10 -10
  115. package/dist/commands/node/lifecycle.js +2 -2
  116. package/dist/commands/node/outcome.js +1 -1
  117. package/dist/commands/node/subscription.js +1 -1
  118. package/dist/commands/node-context.js +2 -2
  119. package/dist/commands/pkg/browse/catalog.js +1 -1
  120. package/dist/commands/pkg/browse/doc-view.js +1 -1
  121. package/dist/commands/pkg/browse/model.d.ts +9 -17
  122. package/dist/commands/pkg/plugin-inspect.js +1 -1
  123. package/dist/commands/pkg/plugin-manage.d.ts +4 -8
  124. package/dist/commands/pkg/plugin-manage.js +15 -17
  125. package/dist/commands/profile/list.js +1 -1
  126. package/dist/commands/profile/new.js +1 -1
  127. package/dist/commands/profile/project.js +1 -1
  128. package/dist/commands/profile/show.js +1 -1
  129. package/dist/commands/push.js +3 -3
  130. package/dist/commands/sys/config.js +1 -1
  131. package/dist/commands/sys/context/admin/actions.d.ts +18 -43
  132. package/dist/commands/sys/context/admin/actions.js +1 -2
  133. package/dist/commands/sys/context/admin/detail-panel.d.ts +17 -25
  134. package/dist/commands/sys/context/admin/detail-panel.js +2 -1
  135. package/dist/commands/sys/context/admin/docs-panel.d.ts +7 -6
  136. package/dist/commands/sys/context/admin/docs-panel.js +1 -1
  137. package/dist/commands/sys/context/admin/list-view.d.ts +12 -12
  138. package/dist/commands/sys/context/admin/list-view.js +1 -1
  139. package/dist/commands/sys/context/admin/model.d.ts +96 -69
  140. package/dist/commands/sys/context/admin/model.js +1 -1
  141. package/dist/commands/sys/context/admin/rail-panel.d.ts +7 -5
  142. package/dist/commands/sys/context/admin/rail-panel.js +1 -1
  143. package/dist/commands/sys/context/admin/read-view.d.ts +10 -14
  144. package/dist/commands/sys/context/admin/read-view.js +1 -2
  145. package/dist/commands/sys/context/admin/shell.d.ts +26 -31
  146. package/dist/commands/sys/context/admin/shell.js +1 -1
  147. package/dist/commands/sys/context/admin.js +2 -2
  148. package/dist/commands/sys/context/doc.js +2 -3
  149. package/dist/commands/sys/context/expose.js +2 -2
  150. package/dist/commands/sys/context/prompt-review.js +4 -4
  151. package/dist/commands/sys/context/resolve.d.ts +92 -65
  152. package/dist/commands/sys/context/resolve.js +7 -9
  153. package/dist/commands/sys/context.js +1 -1
  154. package/dist/commands/sys/doctor.js +1 -1
  155. package/dist/commands/sys/migrate.js +1 -1
  156. package/dist/commands/sys/panels/profiles-panel.d.ts +3 -1
  157. package/dist/commands/sys/panels/profiles-panel.js +1 -1
  158. package/dist/commands/sys/sync-deps.d.ts +6 -11
  159. package/dist/commands/sys/sync-deps.js +7 -8
  160. package/dist/commands/sys/sync-project-guidance.js +5 -4
  161. package/dist/commands/sys/sync-shared.d.ts +41 -4
  162. package/dist/commands/sys/sync-shared.js +1 -1
  163. package/dist/commands/sys/sync-skills.js +2 -2
  164. package/dist/commands/sys/sync.js +1 -1
  165. package/dist/core/bash-job-supervisor.d.ts +2 -3
  166. package/dist/core/bash-job-supervisor.js +3 -3
  167. package/dist/core/bash-jobs.d.ts +0 -5
  168. package/dist/core/bash-jobs.js +7 -7
  169. package/dist/core/bootstrap.js +2 -2
  170. package/dist/core/canvas/canvas.d.ts +6 -50
  171. package/dist/core/canvas/canvas.js +16 -21
  172. package/dist/core/canvas/db.d.ts +4 -1
  173. package/dist/core/canvas/db.js +2 -2
  174. package/dist/core/canvas/history.d.ts +11 -39
  175. package/dist/core/canvas/history.js +9 -20
  176. package/dist/core/canvas/install-id.d.ts +2 -2
  177. package/dist/core/canvas/install-id.js +1 -1
  178. package/dist/core/canvas/memory-reads.d.ts +5 -0
  179. package/dist/core/canvas/memory-reads.js +1 -1
  180. package/dist/core/canvas/migrations.js +215 -41
  181. package/dist/core/canvas/node-agent-paths.js +1 -1
  182. package/dist/core/canvas/node-tokens.js +1 -1
  183. package/dist/core/canvas/paths.d.ts +0 -4
  184. package/dist/core/canvas/paths.js +1 -1
  185. package/dist/core/canvas/remote-canvas-source.d.ts +0 -1
  186. package/dist/core/canvas/remote-canvas-source.js +1 -1
  187. package/dist/core/canvas/render-source.d.ts +9 -6
  188. package/dist/core/canvas/render-source.js +6 -6
  189. package/dist/core/canvas/sessions.js +2 -2
  190. package/dist/core/canvas/source.d.ts +6 -0
  191. package/dist/core/canvas/tree.d.ts +29 -0
  192. package/dist/core/canvas/tree.js +12 -0
  193. package/dist/core/canvas/types.d.ts +0 -20
  194. package/dist/core/command-plugins/bundle.js +1 -1
  195. package/dist/core/config.d.ts +1 -1
  196. package/dist/core/conversation-store/listener.js +4 -2
  197. package/dist/core/feed/feed.d.ts +9 -7
  198. package/dist/core/feed/feed.js +3 -7
  199. package/dist/core/feed/inbox.d.ts +3 -5
  200. package/dist/core/feed/inbox.js +1 -10
  201. package/dist/core/feed/messages.d.ts +33 -6
  202. package/dist/core/feed/messages.js +10 -7
  203. package/dist/core/feed/reports.d.ts +10 -0
  204. package/dist/core/feed/reports.js +2 -0
  205. package/dist/core/grants/remove.js +1 -1
  206. package/dist/core/graph/access.d.ts +24 -0
  207. package/dist/core/graph/access.js +8 -0
  208. package/dist/core/graph/bodies.d.ts +6 -0
  209. package/dist/core/graph/bodies.js +1 -0
  210. package/dist/core/graph/deletion.d.ts +9 -0
  211. package/dist/core/graph/deletion.js +5 -0
  212. package/dist/core/graph/diff.d.ts +4 -0
  213. package/dist/core/graph/diff.js +4 -0
  214. package/dist/core/graph/documents.d.ts +160 -0
  215. package/dist/core/graph/documents.js +7 -0
  216. package/dist/core/graph/edges.d.ts +24 -0
  217. package/dist/core/graph/edges.js +1 -0
  218. package/dist/core/graph/events.d.ts +26 -0
  219. package/dist/core/graph/events.js +6 -0
  220. package/dist/core/graph/exposures.d.ts +53 -0
  221. package/dist/core/graph/exposures.js +4 -0
  222. package/dist/core/graph/jobs.d.ts +31 -0
  223. package/dist/core/graph/jobs.js +2 -0
  224. package/dist/core/graph/names.d.ts +28 -0
  225. package/dist/core/graph/names.js +3 -0
  226. package/dist/core/graph/objects.d.ts +55 -0
  227. package/dist/core/graph/objects.js +9 -0
  228. package/dist/core/graph/package-docs.d.ts +31 -0
  229. package/dist/core/graph/package-docs.js +5 -0
  230. package/dist/core/graph/package-files.d.ts +20 -0
  231. package/dist/core/graph/package-files.js +2 -0
  232. package/dist/core/graph/reader.d.ts +21 -0
  233. package/dist/core/graph/reader.js +3 -0
  234. package/dist/core/graph/repo-sync/exchange.d.ts +34 -0
  235. package/dist/core/graph/repo-sync/exchange.js +2 -0
  236. package/dist/core/graph/repo-sync/identity.d.ts +30 -0
  237. package/dist/core/graph/repo-sync/identity.js +1 -0
  238. package/dist/core/graph/repo-sync/index.d.ts +4 -0
  239. package/dist/core/graph/repo-sync/index.js +1 -0
  240. package/dist/core/graph/repo-sync/mirror.d.ts +30 -0
  241. package/dist/core/graph/repo-sync/mirror.js +6 -0
  242. package/dist/core/graph/repo-sync/ref-format.d.ts +76 -0
  243. package/dist/core/graph/repo-sync/ref-format.js +2 -0
  244. package/dist/core/graph/repo-sync/repos.d.ts +17 -0
  245. package/dist/core/graph/repo-sync/repos.js +3 -0
  246. package/dist/core/graph/repo-sync/sync.d.ts +42 -0
  247. package/dist/core/graph/repo-sync/sync.js +2 -0
  248. package/dist/core/graph/rules.d.ts +26 -0
  249. package/dist/core/graph/rules.js +3 -0
  250. package/dist/core/graph/spaces/app.d.ts +3 -0
  251. package/dist/core/graph/spaces/app.js +1 -0
  252. package/dist/core/graph/spaces/index.d.ts +19 -0
  253. package/dist/core/graph/spaces/index.js +1 -0
  254. package/dist/core/graph/spaces/person.d.ts +5 -0
  255. package/dist/core/graph/spaces/person.js +2 -0
  256. package/dist/core/graph/spaces/repo.d.ts +4 -0
  257. package/dist/core/graph/spaces/repo.js +1 -0
  258. package/dist/core/graph/types.d.ts +75 -0
  259. package/dist/core/graph/types.js +1 -0
  260. package/dist/core/graph/watches.d.ts +62 -0
  261. package/dist/core/graph/watches.js +18 -0
  262. package/dist/core/human/feedback-companion.js +1 -1
  263. package/dist/core/human/requests.d.ts +3 -1
  264. package/dist/core/human/requests.js +6 -6
  265. package/dist/core/inspector/model.js +2 -2
  266. package/dist/core/io.js +5 -5
  267. package/dist/core/layout-migrate/index.d.ts +24 -1
  268. package/dist/core/layout-migrate/index.js +4 -4
  269. package/dist/core/layout-migrate/paths.d.ts +4 -0
  270. package/dist/core/layout-migrate/paths.js +1 -1
  271. package/dist/core/layout-migrate/stored-paths.d.ts +7 -0
  272. package/dist/core/layout-migrate/stored-paths.js +11 -11
  273. package/dist/core/layout-migrate/stores.d.ts +19 -6
  274. package/dist/core/layout-migrate/stores.js +3 -4
  275. package/dist/core/manifest.d.ts +0 -2
  276. package/dist/core/manifest.js +1 -1
  277. package/dist/core/{memory/extensions.d.ts → plugin-extensions.d.ts} +9 -10
  278. package/dist/core/plugin-extensions.js +1 -0
  279. package/dist/core/preview-registry.d.ts +1 -1
  280. package/dist/core/preview-registry.js +3 -2
  281. package/dist/core/profiles/manifest.d.ts +7 -7
  282. package/dist/core/profiles/manifest.js +1 -1
  283. package/dist/core/profiles/select.js +3 -3
  284. package/dist/core/review/birth.js +1 -1
  285. package/dist/core/review/companion.js +1 -1
  286. package/dist/core/review/stage.d.ts +12 -1
  287. package/dist/core/review/stage.js +1 -1
  288. package/dist/core/review/store.d.ts +2 -0
  289. package/dist/core/review/store.js +1 -1
  290. package/dist/core/review/types.d.ts +7 -1
  291. package/dist/core/runs/events.js +1 -1
  292. package/dist/core/runs/operations.js +5 -5
  293. package/dist/core/runs/questions.js +2 -2
  294. package/dist/core/runtime/bearings-render.d.ts +13 -7
  295. package/dist/core/runtime/bearings-render.js +12 -12
  296. package/dist/core/runtime/bearings.d.ts +8 -18
  297. package/dist/core/runtime/bearings.js +7 -7
  298. package/dist/core/runtime/broker/daemon-ops.d.ts +7 -12
  299. package/dist/core/runtime/broker/daemon-ops.js +1 -1
  300. package/dist/core/runtime/broker/fault-retry.d.ts +2 -0
  301. package/dist/core/runtime/broker/fault-retry.js +1 -1
  302. package/dist/core/runtime/broker/frame-dispatch.d.ts +1 -1
  303. package/dist/core/runtime/broker/frame-memory-refs.d.ts +7 -2
  304. package/dist/core/runtime/broker/frame-memory-refs.js +1 -1
  305. package/dist/core/runtime/broker/inbox.d.ts +1 -4
  306. package/dist/core/runtime/broker/inbox.js +1 -10
  307. package/dist/core/runtime/broker/rebind.js +1 -1
  308. package/dist/core/runtime/broker/retry-card-elision.d.ts +7 -0
  309. package/dist/core/runtime/broker/retry-card-elision.js +1 -0
  310. package/dist/core/runtime/broker-extension-render.d.ts +0 -13
  311. package/dist/core/runtime/broker-extension-render.js +2 -4
  312. package/dist/core/runtime/broker-persona-guidance.js +3 -3
  313. package/dist/core/runtime/broker-protocol.d.ts +1 -1
  314. package/dist/core/runtime/broker.js +1 -1
  315. package/dist/core/runtime/close.d.ts +9 -4
  316. package/dist/core/runtime/close.js +1 -1
  317. package/dist/core/runtime/deliver-live.js +1 -1
  318. package/dist/core/runtime/kickoff.js +17 -19
  319. package/dist/core/runtime/launch-target.d.ts +7 -0
  320. package/dist/core/runtime/launch-target.js +1 -1
  321. package/dist/core/runtime/ledger.d.ts +10 -0
  322. package/dist/core/runtime/ledger.js +3 -0
  323. package/dist/core/runtime/lifecycle.js +2 -2
  324. package/dist/core/runtime/nodes.d.ts +10 -2
  325. package/dist/core/runtime/nodes.js +1 -1
  326. package/dist/core/runtime/outcome-document.d.ts +2 -2
  327. package/dist/core/runtime/outcome-document.js +1 -1
  328. package/dist/core/runtime/persona.js +2 -2
  329. package/dist/core/runtime/placement.js +1 -1
  330. package/dist/core/runtime/promote.d.ts +2 -2
  331. package/dist/core/runtime/promote.js +1 -1
  332. package/dist/core/runtime/prospective-inventory-cli.js +2 -2
  333. package/dist/core/runtime/recycle.js +1 -1
  334. package/dist/core/runtime/reopen.js +1 -1
  335. package/dist/core/runtime/revive.js +2 -2
  336. package/dist/core/runtime/roadmap.d.ts +17 -9
  337. package/dist/core/runtime/roadmap.js +4 -4
  338. package/dist/core/runtime/spawn-env.js +1 -1
  339. package/dist/core/runtime/spawn.d.ts +5 -3
  340. package/dist/core/runtime/spawn.js +2 -2
  341. package/dist/core/runtime/structured-output.d.ts +3 -1
  342. package/dist/core/runtime/structured-output.js +4 -4
  343. package/dist/core/scope.d.ts +1 -32
  344. package/dist/core/scope.js +1 -1
  345. package/dist/core/scoped-state/db.js +2 -1
  346. package/dist/core/scoped-state/migrate.js +2 -2
  347. package/dist/core/scoped-state/profiles.d.ts +11 -0
  348. package/dist/core/scoped-state/profiles.js +1 -1
  349. package/dist/core/scoped-state/schema.d.ts +1 -1
  350. package/dist/core/scoped-state/schema.js +7 -5
  351. package/dist/core/spaces/permissions.d.ts +0 -14
  352. package/dist/core/spaces/permissions.js +1 -1
  353. package/dist/core/spaces/stop.d.ts +13 -0
  354. package/dist/core/spaces/stop.js +2 -2
  355. package/dist/core/storage/tables.d.ts +1 -1
  356. package/dist/core/substrate/delivery/corpus.d.ts +21 -0
  357. package/dist/core/substrate/delivery/corpus.js +3 -0
  358. package/dist/core/substrate/delivery/deliver.d.ts +76 -0
  359. package/dist/core/substrate/delivery/deliver.js +6 -0
  360. package/dist/core/substrate/delivery/listings.d.ts +27 -0
  361. package/dist/core/substrate/delivery/listings.js +4 -0
  362. package/dist/core/substrate/delivery/match.d.ts +28 -0
  363. package/dist/core/substrate/delivery/match.js +1 -0
  364. package/dist/core/substrate/delivery/plan.d.ts +67 -0
  365. package/dist/core/substrate/delivery/plan.js +3 -0
  366. package/dist/core/substrate/delivery/render-boot.d.ts +20 -0
  367. package/dist/core/substrate/delivery/render-boot.js +54 -0
  368. package/dist/core/substrate/delivery/render-event.d.ts +47 -0
  369. package/dist/core/substrate/delivery/render-event.js +6 -0
  370. package/dist/core/substrate/delivery/sub-persona-menu.d.ts +2 -0
  371. package/dist/core/substrate/delivery/sub-persona-menu.js +6 -0
  372. package/dist/core/substrate/delivery/types.d.ts +30 -0
  373. package/dist/core/substrate/delivery/types.js +0 -0
  374. package/dist/core/substrate/gate-explain.d.ts +0 -13
  375. package/dist/core/substrate/gate-explain.js +1 -1
  376. package/dist/core/substrate/schema.d.ts +11 -139
  377. package/dist/core/substrate/schema.js +1 -1
  378. package/dist/core/substrate/subject-fields.d.ts +3 -0
  379. package/dist/core/substrate/subject.d.ts +2 -1
  380. package/dist/core/substrate/subject.js +1 -1
  381. package/dist/daemon/api/app-listener.js +11 -11
  382. package/dist/daemon/api/handlers/app-profiles.js +1 -1
  383. package/dist/daemon/api/handlers/bash-jobs.js +1 -2
  384. package/dist/daemon/api/handlers/broker-ops.js +1 -1
  385. package/dist/daemon/api/handlers/canvas.js +5 -5
  386. package/dist/daemon/api/handlers/daemon.js +1 -1
  387. package/dist/daemon/api/handlers/delivery.d.ts +2 -0
  388. package/dist/daemon/api/handlers/delivery.js +1 -0
  389. package/dist/daemon/api/handlers/{memory.d.ts → docs.d.ts} +1 -1
  390. package/dist/daemon/api/handlers/docs.js +1 -0
  391. package/dist/daemon/api/handlers/hook-exec.js +1 -1
  392. package/dist/daemon/api/handlers/messages.js +2 -2
  393. package/dist/daemon/api/handlers/modelauth.d.ts +3 -0
  394. package/dist/daemon/api/handlers/modelauth.js +1 -1
  395. package/dist/daemon/api/handlers/node-records.js +2 -2
  396. package/dist/daemon/api/handlers/nodes.js +1 -1
  397. package/dist/daemon/api/handlers/objects.d.ts +2 -0
  398. package/dist/daemon/api/handlers/objects.js +5 -0
  399. package/dist/daemon/api/handlers/package-docs.d.ts +2 -0
  400. package/dist/daemon/api/handlers/package-docs.js +1 -0
  401. package/dist/daemon/api/handlers/profiles.js +1 -1
  402. package/dist/daemon/api/handlers/reports.d.ts +2 -2
  403. package/dist/daemon/api/handlers/reports.js +4 -4
  404. package/dist/daemon/api/handlers/reviews.js +1 -1
  405. package/dist/daemon/api/handlers/vendor-status.d.ts +8 -0
  406. package/dist/daemon/api/handlers/vendor-status.js +1 -0
  407. package/dist/daemon/api/map.d.ts +2 -2
  408. package/dist/daemon/api/map.js +2 -2
  409. package/dist/daemon/api/operations.d.ts +1 -1
  410. package/dist/daemon/api/operations.js +1 -1
  411. package/dist/daemon/api/principal.d.ts +5 -0
  412. package/dist/daemon/api/principal.js +1 -1
  413. package/dist/daemon/api/reader.d.ts +17 -0
  414. package/dist/daemon/api/reader.js +1 -0
  415. package/dist/daemon/api/server.js +1 -1
  416. package/dist/daemon/control.d.ts +2 -3
  417. package/dist/daemon/crtrd.js +8 -6
  418. package/dist/daemon/fleet.js +4 -4
  419. package/dist/daemon/reconcilers/bash-deadline.d.ts +11 -1
  420. package/dist/daemon/reconcilers/bash-deadline.js +2 -1
  421. package/dist/daemon/reconcilers/broker-supervision.js +4 -4
  422. package/dist/daemon/reconcilers/live-obligation.js +1 -1
  423. package/dist/daemon/reconcilers/node-deadline.js +1 -1
  424. package/dist/daemon/reconcilers/node-lifecycle/freeze-lane.js +1 -1
  425. package/dist/daemon/reconcilers/storage-maintenance.d.ts +1 -0
  426. package/dist/daemon/reconcilers/storage-maintenance.js +1 -1
  427. package/dist/daemon/review/deliver.js +2 -2
  428. package/dist/daemon/review/finish.js +1 -1
  429. package/dist/hook-authoring.d.ts +0 -1
  430. package/dist/hook-authoring.js +3 -3
  431. package/dist/migrations/004-canvas-documents/apply.d.ts +10 -0
  432. package/dist/migrations/004-canvas-documents/apply.js +1 -0
  433. package/dist/migrations/004-canvas-documents/fields.d.ts +24 -0
  434. package/dist/migrations/004-canvas-documents/fields.js +2 -0
  435. package/dist/migrations/004-canvas-documents/index.d.ts +16 -0
  436. package/dist/migrations/004-canvas-documents/index.js +2 -0
  437. package/dist/migrations/004-canvas-documents/legacy/discover.d.ts +16 -0
  438. package/dist/migrations/004-canvas-documents/legacy/discover.js +1 -0
  439. package/dist/migrations/004-canvas-documents/legacy/history.d.ts +5 -0
  440. package/dist/migrations/004-canvas-documents/legacy/history.js +2 -0
  441. package/dist/migrations/004-canvas-documents/legacy/nested.d.ts +7 -0
  442. package/dist/migrations/004-canvas-documents/legacy/nested.js +1 -0
  443. package/dist/migrations/004-canvas-documents/legacy/parse.d.ts +14 -0
  444. package/dist/migrations/004-canvas-documents/legacy/parse.js +1 -0
  445. package/dist/migrations/004-canvas-documents/legacy/types.d.ts +91 -0
  446. package/dist/migrations/004-canvas-documents/legacy/types.js +0 -0
  447. package/dist/migrations/004-canvas-documents/legacy-edges.d.ts +6 -0
  448. package/dist/migrations/004-canvas-documents/legacy-edges.js +18 -0
  449. package/dist/migrations/004-canvas-documents/plan.d.ts +102 -0
  450. package/dist/migrations/004-canvas-documents/plan.js +3 -0
  451. package/dist/migrations/004-canvas-documents/pointers.d.ts +23 -0
  452. package/dist/migrations/004-canvas-documents/pointers.js +4 -0
  453. package/dist/migrations/activation.d.ts +9 -18
  454. package/dist/migrations/activation.js +2 -2
  455. package/dist/pi-extensions/broker-local.d.ts +2 -2
  456. package/dist/pi-extensions/broker-local.js +2 -2
  457. package/dist/pi-extensions/canvas-bash-valve.js +5 -4
  458. package/dist/pi-extensions/canvas-context-intro.js +2 -2
  459. package/dist/pi-extensions/canvas-doc-substrate.d.ts +0 -1
  460. package/dist/pi-extensions/canvas-doc-substrate.js +6 -6
  461. package/dist/pi-extensions/canvas-inbox-watcher.js +2 -2
  462. package/dist/pi-extensions/canvas-passive-context.js +1 -1
  463. package/dist/pi-extensions/canvas-recap.js +2 -2
  464. package/dist/pi-extensions/canvas-stophook.d.ts +1 -1
  465. package/dist/pi-extensions/canvas-stophook.js +1 -1
  466. package/dist/prompts/review.js +3 -3
  467. package/dist/shared/env.d.ts +5 -0
  468. package/dist/shared/env.js +1 -1
  469. package/dist/shared/generated-context.js +2 -10
  470. package/dist/shared/inbox-entry-body.d.ts +22 -0
  471. package/dist/shared/inbox-entry-body.js +10 -0
  472. package/dist/{core/memory → shared}/inline-ref-guidance.d.ts +2 -2
  473. package/dist/shared/inline-ref-guidance.js +2 -0
  474. package/dist/types.d.ts +3 -1
  475. package/docs/cli/memory-and-preferences.md +12 -14
  476. package/docs/concepts/README.md +1 -1
  477. package/docs/concepts/lifecycle-and-wakes.md +1 -1
  478. package/docs/concepts/memory.md +15 -15
  479. package/docs/concepts/nodes-and-the-canvas.md +1 -1
  480. package/docs/concepts/profiles-kinds-and-modes.md +5 -5
  481. package/docs/concepts/scopes-and-trust.md +1 -1
  482. package/docs/concepts/why-a-daemon.md +1 -1
  483. package/docs/sdk/README.md +5 -6
  484. package/docs/sdk/errors.md +0 -13
  485. package/docs/sdk/guides/README.md +0 -1
  486. package/docs/sdk/nodes.md +0 -2
  487. package/docs/sdk/resources.md +0 -1
  488. package/package.json +2 -2
  489. package/packages/crouter-identity/package.json +1 -1
  490. package/runtime.lock.json +11 -11
  491. package/dist/api/dto/memory.d.ts +0 -171
  492. package/dist/api/dto/memory.js +0 -1
  493. package/dist/builtin-memory/crouter-sdk/guides/app-memory.md +0 -73
  494. package/dist/builtin-memory/crouter-sdk/memory.md +0 -87
  495. package/dist/commands/broker-permissions.d.ts +0 -2
  496. package/dist/commands/broker-permissions.js +0 -1
  497. package/dist/commands/memory/client.d.ts +0 -11
  498. package/dist/commands/memory/client.js +0 -1
  499. package/dist/commands/memory/delete.d.ts +0 -1
  500. package/dist/commands/memory/delete.js +0 -1
  501. package/dist/commands/memory/edit.d.ts +0 -1
  502. package/dist/commands/memory/edit.js +0 -21
  503. package/dist/commands/memory/find.d.ts +0 -1
  504. package/dist/commands/memory/find.js +0 -1
  505. package/dist/commands/memory/history.d.ts +0 -1
  506. package/dist/commands/memory/history.js +0 -5
  507. package/dist/commands/memory/lint.d.ts +0 -1
  508. package/dist/commands/memory/lint.js +0 -1
  509. package/dist/commands/memory/list.d.ts +0 -1
  510. package/dist/commands/memory/list.js +0 -1
  511. package/dist/commands/memory/move.d.ts +0 -1
  512. package/dist/commands/memory/move.js +0 -1
  513. package/dist/commands/memory/origin.d.ts +0 -1
  514. package/dist/commands/memory/origin.js +0 -1
  515. package/dist/commands/memory/read.d.ts +0 -1
  516. package/dist/commands/memory/read.js +0 -6
  517. package/dist/commands/memory/shared.d.ts +0 -22
  518. package/dist/commands/memory/shared.js +0 -1
  519. package/dist/commands/memory/write.d.ts +0 -1
  520. package/dist/commands/memory/write.js +0 -13
  521. package/dist/commands/memory.js +0 -1
  522. package/dist/commands/node-inspect-artifacts.d.ts +0 -1
  523. package/dist/commands/node-inspect-artifacts.js +0 -8
  524. package/dist/core/help/memory-extensions.d.ts +0 -3
  525. package/dist/core/help/memory-extensions.js +0 -2
  526. package/dist/core/memory/cli-selector.d.ts +0 -13
  527. package/dist/core/memory/cli-selector.js +0 -1
  528. package/dist/core/memory/doc-link-grammar.d.ts +0 -20
  529. package/dist/core/memory/doc-link-grammar.js +0 -2
  530. package/dist/core/memory/extensions.js +0 -1
  531. package/dist/core/memory/history.d.ts +0 -87
  532. package/dist/core/memory/history.js +0 -6
  533. package/dist/core/memory/identity.d.ts +0 -65
  534. package/dist/core/memory/identity.js +0 -1
  535. package/dist/core/memory/inline-ref-guidance.js +0 -2
  536. package/dist/core/memory/inline-ref-inventory.d.ts +0 -9
  537. package/dist/core/memory/inline-ref-inventory.js +0 -1
  538. package/dist/core/memory/lint.d.ts +0 -163
  539. package/dist/core/memory/lint.js +0 -2
  540. package/dist/core/memory/mutation-domain.d.ts +0 -113
  541. package/dist/core/memory/mutation-domain.js +0 -12
  542. package/dist/core/memory/mutations.d.ts +0 -74
  543. package/dist/core/memory/mutations.js +0 -1
  544. package/dist/core/memory/project-namespace.d.ts +0 -31
  545. package/dist/core/memory/project-namespace.js +0 -2
  546. package/dist/core/memory/repository-association.d.ts +0 -31
  547. package/dist/core/memory/repository-association.js +0 -1
  548. package/dist/core/memory/service.d.ts +0 -145
  549. package/dist/core/memory/service.js +0 -2
  550. package/dist/core/memory/tree.d.ts +0 -39
  551. package/dist/core/memory/tree.js +0 -1
  552. package/dist/core/memory-resolver.d.ts +0 -280
  553. package/dist/core/memory-resolver.js +0 -2
  554. package/dist/core/nested-stores.d.ts +0 -18
  555. package/dist/core/nested-stores.js +0 -1
  556. package/dist/core/runtime/memory.d.ts +0 -3
  557. package/dist/core/runtime/memory.js +0 -1
  558. package/dist/core/substrate/frontmatter-validation.d.ts +0 -11
  559. package/dist/core/substrate/frontmatter-validation.js +0 -1
  560. package/dist/core/substrate/gate.d.ts +0 -16
  561. package/dist/core/substrate/gate.js +0 -1
  562. package/dist/core/substrate/index.d.ts +0 -18
  563. package/dist/core/substrate/index.js +0 -1
  564. package/dist/core/substrate/injected-store.d.ts +0 -75
  565. package/dist/core/substrate/injected-store.js +0 -2
  566. package/dist/core/substrate/listings.d.ts +0 -28
  567. package/dist/core/substrate/listings.js +0 -1
  568. package/dist/core/substrate/memory-events.d.ts +0 -6
  569. package/dist/core/substrate/memory-events.js +0 -1
  570. package/dist/core/substrate/on-read-node.d.ts +0 -6
  571. package/dist/core/substrate/on-read-node.js +0 -1
  572. package/dist/core/substrate/on-read.d.ts +0 -101
  573. package/dist/core/substrate/on-read.js +0 -9
  574. package/dist/core/substrate/plan.d.ts +0 -94
  575. package/dist/core/substrate/plan.js +0 -1
  576. package/dist/core/substrate/render-node.d.ts +0 -12
  577. package/dist/core/substrate/render-node.js +0 -1
  578. package/dist/core/substrate/render.d.ts +0 -41
  579. package/dist/core/substrate/render.js +0 -65
  580. package/dist/core/substrate/session-cache.d.ts +0 -27
  581. package/dist/core/substrate/session-cache.js +0 -1
  582. package/dist/core/substrate/surface-match.d.ts +0 -73
  583. package/dist/core/substrate/surface-match.js +0 -1
  584. package/dist/daemon/api/handlers/memory.js +0 -5
  585. package/dist/migrations/001-surfaces-frontmatter.d.ts +0 -2
  586. package/dist/migrations/001-surfaces-frontmatter.js +0 -1
  587. package/dist/migrations/002-profile-project-memory.d.ts +0 -2
  588. package/dist/migrations/002-profile-project-memory.js +0 -1
  589. package/dist/migrations/003-repository-root-memory-identity/front-door.d.ts +0 -26
  590. package/dist/migrations/003-repository-root-memory-identity/front-door.js +0 -11
  591. package/dist/migrations/003-repository-root-memory-identity/index.d.ts +0 -2
  592. package/dist/migrations/003-repository-root-memory-identity/index.js +0 -5
  593. package/dist/migrations/003-repository-root-memory-identity/references.d.ts +0 -95
  594. package/dist/migrations/003-repository-root-memory-identity/references.js +0 -5
  595. package/dist/migrations/003-repository-root-memory-identity/repository-facts.d.ts +0 -39
  596. package/dist/migrations/003-repository-root-memory-identity/repository-facts.js +0 -3
  597. package/dist/migrations/convergent.d.ts +0 -43
  598. package/dist/migrations/convergent.js +0 -2
  599. package/dist/migrations/corpus.d.ts +0 -75
  600. package/dist/migrations/corpus.js +0 -3
  601. package/dist/migrations/frontmatter-splice.d.ts +0 -15
  602. package/dist/migrations/frontmatter-splice.js +0 -8
  603. package/dist/migrations/profile-manifests.d.ts +0 -30
  604. package/dist/migrations/profile-manifests.js +0 -2
  605. package/dist/migrations/registry.d.ts +0 -7
  606. package/dist/migrations/registry.js +0 -1
  607. package/dist/migrations/runner.d.ts +0 -43
  608. package/dist/migrations/runner.js +0 -1
  609. package/dist/migrations/types.d.ts +0 -211
  610. package/dist/shared/birth-announcement.d.ts +0 -12
  611. package/dist/shared/birth-announcement.js +0 -1
  612. package/docs/sdk/guides/app-memory.md +0 -22
  613. package/docs/sdk/memory.md +0 -85
  614. /package/dist/{migrations/types.js → api/dto/delivery.js} +0 -0
  615. /package/dist/{core/memory → shared}/inline-ref-grammar.d.ts +0 -0
  616. /package/dist/{core/memory → shared}/inline-ref-grammar.js +0 -0
@@ -1,101 +0,0 @@
1
- import { type MemoryDoc, type MemoryTarget } from '../memory-resolver.js';
2
- import { type ContextExposureState, type ExposureTarget } from './injected-store.js';
3
- import { type Rung, type SubstrateDoc } from './schema.js';
4
- import type { NodeConfigSubject } from './subject-fields.js';
5
- export type DeliveryCause = 'directory listing attached to content delivery' | 'memory-read companion of content delivery';
6
- export interface AccountedDelivery {
7
- rung: Rung;
8
- cause?: DeliveryCause;
9
- /** Resolver descriptor for accounting-only attachment rows. */
10
- source?: MemoryDoc;
11
- }
12
- /** The renderer's structured delivery ledger. It records precisely the document
13
- * envelopes and listing lines that rendered, so diagnostics can report the
14
- * same attachment fixpoint without parsing its text or recreating it. */
15
- export interface DeliveryAccounting {
16
- deliveries: Map<string, AccountedDelivery>;
17
- }
18
- export declare function deliveryAccounting(): DeliveryAccounting;
19
- export declare function accountDelivery(accounting: DeliveryAccounting | undefined, doc: Pick<SubstrateDoc, 'path'>, rung: Rung, cause?: DeliveryCause, source?: MemoryDoc): void;
20
- /** How one content delivery's attachments render, and the ledger + corpus the
21
- * whole fixpoint runs against. ONE options object flows through every nested
22
- * companion delivery, so `dirs` accumulates across the fixpoint and a
23
- * companion inherits its parent's listing mode and memory target. */
24
- export interface ContentAttachmentOptions {
25
- /** Subject for companion `memory-read` gate evaluation. */
26
- subject: NodeConfigSubject | null;
27
- /** The one exposure ledger this fixpoint reads and registers against. */
28
- target: ExposureTarget;
29
- /** The corpus every directory question answers from — the caller's own
30
- * listing corpus, never an ambient re-resolution. */
31
- byName: ReadonlyMap<string, MemoryDoc>;
32
- /** What companion `memory-read` routes plan against. Absent = the ambient
33
- * cwd/profile target and this session's cached event corpus. */
34
- memoryTarget?: MemoryTarget;
35
- /** `blocks` attaches each disclosed listing as its own `<memory-listing>`.
36
- * `tree` attaches none and accumulates the disclosed directories into
37
- * `dirs` instead, for a caller that renders those members itself (the boot
38
- * catalog tree) and registers them as it renders. */
39
- listings: 'blocks' | 'tree';
40
- /** Accumulator for `tree` mode: every directory this fixpoint disclosed. */
41
- dirs?: string[];
42
- /** An explicit `crtr memory read`: the read doc's OWN directory renders
43
- * unfiltered and returns as `listing` rather than attaching as a block. */
44
- explicit?: boolean;
45
- /** Optional structured mirror of the actual emitted document deliveries. */
46
- accounting?: DeliveryAccounting;
47
- /** Why this winner was reached through the current content attachment walk. */
48
- deliveryCause?: DeliveryCause;
49
- }
50
- /** The attachment semantics of a content delivery. Content is read-equivalent:
51
- * it exposes its own/enclosing directory listings and fires memory-read routes.
52
- * The exposure ledger makes this finite even when companion routes cycle. */
53
- export declare function contentReadAttachments(doc: Pick<SubstrateDoc, 'name' | 'path' | 'body'>, opts: ContentAttachmentOptions): {
54
- blocks: string[];
55
- listing?: string[];
56
- };
57
- export declare function renderAutoLoadedContext(blocks: readonly string[]): string;
58
- /** Surface docs whose `read` entries match a successfully read file, using
59
- * the caller-supplied daemon snapshot subject. */
60
- export declare function renderOnReadDocBlocksForSubject(subject: NodeConfigSubject, readFilePath: string, target?: ExposureTarget, accounting?: DeliveryAccounting, memoryTarget?: MemoryTarget): string[];
61
- export declare function renderOnReadDocsForSubject(subject: NodeConfigSubject, readFilePath: string, target?: ExposureTarget, accounting?: DeliveryAccounting, memoryTarget?: MemoryTarget): string;
62
- /** Workspace boot docs using the snapshot's cwd/profile instead of a canvas
63
- * lookup. The shared exposure target prevents a later read from repeating a
64
- * document already loaded here.
65
- *
66
- * Each candidate's authored rung is clamped to its project's profile
67
- * relationship cap BEFORE filtering, ordering, rendering, and exposure
68
- * registration. A later explicit `crtr memory read` can still raise a document
69
- * that workspace-open disclosed at a lower rung. */
70
- export declare function renderWorkspaceOpenDocsForSubject(subject: NodeConfigSubject, cwd: string, profileId: string | null, target?: ExposureTarget, accounting?: DeliveryAccounting, memoryTarget?: MemoryTarget): string;
71
- /** Inner `<memory>` blocks for the memory-read event: docs whose
72
- * `memory-read` entries match the doc a `crtr memory read` just resolved
73
- * (known by its exact canonical `name` — no mount-stripped or other alias;
74
- * `excludeRealpath` keeps the resolved doc from delivering itself). Returns
75
- * unwrapped blocks — the read leaf composes one `<auto-loaded-context>`
76
- * envelope from these plus the directory listings. */
77
- export declare function memoryReadDocBlocks(excludeRealpath: string, name: string, opts: Omit<ContentAttachmentOptions, 'byName'> & {
78
- byName?: ReadonlyMap<string, MemoryDoc>;
79
- }): string[];
80
- /** Surface docs whose `command` entries match an executed bash command.
81
- * The corpus is the resolved cwd/profile set; a command has no file from which
82
- * to discover enclosing project stores. */
83
- export declare function renderOnCommandDocsForSubject(subject: NodeConfigSubject, command: string, target?: ExposureTarget, accounting?: DeliveryAccounting, memoryTarget?: MemoryTarget): string;
84
- /** Surface docs whose `pre-command` entries match a bash command that has NOT
85
- * run yet. The exact twin of the post-execution renderer above, and its empty
86
- * string is load-bearing: `''` means every matching doc is already exposed at
87
- * its matching rung or above, which is the release — the caller lets the
88
- * command through. */
89
- export declare function renderPreCommandDocsForSubject(subject: NodeConfigSubject, command: string, target?: ExposureTarget, accounting?: DeliveryAccounting, memoryTarget?: MemoryTarget): string;
90
- /** Whether this command matches a `command` surface before its node-config
91
- * gate is evaluated. A matching gate still requires a subject lookup. */
92
- export declare function corpusHasCommandSurfaceForCommand(command: string): boolean;
93
- /** Whether this command matches a `pre-command` surface before its node-config
94
- * gate is evaluated. A matching gate still requires a subject lookup. */
95
- export declare function corpusHasPreCommandSurfaceForCommand(command: string): boolean;
96
- /** Forget the transcript exposure of every `pre-command` doc, re-arming their
97
- * holds. Compaction drops delivered guidance out of the transcript while the
98
- * ledger still claims it was delivered, so without this pass a doc could be
99
- * held once and then silently absent for the rest of the session. Lives here
100
- * rather than in the extension because the corpus accessor is private. */
101
- export declare function demotePreCommandExposures(state: ContextExposureState, memoryTarget?: MemoryTarget): void;
@@ -1,9 +0,0 @@
1
- var P=Object.defineProperty;var i=(e,n)=>P(e,"name",{value:n,configurable:!0});import{sep as w}from"node:path";import{realpathOrSelf as E}from"../fs-utils.js";import{ambientMemoryTarget as j,listAllMemoryDocs as L,loadMemoryTargetView as S}from"../memory-resolver.js";import{commandEntryMatches as W,owningRootOf as O,preCommandEntryMatches as q}from"./surface-match.js";import{demoteDocumentTranscriptExposure as T,documentExposedAtOrAbove as H,emptyContextExposureState as I,exposedAtOrAbove as K,exposureTarget as V,registerDocumentExposure as z,registerExposure as G}from"./injected-store.js";import{planDelivery as C}from"./plan.js";import{parseSubstrateDoc as A,previewLine as J,rungRank as F}from"./schema.js";import{dirDedupKey as R,docListingDirs as Q,docsByName as $,isDirName as U,renderDirListing as X}from"./listings.js";import{cachedEventCorpusInclusive as Y}from"./session-cache.js";function g(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}i(g,"attr");function D(){try{return Y(L,A)}catch{return[]}}i(D,"resolvedDocs");function Z(e,n){if(n==="none")return null;let t=`kind="${g(e.kind)}" name="${g(e.name)}"`;if(n==="content"){const r=e.body.trim();if(r!=="")return`<memory ${t}>
2
- ${r}
3
- </memory>`}else if(n==="preview"){const r=J(e);r!==""&&(t+=` readWhen="${g(r)}"`)}return`<memory ${t} />`}i(Z,"renderDocEnvelope");function p(e){return e.docs.filter(n=>n.winner).map(n=>({doc:n.doc,rung:n.finalRung,source:n.source}))}i(p,"planWinners");function N(e){return $(e.docs.map(({source:n})=>n))}i(N,"planListingCorpus");function _(e,n){return`<memory-listing dir="${g(e)}">
4
- ${n.join(`
5
- `)}
6
- </memory-listing>`}i(_,"listingBlock");function fe(){return{deliveries:new Map}}i(fe,"deliveryAccounting");function B(e,n,t,r,o){if(e===void 0||t==="none")return;const c=E(n.path),a=e.deliveries.get(c);a!==void 0&&F(a.rung)>=F(t)||e.deliveries.set(c,{rung:t,...r===void 0?{}:{cause:r},...o===void 0?{}:{source:o}})}i(B,"accountDelivery");function ee(e,n){const{target:t,byName:r}=n,o=Q(r,e.name),c=o[0]===e.name,a=[];let s;for(const[h,u]of o.entries()){if(!U(r,u))continue;const m=c&&h===0;if(!m&&K(t.state,R(u),"preview"))continue;if(n.listings==="tree"){n.dirs?.push(u);continue}const l=m&&n.explicit===!0,d=X(r,u,t,!l,b=>B(n.accounting,b,"preview","directory listing attached to content delivery",b));d.length!==0&&(G(t,R(u),"preview"),l?s=d:a.push(_(u,d)))}return a.push(...re(E(e.path),e.name,{...n,deliveryCause:"memory-read companion of content delivery"})),{blocks:a,...s===void 0?{}:{listing:s}}}i(ee,"contentReadAttachments");function f(e,n){const{target:t}=n,r=[];for(const{doc:o,rung:c,source:a}of e){if(H(t.state,o.path,o.body,c))continue;const s=Z(o,c);s!==null&&(z(t,o,c),B(n.accounting,o,c,n.deliveryCause,a),c==="content"&&r.push(...ee(o,{...n,deliveryCause:"memory-read companion of content delivery"}).blocks),r.push(s))}return r}i(f,"renderWinnerBlocks");function k(e,n,t,r,o){return{subject:e,target:n,byName:N(t),listings:"blocks",accounting:r,memoryTarget:o}}i(k,"eventAttachmentOptions");function y(){return V(I(),"transcript")}i(y,"transientTranscriptTarget");function x(e){return e.length===0?"":`<auto-loaded-context>
7
- ${e.join(`
8
- `)}
9
- </auto-loaded-context>`}i(x,"renderAutoLoadedContext");function v(e,n,t,r){return r===void 0?C(e,j(),n,t,D()):C(e,r,n,t)}i(v,"eventPlan");function ne(e,n,t=y(),r,o){const c=v(e,"read",{absoluteFile:n},o);return f(p(c),k(c.subject,t,c,r,o))}i(ne,"renderOnReadDocBlocksForSubject");function ye(e,n,t=y(),r,o){return x(ne(e,n,t,r,o))}i(ye,"renderOnReadDocsForSubject");function he(e,n,t,r=y(),o,c){const a=c===void 0?{cwd:n,profileId:t,nodeId:null}:{...c,cwd:n,profileId:t,nodeId:null};let s,h;try{s=p(C(e,a,"workspace-open")),h=$(S(a,{quiet:!0}).docs)}catch{return""}return s.sort((u,m)=>{const l=O(u.doc)??"",d=O(m.doc)??"";return l.split(w).filter(Boolean).length-d.split(w).filter(Boolean).length||l.localeCompare(d)||u.doc.path.localeCompare(m.doc.path)}),x(f(s,{subject:e,target:r,byName:h,memoryTarget:a,listings:"blocks",accounting:o}))}i(he,"renderWorkspaceOpenDocsForSubject");function re(e,n,t){const r=v(t.subject,"memory-read",{resolvedCanonicalName:n,resolvedDocPath:e},t.memoryTarget);return f(p(r),{...t,byName:t.byName??N(r)})}i(re,"memoryReadDocBlocks");function ge(e,n,t=y(),r,o){const c=v(e,"command",{command:n},o);return x(f(p(c),k(e,t,c,r,o)))}i(ge,"renderOnCommandDocsForSubject");function xe(e,n,t=y(),r,o){const c=v(e,"pre-command",{command:n},o);return x(f(p(c),k(e,t,c,r,o)))}i(xe,"renderPreCommandDocsForSubject");function te(e){return e.surfaces.some(n=>n.on==="pre-command")}i(te,"carriesPreCommandEntry");function M(e,n){const t=n==="command"?W:q;return D().some(({doc:r})=>r.surfaces.some(o=>t(o,e)))}i(M,"hasCommandSurfaceForCommand");function ve(e){return M(e,"command")}i(ve,"corpusHasCommandSurfaceForCommand");function be(e){return M(e,"pre-command")}i(be,"corpusHasPreCommandSurfaceForCommand");function Ce(e,n){const t=n===void 0?D():S(n,{quiet:!0}).docs.map(r=>({doc:A(r)})).filter(r=>r.doc!==null);for(const{doc:r}of t)te(r)&&T(e,r.path,r.body)}i(Ce,"demotePreCommandExposures");export{B as accountDelivery,ee as contentReadAttachments,ve as corpusHasCommandSurfaceForCommand,be as corpusHasPreCommandSurfaceForCommand,fe as deliveryAccounting,Ce as demotePreCommandExposures,re as memoryReadDocBlocks,x as renderAutoLoadedContext,ge as renderOnCommandDocsForSubject,ne as renderOnReadDocBlocksForSubject,ye as renderOnReadDocsForSubject,xe as renderPreCommandDocsForSubject,he as renderWorkspaceOpenDocsForSubject};
@@ -1,94 +0,0 @@
1
- import { type MemoryDoc, type MemoryScope, type MemoryTarget } from '../memory-resolver.js';
2
- import { type DocKind, type Rung, type SubstrateDoc, type SurfaceEntry, type SurfaceEvent } from './schema.js';
3
- import type { EventCorpusDoc } from './session-cache.js';
4
- import type { NodeConfigSubject } from './subject-fields.js';
5
- /** What the event exposes to match against. Every field is optional: an event
6
- * invoked without its payload matches nothing rather than throwing. */
7
- export interface DeliveryPayload {
8
- /** `read`: the file that was read. Realpathed by the planner. */
9
- absoluteFile?: string;
10
- /** `read`: the read file's own frontmatter. Parsed from the file when omitted. */
11
- readFrontmatter?: Record<string, unknown>;
12
- /** `memory-read`: the exact canonical name the read resolved to. */
13
- resolvedCanonicalName?: string;
14
- /** `memory-read`: realpath of the resolved document, which never delivers to
15
- * itself. */
16
- resolvedDocPath?: string;
17
- /** `command` / `pre-command`: the command string. */
18
- command?: string;
19
- }
20
- /** A gate verdict with the reason a failure carries. */
21
- export type GateOutcome = {
22
- pass: true;
23
- } | {
24
- pass: false;
25
- reason: string;
26
- };
27
- /** One authored surface entry of this event and how it fared. `matched` folds
28
- * the entry's constraints AND its own gate; `gate` isolates the gate so a
29
- * reader can tell "did not fit" from "excluded by this node's config". */
30
- export interface EntryDecision {
31
- entry: SurfaceEntry;
32
- matched: boolean;
33
- gate: GateOutcome;
34
- }
35
- /** One document's delivery decision for one event. */
36
- export interface DeliveryRecord {
37
- /** Canonical name — the identity dedup resolves. */
38
- name: string;
39
- kind: DocKind;
40
- scope: MemoryScope;
41
- /** Absolute path to the document file. */
42
- storePath: string;
43
- /** From the node's own store, which is floored rather than capped at boot. */
44
- nodeLocal: boolean;
45
- /** Every entry the document authored for this event. */
46
- authoredEntries: EntryDecision[];
47
- /** The highest-rung entry that matched, or null when none did. */
48
- matchedEntry: SurfaceEntry | null;
49
- /** The matched entry's rung — what the author asked for, before the cap. */
50
- authoredRung: Rung;
51
- /** The profile relationship's cap on this document's store, or null when the
52
- * event is uncapped or the document is node-local. */
53
- projectMemoryCap: Rung | null;
54
- /** `minRung(authoredRung, projectMemoryCap)`. */
55
- cappedRung: Rung;
56
- docGate: GateOutcome;
57
- /** The matched entry's gate, or the verdict that excluded every authored
58
- * entry; null when the document authored no entry for this event. */
59
- entryGate: GateOutcome | null;
60
- /** What this document delivers at after gates, cap, and the boot node-local
61
- * floor. `none` = delivers nothing. */
62
- finalRung: Rung;
63
- /** This document is the one its canonical name resolves to for this event. */
64
- winner: boolean;
65
- /** The document that took this one's name, when it lost the dedup. */
66
- shadowedBy: {
67
- name: string;
68
- scope: MemoryScope;
69
- path: string;
70
- } | null;
71
- /** The parsed document — the renderers' input. */
72
- doc: SubstrateDoc;
73
- /** The resolver descriptor behind it: physical path, representation, and the
74
- * routing anchor a `./` memory-read glob matches against. */
75
- source: MemoryDoc;
76
- }
77
- /** Every document considered for one event, in corpus (precedence) order. */
78
- export interface DeliveryPlan {
79
- event: SurfaceEvent;
80
- subject: NodeConfigSubject | null;
81
- target: MemoryTarget;
82
- docs: DeliveryRecord[];
83
- }
84
- /** Which boot block a record belongs to. The node's own store is the catch-all
85
- * this-node store and rides into the knowledge block whatever its kind, so a
86
- * record's kind alone does not answer this. */
87
- export declare function bootPartitionOf(record: Pick<DeliveryRecord, 'kind' | 'nodeLocal'>): DocKind;
88
- /** Plan one event's delivery.
89
- *
90
- * `corpus` is the already-loaded document set. The live renderers pass their
91
- * session cache (the corpus is scanned and parsed once per session); an
92
- * inspection caller omits it and the planner loads the event's corpus from
93
- * `target`. Either way the planner writes nothing. */
94
- export declare function planDelivery(subject: NodeConfigSubject | null, target: MemoryTarget, event: SurfaceEvent, payload?: DeliveryPayload, corpus?: readonly EventCorpusDoc[]): DeliveryPlan;
@@ -1 +0,0 @@
1
- var b=Object.defineProperty;var c=(e,t)=>b(e,"name",{value:t,configurable:!0});import{homedir as k}from"node:os";import{dirname as F,parse as R,sep as D}from"node:path";import{parseFrontmatterGeneric as G}from"../frontmatter.js";import{readText as E,realpathOrSelf as l}from"../fs-utils.js";import{loadMemoryTargetView as S,loadStoreMemoryDocs as M,openProjectMemoryStore as x}from"../memory-resolver.js";import{userScopeRoot as C}from"../scope.js";import{gatePasses as O,surfaceEntryGatePasses as A}from"./gate.js";import{minRung as $,parseSubstrateDoc as y,rungAtLeast as P}from"./schema.js";import{matchingSurfaceEntry as L,surfaceEntryParticipates as N}from"./surface-match.js";function j(e){return e.nodeLocal?"knowledge":e.kind}c(j,"bootPartitionOf");function ae(e,t,o,n={},r){const s=q(o,n),a=J(o,r??K(t,o),s,t).map(({doc:u,source:i})=>U(u,i,e,o,s));return Q(o,a),{event:o,subject:e,target:t,docs:a}}c(ae,"planDelivery");function q(e,t){if(e!=="read"||t.absoluteFile===void 0)return{...t,readFrontmatter:t.readFrontmatter??{}};const o=l(t.absoluteFile);return{...t,absoluteFile:o,readFrontmatter:t.readFrontmatter??B(o)}}c(q,"resolvePayload");function B(e){if(!/\.(md|mdx|markdown)$/i.test(e))return{};try{return G(E(e)).data??{}}catch{return{}}}c(B,"readFileFrontmatter");function J(e,t,o,n){if(e==="read"){const r=o.absoluteFile;return r===void 0?[...t]:[...I(r,n),...t].filter(({doc:s})=>l(s.path)!==r)}if(e==="memory-read"&&o.resolvedDocPath!==void 0){const r=o.resolvedDocPath;return t.filter(({doc:s})=>l(s.path)!==r)}return[...t]}c(J,"considerFor");const T=new Set(["node_modules",".git","dist","build",".next",".cache",".yalc"]);function _(e){return e.split(D).some(t=>T.has(t))}c(_,"isJunkAncestor");function I(e,t){const o=[],n=new Set,r=l(k()),s=l(C()),m=R(e).root;let a=F(e);for(;;){if(a!==r&&a!==s&&!_(a)){const i=x(a);if(i.mountStatus==="ready"&&!n.has(i.storeRoot)&&t.allowsProject?.(i.repositoryRoot??i.ownerDir??i.storeRoot)!==!1&&t.allowsStore?.(i)!==!1){n.add(i.storeRoot);for(const f of M(i,!0)){if(t.allowsStore?.(i,f.name)===!1)continue;const p=y(f);p!==null&&o.push({doc:p,source:f})}}}if(a===r||a===m)break;const u=F(a);if(u===a)break;a=u}return o}c(I,"enclosingProjectDocs");function K(e,t){const o=t==="workspace-open"?S(e,{quiet:!0,scope:"project"}).docs:S(e,{quiet:!0}).docs,n=[];for(const r of o){const s=y(r);s!==null&&n.push({doc:s,source:r})}return t!=="boot"?n:[...n.filter(r=>r.doc.scope!=="node"),...n.filter(r=>r.doc.scope==="node")]}c(K,"loadEventCorpus");function U(e,t,o,n,r){const s={absoluteFile:r.absoluteFile,readFrontmatter:r.readFrontmatter,resolvedCanonicalName:r.resolvedCanonicalName,routingAnchor:t.routingAnchor,command:r.command},m=V(e,o),a=e.surfaces.filter(d=>d.on===n).map(d=>({entry:d,matched:N(d,e,o,n,s),gate:W(d,o)})),u=L(e,o,n,s),i=u?.at??"none",f=e.scope==="node",h=(n==="boot"||n==="workspace-open")&&!f?e.projectMemory:null,w=h===null?i:$(i,h);let g=m.pass?w:"none";return n==="boot"&&f&&m.pass&&!P(g,"name")&&!e.surfaces.some(d=>d.on==="boot")&&(g="name"),{name:e.name,kind:e.kind,scope:e.scope,storePath:e.path,nodeLocal:f,authoredEntries:a,matchedEntry:u,authoredRung:i,projectMemoryCap:h,cappedRung:w,docGate:m,entryGate:z(a,u),finalRung:g,winner:!1,shadowedBy:null,doc:e,source:t}}c(U,"decide");function V(e,t){if(e.gate===void 0)return{pass:!0};if(t===null)return{pass:!1,reason:"gated document with no node config to match"};try{return O(e,t)?{pass:!0}:{pass:!1,reason:"document gate does not match this node config"}}catch(o){return{pass:!1,reason:`document gate failed to evaluate: ${String(o)}`}}}c(V,"documentGateOutcome");function W(e,t){return e.gate===void 0?{pass:!0}:A(e,t)?{pass:!0}:{pass:!1,reason:"entry gate does not match this node config"}}c(W,"entryGateOutcome");function z(e,t){if(e.length===0)return null;if(t!==null)return{pass:!0};const o=e.find(n=>!n.gate.pass);return o===void 0?{pass:!0}:o.gate}c(z,"recordEntryGate");function H(e,t){return e.docGate.pass?t==="boot"?e.projectMemoryCap!=="none":P(e.finalRung,"name"):!1}c(H,"participates");function Q(e,t){const o=new Map;for(const n of t){if(!H(n,e))continue;const r=e==="boot"?`${j(n)}:${n.name}`:n.name,s=o.get(r);if(s===void 0){o.set(r,n),n.winner=!0;continue}n.shadowedBy={name:s.name,scope:s.scope,path:s.storePath}}}c(Q,"resolveWinners");export{j as bootPartitionOf,ae as planDelivery};
@@ -1,12 +0,0 @@
1
- import { type ExposureTarget } from './injected-store.js';
2
- /** The system-prompt substrate splice for `nodeId` — shipped-layer protocol
3
- * prose followed by the `<memory kind="preference">` block: assemble
4
- * the node's subject from the canvas-db, render the pure splice, then swap the
5
- * literal `$CRTR_CONTEXT_DIR` env-var token for the node's real absolute path
6
- * so agents don't paste it into the non-expanding Write tool (see
7
- * interpolateNodePaths). A null subject (unknown id) still renders the
8
- * always-present memory-usage guidance frame. */
9
- export declare function renderPreferencesSection(nodeId: string): string;
10
- /** The first-message `<memory kind="knowledge">` block for `nodeId`. Rendered
11
- * documents register at their displayed rung through `target`. */
12
- export declare function renderKnowledgeBlock(nodeId: string, target?: ExposureTarget): string;
@@ -1 +0,0 @@
1
- var m=Object.defineProperty;var t=(e,r)=>m(e,"name",{value:r,configurable:!0});import{appForNode as n,interpolateNodePaths as p}from"../canvas/node-agent-paths.js";import{getNode as u}from"../canvas/canvas.js";import{automaticMemoryTarget as i}from"../spaces/permissions.js";import{assembleNodeSubject as c}from"./subject.js";import{emptyContextExposureState as f,exposureTarget as s}from"./injected-store.js";import{renderPreferencesForSubject as a,renderKnowledgeForSubject as l}from"./render.js";function P(e){const r=c(e);return p(a(r).block,e)}t(P,"renderPreferencesSection");function d(e,r=s(f(),"transcript")){const o=c(e);return o===null?"":l(o,e,r,void 0,n(e),i({...u(e),grantee:n(e)}))}t(d,"renderKnowledgeBlock");export{d as renderKnowledgeBlock,P as renderPreferencesSection};
@@ -1,41 +0,0 @@
1
- import { type MemoryTarget } from '../memory-resolver.js';
2
- import { type ExposureTarget } from './injected-store.js';
3
- import { type SubstrateDoc } from './schema.js';
4
- import type { NodeConfigSubject } from './subject-fields.js';
5
- import { type DeliveryAccounting } from './on-read.js';
6
- /** The computed "sub-personas you may spawn" menu for a subject's kind — the
7
- * live restoration of the old `personas/resolve.ts` static menu, now derived
8
- * at render time from the merged kind registry (`subKindsAvailableTo`) so it
9
- * can never drift from `sys context prompt-review --list`'s `subPersonas` metadata.
10
- * Returns '' when the kind has zero available sub-kinds (no dangling empty
11
- * header). Emitted for BOTH base and orchestrator modes per the CTO's ruling —
12
- * mode is irrelevant to which sub-kinds are spawnable. */
13
- export declare function buildSubPersonaMenu(kind: string): string;
14
- export declare function renderPreferencesForSubject(subject: NodeConfigSubject | null, target?: ExposureTarget, accounting?: DeliveryAccounting, memoryTarget?: MemoryTarget): {
15
- block: string;
16
- contentDocs: SubstrateDoc[];
17
- tree: string;
18
- };
19
- /** The `<memory kind="knowledge">` block embedded in the session_start bearings
20
- * message (bearings.ts pushes it as a SIBLING of `<crtr-bearings>`, or drops it
21
- * when ''). The consultable catalog: every eligible `kind: knowledge` resolver
22
- * doc PLUS the node-local memory docs (any kind) — resolver docs win
23
- * first-wins dedup over a same-named node-local doc. GROUPED by rung exactly
24
- * like the preference block: content prose first (general→specific,
25
- * node-local last), then the preview/name catalog tree. A bootless node-local
26
- * doc arrives floored to `name`, so it surfaces as a bare-name tree entry
27
- * rather than collapsing into a `[+N more]` count (its body still never
28
- * renders: floored docs never reach the `content` rung). Procedural guidance and factual
29
- * references both live here as `knowledge`. Returns '' when nothing is
30
- * eligible. */
31
- export declare function renderKnowledgeForSubject(subject: NodeConfigSubject, nodeId: string, target?: ExposureTarget, accounting?: DeliveryAccounting, grantee?: string, memoryTarget?: MemoryTarget): string;
32
- /** What a node's configuration change newly exposes, rendered as up to three
33
- * blocks in one string: the shipped protocol prose, a `<memory kind="preference">`
34
- * block, and a `<memory kind="knowledge">` block — each dropped when empty, ''
35
- * when the change exposes nothing.
36
- *
37
- * Both kinds use the current subject's ordinary winner assembly, then compare
38
- * against the active exposure maximum. A lower rung or removal yields nothing
39
- * because content already loaded into this context cannot be withdrawn.
40
- * Rendered deltas register as transcript exposure through `target`. */
41
- export declare function renderConfigChangeDelta(subject: NodeConfigSubject, nodeId: string, target: ExposureTarget, grantee?: string, memoryTarget?: MemoryTarget): string;
@@ -1,65 +0,0 @@
1
- var J=Object.defineProperty;var l=(e,o)=>J(e,"name",{value:o,configurable:!0});import{sep as Q}from"node:path";import{interpolateNodePaths as M}from"../canvas/paths.js";import{ambientMemoryTarget as X,listAllMemoryDocs as Z,loadMemoryTargetView as N,resolveMemoryDoc as ee}from"../memory-resolver.js";import{buildMemoryTree as S}from"../memory/tree.js";import{subKindsAvailableTo as ne}from"../config.js";import{projectScopeRoots as te}from"../scope.js";import{documentExposedAtOrAbove as R,emptyContextExposureState as oe,exposureTarget as re,registerDocumentExposure as T,registerExposure as se}from"./injected-store.js";import{bootPartitionOf as ie,planDelivery as ce}from"./plan.js";import{parseSubstrateDoc as D,previewLine as ae,rungAtLeast as A,rungRank as _}from"./schema.js";import{accountDelivery as B,contentReadAttachments as ue}from"./on-read.js";import{dirDedupKey as le,docsByName as fe}from"./listings.js";import{cachedEventCorpusInclusive as de}from"./session-cache.js";function j(e,o,n){if(e===null)return[];let r;try{r=N({...n??{cwd:process.cwd(),profileId:null},nodeId:e,grantee:o},{scope:"node",quiet:!0}).docs}catch{return[]}const t=[];for(const s of r){const a=D(s);a!==null&&t.push({doc:a,source:s})}return t}l(j,"nodeStoreCorpus");function pe(e,o,n){let r;try{r=(n===void 0?de(Z,D):N({...n,nodeId:null},{quiet:!0}).docs.map(t=>({source:t,doc:D(t)})).filter(t=>t.doc!==null)).filter(t=>t.doc.scope!=="node")}catch{return j(e,o,n)}return[...r,...j(e,o,n)]}l(pe,"bootCorpus");function x(e,o,n,r){return ce(e,{...r??X(),nodeId:o,grantee:n},"boot",{},pe(o,n,r))}l(x,"bootPlan");function g(e,o){return e.docs.filter(n=>n.winner&&ie(n)===o).map(n=>({...n.doc,source:n.source,bootRung:n.finalRung}))}l(g,"bootWinners");function C(e){return O(e.bootRung)&&(e.bootRung!=="content"||e.body.trim()!=="")}l(C,"rendersAtBoot");function L(e){if(e.scope==="node")return 1e3;if(e.scope==="builtin")return 0;if(e.scope==="user")return 1;if(e.scope==="profile")return 2;const o=te();if(o.length===0)return 3;const n=o.findIndex(t=>e.path.startsWith(t+Q)),r=n===-1?0:n;return 3+(o.length-1-r)}l(L,"scopeGeneralityRank");function I(e){const o=e.source.physicalRelativePath.replace(/\.md$/i,"").split("/");return e.source.representation==="directory-index"&&o.pop(),o}l(I,"physicalSegments");function me(e,o){const n=I(e),r=I(o),t=Math.min(n.length,r.length);for(let s=0;s<t;s++){const a=n[s].localeCompare(r[s]);if(a!==0)return a}return n.length-r.length}l(me,"compareTreePosition");function k(e){return e.scope!=="builtin"&&e.plugin===void 0}l(k,"isAgentEditable");function he(e,o,n){if(o.length===0)return[];const r=new Map(e.map(a=>[a.path,a])),t=S(e.map(a=>a.source)),s=new Map;for(const a of o){const c=t.node(a);if(c===null)continue;let f=!1;const h=[...c.childDocuments.map(p=>p.document),...c.childDirectories.flatMap(p=>p.document===null?[]:[p.document])];for(const p of h){const d=r.get(p.path);d===void 0||s.has(d.path)||d.bootRung==="content"||A(d.bootRung,"preview")||d.unlisted||A(d.projectMemory,"preview")&&(R(n.state,d.path,d.body,"preview")||(s.set(d.path,{...d,bootRung:"preview"}),f=!0))}f&&se(n,le(a),"preview")}return[...s.values()]}l(he,"exposedDirEntries");function $(e,o,n,r,t=e,s,a){const c=r??re(oe(),"transcript"),f=[],h=[];for(const i of e)i.bootRung==="content"?f.push(i):h.push(i);f.sort((i,E)=>L(i)-L(E)||me(i,E)||i.name.localeCompare(E.name));const p=f.filter(i=>!R(c.state,i.path,i.body,"content")),d=p.map(i=>i.body.trim()).filter(i=>i!=="").join(`
2
-
3
- `);for(const i of p)C(i)&&(T(c,i,i.bootRung),B(s,i,i.bootRung,void 0,i.source));const y={subject:n??null,target:c,byName:fe(t.map(i=>i.source)),memoryTarget:a,listings:"tree",dirs:[],accounting:s},w=p.flatMap(i=>ue(i,y).blocks),m=he(t,y.dirs??[],c),u=new Map(m.map(i=>[i.path,i])),b=new Set(h.map(i=>i.path)),P=[...h.map(i=>u.get(i.path)??i),...m.filter(i=>!b.has(i.path))];for(const i of P)C(i)&&(T(c,i,i.bootRung),B(s,i,i.bootRung,u.has(i.path)?"directory listing attached to content delivery":void 0,i.source));return{contentProse:d,tree:ye(P,o),contentDocs:p,attachmentBlocks:w}}l($,"renderGrouped");function G(e){const o=e.lastIndexOf("/");return o===-1?e:e.slice(o+1)}l(G,"leafSegment");function O(e){return _(e)>=_("name")}l(O,"isVisible");function K(e,o){const n=e.childDirectories.map(c=>K(c,o)),r=[];let t=0;for(const c of e.childDocuments){const f=o.get(c.document.path);f!==void 0&&(O(f.bootRung)?r.push({name:c.name,order:c.order,doc:f}):t+=1)}const s=e.document===null?null:o.get(e.document.path)??null;let a=null;return s!==null&&(O(s.bootRung)?a=s:t+=1),{name:e.name,segment:G(e.name),order:e.order,own:a,children:n,leaves:r,hiddenHere:t,renders:!1,ownCount:0}}l(K,"planDir");function F(e,o){let n=e.hiddenHere;for(const s of e.children)n+=F(s,e.name==="");const r=e.own!==null||e.leaves.length>0,t=e.children.some(s=>s.renders);return e.renders=r||t||o||e.name==="",e.ownCount=e.renders?n:0,e.renders?0:n}l(F,"resolveDir");function W(e){return e.kind==="dir"?e.node.order:e.kind==="leaf"?e.entry.order:""}l(W,"itemOrder");function U(e){return e.kind==="dir"?e.node.name:e.kind==="leaf"?e.entry.name:""}l(U,"itemName");function Y(e,o,n,r){const t=e.bootRung==="preview"?ae(e):"";r.push(t===""?`${n}${o}`:`${n}${o} # read when: ${t}`)}l(Y,"renderDocEntry");function q(e,o,n){const r=[];for(const t of e.children)t.renders&&r.push({kind:"dir",node:t});for(const t of e.leaves)r.push({kind:"leaf",entry:t});r.sort((t,s)=>W(t).localeCompare(W(s))||U(t).localeCompare(U(s))),e.ownCount>0&&r.push({kind:"more",count:e.ownCount}),r.forEach((t,s)=>{const a=s===r.length-1,c=o+(a?"\u2514\u2500 ":"\u251C\u2500 "),f=o+(a?" ":"\u2502 ");switch(t.kind){case"more":n.push(`${c}[+${t.count} more]`);break;case"dir":{const h=`${t.node.segment}/`;t.node.own===null?n.push(`${c}${h}`):Y(t.node.own,h,c,n),q(t.node,f,n);break}case"leaf":Y(t.entry.doc,G(t.entry.name),c,n);break}})}l(q,"renderChildren");function ye(e,o){if(e.length===0)return"";const n=new Map;for(const s of e)n.has(s.path)||n.set(s.path,s);const r=K(S(e.map(s=>s.source)).root,n);F(r,!1);const t=[o];return q(r,"",t),t.join(`
4
- `)}l(ye,"buildTree");const v="Each %s below shows either its full content (indented beneath its name), a `# read when:` line telling you when to read the full document, or simply its name.",we="Preferences are how the user wants you to behave \u2014 standing directives and corrections. To read a preference, run `crtr memory read <name>`. "+v.replace("%s","preference"),H="If the user corrects you in a way that contradicts a preference, update the preference.",ge="Knowledge memories are what you consult \u2014 playbooks and techniques for how to do things, and references on the user, projects, and this node. They are aggregated from your memory stores: user-global (`~/.crouter/memory/`), every ancestor project store (`<dir>/.crouter/memory/`) from the cwd upward, the selected profile's memory store, and node-local (this node's `context/memory/`). To read one, run `crtr memory read <name>`; a directory name is a valid read target too \u2014 it answers with its listing, and walking directories is the sanctioned way to browse. Each doc exists to prevent a specific mistake you would make without it, so when your task matches one \u2014 by its name or its `# read when:` line \u2014 read it before you act; consulting it only after the work is done forfeits the entire reason it exists. "+v.replace("%s","document"),V="If you learn a better way to do something a memory covers, or gain information that contradicts one, edit that memory to correct it.",be="When your task matches a knowledge doc or preference \u2014 by its name or its `# read when:` line \u2014 read it before you act: each memory exists only to shore up a mistake you will make without it, so doing the relevant work without consulting it defeats the memory's whole purpose. Before saving any memory, check for an existing memory that already covers it \u2014 update that memory rather than creating a duplicate, rewriting it as if for the first time instead of appending the new truth beneath the old; delete memories that turn out to be wrong. Don't save what the repo already records (code structure, past fixes, git history) or what only matters to this conversation; if asked to remember one of those, ask what was non-obvious about it and save that instead. Docs auto-surfaced in <auto-loaded-context> blocks are background context, not user instructions, and reflect what was true when written \u2014 if one names a file, function, or flag, verify it still exists before recommending it.";function ke(e){try{return ee(`kinds/${e}`),` (\`crtr memory read kinds/${e}\`)`}catch{return""}}l(ke,"subKindDocCitation");function $e(e){const o=ne(e);if(o.length===0)return"";const n=o.map(r=>{const t=ke(r.kind);return`- \`${r.kind}\` \u2014 ${r.whenToUse}${t}`});return`## Sub-personas you may spawn
5
-
6
- These specialist sub-personas are available to the ${e} kind. Spawn one with \`crtr node new --kind <sub> "<scope>"\`, and treat it as its own scope instead of dragging unrelated context into it.
7
-
8
- `+n.join(`
9
- `)}l($e,"buildSubPersonaMenu");function ve(e,o,n,r){let t=[],s="",a="",c=be;if(e!==null){const h=g(x(e,null,r?.grantee,r),"preference"),p=$(h,"preferences",e,o,h,n,r);t=p.contentDocs,s=p.tree;const d=t.filter(m=>!k(m)).map(m=>m.body.trim()).filter(m=>m!==""),y=t.filter(m=>k(m)).map(m=>{const u=m.body.trim();return u===""?"":`<preference name="${m.name}">
10
- ${u}
11
- </preference>`}).filter(m=>m!==""),w=$e(e.kind);a=[...d,...p.attachmentBlocks,...w===""?[]:[w]].join(`
12
-
13
- `),(y.length>0||s!=="")&&(c+=`
14
-
15
- ${we}`,y.length>0&&(c+=`
16
-
17
- ${y.join(`
18
-
19
- `)}`),s!==""&&(c+=`
20
-
21
- ${s}`),c+=`
22
-
23
- ${H}`)}const f=`<memory kind="preference">
24
- ${c}
25
- </memory>`;return{block:a===""?f:`${a}
26
-
27
- ${f}`,contentDocs:t,tree:s}}l(ve,"buildPreferencesBlock");function Ie(e,o,n,r){return ve(e,o,n,r)}l(Ie,"renderPreferencesForSubject");function Ge(e,o,n,r,t,s){const a=g(x(e,o,t,s),"knowledge"),{contentProse:c,tree:f,attachmentBlocks:h}=$(a,"knowledge",e,n,a,r,s),p=[c,...h].filter(y=>y!=="").join(`
28
-
29
- `);if(p===""&&f==="")return"";let d=ge;return p!==""&&(d+=`
30
-
31
- ${p}`),f!==""&&(d+=`
32
-
33
- ${f}`),d+=`
34
-
35
- ${V}`,M(`<memory kind="knowledge">
36
- ${d}
37
- </memory>`,o,t)}l(Ge,"renderKnowledgeForSubject");const Ee="Your node configuration changed. This operating protocol is in force for you now:",Re="Your new configuration puts these preferences in force \u2014 standing directives and corrections from the user. To read one, run `crtr memory read <name>`. "+v.replace("%s","preference"),De="Your new configuration exposes these knowledge documents \u2014 consult them exactly like the rest of your catalog (`crtr memory read <name>`). "+v.replace("%s","document");function z(e,o){return o.filter(n=>C(n)&&!R(e.state,n.path,n.body,n.bootRung))}l(z,"undelivered");function Ke(e,o,n,r,t){const s=x(e,o,r,t),a=z(n,g(s,"preference")),{contentDocs:c,tree:f,attachmentBlocks:h}=$(a,"preferences",e,n,g(s,"preference"),void 0,t),p=c.filter(u=>!k(u)).map(u=>u.body.trim()).filter(u=>u!==""),d=c.filter(u=>k(u)).map(u=>{const b=u.body.trim();return b===""?"":`<preference name="${u.name}">
38
- ${b}
39
- </preference>`}).filter(u=>u!==""),y=[];if((p.length>0||h.length>0)&&y.push(`${Ee}
40
-
41
- ${[...p,...h].join(`
42
-
43
- `)}`),d.length>0||f!==""){let u=Re;d.length>0&&(u+=`
44
-
45
- ${d.join(`
46
-
47
- `)}`),f!==""&&(u+=`
48
-
49
- ${f}`),u+=`
50
-
51
- ${H}`,y.push(`<memory kind="preference">
52
- ${u}
53
- </memory>`)}const w=$(z(n,g(s,"knowledge")),"knowledge",e,n,g(s,"knowledge"),void 0,t),m=[w.contentProse,...w.attachmentBlocks].filter(u=>u!=="").join(`
54
-
55
- `);if(m!==""||w.tree!==""){let u=De;m!==""&&(u+=`
56
-
57
- ${m}`),w.tree!==""&&(u+=`
58
-
59
- ${w.tree}`),u+=`
60
-
61
- ${V}`,y.push(`<memory kind="knowledge">
62
- ${u}
63
- </memory>`)}return y.length===0?"":M(y.join(`
64
-
65
- `),o,r)}l(Ke,"renderConfigChangeDelta");export{$e as buildSubPersonaMenu,Ke as renderConfigChangeDelta,Ge as renderKnowledgeForSubject,Ie as renderPreferencesForSubject};
@@ -1,27 +0,0 @@
1
- import type { MemoryDoc } from '../memory-resolver.js';
2
- import type { SubstrateDoc } from './schema.js';
3
- type ListAllMemoryDocsFn = () => MemoryDoc[];
4
- type ParseSubstrateDocFn = (doc: MemoryDoc) => SubstrateDoc | null;
5
- /** A parsed substrate document with the resolver descriptor it came from. The
6
- * parsed doc carries canonical identity but not the physical form behind it,
7
- * so the descriptor is what supplies the routing anchor a `./` memory-read
8
- * glob matches against. */
9
- export interface EventCorpusDoc {
10
- doc: SubstrateDoc;
11
- source: MemoryDoc;
12
- }
13
- /** Called by canvas-doc-substrate.ts on every `session_start`.
14
- * Resets all cached values so the next access triggers a fresh scan. */
15
- export declare function clearSessionCache(): void;
16
- /** The FULL corpus (listAllMemoryDocs()), INCLUDING node scope, scanned at
17
- * most once per session. `listFn` is injected by the caller to avoid
18
- * circular imports at module init. This is the single filesystem walk the
19
- * whole module performs — every other entry derives from this result rather
20
- * than re-scanning. */
21
- export declare function cachedAllMemoryDocsInclusive(listFn: ListAllMemoryDocsFn): MemoryDoc[];
22
- /** allMemoryDocsInclusive parsed and paired with its descriptors, INCLUDING
23
- * node scope — the event corpus, and the module's only parse pass. */
24
- export declare function cachedEventCorpusInclusive(listFn: ListAllMemoryDocsFn, parseFn: ParseSubstrateDocFn): EventCorpusDoc[];
25
- /** The parsed docs of the inclusive event corpus, without their descriptors. */
26
- export declare function cachedSubstrateDocsInclusive(listFn: ListAllMemoryDocsFn, parseFn: ParseSubstrateDocFn): SubstrateDoc[];
27
- export {};
@@ -1 +0,0 @@
1
- var t=Object.defineProperty;var l=(s,c)=>t(s,"name",{value:c,configurable:!0});const e={allMemoryDocsInclusive:null,eventCorpusInclusive:null,substrateDocsInclusive:null};function a(){e.allMemoryDocsInclusive=null,e.eventCorpusInclusive=null,e.substrateDocsInclusive=null}l(a,"clearSessionCache");function r(s){return e.allMemoryDocsInclusive===null&&(e.allMemoryDocsInclusive=s()),e.allMemoryDocsInclusive}l(r,"cachedAllMemoryDocsInclusive");function i(s,c){if(e.eventCorpusInclusive===null){const n=[];for(const u of r(s)){const o=c(u);o!==null&&n.push({doc:o,source:u})}e.eventCorpusInclusive=n}return e.eventCorpusInclusive}l(i,"cachedEventCorpusInclusive");function I(s,c){return e.substrateDocsInclusive===null&&(e.substrateDocsInclusive=i(s,c).map(n=>n.doc)),e.substrateDocsInclusive}l(I,"cachedSubstrateDocsInclusive");export{r as cachedAllMemoryDocsInclusive,i as cachedEventCorpusInclusive,I as cachedSubstrateDocsInclusive,a as clearSessionCache};
@@ -1,73 +0,0 @@
1
- import { type Rung, type SubstrateDoc, type SurfaceEntry, type SurfaceEvent } from './schema.js';
2
- import type { NodeConfigSubject } from './subject-fields.js';
3
- /** The project directory owning a doc's store: the path segment stack above
4
- * the doc's `.crouter` dir. `null` when the doc's path carries no `.crouter`
5
- * segment (builtin docs). */
6
- export declare function owningRootOf(doc: Pick<SubstrateDoc, 'path'>): string | null;
7
- /** True when the (already-realpathed) file sits beneath the doc's store's
8
- * owning directory. Callers additionally guard on `doc.scope === 'project'`:
9
- * a profile store's path computes an owning root of `~`, and user/builtin/
10
- * node docs likewise have no project-owning dir, so a `./`-anchored glob
11
- * outside a project store must never match. */
12
- export declare function underOwningRoot(doc: Pick<SubstrateDoc, 'path'>, absFile: string): boolean;
13
- /** Does a `read` entry fit the read file? `absReadFile` must already be
14
- * realpathed. `readFrontmatter` is the read file's own parsed YAML (empty
15
- * for non-markdown files); an empty record never satisfies
16
- * `matchFrontmatter`. */
17
- export declare function matchesReadEntry(entry: SurfaceEntry, doc: Pick<SubstrateDoc, 'path' | 'scope'>, subject: NodeConfigSubject | null, absReadFile: string, readFrontmatter: Record<string, unknown>): boolean;
18
- /** Does a `memory-read` entry on a carrier anchored at `routingAnchor` fit a
19
- * resolved read of the doc known by its exact canonical `name`? */
20
- export declare function matchesMemoryReadEntry(entry: SurfaceEntry, routingAnchor: string, subject: NodeConfigSubject | null, name: string): boolean;
21
- /** Does a `command` entry's parsed command pattern fit, without evaluating its
22
- * node-config gate? Callers use this only to determine whether resolving a
23
- * subject could be necessary; delivery must still use `matchesCommandEntry`. */
24
- export declare function commandEntryMatches(entry: SurfaceEntry, command: string): boolean;
25
- /** Does a `command` entry fit the executed command string? */
26
- export declare function matchesCommandEntry(entry: SurfaceEntry, subject: NodeConfigSubject | null, command: string): boolean;
27
- /** Does a `pre-command` entry's parsed command pattern fit, without evaluating
28
- * its node-config gate? Callers use this only to determine whether resolving a
29
- * subject could be necessary; delivery must still use `matchesPreCommandEntry`. */
30
- export declare function preCommandEntryMatches(entry: SurfaceEntry, command: string): boolean;
31
- /** Does a `pre-command` entry fit a command that is ABOUT to run? The same
32
- * glob machinery `command` uses — one matcher, one semantics — applied to the
33
- * command with its heredoc bodies stripped. Subshell parentheses, backticks,
34
- * and path-prefixed binaries stay unhandled: this is a guardrail against the
35
- * faithful-but-uninformed action, not an enforcement boundary. */
36
- export declare function matchesPreCommandEntry(entry: SurfaceEntry, subject: NodeConfigSubject | null, command: string): boolean;
37
- /** What an event occurrence exposes for matching. A field the event does not
38
- * use is ignored; a field the event needs and lacks matches nothing. */
39
- export interface SurfaceMatchPayload {
40
- /** `read`: the read file, already realpathed. */
41
- absoluteFile?: string;
42
- /** `read`: the read file's own parsed YAML (empty for a non-markdown file). */
43
- readFrontmatter?: Record<string, unknown>;
44
- /** `memory-read`: the exact canonical name the read resolved to. */
45
- resolvedCanonicalName?: string;
46
- /** `memory-read`: the CARRIER's routing anchor, from its resolver descriptor
47
- * — not derivable from a canonical name, which cannot say whether the doc
48
- * fronts its own directory. */
49
- routingAnchor?: string;
50
- /** `command` / `pre-command`: the command string. */
51
- command?: string;
52
- }
53
- /** A doc as the matchers see it. `path`/`scope` are consulted only by `read`
54
- * (a `./`-anchored glob resolves against the store's owning repo dir). */
55
- type MatchDoc = Pick<SubstrateDoc, 'surfaces'> & Partial<Pick<SubstrateDoc, 'path' | 'scope'>>;
56
- /** Does ONE entry of `event` fit this occurrence — constraints and the entry's
57
- * own gate together? */
58
- export declare function surfaceEntryParticipates(entry: SurfaceEntry, doc: MatchDoc, subject: NodeConfigSubject | null, event: SurfaceEvent, payload: SurfaceMatchPayload): boolean;
59
- /** The entry that decides this doc's delivery for one event occurrence: the
60
- * highest-rung participating entry, or null when none participates. */
61
- export declare function matchingSurfaceEntry(doc: MatchDoc, subject: NodeConfigSubject | null, event: SurfaceEvent, payload: SurfaceMatchPayload): SurfaceEntry | null;
62
- /** The doc's delivery rung for a read of `absReadFile` (already realpathed). */
63
- export declare function readDeliveryRung(doc: Pick<SubstrateDoc, 'surfaces' | 'path' | 'scope'>, subject: NodeConfigSubject | null, absReadFile: string, readFrontmatter: Record<string, unknown>): Rung;
64
- /** The doc's workspace-open rung. */
65
- export declare function workspaceOpenRung(doc: Pick<SubstrateDoc, 'surfaces'>, subject: NodeConfigSubject | null): Rung;
66
- /** The doc's delivery rung for a `crtr memory read` that resolved a doc known
67
- * by its exact canonical `name` — no mount-stripped or other alias. */
68
- export declare function memoryReadDeliveryRung(doc: Pick<SubstrateDoc, 'surfaces'>, routingAnchor: string, subject: NodeConfigSubject | null, name: string): Rung;
69
- /** The doc's delivery rung for an executed command string. */
70
- export declare function commandDeliveryRung(doc: Pick<SubstrateDoc, 'surfaces'>, subject: NodeConfigSubject | null, command: string): Rung;
71
- /** The doc's delivery rung for a command about to run. */
72
- export declare function preCommandDeliveryRung(doc: Pick<SubstrateDoc, 'surfaces'>, subject: NodeConfigSubject | null, command: string): Rung;
73
- export {};
@@ -1 +0,0 @@
1
- var x=Object.defineProperty;var i=(e,t)=>x(e,"name",{value:t,configurable:!0});import{basename as M,isAbsolute as C,matchesGlob as v,relative as p,sep as l}from"node:path";import{commandSegments as G,stripHeredocs as O}from"../shell-segments.js";import{CRTR_DIR_NAME as $}from"../../types.js";import{realpathOrSelf as g}from"../fs-utils.js";import{evalCondition as D}from"../predicate.js";import{surfaceEntryGatePasses as c}from"./gate.js";import{rungRank as R}from"./schema.js";function E(e){const t=e.path.split(l),n=t.lastIndexOf($);return n<=0?null:t.slice(0,n).join(l)||l}i(E,"owningRootOf");function N(e,t){const n=E(e);if(n===null)return!1;const r=p(g(n),t);return r!==""&&!r.startsWith("..")&&!C(r)}i(N,"underOwningRoot");function a(e,t){try{return v(e,t)}catch{return!1}}i(a,"safeGlob");function P(e,t,n){if(e.startsWith("./")){if(t.scope!=="project"||!N(t,n))return!1;const r=E(t);return r===null?!1:a(p(g(r),n),e.slice(2))}return a(n,e)||a(M(n),e)}i(P,"readGlobMatches");function S(e,t,n,r,o){return e.on!=="read"||!c(e,n)||e.match!==void 0&&!e.match.some(s=>P(s,t,r))||e.matchFrontmatter!==void 0&&(Object.keys(o).length===0||!D(e.matchFrontmatter,o))?!1:e.match!==void 0||e.matchFrontmatter!==void 0}i(S,"matchesReadEntry");function W(e,t,n){if(e.startsWith("./")){const r=e.slice(2);return t===""?a(n,r):n.startsWith(t+"/")?a(n.slice(t.length+1),r):!1}return a(n,e)}i(W,"memoryReadGlobMatches");function k(e,t,n,r){return e.on!=="memory-read"||e.match===void 0||!c(e,n)?!1:e.match.some(o=>W(o,t,r))}i(k,"matchesMemoryReadEntry");function F(e){const t=e.trim().split(/\s+/);if(t.length===1&&t[0]==="")return null;const n=[];for(const r of t){const o=r.split("*");for(let s=0;s<o.length;s+=1)o[s]!==""&&n.push({kind:"literal",text:o[s]}),s<o.length-1&&n.push({kind:"any"})}return n}i(F,"commandGlobPattern");function b(e,t){const n=e.split("").map(r=>r==="?"?"[\\s\\S]":r.replace(/[.+^${}()|[\]\\]/g,"\\$&")).join("");return new RegExp(`^${n}$`).test(t)}i(b,"tokenMatches");function _(e,t){const n=new Map,r=i((o,s)=>{const h=`${o}:${s}`,d=n.get(h);if(d!==void 0)return d;let u;if(o===e.length)u=s===t.length;else if(e[o].kind==="any")u=r(o+1,s)||s<t.length&&r(o,s+1);else{const m=t[s];u=m!==void 0&&!m.opaque&&b(e[o].text,m.text)&&r(o+1,s+1)}return n.set(h,u),u},"match");return r(0,0)}i(_,"segmentMatches");function w(e,t){const n=F(e);return n===null?!1:G(t).filter(({tokens:r})=>r.length>0).some(({tokens:r})=>_(n,r))}i(w,"commandGlobMatches");function q(e,t){return e.on==="command"&&e.match!==void 0&&e.match.some(n=>w(n,t))}i(q,"commandEntryMatches");function A(e,t,n){return q(e,n)&&c(e,t)}i(A,"matchesCommandEntry");function H(e,t){return e.on!=="pre-command"||e.match===void 0?!1:e.match.some(n=>w(n,O(t)))}i(H,"preCommandEntryMatches");function T(e,t,n){return H(e,n)&&c(e,t)}i(T,"matchesPreCommandEntry");function j(e,t,n,r,o){if(e.on!==r)return!1;switch(r){case"boot":case"workspace-open":return c(e,n);case"read":return o.absoluteFile===void 0||t.path===void 0||t.scope===void 0?!1:S(e,{path:t.path,scope:t.scope},n,o.absoluteFile,o.readFrontmatter??{});case"memory-read":return o.resolvedCanonicalName===void 0?!1:k(e,o.routingAnchor??"",n,o.resolvedCanonicalName);case"command":return o.command!==void 0&&A(e,n,o.command);case"pre-command":return o.command!==void 0&&T(e,n,o.command)}}i(j,"surfaceEntryParticipates");function f(e,t,n,r){let o=null;for(const s of e.surfaces)j(s,e,t,n,r)&&(o===null||R(s.at)>R(o.at))&&(o=s);return o}i(f,"matchingSurfaceEntry");function X(e,t,n,r){return f(e,t,"read",{absoluteFile:n,readFrontmatter:r})?.at??"none"}i(X,"readDeliveryRung");function Y(e,t){return f(e,t,"workspace-open",{})?.at??"none"}i(Y,"workspaceOpenRung");function Z(e,t,n,r){return f(e,n,"memory-read",{routingAnchor:t,resolvedCanonicalName:r})?.at??"none"}i(Z,"memoryReadDeliveryRung");function y(e,t,n){return f(e,t,"command",{command:n})?.at??"none"}i(y,"commandDeliveryRung");function I(e,t,n){return f(e,t,"pre-command",{command:n})?.at??"none"}i(I,"preCommandDeliveryRung");export{y as commandDeliveryRung,q as commandEntryMatches,A as matchesCommandEntry,k as matchesMemoryReadEntry,T as matchesPreCommandEntry,S as matchesReadEntry,f as matchingSurfaceEntry,Z as memoryReadDeliveryRung,E as owningRootOf,I as preCommandDeliveryRung,H as preCommandEntryMatches,X as readDeliveryRung,j as surfaceEntryParticipates,N as underOwningRoot,Y as workspaceOpenRung};
@@ -1,5 +0,0 @@
1
- var Fe=Object.defineProperty;var m=(e,t)=>Fe(e,"name",{value:t,configurable:!0});import{createHash as We}from"node:crypto";import{getNode as Z,findNodeBySessionFile as Be}from"../../../core/canvas/canvas.js";import{interpolateNodePaths as ce}from"../../../core/canvas/paths.js";import{existsSync as Ge,readFileSync as ue,realpathSync as ze,statSync as Ue}from"node:fs";import{join as K,resolve as Ze}from"node:path";import{loadProfileManifest as Ke,resolveProfileOperand as He}from"../../../core/profiles/manifest.js";import{conversationStore as Ve,ConversationNotFoundError as Ye}from"../../../core/conversation-store/index.js";import{ApiError as l}from"../../../api/errors.js";import{paginate as H}from"../../../core/pagination.js";import{appSpace as V}from"../../../core/layout.js";import{memoryPermission as fe,readableProjectForScopes as Je}from"../../../core/spaces/permissions.js";import{canReadRun as Xe,resolvedScopes as Y}from"../router.js";import{CrtrError as J}from"../../../core/errors.js";import{memoryDir as Qe}from"../../../core/runtime/memory.js";import{NEUTRAL_PROJECT_MEMORY as xe,projectScopeRoot as X,projectScopeRootsWithMemory as et,scopeMemoryDir as pe,ensureProjectScopeRoot as tt}from"../../../core/scope.js";import{descendantStoreDiscoveryWarnings as ot}from"../../../core/nested-stores.js";import{profileMemoryDir as nt}from"../../../core/profiles/manifest.js";import{openProjectMemoryStore as Q}from"../../../core/memory-resolver.js";import{effectivePrivacy as x,PRIVACY_LEVELS as B}from"../../../core/substrate/schema.js";import{lintMemoryStore as he,lintMemoryTarget as rt,lintOrphans as it,resolvableCanonicalNames as st}from"../../../core/memory/lint.js";import{createMemoryDocSnapshot as ye,loadMemoryTargetView as ge,memoryStoresInPrecedence as ee}from"../../../core/memory-resolver.js";import{parseSubstrateDoc as we}from"../../../core/substrate/schema.js";import{parseFrontmatterGeneric as be}from"../../../core/frontmatter.js";import{dirDedupKey as at,docsByName as dt,renderDirListing as lt}from"../../../core/substrate/listings.js";import{memoryExtensionEffectiveCatalog as mt,memoryExtensionValidationCatalog as ct,projectEffectiveMemoryExtensions as ut}from"../../../core/memory/extensions.js";import{effectiveDocKind as ft}from"../../../core/substrate/schema.js";import{requireUnambiguousDoc as pt}from"../../../core/memory/mutation-domain.js";import{contentReadAttachments as ve}from"../../../core/substrate/on-read.js";import{assembleNodeSubject as _e}from"../../../core/substrate/subject.js";import{emptyContextExposureState as ht,exposureTarget as G,loadContextExposureState as te,registerDocumentExposure as Se,registerExposure as ke,saveContextExposureState as z}from"../../../core/substrate/injected-store.js";import{insertMemoryReads as yt}from"../../../core/canvas/memory-reads.js";import{emitEvent as gt}from"../../../core/events/emit.js";import{memoryEvents as oe}from"../../../core/substrate/memory-events.js";import{candidateLocation as qe,compareMemoryListKeys as wt,memoryListKey as bt,createDoc as je,deleteDoc as De,listDocs as vt,moveDoc as Re,readDoc as Ee,readHistory as _t,searchDocs as St,updateDoc as $e}from"../../../core/memory/service.js";import{MEMORY_SCOPES as Ie,isMemoryDocName as M}from"../../../api/dto/memory.js";import{invalidRequest as N,isRecord as E,objectBody as C,optionalString as I,requiredString as $}from"./validate.js";const P="read",q="rw",ne=100,Pe=100;function A(e){const t=e.params.name;if(t===void 0||!M(t))throw new l(400,"invalid_memory_doc_name","memory document name must be slash-joined [A-Za-z0-9_-] segments");return t}m(A,"requireName");function O(e){return Object.fromEntries(e.query.entries())}m(O,"queryObject");function F(e,t,o,i){return{scope:e,storeRoot:t,namespace:"",mountStatus:"ready",projectMemory:xe,ownerApp:o,profileId:i}}m(F,"nativeStore");function T(e,t){if(e.principal.class==="person")return!0;const o=e.principal.app;return process.platform!=="linux"&&o==="app:terminal"?!0:Je(t,o,Y(e.principal),e.principal.class==="broker"?e.principal.scopes:null)}m(T,"projectReadable");function v(e,t,o,i="read"){const s=[];for(const u of Object.keys(t))o.includes(u)||s.push({field:u,problem:"is not allowed",received:t[u]});const n=I(t,"node",s),r=I(t,"cwd",s),a=I(t,"profile",s),d=I(t,"store",s),f=I(t,"dir",s),c=I(t,"select_profile",s);if(f!==void 0&&(d!==void 0||c!==void 0)&&s.push({field:"dir",problem:"selects the project store itself and cannot combine with store or select_profile"}),c!==void 0&&d!=="profile"&&s.push({field:"select_profile",problem:"requires store profile"}),d!==void 0&&!Ie.includes(d)&&!/^app:[A-Za-z0-9_-]{1,64}$/.test(d)&&s.push({field:"store",problem:`must be one of ${Ie.join(", ")} or app:<id>`,received:d}),e.principal.class==="app"&&(n!==void 0||r!==void 0||a!==void 0||f!==void 0||c!==void 0||t.mode==="cli"))throw new l(403,"scope_missing","an app server cannot select a node, cwd or profile");if(e.principal.class==="broker"&&(n!==void 0&&n!==e.principal.node||r!==void 0||a!==void 0||f!==void 0||c!==void 0))throw new l(403,"scope_missing","a broker can select only its own node and mounted memory");n!==void 0&&a!==void 0&&s.push({field:"node",problem:"derives profile and cannot be combined with it"}),s.length>0&&N("memory scope",s);let g,k;if(n!==void 0){const u=Z(n);if(u===null)throw new l(404,"node_not_found",`unknown node: ${n}`);g={cwd:r??u.cwd,profileId:u.profile_id??null,nodeId:u.node_id,grantee:u.grantee},k=u.node_id}else g={cwd:r??(e.principal.class==="broker"?Z(e.principal.node)?.cwd??"/":e.principal.class==="app"?V(e.principal.app).files:"/"),profileId:a??(e.principal.class==="broker"?Z(e.principal.node)?.profile_id??null:null),nodeId:e.principal.class==="broker"?e.principal.node:null,grantee:e.principal.class==="person"?void 0:e.principal.app},e.principal.class==="broker"&&(k=e.principal.node);const b=d;if(b==="node"&&k===void 0)throw new l(400,"invalid_request","store node requires node");if(b==="profile"&&g.profileId===null&&c===void 0)throw new l(400,"invalid_request","store profile requires profile or node with a profile");if(c!==void 0&&(g={...g,profileId:He(c).profileId}),f!==void 0){const u=Ze(g.cwd,f);if(!Ge(u)||!Ue(u).isDirectory())throw new l(400,"invalid_request",`--dir does not exist or is not a directory: ${f}`);const R=Q(ze(u));if(!T(e,R.repositoryRoot??R.ownerDir??u))throw new l(403,"scope_missing","project memory is outside the run mounts");return g={...g,allowsStore:m((y,me)=>y.scope==="project"&&T(e,y.repositoryRoot??y.ownerDir??y.storeRoot),"allowsStore"),allowsProject:m(y=>T(e,y),"allowsProject")},{target:g,nodeId:k,store:R,access:i,permitted:m(y=>y.scope==="project"&&T(e,y.repositoryRoot??y.ownerDir??y.storeRoot),"permitted")}}const h=e.principal,w=h.class==="person"?[]:Y(h),p=h.class==="broker"?h.scopes:null,S=h.class==="person"?null:h.app,D=m((u,R)=>h.class==="person"?!0:u.scope==="project"?T(e,u.repositoryRoot??u.ownerDir??u.storeRoot):fe(S,w,p,u,i,R),"permitted");if(g={...g,allowsStore:D,allowsProject:m(u=>T(e,u),"allowsProject")},d?.startsWith("app:")||h.class==="app"&&d===void 0){const u=d??(h.class==="person"?"app:terminal":h.app),R=F("profile",V(u).memory,u);if(!D(R))throw new l(403,"scope_missing",`missing memory permission for ${u}`);return{target:g,nodeId:k,store:R,access:i,permitted:D}}if(b!==void 0&&h.class!=="person"){const u=ee({...g,allowsStore:void 0,allowsProject:void 0},b);if(u.length===0||!u.some(R=>D(R)))throw new l(403,"scope_missing",`missing memory permission for ${b}`)}return{target:g,...b===void 0?{}:{scope:b},...k===void 0?{}:{nodeId:k},access:i,permitted:D}}m(v,"resolveScope");function _(e,t){if(e.access!==t)throw new Error("memory route access mismatch");if(e.store!==void 0&&!e.permitted(e.store))throw new l(403,"scope_missing","memory store is not permitted")}m(_,"requireScope");function U(e,t,o){if(!e.permitted(t,o))throw new l(403,"scope_missing",`missing memory write permission for ${o}`)}m(U,"requireWrite");function j(e,t){const o=e.scope;if(!t)return{...o===void 0?{}:{scope:o},...e.store===void 0?{}:{store:e.store}};if(e.store!==void 0)return{scope:e.store.scope,store:e.store,memoryDir:e.store.storeRoot};const i=o??(e.target.nodeId?"node":X(e.target.cwd)!==null?"project":"user");if(i==="builtin")throw new l(400,"invalid_request","builtin memory is read-only");if(i==="node"){const r=Qe(e.target.nodeId,e.target.grantee),a=F("node",r,e.target.grantee);if(!e.permitted(a))throw new l(403,"scope_missing","node memory is not permitted");return{scope:i,store:a,memoryDir:r}}if(i==="profile"){const{profileId:r,manifest:a}=Ke(e.target.profileId),d=a.grantee?.startsWith("app:")?K(V(a.grantee).memory,"profiles",r):nt(r),f=F("profile",d,a.grantee,r);if(!e.permitted(f))throw new l(403,"scope_missing","profile memory is not permitted");return{scope:i,store:f,memoryDir:d}}if(i==="project"){const r=o==="project"?tt(e.target.cwd):X(e.target.cwd);if(r===null)throw new l(400,"invalid_request","store project requires a project memory store in cwd");const a=Q(r.slice(0,-8).replace(/\/$/,""));if(!e.permitted(a))throw new l(403,"scope_missing","project memory is outside the run mounts");return{scope:i,store:a,memoryDir:a.storeRoot}}const s=pe("user");if(s===null)throw new Error("user memory directory unavailable");const n=F("user",s);if(!e.permitted(n))throw new l(403,"scope_missing","user memory is not permitted");return{scope:"user",store:n,memoryDir:s}}m(j,"selection");function Ae(e,t){return e.length>1?e.map(o=>qe(o,t)):void 0}m(Ae,"candidates");function Te(e){return{name:e.name,short_form:e.shortForm,kind:e.kind,privacy:e.privacy,scope:e.scope,extensions:e.extensions,path:e.path,store_root:e.storeRoot,physical_relative_path:e.physicalRelativePath,...Ae(e.candidates,e.candidates[0])===void 0?{}:{candidates:Ae(e.candidates,e.candidates[0])}}}m(Te,"summary");function re(e){try{const t=Ee(e);if(t.kind==="document")return t}catch(t){if(!(t instanceof J)||t.code!=="not_found")throw t}throw new l(404,"memory_document_not_found",`memory document not found: ${e.name}`)}m(re,"requestedDocument");function ie(e,t,o=j(t,!1),i=!1){const s=re({target:t.target,...o,name:e,frontmatter:i,interpolateNodePaths:!1}),n=s.doc;return{...Te({name:n.name,kind:String(n.frontmatter?.kind??""),privacy:x(n.frontmatter),scope:n.scope,path:n.path,storeRoot:n.root,physicalRelativePath:n.physicalRelativePath,shortForm:String(n.frontmatter?.["short-form"]??""),slash:n.frontmatter?.slash===!0,extensions:n.frontmatter?.extensions??{},candidates:s.candidates}),body:s.content,frontmatter:n.frontmatter===null?null:{...n.frontmatter,privacy:x(n.frontmatter)},representation:n.representation,links:[...s.links]}}m(ie,"document");function se(e,t,o){if(e===void 0)return o;const i=typeof e=="number"?e:Number(e);if(!Number.isInteger(i)||i<1||i>Pe)throw new l(400,"invalid_request",`${t} must be an integer from 1 through ${Pe}`);return i}m(se,"number");function ae(e,t,o){if(e===void 0)return t;const i=typeof e=="number"||typeof e=="string"&&e.trim()!==""?Number(e):NaN;if(!Number.isInteger(i)||i<1||o!==void 0&&i>o)throw new l(400,"invalid_request",`limit must be ${o===void 0?"a positive integer":`an integer from 1 through ${o}`}`);return i}m(ae,"cliLimit");function Oe(e,t){const o=typeof e=="number"?e:Number(e);if(!Number.isFinite(o)||o<1)throw new l(400,"invalid_request",`${t} must be a finite number of at least 1`);return o}m(Oe,"positiveNumber");function W(e,t){const o=e[t];if(o!==void 0){if(o===!0||o==="true")return!0;if(o===!1||o==="false")return!1;throw new l(400,"invalid_request",`${t} must be a boolean`)}}m(W,"optionalBoolean");function Ne(e,t,o=[]){if(e!==void 0&&!E(e))throw new l(400,"invalid_request","frontmatter must be an object");const i=e===void 0?{}:e;for(const r of o)if(r in i)throw new l(400,"invalid_request",`frontmatter.${r} cannot be set directly`);const s={},n={"short-form":"shortForm","when-and-why-to-read":"whenAndWhyToRead","lint-ignore":"lintIgnore",rationale:"docRationale",kind:"kind",privacy:"privacy",unlisted:"unlisted",surfaces:"surface",gate:"gate",slash:"slash"};for(const[r,a]of Object.entries(i)){const d=n[r];if(d===void 0)throw new l(400,"invalid_request",`frontmatter.${r} is not writable through this route`);if(r==="privacy"){if(!B.includes(a))throw new l(400,"invalid_request",`frontmatter.privacy must be one of ${B.join(", ")}`)}else if(r==="unlisted"||r==="slash"){if(a!==!0)throw new l(400,"invalid_request",`frontmatter.${r} must be true; remove it with unset`)}else if(r==="surfaces"){if(!Array.isArray(a)||!a.every(f=>typeof f=="string"))throw new l(400,"invalid_request","frontmatter.surfaces must be a string array")}else if(r==="lint-ignore"){if(!Array.isArray(a)||!a.every(f=>typeof f=="string"))throw new l(400,"invalid_request","frontmatter.lint-ignore must be a string array")}else if(typeof a!="string"||a.trim()==="")throw new l(400,"invalid_request",`frontmatter.${r} must be a non-empty string`);s[d]=a}if(t!==void 0){if(!E(t))throw new l(400,"invalid_request","extensions must be an object");const r=[];for(const[a,d]of Object.entries(t)){if(!E(d))throw new l(400,"invalid_request",`extensions.${a} must be an object`);for(const[f,c]of Object.entries(d))r.push(`extensions.${a}.${f}=${String(c)}`)}s.extension=r}return s}m(Ne,"frontmatterFields");function de(e,t){if(t.nodeId!==void 0&&e.principal.class!=="app"){if(e.principal.class==="broker"&&e.principal.node!==t.nodeId)throw new l(403,"other_app_run","memory exposure can only be recorded for the calling node");return t.nodeId}}m(de,"ledgerNode");function Ce(e,t,o,i){const s=de(e,t);if(s===void 0||i.length===0)return;const n=te(s),r=We("sha256").update(JSON.stringify(i)).digest("hex");ke(G(n,"transcript"),`listing:memory-${o}:${r}`,"content"),z(s,n)}m(Ce,"listingExposure");function Me(e,t){if(t.length!==0)try{yt(e,t)}catch(o){gt({level:"warn",event:"memory_reads.insert_failed",error:o,fields:{node_id:e}})}}m(Me,"recordMemoryReads");function kt(e){const t=O(e),o=[],i=I(t,"kind",o),s=I(t,"after",o);o.length>0&&N("memory list query",o);const n=v(e,t,["node","cwd","profile","store","dir","select_profile","mode","kind","limit","cursor","after"]);_(n,P);const r=vt({target:n.target,...j(n,!1),...i===void 0?{}:{kind:i}});if(t.mode==="cli"){const c=H(r,{limit:ae(t.limit,50,200),cursor:t.cursor},{defaultLimit:50,maxLimit:200,keyOf:bt,compareKeys:wt,total:"count"});return Ce(e,n,"list",c.items),{status:200,body:c}}r.sort((c,g)=>c.name.localeCompare(g.name));const a=s===void 0?r:r.filter(c=>c.name.localeCompare(s)>0),d=a.slice(0,se(t.limit,"limit",ne)).map(Te);return{status:200,body:{object:"list",data:d,has_more:a.length>d.length}}}m(kt,"handleList");function qt(e){const t=O(e);if(t.mode==="cli"){const i=v(e,t,["node","cwd","profile","store","dir","mode","kind","frontmatter"]);_(i,P);const s=A(e),n=Ee({target:i.target,...j(i,!1),name:s,...t.kind===void 0?{}:{kind:String(t.kind)},frontmatter:W(t,"frontmatter")===!0}),r=de(e,i),a=r===void 0?ht():te(r),d=[],f=G(a,"transcript",d);if(n.kind==="directory"){const u=lt(n.listingByName,n.name,r===void 0?null:f,!1);return r!==void 0&&(ke(f,at(n.name),"preview"),z(r,a)),{status:200,body:{name:n.name,listing:u,follow_up:"Each line is readable with `crtr memory read <name>` \u2014 a `[[name]]: <line>` entry is a doc, a bare `[[name]]` is a subdirectory whose read browses deeper. Browse the whole inventory with `crtr memory list`."}}}const{doc:c,candidates:g,content:k,links:b,listingByName:h}=n;Se(G(a,"transcript"),c,"content");const w=ve(c,{subject:i.nodeId===void 0?null:_e(i.nodeId),target:f,byName:h,memoryTarget:i.target,listings:"blocks",explicit:!0});if(r!==void 0){z(r,a);const u=new Date().toISOString();Me(r,[...oe([{name:c.name,scope:c.scope}],"read",u),...oe(d,"loaded",u)])}const p=w.listing,S=p!==void 0&&p.length>0,D=S?b.length>0?"Each `[[name]]` line in `listing` is one of this directory\u2019s immediate members, and the `[[name]]` links in the body are further reading \u2014 follow either with `crtr memory read <name>` only when the task needs that depth.":"Each `[[name]]` line in `listing` is one of this directory\u2019s immediate members, readable with `crtr memory read <name>` \u2014 follow one only when the task needs that depth.":b.length>0?"The `[[name]]` links in the body are further reading \u2014 follow one with `crtr memory read <name>` only when the task needs that depth.":null;return{status:200,body:{name:c.name,local_name:c.localName,kind:ft(c),privacy:x(c.frontmatter),scope:c.scope,path:c.path,store_root:c.root,physical_relative_path:c.physicalRelativePath,representation:c.representation,...g.length>1?{candidates:g.map(u=>qe(u,c))}:{},content:k,attachment_blocks:w.blocks,...S?{listing:p}:{},extensions:ut(c.frontmatter?.extensions,mt(c)),...b.length>0?{links:b}:{},...D===null?{}:{follow_up:D}}}}const o=v(e,t,["node","cwd","profile","store","frontmatter"]);return _(o,P),{status:200,body:ie(A(e),o,j(o,!1),W(t,"frontmatter")===!0)}}m(qt,"handleRetrieve");function jt(e){if(E(e.body)&&e.body.mode==="cli"){const{mode:k,...b}=e.body,h=v(e,e.body,["node","cwd","profile","store","dir","select_profile","fields","mode"],q);_(h,q);const w=[],p=C(b.fields,["name","kind","whenAndWhyToRead","body","privacy","shortForm","unlisted","surface","gate","lintIgnore","slash","rationale","extension"],w),S=$(p,"name",w),D=$(p,"kind",w);$(p,"whenAndWhyToRead",w),$(p,"body",w),D!==void 0&&D!=="knowledge"&&D!=="preference"&&w.push({field:"kind",problem:"must be knowledge or preference",received:D});for(const y of["privacy","shortForm","gate","rationale"])p[y]!==void 0&&(typeof p[y]!="string"||p[y].trim()==="")&&w.push({field:y,problem:"must be a non-empty string",received:p[y]});p.privacy!==void 0&&!B.includes(p.privacy)&&w.push({field:"privacy",problem:`must be one of ${B.join(", ")}`,received:p.privacy});for(const y of["unlisted","slash"])p[y]!==void 0&&typeof p[y]!="boolean"&&w.push({field:y,problem:"must be a boolean",received:p[y]});for(const y of["surface","extension"])p[y]!==void 0&&(!Array.isArray(p[y])||!p[y].every(me=>typeof me=="string"))&&w.push({field:y,problem:"must be a string array",received:p[y]});if(p.lintIgnore!==void 0&&typeof p.lintIgnore!="string"&&(!Array.isArray(p.lintIgnore)||!p.lintIgnore.every(y=>typeof y=="string"))&&w.push({field:"lintIgnore",problem:"must be a string or string array",received:p.lintIgnore}),w.length>0&&N("memory create request",w),!M(S))throw new l(400,"invalid_memory_doc_name","memory document name must be slash-joined [A-Za-z0-9_-] segments");const u=j(h,!0);U(h,u.store,S);const R={created:new Date().toISOString(),cwd:h.target.cwd,...h.target.nodeId===null?{}:{node:h.target.nodeId}};return{status:200,body:je({target:h.target,scope:u.scope,store:u.store,memoryDir:u.memoryDir,isExplicitProjectStore:b.dir!==void 0||b.store==="project",origin:R,fields:p})}}const t=[],o=C(e.body,["name","kind","when_and_why_to_read","body","frontmatter","extensions","node","cwd","profile","store"],t),i=$(o,"name",t),s=$(o,"kind",t),n=$(o,"when_and_why_to_read",t),r=$(o,"body",t);if(t.length>0&&N("memory create request",t),!M(i))throw new l(400,"invalid_memory_doc_name","memory document name must be slash-joined [A-Za-z0-9_-] segments");const a=v(e,o,["name","kind","when_and_why_to_read","body","frontmatter","extensions","node","cwd","profile","store"],q);_(a,q);const d=j(a,!0);U(a,d.store,i);const f={name:i,kind:s,whenAndWhyToRead:n,body:r,...Ne(o.frontmatter,o.extensions,["kind","when-and-why-to-read","origin","last-updated"])},c=je({target:a.target,scope:d.scope,memoryDir:d.memoryDir,store:d.store,isExplicitProjectStore:!1,origin:{created:new Date().toISOString(),cwd:a.target.cwd,...a.target.nodeId===null?{}:{node:a.target.nodeId}},fields:f}),g=ie(c.name,a,d);return{status:200,body:c.findings===void 0?g:{...g,findings:c.findings}}}m(jt,"handleCreate");function Dt(e){if(E(e.body)&&e.body.mode==="cli"){const{mode:a,...d}=e.body,f=v(e,e.body,["node","cwd","profile","store","dir","select_profile","fields","mode"],q);if(_(f,q),!E(d.fields))throw new l(400,"invalid_request","fields must be an object");return{status:200,body:$e({target:f.target,selection:{target:f.target,...j(f,!1)},fields:{...d.fields,name:A(e)}})}}const t=[],o=C(e.body,["rationale","body","frontmatter","extensions","unset","node","cwd","profile","store"],t),i=$(o,"rationale",t);o.body!==void 0&&typeof o.body!="string"&&t.push({field:"body",problem:"must be a string",received:o.body}),o.unset!==void 0&&(!Array.isArray(o.unset)||!o.unset.every(a=>typeof a=="string"))&&t.push({field:"unset",problem:"must be a string array",received:o.unset}),t.length>0&&N("memory update request",t);const s=A(e),n=v(e,o,["rationale","body","frontmatter","extensions","unset","node","cwd","profile","store"],q);_(n,q);const r=Ne(o.frontmatter,o.extensions,["kind","when-and-why-to-read","origin","last-updated"]);return $e({target:n.target,selection:{target:n.target,...j(n,!1)},fields:{name:s,rationale:i,...o.body===void 0?{}:{body:o.body},...o.unset===void 0?{}:{unset:o.unset},...r}}),{status:200,body:ie(s,n)}}m(Dt,"handleUpdate");function Rt(e){if(E(e.body)&&e.body.mode==="cli"){const{mode:s,...n}=e.body,r=v(e,e.body,["node","cwd","profile","store","dir","fields","mode"],q);return _(r,q),{status:200,body:De({target:r.target,selection:{target:r.target,...j(r,!1)},fields:{name:A(e)}})}}const t=v(e,O(e),["node","cwd","profile","store"],q);_(t,q);const o=A(e);return{status:200,body:{...De({target:t.target,selection:{target:t.target,...j(t,!1)},fields:{name:o}}),deleted:!0}}}m(Rt,"handleDelete");function Et(e){if(E(e.body)&&e.body.mode==="cli"){const{mode:a,...d}=e.body,f=v(e,e.body,["node","cwd","profile","store","dir","fields","mode"],q);if(_(f,q),!E(d.fields))throw new l(400,"invalid_request","fields must be an object");if(typeof d.fields.to!="string"||!M(d.fields.to))throw new l(400,"invalid_memory_doc_name","move destination must be a memory document name");return Le(f,A(e),d.fields.to),{status:200,body:Re({target:f.target,selection:{target:f.target,...j(f,!1)},fields:{...d.fields,name:A(e)}})}}const t=[],o=C(e.body,["to","node","cwd","profile","store"],t),i=$(o,"to",t);if(t.length>0&&N("memory move request",t),!M(i))throw new l(400,"invalid_memory_doc_name","memory document name must be slash-joined [A-Za-z0-9_-] segments");const s=v(e,o,["to","node","cwd","profile","store"],q);_(s,q);const n=A(e);return Le(s,n,i),{status:200,body:Re({target:s.target,selection:{target:s.target,...j(s,!1)},fields:{name:n,to:i}})}}m(Et,"handleMove");function Le(e,t,o){const i=re({target:e.target,...j(e,!1),name:t}).doc;U(e,i.store,t),U(e,i.store,o)}m(Le,"requireMoveDestination");function le(e){return"line"in e?`${e.name}\0${e.scope}\0${e.physical_relative_path}\0${String(e.line).padStart(10,"0")}`:e.name}m(le,"grepCursor");function $t(e){const t=[],o=C(e.body,["query","kind","grep","body","limit","cursor","after","min_score","node","cwd","profile","store","dir","mode"],t),i=$(o,"query",t),s=I(o,"kind",t),n=I(o,"after",t);t.length>0&&N("memory search request",t);const r=v(e,o,["query","kind","grep","body","limit","cursor","after","min_score","node","cwd","profile","store","dir","mode"]);_(r,P);const a=W(o,"grep"),d=W(o,"body"),f=o.min_score===void 0?void 0:Oe(o.min_score,"min_score");if(a===!0&&d===!0)throw new l(400,"invalid_request","grep and body cannot both be true");if(a===!0&&f!==void 0)throw new l(400,"invalid_request","min_score is only available in ranked mode");const c=St({target:r.target,...j(r,!1),query:i,...s===void 0?{}:{kind:s},...a===void 0?{}:{grep:a},...d===void 0?{}:{body:d},...f===void 0?{}:{minScore:f}});if(o.mode==="cli"){const h=ae(o.limit,10,100),w=o.cursor,p=c.mode==="grep"?H([...c.hits],{limit:h,cursor:w},{defaultLimit:10,maxLimit:100,keyOf:m(S=>`${S.name}:${S.scope}:${S.physical_relative_path}:${String(S.line).padStart(7,"0")}`,"keyOf"),total:"omit"}):H([...c.hits],{limit:h,cursor:w},{defaultLimit:10,maxLimit:100,keyOf:m(S=>`${String(1e6-S.score).padStart(7,"0")}:${S.scope}:${S.name}:${S.physical_relative_path}`,"keyOf"),total:"omit"});return Ce(e,r,"find",p.items),{status:200,body:{mode:c.mode,matches:c.matches,hits:p.items,next_cursor:p.next_cursor}}}const g=[...c.hits].sort((h,w)=>a===!0?le(h).localeCompare(le(w)):h.name.localeCompare(w.name)),k=n===void 0?g:g.filter(h=>(a===!0?le(h):h.name).localeCompare(n)>0),b=k.slice(0,se(o.limit,"limit",ne));return{status:200,body:{object:"list",data:b,has_more:k.length>b.length}}}m($t,"handleSearch");function It(e){const t=O(e),o=v(e,t,["node","cwd","profile","store","dir","select_profile","mode","limit","revision","diff"]);_(o,P);const i=t.revision===void 0?void 0:Oe(t.revision,"revision"),s=W(t,"diff"),n=_t({target:o.target,...j(o,!1),name:A(e),limit:t.mode==="cli"?ae(t.limit,10):se(t.limit,"limit",ne),...i===void 0?{}:{revision:i},...s===void 0?{}:{diff:s}});return t.mode==="cli"?{status:200,body:n}:{status:200,body:{name:n.name,scope:n.scope,log_path:n.logPath,total:n.total,...n.deleted===void 0?{}:{deleted:n.deleted},..."record"in n?{record:n.record}:{revisions:[...n.revisions]}}}}m(It,"handleHistory");function Pt(e){const t=O(e),o=e.query.get("name");if(o===null||!M(o))throw new l(400,"invalid_memory_doc_name","memory document name must be slash-joined [A-Za-z0-9_-] segments");const i=v(e,t,["name","node","cwd","profile","store","dir","select_profile","mode"]);_(i,P);const s=re({target:i.target,...j(i,!1),name:o});if(t.mode==="cli"){const n=pt({name:o,winner:s.doc,candidates:s.candidates});return{status:200,body:{name:n.name,path:n.path,scope:n.scope,local_name:n.localName,store_root:n.root,physical_relative_path:n.physicalRelativePath,representation:n.representation,origin:n.frontmatter?.origin??null}}}return{status:200,body:{name:s.doc.name,scope:s.doc.scope,path:s.doc.path,store_root:s.doc.root,physical_relative_path:s.doc.physicalRelativePath,...s.doc.plugin===void 0?{}:{plugin:s.doc.plugin}}}}m(Pt,"handleResolve");function At(e){const t=v(e,O(e),["node","cwd","profile"]);_(t,P);const o=ye(t.target),i=new Set,s=[];for(const n of o.docs){if(i.has(n.name))continue;i.add(n.name);const r=we(n);if(r?.slash===!0)try{const a=ue(n.path,"utf8"),d=be(a).body;s.push({name:n.name,short_form:r.shortForm,path:n.path,canonical_body:n.body,execution_body:t.nodeId===void 0?d:ce(d,t.nodeId,t.target.grantee)})}catch(a){s.push({name:n.name,short_form:r.shortForm,path:n.path,canonical_body:n.body,error:a instanceof Error?a.message:String(a)})}}return{status:200,body:s}}m(At,"handleSlashDocs");async function Tt(e){const t=C(e.body,["node","name"],[]),o=v(e,t,["node","name"]);if(_(o,P),o.nodeId===void 0)throw new l(400,"invalid_request","slash attachments require a node");const i=$(t,"name",[]);if(i===void 0)throw new l(400,"invalid_request","slash document name required");const n=ye(o.target).resolve([i]).get(i);if(n===void 0)throw new l(404,"not_found",`memory slash document not found: ${i}`);const r=de(e,o);if(r===void 0)throw new l(403,"permission_error","slash attachments require the calling node");const a=be(ue(n.path,"utf8")),d={...n,frontmatter:a.data,body:a.body};if(we(d)?.slash!==!0)throw new l(404,"not_found",`memory slash document not found: ${i}`);const f=ce(d.body,r,o.target.grantee),c=te(r),g=[],k=G(c,"transcript",g);Se(k,d,"content");const b=ge(o.target,{quiet:!0,includeDescendants:!0}),h=ve(d,{subject:_e(o.nodeId),target:k,byName:dt(b.docs),memoryTarget:o.target,listings:"blocks"}).blocks;return z(r,c),Me(r,oe(g,"loaded")),{status:200,body:{blocks:h,execution_body:f}}}m(Tt,"handleSlashAttachments");function Ot(e){const t=C(e.body,["node","cwd","profile","store","dir","mode"],[]),o=v(e,t,["node","cwd","profile","store","dir","mode"]);if(_(o,P),t.dir!==void 0&&(typeof t.dir!="string"||t.dir===""))throw new l(400,"invalid_request","dir must be a nonempty directory path");if(t.dir!==void 0&&t.store!==void 0)throw new l(400,"invalid_request","dir selects one store and cannot combine with store");if(e.principal.class!=="person"){const n=o.store??(o.scope===void 0?void 0:ee(o.target,o.scope).find(d=>d.mountStatus==="ready"));if(n===void 0||(n.scope==="project"?!T(e,n.repositoryRoot??n.ownerDir??n.storeRoot):!fe(e.principal.app,Y(e.principal),e.principal.class==="broker"?e.principal.scopes:null,n,"read",void 0,!0)))throw new l(403,"scope_missing","memory lint requires a whole-store read grant and an explicit store");const r=he(n),a=m(d=>({rule:d.rule,path:d.path,message:d.message}),"row");return{status:200,body:{checked:r.checked,stores:r.storesLinted,findings:r.errors.map(a),warnings:r.warnings.map(a),notices:r.notices.map(a)}}}const i=t.dir===void 0?rt({target:o.target,...o.scope===void 0?{}:{scope:o.scope}}):(()=>{const n=o.store,r=ge({...o.target,cwd:n.ownerDir??n.storeRoot,nodeId:null},{quiet:!0,includeDescendants:!0}),a=he(n,{resolvable:st(r.docs),frontDoor:"advisory"}),d=it(r.docs,{flagStoreRoot:n.storeRoot});return{...a,findings:[...a.findings,...d],warnings:[...a.warnings,...d]}})(),s=m(n=>({rule:n.rule,path:n.path,message:n.message,...n.name===void 0?{}:{name:n.name},...n.scope===void 0?{}:{scope:n.scope},...n.storeRoot===void 0?{}:{store_root:n.storeRoot},...n.paths===void 0?{}:{paths:[...n.paths]}}),"row");return{status:200,body:{checked:i.checked,stores:i.storesLinted,..."profileProjects"in i?{profile_projects:i.profileProjects}:{},findings:i.errors.map(s),warnings:i.warnings.map(s),notices:i.notices.map(s)}}}m(Ot,"handleLint");function Nt(e){const t=v(e,O(e),["node","cwd","profile"]);_(t,P);const o=X(t.target.cwd),i=o!==null&&T(e,t.target.cwd)?"project":"user",s=i==="user"?pe("user"):K(o,"memory");if(e.principal.class!=="person"&&!t.permitted(i==="user"?F("user",s):Q(t.target.cwd)))throw new l(403,"scope_missing","memory extensions are not permitted");if(s===null)throw new Error("user memory directory unavailable");return{status:200,body:ct({scope:i,path:K(s,".extension-help.md")})}}m(Nt,"handleExtensionCatalog");function L(e,t){const o=E(e.body)&&e.body.mode==="cli"?e.body:O(e);if(!E(o)||o.mode!=="cli")return t(e);const i=Object.fromEntries(["node","cwd","profile","store","dir","select_profile"].filter(r=>o[r]!==void 0).map(r=>[r,o[r]])),s=v(e,i,Object.keys(i)),n=(s.store===void 0?ee(s.target,s.scope,!0,!1):[s.store]).filter(r=>r.mountStatus!=="ready"&&r.mountStatus!=="absent"&&r.diagnostic!==void 0).map(r=>`memory store not mounted: ${r.diagnostic}`);s.store===void 0&&(s.scope===void 0||s.scope==="project")&&n.push(...ot(et(s.target.cwd,s.target.profileId).map(({root:r})=>r).filter(r=>T(e,r))));try{const r=t(e);return n.length===0||!E(r.body)?r:{...r,body:{...r.body,diagnostics:n}}}catch(r){throw n.length>0&&r instanceof l&&r.status===404?new l(r.status,r.code,`${r.message}
2
- ${n.join(`
3
- `)}`,r.details):n.length>0&&r instanceof J&&r.code==="not_found"?new J(r.code,`${r.message}
4
- ${n.join(`
5
- `)}`,r.exitCode,r.details):r}}m(L,"withCliDiscovery");function Ct(e){const t=e.query.get("conversation_id");if(t===null||!/^[0-9a-f-]{36}$/i.test(t)||e.query.size!==1)throw new l(400,"invalid_request","conversation_id must be a single conversation UUID");try{const o=Ve().header(t),i=Be(o.path);if(e.principal.class!=="person"&&(i===null||!Xe(e.principal,i.grantee??"app:terminal")))throw new l(404,"not_found",`conversation not found: ${t}`);return{status:200,body:{session_file:o.path}}}catch(o){throw o instanceof Ye?new l(404,"not_found",`conversation not found: ${t}`):o}}m(Ct,"handleOriginConversation");const _o=[{method:"GET",pattern:"/v1/memory/docs",handler:m(e=>L(e,kt),"handler")},{method:"GET",pattern:"/v1/memory/docs/:name",handler:m(e=>L(e,qt),"handler")},{method:"POST",pattern:"/v1/memory/docs",handler:jt},{method:"PATCH",pattern:"/v1/memory/docs/:name",handler:Dt},{method:"DELETE",pattern:"/v1/memory/docs/:name",handler:Rt},{method:"POST",pattern:"/v1/memory/docs/:name/move",handler:Et},{method:"POST",pattern:"/v1/memory/search",handler:m(e=>L(e,$t),"handler")},{method:"GET",pattern:"/v1/memory/docs/:name/history",handler:m(e=>L(e,It),"handler")},{method:"GET",pattern:"/v1/memory/resolve",handler:m(e=>L(e,Pt),"handler")},{method:"GET",pattern:"/v1/memory/origin",handler:Ct},{method:"GET",pattern:"/v1/memory/extensions",handler:Nt},{method:"POST",pattern:"/v1/memory/lint",handler:m(e=>L(e,Ot),"handler")},{method:"GET",pattern:"/v1/memory/slash",handler:At},{method:"POST",pattern:"/v1/memory/slash/attachments",handler:Tt}];export{_o as memoryRoutes};
@@ -1,2 +0,0 @@
1
- import type { ConvergentMigration } from './types.js';
2
- export declare const surfacesFrontmatterMigration: ConvergentMigration;
@@ -1 +0,0 @@
1
- var u=Object.defineProperty;var o=(e,n)=>u(e,"name",{value:n,configurable:!0});import{parse as m}from"yaml";import{parseFrontmatterGeneric as d}from"../core/frontmatter.js";import{appendRenderedKey as h,dropTopLevelKeys as g,proveFrontmatterRoundTrip as y,rebuildDocSource as b}from"./frontmatter-splice.js";const a=["system-prompt-visibility","file-read-visibility","applies-to","read-when"],f=["none","name","preview","content"];function p(e){return f.indexOf(e)}o(p,"rungRank");function c(e){return typeof e=="string"&&f.includes(e)?e:"none"}o(c,"parseRung");function v(e){return typeof e=="string"?e.trim()===""?[]:[e]:Array.isArray(e)?e.filter(n=>typeof n=="string"&&n.trim()!==""):[]}o(v,"parseAppliesTo");function w(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0}o(w,"parsePredicate");function l(e){return e.split("/").map(n=>n.replace(/^\d{2}-/,"")).join("/")}o(l,"normalizeName");function k(e){const n=e.frontmatter;if(n===null||n.kind!=="knowledge"&&n.kind!=="preference")return null;const t=l(e.relPath.replace(/\.md$/,"")),r=n.name,i=typeof r=="string"&&r.trim()!==""?l(r.trim()):t;return{doc:e,name:i,spv:c(n["system-prompt-visibility"]),fv:c(n["file-read-visibility"]),appliesTo:v(n["applies-to"]),readWhen:w(n["read-when"]),hasOldFields:a.some(s=>s in n)}}o(k,"classify");function D(e){const n=new Map;for(const t of e){if(t.name!=="INDEX"&&!t.name.endsWith("/INDEX"))continue;const r=t.name==="INDEX"?"":t.name.slice(0,t.name.length-6);n.has(r)||n.set(r,t.spv)}return n}o(D,"buildCeiling");function N(e,n){let t=e.spv;const r=e.name.split("/");r.pop();for(let i=r.length;i>0;i--){const s=n.get(r.slice(0,i).join("/"));s!==void 0&&p(s)<p(t)&&(t=s)}return t}o(N,"effectiveBootRung");function W(e){const n=e.trim();return!n.includes("/")||n.startsWith("/")||n.startsWith("**")||n.startsWith("./")?n:`./${n}`}o(W,"anchorReadGlob");function E(e,n){const t=[];if(e.spv!=="none"&&n!=="none"&&t.push({on:"boot",at:n}),e.fv!=="none"){e.appliesTo.some(i=>i.trim()===".")&&(t.push({on:"workspace-open",at:e.fv}),t.push({on:"read",match:"./**",at:e.fv}));const r=e.appliesTo.filter(i=>i.trim()!==".").map(W);r.length>0&&t.push({on:"read",match:r.length===1?r[0]:r,at:e.fv}),e.readWhen!==void 0&&t.push({on:"read","match-frontmatter":e.readWhen,at:e.fv})}return t}o(E,"planEntries");function F(e,n,t){let r=g(e,a,t);n.length>0?r=h(r,"surfaces",n,t):r=r.replace(/\r?\n$/,"");const i={...m(e)};for(const s of a)delete i[s];return n.length>0&&(i.surfaces=n),y(r,i,t),r}o(F,"migratedYaml");const x={id:"001-surfaces-frontmatter",lane:"convergent",description:"surfaces frontmatter: fold visibility/applies-to/read-when routing into surfaces entries",apply(e){const n=e.docs.map(k).filter(i=>i!==null),t=D(n),r=[];for(const i of n){if(!i.hasOldFields)continue;const s=F(d(i.doc.source).raw,E(i,N(i,t)),i.doc.path);r.push({path:i.doc.path,after:b(i.doc.source,s,i.doc.path)})}return r}};export{x as surfacesFrontmatterMigration};