@cleocode/core 2026.5.133 → 2026.6.0

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 (560) hide show
  1. package/binaries/README.md +49 -27
  2. package/dist/agents/{agent-registry.d.ts → agent-capacity-tracker.d.ts} +2 -2
  3. package/dist/agents/agent-capacity-tracker.d.ts.map +1 -0
  4. package/dist/agents/{agent-registry.js → agent-capacity-tracker.js} +2 -2
  5. package/dist/agents/agent-capacity-tracker.js.map +1 -0
  6. package/dist/agents/index.d.ts +1 -1
  7. package/dist/agents/index.d.ts.map +1 -1
  8. package/dist/agents/index.js +4 -2
  9. package/dist/agents/index.js.map +1 -1
  10. package/dist/agents/seed-install.d.ts +1 -1
  11. package/dist/agents/seed-install.d.ts.map +1 -1
  12. package/dist/agents/seed-install.js +42 -36
  13. package/dist/agents/seed-install.js.map +1 -1
  14. package/dist/caamp-export.d.ts +18 -0
  15. package/dist/caamp-export.d.ts.map +1 -0
  16. package/dist/caamp-export.js +18 -0
  17. package/dist/caamp-export.js.map +1 -0
  18. package/dist/conduit/local-transport.d.ts +1 -1
  19. package/dist/conduit/local-transport.d.ts.map +1 -1
  20. package/dist/conduit/local-transport.js +69 -43
  21. package/dist/conduit/local-transport.js.map +1 -1
  22. package/dist/dispatch/mutate-projection.d.ts.map +1 -1
  23. package/dist/dispatch/mutate-projection.js +11 -0
  24. package/dist/dispatch/mutate-projection.js.map +1 -1
  25. package/dist/docs/docs-read-model.d.ts +7 -0
  26. package/dist/docs/docs-read-model.d.ts.map +1 -1
  27. package/dist/docs/docs-read-model.js +5 -0
  28. package/dist/docs/docs-read-model.js.map +1 -1
  29. package/dist/docs/supersede.d.ts.map +1 -1
  30. package/dist/docs/supersede.js +12 -7
  31. package/dist/docs/supersede.js.map +1 -1
  32. package/dist/doctor/db-substrate.d.ts.map +1 -1
  33. package/dist/doctor/db-substrate.js +10 -9
  34. package/dist/doctor/db-substrate.js.map +1 -1
  35. package/dist/git-shim-export.d.ts +18 -0
  36. package/dist/git-shim-export.d.ts.map +1 -0
  37. package/dist/git-shim-export.js +18 -0
  38. package/dist/git-shim-export.js.map +1 -0
  39. package/dist/hooks/payload-schemas.d.ts +2 -2
  40. package/dist/init.d.ts.map +1 -1
  41. package/dist/init.js +39 -32
  42. package/dist/init.js.map +1 -1
  43. package/dist/internal.d.ts +11 -3
  44. package/dist/internal.d.ts.map +1 -1
  45. package/dist/internal.js +14 -5
  46. package/dist/internal.js.map +1 -1
  47. package/dist/lafs-export.d.ts +18 -0
  48. package/dist/lafs-export.d.ts.map +1 -0
  49. package/dist/lafs-export.js +18 -0
  50. package/dist/lafs-export.js.map +1 -0
  51. package/dist/lifecycle/effective-stage.js +1 -1
  52. package/dist/lifecycle/index.js +1 -1
  53. package/dist/lifecycle/index.js.map +1 -1
  54. package/dist/lifecycle/rollup.js +1 -1
  55. package/dist/llm/credential-pool.d.ts +17 -0
  56. package/dist/llm/credential-pool.d.ts.map +1 -1
  57. package/dist/llm/credential-pool.js +40 -1
  58. package/dist/llm/credential-pool.js.map +1 -1
  59. package/dist/llm/plugin-facade.d.ts.map +1 -1
  60. package/dist/llm/plugin-facade.js +11 -19
  61. package/dist/llm/plugin-facade.js.map +1 -1
  62. package/dist/llm/role-executor.d.ts +8 -0
  63. package/dist/llm/role-executor.d.ts.map +1 -1
  64. package/dist/llm/role-executor.js +96 -4
  65. package/dist/llm/role-executor.js.map +1 -1
  66. package/dist/llm/role-resolver.d.ts.map +1 -1
  67. package/dist/llm/role-resolver.js +56 -1
  68. package/dist/llm/role-resolver.js.map +1 -1
  69. package/dist/llm/transports/codex-oauth-headers.d.ts +51 -0
  70. package/dist/llm/transports/codex-oauth-headers.d.ts.map +1 -0
  71. package/dist/llm/transports/codex-oauth-headers.js +89 -0
  72. package/dist/llm/transports/codex-oauth-headers.js.map +1 -0
  73. package/dist/memory/claude-mem-migration.d.ts.map +1 -1
  74. package/dist/memory/claude-mem-migration.js +1 -3
  75. package/dist/memory/claude-mem-migration.js.map +1 -1
  76. package/dist/memory/decisions.d.ts.map +1 -1
  77. package/dist/memory/decisions.js +77 -23
  78. package/dist/memory/decisions.js.map +1 -1
  79. package/dist/memory/graph-memory-bridge.d.ts.map +1 -1
  80. package/dist/memory/graph-memory-bridge.js +12 -6
  81. package/dist/memory/graph-memory-bridge.js.map +1 -1
  82. package/dist/memory/learnings.d.ts +2 -2
  83. package/dist/memory/nexus-plasticity.d.ts +21 -9
  84. package/dist/memory/nexus-plasticity.d.ts.map +1 -1
  85. package/dist/memory/nexus-plasticity.js +44 -22
  86. package/dist/memory/nexus-plasticity.js.map +1 -1
  87. package/dist/memory/patterns.d.ts +2 -2
  88. package/dist/memory/redaction.d.ts +19 -3
  89. package/dist/memory/redaction.d.ts.map +1 -1
  90. package/dist/memory/redaction.js +22 -94
  91. package/dist/memory/redaction.js.map +1 -1
  92. package/dist/metrics/token-service.d.ts +8 -2
  93. package/dist/metrics/token-service.d.ts.map +1 -1
  94. package/dist/metrics/token-service.js +1 -1
  95. package/dist/metrics/token-service.js.map +1 -1
  96. package/dist/nexus/analyze-orchestrator.d.ts.map +1 -1
  97. package/dist/nexus/analyze-orchestrator.js +6 -8
  98. package/dist/nexus/analyze-orchestrator.js.map +1 -1
  99. package/dist/nexus/api-extractors/http-extractor.d.ts.map +1 -1
  100. package/dist/nexus/api-extractors/http-extractor.js +3 -3
  101. package/dist/nexus/api-extractors/http-extractor.js.map +1 -1
  102. package/dist/nexus/clusters.d.ts.map +1 -1
  103. package/dist/nexus/clusters.js +3 -2
  104. package/dist/nexus/clusters.js.map +1 -1
  105. package/dist/nexus/context.d.ts.map +1 -1
  106. package/dist/nexus/context.js +10 -16
  107. package/dist/nexus/context.js.map +1 -1
  108. package/dist/nexus/diff.d.ts.map +1 -1
  109. package/dist/nexus/diff.js +6 -4
  110. package/dist/nexus/diff.js.map +1 -1
  111. package/dist/nexus/export.d.ts.map +1 -1
  112. package/dist/nexus/export.js +7 -4
  113. package/dist/nexus/export.js.map +1 -1
  114. package/dist/nexus/flows.d.ts.map +1 -1
  115. package/dist/nexus/flows.js +3 -1
  116. package/dist/nexus/flows.js.map +1 -1
  117. package/dist/nexus/impact.d.ts +1 -1
  118. package/dist/nexus/impact.d.ts.map +1 -1
  119. package/dist/nexus/impact.js +31 -17
  120. package/dist/nexus/impact.js.map +1 -1
  121. package/dist/nexus/living-brain.d.ts.map +1 -1
  122. package/dist/nexus/living-brain.js +27 -15
  123. package/dist/nexus/living-brain.js.map +1 -1
  124. package/dist/nexus/nexus-bridge.d.ts.map +1 -1
  125. package/dist/nexus/nexus-bridge.js +28 -29
  126. package/dist/nexus/nexus-bridge.js.map +1 -1
  127. package/dist/nexus/plasticity-queries.d.ts +4 -2
  128. package/dist/nexus/plasticity-queries.d.ts.map +1 -1
  129. package/dist/nexus/plasticity-queries.js +27 -15
  130. package/dist/nexus/plasticity-queries.js.map +1 -1
  131. package/dist/nexus/query.d.ts.map +1 -1
  132. package/dist/nexus/query.js +6 -2
  133. package/dist/nexus/query.js.map +1 -1
  134. package/dist/nexus/registry.d.ts.map +1 -1
  135. package/dist/nexus/registry.js +65 -30
  136. package/dist/nexus/registry.js.map +1 -1
  137. package/dist/nexus/route-analysis.d.ts +3 -2
  138. package/dist/nexus/route-analysis.d.ts.map +1 -1
  139. package/dist/nexus/route-analysis.js +11 -10
  140. package/dist/nexus/route-analysis.js.map +1 -1
  141. package/dist/nexus/sigil.d.ts.map +1 -1
  142. package/dist/nexus/sigil.js +60 -13
  143. package/dist/nexus/sigil.js.map +1 -1
  144. package/dist/nexus/user-profile.d.ts +2 -1
  145. package/dist/nexus/user-profile.d.ts.map +1 -1
  146. package/dist/nexus/user-profile.js +8 -4
  147. package/dist/nexus/user-profile.js.map +1 -1
  148. package/dist/orchestrate/index.d.ts +1 -1
  149. package/dist/orchestrate/index.d.ts.map +1 -1
  150. package/dist/orchestrate/index.js +1 -1
  151. package/dist/orchestrate/index.js.map +1 -1
  152. package/dist/orchestrate/plan.d.ts +3 -3
  153. package/dist/orchestrate/plan.d.ts.map +1 -1
  154. package/dist/orchestrate/plan.js +7 -7
  155. package/dist/orchestrate/plan.js.map +1 -1
  156. package/dist/orchestrate/spawn-ops.js +2 -2
  157. package/dist/orchestrate/spawn-ops.js.map +1 -1
  158. package/dist/orchestration/classify.d.ts +2 -2
  159. package/dist/orchestration/classify.js +3 -3
  160. package/dist/orchestration/classify.js.map +1 -1
  161. package/dist/orchestration/validate-spawn.d.ts.map +1 -1
  162. package/dist/orchestration/validate-spawn.js +5 -5
  163. package/dist/orchestration/validate-spawn.js.map +1 -1
  164. package/dist/paths-export.d.ts +18 -0
  165. package/dist/paths-export.d.ts.map +1 -0
  166. package/dist/paths-export.js +18 -0
  167. package/dist/paths-export.js.map +1 -0
  168. package/dist/paths.d.ts.map +1 -1
  169. package/dist/paths.js +24 -11
  170. package/dist/paths.js.map +1 -1
  171. package/dist/playbooks/index.d.ts +1 -0
  172. package/dist/playbooks/index.d.ts.map +1 -1
  173. package/dist/playbooks/index.js +4 -0
  174. package/dist/playbooks/index.js.map +1 -1
  175. package/dist/playbooks/skill-node-executor.d.ts +155 -0
  176. package/dist/playbooks/skill-node-executor.d.ts.map +1 -0
  177. package/dist/playbooks/skill-node-executor.js +156 -0
  178. package/dist/playbooks/skill-node-executor.js.map +1 -0
  179. package/dist/repair.d.ts +3 -7
  180. package/dist/repair.d.ts.map +1 -1
  181. package/dist/repair.js +5 -43
  182. package/dist/repair.js.map +1 -1
  183. package/dist/sagas/migrate-containment.js +7 -7
  184. package/dist/sagas/migrate-containment.js.map +1 -1
  185. package/dist/scaffold/ensure-dirs.d.ts +8 -2
  186. package/dist/scaffold/ensure-dirs.d.ts.map +1 -1
  187. package/dist/scaffold/ensure-dirs.js +24 -11
  188. package/dist/scaffold/ensure-dirs.js.map +1 -1
  189. package/dist/scaffold/project-detection.d.ts +5 -1
  190. package/dist/scaffold/project-detection.d.ts.map +1 -1
  191. package/dist/scaffold/project-detection.js +9 -5
  192. package/dist/scaffold/project-detection.js.map +1 -1
  193. package/dist/sentient/hygiene-scan.js +6 -6
  194. package/dist/sentient/hygiene-scan.js.map +1 -1
  195. package/dist/sentient/proposal-dedup.js +2 -2
  196. package/dist/sentient/proposal-rate-limiter.js +1 -1
  197. package/dist/sentient/propose-tick.js +5 -5
  198. package/dist/sentient/propose-tick.js.map +1 -1
  199. package/dist/sentient/stage-drift-tick.js +3 -3
  200. package/dist/sentient/stage-drift-tick.js.map +1 -1
  201. package/dist/sequence/index.d.ts.map +1 -1
  202. package/dist/sequence/index.js +6 -2
  203. package/dist/sequence/index.js.map +1 -1
  204. package/dist/setup/sections/verification.js +2 -2
  205. package/dist/setup/sections/verification.js.map +1 -1
  206. package/dist/shutdown.d.ts +81 -0
  207. package/dist/shutdown.d.ts.map +1 -0
  208. package/dist/shutdown.js +105 -0
  209. package/dist/shutdown.js.map +1 -0
  210. package/dist/skills/index.d.ts +2 -0
  211. package/dist/skills/index.d.ts.map +1 -1
  212. package/dist/skills/index.js +1 -0
  213. package/dist/skills/index.js.map +1 -1
  214. package/dist/skills/skill-executor-adapter.d.ts +136 -0
  215. package/dist/skills/skill-executor-adapter.d.ts.map +1 -0
  216. package/dist/skills/skill-executor-adapter.js +137 -0
  217. package/dist/skills/skill-executor-adapter.js.map +1 -0
  218. package/dist/skills/usage-recorder.d.ts.map +1 -1
  219. package/dist/skills/usage-recorder.js +30 -0
  220. package/dist/skills/usage-recorder.js.map +1 -1
  221. package/dist/skills-export.d.ts +23 -0
  222. package/dist/skills-export.d.ts.map +1 -0
  223. package/dist/skills-export.js +23 -0
  224. package/dist/skills-export.js.map +1 -0
  225. package/dist/stats/index.d.ts.map +1 -1
  226. package/dist/stats/index.js +8 -3
  227. package/dist/stats/index.js.map +1 -1
  228. package/dist/store/agent-doctor.d.ts +3 -3
  229. package/dist/store/agent-doctor.d.ts.map +1 -1
  230. package/dist/store/agent-doctor.js +18 -13
  231. package/dist/store/agent-doctor.js.map +1 -1
  232. package/dist/store/agent-install.d.ts +6 -5
  233. package/dist/store/agent-install.d.ts.map +1 -1
  234. package/dist/store/agent-install.js +20 -16
  235. package/dist/store/agent-install.js.map +1 -1
  236. package/dist/store/agent-registry-accessor.d.ts +66 -28
  237. package/dist/store/agent-registry-accessor.d.ts.map +1 -1
  238. package/dist/store/agent-registry-accessor.js +248 -167
  239. package/dist/store/agent-registry-accessor.js.map +1 -1
  240. package/dist/store/agent-registry-store.d.ts +242 -0
  241. package/dist/store/agent-registry-store.d.ts.map +1 -0
  242. package/dist/store/agent-registry-store.js +501 -0
  243. package/dist/store/agent-registry-store.js.map +1 -0
  244. package/dist/store/agent-resolver.d.ts +8 -8
  245. package/dist/store/agent-resolver.d.ts.map +1 -1
  246. package/dist/store/agent-resolver.js +19 -17
  247. package/dist/store/agent-resolver.js.map +1 -1
  248. package/dist/store/backup-pack.d.ts.map +1 -1
  249. package/dist/store/backup-pack.js +24 -8
  250. package/dist/store/backup-pack.js.map +1 -1
  251. package/dist/store/conduit-sqlite.d.ts +181 -74
  252. package/dist/store/conduit-sqlite.d.ts.map +1 -1
  253. package/dist/store/conduit-sqlite.js +307 -528
  254. package/dist/store/conduit-sqlite.js.map +1 -1
  255. package/dist/store/cross-db-cleanup.d.ts +5 -5
  256. package/dist/store/cross-db-cleanup.d.ts.map +1 -1
  257. package/dist/store/cross-db-cleanup.js +12 -10
  258. package/dist/store/cross-db-cleanup.js.map +1 -1
  259. package/dist/store/data-accessor.d.ts +4 -4
  260. package/dist/store/data-accessor.js +5 -5
  261. package/dist/store/data-accessor.js.map +1 -1
  262. package/dist/store/data-safety-central.d.ts +83 -1
  263. package/dist/store/data-safety-central.d.ts.map +1 -1
  264. package/dist/store/data-safety-central.js +257 -0
  265. package/dist/store/data-safety-central.js.map +1 -1
  266. package/dist/store/db-helpers.d.ts +8 -2
  267. package/dist/store/db-helpers.d.ts.map +1 -1
  268. package/dist/store/db-helpers.js +6 -2
  269. package/dist/store/db-helpers.js.map +1 -1
  270. package/dist/store/dual-scope-db.d.ts +46 -4
  271. package/dist/store/dual-scope-db.d.ts.map +1 -1
  272. package/dist/store/dual-scope-db.js +103 -9
  273. package/dist/store/dual-scope-db.js.map +1 -1
  274. package/dist/store/exodus/__fixtures__/representative-fixture.d.ts +116 -0
  275. package/dist/store/exodus/__fixtures__/representative-fixture.d.ts.map +1 -0
  276. package/dist/store/exodus/__fixtures__/representative-fixture.js +274 -0
  277. package/dist/store/exodus/__fixtures__/representative-fixture.js.map +1 -0
  278. package/dist/store/exodus/index.d.ts +18 -0
  279. package/dist/store/exodus/index.d.ts.map +1 -0
  280. package/dist/store/exodus/index.js +18 -0
  281. package/dist/store/exodus/index.js.map +1 -0
  282. package/dist/store/exodus/migrate.d.ts +160 -0
  283. package/dist/store/exodus/migrate.d.ts.map +1 -0
  284. package/dist/store/exodus/migrate.js +1220 -0
  285. package/dist/store/exodus/migrate.js.map +1 -0
  286. package/dist/store/exodus/on-open.d.ts +189 -0
  287. package/dist/store/exodus/on-open.d.ts.map +1 -0
  288. package/dist/store/exodus/on-open.js +464 -0
  289. package/dist/store/exodus/on-open.js.map +1 -0
  290. package/dist/store/exodus/plan.d.ts +44 -0
  291. package/dist/store/exodus/plan.d.ts.map +1 -0
  292. package/dist/store/exodus/plan.js +178 -0
  293. package/dist/store/exodus/plan.js.map +1 -0
  294. package/dist/store/exodus/status.d.ts +22 -0
  295. package/dist/store/exodus/status.d.ts.map +1 -0
  296. package/dist/store/exodus/status.js +88 -0
  297. package/dist/store/exodus/status.js.map +1 -0
  298. package/dist/store/exodus/table-name-map.d.ts +173 -0
  299. package/dist/store/exodus/table-name-map.d.ts.map +1 -0
  300. package/dist/store/exodus/table-name-map.js +660 -0
  301. package/dist/store/exodus/table-name-map.js.map +1 -0
  302. package/dist/store/exodus/types.d.ts +169 -0
  303. package/dist/store/exodus/types.d.ts.map +1 -0
  304. package/dist/store/exodus/types.js +21 -0
  305. package/dist/store/exodus/types.js.map +1 -0
  306. package/dist/store/exodus/verify-migration.d.ts +72 -0
  307. package/dist/store/exodus/verify-migration.d.ts.map +1 -0
  308. package/dist/store/exodus/verify-migration.js +678 -0
  309. package/dist/store/exodus/verify-migration.js.map +1 -0
  310. package/dist/store/exodus/verify.d.ts +58 -0
  311. package/dist/store/exodus/verify.d.ts.map +1 -0
  312. package/dist/store/exodus/verify.js +74 -0
  313. package/dist/store/exodus/verify.js.map +1 -0
  314. package/dist/store/index.d.ts +2 -3
  315. package/dist/store/index.d.ts.map +1 -1
  316. package/dist/store/index.js +2 -3
  317. package/dist/store/index.js.map +1 -1
  318. package/dist/store/memory-accessor.d.ts +31 -0
  319. package/dist/store/memory-accessor.d.ts.map +1 -1
  320. package/dist/store/memory-accessor.js +38 -0
  321. package/dist/store/memory-accessor.js.map +1 -1
  322. package/dist/store/memory-sqlite.d.ts +86 -13
  323. package/dist/store/memory-sqlite.d.ts.map +1 -1
  324. package/dist/store/memory-sqlite.js +326 -528
  325. package/dist/store/memory-sqlite.js.map +1 -1
  326. package/dist/store/migrate-signaldock-to-conduit.d.ts +1 -1
  327. package/dist/store/migrate-signaldock-to-conduit.d.ts.map +1 -1
  328. package/dist/store/migrate-signaldock-to-conduit.js +126 -35
  329. package/dist/store/migrate-signaldock-to-conduit.js.map +1 -1
  330. package/dist/store/migration-manager.d.ts +49 -0
  331. package/dist/store/migration-manager.d.ts.map +1 -1
  332. package/dist/store/migration-manager.js +167 -67
  333. package/dist/store/migration-manager.js.map +1 -1
  334. package/dist/store/migration-sqlite.d.ts +1 -1
  335. package/dist/store/migration-sqlite.d.ts.map +1 -1
  336. package/dist/store/migration-sqlite.js +32 -3
  337. package/dist/store/migration-sqlite.js.map +1 -1
  338. package/dist/store/nexus-sqlite.d.ts +152 -29
  339. package/dist/store/nexus-sqlite.d.ts.map +1 -1
  340. package/dist/store/nexus-sqlite.js +496 -177
  341. package/dist/store/nexus-sqlite.js.map +1 -1
  342. package/dist/store/nexus-validation-schemas.d.ts +32 -32
  343. package/dist/store/open-cleo-db.d.ts +37 -40
  344. package/dist/store/open-cleo-db.d.ts.map +1 -1
  345. package/dist/store/open-cleo-db.js +76 -153
  346. package/dist/store/open-cleo-db.js.map +1 -1
  347. package/dist/store/role-accessors-impl.d.ts +4 -4
  348. package/dist/store/role-accessors-impl.d.ts.map +1 -1
  349. package/dist/store/role-accessors-impl.js +18 -15
  350. package/dist/store/role-accessors-impl.js.map +1 -1
  351. package/dist/store/schema/{signaldock-schema.d.ts → agent-registry-schema.d.ts} +15 -5
  352. package/dist/store/schema/agent-registry-schema.d.ts.map +1 -0
  353. package/dist/store/schema/{signaldock-schema.js → agent-registry-schema.js} +15 -5
  354. package/dist/store/schema/agent-registry-schema.js.map +1 -0
  355. package/dist/store/schema/agent-schema.d.ts +1 -1
  356. package/dist/store/schema/agent-schema.js +4 -4
  357. package/dist/store/schema/agent-schema.js.map +1 -1
  358. package/dist/store/schema/attachments.d.ts +1 -1
  359. package/dist/store/schema/audit.d.ts +15 -5
  360. package/dist/store/schema/audit.d.ts.map +1 -1
  361. package/dist/store/schema/audit.js +12 -2
  362. package/dist/store/schema/audit.js.map +1 -1
  363. package/dist/store/schema/background-jobs.d.ts +1 -1
  364. package/dist/store/schema/cleo-global/{signaldock.d.ts → agent-registry.d.ts} +277 -271
  365. package/dist/store/schema/cleo-global/agent-registry.d.ts.map +1 -0
  366. package/dist/store/schema/cleo-global/{signaldock.js → agent-registry.js} +136 -125
  367. package/dist/store/schema/cleo-global/agent-registry.js.map +1 -0
  368. package/dist/store/schema/cleo-global/index.d.ts +29 -22
  369. package/dist/store/schema/cleo-global/index.d.ts.map +1 -1
  370. package/dist/store/schema/cleo-global/index.js +29 -22
  371. package/dist/store/schema/cleo-global/index.js.map +1 -1
  372. package/dist/store/schema/cleo-global/nexus.d.ts +36 -1034
  373. package/dist/store/schema/cleo-global/nexus.d.ts.map +1 -1
  374. package/dist/store/schema/cleo-global/nexus.js +32 -337
  375. package/dist/store/schema/cleo-global/nexus.js.map +1 -1
  376. package/dist/store/schema/cleo-global/skills.d.ts +16 -0
  377. package/dist/store/schema/cleo-global/skills.d.ts.map +1 -1
  378. package/dist/store/schema/cleo-global/skills.js +11 -0
  379. package/dist/store/schema/cleo-global/skills.js.map +1 -1
  380. package/dist/store/schema/{cleo-project → cleo-global}/telemetry.d.ts +33 -17
  381. package/dist/store/schema/cleo-global/telemetry.d.ts.map +1 -0
  382. package/dist/store/schema/{cleo-project → cleo-global}/telemetry.js +30 -18
  383. package/dist/store/schema/cleo-global/telemetry.js.map +1 -0
  384. package/dist/store/schema/cleo-project/audit.d.ts +8 -8
  385. package/dist/store/schema/cleo-project/audit.d.ts.map +1 -1
  386. package/dist/store/schema/cleo-project/audit.js +2 -6
  387. package/dist/store/schema/cleo-project/audit.js.map +1 -1
  388. package/dist/store/schema/cleo-project/docs.d.ts +1 -1
  389. package/dist/store/schema/cleo-project/index.d.ts +29 -12
  390. package/dist/store/schema/cleo-project/index.d.ts.map +1 -1
  391. package/dist/store/schema/cleo-project/index.js +29 -12
  392. package/dist/store/schema/cleo-project/index.js.map +1 -1
  393. package/dist/store/schema/cleo-project/lifecycle.d.ts +2 -2
  394. package/dist/store/schema/cleo-project/nexus-graph.d.ts +1067 -0
  395. package/dist/store/schema/cleo-project/nexus-graph.d.ts.map +1 -0
  396. package/dist/store/schema/cleo-project/nexus-graph.js +407 -0
  397. package/dist/store/schema/cleo-project/nexus-graph.js.map +1 -0
  398. package/dist/store/schema/cleo-project/provenance-orphans.d.ts +385 -0
  399. package/dist/store/schema/cleo-project/provenance-orphans.d.ts.map +1 -0
  400. package/dist/store/schema/cleo-project/provenance-orphans.js +142 -0
  401. package/dist/store/schema/cleo-project/provenance-orphans.js.map +1 -0
  402. package/dist/store/schema/cleo-project/provenance-rest.d.ts +1 -1
  403. package/dist/store/schema/cleo-project/runtime.d.ts +1 -1
  404. package/dist/store/schema/cleo-project/tasks-core-batch2.d.ts +1 -1
  405. package/dist/store/schema/cleo-project/tasks-core.d.ts +3 -3
  406. package/dist/store/schema/cleo-shared/brain.d.ts +711 -494
  407. package/dist/store/schema/cleo-shared/brain.d.ts.map +1 -1
  408. package/dist/store/schema/cleo-shared/brain.js +215 -134
  409. package/dist/store/schema/cleo-shared/brain.js.map +1 -1
  410. package/dist/store/schema/conduit-schema.d.ts +63 -51
  411. package/dist/store/schema/conduit-schema.d.ts.map +1 -1
  412. package/dist/store/schema/conduit-schema.js +23 -11
  413. package/dist/store/schema/conduit-schema.js.map +1 -1
  414. package/dist/store/schema/goal.d.ts +3 -2
  415. package/dist/store/schema/goal.d.ts.map +1 -1
  416. package/dist/store/schema/goal.js +3 -2
  417. package/dist/store/schema/goal.js.map +1 -1
  418. package/dist/store/schema/index.d.ts +1 -0
  419. package/dist/store/schema/index.d.ts.map +1 -1
  420. package/dist/store/schema/index.js +1 -0
  421. package/dist/store/schema/index.js.map +1 -1
  422. package/dist/store/schema/lifecycle.d.ts +2 -2
  423. package/dist/store/schema/memory-schema.d.ts +2 -2
  424. package/dist/store/schema/nexus-schema.d.ts +174 -115
  425. package/dist/store/schema/nexus-schema.d.ts.map +1 -1
  426. package/dist/store/schema/nexus-schema.js +175 -55
  427. package/dist/store/schema/nexus-schema.js.map +1 -1
  428. package/dist/store/schema/provenance/releases.d.ts +1 -1
  429. package/dist/store/schema/schema-utils.d.ts +78 -0
  430. package/dist/store/schema/schema-utils.d.ts.map +1 -0
  431. package/dist/store/schema/schema-utils.js +49 -0
  432. package/dist/store/schema/schema-utils.js.map +1 -0
  433. package/dist/store/schema/skills-schema.d.ts +81 -44
  434. package/dist/store/schema/skills-schema.d.ts.map +1 -1
  435. package/dist/store/schema/skills-schema.js +49 -16
  436. package/dist/store/schema/skills-schema.js.map +1 -1
  437. package/dist/store/schema/tasks.d.ts +3 -3
  438. package/dist/store/skills-db.d.ts +90 -50
  439. package/dist/store/skills-db.d.ts.map +1 -1
  440. package/dist/store/skills-db.js +132 -146
  441. package/dist/store/skills-db.js.map +1 -1
  442. package/dist/store/sqlite-backup.d.ts +2 -2
  443. package/dist/store/sqlite-backup.d.ts.map +1 -1
  444. package/dist/store/sqlite-backup.js +11 -10
  445. package/dist/store/sqlite-backup.js.map +1 -1
  446. package/dist/store/sqlite-data-accessor.d.ts.map +1 -1
  447. package/dist/store/sqlite-data-accessor.js +25 -18
  448. package/dist/store/sqlite-data-accessor.js.map +1 -1
  449. package/dist/store/sqlite.d.ts +72 -12
  450. package/dist/store/sqlite.d.ts.map +1 -1
  451. package/dist/store/sqlite.js +153 -89
  452. package/dist/store/sqlite.js.map +1 -1
  453. package/dist/store/tasks-schema.d.ts +4 -0
  454. package/dist/store/tasks-schema.d.ts.map +1 -1
  455. package/dist/store/tasks-schema.js +60 -0
  456. package/dist/store/tasks-schema.js.map +1 -1
  457. package/dist/store/tasks-sqlite.d.ts +2 -2
  458. package/dist/store/tasks-sqlite.d.ts.map +1 -1
  459. package/dist/store/tasks-sqlite.js +10 -5
  460. package/dist/store/tasks-sqlite.js.map +1 -1
  461. package/dist/store/umbrella-data-accessor.d.ts +17 -6
  462. package/dist/store/umbrella-data-accessor.d.ts.map +1 -1
  463. package/dist/store/umbrella-data-accessor.js +8 -8
  464. package/dist/store/umbrella-data-accessor.js.map +1 -1
  465. package/dist/store/validation-schemas.d.ts +241 -208
  466. package/dist/store/validation-schemas.d.ts.map +1 -1
  467. package/dist/system/health.d.ts.map +1 -1
  468. package/dist/system/health.js +11 -6
  469. package/dist/system/health.js.map +1 -1
  470. package/dist/system/project-health.d.ts.map +1 -1
  471. package/dist/system/project-health.js +58 -12
  472. package/dist/system/project-health.js.map +1 -1
  473. package/dist/tasks/add.d.ts +8 -0
  474. package/dist/tasks/add.d.ts.map +1 -1
  475. package/dist/tasks/add.js +101 -0
  476. package/dist/tasks/add.js.map +1 -1
  477. package/dist/tasks/cancelled-child-waiver-audit.d.ts +47 -0
  478. package/dist/tasks/cancelled-child-waiver-audit.d.ts.map +1 -0
  479. package/dist/tasks/cancelled-child-waiver-audit.js +34 -0
  480. package/dist/tasks/cancelled-child-waiver-audit.js.map +1 -0
  481. package/dist/tasks/complete.d.ts +22 -2
  482. package/dist/tasks/complete.d.ts.map +1 -1
  483. package/dist/tasks/complete.js +71 -6
  484. package/dist/tasks/complete.js.map +1 -1
  485. package/dist/tasks/compute-task-view.js +1 -1
  486. package/dist/tasks/session-scope.d.ts +5 -0
  487. package/dist/tasks/session-scope.d.ts.map +1 -1
  488. package/dist/tasks/session-scope.js +4 -0
  489. package/dist/tasks/session-scope.js.map +1 -1
  490. package/dist/tools/guard.d.ts +71 -1
  491. package/dist/tools/guard.d.ts.map +1 -1
  492. package/dist/tools/guard.js +73 -1
  493. package/dist/tools/guard.js.map +1 -1
  494. package/dist/tools/index.d.ts +21 -0
  495. package/dist/tools/index.d.ts.map +1 -1
  496. package/dist/tools/index.js +25 -0
  497. package/dist/tools/index.js.map +1 -1
  498. package/dist/upgrade.d.ts.map +1 -1
  499. package/dist/upgrade.js +22 -13
  500. package/dist/upgrade.js.map +1 -1
  501. package/dist/workgraph/containment.js +18 -18
  502. package/dist/workgraph/relations.js +2 -2
  503. package/dist/worktree/list.d.ts +1 -1
  504. package/dist/worktree/list.d.ts.map +1 -1
  505. package/dist/worktree/list.js +19 -21
  506. package/dist/worktree/list.js.map +1 -1
  507. package/dist/worktree-export.d.ts +18 -0
  508. package/dist/worktree-export.d.ts.map +1 -0
  509. package/dist/worktree-export.js +18 -0
  510. package/dist/worktree-export.js.map +1 -0
  511. package/migrations/drizzle-agent-registry/20260412000000_initial-global-agent-registry/migration.sql +29 -0
  512. package/migrations/drizzle-brain/20260601000001_t11522-brain-task-observations/migration.sql +28 -0
  513. package/migrations/drizzle-brain/20260601000002_t11522-inline-only-brain-tables/migration.sql +75 -0
  514. package/migrations/drizzle-cleo-global/20260531000001_t11363-consolidation-cleo-global/migration.sql +49 -144
  515. package/migrations/drizzle-cleo-global/20260531000001_t11363-consolidation-cleo-global/snapshot.json +8 -8
  516. package/migrations/drizzle-cleo-global/20260531000002_t11546-brain-usage-log/migration.sql +16 -0
  517. package/migrations/drizzle-cleo-global/20260601000001_t11544-skills-usage-project-id/migration.sql +12 -0
  518. package/migrations/drizzle-cleo-global/20260602000001_t11622-agent-registry-rename/migration.sql +80 -0
  519. package/migrations/drizzle-cleo-project/20260531000001_t11363-consolidation-cleo-project/migration.sql +26 -167
  520. package/migrations/drizzle-cleo-project/20260531000001_t11363-consolidation-cleo-project/snapshot.json +8 -8
  521. package/migrations/drizzle-cleo-project/20260531000002_t11546-brain-usage-log/migration.sql +21 -0
  522. package/migrations/drizzle-cleo-project/20260601000001_t11549-agent-credentials-brain-release-links/migration.sql +49 -0
  523. package/migrations/drizzle-cleo-project/20260601000002_t11538-project-nexus-graph/migration.sql +140 -0
  524. package/migrations/drizzle-cleo-project/20260602000002_t11649-token-usage-transport-mcp/migration.sql +146 -0
  525. package/migrations/drizzle-conduit/20260601000003_t11523-conduit-inline-schema/migration.sql +82 -0
  526. package/migrations/drizzle-nexus/20260421200001_t1165-baseline-reset/migration.sql +26 -8
  527. package/migrations/drizzle-nexus/20260601000001_t11545-nexus-relation-weights-partition/migration.sql +97 -0
  528. package/package.json +43 -11
  529. package/scripts/install-supervisor-binary.mjs +50 -201
  530. package/scripts/napi-binary-picker.mjs +267 -0
  531. package/dist/agents/agent-registry.d.ts.map +0 -1
  532. package/dist/agents/agent-registry.js.map +0 -1
  533. package/dist/store/data-safety.d.ts +0 -92
  534. package/dist/store/data-safety.d.ts.map +0 -1
  535. package/dist/store/data-safety.js +0 -274
  536. package/dist/store/data-safety.js.map +0 -1
  537. package/dist/store/schema/cleo-global/signaldock.d.ts.map +0 -1
  538. package/dist/store/schema/cleo-global/signaldock.js.map +0 -1
  539. package/dist/store/schema/cleo-project/telemetry.d.ts.map +0 -1
  540. package/dist/store/schema/cleo-project/telemetry.js.map +0 -1
  541. package/dist/store/schema/signaldock-schema.d.ts.map +0 -1
  542. package/dist/store/schema/signaldock-schema.js.map +0 -1
  543. package/dist/store/signaldock-sqlite.d.ts +0 -173
  544. package/dist/store/signaldock-sqlite.d.ts.map +0 -1
  545. package/dist/store/signaldock-sqlite.js +0 -445
  546. package/dist/store/signaldock-sqlite.js.map +0 -1
  547. package/migrations/drizzle-nexus/20260318205558_initial/migration.sql +0 -46
  548. package/migrations/drizzle-nexus/20260412000001_t529-nexus-graph-tables/migration.sql +0 -49
  549. package/migrations/drizzle-nexus/20260415000001_t622-project-registry-paths/migration.sql +0 -12
  550. package/migrations/drizzle-nexus/20260419000001_t998-nexus-plasticity/migration.sql +0 -13
  551. package/migrations/drizzle-nexus/20260423052640_t1077-add-user-profile-table/migration.sql +0 -16
  552. package/migrations/drizzle-nexus/20260423052640_t1077-add-user-profile-table/snapshot.json +0 -1531
  553. package/migrations/drizzle-nexus/20260424140538_t1148-add-sigils-table/migration.sql +0 -13
  554. package/migrations/drizzle-nexus/20260424140538_t1148-add-sigils-table/snapshot.json +0 -1652
  555. package/migrations/drizzle-nexus/20260504000001_t1839-fts5-nexus-symbols/migration.sql +0 -68
  556. package/migrations/drizzle-nexus/20260507135519_t9163-nexus-is-external/migration.sql +0 -20
  557. package/migrations/drizzle-nexus/20260507135519_t9163-nexus-is-external/snapshot.json +0 -1652
  558. package/migrations/drizzle-nexus/20260526222449_t11025-project-id-aliases/migration.sql +0 -16
  559. package/migrations/drizzle-signaldock/20260412000000_initial-global-signaldock/migration.sql +0 -209
  560. package/migrations/drizzle-signaldock/20260412000000_initial-global-signaldock/snapshot.json +0 -2060
@@ -0,0 +1,660 @@
1
+ /**
2
+ * Deterministic legacy-to-consolidated table-name resolver for exodus migration.
3
+ *
4
+ * ## Problem (ROOT CAUSE 1 — T11532)
5
+ *
6
+ * Legacy source DBs use UNPREFIXED table names (`tasks`, `messages`, `skills`, …)
7
+ * while the consolidated dual-scope `cleo.db` uses DOMAIN-PREFIXED names
8
+ * (`tasks_tasks`, `conduit_messages`, `skills_skills`, …). Without a mapping,
9
+ * every `INSERT OR IGNORE INTO main."<name>"` silently copies 0 rows because the
10
+ * target table is absent under the legacy name.
11
+ *
12
+ * ## Design
13
+ *
14
+ * The mapping is a static lookup table derived from reading every
15
+ * `cleo-project/` and `cleo-global/` schema file and matching the physical
16
+ * `sqliteTable('<consolidated-name>', …)` names against each legacy DB's schema.
17
+ *
18
+ * Rules:
19
+ * - If a legacy table is already domain-prefixed in the consolidated schema
20
+ * (e.g. `brain_observations`, `nexus_audit_log`, `tasks_goal`), map identity.
21
+ * - If a legacy table has NO consolidated counterpart (virtual tables, orphan
22
+ * telemetry tables, …), return `null` so the caller can log + skip explicitly
23
+ * rather than silently discarding rows.
24
+ *
25
+ * ## Source-DB scope
26
+ *
27
+ * The resolver takes a `sourceName` (the `LegacyDbDescriptor.name` value, e.g.
28
+ * `"tasks"`, `"brain (project)"`, `"conduit"`) to disambiguate tables that
29
+ * share the same legacy name across multiple DBs (e.g. `"attachments"` lives in
30
+ * both conduit.db and attachments.ts/tasks.db; `"sessions"` lives in both
31
+ * tasks.db and signaldock.db).
32
+ *
33
+ * ## Nexus code-graph residency move (ADR-090 · T11539)
34
+ *
35
+ * The four nexus code-graph tables — `nexus_nodes`, `nexus_relations`,
36
+ * `nexus_contracts`, `nexus_code_index` (ADR-090 "Category A") — were removed
37
+ * from the GLOBAL schema (`../schema/cleo-global/nexus.ts`) and now reside in
38
+ * PROJECT scope (`../schema/cleo-project/nexus-graph.ts`). They are still
39
+ * extracted from the legacy GLOBAL `nexus.db` source, but exodus MUST route them
40
+ * into the PROJECT-scope consolidated `cleo.db`, not the global one. The source
41
+ * descriptor `nexus` carries `targetScope: 'global'`, so a per-table scope
42
+ * override is required for these four tables — see
43
+ * {@link NEXUS_GRAPH_PROJECT_TABLES} and {@link resolveTableTargetScope}. The
44
+ * six registry/identity tables (`nexus_project_registry`,
45
+ * `nexus_project_id_aliases`, `nexus_audit_log`, `nexus_schema_meta`,
46
+ * `nexus_user_profile`, `nexus_sigils`) stay GLOBAL.
47
+ *
48
+ * @task T11532 (ROOT CAUSE 1 — name-mapping gap)
49
+ * @task T11533 (ROOT CAUSE 3 — signaldock skills mapping + brain_release_links skip +
50
+ * brain_session_narrative mapping)
51
+ * @task T11546 (no-home-table fixes — schema_meta→tasks_schema_meta, brain_usage_log mapping,
52
+ * brain_schema_meta mapping)
53
+ * @task T11539 (nexus code-graph residency — route the 4 graph tables to PROJECT scope)
54
+ * @epic T11248
55
+ * @saga T11242
56
+ */
57
+ // ---------------------------------------------------------------------------
58
+ // Per-source legacy→consolidated mapping tables
59
+ // ---------------------------------------------------------------------------
60
+ /**
61
+ * tasks.db — tables from tasks-schema.ts (tasks.ts, audit.ts, background-jobs.ts,
62
+ * chain-schema.ts, agent-schema.ts, lifecycle.ts, evidence-bindings.ts,
63
+ * experiments.ts, attachments.ts, manifest.ts, code-index.ts, playbooks.ts,
64
+ * provenance/releases.ts, provenance/commits.ts, provenance/pull-requests.ts,
65
+ * goal.ts) all prefixed with `tasks_` in the consolidated schema, except the
66
+ * docs tables which become `docs_*`.
67
+ */
68
+ const TASKS_DB_MAP = new Map([
69
+ // tasks.ts
70
+ ['tasks', 'tasks_tasks'],
71
+ ['task_acceptance_criteria', 'tasks_task_acceptance_criteria'],
72
+ ['acceptance_projection_state', 'tasks_acceptance_projection_state'],
73
+ ['acceptance_projection_dirty', 'tasks_acceptance_projection_dirty'],
74
+ ['task_dependencies', 'tasks_task_dependencies'],
75
+ ['task_labels', 'tasks_task_labels'],
76
+ ['task_relations', 'tasks_task_relations'],
77
+ ['sessions', 'tasks_sessions'],
78
+ ['session_handoff_entries', 'tasks_session_handoff_entries'],
79
+ ['task_work_history', 'tasks_task_work_history'],
80
+ ['task_acceptance_criteria_history', 'tasks_task_acceptance_criteria_history'],
81
+ ['external_task_links', 'tasks_external_task_links'],
82
+ // audit.ts
83
+ ['audit_log', 'tasks_audit_log'],
84
+ ['token_usage', 'tasks_token_usage'],
85
+ ['architecture_decisions', 'tasks_architecture_decisions'],
86
+ ['adr_task_links', 'tasks_adr_task_links'],
87
+ ['adr_relations', 'tasks_adr_relations'],
88
+ ['status_registry', 'tasks_status_registry'],
89
+ // background-jobs.ts
90
+ ['background_jobs', 'tasks_background_jobs'],
91
+ // chain-schema.ts
92
+ ['warp_chains', 'tasks_warp_chains'],
93
+ ['warp_chain_instances', 'tasks_warp_chain_instances'],
94
+ // agent-schema.ts
95
+ ['agent_instances', 'tasks_agent_instances'],
96
+ ['agent_error_log', 'tasks_agent_error_log'],
97
+ // lifecycle.ts
98
+ ['lifecycle_pipelines', 'tasks_lifecycle_pipelines'],
99
+ ['lifecycle_stages', 'tasks_lifecycle_stages'],
100
+ ['lifecycle_gate_results', 'tasks_lifecycle_gate_results'],
101
+ ['lifecycle_evidence', 'tasks_lifecycle_evidence'],
102
+ ['lifecycle_transitions', 'tasks_lifecycle_transitions'],
103
+ // evidence-bindings.ts
104
+ ['evidence_ac_bindings', 'tasks_evidence_ac_bindings'],
105
+ // experiments.ts
106
+ ['experiments', 'tasks_experiments'],
107
+ // attachments.ts (docs-domain in consolidated)
108
+ ['attachments', 'docs_attachments'],
109
+ ['attachment_refs', 'docs_attachment_refs'],
110
+ // manifest.ts (docs-domain in consolidated)
111
+ ['manifest_entries', 'docs_manifest_entries'],
112
+ ['pipeline_manifest', 'docs_pipeline_manifest'],
113
+ // provenance/commits.ts
114
+ ['commits', 'tasks_commits'],
115
+ ['task_commits', 'tasks_task_commits'],
116
+ ['commit_files', 'tasks_commit_files'],
117
+ // provenance/pull-requests.ts
118
+ ['pull_requests', 'tasks_pull_requests'],
119
+ ['pr_commits', 'tasks_pr_commits'],
120
+ ['pr_tasks', 'tasks_pr_tasks'],
121
+ // provenance/releases.ts
122
+ ['releases', 'tasks_releases'],
123
+ ['release_commits', 'tasks_release_commits'],
124
+ ['release_changes', 'tasks_release_changes'],
125
+ ['release_changesets', 'tasks_release_changesets'],
126
+ ['release_artifacts', 'tasks_release_artifacts'],
127
+ // playbooks.ts (tasks.db stores playbook_runs/playbook_approvals)
128
+ ['playbook_runs', 'tasks_playbook_runs'],
129
+ ['playbook_approvals', 'tasks_playbook_approvals'],
130
+ // goal.ts — already prefixed in legacy
131
+ ['tasks_goal', 'tasks_goal'],
132
+ // audit.ts — schema_meta is unprefixed in legacy tasks.db; gains tasks_ prefix in consolidated.
133
+ // (T11546 no-home-table fix — was missing from map, falling through to identity lookup for
134
+ // 'schema_meta' which is absent in consolidated; now correctly mapped to tasks_schema_meta.)
135
+ ['schema_meta', 'tasks_schema_meta'],
136
+ // T11550 P0 fix: agent_credentials and brain_release_links physically live in tasks.db
137
+ // (verified via sqlite_master introspection). T11549 erroneously placed these in BRAIN_DB_MAP
138
+ // because the legacy origin comment said "brain.db due to historical locality" — but the real
139
+ // project DB has them in tasks.db. The exodus source descriptor for tasks.db is 'tasks', so
140
+ // only TASKS_DB_MAP is consulted when copying from tasks.db. These entries must be here for
141
+ // the 3 agent_credentials rows and 8 brain_release_links rows to survive migration.
142
+ ['agent_credentials', 'tasks_agent_credentials'],
143
+ ['brain_release_links', 'tasks_brain_release_links'],
144
+ ]);
145
+ /**
146
+ * brain.db (project) and global brain.db — tables from memory-schema.ts /
147
+ * cleo-shared/brain.ts.
148
+ *
149
+ * Most tables are already `brain_*` prefixed in the legacy schema and keep the
150
+ * same name in the consolidated schema. Three exceptions:
151
+ * - `sticky_tags` → `brain_sticky_tags` (lost prefix in legacy)
152
+ * - `deriver_queue` → `brain_deriver_queue` (lost prefix in legacy)
153
+ * - `session_narrative` → `brain_session_narrative` (lost prefix in legacy)
154
+ *
155
+ * Tables present in the live DB but NOT in the consolidated target schema
156
+ * (virtual tables, orphan telemetry, etc.) map to `null` — they will be
157
+ * logged as explicit skips rather than silently discarded.
158
+ *
159
+ * ## brain_release_links (T11533 → T11549 → T11550 fix)
160
+ *
161
+ * T11533 incorrectly marked `brain_release_links` as `null` (skip). T11549 added
162
+ * the target table `tasks_brain_release_links` to `cleo-project/provenance-orphans.ts`
163
+ * and mapped the table here in BRAIN_DB_MAP — but T11550 discovered that the 8 rows
164
+ * physically live in **tasks.db**, not brain.db (verified via sqlite_master). The
165
+ * correct mapping belongs in TASKS_DB_MAP (added there in T11550). The BRAIN_DB_MAP
166
+ * entry is now `null` (skip) to guard against double-migration if brain.db ever
167
+ * contains a phantom table by this name.
168
+ *
169
+ * ## agent_credentials (T11549 → T11550 fix)
170
+ *
171
+ * Same situation as brain_release_links: the 3 rows physically live in **tasks.db**,
172
+ * not brain.db. T11549 added the target table and mapped it here in BRAIN_DB_MAP,
173
+ * but the source is tasks.db. T11550 moves the mapping to TASKS_DB_MAP and sets
174
+ * this entry to `null` (skip) to prevent double-migration.
175
+ */
176
+ const BRAIN_DB_MAP = new Map([
177
+ // Already-prefixed brain_* tables (identity mapping)
178
+ ['brain_decisions', 'brain_decisions'],
179
+ ['brain_patterns', 'brain_patterns'],
180
+ ['brain_learnings', 'brain_learnings'],
181
+ ['brain_observations', 'brain_observations'],
182
+ ['brain_sticky_notes', 'brain_sticky_notes'],
183
+ ['brain_attention', 'brain_attention'],
184
+ ['brain_memory_links', 'brain_memory_links'],
185
+ ['brain_page_nodes', 'brain_page_nodes'],
186
+ ['brain_page_edges', 'brain_page_edges'],
187
+ ['brain_retrieval_log', 'brain_retrieval_log'],
188
+ ['brain_plasticity_events', 'brain_plasticity_events'],
189
+ ['brain_weight_history', 'brain_weight_history'],
190
+ ['brain_modulators', 'brain_modulators'],
191
+ ['brain_consolidation_events', 'brain_consolidation_events'],
192
+ ['brain_transcript_events', 'brain_transcript_events'],
193
+ ['brain_promotion_log', 'brain_promotion_log'],
194
+ ['brain_backfill_runs', 'brain_backfill_runs'],
195
+ ['brain_memory_trees', 'brain_memory_trees'],
196
+ ['brain_observations_staging', 'brain_observations_staging'],
197
+ // brain_release_links: T11550 P0 fix — table physically lives in tasks.db (not brain.db).
198
+ // The TASKS_DB_MAP entry (added in T11550) handles the real migration path.
199
+ // If a legacy brain.db ever contains this table, skip it to avoid double-migration.
200
+ ['brain_release_links', null],
201
+ // brain_schema_meta: key-value schema-version store (T11546 no-home-table fix —
202
+ // was missing from map, falling through to identity lookup; now correctly mapped).
203
+ ['brain_schema_meta', 'brain_schema_meta'],
204
+ // Unprefixed legacy names (gain brain_ prefix in consolidated)
205
+ ['sticky_tags', 'brain_sticky_tags'],
206
+ ['deriver_queue', 'brain_deriver_queue'],
207
+ // session_narrative → brain_session_narrative (T11533 fix — was missing from map,
208
+ // causing identity fallback to 'session_narrative' which doesn't exist in consolidated).
209
+ ['session_narrative', 'brain_session_narrative'],
210
+ // brain_usage_log: quality-feedback telemetry (8471 rows). Added to the consolidated
211
+ // Drizzle schema in T11546 migration 20260531000002 so exodus can copy these rows.
212
+ // Identity mapping (already has brain_ prefix).
213
+ ['brain_usage_log', 'brain_usage_log'],
214
+ // brain_task_observations: runtime-only observation cache. Not in Drizzle schema.
215
+ ['brain_task_observations', null],
216
+ // brain_embeddings: vec0 VIRTUAL TABLE — cannot be migrated via INSERT/SELECT.
217
+ // Requires the sqlite-vec extension (vec0) to be loaded. Skip — will be
218
+ // recreated lazily by memory-sqlite.ts after the exodus cutover.
219
+ ['brain_embeddings', null],
220
+ // brain_embeddings_info: metadata companion to brain_embeddings vec0 virtual table.
221
+ ['brain_embeddings_info', null],
222
+ // agent_credentials: T11550 P0 fix — table physically lives in tasks.db (not brain.db).
223
+ // The TASKS_DB_MAP entry (added in T11550) handles the real migration path.
224
+ // If a legacy brain.db ever contains this table, skip it to avoid double-migration.
225
+ ['agent_credentials', null],
226
+ ]);
227
+ /**
228
+ * conduit.db — tables from conduit-schema.ts, all prefixed `conduit_*`.
229
+ *
230
+ * Note: conduit.db also has an `attachments` table (conduit attachment tracking),
231
+ * which maps to `conduit_attachments` — NOT `docs_attachments` (that is from
232
+ * tasks.db/attachments.ts).
233
+ */
234
+ const CONDUIT_DB_MAP = new Map([
235
+ ['messages', 'conduit_messages'],
236
+ ['delivery_jobs', 'conduit_delivery_jobs'],
237
+ ['dead_letters', 'conduit_dead_letters'],
238
+ ['message_pins', 'conduit_message_pins'],
239
+ ['attachments', 'conduit_attachments'],
240
+ ['attachment_versions', 'conduit_attachment_versions'],
241
+ ['attachment_approvals', 'conduit_attachment_approvals'],
242
+ ['attachment_contributors', 'conduit_attachment_contributors'],
243
+ ['topics', 'conduit_topics'],
244
+ ['topic_subscriptions', 'conduit_topic_subscriptions'],
245
+ ['topic_messages', 'conduit_topic_messages'],
246
+ ['topic_message_acks', 'conduit_topic_message_acks'],
247
+ // conduit.db may also contain conversation/agent-ref tables
248
+ ['conversations', 'conduit_conversations'],
249
+ ['project_agent_refs', 'conduit_project_agent_refs'],
250
+ ]);
251
+ /**
252
+ * nexus.db — tables from nexus-schema.ts.
253
+ *
254
+ * Some tables are ALREADY prefixed (`nexus_audit_log`, `nexus_nodes`, etc.) and
255
+ * map identity. Others lack the prefix and gain `nexus_` in consolidated.
256
+ *
257
+ * ## Scope split (ADR-090 · T11539)
258
+ *
259
+ * The legacy `nexus.db` source descriptor carries `targetScope: 'global'`, but
260
+ * the four code-graph tables (`code_index`/`nexus_code_index`, `nexus_nodes`,
261
+ * `nexus_relations`, `nexus_contracts`) now live in PROJECT scope. Their
262
+ * consolidated NAME is unchanged (identity / `nexus_code_index`), but their
263
+ * destination DB is the PROJECT `cleo.db` — see {@link NEXUS_GRAPH_PROJECT_TABLES}
264
+ * and {@link resolveTableTargetScope}. The remaining six registry/identity
265
+ * tables stay GLOBAL.
266
+ */
267
+ const NEXUS_DB_MAP = new Map([
268
+ // Unprefixed legacy names
269
+ ['project_registry', 'nexus_project_registry'],
270
+ ['project_id_aliases', 'nexus_project_id_aliases'],
271
+ ['user_profile', 'nexus_user_profile'],
272
+ ['sigils', 'nexus_sigils'],
273
+ // code_index → nexus_code_index: routed to PROJECT scope (ADR-090 §2.1).
274
+ ['code_index', 'nexus_code_index'],
275
+ // Already-prefixed names (identity)
276
+ ['nexus_audit_log', 'nexus_audit_log'],
277
+ // The 3 graph tables below keep identity names but route to PROJECT scope (ADR-090).
278
+ ['nexus_nodes', 'nexus_nodes'],
279
+ ['nexus_relations', 'nexus_relations'],
280
+ // T11545: partitioned Hebbian plasticity weights (1:1 with nexus_relations).
281
+ ['nexus_relation_weights', 'nexus_relation_weights'],
282
+ ['nexus_contracts', 'nexus_contracts'],
283
+ // schema_meta tables created by consolidated schema bootstrap
284
+ ['nexus_schema_meta', 'nexus_schema_meta'],
285
+ ]);
286
+ /**
287
+ * Legacy table names of the four nexus code-graph tables that moved from GLOBAL
288
+ * to PROJECT scope (ADR-090 · T11538/T11539).
289
+ *
290
+ * Keyed by the LEGACY physical name as it appears in `nexus.db`:
291
+ * - `nexus_nodes`, `nexus_relations`, `nexus_contracts` — already prefixed.
292
+ * - `code_index` — bare in legacy `nexus.db`; → `nexus_code_index` consolidated.
293
+ *
294
+ * Membership drives {@link resolveTableTargetScope}: exodus copies/verifies
295
+ * these against the PROJECT consolidated `cleo.db`, NOT the GLOBAL one, even
296
+ * though the `nexus` source descriptor's `targetScope` is `'global'`.
297
+ *
298
+ * @task T11539
299
+ * @epic T11248
300
+ * @saga T11242
301
+ * @see cleo docs fetch adr-090-nexus-graph-residency-split
302
+ */
303
+ export const NEXUS_GRAPH_PROJECT_TABLES = new Set([
304
+ 'nexus_nodes',
305
+ 'nexus_relations',
306
+ 'nexus_contracts',
307
+ 'code_index',
308
+ ]);
309
+ /**
310
+ * Resolve the consolidated TARGET SCOPE for a legacy source table.
311
+ *
312
+ * Most tables share the scope of their source DB descriptor (`sourceScope`).
313
+ * The exception is the four nexus code-graph tables — they are extracted from
314
+ * the GLOBAL legacy `nexus.db` but land in PROJECT scope per ADR-090 (T11539).
315
+ *
316
+ * This is the SSoT consumed by BOTH the exodus migrate runner (insert target DB)
317
+ * and the exodus verifier (verify target DB) so the two never disagree.
318
+ *
319
+ * @param sourceName - `LegacyDbDescriptor.name` (e.g. `"nexus"`, `"tasks"`).
320
+ * @param legacyTable - Physical table name in the legacy source DB.
321
+ * @param sourceScope - The source descriptor's `targetScope`.
322
+ * @returns The scope of the consolidated `cleo.db` this table copies into.
323
+ *
324
+ * @task T11539
325
+ * @epic T11248
326
+ * @saga T11242
327
+ */
328
+ export function resolveTableTargetScope(sourceName, legacyTable, sourceScope) {
329
+ if (inferSourceKind(sourceName) === 'nexus' && NEXUS_GRAPH_PROJECT_TABLES.has(legacyTable)) {
330
+ return 'project';
331
+ }
332
+ return sourceScope;
333
+ }
334
+ /**
335
+ * agent-registry (global) — the legacy on-disk source file is `signaldock.db`
336
+ * (the source-descriptor `name` stays `"signaldock"` — see {@link inferSourceKind} —
337
+ * because that is the genuine artifact name on disk). Its bare tables map to the
338
+ * consolidated PREFIXED `agent_registry_*` tables (renamed from `signaldock_*`
339
+ * under T11622 / SG-AGENT-IDENTITY E4).
340
+ *
341
+ * KEYS are the bare legacy names (the source DB still has the old shape); VALUES
342
+ * are the consolidated `agent_registry_*` target names — these MUST equal the
343
+ * `sqliteTable` names declared in `cleo-global/agent-registry.ts` (asserted by
344
+ * the exodus-map invariant test, the DHQ-046 N→0 deficit catcher).
345
+ *
346
+ * Note: the legacy `signaldock.db` has a `sessions` table (identity session
347
+ * management), which maps to `agent_registry_sessions` — NOT `tasks_sessions`.
348
+ *
349
+ * ## `skills` mapping (T11533 ROOT CAUSE 3 fix)
350
+ *
351
+ * The legacy `signaldock.db` contains a `skills` table (36 rows — pre-seeded skill
352
+ * slug catalog). In the consolidated global schema this becomes
353
+ * `agent_registry_skills`. Without this entry the legacy `skills` table fell
354
+ * through to an identity mapping, looked for a `skills` table in the global
355
+ * cleo.db (absent), and was silently skipped — resulting in
356
+ * agent_registry_skills=0 despite 36 source rows.
357
+ *
358
+ * @task T11622 (signaldock_* → agent_registry_* target rename; folds T11578 AC2)
359
+ */
360
+ const AGENT_REGISTRY_DB_MAP = new Map([
361
+ ['users', 'agent_registry_users'],
362
+ ['organization', 'agent_registry_organization'],
363
+ ['agents', 'agent_registry_agents'],
364
+ ['claim_codes', 'agent_registry_claim_codes'],
365
+ ['agent_capabilities', 'agent_registry_agent_capabilities'],
366
+ // agent_skills junction: agent <-> skill slug catalog bindings
367
+ ['agent_skills', 'agent_registry_agent_skills'],
368
+ ['agent_connections', 'agent_registry_agent_connections'],
369
+ ['accounts', 'agent_registry_accounts'],
370
+ ['sessions', 'agent_registry_sessions'],
371
+ ['verifications', 'agent_registry_verifications'],
372
+ ['org_agent_keys', 'agent_registry_org_agent_keys'],
373
+ // Capability catalog (pre-seeded, 19 entries)
374
+ ['capabilities', 'agent_registry_capabilities'],
375
+ // Skill catalog (pre-seeded, 36 entries) — T11533 ROOT CAUSE 3 fix:
376
+ // was missing → identity fallback → 'skills' absent in global → 0 rows copied.
377
+ ['skills', 'agent_registry_skills'],
378
+ ]);
379
+ /**
380
+ * skills.db (global) — tables from skills-schema.ts, all prefixed `skills_*`.
381
+ */
382
+ const SKILLS_DB_MAP = new Map([
383
+ ['skills', 'skills_skills'],
384
+ ['skill_usage', 'skills_skill_usage'],
385
+ ['skill_reviews', 'skills_skill_reviews'],
386
+ ['skill_patches', 'skills_skill_patches'],
387
+ ]);
388
+ /**
389
+ * Infer the source DB kind from `LegacyDbDescriptor.name`.
390
+ *
391
+ * The descriptor names used in `buildSourceDescriptors()` are:
392
+ * `"tasks"`, `"brain (project)"`, `"conduit"`, `"nexus"`, `"signaldock"`, `"skills"`
393
+ */
394
+ function inferSourceKind(sourceName) {
395
+ const n = sourceName.toLowerCase();
396
+ if (n.startsWith('tasks'))
397
+ return 'tasks';
398
+ if (n.startsWith('brain'))
399
+ return 'brain';
400
+ if (n.startsWith('conduit'))
401
+ return 'conduit';
402
+ if (n.startsWith('nexus'))
403
+ return 'nexus';
404
+ if (n.startsWith('signaldock'))
405
+ return 'signaldock';
406
+ if (n.startsWith('skills'))
407
+ return 'skills';
408
+ return null;
409
+ }
410
+ // ---------------------------------------------------------------------------
411
+ // Derived / internal table classification (T11572)
412
+ // ---------------------------------------------------------------------------
413
+ /**
414
+ * Internal bookkeeping tables that exist in a legacy source DB but have NO
415
+ * consolidated counterpart and carry no user data — they are recreated by the
416
+ * runtime, not migrated. Matched by EXACT name.
417
+ *
418
+ * Each legacy per-domain SQLite file (`conduit.db`, `signaldock.db`,
419
+ * `skills.db`, …) carries its OWN private schema-version / migration-ledger
420
+ * table that records HOW that file was built — NOT user-payload data:
421
+ *
422
+ * - `_conduit_meta` / `_conduit_migrations` — conduit-sqlite's own
423
+ * schema-version + migration-ledger tables (see `conduit-sqlite.ts`).
424
+ * - `_signaldock_meta` / `_signaldock_migrations` — agent-registry-store's own
425
+ * ledger tables (same class — T11577 global-scope cutover blocker).
426
+ * - `_skills_meta` — skills.db's own schema-version row (same class — T11577).
427
+ *
428
+ * The consolidated `cleo.db` has its own Drizzle journal (`__drizzle_*`) for the
429
+ * same purpose, so these legacy ledgers have no consolidated home. Row-comparing
430
+ * them would count internal ledger rows as a user-data deficit and abort the
431
+ * cutover. The {@link INTERNAL_LEDGER_PATTERN} below generalises the same skip
432
+ * to ANY future `_<domain>_meta` / `_<domain>_migrations` ledger so a new source
433
+ * DB never re-introduces this false-positive; these exact entries remain for
434
+ * documentation + as a fast path.
435
+ *
436
+ * @task T11572 (parity gate over-abort — internal/meta exclusion)
437
+ * @task T11577 (generalise to signaldock/skills + any per-source ledger)
438
+ */
439
+ const INTERNAL_BOOKKEEPING_TABLES = new Set([
440
+ '_conduit_meta',
441
+ '_conduit_migrations',
442
+ '_signaldock_meta',
443
+ '_signaldock_migrations',
444
+ '_skills_meta',
445
+ ]);
446
+ /**
447
+ * Pattern matching a per-source SQLite **internal ledger** table: an underscore-
448
+ * prefixed `_<domain>_meta` or `_<domain>_migrations` name where `<domain>` is a
449
+ * lowercase identifier (e.g. `_conduit_meta`, `_signaldock_migrations`,
450
+ * `_skills_meta`).
451
+ *
452
+ * Every legacy domain DB (conduit/signaldock/skills/…) materialises one of these
453
+ * to track its own schema version / applied-migration history. They are private
454
+ * bookkeeping — NOT migratable base data — and have no consolidated home (the
455
+ * consolidated `cleo.db` keeps its own `__drizzle_*` journal). Generalising the
456
+ * skip to this shape is future-proof: a NEW source DB that follows the same
457
+ * `_<domain>_(meta|migrations)` convention is excluded automatically, so this
458
+ * exact false-positive class can never abort the cutover again.
459
+ *
460
+ * The pattern is intentionally conservative — it requires the leading underscore
461
+ * and the exact `_meta` / `_migrations` suffix so it can never match a real
462
+ * data table (those are never underscore-prefixed in any legacy source schema).
463
+ *
464
+ * @task T11577 (parity gate over-abort — generalise per-source ledger skip)
465
+ */
466
+ const INTERNAL_LEDGER_PATTERN = /^_[a-z][a-z0-9]*_(?:meta|migrations)$/;
467
+ /**
468
+ * FTS5 shadow-table suffixes. A full-text index `<base>_fts` (an `fts5` VIRTUAL
469
+ * TABLE — e.g. `brain_decisions_fts`, `messages_fts`) materialises a family of
470
+ * backing tables `<base>_fts_data`, `<base>_fts_idx`, `<base>_fts_docsize`,
471
+ * `<base>_fts_config`, and (for `content=`-less indexes) `<base>_fts_content`.
472
+ *
473
+ * These are DERIVED from their content table and are REBUILT post-migration
474
+ * (`brain-search.ts` issues `INSERT INTO <base>_fts(<base>_fts) VALUES('rebuild')`).
475
+ * Their row counts do NOT correspond 1:1 to user rows, so comparing them against
476
+ * an absent consolidated target produces a spurious N→0 deficit. They must be
477
+ * excluded from the row-count-parity gate, not migrated.
478
+ *
479
+ * @task T11572 (parity gate over-abort — FTS5 shadow-table exclusion)
480
+ */
481
+ const FTS5_SHADOW_SUFFIXES = [
482
+ '_fts_data',
483
+ '_fts_idx',
484
+ '_fts_docsize',
485
+ '_fts_config',
486
+ '_fts_content',
487
+ ];
488
+ /**
489
+ * Return `true` if `tableName` is a DERIVED or INTERNAL table that must be
490
+ * EXCLUDED from the exodus row-count-parity gate (and from the copy path).
491
+ *
492
+ * This is the single, named, documented classification consumed by BOTH the
493
+ * migrate copy loop and the `verifyMigration` parity check, so the two never
494
+ * disagree about which tables carry migratable user data. It recognises:
495
+ *
496
+ * 1. **FTS5 virtual tables** — a bare `*_fts` name (e.g. `brain_decisions_fts`,
497
+ * `messages_fts`). The virtual table itself cannot be `INSERT … SELECT`-ed
498
+ * and is rebuilt from its content table after migration.
499
+ * 2. **FTS5 shadow/backing tables** — `*_fts_data`, `*_fts_idx`,
500
+ * `*_fts_docsize`, `*_fts_config`, `*_fts_content` (see
501
+ * {@link FTS5_SHADOW_SUFFIXES}). Derived; rebuilt post-migration.
502
+ * 3. **Internal bookkeeping** — any per-source schema-version / migration
503
+ * ledger: `_conduit_meta`, `_conduit_migrations`, `_signaldock_meta`,
504
+ * `_signaldock_migrations`, `_skills_meta`, and — generalised via
505
+ * {@link INTERNAL_LEDGER_PATTERN} — ANY `_<domain>_meta` /
506
+ * `_<domain>_migrations` ledger from a future source DB (see
507
+ * {@link INTERNAL_BOOKKEEPING_TABLES}). Schema-version ledgers with no
508
+ * consolidated home.
509
+ *
510
+ * A migration is "safe" iff every BASE-DATA row survives; these derived/internal
511
+ * tables are NOT base data, so a 0-row consolidated counterpart for them is
512
+ * expected and correct — not data loss.
513
+ *
514
+ * @param tableName - Physical table name from a legacy source DB.
515
+ * @returns `true` when the table is derived/internal and must be skipped.
516
+ *
517
+ * @task T11572 (exodus parity gate: exclude FTS5 + internal/meta shadow tables)
518
+ * @task T11577 (generalise internal-ledger skip to signaldock/skills + any per-source ledger)
519
+ * @epic T11249 (E6)
520
+ * @saga T11242
521
+ */
522
+ export function isDerivedOrInternalTable(tableName) {
523
+ // Exact-name fast path (documented known ledgers).
524
+ if (INTERNAL_BOOKKEEPING_TABLES.has(tableName))
525
+ return true;
526
+ // Generalised per-source ledger: `_<domain>_meta` / `_<domain>_migrations`.
527
+ // Future-proofs against a new source DB re-introducing the same false-positive.
528
+ if (INTERNAL_LEDGER_PATTERN.test(tableName))
529
+ return true;
530
+ // Bare FTS5 virtual table (e.g. `brain_decisions_fts`, `messages_fts`).
531
+ if (tableName.endsWith('_fts'))
532
+ return true;
533
+ // FTS5 backing/shadow tables (`*_fts_data`, `*_fts_idx`, …).
534
+ return FTS5_SHADOW_SUFFIXES.some((suffix) => tableName.endsWith(suffix));
535
+ }
536
+ /**
537
+ * Resolve the consolidated target table name for a legacy source table.
538
+ *
539
+ * @param sourceName - `LegacyDbDescriptor.name` (e.g. `"tasks"`, `"brain (project)"`).
540
+ * @param legacyTable - Physical table name from the legacy source DB.
541
+ * @returns A `TableNameResolution` describing how to copy (or skip) the table.
542
+ */
543
+ export function resolveConsolidatedTableName(sourceName, legacyTable) {
544
+ // T11572/T11577: derived (FTS5 shadow) + internal per-source ledger tables
545
+ // (`_<domain>_meta` / `_<domain>_migrations` — conduit/signaldock/skills/…)
546
+ // are excluded BEFORE any per-source map lookup. They carry no migratable base
547
+ // data — comparing them against an absent consolidated target would count an
548
+ // N→0 "deficit" and abort the cutover. This guard is source-kind-agnostic so
549
+ // it covers FTS shadow + ledger tables in any DB (brain/conduit/signaldock/…).
550
+ if (isDerivedOrInternalTable(legacyTable)) {
551
+ return {
552
+ kind: 'skip',
553
+ reason: legacyTable.includes('_fts')
554
+ ? `derived FTS5 table — rebuilt post-migration from its content table, not row-compared`
555
+ : `internal bookkeeping table — no consolidated home (recreated by runtime)`,
556
+ };
557
+ }
558
+ const kind = inferSourceKind(sourceName);
559
+ if (kind === null) {
560
+ // Unrecognized source — identity fallback (forward-compatible).
561
+ return { kind: 'unknown', targetName: legacyTable };
562
+ }
563
+ let map;
564
+ switch (kind) {
565
+ case 'tasks':
566
+ map = TASKS_DB_MAP;
567
+ break;
568
+ case 'brain':
569
+ map = BRAIN_DB_MAP;
570
+ break;
571
+ case 'conduit':
572
+ map = CONDUIT_DB_MAP;
573
+ break;
574
+ case 'nexus':
575
+ map = NEXUS_DB_MAP;
576
+ break;
577
+ case 'signaldock':
578
+ map = AGENT_REGISTRY_DB_MAP;
579
+ break;
580
+ case 'skills':
581
+ map = SKILLS_DB_MAP;
582
+ break;
583
+ }
584
+ if (!map.has(legacyTable)) {
585
+ // Not in the explicit map — try identity (e.g. already-prefixed tables not
586
+ // enumerated, or schema-meta tables created by the consolidated bootstrap).
587
+ return { kind: 'mapped', targetName: legacyTable };
588
+ }
589
+ const consolidated = map.get(legacyTable);
590
+ // `undefined` should not occur since we checked `has()`, but guard for type safety.
591
+ if (consolidated === null || consolidated === undefined) {
592
+ return {
593
+ kind: 'skip',
594
+ reason: getSkipReason(kind, legacyTable),
595
+ };
596
+ }
597
+ return { kind: 'mapped', targetName: consolidated };
598
+ }
599
+ /**
600
+ * Return a human-readable explanation for why a table is intentionally excluded
601
+ * from the consolidated schema.
602
+ */
603
+ function getSkipReason(sourceKind, legacyTable) {
604
+ const reasons = {
605
+ brain_task_observations: 'runtime-only observation cache (not Drizzle-managed); ' +
606
+ 'recreated lazily after exodus cutover',
607
+ brain_embeddings: 'vec0 VIRTUAL TABLE — cannot be migrated via INSERT/SELECT; ' +
608
+ 'requires sqlite-vec extension; recreated lazily after exodus cutover',
609
+ brain_embeddings_info: 'metadata companion to brain_embeddings vec0 virtual table; ' +
610
+ 'excluded from consolidated schema (derived/recreatable)',
611
+ // brain_release_links and agent_credentials are no longer skipped (T11549):
612
+ // they now map to tasks_brain_release_links and tasks_agent_credentials respectively.
613
+ };
614
+ return (reasons[legacyTable] ?? `table '${legacyTable}' from ${sourceKind} has no consolidated target`);
615
+ }
616
+ /**
617
+ * Reverse-lookup: given a consolidated target table name, return the set of
618
+ * legacy (sourceName, legacyTableName) pairs that map to it.
619
+ *
620
+ * Used by `runExodusVerify()` to compare legacy source counts against the
621
+ * correct consolidated target table rather than the legacy table name.
622
+ *
623
+ * Returns an empty array if no legacy table maps to the given consolidated name.
624
+ */
625
+ export function reverseLookup(consolidatedTable, sources) {
626
+ const result = [];
627
+ for (const src of sources) {
628
+ const kind = inferSourceKind(src.name);
629
+ if (kind === null)
630
+ continue;
631
+ let map;
632
+ switch (kind) {
633
+ case 'tasks':
634
+ map = TASKS_DB_MAP;
635
+ break;
636
+ case 'brain':
637
+ map = BRAIN_DB_MAP;
638
+ break;
639
+ case 'conduit':
640
+ map = CONDUIT_DB_MAP;
641
+ break;
642
+ case 'nexus':
643
+ map = NEXUS_DB_MAP;
644
+ break;
645
+ case 'signaldock':
646
+ map = AGENT_REGISTRY_DB_MAP;
647
+ break;
648
+ case 'skills':
649
+ map = SKILLS_DB_MAP;
650
+ break;
651
+ }
652
+ for (const [legacy, consolidated] of map) {
653
+ if (consolidated === consolidatedTable) {
654
+ result.push({ sourceName: src.name, legacyTable: legacy });
655
+ }
656
+ }
657
+ }
658
+ return result;
659
+ }
660
+ //# sourceMappingURL=table-name-map.js.map