feat(opencode): migrate OpenCode Manager to OpenCode 2 (#359)

* feat(opencode): migrate OpenCode Manager to OpenCode 2

Port the backend lifecycle, generated plugins, event aggregation,
schedules, worktrees, provider credentials, MCP, config handling, the
frontend chat model, and the ocm CLI to OpenCode 2.

Adopt @opencode/client 2.0.15 as the single typed V2 API contract,
require OpenCode 2.0.0 or newer (pinned 2.0.15), and delete every
V1-only code path.

* refactor(opencode): reload config in place and drop v1 compatibility shims

Route config/skill/AGENTS.md changes through the OpenCode location reload
API instead of a full server restart, stop auto-resuming interrupted
sessions, remove the restart coordinator and v1 MCP/version shims, and pin
support to OpenCode >=2.0.15 <3.0.0. Adds integration-ready retries,
service-mode launch, ocm-cli repo proxy, and new frontend form/MCP helpers.

* refactor(opencode): consolidate v2 migration helpers and harden install, proxy, and session flows

- extract shared semver and model-ref utilities, reuse across version checks
- share the OpenCode release download script across Docker, entrypoint, dev setup
- unify install/upgrade failure recovery and guard externally managed OPENCODE_BIN
- scope the repo proxy location rewrite and surface ocm proxy errors
- rework frontend session projection, permission lookup, and cache invalidation

* fix(schedules): reject unavailable agents before creating a session

* feat(opencode): add ocm install, schedule agent fallback, and session move guards
This commit is contained in:
Chris Scott authored and GitHub committed 2026-09-26 13:16:45 -04:00
1 parent 6c2ebd764b
commit dacde879d6
383 files changed
+29905 -46566

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
#!/bin/bash
opencode_arch_suffix() {
local arch
arch="$(uname -m | sed 's/x86_64/x64/; s/aarch64/arm64/')"
if ls /lib/ld-musl-* >/dev/null 2>&1; then
arch="${arch}-musl"
fi
printf '%s\n' "$arch"
}
opencode_download_url() {
local version="$1" suffix="${2:-}"
[ -n "$suffix" ] || suffix="$(opencode_arch_suffix)"
printf 'https://opencode.ai/files/bin/%s/opencode-linux-%s.tar.gz\n' "$version" "$suffix"
}
is_stable_opencode_version() {
printf '%s\n' "$1" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'
}
version_gte() {
printf '%s\n%s\n' "$2" "$1" | sort -V -C
}
is_supported_opencode_version() {
local version="$1"
is_stable_opencode_version "$version" || return 1
[ -n "${OPENCODE_SUPPORTED_FLOOR:-}" ] || return 1
[ "${version%%.*}" = "${OPENCODE_SUPPORTED_FLOOR%%.*}" ] || return 1
version_gte "$version" "$OPENCODE_SUPPORTED_FLOOR"
}
supported_opencode_range() {
[ -n "${OPENCODE_SUPPORTED_FLOOR:-}" ] || return 1
printf '>=%s <%s.0.0\n' "$OPENCODE_SUPPORTED_FLOOR" "$(( ${OPENCODE_SUPPORTED_FLOOR%%.*} + 1 ))"
}
download_opencode_to() {
local version="$1" destination="$2" staging
if [ -z "$version" ]; then
echo "ERROR: no OpenCode version provided; refusing to guess the pinned build" >&2
return 1
fi
if ! is_stable_opencode_version "$version"; then
echo "ERROR: OpenCode version '$version' is not an X.Y.Z version; refusing to download it" >&2
return 1
fi
staging="$(mktemp -d)"
if ! curl -fsSL "$(opencode_download_url "$version")" -o "$staging/opencode.tar.gz"; then
echo "ERROR: failed to download OpenCode ${version}" >&2
rm -rf "$staging"
return 1
fi
if ! tar -xzf "$staging/opencode.tar.gz" -C "$staging"; then
echo "ERROR: failed to extract OpenCode ${version}" >&2
rm -rf "$staging"
return 1
fi
mkdir -p "$(dirname "$destination")"
mv "$staging/opencode" "$destination"
chmod 755 "$destination"
rm -rf "$staging"
}