-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·1317 lines (1139 loc) · 36 KB
/
install.sh
File metadata and controls
executable file
·1317 lines (1139 loc) · 36 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
#
# agt — Installer
# Install skills to ~/.claude/skills directory.
#
# 사용법:
# ./install.sh # 전체 설치
# ./install.sh agents # agents 그룹만 설치
# ./install.sh agents development # 여러 그룹 설치
# ./install.sh agents/background-planner # 특정 스킬만 설치
# ./install.sh --list # 사용 가능한 스킬 목록
# ./install.sh --uninstall agents # 삭제
# ./install.sh --link-static # static 디렉토리 심링크
#
set -e
# 색상 정의
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# 기본값
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TARGET_DIR="${HOME}/.claude/skills"
STATIC_TARGET="${HOME}/.agents"
STATIC_SOURCE="${SCRIPT_DIR}/static"
PREFIX=""
POSTFIX=""
COPY_MODE=false
DRY_RUN=false
UNINSTALL=false
LIST_MODE=false
QUIET=false
LINK_STATIC=false
UNLINK_STATIC=false
INSTALL_CLI=false
UNINSTALL_CLI=false
CLI_TARGET="${HOME}/.local/bin"
INSTALL_CODEX=false
CODEX_TARGET="${HOME}/.codex"
CODEX_AGENTS_SOURCE="${SCRIPT_DIR}/codex-support/AGENTS.md"
INSTALL_HOOKS=false
UNINSTALL_HOOKS=false
HOOKS_SOURCE="${SCRIPT_DIR}/hooks"
HOOKS_TARGET="${HOME}/.claude/hooks"
HOOKS_REGISTRY="${HOOKS_SOURCE}/hooks.json"
INSTALL_PERSONAS=false
PERSONAS_SOURCE="${SCRIPT_DIR}/personas"
PERSONAS_TARGET="${HOME}/.agents/personas"
# 제외 디렉토리 (스킬 그룹으로 인식하지 않음)
EXCLUDE_DIRS=("static" "cli" "codex-support" "hooks" "personas" "teams" ".git" ".github" ".agents" "node_modules" "__pycache__")
# Core 스킬 (기본 전역 설치, 워크스페이스 공통 필수)
CORE_SKILLS=(
"development/git-commit-pr"
"context/context-manager"
"context/static-index"
"security/security-auditor"
"agents/background-implementer"
"agents/background-planner"
"agents/background-reviewer"
)
# Core 모드 플래그
CORE_MODE=false
# 스킬 그룹 동적 탐색
get_skill_groups() {
local groups=()
for dir in "${SCRIPT_DIR}"/*/; do
local dirname=$(basename "$dir")
local excluded=false
# 제외 목록 확인
for exclude in "${EXCLUDE_DIRS[@]}"; do
if [[ "$dirname" == "$exclude" ]]; then
excluded=true
break
fi
done
# 숨김 디렉토리 제외
if [[ "$dirname" == .* ]]; then
excluded=true
fi
# 스킬이 하나라도 있는 디렉토리만 그룹으로 인식
if [[ "$excluded" == "false" && -d "$dir" ]]; then
for skill_dir in "$dir"/*/; do
if [[ -f "${skill_dir}SKILL.md" ]]; then
groups+=("$dirname")
break
fi
done
fi
done
echo "${groups[@]}"
}
# 사용법 출력
usage() {
local groups=($(get_skill_groups))
cat <<EOF
사용법: $(basename "$0") [옵션] [그룹/스킬...]
스킬을 Claude Code의 skills 디렉토리에 설치합니다.
인자:
그룹/스킬 설치할 그룹 또는 스킬 (기본: all)
예: agents, development, business
예: agents/background-planner, development/git-commit-pr
옵션:
-h, --help 도움말 표시
-l, --list 사용 가능한 스킬 목록 표시
-u, --uninstall 스킬 삭제
-c, --copy 심볼릭 링크 대신 복사
-n, --dry-run 실제 변경 없이 미리보기
-q, --quiet 최소 출력
--prefix PREFIX 스킬 이름 앞에 접두사 추가 (예: my-)
--postfix POSTFIX 스킬 이름 뒤에 접미사 추가 (예: -dev)
-t, --target DIR 대상 디렉토리 지정 (기본: ~/.claude/skills)
--core Core 스킬만 전역 설치 (워크스페이스 공통)
Static 관리:
--link-static static/ -> ~/.agents 심링크 생성
--unlink-static ~/.agents 심링크 제거
CLI 도구:
--cli agt CLI 도구 설치 (~/.local/bin)
--alias=NAME CLI 도구 별칭 추가 (여러 번 사용 가능, 예: --alias=cs)
--uninstall-cli agt CLI 도구 및 별칭 제거
Hooks:
--hooks Claude Code hooks 설치 (~/.claude/hooks)
- hook 스크립트 심링크/복사
- settings.json에 hook 설정 자동 병합
--uninstall-hooks 설치된 hooks 제거
Personas:
--personas 에이전트 페르소나 설치 (~/.agents/personas/)
- 라이브러리 페르소나를 전역 설치
Codex 지원:
--codex Codex CLI 지원 설정
- ~/.codex/AGENTS.md에 스킬 가이드 추가
- ~/.codex/skills -> ~/.claude/skills 심링크 생성
예시:
$(basename "$0") # 전체 설치
$(basename "$0") --core # Core 스킬만 설치 (권장)
$(basename "$0") agents # agents 그룹만 설치
$(basename "$0") agents development # 여러 그룹 설치
$(basename "$0") agents/background-planner # 특정 스킬만 설치
$(basename "$0") --prefix "my-" agents # 접두사 붙여서 설치
$(basename "$0") --uninstall agents # agents 그룹 삭제
$(basename "$0") --list # 스킬 목록 표시
$(basename "$0") --link-static # static 심링크 설정
$(basename "$0") --core --cli # Core 스킬 + CLI 도구 설치 (권장)
$(basename "$0") --hooks # Hooks 설치
$(basename "$0") --core --cli --hooks # Core + CLI + Hooks (풀 설치)
Core 스킬 (워크스페이스 공통):
- development/git-commit-pr Git 커밋/PR 가이드
- context/context-manager 프로젝트 컨텍스트 로드
- context/static-index 글로벌 설정 인덱스
- security/security-auditor 보안 감사
- agents/background-implementer 백그라운드 병렬 구현
- agents/background-planner 백그라운드 병렬 기획
그룹 (자동 탐색):
EOF
for group in "${groups[@]}"; do
local skills=($(get_skills_in_group "$group"))
echo " ${group} (${#skills[@]}개 스킬)"
done
echo ""
echo "제외 디렉토리: ${EXCLUDE_DIRS[*]}"
echo ""
exit 0
}
# 로그 함수
log_info() {
[[ "$QUIET" == "false" ]] && echo -e "${BLUE}[INFO]${NC} $1" || true
}
log_success() {
[[ "$QUIET" == "false" ]] && echo -e "${GREEN}[OK]${NC} $1" || true
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
}
log_dry() {
echo -e "${CYAN}[DRY-RUN]${NC} $1"
}
# 스킬 목록 가져오기
get_skills_in_group() {
local group="$1"
local group_dir="${SCRIPT_DIR}/${group}"
if [[ ! -d "$group_dir" ]]; then
return
fi
for skill_dir in "$group_dir"/*/; do
if [[ -f "${skill_dir}SKILL.md" ]]; then
basename "$skill_dir"
fi
done
}
# 모든 스킬 목록
get_all_skills() {
local groups=($(get_skill_groups))
for group in "${groups[@]}"; do
for skill in $(get_skills_in_group "$group"); do
echo "${group}/${skill}"
done
done
}
# YAML frontmatter에서 description 추출
extract_description() {
local skill_md="$1"
local max_len="${2:-50}"
# Python으로 YAML frontmatter 파싱
python3 - "$skill_md" "$max_len" 2>/dev/null <<'PYEOF'
import sys
import re
skill_md = sys.argv[1]
max_len = int(sys.argv[2])
try:
with open(skill_md, 'r', encoding='utf-8') as f:
content = f.read()
# YAML frontmatter 추출 (--- 사이)
match = re.match(r'^---\s*\n(.*?)\n---', content, re.DOTALL)
if not match:
print("")
sys.exit(0)
frontmatter = match.group(1)
# description 필드 찾기
desc_match = re.search(r'^description:\s*(.+?)(?:\n(?!\s)|\Z)', frontmatter, re.MULTILINE | re.DOTALL)
if desc_match:
desc = desc_match.group(1).strip()
# 멀티라인인 경우 첫 줄만
desc = desc.split('\n')[0].strip()
# 길이 제한
if len(desc) > max_len:
desc = desc[:max_len-3] + "..."
print(desc)
else:
print("")
except Exception:
print("")
PYEOF
}
# 스킬 목록 출력
list_skills() {
local groups=($(get_skill_groups))
local total_skills=0
local installed_skills=0
echo ""
echo -e "${CYAN}사용 가능한 스킬${NC} (${GREEN}✓${NC} 설치됨 / ${RED}○${NC} 미설치)"
echo "========================================"
echo ""
for group in "${groups[@]}"; do
local group_dir="${SCRIPT_DIR}/${group}"
if [[ -d "$group_dir" ]]; then
# 그룹 내 설치 현황 계산
local group_total=0
local group_installed=0
for skill_dir in "$group_dir"/*/; do
if [[ -f "${skill_dir}SKILL.md" ]]; then
local skill_name=$(basename "$skill_dir")
local target_name="${PREFIX}${skill_name}${POSTFIX}"
group_total=$((group_total + 1))
if [[ -e "${TARGET_DIR}/${target_name}" ]]; then
group_installed=$((group_installed + 1))
fi
fi
done
echo -e "${YELLOW}${group}/${NC} (${group_installed}/${group_total})"
for skill_dir in "$group_dir"/*/; do
if [[ -f "${skill_dir}SKILL.md" ]]; then
local skill_name=$(basename "$skill_dir")
local target_name="${PREFIX}${skill_name}${POSTFIX}"
local description=$(extract_description "${skill_dir}SKILL.md" 40)
if [[ -z "$description" ]]; then
description="(설명 없음)"
fi
# 설치 여부 확인
local status_icon
local name_color
if [[ -e "${TARGET_DIR}/${target_name}" ]]; then
status_icon="${GREEN}✓${NC}"
name_color="$GREEN"
installed_skills=$((installed_skills + 1))
else
status_icon="${RED}○${NC}"
name_color=""
fi
total_skills=$((total_skills + 1))
# 스킬 이름 패딩 (24자)
local padded_name
padded_name=$(printf "%-24s" "$skill_name")
echo -e " ${status_icon} ${name_color}${padded_name}${NC} ${description}"
fi
done
echo ""
fi
done
# 요약
echo -e "${CYAN}요약${NC}"
echo "========================================"
echo -e " 전체: ${total_skills}개 스킬"
echo -e " 설치됨: ${GREEN}${installed_skills}개${NC}"
echo -e " 미설치: ${RED}$((total_skills - installed_skills))개${NC}"
echo ""
# Static 상태 표시
echo -e "${CYAN}Static 디렉토리${NC}"
echo "========================================"
if [[ -L "$STATIC_TARGET" ]]; then
local link_target=$(readlink "$STATIC_TARGET")
echo -e " ${GREEN}✓${NC} 심링크 활성: ~/.agents -> $link_target"
elif [[ -d "$STATIC_TARGET" ]]; then
echo -e " ${YELLOW}!${NC} 일반 디렉토리: ~/.agents (심링크 아님)"
else
echo -e " ${RED}○${NC} 없음: ~/.agents가 존재하지 않음"
fi
echo ""
echo "설치 예시:"
echo " ./install.sh all # 전체 설치"
echo " ./install.sh agents # agents 그룹만"
echo " ./install.sh agents/background-planner # 특정 스킬만"
echo " ./install.sh --link-static # static 심링크 설정"
echo ""
}
# Static 심링크 생성
link_static() {
if [[ ! -d "$STATIC_SOURCE" ]]; then
log_error "static 디렉토리가 없습니다: $STATIC_SOURCE"
log_info "먼저 static 디렉토리를 생성하세요: mkdir -p $STATIC_SOURCE"
exit 1
fi
if [[ "$DRY_RUN" == "true" ]]; then
if [[ -e "$STATIC_TARGET" ]]; then
log_dry "기존 ~/.agents 제거"
fi
log_dry "심링크 생성: ~/.agents -> $STATIC_SOURCE"
return
fi
# 기존 경로 처리
if [[ -L "$STATIC_TARGET" ]]; then
log_warn "기존 심링크 제거: $STATIC_TARGET"
rm "$STATIC_TARGET"
elif [[ -d "$STATIC_TARGET" ]]; then
log_warn "기존 디렉토리를 백업합니다: ${STATIC_TARGET}.backup"
mv "$STATIC_TARGET" "${STATIC_TARGET}.backup"
fi
# 심링크 생성
ln -s "$STATIC_SOURCE" "$STATIC_TARGET"
log_success "심링크 생성됨: ~/.agents -> $STATIC_SOURCE"
}
# CLI 도구 설치 (agt + legacy tools)
install_cli() {
local cli_tools=("claude-skill" "agent-skill" "agent-persona" "agt")
# 대상 디렉토리 생성
if [[ "$DRY_RUN" == "true" ]]; then
log_dry "디렉토리 생성: $CLI_TARGET"
for tool in "${cli_tools[@]}"; do
log_dry "심링크 생성: ${CLI_TARGET}/${tool} -> ${SCRIPT_DIR}/cli/${tool}"
done
for alias_name in "${CLI_ALIASES[@]}"; do
log_dry "별칭 심링크: ${CLI_TARGET}/${alias_name} -> ${SCRIPT_DIR}/cli/claude-skill"
done
return
fi
mkdir -p "$CLI_TARGET"
# 각 CLI 도구 설치
for tool in "${cli_tools[@]}"; do
local cli_source="${SCRIPT_DIR}/cli/${tool}"
local cli_target="${CLI_TARGET}/${tool}"
if [[ ! -f "$cli_source" ]]; then
log_warn "CLI 스크립트를 찾을 수 없습니다: $cli_source"
continue
fi
# 기존 파일 처리
if [[ -e "$cli_target" ]]; then
log_warn "기존 파일 제거: $cli_target"
rm -f "$cli_target"
fi
# 심링크 생성
ln -s "$cli_source" "$cli_target"
log_success "CLI 도구 설치됨: $cli_target"
done
# 별칭 심링크 생성 (claude-skill용)
local claude_skill_source="${SCRIPT_DIR}/cli/claude-skill"
for alias_name in "${CLI_ALIASES[@]}"; do
local alias_target="${CLI_TARGET}/${alias_name}"
if [[ -e "$alias_target" ]]; then
log_warn "기존 별칭 제거: $alias_target"
rm -f "$alias_target"
fi
ln -s "$claude_skill_source" "$alias_target"
log_success "별칭 설치됨: $alias_target"
done
# 사용법 출력
log_info "사용법:"
log_info " agt skill list (스킬 목록)"
log_info " agt persona list (페르소나 목록)"
log_info " agt run \"prompt\" (스킬 실행)"
# PATH 확인
if [[ ":$PATH:" != *":$CLI_TARGET:"* ]]; then
log_warn "$CLI_TARGET 가 PATH에 없습니다."
log_info "다음을 ~/.bashrc 또는 ~/.zshrc에 추가하세요:"
echo " export PATH=\"\$PATH:$CLI_TARGET\""
fi
}
# CLI 도구 제거
uninstall_cli() {
local cli_tools=("claude-skill" "agent-skill" "agent-persona" "agt")
if [[ "$DRY_RUN" == "true" ]]; then
for tool in "${cli_tools[@]}"; do
local cli_target="${CLI_TARGET}/${tool}"
if [[ -e "$cli_target" ]]; then
log_dry "CLI 도구 제거: $cli_target"
fi
done
return
fi
local removed=false
# CLI 도구들 제거
for tool in "${cli_tools[@]}"; do
local cli_target="${CLI_TARGET}/${tool}"
local cli_source="${SCRIPT_DIR}/cli/${tool}"
if [[ -e "$cli_target" ]]; then
rm -f "$cli_target"
log_success "CLI 도구 제거됨: $cli_target"
removed=true
fi
# 별칭 심링크 찾아서 제거
if [[ -d "$CLI_TARGET" ]]; then
for link in "$CLI_TARGET"/*; do
if [[ -L "$link" && "$(readlink -f "$link")" == "$cli_source" ]]; then
rm -f "$link"
log_success "별칭 제거됨: $link"
removed=true
fi
done
fi
done
if [[ "$removed" == "false" ]]; then
log_warn "CLI 도구가 설치되지 않았습니다"
fi
}
# Static 심링크 제거
unlink_static() {
if [[ "$DRY_RUN" == "true" ]]; then
if [[ -L "$STATIC_TARGET" ]]; then
log_dry "심링크 제거: $STATIC_TARGET"
else
log_dry "심링크가 아님: $STATIC_TARGET"
fi
return
fi
if [[ -L "$STATIC_TARGET" ]]; then
rm "$STATIC_TARGET"
log_success "심링크 제거됨: ~/.agents"
# 백업이 있으면 복원 제안
if [[ -d "${STATIC_TARGET}.backup" ]]; then
log_info "백업 디렉토리 발견: ${STATIC_TARGET}.backup"
log_info "복원하려면: mv ${STATIC_TARGET}.backup $STATIC_TARGET"
fi
elif [[ -d "$STATIC_TARGET" ]]; then
log_warn "심링크가 아닌 일반 디렉토리입니다: $STATIC_TARGET"
log_info "수동으로 제거하세요: rm -rf $STATIC_TARGET"
else
log_warn "~/.agents가 존재하지 않습니다"
fi
}
# Codex 지원 설치
install_codex() {
local codex_agents_target="${CODEX_TARGET}/AGENTS.md"
local codex_skills_target="${CODEX_TARGET}/skills"
local claude_skills_source="${HOME}/.claude/skills"
# codex-support/AGENTS.md 확인
if [[ ! -f "$CODEX_AGENTS_SOURCE" ]]; then
log_error "Codex AGENTS.md를 찾을 수 없습니다: $CODEX_AGENTS_SOURCE"
exit 1
fi
# DRY RUN 모드
if [[ "$DRY_RUN" == "true" ]]; then
log_dry "디렉토리 생성: $CODEX_TARGET"
if [[ -f "$codex_agents_target" ]]; then
log_dry "AGENTS.md에 내용 추가: $codex_agents_target"
else
log_dry "AGENTS.md 생성: $codex_agents_target"
fi
log_dry "심링크 생성: $codex_skills_target -> $claude_skills_source"
return
fi
# ~/.codex 디렉토리 생성
mkdir -p "$CODEX_TARGET"
# AGENTS.md에 내용 추가 (기존 내용 유지, 스킬 가이드만 추가)
if [[ -f "$codex_agents_target" ]]; then
# 이미 스킬 가이드가 있는지 확인
if grep -q "## Claude Skills (SKILL.md) 활용" "$codex_agents_target" 2>/dev/null; then
log_warn "=========================================="
log_warn "AGENTS.md에 이미 스킬 가이드가 있습니다!"
log_warn "기존 스킬 설정을 덮어쓰지 않습니다."
log_warn ""
log_warn "덮어쓰려면 다음 단계를 수행하세요:"
log_warn " 1. 기존 스킬 섹션 수동 제거:"
log_warn " vim ~/.codex/AGENTS.md"
log_warn " 2. 다시 설치:"
log_warn " ./install.sh --codex"
log_warn "=========================================="
else
# 기존 내용 뒤에 스킬 가이드 추가
log_info "기존 AGENTS.md에 스킬 가이드를 추가합니다..."
echo "" >>"$codex_agents_target"
echo "" >>"$codex_agents_target"
echo "# ====================================================" >>"$codex_agents_target"
echo "# agt Integration (auto-generated)" >>"$codex_agents_target"
echo "# ====================================================" >>"$codex_agents_target"
echo "" >>"$codex_agents_target"
cat "$CODEX_AGENTS_SOURCE" >>"$codex_agents_target"
log_success "AGENTS.md에 스킬 가이드 추가됨 (기존 내용 유지)"
fi
else
# 새 파일 생성
cat "$CODEX_AGENTS_SOURCE" >"$codex_agents_target"
log_success "AGENTS.md 생성됨: $codex_agents_target"
fi
# skills 심링크 생성
if [[ ! -d "$claude_skills_source" ]]; then
log_warn "Claude skills 디렉토리가 없습니다: $claude_skills_source"
log_info "먼저 스킬을 설치하세요: ./install.sh"
fi
if [[ -L "$codex_skills_target" ]]; then
local current_target=$(readlink "$codex_skills_target")
if [[ "$current_target" == "$claude_skills_source" ]]; then
log_info "skills 심링크가 이미 올바르게 설정됨"
else
log_warn "기존 심링크 교체: $codex_skills_target"
rm "$codex_skills_target"
ln -s "$claude_skills_source" "$codex_skills_target"
log_success "심링크 생성됨: ~/.codex/skills -> ~/.claude/skills"
fi
elif [[ -d "$codex_skills_target" ]]; then
log_warn "기존 디렉토리를 백업합니다: ${codex_skills_target}.backup"
mv "$codex_skills_target" "${codex_skills_target}.backup"
ln -s "$claude_skills_source" "$codex_skills_target"
log_success "심링크 생성됨: ~/.codex/skills -> ~/.claude/skills"
else
ln -s "$claude_skills_source" "$codex_skills_target"
log_success "심링크 생성됨: ~/.codex/skills -> ~/.claude/skills"
fi
echo ""
log_info "Codex CLI에서 스킬을 사용할 수 있습니다"
log_info "AGENTS.md: $codex_agents_target"
log_info "Skills: $codex_skills_target -> $claude_skills_source"
}
# Personas 설치
install_personas() {
if [[ ! -d "$PERSONAS_SOURCE" ]]; then
log_error "personas 디렉토리가 없습니다: $PERSONAS_SOURCE"
exit 1
fi
log_info "Personas 설치 중..."
mkdir -p "$PERSONAS_TARGET"
local installed=0
for persona_file in "$PERSONAS_SOURCE"/*.md; do
[[ -f "$persona_file" ]] || continue
[[ -L "$persona_file" ]] && { log_warn "심링크 스킵: $persona_file"; continue; }
local filename=$(basename "$persona_file")
[[ "$filename" == "README.md" ]] && continue
local target_path="${PERSONAS_TARGET}/${filename}"
if [[ "$DRY_RUN" == "true" ]]; then
log_dry "Link: $filename"
installed=$((installed + 1))
continue
fi
[[ -e "$target_path" ]] && rm -f "$target_path"
if [[ "$COPY_MODE" == "true" ]]; then
cp "$persona_file" "$target_path"
else
ln -s "$persona_file" "$target_path"
fi
log_success "설치됨: $filename"
installed=$((installed + 1))
done
log_info "$installed 개 페르소나 설치됨 ($PERSONAS_TARGET)"
}
# Hooks 설치
install_hooks() {
if [[ ! -f "$HOOKS_REGISTRY" ]]; then
log_error "hooks.json을 찾을 수 없습니다: $HOOKS_REGISTRY"
exit 1
fi
log_info "Hooks 설치 중..."
# hooks.json에서 hook 목록 파싱
local hook_names
hook_names=$(python3 -c "
import json, sys
with open('$HOOKS_REGISTRY') as f:
hooks = json.load(f)
for name in hooks:
print(name)
" 2>/dev/null)
if [[ -z "$hook_names" ]]; then
log_warn "설치할 hook이 없습니다"
return
fi
# command 타입 hook의 스크립트 파일 설치
while IFS= read -r hook_name; do
local hook_type
hook_type=$(python3 -c "
import json
with open('$HOOKS_REGISTRY') as f:
hooks = json.load(f)
print(hooks['$hook_name'].get('type', 'command'))
" 2>/dev/null)
# command 타입만 스크립트 파일 필요; http/prompt/agent는 설정만 등록
if [[ "$hook_type" != "command" ]]; then
log_info "등록: ${hook_name} (${hook_type} 타입)"
continue
fi
local script
script=$(python3 -c "
import json
with open('$HOOKS_REGISTRY') as f:
hooks = json.load(f)
print(hooks['$hook_name'].get('script', ''))
" 2>/dev/null)
if [[ -z "$script" ]]; then
continue
fi
# hooks 디렉토리 생성
if [[ "$DRY_RUN" == "false" ]]; then
mkdir -p "$HOOKS_TARGET"
fi
local source_path="${HOOKS_SOURCE}/${script}"
local target_path="${HOOKS_TARGET}/${script}"
if [[ ! -f "$source_path" ]]; then
log_warn "스크립트를 찾을 수 없습니다: $source_path"
continue
fi
if [[ "$DRY_RUN" == "true" ]]; then
log_dry "심링크: $source_path -> $target_path"
else
[[ -e "$target_path" ]] && rm -f "$target_path"
if [[ "$COPY_MODE" == "true" ]]; then
cp "$source_path" "$target_path"
chmod +x "$target_path"
log_success "복사됨: ${hook_name} (${script})"
else
ln -s "$source_path" "$target_path"
log_success "링크됨: ${hook_name} (${script})"
fi
fi
done <<<"$hook_names"
# settings.json에 hook 설정 병합
local settings_file="${HOME}/.claude/settings.json"
if [[ "$DRY_RUN" == "true" ]]; then
log_dry "settings.json에 hook 설정 병합: $settings_file"
return
fi
# settings.json이 없으면 생성
if [[ ! -f "$settings_file" ]]; then
echo '{}' >"$settings_file"
fi
# Python으로 settings.json에 hooks 설정 병합 (command, http, prompt, agent 지원)
python3 - "$settings_file" "$HOOKS_REGISTRY" "$HOOKS_TARGET" <<'PYEOF'
import json
import sys
import os
settings_path = sys.argv[1]
registry_path = sys.argv[2]
hooks_target = sys.argv[3]
with open(settings_path, 'r') as f:
settings = json.load(f)
with open(registry_path, 'r') as f:
registry = json.load(f)
if 'hooks' not in settings:
settings['hooks'] = {}
for hook_name, hook_config in registry.items():
event = hook_config['event']
hook_type = hook_config.get('type', 'command')
if event not in settings['hooks']:
settings['hooks'][event] = []
# 중복 확인용 식별자 생성
if hook_type == 'command':
script_path = os.path.join(hooks_target, hook_config.get('script', ''))
identifier = f"bash {script_path}"
elif hook_type == 'http':
identifier = hook_config.get('url', '')
else: # prompt or agent
identifier = hook_config.get('prompt', '')[:80]
# 기존에 같은 hook이 있는지 확인
already_exists = False
for entry in settings['hooks'][event]:
for h in entry.get('hooks', []):
if hook_type == 'command' and h.get('command') == identifier:
already_exists = True
break
if hook_type == 'http' and h.get('url') == identifier:
already_exists = True
break
if hook_type in ('prompt', 'agent') and h.get('prompt', '')[:80] == identifier:
already_exists = True
break
if not already_exists:
# hook handler 생성
h = {'type': hook_type}
if hook_type == 'command':
h['command'] = identifier
if hook_config.get('async'):
h['async'] = True
elif hook_type == 'http':
h['url'] = hook_config['url']
if 'headers' in hook_config:
h['headers'] = hook_config['headers']
if 'allowedEnvVars' in hook_config:
h['allowedEnvVars'] = hook_config['allowedEnvVars']
elif hook_type in ('prompt', 'agent'):
h['prompt'] = hook_config['prompt']
if 'statusMessage' in hook_config:
h['statusMessage'] = hook_config['statusMessage']
if 'model' in hook_config:
h['model'] = hook_config['model']
if 'timeout' in hook_config:
h['timeout'] = hook_config['timeout']
hook_entry = {'hooks': [h]}
if 'matcher' in hook_config:
hook_entry['matcher'] = hook_config['matcher']
settings['hooks'][event].append(hook_entry)
with open(settings_path, 'w') as f:
json.dump(settings, f, indent=2, ensure_ascii=False)
print(f"OK: {len(registry)} hook(s) registered")
PYEOF
local result=$?
if [[ $result -eq 0 ]]; then
log_success "settings.json에 hook 설정 병합 완료"
else
log_error "settings.json 병합 실패"
fi
echo ""
log_info "설치된 hooks:"
while IFS= read -r hook_name; do
local desc
desc=$(python3 -c "
import json
with open('$HOOKS_REGISTRY') as f:
hooks = json.load(f)
print(hooks['$hook_name'].get('description', ''))
" 2>/dev/null)
log_info " - ${hook_name}: ${desc}"
done <<<"$hook_names"
}
# Hooks 제거
uninstall_hooks() {
log_info "Hooks 제거 중..."
if [[ ! -f "$HOOKS_REGISTRY" ]]; then
log_warn "hooks.json을 찾을 수 없습니다"
return
fi
local hook_names
hook_names=$(python3 -c "
import json
with open('$HOOKS_REGISTRY') as f:
hooks = json.load(f)
for name in hooks:
print(name)
" 2>/dev/null)
# command 타입 hook의 스크립트 파일 제거
while IFS= read -r hook_name; do
local script
script=$(python3 -c "
import json
with open('$HOOKS_REGISTRY') as f:
hooks = json.load(f)
print(hooks['$hook_name'].get('script', ''))
" 2>/dev/null)
if [[ -n "$script" ]]; then
local target_path="${HOOKS_TARGET}/${script}"
if [[ -e "$target_path" ]]; then
rm -f "$target_path"
log_success "스크립트 제거됨: ${script}"
fi
fi
done <<<"$hook_names"
# settings.json에서 hook 설정 제거
local settings_file="${HOME}/.claude/settings.json"
if [[ -f "$settings_file" ]]; then
python3 - "$settings_file" "$HOOKS_REGISTRY" "$HOOKS_TARGET" <<'PYEOF'
import json
import sys
import os
settings_path = sys.argv[1]
registry_path = sys.argv[2]
hooks_target = sys.argv[3]
with open(settings_path, 'r') as f:
settings = json.load(f)
with open(registry_path, 'r') as f:
registry = json.load(f)
if 'hooks' not in settings:
sys.exit(0)
for hook_name, hook_config in registry.items():
event = hook_config['event']
hook_type = hook_config.get('type', 'command')
if event not in settings['hooks']:
continue
def should_remove(entry):
for h in entry.get('hooks', []):
if hook_type == 'command':
script_path = os.path.join(hooks_target, hook_config.get('script', ''))
if h.get('command') == f"bash {script_path}":
return True
elif hook_type == 'http':
if h.get('url') == hook_config.get('url', ''):
return True
elif hook_type in ('prompt', 'agent'):
if h.get('prompt', '')[:80] == hook_config.get('prompt', '')[:80]:
return True
return False
settings['hooks'][event] = [
entry for entry in settings['hooks'][event]
if not should_remove(entry)
]
if not settings['hooks'][event]:
del settings['hooks'][event]
if not settings.get('hooks'):
del settings['hooks']
with open(settings_path, 'w') as f:
json.dump(settings, f, indent=2, ensure_ascii=False)
PYEOF
log_success "settings.json에서 hook 설정 제거됨"
fi
}
# 스킬 설치
install_skill() {
local group="$1"
local skill="$2"
local source_path="${SCRIPT_DIR}/${group}/${skill}"
local target_name="${PREFIX}${skill}${POSTFIX}"
local target_path="${TARGET_DIR}/${target_name}"
# 소스 확인
if [[ ! -d "$source_path" ]]; then
log_error "스킬을 찾을 수 없습니다: ${group}/${skill}"
return 1
fi
if [[ ! -f "${source_path}/SKILL.md" ]]; then
log_error "SKILL.md가 없습니다: ${group}/${skill}"
return 1
fi
# 이미 존재하는 경우
if [[ -e "$target_path" ]]; then
if [[ "$DRY_RUN" == "true" ]]; then
log_dry "기존 스킬 덮어쓰기: $target_name"
else
log_warn "기존 스킬 덮어쓰기: $target_name"
rm -rf "$target_path"
fi
fi
# 설치
if [[ "$DRY_RUN" == "true" ]]; then
if [[ "$COPY_MODE" == "true" ]]; then
log_dry "복사: ${group}/${skill} -> ${target_name}"
else
log_dry "심볼릭 링크: ${group}/${skill} -> ${target_name}"
fi