Skip to content

Commit 9b6c77f

Browse files
fix(opencode): pass --method curl to the native updater (pingdotgg#34169)
Co-authored-by: Mohamed Sayed <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 5a3e368 commit 9b6c77f

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,9 @@ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
815815
const native = executable(".opencode", "bin", "opencode");
816816
for (const generation of ["v1", "v2"] as const) {
817817
assert.isNull((yield* resolveUpdate(generation, launcher)).update);
818-
assert.deepStrictEqual((yield* resolveUpdate(generation, native)).update?.args, [
819-
"upgrade",
820-
]);
818+
const update = (yield* resolveUpdate(generation, native)).update;
819+
assert.deepStrictEqual(update?.args, ["upgrade", "--method", "curl"]);
820+
assert.strictEqual(update?.env?.HOME, root);
821821
}
822822
}),
823823
);

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,32 @@ function isOpenCodeNativeCommandPath(commandPath: string): boolean {
9393
);
9494
}
9595

96+
function openCodeNativeHome(commandPath: string): string | null {
97+
const slashed = commandPath.replaceAll("\\", "/");
98+
const match = /\/\.opencode\/bin\/opencode(?:\.exe)?$/i.exec(slashed);
99+
if (!match) return null;
100+
return match.index === 0 ? "/" : slashed.slice(0, match.index);
101+
}
102+
96103
/** Update only within the installed package generation; 2.x converts the shared database in place. */
97104
export const openCodeUpdateFor = (generation: ProbedOpenCode["generation"]) =>
98105
makePackageManagedProviderMaintenanceResolver({
99106
provider: DRIVER_KIND,
100107
npmPackageName: generation === "v2" ? "@opencode/cli" : "opencode-ai",
101108
nativeUpdate: {
102-
args: ["upgrade"],
109+
// `isOpenCodeNativeCommandPath` is the curl installer's own binary. Name the
110+
// method so OpenCode does not have to infer it from `process.execPath`, which
111+
// fails when the binary is launched through a wrapper or shim.
112+
args: ["upgrade", "--method", "curl"],
103113
isCommandPath: isOpenCodeNativeCommandPath,
104114
requiresCommandPath: true,
115+
// The curl installer writes to `$HOME/.opencode/bin`, so point HOME at the install it replaces.
116+
env: (context) => {
117+
const home =
118+
openCodeNativeHome(context.realCommandPath) ??
119+
openCodeNativeHome(context.resolvedCommandPath);
120+
return home ? { HOME: home } : {};
121+
},
105122
},
106123
// mise's `opencode` follows releases into 2.x, so it would upgrade 1.x across that line.
107124
mise: { tool: "opencode", upgrade: generation === "v2" },

0 commit comments

Comments
 (0)