From d6c71ef808bd572627b8ba34cf4e2c7b2f1eca46 Mon Sep 17 00:00:00 2001 From: Will Chen Date: Tue, 27 May 2025 14:47:49 -0700 Subject: [PATCH] Normalize Windows-style path for dyad tags to prevent Git issues (#262) --- src/ipc/processors/response_processor.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/ipc/processors/response_processor.ts b/src/ipc/processors/response_processor.ts index 6d01cec..b2afa4e 100644 --- a/src/ipc/processors/response_processor.ts +++ b/src/ipc/processors/response_processor.ts @@ -20,6 +20,16 @@ import { SqlQuery } from "../../lib/schemas"; const readFile = fs.promises.readFile; const logger = log.scope("response_processor"); +/** + * Normalize the path to use forward slashes instead of backslashes. + * This is important to prevent weird Git issues, particularly on Windows. + * @param path Source path. + * @returns Normalized path. + */ +function normalizePath(path: string): string { + return path.replace(/\\/g, "/"); +} + export function getDyadWriteTags(fullResponse: string): { path: string; content: string; @@ -52,7 +62,7 @@ export function getDyadWriteTags(fullResponse: string): { } content = contentLines.join("\n"); - tags.push({ path, content, description }); + tags.push({ path: normalizePath(path), content, description }); } else { logger.warn( "Found tag without a valid 'path' attribute:", @@ -72,7 +82,10 @@ export function getDyadRenameTags(fullResponse: string): { let match; const tags: { from: string; to: string }[] = []; while ((match = dyadRenameRegex.exec(fullResponse)) !== null) { - tags.push({ from: match[1], to: match[2] }); + tags.push({ + from: normalizePath(match[1]), + to: normalizePath(match[2]), + }); } return tags; } @@ -83,7 +96,7 @@ export function getDyadDeleteTags(fullResponse: string): string[] { let match; const paths: string[] = []; while ((match = dyadDeleteRegex.exec(fullResponse)) !== null) { - paths.push(match[1]); + paths.push(normalizePath(match[1])); } return paths; }