Skip to content

The agent that grows with you

fix: use lookbehind anchor so binary-decoded and remote-read content still scans

Teknium20e308fea705
diff --git a/cron/lifecycle_guard.py b/cron/lifecycle_guard.py
index 6f41a42e172..a55f27055c7 100644
--- a/cron/lifecycle_guard.py
+++ b/cron/lifecycle_guard.py
@@ -64,13 +64,13 @@ _GATEWAY_LIFECYCLE_PATTERN = re.compile(
# `start` is intentionally excluded: starting a gateway from inside a
# gateway is benign (a no-op or "already running" error), and a
# legitimate cron job might start a sibling profile's gateway.
- # The leading separator class (#77173): `hermes` must sit at command
- # position — start of text, after whitespace/`;`/`&`/`|`, or inside a
- # substitution/subshell opener — not be a path component. Without it, a
- # file path with embedded spaces like `/docs/hermes gateway
- # restart-notes.md` matched via the `/hermes` tail and hard-blocked an
- # innocent `cat`.
- r"(?:(?:^|[\s;&|(`])hermes\s+gateway\s+(?:restart|stop)\b)"
+ # The lookbehind (#77173): `hermes` must not be a path component or a
+ # word tail. Excluding `/`, word chars, `.` and `-` keeps file paths
+ # with embedded spaces (`/docs/hermes gateway restart-notes.md`) from
+ # matching via the `/hermes` tail, while every real command position
+ # (start of text, whitespace, `;`/`&`/`|`, `$(`, backtick, even a
+ # U+FFFD from binary-content decoding) still matches.
+ r"(?:(?<![/\w.\-])hermes\s+gateway\s+(?:restart|stop)\b)"
# Branch B: launchctl ops on a hermes-gateway label. macOS launchd
# labels look like `ai.hermes.gateway` / `hermes-gateway`. Requiring the
# gateway identifier prevents blocking unrelated hermes services (e.g.
diff --git a/tests/hermes_cli/test_gateway_restart_loop.py b/tests/hermes_cli/test_gateway_restart_loop.py
index d62f50897da..96918cdf488 100644
--- a/tests/hermes_cli/test_gateway_restart_loop.py
+++ b/tests/hermes_cli/test_gateway_restart_loop.py
@@ -1404,7 +1404,7 @@ class TestTerminalToolGatewayLifecycleGuardRemote:
def execute(self, command, **kwargs):
calls.append(command)
if "head -c" in command and "/remote/workspace/remote.sh" in command:
- return {"output": "#!/bin/bash\\nhermes gateway restart\\n", "returncode": 0}
+ return {"output": "#!/bin/bash\nhermes gateway restart\n", "returncode": 0}
return {"output": "", "returncode": 0}
fake_env = _RemoteEnv()