@north-light/crouter 0.3.353 → 0.3.355

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (626) hide show
  1. package/dist/api/client.d.ts +35 -25
  2. package/dist/api/client.js +2 -2
  3. package/dist/api/dto/broker-ops.d.ts +2 -36
  4. package/dist/api/dto/canvas.d.ts +8 -13
  5. package/dist/api/dto/config.d.ts +4 -0
  6. package/dist/api/dto/delivery.d.ts +61 -0
  7. package/dist/api/dto/docs.d.ts +135 -0
  8. package/dist/api/dto/docs.js +1 -0
  9. package/dist/api/dto/health.d.ts +26 -79
  10. package/dist/api/dto/node-outcomes.d.ts +1 -3
  11. package/dist/api/dto/nodes.d.ts +5 -26
  12. package/dist/api/dto/objects.d.ts +168 -0
  13. package/dist/api/dto/objects.js +1 -0
  14. package/dist/api/dto/profiles.d.ts +14 -8
  15. package/dist/api/dto/reports.d.ts +9 -7
  16. package/dist/api/dto/reviews.d.ts +11 -3
  17. package/dist/api/dto/worktree.d.ts +1 -1
  18. package/dist/api/index.d.ts +0 -1
  19. package/dist/api/index.js +1 -1
  20. package/dist/api/routes.d.ts +14 -12
  21. package/dist/api/routes.js +1 -1
  22. package/dist/build-root.js +1 -1
  23. package/dist/builtin-memory/00-runtime-base/00-authoring.md +10 -5
  24. package/dist/builtin-memory/02-turn-lifecycle/02-resident.md +1 -0
  25. package/dist/builtin-memory/04-orchestration-kernel.md +10 -31
  26. package/dist/builtin-memory/05-kinds/advisor/01-orchestrator.md +1 -1
  27. package/dist/builtin-memory/05-kinds/explore/00-base.md +2 -2
  28. package/dist/builtin-memory/05-kinds/explore/01-orchestrator.md +2 -2
  29. package/dist/builtin-memory/crouter-concepts/INDEX.md +2 -2
  30. package/dist/builtin-memory/crouter-concepts/lifecycle-and-wakes.md +1 -1
  31. package/dist/builtin-memory/crouter-concepts/memory.md +15 -15
  32. package/dist/builtin-memory/crouter-concepts/nodes-and-the-canvas.md +1 -1
  33. package/dist/builtin-memory/crouter-concepts/profiles-kinds-and-modes.md +5 -5
  34. package/dist/builtin-memory/crouter-concepts/scopes-and-trust.md +1 -1
  35. package/dist/builtin-memory/crouter-concepts/why-a-daemon.md +1 -1
  36. package/dist/builtin-memory/crouter-sdk/INDEX.md +2 -2
  37. package/dist/builtin-memory/crouter-sdk/README.md +5 -6
  38. package/dist/builtin-memory/crouter-sdk/errors.md +0 -13
  39. package/dist/builtin-memory/crouter-sdk/guides/README.md +0 -1
  40. package/dist/builtin-memory/crouter-sdk/guides/event-driven-assistant.md +2 -2
  41. package/dist/builtin-memory/crouter-sdk/nodes.md +0 -2
  42. package/dist/builtin-memory/crouter-sdk/resources.md +0 -1
  43. package/dist/builtin-memory/explore/exploration-doc.md +4 -4
  44. package/dist/builtin-memory/insights/capture.md +6 -6
  45. package/dist/builtin-memory/insights/init.md +14 -14
  46. package/dist/builtin-memory/internal/INDEX.md +4 -4
  47. package/dist/builtin-memory/internal/agent-shaping.md +20 -20
  48. package/dist/builtin-memory/internal/examples/imessage-assistant.md +2 -2
  49. package/dist/builtin-memory/internal/marketplaces.md +2 -2
  50. package/dist/builtin-memory/internal/memory-loading.md +31 -30
  51. package/dist/builtin-memory/internal/nodes-and-canvas.md +1 -1
  52. package/dist/builtin-memory/internal/plugins.md +16 -14
  53. package/dist/builtin-memory/internal/storage-tiers.md +4 -4
  54. package/dist/builtin-memory/memory-read-orientation.md +1 -1
  55. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/memory-slash-commands.ts +32 -40
  56. package/dist/clients/attach/input/controller.js +1 -1
  57. package/dist/clients/attach/input/ref-autocomplete.js +1 -1
  58. package/dist/clients/attach/input/titled-editor.js +1 -1
  59. package/dist/clients/attach/overlays/file-review.d.ts +1 -0
  60. package/dist/clients/attach/overlays/file-review.js +2 -2
  61. package/dist/clients/attach/render/chat-view.d.ts +6 -0
  62. package/dist/clients/attach/render/chat-view.js +2 -2
  63. package/dist/clients/attach/render/crtr-output.d.ts +1 -2
  64. package/dist/clients/attach/render/crtr-output.js +17 -17
  65. package/dist/clients/attach/render/doc-links.d.ts +34 -0
  66. package/dist/clients/attach/render/doc-links.js +1 -0
  67. package/dist/clients/attach/render/group-activity.d.ts +8 -8
  68. package/dist/clients/attach/render/group-activity.js +2 -2
  69. package/dist/clients/attach/render/group-recap.js +1 -1
  70. package/dist/clients/attach/render/markdown-source.js +5 -5
  71. package/dist/clients/attach/render/tool-calls.d.ts +1 -1
  72. package/dist/clients/attach/session/doc-materialize.d.ts +53 -0
  73. package/dist/clients/attach/session/doc-materialize.js +3 -0
  74. package/dist/clients/attach/session/document-links.d.ts +21 -0
  75. package/dist/clients/attach/session/document-links.js +1 -0
  76. package/dist/clients/attach/session/file-links.d.ts +2 -0
  77. package/dist/clients/attach/session/file-links.js +1 -1
  78. package/dist/clients/attach/session/profile-files.js +1 -1
  79. package/dist/clients/attach/slash/dispatch.js +1 -1
  80. package/dist/clients/attach/viewer.js +816 -1561
  81. package/dist/clients/inbox/review/review-client.d.ts +5 -1
  82. package/dist/clients/inbox/review/review-client.js +1 -1
  83. package/dist/commands/api-client.d.ts +2 -0
  84. package/dist/commands/api-client.js +3 -3
  85. package/dist/commands/canvas/edges.d.ts +2 -0
  86. package/dist/commands/canvas/edges.js +2 -0
  87. package/dist/commands/canvas/list.d.ts +4 -0
  88. package/dist/commands/canvas/list.js +3 -0
  89. package/dist/commands/canvas/read.d.ts +8 -0
  90. package/dist/commands/canvas/read.js +5 -0
  91. package/dist/commands/canvas/search.d.ts +2 -0
  92. package/dist/commands/canvas/search.js +3 -0
  93. package/dist/commands/canvas/unwatch.d.ts +2 -0
  94. package/dist/commands/canvas/unwatch.js +1 -0
  95. package/dist/commands/canvas/watch.d.ts +3 -0
  96. package/dist/commands/canvas/watch.js +1 -0
  97. package/dist/commands/canvas-analytics.js +1 -1
  98. package/dist/commands/canvas-history/grep.js +4 -4
  99. package/dist/commands/canvas-history/read.js +2 -2
  100. package/dist/commands/canvas-history/search.js +7 -7
  101. package/dist/commands/canvas-history/shared.d.ts +0 -1
  102. package/dist/commands/canvas-history/shared.js +1 -1
  103. package/dist/commands/canvas-history/stats.js +2 -2
  104. package/dist/commands/canvas-history.js +1 -1
  105. package/dist/commands/canvas.js +1 -1
  106. package/dist/commands/doc/delete.d.ts +2 -0
  107. package/dist/commands/doc/delete.js +1 -0
  108. package/dist/commands/doc/edit.d.ts +2 -0
  109. package/dist/commands/doc/edit.js +1 -0
  110. package/dist/commands/doc/history.d.ts +2 -0
  111. package/dist/commands/doc/history.js +2 -0
  112. package/dist/commands/doc/lint.d.ts +2 -0
  113. package/dist/commands/doc/lint.js +2 -0
  114. package/dist/commands/doc/list.d.ts +2 -0
  115. package/dist/commands/doc/list.js +1 -0
  116. package/dist/commands/doc/move.d.ts +2 -0
  117. package/dist/commands/doc/move.js +1 -0
  118. package/dist/commands/doc/read.d.ts +2 -0
  119. package/dist/commands/doc/read.js +1 -0
  120. package/dist/commands/doc/shared.d.ts +25 -0
  121. package/dist/commands/doc/shared.js +2 -0
  122. package/dist/commands/doc/write.d.ts +2 -0
  123. package/dist/commands/doc/write.js +1 -0
  124. package/dist/commands/{memory.d.ts → doc.d.ts} +1 -1
  125. package/dist/commands/doc.js +1 -0
  126. package/dist/commands/human/review.js +1 -1
  127. package/dist/commands/node/bash.js +2 -2
  128. package/dist/commands/node/create.js +1 -1
  129. package/dist/commands/node/inspect.js +10 -10
  130. package/dist/commands/node/lifecycle.js +2 -2
  131. package/dist/commands/node/outcome.js +1 -1
  132. package/dist/commands/node/subscription.js +1 -1
  133. package/dist/commands/node-context.js +2 -2
  134. package/dist/commands/pkg/browse/catalog.js +1 -1
  135. package/dist/commands/pkg/browse/doc-view.js +1 -1
  136. package/dist/commands/pkg/browse/model.d.ts +9 -17
  137. package/dist/commands/pkg/plugin-inspect.js +1 -1
  138. package/dist/commands/pkg/plugin-manage.d.ts +4 -8
  139. package/dist/commands/pkg/plugin-manage.js +15 -17
  140. package/dist/commands/profile/list.js +1 -1
  141. package/dist/commands/profile/new.js +1 -1
  142. package/dist/commands/profile/project.js +1 -1
  143. package/dist/commands/profile/show.js +1 -1
  144. package/dist/commands/push.js +3 -3
  145. package/dist/commands/sys/config.js +1 -1
  146. package/dist/commands/sys/context/admin/actions.d.ts +18 -43
  147. package/dist/commands/sys/context/admin/actions.js +1 -2
  148. package/dist/commands/sys/context/admin/detail-panel.d.ts +17 -25
  149. package/dist/commands/sys/context/admin/detail-panel.js +2 -1
  150. package/dist/commands/sys/context/admin/docs-panel.d.ts +7 -6
  151. package/dist/commands/sys/context/admin/docs-panel.js +1 -1
  152. package/dist/commands/sys/context/admin/list-view.d.ts +12 -12
  153. package/dist/commands/sys/context/admin/list-view.js +1 -1
  154. package/dist/commands/sys/context/admin/model.d.ts +96 -69
  155. package/dist/commands/sys/context/admin/model.js +1 -1
  156. package/dist/commands/sys/context/admin/rail-panel.d.ts +7 -5
  157. package/dist/commands/sys/context/admin/rail-panel.js +1 -1
  158. package/dist/commands/sys/context/admin/read-view.d.ts +10 -14
  159. package/dist/commands/sys/context/admin/read-view.js +1 -2
  160. package/dist/commands/sys/context/admin/shell.d.ts +26 -31
  161. package/dist/commands/sys/context/admin/shell.js +1 -1
  162. package/dist/commands/sys/context/admin.js +2 -2
  163. package/dist/commands/sys/context/doc.js +2 -3
  164. package/dist/commands/sys/context/expose.js +2 -2
  165. package/dist/commands/sys/context/prompt-review.js +4 -4
  166. package/dist/commands/sys/context/resolve.d.ts +92 -65
  167. package/dist/commands/sys/context/resolve.js +7 -9
  168. package/dist/commands/sys/context.js +1 -1
  169. package/dist/commands/sys/doctor.js +1 -1
  170. package/dist/commands/sys/migrate.js +1 -1
  171. package/dist/commands/sys/panels/profiles-panel.d.ts +3 -1
  172. package/dist/commands/sys/panels/profiles-panel.js +1 -1
  173. package/dist/commands/sys/sync-deps.d.ts +6 -11
  174. package/dist/commands/sys/sync-deps.js +7 -8
  175. package/dist/commands/sys/sync-project-guidance.js +5 -4
  176. package/dist/commands/sys/sync-shared.d.ts +41 -4
  177. package/dist/commands/sys/sync-shared.js +1 -1
  178. package/dist/commands/sys/sync-skills.js +2 -2
  179. package/dist/commands/sys/sync.js +1 -1
  180. package/dist/core/bash-job-supervisor.d.ts +2 -3
  181. package/dist/core/bash-job-supervisor.js +3 -3
  182. package/dist/core/bash-jobs.d.ts +0 -5
  183. package/dist/core/bash-jobs.js +7 -7
  184. package/dist/core/bootstrap.js +2 -2
  185. package/dist/core/canvas/canvas.d.ts +6 -50
  186. package/dist/core/canvas/canvas.js +16 -21
  187. package/dist/core/canvas/db.d.ts +4 -1
  188. package/dist/core/canvas/db.js +2 -2
  189. package/dist/core/canvas/history.d.ts +11 -39
  190. package/dist/core/canvas/history.js +9 -20
  191. package/dist/core/canvas/install-id.d.ts +2 -2
  192. package/dist/core/canvas/install-id.js +1 -1
  193. package/dist/core/canvas/memory-reads.d.ts +5 -0
  194. package/dist/core/canvas/memory-reads.js +1 -1
  195. package/dist/core/canvas/migrations.js +215 -41
  196. package/dist/core/canvas/node-agent-paths.js +1 -1
  197. package/dist/core/canvas/node-tokens.js +1 -1
  198. package/dist/core/canvas/paths.d.ts +0 -4
  199. package/dist/core/canvas/paths.js +1 -1
  200. package/dist/core/canvas/remote-canvas-source.d.ts +0 -1
  201. package/dist/core/canvas/remote-canvas-source.js +1 -1
  202. package/dist/core/canvas/render-source.d.ts +9 -6
  203. package/dist/core/canvas/render-source.js +6 -6
  204. package/dist/core/canvas/sessions.js +2 -2
  205. package/dist/core/canvas/source.d.ts +6 -0
  206. package/dist/core/canvas/tree.d.ts +29 -0
  207. package/dist/core/canvas/tree.js +12 -0
  208. package/dist/core/canvas/types.d.ts +0 -20
  209. package/dist/core/command-plugins/bundle.js +1 -1
  210. package/dist/core/config.d.ts +1 -1
  211. package/dist/core/conversation-store/listener.js +4 -2
  212. package/dist/core/feed/feed.d.ts +9 -7
  213. package/dist/core/feed/feed.js +3 -7
  214. package/dist/core/feed/inbox.d.ts +3 -5
  215. package/dist/core/feed/inbox.js +1 -10
  216. package/dist/core/feed/messages.d.ts +33 -6
  217. package/dist/core/feed/messages.js +10 -7
  218. package/dist/core/feed/reports.d.ts +10 -0
  219. package/dist/core/feed/reports.js +2 -0
  220. package/dist/core/grants/remove.js +1 -1
  221. package/dist/core/graph/access.d.ts +24 -0
  222. package/dist/core/graph/access.js +8 -0
  223. package/dist/core/graph/bodies.d.ts +6 -0
  224. package/dist/core/graph/bodies.js +1 -0
  225. package/dist/core/graph/deletion.d.ts +10 -0
  226. package/dist/core/graph/deletion.js +5 -0
  227. package/dist/core/graph/diff.d.ts +4 -0
  228. package/dist/core/graph/diff.js +4 -0
  229. package/dist/core/graph/documents.d.ts +167 -0
  230. package/dist/core/graph/documents.js +10 -0
  231. package/dist/core/graph/edges.d.ts +25 -0
  232. package/dist/core/graph/edges.js +1 -0
  233. package/dist/core/graph/events.d.ts +26 -0
  234. package/dist/core/graph/events.js +7 -0
  235. package/dist/core/graph/exposures.d.ts +53 -0
  236. package/dist/core/graph/exposures.js +4 -0
  237. package/dist/core/graph/jobs.d.ts +31 -0
  238. package/dist/core/graph/jobs.js +2 -0
  239. package/dist/core/graph/names.d.ts +30 -0
  240. package/dist/core/graph/names.js +3 -0
  241. package/dist/core/graph/objects.d.ts +55 -0
  242. package/dist/core/graph/objects.js +9 -0
  243. package/dist/core/graph/package-docs.d.ts +31 -0
  244. package/dist/core/graph/package-docs.js +5 -0
  245. package/dist/core/graph/package-files.d.ts +20 -0
  246. package/dist/core/graph/package-files.js +2 -0
  247. package/dist/core/graph/reader.d.ts +21 -0
  248. package/dist/core/graph/reader.js +3 -0
  249. package/dist/core/graph/repo-sync/exchange.d.ts +34 -0
  250. package/dist/core/graph/repo-sync/exchange.js +2 -0
  251. package/dist/core/graph/repo-sync/identity.d.ts +30 -0
  252. package/dist/core/graph/repo-sync/identity.js +1 -0
  253. package/dist/core/graph/repo-sync/index.d.ts +4 -0
  254. package/dist/core/graph/repo-sync/index.js +1 -0
  255. package/dist/core/graph/repo-sync/mirror.d.ts +30 -0
  256. package/dist/core/graph/repo-sync/mirror.js +6 -0
  257. package/dist/core/graph/repo-sync/ref-format.d.ts +76 -0
  258. package/dist/core/graph/repo-sync/ref-format.js +2 -0
  259. package/dist/core/graph/repo-sync/repos.d.ts +17 -0
  260. package/dist/core/graph/repo-sync/repos.js +3 -0
  261. package/dist/core/graph/repo-sync/sync.d.ts +42 -0
  262. package/dist/core/graph/repo-sync/sync.js +2 -0
  263. package/dist/core/graph/rules.d.ts +26 -0
  264. package/dist/core/graph/rules.js +3 -0
  265. package/dist/core/graph/spaces/app.d.ts +3 -0
  266. package/dist/core/graph/spaces/app.js +1 -0
  267. package/dist/core/graph/spaces/index.d.ts +19 -0
  268. package/dist/core/graph/spaces/index.js +1 -0
  269. package/dist/core/graph/spaces/person.d.ts +5 -0
  270. package/dist/core/graph/spaces/person.js +2 -0
  271. package/dist/core/graph/spaces/repo.d.ts +4 -0
  272. package/dist/core/graph/spaces/repo.js +1 -0
  273. package/dist/core/graph/types.d.ts +75 -0
  274. package/dist/core/graph/types.js +1 -0
  275. package/dist/core/graph/watches.d.ts +62 -0
  276. package/dist/core/graph/watches.js +18 -0
  277. package/dist/core/human/feedback-companion.js +1 -1
  278. package/dist/core/human/requests.d.ts +3 -1
  279. package/dist/core/human/requests.js +6 -6
  280. package/dist/core/inspector/model.js +2 -2
  281. package/dist/core/io.js +5 -5
  282. package/dist/core/layout-migrate/index.d.ts +24 -1
  283. package/dist/core/layout-migrate/index.js +4 -4
  284. package/dist/core/layout-migrate/paths.d.ts +4 -0
  285. package/dist/core/layout-migrate/paths.js +1 -1
  286. package/dist/core/layout-migrate/stored-paths.d.ts +7 -0
  287. package/dist/core/layout-migrate/stored-paths.js +11 -11
  288. package/dist/core/layout-migrate/stores.d.ts +19 -6
  289. package/dist/core/layout-migrate/stores.js +3 -4
  290. package/dist/core/manifest.d.ts +0 -2
  291. package/dist/core/manifest.js +1 -1
  292. package/dist/core/{memory/extensions.d.ts → plugin-extensions.d.ts} +9 -10
  293. package/dist/core/plugin-extensions.js +1 -0
  294. package/dist/core/preview-registry.d.ts +1 -1
  295. package/dist/core/preview-registry.js +3 -2
  296. package/dist/core/profiles/manifest.d.ts +7 -7
  297. package/dist/core/profiles/manifest.js +1 -1
  298. package/dist/core/profiles/select.js +3 -3
  299. package/dist/core/review/birth.js +1 -1
  300. package/dist/core/review/companion.js +1 -1
  301. package/dist/core/review/stage.d.ts +12 -1
  302. package/dist/core/review/stage.js +1 -1
  303. package/dist/core/review/store.d.ts +2 -0
  304. package/dist/core/review/store.js +1 -1
  305. package/dist/core/review/types.d.ts +7 -1
  306. package/dist/core/runs/events.js +1 -1
  307. package/dist/core/runs/operations.js +5 -5
  308. package/dist/core/runs/questions.js +2 -2
  309. package/dist/core/runtime/bearings-render.d.ts +13 -7
  310. package/dist/core/runtime/bearings-render.js +12 -12
  311. package/dist/core/runtime/bearings.d.ts +8 -18
  312. package/dist/core/runtime/bearings.js +7 -7
  313. package/dist/core/runtime/broker/daemon-ops.d.ts +7 -12
  314. package/dist/core/runtime/broker/daemon-ops.js +1 -1
  315. package/dist/core/runtime/broker/fault-retry.d.ts +2 -0
  316. package/dist/core/runtime/broker/fault-retry.js +1 -1
  317. package/dist/core/runtime/broker/frame-dispatch.d.ts +1 -1
  318. package/dist/core/runtime/broker/frame-memory-refs.d.ts +7 -2
  319. package/dist/core/runtime/broker/frame-memory-refs.js +1 -1
  320. package/dist/core/runtime/broker/inbox.d.ts +1 -4
  321. package/dist/core/runtime/broker/inbox.js +1 -10
  322. package/dist/core/runtime/broker/rebind.js +1 -1
  323. package/dist/core/runtime/broker/retry-card-elision.d.ts +7 -0
  324. package/dist/core/runtime/broker/retry-card-elision.js +1 -0
  325. package/dist/core/runtime/broker-extension-render.d.ts +0 -13
  326. package/dist/core/runtime/broker-extension-render.js +2 -4
  327. package/dist/core/runtime/broker-persona-guidance.js +3 -3
  328. package/dist/core/runtime/broker-protocol.d.ts +1 -1
  329. package/dist/core/runtime/broker.js +1 -1
  330. package/dist/core/runtime/close.d.ts +9 -4
  331. package/dist/core/runtime/close.js +1 -1
  332. package/dist/core/runtime/deliver-live.js +1 -1
  333. package/dist/core/runtime/kickoff.js +17 -19
  334. package/dist/core/runtime/launch-target.d.ts +7 -0
  335. package/dist/core/runtime/launch-target.js +1 -1
  336. package/dist/core/runtime/ledger.d.ts +10 -0
  337. package/dist/core/runtime/ledger.js +3 -0
  338. package/dist/core/runtime/lifecycle.js +2 -2
  339. package/dist/core/runtime/nodes.d.ts +10 -2
  340. package/dist/core/runtime/nodes.js +1 -1
  341. package/dist/core/runtime/outcome-document.d.ts +2 -2
  342. package/dist/core/runtime/outcome-document.js +1 -1
  343. package/dist/core/runtime/persona.js +2 -2
  344. package/dist/core/runtime/placement.js +1 -1
  345. package/dist/core/runtime/promote.d.ts +2 -2
  346. package/dist/core/runtime/promote.js +1 -1
  347. package/dist/core/runtime/prospective-inventory-cli.js +2 -2
  348. package/dist/core/runtime/recycle.js +1 -1
  349. package/dist/core/runtime/reopen.js +1 -1
  350. package/dist/core/runtime/revive.js +2 -2
  351. package/dist/core/runtime/roadmap.d.ts +20 -9
  352. package/dist/core/runtime/roadmap.js +10 -6
  353. package/dist/core/runtime/spawn-env.js +1 -1
  354. package/dist/core/runtime/spawn.d.ts +5 -3
  355. package/dist/core/runtime/spawn.js +2 -2
  356. package/dist/core/runtime/structured-output.d.ts +3 -1
  357. package/dist/core/runtime/structured-output.js +4 -4
  358. package/dist/core/scope.d.ts +1 -32
  359. package/dist/core/scope.js +1 -1
  360. package/dist/core/scoped-state/db.js +2 -1
  361. package/dist/core/scoped-state/migrate.js +2 -2
  362. package/dist/core/scoped-state/profiles.d.ts +11 -0
  363. package/dist/core/scoped-state/profiles.js +1 -1
  364. package/dist/core/scoped-state/schema.d.ts +1 -1
  365. package/dist/core/scoped-state/schema.js +7 -5
  366. package/dist/core/spaces/permissions.d.ts +0 -14
  367. package/dist/core/spaces/permissions.js +1 -1
  368. package/dist/core/spaces/stop.d.ts +13 -0
  369. package/dist/core/spaces/stop.js +2 -2
  370. package/dist/core/storage/tables.d.ts +1 -1
  371. package/dist/core/substrate/delivery/corpus.d.ts +21 -0
  372. package/dist/core/substrate/delivery/corpus.js +3 -0
  373. package/dist/core/substrate/delivery/deliver.d.ts +76 -0
  374. package/dist/core/substrate/delivery/deliver.js +6 -0
  375. package/dist/core/substrate/delivery/listings.d.ts +30 -0
  376. package/dist/core/substrate/delivery/listings.js +7 -0
  377. package/dist/core/substrate/delivery/match.d.ts +28 -0
  378. package/dist/core/substrate/delivery/match.js +1 -0
  379. package/dist/core/substrate/delivery/plan.d.ts +67 -0
  380. package/dist/core/substrate/delivery/plan.js +3 -0
  381. package/dist/core/substrate/delivery/render-boot.d.ts +20 -0
  382. package/dist/core/substrate/delivery/render-boot.js +54 -0
  383. package/dist/core/substrate/delivery/render-event.d.ts +54 -0
  384. package/dist/core/substrate/delivery/render-event.js +8 -0
  385. package/dist/core/substrate/delivery/sub-persona-menu.d.ts +2 -0
  386. package/dist/core/substrate/delivery/sub-persona-menu.js +6 -0
  387. package/dist/core/substrate/delivery/types.d.ts +30 -0
  388. package/dist/core/substrate/delivery/types.js +0 -0
  389. package/dist/core/substrate/gate-explain.d.ts +0 -13
  390. package/dist/core/substrate/gate-explain.js +1 -1
  391. package/dist/core/substrate/schema.d.ts +11 -139
  392. package/dist/core/substrate/schema.js +1 -1
  393. package/dist/core/substrate/subject-fields.d.ts +3 -0
  394. package/dist/core/substrate/subject.d.ts +2 -1
  395. package/dist/core/substrate/subject.js +1 -1
  396. package/dist/daemon/api/handlers/app-profiles.js +1 -1
  397. package/dist/daemon/api/handlers/bash-jobs.js +1 -2
  398. package/dist/daemon/api/handlers/broker-ops.js +1 -1
  399. package/dist/daemon/api/handlers/canvas.js +5 -5
  400. package/dist/daemon/api/handlers/daemon.js +1 -1
  401. package/dist/daemon/api/handlers/delivery.d.ts +2 -0
  402. package/dist/daemon/api/handlers/delivery.js +1 -0
  403. package/dist/daemon/api/handlers/{memory.d.ts → docs.d.ts} +1 -1
  404. package/dist/daemon/api/handlers/docs.js +1 -0
  405. package/dist/daemon/api/handlers/hook-exec.js +1 -1
  406. package/dist/daemon/api/handlers/messages.js +2 -2
  407. package/dist/daemon/api/handlers/node-records.js +2 -2
  408. package/dist/daemon/api/handlers/nodes.js +1 -1
  409. package/dist/daemon/api/handlers/objects.d.ts +2 -0
  410. package/dist/daemon/api/handlers/objects.js +5 -0
  411. package/dist/daemon/api/handlers/package-docs.d.ts +2 -0
  412. package/dist/daemon/api/handlers/package-docs.js +1 -0
  413. package/dist/daemon/api/handlers/profiles.js +1 -1
  414. package/dist/daemon/api/handlers/reports.d.ts +2 -2
  415. package/dist/daemon/api/handlers/reports.js +4 -4
  416. package/dist/daemon/api/handlers/reviews.d.ts +4 -1
  417. package/dist/daemon/api/handlers/reviews.js +1 -1
  418. package/dist/daemon/api/map.d.ts +2 -2
  419. package/dist/daemon/api/map.js +2 -2
  420. package/dist/daemon/api/operations.d.ts +1 -1
  421. package/dist/daemon/api/operations.js +1 -1
  422. package/dist/daemon/api/reader.d.ts +17 -0
  423. package/dist/daemon/api/reader.js +1 -0
  424. package/dist/daemon/api/server.js +1 -1
  425. package/dist/daemon/control.d.ts +2 -3
  426. package/dist/daemon/crtrd.js +8 -6
  427. package/dist/daemon/fleet.js +4 -4
  428. package/dist/daemon/reconcilers/bash-deadline.d.ts +11 -1
  429. package/dist/daemon/reconcilers/bash-deadline.js +2 -1
  430. package/dist/daemon/reconcilers/broker-supervision.js +4 -4
  431. package/dist/daemon/reconcilers/live-obligation.js +1 -1
  432. package/dist/daemon/reconcilers/node-deadline.js +1 -1
  433. package/dist/daemon/reconcilers/node-lifecycle/freeze-lane.js +1 -1
  434. package/dist/daemon/reconcilers/storage-maintenance.d.ts +1 -0
  435. package/dist/daemon/reconcilers/storage-maintenance.js +1 -1
  436. package/dist/daemon/review/deliver.js +2 -2
  437. package/dist/daemon/review/finish.js +1 -1
  438. package/dist/hook-authoring.d.ts +0 -1
  439. package/dist/hook-authoring.js +3 -3
  440. package/dist/migrations/004-canvas-documents/apply.d.ts +10 -0
  441. package/dist/migrations/004-canvas-documents/apply.js +1 -0
  442. package/dist/migrations/004-canvas-documents/fields.d.ts +24 -0
  443. package/dist/migrations/004-canvas-documents/fields.js +2 -0
  444. package/dist/migrations/004-canvas-documents/index.d.ts +16 -0
  445. package/dist/migrations/004-canvas-documents/index.js +2 -0
  446. package/dist/migrations/004-canvas-documents/legacy/discover.d.ts +16 -0
  447. package/dist/migrations/004-canvas-documents/legacy/discover.js +1 -0
  448. package/dist/migrations/004-canvas-documents/legacy/history.d.ts +5 -0
  449. package/dist/migrations/004-canvas-documents/legacy/history.js +2 -0
  450. package/dist/migrations/004-canvas-documents/legacy/nested.d.ts +7 -0
  451. package/dist/migrations/004-canvas-documents/legacy/nested.js +1 -0
  452. package/dist/migrations/004-canvas-documents/legacy/parse.d.ts +14 -0
  453. package/dist/migrations/004-canvas-documents/legacy/parse.js +1 -0
  454. package/dist/migrations/004-canvas-documents/legacy/types.d.ts +91 -0
  455. package/dist/migrations/004-canvas-documents/legacy/types.js +0 -0
  456. package/dist/migrations/004-canvas-documents/legacy-edges.d.ts +6 -0
  457. package/dist/migrations/004-canvas-documents/legacy-edges.js +18 -0
  458. package/dist/migrations/004-canvas-documents/plan.d.ts +102 -0
  459. package/dist/migrations/004-canvas-documents/plan.js +3 -0
  460. package/dist/migrations/004-canvas-documents/pointers.d.ts +23 -0
  461. package/dist/migrations/004-canvas-documents/pointers.js +4 -0
  462. package/dist/migrations/activation.d.ts +9 -18
  463. package/dist/migrations/activation.js +2 -2
  464. package/dist/pi-extensions/broker-local.d.ts +2 -2
  465. package/dist/pi-extensions/broker-local.js +2 -2
  466. package/dist/pi-extensions/canvas-bash-valve.js +5 -4
  467. package/dist/pi-extensions/canvas-context-intro.js +2 -2
  468. package/dist/pi-extensions/canvas-doc-substrate.d.ts +0 -1
  469. package/dist/pi-extensions/canvas-doc-substrate.js +6 -6
  470. package/dist/pi-extensions/canvas-inbox-watcher.js +2 -2
  471. package/dist/pi-extensions/canvas-passive-context.js +1 -1
  472. package/dist/pi-extensions/canvas-recap.js +2 -2
  473. package/dist/pi-extensions/canvas-stophook.d.ts +1 -1
  474. package/dist/pi-extensions/canvas-stophook.js +1 -1
  475. package/dist/prompts/review.js +3 -3
  476. package/dist/shared/env.d.ts +5 -0
  477. package/dist/shared/env.js +1 -1
  478. package/dist/shared/generated-context.js +2 -10
  479. package/dist/shared/inbox-entry-body.d.ts +22 -0
  480. package/dist/shared/inbox-entry-body.js +10 -0
  481. package/dist/{core/memory → shared}/inline-ref-guidance.d.ts +2 -2
  482. package/dist/shared/inline-ref-guidance.js +2 -0
  483. package/dist/types.d.ts +3 -1
  484. package/docs/cli/memory-and-preferences.md +12 -14
  485. package/docs/concepts/README.md +1 -1
  486. package/docs/concepts/lifecycle-and-wakes.md +1 -1
  487. package/docs/concepts/memory.md +15 -15
  488. package/docs/concepts/nodes-and-the-canvas.md +1 -1
  489. package/docs/concepts/profiles-kinds-and-modes.md +5 -5
  490. package/docs/concepts/scopes-and-trust.md +1 -1
  491. package/docs/concepts/why-a-daemon.md +1 -1
  492. package/docs/sdk/README.md +5 -6
  493. package/docs/sdk/errors.md +0 -13
  494. package/docs/sdk/guides/README.md +0 -1
  495. package/docs/sdk/nodes.md +0 -2
  496. package/docs/sdk/resources.md +0 -1
  497. package/package.json +2 -2
  498. package/packages/crouter-identity/package.json +1 -1
  499. package/runtime.lock.json +11 -11
  500. package/scripts/lib/isolation-env.mjs +8 -2
  501. package/dist/api/dto/memory.d.ts +0 -171
  502. package/dist/api/dto/memory.js +0 -1
  503. package/dist/builtin-memory/crouter-sdk/guides/app-memory.md +0 -73
  504. package/dist/builtin-memory/crouter-sdk/memory.md +0 -87
  505. package/dist/commands/broker-permissions.d.ts +0 -2
  506. package/dist/commands/broker-permissions.js +0 -1
  507. package/dist/commands/memory/client.d.ts +0 -11
  508. package/dist/commands/memory/client.js +0 -1
  509. package/dist/commands/memory/delete.d.ts +0 -1
  510. package/dist/commands/memory/delete.js +0 -1
  511. package/dist/commands/memory/edit.d.ts +0 -1
  512. package/dist/commands/memory/edit.js +0 -21
  513. package/dist/commands/memory/find.d.ts +0 -1
  514. package/dist/commands/memory/find.js +0 -1
  515. package/dist/commands/memory/history.d.ts +0 -1
  516. package/dist/commands/memory/history.js +0 -5
  517. package/dist/commands/memory/lint.d.ts +0 -1
  518. package/dist/commands/memory/lint.js +0 -1
  519. package/dist/commands/memory/list.d.ts +0 -1
  520. package/dist/commands/memory/list.js +0 -1
  521. package/dist/commands/memory/move.d.ts +0 -1
  522. package/dist/commands/memory/move.js +0 -1
  523. package/dist/commands/memory/origin.d.ts +0 -1
  524. package/dist/commands/memory/origin.js +0 -1
  525. package/dist/commands/memory/read.d.ts +0 -1
  526. package/dist/commands/memory/read.js +0 -6
  527. package/dist/commands/memory/shared.d.ts +0 -22
  528. package/dist/commands/memory/shared.js +0 -1
  529. package/dist/commands/memory/write.d.ts +0 -1
  530. package/dist/commands/memory/write.js +0 -13
  531. package/dist/commands/memory.js +0 -1
  532. package/dist/commands/node-inspect-artifacts.d.ts +0 -1
  533. package/dist/commands/node-inspect-artifacts.js +0 -8
  534. package/dist/core/help/memory-extensions.d.ts +0 -3
  535. package/dist/core/help/memory-extensions.js +0 -2
  536. package/dist/core/memory/cli-selector.d.ts +0 -13
  537. package/dist/core/memory/cli-selector.js +0 -1
  538. package/dist/core/memory/doc-link-grammar.d.ts +0 -20
  539. package/dist/core/memory/doc-link-grammar.js +0 -2
  540. package/dist/core/memory/extensions.js +0 -1
  541. package/dist/core/memory/history.d.ts +0 -87
  542. package/dist/core/memory/history.js +0 -6
  543. package/dist/core/memory/identity.d.ts +0 -65
  544. package/dist/core/memory/identity.js +0 -1
  545. package/dist/core/memory/inline-ref-guidance.js +0 -2
  546. package/dist/core/memory/inline-ref-inventory.d.ts +0 -9
  547. package/dist/core/memory/inline-ref-inventory.js +0 -1
  548. package/dist/core/memory/lint.d.ts +0 -163
  549. package/dist/core/memory/lint.js +0 -2
  550. package/dist/core/memory/mutation-domain.d.ts +0 -113
  551. package/dist/core/memory/mutation-domain.js +0 -12
  552. package/dist/core/memory/mutations.d.ts +0 -74
  553. package/dist/core/memory/mutations.js +0 -1
  554. package/dist/core/memory/project-namespace.d.ts +0 -31
  555. package/dist/core/memory/project-namespace.js +0 -2
  556. package/dist/core/memory/repository-association.d.ts +0 -31
  557. package/dist/core/memory/repository-association.js +0 -1
  558. package/dist/core/memory/service.d.ts +0 -145
  559. package/dist/core/memory/service.js +0 -2
  560. package/dist/core/memory/tree.d.ts +0 -39
  561. package/dist/core/memory/tree.js +0 -1
  562. package/dist/core/memory-resolver.d.ts +0 -280
  563. package/dist/core/memory-resolver.js +0 -2
  564. package/dist/core/nested-stores.d.ts +0 -18
  565. package/dist/core/nested-stores.js +0 -1
  566. package/dist/core/runtime/memory.d.ts +0 -3
  567. package/dist/core/runtime/memory.js +0 -1
  568. package/dist/core/substrate/frontmatter-validation.d.ts +0 -11
  569. package/dist/core/substrate/frontmatter-validation.js +0 -1
  570. package/dist/core/substrate/gate.d.ts +0 -16
  571. package/dist/core/substrate/gate.js +0 -1
  572. package/dist/core/substrate/index.d.ts +0 -18
  573. package/dist/core/substrate/index.js +0 -1
  574. package/dist/core/substrate/injected-store.d.ts +0 -75
  575. package/dist/core/substrate/injected-store.js +0 -2
  576. package/dist/core/substrate/listings.d.ts +0 -28
  577. package/dist/core/substrate/listings.js +0 -1
  578. package/dist/core/substrate/memory-events.d.ts +0 -6
  579. package/dist/core/substrate/memory-events.js +0 -1
  580. package/dist/core/substrate/on-read-node.d.ts +0 -6
  581. package/dist/core/substrate/on-read-node.js +0 -1
  582. package/dist/core/substrate/on-read.d.ts +0 -101
  583. package/dist/core/substrate/on-read.js +0 -9
  584. package/dist/core/substrate/plan.d.ts +0 -94
  585. package/dist/core/substrate/plan.js +0 -1
  586. package/dist/core/substrate/render-node.d.ts +0 -12
  587. package/dist/core/substrate/render-node.js +0 -1
  588. package/dist/core/substrate/render.d.ts +0 -41
  589. package/dist/core/substrate/render.js +0 -65
  590. package/dist/core/substrate/session-cache.d.ts +0 -27
  591. package/dist/core/substrate/session-cache.js +0 -1
  592. package/dist/core/substrate/surface-match.d.ts +0 -73
  593. package/dist/core/substrate/surface-match.js +0 -1
  594. package/dist/daemon/api/handlers/memory.js +0 -5
  595. package/dist/migrations/001-surfaces-frontmatter.d.ts +0 -2
  596. package/dist/migrations/001-surfaces-frontmatter.js +0 -1
  597. package/dist/migrations/002-profile-project-memory.d.ts +0 -2
  598. package/dist/migrations/002-profile-project-memory.js +0 -1
  599. package/dist/migrations/003-repository-root-memory-identity/front-door.d.ts +0 -26
  600. package/dist/migrations/003-repository-root-memory-identity/front-door.js +0 -11
  601. package/dist/migrations/003-repository-root-memory-identity/index.d.ts +0 -2
  602. package/dist/migrations/003-repository-root-memory-identity/index.js +0 -5
  603. package/dist/migrations/003-repository-root-memory-identity/references.d.ts +0 -95
  604. package/dist/migrations/003-repository-root-memory-identity/references.js +0 -5
  605. package/dist/migrations/003-repository-root-memory-identity/repository-facts.d.ts +0 -39
  606. package/dist/migrations/003-repository-root-memory-identity/repository-facts.js +0 -3
  607. package/dist/migrations/convergent.d.ts +0 -43
  608. package/dist/migrations/convergent.js +0 -2
  609. package/dist/migrations/corpus.d.ts +0 -75
  610. package/dist/migrations/corpus.js +0 -3
  611. package/dist/migrations/frontmatter-splice.d.ts +0 -15
  612. package/dist/migrations/frontmatter-splice.js +0 -8
  613. package/dist/migrations/profile-manifests.d.ts +0 -30
  614. package/dist/migrations/profile-manifests.js +0 -2
  615. package/dist/migrations/registry.d.ts +0 -7
  616. package/dist/migrations/registry.js +0 -1
  617. package/dist/migrations/runner.d.ts +0 -43
  618. package/dist/migrations/runner.js +0 -1
  619. package/dist/migrations/types.d.ts +0 -211
  620. package/dist/shared/birth-announcement.d.ts +0 -12
  621. package/dist/shared/birth-announcement.js +0 -1
  622. package/docs/sdk/guides/app-memory.md +0 -22
  623. package/docs/sdk/memory.md +0 -85
  624. /package/dist/{migrations/types.js → api/dto/delivery.js} +0 -0
  625. /package/dist/{core/memory → shared}/inline-ref-grammar.d.ts +0 -0
  626. /package/dist/{core/memory → shared}/inline-ref-grammar.js +0 -0
@@ -0,0 +1,24 @@
1
+ import type { Privacy, RuleSpec } from '../../core/graph/types.js';
2
+ export type DocumentKind = 'knowledge' | 'preference' | 'report';
3
+ export interface DocumentFields {
4
+ kind: DocumentKind;
5
+ privacy: Privacy;
6
+ preview: string;
7
+ summary: string | null;
8
+ whyItExists: string | null;
9
+ unlisted: boolean;
10
+ lintIgnore: unknown;
11
+ extensions: unknown;
12
+ rules: RuleSpec[];
13
+ /** Frontmatter keys with no document field; listed in the report. */
14
+ dropped: string[];
15
+ }
16
+ /** First non-empty body line, with a leading markdown heading or list marker removed. */
17
+ export declare function firstLine(body: string): string;
18
+ /** `missingPrivacy` is what a document without a valid `privacy` key gets. */
19
+ export declare function documentFields(fm: Record<string, unknown> | null, body: string, opts: {
20
+ kind?: DocumentKind;
21
+ missingPrivacy: Privacy;
22
+ }): DocumentFields;
23
+ /** AND `extra` into every rule's `if` (private repo documents re-owned to the person). */
24
+ export declare function andIntoRules(rules: RuleSpec[], extra: Record<string, unknown>): RuleSpec[];
@@ -0,0 +1,2 @@
1
+ var c=Object.defineProperty;var r=(e,t)=>c(e,"name",{value:t,configurable:!0});import{rulesFromFrontmatter as u}from"../../core/graph/rules.js";const f=new Set(["kind","privacy","unlisted","lint-ignore","extensions","when-and-why-to-read","short-form","rationale","surfaces","gate","slash","origin","last-updated","name","namespace"]),p=["public","friends","private"],s=r(e=>typeof e=="string"&&e.trim()!==""?e.trim():null,"str");function m(e){for(const t of e.split(`
2
+ `)){const i=t.trim().replace(/^#+\s*/,"").replace(/^[-*]\s+/,"").trim();if(i!==""&&i!=="---")return i}return""}r(m,"firstLine");function g(e,t,i){const n=e??{},o=Object.keys(n).filter(a=>!f.has(a));let l=i.kind??"knowledge";i.kind===void 0&&n.kind!==void 0&&(n.kind==="knowledge"||n.kind==="preference"?l=n.kind:o.push("kind"));const d=typeof n.privacy=="string"&&p.includes(n.privacy)?n.privacy:i.missingPrivacy;return{kind:l,privacy:d,preview:s(n["when-and-why-to-read"])?.replace(/\s+/g," ")??m(t),summary:s(n["short-form"]),whyItExists:s(n.rationale),unlisted:n.unlisted===!0,lintIgnore:n["lint-ignore"]??null,extensions:n.extensions??null,rules:u(n),dropped:o}}r(g,"documentFields");function h(e,t){return e.map(i=>({...i,if:i.if===void 0?t:{all:[i.if,t]}}))}r(h,"andIntoRules");export{h as andIntoRules,g as documentFields,m as firstLine};
@@ -0,0 +1,16 @@
1
+ import { type ImportBlocker, type ImportReport } from './plan.js';
2
+ export type { ImportBlocker, ImportReport } from './plan.js';
3
+ export interface CanvasImportResult {
4
+ report: ImportReport;
5
+ blockers: ImportBlocker[];
6
+ dryRun: boolean;
7
+ /** True while this home still has to be imported (always false after a write run succeeds). */
8
+ pending: boolean;
9
+ }
10
+ /** Whether this home's import has already been recorded. */
11
+ export declare function canvasImportDone(): boolean;
12
+ /** Plan and (unless `dryRun` or blocked) apply the import. On an imported home a dry run
13
+ * returns the recorded report; a write run does nothing and returns empty counts. */
14
+ export declare function runCanvasImport(opts: {
15
+ dryRun: boolean;
16
+ }): CanvasImportResult;
@@ -0,0 +1,2 @@
1
+ var g=Object.defineProperty;var a=(e,n)=>g(e,"name",{value:n,configurable:!0});import{existsSync as f}from"node:fs";import{join as l}from"node:path";import{openDb as c,withCanvasWrite as w}from"../../core/canvas/db.js";import{nodeAgentDir as k,nodeRecordDir as S,onDiskMigrationMarkerPath as C}from"../../core/canvas/paths.js";import{identifyCheckout as j}from"../../core/graph/repo-sync/identity.js";import{profileSpace as I,userRoot as b}from"../../core/layout.js";import{commitConvertedProjectCaps as E,listLegacyProjectCaps as P,listStoredProfiles as x}from"../../core/scoped-state/profiles.js";import{userStore as L}from"../../core/scoped-state/paths.js";import{userScopeRoot as y}from"../../core/scope.js";import{applyPlan as M,readImportRecord as h,storePlanBodies as _}from"./apply.js";import{readLegacyCorpus as v,readMarkerIds as D}from"./legacy/discover.js";import{planImport as O}from"./plan.js";const F=a(()=>({stores:[],counts:{},rewrites:[],droppedFields:[],skipped:[],resolutions:[]}),"emptyReport");function A(){const e=y(),n=x(e),o=P(e),m=L(e).path,i=n.map(({profileId:r,manifest:s})=>{const p=s.grantee??"app:terminal",d=new Map(o.filter(t=>t.profileId===r).map(t=>[t.path,t.memory]));return{id:r,name:s.name,app:p,memory:I(p,r).memory,projects:s.projects.map(t=>t.path),raw:{projects:s.projects.map(t=>d.has(t.path)?{path:t.path,memory:d.get(t.path)}:{path:t.path})},manifestPath:`${m}#${r}`}}),u=c().prepare("SELECT node_id, cwd, grantee FROM node_rows ORDER BY created").all(),R=u.map(r=>{const s=r.grantee==="user:local"?"app:terminal":r.grantee,p=s?.startsWith("app:")?k(r.node_id,s):null,d=p!==null&&(f(l(p,"context"))||f(l(p,"reports")))?p:S(r.node_id);return{id:r.node_id,dir:d}});return{roots:{userMemory:l(b(),"memory"),profiles:i,nodeCwds:[...new Set(u.map(r=>r.cwd))],nodes:R},stored:n}}a(A,"legacyRoots");function N(){const{roots:e,stored:n}=A(),o=v(e),m=c().prepare(`SELECT o.type, o.name AS handle, i.external_id AS externalId FROM objects o
2
+ LEFT JOIN identities i ON i.object = o.rowid WHERE o.type IN ('person','app','repo','profile')`).all();return O(o,{roots:e,markerIds:D(C()),repoIdentity:j,existingOwners:m,storedProfiles:n.map(i=>({id:i.profileId,deliveryLimits:{...i.manifest.delivery_limits??{}}}))})}a(N,"plan");function V(){return h(c())!==null}a(V,"canvasImportDone");function X(e){const n=h(c());if(n!==null)return{report:e.dryRun?n:F(),blockers:[],dryRun:e.dryRun,pending:!1};const o=N();if(e.dryRun||o.blockers.length>0)return{report:o.report,blockers:o.blockers,dryRun:e.dryRun,pending:!0};const m=_(o);return E(y(),o.profileLimits),w(i=>M(i,o,m)),{report:o.report,blockers:[],dryRun:!1,pending:!1}}a(X,"runCanvasImport");export{V as canvasImportDone,X as runCanvasImport};
@@ -0,0 +1,16 @@
1
+ import type { LegacyCorpus, LegacyProfile, LegacyRoots } from './types.js';
2
+ export type { LegacyCorpus, LegacyDoc, LegacyOwnerRef, LegacyProfile, LegacyRoots, LegacyStoreRoot, LegacyHistoryRecord } from './types.js';
3
+ /** Every stored profile manifest, read as raw JSON (the current manifest reader
4
+ * is not used). `memoryFor(app, id)` resolves the profile's store path. */
5
+ export declare function readLegacyProfiles(profilesRoot: string, memoryFor: (app: string, id: string) => string): {
6
+ profiles: LegacyProfile[];
7
+ skipped: Array<{
8
+ path: string;
9
+ reason: string;
10
+ }>;
11
+ };
12
+ /** Ids listed in `<canvas home>/on-disk-migrations.json`, or null when the marker is absent. */
13
+ export declare function readMarkerIds(markerPath: string): string[] | null;
14
+ export declare function readLegacyCorpus(roots: LegacyRoots): LegacyCorpus;
15
+ /** Cheap probe: is there any legacy document to import? */
16
+ export declare function hasLegacyContent(roots: LegacyRoots): boolean;
@@ -0,0 +1 @@
1
+ var J=Object.defineProperty;var l=(t,o)=>J(t,"name",{value:o,configurable:!0});import{existsSync as D,readdirSync as b,readFileSync as x,realpathSync as P,statSync as R}from"node:fs";import{basename as T,dirname as C,isAbsolute as L,join as i,relative as A,resolve as F}from"node:path";import{walkFiles as I}from"../../../core/fs-utils.js";import{historyLogPath as O,HISTORY_DIR as z,readHistory as X}from"./history.js";import{walkNestedStores as W}from"./nested.js";import{contextDocName as _,parseFile as $,rawFile as E,storeDocName as q}from"./parse.js";const G=/^[a-z0-9]+(?:-[a-z0-9]+)*-[0-9a-f]{8}$/;function k(t){try{return P(t)}catch{return F(t)}}l(k,"real");const w=l(t=>{try{return R(t).isDirectory()}catch{return!1}},"isDir"),Y=l(t=>["canvas","canvas.db","runtime","profiles"].some(o=>D(i(t,o))),"isCrouterHome"),H=l(t=>I(t,o=>o.toLowerCase().endsWith(".md"),o=>o.startsWith(".")).sort(),"markdownIn");function re(t,o){const s=[],y=[];if(!w(t))return{profiles:s,skipped:y};for(const j of b(t).sort()){const d=i(t,j,"profile.json");if(!G.test(j)||!D(d))continue;let h;try{const p=JSON.parse(x(d,"utf8"));if(p===null||typeof p!="object"||Array.isArray(p))throw new Error("not a JSON object");h=p}catch(p){y.push({path:d,reason:`invalid-manifest: ${p.message}`});continue}const v=typeof h.grantee=="string"?h.grantee:"app:terminal",M=Array.isArray(h.projects)?h.projects.flatMap(p=>typeof p=="string"?[p]:p!==null&&typeof p=="object"&&typeof p.path=="string"?[p.path]:[]):[];s.push({id:j,name:typeof h.name=="string"?h.name:j,app:v,memory:o(v,j),projects:M,raw:h,manifestPath:d})}return{profiles:s,skipped:y}}l(re,"readLegacyProfiles");function ne(t){if(!D(t))return null;const o=JSON.parse(x(t,"utf8"));if(!Array.isArray(o))throw new Error(`${t}: not a JSON array`);return o.map(s=>typeof s=="string"?s:String(s.id))}l(ne,"readMarkerIds");function B(t){const o=i(t,".git");if(w(o))return k(o);if(!D(o))return null;const s=/^gitdir:\s*(.+)$/m.exec(x(o,"utf8"));if(!s)return null;const y=L(s[1].trim())?s[1].trim():F(t,s[1].trim()),j=i(y,"commondir");if(!D(j))return k(y);const d=x(j,"utf8").trim();return k(L(d)?d:F(y,d))}l(B,"gitCommonDir");function K(t){const o={docs:[],storeRoots:[],skipped:[],orphanHistory:0,orphanNodeDirs:0,nonMarkdown:0,injectedDocs:0},s=new Set([t.userMemory,...t.profiles.map(e=>e.memory)].map(k)),y=l((e,r,c)=>{const u=H(e),S=new Set(u.map(n=>O(e,n)));o.orphanHistory+=I(i(e,z),n=>n.endsWith(".jsonl")).filter(n=>!S.has(n)).length;let g=0;for(const n of u){const f=c+q(A(e,n));let m;try{m=$(n)}catch(N){o.docs.push({path:n,owner:r,name:f,source:"store",...E(n),history:[],invalid:{kind:"invalid-source",reason:`invalid frontmatter: ${N.message}`}}),g+=1;continue}let a;try{a=X(O(e,n))}catch(N){o.docs.push({path:n,owner:r,name:f,source:"store",...m,history:[],invalid:{kind:"invalid-history",reason:`unreadable history log: ${N.message}`}}),g+=1;continue}o.docs.push({path:n,owner:r,name:f,source:"store",...m,history:a}),g+=1}o.storeRoots.push({root:e,owner:r,docs:g})},"readStore");w(t.userMemory)&&y(t.userMemory,{type:"person"},"");for(const e of t.profiles)w(e.memory)&&y(e.memory,{type:"profile",id:e.id},"");const j=l(e=>{let r=null;for(let c=k(e);;c=C(c)){if(D(i(c,".git")))return c;const u=i(c,".crouter","memory");if(r===null&&w(u)&&!s.has(k(u))&&!Y(i(c,".crouter"))&&(r=c),C(c)===c)return r}},"projectRoot"),d=[];for(const e of[...t.profiles.flatMap(r=>r.projects),...t.nodeCwds]){if(!w(e))continue;const r=j(e);r!==null&&d.push(r)}const h=new Map,v=new Set,M=[];for(;d.length>0;){const e=d.shift();if(v.has(e))continue;v.add(e);const r=B(e);if(M.push({root:e,commonDir:r}),r!==null){h.set(r,[...h.get(r)??[],e]);const c=C(r);T(r)===".git"&&w(i(c,".git"))&&d.push(c)}d.push(...W(e).embeddedRepos)}for(const{root:e,commonDir:r}of M.sort((c,u)=>c.root.localeCompare(u.root))){const c=r===null?[e]:h.get(r),u=c.find(a=>w(i(a,".git")))??[...c].sort()[0],S=i(e,".crouter","memory"),g=w(S)&&!s.has(k(S)),n=W(e).nested.filter(a=>!s.has(k(i(e,a,".crouter","memory"))));let f=null;if(g&&D(i(S,"INDEX.md")))try{const a=$(i(S,"INDEX.md")).frontmatter?.namespace;typeof a=="string"&&a!==""&&(f=a)}catch{}const m={type:"repo",root:e,commonDir:r,namespace:f};if(e!==u){g&&o.storeRoots.push({root:S,owner:m,docs:0,skipped:"duplicate-worktree"});for(const a of n)o.storeRoots.push({root:i(e,a,".crouter","memory"),owner:m,docs:0,skipped:"duplicate-worktree"});continue}g&&y(S,m,"");for(const a of n)y(i(e,a,".crouter","memory"),m,a.split(/[\\/]/).join("/")+"/")}const p=new Set(t.nodes.map(e=>e.id));for(const e of new Set(t.nodes.map(r=>C(r.dir))))for(const r of b(e,{withFileTypes:!0}))r.isDirectory()&&!p.has(r.name)&&(o.orphanNodeDirs+=1);for(const{id:e,dir:r}of t.nodes){const c={type:"node",id:e};D(i(r,"injected-docs.json"))&&(o.injectedDocs+=1);const u=i(r,"context");w(i(u,"memory"))&&y(i(u,"memory"),c,"");const S=l((n,f,m)=>{try{o.docs.push({path:n,owner:c,name:f,source:m,...$(n),history:[]})}catch(a){o.docs.push({path:n,owner:c,name:f,source:m,...E(n),history:[],invalid:{kind:"invalid-source",reason:`invalid frontmatter: ${a.message}`}})}},"readPlain");for(const n of I(u,()=>!0,f=>f.startsWith(".")).sort()){const f=A(u,n),m=f.split(/[\\/]/)[0];m==="memory"||m==="jobs"||(n.toLowerCase().endsWith(".md")?S(n,_(f),"context"):o.nonMarkdown+=1)}const g=i(r,"reports");if(w(g))for(const n of b(g,{withFileTypes:!0}).sort((f,m)=>f.name.localeCompare(m.name)))n.isFile()&&(n.name.toLowerCase().endsWith(".md")?S(i(g,n.name),`reports/${n.name.replace(/\.md$/i,"")}`,"report"):o.nonMarkdown+=1)}return o}l(K,"readLegacyCorpus");function se(t){const o=l(s=>w(s)&&H(s).length>0,"anyMd");return o(t.userMemory)||t.profiles.some(s=>o(s.memory))||t.nodes.some(s=>o(i(s.dir,"context"))||o(i(s.dir,"reports")))?!0:K({...t,nodes:[]}).docs.length>0}l(se,"hasLegacyContent");export{se as hasLegacyContent,K as readLegacyCorpus,re as readLegacyProfiles,ne as readMarkerIds};
@@ -0,0 +1,5 @@
1
+ import type { LegacyHistoryRecord } from './types.js';
2
+ export declare const HISTORY_DIR = ".history";
3
+ export declare function historyLogPath(storeRoot: string, docPath: string): string;
4
+ /** Records of the current life, or throws naming the bad line. */
5
+ export declare function readHistory(logPath: string): LegacyHistoryRecord[];
@@ -0,0 +1,2 @@
1
+ var c=Object.defineProperty;var o=(r,t)=>c(r,"name",{value:t,configurable:!0});import{existsSync as f,readFileSync as l}from"node:fs";import{join as a,relative as y}from"node:path";const h=".history";function w(r,t){return a(r,h,y(r,t).replace(/\.md$/i,"")+".jsonl")}o(w,"historyLogPath");function x(r){if(!f(r))return[];const t=[];return l(r,"utf8").split(`
2
+ `).forEach((n,i)=>{if(n.trim()==="")return;let s;try{s=JSON.parse(n)}catch(p){throw new Error(`line ${i+1}: ${p.message}`)}const e=s;if(e===null||typeof e!="object"||typeof e.op!="string"||typeof e.at!="string"||typeof e.after!="string")throw new Error(`line ${i+1}: not a history record`);e.op==="delete"?t.length=0:t.push(e)}),t}o(x,"readHistory");export{h as HISTORY_DIR,w as historyLogPath,x as readHistory};
@@ -0,0 +1,7 @@
1
+ export interface NestedWalk {
2
+ /** `<rel>` of each `<root>/<rel>/.crouter/memory`, rel non-empty. */
3
+ nested: string[];
4
+ /** Folders below the root holding their own `.git`. */
5
+ embeddedRepos: string[];
6
+ }
7
+ export declare function walkNestedStores(root: string): NestedWalk;
@@ -0,0 +1 @@
1
+ var m=Object.defineProperty;var d=(s,e)=>m(s,"name",{value:e,configurable:!0});import{existsSync as c,readdirSync as p}from"node:fs";import{join as i,relative as u}from"node:path";function l(s){const e={nested:[],embeddedRepos:[]},o=[s];for(;o.length>0;){const t=o.pop();if(t!==s){if(c(i(t,".git"))){e.embeddedRepos.push(t);continue}c(i(t,".crouter","memory"))&&e.nested.push(u(s,t))}let r;try{r=p(t,{withFileTypes:!0})}catch{continue}for(const n of r)!n.isDirectory()||n.name.startsWith(".")||n.name==="node_modules"||o.push(i(t,n.name))}return e.nested.sort(),e.embeddedRepos.sort(),e}d(l,"walkNestedStores");export{l as walkNestedStores};
@@ -0,0 +1,14 @@
1
+ export interface ParsedFile {
2
+ frontmatter: Record<string, unknown> | null;
3
+ body: string;
4
+ mtime: string;
5
+ }
6
+ /** Throws when the frontmatter is not valid YAML. */
7
+ export declare function parseFile(path: string): ParsedFile;
8
+ /** A file whose frontmatter does not parse: the whole text is the body. */
9
+ export declare function rawFile(path: string): ParsedFile;
10
+ /** Frozen store naming: drop `.md`, strip each segment's `NN-` ordering prefix,
11
+ * fold `a/INDEX` to `a`; the store's root `INDEX.md` is `index`. */
12
+ export declare function storeDocName(relPath: string): string;
13
+ /** A node context file's name: its folder-relative path without `.md`. */
14
+ export declare function contextDocName(relPath: string): string;
@@ -0,0 +1 @@
1
+ var m=Object.defineProperty;var r=(e,t)=>m(e,"name",{value:t,configurable:!0});import{readFileSync as n,statSync as o}from"node:fs";import{parseFrontmatterGeneric as a}from"../../../core/frontmatter.js";function f(e){const t=a(n(e,"utf8"));return{frontmatter:t.data,body:t.body,mtime:o(e).mtime.toISOString()}}r(f,"parseFile");function u(e){return{frontmatter:null,body:n(e,"utf8"),mtime:o(e).mtime.toISOString()}}r(u,"rawFile");function d(e){const t=e.replace(/\\/g,"/").replace(/\.md$/i,"").split("/").map(i=>i.replace(/^\d{2}-/,""));return t[t.length-1]==="INDEX"&&t.pop(),t.length===0?"index":t.join("/")}r(d,"storeDocName");function s(e){return e.replace(/\\/g,"/").replace(/\.md$/i,"")}r(s,"contextDocName");export{s as contextDocName,f as parseFile,u as rawFile,d as storeDocName};
@@ -0,0 +1,91 @@
1
+ /** Frozen copy of the history record shape the retired store-file history wrote. */
2
+ export interface LegacyHistoryRecord {
3
+ op: 'create' | 'edit' | 'delete' | 'move';
4
+ at: string;
5
+ node?: string;
6
+ cwd: string;
7
+ from?: string;
8
+ rationale?: string;
9
+ verbatim?: boolean;
10
+ before: string;
11
+ after: string;
12
+ }
13
+ export interface LegacyProfile {
14
+ id: string;
15
+ name: string;
16
+ /** The owning app (`grantee`), `app:terminal` for older manifests without one. */
17
+ app: string;
18
+ /** The profile's store (`<app memory>/profiles/<id>`), resolved by the caller. */
19
+ memory: string;
20
+ /** Every `projects[].path` in the manifest. */
21
+ projects: string[];
22
+ /** The manifest as parsed JSON, for fields the plan converts (`projects[].memory`). */
23
+ raw?: Record<string, unknown>;
24
+ manifestPath?: string;
25
+ }
26
+ export interface LegacyRoots {
27
+ userMemory: string;
28
+ profiles: LegacyProfile[];
29
+ nodeCwds: string[];
30
+ /** Node rows that exist in canvas.db and their folders (`<nodes>/<id>`). */
31
+ nodes: Array<{
32
+ id: string;
33
+ dir: string;
34
+ }>;
35
+ }
36
+ export type LegacyOwnerRef = {
37
+ type: 'person';
38
+ } | {
39
+ type: 'profile';
40
+ id: string;
41
+ } | {
42
+ type: 'repo';
43
+ root: string;
44
+ commonDir: string | null;
45
+ namespace: string | null;
46
+ } | {
47
+ type: 'node';
48
+ id: string;
49
+ };
50
+ export interface LegacyDoc {
51
+ path: string;
52
+ owner: LegacyOwnerRef;
53
+ /** The document name under its owner (INDEX folding, nested prefix, `reports/<stem>`, root `INDEX.md` → `index`). */
54
+ name: string;
55
+ source: 'store' | 'context' | 'report';
56
+ frontmatter: Record<string, unknown> | null;
57
+ body: string;
58
+ mtime: string;
59
+ /** Records of the file's current life (after its last `delete`), in file order; store documents only. */
60
+ history: LegacyHistoryRecord[];
61
+ /** Set when the file could not be read as written: `invalid-source` (unparseable
62
+ * frontmatter; `body` is the whole file and `frontmatter` null) or `invalid-history`
63
+ * (its history log is unreadable; `history` is empty). */
64
+ invalid?: {
65
+ kind: 'invalid-source' | 'invalid-history';
66
+ reason: string;
67
+ };
68
+ }
69
+ export interface LegacyStoreRoot {
70
+ root: string;
71
+ owner: LegacyOwnerRef;
72
+ docs: number;
73
+ skipped?: 'duplicate-worktree';
74
+ }
75
+ export interface LegacyCorpus {
76
+ docs: LegacyDoc[];
77
+ storeRoots: LegacyStoreRoot[];
78
+ /** Files or roots not read, with the reason; informational. */
79
+ skipped: Array<{
80
+ path: string;
81
+ reason: string;
82
+ }>;
83
+ /** History logs whose document file no longer exists. */
84
+ orphanHistory: number;
85
+ /** Folders beside the given node folders with no node row. */
86
+ orphanNodeDirs: number;
87
+ /** Non-markdown files under node `context/` and `reports/` folders (not imported). */
88
+ nonMarkdown: number;
89
+ /** `injected-docs.json` ledgers found in node folders (not imported; the roll ends their sessions). */
90
+ injectedDocs: number;
91
+ }
@@ -0,0 +1,6 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ /** canvas.db chain step: converts the node-only `legacy_edges` rows into graph rows, then drops it.
3
+ * `spawned_by(child, parent)` → `edges(acted-on, parent → child)`.
4
+ * `subscribes_to(watcher, object)` → an in-tree watch with one `>` subscription, started `spawn`
5
+ * when the object was spawned by the watcher, else `ask`; a passive row listens at next-turn. */
6
+ export declare function convertLegacyEdges(db: DatabaseSync): void;
@@ -0,0 +1,18 @@
1
+ var n=Object.defineProperty;var s=(e,t)=>n(e,"name",{value:t,configurable:!0});function _(e){if(!e.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'legacy_edges'").get())return;const t=s(d=>e.prepare(d).get().n,"count"),c=t("SELECT COUNT(*) AS n FROM legacy_edges WHERE type = 'spawned_by'"),r=t("SELECT COUNT(*) AS n FROM legacy_edges WHERE type = 'subscribes_to'"),o=t("SELECT COUNT(*) AS n FROM legacy_edges WHERE type NOT IN ('spawned_by', 'subscribes_to')");if(o>0)throw new Error(`convertLegacyEdges: ${o} legacy edge(s) of an unknown type`);const a=e.prepare(`INSERT INTO edges (type, src, dst, written_as, created_at)
2
+ SELECT 'acted-on', p.rowid, c.rowid, NULL, e.created
3
+ FROM legacy_edges e JOIN objects c ON c.id = e.from_id JOIN objects p ON p.id = e.to_id
4
+ WHERE e.type = 'spawned_by'
5
+ ON CONFLICT (type, src, dst) DO NOTHING`).run().changes,E=e.prepare(`INSERT INTO watches (watcher, object, in_tree, read_heads_key, created_at)
6
+ SELECT w.rowid, o.rowid, 1, NULL, e.created
7
+ FROM legacy_edges e JOIN objects w ON w.id = e.from_id JOIN objects o ON o.id = e.to_id
8
+ WHERE e.type = 'subscribes_to'
9
+ ON CONFLICT (watcher, object) DO UPDATE SET in_tree = 1`).run().changes;if(e.exec(`INSERT INTO watch_subscriptions (watch, pattern, filter_json, config_json, started_by, ends_on, created_at)
10
+ SELECT wt.rowid, '>', NULL,
11
+ CASE WHEN e.active = 1 THEN NULL ELSE '{"3":"next-turn"}' END,
12
+ CASE WHEN EXISTS (SELECT 1 FROM legacy_edges s
13
+ WHERE s.type = 'spawned_by' AND s.from_id = e.to_id AND s.to_id = e.from_id)
14
+ THEN 'spawn' ELSE 'ask' END,
15
+ NULL, e.created
16
+ FROM legacy_edges e JOIN objects w ON w.id = e.from_id JOIN objects o ON o.id = e.to_id
17
+ JOIN watches wt ON wt.watcher = w.rowid AND wt.object = o.rowid
18
+ WHERE e.type = 'subscribes_to'`),a!==c||E!==r)throw new Error(`convertLegacyEdges: converted ${a}/${c} spawned_by and ${E}/${r} subscribes_to rows`);e.exec("DROP TABLE legacy_edges")}s(_,"convertLegacyEdges");export{_ as convertLegacyEdges};
@@ -0,0 +1,102 @@
1
+ import { type CheckoutIdentity } from '../../core/graph/repo-sync/identity.js';
2
+ import type { Privacy, RuleSpec } from '../../core/graph/types.js';
3
+ import { type DocumentKind } from './fields.js';
4
+ import type { LegacyCorpus, LegacyRoots } from './legacy/types.js';
5
+ /** The store migrations every plan assumes already ran (the previous release's lanes). */
6
+ export declare const CONVERGED_MARKER_IDS: readonly ["001-surfaces-frontmatter", "002-profile-project-memory", "003-repository-root-memory-identity"];
7
+ export type OwnerType = 'person' | 'app' | 'profile' | 'repo' | 'node';
8
+ export interface PlannedOwner {
9
+ /** Stable key documents point at: `person`, `app:<handle>`, `profile:<id>`, `repo:<externalId>`, `node:<id>`. */
10
+ key: string;
11
+ type: OwnerType;
12
+ handle: string;
13
+ /** Repo identity (`ensureRepo`). */
14
+ scheme?: 'git' | 'local-path';
15
+ externalId?: string;
16
+ /** A profile's owning app, as an owner key (`app:<handle>`). */
17
+ ownerKey?: string;
18
+ }
19
+ export interface PlannedRevision {
20
+ body: string;
21
+ authorNodeId: string | null;
22
+ rationale: string | null;
23
+ createdAt: string;
24
+ }
25
+ export interface PlannedDocument {
26
+ ownerKey: string;
27
+ name: string;
28
+ kind: DocumentKind;
29
+ privacy: Privacy;
30
+ preview: string;
31
+ summary: string | null;
32
+ whyItExists: string | null;
33
+ unlisted: boolean;
34
+ lintIgnore: unknown;
35
+ extensions: unknown;
36
+ rules: RuleSpec[];
37
+ /** Oldest first; the last one is the head, whose body carries the pointer rewrite. */
38
+ revisions: PlannedRevision[];
39
+ sourcePath: string;
40
+ }
41
+ /** A stored-profile update (scoped-state `profiles.delivery_limits_json`): the legacy
42
+ * profile.json `projects[].memory` caps, keyed by repo handle, merged over the row's limits. */
43
+ export interface PlannedProfileLimits {
44
+ profileId: string;
45
+ deliveryLimits: Record<string, string>;
46
+ }
47
+ /** Something that stops the import. Only a runtime that skipped the previous
48
+ * release's store migrations blocks; every other finding resolves itself. */
49
+ export interface ImportBlocker {
50
+ kind: 'marker';
51
+ message: string;
52
+ paths: string[];
53
+ }
54
+ /** One finding the plan resolved on its own, with what it did. */
55
+ export interface ImportResolution {
56
+ kind: 'invalid-source' | 'invalid-history' | 'name-clash' | 'repo-handle' | 'profile-handle' | 'repo-identity' | 'delivery-limit' | 'empty-preview';
57
+ message: string;
58
+ paths: string[];
59
+ }
60
+ export interface ImportReport {
61
+ stores: LegacyCorpus['storeRoots'];
62
+ counts: Record<string, number>;
63
+ rewrites: Array<{
64
+ path: string;
65
+ from: string;
66
+ to: string;
67
+ }>;
68
+ droppedFields: Array<{
69
+ path: string;
70
+ field: string;
71
+ }>;
72
+ skipped: LegacyCorpus['skipped'];
73
+ /** Every clash or unreadable source the plan resolved, one line each. */
74
+ resolutions: ImportResolution[];
75
+ }
76
+ export interface ImportPlan {
77
+ owners: PlannedOwner[];
78
+ documents: PlannedDocument[];
79
+ profileLimits: PlannedProfileLimits[];
80
+ blockers: ImportBlocker[];
81
+ report: ImportReport;
82
+ }
83
+ export interface PlanContext {
84
+ roots: LegacyRoots;
85
+ /** Ids in `on-disk-migrations.json`, or null when it is absent. */
86
+ markerIds: string[] | null;
87
+ /** Repo identity of a git checkout root (repo-sync `identifyCheckout`). */
88
+ repoIdentity: (root: string) => CheckoutIdentity;
89
+ /** Owner objects already in canvas.db; a new handle must not take one of theirs. */
90
+ existingOwners: Array<{
91
+ type: string;
92
+ handle: string;
93
+ externalId: string | null;
94
+ }>;
95
+ /** Stored profile rows (scoped-state) with their current `delivery_limits`. */
96
+ storedProfiles: Array<{
97
+ id: string;
98
+ deliveryLimits: Record<string, string>;
99
+ }>;
100
+ home?: string;
101
+ }
102
+ export declare function planImport(corpus: LegacyCorpus, ctx: PlanContext): ImportPlan;
@@ -0,0 +1,3 @@
1
+ var ae=Object.defineProperty;var c=(o,a)=>ae(o,"name",{value:a,configurable:!0});import{realpathSync as de}from"node:fs";import{homedir as pe}from"node:os";import{isAbsolute as le,join as ce,relative as fe}from"node:path";import{parseFrontmatterGeneric as he}from"../../core/frontmatter.js";import{handleHint as me}from"../../core/graph/repo-sync/identity.js";import{andIntoRules as ue,documentFields as ye}from"./fields.js";import{rewritePointers as we}from"./pointers.js";const $e=["001-surfaces-frontmatter","002-profile-project-memory","003-repository-root-memory-identity"],U=["none","name","preview","content"];function O(o){try{return de(o)}catch{return o}}c(O,"real");const X=c(o=>o.replace(/^app:/,""),"appHandle");function Re(o,a){const v=[],m={},d=c((e,n=1)=>{m[e]=(m[e]??0)+n},"count"),p=[],u=[],g=[],l=c(e=>{g.push(e),d(`resolutions.${e.kind}`)},"resolve");o.docs.length>0&&[...a.markerIds??[]].sort().join(`
2
+ `)!==[...$e].sort().join(`
3
+ `)&&v.push({kind:"marker",paths:[],message:`this runtime skipped the store migrations of the previous release (on-disk-migrations.json lists ${a.markerIds===null?"nothing":JSON.stringify(a.markerIds)}); start the previous crtr release once, then upgrade`});for(const e of o.docs)e.invalid!==void 0&&l({kind:e.invalid.kind,paths:[e.path],message:e.invalid.kind==="invalid-source"?`${e.path}: ${e.invalid.reason} \u2014 imported the whole file as the body, with no rules`:`${e.path}: ${e.invalid.reason} \u2014 imported the current file without its history`});const k=new Map,G=new Map,x=c((e,n)=>G.get(`${e}\0${n}`),"held"),S=c((e,n,t)=>{G.set(`${e}\0${n}`,t)},"hold"),Y=c(e=>e.type==="repo"&&e.externalId!==null?`repo:${e.externalId}`:e.type==="person"?"person":e.type==="profile"&&e.externalId!==null?`profile:${e.externalId}`:`${e.type}:${e.handle}`,"keyOfExisting");for(const e of a.existingOwners)S(e.type,e.handle,Y(e));const W=c((e,n)=>{let t=2;for(;x(e,`${n}-${t}`)!==void 0;)t+=1;return`${n}-${t}`},"freeHandle"),M=c(e=>{const n=k.get(e.key);if(n!==void 0)return n;const t=x(e.type,e.handle),r=t!==void 0&&t!==e.key?W(e.type,e.handle):e.handle,s={...e,handle:r};return S(s.type,r,s.key),k.set(s.key,s),s},"claim");for(const e of a.existingOwners)e.type==="person"&&k.set("person",{key:"person",type:"person",handle:e.handle});const z=M({key:"person",type:"person",handle:"user"}),Z=new Map(a.roots.profiles.map(e=>[e.id,e])),ee=new Set(a.roots.nodes.map(e=>e.id)),te=new Map(a.roots.nodes.map(e=>[e.id,e.dir])),C=new Map;for(const e of[...a.roots.profiles].sort((n,t)=>n.id.localeCompare(t.id))){const n=x("profile",e.name);if(n===void 0||n===`profile:${e.id}`){C.set(e.id,e.name),S("profile",e.name,`profile:${e.id}`);continue}const t=x("profile",e.id)===void 0?e.id:W("profile",e.id);C.set(e.id,t),S("profile",t,`profile:${e.id}`),l({kind:"profile-handle",paths:e.manifestPath===void 0?[]:[e.manifestPath],message:`profile ${e.id} shares the name \`${e.name}\` with ${n}; it takes the handle \`${t}\``})}const N=new Map,E=new Map,B=c((e,n)=>{if(E.has(e.root))return;const t=e.commonDir===null?{ok:!1,code:"not-a-repo",dir:e.root,reason:"no .git"}:a.repoIdentity(e.root);let r="local-path",s=O(e.root),i=me(s);t.ok?(r=t.scheme,s=t.externalId,i=t.handleHint):t.code!=="not-a-repo"&&l({kind:"repo-identity",paths:n,message:`${e.root}: repo identity lookup failed (${t.code}: ${t.reason}); imported as the local-path repo ${s}`});const f=`repo:${s}`;E.set(e.root,f);const h=a.existingOwners.find(y=>y.type==="repo"&&y.externalId===s),w=N.get(f);w!==void 0?w.roots.push(e.root):N.set(f,{key:f,scheme:r,externalId:s,wanted:h?.handle??e.namespace??i,roots:[e.root]})},"identify");for(const e of o.storeRoots)e.owner.type==="repo"&&e.skipped===void 0&&B(e.owner,[e.root]);for(const e of o.docs)e.owner.type==="repo"&&B(e.owner,[e.path]);const J=new Map,K=new Map;for(const e of N.values())K.set(e.wanted,[...K.get(e.wanted)??[],e]);for(const[e,n]of[...K].sort(([t],[r])=>t.localeCompare(r))){const t=c(r=>x("repo",e)===r.key?0:r.scheme==="git"?1:2,"rank");n.sort((r,s)=>t(r)-t(s)||r.externalId.localeCompare(s.externalId));for(const r of n){const s=M({key:r.key,type:"repo",handle:e,scheme:r.scheme,externalId:r.externalId});s.handle!==e&&(J.set(r.key,{from:e,to:s.handle}),l({kind:"repo-handle",paths:r.roots,message:`repo ${r.externalId} (${r.roots.join(", ")}) wanted the handle \`${e}\`, held by ${x("repo",e)}; it takes \`${s.handle}\` and its documents' \`[[${e}/\u2026]]\` links are rewritten to match`}))}}const P=new Map;for(const[e,n]of E)P.set(e,k.get(n));const ne=c(e=>P.get(e.root),"repoOwner"),oe=c(e=>{const n=Z.get(e),t=M({key:`app:${X(n?.app??"app:terminal")}`,type:"app",handle:X(n?.app??"app:terminal")});return M({key:`profile:${e}`,type:"profile",handle:C.get(e)??n?.name??e,ownerKey:t.key})},"profileOwner"),re=c(e=>{switch(e.owner.type){case"person":return z;case"profile":return oe(e.owner.id);case"repo":return ne(e.owner);case"node":return M({key:`node:${e.owner.id}`,type:"node",handle:e.owner.id})}},"ownerFor"),R=new Map;for(const e of o.docs)e.owner.type==="repo"&&e.mtime>(R.get(e.owner.root)??"")&&R.set(e.owner.root,e.mtime);const D=new Map;for(const[e,n]of P){const t=D.get(n.key);(t===void 0||(R.get(e)??"")>(R.get(t)??""))&&D.set(n.key,e)}const A=[...o.skipped],T=new Set,H=[],j=new Map;for(const e of o.docs){const n=re(e);if(e.owner.type==="repo"&&D.get(n.key)!==e.owner.root){T.has(e.owner.root)||(T.add(e.owner.root),A.push({path:e.owner.root,reason:`duplicate-clone: ${n.handle} imports from ${D.get(n.key)}`})),d("documents.duplicate-clone");continue}let t=n.key,r=e.name;const s=e.source==="report",i=ye(e.invalid?.kind==="invalid-source"?null:e.frontmatter,e.body,{...s?{kind:"report"}:{},missingPrivacy:n.type==="repo"?"public":"private"});for(const $ of i.dropped)p.push({path:e.path,field:$});let f=i.rules,h=i.preview;e.source==="context"&&r==="roadmap"&&(f=[...f,{on:"boot",deliver:"content"}],h=h||`The roadmap of node ${n.handle}`),h.trim()===""&&(h=e.name,l({kind:"empty-preview",paths:[e.path],message:`${e.path} has no text to preview; its preview is its name, ${e.name}`})),n.type==="repo"&&i.privacy!=="public"&&(f=ue(f,{repo:n.handle}),t=z.key,r=`${n.handle}/${r}`,d("documents.private-repo-to-person"));const w=ke(e,ee,l),y=k.get(t).handle,b={doc:e,qualified:`${y}/${r}`,contextDir:e.owner.type==="node"?ce(te.get(e.owner.id)??"","context"):null,repoKey:e.owner.type==="repo"?n.key:null,planned:{ownerKey:t,name:r,kind:i.kind,privacy:i.privacy,preview:h,summary:i.summary,whyItExists:i.whyItExists,unlisted:i.unlisted,lintIgnore:i.lintIgnore,extensions:i.extensions,rules:f,revisions:w,sourcePath:e.path}},_=`${t}\0${r}`,I=j.get(_);if(I!==void 0){const $=I.doc.mtime<=e.mtime?I:b;let L=1;for(;j.has(`${t}\0${r}.conflict-${L}`);)L+=1;$.planned.name=`${r}.conflict-${L}`,$.qualified=`${y}/${$.planned.name}`,j.set(`${t}\0${$.planned.name}`,$),j.set(_,$===I?b:I),l({kind:"name-clash",paths:[I.doc.path,e.path],message:`${I.doc.path} and ${e.path} both import as \`${y}/${r}\`; the newer keeps the name and ${$.doc.path} imports as \`${$.planned.name}\``})}else j.set(_,b);H.push(b),d(`documents.${i.kind}`),d(`documents.owner.${k.get(t).type}`),d("revisions",w.length)}const q=new Map,V=new Set,Q=new Set;for(const e of H){q.set(e.doc.path,e.qualified),q.set(O(e.doc.path),e.qualified),e.doc.source==="report"&&V.add(e.qualified);const n=k.get(e.planned.ownerKey);e.planned.name==="index"&&n.type!=="node"&&Q.add(n.handle)}const ie={byPath:q,reports:V,indexHandles:Q,home:a.home??pe(),real:O};for(const e of H){const n=e.planned.revisions[e.planned.revisions.length-1],t=we(n.body,ie,{contextDir:e.contextDir}),r=e.repoKey===null?void 0:J.get(e.repoKey);if(r!==void 0){const s=`[[${r.from}/`,i=`[[${r.to}/`;t.body.includes(s)&&(t.body=t.body.split(s).join(i),t.rewrites.push({from:s,to:i}))}if(t.rewrites.length!==0){n.body=t.body;for(const s of t.rewrites)u.push({path:e.doc.path,...s});d("documents.rewritten")}}const F=[],se=new Map(a.storedProfiles.map(e=>[e.id,e.deliveryLimits]));for(const e of a.roots.profiles){if(e.raw===void 0||e.manifestPath===void 0)continue;const n=Array.isArray(e.raw.projects)?e.raw.projects:[];if(!n.some(i=>i!==null&&typeof i=="object"&&"memory"in i))continue;const t=se.get(e.id);if(t===void 0){A.push({path:e.manifestPath,reason:`profile-not-stored: profile ${e.id} has a manifest but no stored profile row; its memory caps are not carried over`});continue}const r={...t},s=new Map;n.forEach(i=>{if(i===null||typeof i!="object"||!("memory"in i))return i;const{memory:f,...h}=i;if(f==="content"||typeof h.path!="string")return h;const w=ge(h.path,a,P);if(w===null)return A.push({path:e.manifestPath,reason:`delivery-limit-dropped: project ${h.path} (memory ${String(f)}) is in no repo and has no project store`}),h;const y=r[w];if(y!==void 0&&y!==f){const b=U.indexOf(String(f))>U.indexOf(y)?String(f):y;if(l({kind:"delivery-limit",paths:[e.manifestPath],message:`profile ${e.name}: ${s.get(w)??"delivery_limits"} and ${h.path} both map to repo \`${w}\` with different memory caps (${y}, ${String(f)}); kept the larger, ${b}`}),b===y)return h}return r[w]=String(f),s.set(w,h.path),h}),Object.keys(r).some(i=>r[i]!==t[i])&&F.push({profileId:e.id,deliveryLimits:r})}return d("profile-limits",F.length),m.stores=o.storeRoots.filter(e=>e.skipped===void 0).length,m["stores.duplicate-worktree"]=o.storeRoots.filter(e=>e.skipped!==void 0).length,m.owners=k.size,m["orphan-history"]=o.orphanHistory,m["orphan-node-dirs"]=o.orphanNodeDirs,m["non-markdown"]=o.nonMarkdown,m["exposure-ledgers-not-imported"]=o.injectedDocs,{owners:[...k.values()],documents:H.map(e=>e.planned),profileLimits:F,blockers:v,report:{stores:o.storeRoots,counts:m,rewrites:u,droppedFields:p,skipped:A,resolutions:g}}}c(Re,"planImport");function ge(o,a,v){const m=O(o);let d=null;for(const[u,g]of v){const l=fe(O(u),m);(l===""||!l.startsWith("..")&&!le(l))&&(d===null||u.length>d.root.length)&&(d={root:u,owner:g})}const p=a.repoIdentity(m);if(p.ok){const u=[...v.values()].find(l=>l.externalId===p.externalId);return u?u.handle:a.existingOwners.find(l=>l.type==="repo"&&l.externalId===p.externalId)?.handle??p.handleHint}return d?.owner.handle??null}c(ge,"projectHandle");function ke(o,a,v){const m=c(p=>typeof p=="string"&&a.has(p)?p:null,"author");if(o.source!=="store")return[{body:o.body,authorNodeId:o.owner.type==="node"&&a.has(o.owner.id)?o.owner.id:null,rationale:null,createdAt:o.mtime}];const d=[];for(const p of o.history){if(p.op!=="create"&&p.op!=="edit"&&p.op!=="move")continue;let u;try{u=he(p.after).body}catch(g){return v({kind:"invalid-history",paths:[o.path],message:`${o.path}: history record at ${p.at} has invalid frontmatter (${g.message}); imported the current file without its history`}),[{body:o.body,authorNodeId:null,rationale:null,createdAt:o.mtime}]}d.length>0&&d[d.length-1].body===u||d.push({body:u,authorNodeId:m(p.node),rationale:p.rationale??null,createdAt:p.at})}if(d.length===0){const p=o.frontmatter?.origin??{},u=c(l=>typeof l=="string"?l:l instanceof Date?l.toISOString():null,"stamp"),g=u(p.created)??u(o.frontmatter?.["last-updated"])??o.mtime;return[{body:o.body,authorNodeId:m(p.node),rationale:null,createdAt:g}]}return d[d.length-1].body!==o.body&&d.push({body:o.body,authorNodeId:null,rationale:"changed outside crtr before import",createdAt:o.mtime}),d}c(ke,"revisionsOf");export{$e as CONVERGED_MARKER_IDS,Re as planImport};
@@ -0,0 +1,23 @@
1
+ export interface PointerTargets {
2
+ /** Absolute file path (as read and realpath) → qualified document name. */
3
+ byPath: ReadonlyMap<string, string>;
4
+ /** `<node-id>/reports/<stem>` of every imported report. */
5
+ reports: ReadonlySet<string>;
6
+ /** Owner handles that have an imported `index` document. */
7
+ indexHandles: ReadonlySet<string>;
8
+ home: string;
9
+ /** Resolve symlinks of a path that is not in `byPath` as written; returns the input when it does not exist. */
10
+ real: (path: string) => string;
11
+ }
12
+ export interface PointerContext {
13
+ /** The node folder's `context/` dir when the document is owned by a node (for `$CRTR_CONTEXT_DIR/…`). */
14
+ contextDir: string | null;
15
+ }
16
+ /** Rewrite one head body; `rewrites` receives every replacement made. */
17
+ export declare function rewritePointers(body: string, t: PointerTargets, ctx: PointerContext): {
18
+ body: string;
19
+ rewrites: Array<{
20
+ from: string;
21
+ to: string;
22
+ }>;
23
+ };
@@ -0,0 +1,4 @@
1
+ var T=Object.defineProperty;var f=(s,t)=>T(s,"name",{value:t,configurable:!0});import{join as a}from"node:path";const _=/(?<![\w./$-])((?:~|\$CRTR_CONTEXT_DIR|\$\{CRTR_CONTEXT_DIR\})?\/[^\s()[\]<>`'"]*?\.md)(?![\w-]|\.[\w-])/g,m=/(?<![\w/-])([a-z0-9]+(?:-[a-z0-9]+)+):reports\/([A-Za-z0-9._-]+?)(?:\.md)?(?![\w-]|\.[\w-])/g,g=/\[\[([^\]|#/\s]+)((?:[|#][^\]]*)?)\]\]/g;function R(s,t,l){let r;if(s.startsWith("~/"))r=a(t.home,s.slice(2));else if(s.startsWith("$")){if(l.contextDir===null)return null;r=a(l.contextDir,s.slice(s.indexOf("/")+1))}else r=s;return t.byPath.get(r)??t.byPath.get(t.real(r))??null}f(R,"resolvePointer");function $(s,t,l){const r=`${s}/reports/${t}`;return l.reports.has(r)?r:null}f($,"resolveReport");function d(s,t,l,r){const c=f((e,n)=>n===null?e:(r.push({from:e,to:`[[${n}]]`}),`[[${n}]]`),"sub");return s.replace(_,(e,n)=>c(e,R(n,t,l))).replace(m,(e,n,u)=>c(e,$(n,u,t))).replace(g,(e,n,u)=>{if(!t.indexHandles.has(n))return e;const o=`[[${n}/index${u}]]`;return r.push({from:e,to:o}),o})}f(d,"rewriteText");function x(s,t,l,r,c){const e=t.trim(),n=/^([a-z0-9]+(?:-[a-z0-9]+)+):reports\/([A-Za-z0-9._-]+?)(?:\.md)?$/.exec(e),u=n!==null?$(n[1],n[2],l):/^(?:~|\$CRTR_CONTEXT_DIR|\$\{CRTR_CONTEXT_DIR\})?\/\S*\.md$/.test(e)?R(e,l,r):null;return u===null?s:(c.push({from:s,to:`[[${u}]]`}),`[[${u}]]`)}f(x,"rewriteCodeSpan");function D(s,t,l){const r=[],c=[];let e=null,n=[];const u=f(()=>{if(n.length===0)return;const o=n.join(`
2
+ `),i=[];let h=0;for(const p of o.matchAll(/(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/g))i.push(d(o.slice(h,p.index),t,l,r)),i.push(x(p[0],p[2],t,l,r)),h=p.index+p[0].length;i.push(d(o.slice(h),t,l,r)),c.push(i.join("")),n=[]},"flush");for(const o of s.split(`
3
+ `)){const i=/^\s*(`{3,}|~{3,})/.exec(o)?.[1];e===null&&i!==void 0?(u(),e=i,c.push(o)):e!==null?(c.push(o),i!==void 0&&i[0]===e[0]&&i.length>=e.length&&o.trim()===i&&(e=null)):n.push(o)}return u(),{body:c.join(`
4
+ `),rewrites:r}}f(D,"rewritePointers");export{D as rewritePointers};
@@ -1,17 +1,7 @@
1
- import type { NodeMemoryTarget } from '../core/canvas/types.js';
2
- import { runOnDiskMigrations, type OnDiskMigrationRunResult } from './runner.js';
3
- export type OnDiskMigrationRunner = typeof runOnDiskMigrations;
4
- interface CoordinationOptions {
5
- timeoutMs?: number;
6
- runner?: OnDiskMigrationRunner;
7
- nodes: readonly NodeMemoryTarget[];
8
- }
9
- export interface ForcedMigrationOptions extends CoordinationOptions {
10
- dryRun?: boolean;
11
- explicitDirs?: readonly string[];
12
- }
1
+ import { type CanvasImportResult } from './004-canvas-documents/index.js';
2
+ export type { CanvasImportResult } from './004-canvas-documents/index.js';
13
3
  /** A migration blocker is a STANDING condition, not a transient fault: the same
14
- * corpus produces the same blockers on every boot, so a caller that retries a
4
+ * stores produce the same blockers on every boot, so a caller that retries a
15
5
  * daemon start against one retries forever. Typing it lets the startup path
16
6
  * tell "try again" apart from "this needs a human", and carry the repair line
17
7
  * to whoever can act on it. */
@@ -19,8 +9,9 @@ export declare class MigrationBlockedError extends Error {
19
9
  readonly blockerPaths: readonly string[];
20
10
  constructor(message: string, blockerPaths: readonly string[]);
21
11
  }
22
- /** Run startup migration only when this home lacks the current completion marker. */
23
- export declare function activateOnDiskMigrations(options: CoordinationOptions): Promise<OnDiskMigrationRunResult | null>;
24
- /** Run migrations regardless of the marker; dry runs leave marker state untouched. */
25
- export declare function runForcedOnDiskMigrations(options: ForcedMigrationOptions): Promise<OnDiskMigrationRunResult>;
26
- export {};
12
+ /** Startup: import the legacy stores unless already recorded. Throws `MigrationBlockedError` when the plan has blockers. */
13
+ export declare function activateCanvasImport(): Promise<CanvasImportResult | null>;
14
+ /** `crtr sys migrate`: plan (and unless `dryRun`, apply) regardless of startup state. */
15
+ export declare function runForcedCanvasImport(opts: {
16
+ dryRun: boolean;
17
+ }): Promise<CanvasImportResult>;
@@ -1,2 +1,2 @@
1
- var f=Object.defineProperty;var t=(r,i)=>f(r,"name",{value:i,configurable:!0});import{mkdirSync as d,rmSync as m}from"node:fs";import{dirname as p}from"node:path";import{onDiskMigrationLockPath as l,onDiskMigrationMarkerPath as s}from"../core/canvas/paths.js";import{withExclusiveDirectoryLockAsync as k}from"../core/exclusive-lock.js";import{DAEMON_STARTUP_WINDOW_MS as g}from"../daemon/startup-policy.js";import{atomicWriteJson as h,readJsonOrNull as w}from"../core/fs-utils.js";import{onDiskMigrationIdentity as a}from"./registry.js";import{runOnDiskMigrations as y}from"./runner.js";function M(){const r=w(s());return JSON.stringify(r)===JSON.stringify(a())}t(M,"markerIsCurrent");function D(){h(s(),a())}t(D,"writeCurrentMarker");function E(r){return[...new Set(r.blockers.flatMap(i=>[...i.path===void 0?[]:[i.path],...i.paths??[],...i.storeRoot===void 0?[]:[i.storeRoot]]))]}t(E,"blockerPaths");class S extends Error{static{t(this,"MigrationBlockedError")}blockerPaths;constructor(i,o){super(i),this.name="MigrationBlockedError",this.blockerPaths=o}}function v(r){const i=E(r),o=r.blockers.map(c=>`${c.kind}: ${c.message}`),e=[...r.wrote.profileManifests,...r.wrote.documents,...r.wrote.corpusConsumers,...r.wrote.corpusIdentities],n=r.blockers.length>0?[`on-disk migration blocked by ${r.blockers.length} finding(s)`,...o]:["on-disk migration did not complete final verification"];return i.length>0&&n.push(`Blocker paths: ${i.join(", ")}`),e.length>0&&n.push(`Writes completed before failure: ${e.join(", ")}`),n.push("Repair: crtr sys migrate"),new S(n.join(`
2
- `),i)}t(v,"activationError");async function u(r,i){const o=l();return d(p(o),{recursive:!0,mode:448}),k(o,async()=>{if(r==="activation"&&M())return null;const e=i.dryRun===!0;e||m(s(),{force:!0});const n=await(i.runner??y)({dryRun:e,explicitDirs:i.explicitDirs,nodes:i.nodes});if(!e&&n.finalVerificationSucceeded&&D(),r==="activation"&&!n.finalVerificationSucceeded)throw v(n);return n},{timeoutMs:i.timeoutMs??g,timeoutError:t(()=>new Error(`timed out waiting for on-disk migration lock: ${o}`),"timeoutError")})}t(u,"coordinate");async function W(r){return u("activation",r)}t(W,"activateOnDiskMigrations");async function j(r){const i=await u("forced",r);if(i===null)throw new Error("forced on-disk migration unexpectedly skipped");return i}t(j,"runForcedOnDiskMigrations");export{S as MigrationBlockedError,W as activateOnDiskMigrations,j as runForcedOnDiskMigrations};
1
+ var a=Object.defineProperty;var o=(r,t)=>a(r,"name",{value:t,configurable:!0});import{mkdirSync as c}from"node:fs";import{dirname as m}from"node:path";import{onDiskMigrationLockPath as u}from"../core/canvas/paths.js";import{withExclusiveDirectoryLockAsync as p}from"../core/exclusive-lock.js";import{DAEMON_STARTUP_WINDOW_MS as l}from"../daemon/startup-policy.js";import{canvasImportDone as h,runCanvasImport as s}from"./004-canvas-documents/index.js";class d extends Error{static{o(this,"MigrationBlockedError")}blockerPaths;constructor(t,n){super(t),this.name="MigrationBlockedError",this.blockerPaths=n}}function i(r){const t=u();return c(m(t),{recursive:!0,mode:448}),p(t,async()=>r(),{timeoutMs:l,timeoutError:o(()=>new Error(`timed out waiting for the canvas import lock: ${t}`),"timeoutError")})}o(i,"coordinate");async function M(){return i(()=>{if(h())return null;const r=s({dryRun:!1});if(r.blockers.length>0){const t=[...new Set(r.blockers.flatMap(e=>e.paths))],n=[`canvas import (004-canvas-documents) blocked by ${r.blockers.length} finding(s)`,...r.blockers.map(e=>`${e.kind}: ${e.message}`)];throw n.push("Repair each finding, then: crtr sys migrate --dry-run, then crtr sys migrate"),new d(n.join(`
2
+ `),t)}return r})}o(M,"activateCanvasImport");async function w(r){return i(()=>s(r))}o(w,"runForcedCanvasImport");export{d as MigrationBlockedError,M as activateCanvasImport,w as runForcedCanvasImport};
@@ -1,8 +1,8 @@
1
1
  /** Persist a bare root's first real interactive message without clobbering an
2
2
  * existing spawning mandate. This is broker-local file state, not canvas.db. */
3
3
  export declare function captureGoalIfAbsent(nodeId: string, text: string): boolean;
4
- /** Read the node-owned roadmap without importing the canvas state store. */
5
- export declare function readRoadmap(nodeId: string): string | null;
4
+ /** The node's `roadmap` document body, read through crtrd (`/v1`), or null. */
5
+ export declare function readRoadmap(nodeId: string): Promise<string | null>;
6
6
  /** Generate and commit the first name for a node. The initial operation is
7
7
  * guarded by crtrd, so a concurrent rename or another broker cannot be
8
8
  * overwritten after this projection becomes stale. */
@@ -1,2 +1,2 @@
1
- var s=Object.defineProperty;var o=(i,e)=>s(i,"name",{value:e,configurable:!0});import{existsSync as d,mkdirSync as b,readFileSync as c,writeFileSync as h}from"node:fs";import{join as p}from"node:path";import{contextDir as f}from"../core/canvas/paths.js";import{brokerExtensionState as N,commitBrokerGeneratedName as u}from"../core/runtime/broker/daemon-ops.js";import{publishNodeNamed as x}from"../core/runtime/broker/node-named.js";import{headlessName as y,headlessNameFromConversation as L,sanitizeSessionName as S,sanitizeSessionTitle as k,slugFromPrompt as F,titleFromPrompt as v}from"../core/runtime/naming.js";function j(i,e){const r=f(i),n=p(r,"initial-prompt.md");if(d(n)&&c(n,"utf8").trim()!=="")return!1;const t=e.trim();return t===""?!1:(b(r,{recursive:!0}),h(n,`${t}
2
- `,"utf8"),!0)}o(j,"captureGoalIfAbsent");function w(i){const e=p(f(i),"roadmap.md");return d(e)?c(e,"utf8"):null}o(w,"readRoadmap");function l(i,e){return{description:S(e.name)||F(i),title:k(e.title)||v(i),icon:e.icon}}o(l,"generatedLabel");function B(i,e,r){const n=e.trim();n!==""&&N(i).then(t=>{if((t.node.description??"").trim()==="")return y(n).then(a=>u(i,{kind:"initial",...l(n,a)}))}).then(t=>{!t?.applied||t.editorLabel===void 0||(x({description:t.description??"",title:t.title??"",icon:t.icon??"",editorLabel:t.editorLabel}),r?.(t.editorLabel))}).catch(()=>{})}o(B,"generateAndCommitInitialName");function D(i,e,r,n,t){const a=e.trim();a!==""&&L(a).then(m=>{if(n())return u(i,{kind:"recap",...l(a,m),expected:r})}).then(m=>{m?.applied&&m.editorLabel!==void 0&&t?.(m.editorLabel)}).catch(()=>{})}o(D,"generateAndCommitRecapName");export{j as captureGoalIfAbsent,B as generateAndCommitInitialName,D as generateAndCommitRecapName,w as readRoadmap};
1
+ var f=Object.defineProperty;var o=(i,t)=>f(i,"name",{value:t,configurable:!0});import{existsSync as s,mkdirSync as u,readFileSync as l,writeFileSync as b}from"node:fs";import{join as h}from"node:path";import{contextDir as y}from"../core/canvas/paths.js";import{brokerExtensionState as d,commitBrokerGeneratedName as c}from"../core/runtime/broker/daemon-ops.js";import{publishNodeNamed as N}from"../core/runtime/broker/node-named.js";import{headlessName as x,headlessNameFromConversation as L,sanitizeSessionName as S,sanitizeSessionTitle as k,slugFromPrompt as F,titleFromPrompt as v}from"../core/runtime/naming.js";function R(i,t){const r=y(i),n=h(r,"initial-prompt.md");if(s(n)&&l(n,"utf8").trim()!=="")return!1;const e=t.trim();return e===""?!1:(u(r,{recursive:!0}),b(n,`${e}
2
+ `,"utf8"),!0)}o(R,"captureGoalIfAbsent");async function j(i){return(await d(i)).roadmap}o(j,"readRoadmap");function p(i,t){return{description:S(t.name)||F(i),title:k(t.title)||v(i),icon:t.icon}}o(p,"generatedLabel");function B(i,t,r){const n=t.trim();n!==""&&d(i).then(e=>{if((e.node.description??"").trim()==="")return x(n).then(a=>c(i,{kind:"initial",...p(n,a)}))}).then(e=>{!e?.applied||e.editorLabel===void 0||(N({description:e.description??"",title:e.title??"",icon:e.icon??"",editorLabel:e.editorLabel}),r?.(e.editorLabel))}).catch(()=>{})}o(B,"generateAndCommitInitialName");function D(i,t,r,n,e){const a=t.trim();a!==""&&L(a).then(m=>{if(n())return c(i,{kind:"recap",...p(a,m),expected:r})}).then(m=>{m?.applied&&m.editorLabel!==void 0&&e?.(m.editorLabel)}).catch(()=>{})}o(D,"generateAndCommitRecapName");export{R as captureGoalIfAbsent,B as generateAndCommitInitialName,D as generateAndCommitRecapName,j as readRoadmap};
@@ -1,4 +1,5 @@
1
- var te=Object.defineProperty;var o=(r,n)=>te(r,"name",{value:n,configurable:!0});import{envBashAutoBgDeadlineMs as oe,envBashValveMs as ie,envNodeId as se}from"../shared/env.js";import{spawn as de}from"node:child_process";import{closeSync as ae,existsSync as B,mkdirSync as G,openSync as ce,readFileSync as ue,readSync as fe,rmSync as V,statSync as K,writeFileSync as y}from"node:fs";import{homedir as le}from"node:os";import{dirname as be}from"node:path";import{performance as O}from"node:perf_hooks";import{backgroundBashJob as z,bashJobPaths as pe,cancelBashJobProcessTree as he,formatBashElapsed as q,newBashJobId as me,normalizeBashJobPurpose as ge,readBashNiceness as we,writeJobDeadlineMs as ye}from"../core/bash-jobs.js";import{BASH_JOB_SUPERVISOR_SCRIPT as Se}from"../core/bash-job-supervisor.js";import{MAX_BACKGROUND_BASH_LOG_BYTES as ir,BACKGROUND_BASH_LOG_TRUNCATION_MARKER as sr}from"../core/bash-job-supervisor.js";import{startBrokerBashJob as Ee,stopBrokerBashJob as ve}from"../core/runtime/broker/daemon-ops.js";import{bashCommandRefusal as Be}from"../core/bash-guard.js";import{capturePidIdentities as Ie}from"../core/canvas/pid.js";import{readConfig as je}from"../core/config.js";import{PREVIEW_RESULT_PATH_ENV as _e,previewResultPath as Re}from"../core/preview-result-path.js";import{resolveAdmittedHostCommand as ke}from"../core/runtime/spawn-env.js";import{Type as P}from"typebox";import{createBashToolDefinition as W}from"@earendil-works/pi-coding-agent";const Le=200;function xe(){return ie()}o(xe,"resolveValveMs");function Te(r){return pe(r,me())}o(Te,"makeJobPaths");const I=new Set;let X=!1;function Y(){for(const r of[...I])try{z(r),I.delete(r)}catch(n){process.stderr.write(`crtr: failed to background bash job ${r.jobId} during broker termination: ${n.message}
2
- `)}}o(Y,"backgroundLiveJobsForTermination");function Ae(){X||(X=!0,process.prependListener("SIGTERM",Y),process.platform!=="win32"&&process.prependListener("SIGHUP",Y))}o(Ae,"installTerminationHandoff");const Oe=64*1024;function C(r,n,i){let s;try{s=K(r)}catch{return n}if(s.size<=n)return n;const c=ce(r,"r");try{for(;n<s.size;){const m=Math.min(Oe,s.size-n),f=Buffer.allocUnsafe(m),d=fe(c,f,0,m,n);if(d===0)break;i(f.subarray(0,d)),n+=d}return n}finally{ae(c)}}o(C,"tailOnce");function h(r){try{V(r,{recursive:!0,force:!0})}catch{}}o(h,"cleanupJobDir");function Pe(r){try{const n=ue(r,"utf8").trim(),i=Number(n);return Number.isFinite(i)?i:null}catch{return null}}o(Pe,"readExitCode");function Ce(r){try{if(K(r).isDirectory())return{cwd:r}}catch{}const n=le();return{cwd:n,warning:`[working directory no longer exists: ${r}; running from ${n}]
3
- `}}o(Ce,"resolveExecutionCwd");function Q(r,n,i=()=>null,s){return{exec:o((c,m,{onData:f,signal:d,timeout:p,env:k})=>new Promise((j,a)=>{const _=i();if(d?.aborted){a(new Error("aborted"));return}const L=Be(c,m);if(L!==null){a(new Error(L));return}const e=Te(n);G(e.dir,{recursive:!0}),y(e.cmdSh,c),y(e.jobLog,""),y(e.jobRun,""),_!==null&&y(e.jobPurpose,_);let g=0,x=!1,u,w,S,$=!1;const J=process.platform==="linux",M=O.now(),Z=xe();let T;const ee=o(()=>{T&&clearInterval(T),d&&d.removeEventListener("abort",D),I.delete(e)},"teardown"),l=o(t=>{x||(x=!0,ee(),t())},"finish");function A(t=!1){const b=q(O.now()-M);let U="";if(t){const F=oe();ye(e,Date.now()+F),U=`It will be CANCELED in ${q(F)} unless you claim it: crtr node bash extend ${e.jobId} --for <duration> (or --keep to run to completion). `}const ne=`
4
- [backgrounded as job ${e.jobId} after ${b} in the foreground${t?" (auto)":""}. `+U+`It will interrupt you with a message when it exits. Watch: tail -f ${e.jobLog} ; stop: crtr node bash kill ${e.jobId}]`;f(Buffer.from(ne)),l(()=>j({exitCode:0}))}o(A,"finishBackground");function N(){g=C(e.jobLog,g,f);const t=Pe(e.jobExit);l(()=>j({exitCode:t})),h(e.dir)}o(N,"finishForeground");function re(t=!1){const b=z(e);if(b==="backgrounded"||b==="already-backgrounded"){A(t);return}if(b==="finished"){N();return}l(()=>a(new Error(`bash job ${e.jobId} disappeared before it could be backgrounded`))),h(e.dir)}o(re,"requestBackground");function R(t){if(!(x||$)){if(g=C(e.jobLog,g,f),B(e.jobBg)){A();return}if(!B(e.jobExit)){if(u===void 0){S??=t;return}if(J){$=!0,ve(r,e.jobId).then(()=>{l(()=>a(t)),h(e.dir)},b=>l(()=>a(b)));return}u!==void 0&&w!==void 0&&he(u,w),l(()=>a(t)),h(e.dir)}}}o(R,"requestStop");function D(){R(new Error("aborted"))}o(D,"onAbort"),d&&d.addEventListener("abort",D,{once:!0});const E=Ce(m);E.warning&&f(Buffer.from(E.warning));let v=k??process.env;s!==void 0&&(G(be(s),{recursive:!0}),V(s,{force:!0}),v={...v,[_e]:s});const H=ke("bash",v,E.cwd);if(J)Ee(r,{job_id:e.jobId,cwd:E.cwd,env:v}).then(({pid:t})=>{u=t,w=`launcher:${t}`,I.add(e),S!==void 0&&R(S)},t=>{l(()=>a(t)),h(e.dir)});else{const t=de(H,["-c",Se,"--",e.cmdSh,e.jobLog,e.jobExit,e.jobRun,e.jobDone,e.jobBg,e.jobId,r,H,String(we(n)),process.execPath,"direct"],{cwd:E.cwd,detached:!0,stdio:"ignore",env:v});if(t.on("error",b=>{l(()=>a(b)),h(e.dir)}),u=t.pid,u!==void 0){if(w=Ie([u])?.get(u),w===void 0){try{process.kill(-u,"SIGKILL")}catch{}l(()=>a(new Error(`bash job ${e.jobId} started without a process identity`))),h(e.dir);return}y(e.jobPgid,String(u)),y(e.jobPgidIdentity,w),I.add(e),S!==void 0&&R(S)}t.unref()}T=setInterval(()=>{if(g=C(e.jobLog,g,f),B(e.jobDone)){N();return}if(B(e.jobBg)){A();return}if(B(e.jobExit))return;const t=O.now()-M;if(p!==void 0&&p>0){t>=p*1e3&&R(new Error(`timeout:${p}`));return}t>=Z&&re(!0)},Le)}),"exec")}}o(Q,"createValveOperations");const $e=["One short clause naming what this step is FOR, in the words of the person you",'are working for \u2014 "Reading the Acme thread", not "Fetching emails" and never','"Running GMAIL_FETCH_EMAILS". A person reads this while the command runs; it',"is the only thing they see of this step. Under about eight words. Omit it for","steps that only touch your own scratch work."].join(" ");function Je(r){return{...r,parameters:P.Object({purpose:P.Optional(P.String({description:$e})),...r.parameters.properties})}}o(Je,"withPurpose");function Me(r,n,i,s){const c=W(i,{operations:Q(r,n)});return{...s?Je(c):c,execute:o((d,p,k,j,a)=>{const _=s?ge(p.purpose):null;return W(i,{operations:Q(r,n,()=>_,Re(d))}).execute(d,p,k,j,a)},"execute")}}o(Me,"createValveToolDefinition");function Ne(r){const n=se();if(n===void 0||n.trim()==="")return;const i=process.env.CRTR_CONTEXT_DIR;i===void 0||i.trim()===""||(Ae(),r.on("session_start",(s,c)=>{r.registerTool(Me(n,i,c.cwd,je("user").bash_tool_purpose))}))}o(Ne,"default");export{sr as BACKGROUND_BASH_LOG_TRUNCATION_MARKER,ir as MAX_BACKGROUND_BASH_LOG_BYTES,Q as createValveOperations,Me as createValveToolDefinition,Ne as default};
1
+ var de=Object.defineProperty;var o=(r,n)=>de(r,"name",{value:n,configurable:!0});import{envBashAutoBgDeadlineMs as ae,envBashValveMs as ce,envNodeId as ue}from"../shared/env.js";import{spawn as fe}from"node:child_process";import{closeSync as le,existsSync as j,mkdirSync as K,openSync as be,readFileSync as z,readSync as pe,rmSync as W,statSync as q,writeFileSync as y}from"node:fs";import{homedir as he}from"node:os";import{dirname as me}from"node:path";import{performance as A}from"node:perf_hooks";import{backgroundBashJob as X,bashJobPaths as ge,cancelBashJobProcessTree as we,formatBashElapsed as Y,newBashJobId as ye,normalizeBashJobPurpose as Se,readBashNiceness as ve,writeJobDeadlineMs as Ee}from"../core/bash-jobs.js";import{BASH_JOB_SUPERVISOR_SCRIPT as Ie}from"../core/bash-job-supervisor.js";import{MAX_BACKGROUND_BASH_LOG_BYTES as cr,BACKGROUND_BASH_LOG_TRUNCATION_MARKER as ur}from"../core/bash-job-supervisor.js";import{recordBackgroundedJob as je,startBrokerBashJob as Be,stopBrokerBashJob as _e}from"../core/runtime/broker/daemon-ops.js";import{bashCommandRefusal as ke}from"../core/bash-guard.js";import{capturePidIdentities as Re}from"../core/canvas/pid.js";import{readConfig as Le}from"../core/config.js";import{PREVIEW_RESULT_PATH_ENV as xe,previewResultPath as Te}from"../core/preview-result-path.js";import{resolveAdmittedHostCommand as Oe}from"../core/runtime/spawn-env.js";import{Type as P}from"typebox";import{createBashToolDefinition as Q}from"@earendil-works/pi-coding-agent";const Ae=200;function Pe(){return ce()}o(Pe,"resolveValveMs");function Ce(r){return ge(r,ye())}o(Ce,"makeJobPaths");const B=new Set;let Z=!1;function ee(){for(const r of[...B])try{X(r),B.delete(r)}catch(n){process.stderr.write(`crtr: failed to background bash job ${r.jobId} during broker termination: ${n.message}
2
+ `)}}o(ee,"backgroundLiveJobsForTermination");function $e(){Z||(Z=!0,process.prependListener("SIGTERM",ee),process.platform!=="win32"&&process.prependListener("SIGHUP",ee))}o($e,"installTerminationHandoff");const Je=64*1024;function C(r,n,i){let s;try{s=q(r)}catch{return n}if(s.size<=n)return n;const u=be(r,"r");try{for(;n<s.size;){const m=Math.min(Je,s.size-n),l=Buffer.allocUnsafe(m),d=pe(u,l,0,m,n);if(d===0)break;i(l.subarray(0,d)),n+=d}return n}finally{le(u)}}o(C,"tailOnce");function h(r){try{W(r,{recursive:!0,force:!0})}catch{}}o(h,"cleanupJobDir");function Ne(r){try{const n=z(r,"utf8").trim(),i=Number(n);return Number.isFinite(i)?i:null}catch{return null}}o(Ne,"readExitCode");function Me(r){try{if(q(r).isDirectory())return{cwd:r}}catch{}const n=he();return{cwd:n,warning:`[working directory no longer exists: ${r}; running from ${n}]
3
+ `}}o(Me,"resolveExecutionCwd");function re(r,n,i=()=>null,s){return{exec:o((u,m,{onData:l,signal:d,timeout:p,env:x})=>new Promise((_,c)=>{const k=i();if(d?.aborted){c(new Error("aborted"));return}const T=ke(u,m);if(T!==null){c(new Error(T));return}const e=Ce(n);K(e.dir,{recursive:!0}),y(e.cmdSh,u),y(e.jobLog,""),y(e.jobRun,""),k!==null&&y(e.jobPurpose,k);let g=0,R=!1,f,w,S,$=!1;const J=process.platform==="linux",N=A.now(),ne=Pe();let v;const te=o(()=>{v&&clearInterval(v),d&&d.removeEventListener("abort",U),B.delete(e)},"teardown"),b=o(t=>{R||(R=!0,te(),t())},"finish");let M=!1;function O(t=!1){R||M||(M=!0,v&&clearInterval(v),je(r,e.jobId,{command:z(e.cmdSh,"utf8"),job_dir:e.dir,log_path:e.jobLog}).then(()=>D(t,""),a=>D(t,`
4
+ [crtr could not record job ${e.jobId} (${a.message}); it will NOT message you when it exits. Watch its log.]`)))}o(O,"finishBackground");function D(t,a){const ie=Y(A.now()-N);let G="";if(t){const V=ae();Ee(e,Date.now()+V),G=`It will be CANCELED in ${Y(V)} unless you claim it: crtr node bash extend ${e.jobId} --for <duration> (or --keep to run to completion). `}const se=`
5
+ [backgrounded as job ${e.jobId} after ${ie} in the foreground${t?" (auto)":""}. `+G+(a===""?"It will interrupt you with a message when it exits. ":"")+`Watch: tail -f ${e.jobLog} ; stop: crtr node bash kill ${e.jobId}]`;l(Buffer.from(se+a)),b(()=>_({exitCode:0}))}o(D,"handOff");function H(){g=C(e.jobLog,g,l);const t=Ne(e.jobExit);b(()=>_({exitCode:t})),h(e.dir)}o(H,"finishForeground");function oe(t=!1){const a=X(e);if(a==="backgrounded"||a==="already-backgrounded"){O(t);return}if(a==="finished"){H();return}b(()=>c(new Error(`bash job ${e.jobId} disappeared before it could be backgrounded`))),h(e.dir)}o(oe,"requestBackground");function L(t){if(!(R||$)){if(g=C(e.jobLog,g,l),j(e.jobBg)){O();return}if(!j(e.jobExit)){if(f===void 0){S??=t;return}if(J){$=!0,_e(r,e.jobId).then(()=>{b(()=>c(t)),h(e.dir)},a=>b(()=>c(a)));return}f!==void 0&&w!==void 0&&we(f,w),b(()=>c(t)),h(e.dir)}}}o(L,"requestStop");function U(){L(new Error("aborted"))}o(U,"onAbort"),d&&d.addEventListener("abort",U,{once:!0});const E=Me(m);E.warning&&l(Buffer.from(E.warning));let I=x??process.env;s!==void 0&&(K(me(s),{recursive:!0}),W(s,{force:!0}),I={...I,[xe]:s});const F=Oe("bash",I,E.cwd);if(J)Be(r,{job_id:e.jobId,cwd:E.cwd,env:I}).then(({pid:t})=>{f=t,w=`launcher:${t}`,B.add(e),S!==void 0&&L(S)},t=>{b(()=>c(t)),h(e.dir)});else{const t=fe(F,["-c",Ie,"--",e.cmdSh,e.jobLog,e.jobExit,e.jobRun,e.jobDone,F,String(ve(n)),process.execPath],{cwd:E.cwd,detached:!0,stdio:"ignore",env:I});if(t.on("error",a=>{b(()=>c(a)),h(e.dir)}),f=t.pid,f!==void 0){if(w=Re([f])?.get(f),w===void 0){try{process.kill(-f,"SIGKILL")}catch{}b(()=>c(new Error(`bash job ${e.jobId} started without a process identity`))),h(e.dir);return}y(e.jobPgid,String(f)),y(e.jobPgidIdentity,w),B.add(e),S!==void 0&&L(S)}t.unref()}v=setInterval(()=>{if(g=C(e.jobLog,g,l),j(e.jobDone)){H();return}if(j(e.jobBg)){O();return}if(j(e.jobExit))return;const t=A.now()-N;if(p!==void 0&&p>0){t>=p*1e3&&L(new Error(`timeout:${p}`));return}t>=ne&&oe(!0)},Ae)}),"exec")}}o(re,"createValveOperations");const De=["One short clause naming what this step is FOR, in the words of the person you",'are working for \u2014 "Reading the Acme thread", not "Fetching emails" and never','"Running GMAIL_FETCH_EMAILS". A person reads this while the command runs; it',"is the only thing they see of this step. Under about eight words. Omit it for","steps that only touch your own scratch work."].join(" ");function He(r){return{...r,parameters:P.Object({purpose:P.Optional(P.String({description:De})),...r.parameters.properties})}}o(He,"withPurpose");function Ue(r,n,i,s){const u=Q(i,{operations:re(r,n)});return{...s?He(u):u,execute:o((d,p,x,_,c)=>{const k=s?Se(p.purpose):null;return Q(i,{operations:re(r,n,()=>k,Te(d))}).execute(d,p,x,_,c)},"execute")}}o(Ue,"createValveToolDefinition");function Fe(r){const n=ue();if(n===void 0||n.trim()==="")return;const i=process.env.CRTR_CONTEXT_DIR;i===void 0||i.trim()===""||($e(),r.on("session_start",(s,u)=>{r.registerTool(Ue(n,i,u.cwd,Le("user").bash_tool_purpose))}))}o(Fe,"default");export{ur as BACKGROUND_BASH_LOG_TRUNCATION_MARKER,cr as MAX_BACKGROUND_BASH_LOG_BYTES,re as createValveOperations,Ue as createValveToolDefinition,Fe as default};
@@ -1,2 +1,2 @@
1
- var C=Object.defineProperty;var s=(t,n)=>C(t,"name",{value:n,configurable:!0});import{envNodeId as y}from"../shared/env.js";import{CONTEXT_INTRO_CUSTOM_TYPE as c,formatCard as b}from"../shared/generated-context.js";import{brokerContext as p,brokerExtensionState as f,commitBrokerContext as T}from"../core/runtime/broker/daemon-ops.js";import{buildForkBearingsFromState as l}from"../core/runtime/broker-extension-render.js";import{acknowledgePersonaBaseline as h}from"../core/runtime/broker-persona-guidance.js";import{situationalContextEnvelope as x}from"../core/runtime/situational-context.js";import{clearSessionCache as I}from"../core/substrate/session-cache.js";async function A(t){return(await p(t,"baseline")).content}s(A,"buildContextIntro");async function j(t){const n=await f(t);return l(n,x(t)??"")}s(j,"buildForkContextIntro");function g(t){const n=t.content;return typeof n=="string"?n:Array.isArray(n)?n.filter(r=>typeof r?.text=="string").map(r=>r.text).join(`
2
- `):""}s(g,"entryText");function _(t){t.on("session_start",async(n,r)=>{const e=y();if(e===void 0||e.trim()==="")return;const m=n?.reason,a=await f(e);if(a.warm_spare||m==="new"&&a.node.parent===null)return;m==="new"&&I();const d=r.sessionManager.getBranch().filter(o=>o.type==="custom_message"&&o.customType===c);if(d.some(o=>o.details?.nodeId===e||g(o).includes(e)))return;const i=await p(e,d.length>0?"compact":"baseline"),w=i.compact?l(a,x(e)??""):i.content,u=b("bearings",{},w);if(t.sendMessage({customType:c,content:u,display:!0,details:{nodeId:e}}),!r.sessionManager.getBranch().some(o=>o.type==="custom_message"&&o.customType===c&&o.details?.nodeId===e&&g(o)===u))throw new Error(`Pi did not materialize the context baseline for ${e}`);await T(e,i.snapshot,i.loads),await h(a)})}s(_,"registerCanvasContextIntro");var z=_;export{c as CONTEXT_INTRO_CUSTOM_TYPE,A as buildContextIntro,j as buildForkContextIntro,z as default,_ as registerCanvasContextIntro};
1
+ var w=Object.defineProperty;var s=(t,e)=>w(t,"name",{value:e,configurable:!0});import{envNodeId as b}from"../shared/env.js";import{CONTEXT_INTRO_CUSTOM_TYPE as a,formatCard as C}from"../shared/generated-context.js";import{brokerDelivery as m,brokerExtensionState as f}from"../core/runtime/broker/daemon-ops.js";import{buildForkBearingsFromState as p}from"../core/runtime/broker-extension-render.js";import{acknowledgePersonaBaseline as T}from"../core/runtime/broker-persona-guidance.js";import{situationalContextEnvelope as l}from"../core/runtime/situational-context.js";async function O(t){return(await m(t,{activity:"boot"})).content}s(O,"buildContextIntro");async function P(t){const e=await f(t);return p(e,l(t)??"")}s(P,"buildForkContextIntro");function g(t){const e=t.content;return typeof e=="string"?e:Array.isArray(e)?e.filter(r=>typeof r?.text=="string").map(r=>r.text).join(`
2
+ `):""}s(g,"entryText");function v(t){t.on("session_start",async(e,r)=>{const n=b();if(n===void 0||n.trim()==="")return;const x=e?.reason,i=await f(n);if(i.warm_spare||x==="new"&&i.node.parent===null)return;const c=r.sessionManager.getBranch().filter(o=>o.type==="custom_message"&&o.customType===a);if(c.some(o=>o.details?.nodeId===n||g(o).includes(n)))return;const d=await m(n,{activity:"boot",inherited:c.length>0}),y=d.inherited===!0?p(i,l(n)??""):d.content,u=C("bearings",{},y);if(t.sendMessage({customType:a,content:u,display:!0,details:{nodeId:n}}),!r.sessionManager.getBranch().some(o=>o.type==="custom_message"&&o.customType===a&&o.details?.nodeId===n&&g(o)===u))throw new Error(`Pi did not materialize the context baseline for ${n}`);await T(i)})}s(v,"registerCanvasContextIntro");var S=v;export{a as CONTEXT_INTRO_CUSTOM_TYPE,O as buildContextIntro,P as buildForkContextIntro,S as default,v as registerCanvasContextIntro};
@@ -42,7 +42,6 @@ type ToolCallResultLike = {
42
42
  } | void;
43
43
  interface PiLike {
44
44
  on(event: 'before_agent_start', handler: (event: BeforeAgentStartEventLike) => BeforeAgentStartResultLike | void | Promise<BeforeAgentStartResultLike | void>): void;
45
- on(event: 'session_start', handler: (event: unknown, ctx: unknown) => void | Promise<void>): void;
46
45
  on(event: 'session_compact', handler: (event: unknown, ctx: unknown) => void | Promise<void>): void;
47
46
  on(event: 'turn_end', handler: (event: unknown, ctx: unknown) => void | Promise<void>): void;
48
47
  on(event: 'tool_call', handler: (event: ToolCallEventLike, ctx: unknown) => ToolCallResultLike | Promise<ToolCallResultLike>): void;