feat(desktop): bundle pinned OpenCode CLI

Bundle the official OpenCode CLI into Electron desktop builds instead of relying on whichever opencode executable happens to be first on PATH. Pin @opencode-ai/sdk to an exact version and use that version as the source of truth for the downloaded CLI artifact.

Add an Electron prepare script that maps the current platform/arch to the official OpenCode release artifact, downloads it from GitHub releases, caches the archive under packages/electron/.cache, stages the binary under resources/opencode-cli, verifies opencode --version, and skips work when the staged binary already matches.

Prefer explicit OpenCode binary overrides first, then the bundled Electron CLI, then PATH/system installs. Keep rejecting the Windows OpenCode desktop app executable as a CLI candidate and add resolver tests for bundled priority, explicit override priority, resourcesPath lookup, and desktop-app rejection.

Suppress OpenCode CLI update prompts when the active CLI source is bundled. The server now reports upgrade-status as unavailable for bundled CLI while still returning the current OpenCode version for About, and rejects direct upgrade attempts with a 409 instead of trying to mutate the bundled binary.

Update desktop release, smoke, and manual macOS DMG workflows to prepare and verify the bundled CLI before packaging, verify the packaged app contains the expected CLI, cache downloads by OS/arch/OpenCode version, and align the Windows smoke runner with production windows-2022.

Document desktop bundling behavior, ignore generated CLI/cache files, add oc-dev helpers, and keep Web/VS Code behavior dependent on installed OpenCode CLI rather than desktop bundled resources.
This commit is contained in:
Bohdan Triapitsyn
2026-07-02 17:43:33 +03:00
parent bd8ab070e7
commit 33ecd628bd
20 changed files with 640 additions and 34 deletions
+13
View File
@@ -53,6 +53,7 @@ Actions:
start-mobile-dev Start mobile app with dev server live reload
mobile-tools Mobile build/sync/deploy helper menu
start-electron-app Start Electron app in dev mode
prepare-opencode-cli Download/cache bundled OpenCode CLI for Electron
build-electron-app Build Electron app artifacts
start-vscode-extension Build + launch VS Code extension host
install-vscode-extension-local Build, package, and install local VSIX
@@ -180,6 +181,8 @@ function normalizeAction(action = '') {
'mobile-menu': 'mobile-tools',
'remote-deploy-web': 'remote-deploy-web',
'electron-dev': 'start-electron-app',
'opencode-cli': 'prepare-opencode-cli',
'electron-opencode-cli': 'prepare-opencode-cli',
'electron-build': 'build-electron-app',
'vscode-dev': 'start-vscode-extension',
'vscode-install-local': 'install-vscode-extension-local',
@@ -474,10 +477,16 @@ async function mobileTools(options, config) {
}
function startElectronApp() {
prepareOpenCodeCli();
run('bun', ['run', 'electron:dev']);
}
function prepareOpenCodeCli() {
step('Preparing bundled OpenCode CLI', () => run('bun', ['--filter', '@openchamber/electron', 'prepare:opencode-cli']));
}
function buildElectronApp() {
prepareOpenCodeCli();
run('bun', ['run', 'electron:build'], { env: { CSC_IDENTITY_AUTO_DISCOVERY: 'false' } });
const distDir = path.join(repoRoot, 'packages/electron/dist');
if (!existsSync(distDir) || !isMac) return;
@@ -543,6 +552,7 @@ async function chooseAction(config) {
{ value: 'start-mobile-dev', label: 'Start mobile dev' },
{ value: 'mobile-tools', label: 'Mobile tools' },
{ value: 'start-electron-app', label: 'Start Electron app' },
{ value: 'prepare-opencode-cli', label: 'Prepare bundled OpenCode CLI' },
{ value: 'build-electron-app', label: 'Build Electron app' },
{ value: 'start-vscode-extension', label: 'Start VS Code extension' },
{ value: 'install-vscode-extension-local', label: 'Install VS Code extension locally' },
@@ -589,6 +599,9 @@ async function main() {
case 'start-electron-app':
startElectronApp();
break;
case 'prepare-opencode-cli':
prepareOpenCodeCli();
break;
case 'build-electron-app':
buildElectronApp();
break;