Pass whole extensions rather than just context files (#10910)

Co-authored-by: Jake Macdonald <jakemac@google.com>
This commit is contained in:
Zack Birkenbuel
2025-10-20 16:15:23 -07:00
committed by GitHub
parent 995ae717cc
commit cc7e1472f9
35 changed files with 487 additions and 1193 deletions
+23 -17
View File
@@ -15,6 +15,7 @@ import {
} from '../tools/memoryTool.js';
import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
import { GEMINI_DIR } from './paths.js';
import type { GeminiCLIExtension } from '../config/config.js';
vi.mock('os', async (importOriginal) => {
const actualOs = await importOriginal<typeof os>();
@@ -87,7 +88,7 @@ describe('loadServerHierarchicalMemory', () => {
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
false, // untrusted
);
@@ -116,7 +117,7 @@ describe('loadServerHierarchicalMemory', () => {
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
false, // untrusted
);
@@ -132,7 +133,7 @@ describe('loadServerHierarchicalMemory', () => {
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -154,7 +155,7 @@ describe('loadServerHierarchicalMemory', () => {
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -181,7 +182,7 @@ default context content
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -212,7 +213,7 @@ custom context content
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -247,7 +248,7 @@ cwd context content
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -279,7 +280,7 @@ Subdir custom memory
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -311,7 +312,7 @@ Src directory memory
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -355,7 +356,7 @@ Subdir memory
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -408,7 +409,7 @@ Subdir memory
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
'tree',
{
@@ -444,7 +445,7 @@ My code memory
[],
true,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
'tree', // importFormat
{
@@ -466,7 +467,7 @@ My code memory
[],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -488,7 +489,12 @@ My code memory
[],
false,
new FileDiscoveryService(projectRoot),
[extensionFilePath],
[
{
contextFiles: [extensionFilePath],
isActive: true,
} as GeminiCLIExtension,
], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -515,7 +521,7 @@ Extension memory content
[includedDir],
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -550,7 +556,7 @@ included directory memory
createdFiles.map((f) => path.dirname(f)),
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
@@ -585,7 +591,7 @@ included directory memory
[childDir, parentDir], // Deliberately include duplicates
false,
new FileDiscoveryService(projectRoot),
[],
[], // extensions
DEFAULT_FOLDER_TRUST,
);
+10 -10
View File
@@ -15,6 +15,7 @@ import { processImports } from './memoryImportProcessor.js';
import type { FileFilteringOptions } from '../config/constants.js';
import { DEFAULT_MEMORY_FILE_FILTERING_OPTIONS } from '../config/constants.js';
import { GEMINI_DIR } from './paths.js';
import type { GeminiCLIExtension } from '../config/config.js';
// Simple console logger, similar to the one previously in CLI's config.ts
// TODO: Integrate with a more robust server-side logger if available/appropriate.
@@ -84,7 +85,6 @@ async function getGeminiMdFilePathsInternal(
userHomePath: string,
debugMode: boolean,
fileService: FileDiscoveryService,
extensionContextFilePaths: string[] = [],
folderTrust: boolean,
fileFilteringOptions: FileFilteringOptions,
maxDirs: number,
@@ -107,7 +107,6 @@ async function getGeminiMdFilePathsInternal(
userHomePath,
debugMode,
fileService,
extensionContextFilePaths,
folderTrust,
fileFilteringOptions,
maxDirs,
@@ -137,7 +136,6 @@ async function getGeminiMdFilePathsInternalForEachDir(
userHomePath: string,
debugMode: boolean,
fileService: FileDiscoveryService,
extensionContextFilePaths: string[] = [],
folderTrust: boolean,
fileFilteringOptions: FileFilteringOptions,
maxDirs: number,
@@ -226,11 +224,6 @@ async function getGeminiMdFilePathsInternalForEachDir(
}
}
// Add extension context file paths.
for (const extensionPath of extensionContextFilePaths) {
allPaths.add(extensionPath);
}
const finalPaths = Array.from(allPaths);
if (debugMode)
@@ -343,7 +336,7 @@ export async function loadServerHierarchicalMemory(
includeDirectoriesToReadGemini: readonly string[],
debugMode: boolean,
fileService: FileDiscoveryService,
extensionContextFilePaths: string[] = [],
extensions: GeminiCLIExtension[],
folderTrust: boolean,
importFormat: 'flat' | 'tree' = 'tree',
fileFilteringOptions?: FileFilteringOptions,
@@ -363,11 +356,18 @@ export async function loadServerHierarchicalMemory(
userHomePath,
debugMode,
fileService,
extensionContextFilePaths,
folderTrust,
fileFilteringOptions || DEFAULT_MEMORY_FILE_FILTERING_OPTIONS,
maxDirs,
);
// Add extension file paths separately since they may be conditionally enabled.
filePaths.push(
...extensions
.filter((ext) => ext.isActive)
.flatMap((ext) => ext.contextFiles),
);
if (filePaths.length === 0) {
if (debugMode)
logger.debug('No GEMINI.md files found in hierarchy of the workspace.');