-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·261 lines (221 loc) · 10.4 KB
/
start.sh
File metadata and controls
executable file
·261 lines (221 loc) · 10.4 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
#!/bin/bash
# ═══════════════════════════════════════════════════════════════════════════════
# 🚀 Agentists QuickStart - Batteries Included Launcher
# ═══════════════════════════════════════════════════════════════════════════════
# This script initializes claude-flow and launches Claude Code in a tmux session
# with proper configuration and error handling.
# ═══════════════════════════════════════════════════════════════════════════════
set -e
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# Phonetic alphabet for tmux sessions
PHONETIC_NAMES=("alpha" "bravo" "charlie" "delta" "echo" "foxtrot" "golf" "hotel" "india" "juliet" "kilo" "lima" "mike" "november" "oscar" "papa" "quebec" "romeo" "sierra" "tango" "uniform" "victor" "whiskey" "xray" "yankee" "zulu")
# Function to print colored messages
print_message() {
local color=$1
local message=$2
echo -e "${color}${message}${NC}"
}
# Function to print section headers
print_header() {
local header=$1
echo ""
echo -e "${CYAN}╔══════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║${NC} ${BOLD}${header}${NC}"
echo -e "${CYAN}╚══════════════════════════════════════════════════════════════════════╝${NC}"
echo ""
}
# Function to print error messages and exit
error_exit() {
local message=$1
print_message "$RED" "❌ ERROR: $message"
echo ""
print_message "$YELLOW" "💡 Troubleshooting tips:"
echo " 1. Ensure all required tools are installed by running: .devcontainer/install-tools.sh"
echo " 2. Check the installation report: cat .devcontainer/installation-report.md"
echo " 3. Verify Node.js and npm are available: node --version && npm --version"
echo " 4. For tmux issues, try: sudo apt-get install tmux"
echo ""
exit 1
}
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to find next available tmux session name
find_tmux_session() {
for name in "${PHONETIC_NAMES[@]}"; do
if ! tmux has-session -t "$name" 2>/dev/null; then
echo "$name"
return 0
fi
done
# If all phonetic names are taken, use a timestamp
echo "session-$(date +%s)"
return 0
}
# ═══════════════════════════════════════════════════════════════════════════════
# MAIN SCRIPT START
# ═══════════════════════════════════════════════════════════════════════════════
print_header "🚀 Agentists QuickStart - Batteries Included"
# Step 1: Check prerequisites
print_message "$BLUE" "📋 Checking prerequisites..."
# Check for Node.js
if ! command_exists node; then
error_exit "Node.js is not installed. Please install Node.js first."
fi
# Check for npm
if ! command_exists npm; then
error_exit "npm is not installed. Please install npm first."
fi
# Check for tmux
if ! command_exists tmux; then
print_message "$YELLOW" "⚠️ tmux is not installed. Attempting to install..."
if command_exists apt-get; then
if sudo apt-get install -y tmux >/dev/null 2>&1; then
print_message "$GREEN" "✅ tmux installed successfully"
else
error_exit "Failed to install tmux. Please install it manually: sudo apt-get install tmux"
fi
else
error_exit "tmux is not installed and automatic installation is not available on this system."
fi
fi
# Check for claude command (Claude Code)
if ! command_exists claude; then
print_message "$YELLOW" "⚠️ Claude Code is not installed. Attempting to install..."
if npm install -g @anthropic-ai/claude-code 2>/dev/null || sudo npm install -g @anthropic-ai/claude-code 2>/dev/null; then
print_message "$GREEN" "✅ Claude Code installed successfully"
else
error_exit "Failed to install Claude Code. Please install it manually: npm install -g @anthropic-ai/claude-code"
fi
fi
# Check for claude-flow
if ! command_exists claude-flow; then
print_message "$YELLOW" "⚠️ claude-flow is not installed. Attempting to install..."
if npm install -g claude-flow@alpha 2>/dev/null || sudo npm install -g claude-flow@alpha 2>/dev/null; then
print_message "$GREEN" "✅ claude-flow installed successfully"
else
error_exit "Failed to install claude-flow. Please install it manually: npm install -g claude-flow@alpha"
fi
fi
print_message "$GREEN" "✅ All prerequisites are installed"
# Step 2: Initialize claude-flow
print_header "🌊 Claude Flow Initialization"
print_message "$CYAN" "Would you like to force reinitialize claude-flow?"
print_message "$CYAN" "This will overwrite any existing configuration."
echo ""
echo "Options:"
echo " [y/Y] - Initialize with --force (overwrites existing config)"
echo " [n/N] - Initialize normally (preserves existing config)"
echo " [s/S] - Skip initialization"
echo ""
read -p "Your choice [y/n/s]: " -n 1 -r
echo ""
INIT_SUCCESS=false
case "$REPLY" in
[yY])
print_message "$BLUE" "🔧 Initializing claude-flow with --force..."
if claude-flow init --force 2>/dev/null; then
print_message "$GREEN" "✅ claude-flow initialized successfully (forced)"
INIT_SUCCESS=true
else
print_message "$YELLOW" "⚠️ claude-flow initialization failed. This may be okay if it's already configured."
fi
;;
[nN])
print_message "$BLUE" "🔧 Initializing claude-flow..."
if claude-flow init 2>/dev/null; then
print_message "$GREEN" "✅ claude-flow initialized successfully"
INIT_SUCCESS=true
else
print_message "$YELLOW" "⚠️ claude-flow initialization failed. This may be okay if it's already configured."
fi
;;
[sS])
print_message "$YELLOW" "⏭️ Skipping claude-flow initialization"
;;
*)
print_message "$YELLOW" "⚠️ Invalid choice. Skipping initialization."
;;
esac
# Step 3: Check for .mcp.json configuration
print_header "📦 MCP Configuration Check"
MCP_CONFIG_PATH="${WORKSPACE_FOLDER:-$(pwd)}/.mcp.json"
MCP_CONFIG_EXISTS=false
if [ -f "$MCP_CONFIG_PATH" ]; then
print_message "$GREEN" "✅ Found .mcp.json configuration at: $MCP_CONFIG_PATH"
MCP_CONFIG_EXISTS=true
else
print_message "$YELLOW" "⚠️ No .mcp.json configuration found at: $MCP_CONFIG_PATH"
print_message "$BLUE" "💡 Claude Code will run without MCP configuration"
fi
# Step 4: Create tmux session
print_header "🖥️ Tmux Session Management"
# Find available session name
SESSION_NAME=$(find_tmux_session)
print_message "$BLUE" "🔍 Selected tmux session name: ${BOLD}$SESSION_NAME${NC}"
# Check if session already exists (shouldn't happen due to find_tmux_session, but double-check)
if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
print_message "$YELLOW" "⚠️ Session '$SESSION_NAME' already exists. Attaching to it..."
tmux attach-session -t "$SESSION_NAME"
exit 0
fi
# Step 5: Launch Claude Code in tmux
print_header "🚀 Launching Claude Code"
print_message "$BLUE" "📝 Creating tmux session: $SESSION_NAME"
# Prepare the Claude Code command
if [ "$MCP_CONFIG_EXISTS" = true ]; then
CLAUDE_CMD="claude --dangerously-skip-permissions --mcp-config $MCP_CONFIG_PATH"
print_message "$GREEN" "✅ Launching Claude Code with MCP configuration"
else
CLAUDE_CMD="claude --dangerously-skip-permissions"
print_message "$YELLOW" "⚠️ Launching Claude Code without MCP configuration"
fi
# Create tmux session and run Claude Code
if tmux new-session -d -s "$SESSION_NAME" "$CLAUDE_CMD" 2>/dev/null; then
print_message "$GREEN" "✅ Claude Code launched successfully in tmux session: $SESSION_NAME"
echo ""
print_header "📌 Session Information"
echo -e "${GREEN}Session created successfully!${NC}"
echo ""
echo "📋 Tmux Commands Reference:"
echo " • Attach to session: ${CYAN}tmux attach -t $SESSION_NAME${NC}"
echo " • Detach from session: ${CYAN}Ctrl+b, then d${NC}"
echo " • List sessions: ${CYAN}tmux ls${NC}"
echo " • Kill session: ${CYAN}tmux kill-session -t $SESSION_NAME${NC}"
echo " • Switch windows: ${CYAN}Ctrl+b, then n (next) or p (previous)${NC}"
echo " • Create new window: ${CYAN}Ctrl+b, then c${NC}"
echo ""
# Ask if user wants to attach immediately - FIXED FORMATTING
echo -e "${CYAN}Would you like to attach to the session now? [y/N]: ${NC}"
read -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_message "$BLUE" "🔗 Attaching to session..."
tmux attach-session -t "$SESSION_NAME"
else
print_message "$GREEN" "✨ Session is running in the background."
print_message "$CYAN" " To attach later, run: ${BOLD}tmux attach -t $SESSION_NAME${NC}"
fi
else
error_exit "Failed to create tmux session. Please check tmux installation and permissions."
fi
# Step 6: Success message
echo ""
print_header "✅ Setup Complete!"
print_message "$GREEN" "🎉 Your Batteries-Included development environment is ready!"
echo ""
echo "Resources:"
echo " • Claude Flow Docs: https://github.com/ruvnet/claude-flow"
echo " • Claude Code Docs: https://docs.anthropic.com/en/docs/claude-code"
echo " • Report Issues: https://github.com/jedarden/agentists-quickstart/issues"
echo ""
print_message "$CYAN" "Happy coding! 🚀"