Handle clear operation
(os: &Os, session: &mut ChatSession)
| 364 | |
| 365 | /// Handle clear operation |
| 366 | async fn handle_clear(os: &Os, session: &mut ChatSession) -> OperationResult { |
| 367 | // Require confirmation |
| 368 | queue!( |
| 369 | session.stderr, |
| 370 | style::Print("⚠️ This action will remove all knowledge base entries.\n"), |
| 371 | style::Print("Clear the knowledge base? (y/N): ") |
| 372 | ) |
| 373 | .unwrap(); |
| 374 | session.stderr.flush().unwrap(); |
| 375 | |
| 376 | let mut input = String::new(); |
| 377 | if std::io::stdin().read_line(&mut input).is_err() { |
| 378 | return OperationResult::Error("Failed to read input".to_string()); |
| 379 | } |
| 380 | |
| 381 | let input = input.trim().to_lowercase(); |
| 382 | if input != "y" && input != "yes" { |
| 383 | return OperationResult::Info("Clear operation cancelled".to_string()); |
| 384 | } |
| 385 | |
| 386 | let agent = Self::get_agent(session); |
| 387 | let async_knowledge_store = match KnowledgeStore::get_async_instance(os, agent).await { |
| 388 | Ok(store) => store, |
| 389 | Err(e) => return OperationResult::Error(format!("Error accessing knowledge base directory: {}", e)), |
| 390 | }; |
| 391 | let mut store = async_knowledge_store.lock().await; |
| 392 | |
| 393 | // First, cancel any pending operations |
| 394 | queue!( |
| 395 | session.stderr, |
| 396 | style::Print("🛑 Cancelling any pending operations...\n") |
| 397 | ) |
| 398 | .unwrap(); |
| 399 | if let Err(e) = store.cancel_operation(None).await { |
| 400 | queue!( |
| 401 | session.stderr, |
| 402 | style::Print(&format!("⚠️ Warning: Failed to cancel operations: {}\n", e)) |
| 403 | ) |
| 404 | .unwrap(); |
| 405 | } |
| 406 | |
| 407 | // Now perform immediate synchronous clear |
| 408 | queue!( |
| 409 | session.stderr, |
| 410 | style::Print("🗑️ Clearing all knowledge base entries...\n") |
| 411 | ) |
| 412 | .unwrap(); |
| 413 | match store.clear_immediate().await { |
| 414 | Ok(message) => OperationResult::Success(message), |
| 415 | Err(e) => OperationResult::Error(format!("Failed to clear: {}", e)), |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | /// Format status data for display (UI rendering responsibility) |
| 420 | fn format_status_display(status: &SystemStatus) -> String { |
nothing calls this directly
no test coverage detected