Repository navigation
Expand file tree
/
Copy pathhdev
More file actions
executable file
·126 lines (105 loc) · 3.58 KB
/
Copy pathhdev
File metadata and controls
executable file
·126 lines (105 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
# hdev — Harness Dev Bridge CLI wrapper.
#
# Talks to the local HTTP server that the Tauri app runs in debug builds.
# See src-tauri/src/dev_bridge.rs for the server side.
#
# Usage:
# hdev list # enumerate webviews
# hdev eval <target> '<js expression>' # run JS in a webview
# hdev tail # stream console + events (SSE)
# hdev tail --errors # only errors
# hdev health # bridge liveness check
#
# Targets: main | chatgpt | claude | gemini
#
# Environment:
# HARNESS_DEV_PORT port to reach (default 9909)
# HDEV_BASE override full base URL (default http://127.0.0.1:$PORT)
set -euo pipefail
PORT="${HARNESS_DEV_PORT:-9909}"
BASE="${HDEV_BASE:-http://127.0.0.1:$PORT}"
die() { echo "hdev: $*" >&2; exit 1; }
need() {
command -v "$1" >/dev/null 2>&1 || die "required binary not found: $1"
}
# Pretty-print JSON if jq is available, otherwise raw.
pp() {
if command -v jq >/dev/null 2>&1; then jq . 2>/dev/null || cat
else cat
fi
}
usage() {
cat <<EOF
hdev — Harness Dev Bridge CLI
Commands:
list enumerate webviews (label, url)
eval <target> '<code>' run JS in <target>'s webview, print result
tail [--errors] stream console + events (SSE, ctrl-c to stop)
health ping the bridge
Targets: main chatgpt claude gemini (anything in 'hdev list')
Examples:
hdev list
hdev eval main 'document.title'
hdev eval chatgpt 'document.querySelectorAll("[data-message-author-role=assistant]").length'
hdev eval main 'document.querySelector(".nav-bar")?.getBoundingClientRect()'
hdev tail | jq 'select(.level==\"error\")'
Env:
HARNESS_DEV_PORT (default 9909)
HDEV_BASE (default http://127.0.0.1:\$HARNESS_DEV_PORT)
If you see "connection refused", the Tauri app isn't running, isn't in dev
mode, or bound to a different port.
EOF
}
cmd="${1:-}"; shift || true
need curl
case "$cmd" in
"" | -h | --help | help)
usage
;;
health | healthz)
curl -sS "$BASE/healthz" | pp
;;
list | ls)
curl -sS "$BASE/list" | pp
;;
eval)
target="${1:-}"; shift || die "usage: hdev eval <target> '<code>'"
code="${1:-}"; shift || die "usage: hdev eval <target> '<code>'"
[ -z "$target" ] && die "missing target"
[ -z "$code" ] && die "missing code"
# JSON-encode target and code. Use jq if available (robust), fall back
# to a minimal inline Python for maximum availability.
if command -v jq >/dev/null 2>&1; then
body=$(jq -nc --arg t "$target" --arg c "$code" \
'{target:$t, code:$c, timeout_ms:5000}')
else
body=$(python3 -c '
import json, sys
t, c = sys.argv[1], sys.argv[2]
print(json.dumps({"target": t, "code": c, "timeout_ms": 5000}))
' "$target" "$code")
fi
curl -sS -X POST "$BASE/eval" \
-H "Content-Type: application/json" \
-d "$body" | pp
;;
tail)
filter="${1:-}"
if [ "$filter" = "--errors" ] || [ "$filter" = "-e" ]; then
if command -v jq >/dev/null 2>&1; then
# SSE comes as `data: <json>\n\n`. Strip the prefix, then filter.
curl -sN "$BASE/tail" | sed -u -n 's/^data: //p' \
| jq -c 'select(.kind=="console" and .level=="error")'
else
curl -sN "$BASE/tail" | grep --line-buffered '"level":"error"'
fi
else
# Strip SSE prefix so output is plain JSONL (nice for `| jq`).
curl -sN "$BASE/tail" | sed -u -n 's/^data: //p'
fi
;;
*)
die "unknown command: $cmd (try: hdev help)"
;;
esac