fix: clean up /clear and /resume (#22007)

This commit is contained in:
Jack Wotherspoon
2026-03-11 16:23:23 +01:00
committed by GitHub
parent 99bbbc2170
commit b804fe9662
9 changed files with 282 additions and 22 deletions

View File

@@ -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) {