opencode-swarm 7.83.0 → 7.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/.opencode/skills/codebase-review-swarm/references/review-protocol-v8.2.md +4 -0
  2. package/.opencode/skills/council/SKILL.md +6 -1
  3. package/.opencode/skills/deep-dive/SKILL.md +2 -0
  4. package/.opencode/skills/deep-research/SKILL.md +6 -0
  5. package/.opencode/skills/swarm-pr-feedback/SKILL.md +6 -0
  6. package/.opencode/skills/swarm-pr-review/SKILL.md +4 -0
  7. package/README.md +3 -1
  8. package/dist/background/lane-output-store.d.ts +72 -0
  9. package/dist/background/pending-delegations.d.ts +6 -0
  10. package/dist/cli/capability-probe-jevmgwmf.js +18 -0
  11. package/dist/cli/config-doctor-zejarrr6.js +35 -0
  12. package/dist/cli/dispatch-k86d928w.js +477 -0
  13. package/dist/cli/evidence-summary-service-g2znnd33.js +320 -0
  14. package/dist/cli/explorer-gz70sm9b.js +16 -0
  15. package/dist/cli/gate-evidence-y8zn7fe2.js +29 -0
  16. package/dist/cli/guardrail-explain-w4txg349.js +30 -0
  17. package/dist/cli/guardrail-log-80116wmz.js +15 -0
  18. package/dist/cli/index-0sxvwjt0.js +1241 -0
  19. package/dist/cli/index-293f68mj.js +13538 -0
  20. package/dist/cli/index-5cb86007.js +110 -0
  21. package/dist/cli/index-a76rekgs.js +67 -0
  22. package/dist/cli/index-b9v501fr.js +371 -0
  23. package/dist/cli/index-bcp79s17.js +1673 -0
  24. package/dist/cli/index-ckntc5gf.js +91 -0
  25. package/dist/cli/index-d9fbxaqd.js +2314 -0
  26. package/dist/cli/index-e7h9bb6v.js +233 -0
  27. package/dist/cli/index-e8pk68cc.js +540 -0
  28. package/dist/cli/index-eb85wtx9.js +242 -0
  29. package/dist/cli/index-f8r50m3h.js +14505 -0
  30. package/dist/cli/index-fjwwrwr5.js +37 -0
  31. package/dist/cli/index-hw9b2xng.js +2046 -0
  32. package/dist/cli/index-hz59hg4h.js +452 -0
  33. package/dist/cli/index-jtqkh8jf.js +119 -0
  34. package/dist/cli/index-p0arc26j.js +28 -0
  35. package/dist/cli/index-p0ye10nd.js +222 -0
  36. package/dist/cli/index-qqabjns2.js +412 -0
  37. package/dist/cli/index-red8fm8p.js +2914 -0
  38. package/dist/cli/index-vq2321gg.js +2391 -0
  39. package/dist/cli/index-x7qck34v.js +583 -0
  40. package/dist/cli/index-yhqt45de.js +29027 -0
  41. package/dist/cli/index-yhsmmv2z.js +339 -0
  42. package/dist/cli/index-yx44zd0p.js +40 -0
  43. package/dist/cli/index-zfsbaaqh.js +29 -0
  44. package/dist/cli/index.js +73 -69708
  45. package/dist/cli/knowledge-store-n4x6zyk7.js +73 -0
  46. package/dist/cli/pending-delegations-rd40tv9s.js +261 -0
  47. package/dist/cli/pr-subscriptions-y1nn36e5.js +33 -0
  48. package/dist/cli/schema-8d32b2v6.js +168 -0
  49. package/dist/cli/skill-generator-a5ehggyg.js +55 -0
  50. package/dist/cli/task-envelope-qn0qtnh0.js +90 -0
  51. package/dist/cli/telemetry-9bbyxrvn.js +20 -0
  52. package/dist/cli/workspace-snapshot-w58jr2ga.js +90 -0
  53. package/dist/commands/guardrail-explain.d.ts +1 -0
  54. package/dist/commands/guardrail-log.d.ts +1 -0
  55. package/dist/commands/index.d.ts +2 -0
  56. package/dist/commands/registry.d.ts +14 -0
  57. package/dist/hooks/guardrails/audit-log.d.ts +114 -0
  58. package/dist/index.js +4005 -2432
  59. package/dist/services/diagnose-service.d.ts +5 -0
  60. package/dist/services/guardrail-explain-service.d.ts +42 -0
  61. package/dist/services/guardrail-log-service.d.ts +10 -0
  62. package/dist/tools/dispatch-lanes.d.ts +14 -3
  63. package/dist/tools/index.d.ts +1 -0
  64. package/dist/tools/manifest.d.ts +1 -0
  65. package/dist/tools/retrieve-lane-output.d.ts +2 -0
  66. package/dist/tools/tool-metadata.d.ts +4 -0
  67. package/package.json +2 -2
@@ -0,0 +1,222 @@
1
+ // @bun
2
+ // src/telemetry.ts
3
+ import * as fs from "fs";
4
+ import { createWriteStream } from "fs";
5
+ import * as os from "os";
6
+ import * as path from "path";
7
+ var _writeStream = null;
8
+ var _projectDirectory = null;
9
+ var _listeners = [];
10
+ var _disabled = false;
11
+ function resetTelemetryForTesting() {
12
+ _disabled = false;
13
+ _projectDirectory = null;
14
+ _listeners.length = 0;
15
+ if (_writeStream !== null) {
16
+ _writeStream.end();
17
+ _writeStream = null;
18
+ }
19
+ }
20
+ function initTelemetry(projectDirectory) {
21
+ if (_writeStream !== null || _disabled) {
22
+ return;
23
+ }
24
+ try {
25
+ _projectDirectory = projectDirectory;
26
+ const swarmDir = path.join(projectDirectory, ".swarm");
27
+ if (!fs.existsSync(swarmDir)) {
28
+ fs.mkdirSync(swarmDir, { recursive: true });
29
+ }
30
+ const telemetryPath = path.join(swarmDir, "telemetry.jsonl");
31
+ _writeStream = createWriteStream(telemetryPath, { flags: "a" });
32
+ _writeStream.on("error", () => {
33
+ _disabled = true;
34
+ _writeStream = null;
35
+ });
36
+ } catch {
37
+ _disabled = true;
38
+ _writeStream = null;
39
+ }
40
+ }
41
+ function emit(event, data) {
42
+ try {
43
+ if (_disabled || _writeStream === null) {
44
+ return;
45
+ }
46
+ const line = JSON.stringify({
47
+ timestamp: new Date().toISOString(),
48
+ event,
49
+ ...data
50
+ }) + os.EOL;
51
+ _writeStream.write(line, (err) => {
52
+ if (err) {
53
+ _disabled = true;
54
+ _writeStream = null;
55
+ }
56
+ });
57
+ for (const listener of _listeners) {
58
+ try {
59
+ listener(event, data);
60
+ } catch {}
61
+ }
62
+ } catch {}
63
+ }
64
+ function addTelemetryListener(callback) {
65
+ _listeners.push(callback);
66
+ }
67
+ function rotateTelemetryIfNeeded(maxBytes = 10 * 1024 * 1024) {
68
+ try {
69
+ if (_projectDirectory === null) {
70
+ return;
71
+ }
72
+ const telemetryPath = path.join(_projectDirectory, ".swarm", "telemetry.jsonl");
73
+ if (!fs.existsSync(telemetryPath)) {
74
+ return;
75
+ }
76
+ const stats = fs.statSync(telemetryPath);
77
+ if (stats.size < maxBytes) {
78
+ return;
79
+ }
80
+ const rotatedPath = path.join(_projectDirectory, ".swarm", "telemetry.jsonl.1");
81
+ fs.renameSync(telemetryPath, rotatedPath);
82
+ if (_writeStream !== null) {
83
+ _writeStream.end();
84
+ _writeStream = createWriteStream(telemetryPath, { flags: "a" });
85
+ _writeStream.on("error", () => {
86
+ _disabled = true;
87
+ _writeStream = null;
88
+ });
89
+ }
90
+ } catch {}
91
+ }
92
+ var telemetry = {
93
+ sessionStarted(sessionId, agentName) {
94
+ _internals.emit("session_started", { sessionId, agentName });
95
+ },
96
+ sessionEnded(sessionId, reason) {
97
+ _internals.emit("session_ended", { sessionId, reason });
98
+ },
99
+ agentActivated(sessionId, agentName, oldName) {
100
+ _internals.emit("agent_activated", { sessionId, agentName, oldName });
101
+ },
102
+ delegationBegin(sessionId, agentName, taskId) {
103
+ _internals.emit("delegation_begin", { sessionId, agentName, taskId });
104
+ },
105
+ delegationEnd(sessionId, agentName, taskId, result) {
106
+ _internals.emit("delegation_end", { sessionId, agentName, taskId, result });
107
+ },
108
+ taskStateChanged(sessionId, taskId, newState, oldState) {
109
+ _internals.emit("task_state_changed", {
110
+ sessionId,
111
+ taskId,
112
+ newState,
113
+ oldState
114
+ });
115
+ },
116
+ gatePassed(sessionId, gate, taskId) {
117
+ _internals.emit("gate_passed", { sessionId, gate, taskId });
118
+ },
119
+ gateParseError(taskId, error) {
120
+ _internals.emit("gate_parse_error", {
121
+ taskId,
122
+ errorName: error.name,
123
+ errorMessage: error.message.slice(0, 200)
124
+ });
125
+ },
126
+ gateFailed(sessionId, gate, taskId, reason) {
127
+ _internals.emit("gate_failed", { sessionId, gate, taskId, reason });
128
+ },
129
+ phaseChanged(sessionId, oldPhase, newPhase) {
130
+ _internals.emit("phase_changed", { sessionId, oldPhase, newPhase });
131
+ },
132
+ budgetUpdated(sessionId, budgetPct, agentName) {
133
+ _internals.emit("budget_updated", { sessionId, budgetPct, agentName });
134
+ },
135
+ modelFallback(sessionId, agentName, fromModel, toModel, reason) {
136
+ _internals.emit("model_fallback", {
137
+ sessionId,
138
+ agentName,
139
+ fromModel,
140
+ toModel,
141
+ reason
142
+ });
143
+ },
144
+ hardLimitHit(sessionId, agentName, limitType, value) {
145
+ _internals.emit("hard_limit_hit", {
146
+ sessionId,
147
+ agentName,
148
+ limitType,
149
+ value
150
+ });
151
+ },
152
+ revisionLimitHit(sessionId, agentName) {
153
+ _internals.emit("revision_limit_hit", { sessionId, agentName });
154
+ },
155
+ loopDetected(sessionId, agentName, loopType) {
156
+ _internals.emit("loop_detected", { sessionId, agentName, loopType });
157
+ },
158
+ scopeViolation(sessionId, agentName, file, reason) {
159
+ _internals.emit("scope_violation", { sessionId, agentName, file, reason });
160
+ },
161
+ qaSkipViolation(sessionId, agentName, skipCount) {
162
+ _internals.emit("qa_skip_violation", { sessionId, agentName, skipCount });
163
+ },
164
+ heartbeat(sessionId) {
165
+ _internals.emit("heartbeat", { sessionId });
166
+ },
167
+ turboModeChanged(sessionId, enabled, agentName) {
168
+ _internals.emit("turbo_mode_changed", { sessionId, enabled, agentName });
169
+ },
170
+ autoOversightEscalation(sessionId, reason, interactionCount, deadlockCount, phase) {
171
+ _internals.emit("auto_oversight_escalation", {
172
+ sessionId,
173
+ reason,
174
+ interactionCount,
175
+ deadlockCount,
176
+ phase
177
+ });
178
+ },
179
+ environmentDetected(sessionId, hostOS, shellFamily, executionMode) {
180
+ _internals.emit("environment_detected", {
181
+ sessionId,
182
+ hostOS,
183
+ shellFamily,
184
+ executionMode
185
+ });
186
+ },
187
+ prmPatternDetected(sessionId, pattern, severity, category, stepRange) {
188
+ _internals.emit("prm_pattern_detected", {
189
+ sessionId,
190
+ pattern,
191
+ severity,
192
+ category,
193
+ stepRange
194
+ });
195
+ },
196
+ prmCourseCorrectionInjected(sessionId, pattern, level) {
197
+ _internals.emit("prm_course_correction_injected", {
198
+ sessionId,
199
+ pattern,
200
+ level
201
+ });
202
+ },
203
+ prmEscalationTriggered(sessionId, pattern, level, occurrenceCount) {
204
+ _internals.emit("prm_escalation_triggered", {
205
+ sessionId,
206
+ pattern,
207
+ level,
208
+ occurrenceCount
209
+ });
210
+ },
211
+ prmHardStop(sessionId, pattern, level, occurrenceCount) {
212
+ _internals.emit("prm_hard_stop", {
213
+ sessionId,
214
+ pattern,
215
+ level,
216
+ occurrenceCount
217
+ });
218
+ }
219
+ };
220
+ var _internals = { telemetry, emit };
221
+
222
+ export { resetTelemetryForTesting, initTelemetry, emit, addTelemetryListener, rotateTelemetryIfNeeded, telemetry, _internals };
@@ -0,0 +1,412 @@
1
+ // @bun
2
+ import {
3
+ handleGuardrailExplain
4
+ } from "./index-x7qck34v.js";
5
+ import {
6
+ handleGuardrailLog
7
+ } from "./index-5cb86007.js";
8
+ import {
9
+ COMMAND_REGISTRY,
10
+ SWARM_COMMAND_TOOL_ALLOWLIST,
11
+ SWARM_COMMAND_TOOL_COMMANDS,
12
+ VALID_COMMANDS,
13
+ _internals,
14
+ canonicalCommandKey,
15
+ classifySwarmCommandChatFallbackUse,
16
+ classifySwarmCommandToolUse,
17
+ executeSwarmCommand,
18
+ formatCommandNotFound,
19
+ handleAcknowledgeSpecDriftCommand,
20
+ handleAgentsCommand,
21
+ handleAnalyzeCommand,
22
+ handleArchiveCommand,
23
+ handleAutoProceedCommand,
24
+ handleBenchmarkCommand,
25
+ handleBrainstormCommand,
26
+ handleCheckpointCommand,
27
+ handleClarifyCommand,
28
+ handleCloseCommand,
29
+ handleCodebaseReviewCommand,
30
+ handleConcurrencyCommand,
31
+ handleConfigCommand,
32
+ handleConsolidateCommand,
33
+ handleCouncilCommand,
34
+ handleCurateCommand,
35
+ handleDarkMatterCommand,
36
+ handleDeepDiveCommand,
37
+ handleDeepResearchCommand,
38
+ handleDiagnoseCommand,
39
+ handleDoctorCommand,
40
+ handleEvidenceCommand,
41
+ handleEvidenceSummaryCommand,
42
+ handleExportCommand,
43
+ handleFullAutoCommand,
44
+ handleHandoffCommand,
45
+ handleHelpCommand,
46
+ handleHistoryCommand,
47
+ handleKnowledgeListCommand,
48
+ handleKnowledgeMigrateCommand,
49
+ handleKnowledgeQuarantineCommand,
50
+ handleKnowledgeRestoreCommand,
51
+ handleKnowledgeRetryHardeningCommand,
52
+ handleKnowledgeUnactionableCommand,
53
+ handleLearningCommand,
54
+ handleMemoryCommand,
55
+ handleMemoryExportCommand,
56
+ handleMemoryImportCommand,
57
+ handleMemoryMigrateCommand,
58
+ handleMemoryStatusCommand,
59
+ handlePlanCommand,
60
+ handlePreflightCommand,
61
+ handlePromoteCommand,
62
+ handleQaGatesCommand,
63
+ handleResetCommand,
64
+ handleResetSessionCommand,
65
+ handleRetrieveCommand,
66
+ handleRollbackCommand,
67
+ handleSddCommand,
68
+ handleSddProjectCommand,
69
+ handleSddStatusCommand,
70
+ handleSddValidateCommand,
71
+ handleSimulateCommand,
72
+ handleSpecifyCommand,
73
+ handleStatusCommand,
74
+ handleSyncPlanCommand,
75
+ handleTurboCommand,
76
+ handleWriteRetroCommand,
77
+ normalizeSwarmCommandInput,
78
+ resolveCommand
79
+ } from "./index-yhqt45de.js";
80
+ import"./index-vq2321gg.js";
81
+ import"./index-yhsmmv2z.js";
82
+ import"./index-d9fbxaqd.js";
83
+ import"./index-e8pk68cc.js";
84
+ import"./index-0sxvwjt0.js";
85
+ import {
86
+ AGENT_TOOL_MAP,
87
+ ORCHESTRATOR_NAME,
88
+ stripKnownSwarmPrefix
89
+ } from "./index-hw9b2xng.js";
90
+ import"./index-red8fm8p.js";
91
+ import"./index-f8r50m3h.js";
92
+ import"./index-hz59hg4h.js";
93
+ import"./index-e7h9bb6v.js";
94
+ import"./index-fjwwrwr5.js";
95
+ import"./index-eb85wtx9.js";
96
+ import"./index-ckntc5gf.js";
97
+ import"./index-jtqkh8jf.js";
98
+ import"./index-zfsbaaqh.js";
99
+ import"./index-p0arc26j.js";
100
+ import"./index-yx44zd0p.js";
101
+ import"./index-bcp79s17.js";
102
+ import"./index-293f68mj.js";
103
+ import"./index-b9v501fr.js";
104
+ import"./index-p0ye10nd.js";
105
+ import"./index-a76rekgs.js";
106
+ // src/commands/command-names.ts
107
+ var COMMAND_NAMES = Object.freeze(Object.keys(COMMAND_REGISTRY));
108
+ var COMMAND_NAME_SET = new Set(COMMAND_NAMES);
109
+
110
+ // src/commands/index.ts
111
+ function buildHelpText() {
112
+ const lines = [
113
+ "## Swarm Commands",
114
+ "",
115
+ "**Chat routing note**: supported read-only `/swarm` commands are routed through the `swarm_command` tool when the active agent has that tool. Unsupported or state-changing commands remain chat-mediated; use `bunx opencode-swarm run <subcommand>` when you need canonical output.",
116
+ ""
117
+ ];
118
+ const CATEGORIES = [
119
+ "core",
120
+ "agent",
121
+ "config",
122
+ "diagnostics",
123
+ "utility"
124
+ ];
125
+ const byCategory = new Map;
126
+ for (const cat of CATEGORIES) {
127
+ byCategory.set(cat, []);
128
+ }
129
+ const deprecatedAliases = [];
130
+ for (const cmd of VALID_COMMANDS) {
131
+ const entry = COMMAND_REGISTRY[cmd];
132
+ if (entry.aliasOf) {
133
+ deprecatedAliases.push({ name: cmd, aliasOf: entry.aliasOf });
134
+ continue;
135
+ }
136
+ if (entry.subcommandOf) {
137
+ continue;
138
+ }
139
+ if (cmd.includes(" ")) {
140
+ continue;
141
+ }
142
+ const category = entry.category || "utility";
143
+ const catLines = byCategory.get(category) || [];
144
+ catLines.push(cmd);
145
+ byCategory.set(category, catLines);
146
+ }
147
+ const shownAsSubcommand = new Set;
148
+ for (const cat of CATEGORIES) {
149
+ const catLines = byCategory.get(cat);
150
+ if (!catLines || catLines.length === 0)
151
+ continue;
152
+ const catTitle = cat.charAt(0).toUpperCase() + cat.slice(1);
153
+ lines.push(`### ${catTitle}`, "");
154
+ for (const cmd of catLines) {
155
+ const entry = COMMAND_REGISTRY[cmd];
156
+ lines.push(`- \`/swarm ${cmd}\` \u2014 ${entry.description}`);
157
+ if (entry.clashesWithNativeCcCommand) {
158
+ lines.push(` \u26A0\uFE0F Name conflicts with CC built-in \`${entry.clashesWithNativeCcCommand}\` \u2014 always use \`/swarm ${cmd}\``);
159
+ }
160
+ if (entry.args) {
161
+ lines.push(` Args: \`${entry.args}\``);
162
+ }
163
+ if (entry.details) {
164
+ lines.push(` ${entry.details}`);
165
+ }
166
+ const subcommands = VALID_COMMANDS.filter((sub) => sub.startsWith(`${cmd} `) && sub !== cmd);
167
+ for (const sub of subcommands) {
168
+ shownAsSubcommand.add(sub);
169
+ const subEntry = COMMAND_REGISTRY[sub];
170
+ const subName = sub.slice(cmd.length + 1);
171
+ lines.push(` - \`${subName}\` \u2014 ${subEntry.description}`);
172
+ if (subEntry.args) {
173
+ lines.push(` Args: \`${subEntry.args}\``);
174
+ }
175
+ if (subEntry.details) {
176
+ lines.push(` ${subEntry.details}`);
177
+ }
178
+ }
179
+ }
180
+ lines.push("");
181
+ }
182
+ for (const cmd of VALID_COMMANDS) {
183
+ if (!cmd.includes(" ") || shownAsSubcommand.has(cmd))
184
+ continue;
185
+ const entry = COMMAND_REGISTRY[cmd];
186
+ if (entry.aliasOf || entry.subcommandOf)
187
+ continue;
188
+ lines.push(`- \`/swarm ${cmd}\` \u2014 ${entry.description}`);
189
+ if (entry.clashesWithNativeCcCommand) {
190
+ lines.push(` \u26A0\uFE0F Name conflicts with CC built-in \`${entry.clashesWithNativeCcCommand}\` \u2014 always use \`/swarm ${cmd}\``);
191
+ }
192
+ if (entry.args) {
193
+ lines.push(` Args: \`${entry.args}\``);
194
+ }
195
+ if (entry.details) {
196
+ lines.push(` ${entry.details}`);
197
+ }
198
+ }
199
+ if (deprecatedAliases.length > 0) {
200
+ lines.push("### Deprecated Commands", "");
201
+ for (const { name, aliasOf } of deprecatedAliases) {
202
+ lines.push(`- \`/swarm ${name}\` \u2192 Use \`/swarm ${aliasOf}\``);
203
+ const aliasEntry = COMMAND_REGISTRY[name];
204
+ if (aliasEntry?.clashesWithNativeCcCommand) {
205
+ lines.push(` \u26A0\uFE0F Name conflicts with CC built-in \`${aliasEntry.clashesWithNativeCcCommand}\` \u2014 always use \`/swarm ${aliasOf}\``);
206
+ }
207
+ }
208
+ }
209
+ return lines.join(`
210
+ `);
211
+ }
212
+ function createSwarmCommandHandler(directory, agents, options = {}) {
213
+ return async (input, output) => {
214
+ const normalized = normalizeSwarmCommandInput(input.command, input.arguments);
215
+ if (!normalized.isSwarmCommand) {
216
+ return;
217
+ }
218
+ output.parts.splice(0, output.parts.length, {
219
+ type: "text",
220
+ text: await buildSwarmCommandPrompt({
221
+ directory,
222
+ agents,
223
+ sessionID: input.sessionID,
224
+ tokens: normalized.tokens,
225
+ activeAgentName: options.getActiveAgentName?.(input.sessionID),
226
+ packageRoot: options.packageRoot,
227
+ registeredAgents: options.registeredAgents
228
+ })
229
+ });
230
+ return;
231
+ };
232
+ }
233
+ async function buildSwarmCommandPrompt(args) {
234
+ const {
235
+ directory,
236
+ agents,
237
+ sessionID,
238
+ tokens,
239
+ activeAgentName,
240
+ packageRoot,
241
+ registeredAgents
242
+ } = args;
243
+ const resolved = _internals.resolveCommand(tokens);
244
+ if (!resolved) {
245
+ if (tokens.length === 0) {
246
+ return buildHelpText();
247
+ }
248
+ return formatCommandNotFound(tokens);
249
+ }
250
+ const typedResolved = resolved;
251
+ const canonicalKey = canonicalCommandKey(typedResolved);
252
+ const policy = classifySwarmCommandToolUse(typedResolved);
253
+ const isV1ToolCommand = SWARM_COMMAND_TOOL_ALLOWLIST.has(canonicalKey);
254
+ const canUseTool = agentHasSwarmCommandTool(activeAgentName, agents, registeredAgents);
255
+ if (canUseTool && policy.allowed && isV1ToolCommand) {
256
+ return routeToSwarmCommandTool({
257
+ command: canonicalKey,
258
+ args: resolved.remainingArgs,
259
+ original: `/swarm ${tokens.join(" ")}`.trim()
260
+ });
261
+ }
262
+ if (canUseTool && isV1ToolCommand && !policy.allowed) {
263
+ return [
264
+ `The user typed \`/swarm ${tokens.join(" ")}\`.`,
265
+ policy.message,
266
+ "Do not invent command output. Explain the limitation and recommend the canonical CLI path above."
267
+ ].join(`
268
+ `);
269
+ }
270
+ const chatFallbackPolicy = classifySwarmCommandChatFallbackUse(typedResolved);
271
+ if (!chatFallbackPolicy.allowed) {
272
+ return [
273
+ `The user typed \`/swarm ${tokens.join(" ")}\`.`,
274
+ chatFallbackPolicy.message,
275
+ "Do not execute this command through chat and do not invent command output."
276
+ ].join(`
277
+ `);
278
+ }
279
+ const result = await executeSwarmCommand({
280
+ directory,
281
+ agents,
282
+ sessionID,
283
+ tokens,
284
+ packageRoot
285
+ });
286
+ return formatCanonicalPromptFallback({
287
+ original: `/swarm ${tokens.join(" ")}`.trim(),
288
+ text: result.text
289
+ });
290
+ }
291
+ function agentHasSwarmCommandTool(activeAgentName, agents, registeredAgents) {
292
+ const name = activeAgentName ?? ORCHESTRATOR_NAME;
293
+ const registeredTools = registeredAgents?.[name]?.tools;
294
+ if (registeredTools) {
295
+ return registeredTools.swarm_command === true;
296
+ }
297
+ const explicitTools = agents[name]?.config?.tools;
298
+ if (explicitTools) {
299
+ return explicitTools.swarm_command === true;
300
+ }
301
+ const baseName = stripKnownSwarmPrefix(name);
302
+ return AGENT_TOOL_MAP[baseName]?.includes("swarm_command") === true;
303
+ }
304
+ function formatCanonicalPromptFallback(args) {
305
+ if (/^\s*\[MODE:/.test(args.text)) {
306
+ return [
307
+ `The user typed \`${args.original}\`.`,
308
+ "The line below is a swarm MODE-activation signal, NOT output to display.",
309
+ "Enter the mode named in its `[MODE: X ...]` header now: follow your",
310
+ 'prompt\u2019s "### MODE: X" section, load the SKILL.md it references, and',
311
+ "follow that protocol exactly. Treat any text after the closing bracket as",
312
+ "additional instructions. Do NOT echo this signal verbatim.",
313
+ "",
314
+ args.text
315
+ ].join(`
316
+ `);
317
+ }
318
+ return [
319
+ `The user typed \`${args.original}\`.`,
320
+ "Canonical opencode-swarm command output follows.",
321
+ "Show this output verbatim and add no extra swarm state.",
322
+ "",
323
+ args.text
324
+ ].join(`
325
+ `);
326
+ }
327
+ function routeToSwarmCommandTool(args) {
328
+ return [
329
+ `The user typed \`${args.original}\`.`,
330
+ "Call the `swarm_command` tool exactly once with:",
331
+ JSON.stringify({ command: args.command, args: args.args }, null, 2),
332
+ "After the tool returns, show the tool output verbatim and add no extra swarm state."
333
+ ].join(`
334
+ `);
335
+ }
336
+ export {
337
+ resolveCommand,
338
+ normalizeSwarmCommandInput,
339
+ handleWriteRetroCommand,
340
+ handleTurboCommand,
341
+ handleSyncPlanCommand,
342
+ handleStatusCommand,
343
+ handleSpecifyCommand,
344
+ handleSimulateCommand,
345
+ handleSddValidateCommand,
346
+ handleSddStatusCommand,
347
+ handleSddProjectCommand,
348
+ handleSddCommand,
349
+ handleRollbackCommand,
350
+ handleRetrieveCommand,
351
+ handleResetSessionCommand,
352
+ handleResetCommand,
353
+ handleQaGatesCommand,
354
+ handlePromoteCommand,
355
+ handlePreflightCommand,
356
+ handlePlanCommand,
357
+ handleMemoryStatusCommand,
358
+ handleMemoryMigrateCommand,
359
+ handleMemoryImportCommand,
360
+ handleMemoryExportCommand,
361
+ handleMemoryCommand,
362
+ handleLearningCommand,
363
+ handleKnowledgeUnactionableCommand,
364
+ handleKnowledgeRetryHardeningCommand,
365
+ handleKnowledgeRestoreCommand,
366
+ handleKnowledgeQuarantineCommand,
367
+ handleKnowledgeMigrateCommand,
368
+ handleKnowledgeListCommand,
369
+ handleHistoryCommand,
370
+ handleHelpCommand,
371
+ handleHandoffCommand,
372
+ handleGuardrailLog,
373
+ handleGuardrailExplain,
374
+ handleFullAutoCommand,
375
+ handleExportCommand,
376
+ handleEvidenceSummaryCommand,
377
+ handleEvidenceCommand,
378
+ handleDoctorCommand,
379
+ handleDiagnoseCommand,
380
+ handleDeepResearchCommand,
381
+ handleDeepDiveCommand,
382
+ handleDarkMatterCommand,
383
+ handleCurateCommand,
384
+ handleCouncilCommand,
385
+ handleConsolidateCommand,
386
+ handleConfigCommand,
387
+ handleConcurrencyCommand,
388
+ handleCodebaseReviewCommand,
389
+ handleCloseCommand,
390
+ handleClarifyCommand,
391
+ handleCheckpointCommand,
392
+ handleBrainstormCommand,
393
+ handleBenchmarkCommand,
394
+ handleAutoProceedCommand,
395
+ handleArchiveCommand,
396
+ handleAnalyzeCommand,
397
+ handleAgentsCommand,
398
+ handleAcknowledgeSpecDriftCommand,
399
+ formatCommandNotFound,
400
+ executeSwarmCommand,
401
+ createSwarmCommandHandler,
402
+ classifySwarmCommandToolUse,
403
+ classifySwarmCommandChatFallbackUse,
404
+ buildHelpText,
405
+ agentHasSwarmCommandTool,
406
+ VALID_COMMANDS,
407
+ SWARM_COMMAND_TOOL_COMMANDS,
408
+ SWARM_COMMAND_TOOL_ALLOWLIST,
409
+ COMMAND_REGISTRY,
410
+ COMMAND_NAME_SET,
411
+ COMMAND_NAMES
412
+ };