diff --git a/packages/app/src/utils/path-key.ts b/packages/app/src/utils/path-key.ts index 68d53e91d863..671d2dec319d 100644 --- a/packages/app/src/utils/path-key.ts +++ b/packages/app/src/utils/path-key.ts @@ -6,19 +6,13 @@ const isDrive = (value: string) => { return value[1] === ":" && ((code >= 65 && code <= 90) || (code >= 97 && code <= 122)) } -const trimTrailingSlashes = (value: string) => { - for (let i = value.length - 1; i >= 0; i--) { - if (value[i] !== "/") return value.slice(0, i + 1) - } - return "" -} - const isWindowsPath = (value: string) => value[1] === ":" || value.startsWith("\\\\") export const pathKey = (path: string) => { - const value = isWindowsPath(path) ? path.replaceAll("\\", "/") : path - const trimmed = trimTrailingSlashes(value) - if (!trimmed && value.startsWith("/")) return "/" as PathKey - if (isDrive(trimmed)) return `${trimmed}/` as PathKey + let value = isWindowsPath(path) ? path.replaceAll("\\", "/") : path + if (/^\/+$/.test(value)) return "/" as PathKey + if (isDrive(value)) return `${value}/` as PathKey + const trimmed = value.replace(/\/+$/, "") + if (!trimmed) return "/" as PathKey return trimmed as PathKey } diff --git a/packages/opencode/src/session/session.ts b/packages/opencode/src/session/session.ts index 5e574d9911f5..b84c240f7f48 100644 --- a/packages/opencode/src/session/session.ts +++ b/packages/opencode/src/session/session.ts @@ -514,6 +514,14 @@ export const layer: Layer.Layer { + const normalized = directory.replaceAll("\\", "/") + if (/^\/+$/.test(normalized)) return normalized + const driveMatch = normalized.match(/^([A-Za-z]:)\/+$/) + if (driveMatch) return `${driveMatch[1]}/` + return normalized.replace(/\/+$/, "") + } + const createNext = Effect.fn("Session.createNext")(function* (input: { id?: SessionID title?: string @@ -531,7 +539,7 @@ export const layer: Layer.Layer