-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhusky-remote
More file actions
executable file
·162 lines (147 loc) · 6.13 KB
/
Copy pathhusky-remote
File metadata and controls
executable file
·162 lines (147 loc) · 6.13 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# Husky Agent CLI - Remote Mode
# Usage:
# husky-remote tui Connect TUI to configured remote service
# husky-remote install Create symlink in /usr/local/bin for global access
#
# ── Remote Server Configuration ───────────────────────────────────────────────
# Change the following two lines to configure your remote server.
REMOTE_HOST="10.109.214.133"
REMOTE_PORT="8080"
# ──────────────────────────────────────────────────────────────────────────────
# The settings below usually do not need changes.
REMOTE_WS_URL="ws://${REMOTE_HOST}:${REMOTE_PORT}/api/tui"
REMOTE_HTTP_URL="http://${REMOTE_HOST}:${REMOTE_PORT}"
set -e
# ── Resolve script location (handle symlinks & relative paths) ────────────
SOURCE="$0"
while [ -L "$SOURCE" ]; do
DIR="$(cd "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE"
done
SCRIPT_DIR="$(cd "$(dirname "$SOURCE")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
find_packaged_jar() {
local module_dir="$1"
local artifact_id="$2"
local candidate
local newest=""
for candidate in "$PROJECT_DIR/$module_dir/target/$artifact_id.jar" "$PROJECT_DIR/target/$artifact_id.jar"; do
if [ -f "$candidate" ]; then
printf '%s\n' "$candidate"
return 0
fi
done
for candidate in "$PROJECT_DIR/$module_dir"/target/"$artifact_id"-*.jar "$PROJECT_DIR"/target/"$artifact_id"-*.jar; do
[ -f "$candidate" ] || continue
case "$candidate" in
*-sources.jar|*-javadoc.jar|*.original) continue ;;
esac
if [ -z "$newest" ] || [ "$candidate" -nt "$newest" ]; then
newest="$candidate"
fi
done
if [ -n "$newest" ]; then
printf '%s\n' "$newest"
fi
}
# ── Find the Husky Client JAR ──────────────────────────────────────────────
CLIENT_JAR="$(find_packaged_jar client husky-agent-client || true)"
MVNW="$PROJECT_DIR/mvnw"
if [ ! -f "$MVNW" ]; then
MVNW=""
fi
# ── Helper: check if remote service is reachable ──────────────────────────
check_remote() {
if curl -sf "${REMOTE_HTTP_URL}/actuator/health" > /dev/null 2>&1; then
return 0
fi
return 1
}
# ── Commands ──────────────────────────────────────────────────────────────
case "${1:-tui}" in
tui)
shift
SERVER_URL="$REMOTE_WS_URL"
# Allow --server to override the configured URL
while [[ $# -gt 0 ]]; do
case $1 in
--server)
SERVER_URL="$2"
shift 2
;;
--host)
REMOTE_HOST="$2"
SERVER_URL="ws://${REMOTE_HOST}:${REMOTE_PORT}/api/tui"
REMOTE_HTTP_URL="http://${REMOTE_HOST}:${REMOTE_PORT}"
shift 2
;;
--port)
REMOTE_PORT="$2"
SERVER_URL="ws://${REMOTE_HOST}:${REMOTE_PORT}/api/tui"
REMOTE_HTTP_URL="http://${REMOTE_HOST}:${REMOTE_PORT}"
shift 2
;;
*)
shift
;;
esac
done
echo "🐺 Connecting to remote Husky: $SERVER_URL"
# Check service reachability as a non-blocking warning.
if ! check_remote 2>/dev/null; then
echo " Warning: ${REMOTE_HTTP_URL}/actuator/health is unreachable; trying to connect directly..."
fi
if [ -n "$CLIENT_JAR" ]; then
exec java -jar "$CLIENT_JAR" --server "$SERVER_URL"
elif [ -n "$MVNW" ]; then
exec "$MVNW" exec:java -pl client \
-Dexec.mainClass="io.github.huskyagent.tui.AgentTUI" \
-Dexec.args="--server $SERVER_URL"
else
echo "Error: Cannot find Husky client JAR or mvnw"
echo "Please build the project first: ./mvnw clean install -DskipTests"
exit 1
fi
;;
install)
TARGET="/usr/local/bin/husky-remote"
if [ -L "$TARGET" ]; then
existing="$(readlink "$TARGET")"
if [ "$existing" = "$SCRIPT_DIR/husky-remote" ]; then
echo "✓ Already installed: $TARGET → $SCRIPT_DIR/husky-remote"
else
echo "⚠ $TARGET exists (→ $existing), updating..."
sudo ln -sf "$SCRIPT_DIR/husky-remote" "$TARGET"
echo "✓ Updated: $TARGET → $SCRIPT_DIR/husky-remote"
fi
elif [ -e "$TARGET" ]; then
echo "⚠ $TARGET exists and is not a symlink. Remove it first."
exit 1
else
sudo ln -s "$SCRIPT_DIR/husky-remote" "$TARGET"
echo "✓ Installed: $TARGET → $SCRIPT_DIR/husky-remote"
fi
echo ""
echo "Now you can run 'husky-remote tui' from anywhere!"
;;
*)
echo "Usage: husky-remote {tui|install}"
echo ""
echo "Commands:"
echo " tui Connect TUI client to remote service"
echo " (currently configured: $REMOTE_WS_URL)"
echo " install Create symlink in /usr/local/bin for global access"
echo ""
echo "TUI options:"
echo " --server URL Override WebSocket URL completely"
echo " --host HOST Override remote host (keep configured port)"
echo " --port PORT Override remote port (keep configured host)"
echo ""
echo "Configuration (edit this file to change defaults):"
echo " REMOTE_HOST = $REMOTE_HOST"
echo " REMOTE_PORT = $REMOTE_PORT"
exit 1
;;
esac