-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathinstall.sh
More file actions
1174 lines (991 loc) · 39.3 KB
/
install.sh
File metadata and controls
1174 lines (991 loc) · 39.3 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
#
# Genie CLI Installer
# https://github.com/automagik-dev/genie
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/automagik-dev/genie/main/install.sh | bash
# curl -fsSL https://raw.githubusercontent.com/automagik-dev/genie/main/install.sh | bash -s -- uninstall
#
# Exit codes:
# 0 - Success
# 1 - General error
# 2 - Invalid arguments
# 3 - Missing prerequisites
# 4 - Download failed
# 5 - Build failed
set -euo pipefail
# ─────────────────────────────────────────────────────────────────────────────
# Constants
# ─────────────────────────────────────────────────────────────────────────────
readonly VERSION="2.0.0"
readonly PACKAGE_NAME="@automagik/genie"
readonly RAW_REPO_URL="https://raw.githubusercontent.com/automagik-dev/genie"
readonly GENIE_HOME="${GENIE_HOME:-$HOME/.genie}"
readonly CLAUDE_PLUGINS_DIR="$HOME/.claude/plugins"
readonly PLUGIN_SYMLINK="$CLAUDE_PLUGINS_DIR/genie"
readonly CODEX_SKILLS_DIR="$HOME/.agents/skills"
# TTY detection for dual-mode (interactive vs agent)
if [[ -t 0 ]]; then
INTERACTIVE=true
else
INTERACTIVE=false
fi
# Colors (disabled if not a terminal)
if [[ -t 1 ]]; then
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[1;33m'
readonly BLUE='\033[0;34m'
readonly BOLD='\033[1m'
readonly DIM='\033[2m'
readonly NC='\033[0m'
else
readonly RED=''
readonly GREEN=''
readonly YELLOW=''
readonly BLUE=''
readonly BOLD=''
readonly DIM=''
readonly NC=''
fi
# Global state
DOWNLOADER=""
PLATFORM=""
ARCH=""
INSTALL_MODE="install"
LOCAL_PATH="" # If set, use local source instead of npm
AUTO_LOCAL_DETECTED=false # True if local mode was auto-detected
DEV_MODE=false # If true, link plugins instead of copying (for development)
PKG_DIR="" # Set by locate_package_dir after install
# ─────────────────────────────────────────────────────────────────────────────
# Utility Functions
# ─────────────────────────────────────────────────────────────────────────────
log() {
echo -e " ${GREEN}▸${NC} $1"
}
warn() {
echo -e " ${YELLOW}⚠${NC} $1" >&2
}
error() {
echo -e " ${RED}✖${NC} $1" >&2
}
success() {
echo -e " ${GREEN}✔${NC} $1"
}
info() {
echo -e " ${BLUE}ℹ${NC} $1"
}
header() {
echo
echo -e "${BOLD}$1${NC}"
}
# Check if a command exists
check_command() {
command -v "$1" &>/dev/null
}
# Prompt user for confirmation (Y is default)
confirm() {
local prompt="$1"
local response=""
echo -en "${YELLOW}?${NC} $prompt [Y/n] "
# Prefer /dev/tty for interactive installs, but fall back to stdin (CI/heredoc).
# Some environments expose /dev/tty but make it unreadable; suppress that noise.
if [[ -e /dev/tty ]]; then
read -r response < /dev/tty 2>/dev/null || true
fi
if [[ -z "${response:-}" ]]; then
read -r response 2>/dev/null || response=""
fi
[[ -z "$response" || "$response" =~ ^[Yy]$ ]]
}
# Prompt user for confirmation (N is default)
confirm_no() {
local prompt="$1"
local response=""
echo -en "${YELLOW}?${NC} $prompt [y/N] "
if [[ -e /dev/tty ]]; then
read -r response < /dev/tty 2>/dev/null || true
fi
if [[ -z "${response:-}" ]]; then
read -r response 2>/dev/null || response=""
fi
[[ "$response" =~ ^[Yy]$ ]]
}
# ─────────────────────────────────────────────────────────────────────────────
# Symlink Detection and Repair
# ─────────────────────────────────────────────────────────────────────────────
# Check if a path is a broken symlink
is_broken_symlink() {
local path="$1"
# -L checks if it's a symlink, ! -e checks if target doesn't exist
[[ -L "$path" && ! -e "$path" ]]
}
# Check if a path is a valid symlink pointing to an existing directory
is_valid_symlink() {
local path="$1"
[[ -L "$path" && -d "$path" ]]
}
# Check and repair broken plugin symlink
check_and_repair_symlink() {
# Check new path
if is_broken_symlink "$PLUGIN_SYMLINK"; then
local target
target=$(readlink "$PLUGIN_SYMLINK" 2>/dev/null || echo "unknown")
warn "Broken symlink detected: $PLUGIN_SYMLINK -> $target"
warn "The symlink target no longer exists — auto-repairing"
rm -f "$PLUGIN_SYMLINK"
success "Broken symlink removed (will be recreated during install)"
return 0
fi
return 0
}
readonly OPENCLAW_CONFIG="$HOME/.openclaw/openclaw.json"
# Remove genie paths from OpenClaw config (for uninstall)
remove_openclaw_plugin_paths() {
if [[ ! -f "$OPENCLAW_CONFIG" ]] || ! check_command jq; then
return 0
fi
local tmp_config
tmp_config=$(mktemp)
# Remove paths containing plugins/genie
if jq '
.plugins.load.paths = [.plugins.load.paths[]? | select(contains("plugins/genie") | not)] |
del(.plugins.entries["genie"])
' "$OPENCLAW_CONFIG" > "$tmp_config" 2>/dev/null; then
mv "$tmp_config" "$OPENCLAW_CONFIG"
return 0
else
rm -f "$tmp_config"
return 1
fi
}
# Verify symlink was created successfully
verify_symlink() {
local symlink_path="$1"
local expected_target="$2"
if [[ ! -L "$symlink_path" ]]; then
error "Symlink was not created: $symlink_path"
return 1
fi
if [[ ! -d "$symlink_path" ]]; then
error "Symlink points to non-existent directory: $(readlink "$symlink_path")"
return 1
fi
local actual_target
actual_target=$(readlink -f "$symlink_path" 2>/dev/null)
expected_target=$(cd "$expected_target" 2>/dev/null && pwd)
if [[ "$actual_target" != "$expected_target" ]]; then
warn "Symlink target mismatch"
warn " Expected: $expected_target"
warn " Actual: $actual_target"
return 1
fi
success "Symlink verified: $symlink_path -> $actual_target"
return 0
}
# ─────────────────────────────────────────────────────────────────────────────
# Source Directory Auto-Detection
# ─────────────────────────────────────────────────────────────────────────────
# Check if a directory is the genie-cli source directory
is_genie_source_dir() {
local dir="$1"
# Must have package.json
if [[ ! -f "$dir/package.json" ]]; then
return 1
fi
# package.json must contain @automagik/genie
if grep -q '"name"[[:space:]]*:[[:space:]]*"@automagik/genie"' "$dir/package.json" 2>/dev/null; then
return 0
fi
return 1
}
# Auto-detect if we're running from a genie-cli source directory
auto_detect_source_dir() {
# Get the directory where install.sh is located
local script_dir
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if is_genie_source_dir "$script_dir"; then
LOCAL_PATH="$script_dir"
AUTO_LOCAL_DETECTED=true
return 0
fi
return 1
}
# ─────────────────────────────────────────────────────────────────────────────
# Version Detection
# ─────────────────────────────────────────────────────────────────────────────
# Get installed genie-cli version
get_installed_version() {
local version=""
# Try bun first (check global packages)
if check_command bun; then
version=$(bun pm ls -g 2>/dev/null | grep "$PACKAGE_NAME" | grep -o '@[0-9][^[:space:]]*' | tr -d '@' || true)
fi
# Fallback to npm
if [[ -z "$version" ]] && check_command npm; then
version=$(npm ls -g "$PACKAGE_NAME" --depth=0 2>/dev/null | grep "$PACKAGE_NAME" | grep -o '@[0-9][^[:space:]]*' | tr -d '@' || true)
fi
echo "$version"
}
# Get latest version from npm registry
get_latest_version() {
local url="https://registry.npmjs.org/$PACKAGE_NAME/latest"
case "$DOWNLOADER" in
curl)
curl -fsSL "$url" 2>/dev/null | grep -o '"version":"[^"]*"' | cut -d'"' -f4
;;
wget)
wget -qO- "$url" 2>/dev/null | grep -o '"version":"[^"]*"' | cut -d'"' -f4
;;
esac
}
# ─────────────────────────────────────────────────────────────────────────────
# Platform Detection
# ─────────────────────────────────────────────────────────────────────────────
detect_platform() {
local os arch
case "$(uname -s)" in
Darwin)
os="darwin"
;;
Linux)
os="linux"
;;
MINGW*|MSYS*|CYGWIN*)
os="windows"
;;
*)
error "Unsupported operating system: $(uname -s)"
exit 3
;;
esac
case "$(uname -m)" in
x86_64|amd64)
arch="x64"
;;
aarch64|arm64)
arch="arm64"
;;
armv7l)
arch="arm"
;;
*)
error "Unsupported architecture: $(uname -m)"
exit 3
;;
esac
PLATFORM="$os"
ARCH="$arch"
log "Detected platform: ${BOLD}$PLATFORM-$ARCH${NC}"
}
# ─────────────────────────────────────────────────────────────────────────────
# Download Utilities
# ─────────────────────────────────────────────────────────────────────────────
init_downloader() {
if check_command curl; then
DOWNLOADER="curl"
elif check_command wget; then
DOWNLOADER="wget"
else
error "Neither curl nor wget found. Please install one of them."
exit 3
fi
}
# Download a file to stdout
download() {
local url="$1"
case "$DOWNLOADER" in
curl)
curl -fsSL "$url"
;;
wget)
wget -qO- "$url"
;;
esac
}
# ─────────────────────────────────────────────────────────────────────────────
# Package Manager Detection
# ─────────────────────────────────────────────────────────────────────────────
detect_package_manager() {
if check_command brew; then
echo "brew"
elif check_command apt-get; then
echo "apt"
elif check_command dnf; then
echo "dnf"
elif check_command yum; then
echo "yum"
elif check_command pacman; then
echo "pacman"
elif check_command apk; then
echo "apk"
elif check_command zypper; then
echo "zypper"
else
echo "unknown"
fi
}
# Install a package using the detected package manager
install_package() {
local package="$1"
local pm
pm=$(detect_package_manager)
case "$pm" in
brew)
brew install "$package"
;;
apt)
sudo apt-get update -qq && sudo apt-get install -y "$package"
;;
dnf)
sudo dnf install -y "$package"
;;
yum)
sudo yum install -y "$package"
;;
pacman)
sudo pacman -S --noconfirm "$package"
;;
apk)
sudo apk add --no-cache "$package"
;;
zypper)
sudo zypper install -y "$package"
;;
*)
return 1
;;
esac
}
# ─────────────────────────────────────────────────────────────────────────────
# Prerequisite Installation
# ─────────────────────────────────────────────────────────────────────────────
install_git_if_needed() {
if check_command git; then
success "git found"
return 0
fi
log "Installing git..."
if install_package "git" && check_command git; then
success "git installed"
else
error "git is required but could not be installed"
exit 3
fi
}
install_bun_if_needed() {
if check_command bun; then
success "Bun $(bun --version) found"
return 0
fi
log "Installing Bun..."
download "https://bun.sh/install" | bash
export BUN_INSTALL="${BUN_INSTALL:-$HOME/.bun}"
export PATH="$BUN_INSTALL/bin:$PATH"
if check_command bun; then
success "Bun $(bun --version) installed"
else
error "Bun installation failed"
exit 5
fi
}
# Ensure bun's global bin directory is in PATH
# This is needed after installing global packages via bun
ensure_bun_in_path() {
export BUN_INSTALL="${BUN_INSTALL:-$HOME/.bun}"
if [[ ":$PATH:" != *":$BUN_INSTALL/bin:"* ]]; then
export PATH="$BUN_INSTALL/bin:$PATH"
fi
}
# ─────────────────────────────────────────────────────────────────────────────
# Package Directory Location
# ─────────────────────────────────────────────────────────────────────────────
locate_package_dir() {
if [[ -n "$LOCAL_PATH" ]]; then
PKG_DIR="$LOCAL_PATH"
return 0
fi
# Try bun global
local bun_global="${BUN_INSTALL:-$HOME/.bun}/install/global/node_modules/@automagik/genie"
if [[ -d "$bun_global" ]]; then
PKG_DIR="$bun_global"
return 0
fi
# Try npm global
if check_command npm; then
local npm_root
npm_root=$(npm root -g 2>/dev/null || true)
if [[ -n "$npm_root" && -d "$npm_root/@automagik/genie" ]]; then
PKG_DIR="$npm_root/@automagik/genie"
return 0
fi
fi
PKG_DIR=""
return 1
}
# ─────────────────────────────────────────────────────────────────────────────
# Genie CLI Installation
# ─────────────────────────────────────────────────────────────────────────────
install_genie_cli() {
log "Installing $PACKAGE_NAME..."
# Local installation mode - use source directly
if [[ -n "$LOCAL_PATH" ]]; then
if $AUTO_LOCAL_DETECTED; then
info "Using local source mode (auto-detected from source directory)"
else
info "Using local source mode"
fi
log "Source path: $LOCAL_PATH"
if [[ ! -d "$LOCAL_PATH" ]]; then
error "Local path does not exist: $LOCAL_PATH"
exit 1
fi
pushd "$LOCAL_PATH" > /dev/null
# Build
log "Building from source..."
if check_command bun; then
bun install
bun run build
else
npm install
npm run build
fi
# Link globally (npm link creates proper global bin symlinks; bun link does not)
log "Linking globally..."
npm link
popd > /dev/null
success "$PACKAGE_NAME installed from local source"
return
fi
if check_command bun; then
bun install -g "$PACKAGE_NAME"
ensure_bun_in_path
elif check_command npm; then
npm install -g "$PACKAGE_NAME"
else
error "Neither bun nor npm found"
exit 3
fi
success "$PACKAGE_NAME installed"
}
# ─────────────────────────────────────────────────────────────────────────────
# Plugin Integration Offers
# ─────────────────────────────────────────────────────────────────────────────
offer_claude_plugin() {
if ! check_command claude; then
info "Claude Code not found — skipping plugin install"
return 0
fi
info "Installing Genie plugin for Claude Code..."
if [[ -n "$LOCAL_PATH" ]]; then
# Local mode: symlink the plugin directory
local plugin_dir="$PKG_DIR/plugins/genie"
if [[ -d "$plugin_dir" ]]; then
mkdir -p "$CLAUDE_PLUGINS_DIR"
rm -f "$PLUGIN_SYMLINK"
ln -sf "$plugin_dir" "$PLUGIN_SYMLINK"
if verify_symlink "$PLUGIN_SYMLINK" "$plugin_dir"; then
success "Genie Claude Code plugin linked"
else
warn "Failed to create valid symlink for Claude Code plugin"
fi
else
warn "Plugin directory not found: $plugin_dir"
fi
else
# Marketplace mode
claude plugin marketplace add automagik-dev/genie 2>/dev/null || true
if claude plugin install genie@automagik 2>/dev/null; then
success "Genie Claude Code plugin installed"
else
warn "Plugin install failed — try: /plugin install genie@automagik"
fi
fi
}
offer_openclaw_plugin() {
if ! check_command openclaw; then
info "OpenClaw not found — skipping plugin install"
return 0
fi
if openclaw plugins list 2>/dev/null | grep -q "genie"; then
success "Genie OpenClaw plugin already discovered"
return 0
fi
if [[ -z "$PKG_DIR" ]]; then
warn "Could not locate installed Genie package directory"
return 1
fi
if [[ ! -f "$PKG_DIR/openclaw.plugin.json" ]]; then
warn "OpenClaw plugin manifest not found: $PKG_DIR/openclaw.plugin.json"
return 1
fi
info "Installing Genie plugin for OpenClaw..."
if $DEV_MODE; then
log "Linking OpenClaw plugin (dev mode)..."
if openclaw plugins install -l "$PKG_DIR"; then
success "OpenClaw plugin linked"
else
warn "OpenClaw plugin link failed"
fi
else
log "Installing OpenClaw plugin (copy mode)..."
if openclaw plugins install "$PKG_DIR"; then
success "OpenClaw plugin installed"
else
warn "OpenClaw plugin install failed"
fi
fi
}
offer_codex_skills() {
local skills_source="$PKG_DIR/skills"
if [[ ! -d "$skills_source" ]]; then
warn "Skills directory not found in package"
return 1
fi
info "Installing Genie skills for Codex/OpenCode..."
mkdir -p "$CODEX_SKILLS_DIR"
local target="$CODEX_SKILLS_DIR/genie"
ln -sf "$skills_source" "$target"
success "Codex skills linked: $target -> $skills_source"
}
# ─────────────────────────────────────────────────────────────────────────────
# Orchestration Prompt Injection
# ─────────────────────────────────────────────────────────────────────────────
inject_orchestration_prompt() {
local rules_dir="$HOME/.claude/rules"
local rules_file="$rules_dir/genie-orchestration.md"
mkdir -p "$rules_dir"
# Use the already-resolved PKG_DIR to find the rules file
local source_file=""
if [[ -n "$PKG_DIR" && -f "$PKG_DIR/plugins/genie/rules/genie-orchestration.md" ]]; then
source_file="$PKG_DIR/plugins/genie/rules/genie-orchestration.md"
fi
if [[ -n "$source_file" ]]; then
cp "$source_file" "$rules_file"
success "Orchestration rules installed: $rules_file (from $source_file)"
else
# Fallback: write minimal inline message
cat > "$rules_file" <<'FALLBACK_EOF'
# Genie CLI
Use `genie` CLI for all agent operations. Never use native Agent/SendMessage tools.
FALLBACK_EOF
success "Orchestration rules installed (fallback): $rules_file"
fi
}
# ─────────────────────────────────────────────────────────────────────────────
# Default Config Creation
# ─────────────────────────────────────────────────────────────────────────────
create_default_config() {
local config_file="$GENIE_HOME/config.json"
if [[ -f "$config_file" ]]; then
info "Config already exists: $config_file"
return 0
fi
mkdir -p "$GENIE_HOME"
cat > "$config_file" <<'CONFIG_EOF'
{
"version": 2,
"promptMode": "append",
"session": { "name": "genie", "defaultWindow": "shell", "autoCreate": true },
"terminal": { "execTimeout": 120000, "readLines": 100, "worktreeBase": ".worktrees" },
"logging": { "tmuxDebug": false, "verbose": false },
"shell": { "preference": "auto" },
"shortcuts": { "tmuxInstalled": false, "shellInstalled": false },
"setupComplete": false
}
CONFIG_EOF
success "Default config created: $config_file"
}
# ─────────────────────────────────────────────────────────────────────────────
# tmux Installation and Configuration
# ─────────────────────────────────────────────────────────────────────────────
install_tmux_if_needed() {
if check_command tmux; then
success "tmux found"
return 0
fi
log "Installing tmux..."
if install_package "tmux" && check_command tmux; then
success "tmux installed"
else
warn "tmux could not be installed — agent orchestration may not work"
fi
}
configure_tmux_defaults() {
local tmux_conf="$GENIE_HOME/tmux.conf"
local scripts_dir="$GENIE_HOME/scripts"
local tmux_scripts_src=""
# Find tmux scripts source directory
if [[ -n "$PKG_DIR" && -d "$PKG_DIR/scripts/tmux" ]]; then
tmux_scripts_src="$PKG_DIR/scripts/tmux"
fi
if [[ -z "$tmux_scripts_src" ]]; then
warn "tmux scripts not found in package — skipping TUI setup"
return 0
fi
# --- Copy scripts to ~/.genie/scripts/ ---
log "Installing tmux scripts to $scripts_dir..."
mkdir -p "$scripts_dir"
local script_count=0
for script in "$tmux_scripts_src"/*.sh; do
[[ -f "$script" ]] || continue
cp "$script" "$scripts_dir/"
chmod +x "$scripts_dir/$(basename "$script")"
script_count=$((script_count + 1))
done
success "Installed $script_count tmux scripts to $scripts_dir"
# --- Write full tmux config ---
local tmux_conf_src="$tmux_scripts_src/genie.tmux.conf"
if [[ ! -f "$tmux_conf_src" ]]; then
warn "genie.tmux.conf template not found — skipping config"
return 0
fi
info "Genie will configure tmux. Your existing config will be backed up."
# Backup existing config if it exists and differs
if [[ -f "$tmux_conf" ]]; then
if ! diff -q "$tmux_conf" "$tmux_conf_src" &>/dev/null; then
cp "$tmux_conf" "${tmux_conf}.bak"
success "Backed up existing config to ${tmux_conf}.bak"
else
info "tmux config already matches Genie template"
return 0
fi
fi
cp "$tmux_conf_src" "$tmux_conf"
success "Genie tmux config written to $tmux_conf"
# Reload tmux if running
if tmux list-sessions &>/dev/null; then
tmux source-file "$tmux_conf" 2>/dev/null || true
log "tmux config reloaded"
fi
}
# ─────────────────────────────────────────────────────────────────────────────
# Agent Mode Output
# ─────────────────────────────────────────────────────────────────────────────
output_agent_prompt() {
printf 'GENIE_INSTALL_COMPLETE\n'
printf 'package_dir=%s\n' "$PKG_DIR"
cat <<'AGENT_EOF'
Genie has been installed successfully.
## Agent Instructions
Run `/wizard` now to complete onboarding. The wizard will:
1. **Check environment** — verify genie CLI, git repo, and project structure
2. **Shape identity** — define agent roles via `/brainstorm`
3. **Create first wish** — scope work via `/brainstorm` then `/wish`
4. **Execute** — build it via `/work`
5. **Celebrate** — review results and learn next steps
To start: paste `/wizard` in your Claude Code session.
Integrations installed:
- Claude Code plugin (if claude was found in PATH)
- Orchestration rules at ~/.claude/rules/genie-orchestration.md
- Default config at ~/.genie/config.json
- tmux defaults at ~/.tmux.conf
AGENT_EOF
}
# ─────────────────────────────────────────────────────────────────────────────
# Main Install Flow
# ─────────────────────────────────────────────────────────────────────────────
run_install() {
# ─── Prerequisites ───
header "Checking prerequisites..."
# Git only needed for local mode
if [[ -n "$LOCAL_PATH" ]]; then
install_git_if_needed
fi
install_bun_if_needed
install_tmux_if_needed
# ─── Genie CLI Install/Update ───
header "Installing Genie CLI..."
install_genie_cli
# ─── Locate package directory ───
if ! locate_package_dir; then
error "Could not locate Genie package directory"
exit 1
fi
log "Package directory: $PKG_DIR"
# ─── Orchestration Prompt ───
header "Configuring Claude Code..."
inject_orchestration_prompt
# ─── Default Config ───
create_default_config
# ─── tmux Defaults ───
configure_tmux_defaults
# ─── Plugin Integrations ───
header "Installing Integrations..."
echo -e "${DIM}────────────────────────────────────${NC}"
offer_claude_plugin
echo
offer_openclaw_plugin
echo
offer_codex_skills
# Agent mode: structured output for piped installs
if [[ "$INTERACTIVE" == "false" ]]; then
output_agent_prompt
fi
print_success
}
# ─────────────────────────────────────────────────────────────────────────────
# Main Uninstall Flow
# ─────────────────────────────────────────────────────────────────────────────
run_uninstall() {
echo
echo -e "${BOLD}Genie CLI Uninstaller${NC}"
echo -e "${DIM}────────────────────────────────────${NC}"
echo
local removed_something=false
# 1. Genie CLI package (default: yes)
if confirm "Remove Genie CLI package?"; then
if check_command bun; then
bun remove -g "$PACKAGE_NAME" 2>/dev/null || true
fi
if check_command npm; then
npm uninstall -g "$PACKAGE_NAME" 2>/dev/null || true
fi
success "Genie CLI removed"
removed_something=true
else
info "Keeping Genie CLI"
fi
# 2. Claude Code plugin symlink (default: yes)
if [[ -e "$PLUGIN_SYMLINK" || -L "$PLUGIN_SYMLINK" ]]; then
if confirm "Remove Claude Code plugin symlink?"; then
rm -rf "$PLUGIN_SYMLINK"
success "Claude Code plugin symlink removed"
removed_something=true
else
info "Keeping Claude Code plugin symlink"
fi
fi
# Try claude plugin uninstall for marketplace-installed plugins
if check_command claude && claude plugin list 2>/dev/null | grep -q "genie"; then
if confirm "Unregister Claude Code plugin from marketplace?"; then
claude plugin uninstall genie@automagik 2>/dev/null || true
success "Claude Code plugin unregistered"
removed_something=true
else
info "Keeping Claude Code plugin registration"
fi
fi
# 3. OpenClaw plugin (default: yes)
if check_command openclaw && openclaw plugins list 2>/dev/null | grep -q "genie"; then
if confirm "Remove OpenClaw plugin?"; then
local ext_dir="$HOME/.openclaw/extensions/genie"
# Best effort: disable in config first (if present)
openclaw plugins disable genie 2>/dev/null || true
if [[ -e "$ext_dir" || -L "$ext_dir" ]]; then
rm -rf "$ext_dir"
fi
# Also remove paths from OpenClaw config
remove_openclaw_plugin_paths
success "OpenClaw plugin removed"
removed_something=true
else
info "Keeping OpenClaw plugin"
fi
fi
# 4. Codex/OpenCode skills (default: yes)
local codex_link="$CODEX_SKILLS_DIR/genie"
if [[ -e "$codex_link" || -L "$codex_link" ]]; then
if confirm "Remove Codex/OpenCode skills?"; then
rm -f "$codex_link"
success "Codex skills removed"
removed_something=true
else
info "Keeping Codex skills"
fi
fi
# 5. Config directory (default: no - preserve settings)
if [[ -d "$GENIE_HOME" ]]; then
if confirm_no "Remove ~/.genie config directory?"; then
rm -rf "$GENIE_HOME"
success "Configuration removed"
removed_something=true
else
info "Keeping config (reinstall will preserve settings)"
fi
fi
echo
if $removed_something; then
success "Done"
else
info "Nothing removed"
fi
}
# ─────────────────────────────────────────────────────────────────────────────
# Installation Verification
# ─────────────────────────────────────────────────────────────────────────────
# Detect the user's shell profile file
get_shell_profile() {
local shell_name
shell_name=$(basename "${SHELL:-/bin/bash}")
case "$shell_name" in
zsh)
if [[ -f "$HOME/.zshrc" ]]; then
echo "$HOME/.zshrc"
else
echo "$HOME/.zprofile"
fi
;;
bash)
if [[ -f "$HOME/.bashrc" ]]; then
echo "$HOME/.bashrc"
elif [[ -f "$HOME/.bash_profile" ]]; then
echo "$HOME/.bash_profile"
else
echo "$HOME/.profile"
fi
;;
*)
echo "$HOME/.profile"