Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Dec 21, 2025

Summary

Implements a new, more intuitive API for the read_file tool, inspired by OpenAI's Codex CLI read_file implementation. This replaces the previous line_ranges approach with a cleaner offset/limit/mode-based system that provides better pagination and smarter code extraction capabilities.

closes #10239

Changes

  • New API Parameters: Replace line_ranges with:

    • offset: 1-indexed starting line number (default: 1)
    • limit: Maximum lines to return (controlled by maxReadFileLine setting)
    • mode: Either slice (simple reading) or indentation (smart block extraction)
    • indentation: Configuration for indentation mode (anchorLine, maxLevels, includeSiblings, includeHeader)
  • New read-file-content.ts module: Core implementation with:

    • readSlice(): Simple line-by-line reading with offset pagination
    • readIndentationBlock(): Smart extraction of code blocks based on indentation levels
    • Rich metadata for pagination awareness (hasMoreBefore/After, linesBeforeStart/AfterEnd, etc.)
  • Enhanced Model Awareness: Tool descriptions now include the configured line limit so models understand pagination constraints

  • Improved Default Limit: Changed default maxReadFileLine from 500 to 2000 lines for better out-of-box experience

  • Removed Deprecated Code:

    • Deleted truncateDefinitions.ts helper and its tests
    • Removed tree-sitter definition parsing from partial reads (simplifies implementation)

Credits

This implementation is inspired by and adapts concepts from OpenAI's Codex CLI, particularly their approach to file reading with offset-based pagination and indentation-aware code block extraction.


Important

Refactor read_file tool to use offset/limit/mode parameters, adding slice and indentation modes, and update related tests and settings.

  • Behavior:
    • Replaces line_ranges with offset, limit, and mode parameters in read_file tool.
    • Introduces slice and indentation modes for reading files.
    • Updates maxReadFileLine default from 500 to 2000.
  • Implementation:
    • Adds readSlice() and readIndentationBlock() functions in read-file-content.ts.
    • Removes truncateDefinitions.ts and related code.
  • Tests:
    • Updates tests in readFileTool.spec.ts and read-file-content.spec.ts to cover new API.
  • Settings:
    • Updates ContextManagementSettings.tsx to reflect new maxReadFileLine default.

This description was created by Ellipsis for 1264e77. You can customize this summary. It will automatically update as commits are pushed.

@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. Enhancement New feature or request labels Dec 21, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 21, 2025

Oroocle Clock   See task on Roo Cloud

Re-review complete. truncatedByLimit handling in indentation mode looks fixed; remaining item is removing debug logging.

  • readIndentationBlock(): truncatedByLimit should not be true when the returned block spans the full possible range (no lines before/after).
  • Remove console.log debug output from collectFileLines() (leaks file contents into logs).
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph force-pushed the feat/read-file-codex-api branch from b153038 to b0362be Compare December 21, 2025 23:49
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 22, 2025
@hannesrudolph hannesrudolph force-pushed the feat/read-file-codex-api branch from 7ab3bf4 to 91018ae Compare December 23, 2025 05:24
@hannesrudolph hannesrudolph moved this from Triage to PR [Draft / In Progress] in Roo Code Roadmap Jan 7, 2026
@hannesrudolph hannesrudolph removed the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jan 7, 2026
@hannesrudolph hannesrudolph changed the title feat(read_file): implement CodexCLI-inspired slice/indentation reading modes [ENHANCEMENT] Refactor read_file tool Jan 14, 2026
@hannesrudolph hannesrudolph force-pushed the feat/read-file-codex-api branch from e73c499 to 7bd1b7d Compare January 14, 2026 16:51
@hannesrudolph hannesrudolph force-pushed the feat/read-file-codex-api branch from d347945 to ba91006 Compare January 15, 2026 05:25
lineNumber++
records.push(createLineRecord(lineNumber, buffer))
}
console.log(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collectFileLines() has a console.log(...) on stream end; since this runs in the read_file execution path it will spam logs and potentially leak file contents into logs when reading sensitive files. This looks like leftover debugging and should be removed before merge.

Fix it with Roo Code or mention @roomote and request a fix.

…g modes

Replace line_ranges with new offset/limit/mode API for improved file reading:
- Slice mode: simple line-by-line reading with offset pagination
- Indentation mode: smart code block extraction based on indentation
- Add rich metadata for pagination awareness (hasMoreBefore/After, etc.)
- Remove deprecated truncateDefinitions helper
- Update tool definition with new parameters and examples
- Default maxReadFileLine from 500 to 2000 lines
- Use consistent camelCase in error messages (anchorLine, maxLines instead of snake_case)
- Accept both camelCase and snake_case for indentation config in NativeToolCallParser
- Continue counting total lines after hitting limit in readSlice() for accurate metadata
- Return empty content instead of throwing when offset exceeds file length
- Disable strict mode in tool schema when partial reads enabled to allow truly optional params
- Update tests to match new behavior
…indentation mode

When totalLinesInFile is 0, there are no lines before the anchor point,
so hasMoreBefore must be false regardless of the offset/anchorLine value.
The limit parameter was defined in FileEntry but intentionally ignored by
ReadFileTool since the line limit is controlled by the maxReadFileLine
setting. This removes the unused type field and parsing code to align
the types with actual behavior.

- Remove limit from FileEntry interface in tool-params.ts
- Remove limit parsing from NativeToolCallParser.convertFileEntries()
- Remove limit from FileResult interface in ReadFileTool.ts
- Update comment to remove obsolete limit mention
…leLine setting

Addresses review comment about FileEntry.limit being defined but ignored.
The limit parameter was intentionally not exposed to models - it's controlled
by the maxReadFileLine user setting instead. Updated the comment in
NativeToolCallParser.ts to clarify this design decision.
Updates tests to match the new API that replaces line_ranges with:
- offset: 1-indexed starting line number
- mode: 'slice' or 'indentation' reading mode
- indentation: configuration for indentation mode

Also updates strict mode expectations since partialReadsEnabled (default true)
now sets strict to false to allow optional parameters.
…test

The ReadFileTool's execute method requires additional Task methods that were
not mocked:
- sayAndCreateMissingParamError: called when files array is empty/undefined
- cwd: used for path resolution
- apiConfiguration: used for protocol resolution
- taskToolProtocol: used for protocol resolution
- rooIgnoreController: used for access validation
- fileContextTracker: used for tracking file context

This fix ensures the test properly mocks all dependencies required by the
ReadFileTool when invoked through presentAssistantMessage.
- Fix MAX_LINE_BYTES to 500 (was 2000), rename from MAX_LINE_LENGTH for clarity
- Implement byte-based UTF-8 line truncation at safe boundaries (safeUtf8Truncate)
- Rename FALLBACK_LIMIT to DEFAULT_LINE_LIMIT for clarity
- Add maxLines property to indentation schema in tool definition
- Add test for UTF-8 boundary truncation with emoji
@hannesrudolph hannesrudolph force-pushed the feat/read-file-codex-api branch from 1264e77 to 4b14363 Compare January 15, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request PR - Draft / In Progress size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Status: PR [Draft / In Progress]

Development

Successfully merging this pull request may close these issues.

[BUG] Incremental file reading is broken across multiple providers

2 participants