diff --git a/electron/main/utils/process.ts b/electron/main/utils/process.ts index 84d58571f..9382c0f63 100644 --- a/electron/main/utils/process.ts +++ b/electron/main/utils/process.ts @@ -943,7 +943,8 @@ export function ensureNpmWrappersForBrowserToolkit( const eigentBinDir = path.join(os.homedir(), '.eigent', 'bin'); fs.mkdirSync(eigentBinDir, { recursive: true }); - const wrapperVersion = '1'; + // Store wrapper target so wrappers are recreated when venv path changes (e.g. app upgrade) + const wrapperVersion = `wrapper:${pythonPath}`; const versionFile = path.join(eigentBinDir, '.npm_wrapper_version'); const storedVersion = fs.existsSync(versionFile) ? fs.readFileSync(versionFile, 'utf-8').trim() @@ -958,10 +959,14 @@ export function ensureNpmWrappersForBrowserToolkit( process.platform === 'win32' ? 'npx.cmd' : 'npx' ); + // Recreate wrappers when: version changed, wrappers missing, or existing shebang points to wrong Python const needsUpdate = storedVersion !== wrapperVersion || !fs.existsSync(npmWrapper) || - !fs.existsSync(npxWrapper); + !fs.existsSync(npxWrapper) || + (process.platform !== 'win32' && + fs.existsSync(npmWrapper) && + !fs.readFileSync(npmWrapper, 'utf-8').startsWith(`#!${pythonPath}`)); if (needsUpdate) { try {