fix(converters): preserve Codex config on no-MCP install (#564)
This commit is contained in:
@@ -116,12 +116,29 @@ async function readFileSafe(filePath: string): Promise<string> {
|
||||
export function mergeCodexConfig(existingContent: string, mcpToml: string | null): string | null {
|
||||
// Strip current and previous managed blocks
|
||||
let stripped = existingContent
|
||||
let removedManagedBlock = false
|
||||
for (const [start, end] of [[MANAGED_START_MARKER, MANAGED_END_MARKER], [PREV_START_MARKER, PREV_END_MARKER]]) {
|
||||
stripped = stripped.replace(
|
||||
const next = stripped.replace(
|
||||
new RegExp(`${escapeForRegex(start)}[\\s\\S]*?${escapeForRegex(end)}\\n?`, "g"),
|
||||
"",
|
||||
)
|
||||
if (next !== stripped) removedManagedBlock = true
|
||||
stripped = next
|
||||
}
|
||||
|
||||
// No MCP servers to write — only remove bounded managed blocks. Do not strip
|
||||
// unmarked legacy markers here: old Codex config files may contain user
|
||||
// settings after "# Generated by compound-plugin", and there is no safe
|
||||
// boundary for deleting only plugin-owned TOML.
|
||||
if (!mcpToml) {
|
||||
if (!existingContent) return null
|
||||
const legacyMarkerIndex = stripped.indexOf(LEGACY_MARKER)
|
||||
if (legacyMarkerIndex !== -1) {
|
||||
return stripped.slice(0, legacyMarkerIndex).trimEnd()
|
||||
}
|
||||
return removedManagedBlock ? stripped.trimEnd() : existingContent
|
||||
}
|
||||
|
||||
stripped = stripped.trimEnd()
|
||||
|
||||
// Strip from legacy markers to end of content (old formats wrote everything after the marker)
|
||||
@@ -133,12 +150,6 @@ export function mergeCodexConfig(existingContent: string, mcpToml: string | null
|
||||
}
|
||||
}
|
||||
|
||||
// No MCP servers to write — return cleaned content, or null only if there was never a file
|
||||
if (!mcpToml) {
|
||||
if (!existingContent) return null
|
||||
return cleaned
|
||||
}
|
||||
|
||||
const managedBlock = [
|
||||
MANAGED_START_MARKER,
|
||||
mcpToml.trim(),
|
||||
|
||||
Reference in New Issue
Block a user