(self, session: &mut ChatSession)
| 22 | |
| 23 | impl ClearArgs { |
| 24 | pub async fn execute(self, session: &mut ChatSession) -> Result<ChatState, ChatError> { |
| 25 | execute!( |
| 26 | session.stderr, |
| 27 | StyledText::secondary_fg(), |
| 28 | style::Print( |
| 29 | "\nAre you sure? This will erase the conversation history and context from hooks for the current session. " |
| 30 | ), |
| 31 | style::Print("["), |
| 32 | StyledText::success_fg(), |
| 33 | style::Print("y"), |
| 34 | StyledText::secondary_fg(), |
| 35 | style::Print("/"), |
| 36 | StyledText::success_fg(), |
| 37 | style::Print("n"), |
| 38 | StyledText::secondary_fg(), |
| 39 | style::Print("]:\n\n"), |
| 40 | StyledText::reset(), |
| 41 | cursor::Show, |
| 42 | )?; |
| 43 | |
| 44 | // Setting `exit_on_single_ctrl_c` for better ux: exit the confirmation dialog rather than the CLI |
| 45 | let user_input = match session.read_user_input("> ".yellow().to_string().as_str(), true) { |
| 46 | Some(input) => input, |
| 47 | None => "".to_string(), |
| 48 | }; |
| 49 | |
| 50 | if ["y", "Y"].contains(&user_input.as_str()) { |
| 51 | session.conversation.clear(); |
| 52 | if let Some(cm) = session.conversation.context_manager.as_mut() { |
| 53 | cm.hook_executor.cache.clear(); |
| 54 | } |
| 55 | |
| 56 | // Reset pending tool state to prevent orphaned tool approval prompts |
| 57 | session.tool_uses.clear(); |
| 58 | session.pending_tool_index = None; |
| 59 | session.tool_turn_start_time = None; |
| 60 | |
| 61 | execute!( |
| 62 | session.stderr, |
| 63 | StyledText::success_fg(), |
| 64 | style::Print("\nConversation history cleared.\n\n"), |
| 65 | StyledText::reset(), |
| 66 | )?; |
| 67 | } |
| 68 | |
| 69 | Ok(ChatState::default()) |
| 70 | } |
| 71 | } |
nothing calls this directly
no test coverage detected