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(cli): report unknown agent/task ids and value-less options as errors

martinvlad3add332a32b9
diff --git a/v3/@claude-flow/cli/__tests__/cli-not-found-and-valueless-flags.test.ts b/v3/@claude-flow/cli/__tests__/cli-not-found-and-valueless-flags.test.ts
new file mode 100644
index 0000000000..08c9563258
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/cli-not-found-and-valueless-flags.test.ts
@@ -0,0 +1,71 @@
+/**
+ * Two CLI error paths that reported nonsense instead of an error:
+ * - `agent status <unknown>` / `task status <unknown>`: the MCP tool answers
+ * { status: 'not_found' }, which was rendered as "Agent: undefined",
+ * "Invalid Date", "undefined%" and exited 0.
+ * - A value-taking option with no value (`hooks route --task`) parsed as boolean
+ * `true`, and commands then crashed on it ("task.trim is not a function").
+ */
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+vi.mock('../src/mcp-client.js', () => ({
+ callMCPTool: vi.fn(async (tool: string, input: Record<string, unknown>) => {
+ if (tool === 'agent_status') return { agentId: input.agentId, status: 'not_found' };
+ if (tool === 'task_status') return { taskId: input.taskId, status: 'not_found' };
+ throw new Error(`unexpected tool ${tool}`);
+ }),
+ MCPClientError: class extends Error {},
+}));
+
+import { agentCommand } from '../src/commands/agent.js';
+import { taskCommand } from '../src/commands/task.js';
+import { CommandParser } from '../src/parser.js';
+import type { Command, CommandContext } from '../src/types.js';
+
+const ctxFor = (id: string): CommandContext =>
+ ({ args: [id], flags: { _: [] }, cwd: '/test', interactive: false }) as unknown as CommandContext;
+
+describe('status of an unknown id', () => {
+ beforeEach(() => { vi.spyOn(console, 'log').mockImplementation(() => {}); vi.spyOn(console, 'error').mockImplementation(() => {}); });
+
+ it('agent status reports not found and exits 1', async () => {
+ const status = agentCommand.subcommands!.find((c) => c.name === 'status')!;
+ const result = await status.action!(ctxFor('doesnotexist'));
+ expect(result).toMatchObject({ success: false, exitCode: 1 });
+ });
+
+ it('task status reports not found and exits 1', async () => {
+ const status = taskCommand.subcommands!.find((c) => c.name === 'status')!;
+ const result = await status.action!(ctxFor('nope'));
+ expect(result).toMatchObject({ success: false, exitCode: 1 });
+ });
+});
+
+describe('value-taking option given without a value', () => {
+ const cmd: Command = {
+ name: 'route', description: 'r',
+ options: [
+ { name: 'task', short: 't', type: 'string', description: 'Task' },
+ { name: 'top', type: 'number', description: 'Top K' },
+ { name: 'explore', type: 'boolean', description: 'Explore' },
+ ],
+ };
+ const parser = new CommandParser({ allowUnknownFlags: true });
+ parser.registerCommand(cmd);
+
+ it.each([[['route', '--task']], [['route', '-t']], [['route', '--task', '--explore']], [['route', '--top']]])(
+ 'rejects %j with a clear message',
+ (argv) => {
+ const parsed = parser.parse(argv as string[]);
+ const errors = parser.validateFlags(parsed.flags, cmd);
+ expect(errors.some((e) => /needs a value/.test(e))).toBe(true);
+ },
+ );
+
+ it('still accepts real values and bare booleans', () => {
+ for (const argv of [['route', '--task', 'fix bug'], ['route', '--task=x', '--explore'], ['route', '--top', '3']]) {
+ const parsed = parser.parse(argv);
+ expect(parser.validateFlags(parsed.flags, cmd)).toEqual([]);
+ }
+ });
+});
diff --git a/v3/@claude-flow/cli/src/commands/agent.ts b/v3/@claude-flow/cli/src/commands/agent.ts
index 4badfe2e72..99168d6e09 100644
--- a/v3/@claude-flow/cli/src/commands/agent.ts
+++ b/v3/@claude-flow/cli/src/commands/agent.ts
@@ -349,6 +349,18 @@ const statusCommand: Command = {
includeHistory: false,
});
+ // The MCP tool answers an unknown id with status "not_found" and no other fields.
+ // Rendering that as a record printed "Agent: undefined", "Invalid Date" and
+ // "undefined%" and exited 0, so scripts and agents took it as success.
+ if (((status as { status?: string }).status) === 'not_found') {
+ if (ctx.flags.format === 'json') {
+ output.printJson(status);
+ } else {
+ output.printError(`Agent not found: ${agentId}`);
+ }
+ return { success: false, exitCode: 1 };
+ }
+
if (ctx.flags.format === 'json') {
output.printJson(status);
return { success: true, data: status };
diff --git a/v3/@claude-flow/cli/src/commands/task.ts b/v3/@claude-flow/cli/src/commands/task.ts
index 4c231035cc..ccdf546e15 100644
--- a/v3/@claude-flow/cli/src/commands/task.ts
+++ b/v3/@claude-flow/cli/src/commands/task.ts
@@ -410,6 +410,18 @@ const statusCommand: Command = {
includeMetrics: true
});
+ // The MCP tool answers an unknown id with status "not_found" and no other fields.
+ // Rendering that as a record printed "Task: undefined", "Invalid Date" and
+ // "undefined%" and exited 0, so scripts and agents took it as success.
+ if (((result as { status?: string }).status) === 'not_found') {
+ if (ctx.flags.format === 'json') {
+ output.printJson(result);
+ } else {
+ output.printError(`Task not found: ${taskId}`);
+ }
+ return { success: false, exitCode: 1 };
+ }
+
if (ctx.flags.format === 'json') {
output.printJson(result);
return { success: true, data: result };
diff --git a/v3/@claude-flow/cli/src/parser.ts b/v3/@claude-flow/cli/src/parser.ts
index d7bdabe6ca..026d18034e 100644
--- a/v3/@claude-flow/cli/src/parser.ts
+++ b/v3/@claude-flow/cli/src/parser.ts
@@ -632,6 +632,14 @@ export class CommandParser {
errors.push(`Required option missing: --${opt.name}`);
}
+ // A value-taking option given with nothing after it (`--task`, `--key` at the end, or
+ // followed by another flag) is parsed as boolean `true`. Commands then treat `true` as
+ // the value: `hooks route --task` crashed with "task.trim is not a function" and
+ // `memory retrieve --key` looked up the key "true". Report it instead.
+ if ((opt.type === 'string' || opt.type === 'number') && flags[key] === true) {
+ errors.push(`Option --${opt.name} needs a value`);
+ }
+
// Check choices
if (opt.choices && flags[key] !== undefined) {
const value = String(flags[key]);