the runtime your coding agents live on
Rust agentagent-orchestrationaiai-agentsclaude-codeclicodexcoding-agentsdeveloper-toolsdevtoolsmultiplexerrustterminalterminal-multiplexerterminal-uitmuxtuiworkspace-manager
fix: recognize Hermes launched through its Python wrapper (#4911)
akbashe35f3937b0ef
diff --git a/src/detect/mod.rs b/src/detect/mod.rsindex 37d5481a8..afdeed815 100644--- a/src/detect/mod.rs+++ b/src/detect/mod.rs@@ -420,7 +420,8 @@ fn wrapped_agent_name_from_runtime_argv(runtime: &str, argv: Option<&[String]>)"node" => cursor_agent_name_from_bundled_node_argv(argv).or_else(|| script_arg_agent_name(argv, &["-e", "--eval", "-p", "--print"], &[])),"bun" => script_arg_agent_name(argv, &["-e", "--eval", "-p", "--print"], &[]),- name if is_python_runtime(name) => script_arg_agent_name(argv, &["-c"], &["-m"]),+ name if is_python_runtime(name) => hermes_installer_agent_name(argv)+ .or_else(|| script_arg_agent_name(argv, &["-c"], &["-m"])),"sh" | "bash" | "zsh" | "fish" => script_arg_agent_name(argv, &["-c"], &[]),"cmd" => windows_cmd_arg_agent_name(argv),"powershell" | "pwsh" => powershell_arg_agent_name(argv),@@ -429,6 +430,61 @@ fn wrapped_agent_name_from_runtime_argv(runtime: &str, argv: Option<&[String]>)}}+fn hermes_installer_agent_name(argv: &[String]) -> Option<String> {+ let [_, isolation, command, code, args @ ..] = argv else {+ return None;+ };+ if isolation != "-I"+ || command != "-c"+ || args+ .first()+ .is_some_and(|arg| matches!(arg.as_str(), "--run-module" | "--print-runtime-command"))+ {+ return None;+ }++ // Recognize the captured installer bootstrap, not arbitrary Python source.+ // Both root literals must agree; reject escapes or quotes rather than parse Python.+ let rest = code.strip_prefix(HERMES_INSTALLER_PREFIX)?;+ let (root, rest) = rest.split_once("')\n")?;+ if root.is_empty() || root.contains(['\'', '\\', '\n', '\r']) {+ return None;+ }+ let rest = rest+ .strip_prefix(HERMES_INSTALLER_MIDDLE)?+ .strip_prefix(root)?;+ (rest == HERMES_INSTALLER_SUFFIX).then(|| agent_label(Agent::Hermes).to_string())+}++// Installer source captured in #4910. Only the installation root varies. Unknown+// bootstrap revisions deliberately fall back to ordinary process identification.+const HERMES_INSTALLER_PREFIX: &str = "import os, re, sys+os.environ.pop('PYTHONHOME', None)+os.environ.pop('PYTHONPATH', None)+sys.path.insert(0, '";+const HERMES_INSTALLER_MIDDLE: &str =+ "if sys.argv[1:2] == ['--print-runtime-command']: sys.dont_write_bytecode = True+from hermes_constants import get_default_hermes_root+os.environ['HERMES_HOME'] = os.environ.get('HERMES_HOME') or str(get_default_hermes_root())+if sys.argv[1:2] == ['--print-runtime-command']:+ from pathlib import Path+ from hermes_cli._launchers import print_runtime_command+ print_runtime_command(Path('";+const HERMES_INSTALLER_SUFFIX: &str = r"'), sys.argv[2:])+ sys.exit(0)+import hermes_bootstrap+if sys.argv[1:2] == ['--run-module']:+ import runpy+ if len(sys.argv) < 3: sys.exit('hermes: --run-module needs a module')+ module = sys.argv.pop(2)+ del sys.argv[1]+ runpy.run_module(module, run_name='__main__', alter_sys=True)+ sys.exit(0)+from hermes_cli.main import main+sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])+sys.exit(main())+";+fn cursor_agent_name_from_bundled_node_argv(argv: &[String]) -> Option<String> {let (runtime_parent, runtime_name) = path_parent_and_basename(argv.first()?)?;let (script_parent, script_name) = path_parent_and_basename(argv.get(1)?)?;@@ -1368,6 +1424,107 @@ mod tests {);}+ fn hermes_installer_capture() -> crate::platform::ForegroundJob {+ // Exact reporter capture from #4910; private path components were redacted.+ let capture: serde_json::Value = serde_json::from_str(include_str!(+ "../../tests/fixtures/hermes-installer-process-info-4910.json"+ ))+ .unwrap();+ let info = &capture["result"]["process_info"];+ crate::platform::ForegroundJob {+ process_group_id: info["foreground_process_group_id"].as_u64().unwrap() as u32,+ processes: info["foreground_processes"]+ .as_array()+ .unwrap()+ .iter()+ .map(|process| crate::platform::ForegroundProcess {+ pid: process["pid"].as_u64().unwrap() as u32,+ name: process["name"].as_str().unwrap().to_string(),+ argv0: Some(process["argv0"].as_str().unwrap().to_string()),+ argv: Some(serde_json::from_value(process["argv"].clone()).unwrap()),+ cmdline: Some(process["cmdline"].as_str().unwrap().to_string()),+ })+ .collect(),+ }+ }++ #[test]+ fn identify_agent_in_job_detects_hermes_installer_capture() {+ let mut job = hermes_installer_capture();+ assert_eq!(+ identify_agent_in_job(&job),+ Some((Agent::Hermes, "hermes".to_string()))+ );+ // Pane probing also uses a leader-only fast path.+ job.processes+ .retain(|process| process.pid == job.process_group_id);+ assert_eq!(+ identify_agent_in_job(&job),+ Some((Agent::Hermes, "hermes".to_string()))+ );+ }++ #[test]+ fn hermes_installer_signature_allows_another_install_root() {+ let job = hermes_installer_capture();+ let mut argv = job.processes.last().unwrap().argv.clone().unwrap();+ argv[3] = argv[3].replace(+ "/Users/REDACTED/.hermes/hermes-agent",+ "/opt/another install/hermes-agent",+ );+ assert_eq!(hermes_installer_agent_name(&argv), Some("hermes".into()));+ }++ #[test]+ fn identify_agent_in_job_rejects_hermes_installer_helper_modes() {+ for mode in ["--run-module", "--print-runtime-command"] {+ let mut job = hermes_installer_capture();+ let argv = job.processes.last_mut().unwrap().argv.as_mut().unwrap();+ argv.truncate(4);+ argv.extend([mode.into(), "tui_gateway.entry".into()]);+ assert_eq!(identify_agent_in_job(&job), None, "{mode}");+ }+ }++ #[test]+ fn hermes_installer_signature_rejects_incidental_source_and_unsafe_roots() {+ let job = hermes_installer_capture();+ let mut argv = job.processes.last().unwrap().argv.clone().unwrap();+ let original = argv[3].clone();+ for code in [+ "print('hermes_cli.main')".to_string(),+ format!("'''{original}'''"),+ original.lines().map(|line| format!("# {line}\n")).collect(),+ original.replace("/Users/REDACTED", "/Users/has'quote"),+ original.replace("/Users/REDACTED", r"/Users/has\escape"),+ original.replacen("/Users/REDACTED", "/different/root", 1),+ ] {+ argv[3] = code;+ assert_eq!(hermes_installer_agent_name(&argv), None);+ }+ }++ #[test]+ fn identify_agent_in_job_rejects_hermes_source_outside_installer_invocation() {+ for prefix in [+ vec!["python3", "-m", "module"],+ vec!["python3", "--", "script.py"],+ vec!["python3", "script.py"],+ vec!["bash", "-I"],+ ] {+ let mut job = hermes_installer_capture();+ let process = job.processes.last_mut().unwrap();+ let argv = process.argv.as_mut().unwrap();+ let source = argv[3].clone();+ *argv = prefix.iter().map(|arg| (*arg).to_string()).collect();+ argv.extend(["-c".into(), source]);+ process.name = prefix[0].into();+ process.argv0 = Some(prefix[0].into());+ process.cmdline = Some(argv.join(" "));+ assert_eq!(identify_agent_in_job(&job), None, "{prefix:?}");+ }+ }+#[test]fn identify_agent_in_job_detects_python_version_wrapped_hermes() {let job = crate::platform::ForegroundJob {diff --git a/tests/fixtures/hermes-installer-process-info-4910.json b/tests/fixtures/hermes-installer-process-info-4910.jsonnew file mode 100644index 000000000..a4f11100c--- /dev/null+++ b/tests/fixtures/hermes-installer-process-info-4910.json@@ -0,0 +1 @@+{"id":"cli:pane:process_info","result":{"process_info":{"foreground_process_group_id":30455,"foreground_processes":[{"argv":["/Users/REDACTED/.hermes/tools/python-3.14.7+20260901-darwin-arm64/bin/python3","-m","tui_gateway.entry"],"argv0":"python3","cmdline":"/Users/REDACTED/.hermes/tools/python-3.14.7+20260901-darwin-arm64/bin/python3 -m tui_gateway.entry","cwd":"/Users/REDACTED/work/repro","name":"python3.14","pid":30781},{"argv":["/Users/REDACTED/.hermes/tools/node-26.7.0-darwin-arm64/bin/node","--expose-gc","/Users/REDACTED/.hermes/hermes-agent/ui-tui/dist/entry.js"],"argv0":"node","cmdline":"/Users/REDACTED/.hermes/tools/node-26.7.0-darwin-arm64/bin/node --expose-gc /Users/REDACTED/.hermes/hermes-agent/ui-tui/dist/entry.js","cwd":"/Users/REDACTED/.hermes/hermes-agent/ui-tui","name":"node","pid":30778},{"argv":["/Users/REDACTED/.hermes/tools/python-3.14.7+20260901-darwin-arm64/bin/python3","-I","-c","import os, re, sys\nos.environ.pop('PYTHONHOME', None)\nos.environ.pop('PYTHONPATH', None)\nsys.path.insert(0, '/Users/REDACTED/.hermes/hermes-agent')\nif sys.argv[1:2] == ['--print-runtime-command']: sys.dont_write_bytecode = True\nfrom hermes_constants import get_default_hermes_root\nos.environ['HERMES_HOME'] = os.environ.get('HERMES_HOME') or str(get_default_hermes_root())\nif sys.argv[1:2] == ['--print-runtime-command']:\n from pathlib import Path\n from hermes_cli._launchers import print_runtime_command\n print_runtime_command(Path('/Users/REDACTED/.hermes/hermes-agent'), sys.argv[2:])\n sys.exit(0)\nimport hermes_bootstrap\nif sys.argv[1:2] == ['--run-module']:\n import runpy\n if len(sys.argv) < 3: sys.exit('hermes: --run-module needs a module')\n module = sys.argv.pop(2)\n del sys.argv[1]\n runpy.run_module(module, run_name='__main__', alter_sys=True)\n sys.exit(0)\nfrom hermes_cli.main import main\nsys.argv[0] = re.sub(r'(-script\\.pyw|\\.exe)?$', '', sys.argv[0])\nsys.exit(main())\n","--profile","sdlc-planner","--skills","grill-with-docs"],"argv0":"python3","cmdline":"/Users/REDACTED/.hermes/tools/python-3.14.7+20260901-darwin-arm64/bin/python3 -I -c import os, re, sys\nos.environ.pop('PYTHONHOME', None)\nos.environ.pop('PYTHONPATH', None)\nsys.path.insert(0, '/Users/REDACTED/.hermes/hermes-agent')\nif sys.argv[1:2] == ['--print-runtime-command']: sys.dont_write_bytecode = True\nfrom hermes_constants import get_default_hermes_root\nos.environ['HERMES_HOME'] = os.environ.get('HERMES_HOME') or str(get_default_hermes_root())\nif sys.argv[1:2] == ['--print-runtime-command']:\n from pathlib import Path\n from hermes_cli._launchers import print_runtime_command\n print_runtime_command(Path('/Users/REDACTED/.hermes/hermes-agent'), sys.argv[2:])\n sys.exit(0)\nimport hermes_bootstrap\nif sys.argv[1:2] == ['--run-module']:\n import runpy\n if len(sys.argv) < 3: sys.exit('hermes: --run-module needs a module')\n module = sys.argv.pop(2)\n del sys.argv[1]\n runpy.run_module(module, run_name='__main__', alter_sys=True)\n sys.exit(0)\nfrom hermes_cli.main import main\nsys.argv[0] = re.sub(r'(-script\\.pyw|\\.exe)?$', '', sys.argv[0])\nsys.exit(main())\n --profile sdlc-planner --skills grill-with-docs","cwd":"/Users/REDACTED/work/repro","name":"python3.14","pid":30455}],"pane_id":"w1N:p6","shell_pid":28709},"type":"pane_process_info"}}