Skip to content

Commit 0bd6e40

Browse files
committed
fix(opencode): run the native updater with the install's HOME
OpenCode's curl installer writes to $HOME/.opencode/bin, so --method curl upgraded the server's own install instead of a configured one under another home.
1 parent a704bbd commit 0bd6e40

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎packages/provider-opencode/src/server/driver.test.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -749,11 +749,9 @@ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
749749
const native = executable(".opencode", "bin", "opencode");
750750
for (const generation of ["v1", "v2"] as const) {
751751
assert.isNull((yield* resolveUpdate(generation, launcher)).update);
752-
assert.deepStrictEqual((yield* resolveUpdate(generation, native)).update?.args, [
753-
"upgrade",
754-
"--method",
755-
"curl",
756-
]);
752+
const update = (yield* resolveUpdate(generation, native)).update;
753+
assert.deepStrictEqual(update?.args, ["upgrade", "--method", "curl"]);
754+
assert.strictEqual(update?.env?.HOME, root);
757755
}
758756
}),
759757
);

‎packages/provider-opencode/src/server/driver.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,13 @@ function isOpenCodeNativeCommandPath(commandPath: string): boolean {
8080
);
8181
}
8282

83+
function openCodeNativeHome(commandPath: string): string | null {
84+
const slashed = commandPath.replaceAll("\\", "/");
85+
const match = /\/\.opencode\/bin\/opencode(?:\.exe)?$/i.exec(slashed);
86+
if (!match) return null;
87+
return match.index === 0 ? "/" : slashed.slice(0, match.index);
88+
}
89+
8390
/** Update only within the installed package generation; 2.x converts the shared database in place. */
8491
export const openCodeUpdateFor = (generation: ProbedOpenCode["generation"]) =>
8592
makePackageManagedProviderMaintenanceResolver({
@@ -92,6 +99,13 @@ export const openCodeUpdateFor = (generation: ProbedOpenCode["generation"]) =>
9299
args: ["upgrade", "--method", "curl"],
93100
isCommandPath: isOpenCodeNativeCommandPath,
94101
requiresCommandPath: true,
102+
// The curl installer writes to `$HOME/.opencode/bin`, so point HOME at the install it replaces.
103+
env: (context) => {
104+
const home =
105+
openCodeNativeHome(context.realCommandPath) ??
106+
openCodeNativeHome(context.resolvedCommandPath);
107+
return home ? { HOME: home } : {};
108+
},
95109
},
96110
// mise's `opencode` follows releases into 2.x, so it would upgrade 1.x across that line.
97111
mise: { tool: "opencode", upgrade: generation === "v2" },

0 commit comments

Comments
 (0)