Initialize all core services (config, AI client, agentic system). Returns (agentic_system, original_skip_confirmation).
(
skip_tool_confirmation: bool,
)
| 366 | /// Initialize all core services (config, AI client, agentic system). |
| 367 | /// Returns (agentic_system, original_skip_confirmation). |
| 368 | async fn initialize_core_services( |
| 369 | skip_tool_confirmation: bool, |
| 370 | ) -> Result<(agent::agentic_system::AgenticSystem, bool)> { |
| 371 | use bitfun_core::infrastructure::ai::AIClientFactory; |
| 372 | |
| 373 | bitfun_core::service::config::initialize_global_config() |
| 374 | .await |
| 375 | .expect("Failed to initialize global config service"); |
| 376 | tracing::info!("Global config service initialized"); |
| 377 | |
| 378 | // Save and override tool confirmation setting |
| 379 | let config_service = bitfun_core::service::config::get_global_config_service() |
| 380 | .await |
| 381 | .ok(); |
| 382 | let original_skip_confirmation = if let Some(ref svc) = config_service { |
| 383 | let ai_config: bitfun_core::service::config::types::AIConfig = |
| 384 | svc.get_config(Some("ai")).await.unwrap_or_default(); |
| 385 | ai_config.skip_tool_confirmation |
| 386 | } else { |
| 387 | false |
| 388 | }; |
| 389 | if let Some(ref svc) = config_service { |
| 390 | let _ = svc |
| 391 | .set_config("ai.skip_tool_confirmation", skip_tool_confirmation) |
| 392 | .await; |
| 393 | } |
| 394 | |
| 395 | AIClientFactory::initialize_global() |
| 396 | .await |
| 397 | .expect("Failed to initialize global AIClientFactory"); |
| 398 | tracing::info!("Global AI client factory initialized"); |
| 399 | |
| 400 | initialize_terminal_service().await; |
| 401 | |
| 402 | let agentic_system = agent::agentic_system::init_agentic_system() |
| 403 | .await |
| 404 | .expect("Failed to initialize agentic system"); |
| 405 | tracing::info!("Agentic system initialized"); |
| 406 | |
| 407 | // Initialize MCP service in background (non-blocking) |
| 408 | if let Some(ref cfg_svc) = config_service { |
| 409 | match bitfun_core::service::mcp::MCPService::new(cfg_svc.clone()) { |
| 410 | Ok(mcp_service) => { |
| 411 | let mcp_service = std::sync::Arc::new(mcp_service); |
| 412 | MCP_SERVICE.set(mcp_service.clone()).ok(); |
| 413 | |
| 414 | // Mark as in progress |
| 415 | get_mcp_init_status().store(1, Ordering::Relaxed); |
| 416 | |
| 417 | // Background async initialization |
| 418 | tokio::spawn(async move { |
| 419 | let result = mcp_service.server_manager().initialize_all().await; |
| 420 | match result { |
| 421 | Ok(_) => { |
| 422 | tracing::info!("MCP servers initialized successfully"); |
| 423 | get_mcp_init_status().store(2, Ordering::Relaxed); |
| 424 | } |
| 425 | Err(e) => { |
no test coverage detected