feat: unify line_range parameter format for read_file tool in native mode #10250
+203
−71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR attempts to address Issue #10239, specifically @pwilkin's comment about unifying the
line_rangevsline_rangesparameter.Problem
There was inconsistency between XML and Native protocol formats for the read_file tool:
line_range(singular) with format"1-50"line_ranges(plural) with JSON array format[[1, 50], [100, 150]]This inconsistency could confuse models, especially when giving continuation instructions after file truncation.
Solution
Unified the native mode to use the same simpler format as XML mode:
line_rangestoline_range(singular)[[1, 50], [100, 150]]to string"1-50,100-150"Changes
src/core/prompts/tools/native-tools/read_file.ts: Updated tool definition to useline_range(string) instead ofline_ranges(array)src/core/assistant-message/NativeToolCallParser.ts: Added parsing support for the new unified string format while maintaining backward compatibility with legacy formatsTests: Updated all related tests for the new format
Examples
Before (native mode):
{ "files": [{ "path": "src/app.ts", "line_ranges": [[1, 50], [100, 150]] }] }After (native mode):
{ "files": [{ "path": "src/app.ts", "line_range": "1-50,100-150" }] }This matches XML mode:
Feedback and guidance are welcome!