mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-18 01:51:20 -07:00
feat(plan): refresh system prompt when approval mode changes (Shift+Tab) (#17585)
This commit is contained in:
@@ -59,7 +59,7 @@ export async function refreshMemory(
|
||||
fileCount = result.fileCount;
|
||||
}
|
||||
|
||||
await config.updateSystemInstructionIfInitialized();
|
||||
config.updateSystemInstructionIfInitialized();
|
||||
let content: string;
|
||||
|
||||
if (memoryContent.length > 0) {
|
||||
|
||||
@@ -1269,6 +1269,39 @@ describe('setApprovalMode with folder trust', () => {
|
||||
expect(() => config.setApprovalMode(ApprovalMode.DEFAULT)).not.toThrow();
|
||||
});
|
||||
|
||||
it('should update system instruction when entering Plan mode', () => {
|
||||
const config = new Config(baseParams);
|
||||
vi.spyOn(config, 'isTrustedFolder').mockReturnValue(true);
|
||||
const updateSpy = vi.spyOn(config, 'updateSystemInstructionIfInitialized');
|
||||
|
||||
config.setApprovalMode(ApprovalMode.PLAN);
|
||||
|
||||
expect(updateSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should update system instruction when leaving Plan mode', () => {
|
||||
const config = new Config({
|
||||
...baseParams,
|
||||
approvalMode: ApprovalMode.PLAN,
|
||||
});
|
||||
vi.spyOn(config, 'isTrustedFolder').mockReturnValue(true);
|
||||
const updateSpy = vi.spyOn(config, 'updateSystemInstructionIfInitialized');
|
||||
|
||||
config.setApprovalMode(ApprovalMode.DEFAULT);
|
||||
|
||||
expect(updateSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not update system instruction when switching between non-Plan modes', () => {
|
||||
const config = new Config(baseParams);
|
||||
vi.spyOn(config, 'isTrustedFolder').mockReturnValue(true);
|
||||
const updateSpy = vi.spyOn(config, 'updateSystemInstructionIfInitialized');
|
||||
|
||||
config.setApprovalMode(ApprovalMode.AUTO_EDIT);
|
||||
|
||||
expect(updateSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe('registerCoreTools', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
@@ -1341,7 +1341,7 @@ export class Config {
|
||||
}
|
||||
if (this.geminiClient?.isInitialized()) {
|
||||
await this.geminiClient.setTools();
|
||||
await this.geminiClient.updateSystemInstruction();
|
||||
this.geminiClient.updateSystemInstruction();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1409,6 +1409,13 @@ export class Config {
|
||||
}
|
||||
|
||||
this.policyEngine.setApprovalMode(mode);
|
||||
|
||||
const isPlanModeTransition =
|
||||
currentMode !== mode &&
|
||||
(currentMode === ApprovalMode.PLAN || mode === ApprovalMode.PLAN);
|
||||
if (isPlanModeTransition) {
|
||||
this.updateSystemInstructionIfInitialized();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1491,10 +1498,10 @@ export class Config {
|
||||
* Updates the system instruction with the latest user memory.
|
||||
* Whenever the user memory (GEMINI.md files) is updated.
|
||||
*/
|
||||
async updateSystemInstructionIfInitialized(): Promise<void> {
|
||||
updateSystemInstructionIfInitialized(): void {
|
||||
const geminiClient = this.getGeminiClient();
|
||||
if (geminiClient?.isInitialized()) {
|
||||
await geminiClient.updateSystemInstruction();
|
||||
geminiClient.updateSystemInstruction();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1803,7 +1810,7 @@ export class Config {
|
||||
}
|
||||
|
||||
// Notify the client that system instructions might need updating
|
||||
await this.updateSystemInstructionIfInitialized();
|
||||
this.updateSystemInstructionIfInitialized();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2142,7 +2149,7 @@ export class Config {
|
||||
const client = this.getGeminiClient();
|
||||
if (client?.isInitialized()) {
|
||||
await client.setTools();
|
||||
await client.updateSystemInstruction();
|
||||
client.updateSystemInstruction();
|
||||
} else {
|
||||
debugLogger.debug(
|
||||
'[Config] GeminiClient not initialized; skipping live prompt/tool refresh.',
|
||||
|
||||
@@ -1842,7 +1842,7 @@ ${JSON.stringify(
|
||||
const { getCoreSystemPrompt } = await import('./prompts.js');
|
||||
const mockGetCoreSystemPrompt = vi.mocked(getCoreSystemPrompt);
|
||||
|
||||
await client.updateSystemInstruction();
|
||||
client.updateSystemInstruction();
|
||||
|
||||
expect(mockGetCoreSystemPrompt).toHaveBeenCalledWith(
|
||||
mockConfig,
|
||||
@@ -1857,7 +1857,7 @@ ${JSON.stringify(
|
||||
const { getCoreSystemPrompt } = await import('./prompts.js');
|
||||
const mockGetCoreSystemPrompt = vi.mocked(getCoreSystemPrompt);
|
||||
|
||||
await client.updateSystemInstruction();
|
||||
client.updateSystemInstruction();
|
||||
|
||||
expect(mockGetCoreSystemPrompt).toHaveBeenCalledWith(
|
||||
mockConfig,
|
||||
|
||||
@@ -300,7 +300,7 @@ export class GeminiClient {
|
||||
});
|
||||
}
|
||||
|
||||
async updateSystemInstruction(): Promise<void> {
|
||||
updateSystemInstruction(): void {
|
||||
if (!this.isInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user