From 42f16b889c68b789d2f48f44e72b2dd4889a4cd9 Mon Sep 17 00:00:00 2001 From: Jeff Nunn Date: Thu, 25 Sep 2025 08:35:45 -0500 Subject: [PATCH] Typing "quit" or "exit" without slash also terminates session --- crates/chat-cli/src/cli/chat/mod.rs | 48 ++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/crates/chat-cli/src/cli/chat/mod.rs b/crates/chat-cli/src/cli/chat/mod.rs index e15509945..f20bc76cd 100644 --- a/crates/chat-cli/src/cli/chat/mod.rs +++ b/crates/chat-cli/src/cli/chat/mod.rs @@ -2031,6 +2031,8 @@ impl ChatSession { Ok(ChatState::PromptUser { skip_printing_tools: false, }) + } else if matches!(input.to_lowercase().as_str(), "exit" | "quit") { + return Ok(ChatState::Exit); } else if let Some(command) = input.strip_prefix("@") { let input_parts = shlex::split(command).ok_or(ChatError::Custom("Error splitting prompt command".into()))?; @@ -3003,7 +3005,7 @@ impl ChatSession { return Ok(ChatState::PromptUser { skip_printing_tools: false, }); - }, +}, Err(err) => return Err(err), } @@ -4170,6 +4172,50 @@ mod tests { assert_eq!(actual, *expected, "expected {} for input {}", expected, input); } } + + #[tokio::test] + async fn test_exit_quit_commands() { + let mut os = Os::new().await.unwrap(); + let agents = get_test_agents(&os).await; + let tool_manager = ToolManager::default(); + let tool_config = serde_json::from_str::>(include_str!("tools/tool_index.json")) + .expect("Tools failed to load"); + + let mut chat_session = ChatSession::new( + &mut os, + std::io::stdout(), + std::io::stderr(), + "fake_conv_id", + agents, + None, + InputSource::new_mock(vec![]), + false, + || Some(80), + tool_manager, + None, + tool_config, + true, + false, + None, + ) + .await + .unwrap(); + + let test_cases = vec!["exit", "quit", "EXIT", "QUIT", "Exit", "Quit"]; + + for input in test_cases { + let result = chat_session.handle_input(&mut os, input.to_string()).await; + assert!(result.is_ok(), "handle_input should succeed for input: {}", input); + + let chat_state = result.unwrap(); + assert!( + matches!(chat_state, ChatState::Exit), + "Expected ChatState::Exit for input '{}', got {:?}", + input, + chat_state + ); + } + } } // Helper method to save the agent config to file