opencode-swarm 7.164.6 → 7.164.8

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 (96) hide show
  1. package/README.md +1 -1
  2. package/dist/background/pending-delegations.d.ts +3 -0
  3. package/dist/background/pr-subscriptions.d.ts +1 -8
  4. package/dist/cli/{coder-settlement-6qgvzx40.js → coder-settlement-qrtjv4jk.js} +14 -14
  5. package/dist/cli/{config-doctor-d1cbh67h.js → config-doctor-hp9dj0fg.js} +5 -3
  6. package/dist/cli/{core-g0cvvj3b.js → core-bmmrm36k.js} +2 -2
  7. package/dist/cli/{curation-policy-7f8x9yg6.js → curation-policy-de7emfqc.js} +7 -6
  8. package/dist/cli/{curator-drift-0r0scc8r.js → curator-drift-5sykmtf5.js} +8 -6
  9. package/dist/cli/{curator-q3qn89wn.js → curator-k8xdr1mn.js} +40 -38
  10. package/dist/cli/curator-llm-factory-pe61p0r6.js +68 -0
  11. package/dist/cli/{dispatch-q4v8x2pk.js → dispatch-dqybvj8v.js} +10 -6
  12. package/dist/cli/{evidence-summary-service-3meyb8rc.js → evidence-summary-service-qzpkdv7a.js} +20 -17
  13. package/dist/cli/{gate-evidence-mhc0w7vp.js → gate-evidence-jmns4e76.js} +14 -8
  14. package/dist/cli/guardrail-explain-vzwbmvyf.js +69 -0
  15. package/dist/cli/{guardrail-log-0nd1eqvz.js → guardrail-log-kckc7cg4.js} +9 -8
  16. package/dist/cli/{guardrail-reset-mzeyd6jh.js → guardrail-reset-acndbsv9.js} +40 -38
  17. package/dist/cli/hive-promoter-wvt5kk99.js +83 -0
  18. package/dist/cli/{index-x6zyc38w.js → index-0zjwnbze.js} +1 -1
  19. package/dist/cli/{index-x76mprg2.js → index-29w778rw.js} +185 -376
  20. package/dist/cli/{index-fxxja498.js → index-2czt53wz.js} +1 -1
  21. package/dist/cli/{index-pvp5tnn2.js → index-3sv8t7ca.js} +2 -2
  22. package/dist/cli/{index-kvb4dwgf.js → index-4pm3v7yc.js} +12 -6
  23. package/dist/cli/{index-jzvrvdmr.js → index-4v28t7jh.js} +4 -4
  24. package/dist/cli/{index-935ww10s.js → index-52m9kter.js} +1236 -1193
  25. package/dist/cli/index-7qefgq4j.js +71 -0
  26. package/dist/cli/{index-zfwd65c2.js → index-8ntf8jnj.js} +19 -18
  27. package/dist/cli/{index-m1nrd3yd.js → index-8psybzzf.js} +1 -1
  28. package/dist/cli/{index-2c3np82d.js → index-8tqqmsav.js} +1 -1
  29. package/dist/cli/{index-tegp2mny.js → index-93znbdam.js} +9 -5
  30. package/dist/cli/{index-hdapetg1.js → index-9ek9d96g.js} +3 -3
  31. package/dist/cli/{index-p56xc59p.js → index-9ydhzegh.js} +28 -17
  32. package/dist/cli/{index-ew99d4y6.js → index-apdp9bc1.js} +1 -1
  33. package/dist/cli/{index-12xzj0hm.js → index-b10yvv6h.js} +4 -4
  34. package/dist/cli/{index-zjg5ajf5.js → index-bv90qkyw.js} +72 -48
  35. package/dist/cli/{index-zypacgjc.js → index-bz8vsc8r.js} +5 -5
  36. package/dist/cli/{index-4k16cz8r.js → index-bzesypf5.js} +36 -27
  37. package/dist/cli/{index-ay9cr8tr.js → index-chcv8c7n.js} +1 -1
  38. package/dist/cli/index-cw912re7.js +200 -0
  39. package/dist/cli/{index-ty3vtqe2.js → index-espcjyrx.js} +4 -4
  40. package/dist/cli/{index-gwg7a00b.js → index-g2e8b3wm.js} +20 -15
  41. package/dist/cli/{index-rysxqae0.js → index-ghnbpez3.js} +7 -7
  42. package/dist/cli/{index-t1nkr7cz.js → index-gkqrk8dd.js} +2 -2
  43. package/dist/cli/{index-1dz8hv7p.js → index-kvq1e82k.js} +3 -3
  44. package/dist/cli/{index-ze5zyv28.js → index-mr3h3sm5.js} +2 -2
  45. package/dist/cli/{index-zaab1wz9.js → index-n4fzmqz8.js} +3 -1
  46. package/dist/cli/{index-g5714mpv.js → index-px4a2ve0.js} +17 -8
  47. package/dist/cli/index-ry16d01s.js +107 -0
  48. package/dist/cli/{index-j3hsjynw.js → index-s3z936wh.js} +100 -97
  49. package/dist/cli/{index-yh8wxegw.js → index-s6ejwhew.js} +21 -11
  50. package/dist/cli/{index-b0m3efpf.js → index-sxxh4ams.js} +2 -2
  51. package/dist/cli/{index-cyhw0der.js → index-t1qzjhnj.js} +13 -13
  52. package/dist/cli/{index-3f7hqtgg.js → index-w3gtqey0.js} +4 -1
  53. package/dist/cli/{index-9qvmsyab.js → index-wgqeqy68.js} +2 -2
  54. package/dist/cli/{index-y4z0rhsa.js → index-whz6am0v.js} +42 -40
  55. package/dist/cli/{index-g94qqwnz.js → index-wtnx33hz.js} +2 -2
  56. package/dist/cli/{index-j645xpsm.js → index-y6s0gpn3.js} +12 -5
  57. package/dist/cli/{index-6f9yvd67.js → index-ya4ta1pd.js} +2 -2
  58. package/dist/cli/{index-5p1tzpwh.js → index-ypjffdrg.js} +3 -2
  59. package/dist/cli/{index-59hvr3f4.js → index-yscwyq3t.js} +9 -6
  60. package/dist/cli/{index-7v3bb0h3.js → index-yzn1fm9a.js} +1 -1
  61. package/dist/cli/{index-qdbgc16x.js → index-z39vxvdx.js} +20 -12
  62. package/dist/cli/index.js +40 -38
  63. package/dist/cli/{knowledge-escalator-aca0nhqg.js → knowledge-escalator-h9834mrp.js} +15 -14
  64. package/dist/cli/{knowledge-events-n5t313ht.js → knowledge-events-e8hrmjf0.js} +13 -12
  65. package/dist/cli/{knowledge-link-8ea4ksda.js → knowledge-link-hhnmc4g1.js} +6 -5
  66. package/dist/cli/{knowledge-store-j97ejf6a.js → knowledge-store-w3w9gchr.js} +7 -6
  67. package/dist/cli/{knowledge-validator-01evhydg.js → knowledge-validator-exd900vc.js} +9 -8
  68. package/dist/cli/{model-preflight-pmnbfzjv.js → model-preflight-bq035tfh.js} +1 -1
  69. package/dist/cli/{pending-delegations-w73abdk3.js → pending-delegations-p4ak2e86.js} +7 -7
  70. package/dist/cli/{pr-subscriptions-05dzvavk.js → pr-subscriptions-73fs8y3n.js} +7 -6
  71. package/dist/cli/{pr-workflow-gate-t0tnkx5f.js → pr-workflow-gate-pvt2ra6e.js} +40 -38
  72. package/dist/cli/{runner-fh7t0mn9.js → runner-5qqh83e2.js} +6 -6
  73. package/dist/cli/{scan-cursor-63zx2qd8.js → scan-cursor-ysd8b563.js} +8 -7
  74. package/dist/cli/{schema-t1scx08g.js → schema-mbb9g4w4.js} +2 -2
  75. package/dist/cli/{scope-persistence-1a5qmchf.js → scope-persistence-jrbnhxvx.js} +12 -10
  76. package/dist/cli/{skill-generator-7werbwgv.js → skill-generator-b4ng5xky.js} +17 -16
  77. package/dist/cli/{sqlite-loader-8zefc142.js → sqlite-loader-xrnf6bq8.js} +1 -1
  78. package/dist/cli/{telemetry-j14cj552.js → telemetry-85gxedng.js} +1 -1
  79. package/dist/cli/{workspace-snapshot-yq0tc49d.js → workspace-snapshot-eh18vgkn.js} +2 -1
  80. package/dist/cli/{worktree-collision-ownership-wzdzky33.js → worktree-collision-ownership-ns8p2fks.js} +12 -15
  81. package/dist/cli/{worktree-isolation-m02ay3kg.js → worktree-isolation-j6zxhjab.js} +40 -38
  82. package/dist/db/canonical-project.d.ts +10 -3
  83. package/dist/db/driver-parity.d.ts +12 -0
  84. package/dist/db/project-db.d.ts +4 -0
  85. package/dist/evidence/task-gate-repair.d.ts +1 -1
  86. package/dist/gate-evidence.d.ts +19 -1
  87. package/dist/index.js +581 -581
  88. package/dist/plan/ledger.d.ts +2 -0
  89. package/dist/tools/pre-check-batch.d.ts +1 -1
  90. package/dist/utils/canonical-root.d.ts +21 -1
  91. package/dist/utils/filesystem-identity.d.ts +59 -0
  92. package/package.json +2 -1
  93. package/dist/cli/curator-llm-factory-dw7md4nr.js +0 -66
  94. package/dist/cli/guardrail-explain-6cbszhw1.js +0 -67
  95. package/dist/cli/hive-promoter-w7g879cm.js +0 -81
  96. package/dist/cli/index-ddszzne4.js +0 -42
@@ -0,0 +1,71 @@
1
+ // @bun
2
+ // src/utils/canonical-root.ts
3
+ import * as fsSync from "fs";
4
+ import * as path from "path";
5
+ var SESSION_KEY_SEPARATOR = String.fromCharCode(0);
6
+ var canonicalRootMemo = new Map;
7
+ var MAX_CANONICAL_ROOT_CACHE = 128;
8
+ var _internals = {
9
+ realpathSyncNative: fsSync.realpathSync.native,
10
+ realpathSync: fsSync.realpathSync,
11
+ lstatSync: fsSync.lstatSync,
12
+ platform: () => process.platform
13
+ };
14
+ function normalizeIdentityPath(resolved) {
15
+ const normalized = _internals.platform() === "win32" ? path.win32.normalize(resolved) : path.posix.normalize(resolved);
16
+ return _internals.platform() === "win32" ? normalized.toLowerCase() : normalized;
17
+ }
18
+ function lexicalRootAliasKey(directory) {
19
+ return normalizeIdentityPath(path.resolve(directory));
20
+ }
21
+ function resolveCanonicalRootKey(directory) {
22
+ let resolved = path.resolve(directory);
23
+ try {
24
+ resolved = _internals.realpathSyncNative(resolved);
25
+ } catch {
26
+ try {
27
+ resolved = _internals.realpathSync(resolved);
28
+ } catch {}
29
+ }
30
+ return normalizeIdentityPath(resolved);
31
+ }
32
+ function canonicalRootKey(directory) {
33
+ const memoized = canonicalRootMemo.get(directory);
34
+ if (memoized !== undefined) {
35
+ try {
36
+ if (!_internals.lstatSync(directory).isSymbolicLink())
37
+ return memoized;
38
+ } catch {
39
+ return memoized;
40
+ }
41
+ const fresh = resolveCanonicalRootKey(directory);
42
+ if (fresh !== memoized)
43
+ canonicalRootMemo.set(directory, fresh);
44
+ return fresh;
45
+ }
46
+ const key = resolveCanonicalRootKey(directory);
47
+ if (!canonicalRootMemo.has(directory)) {
48
+ while (canonicalRootMemo.size >= MAX_CANONICAL_ROOT_CACHE) {
49
+ const oldest = canonicalRootMemo.keys().next().value;
50
+ if (oldest === undefined)
51
+ break;
52
+ canonicalRootMemo.delete(oldest);
53
+ }
54
+ }
55
+ canonicalRootMemo.set(directory, key);
56
+ return key;
57
+ }
58
+ function canonicalRootKeyFresh(directory) {
59
+ return resolveCanonicalRootKey(directory);
60
+ }
61
+ function sameProjectRoot(a, b) {
62
+ return canonicalRootKeyFresh(a) === canonicalRootKeyFresh(b);
63
+ }
64
+ function compositeSessionKey(directory, sessionId) {
65
+ return `${canonicalRootKey(directory)}${SESSION_KEY_SEPARATOR}${sessionId}`;
66
+ }
67
+ function sessionKeySuffix(sessionId) {
68
+ return `${SESSION_KEY_SEPARATOR}${sessionId}`;
69
+ }
70
+
71
+ export { _internals, lexicalRootAliasKey, canonicalRootKey, canonicalRootKeyFresh, sameProjectRoot, compositeSessionKey, sessionKeySuffix };
@@ -1,19 +1,24 @@
1
1
  // @bun
2
2
  import {
3
3
  validateSwarmPath
4
- } from "./index-2c3np82d.js";
4
+ } from "./index-8tqqmsav.js";
5
5
  import {
6
6
  observeStoreHealth
7
- } from "./index-p56xc59p.js";
7
+ } from "./index-9ydhzegh.js";
8
+ import {
9
+ canonicalRootKey,
10
+ canonicalRootKeyFresh,
11
+ sameProjectRoot
12
+ } from "./index-7qefgq4j.js";
8
13
  import {
9
14
  withEvidenceLock
10
- } from "./index-fxxja498.js";
15
+ } from "./index-2czt53wz.js";
11
16
  import {
12
17
  atomicWriteSwarmFileSync
13
- } from "./index-cyhw0der.js";
18
+ } from "./index-t1qzjhnj.js";
14
19
  import {
15
20
  telemetry
16
- } from "./index-1dz8hv7p.js";
21
+ } from "./index-kvq1e82k.js";
17
22
  import {
18
23
  exports_external,
19
24
  init_zod
@@ -166,13 +171,6 @@ function ensureSwarmDir(directory) {
166
171
  function buildCorrelationId(sessionID, repoFullName, prNumber) {
167
172
  return `${sessionID}::${repoFullName}::${prNumber}`;
168
173
  }
169
- function sameProjectRoot(recorded, current) {
170
- const a = path.resolve(recorded);
171
- const b = path.resolve(current);
172
- if (process.platform === "win32")
173
- return a.toLowerCase() === b.toLowerCase();
174
- return a === b;
175
- }
176
174
  function fileSizeOrNull(filePath) {
177
175
  try {
178
176
  return fs.statSync(filePath).size;
@@ -887,22 +885,24 @@ function emitHealthTelemetry(directory, trigger, checkpoint) {
887
885
  }
888
886
  var legacyOverLimitWarned = new Map;
889
887
  function warnLegacyOverLimit(directory, size) {
890
- if (legacyOverLimitWarned.has(directory))
888
+ const key = canonicalRootKey(directory);
889
+ if (legacyOverLimitWarned.has(key))
891
890
  return;
892
891
  if (legacyOverLimitWarned.size >= 32) {
893
892
  legacyOverLimitWarned.delete(legacyOverLimitWarned.keys().next().value);
894
893
  }
895
- legacyOverLimitWarned.set(directory, true);
894
+ legacyOverLimitWarned.set(key, true);
896
895
  log(`[pr-monitor] legacy subscriptions.jsonl is ${size} bytes (>${PR_SUBSCRIPTION_LIMITS.legacySourceMaxBytes}); refusing to fold it \u2014 archive or split the file so its subscriptions can be re-subscribed, then remove it (reported via /swarm pr status)`);
897
896
  }
898
897
  var migrationCapacityWarned = new Map;
899
898
  function warnMigrationCapacity(directory, records) {
900
- if (migrationCapacityWarned.has(directory))
899
+ const key = canonicalRootKey(directory);
900
+ if (migrationCapacityWarned.has(key))
901
901
  return;
902
902
  if (migrationCapacityWarned.size >= 32) {
903
903
  migrationCapacityWarned.delete(migrationCapacityWarned.keys().next().value);
904
904
  }
905
- migrationCapacityWarned.set(directory, true);
905
+ migrationCapacityWarned.set(key, true);
906
906
  log(`[pr-monitor] legacy subscriptions.jsonl folds to ${records} records (>checkpoint capacity ${PR_SUBSCRIPTION_LIMITS.maxCheckpointRecords}); migration refused \u2014 archive or split the file so its subscriptions can be re-subscribed, then remove it`);
907
907
  }
908
908
  function overlayLegacy(directory, checkpoint) {
@@ -1044,12 +1044,13 @@ async function loadViewForRead(directory) {
1044
1044
  }
1045
1045
  var bootstrapAttempted = new Map;
1046
1046
  async function bootstrapCheckpointFromLegacy(directory) {
1047
- if (bootstrapAttempted.has(directory))
1047
+ const key = canonicalRootKeyFresh(directory);
1048
+ if (bootstrapAttempted.has(key))
1048
1049
  return;
1049
1050
  if (bootstrapAttempted.size >= 32) {
1050
1051
  bootstrapAttempted.delete(bootstrapAttempted.keys().next().value);
1051
1052
  }
1052
- bootstrapAttempted.set(directory, true);
1053
+ bootstrapAttempted.set(key, true);
1053
1054
  try {
1054
1055
  await withEvidenceLock(directory, PR_SUBSCRIPTIONS_FILE, STORE_LOCK_AGENT, STORE_LOCK_TASK, async () => {
1055
1056
  if (readCheckpoint(directory).kind !== "absent")
@@ -462,7 +462,7 @@ var init_tool_metadata = __esm(() => {
462
462
  agents: ["architect"]
463
463
  },
464
464
  repair_gate_evidence: {
465
- description: "quarantine corrupt exact-task gate evidence and install a fresh blocked generation that requires every gate to rerun",
465
+ description: "quarantine recoverable exact-task gate evidence, rebuild from durable requirements, recover receipt-backed legacy marker wedges or the exact sentinel-only historical reset, and refuse every other receipt-less reconstruction",
466
466
  agents: ["architect"]
467
467
  },
468
468
  repair_knowledge_receipt_ledger: {
@@ -7,7 +7,7 @@ import {
7
7
  } from "./index-r3mvsbtq.js";
8
8
  import {
9
9
  readCachedTextFile
10
- } from "./index-cyhw0der.js";
10
+ } from "./index-t1qzjhnj.js";
11
11
  import {
12
12
  warn
13
13
  } from "./index-zgwm4ryv.js";
@@ -1,7 +1,10 @@
1
1
  // @bun
2
2
  import {
3
3
  atomicWriteFile
4
- } from "./index-ze5zyv28.js";
4
+ } from "./index-mr3h3sm5.js";
5
+ import {
6
+ canonicalRootKeyFresh
7
+ } from "./index-7qefgq4j.js";
5
8
  import {
6
9
  init_logger,
7
10
  warn
@@ -189,8 +192,9 @@ function pointerStatFingerprint(directory) {
189
192
  }
190
193
  function resolveKnowledgeStoreDir(directory) {
191
194
  const localSwarm = path.join(directory, ".swarm");
195
+ const cacheKey = canonicalRootKeyFresh(directory);
192
196
  const now = Date.now();
193
- const cached = _resolutionCache.get(directory);
197
+ const cached = _resolutionCache.get(cacheKey);
194
198
  const currentStat = pointerStatFingerprint(directory);
195
199
  if (cached && now < cached.expires && cached.pointerStat === currentStat) {
196
200
  return cached.linkDir ?? localSwarm;
@@ -211,12 +215,12 @@ function resolveKnowledgeStoreDir(directory) {
211
215
  } catch {
212
216
  linkDir = null;
213
217
  }
214
- if (!_resolutionCache.has(directory) && _resolutionCache.size >= MAX_CACHE_ENTRIES) {
218
+ if (!_resolutionCache.has(cacheKey) && _resolutionCache.size >= MAX_CACHE_ENTRIES) {
215
219
  const oldest = _resolutionCache.keys().next().value;
216
220
  if (oldest !== undefined)
217
221
  _resolutionCache.delete(oldest);
218
222
  }
219
- _resolutionCache.set(directory, {
223
+ _resolutionCache.set(cacheKey, {
220
224
  linkDir,
221
225
  expires: now + CACHE_TTL_MS,
222
226
  pointerStat: currentStat
@@ -228,7 +232,7 @@ function invalidateKnowledgeStoreDirCache(directory) {
228
232
  _resolutionCache.clear();
229
233
  return;
230
234
  }
231
- _resolutionCache.delete(directory);
235
+ _resolutionCache.delete(canonicalRootKeyFresh(directory));
232
236
  }
233
237
  function isLinked(directory) {
234
238
  return readLinkPointer(directory) !== null;
@@ -2,14 +2,14 @@
2
2
  import {
3
3
  init_loader,
4
4
  loadPluginConfigWithMeta
5
- } from "./index-ew99d4y6.js";
5
+ } from "./index-apdp9bc1.js";
6
6
  import {
7
7
  init_schema
8
- } from "./index-5p1tzpwh.js";
8
+ } from "./index-ypjffdrg.js";
9
9
  import {
10
10
  DEFAULT_WORKTREE_ISOLATION_CONFIG,
11
11
  init_constants
12
- } from "./index-m1nrd3yd.js";
12
+ } from "./index-8psybzzf.js";
13
13
 
14
14
  // src/config/index.ts
15
15
  init_constants();
@@ -1,12 +1,15 @@
1
1
  // @bun
2
+ import {
3
+ canonicalRootKeyFresh
4
+ } from "./index-7qefgq4j.js";
2
5
  import {
3
6
  atomicWriteSwarmFile
4
- } from "./index-cyhw0der.js";
7
+ } from "./index-t1qzjhnj.js";
5
8
  import {
6
9
  pseudonymousRef,
7
10
  resolveLineageSalt,
8
11
  telemetry
9
- } from "./index-1dz8hv7p.js";
12
+ } from "./index-kvq1e82k.js";
10
13
 
11
14
  // src/health/learning-health.ts
12
15
  import { promises as fs } from "fs";
@@ -178,15 +181,16 @@ var lastPersistAtByDirectory = new Map;
178
181
  var recentPersistDirectories = [];
179
182
  var MAX_TRACKED_DIRECTORIES = 16;
180
183
  function rememberPersistDirectory(directory) {
181
- if (recentPersistDirectories.includes(directory)) {
182
- const idx = recentPersistDirectories.indexOf(directory);
184
+ const key = canonicalRootKeyFresh(directory);
185
+ const idx = recentPersistDirectories.findIndex((entry) => entry.key === key);
186
+ if (idx >= 0) {
183
187
  recentPersistDirectories.splice(idx, 1);
184
188
  }
185
- recentPersistDirectories.push(directory);
189
+ recentPersistDirectories.push({ key, directory });
186
190
  while (recentPersistDirectories.length > MAX_TRACKED_DIRECTORIES) {
187
191
  const evicted = recentPersistDirectories.shift();
188
192
  if (evicted !== undefined)
189
- lastPersistAtByDirectory.delete(evicted);
193
+ lastPersistAtByDirectory.delete(evicted.key);
190
194
  }
191
195
  }
192
196
  var _internals = {
@@ -205,11 +209,12 @@ var _internals = {
205
209
  };
206
210
  var projectRefCache = new Map;
207
211
  function projectRef(directory) {
208
- const cached = projectRefCache.get(directory);
212
+ const key = canonicalRootKeyFresh(directory);
213
+ const cached = projectRefCache.get(key);
209
214
  if (cached !== undefined)
210
215
  return cached;
211
- const ref = pseudonymousRef(directory, resolveLineageSalt());
212
- if (!projectRefCache.has(directory)) {
216
+ const ref = pseudonymousRef(key, resolveLineageSalt());
217
+ if (!projectRefCache.has(key)) {
213
218
  while (projectRefCache.size >= MAX_TRACKED_DIRECTORIES) {
214
219
  const oldest = projectRefCache.keys().next().value;
215
220
  if (oldest === undefined)
@@ -217,9 +222,12 @@ function projectRef(directory) {
217
222
  projectRefCache.delete(oldest);
218
223
  }
219
224
  }
220
- projectRefCache.set(directory, ref);
225
+ projectRefCache.set(key, ref);
221
226
  return ref;
222
227
  }
228
+ function legacyProjectRef(directory) {
229
+ return pseudonymousRef(directory, resolveLineageSalt());
230
+ }
223
231
  function getScopeMap(alarm) {
224
232
  let map = alarmScopes.get(alarm);
225
233
  if (!map) {
@@ -361,13 +369,14 @@ function applyAlarmState(alarm, scopeClass, scopeKey, desired, severity, detail,
361
369
  }
362
370
  }
363
371
  function schedulePersist(directory, now, force) {
364
- const target = directory ?? recentPersistDirectories.at(-1);
372
+ const target = directory ?? recentPersistDirectories.at(-1)?.directory;
365
373
  if (!target)
366
374
  return;
367
- const last = lastPersistAtByDirectory.get(target) ?? 0;
375
+ const targetKey = canonicalRootKeyFresh(target);
376
+ const last = lastPersistAtByDirectory.get(targetKey) ?? 0;
368
377
  if (!force && now - last < PERSIST_DEBOUNCE_MS)
369
378
  return;
370
- lastPersistAtByDirectory.set(target, now);
379
+ lastPersistAtByDirectory.set(targetKey, now);
371
380
  persistLearningHealth(target).catch(() => {
372
381
  return;
373
382
  });
@@ -462,13 +471,14 @@ function isAdoptableScopeKey(key) {
462
471
  if (typeof key !== "string" || key.length === 0 || key.length > 200) {
463
472
  return false;
464
473
  }
465
- return /^[0-9a-zA-Z:_.-/]+$/.test(key);
474
+ return /^[-0-9a-zA-Z:_.\u002f]+$/.test(key);
466
475
  }
467
476
  function isFiniteCounter(value) {
468
477
  return typeof value === "number" && Number.isFinite(value) && value >= 0;
469
478
  }
470
479
  function livenessMap(directory) {
471
- let map = livenessGaps.get(directory);
480
+ const key = canonicalRootKeyFresh(directory);
481
+ let map = livenessGaps.get(key);
472
482
  if (!map) {
473
483
  if (livenessGaps.size >= MAX_TRACKED_DIRECTORIES) {
474
484
  let victim;
@@ -483,7 +493,7 @@ function livenessMap(directory) {
483
493
  livenessGaps.delete(victim);
484
494
  }
485
495
  map = new Map;
486
- livenessGaps.set(directory, map);
496
+ livenessGaps.set(key, map);
487
497
  }
488
498
  return map;
489
499
  }
@@ -742,12 +752,13 @@ async function readLearningHealth(directory) {
742
752
  const now = _internals.now();
743
753
  evaluateLiveness(directory, now);
744
754
  const scopeOwner = projectRef(directory);
755
+ const legacyScopeOwner = legacyProjectRef(directory);
745
756
  const active = [];
746
757
  for (const [alarm, scopes] of alarmScopes) {
747
758
  for (const [key, scope] of scopes) {
748
759
  if (scope.status !== "active")
749
760
  continue;
750
- const owned = key.startsWith(`${scopeOwner}/`) || key.startsWith("u/") || key.startsWith("store/");
761
+ const owned = key.startsWith(`${scopeOwner}/`) || key.startsWith(`${legacyScopeOwner}/`) || key.startsWith("u/") || key.startsWith("store/");
751
762
  if (!owned)
752
763
  continue;
753
764
  active.push({
@@ -6,7 +6,7 @@ import {
6
6
  PluginConfigSchema,
7
7
  init_schema,
8
8
  resolveExternalSkillsConfig
9
- } from "./index-5p1tzpwh.js";
9
+ } from "./index-ypjffdrg.js";
10
10
  import {
11
11
  GIT_BINARY_ENV_VAR,
12
12
  init_git_executable
@@ -11,16 +11,16 @@ import {
11
11
  import {
12
12
  init_schema,
13
13
  stripKnownSwarmPrefix
14
- } from "./index-5p1tzpwh.js";
14
+ } from "./index-ypjffdrg.js";
15
15
  import {
16
16
  observeStoreHealth
17
- } from "./index-p56xc59p.js";
17
+ } from "./index-9ydhzegh.js";
18
18
  import {
19
19
  init_constants
20
- } from "./index-m1nrd3yd.js";
20
+ } from "./index-8psybzzf.js";
21
21
  import {
22
22
  telemetry
23
- } from "./index-1dz8hv7p.js";
23
+ } from "./index-kvq1e82k.js";
24
24
  import {
25
25
  init_logger,
26
26
  warn
@@ -1,7 +1,10 @@
1
1
  // @bun
2
2
  import {
3
3
  loadDatabaseCtor
4
- } from "./index-zaab1wz9.js";
4
+ } from "./index-n4fzmqz8.js";
5
+ import {
6
+ canonicalExistingFilesystemPath
7
+ } from "./index-ry16d01s.js";
5
8
  import {
6
9
  validateSpecContent
7
10
  } from "./index-n832052r.js";
@@ -9,9 +12,13 @@ import {
9
12
  advisoryWarn,
10
13
  init_warning_buffer
11
14
  } from "./index-4rhhvd1a.js";
15
+ import {
16
+ canonicalRootKeyFresh,
17
+ lexicalRootAliasKey
18
+ } from "./index-7qefgq4j.js";
12
19
  import {
13
20
  atomicWriteSwarmFileSync
14
- } from "./index-cyhw0der.js";
21
+ } from "./index-t1qzjhnj.js";
15
22
 
16
23
  // src/sdd/effective-spec.ts
17
24
  import { createHash } from "crypto";
@@ -727,26 +734,9 @@ function withDurabilityClass(db, cls, fn) {
727
734
  }
728
735
  }
729
736
 
730
- // src/db/canonical-project.ts
731
- import { realpathSync } from "fs";
732
- import { resolve as resolve2 } from "path";
733
- var _internals = {
734
- realpathSync
735
- };
736
- function canonicalProjectKey(directory) {
737
- const lexical = resolve2(directory);
738
- let canonical;
739
- try {
740
- canonical = _internals.realpathSync(lexical);
741
- } catch {
742
- canonical = lexical;
743
- }
744
- return process.platform === "win32" ? canonical.toLowerCase() : canonical;
745
- }
746
-
747
737
  // src/db/project-db.ts
748
738
  import { existsSync as existsSync2, mkdirSync as mkdirSync2, unlinkSync } from "fs";
749
- import { join as join2, resolve as resolve3 } from "path";
739
+ import { join as join2 } from "path";
750
740
 
751
741
  // src/db/db-errors.ts
752
742
  class ProjectDbError extends Error {
@@ -964,6 +954,38 @@ var MIGRATIONS = [
964
954
  }
965
955
  ];
966
956
  var _projectDbs = new Map;
957
+ var _projectDbAliases = new Map;
958
+ var MAX_ALIASES_PER_PROJECT_DB = 128;
959
+ function lexicalAliasKey(directory) {
960
+ return lexicalRootAliasKey(directory);
961
+ }
962
+ function unbindAlias(alias, physicalKey) {
963
+ if (_projectDbAliases.get(alias) === physicalKey) {
964
+ _projectDbAliases.delete(alias);
965
+ }
966
+ _projectDbs.get(physicalKey)?.aliases.delete(alias);
967
+ }
968
+ function bindAlias(record, physicalKey, alias) {
969
+ const previousKey = _projectDbAliases.get(alias);
970
+ if (previousKey !== undefined && previousKey !== physicalKey) {
971
+ unbindAlias(alias, previousKey);
972
+ }
973
+ record.aliases.delete(alias);
974
+ record.aliases.add(alias);
975
+ _projectDbAliases.set(alias, physicalKey);
976
+ while (record.aliases.size > MAX_ALIASES_PER_PROJECT_DB) {
977
+ const evicted = [...record.aliases].find((candidate) => candidate !== record.primaryAlias && candidate !== alias);
978
+ if (evicted === undefined)
979
+ break;
980
+ unbindAlias(evicted, physicalKey);
981
+ }
982
+ }
983
+ function closeRecord(physicalKey, record) {
984
+ record.db.close();
985
+ _projectDbs.delete(physicalKey);
986
+ for (const alias of [...record.aliases])
987
+ unbindAlias(alias, physicalKey);
988
+ }
967
989
  function recordMigrationFailure(db, migration, err, markerDir) {
968
990
  const errorText = String(err instanceof Error ? err.message : err).slice(0, MIGRATION_FAILURE_ERROR_MAX_CHARS);
969
991
  try {
@@ -1032,28 +1054,20 @@ function runProjectMigrations(db, markerDir) {
1032
1054
  removeMigrationFailureMarker(markerDir);
1033
1055
  }
1034
1056
  function projectDbPath(directory) {
1035
- return join2(resolve3(directory), ".swarm", "swarm.db");
1057
+ return join2(canonicalRootKeyFresh(directory), ".swarm", "swarm.db");
1036
1058
  }
1037
1059
  function projectDbExists(directory) {
1038
- return existsSync2(join2(canonicalProjectKey(directory), ".swarm", "swarm.db"));
1039
- }
1040
- function checkpointWalBestEffort(db) {
1041
- try {
1042
- const row = db.query("PRAGMA wal_checkpoint(TRUNCATE)").get();
1043
- if (row && row.busy === 1) {
1044
- db.run("PRAGMA wal_checkpoint(PASSIVE);");
1045
- }
1046
- } catch {
1047
- try {
1048
- db.run("PRAGMA wal_checkpoint(PASSIVE);");
1049
- } catch {}
1050
- }
1060
+ return existsSync2(projectDbPath(directory));
1051
1061
  }
1052
1062
  function getProjectDb(directory) {
1053
- const key = canonicalProjectKey(directory);
1063
+ mkdirSync2(directory, { recursive: true });
1064
+ const key = canonicalRootKeyFresh(directory);
1065
+ const alias = lexicalAliasKey(directory);
1054
1066
  const existing = _projectDbs.get(key);
1055
- if (existing)
1056
- return existing;
1067
+ if (existing) {
1068
+ bindAlias(existing, key, alias);
1069
+ return existing.db;
1070
+ }
1057
1071
  const swarmDir = join2(key, ".swarm");
1058
1072
  try {
1059
1073
  mkdirSync2(swarmDir, { recursive: true });
@@ -1084,20 +1098,30 @@ function getProjectDb(directory) {
1084
1098
  throw err;
1085
1099
  throw new ProjectDbError("open_failed", `Failed to open .swarm/swarm.db for project ${key}: ${err instanceof Error ? err.message : String(err)}`);
1086
1100
  }
1087
- _projectDbs.set(key, db);
1101
+ const record = {
1102
+ db,
1103
+ primaryAlias: alias,
1104
+ aliases: new Set
1105
+ };
1106
+ _projectDbs.set(key, record);
1107
+ bindAlias(record, key, alias);
1088
1108
  return db;
1089
1109
  }
1090
1110
  function closeProjectDb(directory) {
1091
- const key = canonicalProjectKey(directory);
1092
- const db = _projectDbs.get(key);
1093
- if (db) {
1094
- checkpointWalBestEffort(db);
1095
- try {
1096
- db.close();
1097
- } finally {
1098
- _projectDbs.delete(key);
1099
- }
1111
+ const alias = lexicalAliasKey(directory);
1112
+ const currentPath = canonicalExistingFilesystemPath(directory);
1113
+ if (currentPath !== null) {
1114
+ const currentKey = canonicalRootKeyFresh(directory);
1115
+ const currentRecord = _projectDbs.get(currentKey);
1116
+ if (currentRecord)
1117
+ closeRecord(currentKey, currentRecord);
1118
+ return;
1119
+ }
1120
+ const previousKey = _projectDbAliases.get(alias);
1121
+ const previousRecord = previousKey === undefined ? undefined : _projectDbs.get(previousKey);
1122
+ if (previousKey !== undefined && previousRecord) {
1123
+ closeRecord(previousKey, previousRecord);
1100
1124
  }
1101
1125
  }
1102
1126
 
1103
- export { DURABILITY_CLASSES, batchDurabilityClass, applySynchronousForClass, withDurabilityClass, canonicalProjectKey, DbWriteError, classifyDbWriteError, projectDbPath, projectDbExists, getProjectDb, closeProjectDb, detectSpeckit, resolveSpeckitProjection, loadSddStatusSync, buildOpenSpecProjectionSync, readEffectiveSpecSync, writeProjectedSpecSync, validateSpeckit };
1127
+ export { DURABILITY_CLASSES, batchDurabilityClass, applySynchronousForClass, withDurabilityClass, DbWriteError, classifyDbWriteError, projectDbPath, projectDbExists, getProjectDb, closeProjectDb, detectSpeckit, resolveSpeckitProjection, loadSddStatusSync, buildOpenSpecProjectionSync, readEffectiveSpecSync, writeProjectedSpecSync, validateSpeckit };
@@ -6,12 +6,12 @@ import {
6
6
  resolveSwarmKnowledgePath,
7
7
  transactKnowledge,
8
8
  wordBigrams
9
- } from "./index-rysxqae0.js";
9
+ } from "./index-ghnbpez3.js";
10
10
  import {
11
11
  queryHistoricalOutcomes,
12
12
  readKnowledgeEvents,
13
13
  recordKnowledgeEvent
14
- } from "./index-gwg7a00b.js";
14
+ } from "./index-g2e8b3wm.js";
15
15
  import {
16
16
  init_knowledge_types,
17
17
  isActiveStatus
@@ -224,11 +224,11 @@ async function maybeQuarantineOnContradiction(directory, entryId, threshold, win
224
224
  alreadyInactive: true
225
225
  };
226
226
  }
227
- const { quarantineEntry } = await import("./knowledge-validator-01evhydg.js");
227
+ const { quarantineEntry } = await import("./knowledge-validator-exd900vc.js");
228
228
  let policyConfig;
229
229
  try {
230
- const { KnowledgeConfigSchema } = await import("./schema-t1scx08g.js");
231
- const { loadPluginConfigWithMeta } = await import("./index-ty3vtqe2.js");
230
+ const { KnowledgeConfigSchema } = await import("./schema-mbb9g4w4.js");
231
+ const { loadPluginConfigWithMeta } = await import("./index-espcjyrx.js");
232
232
  const { config: loadedConfig } = loadPluginConfigWithMeta(directory);
233
233
  policyConfig = KnowledgeConfigSchema.parse(loadedConfig.knowledge ?? {});
234
234
  } catch {