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

+58 -20
View File
@@ -33,6 +33,7 @@ const installPrelude = () => [
extractMinOpenCodeVersion(),
extractShellFunction('version_gte'),
extractShellFunction('read_opencode_version'),
extractShellFunction('opencode_arch_suffix'),
extractShellFunction('install_opencode'),
extractShellFunction('reconcile_persisted_opencode'),
].join('\n')
@@ -191,7 +192,7 @@ const runOpenCodeSection = (snippet: string, env: Record<string, string> = {}) =
OCM_STUB_LOG: logPath,
OCM_STUB_RUNUSER_EXEC: '1',
HOME: homeDir,
OPENCODE_BUNDLED_VERSION: '1.18.16',
OPENCODE_BUNDLED_VERSION: '2.0.15',
...env,
},
})
@@ -205,7 +206,7 @@ while [ "$#" -gt 0 ]; do
shift
done
mkdir -p "$HOME/.opencode/bin"
printf '#!/bin/bash\\necho 1.18.16\\n' > "$HOME/.opencode/bin/opencode"
printf '#!/bin/bash\\necho %s\\n' "$OPENCODE_BUNDLED_VERSION" > "$HOME/.opencode/bin/opencode"
chmod +x "$HOME/.opencode/bin/opencode"
printf 'fake binary\\n' > "$(dirname "$out")/opencode"`)
writeStub('tar', `echo "tar $*" >> "$OCM_STUB_LOG"`)
@@ -219,7 +220,7 @@ describe('install_opencode', () => {
const res = runOpenCodeSection(`${installPrelude()}\ninstall_opencode`)
expect(res.status).toBe(0)
const urls = curlLog().join(' ')
expect(urls).toMatch(/\/releases\/download\/v1\.18\.16\//)
expect(urls).toMatch(/https:\/\/opencode\.ai\/files\/bin\/2\.0\.15\/opencode-linux-(x64|arm64)\.tar\.gz/)
expect(urls).not.toContain('/releases/latest/download/')
expect(urls).not.toContain('/tmp/opencode.tar.gz')
})
@@ -257,21 +258,31 @@ describe('install_opencode', () => {
it('honors an OPENCODE_BUNDLED_VERSION override for the download URL', () => {
stubInstallTools()
const res = runOpenCodeSection(`${installPrelude()}\ninstall_opencode`, {
OPENCODE_BUNDLED_VERSION: '1.22.0',
OPENCODE_BUNDLED_VERSION: '2.1.0',
})
expect(res.status).toBe(0)
const urls = curlLog().join(' ')
expect(urls).toMatch(/\/releases\/download\/v1\.22\.0\//)
expect(urls).toMatch(/https:\/\/opencode\.ai\/files\/bin\/2\.1\.0\/opencode-linux-(x64|arm64)\.tar\.gz/)
expect(urls).not.toContain('/releases/latest/download/')
})
it('refuses a 1.x OPENCODE_BUNDLED_VERSION override below the minimum', () => {
stubInstallTools()
const res = runOpenCodeSection(`${installPrelude()}\ninstall_opencode`, {
OPENCODE_BUNDLED_VERSION: '1.22.0',
})
expect(res.status).not.toBe(0)
expect(res.stderr).toContain('below the minimum supported')
expect(curlLog()).toHaveLength(0)
})
it('reinstalls the bundled verified version when opencode is missing', () => {
stubInstallTools()
const res = runOpenCodeSection(`${installPrelude()}\n${extractOpenCodeInstallSection()}`)
expect(res.status).toBe(0)
expect(res.stdout).toContain('OpenCode not found. Installing...')
const urls = curlLog().join(' ')
expect(urls).toMatch(/\/releases\/download\/v1\.18\.16\//)
expect(urls).toMatch(/https:\/\/opencode\.ai\/files\/bin\/2\.0\.15\/opencode-linux-(x64|arm64)\.tar\.gz/)
expect(urls).not.toContain('/releases/latest/download/')
})
@@ -282,7 +293,7 @@ describe('install_opencode', () => {
expect(res.status).toBe(0)
expect(res.stdout).toContain('below minimum required version')
const urls = curlLog().join(' ')
expect(urls).toMatch(/\/releases\/download\/v1\.18\.16\//)
expect(urls).toMatch(/https:\/\/opencode\.ai\/files\/bin\/2\.0\.15\/opencode-linux-(x64|arm64)\.tar\.gz/)
expect(urls).not.toContain('/releases/latest/download/')
})
})
@@ -306,7 +317,7 @@ if [ -z "$OCM_EXECUTED_AS_NODE" ]; then
echo "persisted binary executed outside runuser" >&2
exit 1
fi
echo "opencode version 1.22.0"`)
echo "opencode version 2.0.15"`)
chmodSync(homeBinPath(), 0o755)
const res = runOpenCodeSection(`${installPrelude()}\n${extractOpenCodeInstallSection()}`)
expect(res.status).toBe(0)
@@ -317,34 +328,34 @@ echo "opencode version 1.22.0"`)
it('retains a persisted home binary equal to the bundled version', () => {
mkdirSync(join(stubDir, 'home/.opencode/bin'), { recursive: true })
writeBinary(join(stubDir, 'home/.opencode/bin'), '1.18.16')
writeBinary(join(stubDir, 'home/.opencode/bin'), '2.0.15')
const res = runOpenCodeSection(`${installPrelude()}\n${extractOpenCodeInstallSection()}`)
expect(res.status).toBe(0)
expect(res.stdout).toContain('retaining it')
expect(existsSync(homeBinPath())).toBe(true)
expect(res.stdout).toContain('OpenCode is installed (version: 1.18.16)')
expect(res.stdout).toContain('OpenCode is installed (version: 2.0.15)')
expect(curlLog()).toHaveLength(0)
})
it('retains a persisted home binary newer than the bundled version', () => {
mkdirSync(join(stubDir, 'home/.opencode/bin'), { recursive: true })
writeBinary(join(stubDir, 'home/.opencode/bin'), '1.22.0')
writeBinary(join(stubDir, 'home/.opencode/bin'), '2.1.0')
const res = runOpenCodeSection(`${installPrelude()}\n${extractOpenCodeInstallSection()}`)
expect(res.status).toBe(0)
expect(res.stdout).toContain('retaining it')
expect(existsSync(homeBinPath())).toBe(true)
expect(res.stdout).toContain('OpenCode is installed (version: 1.22.0)')
expect(res.stdout).toContain('OpenCode is installed (version: 2.1.0)')
expect(curlLog()).toHaveLength(0)
})
it('retains a persisted home binary older than the bundled version but above the minimum', () => {
mkdirSync(join(stubDir, 'home/.opencode/bin'), { recursive: true })
writeBinary(join(stubDir, 'home/.opencode/bin'), '1.10.0')
writeBinary(join(stubDir, 'home/.opencode/bin'), '2.0.0')
const res = runOpenCodeSection(`${installPrelude()}\n${extractOpenCodeInstallSection()}`)
expect(res.status).toBe(0)
expect(res.stdout).toContain('retaining it')
expect(existsSync(homeBinPath())).toBe(true)
expect(res.stdout).toContain('OpenCode is installed (version: 1.10.0)')
expect(res.stdout).toContain('OpenCode is installed (version: 2.0.0)')
expect(curlLog()).toHaveLength(0)
})
@@ -354,11 +365,12 @@ echo "opencode version 1.22.0"`)
writeBinary(join(stubDir, 'home/.opencode/bin'), '1.0.0')
const res = runOpenCodeSection(`${installPrelude()}\n${extractOpenCodeInstallSection()}`)
expect(res.status).toBe(0)
expect(res.stdout).toContain('retaining it')
expect(res.stdout).toContain('below minimum required version')
expect(res.stdout).toContain('Reinstalling bundled OpenCode version 1.18.16...')
expect(res.stdout).not.toContain('retaining it')
expect(res.stdout).toContain('below the minimum supported 2.0.0')
expect(res.stdout).toContain('Installing OpenCode 2.0.15...')
expect(existsSync(homeBinPath())).toBe(true)
const urls = curlLog().join(' ')
expect(urls).toMatch(/\/releases\/download\/v1\.18\.16\//)
expect(urls).toMatch(/https:\/\/opencode\.ai\/files\/bin\/2\.0\.15\/opencode-linux-(x64|arm64)\.tar\.gz/)
expect(urls).not.toContain('/releases/latest/download/')
})
@@ -366,7 +378,7 @@ echo "opencode version 1.22.0"`)
mkdirSync(join(stubDir, 'home/.opencode/bin'), { recursive: true })
writeBinary(join(stubDir, 'home/.opencode/bin'), 'garbage')
mkdirSync(join(stubDir, 'bundled'), { recursive: true })
writeBinary(join(stubDir, 'bundled'), '1.18.16')
writeBinary(join(stubDir, 'bundled'), '2.0.15')
const res = runOpenCodeSection(`${installPrelude()}\n${extractOpenCodeInstallSection()}`, {
PATH: bundledFirstPath(),
})
@@ -374,7 +386,33 @@ echo "opencode version 1.22.0"`)
expect(res.stdout).toContain('malformed or unversioned')
expect(existsSync(homeBinPath())).toBe(false)
expect(existsSync(bundledBinPath())).toBe(true)
expect(res.stdout).toContain('OpenCode is installed (version: 1.18.16)')
expect(res.stdout).toContain('OpenCode is installed (version: 2.0.15)')
expect(curlLog()).toHaveLength(0)
})
it('removes a persisted 1.x binary and installs the bundled 2.x binary', () => {
stubInstallTools()
mkdirSync(join(stubDir, 'home/.opencode/bin'), { recursive: true })
writeBinary(join(stubDir, 'home/.opencode/bin'), '1.18.16')
const res = runOpenCodeSection(
`${installPrelude()}\nreconcile_persisted_opencode\nif [ -e "$HOME/.opencode/bin/opencode" ]; then echo "PERSISTED_PRESENT"; else echo "PERSISTED_REMOVED"; fi\n${extractOpenCodeInstallSection()}`
)
expect(res.status).toBe(0)
expect(res.stdout).toContain('below the minimum supported 2.0.0')
expect(res.stdout).toContain('PERSISTED_REMOVED')
expect(res.stdout).not.toContain('PERSISTED_PRESENT')
expect(existsSync(homeBinPath())).toBe(true)
expect(res.stdout).toContain('Installing OpenCode 2.0.15...')
const urls = curlLog().join(' ')
expect(urls).toMatch(/https:\/\/opencode\.ai\/files\/bin\/2\.0\.15\/opencode-linux-(x64|arm64)\.tar\.gz/)
})
it('appends -musl to the arch suffix when the musl loader is present', () => {
stubInstallTools()
writeStub('ls', 'exit 0')
const res = runOpenCodeSection(`${installPrelude()}\ninstall_opencode`)
expect(res.status).toBe(0)
const urls = curlLog().join(' ')
expect(urls).toMatch(/https:\/\/opencode\.ai\/files\/bin\/2\.0\.15\/opencode-linux-(x64|arm64)-musl\.tar\.gz/)
})
})