2025-07-07 16:45:44 -04:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-07-17 07:14:35 -07:00
|
|
|
import { uiTelemetryService } from '@google/gemini-cli-core';
|
2025-08-26 00:04:53 +02:00
|
|
|
import type { SlashCommand } from './types.js';
|
|
|
|
|
import { CommandKind } from './types.js';
|
2025-07-07 16:45:44 -04:00
|
|
|
|
|
|
|
|
export const clearCommand: SlashCommand = {
|
|
|
|
|
name: 'clear',
|
|
|
|
|
description: 'clear the screen and conversation history',
|
2025-07-20 16:57:34 -04:00
|
|
|
kind: CommandKind.BUILT_IN,
|
2025-07-07 16:45:44 -04:00
|
|
|
action: async (context, _args) => {
|
2025-07-17 07:14:35 -07:00
|
|
|
const geminiClient = context.services.config?.getGeminiClient();
|
|
|
|
|
|
|
|
|
|
if (geminiClient) {
|
|
|
|
|
context.ui.setDebugMessage('Clearing terminal and resetting chat.');
|
|
|
|
|
// If resetChat fails, the exception will propagate and halt the command,
|
|
|
|
|
// which is the correct behavior to signal a failure to the user.
|
|
|
|
|
await geminiClient.resetChat();
|
|
|
|
|
} else {
|
|
|
|
|
context.ui.setDebugMessage('Clearing terminal.');
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-18 11:46:56 -07:00
|
|
|
uiTelemetryService.setLastPromptTokenCount(0);
|
2025-07-07 16:45:44 -04:00
|
|
|
context.ui.clear();
|
|
|
|
|
},
|
|
|
|
|
};
|