claude_cli: tool calls on the event bus, extensions can block, permissions deny/extensions-only (#182)

This commit is contained in:
hermes committed 2026-11-13 19:38:29 +00:00
1 parent 6ebf1c3180
commit 6978aad27a
12 files changed
+297 -12

No files matched your search

+23
View File
@@ -6,6 +6,29 @@ if "--version" in sys.argv:
print("fake"); sys.exit(0)
def out(o): print(json.dumps(o), flush=True)
reply = "hello from claude"
if os.environ.get("FAKE_ASK"): # ask hx about a secret Read and `curl x` (ids t1/t2); report the answers
import subprocess
cfg = json.loads(sys.argv[sys.argv.index("--mcp-config") + 1])["mcpServers"]["hx"]
p = subprocess.Popen([cfg["command"], *cfg["args"]], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
text=True, env={**os.environ, **cfg["env"]})
asks = [("t1", "Read", {"file_path": "/home/u/.ssh/id_rsa"}), ("t2", "Bash", {"command": "curl x"})]
p.stdin.write(json.dumps({"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}) + "\n")
p.stdin.flush()
p.stdout.readline()
ans = []
for i, (tid, n, inp) in enumerate(asks): # one at a time: deterministic order
p.stdin.write(json.dumps({"jsonrpc": "2.0", "id": 10 + i, "method": "tools/call", "params": {"name": "approve",
"arguments": {"tool_name": n, "input": inp, "tool_use_id": tid}}}) + "\n")
p.stdin.flush()
ans.append(json.loads(json.loads(p.stdout.readline())["result"]["content"][0]["text"]))
p.stdin.close()
out({"type": "system", "subtype": "init", "session_id": "S1"})
for (tid, n, inp), a in zip(asks, ans):
out({"type": "assistant", "session_id": "S1", "message": {"content": [{"type": "tool_use", "id": tid, "name": n, "input": inp}]}})
out({"type": "user", "session_id": "S1", "message": {"content": [{"type": "tool_result", "tool_use_id": tid,
"content": a["behavior"] + ": " + a.get("message", ""), "is_error": a["behavior"] == "deny"}]}})
out({"type": "result", "session_id": "S1", "is_error": False, "result": "done", "usage": {"input_tokens": 1, "output_tokens": 1}})
sys.exit(0)
if "--permission-prompt-tool" in sys.argv: # act like claude: ask hx whether `rm -rf x` may run
import subprocess
cfg = json.loads(sys.argv[sys.argv.index("--mcp-config") + 1])["mcpServers"]["hx"]