ai: claude_cli provider (official claude binary, subscription billing)

This commit is contained in:
hermes committed 2026-10-16 20:09:32 +00:00
1 parent bd9671804b
commit 769effc8b0
7 files changed
+293 -1

No files matched your search

+1
View File
@@ -21,3 +21,4 @@ python3 tests/tui_lspinstall.py | grep -q FAIL && { echo "tui lsp install FAIL";
sh tests/m7_e2e.sh
sh tests/m8_e2e.sh
sh tests/sandbox_e2e.sh
sh tests/claude_cli_e2e.sh
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
# claude_cli = [] routes Claude through the `claude` binary (fake here): streamed text arrives, argv is right.
set -eu
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"
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 "hello from claude" "$tmp/out" || { echo "FAIL text"; cat "$tmp/out" "$tmp/err"; exit 1; }
grep -q '"--mcp-config"' "$tmp/argv" && grep -q '"stream-json"' "$tmp/argv" || { echo "FAIL argv"; cat "$tmp/argv"; exit 1; }
echo "claude cli e2e ok"
+14
View File
@@ -0,0 +1,14 @@
#!/usr/bin/env python3
"""Fake `claude -p --output-format stream-json`: logs argv to $FAKE_CLAUDE_LOG, streams one reply."""
import json, os, sys
open(os.environ["FAKE_CLAUDE_LOG"], "a").write(json.dumps(sys.argv[1:]) + "\n")
if "--version" in sys.argv:
print("fake"); sys.exit(0)
def out(o): print(json.dumps(o), flush=True)
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"}})
ev({"type": "content_block_delta", "delta": {"type": "text_delta", "text": "hello "}})
ev({"type": "content_block_delta", "delta": {"type": "text_delta", "text": "from claude"}})
out({"type": "result", "session_id": "S1", "is_error": False, "result": "hello from claude",
"usage": {"input_tokens": 3, "output_tokens": 4}})