The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): a wrapped inner hermes launcher must be this root's
Teknium3e39fa42c361
diff --git a/hermes_cli/gateway_runtime_service_identity.py b/hermes_cli/gateway_runtime_service_identity.pyindex 14ef3928f79..32772c85913 100644--- a/hermes_cli/gateway_runtime_service_identity.py+++ b/hermes_cli/gateway_runtime_service_identity.py@@ -77,7 +77,17 @@ def _launch_module(argv: list[str]) -> tuple[str, list[str]] | None:return None-def verify_gateway_argv(argv: list[str], home: Path) -> None:+def _own_store_launcher(executable: str) -> bool:+ from hermes_cli import gateway+ launcher = Path(gateway.PROJECT_ROOT).resolve() / ".hermes" / "bin" / "hermes"+ return os.path.normcase(str(Path(executable).resolve())) == os.path.normcase(str(launcher))+++def verify_gateway_argv(argv: list[str], home: Path, *, wrapped: bool = False) -> None:+ """``wrapped``: a launcher wrapper was already stripped. A ``hermes`` launcher a wrapper runs must be+ the one ``installation_command`` writes for THIS root (``<root>/.hermes/bin/hermes``), never another+ checkout's. A bare unwrapped ``hermes`` keeps verifying by name, as older systemd/schtasks/launchd+ definitions persisted it; a wrapped ``python`` is held to ``_launch_module`` as before."""from gateway.status import looks_like_gateway_command_line# The installer wraps launchd stderr with this fixed, non-shell module.@@ -86,7 +96,7 @@ def verify_gateway_argv(argv: list[str], home: Path) -> None:args = wrapper[1]if len(args) < 4 or args[0] != "--error-log" or args[2] != "--":_unverified()- argv = args[3:]+ argv, wrapped = args[3:], Trueif not argv or not looks_like_gateway_command_line(subprocess_command(argv)):_unverified()executable = Path(argv[0]).name.lower()@@ -95,7 +105,7 @@ def verify_gateway_argv(argv: list[str], home: Path) -> None:if entry is None or entry[0] != "hermes_cli.main":_unverified()args = entry[1]- elif executable in {"hermes", "hermes.exe"}:+ elif executable in {"hermes", "hermes.exe"} and (not wrapped or _own_store_launcher(argv[0])):args = argv[1:]else:_unverified()@@ -202,6 +212,11 @@ _LAUNCHD_JXA = re.compile(r'\$\.exit\(status === -1 \? 1 : signal === 0 \? \(status >> 8\) & 255 : 128 \+ signal\);')+def _verify_launchd_argv(argv: list[str], home: Path) -> None:+ command = _launchd_command(argv)+ verify_gateway_argv(command, home, wrapped=command is not argv)++def _launchd_command(argv: list[str]) -> list[str]:if argv[:1] != ["/usr/bin/osascript"]:return argv@@ -249,7 +264,7 @@ def verify_launchd_loaded(output: str, home: Path, *, uid: int, username: str) -programs = re.findall(r"^\tprogram = (.+)$", output, re.MULTILINE)if len(programs) != 1 or not argv or programs[0] != argv[0]:_unverified()- verify_gateway_argv(_launchd_command(argv), home)+ _verify_launchd_argv(argv, home)def verify_launchd_plist(definition: dict, label: str, home: Path) -> None:@@ -268,7 +283,7 @@ def verify_launchd_plist(definition: dict, label: str, home: Path) -> None:_unverified()if definition.get("Program", argv[0] if argv else None) != (argv[0] if argv else None):_unverified()- verify_gateway_argv(_launchd_command(argv), home)+ _verify_launchd_argv(argv, home)if home.parent.name != "profiles" and not env.get("HERMES_SUPERVISED_CHILD"):_unverified()diff --git a/tests/hermes_cli/test_gateway_runtime_service.py b/tests/hermes_cli/test_gateway_runtime_service.pyindex 14e1c81f1a9..50c685d1ab9 100644--- a/tests/hermes_cli/test_gateway_runtime_service.py+++ b/tests/hermes_cli/test_gateway_runtime_service.py@@ -156,6 +156,8 @@ def _launchd_gateway_command(tmp_path, monkeypatch, *, store, profile=""):("other_run_module", "service_identity_unverified"),("foreign_root_store", "service_identity_unverified"), ("foreign_root_inline", "service_identity_unverified"),("other_home", "foreign_root"), ("osascript_non_gateway", "service_identity_unverified"),+ ("own_wrapper_foreign_inner", "service_identity_unverified"),+ ("osascript_foreign_bare", "service_identity_unverified"),])def test_launchd_verifies_the_osascript_wrapped_command_the_installer_writes(case, reason, tmp_path, monkeypatch):"""The Local Network wrapper (#71206) is unwrapped only as its exact template, and the command inside@@ -174,6 +176,16 @@ def test_launchd_verifies_the_osascript_wrapped_command_the_installer_writes(casmonkeypatch.setattr(gw, "PROJECT_ROOT", tmp_path / "other-checkout")command = _timestamped_stderr_gateway_command(tmp_path / "logs" / "gateway.error.log", external_supervisor=True)monkeypatch.setattr(gw, "PROJECT_ROOT", root)+ if case in {"own_wrapper_foreign_inner", "osascript_foreign_bare"}:+ # The installer's own gateway command for ANOTHER checkout: inside OUR stderr wrapper, or bare+ # inside the Local Network wrapper. Neither is a launcher this install root writes.+ from hermes_cli._launchers import installation_command+ foreign = installation_command(tmp_path / "other-checkout", ["gateway", "run", "--external-supervisor"],+ python=sys.executable)+ assert Path(foreign[0]).name == "hermes"+ command = foreign if case == "osascript_foreign_bare" else installation_command(+ gw.PROJECT_ROOT, ["--error-log", str(tmp_path / "logs" / "gateway.error.log"), "--", *foreign],+ module="hermes_cli.stderr_timestamp", python=sys.executable)if case == "osascript_non_gateway":command = ["/bin/sh", "-c", "id"]if case == "tampered_bootstrap":