-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·317 lines (270 loc) · 11.7 KB
/
install.sh
File metadata and controls
executable file
·317 lines (270 loc) · 11.7 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
#!/usr/bin/env bash
set -euo pipefail
# ForLoop Plugin Installer
# https://github.com/forloop-cc/forloop-opencode-plugin-planner
#
# Adds the plugin to opencode.json. opencode handles downloading/caching.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/forloop-cc/forloop-opencode-plugin-planner/main/install.sh | bash
# curl -fsSL ... | bash -s -- --global
# bash install.sh --global --npm # Install via npm package
# bash install.sh --local # Install for current project only
# ── Platform & colors ────────────────────────────────────────────────────────
PLATFORM="$(uname -s)"
case "$PLATFORM" in
Darwin*) PLATFORM_LABEL="macOS";;
Linux*) PLATFORM_LABEL="Linux";;
CYGWIN*|MINGW*|MSYS*) PLATFORM_LABEL="Windows";;
*) PLATFORM_LABEL="Unknown";;
esac
if [ "$PLATFORM_LABEL" = "Windows" ] && [ -z "$WT_SESSION" ] && [ -z "$ConEmuPID" ]; then
RED=''; GREEN=''; YELLOW=''; BLUE=''; CYAN=''; BOLD=''; NC=''
else
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
BLUE='\033[0;34m'; CYAN='\033[0;36m'; BOLD='\033[1m'; NC='\033[0m'
fi
# ── Configuration ────────────────────────────────────────────────────────────
NPM_PACKAGE="@forloop-cc/forloop-opencode-plugin-planner"
GIT_URL="forloop-planner@git+https://github.com/forloop-cc/forloop-opencode-plugin-planner.git"
AGENTS_SKILLS_REPO="https://github.com/forloop-cc/forloop-agents-skills.git"
AGENTS_SKILLS_DIR="$HOME/.config/forloop/agents-skills"
INSTALL_TYPE="" # global | local
USE_NPM=false
SKIP_AGENTS=false
NON_INTERACTIVE=false
PROJECT_ROOT="$(pwd)"
print_header() { echo -e "${BLUE}${BOLD}╔══════════════════════════════════════════╗\n║ ForLoop Plugin Installer ║\n╚══════════════════════════════════════════╝${NC}\n"; }
print_success() { echo -e "${GREEN}✓${NC} $1"; }
print_info() { echo -e "${BLUE}ℹ${NC} $1"; }
print_warning() { echo -e "${YELLOW}⚠${NC} $1"; }
print_error() { echo -e "${RED}✗${NC} $1" >&2; }
print_step() { echo -e "\n${CYAN}${BOLD}▶${NC} $1\n"; }
show_help() {
cat << 'HELPEOF'
Usage: install.sh [OPTIONS]
Adds the ForLoop Plugin to your opencode configuration. opencode handles
downloading and caching the plugin on next startup. Also installs agents
and skills from forloop-agents-skills.
Options:
-g, --global Install globally (~/.config/opencode/opencode.json)
-l, --local Install for current project only (./opencode.json)
-n, --npm Use npm package (default: git URL from GitHub)
--skip-agents Skip installing agents and skills
-h, --help Show this help
Examples:
curl -fsSL .../install.sh | bash # Interactive (local by default)
curl -fsSL .../install.sh | bash -s -- -g # Global, non-interactive
bash install.sh --global --npm # Global via npm package
HELPEOF
}
# ── Dependency checks ────────────────────────────────────────────────────────
check_jq() {
if ! command -v jq &>/dev/null; then
print_error "jq is required for config merging"
case "$PLATFORM_LABEL" in
macOS) echo " brew install jq" ;;
Linux) echo " sudo apt-get install jq (Ubuntu/Debian)"
echo " sudo dnf install jq (Fedora/RHEL)" ;;
Windows) echo " scoop install jq or https://stedolan.github.io/jq/download/" ;;
esac
return 1
fi
return 0
}
check_opencode() {
if command -v opencode &>/dev/null; then
print_success "opencode found: $(which opencode)"
else
print_warning "opencode CLI not found"
echo " Install: curl -fsSL https://opencode.ai/install.sh | bash"
if [ "$NON_INTERACTIVE" != true ]; then
read -p "Continue anyway? [y/N] " -r; echo
[[ ! $REPLY =~ ^[Yy]$ ]] && exit 1
fi
fi
}
check_all_deps() {
print_step "Checking dependencies..."
check_jq || exit 1
check_opencode
}
# ── Install location ─────────────────────────────────────────────────────────
get_config_file() {
if [ "$INSTALL_TYPE" = "global" ]; then
mkdir -p "$HOME/.config/opencode"
echo "$HOME/.config/opencode/opencode.json"
else
echo "$PROJECT_ROOT/opencode.json"
fi
}
# ── Plugin entry selection ───────────────────────────────────────────────────
get_plugin_entry() {
if [ "$USE_NPM" = true ]; then
echo "$NPM_PACKAGE"
else
echo "$GIT_URL"
fi
}
# ── Config merging ───────────────────────────────────────────────────────────
merge_plugin_into_config() {
local config_file
config_file="$(get_config_file)"
local plugin_entry
plugin_entry="$(get_plugin_entry)"
print_step "Updating opencode configuration..."
if [ ! -f "$config_file" ]; then
echo "{}" > "$config_file"
fi
local backup="${config_file}.backup.$(date +%Y%m%d%H%M%S)"
cp "$config_file" "$backup"
local tmp
tmp="$(mktemp)"
jq --arg p "$plugin_entry" '
if .plugin then
.plugin += [$p] | .plugin |= unique
else
. + {"plugin": [$p]}
end
' "$config_file" > "$tmp"
if [ -s "$tmp" ]; then
mv "$tmp" "$config_file"
print_success "Plugin registered in: $config_file"
print_info "Backup saved: $backup"
else
print_error "Config merge produced empty file — restoring backup"
mv "$backup" "$config_file"
rm -f "$tmp"
exit 1
fi
}
# ── Agents & skills setup ────────────────────────────────────────────────────
setup_agents_skills() {
print_step "Setting up agents and skills..."
if [ ! -d "$AGENTS_SKILLS_DIR" ]; then
print_info "Cloning forloop-agents-skills..."
if ! git clone --depth 1 "https://github.com/forloop-cc/forloop-agents-skills.git" "$AGENTS_SKILLS_DIR" 2>&1; then
print_warning "Could not clone agents-skills repo (may not be public yet)"
return
fi
else
print_info "Updating forloop-agents-skills..."
cd "$AGENTS_SKILLS_DIR" && git pull origin main 2>/dev/null && cd - > /dev/null || true
fi
local config_dir
if [ "$INSTALL_TYPE" = "global" ]; then
config_dir="$HOME/.config/opencode"
else
config_dir="$PROJECT_ROOT/.opencode"
fi
local agents_dir="$config_dir/agents"
local skills_dir="$config_dir/skills"
mkdir -p "$agents_dir" "$skills_dir"
for agent_file in "$AGENTS_SKILLS_DIR/agents/"*.md; do
[ -f "$agent_file" ] || continue
local name
name="$(basename "$agent_file")"
ln -sf "$agent_file" "$agents_dir/$name"
print_success "Agent linked: $name"
done
for skill_dir in "$AGENTS_SKILLS_DIR/skills/"*/; do
[ -d "$skill_dir" ] || continue
local name
name="$(basename "$skill_dir")"
ln -sfn "$skill_dir" "$skills_dir/$name"
print_success "Skill linked: $name"
done
}
# ── Token setup ──────────────────────────────────────────────────────────────
setup_token() {
echo ""
print_step "Setting up API token..."
echo " Create a token at: https://forloop.cc/profile?tab=api-tokens"
echo " Scopes needed: sprint:read, sprint:write, story:read, story:write, agent:query, profile:read"
echo ""
if [ "$NON_INTERACTIVE" = true ]; then
print_info "Non-interactive mode — set your token later:"
echo " Start opencode, switch to the ForLoop Planner agent, and say 'set my API token'"
return
fi
read -p "Have you created a token? [y/N] " -r; echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_info "Set it later: start opencode, switch to the ForLoop Planner agent, and say 'set my API token'"
return
fi
local TOKEN
read -p "Enter your token: " -s TOKEN; echo
if [ -z "$TOKEN" ]; then
print_info "No token entered, skipping"
return
fi
local token_dir="$HOME/.config/forloop"
mkdir -p "$token_dir"
jq -n --arg token "$TOKEN" --arg ts "$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")" '
{version: "1.0", note: "ForLoop API tokens — do not share", default: $token, lastUpdated: $ts}
' > "$token_dir/tokens.json"
chmod 600 "$token_dir/tokens.json"
print_success "Token saved to: $token_dir/tokens.json"
}
# ── Summary ──────────────────────────────────────────────────────────────────
show_summary() {
local entry
entry="$(get_plugin_entry)"
echo ""
echo -e "${GREEN}${BOLD}========================================${NC}"
echo -e "${GREEN}${BOLD} Installation Complete!${NC}"
echo -e "${GREEN}${BOLD}========================================${NC}"
echo ""
echo " Type: $INSTALL_TYPE"
echo " Source: $entry"
echo ""
echo " Next steps:"
echo " 1. Start opencode: opencode"
echo " 2. Press TAB to switch to the ForLoop Planner agent"
echo " 3. Say: \"List my sprints\" or \"Create a story for login\""
echo ""
echo " Docs: https://github.com/forloop-cc/forloop-opencode-plugin-planner"
echo ""
}
# ── Main ─────────────────────────────────────────────────────────────────────
# Parse CLI flags
while [[ $# -gt 0 ]]; do
case "$1" in
-g|--global) INSTALL_TYPE="global"; shift ;;
-l|--local) INSTALL_TYPE="local"; shift ;;
-n|--npm) USE_NPM=true; shift ;;
--skip-agents) SKIP_AGENTS=true; shift ;;
-h|--help) show_help; exit 0 ;;
*) print_error "Unknown option: $1"; show_help; exit 1 ;;
esac
done
# Detect non-interactive mode (stdin is a pipe, not terminal)
if [ ! -t 0 ]; then
NON_INTERACTIVE=true
if [ -z "$INSTALL_TYPE" ]; then
print_info "Running in non-interactive mode, defaulting to local install"
INSTALL_TYPE="local"
fi
fi
print_header
# Interactive: prompt for install type if not given
if [ -z "$INSTALL_TYPE" ] && [ "$NON_INTERACTIVE" != true ]; then
echo -e "${BOLD}Choose installation type:${NC}"
echo " 1) Global — available for all projects (~/.config/opencode/opencode.json)"
echo " 2) Local — only for this project (./opencode.json)"
echo " 3) Cancel"
read -p "Select [1-3]: " -r; echo
case "$REPLY" in
1) INSTALL_TYPE="global" ;;
2) INSTALL_TYPE="local" ;;
*) print_info "Installation cancelled"; exit 0 ;;
esac
fi
[ -z "$INSTALL_TYPE" ] && { print_error "Installation type required"; exit 1; }
check_all_deps
merge_plugin_into_config
if [ "$SKIP_AGENTS" != true ]; then
setup_agents_skills
fi
setup_token
show_summary