Files
hermes-agent/hermes_cli/subcommands/hooks.py
Teknium 5a18d0f5f4 fix(gateway): register a shell hook once its consent is recorded, without a restart
A non-TTY gateway skips a configured shell hook that has no consent yet. Recording consent
later (CLI prompt, `hermes hooks` revoke, the dashboard, an edited allowlist) only took
effect when a local session opened or the gateway restarted, so a messaging-only gateway
ran tool calls unguarded past a `fail_closed: true` pre_tool_call hook until restart.
The multiplex re-scan watched config.yaml and .env only and never covered the launch
profile; single-profile gateways had no re-check at all.

The 30 s profile watcher now runs on every gateway and, per home (launch + served), re-runs
`sync_from_config` under that home's scope when its shell-hooks-allowlist.json signature
changes: consent registers the hook, revocation unregisters it. It re-runs hook
registration only (idempotent via the per-home registry), never the adapter rebuild,
so no adapter or session is touched by a consent change.

Fixes #132993

Co-authored-by: liuhao1024 <sunsky.lau@gmail.com>
2026-10-18 03:24:34 -07:00

46 lines
2.0 KiB
Python

"""``hermes hooks`` subcommand parser."""
from __future__ import annotations
from typing import Callable
def build_hooks_parser(subparsers, *, cmd_hooks: Callable) -> None:
"""Attach the ``hooks`` subcommand to ``subparsers``."""
hooks_parser = subparsers.add_parser(
"hooks", help="Inspect and manage shell-script hooks",
description="Inspect shell-script hooks declared in ~/.hermes/config.yaml, "
"test them against synthetic payloads, and manage the first-use "
"consent allowlist at ~/.hermes/shell-hooks-allowlist.json.")
hooks_subparsers = hooks_parser.add_subparsers(dest="hooks_action")
hooks_subparsers.add_parser(
"list", aliases=["ls"],
help="List configured hooks with matcher, timeout, and consent status")
_hk_test = hooks_subparsers.add_parser(
"test", help="Fire every hook matching <event> against a synthetic payload")
_hk_test.add_argument(
"event", help="Hook event name (e.g. pre_tool_call, pre_llm_call, subagent_stop)")
_hk_test.add_argument(
"--for-tool", dest="for_tool", default=None,
help="Only fire hooks whose matcher matches this tool name "
"(used for pre_tool_call / post_tool_call)")
_hk_test.add_argument(
"--payload-file", dest="payload_file", default=None,
help="Path to a JSON file whose contents are merged into the "
"synthetic payload before execution")
_hk_revoke = hooks_subparsers.add_parser(
"revoke", aliases=["remove", "rm"],
help="Remove a command's allowlist entries (a running gateway drops it within about 30 seconds)")
_hk_revoke.add_argument(
"command", help="The exact command string to revoke (as declared in config.yaml)")
hooks_subparsers.add_parser(
"doctor",
help="Check each configured hook: exec bit, allowlist, mtime drift, "
"JSON validity, and synthetic run timing")
hooks_parser.set_defaults(func=cmd_hooks)