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: hoist dynamic stdlib imports to static across commands/

Reuvenda2cd80d8e98
diff --git a/v3/@claude-flow/cli/src/commands/appliance.ts b/v3/@claude-flow/cli/src/commands/appliance.ts
index ce2cb93874..4de1d5b604 100644
--- a/v3/@claude-flow/cli/src/commands/appliance.ts
+++ b/v3/@claude-flow/cli/src/commands/appliance.ts
@@ -3,6 +3,8 @@
* Self-contained RVFA appliance management (build, inspect, verify, extract, run, sign, publish, update)
*/
+import { existsSync, mkdirSync, statSync } from 'node:fs';
+import { join as pathJoin, resolve as pathResolve } from 'node:path';
import type { Command, CommandContext, CommandResult } from '../types.js';
import { output } from '../output.js';
import { signCommand, publishCommand, updateAppCommand } from './appliance-advanced.js';
@@ -52,8 +54,7 @@ async function loadModule<T>(path: string, exportName: string, label: string): P
}
async function requireFile(file: string): Promise<boolean> {
- const fs = await import('fs');
- if (!fs.existsSync(file)) {
+ if (!existsSync(file)) {
output.printError(`File not found: ${file}`);
return false;
}
@@ -202,8 +203,7 @@ const inspectCommand: Command = {
output.writeln(output.dim(' No sections found'));
}
- const fs = await import('fs');
- const stat = fs.statSync(file);
+ const stat = statSync(file);
output.writeln();
output.printInfo(`Total file size: ${output.bold(fmtSize(stat.size))}`);
if (hdr.footerHash) {
@@ -308,14 +308,11 @@ const extractCommand: Command = {
if (!(await requireFile(file))) return { success: false, exitCode: 1 };
try {
- const fs = await import('fs');
- const path = await import('path');
-
header('RVFA Extraction');
const reader = new RvfaReader(file);
const hdr = await reader.parse();
- const dest = path.resolve(outputDir);
- if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
+ const dest = pathResolve(outputDir);
+ if (!existsSync(dest)) mkdirSync(dest, { recursive: true });
output.printInfo(`Destination: ${dest}`);
output.writeln();
@@ -340,7 +337,7 @@ const extractCommand: Command = {
output.printSuccess(`Extraction complete: ${dest}`);
output.writeln(output.dim(' Directory structure:'));
for (const d of ['kernel', 'runtime', 'ruflo', 'models', 'data', 'verify']) {
- const exists = fs.existsSync(path.join(dest, d));
+ const exists = existsSync(pathJoin(dest, d));
output.writeln(` ${exists ? output.success('+') : output.dim('-')} ${d}/`);
}
return { success: true };
diff --git a/v3/@claude-flow/cli/src/commands/guidance.ts b/v3/@claude-flow/cli/src/commands/guidance.ts
index bb2b71afff..4a271cb453 100644
--- a/v3/@claude-flow/cli/src/commands/guidance.ts
+++ b/v3/@claude-flow/cli/src/commands/guidance.ts
@@ -3,6 +3,7 @@
* Guidance Control Plane - compile, retrieve, enforce, optimize
*/
+import { existsSync } from 'node:fs';
import type { Command, CommandContext, CommandResult } from '../types.js';
import { output } from '../output.js';
@@ -43,7 +44,6 @@ const compileCommand: Command = {
try {
const { readFile } = await import('node:fs/promises');
- const { existsSync } = await import('node:fs');
if (!existsSync(rootPath)) {
output.writeln(output.error(`Root guidance file not found: ${rootPath}`));
@@ -132,7 +132,6 @@ const retrieveCommand: Command = {
try {
const { readFile } = await import('node:fs/promises');
- const { existsSync } = await import('node:fs');
const { GuidanceCompiler } = await import('@claude-flow/guidance/compiler');
const { ShardRetriever, HashEmbeddingProvider } = await import('@claude-flow/guidance/retriever');
@@ -302,7 +301,6 @@ const statusCommand: Command = {
output.writeln(output.dim('─'.repeat(50)));
try {
- const { existsSync } = await import('node:fs');
const rootExists = existsSync('./CLAUDE.md');
const localExists = existsSync('./CLAUDE.local.md');
@@ -379,7 +377,6 @@ const optimizeCommand: Command = {
try {
const { readFile, writeFile } = await import('node:fs/promises');
- const { existsSync } = await import('node:fs');
if (!existsSync(rootPath)) {
output.writeln(output.error(`Root guidance file not found: ${rootPath}`));
@@ -494,7 +491,6 @@ const abTestCommand: Command = {
try {
const { readFile } = await import('node:fs/promises');
- const { existsSync } = await import('node:fs');
const { abBenchmark, getDefaultABTasks } = await import('@claude-flow/guidance/analyzer');
// Load Config B (candidate) content
diff --git a/v3/@claude-flow/cli/src/commands/performance.ts b/v3/@claude-flow/cli/src/commands/performance.ts
index ab23c69f4a..3b7d792196 100644
--- a/v3/@claude-flow/cli/src/commands/performance.ts
+++ b/v3/@claude-flow/cli/src/commands/performance.ts
@@ -5,6 +5,9 @@
* Created with ❤️ by ruv.io
*/
+import * as os from 'node:os';
+import * as fs from 'node:fs';
+import * as path from 'node:path';
import type { Command, CommandContext, CommandResult } from '../types.js';
import { output } from '../output.js';
@@ -354,10 +357,6 @@ const metricsCommand: Command = {
output.writeln(output.bold(`Performance Metrics (${timeframe})`));
output.writeln(output.dim('─'.repeat(50)));
- const os = await import('os');
- const fs = await import('fs');
- const path = await import('path');
-
// Real system metrics
const memUsage = process.memoryUsage();
const cpuUsage = process.cpuUsage();
diff --git a/v3/@claude-flow/cli/src/commands/process.ts b/v3/@claude-flow/cli/src/commands/process.ts
index a6a3948708..00673e8e57 100644
--- a/v3/@claude-flow/cli/src/commands/process.ts
+++ b/v3/@claude-flow/cli/src/commands/process.ts
@@ -3,7 +3,8 @@
* Background process management, daemon mode, and monitoring
*/
-import { writeFileSync, readFileSync, unlinkSync, existsSync, mkdirSync } from 'fs';
+import { readdirSync, writeFileSync, readFileSync, unlinkSync, existsSync, mkdirSync } from 'fs';
+import { cpus, loadavg, totalmem, freemem } from 'node:os';
import { dirname, resolve } from 'path';
import type { Command, CommandContext, CommandResult } from '../types.js';
@@ -253,11 +254,10 @@ const monitorCommand: Command = {
const alerts = ctx.flags?.alerts !== false;
// Gather real system metrics where possible
- const os = await import('node:os');
const memUsage = process.memoryUsage();
- const loadAvg = os.loadavg();
- const totalMem = os.totalmem();
- const freeMem = os.freemem();
+ const loadAvg = loadavg();
+ const totalMem = totalmem();
+ const freeMem = freemem();
const usedMemMB = Math.round((totalMem - freeMem) / 1024 / 1024);
const totalMemMB = Math.round(totalMem / 1024 / 1024);
@@ -291,7 +291,7 @@ const monitorCommand: Command = {
system: {
cpuLoadAvg1m: loadAvg[0] !== undefined ? parseFloat(loadAvg[0].toFixed(2)) : null,
cpuLoadAvg5m: loadAvg[1] !== undefined ? parseFloat(loadAvg[1].toFixed(2)) : null,
- cpuCount: os.cpus().length,
+ cpuCount: cpus().length,
memoryUsedMB: usedMemMB,
memoryTotalMB: totalMemMB,
processRssMB: Math.round(memUsage.rss / 1024 / 1024),
@@ -650,7 +650,6 @@ const logsCommand: Command = {
if (existsSync(logsDir)) {
try {
- const { readdirSync } = await import('node:fs');
const logFiles = readdirSync(logsDir)
.filter(f => f.endsWith('.log'))
.filter(f => source === 'all' || f.includes(source));