mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-23 20:40:41 -07:00
refactor(core): align JIT memory placement with tiered context model (#22766)
This commit is contained in:
@@ -165,16 +165,27 @@ describe('getEnvironmentContext', () => {
|
||||
expect(getFolderStructure).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should exclude environment memory when JIT context is enabled', async () => {
|
||||
it('should use session memory instead of environment memory when JIT context is enabled', async () => {
|
||||
(mockConfig as Record<string, unknown>)['isJitContextEnabled'] = vi
|
||||
.fn()
|
||||
.mockReturnValue(true);
|
||||
(mockConfig as Record<string, unknown>)['getSessionMemory'] = vi
|
||||
.fn()
|
||||
.mockReturnValue(
|
||||
'\n<loaded_context>\n<extension_context>\nExt Memory\n</extension_context>\n<project_context>\nProj Memory\n</project_context>\n</loaded_context>',
|
||||
);
|
||||
|
||||
const parts = await getEnvironmentContext(mockConfig as Config);
|
||||
|
||||
const context = parts[0].text;
|
||||
expect(context).not.toContain('Mock Environment Memory');
|
||||
expect(mockConfig.getEnvironmentMemory).not.toHaveBeenCalled();
|
||||
expect(context).toContain('<loaded_context>');
|
||||
expect(context).toContain('<extension_context>');
|
||||
expect(context).toContain('Ext Memory');
|
||||
expect(context).toContain('<project_context>');
|
||||
expect(context).toContain('Proj Memory');
|
||||
expect(context).toContain('</loaded_context>');
|
||||
});
|
||||
|
||||
it('should include environment memory when JIT context is disabled', async () => {
|
||||
|
||||
@@ -57,11 +57,15 @@ export async function getEnvironmentContext(config: Config): Promise<Part[]> {
|
||||
? await getDirectoryContextString(config)
|
||||
: '';
|
||||
const tempDir = config.storage.getProjectTempDir();
|
||||
// When JIT context is enabled, project memory is already included in the
|
||||
// system instruction via renderUserMemory(). Skip it here to avoid sending
|
||||
// the same GEMINI.md content twice.
|
||||
// Tiered context model (see issue #11488):
|
||||
// - Tier 1 (global): system instruction only
|
||||
// - Tier 2 (extension + project): first user message (here)
|
||||
// - Tier 3 (subdirectory): tool output (JIT)
|
||||
// When JIT is enabled, Tier 2 memory is provided by getSessionMemory().
|
||||
// When JIT is disabled, all memory is in the system instruction and
|
||||
// getEnvironmentMemory() provides the project memory for this message.
|
||||
const environmentMemory = config.isJitContextEnabled?.()
|
||||
? ''
|
||||
? config.getSessionMemory()
|
||||
: config.getEnvironmentMemory();
|
||||
|
||||
const context = `
|
||||
|
||||
Reference in New Issue
Block a user