forked from wildwasser/opencode-agents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·298 lines (256 loc) · 8.89 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·298 lines (256 loc) · 8.89 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
#!/bin/bash
# OpenCode Agents Installer
# Copies agent .md files and generates opencode.json from agents.json
set -e
# OS Detection
OS="Unknown"
IS_WSL=false
case "$(uname -s)" in
Linux)
if [ -f /proc/sys/fs/binfmt_misc/WSLInterop ] || [ -n "$WSL_DISTRO_NAME" ]; then
OS="WSL"
IS_WSL=true
echo "→ WSL (Windows Subsystem for Linux) detected"
else
OS="Linux"
echo "→ Linux detected"
fi
;;
Darwin)
OS="macOS"
echo "→ macOS detected — native Unix support"
;;
MSYS_NT-*|MINGW*|CYGWIN*)
OS="GitBash"
echo "⚠ Git Bash/MSYS2 detected — this script is designed for Linux/macOS/WSL"
echo " For native Windows, use: .\install.ps1"
echo " Continuing anyway (may work if python3 is available)..."
;;
*)
echo "⚠ Unknown OS: $(uname -s) — proceeding with Unix defaults"
OS="Unknown"
;;
esac
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_DIR="$SCRIPT_DIR/.opencode/agent"
TARGET_DIR="$HOME/.config/opencode/agent"
echo "OpenCode Agents Installer"
echo "========================="
echo ""
# Check source exists
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: Source directory not found: $SOURCE_DIR"
exit 1
fi
# ─── Tech Stack Selection ──────────────────────────────────────
if [ -n "$STACK" ]; then
case "$STACK" in
python|typescript)
echo "→ Stack pre-selected via STACK env var: $STACK"
STACK_CHOICE="$STACK"
;;
*)
echo "Error: Invalid STACK value '$STACK'. Must be 'python' or 'typescript'."
exit 1
;;
esac
else
echo "Select tech stack:"
echo " 1) Python"
echo " 2) TypeScript"
echo " 3) PHP"
read -p "Enter choice (1 or 2 or 3): " STACK_CHOICE
case "$STACK_CHOICE" in
1|python|Python)
STACK_CHOICE="python"
;;
2|typescript|TypeScript|ts|TS)
STACK_CHOICE="typescript"
;;
3|php|PHP)
STACK_CHOICE="php"
;;
*)
echo "Invalid choice. Please select 1, 2, or 3."
exit 1
;;
esac
fi
case "$STACK_CHOICE" in
python) STACK="python"
STACK_NAME="Python"
;;
typescript) STACK="typescript"
STACK_NAME="TypeScript"
;;
php) STACK="php"
STACK_NAME="PHP"
;;
esac
# ─── QA Engineer Agent ─────────────────────────────────────────
if [ -n "$WITH_QA" ]; then
case "$(echo "$WITH_QA" | tr '[:upper:]' '[:lower:]')" in
true|1|yes|y)
INCLUDE_QA="y"
echo "→ QA agent pre-selected via WITH_QA env var: yes"
;;
false|0|no|n)
INCLUDE_QA="n"
echo "→ QA agent pre-selected via WITH_QA env var: no"
;;
*)
echo "Error: Invalid WITH_QA value '$WITH_QA'. Use true/false, yes/no, 1/0."
exit 1
;;
esac
else
read -p "Include QA Engineer/Documenter in the team? (y/N): " -n 1 -r QA_CHOICE
echo ""
if [[ $QA_CHOICE =~ ^[Yy]$ ]]; then
INCLUDE_QA="y"
else
INCLUDE_QA="n"
fi
fi
if [ "$INCLUDE_QA" = "y" ]; then
WITH_QA=true
else
WITH_QA=false
fi
STACK_SRC="$SOURCE_DIR/$STACK"
if [ ! -d "$STACK_SRC" ]; then
echo "Error: Stack source directory not found: $STACK_SRC"
exit 1
fi
echo "Installing $STACK_NAME agents..."
echo ""
# Create target directory
mkdir -p "$TARGET_DIR"
# ──────────────────────────────────────────────
# 1. Copy agent .md files
# ──────────────────────────────────────────────
# Copy base agent files (top-level .md only, skip with-qa/)
for agent in "$STACK_SRC"/*.md; do
if [ -f "$agent" ]; then
AGENT_NAME="$(basename "$agent")"
cp "$agent" "$TARGET_DIR/$AGENT_NAME"
echo " ✓ $AGENT_NAME"
fi
done
# If QA selected, overwrite with with-qa variants
if [ "$WITH_QA" = true ]; then
WITH_QA_DIR="$STACK_SRC/with-qa"
if [ -d "$WITH_QA_DIR" ]; then
echo ""
echo " Applying with-qa variants:"
for variant in "$WITH_QA_DIR"/*.md; do
if [ -f "$variant" ]; then
VARIANT_NAME="$(basename "$variant")"
cp "$variant" "$TARGET_DIR/$VARIANT_NAME"
echo " ✓ $VARIANT_NAME (with-qa)"
fi
done
else
echo " ⚠ Warning: with-qa directory not found: $WITH_QA_DIR"
fi
fi
echo ""
# ──────────────────────────────────────────────
# 2. Copy skills
# ──────────────────────────────────────────────
SKILLS_SRC="$SCRIPT_DIR/.opencode/skills"
SKILLS_TARGET="$HOME/.config/opencode/skills"
if [ -d "$SKILLS_SRC" ]; then
echo "Copying skills..."
mkdir -p "$SKILLS_TARGET"
cp -r "$SKILLS_SRC"/* "$SKILLS_TARGET/"
echo " ✓ Skills installed ($(ls -d "$SKILLS_SRC"/*/ 2>/dev/null | wc -l) skill directories)"
echo ""
fi
# ──────────────────────────────────────────────
# 3. Generate opencode.json from template + agents.json
# ──────────────────────────────────────────────
AGENTS_JSON="$STACK_SRC/agents.json"
TEMPLATE_JSON="$SCRIPT_DIR/opencode.json.example"
if [ ! -f "$AGENTS_JSON" ]; then
echo "⚠ Warning: agents.json not found at $AGENTS_JSON"
echo " Skipping opencode.json generation."
else
read -p "Generate opencode.json from template? (Y/n): " -n 1 -r GEN_CHOICE
echo ""
if [[ ! $GEN_CHOICE =~ ^[Nn]$ ]]; then
if [ -f "$TEMPLATE_JSON" ]; then
echo "Generating opencode.json..."
# Use python3 to merge agents.json into opencode.json.example
python3 -c "
import json
# Read template
with open('$TEMPLATE_JSON') as f:
config = json.load(f)
# Read agents
with open('$AGENTS_JSON') as f:
agents = json.load(f)
# Filter out QA agents if not selected
WITH_QA = $WITH_QA
if not WITH_QA:
# Python QA agent is 'marco' (but only when marco is QA, not truth-teller)
# TypeScript QA agent is 'quill'
qa_agents = {'quill'}
if '$STACK' == 'python':
# In Python stack, 'marco' is the QA engineer — remove it
qa_agents.add('marco')
agents = {k: v for k, v in agents.items() if k not in qa_agents}
# Merge agents into template
config['agent'] = agents
# Set default_agent based on stack
if '$STACK' == 'python':
config['default_agent'] = 'oscar'
else:
config['default_agent'] = 'ostype'
# Write to target
target = '$HOME/.config/opencode/opencode.json'
with open(target, 'w') as f:
json.dump(config, f, indent=2)
f.write('\n')
print(' ✓ opencode.json generated at', target)
print(' ✓ Agents registered:', ', '.join(agents.keys()))
"
else
echo "⚠ Warning: template not found at $TEMPLATE_JSON"
fi
else
echo "Skipping opencode.json generation."
fi
fi
# ─── AGENTS.md Configuration ──────────────────────────────────
echo ""
echo "Configuring AGENTS.md for $STACK_NAME stack..."
if [ -f "$SCRIPT_DIR/AGENTS.$STACK.md" ]; then
cp "$SCRIPT_DIR/AGENTS.$STACK.md" "$SCRIPT_DIR/AGENTS.md"
echo " ✓ AGENTS.md generated from AGENTS.$STACK.md"
else
echo " ⚠ Warning: AGENTS.$STACK.md not found — skipping AGENTS.md generation"
fi
# ──────────────────────────────────────────────
# 4. Summary
# ──────────────────────────────────────────────
echo ""
echo "=============================================="
echo " Installation Complete"
echo "=============================================="
echo ""
echo "Stack: $STACK_NAME"
echo "QA Engineer: $([ "$WITH_QA" = "true" ] && echo 'Yes' || echo 'No')"
echo "Target: $TARGET_DIR"
echo ""
echo "Installed agents:"
for agent in "$TARGET_DIR"/*.md; do
if [ -f "$agent" ]; then
echo " - $(basename "$agent" .md)"
fi
done
echo ""
echo "Next steps:"
echo " 1. Verify ~/.config/opencode/opencode.json has the correct agents"
echo " 2. Set your ZEN_API_KEY environment variable"
echo " 3. Run 'opencode' to start!"