@elyracode/swarm 0.9.57 → 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/CHANGELOG.md +14 -0
- package/README.md +8 -7
- package/extensions/index.ts +262 -172
- package/package.json +9 -2
- package/skills/elyra-swarm/SKILL.md +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.0.0] - 2026-11-22
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- The `swarm` tool now runs every stage as a separate child Elyra agent by default, in the working tree, with each stage receiving the outputs of earlier stages; previously the default mode only returned the stage instructions for the parent agent to follow. Read-only stages are limited to `read,grep,find,ls`, write stages to the built-in tools (no agent-spawning tools), and the tool reports the stages' usage as `details.modelUsage` so session cost includes them
|
|
8
|
+
- Worktree mode outside a git repository (or when the worktree cannot be created) now runs the stages as child agents in the working tree instead of falling back to prompt injection
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Fixed worktree mode starting `elyra` from PATH, which could be a different version or missing; stages now run the same Elyra executable as the parent session
|
|
13
|
+
- Fixed aborting or timing out a worktree stage signalling only the direct `elyra` process; the child's whole process tree is now killed
|
|
14
|
+
|
|
15
|
+
## [0.9.58] - 2026-11-18
|
|
16
|
+
|
|
3
17
|
## [0.9.57] - 2026-11-10
|
|
4
18
|
|
|
5
19
|
## [0.9.56] - 2026-11-01
|
package/README.md
CHANGED
|
@@ -74,18 +74,19 @@ Run a swarm review on the checkout flow
|
|
|
74
74
|
|
|
75
75
|
## How It Works
|
|
76
76
|
|
|
77
|
-
Each pipeline stage runs as a
|
|
77
|
+
Each pipeline stage runs as a separate child Elyra agent with its own context window. Stages run in order, and every stage receives the outputs of the earlier stages in its prompt. The `swarm` tool returns all stage outputs and a summary, and reports the stages' cost so it is added to your session cost.
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
Children run the same Elyra executable as your session (not an `elyra` found on PATH), with your current model, thinking level, and project trust decision. Tool access is enforced with `--tools`: read-only stages (every `review` pipeline stage, and the plan, review, analyze, and verify stages of the other pipelines) get `read,grep,find,ls`; write stages (code, test, fix, implement) get the built-in tools `read,bash,edit,write,grep,find,ls`. Stages cannot start further subagents or swarms.
|
|
80
|
+
|
|
81
|
+
By default write stages edit your working tree directly. The pipeline stops at the first failed stage; changes made by earlier stages remain. Each stage has a 10 minute timeout, and aborting the tool call kills the running stage's process tree.
|
|
80
82
|
|
|
81
83
|
## Worktree Mode
|
|
82
84
|
|
|
83
|
-
Add `--worktrees` (or pass `worktrees=true` to the `swarm` tool) to run every stage
|
|
85
|
+
Add `--worktrees` (or pass `worktrees=true` to the `swarm` tool) to run every stage inside an isolated git worktree instead of your working tree:
|
|
84
86
|
|
|
85
|
-
-
|
|
86
|
-
- Read-only stages are mechanically restricted to `read,grep,find,ls` tools, not just prompted.
|
|
87
|
+
- Stages run inside a detached **git worktree** based on HEAD, so your working tree is never touched while the swarm runs.
|
|
87
88
|
- When all stages complete, the combined changes are checked for conflicts against files that changed in your working tree during the run. If clean, they are applied **uncommitted** so you can review them; if not, the worktree is kept and the conflicting paths are listed.
|
|
88
89
|
- On any failure the worktree is kept for inspection (`git worktree remove --force <dir>` to discard).
|
|
89
|
-
- Outside a git repository, worktree
|
|
90
|
+
- Outside a git repository, or when the worktree cannot be created, the stages run in your working tree as in the default mode.
|
|
90
91
|
|
|
91
|
-
Requirements: a git repository
|
|
92
|
+
Requirements: a git repository. Sub-agents start from HEAD, so uncommitted changes in your tree are not visible to them.
|
package/extensions/index.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
AgentToolUpdateCallback,
|
|
3
|
+
ChildAgentInvocation,
|
|
4
|
+
ChildAgentResult,
|
|
5
|
+
ExtensionAPI,
|
|
6
|
+
ExtensionContext,
|
|
7
|
+
} from "@elyracode/coding-agent";
|
|
8
|
+
import { READ_ONLY_CHILD_AGENT_TOOLS, runChildAgent, sumChildAgentUsage } from "@elyracode/coding-agent";
|
|
2
9
|
import { Type } from "typebox";
|
|
3
10
|
import {
|
|
4
11
|
applyPatch,
|
|
@@ -260,180 +267,254 @@ function renderPipeline(pipeline: Pipeline, activeIndex: number, completedIndice
|
|
|
260
267
|
return lines.join("\n");
|
|
261
268
|
}
|
|
262
269
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
270
|
+
// ── Stage execution (child agents) ──────────────────────────────────────────
|
|
271
|
+
|
|
272
|
+
/** Tools for stages that may edit files. Agent-spawning tools are left out so stages do not recurse. */
|
|
273
|
+
const WRITE_STAGE_TOOLS = ["read", "bash", "edit", "write", "grep", "find", "ls"];
|
|
274
|
+
/** Cap on each stage's output (it is passed to every later stage). */
|
|
275
|
+
const STAGE_OUTPUT_CHARS = 30_000;
|
|
267
276
|
|
|
268
|
-
|
|
277
|
+
export interface SwarmOptions {
|
|
278
|
+
/** Executable used for stage agents. Defaults to the running Elyra (tests inject a fake). */
|
|
279
|
+
invocation?: ChildAgentInvocation;
|
|
280
|
+
/** Per-stage timeout in milliseconds. Default 10 minutes. */
|
|
281
|
+
timeoutMs?: number;
|
|
269
282
|
}
|
|
270
283
|
|
|
271
|
-
|
|
272
|
-
|
|
284
|
+
interface SwarmDetails {
|
|
285
|
+
pipeline?: string;
|
|
286
|
+
stages?: number;
|
|
287
|
+
task?: string;
|
|
288
|
+
worktree?: string;
|
|
289
|
+
files?: string[];
|
|
290
|
+
failedStage?: string;
|
|
291
|
+
modelUsage?: ChildAgentResult["usage"];
|
|
292
|
+
}
|
|
273
293
|
|
|
274
|
-
|
|
275
|
-
|
|
294
|
+
type SwarmUpdate = AgentToolUpdateCallback<SwarmDetails> | undefined;
|
|
295
|
+
|
|
296
|
+
function buildStagePrompt(pipeline: Pipeline, stageIndex: number, task: string, previousOutputs: string[]): string {
|
|
297
|
+
const stage = pipeline.stages[stageIndex]!;
|
|
276
298
|
const parts: string[] = [];
|
|
299
|
+
parts.push(`You are one stage of the "${pipeline.name}" swarm pipeline.`);
|
|
300
|
+
parts.push(`\n\n**Task**: ${task}`);
|
|
301
|
+
parts.push(`\n\n**Your role**:\n${stage.instructions}`);
|
|
302
|
+
if (stage.readOnly) {
|
|
303
|
+
parts.push(`\n\n**Constraint**: This is a read-only stage. You have no tools that edit files or run commands.`);
|
|
304
|
+
}
|
|
305
|
+
if (previousOutputs.length > 0) {
|
|
306
|
+
parts.push(`\n\n**Output from previous stages**:\n\n${previousOutputs.join("\n\n---\n\n")}`);
|
|
307
|
+
}
|
|
308
|
+
parts.push(
|
|
309
|
+
`\n\nWork directly in the current directory. When done, end with a concise summary of what you did/found.`,
|
|
310
|
+
);
|
|
311
|
+
return parts.join("");
|
|
312
|
+
}
|
|
277
313
|
|
|
278
|
-
|
|
314
|
+
interface StagesOutcome {
|
|
315
|
+
completed: Set<number>;
|
|
316
|
+
transcript: string[];
|
|
317
|
+
results: ChildAgentResult[];
|
|
318
|
+
failed?: { stage: Stage; index: number; error: string };
|
|
319
|
+
}
|
|
279
320
|
|
|
280
|
-
|
|
281
|
-
|
|
321
|
+
/** Run every stage as a child agent in `cwd`, in order, passing earlier outputs to later stages. */
|
|
322
|
+
async function runStages(
|
|
323
|
+
elyra: ExtensionAPI,
|
|
324
|
+
options: SwarmOptions,
|
|
325
|
+
pipeline: Pipeline,
|
|
326
|
+
task: string,
|
|
327
|
+
cwd: string,
|
|
328
|
+
ctx: ExtensionContext,
|
|
329
|
+
signal: AbortSignal | undefined,
|
|
330
|
+
progress: (activeIndex: number, completed: Set<number>, line?: string) => void,
|
|
331
|
+
): Promise<StagesOutcome> {
|
|
332
|
+
const model = ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : undefined;
|
|
333
|
+
const thinking = elyra.getThinkingLevel();
|
|
334
|
+
const completed = new Set<number>();
|
|
335
|
+
const stageOutputs: string[] = [];
|
|
336
|
+
const transcript: string[] = [];
|
|
337
|
+
const results: ChildAgentResult[] = [];
|
|
282
338
|
|
|
283
|
-
// Generate instructions for all stages
|
|
284
339
|
for (let i = 0; i < pipeline.stages.length; i++) {
|
|
285
340
|
const stage = pipeline.stages[i]!;
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
341
|
+
progress(i, completed);
|
|
342
|
+
|
|
343
|
+
// The child env carries the parent's project trust (needed in a temp worktree) and any
|
|
344
|
+
// shared services (e.g. an MCP broker) so stages do not start from scratch.
|
|
345
|
+
const result = await runChildAgent({
|
|
346
|
+
prompt: buildStagePrompt(pipeline, i, task, stageOutputs),
|
|
347
|
+
cwd,
|
|
348
|
+
env: ctx.getChildAgentEnv(),
|
|
349
|
+
tools: stage.readOnly ? READ_ONLY_CHILD_AGENT_TOOLS : WRITE_STAGE_TOOLS,
|
|
350
|
+
model,
|
|
351
|
+
thinking,
|
|
352
|
+
signal,
|
|
353
|
+
timeoutMs: options.timeoutMs,
|
|
354
|
+
maxOutputChars: STAGE_OUTPUT_CHARS,
|
|
355
|
+
invocation: options.invocation,
|
|
356
|
+
onProgress: (p) => {
|
|
357
|
+
const last = p.lastTool ? ` (last: ${p.lastTool})` : "";
|
|
358
|
+
progress(i, completed, `${stage.label}: ${p.toolCalls} tool calls${last}`);
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
results.push(result);
|
|
290
362
|
|
|
291
|
-
if (
|
|
292
|
-
|
|
363
|
+
if (result.status !== "ok") {
|
|
364
|
+
const error = `${result.status}: ${result.error ?? "stage failed"}`;
|
|
365
|
+
transcript.push(`#### ${stage.label} Output\n\nFAILED (${error})${result.text ? `\n\n${result.text}` : ""}`);
|
|
366
|
+
return { completed, transcript, results, failed: { stage, index: i, error } };
|
|
293
367
|
}
|
|
294
368
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
);
|
|
299
|
-
} else {
|
|
300
|
-
parts.push(
|
|
301
|
-
`This is the final stage. Write your output under a "#### ${stage.label} Output" heading, then provide a "## Swarm Summary" with the overall result.\n\n`,
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
completedIndices.add(i);
|
|
369
|
+
stageOutputs.push(`#### ${stage.label} Output\n\n${result.text}`);
|
|
370
|
+
transcript.push(`#### ${stage.label} Output\n\n${result.text}`);
|
|
371
|
+
completed.add(i);
|
|
306
372
|
}
|
|
373
|
+
return { completed, transcript, results };
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function makeProgress(pipeline: Pipeline, task: string, onUpdate: SwarmUpdate, prefix: string, worktree?: string) {
|
|
377
|
+
return (activeIndex: number, completed: Set<number>, line?: string) => {
|
|
378
|
+
onUpdate?.({
|
|
379
|
+
content: [
|
|
380
|
+
{
|
|
381
|
+
type: "text",
|
|
382
|
+
text: `${prefix}${renderPipeline(pipeline, activeIndex, completed)}${line ? `${line}\n` : ""}`,
|
|
383
|
+
},
|
|
384
|
+
],
|
|
385
|
+
details: { pipeline: pipeline.name, task, worktree },
|
|
386
|
+
});
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ── Direct mode (child agents in the working tree) ─────────────────────────
|
|
307
391
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
392
|
+
async function runDirectPipeline(
|
|
393
|
+
elyra: ExtensionAPI,
|
|
394
|
+
options: SwarmOptions,
|
|
395
|
+
pipeline: Pipeline,
|
|
396
|
+
task: string,
|
|
397
|
+
ctx: ExtensionContext,
|
|
398
|
+
signal: AbortSignal | undefined,
|
|
399
|
+
onUpdate: SwarmUpdate,
|
|
400
|
+
note?: string,
|
|
401
|
+
) {
|
|
402
|
+
const prefix = note ? `> ${note}\n\n` : "";
|
|
403
|
+
const outcome = await runStages(
|
|
404
|
+
elyra,
|
|
405
|
+
options,
|
|
406
|
+
pipeline,
|
|
407
|
+
task,
|
|
408
|
+
ctx.cwd,
|
|
409
|
+
ctx,
|
|
410
|
+
signal,
|
|
411
|
+
makeProgress(pipeline, task, onUpdate, prefix),
|
|
412
|
+
);
|
|
413
|
+
const summary = outcome.failed
|
|
414
|
+
? `Aborted at stage "${outcome.failed.stage.label}": ${outcome.failed.error}\n\nLater stages did not run. Changes made by earlier stages remain in your working tree.`
|
|
415
|
+
: `All ${pipeline.stages.length} stages completed, each as a separate child agent in your working tree.`;
|
|
416
|
+
const active = outcome.failed ? outcome.failed.index : -1;
|
|
311
417
|
|
|
312
418
|
return {
|
|
313
|
-
content: [
|
|
419
|
+
content: [
|
|
420
|
+
{
|
|
421
|
+
type: "text" as const,
|
|
422
|
+
text:
|
|
423
|
+
`${prefix}${renderPipeline(pipeline, active, outcome.completed)}` +
|
|
424
|
+
`${outcome.transcript.join("\n\n")}\n\n## Swarm Summary\n\n${summary}`,
|
|
425
|
+
},
|
|
426
|
+
],
|
|
314
427
|
details: {
|
|
315
428
|
pipeline: pipeline.name,
|
|
316
429
|
stages: pipeline.stages.length,
|
|
317
430
|
task,
|
|
318
|
-
|
|
431
|
+
failedStage: outcome.failed?.stage.name,
|
|
432
|
+
modelUsage: sumChildAgentUsage(outcome.results),
|
|
433
|
+
} satisfies SwarmDetails,
|
|
319
434
|
};
|
|
320
435
|
}
|
|
321
436
|
|
|
322
|
-
// ── Worktree mode (isolated
|
|
323
|
-
|
|
324
|
-
const STAGE_TIMEOUT_MS = 600_000;
|
|
325
|
-
const READ_ONLY_TOOLS = "read,grep,find,ls";
|
|
326
|
-
|
|
327
|
-
function buildStagePrompt(pipeline: Pipeline, stageIndex: number, task: string, previousOutputs: string[]): string {
|
|
328
|
-
const stage = pipeline.stages[stageIndex]!;
|
|
329
|
-
const parts: string[] = [];
|
|
330
|
-
parts.push(`You are one stage of the "${pipeline.name}" swarm pipeline.`);
|
|
331
|
-
parts.push(`\n\n**Task**: ${task}`);
|
|
332
|
-
parts.push(`\n\n**Your role**:\n${stage.instructions}`);
|
|
333
|
-
if (stage.readOnly) {
|
|
334
|
-
parts.push(`\n\n**Constraint**: This is a read-only stage. Do NOT edit any files.`);
|
|
335
|
-
}
|
|
336
|
-
if (previousOutputs.length > 0) {
|
|
337
|
-
parts.push(`\n\n**Output from previous stages**:\n\n${previousOutputs.join("\n\n---\n\n")}`);
|
|
338
|
-
}
|
|
339
|
-
parts.push(
|
|
340
|
-
`\n\nWork directly in the current directory. When done, end with a concise summary of what you did/found.`,
|
|
341
|
-
);
|
|
342
|
-
return parts.join("");
|
|
343
|
-
}
|
|
437
|
+
// ── Worktree mode (child agents in an isolated git worktree) ────────────────
|
|
344
438
|
|
|
345
439
|
async function runWorktreePipeline(
|
|
346
440
|
elyra: ExtensionAPI,
|
|
441
|
+
options: SwarmOptions,
|
|
347
442
|
pipeline: Pipeline,
|
|
348
443
|
task: string,
|
|
349
444
|
ctx: ExtensionContext,
|
|
350
445
|
signal: AbortSignal | undefined,
|
|
351
|
-
onUpdate:
|
|
352
|
-
| ((partial: { content: Array<{ type: "text"; text: string }>; details: Record<string, unknown> }) => void)
|
|
353
|
-
| undefined,
|
|
446
|
+
onUpdate: SwarmUpdate,
|
|
354
447
|
) {
|
|
355
448
|
const cwd = ctx.cwd;
|
|
356
449
|
const exec = elyra.exec.bind(elyra);
|
|
357
450
|
|
|
358
451
|
if (!(await isGitRepo(exec, cwd))) {
|
|
359
|
-
return
|
|
452
|
+
return runDirectPipeline(
|
|
453
|
+
elyra,
|
|
454
|
+
options,
|
|
360
455
|
pipeline,
|
|
361
456
|
task,
|
|
362
|
-
|
|
457
|
+
ctx,
|
|
458
|
+
signal,
|
|
459
|
+
onUpdate,
|
|
460
|
+
"Worktree mode requested but this is not a git repository: stages run in your working tree instead.",
|
|
363
461
|
);
|
|
364
462
|
}
|
|
365
463
|
|
|
366
464
|
const mainBefore = await changedFiles(exec, cwd);
|
|
367
465
|
const worktree = await createWorktree(exec, cwd);
|
|
368
466
|
if ("error" in worktree) {
|
|
369
|
-
return
|
|
467
|
+
return runDirectPipeline(
|
|
468
|
+
elyra,
|
|
469
|
+
options,
|
|
370
470
|
pipeline,
|
|
371
471
|
task,
|
|
372
|
-
|
|
472
|
+
ctx,
|
|
473
|
+
signal,
|
|
474
|
+
onUpdate,
|
|
475
|
+
`Worktree mode requested but worktree creation failed (${worktree.error}): stages run in your working tree instead.`,
|
|
373
476
|
);
|
|
374
477
|
}
|
|
375
478
|
|
|
376
|
-
const modelArgs = ctx.model ? ["--model", `${ctx.model.provider}/${ctx.model.id}`] : [];
|
|
377
|
-
const completedIndices = new Set<number>();
|
|
378
|
-
const stageOutputs: string[] = [];
|
|
379
|
-
const transcript: string[] = [];
|
|
380
479
|
const dirtyNote =
|
|
381
480
|
mainBefore.size > 0
|
|
382
481
|
? `Note: the main tree has ${mainBefore.size} uncommitted change(s). Sub-agents work from HEAD and cannot see them.\n\n`
|
|
383
482
|
: "";
|
|
384
483
|
|
|
385
|
-
const progress = (activeIndex: number) => {
|
|
386
|
-
onUpdate?.({
|
|
387
|
-
content: [{ type: "text", text: `${dirtyNote}${renderPipeline(pipeline, activeIndex, completedIndices)}` }],
|
|
388
|
-
details: { pipeline: pipeline.name, task, worktree: worktree.dir },
|
|
389
|
-
});
|
|
390
|
-
};
|
|
391
|
-
|
|
392
484
|
try {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
`The worktree is kept for inspection: ${worktree.dir}\n` +
|
|
427
|
-
`Remove it with: git worktree remove --force ${worktree.dir}`,
|
|
428
|
-
},
|
|
429
|
-
],
|
|
430
|
-
details: { pipeline: pipeline.name, task, failedStage: stage.name, worktree: worktree.dir },
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
stageOutputs.push(`#### ${stage.label} Output\n\n${output}`);
|
|
435
|
-
transcript.push(`#### ${stage.label} Output\n\n${output}`);
|
|
436
|
-
completedIndices.add(i);
|
|
485
|
+
const outcome = await runStages(
|
|
486
|
+
elyra,
|
|
487
|
+
options,
|
|
488
|
+
pipeline,
|
|
489
|
+
task,
|
|
490
|
+
worktree.dir,
|
|
491
|
+
ctx,
|
|
492
|
+
signal,
|
|
493
|
+
makeProgress(pipeline, task, onUpdate, dirtyNote, worktree.dir),
|
|
494
|
+
);
|
|
495
|
+
const modelUsage = sumChildAgentUsage(outcome.results);
|
|
496
|
+
|
|
497
|
+
if (outcome.failed) {
|
|
498
|
+
return {
|
|
499
|
+
content: [
|
|
500
|
+
{
|
|
501
|
+
type: "text" as const,
|
|
502
|
+
text:
|
|
503
|
+
`${dirtyNote}${renderPipeline(pipeline, outcome.failed.index, outcome.completed)}` +
|
|
504
|
+
`${outcome.transcript.join("\n\n")}\n\n` +
|
|
505
|
+
`## Swarm Summary\n\nAborted at stage "${outcome.failed.stage.label}": ${outcome.failed.error}\n\n` +
|
|
506
|
+
`The worktree is kept for inspection: ${worktree.dir}\n` +
|
|
507
|
+
`Remove it with: git worktree remove --force ${worktree.dir}`,
|
|
508
|
+
},
|
|
509
|
+
],
|
|
510
|
+
details: {
|
|
511
|
+
pipeline: pipeline.name,
|
|
512
|
+
task,
|
|
513
|
+
failedStage: outcome.failed.stage.name,
|
|
514
|
+
worktree: worktree.dir,
|
|
515
|
+
modelUsage,
|
|
516
|
+
} satisfies SwarmDetails,
|
|
517
|
+
};
|
|
437
518
|
}
|
|
438
519
|
|
|
439
520
|
// Collect and apply the swarm's changes.
|
|
@@ -481,8 +562,8 @@ async function runWorktreePipeline(
|
|
|
481
562
|
{
|
|
482
563
|
type: "text" as const,
|
|
483
564
|
text:
|
|
484
|
-
`${dirtyNote}${renderPipeline(pipeline, -1,
|
|
485
|
-
`${transcript.join("\n\n")}\n\n` +
|
|
565
|
+
`${dirtyNote}${renderPipeline(pipeline, -1, outcome.completed)}` +
|
|
566
|
+
`${outcome.transcript.join("\n\n")}\n\n` +
|
|
486
567
|
`## Swarm Summary\n\nAll ${pipeline.stages.length} stages completed in an isolated git worktree.\n\n${applySection}`,
|
|
487
568
|
},
|
|
488
569
|
],
|
|
@@ -492,10 +573,11 @@ async function runWorktreePipeline(
|
|
|
492
573
|
task,
|
|
493
574
|
worktree: keepWorktree ? worktree.dir : undefined,
|
|
494
575
|
files: changes?.files ?? [],
|
|
495
|
-
|
|
576
|
+
modelUsage,
|
|
577
|
+
} satisfies SwarmDetails,
|
|
496
578
|
};
|
|
497
579
|
} catch (err) {
|
|
498
|
-
// Unexpected failure
|
|
580
|
+
// Unexpected failure: keep the worktree for recovery.
|
|
499
581
|
const message = err instanceof Error ? err.message : String(err);
|
|
500
582
|
return {
|
|
501
583
|
content: [
|
|
@@ -507,61 +589,69 @@ async function runWorktreePipeline(
|
|
|
507
589
|
`Remove it with: git worktree remove --force ${worktree.dir}`,
|
|
508
590
|
},
|
|
509
591
|
],
|
|
510
|
-
details: { pipeline: pipeline.name, task, worktree: worktree.dir },
|
|
592
|
+
details: { pipeline: pipeline.name, task, worktree: worktree.dir } satisfies SwarmDetails,
|
|
511
593
|
};
|
|
512
594
|
}
|
|
513
595
|
}
|
|
514
596
|
|
|
515
|
-
// ── Extension
|
|
516
|
-
|
|
517
|
-
export
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
description: "The task or target to work on",
|
|
538
|
-
}),
|
|
539
|
-
worktrees: Type.Optional(
|
|
540
|
-
Type.Boolean({
|
|
541
|
-
description: "Run stages as isolated sub-agents in a git worktree (requires a git repo)",
|
|
597
|
+
// ── Extension ───────────────────────────────────────────────────────────────
|
|
598
|
+
|
|
599
|
+
export function createSwarmExtension(options: SwarmOptions = {}): (elyra: ExtensionAPI) => void {
|
|
600
|
+
return (elyra: ExtensionAPI): void => {
|
|
601
|
+
// -- Tool: swarm --
|
|
602
|
+
elyra.registerTool({
|
|
603
|
+
name: "swarm",
|
|
604
|
+
label: "Run Swarm Pipeline",
|
|
605
|
+
description:
|
|
606
|
+
"Run an automated multi-agent swarm pipeline. Available pipelines: " +
|
|
607
|
+
"build (plan -> code -> test -> review -> fix), " +
|
|
608
|
+
"review (analyze -> correctness -> security -> tests -> synthesize), " +
|
|
609
|
+
"refactor (analyze -> plan -> implement -> verify). " +
|
|
610
|
+
"Each stage runs as a separate child Elyra agent with its own context; stages run in order and every stage " +
|
|
611
|
+
"receives the outputs of the earlier stages. Read-only stages are limited to read, grep, find, and ls. " +
|
|
612
|
+
"By default write stages edit your working tree directly. " +
|
|
613
|
+
"Set worktrees=true to run every stage in an isolated git worktree instead: " +
|
|
614
|
+
"write stages cannot touch your working tree, and the combined result is applied " +
|
|
615
|
+
"(uncommitted) only after a conflict check.",
|
|
616
|
+
parameters: Type.Object({
|
|
617
|
+
pipeline: Type.String({
|
|
618
|
+
description: "Pipeline name: build, review, refactor",
|
|
542
619
|
}),
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
620
|
+
task: Type.String({
|
|
621
|
+
description: "The task or target to work on, with all context the stages need",
|
|
622
|
+
}),
|
|
623
|
+
worktrees: Type.Optional(
|
|
624
|
+
Type.Boolean({
|
|
625
|
+
description: "Run stages in an isolated git worktree (requires a git repo)",
|
|
626
|
+
}),
|
|
627
|
+
),
|
|
628
|
+
}),
|
|
629
|
+
execute: async (_toolCallId, params, signal, onUpdate, ctx) => {
|
|
630
|
+
const pipeline = PIPELINES[params.pipeline];
|
|
631
|
+
if (!pipeline) {
|
|
632
|
+
const available = Object.entries(PIPELINES)
|
|
633
|
+
.map(([id, p]) => ` ${id}: ${p.description}`)
|
|
634
|
+
.join("\n");
|
|
635
|
+
return {
|
|
636
|
+
content: [{ type: "text", text: `Unknown pipeline: ${params.pipeline}\n\nAvailable:\n${available}` }],
|
|
637
|
+
details: {},
|
|
638
|
+
};
|
|
639
|
+
}
|
|
556
640
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
641
|
+
if (params.worktrees) {
|
|
642
|
+
return runWorktreePipeline(elyra, options, pipeline, params.task, ctx, signal, onUpdate);
|
|
643
|
+
}
|
|
644
|
+
return runDirectPipeline(elyra, options, pipeline, params.task, ctx, signal, onUpdate);
|
|
645
|
+
},
|
|
646
|
+
});
|
|
560
647
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
648
|
+
registerSwarmCommand(elyra);
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
export default createSwarmExtension();
|
|
564
653
|
|
|
654
|
+
function registerSwarmCommand(elyra: ExtensionAPI): void {
|
|
565
655
|
// -- Command: /swarm --
|
|
566
656
|
elyra.registerCommand("swarm", {
|
|
567
657
|
description: "Run a multi-agent swarm pipeline: /swarm [--worktrees] <pipeline> <task>",
|
|
@@ -583,7 +673,7 @@ export default function (elyra: ExtensionAPI): void {
|
|
|
583
673
|
})
|
|
584
674
|
.join("\n\n");
|
|
585
675
|
ctx.ui.notify(
|
|
586
|
-
`Available swarm pipelines:\n\n${pipelineList}\n\nUsage: /swarm [--worktrees] <pipeline> <task>\n\
|
|
676
|
+
`Available swarm pipelines:\n\n${pipelineList}\n\nUsage: /swarm [--worktrees] <pipeline> <task>\n\nEvery stage runs as a separate child agent. --worktrees runs them in an isolated git worktree.`,
|
|
587
677
|
);
|
|
588
678
|
return;
|
|
589
679
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elyracode/swarm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Multi-agent swarm orchestration for Elyra -- automated pipelines with visual progress tracking",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -25,6 +25,12 @@
|
|
|
25
25
|
"./skills"
|
|
26
26
|
]
|
|
27
27
|
},
|
|
28
|
+
"files": [
|
|
29
|
+
"extensions",
|
|
30
|
+
"skills",
|
|
31
|
+
"README.md",
|
|
32
|
+
"CHANGELOG.md"
|
|
33
|
+
],
|
|
28
34
|
"peerDependencies": {
|
|
29
35
|
"@elyracode/coding-agent": "*",
|
|
30
36
|
"typebox": "*"
|
|
@@ -32,6 +38,7 @@
|
|
|
32
38
|
"scripts": {
|
|
33
39
|
"clean": "echo 'nothing to clean'",
|
|
34
40
|
"build": "echo 'nothing to build'",
|
|
35
|
-
"check": "echo 'nothing to check'"
|
|
41
|
+
"check": "echo 'nothing to check'",
|
|
42
|
+
"test": "vitest --run"
|
|
36
43
|
}
|
|
37
44
|
}
|
|
@@ -25,7 +25,7 @@ Use the `swarm` tool when the user asks to:
|
|
|
25
25
|
|
|
26
26
|
1. User describes the task
|
|
27
27
|
2. Swarm selects a pipeline (or user specifies one)
|
|
28
|
-
3. Each stage runs with focused instructions
|
|
28
|
+
3. Each stage runs as a separate child agent with focused instructions; its output is passed to the next stage
|
|
29
29
|
4. Progress is shown as a visual pipeline in the TUI
|
|
30
30
|
5. Final summary collects all results
|
|
31
31
|
|
|
@@ -48,4 +48,6 @@ Commands:
|
|
|
48
48
|
|
|
49
49
|
## Worktree Mode
|
|
50
50
|
|
|
51
|
-
When the user asks for isolation, safety, or mentions worktrees, pass `worktrees=true` to the `swarm` tool.
|
|
51
|
+
By default write stages edit the user's working tree directly. When the user asks for isolation, safety, or mentions worktrees, pass `worktrees=true` to the `swarm` tool. The stages then run in a detached git worktree: the user's working tree is untouched while the swarm runs, and the combined result is applied uncommitted after a conflict check. Requires a git repository; otherwise stages run in the working tree.
|
|
52
|
+
|
|
53
|
+
Read-only stages are tool-restricted in both modes. Stages do not see this conversation: put everything they need in `task`.
|