@@ -26,6 +26,30 @@ import { OpenRouterHandler } from "../../api/providers/openrouter"
2626import { TelemetryService } from "@roo-code/telemetry"
2727import { t } from "../../i18n"
2828import { NativeOllamaHandler } from "../../api/providers/native-ollama"
29+
30+ // Multiplier for fetching extra files when filtering is enabled to ensure enough non-ignored files; only applied when showRooIgnoredFiles is false.
31+ const FILE_LIST_OVER_FETCH_MULTIPLIER = 3
32+
33+ function trimFileList ( fileListStr : string , maxFiles : number ) {
34+ let lines = fileListStr . split ( "\n" )
35+ if ( lines . length <= maxFiles ) {
36+ return fileListStr
37+ }
38+
39+ const lastLine = lines [ lines . length - 1 ]
40+ if ( lastLine . startsWith ( "(File list truncated." ) ) {
41+ // Remove last 3 items from lines (two empty lines and truncation message)
42+ lines = lines . slice ( 0 , - 3 )
43+ }
44+
45+ // Truncate lines to maxFiles
46+ lines = lines . slice ( 0 , maxFiles )
47+
48+ const truncationMsg =
49+ "(File list truncated. Use list_files on specific subdirectories if you need to explore further.)"
50+
51+ return lines . join ( "\n" ) + "\n\n" + truncationMsg
52+ }
2953// kilocode_change end
3054
3155export async function getEnvironmentDetails ( cline : Task , includeFileDetails : boolean = false ) {
@@ -282,9 +306,15 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
282306 if ( maxFiles === 0 ) {
283307 details += "(Workspace files context disabled. Use list_files to explore if needed.)"
284308 } else {
285- const [ files , didHitLimit ] = await listFiles ( cline . cwd , true , maxFiles )
286309 const { showRooIgnoredFiles = false } = state ?? { }
287310
311+ // kilocode_change start
312+ // Only apply multiplier when filtering will remove files (showRooIgnoredFiles = false)
313+ // When showRooIgnoredFiles = true, ignored files are just marked with lock symbol, not removed
314+ const fetchLimit = showRooIgnoredFiles ? maxFiles : maxFiles * FILE_LIST_OVER_FETCH_MULTIPLIER
315+ const [ files , didHitLimit ] = await listFiles ( cline . cwd , true , fetchLimit )
316+ // kilocode_change end
317+
288318 const result = formatResponse . formatFilesList (
289319 cline . cwd ,
290320 files ,
@@ -293,7 +323,14 @@ export async function getEnvironmentDetails(cline: Task, includeFileDetails: boo
293323 showRooIgnoredFiles ,
294324 )
295325
296- details += result
326+ // kilocode_change start
327+ if ( ! showRooIgnoredFiles ) {
328+ // Trim because we over-fetched
329+ details += trimFileList ( result , maxFiles )
330+ } else {
331+ details += result
332+ }
333+ // kilocode_change end
297334 }
298335 }
299336 }
0 commit comments