()
| 527 | // ======================== Main ======================== |
| 528 | |
| 529 | async fn run_cli() -> Result<()> { |
| 530 | let cli = Cli::parse(); |
| 531 | |
| 532 | let is_tui_mode = matches!(cli.command, None | Some(Commands::Chat { .. })); |
| 533 | let is_exec_mode = matches!(cli.command, Some(Commands::Exec { .. })); |
| 534 | let file_log_level = logging::default_log_level(cli.verbose); |
| 535 | let stderr_log_level = if cli.verbose { |
| 536 | tracing::Level::TRACE |
| 537 | } else { |
| 538 | tracing::Level::ERROR |
| 539 | }; |
| 540 | |
| 541 | if is_tui_mode || is_exec_mode { |
| 542 | logging::init_file_logging(file_log_level); |
| 543 | } else { |
| 544 | tracing_subscriber::fmt() |
| 545 | .with_max_level(stderr_log_level) |
| 546 | .with_writer(std::io::stderr) |
| 547 | .with_ansi(false) |
| 548 | .with_target(false) |
| 549 | .init(); |
| 550 | } |
| 551 | |
| 552 | let config = CliConfig::load().unwrap_or_else(|e| { |
| 553 | if !is_tui_mode { |
| 554 | eprintln!("Warning: Failed to load config: {}", e); |
| 555 | eprintln!("Using default configuration"); |
| 556 | } |
| 557 | CliConfig::default() |
| 558 | }); |
| 559 | |
| 560 | match cli.command { |
| 561 | Some(Commands::Chat { agent }) => { |
| 562 | // Interactive mode with startup page, scoped to the current directory. |
| 563 | run_interactive(config, agent, ".".to_string()).await?; |
| 564 | } |
| 565 | |
| 566 | Some(Commands::Exec { |
| 567 | message, |
| 568 | agent, |
| 569 | continue_last, |
| 570 | resume, |
| 571 | session, |
| 572 | session_id, |
| 573 | fork_session, |
| 574 | output_format, |
| 575 | output_patch, |
| 576 | confirm, |
| 577 | }) => { |
| 578 | root_handlers::handle_exec_command( |
| 579 | config, |
| 580 | root_handlers::ExecCommandArgs { |
| 581 | message, |
| 582 | agent, |
| 583 | continue_last, |
| 584 | resume, |
| 585 | session, |
| 586 | session_id, |
no test coverage detected