From 316269e437072e28997d05df8ab394bf212b2b19 Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Wed, 4 Feb 2026 10:32:21 +0000 Subject: [PATCH] fix(codex): only remove top-level profile key, preserve profiles sections Use awk to track when we enter a TOML section and only remove 'profile =' lines that appear at the top level (before any [section] headers). This ensures user-provided [profiles.*] sections are preserved intact. --- registry/coder-labs/modules/codex/scripts/install.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/registry/coder-labs/modules/codex/scripts/install.sh b/registry/coder-labs/modules/codex/scripts/install.sh index d1fdd505..08e6643f 100644 --- a/registry/coder-labs/modules/codex/scripts/install.sh +++ b/registry/coder-labs/modules/codex/scripts/install.sh @@ -155,8 +155,15 @@ function populate_config_toml() { # This allows users to run `codex` without --profile flag if [ "$ARG_ENABLE_AIBRIDGE" = "true" ]; then printf "Setting aibridge as default profile\n" - # Remove any existing profile line from base config (since enable_aibridge=true is explicit) - sed -i '/^profile\s*=/d' "$CONFIG_PATH" + # Remove any existing top-level profile line (before first section header) + # This only removes profile = ... at top level, not inside [profiles.*] sections + awk ' + BEGIN { in_top_level = 1 } + /^\[/ { in_top_level = 0 } + in_top_level && /^profile[ \t]*=/ { next } + { print } + ' "$CONFIG_PATH" > "${CONFIG_PATH}.tmp" + mv "${CONFIG_PATH}.tmp" "$CONFIG_PATH" # Prepend profile = "aibridge" to the config local temp_config temp_config=$(cat "$CONFIG_PATH")