opencode-swarm 7.148.5 → 7.149.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/cli/{config-doctor-6z7x0jnz.js → config-doctor-fx8d6pma.js} +3 -3
  2. package/dist/cli/{core-0ph6pb2y.js → core-0v762txd.js} +3 -3
  3. package/dist/cli/{curation-policy-fbvctttr.js → curation-policy-4jxx3ey4.js} +6 -6
  4. package/dist/cli/{curator-pffqw3br.js → curator-6w4frzdz.js} +32 -31
  5. package/dist/cli/{curator-llm-factory-mbsn281q.js → curator-llm-factory-8fstpeqh.js} +32 -31
  6. package/dist/cli/{evidence-summary-service-9ajw5tpc.js → evidence-summary-service-x00z38n2.js} +15 -14
  7. package/dist/cli/{gate-evidence-wc8wzwaw.js → gate-evidence-ejdek2td.js} +9 -9
  8. package/dist/cli/{guardrail-explain-a8706sq1.js → guardrail-explain-nynjhbzk.js} +33 -32
  9. package/dist/cli/{guardrail-log-wx43bj32.js → guardrail-log-6bktj08e.js} +6 -4
  10. package/dist/cli/{guardrail-reset-sy0vztrd.js → guardrail-reset-hsfd5ykq.js} +32 -31
  11. package/dist/cli/{hive-promoter-jvyzykgx.js → hive-promoter-32artf8c.js} +32 -31
  12. package/dist/cli/{index-1w5nnyew.js → index-01q7mb83.js} +6 -6
  13. package/dist/cli/{index-yezd5ks6.js → index-41n0thtd.js} +2 -1
  14. package/dist/cli/{index-jzz52as5.js → index-42habrdv.js} +4 -4
  15. package/dist/cli/{index-haf092ak.js → index-5q5ws00e.js} +11 -11
  16. package/dist/cli/{index-x3d9asnz.js → index-6thxr1q7.js} +3 -3
  17. package/dist/cli/{index-q7ke7kwd.js → index-79pwr8hc.js} +9 -12
  18. package/dist/cli/{index-kj6m9ry3.js → index-8hkxm9mh.js} +4 -4
  19. package/dist/cli/{index-0yzt06r5.js → index-8yan955h.js} +2 -2
  20. package/dist/cli/{index-vrp2zva8.js → index-a90c1gtn.js} +1 -1
  21. package/dist/cli/{index-kg4knw6r.js → index-ame8ek9g.js} +7 -6
  22. package/dist/cli/{index-3aev3a0c.js → index-bcfcekx9.js} +268 -355
  23. package/dist/cli/{index-nq4tkfpc.js → index-bmaz2yy4.js} +1 -1
  24. package/dist/cli/{index-k1s8gxjh.js → index-c1h0rdkr.js} +1 -1
  25. package/dist/cli/index-c83bztkp.js +881 -0
  26. package/dist/cli/{index-5r2mcgpa.js → index-ccyve4pb.js} +1 -1
  27. package/dist/cli/{index-vhefvcta.js → index-cfvbd3dg.js} +2 -2
  28. package/dist/cli/{index-vyg5b8ee.js → index-ef0wracg.js} +5 -5
  29. package/dist/cli/{index-qbsc2btq.js → index-hbhw2qd7.js} +3 -3
  30. package/dist/cli/{index-ag9bv589.js → index-ka2vav7t.js} +34 -33
  31. package/dist/cli/{index-zhn0q7nf.js → index-kb1p6dpx.js} +18 -17
  32. package/dist/cli/{index-5zq3892p.js → index-mza55jmc.js} +4 -4
  33. package/dist/cli/{index-t25evmna.js → index-n6jykega.js} +1 -1
  34. package/dist/cli/{index-ne45ew6z.js → index-pgfn8h50.js} +10 -10
  35. package/dist/cli/{index-59wqcatm.js → index-q8e2yd98.js} +1 -1
  36. package/dist/cli/{index-zf2vwa7y.js → index-s7t2c9jd.js} +2 -2
  37. package/dist/cli/{index-j382eh60.js → index-vfv4vnnc.js} +1 -1
  38. package/dist/cli/{index-qwmrt51t.js → index-wbz365gn.js} +1 -1
  39. package/dist/cli/{index-ghbkknjz.js → index-wj0gnab0.js} +72 -41
  40. package/dist/cli/{index-arjq717j.js → index-wsar7d91.js} +1 -1
  41. package/dist/cli/{index-c6jqkx9d.js → index-xdp0bx28.js} +2 -2
  42. package/dist/cli/{index-8djgxw2w.js → index-z6471b7r.js} +2 -2
  43. package/dist/cli/{index-579qg534.js → index-zkcwan96.js} +1 -1
  44. package/dist/cli/index.js +32 -31
  45. package/dist/cli/{knowledge-escalator-bvrtfdyb.js → knowledge-escalator-ty2kesdj.js} +14 -14
  46. package/dist/cli/{knowledge-events-rpvkevbm.js → knowledge-events-x3rd7r3j.js} +12 -12
  47. package/dist/cli/{knowledge-link-spw879rs.js → knowledge-link-a5f89833.js} +5 -5
  48. package/dist/cli/{knowledge-store-wjy2kshh.js → knowledge-store-zsz4dxjq.js} +6 -6
  49. package/dist/cli/{knowledge-validator-cq2cgfcx.js → knowledge-validator-bdhgkw9f.js} +8 -8
  50. package/dist/cli/{pending-delegations-f4wvyzbf.js → pending-delegations-aez8ebdr.js} +3 -3
  51. package/dist/cli/{pr-subscriptions-f4xw1rxy.js → pr-subscriptions-cpnwvc6y.js} +3 -3
  52. package/dist/cli/{runner-rk26nk58.js → runner-9mnkfjw7.js} +6 -6
  53. package/dist/cli/{scan-cursor-7n0zs72g.js → scan-cursor-3ba1spad.js} +7 -7
  54. package/dist/cli/{schema-e59spg93.js → schema-h251vmd1.js} +1 -1
  55. package/dist/cli/{scope-persistence-d75p900m.js → scope-persistence-h1b31ba2.js} +8 -10
  56. package/dist/cli/{skill-generator-c65y1h6a.js → skill-generator-esrn40th.js} +16 -16
  57. package/dist/cli/{telemetry-1pnsftp0.js → telemetry-jtq6px7k.js} +1 -1
  58. package/dist/cli/{workspace-snapshot-nq25j94x.js → workspace-snapshot-8269e1p9.js} +2 -2
  59. package/dist/cli/{worktree-collision-ownership-wqy7mgb3.js → worktree-collision-ownership-r8j31h06.js} +8 -8
  60. package/dist/cli/{worktree-isolation-ay9d58w4.js → worktree-isolation-pbr4d5m9.js} +32 -31
  61. package/dist/commands/close.d.ts +1 -0
  62. package/dist/events/core-events.d.ts +250 -0
  63. package/dist/full-auto/oversight.d.ts +5 -3
  64. package/dist/hooks/full-auto-delegation.d.ts +24 -0
  65. package/dist/hooks/full-auto-input-probe.d.ts +11 -0
  66. package/dist/hooks/steering-consumed.d.ts +12 -4
  67. package/dist/index.js +583 -601
  68. package/dist/observability/catalog.d.ts +9 -7
  69. package/dist/services/spec-drift-recovery.d.ts +9 -2
  70. package/dist/telemetry.d.ts +24 -1
  71. package/package.json +2 -1
  72. package/dist/cli/{curator-drift-fv4rttf4.js → curator-drift-2h1d2fnq.js} +1 -1
  73. package/dist/cli/{index-g8wwj0sz.js → index-vnn7qq8c.js} +3 -3
@@ -6,17 +6,17 @@ import {
6
6
  resolveExecutableFromPath,
7
7
  runEvaluation,
8
8
  runExternalTool
9
- } from "./index-j382eh60.js";
9
+ } from "./index-vfv4vnnc.js";
10
10
  import {
11
11
  normalizeToolNameLowerCase,
12
12
  stableCanonicalStringify
13
- } from "./index-arjq717j.js";
13
+ } from "./index-wsar7d91.js";
14
14
  import {
15
15
  detectStraySwarmDirs,
16
16
  readDoctorArtifact,
17
17
  removeStraySwarmDir,
18
18
  runConfigDoctor
19
- } from "./index-5r2mcgpa.js";
19
+ } from "./index-ccyve4pb.js";
20
20
  import {
21
21
  MAX_TRANSIENT_RETRIES,
22
22
  archiveEvidence,
@@ -62,7 +62,7 @@ import {
62
62
  updateTaskStatus,
63
63
  validateProjectRoot,
64
64
  validateSymlinkBoundary
65
- } from "./index-zhn0q7nf.js";
65
+ } from "./index-kb1p6dpx.js";
66
66
  import {
67
67
  EvaluationTaskV1Schema,
68
68
  GateAuditManifestV1Schema,
@@ -79,7 +79,7 @@ import {
79
79
  saveGateAuditResult,
80
80
  savePromotionDecision,
81
81
  saveTaskSetSnapshot
82
- } from "./index-8djgxw2w.js";
82
+ } from "./index-z6471b7r.js";
83
83
  import {
84
84
  loadDatabaseCtor
85
85
  } from "./index-134d35c1.js";
@@ -105,12 +105,12 @@ import {
105
105
  } from "./index-y8552snf.js";
106
106
  import {
107
107
  readRecentEscalations
108
- } from "./index-vyg5b8ee.js";
108
+ } from "./index-ef0wracg.js";
109
109
  import {
110
110
  alreadyCuratedThisGeneration,
111
111
  claimNextScanBatch,
112
112
  resolveCohortId
113
- } from "./index-zf2vwa7y.js";
113
+ } from "./index-s7t2c9jd.js";
114
114
  import {
115
115
  CURATOR_INIT_PROMPT,
116
116
  CURATOR_PHASE_PROMPT,
@@ -153,13 +153,13 @@ import {
153
153
  resolveRemoteRefsContainingHead,
154
154
  resolveRemoteRefsContainingHeadAsync,
155
155
  switchPrFeedbackTrackingCandidateAsync
156
- } from "./index-g8wwj0sz.js";
156
+ } from "./index-vnn7qq8c.js";
157
157
  import {
158
158
  buildCorrelationId,
159
159
  listActive,
160
160
  subscribe,
161
161
  unsubscribe
162
- } from "./index-qwmrt51t.js";
162
+ } from "./index-wbz365gn.js";
163
163
  import {
164
164
  BUNDLED_PROJECT_SKILL_ROOT,
165
165
  DEFAULT_SKILL_MIN_CONFIDENCE,
@@ -180,7 +180,7 @@ import {
180
180
  retireSkill,
181
181
  selectCandidateEntries,
182
182
  syncBundledProjectSkillsIfMissingAsync
183
- } from "./index-jzz52as5.js";
183
+ } from "./index-42habrdv.js";
184
184
  import {
185
185
  appendUnactionable,
186
186
  quarantineEntry,
@@ -191,11 +191,11 @@ import {
191
191
  validateActionableFields,
192
192
  validateLesson,
193
193
  validateSkillPath
194
- } from "./index-kj6m9ry3.js";
194
+ } from "./index-8hkxm9mh.js";
195
195
  import {
196
196
  authorizeCuration,
197
197
  buildConfigFingerprintInput
198
- } from "./index-nq4tkfpc.js";
198
+ } from "./index-bmaz2yy4.js";
199
199
  import {
200
200
  cohortConfigFingerprint
201
201
  } from "./index-rtry5xyf.js";
@@ -219,7 +219,7 @@ import {
219
219
  scanBackgroundCoderReservationsForAdmission,
220
220
  scanDelegationsForRecovery,
221
221
  sweepStaleDelegations
222
- } from "./index-t25evmna.js";
222
+ } from "./index-n6jykega.js";
223
223
  import {
224
224
  WORKTREE_LIFECYCLE_LOCK_FILE,
225
225
  recordWorktreeProvisioningOwner,
@@ -252,18 +252,18 @@ import {
252
252
  transitionTaskWorkflowEvidence,
253
253
  withTaskEvidenceTransaction,
254
254
  writeWorkflowWalFile
255
- } from "./index-haf092ak.js";
255
+ } from "./index-5q5ws00e.js";
256
256
  import {
257
257
  provisionWorktree,
258
258
  removeWorktree
259
- } from "./index-5zq3892p.js";
259
+ } from "./index-mza55jmc.js";
260
260
  import {
261
261
  MAX_PENDING_SCOPE_BINDINGS,
262
262
  canonicalWorkspaceIdentity,
263
263
  clearAllScopes,
264
264
  clearScopeBindingFromDisk,
265
265
  clearScopeBindings
266
- } from "./index-q7ke7kwd.js";
266
+ } from "./index-79pwr8hc.js";
267
267
  import {
268
268
  appendLedgerEvent,
269
269
  computePlanHash,
@@ -278,7 +278,17 @@ import {
278
278
  readPlanEpochIdentity,
279
279
  replayFromLedgerWithStatus,
280
280
  takeSnapshotEvent
281
- } from "./index-x3d9asnz.js";
281
+ } from "./index-6thxr1q7.js";
282
+ import {
283
+ CORE_EVENT_LOCKED,
284
+ appendCoreEventSync,
285
+ appendCoreEventsSync,
286
+ finalizeCoreEventsForClose,
287
+ getCoreEventCoverage,
288
+ hasSpecDriftAuditEvent,
289
+ hasTaskRepairAuditEvent,
290
+ readCoreEvents
291
+ } from "./index-c83bztkp.js";
282
292
  import {
283
293
  isPathWithinDeclaredScope,
284
294
  sanitizeDiagnosticText
@@ -330,7 +340,7 @@ import {
330
340
  transactFile,
331
341
  transactKnowledge,
332
342
  wordBigrams
333
- } from "./index-1w5nnyew.js";
343
+ } from "./index-01q7mb83.js";
334
344
  import {
335
345
  MAX_EVENT_LOG_ENTRIES,
336
346
  _internals as _internals2,
@@ -344,20 +354,32 @@ import {
344
354
  recordKnowledgeEvent,
345
355
  recordPhaseCloseIntent,
346
356
  resolveKnowledgeEventsPath
347
- } from "./index-ne45ew6z.js";
357
+ } from "./index-pgfn8h50.js";
348
358
  import {
349
359
  resolveWorktreeIsolationConfig
350
- } from "./index-c6jqkx9d.js";
360
+ } from "./index-xdp0bx28.js";
351
361
  import {
352
362
  RetrospectiveEvidenceSchema
353
363
  } from "./index-gprxjmm7.js";
364
+ import {
365
+ readSwarmFileAsync,
366
+ safeHook,
367
+ validateSwarmPath
368
+ } from "./index-4cgee5vh.js";
369
+ import {
370
+ bunSpawn,
371
+ bunSpawnSync,
372
+ bunWrite,
373
+ mergeEnvForChild,
374
+ sleep
375
+ } from "./index-r3mvsbtq.js";
354
376
  import {
355
377
  PlanSchema,
356
378
  exports_loader,
357
379
  init_loader,
358
380
  loadPluginConfig,
359
381
  loadPluginConfigWithMeta
360
- } from "./index-59wqcatm.js";
382
+ } from "./index-q8e2yd98.js";
361
383
  import {
362
384
  DEFAULT_SKILL_OPT_CONFIG,
363
385
  FALLBACK_MODELS_MAX,
@@ -371,7 +393,7 @@ import {
371
393
  package_default,
372
394
  resolveAutoReviewConfig,
373
395
  stripKnownSwarmPrefix
374
- } from "./index-yezd5ks6.js";
396
+ } from "./index-41n0thtd.js";
375
397
  import {
376
398
  AGENT_TOOL_MAP,
377
399
  ALL_AGENT_NAMES,
@@ -396,18 +418,6 @@ import {
396
418
  getDeferredWarnings,
397
419
  init_warning_buffer
398
420
  } from "./index-4rhhvd1a.js";
399
- import {
400
- readSwarmFileAsync,
401
- safeHook,
402
- validateSwarmPath
403
- } from "./index-4cgee5vh.js";
404
- import {
405
- bunSpawn,
406
- bunSpawnSync,
407
- bunWrite,
408
- mergeEnvForChild,
409
- sleep
410
- } from "./index-r3mvsbtq.js";
411
421
  import {
412
422
  resolveHiveDataDir,
413
423
  resolveHiveEventsPath,
@@ -423,10 +433,10 @@ import {
423
433
  resolveLinkDir,
424
434
  sanitizeLinkId,
425
435
  writeLinkPointer
426
- } from "./index-k1s8gxjh.js";
436
+ } from "./index-c1h0rdkr.js";
427
437
  import {
428
438
  atomicWriteFile
429
- } from "./index-vhefvcta.js";
439
+ } from "./index-cfvbd3dg.js";
430
440
  import {
431
441
  KNOWLEDGE_SCHEMA_VERSION,
432
442
  OUTCOME_BLOCK_THRESHOLD,
@@ -438,7 +448,7 @@ import {
438
448
  atomicWriteSwarmFileSync,
439
449
  matchTempGrammar,
440
450
  parseTargetBasename
441
- } from "./index-kg4knw6r.js";
451
+ } from "./index-ame8ek9g.js";
442
452
  import {
443
453
  assertProjectRoot,
444
454
  hasExplicitProjectBoundary,
@@ -446,12 +456,12 @@ import {
446
456
  listActiveLocks,
447
457
  tryAcquireLock,
448
458
  withEvidenceLock
449
- } from "./index-vrp2zva8.js";
459
+ } from "./index-a90c1gtn.js";
450
460
  import {
451
461
  emit,
452
462
  getLastHeartbeat,
453
463
  telemetry
454
- } from "./index-ghbkknjz.js";
464
+ } from "./index-wj0gnab0.js";
455
465
  import {
456
466
  require_proper_lockfile
457
467
  } from "./index-7g4c7s5r.js";
@@ -1991,9 +2001,9 @@ var storedInputArgs = new Map;
1991
2001
 
1992
2002
  // src/hooks/skill-propagation-gate.ts
1993
2003
  init_schema();
1994
- init_logger();
1995
2004
  import * as fs4 from "fs";
1996
2005
  import * as path6 from "path";
2006
+ init_logger();
1997
2007
 
1998
2008
  // src/hooks/skill-scoring.ts
1999
2009
  import * as fs3 from "fs";
@@ -4382,14 +4392,8 @@ function extractSkillsFieldFromPrompt(prompt) {
4382
4392
  return "";
4383
4393
  }
4384
4394
  function writeWarnEvent(directory, record) {
4385
- const filePath = path6.join(directory, ".swarm", "events.jsonl");
4386
4395
  try {
4387
- const dir = path6.dirname(filePath);
4388
- if (!_internals10.existsSync(dir)) {
4389
- _internals10.mkdirSync(dir, { recursive: true });
4390
- }
4391
- _internals10.appendFileSync(filePath, `${JSON.stringify(record)}
4392
- `, "utf-8");
4396
+ appendCoreEventSync(directory, record);
4393
4397
  } catch (err) {
4394
4398
  warn(`[skill-propagation-gate] failed to write warning event: ${err instanceof Error ? err.message : String(err)}`);
4395
4399
  }
@@ -5401,8 +5405,7 @@ init_logger();
5401
5405
  import { spawnSync } from "child_process";
5402
5406
  import { randomUUID as randomUUID2 } from "crypto";
5403
5407
  import { existsSync as existsSync6 } from "fs";
5404
- import { appendFile as appendFile2, mkdir as mkdir3, readdir as readdir2 } from "fs/promises";
5405
- import { dirname as dirname7 } from "path";
5408
+ import { readdir as readdir2 } from "fs/promises";
5406
5409
  init_warning_buffer();
5407
5410
  init_git_executable();
5408
5411
  init_logger();
@@ -5440,32 +5443,17 @@ async function writeWal(filePath, wal) {
5440
5443
  await writeWorkflowWalFile("coder-settlement", filePath, wal);
5441
5444
  }
5442
5445
  async function appendSettlementEvent(directory, action, wal, extra) {
5443
- const line = `${JSON.stringify({
5444
- type: "coder_settlement",
5445
- action,
5446
- timestamp: new Date().toISOString(),
5447
- taskId: wal.taskId,
5448
- transitionId: wal.transitionId,
5449
- actor: wal.actor,
5450
- ...extra ?? {}
5451
- })}
5452
- `;
5453
5446
  try {
5454
- const eventsPath = validateSwarmPath(directory, "events.jsonl");
5455
- await mkdir3(dirname7(eventsPath), { recursive: true });
5456
- await appendFile2(eventsPath, line, "utf-8");
5447
+ appendCoreEventSync(directory, {
5448
+ type: "coder_settlement",
5449
+ action,
5450
+ timestamp: new Date().toISOString(),
5451
+ taskId: wal.taskId,
5452
+ transitionId: wal.transitionId,
5453
+ actor: wal.actor,
5454
+ ...extra ?? {}
5455
+ });
5457
5456
  } catch (error2) {
5458
- const code = error2.code;
5459
- if (code === "EBUSY" || code === "EPERM") {
5460
- try {
5461
- const eventsPath = validateSwarmPath(directory, "events.jsonl");
5462
- await appendFile2(eventsPath, line, "utf-8");
5463
- return;
5464
- } catch (retryError) {
5465
- criticalWarn(`[coder-settlement] lifecycle event write failed after retry (${action} ${wal.taskId}): ${retryError instanceof Error ? retryError.message : String(retryError)}`);
5466
- return;
5467
- }
5468
- }
5469
5457
  criticalWarn(`[coder-settlement] lifecycle event write failed (${action} ${wal.taskId}): ${error2 instanceof Error ? error2.message : String(error2)}`);
5470
5458
  }
5471
5459
  }
@@ -5608,7 +5596,7 @@ async function cleanupRecoveredWorktree(directory, descriptor) {
5608
5596
  awaitingMergeByCallID,
5609
5597
  cleanupStandardWorktreeForCallId,
5610
5598
  standardWorktreeByCallID
5611
- } = await import("./worktree-isolation-ay9d58w4.js");
5599
+ } = await import("./worktree-isolation-pbr4d5m9.js");
5612
5600
  standardWorktreeByCallID.delete(descriptor.callID);
5613
5601
  if (hasResidue)
5614
5602
  awaitingMergeByCallID.set(descriptor.callID, {
@@ -5710,7 +5698,7 @@ async function recoverCoderSettlement(directory, taskId) {
5710
5698
  awaitingMergeByCallID,
5711
5699
  finishStandardWorktreeDispatch,
5712
5700
  standardWorktreeByCallID
5713
- } = await import("./worktree-isolation-ay9d58w4.js");
5701
+ } = await import("./worktree-isolation-pbr4d5m9.js");
5714
5702
  const descriptor = wal.worktree;
5715
5703
  const reconstructedDispatch = {
5716
5704
  callID: descriptor.callID,
@@ -5980,17 +5968,15 @@ var _internals13 = {
5980
5968
  };
5981
5969
 
5982
5970
  // src/workflow/task-repair.ts
5983
- import { appendFile as appendFile3, readFile as readFile4 } from "fs/promises";
5984
5971
  async function recoverPreparedTaskRepairWithPlanLock(directory, taskId, actor, currentPlan) {
5985
5972
  const walPath2 = validateSwarmPath(directory, `task-repairs/${taskId}.json`);
5986
- const eventsPath = validateSwarmPath(directory, "events.jsonl");
5987
5973
  const wal = await readWal2(walPath2, taskId);
5988
5974
  if (wal === null)
5989
5975
  return null;
5990
5976
  if (wal.state === "ABORTED")
5991
5977
  return null;
5992
5978
  if (wal.state === "COMMITTED") {
5993
- await ensureAuditEvent(directory, eventsPath, wal);
5979
+ await ensureAuditEvent(directory, wal);
5994
5980
  return null;
5995
5981
  }
5996
5982
  const task = currentPlan.phases.flatMap((phase) => phase.tasks).find((candidate) => candidate.id === taskId);
@@ -6030,57 +6016,15 @@ async function recoverPreparedTaskRepairUnderPlanLock(directory, taskId, actor,
6030
6016
  async function readWal2(filePath, taskId) {
6031
6017
  return readWorkflowWalFile("task-repair", filePath, taskId);
6032
6018
  }
6033
- async function readText(filePath) {
6034
- try {
6035
- return await readFile4(filePath, "utf-8");
6036
- } catch (error2) {
6037
- if (error2.code === "ENOENT")
6038
- return null;
6039
- throw error2;
6040
- }
6041
- }
6042
6019
  async function writeWal2(filePath, wal) {
6043
6020
  await writeWorkflowWalFile("task-repair", filePath, wal);
6044
6021
  }
6045
- function parseAuditEventLine(line) {
6046
- try {
6047
- return JSON.parse(line);
6048
- } catch {
6049
- return null;
6050
- }
6051
- }
6052
- function findRepairEvent(content, taskId, transitionId) {
6053
- if (!content)
6054
- return false;
6055
- const transitionNeedle = JSON.stringify(transitionId).slice(1, -1);
6056
- const taskNeedle = JSON.stringify(taskId).slice(1, -1);
6057
- if (!content.includes(transitionNeedle) || !content.includes(taskNeedle))
6058
- return false;
6059
- for (const line of content.split(`
6060
- `)) {
6061
- if (!line.trim())
6062
- continue;
6063
- const event = parseAuditEventLine(line);
6064
- if (!event)
6065
- continue;
6066
- if (event.type === "task_workflow_repaired" && event.taskId === taskId && event.transitionId === transitionId) {
6067
- return true;
6068
- }
6069
- }
6070
- return false;
6071
- }
6072
- async function ensureAuditEvent(directory, eventsPath, wal) {
6073
- if (findRepairEvent(await readText(eventsPath), wal.taskId, wal.transitionId))
6022
+ async function ensureAuditEvent(directory, wal) {
6023
+ if (hasTaskRepairAuditEvent(directory, wal.taskId, wal.transitionId)) {
6074
6024
  return;
6075
- const lock = await tryAcquireLock(directory, "events.jsonl", "task-repair-audit", `task-repair:${wal.taskId}:${wal.transitionId}`);
6076
- if (!lock.acquired) {
6077
- throw new Error("TASK_REPAIR_AUDIT_LOCKED");
6078
6025
  }
6079
6026
  try {
6080
- const existing = await readText(eventsPath);
6081
- if (findRepairEvent(existing, wal.taskId, wal.transitionId))
6082
- return;
6083
- await appendFile3(eventsPath, `${JSON.stringify({
6027
+ appendCoreEventSync(directory, {
6084
6028
  type: "task_workflow_repaired",
6085
6029
  timestamp: new Date().toISOString(),
6086
6030
  taskId: wal.taskId,
@@ -6092,15 +6036,15 @@ async function ensureAuditEvent(directory, eventsPath, wal) {
6092
6036
  oldWorkflowState: wal.oldWorkflowState,
6093
6037
  newWorkflowState: wal.newWorkflowState,
6094
6038
  generation: wal.generation
6095
- })}
6096
- `, "utf-8");
6097
- const verified = await readText(eventsPath);
6098
- if (!findRepairEvent(verified, wal.taskId, wal.transitionId)) {
6099
- throw new Error("TASK_REPAIR_AUDIT_UNVERIFIED");
6039
+ }, { dedupeOnAuthorityKey: true });
6040
+ } catch (error2) {
6041
+ if (error2 instanceof Error && error2.message === CORE_EVENT_LOCKED) {
6042
+ throw new Error("TASK_REPAIR_AUDIT_LOCKED");
6100
6043
  }
6101
- } finally {
6102
- if (lock.lock._release)
6103
- await lock.lock._release().catch(() => {});
6044
+ throw error2;
6045
+ }
6046
+ if (!hasTaskRepairAuditEvent(directory, wal.taskId, wal.transitionId)) {
6047
+ throw new Error("TASK_REPAIR_AUDIT_UNVERIFIED");
6104
6048
  }
6105
6049
  }
6106
6050
  function workflowMatchesCommittedRepair(evidence, wal) {
@@ -6109,7 +6053,6 @@ function workflowMatchesCommittedRepair(evidence, wal) {
6109
6053
  }
6110
6054
  async function repairTaskWorkflowUnderPlanLock(options) {
6111
6055
  const walPath2 = validateSwarmPath(options.directory, `task-repairs/${options.taskId}.json`);
6112
- const eventsPath = validateSwarmPath(options.directory, "events.jsonl");
6113
6056
  return withTaskEvidenceTransaction(options.directory, options.taskId, options.actor, async (transaction) => {
6114
6057
  await assertNoUnsettledCoderDispatch(options.directory, options.taskId);
6115
6058
  let evidence = transaction.read();
@@ -6127,7 +6070,7 @@ async function repairTaskWorkflowUnderPlanLock(options) {
6127
6070
  throw new Error(`TASK_REPAIR_IDEMPOTENCY_CONFLICT: transition ${options.transitionId} was prepared with different reason or workflow CAS fields`);
6128
6071
  }
6129
6072
  if (existingWal?.state === "COMMITTED" && options.currentPlanStatus === "in_progress" && workflowMatchesCommittedRepair(evidence, existingWal)) {
6130
- await ensureAuditEvent(options.directory, eventsPath, existingWal);
6073
+ await ensureAuditEvent(options.directory, existingWal);
6131
6074
  return {
6132
6075
  plan: options.currentPlan,
6133
6076
  alreadyApplied: true,
@@ -6180,7 +6123,7 @@ async function repairTaskWorkflowUnderPlanLock(options) {
6180
6123
  }
6181
6124
  }
6182
6125
  await writeWal2(walPath2, { ...wal, state: "COMMITTED" });
6183
- await ensureAuditEvent(options.directory, eventsPath, wal);
6126
+ await ensureAuditEvent(options.directory, wal);
6184
6127
  return {
6185
6128
  plan,
6186
6129
  alreadyApplied: false,
@@ -9022,7 +8965,7 @@ async function settlePresumedStalePrWorkflowLanes(directory, sessionID) {
9022
8965
  });
9023
8966
  } catch {}
9024
8967
  try {
9025
- await fsp2.appendFile(validateSwarmPath(directory, "events.jsonl"), `${JSON.stringify({
8968
+ appendCoreEventSync(directory, {
9026
8969
  type: "pr_workflow_lanes_presumed_stale",
9027
8970
  timestamp: isoNow(),
9028
8971
  sessionID,
@@ -9031,8 +8974,7 @@ async function settlePresumedStalePrWorkflowLanes(directory, sessionID) {
9031
8974
  probeStatus: probe.degradedReason ?? "ok",
9032
8975
  probedAliveLanes: probedAliveLaneIds.slice(0, MAX_DISCLOSED_LANE_IDS),
9033
8976
  disclosure
9034
- })}
9035
- `, "utf-8");
8977
+ });
9036
8978
  } catch {}
9037
8979
  return {
9038
8980
  openLaneIds,
@@ -9123,9 +9065,7 @@ async function abortPrWorkflow(directory, sessionID, options = { kind: "recovery
9123
9065
  reason: sanitizedReason
9124
9066
  };
9125
9067
  try {
9126
- const eventsPath = validateSwarmPath(directory, "events.jsonl");
9127
- await fsp2.appendFile(eventsPath, `${JSON.stringify(abortEvent)}
9128
- `, "utf-8");
9068
+ appendCoreEventSync(directory, abortEvent);
9129
9069
  } catch {}
9130
9070
  const casEscape = recovery.salvaged && !recovery.revisionSalvageable;
9131
9071
  await _test_exports2.beforeAbortClear?.();
@@ -9133,7 +9073,7 @@ async function abortPrWorkflow(directory, sessionID, options = { kind: "recovery
9133
9073
  await clearPrWorkflowGateState(directory, sessionID, casEscape ? undefined : state.revision, { allowSalvagedRead: recovery.salvaged });
9134
9074
  } catch (error2) {
9135
9075
  try {
9136
- await fsp2.appendFile(validateSwarmPath(directory, "events.jsonl"), `${JSON.stringify({
9076
+ appendCoreEventSync(directory, {
9137
9077
  type: "pr_workflow_abort_not_completed",
9138
9078
  timestamp: isoNow(),
9139
9079
  sessionID: state.sessionID,
@@ -9146,8 +9086,7 @@ async function abortPrWorkflow(directory, sessionID, options = { kind: "recovery
9146
9086
  } : {},
9147
9087
  failure: (error2 instanceof Error ? error2.message : String(error2)).slice(0, MAX_BASE_COVERAGE_DIAGNOSTIC_CHARS),
9148
9088
  disclosure: "RETRACTION: the pr_workflow_aborted record for this session did NOT complete \u2014 " + "the clear failed and the gate state may still be active. Revalidate the current " + "session state before retrying the abort." + (overridesProbeRetention ? " The probe-retention override finalized no record: it runs only after the " + "clear succeeds, and this clear failed. Other lanes in the same settlement " + "batch may already have been finalized as presumed-stale, and a concurrent abort for this session may have finalized more \u2014 revalidate the lane records rather than assuming they are untouched." : "")
9149
- })}
9150
- `, "utf-8");
9089
+ });
9151
9090
  } catch {}
9152
9091
  throw error2;
9153
9092
  }
@@ -12116,8 +12055,8 @@ ${USAGE}`;
12116
12055
 
12117
12056
  // src/services/spec-drift-recovery.ts
12118
12057
  import { createHash as createHash6 } from "crypto";
12119
- import { appendFile as appendFile5, mkdir as mkdir5, readFile as readFile6, unlink as unlink2 } from "fs/promises";
12120
- import { dirname as dirname10 } from "path";
12058
+ import { mkdir as mkdir4, readFile as readFile5, unlink as unlink2 } from "fs/promises";
12059
+ import { dirname as dirname9 } from "path";
12121
12060
  var SPEC_DRIFT_RECOVERY_AGENT = "spec-drift-recovery";
12122
12061
  var _internals16 = {
12123
12062
  appendEvent,
@@ -12177,7 +12116,7 @@ function parseWal(raw) {
12177
12116
  }
12178
12117
  async function readFileText(filePath) {
12179
12118
  try {
12180
- return await readFile6(filePath, "utf-8");
12119
+ return await readFile5(filePath, "utf-8");
12181
12120
  } catch (error2) {
12182
12121
  if (error2?.code === "ENOENT") {
12183
12122
  return null;
@@ -12197,7 +12136,7 @@ async function unlinkIfExists(filePath) {
12197
12136
  }
12198
12137
  }
12199
12138
  async function writeWal4(walPath2, wal) {
12200
- await mkdir5(dirname10(walPath2), { recursive: true });
12139
+ await mkdir4(dirname9(walPath2), { recursive: true });
12201
12140
  await atomicWriteFile(walPath2, `${JSON.stringify(wal, null, 2)}
12202
12141
  `);
12203
12142
  }
@@ -12243,37 +12182,18 @@ async function ensureSnapshotEvent(directory, plan, transitionId) {
12243
12182
  approvalMetadata: { specDriftTransitionId: transitionId }
12244
12183
  });
12245
12184
  }
12246
- async function appendEvent(eventsPath, event) {
12247
- const existing = await _internals16.verifyEventPresence(eventsPath, event.type, event.transitionId);
12185
+ async function appendEvent(directory, event) {
12186
+ const existing = await _internals16.verifyEventPresence(directory, event.type, event.transitionId);
12248
12187
  if (existing)
12249
12188
  return;
12250
- await appendFile5(eventsPath, `${JSON.stringify(event)}
12251
- `, "utf-8");
12252
- const verified = await _internals16.verifyEventPresence(eventsPath, event.type, event.transitionId);
12189
+ appendCoreEventSync(directory, { ...event }, { dedupeOnAuthorityKey: true });
12190
+ const verified = await _internals16.verifyEventPresence(directory, event.type, event.transitionId);
12253
12191
  if (!verified) {
12254
12192
  throw new Error(`spec drift audit verification failed for transition ${event.transitionId}`);
12255
12193
  }
12256
12194
  }
12257
- async function verifyEventPresence(eventsPath, eventType, transitionId) {
12258
- const raw = await _internals16.readFileText(eventsPath);
12259
- if (raw === null)
12260
- return false;
12261
- for (const line of raw.split(`
12262
- `)) {
12263
- const trimmed = line.trim();
12264
- if (trimmed.length === 0)
12265
- continue;
12266
- let parsed;
12267
- try {
12268
- parsed = JSON.parse(trimmed);
12269
- } catch (error2) {
12270
- throw new Error(`events.jsonl is not valid JSONL near "${trimmed.slice(0, 80)}": ${error2 instanceof Error ? error2.message : String(error2)}`);
12271
- }
12272
- if (parsed.type === eventType && parsed.transitionId === transitionId) {
12273
- return true;
12274
- }
12275
- }
12276
- return false;
12195
+ async function verifyEventPresence(directory, eventType, transitionId) {
12196
+ return hasSpecDriftAuditEvent(directory, eventType, transitionId);
12277
12197
  }
12278
12198
  function buildTransitionId(mode, markerHash, previousHash, newHash) {
12279
12199
  return sha2562(`${mode}:${markerHash}:${previousHash ?? "(null)"}:${newHash ?? "(null)"}`);
@@ -12316,7 +12236,6 @@ async function reconcileSpecDrift(directory, options) {
12316
12236
  const markerPath = _internals16.validateSwarmPath(directory, "spec-staleness.json");
12317
12237
  const walPath2 = _internals16.validateSwarmPath(directory, "spec-drift-recovery.json");
12318
12238
  const snapshotPath = _internals16.validateSwarmPath(directory, "spec-snapshot.md");
12319
- const eventsPath = _internals16.validateSwarmPath(directory, "events.jsonl");
12320
12239
  const markerMaybe = await _internals16.readFileText(markerPath);
12321
12240
  if (markerMaybe === null) {
12322
12241
  return {
@@ -12463,7 +12382,7 @@ async function reconcileSpecDrift(directory, options) {
12463
12382
  previousHash: wal.previousHash,
12464
12383
  transitionId
12465
12384
  });
12466
- await _internals16.appendEvent(eventsPath, event);
12385
+ await _internals16.appendEvent(directory, event);
12467
12386
  await _internals16.writeWal(walPath2, { ...wal, state: "COMMITTED" });
12468
12387
  }
12469
12388
  if (markerReplacedDuringPrepared) {
@@ -12888,7 +12807,7 @@ import * as path14 from "path";
12888
12807
 
12889
12808
  // src/evaluation/gate-ground-truth.ts
12890
12809
  init_zod();
12891
- import { mkdir as mkdir6, readFile as readFile7 } from "fs/promises";
12810
+ import { mkdir as mkdir5, readFile as readFile6 } from "fs/promises";
12892
12811
  import * as path13 from "path";
12893
12812
  var GateGroundTruthV1Schema = exports_external.object({
12894
12813
  v: exports_external.literal(1),
@@ -12941,11 +12860,11 @@ async function saveGateGroundTruth(directory, runId, input) {
12941
12860
  }
12942
12861
  const target = absolutePath(directory, runId);
12943
12862
  assertProjectRoot(directory);
12944
- await mkdir6(path13.dirname(target), { recursive: true });
12863
+ await mkdir5(path13.dirname(target), { recursive: true });
12945
12864
  return withEvidenceLock(directory, relativePath(runId), "gate-ground-truth", runId, async () => {
12946
12865
  let existingEvents = [];
12947
12866
  try {
12948
- existingEvents = parseStrict(await readFile7(target, "utf8"));
12867
+ existingEvents = parseStrict(await readFile6(target, "utf8"));
12949
12868
  } catch (error2) {
12950
12869
  if (error2.code !== "ENOENT")
12951
12870
  throw error2;
@@ -12974,7 +12893,7 @@ async function recordTestImpactGateGroundTruth(directory, runId, input) {
12974
12893
  async function readGateGroundTruth(directory, runId) {
12975
12894
  let content;
12976
12895
  try {
12977
- content = await readFile7(absolutePath(directory, runId), "utf8");
12896
+ content = await readFile6(absolutePath(directory, runId), "utf8");
12978
12897
  } catch (error2) {
12979
12898
  if (error2.code === "ENOENT") {
12980
12899
  return { events: [], malformed: 0 };
@@ -14115,13 +14034,10 @@ function writeCheckpointLog(log2, directory) {
14115
14034
  }
14116
14035
  function appendRetentionEvent(directory, event) {
14117
14036
  try {
14118
- const eventsPath = path17.join(directory, ".swarm", "events.jsonl");
14119
- const line = `${JSON.stringify({
14037
+ appendCoreEventSync(directory, {
14120
14038
  ...event,
14121
14039
  timestamp: new Date().toISOString()
14122
- })}
14123
- `;
14124
- fs10.appendFileSync(eventsPath, line);
14040
+ });
14125
14041
  } catch {}
14126
14042
  }
14127
14043
  function loadCheckpointConfig(directory) {
@@ -17295,7 +17211,7 @@ function formatLearningSummary(metrics) {
17295
17211
  }
17296
17212
 
17297
17213
  // src/services/recommendation-ledger.ts
17298
- import { readFile as readFile8 } from "fs/promises";
17214
+ import { readFile as readFile7 } from "fs/promises";
17299
17215
  import * as path20 from "path";
17300
17216
 
17301
17217
  // src/learning/fingerprint.ts
@@ -17458,7 +17374,7 @@ function parseLedgerJsonl(content) {
17458
17374
  }
17459
17375
  async function readLedgerForTransaction(filePath) {
17460
17376
  try {
17461
- return parseLedgerJsonl(await readFile8(filePath, "utf-8"));
17377
+ return parseLedgerJsonl(await readFile7(filePath, "utf-8"));
17462
17378
  } catch (err) {
17463
17379
  if (err?.code === "ENOENT")
17464
17380
  return [];
@@ -17468,7 +17384,7 @@ async function readLedgerForTransaction(filePath) {
17468
17384
  async function readLedgerStrict(directory) {
17469
17385
  const filePath = _internals23.resolveRecommendationLedgerPath(directory);
17470
17386
  try {
17471
- return parseLedgerJsonl(await readFile8(filePath, "utf-8"));
17387
+ return parseLedgerJsonl(await readFile7(filePath, "utf-8"));
17472
17388
  } catch (err) {
17473
17389
  if (err?.code === "ENOENT")
17474
17390
  return [];
@@ -17747,13 +17663,13 @@ function buildPromotedExternalInputFromSkill(directory, skillSlug, usage, ageDay
17747
17663
 
17748
17664
  // src/services/skill-reviser.ts
17749
17665
  init_logger();
17750
- import { readFile as readFile9, rename as rename3, writeFile as writeFile5 } from "fs/promises";
17666
+ import { readFile as readFile8, rename as rename3, writeFile as writeFile5 } from "fs/promises";
17751
17667
  var REVISION_VIOLATION_THRESHOLD = 0.15;
17752
17668
  var MAX_REVISION_CALLS_PER_PHASE = 3;
17753
17669
  var DEFAULT_MAX_CALLS = 10;
17754
17670
  async function getSkillVersion(skillPath) {
17755
17671
  try {
17756
- const content = await readFile9(skillPath, "utf-8");
17672
+ const content = await readFile8(skillPath, "utf-8");
17757
17673
  const match = content.match(/^version:\s*(\d+)\s*$/m);
17758
17674
  return match ? parseInt(match[1], 10) : 1;
17759
17675
  } catch {
@@ -18386,7 +18302,7 @@ function planMerges(active, threshold, maxComparisons, maxMerges) {
18386
18302
  };
18387
18303
  }
18388
18304
  async function sweepActiveNearDuplicates(directory, options = {}) {
18389
- const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-qbsc2btq.js");
18305
+ const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-hbhw2qd7.js");
18390
18306
  const { config } = loadPluginConfigWithMeta2(directory);
18391
18307
  const sweepConfig = config.learning?.dedup_sweep;
18392
18308
  if (sweepConfig?.enabled === false)
@@ -19347,8 +19263,19 @@ async function runCuratorPhase(directory, phase, agentsDispatched, config, knowl
19347
19263
  already_digested: true
19348
19264
  };
19349
19265
  }
19350
- const eventsJsonlContent = await readSwarmFileAsync(directory, "events.jsonl");
19351
- const phaseEvents = eventsJsonlContent ? _internals25.filterPhaseEvents(eventsJsonlContent, phase) : [];
19266
+ const eventsWindow = readCoreEvents(directory);
19267
+ const phaseEvents = eventsWindow.text.length > 0 ? _internals25.filterPhaseEvents(eventsWindow.text, phase) : [];
19268
+ if (eventsWindow.coverage === "truncated") {
19269
+ try {
19270
+ appendCoreEventSync(directory, {
19271
+ timestamp: new Date().toISOString(),
19272
+ event: "curator_skipped",
19273
+ scope: "phase_digest",
19274
+ phase,
19275
+ reason: "events_window_truncated"
19276
+ });
19277
+ } catch {}
19278
+ }
19352
19279
  const contextMd = await readSwarmFileAsync(directory, "context.md");
19353
19280
  const requiredAgents = ["reviewer", "test_engineer"];
19354
19281
  const complianceObservations = _internals25.checkPhaseCompliance(phaseEvents, agentsDispatched, requiredAgents, phase);
@@ -19491,20 +19418,21 @@ async function runCuratorPhase(directory, phase, agentsDispatched, config, knowl
19491
19418
  warn(`[curator] failed to persist application findings: ${err instanceof Error ? err.message : String(err)}`);
19492
19419
  }
19493
19420
  }
19494
- const eventsPath = path23.join(directory, ".swarm", "events.jsonl");
19495
- for (const obs of complianceObservations) {
19496
- await appendKnowledge(eventsPath, {
19421
+ try {
19422
+ appendCoreEventsSync(directory, complianceObservations.map((obs) => ({
19497
19423
  type: "curator_compliance",
19498
19424
  timestamp: obs.timestamp,
19499
19425
  phase: obs.phase,
19500
19426
  observation_type: obs.type,
19501
19427
  severity: obs.severity,
19502
19428
  description: obs.description
19503
- });
19429
+ })));
19430
+ } catch (err) {
19431
+ warn(`[curator] failed to append compliance events: ${err instanceof Error ? err.message : String(err)}`);
19504
19432
  }
19505
19433
  if (config.skill_generation_enabled === true && skillCandidates.length > 0) {
19506
19434
  try {
19507
- const skillModule = await import("./skill-generator-c65y1h6a.js");
19435
+ const skillModule = await import("./skill-generator-esrn40th.js");
19508
19436
  for (const cand of skillCandidates) {
19509
19437
  if (cand.confidence < (config.min_skill_confidence ?? DEFAULT_SKILL_MIN_CONFIDENCE)) {
19510
19438
  continue;
@@ -19976,7 +19904,7 @@ async function applyCuratorKnowledgeUpdates(directory, recommendations, knowledg
19976
19904
  } catch {}
19977
19905
  }
19978
19906
  if (contradictedEntries.length > 0 && knowledgeConfig.contradiction_threshold_action === "quarantine") {
19979
- const { maybeQuarantineOnContradiction } = await import("./knowledge-escalator-bvrtfdyb.js");
19907
+ const { maybeQuarantineOnContradiction } = await import("./knowledge-escalator-ty2kesdj.js");
19980
19908
  for (const { id } of contradictedEntries) {
19981
19909
  try {
19982
19910
  await maybeQuarantineOnContradiction(directory, id, knowledgeConfig.contradiction_quarantine_threshold, knowledgeConfig.contradiction_quarantine_window_days);
@@ -20795,7 +20723,7 @@ async function runCuratorPostMortem(directory, options = {}) {
20795
20723
  warnings.push("Failed to collect knowledge summary.");
20796
20724
  }
20797
20725
  try {
20798
- const { getScanStatus } = await import("./scan-cursor-7n0zs72g.js");
20726
+ const { getScanStatus } = await import("./scan-cursor-3ba1spad.js");
20799
20727
  const scanStatus = await getScanStatus(directory);
20800
20728
  if (scanStatus.remaining_estimate > 0) {
20801
20729
  warnings.push(`Fair scan: reviewed ${knowledgeSummary.length} entries this sweep (generation ${scanStatus.generation}); ${scanStatus.remaining_estimate} more eligible entries will be visited in future curation sweeps.`);
@@ -20967,9 +20895,9 @@ var _internals26 = {
20967
20895
  verifyPostMortemKnowledgeActions,
20968
20896
  repairPostMortemActions,
20969
20897
  loadDefaultKnowledgeConfig: async (directory) => {
20970
- const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-e59spg93.js");
20898
+ const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-h251vmd1.js");
20971
20899
  try {
20972
- const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-qbsc2btq.js");
20900
+ const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-hbhw2qd7.js");
20973
20901
  const loaded = loadPluginConfigWithMeta2(directory);
20974
20902
  return KnowledgeConfigSchema2.parse(loaded.config.knowledge ?? {});
20975
20903
  } catch {
@@ -20977,11 +20905,11 @@ var _internals26 = {
20977
20905
  }
20978
20906
  },
20979
20907
  applyCuratorKnowledgeUpdates: async (directory, recommendations, knowledgeConfig, generation) => {
20980
- const { applyCuratorKnowledgeUpdates: applyCuratorKnowledgeUpdates2 } = await import("./curator-pffqw3br.js");
20908
+ const { applyCuratorKnowledgeUpdates: applyCuratorKnowledgeUpdates2 } = await import("./curator-6w4frzdz.js");
20981
20909
  return applyCuratorKnowledgeUpdates2(directory, recommendations, knowledgeConfig, generation);
20982
20910
  },
20983
20911
  checkHivePromotions: async (entries, knowledgeConfig, directory) => {
20984
- const { checkHivePromotions } = await import("./hive-promoter-jvyzykgx.js");
20912
+ const { checkHivePromotions } = await import("./hive-promoter-32artf8c.js");
20985
20913
  return checkHivePromotions(entries, knowledgeConfig, directory);
20986
20914
  },
20987
20915
  applyProposalTriage: async (directory, triage) => {
@@ -20990,7 +20918,7 @@ var _internals26 = {
20990
20918
  activateProposal,
20991
20919
  listSkills: listSkills2,
20992
20920
  sanitizeSlug
20993
- } = await import("./skill-generator-c65y1h6a.js");
20921
+ } = await import("./skill-generator-esrn40th.js");
20994
20922
  const result = {
20995
20923
  approved: [],
20996
20924
  rejected: [],
@@ -21032,7 +20960,7 @@ var _internals26 = {
21032
20960
  return result;
21033
20961
  },
21034
20962
  readPriorDriftReports: async (directory) => {
21035
- const { readPriorDriftReports } = await import("./curator-drift-fv4rttf4.js");
20963
+ const { readPriorDriftReports } = await import("./curator-drift-2h1d2fnq.js");
21036
20964
  return readPriorDriftReports(directory);
21037
20965
  },
21038
20966
  readSwarmKnowledge: (directory) => readKnowledge(resolveSwarmKnowledgePath(directory))
@@ -21172,7 +21100,7 @@ function failedGateNames(decision) {
21172
21100
 
21173
21101
  // src/hooks/hive-transaction.ts
21174
21102
  var import_proper_lockfile4 = __toESM(require_proper_lockfile(), 1);
21175
- import { appendFile as appendFile6, mkdir as mkdir8, realpath as realpath2 } from "fs/promises";
21103
+ import { appendFile as appendFile2, mkdir as mkdir7, realpath as realpath2 } from "fs/promises";
21176
21104
  import * as path25 from "path";
21177
21105
  init_logger();
21178
21106
  var HIVE_LOCK_STALE_MS = 5000;
@@ -21197,7 +21125,7 @@ async function transactHiveStore(mutate) {
21197
21125
  const eventsPath = _internals27.resolveHiveEventsPath();
21198
21126
  const diagnostics = [];
21199
21127
  try {
21200
- await mkdir8(dataDir, { recursive: true });
21128
+ await mkdir7(dataDir, { recursive: true });
21201
21129
  } catch (err) {
21202
21130
  diagnostics.push(`hive data dir create failed: ${err instanceof Error ? err.message : String(err)}`);
21203
21131
  return { committed: false, return: undefined, diagnostics };
@@ -21250,13 +21178,13 @@ async function transactHiveStore(mutate) {
21250
21178
  const rejectBlock = `${outcome.rejects.map((r) => JSON.stringify(r)).join(`
21251
21179
  `)}
21252
21180
  `;
21253
- await appendFile6(rejectedPath, rejectBlock, "utf-8");
21181
+ await appendFile2(rejectedPath, rejectBlock, "utf-8");
21254
21182
  }
21255
21183
  if (outcome.audit && outcome.audit.length > 0) {
21256
21184
  const auditBlock = `${outcome.audit.map((a) => a.line).join(`
21257
21185
  `)}
21258
21186
  `;
21259
- await appendFile6(eventsPath, auditBlock, "utf-8");
21187
+ await appendFile2(eventsPath, auditBlock, "utf-8");
21260
21188
  try {
21261
21189
  await trimHiveEventsUnderLock(eventsPath);
21262
21190
  } catch (err) {
@@ -21316,11 +21244,11 @@ async function realpathQuiet(target) {
21316
21244
  }
21317
21245
  }
21318
21246
  async function trimHiveEventsUnderLock(eventsPath) {
21319
- const { readFile: readFile10 } = await import("fs/promises");
21247
+ const { readFile: readFile9 } = await import("fs/promises");
21320
21248
  const { existsSync: existsSync15 } = await import("fs");
21321
21249
  if (!existsSync15(eventsPath))
21322
21250
  return;
21323
- const content = await readFile10(eventsPath, "utf-8");
21251
+ const content = await readFile9(eventsPath, "utf-8");
21324
21252
  const lines = content.split(`
21325
21253
  `).filter((l) => l.trim().length > 0);
21326
21254
  if (lines.length <= MAX_EVENT_LOG_ENTRIES)
@@ -21339,7 +21267,7 @@ var _internals27 = {
21339
21267
  resolveHiveKnowledgePath,
21340
21268
  resolveHiveRejectedPath,
21341
21269
  resolveHiveEventsPath,
21342
- appendFile: appendFile6,
21270
+ appendFile: appendFile2,
21343
21271
  path: path25
21344
21272
  };
21345
21273
 
@@ -22087,20 +22015,14 @@ async function promoteFromSwarm(directory, lessonId, options, config) {
22087
22015
  // src/hooks/knowledge-curator.ts
22088
22016
  import { createHash as createHash10 } from "crypto";
22089
22017
  import { existsSync as existsSync15 } from "fs";
22090
- import {
22091
- appendFile as appendFile7,
22092
- mkdir as mkdir10,
22093
- readFile as readFile11,
22094
- realpath as realpath3,
22095
- writeFile as writeFile7
22096
- } from "fs/promises";
22018
+ import { readFile as readFile10, realpath as realpath3, writeFile as writeFile7 } from "fs/promises";
22097
22019
  import * as path28 from "path";
22098
22020
 
22099
22021
  // src/services/synonym-map.ts
22100
22022
  var import_proper_lockfile5 = __toESM(require_proper_lockfile(), 1);
22101
22023
  import {
22102
- mkdir as mkdir9,
22103
- readFile as readFile10,
22024
+ mkdir as mkdir8,
22025
+ readFile as readFile9,
22104
22026
  rename as rename4,
22105
22027
  stat as stat3,
22106
22028
  unlink as unlink3,
@@ -22254,14 +22176,14 @@ async function readSynonymMap(directory, maxPairs = DEFAULT_MAX_PAIRS) {
22254
22176
  const st = await stat3(filePath);
22255
22177
  if (st.size > ceiling)
22256
22178
  return emptySynonymMap();
22257
- const raw = await readFile10(filePath, "utf-8");
22179
+ const raw = await readFile9(filePath, "utf-8");
22258
22180
  return coerceSynonymMap(JSON.parse(raw), maxPairs);
22259
22181
  } catch {
22260
22182
  return emptySynonymMap();
22261
22183
  }
22262
22184
  }
22263
22185
  async function writeSynonymMapAtomic(filePath, map) {
22264
- await mkdir9(path27.dirname(filePath), { recursive: true });
22186
+ await mkdir8(path27.dirname(filePath), { recursive: true });
22265
22187
  const tmp = `${filePath}.tmp.${Date.now()}.${Math.floor(Math.random() * 1e9)}`;
22266
22188
  try {
22267
22189
  await writeFile6(tmp, JSON.stringify(map, null, 2), "utf-8");
@@ -22275,7 +22197,7 @@ async function writeSynonymMapAtomic(filePath, map) {
22275
22197
  async function rebuildSynonymMap(directory, entries, maxPairs = DEFAULT_MAX_PAIRS) {
22276
22198
  const filePath = resolveSynonymMapPath(directory);
22277
22199
  const dir = path27.dirname(filePath);
22278
- await mkdir9(dir, { recursive: true });
22200
+ await mkdir8(dir, { recursive: true });
22279
22201
  let release = null;
22280
22202
  try {
22281
22203
  release = await import_proper_lockfile5.default.lock(dir, {
@@ -22326,9 +22248,9 @@ function hashContent(content) {
22326
22248
  return createHash10("sha1").update(content).digest("hex");
22327
22249
  }
22328
22250
  async function loadConfigForPolicyCurator(directory) {
22329
- const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-e59spg93.js");
22251
+ const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-h251vmd1.js");
22330
22252
  try {
22331
- const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-qbsc2btq.js");
22253
+ const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-hbhw2qd7.js");
22332
22254
  const { config: loadedConfig } = loadPluginConfigWithMeta2(directory);
22333
22255
  return KnowledgeConfigSchema2.parse(loadedConfig.knowledge ?? {});
22334
22256
  } catch {
@@ -22806,16 +22728,13 @@ RETRY: your last output was missing ${result.missing.join("; ")}; produce valid
22806
22728
  }
22807
22729
  async function appendCuratorSkippedEvent(directory, record) {
22808
22730
  try {
22809
- const filePath = path28.join(directory, ".swarm", "events.jsonl");
22810
- await mkdir10(path28.dirname(filePath), { recursive: true });
22811
- await appendFile7(filePath, `${JSON.stringify({
22731
+ appendCoreEventSync(directory, {
22812
22732
  timestamp: new Date().toISOString(),
22813
22733
  event: "curator_skipped",
22814
22734
  entry_id: record.entry_id,
22815
22735
  lesson: record.lesson.slice(0, 200),
22816
22736
  reason: record.reason
22817
- })}
22818
- `, "utf-8");
22737
+ });
22819
22738
  } catch {}
22820
22739
  }
22821
22740
  var MESO_INSIGHT_BATCH_LIMIT = 20;
@@ -22850,7 +22769,7 @@ async function consumeInsightCandidates(directory, batchLimit = MESO_INSIGHT_BAT
22850
22769
  if (!existsSync15(filePath))
22851
22770
  return [];
22852
22771
  const consumed = [];
22853
- await transactFile(filePath, async (p) => readInsightJsonl2(await readFile11(p, "utf-8").catch(() => "")), async (p, data) => {
22772
+ await transactFile(filePath, async (p) => readInsightJsonl2(await readFile10(p, "utf-8").catch(() => "")), async (p, data) => {
22854
22773
  const body = data.length === 0 ? "" : `${data.map((c) => JSON.stringify(c)).join(`
22855
22774
  `)}
22856
22775
  `;
@@ -24707,9 +24626,9 @@ var import_proper_lockfile6 = __toESM(require_proper_lockfile(), 1);
24707
24626
  import { randomUUID as randomUUID6 } from "crypto";
24708
24627
  import { existsSync as existsSync17, readFileSync as readFileSync14, writeFileSync as writeFileSync8 } from "fs";
24709
24628
  import {
24710
- appendFile as appendFile8,
24711
- mkdir as mkdir11,
24712
- readFile as readFile12,
24629
+ appendFile as appendFile3,
24630
+ mkdir as mkdir9,
24631
+ readFile as readFile11,
24713
24632
  rename as rename5,
24714
24633
  truncate,
24715
24634
  writeFile as writeFile8
@@ -25876,7 +25795,7 @@ class LocalJsonlMemoryProvider {
25876
25795
  }
25877
25796
  async withOutcomeStoreLock(fn) {
25878
25797
  const storageDirectory = path31.dirname(this.pathFor("memories"));
25879
- await mkdir11(storageDirectory, { recursive: true });
25798
+ await mkdir9(storageDirectory, { recursive: true });
25880
25799
  const release = await lockfile6.lock(storageDirectory, {
25881
25800
  realpath: false,
25882
25801
  stale: 1e4,
@@ -26079,7 +25998,7 @@ function validateLoadedProposals(values, config) {
26079
25998
  async function readJsonl(filePath) {
26080
25999
  if (!existsSync17(filePath))
26081
26000
  return [];
26082
- const content = await readFile12(filePath, "utf-8");
26001
+ const content = await readFile11(filePath, "utf-8");
26083
26002
  const records = [];
26084
26003
  for (const line of content.split(`
26085
26004
  `)) {
@@ -26154,12 +26073,12 @@ function parseRewardEvent(value) {
26154
26073
  };
26155
26074
  }
26156
26075
  async function appendJsonl(filePath, value) {
26157
- await mkdir11(path31.dirname(filePath), { recursive: true });
26158
- await appendFile8(filePath, `${JSON.stringify(value)}
26076
+ await mkdir9(path31.dirname(filePath), { recursive: true });
26077
+ await appendFile3(filePath, `${JSON.stringify(value)}
26159
26078
  `, "utf-8");
26160
26079
  }
26161
26080
  async function writeJsonlAtomic(filePath, values) {
26162
- await mkdir11(path31.dirname(filePath), { recursive: true });
26081
+ await mkdir9(path31.dirname(filePath), { recursive: true });
26163
26082
  const tmp = `${filePath}.tmp.${randomUUID6()}`;
26164
26083
  const content = values.map((value) => JSON.stringify(value)).join(`
26165
26084
  `) + (values.length > 0 ? `
@@ -26170,7 +26089,7 @@ async function writeJsonlAtomic(filePath, values) {
26170
26089
  async function repairIncompleteJsonlTail(filePath) {
26171
26090
  if (!existsSync17(filePath))
26172
26091
  return;
26173
- const content = await readFile12(filePath, "utf-8");
26092
+ const content = await readFile11(filePath, "utf-8");
26174
26093
  if (content.length === 0 || content.endsWith(`
26175
26094
  `))
26176
26095
  return;
@@ -26551,7 +26470,7 @@ function resolveRerankerCacheDir() {
26551
26470
 
26552
26471
  // src/memory/jsonl-migration.ts
26553
26472
  import { existsSync as existsSync18, renameSync as renameSync7, unlinkSync as unlinkSync6 } from "fs";
26554
- import { copyFile, mkdir as mkdir12, readFile as readFile13, stat as stat4, writeFile as writeFile9 } from "fs/promises";
26473
+ import { copyFile, mkdir as mkdir10, readFile as readFile12, stat as stat4, writeFile as writeFile9 } from "fs/promises";
26555
26474
  import * as path34 from "path";
26556
26475
  var LEGACY_JSONL_MIGRATION_VERSION = 2;
26557
26476
  var LEGACY_JSONL_MIGRATION_NAME = "legacy_jsonl_import_complete";
@@ -26589,7 +26508,7 @@ async function readLegacyJsonl(rootDirectory, config = {}) {
26589
26508
  async function backupLegacyJsonl(rootDirectory, config = {}) {
26590
26509
  const storageDir = resolveMemoryStorageDir(rootDirectory, config);
26591
26510
  const backupDir = path34.join(storageDir, "backups");
26592
- await mkdir12(backupDir, { recursive: true });
26511
+ await mkdir10(backupDir, { recursive: true });
26593
26512
  const results = [];
26594
26513
  for (const filename of [
26595
26514
  "memories.jsonl",
@@ -26611,7 +26530,7 @@ async function backupLegacyJsonl(rootDirectory, config = {}) {
26611
26530
  }
26612
26531
  async function writeJsonlExport(rootDirectory, config, memories, proposals, outcomeEvents = []) {
26613
26532
  const exportDir = path34.join(resolveMemoryStorageDir(rootDirectory, config), "export");
26614
- await mkdir12(exportDir, { recursive: true });
26533
+ await mkdir10(exportDir, { recursive: true });
26615
26534
  const memoriesPath = path34.join(exportDir, "memories.jsonl");
26616
26535
  const proposalsPath = path34.join(exportDir, "proposals.jsonl");
26617
26536
  const outcomesPath = path34.join(exportDir, "outcome-events.jsonl");
@@ -26649,7 +26568,7 @@ async function writeJsonlExport(rootDirectory, config, memories, proposals, outc
26649
26568
  }
26650
26569
  async function writeMigrationReport(rootDirectory, report, config = {}) {
26651
26570
  const reportPath = path34.join(resolveMemoryStorageDir(rootDirectory, config), "migration-report.json");
26652
- await mkdir12(path34.dirname(reportPath), { recursive: true });
26571
+ await mkdir10(path34.dirname(reportPath), { recursive: true });
26653
26572
  const reportTempPath = path34.join(path34.dirname(reportPath), `${path34.basename(reportPath)}.tmp.${Date.now()}.${Math.floor(Math.random() * 1e9)}`);
26654
26573
  try {
26655
26574
  await writeFile9(reportTempPath, `${JSON.stringify(report, null, 2)}
@@ -26668,7 +26587,7 @@ async function readMigrationReport(rootDirectory, config = {}) {
26668
26587
  if (!existsSync18(reportPath))
26669
26588
  return null;
26670
26589
  try {
26671
- return JSON.parse(await readFile13(reportPath, "utf-8"));
26590
+ return JSON.parse(await readFile12(reportPath, "utf-8"));
26672
26591
  } catch {
26673
26592
  return null;
26674
26593
  }
@@ -26822,7 +26741,7 @@ async function readJsonlRows(filePath) {
26822
26741
  if (!existsSync18(filePath)) {
26823
26742
  return { rows: [], invalidRows: [], totalRows: 0 };
26824
26743
  }
26825
- const content = await readFile13(filePath, "utf-8");
26744
+ const content = await readFile12(filePath, "utf-8");
26826
26745
  const rows = [];
26827
26746
  const invalidRows = [];
26828
26747
  let totalRows = 0;
@@ -30106,7 +30025,10 @@ async function gatherLedgerRejections(directory, sessionId) {
30106
30025
  }
30107
30026
  return readLedger(target);
30108
30027
  };
30109
- let content = await readLedger(path39.join(directory, ".swarm", "events.jsonl"));
30028
+ let content = readCoreEvents(directory).text;
30029
+ if (content === "") {
30030
+ content = null;
30031
+ }
30110
30032
  if (content === null) {
30111
30033
  try {
30112
30034
  const archiveRoot = path39.join(directory, ".swarm", "archive");
@@ -30126,6 +30048,8 @@ async function gatherLedgerRejections(directory, sessionId) {
30126
30048
  continue;
30127
30049
  try {
30128
30050
  const parsed = JSON.parse(trimmed);
30051
+ if (parsed.type === "swarm-events-manifest")
30052
+ continue;
30129
30053
  if (typeof parsed.type === "string" && REJECTION_LEDGER_EVENT_TYPES.has(parsed.type)) {
30130
30054
  if (sessionId !== undefined) {
30131
30055
  const eventSession = typeof parsed.sessionId === "string" ? parsed.sessionId : typeof parsed.sessionID === "string" ? parsed.sessionID : undefined;
@@ -30652,12 +30576,12 @@ var _internals35 = {
30652
30576
 
30653
30577
  // src/services/skill-improver.ts
30654
30578
  import { existsSync as existsSync22 } from "fs";
30655
- import { mkdir as mkdir14, readFile as readFile14 } from "fs/promises";
30579
+ import { mkdir as mkdir12, readFile as readFile13 } from "fs/promises";
30656
30580
  import * as path41 from "path";
30657
30581
  init_logger();
30658
30582
 
30659
30583
  // src/services/trajectory-cluster.ts
30660
- import { mkdir as mkdir13, writeFile as writeFile10 } from "fs/promises";
30584
+ import { mkdir as mkdir11, writeFile as writeFile10 } from "fs/promises";
30661
30585
  import * as path40 from "path";
30662
30586
  init_logger();
30663
30587
  var MACRO_TRAJECTORY_WINDOW = 200;
@@ -30826,7 +30750,7 @@ async function writeMotifProposals(directory, opts = {}) {
30826
30750
  if (emitted.length === 0)
30827
30751
  return result;
30828
30752
  const proposalsDir = validateSwarmPath(directory, path40.join("skills", "proposals"));
30829
- await mkdir13(proposalsDir, { recursive: true });
30753
+ await mkdir11(proposalsDir, { recursive: true });
30830
30754
  const written = [];
30831
30755
  for (const decision of emitted) {
30832
30756
  const motif = selected[decision.index];
@@ -31016,7 +30940,7 @@ async function writeSuccessMotifProposals(directory, opts = {}) {
31016
30940
  if (emitted.length === 0)
31017
30941
  return result;
31018
30942
  const proposalsDir = validateSwarmPath(directory, path40.join("skills", "proposals"));
31019
- await mkdir13(proposalsDir, { recursive: true });
30943
+ await mkdir11(proposalsDir, { recursive: true });
31020
30944
  const written = [];
31021
30945
  for (const decision of emitted) {
31022
30946
  const motif = selected[decision.index];
@@ -31159,7 +31083,7 @@ function timestampSlug(d) {
31159
31083
  return d.toISOString().replace(/[:.]/g, "-");
31160
31084
  }
31161
31085
  async function atomicWrite(p, content) {
31162
- await mkdir14(path41.dirname(p), { recursive: true });
31086
+ await mkdir12(path41.dirname(p), { recursive: true });
31163
31087
  await atomicWriteSwarmFile(p, content);
31164
31088
  }
31165
31089
  async function gatherInventory(directory) {
@@ -31174,7 +31098,7 @@ async function gatherInventory(directory) {
31174
31098
  for (const skill of skills.active) {
31175
31099
  let content;
31176
31100
  try {
31177
- content = await readFile14(skill.path, "utf-8");
31101
+ content = await readFile13(skill.path, "utf-8");
31178
31102
  } catch {
31179
31103
  continue;
31180
31104
  }
@@ -31350,7 +31274,7 @@ async function reconcileStaleActiveSkills(directory, options = {}) {
31350
31274
  for (const skill of skills.active) {
31351
31275
  let content;
31352
31276
  try {
31353
- content = await readFile14(skill.path, "utf-8");
31277
+ content = await readFile13(skill.path, "utf-8");
31354
31278
  } catch {
31355
31279
  continue;
31356
31280
  }
@@ -33094,6 +33018,7 @@ var ARCHIVE_ARTIFACTS = [
33094
33018
  "plan-ledger.jsonl",
33095
33019
  "context.md",
33096
33020
  "events.jsonl",
33021
+ "events-authority-index.json",
33097
33022
  "handoff.md",
33098
33023
  "handoff-prompt.md",
33099
33024
  "handoff-consumed.md",
@@ -33127,6 +33052,7 @@ var ACTIVE_STATE_TO_CLEAN = [
33127
33052
  "plan.md",
33128
33053
  "plan-ledger.jsonl",
33129
33054
  "events.jsonl",
33055
+ "events-authority-index.json",
33130
33056
  "handoff.md",
33131
33057
  "handoff-prompt.md",
33132
33058
  "handoff-consumed.md",
@@ -33524,7 +33450,7 @@ async function runFinalizeStage(ctx) {
33524
33450
  }
33525
33451
  }
33526
33452
  try {
33527
- const { CuratorConfigSchema: CCS } = await import("./schema-e59spg93.js");
33453
+ const { CuratorConfigSchema: CCS } = await import("./schema-h251vmd1.js");
33528
33454
  const { config: pmLoadedConfig } = _internals41.loadPluginConfigWithMeta(ctx.directory);
33529
33455
  const curatorCfg = CCS.parse(pmLoadedConfig.curator ?? {});
33530
33456
  if (curatorCfg.enabled && curatorCfg.postmortem_enabled) {
@@ -33563,6 +33489,12 @@ async function runArchiveStage(ctx) {
33563
33489
  const msg = finalizeErr instanceof Error ? finalizeErr.message : String(finalizeErr);
33564
33490
  ctx.warnings.push(`Context-map telemetry finalize before archive failed: ${msg}`);
33565
33491
  }
33492
+ try {
33493
+ _internals41.finalizeCoreEvents(ctx.directory);
33494
+ } catch (finalizeErr) {
33495
+ const msg = finalizeErr instanceof Error ? finalizeErr.message : String(finalizeErr);
33496
+ ctx.warnings.push(`Core events finalize before archive failed: ${msg}`);
33497
+ }
33566
33498
  const linkedKnowledgeShared = isLinked(ctx.directory);
33567
33499
  if (linkedKnowledgeShared) {
33568
33500
  ctx.warnings.push("Worktree is linked: shared knowledge (knowledge.jsonl, knowledge-rejected.jsonl) lives in the link store and is not archived or cleaned by /swarm close. Manage it via the link.");
@@ -34388,11 +34320,14 @@ var _internals41 = {
34388
34320
  closePlanTerminalState: reconcileCloseTerminalStateForPlan,
34389
34321
  endAgentSession,
34390
34322
  flushAndDrainTelemetry: async () => {
34391
- const { flushAndDrainTelemetry } = await import("./telemetry-1pnsftp0.js");
34323
+ const { flushAndDrainTelemetry } = await import("./telemetry-jtq6px7k.js");
34392
34324
  return flushAndDrainTelemetry();
34393
34325
  },
34394
34326
  finalizeContextTelemetry: (directory) => {
34395
34327
  finalizeContextTelemetry(directory);
34328
+ },
34329
+ finalizeCoreEvents: (directory) => {
34330
+ finalizeCoreEventsForClose(directory);
34396
34331
  }
34397
34332
  };
34398
34333
 
@@ -34657,7 +34592,7 @@ init_schema();
34657
34592
 
34658
34593
  // src/services/skill-consolidation.ts
34659
34594
  import { existsSync as existsSync28 } from "fs";
34660
- import { mkdir as mkdir15, readFile as readFile15 } from "fs/promises";
34595
+ import { mkdir as mkdir13, readFile as readFile14 } from "fs/promises";
34661
34596
  import * as path48 from "path";
34662
34597
  var DEFAULT_CONSOLIDATION_INTERVAL_HOURS = 24;
34663
34598
  var DEFAULT_CONSOLIDATION_MAX_CALLS_PER_RUN = 1;
@@ -34671,7 +34606,7 @@ async function readState2(directory) {
34671
34606
  if (!existsSync28(filePath))
34672
34607
  return {};
34673
34608
  try {
34674
- const parsed = JSON.parse(await readFile15(filePath, "utf-8"));
34609
+ const parsed = JSON.parse(await readFile14(filePath, "utf-8"));
34675
34610
  if (!parsed || typeof parsed !== "object")
34676
34611
  return {};
34677
34612
  return parsed;
@@ -34680,7 +34615,7 @@ async function readState2(directory) {
34680
34615
  }
34681
34616
  }
34682
34617
  async function atomicWrite2(filePath, content) {
34683
- await mkdir15(path48.dirname(filePath), { recursive: true });
34618
+ await mkdir13(path48.dirname(filePath), { recursive: true });
34684
34619
  await atomicWriteSwarmFile(filePath, content);
34685
34620
  }
34686
34621
  async function writeState2(directory, state) {
@@ -35006,7 +34941,7 @@ import { promisify as promisify2 } from "util";
35006
34941
  init_zod();
35007
34942
  import * as child_process3 from "child_process";
35008
34943
  import { randomUUID as randomUUID8 } from "crypto";
35009
- import { readdir as readdir4, readFile as readFile16, stat as stat5 } from "fs/promises";
34944
+ import { readdir as readdir4, readFile as readFile15, stat as stat5 } from "fs/promises";
35010
34945
  import * as path49 from "path";
35011
34946
  import { promisify } from "util";
35012
34947
  function getExecFileAsync() {
@@ -35133,7 +35068,7 @@ async function getStaticEdges(directory) {
35133
35068
  const sourceFiles = await scanSourceFiles(directory);
35134
35069
  for (const sourceFile of sourceFiles) {
35135
35070
  try {
35136
- const content = await readFile16(sourceFile, "utf-8");
35071
+ const content = await readFile15(sourceFile, "utf-8");
35137
35072
  const importRegex = /(?:import|require)\s*(?:\(?\s*['"`]|.*?from\s+['"`])([^'"`]+)['"`]/g;
35138
35073
  for (let match = importRegex.exec(content);match !== null; match = importRegex.exec(content)) {
35139
35074
  const importPath = match[1].trim();
@@ -35717,9 +35652,9 @@ var _internals45 = {
35717
35652
  loadPluginConfigWithMeta,
35718
35653
  loadCuratorDeps: async () => {
35719
35654
  const [{ CuratorConfigSchema }, curator, { createCuratorLLMDelegate: createCuratorLLMDelegate2 }] = await Promise.all([
35720
- import("./schema-e59spg93.js"),
35721
- import("./curator-pffqw3br.js"),
35722
- import("./curator-llm-factory-mbsn281q.js")
35655
+ import("./schema-h251vmd1.js"),
35656
+ import("./curator-6w4frzdz.js"),
35657
+ import("./curator-llm-factory-8fstpeqh.js")
35723
35658
  ]);
35724
35659
  return { CuratorConfigSchema, curator, createCuratorLLMDelegate: createCuratorLLMDelegate2 };
35725
35660
  }
@@ -36360,7 +36295,7 @@ init_git_executable();
36360
36295
  // src/services/knowledge-diagnostics.ts
36361
36296
  init_package();
36362
36297
  import { existsSync as existsSync31, readFileSync as readFileSync21 } from "fs";
36363
- import { readFile as readFile17 } from "fs/promises";
36298
+ import { readFile as readFile16 } from "fs/promises";
36364
36299
  import { join as join41 } from "path";
36365
36300
 
36366
36301
  // src/services/version-check.ts
@@ -36437,7 +36372,7 @@ var INSIGHT_BACKLOG_WARN = 50;
36437
36372
  async function readRawLines(filePath) {
36438
36373
  if (!existsSync31(filePath))
36439
36374
  return { entries: [], corrupt: 0 };
36440
- const content = await readFile17(filePath, "utf-8");
36375
+ const content = await readFile16(filePath, "utf-8");
36441
36376
  const entries = [];
36442
36377
  let corrupt = 0;
36443
36378
  for (const line of content.split(`
@@ -36709,7 +36644,7 @@ async function computeCurationDiagnostics(directory, entries) {
36709
36644
  let scanCompleted = false;
36710
36645
  let scanRemaining = 0;
36711
36646
  try {
36712
- const { getScanStatus } = await import("./scan-cursor-7n0zs72g.js");
36647
+ const { getScanStatus } = await import("./scan-cursor-3ba1spad.js");
36713
36648
  const status = await getScanStatus(directory);
36714
36649
  scanGeneration = status.generation;
36715
36650
  scanCompleted = status.completed;
@@ -36717,19 +36652,19 @@ async function computeCurationDiagnostics(directory, entries) {
36717
36652
  } catch {}
36718
36653
  let configMatch = null;
36719
36654
  try {
36720
- const { isLinked: isLinked2 } = await import("./knowledge-link-spw879rs.js");
36655
+ const { isLinked: isLinked2 } = await import("./knowledge-link-a5f89833.js");
36721
36656
  if (isLinked2(directory)) {
36722
- const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-e59spg93.js");
36657
+ const { KnowledgeConfigSchema: KnowledgeConfigSchema2 } = await import("./schema-h251vmd1.js");
36723
36658
  let config;
36724
36659
  try {
36725
- const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-qbsc2btq.js");
36660
+ const { loadPluginConfigWithMeta: loadPluginConfigWithMeta2 } = await import("./index-hbhw2qd7.js");
36726
36661
  const loaded = loadPluginConfigWithMeta2(directory);
36727
36662
  config = KnowledgeConfigSchema2.parse(loaded.config.knowledge ?? {});
36728
36663
  } catch {
36729
36664
  config = KnowledgeConfigSchema2.parse({});
36730
36665
  }
36731
36666
  const { cohortConfigFingerprint: cohortConfigFingerprint2 } = await import("./config-fingerprint-v22xh5a2.js");
36732
- const { buildConfigFingerprintInput: buildConfigFingerprintInput2, readCohortConfigFingerprint } = await import("./curation-policy-fbvctttr.js");
36667
+ const { buildConfigFingerprintInput: buildConfigFingerprintInput2, readCohortConfigFingerprint } = await import("./curation-policy-4jxx3ey4.js");
36733
36668
  const currentFp = cohortConfigFingerprint2(buildConfigFingerprintInput2(config));
36734
36669
  const cohortFp = await readCohortConfigFingerprint(directory);
36735
36670
  configMatch = cohortFp === null ? null : currentFp === cohortFp;
@@ -36764,7 +36699,7 @@ async function countPendingProposals(directory) {
36764
36699
  if (!existsSync31(proposalsPath))
36765
36700
  return 0;
36766
36701
  try {
36767
- const content = await readFile17(proposalsPath, "utf-8");
36702
+ const content = await readFile16(proposalsPath, "utf-8");
36768
36703
  let n = 0;
36769
36704
  for (const line of content.split(`
36770
36705
  `)) {
@@ -36786,7 +36721,7 @@ async function safeJsonlCount(filePath) {
36786
36721
  if (!filePath || !existsSync31(filePath))
36787
36722
  return 0;
36788
36723
  try {
36789
- const content = await readFile17(filePath, "utf-8");
36724
+ const content = await readFile16(filePath, "utf-8");
36790
36725
  let n = 0;
36791
36726
  for (const line of content.split(`
36792
36727
  `)) {
@@ -37331,8 +37266,7 @@ async function checkCheckpointManifest(directory) {
37331
37266
  }
37332
37267
  }
37333
37268
  async function checkEventStreamIntegrity(directory) {
37334
- const eventsPath = path53.join(directory, ".swarm/events.jsonl");
37335
- if (!existsSync32(eventsPath)) {
37269
+ if (getCoreEventCoverage(directory) === "empty") {
37336
37270
  return {
37337
37271
  name: "Event Stream",
37338
37272
  status: "\u2705",
@@ -37340,8 +37274,8 @@ async function checkEventStreamIntegrity(directory) {
37340
37274
  };
37341
37275
  }
37342
37276
  try {
37343
- const content = readFileSync22(eventsPath, "utf-8");
37344
- const lines = content.split(`
37277
+ const window = readCoreEvents(directory);
37278
+ const lines = window.text.split(`
37345
37279
  `).filter((line) => line.trim() !== "");
37346
37280
  let malformedCount = 0;
37347
37281
  for (const line of lines) {
@@ -37351,11 +37285,12 @@ async function checkEventStreamIntegrity(directory) {
37351
37285
  malformedCount++;
37352
37286
  }
37353
37287
  }
37288
+ const coverageNote = window.coverage === "truncated" ? " (retained window \u2014 compacted history excluded)" : "";
37354
37289
  if (malformedCount === 0) {
37355
37290
  return {
37356
37291
  name: "Event Stream",
37357
37292
  status: "\u2705",
37358
- detail: `events.jsonl is valid \u2014 ${lines.length} event(s)`
37293
+ detail: `events.jsonl is valid \u2014 ${lines.length} event(s)${coverageNote}`
37359
37294
  };
37360
37295
  }
37361
37296
  return {
@@ -37372,8 +37307,7 @@ async function checkEventStreamIntegrity(directory) {
37372
37307
  }
37373
37308
  }
37374
37309
  async function checkSteeringDirectives(directory) {
37375
- const eventsPath = path53.join(directory, ".swarm/events.jsonl");
37376
- if (!existsSync32(eventsPath)) {
37310
+ if (getCoreEventCoverage(directory) === "empty") {
37377
37311
  return {
37378
37312
  name: "Steering Directives",
37379
37313
  status: "\u2705",
@@ -37381,8 +37315,8 @@ async function checkSteeringDirectives(directory) {
37381
37315
  };
37382
37316
  }
37383
37317
  try {
37384
- const content = readFileSync22(eventsPath, "utf-8");
37385
- const lines = content.split(`
37318
+ const window = readCoreEvents(directory);
37319
+ const lines = window.text.split(`
37386
37320
  `).filter((line) => line.trim() !== "");
37387
37321
  const directivesIssued = [];
37388
37322
  const consumedIds = new Set;
@@ -37399,10 +37333,11 @@ async function checkSteeringDirectives(directory) {
37399
37333
  }
37400
37334
  const unconsumed = directivesIssued.filter((id) => !consumedIds.has(id));
37401
37335
  if (unconsumed.length === 0) {
37336
+ const coverageNote = window.coverage === "truncated" ? " (within the retained event window)" : "";
37402
37337
  return {
37403
37338
  name: "Steering Directives",
37404
37339
  status: "\u2705",
37405
- detail: "All steering directives acknowledged (or none issued)"
37340
+ detail: `All steering directives acknowledged (or none issued)${coverageNote}`
37406
37341
  };
37407
37342
  }
37408
37343
  return {
@@ -38033,7 +37968,7 @@ async function handleDoctorCommand(directory, args) {
38033
37968
  const result = runConfigDoctor(config, directory);
38034
37969
  let output;
38035
37970
  if (enableAutoFix && result.hasAutoFixableIssues) {
38036
- const { runConfigDoctorWithFixes } = await import("./config-doctor-6z7x0jnz.js");
37971
+ const { runConfigDoctorWithFixes } = await import("./config-doctor-fx8d6pma.js");
38037
37972
  const fixResult = await runConfigDoctorWithFixes(directory, config, true, {
38038
37973
  applyLossy: true
38039
37974
  });
@@ -38973,7 +38908,7 @@ async function handleEvidenceCommand(directory, args) {
38973
38908
  return formatTaskEvidenceMarkdown(evidenceData);
38974
38909
  }
38975
38910
  async function handleEvidenceSummaryCommand(directory) {
38976
- const { buildEvidenceSummary } = await import("./evidence-summary-service-9ajw5tpc.js");
38911
+ const { buildEvidenceSummary } = await import("./evidence-summary-service-x00z38n2.js");
38977
38912
  const artifact = await buildEvidenceSummary(directory);
38978
38913
  if (!artifact) {
38979
38914
  return "No plan found. Run `/swarm plan` to check plan status.";
@@ -46191,9 +46126,9 @@ import { createHash as createHash19, createHmac, randomBytes, randomUUID as rand
46191
46126
  import {
46192
46127
  chmod,
46193
46128
  copyFile as copyFile2,
46194
- mkdir as mkdir16,
46129
+ mkdir as mkdir14,
46195
46130
  readdir as readdir5,
46196
- readFile as readFile18,
46131
+ readFile as readFile17,
46197
46132
  realpath as realpath4,
46198
46133
  rm as rm2,
46199
46134
  stat as stat6,
@@ -46988,10 +46923,10 @@ function emitMaintenanceTelemetry(payload) {
46988
46923
  }
46989
46924
  var _internals60 = {
46990
46925
  emit,
46991
- readFile: readFile18,
46926
+ readFile: readFile17,
46992
46927
  writeFile: writeFile11,
46993
46928
  copyFile: copyFile2,
46994
- mkdir: mkdir16,
46929
+ mkdir: mkdir14,
46995
46930
  stat: stat6,
46996
46931
  readdir: readdir5,
46997
46932
  resolveHiveDataDir,
@@ -47313,7 +47248,7 @@ init_schema();
47313
47248
  init_logger();
47314
47249
  import { randomUUID as randomUUID10 } from "crypto";
47315
47250
  import { existsSync as existsSync41, readFileSync as readFileSync32 } from "fs";
47316
- import { mkdir as mkdir17, readFile as readFile19, writeFile as writeFile12 } from "fs/promises";
47251
+ import { mkdir as mkdir15, readFile as readFile18, writeFile as writeFile12 } from "fs/promises";
47317
47252
  import * as os9 from "os";
47318
47253
  import * as path68 from "path";
47319
47254
  init_knowledge_types();
@@ -47379,8 +47314,8 @@ var _internals62 = {
47379
47314
  resolveLegacyHiveKnowledgePath,
47380
47315
  existsSync: existsSync41,
47381
47316
  readFileSync: readFileSync32,
47382
- readFile: readFile19,
47383
- mkdir: mkdir17,
47317
+ readFile: readFile18,
47318
+ mkdir: mkdir15,
47384
47319
  writeFile: writeFile12
47385
47320
  };
47386
47321
  async function migrateContextToKnowledge(directory, config) {
@@ -47405,7 +47340,7 @@ async function migrateContextToKnowledge(directory, config) {
47405
47340
  skippedReason: "no-context-file"
47406
47341
  };
47407
47342
  }
47408
- const contextContent = await readFile19(contextPath, "utf-8");
47343
+ const contextContent = await readFile18(contextPath, "utf-8");
47409
47344
  if (contextContent.trim().length === 0) {
47410
47345
  return {
47411
47346
  migrated: false,
@@ -48194,14 +48129,14 @@ var _internals63 = {
48194
48129
  };
48195
48130
 
48196
48131
  // src/commands/link.ts
48197
- import { mkdir as mkdir19, writeFile as writeFile13 } from "fs/promises";
48132
+ import { mkdir as mkdir17, writeFile as writeFile13 } from "fs/promises";
48198
48133
  import * as path70 from "path";
48199
48134
  init_schema();
48200
48135
 
48201
48136
  // src/knowledge/family-migration.ts
48202
48137
  var import_proper_lockfile7 = __toESM(require_proper_lockfile(), 1);
48203
48138
  import { existsSync as existsSync42, readFileSync as readFileSync33 } from "fs";
48204
- import { mkdir as mkdir18 } from "fs/promises";
48139
+ import { mkdir as mkdir16 } from "fs/promises";
48205
48140
  import * as path69 from "path";
48206
48141
 
48207
48142
  // src/knowledge/family-manifest.ts
@@ -48484,7 +48419,7 @@ async function snapshotSourceFamily(storeDir) {
48484
48419
  const snapshot = {};
48485
48420
  let release = null;
48486
48421
  try {
48487
- await mkdir18(storeDir, { recursive: true });
48422
+ await mkdir16(storeDir, { recursive: true });
48488
48423
  } catch {}
48489
48424
  try {
48490
48425
  release = await import_proper_lockfile7.default.lock(storeDir, {
@@ -48503,7 +48438,7 @@ async function snapshotSourceFamily(storeDir) {
48503
48438
  return snapshot;
48504
48439
  }
48505
48440
  async function migrateKnowledgeFamily(destinationDir, sourceDir) {
48506
- await mkdir18(destinationDir, { recursive: true });
48441
+ await mkdir16(destinationDir, { recursive: true });
48507
48442
  let destRelease = null;
48508
48443
  try {
48509
48444
  destRelease = await import_proper_lockfile7.default.lock(destinationDir, {
@@ -48653,7 +48588,7 @@ ${formatStatus(directory)}`;
48653
48588
  const { config: loadedConfig } = loadPluginConfigWithMeta(directory);
48654
48589
  const config = KnowledgeConfigSchema.parse(loadedConfig.knowledge ?? {});
48655
48590
  const fingerprint = cohortConfigFingerprint(buildConfigFingerprintInput(config));
48656
- await mkdir19(linkDir, { recursive: true });
48591
+ await mkdir17(linkDir, { recursive: true });
48657
48592
  await writeFile13(path70.join(linkDir, "cohort-config.json"), JSON.stringify({ fingerprint, updated_at: new Date().toISOString() }, null, 2), "utf-8");
48658
48593
  } catch {}
48659
48594
  const relinkNote = existing ? `
@@ -53377,7 +53312,7 @@ function readDeadAnchorMemoryIds(directory) {
53377
53312
  return new Set(Array.isArray(digest?.deadAnchorMemoryIds) ? digest.deadAnchorMemoryIds.filter((value) => typeof value === "string") : []);
53378
53313
  }
53379
53314
  // src/memory/consolidation-log.ts
53380
- import { appendFile as appendFile9, mkdir as mkdir21, readFile as readFile23 } from "fs/promises";
53315
+ import { appendFile as appendFile4, mkdir as mkdir19, readFile as readFile22 } from "fs/promises";
53381
53316
  import * as path76 from "path";
53382
53317
  var LOG_RELATIVE_PATH = path76.join("memory", "consolidation-log.jsonl");
53383
53318
  var LOG_BASENAME = "consolidation-log.jsonl";
@@ -53394,7 +53329,7 @@ async function readConsolidationLog(target) {
53394
53329
  const filePath = resolveLogPath2(target);
53395
53330
  let raw;
53396
53331
  try {
53397
- raw = await readFile23(filePath, "utf-8");
53332
+ raw = await readFile22(filePath, "utf-8");
53398
53333
  } catch {
53399
53334
  return [];
53400
53335
  }
@@ -54041,14 +53976,14 @@ function truncate2(value, maxLength) {
54041
53976
  }
54042
53977
 
54043
53978
  // src/commands/memory-link.ts
54044
- import { mkdir as mkdir23, writeFile as writeFile15 } from "fs/promises";
53979
+ import { mkdir as mkdir21, writeFile as writeFile15 } from "fs/promises";
54045
53980
  import * as path79 from "path";
54046
53981
  init_schema();
54047
53982
 
54048
53983
  // src/memory/memory-family-migration.ts
54049
53984
  var import_proper_lockfile9 = __toESM(require_proper_lockfile(), 1);
54050
53985
  import { copyFileSync as copyFileSync4, existsSync as existsSync45, readFileSync as readFileSync35, unlinkSync as unlinkSync13 } from "fs";
54051
- import { mkdir as mkdir22, rename as rename8 } from "fs/promises";
53986
+ import { mkdir as mkdir20, rename as rename8 } from "fs/promises";
54052
53987
  import * as path78 from "path";
54053
53988
  init_logger();
54054
53989
 
@@ -54340,7 +54275,7 @@ async function countRowsSafe(dbPath) {
54340
54275
  async function migrateMemoryFamily(destRoot, sourceRoot) {
54341
54276
  const destStoragePath = rootStoragePath(destRoot);
54342
54277
  const sourceStoragePath = rootStoragePath(sourceRoot);
54343
- await mkdir22(destStoragePath, { recursive: true });
54278
+ await mkdir20(destStoragePath, { recursive: true });
54344
54279
  let destRelease = null;
54345
54280
  try {
54346
54281
  destRelease = await import_proper_lockfile9.default.lock(destStoragePath, {
@@ -54387,7 +54322,7 @@ async function migrateMemoryFamily(destRoot, sourceRoot) {
54387
54322
  }
54388
54323
  if (isCohortRoot(sourceRoot)) {
54389
54324
  const backupDir = path78.join(destStoragePath, "backups");
54390
- await mkdir22(backupDir, { recursive: true });
54325
+ await mkdir20(backupDir, { recursive: true });
54391
54326
  const stamp = new Date().toISOString().replace(/[:.]/g, "-");
54392
54327
  const sourceDbPath = path78.join(sourceStoragePath, "memory.db");
54393
54328
  if (existsSync45(sourceDbPath)) {
@@ -54523,7 +54458,7 @@ ${formatStatus2(directory)}`;
54523
54458
  return `\u274C Failed to migrate the memory family into the cohort store: ${error2 instanceof Error ? error2.message : String(error2)}`;
54524
54459
  }
54525
54460
  try {
54526
- await mkdir23(cohortRoot.cohortRoot, { recursive: true });
54461
+ await mkdir21(cohortRoot.cohortRoot, { recursive: true });
54527
54462
  const fingerprintInput = buildMemoryCohortFingerprintInput(memoryConfig);
54528
54463
  const fingerprint = computeMemoryCohortFingerprint(fingerprintInput);
54529
54464
  await writeFile15(path79.join(cohortRoot.cohortRoot, "memory-cohort-config.json"), JSON.stringify({
@@ -59064,7 +58999,7 @@ function getTestFilesFromConvention(sourceFiles, workingDir = process.cwd()) {
59064
58999
  const absoluteFile = resolveWorkspacePath(file, workingDir);
59065
59000
  const relativeFile = path85.relative(workingDir, absoluteFile);
59066
59001
  const basename20 = path85.basename(absoluteFile);
59067
- const dirname38 = path85.dirname(absoluteFile);
59002
+ const dirname36 = path85.dirname(absoluteFile);
59068
59003
  const preferRelativeOutput = !path85.isAbsolute(file);
59069
59004
  if (isConventionTestFilePath(relativeFile) || isConventionTestFilePath(file)) {
59070
59005
  dedupePush(testFiles, toWorkspaceOutputPath(absoluteFile, workingDir, preferRelativeOutput));
@@ -59080,7 +59015,7 @@ function getTestFilesFromConvention(sourceFiles, workingDir = process.cwd()) {
59080
59015
  const colocatedCandidates = [
59081
59016
  ...genericTestNames,
59082
59017
  ...languageSpecificTestNames
59083
- ].map((candidateName) => path85.join(dirname38, candidateName));
59018
+ ].map((candidateName) => path85.join(dirname36, candidateName));
59084
59019
  const testDirectoryNames = [
59085
59020
  basename20,
59086
59021
  ...genericTestNames,
@@ -59089,7 +59024,7 @@ function getTestFilesFromConvention(sourceFiles, workingDir = process.cwd()) {
59089
59024
  const repoLevelDirectories = getRepoLevelCandidateDirectories(workingDir, relativeFile, ext);
59090
59025
  const possibleTestFiles = [
59091
59026
  ...colocatedCandidates,
59092
- ...TEST_DIRECTORY_NAMES.flatMap((dirName) => testDirectoryNames.map((candidateName) => path85.join(dirname38, dirName, candidateName))),
59027
+ ...TEST_DIRECTORY_NAMES.flatMap((dirName) => testDirectoryNames.map((candidateName) => path85.join(dirname36, dirName, candidateName))),
59093
59028
  ...repoLevelDirectories.flatMap((candidateDir) => testDirectoryNames.map((candidateName) => path85.join(candidateDir, candidateName)))
59094
59029
  ];
59095
59030
  for (const testFile of possibleTestFiles) {
@@ -61666,34 +61601,17 @@ async function handleQaGatesCommand(directory, args, sessionID) {
61666
61601
  }
61667
61602
 
61668
61603
  // src/workflow/stage-a-repair.ts
61669
- import { appendFile as appendFile10, mkdir as mkdir24, readdir as readdir8 } from "fs/promises";
61670
- import { dirname as dirname38 } from "path";
61604
+ import { readdir as readdir8 } from "fs/promises";
61671
61605
  init_logger();
61672
61606
  var MAX_STAGE_A_REPAIR_SCAN = 200;
61673
- var RETRYABLE_EVENT_CODES = new Set(["EBUSY", "EPERM"]);
61674
61607
  async function appendStageARepairEvent(directory, payload) {
61675
- const line = `${JSON.stringify({
61676
- type: "stage_a_repair",
61677
- timestamp: new Date().toISOString(),
61678
- ...payload
61679
- })}
61680
- `;
61681
61608
  try {
61682
- const eventsPath = validateSwarmPath(directory, "events.jsonl");
61683
- await mkdir24(dirname38(eventsPath), { recursive: true });
61684
- await appendFile10(eventsPath, line, "utf-8");
61609
+ appendCoreEventSync(directory, {
61610
+ type: "stage_a_repair",
61611
+ timestamp: new Date().toISOString(),
61612
+ ...payload
61613
+ });
61685
61614
  } catch (error2) {
61686
- const code = error2.code;
61687
- if (code && RETRYABLE_EVENT_CODES.has(code)) {
61688
- try {
61689
- const eventsPath = validateSwarmPath(directory, "events.jsonl");
61690
- await appendFile10(eventsPath, line, "utf-8");
61691
- return;
61692
- } catch (retryError) {
61693
- criticalWarn(`[stage-a-repair] audit event write failed after retry: ${retryError instanceof Error ? retryError.message : String(retryError)}`);
61694
- return;
61695
- }
61696
- }
61697
61615
  criticalWarn(`[stage-a-repair] audit event write failed: ${error2 instanceof Error ? error2.message : String(error2)}`);
61698
61616
  }
61699
61617
  }
@@ -62768,6 +62686,7 @@ async function handleResetCommand(directory, args) {
62768
62686
  "plan-export/SWARM_PLAN.json",
62769
62687
  "checkpoints.json",
62770
62688
  "events.jsonl",
62689
+ "events-authority-index.json",
62771
62690
  "run-memory.jsonl",
62772
62691
  "reproduction.json",
62773
62692
  "issue-publication.json",
@@ -67246,7 +67165,6 @@ async function restoreGitCheckpoint(directory, selected) {
67246
67165
  if (parsed.success !== true) {
67247
67166
  return `Error: ${parsed.error || `Failed to restore checkpoint "${selected.label}"`}`;
67248
67167
  }
67249
- const eventsPath = validateSwarmPath(directory, "events.jsonl");
67250
67168
  const rollbackEvent = {
67251
67169
  type: "rollback",
67252
67170
  label: selected.label,
@@ -67255,8 +67173,7 @@ async function restoreGitCheckpoint(directory, selected) {
67255
67173
  source: "checkpoints.json"
67256
67174
  };
67257
67175
  try {
67258
- fs48.appendFileSync(eventsPath, `${JSON.stringify(rollbackEvent)}
67259
- `);
67176
+ appendCoreEventSync(directory, rollbackEvent);
67260
67177
  } catch (error2) {
67261
67178
  log("Failed to write rollback event:", error2 instanceof Error ? error2.message : String(error2));
67262
67179
  }
@@ -67403,7 +67320,6 @@ async function handleRollbackCommand(directory, args) {
67403
67320
  `);
67404
67321
  }
67405
67322
  }
67406
- const eventsPath = validateSwarmPath(directory, "events.jsonl");
67407
67323
  const rollbackEvent = {
67408
67324
  type: "rollback",
67409
67325
  phase: targetPhase,
@@ -67411,8 +67327,7 @@ async function handleRollbackCommand(directory, args) {
67411
67327
  timestamp: new Date().toISOString()
67412
67328
  };
67413
67329
  try {
67414
- fs48.appendFileSync(eventsPath, `${JSON.stringify(rollbackEvent)}
67415
- `);
67330
+ appendCoreEventSync(directory, rollbackEvent);
67416
67331
  } catch (error2) {
67417
67332
  log("Failed to write rollback event:", error2 instanceof Error ? error2.message : String(error2));
67418
67333
  }
@@ -69404,7 +69319,7 @@ async function runValidationWithTransientRetry(input, candidateContent, baseline
69404
69319
  if (!input.dispatcher) {
69405
69320
  throw new Error("no evaluation dispatcher available (cannot run validation)");
69406
69321
  }
69407
- const { createModelEvaluationExecutor: createModelEvaluationExecutor2 } = await import("./runner-rk26nk58.js");
69322
+ const { createModelEvaluationExecutor: createModelEvaluationExecutor2 } = await import("./runner-9mnkfjw7.js");
69408
69323
  const executor = createModelEvaluationExecutor2(input.dispatcher, input.sessionId);
69409
69324
  const result = await _internals95.evaluateCandidateV1({
69410
69325
  projectRoot: input.directory,
@@ -69920,7 +69835,7 @@ async function handleSpecifyCommand(_directory, args) {
69920
69835
 
69921
69836
  // src/services/status-service.ts
69922
69837
  import * as fsSync3 from "fs";
69923
- import { readFile as readFile25 } from "fs/promises";
69838
+ import { readFile as readFile24 } from "fs/promises";
69924
69839
  import * as path109 from "path";
69925
69840
  init_loader();
69926
69841
  init_schema();
@@ -70961,7 +70876,7 @@ async function safeLineCount(filePath) {
70961
70876
  try {
70962
70877
  if (!fsSync3.existsSync(filePath))
70963
70878
  return 0;
70964
- const content = await readFile25(filePath, "utf-8");
70879
+ const content = await readFile24(filePath, "utf-8");
70965
70880
  let n = 0;
70966
70881
  for (const line of content.split(`
70967
70882
  `)) {
@@ -71439,7 +71354,7 @@ function buildDetailedHelp(commandName, entry) {
71439
71354
  async function handleHelpCommand(ctx) {
71440
71355
  const targetCommand = ctx.args.join(" ");
71441
71356
  if (!targetCommand) {
71442
- const { buildHelpText } = await import("./index-ag9bv589.js");
71357
+ const { buildHelpText } = await import("./index-ka2vav7t.js");
71443
71358
  return buildHelpText();
71444
71359
  }
71445
71360
  const tokens = targetCommand.split(/\s+/);
@@ -71448,7 +71363,7 @@ async function handleHelpCommand(ctx) {
71448
71363
  return _internals98.buildDetailedHelp(resolved.key, resolved.entry);
71449
71364
  }
71450
71365
  const similar = _internals98.findSimilarCommands(targetCommand);
71451
- const { buildHelpText: fullHelp } = await import("./index-ag9bv589.js");
71366
+ const { buildHelpText: fullHelp } = await import("./index-ka2vav7t.js");
71452
71367
  if (similar.length > 0) {
71453
71368
  return `Command '/swarm ${targetCommand}' not found.
71454
71369
 
@@ -71628,7 +71543,7 @@ var COMMAND_REGISTRY = {
71628
71543
  },
71629
71544
  "guardrail explain": {
71630
71545
  handler: async (ctx) => {
71631
- const { handleGuardrailExplain } = await import("./guardrail-explain-a8706sq1.js");
71546
+ const { handleGuardrailExplain } = await import("./guardrail-explain-nynjhbzk.js");
71632
71547
  return handleGuardrailExplain(ctx.directory, ctx.args);
71633
71548
  },
71634
71549
  description: "Dry-run: show what the guardrails would do to a command or write target (executes nothing)",
@@ -71638,7 +71553,7 @@ var COMMAND_REGISTRY = {
71638
71553
  },
71639
71554
  "guardrail reset": {
71640
71555
  handler: async (ctx) => {
71641
- const { handleGuardrailReset } = await import("./guardrail-reset-sy0vztrd.js");
71556
+ const { handleGuardrailReset } = await import("./guardrail-reset-hsfd5ykq.js");
71642
71557
  return handleGuardrailReset(ctx.args, ctx.sessionID);
71643
71558
  },
71644
71559
  description: "Reset one exact active invocation/action circuit after repair",
@@ -71647,7 +71562,7 @@ var COMMAND_REGISTRY = {
71647
71562
  },
71648
71563
  "guardrail-explain": {
71649
71564
  handler: async (ctx) => {
71650
- const { handleGuardrailExplain } = await import("./guardrail-explain-a8706sq1.js");
71565
+ const { handleGuardrailExplain } = await import("./guardrail-explain-nynjhbzk.js");
71651
71566
  return handleGuardrailExplain(ctx.directory, ctx.args);
71652
71567
  },
71653
71568
  description: "Dry-run: show what the guardrails would do to a command or write target (executes nothing)",
@@ -71657,7 +71572,7 @@ var COMMAND_REGISTRY = {
71657
71572
  },
71658
71573
  "guardrail-reset": {
71659
71574
  handler: async (ctx) => {
71660
- const { handleGuardrailReset } = await import("./guardrail-reset-sy0vztrd.js");
71575
+ const { handleGuardrailReset } = await import("./guardrail-reset-hsfd5ykq.js");
71661
71576
  return handleGuardrailReset(ctx.args, ctx.sessionID);
71662
71577
  },
71663
71578
  description: "Reset one exact active invocation/action circuit after repair",
@@ -71667,7 +71582,7 @@ var COMMAND_REGISTRY = {
71667
71582
  },
71668
71583
  "guardrail-log": {
71669
71584
  handler: async (ctx) => {
71670
- const { handleGuardrailLog } = await import("./guardrail-log-wx43bj32.js");
71585
+ const { handleGuardrailLog } = await import("./guardrail-log-6bktj08e.js");
71671
71586
  return handleGuardrailLog(ctx.directory, ctx.args);
71672
71587
  },
71673
71588
  description: "Read the guardrail decision log (use --blocks-only for blocks)",
@@ -76902,16 +76817,14 @@ async function forceRecordPlanCriticApproval(directory, sessionID, options = {})
76902
76817
  payloadHashOverride: computePlanStructureHash(plan)
76903
76818
  });
76904
76819
  try {
76905
- const eventsPath = validateSwarmPath(directory, "events.jsonl");
76906
- await fs52.promises.appendFile(eventsPath, `${JSON.stringify({
76820
+ appendCoreEventSync(directory, {
76907
76821
  type: "plan_critic_gate_manual_approval",
76908
76822
  timestamp: recordedAt,
76909
76823
  sessionID,
76910
76824
  plan_id: planId,
76911
76825
  user_confirmed: userConfirmed,
76912
76826
  ...sanitizedReason ? { reason: sanitizedReason } : {}
76913
- })}
76914
- `, "utf-8");
76827
+ });
76915
76828
  } catch (err) {
76916
76829
  warn(`[delegation-gate] plan_critic_gate_manual_approval audit event write failed: ${err instanceof Error ? err.message : String(err)}`);
76917
76830
  }
@@ -78094,7 +78007,7 @@ function getDisplayBudget() {
78094
78007
  async function rehydratePrSubscriptions(sessionID, directory) {
78095
78008
  const map = new Map;
78096
78009
  try {
78097
- const { listActive: listActive2 } = await import("./pr-subscriptions-f4xw1rxy.js");
78010
+ const { listActive: listActive2 } = await import("./pr-subscriptions-cpnwvc6y.js");
78098
78011
  const records = await listActive2(directory);
78099
78012
  for (const record of records) {
78100
78013
  if (record.sessionID !== sessionID)
@@ -78510,7 +78423,7 @@ function isLaneOwnedByCurrentSession(branchName, expectedSessionId) {
78510
78423
  return extracted === expectedSessionId;
78511
78424
  }
78512
78425
  async function inspectStandardWorktreeCollisionOwnership(identity) {
78513
- const collisionOwnership = await import("./worktree-collision-ownership-wqy7mgb3.js");
78426
+ const collisionOwnership = await import("./worktree-collision-ownership-r8j31h06.js");
78514
78427
  return collisionOwnership.inspectStandardWorktreeCollisionOwnership(identity);
78515
78428
  }
78516
78429
  async function precreateStandardWorktreeSession(args) {
@@ -78658,7 +78571,7 @@ async function precreateStandardWorktreeSession(args) {
78658
78571
  const laneProfile = computeLaneRuntimeProfile(worktreeConfig.runtime_isolation, laneIndex, provisionResult.worktreePath);
78659
78572
  if (laneProfile) {
78660
78573
  try {
78661
- const { writeLaneProfileToDiskReal } = await import("./core-0ph6pb2y.js");
78574
+ const { writeLaneProfileToDiskReal } = await import("./core-0v762txd.js");
78662
78575
  await writeLaneProfileToDiskReal(provisionResult.worktreePath, laneProfile.laneIndex, laneProfile.envOverrides);
78663
78576
  } catch {}
78664
78577
  }
@@ -79316,7 +79229,7 @@ async function finishStandardWorktreeDispatch(directory, dispatch, config, callI
79316
79229
  }
79317
79230
  clearWorktreeMergeStatus(statusKey);
79318
79231
  try {
79319
- const { removeLaneProfileFromDiskReal } = await import("./core-0ph6pb2y.js");
79232
+ const { removeLaneProfileFromDiskReal } = await import("./core-0v762txd.js");
79320
79233
  await removeLaneProfileFromDiskReal(dispatch.handle.worktreePath, dispatch.laneIndex);
79321
79234
  } catch {}
79322
79235
  const state = serializationStateBySessionID.get(dispatch.parentSessionID);