From e178f6ba8229be0aad1e7a0dedb473f68238428e Mon Sep 17 00:00:00 2001 From: Jay4242 <96741732+Jay4242@users.noreply.github.com> Date: Mon, 16 Jun 2025 14:34:19 -0700 Subject: [PATCH] Add /clear command to clear goose context (#1802) Co-authored-by: Bradley Axen --- crates/goose-cli/src/session/input.rs | 4 ++++ crates/goose-cli/src/session/mod.rs | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/crates/goose-cli/src/session/input.rs b/crates/goose-cli/src/session/input.rs index c4049674..62c83465 100644 --- a/crates/goose-cli/src/session/input.rs +++ b/crates/goose-cli/src/session/input.rs @@ -17,6 +17,7 @@ pub enum InputResult { GooseMode(String), Plan(PlanCommandOptions), EndPlan, + Clear, Recipe(Option), Summarize, } @@ -91,6 +92,7 @@ fn handle_slash_command(input: &str) -> Option { const CMD_MODE: &str = "/mode "; const CMD_PLAN: &str = "/plan"; const CMD_ENDPLAN: &str = "/endplan"; + const CMD_CLEAR: &str = "/clear"; const CMD_RECIPE: &str = "/recipe"; const CMD_SUMMARIZE: &str = "/summarize"; @@ -134,6 +136,7 @@ fn handle_slash_command(input: &str) -> Option { } s if s.starts_with(CMD_PLAN) => parse_plan_command(s[CMD_PLAN.len()..].trim().to_string()), s if s == CMD_ENDPLAN => Some(InputResult::EndPlan), + s if s == CMD_CLEAR => Some(InputResult::Clear), s if s.starts_with(CMD_RECIPE) => parse_recipe_command(s), s if s == CMD_SUMMARIZE => Some(InputResult::Summarize), _ => None, @@ -246,6 +249,7 @@ fn print_help() { If no filepath is provided, it will be saved to ./recipe.yaml. /summarize - Summarize the current conversation to reduce context length while preserving key information. /? or /help - Display this help message +/clear - Clears the current chat history Navigation: Ctrl+C - Interrupt goose (resets the interaction to before the interrupted user request) diff --git a/crates/goose-cli/src/session/mod.rs b/crates/goose-cli/src/session/mod.rs index 8eeec0ea..3cadb951 100644 --- a/crates/goose-cli/src/session/mod.rs +++ b/crates/goose-cli/src/session/mod.rs @@ -521,6 +521,17 @@ impl Session { output::render_exit_plan_mode(); continue; } + input::InputResult::Clear => { + save_history(&mut editor); + + self.messages.clear(); + tracing::info!("Chat context cleared by user."); + output::render_message( + &Message::assistant().with_text("Chat context cleared."), + self.debug, + ); + continue; + } input::InputResult::PromptCommand(opts) => { save_history(&mut editor); self.handle_prompt_command(opts).await?;