Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 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

fix(workflows): validate the agent bindings used by the runtime

Rudy Celekli7ce0efe815af
diff --git a/v3/@claude-flow/cli/__tests__/workflow-validation-runtime.test.ts b/v3/@claude-flow/cli/__tests__/workflow-validation-runtime.test.ts
new file mode 100644
index 0000000000..a5136ffbc0
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/workflow-validation-runtime.test.ts
@@ -0,0 +1,42 @@
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+const state = vi.hoisted(() => ({ cwd: '', execute: vi.fn() }));
+vi.mock('../src/mcp-tools/types.js', () => ({ getProjectCwd: () => state.cwd }));
+vi.mock('../src/mcp-tools/agent-execute-core.js', () => ({ executeAgentTask: state.execute }));
+import { workflowTools } from '../src/mcp-tools/workflow-tools.js';
+const call = (name: string, input: Record<string, unknown>) => workflowTools.find(t => t.name === name)!.handler(input) as Promise<any>;
+const validate = async (doc: object) => {
+ const file = join(state.cwd, 'workflow.json');
+ writeFileSync(file, JSON.stringify(doc));
+ return call('workflow_validate', { file, strict: true });
+};
+beforeEach(() => {
+ state.cwd = mkdtempSync(join(tmpdir(), 'ruflo-workflow-validation-'));
+ state.execute.mockReset().mockResolvedValue({ success: true, output: 'done' });
+});
+afterEach(() => rmSync(state.cwd, { recursive: true, force: true }));
+it('strictly validates the agentId that the runtime actually dispatches', async () => {
+ const doc = { name: 'explicit', steps: [{ name: 'work', type: 'task', config: { agentId: 'worker', prompt: 'execute' } }] };
+ const { workflowId } = await call('workflow_create', doc);
+ expect(await call('workflow_execute', { workflowId })).toMatchObject({ status: 'completed' });
+ expect(state.execute).toHaveBeenCalledWith(expect.objectContaining({ agentId: 'worker', prompt: 'execute' }));
+ expect(await validate(doc)).toMatchObject({ valid: true, warnings: [], stats: { stages: 1, agents: 1 } });
+});
+it('validates defaultAgentId and exempts control steps from needing their own agents', async () => {
+ const doc = { name: 'mixed', variables: { defaultAgentId: 'default-worker' }, steps: [
+ { name: 'wait', type: 'wait', config: { ms: 0 } },
+ { name: 'branch', type: 'condition', config: { when: 'true' } },
+ { name: 'work', type: 'task' },
+ { name: 'override', type: 'task', config: { agentId: 'other-worker' } },
+ ] };
+ const { workflowId } = await call('workflow_create', doc);
+ expect(await call('workflow_execute', { workflowId })).toMatchObject({ status: 'completed', stepsCompleted: 4 });
+ expect(state.execute.mock.calls.map(([input]) => input.agentId)).toEqual(['default-worker', 'other-worker']);
+ expect(await validate(doc)).toMatchObject({ valid: true, warnings: [], stats: { stages: 4, agents: 2 } });
+});
+it('still warns about a task with no available agent and keeps legacy agent declarations', async () => {
+ expect(await validate({ steps: [{ name: 'missing', type: 'task' }] })).toMatchObject({ valid: false, warnings: [expect.objectContaining({ line: 1 })] });
+ expect(await validate({ steps: [{ agent: 'legacy' }, { agentType: 'legacy' }, { agent_type: 'other' }] })).toMatchObject({ valid: true, stats: { agents: 2 } });
+});
diff --git a/v3/@claude-flow/cli/src/mcp-tools/workflow-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/workflow-tools.ts
index 94bfa29b92..497b1299a2 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/workflow-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/workflow-tools.ts
@@ -943,7 +943,7 @@ export const workflowTools: MCPTool[] = [
// `workflow_validate` tool. Structural sanity check (JSON workflow files);
// a full schema validator is a follow-up.
name: 'workflow_validate',
- description: 'Structurally validate a workflow definition file (JSON) — checks it has a steps/stages/tasks array and that each step names an agent. Use when native Read is wrong because you want a parsed, structured pass/fail with error/warning lists and step/agent counts rather than eyeballing the file. For just reading the file, native Read is fine. (Basic checks today — a full workflow-schema validator is a tracked follow-up.)',
+ description: 'Structurally validate a workflow definition file (JSON) — checks it has a steps/stages/tasks array and that task steps resolve an agent. Use when native Read is wrong because you want a parsed, structured pass/fail with error/warning lists and step/agent counts rather than eyeballing the file. For just reading the file, native Read is fine. (Basic checks today — a full workflow-schema validator is a tracked follow-up.)',
category: 'workflow',
inputSchema: {
type: 'object',
@@ -980,9 +980,15 @@ export const workflowTools: MCPTool[] = [
const agentSet = new Set<string>();
steps.forEach((s, i) => {
const step = (s ?? {}) as Record<string, unknown>;
- const a = (step.agent ?? step.agentType ?? step.agent_type) as string | undefined;
- if (a) agentSet.add(String(a));
- else warnings.push({ line: i + 1, message: `step ${i + 1} ("${step.name ?? step.id ?? i + 1}") names no agent` });
+ // Match workflow_execute: control steps do not dispatch agents,
+ // and task steps use config.agentId or the workflow default.
+ const config = step.config as Record<string, unknown> | undefined;
+ const variables = d.variables as Record<string, unknown> | undefined;
+ const a = config?.agentId || variables?.defaultAgentId
+ || step.agent || step.agentType || step.agent_type;
+ const needsAgent = !['wait', 'condition', 'parallel', 'loop'].includes(String(step.type));
+ if (needsAgent && a) agentSet.add(String(a));
+ else if (needsAgent) warnings.push({ line: i + 1, message: `step ${i + 1} ("${step.name ?? step.id ?? i + 1}") names no agent` });
});
agents = agentSet.size;
}