Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Jan 24, 2026

Thank you @shariqriazz for this idea. (make sure to include this thank you in the change log and the release notes)

What This Does For You

When Roo condenses a long conversation, it now preserves a lightweight map of the files you worked on—function signatures, class declarations, type definitions—so it can continue referencing them accurately after condensing.

File Selection & Budget

Budget: ~50,000 characters total for folded file context.

Order: Files are included most recently read first. If the budget runs out, older files (read earlier in the task) are omitted—your most recent work is always preserved.

Scope: Only files Roo actually read (via tools or mentions) are included. Files you edited outside Roo, or files in the project Roo never saw, are not included.

How It Works

  1. Roo gathers files it read during the task, sorted by most recent first.
  2. For each file, it extracts structural definitions (signatures, declarations) using tree-sitter—no implementation bodies.
  3. Each file is wrapped in a <system-reminder> block and appended to the condensed summary.
  4. Processing stops when the 50k character budget is reached.

What You'll See

After condensing, the summary includes lightweight code outlines:

## File Context: src/api.ts
# api.ts
1--10 | export async function fetchData(url: string): Promise<Response>
12--45 | export class ApiClient

Benefits

  • Better continuity: Roo knows what exists in files it read, even after the original messages are summarized away.
  • Smarter edits: When you say "update that function," Roo still knows its shape.
  • No action required: This happens automatically—you don't need to re-share files.

Limitations

  • Budget cap: Very large codebases may have older files omitted.
  • Supported languages only: File types without tree-sitter support are skipped.
  • Read files only: Files Roo never saw are not included.

Technical Summary

  • getFilesReadByRoo() returns files sorted by most recent read timestamp
  • generateFoldedFileContext() extracts definitions via tree-sitter with a 50k char budget
  • Integrated into summarizeConversation() during context condensation
  • Each file gets its own <system-reminder> block for high-priority retention

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. Enhancement New feature or request labels Jan 24, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 24, 2026

Oroocle Clock   See task on Roo Cloud

Re-review complete. The two previously-tracked TODO items look addressed in the latest commit.

  • Consider reducing per-file error logging in folded context generation (can get noisy during condense when files are missing/denied).
  • If folded context budget is exhausted (remaining < 200 chars), consider breaking early instead of continuing to parse remaining files.
Previous reviews

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

@roomote
Copy link
Contributor

roomote bot commented Jan 24, 2026

Fixaroo Clock   See task on Roo Cloud

Fixed the reported issue. Tree-sitter error strings are now skipped instead of embedded in folded file context. All local checks passed.

View commit | Revert commit

@hannesrudolph hannesrudolph force-pushed the code-folding-condensing branch from cccc2ff to f4c395b Compare January 25, 2026 20:32
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Looks good!

-Sent from Dan's agent

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 26, 2026
@daniel-lxs
Copy link
Member

daniel-lxs commented Jan 26, 2026

One concern - did you test or research if all providers handle multiple text blocks in a single message content array properly? Some providers might have issues with this structure.

@hannesrudolph
Copy link
Collaborator Author

One concern - did you test or research if all providers handle multiple text blocks in a single message content array properly? Some providers might have issues with this structure or flatten it differently than expected.

I verified this works correctly. For user messages (which the summary is), the format converter preserves the array structure:

content: [
  { type: "text", text: "Summary..." },
  { type: "text", text: "<system-reminder>..." },
  { type: "text", text: "<system-reminder>..." }
]

The .join("\n") behavior only applies to assistant messages. All providers properly receive multiple text blocks in user messages.

@hannesrudolph hannesrudolph changed the title feat(condense): add smart code folding with tree-sitter signatures feat(condense v2.1): add smart code folding Jan 26, 2026
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jan 26, 2026
hannesrudolph added a commit that referenced this pull request Jan 27, 2026
…ntent (#10942)

The Bedrock fix in getMessagesSinceLastSummary prepends messages[0] when
the summary has assistant role, but it didn't check if messages[0] had
a condenseParent (was already condensed). This caused previously-condensed
content to incorrectly appear in the active context during nested condense
operations.

Added check for condenseParent on originalFirstMessage before prepending
it. When the original message was already condensed, we now create a
synthetic user message instead to maintain proper alternation.
hannesrudolph and others added 3 commits January 26, 2026 17:20
At context condensation time, use tree-sitter to generate folded code
signatures (function definitions, class declarations) for files read
during the conversation. Each file is included as its own <system-reminder>
block in the condensed summary, preserving structural awareness without
consuming excessive tokens.

- Add getFilesReadByRoo() method to FileContextTracker
- Create generateFoldedFileContext() using tree-sitter parsing
- Update summarizeConversation() to accept array of file sections
- Each file gets its own content block in the summary message
- Add comprehensive test coverage (12 tests)
- Add isTreeSitterErrorString helper to detect error messages
- Skip files that return error strings instead of embedding them
- Add test for error string handling
…on()

- Update summarizeConversation() to accept filesReadByRoo, cwd, rooIgnoreController instead of pre-generated sections
- Move folded file context generation inside summarizeConversation() (lines 319-339)
- Update ContextManagementOptions type and manageContext() to pass new parameters
- Remove generateFoldedFileContext from Task.ts imports - folding now handled internally
- Update all tests to use new parameter signature
- Reduces Task.ts complexity by moving folding logic to summarization module
hannesrudolph and others added 2 commits January 26, 2026 17:20
Files are now sorted by roo_read_date descending before folded context
generation, so if the character budget runs out, the most relevant
(recently read) files are included and older files are skipped.
- Convert summarizeConversation to use options object instead of 11 positional params
- Extract duplicated getFilesReadByRoo error handling into helper method
- Remove unnecessary re-export of generateFoldedFileContext
- Update all test files to use new options object pattern
hannesrudolph added a commit that referenced this pull request Jan 27, 2026
…ntent (#10942)

The Bedrock fix in getMessagesSinceLastSummary prepends messages[0] when
the summary has assistant role, but it didn't check if messages[0] had
a condenseParent (was already condensed). This caused previously-condensed
content to incorrectly appear in the active context during nested condense
operations.

Added check for condenseParent on originalFirstMessage before prepending
it. When the original message was already condensed, we now create a
synthetic user message instead to maintain proper alternation.
@hannesrudolph hannesrudolph force-pushed the code-folding-condensing branch from 1b12051 to 9a16603 Compare January 27, 2026 00:22
hannesrudolph added a commit that referenced this pull request Jan 27, 2026
…ntent (#10942)

The Bedrock fix in getMessagesSinceLastSummary prepends messages[0] when
the summary has assistant role, but it didn't check if messages[0] had
a condenseParent (was already condensed). This caused previously-condensed
content to incorrectly appear in the active context during nested condense
operations.

Added check for condenseParent on originalFirstMessage before prepending
it. When the original message was already condensed, we now create a
synthetic user message instead to maintain proper alternation.
@hannesrudolph hannesrudolph force-pushed the code-folding-condensing branch from 9a16603 to 8834ffe Compare January 27, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request lgtm This PR has been approved by a maintainer size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

4 participants