-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·264 lines (222 loc) · 7.01 KB
/
setup.sh
File metadata and controls
executable file
·264 lines (222 loc) · 7.01 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
#!/bin/bash
# Setup script for AI coding agents integration
# This script helps configure your environment for using multiple AI coding agents
set -e
echo "🤖 AI Coding Agents Setup"
echo "=========================="
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_success() {
echo -e "${GREEN}✓${NC} $1"
}
print_error() {
echo -e "${RED}✗${NC} $1"
}
print_warning() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_info() {
echo -e "ℹ $1"
}
# Check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# 1. Check prerequisites
echo "Checking prerequisites..."
echo ""
# Check Python
if command_exists python3; then
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2)
print_success "Python 3 installed: $PYTHON_VERSION"
else
print_error "Python 3 not found. Please install Python 3.9 or higher."
exit 1
fi
# Check Node.js
if command_exists node; then
NODE_VERSION=$(node --version)
print_success "Node.js installed: $NODE_VERSION"
else
print_warning "Node.js not found. TypeScript examples will not work."
fi
# Check npm
if command_exists npm; then
NPM_VERSION=$(npm --version)
print_success "npm installed: $NPM_VERSION"
else
print_warning "npm not found. TypeScript examples will not work."
fi
# Check gh CLI
if command_exists gh; then
GH_VERSION=$(gh --version | head -n1)
print_success "GitHub CLI installed: $GH_VERSION"
else
print_warning "GitHub CLI not found. Installing is recommended for Copilot CLI."
print_info "Install with: brew install gh (macOS) or sudo apt install gh (Linux)"
fi
echo ""
# 2. Setup environment file
echo "Setting up environment configuration..."
echo ""
if [ -f .env ]; then
print_warning ".env file already exists. Skipping creation."
print_info "If you want to reset it, delete .env and run this script again."
else
if [ -f .env.template ]; then
cp .env.template .env
print_success "Created .env file from template"
print_info "Please edit .env and add your API keys"
else
print_error ".env.template not found"
exit 1
fi
fi
echo ""
# 3. Install Python dependencies
echo "Installing Python dependencies..."
echo ""
if [ -f .github/agents/requirements.txt ]; then
if command_exists pip3; then
pip3 install -r .github/agents/requirements.txt
print_success "Python dependencies installed"
else
print_error "pip3 not found"
exit 1
fi
else
print_error "requirements.txt not found"
exit 1
fi
echo ""
# 4. Install Node.js dependencies (optional)
if command_exists npm && [ -f .github/agents/package.json ]; then
echo "Installing Node.js dependencies..."
echo ""
# Save current directory
ORIGINAL_DIR=$(pwd)
if cd .github/agents; then
npm install || {
print_error "npm install failed"
cd "$ORIGINAL_DIR" || exit 1
exit 1
}
cd "$ORIGINAL_DIR" || exit 1
print_success "Node.js dependencies installed"
else
print_error "Failed to change to .github/agents directory"
exit 1
fi
echo ""
fi
# 5. Install GitHub Copilot CLI (optional)
if command_exists gh; then
echo "Checking GitHub Copilot CLI extension..."
echo ""
if gh extension list | grep -q "github/gh-copilot"; then
print_success "GitHub Copilot CLI extension already installed"
else
print_info "Installing GitHub Copilot CLI extension..."
gh extension install github/gh-copilot
print_success "GitHub Copilot CLI extension installed"
fi
echo ""
fi
# 6. Verify API keys
echo "Verifying API key configuration..."
echo ""
if [ -f .env ]; then
# Safely source .env file with proper quote handling
while IFS= read -r line; do
# Skip comments and empty lines
[[ "$line" =~ ^[[:space:]]*#.*$ || -z "$line" ]] && continue
# Extract key and value (handles quotes properly)
if [[ "$line" =~ ^([A-Z_][A-Z0-9_]*)=(.*)$ ]]; then
key="${BASH_REMATCH[1]}"
value="${BASH_REMATCH[2]}"
# Remove surrounding quotes if present
value="${value%\"}"
value="${value#\"}"
value="${value%\'}"
value="${value#\'}"
# Only export if key is valid
if [[ "$key" =~ ^(OPENAI_API_KEY|ANTHROPIC_API_KEY|GOOGLE_API_KEY|OPENAI_ORG_ID|GOOGLE_PROJECT_ID|OPENAI_MODEL|ANTHROPIC_MODEL|GOOGLE_MODEL|MAX_TOKENS_PER_REQUEST|MAX_REQUESTS_PER_MINUTE|DAILY_BUDGET_USD)$ ]]; then
export "$key=$value"
fi
fi
done < .env
# Check OpenAI key
if [ -n "$OPENAI_API_KEY" ] && [ "$OPENAI_API_KEY" != "sk-..." ]; then
print_success "OpenAI API key configured"
else
print_warning "OpenAI API key not configured"
fi
# Check Anthropic key
if [ -n "$ANTHROPIC_API_KEY" ] && [ "$ANTHROPIC_API_KEY" != "sk-ant-..." ]; then
print_success "Anthropic API key configured"
else
print_warning "Anthropic API key not configured"
fi
# Check Google key
if [ -n "$GOOGLE_API_KEY" ] && [ "$GOOGLE_API_KEY" != "AIza..." ]; then
print_success "Google API key configured"
else
print_warning "Google API key not configured"
fi
fi
echo ""
# 7. Make CLI examples executable
echo "Setting up CLI examples..."
echo ""
if [ -f .github/agents/cli-example.py ]; then
chmod +x .github/agents/cli-example.py
print_success "Python CLI example is executable"
fi
echo ""
# 8. Test installation (optional)
echo "Testing installation..."
echo ""
read -p "Do you want to run a test with configured API keys? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
if [ -f .github/agents/cli-example.py ]; then
print_info "Testing Python CLI..."
python3 .github/agents/cli-example.py --agent openai --prompt "Write a hello world function" 2>&1
print_success "Test completed (check output above)"
fi
fi
echo ""
# 9. Final instructions
echo "=========================="
echo "✅ Setup Complete!"
echo "=========================="
echo ""
echo "Next steps:"
echo ""
echo "1. Edit .env and add your API keys if you haven't already:"
echo " - OpenAI: https://platform.openai.com/api-keys"
echo " - Anthropic: https://console.anthropic.com/settings/keys"
echo " - Google: https://makersuite.google.com/app/apikey"
echo ""
echo "2. Read the documentation:"
echo " - README.md for overview"
echo " - .github/agents/README.md for detailed guide"
echo " - .github/agents/BEST_PRACTICES.md for best practices"
echo ""
echo "3. Try the CLI examples:"
echo " python3 .github/agents/cli-example.py --help"
if command_exists npx; then
echo " npx ts-node .github/agents/cli-example.ts --help"
fi
if command_exists gh; then
echo " gh copilot suggest \"your prompt\""
fi
echo ""
echo "4. Configure your IDE with Copilot"
echo ""
print_success "Happy coding with AI assistants! 🚀"