|
58 | 58 | from headroom.install.supervisors import start_supervisor |
59 | 59 | from headroom.providers.claude import TOOL_SEARCH_DEFAULT, TOOL_SEARCH_ENV |
60 | 60 | from headroom.providers.claude.runtime import TOOL_SEARCH_FOUNDRY_DEFAULT |
61 | | -from headroom.providers.codex.config_toml import loads_codex_config |
| 61 | +from headroom.providers.codex.config_toml import loads_codex_config, root_assignment_lines |
62 | 62 | from headroom.providers.codex.install import ( |
63 | 63 | CodexAuthConfigError, |
64 | 64 | build_codex_auth_config, |
|
92 | 92 | # report ready, and every session is permanently cold. |
93 | 93 | _HOOK_ENSURE_TIMEOUT_SECONDS = 60 |
94 | 94 | _TOML_TABLE_HEADER_RE = re.compile(r"^[ \t]*(?:\[\[[^\]\r\n]+\]\]|\[[^\]\r\n]+\])[ \t]*(?:#.*)?$") |
| 95 | +_ROOT_PROVIDER_KEY_RE = re.compile(r"[ \t]*(?:model_provider|openai_base_url)[ \t]*=") |
95 | 96 | _TOML_FEATURES_NAME_RE = r"(?:features|\"features\"|'features')" |
96 | 97 | _TOML_CODEX_HOOKS_NAME_RE = r"(?:codex_hooks|\"codex_hooks\"|'codex_hooks')" |
97 | 98 | _CODEX_FEATURES_TABLE_RE = re.compile( |
@@ -471,12 +472,14 @@ def _ensure_codex_provider(path: Path, port: int) -> None: |
471 | 472 | # first table header) -- these keys also appear legitimately inside |
472 | 473 | # [profiles.*] tables as per-profile overrides, and stripping them there |
473 | 474 | # silently reroutes the user's profiles to the injected "headroom" default. |
474 | | - _first_table = re.search(r"(?m)^[ \t]*\[", content) |
475 | | - _split = _first_table.start() if _first_table else len(content) |
476 | | - root, rest = content[:_split], content[_split:] |
477 | | - root = re.sub(r"(?m)^[ \t]*model_provider[ \t]*=.*\r?\n", "", root) |
478 | | - root = re.sub(r"(?m)^[ \t]*openai_base_url[ \t]*=.*\r?\n", "", root) |
479 | | - content = root + rest |
| 475 | + # Lines nested in a multi-line inline table (e.g. ``profiles = {``) are |
| 476 | + # profile overrides too, so only true root assignments are dropped. |
| 477 | + _root_lines = root_assignment_lines(content) |
| 478 | + content = "".join( |
| 479 | + line |
| 480 | + for index, line in enumerate(content.splitlines(keepends=True)) |
| 481 | + if index not in _root_lines or not _ROOT_PROVIDER_KEY_RE.match(line) |
| 482 | + ) |
480 | 483 | # The provider block carries top-level keys (model_provider, openai_base_url), |
481 | 484 | # so it must land at the document root rather than after a trailing table (#260). |
482 | 485 | content = _replace_marker_block( |
|
0 commit comments