From 6fc68ff8d4536f35f0ed76af535d5e1e7ac37675 Mon Sep 17 00:00:00 2001 From: Gal Zahavi <38544478+galz10@users.noreply.github.com> Date: Mon, 18 Aug 2025 16:39:05 -0700 Subject: fix(tools): Handle special characters in file paths for glob and read_many_files (#6507) Co-authored-by: Jacob Richman --- packages/core/src/tools/read-many-files.ts | 36 +++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'packages/core/src/tools/read-many-files.ts') diff --git a/packages/core/src/tools/read-many-files.ts b/packages/core/src/tools/read-many-files.ts index 46aab23d..6a6eca9b 100644 --- a/packages/core/src/tools/read-many-files.ts +++ b/packages/core/src/tools/read-many-files.ts @@ -13,8 +13,9 @@ import { } from './tools.js'; import { SchemaValidator } from '../utils/schemaValidator.js'; import { getErrorMessage } from '../utils/errors.js'; +import * as fs from 'fs'; import * as path from 'path'; -import { glob } from 'glob'; +import { glob, escape } from 'glob'; import { getCurrentGeminiMdFilename } from './memoryTool.js'; import { detectFileType, @@ -245,18 +246,27 @@ ${finalExclusionPatternsForDescription const workspaceDirs = this.config.getWorkspaceContext().getDirectories(); for (const dir of workspaceDirs) { - const entriesInDir = await glob( - searchPatterns.map((p) => p.replace(/\\/g, '/')), - { - cwd: dir, - ignore: effectiveExcludes, - nodir: true, - dot: true, - absolute: true, - nocase: true, - signal, - }, - ); + const processedPatterns = []; + for (const p of searchPatterns) { + const normalizedP = p.replace(/\\/g, '/'); + const fullPath = path.join(dir, normalizedP); + if (fs.existsSync(fullPath)) { + processedPatterns.push(escape(normalizedP)); + } else { + // The path does not exist or is not a file, so we treat it as a glob pattern. + processedPatterns.push(normalizedP); + } + } + + const entriesInDir = await glob(processedPatterns, { + cwd: dir, + ignore: effectiveExcludes, + nodir: true, + dot: true, + absolute: true, + nocase: true, + signal, + }); for (const entry of entriesInDir) { allEntries.add(entry); } -- cgit v1.2.3