opencode-swarm 7.148.3 → 7.148.5

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 (65) hide show
  1. package/dist/background/delegation-health.d.ts +100 -0
  2. package/dist/background/pending-delegations.d.ts +97 -0
  3. package/dist/background/queue.d.ts +45 -7
  4. package/dist/background/worker.d.ts +24 -3
  5. package/dist/cli/{config-doctor-q3fw9744.js → config-doctor-6z7x0jnz.js} +2 -2
  6. package/dist/cli/{core-y72nw57z.js → core-0ph6pb2y.js} +1 -1
  7. package/dist/cli/{curation-policy-hkdghd3a.js → curation-policy-fbvctttr.js} +5 -5
  8. package/dist/cli/{curator-llm-factory-sdxsn88r.js → curator-llm-factory-mbsn281q.js} +26 -26
  9. package/dist/cli/{curator-bsr0xx05.js → curator-pffqw3br.js} +26 -26
  10. package/dist/cli/{evidence-summary-service-rk5exnrk.js → evidence-summary-service-9ajw5tpc.js} +10 -10
  11. package/dist/cli/{gate-evidence-cn0dvw8m.js → gate-evidence-wc8wzwaw.js} +5 -5
  12. package/dist/cli/{guardrail-explain-fnnka0vt.js → guardrail-explain-a8706sq1.js} +27 -27
  13. package/dist/cli/{guardrail-log-gsx9kj51.js → guardrail-log-wx43bj32.js} +3 -3
  14. package/dist/cli/{guardrail-reset-kk1rdmm0.js → guardrail-reset-sy0vztrd.js} +26 -26
  15. package/dist/cli/{hive-promoter-w7cr6qym.js → hive-promoter-jvyzykgx.js} +26 -26
  16. package/dist/cli/{index-4aqnb12y.js → index-0yzt06r5.js} +2 -2
  17. package/dist/cli/{index-3vescfdb.js → index-1w5nnyew.js} +6 -6
  18. package/dist/cli/{index-7a41ca8k.js → index-3aev3a0c.js} +1311 -99
  19. package/dist/cli/{index-b0703hjg.js → index-579qg534.js} +1 -1
  20. package/dist/cli/{index-08d3pb9a.js → index-59wqcatm.js} +1 -1
  21. package/dist/cli/{index-fp9d0e6f.js → index-5r2mcgpa.js} +1 -1
  22. package/dist/cli/{index-y8kppv1z.js → index-5zq3892p.js} +1 -1
  23. package/dist/cli/{index-x4kgn37c.js → index-8djgxw2w.js} +2 -2
  24. package/dist/cli/{index-kn36sxj0.js → index-ag9bv589.js} +28 -28
  25. package/dist/cli/{index-et35gcph.js → index-arjq717j.js} +1 -1
  26. package/dist/cli/{index-dh85aep3.js → index-c6jqkx9d.js} +2 -2
  27. package/dist/cli/{index-2d582j6q.js → index-haf092ak.js} +3 -3
  28. package/dist/cli/{index-ebt47fnp.js → index-j382eh60.js} +1 -1
  29. package/dist/cli/{index-xq8eydnk.js → index-jzz52as5.js} +4 -4
  30. package/dist/cli/{index-m5z2fgs4.js → index-k1s8gxjh.js} +1 -1
  31. package/dist/cli/{index-zpn3wqvp.js → index-kg4knw6r.js} +2 -2
  32. package/dist/cli/{index-8w63kj4x.js → index-kj6m9ry3.js} +4 -4
  33. package/dist/cli/{index-dmbvep3q.js → index-ne45ew6z.js} +6 -6
  34. package/dist/cli/{index-r9g7ymv2.js → index-nq4tkfpc.js} +1 -1
  35. package/dist/cli/{index-harsx832.js → index-q7ke7kwd.js} +4 -4
  36. package/dist/cli/{index-hwfs0ze1.js → index-qbsc2btq.js} +3 -3
  37. package/dist/cli/{index-2n9rwvcc.js → index-qwmrt51t.js} +1 -1
  38. package/dist/cli/{index-092deqxs.js → index-t25evmna.js} +400 -12
  39. package/dist/cli/{index-2zz8b0rb.js → index-vhefvcta.js} +2 -2
  40. package/dist/cli/{index-rsn4jm90.js → index-vrp2zva8.js} +1 -1
  41. package/dist/cli/{index-afwwz4py.js → index-vyg5b8ee.js} +5 -5
  42. package/dist/cli/{index-8sz9t8s2.js → index-x3d9asnz.js} +2 -2
  43. package/dist/cli/{index-65jw48eb.js → index-yezd5ks6.js} +1 -1
  44. package/dist/cli/{index-8y79znpe.js → index-zf2vwa7y.js} +2 -2
  45. package/dist/cli/{index-c9xfy8yj.js → index-zhn0q7nf.js} +5 -5
  46. package/dist/cli/index.js +26 -26
  47. package/dist/cli/{knowledge-escalator-jxpz0mv5.js → knowledge-escalator-bvrtfdyb.js} +10 -10
  48. package/dist/cli/{knowledge-events-kjwmc21q.js → knowledge-events-rpvkevbm.js} +8 -8
  49. package/dist/cli/{knowledge-link-5dctq0ax.js → knowledge-link-spw879rs.js} +4 -4
  50. package/dist/cli/{knowledge-store-j9bzs7zx.js → knowledge-store-wjy2kshh.js} +5 -5
  51. package/dist/cli/{knowledge-validator-56w52rwr.js → knowledge-validator-cq2cgfcx.js} +7 -7
  52. package/dist/cli/{pending-delegations-h4gr264y.js → pending-delegations-f4wvyzbf.js} +10 -2
  53. package/dist/cli/{pr-subscriptions-9mg6mwc0.js → pr-subscriptions-f4xw1rxy.js} +2 -2
  54. package/dist/cli/{runner-9g2pcg10.js → runner-rk26nk58.js} +5 -5
  55. package/dist/cli/{scan-cursor-7xbrxm2c.js → scan-cursor-7n0zs72g.js} +6 -6
  56. package/dist/cli/{schema-gcjdpfr9.js → schema-e59spg93.js} +1 -1
  57. package/dist/cli/{scope-persistence-2n9nk833.js → scope-persistence-d75p900m.js} +6 -6
  58. package/dist/cli/{skill-generator-z70bhhx9.js → skill-generator-c65y1h6a.js} +12 -12
  59. package/dist/cli/{worktree-collision-ownership-e0p490vw.js → worktree-collision-ownership-wqy7mgb3.js} +2 -2
  60. package/dist/cli/{worktree-isolation-vg6g00mq.js → worktree-isolation-ay9d58w4.js} +26 -26
  61. package/dist/hooks/delegation-gate.d.ts +1 -0
  62. package/dist/index.js +23 -19
  63. package/dist/sast/rules/javascript-call-classifier.d.ts +4 -0
  64. package/dist/services/status-service.d.ts +55 -3
  65. package/package.json +1 -1
@@ -6,8 +6,9 @@ import {
6
6
  bunWrite
7
7
  } from "./index-r3mvsbtq.js";
8
8
  import {
9
+ EvidenceLockTimeoutError,
9
10
  withEvidenceLock
10
- } from "./index-rsn4jm90.js";
11
+ } from "./index-vrp2zva8.js";
11
12
  import {
12
13
  exports_external,
13
14
  init_zod
@@ -74,6 +75,38 @@ var UncertaintySectionSchema = exports_external.object({
74
75
  source: exports_external.string().min(1).max(256),
75
76
  repairHint: exports_external.string().min(1).max(2000).optional()
76
77
  }).strict();
78
+ var MAX_MAINTENANCE_FACTS = 20;
79
+ var DelegationMaintenanceFactSchema = exports_external.object({
80
+ at: exports_external.number().int().nonnegative(),
81
+ kind: exports_external.enum([
82
+ "release",
83
+ "retained-ambiguity",
84
+ "retained-protected-legacy",
85
+ "lease-renewed",
86
+ "maintenance-failure",
87
+ "lock-contention"
88
+ ]),
89
+ reservationId: exports_external.string().min(1).max(256).optional(),
90
+ correlationId: exports_external.string().min(1).max(256).optional(),
91
+ generation: exports_external.number().int().positive().optional(),
92
+ reason: exports_external.string().min(1).max(2000)
93
+ }).strict();
94
+ var MaintenanceSectionSchema = exports_external.object({
95
+ lastRunAt: exports_external.number().int().nonnegative(),
96
+ lastOkAt: exports_external.number().int().nonnegative().nullable(),
97
+ lastFailure: exports_external.object({
98
+ reason: exports_external.string().min(1).max(2000),
99
+ at: exports_external.number().int().nonnegative()
100
+ }).strict().nullable(),
101
+ lastContentionAt: exports_external.number().int().nonnegative().nullable(),
102
+ lastSummary: exports_external.object({
103
+ sweptStale: exports_external.number().int().nonnegative(),
104
+ released: exports_external.number().int().nonnegative(),
105
+ renewed: exports_external.number().int().nonnegative(),
106
+ retained: exports_external.number().int().nonnegative()
107
+ }).strict(),
108
+ facts: exports_external.array(DelegationMaintenanceFactSchema).max(MAX_MAINTENANCE_FACTS)
109
+ }).strict();
77
110
  var DelegationLedgerHealthSchema = exports_external.object({
78
111
  schemaVersion: exports_external.literal(1),
79
112
  updatedAt: exports_external.number().int().nonnegative(),
@@ -91,7 +124,8 @@ var DelegationLedgerHealthSchema = exports_external.object({
91
124
  pendingAdvisories: exports_external.number().int().nonnegative(),
92
125
  lateTerminals: exports_external.number().int().nonnegative(),
93
126
  orphanWorktreeOwners: exports_external.number().int().nonnegative()
94
- }).strict()
127
+ }).strict(),
128
+ maintenance: MaintenanceSectionSchema.nullable().optional()
95
129
  }).strict();
96
130
  function sleepSync(ms) {
97
131
  try {
@@ -142,7 +176,8 @@ function writeDelegationHealthArtifact(directory, update) {
142
176
  pendingAdvisories: 0,
143
177
  lateTerminals: 0,
144
178
  orphanWorktreeOwners: 0
145
- }
179
+ },
180
+ maintenance: null
146
181
  };
147
182
  const next = {
148
183
  schemaVersion: 1,
@@ -151,7 +186,8 @@ function writeDelegationHealthArtifact(directory, update) {
151
186
  checkpoint: update.checkpoint === undefined ? base.checkpoint : update.checkpoint,
152
187
  recovery: update.recovery === undefined ? base.recovery : update.recovery,
153
188
  lastUncertainty: update.lastUncertainty ?? base.lastUncertainty,
154
- counts: update.counts ?? base.counts
189
+ counts: update.counts ?? base.counts,
190
+ maintenance: update.maintenance === undefined ? base.maintenance ?? null : update.maintenance
155
191
  };
156
192
  if (update.uncertainty) {
157
193
  next.lastUncertainty = update.uncertainty;
@@ -192,6 +228,26 @@ function writeDelegationHealthArtifact(directory, update) {
192
228
  return null;
193
229
  }
194
230
  }
231
+ function appendDelegationMaintenanceObservation(directory, observation) {
232
+ try {
233
+ const existing = readDelegationHealthArtifact(directory);
234
+ const current = existing?.maintenance ?? null;
235
+ const section = {
236
+ lastRunAt: observation.at,
237
+ lastOkAt: observation.status === "ok" ? observation.at : current?.lastOkAt ?? null,
238
+ lastFailure: observation.status === "failure" && observation.reason ? { reason: observation.reason, at: observation.at } : current?.lastFailure ?? null,
239
+ lastContentionAt: observation.status === "contention" ? observation.at : current?.lastContentionAt ?? null,
240
+ lastSummary: observation.summary ?? current?.lastSummary ?? {
241
+ sweptStale: 0,
242
+ released: 0,
243
+ renewed: 0,
244
+ retained: 0
245
+ },
246
+ facts: [...current?.facts ?? [], ...observation.facts].slice(-MAX_MAINTENANCE_FACTS)
247
+ };
248
+ writeDelegationHealthArtifact(directory, { maintenance: section });
249
+ } catch {}
250
+ }
195
251
  function collectDelegationLedgerHealth(directory, options) {
196
252
  const artifact = readDelegationHealthArtifact(directory);
197
253
  let ledgerBytes = 0;
@@ -219,7 +275,8 @@ function collectDelegationLedgerHealth(directory, options) {
219
275
  pendingAdvisories: 0,
220
276
  lateTerminals: 0,
221
277
  orphanWorktreeOwners: 0
222
- }
278
+ },
279
+ maintenance: artifact?.maintenance ?? null
223
280
  };
224
281
  }
225
282
 
@@ -345,6 +402,19 @@ var RESERVATION_LOCK_TASK = "background-coder-reservations";
345
402
  var ADVISORY_PREPARE_LEASE_MS = 30000;
346
403
  var INGESTION_CLAIM_LEASE_MS = 30000;
347
404
  var BACKGROUND_INGESTION_LEASE_MS = 30000;
405
+ var BACKGROUND_CODER_RESERVATION_LEASE_MS = 15 * 60000;
406
+ var BACKGROUND_CODER_RESERVATION_LEASE_MAX_MS = 60 * 60000;
407
+ var BACKGROUND_CODER_RESERVATION_LEASE_MIN_MS = 60000;
408
+ function clampReservationLeaseMs(leaseMs) {
409
+ if (leaseMs === undefined)
410
+ return BACKGROUND_CODER_RESERVATION_LEASE_MS;
411
+ if (!Number.isFinite(leaseMs))
412
+ return BACKGROUND_CODER_RESERVATION_LEASE_MS;
413
+ return Math.min(Math.max(Math.round(leaseMs), BACKGROUND_CODER_RESERVATION_LEASE_MIN_MS), BACKGROUND_CODER_RESERVATION_LEASE_MAX_MS);
414
+ }
415
+ function isValidReservationGeneration(generation) {
416
+ return generation === undefined || Number.isInteger(generation) && generation >= 1 && generation <= MAX_BACKGROUND_DELEGATION_GENERATION;
417
+ }
348
418
  var DEFAULT_STALE_DELEGATION_TIMEOUT_MS = 30 * 60000;
349
419
  var DEFAULT_SWEEPABLE_DELEGATION_STATUSES = new Set(["pending", "running", "ingestion_error"]);
350
420
  var WorkflowLaneRecoverySchema = exports_external.object({
@@ -500,6 +570,8 @@ var BackgroundCoderReservationSchema = exports_external.object({
500
570
  callID: exports_external.string().min(1).max(256),
501
571
  state: exports_external.enum(["reserved", "bound"]),
502
572
  correlationId: exports_external.string().min(1).max(256).nullable(),
573
+ generation: exports_external.number().int().min(1).max(MAX_BACKGROUND_DELEGATION_GENERATION).optional(),
574
+ leaseExpiresAt: exports_external.number().int().nonnegative().optional(),
503
575
  createdAt: exports_external.number().int().nonnegative(),
504
576
  updatedAt: exports_external.number().int().nonnegative()
505
577
  }).strict().superRefine((value, context) => {
@@ -2196,13 +2268,15 @@ function findOpenAsyncLaneBatches(directory) {
2196
2268
  function isTerminal(status) {
2197
2269
  return status === "completed" || status === "error" || status === "cancelled" || status === "stale" || status === "consumed";
2198
2270
  }
2199
- function sweepStaleLocked(directory, timeoutMs, now, statuses = DEFAULT_SWEEPABLE_DELEGATION_STATUSES, filters = {}) {
2271
+ function sweepStaleLocked(directory, timeoutMs, now, statuses = DEFAULT_SWEEPABLE_DELEGATION_STATUSES, filters = {}, limits = {}) {
2200
2272
  let swept = 0;
2201
2273
  const { excludeCorrelationIds, includeCorrelationIds } = filters;
2202
2274
  const records = loadRecordsForWrite(directory);
2203
2275
  if (records === null)
2204
2276
  return 0;
2205
2277
  for (const record of records) {
2278
+ if (limits.maxSweep !== undefined && swept >= limits.maxSweep)
2279
+ break;
2206
2280
  if (includeCorrelationIds !== undefined && !includeCorrelationIds.has(record.correlationId)) {
2207
2281
  continue;
2208
2282
  }
@@ -2627,7 +2701,7 @@ function validateReservationIdentity(input) {
2627
2701
  return typeof input.parentSessionId === "string" && input.parentSessionId.length > 0 && input.parentSessionId.length <= 256 && input.parentSessionId.trim() === input.parentSessionId && typeof input.callID === "string" && input.callID.length > 0 && input.callID.length <= 256 && input.callID.trim() === input.callID && (input.planTaskId === null || typeof input.planTaskId === "string" && input.planTaskId.length > 0 && input.planTaskId.length <= 256 && input.planTaskId.trim() === input.planTaskId);
2628
2702
  }
2629
2703
  async function reserveBackgroundCoderSlot(directory, input) {
2630
- if (!validateReservationIdentity(input) || !Number.isInteger(input.maxConcurrent) || input.maxConcurrent < 1 || input.maxConcurrent > 64 || (input.occupiedTaskIds?.length ?? 0) > 64) {
2704
+ if (!validateReservationIdentity(input) || !Number.isInteger(input.maxConcurrent) || input.maxConcurrent < 1 || input.maxConcurrent > 64 || (input.occupiedTaskIds?.length ?? 0) > 64 || !isValidReservationGeneration(input.generation)) {
2631
2705
  return { ok: false, reason: "invalid" };
2632
2706
  }
2633
2707
  const occupiedTaskIds = new Set;
@@ -2722,6 +2796,7 @@ async function reserveBackgroundCoderSlot(directory, input) {
2722
2796
  };
2723
2797
  }
2724
2798
  const now = input.now ?? Date.now();
2799
+ const leaseMs = clampReservationLeaseMs(input.leaseMs);
2725
2800
  const reservation = {
2726
2801
  reservationId,
2727
2802
  parentSessionId: input.parentSessionId,
@@ -2729,6 +2804,8 @@ async function reserveBackgroundCoderSlot(directory, input) {
2729
2804
  callID: input.callID,
2730
2805
  state: "reserved",
2731
2806
  correlationId: null,
2807
+ generation: input.generation ?? 1,
2808
+ leaseExpiresAt: now + leaseMs,
2732
2809
  createdAt: now,
2733
2810
  updatedAt: now
2734
2811
  };
@@ -2757,7 +2834,7 @@ async function reserveBackgroundCoderSlot(directory, input) {
2757
2834
  }
2758
2835
  }
2759
2836
  async function bindBackgroundCoderReservation(directory, input) {
2760
- if (!validateReservationIdentity(input) || !input.reservationId || !input.correlationId || input.correlationId.length > 256 || input.correlationId.trim() !== input.correlationId || input.reservationId !== buildBackgroundCoderReservationId(input)) {
2837
+ if (!validateReservationIdentity(input) || !input.reservationId || !input.correlationId || input.correlationId.length > 256 || input.correlationId.trim() !== input.correlationId || input.reservationId !== buildBackgroundCoderReservationId(input) || !isValidReservationGeneration(input.generation)) {
2761
2838
  return null;
2762
2839
  }
2763
2840
  try {
@@ -2773,13 +2850,32 @@ async function bindBackgroundCoderReservation(directory, input) {
2773
2850
  return null;
2774
2851
  }
2775
2852
  if (current.state === "bound") {
2776
- return current.correlationId === input.correlationId ? current : null;
2853
+ if (current.correlationId !== input.correlationId)
2854
+ return null;
2855
+ const now2 = input.now ?? Date.now();
2856
+ const leaseMs2 = clampReservationLeaseMs(input.leaseMs);
2857
+ const next2 = {
2858
+ ...current,
2859
+ leaseExpiresAt: now2 + leaseMs2,
2860
+ updatedAt: now2
2861
+ };
2862
+ const reservations2 = [...scan.reservations];
2863
+ reservations2[index] = next2;
2864
+ return await writeBackgroundCoderReservations(directory, reservations2) ? next2 : current;
2865
+ }
2866
+ const currentGeneration = current.generation ?? 1;
2867
+ if (input.generation !== undefined && input.generation < currentGeneration) {
2868
+ return null;
2777
2869
  }
2870
+ const now = input.now ?? Date.now();
2871
+ const leaseMs = clampReservationLeaseMs(input.leaseMs);
2778
2872
  const next = {
2779
2873
  ...current,
2780
2874
  state: "bound",
2781
2875
  correlationId: input.correlationId,
2782
- updatedAt: input.now ?? Date.now()
2876
+ ...input.generation !== undefined || current.generation === undefined ? { generation: input.generation ?? currentGeneration } : {},
2877
+ leaseExpiresAt: now + leaseMs,
2878
+ updatedAt: now
2783
2879
  };
2784
2880
  const reservations = [...scan.reservations];
2785
2881
  reservations[index] = next;
@@ -2790,7 +2886,7 @@ async function bindBackgroundCoderReservation(directory, input) {
2790
2886
  }
2791
2887
  }
2792
2888
  async function releaseBackgroundCoderReservation(directory, input) {
2793
- if (!validateReservationIdentity(input) || !input.reservationId || input.reservationId !== buildBackgroundCoderReservationId(input) || input.correlationId !== null && (input.correlationId.length === 0 || input.correlationId.length > 256 || input.correlationId.trim() !== input.correlationId)) {
2889
+ if (!validateReservationIdentity(input) || !input.reservationId || input.reservationId !== buildBackgroundCoderReservationId(input) || input.correlationId !== null && (input.correlationId.length === 0 || input.correlationId.length > 256 || input.correlationId.trim() !== input.correlationId) || !isValidReservationGeneration(input.generation)) {
2794
2890
  return false;
2795
2891
  }
2796
2892
  try {
@@ -2805,6 +2901,10 @@ async function releaseBackgroundCoderReservation(directory, input) {
2805
2901
  if (current.parentSessionId !== input.parentSessionId || current.planTaskId !== input.planTaskId || current.callID !== input.callID || current.correlationId !== input.correlationId) {
2806
2902
  return false;
2807
2903
  }
2904
+ if (input.generation !== undefined && current.generation !== undefined && input.generation !== current.generation) {
2905
+ warn(`[background] refusing reservation release: terminal generation ${input.generation} does not match owned generation ${current.generation} for ${input.reservationId}`);
2906
+ return false;
2907
+ }
2808
2908
  if (input.reason === "consumed") {
2809
2909
  if (current.state !== "bound" || !current.correlationId) {
2810
2910
  return false;
@@ -2824,5 +2924,293 @@ async function releaseBackgroundCoderReservation(directory, input) {
2824
2924
  return false;
2825
2925
  }
2826
2926
  }
2927
+ var DEFAULT_MAINTENANCE_LOCK_TIMEOUT_MS = 5000;
2928
+ var DEFAULT_MAINTENANCE_BATCH = 256;
2929
+ async function maintainBackgroundDelegations(directory, options = {}) {
2930
+ const now = options.now ?? Date.now();
2931
+ const staleTimeoutMs = options.staleTimeoutMs ?? DEFAULT_STALE_DELEGATION_TIMEOUT_MS;
2932
+ const maxRecords = options.maxRecords ?? DEFAULT_MAINTENANCE_BATCH;
2933
+ const lockTimeoutMs = options.lockTimeoutMs ?? DEFAULT_MAINTENANCE_LOCK_TIMEOUT_MS;
2934
+ const reason = options.reason ?? "manual";
2935
+ const result = {
2936
+ status: "ok",
2937
+ sweptStale: 0,
2938
+ released: [],
2939
+ renewed: [],
2940
+ retained: [],
2941
+ examinedReservations: 0
2942
+ };
2943
+ const facts = [];
2944
+ const emitObservation = (status, failureReason) => {
2945
+ appendDelegationMaintenanceObservation(directory, {
2946
+ at: now,
2947
+ status,
2948
+ reason: failureReason,
2949
+ summary: status === "ok" ? {
2950
+ sweptStale: result.sweptStale,
2951
+ released: result.released.length,
2952
+ renewed: result.renewed.length,
2953
+ retained: result.retained.length
2954
+ } : undefined,
2955
+ facts
2956
+ });
2957
+ return {
2958
+ ...result,
2959
+ status,
2960
+ ...failureReason ? { reason: failureReason } : {}
2961
+ };
2962
+ };
2963
+ try {
2964
+ result.sweptStale = await withEvidenceLock(directory, BACKGROUND_DELEGATIONS_FILE, STORE_LOCK_AGENT, STORE_LOCK_TASK, async () => sweepStaleLocked(directory, staleTimeoutMs, now, DEFAULT_SWEEPABLE_DELEGATION_STATUSES, {}, { maxSweep: maxRecords }), lockTimeoutMs);
2965
+ } catch (error) {
2966
+ if (error instanceof EvidenceLockTimeoutError) {
2967
+ facts.push({
2968
+ at: now,
2969
+ kind: "lock-contention",
2970
+ reason: `maintenance point '${reason}' skipped: delegations store lock contended`
2971
+ });
2972
+ return emitObservation("contention", error.message);
2973
+ }
2974
+ facts.push({
2975
+ at: now,
2976
+ kind: "maintenance-failure",
2977
+ reason: `maintenance point '${reason}' sweep failed: ${error instanceof Error ? error.message : String(error)}`
2978
+ });
2979
+ return emitObservation("failure", error instanceof Error ? error.message : String(error));
2980
+ }
2981
+ try {
2982
+ await withEvidenceLock(directory, BACKGROUND_CODER_RESERVATIONS_FILE, STORE_LOCK_AGENT, RESERVATION_LOCK_TASK, async () => {
2983
+ const reservationScan = scanBackgroundCoderReservationsForAdmission(directory);
2984
+ if (reservationScan.status === "uncertain") {
2985
+ result.status = "failure";
2986
+ result.reason = reservationScan.reason;
2987
+ facts.push({
2988
+ at: now,
2989
+ kind: "maintenance-failure",
2990
+ reason: `reservation store uncertain: ${reservationScan.reason}`
2991
+ });
2992
+ return;
2993
+ }
2994
+ const ownerScan = await scanDurableCoderOwners(directory);
2995
+ if (ownerScan.status === "uncertain") {
2996
+ result.status = "failure";
2997
+ result.reason = ownerScan.reason;
2998
+ facts.push({
2999
+ at: now,
3000
+ kind: "maintenance-failure",
3001
+ reason: `owner evidence uncertain; all reservations retained: ${ownerScan.reason}`
3002
+ });
3003
+ return;
3004
+ }
3005
+ const batch = reservationScan.reservations.slice(0, maxRecords);
3006
+ result.examinedReservations = batch.length;
3007
+ const next = [];
3008
+ let mutated = false;
3009
+ for (const reservation of batch) {
3010
+ const generation = reservation.generation ?? 1;
3011
+ const primary = findExactPrimaryReservationOwner(reservation, ownerScan);
3012
+ if (primary && hasProvenReleasedReservationOwner(primary)) {
3013
+ if ((primary.generation ?? 1) !== generation) {
3014
+ result.retained.push({
3015
+ reservationId: reservation.reservationId,
3016
+ reason: "owner-terminal-older-generation"
3017
+ });
3018
+ facts.push({
3019
+ at: now,
3020
+ kind: "retained-ambiguity",
3021
+ reservationId: reservation.reservationId,
3022
+ correlationId: reservation.correlationId ?? undefined,
3023
+ generation,
3024
+ reason: `proven-terminal owner is generation ${primary.generation ?? 1}, reservation owns ${generation}`
3025
+ });
3026
+ next.push(reservation);
3027
+ continue;
3028
+ }
3029
+ mutated = true;
3030
+ result.released.push({
3031
+ reservationId: reservation.reservationId,
3032
+ generation,
3033
+ reason: "proven-terminal-owner"
3034
+ });
3035
+ facts.push({
3036
+ at: now,
3037
+ kind: "release",
3038
+ reservationId: reservation.reservationId,
3039
+ correlationId: reservation.correlationId ?? undefined,
3040
+ generation,
3041
+ reason: "proven-terminal-owner"
3042
+ });
3043
+ continue;
3044
+ }
3045
+ if (reservation.leaseExpiresAt === undefined) {
3046
+ result.retained.push({
3047
+ reservationId: reservation.reservationId,
3048
+ reason: "protected-legacy-no-lease"
3049
+ });
3050
+ facts.push({
3051
+ at: now,
3052
+ kind: "retained-protected-legacy",
3053
+ reservationId: reservation.reservationId,
3054
+ generation,
3055
+ reason: "legacy reservation without leaseExpiresAt"
3056
+ });
3057
+ next.push(reservation);
3058
+ continue;
3059
+ }
3060
+ const leaseExpired = reservation.leaseExpiresAt <= now;
3061
+ if (!leaseExpired) {
3062
+ next.push(reservation);
3063
+ continue;
3064
+ }
3065
+ if (primary) {
3066
+ if ((primary.generation ?? 1) !== generation) {
3067
+ result.retained.push({
3068
+ reservationId: reservation.reservationId,
3069
+ reason: "owner-older-generation"
3070
+ });
3071
+ facts.push({
3072
+ at: now,
3073
+ kind: "retained-ambiguity",
3074
+ reservationId: reservation.reservationId,
3075
+ correlationId: reservation.correlationId ?? undefined,
3076
+ generation,
3077
+ reason: `owner record is generation ${primary.generation ?? 1}, reservation owns ${generation}`
3078
+ });
3079
+ next.push(reservation);
3080
+ continue;
3081
+ }
3082
+ if (primary.status === "stale") {
3083
+ mutated = true;
3084
+ result.released.push({
3085
+ reservationId: reservation.reservationId,
3086
+ generation,
3087
+ reason: "owner-swept-stale"
3088
+ });
3089
+ facts.push({
3090
+ at: now,
3091
+ kind: "release",
3092
+ reservationId: reservation.reservationId,
3093
+ correlationId: reservation.correlationId ?? undefined,
3094
+ generation,
3095
+ reason: "owner record durably stale"
3096
+ });
3097
+ continue;
3098
+ }
3099
+ if (isActiveCoderOwner(primary)) {
3100
+ mutated = true;
3101
+ result.renewed.push({
3102
+ reservationId: reservation.reservationId,
3103
+ generation
3104
+ });
3105
+ facts.push({
3106
+ at: now,
3107
+ kind: "lease-renewed",
3108
+ reservationId: reservation.reservationId,
3109
+ correlationId: reservation.correlationId ?? undefined,
3110
+ generation,
3111
+ reason: "exact owner record still active"
3112
+ });
3113
+ next.push({
3114
+ ...reservation,
3115
+ leaseExpiresAt: now + BACKGROUND_CODER_RESERVATION_LEASE_MS,
3116
+ updatedAt: now
3117
+ });
3118
+ continue;
3119
+ }
3120
+ result.retained.push({
3121
+ reservationId: reservation.reservationId,
3122
+ reason: "owner-terminal-unproven"
3123
+ });
3124
+ facts.push({
3125
+ at: now,
3126
+ kind: "retained-ambiguity",
3127
+ reservationId: reservation.reservationId,
3128
+ correlationId: reservation.correlationId ?? undefined,
3129
+ generation,
3130
+ reason: `owner status '${primary.status}' does not prove release`
3131
+ });
3132
+ next.push(reservation);
3133
+ continue;
3134
+ }
3135
+ if (reservation.correlationId !== null && ownerScan.recordsByCorrelation.has(reservation.correlationId)) {
3136
+ result.retained.push({
3137
+ reservationId: reservation.reservationId,
3138
+ reason: "owner-identity-mismatch"
3139
+ });
3140
+ facts.push({
3141
+ at: now,
3142
+ kind: "retained-ambiguity",
3143
+ reservationId: reservation.reservationId,
3144
+ correlationId: reservation.correlationId ?? undefined,
3145
+ generation,
3146
+ reason: "correlation exists under a different owner identity"
3147
+ });
3148
+ next.push(reservation);
3149
+ continue;
3150
+ }
3151
+ if (now - reservation.createdAt > staleTimeoutMs) {
3152
+ mutated = true;
3153
+ result.released.push({
3154
+ reservationId: reservation.reservationId,
3155
+ generation,
3156
+ reason: "unbound-orphan"
3157
+ });
3158
+ facts.push({
3159
+ at: now,
3160
+ kind: "release",
3161
+ reservationId: reservation.reservationId,
3162
+ generation,
3163
+ reason: "no durable owner anywhere and pre-launch window exceeded"
3164
+ });
3165
+ continue;
3166
+ }
3167
+ result.retained.push({
3168
+ reservationId: reservation.reservationId,
3169
+ reason: "unbound-within-stale-window"
3170
+ });
3171
+ facts.push({
3172
+ at: now,
3173
+ kind: "retained-ambiguity",
3174
+ reservationId: reservation.reservationId,
3175
+ generation,
3176
+ reason: "no owner record yet; still inside the pre-launch stale window"
3177
+ });
3178
+ next.push(reservation);
3179
+ }
3180
+ next.push(...reservationScan.reservations.slice(maxRecords));
3181
+ if (mutated) {
3182
+ const written = await writeBackgroundCoderReservations(directory, next);
3183
+ if (!written) {
3184
+ result.status = "failure";
3185
+ result.reason = "reservation reconciliation could not be persisted";
3186
+ facts.push({
3187
+ at: now,
3188
+ kind: "maintenance-failure",
3189
+ reason: "reservation store write failed during reconciliation"
3190
+ });
3191
+ }
3192
+ }
3193
+ }, lockTimeoutMs);
3194
+ } catch (error) {
3195
+ if (error instanceof EvidenceLockTimeoutError) {
3196
+ facts.push({
3197
+ at: now,
3198
+ kind: "lock-contention",
3199
+ reason: `maintenance point '${reason}' skipped: reservation store lock contended`
3200
+ });
3201
+ return emitObservation("contention", error.message);
3202
+ }
3203
+ facts.push({
3204
+ at: now,
3205
+ kind: "maintenance-failure",
3206
+ reason: `maintenance point '${reason}' reconciliation failed: ${error instanceof Error ? error.message : String(error)}`
3207
+ });
3208
+ return emitObservation("failure", error instanceof Error ? error.message : String(error));
3209
+ }
3210
+ if (result.status === "failure") {
3211
+ return emitObservation("failure", result.reason);
3212
+ }
3213
+ return emitObservation("ok");
3214
+ }
2827
3215
 
2828
- export { MAX_RECOVERY_LEDGER_BYTES, collectDelegationLedgerHealth, MAX_PR_REVIEW_COLLECTION_RECEIPT_ITEM_IDS, BACKGROUND_DELEGATIONS_FILE, BACKGROUND_DELEGATION_FALLBACK_DIR, BACKGROUND_CODER_RESERVATIONS_FILE, BACKGROUND_DELEGATIONS_CHECKPOINT_FILE, BACKGROUND_DELEGATIONS_MANIFEST_FILE, MAX_LIVE_BACKGROUND_FALLBACKS, MAX_LIVE_BACKGROUND_CODER_RESERVATIONS, MAX_BACKGROUND_OBSERVED_FILES, MAX_BACKGROUND_ADVISORY_CHARS, DELEGATION_COMPACTION_LOW_WATER_BYTES, DELEGATION_COMPACTION_HIGH_WATER_BYTES, MAX_CHECKPOINT_BYTES, MAX_CHECKPOINT_RECORDS, TOMBSTONE_MIN_AGE_MS, BACKGROUND_INGESTION_LEASE_MS, DEFAULT_STALE_DELEGATION_TIMEOUT_MS, DEFAULT_SWEEPABLE_DELEGATION_STATUSES, _checkpointInternals, isUnsettledWorktreeOwner, compactBackgroundDelegations, readDelegations, scanDelegationsForRecovery, findByCorrelationId, recordPendingDelegationDetailed, recordPendingDelegation, buildPromptSnapshot, appendDelegationTransition, buildBackgroundCompletionEventId, claimTerminalResult, claimCoderSettlement, normalizeBackgroundObservedFiles, updateCoderSettlement, claimDelegationIngestion, recordDelegationIngestionResult, putPendingBackgroundAdvisory, preparePendingBackgroundAdvisories, acknowledgeObservedBackgroundAdvisories, releasePreparedBackgroundAdvisories, findByBatchId, findOpenAsyncLaneBatches, sweepStaleDelegations, readDelegationFallback, listDelegationFallbacks, scanDelegationFallbacksForRecovery, writeDelegationFallback, removeDelegationFallback, findDelegationForCompletion, promoteDelegationFallback, buildBackgroundCoderReservationId, scanBackgroundCoderReservationsForAdmission, reserveBackgroundCoderSlot, bindBackgroundCoderReservation, releaseBackgroundCoderReservation };
3216
+ export { MAX_RECOVERY_LEDGER_BYTES, readDelegationHealthArtifact, collectDelegationLedgerHealth, MAX_PR_REVIEW_COLLECTION_RECEIPT_ITEM_IDS, BACKGROUND_DELEGATIONS_FILE, BACKGROUND_DELEGATION_FALLBACK_DIR, BACKGROUND_CODER_RESERVATIONS_FILE, BACKGROUND_DELEGATIONS_CHECKPOINT_FILE, BACKGROUND_DELEGATIONS_MANIFEST_FILE, MAX_LIVE_BACKGROUND_FALLBACKS, MAX_LIVE_BACKGROUND_CODER_RESERVATIONS, MAX_BACKGROUND_OBSERVED_FILES, MAX_BACKGROUND_ADVISORY_CHARS, DELEGATION_COMPACTION_LOW_WATER_BYTES, DELEGATION_COMPACTION_HIGH_WATER_BYTES, MAX_CHECKPOINT_BYTES, MAX_CHECKPOINT_RECORDS, TOMBSTONE_MIN_AGE_MS, BACKGROUND_INGESTION_LEASE_MS, BACKGROUND_CODER_RESERVATION_LEASE_MS, BACKGROUND_CODER_RESERVATION_LEASE_MAX_MS, BACKGROUND_CODER_RESERVATION_LEASE_MIN_MS, DEFAULT_STALE_DELEGATION_TIMEOUT_MS, DEFAULT_SWEEPABLE_DELEGATION_STATUSES, _checkpointInternals, isUnsettledWorktreeOwner, compactBackgroundDelegations, readDelegations, scanDelegationsForRecovery, findByCorrelationId, recordPendingDelegationDetailed, recordPendingDelegation, buildPromptSnapshot, appendDelegationTransition, buildBackgroundCompletionEventId, claimTerminalResult, claimCoderSettlement, normalizeBackgroundObservedFiles, updateCoderSettlement, claimDelegationIngestion, recordDelegationIngestionResult, putPendingBackgroundAdvisory, preparePendingBackgroundAdvisories, acknowledgeObservedBackgroundAdvisories, releasePreparedBackgroundAdvisories, findByBatchId, findOpenAsyncLaneBatches, sweepStaleDelegations, readDelegationFallback, listDelegationFallbacks, scanDelegationFallbacksForRecovery, writeDelegationFallback, removeDelegationFallback, findDelegationForCompletion, promoteDelegationFallback, buildBackgroundCoderReservationId, scanBackgroundCoderReservationsForAdmission, reserveBackgroundCoderSlot, bindBackgroundCoderReservation, releaseBackgroundCoderReservation, maintainBackgroundDelegations };
@@ -1,10 +1,10 @@
1
1
  // @bun
2
2
  import {
3
3
  atomicWriteFileAnyRoot
4
- } from "./index-zpn3wqvp.js";
4
+ } from "./index-kg4knw6r.js";
5
5
  import {
6
6
  withEvidenceLock
7
- } from "./index-rsn4jm90.js";
7
+ } from "./index-vrp2zva8.js";
8
8
 
9
9
  // src/evidence/task-file.ts
10
10
  import * as path from "path";
@@ -360,4 +360,4 @@ async function withEvidenceLock(directory, evidencePath, agent, taskId, fn, time
360
360
  }
361
361
  }
362
362
 
363
- export { tryAcquireLock, listActiveLocks, hasExplicitProjectBoundary, isStrictPathDescendant, assertProjectRoot, withEvidenceLock };
363
+ export { tryAcquireLock, listActiveLocks, hasExplicitProjectBoundary, isStrictPathDescendant, assertProjectRoot, EvidenceLockTimeoutError, withEvidenceLock };
@@ -6,12 +6,12 @@ import {
6
6
  resolveSwarmKnowledgePath,
7
7
  transactKnowledge,
8
8
  wordBigrams
9
- } from "./index-3vescfdb.js";
9
+ } from "./index-1w5nnyew.js";
10
10
  import {
11
11
  queryHistoricalOutcomes,
12
12
  readKnowledgeEvents,
13
13
  recordKnowledgeEvent
14
- } from "./index-dmbvep3q.js";
14
+ } from "./index-ne45ew6z.js";
15
15
  import {
16
16
  init_knowledge_types,
17
17
  isActiveStatus
@@ -224,11 +224,11 @@ async function maybeQuarantineOnContradiction(directory, entryId, threshold, win
224
224
  alreadyInactive: true
225
225
  };
226
226
  }
227
- const { quarantineEntry } = await import("./knowledge-validator-56w52rwr.js");
227
+ const { quarantineEntry } = await import("./knowledge-validator-cq2cgfcx.js");
228
228
  let policyConfig;
229
229
  try {
230
- const { KnowledgeConfigSchema } = await import("./schema-gcjdpfr9.js");
231
- const { loadPluginConfigWithMeta } = await import("./index-hwfs0ze1.js");
230
+ const { KnowledgeConfigSchema } = await import("./schema-e59spg93.js");
231
+ const { loadPluginConfigWithMeta } = await import("./index-qbsc2btq.js");
232
232
  const { config: loadedConfig } = loadPluginConfigWithMeta(directory);
233
233
  policyConfig = KnowledgeConfigSchema.parse(loadedConfig.knowledge ?? {});
234
234
  } catch {
@@ -4,11 +4,11 @@ import {
4
4
  PlanSchema,
5
5
  TaskStatusSchema,
6
6
  init_loader
7
- } from "./index-08d3pb9a.js";
7
+ } from "./index-59wqcatm.js";
8
8
  import {
9
9
  assertProjectRoot,
10
10
  withEvidenceLock
11
- } from "./index-rsn4jm90.js";
11
+ } from "./index-vrp2zva8.js";
12
12
  import {
13
13
  emit
14
14
  } from "./index-ghbkknjz.js";
@@ -21,7 +21,7 @@ var package_default;
21
21
  var init_package = __esm(() => {
22
22
  package_default = {
23
23
  name: "opencode-swarm",
24
- version: "7.148.3",
24
+ version: "7.148.5",
25
25
  description: "Architect-centric agentic swarm plugin for OpenCode - hub-and-spoke orchestration with SME consultation, code generation, and QA review",
26
26
  main: "dist/index.js",
27
27
  types: "dist/index.d.ts",
@@ -2,14 +2,14 @@
2
2
  import {
3
3
  readKnowledge,
4
4
  transactKnowledge
5
- } from "./index-3vescfdb.js";
5
+ } from "./index-1w5nnyew.js";
6
6
  import {
7
7
  init_git_executable,
8
8
  resolveGitExecutableAsync
9
9
  } from "./index-9e6fdz2h.js";
10
10
  import {
11
11
  resolveKnowledgeStoreDir
12
- } from "./index-m5z2fgs4.js";
12
+ } from "./index-k1s8gxjh.js";
13
13
  import {
14
14
  init_knowledge_types,
15
15
  isActiveStatus