OpenCode 2 publishes its CLI as @opencode/cli (opencode-ai stops at 1.19.x), so install that package and pin it to 2.0.32. Also fix what the v2 migration invalidates: - renovate.json: track @opencode/cli instead of opencode-ai, otherwise the pin is never bumped. - opencode-attach: `opencode attach` no longer exists in v2. Point the client at the server with `--server <url>` instead (appended after a subcommand when one is given); auth still comes from OPENCODE_SERVER_PASSWORD / OPENCODE_PASSWORD. - README/AGENTS: v2 package name, entrypoint, serve defaults, API surface (/global/health is gone, everything lives under authenticated /api/*), and removal of OPENCODE_SERVER_USERNAME (the username is always `opencode` in v2). The entrypoint stays ["opencode"] on purpose: existing deployments pass `serve ...` at runtime, and OpenCode 2 is invoked the same way.
57 lines
1.4 KiB
Bash
57 lines
1.4 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
LOCKFILE="${OPENCODE_ATTACH_LOCK:-/tmp/opencode-attach.lock}"
|
|
|
|
: "${OPENCODE_SERVER_PASSWORD:?OPENCODE_SERVER_PASSWORD is required}"
|
|
: "${OPENCODE_API_URL:?OPENCODE_API_URL is required}"
|
|
|
|
cleanup_lock() {
|
|
if [ -f "$LOCKFILE" ]; then
|
|
existing_pid=$(cat "$LOCKFILE" 2>/dev/null || true)
|
|
[ "$existing_pid" = "$$" ] && rm -f "$LOCKFILE"
|
|
fi
|
|
}
|
|
|
|
kill_existing_instance() {
|
|
if [ ! -f "$LOCKFILE" ]; then
|
|
return
|
|
fi
|
|
|
|
existing_pid=$(cat "$LOCKFILE" 2>/dev/null || true)
|
|
if [ -z "$existing_pid" ] || [ "$existing_pid" = "$$" ]; then
|
|
rm -f "$LOCKFILE"
|
|
return
|
|
fi
|
|
|
|
if kill -0 "$existing_pid" 2>/dev/null; then
|
|
kill "$existing_pid" 2>/dev/null
|
|
for _ in 1 2 3 4 5; do
|
|
if ! kill -0 "$existing_pid" 2>/dev/null; then
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
if kill -0 "$existing_pid" 2>/dev/null; then
|
|
kill -9 "$existing_pid" 2>/dev/null || true
|
|
fi
|
|
fi
|
|
|
|
rm -f "$LOCKFILE"
|
|
}
|
|
|
|
trap cleanup_lock INT TERM EXIT
|
|
|
|
kill_existing_instance
|
|
printf '%s\n' "$$" > "$LOCKFILE"
|
|
|
|
# OpenCode 2 dropped `opencode attach`: a client is pointed at a server with
|
|
# --server <url>, which must follow the subcommand when one is given.
|
|
if [ "$#" -eq 0 ]; then
|
|
set -- --server "${OPENCODE_API_URL}"
|
|
else
|
|
set -- "$@" --server "${OPENCODE_API_URL}"
|
|
fi
|
|
|
|
exec opencode "$@"
|