diff --git a/apps/web/src/components/files/filePath.test.ts b/apps/web/src/components/files/filePath.test.ts index fbe6a67ece922..00a3247dc6508 100644 --- a/apps/web/src/components/files/filePath.test.ts +++ b/apps/web/src/components/files/filePath.test.ts @@ -33,6 +33,11 @@ describe("fileBreadcrumbs", () => { { label: ".claude", path: "~/.claude", kind: "directory" }, { label: "CLAUDE.md", path: "~/.claude/CLAUDE.md", kind: "file" }, ]); + expect(fileBreadcrumbs("t3code", "~\\.claude/CLAUDE.md")).toEqual([ + { label: "~", path: "~/", kind: "directory" }, + { label: ".claude", path: "~/.claude", kind: "directory" }, + { label: "CLAUDE.md", path: "~/.claude/CLAUDE.md", kind: "file" }, + ]); expect(isListableHostFolder("~/")).toBe(true); expect(isListableHostFolder("~/.claude")).toBe(true); }); diff --git a/apps/web/src/components/files/filePath.ts b/apps/web/src/components/files/filePath.ts index facefbb173016..b7a9d2784d973 100644 --- a/apps/web/src/components/files/filePath.ts +++ b/apps/web/src/components/files/filePath.ts @@ -16,7 +16,9 @@ export function fileBreadcrumbs(projectName: string, relativePath: string): File const windowsPath = isWindowsAbsolutePath(relativePath); const separator = windowsPath ? "\\" : "/"; // `\` is a legal filename character outside Windows paths. - const parts = relativePath.split(windowsPath ? /[\\/]/ : "/").filter(Boolean); + // The server reads `~\` as home; the rest keeps the usual relative-path spelling. + const homePath = relativePath.startsWith("~\\") ? `~/${relativePath.slice(2)}` : relativePath; + const parts = homePath.split(windowsPath ? /[\\/]/ : "/").filter(Boolean); const root = relativePath.startsWith("\\\\") ? "\\\\" : relativePath.startsWith("/") ? "/" : ""; return [ ...(hostPath ? [] : [{ label: projectName, path: "", kind: "project" as const }]), diff --git a/packages/client-runtime/src/operations/projects.ts b/packages/client-runtime/src/operations/projects.ts index 92532a6a90579..c56fa973c4501 100644 --- a/packages/client-runtime/src/operations/projects.ts +++ b/packages/client-runtime/src/operations/projects.ts @@ -11,7 +11,7 @@ import type { } from "@t3tools/contracts"; import { SourceControlProviderKind } from "@t3tools/contracts"; import { cloneUrlRepositoryPath } from "@t3tools/shared/cloneUrl"; -import { isExplicitRelativePath, isHostPath, newProjectFolderName } from "@t3tools/shared/path"; +import { isAbsolutePath, isExplicitRelativePath, newProjectFolderName } from "@t3tools/shared/path"; import * as Arr from "effect/Array"; import * as Option from "effect/Option"; import * as Order from "effect/Order"; @@ -222,8 +222,13 @@ export function buildAddProjectRemoteSourceReadiness( export function getAddProjectInitialQuery(baseDirectory: string | null | undefined): string { const trimmed = baseDirectory?.trim() ?? ""; if (trimmed.length === 0) return "~/"; - // A bare relative setting such as `Desktop/dev` means a folder under home. - const isAnchored = trimmed === "~" || isHostPath(trimmed) || isExplicitRelativePath(trimmed); + // A bare relative setting such as `Desktop/dev` means a folder under home. The browser + // navigates `~/` but not `~\` home paths. + const isAnchored = + trimmed === "~" || + isAbsolutePath(trimmed) || + trimmed.startsWith("~/") || + isExplicitRelativePath(trimmed); return ensureBrowseDirectoryPath(isAnchored ? trimmed : `~/${trimmed}`); } diff --git a/packages/shared/src/path.test.ts b/packages/shared/src/path.test.ts index 514f92b8f54e0..9a9647c1bcd4b 100644 --- a/packages/shared/src/path.test.ts +++ b/packages/shared/src/path.test.ts @@ -59,6 +59,7 @@ describe("resolvePastedPath", () => { ["over a selection", "/Users/me/old", "'/Users/me/My Code'", "/Users/me/My Code"], ["after a prefilled folder", "~/", "~/'/Users/me/My Code'", "/Users/me/My Code"], ["plain, after a prefilled folder", "~/", "~//Users/me/code", "/Users/me/code"], + ["backslash home, after a folder", "~/", "~/~\\folder\\ child", "~/~\\folder\\ child"], ["after a Windows folder", "C:\\Users\\", 'C:\\Users\\"D:\\My Code"', "D:\\My Code"], ["a shell's quoted apostrophe", "", "'/Users/me/Bob'\\''s Work'", "/Users/me/Bob's Work"], ["after a clone destination", "~/code/repo", "~/code/repo'/a b'", "/a b"], diff --git a/packages/shared/src/path.ts b/packages/shared/src/path.ts index 45b49b200091c..e4351b97b2626 100644 --- a/packages/shared/src/path.ts +++ b/packages/shared/src/path.ts @@ -134,15 +134,20 @@ export function isAbsolutePath(value: string): boolean { return value.startsWith("/") || isWindowsAbsolutePath(value); } -/** Home-relative host paths are expanded by the destination server. */ +/** Both ~/ and ~\ home prefixes are expanded by the destination server. */ export function isHostPath(value: string): boolean { - return isAbsolutePath(value) || value.startsWith("~/"); + return isAbsolutePath(value) || value.startsWith("~/") || value.startsWith("~\\"); } // Finder and Explorer copy a path ready for a shell: `'/a b'`, `/a\'s\ b`, or `"C:\a b"`. const QUOTED_PATH_AT_END = /(?:'((?:[^']|'\\'')+)'|"([^"]+)")\s*$/; const SHELL_ESCAPE = /\\([\s'"\\()[\]{}<>|&;$`!*?#~^=])/g; +// Folder browsers only navigate `~/` home paths, so a pasted `~\` path is not a replacement. +function isPastedFolderPath(value: string): boolean { + return isAbsolutePath(value) || value.startsWith("~/"); +} + /** * What a folder box holds after a change. A full path pasted into it replaces the box, even after * the text already there, because `~/'/a b'` would create that nested folder. @@ -157,13 +162,13 @@ export function resolvePastedPath(previous: string, next: string): string { // Text before the quote that wasn't in the box is a search, not a folder to paste after. if (match && previous.startsWith(next.slice(0, match.index).trimEnd())) { const quoted = match[1]?.replaceAll("'\\''", "'") ?? match[2] ?? ""; - if (isHostPath(quoted)) return quoted; + if (isPastedFolderPath(quoted)) return quoted; } // Without a trailing separator, `/a` then `/a/b` is a longer path, not one pasted after a folder. const afterFolder = /[/\\]$/.test(previous) && next.startsWith(previous); const path = afterFolder ? next.slice(previous.length) : next; - if (!isHostPath(path)) return next; + if (!isPastedFolderPath(path)) return next; // `\` separates folders in Windows paths, so it only escapes in `/` and `~/` paths. return isWindowsAbsolutePath(path) ? path : path.replace(SHELL_ESCAPE, "$1"); }