π 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(ruflo): require matching wrapper and CLI runtime versions
Rudy Celekli3c20d34acb65
diff --git a/ruflo/bin/ruflo.js b/ruflo/bin/ruflo.jsindex bb92ece3a2..4e9d99ff67 100755--- a/ruflo/bin/ruflo.js+++ b/ruflo/bin/ruflo.js@@ -6,26 +6,6 @@ import { existsSync, readFileSync } from 'node:fs';const __dirname = dirname(fileURLToPath(import.meta.url));-// #2256 fast path: --version / -V must NOT trigger heavy imports (the-// downstream @claude-flow/cli dist eagerly loads ruvector + a 23 MB ONNX-// model on cold cache, blocking 60+ s and causing SIGTERM under common-// timeout windows: npx default, MCP stdio 30s window). Resolve version-// from this wrapper's own package.json and exit before any heavy import.-// (bin/cli.js has the same guard for the direct path; needed here too-// because the wrapper imports dist/src/index.js, bypassing bin/cli.js.)-{- const _argv = process.argv.slice(2);- if (_argv.length === 1 && (_argv[0] === '--version' || _argv[0] === '-V')) {- try {- const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'));- process.stdout.write(`ruflo v${pkg.version || '0.0.0'}\n`);- } catch {- process.stdout.write('ruflo v0.0.0\n');- }- process.exit(0);- }-}-// Walk up from ruflo/bin/ to find @claude-flow/cli in node_modulesfunction findCliPath() {let dir = resolve(__dirname, '..');@@ -49,6 +29,30 @@ const cliBase = pkgDir? join(pkgDir, 'node_modules', '@claude-flow', 'cli'): resolve(__dirname, '../../v3/@claude-flow/cli');+// The wrapper and implementation ship in lockstep. A broad dependency range+// previously let a current wrapper silently run an older cached CLI (#3306).+// Check package metadata before either the fast --version path or an MCP+// import, without loading the CLI or its expensive model dependencies.+let wrapperVersion;+let cliVersion;+try {+ wrapperVersion = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8')).version;+ cliVersion = JSON.parse(readFileSync(join(cliBase, 'package.json'), 'utf-8')).version;+} catch (error) {+ console.error(`ruflo: cannot verify installed CLI version: ${error.message}`);+ process.exit(1);+}+if (!wrapperVersion || wrapperVersion !== cliVersion) {+ console.error(`ruflo: wrapper v${wrapperVersion || 'unknown'} requires @claude-flow/cli v${wrapperVersion || 'unknown'}, but resolved v${cliVersion || 'unknown'} at ${cliBase}`);+ process.exit(1);+}++// #2256: --version / -V must not trigger heavy CLI/model imports.+if (process.argv.length === 3 && ['--version', '-V'].includes(process.argv[2])) {+ process.stdout.write(`ruflo v${wrapperVersion}\n`);+ process.exit(0);+}+// MCP mode: delegate to cli.js directly (branding irrelevant for JSON-RPC)const cliArgs = process.argv.slice(2);const isExplicitMCP = cliArgs.length >= 1 && cliArgs[0] === 'mcp' && (cliArgs.length === 1 || cliArgs[1] === 'start');diff --git a/ruflo/package.json b/ruflo/package.jsonindex 6e7a13dc52..c1ec706c73 100644--- a/ruflo/package.json+++ b/ruflo/package.json@@ -40,7 +40,7 @@"package:rvf": "bash src/scripts/package-rvf.sh"},"dependencies": {- "@claude-flow/cli": "^3.48.0"+ "@claude-flow/cli": "3.48.0"},"optionalDependencies": {},"overrides": {diff --git a/ruflo/tests/wrapper-runtime-3306.test.mjs b/ruflo/tests/wrapper-runtime-3306.test.mjsnew file mode 100644index 0000000000..f3349c5745--- /dev/null+++ b/ruflo/tests/wrapper-runtime-3306.test.mjs@@ -0,0 +1,63 @@+import assert from 'node:assert/strict';+import { spawnSync } from 'node:child_process';+import { copyFileSync, existsSync, mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { fileURLToPath } from 'node:url';+import test from 'node:test';++const wrapperSource = fileURLToPath(new URL('../bin/ruflo.js', import.meta.url));++function install(t, cliVersion) {+ const root = mkdtempSync(join(tmpdir(), 'ruflo-wrapper-3306-'));+ t.after(() => rmSync(root, { recursive: true, force: true }));+ const wrapperDir = join(root, 'node_modules', 'ruflo');+ const cliDir = join(root, 'node_modules', '@claude-flow', 'cli');+ mkdirSync(join(wrapperDir, 'bin'), { recursive: true });+ mkdirSync(join(cliDir, 'bin'), { recursive: true });+ copyFileSync(wrapperSource, join(wrapperDir, 'bin', 'ruflo.js'));+ writeFileSync(join(wrapperDir, 'package.json'), JSON.stringify({ name: 'ruflo', version: '3.45.0', type: 'module' }));+ writeFileSync(join(cliDir, 'package.json'), JSON.stringify({ name: '@claude-flow/cli', version: cliVersion, type: 'module' }));+ writeFileSync(join(cliDir, 'bin', 'cli.js'), `import { writeFileSync } from 'node:fs';\nwriteFileSync(process.env.RUFLO_TEST_MARKER, 'launched');\n`);+ return { bin: join(wrapperDir, 'bin', 'ruflo.js'), marker: join(root, 'cli-launched') };+}++function run(fixture, args) {+ return spawnSync(process.execPath, [fixture.bin, ...args], {+ encoding: 'utf-8',+ env: { ...process.env, RUFLO_TEST_MARKER: fixture.marker },+ });+}++test('matching wrapper and runtime report the version without importing the CLI', (t) => {+ const fixture = install(t, '3.45.0');+ const result = run(fixture, ['--version']);+ assert.equal(result.status, 0, result.stderr);+ assert.equal(result.stdout, 'ruflo v3.45.0\n');+ assert.equal(existsSync(fixture.marker), false);+});++test('a stale runtime cannot masquerade as the current wrapper version', (t) => {+ const fixture = install(t, '3.33.0');+ const result = run(fixture, ['--version']);+ assert.equal(result.status, 1);+ assert.equal(result.stdout, '');+ assert.match(result.stderr, /3\.45\.0.*3\.33\.0/);+ assert.equal(existsSync(fixture.marker), false);+});++test('a stale runtime is refused before MCP protocol output or implementation import', (t) => {+ const fixture = install(t, '3.33.0');+ const result = run(fixture, ['mcp', 'start']);+ assert.equal(result.status, 1);+ assert.equal(result.stdout, '');+ assert.match(result.stderr, /requires @claude-flow\/cli/);+ assert.equal(existsSync(fixture.marker), false);+});++test('a matching runtime still receives MCP commands', (t) => {+ const fixture = install(t, '3.45.0');+ const result = run(fixture, ['mcp', 'start']);+ assert.equal(result.status, 0, result.stderr);+ assert.equal(existsSync(fixture.marker), true);+});diff --git a/scripts/audit-umbrella-version-lockstep.mjs b/scripts/audit-umbrella-version-lockstep.mjsindex 541b7fb5ba..81180320d6 100755--- a/scripts/audit-umbrella-version-lockstep.mjs+++ b/scripts/audit-umbrella-version-lockstep.mjs@@ -16,20 +16,17 @@* version. This audit enforces that locally so a drift can't reach a* release. Wired into v3-ci.yml as `umbrella-version-lockstep-audit`.*- * Also asserts ruflo's @claude-flow/cli dep range INCLUDES the cli's- * actual version (overlap with audit-wrapper-dep-ranges.mjs is intentional;- * this audit is about identity, that one is about inclusion).+ * Also asserts ruflo pins the exact CLI version (#3306). A range that merely+ * includes it can retain an older cached implementation behind a new wrapper.** Exit codes:- * 0 β versions identical and dep range covers cli+ * 0 β versions identical and ruflo pins that CLI version* 1 β drift detected; remediation hints printed*/import { readFileSync, existsSync } from 'node:fs';import { fileURLToPath } from 'node:url';import { dirname, join, resolve } from 'node:path';-import semver from 'semver';-const __dirname = dirname(fileURLToPath(import.meta.url));const REPO_ROOT = resolve(__dirname, '..');@@ -74,25 +71,25 @@ if (unique.size > 1) {);}-// Cross-check: ruflo's dep range must include cli's actual version.+// Cross-check: ruflo must resolve exactly the CLI version it advertises.const rufloPkg = readPkg('ruflo/package.json');const cliVersion = versions['@claude-flow/cli'];if (rufloPkg && cliVersion) {const range = rufloPkg.dependencies?.['@claude-flow/cli'];if (range) {- if (!semver.satisfies(cliVersion, range, { includePrerelease: true })) {+ if (range !== cliVersion) {violations.push(- `ruflo "@claude-flow/cli": "${range}" does NOT include cli's actual version ${cliVersion}.\n` +- ` Update ruflo/package.json dependencies to "^${cliVersion}".`+ `ruflo "@claude-flow/cli": "${range}" must pin cli's actual version ${cliVersion}.\n` ++ ` Update ruflo/package.json dependencies to "${cliVersion}".`);} else {- console.log(` ruflo dep "@claude-flow/cli": "${range}" covers ${cliVersion} β`);+ console.log(` ruflo dep "@claude-flow/cli": "${range}" matches ${cliVersion} β`);}}}if (violations.length === 0) {- console.log('\n ok: all three umbrella packages at identical version, ruflo dep covers cli');+ console.log('\n ok: all three umbrella packages at identical version, ruflo pins cli');process.exit(0);}diff --git a/scripts/audit-wrapper-dep-ranges.mjs b/scripts/audit-wrapper-dep-ranges.mjsindex edd07fa8e4..6680207d77 100644--- a/scripts/audit-wrapper-dep-ranges.mjs+++ b/scripts/audit-wrapper-dep-ranges.mjs@@ -12,8 +12,8 @@** This audit asserts:*- * 1. The `ruflo` wrapper's `@claude-flow/cli` dep range INCLUDES the- * version that `v3/@claude-flow/cli` currently publishes.+ * 1. The `ruflo` wrapper pins the exact version that+ * `v3/@claude-flow/cli` currently publishes (#3306).** 2. The root `claude-flow` umbrella's sibling deps that we maintain* (`@claude-flow/cli-core`, `@claude-flow/mcp`, `@claude-flow/neural`,@@ -71,11 +71,12 @@ if (!rufloPkg) {} else {checks.push(`ruflo wraps @claude-flow/cli with range "${rufloDepRange}" β cli published as ${cliVersion}`);- // 1a. Range must include the current cli version- if (!semver.satisfies(cliVersion, rufloDepRange, { includePrerelease: true })) {+ // #3306: inclusion is insufficient: ^3.33.0 allowed a cached 3.33.0+ // implementation to sit behind a 3.41.2 wrapper and report as current.+ if (rufloDepRange !== cliVersion) {violations.push(- `ruflo's "@claude-flow/cli": "${rufloDepRange}" does NOT include the cli's actual ` +- `version ${cliVersion}. Bump the range to "^${cliVersion}" or wider that covers it.`+ `ruflo's "@claude-flow/cli": "${rufloDepRange}" must pin the exact CLI ` ++ `version ${cliVersion} (no range).`);}@@ -131,7 +132,7 @@ console.log(`wrapper-dep-ranges audit β scanned ${checks.length} declaration(sfor (const c of checks) console.log(` ${c}`);if (violations.length === 0) {- console.log(' ok: all wrapper ranges include their published target versions');+ console.log(' ok: ruflo pins its exact CLI version; other ranges include published targets');console.log(' ok: no pre-release ranges pointing at stable deps');process.exit(0);}