From a07c068b667068cb8f404e6ef0ce9cc0034d5bb5 Mon Sep 17 00:00:00 2001 From: zerone0x Date: Tue, 17 Mar 2026 17:29:50 +0800 Subject: [PATCH] fix(web): normalize Windows drive letter case for session path matching (#675) On Windows, VS Code's uri.fsPath returns a lowercase drive letter (e.g. d:\MyProject) while the OpenCode server stores paths using process.cwd() which returns uppercase (D:\MyProject). This caused session queries to return empty results due to case-sensitive string comparison. Normalize drive letters to uppercase in both the VS Code extension (opencode.ts) and the shared UI client (client.ts) so that directory paths match regardless of the source casing. Fixes #670 --- packages/ui/src/lib/opencode/client.ts | 6 +++++- packages/vscode/src/opencode.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/lib/opencode/client.ts b/packages/ui/src/lib/opencode/client.ts index 0496baf1..9f8016cd 100644 --- a/packages/ui/src/lib/opencode/client.ts +++ b/packages/ui/src/lib/opencode/client.ts @@ -199,7 +199,11 @@ class OpencodeService { return null; } - const normalized = trimmed.replace(/\\/g, '/'); + // Normalize backslashes and uppercase the Windows drive letter so that + // d:\MyProject and D:\MyProject resolve to the same canonical form. + const normalized = trimmed + .replace(/\\/g, '/') + .replace(/^([a-z]):/, (_, letter: string) => letter.toUpperCase() + ':'); const withoutTrailingSlash = normalized.length > 1 ? normalized.replace(/\/+$/, '') : normalized; return withoutTrailingSlash || null; diff --git a/packages/vscode/src/opencode.ts b/packages/vscode/src/opencode.ts index 36b7e8b5..4139ddca 100644 --- a/packages/vscode/src/opencode.ts +++ b/packages/vscode/src/opencode.ts @@ -467,8 +467,13 @@ export function createOpenCodeManager(_context: vscode.ExtensionContext): OpenCo let status: ConnectionStatus = 'disconnected'; let lastError: string | undefined; const listeners = new Set<(status: ConnectionStatus, error?: string) => void>(); + /** On Windows, VS Code's uri.fsPath returns a lowercase drive letter (e.g. d:\...) + * while process.cwd() (used by OpenCode server) returns uppercase (D:\...). + * Normalize to uppercase so session directory queries match. */ + const normalizeWindowsDriveLetter = (p: string): string => + p.replace(/^([a-z]):/, (_, letter: string) => letter.toUpperCase() + ':'); const workspaceDirectory = (): string => - vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || os.homedir(); + normalizeWindowsDriveLetter(vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || os.homedir()); let workingDirectory: string = workspaceDirectory(); let startCount = 0; let restartCount = 0; @@ -577,7 +582,7 @@ export function createOpenCodeManager(_context: vscode.ExtensionContext): OpenCo lastStartAttempts = startCount; if (typeof workdir === 'string' && workdir.trim().length > 0) { - workingDirectory = workdir.trim(); + workingDirectory = normalizeWindowsDriveLetter(workdir.trim()); } else { workingDirectory = workspaceDirectory(); }