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.

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

Introduces a new API for the read_file tool with offset/limit/mode-based parameters, enhancing file reading capabilities and replacing the old line_ranges approach.

  • Behavior:
    • Replaces line_ranges with offset, limit, mode, and indentation parameters in read_file tool.
    • Supports slice and indentation modes for file reading.
    • Default maxReadFileLine increased from 500 to 2000.
  • Implementation:
    • Adds readSlice() and readIndentationBlock() in read-file-content.ts.
    • Updates NativeToolCallParser.ts to handle new parameters.
    • Modifies ReadFileTool.ts to use new reading modes.
  • Testing:
    • Updates tests in NativeToolCallParser.spec.ts and readFileTool.spec.ts.
    • Adds tests for read-file-content.ts.
  • Misc:
    • Removes truncateDefinitions.ts and related tests.
    • Updates i18n files for new functionality.

This description was created by Ellipsis for c9fdfa8. 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 for c9fdfa8.

  • read_file: FileEntry.limit is defined in types but ignored by ReadFileTool (either remove from schema/types or clamp+honor it)
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
}

// Map indentation configuration
if (file.indentation && typeof file.indentation === "object") {
Copy link
Contributor

Choose a reason for hiding this comment

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

createReadFileTool() defines indentation config keys as anchorLine/maxLevels/includeSiblings/includeHeader, but convertFileEntries() only reads indentation.anchor_line/max_levels/etc, so a tool call that follows the schema will silently drop indentation settings. Consider accepting both casings (camelCase + snake_case) or aligning the schema and examples to the parser.

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

let xmlInfo = ""
let nativeInfo = ""

if (result.lineCount === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

readSlice() rejects when offset is beyond EOF, but ReadFileTool special-cases lineCount === 0 as “offset exceeds file length”. That branch will never be hit with the current readSlice() behavior, so callers always see an error instead of a graceful empty page. If you want “empty content” semantics, consider returning { lineCount: 0, ... } when offset is past EOF rather than throwing.

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

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 22, 2025
description: "Configuration for indentation mode. Only used when mode is 'indentation'.",
properties: {
anchorLine: {
type: ["integer", "null"],
Copy link
Contributor

Choose a reason for hiding this comment

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

The native tool schema for read_file advertises indentation.anchorLine/maxLevels/includeSiblings/includeHeader (camelCase), but the examples still show indentation: { maxLevels: 2 } while the parser expects snake_case keys like max_levels. Either the schema should match what the parser accepts, or the parser should accept the camelCase keys models are likely to send.

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.
@hannesrudolph hannesrudolph force-pushed the feat/read-file-codex-api branch from 7ab3bf4 to 91018ae Compare December 23, 2025 05:24
mode?: ReadMode
/** Configuration for indentation mode */
indentation?: IndentationConfig
}
Copy link
Contributor

Choose a reason for hiding this comment

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

FileEntry in tool-params.ts still defines limit?: number, but ReadFileTool intentionally ignores entry.limit (uses maxReadFileLine only). This is a contract mismatch: models may send limit expecting it to work, and it will be silently ignored. Either document that limit is ignored (and remove it from schema/types), or wire it through and clamp to maxReadFileLine.

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

2 participants