diff --git a/webview-ui/src/utils/__tests__/path-mentions.test.ts b/webview-ui/src/utils/__tests__/path-mentions.test.ts index 1163324503..1512fbcadc 100644 --- a/webview-ui/src/utils/__tests__/path-mentions.test.ts +++ b/webview-ui/src/utils/__tests__/path-mentions.test.ts @@ -102,5 +102,25 @@ describe("Path Mentions Utilities", () => { const absPath = "/Users/test/project/src/file with spaces.ts" expect(convertToMentionPath(absPath, undefined)).toBe("/Users/test/project/src/file with spaces.ts") }) + + it("should return path as-is if it already starts with @", () => { + const mentionPath = "@/src/file.ts" + expect(convertToMentionPath(mentionPath, MOCK_CWD_POSIX)).toBe("@/src/file.ts") + }) + + it("should return path as-is if it already starts with @ even with spaces", () => { + const mentionPath = "@/src/file\\ with\\ spaces.ts" + expect(convertToMentionPath(mentionPath, MOCK_CWD_POSIX)).toBe("@/src/file\\ with\\ spaces.ts") + }) + + it("should return path as-is if it already starts with @ regardless of cwd", () => { + const mentionPath = "@/Logs/SCC_Engine_2025-07-18_18-29-42_0.log" + expect(convertToMentionPath(mentionPath, MOCK_CWD_POSIX)).toBe("@/Logs/SCC_Engine_2025-07-18_18-29-42_0.log") + }) + + it("should return path as-is if it already starts with @ even when cwd is undefined", () => { + const mentionPath = "@/some/path/file.txt" + expect(convertToMentionPath(mentionPath, undefined)).toBe("@/some/path/file.txt") + }) }) }) diff --git a/webview-ui/src/utils/path-mentions.ts b/webview-ui/src/utils/path-mentions.ts index 4ad25b9b56..70751d4684 100644 --- a/webview-ui/src/utils/path-mentions.ts +++ b/webview-ui/src/utils/path-mentions.ts @@ -23,6 +23,11 @@ export function escapeSpaces(path: string): string { * @returns A mention-friendly path */ export function convertToMentionPath(path: string, cwd?: string): string { + // If the path already starts with @, return it as-is to avoid double prefixing + if (path.startsWith("@")) { + return path + } + // Strip file:// or vscode-remote:// protocol if present let pathWithoutProtocol = path