From 7cb8603b7f7432c9aa9326862bae9b59ab985cce Mon Sep 17 00:00:00 2001 From: r Date: Tue, 10 Nov 2026 08:40:27 -0500 Subject: [PATCH 1/2] fix(release): ship zod 4 inside the bundled security package; release 3.75.1 (#4940) @claude-flow/cli 3.74.1 and 3.75.0 (and the claude-flow umbrella) bundle @claude-flow/security 3.0.7, which needs zod >=4.6.7, while the wrappers keep zod 3. The staging script stripped the nested dependencies, so security's `import 'zod'` resolved to zod 3 and the root export threw `z.config is not a function`. Declaring the dependency is not enough: npm never installs the dependencies of a bundled package (checked against the 3.75.0 tarball). The stager now vendors declared leaf dependencies into the bundled package's own node_modules, checks the workspace copy satisfies the declared range, and refuses a dependency that has dependencies itself. The npx-install smoke now imports every bundled runtime package from the installed CLI, so this fails CI instead of users. Co-Authored-By: RuFlo --- package-lock.json | 4 +- package.json | 2 +- ruflo/package.json | 4 +- ruflo/server.json | 4 +- .../stage-internal-runtime-bundles.test.mjs | 55 +++++++++++++++ scripts/smoke-cli-npx-install.mjs | 18 ++++- scripts/stage-internal-runtime-bundles.mjs | 68 ++++++++++++++++++- v3/@claude-flow/cli/package.json | 2 +- 8 files changed, 146 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index d2e35a47ac..956d931cb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "claude-flow", - "version": "3.75.0", + "version": "3.75.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "claude-flow", - "version": "3.75.0", + "version": "3.75.1", "bundleDependencies": [ "@claude-flow/codex", "@claude-flow/mcp", diff --git a/package.json b/package.json index a76361827c..6bf5a7dc70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "claude-flow", - "version": "3.75.0", + "version": "3.75.1", "workspaces": [ "v3/@claude-flow/codex", "v3/@claude-flow/mcp", diff --git a/ruflo/package.json b/ruflo/package.json index 19ca340ac4..e9cb81915a 100644 --- a/ruflo/package.json +++ b/ruflo/package.json @@ -1,7 +1,7 @@ { "name": "ruflo", "mcpName": "io.github.ruvnet/ruflo", - "version": "3.75.0", + "version": "3.75.1", "description": "Ruflo - Enterprise AI agent orchestration platform. Deploy 60+ specialized agents in coordinated swarms with self-learning, fault-tolerant consensus, vector memory, and MCP integration", "main": "bin/ruflo.js", "type": "module", @@ -41,7 +41,7 @@ "package:rvf": "bash src/scripts/package-rvf.sh" }, "dependencies": { - "@claude-flow/cli": "3.75.0" + "@claude-flow/cli": "3.75.1" }, "optionalDependencies": {}, "overrides": { diff --git a/ruflo/server.json b/ruflo/server.json index 379d0336a0..11982aeb74 100644 --- a/ruflo/server.json +++ b/ruflo/server.json @@ -9,12 +9,12 @@ "subfolder": "ruflo" }, "websiteUrl": "https://github.com/ruvnet/ruflo", - "version": "3.75.0", + "version": "3.75.1", "packages": [ { "registryType": "npm", "identifier": "ruflo", - "version": "3.75.0", + "version": "3.75.1", "runtimeHint": "npx", "transport": { "type": "stdio" diff --git a/scripts/__tests__/stage-internal-runtime-bundles.test.mjs b/scripts/__tests__/stage-internal-runtime-bundles.test.mjs index b1db1e2a83..7343b58712 100644 --- a/scripts/__tests__/stage-internal-runtime-bundles.test.mjs +++ b/scripts/__tests__/stage-internal-runtime-bundles.test.mjs @@ -51,3 +51,58 @@ assert.equal(alignBundledRuntimeVersion(target, { }), false); console.log('bundled runtime manifest is self-contained and preserves source metadata'); + +// #4940: a vendored dependency stays declared and its files ship in the bundle. +{ + const { mkdtemp, mkdir, writeFile, readFile, rm, access } = await import('node:fs/promises'); + const { tmpdir } = await import('node:os'); + const { join } = await import('node:path'); + const { vendorDependency } = await import('../stage-internal-runtime-bundles.mjs'); + + const withVendored = createBundledRuntimeManifest( + { name: '@claude-flow/example', version: '1.0.0', dependencies: { leaf: '^4.6.7', other: '^1.0.0' } }, + ['leaf'], + ); + assert.deepEqual(withVendored.dependencies, { leaf: '^4.6.7' }); + assert.deepEqual(withVendored.rufloBundledRuntime.sourceDependencies.dependencies, { + leaf: '^4.6.7', + other: '^1.0.0', + }); + assert.throws( + () => createBundledRuntimeManifest({ name: 'x', dependencies: {} }, ['leaf']), + /does not declare its vendored dependency leaf/, + ); + + const root = await mkdtemp(join(tmpdir(), 'stage-vendored-')); + try { + const source = join(root, 'source'); + const staged = join(root, 'staged'); + const fixture = async (name, manifest) => { + const directory = join(source, 'node_modules', name); + await mkdir(join(directory, 'node_modules', 'nested'), { recursive: true }); + await writeFile(join(directory, 'package.json'), JSON.stringify({ name, main: 'index.js', ...manifest })); + await writeFile(join(directory, 'index.js'), 'module.exports = 4;\n'); + await writeFile(join(directory, 'node_modules', 'nested', 'x.js'), ''); + }; + await mkdir(source, { recursive: true }); + await writeFile(join(source, 'package.json'), '{"name":"@claude-flow/example"}'); + await fixture('leaf', { version: '4.6.9' }); + await fixture('old', { version: '3.25.76' }); + await fixture('tree', { version: '1.0.0', dependencies: { more: '^1.0.0' } }); + const pkg = { name: '@claude-flow/example', dependencies: { leaf: '^4.6.7', old: '^4.6.7', tree: '^1.0.0' } }; + + assert.equal(await vendorDependency(source, staged, pkg, 'leaf'), '4.6.9'); + const copied = JSON.parse(await readFile(join(staged, 'node_modules', 'leaf', 'package.json'), 'utf8')); + assert.equal(copied.version, '4.6.9'); + await access(join(staged, 'node_modules', 'leaf', 'index.js')); + await assert.rejects(access(join(staged, 'node_modules', 'leaf', 'node_modules'))); + + // The workspace copy must satisfy the declared range, or zod 3 ships again. + await assert.rejects(vendorDependency(source, staged, pkg, 'old'), /workspace resolved 3\.25\.76/); + await assert.rejects(vendorDependency(source, staged, pkg, 'tree'), /dependencies of its own/); + await assert.rejects(vendorDependency(source, staged, pkg, 'absent'), /does not declare/); + } finally { + await rm(root, { recursive: true, force: true }); + } + console.log('vendored dependencies are declared, range-checked and copied without nested trees'); +} diff --git a/scripts/smoke-cli-npx-install.mjs b/scripts/smoke-cli-npx-install.mjs index bcca1dfde7..626eac8e6e 100644 --- a/scripts/smoke-cli-npx-install.mjs +++ b/scripts/smoke-cli-npx-install.mjs @@ -112,4 +112,20 @@ if (ver.code !== 0 || !ver.stdout.trim()) { } console.log(` ${ver.stdout.trim()}`); -console.log(`[5/5] ok — installed cleanly, no "Invalid Version" regression`); +// #4940: every bundled runtime package must load from the installed CLI. The +// bundled security package once resolved `zod` to the CLI's zod 3 and its root +// export threw `z.config is not a function`; --version never imports it. +const cliRoot = join(scratch, 'node_modules', '@claude-flow', 'cli'); +for (const name of installedPkg.bundleDependencies ?? installedPkg.bundledDependencies ?? []) { + const load = run('node', ['--input-type=module', '-e', + `import { createRequire } from 'node:module'; import { pathToFileURL } from 'node:url'; + const r = createRequire(${JSON.stringify(join(cliRoot, 'package.json'))}); + await import(pathToFileURL(r.resolve(${JSON.stringify(name)})).href);`], { cwd: scratch }); + if (load.code !== 0) { + console.error(load.stderr); + fail(`bundled ${name} does not import from the installed CLI (exit ${load.code})`); + } + console.log(` bundled ${name} imports`); +} + +console.log(`[5/5] ok — installed cleanly, no "Invalid Version" regression, bundled runtimes import`); diff --git a/scripts/stage-internal-runtime-bundles.mjs b/scripts/stage-internal-runtime-bundles.mjs index 1bb3aa80cd..05b1da6b69 100644 --- a/scripts/stage-internal-runtime-bundles.mjs +++ b/scripts/stage-internal-runtime-bundles.mjs @@ -11,6 +11,7 @@ import { writeFile, } from 'node:fs/promises'; import { spawnSync } from 'node:child_process'; +import { createRequire } from 'node:module'; import { dirname, join, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -23,6 +24,11 @@ export const INTERNAL_RUNTIME_PACKAGES = [ name: '@claude-flow/security', requiredAssets: ['dist'], optionalAssets: ['README.md'], + // #4940: security needs zod >=4.6.7 while the CLI and the umbrella keep + // zod 3. npm never installs the dependencies of a bundled package, so a + // declaration alone still resolves `zod` to the wrapper's zod 3 and the + // root export dies at `z.config`. The files have to ship in the bundle. + vendoredDependencies: ['zod'], }, { directory: 'codex', @@ -125,7 +131,7 @@ async function validateEntrypoints(packageRoot, packageJson) { } } -export function createBundledRuntimeManifest(packageJson) { +export function createBundledRuntimeManifest(packageJson, vendoredDependencies = []) { const dependencyMetadata = {}; for (const field of [ 'dependencies', @@ -146,12 +152,63 @@ export function createBundledRuntimeManifest(packageJson) { }, }; delete bundledManifest.dependencies; + // A vendored dependency ships inside this package's own node_modules. It + // stays declared so the manifest matches the files and npm packs them. + const vendored = {}; + for (const name of vendoredDependencies) { + const range = packageJson.dependencies?.[name]; + if (range === undefined) { + throw new Error(`${packageJson.name} does not declare its vendored dependency ${name}`); + } + vendored[name] = range; + } + if (Object.keys(vendored).length > 0) bundledManifest.dependencies = vendored; delete bundledManifest.optionalDependencies; delete bundledManifest.peerDependencies; delete bundledManifest.peerDependenciesMeta; return bundledManifest; } +/** + * Copy one dependency of a bundled package into that package's node_modules, + * from the copy the workspace build resolved. Only leaf packages qualify: a + * vendored dependency with dependencies of its own would need them vendored + * too, so that is refused instead of shipping a tree that cannot load. + */ +export async function vendorDependency(sourceRoot, stagedRoot, packageJson, name) { + const range = packageJson.dependencies?.[name]; + if (range === undefined) { + throw new Error(`${packageJson.name} does not declare its vendored dependency ${name}`); + } + let directory = dirname(createRequire(join(sourceRoot, 'package.json')).resolve(name)); + let manifest; + for (;;) { + try { + const candidate = JSON.parse(await readFile(join(directory, 'package.json'), 'utf8')); + if (candidate.name === name) { manifest = candidate; break; } + } catch { /* keep walking up to the package root */ } + const parent = dirname(directory); + if (parent === directory) throw new Error(`Cannot find the package root of ${name}`); + directory = parent; + } + const { default: semver } = await import('semver'); + if (!semver.satisfies(manifest.version, range)) { + throw new Error( + `${packageJson.name} needs ${name}@${range}, but the workspace resolved ${manifest.version}`, + ); + } + const own = { ...manifest.dependencies, ...manifest.optionalDependencies, ...manifest.peerDependencies }; + if (Object.keys(own).length > 0) { + throw new Error(`${name}@${manifest.version} has dependencies of its own and cannot be vendored`); + } + await cp(directory, join(stagedRoot, 'node_modules', name), { + recursive: true, + dereference: true, + filter: (source) => !source.slice(directory.length).split(/[\\/]/).includes('node_modules'), + }); + return manifest.version; +} + export function alignBundledRuntimeVersion(targetPackageJson, runtimePackageJson) { const current = targetPackageJson.dependencies?.[runtimePackageJson.name]; if (current === undefined) { @@ -224,8 +281,15 @@ export async function stageInternalRuntimeBundles( await mkdir(temporary, { recursive: true }); await writeFile( join(temporary, 'package.json'), - `${JSON.stringify(createBundledRuntimeManifest(packageJson), null, 2)}\n`, + `${JSON.stringify( + createBundledRuntimeManifest(packageJson, runtimePackage.vendoredDependencies), + null, + 2, + )}\n`, ); + for (const name of runtimePackage.vendoredDependencies ?? []) { + await vendorDependency(sourceRoot, temporary, packageJson, name); + } for (const asset of runtimePackage.requiredAssets) { await copyRequired(join(sourceRoot, asset), join(temporary, asset)); } diff --git a/v3/@claude-flow/cli/package.json b/v3/@claude-flow/cli/package.json index 4a1b609af8..dd17ff766b 100644 --- a/v3/@claude-flow/cli/package.json +++ b/v3/@claude-flow/cli/package.json @@ -1,6 +1,6 @@ { "name": "@claude-flow/cli", - "version": "3.75.0", + "version": "3.75.1", "type": "module", "description": "Ruflo CLI - Enterprise AI agent orchestration with 60+ specialized agents, swarm coordination, MCP server, self-learning hooks, and vector memory for Claude Code", "main": "dist/src/index.js", From 5490095e7e9fe45176e60fbc18fe331c25fa3f2b Mon Sep 17 00:00:00 2001 From: r Date: Tue, 10 Nov 2026 09:02:17 -0500 Subject: [PATCH 2/2] test(release): the npx-install smoke packs the staged CLI, as a release does The smoke ran a bare pnpm pack, which bundles workspace links and never runs the staging step, so it tested a tarball nobody installs. It now stages the bundled runtime packages and packs with npm. The vendored range check no longer needs the semver package, which that job does not install. Co-Authored-By: RuFlo --- .../stage-internal-runtime-bundles.test.mjs | 10 ++++++++- scripts/smoke-cli-npx-install.mjs | 13 ++++++++++-- scripts/stage-internal-runtime-bundles.mjs | 21 +++++++++++++++++-- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/scripts/__tests__/stage-internal-runtime-bundles.test.mjs b/scripts/__tests__/stage-internal-runtime-bundles.test.mjs index 7343b58712..aaf99f66c1 100644 --- a/scripts/__tests__/stage-internal-runtime-bundles.test.mjs +++ b/scripts/__tests__/stage-internal-runtime-bundles.test.mjs @@ -57,7 +57,15 @@ console.log('bundled runtime manifest is self-contained and preserves source met const { mkdtemp, mkdir, writeFile, readFile, rm, access } = await import('node:fs/promises'); const { tmpdir } = await import('node:os'); const { join } = await import('node:path'); - const { vendorDependency } = await import('../stage-internal-runtime-bundles.mjs'); + const { vendorDependency, satisfiesCaretOrExact } = await import('../stage-internal-runtime-bundles.mjs'); + assert.equal(satisfiesCaretOrExact('4.6.7', '^4.6.7'), true); + assert.equal(satisfiesCaretOrExact('4.7.0', '^4.6.7'), true); + assert.equal(satisfiesCaretOrExact('4.6.6', '^4.6.7'), false); + assert.equal(satisfiesCaretOrExact('5.0.0', '^4.6.7'), false); + assert.equal(satisfiesCaretOrExact('3.25.76', '^4.6.7'), false); + assert.equal(satisfiesCaretOrExact('4.6.7', '4.6.7'), true); + assert.throws(() => satisfiesCaretOrExact('4.6.7', '>=4'), /Unsupported/); + assert.throws(() => satisfiesCaretOrExact('0.2.1', '^0.2.0'), /Unsupported/); const withVendored = createBundledRuntimeManifest( { name: '@claude-flow/example', version: '1.0.0', dependencies: { leaf: '^4.6.7', other: '^1.0.0' } }, diff --git a/scripts/smoke-cli-npx-install.mjs b/scripts/smoke-cli-npx-install.mjs index 626eac8e6e..7ab775b0d9 100644 --- a/scripts/smoke-cli-npx-install.mjs +++ b/scripts/smoke-cli-npx-install.mjs @@ -49,10 +49,19 @@ const packDest = mkdtempSync(join(tmpdir(), 'cli-pack-')); let tarball; { console.log(`[1/5] packing CLI to ${packDest}`); - const pnpm = run('pnpm', ['pack', '--pack-destination', packDest], { cwd: CLI_DIR }); - if (pnpm.code === 0) { + // #4940: pack what a release packs. A release stages the bundled runtime + // packages (and their vendored dependencies) and then runs npm pack; a bare + // `pnpm pack` bundles the workspace links, which is not the published shape. + let pnpm = { code: 1, stderr: 'skipped: staged bundles are packed with npm' }; + try { + const { stageInternalRuntimeBundles } = await import('./stage-internal-runtime-bundles.mjs'); + await stageInternalRuntimeBundles(CLI_DIR, { build: false }); + const staged = run('npm', ['pack', '--ignore-scripts', '--pack-destination', packDest], { cwd: CLI_DIR }); + if (staged.code !== 0) fail(`npm pack of the staged CLI failed:\n${staged.stderr}`); const tgz = readdirSync(packDest).find((f) => f.endsWith('.tgz')); if (tgz) tarball = join(packDest, tgz); + } catch (error) { + fail(`staging the bundled runtime packages failed: ${error?.stack ?? error}`); } if (!tarball) { // Fallback to npm pack — works when run with pnpm-resolved workspace already installed diff --git a/scripts/stage-internal-runtime-bundles.mjs b/scripts/stage-internal-runtime-bundles.mjs index 05b1da6b69..d55d32200c 100644 --- a/scripts/stage-internal-runtime-bundles.mjs +++ b/scripts/stage-internal-runtime-bundles.mjs @@ -169,6 +169,24 @@ export function createBundledRuntimeManifest(packageJson, vendoredDependencies = return bundledManifest; } +/** + * Range check for a vendored dependency, without a semver package: this script + * also runs in CI jobs that install only the v3 workspace. Accepts an exact + * version or a caret range on a major >= 1; anything else is refused so an + * unusual range is looked at, not guessed. + */ +export function satisfiesCaretOrExact(version, range) { + const parse = (value) => /^(\d+)\.(\d+)\.(\d+)$/.exec(value)?.slice(1).map(Number); + const got = parse(version); + const caret = range.startsWith('^'); + const want = parse(caret ? range.slice(1) : range); + if (!got || !want) throw new Error(`Unsupported vendored version or range: ${version} vs ${range}`); + if (!caret) return got.join('.') === want.join('.'); + if (want[0] === 0) throw new Error(`Unsupported vendored range (0.x caret): ${range}`); + if (got[0] !== want[0]) return false; + return got[1] !== want[1] ? got[1] > want[1] : got[2] >= want[2]; +} + /** * Copy one dependency of a bundled package into that package's node_modules, * from the copy the workspace build resolved. Only leaf packages qualify: a @@ -191,8 +209,7 @@ export async function vendorDependency(sourceRoot, stagedRoot, packageJson, name if (parent === directory) throw new Error(`Cannot find the package root of ${name}`); directory = parent; } - const { default: semver } = await import('semver'); - if (!semver.satisfies(manifest.version, range)) { + if (!satisfiesCaretOrExact(manifest.version, range)) { throw new Error( `${packageJson.name} needs ${name}@${range}, but the workspace resolved ${manifest.version}`, );