-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fixes #4009 line file read capability updates while "always read enti… #4391
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
Conversation
…re file" is true
| ) | ||
| }) | ||
|
|
||
| // Mock lucide-react icons globally using Proxy for dynamic icon handling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a duplicate comment regarding the lucide‐react icon mocking using Proxy (the initial comment on lines 35–52 and then again on line 54). Consider removing the redundant comment to keep the file clean.
| // Mock lucide-react icons globally using Proxy for dynamic icon handling |
|
Hey @KJ7LNW, I noticed you left your thoughts in the issue, what do you think of the PR? |
The additional metadata for storing modification times with line ranges is quite small, just a few integers and file names is enough. The best place to put it is in here is an example for api_conversation_history.json: [
{
"role": "assistant",
"content": [
{ "type": "text", "text": "I need to fix the login function in the authentication file <apply_diff>..." }
],
"ts": 1717620045000
},
{
"role": "user",
"content": [
{ "type": "text", "text": "I've applied a diff to fix the login function. <file><user_changes>..." }
],
"ts": 1717620050000,
//
// New structures stored in api_conversation_history.json:
//
"tool": { // Tool metadata at same level as ts
"name": "apply_diff", // Name of the tool used
"options": { // Original tool parameters
"path": "src/services/Auth.js",
}
},
//
// File metadata for tracking
//
"files": [
{
"fileName": "src/services/Auth.js",
"lineRanges": [
// Only the specific lines modified by the diff, as reported by the RESULT
// not the request, because sometimes line numbers are fuzzy and what actually
// gets replaced is the part that needs to be updated in terms of being valid.
// these lines are used to decide if they exist: writes update the validity of line
// ranges without the need for an additional read:
{ "start": 120, "end": 124 },
{ "start": 222, "end": 333 }
...
],
"mtime": 1717620048000 // mtime of the file after applying the diff
}
]
}
] |
|
sigh sorry still learning how to use github properly, was trying to resolve a different issue.... |
Related GitHub Issue
Closes: #4009
Description
This PR addresses Issue #4009, where the "Always read entire file" setting inadvertently prevented the model from utilizing line-range reads. The fix involves two main parts:
System Prompt Modification:
read_filetool description, generated bysrc/core/prompts/tools/read-file.ts, has been updated to always include information about theline_rangeparameter (start_line,end_line) and its usage. This ensures the AI model is consistently aware of its capability to request specific line ranges, irrespective of the "Always read entire file" setting.src/core/prompts/__tests__/__snapshots__/system.test.ts.snapwere updated accordingly.readFileTool.tsEnhancement:src/core/tools/readFileTool.tshas been enhanced to implement intelligent caching and avoid redundant file I/O.mtime) before reading.mtimeand the content of loaded line ranges (or full file content).mtime. If the requested range is already loaded and the file has not been modified since that read, the tool serves the content from the cache, skipping actual file I/O.mtime) or the range isn't cached, a fresh read is performed, and the cache is updated.mtimelogic were added and updated insrc/core/tools/__tests__/readFileTool.test.ts.Reviewers should pay attention to the new caching logic in
readFileTool.tsand the unconditional inclusion ofline_rangein theread_filetool's prompt description.Test Procedure
Unit Tests:
read_fileprompt generation are covered by updated snapshots insrc/core/prompts/__tests__/system.test.tsandsrc/core/prompts/__tests__/custom-system-prompt.test.ts.mtimelogic inreadFileTool.tsis covered by extensive unit tests insrc/core/tools/__tests__/readFileTool.test.ts. These tests mock file system operations to verify cache hits and misses under various conditions (file modification, different ranges, etc.).pnpm testin the root directory. All tests should pass. Specifically, ensure tests insrc/core/prompts/__tests__/andsrc/core/tools/__tests__/pass.Manual End-to-End Verification (as performed during development):
path/to/your/largeTestFile.js).path/to/your/largeTestFile.js."read_filewith the specified line range.path/to/your/largeTestFile.jsagain."readFileTool.tsserves from cache (no new file I/O if file is unmodified).path/to/your/largeTestFile.js."path/to/your/largeTestFile.js."path/to/your/largeTestFile.js(e.g., change line 10). Save it.path/to/your/largeTestFile.jshas been modified. Please read lines 10 to 15 ofpath/to/your/largeTestFile.jsagain."readFileTool.tsdetects modification, performs a fresh read, and returns updated content.read_filerequests with line ranges.Type of Change
readFileTool.ts).esbuild.mjsand test setups).srcor test files.Pre-Submission Checklist
npm run lint). (Verified by successfulpnpm testwhich includes linting).console.log) has been removed.pnpm test).mainbranch. (Assumed for PR template generation)npm run changesetif this PR includes user-facing changes or dependency updates. (This change is primarily internal/developer-facing regarding tool behavior, but a changeset might be considered if the improved efficiency or reliability is user-noticeable).Screenshots / Videos
N/A. Changes are backend/tool behavior and build/test scripts.
Documentation Updates
read_fileconcept (if they were manually crafting tool calls, which is rare) doesn't change. The primary impact is on the model's ability to use the tool effectively and internal efficiency.Additional Notes
To ensure the primary fix for #4009 could be successfully tested and merged, this PR includes the following targeted adjustments that were made to the 6 files in this changeset:
Testing the "Always read entire file" setting prevents line-range reads #4009 Feature (
readFileTool.tscaching):src/core/tools/__tests__/readFileTool.test.tswere refined to correctly validate the new caching andmtimelogic insrc/core/tools/readFileTool.ts. This involved adjusting mock setups for file system interactions, implementing proper test file lifecycle management (creation/cleanup of temporary files for read operations), and correcting assertions.readFileTool.tswas removed as its coverage was consolidated into the more robust Jest tests, also avoiding unrelatedvscodemodule resolution issues.Enabling
pnpm testto Pass After "Always read entire file" setting prevents line-range reads #4009 Changes:pnpm test(in theroo-cline:bundlescript) was resolved by modifyingsrc/esbuild.mjsto use a more robust directory removal method, preventing anENOTEMPTYerror.@roo-code/vscode-webviewpackage (also blockingpnpm test) were addressed by ensuring its Jest setup was correct. This involved modifications towebview-ui/src/setupTests.tsxto align with the package's Jest configuration.These specific changes to the 6 files in this PR were essential for delivering the fix for #4009 with a fully passing test suite.
Get in Touch
Mnehmos
Important
Fixes issue #4009 by updating
read_filetool to support line-range reads and implementing caching to avoid redundant file I/O.read_filetool inreadFileTool.tsto support line-range reads regardless of 'Always read entire file' setting.read_filetool description inread-file.tsto always includeline_rangeparameter.system.test.ts.snap.readFileTool.test.tsto cover caching logic and line-range reads.esbuild.mjsto preventENOTEMPTYerror duringpnpm test.setupTests.tsxfor Jest setup inwebview-ui.This description was created by
for e3f9f12. You can customize this summary. It will automatically update as commits are pushed.