-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·3472 lines (3043 loc) · 134 KB
/
install.sh
File metadata and controls
executable file
·3472 lines (3043 loc) · 134 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
#!/bin/bash
# Agent-Agnostic Coding Tools - Universal Installation Script
# Supports: Claude Code (with MCP) and GitHub CoPilot (with fallbacks)
# Platforms: macOS, Linux, Windows (via WSL/Git Bash)
# Version: 2.0.0
# Check if script is being sourced or executed
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
# Script is being executed directly
SCRIPT_EXECUTED=true
set -euo pipefail
else
# Script is being sourced
SCRIPT_EXECUTED=false
fi
# Colors for 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'
NC='\033[0m' # No Color
# Installation configuration
# Save original CODING_REPO before overwriting (for sandbox detection)
ORIGINAL_CODING_REPO="${CODING_REPO:-}"
CODING_REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
INSTALL_LOG="$CODING_REPO/install.log"
# Repository URLs - will be set based on CN/VPN detection
MEMORY_VISUALIZER_REPO_SSH=""
MEMORY_VISUALIZER_REPO_HTTPS=""
MEMORY_VISUALIZER_DIR="$CODING_REPO/integrations/memory-visualizer"
SEMANTIC_ANALYSIS_DIR="$CODING_REPO/integrations/mcp-server-semantic-analysis"
# Installation status tracking
INSIDE_CN=false
PROXY_WORKING=false
INSTALLATION_WARNINGS=()
INSTALLATION_FAILURES=()
SANDBOX_MODE=false
SKIP_ALL_SYSTEM_CHANGES=false
SKIPPED_SYSTEM_DEPS=()
# Safety: Confirm before any system-level modification
# Usage: confirm_system_change "action description" "risk warning"
# Returns: 0 if approved, 1 if declined
confirm_system_change() {
local action="$1"
local risk="$2"
# Skip if user already chose to skip all
if [[ "$SKIP_ALL_SYSTEM_CHANGES" == "true" ]]; then
return 1
fi
echo ""
echo -e "${YELLOW}╔══════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${YELLOW}║ SYSTEM MODIFICATION REQUEST ║${NC}"
echo -e "${YELLOW}╚══════════════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${CYAN}Action:${NC} $action"
echo ""
echo -e "${RED}Risk:${NC} $risk"
echo ""
echo -e "${BLUE}Options:${NC}"
echo -e " ${GREEN}y${NC} = Proceed with this action"
echo -e " ${YELLOW}n${NC} = Skip this action (installation continues)"
echo -e " ${PURPLE}skip-all${NC} = Skip ALL remaining system modifications"
echo ""
read -p "$(echo -e ${CYAN}Your choice [y/N/skip-all]: ${NC})" response
case "$response" in
[yY]|[yY][eE][sS])
return 0
;;
skip-all|SKIP-ALL|Skip-all)
SKIP_ALL_SYSTEM_CHANGES=true
info "Skipping all remaining system modifications"
return 1
;;
*)
return 1
;;
esac
}
# Repository URLs by network location
# Only memory-visualizer has a CN mirror, others always use public repos
# Memory Visualizer (HAS CN MIRROR)
MEMORY_VISUALIZER_CN_SSH="git@cc-github.bmwgroup.net:frankwoernle/memory-visualizer.git"
MEMORY_VISUALIZER_CN_HTTPS="https://cc-github.bmwgroup.net/frankwoernle/memory-visualizer.git"
MEMORY_VISUALIZER_PUBLIC_SSH="git@github.com:fwornle/memory-visualizer.git"
MEMORY_VISUALIZER_PUBLIC_HTTPS="https://github.com/fwornle/memory-visualizer.git"
# Semantic Analysis MCP Server (HAS CN MIRROR)
SEMANTIC_ANALYSIS_CN_SSH="git@cc-github.bmwgroup.net:frankwoernle/mcp-server-semantic-analysis.git"
SEMANTIC_ANALYSIS_CN_HTTPS="https://cc-github.bmwgroup.net/frankwoernle/mcp-server-semantic-analysis.git"
SEMANTIC_ANALYSIS_PUBLIC_SSH="git@github.com:fwornle/mcp-server-semantic-analysis.git"
SEMANTIC_ANALYSIS_PUBLIC_HTTPS="https://github.com/fwornle/mcp-server-semantic-analysis.git"
# Code Graph RAG (forked with semantic enhancements)
CODE_GRAPH_RAG_SSH="git@github.com:fwornle/code-graph-rag.git"
CODE_GRAPH_RAG_HTTPS="https://github.com/fwornle/code-graph-rag.git"
CODE_GRAPH_RAG_BRANCH="semantic-enhancements"
CODE_GRAPH_RAG_DIR="$CODING_REPO/integrations/code-graph-rag"
# Platform detection
PLATFORM=""
SHELL_RC=""
detect_platform() {
case "$(uname -s)" in
Darwin*)
PLATFORM="macos"
;;
Linux*)
PLATFORM="linux"
;;
MINGW*|CYGWIN*|MSYS*)
PLATFORM="windows"
;;
*)
echo -e "${RED}Unsupported platform: $(uname -s)${NC}"
exit 1
;;
esac
# Detect actual shell in use (prefer accuracy over platform defaults)
if [[ -n "$SHELL" ]]; then
case "$SHELL" in
*/zsh)
SHELL_RC="$HOME/.zshrc"
;;
*/bash)
# Check which bash config exists and is used
if [[ -f "$HOME/.bash_profile" ]]; then
SHELL_RC="$HOME/.bash_profile"
elif [[ -f "$HOME/.bashrc" ]]; then
SHELL_RC="$HOME/.bashrc"
else
SHELL_RC="$HOME/.bash_profile" # Create if needed
fi
;;
*)
# Fallback to platform default
if [[ "$PLATFORM" == "macos" ]]; then
SHELL_RC="$HOME/.zshrc"
else
SHELL_RC="$HOME/.bashrc"
fi
;;
esac
else
# No $SHELL set, use platform default
if [[ "$PLATFORM" == "macos" ]]; then
SHELL_RC="$HOME/.zshrc"
else
SHELL_RC="$HOME/.bashrc"
fi
fi
}
# Detect if we should run in sandbox mode
detect_sandbox_mode() {
# Check if ORIGINAL_CODING_REPO is already set and points to a valid coding installation
if [[ -n "$ORIGINAL_CODING_REPO" ]] && [[ -d "$ORIGINAL_CODING_REPO" ]] && [[ -f "$ORIGINAL_CODING_REPO/bin/coding" ]]; then
local current_install="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# If ORIGINAL_CODING_REPO points to a different installation, use sandbox mode
if [[ "$ORIGINAL_CODING_REPO" != "$current_install" ]]; then
SANDBOX_MODE=true
echo ""
echo -e "${YELLOW}╔══════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${YELLOW}║ ║${NC}"
echo -e "${YELLOW}║ ${RED}SANDBOX MODE DETECTED${YELLOW} ║${NC}"
echo -e "${YELLOW}║ ║${NC}"
echo -e "${YELLOW}╚══════════════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${CYAN}A coding installation is already configured at:${NC}"
echo -e " ${GREEN}$ORIGINAL_CODING_REPO${NC}"
echo ""
echo -e "${CYAN}You are attempting to install to:${NC}"
echo -e " ${BLUE}$current_install${NC}"
echo ""
echo -e "${YELLOW}Installing in SANDBOX MODE to prevent conflicts.${NC}"
echo ""
echo -e "${CYAN}Sandbox mode will:${NC}"
echo -e " ${GREEN}✓${NC} NOT modify global shell configs (.zshrc, .bash_profile)"
echo -e " ${GREEN}✓${NC} Create local .activate file for manual sourcing"
echo -e " ${GREEN}✓${NC} Allow testing install.sh without pollution"
echo ""
echo -e "${CYAN}To use this installation after install completes:${NC}"
echo -e " ${BLUE}source $current_install/.activate${NC}"
echo ""
read -p "$(echo -e ${YELLOW}Continue with sandbox installation? [y/N]: ${NC})" response
case "$response" in
[yY][eE][sS]|[yY])
info "Proceeding with sandbox installation..."
echo ""
;;
*)
info "Installation cancelled by user"
exit 0
;;
esac
fi
fi
}
# Logging functions
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$INSTALL_LOG"
}
error_exit() {
echo -e "${RED}ERROR: $1${NC}" >&2
log "ERROR: $1"
exit 1
}
success() {
echo -e "${GREEN}✅ $1${NC}"
log "SUCCESS: $1"
}
info() {
echo -e "${BLUE}ℹ️ $1${NC}"
log "INFO: $1"
}
warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
log "WARNING: $1"
}
# Detect network location and set repository URLs
detect_network_and_set_repos() {
info "Detecting network location (CN vs Public)..."
local inside_cn=false
local cn_ssh_ok=false
local public_ssh_ok=false
# Test BMW GitHub accessibility to determine if inside CN
info "Testing cc-github.bmwgroup.net accessibility..."
local bmw_response=$(timeout 5s ssh -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no -T git@cc-github.bmwgroup.net 2>&1 || true)
if echo "$bmw_response" | grep -q -iE "(successfully authenticated|Welcome to GitLab|You've successfully authenticated)"; then
success "Inside Corporate Network - SSH access to cc-github.bmwgroup.net works"
inside_cn=true
cn_ssh_ok=true
else
# Try HTTPS to CN to double-check
if timeout 5s curl -s --connect-timeout 5 https://cc-github.bmwgroup.net >/dev/null 2>&1; then
info "Inside Corporate Network - cc-github.bmwgroup.net accessible via HTTPS"
inside_cn=true
else
info "Outside Corporate Network - cc-github.bmwgroup.net not accessible"
inside_cn=false
fi
fi
if [[ "$inside_cn" == true ]]; then
info "🏢 Corporate Network detected - using selective CN mirrors"
INSIDE_CN=true
# Memory Visualizer: Use CN mirror (has modifications)
MEMORY_VISUALIZER_REPO_SSH="$MEMORY_VISUALIZER_CN_SSH"
MEMORY_VISUALIZER_REPO_HTTPS="$MEMORY_VISUALIZER_CN_HTTPS"
# Semantic Analysis: Use CN mirror (has corporate modifications)
SEMANTIC_ANALYSIS_REPO_SSH="$SEMANTIC_ANALYSIS_CN_SSH"
SEMANTIC_ANALYSIS_REPO_HTTPS="$SEMANTIC_ANALYSIS_CN_HTTPS"
else
info "🌍 Public network detected - using public repositories"
# Test public GitHub SSH
info "Testing github.com SSH access..."
local github_response=$(timeout 5s ssh -o BatchMode=yes -o ConnectTimeout=5 -o StrictHostKeyChecking=no -T git@github.com 2>&1 || true)
if echo "$github_response" | grep -q -i "successfully authenticated"; then
success "SSH access to github.com works"
public_ssh_ok=true
fi
# All repositories: Use public repos
MEMORY_VISUALIZER_REPO_SSH="$MEMORY_VISUALIZER_PUBLIC_SSH"
MEMORY_VISUALIZER_REPO_HTTPS="$MEMORY_VISUALIZER_PUBLIC_HTTPS"
SEMANTIC_ANALYSIS_REPO_SSH="$SEMANTIC_ANALYSIS_PUBLIC_SSH"
SEMANTIC_ANALYSIS_REPO_HTTPS="$SEMANTIC_ANALYSIS_PUBLIC_HTTPS"
fi
# Log selected repositories
info "Selected repositories:"
info " Memory Visualizer: $(echo "$MEMORY_VISUALIZER_REPO_SSH" | sed 's/git@//' | sed 's/.git$//')"
info " Semantic Analysis: $(echo "$SEMANTIC_ANALYSIS_REPO_SSH" | sed 's/git@//' | sed 's/.git$//')"
return 0
}
# Test proxy connectivity for external repos
test_proxy_connectivity() {
if [[ "$INSIDE_CN" == false ]]; then
PROXY_WORKING=true # Outside CN, assume direct access works
return 0
fi
info "Testing proxy connectivity for external repositories..."
if timeout 5s curl -s --connect-timeout 5 https://google.de >/dev/null 2>&1; then
success "Proxy is working - external repositories accessible"
PROXY_WORKING=true
else
warning "Proxy not working or external access blocked"
PROXY_WORKING=false
fi
}
# Check for required dependencies
check_dependencies() {
echo -e "${CYAN}🔍 Checking dependencies...${NC}"
local missing_deps=()
# Core dependencies
if ! command -v git >/dev/null 2>&1; then
missing_deps+=("git")
fi
if ! command -v node >/dev/null 2>&1; then
missing_deps+=("node")
else
# Node.js exists - verify it actually works (catches library issues like simdjson mismatch)
local node_health_output
if ! node_health_output=$(node -e "console.log('ok')" 2>&1); then
echo ""
echo -e "${RED}╔══════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${RED}║ ║${NC}"
echo -e "${RED}║ ⚠️ NODE.JS IS BROKEN ⚠️ ║${NC}"
echo -e "${RED}║ ║${NC}"
echo -e "${RED}╚══════════════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${YELLOW}Node.js is installed but fails to execute. This is commonly caused by${NC}"
echo -e "${YELLOW}Homebrew library version mismatches (e.g., libsimdjson, libuv).${NC}"
echo ""
echo -e "${CYAN}Error:${NC}"
echo "$node_health_output" | head -5
echo ""
echo -e "${CYAN}Common causes and fixes:${NC}"
echo -e " ${GREEN}1.${NC} Library mismatch after Homebrew update - try: brew upgrade"
echo -e " ${GREEN}2.${NC} Use nvm for isolated Node management: nvm install --lts && nvm use --lts"
echo -e " ${GREEN}3.${NC} Check if libsimdjson needs linking: brew link simdjson"
echo ""
echo -e "${RED}IMPORTANT:${NC} This installer will NOT attempt to fix your Node installation."
echo -e " Please resolve this issue manually before proceeding."
echo ""
error_exit "Node.js is broken. Please fix it before running this installer."
fi
fi
if ! command -v npm >/dev/null 2>&1; then
missing_deps+=("npm")
fi
if ! command -v python3 >/dev/null 2>&1; then
missing_deps+=("python3")
fi
if ! command -v jq >/dev/null 2>&1; then
missing_deps+=("jq")
fi
if ! command -v plantuml >/dev/null 2>&1; then
missing_deps+=("plantuml")
fi
if ! command -v tmux >/dev/null 2>&1; then
missing_deps+=("tmux")
fi
# Install uv if missing (required for code-graph-rag Python venv)
if ! command -v uv >/dev/null 2>&1; then
if confirm_system_change \
"Install uv (Python package installer) via curl | sh" \
"This downloads and executes an installer script from astral.sh. Required for code-graph-rag."; then
info "Installing uv (Python package installer, required for code-graph-rag)..."
if curl -LsSf https://astral.sh/uv/install.sh | sh; then
# Source shell config to update PATH
export PATH="$HOME/.local/bin:$PATH"
if command -v uv >/dev/null 2>&1; then
success "uv installed successfully"
else
warning "uv installed but not in PATH. You may need to restart your shell."
info "Add to PATH: export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
else
warning "Failed to install uv. code-graph-rag may not be available."
SKIPPED_SYSTEM_DEPS+=("uv")
fi
else
warning "Skipped uv installation. code-graph-rag may not be available."
SKIPPED_SYSTEM_DEPS+=("uv")
info "To install manually: curl -LsSf https://astral.sh/uv/install.sh | sh"
fi
else
success "uv is already installed"
fi
# Platform-specific checks
if [[ "$PLATFORM" == "macos" ]]; then
if ! command -v brew >/dev/null 2>&1; then
warning "Homebrew not found. Some installations may require manual setup."
else
# Check for GNU coreutils (provides timeout command needed by test scripts)
if ! command -v timeout >/dev/null 2>&1; then
if confirm_system_change \
"Install GNU coreutils via Homebrew (brew install coreutils)" \
"Provides the 'timeout' command needed for test scripts. Safe to install."; then
info "Installing GNU coreutils (for timeout command)..."
if brew install coreutils; then
# Add gnubin to PATH for this session
export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"
success "GNU coreutils installed successfully"
info "Adding gnubin to PATH in shell config..."
# Add to shell config if not already there
if ! grep -q "coreutils/libexec/gnubin" "$SHELL_RC" 2>/dev/null; then
echo '' >> "$SHELL_RC"
echo '# GNU coreutils (provides timeout, etc.)' >> "$SHELL_RC"
echo 'export PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH"' >> "$SHELL_RC"
fi
else
warning "Failed to install GNU coreutils. Some test scripts may not work."
SKIPPED_SYSTEM_DEPS+=("coreutils")
fi
else
warning "Skipped coreutils installation. timeout command may not be available."
SKIPPED_SYSTEM_DEPS+=("coreutils")
info "To install manually: brew install coreutils"
fi
else
success "GNU coreutils (timeout) is already available"
fi
fi
fi
# Clone repository with SSH first, fallback to HTTPS
clone_repository() {
local ssh_url="$1"
local https_url="$2"
local target_dir="$3"
local repo_name=$(basename "$target_dir")
# Determine if this is a BMW repository
local is_bmw_repo=false
if [[ "$ssh_url" == *"bmwgroup.net"* ]]; then
is_bmw_repo=true
fi
info "Attempting to clone $repo_name..."
# Try SSH first
if git clone "$ssh_url" "$target_dir" 2>/dev/null; then
success "Successfully cloned $repo_name using SSH"
return 0
else
if [[ "$is_bmw_repo" == true ]]; then
warning "SSH clone failed (may be outside VPN), trying HTTPS..."
else
warning "SSH clone failed (may be inside VPN), trying HTTPS..."
fi
if git clone "$https_url" "$target_dir" 2>/dev/null; then
success "Successfully cloned $repo_name using HTTPS"
return 0
else
# For external repos, if HTTPS fails inside VPN, provide helpful message
if [[ "$is_bmw_repo" == false ]]; then
error_exit "Failed to clone $repo_name. If you're inside the corporate VPN, external GitHub access may be blocked."
else
error_exit "Failed to clone $repo_name. Please check your network connection and credentials."
fi
return 1
fi
fi
}
# Handle non-mirrored repository inside CN (with proxy detection)
handle_non_mirrored_repo_cn() {
local repo_name="$1"
local ssh_url="$2"
local https_url="$3"
local target_dir="$4"
if [[ -d "$target_dir" ]]; then
info "$repo_name already exists, attempting update..."
cd "$target_dir"
if [[ "$PROXY_WORKING" == true ]]; then
info "Proxy working - attempting update from external repo"
if timeout 5s git pull origin main 2>/dev/null; then
success "$repo_name updated successfully"
return 0
else
warning "Could not update $repo_name (network/proxy issue)"
INSTALLATION_WARNINGS+=("$repo_name: Could not update from external repo")
return 0 # Continue - we have existing code
fi
else
warning "Proxy not working - skipping update of $repo_name"
INSTALLATION_WARNINGS+=("$repo_name: Skipped update due to proxy/network issues")
return 0 # Continue - we have existing code
fi
else
# Repository doesn't exist - try to clone
if [[ "$PROXY_WORKING" == true ]]; then
info "Proxy working - attempting to clone $repo_name"
if clone_repository "$ssh_url" "$https_url" "$target_dir" 2>/dev/null; then
success "$repo_name cloned successfully"
return 0
else
warning "Failed to clone $repo_name despite working proxy"
INSTALLATION_FAILURES+=("$repo_name: Failed to clone external repository")
return 1
fi
else
warning "Cannot clone $repo_name - proxy not working and no existing copy"
INSTALLATION_FAILURES+=("$repo_name: Cannot clone - no proxy access and repository missing")
return 1
fi
fi
}
if [[ ${#missing_deps[@]} -ne 0 ]]; then
echo -e "${RED}Missing required dependencies: ${missing_deps[*]}${NC}"
echo -e "${YELLOW}Please install the missing dependencies and run the installer again.${NC}"
# Provide installation hints
echo -e "\n${CYAN}Installation hints:${NC}"
case "$PLATFORM" in
macos)
echo " - Install Homebrew: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
echo " - Then run: brew install git node python3 jq plantuml tmux"
;;
linux)
echo " - Ubuntu/Debian: sudo apt-get update && sudo apt-get install -y git nodejs npm python3 python3-pip jq plantuml tmux"
echo " - RHEL/CentOS: sudo yum install -y git nodejs npm python3 python3-pip jq plantuml tmux"
echo " - Arch: sudo pacman -S git nodejs npm python python-pip jq plantuml tmux"
;;
windows)
echo " - Install Git Bash: https://git-scm.com/downloads"
echo " - Install Node.js: https://nodejs.org/"
echo " - Install Python: https://www.python.org/downloads/"
echo " - Install jq: https://stedolan.github.io/jq/download/"
;;
esac
exit 1
fi
success "All required dependencies are installed"
}
# Install memory-visualizer (git submodule)
install_memory_visualizer() {
echo -e "\n${CYAN}📊 Installing memory-visualizer (git submodule)...${NC}"
cd "$CODING_REPO"
# Check for both .git directory and .git file (for submodules)
if [[ -d "$MEMORY_VISUALIZER_DIR/.git" ]] || [[ -f "$MEMORY_VISUALIZER_DIR/.git" ]]; then
info "Memory visualizer submodule already exists, updating..."
cd "$MEMORY_VISUALIZER_DIR"
if timeout 10s git pull origin main 2>/dev/null; then
success "Memory visualizer updated"
else
info "Could not update memory-visualizer (may be on specific commit)"
fi
else
info "Initializing memory-visualizer submodule..."
git submodule update --init --recursive integrations/memory-visualizer || error_exit "Failed to initialize memory-visualizer submodule"
fi
cd "$MEMORY_VISUALIZER_DIR"
# Install dependencies
info "Installing memory-visualizer dependencies..."
npm install || error_exit "Failed to install memory-visualizer dependencies"
# Build the visualizer
info "Building memory-visualizer..."
npm run build || error_exit "Failed to build memory-visualizer"
# Update browserslist database to suppress warnings
info "Updating browserslist database..."
npx update-browserslist-db@latest 2>/dev/null || warning "Could not update browserslist database"
# Update vkb script to use local memory-visualizer
if [[ "$PLATFORM" == "macos" ]]; then
sed -i '' "s|VISUALIZER_DIR=.*|VISUALIZER_DIR=\"$MEMORY_VISUALIZER_DIR\"|" "$CODING_REPO/knowledge-management/vkb"
else
sed -i "s|VISUALIZER_DIR=.*|VISUALIZER_DIR=\"$MEMORY_VISUALIZER_DIR\"|" "$CODING_REPO/knowledge-management/vkb"
fi
success "Memory visualizer installed successfully"
}
# Install semantic analysis MCP server (git submodule)
install_semantic_analysis() {
echo -e "\n${CYAN}🧠 Installing semantic analysis MCP server (git submodule)...${NC}"
cd "$CODING_REPO"
# Check for both .git directory and .git file (for submodules)
if [[ -d "$SEMANTIC_ANALYSIS_DIR/.git" ]] || [[ -f "$SEMANTIC_ANALYSIS_DIR/.git" ]]; then
info "mcp-server-semantic-analysis submodule already exists, updating..."
cd "$SEMANTIC_ANALYSIS_DIR"
if timeout 10s git pull origin main 2>/dev/null; then
success "mcp-server-semantic-analysis updated"
else
info "Could not update mcp-server-semantic-analysis (may be on specific commit)"
fi
else
info "Initializing mcp-server-semantic-analysis submodule..."
git submodule update --init --recursive integrations/mcp-server-semantic-analysis || error_exit "Failed to initialize semantic-analysis submodule"
fi
# Only proceed with build if we have the repository
if [[ -d "$SEMANTIC_ANALYSIS_DIR" && -f "$SEMANTIC_ANALYSIS_DIR/package.json" ]]; then
info "Installing semantic analysis dependencies..."
cd "$SEMANTIC_ANALYSIS_DIR"
# Check for Node.js
if ! command -v node &> /dev/null; then
warning "Node.js not found. Please install Node.js 18+ to use semantic analysis."
return 1
fi
# Install dependencies and build
npm install || warning "Failed to install semantic analysis dependencies"
npm run build || warning "Failed to build semantic analysis server"
# Make built server executable
if [[ -f "dist/index.js" ]]; then
chmod +x dist/index.js
fi
success "Semantic analysis MCP server installed successfully"
else
warning "Semantic analysis repository not available - skipping build"
fi
cd "$CODING_REPO"
}
# Install MCP Constraint Monitor with Professional Dashboard (git submodule)
install_constraint_monitor() {
echo -e "\n${CYAN}🚦 Installing MCP Constraint Monitor with Professional Dashboard (git submodule)...${NC}"
cd "$CODING_REPO"
local constraint_monitor_dir="$CODING_REPO/integrations/mcp-constraint-monitor"
# Initialize or update submodule (check for both .git directory and .git file)
if [[ -d "$constraint_monitor_dir/.git" ]] || [[ -f "$constraint_monitor_dir/.git" ]]; then
info "mcp-constraint-monitor submodule already exists, updating..."
cd "$constraint_monitor_dir"
if timeout 10s git pull origin main 2>/dev/null; then
success "mcp-constraint-monitor updated"
else
info "Could not update mcp-constraint-monitor (may be on specific commit)"
fi
else
info "Initializing mcp-constraint-monitor submodule..."
git submodule update --init --recursive integrations/mcp-constraint-monitor || {
warning "Failed to initialize mcp-constraint-monitor submodule"
info "You can manually clone: git clone https://github.com/fwornle/mcp-constraint-monitor.git integrations/mcp-constraint-monitor"
INSTALLATION_WARNINGS+=("mcp-constraint-monitor: Failed to initialize submodule")
return 1
}
fi
# Install constraint monitor dependencies
if [[ -d "$constraint_monitor_dir" && -f "$constraint_monitor_dir/package.json" ]]; then
cd "$constraint_monitor_dir"
# Run the constraint monitor's own install script (skip hooks - we handle those in main install)
if [[ -f "install.sh" ]]; then
info "Running constraint monitor installation (dependencies only)..."
bash install.sh --skip-hooks || warning "Constraint monitor installation had issues"
else
# Fallback to manual installation if install.sh doesn't exist
info "Installing constraint monitor dependencies..."
npm install || warning "Failed to install constraint monitor dependencies"
fi
# Install professional dashboard dependencies
if [[ -d "dashboard" ]]; then
info "Installing professional dashboard dependencies..."
cd dashboard
# Prefer pnpm if available (Next.js works better with pnpm)
if command -v pnpm >/dev/null 2>&1; then
pnpm install || npm install || warning "Failed to install dashboard dependencies"
else
npm install || warning "Failed to install dashboard dependencies"
fi
cd ..
success "Professional Dashboard dependencies installed"
info "Dashboard runs on port 3030"
else
warning "Dashboard directory not found in constraint monitor"
fi
success "MCP Constraint Monitor with Professional Dashboard installed"
info "Global monitoring supports multi-project constraint tracking"
info "Hooks will be configured in the main installation process"
else
warning "Constraint monitor package.json not found"
INSTALLATION_WARNINGS+=("mcp-constraint-monitor: Missing package.json")
fi
cd "$CODING_REPO"
}
# Install System Health Dashboard
install_system_health_dashboard() {
echo -e "\n${CYAN}🏥 Installing System Health Dashboard...${NC}"
if [[ ! -d "$CODING_REPO/integrations/system-health-dashboard" ]]; then
warning "System Health Dashboard directory not found"
return 1
fi
cd "$CODING_REPO/integrations/system-health-dashboard"
if [[ ! -f "package.json" ]]; then
warning "System Health Dashboard package.json not found"
cd "$CODING_REPO"
return 1
fi
info "Installing System Health Dashboard dependencies..."
npm install || warning "Failed to install System Health Dashboard dependencies"
success "System Health Dashboard dependencies installed"
info "Dashboard will run on port 3032 (frontend) and 3033 (API)"
info "Access at: http://localhost:3032"
cd "$CODING_REPO"
}
# Install code-graph-rag MCP server (AST-based code knowledge graph)
install_code_graph_rag() {
echo -e "\n${CYAN}🔗 Installing code-graph-rag MCP server...${NC}"
cd "$CODING_REPO"
# Check for uv package manager
if ! command -v uv >/dev/null 2>&1; then
warning "uv not found - code-graph-rag requires uv package manager"
info "Install with: curl -LsSf https://astral.sh/uv/install.sh | sh"
INSTALLATION_WARNINGS+=("code-graph-rag: uv not installed")
return 1
fi
# Clone or update repository (check for both .git directory and .git file for submodules)
if [[ -d "$CODE_GRAPH_RAG_DIR/.git" ]] || [[ -f "$CODE_GRAPH_RAG_DIR/.git" ]]; then
info "code-graph-rag exists (submodule), updating..."
cd "$CODE_GRAPH_RAG_DIR"
timeout 30s git pull origin "$CODE_GRAPH_RAG_BRANCH" 2>/dev/null || info "Could not update code-graph-rag (may be on specific commit)"
else
info "Cloning code-graph-rag (branch: $CODE_GRAPH_RAG_BRANCH)..."
if git clone -b "$CODE_GRAPH_RAG_BRANCH" "$CODE_GRAPH_RAG_HTTPS" "$CODE_GRAPH_RAG_DIR" 2>/dev/null; then
success "Cloned code-graph-rag"
elif git clone -b "$CODE_GRAPH_RAG_BRANCH" "$CODE_GRAPH_RAG_SSH" "$CODE_GRAPH_RAG_DIR" 2>/dev/null; then
success "Cloned code-graph-rag via SSH"
else
warning "Failed to clone code-graph-rag"
INSTALLATION_WARNINGS+=("code-graph-rag: Failed to clone")
return 1
fi
fi
cd "$CODE_GRAPH_RAG_DIR"
# Install dependencies with uv
info "Installing dependencies with uv..."
if uv sync --extra treesitter-full 2>/dev/null; then
success "code-graph-rag dependencies installed"
else
warning "Failed to install code-graph-rag dependencies"
INSTALLATION_WARNINGS+=("code-graph-rag: uv sync failed")
cd "$CODING_REPO"
return 1
fi
# Create .env if not exists
if [[ ! -f "$CODE_GRAPH_RAG_DIR/.env" ]]; then
# Source main .env to get API keys
if [[ -f "$CODING_REPO/.env" ]]; then
source "$CODING_REPO/.env"
fi
# Use Groq as default (OpenAI quota issues are common)
# Fall back to OpenAI if no Groq key available
if [[ -n "$GROQ_API_KEY" ]]; then
cat > "$CODE_GRAPH_RAG_DIR/.env" << ENVEOF
# code-graph-rag configuration
MEMGRAPH_HOST=localhost
MEMGRAPH_PORT=7687
MEMGRAPH_BATCH_SIZE=1000
# Using Groq via OpenAI-compatible API (faster, no quota issues)
CYPHER_PROVIDER=openai
CYPHER_MODEL=llama-3.3-70b-versatile
CYPHER_ENDPOINT=https://api.groq.com/openai/v1
CYPHER_API_KEY=$GROQ_API_KEY
ENVEOF
info "Created .env with Groq configuration"
else
cat > "$CODE_GRAPH_RAG_DIR/.env" << 'ENVEOF'
# code-graph-rag configuration
MEMGRAPH_HOST=localhost
MEMGRAPH_PORT=7687
MEMGRAPH_BATCH_SIZE=1000
# Using OpenAI (set CYPHER_API_KEY or OPENAI_API_KEY)
CYPHER_PROVIDER=openai
CYPHER_MODEL=gpt-4o-mini
ENVEOF
info "Created .env with OpenAI configuration (set GROQ_API_KEY in main .env for better performance)"
fi
else
# Update existing .env if GROQ_API_KEY is available but not configured
if [[ -f "$CODING_REPO/.env" ]]; then
source "$CODING_REPO/.env"
fi
if [[ -n "$GROQ_API_KEY" ]] && ! grep -q "CYPHER_API_KEY" "$CODE_GRAPH_RAG_DIR/.env"; then
info "Adding Groq API key to existing code-graph-rag .env..."
echo "" >> "$CODE_GRAPH_RAG_DIR/.env"
echo "# Groq API key added by installer" >> "$CODE_GRAPH_RAG_DIR/.env"
echo "CYPHER_ENDPOINT=https://api.groq.com/openai/v1" >> "$CODE_GRAPH_RAG_DIR/.env"
echo "CYPHER_API_KEY=$GROQ_API_KEY" >> "$CODE_GRAPH_RAG_DIR/.env"
fi
fi
# Create docker-compose.yaml for Memgraph if not exists
if [[ ! -f "$CODE_GRAPH_RAG_DIR/docker-compose.yaml" ]]; then
cat > "$CODE_GRAPH_RAG_DIR/docker-compose.yaml" << 'DCEOF'
# Memgraph database for code-graph-rag
version: '3.8'
services:
memgraph:
image: memgraph/memgraph-platform
container_name: code-graph-memgraph
ports:
- "7687:7687" # Bolt protocol
- "7444:7444" # HTTPS
- "3100:3000" # Memgraph Lab (UI)
volumes:
- memgraph_data:/var/lib/memgraph
restart: unless-stopped
environment:
- MEMGRAPH_TELEMETRY_ENABLED=false
volumes:
memgraph_data:
DCEOF
info "Created docker-compose.yaml for Memgraph"
fi
# Download pre-built cache from GitHub Release (if available)
download_cgr_cache() {
local cache_url="https://github.com/fwornle/code-graph-rag/releases/download/v1.0.0-cache-coding/cgr-cache-coding.tar.gz"
local cache_dir="$CODE_GRAPH_RAG_DIR/shared-data"
info "Checking for pre-built code-graph-rag cache..."
# Skip if cache already exists with metadata
if [[ -f "$cache_dir/cache-metadata.json" ]]; then
info "Cache already exists, skipping download"
return 0
fi
# Try to download cache
if curl -fsSL --head "$cache_url" >/dev/null 2>&1; then
info "Downloading pre-built cache (saves ~20 min indexing)..."
local tmp_file="/tmp/cgr-cache-$$.tar.gz"
if curl -fsSL "$cache_url" -o "$tmp_file" 2>/dev/null; then
mkdir -p "$cache_dir"
tar -xzf "$tmp_file" -C "$CODE_GRAPH_RAG_DIR" 2>/dev/null && \
success "Pre-built cache downloaded and extracted" || \
warning "Failed to extract cache - will need to index on first run"
rm -f "$tmp_file"
else
warning "Cache download failed - will need to index on first run"
fi
else
info "No pre-built cache available yet - will need to index on first run"
info " Run: cd integrations/code-graph-rag && uv run graph-code load-index /path/to/repo"
fi
}
download_cgr_cache
# Reindex CGR cache if stale (requires Docker for Memgraph)
reindex_cgr_if_needed() {
local staleness_script="$CODE_GRAPH_RAG_DIR/scripts/check-cache-staleness.sh"
local reindex_script="$CODE_GRAPH_RAG_DIR/scripts/reindex-with-metadata.sh"
# Check if staleness script exists
if [[ ! -x "$staleness_script" ]]; then
info "CGR staleness check script not found, skipping reindex"
return 0
fi
# Check cache staleness
info "Checking CGR cache freshness..."
local staleness_json
staleness_json=$("$staleness_script" "$CODING_REPO" 2>/dev/null) || true
local is_stale=$(echo "$staleness_json" | jq -r '.is_stale // true' 2>/dev/null)
local commits_behind=$(echo "$staleness_json" | jq -r '.commits_behind // "unknown"' 2>/dev/null)
if [[ "$is_stale" != "true" ]]; then
success "CGR cache is fresh"
return 0
fi
info "CGR cache is stale ($commits_behind commits behind)"
# Check if Docker is available
if ! command -v docker &>/dev/null; then
warning "Docker not available - CGR reindex skipped"
info " Run manually: cd integrations/code-graph-rag && docker-compose up -d && ./scripts/reindex-with-metadata.sh"
return 0
fi
# Check if Docker daemon is running
if ! docker info &>/dev/null; then
warning "Docker daemon not running - CGR reindex skipped"
info " Start Docker and run: cd integrations/code-graph-rag && docker-compose up -d && ./scripts/reindex-with-metadata.sh"
return 0
fi
info "Starting Memgraph for CGR reindex..."
cd "$CODE_GRAPH_RAG_DIR"
# Start Memgraph container
if ! docker-compose up -d 2>/dev/null; then
warning "Failed to start Memgraph - CGR reindex skipped"
cd "$CODING_REPO"
return 0
fi
# Wait for Memgraph to be ready (max 30 seconds)
info "Waiting for Memgraph to be ready..."
local max_wait=30
local waited=0
while ! docker-compose exec -T memgraph mgconsole -c "RETURN 1" &>/dev/null; do
sleep 1
((waited++))
if [[ $waited -ge $max_wait ]]; then
warning "Memgraph not ready after ${max_wait}s - CGR reindex skipped"
cd "$CODING_REPO"
return 0
fi
done
success "Memgraph ready"
# Run reindex
info "Reindexing CGR cache (this may take a few minutes)..."
if [[ -x "$reindex_script" ]]; then
if "$reindex_script" "$CODING_REPO" "coding" 2>&1 | tail -5; then
success "CGR cache reindexed successfully"
else
warning "CGR reindex had issues - check logs in integrations/code-graph-rag/shared-data/reindex.log"
fi
else
warning "Reindex script not executable"
fi
cd "$CODING_REPO"
}
reindex_cgr_if_needed
success "code-graph-rag installed"
info " - Memgraph Lab: http://localhost:3100"
info " - MCP server: uv run graph-code mcp-server"
cd "$CODING_REPO"
}
# Create universal command wrappers
create_command_wrappers() {
echo -e "\n${CYAN}🔧 Creating command wrappers...${NC}"