summaryrefslogtreecommitdiff
path: root/packages/core/src/tools/read-many-files.ts
diff options
context:
space:
mode:
authorAnas H. Sulaiman <[email protected]>2025-06-14 10:25:34 -0400
committerGitHub <[email protected]>2025-06-14 14:25:34 +0000
commit4873fce7919b4d74cee183a91fa8a3af58aef993 (patch)
treec08502c1e4592667160cb006528f868fd6283294 /packages/core/src/tools/read-many-files.ts
parente6d54771686b3f9537a5a05c9f9101afad3ffdcd (diff)
centralize file filtering in `FileDiscoveryService` (#1039)
Diffstat (limited to 'packages/core/src/tools/read-many-files.ts')
-rw-r--r--packages/core/src/tools/read-many-files.ts41
1 files changed, 17 insertions, 24 deletions
diff --git a/packages/core/src/tools/read-many-files.ts b/packages/core/src/tools/read-many-files.ts
index daf9bc04..107e16b3 100644
--- a/packages/core/src/tools/read-many-files.ts
+++ b/packages/core/src/tools/read-many-files.ts
@@ -119,7 +119,7 @@ export class ReadManyFilesTool extends BaseTool<
ToolResult
> {
static readonly Name: string = 'read_many_files';
- private readonly geminiIgnorePatterns: string[];
+ private readonly geminiIgnorePatterns: string[] = [];
/**
* Creates an instance of ReadManyFilesTool.
@@ -191,7 +191,9 @@ Use this tool when the user's query implies needing the content of several files
parameterSchema,
);
this.targetDir = path.resolve(targetDir);
- this.geminiIgnorePatterns = config.getGeminiIgnorePatterns() || [];
+ this.geminiIgnorePatterns = config
+ .getFileService()
+ .getGeminiIgnorePatterns();
}
validateParams(params: ReadManyFilesParams): string | null {
@@ -292,7 +294,7 @@ Use this tool when the user's query implies needing the content of several files
respect_git_ignore ?? this.config.getFileFilteringRespectGitIgnore();
// Get centralized file discovery service
- const fileDiscovery = await this.config.getFileService();
+ const fileDiscovery = this.config.getFileService();
const toolBaseDir = this.targetDir;
const filesToConsider = new Set<string>();
@@ -323,18 +325,16 @@ Use this tool when the user's query implies needing the content of several files
signal,
});
- // Apply git-aware filtering if enabled and in git repository
- const filteredEntries =
- respectGitIgnore && fileDiscovery.isGitRepository()
- ? fileDiscovery
- .filterFiles(
- entries.map((p) => path.relative(toolBaseDir, p)),
- {
- respectGitIgnore,
- },
- )
- .map((p) => path.resolve(toolBaseDir, p))
- : entries;
+ const filteredEntries = respectGitIgnore
+ ? fileDiscovery
+ .filterFiles(
+ entries.map((p) => path.relative(toolBaseDir, p)),
+ {
+ respectGitIgnore,
+ },
+ )
+ .map((p) => path.resolve(toolBaseDir, p))
+ : entries;
let gitIgnoredCount = 0;
for (const absoluteFilePath of entries) {
@@ -348,11 +348,7 @@ Use this tool when the user's query implies needing the content of several files
}
// Check if this file was filtered out by git ignore
- if (
- respectGitIgnore &&
- fileDiscovery.isGitRepository() &&
- !filteredEntries.includes(absoluteFilePath)
- ) {
+ if (respectGitIgnore && !filteredEntries.includes(absoluteFilePath)) {
gitIgnoredCount++;
continue;
}
@@ -362,12 +358,9 @@ Use this tool when the user's query implies needing the content of several files
// Add info about git-ignored files if any were filtered
if (gitIgnoredCount > 0) {
- const reason = respectGitIgnore
- ? 'git-ignored'
- : 'filtered by custom ignore patterns';
skippedFiles.push({
path: `${gitIgnoredCount} file(s)`,
- reason,
+ reason: 'ignored',
});
}
} catch (error) {