-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathlaunch.sh
More file actions
391 lines (348 loc) · 13 KB
/
Copy pathlaunch.sh
File metadata and controls
391 lines (348 loc) · 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
#!/bin/bash
# ============================================================================
# Hermes Agent - Portable Launcher (macOS / Linux)
# ============================================================================
# Terminal: ./launch.sh
# macOS Finder: rename this file to "launch.command" for double-click support.
# On first run, it downloads ~600MB of runtime files automatically.
# All data stays in the "data/" folder — nothing touches the host computer.
# ============================================================================
set -e
# Resolve portable root (directory containing this script)
PORTABLE_ROOT="$(cd "$(dirname "$0")" && pwd)"
HERMES_HOME="$PORTABLE_ROOT/data"
CACHE_DIR="$PORTABLE_ROOT/.cache"
SRC_DIR="$PORTABLE_ROOT/src"
# ---------------------------------------------------------------------------
# Detect OS and architecture
# ---------------------------------------------------------------------------
OS_RAW="$(uname -s)"
ARCH_RAW="$(uname -m)"
case "$OS_RAW" in
Linux*) PLATFORM="linux" ;;
Darwin*) PLATFORM="macos" ;;
CYGWIN*|MINGW*|MSYS*) PLATFORM="windows" ;;
*)
echo "[ERROR] Unsupported operating system: $OS_RAW"
exit 1
;;
esac
case "$ARCH_RAW" in
x86_64|amd64) ARCH="x64" ;;
aarch64|arm64) ARCH="arm64" ;;
*)
echo "[ERROR] Unsupported architecture: $ARCH_RAW"
exit 1
;;
esac
RUNTIME_DIR="$CACHE_DIR/runtimes/${PLATFORM}-${ARCH}"
portable_id() {
if command -v md5sum >/dev/null 2>&1; then
printf '%s' "$1" | md5sum | cut -c1-8
elif command -v md5 >/dev/null 2>&1; then
printf '%s' "$1" | md5 | cut -c1-8
else
basename "$1" | tr -cd '[:alnum:]' | cut -c1-8
fi
}
# ---------------------------------------------------------------------------
# First-run setup
# ---------------------------------------------------------------------------
if [ ! -f "$RUNTIME_DIR/ready.flag" ]; then
echo ""
echo "============================================"
echo " Hermes Portable - First Run Setup"
echo "============================================"
echo " Platform: ${PLATFORM}-${ARCH}"
echo " This will download ~600MB of runtime files."
echo " Please be patient."
echo "============================================"
echo ""
bash "$PORTABLE_ROOT/scripts/setup-unix.sh" "$PORTABLE_ROOT"
if [ $? -ne 0 ]; then
echo ""
echo "[ERROR] Setup failed. Please check your internet connection and try again."
exit 1
fi
fi
# ---------------------------------------------------------------------------
# Environment isolation — keep everything inside the portable folder
# (except the venv, which must live on a local FS to avoid exFAT hardlink
# limitations — see scripts/setup-unix.sh for details)
# ---------------------------------------------------------------------------
# Read the venv path from the pointer file written during setup.
if [ -f "$RUNTIME_DIR/venv.path" ]; then
VIRTUAL_ENV="$(cat "$RUNTIME_DIR/venv.path")"
else
# Fallback for older setups that put the venv on the drive.
VIRTUAL_ENV="$RUNTIME_DIR/venv"
fi
# If the venv is missing (e.g. after a reboot purged $TMPDIR), rebuild it.
if [ ! -x "$VIRTUAL_ENV/bin/python" ]; then
echo ""
echo "[INFO] Local venv not found (temp was likely cleared). Rebuilding ..."
echo " This is fast because packages are cached on the drive."
UV_EXE="$RUNTIME_DIR/uv/uv"
PYTHON_EXE="$RUNTIME_DIR/python/bin/python3"
SRC_DIR="$PORTABLE_ROOT/src"
if [ "$PLATFORM" = "macos" ]; then
LOCAL_BASE="${TMPDIR:-/tmp}"
else
LOCAL_BASE="/tmp"
fi
DRIVE_ID="$(portable_id "$RUNTIME_DIR")"
VIRTUAL_ENV="${LOCAL_BASE}/hermes-portable-venv-${DRIVE_ID}"
export UV_CACHE_DIR="${LOCAL_BASE}/hermes-uv-cache-${DRIVE_ID}"
mkdir -p "$UV_CACHE_DIR"
# Save updated path
echo "$VIRTUAL_ENV" > "$RUNTIME_DIR/venv.path"
rm -rf "$VIRTUAL_ENV"
if ! "$UV_EXE" venv "$VIRTUAL_ENV" --python "$PYTHON_EXE" --seed 2>/dev/null; then
"$UV_EXE" venv "$VIRTUAL_ENV" --python "$PYTHON_EXE"
fi
if ! "$UV_EXE" pip install --python "$VIRTUAL_ENV/bin/python" --link-mode=copy \
-e "$SRC_DIR/hermes-agent[all]" \
"python-telegram-bot[webhooks]==22.6" 2>/dev/null; then
"$VIRTUAL_ENV/bin/python" -m ensurepip --upgrade >/dev/null 2>&1 || true
"$VIRTUAL_ENV/bin/python" -m pip install \
-e "$SRC_DIR/hermes-agent[all]" \
"python-telegram-bot[webhooks]==22.6" 2>/dev/null || true
fi
echo "[OK] Venv rebuilt."
fi
export HERMES_HOME="$HERMES_HOME"
export VIRTUAL_ENV
export PATH="$VIRTUAL_ENV/bin:$RUNTIME_DIR/python/bin:$RUNTIME_DIR/node/bin:$RUNTIME_DIR/uv:$RUNTIME_DIR/bin:$PATH"
export PYTHONNOUSERSITE=1
export PYTHONHOME=""
export PYTHONPATH=""
export UV_NO_CONFIG=1
export UV_PYTHON="$RUNTIME_DIR/python/bin/python3"
export PLAYWRIGHT_BROWSERS_PATH="$RUNTIME_DIR/playwright"
export NODE_PATH="$RUNTIME_DIR/node/lib/node_modules"
export NPM_CONFIG_PREFIX="$RUNTIME_DIR/node"
# Prevent Node/npm from writing to host home directory
export HOME="$PORTABLE_ROOT/.cache/unix-home"
mkdir -p "$HOME"
# ---------------------------------------------------------------------------
# Launch Hermes
# ---------------------------------------------------------------------------
if [ ! -d "$SRC_DIR/hermes-agent" ]; then
echo "[ERROR] Hermes source not found. Please delete .cache and try again."
exit 1
fi
cd "$SRC_DIR/hermes-agent"
# Strip "hermes" from the start of arguments if user typed "launch.sh hermes setup"
if [ "$1" = "hermes" ] || [ "$1" = "HERMES" ]; then
shift
fi
# If explicit arguments were passed, run Hermes directly (skip menu)
if [ $# -gt 0 ]; then
hermes "$@"
exit 0
fi
# ---------------------------------------------------------------------------
# ANSI Colors
# ---------------------------------------------------------------------------
ESC='\033'
RESET="${ESC}[0m"
BOLD="${ESC}[1m"
DIM="${ESC}[2m"
CYAN="${ESC}[36m"
BRIGHT_CYAN="${ESC}[96m"
GREEN="${ESC}[32m"
BRIGHT_GREEN="${ESC}[92m"
YELLOW="${ESC}[33m"
BRIGHT_YELLOW="${ESC}[93m"
RED="${ESC}[31m"
BRIGHT_RED="${ESC}[91m"
WHITE="${ESC}[37m"
BRIGHT_WHITE="${ESC}[97m"
GRAY="${ESC}[90m"
# ---------------------------------------------------------------------------
# Status Detection
# ---------------------------------------------------------------------------
detect_status() {
SETUP_STATUS="Not configured"
SETUP_ICON="[x]"
SETUP_COLOR="$RED"
PROVIDER_NAME=""
MODEL_NAME=""
if [ -f "$HERMES_HOME/.env" ] && grep -q '^[A-Z].*=' "$HERMES_HOME/.env"; then
SETUP_STATUS="Configured"
SETUP_ICON="[OK]"
SETUP_COLOR="$BRIGHT_GREEN"
fi
if [ -f "$HERMES_HOME/config.yaml" ]; then
PROVIDER_NAME=$(grep '^ provider:' "$HERMES_HOME/config.yaml" | head -n 1 | awk '{print $2}' || true)
MODEL_NAME=$(grep '^ default:' "$HERMES_HOME/config.yaml" | head -n 1 | awk '{print $2}' || true)
fi
GATEWAY_STATUS="Stopped"
GATEWAY_ICON="[ ]"
GATEWAY_COLOR="$GRAY"
GATEWAY_PID=""
if [ -f "$HERMES_HOME/gateway.pid" ]; then
GATEWAY_PID=$(grep -o '"pid":[0-9]*' "$HERMES_HOME/gateway.pid" | grep -o '[0-9]*' || true)
fi
if [ -n "$GATEWAY_PID" ]; then
if kill -0 "$GATEWAY_PID" 2>/dev/null; then
GATEWAY_STATUS="Running (PID $GATEWAY_PID)"
GATEWAY_ICON="[OK]"
GATEWAY_COLOR="$BRIGHT_GREEN"
else
GATEWAY_STATUS="Stopped (stale lock)"
GATEWAY_ICON="[!]"
GATEWAY_COLOR="$YELLOW"
fi
fi
HERMES_VERSION="unknown"
if [ -f "$SRC_DIR/hermes-agent/hermes_cli/__init__.py" ]; then
HERMES_VERSION=$(grep '__version__' "$SRC_DIR/hermes-agent/hermes_cli/__init__.py" | head -n 1 | sed 's/.*"\(.*\)".*/\1/')
fi
}
# ---------------------------------------------------------------------------
# Main Menu
# ---------------------------------------------------------------------------
show_menu() {
clear
echo ""
echo -e "${BRIGHT_CYAN}----------------------------------------------------------------${RESET}"
echo -e "${BOLD}${BRIGHT_WHITE} HERMES PORTABLE LAUNCHER${RESET}"
echo -e "${DIM}${GRAY} AI Agent for Everyone${RESET}"
echo -e "${BRIGHT_CYAN}----------------------------------------------------------------${RESET}"
echo ""
echo -e " ${DIM}Setup${RESET} ${SETUP_COLOR}${SETUP_ICON}${RESET} ${WHITE}${SETUP_STATUS}${RESET}"
[ -n "$PROVIDER_NAME" ] && echo -e " ${DIM}Provider${RESET} ${CYAN}${PROVIDER_NAME}${RESET}"
[ -n "$MODEL_NAME" ] && echo -e " ${DIM}Model${RESET} ${WHITE}${MODEL_NAME}${RESET}"
echo -e " ${DIM}Gateway${RESET} ${GATEWAY_COLOR}${GATEWAY_ICON}${RESET} ${WHITE}${GATEWAY_STATUS}${RESET}"
echo -e " ${DIM}Version${RESET} ${GRAY}v${HERMES_VERSION}${RESET}"
echo ""
echo -e "${BRIGHT_CYAN}----------------------------------------------------------------${RESET}"
echo ""
echo -e " ${BRIGHT_YELLOW}[1]${RESET} ${WHITE}Start Hermes Chat${RESET}"
echo -e " ${BRIGHT_YELLOW}[2]${RESET} ${WHITE}Setup / Reconfigure Hermes${RESET}"
if [ "$GATEWAY_STATUS" = "Running (PID $GATEWAY_PID)" ]; then
echo -e " ${BRIGHT_YELLOW}[3]${RESET} ${WHITE}Stop Gateway${RESET} ${RED}[live]${RESET}"
else
echo -e " ${BRIGHT_YELLOW}[3]${RESET} ${WHITE}Start Gateway${RESET}"
fi
echo -e " ${BRIGHT_YELLOW}[4]${RESET} ${WHITE}Advanced Options${RESET} ${GRAY}-->${RESET}"
echo -e " ${BRIGHT_YELLOW}[5]${RESET} ${GRAY}Exit${RESET}"
echo ""
echo -e "${BRIGHT_CYAN}----------------------------------------------------------------${RESET}"
echo ""
read -p "$(echo -e "${BRIGHT_CYAN}Select option: ${RESET}")" choice
case "$choice" in
1) menu_chat ;;
2) menu_setup ;;
3) menu_gateway ;;
4) show_advanced ;;
5) menu_exit ;;
*) show_menu ;;
esac
}
menu_chat() {
clear
hermes
show_menu
}
menu_setup() {
clear
hermes setup
detect_status
show_menu
}
menu_gateway() {
if [ "$GATEWAY_STATUS" = "Running (PID $GATEWAY_PID)" ]; then
hermes gateway stop
echo ""
echo -e "${BRIGHT_GREEN}Gateway stopped.${RESET}"
else
echo ""
echo -e "${CYAN}Starting gateway in background ...${RESET}"
hermes gateway &
sleep 2
fi
read -p "Press Enter to continue ..."
detect_status
show_menu
}
menu_exit() {
clear
echo ""
echo -e "${GRAY}Goodbye!${RESET}"
echo ""
exit 0
}
# ---------------------------------------------------------------------------
# Advanced Menu
# ---------------------------------------------------------------------------
show_advanced() {
clear
echo ""
echo -e "${BRIGHT_CYAN}----------------------------------------------------------------${RESET}"
echo -e "${BOLD}${BRIGHT_WHITE} Advanced Options${RESET}"
echo -e "${BRIGHT_CYAN}----------------------------------------------------------------${RESET}"
echo ""
echo -e " ${BRIGHT_YELLOW}[1]${RESET} ${WHITE}Run Doctor${RESET} ${GRAY}- check for issues${RESET}"
echo -e " ${BRIGHT_YELLOW}[2]${RESET} ${WHITE}View Logs${RESET} ${GRAY}- last 20 lines${RESET}"
echo -e " ${BRIGHT_YELLOW}[3]${RESET} ${WHITE}Edit Config${RESET} ${GRAY}- open in editor${RESET}"
echo -e " ${BRIGHT_YELLOW}[4]${RESET} ${WHITE}Restart Gateway${RESET} ${GRAY}- stop + start${RESET}"
echo -e " ${BRIGHT_YELLOW}[5]${RESET} ${WHITE}Update Hermes${RESET} ${GRAY}- fetch latest${RESET}"
echo -e " ${BRIGHT_YELLOW}[6]${RESET} ${GRAY}Back to Main Menu${RESET}"
echo ""
echo -e "${BRIGHT_CYAN}----------------------------------------------------------------${RESET}"
echo ""
read -p "$(echo -e "${BRIGHT_CYAN}Select option: ${RESET}")" choice
case "$choice" in
1) adv_doctor ;;
2) adv_logs ;;
3) adv_config ;;
4) adv_restart ;;
5) adv_update ;;
6) show_menu ;;
*) show_advanced ;;
esac
}
adv_doctor() {
clear
hermes doctor
read -p "Press Enter to continue ..."
show_advanced
}
adv_logs() {
clear
if [ -f "$HERMES_HOME/logs/gateway.log" ]; then
echo -e "${CYAN}=== Gateway Log (last 20 lines) ===${RESET}"
tail -n 20 "$HERMES_HOME/logs/gateway.log"
else
echo -e "${YELLOW}No logs found.${RESET}"
fi
echo ""
read -p "Press Enter to continue ..."
show_advanced
}
adv_config() {
clear
hermes config edit
show_advanced
}
adv_restart() {
hermes gateway restart
echo ""
echo -e "${BRIGHT_GREEN}Gateway restarted.${RESET}"
read -p "Press Enter to continue ..."
detect_status
show_menu
}
adv_update() {
clear
hermes update
read -p "Press Enter to continue ..."
show_advanced
}
# ---------------------------------------------------------------------------
# Entry point
# ---------------------------------------------------------------------------
detect_status
show_menu