Add /clear command to clear goose context (#1802)

Co-authored-by: Bradley Axen <baxen@squareup.com>
This commit is contained in:
Jay4242
2025-06-16 14:34:19 -07:00
committed by GitHub
parent 516e5fed7a
commit e178f6ba82
2 changed files with 15 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ pub enum InputResult {
GooseMode(String),
Plan(PlanCommandOptions),
EndPlan,
Clear,
Recipe(Option<String>),
Summarize,
}
@@ -91,6 +92,7 @@ fn handle_slash_command(input: &str) -> Option<InputResult> {
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<InputResult> {
}
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)

View File

@@ -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?;