Repository navigation
Expand file tree
/
Copy pathsetup.sh.bak
More file actions
executable file
·1023 lines (933 loc) · 45.6 KB
/
Copy pathsetup.sh.bak
File metadata and controls
executable file
·1023 lines (933 loc) · 45.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
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
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# setup.sh — Automated installation and setup script for the Wizard-AI environment.
# Supported Platform: Linux (x86_64 / aarch64) | macOS (x86_64 / arm64)
#
# After installation, the variable $WIZARD_AI_DIR is available in your shell
# and points to the directory where you cloned this repository.
set -euo pipefail
# ANSI color codes for premium terminal output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
echo -e "\033[38;5;250m███████╗██╗ ██╗██╗██╗ ██╗ ███████╗\033[0m"
echo -e "\033[38;5;248m██╔════╝██║ ██╔╝██║██║ ██║ ██╔════╝\033[0m"
echo -e "\033[38;5;245m███████╗█████╔╝ ██║██║ ██║ ███████╗\033[0m"
echo -e "\033[38;5;243m╚════██║██╔═██╗ ██║██║ ██║ ╚════██║\033[0m"
echo -e "\033[38;5;240m███████║██║ ██╗██║███████╗███████╗███████║\033[0m"
echo -e "\033[38;5;238m╚══════╝╚═╝ ╚═╝╚═╝╚══════╝╚══════╝╚══════╝\033[0m"
echo -e "${CYAN}┌ ${BOLD}Wizard-AI — Open Agent Skills & Frameworks Installer${NC}\n"
# 0. Parse arguments
VERBOSE=0
YES_MODE=0
QUIET_OPT="--quiet"
for arg in "$@"; do
case "$arg" in
--verbose|-v) VERBOSE=1; QUIET_OPT="" ;;
--yes|-y) YES_MODE=1 ;;
esac
done
# 0. User environment resolution
REAL_USER="${SUDO_USER:-$USER}"
REAL_HOME="$HOME"
if [ -n "${SUDO_USER:-}" ] && [ "$SUDO_USER" != "root" ]; then
REAL_HOME=$(getent passwd "$REAL_USER" 2>/dev/null | cut -d: -f6 || echo "/home/$REAL_USER")
export HOME="$REAL_HOME"
export USER="$REAL_USER"
export CARGO_HOME="$REAL_HOME/.cargo"
export UV_TOOL_DIR="$REAL_HOME/.local/share/uv/tools"
fi
# Resolve the absolute path of this script (= repo root, works even if symlinked)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# 0. Save WIZARD_AI_DIR so skills and wrappers can reference the repo portably
echo -e "\n${BLUE}[0/10] Registering Wizard-AI installation path...${NC}"
mkdir -p "$HOME/.config/wizard-ai"
cat > "$HOME/.config/wizard-ai/env" <<EOF
# Wizard-AI environment — auto-generated by setup.sh on $(date '+%Y-%m-%d')
# Do not edit manually; re-run setup.sh to update.
export WIZARD_AI_DIR="$SCRIPT_DIR"
export PATH="\$HOME/.local/bin:\$PATH"
EOF
# Source the env file in the user's shell config if not already present
for RC in "$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.profile"; do
if [[ -f "$RC" ]] && ! grep -q "wizard-ai/env" "$RC"; then
echo "" >> "$RC"
echo "# Wizard-AI — load environment (added by setup.sh)" >> "$RC"
echo 'source "$HOME/.config/wizard-ai/env"' >> "$RC"
echo -e " ${GREEN}✓ Added source line to $RC${NC}"
fi
done
# Export for the current session
export WIZARD_AI_DIR="$SCRIPT_DIR"
export PATH="$HOME/.local/bin:$PATH"
echo -e "${GREEN}✓ WIZARD_AI_DIR=\"$WIZARD_AI_DIR\"${NC}"
# 0.5 Install System Dependencies
echo -e "\n${BLUE}[0.5/10] Checking and installing system dependencies...${NC}"
MISSING_PKGS=""
if ! command -v node &>/dev/null || ! command -v npm &>/dev/null; then
MISSING_PKGS="nodejs npm"
fi
if ! command -v git &>/dev/null; then
MISSING_PKGS="$MISSING_PKGS git"
fi
if ! command -v curl &>/dev/null; then
MISSING_PKGS="$MISSING_PKGS curl"
fi
if ! command -v gcc &>/dev/null || ! command -v make &>/dev/null; then
MISSING_PKGS="$MISSING_PKGS build-tools"
fi
if [ -n "$MISSING_PKGS" ]; then
echo -e "${YELLOW}Missing base dependencies ($MISSING_PKGS). Installing automatically...${NC}"
if [ -f /etc/os-release ]; then
. /etc/os-release
OS_ID=$ID
OS_LIKE=${ID_LIKE:-""}
else
OS_ID=$(uname -s | tr '[:upper:]' '[:lower:]')
OS_LIKE=""
fi
if [[ "$OS_ID" == "ubuntu" || "$OS_ID" == "debian" || "$OS_LIKE" == *"debian"* || "$OS_LIKE" == *"ubuntu"* ]]; then
if ! command -v node &>/dev/null; then
echo -e "${CYAN}Adding NodeSource repository for Node.js 20...${NC}"
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
fi
apt-get update -y
apt-get install -y git curl build-essential pkg-config libssl-dev nodejs
elif [[ "$OS_ID" == "fedora" || "$OS_LIKE" == *"fedora"* || "$OS_LIKE" == *"rhel"* || "$OS_ID" == "centos" ]]; then
dnf install -y git curl gcc gcc-c++ make openssl-devel pkgconf-pkg-config nodejs npm
elif [[ "$OS_ID" == "arch" || "$OS_LIKE" == *"arch"* || "$OS_ID" == "cachyos" ]]; then
pacman -Syu --noconfirm git curl base-devel pkgconf openssl nodejs npm uv || pacman -Syu --noconfirm git curl base-devel pkgconf openssl nodejs npm
elif [[ "$OS_ID" == "darwin" || "$(uname)" == "Darwin" ]]; then
if ! command -v brew &>/dev/null; then
echo -e "${RED}Homebrew is required on macOS but not installed. Please install it first: https://brew.sh/${NC}"
else
BREW_USER="${REAL_USER:-$USER}"
sudo -u "$BREW_USER" brew install git curl node pkg-config openssl uv
fi
else
echo -e "${RED}Unsupported OS for automatic dependency installation. Please install Node.js, npm, git, curl, and build tools manually.${NC}"
fi
echo -e "${GREEN}✓ System dependencies installed.${NC}"
else
echo -e "${GREEN}✓ All system dependencies are already installed.${NC}"
fi
# Ensure local user bin paths are exported in PATH before checking tools
if [ -n "${SUDO_USER:-}" ] && [ "$SUDO_USER" != "root" ]; then
SUDO_HOME=$(eval echo "~$SUDO_USER" 2>/dev/null || echo "/home/$SUDO_USER")
export PATH="$SUDO_HOME/.local/bin:$SUDO_HOME/.cargo/bin:$PATH"
fi
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
# 1. Check/Install UV with Segfault Protection
echo -e "\n${BLUE}[1/10] Checking for modern Python & Package Manager (uv)...${NC}"
UV_OK=0
if command -v uv &>/dev/null; then
UV_VER=$(uv --version 2>/dev/null || echo "")
if [ -n "$UV_VER" ]; then
UV_OK=1
echo -e "${GREEN}✓ uv is already installed: ${UV_VER}${NC}"
else
echo -e "${YELLOW}Detected corrupted or segfaulting prebuilt uv binary. Cleaning up...${NC}"
rm -f "$HOME/.local/bin/uv" "$HOME/.cargo/bin/uv" 2>/dev/null || true
fi
fi
if [ "$UV_OK" -eq 0 ]; then
echo -e "${YELLOW}Installing native uv package manager...${NC}"
if command -v pacman &>/dev/null; then
pacman -S --noconfirm uv 2>/dev/null || true
elif command -v apt-get &>/dev/null; then
apt-get install -y uv 2>/dev/null || true
fi
if ! command -v uv &>/dev/null || [ -z "$(uv --version 2>/dev/null)" ]; then
curl -LsSf https://astral.sh/uv/install.sh | sh 2>/dev/null || true
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
fi
if command -v uv &>/dev/null && [ -n "$(uv --version 2>/dev/null)" ]; then
echo -e "${GREEN}✓ uv installed successfully: $(uv --version 2>/dev/null)${NC}"
else
echo -e "${YELLOW}⚠ Prebuilt uv binary not compatible with system glibc/CPU. Falling back to python3 -m venv...${NC}"
fi
fi
# Ensure local directories exist
mkdir -p "$HOME/.local/bin"
mkdir -p "$HOME/.wizard-ai"
# 2. Recreate Python Virtual Environment for wrappers
echo -e "\n${BLUE}[2/10] Preparing Python Virtual Environment for LLMLingua & FlashRank...${NC}"
rm -rf "$HOME/.wizard-ai/venv" 2>/dev/null || true
if ! uv venv "$HOME/.wizard-ai/venv" --python 3.12 --seed $QUIET_OPT 2>/dev/null; then
echo -e "${YELLOW}uv venv with Python 3.12 failed (WSL segfault?). Trying system Python...${NC}"
if ! uv venv "$HOME/.wizard-ai/venv" --seed $QUIET_OPT 2>/dev/null; then
echo -e "${YELLOW}uv venv failed completely. Falling back to python3 -m venv...${NC}"
python3 -m venv "$HOME/.wizard-ai/venv" || {
echo -e "${RED}❌ Failed to create virtual environment. Please install python3-venv.${NC}"
exit 1
}
fi
fi
VENV_PYTHON="$HOME/.wizard-ai/venv/bin/python"
echo -e "${YELLOW}Installing llmlingua and flashrank inside the venv...${NC}"
if ! uv pip install $QUIET_OPT --python "$VENV_PYTHON" llmlingua flashrank aisuite; then
echo -e "${YELLOW}uv pip install failed. Falling back to standard pip...${NC}"
"$VENV_PYTHON" -m pip install llmlingua flashrank aisuite || {
echo -e "${RED}❌ Failed to install Python dependencies.${NC}"
exit 1
}
fi
echo -e "${GREEN}✓ Virtual environment ready at ~/.wizard-ai/venv/${NC}"
# 3. Setting up external git skill & framework repositories (Interactive Selector)
# ═══════════════════════════════════════════════════════════════════════════════
# Reads from scripts/repo-registry.json — single source of truth for all repos.
# Inspired by caveman installer UX: numbered categories, selectable items.
# ═══════════════════════════════════════════════════════════════════════════════
REGISTRY_FILE="$SCRIPT_DIR/scripts/repo-registry.json"
if [ ! -f "$REGISTRY_FILE" ]; then
echo -e "${RED}[ERROR] Missing repo-registry.json at $REGISTRY_FILE${NC}"
exit 1
fi
# ── clone_skill_repo: clone + auto-install dependencies ────────────────────
SKILL_REPO_INDEX=0
SKILL_REPO_TOTAL=0
INSTALL_OK=0
INSTALL_SKIP=0
INSTALL_FAIL=0
FAILED_REPOS=""
clone_skill_repo() {
local url="$1"
local dest_name="$2"
local badge="${3:-}"
local dest_dir="$HOME/.wizard-ai/$dest_name"
SKILL_REPO_INDEX=$((SKILL_REPO_INDEX + 1))
local badge_str=""
[ -n "$badge" ] && badge_str=" ${CYAN}${badge}${NC}"
echo -e "${BOLD}[3/10] [${SKILL_REPO_INDEX}/${SKILL_REPO_TOTAL}] ${dest_name}${badge_str}${NC}"
if [ ! -d "$dest_dir" ]; then
echo -e "${YELLOW} ↳ Cloning ${dest_name} from ${url}...${NC}"
if [ "$VERBOSE" -eq 1 ]; then
git clone --recurse-submodules --shallow-submodules --depth 1 "$url" "$dest_dir" || { INSTALL_FAIL=$((INSTALL_FAIL+1)); FAILED_REPOS="$FAILED_REPOS $dest_name"; echo -e "${RED} ✗ Clone failed for $dest_name${NC}"; return; }
else
git clone --recurse-submodules --shallow-submodules --depth 1 $QUIET_OPT "$url" "$dest_dir" 2>/dev/null || { INSTALL_FAIL=$((INSTALL_FAIL+1)); FAILED_REPOS="$FAILED_REPOS $dest_name"; echo -e "${RED} ✗ Clone failed for $dest_name${NC}"; return; }
fi
echo -e "${GREEN} ✓ ${dest_name} cloned.${NC}"
INSTALL_OK=$((INSTALL_OK + 1))
else
echo -e "${GREEN} ✓ ${dest_name} is already present.${NC}"
INSTALL_SKIP=$((INSTALL_SKIP + 1))
fi
# Auto-install framework / skill dependencies per OS specification
if [ -d "$dest_dir" ]; then
if [ -f "$dest_dir/bin/install.js" ]; then
echo -e "${CYAN} ↳ Running bin/install.js installer for $dest_name...${NC}"
if [ "$VERBOSE" -eq 1 ]; then
GITHUB_TOKEN="" node "$dest_dir/bin/install.js" --all --non-interactive || true
else
GITHUB_TOKEN="" node "$dest_dir/bin/install.js" --all --non-interactive >/dev/null 2>&1 || true
fi
elif [ -f "$dest_dir/install.sh" ]; then
echo -e "${CYAN} ↳ Running install.sh script for $dest_name...${NC}"
if [ "$VERBOSE" -eq 1 ]; then
bash "$dest_dir/install.sh" || true
else
bash "$dest_dir/install.sh" >/dev/null 2>&1 || true
fi
elif [ -f "$dest_dir/setup.sh" ] && [ "$dest_dir/setup.sh" != "$SCRIPT_DIR/setup.sh" ]; then
echo -e "${CYAN} ↳ Running setup.sh script for $dest_name...${NC}"
if [ "$VERBOSE" -eq 1 ]; then
bash "$dest_dir/setup.sh" || true
else
bash "$dest_dir/setup.sh" >/dev/null 2>&1 || true
fi
elif [ -f "$dest_dir/pyproject.toml" ] || [ -f "$dest_dir/setup.py" ]; then
echo -e "${CYAN} ↳ Building Python package for $dest_name...${NC}"
if [ "$VERBOSE" -eq 1 ]; then
uv pip install --python "$VENV_PYTHON" -e "$dest_dir" || true
else
uv pip install --python "$VENV_PYTHON" -e "$dest_dir" $QUIET_OPT 2>/dev/null || true
fi
elif [ -f "$dest_dir/package.json" ] && command -v npm &>/dev/null; then
echo -e "${CYAN} ↳ Installing npm packages for $dest_name...${NC}"
if [ "$VERBOSE" -eq 1 ]; then
npm install --prefix "$dest_dir" --no-audit --no-fund || true
npm --prefix "$dest_dir" approve-scripts --allow-scripts-pending || true
else
npm install --prefix "$dest_dir" --no-audit --no-fund >/dev/null 2>&1 || true
npm --prefix "$dest_dir" approve-scripts --allow-scripts-pending >/dev/null 2>&1 || true
fi
fi
fi
}
# ── Parse repo-registry.json with Node.js (available on all supported OSes) ──
# Outputs flat lines: CATEGORY_KEY|CATEGORY_NAME|BADGE|REPO_NAME|URL|DESC
REGISTRY_LINES=$(node -e "
const r = require('$REGISTRY_FILE');
for (const [ck, cv] of Object.entries(r.categories)) {
for (const rp of cv.repos) {
console.log([ck, cv.name, cv.badge, rp.name, rp.url, rp.desc].join('|'));
}
}
")
# Build category summary (for menu display)
CATEGORY_KEYS=()
CATEGORY_NAMES=()
CATEGORY_BADGES=()
CATEGORY_COUNTS=()
CATEGORY_DESCS=()
eval "$(node -e "
const r = require('$REGISTRY_FILE');
const keys = Object.keys(r.categories);
keys.forEach((k, i) => {
const c = r.categories[k];
console.log('CATEGORY_KEYS[' + i + ']=\"' + k + '\"');
console.log('CATEGORY_NAMES[' + i + ']=\"' + c.name + '\"');
console.log('CATEGORY_BADGES[' + i + ']=\"' + c.badge + '\"');
console.log('CATEGORY_COUNTS[' + i + ']=' + c.repos.length);
console.log('CATEGORY_DESCS[' + i + ']=\"' + (c.description || '') + '\"');
});
")"
TOTAL_REPOS=$(echo "$REGISTRY_LINES" | wc -l)
# ── Interactive Selection Menu ──────────────────────────────────────────────
echo -e "\n${BLUE}[3/10] Setting up external git skill & framework repositories...${NC}"
if [ "$VERBOSE" -eq 0 ]; then
echo -e "${CYAN}💡 [Tip] Run setup with --verbose to see full clone & build logs.${NC}"
fi
SELECTED_REPOS="" # newline-separated "name|url|badge" of repos to install
if [ "$YES_MODE" -eq 1 ] || [ ! -t 0 ]; then
# Non-interactive: install everything
echo -e "${YELLOW}Installing all $TOTAL_REPOS repositories (--yes mode)...${NC}"
SELECTED_REPOS="$REGISTRY_LINES"
else
# ── Interactive menu ──
echo -e "${CYAN}│${NC}"
echo -e "${CYAN}◇ ${BOLD}Skill & Framework Selection Mode:${NC}"
echo -e "${CYAN}│${NC} ${BOLD}[1]${NC} 🚀 Install Everything ${GREEN}(Recommended — all $TOTAL_REPOS items)${NC}"
echo -e "${CYAN}│${NC} ${BOLD}[2]${NC} 📦 Select by Category ${PURPLE}(Agent Frameworks, CLI Tools, Prompt Skills, etc.)${NC}"
echo -e "${CYAN}│${NC} ${BOLD}[3]${NC} 🔧 Cherry-Pick Individual Skills"
echo -e "${CYAN}│${NC} ${BOLD}[4]${NC} ⏭️ Skip (install only core tools)"
echo -e "${CYAN}│${NC}"
read -p "$(echo -e "${CYAN}◇ Selection > ${NC}")" INSTALL_MODE
INSTALL_MODE="${INSTALL_MODE:-1}"
case "$INSTALL_MODE" in
1)
echo -e "${GREEN}Installing all $TOTAL_REPOS repositories...${NC}"
SELECTED_REPOS="$REGISTRY_LINES"
;;
2)
# ── Category Selection ──
echo -e "\n${BOLD}Available Categories:${NC}\n"
for i in "${!CATEGORY_KEYS[@]}"; do
idx=$((i + 1))
echo -e " ${BOLD}[${idx}]${NC} ${CATEGORY_NAMES[$i]} ${PURPLE}(${CATEGORY_COUNTS[$i]} repos)${NC} ${CYAN}${CATEGORY_BADGES[$i]}${NC}"
echo -e " ${YELLOW}${CATEGORY_DESCS[$i]}${NC}"
done
echo -e ""
echo -e "Enter numbers separated by commas (e.g. ${BOLD}1,3,5${NC}) or ${BOLD}'all'${NC}:"
read -p "> " CAT_SELECTION
CAT_SELECTION="${CAT_SELECTION:-all}"
if [ "${CAT_SELECTION,,}" = "all" ]; then
SELECTED_REPOS="$REGISTRY_LINES"
else
IFS=',' read -ra CAT_INDICES <<< "$CAT_SELECTION"
for ci in "${CAT_INDICES[@]}"; do
ci=$(echo "$ci" | tr -d ' ')
ci=$((ci - 1))
if [ "$ci" -ge 0 ] && [ "$ci" -lt "${#CATEGORY_KEYS[@]}" ]; then
local_cat_key="${CATEGORY_KEYS[$ci]}"
SELECTED_REPOS="${SELECTED_REPOS}$(echo "$REGISTRY_LINES" | grep "^${local_cat_key}|")
"
fi
done
fi
;;
3)
# ── Individual Skill Selection ──
echo -e "\n${BOLD}All Available Skills & Frameworks:${NC}\n"
GLOBAL_IDX=0
ALL_ITEMS=()
CURRENT_CAT=""
while IFS='|' read -r cat_key cat_name badge repo_name url desc; do
if [ "$cat_key" != "$CURRENT_CAT" ]; then
CURRENT_CAT="$cat_key"
echo -e "\n ${PURPLE}${cat_name}${NC}"
fi
GLOBAL_IDX=$((GLOBAL_IDX + 1))
ALL_ITEMS+=("$cat_key|$cat_name|$badge|$repo_name|$url|$desc")
printf " ${BOLD}[%2d]${NC} %-28s ${CYAN}%-18s${NC} ${YELLOW}%s${NC}\n" "$GLOBAL_IDX" "$repo_name" "$badge" "$desc"
done <<< "$REGISTRY_LINES"
echo -e ""
echo -e "Enter numbers/ranges (e.g. ${BOLD}1,5,10-15${NC}) or ${BOLD}'all'${NC}:"
read -p "> " SKILL_SELECTION
SKILL_SELECTION="${SKILL_SELECTION:-all}"
if [ "${SKILL_SELECTION,,}" = "all" ]; then
SELECTED_REPOS="$REGISTRY_LINES"
else
# Parse comma-separated, support ranges (e.g. 10-15)
IFS=',' read -ra TOKENS <<< "$SKILL_SELECTION"
SELECTED_INDICES=()
for token in "${TOKENS[@]}"; do
token=$(echo "$token" | tr -d ' ')
if [[ "$token" == *"-"* ]]; then
IFS='-' read -r range_start range_end <<< "$token"
for ((ri=range_start; ri<=range_end; ri++)); do
SELECTED_INDICES+=("$ri")
done
else
SELECTED_INDICES+=("$token")
fi
done
for si in "${SELECTED_INDICES[@]}"; do
si_idx=$((si - 1))
if [ "$si_idx" -ge 0 ] && [ "$si_idx" -lt "${#ALL_ITEMS[@]}" ]; then
SELECTED_REPOS="${SELECTED_REPOS}${ALL_ITEMS[$si_idx]}
"
fi
done
fi
;;
4)
echo -e "${YELLOW}⏭️ Skipping skill & framework installation. Only core tools will be installed.${NC}"
SELECTED_REPOS=""
;;
*)
echo -e "${YELLOW}Invalid selection. Installing everything...${NC}"
SELECTED_REPOS="$REGISTRY_LINES"
;;
esac
fi
# ── Execute installation for selected repos ─────────────────────────────────
SELECTED_COUNT=$(echo "$SELECTED_REPOS" | sed '/^$/d' | wc -l)
SKILL_REPO_TOTAL=$SELECTED_COUNT
if [ "$SELECTED_COUNT" -gt 0 ]; then
echo -e "\n${GREEN}🚀 Installing ${SELECTED_COUNT} selected repositories...${NC}\n"
while IFS='|' read -r cat_key cat_name badge repo_name url desc; do
[ -z "$repo_name" ] && continue
clone_skill_repo "$url" "$repo_name" "$badge"
done <<< "$(echo "$SELECTED_REPOS" | sed '/^$/d')"
else
echo -e "${YELLOW}No repositories selected for installation.${NC}"
fi
# ── Post-install: optional NPM global packages for special repos ─────────
# Only run if ECC or caveman were among the selected repos
if echo "$SELECTED_REPOS" | grep -q "ECC\|caveman\|design\.md"; then
if command -v npm &>/dev/null; then
echo -e "\n${BLUE}Running post-install hooks for special packages...${NC}"
if echo "$SELECTED_REPOS" | grep -q "ECC"; then
npm install -g --allow-scripts=ecc-universal ecc-universal 2>/dev/null || echo -e "${YELLOW}Note: ecc-universal npm install skipped/failed.${NC}"
fi
if echo "$SELECTED_REPOS" | grep -q "caveman"; then
if [ -f "$HOME/.wizard-ai/caveman/bin/install.js" ]; then
echo -e "${CYAN} ↳ Running caveman installer...${NC}"
GITHUB_TOKEN="" node "$HOME/.wizard-ai/caveman/bin/install.js" --all --non-interactive 2>/dev/null || true
fi
fi
if echo "$SELECTED_REPOS" | grep -q "design\.md"; then
npm install -g --allow-scripts=puppeteer @google/design.md 2>/dev/null || echo -e "${YELLOW}Note: @google/design.md npm install skipped/failed.${NC}"
fi
fi
fi
# ── Installation Summary ────────────────────────────────────────────────────
if [ "$SELECTED_COUNT" -gt 0 ]; then
echo -e ""
echo -e "${CYAN}────────────────────────────────────────────────────────────${NC}"
echo -e "${BOLD}📊 Repository Installation Summary:${NC}"
echo -e "${CYAN}────────────────────────────────────────────────────────────${NC}"
echo -e " ${GREEN}✓ Installed:${NC} $INSTALL_OK new"
echo -e " ${BLUE}⏭ Skipped:${NC} $INSTALL_SKIP (already present)"
if [ "$INSTALL_FAIL" -gt 0 ]; then
echo -e " ${RED}✗ Failed:${NC} $INSTALL_FAIL ($FAILED_REPOS)"
fi
echo -e "${CYAN}────────────────────────────────────────────────────────────${NC}"
fi
# 4. Install UV Global Tools
echo -e "\n${BLUE}[4/10] Installing global CLI Tools via uv tool...${NC}"
install_uv_tool() {
local tool="$1"
local pkg="${2:-$1}" # optional package name if different from tool name
echo -e "${YELLOW}Installing/Updating $tool...${NC}"
# Capture previous version if tool is already installed
local prev_ver=""
if command -v "$tool" &>/dev/null; then
prev_ver=$(uv tool list 2>/dev/null | grep -E "^$pkg v" | awk '{print $2}' | tr -d 'v' || echo "")
fi
local exit_code=0
if [ "$VERBOSE" -eq 1 ]; then
uv tool install --force "$pkg" || exit_code=$?
else
uv tool install --force "$pkg" &>/dev/null || exit_code=$?
fi
if [ $exit_code -eq 0 ] && command -v "$tool" &>/dev/null; then
echo -e "${GREEN} ✓ $tool installed/updated safely.${NC}"
else
echo -e "${RED} ⚠ Failed to install $tool (exit code $exit_code). You may need to install C++/Rust Build Tools.${NC}"
if [ -n "$prev_ver" ]; then
echo -e "${YELLOW} ⚠ Rolling back $tool ($pkg) to previous working version ($prev_ver)...${NC}"
uv tool install --force "$pkg@$prev_ver" &>/dev/null || true
if command -v "$tool" &>/dev/null; then
echo -e "${GREEN} ✓ Rolled back $tool to $prev_ver successfully.${NC}"
fi
fi
fi
}
install_uv_tool "graphify" "graphifyy[all]"
# Fix pyo3 max version compatibility error for litellm and strix on python >= 3.14
export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
install_uv_tool "litellm" "litellm[proxy]"
install_uv_tool "markitdown"
install_uv_tool "sqz"
install_uv_tool "headroom" "headroom-ai"
install_uv_tool "strix" "strix-agent"
# Install serena (semantic code intelligence — available via uvx)
echo -e "${YELLOW}Checking serena (semantic code search)...${NC}"
if ! command -v serena &>/dev/null; then
if [ "$VERBOSE" -eq 1 ]; then
uv tool install --force serena-agent || true
else
uv tool install --force serena-agent &>/dev/null || true
fi
# Verify installation
if command -v serena &>/dev/null; then
echo -e "${GREEN} ✓ serena installed.${NC}"
else
echo -e "${RED} ❌ failed to install serena.${NC}"
fi
else
echo -e "${GREEN}✓ serena already installed.${NC}"
fi
# Install lean-ctx (context intelligence binary)
echo -e "${YELLOW}Checking lean-ctx (context intelligence)...${NC}"
if command -v lean-ctx &>/dev/null; then
echo -e "${GREEN}✓ lean-ctx already installed.${NC}"
else
# Pre-flight check for node/npm
if command -v npm &>/dev/null; then
echo -e "${BLUE} NPM detected, installing lean-ctx-bin...${NC}"
if npm install -g lean-ctx-bin 2>/dev/null; then
echo -e "${GREEN} ✓ lean-ctx installed via npm.${NC}"
elif npm install -g lean-ctx-bin --prefix ~/.local 2>/dev/null; then
echo -e "${GREEN} ✓ lean-ctx installed via npm locally (~/.local/bin).${NC}"
elif command -v cargo &>/dev/null; then
echo -e "${YELLOW} ⚠ npm installation failed. Falling back to Cargo...${NC}"
cargo install lean-ctx --locked --quiet 2>/dev/null && echo -e "${GREEN} ✓ lean-ctx installed via cargo.${NC}" || {
echo -e "${RED} ✗ lean-ctx installation failed (Rust version too old or build error).${NC}"
echo -e "${YELLOW} Suggestion: Install build dependencies (e.g. sudo apt install -y build-essential pkg-config libssl-dev)${NC}"
}
else
echo -e "${RED} ✗ lean-ctx installation via npm failed and Cargo is not available.${NC}"
echo -e "${YELLOW} Suggestion: run 'sudo npm install -g lean-ctx-bin' manually.${NC}"
fi
elif command -v cargo &>/dev/null; then
echo -e "${BLUE} NPM not found, but Cargo detected. Installing via Cargo...${NC}"
cargo install lean-ctx --locked --quiet 2>/dev/null && echo -e "${GREEN} ✓ lean-ctx installed via cargo.${NC}" || {
echo -e "${RED} ✗ lean-ctx installation failed (Rust version too old or build error).${NC}"
echo -e "${YELLOW} Attempting fallback to pre-compiled binary from GitHub...${NC}"
ARCH=$(uname -m)
LEAN_CTX_LATEST=$(curl -sL https://api.github.com/repos/yvgude/lean-ctx/releases/latest | grep -m 1 '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' || echo "")
if [ -n "$LEAN_CTX_LATEST" ]; then
case "$ARCH" in
x86_64) LEAN_CTX_URL="https://github.com/yvgude/lean-ctx/releases/download/${LEAN_CTX_LATEST}/lean-ctx-x86_64-unknown-linux-musl.tar.gz" ;;
aarch64|arm64) LEAN_CTX_URL="https://github.com/yvgude/lean-ctx/releases/download/${LEAN_CTX_LATEST}/lean-ctx-aarch64-unknown-linux-musl.tar.gz" ;;
*) LEAN_CTX_URL="" ;;
esac
if [ -n "$LEAN_CTX_URL" ]; then
TMP_DIR=$(mktemp -d)
curl -L -s "$LEAN_CTX_URL" -o "$TMP_DIR/lean-ctx.tar.gz" && tar -xzf "$TMP_DIR/lean-ctx.tar.gz" -C "$TMP_DIR/" 2>/dev/null || true
if [ -x "$TMP_DIR/lean-ctx" ]; then
mkdir -p "$HOME/.local/bin"
cp -f "$TMP_DIR/lean-ctx" "$HOME/.local/bin/lean-ctx"
chmod +x "$HOME/.local/bin/lean-ctx"
echo -e "${GREEN} ✓ lean-ctx binary fallback installed to ~/.local/bin/lean-ctx.${NC}"
else
echo -e "${RED} ✗ Pre-compiled binary fallback failed.${NC}"
echo -e "${YELLOW} Suggestion: Install build dependencies (e.g. sudo apt install -y build-essential pkg-config libssl-dev)${NC}"
fi
rm -rf "$TMP_DIR"
fi
else
echo -e "${YELLOW} Suggestion: Install build dependencies (e.g. sudo apt install -y build-essential pkg-config libssl-dev)${NC}"
fi
}
else
echo -e "${YELLOW} ⚠ lean-ctx requires Node.js (npm) or Rust (cargo). Neither found.${NC}"
echo -e " Please install Node.js (https://nodejs.org) to enable context intelligence."
fi
fi
# 5. Fix sqz binary (pre-compiled native binary for token compression)
echo -e "\n${BLUE}[5/10] Placing pre-compiled sqz binary...${NC}"
ARCH=$(uname -m)
# Capture previous binary if it exists
PREV_SQZ_PATH=$(command -v sqz 2>/dev/null || echo "")
TMP_BAK=$(mktemp -d)
if [ -n "$PREV_SQZ_PATH" ] && [ -f "$PREV_SQZ_PATH" ]; then
cp -p "$PREV_SQZ_PATH" "$TMP_BAK/sqz.bak" 2>/dev/null || true
fi
# Dynamically fetch latest version tag from GitHub Releases API
SQZ_LATEST=$(curl -sL https://api.github.com/repos/ojuschugh1/sqz/releases/latest | grep -m 1 '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' || echo "")
SQZ_VER="${SQZ_LATEST:-v1.3.0}"
SQZ_URL=""
case "$ARCH" in
x86_64)
SQZ_URL="https://github.com/ojuschugh1/sqz/releases/download/${SQZ_VER}/sqz-${SQZ_VER}-x86_64-unknown-linux-musl.tar.gz"
;;
aarch64|arm64)
SQZ_URL="https://github.com/ojuschugh1/sqz/releases/download/${SQZ_VER}/sqz-${SQZ_VER}-aarch64-unknown-linux-musl.tar.gz"
;;
*)
echo -e "${RED}✗ Unsupported architecture ($ARCH) for sqz binary. Compile sqz manually.${NC}"
;;
esac
if [ -n "$SQZ_URL" ]; then
echo -e "${YELLOW}Fetching compiled sqz ${SQZ_VER} binary for $ARCH...${NC}"
TMP_DIR=$(mktemp -d)
curl -L -s "$SQZ_URL" -o "$TMP_DIR/sqz.tar.gz"
tar -xzf "$TMP_DIR/sqz.tar.gz" -C "$TMP_DIR/" 2>/dev/null || true
# Verify executable works before placing it
if [ -f "$TMP_DIR/sqz" ] && "$TMP_DIR/sqz" --version &>/dev/null || [ -x "$TMP_DIR/sqz" ]; then
# Try to place in uv tool site-packages first, fallback to ~/.local/bin
SQZ_BIN_DIR="$HOME/.local/share/uv/tools/sqz/lib"
PYTHON_DIR=$(find "$SQZ_BIN_DIR" -maxdepth 2 -type d \
-name "site-packages" 2>/dev/null | head -n 1 || true)
if [ -n "$PYTHON_DIR" ]; then
mkdir -p "$PYTHON_DIR/sqz/_bin"
cp -f "$TMP_DIR/sqz" "$PYTHON_DIR/sqz/_bin/sqz"
chmod +x "$PYTHON_DIR/sqz/_bin/sqz"
echo -e "${GREEN}✓ sqz ${SQZ_VER} binary placed in Python site-packages ($ARCH).${NC}"
else
mkdir -p "$HOME/.local/bin"
cp -f "$TMP_DIR/sqz" "$HOME/.local/bin/sqz"
chmod +x "$HOME/.local/bin/sqz"
echo -e "${GREEN}✓ sqz ${SQZ_VER} binary placed in ~/.local/bin/sqz ($ARCH).${NC}"
fi
else
echo -e "${RED}⚠ Downloaded sqz ${SQZ_VER} binary failed verification on this system ($ARCH).${NC}"
if [ -f "$TMP_BAK/sqz.bak" ] && [ -n "$PREV_SQZ_PATH" ]; then
echo -e "${YELLOW}⚠ Rolling back sqz to previous working version...${NC}"
cp -f "$TMP_BAK/sqz.bak" "$PREV_SQZ_PATH"
chmod +x "$PREV_SQZ_PATH"
echo -e "${GREEN}✓ Restored previous working sqz binary successfully.${NC}"
else
echo -e "${YELLOW}⚠ Attempting fallback to known stable release v1.0.5...${NC}"
# Fallback to v1.0.5 if no previous version existed
case "$ARCH" in
x86_64) FB_URL="https://github.com/ojuschugh1/sqz/releases/download/v1.0.5/sqz-v1.0.5-x86_64-unknown-linux-musl.tar.gz" ;;
aarch64|arm64) FB_URL="https://github.com/ojuschugh1/sqz/releases/download/v1.0.5/sqz-v1.0.5-aarch64-unknown-linux-musl.tar.gz" ;;
esac
curl -L -s "$FB_URL" -o "$TMP_DIR/sqz-fb.tar.gz" && tar -xzf "$TMP_DIR/sqz-fb.tar.gz" -C "$TMP_DIR/" 2>/dev/null || true
if [ -x "$TMP_DIR/sqz" ]; then
cp -f "$TMP_DIR/sqz" "$HOME/.local/bin/sqz"
chmod +x "$HOME/.local/bin/sqz"
echo -e "${GREEN}✓ Fallback sqz v1.0.5 installed to ~/.local/bin/sqz.${NC}"
fi
fi
fi
rm -rf "$TMP_DIR" "$TMP_BAK"
fi
# 6. Copy and configure CLI Wrappers
echo -e "\n${BLUE}[6/10] Deploying custom AI CLI wrappers to ~/.local/bin/...${NC}"
cp -p "$SCRIPT_DIR"/bin/wz-ai* "$SCRIPT_DIR"/bin/ai-* "$SCRIPT_DIR"/bin/wizard-* "$SCRIPT_DIR"/bin/book-to-skill "$HOME/.local/bin/" 2>/dev/null || true
chmod +x "$HOME/.local/bin"/wz-ai* "$HOME/.local/bin"/ai-* "$HOME/.local/bin"/wizard-* "$HOME/.local/bin"/book-to-skill 2>/dev/null || true
# Fix CRLF line endings for WSL users cloning from Windows
# IMPORTANT: only touch files WE just deployed (by basename from $SCRIPT_DIR/bin/),
# never blanket-iterate $HOME/.local/bin/* — that dir also holds third-party
# npm/nvm-managed binaries (e.g. `pi`, `agy`) that may be symlinks. GNU `sed -i`
# on a symlink deletes it and writes a flat standalone file in its place,
# breaking relative imports (e.g. `import './config.js'`) the real package
# depended on. See docs/AGENTIC_SKILLS_AUDIT.md / cli.js history for context.
for name in $(ls "$SCRIPT_DIR/bin/"); do
file="$HOME/.local/bin/$name"
if [ -f "$file" ] && [ ! -L "$file" ]; then
sed -i 's/\r$//' "$file" 2>/dev/null || true
fi
done
# Create symlink for gemini-usage pointing to wz-ai-usage to avoid duplicate script files
ln -sf wz-ai-usage "$HOME/.local/bin/gemini-usage"
echo -e "${GREEN}✓ $(ls "$SCRIPT_DIR/bin/" | wc -l) wrapper scripts installed to ~/.local/bin/ (with gemini-usage symlinked)${NC}"
# 7. Install Skills for all agents (hierarchical → flat)
echo -e "\n${BLUE}[7/10] Installing AI agent skills...${NC}"
SKILLS_DEST="$HOME/.gemini/config/skills"
mkdir -p "$SKILLS_DEST"
SKILL_COUNT=0
# Find every SKILL.md inside the categorized directories and copy its parent
# folder flatly into the global skills directory (e.g. skills/reference/core/brainstorming → ~/.gemini/config/skills/brainstorming)
while IFS= read -r -d '' skill_md; do
skill_dir=$(dirname "$skill_md")
skill_name=$(basename "$skill_dir")
mkdir -p "$SKILLS_DEST/$skill_name"
cp -r "$skill_dir"/. "$SKILLS_DEST/$skill_name/"
((SKILL_COUNT++)) || true
done < <(find "$SCRIPT_DIR/skills" "$SCRIPT_DIR/.agents/skills" -name "SKILL.md" -type f -print0 2>/dev/null)
# Also copy skills.json for reference
cp -f "$SCRIPT_DIR/skills/skills.json" "$SKILLS_DEST/" 2>/dev/null || cp -f "$SCRIPT_DIR/.agents/skills.json" "$SKILLS_DEST/" 2>/dev/null || true
echo -e "${GREEN}✓ $SKILL_COUNT skills installed to ~/.gemini/config/skills/${NC}"
# Clean up duplicate skill folders inside project root to avoid Pi CLI collisions
echo -e "${YELLOW}Cleaning up duplicate skills in project root...${NC}"
for d in "$SCRIPT_DIR/.agents/skills"/* "$SCRIPT_DIR/.pi/skills"/* "$SCRIPT_DIR/skills"/*; do
if [ -d "$d" ]; then
skill_name=$(basename "$d")
if [ -d "$SKILLS_DEST/$skill_name" ]; then
if [[ "$d" == *".agents/skills"* ]] || [[ "$d" == *".pi/skills"* ]]; then
rm -rf "$d" 2>/dev/null || true
fi
fi
fi
done
echo -e "${YELLOW}Syncing skills to Claude Code, Amp, and other agents...${NC}"
"$HOME/.local/bin/wz-ai-sync-skills"
# 7.5. Interactive Skill Setup and Configuration
echo -e "\n${BLUE}[7.5/10] Interactive Skill Setup and Configuration...${NC}"
for skill_dir in "$HOME/.gemini/config/skills"/*; do
if [ -d "$skill_dir" ]; then
skill_name=$(basename "$skill_dir")
setup_script="$skill_dir/scripts/setup.sh"
install_script="$skill_dir/scripts/install.sh"
skill_md="$skill_dir/SKILL.md"
needs_setup=0
setup_info=""
if [ -f "$skill_md" ]; then
# Extract Setup/Configuration section if present using awk
setup_info=$(awk '
/^#+ *(Setup|Configuration|Installation|Config)/ { flag=1; print; next }
/^#+/ { if(flag) flag=0 }
flag { print }
' "$skill_md" | sed '/^$/d')
if [ -n "$setup_info" ]; then
needs_setup=1
fi
fi
if [ -f "$setup_script" ] || [ -f "$install_script" ]; then
needs_setup=1
fi
if [ $needs_setup -eq 1 ]; then
echo -e "\n ${PURPLE}┌ 🛠 Configuration available for skill: ${BOLD}${skill_name}${NC}"
if [ -n "$setup_info" ]; then
echo -e " ${PURPLE}│${NC} ${CYAN}Instructions from SKILL.md:${NC}"
echo -e "$setup_info" | while IFS= read -r line; do
echo -e " ${PURPLE}│${NC} $line"
done
echo -e " ${PURPLE}│${NC}"
fi
script_to_run=""
if [ -f "$setup_script" ]; then script_to_run="$setup_script"; fi
if [ -f "$install_script" ]; then script_to_run="$install_script"; fi
if [ -n "$script_to_run" ]; then
echo -e " ${PURPLE}│${NC} ${CYAN}Found automated setup script: $(basename "$script_to_run")${NC}"
if [ "$YES_MODE" -eq 1 ]; then
run_setup="y"
echo -e " ${PURPLE}│${NC} ${YELLOW}Auto-running setup script...${NC}"
else
echo -ne " ${PURPLE}│${NC} Do you want to run the automated setup for ${skill_name} now? [Y/n] "
read run_setup
fi
if [[ ! "$run_setup" =~ ^[Nn]$ ]]; then
echo -e " ${PURPLE}│${NC} ${BLUE}Running $(basename "$script_to_run")...${NC}"
bash "$script_to_run" 2>&1 | while IFS= read -r line; do
echo -e " ${PURPLE}│${NC} $line"
done
echo -e " ${PURPLE}│${NC} ${GREEN}✓ Setup completed for ${skill_name}.${NC}"
else
echo -e " ${PURPLE}│${NC} ${YELLOW}Skipped automated setup.${NC}"
fi
else
if [ "$YES_MODE" -eq 0 ]; then
echo -ne " ${PURPLE}│${NC} Press Enter after you have completed any manual configuration above..."
read dummy
else
echo -e " ${PURPLE}│${NC} ${YELLOW}Auto-skipped manual config in --yes mode${NC}"
fi
fi
echo -e " ${PURPLE}└────────────────────────────────────────────────────────${NC}"
fi
fi
done
# 7.6. Pi Integration and Cockpit Proxy Setup
echo -e "\n${BLUE}[7.6/10] Pi Integration and Cockpit Proxy Setup...${NC}"
PI_SETTINGS="$HOME/.pi/agent/settings.json"
if command -v pi &>/dev/null || [ -f "$PI_SETTINGS" ]; then
echo -e "${GREEN}✓ Pi environment detected. Injecting Wizard-AI as a native package...${NC}"
if [ -f "$PI_SETTINGS" ]; then
if command -v jq &>/dev/null; then
jq '.packages |= (if type=="array" then . else [] end | if index("file://'"$WIZARD_AI_DIR"'") then . else . + ["file://'"$WIZARD_AI_DIR"'"] end)' "$PI_SETTINGS" > "${PI_SETTINGS}.tmp" && mv "${PI_SETTINGS}.tmp" "$PI_SETTINGS"
echo -e "${GREEN} ✓ Wizard-AI repository injected into Pi settings.json${NC}"
else
echo -e "${YELLOW} ⚠ jq not found. Please add \"file://$WIZARD_AI_DIR\" to packages in $PI_SETTINGS manually.${NC}"
fi
fi
fi
if command -v npm &>/dev/null; then
# Auto-detect Cockpit Tools installation
COCKPIT_DETECTED=0
for dir in "$HOME/.antigravity_cockpit" "$HOME/.local/share/cockpit-tools" "$HOME/.config/cockpit-tools" "$HOME/.wizard-ai/cockpit-tools"; do
if [ -d "$dir" ] && ([ -f "$dir/accounts.json" ] || [ -f "$dir/account-token.key" ]); then
COCKPIT_DETECTED=1
echo -e "${GREEN}✓ Auto-detected Cockpit Tools installation at: $dir${NC}"
break
fi
done
echo -e "${YELLOW}Configure Cockpit Tools Proxy Rotator for Pi (Multi-Account Load Balancing)? [Y/n]${NC}"
if [ "$YES_MODE" -eq 1 ]; then
RUN_COCKPIT="y"
echo -e "${YELLOW} (auto-accepted in --yes mode)${NC}"
else
read -p "> " RUN_COCKPIT
fi
if [[ ! "$RUN_COCKPIT" =~ ^[Nn]$ ]]; then
echo -e "${CYAN}Running pi-cockpit-proxy-setup via npx...${NC}"
npx --yes pi-cockpit-proxy-setup || echo -e "${RED}Failed to run pi-cockpit-proxy-setup.${NC}"
echo -e "\n${CYAN}⚙️ Installing and enabling background Proxy Rotator...${NC}"
echo -e "${YELLOW}Il proxy verrà installato e abilitato come servizio in background per evitare problemi di quota (429).${NC}"
# Try local prefix first (no EACCES), then global, then sudo
npm install -g pi-antigravity-rotator --prefix "$HOME/.local" 2>/dev/null \
|| npm install -g pi-antigravity-rotator 2>/dev/null \
|| sudo npm install -g pi-antigravity-rotator \
|| echo -e "${RED}Failed to install pi-antigravity-rotator.${NC}"
# Provision Cockpit Tools accounts, inject Pi config, and enable background daemon
"$HOME/.local/bin/wz-ai-proxy" boot || true
echo -e "\n${GREEN}✓ Proxy configured. Pi will route through the local rotator on port 51200.${NC}"
echo -e "${CYAN} To add Google accounts: wz-ai-proxy login${NC}"
echo -e "${CYAN} To see accounts: wz-ai-proxy accounts${NC}"
echo -e "${CYAN} To check status: wz-ai-proxy status${NC}"
fi
else
echo -e "${YELLOW}NPM not found. Cockpit Proxy setup skipped.${NC}"
fi
# 7.7. Auto-configure Pi Models from Cockpit
echo -e "\n${BLUE}[7.7/10] Auto-configuring Pi Agent Models...${NC}"
if command -v node &>/dev/null; then
echo -e "${YELLOW}Syncing benchmarks and mapping best Cockpit models to Pi roles...${NC}"
node "$WIZARD_AI_DIR/scripts/wz-ai-benchmark-sync.js" 2>/dev/null || true
node "$WIZARD_AI_DIR/scripts/wz-ai-pi-configurator.js" 2>/dev/null || echo -e "${RED}Failed to run pi-configurator.${NC}"
else
echo -e "${YELLOW}Node.js not found. Skipping Pi auto-configuration.${NC}"
fi
# 8. Git & NPM Credentials Setup (Optional for Contributors)
echo -e "\n${BLUE}[8/10] Git & NPM Credentials Setup (Optional for Contributors)...${NC}"
echo -e "${YELLOW}Do you want to configure your GitHub & NPM credentials now? (e.g. for publishing or contributing) [y/N]${NC}"
if [ "$YES_MODE" -eq 1 ]; then
CONFIRM_CREDS="n"
echo -e "${YELLOW} (auto-skipped in --yes mode)${NC}"
else
read -p "> " CONFIRM_CREDS
fi
if [[ "$CONFIRM_CREDS" =~ ^[Yy]$ ]]; then
# NPM Token
echo -e "${CYAN}Please enter your NPM Publishing Token (or press enter to skip):${NC}"
read -s -p "> " USER_NPM_TOKEN
echo ""
if [ -n "$USER_NPM_TOKEN" ]; then
echo "//registry.npmjs.org/:_authToken=$USER_NPM_TOKEN" >> "$HOME/.npmrc"
if ! grep -q "NPM_TOKEN" "$HOME/.config/wizard-ai/env"; then
echo "export NPM_TOKEN=\"$USER_NPM_TOKEN\"" >> "$HOME/.config/wizard-ai/env"
else
sed -i "s|export NPM_TOKEN=.*|export NPM_TOKEN=\"$USER_NPM_TOKEN\"|" "$HOME/.config/wizard-ai/env"
fi
echo -e " ${GREEN}✓ NPM Token registered.${NC}"
fi
# GitHub Token
echo -e "${CYAN}Please enter your GitHub Personal Access Token (or press enter to skip):${NC}"
read -s -p "> " USER_GH_TOKEN
echo ""
if [ -n "$USER_GH_TOKEN" ]; then
# We intentionally DO NOT export GITHUB_TOKEN to ~/.config/wizard-ai/env
# because it overrides the secure keyring authentication used by gh cli.
# We only use it once to login, then let the system keyring handle it.
if command -v gh &>/dev/null; then
echo "$USER_GH_TOKEN" | env -u GITHUB_TOKEN gh auth login --with-token 2>/dev/null && \
echo -e " ${GREEN}✓ Logged in to GitHub CLI successfully.${NC}" || \
echo -e " ${YELLOW}⚠ Could not log in via gh CLI with the provided token.${NC}"
fi
echo -e " ${GREEN}✓ GitHub Token registered.${NC}"
fi
fi
# 9. Auto-Update Configuration
echo -e "\n${BLUE}[9/10] Auto-Update Configuration...${NC}"
echo -e "${YELLOW}Do you want to enable automatic background updates at system boot? [Y/n] (Auto-yes in 10s)${NC}"
ENABLE_UPDATE="Y"
if [ "$YES_MODE" -eq 0 ]; then
read -t 10 -p "> " USER_INPUT || true
if [ -n "$USER_INPUT" ]; then
ENABLE_UPDATE="$USER_INPUT"
fi
fi
if [[ "$ENABLE_UPDATE" =~ ^[Yy]$ ]]; then
echo -e "${GREEN}✓ Enabling automatic background updates at boot...${NC}"
if command -v crontab &>/dev/null; then
CRON_CMD="@reboot $HOME/.local/bin/wz-ai-update --quiet"
(crontab -u "$USER" -l 2>/dev/null | grep -v "wz-ai-update" ; echo "$CRON_CMD") | crontab -u "$USER" -
echo -e "${GREEN} ✓ Cronjob installed for user $USER.${NC}"
elif command -v systemctl &>/dev/null; then
echo -e "${BLUE} i cron not found. Setting up systemd user service instead...${NC}"
mkdir -p "$HOME/.config/systemd/user"
cat > "$HOME/.config/systemd/user/wz-ai-update.service" <<EOF
[Unit]
Description=Wizard-AI Auto Update
After=network-online.target
[Service]
Type=oneshot
ExecStart=$HOME/.local/bin/wz-ai-update --quiet
[Install]
WantedBy=default.target
EOF
chown -R "$USER:$USER" "$HOME/.config/systemd"
if [ -n "${SUDO_USER:-}" ]; then
sudo -u "$USER" XDG_RUNTIME_DIR="/run/user/$REAL_UID" DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$REAL_UID/bus" systemctl --user daemon-reload || true
sudo -u "$USER" XDG_RUNTIME_DIR="/run/user/$REAL_UID" DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$REAL_UID/bus" systemctl --user enable wz-ai-update.service || true
else
systemctl --user daemon-reload || true
systemctl --user enable wz-ai-update.service || true
fi
echo -e "${GREEN} ✓ systemd service installed for user $USER.${NC}"
else
echo -e "${RED}⚠ cron and systemctl not found. Auto-updates cannot be configured.${NC}"
fi
else
echo -e "${YELLOW} Auto-updates disabled. Update manually using 'wz-ai-update'.${NC}"
if command -v crontab &>/dev/null; then
crontab -u "$USER" -l 2>/dev/null | grep -v "wz-ai-update" | crontab -u "$USER" - || true
fi
fi
# 9.5 Optional Docker Deployment for MinerU
echo -e "\n${BLUE}[9.5/10] Optional: MinerU Docker Web UI...${NC}"
if command -v docker &>/dev/null; then
# Default to NO in non-interactive mode unless specified
deploy_mineru="N"
if [ -n "${INTERACTIVE:-}" ] || [ -t 0 ]; then
echo -e "${YELLOW}MinerU provides a Gradio Web UI via Docker for visual PDF parsing.${NC}"
read -p "Do you want to deploy the MinerU Web UI now? (y/N): " response
if [[ "$response" =~ ^[Yy]$ ]]; then
deploy_mineru="Y"
fi
fi
if [ "$deploy_mineru" = "Y" ]; then
echo -e "${GREEN}Starting MinerU Gradio Web UI...${NC}"
if [ -f "$WIZARD_AI_DIR/docker/mineru/compose.yaml" ]; then
docker compose -f "$WIZARD_AI_DIR/docker/mineru/compose.yaml" --profile gradio up -d || true
echo -e "${GREEN}✓ MinerU Web UI is starting at http://localhost:7860${NC}"
else
echo -e "${RED}⚠ compose.yaml not found in docker/mineru/${NC}"
fi
else
echo -e "${YELLOW}Skipping MinerU Web UI deployment. You can start it later with 'wz-ai-mineru-gui up'.${NC}"
fi
else
echo -e "${YELLOW}Docker not found. Skipping MinerU Web UI deployment.${NC}"