Skip to content

Commit b563615

Browse files
feat(config): add setting to make directory tree context configurable (#19053)
1 parent c62601e commit b563615

8 files changed

Lines changed: 54 additions & 1 deletion

File tree

docs/get-started/configuration.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,11 @@ their corresponding top-level category object in your `settings.json` file.
633633
- **Description:** The format to use when importing memory.
634634
- **Default:** `undefined`
635635

636+
- **`context.includeDirectoryTree`** (boolean):
637+
- **Description:** Whether to include the directory tree of the current
638+
working directory in the initial request to the model.
639+
- **Default:** `true`
640+
636641
- **`context.discoveryMaxDirs`** (number):
637642
- **Description:** Maximum number of directories to search for memory.
638643
- **Default:** `200`

packages/cli/src/config/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ export async function loadCliConfig(
454454
}
455455

456456
const memoryImportFormat = settings.context?.importFormat || 'tree';
457+
const includeDirectoryTree = settings.context?.includeDirectoryTree ?? true;
457458

458459
const ideMode = settings.ide?.enabled ?? false;
459460

@@ -745,6 +746,7 @@ export async function loadCliConfig(
745746
embeddingModel: DEFAULT_GEMINI_EMBEDDING_MODEL,
746747
sandbox: sandboxConfig,
747748
targetDir: cwd,
749+
includeDirectoryTree,
748750
includeDirectories,
749751
loadMemoryFromIncludeDirectories:
750752
settings.context?.loadMemoryFromIncludeDirectories || false,

packages/cli/src/config/settingsSchema.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,16 @@ const SETTINGS_SCHEMA = {
949949
description: 'The format to use when importing memory.',
950950
showInDialog: false,
951951
},
952+
includeDirectoryTree: {
953+
type: 'boolean',
954+
label: 'Include Directory Tree',
955+
category: 'Context',
956+
requiresRestart: false,
957+
default: true,
958+
description:
959+
'Whether to include the directory tree of the current working directory in the initial request to the model.',
960+
showInDialog: false,
961+
},
952962
discoveryMaxDirs: {
953963
type: 'number',
954964
label: 'Memory Discovery Max Dirs',

packages/core/src/config/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ export interface ConfigParameters {
436436
folderTrust?: boolean;
437437
ideMode?: boolean;
438438
loadMemoryFromIncludeDirectories?: boolean;
439+
includeDirectoryTree?: boolean;
439440
importFormat?: 'tree' | 'flat';
440441
discoveryMaxDirs?: number;
441442
compressionThreshold?: number;
@@ -603,6 +604,7 @@ export class Config {
603604
| undefined;
604605
private readonly experimentalZedIntegration: boolean = false;
605606
private readonly loadMemoryFromIncludeDirectories: boolean = false;
607+
private readonly includeDirectoryTree: boolean = true;
606608
private readonly importFormat: 'tree' | 'flat';
607609
private readonly discoveryMaxDirs: number;
608610
private readonly compressionThreshold: number | undefined;
@@ -786,6 +788,7 @@ export class Config {
786788
this.summarizeToolOutput = params.summarizeToolOutput;
787789
this.folderTrust = params.folderTrust ?? false;
788790
this.ideMode = params.ideMode ?? false;
791+
this.includeDirectoryTree = params.includeDirectoryTree ?? true;
789792
this.loadMemoryFromIncludeDirectories =
790793
params.loadMemoryFromIncludeDirectories ?? false;
791794
this.importFormat = params.importFormat ?? 'tree';
@@ -1161,6 +1164,10 @@ export class Config {
11611164
return this.loadMemoryFromIncludeDirectories;
11621165
}
11631166

1167+
getIncludeDirectoryTree(): boolean {
1168+
return this.includeDirectoryTree;
1169+
}
1170+
11641171
getImportFormat(): 'tree' | 'flat' {
11651172
return this.importFormat;
11661173
}

packages/core/src/core/client.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ describe('Gemini Client (client.ts)', () => {
244244
getShowModelInfoInChat: vi.fn().mockReturnValue(false),
245245
getContinueOnFailedApiCall: vi.fn(),
246246
getProjectRoot: vi.fn().mockReturnValue('/test/project/root'),
247+
getIncludeDirectoryTree: vi.fn().mockReturnValue(true),
247248
storage: {
248249
getProjectTempDir: vi.fn().mockReturnValue('/test/temp'),
249250
},

packages/core/src/utils/environmentContext.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe('getEnvironmentContext', () => {
8888
getDirectories: vi.fn().mockReturnValue(['/test/dir']),
8989
}),
9090
getFileService: vi.fn(),
91+
getIncludeDirectoryTree: vi.fn().mockReturnValue(true),
9192
getEnvironmentMemory: vi.fn().mockReturnValue('Mock Environment Memory'),
9293

9394
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
@@ -146,6 +147,24 @@ describe('getEnvironmentContext', () => {
146147
expect(getFolderStructure).toHaveBeenCalledTimes(2);
147148
});
148149

150+
it('should omit directory structure when getIncludeDirectoryTree is false', async () => {
151+
(vi.mocked(mockConfig.getIncludeDirectoryTree!) as Mock).mockReturnValue(
152+
false,
153+
);
154+
155+
const parts = await getEnvironmentContext(mockConfig as Config);
156+
157+
expect(parts.length).toBe(1);
158+
const context = parts[0].text;
159+
160+
expect(context).toContain('<session_context>');
161+
expect(context).not.toContain('Directory Structure:');
162+
expect(context).not.toContain('Mock Folder Structure');
163+
expect(context).toContain('Mock Environment Memory');
164+
expect(context).toContain('</session_context>');
165+
expect(getFolderStructure).not.toHaveBeenCalled();
166+
});
167+
149168
it('should handle read_many_files returning no content', async () => {
150169
const mockReadManyFilesTool = {
151170
build: vi.fn().mockReturnValue({

packages/core/src/utils/environmentContext.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export async function getEnvironmentContext(config: Config): Promise<Part[]> {
5353
day: 'numeric',
5454
});
5555
const platform = process.platform;
56-
const directoryContext = await getDirectoryContextString(config);
56+
const directoryContext = config.getIncludeDirectoryTree()
57+
? await getDirectoryContextString(config)
58+
: '';
5759
const tempDir = config.storage.getProjectTempDir();
5860
const environmentMemory = config.getEnvironmentMemory();
5961

schemas/settings.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,13 @@
10521052
"markdownDescription": "The format to use when importing memory.\n\n- Category: `Context`\n- Requires restart: `no`",
10531053
"type": "string"
10541054
},
1055+
"includeDirectoryTree": {
1056+
"title": "Include Directory Tree",
1057+
"description": "Whether to include the directory tree of the current working directory in the initial request to the model.",
1058+
"markdownDescription": "Whether to include the directory tree of the current working directory in the initial request to the model.\n\n- Category: `Context`\n- Requires restart: `no`\n- Default: `true`",
1059+
"default": true,
1060+
"type": "boolean"
1061+
},
10551062
"discoveryMaxDirs": {
10561063
"title": "Memory Discovery Max Dirs",
10571064
"description": "Maximum number of directories to search for memory.",

0 commit comments

Comments
 (0)