Subagents: task tool (explore on cheap model, general), child sessions, usage roll-up, stats
This commit is contained in:
1 parent
6b980591ed
commit
359a5058d7
14 files changed
+525
-2
No files matched your search
@@ -19,3 +19,4 @@ sh tests/m5_e2e.sh
|
||||
sh tests/m6_e2e.sh
|
||||
python3 tests/tui_lspinstall.py | grep -q FAIL && { echo "tui lsp install FAIL"; exit 1; } || echo "tui lsp install ok"
|
||||
sh tests/m7_e2e.sh
|
||||
sh tests/m8_e2e.sh
|
||||
@@ -1,7 +1,7 @@
|
||||
"""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
|
||||
Usage: python3 tests/fake_anthropic.py PORT [TURNS.json]
|
||||
"""
|
||||
import http.server, json, sys
|
||||
|
||||
@@ -10,6 +10,8 @@ TURNS = [
|
||||
[("tool_use", {"id": "t2", "name": "Bash", "input": {"command": "cat hello.txt"}})],
|
||||
[("text", "Done: file says hi from hx.")],
|
||||
]
|
||||
if len(sys.argv) > 2: # optional scripted turns: JSON [[["tool_use", {...}] | ["text", "..."], ...], ...]
|
||||
TURNS = [[tuple(b) for b in t] for t in json.load(open(sys.argv[2]))]
|
||||
LOG = []
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
# M8 e2e: the parent calls `task`; the child (own session, cheap model) reads a file and answers;
|
||||
# only the answer reaches the parent; child usage is logged under <session>.sub/.
|
||||
set -eu
|
||||
root=$(cd "$(dirname "$0")/.." && pwd)
|
||||
tmp=$(mktemp -d)
|
||||
trap 'kill $srv 2>/dev/null; rm -rf "$tmp"' EXIT
|
||||
mkdir -p "$tmp/home/.hx" "$tmp/repo"
|
||||
echo '{"claude":{"access":"fake-token","refresh":"r","expires":99999999999999}}' > "$tmp/home/.hx/auth.json"
|
||||
printf '[lsp]\nmode = "off"\ntests = "off"\n' > "$tmp/home/.hx/config.toml"
|
||||
echo "secret is 42" > "$tmp/repo/note.txt"
|
||||
cat > "$tmp/turns.json" <<'J'
|
||||
[[["tool_use", {"id": "p1", "name": "Task", "input": {"prompt": "what is in note.txt?"}}]],
|
||||
[["tool_use", {"id": "c1", "name": "Read", "input": {"path": "note.txt"}}]],
|
||||
[["text", "note.txt says: secret is 42"]],
|
||||
[["text", "Parent done."]]]
|
||||
J
|
||||
cd "$tmp/repo"
|
||||
export HOME="$tmp/home"
|
||||
port=$((20000 + $$ % 20000))
|
||||
python3 "$root/tests/fake_anthropic.py" $port "$tmp/turns.json" & srv=$!
|
||||
export HX_BASE_URL="http://127.0.0.1:$port"
|
||||
sleep 0.5
|
||||
"$root/target/debug/hx" -p "go" -s "$tmp/s.jsonl" > "$tmp/out" 2> "$tmp/err" || { echo "FAIL run"; cat "$tmp/err"; exit 1; }
|
||||
grep -q "Parent done." "$tmp/out" || { echo "FAIL parent text"; cat "$tmp/out" "$tmp/err"; exit 1; }
|
||||
curl -s "http://127.0.0.1:$port/log" > "$tmp/log"
|
||||
python3 - "$tmp/log" "$tmp/s.jsonl" <<'PY' || { echo "FAIL requests"; exit 1; }
|
||||
import json, sys
|
||||
log = json.load(open(sys.argv[1]))
|
||||
assert len(log) == 4, len(log)
|
||||
parent, child1, child2, parent2 = [r["body"] for r in log]
|
||||
assert "haiku" in child1["model"] and "sonnet" in parent["model"], (child1["model"], parent["model"])
|
||||
assert child1["messages"][0]["content"][0]["text"] == "what is in note.txt?"
|
||||
assert {t["name"] for t in child1["tools"]} == {"Read", "Bash"}, [t["name"] for t in child1["tools"]]
|
||||
assert "Task" in {t["name"] for t in parent["tools"]}
|
||||
# parent got only the child's answer (+ stats line), not the Read result
|
||||
res = json.dumps(parent2["messages"][-1])
|
||||
assert "secret is 42" in res and "[task explore" in res
|
||||
PY
|
||||
ls "$tmp/s.sub/001-explore.jsonl" > /dev/null || { echo "FAIL child session"; exit 1; }
|
||||
"$root/target/debug/hx" stats "$tmp/s.jsonl" | grep -q "subagents (1 runs" || { echo "FAIL stats"; exit 1; }
|
||||
echo "m8 e2e ok"
|
||||
Reference in new issue
Block a user