| |
| |
| |
| |
| |
|
|
| import { |
| uiTelemetryService, |
| SessionEndReason, |
| SessionStartSource, |
| flushTelemetry, |
| resetBrowserSession, |
| } from '@google/gemini-cli-core'; |
| import { CommandKind, type SlashCommand } from './types.js'; |
| import { MessageType } from '../types.js'; |
| import { randomUUID } from 'node:crypto'; |
|
|
| export const clearCommand: SlashCommand = { |
| name: 'clear', |
| altNames: ['new'], |
| description: 'Clear the screen and start a new session', |
| kind: CommandKind.BUILT_IN, |
| autoExecute: true, |
| action: async (context, _args) => { |
| const geminiClient = context.services.agentContext?.geminiClient; |
| const config = context.services.agentContext?.config; |
|
|
| |
| const hookSystem = config?.getHookSystem(); |
| if (hookSystem) { |
| await hookSystem.fireSessionEndEvent(SessionEndReason.Clear); |
| } |
|
|
| |
| config?.injectionService.clear(); |
|
|
| |
| |
| |
| let newSessionId: string | undefined; |
| if (config) { |
| newSessionId = randomUUID(); |
| config.resetNewSessionState(newSessionId); |
| } |
|
|
| if (geminiClient) { |
| context.ui.setDebugMessage('Clearing terminal and resetting chat.'); |
|
|
| |
| await resetBrowserSession(); |
|
|
| |
| |
| await geminiClient.resetChat(); |
| } else { |
| context.ui.setDebugMessage('Clearing terminal.'); |
| } |
|
|
| |
| let result; |
| if (hookSystem) { |
| result = await hookSystem.fireSessionStartEvent(SessionStartSource.Clear); |
| } |
|
|
| |
| |
| await new Promise((resolve) => setImmediate(resolve)); |
|
|
| |
| |
| if (config) { |
| await flushTelemetry(config); |
| } |
|
|
| uiTelemetryService.clear(newSessionId); |
| context.ui.clear(); |
|
|
| if (result?.systemMessage) { |
| context.ui.addItem( |
| { |
| type: MessageType.INFO, |
| text: result.systemMessage, |
| }, |
| Date.now(), |
| ); |
| } |
| }, |
| }; |
|
|