fix: Ctrl+C or ESC during CLI menu selection continues the current session gracefully (#2664)
Co-authored-by: Angie Jones <jones.angie@gmail.com>
This commit is contained in:
@@ -555,7 +555,16 @@ impl Session {
|
|||||||
|
|
||||||
let prompt = "Are you sure you want to summarize this conversation? This will condense the message history.";
|
let prompt = "Are you sure you want to summarize this conversation? This will condense the message history.";
|
||||||
let should_summarize =
|
let should_summarize =
|
||||||
cliclack::confirm(prompt).initial_value(true).interact()?;
|
match cliclack::confirm(prompt).initial_value(true).interact() {
|
||||||
|
Ok(choice) => choice,
|
||||||
|
Err(e) => {
|
||||||
|
if e.kind() == std::io::ErrorKind::Interrupted {
|
||||||
|
false // If interrupted, set should_summarize to false
|
||||||
|
} else {
|
||||||
|
return Err(e.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if should_summarize {
|
if should_summarize {
|
||||||
println!("{}", console::style("Summarizing conversation...").yellow());
|
println!("{}", console::style("Summarizing conversation...").yellow());
|
||||||
@@ -624,10 +633,21 @@ impl Session {
|
|||||||
match planner_response_type {
|
match planner_response_type {
|
||||||
PlannerResponseType::Plan => {
|
PlannerResponseType::Plan => {
|
||||||
println!();
|
println!();
|
||||||
let should_act =
|
let should_act = match cliclack::confirm(
|
||||||
cliclack::confirm("Do you want to clear message history & act on this plan?")
|
"Do you want to clear message history & act on this plan?",
|
||||||
.initial_value(true)
|
)
|
||||||
.interact()?;
|
.initial_value(true)
|
||||||
|
.interact()
|
||||||
|
{
|
||||||
|
Ok(choice) => choice,
|
||||||
|
Err(e) => {
|
||||||
|
if e.kind() == std::io::ErrorKind::Interrupted {
|
||||||
|
false // If interrupted, set should_act to false
|
||||||
|
} else {
|
||||||
|
return Err(e.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
if should_act {
|
if should_act {
|
||||||
output::render_act_on_plan();
|
output::render_act_on_plan();
|
||||||
self.run_mode = RunMode::Normal;
|
self.run_mode = RunMode::Normal;
|
||||||
@@ -751,11 +771,23 @@ impl Session {
|
|||||||
if interactive {
|
if interactive {
|
||||||
// In interactive mode, ask the user what to do
|
// In interactive mode, ask the user what to do
|
||||||
let prompt = "The model's context length is maxed out. You will need to reduce the # msgs. Do you want to?".to_string();
|
let prompt = "The model's context length is maxed out. You will need to reduce the # msgs. Do you want to?".to_string();
|
||||||
let selected = cliclack::select(prompt)
|
let selected_result = cliclack::select(prompt)
|
||||||
.item("clear", "Clear Session", "Removes all messages from Goose's memory")
|
.item("clear", "Clear Session", "Removes all messages from Goose's memory")
|
||||||
.item("truncate", "Truncate Messages", "Removes old messages till context is within limits")
|
.item("truncate", "Truncate Messages", "Removes old messages till context is within limits")
|
||||||
.item("summarize", "Summarize Session", "Summarize the session to reduce context length")
|
.item("summarize", "Summarize Session", "Summarize the session to reduce context length")
|
||||||
.interact()?;
|
.item("cancel", "Cancel", "Cancel and return to chat")
|
||||||
|
.interact();
|
||||||
|
|
||||||
|
let selected = match selected_result {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(e) => {
|
||||||
|
if e.kind() == std::io::ErrorKind::Interrupted {
|
||||||
|
"cancel" // If interrupted, set selected to cancel
|
||||||
|
} else {
|
||||||
|
return Err(e.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
match selected {
|
match selected {
|
||||||
"clear" => {
|
"clear" => {
|
||||||
@@ -776,6 +808,9 @@ impl Session {
|
|||||||
// Use the helper function to summarize context
|
// Use the helper function to summarize context
|
||||||
Self::summarize_context_messages(&mut self.messages, &self.agent, "Goose summarized messages for you.").await?;
|
Self::summarize_context_messages(&mut self.messages, &self.agent, "Goose summarized messages for you.").await?;
|
||||||
}
|
}
|
||||||
|
"cancel" => {
|
||||||
|
break; // Return to main prompt
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user