Skip to content

Commit bc00c16

Browse files
committed
feat: add maxConcurrentFileReads setting to enhance read_file tool performance
1 parent ae69555 commit bc00c16

File tree

16 files changed

+70
-4
lines changed

16 files changed

+70
-4
lines changed

src/core/Cline.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ export class Cline extends EventEmitter<ClineEvents> {
986986
enableMcpServerCreation,
987987
browserToolEnabled,
988988
language,
989+
maxConcurrentFileReads,
989990
} = (await this.providerRef.deref()?.getState()) ?? {}
990991

991992
const { customModes } = (await this.providerRef.deref()?.getState()) ?? {}
@@ -1013,6 +1014,9 @@ export class Cline extends EventEmitter<ClineEvents> {
10131014
enableMcpServerCreation,
10141015
language,
10151016
rooIgnoreInstructions,
1017+
{
1018+
maxConcurrentFileReads,
1019+
},
10161020
)
10171021
})()
10181022

src/core/prompts/system.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ async function generatePrompt(
4444
enableMcpServerCreation?: boolean,
4545
language?: string,
4646
rooIgnoreInstructions?: string,
47+
settings?: Record<string, any>,
4748
): Promise<string> {
4849
if (!context) {
4950
throw new Error("Extension context is required for generating system prompt")
@@ -76,6 +77,7 @@ ${getToolDescriptionsForMode(
7677
mcpHub,
7778
customModeConfigs,
7879
experiments,
80+
settings,
7981
)}
8082
8183
${getToolUseGuidelinesSection()}
@@ -113,6 +115,7 @@ export const SYSTEM_PROMPT = async (
113115
enableMcpServerCreation?: boolean,
114116
language?: string,
115117
rooIgnoreInstructions?: string,
118+
settings?: Record<string, any>,
116119
): Promise<string> => {
117120
if (!context) {
118121
throw new Error("Extension context is required for generating system prompt")
@@ -179,5 +182,6 @@ ${customInstructions}`
179182
enableMcpServerCreation,
180183
language,
181184
rooIgnoreInstructions,
185+
settings,
182186
)
183187
}

src/core/prompts/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export function getToolDescriptionsForMode(
5252
mcpHub?: McpHub,
5353
customModes?: ModeConfig[],
5454
experiments?: Record<string, boolean>,
55+
settings?: Record<string, any>,
5556
): string {
5657
const config = getModeConfig(mode, customModes)
5758
const args: ToolArgs = {
@@ -60,6 +61,7 @@ export function getToolDescriptionsForMode(
6061
diffStrategy,
6162
browserViewportSize,
6263
mcpHub,
64+
settings,
6365
}
6466

6567
const tools = new Set<string>()

src/core/prompts/tools/read-file.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export function getReadFileDescription(args: ToolArgs): string {
44
return `## read_file
55
Description: Request to read the contents of one or more files. The tool outputs line-numbered content (e.g. "1 | const x = 1") for easy reference when creating diffs or discussing code. Use line ranges to efficiently read specific portions of large files. Supports text extraction from PDF and DOCX files, but may not handle other binary files properly.
66
7+
${args.settings?.maxConcurrentFileReads ? `**IMPORTANT: You can read a maximum of ${args.settings?.maxConcurrentFileReads} files in a single request.** If you need to read more files, use multiple sequential read_file requests.` : ""}
8+
79
Parameters:
810
- args: Contains one or more file elements, where each file contains:
911
- path: (required) File path (relative to workspace directory ${args.cwd})
@@ -32,7 +34,7 @@ Examples:
3234
</args>
3335
</read_file>
3436
35-
2. Reading multiple files with different line ranges:
37+
2. Reading multiple files with different line ranges${args.settings?.maxConcurrentFileReads ? ` (within the ${args.settings?.maxConcurrentFileReads}-file limit)` : ""}:
3638
<read_file>
3739
<args>
3840
<file>
@@ -57,9 +59,10 @@ Examples:
5759
</read_file>
5860
5961
IMPORTANT: You MUST use this Efficient Reading Strategy:
60-
- You MUST read all related files and implementations together in a single operation
62+
- You MUST read all related files and implementations together in a single operation${args.settings?.maxConcurrentFileReads ? ` (up to ${args.settings?.maxConcurrentFileReads} files at once)` : ""}
6163
- You MUST obtain all necessary context before proceeding with changes
6264
- You MUST combine adjacent line ranges (<10 lines apart)
6365
- You MUST use multiple ranges for content separated by >10 lines
64-
- You MUST include sufficient line context for planned modifications while keeping ranges minimal`
66+
- You MUST include sufficient line context for planned modifications while keeping ranges minimal
67+
${args.settings?.maxConcurrentFileReads ? `- When you need to read more than ${args.settings?.maxConcurrentFileReads} files, prioritize the most critical files first, then use subsequent read_file requests for additional files` : ""}`
6568
}

src/core/prompts/tools/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export type ToolArgs = {
88
browserViewportSize?: string
99
mcpHub?: McpHub
1010
toolOptions?: any
11+
settings?: Record<string, any>
1112
}

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
11941194
maxReadFileLine,
11951195
terminalCompressProgressBar,
11961196
historyPreviewCollapsed,
1197+
maxConcurrentFileReads,
11971198
} = await this.getState()
11981199

11991200
const telemetryKey = process.env.POSTHOG_API_KEY
@@ -1277,6 +1278,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
12771278
language: language ?? formatLanguage(vscode.env.language),
12781279
renderContext: this.renderContext,
12791280
maxReadFileLine: maxReadFileLine ?? 500,
1281+
maxConcurrentFileReads: maxConcurrentFileReads ?? 5,
12801282
settingsImportedAt: this.settingsImportedAt,
12811283
terminalCompressProgressBar: terminalCompressProgressBar ?? true,
12821284
hasSystemPromptOverride,
@@ -1370,6 +1372,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
13701372
telemetrySetting: stateValues.telemetrySetting || "unset",
13711373
showRooIgnoredFiles: stateValues.showRooIgnoredFiles ?? true,
13721374
maxReadFileLine: stateValues.maxReadFileLine ?? 500,
1375+
maxConcurrentFileReads: stateValues.maxConcurrentFileReads ?? 1,
13731376
historyPreviewCollapsed: stateValues.historyPreviewCollapsed ?? false,
13741377
}
13751378
}

src/core/webview/webviewMessageHandler.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,11 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
856856
await updateGlobalState("maxReadFileLine", message.value)
857857
await provider.postStateToWebview()
858858
break
859+
case "maxConcurrentFileReads":
860+
const valueToSave = message.value // Capture the value intended for saving
861+
await updateGlobalState("maxConcurrentFileReads", valueToSave)
862+
await provider.postStateToWebview()
863+
break
859864
case "setHistoryPreviewCollapsed": // Add the new case handler
860865
await updateGlobalState("historyPreviewCollapsed", message.bool ?? false)
861866
// No need to call postStateToWebview here as the UI already updated optimistically
@@ -1273,6 +1278,7 @@ const generateSystemPrompt = async (provider: ClineProvider, message: WebviewMes
12731278
enableMcpServerCreation,
12741279
browserToolEnabled,
12751280
language,
1281+
maxConcurrentFileReads,
12761282
} = await provider.getState()
12771283

12781284
const diffStrategy = new MultiSearchReplaceDiffStrategy(fuzzyMatchThreshold)
@@ -1320,6 +1326,9 @@ const generateSystemPrompt = async (provider: ClineProvider, message: WebviewMes
13201326
enableMcpServerCreation,
13211327
language,
13221328
rooIgnoreInstructions,
1329+
{
1330+
maxConcurrentFileReads,
1331+
},
13231332
)
13241333

13251334
return systemPrompt

src/exports/roo-code.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ type GlobalSettings = {
213213
maxWorkspaceFiles?: number | undefined
214214
showRooIgnoredFiles?: boolean | undefined
215215
maxReadFileLine?: number | undefined
216+
maxConcurrentFileReads?: number | undefined
216217
terminalOutputLineLimit?: number | undefined
217218
terminalShellIntegrationTimeout?: number | undefined
218219
terminalShellIntegrationDisabled?: boolean | undefined

src/exports/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ type GlobalSettings = {
216216
maxWorkspaceFiles?: number | undefined
217217
showRooIgnoredFiles?: boolean | undefined
218218
maxReadFileLine?: number | undefined
219+
maxConcurrentFileReads?: number | undefined
219220
terminalOutputLineLimit?: number | undefined
220221
terminalShellIntegrationTimeout?: number | undefined
221222
terminalShellIntegrationDisabled?: boolean | undefined

src/schemas/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ export const globalSettingsSchema = z.object({
573573
maxWorkspaceFiles: z.number().optional(),
574574
showRooIgnoredFiles: z.boolean().optional(),
575575
maxReadFileLine: z.number().optional(),
576+
maxConcurrentFileReads: z.number().optional(),
576577

577578
terminalOutputLineLimit: z.number().optional(),
578579
terminalShellIntegrationTimeout: z.number().optional(),
@@ -651,6 +652,7 @@ const globalSettingsRecord: GlobalSettingsRecord = {
651652
maxWorkspaceFiles: undefined,
652653
showRooIgnoredFiles: undefined,
653654
maxReadFileLine: undefined,
655+
maxConcurrentFileReads: undefined,
654656

655657
terminalOutputLineLimit: undefined,
656658
terminalShellIntegrationTimeout: undefined,

0 commit comments

Comments
 (0)