Run the full interactive TUI flow: loading screen → startup page → chat
(
_config: CliConfig,
default_agent: String,
_workspace_str: String,
)
| 461 | |
| 462 | /// Run the full interactive TUI flow: loading screen → startup page → chat |
| 463 | async fn run_interactive( |
| 464 | _config: CliConfig, |
| 465 | default_agent: String, |
| 466 | _workspace_str: String, |
| 467 | ) -> Result<()> { |
| 468 | use ui::startup::{StartupPage, StartupResult}; |
| 469 | |
| 470 | // 1. Initialize terminal and show loading screen |
| 471 | let mut terminal = ui::init_terminal()?; |
| 472 | ui::render_loading(&mut terminal, "Initializing system, please wait...")?; |
| 473 | |
| 474 | // 2. Set workspace path |
| 475 | let workspace = setup_workspace(); |
| 476 | |
| 477 | // 3. Initialize core services |
| 478 | let (agentic_system, original_skip_confirmation) = initialize_core_services(true).await?; |
| 479 | |
| 480 | // 4. Show startup page (with full command support) |
| 481 | let mut startup_page = StartupPage::new( |
| 482 | agentic_system.coordinator.clone(), |
| 483 | default_agent, |
| 484 | workspace.clone(), |
| 485 | ); |
| 486 | let startup_result = startup_page.run(&mut terminal)?; |
| 487 | |
| 488 | match startup_result { |
| 489 | StartupResult::Exit => { |
| 490 | shutdown_mcp_servers().await; |
| 491 | restore_tool_confirmation(original_skip_confirmation).await; |
| 492 | ui::restore_terminal(terminal)?; |
| 493 | println!("Goodbye!"); |
| 494 | return Ok(()); |
| 495 | } |
| 496 | _ => {} |
| 497 | } |
| 498 | |
| 499 | // 5. Parse startup result and enter chat |
| 500 | let (restore_session_id, initial_prompt) = match &startup_result { |
| 501 | StartupResult::NewSession { prompt } => (None, prompt.clone()), |
| 502 | StartupResult::ContinueSession(id) => (Some(id.clone()), None), |
| 503 | StartupResult::Exit => unreachable!(), |
| 504 | }; |
| 505 | |
| 506 | let agent_type = startup_page.agent_type().to_string(); |
| 507 | // Use the current project workspace selected at process start. |
| 508 | let workspace = startup_page.workspace(); |
| 509 | let config = startup_page.config().clone(); |
| 510 | let mut chat_mode = ChatMode::new(config, agent_type, workspace, &agentic_system); |
| 511 | if let Some(session_id) = restore_session_id { |
| 512 | chat_mode = chat_mode.with_restore_session(session_id); |
| 513 | } |
| 514 | if let Some(prompt) = initial_prompt { |
| 515 | chat_mode = chat_mode.with_initial_prompt(prompt); |
| 516 | } |
| 517 | let _exit_reason = chat_mode.run(Some(terminal))?; |
| 518 | |
| 519 | // 6. Cleanup |
| 520 | shutdown_mcp_servers().await; |
no test coverage detected