Skip to main content

Module hook_emit

Module hook_emit 

Source
Expand description

Cross-process hook activity emit.

Why: Claude Code’s hook commands (UserPromptSubmitprompt-context, SessionStartinbox-check) run as ephemeral CLI subprocesses, not inside the long-lived daemon. They cannot call state.emit directly because they hold no AppState. Prior to this module they had no way to populate the activity feed, which led directly to the user complaint “the TUI activity feed is always empty in a normal Claude Code session” — because in a normal session the only daemon traffic is hooks, and hooks emitted nothing.

What: this module exposes post_hook_event — a best-effort async helper that resolves the running daemon’s HTTP address via trusty_common::read_daemon_addr and POSTs the hook payload to POST /api/v1/activity/hook. Failures are swallowed (warn-logged to stderr) so the hook never fails because of a missing or unresponsive daemon — that contract matches the prompt-context handler’s “always exit 0” rule. The receiving daemon side lives in web.rs and forwards the payload to state.emit(DaemonEvent::HookFired { … }).

Test: post_hook_event_no_daemon_is_noop (the no-daemon branch); the live-daemon round trip is covered in the prompt-context / inbox-check integration tests.

Structs§

HookEventPayload
JSON payload posted to POST /api/v1/activity/hook.

Constants§

HOOK_EVENT_PATH
HTTP path for the hook ingestion endpoint.

Functions§

post_hook_event
Post a hook event to the running daemon, best-effort.