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

perf(cli): keep node:http and the security barrel off the MCP startup path

Marius Carlssona7992f06c711
diff --git a/v3/@claude-flow/cli/src/mcp-tools/agentbbs-federation.ts b/v3/@claude-flow/cli/src/mcp-tools/agentbbs-federation.ts
index 93e776c717..a591d76ed3 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/agentbbs-federation.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/agentbbs-federation.ts
@@ -54,7 +54,14 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync, appendFileSync, chmodSync } from 'node:fs';
import { join } from 'node:path';
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
-import { createServer, type Server, type IncomingMessage, type ServerResponse } from 'node:http';
+import { createRequire } from 'node:module';
+import type { Server, IncomingMessage, ServerResponse } from 'node:http';
+
+// Lazy, CommonJS-style load of node:http: an ESM `import … from 'node:http'`
+// materialises every export of the builtin, which trips http's lazy undici
+// getters (~2.5 MB heap / ~6 MB RSS) at MCP startup even when no server is
+// ever started. require() of the builtin does not touch those getters.
+const loadHttp = (): typeof import('node:http') => createRequire(import.meta.url)('node:http');
/** Max envelopes accepted from one peer in one sync. */
export const MAX_ENVELOPES_PER_SYNC = 5_000;
@@ -425,7 +432,7 @@ export function serveFederation(
opts: { port?: number; bindHost?: string } = {},
): Promise<{ server: Server; port: number; host: string }> {
const host = opts.bindHost ?? '127.0.0.1';
- const server = createServer((req: IncomingMessage, res: ServerResponse) => {
+ const server = loadHttp().createServer((req: IncomingMessage, res: ServerResponse) => {
const send = (code: number, obj: unknown) => {
const buf = Buffer.from(JSON.stringify(obj));
res.writeHead(code, { 'content-type': 'application/json', 'content-length': buf.length });
diff --git a/v3/@claude-flow/cli/src/mcp-tools/browser-intent-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/browser-intent-tools.ts
index c63d04bce2..8d9598ce83 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/browser-intent-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/browser-intent-tools.ts
@@ -86,10 +86,16 @@
*/
import { createRequire } from 'node:module';
-import { createServer, type Server } from 'node:http';
+import type { Server } from 'node:http';
import { readFileSync, existsSync } from 'node:fs';
import { dirname, join } from 'node:path';
import type { MCPTool, MCPToolResult } from './types.js';
+
+// Lazy, CommonJS-style load of node:http: an ESM `import … from 'node:http'`
+// materialises every export of the builtin, which trips http's lazy undici
+// getters (~2.5 MB heap / ~6 MB RSS) at MCP startup even when no server is
+// ever started. require() of the builtin does not touch those getters.
+const loadHttp = (): typeof import('node:http') => createRequire(import.meta.url)('node:http');
import { validateText, validateIdentifier } from './validate-input.js';
import { execBrowserCommand } from './browser-tools.js';
import { storeEntry } from '../memory/memory-initializer.js';
@@ -219,7 +225,7 @@ export interface LLMProxyHandle {
export function startLocalLLMProxy(real: { baseURL: string; apiKey: string }): Promise<LLMProxyHandle> {
return new Promise((resolve, reject) => {
- const server: Server = createServer((req, res) => {
+ const server: Server = loadHttp().createServer((req, res) => {
const target = `${real.baseURL.replace(/\/+$/, '')}${req.url ?? ''}`;
const chunks: Buffer[] = [];
req.on('data', (c: Buffer) => chunks.push(c));
diff --git a/v3/@claude-flow/cli/src/services/policy-runtime.ts b/v3/@claude-flow/cli/src/services/policy-runtime.ts
index 2672cf9732..1cc9a8a699 100644
--- a/v3/@claude-flow/cli/src/services/policy-runtime.ts
+++ b/v3/@claude-flow/cli/src/services/policy-runtime.ts
@@ -1,10 +1,11 @@
+// Narrow subpath imports (not the '@claude-flow/security' barrel): this module
+// is loaded eagerly by the MCP server, and the barrel also evaluates the OAuth
+// callback server (an ESM `node:http` import that materialises http's lazy
+// undici getters), bcryptjs, keychain and credential helpers that the policy
+// runtime never uses.
import {
AgenticPolicyEngine,
createLegacyCompatibleState,
- isMcpCallerAuthEnabled,
- decodeTokenEnvelope,
- publicKeyFromHex,
- verifyInvocationToken,
type BudgetLimit,
type CapabilityEnvelope,
type PolicyApproval,
@@ -13,7 +14,13 @@ import {
type PolicyRequest,
type PolicyRule,
type PolicyState,
-} from '@claude-flow/security';
+} from '@claude-flow/security/policy/index';
+import {
+ isMcpCallerAuthEnabled,
+ decodeTokenEnvelope,
+ publicKeyFromHex,
+ verifyInvocationToken,
+} from '@claude-flow/security/mcp-caller-identity';
import { createHash, createHmac, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
import { execFileSync } from 'node:child_process';
import {