fix: detect npm-wrapped pi on windows

refs #754
This commit is contained in:
Ogulcan Celik 2026-06-23 15:26:51 +03:00
parent 088922dfab
commit c580840307
1 changed files with 61 additions and 0 deletions

View File

@ -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 {
@ -782,6 +806,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 {