opencode-swarm 6.33.6 → 6.33.8

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 (2) hide show
  1. package/dist/index.js +134 -85
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -50891,17 +50891,10 @@ async function getEvidenceTaskId(session, directory) {
50891
50891
  }
50892
50892
  }
50893
50893
  } catch (err2) {
50894
- if (err2 instanceof Error) {
50895
- if (err2 instanceof SyntaxError) {
50896
- return null;
50897
- }
50898
- const code = err2.code;
50899
- if (code === "ENOENT" || code === "ENOTDIR") {
50900
- return null;
50901
- }
50902
- throw err2;
50894
+ if (process.env.DEBUG_SWARM && err2 instanceof Error) {
50895
+ console.warn(`[delegation-gate] getEvidenceTaskId error: ${err2.message} (code=${err2.code ?? "none"})`);
50903
50896
  }
50904
- throw err2;
50897
+ return null;
50905
50898
  }
50906
50899
  return null;
50907
50900
  }
@@ -50995,10 +50988,10 @@ function createDelegationGateHook(config3, directory) {
50995
50988
  }
50996
50989
  }
50997
50990
  if (typeof subagentType === "string") {
50998
- const rawTaskId = directArgs?.task_id;
50999
- const evidenceTaskId = typeof rawTaskId === "string" && rawTaskId.length <= 20 && /^\d+\.\d+$/.test(rawTaskId.trim()) ? rawTaskId.trim() : await getEvidenceTaskId(session, directory);
51000
- if (evidenceTaskId) {
51001
- try {
50991
+ try {
50992
+ const rawTaskId = directArgs?.task_id;
50993
+ const evidenceTaskId = typeof rawTaskId === "string" && rawTaskId.length <= 20 && /^\d+\.\d+$/.test(rawTaskId.trim()) ? rawTaskId.trim() : await getEvidenceTaskId(session, directory);
50994
+ if (evidenceTaskId) {
51002
50995
  const turbo = hasActiveTurboMode();
51003
50996
  const gateAgents = [
51004
50997
  "reviewer",
@@ -51017,9 +51010,9 @@ function createDelegationGateHook(config3, directory) {
51017
51010
  const { recordAgentDispatch: recordAgentDispatch2 } = await Promise.resolve().then(() => (init_gate_evidence(), exports_gate_evidence));
51018
51011
  await recordAgentDispatch2(directory, evidenceTaskId, targetAgentForEvidence, turbo);
51019
51012
  }
51020
- } catch (err2) {
51021
- console.warn(`[delegation-gate] evidence write failed for task ${evidenceTaskId}: ${err2 instanceof Error ? err2.message : String(err2)}`);
51022
51013
  }
51014
+ } catch (err2) {
51015
+ console.warn(`[delegation-gate] evidence recording failed: ${err2 instanceof Error ? err2.message : String(err2)}`);
51023
51016
  }
51024
51017
  }
51025
51018
  if (storedArgs !== undefined) {
@@ -51114,24 +51107,22 @@ function createDelegationGateHook(config3, directory) {
51114
51107
  }
51115
51108
  }
51116
51109
  }
51117
- {
51110
+ try {
51118
51111
  const rawTaskId = directArgs?.task_id;
51119
51112
  const evidenceTaskId = typeof rawTaskId === "string" && rawTaskId.length <= 20 && /^\d+\.\d+$/.test(rawTaskId.trim()) ? rawTaskId.trim() : await getEvidenceTaskId(session, directory);
51120
51113
  if (evidenceTaskId) {
51121
- try {
51122
- const turbo = hasActiveTurboMode();
51123
- if (hasReviewer) {
51124
- const { recordGateEvidence: recordGateEvidence2 } = await Promise.resolve().then(() => (init_gate_evidence(), exports_gate_evidence));
51125
- await recordGateEvidence2(directory, evidenceTaskId, "reviewer", input.sessionID, turbo);
51126
- }
51127
- if (hasTestEngineer) {
51128
- const { recordGateEvidence: recordGateEvidence2 } = await Promise.resolve().then(() => (init_gate_evidence(), exports_gate_evidence));
51129
- await recordGateEvidence2(directory, evidenceTaskId, "test_engineer", input.sessionID, turbo);
51130
- }
51131
- } catch (err2) {
51132
- console.warn(`[delegation-gate] evidence write failed for task ${evidenceTaskId}: ${err2 instanceof Error ? err2.message : String(err2)}`);
51114
+ const turbo = hasActiveTurboMode();
51115
+ if (hasReviewer) {
51116
+ const { recordGateEvidence: recordGateEvidence2 } = await Promise.resolve().then(() => (init_gate_evidence(), exports_gate_evidence));
51117
+ await recordGateEvidence2(directory, evidenceTaskId, "reviewer", input.sessionID, turbo);
51118
+ }
51119
+ if (hasTestEngineer) {
51120
+ const { recordGateEvidence: recordGateEvidence2 } = await Promise.resolve().then(() => (init_gate_evidence(), exports_gate_evidence));
51121
+ await recordGateEvidence2(directory, evidenceTaskId, "test_engineer", input.sessionID, turbo);
51133
51122
  }
51134
51123
  }
51124
+ } catch (err2) {
51125
+ console.warn(`[delegation-gate] fallback evidence recording failed: ${err2 instanceof Error ? err2.message : String(err2)}`);
51135
51126
  }
51136
51127
  }
51137
51128
  }
@@ -65267,6 +65258,8 @@ var OpenCodeSwarm = async (ctx) => {
65267
65258
  },
65268
65259
  "experimental.chat.messages.transform": composeHandlers(...[
65269
65260
  (input, _output) => {
65261
+ if (process.env.DEBUG_SWARM)
65262
+ console.error(`[DIAG] messagesTransform START`);
65270
65263
  const p = input;
65271
65264
  if (p.sessionID) {
65272
65265
  const archAgent = swarmState.activeAgent.get(p.sessionID);
@@ -65290,16 +65283,28 @@ var OpenCodeSwarm = async (ctx) => {
65290
65283
  if (output.messages) {
65291
65284
  output.messages = consolidateSystemMessages(output.messages);
65292
65285
  }
65286
+ if (process.env.DEBUG_SWARM)
65287
+ console.error(`[DIAG] messagesTransform DONE`);
65293
65288
  return Promise.resolve();
65294
65289
  }
65295
65290
  ].filter((fn) => Boolean(fn))),
65296
65291
  "experimental.chat.system.transform": composeHandlers(...[
65292
+ async (input, output) => {
65293
+ if (process.env.DEBUG_SWARM)
65294
+ console.error(`[DIAG] systemTransform START`);
65295
+ },
65297
65296
  systemEnhancerHook["experimental.chat.system.transform"],
65297
+ async (_input, _output) => {
65298
+ if (process.env.DEBUG_SWARM)
65299
+ console.error(`[DIAG] systemTransform enhancer DONE`);
65300
+ },
65298
65301
  automationConfig.capabilities?.phase_preflight === true && preflightTriggerManager ? createPhaseMonitorHook(ctx.directory, preflightTriggerManager) : knowledgeConfig.enabled ? createPhaseMonitorHook(ctx.directory) : undefined
65299
65302
  ].filter(Boolean)),
65300
65303
  "experimental.session.compacting": compactionHook["experimental.session.compacting"],
65301
65304
  "command.execute.before": safeHook(commandHandler),
65302
65305
  "tool.execute.before": async (input, output) => {
65306
+ if (process.env.DEBUG_SWARM)
65307
+ console.error(`[DIAG] toolBefore tool=${input.tool?.replace?.(/^[^:]+[:.]/, "") ?? input.tool} session=${input.sessionID}`);
65303
65308
  if (!swarmState.activeAgent.has(input.sessionID)) {
65304
65309
  swarmState.activeAgent.set(input.sessionID, ORCHESTRATOR_NAME);
65305
65310
  }
@@ -65328,72 +65333,116 @@ var OpenCodeSwarm = async (ctx) => {
65328
65333
  await safeHook(activityHooks.toolBefore)(input, output);
65329
65334
  },
65330
65335
  "tool.execute.after": async (input, output) => {
65331
- if (process.env.DEBUG_SWARM) {
65332
- console.debug("[hook-chain] toolAfter start sessionID=%s agent=%s tool=%s", input.sessionID, input.agent, input.tool?.name);
65333
- }
65334
- await activityHooks.toolAfter(input, output);
65335
- await guardrailsHooks.toolAfter(input, output);
65336
- await safeHook(delegationLedgerHook.toolAfter)(input, output);
65337
- await safeHook(selfReviewHook.toolAfter)(input, output);
65338
- await safeHook(delegationGateHooks.toolAfter)(input, output);
65339
- if (knowledgeCuratorHook)
65340
- await safeHook(knowledgeCuratorHook)(input, output);
65341
- if (hivePromoterHook)
65342
- await safeHook(hivePromoterHook)(input, output);
65343
- await safeHook(steeringConsumedHook)(input, output);
65344
- await safeHook(coChangeSuggesterHook)(input, output);
65345
- await safeHook(darkMatterDetectorHook)(input, output);
65346
- await snapshotWriterHook(input, output);
65347
- await toolSummarizerHook?.(input, output);
65348
- const execMode = config3.execution_mode ?? "balanced";
65349
- if (execMode === "strict") {
65350
- if (slopDetectorHook)
65351
- await slopDetectorHook.toolAfter(input, output);
65352
- if (incrementalVerifyHook)
65353
- await incrementalVerifyHook.toolAfter(input, output);
65354
- if (compactionServiceHook)
65355
- await compactionServiceHook.toolAfter(input, output);
65356
- }
65357
- const toolOutputConfig = config3.tool_output;
65358
- if (toolOutputConfig && toolOutputConfig.truncation_enabled !== false && typeof output.output === "string") {
65359
- const defaultTruncatableTools = new Set([
65360
- "diff",
65361
- "symbols",
65362
- "bash",
65363
- "shell",
65364
- "test_runner",
65365
- "lint",
65366
- "pre_check_batch",
65367
- "complexity_hotspots",
65368
- "pkg_audit",
65369
- "sbom_generate",
65370
- "schema_drift"
65371
- ]);
65372
- const configuredTools = toolOutputConfig.truncation_tools;
65373
- const truncatableTools = configuredTools && configuredTools.length > 0 ? new Set(configuredTools) : defaultTruncatableTools;
65374
- const maxLines = toolOutputConfig.per_tool?.[input.tool] ?? toolOutputConfig.max_lines ?? 150;
65375
- if (truncatableTools.has(input.tool)) {
65376
- output.output = truncateToolOutput(output.output, maxLines, input.tool, 10);
65377
- }
65378
- }
65336
+ const _dbg = !!process.env.DEBUG_SWARM;
65337
+ const _toolName = input.tool?.replace?.(/^[^:]+[:.]/, "") ?? input.tool;
65338
+ if (_dbg)
65339
+ console.error(`[DIAG] toolAfter START tool=${_toolName} session=${input.sessionID}`);
65379
65340
  const normalizedTool = input.tool.replace(/^[^:]+[:.]/, "");
65380
- if (normalizedTool === "Task" || normalizedTool === "task") {
65341
+ const isTaskTool = normalizedTool === "Task" || normalizedTool === "task";
65342
+ if (isTaskTool) {
65381
65343
  const sessionId = input.sessionID;
65382
65344
  swarmState.activeAgent.set(sessionId, ORCHESTRATOR_NAME);
65383
65345
  ensureAgentSession(sessionId, ORCHESTRATOR_NAME);
65384
- const session = swarmState.agentSessions.get(sessionId);
65385
- if (session) {
65386
- session.delegationActive = false;
65387
- session.lastAgentEventTime = Date.now();
65346
+ const taskSession = swarmState.agentSessions.get(sessionId);
65347
+ if (taskSession) {
65348
+ taskSession.delegationActive = false;
65349
+ taskSession.lastAgentEventTime = Date.now();
65350
+ }
65351
+ if (_dbg)
65352
+ console.error(`[DIAG] Task handoff DONE (early) session=${sessionId} activeAgent=${swarmState.activeAgent.get(sessionId)}`);
65353
+ }
65354
+ const HOOK_CHAIN_TIMEOUT_MS = 30000;
65355
+ const hookChainStart = Date.now();
65356
+ let hookChainTimedOut = false;
65357
+ const hookChain = async () => {
65358
+ await activityHooks.toolAfter(input, output);
65359
+ if (_dbg)
65360
+ console.error(`[DIAG] toolAfter activity done tool=${_toolName}`);
65361
+ await guardrailsHooks.toolAfter(input, output);
65362
+ if (_dbg)
65363
+ console.error(`[DIAG] toolAfter guardrails done tool=${_toolName}`);
65364
+ await safeHook(delegationLedgerHook.toolAfter)(input, output);
65365
+ if (_dbg)
65366
+ console.error(`[DIAG] toolAfter ledger done tool=${_toolName}`);
65367
+ await safeHook(selfReviewHook.toolAfter)(input, output);
65368
+ if (_dbg)
65369
+ console.error(`[DIAG] toolAfter selfReview done tool=${_toolName}`);
65370
+ await safeHook(delegationGateHooks.toolAfter)(input, output);
65371
+ if (_dbg)
65372
+ console.error(`[DIAG] toolAfter delegationGate done tool=${_toolName}`);
65373
+ if (knowledgeCuratorHook)
65374
+ await safeHook(knowledgeCuratorHook)(input, output);
65375
+ if (hivePromoterHook)
65376
+ await safeHook(hivePromoterHook)(input, output);
65377
+ if (_dbg)
65378
+ console.error(`[DIAG] toolAfter knowledge done tool=${_toolName}`);
65379
+ await safeHook(steeringConsumedHook)(input, output);
65380
+ await safeHook(coChangeSuggesterHook)(input, output);
65381
+ await safeHook(darkMatterDetectorHook)(input, output);
65382
+ if (_dbg)
65383
+ console.error(`[DIAG] toolAfter intelligence done tool=${_toolName}`);
65384
+ await snapshotWriterHook(input, output);
65385
+ await toolSummarizerHook?.(input, output);
65386
+ if (_dbg)
65387
+ console.error(`[DIAG] toolAfter snapshot+summarizer done tool=${_toolName}`);
65388
+ const execMode = config3.execution_mode ?? "balanced";
65389
+ if (execMode === "strict") {
65390
+ if (slopDetectorHook)
65391
+ await slopDetectorHook.toolAfter(input, output);
65392
+ if (incrementalVerifyHook)
65393
+ await incrementalVerifyHook.toolAfter(input, output);
65394
+ if (compactionServiceHook)
65395
+ await compactionServiceHook.toolAfter(input, output);
65396
+ }
65397
+ const toolOutputConfig = config3.tool_output;
65398
+ if (toolOutputConfig && toolOutputConfig.truncation_enabled !== false && typeof output.output === "string") {
65399
+ const defaultTruncatableTools = new Set([
65400
+ "diff",
65401
+ "symbols",
65402
+ "bash",
65403
+ "shell",
65404
+ "test_runner",
65405
+ "lint",
65406
+ "pre_check_batch",
65407
+ "complexity_hotspots",
65408
+ "pkg_audit",
65409
+ "sbom_generate",
65410
+ "schema_drift"
65411
+ ]);
65412
+ const configuredTools = toolOutputConfig.truncation_tools;
65413
+ const truncatableTools = configuredTools && configuredTools.length > 0 ? new Set(configuredTools) : defaultTruncatableTools;
65414
+ const maxLines = toolOutputConfig.per_tool?.[input.tool] ?? toolOutputConfig.max_lines ?? 150;
65415
+ if (truncatableTools.has(input.tool)) {
65416
+ output.output = truncateToolOutput(output.output, maxLines, input.tool, 10);
65417
+ }
65388
65418
  }
65419
+ };
65420
+ const timeout = new Promise((resolve23) => {
65421
+ setTimeout(() => {
65422
+ hookChainTimedOut = true;
65423
+ resolve23();
65424
+ }, HOOK_CHAIN_TIMEOUT_MS);
65425
+ });
65426
+ await Promise.race([
65427
+ hookChain().catch((err2) => {
65428
+ console.warn(`[swarm] toolAfter hook chain error tool=${_toolName}: ${err2 instanceof Error ? err2.message : String(err2)}`);
65429
+ }),
65430
+ timeout
65431
+ ]);
65432
+ if (hookChainTimedOut) {
65433
+ const elapsed = Date.now() - hookChainStart;
65434
+ console.warn(`[swarm] toolAfter TIMEOUT after ${elapsed}ms tool=${_toolName} session=${input.sessionID} \u2014 hooks abandoned to prevent session freeze`);
65389
65435
  }
65390
65436
  deleteStoredInputArgs(input.callID);
65437
+ if (_dbg)
65438
+ console.error(`[DIAG] toolAfter COMPLETE tool=${_toolName}`);
65391
65439
  },
65392
65440
  "chat.message": safeHook(async (input, output) => {
65393
- if (process.env.DEBUG_SWARM) {
65394
- console.debug("[session] chat.message sessionID=%s agent=%s", input.sessionID, input.agent);
65395
- }
65441
+ if (process.env.DEBUG_SWARM)
65442
+ console.error(`[DIAG] chat.message agent=${input.agent ?? "none"} session=${input.sessionID}`);
65396
65443
  await delegationHandler(input, output);
65444
+ if (process.env.DEBUG_SWARM)
65445
+ console.error(`[DIAG] chat.message DONE agent=${input.agent ?? "none"}`);
65397
65446
  }),
65398
65447
  automation: automationManager
65399
65448
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-swarm",
3
- "version": "6.33.6",
3
+ "version": "6.33.8",
4
4
  "description": "Architect-centric agentic swarm plugin for OpenCode - hub-and-spoke orchestration with SME consultation, code generation, and QA review",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",