opencode-swarm 7.99.3 → 7.99.4

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.
@@ -6,7 +6,7 @@ import {
6
6
  loadPlanJsonOnly,
7
7
  mergeDurableGateEntriesFromEvidence,
8
8
  readDurableGateEvidence
9
- } from "./index-6wgwybzj.js";
9
+ } from "./index-9twtnjkv.js";
10
10
  import"./index-r8f89sm9.js";
11
11
  import"./index-9b7qp18e.js";
12
12
  import"./index-94qwbx11.js";
@@ -1,15 +1,15 @@
1
1
  // @bun
2
2
  import {
3
3
  handleGuardrailExplain
4
- } from "./index-nytjghhx.js";
5
- import"./index-fhve3nj7.js";
4
+ } from "./index-rq7arj2r.js";
5
+ import"./index-0avc4356.js";
6
6
  import"./index-xsswhy6k.js";
7
7
  import"./index-ydgy7vg5.js";
8
8
  import"./index-vwyjkzgs.js";
9
9
  import"./index-f7nma02k.js";
10
10
  import"./index-svf2zjxs.js";
11
11
  import"./index-7hnwnw5g.js";
12
- import"./index-6wgwybzj.js";
12
+ import"./index-9twtnjkv.js";
13
13
  import"./index-adz3nk9b.js";
14
14
  import"./index-v4fcn4tr.js";
15
15
  import"./index-r8f89sm9.js";
@@ -114,7 +114,7 @@ import {
114
114
  transientBackoff,
115
115
  validateProjectRoot,
116
116
  writeProjectedSpecSync
117
- } from "./index-6wgwybzj.js";
117
+ } from "./index-9twtnjkv.js";
118
118
  import {
119
119
  _internals as _internals2,
120
120
  _internals1 as _internals3,
@@ -909,7 +909,7 @@ var init_executor = __esm(() => {
909
909
  // package.json
910
910
  var package_default = {
911
911
  name: "opencode-swarm",
912
- version: "7.99.3",
912
+ version: "7.99.4",
913
913
  description: "Architect-centric agentic swarm plugin for OpenCode - hub-and-spoke orchestration with SME consultation, code generation, and QA review",
914
914
  main: "dist/index.js",
915
915
  types: "dist/index.d.ts",
@@ -5368,6 +5368,7 @@ function resetSwarmState() {
5368
5368
  swarmState.pendingEvents = 0;
5369
5369
  swarmState.lastBudgetPct = 0;
5370
5370
  swarmState.agentSessions.clear();
5371
+ _lastIdleSweepAtMs = 0;
5371
5372
  clearTrajectoryCache();
5372
5373
  clearTrajectoryStepCounters();
5373
5374
  swarmState.pendingRehydrations.clear();
@@ -5409,8 +5410,10 @@ function resetSwarmStatePreservingSingletons() {
5409
5410
  swarmState.specWriterAgentNames = preservedSpecWriterAgentNames;
5410
5411
  swarmState.generatedAgentNames = preservedGeneratedAgentNames;
5411
5412
  }
5412
- function startAgentSession(sessionId, agentName, staleDurationMs = 7200000, directory) {
5413
- const now = Date.now();
5413
+ var STALE_SESSION_TTL_MS = 7200000;
5414
+ var IDLE_SWEEP_COOLDOWN_MS = 60000;
5415
+ var _lastIdleSweepAtMs = 0;
5416
+ function sweepStaleSessions(staleDurationMs = STALE_SESSION_TTL_MS, now = Date.now()) {
5414
5417
  const staleIds = [];
5415
5418
  for (const [id, session] of swarmState.agentSessions) {
5416
5419
  if (now - session.lastToolCallTime > staleDurationMs) {
@@ -5419,7 +5422,20 @@ function startAgentSession(sessionId, agentName, staleDurationMs = 7200000, dire
5419
5422
  }
5420
5423
  for (const id of staleIds) {
5421
5424
  swarmState.agentSessions.delete(id);
5425
+ swarmState.delegationChains.delete(id);
5426
+ }
5427
+ return staleIds;
5428
+ }
5429
+ function maybeSweepStaleSessions(staleDurationMs = STALE_SESSION_TTL_MS, now = Date.now()) {
5430
+ if (now - _lastIdleSweepAtMs < IDLE_SWEEP_COOLDOWN_MS) {
5431
+ return [];
5422
5432
  }
5433
+ _lastIdleSweepAtMs = now;
5434
+ return sweepStaleSessions(staleDurationMs, now);
5435
+ }
5436
+ function startAgentSession(sessionId, agentName, staleDurationMs = STALE_SESSION_TTL_MS, directory) {
5437
+ const now = Date.now();
5438
+ sweepStaleSessions(staleDurationMs, now);
5423
5439
  const sessionState = {
5424
5440
  agentName,
5425
5441
  lastToolCallTime: now,
@@ -5670,6 +5686,7 @@ function ensureAgentSession(sessionId, agentName, directory) {
5670
5686
  session.prSubscriptions = new Map;
5671
5687
  }
5672
5688
  session.lastToolCallTime = now;
5689
+ maybeSweepStaleSessions();
5673
5690
  return session;
5674
5691
  }
5675
5692
  _internals12.startAgentSession(sessionId, agentName ?? "unknown", 7200000, directory);
@@ -15869,6 +15886,7 @@ import { existsSync as existsSync16, mkdirSync as mkdirSync9, readFileSync as re
15869
15886
  import { homedir as homedir4 } from "os";
15870
15887
  import { join as join27 } from "path";
15871
15888
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
15889
+ var MAX_RESPONSE_BYTES = 256 * 1024;
15872
15890
  function cacheDir() {
15873
15891
  const xdg = process.env.XDG_CACHE_HOME;
15874
15892
  const base = xdg && xdg.length > 0 ? xdg : join27(homedir4(), ".cache");
@@ -17932,7 +17950,7 @@ async function handleEvidenceCommand(directory, args) {
17932
17950
  return formatTaskEvidenceMarkdown(evidenceData);
17933
17951
  }
17934
17952
  async function handleEvidenceSummaryCommand(directory) {
17935
- const { buildEvidenceSummary } = await import("./evidence-summary-service-wxarfgt8.js");
17953
+ const { buildEvidenceSummary } = await import("./evidence-summary-service-5ww1npaa.js");
17936
17954
  const artifact = await buildEvidenceSummary(directory);
17937
17955
  if (!artifact) {
17938
17956
  return "No plan found. Run `/swarm plan` to check plan status.";
@@ -26961,7 +26979,7 @@ function resolveWorkingDirectory(workingDirectory, fallbackDirectory) {
26961
26979
  };
26962
26980
  }
26963
26981
  }
26964
- const rawPathParts = workingDirectory.split(path53.sep);
26982
+ const rawPathParts = workingDirectory.split(/[\\/]/);
26965
26983
  if (rawPathParts.includes("..")) {
26966
26984
  return {
26967
26985
  success: false,
@@ -32278,7 +32296,7 @@ function buildDetailedHelp(commandName, entry) {
32278
32296
  async function handleHelpCommand(ctx) {
32279
32297
  const targetCommand = ctx.args.join(" ");
32280
32298
  if (!targetCommand) {
32281
- const { buildHelpText } = await import("./index-y1fgp4xa.js");
32299
+ const { buildHelpText } = await import("./index-r431nee9.js");
32282
32300
  return buildHelpText();
32283
32301
  }
32284
32302
  const tokens = targetCommand.split(/\s+/);
@@ -32287,7 +32305,7 @@ async function handleHelpCommand(ctx) {
32287
32305
  return _internals46.buildDetailedHelp(resolved.key, resolved.entry);
32288
32306
  }
32289
32307
  const similar = _internals46.findSimilarCommands(targetCommand);
32290
- const { buildHelpText: fullHelp } = await import("./index-y1fgp4xa.js");
32308
+ const { buildHelpText: fullHelp } = await import("./index-r431nee9.js");
32291
32309
  if (similar.length > 0) {
32292
32310
  return `Command '/swarm ${targetCommand}' not found.
32293
32311
 
@@ -32420,7 +32438,7 @@ var COMMAND_REGISTRY = {
32420
32438
  },
32421
32439
  "guardrail explain": {
32422
32440
  handler: async (ctx) => {
32423
- const { handleGuardrailExplain } = await import("./guardrail-explain-5fpwhqk5.js");
32441
+ const { handleGuardrailExplain } = await import("./guardrail-explain-3dxh8t8v.js");
32424
32442
  return handleGuardrailExplain(ctx.directory, ctx.args);
32425
32443
  },
32426
32444
  description: "Dry-run: show what the guardrails would do to a command or write target (executes nothing)",
@@ -2047,6 +2047,7 @@ class PlanTaskRemovalNotAcknowledgedError extends Error {
2047
2047
  }
2048
2048
  }
2049
2049
  var startupLedgerCheckedWorkspaces = new Set;
2050
+ var ledgerStaleWorkspaces = new Set;
2050
2051
  var recoveryMutexes = new Map;
2051
2052
  var PLAN_JSON_CACHE_NAMESPACE = "plan-json:validated:v1";
2052
2053
  var _internals4 = {
@@ -2128,6 +2129,25 @@ async function getLatestLedgerHash(directory) {
2128
2129
  return "";
2129
2130
  }
2130
2131
  }
2132
+ async function surfaceLedgerStaleIfPersisted(directory, plan) {
2133
+ const resolvedWorkspace = path6.resolve(directory);
2134
+ if (!ledgerStaleWorkspaces.has(resolvedWorkspace)) {
2135
+ return plan;
2136
+ }
2137
+ try {
2138
+ const planHash = computePlanHash(plan);
2139
+ const ledgerHash = await getLatestLedgerHash(directory);
2140
+ if (ledgerHash !== "" && planHash === ledgerHash) {
2141
+ ledgerStaleWorkspaces.delete(resolvedWorkspace);
2142
+ return plan;
2143
+ }
2144
+ } catch {}
2145
+ plan._ledgerReplayStale = true;
2146
+ if (typeof plan._ledgerReplayStaleReason !== "string" || plan._ledgerReplayStaleReason.length === 0) {
2147
+ plan._ledgerReplayStaleReason = "plan.json still hash-mismatches the ledger after a startup ledger-replay failure (replay could not be applied and no critic-approved snapshot was available). Run /swarm reset-session if this persists.";
2148
+ }
2149
+ return plan;
2150
+ }
2131
2151
  async function parsePlanJsonCached(directory) {
2132
2152
  const planJsonPath = path6.resolve(directory, ".swarm", "plan.json");
2133
2153
  return readCachedParsedFile(planJsonPath, PLAN_JSON_CACHE_NAMESPACE, () => readSwarmFileAsync(directory, "plan.json"), (planJsonContent) => {
@@ -2186,7 +2206,7 @@ async function isPlanMdInSync(directory, plan, cache) {
2186
2206
  if (normalizedActual === normalizedExpected) {
2187
2207
  return true;
2188
2208
  }
2189
- return normalizedActual.includes(normalizedExpected) || normalizedExpected.includes(normalizedActual.replace(/^#.*$/gm, "").trim());
2209
+ return false;
2190
2210
  }
2191
2211
  async function regeneratePlanMarkdown(directory, plan) {
2192
2212
  const swarmDir = path6.resolve(directory, ".swarm");
@@ -2267,6 +2287,12 @@ async function loadPlan(directory, cache) {
2267
2287
  return approved.plan;
2268
2288
  }
2269
2289
  } catch {}
2290
+ {
2291
+ const runtimeStale = validated;
2292
+ runtimeStale._ledgerReplayStale = true;
2293
+ runtimeStale._ledgerReplayStaleReason = `Ledger replay failed during hash-mismatch rebuild and no approved snapshot was available: ${replayError instanceof Error ? replayError.message : String(replayError)}`;
2294
+ ledgerStaleWorkspaces.add(resolvedWorkspace);
2295
+ }
2270
2296
  warn(`[loadPlan] Ledger replay failed during hash-mismatch rebuild: ${replayError instanceof Error ? replayError.message : String(replayError)}. Returning stale plan.json. To recover: check .swarm/plan-export/SWARM_PLAN.md for a checkpoint, or run /swarm reset-session.`);
2271
2297
  }
2272
2298
  }
@@ -2311,7 +2337,7 @@ async function loadPlan(directory, cache) {
2311
2337
  } catch {}
2312
2338
  }
2313
2339
  }
2314
- return validated;
2340
+ return await surfaceLedgerStaleIfPersisted(directory, validated);
2315
2341
  }
2316
2342
  } catch (error2) {
2317
2343
  warn(`[loadPlan] plan.json validation failed: ${error2 instanceof Error ? error2.message : String(error2)}. Attempting rebuild from ledger. If rebuild fails, check .swarm/plan-export/SWARM_PLAN.md for a checkpoint.`);
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  handleGuardrailExplain
4
- } from "./index-nytjghhx.js";
4
+ } from "./index-rq7arj2r.js";
5
5
  import {
6
6
  handleGuardrailLog
7
7
  } from "./index-h9ptj4b1.js";
@@ -79,7 +79,7 @@ import {
79
79
  handleWriteRetroCommand,
80
80
  normalizeSwarmCommandInput,
81
81
  resolveCommand
82
- } from "./index-fhve3nj7.js";
82
+ } from "./index-0avc4356.js";
83
83
  import"./index-xsswhy6k.js";
84
84
  import"./index-ydgy7vg5.js";
85
85
  import"./index-vwyjkzgs.js";
@@ -90,7 +90,7 @@ import {
90
90
  ORCHESTRATOR_NAME,
91
91
  stripKnownSwarmPrefix
92
92
  } from "./index-7hnwnw5g.js";
93
- import"./index-6wgwybzj.js";
93
+ import"./index-9twtnjkv.js";
94
94
  import"./index-adz3nk9b.js";
95
95
  import"./index-v4fcn4tr.js";
96
96
  import"./index-r8f89sm9.js";
@@ -12,7 +12,7 @@ import {
12
12
  detectPosixWrites,
13
13
  detectWindowsWrites,
14
14
  resolveWriteTargets
15
- } from "./index-fhve3nj7.js";
15
+ } from "./index-0avc4356.js";
16
16
  import {
17
17
  checkFileAuthority,
18
18
  classifyFile,
package/dist/cli/index.js CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  getPluginLockFilePaths,
8
8
  package_default,
9
9
  resolveCommand
10
- } from "./index-fhve3nj7.js";
10
+ } from "./index-0avc4356.js";
11
11
  import"./index-xsswhy6k.js";
12
12
  import"./index-ydgy7vg5.js";
13
13
  import"./index-vwyjkzgs.js";
@@ -16,7 +16,7 @@ import"./index-svf2zjxs.js";
16
16
  import {
17
17
  DEFAULT_AGENT_CONFIGS
18
18
  } from "./index-7hnwnw5g.js";
19
- import"./index-6wgwybzj.js";
19
+ import"./index-9twtnjkv.js";
20
20
  import"./index-adz3nk9b.js";
21
21
  import"./index-v4fcn4tr.js";
22
22
  import"./index-r8f89sm9.js";
@@ -178,6 +178,25 @@ export type Plan = z.infer<typeof PlanSchema>;
178
178
  * `_midLoadRemovals` is attached by loadPlan-recovery paths that auto-
179
179
  * acknowledged task removals (issue #853) so the system-enhancer Layer A
180
180
  * can disclose the count to the model without re-reading the ledger.
181
+ *
182
+ * `_ledgerReplayStale` / `_ledgerReplayStaleReason` are attached by loadPlan
183
+ * when it returns a STALE plan.json: the plan.json hash mismatched the ledger,
184
+ * ledger replay failed (threw), AND no critic-approved snapshot was available,
185
+ * so the loader fell back to the (stale) plan.json (#1269 finding 2). Consumers
186
+ * in phase-complete.ts and update-task-status.ts read these to surface a
187
+ * structured staleness signal instead of silently trusting plan.json.
188
+ *
189
+ * RUNTIME-ONLY CONTRACT (mirrors `_specStale`): every field on RuntimePlan is a
190
+ * TypeScript-only overlay on the persisted `Plan`. It is NOT part of the durable
191
+ * `PlanSchema` (see this file ~line 95 — a plain `z.object`, no `.passthrough()`,
192
+ * so Zod strips unknown keys), so `savePlan`'s `JSON.stringify(PlanSchema.parse(...))`
193
+ * can never write these to .swarm/plan.json. It is also excluded from plan hashing:
194
+ * both `computePlanHash` (src/plan/ledger.ts) and `computePlanContentHash`
195
+ * (src/plan/manager.ts) hash an explicit allow-list of fields, never the whole
196
+ * object. Because of this, AGENTS.md invariant-5's "six places" (ledger replay,
197
+ * projection, checkpoint import/export, get_approved_plan, tests, docs) do NOT
198
+ * all apply — these are not durable schema fields. Do NOT move these into
199
+ * `PlanSchema`.
181
200
  */
182
201
  export type RuntimePlan = Plan & {
183
202
  _specStale?: boolean;
@@ -186,6 +205,8 @@ export type RuntimePlan = Plan & {
186
205
  count: number;
187
206
  source: string;
188
207
  };
208
+ _ledgerReplayStale?: boolean;
209
+ _ledgerReplayStaleReason?: string;
189
210
  };
190
211
  /**
191
212
  * Find the first phase that is in progress.