diff --git a/packages/cli/src/ui/hooks/useLaunchEditor.ts b/packages/cli/src/ui/hooks/useLaunchEditor.ts index 14e2f56e8..d3aeb1837 100644 --- a/packages/cli/src/ui/hooks/useLaunchEditor.ts +++ b/packages/cli/src/ui/hooks/useLaunchEditor.ts @@ -29,17 +29,29 @@ const editorCommands: Record< trae: { win32: ['trae'], default: ['trae'] }, }; +/** + * Cache for command existence checks to avoid repeated execSync calls. + */ +const commandExistsCache = new Map(); + /** * Check if a command exists in the system. + * Results are cached to improve performance in test environments. */ function commandExists(cmd: string): boolean { + if (commandExistsCache.has(cmd)) { + return commandExistsCache.get(cmd)!; + } + try { execSync( process.platform === 'win32' ? `where.exe ${cmd}` : `command -v ${cmd}`, { stdio: 'ignore' }, ); + commandExistsCache.set(cmd, true); return true; } catch { + commandExistsCache.set(cmd, false); return false; } }