🌊 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(daemon): honor --max-cpu-load, --min-free-memory and --no-distill (#4349)
nk-batman21f43f584a4fc4
diff --git a/v3/@claude-flow/cli/__tests__/daemon-start-flag-keys.test.ts b/v3/@claude-flow/cli/__tests__/daemon-start-flag-keys.test.tsnew file mode 100644index 0000000000..e784209416--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/daemon-start-flag-keys.test.ts@@ -0,0 +1,56 @@+import { afterEach, describe, expect, it, vi } from 'vitest';+import { mkdtempSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import * as daemonService from '../src/services/worker-daemon.js';+import { CommandParser } from '../src/parser.js';+import { daemonCommand } from '../src/commands/daemon.js';+import type { DaemonConfig } from '../src/services/worker-daemon.js';++const dirs: string[] = [];+const signals = ['SIGTERM', 'SIGINT', 'SIGHUP', 'exit'] as const;+const listeners = new Map(signals.map(signal => [signal, process.listeners(signal)]));+afterEach(() => {+ vi.restoreAllMocks(); vi.unstubAllEnvs();+ for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });+ for (const signal of signals) {+ for (const listener of process.listeners(signal)) {+ if (!listeners.get(signal)!.includes(listener)) process.removeListener(signal, listener);+ }+ }+});++async function runStart(flags: string[]): Promise<Partial<DaemonConfig>> {+ const workspace = mkdtempSync(join(tmpdir(), 'ruflo-daemon-start-flags-')); dirs.push(workspace);+ vi.stubEnv('CLAUDE_FLOW_DAEMON', '1');+ vi.stubEnv('RUFLO_DAEMON_NO_DISTILL', undefined);+ // A daemon that declines to start makes the foreground action return.+ const start = vi.spyOn(daemonService, 'startDaemon')+ .mockResolvedValue({ getStatus: () => ({ running: false }) } as unknown as daemonService.WorkerDaemon);+ const parser = new CommandParser();+ parser.registerCommand(daemonCommand);+ const parsed = parser.parse(['daemon', 'start', '--foreground', '--quiet', '--workspace', workspace, ...flags]);+ const action = daemonCommand.subcommands!.find(command => command.name === 'start')!.action!;+ const result = await action({ args: [], flags: parsed.flags, cwd: workspace, interactive: false });+ expect(result?.success).toBe(true);+ expect(start).toHaveBeenCalledTimes(1);+ return start.mock.calls[0][1] as Partial<DaemonConfig>;+}++describe('daemon start flags through the real command parser', () => {+ it('applies --max-cpu-load and --min-free-memory', async () => {+ const config = await runStart(['--max-cpu-load', '8', '--min-free-memory', '5']);+ expect(config.resourceThresholds).toEqual({ maxCpuLoad: 8, minFreeMemoryPercent: 5 });+ });++ it('applies --no-distill', async () => {+ await runStart(['--no-distill']);+ expect(process.env.RUFLO_DAEMON_NO_DISTILL).toBe('1');+ });++ it('leaves thresholds and distillation alone without the flags', async () => {+ const config = await runStart([]);+ expect(config.resourceThresholds).toBeUndefined();+ expect(process.env.RUFLO_DAEMON_NO_DISTILL).toBeUndefined();+ });+});diff --git a/v3/@claude-flow/cli/src/commands/daemon.ts b/v3/@claude-flow/cli/src/commands/daemon.tsindex 1f950d1656..84a81822cb 100644--- a/v3/@claude-flow/cli/src/commands/daemon.ts+++ b/v3/@claude-flow/cli/src/commands/daemon.ts@@ -59,7 +59,8 @@ const startCommand: Command = {action: async (ctx: CommandContext): Promise<CommandResult> => {const quiet = ctx.flags.quiet as boolean;const foreground = ctx.flags.foreground as boolean;- const noDistill = ctx.flags['no-distill'] as boolean | undefined;+ // The CLI parser stores `--no-distill` as `distill: false`.+ const noDistill = ctx.flags['no-distill'] === true || ctx.flags.distill === false;// ADR-174 M3: honored by WorkerDaemon's consolidate worker directly via// process.env — set it now so the foreground path (which runs in this// same process) picks it up too; the background path forwards it to the@@ -87,8 +88,8 @@ const startCommand: Command = {if (ctx.flags.headless === true) {config.aiWorkersEnabled = true;}- const rawMaxCpu = ctx.flags['max-cpu-load'] as string | undefined;- const rawMinMem = ctx.flags['min-free-memory'] as string | undefined;+ const rawMaxCpu = ctx.flags.maxCpuLoad as string | undefined;+ const rawMinMem = ctx.flags.minFreeMemory as string | undefined;// Strict numeric pattern to prevent command injection when forwarding to subprocess (S1)const NUMERIC_RE = /^\d+(\.\d+)?$/;