@@ -55,7 +55,9 @@ import { withInstanceIdentity } from "./instanceIdentity.ts";
5555import { mergeProviderInstanceEnvironment } from "../ProviderInstanceEnvironment.ts" ;
5656import {
5757 enrichProviderSnapshotWithVersionAdvisory ,
58+ makeCachedProviderMaintenanceResolution ,
5859 makePackageManagedProviderMaintenanceResolver ,
60+ normalizeCommandPath ,
5961 resolveProviderMaintenanceCapabilitiesEffect ,
6062} from "../providerMaintenance.ts" ;
6163import {
@@ -71,12 +73,29 @@ import {
7173const decodeCodexSettings = Schema . decodeSync ( CodexSettings ) ;
7274
7375const DRIVER_KIND = ProviderDriverKind . make ( "codex" ) ;
74- const UPDATE = makePackageManagedProviderMaintenanceResolver ( {
75- provider : DRIVER_KIND ,
76- npmPackageName : "@openai/codex" ,
77- homebrewFormula : "codex" ,
78- nativeUpdate : null ,
79- } ) ;
76+ // The standalone installer lays out `<CODEX_HOME>/packages/standalone/…`;
77+ // CODEX_HOME is not always `~/.codex`.
78+ function isCodexStandaloneCommandPath ( commandPath : string ) : boolean {
79+ return normalizeCommandPath ( commandPath ) . includes ( "/packages/standalone/" ) ;
80+ }
81+
82+ /**
83+ * `codex update` replaces the standalone tree under `CODEX_HOME`. That tree
84+ * lives in the shared home even when an auth-overlay shadow home is in use
85+ * (the overlay only carries auth and a few local entries), so the updater
86+ * runs against `sharedHomePath` rather than the instance's effective home.
87+ */
88+ function makeCodexMaintenanceResolver ( sharedHomePath : string ) {
89+ return makePackageManagedProviderMaintenanceResolver ( {
90+ provider : DRIVER_KIND ,
91+ npmPackageName : "@openai/codex" ,
92+ nativeUpdate : {
93+ args : [ "update" ] ,
94+ isCommandPath : isCodexStandaloneCommandPath ,
95+ env : { CODEX_HOME : sharedHomePath } ,
96+ } ,
97+ } ) ;
98+ }
8099
81100/**
82101 * Services the driver needs to materialize an instance. Surfaced as the
@@ -108,6 +127,8 @@ export const CodexDriver: ProviderDriver<CodexSettings, CodexDriverEnv> = {
108127 Effect . gen ( function * ( ) {
109128 const spawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
110129 const resetCreditCoordinator = yield * CodexResetCreditCoordinator ;
130+ const fileSystem = yield * FileSystem . FileSystem ;
131+ const pathService = yield * Path . Path ;
111132 const httpClient = yield * HttpClient . HttpClient ;
112133 const serverSettings = yield * ServerSettingsService ;
113134 const eventLoggers = yield * ProviderEventLoggers ;
@@ -138,10 +159,19 @@ export const CodexDriver: ProviderDriver<CodexSettings, CodexDriverEnv> = {
138159 enabled,
139160 homePath : homeLayout . effectiveHomePath ?? "" ,
140161 } satisfies CodexSettings ;
141- const maintenanceCapabilities = yield * resolveProviderMaintenanceCapabilitiesEffect ( UPDATE , {
142- binaryPath : effectiveConfig . binaryPath ,
143- env : processEnv ,
144- } ) ;
162+ const resolveMaintenance = yield * makeCachedProviderMaintenanceResolution (
163+ resolveProviderMaintenanceCapabilitiesEffect (
164+ makeCodexMaintenanceResolver ( homeLayout . sharedHomePath ) ,
165+ {
166+ binaryPath : effectiveConfig . binaryPath ,
167+ env : processEnv ,
168+ } ,
169+ ) . pipe (
170+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
171+ Effect . provideService ( FileSystem . FileSystem , fileSystem ) ,
172+ Effect . provideService ( Path . Path , pathService ) ,
173+ ) ,
174+ ) ;
145175
146176 // `makeCodexAdapter` and `makeCodexTextGeneration` have `never` error
147177 // channels at construction time — their failure modes are all on the
@@ -177,7 +207,7 @@ export const CodexDriver: ProviderDriver<CodexSettings, CodexDriverEnv> = {
177207 ) ;
178208 const snapshotSettings = makeProviderSnapshotSettingsSource ( effectiveConfig , serverSettings ) ;
179209 const snapshot = yield * makeManagedServerProvider < ProviderSnapshotSettings < CodexSettings > > ( {
180- maintenanceCapabilities ,
210+ resolveMaintenance ,
181211 getSettings : snapshotSettings . getSettings ,
182212 streamSettings : snapshotSettings . streamSettings ,
183213 haveSettingsChanged : haveProviderSnapshotSettingsChanged ,
@@ -190,9 +220,12 @@ export const CodexDriver: ProviderDriver<CodexSettings, CodexDriverEnv> = {
190220 ) ,
191221 checkProvider,
192222 enrichSnapshot : ( { settings, snapshot, publishSnapshot } ) =>
193- enrichProviderSnapshotWithVersionAdvisory ( snapshot , maintenanceCapabilities , {
194- enableProviderUpdateChecks : settings . enableProviderUpdateChecks ,
195- } ) . pipe (
223+ resolveMaintenance ( ) . pipe (
224+ Effect . flatMap ( ( maintenanceCapabilities ) =>
225+ enrichProviderSnapshotWithVersionAdvisory ( snapshot , maintenanceCapabilities , {
226+ enableProviderUpdateChecks : settings . enableProviderUpdateChecks ,
227+ } ) ,
228+ ) ,
196229 Effect . provideService ( HttpClient . HttpClient , httpClient ) ,
197230 Effect . flatMap ( ( enrichedSnapshot ) => publishSnapshot ( enrichedSnapshot ) ) ,
198231 ) ,
0 commit comments