fix(vscode): improve opencode binary detection

This commit is contained in:
Bohdan Triapitsyn
2026-06-04 14:59:33 +03:00
parent 83d8ca3c74
commit e26f87a57c
+21 -8
View File
@@ -10,7 +10,11 @@ import { randomBytes } from 'crypto';
import { normalizeWindowsDriveLetter } from './pathUtils'; import { normalizeWindowsDriveLetter } from './pathUtils';
const READY_CHECK_TIMEOUT_MS = 30000; const READY_CHECK_TIMEOUT_MS = 30000;
const WINDOWS_EXECUTABLE_EXTENSIONS = ['', '.exe', '.cmd', '.bat', '.com']; const WINDOWS_EXECUTABLE_EXTENSIONS = (process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM')
.split(';')
.map((ext) => ext.trim().toLowerCase())
.filter(Boolean)
.map((ext) => (ext.startsWith('.') ? ext : `.${ext}`));
export type ConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error'; export type ConnectionStatus = 'disconnected' | 'connecting' | 'connected' | 'error';
export type OpenCodeDebugInfo = { export type OpenCodeDebugInfo = {
@@ -336,10 +340,12 @@ function resolveOpencodeCliPath(): string | null {
].filter(Boolean); ].filter(Boolean);
})(); })();
const fromPath = findExecutableInPath('opencode'); if (process.platform !== 'win32') {
if (fromPath) { const fromPath = findExecutableInPath('opencode');
cachedDetectedOpencodeCliPath = fromPath; if (fromPath) {
return fromPath; cachedDetectedOpencodeCliPath = fromPath;
return fromPath;
}
} }
const fallbacks = process.platform === 'win32' ? winFallbacks : unixFallbacks; const fallbacks = process.platform === 'win32' ? winFallbacks : unixFallbacks;
@@ -351,6 +357,12 @@ function resolveOpencodeCliPath(): string | null {
} }
if (process.platform === 'win32') { if (process.platform === 'win32') {
const fromPath = findExecutableInPath('opencode');
if (fromPath) {
cachedDetectedOpencodeCliPath = fromPath;
return fromPath;
}
try { try {
const result = spawnSync('where', ['opencode'], { const result = spawnSync('where', ['opencode'], {
encoding: 'utf8', encoding: 'utf8',
@@ -1054,16 +1066,17 @@ export function createOpenCodeManager(_context: vscode.ExtensionContext): OpenCo
getApiUrl, getApiUrl,
getOpenCodeAuthHeaders, getOpenCodeAuthHeaders,
getWorkingDirectory: () => workingDirectory, getWorkingDirectory: () => workingDirectory,
isCliAvailable: () => !cliMissing, isCliAvailable: () => !cliMissing || Boolean(cliPath || resolveOpencodeCliPath()),
getDebugInfo: () => { getDebugInfo: () => {
const secureConnection = Boolean(getOpenCodeAuthHeaders().Authorization); const secureConnection = Boolean(getOpenCodeAuthHeaders().Authorization);
const detectedCliPath = cliPath || resolveOpencodeCliPath();
return { return {
mode: useConfiguredUrl && configuredApiUrl ? 'external' : 'managed', mode: useConfiguredUrl && configuredApiUrl ? 'external' : 'managed',
status, status,
lastError, lastError,
workingDirectory, workingDirectory,
cliAvailable: !cliMissing, cliAvailable: !cliMissing || Boolean(detectedCliPath),
cliPath, cliPath: detectedCliPath,
configuredApiUrl: useConfiguredUrl && configuredApiUrl ? configuredApiUrl.replace(/\/+$/, '') : null, configuredApiUrl: useConfiguredUrl && configuredApiUrl ? configuredApiUrl.replace(/\/+$/, '') : null,
configuredPort, configuredPort,
detectedPort, detectedPort,