-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·1029 lines (922 loc) · 33.2 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·1029 lines (922 loc) · 33.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
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
set -euo pipefail
# ============================================================
# PI / Wisdom-in-Action Engine v20 — One-Click Installer
# Supports 16+ AI coding platforms
# Interactive TUI selector: arrow keys to navigate, space to
# toggle, enter to confirm
# ============================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
PI_REPO_ARCHIVE_URL="${PI_REPO_ARCHIVE_URL:-https://github.com/share-skills/pi/archive/refs/heads/main.tar.gz}"
BOOTSTRAP_TMP_DIR=""
CURSOR_HIDDEN=0
INSTALL_MODE="copy"
# Parse command-line arguments
for arg in "$@"; do
case "$arg" in
--link|--symlink) INSTALL_MODE="link" ;;
esac
done
cleanup_bootstrap_dir() {
if [[ -n "$BOOTSTRAP_TMP_DIR" && -d "$BOOTSTRAP_TMP_DIR" ]]; then
rm -rf "$BOOTSTRAP_TMP_DIR"
fi
}
restore_cursor() {
if [[ "$CURSOR_HIDDEN" == "1" ]]; then
printf '\033[?25h'
CURSOR_HIDDEN=0
fi
}
on_exit() {
restore_cursor
cleanup_bootstrap_dir
}
trap on_exit EXIT
repo_assets_present() {
local dir="$1"
[[ -f "$dir/install.sh" ]] \
&& [[ -f "$dir/commands/pi.md" ]] \
&& [[ -f "$dir/skills/pi/SKILL.md" ]]
}
ensure_script_dir() {
if repo_assets_present "$SCRIPT_DIR"; then
return 0
fi
if ! command -v curl >/dev/null 2>&1; then
echo "install.sh requires curl when running outside a PI checkout." >&2
exit 1
fi
if ! command -v tar >/dev/null 2>&1; then
echo "install.sh requires tar when bootstrapping PI assets from the release archive." >&2
exit 1
fi
BOOTSTRAP_TMP_DIR="$(mktemp -d)"
local archive="$BOOTSTRAP_TMP_DIR/pi.tar.gz"
local extract_root="$BOOTSTRAP_TMP_DIR/extract"
mkdir -p "$extract_root"
curl -fsSL "$PI_REPO_ARCHIVE_URL" -o "$archive"
tar -xzf "$archive" -C "$extract_root"
local extracted_dir
extracted_dir="$(find "$extract_root" -mindepth 1 -maxdepth 1 -type d | head -n 1)"
if [[ -z "$extracted_dir" ]] || ! repo_assets_present "$extracted_dir"; then
echo "Failed to bootstrap PI installer assets from $PI_REPO_ARCHIVE_URL" >&2
exit 1
fi
SCRIPT_DIR="$extracted_dir"
}
# --- Locale detection ---
detect_lang() {
local locale="${LANG:-${LC_ALL:-${LC_MESSAGES:-en}}}"
case "$locale" in
zh*|ZH*) echo "zh" ;;
*) echo "en" ;;
esac
}
LANG_CODE="$(detect_lang)"
# --- i18n messages ---
if [[ "$LANG_CODE" == "zh" ]]; then
MSG_TITLE="🐲 PI 智行合一引擎 — 一键安装"
MSG_DETECT="正在检测可用平台..."
MSG_FOUND="检测到以下平台(↑↓ 移动,空格 选择/取消,a 全选/全不选,回车 确认):"
MSG_NONE="未检测到任何已知平台。请先安装至少一个支持的 AI 编程工具。"
MSG_LANG_TITLE="选择语言版本(↑↓ 移动,回车 确认):"
MSG_EDITION_TITLE="选择 PI 版本(↑↓ 移动,回车 确认):"
MSG_INSTALLING="正在安装到"
MSG_DONE="安装完成!"
MSG_SKIP="跳过(未在仓库中找到对应文件)"
MSG_COACH_TITLE="是否安装 Agent Team 角色?(↑↓ 移动,回车 确认):"
MSG_COACH_DONE="Agent Team 文件已安装到"
MSG_VISUALIZER_READY="可视化启动器已安装到"
MSG_VISUALIZER_SKIP="跳过可视化启动器(未找到 setup 脚本,且无法自动下载)"
MSG_SUCCESS="🐲 PI 智行合一引擎安装成功!善战者,致人而不致于人。"
MSG_INVALID="无效选择,请重新输入"
MSG_NO_SELECTION="未选择任何平台,退出安装"
LANG_OPT_1="中文"
LANG_OPT_2="英文"
LANG_OPT_3="双语(中文 + 英文)"
EDITION_OPT_1="原版(完整认知框架,适合大模型)"
EDITION_OPT_2="渐进式(轻量引导+按需加载,适合上下文敏感场景)"
EDITION_OPT_3="两个都装"
COACH_OPT_Y="是,安装 Teammate + Coach"
COACH_OPT_N="否,跳过"
else
MSG_TITLE="🐲 PI Wisdom-in-Action Engine — One-Click Install"
MSG_DETECT="Detecting available platforms..."
MSG_FOUND="Detected platforms (↑↓ move, Space toggle, a select/deselect all, Enter confirm):"
MSG_NONE="No known platforms detected. Please install at least one supported AI coding tool first."
MSG_LANG_TITLE="Select language (↑↓ move, Enter confirm):"
MSG_EDITION_TITLE="Select PI edition (↑↓ move, Enter confirm):"
MSG_INSTALLING="Installing to"
MSG_DONE="Installation complete!"
MSG_SKIP="Skipped (source files not found in repo)"
MSG_COACH_TITLE="Install Agent Team roles? (↑↓ move, Enter confirm):"
MSG_COACH_DONE="Agent Team files installed to"
MSG_VISUALIZER_READY="Visualizer launcher installed to"
MSG_VISUALIZER_SKIP="Skipped visualizer launcher (setup script missing and auto-download unavailable)"
MSG_SUCCESS="🐲 PI Engine installed successfully! Wisdom in Action — control the pace."
MSG_INVALID="Invalid selection, please try again"
MSG_NO_SELECTION="No platforms selected, exiting"
LANG_OPT_1="Chinese"
LANG_OPT_2="English"
LANG_OPT_3="Both (Chinese + English)"
EDITION_OPT_1="Original (full cognitive framework)"
EDITION_OPT_2="Progressive (lightweight bootstrap + on-demand loading)"
EDITION_OPT_3="Both"
COACH_OPT_Y="Yes, install Teammate + Coach"
COACH_OPT_N="No, skip"
fi
ensure_script_dir
# ============================================================
# TUI Components — pure bash interactive selectors
# ============================================================
# Colors
_C_RESET='\033[0m'
_C_BOLD='\033[1m'
_C_DIM='\033[2m'
_C_CYAN='\033[36m'
_C_GREEN='\033[32m'
_C_YELLOW='\033[33m'
# Read a single keypress, handling escape sequences for arrow keys
_read_key() {
local key
IFS= read -rsn1 key < /dev/tty 2>/dev/null || true
if [[ "$key" == $'\x1b' ]]; then
local seq
# Bash 3.2 (macOS default) truncates -t 0.1 to -t 0 (immediate timeout),
# so we use -t 1 to reliably capture arrow key escape sequences.
IFS= read -rsn1 -t 1 seq < /dev/tty 2>/dev/null || true
if [[ "$seq" == "[" ]]; then
IFS= read -rsn1 -t 1 seq < /dev/tty 2>/dev/null || true
case "$seq" in
A) echo "UP" ;;
B) echo "DOWN" ;;
C) echo "RIGHT" ;;
D) echo "LEFT" ;;
*) echo "OTHER" ;;
esac
else
echo "ESC"
fi
elif [[ "$key" == "" ]]; then
echo "ENTER"
elif [[ "$key" == " " ]]; then
echo "SPACE"
elif [[ "$key" == "a" || "$key" == "A" ]]; then
echo "ALL"
elif [[ "$key" == "q" || "$key" == "Q" ]]; then
echo "QUIT"
else
echo "OTHER"
fi
}
# Multi-select checkbox TUI
# Usage: multiselect result_var "title" option1 option2 ...
# Sets result_var to space-separated indices (0-based) of selected items
multiselect() {
local _result_var="$1"
local _title="$2"
shift 2
local -a _options=("$@")
local _count=${#_options[@]}
local _cursor=0
local -a _selected=()
# Initialize all as selected
for ((i = 0; i < _count; i++)); do
_selected+=("1")
done
# Hide cursor
printf '\033[?25l'
CURSOR_HIDDEN=1
while true; do
# Move cursor to start and clear lines
printf '\r'
# Print title
printf "${_C_BOLD}${_C_CYAN}%s${_C_RESET}\n" "$_title"
# Print options
for ((i = 0; i < _count; i++)); do
local _check
if [[ "${_selected[$i]}" == "1" ]]; then
_check="${_C_GREEN}[x]${_C_RESET}"
else
_check="${_C_DIM}[ ]${_C_RESET}"
fi
if [[ $i -eq $_cursor ]]; then
printf " ${_C_YELLOW}▸${_C_RESET} ${_check} ${_C_BOLD}%s${_C_RESET}\n" "${_options[$i]}"
else
printf " ${_check} %s\n" "${_options[$i]}"
fi
done
# Read key
local _key
_key=$(_read_key)
# Move cursor up to redraw (title + options)
printf "\033[%dA" $((_count + 1))
case "$_key" in
UP)
((_cursor > 0)) && ((_cursor--)) || true
;;
DOWN)
((_cursor < _count - 1)) && ((_cursor++)) || true
;;
SPACE)
if [[ "${_selected[$_cursor]}" == "1" ]]; then
_selected[$_cursor]="0"
else
_selected[$_cursor]="1"
fi
;;
ALL)
# Toggle all: if any unselected, select all; else deselect all
local _any_off=0
for ((i = 0; i < _count; i++)); do
[[ "${_selected[$i]}" == "0" ]] && _any_off=1
done
local _new_val="0"
[[ $_any_off -eq 1 ]] && _new_val="1"
for ((i = 0; i < _count; i++)); do
_selected[$i]="$_new_val"
done
;;
ENTER)
# Final redraw
printf '\r'
printf "${_C_BOLD}${_C_CYAN}%s${_C_RESET}\n" "$_title"
for ((i = 0; i < _count; i++)); do
local _check
if [[ "${_selected[$i]}" == "1" ]]; then
_check="${_C_GREEN}[x]${_C_RESET}"
else
_check="${_C_DIM}[ ]${_C_RESET}"
fi
if [[ $i -eq $_cursor ]]; then
printf " ${_C_YELLOW}▸${_C_RESET} ${_check} ${_C_BOLD}%s${_C_RESET}\n" "${_options[$i]}"
else
printf " ${_check} %s\n" "${_options[$i]}"
fi
done
# Collect results
local _result=""
for ((i = 0; i < _count; i++)); do
if [[ "${_selected[$i]}" == "1" ]]; then
_result+="$i "
fi
done
restore_cursor
eval "$_result_var='${_result% }'"
return 0
;;
QUIT)
restore_cursor
echo ""
exit 0
;;
esac
done
}
# Single-select radio TUI
# Usage: singleselect result_var "title" option1 option2 ...
# Sets result_var to the index (0-based) of the selected item
singleselect() {
local _result_var="$1"
local _title="$2"
shift 2
local -a _options=("$@")
local _count=${#_options[@]}
local _cursor=0
# Hide cursor
printf '\033[?25l'
CURSOR_HIDDEN=1
while true; do
printf '\r'
printf "${_C_BOLD}${_C_CYAN}%s${_C_RESET}\n" "$_title"
for ((i = 0; i < _count; i++)); do
local _radio
if [[ $i -eq $_cursor ]]; then
_radio="${_C_GREEN}(*)${_C_RESET}"
printf " ${_C_YELLOW}▸${_C_RESET} ${_radio} ${_C_BOLD}%s${_C_RESET}\n" "${_options[$i]}"
else
_radio="${_C_DIM}( )${_C_RESET}"
printf " ${_radio} %s\n" "${_options[$i]}"
fi
done
local _key
_key=$(_read_key)
printf "\033[%dA" $((_count + 1))
case "$_key" in
UP)
((_cursor > 0)) && ((_cursor--)) || true
;;
DOWN)
((_cursor < _count - 1)) && ((_cursor++)) || true
;;
ENTER)
# Final redraw
printf '\r'
printf "${_C_BOLD}${_C_CYAN}%s${_C_RESET}\n" "$_title"
for ((i = 0; i < _count; i++)); do
local _radio
if [[ $i -eq $_cursor ]]; then
_radio="${_C_GREEN}(*)${_C_RESET}"
printf " ${_C_YELLOW}▸${_C_RESET} ${_radio} ${_C_BOLD}%s${_C_RESET}\n" "${_options[$i]}"
else
_radio="${_C_DIM}( )${_C_RESET}"
printf " ${_radio} %s\n" "${_options[$i]}"
fi
done
restore_cursor
eval "$_result_var=$_cursor"
return 0
;;
QUIT)
restore_cursor
echo ""
exit 0
;;
esac
done
}
# ============================================================
# Platform detection & install functions
# ============================================================
declare -a DETECTED=()
VISUALIZER_SETUP_URL="${PI_VISUALIZER_SETUP_URL:-https://raw.githubusercontent.com/share-skills/pi/main/scripts/setup-standalone-visualize.sh}"
# Detection functions
detect_claude_code() { [[ -d "$HOME/.claude" ]]; }
detect_codex_cli() { [[ -d "$HOME/.codex" ]] || command -v codex &>/dev/null; }
detect_cursor() { [[ -d ".cursor" ]] || [[ -d "$HOME/.cursor" ]]; }
detect_kiro() { [[ -d ".kiro" ]] || [[ -d "$HOME/.kiro" ]]; }
detect_openclaw() { [[ -d "$HOME/.openclaw" ]] || command -v claw &>/dev/null; }
detect_antigravity() { [[ -d "$HOME/.gemini/antigravity" ]]; }
detect_opencode() { [[ -d "$HOME/.config/opencode" ]] || command -v opencode &>/dev/null; }
detect_gemini_cli() { [[ -d "$HOME/.gemini" ]] || command -v gemini &>/dev/null; }
detect_copilot_cli() { [[ -d "$HOME/.copilot" ]] || command -v github-copilot-cli &>/dev/null; }
detect_qwen_code() { [[ -d "$HOME/.qwen" ]] || command -v qwen &>/dev/null; }
detect_qoder_cli() { [[ -d "$HOME/.qoder" ]] || command -v qoder &>/dev/null; }
detect_iflow() { [[ -d "$HOME/.iflow" ]] || command -v iflow &>/dev/null; }
detect_copaw() { [[ -d "$HOME/.copaw" ]] || command -v copaw &>/dev/null; }
detect_trae() { [[ -d "$HOME/.trae" ]] || [[ -d ".trae" ]] || command -v trae &>/dev/null; }
detect_augment() { [[ -d "$HOME/.augment" ]] || [[ -d ".augment" ]] || command -v augment &>/dev/null; }
detect_windsurf() { [[ -d "$HOME/.windsurf" ]] || [[ -d ".windsurf" ]] || command -v windsurf &>/dev/null; }
# Install helper — smart copy (supports --link symlink mode)
smart_copy() {
local src="$1" dst="$2"
if [[ "$INSTALL_MODE" == "link" ]]; then
local abs_src
abs_src="$(cd "$(dirname "$src")" && pwd)/$(basename "$src")"
ln -sf "$abs_src" "$dst"
else
cp "$src" "$dst"
fi
}
smart_copy_dir() {
local src="$1" dst="$2"
if [[ "$INSTALL_MODE" == "link" ]]; then
local abs_src
abs_src="$(cd "$src" && pwd)"
ln -sfn "$abs_src" "$dst"
else
cp -r "$src" "$dst"
fi
}
# Install helper
install_skill_to_dir() {
local target_dir="$1"
local source_dir="$2"
local cn_name="$3"
local en_name="$4"
local lang="$5"
local edition="$6"
# Clean old files before copying to ensure overwrite
if [[ "$lang" == "1" || "$lang" == "3" ]]; then
rm -rf "${target_dir:?}/$cn_name"
[[ "$edition" == "3" ]] && rm -rf "${target_dir:?}/${cn_name}-progressive"
fi
if [[ "$lang" == "2" || "$lang" == "3" ]]; then
rm -rf "${target_dir:?}/$en_name"
[[ "$edition" == "3" ]] && rm -rf "${target_dir:?}/${en_name}-progressive"
fi
if [[ "$lang" == "1" || "$lang" == "3" ]]; then
if [[ "$edition" == "1" || "$edition" == "3" ]]; then
# Original
if [[ -f "$source_dir/$cn_name/SKILL.md" ]]; then
mkdir -p "$target_dir/$cn_name"
smart_copy "$source_dir/$cn_name/SKILL.md" "$target_dir/$cn_name/SKILL.md"
fi
fi
if [[ "$edition" == "2" ]]; then
# Progressive only → install as main skill
if [[ -f "$source_dir/${cn_name}-progressive/SKILL.md" ]]; then
mkdir -p "$target_dir/$cn_name"
smart_copy "$source_dir/${cn_name}-progressive/SKILL.md" "$target_dir/$cn_name/SKILL.md"
if [[ -d "$source_dir/${cn_name}-progressive/references" ]]; then
smart_copy_dir "$source_dir/${cn_name}-progressive/references" "$target_dir/$cn_name/references"
fi
fi
fi
if [[ "$edition" == "3" ]]; then
# Both → progressive goes to separate dir
if [[ -f "$source_dir/${cn_name}-progressive/SKILL.md" ]]; then
mkdir -p "$target_dir/${cn_name}-progressive"
smart_copy "$source_dir/${cn_name}-progressive/SKILL.md" "$target_dir/${cn_name}-progressive/SKILL.md"
if [[ -d "$source_dir/${cn_name}-progressive/references" ]]; then
smart_copy_dir "$source_dir/${cn_name}-progressive/references" "$target_dir/${cn_name}-progressive/references"
fi
fi
fi
fi
if [[ "$lang" == "2" || "$lang" == "3" ]]; then
if [[ "$edition" == "1" || "$edition" == "3" ]]; then
# Original
if [[ -f "$source_dir/$en_name/SKILL.md" ]]; then
mkdir -p "$target_dir/$en_name"
smart_copy "$source_dir/$en_name/SKILL.md" "$target_dir/$en_name/SKILL.md"
fi
fi
if [[ "$edition" == "2" ]]; then
# Progressive only → install as main skill
if [[ -f "$source_dir/${en_name}-progressive/SKILL.md" ]]; then
mkdir -p "$target_dir/$en_name"
smart_copy "$source_dir/${en_name}-progressive/SKILL.md" "$target_dir/$en_name/SKILL.md"
if [[ -d "$source_dir/${en_name}-progressive/references" ]]; then
smart_copy_dir "$source_dir/${en_name}-progressive/references" "$target_dir/$en_name/references"
fi
fi
fi
if [[ "$edition" == "3" ]]; then
# Both → progressive goes to separate dir
if [[ -f "$source_dir/${en_name}-progressive/SKILL.md" ]]; then
mkdir -p "$target_dir/${en_name}-progressive"
smart_copy "$source_dir/${en_name}-progressive/SKILL.md" "$target_dir/${en_name}-progressive/SKILL.md"
if [[ -d "$source_dir/${en_name}-progressive/references" ]]; then
smart_copy_dir "$source_dir/${en_name}-progressive/references" "$target_dir/${en_name}-progressive/references"
fi
fi
fi
fi
}
prepare_visualizer_setup_script() {
local dest="$1"
local source="$SCRIPT_DIR/scripts/setup-standalone-visualize.sh"
mkdir -p "$(dirname "$dest")"
if [[ -f "$source" ]]; then
cp "$source" "$dest"
elif command -v curl >/dev/null 2>&1; then
curl -fsSL "$VISUALIZER_SETUP_URL" -o "$dest"
else
return 1
fi
chmod +x "$dest"
}
install_visualizer_launcher() {
local pi_root="$HOME/.pi"
local setup_script="$pi_root/setup-standalone-visualize.sh"
local launcher="$pi_root/visualize.sh"
if ! prepare_visualizer_setup_script "$setup_script"; then
echo " $MSG_VISUALIZER_SKIP"
return 0
fi
if ! command -v node >/dev/null 2>&1; then
if [[ "$LANG_CODE" == "zh" ]]; then
echo " ⚠️ 未检测到 Node.js。可视化启动器已安装,但首次运行时需要 node 和 npm。"
echo " 安装 Node.js: https://nodejs.org/"
else
echo " ⚠️ Node.js not detected. Visualizer launcher installed, but node & npm are required on first run."
echo " Install Node.js: https://nodejs.org/"
fi
fi
cat > "$launcher" <<EOF
#!/usr/bin/env bash
set -euo pipefail
PI_ROOT="\${HOME}/.pi"
INSTALL_DIR="\${PI_ROOT}/visualize"
SETUP_SCRIPT="\${PI_ROOT}/setup-standalone-visualize.sh"
CLONED_SETUP_SCRIPT="\${INSTALL_DIR}/scripts/setup-standalone-visualize.sh"
if [[ ! -f "\${INSTALL_DIR}/visualize/package.json" ]]; then
echo "PI visualizer runtime is not installed yet."
echo "Bootstrapping standalone visualizer into \${INSTALL_DIR}..."
if [[ ! -x "\$SETUP_SCRIPT" ]]; then
if [[ -r "\$CLONED_SETUP_SCRIPT" ]]; then
echo "Restoring setup script from \${CLONED_SETUP_SCRIPT}..."
cp "\$CLONED_SETUP_SCRIPT" "\$SETUP_SCRIPT"
chmod +x "\$SETUP_SCRIPT"
elif command -v curl >/dev/null 2>&1; then
echo "Refreshing missing setup script into \$SETUP_SCRIPT..."
curl -fsSL "$VISUALIZER_SETUP_URL" -o "\$SETUP_SCRIPT"
chmod +x "\$SETUP_SCRIPT"
else
echo "Missing setup script: \$SETUP_SCRIPT" >&2
exit 1
fi
fi
bash "\$SETUP_SCRIPT"
fi
cd "\${INSTALL_DIR}/visualize"
if [[ ! -d "node_modules" ]]; then
npm install
fi
exec npm run server -- "\$@"
EOF
chmod +x "$launcher"
echo " $MSG_VISUALIZER_READY $launcher"
}
install_claude_code() {
local lang="$1"
local edition="$2"
local skills_base="$HOME/.claude/skills"
local agents_dir="$HOME/.claude/agents"
local commands_dir="$HOME/.claude/commands"
local target="$skills_base/pi"
# Clean all PI skill directories — including broken legacy nested layouts
# (older installer versions placed .claude-plugin/, agents/, commands/ INSIDE
# the skill dir, which is invalid and prevented Claude Code from recognizing
# the skill).
rm -rf "${target:?}"
rm -rf "$skills_base/pi-en" "$skills_base/pi-progressive" "$skills_base/pi-en-progressive"
# Skill directories MUST contain ONLY SKILL.md (and optional references/).
# Agents and commands live in their own global directories so Claude Code
# discovers them properly.
local primary_installed=0
# --- Chinese skill ---
if [[ "$lang" == "1" || "$lang" == "3" ]]; then
if [[ "$edition" == "1" || "$edition" == "3" ]]; then
if [[ -f "$SCRIPT_DIR/claude-code/pi/SKILL.md" ]]; then
mkdir -p "$target"
smart_copy "$SCRIPT_DIR/claude-code/pi/SKILL.md" "$target/SKILL.md"
primary_installed=1
fi
fi
if [[ "$edition" == "2" ]]; then
if [[ -f "$SCRIPT_DIR/claude-code/pi-progressive/SKILL.md" ]]; then
mkdir -p "$target"
smart_copy "$SCRIPT_DIR/claude-code/pi-progressive/SKILL.md" "$target/SKILL.md"
if [[ -d "$SCRIPT_DIR/claude-code/pi-progressive/references" ]]; then
smart_copy_dir "$SCRIPT_DIR/claude-code/pi-progressive/references" "$target/references"
fi
primary_installed=1
fi
fi
if [[ "$edition" == "3" ]]; then
if [[ -f "$SCRIPT_DIR/claude-code/pi-progressive/SKILL.md" ]]; then
mkdir -p "$skills_base/pi-progressive"
smart_copy "$SCRIPT_DIR/claude-code/pi-progressive/SKILL.md" "$skills_base/pi-progressive/SKILL.md"
if [[ -d "$SCRIPT_DIR/claude-code/pi-progressive/references" ]]; then
smart_copy_dir "$SCRIPT_DIR/claude-code/pi-progressive/references" "$skills_base/pi-progressive/references"
fi
fi
fi
fi
# --- English skill ---
if [[ "$lang" == "2" || "$lang" == "3" ]]; then
local en_src="$SCRIPT_DIR/claude-code/pi-en"
local en_prog_src="$SCRIPT_DIR/claude-code/pi-en-progressive"
[[ ! -f "$en_src/SKILL.md" ]] && en_src="$SCRIPT_DIR/skills/pi-en"
[[ ! -f "$en_prog_src/SKILL.md" ]] && en_prog_src="$SCRIPT_DIR/skills/pi-en-progressive"
# If Chinese wasn't installed, English becomes primary at $target
local en_dir="$skills_base/pi-en"
[[ "$primary_installed" == "0" ]] && en_dir="$target"
if [[ "$edition" == "1" || "$edition" == "3" ]]; then
if [[ -f "$en_src/SKILL.md" ]]; then
mkdir -p "$en_dir"
smart_copy "$en_src/SKILL.md" "$en_dir/SKILL.md"
fi
fi
if [[ "$edition" == "2" ]]; then
if [[ -f "$en_prog_src/SKILL.md" ]]; then
mkdir -p "$en_dir"
smart_copy "$en_prog_src/SKILL.md" "$en_dir/SKILL.md"
if [[ -d "$en_prog_src/references" ]]; then
smart_copy_dir "$en_prog_src/references" "$en_dir/references"
fi
fi
fi
if [[ "$edition" == "3" ]]; then
if [[ -f "$en_prog_src/SKILL.md" ]]; then
mkdir -p "$skills_base/pi-en-progressive"
smart_copy "$en_prog_src/SKILL.md" "$skills_base/pi-en-progressive/SKILL.md"
if [[ -d "$en_prog_src/references" ]]; then
smart_copy_dir "$en_prog_src/references" "$skills_base/pi-en-progressive/references"
fi
fi
fi
fi
# --- Agents → ~/.claude/agents/ ---
mkdir -p "$agents_dir"
rm -f "$agents_dir/pi-coach.md" "$agents_dir/pi-teammate.md" \
"$agents_dir/pi-coach-en.md" "$agents_dir/pi-teammate-en.md" 2>/dev/null || true
if [[ "$lang" == "1" || "$lang" == "3" ]]; then
[[ -f "$SCRIPT_DIR/agents/pi-coach.md" ]] && smart_copy "$SCRIPT_DIR/agents/pi-coach.md" "$agents_dir/pi-coach.md"
[[ -f "$SCRIPT_DIR/agents/pi-teammate.md" ]] && smart_copy "$SCRIPT_DIR/agents/pi-teammate.md" "$agents_dir/pi-teammate.md"
fi
if [[ "$lang" == "2" || "$lang" == "3" ]]; then
[[ -f "$SCRIPT_DIR/agents/pi-coach-en.md" ]] && smart_copy "$SCRIPT_DIR/agents/pi-coach-en.md" "$agents_dir/pi-coach-en.md"
[[ -f "$SCRIPT_DIR/agents/pi-teammate-en.md" ]] && smart_copy "$SCRIPT_DIR/agents/pi-teammate-en.md" "$agents_dir/pi-teammate-en.md"
fi
# --- Commands → ~/.claude/commands/ ---
if [[ -d "$SCRIPT_DIR/commands" ]]; then
mkdir -p "$commands_dir"
local cmd
for cmd in "$SCRIPT_DIR/commands"/*.md; do
[[ -f "$cmd" ]] || continue
smart_copy "$cmd" "$commands_dir/$(basename "$cmd")"
done
fi
echo " $MSG_INSTALLING $target"
}
install_codex_cli() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.codex/skills" "$SCRIPT_DIR/skills" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.codex/skills/"
}
install_cursor() {
local lang="$1"
local edition="$2"
local target=".cursor/rules"
mkdir -p "$target"
if [[ "$lang" == "1" || "$lang" == "3" ]]; then
if [[ "$edition" == "1" || "$edition" == "3" ]]; then
[[ -f "$SCRIPT_DIR/cursor/rules/pi.mdc" ]] && smart_copy "$SCRIPT_DIR/cursor/rules/pi.mdc" "$target/pi.mdc"
fi
if [[ "$edition" == "2" ]]; then
# Cursor doesn't support references/, progressive uses full version
[[ -f "$SCRIPT_DIR/cursor/rules/pi.mdc" ]] && smart_copy "$SCRIPT_DIR/cursor/rules/pi.mdc" "$target/pi.mdc"
fi
fi
if [[ "$lang" == "2" || "$lang" == "3" ]]; then
if [[ "$edition" == "1" || "$edition" == "3" ]]; then
[[ -f "$SCRIPT_DIR/cursor/rules/pi-en.mdc" ]] && smart_copy "$SCRIPT_DIR/cursor/rules/pi-en.mdc" "$target/pi-en.mdc"
fi
if [[ "$edition" == "2" ]]; then
# Cursor doesn't support references/, progressive uses full version
[[ -f "$SCRIPT_DIR/cursor/rules/pi-en.mdc" ]] && smart_copy "$SCRIPT_DIR/cursor/rules/pi-en.mdc" "$target/pi-en.mdc"
fi
fi
[[ -f "$SCRIPT_DIR/cursor/rules/pi-visualize.mdc" ]] && smart_copy "$SCRIPT_DIR/cursor/rules/pi-visualize.mdc" "$target/pi-visualize.mdc"
echo " $MSG_INSTALLING $target"
}
install_kiro() {
local lang="$1"
local edition="$2"
local target=".kiro/steering"
mkdir -p "$target"
if [[ "$lang" == "1" || "$lang" == "3" ]]; then
if [[ "$edition" == "1" || "$edition" == "3" ]]; then
[[ -f "$SCRIPT_DIR/kiro/steering/pi.md" ]] && smart_copy "$SCRIPT_DIR/kiro/steering/pi.md" "$target/pi.md"
fi
if [[ "$edition" == "2" ]]; then
# Kiro doesn't support references/, progressive uses full version
[[ -f "$SCRIPT_DIR/kiro/steering/pi.md" ]] && smart_copy "$SCRIPT_DIR/kiro/steering/pi.md" "$target/pi.md"
fi
fi
if [[ "$lang" == "2" || "$lang" == "3" ]]; then
if [[ "$edition" == "1" || "$edition" == "3" ]]; then
[[ -f "$SCRIPT_DIR/kiro/steering/pi-en.md" ]] && smart_copy "$SCRIPT_DIR/kiro/steering/pi-en.md" "$target/pi-en.md"
fi
if [[ "$edition" == "2" ]]; then
# Kiro doesn't support references/, progressive uses full version
[[ -f "$SCRIPT_DIR/kiro/steering/pi-en.md" ]] && smart_copy "$SCRIPT_DIR/kiro/steering/pi-en.md" "$target/pi-en.md"
fi
fi
echo " $MSG_INSTALLING $target"
}
install_openclaw() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.openclaw/skills" "$SCRIPT_DIR/openclaw" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.openclaw/skills/"
}
install_antigravity() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.gemini/antigravity/skills" "$SCRIPT_DIR/skills" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.gemini/antigravity/skills/"
}
install_opencode() {
local lang="$1"
local edition="$2"
local base="$HOME/.config/opencode"
local skills_src="$SCRIPT_DIR/opencode"
[[ -d "$skills_src" ]] || skills_src="$SCRIPT_DIR/skills"
install_skill_to_dir "$base/skills" "$skills_src" "pi" "pi-en" "$lang" "$edition"
# --- Agents → ~/.config/opencode/agents/ ---
local agents_dir="$base/agents"
mkdir -p "$agents_dir"
rm -f "$agents_dir/pi-coach.md" "$agents_dir/pi-teammate.md" \
"$agents_dir/pi-coach-en.md" "$agents_dir/pi-teammate-en.md" 2>/dev/null || true
if [[ "$lang" == "1" || "$lang" == "3" ]]; then
[[ -f "$SCRIPT_DIR/agents/pi-coach.md" ]] && smart_copy "$SCRIPT_DIR/agents/pi-coach.md" "$agents_dir/pi-coach.md"
[[ -f "$SCRIPT_DIR/agents/pi-teammate.md" ]] && smart_copy "$SCRIPT_DIR/agents/pi-teammate.md" "$agents_dir/pi-teammate.md"
fi
if [[ "$lang" == "2" || "$lang" == "3" ]]; then
[[ -f "$SCRIPT_DIR/agents/pi-coach-en.md" ]] && smart_copy "$SCRIPT_DIR/agents/pi-coach-en.md" "$agents_dir/pi-coach-en.md"
[[ -f "$SCRIPT_DIR/agents/pi-teammate-en.md" ]] && smart_copy "$SCRIPT_DIR/agents/pi-teammate-en.md" "$agents_dir/pi-teammate-en.md"
fi
# --- Commands → ~/.config/opencode/commands/ ---
if [[ -d "$SCRIPT_DIR/commands" ]]; then
local commands_dir="$base/commands"
mkdir -p "$commands_dir"
local cmd
for cmd in "$SCRIPT_DIR/commands"/*.md; do
[[ -f "$cmd" ]] || continue
smart_copy "$cmd" "$commands_dir/$(basename "$cmd")"
done
fi
echo " $MSG_INSTALLING ~/.config/opencode/{skills,agents,commands}/"
}
install_gemini_cli() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.gemini/skills" "$SCRIPT_DIR/skills" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.gemini/skills/"
}
install_copilot_cli() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.copilot/skills" "$SCRIPT_DIR/copilot-cli" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.copilot/skills/"
}
install_qwen_code() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.qwen/skills" "$SCRIPT_DIR/skills" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.qwen/skills/"
}
install_qoder_cli() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.qoder/skills" "$SCRIPT_DIR/skills" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.qoder/skills/"
}
install_iflow() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.iflow/skills" "$SCRIPT_DIR/skills" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.iflow/skills/"
}
install_copaw() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.copaw/skills" "$SCRIPT_DIR/skills" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.copaw/skills/"
}
install_trae() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.trae/skills" "$SCRIPT_DIR/skills" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.trae/skills/"
}
install_augment() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.augment/skills" "$SCRIPT_DIR/skills" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.augment/skills/"
}
install_windsurf() {
local lang="$1"
local edition="$2"
install_skill_to_dir "$HOME/.windsurf/skills" "$SCRIPT_DIR/skills" "pi" "pi-en" "$lang" "$edition"
echo " $MSG_INSTALLING ~/.windsurf/skills/"
}
# --- Platform registry ---
PLATFORM_NAMES=(
"Claude Code"
"Codex CLI"
"Cursor"
"Kiro"
"OpenClaw"
"Antigravity"
"OpenCode"
"Gemini CLI"
"Copilot CLI"
"Qwen Code"
"Qoder"
"Iflow"
"COPAW"
"Trae"
"Augment"
"Windsurf"
)
PLATFORM_DETECTORS=(
detect_claude_code
detect_codex_cli
detect_cursor
detect_kiro
detect_openclaw
detect_antigravity
detect_opencode
detect_gemini_cli
detect_copilot_cli
detect_qwen_code
detect_qoder_cli
detect_iflow
detect_copaw
detect_trae
detect_augment
detect_windsurf
)
PLATFORM_INSTALLERS=(
install_claude_code
install_codex_cli
install_cursor
install_kiro
install_openclaw
install_antigravity
install_opencode
install_gemini_cli
install_copilot_cli
install_qwen_code
install_qoder_cli
install_iflow
install_copaw
install_trae
install_augment
install_windsurf
)
# ============================================================
# Main flow
# ============================================================
echo ""
echo "============================================"
echo " $MSG_TITLE"
if [[ "$INSTALL_MODE" == "link" ]]; then
echo " [symlink mode]"
fi
echo "============================================"
echo ""
# --- Detect platforms ---
echo "$MSG_DETECT"
echo ""
for i in "${!PLATFORM_NAMES[@]}"; do
if ${PLATFORM_DETECTORS[$i]} 2>/dev/null; then
DETECTED+=("$i")
fi
done
if [[ ${#DETECTED[@]} -eq 0 ]]; then
echo "$MSG_NONE"
echo ""
echo "Supported platforms: ${PLATFORM_NAMES[*]}"
exit 0
fi
# --- Step 1: Select platforms (multi-select) ---
declare -a detected_names=()
for i in "${DETECTED[@]}"; do
detected_names+=("${PLATFORM_NAMES[$i]}")
done
platform_result=""
multiselect platform_result "$MSG_FOUND" "${detected_names[@]}"
echo ""
# Parse selected indices
declare -a SELECTED=()
if [[ -n "$platform_result" ]]; then
for idx in $platform_result; do
SELECTED+=("${DETECTED[$idx]}")
done
fi
if [[ ${#SELECTED[@]} -eq 0 ]]; then
echo "$MSG_NO_SELECTION"
exit 0
fi
# --- Step 2: Select language (single-select) ---
lang_result=0
singleselect lang_result "$MSG_LANG_TITLE" "$LANG_OPT_1" "$LANG_OPT_2" "$LANG_OPT_3"
lang_choice=$((lang_result + 1))
echo ""
# --- Step 3: Select edition (single-select) ---
edition_result=0
singleselect edition_result "$MSG_EDITION_TITLE" "$EDITION_OPT_1" "$EDITION_OPT_2" "$EDITION_OPT_3"
edition_choice=$((edition_result + 1))
echo ""
# --- Step 4: Install ---
echo "--------------------------------------------"
for i in "${SELECTED[@]}"; do
echo "${PLATFORM_NAMES[$i]}:"
${PLATFORM_INSTALLERS[$i]} "$lang_choice" "$edition_choice"
done
install_visualizer_launcher