Make ctrl-c work like in claude code (#6900)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -166,11 +166,19 @@ pub struct CliSession {
|
||||
output_format: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum HintStatus {
|
||||
Default,
|
||||
Interrupted,
|
||||
MaybeExit,
|
||||
}
|
||||
|
||||
// Cache structure for completion data
|
||||
struct CompletionCache {
|
||||
prompts: HashMap<String, Vec<String>>,
|
||||
prompt_info: HashMap<String, output::PromptInfo>,
|
||||
last_updated: Instant,
|
||||
pub struct CompletionCache {
|
||||
pub prompts: HashMap<String, Vec<String>>,
|
||||
pub prompt_info: HashMap<String, output::PromptInfo>,
|
||||
pub last_updated: Instant,
|
||||
pub hint_status: HintStatus,
|
||||
}
|
||||
|
||||
impl CompletionCache {
|
||||
@@ -179,6 +187,7 @@ impl CompletionCache {
|
||||
prompts: HashMap::new(),
|
||||
prompt_info: HashMap::new(),
|
||||
last_updated: Instant::now(),
|
||||
hint_status: HintStatus::Default,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1095,7 +1104,11 @@ impl CliSession {
|
||||
}
|
||||
|
||||
async fn handle_interrupted_messages(&mut self, interrupt: bool) -> Result<()> {
|
||||
// First, get any tool requests from the last message if it exists
|
||||
if interrupt {
|
||||
let mut cache = self.completion_cache.write().unwrap();
|
||||
cache.hint_status = HintStatus::Interrupted;
|
||||
}
|
||||
|
||||
let tool_requests = self
|
||||
.messages
|
||||
.last()
|
||||
@@ -1116,6 +1129,7 @@ impl CliSession {
|
||||
if !tool_requests.is_empty() {
|
||||
// Interrupted during a tool request
|
||||
// Create tool responses for all interrupted tool requests
|
||||
// TODO(Douwe): if we need this, it should happen in agent reply
|
||||
let mut response_message = Message::user();
|
||||
let last_tool_name = tool_requests
|
||||
.last()
|
||||
@@ -1142,7 +1156,6 @@ impl CliSession {
|
||||
}),
|
||||
));
|
||||
}
|
||||
// TODO(Douwe): update also db
|
||||
self.push_message(response_message);
|
||||
let prompt = format!(
|
||||
"The existing call to {} was interrupted. How would you like to proceed?",
|
||||
|
||||
Reference in New Issue
Block a user