-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(condense): add smart code folding with tree-sitter signatures #10942
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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)
Re-review complete. The previously flagged tree-sitter error-string embedding issue is resolved in the latest commit.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
|
|
||
| try { | ||
| // Get the folded definitions using tree-sitter | ||
| const definitions = await parseSourceCodeDefinitionsForFile(absolutePath, rooIgnoreController) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseSourceCodeDefinitionsForFile() can return human-readable error strings (for example when a file is missing). Since those are truthy, generateFoldedFileContext() will embed the error text into the condensed context as if it were a code signature; it seems better to treat these as a skip (undefined/null) so condensation does not preserve error messages.
Fix it with Roo Code or mention @roomote and request a fix.
Fixed the reported issue. Tree-sitter error strings are now skipped instead of embedded in folded file context. All local checks passed. |
- Add isTreeSitterErrorString helper to detect error messages - Skip files that return error strings instead of embedding them - Add test for error string handling
Summary
At context condensation time, this PR uses tree-sitter to generate folded code signatures (function definitions, class declarations, etc.) for files that were 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.This allows the model to retain awareness of file structure after condensing, enabling better continuity when working with codebases.
File Selection Behavior
Files accumulate across multiple condensing events within a task:
This is because
files_in_contextmetadata is persisted to disk viasaveTaskMetadata(). ThegetFilesReadByRoo()method queries all files ever read during the task lifetime, not just since the last condense.File sources included:
read_tool- Files explicitly read by the agentfile_mentioned- Files mentioned/referenced in conversationChanges
FileContextTracker: Added
getFilesReadByRoo()method to query files read during the task (filters byread_toolandfile_mentionedsources)foldedFileContext.ts (new file):
generateFoldedFileContext()function using tree-sitter parsingcontent(joined string) andsections(array of individual file blocks)<system-reminder>blockindex.ts (condense): Updated
summarizeConversation()to acceptfoldedFileContextSections?: string[]and push each section as a separate content block in the summary messageTask.ts: Integrated smart code folding in
condenseContext()- callsgenerateFoldedFileContext()and passes sections tosummarizeConversation()Tests: 12 comprehensive tests covering:
Output Format
Each file gets its own content block in the summary message: