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): show registered agents in status agents

Devesh Maheshwari33d063de4839
diff --git a/v3/@claude-flow/cli/__tests__/status-agents.test.ts b/v3/@claude-flow/cli/__tests__/status-agents.test.ts
new file mode 100644
index 0000000000..dbc4674a53
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/status-agents.test.ts
@@ -0,0 +1,93 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { agentTools } from '../src/mcp-tools/agent-tools.js';
+import { callMCPTool, MCPClientError } from '../src/mcp-client.js';
+import { output } from '../src/output.js';
+import { statusCommand } from '../src/commands/status.js';
+
+// Keep the real agent_list handler and file stores; bypass unrelated MCP tools.
+vi.mock('../src/mcp-client.js', () => ({
+ callMCPTool: vi.fn(),
+ MCPClientError: class MCPClientError extends Error {},
+}));
+
+const action = statusCommand.subcommands!.find(command => command.name === 'agents')!.action!;
+const listAgents = agentTools.find(tool => tool.name === 'agent_list')!;
+const agent = (agentId: string, status = 'idle') => ({
+ agentId, agentType: 'coder', status, health: 0.85, taskCount: 3,
+ createdAt: '2026-01-01T00:00:00.000Z', config: {},
+});
+
+describe('status agents with the persisted agent registry', () => {
+ let dir: string;
+ const run = (format = 'text') => action({
+ args: [], flags: { _: [], format }, cwd: dir, interactive: false,
+ });
+
+ beforeEach(() => {
+ dir = mkdtempSync(join(tmpdir(), 'ruflo-status-agents-'));
+ vi.stubEnv('CLAUDE_FLOW_CWD', dir);
+ mkdirSync(join(dir, '.claude-flow', 'agents'), { recursive: true });
+ writeFileSync(join(dir, '.claude-flow', 'agents', 'store.json'), JSON.stringify({
+ version: '3.0.0', agents: {
+ idle: agent('idle-coder'), busy: agent('busy-coder', 'busy'),
+ ended: agent('ended-coder', 'terminated'),
+ },
+ }));
+ writeFileSync(join(dir, '.claude-flow', 'agents.json'), JSON.stringify({
+ agents: { hive: { ...agent('hive-reviewer'), agentType: 'reviewer' } },
+ }));
+ vi.mocked(callMCPTool).mockImplementation(async (name, input) => {
+ if (name !== 'agent_list') throw new Error(`Unexpected tool: ${name}`);
+ return listAgents.handler(input ?? {});
+ });
+ vi.spyOn(output, 'writeln').mockImplementation(() => {});
+ vi.spyOn(output, 'printTable').mockImplementation(() => {});
+ vi.spyOn(output, 'printJson').mockImplementation(() => {});
+ vi.spyOn(output, 'printInfo').mockImplementation(() => {});
+ vi.spyOn(output, 'printError').mockImplementation(() => {});
+ });
+
+ afterEach(() => {
+ vi.restoreAllMocks();
+ vi.resetAllMocks();
+ vi.unstubAllEnvs();
+ rmSync(dir, { recursive: true, force: true });
+ });
+
+ it('lists idle, busy and hive agents in JSON, excluding terminated agents', async () => {
+ const expected = await listAgents.handler({});
+ expect(expected).toMatchObject({ total: 3 });
+ expect(await run('json')).toEqual({ success: true, data: expected });
+ expect(output.printJson).toHaveBeenCalledWith(expected);
+ });
+
+ it('renders IDs, types and recorded counts without requiring unavailable metrics', async () => {
+ expect(await run()).toMatchObject({ success: true });
+ expect(output.printTable).toHaveBeenCalledOnce();
+ const table = vi.mocked(output.printTable).mock.calls[0][0];
+ expect(table.data).toEqual(expect.arrayContaining([
+ expect.objectContaining({ id: 'idle-coder', type: 'coder', tasks: 3, health: 0.85 }),
+ expect.objectContaining({ id: 'busy-coder', type: 'coder', status: expect.stringContaining('busy') }),
+ expect.objectContaining({ id: 'hive-reviewer', type: 'reviewer' }),
+ ]));
+ expect(table.data).toHaveLength(3);
+ expect(output.printError).not.toHaveBeenCalled();
+ });
+
+ it('reports an empty registry without a table', async () => {
+ rmSync(join(dir, '.claude-flow'), { recursive: true });
+ expect(await run()).toMatchObject({ success: true, data: { agents: [], total: 0 } });
+ expect(output.printInfo).toHaveBeenCalledWith('No agents registered');
+ expect(output.printTable).not.toHaveBeenCalled();
+ });
+
+ it('reports tool failures instead of claiming an empty registry', async () => {
+ vi.mocked(callMCPTool).mockRejectedValueOnce(new MCPClientError('unavailable', 'agent_list'));
+ expect(await run()).toEqual({ success: false, exitCode: 1 });
+ expect(output.printError).toHaveBeenCalledWith('Failed to get agent status: unavailable');
+ expect(output.printInfo).not.toHaveBeenCalled();
+ });
+});
diff --git a/v3/@claude-flow/cli/src/commands/status.ts b/v3/@claude-flow/cli/src/commands/status.ts
index 586818200d..6918d989a7 100644
--- a/v3/@claude-flow/cli/src/commands/status.ts
+++ b/v3/@claude-flow/cli/src/commands/status.ts
@@ -521,14 +521,13 @@ const agentsCommand: Command = {
try {
const result = await callMCPTool<{
agents: Array<{
- id: string;
- type: string;
+ agentId: string;
+ agentType: string;
status: string;
- task?: string;
- uptime: number;
- metrics: { tasksCompleted: number; successRate: number };
+ health: number;
+ taskCount: number;
}>;
- }>('agent_list', { includeMetrics: true, status: 'all' });
+ }>('agent_list', {});
if (ctx.flags.format === 'json') {
output.printJson(result);
@@ -540,7 +539,7 @@ const agentsCommand: Command = {
output.writeln();
if (result.agents.length === 0) {
- output.printInfo('No agents running');
+ output.printInfo('No agents registered');
return { success: true, data: result };
}
@@ -549,17 +548,15 @@ const agentsCommand: Command = {
{ key: 'id', header: 'ID', width: 20 },
{ key: 'type', header: 'Type', width: 12 },
{ key: 'status', header: 'Status', width: 10 },
- { key: 'task', header: 'Current Task', width: 25 },
- { key: 'uptime', header: 'Uptime', width: 12 },
- { key: 'success', header: 'Success', width: 8 }
+ { key: 'tasks', header: 'Tasks', width: 8 },
+ { key: 'health', header: 'Health', width: 8 }
],
data: result.agents.map(a => ({
- id: a.id,
- type: a.type,
+ id: a.agentId,
+ type: a.agentType,
status: formatHealth(a.status),
- task: a.task || '-',
- uptime: formatUptime(a.uptime),
- success: `${(a.metrics.successRate * 100).toFixed(0)}%`
+ tasks: a.taskCount,
+ health: a.health
}))
});