Skip to content

Commit ec62e2f

Browse files
committed
# Fix: Exclude cache files from rules compilation
## Summary Prevents system files like `.DS_Store`, `.Thumbs.db`, and other cache files from being processed as rule files in the `.roo/rules-{mode-slug}` directories. ## Changes - Added `shouldIncludeRuleFile()` function to filter out unwanted files during rule compilation - Modified `readTextFilesFromDirectory()` to apply file filtering before processing - Added support for 21 common cache file patterns including `.DS_Store`, `.db`, `.bak`, `.log`, etc. - Updated comment to reflect the new filtering behavior ## Impact - Fixes issue where macOS `.DS_Store` files were being included in system prompts - Prevents other cache and temporary files from polluting rule compilation - Improves system prompt quality and reduces noise ## Additional Notes **Why we didn't import from existing exclusion patterns:** The existing `getCacheFilePatterns()` function in `src/services/checkpoints/excludes.ts` contains identical patterns, but we cannot import from it due to architectural constraints: - The `custom-instructions.ts` file is imported by webview components that run in the browser - `excludes.ts` has Node.js dependencies (`fs/promises`, `path`) that cannot be bundled for browser environments - Importing from `excludes.ts` would cause Vite build failures in the webview This is a necessary architectural trade-off to maintain browser compatibility while solving the cache file inclusion issue. Resolves: #2728
1 parent 24eb6e4 commit ec62e2f

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/core/prompts/sections/custom-instructions.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ async function readTextFilesFromDirectory(dirPath: string): Promise<Array<{ file
123123
// Check if it's a file (not a directory)
124124
const stats = await fs.stat(file)
125125
if (stats.isFile()) {
126+
// Filter out cache files and system files that shouldn't be in rules
127+
if (!shouldIncludeRuleFile(file)) {
128+
return null
129+
}
126130
const content = await safeReadFile(file)
127131
return { filename: file, content }
128132
}
@@ -133,7 +137,7 @@ async function readTextFilesFromDirectory(dirPath: string): Promise<Array<{ file
133137
}),
134138
)
135139

136-
// Filter out null values (directories or failed reads)
140+
// Filter out null values (directories, failed reads, or excluded files)
137141
return fileContents.filter((item): item is { filename: string; content: string } => item !== null)
138142
} catch (err) {
139143
return []
@@ -297,3 +301,48 @@ The following additional instructions are provided by the user, and should be fo
297301
${joinedSections}`
298302
: ""
299303
}
304+
305+
/**
306+
* Check if a file should be included in rule compilation.
307+
* Excludes cache files and system files that shouldn't be processed as rules.
308+
*/
309+
function shouldIncludeRuleFile(filename: string): boolean {
310+
const basename = path.basename(filename)
311+
312+
const cachePatterns = [
313+
"*.DS_Store",
314+
"*.bak",
315+
"*.cache",
316+
"*.crdownload",
317+
"*.db",
318+
"*.dmp",
319+
"*.dump",
320+
"*.eslintcache",
321+
"*.lock",
322+
"*.log",
323+
"*.old",
324+
"*.part",
325+
"*.partial",
326+
"*.pyc",
327+
"*.pyo",
328+
"*.stackdump",
329+
"*.swo",
330+
"*.swp",
331+
"*.temp",
332+
"*.tmp",
333+
"*.Thumbs.db",
334+
]
335+
336+
for (const pattern of cachePatterns) {
337+
if (pattern.startsWith("*.")) {
338+
const extension = pattern.slice(1)
339+
if (basename.endsWith(extension)) {
340+
return false
341+
}
342+
} else if (basename === pattern) {
343+
return false
344+
}
345+
}
346+
347+
return true
348+
}

0 commit comments

Comments
 (0)