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(hooks): disclose synthetic worker-detect dispatches (#4576)

ordinary beinga7313c3de590
diff --git a/v3/@claude-flow/cli/__tests__/hooks-worker-detect-synthetic-4549.test.ts b/v3/@claude-flow/cli/__tests__/hooks-worker-detect-synthetic-4549.test.ts
new file mode 100644
index 0000000000..64703b54ce
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/hooks-worker-detect-synthetic-4549.test.ts
@@ -0,0 +1,50 @@
+/**
+ * #4549 automation scan: hooks_worker-detect's autoDispatch created a worker
+ * record and marked it completed after a hardcoded 1.5 s timer without running
+ * anything, unlike the sibling hooks_worker-dispatch path that reports
+ * 'synthetic-completed' honestly.
+ */
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { hooksWorkerDetect, hooksWorkerStatus } from '../src/mcp-tools/hooks-tools.js';
+
+afterEach(() => {
+ vi.useRealTimers();
+});
+
+describe('hooks_worker-detect synthetic dispatch disclosure (#4549)', () => {
+ it('marks auto-dispatched records and responses as synthetic', async () => {
+ vi.useFakeTimers();
+
+ const result = await hooksWorkerDetect.handler({
+ prompt: 'run a security audit for vulnerabilities',
+ autoDispatch: true,
+ minConfidence: 0,
+ }) as {
+ autoDispatched: boolean;
+ autoDispatchStatus: string;
+ note: string;
+ workerIds: string[];
+ };
+
+ expect(result.autoDispatched).toBe(true);
+ expect(result.autoDispatchStatus).toBe('synthetic-completed');
+ expect(result.note).toMatch(/no executor ran/i);
+ expect(result.workerIds.length).toBeGreaterThan(0);
+
+ const before = await hooksWorkerStatus.handler({ workerId: result.workerIds[0] }) as {
+ worker: { status: string; synthetic?: boolean; note?: string };
+ };
+ expect(before.worker.status).toBe('running');
+ expect(before.worker.synthetic).toBe(true);
+ expect(before.worker.note).toMatch(/no executor ran/i);
+
+ await vi.advanceTimersByTimeAsync(1500);
+
+ const after = await hooksWorkerStatus.handler({ workerId: result.workerIds[0] }) as {
+ worker: { status: string; phase: string; synthetic?: boolean };
+ };
+ expect(after.worker.status).toBe('completed');
+ expect(after.worker.phase).toBe('synthetic-completed');
+ expect(after.worker.synthetic).toBe(true);
+ });
+});
diff --git a/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts
index 1aeb6ec5f7..6c7ca85428 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/hooks-tools.ts
@@ -4829,6 +4829,10 @@ const activeWorkers: Map<string, {
phase: string;
startedAt: Date;
completedAt?: Date;
+ /** True when this record was created by the in-process detect path, not a real executor. */
+ synthetic?: boolean;
+ /** Why the worker record is synthetic, propagated to worker-status/list. */
+ note?: string;
}> = new Map();
let workerIdCounter = 0;
@@ -5163,6 +5167,12 @@ export const hooksWorkerDetect: MCPTool = {
progress: 0,
phase: 'initializing',
startedAt: new Date(),
+ // hooks_worker-detect has no executor. Unlike its sibling
+ // hooks_worker-dispatch, it used to silently fabricate a
+ // completed worker after 1.5s. Mark the record and response so
+ // callers cannot treat it as real analysis (#4549 automation scan).
+ synthetic: true,
+ note: 'No executor ran: hooks_worker-detect only records a synthetic worker. Use hooks_worker-dispatch with the daemon for real work.',
});
dispatched.push(workerId);
@@ -5171,13 +5181,15 @@ export const hooksWorkerDetect: MCPTool = {
const w = activeWorkers.get(workerId);
if (w) {
w.progress = 100;
- w.phase = 'completed';
+ w.phase = 'synthetic-completed';
w.status = 'completed';
w.completedAt = new Date();
}
}, 1500);
}
result.autoDispatched = true;
+ result.autoDispatchStatus = 'synthetic-completed';
+ result.note = 'No executor ran: these worker records are synthetic placeholders. Use hooks_worker-dispatch with the daemon for real work.';
result.workerIds = dispatched;
}
}