claude_cli guard: extensions-only, bridge test against real hx (closes #17)

This commit is contained in:
hermes committed 2026-11-14 10:52:06 +00:00
1 parent a76c0ac16f
commit 28ad9934e5
5 files changed
+96 -25

No files matched your search

+19 -12
View File
@@ -36,24 +36,31 @@ A repo that already has its own `.hx/config.toml` is refused (`setup:` failure)
hx reaches Claude in two ways:
| mode | who runs the tools | what orch sees |
| mode | who runs the tools | how `allow` is enforced |
|---|---|---|
| `direct` (API provider) | hx | every tool as a `tool_call` event |
| `claude_cli` (hx starts the `claude` binary; auto-on when `claude` is in PATH and `HX_BASE_URL` is unset) | the `claude` binary | with johannes/hx#182: every tool as a `tool_call` event, decided by the guard through hx' permission bridge; without it: only a `[claude TOOL: ...]` text line |
| `direct` (API provider) | hx | `orch guard` blocks the `tool_call` before the tool runs; orch re-checks the event stream |
| `claude_cli` (hx starts the `claude` binary; auto-on when `claude` is in PATH and `HX_BASE_URL` is unset) | the `claude` binary | requires hx with johannes/hx#182: claude asks `mcp__hx__approve` first, hx puts the question on the event bus as `tool_call` (`bash{command}`, `write|edit|read{path}`), `orch guard` blocks it before the tool runs |
`allow` works in both modes **provided hx reports claude's tools as `tool_call` events** (hx#182). orch checks this
on every run: it counts the `[claude ...]` tool lines in the text stream and the `tool_call` events. If claude used
more tools than hx reported, the run ends `needs-human` with `policy: claude used N tool(s) but hx reported M
tool_call event(s) ...`: a profile is never silently unguarded. On an hx without #182 every claude_cli run that
uses a tool therefore fails closed; the tool has already run by then (the check is after the fact), so on such an hx
use no `allow` plus `sandbox = true` for claude_cli profiles.
`max_turns` counts model turns; in claude_cli mode there is one hx request per run, so it is not a useful limit there.
For `claude_cli` orch writes `permissions = "extensions-only"` into the generated worktree config. Then a question
is allowed only while a live `tool_call` extension guards it: if the guard dies or never starts, hx denies (a dead
extension otherwise counts as "continue"). Reads and Bash are asked too (hx passes `--settings permissions.ask`).
Checks that do not depend on trusting hx or claude:
- Stream check: orch sees `tool_call` events from claude's tools too and kills the run on a denied one.
- Count check: orch counts the `[claude TOOL: ...]` lines hx prints for every tool claude ran and the `tool_call`
events. Fewer events than lines (hx without #182, or a claude that skips the permission prompt) ends the run
`needs-human`: `policy: claude used N tool(s) but hx reported M tool_call event(s) ...`. This check is after the
fact (the tool already ran); the bridge is what prevents the call.
`max_turns` counts model turns; in claude_cli mode there is one hx request per run, so it is not a useful limit.
Telemetry records the mode (`provider_mode`: `claude_cli`, `direct`, `codex`; old lines `unknown`). `orch report`
shows it as a column and `orch eval` refuses to compare files with different (or mixed) modes ("NOT COMPARABLE",
exit 1): tokens, turns and tool behaviour differ by an order of magnitude between the modes.
Limit: the mode is derived from config and the `claude` binary, not from hx itself; hx' remembered last provider
(`last.json`) is not read, so set `provider` in profiles you compare.
Limits: the mode is derived from config and the `claude` binary, not from hx itself (hx' remembered last provider
`last.json` is not read, so set `provider` in profiles you compare). hx#182's `--settings` flag is untested against a
real `claude` binary (upstream says so too); tests use a fake claude that asks the bridge like the real one.
## Audit log