mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 03:24:42 -07:00
fix: clean up /clear and /resume (#22007)
This commit is contained in:
@@ -17,6 +17,7 @@ vi.mock('@google/gemini-cli-core', async () => {
|
||||
...actual,
|
||||
uiTelemetryService: {
|
||||
setLastPromptTokenCount: vi.fn(),
|
||||
clear: vi.fn(),
|
||||
},
|
||||
};
|
||||
});
|
||||
@@ -74,17 +75,16 @@ describe('clearCommand', () => {
|
||||
|
||||
expect(mockResetChat).toHaveBeenCalledTimes(1);
|
||||
expect(mockHintClear).toHaveBeenCalledTimes(1);
|
||||
expect(uiTelemetryService.setLastPromptTokenCount).toHaveBeenCalledWith(0);
|
||||
expect(uiTelemetryService.setLastPromptTokenCount).toHaveBeenCalledTimes(1);
|
||||
expect(uiTelemetryService.clear).toHaveBeenCalled();
|
||||
expect(uiTelemetryService.clear).toHaveBeenCalledTimes(1);
|
||||
expect(mockContext.ui.clear).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Check the order of operations.
|
||||
const setDebugMessageOrder = (mockContext.ui.setDebugMessage as Mock).mock
|
||||
.invocationCallOrder[0];
|
||||
const resetChatOrder = mockResetChat.mock.invocationCallOrder[0];
|
||||
const resetTelemetryOrder = (
|
||||
uiTelemetryService.setLastPromptTokenCount as Mock
|
||||
).mock.invocationCallOrder[0];
|
||||
const resetTelemetryOrder = (uiTelemetryService.clear as Mock).mock
|
||||
.invocationCallOrder[0];
|
||||
const clearOrder = (mockContext.ui.clear as Mock).mock
|
||||
.invocationCallOrder[0];
|
||||
|
||||
@@ -110,8 +110,8 @@ describe('clearCommand', () => {
|
||||
'Clearing terminal.',
|
||||
);
|
||||
expect(mockResetChat).not.toHaveBeenCalled();
|
||||
expect(uiTelemetryService.setLastPromptTokenCount).toHaveBeenCalledWith(0);
|
||||
expect(uiTelemetryService.setLastPromptTokenCount).toHaveBeenCalledTimes(1);
|
||||
expect(uiTelemetryService.clear).toHaveBeenCalled();
|
||||
expect(uiTelemetryService.clear).toHaveBeenCalledTimes(1);
|
||||
expect(nullConfigContext.ui.clear).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,10 +23,6 @@ export const clearCommand: SlashCommand = {
|
||||
action: async (context, _args) => {
|
||||
const geminiClient = context.services.config?.getGeminiClient();
|
||||
const config = context.services.config;
|
||||
const chatRecordingService = context.services.config
|
||||
?.getGeminiClient()
|
||||
?.getChat()
|
||||
.getChatRecordingService();
|
||||
|
||||
// Fire SessionEnd hook before clearing
|
||||
const hookSystem = config?.getHookSystem();
|
||||
@@ -34,6 +30,18 @@ export const clearCommand: SlashCommand = {
|
||||
await hookSystem.fireSessionEndEvent(SessionEndReason.Clear);
|
||||
}
|
||||
|
||||
// Reset user steering hints
|
||||
config?.userHintService.clear();
|
||||
|
||||
// Start a new conversation recording with a new session ID
|
||||
// We MUST do this before calling resetChat() so the new ChatRecordingService
|
||||
// initialized by GeminiChat picks up the new session ID.
|
||||
let newSessionId: string | undefined;
|
||||
if (config) {
|
||||
newSessionId = randomUUID();
|
||||
config.setSessionId(newSessionId);
|
||||
}
|
||||
|
||||
if (geminiClient) {
|
||||
context.ui.setDebugMessage('Clearing terminal and resetting chat.');
|
||||
// If resetChat fails, the exception will propagate and halt the command,
|
||||
@@ -43,16 +51,6 @@ export const clearCommand: SlashCommand = {
|
||||
context.ui.setDebugMessage('Clearing terminal.');
|
||||
}
|
||||
|
||||
// Reset user steering hints
|
||||
config?.userHintService.clear();
|
||||
|
||||
// Start a new conversation recording with a new session ID
|
||||
if (config && chatRecordingService) {
|
||||
const newSessionId = randomUUID();
|
||||
config.setSessionId(newSessionId);
|
||||
chatRecordingService.initialize();
|
||||
}
|
||||
|
||||
// Fire SessionStart hook after clearing
|
||||
let result;
|
||||
if (hookSystem) {
|
||||
@@ -69,7 +67,7 @@ export const clearCommand: SlashCommand = {
|
||||
await flushTelemetry(config);
|
||||
}
|
||||
|
||||
uiTelemetryService.setLastPromptTokenCount(0);
|
||||
uiTelemetryService.clear(newSessionId);
|
||||
context.ui.clear();
|
||||
|
||||
if (result?.systemMessage) {
|
||||
|
||||
Reference in New Issue
Block a user