claude_cli: offer codemode to claude (codemode = true), hx tools inside it ask via the permission bridge

This commit is contained in:
hermes committed 2026-10-16 20:42:10 +00:00
1 parent 785effef11
commit fdeaaf5cf2
4 files changed
+111 -27

No files matched your search

+2 -1
View File
@@ -5,11 +5,12 @@ root=$(cd "$(dirname "$0")/.." && pwd)
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
mkdir -p "$tmp/home/.hx" "$tmp/repo"
printf 'claude_cli = []\n[lsp]\nmode = "off"\ntests = "off"\n' > "$tmp/home/.hx/config.toml"
printf 'claude_cli = []\ncodemode = true\n[lsp]\nmode = "off"\ntests = "off"\n' > "$tmp/home/.hx/config.toml"
chmod +x "$root/tests/fake_claude.py"
cd "$tmp/repo"
export HOME="$tmp/home" HX_CLAUDE_BIN="$root/tests/fake_claude.py" FAKE_CLAUDE_LOG="$tmp/argv"
"$root/target/debug/hx" -p "hi" -s "$tmp/s.jsonl" > "$tmp/out" 2> "$tmp/err" || { echo "FAIL run"; cat "$tmp/err"; exit 1; }
grep -q "approve: allow" "$tmp/out" || { echo "FAIL text"; cat "$tmp/out" "$tmp/err"; exit 1; }
grep -q '"--permission-prompt-tool"' "$tmp/argv" && grep -q '"--mcp-config"' "$tmp/argv" && grep -q '"stream-json"' "$tmp/argv" || { echo "FAIL argv"; cat "$tmp/argv"; exit 1; }
grep -q "cm-ok" "$tmp/out" || { echo "FAIL codemode"; cat "$tmp/out" "$tmp/err"; exit 1; }
echo "claude cli e2e ok"
+7 -1
View File
@@ -15,9 +15,15 @@ if "--permission-prompt-tool" in sys.argv: # act like claude: ask hx whether `r
{"tool_name": "Bash", "input": {"command": "rm -rf x"}}}}
p.stdin.write(json.dumps({"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}) + "\n" + json.dumps(call) + "\n")
p.stdin.flush()
lines = [json.loads(p.stdout.readline()) for _ in range(2)]
cm = {"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "codemode", "arguments":
{"script": "return await tools.bash({command: 'echo cm-' + 'ok > cm.txt; cat cm.txt'})"}}}
if "HX_CODEMODE" in cfg["env"]:
p.stdin.write(json.dumps(cm) + "\n"); p.stdin.flush()
lines = [json.loads(p.stdout.readline()) for _ in range(2 + ("HX_CODEMODE" in cfg["env"]))]
p.stdin.close()
reply = "approve: " + json.loads(lines[1]["result"]["content"][0]["text"])["behavior"]
if len(lines) == 3:
reply += " " + lines[2]["result"]["content"][0]["text"]
out({"type": "system", "subtype": "init", "session_id": "S1"})
ev = lambda e: out({"type": "stream_event", "session_id": "S1", "event": e})
ev({"type": "content_block_start", "content_block": {"type": "tool_use", "name": "Read"}})