diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-23 15:26:51 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-23 15:26:51 +0300 |
| commit | c580840307f0bb03ee3ccb8fe659282f3a1031e1 (patch) | |
| tree | 305fb44288060e70fed87d837f0b1f0de61390fd | |
| parent | 088922dfabca152047c8f39f660893b3b19dbe2d (diff) | |
fix: detect npm-wrapped pi on windows
refs #754
| -rw-r--r-- | src/detect/mod.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/detect/mod.rs b/src/detect/mod.rs index c8292ab2..e88d5e5d 100644 --- a/src/detect/mod.rs +++ b/src/detect/mod.rs @@ -471,9 +471,33 @@ fn agent_name_from_path_token(token: &str) -> Option<String> { } agent_name_from_basename(path_basename(trimmed)) + .or_else(|| agent_name_from_known_package_path(trimmed)) .or_else(|| resolved_agent_name_from_path_token(trimmed)) } +fn agent_name_from_known_package_path(path: &str) -> Option<String> { + let components: Vec<String> = path + .split(['/', '\\']) + .filter(|component| !component.is_empty()) + .map(normalized_agent_lookup_name) + .collect(); + + for window in components.windows(5) { + if window + == [ + "node_modules", + "@earendil-works", + "pi-coding-agent", + "dist", + "cli", + ] + { + return Some(agent_label(Agent::Pi).to_string()); + } + } + None +} + fn resolved_agent_name_from_path_token(token: &str) -> Option<String> { let path = std::path::Path::new(token); if path.components().count() < 2 { @@ -783,6 +807,43 @@ mod tests { } #[test] + fn identify_agent_in_job_detects_node_wrapped_pi_package_cli() { + let job = crate::platform::ForegroundJob { + process_group_id: 123, + processes: vec![foreground_process( + 123, + "node.exe", + &[ + "node.exe", + "C:\\Users\\herdr\\AppData\\Roaming\\npm\\node_modules\\@earendil-works\\pi-coding-agent\\dist\\cli.js", + ], + )], + }; + + assert_eq!( + identify_agent_in_job(&job), + Some((Agent::Pi, "pi".to_string())) + ); + } + + #[test] + fn identify_agent_in_job_ignores_non_cli_pi_package_script() { + let job = crate::platform::ForegroundJob { + process_group_id: 123, + processes: vec![foreground_process( + 123, + "node.exe", + &[ + "node.exe", + "C:\\Users\\herdr\\AppData\\Roaming\\npm\\node_modules\\@earendil-works\\pi-coding-agent\\scripts\\build.js", + ], + )], + }; + + assert_eq!(identify_agent_in_job(&job), None); + } + + #[test] fn identify_agent_in_job_detects_windows_cmd_wrapped_codex() { let job = crate::platform::ForegroundJob { process_group_id: 123, |
