Skip to content

Commit 9bbbaf2

Browse files
committed
Add a new setting to control the number of workspace files included in the system prompt
1 parent a679c95 commit 9bbbaf2

File tree

13 files changed

+90
-11
lines changed

13 files changed

+90
-11
lines changed

src/core/Cline.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3501,14 +3501,15 @@ export class Cline extends EventEmitter<ClineEvents> {
35013501
async getEnvironmentDetails(includeFileDetails: boolean = false) {
35023502
let details = ""
35033503

3504-
const { terminalOutputLineLimit } = (await this.providerRef.deref()?.getState()) ?? {}
3504+
const { terminalOutputLineLimit, maxWorkspaceFiles } = (await this.providerRef.deref()?.getState()) ?? {}
35053505

35063506
// It could be useful for cline to know if the user went from one or no file to another between messages, so we always include this context
35073507
details += "\n\n# VSCode Visible Files"
35083508
const visibleFilePaths = vscode.window.visibleTextEditors
35093509
?.map((editor) => editor.document?.uri?.fsPath)
35103510
.filter(Boolean)
35113511
.map((absolutePath) => path.relative(cwd, absolutePath))
3512+
.slice(0, maxWorkspaceFiles ?? 200)
35123513

35133514
// Filter paths through rooIgnoreController
35143515
const allowedVisibleFiles = this.rooIgnoreController
@@ -3715,7 +3716,8 @@ export class Cline extends EventEmitter<ClineEvents> {
37153716
// don't want to immediately access desktop since it would show permission popup
37163717
details += "(Desktop files not shown automatically. Use list_files to explore if needed.)"
37173718
} else {
3718-
const [files, didHitLimit] = await listFiles(cwd, true, 200)
3719+
const maxFiles = maxWorkspaceFiles ?? 200
3720+
const [files, didHitLimit] = await listFiles(cwd, true, maxFiles)
37193721
const { showRooIgnoredFiles } = (await this.providerRef.deref()?.getState()) ?? {}
37203722
const result = formatResponse.formatFilesList(
37213723
cwd,

src/core/webview/ClineProvider.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,11 @@ export class ClineProvider implements vscode.WebviewViewProvider {
15181518
await this.updateGlobalState("maxOpenTabsContext", tabCount)
15191519
await this.postStateToWebview()
15201520
break
1521+
case "maxWorkspaceFiles":
1522+
const fileCount = Math.min(Math.max(0, message.value ?? 200), 500)
1523+
await this.updateGlobalState("maxWorkspaceFiles", fileCount)
1524+
await this.postStateToWebview()
1525+
break
15211526
case "browserToolEnabled":
15221527
await this.updateGlobalState("browserToolEnabled", message.bool ?? true)
15231528
await this.postStateToWebview()
@@ -2297,6 +2302,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
22972302
autoApprovalEnabled,
22982303
experiments,
22992304
maxOpenTabsContext,
2305+
maxWorkspaceFiles,
23002306
browserToolEnabled,
23012307
telemetrySetting,
23022308
showRooIgnoredFiles,
@@ -2359,6 +2365,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
23592365
experiments: experiments ?? experimentDefault,
23602366
mcpServers: this.mcpHub?.getAllServers() ?? [],
23612367
maxOpenTabsContext: maxOpenTabsContext ?? 20,
2368+
maxWorkspaceFiles: maxWorkspaceFiles ?? 200,
23622369
cwd,
23632370
browserToolEnabled: browserToolEnabled ?? true,
23642371
telemetrySetting,
@@ -2516,6 +2523,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
25162523
autoApprovalEnabled: stateValues.autoApprovalEnabled ?? false,
25172524
customModes,
25182525
maxOpenTabsContext: stateValues.maxOpenTabsContext ?? 20,
2526+
maxWorkspaceFiles: stateValues.maxWorkspaceFiles ?? 200,
25192527
openRouterUseMiddleOutTransform: stateValues.openRouterUseMiddleOutTransform ?? true,
25202528
browserToolEnabled: stateValues.browserToolEnabled ?? true,
25212529
telemetrySetting: stateValues.telemetrySetting || "unset",

src/core/webview/__tests__/ClineProvider.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ describe("ClineProvider", () => {
448448
customModes: [],
449449
experiments: experimentDefault,
450450
maxOpenTabsContext: 20,
451+
maxWorkspaceFiles: 200,
451452
browserToolEnabled: true,
452453
telemetrySetting: "unset",
453454
showRooIgnoredFiles: true,
@@ -794,6 +795,17 @@ describe("ClineProvider", () => {
794795
expect(state.customModePrompts).toEqual({})
795796
})
796797

798+
test("handles maxWorkspaceFiles message", async () => {
799+
await provider.resolveWebviewView(mockWebviewView)
800+
const messageHandler = (mockWebviewView.webview.onDidReceiveMessage as jest.Mock).mock.calls[0][0]
801+
802+
await messageHandler({ type: "maxWorkspaceFiles", value: 300 })
803+
804+
expect(mockContextProxy.updateGlobalState).toHaveBeenCalledWith("maxWorkspaceFiles", 300)
805+
expect(mockContext.globalState.update).toHaveBeenCalledWith("maxWorkspaceFiles", 300)
806+
expect(mockPostMessage).toHaveBeenCalled()
807+
})
808+
797809
test.only("uses mode-specific custom instructions in Cline initialization", async () => {
798810
// Setup mock state
799811
const modeCustomInstructions = "Code mode instructions"

src/exports/roo-code.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export type GlobalStateKey =
211211
| "modelMaxTokens"
212212
| "mistralCodestralUrl"
213213
| "maxOpenTabsContext"
214+
| "maxWorkspaceFiles"
214215
| "browserToolEnabled"
215216
| "lmStudioSpeculativeDecodingEnabled"
216217
| "lmStudioDraftModelId"

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export interface ExtensionState {
147147
customModes: ModeConfig[]
148148
toolRequirements?: Record<string, boolean> // Map of tool names to their requirements (e.g. {"apply_diff": true} if diffEnabled)
149149
maxOpenTabsContext: number // Maximum number of VSCode open tabs to include in context (0-500)
150+
maxWorkspaceFiles: number // Maximum number of files to include in current working directory details (0-500)
150151
cwd?: string // Current working directory
151152
telemetrySetting: TelemetrySetting
152153
telemetryKey?: string

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export interface WebviewMessage {
9797
| "checkpointRestore"
9898
| "deleteMcpServer"
9999
| "maxOpenTabsContext"
100+
| "maxWorkspaceFiles"
100101
| "humanRelayResponse"
101102
| "humanRelayCancel"
102103
| "browserToolEnabled"

src/shared/globalState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export const GLOBAL_STATE_KEYS = [
116116
"telemetrySetting",
117117
"showRooIgnoredFiles",
118118
"remoteBrowserEnabled",
119+
"maxWorkspaceFiles",
119120
] as const
120121

121122
type CheckGlobalStateKeysExhaustiveness =

webview-ui/src/__mocks__/lucide-react.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export const Check = () => React.createElement("div")
44
export const ChevronsUpDown = () => React.createElement("div")
55
export const Loader = () => React.createElement("div")
66
export const X = () => React.createElement("div")
7+
export const Database = (props: any) => React.createElement("span", { "data-testid": "database-icon", ...props })

webview-ui/src/components/settings/ContextManagementSettings.tsx

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,25 @@ import { Section } from "./Section"
1212
type ContextManagementSettingsProps = HTMLAttributes<HTMLDivElement> & {
1313
terminalOutputLineLimit?: number
1414
maxOpenTabsContext: number
15+
maxWorkspaceFiles: number
1516
showRooIgnoredFiles?: boolean
16-
setCachedStateField: SetCachedStateField<"terminalOutputLineLimit" | "maxOpenTabsContext" | "showRooIgnoredFiles">
17+
setCachedStateField: SetCachedStateField<
18+
"terminalOutputLineLimit" | "maxOpenTabsContext" | "maxWorkspaceFiles" | "showRooIgnoredFiles"
19+
>
1720
}
1821

1922
export const ContextManagementSettings = ({
2023
terminalOutputLineLimit,
2124
maxOpenTabsContext,
25+
maxWorkspaceFiles,
2226
showRooIgnoredFiles,
2327
setCachedStateField,
2428
className,
2529
...props
2630
}: ContextManagementSettingsProps) => {
2731
return (
2832
<div className={cn("flex flex-col gap-2", className)} {...props}>
29-
<SectionHeader>
33+
<SectionHeader description="Control what information is included in the AI's context window, affecting token usage and response quality">
3034
<div className="flex items-center gap-2">
3135
<Database className="w-4" />
3236
<div>Context Management</div>
@@ -48,6 +52,7 @@ export const ContextManagementSettings = ({
4852
setCachedStateField("terminalOutputLineLimit", parseInt(e.target.value))
4953
}
5054
className="h-2 focus:outline-0 w-4/5 accent-vscode-button-background"
55+
data-testid="terminal-output-limit-slider"
5156
/>
5257
<span style={{ ...sliderLabelStyle }}>{terminalOutputLineLimit ?? 500}</span>
5358
</div>
@@ -70,6 +75,7 @@ export const ContextManagementSettings = ({
7075
value={maxOpenTabsContext ?? 20}
7176
onChange={(e) => setCachedStateField("maxOpenTabsContext", parseInt(e.target.value))}
7277
className="h-2 focus:outline-0 w-4/5 accent-vscode-button-background"
78+
data-testid="open-tabs-limit-slider"
7379
/>
7480
<span style={{ ...sliderLabelStyle }}>{maxOpenTabsContext ?? 20}</span>
7581
</div>
@@ -80,12 +86,36 @@ export const ContextManagementSettings = ({
8086
</p>
8187
</div>
8288

89+
<div>
90+
<div className="flex flex-col gap-2">
91+
<span className="font-medium">Workspace files context limit</span>
92+
<div className="flex items-center gap-2">
93+
<input
94+
type="range"
95+
min="0"
96+
max="500"
97+
step="1"
98+
value={maxWorkspaceFiles ?? 200}
99+
onChange={(e) => setCachedStateField("maxWorkspaceFiles", parseInt(e.target.value))}
100+
className="h-2 focus:outline-0 w-4/5 accent-vscode-button-background"
101+
data-testid="workspace-files-limit-slider"
102+
/>
103+
<span style={{ ...sliderLabelStyle }}>{maxWorkspaceFiles ?? 200}</span>
104+
</div>
105+
</div>
106+
<p className="text-vscode-descriptionForeground text-sm mt-0">
107+
Maximum number of files to include in current working directory details. Higher values provide
108+
more context but increase token usage.
109+
</p>
110+
</div>
111+
83112
<div>
84113
<VSCodeCheckbox
85114
checked={showRooIgnoredFiles}
86115
onChange={(e: any) => {
87116
setCachedStateField("showRooIgnoredFiles", e.target.checked)
88-
}}>
117+
}}
118+
data-testid="show-rooignored-files-checkbox">
89119
<span className="font-medium">Show .rooignore'd files in lists and searches</span>
90120
</VSCodeCheckbox>
91121
<p className="text-vscode-descriptionForeground text-sm mt-0">

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone },
8585
experiments,
8686
fuzzyMatchThreshold,
8787
maxOpenTabsContext,
88+
maxWorkspaceFiles,
8889
mcpEnabled,
8990
rateLimitSeconds,
9091
requestDelaySeconds,
@@ -196,6 +197,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone },
196197
vscode.postMessage({ type: "requestDelaySeconds", value: requestDelaySeconds })
197198
vscode.postMessage({ type: "rateLimitSeconds", value: rateLimitSeconds })
198199
vscode.postMessage({ type: "maxOpenTabsContext", value: maxOpenTabsContext })
200+
vscode.postMessage({ type: "maxWorkspaceFiles", value: maxWorkspaceFiles ?? 200 })
199201
vscode.postMessage({ type: "showRooIgnoredFiles", bool: showRooIgnoredFiles })
200202
vscode.postMessage({ type: "currentApiConfigName", text: currentApiConfigName })
201203
vscode.postMessage({ type: "updateExperimental", values: experiments })
@@ -410,6 +412,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone },
410412
<ContextManagementSettings
411413
terminalOutputLineLimit={terminalOutputLineLimit}
412414
maxOpenTabsContext={maxOpenTabsContext}
415+
maxWorkspaceFiles={maxWorkspaceFiles ?? 200}
413416
showRooIgnoredFiles={showRooIgnoredFiles}
414417
setCachedStateField={setCachedStateField}
415418
/>

0 commit comments

Comments
 (0)