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(autopilot): reject invalid task sources (#2838)

Dragan Spiridonov872ca80a5131
diff --git a/v3/@claude-flow/cli/__tests__/autopilot-task-sources.test.ts b/v3/@claude-flow/cli/__tests__/autopilot-task-sources.test.ts
new file mode 100644
index 0000000000..9024bd6f53
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/autopilot-task-sources.test.ts
@@ -0,0 +1,45 @@
+import { describe, expect, it } from 'vitest';
+import {
+ validateConfiguredTaskSources,
+ validateTaskSources,
+} from '../src/autopilot-state.js';
+
+describe('autopilot task-source validation', () => {
+ it('keeps recovery defaults for absent persisted state', () => {
+ expect(validateTaskSources(undefined)).toEqual([
+ 'team-tasks',
+ 'swarm-tasks',
+ 'file-checklist',
+ ]);
+ });
+
+ it('rejects an unsupported explicit source instead of enabling defaults', () => {
+ expect(validateConfiguredTaskSources(['issues'])).toEqual({
+ valid: false,
+ invalidSources: ['issues'],
+ reason: 'Unsupported task source(s): issues',
+ });
+ });
+
+ it('rejects a mixed configuration instead of silently dropping invalid entries', () => {
+ expect(validateConfiguredTaskSources(['swarm-tasks', 'issues'])).toEqual({
+ valid: false,
+ invalidSources: ['issues'],
+ reason: 'Unsupported task source(s): issues',
+ });
+ });
+
+ it('normalizes and deduplicates valid explicit sources', () => {
+ expect(validateConfiguredTaskSources([' swarm-tasks ', 'file-checklist', 'swarm-tasks'])).toEqual({
+ valid: true,
+ sources: ['swarm-tasks', 'file-checklist'],
+ });
+ });
+
+ it('rejects an empty explicit source list', () => {
+ expect(validateConfiguredTaskSources([])).toMatchObject({
+ valid: false,
+ reason: 'At least one task source is required',
+ });
+ });
+});
diff --git a/v3/@claude-flow/cli/src/autopilot-state.ts b/v3/@claude-flow/cli/src/autopilot-state.ts
index e193d20fa1..d9ec7e6924 100644
--- a/v3/@claude-flow/cli/src/autopilot-state.ts
+++ b/v3/@claude-flow/cli/src/autopilot-state.ts
@@ -116,6 +116,29 @@ export function validateTaskSources(sources: unknown): string[] {
return valid.length > 0 ? valid : defaults;
}
+export type TaskSourceValidation =
+ | { valid: true; sources: string[] }
+ | { valid: false; invalidSources: string[]; reason: string };
+
+/** Strictly validate user-supplied task sources without enabling defaults. */
+export function validateConfiguredTaskSources(sources: unknown): TaskSourceValidation {
+ if (!Array.isArray(sources) || sources.length === 0) {
+ return { valid: false, invalidSources: [], reason: 'At least one task source is required' };
+ }
+
+ const normalized = sources.map(source => typeof source === 'string' ? source.trim() : String(source));
+ const invalidSources = normalized.filter(source => !VALID_TASK_SOURCES.has(source));
+ if (invalidSources.length > 0) {
+ return {
+ valid: false,
+ invalidSources,
+ reason: `Unsupported task source(s): ${invalidSources.join(', ')}`,
+ };
+ }
+
+ return { valid: true, sources: [...new Set(normalized)] };
+}
+
// ── State Management ──────────────────────────────────────────
export function getDefaultState(): AutopilotState {
diff --git a/v3/@claude-flow/cli/src/commands/autopilot.ts b/v3/@claude-flow/cli/src/commands/autopilot.ts
index 15d8d11b44..345cab48ff 100644
--- a/v3/@claude-flow/cli/src/commands/autopilot.ts
+++ b/v3/@claude-flow/cli/src/commands/autopilot.ts
@@ -10,7 +10,7 @@ import { output } from '../output.js';
import {
loadState, saveState, appendLog, loadLog, discoverTasks,
getProgress, calculateReward, tryLoadLearning, validateNumber,
- validateTaskSources, LOG_FILE,
+ validateConfiguredTaskSources, VALID_TASK_SOURCES, LOG_FILE,
} from '../autopilot-state.js';
import { getCheckpointGate, CheckpointGate } from '../services/checkpoint-gate.js';
@@ -209,7 +209,7 @@ const configCommand: Command = {
options: [
{ name: 'max-iterations', type: 'string', description: 'Max re-engagement iterations (1-1000)' },
{ name: 'timeout', type: 'string', description: 'Timeout in minutes (1-1440)' },
- { name: 'task-sources', type: 'string', description: 'Comma-separated task sources' },
+ { name: 'task-sources', type: 'string', description: `Comma-separated task sources: ${[...VALID_TASK_SOURCES].join(', ')}` },
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
const state = loadState();
@@ -219,7 +219,14 @@ const configCommand: Command = {
if (maxIter) state.maxIterations = validateNumber(maxIter, 1, 1000, state.maxIterations);
if (timeout) state.timeoutMinutes = validateNumber(timeout, 1, 1440, state.timeoutMinutes);
- if (sources) state.taskSources = validateTaskSources(sources.split(',').map(s => s.trim()).filter(Boolean));
+ if (sources !== undefined) {
+ const validation = validateConfiguredTaskSources(sources.split(',').map(s => s.trim()).filter(Boolean));
+ if (!validation.valid) {
+ output.printError(`${validation.reason}. Valid sources: ${[...VALID_TASK_SOURCES].join(', ')}`);
+ return { success: false, exitCode: 1 };
+ }
+ state.taskSources = validation.sources;
+ }
saveState(state);
appendLog({ ts: Date.now(), event: 'config-updated', maxIterations: state.maxIterations, timeoutMinutes: state.timeoutMinutes, taskSources: state.taskSources });
diff --git a/v3/@claude-flow/cli/src/mcp-tools/autopilot-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/autopilot-tools.ts
index 60aa186804..b7ff5e54ca 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/autopilot-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/autopilot-tools.ts
@@ -13,7 +13,7 @@ import { validateText } from './validate-input.js';
import {
loadState, saveState, appendLog, loadLog, discoverTasks,
isTerminal, tryLoadLearning,
- validateNumber, validateTaskSources,
+ validateNumber, validateConfiguredTaskSources,
VALID_TASK_SOURCES,
} from '../autopilot-state.js';
@@ -84,7 +84,12 @@ const autopilotConfig: MCPTool = {
properties: {
maxIterations: { type: 'number', description: 'Max re-engagement iterations (1-1000)' },
timeoutMinutes: { type: 'number', description: 'Timeout in minutes (1-1440)' },
- taskSources: { type: 'array', items: { type: 'string' }, description: `Task sources: ${[...VALID_TASK_SOURCES].join(', ')}` },
+ taskSources: {
+ type: 'array',
+ minItems: 1,
+ items: { type: 'string', enum: [...VALID_TASK_SOURCES] },
+ description: `Task sources: ${[...VALID_TASK_SOURCES].join(', ')}`,
+ },
},
},
handler: async (params: Record<string, unknown>) => {
@@ -96,7 +101,17 @@ const autopilotConfig: MCPTool = {
state.timeoutMinutes = validateNumber(params.timeoutMinutes, 1, 1440, state.timeoutMinutes);
}
if (params.taskSources !== undefined) {
- state.taskSources = validateTaskSources(params.taskSources);
+ const validation = validateConfiguredTaskSources(params.taskSources);
+ if (!validation.valid) {
+ return {
+ content: [{ type: 'text' as const, text: JSON.stringify({
+ error: validation.reason,
+ validSources: [...VALID_TASK_SOURCES],
+ }) }],
+ isError: true,
+ };
+ }
+ state.taskSources = validation.sources;
}
saveState(state);
return ok({ maxIterations: state.maxIterations, timeoutMinutes: state.timeoutMinutes, taskSources: state.taskSources });