From 4160d904da8328eb7168b5b652d4c0f17682546c Mon Sep 17 00:00:00 2001 From: matt korwel Date: Wed, 11 Jun 2025 13:34:35 -0700 Subject: Extensibility: Gemini.md files (#944) --- packages/core/src/utils/memoryDiscovery.test.ts | 28 +++++++++++++++++++++++++ packages/core/src/utils/memoryDiscovery.ts | 10 +++++++++ 2 files changed, 38 insertions(+) (limited to 'packages/core/src') diff --git a/packages/core/src/utils/memoryDiscovery.test.ts b/packages/core/src/utils/memoryDiscovery.test.ts index 5329a15b..9c78f625 100644 --- a/packages/core/src/utils/memoryDiscovery.test.ts +++ b/packages/core/src/utils/memoryDiscovery.test.ts @@ -564,4 +564,32 @@ describe('loadServerHierarchicalMemory', () => { ); consoleDebugSpy.mockRestore(); }); + + it('should load extension context file paths', async () => { + const extensionFilePath = '/test/extensions/ext1/gemini.md'; + mockFs.access.mockImplementation(async (p) => { + if (p === extensionFilePath) { + return undefined; + } + throw new Error('File not found'); + }); + mockFs.readFile.mockImplementation(async (p) => { + if (p === extensionFilePath) { + return 'Extension memory content'; + } + throw new Error('File not found'); + }); + + const { memoryContent, fileCount } = await loadServerHierarchicalMemory( + CWD, + false, + [extensionFilePath], + ); + + expect(memoryContent).toBe( + `--- Context from: ${path.relative(CWD, extensionFilePath)} ---\nExtension memory content\n--- End of Context from: ${path.relative(CWD, extensionFilePath)} ---`, + ); + expect(fileCount).toBe(1); + expect(mockFs.readFile).toHaveBeenCalledWith(extensionFilePath, 'utf-8'); + }); }); diff --git a/packages/core/src/utils/memoryDiscovery.ts b/packages/core/src/utils/memoryDiscovery.ts index 6e822145..07649415 100644 --- a/packages/core/src/utils/memoryDiscovery.ts +++ b/packages/core/src/utils/memoryDiscovery.ts @@ -81,6 +81,7 @@ async function getGeminiMdFilePathsInternal( currentWorkingDirectory: string, userHomePath: string, debugMode: boolean, + extensionContextFilePaths: string[] = [], ): Promise { const resolvedCwd = path.resolve(currentWorkingDirectory); const resolvedHome = path.resolve(userHomePath); @@ -195,6 +196,13 @@ async function getGeminiMdFilePathsInternal( } } + // Add extension context file paths + for (const extensionPath of extensionContextFilePaths) { + if (!paths.includes(extensionPath)) { + paths.push(extensionPath); + } + } + if (debugMode) logger.debug( `Final ordered ${getCurrentGeminiMdFilename()} paths to read: ${JSON.stringify(paths)}`, @@ -258,6 +266,7 @@ function concatenateInstructions( export async function loadServerHierarchicalMemory( currentWorkingDirectory: string, debugMode: boolean, + extensionContextFilePaths: string[] = [], ): Promise<{ memoryContent: string; fileCount: number }> { if (debugMode) logger.debug( @@ -270,6 +279,7 @@ export async function loadServerHierarchicalMemory( currentWorkingDirectory, userHomePath, debugMode, + extensionContextFilePaths, ); if (filePaths.length === 0) { if (debugMode) logger.debug('No GEMINI.md files found in hierarchy.'); -- cgit v1.2.3