-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·834 lines (747 loc) · 37.2 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·834 lines (747 loc) · 37.2 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
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
#!/bin/bash
# JAT (Jomarchy Agent Tools) Installer
# Complete AI-assisted development environment setup
# https://github.com/joewinke/jat
set -e # Exit on error
# Ensure ~/.local/bin is in PATH for this session
# Tools install there, but on fresh systems (especially macOS) it's not in PATH yet
if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
export PATH="$HOME/.local/bin:$PATH"
fi
# Color codes
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BOLD='\033[1m'
NC='\033[0m'
# Helper function for safe user input
# Handles piped execution (curl | bash) by reading from /dev/tty
# Falls back to non-interactive defaults when TTY unavailable
prompt_user() {
local prompt="$1"
local default="$2"
local varname="$3"
echo -en "$prompt"
# Check if /dev/tty is available for interactive input
if [ -t 0 ] || [ -e /dev/tty ]; then
read -r response </dev/tty 2>/dev/null || response="$default"
else
# Non-interactive mode (e.g., Docker build, CI)
echo ""
echo -e "${YELLOW} (non-interactive mode - using default: ${default:-empty})${NC}"
response="$default"
fi
eval "$varname=\"\$response\""
}
# Helper function for yes/no prompts
# Returns 0 for yes, 1 for no
# default: "y" means empty response = yes, "n" means empty response = no
prompt_yes_no() {
local prompt="$1"
local default="$2" # "y" or "n"
local response
prompt_user "$prompt" "" "response"
# Empty response uses default
if [ -z "$response" ]; then
[ "$default" = "y" ] || [ "$default" = "Y" ]
return $?
fi
# Check for explicit yes/no
case "$response" in
[yY]|[yY][eE][sS])
return 0
;;
*)
return 1
;;
esac
}
# Poll /health up to 10 times, print summary table; return 1 if never responds
verify_install() {
local port="${PORT:-8080}"
local url="http://localhost:${port}/health"
local max_attempts=10
local attempt=0
local health_data=""
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Post-Install Verification${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
echo -n " Polling $url"
while [ $attempt -lt $max_attempts ]; do
attempt=$((attempt + 1))
echo -n "."
if command -v curl &>/dev/null; then
health_data=$(curl -sf --max-time 2 "$url" 2>/dev/null || true)
elif command -v wget &>/dev/null; then
health_data=$(wget -qO- --timeout=2 "$url" 2>/dev/null || true)
fi
if [ -n "$health_data" ]; then
echo ""
break
fi
[ $attempt -lt $max_attempts ] && sleep 3
done
if [ -z "$health_data" ]; then
echo ""
echo ""
echo -e " ${RED}✗ jat-inference did not respond after $max_attempts attempts${NC}"
if [ "$(uname -s)" = "Linux" ]; then
echo -e " systemctl --user status jat-inference"
echo -e " journalctl --user -u jat-inference -n 20"
elif [ "$(uname -s)" = "Darwin" ]; then
echo -e " launchctl list com.jat.inference"
fi
echo ""
return 1
fi
local svc_status device llm_ok diarize_ok models_str
svc_status=$(printf '%s' "$health_data" | jq -r '.status // "unknown"' 2>/dev/null)
device=$(printf '%s' "$health_data" | jq -r '.device // "unknown"' 2>/dev/null)
llm_ok=$(printf '%s' "$health_data" | jq -r '.llm' 2>/dev/null)
diarize_ok=$(printf '%s' "$health_data" | jq -r '.diarize' 2>/dev/null)
models_str=$(printf '%s' "$health_data" | jq -r '.models | if length > 0 then join(", ") else "(none loaded)" end' 2>/dev/null)
local llm_disp whisperx_disp svc_disp
[ "$llm_ok" = "true" ] && llm_disp="${GREEN}✓${NC} ready" || llm_disp="${YELLOW}✗${NC} not found"
[ "$diarize_ok" = "true" ] && whisperx_disp="${GREEN}✓${NC} ready" || whisperx_disp="${YELLOW}✗${NC} not found"
[ "$svc_status" = "ok" ] && svc_disp="${GREEN}ok${NC}" || svc_disp="${RED}$svc_status${NC}"
echo ""
echo -e " ${BOLD}Component Status${NC}"
echo " ──────────────── ─────────────────────────"
printf " %-16s " "Service"; echo -e "$svc_disp"
printf " %-16s %s\n" "Device" "$device"
printf " %-16s " "Ollama"; echo -e "$llm_disp"
if [ "$llm_ok" = "true" ]; then
printf " %-16s %s\n" " Models" "$models_str"
fi
printf " %-16s " "WhisperX"; echo -e "$whisperx_disp"
printf " %-16s %s\n" "URL" "$url"
echo ""
}
# Check if running as root
if [ "$EUID" -eq 0 ]; then
sudo() { "$@"; }
fi
# Check for required dependencies
MISSING_DEPS=""
if ! command -v tmux &> /dev/null; then
MISSING_DEPS="$MISSING_DEPS tmux"
fi
if ! command -v sqlite3 &> /dev/null; then
MISSING_DEPS="$MISSING_DEPS sqlite3"
fi
if ! command -v jq &> /dev/null; then
MISSING_DEPS="$MISSING_DEPS jq"
fi
if [ -n "$MISSING_DEPS" ]; then
echo -e "${YELLOW}⚠ Missing required dependencies:${NC}$MISSING_DEPS"
echo ""
# Detect package manager and build install command
PKG_MANAGER=""
INSTALL_CMD=""
if command -v pacman &> /dev/null; then
PKG_MANAGER="pacman"
INSTALL_CMD="sudo pacman -S --noconfirm$MISSING_DEPS"
elif command -v apt &> /dev/null; then
PKG_MANAGER="apt"
# Update package lists first for fresh systems
INSTALL_CMD="sudo apt update && sudo apt install -y$MISSING_DEPS"
elif command -v dnf &> /dev/null; then
PKG_MANAGER="dnf"
INSTALL_CMD="sudo dnf install -y$MISSING_DEPS"
elif command -v yum &> /dev/null; then
PKG_MANAGER="yum"
INSTALL_CMD="sudo yum install -y$MISSING_DEPS"
elif command -v zypper &> /dev/null; then
PKG_MANAGER="zypper"
INSTALL_CMD="sudo zypper install -y$MISSING_DEPS"
elif command -v brew &> /dev/null; then
PKG_MANAGER="brew"
INSTALL_CMD="brew install$MISSING_DEPS"
elif command -v apk &> /dev/null; then
PKG_MANAGER="apk"
INSTALL_CMD="sudo apk add$MISSING_DEPS"
fi
if [ -n "$PKG_MANAGER" ]; then
echo -e "Detected package manager: ${BOLD}$PKG_MANAGER${NC}"
echo -e "Command: ${BLUE}$INSTALL_CMD${NC}"
echo ""
if prompt_yes_no "${BLUE}Would you like to install them now? [Y/n]${NC} " "y"; then
echo ""
echo -e "${BLUE}Installing dependencies...${NC}"
echo ""
# Run installation with visible output
if eval "$INSTALL_CMD"; then
echo ""
echo -e "${GREEN}✓ Dependencies installed successfully${NC}"
echo ""
# Verify installation
STILL_MISSING=""
for dep in $MISSING_DEPS; do
if ! command -v "$dep" &> /dev/null; then
STILL_MISSING="$STILL_MISSING $dep"
fi
done
if [ -n "$STILL_MISSING" ]; then
echo -e "${YELLOW}⚠ Some dependencies may not be in PATH:${NC}$STILL_MISSING"
echo " You may need to open a new terminal or run: source ~/$([ "$(basename "$SHELL")" = "zsh" ] && echo ".zshrc" || echo ".bashrc")"
echo ""
fi
else
echo ""
echo -e "${RED}ERROR: Failed to install dependencies${NC}"
echo ""
echo "Possible causes:"
echo " • Network issues - check your internet connection"
echo " • Permission denied - ensure you can run sudo"
echo " • Package not found - the package may have a different name"
echo ""
echo "Try installing manually:"
echo " $INSTALL_CMD"
echo ""
echo "Then re-run this script."
exit 1
fi
else
echo ""
echo -e "${YELLOW}Installation skipped.${NC}"
echo ""
echo "JAT requires these dependencies to function properly."
echo "Install them manually with:"
echo ""
echo " $INSTALL_CMD"
echo ""
echo "Then re-run this script."
exit 1
fi
else
echo -e "${RED}ERROR: Could not detect a supported package manager${NC}"
echo ""
echo "JAT supports: pacman, apt, dnf, yum, zypper, brew, apk"
echo ""
echo "Install dependencies manually using your package manager:"
echo ""
echo " # Arch/Manjaro"
echo " sudo pacman -S$MISSING_DEPS"
echo ""
echo " # Debian/Ubuntu"
echo " sudo apt install$MISSING_DEPS"
echo ""
echo " # Fedora"
echo " sudo dnf install$MISSING_DEPS"
echo ""
echo " # openSUSE"
echo " sudo zypper install$MISSING_DEPS"
echo ""
echo " # macOS"
echo " brew install$MISSING_DEPS"
echo ""
echo " # Alpine"
echo " apk add$MISSING_DEPS"
echo ""
echo "Then re-run this script."
exit 1
fi
fi
# Determine installation directory
# Priority: JAT_INSTALL_DIR env var > XDG standard > legacy ~/code locations
# Determine installation directory
# Priority: JAT_INSTALL_DIR env var > current dir (if JAT repo) > XDG location
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -n "$JAT_INSTALL_DIR" ]; then
# User specified custom location via environment variable
INSTALL_DIR="$JAT_INSTALL_DIR"
echo -e "${BLUE}Using JAT_INSTALL_DIR: $INSTALL_DIR${NC}"
elif [ -f "$SCRIPT_DIR/install.sh" ] && [ -d "$SCRIPT_DIR/tools" ] && [ -d "$SCRIPT_DIR/ide" ]; then
# Running from a JAT repo (developer mode)
INSTALL_DIR="$SCRIPT_DIR"
echo -e "${BLUE}Using current JAT repo: $INSTALL_DIR${NC}"
elif [ -d "${XDG_DATA_HOME:-$HOME/.local/share}/jat" ]; then
# Existing XDG installation
INSTALL_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/jat"
echo -e "${BLUE}Using existing installation: $INSTALL_DIR${NC}"
else
# New installation - clone to XDG location
INSTALL_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/jat"
echo -e "${BLUE}Installing to: $INSTALL_DIR${NC}"
mkdir -p "$(dirname "$INSTALL_DIR")"
git clone https://github.com/joewinke/jat.git "$INSTALL_DIR"
fi
cd "$INSTALL_DIR"
echo ""
# Gradient logo (blue → sky → lavender → teal) - matches jat CLI
B=$'\033[1m' R=$'\033[0m'
b1=$'\033[38;5;33m' b2=$'\033[38;5;39m' # J: blue tones
b3=$'\033[38;5;75m' b4=$'\033[38;5;111m' # A: sky/periwinkle
b5=$'\033[38;5;147m' b6=$'\033[38;5;183m' # T: lavender/lilac
b7=$'\033[38;5;80m' # T stem: teal
d=$'\033[2m' # dim for tagline
echo "${b1}${B} ╔───────────────${b3}───────────────${b5}─────────────╗${R}"
echo "${b1}${B} │${R} ${b5}${B}│${R}"
echo "${b1}${B} │${R}${b1}${B} __${R} ${b3}${B}___${R} ${b5}${B}.___________.${R} ${b5}${B}│${R}"
echo "${b1}${B} │${R}${b1}${B} | |${R} ${b3}${B}/ \\ ${R} ${b5}${B}| |${R} ${b5}${B}│${R}"
echo "${b1}${B} │${R}${b1}${B} | |${R} ${b3}${B}/ ^ \\ ${R}${b5}${B}\`---| |----\`${R} ${b5}${B}│${R}"
echo "${b2}${B} │${R}${b2}${B} .--. | |${R} ${b4}${B}/ /_\\ \\ ${R} ${b6}${B}| |${R} ${b6}${B}│${R}"
echo "${b2}${B} │${R}${b2}${B} | \`--' |${R} ${b4}${B}/ _____ \\ ${R} ${b6}${B}| |${R} ${b6}${B}│${R}"
echo "${b2}${B} │${R}${b2}${B} \\______/${R} ${b4}${B}/__/ \\__\\ ${R} ${b7}${B}|__|${R} ${b7}${B}│${R}"
echo "${b2}${B} │${R} ${b7}${B}│${R}"
echo "${b2}${B} │${R}${d} ◇ Supervise the Swarm ◇${R} ${b7}${B}│${R}"
echo "${b3}${B} │${R} ${b7}${B}│${R}"
echo "${b3}${B} ╚───────────────${b5}───────────────${b7}─────────────╝${R}"
echo ""
echo "The world's first agentic IDE. Agents ship, you supervise."
echo ""
echo " • Multi-agent orchestration (20+ agents simultaneously)"
echo " • Full IDE: Monaco editor, git, task management"
echo " • Epic Swarm: spawn parallel agents on subtasks"
echo " • Smart question UI: agent questions become buttons"
echo " • Auto-proceed rules for hands-off completion"
echo " • 50+ CLI tools (agent mail, browser, media, db)"
echo " • Works with Claude Code, Codex, Gemini, Aider"
echo " • 100% local, open source (MIT)"
echo ""
# Only pause for confirmation on first install, not re-runs
if [ ! -x "$HOME/.local/bin/jat" ]; then
echo -e "${YELLOW}Press ENTER to continue or Ctrl+C to cancel${NC}"
if [ -t 0 ] || [ -e /dev/tty ]; then
read </dev/tty 2>/dev/null || true
else
echo -e "${BLUE} (non-interactive mode - continuing automatically)${NC}"
fi
else
echo -e "${DIM}Re-run detected — updating...${NC}"
fi
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Step 1/10: Installing Agent Registry (bash + SQLite)${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
bash "$INSTALL_DIR/tools/scripts/install-agent-mail.sh"
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Step 2/10: Setting Up JAT Task CLI${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# jt CLI is symlinked via symlink-tools.sh (Step 3)
# Just verify the binary exists
if [ -f "$INSTALL_DIR/cli/jat" ]; then
echo -e " ${GREEN}✓${NC} JAT CLI found (will be symlinked in next step)"
else
echo -e " ${YELLOW}⚠${NC} JAT CLI not found at $INSTALL_DIR/cli/jat"
fi
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Step 3/10: Symlinking Generic Tools${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
bash "$INSTALL_DIR/tools/scripts/symlink-tools.sh"
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Step 4/10: Installing Node.js Dependencies${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# Check if npm is available
if command -v npm &> /dev/null; then
# Check Node.js version (need LTS: 20 or 22, not odd/current like 23/25)
NODE_MAJOR=$(node -v 2>/dev/null | sed 's/v\([0-9]*\).*/\1/')
if [ -n "$NODE_MAJOR" ] && [ "$NODE_MAJOR" -gt 22 ] 2>/dev/null; then
echo -e "${YELLOW} ⚠ Node.js v$(node -v | sed 's/v//') detected - this may cause build failures${NC}"
echo -e "${YELLOW} JAT requires Node.js 20 or 22 (LTS). Current/odd versions (23, 25)${NC}"
echo -e "${YELLOW} break native modules like better-sqlite3.${NC}"
echo ""
echo -e " Fix with nvm: ${BOLD}nvm install 22 && nvm use 22${NC}"
echo -e " Or Homebrew: ${BOLD}brew install node@22 && brew link --overwrite node@22${NC}"
echo ""
fi
# Install root jat dependencies (better-sqlite3 for lib/tasks.js)
if [ -f "$INSTALL_DIR/package.json" ]; then
echo " → Installing jat core dependencies..."
(cd "$INSTALL_DIR" && npm install --silent 2>/dev/null) && \
echo -e " ${GREEN}✓${NC} jat core dependencies installed" || \
echo -e " ${YELLOW}⚠${NC} jat npm install failed (run manually: cd ~/code/jat && npm install)"
fi
# Install browser-tools dependencies (puppeteer-core, cheerio)
if [ -f "$INSTALL_DIR/tools/browser/package.json" ]; then
echo " → Installing browser-tools dependencies..."
(cd "$INSTALL_DIR/tools/browser" && npm install --silent 2>/dev/null) && \
echo -e " ${GREEN}✓${NC} browser-tools dependencies installed" || \
echo -e " ${YELLOW}⚠${NC} browser-tools npm install failed (run manually: cd tools/browser && npm install)"
fi
# Install ingest daemon dependencies (better-sqlite3, rss-parser)
if [ -f "$INSTALL_DIR/tools/ingest/package.json" ]; then
echo " → Installing ingest daemon dependencies..."
(cd "$INSTALL_DIR/tools/ingest" && npm install --silent 2>/dev/null) && \
echo -e " ${GREEN}✓${NC} ingest daemon dependencies installed" || \
echo -e " ${YELLOW}⚠${NC} ingest npm install failed (run manually: cd tools/ingest && npm install)"
fi
# Install inference relay dependencies (infra/jat-inference/)
if [ -f "$INSTALL_DIR/infra/jat-inference/package.json" ]; then
echo " → Installing inference relay dependencies..."
(cd "$INSTALL_DIR/infra/jat-inference" && npm install --silent 2>/dev/null) && \
echo -e " ${GREEN}✓${NC} inference relay dependencies installed" || \
echo -e " ${YELLOW}⚠${NC} relay npm install failed (run manually: cd infra/jat-inference && npm install)"
# Write jat-inference launcher to ~/.local/bin/
INFERENCE_BIN="$HOME/.local/bin/jat-inference"
printf '#!/bin/bash\n# jat-inference: Launch the JAT Inference Relay\n# Proxies Ollama /v1/* and handles whisperx diarization\n# Required env vars: INFERENCE_SECRET, PORT (default 8080), OLLAMA_URL\nexec node "%s/infra/jat-inference/server.js" "$@"\n' "$INSTALL_DIR" > "$INFERENCE_BIN"
chmod +x "$INFERENCE_BIN"
echo -e " ${GREEN}✓${NC} jat-inference launcher written to $INFERENCE_BIN"
# On Linux: write systemd user unit and enable/start it
if [ "$(uname -s)" = "Linux" ]; then
SYSTEMD_USER_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
mkdir -p "$SYSTEMD_USER_DIR"
cat > "$SYSTEMD_USER_DIR/jat-inference.service" <<'UNIT'
[Unit]
Description=JAT Inference Relay
After=network.target
[Service]
Type=simple
ExecStart=%h/.local/bin/jat-inference
Restart=on-failure
RestartSec=5
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=default.target
UNIT
echo -e " ${GREEN}✓${NC} systemd user unit written to $SYSTEMD_USER_DIR/jat-inference.service"
if systemctl --user daemon-reload 2>/dev/null; then
systemctl --user enable jat-inference 2>/dev/null && \
echo -e " ${GREEN}✓${NC} jat-inference service enabled" || \
echo -e " ${YELLOW}⚠${NC} Could not enable service (run: systemctl --user enable jat-inference)"
if systemctl --user is-active --quiet jat-inference 2>/dev/null; then
systemctl --user restart jat-inference 2>/dev/null && \
echo -e " ${GREEN}✓${NC} jat-inference service restarted" || \
echo -e " ${YELLOW}⚠${NC} Service restart failed — set INFERENCE_SECRET then: systemctl --user restart jat-inference"
else
systemctl --user start jat-inference 2>/dev/null && \
echo -e " ${GREEN}✓${NC} jat-inference service started" || \
echo -e " ${YELLOW}⚠${NC} Service start failed — set INFERENCE_SECRET then: systemctl --user start jat-inference"
fi
else
echo -e " ${YELLOW}⚠${NC} systemd user session unavailable — enable manually:"
echo -e " systemctl --user enable --now jat-inference"
fi
fi
# macOS: register jat-inference as a launchd user agent
if [ "$(uname -s)" = "Darwin" ]; then
LAUNCH_AGENTS_DIR="$HOME/Library/LaunchAgents"
PLIST_PATH="$LAUNCH_AGENTS_DIR/com.jat.inference.plist"
LOG_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/jat/logs"
mkdir -p "$LAUNCH_AGENTS_DIR" "$LOG_DIR"
# Retrieve INFERENCE_SECRET from jat-secret vault
INFERENCE_SECRET_VAL=$(jat-secret inference-secret 2>/dev/null || echo "")
if [ -z "$INFERENCE_SECRET_VAL" ]; then
echo -e " ${YELLOW}⚠${NC} inference-secret not found in jat-secret"
echo -e " Set it and re-run install.sh to bake it into the plist:"
echo -e " ${BOLD}jat-secret --set inference-secret <your-secret>${NC}"
INFERENCE_SECRET_VAL="REPLACE_ME"
fi
# Retrieve HF_TOKEN — required by whisperx-diarize.py for pyannote model download
HF_TOKEN_VAL=$(jat-secret hf-token 2>/dev/null || echo "")
if [ -z "$HF_TOKEN_VAL" ]; then
echo -e " ${YELLOW}⚠${NC} hf-token not found in jat-secret (needed for whisperx diarization)"
echo -e " Get a token at https://huggingface.co/settings/tokens then:"
echo -e " ${BOLD}jat-secret --set hf-token <your-token>${NC}"
echo -e " Then re-run install.sh to bake it into the plist."
HF_TOKEN_VAL="REPLACE_ME"
fi
cat > "$PLIST_PATH" <<PLIST
<?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>com.jat.inference</string>
<key>ProgramArguments</key>
<array>
<string>${INFERENCE_BIN}</string>
</array>
<key>EnvironmentVariables</key>
<dict>
<key>INFERENCE_SECRET</key>
<string>${INFERENCE_SECRET_VAL}</string>
<key>PORT</key>
<string>8080</string>
<key>OLLAMA_URL</key>
<string>http://localhost:11434</string>
<key>HF_TOKEN</key>
<string>${HF_TOKEN_VAL}</string>
<key>PATH</key>
<string>/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>${LOG_DIR}/inference.log</string>
<key>StandardErrorPath</key>
<string>${LOG_DIR}/inference-error.log</string>
</dict>
</plist>
PLIST
echo -e " ${GREEN}✓${NC} launchd plist written to $PLIST_PATH"
# Unload any existing instance then load fresh
launchctl unload "$PLIST_PATH" 2>/dev/null || true
if launchctl load -w "$PLIST_PATH" 2>/dev/null; then
echo -e " ${GREEN}✓${NC} jat-inference service loaded via launchctl"
else
echo -e " ${YELLOW}⚠${NC} launchctl load failed — load manually:"
echo -e " ${BOLD}launchctl load -w $PLIST_PATH${NC}"
fi
fi
fi
# Install IDE dependencies (SvelteKit, etc.)
if [ -f "$INSTALL_DIR/ide/package.json" ]; then
echo " → Installing IDE dependencies..."
if (cd "$INSTALL_DIR/ide" && npm install --legacy-peer-deps --engine-strict=false 2>&1); then
echo -e " ${GREEN}✓${NC} IDE dependencies installed"
# On headless servers, pre-build the IDE for production
# (Vite dev server uses ~800MB — too much for small VPS instances)
if [ -z "${DISPLAY:-}" ] && [ -z "${WAYLAND_DISPLAY:-}" ]; then
echo " → Building IDE for production (headless server)..."
if (cd "$INSTALL_DIR/ide" && NODE_OPTIONS="--max-old-space-size=2048" npx vite build 2>&1); then
echo -e " ${GREEN}✓${NC} IDE production build complete"
else
echo -e " ${YELLOW}⚠${NC} IDE build failed — build locally and sync:"
echo -e " ${BOLD}cd ide && npm run build${NC}"
echo -e " ${BOLD}tar -czf /tmp/ide-build.tar.gz build/${NC}"
echo -e " ${BOLD}scp /tmp/ide-build.tar.gz root@<vps>:/tmp/${NC}"
echo -e " ${BOLD}ssh root@<vps> 'cd ~/.local/share/jat/ide && tar -xzf /tmp/ide-build.tar.gz'${NC}"
fi
fi
else
echo -e " ${YELLOW}⚠${NC} IDE npm install failed (run manually: cd ide && npm install --legacy-peer-deps)"
if [ "$(uname -s)" = "Darwin" ]; then
echo -e " ${YELLOW} On macOS, you may need Xcode Command Line Tools:${NC}"
echo -e " ${YELLOW} xcode-select --install${NC}"
fi
fi
fi
else
echo -e "${YELLOW} ⚠ npm not found - skipping Node.js dependencies${NC}"
echo " Install Node.js/npm, then run manually:"
echo " cd $INSTALL_DIR && npm install"
echo " cd $INSTALL_DIR/tools/browser && npm install"
echo " cd $INSTALL_DIR/ide && npm install"
fi
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Step 5/10: WhisperX Voice Diarization${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
WHISPERX_VENV="${XDG_DATA_HOME:-$HOME/.local/share}/whisperx-env"
DIARIZE_SRC="$INSTALL_DIR/ide/src/lib/server/whisperx-diarize.py"
DIARIZE_DST="$WHISPERX_VENV/bin/whisperx-diarize.py"
WHISPERX_OK=false
if command -v python3 &>/dev/null; then
if python3 -c "import sys; assert sys.version_info >= (3, 10)" 2>/dev/null; then
# Create venv if it doesn't exist
if [ ! -x "$WHISPERX_VENV/bin/python3" ]; then
echo " → Creating Python venv at $WHISPERX_VENV..."
if python3 -m venv "$WHISPERX_VENV" 2>&1; then
echo -e " ${GREEN}✓${NC} Python venv created"
else
echo -e " ${YELLOW}⚠${NC} Failed to create venv — skipping whisperx"
fi
else
echo -e " ${GREEN}✓${NC} Python venv exists ($WHISPERX_VENV)"
fi
if [ -x "$WHISPERX_VENV/bin/python3" ]; then
echo " → Installing whisperx + pyannote.audio (may take several minutes)..."
if "$WHISPERX_VENV/bin/pip" install --quiet --upgrade pip wheel 2>/dev/null && \
"$WHISPERX_VENV/bin/pip" install --quiet whisperx pyannote.audio 2>/dev/null; then
echo -e " ${GREEN}✓${NC} whisperx + pyannote.audio installed"
WHISPERX_OK=true
else
echo -e " ${YELLOW}⚠${NC} pip install failed — run manually:"
echo -e " ${BOLD}$WHISPERX_VENV/bin/pip install whisperx pyannote.audio${NC}"
fi
# Copy whisperx-diarize.py into venv/bin/
if [ -f "$DIARIZE_SRC" ]; then
cp "$DIARIZE_SRC" "$DIARIZE_DST"
chmod +x "$DIARIZE_DST"
echo -e " ${GREEN}✓${NC} whisperx-diarize.py → $DIARIZE_DST"
else
echo -e " ${YELLOW}⚠${NC} $DIARIZE_SRC not found — whisperx-diarize.py not installed"
fi
fi
else
PY_VER=$(python3 -c "import sys; v=sys.version_info; print(f'{v.major}.{v.minor}')" 2>/dev/null || echo "unknown")
echo -e " ${YELLOW}⚠${NC} Python 3.10+ required for whisperx (found $PY_VER) — skipping"
echo -e " Install Python 3.10+, then run: python3 -m venv $WHISPERX_VENV"
fi
else
echo -e " ${YELLOW}⚠${NC} python3 not found — skipping whisperx voice diarization"
echo -e " Install Python 3.10+, then re-run this script"
fi
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Step 6/10: Statusline & Hooks Configuration${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
bash "$INSTALL_DIR/tools/scripts/setup-statusline-and-hooks.sh" "$INSTALL_DIR"
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Step 7/10: Tmux Mouse Configuration${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
bash "$INSTALL_DIR/tools/scripts/setup-tmux.sh"
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Step 8/10: Optional Tech Stack Tools${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# Ask about optional tech stacks
SELECTED_STACKS=""
# On headless servers, skip interactive stack selection — agents don't need these
if [ -z "${DISPLAY:-}" ] && [ -z "${WAYLAND_DISPLAY:-}" ]; then
echo " Headless server — skipping optional stacks"
else
echo "Optional tech stack tools available:"
echo " • SvelteKit + Supabase (11 tools: component-deps, route-list, error-log, etc.)"
echo ""
if command -v gum &> /dev/null && [ -t 0 ]; then
SELECTED_STACKS=$(gum choose --no-limit \
"SvelteKit + Supabase" \
"Skip - No additional stacks")
else
if prompt_yes_no "Install SvelteKit + Supabase tools? [y/N] " "n"; then
SELECTED_STACKS="SvelteKit"
fi
fi
if echo "$SELECTED_STACKS" | grep -q "SvelteKit"; then
echo ""
echo "Installing SvelteKit + Supabase stack..."
bash "$INSTALL_DIR/stacks/sveltekit-supabase/install.sh"
else
echo ""
echo "Skipping stack installation"
fi
fi
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Step 9/10: Voice-to-Text (Optional)${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
# Skip voice/Pi on headless servers
if [ -z "${DISPLAY:-}" ] && [ -z "${WAYLAND_DISPLAY:-}" ]; then
echo " Headless server — skipping voice-to-text + Pi skills"
fi
# Install Pi skills if Pi is available
INSTALL_PI_SKILLS="no"
if [ -n "${DISPLAY:-}" ] || [ -n "${WAYLAND_DISPLAY:-}" ]; then
if command -v pi &> /dev/null; then
echo ""
echo "Pi coding agent detected ($(pi --version 2>/dev/null))."
echo "JAT skills enable Pi to participate in multi-agent workflows."
echo ""
if command -v gum &> /dev/null && [ -t 0 ]; then
if gum confirm "Install JAT skills for Pi?"; then
INSTALL_PI_SKILLS="yes"
fi
else
if prompt_yes_no "Install JAT skills for Pi? [Y/n] " "y"; then
INSTALL_PI_SKILLS="yes"
fi
fi
if [ "$INSTALL_PI_SKILLS" = "yes" ]; then
bash "$INSTALL_DIR/tools/scripts/install-pi-skills.sh"
else
echo ""
echo " Skipping Pi skills installation"
echo " Run later with: bash $INSTALL_DIR/tools/scripts/install-pi-skills.sh"
fi
fi
fi # end headless guard
echo ""
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${BOLD}Step 10/10: Setting Up Global Configuration${NC}"
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo ""
bash "$INSTALL_DIR/tools/scripts/setup-global-claude-md.sh"
echo ""
echo ""
echo -e "${GREEN}╔───────────────────────────────────────────╗${NC}"
echo -e "${GREEN}│ │${NC}"
echo -e "${GREEN}│ ${BOLD}✓ JAT Successfully Installed!${NC}${GREEN} │${NC}"
echo -e "${GREEN}│ │${NC}"
echo -e "${GREEN}╚───────────────────────────────────────────╝${NC}"
echo ""
echo "What was installed:"
echo ""
echo " ✓ Agent Registry (4 bash/SQLite tools: am-register, am-agents, am-whoami, am-delete-agent)"
echo " ✓ JAT Task CLI (jt command + 4 review tools)"
echo " ✓ Browser Tools (12 CDP automation tools: browser-*.js)"
echo " ✓ Database Tools (4 tools: db-query, db-schema, etc.)"
echo " ✓ Signal Tools (2 tools: jat-signal, jat-signal-validate)"
if [ -f "$HOME/.local/bin/jat-inference" ]; then
echo " ✓ Inference Relay (jat-inference: Ollama proxy + whisperx diarization)"
SYSTEMD_UNIT="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/jat-inference.service"
if [ "$(uname -s)" = "Linux" ] && [ -f "$SYSTEMD_UNIT" ]; then
echo " ✓ systemd user unit (~/.config/systemd/user/jat-inference.service)"
fi
fi
if [ "$WHISPERX_OK" = "true" ]; then
echo " ✓ WhisperX Voice Diarization (venv at ${XDG_DATA_HOME:-$HOME/.local/share}/whisperx-env/)"
fi
if [ ! -z "$SELECTED_STACKS" ] && echo "$SELECTED_STACKS" | grep -q "SvelteKit"; then
echo " ✓ SvelteKit + Supabase Stack (11 additional tools)"
fi
if [ "$INSTALL_PI_SKILLS" = "yes" ]; then
echo " ✓ Pi Skills (jat-start, jat-complete, jat-verify + AGENTS.md)"
fi
echo " ✓ Multi-line statusline (agent, task, git, context)"
echo " ✓ Real-time hooks (auto-refresh on jt/am-* commands)"
echo " ✓ Git pre-commit hook (agent registration check)"
echo " ✓ Global ~/.claude/CLAUDE.md (multi-project instructions)"
echo " ✓ Per-repo setup (jt init, CLAUDE.md templates)"
echo ""
# Detect shell config file
SHELL_NAME=$(basename "$SHELL")
if [[ "$SHELL_NAME" == "zsh" ]]; then
SHELL_CONFIG="$HOME/.zshrc"
elif [[ "$SHELL_NAME" == "bash" ]]; then
SHELL_CONFIG="$HOME/.bashrc"
else
SHELL_CONFIG="$HOME/.bashrc"
fi
# Ensure ~/.local/bin is in PATH
if ! grep -q '\.local/bin' "$SHELL_CONFIG" 2>/dev/null; then
echo "" >> "$SHELL_CONFIG"
echo '# JAT tools' >> "$SHELL_CONFIG"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$SHELL_CONFIG"
echo -e " ${GREEN}✓${NC} Added ~/.local/bin to PATH in $SHELL_CONFIG"
fi
# Post-install verification (only if inference relay was installed)
VERIFY_STATUS=0
if [ -f "$HOME/.local/bin/jat-inference" ]; then
verify_install || VERIFY_STATUS=$?
fi
echo ""
echo "The IDE will guide you through adding your first project."
echo ""
echo "Documentation: https://github.com/joewinke/jat"
echo ""
if [ -z "$DISPLAY" ] && [ -z "$WAYLAND_DISPLAY" ]; then
TS_IP=$(tailscale ip -4 2>/dev/null || echo "<tailscale-ip>")
if prompt_yes_no "${BOLD}Start JAT IDE server now? [Y/n]${NC} " "y"; then
echo ""
"$HOME/.local/bin/jat" &
sleep 4
echo -e " ${GREEN}✓${NC} JAT IDE server started"
echo ""
echo -e " Open on any Tailscale device: ${BOLD}http://${TS_IP}:3333${NC}"
else
echo -e " Start later with: ${BOLD}jat${NC}"
echo -e " Then open: ${BOLD}http://${TS_IP}:3333${NC}"
fi
echo ""
elif prompt_yes_no "${BOLD}Launch JAT now? [Y/n]${NC} " "y"; then
echo ""
exec "$HOME/.local/bin/jat"
fi
echo ""
exit ${VERIFY_STATUS:-0}