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

feat(metaharness): top-level `ruflo metaharness` CLI command + wrapper wiring (iter 3)

ruv9a517606ae92
diff --git a/plugins/ruflo-metaharness/scripts/smoke.sh b/plugins/ruflo-metaharness/scripts/smoke.sh
index 80278bae44..4ae0512275 100755
--- a/plugins/ruflo-metaharness/scripts/smoke.sh
+++ b/plugins/ruflo-metaharness/scripts/smoke.sh
@@ -146,5 +146,29 @@ step "14. plugin.json parses as valid JSON + version sentinel matches step 1"
node -e "JSON.parse(require('fs').readFileSync('$ROOT/.claude-plugin/plugin.json'))" 2>/dev/null \
&& ok || bad "plugin.json invalid JSON"
+step "15. top-level CLI command registered (deep integration β€” iter 3)"
+F="$ROOT/../../v3/@claude-flow/cli/src/commands/metaharness.ts"
+miss=""
+[[ -f "$F" ]] || miss="$miss command-file-missing"
+grep -q "name: 'metaharness'" "$F" 2>/dev/null || miss="$miss no-name-field"
+# The 5 subcommands must each be present in the dispatch table.
+# Match either quoted ('mcp-scan': ...) or unquoted shorthand (score: ...) keys.
+for sub in score genome mcp-scan threat-model mint; do
+ grep -qE "(^|[[:space:]])'?${sub}'?:" "$F" 2>/dev/null || miss="$miss missing-$sub"
+done
+# Registered in the loader
+LOADER="$ROOT/../../v3/@claude-flow/cli/src/commands/index.ts"
+grep -q "metaharness: () => import" "$LOADER" 2>/dev/null || miss="$miss not-registered-in-loader"
+[[ -z "$miss" ]] && ok || bad "$miss"
+
+step "16. ruflo wrapper has metaharness in optionalDependencies (architectural constraint #2)"
+F="$ROOT/../../ruflo/package.json"
+node -e "
+const j = JSON.parse(require('fs').readFileSync('$F','utf-8'));
+const od = j.optionalDependencies || {};
+if (!od.metaharness) { console.error('missing metaharness in optionalDependencies'); process.exit(1); }
+if (j.dependencies && j.dependencies.metaharness) { console.error('metaharness leaked into dependencies'); process.exit(1); }
+" 2>/dev/null && ok || bad "ruflo wrapper missing metaharness optionalDep"
+
printf "\n%s passed, %s failed\n" "$PASS" "$FAIL"
[[ $FAIL -eq 0 ]] || exit 1
diff --git a/ruflo/package.json b/ruflo/package.json
index d690768c10..8064d5a2e1 100644
--- a/ruflo/package.json
+++ b/ruflo/package.json
@@ -42,6 +42,10 @@
"dependencies": {
"@claude-flow/cli": "^3.10.3"
},
+ "optionalDependencies": {
+ "metaharness": "~0.1.11",
+ "@metaharness/router": "~0.3.2"
+ },
"overrides": {
"ruvector": "^0.2.27",
"better-sqlite3": ">=12.8.0",
diff --git a/v3/@claude-flow/cli/src/commands/index.ts b/v3/@claude-flow/cli/src/commands/index.ts
index 2745e64462..5f534412ab 100644
--- a/v3/@claude-flow/cli/src/commands/index.ts
+++ b/v3/@claude-flow/cli/src/commands/index.ts
@@ -78,6 +78,8 @@ const commandLoaders: Record<string, CommandLoader> = {
autopilot: () => import('./autopilot.js'),
// GAIA Benchmark Harness (ADR-133)
'gaia-bench': () => import('./gaia-bench.js'),
+ // MetaHarness integration (ADR-150) β€” dispatcher over plugins/ruflo-metaharness/
+ metaharness: () => import('./metaharness.js'),
};
// Cache for loaded commands
diff --git a/v3/@claude-flow/cli/src/commands/metaharness.ts b/v3/@claude-flow/cli/src/commands/metaharness.ts
new file mode 100644
index 0000000000..5aef396e4c
--- /dev/null
+++ b/v3/@claude-flow/cli/src/commands/metaharness.ts
@@ -0,0 +1,154 @@
+/**
+ * V3 CLI MetaHarness Command β€” ADR-150 deep integration entry point.
+ *
+ * Top-level dispatcher that delegates each subcommand to the matching
+ * `plugins/ruflo-metaharness/scripts/<name>.mjs` via spawnSync. This is
+ * the user-facing wrapper around the upstream `metaharness` / `harness`
+ * CLIs.
+ *
+ * SUBCOMMANDS
+ * score β€” 5-dim readiness scorecard
+ * genome β€” 7-section categorical report
+ * mcp-scan β€” static MCP security findings
+ * threat-model β€” enterprise-grade threat model
+ * mint β€” scaffold custom harness (DRY-RUN by default)
+ *
+ * Each subcommand is a thin subprocess invocation β€” the plugin scripts
+ * own the actual logic. This command exists so users can run:
+ *
+ * npx ruflo metaharness score
+ * npx ruflo metaharness mcp-scan --fail-on high
+ * npx ruflo metaharness mint --name foo --template vertical:coding
+ *
+ * instead of:
+ *
+ * node plugins/ruflo-metaharness/scripts/score.mjs
+ *
+ * ADR-150 ARCHITECTURAL CONSTRAINT
+ * --------------------------------
+ * This command file MUST NOT statically import any `@metaharness/*`
+ * package. The plugin scripts handle all metaharness invocation;
+ * here we only spawn the local Node script (which then handles
+ * `npx metaharness` + graceful degradation).
+ *
+ * Created with ruv.io
+ */
+
+import type { Command, CommandContext, CommandResult } from '../types.js';
+import { output } from '../output.js';
+import { spawnSync } from 'child_process';
+import { existsSync } from 'fs';
+import { join, dirname, resolve } from 'path';
+import { fileURLToPath } from 'url';
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+
+// Subcommand β†’ plugin script filename
+const SUBCOMMANDS: Record<string, string> = {
+ score: 'score.mjs',
+ genome: 'genome.mjs',
+ 'mcp-scan': 'mcp-scan.mjs',
+ 'threat-model': 'threat-model.mjs',
+ mint: 'mint.mjs',
+};
+
+/**
+ * Walk up from the current dirname to find the ruflo repo root that
+ * contains plugins/ruflo-metaharness/. Handles three install layouts:
+ * 1. ruflo dev tree (cwd / ../plugins/...)
+ * 2. ruflo wrapper (ruflo/node_modules/@claude-flow/cli/...)
+ * 3. npx (npm-cache/__npx/... β€” fall back to cwd-scan)
+ */
+function locatePluginScripts(): string | null {
+ const candidates: string[] = [];
+ // Up from the cli dist dir
+ let p = resolve(__dirname);
+ for (let i = 0; i < 8; i++) {
+ candidates.push(join(p, 'plugins', 'ruflo-metaharness', 'scripts'));
+ candidates.push(join(p, '..', 'plugins', 'ruflo-metaharness', 'scripts'));
+ p = dirname(p);
+ }
+ // Also try from cwd (covers the "npx ruflo" case where the user is
+ // sitting in their own repo and `npx ruflo metaharness score` should
+ // score THAT repo using the LOCAL plugin if present).
+ const cwd = process.cwd();
+ candidates.push(join(cwd, 'plugins', 'ruflo-metaharness', 'scripts'));
+ candidates.push(join(cwd, 'node_modules', '@claude-flow', 'cli', 'plugins', 'ruflo-metaharness', 'scripts'));
+
+ for (const c of candidates) {
+ if (existsSync(join(c, '_harness.mjs'))) return c;
+ }
+ return null;
+}
+
+function dispatchPluginScript(scriptDir: string, scriptName: string, extraArgs: string[]): CommandResult {
+ const scriptPath = join(scriptDir, scriptName);
+ const r = spawnSync('node', [scriptPath, ...extraArgs], {
+ stdio: 'inherit',
+ env: process.env,
+ timeout: 5 * 60 * 1000,
+ });
+ return {
+ success: (r.status ?? 0) === 0,
+ exitCode: r.status ?? 1,
+ data: { scriptPath, args: extraArgs },
+ };
+}
+
+export const metaharnessCommand: Command = {
+ name: 'metaharness',
+ description:
+ 'MetaHarness integration (ADR-150) β€” score / genome / mcp-scan / threat-model / mint. Subprocess-invoked plugin skills with graceful degradation.',
+ options: [
+ {
+ name: 'subcommand',
+ description: 'One of: score | genome | mcp-scan | threat-model | mint',
+ type: 'string' as const,
+ },
+ ],
+ async action(context: CommandContext): Promise<CommandResult> {
+ const args = (context as { args?: string[] }).args || [];
+ const subcommand = args[0];
+ const subArgs = args.slice(1);
+
+ if (!subcommand || subcommand === 'help' || subcommand === '--help' || subcommand === '-h') {
+ output.writeln(output.bold('npx ruflo metaharness <subcommand> [options]'));
+ output.writeln('');
+ output.writeln('Subcommands:');
+ output.writeln(' score 5-dimension harness readiness scorecard');
+ output.writeln(' genome 7-section categorical readiness report');
+ output.writeln(' mcp-scan static security scan of declared MCP surface');
+ output.writeln(' threat-model enterprise-grade threat model');
+ output.writeln(' mint scaffold a custom harness (dry-run by default)');
+ output.writeln('');
+ output.writeln('Each subcommand accepts --format json|table and --help.');
+ output.writeln('');
+ output.writeln(output.dim('ADR-150 β€” runs as subprocess; graceful degradation if metaharness is not installed.'));
+ return { success: true, exitCode: 0, data: { subcommand: null } };
+ }
+
+ if (!SUBCOMMANDS[subcommand]) {
+ output.writeln(output.error(`Unknown subcommand: ${subcommand}`));
+ output.writeln(`Valid: ${Object.keys(SUBCOMMANDS).join(', ')}`);
+ return { success: false, exitCode: 2, data: { subcommand } };
+ }
+
+ const scriptDir = locatePluginScripts();
+ if (!scriptDir) {
+ output.writeln(
+ output.warning(
+ 'metaharness: plugins/ruflo-metaharness/scripts/ not found. Install ruflo with `npm i ruflo` or run from the ruflo repo.'
+ )
+ );
+ output.writeln(
+ output.dim('(ADR-150 graceful degradation: this command is a thin delegator over the plugin; the plugin must be present.)')
+ );
+ // Exit 0 β€” this is "feature not available", not a runtime failure.
+ return { success: true, exitCode: 0, data: { degraded: true, reason: 'plugin-not-found' } };
+ }
+
+ return dispatchPluginScript(scriptDir, SUBCOMMANDS[subcommand], subArgs);
+ },
+};
+
+export default metaharnessCommand;