Fire matching hook commands with `payload` serialized as JSON on stdin. The `event` name is automatically injected into the payload under the `"event"` key so callers don't need to duplicate it. The blocking subprocess work is offloaded to a thread so the caller's event loop is nev
(event: str, payload: dict[str, Any])
| 159 | |
| 160 | |
| 161 | async def dispatch_hook(event: str, payload: dict[str, Any]) -> None: |
| 162 | """Fire matching hook commands with `payload` serialized as JSON on stdin. |
| 163 | |
| 164 | The `event` name is automatically injected into the payload under the |
| 165 | `"event"` key so callers don't need to duplicate it. |
| 166 | |
| 167 | The blocking subprocess work is offloaded to a thread so the caller's |
| 168 | event loop is never stalled. Matching hooks run concurrently, each with |
| 169 | a 5-second timeout. Errors are logged and never propagated. |
| 170 | |
| 171 | Args: |
| 172 | event: Dotted event name (e.g. `'session.start'`). |
| 173 | payload: Arbitrary JSON-serializable dict sent on the command's stdin. |
| 174 | """ |
| 175 | try: |
| 176 | hooks = _load_hooks() |
| 177 | if not hooks: |
| 178 | return |
| 179 | |
| 180 | payload_bytes = json.dumps({"event": event, **payload}).encode() |
| 181 | await asyncio.to_thread(_dispatch_hook_sync, event, payload_bytes, hooks) |
| 182 | except Exception: |
| 183 | logger.warning( |
| 184 | "Unexpected error in dispatch_hook for event %s", |
| 185 | event, |
| 186 | exc_info=True, |
| 187 | ) |
| 188 | |
| 189 | |
| 190 | def dispatch_hook_fire_and_forget(event: str, payload: dict[str, Any]) -> None: |
no test coverage detected
searching dependent graphs…