Fix windows bugs in atCommandProcessor.ts (#4684)

This commit is contained in:
Tommaso Sciortino 2025-07-22 17:18:57 -07:00 committed by GitHub
parent a00f1bb916
commit 30c68922a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 386 additions and 803 deletions

File diff suppressed because it is too large Load Diff

View File

@ -222,14 +222,13 @@ export async function handleAtCommand({
const absolutePath = path.resolve(config.getTargetDir(), pathName); const absolutePath = path.resolve(config.getTargetDir(), pathName);
const stats = await fs.stat(absolutePath); const stats = await fs.stat(absolutePath);
if (stats.isDirectory()) { if (stats.isDirectory()) {
currentPathSpec = pathName.endsWith('/') currentPathSpec =
? `${pathName}**` pathName + (pathName.endsWith(path.sep) ? `**` : `/**`);
: `${pathName}/**`;
onDebugMessage( onDebugMessage(
`Path ${pathName} resolved to directory, using glob: ${currentPathSpec}`, `Path ${pathName} resolved to directory, using glob: ${currentPathSpec}`,
); );
} else { } else {
onDebugMessage(`Path ${pathName} resolved to file: ${currentPathSpec}`); onDebugMessage(`Path ${pathName} resolved to file: ${absolutePath}`);
} }
resolvedSuccessfully = true; resolvedSuccessfully = true;
} catch (error) { } catch (error) {
@ -240,7 +239,10 @@ export async function handleAtCommand({
); );
try { try {
const globResult = await globTool.execute( const globResult = await globTool.execute(
{ pattern: `**/*${pathName}*`, path: config.getTargetDir() }, {
pattern: `**/*${pathName}*`,
path: config.getTargetDir(),
},
signal, signal,
); );
if ( if (

View File

@ -128,8 +128,6 @@ export class ReadManyFilesTool extends BaseTool<
> { > {
static readonly Name: string = 'read_many_files'; static readonly Name: string = 'read_many_files';
private readonly geminiIgnorePatterns: string[] = [];
constructor(private config: Config) { constructor(private config: Config) {
const parameterSchema: Schema = { const parameterSchema: Schema = {
type: Type.OBJECT, type: Type.OBJECT,
@ -213,9 +211,6 @@ Use this tool when the user's query implies needing the content of several files
Icon.FileSearch, Icon.FileSearch,
parameterSchema, parameterSchema,
); );
this.geminiIgnorePatterns = config
.getFileService()
.getGeminiIgnorePatterns();
} }
validateParams(params: ReadManyFilesParams): string | null { validateParams(params: ReadManyFilesParams): string | null {
@ -233,17 +228,19 @@ Use this tool when the user's query implies needing the content of several files
// Determine the final list of exclusion patterns exactly as in execute method // Determine the final list of exclusion patterns exactly as in execute method
const paramExcludes = params.exclude || []; const paramExcludes = params.exclude || [];
const paramUseDefaultExcludes = params.useDefaultExcludes !== false; const paramUseDefaultExcludes = params.useDefaultExcludes !== false;
const geminiIgnorePatterns = this.config
.getFileService()
.getGeminiIgnorePatterns();
const finalExclusionPatternsForDescription: string[] = const finalExclusionPatternsForDescription: string[] =
paramUseDefaultExcludes paramUseDefaultExcludes
? [...DEFAULT_EXCLUDES, ...paramExcludes, ...this.geminiIgnorePatterns] ? [...DEFAULT_EXCLUDES, ...paramExcludes, ...geminiIgnorePatterns]
: [...paramExcludes, ...this.geminiIgnorePatterns]; : [...paramExcludes, ...geminiIgnorePatterns];
let excludeDesc = `Excluding: ${finalExclusionPatternsForDescription.length > 0 ? `patterns like \`${finalExclusionPatternsForDescription.slice(0, 2).join('`, `')}${finalExclusionPatternsForDescription.length > 2 ? '...`' : '`'}` : 'none specified'}`; let excludeDesc = `Excluding: ${finalExclusionPatternsForDescription.length > 0 ? `patterns like \`${finalExclusionPatternsForDescription.slice(0, 2).join('`, `')}${finalExclusionPatternsForDescription.length > 2 ? '...`' : '`'}` : 'none specified'}`;
// Add a note if .geminiignore patterns contributed to the final list of exclusions // Add a note if .geminiignore patterns contributed to the final list of exclusions
if (this.geminiIgnorePatterns.length > 0) { if (geminiIgnorePatterns.length > 0) {
const geminiPatternsInEffect = this.geminiIgnorePatterns.filter((p) => const geminiPatternsInEffect = geminiIgnorePatterns.filter((p) =>
finalExclusionPatternsForDescription.includes(p), finalExclusionPatternsForDescription.includes(p),
).length; ).length;
if (geminiPatternsInEffect > 0) { if (geminiPatternsInEffect > 0) {
@ -305,7 +302,9 @@ Use this tool when the user's query implies needing the content of several files
} }
try { try {
const entries = await glob(searchPatterns, { const entries = await glob(
searchPatterns.map((p) => p.replace(/\\/g, '/')),
{
cwd: this.config.getTargetDir(), cwd: this.config.getTargetDir(),
ignore: effectiveExcludes, ignore: effectiveExcludes,
nodir: true, nodir: true,
@ -313,7 +312,8 @@ Use this tool when the user's query implies needing the content of several files
absolute: true, absolute: true,
nocase: true, nocase: true,
signal, signal,
}); },
);
const gitFilteredEntries = fileFilteringOptions.respectGitIgnore const gitFilteredEntries = fileFilteringOptions.respectGitIgnore
? fileDiscovery ? fileDiscovery

View File

@ -4,42 +4,37 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import fsPromises from 'fs/promises'; import fsPromises from 'fs/promises';
import * as nodePath from 'path'; import * as nodePath from 'path';
import * as os from 'os'; import * as os from 'os';
import { getFolderStructure } from './getFolderStructure.js'; import { getFolderStructure } from './getFolderStructure.js';
import * as gitUtils from './gitUtils.js';
import { FileDiscoveryService } from '../services/fileDiscoveryService.js'; import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
import * as path from 'path'; import * as path from 'path';
vi.mock('./gitUtils.js');
describe('getFolderStructure', () => { describe('getFolderStructure', () => {
let testRootDir: string; let testRootDir: string;
const createEmptyDir = async (...pathSegments: string[]) => { async function createEmptyDir(...pathSegments: string[]) {
const fullPath = path.join(testRootDir, ...pathSegments); const fullPath = path.join(testRootDir, ...pathSegments);
await fsPromises.mkdir(fullPath, { recursive: true }); await fsPromises.mkdir(fullPath, { recursive: true });
}; }
const createTestFile = async (...pathSegments: string[]) => { async function createTestFile(...pathSegments: string[]) {
const fullPath = path.join(testRootDir, ...pathSegments); const fullPath = path.join(testRootDir, ...pathSegments);
await fsPromises.mkdir(path.dirname(fullPath), { recursive: true }); await fsPromises.mkdir(path.dirname(fullPath), { recursive: true });
await fsPromises.writeFile(fullPath, ''); await fsPromises.writeFile(fullPath, '');
return fullPath; return fullPath;
}; }
beforeEach(async () => { beforeEach(async () => {
testRootDir = await fsPromises.mkdtemp( testRootDir = await fsPromises.mkdtemp(
path.join(os.tmpdir(), 'folder-structure-test-'), path.join(os.tmpdir(), 'folder-structure-test-'),
); );
vi.resetAllMocks();
}); });
afterEach(async () => { afterEach(async () => {
await fsPromises.rm(testRootDir, { recursive: true, force: true }); await fsPromises.rm(testRootDir, { recursive: true, force: true });
vi.restoreAllMocks();
}); });
it('should return basic folder structure', async () => { it('should return basic folder structure', async () => {
@ -246,8 +241,10 @@ ${testRootDir}${path.sep}
}); });
describe('with gitignore', () => { describe('with gitignore', () => {
beforeEach(() => { beforeEach(async () => {
vi.mocked(gitUtils.isGitRepository).mockReturnValue(true); await fsPromises.mkdir(path.join(testRootDir, '.git'), {
recursive: true,
});
}); });
it('should ignore files and folders specified in .gitignore', async () => { it('should ignore files and folders specified in .gitignore', async () => {