opencode-orchestra 0.0.0-stage → 1.0.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 +73 -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/index.d.ts +3 -0
- package/dist/index.js +634 -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 +75 -0
- package/dist/session-registry.js +199 -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/package.json +28 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import { Plugin } from "@opencode/plugin";
|
|
2
|
+
import { checkPeerWait, getBoardHead, postToBoard, readBoard, } from "./board.js";
|
|
3
|
+
import { parseBoostArgs, parseModelRef, parseSwarmArgs, parseTeamworkArgs, } from "./parser.js";
|
|
4
|
+
import { runBoostPipeline } from "./pipeline.js";
|
|
5
|
+
import { runSwarmPipeline } from "./swarm.js";
|
|
6
|
+
import { runTeamworkPipeline, } from "./teamwork.js";
|
|
7
|
+
import { advanceSwarmWorkerOnOwnPost, applyContextHook, applyIdleParkGuardHook, clearCoordinatorOnIdle, getSwarmWorkerSession, markSwarmWorkerRead, registerCoordinatorSession, resetSessionRegistry, unregisterCoordinatorSession, } from "./session-registry.js";
|
|
8
|
+
function clampInt(value, min, max, fallback) {
|
|
9
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
10
|
+
return Math.max(min, Math.min(max, Math.floor(value)));
|
|
11
|
+
}
|
|
12
|
+
return fallback;
|
|
13
|
+
}
|
|
14
|
+
function readPluginConfig(options) {
|
|
15
|
+
const cfg = (options ?? {});
|
|
16
|
+
const defaultMode = cfg.defaultMode === "coder" || cfg.defaultMode === "investigate"
|
|
17
|
+
? cfg.defaultMode
|
|
18
|
+
: "auto";
|
|
19
|
+
const teamworkDefaultMode = cfg.teamworkDefaultMode === "swe" ||
|
|
20
|
+
cfg.teamworkDefaultMode === "review" ||
|
|
21
|
+
cfg.teamworkDefaultMode === "colosseum" ||
|
|
22
|
+
cfg.teamworkDefaultMode === "discover" ||
|
|
23
|
+
cfg.teamworkDefaultMode === "audit"
|
|
24
|
+
? cfg.teamworkDefaultMode
|
|
25
|
+
: "auto";
|
|
26
|
+
const swarmDefaultMode = cfg.swarmDefaultMode === "fanout" || cfg.swarmDefaultMode === "pipeline"
|
|
27
|
+
? cfg.swarmDefaultMode
|
|
28
|
+
: "auto";
|
|
29
|
+
return {
|
|
30
|
+
defaultMode,
|
|
31
|
+
improvementRounds: clampInt(cfg.improvementRounds, 0, 5, 1),
|
|
32
|
+
maxExtraVerificationRounds: clampInt(cfg.maxExtraVerificationRounds, 0, 3, 1),
|
|
33
|
+
teamworkDefaultMode,
|
|
34
|
+
teamworkQaRounds: clampInt(cfg.teamworkQaRounds, 0, 3, 1),
|
|
35
|
+
teamworkWorkers: clampInt(cfg.teamworkWorkers, 2, 5, 2),
|
|
36
|
+
swarmDefaultMode,
|
|
37
|
+
swarmWorkers: clampInt(cfg.swarmWorkers, 2, 6, 3),
|
|
38
|
+
modelOverride: parseModelRef(cfg.model),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function formatBoostOutput(result) {
|
|
42
|
+
const pipelineName = result.mode === "coder" ? "DeepCoder" : "DeepInvestigator";
|
|
43
|
+
return [
|
|
44
|
+
`# Boost (${pipelineName}) — ${result.verificationVerdict}`,
|
|
45
|
+
"",
|
|
46
|
+
`- **Pipeline**: \`${pipelineName}\` (${result.roundsExecuted} improvement round(s))`,
|
|
47
|
+
`- **Isolated sub-sessions**: ${result.childSessionIDs.length}`,
|
|
48
|
+
"",
|
|
49
|
+
result.report,
|
|
50
|
+
"",
|
|
51
|
+
"---",
|
|
52
|
+
"## Orchestrator Spot-Check",
|
|
53
|
+
result.verificationNote,
|
|
54
|
+
].join("\n");
|
|
55
|
+
}
|
|
56
|
+
function formatTeamworkOutput(result) {
|
|
57
|
+
const trackLabel = result.mode === "swe"
|
|
58
|
+
? "SWE Light"
|
|
59
|
+
: result.mode === "review"
|
|
60
|
+
? "Review Track"
|
|
61
|
+
: result.mode === "discover"
|
|
62
|
+
? "Duo Discovery"
|
|
63
|
+
: result.mode === "audit"
|
|
64
|
+
? "Forensic & Victory Audit"
|
|
65
|
+
: "Colosseum";
|
|
66
|
+
return [
|
|
67
|
+
`# Teamwork (${trackLabel}) — ${result.gateVerdict}`,
|
|
68
|
+
"",
|
|
69
|
+
`- **Track**: \`${trackLabel}\`${result.mode === "swe" ? ` (${result.qaRoundsExecuted} QA round(s))` : ""}`,
|
|
70
|
+
`- **Isolated sub-sessions**: ${result.childSessionIDs.length}`,
|
|
71
|
+
"",
|
|
72
|
+
result.report,
|
|
73
|
+
"",
|
|
74
|
+
"---",
|
|
75
|
+
"## Gate & Review Summary",
|
|
76
|
+
result.gateSummary,
|
|
77
|
+
].join("\n");
|
|
78
|
+
}
|
|
79
|
+
function formatSwarmOutput(result) {
|
|
80
|
+
const modeLabel = result.mode === "pipeline" ? "Pipeline Conductor" : "Swarm Orchestrator";
|
|
81
|
+
return [
|
|
82
|
+
`# Swarm (${modeLabel})`,
|
|
83
|
+
"",
|
|
84
|
+
`- **Workers**: ${result.succeededWorkers}/${result.workerCount} succeeded${result.failedWorkers > 0 ? ` (${result.failedWorkers} failed)` : ""}`,
|
|
85
|
+
`- **Isolated sub-sessions**: ${result.childSessionIDs.length}`,
|
|
86
|
+
"",
|
|
87
|
+
result.report,
|
|
88
|
+
"",
|
|
89
|
+
"---",
|
|
90
|
+
result.blackboard,
|
|
91
|
+
].join("\n");
|
|
92
|
+
}
|
|
93
|
+
export default Plugin.define({
|
|
94
|
+
id: "opencode.orchestra",
|
|
95
|
+
async setup(ctx) {
|
|
96
|
+
const pluginCfg = readPluginConfig(ctx.options);
|
|
97
|
+
const registrations = [];
|
|
98
|
+
const formatModelSpec = (ref) => ref ? `${ref.providerID}/${ref.id}` : undefined;
|
|
99
|
+
const cmdReg = await ctx.command.transform((editor) => {
|
|
100
|
+
editor.add({
|
|
101
|
+
name: "boost",
|
|
102
|
+
description: "Run multi-agent deep reasoning (Layer 0 + adversarial improvement + orchestrator verification) using the active model.",
|
|
103
|
+
execute: async ({ sessionID, prompt, delivery }) => {
|
|
104
|
+
const parsed = parseBoostArgs(prompt.text ?? "");
|
|
105
|
+
const baseArgs = {
|
|
106
|
+
...(parsed.task ? { task: parsed.task } : {}),
|
|
107
|
+
mode: parsed.mode === "auto" ? pluginCfg.defaultMode : parsed.mode,
|
|
108
|
+
rounds: parsed.rounds ?? pluginCfg.improvementRounds,
|
|
109
|
+
...(formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride)
|
|
110
|
+
? {
|
|
111
|
+
model: formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride),
|
|
112
|
+
}
|
|
113
|
+
: {}),
|
|
114
|
+
};
|
|
115
|
+
if (parsed.task) {
|
|
116
|
+
registerCoordinatorSession(sessionID, "boost");
|
|
117
|
+
}
|
|
118
|
+
await ctx.session.prompt({
|
|
119
|
+
...prompt,
|
|
120
|
+
sessionID,
|
|
121
|
+
text: parsed.task
|
|
122
|
+
? [
|
|
123
|
+
"You are the **Boost Orchestrator**.",
|
|
124
|
+
"Immediately invoke the `boost` tool (do not solve the task manually first) using the base arguments below:",
|
|
125
|
+
"```json",
|
|
126
|
+
JSON.stringify(baseArgs, null, 2),
|
|
127
|
+
"```",
|
|
128
|
+
"",
|
|
129
|
+
"### Rules for `task` and `additionalContext`",
|
|
130
|
+
"- Keep `task` **verbatim** as provided above (do not rephrase or inject your own solution).",
|
|
131
|
+
"- **First turn**: omit `additionalContext`.",
|
|
132
|
+
"- **Follow-up turn**: include `additionalContext` summarizing only the relevant facts, decisions, file paths, or constraints from earlier turns that the worker needs to understand `task` (do not include your own proposed solution).",
|
|
133
|
+
"- Present the verified result clearly to the user after the tool completes.",
|
|
134
|
+
].join("\n")
|
|
135
|
+
: [
|
|
136
|
+
"You are the **Boost Orchestrator**.",
|
|
137
|
+
"The user invoked `/boost` without an inline task.",
|
|
138
|
+
"- If earlier turns in this conversation contain a clear pending task or request, immediately invoke the `boost` tool with `task` capturing that request verbatim, `additionalContext` summarizing the relevant prior-turn context, and the base options below.",
|
|
139
|
+
"- Otherwise, briefly show the usage: `/boost [--coder | --investigate] [--rounds=N] [--model=provider/model] <task>`.",
|
|
140
|
+
"```json",
|
|
141
|
+
JSON.stringify(baseArgs, null, 2),
|
|
142
|
+
"```",
|
|
143
|
+
].join("\n"),
|
|
144
|
+
delivery,
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
editor.add({
|
|
149
|
+
name: "teamwork",
|
|
150
|
+
description: "Run role-based Teamwork multi-agent orchestration (SWE Light, Review Track, Audit Track, Duo Discovery, or Colosseum + Verifier + Judge).",
|
|
151
|
+
execute: async ({ sessionID, prompt, delivery }) => {
|
|
152
|
+
const parsed = parseTeamworkArgs(prompt.text ?? "");
|
|
153
|
+
const baseArgs = {
|
|
154
|
+
...(parsed.task ? { task: parsed.task } : {}),
|
|
155
|
+
mode: parsed.mode === "auto"
|
|
156
|
+
? pluginCfg.teamworkDefaultMode
|
|
157
|
+
: parsed.mode,
|
|
158
|
+
qaRounds: parsed.qaRounds ?? pluginCfg.teamworkQaRounds,
|
|
159
|
+
workers: parsed.workers ?? pluginCfg.teamworkWorkers,
|
|
160
|
+
...(formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride)
|
|
161
|
+
? {
|
|
162
|
+
model: formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride),
|
|
163
|
+
}
|
|
164
|
+
: {}),
|
|
165
|
+
};
|
|
166
|
+
if (!parsed.task) {
|
|
167
|
+
await ctx.session.prompt({
|
|
168
|
+
...prompt,
|
|
169
|
+
sessionID,
|
|
170
|
+
text: [
|
|
171
|
+
"You are the **Teamwork Orchestrator**.",
|
|
172
|
+
"The user invoked `/teamwork` without an inline task.",
|
|
173
|
+
"- If earlier turns in this conversation contain a clear pending task, invoke the `teamwork` tool with `task` verbatim, `additionalContext` summarizing relevant prior-turn context, and the base options below.",
|
|
174
|
+
"- Otherwise, briefly show the usage: `/teamwork [--swe | --review | --audit | --discover | --colosseum] [--qa-rounds=N] [--workers=N] [--no-interview] [--model=provider/model] <task>`.",
|
|
175
|
+
"```json",
|
|
176
|
+
JSON.stringify(baseArgs, null, 2),
|
|
177
|
+
"```",
|
|
178
|
+
].join("\n"),
|
|
179
|
+
delivery,
|
|
180
|
+
});
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
registerCoordinatorSession(sessionID, "teamwork");
|
|
184
|
+
await ctx.session.prompt({
|
|
185
|
+
...prompt,
|
|
186
|
+
sessionID,
|
|
187
|
+
text: parsed.skipInterview
|
|
188
|
+
? [
|
|
189
|
+
"You are the **Teamwork Orchestrator**.",
|
|
190
|
+
"Immediately invoke the `teamwork` tool (do not solve the task manually first) using the base arguments below:",
|
|
191
|
+
"```json",
|
|
192
|
+
JSON.stringify(baseArgs, null, 2),
|
|
193
|
+
"```",
|
|
194
|
+
"Keep `task` verbatim. On follow-up turns, include `additionalContext` summarizing relevant prior-turn context (without injecting your own solution). Then present the verified result clearly to the user.",
|
|
195
|
+
].join("\n")
|
|
196
|
+
: [
|
|
197
|
+
"You are the **Teamwork Orchestrator**.",
|
|
198
|
+
"Before dispatching workers, conduct a brief upfront **scoping interview** (2–4 concise multiple-choice/clarifying questions about scope, constraints, and acceptance criteria) using the `question` tool (unless the task is already 100% unambiguous).",
|
|
199
|
+
"Once the user answers, immediately invoke the `teamwork` tool with the base arguments below plus `scopingContext` (their answers) and, on follow-up turns, `additionalContext` summarizing relevant prior-turn context. Keep `task` verbatim:",
|
|
200
|
+
"```json",
|
|
201
|
+
JSON.stringify(baseArgs, null, 2),
|
|
202
|
+
"```",
|
|
203
|
+
].join("\n"),
|
|
204
|
+
delivery,
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
editor.add({
|
|
209
|
+
name: "swarm",
|
|
210
|
+
description: "Run parallel Swarm multi-agent orchestration (Swarm Orchestrator fan-out or Pipeline Conductor multi-stage + Blackboard + Synthesizer).",
|
|
211
|
+
execute: async ({ sessionID, prompt, delivery }) => {
|
|
212
|
+
const parsed = parseSwarmArgs(prompt.text ?? "");
|
|
213
|
+
const baseArgs = {
|
|
214
|
+
...(parsed.task ? { task: parsed.task } : {}),
|
|
215
|
+
mode: parsed.mode === "auto"
|
|
216
|
+
? pluginCfg.swarmDefaultMode
|
|
217
|
+
: parsed.mode,
|
|
218
|
+
workers: parsed.workers ?? pluginCfg.swarmWorkers,
|
|
219
|
+
...(parsed.useWorktree ? { useWorktree: true } : {}),
|
|
220
|
+
...(formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride)
|
|
221
|
+
? {
|
|
222
|
+
model: formatModelSpec(parsed.modelOverride ?? pluginCfg.modelOverride),
|
|
223
|
+
}
|
|
224
|
+
: {}),
|
|
225
|
+
};
|
|
226
|
+
if (parsed.task) {
|
|
227
|
+
registerCoordinatorSession(sessionID, "swarm");
|
|
228
|
+
}
|
|
229
|
+
await ctx.session.prompt({
|
|
230
|
+
...prompt,
|
|
231
|
+
sessionID,
|
|
232
|
+
text: parsed.task
|
|
233
|
+
? [
|
|
234
|
+
"You are the **Swarm Orchestrator**.",
|
|
235
|
+
"Immediately invoke the `swarm` tool (do not solve the task manually first) using the base arguments below:",
|
|
236
|
+
"```json",
|
|
237
|
+
JSON.stringify(baseArgs, null, 2),
|
|
238
|
+
"```",
|
|
239
|
+
"Keep `task` verbatim. On follow-up turns, include `additionalContext` summarizing relevant prior-turn context (without injecting your own solution). Then present the verified result clearly to the user.",
|
|
240
|
+
].join("\n")
|
|
241
|
+
: [
|
|
242
|
+
"You are the **Swarm Orchestrator**.",
|
|
243
|
+
"The user invoked `/swarm` without an inline task.",
|
|
244
|
+
"- If earlier turns in this conversation contain a clear pending task, invoke the `swarm` tool with `task` verbatim, `additionalContext` summarizing relevant prior-turn context, and the base options below.",
|
|
245
|
+
"- Otherwise, briefly show the usage: `/swarm [--fanout | --pipeline] [--workers=N] [--worktree] [--model=provider/model] <task>`.",
|
|
246
|
+
"```json",
|
|
247
|
+
JSON.stringify(baseArgs, null, 2),
|
|
248
|
+
"```",
|
|
249
|
+
].join("\n"),
|
|
250
|
+
delivery,
|
|
251
|
+
});
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
if (cmdReg)
|
|
256
|
+
registrations.push(cmdReg);
|
|
257
|
+
const toolReg = await ctx.tool.transform((editor) => {
|
|
258
|
+
editor.add({
|
|
259
|
+
name: "boost",
|
|
260
|
+
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.",
|
|
261
|
+
input: {
|
|
262
|
+
type: "object",
|
|
263
|
+
properties: {
|
|
264
|
+
task: {
|
|
265
|
+
type: "string",
|
|
266
|
+
description: "The complex coding, debugging, refactoring, or investigation task (verbatim).",
|
|
267
|
+
},
|
|
268
|
+
additionalContext: {
|
|
269
|
+
type: "string",
|
|
270
|
+
description: "Optional relevant context from earlier turns or prior progress (omit on first turn; do not inject your own solution).",
|
|
271
|
+
},
|
|
272
|
+
continueSessionID: {
|
|
273
|
+
type: "string",
|
|
274
|
+
description: "Optional existing worker session ID to continue instead of spawning a fresh Layer 0 session.",
|
|
275
|
+
},
|
|
276
|
+
mode: {
|
|
277
|
+
type: "string",
|
|
278
|
+
enum: ["auto", "coder", "investigate"],
|
|
279
|
+
description: "Pipeline mode: auto (default), coder, or investigate.",
|
|
280
|
+
},
|
|
281
|
+
rounds: {
|
|
282
|
+
type: "integer",
|
|
283
|
+
minimum: 0,
|
|
284
|
+
maximum: 5,
|
|
285
|
+
description: "Number of adversarial improvement rounds after Layer 0 (default 1).",
|
|
286
|
+
},
|
|
287
|
+
model: {
|
|
288
|
+
type: "string",
|
|
289
|
+
description: "Optional providerID/modelID override; omit to inherit the active session model.",
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
required: ["task"],
|
|
293
|
+
additionalProperties: false,
|
|
294
|
+
},
|
|
295
|
+
execute: async (rawInput, context) => {
|
|
296
|
+
const input = rawInput;
|
|
297
|
+
try {
|
|
298
|
+
const result = await runBoostPipeline(ctx.session, {
|
|
299
|
+
sessionID: context.sessionID,
|
|
300
|
+
task: input.task,
|
|
301
|
+
additionalContext: input.additionalContext,
|
|
302
|
+
continueSessionID: input.continueSessionID,
|
|
303
|
+
mode: input.mode ?? pluginCfg.defaultMode,
|
|
304
|
+
improvementRounds: input.rounds ?? pluginCfg.improvementRounds,
|
|
305
|
+
maxExtraVerificationRounds: pluginCfg.maxExtraVerificationRounds,
|
|
306
|
+
modelOverride: parseModelRef(input.model) ?? pluginCfg.modelOverride,
|
|
307
|
+
signal: context.signal,
|
|
308
|
+
onProgress: async (status) => {
|
|
309
|
+
await context.progress({ status });
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
content: formatBoostOutput(result),
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
finally {
|
|
317
|
+
unregisterCoordinatorSession(context.sessionID);
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
editor.add({
|
|
322
|
+
name: "teamwork",
|
|
323
|
+
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).",
|
|
324
|
+
input: {
|
|
325
|
+
type: "object",
|
|
326
|
+
properties: {
|
|
327
|
+
task: {
|
|
328
|
+
type: "string",
|
|
329
|
+
description: "The engineering, review, audit, discovery, or architecture comparison task (verbatim).",
|
|
330
|
+
},
|
|
331
|
+
additionalContext: {
|
|
332
|
+
type: "string",
|
|
333
|
+
description: "Optional relevant context from earlier conversation turns.",
|
|
334
|
+
},
|
|
335
|
+
mode: {
|
|
336
|
+
type: "string",
|
|
337
|
+
enum: ["auto", "swe", "review", "audit", "discover", "colosseum"],
|
|
338
|
+
description: "Teamwork track: auto (default), swe, review, audit, discover, or colosseum.",
|
|
339
|
+
},
|
|
340
|
+
qaRounds: {
|
|
341
|
+
type: "integer",
|
|
342
|
+
minimum: 0,
|
|
343
|
+
maximum: 3,
|
|
344
|
+
description: "Maximum QA fix rounds if SWE gate fails (default 1).",
|
|
345
|
+
},
|
|
346
|
+
workers: {
|
|
347
|
+
type: "integer",
|
|
348
|
+
minimum: 2,
|
|
349
|
+
maximum: 5,
|
|
350
|
+
description: "Number of competing contenders in colosseum mode (default 2).",
|
|
351
|
+
},
|
|
352
|
+
scopingContext: {
|
|
353
|
+
type: "string",
|
|
354
|
+
description: "Optional scoping interview answers, constraints, and acceptance criteria.",
|
|
355
|
+
},
|
|
356
|
+
model: {
|
|
357
|
+
type: "string",
|
|
358
|
+
description: "Optional providerID/modelID override; omit to inherit the active session model.",
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
required: ["task"],
|
|
362
|
+
additionalProperties: false,
|
|
363
|
+
},
|
|
364
|
+
execute: async (rawInput, context) => {
|
|
365
|
+
const input = rawInput;
|
|
366
|
+
try {
|
|
367
|
+
const result = await runTeamworkPipeline(ctx.session, {
|
|
368
|
+
sessionID: context.sessionID,
|
|
369
|
+
task: input.task,
|
|
370
|
+
additionalContext: input.additionalContext,
|
|
371
|
+
mode: input.mode ?? pluginCfg.teamworkDefaultMode,
|
|
372
|
+
maxQaRounds: input.qaRounds ?? pluginCfg.teamworkQaRounds,
|
|
373
|
+
workers: input.workers ?? pluginCfg.teamworkWorkers,
|
|
374
|
+
scopingContext: input.scopingContext,
|
|
375
|
+
storage: ctx.storage,
|
|
376
|
+
modelOverride: parseModelRef(input.model) ?? pluginCfg.modelOverride,
|
|
377
|
+
signal: context.signal,
|
|
378
|
+
onProgress: async (status) => {
|
|
379
|
+
await context.progress({ status });
|
|
380
|
+
},
|
|
381
|
+
});
|
|
382
|
+
return {
|
|
383
|
+
content: formatTeamworkOutput(result),
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
finally {
|
|
387
|
+
unregisterCoordinatorSession(context.sessionID);
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
});
|
|
391
|
+
editor.add({
|
|
392
|
+
name: "swarm",
|
|
393
|
+
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.",
|
|
394
|
+
input: {
|
|
395
|
+
type: "object",
|
|
396
|
+
properties: {
|
|
397
|
+
task: {
|
|
398
|
+
type: "string",
|
|
399
|
+
description: "The task to partition and execute across parallel Swarm Workers (verbatim).",
|
|
400
|
+
},
|
|
401
|
+
additionalContext: {
|
|
402
|
+
type: "string",
|
|
403
|
+
description: "Optional relevant context from earlier conversation turns.",
|
|
404
|
+
},
|
|
405
|
+
mode: {
|
|
406
|
+
type: "string",
|
|
407
|
+
enum: ["auto", "fanout", "pipeline"],
|
|
408
|
+
description: "Swarm mode: auto (default), fanout (single-stage), or pipeline (multi-stage with critique).",
|
|
409
|
+
},
|
|
410
|
+
workers: {
|
|
411
|
+
type: "integer",
|
|
412
|
+
minimum: 2,
|
|
413
|
+
maximum: 6,
|
|
414
|
+
description: "Number of parallel Swarm Workers (default 3).",
|
|
415
|
+
},
|
|
416
|
+
useWorktree: {
|
|
417
|
+
type: "boolean",
|
|
418
|
+
description: "Run each Swarm Worker in its own isolated git worktree (default false).",
|
|
419
|
+
},
|
|
420
|
+
model: {
|
|
421
|
+
type: "string",
|
|
422
|
+
description: "Optional providerID/modelID override; omit to inherit the active session model.",
|
|
423
|
+
},
|
|
424
|
+
},
|
|
425
|
+
required: ["task"],
|
|
426
|
+
additionalProperties: false,
|
|
427
|
+
},
|
|
428
|
+
execute: async (rawInput, context) => {
|
|
429
|
+
const input = rawInput;
|
|
430
|
+
try {
|
|
431
|
+
const result = await runSwarmPipeline(ctx.session, {
|
|
432
|
+
sessionID: context.sessionID,
|
|
433
|
+
task: input.task,
|
|
434
|
+
additionalContext: input.additionalContext,
|
|
435
|
+
mode: input.mode ?? pluginCfg.swarmDefaultMode,
|
|
436
|
+
workers: input.workers ?? pluginCfg.swarmWorkers,
|
|
437
|
+
useWorktree: input.useWorktree ?? false,
|
|
438
|
+
storage: ctx.storage,
|
|
439
|
+
worktree: ctx.worktree,
|
|
440
|
+
modelOverride: parseModelRef(input.model) ?? pluginCfg.modelOverride,
|
|
441
|
+
signal: context.signal,
|
|
442
|
+
onProgress: async (status) => {
|
|
443
|
+
await context.progress({ status });
|
|
444
|
+
},
|
|
445
|
+
});
|
|
446
|
+
return {
|
|
447
|
+
content: formatSwarmOutput(result),
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
finally {
|
|
451
|
+
unregisterCoordinatorSession(context.sessionID);
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
});
|
|
455
|
+
editor.add({
|
|
456
|
+
name: "swarm_board_post",
|
|
457
|
+
description: "Post a message or finding to the shared Swarm message board for peer workers and the Synthesizer.",
|
|
458
|
+
input: {
|
|
459
|
+
type: "object",
|
|
460
|
+
properties: {
|
|
461
|
+
boardId: {
|
|
462
|
+
type: "string",
|
|
463
|
+
description: "The Swarm board identifier provided in your prompt.",
|
|
464
|
+
},
|
|
465
|
+
author: {
|
|
466
|
+
type: "string",
|
|
467
|
+
description: "Your worker ID (e.g. worker-1).",
|
|
468
|
+
},
|
|
469
|
+
to: {
|
|
470
|
+
type: "string",
|
|
471
|
+
description: "Optional recipient (e.g. all, worker-2, coordinator).",
|
|
472
|
+
},
|
|
473
|
+
channel: {
|
|
474
|
+
type: "string",
|
|
475
|
+
description: "Optional channel name (default 'general', e.g. 'findings', 'blockers', 'handoffs').",
|
|
476
|
+
},
|
|
477
|
+
message: {
|
|
478
|
+
type: "string",
|
|
479
|
+
description: "Concise status, finding, or blocker to share. Supports @worker-N mentions.",
|
|
480
|
+
},
|
|
481
|
+
},
|
|
482
|
+
required: ["boardId", "author", "message"],
|
|
483
|
+
additionalProperties: false,
|
|
484
|
+
},
|
|
485
|
+
execute: async (rawInput) => {
|
|
486
|
+
const input = rawInput;
|
|
487
|
+
const post = await postToBoard(ctx.storage, input.boardId, {
|
|
488
|
+
author: input.author,
|
|
489
|
+
to: input.to,
|
|
490
|
+
channel: input.channel,
|
|
491
|
+
message: input.message,
|
|
492
|
+
});
|
|
493
|
+
advanceSwarmWorkerOnOwnPost(input.boardId, input.author, post.seq);
|
|
494
|
+
return {
|
|
495
|
+
content: `Posted #${post.seq} to board ${input.boardId}${post.channel ? ` (#${post.channel})` : ""}.`,
|
|
496
|
+
};
|
|
497
|
+
},
|
|
498
|
+
});
|
|
499
|
+
editor.add({
|
|
500
|
+
name: "swarm_board_read",
|
|
501
|
+
description: "Read messages from the shared Swarm message board.",
|
|
502
|
+
input: {
|
|
503
|
+
type: "object",
|
|
504
|
+
properties: {
|
|
505
|
+
boardId: {
|
|
506
|
+
type: "string",
|
|
507
|
+
description: "The Swarm board identifier provided in your prompt.",
|
|
508
|
+
},
|
|
509
|
+
workerId: {
|
|
510
|
+
type: "string",
|
|
511
|
+
description: "Optional worker ID (e.g. worker-1) to advance your read cursor.",
|
|
512
|
+
},
|
|
513
|
+
channel: {
|
|
514
|
+
type: "string",
|
|
515
|
+
description: "Optional channel filter (e.g. 'general', 'findings', 'blockers').",
|
|
516
|
+
},
|
|
517
|
+
afterSeq: {
|
|
518
|
+
type: "integer",
|
|
519
|
+
minimum: 0,
|
|
520
|
+
description: "Optional sequence cursor; only return posts with seq > afterSeq.",
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
required: ["boardId"],
|
|
524
|
+
additionalProperties: false,
|
|
525
|
+
},
|
|
526
|
+
execute: async (rawInput, context) => {
|
|
527
|
+
const input = rawInput;
|
|
528
|
+
const posts = await readBoard(ctx.storage, input.boardId, input.afterSeq ?? 0, input.channel);
|
|
529
|
+
if (posts.length > 0 && !input.channel) {
|
|
530
|
+
const latestSeq = Math.max(...posts.map((p) => p.seq));
|
|
531
|
+
const effectiveWorkerId = input.workerId ??
|
|
532
|
+
(getSwarmWorkerSession(context.sessionID)?.boardId === input.boardId
|
|
533
|
+
? getSwarmWorkerSession(context.sessionID)?.workerId
|
|
534
|
+
: undefined);
|
|
535
|
+
if (effectiveWorkerId) {
|
|
536
|
+
markSwarmWorkerRead(input.boardId, effectiveWorkerId, latestSeq);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
if (posts.length === 0) {
|
|
540
|
+
return { content: "(no new posts on board)" };
|
|
541
|
+
}
|
|
542
|
+
return {
|
|
543
|
+
content: posts
|
|
544
|
+
.map((p) => `#${p.seq}${p.channel && p.channel !== "general" ? ` [#${p.channel}]` : ""} [@${p.author}${p.to ? ` -> @${p.to}` : ""}]: ${p.message}`)
|
|
545
|
+
.join("\n"),
|
|
546
|
+
};
|
|
547
|
+
},
|
|
548
|
+
});
|
|
549
|
+
editor.add({
|
|
550
|
+
name: "swarm_board_head",
|
|
551
|
+
description: "Lightweight check of the Swarm message board head (latest sequence number, post count, and active authors).",
|
|
552
|
+
input: {
|
|
553
|
+
type: "object",
|
|
554
|
+
properties: {
|
|
555
|
+
boardId: {
|
|
556
|
+
type: "string",
|
|
557
|
+
description: "The Swarm board identifier provided in your prompt.",
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
required: ["boardId"],
|
|
561
|
+
additionalProperties: false,
|
|
562
|
+
},
|
|
563
|
+
execute: async (rawInput) => {
|
|
564
|
+
const input = rawInput;
|
|
565
|
+
const head = await getBoardHead(ctx.storage, input.boardId);
|
|
566
|
+
return {
|
|
567
|
+
content: JSON.stringify(head),
|
|
568
|
+
};
|
|
569
|
+
},
|
|
570
|
+
});
|
|
571
|
+
editor.add({
|
|
572
|
+
name: "swarm_wait_check",
|
|
573
|
+
description: "Check for unread peer messages addressed to your workerId or 'all' before finishing or parking.",
|
|
574
|
+
input: {
|
|
575
|
+
type: "object",
|
|
576
|
+
properties: {
|
|
577
|
+
boardId: {
|
|
578
|
+
type: "string",
|
|
579
|
+
description: "The Swarm board identifier provided in your prompt.",
|
|
580
|
+
},
|
|
581
|
+
workerId: {
|
|
582
|
+
type: "string",
|
|
583
|
+
description: "Your worker ID (e.g. worker-1).",
|
|
584
|
+
},
|
|
585
|
+
afterSeq: {
|
|
586
|
+
type: "integer",
|
|
587
|
+
minimum: 0,
|
|
588
|
+
description: "Last sequence number you have already read (default 0).",
|
|
589
|
+
},
|
|
590
|
+
},
|
|
591
|
+
required: ["boardId", "workerId"],
|
|
592
|
+
additionalProperties: false,
|
|
593
|
+
},
|
|
594
|
+
execute: async (rawInput) => {
|
|
595
|
+
const input = rawInput;
|
|
596
|
+
const status = await checkPeerWait(ctx.storage, input.boardId, input.workerId, input.afterSeq ?? 0);
|
|
597
|
+
markSwarmWorkerRead(input.boardId, input.workerId, status.latestSeq);
|
|
598
|
+
if (!status.hasUnreadPeerActivity) {
|
|
599
|
+
return {
|
|
600
|
+
content: `No unread peer messages for ${input.workerId} (latestSeq=${status.latestSeq}). Safe to finalize.`,
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
const formatted = status.unreadForWorker
|
|
604
|
+
.map((p) => `#${p.seq} [@${p.author}${p.to ? ` -> @${p.to}` : ""}]: ${p.message}`)
|
|
605
|
+
.join("\n");
|
|
606
|
+
return {
|
|
607
|
+
content: `Unread peer messages for ${input.workerId} (latestSeq=${status.latestSeq}):\n${formatted}`,
|
|
608
|
+
};
|
|
609
|
+
},
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
if (toolReg)
|
|
613
|
+
registrations.push(toolReg);
|
|
614
|
+
if (typeof ctx.session.hook === "function") {
|
|
615
|
+
const ctxHookReg = await ctx.session.hook("context", async (event) => {
|
|
616
|
+
await applyContextHook(event, ctx.storage);
|
|
617
|
+
});
|
|
618
|
+
if (ctxHookReg)
|
|
619
|
+
registrations.push(ctxHookReg);
|
|
620
|
+
const idleHookReg = await ctx.session.hook("experimental.idle", async (event) => {
|
|
621
|
+
clearCoordinatorOnIdle(event.sessionID);
|
|
622
|
+
await applyIdleParkGuardHook(event, ctx.storage, ctx.session);
|
|
623
|
+
});
|
|
624
|
+
if (idleHookReg)
|
|
625
|
+
registrations.push(idleHookReg);
|
|
626
|
+
}
|
|
627
|
+
await ctx.command.reload();
|
|
628
|
+
await ctx.tool.reload();
|
|
629
|
+
return async () => {
|
|
630
|
+
await Promise.allSettled(registrations.map((reg) => reg.dispose()));
|
|
631
|
+
resetSessionRegistry();
|
|
632
|
+
};
|
|
633
|
+
},
|
|
634
|
+
});
|