diff --git a/package.json b/package.json index 3e4f00ba3f..0005577738 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "module", "packageManager": "bun@1.3.14", "scripts": { - "dev": "bun run --cwd packages/opencode --conditions=browser src/index.ts", + "dev": "bun run --cwd packages/opencode --conditions=node src/index.ts", "dev:local": "bun run packages/opencode/script/dev-local.ts", "dev:stats": "bun sst shell --stage=production -- bun run --cwd packages/stats/app dev", "dev:storybook": "bun --cwd packages/storybook storybook", diff --git a/packages/kilo-vscode/script/local-bin.ts b/packages/kilo-vscode/script/local-bin.ts index 177a2d4077..9a2f11f550 100644 --- a/packages/kilo-vscode/script/local-bin.ts +++ b/packages/kilo-vscode/script/local-bin.ts @@ -30,6 +30,7 @@ const forceRebuild = process.argv.includes("--force") const kiloVscodeDir = join(import.meta.dir, "..") const packagesDir = join(kiloVscodeDir, "..") +const repoDir = join(packagesDir, "..") const opencodeDir = join(packagesDir, "opencode") const coreDir = join(packagesDir, "core") const gatewayDir = join(packagesDir, "kilo-gateway") @@ -150,20 +151,20 @@ async function ensureBuiltBinary(): Promise { `No prebuilt binary found under ${relative(kiloVscodeDir, join(opencodeDir, "dist"))} - attempting build via bun.`, ) - const bunPath = Bun.which("bun") - if (!bunPath) { + if (!Bun.which("bun")) { throw new Error( `Bun is required to build the CLI binary, but was not found on PATH. ` + `Install bun, or build the CLI separately in ${opencodeDir} and re-run.`, ) } - // Ensure dependencies are installed before building. + // Use the repository-pinned Bun version throughout. Newer canaries can fail compilation + // and must not cause packaged snapshots to fall back to the browser-mode source wrapper. + const pkg = await Bun.file(join(repoDir, "package.json")).json() + const bun = String(pkg.packageManager) log("Installing dependencies in opencode package...") - await $`bun install --frozen-lockfile`.cwd(opencodeDir) - - // Build using the opencode package script. - await $`bun run build --single`.cwd(opencodeDir) + await $`bunx ${bun} install --frozen-lockfile`.cwd(opencodeDir) + await $`bunx ${bun} run build --single --skip-install`.cwd(opencodeDir) const built = await findKiloBinaryInOpencodeDist() if (!built) { @@ -205,7 +206,7 @@ async function writeSourceWrapper() { "#!/usr/bin/env bash", "set -euo pipefail", `cd ${JSON.stringify(opencodeDir)}`, - `exec ${JSON.stringify(bun)} --conditions=browser src/index.ts "$@"`, + `exec ${JSON.stringify(bun)} --conditions=node src/index.ts "$@"`, "", ].join("\n"), ) @@ -255,6 +256,7 @@ async function main() { } const sourceBinPath = await ensureBuiltBinary().catch(async (err) => { + if (forceRebuild) throw err await writeSourceWrapper() log(`Wrapper fallback reason: ${err instanceof Error ? err.message : String(err)}`) return null diff --git a/packages/opencode/package.json b/packages/opencode/package.json index 588fb4b511..7af10612ee 100644 --- a/packages/opencode/package.json +++ b/packages/opencode/package.json @@ -12,8 +12,8 @@ "bench:test": "bun run script/bench-test-suite.ts", "profile:test": "bun run script/profile-test-files.ts", "build": "bun run script/build.ts", - "dev": "bun run --conditions=browser ./src/index.ts", - "dev:temporary": "bun run --conditions=browser ./src/temporary.ts", + "dev": "bun run --conditions=node ./src/index.ts", + "dev:temporary": "bun run --conditions=node ./src/temporary.ts", "test:ci": "bun run script/test-runner.ts --ci" }, "bin": {