|
113 | 113 | ) |
114 | 114 | from headroom.providers.claude.runtime import TOOL_SEARCH_FOUNDRY_DEFAULT |
115 | 115 | from headroom.providers.codex import build_launch_env as _build_codex_launch_env |
| 116 | +from headroom.providers.codex.config_toml import loads_codex_config |
116 | 117 | from headroom.providers.codex.install import ( |
117 | 118 | CodexAuthConfigError, |
118 | 119 | build_codex_auth_config, |
@@ -3086,7 +3087,7 @@ def _codex_session_launch_settings( |
3086 | 3087 | """Build process-local routing while preserving the selected provider id.""" |
3087 | 3088 | config_file, _ = _codex_config_paths() |
3088 | 3089 | try: |
3089 | | - config = tomllib.loads(_read_text(config_file)) if config_file.exists() else {} |
| 3090 | + config = loads_codex_config(_read_text(config_file)) if config_file.exists() else {} |
3090 | 3091 | except (OSError, tomllib.TOMLDecodeError) as exc: |
3091 | 3092 | raise click.ClickException( |
3092 | 3093 | f"could not read Codex config for session routing: {exc}" |
@@ -3718,10 +3719,10 @@ def _build_top_level_block(user_content: str) -> str: |
3718 | 3719 | # name a line the user never wrote. Only the user's part has to |
3719 | 3720 | # parse: stripping a stale Headroom block may be what repairs it. |
3720 | 3721 | try: |
3721 | | - tomllib.loads(content) |
| 3722 | + loads_codex_config(content) |
3722 | 3723 | except tomllib.TOMLDecodeError: |
3723 | 3724 | try: |
3724 | | - tomllib.loads(original) |
| 3725 | + loads_codex_config(original) |
3725 | 3726 | reason = "it is no longer valid TOML once Headroom's block is removed" |
3726 | 3727 | except tomllib.TOMLDecodeError as exc: |
3727 | 3728 | reason = f"it is not valid TOML ({exc})" |
@@ -3769,7 +3770,7 @@ def _build_top_level_block(user_content: str) -> str: |
3769 | 3770 | ) |
3770 | 3771 |
|
3771 | 3772 | # Never replace a usable config with a malformed generated candidate. |
3772 | | - tomllib.loads(content) |
| 3773 | + loads_codex_config(content) |
3773 | 3774 | _write_text(config_file, content) |
3774 | 3775 | click.echo(f" Codex config: injected Headroom provider (WS + HTTP) into {config_file}") |
3775 | 3776 | if custom_upstream_base_url: |
@@ -4066,7 +4067,7 @@ def _inject_memory_mcp_config(user_id: str) -> None: |
4066 | 4067 | content = mcp_section |
4067 | 4068 |
|
4068 | 4069 | # Never replace a usable config with a malformed generated candidate. |
4069 | | - tomllib.loads(content) |
| 4070 | + loads_codex_config(content) |
4070 | 4071 | _write_text(config_file, content) |
4071 | 4072 | click.echo(f" Memory MCP: registered in {config_file}") |
4072 | 4073 | except Exception as e: |
|
0 commit comments