mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
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:
1 parent
6c2ebd764b
commit
7351d5f002
313 files changed
+23848
-36801
No files matched your search
@@ -42,7 +42,7 @@ grant_kvm_access() {
|
||||
echo "Granted node access to $dev (group '$group_name', gid $dev_gid)"
|
||||
}
|
||||
|
||||
MIN_OPENCODE_VERSION="1.0.137"
|
||||
MIN_OPENCODE_VERSION="2.0.0"
|
||||
|
||||
version_gte() {
|
||||
printf '%s\n%s\n' "$2" "$1" | sort -V -C
|
||||
@@ -57,6 +57,15 @@ read_opencode_version() {
|
||||
runuser -u node -- "$binary" --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1 || true
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
install_opencode() {
|
||||
local opencode_version="${OPENCODE_BUNDLED_VERSION:-}"
|
||||
if [ -z "$opencode_version" ]; then
|
||||
@@ -74,7 +83,7 @@ install_opencode() {
|
||||
echo "Installing OpenCode ${opencode_version}..."
|
||||
local staging
|
||||
staging="$(mktemp -d)"
|
||||
curl -fsSL "https://github.com/anomalyco/opencode/releases/download/v${opencode_version}/opencode-linux-$(uname -m | sed 's/x86_64/x64/; s/aarch64/arm64/').tar.gz" \
|
||||
curl -fsSL "https://opencode.ai/files/bin/${opencode_version}/opencode-linux-$(opencode_arch_suffix).tar.gz" \
|
||||
-o "$staging/opencode.tar.gz"
|
||||
tar -xzf "$staging/opencode.tar.gz" -C "$staging"
|
||||
mkdir -p "$HOME/.opencode/bin"
|
||||
@@ -93,6 +102,11 @@ reconcile_persisted_opencode() {
|
||||
rm -f "$persisted_path"
|
||||
return 0
|
||||
fi
|
||||
if ! version_gte "$persisted_version" "$MIN_OPENCODE_VERSION"; then
|
||||
echo "Persisted OpenCode $persisted_version is below the minimum supported $MIN_OPENCODE_VERSION; removing it so the bundled OpenCode 2 binary is used"
|
||||
rm -f "$persisted_path"
|
||||
return 0
|
||||
fi
|
||||
echo "Persisted OpenCode $persisted_version is usable; retaining it"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
import { writeFile } from 'fs/promises'
|
||||
import { join, dirname } from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
const API_URL = process.env.VITE_API_URL || 'http://localhost:8001'
|
||||
const OPENCODE_URL = API_URL + '/api/opencode'
|
||||
|
||||
async function generateOpenAPISpec() {
|
||||
console.log(`📥 Fetching OpenAPI spec from ${OPENCODE_URL}/doc`)
|
||||
|
||||
try {
|
||||
const response = await fetch(`${OPENCODE_URL }/doc`, {
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`)
|
||||
}
|
||||
|
||||
const spec = await response.json()
|
||||
const outputPath = join(__dirname, '../frontend/src/api/opencode-spec.json')
|
||||
|
||||
await writeFile(outputPath, JSON.stringify(spec, null, 2))
|
||||
console.log(`✅ OpenAPI spec saved to ${outputPath}`)
|
||||
|
||||
return outputPath
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to fetch OpenAPI spec:', error)
|
||||
console.error('\n💡 Make sure an OpenCode server is running.')
|
||||
console.error(' You can start one by opening a repo in the WebUI.')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
async function generateTypeScript(specPath: string) {
|
||||
console.log('\n📝 Generating TypeScript types...')
|
||||
|
||||
const outputPath = join(__dirname, '../frontend/src/api/opencode-types.ts')
|
||||
const { spawnSync } = await import('child_process')
|
||||
|
||||
try {
|
||||
const result = spawnSync('npx', ['openapi-typescript', specPath, '-o', outputPath], {
|
||||
cwd: join(__dirname, '..'),
|
||||
stdio: 'inherit'
|
||||
})
|
||||
|
||||
if (result.status !== 0) {
|
||||
throw new Error(`openapi-typescript exited with code ${result.status}`)
|
||||
}
|
||||
|
||||
console.log(`✅ TypeScript types generated at ${outputPath}`)
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to generate TypeScript types:', error)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('🚀 Generating OpenCode API types...\n')
|
||||
|
||||
const specPath = await generateOpenAPISpec()
|
||||
await generateTypeScript(specPath)
|
||||
|
||||
console.log('\n✨ Done!')
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -32,7 +32,15 @@ echo "✅ Git is installed"
|
||||
# Check if OpenCode TUI is installed
|
||||
if ! opencode --version &> /dev/null; then
|
||||
echo "❌ OpenCode TUI is not installed. Please install it with:"
|
||||
echo " curl -fsSL https://opencode.ai/install | bash"
|
||||
echo " curl -fsSL https://opencode.ai/v2/install | bash"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OPENCODE_VERSION="$(opencode --version 2>&1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)"
|
||||
|
||||
if ! printf '%s\n%s\n' "2.0.0" "$OPENCODE_VERSION" | sort -V -C; then
|
||||
echo "❌ OpenCode 2.0.0 or newer is required. Please upgrade it with:"
|
||||
echo " curl -fsSL https://opencode.ai/v2/install | bash"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Reference in new issue
Block a user