diff --git a/packages/app/e2e/projects/workspace-new-session.spec.ts b/packages/app/e2e/projects/workspace-new-session.spec.ts index 18fa46d3299..643aa1212d7 100644 --- a/packages/app/e2e/projects/workspace-new-session.spec.ts +++ b/packages/app/e2e/projects/workspace-new-session.spec.ts @@ -70,7 +70,11 @@ async function createSessionFromWorkspace(page: Page, slug: string, text: string } async function sessionDirectory(directory: string, sessionID: string) { - const info = await createSdk(directory) + // Normalize directory path for consistent comparison on Windows + // (convert backslashes to forward slashes and uppercase drive letter) + const normalizedDir = directory.replace(/\\/g, "/").replace(/^([a-z]):/, (_, drive) => drive.toUpperCase() + ":") + + const info = await createSdk(normalizedDir) .session.get({ sessionID }) .then((x) => x.data) .catch(() => undefined) diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts index 0879fe87fd3..92e1bf8e27d 100644 --- a/packages/opencode/src/session/index.ts +++ b/packages/opencode/src/session/index.ts @@ -39,6 +39,21 @@ export namespace Session { const parentTitlePrefix = "New session - " const childTitlePrefix = "Child session - " + /** + * Normalize directory path for consistent comparison across platforms. + * On Windows, paths can have different representations (e.g., B: vs b:, / vs \). + * This function ensures consistent path comparison for session listing. + */ + function normalizeDirectory(dir: string): string { + // Normalize backslashes to forward slashes + let normalized = dir.replaceAll("\\", "/") + // Normalize drive letter to uppercase for case-insensitive comparison on Windows + if (process.platform === "win32") { + normalized = normalized.replace(/^([a-z]):/, (_, drive) => drive.toUpperCase() + ":") + } + return normalized + } + function createDefaultTitle(isChild = false) { return (isChild ? childTitlePrefix : parentTitlePrefix) + new Date().toISOString() } @@ -92,7 +107,7 @@ export namespace Session { workspace_id: info.workspaceID, parent_id: info.parentID, slug: info.slug, - directory: info.directory, + directory: normalizeDirectory(info.directory), title: info.title, version: info.version, share_url: info.share?.url, @@ -552,7 +567,10 @@ export namespace Session { conditions.push(eq(SessionTable.workspace_id, WorkspaceContext.workspaceID)) } if (input?.directory) { - conditions.push(eq(SessionTable.directory, input.directory)) + // Normalize the directory path to handle Windows path variations + // (e.g., B: vs b:, / vs \) + const normalizedDir = normalizeDirectory(input.directory) + conditions.push(eq(SessionTable.directory, normalizedDir)) } if (input?.roots) { conditions.push(isNull(SessionTable.parent_id)) @@ -592,7 +610,10 @@ export namespace Session { const conditions: SQL[] = [] if (input?.directory) { - conditions.push(eq(SessionTable.directory, input.directory)) + // Normalize the directory path to handle Windows path variations + // (e.g., B: vs b:, / vs \) + const normalizedDir = normalizeDirectory(input.directory) + conditions.push(eq(SessionTable.directory, normalizedDir)) } if (input?.roots) { conditions.push(isNull(SessionTable.parent_id))