Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions packages/app/src/utils/path-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 9 additions & 1 deletion packages/opencode/src/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,14 @@ export const layer: Layer.Layer<Service, never, Bus.Service | Storage.Service |
const storage = yield* Storage.Service
const sync = yield* SyncEvent.Service

const normalizeDirectory = (directory: string) => {
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
Expand All @@ -531,7 +539,7 @@ export const layer: Layer.Layer<Service, never, Bus.Service | Storage.Service |
slug: Slug.create(),
version: InstallationVersion,
projectID: ctx.project.id,
directory: input.directory,
directory: normalizeDirectory(input.directory),
path: input.path,
workspaceID: input.workspaceID,
parentID: input.parentID,
Expand Down
Loading