mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
feat(config): add setting to make directory tree context configurable (#19053)
This commit is contained in:
@@ -633,6 +633,11 @@ their corresponding top-level category object in your `settings.json` file.
|
|||||||
- **Description:** The format to use when importing memory.
|
- **Description:** The format to use when importing memory.
|
||||||
- **Default:** `undefined`
|
- **Default:** `undefined`
|
||||||
|
|
||||||
|
- **`context.includeDirectoryTree`** (boolean):
|
||||||
|
- **Description:** Whether to include the directory tree of the current
|
||||||
|
working directory in the initial request to the model.
|
||||||
|
- **Default:** `true`
|
||||||
|
|
||||||
- **`context.discoveryMaxDirs`** (number):
|
- **`context.discoveryMaxDirs`** (number):
|
||||||
- **Description:** Maximum number of directories to search for memory.
|
- **Description:** Maximum number of directories to search for memory.
|
||||||
- **Default:** `200`
|
- **Default:** `200`
|
||||||
|
|||||||
@@ -454,6 +454,7 @@ export async function loadCliConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const memoryImportFormat = settings.context?.importFormat || 'tree';
|
const memoryImportFormat = settings.context?.importFormat || 'tree';
|
||||||
|
const includeDirectoryTree = settings.context?.includeDirectoryTree ?? true;
|
||||||
|
|
||||||
const ideMode = settings.ide?.enabled ?? false;
|
const ideMode = settings.ide?.enabled ?? false;
|
||||||
|
|
||||||
@@ -745,6 +746,7 @@ export async function loadCliConfig(
|
|||||||
embeddingModel: DEFAULT_GEMINI_EMBEDDING_MODEL,
|
embeddingModel: DEFAULT_GEMINI_EMBEDDING_MODEL,
|
||||||
sandbox: sandboxConfig,
|
sandbox: sandboxConfig,
|
||||||
targetDir: cwd,
|
targetDir: cwd,
|
||||||
|
includeDirectoryTree,
|
||||||
includeDirectories,
|
includeDirectories,
|
||||||
loadMemoryFromIncludeDirectories:
|
loadMemoryFromIncludeDirectories:
|
||||||
settings.context?.loadMemoryFromIncludeDirectories || false,
|
settings.context?.loadMemoryFromIncludeDirectories || false,
|
||||||
|
|||||||
@@ -949,6 +949,16 @@ const SETTINGS_SCHEMA = {
|
|||||||
description: 'The format to use when importing memory.',
|
description: 'The format to use when importing memory.',
|
||||||
showInDialog: false,
|
showInDialog: false,
|
||||||
},
|
},
|
||||||
|
includeDirectoryTree: {
|
||||||
|
type: 'boolean',
|
||||||
|
label: 'Include Directory Tree',
|
||||||
|
category: 'Context',
|
||||||
|
requiresRestart: false,
|
||||||
|
default: true,
|
||||||
|
description:
|
||||||
|
'Whether to include the directory tree of the current working directory in the initial request to the model.',
|
||||||
|
showInDialog: false,
|
||||||
|
},
|
||||||
discoveryMaxDirs: {
|
discoveryMaxDirs: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
label: 'Memory Discovery Max Dirs',
|
label: 'Memory Discovery Max Dirs',
|
||||||
|
|||||||
@@ -436,6 +436,7 @@ export interface ConfigParameters {
|
|||||||
folderTrust?: boolean;
|
folderTrust?: boolean;
|
||||||
ideMode?: boolean;
|
ideMode?: boolean;
|
||||||
loadMemoryFromIncludeDirectories?: boolean;
|
loadMemoryFromIncludeDirectories?: boolean;
|
||||||
|
includeDirectoryTree?: boolean;
|
||||||
importFormat?: 'tree' | 'flat';
|
importFormat?: 'tree' | 'flat';
|
||||||
discoveryMaxDirs?: number;
|
discoveryMaxDirs?: number;
|
||||||
compressionThreshold?: number;
|
compressionThreshold?: number;
|
||||||
@@ -603,6 +604,7 @@ export class Config {
|
|||||||
| undefined;
|
| undefined;
|
||||||
private readonly experimentalZedIntegration: boolean = false;
|
private readonly experimentalZedIntegration: boolean = false;
|
||||||
private readonly loadMemoryFromIncludeDirectories: boolean = false;
|
private readonly loadMemoryFromIncludeDirectories: boolean = false;
|
||||||
|
private readonly includeDirectoryTree: boolean = true;
|
||||||
private readonly importFormat: 'tree' | 'flat';
|
private readonly importFormat: 'tree' | 'flat';
|
||||||
private readonly discoveryMaxDirs: number;
|
private readonly discoveryMaxDirs: number;
|
||||||
private readonly compressionThreshold: number | undefined;
|
private readonly compressionThreshold: number | undefined;
|
||||||
@@ -786,6 +788,7 @@ export class Config {
|
|||||||
this.summarizeToolOutput = params.summarizeToolOutput;
|
this.summarizeToolOutput = params.summarizeToolOutput;
|
||||||
this.folderTrust = params.folderTrust ?? false;
|
this.folderTrust = params.folderTrust ?? false;
|
||||||
this.ideMode = params.ideMode ?? false;
|
this.ideMode = params.ideMode ?? false;
|
||||||
|
this.includeDirectoryTree = params.includeDirectoryTree ?? true;
|
||||||
this.loadMemoryFromIncludeDirectories =
|
this.loadMemoryFromIncludeDirectories =
|
||||||
params.loadMemoryFromIncludeDirectories ?? false;
|
params.loadMemoryFromIncludeDirectories ?? false;
|
||||||
this.importFormat = params.importFormat ?? 'tree';
|
this.importFormat = params.importFormat ?? 'tree';
|
||||||
@@ -1161,6 +1164,10 @@ export class Config {
|
|||||||
return this.loadMemoryFromIncludeDirectories;
|
return this.loadMemoryFromIncludeDirectories;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getIncludeDirectoryTree(): boolean {
|
||||||
|
return this.includeDirectoryTree;
|
||||||
|
}
|
||||||
|
|
||||||
getImportFormat(): 'tree' | 'flat' {
|
getImportFormat(): 'tree' | 'flat' {
|
||||||
return this.importFormat;
|
return this.importFormat;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -244,6 +244,7 @@ describe('Gemini Client (client.ts)', () => {
|
|||||||
getShowModelInfoInChat: vi.fn().mockReturnValue(false),
|
getShowModelInfoInChat: vi.fn().mockReturnValue(false),
|
||||||
getContinueOnFailedApiCall: vi.fn(),
|
getContinueOnFailedApiCall: vi.fn(),
|
||||||
getProjectRoot: vi.fn().mockReturnValue('/test/project/root'),
|
getProjectRoot: vi.fn().mockReturnValue('/test/project/root'),
|
||||||
|
getIncludeDirectoryTree: vi.fn().mockReturnValue(true),
|
||||||
storage: {
|
storage: {
|
||||||
getProjectTempDir: vi.fn().mockReturnValue('/test/temp'),
|
getProjectTempDir: vi.fn().mockReturnValue('/test/temp'),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ describe('getEnvironmentContext', () => {
|
|||||||
getDirectories: vi.fn().mockReturnValue(['/test/dir']),
|
getDirectories: vi.fn().mockReturnValue(['/test/dir']),
|
||||||
}),
|
}),
|
||||||
getFileService: vi.fn(),
|
getFileService: vi.fn(),
|
||||||
|
getIncludeDirectoryTree: vi.fn().mockReturnValue(true),
|
||||||
getEnvironmentMemory: vi.fn().mockReturnValue('Mock Environment Memory'),
|
getEnvironmentMemory: vi.fn().mockReturnValue('Mock Environment Memory'),
|
||||||
|
|
||||||
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
|
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
|
||||||
@@ -146,6 +147,24 @@ describe('getEnvironmentContext', () => {
|
|||||||
expect(getFolderStructure).toHaveBeenCalledTimes(2);
|
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 () => {
|
it('should handle read_many_files returning no content', async () => {
|
||||||
const mockReadManyFilesTool = {
|
const mockReadManyFilesTool = {
|
||||||
build: vi.fn().mockReturnValue({
|
build: vi.fn().mockReturnValue({
|
||||||
|
|||||||
@@ -53,7 +53,9 @@ export async function getEnvironmentContext(config: Config): Promise<Part[]> {
|
|||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
});
|
});
|
||||||
const platform = process.platform;
|
const platform = process.platform;
|
||||||
const directoryContext = await getDirectoryContextString(config);
|
const directoryContext = config.getIncludeDirectoryTree()
|
||||||
|
? await getDirectoryContextString(config)
|
||||||
|
: '';
|
||||||
const tempDir = config.storage.getProjectTempDir();
|
const tempDir = config.storage.getProjectTempDir();
|
||||||
const environmentMemory = config.getEnvironmentMemory();
|
const environmentMemory = config.getEnvironmentMemory();
|
||||||
|
|
||||||
|
|||||||
@@ -1052,6 +1052,13 @@
|
|||||||
"markdownDescription": "The format to use when importing memory.\n\n- Category: `Context`\n- Requires restart: `no`",
|
"markdownDescription": "The format to use when importing memory.\n\n- Category: `Context`\n- Requires restart: `no`",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"includeDirectoryTree": {
|
||||||
|
"title": "Include Directory Tree",
|
||||||
|
"description": "Whether to include the directory tree of the current working directory in the initial request to the model.",
|
||||||
|
"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`",
|
||||||
|
"default": true,
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"discoveryMaxDirs": {
|
"discoveryMaxDirs": {
|
||||||
"title": "Memory Discovery Max Dirs",
|
"title": "Memory Discovery Max Dirs",
|
||||||
"description": "Maximum number of directories to search for memory.",
|
"description": "Maximum number of directories to search for memory.",
|
||||||
|
|||||||
Reference in New Issue
Block a user