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/parser.js
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
export function parseModelRef(spec) {
|
|
2
|
+
if (!spec)
|
|
3
|
+
return undefined;
|
|
4
|
+
const trimmed = spec.trim();
|
|
5
|
+
const slash = trimmed.indexOf("/");
|
|
6
|
+
if (slash <= 0 || slash === trimmed.length - 1)
|
|
7
|
+
return undefined;
|
|
8
|
+
return {
|
|
9
|
+
providerID: trimmed.slice(0, slash),
|
|
10
|
+
id: trimmed.slice(slash + 1),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function parseStrictInt(raw) {
|
|
14
|
+
if (!/^\d+$/.test(raw))
|
|
15
|
+
return undefined;
|
|
16
|
+
const n = Number.parseInt(raw, 10);
|
|
17
|
+
return Number.isSafeInteger(n) ? n : undefined;
|
|
18
|
+
}
|
|
19
|
+
function consumeLeadingFlags(raw, onFlag) {
|
|
20
|
+
const len = raw.length;
|
|
21
|
+
const skipWs = (i) => {
|
|
22
|
+
let idx = i;
|
|
23
|
+
while (idx < len && /\s/.test(raw[idx]))
|
|
24
|
+
idx++;
|
|
25
|
+
return idx;
|
|
26
|
+
};
|
|
27
|
+
const readToken = (i) => {
|
|
28
|
+
const start = skipWs(i);
|
|
29
|
+
if (start >= len)
|
|
30
|
+
return undefined;
|
|
31
|
+
let end = start;
|
|
32
|
+
while (end < len && !/\s/.test(raw[end]))
|
|
33
|
+
end++;
|
|
34
|
+
return { token: raw.slice(start, end), start, end };
|
|
35
|
+
};
|
|
36
|
+
let pos = 0;
|
|
37
|
+
while (pos < len) {
|
|
38
|
+
const cur = readToken(pos);
|
|
39
|
+
if (!cur)
|
|
40
|
+
return "";
|
|
41
|
+
if (cur.token === "--") {
|
|
42
|
+
pos = cur.end;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
let nextPos = cur.end;
|
|
46
|
+
const peekNext = () => readToken(nextPos)?.token;
|
|
47
|
+
const consumeNext = () => {
|
|
48
|
+
const next = readToken(nextPos);
|
|
49
|
+
nextPos = next.end;
|
|
50
|
+
return next.token;
|
|
51
|
+
};
|
|
52
|
+
if (onFlag(cur.token, peekNext, consumeNext)) {
|
|
53
|
+
pos = nextPos;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
pos = cur.start;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
return raw.slice(pos).trim();
|
|
60
|
+
}
|
|
61
|
+
export function parseBoostArgs(raw) {
|
|
62
|
+
let mode = "auto";
|
|
63
|
+
let rounds;
|
|
64
|
+
let modelOverride;
|
|
65
|
+
const task = consumeLeadingFlags(raw, (tok, peekNext, consumeNext) => {
|
|
66
|
+
if (tok === "--investigate" || tok === "-i") {
|
|
67
|
+
mode = "investigate";
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
if (tok === "--coder" || tok === "-c") {
|
|
71
|
+
mode = "coder";
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if (tok.startsWith("--rounds=")) {
|
|
75
|
+
const n = parseStrictInt(tok.slice("--rounds=".length));
|
|
76
|
+
if (n !== undefined && n >= 0 && n <= 5)
|
|
77
|
+
rounds = n;
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
if ((tok === "--rounds" || tok === "-r") && peekNext() !== undefined) {
|
|
81
|
+
const n = parseStrictInt(consumeNext());
|
|
82
|
+
if (n !== undefined && n >= 0 && n <= 5)
|
|
83
|
+
rounds = n;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (tok.startsWith("--model=")) {
|
|
87
|
+
const parsed = parseModelRef(tok.slice("--model=".length));
|
|
88
|
+
if (parsed)
|
|
89
|
+
modelOverride = parsed;
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if ((tok === "--model" || tok === "-m") && peekNext() !== undefined) {
|
|
93
|
+
const parsed = parseModelRef(consumeNext());
|
|
94
|
+
if (parsed)
|
|
95
|
+
modelOverride = parsed;
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
mode,
|
|
102
|
+
rounds,
|
|
103
|
+
modelOverride,
|
|
104
|
+
task,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export function extractAssistantText(messages) {
|
|
108
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
109
|
+
const msg = messages[i];
|
|
110
|
+
if (msg.type !== "assistant")
|
|
111
|
+
continue;
|
|
112
|
+
const textParts = (msg.content ?? [])
|
|
113
|
+
.filter((p) => p.type === "text" && typeof p.text === "string")
|
|
114
|
+
.map((p) => p.text.trim())
|
|
115
|
+
.filter(Boolean);
|
|
116
|
+
let errorText;
|
|
117
|
+
if (msg.error) {
|
|
118
|
+
if (typeof msg.error === "object" && msg.error !== null && "message" in msg.error) {
|
|
119
|
+
errorText = String(msg.error.message ?? "Unknown assistant error");
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
errorText = String(msg.error);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (textParts.length === 0 && !errorText) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
text: textParts.join("\n\n"),
|
|
130
|
+
...(errorText ? { error: errorText } : {}),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return { text: "" };
|
|
134
|
+
}
|
|
135
|
+
const INVESTIGATE_KEYWORDS = /\b(investigate|trace|explain|why|how does|root cause|find out|without modifying|read-only|analyze|audit|diagnose|cari tahu|jelaskan|kenapa|mengapa|analisis|telusuri)\b/i;
|
|
136
|
+
const CODER_KEYWORDS = /\b(implement|fix|refactor|optimize|add|create|write|build|update|migrate|patch|remove|delete|buat|perbaiki|ubah|tambah|optimasi)\b/i;
|
|
137
|
+
export function heuristicClassifyTask(task) {
|
|
138
|
+
const hasInvestigate = INVESTIGATE_KEYWORDS.test(task);
|
|
139
|
+
const hasCoder = CODER_KEYWORDS.test(task);
|
|
140
|
+
if (hasInvestigate && !hasCoder)
|
|
141
|
+
return "investigate";
|
|
142
|
+
return "coder";
|
|
143
|
+
}
|
|
144
|
+
export function parseClassifierDecision(output, fallbackTask) {
|
|
145
|
+
const normalized = output.trim().toLowerCase();
|
|
146
|
+
if (normalized.includes("investigate") || normalized.includes("deepinvestigator")) {
|
|
147
|
+
return "investigate";
|
|
148
|
+
}
|
|
149
|
+
if (normalized.includes("coder") || normalized.includes("deepcoder")) {
|
|
150
|
+
return "coder";
|
|
151
|
+
}
|
|
152
|
+
return heuristicClassifyTask(fallbackTask);
|
|
153
|
+
}
|
|
154
|
+
export function parseVerificationDecision(output) {
|
|
155
|
+
const trimmed = output.trim();
|
|
156
|
+
const firstLine = trimmed.split(/\r?\n/, 1)[0] ?? "";
|
|
157
|
+
const firstLineClean = firstLine.replace(/[*`_]/g, "").trim();
|
|
158
|
+
const cleaned = trimmed.replace(/[*`_]/g, "");
|
|
159
|
+
if (/\bVERDICT:\s*FAIL\b/i.test(firstLineClean)) {
|
|
160
|
+
return { passed: false, reason: trimmed };
|
|
161
|
+
}
|
|
162
|
+
if (/\bVERDICT:\s*PASS\b/i.test(firstLineClean)) {
|
|
163
|
+
return { passed: true, reason: trimmed };
|
|
164
|
+
}
|
|
165
|
+
if (/\bVERDICT:\s*FAIL\b/i.test(cleaned)) {
|
|
166
|
+
return { passed: false, reason: trimmed };
|
|
167
|
+
}
|
|
168
|
+
if (/\bVERDICT:\s*PASS\b/i.test(cleaned)) {
|
|
169
|
+
return { passed: true, reason: trimmed };
|
|
170
|
+
}
|
|
171
|
+
if (/\bFAIL\b/i.test(firstLineClean) && !/\bPASS\b/i.test(firstLineClean)) {
|
|
172
|
+
return { passed: false, reason: trimmed };
|
|
173
|
+
}
|
|
174
|
+
if (/\bPASS\b/i.test(firstLineClean) && !/\bFAIL\b/i.test(firstLineClean)) {
|
|
175
|
+
return { passed: true, reason: trimmed };
|
|
176
|
+
}
|
|
177
|
+
return { passed: false, reason: trimmed };
|
|
178
|
+
}
|
|
179
|
+
export function parseTeamworkArgs(raw) {
|
|
180
|
+
let mode = "auto";
|
|
181
|
+
let qaRounds;
|
|
182
|
+
let workers;
|
|
183
|
+
let skipInterview = false;
|
|
184
|
+
let modelOverride;
|
|
185
|
+
const rawTask = consumeLeadingFlags(raw, (tok, peekNext, consumeNext) => {
|
|
186
|
+
if (tok.toLowerCase() === "[skip-interview]") {
|
|
187
|
+
skipInterview = true;
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
if (tok === "--swe" || tok === "-s") {
|
|
191
|
+
mode = "swe";
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
if (tok === "--review" || tok === "-r") {
|
|
195
|
+
mode = "review";
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
if (tok === "--colosseum" || tok === "-c") {
|
|
199
|
+
mode = "colosseum";
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
if (tok === "--discover" || tok === "-d") {
|
|
203
|
+
mode = "discover";
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
if (tok === "--audit" || tok === "-a") {
|
|
207
|
+
mode = "audit";
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
if (tok.startsWith("--mode=")) {
|
|
211
|
+
const m = tok.slice("--mode=".length).toLowerCase();
|
|
212
|
+
if (m === "auto" ||
|
|
213
|
+
m === "swe" ||
|
|
214
|
+
m === "review" ||
|
|
215
|
+
m === "colosseum" ||
|
|
216
|
+
m === "discover" ||
|
|
217
|
+
m === "audit") {
|
|
218
|
+
mode = m;
|
|
219
|
+
}
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
if (tok.startsWith("--qa-rounds=")) {
|
|
223
|
+
const n = parseStrictInt(tok.slice("--qa-rounds=".length));
|
|
224
|
+
if (n !== undefined && n >= 0 && n <= 3)
|
|
225
|
+
qaRounds = n;
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
if (tok === "--qa-rounds" && peekNext() !== undefined) {
|
|
229
|
+
const n = parseStrictInt(consumeNext());
|
|
230
|
+
if (n !== undefined && n >= 0 && n <= 3)
|
|
231
|
+
qaRounds = n;
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
if (tok.startsWith("--workers=")) {
|
|
235
|
+
const n = parseStrictInt(tok.slice("--workers=".length));
|
|
236
|
+
if (n !== undefined && n >= 2 && n <= 5)
|
|
237
|
+
workers = n;
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
if ((tok === "--workers" || tok === "-w") && peekNext() !== undefined) {
|
|
241
|
+
const n = parseStrictInt(consumeNext());
|
|
242
|
+
if (n !== undefined && n >= 2 && n <= 5)
|
|
243
|
+
workers = n;
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
if (tok.startsWith("--model=")) {
|
|
247
|
+
const parsed = parseModelRef(tok.slice("--model=".length));
|
|
248
|
+
if (parsed)
|
|
249
|
+
modelOverride = parsed;
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
if (tok === "--no-interview" || tok === "--skip-interview") {
|
|
253
|
+
skipInterview = true;
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
if ((tok === "--model" || tok === "-m") && peekNext() !== undefined) {
|
|
257
|
+
const parsed = parseModelRef(consumeNext());
|
|
258
|
+
if (parsed)
|
|
259
|
+
modelOverride = parsed;
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
return false;
|
|
263
|
+
});
|
|
264
|
+
let task = rawTask;
|
|
265
|
+
const skipPrefixMatch = task.match(/^\[skip-interview\]\s*/i);
|
|
266
|
+
if (skipPrefixMatch) {
|
|
267
|
+
skipInterview = true;
|
|
268
|
+
task = task.slice(skipPrefixMatch[0].length);
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
mode,
|
|
272
|
+
qaRounds,
|
|
273
|
+
workers,
|
|
274
|
+
skipInterview,
|
|
275
|
+
modelOverride,
|
|
276
|
+
task,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
const COLOSSEUM_KEYWORDS = /\b(compare|versus|vs\.?|trade-?off|competing|alternatives|architecture options|benchmark approaches|colosseum|bandingkan)\b/i;
|
|
280
|
+
const AUDIT_KEYWORDS = /\b(audit|forensic|compliance|security audit|vulnerability|hardening|post-?mortem|verify claims|deep audit)\b/i;
|
|
281
|
+
const DISCOVER_KEYWORDS = /\b(discover|explore|investigate|trace|understand|root cause|how does|map out|deep dive|research)\b/i;
|
|
282
|
+
const REVIEW_KEYWORDS = /\b(review|critique|evaluate|assess|inspect|document review|pr review|code review|tinjau|evaluasi)\b/i;
|
|
283
|
+
export function heuristicClassifyTeamwork(task) {
|
|
284
|
+
if (COLOSSEUM_KEYWORDS.test(task))
|
|
285
|
+
return "colosseum";
|
|
286
|
+
if (AUDIT_KEYWORDS.test(task) && !CODER_KEYWORDS.test(task))
|
|
287
|
+
return "audit";
|
|
288
|
+
if (DISCOVER_KEYWORDS.test(task) && !CODER_KEYWORDS.test(task))
|
|
289
|
+
return "discover";
|
|
290
|
+
if (REVIEW_KEYWORDS.test(task) && !CODER_KEYWORDS.test(task))
|
|
291
|
+
return "review";
|
|
292
|
+
return "swe";
|
|
293
|
+
}
|
|
294
|
+
export function parseTeamworkClassifierDecision(output, fallbackTask) {
|
|
295
|
+
const normalized = output.trim().toLowerCase();
|
|
296
|
+
if (normalized.includes("colosseum"))
|
|
297
|
+
return "colosseum";
|
|
298
|
+
if (normalized.includes("discover"))
|
|
299
|
+
return "discover";
|
|
300
|
+
if (normalized.includes("audit"))
|
|
301
|
+
return "audit";
|
|
302
|
+
if (normalized.includes("review"))
|
|
303
|
+
return "review";
|
|
304
|
+
if (normalized.includes("swe"))
|
|
305
|
+
return "swe";
|
|
306
|
+
return heuristicClassifyTeamwork(fallbackTask);
|
|
307
|
+
}
|
|
308
|
+
export function parseSwarmArgs(raw) {
|
|
309
|
+
let mode = "auto";
|
|
310
|
+
let workers;
|
|
311
|
+
let useWorktree = false;
|
|
312
|
+
let modelOverride;
|
|
313
|
+
const task = consumeLeadingFlags(raw, (tok, peekNext, consumeNext) => {
|
|
314
|
+
if (tok === "--fanout" || tok === "-f") {
|
|
315
|
+
mode = "fanout";
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
if (tok === "--pipeline" || tok === "-p") {
|
|
319
|
+
mode = "pipeline";
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
if (tok.startsWith("--mode=")) {
|
|
323
|
+
const m = tok.slice("--mode=".length).toLowerCase();
|
|
324
|
+
if (m === "auto" || m === "fanout" || m === "pipeline") {
|
|
325
|
+
mode = m;
|
|
326
|
+
}
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
if (tok.startsWith("--workers=")) {
|
|
330
|
+
const n = parseStrictInt(tok.slice("--workers=".length));
|
|
331
|
+
if (n !== undefined && n >= 2 && n <= 6)
|
|
332
|
+
workers = n;
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
if ((tok === "--workers" || tok === "-w") && peekNext() !== undefined) {
|
|
336
|
+
const n = parseStrictInt(consumeNext());
|
|
337
|
+
if (n !== undefined && n >= 2 && n <= 6)
|
|
338
|
+
workers = n;
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
if (tok === "--worktree" || tok === "--share") {
|
|
342
|
+
useWorktree = true;
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
if (tok.startsWith("--model=")) {
|
|
346
|
+
const parsed = parseModelRef(tok.slice("--model=".length));
|
|
347
|
+
if (parsed)
|
|
348
|
+
modelOverride = parsed;
|
|
349
|
+
return true;
|
|
350
|
+
}
|
|
351
|
+
if ((tok === "--model" || tok === "-m") && peekNext() !== undefined) {
|
|
352
|
+
const parsed = parseModelRef(consumeNext());
|
|
353
|
+
if (parsed)
|
|
354
|
+
modelOverride = parsed;
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
return false;
|
|
358
|
+
});
|
|
359
|
+
return {
|
|
360
|
+
mode,
|
|
361
|
+
workers,
|
|
362
|
+
useWorktree,
|
|
363
|
+
modelOverride,
|
|
364
|
+
task,
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
const PIPELINE_KEYWORDS = /\b(multi-stage|pipeline|end-to-end|design and verify|generate and critique|full audit|comprehensive|migrate|redesign|build and test)\b/i;
|
|
368
|
+
export function heuristicClassifySwarm(task) {
|
|
369
|
+
if (PIPELINE_KEYWORDS.test(task))
|
|
370
|
+
return "pipeline";
|
|
371
|
+
return "fanout";
|
|
372
|
+
}
|
|
373
|
+
export function parseSwarmClassifierDecision(output, fallbackTask) {
|
|
374
|
+
const normalized = output.trim().toLowerCase();
|
|
375
|
+
if (normalized.includes("pipeline"))
|
|
376
|
+
return "pipeline";
|
|
377
|
+
if (normalized.includes("fanout") || normalized.includes("simple"))
|
|
378
|
+
return "fanout";
|
|
379
|
+
return heuristicClassifySwarm(fallbackTask);
|
|
380
|
+
}
|
|
381
|
+
export function parseSwarmSlices(output, count, task) {
|
|
382
|
+
const rawLines = output.split(/\r?\n/);
|
|
383
|
+
const listMarker = /^\s*(?:[-*+]|\d+[.)])\s+/;
|
|
384
|
+
const listLines = rawLines
|
|
385
|
+
.filter((line) => listMarker.test(line))
|
|
386
|
+
.map((line) => line.replace(listMarker, "").trim())
|
|
387
|
+
.filter((line) => line.length >= 6);
|
|
388
|
+
const lines = listLines.length > 0
|
|
389
|
+
? listLines
|
|
390
|
+
: rawLines
|
|
391
|
+
.map((line) => line.trim())
|
|
392
|
+
.filter((line) => line.length >= 6);
|
|
393
|
+
if (lines.length >= count) {
|
|
394
|
+
return lines.slice(0, count);
|
|
395
|
+
}
|
|
396
|
+
const defaults = [
|
|
397
|
+
`Core architecture, primary code paths, and direct requirements for: ${task}`,
|
|
398
|
+
`Edge cases, error handling, failure modes, and hidden assumptions for: ${task}`,
|
|
399
|
+
`Testing, verification strategy, performance, and integration impact for: ${task}`,
|
|
400
|
+
`Security, concurrency, and backward-compatibility implications for: ${task}`,
|
|
401
|
+
`Alternative designs, maintainability, and simplification opportunities for: ${task}`,
|
|
402
|
+
`Documentation, developer experience, and operational readiness for: ${task}`,
|
|
403
|
+
];
|
|
404
|
+
const merged = [...lines];
|
|
405
|
+
for (const fallback of defaults) {
|
|
406
|
+
if (merged.length >= count)
|
|
407
|
+
break;
|
|
408
|
+
merged.push(fallback);
|
|
409
|
+
}
|
|
410
|
+
return merged.slice(0, count);
|
|
411
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type BoostMode, type ModelRef, type ResolvedBoostMode, type SessionMessageLike } from "./parser.js";
|
|
2
|
+
export interface WorkerRuntimeMeta {
|
|
3
|
+
readOnly?: boolean;
|
|
4
|
+
swarmWorker?: {
|
|
5
|
+
boardId: string;
|
|
6
|
+
workerId: string;
|
|
7
|
+
initialSeenSeq?: number;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface BoostSessionClient {
|
|
11
|
+
get?(input: {
|
|
12
|
+
sessionID: string;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
model?: ModelRef;
|
|
15
|
+
projectID?: string;
|
|
16
|
+
}>;
|
|
17
|
+
create(input: {
|
|
18
|
+
parentID?: string;
|
|
19
|
+
title?: string;
|
|
20
|
+
model?: ModelRef;
|
|
21
|
+
location?: {
|
|
22
|
+
directory: string;
|
|
23
|
+
};
|
|
24
|
+
}): Promise<{
|
|
25
|
+
id: string;
|
|
26
|
+
}>;
|
|
27
|
+
prompt(input: {
|
|
28
|
+
sessionID: string;
|
|
29
|
+
text: string;
|
|
30
|
+
}): Promise<unknown>;
|
|
31
|
+
wait(input: {
|
|
32
|
+
sessionID: string;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
interrupt?(input: {
|
|
35
|
+
sessionID: string;
|
|
36
|
+
}): Promise<unknown>;
|
|
37
|
+
context(input: {
|
|
38
|
+
sessionID: string;
|
|
39
|
+
}): Promise<readonly SessionMessageLike[]>;
|
|
40
|
+
generate(input: {
|
|
41
|
+
sessionID: string;
|
|
42
|
+
prompt: string;
|
|
43
|
+
}): Promise<{
|
|
44
|
+
text: string;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
export interface BoostPipelineOptions {
|
|
48
|
+
sessionID: string;
|
|
49
|
+
task: string;
|
|
50
|
+
additionalContext?: string;
|
|
51
|
+
continueSessionID?: string;
|
|
52
|
+
mode?: BoostMode;
|
|
53
|
+
improvementRounds?: number;
|
|
54
|
+
maxExtraVerificationRounds?: number;
|
|
55
|
+
modelOverride?: ModelRef;
|
|
56
|
+
onProgress?: (status: string) => void | Promise<void>;
|
|
57
|
+
signal?: AbortSignal;
|
|
58
|
+
}
|
|
59
|
+
export interface BoostPipelineResult {
|
|
60
|
+
mode: ResolvedBoostMode;
|
|
61
|
+
roundsExecuted: number;
|
|
62
|
+
childSessionIDs: string[];
|
|
63
|
+
report: string;
|
|
64
|
+
verificationVerdict: "PASS" | "FAIL" | "SKIPPED";
|
|
65
|
+
verificationNote: string;
|
|
66
|
+
}
|
|
67
|
+
export declare function throwIfAborted(signal?: AbortSignal, label?: string): void;
|
|
68
|
+
export declare function runIsolatedWorker(sessionClient: BoostSessionClient, parentID: string, title: string, promptText: string, modelOverride?: ModelRef, signal?: AbortSignal, location?: {
|
|
69
|
+
directory: string;
|
|
70
|
+
}, continueSessionID?: string, runtimeMeta?: WorkerRuntimeMeta): Promise<{
|
|
71
|
+
sessionID: string;
|
|
72
|
+
text: string;
|
|
73
|
+
}>;
|
|
74
|
+
export declare function runBoostPipeline(sessionClient: BoostSessionClient, options: BoostPipelineOptions): Promise<BoostPipelineResult>;
|
package/dist/pipeline.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { extractConversationContext, hasReportUnresolvedGaps, mergeAdditionalContext, } from "./context.js";
|
|
2
|
+
import { extractAssistantText, heuristicClassifyTask, parseClassifierDecision, parseVerificationDecision, } from "./parser.js";
|
|
3
|
+
import { buildClassifyPrompt, buildCoderImprovementPrompt, buildCoderWorkerL0Prompt, buildInvestigatorImprovementPrompt, buildInvestigatorWorkerL0Prompt, buildOrchestratorVerifyPrompt, } from "./prompts.js";
|
|
4
|
+
import { registerReadOnlySession, registerSwarmWorkerSession, unregisterReadOnlySession, unregisterSwarmWorkerSession, } from "./session-registry.js";
|
|
5
|
+
export function throwIfAborted(signal, label = "Boost pipeline") {
|
|
6
|
+
if (signal?.aborted) {
|
|
7
|
+
throw new Error(`${label} aborted.`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
async function resolveEffectiveModel(sessionClient, parentID, modelOverride) {
|
|
11
|
+
if (modelOverride) {
|
|
12
|
+
return modelOverride;
|
|
13
|
+
}
|
|
14
|
+
if (!sessionClient.get) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const parent = await sessionClient.get({ sessionID: parentID });
|
|
19
|
+
return parent?.model;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function runIsolatedWorker(sessionClient, parentID, title, promptText, modelOverride, signal, location, continueSessionID, runtimeMeta) {
|
|
26
|
+
throwIfAborted(signal, title);
|
|
27
|
+
let targetSessionID = continueSessionID;
|
|
28
|
+
if (!targetSessionID) {
|
|
29
|
+
// Explicitly resolve and pass the parent session's active model so child sessions
|
|
30
|
+
// never fall back to OpenCode's global default model (which may differ or be unavailable).
|
|
31
|
+
const effectiveModel = await resolveEffectiveModel(sessionClient, parentID, modelOverride);
|
|
32
|
+
// OpenCode ignores `location` when `parentID` is set, so omit `parentID` when targeting a worktree.
|
|
33
|
+
const child = await sessionClient.create({
|
|
34
|
+
...(location ? { location } : { parentID }),
|
|
35
|
+
title,
|
|
36
|
+
...(effectiveModel ? { model: effectiveModel } : {}),
|
|
37
|
+
});
|
|
38
|
+
targetSessionID = child.id;
|
|
39
|
+
}
|
|
40
|
+
if (runtimeMeta?.readOnly) {
|
|
41
|
+
registerReadOnlySession(targetSessionID);
|
|
42
|
+
}
|
|
43
|
+
if (runtimeMeta?.swarmWorker) {
|
|
44
|
+
registerSwarmWorkerSession(targetSessionID, runtimeMeta.swarmWorker.boardId, runtimeMeta.swarmWorker.workerId, runtimeMeta.swarmWorker.initialSeenSeq ?? 0);
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await sessionClient.prompt({
|
|
48
|
+
sessionID: targetSessionID,
|
|
49
|
+
text: promptText,
|
|
50
|
+
});
|
|
51
|
+
if (signal) {
|
|
52
|
+
if (signal.aborted) {
|
|
53
|
+
await Promise.resolve(sessionClient.interrupt?.({ sessionID: targetSessionID })).catch(() => { });
|
|
54
|
+
throw new Error(`${title} aborted.`);
|
|
55
|
+
}
|
|
56
|
+
let onAbort;
|
|
57
|
+
const abortPromise = new Promise((_, reject) => {
|
|
58
|
+
onAbort = () => {
|
|
59
|
+
void Promise.resolve(sessionClient.interrupt?.({ sessionID: targetSessionID })).catch(() => { });
|
|
60
|
+
reject(new Error(`${title} aborted.`));
|
|
61
|
+
};
|
|
62
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
63
|
+
});
|
|
64
|
+
const waitPromise = sessionClient.wait({ sessionID: targetSessionID });
|
|
65
|
+
waitPromise.catch(() => { });
|
|
66
|
+
try {
|
|
67
|
+
await Promise.race([waitPromise, abortPromise]);
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
if (onAbort) {
|
|
71
|
+
signal.removeEventListener("abort", onAbort);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
await sessionClient.wait({ sessionID: targetSessionID });
|
|
77
|
+
}
|
|
78
|
+
throwIfAborted(signal, title);
|
|
79
|
+
const messages = await sessionClient.context({ sessionID: targetSessionID });
|
|
80
|
+
const { text, error } = extractAssistantText(messages);
|
|
81
|
+
if (error) {
|
|
82
|
+
throw new Error(`Worker "${title}" failed: ${error}`);
|
|
83
|
+
}
|
|
84
|
+
if (!text) {
|
|
85
|
+
throw new Error(`Worker "${title}" completed without producing a text report.`);
|
|
86
|
+
}
|
|
87
|
+
return { sessionID: targetSessionID, text };
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
if (runtimeMeta?.readOnly) {
|
|
91
|
+
unregisterReadOnlySession(targetSessionID);
|
|
92
|
+
}
|
|
93
|
+
if (runtimeMeta?.swarmWorker) {
|
|
94
|
+
unregisterSwarmWorkerSession(targetSessionID);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function resolveMode(sessionClient, sessionID, task, requestedMode, additionalContext) {
|
|
99
|
+
if (requestedMode === "coder" || requestedMode === "investigate") {
|
|
100
|
+
return requestedMode;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const res = await sessionClient.generate({
|
|
104
|
+
sessionID,
|
|
105
|
+
prompt: buildClassifyPrompt(task, additionalContext),
|
|
106
|
+
});
|
|
107
|
+
return parseClassifierDecision(res.text, task);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return heuristicClassifyTask(task);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export async function runBoostPipeline(sessionClient, options) {
|
|
114
|
+
const { sessionID, task, additionalContext, continueSessionID, mode: requestedMode = "auto", improvementRounds = 1, maxExtraVerificationRounds = 1, modelOverride, onProgress, signal, } = options;
|
|
115
|
+
const childSessionIDs = [];
|
|
116
|
+
throwIfAborted(signal, "Boost pipeline");
|
|
117
|
+
const parentContext = additionalContext?.trim()
|
|
118
|
+
? undefined
|
|
119
|
+
: await extractConversationContext(sessionClient, sessionID);
|
|
120
|
+
const effectiveContext = mergeAdditionalContext(additionalContext, parentContext);
|
|
121
|
+
await onProgress?.("Phase 1/3: Formulating strategy & routing mode...");
|
|
122
|
+
const mode = await resolveMode(sessionClient, sessionID, task, requestedMode, effectiveContext);
|
|
123
|
+
throwIfAborted(signal, "Boost pipeline");
|
|
124
|
+
const labelPrefix = mode === "coder" ? "DeepCoder" : "DeepInvestigator";
|
|
125
|
+
// Phase 2a: Layer 0 Worker
|
|
126
|
+
await onProgress?.(`Phase 2/3 (${labelPrefix}): Running Layer 0 worker...`);
|
|
127
|
+
const l0Prompt = mode === "coder"
|
|
128
|
+
? buildCoderWorkerL0Prompt(task, effectiveContext)
|
|
129
|
+
: buildInvestigatorWorkerL0Prompt(task, effectiveContext);
|
|
130
|
+
const isReadOnly = mode === "investigate";
|
|
131
|
+
const l0Result = await runIsolatedWorker(sessionClient, sessionID, `Boost ${labelPrefix} L0`, l0Prompt, modelOverride, signal, undefined, continueSessionID, { readOnly: isReadOnly });
|
|
132
|
+
childSessionIDs.push(l0Result.sessionID);
|
|
133
|
+
let currentReport = l0Result.text;
|
|
134
|
+
let roundsExecuted = 0;
|
|
135
|
+
// Phase 2b: Iterative Adversarial Improvement Rounds
|
|
136
|
+
for (let round = 1; round <= improvementRounds; round++) {
|
|
137
|
+
roundsExecuted++;
|
|
138
|
+
await onProgress?.(`Phase 2/3 (${labelPrefix}): Running Improvement Worker #${round}...`);
|
|
139
|
+
const impPrompt = mode === "coder"
|
|
140
|
+
? buildCoderImprovementPrompt(task, currentReport, round, effectiveContext)
|
|
141
|
+
: buildInvestigatorImprovementPrompt(task, currentReport, round, effectiveContext);
|
|
142
|
+
const impResult = await runIsolatedWorker(sessionClient, sessionID, `Boost ${labelPrefix} Improvement #${round}`, impPrompt, modelOverride, signal, undefined, undefined, { readOnly: isReadOnly });
|
|
143
|
+
childSessionIDs.push(impResult.sessionID);
|
|
144
|
+
currentReport = impResult.text;
|
|
145
|
+
if (round < improvementRounds && !hasReportUnresolvedGaps(currentReport)) {
|
|
146
|
+
await onProgress?.(`Phase 2/3 (${labelPrefix}): Improvement #${round} report is clean — stopping improvement rounds early.`);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Phase 3: Independent Orchestrator Verification
|
|
151
|
+
let verificationVerdict = "SKIPPED";
|
|
152
|
+
let verificationNote = "";
|
|
153
|
+
for (let attempt = 0; attempt <= maxExtraVerificationRounds; attempt++) {
|
|
154
|
+
await onProgress?.(`Phase 3/3 (${labelPrefix}): Independent orchestrator spot-check...`);
|
|
155
|
+
const verifyResult = await runIsolatedWorker(sessionClient, sessionID, `Boost Orchestrator Verify #${attempt + 1}`, buildOrchestratorVerifyPrompt(task, mode, currentReport, effectiveContext), modelOverride, signal, undefined, undefined, { readOnly: true });
|
|
156
|
+
childSessionIDs.push(verifyResult.sessionID);
|
|
157
|
+
const decision = parseVerificationDecision(verifyResult.text);
|
|
158
|
+
verificationNote = decision.reason;
|
|
159
|
+
const reportHasUnresolvedGaps = hasReportUnresolvedGaps(currentReport);
|
|
160
|
+
if (decision.passed && !reportHasUnresolvedGaps) {
|
|
161
|
+
verificationVerdict = "PASS";
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
verificationVerdict = "FAIL";
|
|
165
|
+
if (attempt < maxExtraVerificationRounds) {
|
|
166
|
+
roundsExecuted++;
|
|
167
|
+
const fixRound = roundsExecuted;
|
|
168
|
+
const feedbackReason = !decision.passed
|
|
169
|
+
? decision.reason
|
|
170
|
+
: `${decision.reason}\n\nWorker report still contains unresolved gaps (e.g., Fatal/Critical/Blocking issues, Shallow Verification, Remaining Questions & Gaps, or a FAIL verdict).`;
|
|
171
|
+
await onProgress?.(`Phase 3/3 (${labelPrefix}): Spot-check found gaps; running targeted Improvement Worker #${fixRound}...`);
|
|
172
|
+
const impPrompt = mode === "coder"
|
|
173
|
+
? buildCoderImprovementPrompt(task, currentReport, fixRound, effectiveContext, feedbackReason)
|
|
174
|
+
: buildInvestigatorImprovementPrompt(task, currentReport, fixRound, effectiveContext, feedbackReason);
|
|
175
|
+
const fixResult = await runIsolatedWorker(sessionClient, sessionID, `Boost ${labelPrefix} Fix #${fixRound}`, impPrompt, modelOverride, signal, undefined, undefined, { readOnly: isReadOnly });
|
|
176
|
+
childSessionIDs.push(fixResult.sessionID);
|
|
177
|
+
currentReport = fixResult.text;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
mode,
|
|
182
|
+
roundsExecuted,
|
|
183
|
+
childSessionIDs,
|
|
184
|
+
report: currentReport,
|
|
185
|
+
verificationVerdict,
|
|
186
|
+
verificationNote,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ResolvedBoostMode } from "./parser.js";
|
|
2
|
+
export declare function buildClassifyPrompt(task: string, additionalContext?: string): string;
|
|
3
|
+
export declare function buildCoderWorkerL0Prompt(task: string, additionalContext?: string): string;
|
|
4
|
+
export declare function buildCoderImprovementPrompt(task: string, priorAttempt: string, round: number, additionalContext?: string, spotCheckFeedback?: string): string;
|
|
5
|
+
export declare function buildInvestigatorWorkerL0Prompt(task: string, additionalContext?: string): string;
|
|
6
|
+
export declare function buildInvestigatorImprovementPrompt(task: string, priorAttempt: string, round: number, additionalContext?: string, spotCheckFeedback?: string): string;
|
|
7
|
+
export declare function buildOrchestratorVerifyPrompt(task: string, mode: ResolvedBoostMode, finalReport: string, additionalContext?: string): string;
|