feat(core): Implement JIT context memory loading and UI sync (#14469)

This commit is contained in:
Sandy Tao
2025-12-19 07:04:03 -10:00
committed by GitHub
parent 3c92bdb1ad
commit 2e229d3bb6
14 changed files with 292 additions and 91 deletions

View File

@@ -92,6 +92,7 @@ describe('getEnvironmentContext', () => {
getDirectories: vi.fn().mockReturnValue(['/test/dir']),
}),
getFileService: vi.fn(),
getEnvironmentMemory: vi.fn().mockReturnValue('Mock Environment Memory'),
getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry),
storage: {
@@ -122,6 +123,7 @@ describe('getEnvironmentContext', () => {
expect(context).toContain(
'Here is the folder structure of the current working directories:\n\nMock Folder Structure',
);
expect(context).toContain('Mock Environment Memory');
expect(getFolderStructure).toHaveBeenCalledWith('/test/dir', {
fileService: undefined,
});

View File

@@ -62,6 +62,7 @@ export async function getEnvironmentContext(config: Config): Promise<Part[]> {
const platform = process.platform;
const directoryContext = await getDirectoryContextString(config);
const tempDir = config.storage.getProjectTempDir();
const environmentMemory = config.getEnvironmentMemory();
const context = `
This is the Gemini CLI. We are setting up the context for our chat.
@@ -69,6 +70,8 @@ Today's date is ${today} (formatted according to the user's locale).
My operating system is: ${platform}
The project's temporary directory is: ${tempDir}
${directoryContext}
${environmentMemory}
`.trim();
const initialParts: Part[] = [{ text: context }];

View File

@@ -5,7 +5,6 @@
*/
import { EventEmitter } from 'node:events';
import type { LoadServerHierarchicalMemoryResponse } from './memoryDiscovery.js';
/**
* Defines the severity level for user-facing feedback.
@@ -64,7 +63,9 @@ export interface OutputPayload {
/**
* Payload for the 'memory-changed' event.
*/
export type MemoryChangedPayload = LoadServerHierarchicalMemoryResponse;
export interface MemoryChangedPayload {
fileCount: number;
}
export enum CoreEvent {
UserFeedback = 'user-feedback',

View File

@@ -932,7 +932,9 @@ included directory memory
path.join(extensionPath, 'CustomContext.md'),
);
expect(config.getGeminiMdFilePaths()).equals(refreshResult.filePaths);
expect(mockEventListener).toHaveBeenCalledExactlyOnceWith(refreshResult);
expect(mockEventListener).toHaveBeenCalledExactlyOnceWith({
fileCount: refreshResult.fileCount,
});
});
it('should include MCP instructions in user memory', async () => {

View File

@@ -577,7 +577,7 @@ export async function refreshServerHierarchicalMemory(config: Config) {
config.setUserMemory(finalMemory);
config.setGeminiMdFileCount(result.fileCount);
config.setGeminiMdFilePaths(result.filePaths);
coreEvents.emit(CoreEvent.MemoryChanged, result);
coreEvents.emit(CoreEvent.MemoryChanged, { fileCount: result.fileCount });
return result;
}