From f88488d1f90c3649947099d19004a506a41d6e82 Mon Sep 17 00:00:00 2001 From: Muhammad Usman <146759960+muhammadusman586@users.noreply.github.com> Date: Tue, 10 Mar 2026 03:40:22 +0500 Subject: [PATCH] fix(core): resolve Windows line ending and path separation bugs across CLI (#21068) --- packages/cli/src/ui/components/messages/DiffRenderer.tsx | 2 +- packages/cli/src/ui/utils/CodeColorizer.tsx | 4 ++-- packages/core/src/tools/read-many-files.test.ts | 2 +- packages/core/src/utils/fileUtils.ts | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/ui/components/messages/DiffRenderer.tsx b/packages/cli/src/ui/components/messages/DiffRenderer.tsx index 83b205ac76..0859bc13f3 100644 --- a/packages/cli/src/ui/components/messages/DiffRenderer.tsx +++ b/packages/cli/src/ui/components/messages/DiffRenderer.tsx @@ -22,7 +22,7 @@ interface DiffLine { } function parseDiffWithLineNumbers(diffContent: string): DiffLine[] { - const lines = diffContent.split('\n'); + const lines = diffContent.split(/\r?\n/); const result: DiffLine[] = []; let currentOldLine = 0; let currentNewLine = 0; diff --git a/packages/cli/src/ui/utils/CodeColorizer.tsx b/packages/cli/src/ui/utils/CodeColorizer.tsx index e5ce2562af..948a5f8988 100644 --- a/packages/cli/src/ui/utils/CodeColorizer.tsx +++ b/packages/cli/src/ui/utils/CodeColorizer.tsx @@ -156,7 +156,7 @@ export function colorizeCode({ try { // Render the HAST tree using the adapted theme // Apply the theme's default foreground color to the top-level Text element - let lines = codeToHighlight.split('\n'); + let lines = codeToHighlight.split(/\r?\n/); const padWidth = String(lines.length).length; // Calculate padding width based on number of lines let hiddenLinesCount = 0; @@ -225,7 +225,7 @@ export function colorizeCode({ ); // Fall back to plain text with default color on error // Also display line numbers in fallback - const lines = codeToHighlight.split('\n'); + const lines = codeToHighlight.split(/\r?\n/); const padWidth = String(lines.length).length; // Calculate padding width based on number of lines const fallbackLines = lines.map((line, index) => ( diff --git a/packages/core/src/tools/read-many-files.test.ts b/packages/core/src/tools/read-many-files.test.ts index 875ccf0bd5..0b8e3a1745 100644 --- a/packages/core/src/tools/read-many-files.test.ts +++ b/packages/core/src/tools/read-many-files.test.ts @@ -776,7 +776,7 @@ Content of file[1] // Mock to track concurrent vs sequential execution detectFileTypeSpy.mockImplementation(async (filePath: string) => { - const fileName = filePath.split('/').pop() || ''; + const fileName = path.basename(filePath); executionOrder.push(`start:${fileName}`); // Add delay to make timing differences visible diff --git a/packages/core/src/utils/fileUtils.ts b/packages/core/src/utils/fileUtils.ts index 2497439a63..6bb89df83c 100644 --- a/packages/core/src/utils/fileUtils.ts +++ b/packages/core/src/utils/fileUtils.ts @@ -8,7 +8,6 @@ import fs from 'node:fs'; import fsPromises from 'node:fs/promises'; import path from 'node:path'; import type { PartUnion } from '@google/genai'; - import mime from 'mime/lite'; import type { FileSystemService } from '../services/fileSystemService.js'; import { ToolErrorType } from '../tools/tool-error.js'; @@ -473,7 +472,7 @@ export async function processSingleFileContent( case 'text': { // Use BOM-aware reader to avoid leaving a BOM character in content and to support UTF-16/32 transparently const content = await readFileWithEncoding(filePath); - const lines = content.split('\n'); + const lines = content.split(/\r?\n/); const originalLineCount = lines.length; let sliceStart = 0;