fix(tools): find gh across common install paths
## Summary - Probe common Linux and macOS gh CLI paths when DEEPSEEK_GH_BIN is not set. - Keep the existing /opt/homebrew/bin/gh fallback for compatibility. - Improve the not-installed error message. ## Verification - GitHub CI passed: lint, version drift, ubuntu/macos/windows tests, npm wrapper smoke, GitGuardian.
This commit is contained in:
@@ -15,6 +15,12 @@ use crate::tools::spec::{
|
||||
};
|
||||
|
||||
const DEFAULT_GH: &str = "/opt/homebrew/bin/gh";
|
||||
const FALLBACK_GH_PATHS: &[&str] = &[
|
||||
"/usr/bin/gh", // Linux system package manager
|
||||
"/usr/local/bin/gh", // macOS Intel Homebrew / manual install
|
||||
"/home/linuxbrew/.linuxbrew/bin/gh", // Linux Homebrew (official prefix)
|
||||
"/opt/homebrew/bin/gh", // macOS Apple Silicon Homebrew
|
||||
];
|
||||
const BODY_ARTIFACT_THRESHOLD: usize = 4_000;
|
||||
const DIFF_ARTIFACT_THRESHOLD: usize = 8_000;
|
||||
|
||||
@@ -300,7 +306,15 @@ impl ToolSpec for GithubCloseIssueTool {
|
||||
}
|
||||
|
||||
fn gh_bin() -> String {
|
||||
std::env::var("DEEPSEEK_GH_BIN").unwrap_or_else(|_| DEFAULT_GH.to_string())
|
||||
if let Ok(bin) = std::env::var("DEEPSEEK_GH_BIN") {
|
||||
return bin;
|
||||
}
|
||||
for path in FALLBACK_GH_PATHS {
|
||||
if std::path::Path::new(path).is_file() {
|
||||
return path.to_string();
|
||||
}
|
||||
}
|
||||
DEFAULT_GH.to_string()
|
||||
}
|
||||
|
||||
fn run_gh_text(context: &ToolContext, args: &[&str]) -> Result<String, ToolError> {
|
||||
@@ -310,7 +324,7 @@ fn run_gh_text(context: &ToolContext, args: &[&str]) -> Result<String, ToolError
|
||||
.output()
|
||||
.map_err(|e| {
|
||||
if e.kind() == std::io::ErrorKind::NotFound {
|
||||
ToolError::not_available("gh CLI is not installed at /opt/homebrew/bin/gh")
|
||||
ToolError::not_available("gh CLI not found; install it or set DEEPSEEK_GH_BIN")
|
||||
} else {
|
||||
ToolError::execution_failed(format!("failed to run gh: {e}"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user