🌊 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): load YAML config from ESM runtime
Rudy Celekli991caf68fb71
diff --git a/v3/@claude-flow/cli/__tests__/services/worker-daemon-resource-thresholds.test.ts b/v3/@claude-flow/cli/__tests__/services/worker-daemon-resource-thresholds.test.tsindex aec451359c..258c69408d 100644--- a/v3/@claude-flow/cli/__tests__/services/worker-daemon-resource-thresholds.test.ts+++ b/v3/@claude-flow/cli/__tests__/services/worker-daemon-resource-thresholds.test.ts@@ -11,9 +11,11 @@import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';import { WorkerDaemon } from '../../src/services/worker-daemon.js';-import { mkdtempSync, rmSync, mkdirSync, writeFileSync } from 'fs';+import { mkdtempSync, rmSync, mkdirSync, writeFileSync, readFileSync } from 'fs';import { join } from 'path';import { tmpdir, cpus } from 'os';+import { execFileSync } from 'node:child_process';+import { fileURLToPath } from 'node:url';describe('WorkerDaemon resource thresholds', () => {let tempDir: string;@@ -188,6 +190,32 @@ describe('WorkerDaemon resource thresholds', () => {});});+ it('loads daemon settings from config.yaml in the ESM runtime', () => {+ const configFile = join(tempDir, '.claude-flow', 'config.yaml');+ writeFileSync(configFile, [+ "'daemon.maxConcurrent': 7",+ "'daemon.resourceThresholds.minFreeMemoryPercent': 0",+ ].join('\n'));++ // Vitest's transform supplies a CommonJS `require`, masking the bug in+ // the published ESM runtime. Run the source in a real Node ESM process.+ const cliRoot = fileURLToPath(new URL('../..', import.meta.url));+ const moduleUrl = new URL('../../src/services/worker-daemon.ts', import.meta.url).href;+ const script = `import { WorkerDaemon } from ${JSON.stringify(moduleUrl)};+ const daemon = new WorkerDaemon(${JSON.stringify(tempDir)});+ console.log('__DAEMON_CONFIG__' + JSON.stringify(daemon.getStatus().config));`;+ const stdout = execFileSync(process.execPath, ['--import', 'tsx', '--input-type=module', '-e', script], {+ cwd: cliRoot, encoding: 'utf8', timeout: 15_000,+ });+ const payload = stdout.match(/__DAEMON_CONFIG__(\{[^\n]+\})/);+ expect(payload).not.toBeNull();+ const config = JSON.parse(payload![1]);+ expect(config.maxConcurrent).toBe(7);+ expect(config.resourceThresholds.minFreeMemoryPercent).toBe(0);+ expect(readFileSync(join(tempDir, '.claude-flow', 'logs', 'daemon.log'), 'utf8'))+ .toContain(`Daemon config loaded from ${configFile}`);+ });+// =========================================================================// Config priority chain// =========================================================================diff --git a/v3/@claude-flow/cli/src/services/worker-daemon.ts b/v3/@claude-flow/cli/src/services/worker-daemon.tsindex a4c163d315..694a082c15 100644--- a/v3/@claude-flow/cli/src/services/worker-daemon.ts+++ b/v3/@claude-flow/cli/src/services/worker-daemon.ts@@ -15,6 +15,7 @@ import { EventEmitter } from 'events';import { existsSync, mkdirSync, writeFileSync, readFileSync, appendFileSync, unlinkSync, renameSync } from 'fs';import { cpus } from 'os';import { join } from 'path';+import { createRequire } from 'node:module';import { writeFileAtomic } from '../fs-secure.js';import {HeadlessWorkerExecutor,@@ -35,6 +36,10 @@ import { resolveGitWorkspaceIdentity, type GitWorkspaceIdentity } from './git-woimport { getWorkspaceLeaseRegistry } from './workspace-lease.js';import { getRepoSupervisorRegistry, type SupervisorRecord } from './repo-supervisor.js';+// Daemon config is read synchronously from the constructor. In an ESM build,+// bare `require` is undefined, so use a module-relative require for YAML.+const requireYaml = createRequire(import.meta.url);+// Worker types matching hooks-tools.tsexport type WorkerType =| 'ultralearn'@@ -517,8 +522,7 @@ export class WorkerDaemon extends EventEmitter {try {// Lazy-load yaml so the daemon doesn't hard-require it; if the// dep isn't installed, fall back to the previous warn-only path.- // eslint-disable-next-line @typescript-eslint/no-var-requires- const yamlMod = require('yaml') as { parse(s: string): unknown };+ const yamlMod = requireYaml('yaml') as { parse(s: string): unknown };const parsed = yamlMod.parse(readFileSync(yPath, 'utf-8'));if (parsed && typeof parsed === 'object') {// eslint-disable-next-line @typescript-eslint/no-explicit-any