🌊 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
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(hooks): worker dispatch prints the status the tool returned (#4196)
Rudy Celekli02b0ea57a92f
diff --git a/v3/@claude-flow/cli/__tests__/hooks-worker-dispatch-status-4196.test.ts b/v3/@claude-flow/cli/__tests__/hooks-worker-dispatch-status-4196.test.tsnew file mode 100644index 0000000000..18ae83decb--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/hooks-worker-dispatch-status-4196.test.ts@@ -0,0 +1,49 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';++const mocks = vi.hoisted(() => ({ call: vi.fn(), table: vi.fn(), warn: vi.fn() }));+vi.mock('../src/mcp-client.js', () => ({ callMCPTool: mocks.call, MCPClientError: class extends Error {} }));+vi.mock('../src/output.js', () => ({+ output: new Proxy({}, {+ get: (_t, prop) => {+ if (prop === 'printTable') return mocks.table;+ if (prop === 'printWarning') return mocks.warn;+ if (prop === 'createSpinner') return () => ({ start() {}, succeed() {}, fail() {}, stop() {} });+ return (value: unknown) => value;+ },+ }),+}));+import { hooksCommand } from '../src/commands/hooks.js';++const worker = hooksCommand.subcommands!.find(c => c.name === 'worker')!;+const dispatch = worker.subcommands!.find(c => c.name === 'dispatch')!;+const run = () => dispatch.action!({ args: [], flags: { trigger: 'document' } } as any);+const toolResult = (status: string, note?: string) => ({+ success: true, workerId: 'worker_1', trigger: 'document', context: 'default', priority: 'normal',+ config: { description: 'd', estimatedDuration: '1m', capabilities: ['a'] }, status, note,+});+const statusCell = () => mocks.table.mock.calls[0][0].data.find((r: { field: string }) => r.field === 'Status').value;++beforeEach(() => { mocks.call.mockReset(); mocks.table.mockReset(); mocks.warn.mockReset(); });++describe('hooks worker dispatch status (#4196)', () => {+ it('does not report "completed" when no daemon ran anything, and shows why', async () => {+ mocks.call.mockResolvedValue(toolResult('no-daemon', 'No worker daemon detected.'));+ await run();+ expect(statusCell()).not.toContain('completed');+ expect(statusCell()).toContain('no-daemon');+ expect(mocks.warn).toHaveBeenCalledWith('No worker daemon detected.');+ });++ it('reports a queued worker as queued', async () => {+ mocks.call.mockResolvedValue(toolResult('queued'));+ await run();+ expect(statusCell()).toContain('queued');+ expect(statusCell()).not.toContain('completed');+ });++ it('still reports a real completed status as completed', async () => {+ mocks.call.mockResolvedValue(toolResult('completed'));+ await run();+ expect(statusCell()).toContain('completed');+ });+});diff --git a/v3/@claude-flow/cli/src/commands/hooks.ts b/v3/@claude-flow/cli/src/commands/hooks.tsindex 037c338a65..b09f4c6fd5 100644--- a/v3/@claude-flow/cli/src/commands/hooks.ts+++ b/v3/@claude-flow/cli/src/commands/hooks.ts@@ -2802,6 +2802,20 @@ const workerListCommand: Command = {}};+// Render the status hooks_worker-dispatch actually returned. Only a status that+// means work finished may read as "completed" (#4196).+function dispatchStatusLabel(status: string): string {+ switch (status) {+ case 'dispatched': return output.highlight('dispatched (background)');+ case 'queued': return output.highlight('queued (daemon)');+ case 'no-daemon': return output.warning('no-daemon (not run)');+ case 'mcp-only': return output.warning('mcp-only (not queued)');+ case 'synthetic-completed': return output.warning('recorded (no work executed)');+ case 'completed': return output.success('completed');+ default: return output.dim(String(status));+ }+}+const workerDispatchCommand: Command = {name: 'dispatch',description: 'Dispatch a background worker for analysis/optimization',@@ -2845,6 +2859,7 @@ const workerDispatchCommand: Command = {capabilities: string[];};status: string;+ note?: string;error?: string;}>('hooks_worker-dispatch', {trigger,@@ -2874,10 +2889,17 @@ const workerDispatchCommand: Command = {{ field: 'Description', value: result.config.description },{ field: 'Est. Duration', value: result.config.estimatedDuration },{ field: 'Capabilities', value: result.config.capabilities.join(', ') },- { field: 'Status', value: result.status === 'dispatched' ? output.highlight('dispatched (background)') : output.success('completed') },+ { field: 'Status', value: dispatchStatusLabel(result.status) },],});+ // The tool says why it could not run the worker (e.g. no daemon); show it+ // rather than letting a recorded-only dispatch read as finished work (#4196).+ if (result.note) {+ output.writeln();+ output.printWarning(result.note);+ }+if (background) {output.writeln();output.writeln(output.dim(`Check status: claude-flow hooks worker status --id ${result.workerId}`));