-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Enhance read_file tool to support multiple files via setting #2929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Enhance read_file tool to support multiple files via setting #2929
Conversation
Implements the ability for the `read_file` tool to accept a JSON array string of file paths in its `path` parameter, allowing the AI to request multiple files in a single call. Key changes: - Added `maxConcurrentFileReads` setting (default: 1) to control the maximum number of files read per request. - Updated setting schema, types, UI (slider in Context Management), state management, and persistence logic for the new setting. - Modified `readFileTool.ts` to parse the `path` parameter (handling both single strings and JSON arrays), enforce the `maxConcurrentFileReads` limit, and aggregate results/errors. - Updated the `read_file` tool prompt description to inform the AI about the new capability and usage. - Includes fixes for UI slider display/persistence and backend state handling. - Updated relevant unit tests.
|
- Adjusted mocks for range reads, rooignore, and path validation in read-file-xml.test.ts. - Updated expectations for range read behavior (ignoring maxReadFileLine). - Corrected mock interactions for rooignore and empty array path tests. - Fixed assertion for askApproval call order in empty array path test.
- Correct path mocking/usage for Windows compatibility. - Ensure mock keys use platform-correct paths. - Fix mock signatures and interactions for edge cases (empty/binary files). - Adjusted expectations for empty file handling with maxReadFileLine=0. - Corrected spyOn usage for pathUtils mock.
67fcc7f to
c7b815a
Compare
- Added translations for new `read_file` tool errors and functionality in `src/i18n/locales/*/tools.json`. - Added translations for new `maxConcurrentFileReads` setting in `webview-ui/src/i18n/locales/*/settings.json`. - Verified completion using `scripts/find-missing-translations.js`.
|
I think this PR duplicates earlier work in #2886 |
Yes and no lol. i had a PR before as well which implemented it via experimental mode and as per the request of mrubens i combined it with reed_file and some gui settings option, meanwhile 2886 was also running side by side and it all became confusing. |
I am not in charge I just wanted to point it out. If you have already been working with Sam then whatever you think is best. See the comments in #2886 for multi-file multi-read w/ XML-based tool syntax to conform with the same style as all other tools and facilitate future programmatic standardization of tool use (currently XML, but standardization would let us experiment with other formats such as JSON to see what works best) for when #2467 lands. |
|
Hey @shariqriazz, |
Context
This PR enhances the existing
read_filetool to allow the AI model to request the content of multiple files within a single operation. This approach was chosen based on feedback to avoid introducing a new experimental tool and instead leverage the existingread_filefunctionality, controlled by a user setting.The goal is to improve efficiency and reduce the number of tool calls required for tasks needing context from several sources, while giving users control over the maximum number of files read concurrently.
Implementation
The implementation involved the following key steps:
New Setting (
maxConcurrentFileReads):maxConcurrentFileReadstosrc/schemas/index.tswith a default value of 1. This setting controls the maximum number of files theread_filetool can process in a single request when given multiple paths.RooCodeSettings,ExtensionState, etc.) insrc/schemas/index.ts,src/shared/ExtensionMessage.ts,src/shared/WebviewMessage.ts, andsrc/exports/roo-code.d.ts.webview-ui/src/components/settings/ContextManagementSettings.tsx,webview-ui/src/components/settings/SettingsView.tsx,webview-ui/src/i18n/locales/en/settings.json).webview-ui/src/context/ExtensionStateContext.tsx) and persistence logic (src/core/config/ContextProxy.ts,src/core/webview/ClineProvider.ts,src/core/webview/webviewMessageHandler.ts) to handle the new setting.readFileToolEnhancement (src/core/tools/readFileTool.ts):<path>parameter. It now detects if the parameter value is a JSON string array or a single path string.maxConcurrentFileReadssetting limit. If the number of requested paths exceeds the limit, a specific error is returned.<file_content>or<file_error>) within a parent<read_result>tag.start_lineandend_lineparameters are now explicitly disallowed when multiple files are requested.Tool Prompt Update (
src/core/prompts/tools/read-file.ts):read_filetool description provided to the AI model. It now explains the ability to use a JSON string array for thepathparameter, mentions themaxConcurrentFileReadssetting, and clarifies thatstart_line/end_lineonly apply to single-file reads.Testing:
src/core/__tests__/read-file-tool.test.ts,src/core/__tests__/read-file-xml.test.ts) to cover the new multi-file functionality, including JSON parsing, limit enforcement, error handling, and result aggregation.How to Test
feature/multi-file-read-settingbranch.<read_file>tool with a JSON array string in the<path>parameter (e.g.,<path>["package.json", "README.md", ".gitignore"]</path>).<read_result>) should contain<file_content>tags for successfully read files and<file_error>tags for any files that couldn't be read.<tool_error>fromread_fileindicating that the requested number of files exceeds the configured maximum.start_lineorend_line.start_lineorend_line.<tool_error>indicating that line parameters are not supported for multi-file reads.<tool_error>for exceeding the maximum (which is now 1).Screenshots
Context Management Settings:


[Screenshot of the slider]
Important
Enhances
read_filetool to support concurrent multi-file reads with a newmaxConcurrentFileReadssetting, updating UI, settings, and error handling accordingly.read_filetool inreadFileTool.tsto support multiple file reads using a JSON array forpathparameter.maxConcurrentFileReadssetting inindex.tsto limit concurrent file reads, defaulting to 1.start_lineandend_linewhen reading multiple files.maxConcurrentFileReadsinContextManagementSettings.tsxandSettingsView.tsx.webviewMessageHandler.tsto handlemaxConcurrentFileReadssetting changes.tools.jsonfor invalid JSON, too many files, and line parameter misuse.read-file-tool.test.tsandread-file-xml.test.tsto cover new multi-file functionality and error cases.This description was created by
for b1ac780. You can customize this summary. It will automatically update as commits are pushed.