@cleocode/core 2026.8.1 → 2026.8.3

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 (323) hide show
  1. package/dist/bootstrap.d.ts.map +1 -1
  2. package/dist/bootstrap.js +57 -27
  3. package/dist/bootstrap.js.map +1 -1
  4. package/dist/check/pr-gate.d.ts.map +1 -1
  5. package/dist/check/pr-gate.js +9 -0
  6. package/dist/check/pr-gate.js.map +1 -1
  7. package/dist/db/index.d.ts +13 -0
  8. package/dist/db/index.d.ts.map +1 -1
  9. package/dist/db/index.js +13 -0
  10. package/dist/db/index.js.map +1 -1
  11. package/dist/docs/display-alias.js +1 -1
  12. package/dist/docs/display-alias.js.map +1 -1
  13. package/dist/docs/export-document.js +499 -380
  14. package/dist/docs/export-document.js.map +3 -3
  15. package/dist/docs/numbering.js +1 -1
  16. package/dist/docs/numbering.js.map +1 -1
  17. package/dist/docs/supersede.js +1 -1
  18. package/dist/docs/supersede.js.map +1 -1
  19. package/dist/hooks/registry.d.ts +2 -2
  20. package/dist/hooks/registry.d.ts.map +1 -1
  21. package/dist/hooks/registry.js +5 -0
  22. package/dist/hooks/registry.js.map +1 -1
  23. package/dist/hooks/types.d.ts +59 -0
  24. package/dist/hooks/types.d.ts.map +1 -1
  25. package/dist/init/scaffold-workflows.d.ts +12 -0
  26. package/dist/init/scaffold-workflows.d.ts.map +1 -1
  27. package/dist/init/scaffold-workflows.js +16 -0
  28. package/dist/init/scaffold-workflows.js.map +1 -1
  29. package/dist/init/upgrade-workflows.d.ts.map +1 -1
  30. package/dist/init/upgrade-workflows.js +16 -0
  31. package/dist/init/upgrade-workflows.js.map +1 -1
  32. package/dist/init.d.ts.map +1 -1
  33. package/dist/init.js +16 -1
  34. package/dist/init.js.map +1 -1
  35. package/dist/injection.d.ts.map +1 -1
  36. package/dist/injection.js +44 -3
  37. package/dist/injection.js.map +1 -1
  38. package/dist/internal.d.ts +1 -0
  39. package/dist/internal.d.ts.map +1 -1
  40. package/dist/internal.js +2 -0
  41. package/dist/internal.js.map +1 -1
  42. package/dist/lifecycle/index.js +1 -1
  43. package/dist/lifecycle/index.js.map +1 -1
  44. package/dist/llm/credentials.d.ts +16 -1
  45. package/dist/llm/credentials.d.ts.map +1 -1
  46. package/dist/llm/credentials.js.map +1 -1
  47. package/dist/llm/cross-provider-selector.d.ts +25 -0
  48. package/dist/llm/cross-provider-selector.d.ts.map +1 -1
  49. package/dist/llm/cross-provider-selector.js +76 -3
  50. package/dist/llm/cross-provider-selector.js.map +1 -1
  51. package/dist/llm/local-inference-probe.d.ts +101 -0
  52. package/dist/llm/local-inference-probe.d.ts.map +1 -0
  53. package/dist/llm/local-inference-probe.js +174 -0
  54. package/dist/llm/local-inference-probe.js.map +1 -0
  55. package/dist/llm/plugin-facade.js +429 -115
  56. package/dist/llm/plugin-facade.js.map +3 -3
  57. package/dist/llm/role-executor.d.ts.map +1 -1
  58. package/dist/llm/role-executor.js +95 -9
  59. package/dist/llm/role-executor.js.map +1 -1
  60. package/dist/llm/role-resolver.d.ts +10 -0
  61. package/dist/llm/role-resolver.d.ts.map +1 -1
  62. package/dist/llm/role-resolver.js +92 -1
  63. package/dist/llm/role-resolver.js.map +1 -1
  64. package/dist/llm/system-resolver.d.ts.map +1 -1
  65. package/dist/llm/system-resolver.js +2 -0
  66. package/dist/llm/system-resolver.js.map +1 -1
  67. package/dist/memory/brain-backfill.js +3 -3
  68. package/dist/memory/brain-backfill.js.map +1 -1
  69. package/dist/memory/brain-consolidator.js +2 -2
  70. package/dist/memory/brain-consolidator.js.map +1 -1
  71. package/dist/memory/brain-doctor.js +1 -1
  72. package/dist/memory/brain-doctor.js.map +1 -1
  73. package/dist/memory/brain-health-dashboard.js +1 -1
  74. package/dist/memory/brain-health-dashboard.js.map +1 -1
  75. package/dist/memory/brain-lifecycle.js +10 -10
  76. package/dist/memory/brain-lifecycle.js.map +1 -1
  77. package/dist/memory/brain-maintenance.js +1 -1
  78. package/dist/memory/brain-maintenance.js.map +1 -1
  79. package/dist/memory/brain-page-nodes.js +4 -4
  80. package/dist/memory/brain-page-nodes.js.map +1 -1
  81. package/dist/memory/brain-reasoning.js +1 -1
  82. package/dist/memory/brain-reasoning.js.map +1 -1
  83. package/dist/memory/brain-search.d.ts +109 -0
  84. package/dist/memory/brain-search.d.ts.map +1 -1
  85. package/dist/memory/brain-search.js +150 -38
  86. package/dist/memory/brain-search.js.map +1 -1
  87. package/dist/memory/brain-similarity.js +1 -1
  88. package/dist/memory/brain-similarity.js.map +1 -1
  89. package/dist/memory/brain-stdp.js +6 -6
  90. package/dist/memory/brain-stdp.js.map +1 -1
  91. package/dist/memory/brain-stub-prune.d.ts +109 -0
  92. package/dist/memory/brain-stub-prune.d.ts.map +1 -0
  93. package/dist/memory/brain-stub-prune.js +155 -0
  94. package/dist/memory/brain-stub-prune.js.map +1 -0
  95. package/dist/memory/brain-sweep-executor.js +1 -1
  96. package/dist/memory/brain-sweep-executor.js.map +1 -1
  97. package/dist/memory/brain-writer-handlers.js +2 -2
  98. package/dist/memory/brain-writer-handlers.js.map +1 -1
  99. package/dist/memory/claude-mem-migration.d.ts.map +1 -1
  100. package/dist/memory/claude-mem-migration.js +2 -2
  101. package/dist/memory/claude-mem-migration.js.map +1 -1
  102. package/dist/memory/engine-compat.d.ts.map +1 -1
  103. package/dist/memory/engine-compat.js +65 -7
  104. package/dist/memory/engine-compat.js.map +1 -1
  105. package/dist/memory/extraction-gate.js +3 -3
  106. package/dist/memory/extraction-gate.js.map +1 -1
  107. package/dist/memory/graph-memory-bridge.js +9 -9
  108. package/dist/memory/graph-memory-bridge.js.map +1 -1
  109. package/dist/memory/graph-queries.js +4 -4
  110. package/dist/memory/graph-queries.js.map +1 -1
  111. package/dist/memory/llm-extraction.js +1 -1
  112. package/dist/memory/llm-extraction.js.map +1 -1
  113. package/dist/memory/memory-bridge.js +1 -1
  114. package/dist/memory/memory-bridge.js.map +1 -1
  115. package/dist/memory/nexus-plasticity.js +1 -1
  116. package/dist/memory/nexus-plasticity.js.map +1 -1
  117. package/dist/memory/observer-reflector.js +1 -1
  118. package/dist/memory/observer-reflector.js.map +1 -1
  119. package/dist/memory/pipeline-manifest-sqlite.d.ts.map +1 -1
  120. package/dist/memory/pipeline-manifest-sqlite.js +13 -3
  121. package/dist/memory/pipeline-manifest-sqlite.js.map +1 -1
  122. package/dist/memory/quality-feedback.js +4 -4
  123. package/dist/memory/quality-feedback.js.map +1 -1
  124. package/dist/memory/retrieval/increment-citation-counts.js +1 -1
  125. package/dist/memory/retrieval/increment-citation-counts.js.map +1 -1
  126. package/dist/memory/retrieval/log-retrieval.js +1 -1
  127. package/dist/memory/retrieval/log-retrieval.js.map +1 -1
  128. package/dist/memory/retrieval/observe.js +1 -1
  129. package/dist/memory/retrieval/observe.js.map +1 -1
  130. package/dist/memory/retrieval/search.js +1 -1
  131. package/dist/memory/retrieval/search.js.map +1 -1
  132. package/dist/memory/retrieval/timeline.js +1 -1
  133. package/dist/memory/retrieval/timeline.js.map +1 -1
  134. package/dist/memory/sleep-consolidation.js +4 -4
  135. package/dist/memory/sleep-consolidation.js.map +1 -1
  136. package/dist/memory/temporal-supersession.js +5 -5
  137. package/dist/memory/temporal-supersession.js.map +1 -1
  138. package/dist/memory/transcript-extractor.js +1 -1
  139. package/dist/memory/transcript-extractor.js.map +1 -1
  140. package/dist/memory/transcript-ingestor.js +1 -1
  141. package/dist/memory/transcript-ingestor.js.map +1 -1
  142. package/dist/memory/transcript-scanner.js +1 -1
  143. package/dist/memory/transcript-scanner.js.map +1 -1
  144. package/dist/nexus/analyze-orchestrator.d.ts.map +1 -1
  145. package/dist/nexus/analyze-orchestrator.js +28 -0
  146. package/dist/nexus/analyze-orchestrator.js.map +1 -1
  147. package/dist/nexus/context.d.ts.map +1 -1
  148. package/dist/nexus/context.js +3 -3
  149. package/dist/nexus/context.js.map +1 -1
  150. package/dist/nexus/impact.d.ts.map +1 -1
  151. package/dist/nexus/impact.js +3 -3
  152. package/dist/nexus/impact.js.map +1 -1
  153. package/dist/nexus/living-brain.js +7 -7
  154. package/dist/nexus/living-brain.js.map +1 -1
  155. package/dist/nexus/symbol-miss.d.ts +132 -0
  156. package/dist/nexus/symbol-miss.d.ts.map +1 -0
  157. package/dist/nexus/symbol-miss.js +168 -0
  158. package/dist/nexus/symbol-miss.js.map +1 -0
  159. package/dist/nexus/tasks-bridge.js +4 -4
  160. package/dist/nexus/tasks-bridge.js.map +1 -1
  161. package/dist/orchestrate/spawn-ops.d.ts +21 -1
  162. package/dist/orchestrate/spawn-ops.d.ts.map +1 -1
  163. package/dist/orchestrate/spawn-ops.js +39 -2
  164. package/dist/orchestrate/spawn-ops.js.map +1 -1
  165. package/dist/orchestrate/worker-verify.d.ts.map +1 -1
  166. package/dist/orchestrate/worker-verify.js +22 -0
  167. package/dist/orchestrate/worker-verify.js.map +1 -1
  168. package/dist/release/changesets-aggregator.d.ts.map +1 -1
  169. package/dist/release/changesets-aggregator.js +15 -1
  170. package/dist/release/changesets-aggregator.js.map +1 -1
  171. package/dist/release/open.d.ts +29 -2
  172. package/dist/release/open.d.ts.map +1 -1
  173. package/dist/release/open.js +48 -11
  174. package/dist/release/open.js.map +1 -1
  175. package/dist/release/reconcile.d.ts.map +1 -1
  176. package/dist/release/reconcile.js +5 -1
  177. package/dist/release/reconcile.js.map +1 -1
  178. package/dist/resources/governor.d.ts +12 -2
  179. package/dist/resources/governor.d.ts.map +1 -1
  180. package/dist/resources/governor.js +12 -3
  181. package/dist/resources/governor.js.map +1 -1
  182. package/dist/sagas/migrate-containment.d.ts.map +1 -1
  183. package/dist/sagas/migrate-containment.js +4 -2
  184. package/dist/sagas/migrate-containment.js.map +1 -1
  185. package/dist/scaffold/ensure-dirs.d.ts.map +1 -1
  186. package/dist/scaffold/ensure-dirs.js +15 -3
  187. package/dist/scaffold/ensure-dirs.js.map +1 -1
  188. package/dist/scaffold/project-detection.d.ts.map +1 -1
  189. package/dist/scaffold/project-detection.js +2 -1
  190. package/dist/scaffold/project-detection.js.map +1 -1
  191. package/dist/selfimprove/draft-pr.d.ts +14 -1
  192. package/dist/selfimprove/draft-pr.d.ts.map +1 -1
  193. package/dist/selfimprove/draft-pr.js.map +1 -1
  194. package/dist/selfimprove/fix-gen.d.ts +0 -21
  195. package/dist/selfimprove/fix-gen.d.ts.map +1 -1
  196. package/dist/selfimprove/fix-gen.js +509 -173
  197. package/dist/selfimprove/fix-gen.js.map +3 -3
  198. package/dist/selfimprove/run-loop.d.ts.map +1 -1
  199. package/dist/selfimprove/run-loop.js +50 -19
  200. package/dist/selfimprove/run-loop.js.map +1 -1
  201. package/dist/selfimprove/scenarios/dhq-replay-find/golden.json +114 -4
  202. package/dist/selfimprove/scenarios/dhq-replay-find/scenario.json +3 -3
  203. package/dist/sentient/dream-cycle.d.ts +20 -19
  204. package/dist/sentient/dream-cycle.d.ts.map +1 -1
  205. package/dist/sentient/dream-cycle.js +323 -12
  206. package/dist/sentient/dream-cycle.js.map +1 -1
  207. package/dist/sentient/dream-watermark.d.ts +134 -0
  208. package/dist/sentient/dream-watermark.d.ts.map +1 -0
  209. package/dist/sentient/dream-watermark.js +156 -0
  210. package/dist/sentient/dream-watermark.js.map +1 -0
  211. package/dist/sentient/hygiene-scan.js +1 -1
  212. package/dist/sentient/hygiene-scan.js.map +1 -1
  213. package/dist/sentient/propose-tick.js +3 -3
  214. package/dist/sentient/propose-tick.js.map +1 -1
  215. package/dist/sentient/stage-drift-tick.js +1 -1
  216. package/dist/sentient/stage-drift-tick.js.map +1 -1
  217. package/dist/sentient/state.d.ts +17 -0
  218. package/dist/sentient/state.d.ts.map +1 -1
  219. package/dist/sentient/state.js +22 -3
  220. package/dist/sentient/state.js.map +1 -1
  221. package/dist/sentient/tick.d.ts.map +1 -1
  222. package/dist/sentient/tick.js +79 -2
  223. package/dist/sentient/tick.js.map +1 -1
  224. package/dist/sequence/index.js +1 -1
  225. package/dist/sequence/index.js.map +1 -1
  226. package/dist/sessions/index.d.ts.map +1 -1
  227. package/dist/sessions/index.js +5 -1
  228. package/dist/sessions/index.js.map +1 -1
  229. package/dist/sessions/snapshot.d.ts.map +1 -1
  230. package/dist/sessions/snapshot.js +6 -3
  231. package/dist/sessions/snapshot.js.map +1 -1
  232. package/dist/store/agent-registry-store.d.ts.map +1 -1
  233. package/dist/store/agent-registry-store.js +71 -28
  234. package/dist/store/agent-registry-store.js.map +1 -1
  235. package/dist/store/attachment-store.js +3 -3
  236. package/dist/store/attachment-store.js.map +1 -1
  237. package/dist/store/checkpoint-git-dir.d.ts +95 -0
  238. package/dist/store/checkpoint-git-dir.d.ts.map +1 -0
  239. package/dist/store/checkpoint-git-dir.js +111 -0
  240. package/dist/store/checkpoint-git-dir.js.map +1 -0
  241. package/dist/store/conduit-sqlite.d.ts +21 -1
  242. package/dist/store/conduit-sqlite.d.ts.map +1 -1
  243. package/dist/store/conduit-sqlite.js +42 -56
  244. package/dist/store/conduit-sqlite.js.map +1 -1
  245. package/dist/store/dual-scope-db.d.ts +39 -0
  246. package/dist/store/dual-scope-db.d.ts.map +1 -1
  247. package/dist/store/dual-scope-db.js +26 -8
  248. package/dist/store/dual-scope-db.js.map +1 -1
  249. package/dist/store/git-checkpoint.d.ts.map +1 -1
  250. package/dist/store/git-checkpoint.js +6 -5
  251. package/dist/store/git-checkpoint.js.map +1 -1
  252. package/dist/store/memory-sqlite.d.ts +57 -3
  253. package/dist/store/memory-sqlite.d.ts.map +1 -1
  254. package/dist/store/memory-sqlite.js +70 -89
  255. package/dist/store/memory-sqlite.js.map +1 -1
  256. package/dist/store/nexus-sqlite.d.ts +42 -0
  257. package/dist/store/nexus-sqlite.d.ts.map +1 -1
  258. package/dist/store/nexus-sqlite.js +79 -115
  259. package/dist/store/nexus-sqlite.js.map +1 -1
  260. package/dist/store/ports/domain-binding.d.ts +233 -0
  261. package/dist/store/ports/domain-binding.d.ts.map +1 -0
  262. package/dist/store/ports/domain-binding.js +500 -0
  263. package/dist/store/ports/domain-binding.js.map +1 -0
  264. package/dist/store/ports/fk-integrity.d.ts +155 -0
  265. package/dist/store/ports/fk-integrity.d.ts.map +1 -0
  266. package/dist/store/ports/fk-integrity.js +182 -0
  267. package/dist/store/ports/fk-integrity.js.map +1 -0
  268. package/dist/store/role-accessors-impl.js +2 -2
  269. package/dist/store/role-accessors-impl.js.map +1 -1
  270. package/dist/store/skills-db.d.ts +19 -0
  271. package/dist/store/skills-db.d.ts.map +1 -1
  272. package/dist/store/skills-db.js +80 -72
  273. package/dist/store/skills-db.js.map +1 -1
  274. package/dist/store/sqlite-backup.js +2 -2
  275. package/dist/store/sqlite-backup.js.map +1 -1
  276. package/dist/store/sqlite-data-accessor.js +1 -1
  277. package/dist/store/sqlite-data-accessor.js.map +1 -1
  278. package/dist/store/sqlite.d.ts +72 -10
  279. package/dist/store/sqlite.d.ts.map +1 -1
  280. package/dist/store/sqlite.js +173 -160
  281. package/dist/store/sqlite.js.map +1 -1
  282. package/dist/store/tasks-sqlite.js +2 -2
  283. package/dist/store/tasks-sqlite.js.map +1 -1
  284. package/dist/system/health.d.ts +0 -4
  285. package/dist/system/health.d.ts.map +1 -1
  286. package/dist/system/health.js +60 -3
  287. package/dist/system/health.js.map +1 -1
  288. package/dist/tasks/add.d.ts.map +1 -1
  289. package/dist/tasks/add.js +40 -4
  290. package/dist/tasks/add.js.map +1 -1
  291. package/dist/tasks/collection.d.ts +51 -0
  292. package/dist/tasks/collection.d.ts.map +1 -0
  293. package/dist/tasks/collection.js +81 -0
  294. package/dist/tasks/collection.js.map +1 -0
  295. package/dist/tasks/complete.d.ts.map +1 -1
  296. package/dist/tasks/complete.js +8 -3
  297. package/dist/tasks/complete.js.map +1 -1
  298. package/dist/tasks/evidence.d.ts.map +1 -1
  299. package/dist/tasks/evidence.js +17 -0
  300. package/dist/tasks/evidence.js.map +1 -1
  301. package/dist/tasks/find.d.ts +50 -0
  302. package/dist/tasks/find.d.ts.map +1 -1
  303. package/dist/tasks/find.js +63 -2
  304. package/dist/tasks/find.js.map +1 -1
  305. package/dist/tasks/tool-resolver.d.ts +1 -1
  306. package/dist/tasks/tool-resolver.d.ts.map +1 -1
  307. package/dist/tasks/tool-resolver.js +83 -0
  308. package/dist/tasks/tool-resolver.js.map +1 -1
  309. package/dist/tasks/tool-semaphore.d.ts +82 -12
  310. package/dist/tasks/tool-semaphore.d.ts.map +1 -1
  311. package/dist/tasks/tool-semaphore.js +79 -17
  312. package/dist/tasks/tool-semaphore.js.map +1 -1
  313. package/dist/upgrade.js +2 -2
  314. package/dist/upgrade.js.map +1 -1
  315. package/dist/validation/doctor/checks.d.ts +23 -1
  316. package/dist/validation/doctor/checks.d.ts.map +1 -1
  317. package/dist/validation/doctor/checks.js +79 -19
  318. package/dist/validation/doctor/checks.js.map +1 -1
  319. package/dist/worktree/list.js +1 -1
  320. package/dist/worktree/list.js.map +1 -1
  321. package/package.json +23 -13
  322. package/templates/CLEO-INJECTION.md +40 -25
  323. package/templates/workflows/release-prepare.yml.tmpl +73 -16
@@ -10019,6 +10019,27 @@ var init_operations_registry = __esm({
10019
10019
  type: "boolean",
10020
10020
  required: false,
10021
10021
  description: "Commit plan file before dispatching"
10022
+ },
10023
+ // T12089: the plan SCOPE. The workflow regenerates the plan when no
10024
+ // committed plan is supplied, and `cleo release plan` requires
10025
+ // `--saga | --epic | --tasks` — so without one of these the dispatched
10026
+ // run dies at "Prepare bump-PR" after a fully green preflight.
10027
+ //
10028
+ // A param absent from this registry is STRIPPED before the domain handler
10029
+ // sees it, silently. `--tasks` was accepted by the CLI, forwarded by the
10030
+ // handler and by `releaseOpen`, and still arrived empty at the workflow
10031
+ // because this declaration was the fourth hop in the chain.
10032
+ {
10033
+ name: "epic",
10034
+ type: "string",
10035
+ required: false,
10036
+ description: "Epic task ID forwarded as the plan scope (e.g. T9999)"
10037
+ },
10038
+ {
10039
+ name: "tasks",
10040
+ type: "string",
10041
+ required: false,
10042
+ description: "Comma-separated task IDs forwarded as the plan scope for a task-scoped release"
10022
10043
  }
10023
10044
  ]
10024
10045
  },
@@ -15670,6 +15691,25 @@ var init_service_provider = __esm({
15670
15691
  }
15671
15692
  });
15672
15693
 
15694
+ // packages/contracts/src/caamp-markers.ts
15695
+ var H, damagedMarkerSource, CAAMP_DAMAGED_START_PATTERN_SOURCE, CAAMP_DAMAGED_END_PATTERN_SOURCE;
15696
+ var init_caamp_markers = __esm({
15697
+ "packages/contracts/src/caamp-markers.ts"() {
15698
+ "use strict";
15699
+ H = "[ \\t\\r]";
15700
+ damagedMarkerSource = (keyword) => `^${H}*[<!-]{1,4}${H}*CAAMP${H}*:${H}*${keyword}${H}*[->]{1,3}${H}*$`;
15701
+ CAAMP_DAMAGED_START_PATTERN_SOURCE = damagedMarkerSource("START");
15702
+ CAAMP_DAMAGED_END_PATTERN_SOURCE = damagedMarkerSource("END");
15703
+ }
15704
+ });
15705
+
15706
+ // packages/contracts/src/collection-keys.ts
15707
+ var init_collection_keys = __esm({
15708
+ "packages/contracts/src/collection-keys.ts"() {
15709
+ "use strict";
15710
+ }
15711
+ });
15712
+
15673
15713
  // packages/contracts/src/index.ts
15674
15714
  var init_src = __esm({
15675
15715
  "packages/contracts/src/index.ts"() {
@@ -15737,6 +15777,8 @@ var init_src = __esm({
15737
15777
  init_validator();
15738
15778
  init_service_provider();
15739
15779
  init_workgraph();
15780
+ init_caamp_markers();
15781
+ init_collection_keys();
15740
15782
  }
15741
15783
  });
15742
15784
 
@@ -17629,7 +17671,7 @@ var init_sql = __esm({
17629
17671
  return new SQL([new StringChunk(str)]);
17630
17672
  }
17631
17673
  _sql.raw = raw;
17632
- function join25(chunks, separator) {
17674
+ function join26(chunks, separator) {
17633
17675
  const result = [];
17634
17676
  for (const [i, chunk] of chunks.entries()) {
17635
17677
  if (i > 0 && separator !== void 0) result.push(separator);
@@ -17637,7 +17679,7 @@ var init_sql = __esm({
17637
17679
  }
17638
17680
  return new SQL(result);
17639
17681
  }
17640
- _sql.join = join25;
17682
+ _sql.join = join26;
17641
17683
  function identifier(value) {
17642
17684
  return new Name(value);
17643
17685
  }
@@ -19652,7 +19694,7 @@ var init_select = __esm({
19652
19694
  const baseTableName = this.tableName;
19653
19695
  const tableName = getTableLikeName(table);
19654
19696
  for (const item of extractUsedTable(table)) this.usedTables.add(item);
19655
- if (typeof tableName === "string" && this.config.joins?.some((join25) => join25.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
19697
+ if (typeof tableName === "string" && this.config.joins?.some((join26) => join26.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
19656
19698
  if (!this.isPartialSelect) {
19657
19699
  if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
19658
19700
  if (typeof tableName === "string" && !is(table, SQL)) {
@@ -21249,7 +21291,7 @@ var init_dialect = __esm({
21249
21291
  if (!joins2) return;
21250
21292
  const withEntries = Object.entries(joins2).filter(([_, v]) => v);
21251
21293
  if (!withEntries.length) return;
21252
- return sql.join(withEntries.map(([k, join25]) => {
21294
+ return sql.join(withEntries.map(([k, join26]) => {
21253
21295
  const relation = tableConfig.relations[k];
21254
21296
  const isSingle2 = is(relation, One);
21255
21297
  const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
@@ -21260,7 +21302,7 @@ var init_dialect = __esm({
21260
21302
  table: targetTable,
21261
21303
  mode: isSingle2 ? "first" : "many",
21262
21304
  schema,
21263
- queryConfig: join25,
21305
+ queryConfig: join26,
21264
21306
  tableConfig: schema[relation.targetTableName],
21265
21307
  relationWhere: filter,
21266
21308
  isNested: true,
@@ -21274,7 +21316,7 @@ var init_dialect = __esm({
21274
21316
  key: k,
21275
21317
  selection: innerQuery.selection,
21276
21318
  isArray: !isSingle2,
21277
- isOptional: (relation.optional ?? false) || join25 !== true && !!join25.where
21319
+ isOptional: (relation.optional ?? false) || join26 !== true && !!join26.where
21278
21320
  });
21279
21321
  const jsonColumns = sql.join(innerQuery.selection.map((s) => {
21280
21322
  return sql`${sql.raw(this.escapeString(s.key))}, ${s.selection ? sql`${jsonb2}(${sql.identifier(s.key)})` : sql.identifier(s.key)}`;
@@ -21696,7 +21738,7 @@ var init_update = __esm({
21696
21738
  createJoin(joinType) {
21697
21739
  return ((table, on) => {
21698
21740
  const tableName = getTableLikeName(table);
21699
- if (typeof tableName === "string" && this.config.joins.some((join25) => join25.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
21741
+ if (typeof tableName === "string" && this.config.joins.some((join26) => join26.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
21700
21742
  if (typeof on === "function") {
21701
21743
  const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
21702
21744
  on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
@@ -22852,7 +22894,7 @@ async function withWriteRetry(fn, opts = {}) {
22852
22894
  throw contentionErr;
22853
22895
  }
22854
22896
  function sleep(ms) {
22855
- return new Promise((resolve7) => setTimeout(resolve7, ms));
22897
+ return new Promise((resolve8) => setTimeout(resolve8, ms));
22856
22898
  }
22857
22899
  var DEFAULT_MAX_ATTEMPTS, DEFAULT_BASE_DELAY_MS, DEFAULT_JITTER_MS;
22858
22900
  var init_with_retry = __esm({
@@ -23673,7 +23715,7 @@ function resolveDbIdentity(db) {
23673
23715
  return identity;
23674
23716
  }
23675
23717
  function sleepAsync(ms) {
23676
- return new Promise((resolve7) => setTimeout(resolve7, Math.max(0, Math.round(ms))));
23718
+ return new Promise((resolve8) => setTimeout(resolve8, Math.max(0, Math.round(ms))));
23677
23719
  }
23678
23720
  function isPidAlive(pid) {
23679
23721
  try {
@@ -24491,7 +24533,7 @@ async function sendResourceRelease(socketPath, cls, holderId) {
24491
24533
  return { unavailable: true, reason: `unexpected response kind: ${result.kind}` };
24492
24534
  }
24493
24535
  function sendLeaseRequest(socketPath, request, expectedKind) {
24494
- return new Promise((resolve7) => {
24536
+ return new Promise((resolve8) => {
24495
24537
  const id = `ra-${process.pid}-${request.kind}`;
24496
24538
  const envelope = LeaseIpcRequestEnvelopeSchema.parse({
24497
24539
  protocol_version: LEASE_IPC_PROTOCOL_VERSION,
@@ -24509,7 +24551,7 @@ function sendLeaseRequest(socketPath, request, expectedKind) {
24509
24551
  settled = true;
24510
24552
  socket.removeAllListeners();
24511
24553
  socket.destroy();
24512
- resolve7(value);
24554
+ resolve8(value);
24513
24555
  };
24514
24556
  const degrade = (reason) => done({ unavailable: true, reason });
24515
24557
  socket.setTimeout(REQUEST_TIMEOUT_MS);
@@ -24632,7 +24674,9 @@ function computeClassBudget(cls, sample, opts = {}) {
24632
24674
  return Math.max(1, cpus - 2);
24633
24675
  case "test-run":
24634
24676
  case "scoped-build": {
24635
- const base = Math.max(1, Math.floor(cpus / 4));
24677
+ const estRamBytes = (opts.testRunEstRamMb ?? 24576) * MB;
24678
+ const byMem = Math.floor((availBytes - headroomBytes) / estRamBytes);
24679
+ const base = clamp(1, byMem, Math.max(1, Math.floor(cpus / 4)));
24636
24680
  if (some > floor) return 1;
24637
24681
  if (some > hold) return Math.max(1, Math.floor(base / 2));
24638
24682
  return base;
@@ -25125,6 +25169,11 @@ var init_registry = __esm({
25125
25169
  * });
25126
25170
  * ```
25127
25171
  */
25172
+ // T12071: keyed on the EVENT so the payload shape is checked against
25173
+ // `HookEventPayloadMap`. The previous `<T extends HookPayload>` form inferred
25174
+ // T from the argument, relating the event and the payload not at all — which
25175
+ // is how `PostToolUse` came to be dispatched with `newStatus` instead of
25176
+ // `status` and filled 29% of BRAIN with "status: undefined".
25128
25177
  async dispatch(event, projectRoot, payload) {
25129
25178
  if (!this.config.enabled) return;
25130
25179
  const resolvedEvent = this.resolveEvent(event);
@@ -28062,8 +28111,8 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
28062
28111
  }
28063
28112
  let initResolve = null;
28064
28113
  let initReject = null;
28065
- const initPromise = new Promise((resolve7, reject) => {
28066
- initResolve = resolve7;
28114
+ const initPromise = new Promise((resolve8, reject) => {
28115
+ initResolve = resolve8;
28067
28116
  initReject = reject;
28068
28117
  });
28069
28118
  _cache.set(key, {
@@ -28316,24 +28365,35 @@ var init_dual_scope_db = __esm({
28316
28365
  async openProject(dbPath, options) {
28317
28366
  const normalized = resolve3(dbPath);
28318
28367
  if (options?.dedicated) {
28319
- const handle = await openDualScopeDbAtPath("project", normalized, void 0, {
28368
+ const handle = await openDualScopeDbAtPath("project", normalized, options?.exodusCwd, {
28320
28369
  dedicated: true
28321
28370
  });
28322
28371
  return this.buildStore("project", handle, 0);
28323
28372
  }
28324
- return this.openEntry("project", normalized);
28373
+ return this.openEntry("project", normalized, 0, options?.exodusCwd);
28325
28374
  }
28326
28375
  /** @inheritdoc */
28327
28376
  async openGlobal(options) {
28328
28377
  const dbPath = resolveDualScopeDbPath("global");
28329
28378
  const normalized = resolve3(dbPath);
28330
28379
  if (options?.dedicated) {
28331
- const handle = await openDualScopeDbAtPath("global", normalized, void 0, {
28380
+ const handle = await openDualScopeDbAtPath("global", normalized, options?.exodusCwd, {
28332
28381
  dedicated: true
28333
28382
  });
28334
28383
  return this.buildStore("global", handle, 0);
28335
28384
  }
28336
- return this.openEntry("global", normalized);
28385
+ return this.openEntry("global", normalized, 0, options?.exodusCwd);
28386
+ }
28387
+ /** @inheritdoc */
28388
+ async openGlobalAt(dbPath, options) {
28389
+ const normalized = resolve3(dbPath);
28390
+ if (options?.dedicated) {
28391
+ const handle = await openDualScopeDbAtPath("global", normalized, options?.exodusCwd, {
28392
+ dedicated: true
28393
+ });
28394
+ return this.buildStore("global", handle, 0);
28395
+ }
28396
+ return this.openEntry("global", normalized, 0, options?.exodusCwd);
28337
28397
  }
28338
28398
  /** @inheritdoc */
28339
28399
  closeProject(dbPath) {
@@ -28359,7 +28419,7 @@ var init_dual_scope_db = __esm({
28359
28419
  * retry calls this with `depth + 1`. A second dead handle at depth 1
28360
28420
  * throws {@link LivenessExhaustedError} instead of recursing further.
28361
28421
  */
28362
- async openEntry(scope, dbPath, depth = 0) {
28422
+ async openEntry(scope, dbPath, depth = 0, exodusCwd) {
28363
28423
  const key = cacheKey(scope, dbPath);
28364
28424
  const existing = this._registry.get(key);
28365
28425
  if (existing) {
@@ -28374,8 +28434,8 @@ var init_dual_scope_db = __esm({
28374
28434
  const entryId = ++this._nextId;
28375
28435
  let initResolve;
28376
28436
  let initReject;
28377
- const initPromise = new Promise((resolve7, reject) => {
28378
- initResolve = resolve7;
28437
+ const initPromise = new Promise((resolve8, reject) => {
28438
+ initResolve = resolve8;
28379
28439
  initReject = reject;
28380
28440
  });
28381
28441
  this._registry.set(key, { id: entryId, store: null, initPromise });
@@ -28386,7 +28446,7 @@ var init_dual_scope_db = __esm({
28386
28446
  }
28387
28447
  });
28388
28448
  try {
28389
- const dualHandle = scope === "project" ? await this.openDualScopeFn("project", dbPath) : await this.openDualScopeFn("global", dbPath);
28449
+ const dualHandle = scope === "project" ? await this.openDualScopeFn("project", dbPath, exodusCwd) : await this.openDualScopeFn("global", dbPath, exodusCwd);
28390
28450
  const current = this._registry.get(key);
28391
28451
  if (!current || current.id !== entryId) {
28392
28452
  throw new EntryCancelledError(scope, dbPath);
@@ -28397,7 +28457,7 @@ var init_dual_scope_db = __esm({
28397
28457
  if (depth >= 1) {
28398
28458
  throw new LivenessExhaustedError(scope, dbPath);
28399
28459
  }
28400
- const retryStore = await this.openEntry(scope, dbPath, depth + 1);
28460
+ const retryStore = await this.openEntry(scope, dbPath, depth + 1, exodusCwd);
28401
28461
  initResolve(retryStore);
28402
28462
  return retryStore;
28403
28463
  }
@@ -28493,6 +28553,197 @@ var init_dual_scope_db = __esm({
28493
28553
  }
28494
28554
  });
28495
28555
 
28556
+ // packages/core/src/store/ports/domain-binding.ts
28557
+ import { resolve as resolve4 } from "node:path";
28558
+ function getCleoRuntime() {
28559
+ if (!_runtime) {
28560
+ _runtime = createCleoRuntime();
28561
+ }
28562
+ return _runtime;
28563
+ }
28564
+ function resetCleoRuntime() {
28565
+ releaseAllDomainBindings();
28566
+ if (_runtime) {
28567
+ try {
28568
+ _runtime.closeAll();
28569
+ } catch {
28570
+ }
28571
+ _runtime = null;
28572
+ }
28573
+ }
28574
+ function bindingKey(scope, dbPath, domain) {
28575
+ return `${scope}::${dbPath}::${domain}`;
28576
+ }
28577
+ function nativeOf(store) {
28578
+ const native = store.db.$client;
28579
+ if (!native) {
28580
+ throw new Error(
28581
+ `T12037: CleoRuntime store for ${store.scope}::${store.dbPath} exposed no $client \u2014 cannot bind a domain schema to it.`
28582
+ );
28583
+ }
28584
+ return native;
28585
+ }
28586
+ function reuseValid(key, store) {
28587
+ const row = _bindings.get(key);
28588
+ if (!row) return void 0;
28589
+ if (row.store !== store || !store.isOpen || !row.native.isOpen) {
28590
+ _bindings.delete(key);
28591
+ return void 0;
28592
+ }
28593
+ return row;
28594
+ }
28595
+ async function bindAgainst(key, store, establish) {
28596
+ const cached = reuseValid(key, store);
28597
+ if (cached) return cached;
28598
+ const pending = _inflight.get(key);
28599
+ if (pending) {
28600
+ const row = await pending;
28601
+ if (row.store === store && row.native.isOpen) return row;
28602
+ return bindAgainst(key, store, establish);
28603
+ }
28604
+ const native = nativeOf(store);
28605
+ const flight = (async () => {
28606
+ const db = await establish(native, store);
28607
+ const row = { store, native, db };
28608
+ if (store.isOpen && native.isOpen) {
28609
+ _bindings.set(key, row);
28610
+ }
28611
+ return row;
28612
+ })();
28613
+ _inflight.set(key, flight);
28614
+ try {
28615
+ return await flight;
28616
+ } finally {
28617
+ if (_inflight.get(key) === flight) {
28618
+ _inflight.delete(key);
28619
+ }
28620
+ }
28621
+ }
28622
+ async function bindLive(scope, key, dbPath, openStore, establish) {
28623
+ let lastError;
28624
+ for (let attempt = 0; attempt < MAX_LIVENESS_ATTEMPTS; attempt += 1) {
28625
+ let store;
28626
+ try {
28627
+ store = await openStore();
28628
+ } catch (err) {
28629
+ lastError = err;
28630
+ releaseDomainBindings({ scope, dbPath });
28631
+ if (attempt + 1 >= MAX_LIVENESS_ATTEMPTS) throw err;
28632
+ continue;
28633
+ }
28634
+ try {
28635
+ const row = await bindAgainst(key, store, establish);
28636
+ if (row.store.isOpen && row.native.isOpen) return row;
28637
+ } catch (err) {
28638
+ lastError = err;
28639
+ if (store.isOpen) throw err;
28640
+ }
28641
+ releaseDomainBindings({ scope, dbPath });
28642
+ try {
28643
+ store.close();
28644
+ } catch {
28645
+ }
28646
+ }
28647
+ if (lastError !== void 0) throw lastError;
28648
+ throw new Error(
28649
+ `T12037: could not bind ${key} over a live connection after ${MAX_LIVENESS_ATTEMPTS} attempts \u2014 the consolidated handle was closed each time.`
28650
+ );
28651
+ }
28652
+ async function bindProjectDomain(domain, cwd, establish) {
28653
+ const dbPath = resolve4(resolveDualScopeDbPath("project", cwd));
28654
+ const row = await bindLive(
28655
+ "project",
28656
+ bindingKey("project", dbPath, domain),
28657
+ dbPath,
28658
+ () => getCleoRuntime().openProject(dbPath, { exodusCwd: cwd }),
28659
+ establish
28660
+ );
28661
+ return row;
28662
+ }
28663
+ async function bindGlobalDomain(domain, establish, cwd) {
28664
+ const dbPath = resolve4(resolveDualScopeDbPath("global"));
28665
+ const row = await bindLive(
28666
+ "global",
28667
+ bindingKey("global", dbPath, domain),
28668
+ dbPath,
28669
+ () => getCleoRuntime().openGlobal({ exodusCwd: cwd }),
28670
+ establish
28671
+ );
28672
+ return row;
28673
+ }
28674
+ async function bindGlobalDomainAtPath(domain, dbPath, establish) {
28675
+ const normalized = resolve4(dbPath);
28676
+ const row = await bindLive(
28677
+ "global",
28678
+ bindingKey("global", normalized, domain),
28679
+ normalized,
28680
+ () => getCleoRuntime().openGlobalAt(normalized),
28681
+ establish
28682
+ );
28683
+ return row;
28684
+ }
28685
+ function peekDomainAtPath(scope, dbPath, domain) {
28686
+ const row = _bindings.get(bindingKey(scope, resolve4(dbPath), domain));
28687
+ if (!row?.native.isOpen) return null;
28688
+ return row;
28689
+ }
28690
+ function releaseDomainBindings(filter) {
28691
+ if (!filter) {
28692
+ _bindings.clear();
28693
+ return;
28694
+ }
28695
+ const wantPath = filter.dbPath === void 0 ? void 0 : resolve4(filter.dbPath);
28696
+ for (const key of [..._bindings.keys()]) {
28697
+ const sep2 = key.indexOf("::");
28698
+ const lastSep = key.lastIndexOf("::");
28699
+ const scope = key.slice(0, sep2);
28700
+ const dbPath = key.slice(sep2 + 2, lastSep);
28701
+ const domain = key.slice(lastSep + 2);
28702
+ if (filter.scope !== void 0 && scope !== filter.scope) continue;
28703
+ if (wantPath !== void 0 && dbPath !== wantPath) continue;
28704
+ if (filter.domain !== void 0 && domain !== filter.domain) continue;
28705
+ _bindings.delete(key);
28706
+ }
28707
+ }
28708
+ function releaseAllDomainBindings() {
28709
+ _bindings.clear();
28710
+ }
28711
+ function boundProjectNative(domain, cwd) {
28712
+ return peekProjectDomain(domain, cwd)?.native ?? null;
28713
+ }
28714
+ function peekProjectDomain(domain, cwd) {
28715
+ const dbPath = resolve4(resolveDualScopeDbPath("project", cwd));
28716
+ const row = _bindings.get(bindingKey("project", dbPath, domain));
28717
+ if (row?.native.isOpen) return row;
28718
+ if (cwd !== void 0) return null;
28719
+ const suffix = `::${domain}`;
28720
+ let sole;
28721
+ for (const [key, candidate] of _bindings) {
28722
+ if (!key.startsWith("project::") || !key.endsWith(suffix)) continue;
28723
+ if (!candidate.native.isOpen) continue;
28724
+ if (sole) return null;
28725
+ sole = candidate;
28726
+ }
28727
+ return sole ?? null;
28728
+ }
28729
+ function peekGlobalDomain(domain) {
28730
+ const dbPath = resolve4(resolveDualScopeDbPath("global"));
28731
+ const row = _bindings.get(bindingKey("global", dbPath, domain));
28732
+ if (!row || !row.native.isOpen) return null;
28733
+ return row;
28734
+ }
28735
+ var _runtime, _bindings, _inflight, MAX_LIVENESS_ATTEMPTS;
28736
+ var init_domain_binding = __esm({
28737
+ "packages/core/src/store/ports/domain-binding.ts"() {
28738
+ "use strict";
28739
+ init_dual_scope_db();
28740
+ _runtime = null;
28741
+ _bindings = /* @__PURE__ */ new Map();
28742
+ _inflight = /* @__PURE__ */ new Map();
28743
+ MAX_LIVENESS_ATTEMPTS = 2;
28744
+ }
28745
+ });
28746
+
28496
28747
  // packages/core/src/store/schema/nexus-schema.ts
28497
28748
  var nexus_schema_exports = {};
28498
28749
  __export(nexus_schema_exports, {
@@ -29001,6 +29252,7 @@ var nexus_sqlite_exports = {};
29001
29252
  __export(nexus_sqlite_exports, {
29002
29253
  NEXUS_SCHEMA_VERSION: () => NEXUS_SCHEMA_VERSION,
29003
29254
  _resetNestedNexusWarningGate: () => _resetNestedNexusWarningGate,
29255
+ bindNexusDomain: () => bindNexusDomain,
29004
29256
  closeNexusDb: () => closeNexusDb,
29005
29257
  detectAndWarnOnNestedNexus: () => detectAndWarnOnNestedNexus,
29006
29258
  getNestedNexusSentinelPath: () => getNestedNexusSentinelPath,
@@ -29209,13 +29461,13 @@ function ensureNexusRelationWeights(nativeDb) {
29209
29461
  nativeDb.exec(`PRAGMA foreign_keys=${fkWasOn ? "ON" : "OFF"}`);
29210
29462
  }
29211
29463
  }
29212
- function runNexusMigrations(nativeDb, db) {
29464
+ function runNexusMigrations(nativeDb, db, dbPath) {
29213
29465
  const migrationsFolder = resolveNexusMigrationsFolder();
29214
- if (tableExists4(nativeDb, "nexus_nodes") && _nexusDbPath) {
29215
- const backupPath = _nexusDbPath.replace(/\.db$/, "-pre-cleo.db.bak");
29466
+ if (tableExists4(nativeDb, "nexus_nodes")) {
29467
+ const backupPath = dbPath.replace(/\.db$/, "-pre-cleo.db.bak");
29216
29468
  if (!existsSync16(backupPath)) {
29217
29469
  try {
29218
- copyFileSync4(_nexusDbPath, backupPath);
29470
+ copyFileSync4(dbPath, backupPath);
29219
29471
  } catch {
29220
29472
  }
29221
29473
  }
@@ -29257,75 +29509,45 @@ function runNexusMigrations(nativeDb, db) {
29257
29509
  ensureNexusFts5(nativeDb);
29258
29510
  }
29259
29511
  async function getNexusDb() {
29260
- const requestedPath = getNexusDbPath();
29512
+ return (await bindNexusDomain()).db.drizzle;
29513
+ }
29514
+ async function bindNexusDomain() {
29261
29515
  const requestedRegistryPath = getNexusRegistryDbPath();
29262
- if (_nexusDb && _nexusDbPath !== requestedPath) {
29263
- resetNexusDbState();
29264
- }
29265
- if (_nexusDb && _nexusRegistryPath !== requestedRegistryPath) {
29266
- resetNexusDbState();
29267
- }
29268
- if (_nexusDb && (_nexusNativeDb === null || !_nexusNativeDb.isOpen)) {
29269
- resetNexusDbState();
29516
+ const bound = peekProjectDomain("nexus");
29517
+ if (bound && bound.db.registryPath !== requestedRegistryPath) {
29518
+ releaseDomainBindings({ scope: "project", domain: "nexus" });
29270
29519
  }
29271
- if (_nexusDb) {
29272
- if (_nexusNativeDb) {
29273
- try {
29274
- ensureGlobalRegistryAttached(_nexusNativeDb);
29275
- } catch {
29276
- resetNexusDbState();
29277
- }
29278
- }
29279
- if (_nexusDb) return _nexusDb;
29280
- }
29281
- if (_nexusInitPromise) return _nexusInitPromise;
29282
- _nexusInitPromise = (async () => {
29283
- const dbPath = requestedPath;
29284
- _nexusDbPath = dbPath;
29285
- _nexusRegistryPath = requestedRegistryPath;
29286
- detectAndWarnOnNestedNexus();
29287
- await openDualScopeDb("global");
29288
- const dualHandle = await openDualScopeDb("project");
29289
- const nativeDb = dualHandle.db.$client ?? null;
29290
- if (!nativeDb) {
29291
- throw new Error(
29292
- "T11648: openDualScopeDb returned a handle without $client \u2014 cannot extract DatabaseSync for the nexus-schema drizzle wrapping."
29293
- );
29294
- }
29295
- _nexusNativeDb = nativeDb;
29520
+ detectAndWarnOnNestedNexus();
29521
+ await openDualScopeDb("global");
29522
+ const binding = await bindProjectDomain("nexus", void 0, (nativeDb, store) => {
29296
29523
  ensureGlobalRegistryAttached(nativeDb);
29297
29524
  const db = drizzle({ client: nativeDb });
29298
- runNexusMigrations(nativeDb, db);
29525
+ runNexusMigrations(nativeDb, db, store.dbPath);
29299
29526
  nativeDb.prepare(
29300
29527
  `INSERT OR IGNORE INTO nexus_schema_meta (key, value) VALUES ('schemaVersion', '${NEXUS_SCHEMA_VERSION}')`
29301
29528
  ).run();
29302
- _nexusDb = db;
29303
- return db;
29304
- })();
29529
+ return { drizzle: db, registryPath: requestedRegistryPath };
29530
+ });
29305
29531
  try {
29306
- return await _nexusInitPromise;
29307
- } finally {
29308
- _nexusInitPromise = null;
29532
+ ensureGlobalRegistryAttached(binding.native);
29533
+ } catch {
29534
+ releaseDomainBindings({ scope: "project", domain: "nexus" });
29535
+ throw new Error(
29536
+ "T12039: nexus binding lost its GLOBAL registry ATTACH and could not re-attach."
29537
+ );
29309
29538
  }
29539
+ return binding;
29310
29540
  }
29311
29541
  function closeNexusDb() {
29312
- _nexusNativeDb = null;
29313
- _nexusDb = null;
29314
- _nexusDbPath = null;
29315
- _nexusRegistryPath = null;
29316
- _nexusInitPromise = null;
29542
+ releaseDomainBindings({ scope: "project", domain: "nexus" });
29317
29543
  }
29318
29544
  function resetNexusDbState() {
29319
- _nexusNativeDb = null;
29320
- _nexusDb = null;
29321
- _nexusDbPath = null;
29322
- _nexusRegistryPath = null;
29323
- _nexusInitPromise = null;
29545
+ releaseDomainBindings({ scope: "project", domain: "nexus" });
29324
29546
  }
29325
29547
  function getNexusNativeDb() {
29326
- return _nexusNativeDb;
29548
+ return boundProjectNative("nexus");
29327
29549
  }
29328
- var NEXUS_SCHEMA_VERSION, _nexusDb, _nexusNativeDb, _nexusDbPath, _nexusRegistryPath, _nexusInitPromise, NEXUS_GLOBAL_ATTACH_ALIAS, NESTED_NEXUS_SENTINEL, _warnedNestedPaths;
29550
+ var NEXUS_SCHEMA_VERSION, NEXUS_GLOBAL_ATTACH_ALIAS, NESTED_NEXUS_SENTINEL, _warnedNestedPaths;
29329
29551
  var init_nexus_sqlite = __esm({
29330
29552
  "packages/core/src/store/nexus-sqlite.ts"() {
29331
29553
  "use strict";
@@ -29334,15 +29556,11 @@ var init_nexus_sqlite = __esm({
29334
29556
  init_paths();
29335
29557
  init_dual_scope_db();
29336
29558
  init_migration_manager();
29559
+ init_domain_binding();
29337
29560
  init_resolve_migrations_folder();
29338
29561
  init_nexus_schema();
29339
29562
  init_with_retry();
29340
29563
  NEXUS_SCHEMA_VERSION = "1.0.0";
29341
- _nexusDb = null;
29342
- _nexusNativeDb = null;
29343
- _nexusDbPath = null;
29344
- _nexusRegistryPath = null;
29345
- _nexusInitPromise = null;
29346
29564
  NEXUS_GLOBAL_ATTACH_ALIAS = "nexus_global";
29347
29565
  NESTED_NEXUS_SENTINEL = "nexus.db";
29348
29566
  _warnedNestedPaths = /* @__PURE__ */ new Set();
@@ -29354,7 +29572,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
29354
29572
  import { existsSync as existsSync17, readFileSync as readFileSync5, statSync as statSync6 } from "node:fs";
29355
29573
  import { createRequire as createRequire5 } from "node:module";
29356
29574
  import { homedir } from "node:os";
29357
- import { basename as basename4, dirname as dirname7, join as join17, resolve as resolve4 } from "node:path";
29575
+ import { basename as basename4, dirname as dirname7, join as join17, resolve as resolve5 } from "node:path";
29358
29576
  import {
29359
29577
  computeCanonicalProjectId as _computeCanonicalProjectId,
29360
29578
  getCanonicalTemplatesTildePath as _getCanonicalTemplatesTildePath,
@@ -29421,24 +29639,24 @@ function getCleoDirAbsolute(cwd, opts) {
29421
29639
  try {
29422
29640
  const projectRoot = getProjectRoot(cwd);
29423
29641
  const canonical = _resolveCanonicalCleoDir(project.projectId);
29424
- if (canonical !== null && canonical === resolve4(projectRoot, cleoDir)) {
29642
+ if (canonical !== null && canonical === resolve5(projectRoot, cleoDir)) {
29425
29643
  return canonical;
29426
29644
  }
29427
- return resolve4(projectRoot, cleoDir);
29645
+ return resolve5(projectRoot, cleoDir);
29428
29646
  } catch {
29429
- return resolve4(project.projectRoot, cleoDir);
29647
+ return resolve5(project.projectRoot, cleoDir);
29430
29648
  }
29431
29649
  }
29432
29650
  try {
29433
- return resolve4(getProjectRoot(cwd), cleoDir);
29651
+ return resolve5(getProjectRoot(cwd), cleoDir);
29434
29652
  } catch (err) {
29435
29653
  if (opts?.bootstrap) {
29436
- return resolve4(cwd ?? process.cwd(), cleoDir);
29654
+ return resolve5(cwd ?? process.cwd(), cleoDir);
29437
29655
  }
29438
29656
  if (_cwdHasGitAncestor(cwd)) {
29439
29657
  throw err;
29440
29658
  }
29441
- return resolve4(cwd ?? process.cwd(), cleoDir);
29659
+ return resolve5(cwd ?? process.cwd(), cleoDir);
29442
29660
  }
29443
29661
  }
29444
29662
  function _resolveProjectByCwdFromNexus(cwd) {
@@ -29446,7 +29664,7 @@ function _resolveProjectByCwdFromNexus(cwd) {
29446
29664
  const cleoHome = getCleoHome();
29447
29665
  const globalDbPath = join17(cleoHome, "cleo.db");
29448
29666
  if (!existsSync17(globalDbPath)) return null;
29449
- const start = resolve4(cwd ?? process.cwd());
29667
+ const start = resolve5(cwd ?? process.cwd());
29450
29668
  let current = start;
29451
29669
  const DatabaseSync3 = _getDatabaseSyncCtor();
29452
29670
  const db = new DatabaseSync3(globalDbPath, { readOnly: true });
@@ -29479,7 +29697,7 @@ function _cleoDirEnvOverride() {
29479
29697
  }
29480
29698
  function _findCleoDirRoot(cwd) {
29481
29699
  const homeRoot = homedir();
29482
- let current = resolve4(cwd ?? process.cwd());
29700
+ let current = resolve5(cwd ?? process.cwd());
29483
29701
  while (true) {
29484
29702
  const isDangerousRoot = current === homeRoot || current === "/" || current === "";
29485
29703
  if (!isDangerousRoot) {
@@ -29509,7 +29727,7 @@ function resolveCleoDir(cwd) {
29509
29727
  if (root !== null) {
29510
29728
  return join17(root, ".cleo");
29511
29729
  }
29512
- const start = resolve4(cwd ?? process.cwd());
29730
+ const start = resolve5(cwd ?? process.cwd());
29513
29731
  let current = start;
29514
29732
  while (true) {
29515
29733
  const mainRepo = _resolveMainRepoFromGitlink(current);
@@ -29545,15 +29763,15 @@ function _resolveCleoDir(cwd) {
29545
29763
  const project = _pathsResolveProjectByCwd(cwd);
29546
29764
  if (project !== null) {
29547
29765
  try {
29548
- return resolve4(getProjectRoot(cwd), cleoDir);
29766
+ return resolve5(getProjectRoot(cwd), cleoDir);
29549
29767
  } catch {
29550
- return resolve4(project.projectRoot, cleoDir);
29768
+ return resolve5(project.projectRoot, cleoDir);
29551
29769
  }
29552
29770
  }
29553
29771
  return getCleoDirAbsolute(cwd);
29554
29772
  }
29555
29773
  function _cwdHasGitAncestor(cwd) {
29556
- const start = resolve4(cwd ?? process.cwd());
29774
+ const start = resolve5(cwd ?? process.cwd());
29557
29775
  let current = start;
29558
29776
  while (true) {
29559
29777
  const gitMarker = join17(current, ".git");
@@ -29653,7 +29871,7 @@ function getProjectRoot(cwd) {
29653
29871
  }
29654
29872
  return cleoDirEnv;
29655
29873
  }
29656
- const start = resolve4(cwd ?? process.cwd());
29874
+ const start = resolve5(cwd ?? process.cwd());
29657
29875
  let current = start;
29658
29876
  const mainRepoFromStart = _resolveMainRepoFromGitlink(start);
29659
29877
  if (mainRepoFromStart !== null) return mainRepoFromStart;
@@ -29746,7 +29964,7 @@ async function registerProjectOnEncounter(projectRoot, infoProjectId) {
29746
29964
  const db = await getNexusDb2();
29747
29965
  const existingRows = await db.select().from(projectRegistry2).where(eq11(projectRegistry2.projectId, immutableId)).limit(1);
29748
29966
  const now = (/* @__PURE__ */ new Date()).toISOString();
29749
- const resolvedPath = resolve4(projectRoot);
29967
+ const resolvedPath = resolve5(projectRoot);
29750
29968
  const projectName = _readProjectNameFromInfo(resolvedPath) || basename4(projectRoot) || "unnamed";
29751
29969
  if (existingRows.length > 0) {
29752
29970
  const existingPath = existingRows[0].projectPath;
@@ -32315,6 +32533,7 @@ var init_brain_embedding = __esm({
32315
32533
  var memory_sqlite_exports = {};
32316
32534
  __export(memory_sqlite_exports, {
32317
32535
  BRAIN_SCHEMA_VERSION: () => BRAIN_SCHEMA_VERSION,
32536
+ bindBrainDomain: () => bindBrainDomain,
32318
32537
  brainSchema: () => memory_schema_exports,
32319
32538
  closeBrainDb: () => closeBrainDb,
32320
32539
  getBrainDb: () => getBrainDb,
@@ -32344,7 +32563,7 @@ function brainTablesAreConsolidatedShape(nativeDb) {
32344
32563
  const createdAt = cols.find((c) => c.name === "created_at");
32345
32564
  return createdAt !== void 0 && createdAt.type.toUpperCase() !== "INTEGER";
32346
32565
  }
32347
- function establishLegacyBrainSchema(nativeDb, db) {
32566
+ function establishLegacyBrainSchema(nativeDb, db, dbPath) {
32348
32567
  const log12 = getLogger("brain-schema");
32349
32568
  if (brainTablesAreConsolidatedShape(nativeDb)) {
32350
32569
  const fkRow = nativeDb.prepare("PRAGMA foreign_keys").get();
@@ -32381,8 +32600,8 @@ function establishLegacyBrainSchema(nativeDb, db) {
32381
32600
  );
32382
32601
  return;
32383
32602
  }
32384
- if (tableExists(nativeDb, "brain_decisions") && _dbPath) {
32385
- createSafetyBackup(_dbPath);
32603
+ if (tableExists(nativeDb, "brain_decisions")) {
32604
+ createSafetyBackup(dbPath);
32386
32605
  }
32387
32606
  reconcileJournal(nativeDb, migrationsFolder, "brain_decisions", "brain");
32388
32607
  migrateWithRetry(db, migrationsFolder, nativeDb, "brain_decisions", "brain");
@@ -32401,8 +32620,8 @@ function initializeBrainVec(nativeDb) {
32401
32620
  "CREATE VIRTUAL TABLE IF NOT EXISTS brain_embeddings USING vec0(id TEXT PRIMARY KEY, embedding FLOAT[384])"
32402
32621
  ).run();
32403
32622
  }
32404
- function isBrainVecLoaded() {
32405
- return _vecLoaded;
32623
+ function isBrainVecLoaded(cwd) {
32624
+ return peekProjectDomain("brain", cwd)?.db.vecLoaded ?? false;
32406
32625
  }
32407
32626
  async function initEmbeddingProvider(cwd) {
32408
32627
  try {
@@ -32416,92 +32635,52 @@ async function initEmbeddingProvider(cwd) {
32416
32635
  }
32417
32636
  }
32418
32637
  async function getBrainDb(cwd) {
32419
- const requestedPath = getBrainDbPath(cwd);
32638
+ return (await bindBrainDomain(cwd)).db.drizzle;
32639
+ }
32640
+ async function bindBrainDomain(cwd) {
32420
32641
  const { assertTestEnv: assertTestEnv2 } = await Promise.resolve().then(() => (init_data_accessor(), data_accessor_exports));
32421
- assertTestEnv2(requestedPath);
32422
- if (_db && _dbPath !== requestedPath) {
32423
- resetBrainDbState();
32424
- }
32425
- if (_db && (_nativeDb === null || !_nativeDb.isOpen)) {
32426
- resetBrainDbState();
32427
- }
32428
- if (_db) return _db;
32429
- if (_initPromise) return _initPromise;
32430
- _initPromise = (async () => {
32431
- let nativeDb = null;
32432
- for (let attempt = 0; attempt < 2; attempt += 1) {
32433
- const dualHandle = await openDualScopeDb("project", cwd);
32434
- nativeDb = dualHandle.db.$client ?? null;
32435
- if (!nativeDb) {
32436
- throw new Error(
32437
- "E6-L2: openDualScopeDb returned a handle without $client \u2014 cannot extract DatabaseSync for legacy brain-schema wrapping."
32438
- );
32439
- }
32440
- if (nativeDb.isOpen) break;
32441
- }
32442
- if (!nativeDb?.isOpen) {
32443
- throw new Error("E6-L2: openDualScopeDb repeatedly returned a closed DatabaseSync handle.");
32444
- }
32445
- _nativeDb = nativeDb;
32446
- _dbPath = requestedPath;
32447
- _vecLoaded = loadBrainVecExtension(nativeDb);
32448
- const db = _getDrizzle()({ client: nativeDb });
32449
- establishLegacyBrainSchema(nativeDb, db);
32450
- if (_vecLoaded) {
32642
+ assertTestEnv2(getBrainDbPath(cwd));
32643
+ return bindProjectDomain("brain", cwd, (nativeDb, store) => {
32644
+ const vecLoaded = loadBrainVecExtension(nativeDb);
32645
+ const drizzle2 = _getDrizzle()({ client: nativeDb });
32646
+ establishLegacyBrainSchema(nativeDb, drizzle2, store.dbPath);
32647
+ if (vecLoaded) {
32451
32648
  initializeBrainVec(nativeDb);
32452
32649
  }
32453
32650
  nativeDb.prepare(
32454
32651
  `INSERT OR IGNORE INTO brain_schema_meta (key, value) VALUES ('schemaVersion', '${BRAIN_SCHEMA_VERSION}')`
32455
32652
  ).run();
32456
- _db = db;
32457
- if (_vecLoaded) {
32653
+ if (vecLoaded) {
32458
32654
  setImmediate(() => {
32459
32655
  initEmbeddingProvider(cwd).catch(() => {
32460
32656
  });
32461
32657
  });
32462
32658
  }
32463
- return db;
32464
- })();
32465
- try {
32466
- return await _initPromise;
32467
- } finally {
32468
- _initPromise = null;
32469
- }
32659
+ return { drizzle: drizzle2, vecLoaded };
32660
+ });
32470
32661
  }
32471
32662
  function closeBrainDb() {
32472
- _nativeDb = null;
32473
- _db = null;
32474
- _dbPath = null;
32475
- _initPromise = null;
32476
- _vecLoaded = false;
32663
+ releaseDomainBindings({ scope: "project", domain: "brain" });
32477
32664
  }
32478
32665
  function resetBrainDbState() {
32479
- _nativeDb = null;
32480
- _db = null;
32481
- _dbPath = null;
32482
- _initPromise = null;
32483
- _vecLoaded = false;
32666
+ releaseDomainBindings({ scope: "project", domain: "brain" });
32484
32667
  }
32485
- function getBrainNativeDb() {
32486
- return _nativeDb;
32668
+ function getBrainNativeDb(cwd) {
32669
+ return boundProjectNative("brain", cwd);
32487
32670
  }
32488
- var _require3, _drizzle2, BRAIN_SCHEMA_VERSION, _db, _nativeDb, _dbPath, _initPromise, _vecLoaded, CONSOLIDATED_BRAIN_TABLES;
32671
+ var _require3, _drizzle2, BRAIN_SCHEMA_VERSION, CONSOLIDATED_BRAIN_TABLES;
32489
32672
  var init_memory_sqlite = __esm({
32490
32673
  "packages/core/src/store/memory-sqlite.ts"() {
32491
32674
  "use strict";
32492
32675
  init_logger2();
32493
32676
  init_dual_scope_db();
32494
32677
  init_migration_manager();
32678
+ init_domain_binding();
32495
32679
  init_resolve_migrations_folder();
32496
32680
  init_memory_schema();
32497
32681
  _require3 = createRequire6(import.meta.url);
32498
32682
  _drizzle2 = null;
32499
32683
  BRAIN_SCHEMA_VERSION = "1.0.0";
32500
- _db = null;
32501
- _nativeDb = null;
32502
- _dbPath = null;
32503
- _initPromise = null;
32504
- _vecLoaded = false;
32505
32684
  CONSOLIDATED_BRAIN_TABLES = [
32506
32685
  "brain_attention",
32507
32686
  "brain_backfill_runs",
@@ -36324,41 +36503,41 @@ function runTelemetryMigrations(nativeDb, db) {
36324
36503
  }
36325
36504
  function resetTelemetryDbState() {
36326
36505
  try {
36327
- _nativeDb2?.close();
36506
+ _nativeDb?.close();
36328
36507
  } catch {
36329
36508
  }
36330
- _db2 = null;
36331
- _nativeDb2 = null;
36332
- _dbPath2 = null;
36333
- _initPromise2 = null;
36509
+ _db = null;
36510
+ _nativeDb = null;
36511
+ _dbPath = null;
36512
+ _initPromise = null;
36334
36513
  }
36335
36514
  function getTelemetryNativeDb() {
36336
- return _nativeDb2;
36515
+ return _nativeDb;
36337
36516
  }
36338
36517
  async function getTelemetryDb() {
36339
36518
  const requestedPath = getTelemetryDbPath();
36340
- if (_db2 && _dbPath2 !== requestedPath) {
36519
+ if (_db && _dbPath !== requestedPath) {
36341
36520
  resetTelemetryDbState();
36342
36521
  }
36343
- if (_db2) return _db2;
36344
- if (_initPromise2) return _initPromise2;
36345
- _initPromise2 = (async () => {
36522
+ if (_db) return _db;
36523
+ if (_initPromise) return _initPromise;
36524
+ _initPromise = (async () => {
36346
36525
  const dbPath = requestedPath;
36347
- _dbPath2 = dbPath;
36526
+ _dbPath = dbPath;
36348
36527
  mkdirSync5(dirname8(dbPath), { recursive: true });
36349
36528
  const nativeDb = openNativeDatabase(dbPath);
36350
- _nativeDb2 = nativeDb;
36529
+ _nativeDb = nativeDb;
36351
36530
  const db = drizzle({ client: nativeDb });
36352
36531
  runTelemetryMigrations(nativeDb, db);
36353
36532
  nativeDb.prepare(
36354
36533
  `INSERT OR IGNORE INTO telemetry_schema_meta (key, value) VALUES ('schemaVersion', '${TELEMETRY_SCHEMA_VERSION}')`
36355
36534
  ).run();
36356
- _db2 = db;
36535
+ _db = db;
36357
36536
  return db;
36358
36537
  })();
36359
- return _initPromise2;
36538
+ return _initPromise;
36360
36539
  }
36361
- var DB_FILENAME, TELEMETRY_SCHEMA_VERSION, _db2, _nativeDb2, _dbPath2, _initPromise2;
36540
+ var DB_FILENAME, TELEMETRY_SCHEMA_VERSION, _db, _nativeDb, _dbPath, _initPromise;
36362
36541
  var init_sqlite2 = __esm({
36363
36542
  "packages/core/src/telemetry/sqlite.ts"() {
36364
36543
  "use strict";
@@ -36369,10 +36548,10 @@ var init_sqlite2 = __esm({
36369
36548
  init_sqlite3();
36370
36549
  DB_FILENAME = "telemetry.db";
36371
36550
  TELEMETRY_SCHEMA_VERSION = "1.0.0";
36372
- _db2 = null;
36373
- _nativeDb2 = null;
36374
- _dbPath2 = null;
36375
- _initPromise2 = null;
36551
+ _db = null;
36552
+ _nativeDb = null;
36553
+ _dbPath = null;
36554
+ _initPromise = null;
36376
36555
  }
36377
36556
  });
36378
36557
 
@@ -36404,6 +36583,9 @@ function runAgentRegistryMigrations(nativeDb) {
36404
36583
  const db = drizzle({ client: nativeDb });
36405
36584
  migrateSanitized(db, { migrationsFolder });
36406
36585
  }
36586
+ function boundAgentRegistryNative() {
36587
+ return peekDomainAtPath("global", getGlobalAgentRegistryDbPath(), AGENT_REGISTRY_DOMAIN)?.native ?? null;
36588
+ }
36407
36589
  function readAgentRegistrySchemaVersionSentinel(db) {
36408
36590
  try {
36409
36591
  const row = db.prepare("SELECT value FROM _agent_registry_meta WHERE key = 'schema_version'").get();
@@ -36426,16 +36608,36 @@ function writeAgentRegistrySchemaVersionSentinel(db) {
36426
36608
  } catch {
36427
36609
  }
36428
36610
  }
36611
+ function establishAgentRegistrySchema(native) {
36612
+ const hasSchema = (() => {
36613
+ try {
36614
+ return !!native.prepare(
36615
+ "SELECT name FROM sqlite_master WHERE type='table' AND name='agent_registry_agents'"
36616
+ ).get();
36617
+ } catch {
36618
+ return false;
36619
+ }
36620
+ })();
36621
+ if (hasSchema && readAgentRegistrySchemaVersionSentinel(native) === GLOBAL_AGENT_REGISTRY_SCHEMA_VERSION) {
36622
+ return false;
36623
+ }
36624
+ runAgentRegistryMigrations(native);
36625
+ writeAgentRegistrySchemaVersionSentinel(native);
36626
+ return true;
36627
+ }
36429
36628
  async function ensureGlobalAgentRegistryDb() {
36430
36629
  const dbPath = getGlobalAgentRegistryDbPath();
36431
36630
  const alreadyExists = existsSync19(dbPath);
36432
- const dualHandle = await openDualScopeDbAtPath("global", dbPath);
36433
- const nativeDb = dualHandle.db.$client ?? null;
36434
- if (!nativeDb) {
36435
- throw new Error(
36436
- "E6-L5: openDualScopeDb returned a handle without $client \u2014 cannot extract DatabaseSync for the Agent Registry ledger reconcile."
36437
- );
36438
- }
36631
+ let created = false;
36632
+ const { native: nativeDb } = await bindGlobalDomainAtPath(
36633
+ AGENT_REGISTRY_DOMAIN,
36634
+ dbPath,
36635
+ (native) => {
36636
+ const applied = establishAgentRegistrySchema(native);
36637
+ created = created || applied;
36638
+ return native;
36639
+ }
36640
+ );
36439
36641
  const hasSchema = (() => {
36440
36642
  try {
36441
36643
  const result = nativeDb.prepare(
@@ -36446,22 +36648,15 @@ async function ensureGlobalAgentRegistryDb() {
36446
36648
  return false;
36447
36649
  }
36448
36650
  })();
36449
- if (hasSchema && readAgentRegistrySchemaVersionSentinel(nativeDb) === GLOBAL_AGENT_REGISTRY_SCHEMA_VERSION) {
36450
- _globalAgentRegistryNativeDb = nativeDb;
36451
- return { action: "exists", path: dbPath };
36452
- }
36453
- runAgentRegistryMigrations(nativeDb);
36454
- writeAgentRegistrySchemaVersionSentinel(nativeDb);
36455
- _globalAgentRegistryNativeDb = nativeDb;
36456
36651
  return {
36457
36652
  action: alreadyExists && hasSchema ? "exists" : "created",
36458
36653
  path: dbPath
36459
36654
  };
36460
36655
  }
36461
36656
  function getGlobalAgentRegistryNativeDb() {
36462
- return _globalAgentRegistryNativeDb;
36657
+ return boundAgentRegistryNative();
36463
36658
  }
36464
- var GLOBAL_AGENT_REGISTRY_SCHEMA_VERSION, _globalAgentRegistryNativeDb;
36659
+ var GLOBAL_AGENT_REGISTRY_SCHEMA_VERSION, AGENT_REGISTRY_DOMAIN;
36465
36660
  var init_agent_registry_store = __esm({
36466
36661
  "packages/core/src/store/agent-registry-store.ts"() {
36467
36662
  "use strict";
@@ -36469,9 +36664,10 @@ var init_agent_registry_store = __esm({
36469
36664
  init_paths();
36470
36665
  init_dual_scope_db();
36471
36666
  init_migration_manager();
36667
+ init_domain_binding();
36472
36668
  init_resolve_migrations_folder();
36473
36669
  GLOBAL_AGENT_REGISTRY_SCHEMA_VERSION = "2026.4.12";
36474
- _globalAgentRegistryNativeDb = null;
36670
+ AGENT_REGISTRY_DOMAIN = "agents";
36475
36671
  }
36476
36672
  });
36477
36673
 
@@ -36505,60 +36701,36 @@ function runConduitMigrations(nativeDb) {
36505
36701
  }
36506
36702
  async function ensureConduitDb(projectRoot) {
36507
36703
  const dbPath = getConduitDbPath(projectRoot);
36508
- if (_conduitNativeDb && (!_conduitNativeDb.isOpen || _conduitDbPath !== dbPath)) {
36509
- resetConduitDbState();
36510
- }
36511
- if (_conduitNativeDb && _conduitDbPath === dbPath) {
36512
- return { action: "exists", path: dbPath };
36513
- }
36514
- if (_initPromise3) return _initPromise3;
36515
- _initPromise3 = (async () => {
36516
- const alreadyExists = existsSync20(dbPath);
36517
- const dualHandle = await openDualScopeDb("project", projectRoot);
36518
- const nativeDb = dualHandle.db.$client ?? null;
36519
- if (!nativeDb) {
36520
- throw new Error(
36521
- "E6-L3: openDualScopeDb returned a handle without $client \u2014 cannot extract DatabaseSync for legacy conduit-schema wrapping."
36522
- );
36523
- }
36704
+ const alreadyExists = peekProjectDomain("conduit", projectRoot) !== null || existsSync20(dbPath);
36705
+ await bindConduitDomain(projectRoot);
36706
+ return { action: alreadyExists ? "exists" : "created", path: dbPath };
36707
+ }
36708
+ async function bindConduitDomain(projectRoot) {
36709
+ return bindProjectDomain("conduit", projectRoot, (nativeDb) => {
36524
36710
  runConduitMigrations(nativeDb);
36525
36711
  nativeDb.exec(
36526
36712
  `INSERT OR REPLACE INTO _conduit_meta (key, value, updated_at)
36527
36713
  VALUES ('schema_version', '${CONDUIT_SCHEMA_VERSION}', strftime('%s', 'now'))`
36528
36714
  );
36529
- _conduitNativeDb = nativeDb;
36530
- _conduitDbPath = dbPath;
36531
- return { action: alreadyExists ? "exists" : "created", path: dbPath };
36532
- })();
36533
- try {
36534
- return await _initPromise3;
36535
- } finally {
36536
- _initPromise3 = null;
36537
- }
36538
- }
36539
- function getConduitNativeDb() {
36540
- return _conduitNativeDb;
36715
+ return nativeDb;
36716
+ });
36541
36717
  }
36542
- function resetConduitDbState() {
36543
- _conduitNativeDb = null;
36544
- _conduitDbPath = null;
36545
- _initPromise3 = null;
36718
+ function getConduitNativeDb(projectRoot) {
36719
+ return boundProjectNative("conduit", projectRoot);
36546
36720
  }
36547
- var _require4, DatabaseSync2, _drizzle3, CONDUIT_SCHEMA_VERSION, _conduitNativeDb, _conduitDbPath, _initPromise3;
36721
+ var _require4, DatabaseSync2, _drizzle3, CONDUIT_SCHEMA_VERSION;
36548
36722
  var init_conduit_sqlite = __esm({
36549
36723
  "packages/core/src/store/conduit-sqlite.ts"() {
36550
36724
  "use strict";
36551
36725
  init_dual_scope_db();
36552
36726
  init_migration_manager();
36727
+ init_domain_binding();
36553
36728
  init_resolve_migrations_folder();
36554
36729
  init_sqlite_pragmas();
36555
36730
  _require4 = createRequire7(import.meta.url);
36556
36731
  ({ DatabaseSync: DatabaseSync2 } = _require4("node:sqlite"));
36557
36732
  _drizzle3 = null;
36558
36733
  CONDUIT_SCHEMA_VERSION = "2026.4.23";
36559
- _conduitNativeDb = null;
36560
- _conduitDbPath = null;
36561
- _initPromise3 = null;
36562
36734
  }
36563
36735
  });
36564
36736
 
@@ -36738,47 +36910,26 @@ function getDefaultSkillsDbPath() {
36738
36910
  return dbPath;
36739
36911
  }
36740
36912
  async function openSkillsDb(options) {
36741
- if (_skillsDb && !options?.path) return _skillsDb;
36742
- const requestedPath = options?.path ?? getDefaultSkillsDbPath();
36743
- if (_skillsDb && _skillsDbPath !== requestedPath) {
36744
- resetSkillsDbState();
36745
- }
36746
- if (_skillsDb && (_skillsNativeDb === null || !_skillsNativeDb.isOpen)) {
36747
- resetSkillsDbState();
36748
- }
36749
- if (_skillsDb) return _skillsDb;
36750
- if (_skillsInitPromise) return _skillsInitPromise;
36751
- _skillsInitPromise = (async () => {
36752
- _skillsDbPath = requestedPath;
36753
- const dualHandle = options?.path ? await openDualScopeDbAtPath("global", options.path) : await openDualScopeDb("global");
36754
- const nativeDb = dualHandle.db.$client ?? null;
36755
- if (!nativeDb) {
36756
- throw new Error(
36757
- "E6-L5: openDualScopeDb returned a handle without $client \u2014 cannot extract DatabaseSync for the skills-schema wrapping."
36758
- );
36759
- }
36760
- _skillsNativeDb = nativeDb;
36761
- const db = drizzle({ client: nativeDb });
36762
- _skillsDb = db;
36763
- return db;
36764
- })();
36765
- try {
36766
- return await _skillsInitPromise;
36767
- } finally {
36768
- _skillsInitPromise = null;
36913
+ return (await bindSkillsDomain(options)).db;
36914
+ }
36915
+ function resolveSkillsBindPath(options) {
36916
+ if (options?.path) {
36917
+ _skillsOverridePath = options.path;
36918
+ return { path: options.path, canonical: false };
36769
36919
  }
36920
+ if (_skillsOverridePath) return { path: _skillsOverridePath, canonical: false };
36921
+ return { path: getDefaultSkillsDbPath(), canonical: true };
36770
36922
  }
36771
- function resetSkillsDbState() {
36772
- _skillsNativeDb = null;
36773
- _skillsDb = null;
36774
- _skillsDbPath = null;
36775
- _skillsInitPromise = null;
36776
- _resetDualScopeDbCache("global");
36923
+ async function bindSkillsDomain(options) {
36924
+ const { path: path2, canonical } = resolveSkillsBindPath(options);
36925
+ const establish = (nativeDb) => drizzle({ client: nativeDb });
36926
+ return canonical ? bindGlobalDomain("skills", establish) : bindGlobalDomainAtPath("skills", path2, establish);
36777
36927
  }
36778
36928
  function getSkillsNativeDb() {
36779
- return _skillsNativeDb;
36929
+ const bound = _skillsOverridePath ? peekDomainAtPath("global", _skillsOverridePath, "skills") : peekGlobalDomain("skills");
36930
+ return bound?.native ?? null;
36780
36931
  }
36781
- var _skillsDb, _skillsNativeDb, _skillsDbPath, _skillsInitPromise;
36932
+ var _skillsOverridePath;
36782
36933
  var init_skills_db = __esm({
36783
36934
  "packages/core/src/store/skills-db.ts"() {
36784
36935
  "use strict";
@@ -36786,12 +36937,10 @@ var init_skills_db = __esm({
36786
36937
  init_paths();
36787
36938
  init_skill_provenance();
36788
36939
  init_dual_scope_db();
36940
+ init_domain_binding();
36789
36941
  init_skills_schema();
36790
36942
  init_skills_schema();
36791
- _skillsDb = null;
36792
- _skillsNativeDb = null;
36793
- _skillsDbPath = null;
36794
- _skillsInitPromise = null;
36943
+ _skillsOverridePath = null;
36795
36944
  }
36796
36945
  });
36797
36946
 
@@ -36820,11 +36969,11 @@ function resolveInventoryPath(entry, cwd) {
36820
36969
  }
36821
36970
  async function openBrainDbForSnapshot(cwd) {
36822
36971
  await getBrainDb(cwd);
36823
- return getBrainNativeDb();
36972
+ return getBrainNativeDb(cwd);
36824
36973
  }
36825
36974
  async function openTasksDbForSnapshot(cwd) {
36826
36975
  await getDb(cwd);
36827
- return getNativeDb();
36976
+ return getNativeDb(cwd);
36828
36977
  }
36829
36978
  async function openConduitDbForSnapshot(cwd) {
36830
36979
  await ensureConduitDb(resolveOrCwd(cwd));
@@ -37067,7 +37216,7 @@ __export(sqlite_native_exports, {
37067
37216
  import { realpathSync } from "node:fs";
37068
37217
  import { createRequire as createRequire8 } from "node:module";
37069
37218
  import { tmpdir } from "node:os";
37070
- import { delimiter, dirname as dirname9, isAbsolute, join as join22, resolve as resolve5, sep } from "node:path";
37219
+ import { delimiter, dirname as dirname9, isAbsolute, join as join22, resolve as resolve6, sep } from "node:path";
37071
37220
  function getDbSyncConstructor() {
37072
37221
  if (_ctor === null) {
37073
37222
  const mod = _require5("node:sqlite");
@@ -37076,7 +37225,7 @@ function getDbSyncConstructor() {
37076
37225
  return _ctor;
37077
37226
  }
37078
37227
  function resolveAbsoluteSafe(p) {
37079
- const abs = isAbsolute(p) ? p : resolve5(p);
37228
+ const abs = isAbsolute(p) ? p : resolve6(p);
37080
37229
  try {
37081
37230
  return realpathSync(abs);
37082
37231
  } catch {
@@ -37180,6 +37329,7 @@ var sqlite_exports = {};
37180
37329
  __export(sqlite_exports, {
37181
37330
  SQLITE_SCHEMA_VERSION: () => SQLITE_SCHEMA_VERSION,
37182
37331
  autoRecoverFromBackup: () => autoRecoverFromBackup,
37332
+ bindTasksDomain: () => bindTasksDomain,
37183
37333
  closeAllDatabases: () => closeAllDatabases,
37184
37334
  closeDb: () => closeDb,
37185
37335
  dbExists: () => dbExists,
@@ -37237,13 +37387,14 @@ function countBackupTasks(backupDb) {
37237
37387
  async function autoRecoverFromBackup(nativeDb, dbPath, cwd) {
37238
37388
  const { openNativeDatabase: openNativeDatabase2 } = await Promise.resolve().then(() => (init_sqlite_native(), sqlite_native_exports));
37239
37389
  const log12 = getLogger("sqlite");
37390
+ let restored = false;
37240
37391
  try {
37241
37392
  const countResult = nativeDb.prepare("SELECT COUNT(*) as cnt FROM tasks_tasks").get();
37242
37393
  const taskCount = countResult?.cnt ?? 0;
37243
- if (taskCount > 0) return;
37394
+ if (taskCount > 0) return false;
37244
37395
  const backups = listSqliteBackups(cwd);
37245
37396
  if (backups.length === 0) {
37246
- return;
37397
+ return false;
37247
37398
  }
37248
37399
  const newestBackup = backups[0];
37249
37400
  const backupDb = openNativeDatabase2(newestBackup.path, { readonly: true, enableWal: false });
@@ -37254,7 +37405,7 @@ async function autoRecoverFromBackup(nativeDb, dbPath, cwd) {
37254
37405
  backupDb.close();
37255
37406
  }
37256
37407
  if (backupTaskCount < MIN_BACKUP_TASK_COUNT) {
37257
- return;
37408
+ return false;
37258
37409
  }
37259
37410
  const lockPath2 = dbPath + FIRST_OPEN_LOCK_SUFFIX;
37260
37411
  await withLock(
@@ -37293,11 +37444,7 @@ async function autoRecoverFromBackup(nativeDb, dbPath, cwd) {
37293
37444
  "Database auto-recovered from backup successfully."
37294
37445
  );
37295
37446
  _resetDualScopeDbCache();
37296
- const restoredNativeDb = openNativeDatabase2(dbPath);
37297
- _nativeDb3 = restoredNativeDb;
37298
- const restoredDb = _getDrizzle3()({ client: restoredNativeDb });
37299
- runMigrations(restoredNativeDb, restoredDb);
37300
- _db3 = restoredDb;
37447
+ restored = true;
37301
37448
  },
37302
37449
  // Allow a generous stale window + retries: an exodus migration holding this
37303
37450
  // lock can take a while on a large fleet (matches on-open.ts), so a blocked
@@ -37307,64 +37454,46 @@ async function autoRecoverFromBackup(nativeDb, dbPath, cwd) {
37307
37454
  } catch (err) {
37308
37455
  log12.error({ err, dbPath }, "Auto-recovery from backup failed. Continuing with empty database.");
37309
37456
  }
37457
+ return restored;
37310
37458
  }
37311
37459
  async function getDb(cwd) {
37460
+ return (await bindTasksDomain(cwd)).db;
37461
+ }
37462
+ async function bindTasksDomain(cwd) {
37312
37463
  assertDbPathIsNotWorktreeResident("tasks", cwd);
37313
- const requestedPath = resolveDualScopeDbPath("project", cwd);
37314
- if (_db3 && _dbPath3 !== requestedPath) {
37315
- resetDbState();
37316
- }
37317
- if (_db3 && (_nativeDb3 === null || !_nativeDb3.isOpen)) {
37318
- resetDbState();
37319
- }
37320
- if (_db3) return _db3;
37321
- if (_initPromise4) return _initPromise4;
37322
- _initPromise4 = (async () => {
37323
- let nativeDb = null;
37324
- for (let attempt = 0; attempt < 2; attempt += 1) {
37325
- const dualHandle = await openDualScopeDb("project", cwd);
37326
- nativeDb = dualHandle.db.$client ?? null;
37327
- if (!nativeDb) {
37328
- throw new Error(
37329
- "E6-L1: openDualScopeDb returned a handle without $client \u2014 cannot extract DatabaseSync for legacy tasks-schema wrapping."
37330
- );
37331
- }
37332
- if (nativeDb.isOpen) break;
37333
- dualHandle.close();
37334
- }
37335
- if (!nativeDb?.isOpen) {
37336
- throw new Error("E6-L1: openDualScopeDb repeatedly returned a closed DatabaseSync handle.");
37337
- }
37338
- _nativeDb3 = nativeDb;
37339
- _dbPath3 = requestedPath;
37340
- const db = _getDrizzle3()({ client: nativeDb });
37341
- runMigrations(nativeDb, db);
37342
- if (process.env.VITEST) {
37343
- nativeDb.exec("PRAGMA foreign_keys=OFF");
37344
- }
37345
- nativeDb.exec(
37346
- `INSERT OR IGNORE INTO schema_meta (key, value) VALUES ('schemaVersion', '${SCHEMA_VERSION}')`
37347
- );
37348
- nativeDb.exec(
37349
- `INSERT OR IGNORE INTO schema_meta (key, value) VALUES ('task_id_sequence', '{"counter":0,"lastId":"T000","checksum":"seed"}')`
37350
- );
37351
- await autoRecoverFromBackup(nativeDb, requestedPath, cwd);
37352
- _db3 = db;
37353
- return db;
37354
- })();
37355
- try {
37356
- return await _initPromise4;
37357
- } finally {
37358
- _initPromise4 = null;
37464
+ let coldBind = false;
37465
+ const binding = await bindProjectDomain("tasks", cwd, (nativeDb, store) => {
37466
+ coldBind = true;
37467
+ return establishTasksSchema(nativeDb, store);
37468
+ });
37469
+ if (!coldBind) return binding;
37470
+ if (await autoRecoverFromBackup(binding.native, binding.store.dbPath, cwd)) {
37471
+ releaseDomainBindings({ scope: "project", dbPath: binding.store.dbPath });
37472
+ return bindProjectDomain("tasks", cwd, establishTasksSchema);
37359
37473
  }
37474
+ return binding;
37475
+ }
37476
+ function establishTasksSchema(nativeDb, store) {
37477
+ const db = _getDrizzle3()({ client: nativeDb });
37478
+ runMigrations(nativeDb, db, store.dbPath);
37479
+ if (process.env.VITEST) {
37480
+ nativeDb.exec("PRAGMA foreign_keys=OFF");
37481
+ }
37482
+ nativeDb.exec(
37483
+ `INSERT OR IGNORE INTO schema_meta (key, value) VALUES ('schemaVersion', '${SCHEMA_VERSION}')`
37484
+ );
37485
+ nativeDb.exec(
37486
+ `INSERT OR IGNORE INTO schema_meta (key, value) VALUES ('task_id_sequence', '{"counter":0,"lastId":"T000","checksum":"seed"}')`
37487
+ );
37488
+ return db;
37360
37489
  }
37361
37490
  function resolveMigrationsFolder() {
37362
37491
  return resolveCorePackageMigrationsFolder("drizzle-tasks");
37363
37492
  }
37364
- function runMigrations(nativeDb, db) {
37493
+ function runMigrations(nativeDb, db, dbPath) {
37365
37494
  const migrationsFolder = resolveMigrationsFolder();
37366
- if (tableExists(nativeDb, "tasks") && _dbPath3) {
37367
- createSafetyBackup(_dbPath3);
37495
+ if (tableExists(nativeDb, "tasks")) {
37496
+ createSafetyBackup(dbPath);
37368
37497
  }
37369
37498
  reconcileJournal(
37370
37499
  nativeDb,
@@ -37388,33 +37517,11 @@ function runMigrations(nativeDb, db) {
37388
37517
  }
37389
37518
  function closeDb() {
37390
37519
  _resetDualScopeDbCache("project");
37391
- if (_nativeDb3) {
37392
- try {
37393
- if (_nativeDb3.isOpen) {
37394
- _nativeDb3.close();
37395
- }
37396
- } catch {
37397
- }
37398
- _nativeDb3 = null;
37399
- }
37400
- _db3 = null;
37401
- _dbPath3 = null;
37402
- _initPromise4 = null;
37520
+ releaseDomainBindings({ scope: "project" });
37403
37521
  }
37404
37522
  function resetDbState() {
37405
37523
  _resetDualScopeDbCache("project");
37406
- if (_nativeDb3) {
37407
- try {
37408
- if (_nativeDb3.isOpen) {
37409
- _nativeDb3.close();
37410
- }
37411
- } catch {
37412
- }
37413
- _nativeDb3 = null;
37414
- }
37415
- _db3 = null;
37416
- _dbPath3 = null;
37417
- _initPromise4 = null;
37524
+ releaseDomainBindings({ scope: "project" });
37418
37525
  }
37419
37526
  async function getSchemaVersion(cwd) {
37420
37527
  const db = await getDb(cwd);
@@ -37424,11 +37531,11 @@ async function getSchemaVersion(cwd) {
37424
37531
  function dbExists(cwd) {
37425
37532
  return existsSync22(resolveDualScopeDbPath("project", cwd));
37426
37533
  }
37427
- function getNativeDb() {
37428
- return _nativeDb3;
37534
+ function getNativeDb(cwd) {
37535
+ return boundProjectNative("tasks", cwd);
37429
37536
  }
37430
- function getNativeTasksDb() {
37431
- return _nativeDb3;
37537
+ function getNativeTasksDb(cwd) {
37538
+ return boundProjectNative("tasks", cwd);
37432
37539
  }
37433
37540
  async function closeAllDatabases() {
37434
37541
  closeDb();
@@ -37442,8 +37549,9 @@ async function closeAllDatabases() {
37442
37549
  closeNexusDb2();
37443
37550
  } catch {
37444
37551
  }
37552
+ resetCleoRuntime();
37445
37553
  }
37446
- var _drizzle4, SQLITE_SCHEMA_VERSION, SCHEMA_VERSION, _db3, _nativeDb3, _dbPath3, _initPromise4, MIN_BACKUP_TASK_COUNT, FIRST_OPEN_LOCK_SUFFIX, REQUIRED_TASK_COLUMNS, REQUIRED_SESSION_COLUMNS;
37554
+ var _drizzle4, SQLITE_SCHEMA_VERSION, SCHEMA_VERSION, MIN_BACKUP_TASK_COUNT, FIRST_OPEN_LOCK_SUFFIX, REQUIRED_TASK_COLUMNS, REQUIRED_SESSION_COLUMNS;
37447
37555
  var init_sqlite3 = __esm({
37448
37556
  "packages/core/src/store/sqlite.ts"() {
37449
37557
  "use strict";
@@ -37451,6 +37559,7 @@ var init_sqlite3 = __esm({
37451
37559
  init_dual_scope_db();
37452
37560
  init_lock();
37453
37561
  init_migration_manager();
37562
+ init_domain_binding();
37454
37563
  init_resolve_migrations_folder();
37455
37564
  init_sqlite_backup();
37456
37565
  init_worktree_isolation_guard();
@@ -37460,10 +37569,6 @@ var init_sqlite3 = __esm({
37460
37569
  _drizzle4 = null;
37461
37570
  SQLITE_SCHEMA_VERSION = "2.0.0";
37462
37571
  SCHEMA_VERSION = SQLITE_SCHEMA_VERSION;
37463
- _db3 = null;
37464
- _nativeDb3 = null;
37465
- _dbPath3 = null;
37466
- _initPromise4 = null;
37467
37572
  MIN_BACKUP_TASK_COUNT = 10;
37468
37573
  FIRST_OPEN_LOCK_SUFFIX = ".exodus-on-open.lock";
37469
37574
  REQUIRED_TASK_COLUMNS = [
@@ -38403,7 +38508,7 @@ async function createSqliteDataAccessor(cwd) {
38403
38508
  },
38404
38509
  async transaction(fn) {
38405
38510
  const db = await getDb(cwd);
38406
- const nativeDb = getNativeTasksDb();
38511
+ const nativeDb = getNativeTasksDb(cwd);
38407
38512
  if (!nativeDb) {
38408
38513
  throw new Error("Native database not initialized");
38409
38514
  }
@@ -38842,24 +38947,37 @@ var init_sequence = __esm({
38842
38947
  }
38843
38948
  });
38844
38949
 
38950
+ // packages/core/src/store/checkpoint-git-dir.ts
38951
+ import { join as join24 } from "node:path";
38952
+ function checkpointGitDir(cleoDir) {
38953
+ return join24(cleoDir, CHECKPOINT_GIT_DIRNAME);
38954
+ }
38955
+ var CHECKPOINT_GIT_DIRNAME;
38956
+ var init_checkpoint_git_dir = __esm({
38957
+ "packages/core/src/store/checkpoint-git-dir.ts"() {
38958
+ "use strict";
38959
+ CHECKPOINT_GIT_DIRNAME = "checkpoint.git";
38960
+ }
38961
+ });
38962
+
38845
38963
  // packages/core/src/store/git-checkpoint.ts
38846
38964
  import { execFile as execFile2 } from "node:child_process";
38847
38965
  import { existsSync as existsSync24 } from "node:fs";
38848
38966
  import { readFile as readFile4, writeFile } from "node:fs/promises";
38849
- import { join as join24, resolve as resolve6 } from "node:path";
38967
+ import { join as join25, resolve as resolve7 } from "node:path";
38850
38968
  import { promisify as promisify2 } from "node:util";
38851
38969
  function makeCleoGitEnv(cleoDir) {
38852
- const abs = resolve6(cleoDir);
38970
+ const abs = resolve7(cleoDir);
38853
38971
  return {
38854
38972
  ...process.env,
38855
- GIT_DIR: join24(abs, ".git"),
38973
+ GIT_DIR: checkpointGitDir(abs),
38856
38974
  GIT_WORK_TREE: abs
38857
38975
  };
38858
38976
  }
38859
38977
  async function cleoGitCommand(args, cleoDir) {
38860
38978
  try {
38861
38979
  const result = await execFileAsync2("git", args, {
38862
- cwd: resolve6(cleoDir),
38980
+ cwd: resolve7(cleoDir),
38863
38981
  // absolute cwd so relative paths in args resolve correctly
38864
38982
  env: makeCleoGitEnv(cleoDir),
38865
38983
  timeout: 1e4
@@ -38870,7 +38988,7 @@ async function cleoGitCommand(args, cleoDir) {
38870
38988
  }
38871
38989
  }
38872
38990
  function isCleoGitInitialized(cleoDir) {
38873
- return existsSync24(join24(cleoDir, ".git", "HEAD"));
38991
+ return existsSync24(join25(checkpointGitDir(cleoDir), "HEAD"));
38874
38992
  }
38875
38993
  async function loadStateFileAllowlist(cwd) {
38876
38994
  try {
@@ -38914,25 +39032,25 @@ async function isCleoGitRepo(cleoDir) {
38914
39032
  return result.success && (result.stdout === "true" || isCleoGitInitialized(cleoDir));
38915
39033
  }
38916
39034
  function isMergeInProgress(cleoDir) {
38917
- return existsSync24(join24(cleoDir, ".git", "MERGE_HEAD"));
39035
+ return existsSync24(join25(checkpointGitDir(cleoDir), "MERGE_HEAD"));
38918
39036
  }
38919
39037
  async function isDetachedHead(cleoDir) {
38920
39038
  const result = await cleoGitCommand(["symbolic-ref", "HEAD"], cleoDir);
38921
39039
  return !result.success;
38922
39040
  }
38923
39041
  function isRebaseInProgress(cleoDir) {
38924
- return existsSync24(join24(cleoDir, ".git", "rebase-merge")) || existsSync24(join24(cleoDir, ".git", "rebase-apply"));
39042
+ return existsSync24(join25(checkpointGitDir(cleoDir), "rebase-merge")) || existsSync24(join25(checkpointGitDir(cleoDir), "rebase-apply"));
38925
39043
  }
38926
39044
  async function recordCheckpointTime(cleoDir) {
38927
39045
  try {
38928
- const stateFile = join24(cleoDir, CHECKPOINT_STATE_FILE);
39046
+ const stateFile = join25(cleoDir, CHECKPOINT_STATE_FILE);
38929
39047
  await writeFile(stateFile, String(Math.floor(Date.now() / 1e3)));
38930
39048
  } catch {
38931
39049
  }
38932
39050
  }
38933
39051
  async function getLastCheckpointTime(cleoDir) {
38934
39052
  try {
38935
- const stateFile = join24(cleoDir, CHECKPOINT_STATE_FILE);
39053
+ const stateFile = join25(cleoDir, CHECKPOINT_STATE_FILE);
38936
39054
  const content = await readFile4(stateFile, "utf-8");
38937
39055
  const epoch = parseInt(content.trim(), 10);
38938
39056
  return Number.isNaN(epoch) ? 0 : epoch;
@@ -38944,7 +39062,7 @@ async function getChangedStateFiles(cleoDir, cwd) {
38944
39062
  const changed = [];
38945
39063
  const allStateFiles = await getAllStateFiles(cwd);
38946
39064
  for (const stateFile of allStateFiles) {
38947
- const fullPath = join24(cleoDir, stateFile);
39065
+ const fullPath = join25(cleoDir, stateFile);
38948
39066
  if (!existsSync24(fullPath)) continue;
38949
39067
  const diffResult = await cleoGitCommand(["diff", "--quiet", "--", stateFile], cleoDir);
38950
39068
  const cachedResult = await cleoGitCommand(
@@ -39029,6 +39147,7 @@ var init_git_checkpoint = __esm({
39029
39147
  "packages/core/src/store/git-checkpoint.ts"() {
39030
39148
  "use strict";
39031
39149
  init_paths();
39150
+ init_checkpoint_git_dir();
39032
39151
  init_json();
39033
39152
  execFileAsync2 = promisify2(execFile2);
39034
39153
  STATE_FILES = [