-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.sh
More file actions
executable file
·681 lines (593 loc) · 21.9 KB
/
quickstart.sh
File metadata and controls
executable file
·681 lines (593 loc) · 21.9 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
#!/usr/bin/env bash
#
# Blerbz Plugins - Quickstart Setup Script
# Automates installation of inference-confidenz and inference-continuez plugins
#
# Usage: ./quickstart.sh [--install-path /path/to/install]
#
set -euo pipefail
# ============================================================================
# Configuration
# ============================================================================
VERSION="2.0.0"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEFAULT_INSTALL_PATH="$HOME/blerbz-plugins"
CLAUDE_DIR="$HOME/.claude"
PLUGINS_DIR="$CLAUDE_DIR/plugins"
SETTINGS_FILE="$CLAUDE_DIR/settings.json"
MARKETPLACES_FILE="$PLUGINS_DIR/known_marketplaces.json"
INSTALLED_PLUGINS_FILE="$PLUGINS_DIR/installed_plugins.json"
# Project-scoped installation flags
PROJECT_SCOPED=false
PROJECT_ROOT=""
INSTALL_SCOPE="user"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# ============================================================================
# Helper Functions
# ============================================================================
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[OK]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_step() {
echo -e "\n${CYAN}${BOLD}==> $1${NC}"
}
# Check if a command exists
command_exists() {
command -v "$1" &> /dev/null
}
# Merge JSON objects (key-value at top level)
# Falls back to Python if jq isn't available
merge_json_objects() {
local base_file="$1"
local new_json="$2"
local output_file="$3"
if command_exists jq; then
if [[ -f "$base_file" ]]; then
jq -s '.[0] * .[1]' "$base_file" <(echo "$new_json") > "$output_file.tmp"
mv "$output_file.tmp" "$output_file"
else
echo "$new_json" | jq '.' > "$output_file"
fi
elif command_exists python3; then
python3 << EOF
import json
import sys
base = {}
if '$base_file' and __import__('os').path.exists('$base_file'):
with open('$base_file', 'r') as f:
base = json.load(f)
new = json.loads('''$new_json''')
base.update(new)
with open('$output_file', 'w') as f:
json.dump(base, f, indent=2)
EOF
else
log_error "Neither jq nor python3 found. Cannot merge JSON files."
return 1
fi
}
# Merge installed plugins (handles nested structure)
merge_installed_plugins() {
local base_file="$1"
local new_plugins="$2"
local output_file="$3"
if command_exists jq; then
if [[ -f "$base_file" ]]; then
jq -s '
.[0] as $base | .[1] as $new |
$base * {plugins: ($base.plugins + $new.plugins)}
' "$base_file" <(echo "$new_plugins") > "$output_file.tmp"
mv "$output_file.tmp" "$output_file"
else
echo "$new_plugins" | jq '.' > "$output_file"
fi
elif command_exists python3; then
python3 << EOF
import json
import os
base = {"version": 2, "plugins": {}}
if os.path.exists('$base_file'):
with open('$base_file', 'r') as f:
base = json.load(f)
new = json.loads('''$new_plugins''')
if 'plugins' not in base:
base['plugins'] = {}
base['plugins'].update(new.get('plugins', {}))
with open('$output_file', 'w') as f:
json.dump(base, f, indent=2)
EOF
else
log_error "Neither jq nor python3 found. Cannot merge JSON files."
return 1
fi
}
# Merge settings.json (handles enabledPlugins)
merge_settings() {
local base_file="$1"
local new_enabled="$2"
local output_file="$3"
if command_exists jq; then
if [[ -f "$base_file" ]]; then
jq --argjson enabled "$new_enabled" '
.enabledPlugins = (.enabledPlugins // {}) + $enabled
' "$base_file" > "$output_file.tmp"
mv "$output_file.tmp" "$output_file"
else
echo "{\"enabledPlugins\": $new_enabled}" | jq '.' > "$output_file"
fi
elif command_exists python3; then
python3 << EOF
import json
import os
base = {}
if os.path.exists('$base_file'):
with open('$base_file', 'r') as f:
base = json.load(f)
new_enabled = json.loads('''$new_enabled''')
if 'enabledPlugins' not in base:
base['enabledPlugins'] = {}
base['enabledPlugins'].update(new_enabled)
with open('$output_file', 'w') as f:
json.dump(base, f, indent=2)
EOF
else
log_error "Neither jq nor python3 found. Cannot merge JSON files."
return 1
fi
}
# Prompt user for yes/no
confirm() {
local prompt="$1"
local default="${2:-y}"
local response
if [[ "$default" == "y" ]]; then
prompt="$prompt [Y/n]: "
else
prompt="$prompt [y/N]: "
fi
read -rp "$prompt" response
response="${response:-$default}"
[[ "$response" =~ ^[Yy] ]]
}
# ============================================================================
# Pre-flight Checks
# ============================================================================
check_prerequisites() {
log_step "Checking prerequisites..."
local has_errors=false
# Check for Claude Code directory
if [[ -d "$CLAUDE_DIR" ]]; then
log_success "Claude Code directory found: $CLAUDE_DIR"
else
log_warn "Claude Code directory not found. Will create: $CLAUDE_DIR"
fi
# Check for jq or python3
if command_exists jq; then
log_success "jq found (preferred for JSON manipulation)"
elif command_exists python3; then
log_success "python3 found (fallback for JSON manipulation)"
else
log_error "Neither jq nor python3 found. Please install one of them."
log_info " macOS: brew install jq"
log_info " Ubuntu: sudo apt install jq"
has_errors=true
fi
# Check for git (optional, for cloning)
if command_exists git; then
log_success "git found"
else
log_warn "git not found. Cannot clone repository (local install only)"
fi
if [[ "$has_errors" == true ]]; then
log_error "Prerequisites check failed. Please fix the issues above."
exit 1
fi
}
# ============================================================================
# Installation Functions
# ============================================================================
determine_install_path() {
local custom_path="${1:-}"
# Handle project-scoped installation
if [[ "$PROJECT_SCOPED" == true ]]; then
# Auto-detect project root if not specified
if [[ -z "$PROJECT_ROOT" ]]; then
if command_exists git && git rev-parse --show-toplevel &>/dev/null; then
PROJECT_ROOT=$(git rev-parse --show-toplevel)
log_info "Detected git repository at: $PROJECT_ROOT"
else
PROJECT_ROOT=$(pwd)
log_warn "Not in a git repository. Using current directory: $PROJECT_ROOT"
fi
fi
# Set project-scoped paths
CLAUDE_DIR="$PROJECT_ROOT/.claude"
PLUGINS_DIR="$CLAUDE_DIR/plugins"
INSTALL_PATH="$PLUGINS_DIR/blerbz-plugins"
SETTINGS_FILE="$CLAUDE_DIR/settings.json"
INSTALLED_PLUGINS_FILE="$PLUGINS_DIR/installed_plugins.json"
INSTALL_SCOPE="project"
log_info "Installing in PROJECT-SCOPED mode"
log_info " Project root: $PROJECT_ROOT"
log_info " Install path: $INSTALL_PATH"
return 0
fi
# Global installation (original behavior)
INSTALL_SCOPE="user"
# If running from cloned repo, use that location
if [[ -f "$SCRIPT_DIR/.claude-plugin/marketplace.json" ]]; then
INSTALL_PATH="$SCRIPT_DIR"
log_info "Using current directory as install path: $INSTALL_PATH"
return 0
fi
# Use custom path if provided
if [[ -n "$custom_path" ]]; then
INSTALL_PATH="$custom_path"
return 0
fi
# Ask user
echo ""
read -rp "Install path [$DEFAULT_INSTALL_PATH]: " INSTALL_PATH
INSTALL_PATH="${INSTALL_PATH:-$DEFAULT_INSTALL_PATH}"
# Expand ~ if present
INSTALL_PATH="${INSTALL_PATH/#\~/$HOME}"
}
setup_repository() {
log_step "Setting up repository..."
if [[ -d "$INSTALL_PATH" ]] && [[ -f "$INSTALL_PATH/.claude-plugin/marketplace.json" ]]; then
log_success "Repository already exists at $INSTALL_PATH"
if confirm "Update to latest version?"; then
if [[ -d "$INSTALL_PATH/.git" ]] && command_exists git; then
log_info "Pulling latest changes..."
(cd "$INSTALL_PATH" && git pull origin main 2>/dev/null || git pull origin master 2>/dev/null || true)
log_success "Repository updated"
else
log_warn "Not a git repository or git not available. Skipping update."
fi
fi
else
if command_exists git; then
log_info "Cloning repository to $INSTALL_PATH..."
git clone https://github.com/Blerbz/blerbz-plugins.git "$INSTALL_PATH"
log_success "Repository cloned"
else
log_error "Cannot clone repository without git."
log_info "Please manually copy the blerbz-plugins folder to: $INSTALL_PATH"
exit 1
fi
fi
}
create_directories() {
log_step "Creating directories..."
mkdir -p "$CLAUDE_DIR"
mkdir -p "$PLUGINS_DIR"
log_success "Directories created"
}
register_marketplace() {
# Skip marketplace registration for project-scoped installations
if [[ "$PROJECT_SCOPED" == true ]]; then
log_info "Skipping marketplace registration (project-scoped mode)"
return 0
fi
log_step "Registering marketplace..."
local timestamp
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
local marketplace_json
marketplace_json=$(cat << EOF
{
"blerbz-plugins": {
"source": {
"source": "directory",
"path": "$INSTALL_PATH"
},
"installLocation": "$INSTALL_PATH",
"lastUpdated": "$timestamp"
}
}
EOF
)
merge_json_objects "$MARKETPLACES_FILE" "$marketplace_json" "$MARKETPLACES_FILE"
log_success "Marketplace registered in $MARKETPLACES_FILE"
}
register_plugins() {
log_step "Registering plugins..."
local timestamp
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
# Use relative paths for project-scoped, absolute for global
local plugin_path_prefix
if [[ "$PROJECT_SCOPED" == true ]]; then
plugin_path_prefix="./.claude/plugins/blerbz-plugins"
else
plugin_path_prefix="$INSTALL_PATH"
fi
local plugins_json
plugins_json=$(cat << EOF
{
"version": 2,
"plugins": {
"inference-confidenz@blerbz-plugins": [
{
"scope": "$INSTALL_SCOPE",
"installPath": "$plugin_path_prefix/inference-confidenz",
"version": "1.0.0",
"installedAt": "$timestamp",
"lastUpdated": "$timestamp"
}
],
"inference-continuez@blerbz-plugins": [
{
"scope": "$INSTALL_SCOPE",
"installPath": "$plugin_path_prefix/inference-continuez",
"version": "1.0.0",
"installedAt": "$timestamp",
"lastUpdated": "$timestamp"
}
],
"inference-planz@blerbz-plugins": [
{
"scope": "$INSTALL_SCOPE",
"installPath": "$plugin_path_prefix/inference-planz",
"version": "1.0.0",
"installedAt": "$timestamp",
"lastUpdated": "$timestamp"
}
]
}
}
EOF
)
merge_installed_plugins "$INSTALLED_PLUGINS_FILE" "$plugins_json" "$INSTALLED_PLUGINS_FILE"
log_success "Plugins registered in $INSTALLED_PLUGINS_FILE"
}
enable_plugins() {
log_step "Enabling plugins..."
local enabled_json='{"inference-confidenz@blerbz-plugins": true, "inference-continuez@blerbz-plugins": true, "inference-planz@blerbz-plugins": true}'
merge_settings "$SETTINGS_FILE" "$enabled_json" "$SETTINGS_FILE"
log_success "Plugins enabled in $SETTINGS_FILE"
}
# ============================================================================
# Post-Installation
# ============================================================================
show_verification() {
log_step "Verifying installation..."
local all_good=true
# Check marketplace (global only - not used for project-scoped)
if [[ "$PROJECT_SCOPED" == false ]]; then
if [[ -f "$MARKETPLACES_FILE" ]] && grep -q "blerbz-plugins" "$MARKETPLACES_FILE" 2>/dev/null; then
log_success "Marketplace registered"
else
log_error "Marketplace not found in config"
all_good=false
fi
else
log_success "Project-scoped installation (marketplace not required)"
fi
# Check installed plugins
if [[ -f "$INSTALLED_PLUGINS_FILE" ]]; then
if grep -q "inference-confidenz@blerbz-plugins" "$INSTALLED_PLUGINS_FILE" 2>/dev/null; then
log_success "inference-confidenz registered"
else
log_warn "inference-confidenz not found in installed plugins"
all_good=false
fi
if grep -q "inference-continuez@blerbz-plugins" "$INSTALLED_PLUGINS_FILE" 2>/dev/null; then
log_success "inference-continuez registered"
else
log_warn "inference-continuez not found in installed plugins"
all_good=false
fi
if grep -q "inference-planz@blerbz-plugins" "$INSTALLED_PLUGINS_FILE" 2>/dev/null; then
log_success "inference-planz registered"
else
log_warn "inference-planz not found in installed plugins"
all_good=false
fi
else
log_error "Installed plugins file not found"
all_good=false
fi
# Check enabled
if [[ -f "$SETTINGS_FILE" ]] && grep -q '"inference-confidenz@blerbz-plugins": true' "$SETTINGS_FILE" 2>/dev/null; then
log_success "Plugins enabled in settings"
else
log_warn "Plugins may not be enabled in settings"
fi
echo ""
if [[ "$all_good" == true ]]; then
log_success "All checks passed!"
else
log_warn "Some checks failed. Review the output above."
fi
}
post_install_config() {
log_step "Post-Installation Configuration"
echo ""
echo -e "${BOLD}Configure auto-continue threshold?${NC}"
echo ""
echo "The Continuez threshold determines when Claude auto-proceeds vs asks you."
echo "Confidence scores (0-99%) are displayed automatically - no configuration needed."
echo ""
if confirm "Set auto-continue threshold?" "n"; then
echo ""
echo "Auto-Continue Threshold:"
echo " - Higher value = more conservative (asks more often)"
echo " - Lower value = more permissive (continues more often)"
echo " - Default: 70% | Conservative: 80-90%"
echo ""
read -rp "Threshold [default: 70]: " continuez_threshold
continuez_threshold="${continuez_threshold:-70}"
# Create continuez settings
local continuez_config_dir="$HOME/.config/inference-continuez"
mkdir -p "$continuez_config_dir"
cat > "$continuez_config_dir/settings.json" << EOF
{
"confidence_threshold": $continuez_threshold
}
EOF
log_success "Config created: $continuez_config_dir/settings.json"
# Optionally set environment variable
if confirm "Add threshold to shell profile (~/.zshrc or ~/.bashrc)?"; then
local profile_file="$HOME/.zshrc"
[[ ! -f "$profile_file" ]] && profile_file="$HOME/.bashrc"
if [[ -f "$profile_file" ]]; then
if ! grep -q "INFERENCE_CONTINUEZ_THRESHOLD" "$profile_file" 2>/dev/null; then
echo "" >> "$profile_file"
echo "# Inference Continuez threshold" >> "$profile_file"
echo "export INFERENCE_CONTINUEZ_THRESHOLD=$continuez_threshold" >> "$profile_file"
log_success "Added to $profile_file"
else
log_info "INFERENCE_CONTINUEZ_THRESHOLD already in $profile_file"
fi
fi
fi
fi
}
show_usage_guide() {
echo ""
echo -e "${CYAN}${BOLD}============================================================${NC}"
echo -e "${CYAN}${BOLD} Installation Complete!${NC}"
echo -e "${CYAN}${BOLD}============================================================${NC}"
echo ""
echo -e "${RED}${BOLD}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${RED}${BOLD}║ ║${NC}"
echo -e "${RED}${BOLD}║ ⚠️ ACTION REQUIRED: RESTART CLAUDE CODE NOW ║${NC}"
echo -e "${RED}${BOLD}║ ║${NC}"
echo -e "${RED}${BOLD}║ Plugins will NOT work until you restart! ║${NC}"
echo -e "${RED}${BOLD}║ Close your terminal and run 'claude' again. ║${NC}"
echo -e "${RED}${BOLD}║ ║${NC}"
echo -e "${RED}${BOLD}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${BOLD}Verification Commands (run in Claude Code after restart):${NC}"
echo " /inference-confidenz:status"
echo " /inference-continuez:continuez show"
echo " /inference-planz:status"
echo ""
echo -e "${BOLD}How It Works:${NC}"
echo ""
echo -e "${GREEN}Inference Confidenz${NC} - Shows confidence score on every response:"
echo " Your response from Claude..."
echo " ---"
echo " CZ 87%"
echo ""
echo " Score colors:"
echo " ${RED}Red${NC}: 0-32% (low confidence)"
echo " ${YELLOW}Yellow${NC}: 33-65% (medium confidence)"
echo " ${GREEN}Green${NC}: 66-99% (high confidence)"
echo ""
echo -e "${GREEN}Inference Continuez${NC} - Auto-continues based on confidence:"
echo " - Auto-proceeds when confidence >= threshold (default 70%)"
echo " - Asks you when confidence is lower or operation is risky"
echo ""
echo -e "${GREEN}Inference Planz${NC} - Multi-agent planning workflow:"
echo " - Research Agent: Analyzes intent and identifies unknowns"
echo " - Survey Agent: Generates interactive clarification questions"
echo " - Plan Agent: Creates production-grade implementation roadmap"
echo ""
echo -e "${BOLD}Quick Commands:${NC}"
echo " /inference-confidenz:help - Full documentation"
echo " /inference-confidenz:configure display minimal"
echo " /inference-continuez:confidence 85 - Set threshold to 85%"
echo " /inference-continuez:continuez disable - Disable auto-continue"
echo " /inference-planz:run <prompt> - Execute planning pipeline"
echo " /inference-planz:help - Show planz documentation"
echo ""
echo -e "${BOLD}Installation Paths:${NC}"
echo " Plugins: $INSTALL_PATH"
echo " Marketplace: $MARKETPLACES_FILE"
echo " Plugins DB: $INSTALLED_PLUGINS_FILE"
echo " Settings: $SETTINGS_FILE"
echo ""
echo -e "${BOLD}Need Help?${NC}"
echo " GitHub: https://github.com/Blerbz/blerbz-plugins/issues"
echo " Docs: https://github.com/Blerbz/blerbz-plugins#readme"
echo ""
echo -e "${GREEN}Happy coding with confidence!${NC}"
echo ""
echo -e "${YELLOW}${BOLD}Remember: Restart Claude Code now to activate plugins!${NC}"
echo ""
}
# ============================================================================
# Main
# ============================================================================
main() {
echo ""
echo -e "${CYAN}${BOLD}============================================================${NC}"
echo -e "${CYAN}${BOLD} Blerbz Plugins - Quickstart Setup v$VERSION${NC}"
echo -e "${CYAN}${BOLD}============================================================${NC}"
echo ""
# Parse arguments
local custom_install_path=""
while [[ $# -gt 0 ]]; do
case $1 in
--project)
PROJECT_SCOPED=true
shift
;;
--project-root)
PROJECT_ROOT="$2"
PROJECT_SCOPED=true
shift 2
;;
--global)
PROJECT_SCOPED=false
shift
;;
--install-path)
custom_install_path="$2"
shift 2
;;
--help|-h)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Installation Modes:"
echo " --project Install in project-scoped mode (.claude/plugins/)"
echo " --project-root DIR Specify project root directory (implies --project)"
echo " --global Install in global mode ~/.claude/plugins/ (default)"
echo ""
echo "Other Options:"
echo " --install-path DIR Custom installation path (global mode only)"
echo " --help, -h Show this help message"
echo ""
echo "Examples:"
echo " $0 # Global installation"
echo " $0 --project # Project-scoped (auto-detect git root)"
echo " $0 --project-root /path/to/project # Project-scoped with explicit root"
exit 0
;;
*)
log_error "Unknown option: $1"
exit 1
;;
esac
done
# Run installation steps
check_prerequisites
determine_install_path "$custom_install_path"
setup_repository
create_directories
register_marketplace
register_plugins
enable_plugins
show_verification
# Post-installation configuration
post_install_config
# Show usage guide
show_usage_guide
}
main "$@"