🌊 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): read the version of a claude.cmd shim on Windows (#4397 part 3) (#4408)
rUva413f4781230
diff --git a/v3/@claude-flow/cli/__tests__/mods-claude-installs-cmd-shim-4397.test.ts b/v3/@claude-flow/cli/__tests__/mods-claude-installs-cmd-shim-4397.test.tsnew file mode 100644index 0000000000..0176d3f147--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/mods-claude-installs-cmd-shim-4397.test.ts@@ -0,0 +1,30 @@+// #4397 part 3: an npm-global claude.cmd shim must be probed through cmd.exe,+// not execFile'd directly (Node rejects that with EINVAL on Windows).+import { describe, it, expect } from 'vitest';+import { versionProbe } from '../src/mods/claude-installs.js';++describe('versionProbe (#4397)', () => {+ const shim = 'C:\\Users\\me\\AppData\\Roaming\\npm\\claude.cmd';+ it('routes a .cmd shim on win32 through cmd.exe with a quoted path', () => {+ const p = versionProbe(shim, 'win32', 'cmd.exe');+ expect(p).toEqual({+ command: 'cmd.exe',+ args: ['/d', '/s', '/c', `""${shim}" --version"`],+ windowsVerbatimArguments: true,+ });+ });+ it('matches .bat and is case-insensitive', () => {+ expect(versionProbe('C:\\x\\CLAUDE.CMD', 'win32', 'cmd.exe')?.command).toBe('cmd.exe');+ expect(versionProbe('C:\\x\\c.bat', 'win32', 'cmd.exe')?.command).toBe('cmd.exe');+ });+ it('does not probe a shim path containing cmd metacharacters', () => {+ for (const bad of ['C:\\a&calc\\claude.cmd', 'C:\\a%PATH%\\claude.cmd', 'C:\\a^b\\claude.cmd', 'C:\\a|b\\claude.cmd']) {+ expect(versionProbe(bad, 'win32', 'cmd.exe')).toBeNull();+ }+ });+ it('execs .exe and non-Windows binaries directly', () => {+ expect(versionProbe('C:\\x\\claude.exe', 'win32')).toEqual({ command: 'C:\\x\\claude.exe', args: ['--version'] });+ expect(versionProbe('/usr/bin/claude', 'linux')).toEqual({ command: '/usr/bin/claude', args: ['--version'] });+ expect(versionProbe('/opt/claude.cmd', 'linux')?.command).toBe('/opt/claude.cmd');+ });+});diff --git a/v3/@claude-flow/cli/src/mods/claude-installs.ts b/v3/@claude-flow/cli/src/mods/claude-installs.tsindex 0777913454..28a1b37209 100644--- a/v3/@claude-flow/cli/src/mods/claude-installs.ts+++ b/v3/@claude-flow/cli/src/mods/claude-installs.ts@@ -32,10 +32,31 @@ export function versionLess(a: string, b: string): boolean {return false;}+export interface VersionProbe { command: string; args: string[]; windowsVerbatimArguments?: boolean }++/**+ * #4397: Node refuses to execFile a .cmd/.bat shim on Windows (EINVAL), so the+ * npm-global `claude.cmd` read as "version unknown". Shims go through cmd.exe+ * with the path quoted; a path holding cmd metacharacters is not probed at+ * all (null) rather than risk interpreting it.+ */+export function versionProbe(path: string, platform: NodeJS.Platform = process.platform, comspec = process.env.ComSpec || 'cmd.exe'): VersionProbe | null {+ if (platform === 'win32' && /\.(cmd|bat)$/i.test(path)) {+ if (/["&|<>^%\r\n]/.test(path)) return null;+ return { command: comspec, args: ['/d', '/s', '/c', `""${path}" --version"`], windowsVerbatimArguments: true };+ }+ return { command: path, args: ['--version'] };+}+/** `claude --version` of one binary, bounded; null when it cannot say. */export const defaultVersionOf: VersionOf = (path) => {+ const probe = versionProbe(path);+ if (!probe) return null;try {- const out = execFileSync(path, ['--version'], { encoding: 'utf8', timeout: 5000, stdio: ['ignore', 'pipe', 'ignore'] });+ const out = execFileSync(probe.command, probe.args, {+ encoding: 'utf8', timeout: 5000, stdio: ['ignore', 'pipe', 'ignore'],+ ...(probe.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}),+ });return out.match(/\d+\.\d+\.\d+/)?.[0] ?? null;} catch {return null;