fix: improve auto-accept and Windows opencode upgrades

This commit is contained in:
Bohdan Triapitsyn
2026-06-05 13:36:39 +03:00
parent ebc2168ceb
commit 4e1560a10e
4 changed files with 141 additions and 9 deletions
@@ -62,8 +62,69 @@ export const createServerUtilsRuntime = (dependencies) => {
throw new Error('Timed out waiting for OpenCode port');
};
const getEnvValue = (name) => {
const env = process.env || {};
if (typeof env[name] === 'string') return env[name];
const key = Object.keys(env).find((candidate) => candidate.toLowerCase() === name.toLowerCase());
return key && typeof env[key] === 'string' ? env[key] : '';
};
const buildWindowsManagedToolchainPath = () => {
if (process.platform !== 'win32') return '';
const home = os.homedir();
const userProfile = getEnvValue('USERPROFILE') || home;
const appData = getEnvValue('APPDATA') || (userProfile ? path.join(userProfile, 'AppData', 'Roaming') : '');
const localAppData = getEnvValue('LOCALAPPDATA') || (userProfile ? path.join(userProfile, 'AppData', 'Local') : '');
const programFiles = getEnvValue('ProgramFiles') || 'C:\\Program Files';
const programFilesX86 = getEnvValue('ProgramFiles(x86)');
const programData = getEnvValue('ProgramData') || 'C:\\ProgramData';
const bunInstall = getEnvValue('BUN_INSTALL');
const voltaHome = getEnvValue('VOLTA_HOME');
const scoop = getEnvValue('SCOOP');
const scoopGlobal = getEnvValue('SCOOP_GLOBAL');
const candidates = [
path.join(appData, 'npm'),
path.join(programFiles, 'nodejs'),
programFilesX86 ? path.join(programFilesX86, 'nodejs') : '',
path.join(localAppData, 'Programs', 'nodejs'),
getEnvValue('PNPM_HOME'),
path.join(localAppData, 'pnpm'),
bunInstall ? path.join(bunInstall, 'bin') : '',
path.join(userProfile, '.bun', 'bin'),
voltaHome ? path.join(voltaHome, 'bin') : '',
path.join(localAppData, 'Volta', 'bin'),
path.join(localAppData, 'Yarn', 'bin'),
path.join(localAppData, 'Yarn', 'Data', 'global', 'node_modules', '.bin'),
scoop ? path.join(scoop, 'shims') : '',
path.join(userProfile, 'scoop', 'shims'),
scoopGlobal ? path.join(scoopGlobal, 'shims') : '',
path.join(programData, 'chocolatey', 'bin'),
path.join(localAppData, 'Microsoft', 'WindowsApps'),
path.join(userProfile, '.opencode', 'bin'),
path.join(userProfile, '.local', 'bin'),
];
const seen = new Set();
const existing = [];
for (const candidate of candidates) {
const trimmed = typeof candidate === 'string' ? candidate.trim() : '';
if (!trimmed) continue;
const normalized = trimmed.toLowerCase();
if (seen.has(normalized)) continue;
seen.add(normalized);
try {
if (fs.existsSync(trimmed)) existing.push(trimmed);
} catch {
}
}
return existing.join(path.delimiter);
};
const buildAugmentedPath = () => {
const currentPath = process.env.PATH || '';
const currentPath = getEnvValue('PATH');
const loginShellPath = getLoginShellPath();
const home = os.homedir();
const currentPathLooksUserConfigured = pathLooksUserConfigured(currentPath, home, path.delimiter);
@@ -74,10 +135,11 @@ export const createServerUtilsRuntime = (dependencies) => {
};
const buildManagedOpenCodePath = () => {
const currentPath = process.env.PATH || '';
const currentPath = getEnvValue('PATH');
const loginShellPath = getLoginShellPath();
const basePath = mergePathValues(loginShellPath || '', currentPath, path.delimiter);
return mergePathValues(loginShellPath || '', currentPath, path.delimiter);
return mergePathValues(basePath, buildWindowsManagedToolchainPath(), path.delimiter);
};
const parseSseDataPayload = (block) => {