Skip to content

Commit d3b06b8

Browse files
committed
fix(docker-git): propagate default Codex config to new containers
- Rewrite docker-git-managed Codex config.toml when defaults change - Ensure per-project .orch/auth/codex/config.toml is updated on create and up
1 parent 6b1668b commit d3b06b8

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

effect-template/packages/lib/src/usecases/actions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ const prepareProjectFiles = (
233233
}
234234
})
235235
)
236+
// Ensure per-project config stays in sync even when `.orch/auth/codex` already exists.
237+
yield* _(ensureCodexConfigFile(resolvedOutDir, projectConfig.codexAuthPath))
236238
return createdFiles
237239
})
238240

effect-template/packages/lib/src/usecases/auth-sync.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ const defaultCodexConfig = [
3939
const 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+
4260
const 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|
147165
export 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 }))

effect-template/packages/lib/src/usecases/projects-up.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import type {
2020
PortProbeError
2121
} from "../shell/errors.js"
2222
import { writeProjectFiles } from "../shell/files.js"
23+
import { ensureCodexConfigFile } from "./auth-sync.js"
2324
import { loadReservedPorts, selectAvailablePort } from "./ports-reserve.js"
2425
import { parseComposePsOutput } from "./projects-core.js"
2526

@@ -94,6 +95,7 @@ export const runDockerComposeUpWithPortCheck = (
9495
: yield* _(ensureAvailableSshPort(projectDir, config))
9596
// Keep generated templates in sync with the running CLI version.
9697
yield* _(writeProjectFiles(projectDir, updated, true))
98+
yield* _(ensureCodexConfigFile(projectDir, updated.codexAuthPath))
9799
yield* _(runDockerComposeUp(projectDir))
98100

99101
const ensureBridgeAccess = (containerName: string) =>

0 commit comments

Comments
 (0)