- hx-core: Tool trait + registry (schema validation, parallel calls), event bus with Block/Mutate/Inject hooks, agent loop (abort, max turns, AgentEnd inject), JSONL session tree (fork, resume, torn-line tolerant), AGENTS.md/CLAUDE.md hierarchy, skills index (bodies on demand) - hx-tools: read (ranges, binary, images, caps), write/edit (exact match, ambiguity, CRLF, diff, read-guard), bash (merged output, timeout kills process group, tail truncation to temp file) - hx-cli: -p runs full agent loop, --session / --continue, Ctrl-C abort, HX_BASE_URL override - tests/e2e.sh: scripted fake Anthropic server drives write -> bash -> answer Closes #6, closes #7, closes #8, closes #9, closes #10, closes #11, closes #12, closes #13, closes #14
This commit is contained in:
1 parent
da9d5d1ae0
commit
21d4d2bb3d
15 files changed
+1752
-52
No files matched your search
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
# End-to-end: hx -p against a scripted fake Anthropic API. No network, no real credentials.
|
||||
set -eu
|
||||
root=$(cd "$(dirname "$0")/.." && pwd)
|
||||
tmp=$(mktemp -d)
|
||||
trap 'kill $srv 2>/dev/null; rm -rf "$tmp"' EXIT
|
||||
port=$((20000 + $$ % 20000))
|
||||
python3 "$root/tests/fake_anthropic.py" $port & srv=$!
|
||||
mkdir -p "$tmp/home/.hx" "$tmp/repo"
|
||||
echo '{"claude":{"access":"fake-token","refresh":"r","expires":99999999999999}}' > "$tmp/home/.hx/auth.json"
|
||||
sleep 0.5
|
||||
cd "$tmp/repo"
|
||||
HOME="$tmp/home" HX_BASE_URL="http://127.0.0.1:$port" "$root/target/debug/hx" -p "make hello.txt" > "$tmp/out" 2> "$tmp/err"
|
||||
grep -q "Done: file says hi from hx." "$tmp/out"
|
||||
[ "$(cat hello.txt)" = "hi from hx" ]
|
||||
log=$(curl -s "http://127.0.0.1:$port/")
|
||||
echo "$log" | grep -q '"auth": "Bearer fake-token"'
|
||||
echo "$log" | grep -q 'oauth-2025-04-20'
|
||||
echo "$log" | grep -q 'hi from hx' # bash tool result sent back to the model
|
||||
ls "$tmp/home/.hx/sessions/"*/*.jsonl > /dev/null
|
||||
echo "e2e ok"
|
||||
@@ -0,0 +1,52 @@
|
||||
"""Scripted fake of the Anthropic SSE API for end-to-end tests of `hx -p`.
|
||||
|
||||
Turn 1: tool_use write hello.txt. Turn 2: tool_use bash cat. Turn 3: final text.
|
||||
Usage: python3 tests/fake_anthropic.py PORT
|
||||
"""
|
||||
import http.server, json, sys
|
||||
|
||||
TURNS = [
|
||||
[("tool_use", {"id": "t1", "name": "Write", "input": {"path": "hello.txt", "content": "hi from hx\n"}})],
|
||||
[("tool_use", {"id": "t2", "name": "Bash", "input": {"command": "cat hello.txt"}})],
|
||||
[("text", "Done: file says hi from hx.")],
|
||||
]
|
||||
LOG = []
|
||||
|
||||
|
||||
def sse(ev, d):
|
||||
return f"event: {ev}\ndata: {json.dumps(d)}\n\n".encode()
|
||||
|
||||
|
||||
class H(http.server.BaseHTTPRequestHandler):
|
||||
def log_message(self, *a):
|
||||
pass
|
||||
|
||||
def do_POST(self):
|
||||
body = json.loads(self.rfile.read(int(self.headers["content-length"])))
|
||||
LOG.append({"auth": self.headers.get("authorization"), "beta": self.headers.get("anthropic-beta"), "body": body})
|
||||
turn = TURNS[min(len(LOG) - 1, len(TURNS) - 1)]
|
||||
self.send_response(200)
|
||||
self.send_header("content-type", "text/event-stream")
|
||||
self.end_headers()
|
||||
w = self.wfile.write
|
||||
w(sse("message_start", {"message": {"usage": {"input_tokens": 5, "output_tokens": 1}}}))
|
||||
stop = "end_turn"
|
||||
for i, (kind, v) in enumerate(turn):
|
||||
if kind == "text":
|
||||
w(sse("content_block_start", {"index": i, "content_block": {"type": "text", "text": ""}}))
|
||||
w(sse("content_block_delta", {"index": i, "delta": {"type": "text_delta", "text": v}}))
|
||||
else:
|
||||
stop = "tool_use"
|
||||
w(sse("content_block_start", {"index": i, "content_block": {"type": "tool_use", "id": v["id"], "name": v["name"], "input": {}}}))
|
||||
w(sse("content_block_delta", {"index": i, "delta": {"type": "input_json_delta", "partial_json": json.dumps(v["input"])}}))
|
||||
w(sse("content_block_stop", {"index": i}))
|
||||
w(sse("message_delta", {"delta": {"stop_reason": stop}, "usage": {"output_tokens": 3}}))
|
||||
w(sse("message_stop", {}))
|
||||
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(LOG).encode())
|
||||
|
||||
|
||||
http.server.ThreadingHTTPServer(("127.0.0.1", int(sys.argv[1])), H).serve_forever()
|
||||
Reference in new issue
Block a user