-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall-local.sh
More file actions
executable file
·478 lines (443 loc) · 14.6 KB
/
Copy pathinstall-local.sh
File metadata and controls
executable file
·478 lines (443 loc) · 14.6 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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
#!/usr/bin/env bash
set -euo pipefail
# AgentPulse local installer
# One-command Bun + SQLite deployment for macOS/Linux.
REPO_URL="https://github.com/jstuart0/agentpulse.git"
REPO_REF="main"
INSTALL_DIR="${HOME}/.agentpulse/app"
DATA_DIR="${HOME}/.agentpulse/data"
PORT="3000"
HOST="0.0.0.0"
PUBLIC_URL=""
DISABLE_AUTH="true"
API_KEY=""
AUTO_HOOKS="true"
AUTO_SUPERVISOR="true"
SERVICE_MODE="auto"
SERVICE_NAME="agentpulse"
while [[ $# -gt 0 ]]; do
case "$1" in
--ref) REPO_REF="$2"; shift 2 ;;
--repo) REPO_URL="$2"; shift 2 ;;
--dir) INSTALL_DIR="$2"; shift 2 ;;
--data-dir) DATA_DIR="$2"; shift 2 ;;
--port) PORT="$2"; shift 2 ;;
--host) HOST="$2"; shift 2 ;;
--public-url) PUBLIC_URL="$2"; shift 2 ;;
--disable-auth) DISABLE_AUTH="$2"; shift 2 ;;
--api-key) API_KEY="$2"; shift 2 ;;
--skip-hooks) AUTO_HOOKS="false"; shift 1 ;;
--skip-supervisor) AUTO_SUPERVISOR="false"; shift 1 ;;
--service) SERVICE_MODE="$2"; shift 2 ;;
-h|--help)
cat <<EOF
AgentPulse local installer
Usage:
curl -fsSL <script-url> | bash
Options:
--ref <git-ref> Git branch/tag to install (default: main)
--repo <git-url> Git repo to install from
--dir <path> Install directory (default: ~/.agentpulse/app)
--data-dir <path> SQLite/data directory (default: ~/.agentpulse/data)
--port <port> Web port (default: 3000)
--host <host> Bind host (default: 0.0.0.0)
--public-url <url> Public URL used for setup.sh output
--disable-auth <bool> Set DISABLE_AUTH (default: true)
--api-key <key> Set AGENTPULSE_INITIAL_API_KEY
--skip-hooks Do not auto-run setup.sh after install
--skip-supervisor Do not auto-install the local supervisor
--service <mode> auto | none | systemd | launchd
EOF
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
if [[ -z "${PUBLIC_URL}" ]]; then
PUBLIC_URL="http://localhost:${PORT}"
fi
echo ""
echo " AgentPulse Local Install"
echo " ────────────────────────"
echo " Repo: ${REPO_URL} (${REPO_REF})"
echo " Install: ${INSTALL_DIR}"
echo " Data: ${DATA_DIR}"
echo " URL: ${PUBLIC_URL}"
echo " Hooks: ${AUTO_HOOKS}"
echo " Supervisor: ${AUTO_SUPERVISOR}"
echo " Service: ${SERVICE_MODE}"
echo ""
need_cmd() {
command -v "$1" >/dev/null 2>&1
}
install_bun() {
if need_cmd bun; then
echo " ✓ Bun: $(command -v bun)"
return
fi
if [[ -x "${HOME}/.bun/bin/bun" ]]; then
export PATH="${HOME}/.bun/bin:${PATH}"
echo " ✓ Bun: ${HOME}/.bun/bin/bun"
return
fi
echo " Installing Bun..."
curl -fsSL https://bun.sh/install | bash >/dev/null 2>&1
export PATH="${HOME}/.bun/bin:${PATH}"
echo " ✓ Bun: ${HOME}/.bun/bin/bun"
}
if ! need_cmd git; then
echo "Error: git is required for local installation."
exit 1
fi
install_bun
mkdir -p "$(dirname "${INSTALL_DIR}")" "${DATA_DIR}"
if [[ -d "${INSTALL_DIR}/.git" ]]; then
echo " Updating existing checkout..."
git -C "${INSTALL_DIR}" fetch --tags origin
git -C "${INSTALL_DIR}" checkout "${REPO_REF}"
git -C "${INSTALL_DIR}" pull --ff-only origin "${REPO_REF}" || true
else
echo " Cloning repository..."
rm -rf "${INSTALL_DIR}"
git clone --branch "${REPO_REF}" --single-branch "${REPO_URL}" "${INSTALL_DIR}"
fi
cd "${INSTALL_DIR}"
echo " Installing dependencies..."
bun install
echo " Building application..."
NODE_ENV=production bun run build
ENV_FILE="${INSTALL_DIR}/.env.local"
cat > "${ENV_FILE}" <<EOF
PORT=${PORT}
HOST=${HOST}
PUBLIC_URL=${PUBLIC_URL}
DISABLE_AUTH=${DISABLE_AUTH}
AGENTPULSE_INITIAL_API_KEY=${API_KEY}
DATA_DIR=${DATA_DIR}
SQLITE_PATH=${DATA_DIR}/agentpulse.db
NODE_ENV=production
EOF
echo " ✓ Wrote ${ENV_FILE}"
AGENTPULSE_DIR="${HOME}/.agentpulse"
LOG_DIR="${AGENTPULSE_DIR}/logs"
SUPERVISOR_CONFIG_FILE="${AGENTPULSE_DIR}/supervisor.json"
SUPERVISOR_ENROLLMENT_TOKEN=""
mkdir -p "${AGENTPULSE_DIR}" "${LOG_DIR}"
json_escape() {
python3 - "$1" <<'PY'
import json, sys
print(json.dumps(sys.argv[1]))
PY
}
configure_supervisor() {
local trusted_root="${HOME}/dev"
if [[ ! -d "${trusted_root}" ]]; then
trusted_root="${HOME}"
fi
local enrollment_json="null"
local api_key_json="null"
local claude_json="null"
local codex_json="null"
if [[ -n "${SUPERVISOR_ENROLLMENT_TOKEN}" ]]; then
enrollment_json="$(json_escape "${SUPERVISOR_ENROLLMENT_TOKEN}")"
fi
if [[ -n "${API_KEY}" ]]; then
api_key_json="$(json_escape "${API_KEY}")"
fi
if command -v claude >/dev/null 2>&1; then
claude_json="$(json_escape "$(command -v claude)")"
fi
if command -v codex >/dev/null 2>&1; then
codex_json="$(json_escape "$(command -v codex)")"
fi
python3 - "${SUPERVISOR_CONFIG_FILE}" "${PUBLIC_URL}" "${trusted_root}" "${enrollment_json}" "${api_key_json}" "${claude_json}" "${codex_json}" <<'PY'
import json, os, socket, sys
path, server_url, trusted_root, enrollment_json, api_key_json, claude_json, codex_json = sys.argv[1:]
data = {}
if os.path.exists(path):
with open(path) as f:
data = json.load(f)
data["serverUrl"] = server_url
data["hostName"] = data.get("hostName") or socket.gethostname()
data["trustedRoots"] = data.get("trustedRoots") or [trusted_root]
enrollment = json.loads(enrollment_json)
if enrollment:
data["enrollmentToken"] = enrollment
api_key = json.loads(api_key_json)
if api_key:
data["apiKey"] = api_key
claude = json.loads(claude_json)
if claude:
data["claudeCommand"] = claude
codex = json.loads(codex_json)
if codex:
data["codexCommand"] = codex
with open(path, "w") as f:
json.dump(data, f, indent=2)
f.write("\n")
PY
echo " ✓ Wrote ${SUPERVISOR_CONFIG_FILE}"
}
create_systemd() {
mkdir -p "${HOME}/.config/systemd/user"
local unit="${HOME}/.config/systemd/user/${SERVICE_NAME}.service"
cat > "${unit}" <<EOF
[Unit]
Description=AgentPulse local server
After=network.target
[Service]
Type=simple
WorkingDirectory=${INSTALL_DIR}
EnvironmentFile=${ENV_FILE}
Environment=HOME=${HOME}
Environment=PATH=${HOME}/.bun/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
ExecStart=${HOME}/.bun/bin/bun run start
Restart=always
RestartSec=3
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now "${SERVICE_NAME}" >/dev/null
echo " ✓ systemd user service started"
echo " Logs: journalctl --user -u ${SERVICE_NAME} -f"
}
create_supervisor_systemd() {
mkdir -p "${HOME}/.config/systemd/user"
local unit="${HOME}/.config/systemd/user/${SERVICE_NAME}-supervisor.service"
cat > "${unit}" <<EOF
[Unit]
Description=AgentPulse local supervisor
After=network.target ${SERVICE_NAME}.service
[Service]
Type=simple
WorkingDirectory=${INSTALL_DIR}
EnvironmentFile=${ENV_FILE}
Environment=HOME=${HOME}
Environment=PATH=${HOME}/.bun/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
ExecStart=${HOME}/.bun/bin/bun run supervisor
Restart=always
RestartSec=3
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now "${SERVICE_NAME}-supervisor" >/dev/null
echo " ✓ systemd supervisor started"
echo " Logs: journalctl --user -u ${SERVICE_NAME}-supervisor -f"
}
create_launchd() {
mkdir -p "${HOME}/Library/LaunchAgents" "${LOG_DIR}"
local plist="${HOME}/Library/LaunchAgents/dev.agentpulse.local.plist"
cat > "${plist}" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>dev.agentpulse.local</string>
<key>ProgramArguments</key>
<array>
<string>${HOME}/.bun/bin/bun</string>
<string>run</string>
<string>start</string>
</array>
<key>WorkingDirectory</key>
<string>${INSTALL_DIR}</string>
<key>EnvironmentVariables</key>
<dict>
<key>HOME</key><string>${HOME}</string>
<key>PATH</key><string>${HOME}/.bun/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
<key>PORT</key><string>${PORT}</string>
<key>HOST</key><string>${HOST}</string>
<key>PUBLIC_URL</key><string>${PUBLIC_URL}</string>
<key>DISABLE_AUTH</key><string>${DISABLE_AUTH}</string>
<key>AGENTPULSE_INITIAL_API_KEY</key><string>${API_KEY}</string>
<key>DATA_DIR</key><string>${DATA_DIR}</string>
<key>SQLITE_PATH</key><string>${DATA_DIR}/agentpulse.db</string>
<key>NODE_ENV</key><string>production</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>${LOG_DIR}/agentpulse.out.log</string>
<key>StandardErrorPath</key>
<string>${LOG_DIR}/agentpulse.err.log</string>
</dict>
</plist>
EOF
launchctl unload "${plist}" >/dev/null 2>&1 || true
launchctl load "${plist}"
echo " ✓ launchd service started"
echo " Logs: tail -f ${LOG_DIR}/agentpulse.out.log"
}
create_supervisor_launchd() {
mkdir -p "${HOME}/Library/LaunchAgents" "${LOG_DIR}"
local plist="${HOME}/Library/LaunchAgents/dev.agentpulse.supervisor.plist"
cat > "${plist}" <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>dev.agentpulse.supervisor</string>
<key>ProgramArguments</key>
<array>
<string>${HOME}/.bun/bin/bun</string>
<string>run</string>
<string>supervisor</string>
</array>
<key>WorkingDirectory</key>
<string>${INSTALL_DIR}</string>
<key>EnvironmentVariables</key>
<dict>
<key>HOME</key><string>${HOME}</string>
<key>PATH</key><string>${HOME}/.bun/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
<key>PORT</key><string>${PORT}</string>
<key>HOST</key><string>${HOST}</string>
<key>PUBLIC_URL</key><string>${PUBLIC_URL}</string>
<key>DISABLE_AUTH</key><string>${DISABLE_AUTH}</string>
<key>AGENTPULSE_INITIAL_API_KEY</key><string>${API_KEY}</string>
<key>DATA_DIR</key><string>${DATA_DIR}</string>
<key>SQLITE_PATH</key><string>${DATA_DIR}/agentpulse.db</string>
<key>NODE_ENV</key><string>production</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>ThrottleInterval</key>
<integer>10</integer>
<key>StandardOutPath</key>
<string>${LOG_DIR}/supervisor.out.log</string>
<key>StandardErrorPath</key>
<string>${LOG_DIR}/supervisor.err.log</string>
</dict>
</plist>
EOF
launchctl unload "${plist}" >/dev/null 2>&1 || true
launchctl load "${plist}"
echo " ✓ launchd supervisor started"
echo " Logs: tail -f ${LOG_DIR}/supervisor.out.log"
}
if [[ "${SERVICE_MODE}" == "auto" ]]; then
if [[ "$(uname)" == "Darwin" ]]; then
SERVICE_MODE="launchd"
elif need_cmd systemctl; then
SERVICE_MODE="systemd"
else
SERVICE_MODE="none"
fi
fi
case "${SERVICE_MODE}" in
systemd)
create_systemd
;;
launchd)
create_launchd
;;
none)
echo " Starting AgentPulse in the background..."
env $(tr '\n' ' ' < "${ENV_FILE}") "${HOME}/.bun/bin/bun" run start > "${LOG_DIR}/agentpulse.out.log" 2>&1 &
echo $! > "${AGENTPULSE_DIR}/agentpulse.pid"
echo " ✓ Started background process"
echo " Logs: tail -f ${LOG_DIR}/agentpulse.out.log"
;;
*)
echo "Error: unsupported --service mode '${SERVICE_MODE}'"
exit 1
;;
esac
echo ""
echo " Waiting for AgentPulse to start..."
for _ in $(seq 1 30); do
if curl -fsSL "${PUBLIC_URL}/api/v1/health" >/dev/null 2>&1; then
echo " ✓ AgentPulse is running at ${PUBLIC_URL}"
echo ""
if [[ "${AUTO_SUPERVISOR}" == "true" ]]; then
if [[ "${DISABLE_AUTH}" != "true" ]]; then
if [[ -n "${API_KEY}" ]]; then
echo " Creating local supervisor enrollment token..."
SUPERVISOR_ENROLLMENT_TOKEN="$(
curl -fsSL -X POST \
-H "Authorization: Bearer ${API_KEY}" \
-H "Content-Type: application/json" \
"${PUBLIC_URL}/api/v1/supervisors/enroll" \
-d '{"name":"local-supervisor"}' \
| python3 -c 'import json,sys; print(json.load(sys.stdin)["token"])'
)"
echo " ✓ Enrollment token issued"
else
echo " ! Skipping supervisor auto-install because auth is enabled and no --api-key was provided."
echo " Add a supervisor later from Hosts, or rerun with --api-key."
echo ""
fi
fi
if [[ "${DISABLE_AUTH}" == "true" || -n "${SUPERVISOR_ENROLLMENT_TOKEN}" ]]; then
echo " Configuring local supervisor..."
configure_supervisor
case "${SERVICE_MODE}" in
systemd)
create_supervisor_systemd
;;
launchd)
create_supervisor_launchd
;;
none)
echo " Starting AgentPulse supervisor in the background..."
HOME="${HOME}" PATH="${HOME}/.bun/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" \
env $(tr '\n' ' ' < "${ENV_FILE}") "${HOME}/.bun/bin/bun" run supervisor > "${LOG_DIR}/supervisor.out.log" 2> "${LOG_DIR}/supervisor.err.log" &
echo $! > "${AGENTPULSE_DIR}/supervisor.pid"
echo " ✓ Started background supervisor"
echo " Logs: tail -f ${LOG_DIR}/supervisor.out.log"
;;
esac
echo ""
fi
fi
if [[ "${AUTO_HOOKS}" == "true" ]]; then
if [[ "${DISABLE_AUTH}" == "true" ]]; then
echo " Configuring Claude Code + Codex hooks..."
curl -fsSL "${PUBLIC_URL}/setup.sh" | bash
echo ""
echo " ✓ Hooks configured"
elif [[ -n "${API_KEY}" ]]; then
echo " Configuring Claude Code + Codex hooks with API key..."
curl -fsSL "${PUBLIC_URL}/setup.sh" | bash -s -- --key "${API_KEY}"
echo ""
echo " ✓ Hooks configured"
else
echo " ! Skipping automatic hook setup because auth is enabled and no --api-key was provided."
echo " Run this next:"
echo " curl -sSL ${PUBLIC_URL}/setup.sh | bash -s -- --key ap_YOUR_KEY"
echo ""
fi
else
echo " Next step:"
echo " curl -sSL ${PUBLIC_URL}/setup.sh | bash"
echo ""
fi
echo " Local control plane:"
if [[ "${AUTO_SUPERVISOR}" == "true" ]]; then
echo " enabled"
else
echo " skipped (--skip-supervisor)"
fi
echo " Open:"
echo " ${PUBLIC_URL}"
exit 0
fi
sleep 1
done
echo ""
echo " AgentPulse was installed but the health check did not pass in time."
echo " Try starting it manually:"
echo " cd ${INSTALL_DIR}"
echo " export \$(cat .env.local | xargs)"
echo " ${HOME}/.bun/bin/bun run start"
exit 1