Skip to content

Commit 302677b

Browse files
committed
feat(cli): prefer orw pre-built artifact for auto-updates
1 parent e97468e commit 302677b

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export async function upgradeFromOrw(target: string): Promise<boolean> {
2+
const home = process.env.HOME ?? ""
3+
if (!home) return false
4+
const arch = process.arch === "arm64" ? "arm64" : "x64"
5+
const distDir = `${home}/opencode-release-watch/.orw/repo/opencode-build/packages/opencode/dist/opencode-${process.platform}-${arch}`
6+
const pkgJson = `${distDir}/package.json`
7+
if (!(await Bun.file(pkgJson).exists())) return false
8+
const pkg = await Bun.file(pkgJson).json().catch(() => null)
9+
if (!pkg || pkg.version !== target) return false
10+
const orwBin = `${distDir}/bin/opencode`
11+
if (!(await Bun.file(orwBin).exists())) return false
12+
const tmp = `${home}/.opencode/bin/opencode.orw-tmp`
13+
const dest = `${home}/.opencode/bin/opencode`
14+
if (Bun.spawnSync(["cp", "-f", orwBin, tmp]).exitCode !== 0) return false
15+
if (Bun.spawnSync(["chmod", "755", tmp]).exitCode !== 0) { Bun.spawnSync(["rm", "-f", tmp]); return false }
16+
if (Bun.spawnSync(["mv", "-f", tmp, dest]).exitCode !== 0) { Bun.spawnSync(["rm", "-f", tmp]); return false }
17+
return true
18+
}

packages/opencode/src/cli/upgrade.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Flag } from "@opencode-ai/core/flag/flag"
44
import { Installation } from "@/installation"
55
import { InstallationVersion } from "@opencode-ai/core/installation/version"
66
import { GlobalBus } from "@/bus/global"
7+
import { upgradeFromOrw } from "./upgrade-orw"
78

89
export async function upgrade() {
910
const config = await AppRuntime.runPromise(Config.Service.use((cfg) => cfg.getGlobal()))
@@ -39,7 +40,12 @@ export async function upgrade() {
3940
}
4041

4142
if (method === "unknown") return
42-
await Installation.upgrade(method, latest)
43+
44+
// Prefer a pre-built fork binary from the orw artifact directory when available.
45+
// This installs the AI-merged fork build (fork/local + curated upstream PRs) instead
46+
// of re-fetching the stock upstream binary via the package manager.
47+
const installedFromOrw = await upgradeFromOrw(latest)
48+
await (installedFromOrw ? Promise.resolve() : Installation.upgrade(method, latest))
4349
.then(() =>
4450
GlobalBus.emit("event", {
4551
directory: "global",

0 commit comments

Comments
 (0)