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(agent): make agent list --all and --type filter as documented (#4302)

kevin0dfaafe8871f
diff --git a/v3/@claude-flow/cli/__tests__/agent-list-filters.test.ts b/v3/@claude-flow/cli/__tests__/agent-list-filters.test.ts
new file mode 100644
index 0000000000..aa6d2bef4a
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/agent-list-filters.test.ts
@@ -0,0 +1,77 @@
+/**
+ * `agent list --all` and `agent list --type <t>`.
+ *
+ * --all sent `status: 'all'`, which agent_list treats as a literal status, so
+ * it filtered every agent out and printed "No agents found". --type sent
+ * `agentType`, which agent_list never read, so it listed every type.
+ */
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { agentTools } from '../src/mcp-tools/agent-tools.js';
+import { agentCommand } from '../src/commands/agent.js';
+import type { CommandContext } from '../src/types.js';
+
+const tool = (name: string) => {
+ const t = agentTools.find(t => t.name === name);
+ if (!t) throw new Error(`MCP tool not registered: ${name}`);
+ return t;
+};
+
+const listCommand = agentCommand.subcommands!.find(c => c.name === 'list')!;
+
+async function runList(flags: Record<string, unknown>): Promise<Array<{ agentId: string; agentType: string; status: string }>> {
+ const ctx = { args: [], flags: { format: 'json', ...flags }, cwd: process.cwd(), interactive: false } as unknown as CommandContext;
+ const result = await listCommand.action!(ctx);
+ expect(result?.success).toBe(true);
+ return (result!.data as { agents: Array<{ agentId: string; agentType: string; status: string }> }).agents;
+}
+
+describe('agent list filters', () => {
+ let dir: string;
+ let prevCwd: string | undefined;
+ let coder: string;
+ let tester: string;
+ let stopped: string;
+
+ beforeEach(async () => {
+ dir = mkdtempSync(join(tmpdir(), 'ruflo-agent-list-'));
+ prevCwd = process.env.CLAUDE_FLOW_CWD;
+ process.env.CLAUDE_FLOW_CWD = dir;
+
+ const spawn = tool('agent_spawn').handler;
+ coder = (await spawn({ agentType: 'coder' }) as { agentId: string }).agentId;
+ tester = (await spawn({ agentType: 'tester' }) as { agentId: string }).agentId;
+ stopped = (await spawn({ agentType: 'coder' }) as { agentId: string }).agentId;
+ await tool('agent_terminate').handler({ agentId: stopped });
+ });
+
+ afterEach(() => {
+ if (prevCwd === undefined) delete process.env.CLAUDE_FLOW_CWD;
+ else process.env.CLAUDE_FLOW_CWD = prevCwd;
+ rmSync(dir, { recursive: true, force: true });
+ });
+
+ it('agent_list filters by agentType', async () => {
+ const result = await tool('agent_list').handler({ agentType: 'tester' }) as { agents: Array<{ agentId: string }> };
+ expect(result.agents.map(a => a.agentId)).toEqual([tester]);
+ });
+
+ it('agent list without flags hides terminated agents', async () => {
+ const ids = (await runList({})).map(a => a.agentId).sort();
+ expect(ids).toEqual([coder, tester].sort());
+ });
+
+ it('agent list --all includes terminated agents', async () => {
+ const ids = (await runList({ all: true })).map(a => a.agentId).sort();
+ expect(ids).toEqual([coder, tester, stopped].sort());
+ });
+
+ it('agent list --type only lists that type', async () => {
+ const agents = await runList({ type: 'coder' });
+ expect(agents.map(a => a.agentId)).toEqual([coder]);
+ const all = await runList({ type: 'coder', all: true });
+ expect(all.map(a => a.agentId).sort()).toEqual([coder, stopped].sort());
+ });
+});
diff --git a/v3/@claude-flow/cli/src/commands/agent.ts b/v3/@claude-flow/cli/src/commands/agent.ts
index f391aeddb2..ac87de8441 100644
--- a/v3/@claude-flow/cli/src/commands/agent.ts
+++ b/v3/@claude-flow/cli/src/commands/agent.ts
@@ -246,7 +246,9 @@ const listCommand: Command = {
}>;
total: number;
}>('agent_list', {
- status: ctx.flags.all ? 'all' : ctx.flags.status || undefined,
+ // agent_list has no 'all' status: --all means "don't hide terminated agents".
+ status: ctx.flags.status || undefined,
+ includeTerminated: ctx.flags.all ? true : undefined,
agentType: ctx.flags.type || undefined,
limit: 100,
});
diff --git a/v3/@claude-flow/cli/src/mcp-tools/agent-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/agent-tools.ts
index 0d7ebd5e2c..e25d7826e0 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/agent-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/agent-tools.ts
@@ -635,6 +635,7 @@ export const agentTools: MCPTool[] = [
properties: {
status: { type: 'string', description: 'Filter by status' },
domain: { type: 'string', description: 'Filter by domain' },
+ agentType: { type: 'string', description: 'Filter by agent type' },
includeTerminated: { type: 'boolean', description: 'Include terminated agents' },
},
},
@@ -647,6 +648,10 @@ export const agentTools: MCPTool[] = [
const v = validateIdentifier(input.domain, 'domain');
if (!v.valid) return { agents: [], total: 0, error: `Input validation failed: ${v.error}` };
}
+ if (input.agentType) {
+ const v = validateIdentifier(input.agentType, 'agentType');
+ if (!v.valid) return { agents: [], total: 0, error: `Input validation failed: ${v.error}` };
+ }
let agents = Object.values(loadAllAgents()); // #1916: includes hive-mind-spawned workers
@@ -662,6 +667,11 @@ export const agentTools: MCPTool[] = [
agents = agents.filter(a => a.domain === input.domain);
}
+ // Filter by agent type
+ if (input.agentType) {
+ agents = agents.filter(a => a.agentType === input.agentType);
+ }
+
return {
agents: agents.map(a => ({
agentId: a.agentId,
@@ -677,6 +687,7 @@ export const agentTools: MCPTool[] = [
filters: {
status: input.status,
domain: input.domain,
+ agentType: input.agentType,
includeTerminated: input.includeTerminated,
},
};