使用rust which包来查找命令路径,解决部分电脑环境变量识别问题
This commit is contained in:
@@ -81,27 +81,15 @@ fn package_name_from_spec(package: &str) -> String {
|
||||
/// Check whether a command is available on the system PATH.
|
||||
/// Uses `which` on unix and `where` on windows — lightweight and does not
|
||||
/// invoke the target binary itself, avoiding side-effects or slow startups.
|
||||
async fn is_cmd_available(cmd: &str) -> bool {
|
||||
#[cfg(unix)]
|
||||
let check_cmd = "which";
|
||||
#[cfg(windows)]
|
||||
let check_cmd = "where";
|
||||
|
||||
crate::process::tokio_command(check_cmd)
|
||||
.arg(cmd)
|
||||
.stdout(std::process::Stdio::null())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.status()
|
||||
.await
|
||||
.map(|s| s.success())
|
||||
.unwrap_or(false)
|
||||
fn is_cmd_available(cmd: &str) -> bool {
|
||||
which::which(cmd).is_ok()
|
||||
}
|
||||
|
||||
async fn detect_local_version(agent_type: AgentType) -> Option<String> {
|
||||
let meta = registry::get_agent_meta(agent_type);
|
||||
match meta.distribution {
|
||||
registry::AgentDistribution::Npx { cmd, package, .. } => {
|
||||
if is_cmd_available(cmd).await {
|
||||
if is_cmd_available(cmd) {
|
||||
version_from_package_spec(package)
|
||||
} else {
|
||||
None
|
||||
@@ -1047,7 +1035,7 @@ pub async fn acp_connect(
|
||||
}
|
||||
|
||||
if let registry::AgentDistribution::Npx { cmd, .. } = meta.distribution {
|
||||
if !is_cmd_available(cmd).await {
|
||||
if !is_cmd_available(cmd) {
|
||||
return Err(AcpError::protocol(format!(
|
||||
"{} SDK is not installed. Please install it in Agent Settings.",
|
||||
meta.name
|
||||
|
||||
Reference in New Issue
Block a user