@@ -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 = / \/ \. o p e n c o d e \/ b i n \/ o p e n c o d e (?: \. e x e ) ? $ / 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. */
97104export 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