mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 14:10:37 -07:00
Fix: Update system instruction when GEMINI.md memory is loaded or refreshed (#12136)
This commit is contained in:
@@ -182,6 +182,9 @@ describe('memoryCommand', () => {
|
||||
include: [],
|
||||
}),
|
||||
isTrustedFolder: () => false,
|
||||
updateSystemInstructionIfInitialized: vi
|
||||
.fn()
|
||||
.mockResolvedValue(undefined),
|
||||
};
|
||||
|
||||
mockContext = createMockCommandContext({
|
||||
|
||||
@@ -86,6 +86,8 @@ export const memoryCommand: SlashCommand = {
|
||||
const { memoryContent, fileCount } =
|
||||
await refreshServerHierarchicalMemory(config);
|
||||
|
||||
await config.updateSystemInstructionIfInitialized();
|
||||
|
||||
const successMessage =
|
||||
memoryContent.length > 0
|
||||
? `Memory refreshed successfully. Loaded ${memoryContent.length} characters from ${fileCount} file(s).`
|
||||
|
||||
@@ -1020,6 +1020,17 @@ export class Config {
|
||||
return this.geminiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the system instruction with the latest user memory.
|
||||
* Whenever the user memory (GEMINI.md files) is updated.
|
||||
*/
|
||||
async updateSystemInstructionIfInitialized(): Promise<void> {
|
||||
const geminiClient = this.getGeminiClient();
|
||||
if (geminiClient?.isInitialized()) {
|
||||
await geminiClient.updateSystemInstruction();
|
||||
}
|
||||
}
|
||||
|
||||
getModelRouterService(): ModelRouterService {
|
||||
return this.modelRouterService;
|
||||
}
|
||||
|
||||
@@ -168,6 +168,16 @@ export class GeminiClient {
|
||||
});
|
||||
}
|
||||
|
||||
async updateSystemInstruction(): Promise<void> {
|
||||
if (!this.isInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const userMemory = this.config.getUserMemory();
|
||||
const systemInstruction = getCoreSystemPrompt(this.config, userMemory);
|
||||
this.getChat().setSystemInstruction(systemInstruction);
|
||||
}
|
||||
|
||||
async startChat(
|
||||
extraHistory?: Content[],
|
||||
resumedSessionData?: ResumedSessionData,
|
||||
|
||||
Reference in New Issue
Block a user