diff --git a/packages/vscode/src/extension.ts b/packages/vscode/src/extension.ts index f886e363..652796be 100644 --- a/packages/vscode/src/extension.ts +++ b/packages/vscode/src/extension.ts @@ -4,6 +4,7 @@ import { AgentManagerPanelProvider } from './AgentManagerPanelProvider'; import { SessionEditorPanelProvider } from './SessionEditorPanelProvider'; import { createOpenCodeManager, type OpenCodeManager } from './opencode'; import { startGlobalEventWatcher, stopGlobalEventWatcher, setChatViewProvider } from './sessionActivityWatcher'; +import { pathsEqualWithNormalizedDriveLetter } from './pathUtils'; import { resolveWorkspaceFolders } from './workspaceResolver'; let chatViewProvider: ChatViewProvider | undefined; @@ -537,7 +538,9 @@ export async function activate(context: vscode.ExtensionContext) { const debug = openCodeManager?.getDebugInfo(); const resolvedApiUrl = openCodeManager?.getApiUrl(); const workingDirectory = openCodeManager?.getWorkingDirectory() ?? ''; - const workingDirectoryMatchesWorkspace = Boolean(primaryWorkspace && workingDirectory === primaryWorkspace); + const workingDirectoryMatchesWorkspace = Boolean( + primaryWorkspace && pathsEqualWithNormalizedDriveLetter(workingDirectory, primaryWorkspace) + ); let resolvedApiPath = ''; if (resolvedApiUrl) { try { diff --git a/packages/vscode/src/pathUtils.test.ts b/packages/vscode/src/pathUtils.test.ts new file mode 100644 index 00000000..0088124b --- /dev/null +++ b/packages/vscode/src/pathUtils.test.ts @@ -0,0 +1,24 @@ +import assert from 'node:assert/strict'; +import { describe, test } from 'node:test'; +import { pathsEqualWithNormalizedDriveLetter } from './pathUtils'; + +describe('pathsEqualWithNormalizedDriveLetter', () => { + test('matches Windows paths that differ only in drive-letter case', () => { + assert.equal( + pathsEqualWithNormalizedDriveLetter('C:\\Users\\user\\project', 'c:\\Users\\user\\project'), + true + ); + }); + + test('does not ignore case outside the drive letter', () => { + assert.equal( + pathsEqualWithNormalizedDriveLetter('C:\\Users\\user\\project', 'C:\\Users\\User\\project'), + false + ); + }); + + test('preserves exact comparison for paths without a Windows drive letter', () => { + assert.equal(pathsEqualWithNormalizedDriveLetter('/work/project', '/work/project'), true); + assert.equal(pathsEqualWithNormalizedDriveLetter('/work/project', '/work/other'), false); + }); +}); diff --git a/packages/vscode/src/pathUtils.ts b/packages/vscode/src/pathUtils.ts index 85245a9d..0dd63c74 100644 --- a/packages/vscode/src/pathUtils.ts +++ b/packages/vscode/src/pathUtils.ts @@ -7,3 +7,6 @@ */ export const normalizeWindowsDriveLetter = (p: string): string => p.replace(/^([a-z]):/, (_, letter: string) => letter.toUpperCase() + ':'); + +export const pathsEqualWithNormalizedDriveLetter = (left: string, right: string): boolean => + normalizeWindowsDriveLetter(left) === normalizeWindowsDriveLetter(right);