(
project: Option<PathBuf>,
model: Option<String>,
continue_last: bool,
session: Option<String>,
fork: bool,
agent_name: String,
initial_prompt: Option<String>,
port: u
| 790 | } |
| 791 | |
| 792 | async fn run_tui( |
| 793 | project: Option<PathBuf>, |
| 794 | model: Option<String>, |
| 795 | continue_last: bool, |
| 796 | session: Option<String>, |
| 797 | fork: bool, |
| 798 | agent_name: String, |
| 799 | initial_prompt: Option<String>, |
| 800 | port: u16, |
| 801 | hostname: String, |
| 802 | mdns: bool, |
| 803 | mdns_domain: String, |
| 804 | cors: Vec<String>, |
| 805 | attach_url: Option<String>, |
| 806 | _password: Option<String>, |
| 807 | ) -> anyhow::Result<()> { |
| 808 | if let Some(project) = project { |
| 809 | std::env::set_current_dir(&project).map_err(|e| { |
| 810 | anyhow::anyhow!("Failed to change directory to {}: {}", project.display(), e) |
| 811 | })?; |
| 812 | } |
| 813 | |
| 814 | if fork && !continue_last && session.is_none() { |
| 815 | anyhow::bail!("--fork requires --continue or --session"); |
| 816 | } |
| 817 | |
| 818 | let mut server_handle = None; |
| 819 | let mut mdns_publisher: Option<MdnsPublisher> = None; |
| 820 | let base_url = if let Some(url) = attach_url { |
| 821 | url |
| 822 | } else { |
| 823 | let bind_host = if mdns && hostname == "127.0.0.1" { |
| 824 | "0.0.0.0".to_string() |
| 825 | } else { |
| 826 | hostname.clone() |
| 827 | }; |
| 828 | let client_host = if bind_host == "0.0.0.0" { |
| 829 | "127.0.0.1".to_string() |
| 830 | } else { |
| 831 | bind_host.clone() |
| 832 | }; |
| 833 | let bind_port = if port == 0 { 3000 } else { port }; |
| 834 | let addr: SocketAddr = format!("{}:{}", bind_host, bind_port).parse()?; |
| 835 | let server_url = format!("http://{}:{}", client_host, bind_port); |
| 836 | eprintln!("Starting local server for TUI at {}", server_url); |
| 837 | opencode_server::set_cors_whitelist(cors.clone()); |
| 838 | let mut handle = tokio::spawn(async move { opencode_server::run_server(addr).await }); |
| 839 | wait_for_server_ready(&server_url, Duration::from_secs(90), Some(&mut handle)).await?; |
| 840 | server_handle = Some(handle); |
| 841 | mdns_publisher = start_mdns_publisher_if_needed(mdns, &bind_host, bind_port, &mdns_domain); |
| 842 | server_url |
| 843 | }; |
| 844 | |
| 845 | let selected_session = resolve_requested_session(continue_last, session, fork).await?; |
| 846 | std::env::set_var("OPENCODE_TUI_BASE_URL", &base_url); |
| 847 | if let Some(model) = model { |
| 848 | std::env::set_var("OPENCODE_TUI_MODEL", model); |
| 849 | } |
no test coverage detected