From 8b7d801ec1b37d4d4608fa9c6a2536cb398230a6 Mon Sep 17 00:00:00 2001 From: akbash-bot <300245827+akbash-bot@users.noreply.github.com> Date: Mon, 24 Aug 2026 20:49:09 +0000 Subject: [PATCH] fix(windows): detect pi bundled cli refs #3205 --- src/detect/mod.rs | 59 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/src/detect/mod.rs b/src/detect/mod.rs index def440dcf0..63480e318d 100644 --- a/src/detect/mod.rs +++ b/src/detect/mod.rs @@ -583,12 +583,31 @@ fn agent_name_from_path_token(token: &str) -> Option { } fn agent_name_from_known_package_path(path: &str) -> Option { - let components: Vec = path + let raw_components: Vec<&str> = path .split(['/', '\\']) .filter(|component| !component.is_empty()) - .map(normalized_agent_lookup_name) .collect(); + let bundled_pi_cli = [ + "node_modules", + "@earendil-works", + "pi-coding-agent", + "dist", + "bundle", + "cli.js", + ]; + if raw_components.len() >= bundled_pi_cli.len() + && raw_components[raw_components.len() - bundled_pi_cli.len()..] + .iter() + .zip(bundled_pi_cli) + .all(|(actual, expected)| actual.eq_ignore_ascii_case(expected)) + { + return Some(agent_label(Agent::Pi).to_string()); + } + let components: Vec = raw_components + .into_iter() + .map(normalized_agent_lookup_name) + .collect(); for window in components.windows(5) { if window == [ @@ -1125,27 +1144,27 @@ mod tests { } #[test] - fn identify_agent_in_job_detects_node_wrapped_mastracode_package_cli() { + fn identify_agent_in_job_detects_node_wrapped_pi_bundled_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\\mastracode\\dist\\cli.js", + r"C:\Users\herdr\AppData\Local\pi-node\current\node.exe", + r"C:\Users\herdr\AppData\Local\pi-node\current/node_modules/@earendil-works/pi-coding-agent/dist/bundle/cli.js", ], )], }; assert_eq!( identify_agent_in_job(&job), - Some((Agent::Mastracode, "mastracode".to_string())) + Some((Agent::Pi, "pi".to_string())) ); } #[test] - fn identify_agent_in_job_ignores_non_cli_pi_package_script() { + fn identify_agent_in_job_detects_node_wrapped_mastracode_package_cli() { let job = crate::platform::ForegroundJob { process_group_id: 123, processes: vec![foreground_process( @@ -1153,12 +1172,34 @@ mod tests { "node.exe", &[ "node.exe", - "C:\\Users\\herdr\\AppData\\Roaming\\npm\\node_modules\\@earendil-works\\pi-coding-agent\\scripts\\build.js", + "C:\\Users\\herdr\\AppData\\Roaming\\npm\\node_modules\\mastracode\\dist\\cli.js", ], )], }; - assert_eq!(identify_agent_in_job(&job), None); + assert_eq!( + identify_agent_in_job(&job), + Some((Agent::Mastracode, "mastracode".to_string())) + ); + } + + #[test] + fn identify_agent_in_job_ignores_non_cli_pi_package_scripts() { + for script in [ + r"C:\Users\herdr\AppData\Roaming\npm\node_modules\@earendil-works\pi-coding-agent\scripts\build.js", + r"C:\Users\herdr\AppData\Local\pi-node\current\node_modules\@earendil-works\pi-coding-agent\dist\bundle\update.js", + r"C:\workspace\dist\bundle\cli.js", + r"C:\workspace\node_modules\other-package\dist\bundle\cli.js", + r"C:\workspace\node_modules\@earendil-works\pi-coding-agent\dist\bundle\cli.exe", + r"C:\workspace\node_modules\@earendil-works\pi-coding-agent\dist\bundle\cli.js\other.js", + ] { + let job = crate::platform::ForegroundJob { + process_group_id: 123, + processes: vec![foreground_process(123, "node.exe", &["node.exe", script])], + }; + + assert_eq!(identify_agent_in_job(&job), None, "script: {script}"); + } } #[test]