refactor(read_file): Codex-inspired read_file refactor EXT-617#10981
refactor(read_file): Codex-inspired read_file refactor EXT-617#10981hannesrudolph merged 16 commits intomainfrom
Conversation
Re-review for 1a9bbc8 complete. One remaining item still applies.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
5c7a773 to
5785b36
Compare
|
This requires us to enable parallel tool calling by default, moving it out of experimental |
68ef238 to
9c670b4
Compare
123aacc to
1c3ef7d
Compare
3ae0e4d to
ff54851
Compare
mrubens
left a comment
There was a problem hiding this comment.
Sorry to keep nagging on this, but are we confident that this won't break existing conversations for people? If there's a chance it will I think we need to discuss the rollout plan more.
My tests worked without a problem |
Added fallback for legacy format so if the model gets confused and sends the old format Roo will not break! |
When the model makes multiple parallel read_file tool calls, the UI now consolidates consecutive read_file ask messages into a single batch view showing 'Roo wants to read these files' instead of showing repeated 'Roo wants to read this file' messages for each file. The groupedMessages useMemo in ChatView now detects consecutive read_file asks and creates a synthetic batch message with batchFiles, which triggers the existing BatchFilePermission component to render the files as a group. This improves the UX by reducing visual noise when reading multiple files.
Remove IndentationReadResult and MAX_LINE_LENGTH imports that were not being used, as flagged by the review bot.
…pproval flow Adds comprehensive tests for ReadFileTool covering: - Input validation (missing path parameter) - RooIgnore blocking - Directory read error handling - Image handling (memory limits, format detection, model support) - Binary file handling (PDF, DOCX, unsupported formats) - Text file processing (slice and indentation modes) - Approval flow (approve, deny, feedback) - Output structure formatting - Error handling (file read errors, stat errors) 29 new tests covering the orchestration layer that was previously untested after the Codex-inspired refactor.
- Restore convertFileEntries() function in NativeToolCallParser
- Detect and handle both old { files: [...] } and new { path, mode, ... } formats
- Handle double-stringified JSON from models (files as string vs array)
- Add executeLegacy() method in ReadFileTool for multi-file batch processing
- Add READ_FILE_LEGACY_FORMAT_USED telemetry event
- Add console.warn indicator when legacy format is detected (for testing)
- Add 7 new tests for backward compatibility scenarios
- Add legacy param names (files, line_ranges) to toolParamNames
…itted - getLineSnippet() now always displays 'indentation mode at line X' when mode is indentation - getStartLine() now always returns the effective anchor line for indentation mode - Both methods use fallback chain: anchor_line ?? offset ?? 1 Addresses review feedback about approval UI not reflecting defaulted anchor_line
- Clarify when to use each mode with balanced positive framing - Slice: ideal for exploration, understanding structure, config files - Indentation: PREFERRED when you have a line number for complete blocks - Add warning about anchor_line requirement for indentation mode - Add concrete example from condensed file summaries format - Strengthen guidance in mode, anchor_line, and indentation field descriptions - Increase MAX_LINE_LENGTH from 500 to 2000 characters
061496b to
3e25f9c
Compare
…p line info in brackets
| if (params.indentation?.anchor_line !== undefined && params.indentation.anchor_line < 1) { | ||
| const errorMsg = `anchor_line must be a 1-indexed line number (got ${params.indentation.anchor_line}). Line numbers start at 1.` | ||
| pushToolResult(`Error: ${errorMsg}`) | ||
| return |
There was a problem hiding this comment.
The current behavior rejects offset/anchor_line <= 0 with an error, but earlier reviews asked to clamp to the documented defaults (>= 1) so invalid model output degrades gracefully (and avoids “line 0” approval UI). If clamping is the intended UX, these early returns should normalize to 1 instead of failing.
Fix it with Roo Code or mention @roomote and request a fix.
Summary
closes #10239
This PR introduces a smarter way for Roo to read your code files. Instead of just grabbing arbitrary line ranges, Roo can now intelligently extract complete functions, classes, and code blocks based on their structure.
What's New
Indentation Mode for Smart Code Extraction
When Roo needs to read code around a specific line (like when investigating an error or following a search result), it can now use indentation mode to automatically extract the complete containing function or class—not just a fixed number of lines that might cut off mid-block.
Example: If Roo finds an error on line 42 inside a function, indentation mode will return the entire function definition with proper context, instead of an arbitrary range like "lines 40-60" that might miss important context or include unrelated code.
Simplified File Reading
The
read_filetool now has two clear modes:Breaking Changes
Settings Removed
The following settings have been removed from the UI:
If you previously relied on
maxReadFileLineto limit file reads, this behavior is now handled automatically by the agent's per-request parameters.API Changes (for Custom Modes/Prompts)
The
line_rangesparameter has been replaced with a simpleroffset/limitapproach:Before:
{ "files": [{ "path": "app.ts", "line_ranges": [[1, 50]] }] }After:
{ "path": "app.ts", "mode": "slice", "offset": 1, "limit": 50 }For semantic code extraction, use the new indentation mode:
{ "path": "app.ts", "mode": "indentation", "indentation": { "anchor_line": 42 } }Backward Compatibility
Legacy Format Support
To ensure smooth mid-chat updates, the parser maintains full backward compatibility with the old
read_fileformat. If a model uses the legacy format (based on chat history from before the update), it will still work correctly.Supported legacy formats:
{ files: [{ path: "...", line_ranges: [[start, end]] }] }- Array format{ files: "[{...}]" }- Double-stringified JSON (model quirk)line_rangesas tuples, objects, or stringsHow it works:
NativeToolCallParserdetects the presence of afilesparameterReadFileTool.executeLegacy()handles multi-file batch processingREAD_FILE_LEGACY_FORMAT_USED) is captured for monitoring adoptionTesting indicator: A
console.warn("[read_file] Legacy format detected")message appears when the fallback path is used (temporary, for validation).Benefits