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

The separator-class anchor broke two fail-closed tests (binary bytes
decode to U+FFFD adjacent to the CLI name; remote head-c reads). A
negative lookbehind excluding path/word chars keeps the #77173 fix
while preserving every fail-closed content-scan path.
This commit is contained in:
Teknium
2026-08-23 16:44:08 -07:00
parent ec169b4885
commit 20e308fea7
2 changed files with 8 additions and 8 deletions
+7 -7
View File
@@ -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.
@@ -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()