M7: json + rpc modes, subprocess extensions (closes #52 #53 #54)
ci / check (pull_request) Canceled after 0s
ci / check (push) Canceled after 0s

This commit is contained in:
hermes committed 2026-09-30 21:40:20 +00:00
1 parent cf8268d17b
commit a01d0cbb5b
15 files changed
+723 -3

No files matched your search

+40
View File
@@ -116,3 +116,43 @@ poor proxy (context7: 2 tools, 1.1k tokens), the eager rule is schema size, not
`hx mcp-serve` runs hx as a stdio MCP server exposing the `lsp` tool (diagnostics, definition, references,
hover, symbols) to other clients.
## Machine interfaces
### Event stream (`hx -p "..." --mode json`)
One JSON object per line on stdout. `type` is one of:
| type | fields |
|---|---|
| `session_start`, `turn_start`, `turn_end`, `agent_end` | none |
| `stream` | `event`: `{type: "text_delta", text}` · `{type: "thinking_delta", text}` · `{type: "tool_use_start", id, name}` · `{type: "done", message, stop, usage}` |
| `message` | `message`: `{role, content: [{type: "text", text} \| {type: "tool_use", id, name, input} \| {type: "tool_result", tool_use_id, content, is_error}]}` |
| `tool_call` | `id`, `name`, `args` |
| `tool_result` | `id`, `name`, `args`, `content`, `is_error` (blocked calls: `is_error: true`, content `blocked: <reason>`) |
| `info` | `text` |
| `done` (last line) | `error` (null on success), `usage`, `session` |
### RPC (`hx --mode rpc`)
JSON-RPC 2.0, one message per line on stdin/stdout. Events arrive as `event` notifications (params = the
event object above). Methods: `prompt {text}` (replies `{message, usage}` when the run ends), `abort`,
`state`, `messages`, `fork {id}`, `clear`, `set_model {model}`, `compact`. One prompt at a time; other
methods are rejected while it runs (except `abort`). Example client: `examples/rpc_client.py`.
### Extensions
```toml
# ~/.hx/config.toml or .hx/config.toml (lists are concatenated)
[[extensions]]
command = ["python3", "/path/to/ext_guard.py", "rm -rf"]
timeout_secs = 10
```
An extension is a process speaking JSON-RPC over stdio. hx sends `initialize {protocolVersion, cwd}`; the
reply `{subscribe: ["tool_call", ...] | ["*"], tools: [{name, description, inputSchema}]}` picks events and
registers tools. Each subscribed event is sent as `event {event}`; reply `{action: "continue"}`,
`{action: "block", reason}` (tool_call), `{action: "mutate", args}` (tool_call) or
`{action: "inject", text}` (turn_end / agent_end). Tools are called as `tool/call {name, args}` ->
`{content, is_error}`. Errors and timeouts count as `continue`; extensions run before the lens.
Sample: `examples/ext_guard.py`.