Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
],
"dependencies": {
"@google/genai": "^1.26.0",
"p-limit": "^6.2.0",
"@lvce-editor/ripgrep": "^1.6.0",
"@modelcontextprotocol/sdk": "^1.11.0",
"xlsx": "^0.18.5",
Expand Down
11 changes: 8 additions & 3 deletions packages/core/src/tools/read-many-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { getProgrammingLanguage } from '../telemetry/telemetry-utils.js';
import { logFileOperation } from '../telemetry/loggers.js';
import { FileOperationEvent } from '../telemetry/types.js';
import { ToolErrorType } from './tool-error.js';
import pLimit from 'p-limit';

/**
* Parameters for the ReadManyFilesTool.
Expand Down Expand Up @@ -327,8 +328,12 @@ ${finalExclusionPatternsForDescription
const file_line_limit =
DEFAULT_MAX_LINES_TEXT_FILE / Math.max(1, sortedFiles.length);

const fileProcessingPromises = sortedFiles.map(
async (filePath): Promise<FileProcessingResult> => {
// to prevent too many open files errors
const MAX_CONCURRENT_FILE_OPS = 20;
const limit = pLimit(MAX_CONCURRENT_FILE_OPS);

const fileProcessingPromises = sortedFiles.map((filePath) =>
limit(async (): Promise<FileProcessingResult> => {
try {
const relativePathForDisplay = path
.relative(this.config.getTargetDir(), filePath)
Expand Down Expand Up @@ -395,7 +400,7 @@ ${finalExclusionPatternsForDescription
reason: `Unexpected error: ${error instanceof Error ? error.message : String(error)}`,
};
}
},
}),
);

const results = await Promise.allSettled(fileProcessingPromises);
Expand Down