Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(agents): normalize detected CLI versions (#18227)

AmAzing-dcc08da41348
diff --git a/apps/desktop/src/main/modules/binaries/__tests__/cliAgentBinaries.test.ts b/apps/desktop/src/main/modules/binaries/__tests__/cliAgentBinaries.test.ts
index 99d390075c7..d2f85d410ab 100644
--- a/apps/desktop/src/main/modules/binaries/__tests__/cliAgentBinaries.test.ts
+++ b/apps/desktop/src/main/modules/binaries/__tests__/cliAgentBinaries.test.ts
@@ -119,7 +119,7 @@ describe('cliAgentBinaries', () => {
expect(status.available).toBe(true);
expect(status.path).toBe(`${npmDir}\\claude.cmd`);
- expect(status.version).toBe('1.2.3 (Claude Code)');
+ expect(status.version).toBe('1.2.3');
expect(execMock).not.toHaveBeenCalled();
expect(execFileMock).toHaveBeenCalledTimes(2);
@@ -354,7 +354,7 @@ describe('cliAgentBinaries', () => {
expect(status.available).toBe(true);
expect(status.path).toBe(path.join(os.homedir(), '.local', 'bin', 'claude'));
- expect(status.version).toBe('2.1.196 (Claude Code)');
+ expect(status.version).toBe('2.1.196');
expect(execFileMock).toHaveBeenCalledTimes(2);
expect(execFileMock.mock.calls[0]![0]).toBe('which');
@@ -410,7 +410,7 @@ describe('cliAgentBinaries', () => {
expect(status.available).toBe(true);
expect(status.path).toBe('/Applications/ChatGPT.app/Contents/Resources/codex');
- expect(status.version).toBe('codex-cli 0.138.0');
+ expect(status.version).toBe('0.138.0');
expect(execFileMock).toHaveBeenCalledTimes(2);
expect(execFileMock.mock.calls[0]![0]).toBe('which');
@@ -480,7 +480,7 @@ describe('cliAgentBinaries', () => {
expect(status.available).toBe(true);
expect(status.path).toBe('/Users/Hanam/.local/share/mise/shims/gemini');
- expect(status.version).toBe('gemini 0.2.0');
+ expect(status.version).toBe('0.2.0');
// The login-shell PATH that resolved the shim must be surfaced so the
// spawn site can carry it into the child env (mise/nvm `node` lives
// there, not on the leaner inherited PATH).
diff --git a/packages/heterogeneous-agents/src/scan/scanHost.test.ts b/packages/heterogeneous-agents/src/scan/scanHost.test.ts
index 05e3cb88e86..99db7b2fd13 100644
--- a/packages/heterogeneous-agents/src/scan/scanHost.test.ts
+++ b/packages/heterogeneous-agents/src/scan/scanHost.test.ts
@@ -22,7 +22,7 @@ describe('platform command scanning', () => {
available: true,
path: '/resolved/bin/openclaw',
resolvedPathEnv: '/resolved/bin:/usr/bin',
- version: 'openclaw 1.2.3',
+ version: '1.2.3',
});
await expect(resolveRemotePlatformCommand('openclaw')).resolves.toEqual({
@@ -41,7 +41,7 @@ describe('platform command scanning', () => {
available: true,
path: '/private/bin/hermes',
resolvedPathEnv: '/private/bin:/usr/bin',
- version: 'Hermes Agent v0.9.0 (build 1)',
+ version: '0.9.0',
});
await expect(probeRemotePlatform('hermes')).resolves.toEqual({
diff --git a/packages/heterogeneous-agents/src/scan/scanHost.ts b/packages/heterogeneous-agents/src/scan/scanHost.ts
index adb6e41df3c..1ea347d1861 100644
--- a/packages/heterogeneous-agents/src/scan/scanHost.ts
+++ b/packages/heterogeneous-agents/src/scan/scanHost.ts
@@ -1,13 +1,7 @@
-import {
- HETEROGENEOUS_AGENT_CONFIGS,
- REMOTE_HETEROGENEOUS_AGENT_CONFIGS,
- type RemoteHeterogeneousAgentType,
-} from '../config';
-import {
- type CliCommandStatus,
- detectHeterogeneousCliCommand,
- detectValidatedCommand,
-} from '../spawn/resolveCliCommand';
+import type { RemoteHeterogeneousAgentType } from '../config';
+import { HETEROGENEOUS_AGENT_CONFIGS, REMOTE_HETEROGENEOUS_AGENT_CONFIGS } from '../config';
+import type { CliCommandStatus } from '../spawn/resolveCliCommand';
+import { detectHeterogeneousCliCommand, detectValidatedCommand } from '../spawn/resolveCliCommand';
import type { HeterogeneousAgentScanMap, HeterogeneousAgentScanStatus } from './types';
/**
@@ -18,15 +12,6 @@ import type { HeterogeneousAgentScanMap, HeterogeneousAgentScanStatus } from './
* (`@lobechat/heterogeneous-agents/scanHost`), never from a browser bundle.
*/
-// openclaw prints "openclaw x.y.z"; hermes prints "Hermes Agent vX.Y.Z (...)"
-const parsePlatformVersion = (type: RemoteHeterogeneousAgentType, output: string) => {
- if (type === 'hermes') {
- const match = output.match(/v(\d+\.\d+\.\d+)/);
- if (match) return match[1];
- }
- return output.split(/\s+/).at(-1);
-};
-
/**
* Resolve and validate a notify-based platform executable using the same
* login-shell PATH and Windows npm-shim handling as the CLI agent resolver.
@@ -35,12 +20,7 @@ const parsePlatformVersion = (type: RemoteHeterogeneousAgentType, output: string
*/
export const resolveRemotePlatformCommand = async (
type: RemoteHeterogeneousAgentType,
-): Promise<CliCommandStatus> => {
- const status = await detectValidatedCommand(type, { validateKeywords: [type] });
- return status.version
- ? { ...status, version: parsePlatformVersion(type, status.version) }
- : status;
-};
+): Promise<CliCommandStatus> => detectValidatedCommand(type, { validateKeywords: [type] });
export const probeRemotePlatform = async (
type: RemoteHeterogeneousAgentType,
diff --git a/packages/heterogeneous-agents/src/spawn/resolveCliCommand.test.ts b/packages/heterogeneous-agents/src/spawn/resolveCliCommand.test.ts
index ccb09f99120..61653a7859d 100644
--- a/packages/heterogeneous-agents/src/spawn/resolveCliCommand.test.ts
+++ b/packages/heterogeneous-agents/src/spawn/resolveCliCommand.test.ts
@@ -102,9 +102,10 @@ describe('resolveCliCommand', () => {
platformMock.mockReturnValue('darwin');
});
- it('resolves AMP on PATH and validates its help banner', async () => {
+ it('resolves Amp on PATH and reports its normalized version', async () => {
callExecFile('/Users/x/.local/bin/amp\n');
callExecFile('Amp CLI\n\nUsage: amp [options] [command]');
+ callExecFile('0.0.1786551414-g7b8b6b (released 2026-08-12T16:16:54.000Z, 38m ago)');
const { detectHeterogeneousCliCommand } = await importModule();
const status = await detectHeterogeneousCliCommand('amp', 'amp');
@@ -112,21 +113,37 @@ describe('resolveCliCommand', () => {
expect(status).toMatchObject({
available: true,
path: '/Users/x/.local/bin/amp',
- version: 'Amp CLI',
+ version: '0.0.1786551414-g7b8b6b',
});
expect(execFileMock.mock.calls[1]![1]).toEqual(['--help']);
+ expect(execFileMock.mock.calls[2]![1]).toEqual(['--version']);
+ });
+
+ it('keeps an older Amp available when it does not support the version flag', async () => {
+ callExecFile('/Users/x/.local/bin/amp\n');
+ callExecFile('Amp CLI\n\nUsage: amp [options] [command]');
+ callExecFileError(new Error('unknown option: --version'));
+
+ const { detectHeterogeneousCliCommand } = await importModule();
+ const status = await detectHeterogeneousCliCommand('amp', 'amp');
+
+ expect(status).toMatchObject({
+ available: true,
+ path: '/Users/x/.local/bin/amp',
+ });
+ expect(status.version).toBeUndefined();
});
it('resolves `codex` on PATH and validates it via execFile (no shell)', async () => {
callExecFile('/usr/local/bin/codex\n');
- callExecFile('codex-cli 0.142.5');
+ callExecFile('codex-cli 0.147.0-alpha.6.6');
const { detectHeterogeneousCliCommand } = await importModule();
const status = await detectHeterogeneousCliCommand('codex', 'codex');
expect(status.available).toBe(true);
expect(status.path).toBe('/usr/local/bin/codex');
- expect(status.version).toBe('codex-cli 0.142.5');
+ expect(status.version).toBe('0.147.0-alpha.6.6');
expect(status.resolvedPathEnv).toBeUndefined();
expect(execMock).not.toHaveBeenCalled();
});
@@ -402,7 +419,7 @@ describe('resolveCliCommand', () => {
expect(status).toMatchObject({
available: true,
path: nativeExe,
- version: 'codex-cli 0.146.0',
+ version: '0.146.0',
});
// The unrunnable shim is never spawned: `execFile` on a .cmd throws
// EINVAL since the CVE-2024-27980 fix, so trying it would only waste a
@@ -582,6 +599,18 @@ describe('resolveCliCommand', () => {
expect(status).toMatchObject({ available: true, version: '1.18.3' });
});
+ it('reports the semantic version instead of an OpenClaw build hash', async () => {
+ callExecFile('/Users/x/.local/bin/openclaw\n');
+ callExecFile('openclaw 2026.8.8 (0790d9f)');
+
+ const { detectValidatedCommand } = await importModule();
+ const status = await detectValidatedCommand('openclaw', {
+ validateKeywords: ['openclaw'],
+ });
+
+ expect(status).toMatchObject({ available: true, version: '2026.8.8' });
+ });
+
it('still rejects output whose first line is not a version', async () => {
callExecFile('/Users/x/.local/bin/qodercli\n');
callExecFile('Usage: qodercli [command]\n1.0.39');
@@ -603,6 +632,7 @@ describe('resolveCliCommand', () => {
it('uses amp as the default command for the AMP adapter', async () => {
callExecFile('/Users/x/.local/bin/amp\n');
callExecFile('Amp CLI');
+ callExecFile('0.0.1786551414-g7b8b6b');
const { resolveHeteroSpawnCommand } = await importModule();
const resolved = await resolveHeteroSpawnCommand('amp', undefined);
diff --git a/packages/heterogeneous-agents/src/spawn/resolveCliCommand.ts b/packages/heterogeneous-agents/src/spawn/resolveCliCommand.ts
index d1685b2aa4b..56719ec8923 100644
--- a/packages/heterogeneous-agents/src/spawn/resolveCliCommand.ts
+++ b/packages/heterogeneous-agents/src/spawn/resolveCliCommand.ts
@@ -49,6 +49,7 @@ interface ValidateOptions {
validateFlag?: string;
validateKeywords?: string[];
validatePattern?: RegExp;
+ versionFlag?: string;
}
interface ResolvedCommand {
@@ -56,6 +57,11 @@ interface ResolvedCommand {
path: string;
}
+const VERSION_PATTERN = /v?(\d+\.\d+\.\d+(?:[-+][\dA-Za-z.-]+)?)/;
+
+const extractVersion = (versionBanner: string): string | undefined =>
+ versionBanner.match(VERSION_PATTERN)?.[1];
+
const isWindows = () => platform() === 'win32';
let shellPathPromise: Promise<string | undefined> | undefined;
let registryPathPromise: Promise<string | undefined> | undefined;
@@ -376,7 +382,7 @@ export const detectValidatedCommand = async (
if (!trimmedCommand) return { available: false };
if (isWindows() && WINDOWS_SHELL_METAS.test(trimmedCommand)) return { available: false };
- const { validateFlag = '--version', validateKeywords, validatePattern } = options;
+ const { validateFlag = '--version', validateKeywords, validatePattern, versionFlag } = options;
// Resolve via where/which BEFORE invoking. On Windows this is what discovers
// npm-installed shims like `claude.cmd` under %APPDATA%\npm — `execFile`
@@ -414,6 +420,24 @@ export const detectValidatedCommand = async (
return { available: false };
}
+ let versionBanner = firstLine;
+ if (versionFlag && versionFlag !== validateFlag) {
+ try {
+ const versionResult = await execProbe(resolvedPath, [versionFlag], env, viaShell);
+ if (versionResult !== UNRESOLVED_SHIM) {
+ versionBanner = `${versionResult.stdout}\n${versionResult.stderr}`
+ .trim()
+ .split(/\r?\n/)[0]!
+ .trim();
+ }
+ } catch {
+ // Validation already proved the binary is available. Older releases
+ // may not support the separate version flag, so keep the successful
+ // detection and omit its version instead of reporting it unavailable.
+ versionBanner = '';
+ }
+ }
+
return {
available: true,
path: resolvedPath,
@@ -423,7 +447,11 @@ export const detectValidatedCommand = async (
// `#!/usr/bin/env node` shim resolved here can't find `node` under the
// leaner inherited PATH (Finder-launched Electron).
resolvedPathEnv: env?.PATH,
- version: firstLine,
+ // CLIs format their banners differently (`codex-cli 0.147.0`,
+ // `1.2.3 (Claude Code)`, etc.). Keep validation against the original
+ // output, but expose only the version so every consumer renders the same
+ // value. A product-only banner is availability evidence, not a version.
+ version: extractVersion(versionBanner),
};
};
@@ -454,6 +482,7 @@ const HETEROGENEOUS_CLI_AGENT_OPTIONS = {
'amp': {
validateFlag: '--help',
validateKeywords: ['Amp CLI'],
+ versionFlag: '--version',
},
'claude-code': {
validateKeywords: ['claude code'],