The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
docs(plugins): describe pre_command's per-delivery thread and Ink's command.observe
unsupportedpastels6928c538f998
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.tsindex cb774dce133..f2ae60c691c 100644--- a/apps/shared/src/gateway-contract.generated.ts+++ b/apps/shared/src/gateway-contract.generated.ts@@ -6690,7 +6690,7 @@ export interface CanonicalRpcMethods {'bot_relay.deliver': { params: CanonicalBotDeliverParams; result: CanonicalBotDeliverResult }/** Generation-fenced answer to a pending clarify prompt (empty answer = skipped). */'clarify.respond': { params: ClarifyRespondParams; result: PromptResponseResult }- /** Fire-only: a recognized command the classic CLI runs in its own process; the gateway fires `pre_command` for it in the session's profile after replying (`queued` false: not fired). */+ /** Fire-only: a recognized command the classic CLI or the TUI runs itself; the gateway fires `pre_command` for it in the session's profile after replying (`queued` false: not fired). */'command.observe': { params: CommandObserveParams; result: CommandObserveResult }'config.get': { params: ConfigGetParams; result: CanonicalConfigGetResult }'config.set': { params: CanonicalConfigSetParams; result: ConfigSetResult }diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.jsonindex 03b89d25563..77f125b52fa 100644--- a/apps/shared/src/gateway-contract.openrpc.json+++ b/apps/shared/src/gateway-contract.openrpc.json@@ -46741,7 +46741,7 @@},{"name": "command.observe",- "summary": "Fire-only: a recognized command the classic CLI runs in its own process; the gateway fires `pre_command` for it in the session's profile after replying (`queued` false: not fired).",+ "summary": "Fire-only: a recognized command the classic CLI or the TUI runs itself; the gateway fires `pre_command` for it in the session's profile after replying (`queued` false: not fired).","params": [{"name": "params",diff --git a/gateway/session_commands.py b/gateway/session_commands.pyindex 67f84f69b02..1910265a006 100644--- a/gateway/session_commands.py+++ b/gateway/session_commands.py@@ -312,9 +312,9 @@ async def _pre_command_before(authority, ref, canonical, alias, arg):async def observe_command(connection, ref, params):- """``command.observe``: a recognized command the classic CLI runs in its own process on this- session. ``pre_command`` fires here, in the session's profile, after the reply: the CLI never waits- on a plugin and never loads one. Plain data only (the command name as typed and its arguments)."""+ """``command.observe``: a recognized command the classic CLI or Ink runs itself on this session.+ ``pre_command`` fires here, in the session's profile, after the reply: the client never waits on a+ plugin and never loads one. Plain data only (the command name as typed and its arguments)."""from hermes_cli.commands import resolve_commandfrom hermes_cli.profiles import profile_matches_homeauthority, actor = connection.authority, connection.actordiff --git a/tests/gateway/test_pre_command_in_gateway.py b/tests/gateway/test_pre_command_in_gateway.pyindex 628a6a197ad..8c8d0c881b9 100644--- a/tests/gateway/test_pre_command_in_gateway.py+++ b/tests/gateway/test_pre_command_in_gateway.py@@ -480,7 +480,7 @@ def test_only_the_escape_hatches_skip_pre_command_during_a_turn(monkeypatch, stadef test_a_hung_pre_command_callback_is_bounded_and_each_session_keeps_its_order(monkeypatch):"""``pre_command`` runs through the hook dispatcher's bounded path (``plugins.hook_callback_timeout``,- abandoned worker, suppression), on the gateway's own observer workers, never the loop's shared+ abandoned worker, suppression), each delivery on a thread of its own, never the loop's sharedexecutor. A callback that hangs for session A's first command: session B's observers run at once,A's next command waits only for the bound and skips the still-running callback (never overlappingor reordering it), later commands skip it, no extra worker piles up, and a session's backlog is capped."""diff --git a/tui_gateway/contracts/canonical.py b/tui_gateway/contracts/canonical.pyindex eefe6973a0d..e36623ee1d1 100644--- a/tui_gateway/contracts/canonical.py+++ b/tui_gateway/contracts/canonical.py@@ -138,7 +138,7 @@ class CommandObserveResult(Result):canonical_method("command.observe", params=CommandObserveParams, result=CommandObserveResult,- doc="Fire-only: a recognized command the classic CLI runs in its own process; the gateway fires "+ doc="Fire-only: a recognized command the classic CLI or the TUI runs itself; the gateway fires ""`pre_command` for it in the session's profile after replying (`queued` false: not fired).")diff --git a/website/docs/user-guide/features/hooks.md b/website/docs/user-guide/features/hooks.mdindex c63e3fcb26e..405677ed4fe 100644--- a/website/docs/user-guide/features/hooks.md+++ b/website/docs/user-guide/features/hooks.md@@ -478,7 +478,7 @@ Payload fields below are the exact event-specific fields supplied by each call s| `pre_gateway_dispatch` | Directive/control | Once per incoming non-internal message, at ingress: platform-adapter messages before auth/pairing/dispatch; webhook and relay deliveries after their authorization, before the admission commits; never for local CLI/TUI/Desktop or API turns, a retry of a committed delivery, or a queued admission when it executes. First valid `skip`, `rewrite`, or `allow` controls flow. | `event`, `gateway`, `session_store` | Extremely privileged in-process objects expose inbound user/routing data and host handles. || `post_gateway_admission` | Directive/control (fail-open) | Admitted non-internal message after auth, pause/drain, pending-reply, running-session and slash-command lanes, inside the claimed session slot and the routed profile's scope; first `handled` result skips the agent turn, anything else (including a raise or timeout) runs it. | `session_key`, `platform`, `source` (dict snapshot), `message_id`, `text` | Inbound text is untrusted user data; no runner or session-store handles are passed. || `gateway_platform_event` | Observer | After the gateway's profile-scoped authorization succeeds, when a supported platform-native event is normalized at the gateway boundary (Telegram: reactions, message edits; Discord: message edits/deletes, thread created/renamed); return ignored. | `platform`, `event_type`, `payload` (event-type-specific dict — see the per-event contracts below) | Normalized plain-dict envelope only; raw SDK objects, adapter handles, and bot clients are never exposed. |-| `pre_command` | Observer | Recognized slash command about to be dispatched, before the handler runs, on CLI and gateway cold-path dispatch; return ignored in v1 (directive-shaped dicts are logged at debug). A command the classic CLI, TUI or Desktop sends to the gateway fires it once, in the gateway, with `surface` and `platform` both `"cli"` as before (Ink and Desktop fired it through the CLI slash worker) and `session_key` the session id; a recognized command the classic CLI or the TUI answers itself is reported to the gateway (`command.observe`), which fires it there after replying, so neither loads plugin code. A gateway older than the client fires no hook for those commands (the classic CLI prints a one-time notice). Desktop's own pickers, actions and dedicated RPCs (commands it answers without `slash.exec`) fire nothing yet. During a local session's turn every command that still runs fires it except `/stop`, `/approve` and `/deny`; a command that is refused (rejected while busy, or named as unavailable on the gateway) fires nothing. Each callback is timeout-bounded (`plugins.hook_callback_timeout`) and runs on the gateway's own observer workers; one session's commands reach it in order, and a callback still running for that session (hung) is skipped for its later commands instead of running out of order, without holding up other sessions. Gateway running-agent intercept commands (`/stop`, `/approve` during an active run) are deliberately excluded — control-plane escape hatches must stay outside plugin reach. | `surface` (`"cli"` \| `"gateway"`), `command` (canonical name), `alias_used`, `args_raw`, `session_key`, `platform` | `args_raw` may contain user content or secrets typed after the command. |+| `pre_command` | Observer | Recognized slash command about to be dispatched, before the handler runs, on CLI and gateway cold-path dispatch; return ignored in v1 (directive-shaped dicts are logged at debug). A command the classic CLI, TUI or Desktop sends to the gateway fires it once, in the gateway, with `surface` and `platform` both `"cli"` as before (Ink and Desktop fired it through the CLI slash worker) and `session_key` the session id; a recognized command the classic CLI or the TUI answers itself is reported to the gateway (`command.observe`), which fires it there after replying, so neither loads plugin code. A gateway older than the client fires no hook for those commands (the classic CLI prints a one-time notice). Desktop's own pickers, actions and dedicated RPCs (commands it answers without `slash.exec`) fire nothing yet. During a local session's turn every command that still runs fires it except `/stop`, `/approve` and `/deny`; a command that is refused (rejected while busy, or named as unavailable on the gateway) fires nothing. Each callback is timeout-bounded (`plugins.hook_callback_timeout`); each delivery waits on a thread of its own, never a worker shared with other sessions or the event loop's executor. One session's commands reach it in order, and a callback still running for that session (hung) is skipped for its later commands instead of running out of order, without holding up other sessions. Gateway running-agent intercept commands (`/stop`, `/approve` during an active run) are deliberately excluded — control-plane escape hatches must stay outside plugin reach. | `surface` (`"cli"` \| `"gateway"`), `command` (canonical name), `alias_used`, `args_raw`, `session_key`, `platform` | `args_raw` may contain user content or secrets typed after the command. || `pre_approval_request` | Observer | Before prompted or smart approval; return ignored. | `command`, `description`, `pattern_key`, `pattern_keys`, `session_key`, `surface`, `turn_id`, `tool_call_id` | Command may contain secrets; smart observer preparation force-redacts, but surfaces do not all have identical redaction. || `post_approval_response` | Observer | After a decision, timeout, or gateway notification failure; return ignored. | `command`, `description`, `pattern_key`, `pattern_keys`, `session_key`, `surface`, `turn_id`, `tool_call_id`, `choice`; smart path may add `decided_by` | Same command sensitivity plus decision metadata. || `on_human_input_request` | Observer | The agent is about to block on a person — sudo password prompt, `clarify` question, or dangerous-command approval — on CLI, Ink TUI/Desktop, ACP and gateway platforms; return ignored. | `kind` (`"sudo"` \| `"clarify"` \| `"approval"`), `request_id`, `session_id`, `session_key`, `platform`, `prompt` | `prompt` is always force-redacted; the typed password or answer is never passed. |