@cleocode/core 2026.8.1 → 2026.8.2

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 (174) 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/db/index.d.ts +13 -0
  5. package/dist/db/index.d.ts.map +1 -1
  6. package/dist/db/index.js +13 -0
  7. package/dist/db/index.js.map +1 -1
  8. package/dist/docs/display-alias.js +1 -1
  9. package/dist/docs/display-alias.js.map +1 -1
  10. package/dist/docs/export-document.js +434 -365
  11. package/dist/docs/export-document.js.map +3 -3
  12. package/dist/docs/numbering.js +1 -1
  13. package/dist/docs/numbering.js.map +1 -1
  14. package/dist/docs/supersede.js +1 -1
  15. package/dist/docs/supersede.js.map +1 -1
  16. package/dist/injection.d.ts.map +1 -1
  17. package/dist/injection.js +44 -3
  18. package/dist/injection.js.map +1 -1
  19. package/dist/lifecycle/index.js +1 -1
  20. package/dist/lifecycle/index.js.map +1 -1
  21. package/dist/llm/plugin-facade.js +232 -96
  22. package/dist/llm/plugin-facade.js.map +3 -3
  23. package/dist/memory/brain-backfill.js +3 -3
  24. package/dist/memory/brain-backfill.js.map +1 -1
  25. package/dist/memory/brain-consolidator.js +2 -2
  26. package/dist/memory/brain-consolidator.js.map +1 -1
  27. package/dist/memory/brain-doctor.js +1 -1
  28. package/dist/memory/brain-doctor.js.map +1 -1
  29. package/dist/memory/brain-health-dashboard.js +1 -1
  30. package/dist/memory/brain-health-dashboard.js.map +1 -1
  31. package/dist/memory/brain-lifecycle.js +10 -10
  32. package/dist/memory/brain-lifecycle.js.map +1 -1
  33. package/dist/memory/brain-maintenance.js +1 -1
  34. package/dist/memory/brain-maintenance.js.map +1 -1
  35. package/dist/memory/brain-page-nodes.js +4 -4
  36. package/dist/memory/brain-page-nodes.js.map +1 -1
  37. package/dist/memory/brain-reasoning.js +1 -1
  38. package/dist/memory/brain-reasoning.js.map +1 -1
  39. package/dist/memory/brain-search.js +1 -1
  40. package/dist/memory/brain-search.js.map +1 -1
  41. package/dist/memory/brain-similarity.js +1 -1
  42. package/dist/memory/brain-similarity.js.map +1 -1
  43. package/dist/memory/brain-stdp.js +6 -6
  44. package/dist/memory/brain-stdp.js.map +1 -1
  45. package/dist/memory/brain-sweep-executor.js +1 -1
  46. package/dist/memory/brain-sweep-executor.js.map +1 -1
  47. package/dist/memory/brain-writer-handlers.js +2 -2
  48. package/dist/memory/brain-writer-handlers.js.map +1 -1
  49. package/dist/memory/claude-mem-migration.d.ts.map +1 -1
  50. package/dist/memory/claude-mem-migration.js +2 -2
  51. package/dist/memory/claude-mem-migration.js.map +1 -1
  52. package/dist/memory/engine-compat.js +4 -4
  53. package/dist/memory/engine-compat.js.map +1 -1
  54. package/dist/memory/extraction-gate.js +3 -3
  55. package/dist/memory/extraction-gate.js.map +1 -1
  56. package/dist/memory/graph-memory-bridge.js +9 -9
  57. package/dist/memory/graph-memory-bridge.js.map +1 -1
  58. package/dist/memory/graph-queries.js +4 -4
  59. package/dist/memory/graph-queries.js.map +1 -1
  60. package/dist/memory/llm-extraction.js +1 -1
  61. package/dist/memory/llm-extraction.js.map +1 -1
  62. package/dist/memory/memory-bridge.js +1 -1
  63. package/dist/memory/memory-bridge.js.map +1 -1
  64. package/dist/memory/nexus-plasticity.js +1 -1
  65. package/dist/memory/nexus-plasticity.js.map +1 -1
  66. package/dist/memory/observer-reflector.js +1 -1
  67. package/dist/memory/observer-reflector.js.map +1 -1
  68. package/dist/memory/pipeline-manifest-sqlite.d.ts.map +1 -1
  69. package/dist/memory/pipeline-manifest-sqlite.js +13 -3
  70. package/dist/memory/pipeline-manifest-sqlite.js.map +1 -1
  71. package/dist/memory/quality-feedback.js +4 -4
  72. package/dist/memory/quality-feedback.js.map +1 -1
  73. package/dist/memory/retrieval/increment-citation-counts.js +1 -1
  74. package/dist/memory/retrieval/increment-citation-counts.js.map +1 -1
  75. package/dist/memory/retrieval/log-retrieval.js +1 -1
  76. package/dist/memory/retrieval/log-retrieval.js.map +1 -1
  77. package/dist/memory/retrieval/observe.js +1 -1
  78. package/dist/memory/retrieval/observe.js.map +1 -1
  79. package/dist/memory/retrieval/search.js +1 -1
  80. package/dist/memory/retrieval/search.js.map +1 -1
  81. package/dist/memory/retrieval/timeline.js +1 -1
  82. package/dist/memory/retrieval/timeline.js.map +1 -1
  83. package/dist/memory/sleep-consolidation.js +4 -4
  84. package/dist/memory/sleep-consolidation.js.map +1 -1
  85. package/dist/memory/temporal-supersession.js +5 -5
  86. package/dist/memory/temporal-supersession.js.map +1 -1
  87. package/dist/memory/transcript-extractor.js +1 -1
  88. package/dist/memory/transcript-extractor.js.map +1 -1
  89. package/dist/memory/transcript-ingestor.js +1 -1
  90. package/dist/memory/transcript-ingestor.js.map +1 -1
  91. package/dist/memory/transcript-scanner.js +1 -1
  92. package/dist/memory/transcript-scanner.js.map +1 -1
  93. package/dist/nexus/living-brain.js +7 -7
  94. package/dist/nexus/living-brain.js.map +1 -1
  95. package/dist/nexus/tasks-bridge.js +4 -4
  96. package/dist/nexus/tasks-bridge.js.map +1 -1
  97. package/dist/release/reconcile.d.ts.map +1 -1
  98. package/dist/release/reconcile.js +5 -1
  99. package/dist/release/reconcile.js.map +1 -1
  100. package/dist/sagas/migrate-containment.d.ts.map +1 -1
  101. package/dist/sagas/migrate-containment.js +4 -2
  102. package/dist/sagas/migrate-containment.js.map +1 -1
  103. package/dist/scaffold/ensure-dirs.js +1 -1
  104. package/dist/scaffold/ensure-dirs.js.map +1 -1
  105. package/dist/selfimprove/fix-gen.js +235 -99
  106. package/dist/selfimprove/fix-gen.js.map +3 -3
  107. package/dist/sentient/dream-cycle.js +1 -1
  108. package/dist/sentient/dream-cycle.js.map +1 -1
  109. package/dist/sentient/hygiene-scan.js +1 -1
  110. package/dist/sentient/hygiene-scan.js.map +1 -1
  111. package/dist/sentient/propose-tick.js +3 -3
  112. package/dist/sentient/propose-tick.js.map +1 -1
  113. package/dist/sentient/stage-drift-tick.js +1 -1
  114. package/dist/sentient/stage-drift-tick.js.map +1 -1
  115. package/dist/sequence/index.js +1 -1
  116. package/dist/sequence/index.js.map +1 -1
  117. package/dist/store/agent-registry-store.d.ts.map +1 -1
  118. package/dist/store/agent-registry-store.js +71 -28
  119. package/dist/store/agent-registry-store.js.map +1 -1
  120. package/dist/store/attachment-store.js +3 -3
  121. package/dist/store/attachment-store.js.map +1 -1
  122. package/dist/store/conduit-sqlite.d.ts +21 -1
  123. package/dist/store/conduit-sqlite.d.ts.map +1 -1
  124. package/dist/store/conduit-sqlite.js +42 -56
  125. package/dist/store/conduit-sqlite.js.map +1 -1
  126. package/dist/store/dual-scope-db.d.ts +39 -0
  127. package/dist/store/dual-scope-db.d.ts.map +1 -1
  128. package/dist/store/dual-scope-db.js +26 -8
  129. package/dist/store/dual-scope-db.js.map +1 -1
  130. package/dist/store/memory-sqlite.d.ts +57 -3
  131. package/dist/store/memory-sqlite.d.ts.map +1 -1
  132. package/dist/store/memory-sqlite.js +70 -89
  133. package/dist/store/memory-sqlite.js.map +1 -1
  134. package/dist/store/nexus-sqlite.d.ts +42 -0
  135. package/dist/store/nexus-sqlite.d.ts.map +1 -1
  136. package/dist/store/nexus-sqlite.js +79 -115
  137. package/dist/store/nexus-sqlite.js.map +1 -1
  138. package/dist/store/ports/domain-binding.d.ts +233 -0
  139. package/dist/store/ports/domain-binding.d.ts.map +1 -0
  140. package/dist/store/ports/domain-binding.js +500 -0
  141. package/dist/store/ports/domain-binding.js.map +1 -0
  142. package/dist/store/ports/fk-integrity.d.ts +155 -0
  143. package/dist/store/ports/fk-integrity.d.ts.map +1 -0
  144. package/dist/store/ports/fk-integrity.js +182 -0
  145. package/dist/store/ports/fk-integrity.js.map +1 -0
  146. package/dist/store/role-accessors-impl.js +2 -2
  147. package/dist/store/role-accessors-impl.js.map +1 -1
  148. package/dist/store/skills-db.d.ts +19 -0
  149. package/dist/store/skills-db.d.ts.map +1 -1
  150. package/dist/store/skills-db.js +80 -72
  151. package/dist/store/skills-db.js.map +1 -1
  152. package/dist/store/sqlite-backup.js +2 -2
  153. package/dist/store/sqlite-backup.js.map +1 -1
  154. package/dist/store/sqlite-data-accessor.js +1 -1
  155. package/dist/store/sqlite-data-accessor.js.map +1 -1
  156. package/dist/store/sqlite.d.ts +72 -10
  157. package/dist/store/sqlite.d.ts.map +1 -1
  158. package/dist/store/sqlite.js +173 -160
  159. package/dist/store/sqlite.js.map +1 -1
  160. package/dist/store/tasks-sqlite.js +2 -2
  161. package/dist/store/tasks-sqlite.js.map +1 -1
  162. package/dist/system/health.d.ts +0 -4
  163. package/dist/system/health.d.ts.map +1 -1
  164. package/dist/system/health.js +58 -2
  165. package/dist/system/health.js.map +1 -1
  166. package/dist/upgrade.js +2 -2
  167. package/dist/upgrade.js.map +1 -1
  168. package/dist/validation/doctor/checks.d.ts +23 -1
  169. package/dist/validation/doctor/checks.d.ts.map +1 -1
  170. package/dist/validation/doctor/checks.js +79 -19
  171. package/dist/validation/doctor/checks.js.map +1 -1
  172. package/dist/worktree/list.js +1 -1
  173. package/dist/worktree/list.js.map +1 -1
  174. package/package.json +22 -12
@@ -102,9 +102,9 @@ function getLogDir() {
102
102
  return currentLogDir;
103
103
  }
104
104
  function closeLogger() {
105
- return new Promise((resolve6) => {
105
+ return new Promise((resolve7) => {
106
106
  if (!rootLogger) {
107
- resolve6();
107
+ resolve7();
108
108
  return;
109
109
  }
110
110
  const logger8 = rootLogger;
@@ -116,7 +116,7 @@ function closeLogger() {
116
116
  rootLogger = null;
117
117
  currentLogDir = null;
118
118
  currentTransport = null;
119
- resolve6();
119
+ resolve7();
120
120
  };
121
121
  logger8.flush(() => {
122
122
  if (transport && typeof transport.end === "function") {
@@ -15796,6 +15796,18 @@ var init_service_provider = __esm({
15796
15796
  }
15797
15797
  });
15798
15798
 
15799
+ // packages/contracts/src/caamp-markers.ts
15800
+ var H, damagedMarkerSource, CAAMP_DAMAGED_START_PATTERN_SOURCE, CAAMP_DAMAGED_END_PATTERN_SOURCE;
15801
+ var init_caamp_markers = __esm({
15802
+ "packages/contracts/src/caamp-markers.ts"() {
15803
+ "use strict";
15804
+ H = "[ \\t\\r]";
15805
+ damagedMarkerSource = (keyword) => `^${H}*[<!-]{1,4}${H}*CAAMP${H}*:${H}*${keyword}${H}*[->]{1,3}${H}*$`;
15806
+ CAAMP_DAMAGED_START_PATTERN_SOURCE = damagedMarkerSource("START");
15807
+ CAAMP_DAMAGED_END_PATTERN_SOURCE = damagedMarkerSource("END");
15808
+ }
15809
+ });
15810
+
15799
15811
  // packages/contracts/src/index.ts
15800
15812
  var init_src = __esm({
15801
15813
  "packages/contracts/src/index.ts"() {
@@ -15863,6 +15875,7 @@ var init_src = __esm({
15863
15875
  init_validator();
15864
15876
  init_service_provider();
15865
15877
  init_workgraph();
15878
+ init_caamp_markers();
15866
15879
  }
15867
15880
  });
15868
15881
 
@@ -23712,7 +23725,7 @@ function resolveDbIdentity(db) {
23712
23725
  return identity;
23713
23726
  }
23714
23727
  function sleepAsync(ms) {
23715
- return new Promise((resolve6) => setTimeout(resolve6, Math.max(0, Math.round(ms))));
23728
+ return new Promise((resolve7) => setTimeout(resolve7, Math.max(0, Math.round(ms))));
23716
23729
  }
23717
23730
  function isPidAlive(pid) {
23718
23731
  try {
@@ -24530,7 +24543,7 @@ async function sendResourceRelease(socketPath, cls, holderId) {
24530
24543
  return { unavailable: true, reason: `unexpected response kind: ${result.kind}` };
24531
24544
  }
24532
24545
  function sendLeaseRequest(socketPath, request, expectedKind) {
24533
- return new Promise((resolve6) => {
24546
+ return new Promise((resolve7) => {
24534
24547
  const id = `ra-${process.pid}-${request.kind}`;
24535
24548
  const envelope = LeaseIpcRequestEnvelopeSchema.parse({
24536
24549
  protocol_version: LEASE_IPC_PROTOCOL_VERSION,
@@ -24548,7 +24561,7 @@ function sendLeaseRequest(socketPath, request, expectedKind) {
24548
24561
  settled = true;
24549
24562
  socket.removeAllListeners();
24550
24563
  socket.destroy();
24551
- resolve6(value);
24564
+ resolve7(value);
24552
24565
  };
24553
24566
  const degrade = (reason) => done({ unavailable: true, reason });
24554
24567
  socket.setTimeout(REQUEST_TIMEOUT_MS);
@@ -27973,8 +27986,8 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
27973
27986
  }
27974
27987
  let initResolve = null;
27975
27988
  let initReject = null;
27976
- const initPromise = new Promise((resolve6, reject) => {
27977
- initResolve = resolve6;
27989
+ const initPromise = new Promise((resolve7, reject) => {
27990
+ initResolve = resolve7;
27978
27991
  initReject = reject;
27979
27992
  });
27980
27993
  _cache.set(key, {
@@ -28227,24 +28240,35 @@ var init_dual_scope_db = __esm({
28227
28240
  async openProject(dbPath, options) {
28228
28241
  const normalized = resolve3(dbPath);
28229
28242
  if (options?.dedicated) {
28230
- const handle = await openDualScopeDbAtPath("project", normalized, void 0, {
28243
+ const handle = await openDualScopeDbAtPath("project", normalized, options?.exodusCwd, {
28231
28244
  dedicated: true
28232
28245
  });
28233
28246
  return this.buildStore("project", handle, 0);
28234
28247
  }
28235
- return this.openEntry("project", normalized);
28248
+ return this.openEntry("project", normalized, 0, options?.exodusCwd);
28236
28249
  }
28237
28250
  /** @inheritdoc */
28238
28251
  async openGlobal(options) {
28239
28252
  const dbPath = resolveDualScopeDbPath("global");
28240
28253
  const normalized = resolve3(dbPath);
28241
28254
  if (options?.dedicated) {
28242
- const handle = await openDualScopeDbAtPath("global", normalized, void 0, {
28255
+ const handle = await openDualScopeDbAtPath("global", normalized, options?.exodusCwd, {
28256
+ dedicated: true
28257
+ });
28258
+ return this.buildStore("global", handle, 0);
28259
+ }
28260
+ return this.openEntry("global", normalized, 0, options?.exodusCwd);
28261
+ }
28262
+ /** @inheritdoc */
28263
+ async openGlobalAt(dbPath, options) {
28264
+ const normalized = resolve3(dbPath);
28265
+ if (options?.dedicated) {
28266
+ const handle = await openDualScopeDbAtPath("global", normalized, options?.exodusCwd, {
28243
28267
  dedicated: true
28244
28268
  });
28245
28269
  return this.buildStore("global", handle, 0);
28246
28270
  }
28247
- return this.openEntry("global", normalized);
28271
+ return this.openEntry("global", normalized, 0, options?.exodusCwd);
28248
28272
  }
28249
28273
  /** @inheritdoc */
28250
28274
  closeProject(dbPath) {
@@ -28270,7 +28294,7 @@ var init_dual_scope_db = __esm({
28270
28294
  * retry calls this with `depth + 1`. A second dead handle at depth 1
28271
28295
  * throws {@link LivenessExhaustedError} instead of recursing further.
28272
28296
  */
28273
- async openEntry(scope, dbPath, depth = 0) {
28297
+ async openEntry(scope, dbPath, depth = 0, exodusCwd) {
28274
28298
  const key = cacheKey(scope, dbPath);
28275
28299
  const existing = this._registry.get(key);
28276
28300
  if (existing) {
@@ -28285,8 +28309,8 @@ var init_dual_scope_db = __esm({
28285
28309
  const entryId = ++this._nextId;
28286
28310
  let initResolve;
28287
28311
  let initReject;
28288
- const initPromise = new Promise((resolve6, reject) => {
28289
- initResolve = resolve6;
28312
+ const initPromise = new Promise((resolve7, reject) => {
28313
+ initResolve = resolve7;
28290
28314
  initReject = reject;
28291
28315
  });
28292
28316
  this._registry.set(key, { id: entryId, store: null, initPromise });
@@ -28297,7 +28321,7 @@ var init_dual_scope_db = __esm({
28297
28321
  }
28298
28322
  });
28299
28323
  try {
28300
- const dualHandle = scope === "project" ? await this.openDualScopeFn("project", dbPath) : await this.openDualScopeFn("global", dbPath);
28324
+ const dualHandle = scope === "project" ? await this.openDualScopeFn("project", dbPath, exodusCwd) : await this.openDualScopeFn("global", dbPath, exodusCwd);
28301
28325
  const current = this._registry.get(key);
28302
28326
  if (!current || current.id !== entryId) {
28303
28327
  throw new EntryCancelledError(scope, dbPath);
@@ -28308,7 +28332,7 @@ var init_dual_scope_db = __esm({
28308
28332
  if (depth >= 1) {
28309
28333
  throw new LivenessExhaustedError(scope, dbPath);
28310
28334
  }
28311
- const retryStore = await this.openEntry(scope, dbPath, depth + 1);
28335
+ const retryStore = await this.openEntry(scope, dbPath, depth + 1, exodusCwd);
28312
28336
  initResolve(retryStore);
28313
28337
  return retryStore;
28314
28338
  }
@@ -28404,6 +28428,151 @@ var init_dual_scope_db = __esm({
28404
28428
  }
28405
28429
  });
28406
28430
 
28431
+ // packages/core/src/store/ports/domain-binding.ts
28432
+ import { resolve as resolve4 } from "node:path";
28433
+ function getCleoRuntime() {
28434
+ if (!_runtime) {
28435
+ _runtime = createCleoRuntime();
28436
+ }
28437
+ return _runtime;
28438
+ }
28439
+ function bindingKey(scope, dbPath, domain2) {
28440
+ return `${scope}::${dbPath}::${domain2}`;
28441
+ }
28442
+ function nativeOf(store) {
28443
+ const native = store.db.$client;
28444
+ if (!native) {
28445
+ throw new Error(
28446
+ `T12037: CleoRuntime store for ${store.scope}::${store.dbPath} exposed no $client \u2014 cannot bind a domain schema to it.`
28447
+ );
28448
+ }
28449
+ return native;
28450
+ }
28451
+ function reuseValid(key, store) {
28452
+ const row = _bindings.get(key);
28453
+ if (!row) return void 0;
28454
+ if (row.store !== store || !store.isOpen || !row.native.isOpen) {
28455
+ _bindings.delete(key);
28456
+ return void 0;
28457
+ }
28458
+ return row;
28459
+ }
28460
+ async function bindAgainst(key, store, establish) {
28461
+ const cached2 = reuseValid(key, store);
28462
+ if (cached2) return cached2;
28463
+ const pending = _inflight.get(key);
28464
+ if (pending) {
28465
+ const row = await pending;
28466
+ if (row.store === store && row.native.isOpen) return row;
28467
+ return bindAgainst(key, store, establish);
28468
+ }
28469
+ const native = nativeOf(store);
28470
+ const flight = (async () => {
28471
+ const db = await establish(native, store);
28472
+ const row = { store, native, db };
28473
+ if (store.isOpen && native.isOpen) {
28474
+ _bindings.set(key, row);
28475
+ }
28476
+ return row;
28477
+ })();
28478
+ _inflight.set(key, flight);
28479
+ try {
28480
+ return await flight;
28481
+ } finally {
28482
+ if (_inflight.get(key) === flight) {
28483
+ _inflight.delete(key);
28484
+ }
28485
+ }
28486
+ }
28487
+ async function bindLive(scope, key, dbPath, openStore, establish) {
28488
+ let lastError;
28489
+ for (let attempt = 0; attempt < MAX_LIVENESS_ATTEMPTS; attempt += 1) {
28490
+ let store;
28491
+ try {
28492
+ store = await openStore();
28493
+ } catch (err) {
28494
+ lastError = err;
28495
+ releaseDomainBindings({ scope, dbPath });
28496
+ if (attempt + 1 >= MAX_LIVENESS_ATTEMPTS) throw err;
28497
+ continue;
28498
+ }
28499
+ try {
28500
+ const row = await bindAgainst(key, store, establish);
28501
+ if (row.store.isOpen && row.native.isOpen) return row;
28502
+ } catch (err) {
28503
+ lastError = err;
28504
+ if (store.isOpen) throw err;
28505
+ }
28506
+ releaseDomainBindings({ scope, dbPath });
28507
+ try {
28508
+ store.close();
28509
+ } catch {
28510
+ }
28511
+ }
28512
+ if (lastError !== void 0) throw lastError;
28513
+ throw new Error(
28514
+ `T12037: could not bind ${key} over a live connection after ${MAX_LIVENESS_ATTEMPTS} attempts \u2014 the consolidated handle was closed each time.`
28515
+ );
28516
+ }
28517
+ async function bindProjectDomain(domain2, cwd, establish) {
28518
+ const dbPath = resolve4(resolveDualScopeDbPath("project", cwd));
28519
+ const row = await bindLive(
28520
+ "project",
28521
+ bindingKey("project", dbPath, domain2),
28522
+ dbPath,
28523
+ () => getCleoRuntime().openProject(dbPath, { exodusCwd: cwd }),
28524
+ establish
28525
+ );
28526
+ return row;
28527
+ }
28528
+ function releaseDomainBindings(filter2) {
28529
+ if (!filter2) {
28530
+ _bindings.clear();
28531
+ return;
28532
+ }
28533
+ const wantPath = filter2.dbPath === void 0 ? void 0 : resolve4(filter2.dbPath);
28534
+ for (const key of [..._bindings.keys()]) {
28535
+ const sep = key.indexOf("::");
28536
+ const lastSep = key.lastIndexOf("::");
28537
+ const scope = key.slice(0, sep);
28538
+ const dbPath = key.slice(sep + 2, lastSep);
28539
+ const domain2 = key.slice(lastSep + 2);
28540
+ if (filter2.scope !== void 0 && scope !== filter2.scope) continue;
28541
+ if (wantPath !== void 0 && dbPath !== wantPath) continue;
28542
+ if (filter2.domain !== void 0 && domain2 !== filter2.domain) continue;
28543
+ _bindings.delete(key);
28544
+ }
28545
+ }
28546
+ function boundProjectNative(domain2, cwd) {
28547
+ return peekProjectDomain(domain2, cwd)?.native ?? null;
28548
+ }
28549
+ function peekProjectDomain(domain2, cwd) {
28550
+ const dbPath = resolve4(resolveDualScopeDbPath("project", cwd));
28551
+ const row = _bindings.get(bindingKey("project", dbPath, domain2));
28552
+ if (row?.native.isOpen) return row;
28553
+ if (cwd !== void 0) return null;
28554
+ const suffix = `::${domain2}`;
28555
+ let sole;
28556
+ for (const [key, candidate] of _bindings) {
28557
+ if (!key.startsWith("project::") || !key.endsWith(suffix)) continue;
28558
+ if (!candidate.native.isOpen) continue;
28559
+ if (sole) return null;
28560
+ sole = candidate;
28561
+ }
28562
+ return sole ?? null;
28563
+ }
28564
+ var _runtime, _bindings, _inflight, MAX_LIVENESS_ATTEMPTS;
28565
+ var init_domain_binding = __esm({
28566
+ "packages/core/src/store/ports/domain-binding.ts"() {
28567
+ "use strict";
28568
+ init_dual_scope_db();
28569
+ _runtime = null;
28570
+ _bindings = /* @__PURE__ */ new Map();
28571
+ _inflight = /* @__PURE__ */ new Map();
28572
+ MAX_LIVENESS_ATTEMPTS = 2;
28573
+ }
28574
+ });
28575
+
28407
28576
  // packages/core/src/store/schema/nexus-schema.ts
28408
28577
  var nexus_schema_exports = {};
28409
28578
  __export(nexus_schema_exports, {
@@ -28912,6 +29081,7 @@ var nexus_sqlite_exports = {};
28912
29081
  __export(nexus_sqlite_exports, {
28913
29082
  NEXUS_SCHEMA_VERSION: () => NEXUS_SCHEMA_VERSION,
28914
29083
  _resetNestedNexusWarningGate: () => _resetNestedNexusWarningGate,
29084
+ bindNexusDomain: () => bindNexusDomain,
28915
29085
  closeNexusDb: () => closeNexusDb,
28916
29086
  detectAndWarnOnNestedNexus: () => detectAndWarnOnNestedNexus,
28917
29087
  getNestedNexusSentinelPath: () => getNestedNexusSentinelPath,
@@ -29120,13 +29290,13 @@ function ensureNexusRelationWeights(nativeDb) {
29120
29290
  nativeDb.exec(`PRAGMA foreign_keys=${fkWasOn ? "ON" : "OFF"}`);
29121
29291
  }
29122
29292
  }
29123
- function runNexusMigrations(nativeDb, db) {
29293
+ function runNexusMigrations(nativeDb, db, dbPath) {
29124
29294
  const migrationsFolder = resolveNexusMigrationsFolder();
29125
- if (tableExists4(nativeDb, "nexus_nodes") && _nexusDbPath) {
29126
- const backupPath = _nexusDbPath.replace(/\.db$/, "-pre-cleo.db.bak");
29295
+ if (tableExists4(nativeDb, "nexus_nodes")) {
29296
+ const backupPath = dbPath.replace(/\.db$/, "-pre-cleo.db.bak");
29127
29297
  if (!existsSync15(backupPath)) {
29128
29298
  try {
29129
- copyFileSync4(_nexusDbPath, backupPath);
29299
+ copyFileSync4(dbPath, backupPath);
29130
29300
  } catch {
29131
29301
  }
29132
29302
  }
@@ -29168,75 +29338,45 @@ function runNexusMigrations(nativeDb, db) {
29168
29338
  ensureNexusFts5(nativeDb);
29169
29339
  }
29170
29340
  async function getNexusDb() {
29171
- const requestedPath = getNexusDbPath();
29341
+ return (await bindNexusDomain()).db.drizzle;
29342
+ }
29343
+ async function bindNexusDomain() {
29172
29344
  const requestedRegistryPath = getNexusRegistryDbPath();
29173
- if (_nexusDb && _nexusDbPath !== requestedPath) {
29174
- resetNexusDbState();
29175
- }
29176
- if (_nexusDb && _nexusRegistryPath !== requestedRegistryPath) {
29177
- resetNexusDbState();
29345
+ const bound = peekProjectDomain("nexus");
29346
+ if (bound && bound.db.registryPath !== requestedRegistryPath) {
29347
+ releaseDomainBindings({ scope: "project", domain: "nexus" });
29178
29348
  }
29179
- if (_nexusDb && (_nexusNativeDb === null || !_nexusNativeDb.isOpen)) {
29180
- resetNexusDbState();
29181
- }
29182
- if (_nexusDb) {
29183
- if (_nexusNativeDb) {
29184
- try {
29185
- ensureGlobalRegistryAttached(_nexusNativeDb);
29186
- } catch {
29187
- resetNexusDbState();
29188
- }
29189
- }
29190
- if (_nexusDb) return _nexusDb;
29191
- }
29192
- if (_nexusInitPromise) return _nexusInitPromise;
29193
- _nexusInitPromise = (async () => {
29194
- const dbPath = requestedPath;
29195
- _nexusDbPath = dbPath;
29196
- _nexusRegistryPath = requestedRegistryPath;
29197
- detectAndWarnOnNestedNexus();
29198
- await openDualScopeDb("global");
29199
- const dualHandle = await openDualScopeDb("project");
29200
- const nativeDb = dualHandle.db.$client ?? null;
29201
- if (!nativeDb) {
29202
- throw new Error(
29203
- "T11648: openDualScopeDb returned a handle without $client \u2014 cannot extract DatabaseSync for the nexus-schema drizzle wrapping."
29204
- );
29205
- }
29206
- _nexusNativeDb = nativeDb;
29349
+ detectAndWarnOnNestedNexus();
29350
+ await openDualScopeDb("global");
29351
+ const binding = await bindProjectDomain("nexus", void 0, (nativeDb, store) => {
29207
29352
  ensureGlobalRegistryAttached(nativeDb);
29208
29353
  const db = drizzle({ client: nativeDb });
29209
- runNexusMigrations(nativeDb, db);
29354
+ runNexusMigrations(nativeDb, db, store.dbPath);
29210
29355
  nativeDb.prepare(
29211
29356
  `INSERT OR IGNORE INTO nexus_schema_meta (key, value) VALUES ('schemaVersion', '${NEXUS_SCHEMA_VERSION}')`
29212
29357
  ).run();
29213
- _nexusDb = db;
29214
- return db;
29215
- })();
29358
+ return { drizzle: db, registryPath: requestedRegistryPath };
29359
+ });
29216
29360
  try {
29217
- return await _nexusInitPromise;
29218
- } finally {
29219
- _nexusInitPromise = null;
29361
+ ensureGlobalRegistryAttached(binding.native);
29362
+ } catch {
29363
+ releaseDomainBindings({ scope: "project", domain: "nexus" });
29364
+ throw new Error(
29365
+ "T12039: nexus binding lost its GLOBAL registry ATTACH and could not re-attach."
29366
+ );
29220
29367
  }
29368
+ return binding;
29221
29369
  }
29222
29370
  function closeNexusDb() {
29223
- _nexusNativeDb = null;
29224
- _nexusDb = null;
29225
- _nexusDbPath = null;
29226
- _nexusRegistryPath = null;
29227
- _nexusInitPromise = null;
29371
+ releaseDomainBindings({ scope: "project", domain: "nexus" });
29228
29372
  }
29229
29373
  function resetNexusDbState() {
29230
- _nexusNativeDb = null;
29231
- _nexusDb = null;
29232
- _nexusDbPath = null;
29233
- _nexusRegistryPath = null;
29234
- _nexusInitPromise = null;
29374
+ releaseDomainBindings({ scope: "project", domain: "nexus" });
29235
29375
  }
29236
29376
  function getNexusNativeDb() {
29237
- return _nexusNativeDb;
29377
+ return boundProjectNative("nexus");
29238
29378
  }
29239
- var NEXUS_SCHEMA_VERSION, _nexusDb, _nexusNativeDb, _nexusDbPath, _nexusRegistryPath, _nexusInitPromise, NEXUS_GLOBAL_ATTACH_ALIAS, NESTED_NEXUS_SENTINEL, _warnedNestedPaths;
29379
+ var NEXUS_SCHEMA_VERSION, NEXUS_GLOBAL_ATTACH_ALIAS, NESTED_NEXUS_SENTINEL, _warnedNestedPaths;
29240
29380
  var init_nexus_sqlite = __esm({
29241
29381
  "packages/core/src/store/nexus-sqlite.ts"() {
29242
29382
  "use strict";
@@ -29245,15 +29385,11 @@ var init_nexus_sqlite = __esm({
29245
29385
  init_paths();
29246
29386
  init_dual_scope_db();
29247
29387
  init_migration_manager();
29388
+ init_domain_binding();
29248
29389
  init_resolve_migrations_folder();
29249
29390
  init_nexus_schema();
29250
29391
  init_with_retry();
29251
29392
  NEXUS_SCHEMA_VERSION = "1.0.0";
29252
- _nexusDb = null;
29253
- _nexusNativeDb = null;
29254
- _nexusDbPath = null;
29255
- _nexusRegistryPath = null;
29256
- _nexusInitPromise = null;
29257
29393
  NEXUS_GLOBAL_ATTACH_ALIAS = "nexus_global";
29258
29394
  NESTED_NEXUS_SENTINEL = "nexus.db";
29259
29395
  _warnedNestedPaths = /* @__PURE__ */ new Set();
@@ -29265,7 +29401,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
29265
29401
  import { existsSync as existsSync16, readFileSync as readFileSync5, statSync as statSync5 } from "node:fs";
29266
29402
  import { createRequire as createRequire5 } from "node:module";
29267
29403
  import { homedir } from "node:os";
29268
- import { basename as basename4, dirname as dirname7, join as join17, resolve as resolve4 } from "node:path";
29404
+ import { basename as basename4, dirname as dirname7, join as join17, resolve as resolve5 } from "node:path";
29269
29405
  import {
29270
29406
  computeCanonicalProjectId as _computeCanonicalProjectId,
29271
29407
  getCanonicalTemplatesTildePath as _getCanonicalTemplatesTildePath,
@@ -29332,24 +29468,24 @@ function getCleoDirAbsolute(cwd, opts) {
29332
29468
  try {
29333
29469
  const projectRoot = getProjectRoot(cwd);
29334
29470
  const canonical = _resolveCanonicalCleoDir(project.projectId);
29335
- if (canonical !== null && canonical === resolve4(projectRoot, cleoDir)) {
29471
+ if (canonical !== null && canonical === resolve5(projectRoot, cleoDir)) {
29336
29472
  return canonical;
29337
29473
  }
29338
- return resolve4(projectRoot, cleoDir);
29474
+ return resolve5(projectRoot, cleoDir);
29339
29475
  } catch {
29340
- return resolve4(project.projectRoot, cleoDir);
29476
+ return resolve5(project.projectRoot, cleoDir);
29341
29477
  }
29342
29478
  }
29343
29479
  try {
29344
- return resolve4(getProjectRoot(cwd), cleoDir);
29480
+ return resolve5(getProjectRoot(cwd), cleoDir);
29345
29481
  } catch (err) {
29346
29482
  if (opts?.bootstrap) {
29347
- return resolve4(cwd ?? process.cwd(), cleoDir);
29483
+ return resolve5(cwd ?? process.cwd(), cleoDir);
29348
29484
  }
29349
29485
  if (_cwdHasGitAncestor(cwd)) {
29350
29486
  throw err;
29351
29487
  }
29352
- return resolve4(cwd ?? process.cwd(), cleoDir);
29488
+ return resolve5(cwd ?? process.cwd(), cleoDir);
29353
29489
  }
29354
29490
  }
29355
29491
  function _resolveProjectByCwdFromNexus(cwd) {
@@ -29357,7 +29493,7 @@ function _resolveProjectByCwdFromNexus(cwd) {
29357
29493
  const cleoHome = getCleoHome();
29358
29494
  const globalDbPath = join17(cleoHome, "cleo.db");
29359
29495
  if (!existsSync16(globalDbPath)) return null;
29360
- const start = resolve4(cwd ?? process.cwd());
29496
+ const start = resolve5(cwd ?? process.cwd());
29361
29497
  let current = start;
29362
29498
  const DatabaseSync2 = _getDatabaseSyncCtor();
29363
29499
  const db = new DatabaseSync2(globalDbPath, { readOnly: true });
@@ -29390,7 +29526,7 @@ function _cleoDirEnvOverride() {
29390
29526
  }
29391
29527
  function _findCleoDirRoot(cwd) {
29392
29528
  const homeRoot = homedir();
29393
- let current = resolve4(cwd ?? process.cwd());
29529
+ let current = resolve5(cwd ?? process.cwd());
29394
29530
  while (true) {
29395
29531
  const isDangerousRoot = current === homeRoot || current === "/" || current === "";
29396
29532
  if (!isDangerousRoot) {
@@ -29420,7 +29556,7 @@ function resolveCleoDir(cwd) {
29420
29556
  if (root !== null) {
29421
29557
  return join17(root, ".cleo");
29422
29558
  }
29423
- const start = resolve4(cwd ?? process.cwd());
29559
+ const start = resolve5(cwd ?? process.cwd());
29424
29560
  let current = start;
29425
29561
  while (true) {
29426
29562
  const mainRepo = _resolveMainRepoFromGitlink(current);
@@ -29456,15 +29592,15 @@ function _resolveCleoDir(cwd) {
29456
29592
  const project = _pathsResolveProjectByCwd(cwd);
29457
29593
  if (project !== null) {
29458
29594
  try {
29459
- return resolve4(getProjectRoot(cwd), cleoDir);
29595
+ return resolve5(getProjectRoot(cwd), cleoDir);
29460
29596
  } catch {
29461
- return resolve4(project.projectRoot, cleoDir);
29597
+ return resolve5(project.projectRoot, cleoDir);
29462
29598
  }
29463
29599
  }
29464
29600
  return getCleoDirAbsolute(cwd);
29465
29601
  }
29466
29602
  function _cwdHasGitAncestor(cwd) {
29467
- const start = resolve4(cwd ?? process.cwd());
29603
+ const start = resolve5(cwd ?? process.cwd());
29468
29604
  let current = start;
29469
29605
  while (true) {
29470
29606
  const gitMarker = join17(current, ".git");
@@ -29564,7 +29700,7 @@ function getProjectRoot(cwd) {
29564
29700
  }
29565
29701
  return cleoDirEnv;
29566
29702
  }
29567
- const start = resolve4(cwd ?? process.cwd());
29703
+ const start = resolve5(cwd ?? process.cwd());
29568
29704
  let current = start;
29569
29705
  const mainRepoFromStart = _resolveMainRepoFromGitlink(start);
29570
29706
  if (mainRepoFromStart !== null) return mainRepoFromStart;
@@ -29657,7 +29793,7 @@ async function registerProjectOnEncounter(projectRoot, infoProjectId) {
29657
29793
  const db = await getNexusDb2();
29658
29794
  const existingRows = await db.select().from(projectRegistry2).where(eq2(projectRegistry2.projectId, immutableId)).limit(1);
29659
29795
  const now = (/* @__PURE__ */ new Date()).toISOString();
29660
- const resolvedPath = resolve4(projectRoot);
29796
+ const resolvedPath = resolve5(projectRoot);
29661
29797
  const projectName = _readProjectNameFromInfo(resolvedPath) || basename4(projectRoot) || "unnamed";
29662
29798
  if (existingRows.length > 0) {
29663
29799
  const existingPath = existingRows[0].projectPath;
@@ -34158,7 +34294,7 @@ function storedToResolved(stored) {
34158
34294
  };
34159
34295
  }
34160
34296
  function sleep2(ms) {
34161
- return new Promise((resolve6) => setTimeout(resolve6, ms));
34297
+ return new Promise((resolve7) => setTimeout(resolve7, ms));
34162
34298
  }
34163
34299
  function backoffMs(policy, attempt) {
34164
34300
  const base = policy.baseDelayMs * 2 ** attempt;
@@ -37980,7 +38116,7 @@ function normalizeOllamaToolCall(tc) {
37980
38116
  };
37981
38117
  }
37982
38118
  function sleep3(ms) {
37983
- return new Promise((resolve6) => setTimeout(resolve6, ms));
38119
+ return new Promise((resolve7) => setTimeout(resolve7, ms));
37984
38120
  }
37985
38121
  var OLLAMA_DEFAULT_BASE_URL, MAX_RETRIES, INITIAL_BACKOFF_MS, RETRYABLE_STATUS_CODES, OllamaTransport;
37986
38122
  var init_ollama2 = __esm({
@@ -58494,7 +58630,7 @@ function createProviderToolFactoryWithOutputSchema({
58494
58630
  supportsDeferredResults
58495
58631
  });
58496
58632
  }
58497
- async function resolve5(value) {
58633
+ async function resolve6(value) {
58498
58634
  if (typeof value === "function") {
58499
58635
  value = value();
58500
58636
  }
@@ -62528,14 +62664,14 @@ var init_dist4 = __esm({
62528
62664
  headers
62529
62665
  }) {
62530
62666
  return combineHeaders(
62531
- await resolve5(this.config.headers),
62667
+ await resolve6(this.config.headers),
62532
62668
  headers,
62533
62669
  betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {}
62534
62670
  );
62535
62671
  }
62536
62672
  async getBetasFromHeaders(requestHeaders) {
62537
62673
  var _a17, _b16;
62538
- const configHeaders = await resolve5(this.config.headers);
62674
+ const configHeaders = await resolve6(this.config.headers);
62539
62675
  const configBetaHeader = (_a17 = configHeaders["anthropic-beta"]) != null ? _a17 : "";
62540
62676
  const requestBetaHeader = (_b16 = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b16 : "";
62541
62677
  return new Set(