Merge pull request 'claude_cli: codemode for claude' (#167) from feat/claude-cli-codemode into main
This commit was merged in pull request #167.
This commit is contained in:
commit
d69c56b3c8
4 files changed
+111
-27
No files matched your search
@@ -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 "claude Bash: echo hi-from-tool" "$tmp/out" && 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"
|
||||
@@ -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})
|
||||
out({"type": "assistant", "session_id": "S1", "message": {"content": [
|
||||
|
||||
Reference in new issue
Block a user