diff --git a/src/app/api/cli-tools/codex-settings/route.ts b/src/app/api/cli-tools/codex-settings/route.ts index deac929dae..5cf1151a1d 100644 --- a/src/app/api/cli-tools/codex-settings/route.ts +++ b/src/app/api/cli-tools/codex-settings/route.ts @@ -38,9 +38,16 @@ const parseToml = (content: string) => { // Key = value const kvMatch = trimmed.match(/^([^=]+)\s*=\s*(.+)$/); if (kvMatch) { - const key = kvMatch[1].trim(); + let key = kvMatch[1].trim(); let value = kvMatch[2].trim(); - // Remove quotes + // Strip quotes from key (TOML quoted keys like "gpt-5.3-codex") + if ( + (key.startsWith('"') && key.endsWith('"')) || + (key.startsWith("'") && key.endsWith("'")) + ) { + key = key.slice(1, -1); + } + // Remove quotes from string values only (not arrays, booleans, numbers) if ( (value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'")) @@ -58,13 +65,23 @@ const parseToml = (content: string) => { return result; }; +// Format a TOML value: arrays and booleans stay unquoted, strings get quoted +const formatTomlValue = (value: unknown): string => { + if (typeof value === "boolean") return value ? "true" : "false"; + if (typeof value === "number") return String(value); + // Preserve pre-formatted TOML arrays (e.g. ["a", "b"]) + if (typeof value === "string" && value.startsWith("[") && value.endsWith("]")) return value; + if (typeof value === "string") return `"${value}"`; + return `"${value}"`; +}; + // Convert parsed object back to TOML string const toToml = (parsed: Record) => { let lines: string[] = []; // Root level keys Object.entries(parsed._root).forEach(([key, value]) => { - lines.push(`${key} = "${value}"`); + lines.push(`${key} = ${formatTomlValue(value)}`); }); // Sections @@ -73,7 +90,7 @@ const toToml = (parsed: Record) => { lines.push(`[${section}]`); Object.entries(values).forEach(([key, value]) => { const formattedKey = key.includes(".") ? `"${key}"` : key; - lines.push(`${formattedKey} = "${value}"`); + lines.push(`${formattedKey} = ${formatTomlValue(value)}`); }); });