Skip to content

The agent that grows with you

fix(hooks): in-memory launch consent ends with the config entry; refused entries don't suspend removal

kshitijk4poor8b9ac5773ea0
diff --git a/agent/shell_hooks.py b/agent/shell_hooks.py
index eb22d325434..d4b51fe32e7 100644
--- a/agent/shell_hooks.py
+++ b/agent/shell_hooks.py
@@ -213,6 +213,9 @@ def sync_from_config(load_cfg: Callable[[], dict[str, Any]]) -> None:
"fixed", "the allowlist is unreadable" if not readable
else "a hooks: entry in config.yaml is malformed")
return
+ # In-memory consent ends with the hook's config entry, so a removed-and-re-added hook asks again.
+ configured = {(home_key, spec.event, spec.command) for spec in specs}
+ _launch_consent.difference_update({c for c in _launch_consent if c[0] == home_key and c not in configured})
keep = {_key(home_key, spec) for spec in wanted}
stale = {k for k in _registered if k[0] == home_key and k not in keep}
_registered.difference_update(stale)
@@ -369,8 +372,7 @@ def _parse_hooks(hooks_cfg: Any) -> tuple[list[ShellHookSpec], bool]:
if event_name in SHELL_UNSUPPORTED_HOOKS: # _parse_response has no channel for these directives — refuse loudly
logger.warning("hook event %r is Python-plugin-only: shell hooks cannot return its directive, "
"so this registration is refused rather than silently ignored", event_name)
- complete = False
- continue
+ continue # well-formed and deliberate: refused, but not a typo that should suspend removal
if event_name not in VALID_HOOKS:
suggestion = difflib.get_close_matches(str(event_name), VALID_HOOKS, n=1, cutoff=0.6)
if suggestion:
diff --git a/tests/gateway/test_shell_hook_resync.py b/tests/gateway/test_shell_hook_resync.py
index 42c5af68660..a59ec91c078 100644
--- a/tests/gateway/test_shell_hook_resync.py
+++ b/tests/gateway/test_shell_hook_resync.py
@@ -177,6 +177,28 @@ def test_saved_launch_approval_stays_revocable_and_bad_records_are_skipped(home,
assert _wired() == [f"shell_hook[pre_tool_call:{b}]"]
+def test_unsaved_launch_consent_ends_with_the_config_entry(home, tmp_path, monkeypatch):
+ a = _script(tmp_path, "a.sh")
+ with monkeypatch.context() as unwritable:
+ unwritable.setattr(shell_hooks, "atomic_json_write", lambda *a, **k: (_ for _ in ()).throw(OSError("ro")))
+ shell_hooks.accept_for_launch(_cfg(a))
+ shell_hooks.sync_from_config(lambda: _cfg(a))
+ assert _wired() == [f"shell_hook[pre_tool_call:{a}]"]
+ shell_hooks.sync_from_config(lambda: {"hooks": {}}) # removed from config.yaml
+ shell_hooks.sync_from_config(lambda: _cfg(a)) # added back: needs consent again
+ assert _wired() == []
+
+
+def test_refused_plugin_only_entry_does_not_suspend_removal(home, tmp_path):
+ a = _script(tmp_path, "a.sh")
+ shell_hooks.register_from_config(_cfg(a), accept_hooks=True)
+ shell_hooks.revoke(a)
+ cfg = _cfg(a)
+ cfg["hooks"]["transform_api_error_classification"] = [{"command": a}]
+ shell_hooks.sync_from_config(lambda: cfg)
+ assert _wired() == []
+
+
def test_register_never_reasks_for_a_wired_hook(home, tmp_path, monkeypatch):
a = _script(tmp_path, "a.sh")
shell_hooks.register_from_config(_cfg(a), accept_hooks=True)
diff --git a/website/docs/user-guide/features/hooks.md b/website/docs/user-guide/features/hooks.md
index 3d17cd9148e..124926c6a44 100644
--- a/website/docs/user-guide/features/hooks.md
+++ b/website/docs/user-guide/features/hooks.md
@@ -2016,7 +2016,7 @@ Three escape hatches bypass the interactive prompt — any one is sufficient:
2. `HERMES_ACCEPT_HOOKS=1` environment variable
3. `hooks_auto_accept: true` in `~/.hermes/config.yaml`
-Non-TTY runs (gateway, cron, CI) need one of these three — otherwise any newly-added hook silently stays un-registered and logs a warning.
+Non-TTY runs (gateway, cron, CI) need one of these three — otherwise any newly-added hook silently stays un-registered and logs a warning. `hermes gateway run --accept-hooks` (like `HERMES_ACCEPT_HOOKS=1` on the gateway) approves the hooks of every profile that gateway serves, including hooks added after it started.
**Script edits are silently trusted.** The allowlist keys on the exact command string, not the script's hash, so editing the script on disk does not invalidate consent. `hermes hooks doctor` flags mtime drift so you can spot edits and decide whether to re-approve.