launch-upgrader: fix opencode --model placement + add web-attach/--share

The opencode backend emitted 'opencode --model X run ...' but -m/--model is a
flag on the run subcommand, so the model was being ignored. Move it after run.
Add OPENCODE_SHARE (default on): attach the session to the shared opencode web
server (oc.commoninternet.net) AND create a public --share link for monitoring.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
autonomic-bot
2026-06-22 20:14:27 +00:00
parent f29aacc29a
commit ec18c98af6

View File

@ -16,13 +16,14 @@ Usage:
Env:
LOOP_BACKEND claude (default) | opencode — also accepts UPGRADER_BACKEND
LOOP_MODEL model flag (overrides UPGRADER_MODEL)
UPGRADER_MODEL sonnet (default for claude) | tinfoil/deepseek-v4-pro (opencode example)
UPGRADER_MODEL sonnet (default for claude) | provider/model for opencode, e.g.
opencode/glm-5.1 (opencode Zen "go" subscription) or tinfoil/deepseek-v4-pro
UPGRADER_ARGS extra args passed to /upgrade-all (e.g. "n8n ghost", "--dry-run")
claude backend:
CLAUDE_BIN, CLAUDE_FLAGS, REMOTE_CONTROL
opencode backend:
OPENCODE_BIN, OPENCODE_SERVER
OPENCODE_BIN, OPENCODE_SERVER, OPENCODE_SHARE (1=attach to web server + public --share link)
"""
import os, sys, subprocess, re
@ -45,6 +46,10 @@ REMOTE_CONTROL = os.environ.get("REMOTE_CONTROL", "1") == "1"
OPENCODE_BIN = os.environ.get("OPENCODE_BIN", "/home/loops/.local/bin/opencode")
OPENCODE_SERVER = os.environ.get("OPENCODE_SERVER", "http://127.0.0.1:4096")
# Web visibility for the opencode backend: attach the session to the shared opencode
# web server (viewable at http://oc.commoninternet.net, tailnet-only) AND optionally
# create a public opencode.ai --share link. Default both on so the run is monitorable.
OPENCODE_SHARE = os.environ.get("OPENCODE_SHARE", "1") == "1"
UPGRADER_ARGS = os.environ.get("UPGRADER_ARGS", "")
@ -135,12 +140,16 @@ def start(mode="use-or-create"):
elif BACKEND == "opencode":
if not Path(OPENCODE_BIN).exists():
die(f"opencode not found at {OPENCODE_BIN}")
# NOTE: -m/--model and --attach/--title/--share are flags on the `run` SUBCOMMAND,
# so they must come AFTER `run` (a global `opencode --model X run` is ignored).
share_flag = "--share" if OPENCODE_SHARE else ""
cmd = (
f"set -a; . /srv/cc-ci/.testenv; set +a; "
f"{OPENCODE_BIN} {model_flag} run --attach '{OPENCODE_SERVER}' "
f"{OPENCODE_BIN} run {model_flag} {share_flag} --attach '{OPENCODE_SERVER}' "
f"--title '{SESSION}' \"$(cat '{kf}')\""
)
log(f" visible at http://oc.commoninternet.net (tailnet only)")
log(f" attached to {OPENCODE_SERVER} http://oc.commoninternet.net (tailnet only)"
+ (" +public --share link (printed in the session)" if OPENCODE_SHARE else ""))
else:
die(f"unknown LOOP_BACKEND '{BACKEND}' — use 'claude' or 'opencode'")