Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit f4c395b

Browse files
roomotehannesrudolph
authored andcommitted
fix: skip tree-sitter error strings in folded file context
- Add isTreeSitterErrorString helper to detect error messages - Skip files that return error strings instead of embedding them - Add test for error string handling
1 parent 212ccb9 commit f4c395b

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/core/condense/__tests__/foldedFileContext.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,32 @@ describe("foldedFileContext", () => {
9494
expect(result.filesSkipped).toBe(1)
9595
})
9696

97+
it("should skip files when parseSourceCodeDefinitions returns error strings", async () => {
98+
// Tree-sitter can return error strings for missing or denied files
99+
// These should be treated as skipped, not embedded in the output
100+
mockedParseSourceCodeDefinitions
101+
.mockResolvedValueOnce("1--3 | export const x = 1")
102+
.mockResolvedValueOnce("This file does not exist or you do not have permission to access it.")
103+
.mockResolvedValueOnce("Unsupported file type: /test/file.xyz")
104+
105+
const result = await generateFoldedFileContext(["/test/valid.ts", "/test/missing.ts", "/test/file.xyz"], {
106+
cwd: "/test",
107+
})
108+
109+
// Only the first file should be processed, the other two return error strings
110+
expect(result.filesProcessed).toBe(1)
111+
expect(result.filesSkipped).toBe(2)
112+
113+
// The content should NOT contain the error messages
114+
expect(result.content).not.toContain("does not exist")
115+
expect(result.content).not.toContain("do not have permission")
116+
expect(result.content).not.toContain("Unsupported file type")
117+
118+
// But it should contain the valid file's content
119+
expect(result.content).toContain("## File Context: /test/valid.ts")
120+
expect(result.content).toContain("export const x = 1")
121+
})
122+
97123
it("should respect character budget limit", async () => {
98124
// Create multiple files that would exceed a small budget
99125
const longDefinitions = `1--3 | export function longFunctionName1()

src/core/condense/foldedFileContext.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ import * as path from "path"
22
import { parseSourceCodeDefinitionsForFile } from "../../services/tree-sitter"
33
import { RooIgnoreController } from "../ignore/RooIgnoreController"
44

5+
/**
6+
* Checks if a definitions string is actually an error message from tree-sitter
7+
* rather than valid code definitions. These error strings should not be embedded
8+
* in the folded file context - instead, the file should be skipped.
9+
*/
10+
function isTreeSitterErrorString(definitions: string): boolean {
11+
// These are known error messages from parseSourceCodeDefinitionsForFile
12+
const errorPatterns = ["This file does not exist", "do not have permission", "Unsupported file type:"]
13+
return errorPatterns.some((pattern) => definitions.includes(pattern))
14+
}
15+
516
/**
617
* Result of generating folded file context.
718
*/
@@ -91,8 +102,8 @@ export async function generateFoldedFileContext(
91102
// Get the folded definitions using tree-sitter
92103
const definitions = await parseSourceCodeDefinitionsForFile(absolutePath, rooIgnoreController)
93104

94-
if (!definitions) {
95-
// File type not supported or no definitions found
105+
if (!definitions || isTreeSitterErrorString(definitions)) {
106+
// File type not supported, no definitions found, or error accessing file
96107
result.filesSkipped++
97108
continue
98109
}

0 commit comments

Comments
 (0)