-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·370 lines (354 loc) · 16 KB
/
install.sh
File metadata and controls
executable file
·370 lines (354 loc) · 16 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
#!/usr/bin/env bash
set -euo pipefail
REPO_URL="${REPO_URL:-https://github.com/dmoliveira/my_opencode.git}"
REPO_REF="${REPO_REF:-}"
INSTALL_DIR="${INSTALL_DIR:-$HOME/.config/opencode/my_opencode}"
CONFIG_DIR="$HOME/.config/opencode"
CONFIG_PATH="$CONFIG_DIR/opencode.json"
NON_INTERACTIVE=false
SKIP_SELF_CHECK=false
RUN_WIZARD=false
WIZARD_RECONFIGURE=false
QUIET=false
VERBOSE=false
while [ "$#" -gt 0 ]; do
case "$1" in
--non-interactive)
NON_INTERACTIVE=true
;;
--skip-self-check)
SKIP_SELF_CHECK=true
;;
--wizard)
RUN_WIZARD=true
;;
--reconfigure)
WIZARD_RECONFIGURE=true
;;
--quiet)
QUIET=true
;;
--verbose)
VERBOSE=true
;;
-h | --help)
printf "Usage: %s [--non-interactive] [--skip-self-check] [--wizard] [--reconfigure] [--quiet] [--verbose]\n" "$0"
exit 0
;;
*)
printf "Error: unknown argument: %s\n" "$1" >&2
exit 2
;;
esac
shift
done
log_info() {
if [ "$QUIET" = false ]; then
printf "%s\n" "$1"
fi
}
log_verbose() {
if [ "$VERBOSE" = true ] && [ "$QUIET" = false ]; then
printf "%s\n" "$1"
fi
}
if ! command -v git >/dev/null 2>&1; then
printf "Error: git is required but not installed.\n" >&2
exit 1
fi
if ! command -v python3 >/dev/null 2>&1; then
printf "Error: python3 is required but not installed.\n" >&2
exit 1
fi
mkdir -p "$CONFIG_DIR"
if [ -d "$INSTALL_DIR/.git" ]; then
log_info "Updating existing config repo at $INSTALL_DIR"
git -C "$INSTALL_DIR" fetch --all --prune
git -C "$INSTALL_DIR" pull --ff-only
else
if [ -e "$INSTALL_DIR" ] && [ ! -d "$INSTALL_DIR/.git" ]; then
printf "Error: %s exists and is not a git repository.\n" "$INSTALL_DIR" >&2
exit 1
fi
log_info "Cloning config repo into $INSTALL_DIR"
git clone --depth 1 "$REPO_URL" "$INSTALL_DIR"
fi
if [ -n "$REPO_REF" ]; then
log_info "Checking out repo ref $REPO_REF"
git -C "$INSTALL_DIR" fetch --all --prune >/dev/null 2>&1 || true
git -C "$INSTALL_DIR" checkout "$REPO_REF"
fi
chmod +x "$INSTALL_DIR/scripts/mcp_command.py" "$INSTALL_DIR/scripts/plugin_command.py" "$INSTALL_DIR/scripts/notify_command.py" "$INSTALL_DIR/scripts/session_digest.py" "$INSTALL_DIR/scripts/opencode_session.sh" "$INSTALL_DIR/scripts/telemetry_command.py" "$INSTALL_DIR/scripts/post_session_command.py" "$INSTALL_DIR/scripts/policy_command.py" "$INSTALL_DIR/scripts/doctor_command.py" "$INSTALL_DIR/scripts/config_command.py" "$INSTALL_DIR/scripts/stack_profile_command.py" "$INSTALL_DIR/scripts/install_wizard.py" "$INSTALL_DIR/scripts/nvim_integration_command.py" "$INSTALL_DIR/scripts/devtools_command.py" "$INSTALL_DIR/scripts/background_task_manager.py" "$INSTALL_DIR/scripts/refactor_lite_command.py"
if [ -f "$INSTALL_DIR/scripts/session_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/session_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/browser_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/browser_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/todo_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/todo_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/resume_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/resume_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/safe_edit_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/safe_edit_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/budget_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/budget_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/autopilot_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/autopilot_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/pr_review_analyzer.py" ]; then
chmod +x "$INSTALL_DIR/scripts/pr_review_analyzer.py"
fi
if [ -f "$INSTALL_DIR/scripts/pr_review_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/pr_review_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/release_train_engine.py" ]; then
chmod +x "$INSTALL_DIR/scripts/release_train_engine.py"
fi
if [ -f "$INSTALL_DIR/scripts/release_train_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/release_train_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/hotfix_runtime.py" ]; then
chmod +x "$INSTALL_DIR/scripts/hotfix_runtime.py"
fi
if [ -f "$INSTALL_DIR/scripts/hotfix_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/hotfix_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/health_score_collector.py" ]; then
chmod +x "$INSTALL_DIR/scripts/health_score_collector.py"
fi
if [ -f "$INSTALL_DIR/scripts/health_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/health_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/learn_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/learn_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/agent_doctor.py" ]; then
chmod +x "$INSTALL_DIR/scripts/agent_doctor.py"
fi
if [ -f "$INSTALL_DIR/scripts/quality_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/quality_command.py"
fi
if [ -f "$INSTALL_DIR/scripts/gateway_command.py" ]; then
chmod +x "$INSTALL_DIR/scripts/gateway_command.py"
fi
ln -sfn "$INSTALL_DIR/opencode.json" "$CONFIG_PATH"
if [ -d "$INSTALL_DIR/agent" ]; then
mkdir -p "$CONFIG_DIR/agent"
cp -f "$INSTALL_DIR"/agent/*.md "$CONFIG_DIR/agent/" 2>/dev/null || true
fi
if [ -d "$INSTALL_DIR/plugin/gateway-core" ]; then
if command -v npm >/dev/null 2>&1; then
(
cd "$INSTALL_DIR/plugin/gateway-core" && npm ci --yes --no-audit --no-fund --silent && npm run build --silent
) || {
printf "error: gateway-core plugin build failed; installation aborted\n" >&2
exit 1
}
else
printf "error: npm not found; gateway-core plugin build is required\n" >&2
exit 1
fi
if [ -f "$INSTALL_DIR/scripts/gateway_command.py" ]; then
if command -v bun >/dev/null 2>&1; then
python3 "$INSTALL_DIR/scripts/gateway_command.py" enable --json >/dev/null 2>&1 || printf "warning: failed to enable gateway plugin mode; bridge fallback remains active\n"
log_info "gateway mode: plugin_gateway preferred"
else
python3 "$INSTALL_DIR/scripts/gateway_command.py" disable --json >/dev/null 2>&1 || true
log_info "gateway mode: python_command_bridge fallback (bun unavailable)"
fi
fi
fi
if [ "$RUN_WIZARD" = true ]; then
log_info ""
log_info "Running install wizard..."
WIZARD_ARGS=()
if [ "$WIZARD_RECONFIGURE" = true ]; then
WIZARD_ARGS+=("--reconfigure")
fi
if [ "$NON_INTERACTIVE" = true ]; then
WIZARD_ARGS+=("--non-interactive")
fi
python3 "$INSTALL_DIR/scripts/install_wizard.py" "${WIZARD_ARGS[@]}"
fi
if [ "$SKIP_SELF_CHECK" = false ]; then
log_info ""
log_info "Running self-check..."
python3 "$INSTALL_DIR/scripts/mcp_command.py" status
python3 "$INSTALL_DIR/scripts/plugin_command.py" status
python3 "$INSTALL_DIR/scripts/notify_command.py" status
python3 "$INSTALL_DIR/scripts/notify_command.py" doctor
python3 "$INSTALL_DIR/scripts/session_digest.py" show || true
python3 "$INSTALL_DIR/scripts/session_digest.py" doctor
if [ -f "$INSTALL_DIR/scripts/session_command.py" ]; then
python3 "$INSTALL_DIR/scripts/session_command.py" list --json
python3 "$INSTALL_DIR/scripts/session_command.py" search selfcheck --json
python3 "$INSTALL_DIR/scripts/session_command.py" doctor --json
fi
python3 "$INSTALL_DIR/scripts/telemetry_command.py" status
python3 "$INSTALL_DIR/scripts/post_session_command.py" status
python3 "$INSTALL_DIR/scripts/policy_command.py" status
python3 "$INSTALL_DIR/scripts/config_command.py" status
python3 "$INSTALL_DIR/scripts/config_command.py" layers
python3 "$INSTALL_DIR/scripts/background_task_manager.py" status
python3 "$INSTALL_DIR/scripts/background_task_manager.py" doctor --json
if [ -f "$INSTALL_DIR/scripts/refactor_lite_command.py" ]; then
python3 "$INSTALL_DIR/scripts/refactor_lite_command.py" profile --scope "scripts/*.py" --dry-run --json
fi
python3 "$INSTALL_DIR/scripts/stack_profile_command.py" status
python3 "$INSTALL_DIR/scripts/browser_command.py" status
python3 "$INSTALL_DIR/scripts/browser_command.py" doctor --json
if [ -f "$INSTALL_DIR/scripts/gateway_command.py" ]; then
python3 "$INSTALL_DIR/scripts/gateway_command.py" status --json
python3 "$INSTALL_DIR/scripts/gateway_command.py" doctor --json
fi
SELF_CHECK_PLAN="$HOME/.config/opencode/my_opencode/.install-selfcheck-plan.md"
python3 -c "from pathlib import Path; Path('$SELF_CHECK_PLAN').write_text('---\nid: install-selfcheck-plan\ntitle: Install Selfcheck Plan\nowner: installer\ncreated_at: 2026-02-13T00:00:00Z\nversion: 1\n---\n\n# Plan\n\n- [ ] 1. Confirm command wiring\n- [ ] 2. Confirm checkpoint persistence\n', encoding='utf-8')"
if [ -f "$INSTALL_DIR/scripts/todo_command.py" ]; then
python3 "$INSTALL_DIR/scripts/todo_command.py" status --json
python3 "$INSTALL_DIR/scripts/todo_command.py" enforce --json
fi
if [ -f "$INSTALL_DIR/scripts/resume_command.py" ]; then
python3 "$INSTALL_DIR/scripts/resume_command.py" status --json || true
RUNTIME_PATH="$HOME/.config/opencode/my_opencode/runtime/plan_execution.json"
python3 -c "import json,pathlib; p=pathlib.Path('$RUNTIME_PATH'); data=json.loads(p.read_text(encoding='utf-8')) if p.exists() else {}; steps=data.get('steps', []); data['status']='failed'; data['resume']={'enabled': True, 'attempt_count': 0, 'max_attempts': 3, 'trail': []};
if isinstance(steps, list) and len(steps) >= 2:
steps[0]['state']='done';
steps[1]['state']='pending';
steps[1]['idempotent']=False;
p.parent.mkdir(parents=True, exist_ok=True); p.write_text(json.dumps(data, indent=2)+'\n', encoding='utf-8')"
python3 "$INSTALL_DIR/scripts/resume_command.py" now --interruption-class tool_failure --json || true
if ! python3 "$INSTALL_DIR/scripts/resume_command.py" now --interruption-class tool_failure --approve-step 2 --json; then
sleep 31
python3 "$INSTALL_DIR/scripts/resume_command.py" now --interruption-class tool_failure --approve-step 2 --json
fi
fi
if [ -f "$INSTALL_DIR/scripts/safe_edit_command.py" ]; then
python3 "$INSTALL_DIR/scripts/safe_edit_command.py" status --json
python3 "$INSTALL_DIR/scripts/safe_edit_command.py" plan --operation rename --scope "scripts/*.py" --allow-text-fallback --json
python3 "$INSTALL_DIR/scripts/safe_edit_command.py" doctor --json || true
fi
if [ -f "$INSTALL_DIR/scripts/checkpoint_command.py" ]; then
python3 "$INSTALL_DIR/scripts/checkpoint_command.py" list --json
python3 "$INSTALL_DIR/scripts/checkpoint_command.py" show --snapshot latest --json || true
python3 "$INSTALL_DIR/scripts/checkpoint_command.py" prune --max-per-run 50 --max-age-days 14 --json
python3 "$INSTALL_DIR/scripts/checkpoint_command.py" doctor --json || true
fi
if [ -f "$INSTALL_DIR/scripts/budget_command.py" ]; then
python3 "$INSTALL_DIR/scripts/budget_command.py" status --json
python3 "$INSTALL_DIR/scripts/budget_command.py" override --tool-call-count 120 --reason install-self-check --json
python3 "$INSTALL_DIR/scripts/budget_command.py" doctor --json
python3 "$INSTALL_DIR/scripts/budget_command.py" override --clear --json
fi
if [ -f "$INSTALL_DIR/scripts/autopilot_command.py" ]; then
python3 "$INSTALL_DIR/scripts/autopilot_command.py" start --goal "Install self-check objective" --scope "scripts/autopilot_command.py" --done-criteria "verify command wiring;verify runtime status" --max-budget balanced --json
python3 "$INSTALL_DIR/scripts/autopilot_command.py" status --confidence 0.9 --json
python3 "$INSTALL_DIR/scripts/autopilot_command.py" report --json
python3 "$INSTALL_DIR/scripts/autopilot_command.py" pause --json
python3 "$INSTALL_DIR/scripts/autopilot_command.py" resume --confidence 0.9 --tool-calls 1 --token-estimate 50 --touched-paths scripts/autopilot_command.py --json
python3 "$INSTALL_DIR/scripts/autopilot_command.py" resume --confidence 0.9 --tool-calls 1 --token-estimate 50 --touched-paths README.md --json || true
python3 "$INSTALL_DIR/scripts/autopilot_command.py" stop --reason install-self-check --json
python3 "$INSTALL_DIR/scripts/autopilot_command.py" doctor --json
fi
if [ -f "$INSTALL_DIR/scripts/pr_review_command.py" ]; then
SELF_CHECK_DIFF="$HOME/.config/opencode/my_opencode/.install-selfcheck-pr.diff"
python3 -c "from pathlib import Path; Path('$SELF_CHECK_DIFF').write_text('diff --git a/scripts/install_selfcheck.py b/scripts/install_selfcheck.py\nindex 0000000..1111111 100644\n--- a/scripts/install_selfcheck.py\n+++ b/scripts/install_selfcheck.py\n@@ -0,0 +1,1 @@\n+print(\"install\")\n', encoding='utf-8')"
python3 "$INSTALL_DIR/scripts/pr_review_command.py" --diff-file "$SELF_CHECK_DIFF" --json
python3 "$INSTALL_DIR/scripts/pr_review_command.py" checklist --diff-file "$SELF_CHECK_DIFF" --json
python3 "$INSTALL_DIR/scripts/pr_review_command.py" doctor --json
fi
if [ -f "$INSTALL_DIR/scripts/release_train_command.py" ]; then
python3 "$INSTALL_DIR/scripts/release_train_command.py" status --json
python3 "$INSTALL_DIR/scripts/release_train_command.py" prepare --version 0.0.1 --json || true
python3 "$INSTALL_DIR/scripts/release_train_command.py" draft --head HEAD --json
python3 "$INSTALL_DIR/scripts/release_train_command.py" doctor --json
fi
if [ -f "$INSTALL_DIR/scripts/hotfix_command.py" ]; then
(
cd "$INSTALL_DIR"
python3 "$INSTALL_DIR/scripts/hotfix_command.py" start --incident-id INSTALL-SELF-CHECK --scope config_only --impact sev3 --json
python3 "$INSTALL_DIR/scripts/hotfix_runtime.py" checkpoint --label install-self-check --json
python3 "$INSTALL_DIR/scripts/hotfix_runtime.py" validate --target validate --result pass --json
python3 "$INSTALL_DIR/scripts/hotfix_command.py" status --json
python3 "$INSTALL_DIR/scripts/hotfix_command.py" remind --json
python3 "$INSTALL_DIR/scripts/hotfix_command.py" close --outcome resolved --followup-issue install-self-check --deferred-validation-owner installer --deferred-validation-due 2026-03-01 --json
python3 "$INSTALL_DIR/scripts/hotfix_command.py" doctor --json
)
fi
if [ -f "$INSTALL_DIR/scripts/health_command.py" ]; then
(
cd "$INSTALL_DIR"
python3 "$INSTALL_DIR/scripts/health_command.py" status --force-refresh --json
python3 "$INSTALL_DIR/scripts/health_command.py" trend --limit 5 --json
python3 "$INSTALL_DIR/scripts/health_command.py" drift --json
python3 "$INSTALL_DIR/scripts/health_command.py" doctor --json
)
fi
if [ -f "$INSTALL_DIR/scripts/learn_command.py" ]; then
(
cd "$INSTALL_DIR"
python3 "$INSTALL_DIR/scripts/learn_command.py" capture --limit 5 --json
LEARN_ENTRY_ID=$(python3 "$INSTALL_DIR/scripts/learn_command.py" search --limit 1 --json | python3 -c 'import json,sys; payload=json.load(sys.stdin); entries=payload.get("entries", []); print(entries[0].get("entry_id", "") if entries else "")')
if [ -n "$LEARN_ENTRY_ID" ]; then
python3 "$INSTALL_DIR/scripts/learn_command.py" review --entry-id "$LEARN_ENTRY_ID" --summary "install-self-check review" --confidence 88 --risk high --json
if python3 "$INSTALL_DIR/scripts/learn_command.py" publish --entry-id "$LEARN_ENTRY_ID" --approved-by installer --json; then
printf "learn publish high-risk single approval unexpectedly passed\n" >&2
exit 1
fi
python3 "$INSTALL_DIR/scripts/learn_command.py" publish --entry-id "$LEARN_ENTRY_ID" --approved-by installer-2 --json
fi
python3 "$INSTALL_DIR/scripts/learn_command.py" search --query release --json
python3 "$INSTALL_DIR/scripts/learn_command.py" doctor --json
)
fi
python3 "$INSTALL_DIR/scripts/nvim_integration_command.py" status
python3 "$INSTALL_DIR/scripts/devtools_command.py" status
python3 "$INSTALL_DIR/scripts/doctor_command.py" run || true
if ! python3 "$INSTALL_DIR/scripts/plugin_command.py" doctor; then
if [ "$NON_INTERACTIVE" = true ]; then
printf "\nSelf-check failed in non-interactive mode.\n" >&2
exit 1
fi
printf "\nSelf-check reported missing prerequisites; setup can continue.\n"
python3 "$INSTALL_DIR/scripts/plugin_command.py" setup-keys
fi
fi
if [ "$QUIET" = false ]; then
printf "
Done! ✅
"
printf "Config linked: %s -> %s
" "$CONFIG_PATH" "$INSTALL_DIR/opencode.json"
printf "
Open OpenCode quickstart:
"
printf " /doctor run
"
printf " /plugin status
"
printf " /mcp status
"
printf " /notify status
"
printf " /autopilot go --goal 'finish current objective' --json
"
printf " /budget status --json
"
printf " /gateway status
"
printf " /hooks status
"
printf "
Command references:
"
printf " docs/quickstart.md (installation + first run)
"
printf " docs/command-handbook.md (full slash-command catalog)
"
printf " ~/.config/opencode/my_opencode/install.sh --wizard --reconfigure
"
fi