-
Notifications
You must be signed in to change notification settings - Fork 400
Expand file tree
/
Copy pathinstall.sh
More file actions
2537 lines (2294 loc) · 108 KB
/
Copy pathinstall.sh
File metadata and controls
2537 lines (2294 loc) · 108 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
#
# Databricks AI Dev Kit - Unified Installer
#
# Installs skills, MCP server, and configuration for Claude Code, Cursor, OpenAI Codex, GitHub Copilot, Gemini CLI, Antigravity, Windsurf, OpenCode, and Kiro.
#
# Usage: bash <(curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh) [OPTIONS]
#
# Examples:
# # Basic installation (project scoped, prompts for inputs, uses latest release)
# bash <(curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh)
#
# # Global installation with force reinstall
# bash <(curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh) --global --force
#
# # Specify profile and force reinstall
# bash <(curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh) --profile DEFAULT --force
#
# # Install for specific tools only
# bash <(curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh) --tools cursor,codex,copilot,gemini
#
# # Skills only (skip MCP server)
# bash <(curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh) --skills-only
#
# # Install skills for a specific profile
# bash <(curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh) --skills-profile data-engineer
#
# # Install multiple profiles
# bash <(curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh) --skills-profile data-engineer,ai-ml-engineer
#
# # Install specific skills only
# bash <(curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh) --skills databricks-jobs,databricks-dbsql
#
# # List available skills and profiles
# bash <(curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh) --list-skills
#
# Alternative: Use environment variables
# DEVKIT_TOOLS=cursor curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh | bash
# DEVKIT_FORCE=true DEVKIT_PROFILE=DEFAULT curl -sL https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/main/install.sh | bash
#
set -e
# Defaults (can be overridden by environment variables or command-line arguments)
PROFILE="${DEVKIT_PROFILE:-DEFAULT}"
SCOPE="${DEVKIT_SCOPE:-project}"
SCOPE_EXPLICIT=false # Track if --global was explicitly passed
FORCE="${DEVKIT_FORCE:-false}"
IS_UPDATE=false
UNINSTALL=false
DRY_RUN=false
ASSUME_YES=false
SILENT="${DEVKIT_SILENT:-false}"
TOOLS="${DEVKIT_TOOLS:-}"
USER_TOOLS=""
USER_MCP_PATH="${DEVKIT_MCP_PATH:-}"
SKILLS_PROFILE="${DEVKIT_SKILLS_PROFILE:-}"
USER_SKILLS="${DEVKIT_SKILLS:-}"
CHANNEL="${DEVKIT_CHANNEL:-stable}" # stable or experimental
# Convert string booleans from env vars to actual booleans
[ "$FORCE" = "true" ] || [ "$FORCE" = "1" ] && FORCE=true || FORCE=false
[ "$SILENT" = "true" ] || [ "$SILENT" = "1" ] && SILENT=true || SILENT=false
# Check if scope was explicitly set via env var
[ -n "${DEVKIT_SCOPE:-}" ] && SCOPE_EXPLICIT=true
OWNER="databricks-solutions"
REPO="ai-dev-kit"
if [ -n "${DEVKIT_BRANCH:-}" ]; then
BRANCH="$DEVKIT_BRANCH"
else
BRANCH="$(
curl -s "https://api.github.com/repos/${OWNER}/${REPO}/releases/latest" \
| grep '"tag_name"' \
| sed -E 's/.*"tag_name": *"([^"]+)".*/\1/'
)"
# Fallback to main if we couldn't fetch the latest release
[ -z "$BRANCH" ] && BRANCH="main"
fi
# Installation mode defaults
INSTALL_MCP=true
INSTALL_SKILLS=true
# Minimum required versions
MIN_CLI_VERSION="0.278.0"
MIN_SDK_VERSION="0.85.0"
# Colors
G='\033[0;32m' Y='\033[1;33m' R='\033[0;31m' BL='\033[0;34m' B='\033[1m' D='\033[2m' N='\033[0m'
# Databricks skills (bundled in repo)
SKILLS="databricks-agent-bricks databricks-ai-functions databricks-aibi-dashboards databricks-apps-python databricks-bundles databricks-config databricks-dbsql databricks-docs databricks-genie databricks-iceberg databricks-jobs databricks-lakebase-autoscale databricks-lakebase-provisioned databricks-metric-views databricks-mlflow-evaluation databricks-model-serving databricks-python-sdk databricks-spark-declarative-pipelines databricks-spark-structured-streaming databricks-synthetic-data-gen databricks-unity-catalog databricks-unstructured-pdf-generation databricks-vector-search databricks-zerobus-ingest spark-python-data-source"
# MLflow skills (fetched from mlflow/skills repo)
MLFLOW_SKILLS="agent-evaluation analyze-mlflow-chat-session analyze-mlflow-trace instrumenting-with-mlflow-tracing mlflow-onboarding querying-mlflow-metrics retrieving-mlflow-traces searching-mlflow-docs"
MLFLOW_RAW_URL="https://raw.githubusercontent.com/mlflow/skills/main"
# Agent skills (fetched from databricks/databricks-agent-skills repo)
AGENT_SKILLS="databricks-core:databricks databricks-apps databricks-lakebase"
AGENT_SKILLS_RAW_URL="https://raw.githubusercontent.com/databricks/databricks-agent-skills/main/skills"
AGENT_SKILLS_API_URL="https://api.github.com/repos/databricks/databricks-agent-skills/git/trees/main?recursive=1"
# ─── Skill profiles ──────────────────────────────────────────
# Core skills always installed regardless of profile selection
CORE_SKILLS="databricks-config databricks-docs databricks-python-sdk databricks-unity-catalog"
# Profile definitions (non-core skills only — core skills are always added)
PROFILE_DATA_ENGINEER="databricks-spark-declarative-pipelines databricks-spark-structured-streaming databricks-jobs databricks-bundles databricks-dbsql databricks-iceberg databricks-zerobus-ingest spark-python-data-source databricks-metric-views databricks-synthetic-data-gen"
PROFILE_ANALYST="databricks-aibi-dashboards databricks-dbsql databricks-genie databricks-metric-views"
PROFILE_AIML_ENGINEER="databricks-agent-bricks databricks-ai-functions databricks-vector-search databricks-model-serving databricks-genie databricks-unstructured-pdf-generation databricks-mlflow-evaluation databricks-synthetic-data-gen databricks-jobs"
PROFILE_AIML_MLFLOW="agent-evaluation analyze-mlflow-chat-session analyze-mlflow-trace instrumenting-with-mlflow-tracing mlflow-onboarding querying-mlflow-metrics retrieving-mlflow-traces searching-mlflow-docs"
PROFILE_APP_DEVELOPER="databricks-apps-python databricks-lakebase-autoscale databricks-lakebase-provisioned databricks-model-serving databricks-dbsql databricks-jobs databricks-bundles"
PROFILE_APP_DEVELOPER_AGENT="databricks-core:databricks databricks-apps databricks-lakebase"
# Selected skills (populated during profile selection)
SELECTED_SKILLS=""
SELECTED_MLFLOW_SKILLS=""
SELECTED_AGENT_SKILLS=""
# Output helpers
msg() { [ "$SILENT" = true ] || echo -e " $*"; }
ok() { [ "$SILENT" = true ] || echo -e " ${G}✓${N} $*"; }
warn() { [ "$SILENT" = true ] || echo -e " ${Y}!${N} $*"; }
die() { echo -e " ${R}✗${N} $*" >&2; exit 1; } # Always show errors
step() { [ "$SILENT" = true ] || echo -e "\n${B}$*${N}"; }
# Deprecation notice — shown on every install/upgrade while skills still ship
# from this repo. The next major release installs skills via the Databricks CLI
# from the official databricks/databricks-agent-skills set.
deprecation_notice() {
[ "$SILENT" = true ] && return
echo ""
echo -e " ${Y}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${N}"
echo -e " ${Y}${B}⚠ Heads up: skills are moving${N}"
echo -e " ${D}In the next release, the skills for AI Dev Kit will be${N}"
echo -e " ${D}promoted to a shared, engineering-supported repository.${N}"
echo -e " ${D}In future releases, this installer will set up skills${N}"
echo -e " ${D}using the Databricks CLI.${N}"
echo -e " ${Y}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${N}"
}
# Parse arguments
while [ $# -gt 0 ]; do
case $1 in
-p|--profile) PROFILE="$2"; shift 2 ;;
-g|--global) SCOPE="global"; SCOPE_EXPLICIT=true; shift ;;
-b|--branch) BRANCH="$2"; shift 2 ;;
--skills-only) INSTALL_MCP=false; shift ;;
--mcp-only) INSTALL_SKILLS=false; shift ;;
--mcp-path) USER_MCP_PATH="$2"; shift 2 ;;
--skills-profile) SKILLS_PROFILE="$2"; shift 2 ;;
--skills) USER_SKILLS="$2"; shift 2 ;;
--list-skills) LIST_SKILLS=true; shift ;;
--silent) SILENT=true; shift ;;
--tools) USER_TOOLS="$2"; shift 2 ;;
--experimental) CHANNEL="experimental"; shift ;;
-f|--force) FORCE=true; shift ;;
--uninstall) UNINSTALL=true; shift ;;
--dry-run) DRY_RUN=true; shift ;;
-y|--yes) ASSUME_YES=true; shift ;;
-h|--help)
echo "Databricks AI Dev Kit Installer"
echo ""
echo "Usage: bash <(curl -sL .../install.sh) [OPTIONS]"
echo ""
echo "Options:"
echo " -p, --profile NAME Databricks profile (default: DEFAULT)"
echo " -b, --branch NAME Git branch/tag to install (default: latest release)"
echo " -g, --global Install globally for all projects"
echo " --skills-only Skip MCP server setup"
echo " --mcp-only Skip skills installation"
echo " --mcp-path PATH Path to MCP server installation (default: ~/.ai-dev-kit)"
echo " --silent Silent mode (no output except errors)"
echo " --tools LIST Comma-separated: claude,cursor,copilot,codex,gemini,antigravity,windsurf,opencode,kiro"
echo " --skills-profile LIST Comma-separated profiles: all,data-engineer,analyst,ai-ml-engineer,app-developer"
echo " --skills LIST Comma-separated skill names to install (overrides profile)"
echo " --list-skills List available skills and profiles, then exit"
echo " --experimental Install from experimental branch (early access features)"
echo " -f, --force Force reinstall"
echo " --uninstall Remove AI Dev Kit: skills, MCP server runtime, MCP config, and Claude Code plugin"
echo " --dry-run With --uninstall: print what would be removed, change nothing"
echo " -y, --yes With --uninstall: skip the confirmation prompt"
echo " -h, --help Show this help"
echo ""
echo "Environment Variables (alternative to flags):"
echo " DEVKIT_PROFILE Databricks config profile"
echo " DEVKIT_BRANCH Git branch/tag to install (default: latest release)"
echo " DEVKIT_SCOPE 'project' or 'global'"
echo " DEVKIT_TOOLS Comma-separated list of tools"
echo " DEVKIT_FORCE Set to 'true' to force reinstall"
echo " DEVKIT_MCP_PATH Path to MCP server installation"
echo " DEVKIT_SKILLS_PROFILE Comma-separated skill profiles"
echo " DEVKIT_SKILLS Comma-separated skill names"
echo " DEVKIT_SILENT Set to 'true' for silent mode"
echo " DEVKIT_CHANNEL 'stable' (default) or 'experimental'"
echo " AIDEVKIT_HOME Installation directory (default: ~/.ai-dev-kit)"
echo ""
echo "Examples:"
echo " # Using environment variables"
echo " DEVKIT_TOOLS=cursor curl -sL .../install.sh | bash"
echo ""
exit 0 ;;
*) die "Unknown option: $1 (use -h for help)" ;;
esac
done
# ─── --list-skills handler ─────────────────────────────────────
if [ "${LIST_SKILLS:-false}" = true ]; then
echo ""
echo -e "${B}Available Skill Profiles${N}"
echo "────────────────────────────────"
echo ""
echo -e " ${B}all${N} All 36 skills (default)"
echo -e " ${B}data-engineer${N} Pipelines, Spark, Jobs, Streaming (14 skills)"
echo -e " ${B}analyst${N} Dashboards, SQL, Genie, Metrics (8 skills)"
echo -e " ${B}ai-ml-engineer${N} Agents, RAG, Vector Search, MLflow (17 skills)"
echo -e " ${B}app-developer${N} Apps, Lakebase, Deployment (9 skills)"
echo ""
echo -e "${B}Core Skills${N} (always installed)"
echo "────────────────────────────────"
for skill in $CORE_SKILLS; do
echo -e " ${G}✓${N} $skill"
done
echo ""
echo -e "${B}Data Engineer${N}"
echo "────────────────────────────────"
for skill in $PROFILE_DATA_ENGINEER; do
echo -e " $skill"
done
echo ""
echo -e "${B}Business Analyst${N}"
echo "────────────────────────────────"
for skill in $PROFILE_ANALYST; do
echo -e " $skill"
done
echo ""
echo -e "${B}AI/ML Engineer${N}"
echo "────────────────────────────────"
for skill in $PROFILE_AIML_ENGINEER; do
echo -e " $skill"
done
echo -e " ${D}+ MLflow skills:${N}"
for skill in $PROFILE_AIML_MLFLOW; do
echo -e " $skill"
done
echo ""
echo -e "${B}App Developer${N}"
echo "────────────────────────────────"
for skill in $PROFILE_APP_DEVELOPER; do
echo -e " $skill"
done
echo ""
echo -e "${B}MLflow Skills${N} (from mlflow/skills repo)"
echo "────────────────────────────────"
for skill in $MLFLOW_SKILLS; do
echo -e " $skill"
done
echo ""
echo -e "${B}Agent Skills${N} (from databricks/databricks-agent-skills repo)"
echo "────────────────────────────────"
for entry in $AGENT_SKILLS; do
echo -e " ${entry#*:}"
done
echo ""
echo -e "${D}Usage: bash install.sh --skills-profile data-engineer,ai-ml-engineer${N}"
echo -e "${D} bash install.sh --skills databricks-jobs,databricks-dbsql${N}"
echo ""
exit 0
fi
# ─── --uninstall handler ───────────────────────────────────────
# All skill directory names the installer has EVER shipped (current + historical
# renames/removals). Uninstall sweeps this union so old installs — e.g. the
# removed databricks-lakebase-provisioned or the renamed databricks-app-python —
# are cleaned up, not just whatever the current release ships.
UNINSTALL_SKILL_NAMES="
databricks-agent-bricks databricks-ai-functions databricks-aibi-dashboards
databricks-bundles databricks-asset-bundles databricks-apps-python databricks-app-python
databricks-app-apx databricks-config databricks-dbsql databricks-docs
databricks-execution-compute databricks-genie databricks-iceberg databricks-jobs
databricks-lakebase-autoscale databricks-lakebase-provisioned databricks-metric-views
databricks-ml-training-serving databricks-model-serving databricks-mlflow-evaluation
databricks-parsing databricks-python-sdk databricks-spark-declarative-pipelines
databricks-spark-structured-streaming databricks-synthetic-data-gen databricks-synthetic-data-generation
databricks-unity-catalog databricks-unstructured-pdf-generation databricks-vector-search
databricks-zerobus-ingest spark-python-data-source
databricks databricks-apps databricks-lakebase
agent-evaluation analyze-mlflow-chat-session analyze-mlflow-trace
instrumenting-with-mlflow-tracing mlflow-onboarding querying-mlflow-metrics
retrieving-mlflow-traces searching-mlflow-docs
"
# The Claude Code plugin (installed via a marketplace, separate from the skills
# this script drops directly). Its on-disk state lives across several shared
# files (~/.claude/plugins/installed_plugins.json, enabledPlugins in
# settings.json, known_marketplaces.json, the cache dir) that are shared with
# the user's OTHER plugins — so we never hand-edit them. Detection is read-only;
# removal is delegated to the official `claude` CLI (or shown as a command).
#
# The plugin can be installed from ANY marketplace, so we match by plugin name and
# discover the actual "name@marketplace" key(s) rather than assuming a marketplace.
PLUGIN_NAME="databricks-ai-dev-kit"
# Read-only: true only if the EXACT top-level server key ($2) contains a
# 'databricks' entry — the same thing removal targets. This deliberately does NOT
# match nested occurrences (e.g. ~/.claude.json's projects.<path>.mcpServers.databricks,
# which is a project-scoped server we never touch) that a plain grep would flag.
mcp_json_has_databricks() {
local path=$1 top=$2 py=""
[ -f "$path" ] || return 1
command -v python3 >/dev/null 2>&1 && py=python3
[ -z "$py" ] && [ -f "$VENV_PYTHON" ] && py="$VENV_PYTHON"
# No Python: fall back to a loose grep (best effort; may over-match).
[ -z "$py" ] && { grep -qF '"databricks"' "$path" 2>/dev/null; return; }
"$py" - "$path" "$top" <<'PYEOF'
import json, sys
try:
cfg = json.load(open(sys.argv[1]))
except Exception:
sys.exit(1)
top = cfg.get(sys.argv[2])
sys.exit(0 if (isinstance(top, dict) and "databricks" in top) else 1)
PYEOF
}
# Remove the 'databricks' MCP server entry from a JSON config, preserving all
# other servers and settings. $2 is the top-level key ('mcpServers' or 'servers').
uninstall_remove_json_key() {
local path=$1 top=$2
[ -f "$path" ] || return 1
grep -qF '"databricks"' "$path" 2>/dev/null || return 1
if [ "$DRY_RUN" = true ]; then echo "$path"; return 0; fi
local py=""
command -v python3 >/dev/null 2>&1 && py=python3
[ -z "$py" ] && [ -f "$VENV_PYTHON" ] && py="$VENV_PYTHON"
if [ -z "$py" ]; then warn "No Python to edit $path — remove the 'databricks' entry manually."; return 1; fi
# Python decides whether the exact top-level 'databricks' key is present; it
# writes (and the shell backs up) only when a key is actually removed, so a
# stray '"databricks"' elsewhere in the file doesn't trigger a no-op rewrite.
cp "$path" "${path}.bak"
if "$py" - "$path" "$top" <<'PYEOF'
import json, sys
path, top = sys.argv[1], sys.argv[2]
try:
with open(path) as f: cfg = json.load(f)
except Exception: sys.exit(2)
if not (isinstance(cfg.get(top), dict) and 'databricks' in cfg[top]):
sys.exit(1) # nothing to remove
cfg[top].pop('databricks', None)
if not cfg[top]: cfg.pop(top, None)
with open(path, 'w') as f: json.dump(cfg, f, indent=2); f.write('\n')
sys.exit(0)
PYEOF
then
return 0
else
rm -f "${path}.bak" # nothing changed — don't leave a spurious backup
return 1
fi
}
# Remove the [mcp_servers.databricks] block from a Codex TOML config.
uninstall_remove_toml_block() {
local path=$1
[ -f "$path" ] || return 1
grep -qF 'mcp_servers.databricks' "$path" 2>/dev/null || return 1
if [ "$DRY_RUN" = true ]; then echo "$path"; return 0; fi
cp "$path" "${path}.bak"
# Delete the [mcp_servers.databricks] table AND its dotted subtables
# (e.g. [mcp_servers.databricks.env]) through to the next unrelated
# [section] header (or EOF). awk keeps everything outside that block.
awk '
/^\[mcp_servers\.databricks(\.|\])/ { skip=1; next }
/^\[/ { skip=0 }
!skip { print }
' "${path}.bak" > "$path"
return 0
}
# Remove the AI Dev Kit SessionStart hook (identified by check_update.sh) from a
# Claude settings.json, leaving other hooks intact.
uninstall_remove_claude_hook() {
local path=$1
[ -f "$path" ] || return 1
grep -q 'check_update.sh' "$path" 2>/dev/null || return 1
if [ "$DRY_RUN" = true ]; then echo "$path"; return 0; fi
local py=""
command -v python3 >/dev/null 2>&1 && py=python3
[ -z "$py" ] && [ -f "$VENV_PYTHON" ] && py="$VENV_PYTHON"
[ -z "$py" ] && { warn "No Python to edit $path — remove the check_update.sh hook manually."; return 1; }
cp "$path" "${path}.bak"
"$py" - "$path" <<'PYEOF'
import json, sys
path = sys.argv[1]
try:
with open(path) as f: cfg = json.load(f)
except Exception: sys.exit(0)
sh = cfg.get('hooks', {}).get('SessionStart')
if isinstance(sh, list):
for group in sh:
group['hooks'] = [h for h in group.get('hooks', []) if 'check_update.sh' not in h.get('command', '')]
sh[:] = [g for g in sh if g.get('hooks')]
if not sh: cfg['hooks'].pop('SessionStart', None)
if not cfg.get('hooks'): cfg.pop('hooks', None)
with open(path, 'w') as f: json.dump(cfg, f, indent=2); f.write('\n')
PYEOF
return 0
}
# Read-only detection of the plugin per scope. The scope is recorded by which
# settings.json enables it: user scope in ~/.claude/settings.json, project scope in
# the project's .claude/settings.json(.local). (installed_plugins.json is user-level
# and lists ALL scopes together, so it can't distinguish them.) Prints the enabled
# "name@marketplace" key(s) — one per line — so any marketplace is matched.
plugin_keys_in() {
grep -hoE "\"${PLUGIN_NAME}@[A-Za-z0-9._-]+\"" "$@" 2>/dev/null | tr -d '"' | sort -u
}
plugin_keys_global() { plugin_keys_in "$HOME/.claude/settings.json"; }
plugin_keys_project() { plugin_keys_in "$1/.claude/settings.json" "$1/.claude/settings.local.json"; }
# Warn that the plugin also exists in the scope we're NOT uninstalling, and print
# the command to remove each detected key there too. $1 = newline-separated keys.
# Leads with a blank line to separate it from whatever preceded it.
# Count skill folders and 'databricks' MCP entries under the given roots/targets,
# plus hook/state/plugin, emitting one " - ..." summary line each. Shared by the
# project- and global-scope summaries below. Read-only; always returns 0.
_leftovers_summary() {
local hook=$1 state_dir=$2 plugin_keys=$3; shift 3
local root name entry path kind n=0
# Remaining args: skill roots, then a "--" separator, then "path|kind" MCP targets.
local -a roots=() targets=(); local sep=false a
for a in "$@"; do
[ "$a" = "--" ] && { sep=true; continue; }
$sep && targets+=("$a") || roots+=("$a")
done
for root in "${roots[@]}"; do
[ -d "$root" ] || continue
for name in $UNINSTALL_SKILL_NAMES; do [ -d "$root/$name" ] && n=$((n + 1)); done
done
[ "$n" -gt 0 ] && echo " - ${n} skill folder(s)"
n=0
for entry in "${targets[@]}"; do
path="${entry%%|*}"; kind="${entry#*|}"
[ -f "$path" ] || continue
case "$kind" in
json:*) mcp_json_has_databricks "$path" "${kind#json:}" && n=$((n + 1)) ;;
toml) grep -qF 'mcp_servers.databricks' "$path" 2>/dev/null && n=$((n + 1)) ;;
esac
done
[ "$n" -gt 0 ] && echo " - ${n} MCP config file(s) with the 'databricks' server"
[ -n "$hook" ] && grep -q 'check_update.sh' "$hook" 2>/dev/null && echo " - Claude update hook"
[ -n "$state_dir" ] && [ -d "$state_dir" ] && echo " - MCP server runtime / state ($(printf '%s' "$state_dir" | sed "s#$HOME#~#"))"
[ -n "$plugin_keys" ] && echo " - Claude Code plugin: $(printf '%s' "$plugin_keys" | tr '\n' ' ')"
return 0 # never let the last test's exit status trip `set -e` in the caller
}
# Project-scope artifacts under $1 (what a project uninstall from that dir removes).
project_leftovers_summary() {
local dir=$1
_leftovers_summary "$dir/.claude/settings.json" "$dir/.ai-dev-kit" "$(plugin_keys_project "$dir")" \
"$dir/.claude/skills" "$dir/.cursor/skills" "$dir/.github/skills" \
"$dir/.agents/skills" "$dir/.gemini/skills" "$dir/.windsurf/skills" \
"$dir/.opencode/skills" "$dir/.kiro/skills" \
-- \
"$dir/.mcp.json|json:mcpServers" "$dir/.cursor/mcp.json|json:mcpServers" "$dir/.vscode/mcp.json|json:servers" \
"$dir/.codex/config.toml|toml" "$dir/.gemini/settings.json|json:mcpServers" \
"$dir/opencode.json|json:mcp" "$dir/.kiro/settings/mcp.json|json:mcpServers"
}
# Global/user-scope artifacts (what a --global uninstall removes).
global_leftovers_summary() {
local install_dir="${AIDEVKIT_HOME:-$HOME/.ai-dev-kit}"
_leftovers_summary "$HOME/.claude/settings.json" "$install_dir" "$(plugin_keys_global)" \
"$HOME/.claude/skills" "$HOME/.cursor/skills" "$HOME/.github/skills" \
"$HOME/.agents/skills" "$HOME/.gemini/skills" "$HOME/.gemini/antigravity/skills" \
"$HOME/.codeium/windsurf/skills" "$HOME/.config/opencode/skills" "$HOME/.kiro/skills" \
-- \
"$HOME/.claude.json|json:mcpServers" "$HOME/.codex/config.toml|toml" "$HOME/.gemini/settings.json|json:mcpServers" \
"$HOME/.gemini/antigravity/mcp_config.json|json:mcpServers" "$HOME/.codeium/windsurf/mcp_config.json|json:mcpServers" \
"$HOME/.config/opencode/opencode.json|json:mcp" "$HOME/.kiro/settings/mcp.json|json:mcpServers"
}
# Very noticeable end-of-run box warning that files remain in the OTHER scope.
# $1 = headline, $2 = detail line, $3 = summary lines, $4 = how-to-remove action.
leftovers_box() {
local headline=$1 detail=$2 summary=$3 action=$4
local bar=" ${Y}${B}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${N}"
echo ""
echo -e "$bar"
echo -e " ${Y}${B}${headline}${N}"
echo -e "$bar"
echo -e " ${D}${detail}${N}"
echo -e "$summary"
echo -e " ${Y}${action}${N}"
echo -e "$bar"
}
# Warn (after a global uninstall) that project-scoped files remain in $1.
warn_project_leftovers() {
leftovers_box "⚠ PROJECT-LEVEL AI DEV KIT FILES STILL REMAIN" \
"This global uninstall did not touch project-scoped files in: ${B}$1${N}" \
"$2" \
"Re-run the uninstaller from that folder ${B}without --global${N}${Y} to remove them."
}
# Warn (after a project uninstall) that global/user-level files remain.
warn_global_leftovers() {
leftovers_box "⚠ GLOBAL AI DEV KIT FILES STILL REMAIN" \
"This project uninstall did not touch global (user-level) files:" \
"$1" \
"Re-run the uninstaller with ${B}--global${N}${Y} to remove them."
}
# Remove the plugin from the CURRENT uninstall scope via the official CLI (atomic
# across the shared plugin state — we never hand-edit it). Removes every detected
# "name@marketplace" key (the plugin may come from any marketplace). A project
# install can be 'project' (.claude/settings.json) or 'local' (settings.local.json),
# so a project uninstall tries both CLI scopes. If nothing could be removed (CLI
# missing or every attempt failed) this is a hard error that reports whether the
# rest of the uninstall completed and prints the exact command to run manually.
# $1 = count of other AI Dev Kit artifacts already removed this run; $2 = keys.
remove_claude_plugin() {
local others_removed=$1 keys=$2
local scopes cmd_scope
if [ "$SCOPE" = "project" ]; then scopes="project local"; cmd_scope="project"; else scopes="user"; cmd_scope="user"; fi
if command -v claude >/dev/null 2>&1; then
local k sc removed=false
while IFS= read -r k; do
[ -z "$k" ] && continue
for sc in $scopes; do
# Subcommand name has varied across versions (uninstall vs remove) — try both.
if claude plugin uninstall "$k" -y --scope "$sc" >/dev/null 2>&1 \
|| claude plugin remove "$k" -y --scope "$sc" >/dev/null 2>&1; then
msg "removed Claude Code plugin ${k} (${sc} scope)"
removed=true
fi
done
done <<< "$keys"
[ "$removed" = true ] && return 0
fi
local partial="" alt="" manual="" k
[ "$others_removed" -gt 0 ] && partial="Skills, MCP server, and config WERE removed (partial uninstall). "
[ "$SCOPE" = "project" ] && alt=" (or --scope local)"
while IFS= read -r k; do [ -n "$k" ] && manual="${manual:+$manual; }claude plugin uninstall ${k} --scope ${cmd_scope}"; done <<< "$keys"
die "Could not remove the Claude Code plugin. ${partial}Finish it manually: ${B}${manual}${N}${alt}"
}
run_uninstall() {
local base_dir install_dir state_dir
# Mirror install: if scope wasn't set explicitly, ask (interactive, non --yes)
# so a user who did a global install isn't silently told "nothing to uninstall
# for project scope". Non-interactive/--yes keeps the documented 'project' default.
# Ask for scope with the same selector install uses, unless it was set
# explicitly (-g/--global, DEVKIT_SCOPE) or we're non-interactive/--yes.
if [ "$SCOPE_EXPLICIT" = false ] && [ "$ASSUME_YES" != true ]; then
SCOPE_PROMPT_TITLE="Select uninstall scope" SCOPE_PROMPT_VERB="Remove from" prompt_scope
# renders: "Remove from current directory ..." / "Remove from home directory ..."
fi
[ "$SCOPE" = "global" ] && base_dir="$HOME" || base_dir="$(pwd)"
install_dir="${USER_MCP_PATH:-${AIDEVKIT_HOME:-$HOME/.ai-dev-kit}}"
[ "$SCOPE" = "global" ] && state_dir="$install_dir" || state_dir="$base_dir/.ai-dev-kit"
VENV_PYTHON="$install_dir/.venv/bin/python"
# Scope strictly gates locations. The installer writes project artifacts under
# the project dir and global artifacts under $HOME; a project uninstall must
# never touch $HOME configs (and vice-versa), or it would clobber the other
# scope's install. The few tools that always use $HOME even for project scope
# (antigravity/windsurf/opencode/kiro) are therefore only cleaned in --global.
local skill_roots mcp_targets hook_targets
if [ "$SCOPE" = "global" ]; then
skill_roots=(
"$HOME/.claude/skills" "$HOME/.cursor/skills" "$HOME/.github/skills"
"$HOME/.agents/skills" "$HOME/.gemini/skills"
"$HOME/.gemini/antigravity/skills" "$HOME/.codeium/windsurf/skills"
"$HOME/.config/opencode/skills" "$HOME/.kiro/skills"
)
mcp_targets=(
"$HOME/.claude.json|json:mcpServers"
"$HOME/.codex/config.toml|toml"
"$HOME/.gemini/settings.json|json:mcpServers"
"$HOME/.gemini/antigravity/mcp_config.json|json:mcpServers"
"$HOME/.codeium/windsurf/mcp_config.json|json:mcpServers"
"$HOME/.config/opencode/opencode.json|json:mcp"
"$HOME/.kiro/settings/mcp.json|json:mcpServers"
)
hook_targets=("$HOME/.claude/settings.json")
else
skill_roots=(
"$base_dir/.claude/skills" "$base_dir/.cursor/skills" "$base_dir/.github/skills"
"$base_dir/.agents/skills" "$base_dir/.gemini/skills" "$base_dir/.windsurf/skills"
"$base_dir/.opencode/skills" "$base_dir/.kiro/skills"
)
mcp_targets=(
"$base_dir/.mcp.json|json:mcpServers"
"$base_dir/.cursor/mcp.json|json:mcpServers" "$base_dir/.vscode/mcp.json|json:servers"
"$base_dir/.codex/config.toml|toml"
"$base_dir/.gemini/settings.json|json:mcpServers"
"$base_dir/opencode.json|json:mcp"
"$base_dir/.kiro/settings/mcp.json|json:mcpServers"
)
hook_targets=("$base_dir/.claude/settings.json")
fi
# ── Build the plan (paths that actually exist / contain our entries) ──
local -a plan_skills=() plan_mcp=() plan_hooks=() plan_runtime=() plan_state=()
local root name
for root in "${skill_roots[@]}"; do
[ -d "$root" ] || continue
for name in $UNINSTALL_SKILL_NAMES; do
[ -d "$root/$name" ] && plan_skills+=("$root/$name")
done
done
local entry path kind
for entry in "${mcp_targets[@]}"; do
path="${entry%%|*}"; kind="${entry#*|}"
case "$kind" in
json:*) mcp_json_has_databricks "$path" "${kind#json:}" && plan_mcp+=("$entry") ;;
toml) [ -f "$path" ] && grep -qF 'mcp_servers.databricks' "$path" 2>/dev/null && plan_mcp+=("$entry") ;;
esac
done
for path in "${hook_targets[@]}"; do
[ -f "$path" ] && grep -q 'check_update.sh' "$path" 2>/dev/null && plan_hooks+=("$path")
done
# The shared MCP runtime (~/.ai-dev-kit) is global; only remove it on a global
# uninstall, or when the user explicitly points --mcp-path at it. A project
# uninstall leaves it so other projects/global keep working.
if [ "$SCOPE" = "global" ] || [ -n "$USER_MCP_PATH" ]; then
[ -d "$install_dir" ] && plan_runtime+=("$install_dir")
fi
# On a global uninstall state_dir IS the runtime dir; when that dir is already in
# plan_runtime the state files inside it are removed along with it — planning them
# separately would double-delete (and double-list them in the plan).
if [[ " ${plan_runtime[*]} " != *" $state_dir "* ]]; then
for path in "$state_dir/.installed-skills" "$state_dir/.skills-profile" "$state_dir/version"; do
[ -f "$path" ] && plan_state+=("$path")
done
fi
# Project-scope leftover marker dir
[ "$SCOPE" = "project" ] && [ -d "$base_dir/.ai-dev-kit" ] && plan_state+=("$base_dir/.ai-dev-kit/")
# Claude Code plugin at the CURRENT scope — collect the enabled "name@marketplace"
# key(s) so any marketplace is matched; these are what we remove.
local plugin_keys="" plan_plugin=false plugin_count=0 k
if [ "$SCOPE" = "global" ]; then plugin_keys=$(plugin_keys_global); else plugin_keys=$(plugin_keys_project "$base_dir"); fi
[ -n "$plugin_keys" ] && { plan_plugin=true; plugin_count=$(printf '%s\n' "$plugin_keys" | grep -c .); }
# Warn about artifacts left behind in the OTHER scope. A global uninstall looks
# for project-scope files in the current folder ($PWD); a project uninstall looks
# for global/user-level files. Skip the $PWD scan when $PWD is $HOME (there the
# project and global paths coincide and are already handled by the global side).
local project_leftovers="" global_leftovers=""
if [ "$SCOPE" = "global" ]; then
[ "$PWD" != "$HOME" ] && project_leftovers=$(project_leftovers_summary "$PWD")
else
[ "$base_dir" != "$HOME" ] && global_leftovers=$(global_leftovers_summary)
fi
local total=$(( ${#plan_skills[@]} + ${#plan_mcp[@]} + ${#plan_hooks[@]} + ${#plan_runtime[@]} + ${#plan_state[@]} + plugin_count ))
if [ "$total" -eq 0 ]; then
ok "Nothing to uninstall for ${B}$SCOPE${N} scope at ${D}${base_dir}${N} — no AI Dev Kit artifacts found."
[ "$SCOPE" = "project" ] && [ -z "$global_leftovers" ] && msg "${D}Tip: pass --global to remove a global install.${N}"
[ -n "$project_leftovers" ] && warn_project_leftovers "$PWD" "$project_leftovers"
[ -n "$global_leftovers" ] && warn_global_leftovers "$global_leftovers"
exit 0
fi
step "Uninstall plan (${SCOPE} scope)"
[ ${#plan_skills[@]} -gt 0 ] && { echo -e " ${B}Skill folders (${#plan_skills[@]}):${N}"; for p in "${plan_skills[@]}"; do echo " ${p/#$HOME/~}"; done; }
[ ${#plan_mcp[@]} -gt 0 ] && { echo -e " ${B}MCP config — remove 'databricks' entry (${#plan_mcp[@]}):${N}"; for e in "${plan_mcp[@]}"; do echo " ${e%%|*}" | sed "s#$HOME#~#"; done; }
[ ${#plan_hooks[@]} -gt 0 ] && { echo -e " ${B}Claude update hook (${#plan_hooks[@]}):${N}"; for p in "${plan_hooks[@]}"; do echo " ${p/#$HOME/~}"; done; }
[ ${#plan_runtime[@]} -gt 0 ] && { echo -e " ${B}MCP server runtime:${N}"; for p in "${plan_runtime[@]}"; do echo " ${p/#$HOME/~}"; done; }
[ ${#plan_state[@]} -gt 0 ] && { echo -e " ${B}State files:${N}"; for p in "${plan_state[@]}"; do echo " ${p/#$HOME/~}"; done; }
[ "$plan_plugin" = true ] && {
echo -e " ${B}Claude Code plugin:${N}"
while IFS= read -r k; do [ -n "$k" ] && echo -e " ${k} ${D}(removed via the claude CLI, ${SCOPE} scope)${N}"; done <<< "$plugin_keys"
echo -e " ${Y}${B}⚠ Heads up: the AI Dev Kit Claude Code plugin will also be removed.${N}"
}
echo ""
msg "${D}Config files are backed up to <file>.bak before editing.${N}"
if [ "$DRY_RUN" = true ]; then
[ -n "$project_leftovers" ] && warn_project_leftovers "$PWD" "$project_leftovers"
[ -n "$global_leftovers" ] && warn_global_leftovers "$global_leftovers"
ok "Dry run — nothing was changed. Re-run without --dry-run to apply."
exit 0
fi
if [ "$ASSUME_YES" != true ]; then
local reply=""
if { exec 3</dev/tty; } 2>/dev/null; then
printf " ${Y}Remove these %d item(s)?${N} [y/N] " "$total"
read -r reply <&3 || reply=""
exec 3<&-
else
die "No terminal to confirm on. Re-run with -y/--yes to proceed non-interactively (or --dry-run to preview)."
fi
case "$reply" in [yY]|[yY][eE][sS]) ;; *) die "Aborted — nothing removed." ;; esac
fi
step "Removing"
local p e
for p in "${plan_skills[@]}"; do rm -rf "$p" && msg "removed ${p/#$HOME/~}"; done
for e in "${plan_mcp[@]}"; do
path="${e%%|*}"; kind="${e#*|}"
case "$kind" in
json:*) uninstall_remove_json_key "$path" "${kind#json:}" && msg "cleaned ${path/#$HOME/~}" ;;
toml) uninstall_remove_toml_block "$path" && msg "cleaned ${path/#$HOME/~}" ;;
esac
done
for p in "${plan_hooks[@]}"; do uninstall_remove_claude_hook "$p" && msg "cleaned hook in ${p/#$HOME/~}"; done
for p in "${plan_runtime[@]}"; do rm -rf "$p" && msg "removed ${p/#$HOME/~}"; done
for p in "${plan_state[@]}"; do rm -rf "$p" && msg "removed ${p/#$HOME/~}"; done
[ "$plan_plugin" = true ] && remove_claude_plugin "$(( total - plugin_count ))" "$plugin_keys"
echo ""
ok "AI Dev Kit uninstalled (${SCOPE} scope)."
msg "${D}Other scopes and per-editor .bak backups were left untouched.${N}"
[ -n "$project_leftovers" ] && warn_project_leftovers "$PWD" "$project_leftovers"
[ -n "$global_leftovers" ] && warn_global_leftovers "$global_leftovers"
exit 0
}
# Set configuration URLs after parsing branch argument
REPO_URL="https://github.com/databricks-solutions/ai-dev-kit.git"
RAW_URL="https://raw.githubusercontent.com/databricks-solutions/ai-dev-kit/${BRANCH}"
INSTALL_DIR="${AIDEVKIT_HOME:-$HOME/.ai-dev-kit}"
REPO_DIR="$INSTALL_DIR/repo"
VENV_DIR="$INSTALL_DIR/.venv"
VENV_PYTHON="$VENV_DIR/bin/python"
MCP_ENTRY="$REPO_DIR/databricks-mcp-server/run_server.py"
# ─── Interactive helpers ────────────────────────────────────────
# Reads from /dev/tty so prompts work even when piped via curl | bash
# True if we have an interactive tty we can read from.
# `[ -e /dev/tty ]` is not safe here — on macOS the device node always exists
# even when the process has no controlling terminal, so existence does not
# imply we can open it. We check stdin first (normal interactive runs) and
# fall back to attempting to open /dev/tty (needed for `curl … | bash` where
# stdin is piped but a controlling terminal is still available).
is_interactive() {
[ -t 0 ] || ( : < /dev/tty ) 2>/dev/null
}
# Simple text prompt with default value
prompt() {
local prompt_text=$1
local default_value=$2
local result=""
if [ "$SILENT" = true ]; then
echo "$default_value"
return
fi
if ( : < /dev/tty ) 2>/dev/null; then
printf " %b [%s]: " "$prompt_text" "$default_value" > /dev/tty
read -r result < /dev/tty
elif [ -t 0 ]; then
printf " %b [%s]: " "$prompt_text" "$default_value"
read -r result
else
echo "$default_value"
return
fi
if [ -z "$result" ]; then
echo "$default_value"
else
echo "$result"
fi
}
# Interactive checkbox selector using arrow keys + space/enter + "Done" button
# Outputs space-separated selected values to stdout
# Args: "Label|value|on_or_off|hint" ...
checkbox_select() {
# Parse items
local -a labels=()
local -a values=()
local -a states=()
local -a hints=()
local count=0
for item in "$@"; do
IFS='|' read -r label value state hint <<< "$item"
labels+=("$label")
values+=("$value")
hints+=("$hint")
if [ "$state" = "on" ]; then
states+=(1)
else
states+=(0)
fi
count=$((count + 1))
done
local cursor=0
local total_rows=$((count + 2)) # items + blank line + Done button
# Draw the checkbox list + Done button
_checkbox_draw() {
local i
for i in $(seq 0 $((count - 1))); do
local check=" "
[ "${states[$i]}" = "1" ] && check="\033[0;32m✓\033[0m"
local arrow=" "
[ "$i" = "$cursor" ] && arrow="\033[0;34m❯\033[0m "
local hint_style="\033[2m"
[ "${states[$i]}" = "1" ] && hint_style="\033[0;32m"
printf "\033[2K %b[%b] %-16s %b%s\033[0m\n" "$arrow" "$check" "${labels[$i]}" "$hint_style" "${hints[$i]}" > /dev/tty
done
# Blank separator line
printf "\033[2K\n" > /dev/tty
# Done button
if [ "$cursor" = "$count" ]; then
printf "\033[2K \033[0;34m❯\033[0m \033[1;32m[ Confirm ]\033[0m\n" > /dev/tty
else
printf "\033[2K \033[2m[ Confirm ]\033[0m\n" > /dev/tty
fi
}
# Print instructions
printf "\n \033[2m↑/↓ navigate · space/enter select · enter on Confirm to finish\033[0m\n\n" > /dev/tty
# Hide cursor
printf "\033[?25l" > /dev/tty
# Restore cursor on exit (Ctrl+C safety)
trap 'printf "\033[?25h" > /dev/tty 2>/dev/null' EXIT
# Initial draw
_checkbox_draw
# Input loop
while true; do
# Move back to top of drawn area and redraw
printf "\033[%dA" "$total_rows" > /dev/tty
_checkbox_draw
# Read input
local key=""
IFS= read -rsn1 key < /dev/tty 2>/dev/null
if [ "$key" = $'\x1b' ]; then
local s1="" s2=""
read -rsn1 s1 < /dev/tty 2>/dev/null
read -rsn1 s2 < /dev/tty 2>/dev/null
if [ "$s1" = "[" ]; then
case "$s2" in
A) [ "$cursor" -gt 0 ] && cursor=$((cursor - 1)) ;; # Up
B) [ "$cursor" -lt "$count" ] && cursor=$((cursor + 1)) ;; # Down (can go to Done)
esac
fi
elif [ "$key" = " " ] || [ "$key" = "" ]; then
# Space or Enter
if [ "$cursor" -lt "$count" ]; then
# On a checkbox item — toggle it
if [ "${states[$cursor]}" = "1" ]; then
states[$cursor]=0
else
states[$cursor]=1
fi
else
# On the Confirm button — done
printf "\033[%dA" "$total_rows" > /dev/tty
_checkbox_draw
break
fi
fi
done
# Show cursor again
printf "\033[?25h" > /dev/tty
trap - EXIT
# Build result
local selected=""
for i in $(seq 0 $((count - 1))); do
if [ "${states[$i]}" = "1" ]; then
selected="${selected:+$selected }${values[$i]}"
fi
done
echo "$selected"
}
# Interactive single-select using arrow keys + enter + "Confirm" button
# Outputs the selected value to stdout
# Args: "Label|value|selected|hint" ... (exactly one should have selected=on)
radio_select() {
# Parse items
local -a labels=()
local -a values=()
local -a hints=()
local count=0
local selected=0
for item in "$@"; do
IFS='|' read -r label value state hint <<< "$item"
labels+=("$label")
values+=("$value")
hints+=("$hint")
[ "$state" = "on" ] && selected=$count
count=$((count + 1))
done
local cursor=0
local total_rows=$((count + 2)) # items + blank line + Confirm button
_radio_draw() {
local i
for i in $(seq 0 $((count - 1))); do
local dot="○"
local dot_color="\033[2m"
[ "$i" = "$selected" ] && dot="●" && dot_color="\033[0;32m"
local arrow=" "
[ "$i" = "$cursor" ] && arrow="\033[0;34m❯\033[0m "
local hint_style="\033[2m"
[ "$i" = "$selected" ] && hint_style="\033[0;32m"
printf "\033[2K %b%b%b %-20s %b%s\033[0m\n" "$arrow" "$dot_color" "$dot" "${labels[$i]}" "$hint_style" "${hints[$i]}" > /dev/tty
done
printf "\033[2K\n" > /dev/tty
if [ "$cursor" = "$count" ]; then
printf "\033[2K \033[0;34m❯\033[0m \033[1;32m[ Confirm ]\033[0m\n" > /dev/tty
else
printf "\033[2K \033[2m[ Confirm ]\033[0m\n" > /dev/tty
fi
}
printf "\n \033[2m↑/↓ navigate · enter confirm · space preview\033[0m\n\n" > /dev/tty
printf "\033[?25l" > /dev/tty
trap 'printf "\033[?25h" > /dev/tty 2>/dev/null' EXIT
_radio_draw
while true; do
printf "\033[%dA" "$total_rows" > /dev/tty
_radio_draw
local key=""
IFS= read -rsn1 key < /dev/tty 2>/dev/null
if [ "$key" = $'\x1b' ]; then
local s1="" s2=""
read -rsn1 s1 < /dev/tty 2>/dev/null
read -rsn1 s2 < /dev/tty 2>/dev/null
if [ "$s1" = "[" ]; then
case "$s2" in
A) [ "$cursor" -gt 0 ] && cursor=$((cursor - 1)) ;;
B) [ "$cursor" -lt "$count" ] && cursor=$((cursor + 1)) ;;
esac
fi
elif [ "$key" = "" ]; then
# Enter — select current item and confirm immediately
if [ "$cursor" -lt "$count" ]; then
selected=$cursor
fi
printf "\033[%dA" "$total_rows" > /dev/tty
_radio_draw
break
elif [ "$key" = " " ]; then
# Space — select but keep browsing
if [ "$cursor" -lt "$count" ]; then
selected=$cursor
fi
fi
done
printf "\033[?25h" > /dev/tty
trap - EXIT
echo "${values[$selected]}"
}
# ─── Tool detection & selection ─────────────────────────────────
detect_tools() {
# If provided via --tools flag or TOOLS env var, skip detection and prompts
if [ -n "$USER_TOOLS" ]; then
TOOLS=$(echo "$USER_TOOLS" | tr ',' ' ')
return
elif [ -n "$TOOLS" ]; then
# TOOLS env var already set, just normalize it
TOOLS=$(echo "$TOOLS" | tr ',' ' ')
return
fi
# Auto-detect what's installed
local has_claude=false
local has_cursor=false
local has_codex=false
local has_copilot=false
local has_gemini=false
local has_antigravity=false
local has_windsurf=false
local has_opencode=false
local has_kiro=false