opencode-swarm 7.166.1 → 7.166.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 (115) hide show
  1. package/binaries/win32-arm64/swarm-sandbox-runner.exe +0 -0
  2. package/binaries/win32-x64/swarm-sandbox-runner.exe +0 -0
  3. package/dist/background/candidate-contract.d.ts +14 -0
  4. package/dist/background/pr-subscriptions.d.ts +33 -1
  5. package/dist/background/workspace-snapshot.d.ts +41 -0
  6. package/dist/cli/{coder-settlement-x0h3h6vd.js → coder-settlement-nx8ff9k1.js} +13 -13
  7. package/dist/cli/{config-doctor-pjcjeh8f.js → config-doctor-n9cjh11e.js} +4 -4
  8. package/dist/cli/{core-v11pd1yk.js → core-cbwrwhcz.js} +2 -2
  9. package/dist/cli/{curation-policy-jtzwz6bc.js → curation-policy-bvxf5pxv.js} +11 -6
  10. package/dist/cli/{curator-ssvd7evd.js → curator-c7amtass.js} +40 -39
  11. package/dist/cli/{curator-drift-jpdfwae9.js → curator-drift-20m2ab5w.js} +6 -6
  12. package/dist/cli/curator-llm-factory-2gv6kt1v.js +71 -0
  13. package/dist/cli/{dispatch-591v13pp.js → dispatch-tmb929w8.js} +2 -2
  14. package/dist/cli/{evidence-summary-service-mw6tnsp9.js → evidence-summary-service-5th3zm9c.js} +17 -17
  15. package/dist/cli/{gate-evidence-jymaxb82.js → gate-evidence-py8v0w28.js} +9 -8
  16. package/dist/cli/guardrail-explain-qzhjhtyk.js +72 -0
  17. package/dist/cli/{guardrail-log-kzq2sktb.js → guardrail-log-rtdpk545.js} +9 -9
  18. package/dist/cli/{guardrail-reset-ea1g3g7d.js → guardrail-reset-s27fehv6.js} +40 -39
  19. package/dist/cli/{hive-promoter-ghjbgsms.js → hive-promoter-56mfysq6.js} +40 -39
  20. package/dist/cli/{index-52xdezsh.js → index-0jpv5z94.js} +5 -5
  21. package/dist/cli/{index-8hqkrd2j.js → index-1aex5zd9.js} +1 -1
  22. package/dist/cli/{index-6chhqq2n.js → index-251vrmge.js} +94 -3
  23. package/dist/cli/{index-w11whwn3.js → index-2c7eabkr.js} +9 -9
  24. package/dist/cli/{index-edm41q4j.js → index-2w0beg3s.js} +2 -2
  25. package/dist/cli/{index-nph5g4em.js → index-3a2xznmd.js} +2 -2
  26. package/dist/cli/{index-2y4kargd.js → index-3f1tr4ha.js} +4 -4
  27. package/dist/cli/{index-xezfx7ge.js → index-3nm1b3t2.js} +47 -13
  28. package/dist/cli/{index-gr8ppbq3.js → index-4c50tm9j.js} +3 -3
  29. package/dist/cli/{index-wf12wckd.js → index-4mgggb8x.js} +8 -3
  30. package/dist/cli/{index-17yszqs5.js → index-5bd84nxc.js} +1 -1
  31. package/dist/cli/{index-jx9f4ke1.js → index-6d4dc99f.js} +1 -1
  32. package/dist/cli/{index-79sr3fd1.js → index-75f9jj3h.js} +2 -2
  33. package/dist/cli/{index-ybcxvv17.js → index-87wqes24.js} +2 -2
  34. package/dist/cli/{index-bkd3450m.js → index-8cky7ksv.js} +36 -10
  35. package/dist/cli/{index-1zqf2pny.js → index-9wv6a3jx.js} +2 -2
  36. package/dist/cli/{index-fc1dqzjp.js → index-b7ra4hwj.js} +1 -1
  37. package/dist/cli/{index-6rff2h8x.js → index-bwvbj3fp.js} +4 -4
  38. package/dist/cli/{index-j29nkq5d.js → index-ch293kd3.js} +4 -4
  39. package/dist/cli/{index-gerkwyrr.js → index-d5gvr6z4.js} +1 -1
  40. package/dist/cli/{index-399nq780.js → index-dvhecfa9.js} +3839 -3182
  41. package/dist/cli/{index-hwj25q9r.js → index-f6zgz02s.js} +70 -53
  42. package/dist/cli/{index-3tyym20r.js → index-gbv76wf7.js} +2 -2
  43. package/dist/cli/{index-8fr2wn18.js → index-gk1w1h9k.js} +5 -1
  44. package/dist/cli/{index-13egyjgv.js → index-h92cqbqa.js} +5 -5
  45. package/dist/cli/{index-k5w284js.js → index-hfrb77tj.js} +17 -17
  46. package/dist/cli/{index-gy0nyfbw.js → index-m21x1bkx.js} +78 -25
  47. package/dist/cli/{index-hvk3zs62.js → index-m3tx1q9v.js} +1 -1
  48. package/dist/cli/{index-xwkn5hse.js → index-ms16gaa4.js} +7 -7
  49. package/dist/cli/{index-066xxa4q.js → index-qa7t42e7.js} +96 -31
  50. package/dist/cli/{index-2v17wb75.js → index-qd619x3r.js} +2 -2
  51. package/dist/cli/{index-axf65x87.js → index-qd726agw.js} +5 -5
  52. package/dist/cli/{index-c20gf089.js → index-qww0h314.js} +11 -6
  53. package/dist/cli/{index-aftapk6j.js → index-rk10x4zr.js} +3 -3
  54. package/dist/cli/{index-bfr392e7.js → index-sahf5yz3.js} +13 -6
  55. package/dist/cli/{index-a7rw4g4s.js → index-t8tw1bhs.js} +3 -3
  56. package/dist/cli/{index-0g5v4s0x.js → index-t9kjxzdr.js} +14 -14
  57. package/dist/cli/{index-zha9bdj9.js → index-tzq6t9wc.js} +11 -11
  58. package/dist/cli/index-vzm6zre7.js +167 -0
  59. package/dist/cli/{index-crjx4sx0.js → index-w50dk71y.js} +42 -41
  60. package/dist/cli/{index-yt25kpvz.js → index-xn16akay.js} +4 -4
  61. package/dist/cli/index.js +40 -39
  62. package/dist/cli/{knowledge-escalator-3pjed4tq.js → knowledge-escalator-stnveccq.js} +15 -14
  63. package/dist/cli/{knowledge-events-a5dwkg30.js → knowledge-events-ph6txm8h.js} +12 -12
  64. package/dist/cli/{knowledge-link-1zykfk1p.js → knowledge-link-w1fwqts4.js} +6 -4
  65. package/dist/cli/{knowledge-store-h85efsak.js → knowledge-store-tgyhr9nf.js} +10 -5
  66. package/dist/cli/{knowledge-validator-76qrf1ev.js → knowledge-validator-2g547bcn.js} +10 -7
  67. package/dist/cli/{pending-delegations-zgwfqfac.js → pending-delegations-873dtyw6.js} +14 -13
  68. package/dist/cli/{pr-subscriptions-fzy3ks1k.js → pr-subscriptions-xmxdrj1z.js} +20 -13
  69. package/dist/cli/{pr-workflow-gate-1gtsn7f0.js → pr-workflow-gate-h7644byf.js} +40 -39
  70. package/dist/cli/{runner-j3acybhs.js → runner-nmrjv7te.js} +8 -5
  71. package/dist/cli/{scan-cursor-ahwkxa8j.js → scan-cursor-tx72gxp0.js} +9 -6
  72. package/dist/cli/{schema-27sedbfk.js → schema-cpc92vq0.js} +4 -2
  73. package/dist/cli/{scope-persistence-q792yfxh.js → scope-persistence-xy3xs55f.js} +17 -15
  74. package/dist/cli/{skill-generator-g8wbjw6v.js → skill-generator-4f1v5zwx.js} +17 -16
  75. package/dist/cli/{snapshot-coordination-init-y6spakwm.js → snapshot-coordination-init-w2nw33pn.js} +40 -39
  76. package/dist/cli/{telemetry-9h1z2w9d.js → telemetry-ce0tx41h.js} +5 -1
  77. package/dist/cli/{workspace-snapshot-6z9rk7xw.js → workspace-snapshot-0kxj2grt.js} +11 -1
  78. package/dist/cli/{worktree-collision-ownership-pmpnftkd.js → worktree-collision-ownership-1g1qz8wc.js} +15 -14
  79. package/dist/cli/{worktree-isolation-4053n0px.js → worktree-isolation-jwxtrh3z.js} +40 -39
  80. package/dist/commands/close.d.ts +82 -0
  81. package/dist/config/schema.d.ts +9 -0
  82. package/dist/context-map/capsule-persistence.d.ts +13 -8
  83. package/dist/evidence/phase-participation.d.ts +1 -1
  84. package/dist/hooks/delegate-ack-collector.d.ts +7 -0
  85. package/dist/hooks/guardrails/execution-stall.d.ts +10 -5
  86. package/dist/hooks/hive-promoter.d.ts +28 -5
  87. package/dist/hooks/knowledge-store.d.ts +7 -0
  88. package/dist/hooks/repo-graph-builder.d.ts +14 -0
  89. package/dist/hooks/review-receipt.d.ts +29 -1
  90. package/dist/hooks/system-enhancer.d.ts +21 -0
  91. package/dist/index.js +578 -573
  92. package/dist/knowledge/curation-policy.d.ts +7 -0
  93. package/dist/memory/consolidation-log.d.ts +9 -0
  94. package/dist/memory/injector.d.ts +7 -0
  95. package/dist/memory/run-log.d.ts +8 -0
  96. package/dist/observability/catalog.d.ts +1 -1
  97. package/dist/retention/caps.d.ts +33 -0
  98. package/dist/retention/dir-prune.d.ts +72 -0
  99. package/dist/retention/jsonl-cap.d.ts +84 -0
  100. package/dist/retention/sweep.d.ts +67 -0
  101. package/dist/services/compaction-service.d.ts +14 -0
  102. package/dist/services/skill-changelog.d.ts +20 -0
  103. package/dist/session/snapshot-writer.d.ts +42 -0
  104. package/dist/summaries/manager.d.ts +41 -4
  105. package/dist/telemetry.d.ts +31 -1
  106. package/dist/test-impact/history-store.d.ts +16 -0
  107. package/dist/turbo/epic/calibration.d.ts +16 -1
  108. package/dist/turbo/epic/divergence-recorder.d.ts +11 -0
  109. package/dist/utils/atomic-write.d.ts +32 -0
  110. package/dist/utils/swarm-artifact-cache.d.ts +6 -0
  111. package/opencode-swarm.schema.json +15 -0
  112. package/package.json +1 -1
  113. package/dist/cli/curator-llm-factory-da5q3gg6.js +0 -70
  114. package/dist/cli/guardrail-explain-eva1yrtf.js +0 -71
  115. package/dist/cli/{index-2sqgbmtq.js → index-d5qf7hvh.js} +3 -3
@@ -6,6 +6,21 @@ import * as path from "path";
6
6
  var MAX_CACHE_ENTRIES = 128;
7
7
  var textCache = new Map;
8
8
  var parsedCache = new Map;
9
+ var MAX_KNOWN_TO_EXIST_PATHS = 512;
10
+ var knownToExist = new Set;
11
+ function noteKnownToExist(resolvedPath) {
12
+ if (knownToExist.has(resolvedPath))
13
+ return;
14
+ knownToExist.add(resolvedPath);
15
+ if (knownToExist.size > MAX_KNOWN_TO_EXIST_PATHS) {
16
+ const oldest = knownToExist.values().next().value;
17
+ if (oldest !== undefined)
18
+ knownToExist.delete(oldest);
19
+ }
20
+ }
21
+ function wasObservedToExist(filePath) {
22
+ return knownToExist.has(path.resolve(filePath));
23
+ }
9
24
  var stats = {
10
25
  textReadCount: 0,
11
26
  textCacheHitCount: 0,
@@ -76,6 +91,7 @@ async function readCachedTextFile(filePath, directRead) {
76
91
  stats.textReadCount++;
77
92
  return directRead();
78
93
  }
94
+ noteKnownToExist(cacheKey);
79
95
  const cached = textCache.get(cacheKey);
80
96
  if (cached && sameStamp(cached, stamp)) {
81
97
  stats.textCacheHitCount++;
@@ -218,15 +234,15 @@ var SWARM_TEMP_GRAMMARS = [
218
234
  "src/plan/manager.ts:1832",
219
235
  "src/review/evidence.ts:175",
220
236
  "src/turbo/lean/evidence.ts:182",
221
- "src/summaries/manager.ts:122",
237
+ "src/summaries/manager.ts:123",
222
238
  "src/evidence/manager.ts:288",
223
239
  "src/evidence/manager.ts:456",
224
240
  "src/tools/sast-baseline.ts:199",
225
241
  "src/tools/repo-graph/storage.ts:524",
226
242
  "src/memory/reflection-service.ts (pre-#2035; migrated-to=src/memory/reflection-service.ts:atomicWrite)",
227
- "src/hooks/review-receipt.ts:608",
228
- "src/hooks/review-receipt.ts:674",
229
- "src/hooks/review-receipt.ts:812",
243
+ "src/hooks/review-receipt.ts:609",
244
+ "src/hooks/review-receipt.ts:675",
245
+ "src/hooks/review-receipt.ts:894",
230
246
  "src/knowledge/identity.ts:209",
231
247
  "src/evidence/phase-participation.ts (pre-#2035; migrated-to=src/evidence/phase-participation.ts:atomicWriteBytes)",
232
248
  "src/turbo/lean/integration.ts:428",
@@ -235,7 +251,7 @@ var SWARM_TEMP_GRAMMARS = [
235
251
  "src/services/synonym-map.ts:389",
236
252
  "src/services/skill-optimizer/store.ts:340",
237
253
  "src/services/skill-optimizer/store.ts:503",
238
- "src/turbo/epic/calibration.ts:202",
254
+ "src/turbo/epic/calibration.ts:234",
239
255
  "src/commands/archive-sqlite.ts:318",
240
256
  "src/memory/jsonl-migration.ts:161"
241
257
  ],
@@ -272,7 +288,10 @@ var SWARM_TEMP_GRAMMARS = [
272
288
  "src/background/pending-delegations.ts:1443",
273
289
  "src/background/delegation-health.ts:391",
274
290
  "src/tools/submit-phase-council-verdicts.ts:458",
275
- "src/summaries/store.ts (pre-#2035; migrated-to=src/summaries/store.ts:writeRawSidecar)"
291
+ "src/summaries/store.ts (pre-#2035; migrated-to=src/summaries/store.ts:writeRawSidecar)",
292
+ "src/retention/jsonl-cap.ts:213",
293
+ "src/services/skill-changelog.ts:58",
294
+ "src/turbo/epic/divergence-recorder.ts:108"
276
295
  ],
277
296
  note: "background lane/delegation stores keep bounded-retry rename semantics wired into their callers (#2034/#2276 delivery contracts); migration candidates for a follow-up but grammars registered"
278
297
  },
@@ -397,9 +416,11 @@ var SWARM_TEMP_GRAMMARS = [
397
416
  "src/tools/checkpoint.ts:195",
398
417
  "src/full-auto/state.ts:460",
399
418
  "src/context-map/persistence.ts:119",
400
- "src/context-map/capsule-persistence.ts:109",
401
- "src/test-impact/history-store.ts:225",
402
- "src/test-impact/history-store.ts:353",
419
+ "src/context-map/capsule-persistence.ts:111",
420
+ "src/test-impact/history-store.ts:297",
421
+ "src/test-impact/history-store.ts:302",
422
+ "src/test-impact/history-store.ts:429",
423
+ "src/test-impact/history-store.ts:435",
403
424
  "src/hooks/promotion-evidence-store.ts:112",
404
425
  "src/hooks/skill-usage-log.ts:1165",
405
426
  "src/hooks/skill-usage-log.ts:1675",
@@ -440,6 +461,9 @@ var WRITER_CLASSIFICATION = Object.freeze({
440
461
  "src/services/skill-improver.ts": "migrated",
441
462
  "src/summaries/store.ts": "migrated",
442
463
  "src/prm/trajectory-store.ts": "migrated",
464
+ "src/retention/jsonl-cap.ts": "registered-bespoke",
465
+ "src/services/skill-changelog.ts": "registered-bespoke",
466
+ "src/turbo/epic/divergence-recorder.ts": "registered-bespoke",
443
467
  "src/background/delegation-health.ts": "registered-bespoke",
444
468
  "src/background/lane-output-store.ts": "registered-bespoke",
445
469
  "src/background/pending-delegations.ts": "registered-bespoke",
@@ -574,6 +598,28 @@ function assertSwarmContainedTarget(targetPath) {
574
598
  var MAX_ATOMIC_WRITE_BYTES = 256 * 1024 * 1024;
575
599
  var RENAME_RETRY_DELAYS_MS = [10, 25, 50, 100, 200];
576
600
  var RETRYABLE_RENAME_CODES = new Set(["EPERM", "EBUSY", "EACCES", "EEXIST"]);
601
+ var MAX_RECENT_WRITE_TRACKED_PATHS = 256;
602
+ var RECENT_WRITE_WINDOW_MS = 500;
603
+ var recentWriteActivity = new Map;
604
+ function noteRecentWriteActivity(resolvedTarget) {
605
+ recentWriteActivity.delete(resolvedTarget);
606
+ recentWriteActivity.set(resolvedTarget, Date.now());
607
+ while (recentWriteActivity.size > MAX_RECENT_WRITE_TRACKED_PATHS) {
608
+ const oldest = recentWriteActivity.keys().next().value;
609
+ if (oldest === undefined)
610
+ break;
611
+ recentWriteActivity.delete(oldest);
612
+ }
613
+ }
614
+ function clearRecentWriteActivity(targetPath) {
615
+ return recentWriteActivity.delete(path2.resolve(targetPath));
616
+ }
617
+ function wasRecentlyWrittenByThisProcess(targetPath, withinMs = RECENT_WRITE_WINDOW_MS) {
618
+ const last = recentWriteActivity.get(path2.resolve(targetPath));
619
+ if (last === undefined)
620
+ return false;
621
+ return Date.now() - last <= withinMs;
622
+ }
577
623
  var _internals2 = {
578
624
  randomSuffix: () => randomBytes(16).toString("hex"),
579
625
  writeSync: (fd, buffer, offset, length) => fs2.writeSync(fd, buffer, offset, length),
@@ -619,6 +665,7 @@ function writeAtomicSync(targetPath, content, options) {
619
665
  assertWellFormedTargetPath(targetPath);
620
666
  }
621
667
  const resolvedTarget = path2.resolve(targetPath);
668
+ noteRecentWriteActivity(resolvedTarget);
622
669
  const buffer = toBuffer(content);
623
670
  const maxBytes = options?.maxBytes ?? MAX_ATOMIC_WRITE_BYTES;
624
671
  if (buffer.byteLength > maxBytes) {
@@ -627,25 +674,30 @@ function writeAtomicSync(targetPath, content, options) {
627
674
  const tempPath = `${resolvedTarget}.${_internals2.randomSuffix()}.tmp`;
628
675
  fs2.mkdirSync(path2.dirname(tempPath), { recursive: true });
629
676
  try {
630
- const fd = fs2.openSync(tempPath, "wx", options?.mode);
631
677
  try {
632
- let written = 0;
633
- while (written < buffer.byteLength) {
634
- written += _internals2.writeSync(fd, buffer, written, buffer.byteLength - written);
635
- }
636
- if (options?.skipFsync !== true) {
637
- try {
638
- _internals2.fsyncSync(fd);
639
- } catch {}
678
+ const fd = fs2.openSync(tempPath, "wx", options?.mode);
679
+ try {
680
+ let written = 0;
681
+ while (written < buffer.byteLength) {
682
+ written += _internals2.writeSync(fd, buffer, written, buffer.byteLength - written);
683
+ }
684
+ if (options?.skipFsync !== true) {
685
+ try {
686
+ _internals2.fsyncSync(fd);
687
+ } catch {}
688
+ }
689
+ } finally {
690
+ fs2.closeSync(fd);
640
691
  }
692
+ renameWithRetry(tempPath, resolvedTarget);
641
693
  } finally {
642
- fs2.closeSync(fd);
694
+ try {
695
+ _internals2.unlinkSync(tempPath);
696
+ } catch {}
643
697
  }
644
- renameWithRetry(tempPath, resolvedTarget);
645
- } finally {
646
- try {
647
- _internals2.unlinkSync(tempPath);
648
- } catch {}
698
+ } catch (error) {
699
+ clearRecentWriteActivity(resolvedTarget);
700
+ throw error;
649
701
  }
650
702
  try {
651
703
  const dirFd = fs2.openSync(path2.dirname(resolvedTarget), "r");
@@ -656,6 +708,7 @@ function writeAtomicSync(targetPath, content, options) {
656
708
  }
657
709
  } catch {}
658
710
  invalidateCachedArtifact(resolvedTarget);
711
+ noteRecentWriteActivity(resolvedTarget);
659
712
  }
660
713
  async function atomicWriteSwarmFile(targetPath, content, options) {
661
714
  await new Promise((resolve3) => setImmediate(resolve3));
@@ -669,4 +722,4 @@ async function atomicWriteFileAnyRoot(targetPath, content, options) {
669
722
  writeAtomicSync(targetPath, content, { ...options, contained: false });
670
723
  }
671
724
 
672
- export { readCachedTextFile, readCachedParsedFile, invalidateCachedArtifact, resetSwarmArtifactCache, matchTempGrammar, parseTargetBasename, atomicWriteSwarmFile, atomicWriteSwarmFileSync, atomicWriteFileAnyRoot };
725
+ export { wasObservedToExist, readCachedTextFile, readCachedParsedFile, invalidateCachedArtifact, resetSwarmArtifactCache, matchTempGrammar, parseTargetBasename, RECENT_WRITE_WINDOW_MS, wasRecentlyWrittenByThisProcess, atomicWriteSwarmFile, atomicWriteSwarmFileSync, atomicWriteFileAnyRoot };
@@ -9,7 +9,7 @@ import {
9
9
  readEvaluationRun,
10
10
  saveEvaluationRun,
11
11
  saveTaskSetSnapshot
12
- } from "./index-17yszqs5.js";
12
+ } from "./index-5bd84nxc.js";
13
13
  import {
14
14
  canonicalHash,
15
15
  computeCandidateInputContentHash,
@@ -1,10 +1,10 @@
1
1
  // @bun
2
2
  import {
3
3
  computePlanStructureHash
4
- } from "./index-2y4kargd.js";
4
+ } from "./index-3f1tr4ha.js";
5
5
  import {
6
6
  appendCoreEventSync
7
- } from "./index-2v17wb75.js";
7
+ } from "./index-qd619x3r.js";
8
8
  import {
9
9
  deleteCoordinationState,
10
10
  derivePlanId,
@@ -13,27 +13,27 @@ import {
13
13
  transitionCoordinationState,
14
14
  transitionCoordinationStateWithinTransaction,
15
15
  withCoordinationTransaction
16
- } from "./index-jx9f4ke1.js";
16
+ } from "./index-6d4dc99f.js";
17
17
  import {
18
18
  getProjectDb
19
- } from "./index-aftapk6j.js";
19
+ } from "./index-rk10x4zr.js";
20
20
  import {
21
21
  canonicalExistingFilesystemPath,
22
22
  legacyCanonicalExistingFilesystemPath
23
23
  } from "./index-ry16d01s.js";
24
24
  import {
25
25
  assertProjectRoot
26
- } from "./index-edm41q4j.js";
26
+ } from "./index-2w0beg3s.js";
27
27
  import {
28
28
  atomicWriteSwarmFile,
29
29
  atomicWriteSwarmFileSync
30
- } from "./index-gy0nyfbw.js";
30
+ } from "./index-m21x1bkx.js";
31
31
  import {
32
32
  require_proper_lockfile
33
33
  } from "./index-7g4c7s5r.js";
34
34
  import {
35
35
  PlanSchema
36
- } from "./index-52xdezsh.js";
36
+ } from "./index-0jpv5z94.js";
37
37
  import {
38
38
  init_path_identity,
39
39
  unsafePathTextReason
@@ -5,25 +5,29 @@ import {
5
5
  import {
6
6
  effectiveRetrievalOutcomes,
7
7
  readAuthoritativeKnowledgeCounterRollups
8
- } from "./index-zha9bdj9.js";
8
+ } from "./index-tzq6t9wc.js";
9
9
  import {
10
10
  ALLOWED_SKILL_PATH_PREFIXES,
11
11
  validateSkillPath
12
- } from "./index-6rff2h8x.js";
12
+ } from "./index-bwvbj3fp.js";
13
13
  import {
14
14
  computeOutcomeSignal,
15
15
  readKnowledge,
16
16
  resolveHiveKnowledgePath,
17
17
  resolveSwarmKnowledgePath,
18
18
  transactKnowledge
19
- } from "./index-bkd3450m.js";
19
+ } from "./index-8cky7ksv.js";
20
20
  import {
21
- canonicalRootKeyFresh
22
- } from "./index-7qefgq4j.js";
21
+ appendCappedJsonl,
22
+ resolveRetentionCap
23
+ } from "./index-vzm6zre7.js";
23
24
  import {
24
25
  atomicWriteFileAnyRoot,
25
26
  atomicWriteSwarmFile
26
- } from "./index-gy0nyfbw.js";
27
+ } from "./index-m21x1bkx.js";
28
+ import {
29
+ canonicalRootKeyFresh
30
+ } from "./index-7qefgq4j.js";
27
31
  import {
28
32
  advisoryWarn,
29
33
  init_warning_buffer
@@ -43,7 +47,7 @@ import {
43
47
 
44
48
  // src/services/skill-generator.ts
45
49
  import { existsSync as existsSync2, unlinkSync } from "fs";
46
- import { mkdir as mkdir4, readFile as readFile4, unlink, writeFile as writeFile3 } from "fs/promises";
50
+ import { mkdir as mkdir3, readFile as readFile4, unlink as unlink2, writeFile as writeFile3 } from "fs/promises";
47
51
  import * as path4 from "path";
48
52
 
49
53
  // src/config/bundled-skills.ts
@@ -406,34 +410,95 @@ init_knowledge_types();
406
410
  init_logger();
407
411
 
408
412
  // src/services/skill-changelog.ts
409
- init_logger();
410
- import { appendFile, mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
413
+ import { readdir as readdir2, readFile as readFile2, rename as rename2, unlink, writeFile as writeFile2 } from "fs/promises";
411
414
  import * as path2 from "path";
412
- var MAX_CHANGELOG_ENTRIES_PER_SKILL = 200;
415
+ init_logger();
416
+ var MAX_SKILL_CHANGELOG_ENTRIES_PER_SKILL = 200;
417
+ var MAX_SKILL_CHANGELOG_GLOBAL_ENTRIES = 1e4;
413
418
  function resolveSkillChangelogPath(directory, slug) {
414
419
  if (slug.includes("..") || slug.includes("/") || slug.includes("\\")) {
415
420
  throw new Error(`Invalid skill slug: ${slug} \u2014 must not contain "..", "/" or "\\"`);
416
421
  }
417
422
  return path2.join(directory, ".swarm", "skill-changelogs", `${slug}.jsonl`);
418
423
  }
419
- async function appendSkillChangelog(directory, slug, entry) {
420
- const filePath = resolveSkillChangelogPath(directory, slug);
421
- const dirPath = path2.dirname(filePath);
422
- await mkdir2(dirPath, { recursive: true });
423
- await appendFile(filePath, `${JSON.stringify(entry)}
424
+ async function rewriteLinesAtomically(filePath, lines) {
425
+ const tmpPath = `${filePath}.tmp-${process.pid}-${Math.random().toString(36).slice(2, 8)}`;
426
+ await writeFile2(tmpPath, `${lines.join(`
427
+ `)}
424
428
  `, "utf-8");
425
429
  try {
426
- const content = await readFile2(filePath, "utf-8");
430
+ await rename2(tmpPath, filePath);
431
+ } catch (err) {
432
+ await unlink(tmpPath).catch(() => {});
433
+ throw err;
434
+ }
435
+ }
436
+ async function enforceGlobalEntryCap(dirPath) {
437
+ const cap = resolveRetentionCap("MAX_SKILL_CHANGELOG_GLOBAL_ENTRIES", MAX_SKILL_CHANGELOG_GLOBAL_ENTRIES);
438
+ let files;
439
+ try {
440
+ files = (await readdir2(dirPath)).filter((name) => name.endsWith(".jsonl"));
441
+ } catch {
442
+ return;
443
+ }
444
+ const linesByFile = new Map;
445
+ const stamped = [];
446
+ for (const file of files) {
447
+ let content;
448
+ try {
449
+ content = await readFile2(path2.join(dirPath, file), "utf-8");
450
+ } catch {
451
+ continue;
452
+ }
427
453
  const lines = content.split(`
428
454
  `).filter((line) => line.trim().length > 0);
429
- if (lines.length > MAX_CHANGELOG_ENTRIES_PER_SKILL) {
430
- const trimmed = lines.slice(lines.length - MAX_CHANGELOG_ENTRIES_PER_SKILL);
431
- await writeFile2(filePath, `${trimmed.join(`
432
- `)}
433
- `, "utf-8");
455
+ linesByFile.set(file, lines);
456
+ for (let i = 0;i < lines.length; i++) {
457
+ let timestamp = "";
458
+ try {
459
+ const parsed = JSON.parse(lines[i]);
460
+ if (typeof parsed.timestamp === "string")
461
+ timestamp = parsed.timestamp;
462
+ } catch {}
463
+ stamped.push({ file, index: i, timestamp });
464
+ }
465
+ }
466
+ if (stamped.length <= cap)
467
+ return;
468
+ stamped.sort((a, b) => {
469
+ if (a.timestamp !== b.timestamp) {
470
+ return a.timestamp < b.timestamp ? -1 : 1;
434
471
  }
472
+ if (a.file !== b.file)
473
+ return a.file < b.file ? -1 : 1;
474
+ return a.index - b.index;
475
+ });
476
+ const drop = new Set;
477
+ for (let i = 0;i < stamped.length - cap; i++) {
478
+ const item = stamped[i];
479
+ drop.add(`${item.file}\x00${item.index}`);
480
+ }
481
+ for (const [file, lines] of linesByFile) {
482
+ const kept = lines.filter((_, index) => !drop.has(`${file}\x00${index}`));
483
+ if (kept.length === lines.length)
484
+ continue;
485
+ const filePath = path2.join(dirPath, file);
486
+ if (kept.length === 0) {
487
+ await unlink(filePath).catch(() => {});
488
+ continue;
489
+ }
490
+ await rewriteLinesAtomically(filePath, kept);
491
+ }
492
+ }
493
+ async function appendSkillChangelog(directory, slug, entry) {
494
+ const filePath = resolveSkillChangelogPath(directory, slug);
495
+ await appendCappedJsonl(filePath, JSON.stringify(entry), {
496
+ maxEntries: resolveRetentionCap("MAX_SKILL_CHANGELOG_ENTRIES_PER_SKILL", MAX_SKILL_CHANGELOG_ENTRIES_PER_SKILL)
497
+ });
498
+ try {
499
+ await enforceGlobalEntryCap(path2.dirname(filePath));
435
500
  } catch (err) {
436
- warn(`[skill-changelog] FIFO trim failed (non-fatal): ${err instanceof Error ? err.message : String(err)}`);
501
+ warn(`[skill-changelog] global ceiling enforcement failed (non-fatal): ${err instanceof Error ? err.message : String(err)}`);
437
502
  }
438
503
  }
439
504
 
@@ -442,8 +507,8 @@ import { createHash } from "crypto";
442
507
  import { existsSync } from "fs";
443
508
  import {
444
509
  lstat as lstat2,
445
- mkdir as mkdir3,
446
- readdir as readdir2,
510
+ mkdir as mkdir2,
511
+ readdir as readdir3,
447
512
  readFile as readFile3,
448
513
  realpath,
449
514
  stat as stat2
@@ -559,7 +624,7 @@ async function loadEvalSet(directory, slug) {
559
624
  }
560
625
  let entries;
561
626
  try {
562
- entries = await readdir2(root);
627
+ entries = await readdir3(root);
563
628
  } catch (err) {
564
629
  return {
565
630
  status: "invalid",
@@ -760,7 +825,7 @@ async function evaluateSkillChange(req) {
760
825
  };
761
826
  }
762
827
  async function atomicWrite(filePath, content) {
763
- await mkdir3(path3.dirname(filePath), { recursive: true });
828
+ await mkdir2(path3.dirname(filePath), { recursive: true });
764
829
  await atomicWriteSwarmFile(filePath, content);
765
830
  }
766
831
  async function appendRejectedSkillEdit(req, evaluation) {
@@ -871,7 +936,7 @@ async function writeEvalStub(directory, slug, cases) {
871
936
  return { written: false, path: stubPath, reason: "no directive fields" };
872
937
  }
873
938
  try {
874
- await mkdir4(path4.dirname(stubPath), { recursive: true });
939
+ await mkdir3(path4.dirname(stubPath), { recursive: true });
875
940
  await atomicWrite2(stubPath, `${JSON.stringify({ cases })}
876
941
  `);
877
942
  return { written: true, path: stubPath };
@@ -1106,7 +1171,7 @@ function escapeMarkdown(s) {
1106
1171
  return s.replace(/[\r\n]+/g, " ").slice(0, 280);
1107
1172
  }
1108
1173
  async function atomicWrite2(p, content) {
1109
- await mkdir4(path4.dirname(p), { recursive: true });
1174
+ await mkdir3(path4.dirname(p), { recursive: true });
1110
1175
  await atomicWriteFileAnyRoot(p, content);
1111
1176
  }
1112
1177
  async function generateSkills(req) {
@@ -1864,7 +1929,7 @@ async function retireSkill(directory, slug, reason) {
1864
1929
  retiredAt: new Date().toISOString(),
1865
1930
  reason: reason ?? "manual_retire"
1866
1931
  });
1867
- await mkdir4(markerDir, { recursive: true });
1932
+ await mkdir3(markerDir, { recursive: true });
1868
1933
  await writeFile3(markerPath, markerContent, "utf-8");
1869
1934
  let clearedLinks = [];
1870
1935
  try {
@@ -1954,13 +2019,13 @@ async function clearSkillLinks(directory, skillFilePath, slug, mode) {
1954
2019
  return cleared;
1955
2020
  }
1956
2021
  async function markSkillStale(skillDir, reason) {
1957
- await mkdir4(skillDir, { recursive: true });
2022
+ await mkdir3(skillDir, { recursive: true });
1958
2023
  await writeFile3(path4.join(skillDir, "stale.marker"), reason, "utf-8");
1959
2024
  }
1960
2025
  async function clearSkillStale(skillDir) {
1961
2026
  const markerPath = path4.join(skillDir, "stale.marker");
1962
2027
  try {
1963
- await unlink(markerPath);
2028
+ await unlink2(markerPath);
1964
2029
  } catch (err) {
1965
2030
  if (err instanceof Error && "code" in err && err.code === "ENOENT") {
1966
2031
  return;
@@ -1,10 +1,10 @@
1
1
  // @bun
2
2
  import {
3
3
  observeStoreHealth
4
- } from "./index-axf65x87.js";
4
+ } from "./index-qd726agw.js";
5
5
  import {
6
6
  telemetry
7
- } from "./index-hwj25q9r.js";
7
+ } from "./index-f6zgz02s.js";
8
8
  import {
9
9
  init_logger,
10
10
  warn
@@ -1,15 +1,15 @@
1
1
  // @bun
2
- import {
3
- canonicalRootKeyFresh
4
- } from "./index-7qefgq4j.js";
5
2
  import {
6
3
  atomicWriteSwarmFile
7
- } from "./index-gy0nyfbw.js";
4
+ } from "./index-m21x1bkx.js";
8
5
  import {
9
6
  pseudonymousRef,
10
7
  resolveLineageSalt,
11
8
  telemetry
12
- } from "./index-hwj25q9r.js";
9
+ } from "./index-f6zgz02s.js";
10
+ import {
11
+ canonicalRootKeyFresh
12
+ } from "./index-7qefgq4j.js";
13
13
 
14
14
  // src/health/learning-health.ts
15
15
  import { promises as fs } from "fs";
@@ -2,15 +2,19 @@
2
2
  import {
3
3
  cohortConfigFingerprint
4
4
  } from "./index-rtry5xyf.js";
5
+ import {
6
+ appendCappedJsonl,
7
+ resolveRetentionCap
8
+ } from "./index-vzm6zre7.js";
5
9
  import {
6
10
  isLinked,
7
11
  readLinkPointer,
8
12
  resolveKnowledgeStoreDir,
9
13
  resolveLinkDir
10
- } from "./index-a7rw4g4s.js";
14
+ } from "./index-t8tw1bhs.js";
11
15
 
12
16
  // src/knowledge/curation-policy.ts
13
- import { appendFile, mkdir as mkdir2, readFile as readFile2 } from "fs/promises";
17
+ import { readFile as readFile2 } from "fs/promises";
14
18
  import * as path2 from "path";
15
19
 
16
20
  // src/knowledge/worktree-identity.ts
@@ -85,6 +89,7 @@ async function resolveWorktreeId(directory) {
85
89
 
86
90
  // src/knowledge/curation-policy.ts
87
91
  var DEFAULT_QUORUM = { minCohortEvidence: 3 };
92
+ var MAX_CURATION_PROPOSALS = 200;
88
93
  async function authorizeCuration(input, context, quorum = DEFAULT_QUORUM) {
89
94
  const { directory, action, entryId } = input;
90
95
  const proposal = {
@@ -99,9 +104,9 @@ async function authorizeCuration(input, context, quorum = DEFAULT_QUORUM) {
99
104
  queueMicrotask(async () => {
100
105
  try {
101
106
  const storeDir = _internals2.resolveKnowledgeStoreDir(directory);
102
- await mkdir2(storeDir, { recursive: true });
103
- await appendFile(path2.join(storeDir, "curation-proposals.jsonl"), `${JSON.stringify(p)}
104
- `, "utf-8");
107
+ await appendCappedJsonl(path2.join(storeDir, "curation-proposals.jsonl"), JSON.stringify(p), {
108
+ maxEntries: resolveRetentionCap("MAX_CURATION_PROPOSALS", MAX_CURATION_PROPOSALS)
109
+ });
105
110
  } catch {}
106
111
  });
107
112
  };
@@ -241,4 +246,4 @@ var _internals2 = {
241
246
  resolveKnowledgeStoreDir
242
247
  };
243
248
 
244
- export { authorizeCuration, buildConfigFingerprintInput, readCohortConfigFingerprint, _internals2 as _internals };
249
+ export { MAX_CURATION_PROPOSALS, authorizeCuration, buildConfigFingerprintInput, readCohortConfigFingerprint, _internals2 as _internals };
@@ -5,13 +5,13 @@ import {
5
5
  import {
6
6
  loadDatabaseCtor
7
7
  } from "./index-n4fzmqz8.js";
8
+ import {
9
+ atomicWriteSwarmFileSync
10
+ } from "./index-m21x1bkx.js";
8
11
  import {
9
12
  canonicalRootKeyFresh,
10
13
  lexicalRootAliasKey
11
14
  } from "./index-7qefgq4j.js";
12
- import {
13
- atomicWriteSwarmFileSync
14
- } from "./index-gy0nyfbw.js";
15
15
 
16
16
  // src/db/project-db.ts
17
17
  import { existsSync, mkdirSync, unlinkSync } from "fs";
@@ -1,13 +1,16 @@
1
1
  // @bun
2
- import {
3
- SwarmError
4
- } from "./index-ee6ydtfe.js";
5
2
  import {
6
3
  bunFile
7
4
  } from "./index-p612v1mv.js";
8
5
  import {
9
- readCachedTextFile
10
- } from "./index-gy0nyfbw.js";
6
+ RECENT_WRITE_WINDOW_MS,
7
+ readCachedTextFile,
8
+ wasObservedToExist,
9
+ wasRecentlyWrittenByThisProcess
10
+ } from "./index-m21x1bkx.js";
11
+ import {
12
+ SwarmError
13
+ } from "./index-ee6ydtfe.js";
11
14
  import {
12
15
  warn
13
16
  } from "./index-zgwm4ryv.js";
@@ -144,8 +147,9 @@ async function readSwarmFileAsync(directory, filename, cache) {
144
147
  const ENOENT_RETRY_DELAY_MS = 10;
145
148
  const maxAttempts = 6;
146
149
  for (let attempt = 0;attempt < maxAttempts; attempt++) {
150
+ let resolvedPath = "";
147
151
  try {
148
- const resolvedPath = _internals.validateSwarmPath(directory, filename);
152
+ resolvedPath = _internals.validateSwarmPath(directory, filename);
149
153
  return await _internals.readCachedTextFile(resolvedPath, async () => {
150
154
  const file = bunFile(resolvedPath);
151
155
  return await file.text();
@@ -153,6 +157,9 @@ async function readSwarmFileAsync(directory, filename, cache) {
153
157
  } catch (err) {
154
158
  const code = err?.code;
155
159
  if (code === "ENOENT") {
160
+ const retryWorthy = resolvedPath !== "" && (wasRecentlyWrittenByThisProcess(resolvedPath, RECENT_WRITE_WINDOW_MS) || wasObservedToExist(resolvedPath));
161
+ if (!retryWorthy)
162
+ return null;
156
163
  if (attempt >= ENOENT_MAX_ATTEMPTS - 1)
157
164
  return null;
158
165
  await new Promise((resolve2) => setTimeout(resolve2, ENOENT_RETRY_DELAY_MS));
@@ -1,10 +1,10 @@
1
1
  // @bun
2
+ import {
3
+ atomicWriteFile
4
+ } from "./index-2w0beg3s.js";
2
5
  import {
3
6
  canonicalRootKeyFresh
4
7
  } from "./index-7qefgq4j.js";
5
- import {
6
- atomicWriteFile
7
- } from "./index-edm41q4j.js";
8
8
  import {
9
9
  init_logger,
10
10
  warn