Fix Linux Pi detection: resolve via npm root -g (Sam & Claude)
pi --version has no stable stdout and the ~/.npm-global path does not match nvm layouts, so Pi went undetected on Linux. Now also resolve the active node's global modules via 'npm root -g' and read pi's package.json. Additive — the FreeBSD/.npm-global paths Codex hardened are unchanged. Verified on domedog (login shell, node v24.16.0): inventory now reports pi 0.75.5. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
6269030424
commit
094b98faf4
1 changed files with 26 additions and 2 deletions
|
|
@ -99,15 +99,22 @@ fn command_exists(program: &str) -> bool {
|
|||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
<<<<<<< Updated upstream
|
||||
fn package_json_version(path: impl AsRef<Path>) -> Option<String> {
|
||||
let raw = fs::read_to_string(path).ok()?;
|
||||
let parsed = serde_json::from_str::<serde_json::Value>(&raw).ok()?;
|
||||
=======
|
||||
fn read_pi_version_from(package_json: &str) -> Option<String> {
|
||||
let raw = fs::read_to_string(package_json).ok()?;
|
||||
let parsed: serde_json::Value = serde_json::from_str(&raw).ok()?;
|
||||
>>>>>>> Stashed changes
|
||||
parsed
|
||||
.get("version")
|
||||
.and_then(|value| value.as_str())
|
||||
.map(|value| value.to_string())
|
||||
}
|
||||
|
||||
<<<<<<< Updated upstream
|
||||
fn pi_package_version_from_bin(candidate: &str) -> Option<String> {
|
||||
let canonical = fs::canonicalize(candidate).ok()?;
|
||||
for dir in canonical.ancestors() {
|
||||
|
|
@ -122,6 +129,8 @@ fn pi_package_version_from_bin(candidate: &str) -> Option<String> {
|
|||
None
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> Stashed changes
|
||||
fn detect_pi_version() -> Option<String> {
|
||||
if let Ok(pi_bin) = env::var("PI_BIN") {
|
||||
if let Some(version) =
|
||||
|
|
@ -132,17 +141,32 @@ fn detect_pi_version() -> Option<String> {
|
|||
}
|
||||
|
||||
if let Ok(home) = env::var("HOME") {
|
||||
// Explicit npm-global layout (FreeBSD / user installs).
|
||||
let pi_bin = format!("{home}/.npm-global/bin/pi");
|
||||
if let Some(version) =
|
||||
command_output(&pi_bin, &["--version"]).or_else(|| pi_package_version_from_bin(&pi_bin))
|
||||
{
|
||||
return Some(version);
|
||||
}
|
||||
|
||||
let package_json = format!(
|
||||
if let Some(version) = read_pi_version_from(&format!(
|
||||
"{home}/.npm-global/lib/node_modules/@earendil-works/pi-coding-agent/package.json"
|
||||
<<<<<<< Updated upstream
|
||||
);
|
||||
if let Some(version) = package_json_version(package_json) {
|
||||
=======
|
||||
)) {
|
||||
return Some(version);
|
||||
}
|
||||
}
|
||||
|
||||
// Active-node global install (nvm on Linux, pkg node on FreeBSD): resolve
|
||||
// the global node_modules with `npm root -g` and read pi's package.json.
|
||||
// `pi --version` is unreliable (no stable stdout), so prefer the manifest.
|
||||
if let Some(root) = command_output("npm", &["root", "-g"]) {
|
||||
if let Some(version) = read_pi_version_from(&format!(
|
||||
"{root}/@earendil-works/pi-coding-agent/package.json"
|
||||
)) {
|
||||
>>>>>>> Stashed changes
|
||||
return Some(version);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue