opencode-swarm 7.167.2 → 7.168.1

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 (102) hide show
  1. package/binaries/win32-arm64/swarm-sandbox-runner.exe +0 -0
  2. package/binaries/win32-x64/swarm-sandbox-runner.exe +0 -0
  3. package/dist/cli/{coder-settlement-jy9rad28.js → coder-settlement-54a3d97g.js} +12 -12
  4. package/dist/cli/{config-doctor-p66vnpy3.js → config-doctor-vzp6b3ng.js} +3 -3
  5. package/dist/cli/{core-tw0wtntz.js → core-yynse50x.js} +2 -2
  6. package/dist/cli/{curation-policy-ndp27v0c.js → curation-policy-mgwv8h2k.js} +5 -5
  7. package/dist/cli/{curator-5nzde80g.js → curator-agdhhzqt.js} +38 -38
  8. package/dist/cli/{curator-drift-gb651hcw.js → curator-drift-k0zrnm09.js} +5 -5
  9. package/dist/cli/curator-llm-factory-ygxd6hfx.js +71 -0
  10. package/dist/cli/{evidence-summary-service-bzpfaypy.js → evidence-summary-service-6mmcekr7.js} +17 -17
  11. package/dist/cli/{gate-evidence-wa8cj8h6.js → gate-evidence-xqvkqhrk.js} +7 -7
  12. package/dist/cli/guardrail-explain-vjtjhgzs.js +72 -0
  13. package/dist/cli/{guardrail-log-7dv73e0q.js → guardrail-log-5wa5c77w.js} +8 -8
  14. package/dist/cli/{guardrail-reset-1kng6y8x.js → guardrail-reset-dh78tbcf.js} +38 -38
  15. package/dist/cli/{hive-promoter-87kk2pg5.js → hive-promoter-3czsx7c6.js} +38 -38
  16. package/dist/cli/{index-18rfc7qv.js → index-2xbww1x0.js} +7 -7
  17. package/dist/cli/{index-3ws11dq0.js → index-3jmb4ppa.js} +2 -2
  18. package/dist/cli/{index-79234evf.js → index-4kv1ew3q.js} +1 -1
  19. package/dist/cli/{index-vgpedapd.js → index-4r5pmtvk.js} +2 -2
  20. package/dist/cli/{index-rrne6g2m.js → index-5g6rhkn7.js} +6 -2
  21. package/dist/cli/{index-m7cwnt9r.js → index-5zqakgp4.js} +2 -2
  22. package/dist/cli/{index-m3z83nhs.js → index-6df6wbvj.js} +8 -8
  23. package/dist/cli/{index-0q839sg6.js → index-8ybjqg51.js} +1 -1
  24. package/dist/cli/{index-wjet7x0a.js → index-91ww9hyr.js} +1 -1
  25. package/dist/cli/{index-pdcperq5.js → index-9b2105n0.js} +2 -2
  26. package/dist/cli/{index-z6we1abx.js → index-a8xbvsse.js} +2 -2
  27. package/dist/cli/{index-2b1hd1fx.js → index-apy1qfj0.js} +13 -4
  28. package/dist/cli/{index-gmjg65tm.js → index-bvqqwx84.js} +2 -2
  29. package/dist/cli/{index-ce8p9t28.js → index-bw9x8d8n.js} +5 -5
  30. package/dist/cli/{index-dme7wvwg.js → index-chebm5h5.js} +4 -4
  31. package/dist/cli/{index-mtepgqan.js → index-dfyv3xkd.js} +7 -7
  32. package/dist/cli/{index-sjkg2hc4.js → index-f1fps3w9.js} +6 -6
  33. package/dist/cli/index-gh9ybrrs.js +2008 -0
  34. package/dist/cli/{index-3r6k6qa7.js → index-gmpmgtzn.js} +4 -4
  35. package/dist/cli/{index-83r0v5tn.js → index-gp9yzr1v.js} +1 -1
  36. package/dist/cli/{index-962qme08.js → index-h439y187.js} +1 -1
  37. package/dist/cli/{index-5sjq3shs.js → index-j0bxxz9d.js} +8 -8
  38. package/dist/cli/{index-8vbahc4c.js → index-kear8gb7.js} +11 -6
  39. package/dist/cli/{index-y1sj2e1n.js → index-kkmezerc.js} +2094 -1686
  40. package/dist/cli/{index-syedr4e3.js → index-m35hybf0.js} +1 -1
  41. package/dist/cli/{index-f8cc92g7.js → index-nwwk3dej.js} +1 -1
  42. package/dist/cli/{index-g409c7ke.js → index-pyf517sz.js} +2 -2
  43. package/dist/cli/{index-ehq2vtkq.js → index-q8091q8b.js} +4 -4
  44. package/dist/cli/{index-k73ehxa1.js → index-qhey6vc3.js} +1 -1
  45. package/dist/cli/{index-09gv90d7.js → index-qkwtth00.js} +2 -2
  46. package/dist/cli/{index-shrf0wt3.js → index-qthc56c4.js} +4 -4
  47. package/dist/cli/{index-gs12223x.js → index-qwsh0h2g.js} +2 -2
  48. package/dist/cli/{index-n4fzmqz8.js → index-rdm3px0g.js} +4 -2
  49. package/dist/cli/{index-g5m43paw.js → index-sxt7fgcw.js} +1 -0
  50. package/dist/cli/{index-x7pm61wk.js → index-v3xc4sde.js} +9 -8
  51. package/dist/cli/{index-arqv4psy.js → index-w1dfkp1q.js} +57 -101
  52. package/dist/cli/{index-25xeyjfx.js → index-w3x1dmrf.js} +38 -38
  53. package/dist/cli/{index-hhkm64wh.js → index-wst6n478.js} +103 -3
  54. package/dist/cli/{index-f91fhch0.js → index-xhb4gryr.js} +4 -4
  55. package/dist/cli/{index-s7a9dqtb.js → index-xkf3672y.js} +4 -3
  56. package/dist/cli/{index-jhd3pmd1.js → index-y85aptep.js} +7 -7
  57. package/dist/cli/{index-65s0vgb1.js → index-yt9n9zt3.js} +40 -40
  58. package/dist/cli/{index-tcj8v6my.js → index-z6qreakh.js} +6 -6
  59. package/dist/cli/index.js +38 -38
  60. package/dist/cli/{knowledge-escalator-5e4zxan5.js → knowledge-escalator-135dz4eh.js} +13 -13
  61. package/dist/cli/{knowledge-events-abzm5vfh.js → knowledge-events-27gwv47q.js} +11 -11
  62. package/dist/cli/{knowledge-link-9ga6hyd5.js → knowledge-link-dr3xnwyd.js} +4 -4
  63. package/dist/cli/{knowledge-store-q4a92eq7.js → knowledge-store-80m44bfw.js} +5 -5
  64. package/dist/cli/{knowledge-validator-pn3m5r41.js → knowledge-validator-crsfb2cc.js} +7 -7
  65. package/dist/cli/{model-preflight-mw895vgt.js → model-preflight-1ycat9jz.js} +1 -1
  66. package/dist/cli/{pending-delegations-3z0xjppd.js → pending-delegations-gwgjzzkz.js} +12 -12
  67. package/dist/cli/{pr-subscriptions-h7mwnp62.js → pr-subscriptions-g633nhz4.js} +12 -12
  68. package/dist/cli/{pr-workflow-gate-fec04fa0.js → pr-workflow-gate-4dc5nt2e.js} +38 -38
  69. package/dist/cli/{runner-d9833azt.js → runner-k0ycgv8x.js} +5 -5
  70. package/dist/cli/{scan-cursor-ymfvzdkz.js → scan-cursor-avxjsm4w.js} +6 -6
  71. package/dist/cli/{schema-chc4aez6.js → schema-3ja77k4y.js} +4 -2
  72. package/dist/cli/{scope-persistence-3xnr59y8.js → scope-persistence-f540tc50.js} +16 -16
  73. package/dist/cli/{skill-generator-3mvaghxk.js → skill-generator-kcqqpg1g.js} +15 -15
  74. package/dist/cli/{snapshot-coordination-init-arnc77r9.js → snapshot-coordination-init-e4s8bn4p.js} +38 -38
  75. package/dist/cli/{sqlite-loader-xrnf6bq8.js → sqlite-loader-amp9z7ty.js} +1 -1
  76. package/dist/cli/{telemetry-g9pppt9e.js → telemetry-2wzapf11.js} +1 -1
  77. package/dist/cli/{workspace-snapshot-hvsjtepd.js → workspace-snapshot-rkgxhj9b.js} +3 -3
  78. package/dist/cli/{worktree-collision-ownership-vj8anvb7.js → worktree-collision-ownership-rk9gz638.js} +13 -13
  79. package/dist/cli/{worktree-isolation-mt7z75hz.js → worktree-isolation-1bdzfgky.js} +38 -38
  80. package/dist/commands/reset.d.ts +10 -0
  81. package/dist/commands/rollback.d.ts +9 -0
  82. package/dist/config/schema.d.ts +29 -0
  83. package/dist/db/project-db.d.ts +8 -0
  84. package/dist/db/sqlite-loader.d.ts +2 -1
  85. package/dist/dispatch/spawn-circuit.d.ts +121 -0
  86. package/dist/dispatch/token-bucket.d.ts +46 -0
  87. package/dist/hooks/delegation-gate/dead-lane-reclaim.d.ts +61 -0
  88. package/dist/hooks/delegation-gate/worktree-isolation.d.ts +22 -0
  89. package/dist/hooks/issue-trace.d.ts +3 -0
  90. package/dist/hooks/utils.d.ts +1 -1
  91. package/dist/index.js +657 -572
  92. package/dist/plan/ledger-sqlite.d.ts +226 -0
  93. package/dist/plan/ledger.d.ts +24 -0
  94. package/dist/plan/manager.d.ts +19 -0
  95. package/dist/retention/sweep.d.ts +2 -0
  96. package/dist/services/spec-drift-recovery.d.ts +2 -1
  97. package/dist/utils/ephemeral-session-teardown.d.ts +55 -2
  98. package/opencode-swarm.schema.json +41 -0
  99. package/package.json +1 -1
  100. package/dist/cli/curator-llm-factory-xy96x5x8.js +0 -71
  101. package/dist/cli/guardrail-explain-1ef5he6j.js +0 -72
  102. package/dist/cli/index-z7z3g5wt.js +0 -1017
@@ -11,7 +11,7 @@ import {
11
11
  readLinkPointer,
12
12
  resolveKnowledgeStoreDir,
13
13
  resolveLinkDir
14
- } from "./index-0q839sg6.js";
14
+ } from "./index-8ybjqg51.js";
15
15
 
16
16
  // src/knowledge/curation-policy.ts
17
17
  import { readFile as readFile2 } from "fs/promises";
@@ -5,7 +5,7 @@ import {
5
5
  batchDurabilityClass,
6
6
  classifyDbWriteError,
7
7
  getProjectDb
8
- } from "./index-hhkm64wh.js";
8
+ } from "./index-wst6n478.js";
9
9
  import {
10
10
  _internals,
11
11
  canonicalRootKeyFresh
@@ -2,13 +2,13 @@
2
2
  import {
3
3
  derivePlanId,
4
4
  derivePlanIdentityHash
5
- } from "./index-962qme08.js";
5
+ } from "./index-h439y187.js";
6
6
  import {
7
7
  DURABILITY_CLASSES,
8
8
  getProjectDb,
9
9
  projectDbExists,
10
10
  withImmediateTransaction
11
- } from "./index-hhkm64wh.js";
11
+ } from "./index-wst6n478.js";
12
12
  import {
13
13
  init_logger,
14
14
  warn
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  _internals,
4
4
  resolveWorktreeIsolationConfig
5
- } from "./index-s7a9dqtb.js";
5
+ } from "./index-xkf3672y.js";
6
6
  import {
7
7
  ApprovalEvidenceSchema,
8
8
  BaseEvidenceSchema,
@@ -44,7 +44,7 @@ import {
44
44
  loadPluginConfigWithMeta,
45
45
  loadPluginConfigWithMetaAsync,
46
46
  resetConfigAdvisoryDedup
47
- } from "./index-wjet7x0a.js";
47
+ } from "./index-91ww9hyr.js";
48
48
  import"./index-0mhftbpp.js";
49
49
  import"./index-a1w58b47.js";
50
50
  import {
@@ -70,7 +70,7 @@ import {
70
70
  TurboConfigSchema,
71
71
  WorktreeIsolationConfigSchema,
72
72
  resolveAutoReviewConfig
73
- } from "./index-2b1hd1fx.js";
73
+ } from "./index-apy1qfj0.js";
74
74
  import {
75
75
  ALL_AGENT_NAMES,
76
76
  ALL_SUBAGENT_NAMES,
@@ -80,7 +80,7 @@ import {
80
80
  QA_AGENTS,
81
81
  isQAAgent,
82
82
  isSubagent
83
- } from "./index-g5m43paw.js";
83
+ } from "./index-sxt7fgcw.js";
84
84
  import"./index-bk5tah7q.js";
85
85
  import"./index-bpmtbmy9.js";
86
86
  import"./index-zpsr8rpc.js";
@@ -9,7 +9,7 @@ import {
9
9
  readEvaluationRun,
10
10
  saveEvaluationRun,
11
11
  saveTaskSetSnapshot
12
- } from "./index-83r0v5tn.js";
12
+ } from "./index-gp9yzr1v.js";
13
13
  import {
14
14
  canonicalHash,
15
15
  computeCandidateInputContentHash,
@@ -13,7 +13,7 @@ import {
13
13
  import {
14
14
  SWARM_WORKTREE_DIR_NAME,
15
15
  init_constants
16
- } from "./index-g5m43paw.js";
16
+ } from "./index-sxt7fgcw.js";
17
17
  import {
18
18
  log
19
19
  } from "./index-zgwm4ryv.js";
@@ -92,7 +92,7 @@ var _internals = {
92
92
  symlinkSync: fs.symlinkSync
93
93
  },
94
94
  writeScopeToDisk: async (directory, taskId, files) => {
95
- const { writeScopeToDisk: realWrite } = await import("./scope-persistence-3xnr59y8.js");
95
+ const { writeScopeToDisk: realWrite } = await import("./scope-persistence-f540tc50.js");
96
96
  return realWrite(directory, taskId, files);
97
97
  },
98
98
  writeLaneProfileToDisk: async (_worktreePath, _laneIndex, _envOverrides) => {
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  authorizeCuration
4
- } from "./index-syedr4e3.js";
4
+ } from "./index-m35hybf0.js";
5
5
  import {
6
6
  findNearDuplicate,
7
7
  inferTags,
@@ -9,13 +9,13 @@ import {
9
9
  resolveSwarmKnowledgePath,
10
10
  resolveSwarmRejectedPath,
11
11
  transactKnowledge
12
- } from "./index-18rfc7qv.js";
12
+ } from "./index-2xbww1x0.js";
13
13
  import {
14
14
  resolveKnowledgeStoreDir
15
- } from "./index-0q839sg6.js";
15
+ } from "./index-8ybjqg51.js";
16
16
  import {
17
17
  atomicWriteFile
18
- } from "./index-vgpedapd.js";
18
+ } from "./index-4r5pmtvk.js";
19
19
  import {
20
20
  require_proper_lockfile
21
21
  } from "./index-7g4c7s5r.js";
@@ -1,12 +1,12 @@
1
1
  // @bun
2
2
  import {
3
3
  atomicWriteSwarmFile
4
- } from "./index-x7pm61wk.js";
4
+ } from "./index-v3xc4sde.js";
5
5
  import {
6
6
  pseudonymousRef,
7
7
  resolveLineageSalt,
8
8
  telemetry
9
- } from "./index-tcj8v6my.js";
9
+ } from "./index-z6qreakh.js";
10
10
  import {
11
11
  canonicalRootKeyFresh
12
12
  } from "./index-1xnse449.js";
@@ -7,8 +7,10 @@ function createNodeDatabaseCtor(DatabaseSyncCtor) {
7
7
  raw;
8
8
  stmts = new Map;
9
9
  savepointCounter = 0;
10
- constructor(filename) {
11
- this.raw = new DatabaseSyncCtor(filename, { allowExtension: true });
10
+ constructor(filename, options) {
11
+ const immutableReadOnly = typeof options === "number" && (options & 1) !== 0 && (options & 64) !== 0 && filename.startsWith("file:");
12
+ const readOnly = immutableReadOnly || typeof options === "object" && options?.readonly === true;
13
+ this.raw = new DatabaseSyncCtor(immutableReadOnly ? new URL(filename) : filename, readOnly ? { allowExtension: false, readOnly: true } : { allowExtension: true });
12
14
  }
13
15
  statement(sql) {
14
16
  let stmt = this.stmts.get(sql);
@@ -1350,6 +1350,7 @@ var init_constants = __esm(() => {
1350
1350
  lane_permissions: "scoped_allow",
1351
1351
  serialization_release_after_dispatches: 5,
1352
1352
  serialization_release_after_ms: 60000,
1353
+ session_create_timeout_ms: 30000,
1353
1354
  runtime_isolation: {
1354
1355
  enabled: false,
1355
1356
  port_stride: 1
@@ -229,9 +229,9 @@ var SWARM_TEMP_GRAMMARS = [
229
229
  "src/evidence/task-file.ts (pre-#2035; migrated-to=src/evidence/task-file.ts:atomicWriteFile)",
230
230
  "src/scope/scope-persistence.ts (pre-#2035; migrated-to=src/scope/scope-persistence.ts:atomicWrite)",
231
231
  "src/scope/scope-persistence.ts (pre-#2035; migrated-to=src/scope/scope-persistence.ts:atomicWriteSync)",
232
- "src/plan/manager.ts:630",
233
- "src/plan/manager.ts:1786",
234
- "src/plan/manager.ts:1832",
232
+ "src/plan/manager.ts:651",
233
+ "src/plan/manager.ts:1715",
234
+ "src/plan/manager.ts:1761",
235
235
  "src/review/evidence.ts:175",
236
236
  "src/turbo/lean/evidence.ts:182",
237
237
  "src/summaries/manager.ts:123",
@@ -247,7 +247,7 @@ var SWARM_TEMP_GRAMMARS = [
247
247
  "src/evidence/phase-participation.ts (pre-#2035; migrated-to=src/evidence/phase-participation.ts:atomicWriteBytes)",
248
248
  "src/turbo/lean/integration.ts:428",
249
249
  "src/turbo/lean/reviewer.ts:403",
250
- "src/plan/ledger.ts:746",
250
+ "src/plan/ledger.ts:1077",
251
251
  "src/services/synonym-map.ts:389",
252
252
  "src/services/skill-optimizer/store.ts:340",
253
253
  "src/services/skill-optimizer/store.ts:503",
@@ -267,7 +267,8 @@ var SWARM_TEMP_GRAMMARS = [
267
267
  producers: [
268
268
  "src/turbo/lean/state.ts:129",
269
269
  "src/turbo/lean/recovery.ts:175",
270
- "src/hooks/delegation-gate/worktree-merge-status.ts:110"
270
+ "src/hooks/delegation-gate/worktree-merge-status.ts:110",
271
+ "src/plan/ledger.ts:606"
271
272
  ]
272
273
  },
273
274
  {
@@ -360,7 +361,7 @@ var SWARM_TEMP_GRAMMARS = [
360
361
  token: "instance",
361
362
  quarantineEligible: true,
362
363
  parsesTarget: true,
363
- producers: ["src/plan/manager.ts:1972", "src/plan/manager.ts:2161"],
364
+ producers: ["src/plan/manager.ts:1901", "src/plan/manager.ts:2090"],
364
365
  note: "plan-durability (invariant 5) fd-write paths; grammars registered, writers unchanged in this PR"
365
366
  },
366
367
  {
@@ -426,8 +427,8 @@ var SWARM_TEMP_GRAMMARS = [
426
427
  "src/hooks/skill-usage-log.ts:1675",
427
428
  "src/hooks/skill-usage-pending.ts:817",
428
429
  "src/parallel/file-locks.ts:113",
429
- "src/plan/ledger.ts:1344",
430
- "src/plan/ledger.ts:1345"
430
+ "src/plan/ledger.ts:578",
431
+ "src/plan/ledger.ts:1756"
431
432
  ],
432
433
  note: "constant-name temps: reported when stale, never auto-quarantined. file-locks meta sidecars live under the scanner-skipped .swarm/locks/ subtree; the ledger reconcile temp embeds instance tokens but its .tmp-suffix shape maps here (conservatively report-only)"
433
434
  }
@@ -3,7 +3,7 @@ import {
3
3
  EvaluationRunV1Schema,
4
4
  GateAuditResultV1Schema,
5
5
  getProtectedEvaluationRunIds
6
- } from "./index-83r0v5tn.js";
6
+ } from "./index-gp9yzr1v.js";
7
7
  import {
8
8
  readEffectiveSpecSync
9
9
  } from "./index-9br68j86.js";
@@ -23,13 +23,13 @@ import {
23
23
  readTaskEvidence,
24
24
  readTaskEvidenceRaw,
25
25
  sanitizeTaskId
26
- } from "./index-3r6k6qa7.js";
26
+ } from "./index-gmpmgtzn.js";
27
27
  import {
28
28
  estimateCharsForTokens,
29
29
  estimateTokens,
30
30
  readSwarmFileAsync,
31
31
  validateSwarmPath
32
- } from "./index-8vbahc4c.js";
32
+ } from "./index-kear8gb7.js";
33
33
  import {
34
34
  bunHash,
35
35
  bunWrite,
@@ -52,15 +52,16 @@ import {
52
52
  normalizeExecutionProfileForHash,
53
53
  readLedgerEvents,
54
54
  readLedgerEventsWithIntegrity,
55
+ replacePlanLedgerWithRoot,
55
56
  replaceTruncatedLedgerWithRecoveryRoot,
56
57
  replayFromLedger,
57
58
  replayFromLedgerWithStatus,
58
59
  takeSnapshotEvent,
59
60
  takeSnapshotWithRetry
60
- } from "./index-z7z3g5wt.js";
61
+ } from "./index-gh9ybrrs.js";
61
62
  import {
62
63
  appendCoreEventSync
63
- } from "./index-z6we1abx.js";
64
+ } from "./index-a8xbvsse.js";
64
65
  import {
65
66
  derivePlanId,
66
67
  derivePlanIdentityHash,
@@ -68,32 +69,32 @@ import {
68
69
  importCoordinationOnce,
69
70
  listCoordinationStates,
70
71
  transitionCoordinationState
71
- } from "./index-962qme08.js";
72
+ } from "./index-h439y187.js";
72
73
  import {
73
74
  DURABILITY_CLASSES,
74
75
  getProjectDb,
75
76
  projectDbExists,
76
77
  withDurabilityClass
77
- } from "./index-hhkm64wh.js";
78
+ } from "./index-wst6n478.js";
78
79
  import {
79
80
  assertProjectRoot,
80
81
  tryAcquireLock,
81
82
  withEvidenceLock
82
- } from "./index-vgpedapd.js";
83
+ } from "./index-4r5pmtvk.js";
83
84
  import {
84
85
  atomicWriteSwarmFileSync,
85
86
  invalidateCachedArtifact,
86
87
  readCachedParsedFile
87
- } from "./index-x7pm61wk.js";
88
+ } from "./index-v3xc4sde.js";
88
89
  import {
89
90
  emit
90
- } from "./index-tcj8v6my.js";
91
+ } from "./index-z6qreakh.js";
91
92
  import {
92
93
  canonicalRootKeyFresh
93
94
  } from "./index-1xnse449.js";
94
95
  import {
95
96
  PlanSchema
96
- } from "./index-wjet7x0a.js";
97
+ } from "./index-91ww9hyr.js";
97
98
  import {
98
99
  GIT_BINARY_ENV_VAR,
99
100
  describeGitResolution,
@@ -119,12 +120,9 @@ import {
119
120
  // src/plan/manager.ts
120
121
  import {
121
122
  closeSync,
122
- copyFileSync,
123
- existsSync as existsSync3,
124
123
  fsyncSync,
125
124
  mkdirSync as mkdirSync2,
126
125
  openSync,
127
- readdirSync,
128
126
  renameSync as renameSync2,
129
127
  unlinkSync,
130
128
  writeFileSync
@@ -1880,6 +1878,8 @@ var PLAN_JSON_CACHE_NAMESPACE = "plan-json:validated:v1";
1880
1878
  var _internals5 = {
1881
1879
  loadPlan,
1882
1880
  loadPlanJsonOnly,
1881
+ readPlanJsonUtf8,
1882
+ readPlanFileUtf8,
1883
1883
  regeneratePlanMarkdown,
1884
1884
  isGitRepo,
1885
1885
  isEpicModeActiveForProject,
@@ -2038,14 +2038,20 @@ async function surfaceLedgerStaleIfPersisted(directory, plan) {
2038
2038
  }
2039
2039
  async function parsePlanJsonCached(directory) {
2040
2040
  const planJsonPath = path4.resolve(directory, ".swarm", "plan.json");
2041
- return readCachedParsedFile(planJsonPath, PLAN_JSON_CACHE_NAMESPACE, () => readSwarmFileAsync(directory, "plan.json"), (planJsonContent) => {
2042
- if (planJsonContent.includes("\x00") || planJsonContent.includes("\uFFFD")) {
2043
- throw new Error("Plan rejected: .swarm/plan.json contains null bytes or invalid encoding");
2041
+ return readCachedParsedFile(planJsonPath, PLAN_JSON_CACHE_NAMESPACE, () => _internals5.readPlanJsonUtf8(directory), (planJsonContent) => {
2042
+ if (planJsonContent.includes("\x00")) {
2043
+ throw new Error("Plan rejected: .swarm/plan.json contains null bytes");
2044
2044
  }
2045
2045
  const parsed = JSON.parse(planJsonContent);
2046
2046
  return PlanSchema.parse(parsed);
2047
2047
  });
2048
2048
  }
2049
+ async function readPlanJsonUtf8(directory) {
2050
+ return readSwarmFileAsync(directory, "plan.json", undefined, (filePath) => _internals5.readPlanFileUtf8(filePath), false);
2051
+ }
2052
+ async function readPlanFileUtf8(filePath) {
2053
+ return new TextDecoder("utf-8", { fatal: true }).decode(await fsPromises.readFile(filePath));
2054
+ }
2049
2055
  function computePlanContentHash(plan) {
2050
2056
  const content = {
2051
2057
  schema_version: plan.schema_version,
@@ -2117,10 +2123,15 @@ ${markdown}`;
2117
2123
  invalidateCachedArtifact(mdPath);
2118
2124
  }
2119
2125
  async function loadPlan(directory, cache) {
2120
- const planJsonContent = await readSwarmFileAsync(directory, "plan.json", cache);
2126
+ let planJsonContent = null;
2127
+ try {
2128
+ planJsonContent = await _internals5.readPlanJsonUtf8(directory);
2129
+ } catch (error2) {
2130
+ warn(`Plan rejected: .swarm/plan.json could not be decoded as valid UTF-8: ${error2 instanceof Error ? error2.message : String(error2)}`);
2131
+ }
2121
2132
  if (planJsonContent !== null) {
2122
- if (planJsonContent.includes("\x00") || planJsonContent.includes("\uFFFD")) {
2123
- warn("Plan rejected: .swarm/plan.json contains null bytes or invalid encoding");
2133
+ if (planJsonContent.includes("\x00")) {
2134
+ warn("Plan rejected: .swarm/plan.json contains null bytes");
2124
2135
  } else {
2125
2136
  try {
2126
2137
  const validated = await parsePlanJsonCached(directory);
@@ -2286,12 +2297,6 @@ async function loadPlan(directory, cache) {
2286
2297
  }
2287
2298
  }
2288
2299
  }
2289
- const planMdContent = await readSwarmFileAsync(directory, "plan.md", cache);
2290
- if (planMdContent !== null) {
2291
- const migrated = migrateLegacyPlan(planMdContent);
2292
- await savePlan(directory, migrated);
2293
- return migrated;
2294
- }
2295
2300
  if (await ledgerExists(directory)) {
2296
2301
  const resolvedDir = canonicalRootKeyFresh(directory);
2297
2302
  const existingMutex = recoveryMutexes.get(resolvedDir);
@@ -2354,6 +2359,12 @@ async function loadPlan(directory, cache) {
2354
2359
  recoveryMutexes.delete(resolvedDir);
2355
2360
  }
2356
2361
  }
2362
+ const planMdContent = await readSwarmFileAsync(directory, "plan.md", cache);
2363
+ if (planMdContent !== null) {
2364
+ const migrated = migrateLegacyPlan(planMdContent);
2365
+ await savePlan(directory, migrated);
2366
+ return migrated;
2367
+ }
2357
2368
  return null;
2358
2369
  }
2359
2370
  async function savePlanWithAutoAcknowledgedRemovals(directory, plan, source, reason, options) {
@@ -2378,6 +2389,20 @@ async function savePlanWithAutoAcknowledgedRemovals(directory, plan, source, rea
2378
2389
  });
2379
2390
  return { removedCount: removedIds.length };
2380
2391
  }
2392
+ async function withPlanLifecycleLock(directory, taskId, fn) {
2393
+ assertProjectRoot(directory);
2394
+ const lockResult = await tryAcquireLock(directory, "plan.json", "plan-lifecycle", taskId);
2395
+ if (!lockResult.acquired) {
2396
+ throw new PlanConcurrentModificationError(`Plan lifecycle blocked: plan.json is locked by ${lockResult.existing?.agent ?? "another agent"} (task: ${lockResult.existing?.taskId ?? "unknown"})`);
2397
+ }
2398
+ try {
2399
+ return await fn();
2400
+ } finally {
2401
+ if (lockResult.lock._release) {
2402
+ await lockResult.lock._release().catch(() => {});
2403
+ }
2404
+ }
2405
+ }
2381
2406
  async function savePlan(directory, plan, options) {
2382
2407
  if (directory === null || directory === undefined || typeof directory !== "string" || directory.trim().length === 0) {
2383
2408
  throw new Error(`Invalid directory: directory must be a non-empty string`);
@@ -2445,78 +2470,9 @@ async function savePlan(directory, plan, options) {
2445
2470
  } else {
2446
2471
  const existingEvents = await readLedgerEvents(directory);
2447
2472
  if (existingEvents.length > 0 && existingEvents[0].plan_id !== planId) {
2448
- const swarmDir2 = path4.resolve(directory, ".swarm");
2449
- const oldLedgerPath = path4.join(swarmDir2, "plan-ledger.jsonl");
2450
- const oldLedgerBackupPath = path4.join(swarmDir2, `plan-ledger.backup-${Date.now()}-${Math.floor(Math.random() * 1e9)}.jsonl`);
2451
- let backupExists = false;
2452
- if (existsSync3(oldLedgerPath)) {
2453
- try {
2454
- options?.preCommitCheck?.();
2455
- renameSync2(oldLedgerPath, oldLedgerBackupPath);
2456
- backupExists = true;
2457
- } catch (renameErr) {
2458
- throw new Error(`[savePlan] Cannot reinitialize ledger: could not move old ledger aside (rename failed: ${renameErr instanceof Error ? renameErr.message : String(renameErr)}). The existing ledger has plan_id="${existingEvents[0].plan_id}" which does not match the current plan="${planId}". To proceed, close any programs that may have the ledger file open, or run /swarm reset-session to clear the ledger.`);
2459
- }
2460
- }
2461
- let initSucceeded = false;
2462
- if (backupExists) {
2463
- try {
2464
- options?.preCommitCheck?.();
2465
- await initLedger(directory, planId, planHashForInit, validated);
2466
- initSucceeded = true;
2467
- } catch (initErr) {
2468
- const errorMessage2 = String(initErr);
2469
- if (errorMessage2.includes("already initialized")) {
2470
- try {
2471
- if (existsSync3(oldLedgerBackupPath))
2472
- unlinkSync(oldLedgerBackupPath);
2473
- } catch {}
2474
- } else {
2475
- if (existsSync3(oldLedgerBackupPath)) {
2476
- try {
2477
- renameSync2(oldLedgerBackupPath, oldLedgerPath);
2478
- } catch {
2479
- copyFileSync(oldLedgerBackupPath, oldLedgerPath);
2480
- try {
2481
- unlinkSync(oldLedgerBackupPath);
2482
- } catch {}
2483
- }
2484
- }
2485
- throw initErr;
2486
- }
2487
- }
2488
- }
2489
- if (initSucceeded && backupExists) {
2490
- const archivePath = path4.join(swarmDir2, `plan-ledger.archived-${Date.now()}-${Math.floor(Math.random() * 1e9)}.jsonl`);
2491
- try {
2492
- renameSync2(oldLedgerBackupPath, archivePath);
2493
- warn(`[savePlan] Ledger identity mismatch (was "${existingEvents[0].plan_id}", now "${planId}") \u2014 archived old ledger to ${archivePath} and reinitializing.`);
2494
- } catch (renameErr) {
2495
- warn(`[savePlan] Could not archive old ledger (rename failed: ${renameErr instanceof Error ? renameErr.message : String(renameErr)}). Old ledger may still exist at ${oldLedgerBackupPath}.`);
2496
- try {
2497
- if (existsSync3(oldLedgerBackupPath))
2498
- unlinkSync(oldLedgerBackupPath);
2499
- } catch {}
2500
- }
2501
- } else if (!initSucceeded && backupExists) {
2502
- try {
2503
- if (existsSync3(oldLedgerBackupPath))
2504
- unlinkSync(oldLedgerBackupPath);
2505
- } catch {}
2506
- }
2507
- const MAX_ARCHIVED_SIBLINGS = 5;
2508
- try {
2509
- const allFiles = readdirSync(swarmDir2);
2510
- const archivedSiblings = allFiles.filter((f) => f.startsWith("plan-ledger.archived-") && f.endsWith(".jsonl")).sort();
2511
- if (archivedSiblings.length > MAX_ARCHIVED_SIBLINGS) {
2512
- const toRemove = archivedSiblings.slice(0, archivedSiblings.length - MAX_ARCHIVED_SIBLINGS);
2513
- for (const file of toRemove) {
2514
- try {
2515
- unlinkSync(path4.join(swarmDir2, file));
2516
- } catch {}
2517
- }
2518
- }
2519
- } catch {}
2473
+ options?.preCommitCheck?.();
2474
+ await replacePlanLedgerWithRoot(directory, validated, "savePlan_identity_migration");
2475
+ warn(`[savePlan] Ledger identity mismatch (was "${existingEvents[0].plan_id}", now "${planId}") \u2014 archived the prior exact history and committed a new root.`);
2520
2476
  }
2521
2477
  }
2522
2478
  if (options?.staleProjectionReconcile) {
@@ -3339,7 +3295,7 @@ function migrateLegacyPlan(planContent, swarmId) {
3339
3295
  init_zod();
3340
3296
  import {
3341
3297
  mkdirSync as mkdirSync3,
3342
- readdirSync as readdirSync2,
3298
+ readdirSync,
3343
3299
  realpathSync,
3344
3300
  renameSync as renameSync3,
3345
3301
  rmSync,
@@ -3936,7 +3892,7 @@ async function listEvidenceTaskIds(directory) {
3936
3892
  }
3937
3893
  let entries;
3938
3894
  try {
3939
- entries = readdirSync2(evidenceBasePath);
3895
+ entries = readdirSync(evidenceBasePath);
3940
3896
  } catch {
3941
3897
  return [];
3942
3898
  }
@@ -4210,4 +4166,4 @@ function mergeDurableGateEntriesFromEvidence(taskId, entries, evidence) {
4210
4166
  return merged;
4211
4167
  }
4212
4168
 
4213
- export { normalizePath, buildTaskCompletionDescriptor, ensureTaskCheckpointReceipt, updateTaskCheckpointReceipt, MAX_TRANSIENT_RETRIES, isTransientSpawnError, transientBackoff, readLaneEnvFileFromDiskSync, getGitRepositoryStatus, isGitRepo, getDefaultBaseBranch, detectDefaultRemoteBranch, resetToRemoteBranch, resetToMainAfterMerge, isStateUnreadable, loadEpicSessionState, isEpicModeActive, enableEpicMode, disableEpicMode, pathsConflict, isGlobalFile, isProtectedPath, readTaskScopes, loadPlanJsonOnly, loadPlan, savePlan, closePlanTerminalState, updateTaskStatus, derivePlanMarkdown, isValidEvidenceType, isSecretscanEvidence, sanitizeTaskId2 as sanitizeTaskId, validateProjectRoot, saveEvidence, loadEvidence, listEvidenceTaskIds, checkRequirementCoverage, archiveEvidence, readDurableGateEvidence, getDurableGateEvidenceStatus, getDurableGateEvidenceStatusForTask, mergeDurableGateEntriesFromEvidence };
4169
+ export { normalizePath, buildTaskCompletionDescriptor, ensureTaskCheckpointReceipt, updateTaskCheckpointReceipt, MAX_TRANSIENT_RETRIES, isTransientSpawnError, transientBackoff, readLaneEnvFileFromDiskSync, getGitRepositoryStatus, isGitRepo, getDefaultBaseBranch, detectDefaultRemoteBranch, resetToRemoteBranch, resetToMainAfterMerge, isStateUnreadable, loadEpicSessionState, isEpicModeActive, enableEpicMode, disableEpicMode, pathsConflict, isGlobalFile, isProtectedPath, readTaskScopes, loadPlanJsonOnly, loadPlan, withPlanLifecycleLock, savePlan, closePlanTerminalState, updateTaskStatus, derivePlanMarkdown, isValidEvidenceType, isSecretscanEvidence, sanitizeTaskId2 as sanitizeTaskId, validateProjectRoot, saveEvidence, loadEvidence, listEvidenceTaskIds, checkRequirementCoverage, archiveEvidence, readDurableGateEvidence, getDurableGateEvidenceStatus, getDurableGateEvidenceStatusForTask, mergeDurableGateEntriesFromEvidence };
@@ -22,66 +22,66 @@ import {
22
22
  resolveFallbackModel,
23
23
  resolvePrimaryAgentNames,
24
24
  stripSwarmPrefix
25
- } from "./index-y1sj2e1n.js";
25
+ } from "./index-kkmezerc.js";
26
26
  import"./index-d5qf7hvh.js";
27
- import"./index-k73ehxa1.js";
28
- import"./index-dme7wvwg.js";
29
- import"./index-f8cc92g7.js";
30
- import"./index-rrne6g2m.js";
31
- import"./index-arqv4psy.js";
32
- import"./index-83r0v5tn.js";
27
+ import"./index-qhey6vc3.js";
28
+ import"./index-chebm5h5.js";
29
+ import"./index-nwwk3dej.js";
30
+ import"./index-5g6rhkn7.js";
31
+ import"./index-w1dfkp1q.js";
32
+ import"./index-gp9yzr1v.js";
33
33
  import"./index-txdagbh7.js";
34
34
  import"./index-9br68j86.js";
35
35
  import"./index-cw912re7.js";
36
- import"./index-f91fhch0.js";
37
- import"./index-ce8p9t28.js";
38
- import"./index-pdcperq5.js";
36
+ import"./index-xhb4gryr.js";
37
+ import"./index-bw9x8d8n.js";
38
+ import"./index-9b2105n0.js";
39
39
  import {
40
40
  createExplorerAgent
41
41
  } from "./index-fyfbpz4f.js";
42
- import"./index-mtepgqan.js";
42
+ import"./index-dfyv3xkd.js";
43
43
  import"./index-zsrtt42s.js";
44
- import"./index-5sjq3shs.js";
45
- import"./index-m7cwnt9r.js";
46
- import"./index-gmjg65tm.js";
44
+ import"./index-j0bxxz9d.js";
45
+ import"./index-5zqakgp4.js";
46
+ import"./index-bvqqwx84.js";
47
47
  import"./index-b43rt5ph.js";
48
48
  import"./index-q7sjgr1y.js";
49
- import"./index-3r6k6qa7.js";
50
- import"./index-09gv90d7.js";
51
- import"./index-sjkg2hc4.js";
52
- import"./index-m3z83nhs.js";
53
- import"./index-8vbahc4c.js";
49
+ import"./index-gmpmgtzn.js";
50
+ import"./index-qkwtth00.js";
51
+ import"./index-f1fps3w9.js";
52
+ import"./index-6df6wbvj.js";
53
+ import"./index-kear8gb7.js";
54
54
  import"./index-p612v1mv.js";
55
- import"./index-shrf0wt3.js";
56
- import"./index-syedr4e3.js";
55
+ import"./index-qthc56c4.js";
56
+ import"./index-m35hybf0.js";
57
57
  import"./index-rtry5xyf.js";
58
- import"./index-s7a9dqtb.js";
58
+ import"./index-xkf3672y.js";
59
59
  import"./index-3qf1vxtb.js";
60
60
  import"./index-n832052r.js";
61
- import"./index-jhd3pmd1.js";
62
- import"./index-z7z3g5wt.js";
63
- import"./index-z6we1abx.js";
64
- import"./index-g409c7ke.js";
65
- import"./index-962qme08.js";
66
- import"./index-hhkm64wh.js";
67
- import"./index-n4fzmqz8.js";
61
+ import"./index-y85aptep.js";
62
+ import"./index-gh9ybrrs.js";
63
+ import"./index-a8xbvsse.js";
64
+ import"./index-pyf517sz.js";
65
+ import"./index-h439y187.js";
66
+ import"./index-wst6n478.js";
67
+ import"./index-rdm3px0g.js";
68
68
  import"./index-ry16d01s.js";
69
- import"./index-gs12223x.js";
70
- import"./index-18rfc7qv.js";
69
+ import"./index-qwsh0h2g.js";
70
+ import"./index-2xbww1x0.js";
71
71
  import"./index-vzm6zre7.js";
72
72
  import"./index-ae75rja9.js";
73
- import"./index-0q839sg6.js";
74
- import"./index-vgpedapd.js";
73
+ import"./index-8ybjqg51.js";
74
+ import"./index-4r5pmtvk.js";
75
75
  import"./index-7g4c7s5r.js";
76
- import"./index-x7pm61wk.js";
77
- import"./index-tcj8v6my.js";
76
+ import"./index-v3xc4sde.js";
77
+ import"./index-z6qreakh.js";
78
78
  import"./index-1xnse449.js";
79
79
  import"./index-ee6ydtfe.js";
80
- import"./index-wjet7x0a.js";
80
+ import"./index-91ww9hyr.js";
81
81
  import"./index-0mhftbpp.js";
82
82
  import"./index-a1w58b47.js";
83
- import"./index-2b1hd1fx.js";
84
- import"./index-g5m43paw.js";
83
+ import"./index-apy1qfj0.js";
84
+ import"./index-sxt7fgcw.js";
85
85
  import"./index-bk5tah7q.js";
86
86
  import"./index-bpmtbmy9.js";
87
87
  import"./index-zpsr8rpc.js";