diff --git a/Cargo.lock b/Cargo.lock index a429ade..7987daf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -732,9 +732,9 @@ dependencies = [ [[package]] name = "cookie" -version = "0.18.2" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a373e3602691c3cdea496d2f0ee5935151e6168fe87739483c463db1b2f2f87" +checksum = "d55f2d6c30eeec7d5c6f98bd4395d4abb1895629eab97ee6522d340623615f8a" dependencies = [ "time", "version_check", diff --git a/crates/process-manager/src/agents.rs b/crates/process-manager/src/agents.rs index 4e77ff3..54cd0f7 100644 --- a/crates/process-manager/src/agents.rs +++ b/crates/process-manager/src/agents.rs @@ -186,8 +186,17 @@ pub fn identify(p: &ProcessInfo) -> Option<&'static AgentSignature> { .take(3) .map(|a| a.replace('\\', "/")) .collect(); + // The script a launcher runs: `node /opt/homebrew/bin/qwen` runs `qwen`. + // Global npm installs and npx start agents through such a bin link, whose + // path does not contain the package name. + let launched = is_launcher(name) + .then(|| args.iter().skip(1).find(|a| !a.starts_with('-'))) + .flatten() + .and_then(|a| a.rsplit('/').next()); AGENTS.iter().find(|a| { - a.names.iter().any(|n| name == *n || exe_name == Some(n)) + a.names + .iter() + .any(|n| name == *n || exe_name == Some(n) || launched == Some(n)) // Node/Python launchers: the agent is named in the first few arguments. || (is_launcher(name) && args.iter().any(|arg| a.arg_markers.iter().any(|m| arg.contains(m)))) @@ -787,6 +796,53 @@ mod tests { assert_eq!(identify(&plain).map(|a| a.id), None); } + #[test] + fn identifies_agents_started_through_a_bin_link() { + // `npm i -g` / npx: node runs the bin link, not the package path. + let cases = [ + (&["node", "/opt/homebrew/bin/qwen"][..], "qwen-code"), + ( + &["node", "/Users/u/.npm/_npx/1a2b/node_modules/.bin/qwen"][..], + "qwen-code", + ), + ( + &["node", "--no-warnings", "/usr/local/bin/gemini"][..], + "gemini-cli", + ), + ( + &["node", "/opt/homebrew/bin/openclaw", "gateway"][..], + "openclaw", + ), + (&["python3", "/Users/u/.local/bin/aider"][..], "aider"), + ]; + for (args, want) in cases { + assert_eq!( + identify(&proc(10, 1, args[0], args, 100)).map(|a| a.id), + Some(want), + "{args:?}" + ); + } + // The package path still works, and ordinary scripts are not agents. + let pkg = [ + "node", + "/opt/homebrew/lib/node_modules/@qwen-code/qwen-code/cli-entry.js", + ]; + assert_eq!( + identify(&proc(11, 1, "node", &pkg, 100)).map(|a| a.id), + Some("qwen-code") + ); + for args in [ + &["node", "server.js", "qwen"][..], + &["node", "/srv/app/index.js"][..], + ] { + assert_eq!( + identify(&proc(12, 1, "node", args, 100)).map(|a| a.id), + None, + "{args:?}" + ); + } + } + #[test] fn gui_apps_are_hosts_not_sessions() { let mut p = proc(5, 1, "claude", &[], 10);