🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(workflows): validate execution and branch step boundaries
Rudy Celekli416663b02771
diff --git a/v3/@claude-flow/cli/__tests__/workflow-step-bounds-r50.test.ts b/v3/@claude-flow/cli/__tests__/workflow-step-bounds-r50.test.tsnew file mode 100644index 0000000000..11295836ba--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/workflow-step-bounds-r50.test.ts@@ -0,0 +1,29 @@+import { beforeEach, afterEach, expect, it, vi } from 'vitest';+import { mkdtempSync, readFileSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+const state = vi.hoisted(() => ({ cwd: '' }));+vi.mock('../src/mcp-tools/types.js', () => ({ getProjectCwd: () => state.cwd }));+vi.mock('../src/mcp-tools/agent-execute-core.js', () => ({ executeAgentTask: vi.fn() }));+import { workflowTools } from '../src/mcp-tools/workflow-tools.js';+const call = (name: string, input: object) => workflowTools.find(t => t.name === name)!.handler(input) as Promise<any>;+const raw = () => readFileSync(join(state.cwd, '.claude-flow/workflows/store.json'), 'utf8');+beforeEach(() => { state.cwd = mkdtempSync(join(tmpdir(), 'ruflo-step-bounds-')); });+afterEach(() => rmSync(state.cwd, { recursive: true, force: true }));+it.each([-1, 0.5, 3, NaN, Infinity, '1'])('rejects invalid start index %s before changing persisted state', async startFromStep => {+ const { workflowId } = await call('workflow_create', { name: 'bounds', steps: [{type:'wait'}, {type:'wait'}] });+ const before = raw();+ expect(await call('workflow_execute', { workflowId, startFromStep })).toMatchObject({ error: expect.stringContaining('startFromStep') });+ expect(raw()).toBe(before);+});+it.each([-1, 0.5, 3, Infinity, '1'])('rejects invalid condition target %s before changing persisted state', async thenStep => {+ const { workflowId } = await call('workflow_create', { name: 'jump', steps: [{type:'condition',config:{when:'true',thenStep}}, {type:'wait'}] });+ const before = raw();+ expect(await call('workflow_execute', { workflowId })).toMatchObject({ error: expect.stringContaining('thenStep') });+ expect(raw()).toBe(before);+});+it('allows a resume at the completed boundary and valid forward branch', async () => {+ const { workflowId } = await call('workflow_create', { name: 'valid', steps: [{type:'condition',config:{when:'true',thenStep:2}}, {type:'wait'}] });+ expect(await call('workflow_execute', { workflowId })).toMatchObject({status:'completed',stepsCompleted:1});+ expect(await call('workflow_execute', { workflowId,startFromStep:2 })).toMatchObject({status:'completed',stepsCompleted:0});+});diff --git a/v3/@claude-flow/cli/src/mcp-tools/workflow-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/workflow-tools.tsindex 56232f651f..1b29dd57e2 100644--- a/v3/@claude-flow/cli/src/mcp-tools/workflow-tools.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/workflow-tools.ts@@ -289,6 +289,23 @@ export const workflowTools: MCPTool[] = [return { workflowId, error: 'Workflow already running' };}+ // Indices may name a step or the end boundary (used when resuming+ // after the final step). Reject invalid control flow before any writes.+ const validIndex = (value: unknown): value is number =>+ typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 && value <= workflow.steps.length;+ const startFromStep = input.startFromStep === undefined ? 0 : input.startFromStep;+ if (!validIndex(startFromStep)) {+ return { workflowId, error: `startFromStep must be an integer between 0 and ${workflow.steps.length}` };+ }+ for (const step of workflow.steps) {+ if (step.type !== 'condition') continue;+ for (const target of ['thenStep', 'elseStep']) {+ if (step.config[target] !== undefined && !validIndex(step.config[target])) {+ return { workflowId, error: `${step.stepId}.${target} must be an integer between 0 and ${workflow.steps.length}` };+ }+ }+ }+// Inject runtime variablesif (input.variables) {workflow.variables = { ...workflow.variables, ...(input.variables as Record<string, unknown>) };@@ -296,7 +313,7 @@ export const workflowTools: MCPTool[] = [workflow.status = 'running';workflow.startedAt = new Date().toISOString();- workflow.currentStep = (input.startFromStep as number) || 0;+ workflow.currentStep = startFromStep;saveWorkflowStore(store);// ADR-095 G3: real workflow runtime. Walk the steps in order;