@north-light/crouter 0.3.227 → 0.3.228

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 (286) hide show
  1. package/dist/api/client.d.ts +5 -5
  2. package/dist/api/client.js +3 -3
  3. package/dist/api/dto/broker-ops.d.ts +8 -0
  4. package/dist/api/dto/memory.d.ts +8 -7
  5. package/dist/api/dto/memory.js +2 -2
  6. package/dist/builtin-memory/05-kinds/design/00-base.md +3 -4
  7. package/dist/builtin-memory/05-kinds/design/01-orchestrator.md +4 -3
  8. package/dist/builtin-memory/05-kinds/design/design-contract.md +3 -6
  9. package/dist/builtin-memory/05-kinds/plan/00-base.md +3 -4
  10. package/dist/builtin-memory/05-kinds/plan/01-orchestrator.md +4 -5
  11. package/dist/builtin-memory/05-kinds/plan/plan-contract.md +5 -13
  12. package/dist/builtin-memory/design/guide.md +38 -16
  13. package/dist/builtin-memory/design/roadmap.md +4 -4
  14. package/dist/builtin-memory/insights/init.md +5 -5
  15. package/dist/builtin-memory/internal/INDEX.md +1 -1
  16. package/dist/builtin-memory/internal/examples/INDEX.md +1 -1
  17. package/dist/builtin-memory/internal/memory-loading.md +6 -6
  18. package/dist/builtin-memory/internal/plugins.md +1 -1
  19. package/dist/builtin-memory/plan/guide.md +53 -0
  20. package/dist/builtin-memory/plan/roadmap.md +10 -8
  21. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/memory-slash-commands.ts +50 -37
  22. package/dist/clients/attach/__tests__/pane-tag-successor.test.js +56 -0
  23. package/dist/clients/attach/__tests__/profile-files.test.js +21 -0
  24. package/dist/clients/attach/chrome/inbox-strip.js +11 -7
  25. package/dist/clients/attach/session/pane-tag.d.ts +28 -2
  26. package/dist/clients/attach/session/pane-tag.js +48 -22
  27. package/dist/clients/attach/session/profile-files.d.ts +6 -0
  28. package/dist/clients/attach/session/profile-files.js +44 -11
  29. package/dist/clients/attach/slash/dispatch.js +4 -7
  30. package/dist/clients/attach/viewer.js +588 -596
  31. package/dist/commands/__tests__/surface-reload-target.test.js +21 -0
  32. package/dist/commands/api-client.d.ts +3 -7
  33. package/dist/commands/api-client.js +7 -12
  34. package/dist/commands/memory/__tests__/command-selector-and-mutation-guards.test.js +292 -0
  35. package/dist/commands/memory/__tests__/repository-root-lint.test.js +146 -0
  36. package/dist/commands/memory/delete.js +51 -24
  37. package/dist/commands/memory/edit.js +50 -10
  38. package/dist/commands/memory/find.js +105 -56
  39. package/dist/commands/memory/history.js +51 -31
  40. package/dist/commands/memory/lint.d.ts +0 -9
  41. package/dist/commands/memory/lint.js +78 -322
  42. package/dist/commands/memory/list.d.ts +12 -4
  43. package/dist/commands/memory/list.js +64 -25
  44. package/dist/commands/memory/move.js +103 -73
  45. package/dist/commands/memory/origin.js +35 -5
  46. package/dist/commands/memory/read.d.ts +4 -0
  47. package/dist/commands/memory/read.js +132 -80
  48. package/dist/commands/memory/shared.d.ts +115 -25
  49. package/dist/commands/memory/shared.js +331 -74
  50. package/dist/commands/memory/write.js +72 -21
  51. package/dist/commands/memory.js +2 -2
  52. package/dist/commands/node/lifecycle.js +2 -2
  53. package/dist/commands/pkg/market-manage.js +25 -24
  54. package/dist/commands/pkg/plugin-manage.d.ts +22 -6
  55. package/dist/commands/pkg/plugin-manage.js +118 -25
  56. package/dist/commands/pkg/shared.d.ts +8 -0
  57. package/dist/commands/pkg/shared.js +23 -20
  58. package/dist/commands/surface-reload.d.ts +5 -0
  59. package/dist/commands/surface-reload.js +9 -1
  60. package/dist/commands/sys/__tests__/migrate.test.js +1140 -22
  61. package/dist/commands/sys/__tests__/sync-project-guidance.test.js +218 -0
  62. package/dist/commands/sys/migrate.js +126 -140
  63. package/dist/commands/sys/panels/profiles-panel.d.ts +66 -0
  64. package/dist/commands/sys/panels/profiles-panel.js +599 -0
  65. package/dist/commands/sys/settings-shell.d.ts +4 -2
  66. package/dist/commands/sys/settings-shell.js +35 -4
  67. package/dist/commands/sys/settings.js +21 -5
  68. package/dist/commands/sys/sync-deps.d.ts +2 -0
  69. package/dist/commands/sys/sync-deps.js +26 -15
  70. package/dist/commands/sys/sync-project-guidance.js +228 -145
  71. package/dist/commands/sys/sync-skills.js +28 -17
  72. package/dist/commands/sys/update.js +11 -3
  73. package/dist/core/__tests__/canvas-inbox-watcher-hold.test.js +15 -2
  74. package/dist/core/__tests__/config-change-delta.test.js +106 -0
  75. package/dist/core/__tests__/context-intro.test.js +13 -9
  76. package/dist/core/__tests__/daemon-boot.test.js +22 -16
  77. package/dist/core/__tests__/fixtures/memory-slash-live-probe.js +5 -1
  78. package/dist/core/__tests__/human-deliver.test.js +19 -0
  79. package/dist/core/__tests__/inline-memory-refs.test.js +50 -46
  80. package/dist/core/__tests__/{serial → integration}/broker-fork-seam.test.js +1 -1
  81. package/dist/core/__tests__/{serial → integration}/broker-sdk-wiring.test.js +1 -1
  82. package/dist/core/__tests__/{serial → integration}/broker-snapshot-history.test.js +1 -1
  83. package/dist/core/__tests__/{serial → integration}/command-plugins.test.js +94 -3
  84. package/dist/core/__tests__/{serial → integration}/deferred-no-wake.test.js +1 -1
  85. package/dist/core/__tests__/{serial → integration}/flagship-lifecycle.test.js +13 -27
  86. package/dist/core/__tests__/{serial → integration}/host-teardown-process-group.test.js +1 -1
  87. package/dist/core/__tests__/{serial → integration}/human-deliver-e2e.test.js +1 -1
  88. package/dist/core/__tests__/{live-mutation-verbs.test.js → integration/live-mutation-verbs.test.js} +22 -33
  89. package/dist/core/__tests__/{serial → integration}/live-mutation.test.js +21 -41
  90. package/dist/core/__tests__/integration/refresh-stall-recycle.test.d.ts +1 -0
  91. package/dist/core/__tests__/{serial → integration}/refresh-stall-recycle.test.js +1 -1
  92. package/dist/core/__tests__/integration/revive.test.d.ts +1 -0
  93. package/dist/core/__tests__/{serial → integration}/revive.test.js +38 -19
  94. package/dist/core/__tests__/integration/spawn-root.test.d.ts +1 -0
  95. package/dist/core/__tests__/{serial → integration}/spawn-root.test.js +104 -1
  96. package/dist/core/__tests__/integration/subscription-delivery.test.d.ts +1 -0
  97. package/dist/core/__tests__/{serial → integration}/subscription-delivery.test.js +1 -1
  98. package/dist/core/__tests__/integration/tmux-surface.test.d.ts +1 -0
  99. package/dist/core/__tests__/{serial → integration}/tmux-surface.test.js +1 -1
  100. package/dist/core/__tests__/integration/worktree-land.test.d.ts +1 -0
  101. package/dist/core/__tests__/integration/worktree-land.test.js +400 -0
  102. package/dist/core/__tests__/integration/worktree-reap.test.d.ts +1 -0
  103. package/dist/core/__tests__/{serial/worktree.test.js → integration/worktree-reap.test.js} +6 -338
  104. package/dist/core/__tests__/kickoff.test.js +16 -5
  105. package/dist/core/__tests__/memory-resolver-precedence.test.js +122 -91
  106. package/dist/core/__tests__/nested-store-discovery.test.js +5 -3
  107. package/dist/core/__tests__/on-read-crouter-home-fence.test.js +2 -1
  108. package/dist/core/__tests__/on-read-dedup-resume.test.js +39 -27
  109. package/dist/core/__tests__/on-read-nested-store.test.js +19 -13
  110. package/dist/core/__tests__/profile-project-memory-delivery.test.js +138 -44
  111. package/dist/core/__tests__/repository-association.test.d.ts +1 -0
  112. package/dist/core/__tests__/repository-association.test.js +153 -0
  113. package/dist/core/__tests__/repository-root-identity.test.d.ts +1 -0
  114. package/dist/core/__tests__/repository-root-identity.test.js +219 -0
  115. package/dist/core/__tests__/seam/memory-slash-node-relative-inventory.test.js +27 -11
  116. package/dist/core/__tests__/warm-claim-preference-snapshot.test.d.ts +1 -0
  117. package/dist/core/__tests__/warm-claim-preference-snapshot.test.js +40 -0
  118. package/dist/core/canvas/canvas.d.ts +3 -0
  119. package/dist/core/canvas/canvas.js +30 -10
  120. package/dist/core/canvas/db.js +28 -1
  121. package/dist/core/canvas/paths.d.ts +4 -6
  122. package/dist/core/canvas/paths.js +8 -6
  123. package/dist/core/canvas/render-source.js +2 -2
  124. package/dist/core/canvas/types.d.ts +9 -13
  125. package/dist/core/exclusive-lock.d.ts +2 -0
  126. package/dist/core/exclusive-lock.js +21 -0
  127. package/dist/core/git.d.ts +0 -1
  128. package/dist/core/git.js +0 -3
  129. package/dist/core/human/__tests__/integration/inbox-core.test.d.ts +1 -0
  130. package/dist/core/human/feedback-companion.js +3 -0
  131. package/dist/core/human/scan.js +8 -1
  132. package/dist/core/keybindings/catalog.d.ts +2 -2
  133. package/dist/core/keybindings/catalog.js +2 -1
  134. package/dist/core/memory/doc-link-grammar.js +2 -2
  135. package/dist/core/memory/history.d.ts +24 -0
  136. package/dist/core/memory/history.js +66 -1
  137. package/dist/core/memory/identity.d.ts +65 -0
  138. package/dist/core/memory/identity.js +185 -0
  139. package/dist/core/memory/inline-ref-guidance.d.ts +1 -1
  140. package/dist/core/memory/inline-ref-guidance.js +1 -1
  141. package/dist/core/memory/inline-ref-inventory.d.ts +3 -10
  142. package/dist/core/memory/inline-ref-inventory.js +30 -62
  143. package/dist/core/memory/lint.d.ts +129 -0
  144. package/dist/core/memory/lint.js +517 -0
  145. package/dist/core/memory/project-namespace.d.ts +31 -0
  146. package/dist/core/memory/project-namespace.js +85 -0
  147. package/dist/core/memory/repository-association.d.ts +31 -0
  148. package/dist/core/memory/repository-association.js +129 -0
  149. package/dist/core/memory/tree.d.ts +39 -0
  150. package/dist/core/memory/tree.js +93 -0
  151. package/dist/core/memory-resolver.d.ts +193 -90
  152. package/dist/core/memory-resolver.js +461 -375
  153. package/dist/core/nested-stores.js +6 -13
  154. package/dist/core/profiles/select.d.ts +4 -1
  155. package/dist/core/profiles/select.js +108 -48
  156. package/dist/core/review/__tests__/capture-origin.test.js +2 -2
  157. package/dist/core/review/__tests__/stage-identity.test.js +2 -2
  158. package/dist/core/review/companion.js +11 -2
  159. package/dist/core/runtime/bearings.d.ts +2 -2
  160. package/dist/core/runtime/bearings.js +3 -3
  161. package/dist/core/runtime/broker/daemon-ops.d.ts +2 -2
  162. package/dist/core/runtime/broker/rebind.js +5 -0
  163. package/dist/core/runtime/broker-extension-render.d.ts +7 -3
  164. package/dist/core/runtime/broker-extension-render.js +10 -5
  165. package/dist/core/runtime/broker-persona-guidance.d.ts +19 -5
  166. package/dist/core/runtime/broker-persona-guidance.js +122 -27
  167. package/dist/core/runtime/deliver-live.d.ts +16 -4
  168. package/dist/core/runtime/deliver-live.js +29 -15
  169. package/dist/core/runtime/kickoff.d.ts +3 -3
  170. package/dist/core/runtime/kickoff.js +8 -16
  171. package/dist/core/runtime/lifecycle.js +2 -3
  172. package/dist/core/runtime/nodes.d.ts +3 -4
  173. package/dist/core/runtime/nodes.js +3 -4
  174. package/dist/core/runtime/persona.d.ts +8 -12
  175. package/dist/core/runtime/persona.js +24 -96
  176. package/dist/core/runtime/promote.d.ts +2 -2
  177. package/dist/core/runtime/promote.js +8 -21
  178. package/dist/core/runtime/revive.js +20 -17
  179. package/dist/core/runtime/spawn.js +18 -7
  180. package/dist/core/runtime/tmux-bindings.js +2 -3
  181. package/dist/core/runtime/warm-pool.js +3 -4
  182. package/dist/core/scope.js +2 -0
  183. package/dist/core/self-update.d.ts +0 -2
  184. package/dist/core/self-update.js +2 -35
  185. package/dist/core/substrate/__tests__/surface-match-memory-read.test.d.ts +1 -0
  186. package/dist/core/substrate/__tests__/surface-match-memory-read.test.js +28 -0
  187. package/dist/core/substrate/index.d.ts +2 -2
  188. package/dist/core/substrate/index.js +1 -1
  189. package/dist/core/substrate/injected-store.d.ts +43 -27
  190. package/dist/core/substrate/injected-store.js +208 -104
  191. package/dist/core/substrate/listings.d.ts +19 -12
  192. package/dist/core/substrate/listings.js +75 -52
  193. package/dist/core/substrate/on-read-node.d.ts +4 -7
  194. package/dist/core/substrate/on-read-node.js +6 -8
  195. package/dist/core/substrate/on-read.d.ts +22 -25
  196. package/dist/core/substrate/on-read.js +103 -147
  197. package/dist/core/substrate/render-node.d.ts +4 -7
  198. package/dist/core/substrate/render-node.js +5 -7
  199. package/dist/core/substrate/render.d.ts +21 -3
  200. package/dist/core/substrate/render.js +291 -223
  201. package/dist/core/substrate/schema.d.ts +1 -13
  202. package/dist/core/substrate/schema.js +5 -40
  203. package/dist/core/substrate/session-cache.d.ts +14 -4
  204. package/dist/core/substrate/session-cache.js +40 -22
  205. package/dist/core/substrate/surface-match.d.ts +9 -7
  206. package/dist/core/substrate/surface-match.js +26 -25
  207. package/dist/daemon/__tests__/helpers/source-daemon.d.ts +30 -0
  208. package/dist/daemon/__tests__/helpers/source-daemon.js +174 -0
  209. package/dist/daemon/__tests__/integration/migration-startup.test.d.ts +1 -0
  210. package/dist/daemon/__tests__/integration/migration-startup.test.js +97 -0
  211. package/dist/daemon/api/__tests__/bridge-heartbeat.test.js +21 -5
  212. package/dist/daemon/api/handlers/broker-ops.js +21 -16
  213. package/dist/daemon/api/handlers/memory.js +2 -0
  214. package/dist/daemon/crtrd.js +2 -0
  215. package/dist/daemon/human/finish.js +8 -1
  216. package/dist/daemon/manage.d.ts +0 -1
  217. package/dist/daemon/manage.js +7 -16
  218. package/dist/daemon/startup-policy.d.ts +1 -0
  219. package/dist/daemon/startup-policy.js +1 -0
  220. package/dist/migrations/001-surfaces-frontmatter.js +21 -109
  221. package/dist/migrations/002-profile-project-memory.js +1 -0
  222. package/dist/migrations/003-repository-root-memory-identity/front-door.d.ts +26 -0
  223. package/dist/migrations/003-repository-root-memory-identity/front-door.js +231 -0
  224. package/dist/migrations/003-repository-root-memory-identity/index.d.ts +2 -0
  225. package/dist/migrations/003-repository-root-memory-identity/index.js +513 -0
  226. package/dist/migrations/003-repository-root-memory-identity/references.d.ts +95 -0
  227. package/dist/migrations/003-repository-root-memory-identity/references.js +469 -0
  228. package/dist/migrations/003-repository-root-memory-identity/repository-facts.d.ts +39 -0
  229. package/dist/migrations/003-repository-root-memory-identity/repository-facts.js +349 -0
  230. package/dist/migrations/__tests__/activation-concurrency.test.d.ts +1 -0
  231. package/dist/migrations/__tests__/activation-concurrency.test.js +145 -0
  232. package/dist/migrations/__tests__/activation.test.d.ts +1 -0
  233. package/dist/migrations/__tests__/activation.test.js +149 -0
  234. package/dist/migrations/__tests__/deletion-and-root-declaration.test.d.ts +1 -0
  235. package/dist/migrations/__tests__/deletion-and-root-declaration.test.js +149 -0
  236. package/dist/migrations/activation.d.ts +16 -0
  237. package/dist/migrations/activation.js +78 -0
  238. package/dist/migrations/convergent.d.ts +14 -3
  239. package/dist/migrations/convergent.js +21 -10
  240. package/dist/migrations/corpus.d.ts +78 -0
  241. package/dist/migrations/corpus.js +497 -0
  242. package/dist/migrations/frontmatter-splice.d.ts +15 -0
  243. package/dist/migrations/frontmatter-splice.js +176 -0
  244. package/dist/migrations/registry.d.ts +6 -1
  245. package/dist/migrations/registry.js +7 -2
  246. package/dist/migrations/runner.d.ts +41 -0
  247. package/dist/migrations/runner.js +81 -0
  248. package/dist/migrations/types.d.ts +148 -9
  249. package/dist/migrations/types.js +9 -2
  250. package/dist/pi-extensions/__tests__/canvas-context-intro.test.js +225 -17
  251. package/dist/pi-extensions/__tests__/canvas-goal-capture-envelope.test.js +11 -3
  252. package/dist/pi-extensions/canvas-context-intro.d.ts +3 -5
  253. package/dist/pi-extensions/canvas-context-intro.js +50 -46
  254. package/dist/pi-extensions/canvas-doc-substrate.d.ts +1 -8
  255. package/dist/pi-extensions/canvas-doc-substrate.js +55 -122
  256. package/dist/pi-extensions/canvas-stophook.js +6 -13
  257. package/dist/shared/generated-context.d.ts +0 -3
  258. package/dist/shared/generated-context.js +0 -57
  259. package/dist/shared/tool-groups.js +2 -3
  260. package/package.json +5 -4
  261. package/runtime.lock.json +2 -2
  262. /package/dist/api/__tests__/{serial → integration}/client.test.d.ts +0 -0
  263. /package/dist/api/__tests__/{serial → integration}/client.test.js +0 -0
  264. /package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/__tests__/{serial → integration}/provider-rotation.test.ts +0 -0
  265. /package/dist/clients/{inbox/__tests__/serial/inbox-controller.test.d.ts → attach/__tests__/pane-tag-successor.test.d.ts} +0 -0
  266. /package/dist/clients/{inbox/__tests__/serial/mount-panel.test.d.ts → attach/__tests__/profile-files.test.d.ts} +0 -0
  267. /package/dist/{core/__tests__/live-mutation-verbs.test.d.ts → clients/inbox/__tests__/integration/inbox-controller.test.d.ts} +0 -0
  268. /package/dist/clients/inbox/__tests__/{serial → integration}/inbox-controller.test.js +0 -0
  269. /package/dist/{core/__tests__/serial/broker-fork-seam.test.d.ts → clients/inbox/__tests__/integration/mount-panel.test.d.ts} +0 -0
  270. /package/dist/clients/inbox/__tests__/{serial → integration}/mount-panel.test.js +0 -0
  271. /package/dist/{core/__tests__/serial/broker-sdk-wiring.test.d.ts → commands/__tests__/surface-reload-target.test.d.ts} +0 -0
  272. /package/dist/{core/__tests__/serial/broker-snapshot-history.test.d.ts → commands/memory/__tests__/command-selector-and-mutation-guards.test.d.ts} +0 -0
  273. /package/dist/{core/__tests__/serial/command-plugins.test.d.ts → commands/memory/__tests__/repository-root-lint.test.d.ts} +0 -0
  274. /package/dist/{core/__tests__/serial/deferred-no-wake.test.d.ts → commands/sys/__tests__/sync-project-guidance.test.d.ts} +0 -0
  275. /package/dist/core/__tests__/{serial/flagship-lifecycle.test.d.ts → config-change-delta.test.d.ts} +0 -0
  276. /package/dist/core/__tests__/{serial/host-teardown-process-group.test.d.ts → integration/broker-fork-seam.test.d.ts} +0 -0
  277. /package/dist/core/__tests__/{serial/human-deliver-e2e.test.d.ts → integration/broker-sdk-wiring.test.d.ts} +0 -0
  278. /package/dist/core/__tests__/{serial/live-mutation.test.d.ts → integration/broker-snapshot-history.test.d.ts} +0 -0
  279. /package/dist/core/__tests__/{serial/refresh-stall-recycle.test.d.ts → integration/command-plugins.test.d.ts} +0 -0
  280. /package/dist/core/__tests__/{serial/revive.test.d.ts → integration/deferred-no-wake.test.d.ts} +0 -0
  281. /package/dist/core/__tests__/{serial/spawn-root.test.d.ts → integration/flagship-lifecycle.test.d.ts} +0 -0
  282. /package/dist/core/__tests__/{serial/subscription-delivery.test.d.ts → integration/host-teardown-process-group.test.d.ts} +0 -0
  283. /package/dist/core/__tests__/{serial/tmux-surface.test.d.ts → integration/human-deliver-e2e.test.d.ts} +0 -0
  284. /package/dist/core/__tests__/{serial/worktree.test.d.ts → integration/live-mutation-verbs.test.d.ts} +0 -0
  285. /package/dist/core/{human/__tests__/serial/inbox-core.test.d.ts → __tests__/integration/live-mutation.test.d.ts} +0 -0
  286. /package/dist/core/human/__tests__/{serial → integration}/inbox-core.test.js +0 -0
@@ -0,0 +1,513 @@
1
+ // 003 — replace per-store project identity with one repository-root declaration.
2
+ //
3
+ // The migration freezes both pre-003 identity shapes, resolves consumers against
4
+ // that old corpus, then writes consumers before the repository identity cut.
5
+ import { existsSync, readFileSync } from 'node:fs';
6
+ import { dirname, matchesGlob } from 'node:path';
7
+ import { realpathOrSelf } from '../../core/fs-utils.js';
8
+ import { parseFrontmatterGeneric } from '../../core/frontmatter.js';
9
+ import { loadStoreMemoryDocs, openProjectMemoryStore } from '../../core/memory-resolver.js';
10
+ import { canonicalSegments, composeCanonicalName, explicitLocalName, INDEX_SEGMENT, localNameFromPath, normalizeDocName, normalizeNameSegment, resolveLocalName, stripNamespace, validateExplicitLocalName, validateNamespace, } from '../../core/memory/identity.js';
11
+ import { lintMemoryStore, MEMORY_LINT_IDENTITY_RULES, resolvableCanonicalNames } from '../../core/memory/lint.js';
12
+ import { completeRootFrontDoor, demoteLeafSurfaces, planFrontDoors, rootIndexSource, } from './front-door.js';
13
+ import { planRepositories, } from './repository-facts.js';
14
+ import { applySplices, itemFor, keyLineSpan, linkRewrites, OldCorpus, renderScalar, routeRewrites, valueSpan, viewsForStore, yamlBlock, yamlMap, } from './references.js';
15
+ let planned = { links: [], routes: [], wrote: new Set(), repositories: [] };
16
+ function emptyPlan(blockers = []) {
17
+ return {
18
+ blockers,
19
+ consumers: [],
20
+ identities: [],
21
+ repositories: [],
22
+ storePrefixes: [],
23
+ renames: [],
24
+ references: [],
25
+ };
26
+ }
27
+ /** Frozen pre-003 path-derived name: no project prefix and no INDEX collapse. */
28
+ function pathNameNoCollapse(relPath) {
29
+ return canonicalSegments(relPath.replace(/\\/g, '/').replace(/\.md$/i, ''))
30
+ .map(normalizeNameSegment)
31
+ .join('/');
32
+ }
33
+ function rawExplicitName(doc) {
34
+ const raw = doc.frontmatter?.['name'];
35
+ return typeof raw === 'string' && raw.trim() !== '' ? raw.trim() : null;
36
+ }
37
+ function ownerDirOf(store) {
38
+ return store.descriptor.ownerDir ?? dirname(dirname(store.descriptor.storeRoot));
39
+ }
40
+ function isProjectStore(descriptor) {
41
+ return descriptor.scope === 'project' && descriptor.plugin === undefined;
42
+ }
43
+ function fallbackPrefix(store) {
44
+ const effectivePrefix = store.descriptor.namespace;
45
+ const ownerDir = ownerDirOf(store);
46
+ const oldPrefix = store.descriptor.plugin ?? '';
47
+ return {
48
+ store,
49
+ storeKey: store.key,
50
+ storeRoot: store.snapshot.root,
51
+ ownerDir,
52
+ repositoryKey: '',
53
+ repositoryRoot: ownerDir,
54
+ ownerRelativePath: '',
55
+ oldPrefix,
56
+ oldRule: 'pre-003',
57
+ effectivePrefix,
58
+ nestedDeclarationAction: 'none',
59
+ legacyDeclaration: null,
60
+ };
61
+ }
62
+ function repositoryForPrefix(prefix, repositories) {
63
+ return repositories.find((repository) => repository.repositoryRoot === prefix.repositoryRoot);
64
+ }
65
+ function buildDocFacts(store, prefix, repositories, blockers) {
66
+ const repository = repositoryForPrefix(prefix, repositories);
67
+ const facts = [];
68
+ if (store.snapshot.docs.length === 0)
69
+ return facts;
70
+ if (store.descriptor.plugin !== undefined) {
71
+ const valid = validateNamespace(prefix.effectivePrefix);
72
+ if (!valid.ok) {
73
+ blockers.push({
74
+ kind: 'namespace',
75
+ message: `plugin \`${store.descriptor.plugin}\` mounts its memory under \`${prefix.effectivePrefix}\`, which is not a valid namespace (${valid.reason}) — fix the plugin package and re-run`,
76
+ storeRoot: store.key,
77
+ name: prefix.effectivePrefix,
78
+ });
79
+ }
80
+ }
81
+ for (const doc of store.snapshot.docs) {
82
+ const pathLocal = localNameFromPath(doc.relPath);
83
+ if (pathLocal === '' && !isProjectStore(store.descriptor) && store.descriptor.plugin === undefined) {
84
+ blockers.push({
85
+ kind: 'namespace',
86
+ message: `a root ${INDEX_SEGMENT}.md in a ${store.descriptor.scope} store composes to the empty canonical name — only a project store's root document answers at its effective prefix; rename this file to a named document (\`<topic>.md\`) or fold its content into the docs it introduces, then re-run`,
87
+ storeRoot: store.key,
88
+ path: doc.path,
89
+ });
90
+ }
91
+ const raw = rawExplicitName(doc);
92
+ const frozenLocal = raw === null ? pathNameNoCollapse(doc.relPath) : normalizeDocName(raw);
93
+ const oldName = prefix.oldRule === 'per-store-declaration'
94
+ ? composeCanonicalName(prefix.oldPrefix, resolveLocalName(doc.frontmatter, pathLocal))
95
+ : composeCanonicalName(prefix.oldPrefix, frozenLocal);
96
+ let finalLocal = pathLocal;
97
+ let nameEdit = null;
98
+ if (pathLocal === '') {
99
+ if (raw !== null)
100
+ nameEdit = 'remove';
101
+ }
102
+ else {
103
+ const explicit = explicitLocalName(doc.frontmatter);
104
+ if (explicit !== null) {
105
+ const localized = stripNamespace(explicit, prefix.effectivePrefix) ?? explicit;
106
+ if (localized === '' || localized === pathLocal) {
107
+ nameEdit = 'remove';
108
+ }
109
+ else {
110
+ const valid = validateExplicitLocalName(localized, prefix.effectivePrefix);
111
+ if (!valid.ok) {
112
+ blockers.push({
113
+ kind: 'namespace',
114
+ message: `explicit \`name: ${raw}\` cannot become a store-local name (${valid.reason}) — correct it and re-run`,
115
+ storeRoot: store.key,
116
+ path: doc.path,
117
+ name: raw ?? localized,
118
+ });
119
+ }
120
+ finalLocal = localized;
121
+ if (localized !== raw)
122
+ nameEdit = { value: localized };
123
+ }
124
+ }
125
+ }
126
+ let namespaceEdit = null;
127
+ if (pathLocal === '' && isProjectStore(store.descriptor)) {
128
+ if (prefix.ownerRelativePath === '') {
129
+ const declared = doc.frontmatter?.['namespace'];
130
+ if (repository !== undefined && declared !== repository.namespace) {
131
+ namespaceEdit = { value: repository.namespace };
132
+ }
133
+ }
134
+ else if (prefix.nestedDeclarationAction !== 'none') {
135
+ namespaceEdit = 'remove';
136
+ }
137
+ }
138
+ facts.push({
139
+ doc,
140
+ storeKey: store.key,
141
+ realPath: realpathOrSelf(doc.path),
142
+ oldName,
143
+ finalName: composeCanonicalName(prefix.effectivePrefix, finalLocal),
144
+ finalLocal,
145
+ nameEdit,
146
+ namespaceEdit,
147
+ oldPrefix: prefix.oldPrefix,
148
+ deleted: prefix.nestedDeclarationAction === 'synthetic-index-removed' && pathLocal === '',
149
+ });
150
+ }
151
+ return facts;
152
+ }
153
+ function addFinalCollisions(store, facts, blockers) {
154
+ const byFinalName = new Map();
155
+ for (const fact of facts) {
156
+ const bucket = byFinalName.get(fact.finalName);
157
+ if (bucket === undefined)
158
+ byFinalName.set(fact.finalName, [fact]);
159
+ else
160
+ bucket.push(fact);
161
+ }
162
+ for (const [name, bucket] of byFinalName) {
163
+ if (bucket.length < 2)
164
+ continue;
165
+ blockers.push({
166
+ kind: 'collision',
167
+ message: `${bucket.length} documents in this store would own canonical name \`${name}\` (${bucket.map((fact) => fact.doc.relPath).join(', ')}) — merge them into one document or rename one, then re-run`,
168
+ storeRoot: store.key,
169
+ name,
170
+ paths: bucket.map((fact) => fact.doc.path),
171
+ });
172
+ }
173
+ }
174
+ function packageOwnedCorpusMessage(store, fact) {
175
+ const owner = store.descriptor.plugin !== undefined ? `plugin \`${store.descriptor.plugin}\`` : "crouter's builtin corpus";
176
+ const remedy = store.descriptor.plugin !== undefined
177
+ ? `update the plugin package (\`crtr pkg plugin update ${store.descriptor.plugin}\`) once it ships the corrected corpus`
178
+ : 'update crouter (`crtr sys update`) to a release whose builtin corpus already uses repository-root identity';
179
+ return `${fact.doc.relPath} needs an identity rewrite (\`${fact.oldName}\` → \`${fact.finalName}\`) in ${owner}, a package-owned store this migration never writes — ${remedy}`;
180
+ }
181
+ function identityRewrites(source, store, fact, result) {
182
+ if (fact.nameEdit === null && fact.namespaceEdit === null)
183
+ return [];
184
+ const block = yamlBlock(source);
185
+ if (block === null) {
186
+ if (fact.namespaceEdit === null || fact.namespaceEdit === 'remove')
187
+ return [];
188
+ return [{ start: 0, end: 0, text: `---\nnamespace: ${renderScalar(fact.namespaceEdit.value)}\n---\n` }];
189
+ }
190
+ const map = yamlMap(block.raw);
191
+ if (map === null) {
192
+ result.blockers.push({
193
+ kind: 'parse-failure',
194
+ message: `${fact.doc.relPath}: frontmatter is not a YAML mapping, so its identity fields cannot be rewritten — fix the file and re-run`,
195
+ storeRoot: store.key,
196
+ path: fact.doc.path,
197
+ });
198
+ return [];
199
+ }
200
+ const splices = [];
201
+ if (fact.namespaceEdit !== null) {
202
+ const item = itemFor(map, 'namespace');
203
+ if (fact.namespaceEdit === 'remove') {
204
+ if (item !== null) {
205
+ const span = keyLineSpan(block.raw, item);
206
+ if (span !== null)
207
+ splices.push({ start: block.base + span[0], end: block.base + span[1], text: '' });
208
+ }
209
+ }
210
+ else if (item === null) {
211
+ splices.push({
212
+ start: block.base,
213
+ end: block.base,
214
+ text: `namespace: ${renderScalar(fact.namespaceEdit.value)}\n`,
215
+ });
216
+ }
217
+ else {
218
+ const span = valueSpan(block.raw, item);
219
+ if (span !== null) {
220
+ splices.push({
221
+ start: block.base + span[0],
222
+ end: block.base + span[1],
223
+ text: renderScalar(fact.namespaceEdit.value),
224
+ });
225
+ }
226
+ }
227
+ }
228
+ if (fact.nameEdit !== null) {
229
+ const item = itemFor(map, 'name');
230
+ if (item !== null) {
231
+ if (fact.nameEdit === 'remove') {
232
+ const span = keyLineSpan(block.raw, item);
233
+ if (span !== null)
234
+ splices.push({ start: block.base + span[0], end: block.base + span[1], text: '' });
235
+ }
236
+ else {
237
+ const span = valueSpan(block.raw, item);
238
+ if (span !== null) {
239
+ splices.push({
240
+ start: block.base + span[0],
241
+ end: block.base + span[1],
242
+ text: renderScalar(fact.nameEdit.value),
243
+ });
244
+ }
245
+ }
246
+ }
247
+ }
248
+ return splices;
249
+ }
250
+ function storePrefixRow(prefix, plans) {
251
+ const frontDoorAction = prefix.ownerRelativePath === ''
252
+ ? (plans.find((plan) => plan.storeKey === prefix.storeKey)?.action ?? 'none')
253
+ : 'none';
254
+ return {
255
+ storeRoot: prefix.storeRoot,
256
+ ownerDir: prefix.ownerDir,
257
+ repositoryRoot: prefix.repositoryRoot,
258
+ ownerRelativePath: prefix.ownerRelativePath,
259
+ oldPrefix: prefix.oldPrefix,
260
+ oldRule: prefix.oldRule,
261
+ effectivePrefix: prefix.effectivePrefix,
262
+ nestedDeclarationAction: prefix.nestedDeclarationAction,
263
+ frontDoorAction,
264
+ };
265
+ }
266
+ function repositoryRow(decision) {
267
+ return {
268
+ repositoryRoot: decision.repositoryRoot,
269
+ repositoryKey: decision.repositoryKey,
270
+ declarationPath: decision.declarationPath,
271
+ namespace: decision.namespace,
272
+ source: decision.source,
273
+ action: decision.action,
274
+ };
275
+ }
276
+ function plan(snapshot) {
277
+ planned = { links: [], routes: [], wrote: new Set(), repositories: [] };
278
+ const result = emptyPlan();
279
+ const repositoryPlan = planRepositories(snapshot);
280
+ if (repositoryPlan.blockers.length > 0)
281
+ return emptyPlan(repositoryPlan.blockers);
282
+ const docsByStoreKey = new Map();
283
+ const prefixByStoreKey = new Map();
284
+ for (const store of snapshot.stores) {
285
+ const prefix = repositoryPlan.prefixes.get(store.key) ?? fallbackPrefix(store);
286
+ prefixByStoreKey.set(store.key, prefix);
287
+ const facts = buildDocFacts(store, prefix, repositoryPlan.repositories, result.blockers);
288
+ docsByStoreKey.set(store.key, facts);
289
+ addFinalCollisions(store, facts, result.blockers);
290
+ }
291
+ const oldCorpus = new OldCorpus(docsByStoreKey);
292
+ const finalNameByPath = new Map();
293
+ for (const facts of docsByStoreKey.values()) {
294
+ for (const fact of facts)
295
+ finalNameByPath.set(fact.realPath, fact.finalName);
296
+ }
297
+ const frontDoorResult = planFrontDoors(repositoryPlan.repositories, repositoryPlan.prefixes, snapshot, (realPath) => finalNameByPath.get(realpathOrSelf(realPath)));
298
+ result.blockers.push(...frontDoorResult.blockers);
299
+ result.repositories.push(...repositoryPlan.repositories.map(repositoryRow));
300
+ result.storePrefixes.push(...[...repositoryPlan.prefixes.values()].map((prefix) => storePrefixRow(prefix, frontDoorResult.plans)));
301
+ const completeRoot = new Set(frontDoorResult.plans
302
+ .filter((frontDoor) => frontDoor.rootAction === 'completed')
303
+ .map((frontDoor) => realpathOrSelf(frontDoor.rootDocPath)));
304
+ const demotedLeaf = new Set(frontDoorResult.plans
305
+ .map((frontDoor) => frontDoor.leafDocPath)
306
+ .filter((path) => path !== null)
307
+ .map(realpathOrSelf));
308
+ const identityChanges = new Map();
309
+ for (const store of snapshot.stores) {
310
+ const prefix = prefixByStoreKey.get(store.key);
311
+ const facts = docsByStoreKey.get(store.key) ?? [];
312
+ const views = store.writable ? viewsForStore(snapshot, store) : [];
313
+ for (const fact of facts) {
314
+ const consumerSplices = store.writable
315
+ ? [
316
+ ...linkRewrites(oldCorpus, views, store, fact, result, planned.links),
317
+ ...routeRewrites(oldCorpus, views, store, fact, prefix, result, planned.routes),
318
+ ]
319
+ : [];
320
+ const text1 = applySplices(fact.doc.source, consumerSplices);
321
+ if (fact.deleted && store.writable) {
322
+ identityChanges.set(fact.realPath, { path: fact.doc.path, after: null });
323
+ continue;
324
+ }
325
+ const text2 = completeRoot.has(fact.realPath)
326
+ ? completeRootFrontDoor(text1, fact.doc.path)
327
+ : demotedLeaf.has(fact.realPath)
328
+ ? demoteLeafSurfaces(text1, fact.doc.path)
329
+ : text1;
330
+ const ownSplices = identityRewrites(text2, store, fact, result);
331
+ const finalText = applySplices(text2, ownSplices);
332
+ if (!store.writable) {
333
+ const prefixMoved = fact.oldPrefix !== prefix.effectivePrefix;
334
+ if ((prefixMoved || ownSplices.length > 0) && fact.oldName !== fact.finalName) {
335
+ result.blockers.push({
336
+ kind: 'package-owned-corpus',
337
+ message: packageOwnedCorpusMessage(store, fact),
338
+ storeRoot: store.key,
339
+ path: fact.doc.path,
340
+ name: fact.finalName,
341
+ });
342
+ }
343
+ continue;
344
+ }
345
+ if (consumerSplices.length > 0)
346
+ result.consumers.push({ path: fact.doc.path, after: text1 });
347
+ if (text2 !== text1 || ownSplices.length > 0)
348
+ identityChanges.set(fact.realPath, { path: fact.doc.path, after: finalText });
349
+ const identityMoved = fact.oldPrefix !== prefix.effectivePrefix || fact.nameEdit !== null || fact.namespaceEdit !== null;
350
+ if (identityMoved && fact.oldName !== fact.finalName) {
351
+ result.renames.push({
352
+ storeRoot: store.key,
353
+ path: fact.doc.path,
354
+ from: fact.oldName,
355
+ to: fact.finalName,
356
+ });
357
+ }
358
+ }
359
+ }
360
+ // FrontDoorPlan alone creates repository-root indexes. Root writes precede
361
+ // leaf demotions so an interrupted phase always leaves an authoritative door.
362
+ for (const frontDoor of frontDoorResult.plans) {
363
+ if (frontDoor.rootAction === 'created') {
364
+ const repository = repositoryPlan.repositories.find((candidate) => candidate.repositoryRoot === frontDoor.repositoryRoot);
365
+ if (repository === undefined) {
366
+ throw new Error(`migration 003: no repository decision for ${frontDoor.repositoryRoot}`);
367
+ }
368
+ result.identities.push({
369
+ path: frontDoor.rootDocPath,
370
+ after: rootIndexSource(repository.namespace, frontDoor.leafCanonicalName),
371
+ });
372
+ }
373
+ else {
374
+ const rootKey = realpathOrSelf(frontDoor.rootDocPath);
375
+ const rootChange = identityChanges.get(rootKey);
376
+ if (rootChange !== undefined) {
377
+ result.identities.push(rootChange);
378
+ identityChanges.delete(rootKey);
379
+ }
380
+ }
381
+ }
382
+ for (const frontDoor of frontDoorResult.plans) {
383
+ if (frontDoor.leafDocPath === null)
384
+ continue;
385
+ const leafKey = realpathOrSelf(frontDoor.leafDocPath);
386
+ const leafChange = identityChanges.get(leafKey);
387
+ if (leafChange !== undefined) {
388
+ result.identities.push(leafChange);
389
+ identityChanges.delete(leafKey);
390
+ }
391
+ }
392
+ result.identities.push(...identityChanges.values());
393
+ for (const change of [...result.consumers, ...result.identities])
394
+ planned.wrote.add(change.path);
395
+ planned.repositories = result.repositories.map((row) => ({ ...row }));
396
+ return result;
397
+ }
398
+ function freshDescriptor(store) {
399
+ return isProjectStore(store.descriptor) ? openProjectMemoryStore(ownerDirOf(store)) : store.descriptor;
400
+ }
401
+ function sameSet(a, b) {
402
+ if (a.size !== b.size)
403
+ return false;
404
+ for (const value of a)
405
+ if (!b.has(value))
406
+ return false;
407
+ return true;
408
+ }
409
+ function safeGlob(target, glob) {
410
+ try {
411
+ return matchesGlob(target, glob);
412
+ }
413
+ catch {
414
+ return false;
415
+ }
416
+ }
417
+ function verify(snapshot) {
418
+ const findings = [];
419
+ for (const repository of planned.repositories) {
420
+ if (!existsSync(repository.declarationPath)) {
421
+ findings.push({
422
+ kind: 'verification',
423
+ message: `repository declaration ${repository.declarationPath} was not written`,
424
+ path: repository.declarationPath,
425
+ name: repository.namespace,
426
+ });
427
+ continue;
428
+ }
429
+ try {
430
+ const declared = parseFrontmatterGeneric(readFileSync(repository.declarationPath, 'utf8')).data?.['namespace'];
431
+ if (declared === repository.namespace)
432
+ continue;
433
+ findings.push({
434
+ kind: 'verification',
435
+ message: `repository declaration ${repository.declarationPath} declares ${JSON.stringify(declared)}, not the planned namespace \`${repository.namespace}\``,
436
+ path: repository.declarationPath,
437
+ name: repository.namespace,
438
+ });
439
+ }
440
+ catch (error) {
441
+ findings.push({
442
+ kind: 'verification',
443
+ message: `repository declaration ${repository.declarationPath} cannot be parsed after the write (${error instanceof Error ? error.message : String(error)})`,
444
+ path: repository.declarationPath,
445
+ name: repository.namespace,
446
+ });
447
+ }
448
+ }
449
+ for (const store of snapshot.stores) {
450
+ if (!store.writable || store.snapshot.docs.length === 0)
451
+ continue;
452
+ for (const finding of lintMemoryStore(freshDescriptor(store)).errors) {
453
+ const damage = finding.rule === 'yaml' && planned.wrote.has(finding.path);
454
+ if (!MEMORY_LINT_IDENTITY_RULES.has(finding.rule) && !damage)
455
+ continue;
456
+ findings.push({
457
+ kind: 'verification',
458
+ message: `${finding.rule}: ${finding.message}`,
459
+ storeRoot: store.key,
460
+ path: finding.path,
461
+ ...(finding.name === undefined ? {} : { name: finding.name }),
462
+ });
463
+ }
464
+ }
465
+ const viewCache = new Map();
466
+ const viewFor = (targetId) => {
467
+ const cached = viewCache.get(targetId);
468
+ if (cached !== undefined)
469
+ return cached;
470
+ const docs = snapshot.storesForTarget(targetId).flatMap((store) => loadStoreMemoryDocs(freshDescriptor(store), true));
471
+ const view = {
472
+ names: resolvableCanonicalNames(docs),
473
+ docs: docs.map((doc) => ({ name: doc.name, realPath: realpathOrSelf(doc.path) })),
474
+ };
475
+ viewCache.set(targetId, view);
476
+ return view;
477
+ };
478
+ for (const proof of planned.links) {
479
+ if (viewFor(proof.targetId).names.has(proof.name))
480
+ continue;
481
+ findings.push({
482
+ kind: 'verification',
483
+ message: `rewritten link [[${proof.name}]] resolves to no document in target ${proof.targetId} after the write phases`,
484
+ path: proof.carrier,
485
+ targetId: proof.targetId,
486
+ name: proof.name,
487
+ });
488
+ }
489
+ for (const proof of planned.routes) {
490
+ const view = viewFor(proof.targetId);
491
+ const actual = new Set();
492
+ for (const doc of view.docs) {
493
+ if (proof.globs.some((glob) => safeGlob(doc.name, glob)))
494
+ actual.add(doc.realPath);
495
+ }
496
+ if (sameSet(actual, new Set(proof.expected)))
497
+ continue;
498
+ findings.push({
499
+ kind: 'verification',
500
+ message: `rewritten memory-read route \`${proof.globs.join(', ')}\` names ${actual.size} document(s) in target ${proof.targetId}, not the ${proof.expected.length} it named before the cut`,
501
+ path: proof.carrier,
502
+ targetId: proof.targetId,
503
+ });
504
+ }
505
+ return findings;
506
+ }
507
+ export const repositoryRootMemoryIdentityMigration = {
508
+ id: '003-repository-root-memory-identity',
509
+ lane: 'corpus',
510
+ description: 'repository-root memory identity: one namespace per repository, nested stores derive their prefix from their path under it',
511
+ plan,
512
+ verify,
513
+ };
@@ -0,0 +1,95 @@
1
+ import { type Pair, type YAMLMap } from 'yaml';
2
+ import type { CorpusPlan, CorpusSnapshot, CorpusStore, StoreDoc } from '../types.js';
3
+ import type { StorePrefixFacts } from './repository-facts.js';
4
+ export interface DocFacts {
5
+ doc: StoreDoc;
6
+ storeKey: string;
7
+ /** Realpath of the file: the identity a reference proof is keyed by. */
8
+ realPath: string;
9
+ /** The exact name this document answered at before this migration. */
10
+ oldName: string;
11
+ /** Its repository-root canonical name after this migration. */
12
+ finalName: string;
13
+ /** The store-local half of `finalName`; `''` for a store root document. */
14
+ finalLocal: string;
15
+ nameEdit: 'remove' | {
16
+ value: string;
17
+ } | null;
18
+ namespaceEdit: 'remove' | {
19
+ value: string;
20
+ } | null;
21
+ /** True when phase 2 deletes this exact synthetic nested INDEX document. */
22
+ deleted: boolean;
23
+ /** The prefix this document's store answered under before this migration. */
24
+ oldPrefix: string;
25
+ }
26
+ export interface Splice {
27
+ start: number;
28
+ end: number;
29
+ text: string;
30
+ }
31
+ /** Right-to-left, widest-first at a shared start. A whole-key removal beginning
32
+ * at the YAML block base must run before a zero-width insertion there. */
33
+ export declare function applySplices(source: string, splices: readonly Splice[]): string;
34
+ /** Locate the raw YAML within a complete document source. */
35
+ export declare function yamlBlock(source: string): {
36
+ base: number;
37
+ raw: string;
38
+ } | null;
39
+ export declare function yamlMap(raw: string): YAMLMap | null;
40
+ export declare function itemFor(map: YAMLMap, key: string): Pair | null;
41
+ /** Whole-line span of a mapping key, including its multiline value. */
42
+ export declare function keyLineSpan(raw: string, item: Pair): [number, number] | null;
43
+ /** Span of a mapping value with trailing whitespace excluded. */
44
+ export declare function valueSpan(raw: string, item: Pair): [number, number] | null;
45
+ export declare function renderScalar(value: string): string;
46
+ /** Render one or several route globs without expanding a one-line value into a
47
+ * block sequence. */
48
+ export declare function renderGlobList(globs: readonly string[]): string;
49
+ export interface View {
50
+ signature: string;
51
+ storeKeys: readonly string[];
52
+ targetIds: readonly string[];
53
+ }
54
+ export declare function viewsForStore(corpus: CorpusSnapshot, store: CorpusStore): View[];
55
+ export interface LinkProof {
56
+ targetId: string;
57
+ carrier: string;
58
+ name: string;
59
+ }
60
+ export interface RouteProof {
61
+ targetId: string;
62
+ carrier: string;
63
+ globs: readonly string[];
64
+ /** Realpaths the rewritten globs must still name exactly. */
65
+ expected: readonly string[];
66
+ }
67
+ /** Reference resolution under the frozen old corpus view. */
68
+ export declare class OldCorpus {
69
+ private readonly facts;
70
+ private readonly matchCache;
71
+ constructor(docsByStoreKey: ReadonlyMap<string, DocFacts[]>);
72
+ /** The physical old-name winner in one view, including a synthetic document
73
+ * phase 2 will delete. The retired directory-index fallback is part of this
74
+ * frozen lookup. A virtual bare-directory prefix has no physical fact. */
75
+ resolveOldFact(view: View, written: string): DocFacts | null;
76
+ /** The final canonical name a written old name denoted in one view. Deleted
77
+ * physical winners have no final projection; dangling references and
78
+ * unprovable bare-directory mappings likewise return null. */
79
+ resolveOld(view: View, written: string): string | null;
80
+ /** Realpaths a glob names under old or final identity, plus the effective
81
+ * prefixes of stores contributing a match. */
82
+ matchSet(view: View, glob: string, phase: 'old' | 'final'): {
83
+ paths: Set<string>;
84
+ namespaces: Set<string>;
85
+ };
86
+ /** Candidate qualification for both accepted old models. A pre-003 store
87
+ * gains its final prefix; a superseded per-store declaration has its old
88
+ * prefix replaced by the repository-derived one. */
89
+ finalGlobSpellings(views: readonly View[], glob: string): string[];
90
+ }
91
+ /** The minimal glob list naming exactly the old match set under final identity,
92
+ * or null when no exact rewrite can be proved. */
93
+ export declare function provenGlobs(corpus: OldCorpus, views: readonly View[], glob: string): string[] | null;
94
+ export declare function linkRewrites(corpus: OldCorpus, views: readonly View[], store: CorpusStore, fact: DocFacts, result: CorpusPlan, proofs: LinkProof[]): Splice[];
95
+ export declare function routeRewrites(corpus: OldCorpus, views: readonly View[], store: CorpusStore, fact: DocFacts, prefix: StorePrefixFacts, result: CorpusPlan, proofs: RouteProof[]): Splice[];