MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / try_run_external_acp_bridge

Function try_run_external_acp_bridge

crates/opencode-cli/src/main.rs:2173–2228  ·  view source on GitHub ↗
(
    port: u16,
    hostname: &str,
    mdns: bool,
    mdns_domain: &str,
    cors: &[String],
    cwd: &Path,
)

Source from the content-addressed store, hash-verified

2171}
2172
2173fn try_run_external_acp_bridge(
2174 port: u16,
2175 hostname: &str,
2176 mdns: bool,
2177 mdns_domain: &str,
2178 cors: &[String],
2179 cwd: &Path,
2180) -> anyhow::Result<bool> {
2181 if std::env::var("OPENCODE_ACP_BRIDGE_ACTIVE").ok().as_deref() == Some("1") {
2182 return Ok(false);
2183 }
2184
2185 let acp_args = build_acp_network_args(port, hostname, mdns, mdns_domain, cors, cwd);
2186
2187 if let Ok(bin) = std::env::var("OPENCODE_ACP_BRIDGE_BIN") {
2188 let bin = bin.trim();
2189 if bin.is_empty() {
2190 anyhow::bail!("OPENCODE_ACP_BRIDGE_BIN is set but empty.");
2191 }
2192 return run_acp_bridge_candidate(bin, &acp_args, None);
2193 }
2194
2195 if let Ok(opencode_path) = which::which("opencode") {
2196 let is_self = std::env::current_exe()
2197 .ok()
2198 .and_then(|exe| {
2199 let lhs = fs::canonicalize(exe).ok()?;
2200 let rhs = fs::canonicalize(opencode_path).ok()?;
2201 Some(lhs == rhs)
2202 })
2203 .unwrap_or(false);
2204 if !is_self {
2205 if run_acp_bridge_candidate("opencode", &acp_args, None)? {
2206 return Ok(true);
2207 }
2208 }
2209 }
2210
2211 if which::which("bun").is_ok() {
2212 if let Some(pkg_dir) = find_local_ts_opencode_package_dir() {
2213 let mut bun_args = vec![
2214 "run".to_string(),
2215 "--cwd".to_string(),
2216 pkg_dir.display().to_string(),
2217 "--conditions=browser".to_string(),
2218 "src/index.ts".to_string(),
2219 ];
2220 bun_args.extend(acp_args);
2221 if run_acp_bridge_candidate("bun", &bun_args, None)? {
2222 return Ok(true);
2223 }
2224 }
2225 }
2226
2227 Ok(false)
2228}
2229
2230fn truncate_text(input: &str, max_chars: usize) -> String {

Callers 1

run_acp_commandFunction · 0.85

Calls 4

build_acp_network_argsFunction · 0.85
run_acp_bridge_candidateFunction · 0.85
is_emptyMethod · 0.80

Tested by

no test coverage detected