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.
This commit is contained in:
Chris Scott committed 2026-09-24 08:38:26 -04:00
1 parent 6c2ebd764b
commit 7351d5f002
313 files changed
+23848 -36801

No files matched your search

+15 -18
View File
@@ -131,9 +131,9 @@ The container entrypoint (`scripts/docker-entrypoint.sh`) automatically:
1. **Verifies Bun** is installed (installed at build time, fallback install if missing)
2. **Reconciles the persisted OpenCode home binary** (`/home/node/.opencode/bin/opencode`):
- any valid persisted binary is retained, including a user-selected version older than the image-bundled `OPENCODE_BUNDLED_VERSION`;
- a persisted binary that is malformed or unversioned is removed (only that binary), so `PATH` falls back to the image-bundled `/usr/local/bin/opencode` without a download
3. **Installs OpenCode** only when no usable binary is present: if opencode is missing entirely, or if the surviving binary is still below the minimum version (1.0.137), the pinned bundled version is downloaded into the persisted `bin` volume
- any valid persisted binary at or above the minimum version (2.0.0) is retained, including a user-selected version newer or older than the image-bundled `OPENCODE_BUNDLED_VERSION`;
- a persisted binary that is malformed, unversioned, or below the minimum version is removed (only that binary), so `PATH` falls back to the image-bundled `/usr/local/bin/opencode` without a download
3. **Installs OpenCode** only when no usable binary is present: if opencode is missing entirely, or if the surviving binary is still below the minimum version (2.0.0), the pinned bundled version is downloaded from `https://opencode.ai/files/bin/` into the persisted `bin` volume
4. **Validates AUTH_SECRET** is set (required for startup)
5. **Aligns the `node` account** to `PUID`/`PGID` (default `1000`) before chowning the workspace, the `/app/data` directory, and the `node` home directory. If `PUID`/`PGID` are already used by another account in the image, startup aborts with an explicit error. Group alignment runs first, so a free `PGID` combined with an occupied `PUID` mutates `/etc/group` before the UID collision is detected and aborts startup; realign to the original ids or pick a free pair before retrying.
@@ -273,13 +273,13 @@ volumes:
- opencode-bin:/home/node/.opencode/bin
```
Persists the OpenCode binary that OpenCode's own `upgrade --method curl` command (run from the UI's OpenCode settings) installs into `~/.opencode/bin`, so an upgrade survives container recreations. The volume is limited to the binary and leaves existing workspace and XDG persistence behavior for config, auth, and chat state unchanged.
Persists the OpenCode binary that the Manager's installer (from the UI's OpenCode settings) writes into `~/.opencode/bin`, so an upgrade survives container recreations. The volume is limited to the binary and leaves existing workspace and XDG persistence behavior for config, auth, and chat state unchanged.
On startup the entrypoint reconciles the persisted binary:
- any valid persisted binary is retained, including a user-selected version older than the image-bundled `OPENCODE_BUNDLED_VERSION`;
- any valid persisted binary at or above the minimum version (2.0.0) is retained, including a user-selected version newer or older than the image-bundled `OPENCODE_BUNDLED_VERSION`;
- a malformed or unversioned persisted binary is removed so `PATH` falls back to the image-bundled `/usr/local/bin/opencode`, avoiding a download;
- a persisted binary still below the minimum version (1.0.137) is replaced by the pinned bundled version, which is downloaded into this volume.
- a persisted binary still below the minimum version (2.0.0) is removed so the pinned bundled OpenCode 2 binary is used, downloaded from `https://opencode.ai/files/bin/` into this volume.
A fresh volume starts empty and the image-bundled binary is used until an upgrade installs into the volume.
@@ -309,7 +309,7 @@ services:
- ${OCM_OPENCODE_STATE_HOST_PATH}:/import/opencode-state:ro
```
`OPENCODE_IMPORT_CONFIG_PATH` imports a single file. For a host with multiple recognized config files (`config.json`, `opencode.json`, `opencode.jsonc`), omit it and mount `${OCM_OPENCODE_CONFIG_HOST_PATH}` writable at the container's OpenCode config directory (`/home/node/.config/opencode`) instead. Import mirrors the host's recognized files into the workspace and removes workspace copies absent on the host.
`OPENCODE_IMPORT_CONFIG_PATH` imports a single file. For a host with multiple config files (`opencode.json`, `opencode.jsonc`, and a legacy `config.json`), omit it and mount `${OCM_OPENCODE_CONFIG_HOST_PATH}` writable at the container's OpenCode config directory (`/home/node/.config/opencode`) instead. Import mirrors the host's files into the workspace, removes workspace copies absent on the host, and folds a mirrored legacy `config.json` into the workspace config.
Why the repo mount uses the host path as the container path:
@@ -513,8 +513,8 @@ By default, the OpenCode server binds to `127.0.0.1` inside the container and is
You only need to expose the OpenCode server on an external interface if you have a specific use case that requires other services or machines to connect directly to it.
!!! warning "Sandbox enforcement is agent-tool-scoped"
Sandbox enforcement applies only to the OpenCode agent `bash` tool. The rewrite runs as a plugin hook inside the OpenCode process, so it guards both proxied and direct connections to the OpenCode server. WebUI shell, slash shell, PTY, and server binding follow normal OpenCode behavior while sandboxing is enabled (see [Agent Sandboxing](../features/sandboxing.md)).
!!! warning "Sandbox enforcement is shell-scoped"
Sandbox enforcement applies to every shell spawn that goes through OpenCode's `Shell.create`: the agent `shell` tool, the WebUI `!command` shell, and the shell API (`POST /api/shell`). The rewrite runs as a plugin hook inside the OpenCode process, so it guards both proxied and direct connections to the OpenCode server. PTY terminals, slash-command shell interpolation (a `` !`cmd` `` template is expanded by OpenCode with the configured shell directly on the host), and server binding follow normal OpenCode behavior while sandboxing is enabled (see [Agent Sandboxing](../features/sandboxing.md)).
### How to Expose Safely
@@ -522,7 +522,7 @@ To expose the OpenCode server on the host network:
1. **Set `OPENCODE_HOST=0.0.0.0`** in your environment
2. **Add port `5551:5551`** to the compose ports
3. **Set `OPENCODE_SERVER_PASSWORD`** — this is **required**; the managed OpenCode server will refuse to start without it
3. **Set `OPENCODE_SERVER_PASSWORD`** — recommended so the exposed server uses a password you control; without it OpenCode Manager generates and persists one
Example compose override:
@@ -538,13 +538,10 @@ services:
### Password Configuration
The password can be configured in two ways:
OpenCode 2 always requires Basic Auth on the managed server, so a password is always in effect. It is resolved in this order:
1. **Environment variable:** Set `OPENCODE_SERVER_PASSWORD` in your `.env` file or compose environment
2. **Via UI:** Use Settings → OpenCode → Server Auth to set a password at runtime
1. **Via UI:** Use Settings → OpenCode → Server Auth to set a password at runtime
2. **Environment variable:** Set `OPENCODE_SERVER_PASSWORD` in your `.env` file or compose environment
3. **Auto-generated:** When neither is configured, OpenCode Manager generates a random password and persists it in its database
**DB-stored passwords take precedence over the environment variable.** If you set a password via the UI, it will override the env var.
### Startup Guard
If you set `OPENCODE_HOST=0.0.0.0` (or any non-localhost host) without configuring a password (either via env var or UI), the managed OpenCode server will refuse to start with an error message explaining how to fix it. The OpenCode Manager UI/API may remain available so you can configure a password and restart the managed server. The password guard applies in both sandboxing modes — an enforced server binds the configured `OPENCODE_HOST` like any other server.
**DB-stored passwords take precedence over the environment variable, which takes precedence over the auto-generated password.**
+2 -4
View File
@@ -94,18 +94,16 @@ When configured, users can enable push notifications in Settings → Notificatio
|----------|-------------|---------|
| `OPENCODE_SERVER_PORT` | Port for the OpenCode CLI server | `5551` |
| `OPENCODE_HOST` | OpenCode server bind address | `127.0.0.1` |
| `OPENCODE_PUBLIC_URL` | Public URL passed to OpenCode for OAuth callbacks | - |
| `OPENCODE_HEALTH_WATCH_ENABLED` | Enable OpenCode health watcher and recovery | `true` (`false` in tests) |
| `OPENCODE_HEALTH_POLL_MS` | OpenCode health watcher poll interval | `30000` |
| `OPENCODE_HEALTH_FAILURE_THRESHOLD` | Failed health checks before recovery starts | `2` |
| `OPENCODE_SERVER_PASSWORD` | Basic Auth password required when binding OpenCode to a non-loopback host. Can also be set via UI (Settings → OpenCode → Server Auth). DB-stored passwords override this env var. | - |
| `OPENCODE_SERVER_USERNAME` | Basic Auth username | `opencode` |
| `OPENCODE_SERVER_PASSWORD` | Basic Auth password for the managed OpenCode server. OpenCode 2 always requires one: when unset, OpenCode Manager generates and persists a password (override it any time via Settings → OpenCode → Server Auth). DB-stored passwords override this env var. | auto-generated |
## OpenCode Import
| Variable | Description | Default |
|----------|-------------|---------|
| `OPENCODE_IMPORT_CONFIG_PATH` | Existing standalone OpenCode config file to import on first startup. When set to a single file, only that file is imported. When unset, the host's recognized config files (`config.json`, `opencode.json`, `opencode.jsonc`) are mirrored into the workspace and workspace copies absent on the host are removed | - |
| `OPENCODE_IMPORT_CONFIG_PATH` | Existing standalone OpenCode config file to import on first startup. When set to a single file, only that file is imported. When unset, the host's `opencode.json`, `opencode.jsonc`, and legacy `config.json` are mirrored into the workspace, workspace copies absent on the host are removed, and the mirrored legacy file is folded into the workspace config | - |
| `OPENCODE_IMPORT_STATE_PATH` | Existing standalone OpenCode state directory to import on first startup | - |
## Agent Sandboxing