opencode-orchestra 0.0.0-stage → 1.1.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.
- package/README.md +49 -2
- package/dist/board.d.ts +47 -0
- package/dist/board.js +89 -0
- package/dist/context.d.ts +22 -0
- package/dist/context.js +120 -0
- package/dist/dispatch.d.ts +24 -0
- package/dist/dispatch.js +49 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +591 -0
- package/dist/parser.d.ts +63 -0
- package/dist/parser.js +411 -0
- package/dist/pipeline.d.ts +74 -0
- package/dist/pipeline.js +188 -0
- package/dist/prompts.d.ts +7 -0
- package/dist/prompts.js +175 -0
- package/dist/session-registry.d.ts +77 -0
- package/dist/session-registry.js +200 -0
- package/dist/swarm.d.ts +61 -0
- package/dist/swarm.js +369 -0
- package/dist/teamwork.d.ts +45 -0
- package/dist/teamwork.js +545 -0
- package/dist/tui.d.ts +3 -0
- package/dist/tui.js +169 -0
- package/dist/verify.d.ts +24 -0
- package/dist/verify.js +117 -0
- package/package.json +34 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
import { Plugin } from "@opencode/plugin";
|
|
2
|
+
import { dispatchBackground } from "./dispatch.js";
|
|
3
|
+
import { checkPeerWait, getBoardHead, postToBoard, readBoard, } from "./board.js";
|
|
4
|
+
import { parseBoostArgs, parseModelRef, parseSwarmArgs, parseTeamworkArgs, } from "./parser.js";
|
|
5
|
+
import { runBoostPipeline } from "./pipeline.js";
|
|
6
|
+
import { runSwarmPipeline } from "./swarm.js";
|
|
7
|
+
import { runTeamworkPipeline, } from "./teamwork.js";
|
|
8
|
+
import { verifyReportAutomatically } from "./verify.js";
|
|
9
|
+
import { advanceSwarmWorkerOnOwnPost, applyContextHook, applyIdleParkGuardHook, clearCoordinatorOnIdle, registerCoordinatorSession, resetSessionRegistry, unregisterCoordinatorSession, } from "./session-registry.js";
|
|
10
|
+
function clampInt(value, min, max, fallback) {
|
|
11
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
12
|
+
return Math.max(min, Math.min(max, Math.floor(value)));
|
|
13
|
+
}
|
|
14
|
+
return fallback;
|
|
15
|
+
}
|
|
16
|
+
function readPluginConfig(options) {
|
|
17
|
+
const cfg = (options ?? {});
|
|
18
|
+
const defaultMode = cfg.defaultMode === "coder" || cfg.defaultMode === "investigate"
|
|
19
|
+
? cfg.defaultMode
|
|
20
|
+
: "auto";
|
|
21
|
+
const teamworkDefaultMode = cfg.teamworkDefaultMode === "swe" ||
|
|
22
|
+
cfg.teamworkDefaultMode === "review" ||
|
|
23
|
+
cfg.teamworkDefaultMode === "colosseum" ||
|
|
24
|
+
cfg.teamworkDefaultMode === "discover" ||
|
|
25
|
+
cfg.teamworkDefaultMode === "audit"
|
|
26
|
+
? cfg.teamworkDefaultMode
|
|
27
|
+
: "auto";
|
|
28
|
+
const swarmDefaultMode = cfg.swarmDefaultMode === "fanout" || cfg.swarmDefaultMode === "pipeline"
|
|
29
|
+
? cfg.swarmDefaultMode
|
|
30
|
+
: "auto";
|
|
31
|
+
return {
|
|
32
|
+
defaultMode,
|
|
33
|
+
improvementRounds: clampInt(cfg.improvementRounds, 0, 5, 1),
|
|
34
|
+
maxExtraVerificationRounds: clampInt(cfg.maxExtraVerificationRounds, 0, 3, 1),
|
|
35
|
+
teamworkDefaultMode,
|
|
36
|
+
teamworkQaRounds: clampInt(cfg.teamworkQaRounds, 0, 3, 1),
|
|
37
|
+
teamworkWorkers: clampInt(cfg.teamworkWorkers, 2, 5, 2),
|
|
38
|
+
swarmDefaultMode,
|
|
39
|
+
swarmWorkers: clampInt(cfg.swarmWorkers, 2, 6, 3),
|
|
40
|
+
modelOverride: parseModelRef(cfg.model),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function verificationMode(requested) {
|
|
44
|
+
return requested === "investigate" || requested === "review" || requested === "coder"
|
|
45
|
+
? requested
|
|
46
|
+
: "generic";
|
|
47
|
+
}
|
|
48
|
+
function formatBoostOutput(result) {
|
|
49
|
+
const pipelineName = result.mode === "coder" ? "DeepCoder" : "DeepInvestigator";
|
|
50
|
+
return [
|
|
51
|
+
`# Boost (${pipelineName}) — ${result.verificationVerdict}`,
|
|
52
|
+
"",
|
|
53
|
+
`- **Pipeline**: \`${pipelineName}\` (${result.roundsExecuted} improvement round(s))`,
|
|
54
|
+
`- **Isolated sub-sessions**: ${result.childSessionIDs.length}`,
|
|
55
|
+
"",
|
|
56
|
+
result.report,
|
|
57
|
+
].join("\n");
|
|
58
|
+
}
|
|
59
|
+
function formatTeamworkOutput(result) {
|
|
60
|
+
const trackLabel = result.mode === "swe"
|
|
61
|
+
? "SWE Light"
|
|
62
|
+
: result.mode === "review"
|
|
63
|
+
? "Review Track"
|
|
64
|
+
: result.mode === "discover"
|
|
65
|
+
? "Duo Discovery"
|
|
66
|
+
: result.mode === "audit"
|
|
67
|
+
? "Forensic & Victory Audit"
|
|
68
|
+
: "Colosseum";
|
|
69
|
+
return [
|
|
70
|
+
`# Teamwork (${trackLabel}) — ${result.gateVerdict}`,
|
|
71
|
+
"",
|
|
72
|
+
`- **Track**: \`${trackLabel}\`${result.mode === "swe" ? ` (${result.qaRoundsExecuted} QA round(s))` : ""}`,
|
|
73
|
+
`- **Isolated sub-sessions**: ${result.childSessionIDs.length}`,
|
|
74
|
+
"",
|
|
75
|
+
result.report,
|
|
76
|
+
"",
|
|
77
|
+
result.gateSummary,
|
|
78
|
+
].join("\n");
|
|
79
|
+
}
|
|
80
|
+
function formatSwarmOutput(result) {
|
|
81
|
+
const modeLabel = result.mode === "pipeline" ? "Pipeline Conductor" : "Swarm Orchestrator";
|
|
82
|
+
return [
|
|
83
|
+
`# Swarm (${modeLabel})`,
|
|
84
|
+
"",
|
|
85
|
+
`- **Workers**: ${result.succeededWorkers}/${result.workerCount} succeeded${result.failedWorkers > 0 ? ` (${result.failedWorkers} failed)` : ""}`,
|
|
86
|
+
`- **Isolated sub-sessions**: ${result.childSessionIDs.length}`,
|
|
87
|
+
"",
|
|
88
|
+
result.report,
|
|
89
|
+
"",
|
|
90
|
+
result.blackboard,
|
|
91
|
+
].join("\n");
|
|
92
|
+
}
|
|
93
|
+
function dispatchDirective(role, args, mode, askFirst) {
|
|
94
|
+
return [
|
|
95
|
+
`[Orchestra ${role} command] The latest user message is the original request. Do not solve it inline and do not delegate it to a generic subagent.`,
|
|
96
|
+
askFirst
|
|
97
|
+
? "Ask concise scoping questions first, then call the tool with the user's answers."
|
|
98
|
+
: `Call the \`${role}\` tool now with these arguments, keeping the task verbatim.`,
|
|
99
|
+
JSON.stringify(args),
|
|
100
|
+
`One ${role} head orchestrator will control every worker and verifier subagent. The tool returns at once, so tell the user only what was dispatched and end this turn.`,
|
|
101
|
+
"When the completion arrives, confirm the material claims in the workspace, then reply only with the answer to the original request. Leave out the process, who was right or wrong, mistakes, confidence language, and the verification narrative.",
|
|
102
|
+
`Verification mode: ${mode}.`,
|
|
103
|
+
].join("\n");
|
|
104
|
+
}
|
|
105
|
+
const EMPTY_TASK_DIRECTIVE = {
|
|
106
|
+
boost: "The user invoked /boost without an inline task. If the conversation has a clear pending task, call boost with that task. Otherwise show /boost [--coder | --investigate] [--rounds=N] <task>. Do not invent a task.",
|
|
107
|
+
teamwork: "The user invoked /teamwork without an inline task. If a clear pending task exists, call teamwork with it. Otherwise show /teamwork [--swe | --review | --audit | --discover | --colosseum] <task>. Do not invent a task.",
|
|
108
|
+
swarm: "The user invoked /swarm without an inline task. If a clear pending task exists, call swarm with it. Otherwise show /swarm [--fanout | --pipeline] <task>. Do not invent a task.",
|
|
109
|
+
};
|
|
110
|
+
export default Plugin.define({
|
|
111
|
+
id: "opencode.orchestra",
|
|
112
|
+
async setup(ctx) {
|
|
113
|
+
const pluginCfg = readPluginConfig(ctx.options);
|
|
114
|
+
const registrations = [];
|
|
115
|
+
const formatModelSpec = (ref) => ref ? `${ref.providerID}/${ref.id}` : undefined;
|
|
116
|
+
const runVerifier = async (sessionID, task, report, mode, modelOverride, verifierTitle) => {
|
|
117
|
+
const result = await verifyReportAutomatically(ctx.session, {
|
|
118
|
+
sessionID,
|
|
119
|
+
task,
|
|
120
|
+
report,
|
|
121
|
+
mode,
|
|
122
|
+
verifierTitle,
|
|
123
|
+
maxVerificationRounds: pluginCfg.maxExtraVerificationRounds + 1,
|
|
124
|
+
...(modelOverride ? { modelOverride } : {}),
|
|
125
|
+
});
|
|
126
|
+
if (!result.blocked)
|
|
127
|
+
return { status: "verified", detail: "" };
|
|
128
|
+
return {
|
|
129
|
+
status: "blocked",
|
|
130
|
+
detail: result.blockers.join("; "),
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
const dispatched = (role, runID) => ({
|
|
134
|
+
content: `Dispatched ${runID}. One ${role} head orchestrator owns all worker and verifier subagents. Tell the user only what was dispatched, then end this turn.`,
|
|
135
|
+
});
|
|
136
|
+
const cmdReg = await ctx.command.transform((editor) => {
|
|
137
|
+
editor.add({
|
|
138
|
+
name: "boost",
|
|
139
|
+
description: "Run multi-agent deep reasoning (Layer 0 + adversarial improvement + orchestrator verification) using the active model.",
|
|
140
|
+
execute: async ({ sessionID, prompt, delivery }) => {
|
|
141
|
+
const parsed = parseBoostArgs(prompt.text ?? "");
|
|
142
|
+
const baseArgs = {
|
|
143
|
+
...(parsed.task ? { task: parsed.task } : {}),
|
|
144
|
+
mode: parsed.mode === "auto" ? pluginCfg.defaultMode : parsed.mode,
|
|
145
|
+
rounds: parsed.rounds ?? pluginCfg.improvementRounds,
|
|
146
|
+
...(formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride)
|
|
147
|
+
? {
|
|
148
|
+
model: formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride),
|
|
149
|
+
}
|
|
150
|
+
: {}),
|
|
151
|
+
};
|
|
152
|
+
registerCoordinatorSession(sessionID, "boost", {
|
|
153
|
+
directive: parsed.task
|
|
154
|
+
? dispatchDirective("boost", baseArgs, verificationMode(parsed.mode), false)
|
|
155
|
+
: EMPTY_TASK_DIRECTIVE.boost,
|
|
156
|
+
});
|
|
157
|
+
await ctx.session.prompt({
|
|
158
|
+
...prompt,
|
|
159
|
+
sessionID,
|
|
160
|
+
text: prompt.text || "/boost",
|
|
161
|
+
delivery,
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
editor.add({
|
|
166
|
+
name: "teamwork",
|
|
167
|
+
description: "Run role-based Teamwork multi-agent orchestration (SWE Light, Review Track, Audit Track, Duo Discovery, or Colosseum + Verifier + Judge).",
|
|
168
|
+
execute: async ({ sessionID, prompt, delivery }) => {
|
|
169
|
+
const parsed = parseTeamworkArgs(prompt.text ?? "");
|
|
170
|
+
const baseArgs = {
|
|
171
|
+
...(parsed.task ? { task: parsed.task } : {}),
|
|
172
|
+
mode: parsed.mode === "auto"
|
|
173
|
+
? pluginCfg.teamworkDefaultMode
|
|
174
|
+
: parsed.mode,
|
|
175
|
+
qaRounds: parsed.qaRounds ?? pluginCfg.teamworkQaRounds,
|
|
176
|
+
workers: parsed.workers ?? pluginCfg.teamworkWorkers,
|
|
177
|
+
...(formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride)
|
|
178
|
+
? {
|
|
179
|
+
model: formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride),
|
|
180
|
+
}
|
|
181
|
+
: {}),
|
|
182
|
+
};
|
|
183
|
+
registerCoordinatorSession(sessionID, "teamwork", {
|
|
184
|
+
directive: parsed.task
|
|
185
|
+
? dispatchDirective("teamwork", baseArgs, verificationMode(parsed.mode), !parsed.skipInterview)
|
|
186
|
+
: EMPTY_TASK_DIRECTIVE.teamwork,
|
|
187
|
+
});
|
|
188
|
+
await ctx.session.prompt({
|
|
189
|
+
...prompt,
|
|
190
|
+
sessionID,
|
|
191
|
+
text: prompt.text || "/teamwork",
|
|
192
|
+
delivery,
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
editor.add({
|
|
197
|
+
name: "swarm",
|
|
198
|
+
description: "Run parallel Swarm multi-agent orchestration (Swarm Orchestrator fan-out or Pipeline Conductor multi-stage + Blackboard + Synthesizer).",
|
|
199
|
+
execute: async ({ sessionID, prompt, delivery }) => {
|
|
200
|
+
const parsed = parseSwarmArgs(prompt.text ?? "");
|
|
201
|
+
const baseArgs = {
|
|
202
|
+
...(parsed.task ? { task: parsed.task } : {}),
|
|
203
|
+
mode: parsed.mode === "auto"
|
|
204
|
+
? pluginCfg.swarmDefaultMode
|
|
205
|
+
: parsed.mode,
|
|
206
|
+
workers: parsed.workers ?? pluginCfg.swarmWorkers,
|
|
207
|
+
...(parsed.useWorktree ? { useWorktree: true } : {}),
|
|
208
|
+
...(formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride)
|
|
209
|
+
? {
|
|
210
|
+
model: formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride),
|
|
211
|
+
}
|
|
212
|
+
: {}),
|
|
213
|
+
};
|
|
214
|
+
registerCoordinatorSession(sessionID, "swarm", {
|
|
215
|
+
directive: parsed.task
|
|
216
|
+
? dispatchDirective("swarm", baseArgs, "generic", false)
|
|
217
|
+
: EMPTY_TASK_DIRECTIVE.swarm,
|
|
218
|
+
});
|
|
219
|
+
await ctx.session.prompt({
|
|
220
|
+
...prompt,
|
|
221
|
+
sessionID,
|
|
222
|
+
text: prompt.text || "/swarm",
|
|
223
|
+
delivery,
|
|
224
|
+
});
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
if (cmdReg)
|
|
229
|
+
registrations.push(cmdReg);
|
|
230
|
+
const toolReg = await ctx.tool.transform((editor) => {
|
|
231
|
+
editor.add({
|
|
232
|
+
name: "boost",
|
|
233
|
+
description: "Run the multi-agent Boost deep-reasoning pipeline (DeepCoder / DeepInvestigator + adversarial Improvement Worker + Orchestrator spot-check) on a complex task using the session's active model.",
|
|
234
|
+
input: {
|
|
235
|
+
type: "object",
|
|
236
|
+
properties: {
|
|
237
|
+
task: {
|
|
238
|
+
type: "string",
|
|
239
|
+
description: "The complex coding, debugging, refactoring, or investigation task (verbatim).",
|
|
240
|
+
},
|
|
241
|
+
additionalContext: {
|
|
242
|
+
type: "string",
|
|
243
|
+
description: "Optional relevant context from earlier turns or prior progress (omit on first turn; do not inject your own solution).",
|
|
244
|
+
},
|
|
245
|
+
continueSessionID: {
|
|
246
|
+
type: "string",
|
|
247
|
+
description: "Optional existing worker session ID to continue instead of spawning a fresh Layer 0 session.",
|
|
248
|
+
},
|
|
249
|
+
mode: {
|
|
250
|
+
type: "string",
|
|
251
|
+
enum: ["auto", "coder", "investigate"],
|
|
252
|
+
description: "Pipeline mode: auto (default), coder, or investigate.",
|
|
253
|
+
},
|
|
254
|
+
rounds: {
|
|
255
|
+
type: "integer",
|
|
256
|
+
minimum: 0,
|
|
257
|
+
maximum: 5,
|
|
258
|
+
description: "Number of adversarial improvement rounds after Layer 0 (default 1).",
|
|
259
|
+
},
|
|
260
|
+
model: {
|
|
261
|
+
type: "string",
|
|
262
|
+
description: "Optional providerID/modelID override; omit to inherit the active session model.",
|
|
263
|
+
},
|
|
264
|
+
},
|
|
265
|
+
required: ["task"],
|
|
266
|
+
additionalProperties: false,
|
|
267
|
+
},
|
|
268
|
+
execute: async (rawInput, context) => {
|
|
269
|
+
const input = rawInput;
|
|
270
|
+
const modelOverride = parseModelRef(input.model) ?? pluginCfg.modelOverride;
|
|
271
|
+
const requestedMode = input.mode ?? pluginCfg.defaultMode;
|
|
272
|
+
let report = "";
|
|
273
|
+
const runID = dispatchBackground({
|
|
274
|
+
session: ctx.session,
|
|
275
|
+
sessionID: context.sessionID,
|
|
276
|
+
role: "boost",
|
|
277
|
+
task: input.task,
|
|
278
|
+
run: async () => {
|
|
279
|
+
const result = await runBoostPipeline(ctx.session, {
|
|
280
|
+
sessionID: context.sessionID,
|
|
281
|
+
task: input.task,
|
|
282
|
+
additionalContext: input.additionalContext,
|
|
283
|
+
continueSessionID: input.continueSessionID,
|
|
284
|
+
mode: requestedMode,
|
|
285
|
+
improvementRounds: input.rounds ?? pluginCfg.improvementRounds,
|
|
286
|
+
maxExtraVerificationRounds: pluginCfg.maxExtraVerificationRounds,
|
|
287
|
+
modelOverride,
|
|
288
|
+
});
|
|
289
|
+
report = formatBoostOutput(result);
|
|
290
|
+
return report;
|
|
291
|
+
},
|
|
292
|
+
verify: () => runVerifier(context.sessionID, input.task, report, verificationMode(requestedMode), modelOverride, "Boost Final Verifier"),
|
|
293
|
+
});
|
|
294
|
+
unregisterCoordinatorSession(context.sessionID);
|
|
295
|
+
return dispatched("boost", runID);
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
editor.add({
|
|
299
|
+
name: "teamwork",
|
|
300
|
+
description: "Run role-based Teamwork orchestration: SWE Light (Implementer -> parallel Gate Reviewer & Critic -> QA fix loop), Review Track (parallel Reviewer & Critic -> Track Synthesizer), Audit Track (Forensic + Victory Auditors -> Synthesizer), Duo Discovery (Explorer + Empirical Challenger -> Knowledge Curator), or Colosseum (competing contenders -> independent Verifier -> Judge).",
|
|
301
|
+
input: {
|
|
302
|
+
type: "object",
|
|
303
|
+
properties: {
|
|
304
|
+
task: {
|
|
305
|
+
type: "string",
|
|
306
|
+
description: "The engineering, review, audit, discovery, or architecture comparison task (verbatim).",
|
|
307
|
+
},
|
|
308
|
+
additionalContext: {
|
|
309
|
+
type: "string",
|
|
310
|
+
description: "Optional relevant context from earlier conversation turns.",
|
|
311
|
+
},
|
|
312
|
+
mode: {
|
|
313
|
+
type: "string",
|
|
314
|
+
enum: ["auto", "swe", "review", "audit", "discover", "colosseum"],
|
|
315
|
+
description: "Teamwork track: auto (default), swe, review, audit, discover, or colosseum.",
|
|
316
|
+
},
|
|
317
|
+
qaRounds: {
|
|
318
|
+
type: "integer",
|
|
319
|
+
minimum: 0,
|
|
320
|
+
maximum: 3,
|
|
321
|
+
description: "Maximum QA fix rounds if SWE gate fails (default 1).",
|
|
322
|
+
},
|
|
323
|
+
workers: {
|
|
324
|
+
type: "integer",
|
|
325
|
+
minimum: 2,
|
|
326
|
+
maximum: 5,
|
|
327
|
+
description: "Number of competing contenders in colosseum mode (default 2).",
|
|
328
|
+
},
|
|
329
|
+
scopingContext: {
|
|
330
|
+
type: "string",
|
|
331
|
+
description: "Optional scoping interview answers, constraints, and acceptance criteria.",
|
|
332
|
+
},
|
|
333
|
+
model: {
|
|
334
|
+
type: "string",
|
|
335
|
+
description: "Optional providerID/modelID override; omit to inherit the active session model.",
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
required: ["task"],
|
|
339
|
+
additionalProperties: false,
|
|
340
|
+
},
|
|
341
|
+
execute: async (rawInput, context) => {
|
|
342
|
+
const input = rawInput;
|
|
343
|
+
const modelOverride = parseModelRef(input.model) ?? pluginCfg.modelOverride;
|
|
344
|
+
const requestedMode = input.mode ?? pluginCfg.teamworkDefaultMode;
|
|
345
|
+
let report = "";
|
|
346
|
+
const runID = dispatchBackground({
|
|
347
|
+
session: ctx.session,
|
|
348
|
+
sessionID: context.sessionID,
|
|
349
|
+
role: "teamwork",
|
|
350
|
+
task: input.task,
|
|
351
|
+
run: async () => {
|
|
352
|
+
const result = await runTeamworkPipeline(ctx.session, {
|
|
353
|
+
sessionID: context.sessionID,
|
|
354
|
+
task: input.task,
|
|
355
|
+
additionalContext: input.additionalContext,
|
|
356
|
+
mode: requestedMode,
|
|
357
|
+
maxQaRounds: input.qaRounds ?? pluginCfg.teamworkQaRounds,
|
|
358
|
+
workers: input.workers ?? pluginCfg.teamworkWorkers,
|
|
359
|
+
scopingContext: input.scopingContext,
|
|
360
|
+
storage: ctx.storage,
|
|
361
|
+
modelOverride,
|
|
362
|
+
});
|
|
363
|
+
report = formatTeamworkOutput(result);
|
|
364
|
+
return report;
|
|
365
|
+
},
|
|
366
|
+
verify: () => runVerifier(context.sessionID, input.task, report, verificationMode(requestedMode), modelOverride),
|
|
367
|
+
});
|
|
368
|
+
unregisterCoordinatorSession(context.sessionID);
|
|
369
|
+
return dispatched("teamwork", runID);
|
|
370
|
+
},
|
|
371
|
+
});
|
|
372
|
+
editor.add({
|
|
373
|
+
name: "swarm",
|
|
374
|
+
description: "Run parallel Swarm orchestration: partitions a task into independent slices executed concurrently by isolated Swarm Workers, tracks status on a Swarm Blackboard, optionally runs a Pipeline Critique stage, and consolidates via a Synthesizer.",
|
|
375
|
+
input: {
|
|
376
|
+
type: "object",
|
|
377
|
+
properties: {
|
|
378
|
+
task: {
|
|
379
|
+
type: "string",
|
|
380
|
+
description: "The task to partition and execute across parallel Swarm Workers (verbatim).",
|
|
381
|
+
},
|
|
382
|
+
additionalContext: {
|
|
383
|
+
type: "string",
|
|
384
|
+
description: "Optional relevant context from earlier conversation turns.",
|
|
385
|
+
},
|
|
386
|
+
mode: {
|
|
387
|
+
type: "string",
|
|
388
|
+
enum: ["auto", "fanout", "pipeline"],
|
|
389
|
+
description: "Swarm mode: auto (default), fanout (single-stage), or pipeline (multi-stage with critique).",
|
|
390
|
+
},
|
|
391
|
+
workers: {
|
|
392
|
+
type: "integer",
|
|
393
|
+
minimum: 2,
|
|
394
|
+
maximum: 6,
|
|
395
|
+
description: "Number of parallel Swarm Workers (default 3).",
|
|
396
|
+
},
|
|
397
|
+
useWorktree: {
|
|
398
|
+
type: "boolean",
|
|
399
|
+
description: "Run each Swarm Worker in its own isolated git worktree (default false).",
|
|
400
|
+
},
|
|
401
|
+
model: {
|
|
402
|
+
type: "string",
|
|
403
|
+
description: "Optional providerID/modelID override; omit to inherit the active session model.",
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
required: ["task"],
|
|
407
|
+
additionalProperties: false,
|
|
408
|
+
},
|
|
409
|
+
execute: async (rawInput, context) => {
|
|
410
|
+
const input = rawInput;
|
|
411
|
+
const modelOverride = parseModelRef(input.model) ?? pluginCfg.modelOverride;
|
|
412
|
+
let report = "";
|
|
413
|
+
const runID = dispatchBackground({
|
|
414
|
+
session: ctx.session,
|
|
415
|
+
sessionID: context.sessionID,
|
|
416
|
+
role: "swarm",
|
|
417
|
+
task: input.task,
|
|
418
|
+
run: async () => {
|
|
419
|
+
const result = await runSwarmPipeline(ctx.session, {
|
|
420
|
+
sessionID: context.sessionID,
|
|
421
|
+
task: input.task,
|
|
422
|
+
additionalContext: input.additionalContext,
|
|
423
|
+
mode: input.mode ?? pluginCfg.swarmDefaultMode,
|
|
424
|
+
workers: input.workers ?? pluginCfg.swarmWorkers,
|
|
425
|
+
useWorktree: input.useWorktree ?? false,
|
|
426
|
+
storage: ctx.storage,
|
|
427
|
+
worktree: ctx.worktree,
|
|
428
|
+
modelOverride,
|
|
429
|
+
});
|
|
430
|
+
report = formatSwarmOutput(result);
|
|
431
|
+
return report;
|
|
432
|
+
},
|
|
433
|
+
verify: () => runVerifier(context.sessionID, input.task, report, "generic", modelOverride),
|
|
434
|
+
});
|
|
435
|
+
unregisterCoordinatorSession(context.sessionID);
|
|
436
|
+
return dispatched("swarm", runID);
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
editor.add({
|
|
440
|
+
name: "swarm_board_post",
|
|
441
|
+
description: "Post a message or finding to the shared Swarm message board for peer workers and the Synthesizer.",
|
|
442
|
+
input: {
|
|
443
|
+
type: "object",
|
|
444
|
+
properties: {
|
|
445
|
+
boardId: {
|
|
446
|
+
type: "string",
|
|
447
|
+
description: "The Swarm board identifier provided in your prompt.",
|
|
448
|
+
},
|
|
449
|
+
author: {
|
|
450
|
+
type: "string",
|
|
451
|
+
description: "Your worker ID (e.g. worker-1).",
|
|
452
|
+
},
|
|
453
|
+
to: {
|
|
454
|
+
type: "string",
|
|
455
|
+
description: "Optional recipient (e.g. all, worker-2, coordinator).",
|
|
456
|
+
},
|
|
457
|
+
message: {
|
|
458
|
+
type: "string",
|
|
459
|
+
description: "Concise status, finding, or blocker to share.",
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
required: ["boardId", "author", "message"],
|
|
463
|
+
additionalProperties: false,
|
|
464
|
+
},
|
|
465
|
+
execute: async (rawInput) => {
|
|
466
|
+
const input = rawInput;
|
|
467
|
+
const post = await postToBoard(ctx.storage, input.boardId, {
|
|
468
|
+
author: input.author,
|
|
469
|
+
to: input.to,
|
|
470
|
+
message: input.message,
|
|
471
|
+
});
|
|
472
|
+
advanceSwarmWorkerOnOwnPost(input.boardId, input.author, post.seq);
|
|
473
|
+
return {
|
|
474
|
+
content: `Posted #${post.seq} to board ${input.boardId}.`,
|
|
475
|
+
};
|
|
476
|
+
},
|
|
477
|
+
});
|
|
478
|
+
editor.add({
|
|
479
|
+
name: "swarm_board_read",
|
|
480
|
+
description: "Read messages from the shared Swarm message board.",
|
|
481
|
+
input: {
|
|
482
|
+
type: "object",
|
|
483
|
+
properties: {
|
|
484
|
+
boardId: {
|
|
485
|
+
type: "string",
|
|
486
|
+
description: "The Swarm board identifier provided in your prompt.",
|
|
487
|
+
},
|
|
488
|
+
afterSeq: {
|
|
489
|
+
type: "integer",
|
|
490
|
+
minimum: 0,
|
|
491
|
+
description: "Optional sequence cursor; only return posts with seq > afterSeq.",
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
required: ["boardId"],
|
|
495
|
+
additionalProperties: false,
|
|
496
|
+
},
|
|
497
|
+
execute: async (rawInput) => {
|
|
498
|
+
const input = rawInput;
|
|
499
|
+
const posts = await readBoard(ctx.storage, input.boardId, input.afterSeq ?? 0);
|
|
500
|
+
if (posts.length === 0) {
|
|
501
|
+
return { content: "(no new posts on board)" };
|
|
502
|
+
}
|
|
503
|
+
return {
|
|
504
|
+
content: posts
|
|
505
|
+
.map((p) => `#${p.seq} [@${p.author}${p.to ? ` -> @${p.to}` : ""}]: ${p.message}`)
|
|
506
|
+
.join("\n"),
|
|
507
|
+
};
|
|
508
|
+
},
|
|
509
|
+
});
|
|
510
|
+
editor.add({
|
|
511
|
+
name: "swarm_board_head",
|
|
512
|
+
description: "Lightweight check of the Swarm message board head (latest sequence number, post count, and active authors).",
|
|
513
|
+
input: {
|
|
514
|
+
type: "object",
|
|
515
|
+
properties: {
|
|
516
|
+
boardId: {
|
|
517
|
+
type: "string",
|
|
518
|
+
description: "The Swarm board identifier provided in your prompt.",
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
required: ["boardId"],
|
|
522
|
+
additionalProperties: false,
|
|
523
|
+
},
|
|
524
|
+
execute: async (rawInput) => {
|
|
525
|
+
const input = rawInput;
|
|
526
|
+
const head = await getBoardHead(ctx.storage, input.boardId);
|
|
527
|
+
return {
|
|
528
|
+
content: `boardId="${input.boardId}" latestSeq=${head.latestSeq} totalPosts=${head.totalPosts} authors=${head.authors.join(", ") || "(none)"}`,
|
|
529
|
+
};
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
editor.add({
|
|
533
|
+
name: "swarm_wait_check",
|
|
534
|
+
description: "Check for unread peer messages addressed to your workerId or 'all' before finishing or parking.",
|
|
535
|
+
input: {
|
|
536
|
+
type: "object",
|
|
537
|
+
properties: {
|
|
538
|
+
boardId: {
|
|
539
|
+
type: "string",
|
|
540
|
+
description: "The Swarm board identifier provided in your prompt.",
|
|
541
|
+
},
|
|
542
|
+
workerId: {
|
|
543
|
+
type: "string",
|
|
544
|
+
description: "Your worker ID (e.g. worker-1).",
|
|
545
|
+
},
|
|
546
|
+
afterSeq: {
|
|
547
|
+
type: "integer",
|
|
548
|
+
minimum: 0,
|
|
549
|
+
description: "Last sequence number you have already read (default 0).",
|
|
550
|
+
},
|
|
551
|
+
},
|
|
552
|
+
required: ["boardId", "workerId"],
|
|
553
|
+
additionalProperties: false,
|
|
554
|
+
},
|
|
555
|
+
execute: async (rawInput) => {
|
|
556
|
+
const input = rawInput;
|
|
557
|
+
const status = await checkPeerWait(ctx.storage, input.boardId, input.workerId, input.afterSeq ?? 0);
|
|
558
|
+
if (!status.hasUnreadPeerActivity) {
|
|
559
|
+
return { content: "(no unread peer activity)" };
|
|
560
|
+
}
|
|
561
|
+
return {
|
|
562
|
+
content: status.unreadForWorker
|
|
563
|
+
.map((p) => `#${p.seq} [@${p.author}${p.to ? ` -> @${p.to}` : ""}]: ${p.message}`)
|
|
564
|
+
.join("\n"),
|
|
565
|
+
};
|
|
566
|
+
},
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
if (toolReg)
|
|
570
|
+
registrations.push(toolReg);
|
|
571
|
+
if (typeof ctx.session.hook === "function") {
|
|
572
|
+
const ctxHookReg = await ctx.session.hook("context", async (event) => {
|
|
573
|
+
await applyContextHook(event, ctx.storage);
|
|
574
|
+
});
|
|
575
|
+
if (ctxHookReg)
|
|
576
|
+
registrations.push(ctxHookReg);
|
|
577
|
+
const idleHookReg = await ctx.session.hook("experimental.idle", async (event) => {
|
|
578
|
+
clearCoordinatorOnIdle(event.sessionID);
|
|
579
|
+
await applyIdleParkGuardHook(event, ctx.storage, ctx.session);
|
|
580
|
+
});
|
|
581
|
+
if (idleHookReg)
|
|
582
|
+
registrations.push(idleHookReg);
|
|
583
|
+
}
|
|
584
|
+
return async () => {
|
|
585
|
+
for (const registration of registrations) {
|
|
586
|
+
await registration.dispose().catch(() => { });
|
|
587
|
+
}
|
|
588
|
+
resetSessionRegistry();
|
|
589
|
+
};
|
|
590
|
+
},
|
|
591
|
+
});
|
package/dist/parser.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export type BoostMode = "auto" | "coder" | "investigate";
|
|
2
|
+
export type ResolvedBoostMode = "coder" | "investigate";
|
|
3
|
+
export interface ModelRef {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly providerID: string;
|
|
6
|
+
readonly variant?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ParsedBoostArgs {
|
|
9
|
+
mode: BoostMode;
|
|
10
|
+
rounds?: number;
|
|
11
|
+
modelOverride?: ModelRef;
|
|
12
|
+
task: string;
|
|
13
|
+
}
|
|
14
|
+
export interface AssistantPartLike {
|
|
15
|
+
type: string;
|
|
16
|
+
text?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SessionMessageLike {
|
|
19
|
+
type: string;
|
|
20
|
+
content?: readonly AssistantPartLike[];
|
|
21
|
+
error?: {
|
|
22
|
+
message?: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
} | unknown;
|
|
25
|
+
}
|
|
26
|
+
export declare function parseModelRef(spec: string | undefined): ModelRef | undefined;
|
|
27
|
+
export declare function parseBoostArgs(raw: string): ParsedBoostArgs;
|
|
28
|
+
export declare function extractAssistantText(messages: readonly SessionMessageLike[]): {
|
|
29
|
+
text: string;
|
|
30
|
+
error?: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function heuristicClassifyTask(task: string): ResolvedBoostMode;
|
|
33
|
+
export declare function parseClassifierDecision(output: string, fallbackTask: string): ResolvedBoostMode;
|
|
34
|
+
export declare function parseVerificationDecision(output: string): {
|
|
35
|
+
passed: boolean;
|
|
36
|
+
reason: string;
|
|
37
|
+
};
|
|
38
|
+
export type TeamworkMode = "auto" | "swe" | "review" | "colosseum" | "discover" | "audit";
|
|
39
|
+
export type ResolvedTeamworkMode = "swe" | "review" | "colosseum" | "discover" | "audit";
|
|
40
|
+
export interface ParsedTeamworkArgs {
|
|
41
|
+
mode: TeamworkMode;
|
|
42
|
+
qaRounds?: number;
|
|
43
|
+
workers?: number;
|
|
44
|
+
skipInterview: boolean;
|
|
45
|
+
modelOverride?: ModelRef;
|
|
46
|
+
task: string;
|
|
47
|
+
}
|
|
48
|
+
export declare function parseTeamworkArgs(raw: string): ParsedTeamworkArgs;
|
|
49
|
+
export declare function heuristicClassifyTeamwork(task: string): ResolvedTeamworkMode;
|
|
50
|
+
export declare function parseTeamworkClassifierDecision(output: string, fallbackTask: string): ResolvedTeamworkMode;
|
|
51
|
+
export type SwarmMode = "auto" | "fanout" | "pipeline";
|
|
52
|
+
export type ResolvedSwarmMode = "fanout" | "pipeline";
|
|
53
|
+
export interface ParsedSwarmArgs {
|
|
54
|
+
mode: SwarmMode;
|
|
55
|
+
workers?: number;
|
|
56
|
+
useWorktree: boolean;
|
|
57
|
+
modelOverride?: ModelRef;
|
|
58
|
+
task: string;
|
|
59
|
+
}
|
|
60
|
+
export declare function parseSwarmArgs(raw: string): ParsedSwarmArgs;
|
|
61
|
+
export declare function heuristicClassifySwarm(task: string): ResolvedSwarmMode;
|
|
62
|
+
export declare function parseSwarmClassifierDecision(output: string, fallbackTask: string): ResolvedSwarmMode;
|
|
63
|
+
export declare function parseSwarmSlices(output: string, count: number, task: string): string[];
|