feat: add /clear command to clear chat history

This commit is contained in:
Nate 2025-07-13 23:41:08 -07:00
parent 44de852486
commit c9c000cfab
4 changed files with 25 additions and 2 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "@continuedev/cli", "name": "@continuedev/cli",
"version": "1.0.1", "version": "1.1.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@continuedev/cli", "name": "@continuedev/cli",
"version": "1.0.1", "version": "1.1.0",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@continuedev/openai-adapters": "^1.0.18", "@continuedev/openai-adapters": "^1.0.18",

View file

@ -14,6 +14,7 @@ export function handleSlashCommands(
output?: string; output?: string;
exit?: boolean; exit?: boolean;
newInput?: string; newInput?: string;
clear?: boolean;
} | null { } | null {
if (input.startsWith("/")) { if (input.startsWith("/")) {
const [command, ...args] = input.slice(1).split(" "); const [command, ...args] = input.slice(1).split(" ");
@ -22,6 +23,7 @@ export function handleSlashCommands(
const helpMessage = [ const helpMessage = [
"Available commands:", "Available commands:",
"/help - Show this help message", "/help - Show this help message",
"/clear - Clear the chat history",
"/exit - Exit the chat", "/exit - Exit the chat",
"/login - Authenticate with your account", "/login - Authenticate with your account",
"/logout - Sign out of your current session", "/logout - Sign out of your current session",
@ -39,6 +41,8 @@ export function handleSlashCommands(
"None" "None"
}`, }`,
}; };
case "clear":
return { clear: true, output: "Chat history cleared." };
case "exit": case "exit":
return { exit: true, output: "Goodbye!" }; return { exit: true, output: "Goodbye!" };
case "login": case "login":

View file

@ -25,6 +25,7 @@ const SlashCommandUI: React.FC<SlashCommandUIProps> = ({
const getSlashCommands = (): SlashCommand[] => { const getSlashCommands = (): SlashCommand[] => {
const systemCommands: SlashCommand[] = [ const systemCommands: SlashCommand[] = [
{ name: "help", description: "Show help message", category: "system" }, { name: "help", description: "Show help message", category: "system" },
{ name: "clear", description: "Clear the chat history", category: "system" },
{ name: "exit", description: "Exit the chat", category: "system" }, { name: "exit", description: "Exit the chat", category: "system" },
{ {
name: "login", name: "login",

View file

@ -65,6 +65,24 @@ const TUIChat: React.FC<TUIChatProps> = ({
return; return;
} }
if (commandResult.clear) {
// Clear chat history but keep system message
const systemMessage = chatHistory.find(msg => msg.role === "system");
const newHistory = systemMessage ? [systemMessage] : [];
setChatHistory(newHistory);
setMessages([]);
// Add command output to messages
if (commandResult.output) {
setMessages([{
role: "system",
content: commandResult.output!,
messageType: "system",
}]);
}
return;
}
// Add command output to messages // Add command output to messages
if (commandResult.output) { if (commandResult.output) {
setMessages((prev) => [ setMessages((prev) => [