@@ -39,6 +39,24 @@ const defaultCodexConfig = [
3939const resolvePathFromBase = ( path : Path . Path , baseDir : string , targetPath : string ) : string =>
4040 path . isAbsolute ( targetPath ) ? targetPath : path . resolve ( baseDir , targetPath )
4141
42+ const codexConfigMarker = "# docker-git codex config"
43+
44+ const normalizeConfigText = ( text : string ) : string =>
45+ text
46+ . replaceAll ( "\r\n" , "\n" )
47+ . trim ( )
48+
49+ const shouldRewriteDockerGitCodexConfig = ( existing : string ) : boolean => {
50+ const normalized = normalizeConfigText ( existing )
51+ if ( normalized . length === 0 ) {
52+ return true
53+ }
54+ if ( ! normalized . startsWith ( codexConfigMarker ) ) {
55+ return false
56+ }
57+ return normalized !== normalizeConfigText ( defaultCodexConfig )
58+ }
59+
4260const shouldCopyEnv = ( sourceText : string , targetText : string ) : CopyDecision => {
4361 if ( sourceText . trim ( ) . length === 0 ) {
4462 return "skip"
@@ -142,8 +160,8 @@ const copyCodexFile = (
142160// FORMAT THEOREM: forall p: missing(config(p)) -> config(p)=defaults
143161// PURITY: SHELL
144162// EFFECT: Effect<void, PlatformError, FileSystem | Path>
145- // INVARIANT: does not overwrite existing config.toml
146- // COMPLEXITY: O(1)
163+ // INVARIANT: rewrites only docker-git-managed configs to keep defaults in sync
164+ // COMPLEXITY: O(n) where n = |config|
147165export const ensureCodexConfigFile = (
148166 baseDir : string ,
149167 codexAuthPath : string
@@ -154,6 +172,12 @@ export const ensureCodexConfigFile = (
154172 const configPath = path . join ( resolved , "config.toml" )
155173 const exists = yield * _ ( fs . exists ( configPath ) )
156174 if ( exists ) {
175+ const current = yield * _ ( fs . readFileString ( configPath ) )
176+ if ( ! shouldRewriteDockerGitCodexConfig ( current ) ) {
177+ return
178+ }
179+ yield * _ ( fs . writeFileString ( configPath , defaultCodexConfig ) )
180+ yield * _ ( Effect . log ( `Updated Codex config at ${ configPath } ` ) )
157181 return
158182 }
159183 yield * _ ( fs . makeDirectory ( resolved , { recursive : true } ) )
0 commit comments