feat(config): add setting to make directory tree context configurable (#19053)

This commit is contained in:
Kevin Ramdass
2026-02-17 11:19:26 -08:00
committed by GitHub
parent c62601e90c
commit b56361559d
8 changed files with 54 additions and 1 deletions
+7
View File
@@ -436,6 +436,7 @@ export interface ConfigParameters {
folderTrust?: boolean;
ideMode?: boolean;
loadMemoryFromIncludeDirectories?: boolean;
includeDirectoryTree?: boolean;
importFormat?: 'tree' | 'flat';
discoveryMaxDirs?: number;
compressionThreshold?: number;
@@ -603,6 +604,7 @@ export class Config {
| undefined;
private readonly experimentalZedIntegration: boolean = false;
private readonly loadMemoryFromIncludeDirectories: boolean = false;
private readonly includeDirectoryTree: boolean = true;
private readonly importFormat: 'tree' | 'flat';
private readonly discoveryMaxDirs: number;
private readonly compressionThreshold: number | undefined;
@@ -786,6 +788,7 @@ export class Config {
this.summarizeToolOutput = params.summarizeToolOutput;
this.folderTrust = params.folderTrust ?? false;
this.ideMode = params.ideMode ?? false;
this.includeDirectoryTree = params.includeDirectoryTree ?? true;
this.loadMemoryFromIncludeDirectories =
params.loadMemoryFromIncludeDirectories ?? false;
this.importFormat = params.importFormat ?? 'tree';
@@ -1161,6 +1164,10 @@ export class Config {
return this.loadMemoryFromIncludeDirectories;
}
getIncludeDirectoryTree(): boolean {
return this.includeDirectoryTree;
}
getImportFormat(): 'tree' | 'flat' {
return this.importFormat;
}
+1
View File
@@ -244,6 +244,7 @@ describe('Gemini Client (client.ts)', () => {
getShowModelInfoInChat: vi.fn().mockReturnValue(false),
getContinueOnFailedApiCall: vi.fn(),
getProjectRoot: vi.fn().mockReturnValue('/test/project/root'),
getIncludeDirectoryTree: vi.fn().mockReturnValue(true),
storage: {
getProjectTempDir: vi.fn().mockReturnValue('/test/temp'),
},
@@ -88,6 +88,7 @@ describe('getEnvironmentContext', () => {
getDirectories: vi.fn().mockReturnValue(['/test/dir']),
}),
getFileService: vi.fn(),
getIncludeDirectoryTree: vi.fn().mockReturnValue(true),
getEnvironmentMemory: vi.fn().mockReturnValue('Mock Environment Memory'),
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
@@ -146,6 +147,24 @@ describe('getEnvironmentContext', () => {
expect(getFolderStructure).toHaveBeenCalledTimes(2);
});
it('should omit directory structure when getIncludeDirectoryTree is false', async () => {
(vi.mocked(mockConfig.getIncludeDirectoryTree!) as Mock).mockReturnValue(
false,
);
const parts = await getEnvironmentContext(mockConfig as Config);
expect(parts.length).toBe(1);
const context = parts[0].text;
expect(context).toContain('<session_context>');
expect(context).not.toContain('Directory Structure:');
expect(context).not.toContain('Mock Folder Structure');
expect(context).toContain('Mock Environment Memory');
expect(context).toContain('</session_context>');
expect(getFolderStructure).not.toHaveBeenCalled();
});
it('should handle read_many_files returning no content', async () => {
const mockReadManyFilesTool = {
build: vi.fn().mockReturnValue({
@@ -53,7 +53,9 @@ export async function getEnvironmentContext(config: Config): Promise<Part[]> {
day: 'numeric',
});
const platform = process.platform;
const directoryContext = await getDirectoryContextString(config);
const directoryContext = config.getIncludeDirectoryTree()
? await getDirectoryContextString(config)
: '';
const tempDir = config.storage.getProjectTempDir();
const environmentMemory = config.getEnvironmentMemory();