Skip to content

fix(tui_gateway): register shell hooks at desktop/TUI startup - #43826

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/shell-hooks-tui-registration
Closed

fix(tui_gateway): register shell hooks at desktop/TUI startup#43826
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/shell-hooks-tui-registration

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Registers declarative shell hooks (config.yaml hooks: entries) at TUI/desktop startup, fixing a security gap where pre_tool_call blocking hooks were silently ignored in the desktop app.

Related Issue

Fixes #43823

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • tui_gateway/entry.py: Added register_from_config(load_config(), accept_hooks=False) call in main(), wrapped in try/except to never block TUI startup. Matches the existing pattern in gateway/run.py:4500-4508.
  • tests/tui_gateway/test_shell_hooks_registration.py: Added 2 tests — (1) register_from_config is called with accept_hooks=False, (2) registration failure does not block startup.

How to Test

  1. Add a shell hook to config.yaml:
    hooks:
      pre_tool_call:
        - matcher: "terminal"
          command: "echo blocked"
          timeout: 5
    hooks_auto_accept: true
  2. Start hermes --tui, send a prompt that triggers a terminal tool call.
  3. Verify the hook fires (check agent.log for "shell hook" entries).
  4. Without this fix, the hook is silently skipped in the desktop/TUI.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Code Intelligence

  • Analyzed: tui_gateway/entry.py::main() — entry point for desktop/TUI JSON-RPC server
  • Blast radius: LOW — adds a single registration call with exception guard; no existing behavior changed
  • Related patterns: entry-point parity gap (cli.py:943, gateway/run.py:4502 both call register_from_config; tui_gateway was the missing surface)

register_from_config() is called at CLI startup (cli.py, main.py) and
gateway startup (gateway/run.py) but never from tui_gateway/entry.py.
This means declarative shell hooks (e.g. pre_tool_call blocking) are
silently ignored in the desktop app / TUI — users configure security
hooks, see no error, and believe they are protected when they are not.

Add the same try/except-wrapped register_from_config() call to
tui_gateway/entry.py::main(), matching the gateway pattern with
accept_hooks=False so consent is resolved from hooks_auto_accept or
HERMES_ACCEPT_HOOKS env var.

Fixes NousResearch#43823
@alt-glitch alt-glitch added type/bug Something isn't working comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Jun 10, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #13854 — same fix (register shell hooks at tui_gateway startup). #13854 is the earliest open canonical; competing #34112/#41464; #43828 is an identical same-batch twin. Fixes #43823.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Closing in favor of #13854 by @witt3rd, which is the earliest open canonical fix for the same issue (register shell hooks at tui_gateway startup). #13854 has a more structured implementation (+108 lines, extracted _register_shell_hooks() function + 2 regression tests).

Both PRs address the same security gap: pre_tool_call blocking hooks from config.yaml hooks: are silently ignored in Desktop/TUI sessions because register_from_config() was never called in tui_gateway/entry.py::main().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Shell hooks (config.yaml hooks:) are never registered in the desktop TUI entry point

2 participants