🌊 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(cli,plugins): stop plugin-dir walk-ups at the node_modules boundary; drop embeddings hunk
readc4adfe37a
diff --git a/v3/@claude-flow/cli/__tests__/optional-module-resolution-trust.test.ts b/v3/@claude-flow/cli/__tests__/optional-module-resolution-trust.test.tsindex 98e762d447..5b0c92d23e 100644--- a/v3/@claude-flow/cli/__tests__/optional-module-resolution-trust.test.ts+++ b/v3/@claude-flow/cli/__tests__/optional-module-resolution-trust.test.ts@@ -10,6 +10,7 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync,import { tmpdir } from 'node:os';import { dirname, join, resolve } from 'node:path';import { fileURLToPath, pathToFileURL } from 'node:url';+import { ownInstallAncestors, ownPluginDirs } from '../src/plugins/own-install.js';const here = dirname(fileURLToPath(import.meta.url));const REPO = resolve(here, '../../../..');@@ -55,19 +56,62 @@ describe('locators of executed modules never consult the cwd', () => {});}- it('embedding-service resolves agentic-flow from its own package only', () => {- const source = readFileSync(resolve(REPO, 'v3/@claude-flow/embeddings/src/embedding-service.ts'), 'utf8');- expect(source).not.toContain("path.join(cwd, 'node_modules/agentic-flow");- expect(source).not.toContain('/workspaces/claude-flow/node_modules');- expect(source).toContain("require.resolve('agentic-flow/package.json')");- });-it('compact.mjs does not resolve the token optimizer from the cwd', () => {const source = readFileSync(resolve(REPO, 'plugins/ruflo-cost-tracker/scripts/compact.mjs'), 'utf8');expect(source).not.toContain("tryResolveFrom(join(process.cwd(), 'package.json'))");});});+describe('plugin locators stay inside the package own install', () => {+ const sources: Array<[string, string]> = [+ ['v3/@claude-flow/cli/src/mcp-tools/testgen-tools.ts', 'locateTestgenScripts'],+ ['v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.ts', 'locatePluginScripts'],+ ['v3/@claude-flow/cli/src/commands/metaharness.ts', 'locatePluginScripts'],+ ['v3/@claude-flow/cli/src/commands/doctor.ts', 'checkMetaharnessIntegration'],+ ];+ for (const [file, name] of sources) {+ it(`${file} ${name}() walks up through the bounded helper, not a hand-rolled loop`, () => {+ const body = fnSource(file, name);+ expect(body).toMatch(/ownPluginDirs\(|ownInstallAncestors\(/);+ expect(body).not.toMatch(/(\w+) = dirname\(\1\)/);+ });+ }++ it("a project-local install never reaches the project's own plugins/ directory", () => {+ const project = scratch();+ const cliDir = join(project, 'node_modules', '@claude-flow', 'cli', 'dist', 'src', 'mcp-tools');+ for (const plugin of ['ruflo-testgen', 'ruflo-metaharness']) {+ const dirs = [...ownPluginDirs(cliDir, plugin, 'scripts'), ...ownInstallAncestors(cliDir).map((d) => join(d, 'plugins', plugin))];+ expect(dirs.length).toBeGreaterThan(0);+ // Every candidate is inside the package; none is the project or above it.+ for (const d of dirs) expect(d.startsWith(join(project, 'node_modules', '@claude-flow', 'cli')) || d.startsWith(join(project, 'node_modules', '@claude-flow', 'plugins'))).toBe(true);+ expect(dirs).not.toContain(join(project, 'plugins', plugin, 'scripts'));+ }+ // The package's own bundled plugin is still found.+ expect(ownPluginDirs(cliDir, 'ruflo-metaharness', 'scripts')).toContain(+ join(project, 'node_modules', '@claude-flow', 'cli', 'plugins', 'ruflo-metaharness', 'scripts'),+ );+ });++ it('pnpm and global layouts stop at their node_modules too', () => {+ const pnpm = '/p/node_modules/.pnpm/@claude-flow+cli@1/node_modules/@claude-flow/cli/dist/src/commands';+ expect(ownInstallAncestors(pnpm)).not.toContain('/p/node_modules/.pnpm/@claude-flow+cli@1');+ expect(ownInstallAncestors('/usr/lib/node_modules/@claude-flow/cli/dist/src')).toEqual([+ '/usr/lib/node_modules/@claude-flow/cli/dist/src',+ '/usr/lib/node_modules/@claude-flow/cli/dist',+ '/usr/lib/node_modules/@claude-flow/cli',+ '/usr/lib/node_modules/@claude-flow',+ ]);+ });++ it('a source checkout still reaches the repo root (monorepo dev)', () => {+ const repo = '/work/ruflo';+ expect(ownPluginDirs(`${repo}/v3/@claude-flow/cli/src/mcp-tools`, 'ruflo-testgen', 'scripts')).toContain(+ `${repo}/plugins/ruflo-testgen/scripts`,+ );+ });+});+describe('ruflo-ruos resolveCallTool at runtime', () => {it("never imports a dispatcher planted in the project's node_modules", async () => {const project = scratch();diff --git a/v3/@claude-flow/cli/src/commands/doctor.ts b/v3/@claude-flow/cli/src/commands/doctor.tsindex 6be2781f6d..97eaa30d6b 100644--- a/v3/@claude-flow/cli/src/commands/doctor.ts+++ b/v3/@claude-flow/cli/src/commands/doctor.ts@@ -11,6 +11,7 @@ import { existsSync, readFileSync, statSync, openSync, readSync, closeSync } froimport { join, dirname } from 'path';import { fileURLToPath, pathToFileURL } from 'url';import { createHash } from 'crypto';+import { ownInstallAncestors } from '../plugins/own-install.js';import { execSync, exec, execFile } from 'child_process';import { promisify } from 'util';import { decodeKey, isEncryptionEnabled } from '../encryption/vault.js';@@ -2117,11 +2118,10 @@ async function checkMetaharnessIntegration(): Promise<HealthCheck> {// installs and monorepo dev. The plugin found here is imported below, so it// must come from this CLI's own install, never from the cwd (the project).try {+ // Bounded at node_modules: a project-local install must not reach the project.const selfDir = dirname(fileURLToPath(import.meta.url));- let q = selfDir;- for (let i = 0; i < 8; i++) {+ for (const q of ownInstallAncestors(selfDir)) {candidates.push(join(q, 'plugins', 'ruflo-metaharness'));- q = dirname(q);}} catch {// import.meta.url unavailable under some bundlers — the plugin is reported absent.diff --git a/v3/@claude-flow/cli/src/commands/metaharness.ts b/v3/@claude-flow/cli/src/commands/metaharness.tsindex 2f4804173c..fe6e72c970 100644--- a/v3/@claude-flow/cli/src/commands/metaharness.ts+++ b/v3/@claude-flow/cli/src/commands/metaharness.ts@@ -41,6 +41,7 @@ import { existsSync, readFileSync } from 'fs';import { join, dirname, resolve } from 'path';import { fileURLToPath } from 'url';import { homedir } from 'os';+import { ownPluginDirs } from '../plugins/own-install.js';import { runFlywheelWorker } from '../services/harness-flywheel-runtime.js';import {listFlywheelReceipts,@@ -220,14 +221,9 @@ async function dispatchFlywheel(* `prepublishOnly`).*/function locatePluginScripts(requiredScript?: string): 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);- }+ // Up from the cli dist dir, bounded at node_modules: a project-local install+ // must not reach the project.+ const candidates: string[] = ownPluginDirs(__dirname, 'ruflo-metaharness', 'scripts');// The scripts are executed, so they come from this CLI's own install (or the// user's marketplace checkout), never from the cwd: scoring a repo must not// run plugin code that repo supplies. The repo is still the scoring target.diff --git a/v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.tsindex 6551dbca66..5b8e5ad981 100644--- a/v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/metaharness-tools.ts@@ -54,6 +54,7 @@ import { existsSync, readFileSync } from 'node:fs';import { join, dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { homedir } from 'node:os';+import { ownPluginDirs } from '../plugins/own-install.js';import { runFlywheelWorker } from '../services/harness-flywheel-runtime.js';import { evaluatePolicyRequest } from '../services/policy-runtime.js';import {@@ -77,13 +78,8 @@ const __dirname = dirname(fileURLToPath(import.meta.url));* script.*/function locatePluginScripts(requiredScript?: string): string | null {- const candidates: string[] = [];- 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);- }+ // Bounded at node_modules: a project-local install must not reach the project.+ const candidates: string[] = ownPluginDirs(__dirname, 'ruflo-metaharness', 'scripts');// Scripts found here are executed, so they come from this CLI's own install// (or the user's marketplace checkout), never from the project's cwd.candidates.push(join(homedir(), '.claude', 'plugins', 'marketplaces', 'ruflo', 'plugins', 'ruflo-metaharness', 'scripts'));diff --git a/v3/@claude-flow/cli/src/mcp-tools/testgen-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/testgen-tools.tsindex e698ef79b6..bd317d04de 100644--- a/v3/@claude-flow/cli/src/mcp-tools/testgen-tools.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/testgen-tools.ts@@ -28,6 +28,7 @@ import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import type { MCPTool } from './types.js';import { homedir } from 'node:os';+import { ownPluginDirs } from '../plugins/own-install.js';const __filename = fileURLToPath(import.meta.url);const __dirname = dirname(__filename);@@ -42,13 +43,8 @@ const __dirname = dirname(__filename);* today) — when that lands at a candidate path, we've found the dir.*/function locateTestgenScripts(): string | null {- const candidates: string[] = [];- let p = resolve(__dirname);- for (let i = 0; i < 8; i++) {- candidates.push(join(p, 'plugins', 'ruflo-testgen', 'scripts'));- candidates.push(join(p, '..', 'plugins', 'ruflo-testgen', 'scripts'));- p = dirname(p);- }+ // Bounded at node_modules: a project-local install must not reach the project.+ const candidates: string[] = ownPluginDirs(__dirname, 'ruflo-testgen', 'scripts');// Scripts found here are executed, so they come from this CLI's own install// (or the user's marketplace checkout), never from the project's cwd.candidates.push(join(homedir(), '.claude', 'plugins', 'marketplaces', 'ruflo', 'plugins', 'ruflo-testgen', 'scripts'));diff --git a/v3/@claude-flow/cli/src/plugins/own-install.ts b/v3/@claude-flow/cli/src/plugins/own-install.tsnew file mode 100644index 0000000000..9a1330cddb--- /dev/null+++ b/v3/@claude-flow/cli/src/plugins/own-install.ts@@ -0,0 +1,49 @@+/**+ * Where the CLI may load executable plugin code from: its OWN install only.+ *+ * Several callers walk up from their own module location to find a bundled+ * plugin directory (`plugins/ruflo-*`) whose scripts they then import or spawn.+ * A project-local install lives at `<project>/node_modules/@claude-flow/cli/...`,+ * so an unbounded walk-up leaves the package, crosses `node_modules`, and lands in+ * `<project>` itself, where `<project>/plugins/ruflo-*` is whatever the opened+ * repository ships. The walk must therefore stop at the `node_modules` boundary:+ * everything above it belongs to whoever installed the package (a project, a+ * global prefix, an npx cache), not to the package.+ */+import { basename, dirname, join, resolve } from 'node:path';++/**+ * Directories from `startDir` upward that still belong to the package's own+ * install: `startDir` and its ancestors, up to but excluding the first+ * `node_modules` directory. In a source checkout (no `node_modules` between the+ * module and the repo root) this reaches the repo root, as monorepo dev needs.+ */+export function ownInstallAncestors(startDir: string, maxDepth = 8): string[] {+ const dirs: string[] = [];+ let p = resolve(startDir);+ for (let i = 0; i < maxDepth; i++) {+ if (basename(p) === 'node_modules') break;+ dirs.push(p);+ const parent = dirname(p);+ if (parent === p) break;+ p = parent;+ }+ return dirs;+}++/**+ * Candidate `<ancestor>/plugins/<plugin>/<...sub>` directories inside the+ * package's own install (see {@link ownInstallAncestors}). The `<ancestor>/../plugins`+ * form (the sibling of a package root) is only produced when that sibling is itself+ * still inside the own-install boundary.+ */+export function ownPluginDirs(startDir: string, plugin: string, ...sub: string[]): string[] {+ const ancestors = ownInstallAncestors(startDir);+ const inside = new Set(ancestors);+ const out: string[] = [];+ for (const p of ancestors) {+ out.push(join(p, 'plugins', plugin, ...sub));+ if (inside.has(dirname(p))) out.push(join(p, '..', 'plugins', plugin, ...sub));+ }+ return out;+}diff --git a/v3/@claude-flow/embeddings/src/embedding-service.ts b/v3/@claude-flow/embeddings/src/embedding-service.tsindex 790ae4ffa3..2b72a61a09 100644--- a/v3/@claude-flow/embeddings/src/embedding-service.ts+++ b/v3/@claude-flow/embeddings/src/embedding-service.ts@@ -670,18 +670,26 @@ export class AgenticFlowEmbeddingService extends BaseEmbeddingService {// Try proper package exports first (preferred)possiblePaths.push('agentic-flow/embeddings');- // File fallback: resolve from this package's own location, never from- // the cwd or a fixed path — the module found here is imported.+ // Try node_modules resolution from different locations (for file:// imports)try {- const { createRequire } = await import('module');- const { existsSync } = await import('fs');const path = await import('path');- const require = createRequire(import.meta.url);- const pkgDir = path.dirname(require.resolve('agentic-flow/package.json'));- const embedder = path.join(pkgDir, 'dist/embeddings/optimized-embedder.js');- if (existsSync(embedder)) possiblePaths.push(embedder);+ const { existsSync } = await import('fs');+ const cwd = process.cwd();++ // Prioritize absolute paths that exist (for file:// import fallback)+ const absolutePaths = [+ path.join(cwd, 'node_modules/agentic-flow/dist/embeddings/optimized-embedder.js'),+ path.join(cwd, '../node_modules/agentic-flow/dist/embeddings/optimized-embedder.js'),+ '/workspaces/claude-flow/node_modules/agentic-flow/dist/embeddings/optimized-embedder.js',+ ];++ for (const p of absolutePaths) {+ if (existsSync(p)) {+ possiblePaths.push(p);+ }+ }} catch {- // agentic-flow not resolvable from this package+ // fs/path module not available}// Try each path