π 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(doctor): reject unsupported component selections
Rudy Celekliedbeaea602ee
diff --git a/v3/@claude-flow/cli/__tests__/doctor-component-selection.test.ts b/v3/@claude-flow/cli/__tests__/doctor-component-selection.test.tsnew file mode 100644index 0000000000..8898ee5324--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/doctor-component-selection.test.ts@@ -0,0 +1,134 @@+import { afterAll, beforeAll, describe, expect, it } from 'vitest';+import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';+import { spawnSync } from 'node:child_process';+import { createRequire } from 'node:module';+import { tmpdir } from 'node:os';+import { dirname, join, resolve } from 'node:path';+import { fileURLToPath } from 'node:url';++const cli = resolve(dirname(fileURLToPath(import.meta.url)), '..');+const requireHere = createRequire(join(cli, 'package.json'));++// The private PATH uses a real executable symlink, which requires privileges+// on Windows. The inherited platform build remains separate from these cases.+describe.skipIf(process.platform === 'win32')('doctor component selection', () => {+ let owned: string;+ let source: string;+ let runner: string;+ let semver: string;+ let nativeSqlite: string;++ beforeAll(() => {+ owned = mkdtempSync(join(tmpdir(), 'ruflo-doctor-selection-'));+ source = join(owned, 'source');+ for (const name of ['cli', 'cli-core', 'security']) {+ cpSync(join(cli, '..', name, 'src'), join(source, name, 'src'), { recursive: true });+ }+ runner = requireHere.resolve('vitest/vitest.mjs');+ semver = requireHere.resolve('semver');+ nativeSqlite = requireHere.resolve('better-sqlite3');+ // Physical source isolation keeps optional providers genuinely absent.+ const isolatedRequire = createRequire(join(source, 'cli', 'package.json'));+ for (const name of ['ruvector', '@ruvector/sona', '@huggingface/transformers', '@xenova/transformers', 'agentic-flow']) {+ expect(() => isolatedRequire.resolve(name)).toThrow();+ }+ });+ afterAll(() => { if (owned) rmSync(owned, { recursive: true, force: true }); });++ function run(args: string[], withNativeStore = false) {+ const project = mkdtempSync(join(owned, 'project-'));+ const home = join(project, 'home');+ const temp = join(project, 'tmp');+ const bin = join(project, 'bin');+ for (const directory of [home, temp, bin]) mkdirSync(directory);+ // No npm, installers or other diagnostic tools are on the private PATH.+ symlinkSync(process.execPath, join(bin, 'node'));+ const driver = join(project, 'native.test.ts');+ const config = join(project, 'native.config.mts');+ const receipt = join(project, 'receipt.json');+ writeFileSync(driver, `+import { it, expect } from 'vitest';+import { mkdirSync, writeFileSync } from 'node:fs';+import Database from 'better-sqlite3';+import { CommandParser } from ${JSON.stringify(join(source, 'cli/src/parser.ts'))};+import { doctorCommand } from ${JSON.stringify(join(source, 'cli/src/commands/doctor.ts'))};+it('registered parser and real doctor action', async () => {+ if (${JSON.stringify(withNativeStore)}) {+ mkdirSync('.swarm');+ const db = new Database('.swarm/agentdb-memory.db');+ db.exec('CREATE TABLE fixture (id INTEGER PRIMARY KEY); INSERT INTO fixture VALUES (1)');+ db.close();+ }+ const parser = new CommandParser();+ parser.registerCommand(doctorCommand);+ const parsed = parser.parse(${JSON.stringify(['doctor', ...args])});+ expect(parser.validateFlags(parsed.flags, doctorCommand)).toEqual([]);+ expect(parsed.flags.install).toBe(false);+ expect(parsed.flags.fix).toBe(false);+ const result = await doctorCommand.action!({ args: parsed.positional, flags: parsed.flags, cwd: process.cwd(), interactive: false });+ writeFileSync(${JSON.stringify(receipt)}, JSON.stringify({ parsed, result, node: process.version, bun: process.versions.bun ?? null }));+}, 10000);+`);+ writeFileSync(config, `export default ${JSON.stringify({+ root: project, cacheDir: join(project, 'cache'),+ esbuild: { tsconfigRaw: { compilerOptions: {} } },+ resolve: { alias: {+ vitest: join(dirname(runner), 'dist/index.js'),+ semver,+ 'better-sqlite3': nativeSqlite,+ '@claude-flow/cli-core': join(source, 'cli-core/src'),+ '@claude-flow/security': join(source, 'security/src'),+ } },+ test: { include: [driver], maxWorkers: 1, fileParallelism: false },+ })};`);+ const child = spawnSync(process.execPath, [runner, 'run', '--config', config, '--reporter=verbose'], {+ cwd: project,+ env: { PATH: bin, HOME: home, TMPDIR: temp, TEMP: temp, TMP: temp, CI: 'true', TERM: 'dumb',+ RUFLO_DAEMON_AUTOSTART: '0', CLAUDE_FLOW_NATIVE_ROUTER: '0', CLAUDE_FLOW_AI_WORKERS: '0', CLAUDE_FLOW_ROUTER_BRIDGE: '1' },+ encoding: 'utf8', timeout: 15000, maxBuffer: 1024 * 1024,+ });+ expect(child.error, child.stdout + child.stderr).toBeUndefined();+ expect(child.status, child.stdout + child.stderr).toBe(0);+ return JSON.parse(readFileSync(receipt, 'utf8'));+ }++ it.each(['--component', '-c'])('runs only the real Node check with %s', flag => {+ const { result, node, bun } = run([flag, 'node']);+ expect(result.success).toBe(true);+ expect(bun).toBeNull();+ expect(result.data.results).toHaveLength(1);+ expect(result.data.results[0]).toMatchObject({ name: 'Node.js Version', status: 'pass' });+ expect(result.data.results[0].message).toContain(node);+ }, 20000);++ it.each(['not-a-doctor-component', 'toString', 'constructor', '__proto__', ''])('rejects unsupported component %j without health results', component => {+ const { result } = run(['--component', component]);+ expect(result.success).toBe(false);+ expect(result.exitCode).toBe(1);+ expect(result.message).toMatch(/unknown.*component/i);+ expect(result.data).toBeUndefined();+ }, 20000);++ it.each(['learning', 'learning-bridge'])('preserves the existing %s alias', component => {+ const { result } = run(['--component', component]);+ expect(result.data.results).toHaveLength(1);+ expect(result.data.results[0].name).toBe('Learning Bridge');+ }, 20000);++ it('preserves the lazy grouped memory checks on an uninitialized private project', () => {+ const { result } = run(['--component', 'memory']);+ const names = result.data.results.map((check: { name: string }) => check.name);+ expect(names).toHaveLength(8);+ expect(names[0]).toBe('Memory Database Presence');+ expect(names).not.toContain('Node.js Version');+ expect(names).not.toContain('npm Version');+ }, 20000);++ it('includes the discovered native authority in the grouped memory checks', () => {+ const { result } = run(['--component', 'memory'], true);+ expect(result.data.results).toHaveLength(9);+ const native = result.data.results.find((check: { name: string }) => check.name === 'Native AgentDB Structural Integrity (quick_check)');+ expect(native).toMatchObject({ status: 'pass' });+ expect(native.message).toContain('PRAGMA quick_check: ok');+ }, 20000);+});diff --git a/v3/@claude-flow/cli/src/commands/doctor.ts b/v3/@claude-flow/cli/src/commands/doctor.tsindex da80b2eddf..754d4dd3d4 100644--- a/v3/@claude-flow/cli/src/commands/doctor.ts+++ b/v3/@claude-flow/cli/src/commands/doctor.ts@@ -2646,6 +2646,67 @@ export const doctorCommand: Command = {// Parser camelCases kebab-case flag names β read via `fixHandles`, not `['fix-handles']`.const fixHandles = ctx.flags.fixHandles as boolean;+ // #2677: `--component memory` now runs the whole memory-health suite,+ // not just the existence check. Values can be a single check or an+ // array β expanded at execution time. Stuinfla's report showed the+ // existence-only check reporting PASS on a 99.97%-empty and even a+ // SQLite-malformed DB; the array here layers integrity β content β+ // embedding coverage over the existing existence probe; check 6 then+ // verifies that distilled episodes are actually Reflexion-retrievable and+ // execution feedback carries a lesson.+ const componentMap: Record<string, (() => Promise<HealthCheck>) | Array<() => Promise<HealthCheck>>> = {+ 'version': checkVersionFreshness,+ 'freshness': checkVersionFreshness,+ 'node': checkNodeVersion,+ 'npm': checkNpmVersion,+ 'claude': checkClaudeCode,+ 'browser': checkAgentBrowserVersion,+ 'config': checkConfigFile,+ 'stale-settings': checkStaleSettingsNpx, // #2448+ 'helpers': () => checkHelperIntegrity(), // #3565+ 'daemon': checkDaemonStatus,+ get memory() { return [+ checkMemoryDatabase, // existing: exists + statable (unchanged)+ checkMemoryIntegrity, // #2677 check 1: sql.js open + PRAGMA integrity_check+ ...nativeAgentDbChecks, // #3195: present AgentDB authority, checked independently+ checkMemoryPersistenceDriver, // #2968/#3321: read-only native capability probe+ checkMemoryPackageVersion, // #3392: loaded memory package satisfies the declared range+ checkMemoryContent, // #2677 check 2: memory_entries content coverage+ checkMemoryEmbeddingCoverage, // #2677 check 3: vector coverage on populated rows+ checkMemoryReflexionCoverage, // #2677 check 6: episodes are retrievable+ checkMemoryCritiqueCoverage, // #2677 check 6: feedback carries lessons+ ]; },+ 'memory-package': checkMemoryPackageVersion, // #3392+ 'learning': checkLearningBridge, // #2545+ 'learning-bridge': checkLearningBridge, // #2545+ 'api': checkApiKeys,+ 'git': checkGit,+ 'mcp': checkMcpServers,+ 'mcp-overhead': checkMcpSchemaOverhead,+ 'aidefence': checkAIDefence, // #1807+ 'disk': checkDiskSpace,+ 'typescript': checkBuildTools,+ 'agentic-flow': checkAgenticFlow,+ 'encryption': checkEncryptionAtRest, // ADR-096 Phase 5+ 'federation': checkFederationBreaker, // ADR-097 Phase 4+ 'metaharness': [checkMetaharness, checkMetaharnessDeclaredPackages, checkMetaharnessIntegration], // ADR-150 β upstream + declared deps + ruflo-side+ 'metaharness-integration': checkMetaharnessIntegration, // iter 45 β ruflo-side+ 'funnel': checkFunnel, // ADR-305+ // ADR-307 β deep-dive array, same pattern as 'memory' above: the cheap+ // sponsored-consent check first, then binary/process/bind in the order+ // a user would actually debug them (is it installed? running? exposed?).+ 'proxy': [checkProxySponsoredConsent, checkProxyBinary, checkProxyProcess, checkProxyBindAddress],+ 'auth': checkAuth, // ADR-306+ 'typesafe': checkTypesafeRouter, // opt-in @ruvector/typesafe task router+ 'mods': checkMods, // ADR-404 β ruflo as a Claude Code mod+ };++ if (component !== undefined && !Object.hasOwn(componentMap, component)) {+ const message = `Unknown doctor component: ${JSON.stringify(component)}. Valid components: ${Object.keys(componentMap).join(', ')}`;+ output.printError(message);+ return { success: false, exitCode: 1, message };+ }+// Early-return short-circuit: `--fix-handles` is a targeted mitigation, not// part of the health-check flow. Runs, reports, exits.if (fixHandles) {@@ -2759,63 +2820,8 @@ export const doctorCommand: Command = {checkMods, // ADR-404 β Claude Code mod path (warn-only)];- // #2677: `--component memory` now runs the whole memory-health suite,- // not just the existence check. Values can be a single check or an- // array β expanded at execution time. Stuinfla's report showed the- // existence-only check reporting PASS on a 99.97%-empty and even a- // SQLite-malformed DB; the array here layers integrity β content β- // embedding coverage over the existing existence probe; check 6 then- // verifies that distilled episodes are actually Reflexion-retrievable and- // execution feedback carries a lesson.- const componentMap: Record<string, (() => Promise<HealthCheck>) | Array<() => Promise<HealthCheck>>> = {- 'version': checkVersionFreshness,- 'freshness': checkVersionFreshness,- 'node': checkNodeVersion,- 'npm': checkNpmVersion,- 'claude': checkClaudeCode,- 'browser': checkAgentBrowserVersion,- 'config': checkConfigFile,- 'stale-settings': checkStaleSettingsNpx, // #2448- 'helpers': () => checkHelperIntegrity(), // #3565- 'daemon': checkDaemonStatus,- 'memory': [- checkMemoryDatabase, // existing: exists + statable (unchanged)- checkMemoryIntegrity, // #2677 check 1: sql.js open + PRAGMA integrity_check- ...nativeAgentDbChecks, // #3195: present AgentDB authority, checked independently- checkMemoryPersistenceDriver, // #2968/#3321: read-only native capability probe- checkMemoryPackageVersion, // #3392: loaded memory package satisfies the declared range- checkMemoryContent, // #2677 check 2: memory_entries content coverage- checkMemoryEmbeddingCoverage, // #2677 check 3: vector coverage on populated rows- checkMemoryReflexionCoverage, // #2677 check 6: episodes are retrievable- checkMemoryCritiqueCoverage, // #2677 check 6: feedback carries lessons- ],- 'memory-package': checkMemoryPackageVersion, // #3392- 'learning': checkLearningBridge, // #2545- 'learning-bridge': checkLearningBridge, // #2545- 'api': checkApiKeys,- 'git': checkGit,- 'mcp': checkMcpServers,- 'mcp-overhead': checkMcpSchemaOverhead,- 'aidefence': checkAIDefence, // #1807- 'disk': checkDiskSpace,- 'typescript': checkBuildTools,- 'agentic-flow': checkAgenticFlow,- 'encryption': checkEncryptionAtRest, // ADR-096 Phase 5- 'federation': checkFederationBreaker, // ADR-097 Phase 4- 'metaharness': [checkMetaharness, checkMetaharnessDeclaredPackages, checkMetaharnessIntegration], // ADR-150 β upstream + declared deps + ruflo-side- 'metaharness-integration': checkMetaharnessIntegration, // iter 45 β ruflo-side- 'funnel': checkFunnel, // ADR-305- // ADR-307 β deep-dive array, same pattern as 'memory' above: the cheap- // sponsored-consent check first, then binary/process/bind in the order- // a user would actually debug them (is it installed? running? exposed?).- 'proxy': [checkProxySponsoredConsent, checkProxyBinary, checkProxyProcess, checkProxyBindAddress],- 'auth': checkAuth, // ADR-306- 'typesafe': checkTypesafeRouter, // opt-in @ruvector/typesafe task router- 'mods': checkMods, // ADR-404 β ruflo as a Claude Code mod- };-let checksToRun = allChecks;- if (component && componentMap[component]) {+ if (component !== undefined) {const entry = componentMap[component];checksToRun = Array.isArray(entry) ? entry : [entry];}