Skip to content

Conversation

elianiva
Copy link

@elianiva elianiva commented Oct 4, 2025

Related GitHub Issue

Closes: #8149

Roo Code Task Context (Optional

Description

This PR adds the ability to truncate the list_code_definition_names to match the maximum line that can be read. Previously, only the read_file tool call that applies this limit. Since list_code_definition_names come from the file, it should also respect that setting. Otherwise we might pollute the context and exceeds the context window limit.

Test Procedure

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates

Additional Notes

Get in Touch

@elianiva


Important

Add truncation of code definitions to respect maxReadFileLine in listCodeDefinitionNamesTool and readFileTool.

  • Behavior:
    • listCodeDefinitionNamesTool in listCodeDefinitionNamesTool.ts now truncates code definitions based on maxReadFileLine setting.
    • readFileTool in readFileTool.ts applies truncation to code definitions when reading files exceeding line limits.
  • Helpers:
    • New function truncateDefinitionsToLineLimit in truncateDefinitions.ts to handle truncation logic.
  • Tests:
    • Added tests for truncateDefinitionsToLineLimit in truncateDefinitions.spec.ts.
    • Added tests for listCodeDefinitionNamesTool in listCodeDefinitionNamesTool.spec.ts to verify truncation behavior.

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

@elianiva elianiva requested review from mrubens, cte and jr as code owners October 4, 2025 12:18
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. bug Something isn't working labels Oct 4, 2025
Copy link

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

I found some issues that need attention. See inline comments.

const line = lines[i]

// Match definition format: "startLine--endLine | content" or "lineNumber | content"
const rangeMatch = line.match(/^(\d+)(?:--(\d+))?\s*\|/)
Copy link

Choose a reason for hiding this comment

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

P2: The regex doesn't account for leading whitespace on definition lines (e.g., indented output or CRLF artifacts). This can cause valid lines to be skipped. Consider allowing optional leading whitespace to make parsing more robust.

Suggested change
const rangeMatch = line.match(/^(\d+)(?:--(\d+))?\s*\|/)
const rangeMatch = line.match(/^\s*(\d+)(?:--(\d+))?\s*\|/)

if (defResult) {
xmlInfo += `<list_code_definition_names>${defResult}</list_code_definition_names>\n`
// Truncate definitions to match the truncated file content
const truncatedDefs = truncateDefinitionsToLineLimit(defResult, maxReadFileLine)
Copy link

Choose a reason for hiding this comment

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

P3: Truncation is now applied to embedded code definitions in the truncated-read path. Please add a unit test covering this path (similar to listCodeDefinitionNamesTool.spec.ts and truncateDefinitions.spec.ts) to prevent regressions.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
Status: Triage
Development

Successfully merging this pull request may close these issues.

[BUG]Regarding automatic file truncation
2 participants