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): declare numeric configuration limits

Rudy Celeklib8fc9d9b9dea
diff --git a/v3/@claude-flow/cli/__tests__/autopilot-task-sources.test.ts b/v3/@claude-flow/cli/__tests__/autopilot-task-sources.test.ts
index 062858afe3..37e18339f5 100644
--- a/v3/@claude-flow/cli/__tests__/autopilot-task-sources.test.ts
+++ b/v3/@claude-flow/cli/__tests__/autopilot-task-sources.test.ts
@@ -112,4 +112,59 @@ describe('autopilot task-source validation', () => {
rmSync(projectRoot, { recursive: true, force: true });
}
});
+
+ it.each([
+ { flags: ['--max-iterations', '77', '--timeout', '180'], maxIterations: 77, timeoutMinutes: 180 },
+ { flags: ['--max-iterations=77', '--timeout=180'], maxIterations: 77, timeoutMinutes: 180 },
+ { flags: ['--max-iterations=2000', '--timeout=2000'], maxIterations: 1000, timeoutMinutes: 1440 },
+ { flags: ['--max-iterations=invalid', '--timeout=invalid'], maxIterations: 50, timeoutMinutes: 240 },
+ ])('persists numeric limits with existing bounds and fallback: $flags', async ({ flags, maxIterations, timeoutMinutes }) => {
+ const parser = new CommandParser();
+ parser.registerCommand(autopilotCommand);
+ const config = autopilotCommand.subcommands!.find(command => command.name === 'config')!;
+ expect(config.options!.find(option => option.name === 'max-iterations')!.type).toBe('number');
+ expect(config.options!.find(option => option.name === 'timeout')!.type).toBe('number');
+ const parsed = parser.parse(['autopilot', 'config', ...flags, '--task-sources', 'swarm-tasks']);
+ expect(parser.validateFlags(parsed.flags, config)).toEqual([]);
+ if (flags[0] !== '--max-iterations=invalid') {
+ expect(typeof parsed.flags.maxIterations).toBe('number');
+ expect(typeof parsed.flags.timeout).toBe('number');
+ }
+
+ const projectRoot = mkdtempSync(join(tmpdir(), 'ruflo-autopilot-limits-'));
+ const previousCwd = process.cwd();
+ try {
+ process.chdir(projectRoot);
+ const result = await config.action!({ args: parsed.positional, flags: parsed.flags, cwd: projectRoot, interactive: false });
+ expect(result).toMatchObject({ success: true });
+ const state = JSON.parse(readFileSync(STATE_FILE, 'utf8'));
+ expect(state).toMatchObject({ maxIterations, timeoutMinutes, taskSources: ['swarm-tasks'] });
+ expect(typeof state.maxIterations).toBe('number');
+ expect(typeof state.timeoutMinutes).toBe('number');
+ } finally {
+ process.chdir(previousCwd);
+ rmSync(projectRoot, { recursive: true, force: true });
+ }
+ });
+
+ it.each(['false', '001'])('rejects the literal string task source %s without writing state', async source => {
+ const parser = new CommandParser();
+ parser.registerCommand(autopilotCommand);
+ const parsed = parser.parse(['autopilot', 'config', `--task-sources=${source}`, '--max-iterations=77']);
+ expect(parsed.flags.taskSources).toBe(source);
+ const config = autopilotCommand.subcommands!.find(command => command.name === 'config')!;
+ expect(parser.validateFlags(parsed.flags, config)).toEqual([]);
+ const projectRoot = mkdtempSync(join(tmpdir(), 'ruflo-autopilot-literal-'));
+ const previousCwd = process.cwd();
+ try {
+ process.chdir(projectRoot);
+ const result = await config.action!({ args: parsed.positional, flags: parsed.flags, cwd: projectRoot, interactive: false });
+ expect(result).toMatchObject({ success: false, exitCode: 1 });
+ expect(existsSync(STATE_FILE)).toBe(false);
+ } finally {
+ process.chdir(previousCwd);
+ rmSync(projectRoot, { recursive: true, force: true });
+ }
+ });
+
});
diff --git a/v3/@claude-flow/cli/src/commands/autopilot.ts b/v3/@claude-flow/cli/src/commands/autopilot.ts
index 72d768069a..84f341223c 100644
--- a/v3/@claude-flow/cli/src/commands/autopilot.ts
+++ b/v3/@claude-flow/cli/src/commands/autopilot.ts
@@ -207,8 +207,8 @@ const configCommand: Command = {
name: 'config',
description: 'Configure max iterations, timeout, and task sources',
options: [
- { name: 'max-iterations', type: 'string', description: 'Max re-engagement iterations (1-1000)' },
- { name: 'timeout', type: 'string', description: 'Timeout in minutes (1-1440)' },
+ { name: 'max-iterations', type: 'number', description: 'Max re-engagement iterations (1-1000)' },
+ { name: 'timeout', type: 'number', description: 'Timeout in minutes (1-1440)' },
{ name: 'task-sources', type: 'string', description: `Comma-separated task sources: ${[...VALID_TASK_SOURCES].join(', ')}` },
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
@@ -216,7 +216,7 @@ const configCommand: Command = {
// CommandParser canonicalizes kebab-case flags to camelCase.
// Retain kebab-case reads for direct/legacy action callers.
const maxIter = (ctx.flags?.maxIterations ?? ctx.flags?.['max-iterations']) as string | number | undefined;
- const timeout = ctx.flags?.timeout as string | undefined;
+ const timeout = ctx.flags?.timeout as string | number | undefined;
const sources = (ctx.flags?.taskSources ?? ctx.flags?.['task-sources']) as string | undefined;
if (maxIter) state.maxIterations = validateNumber(maxIter, 1, 1000, state.maxIterations);