(cwd: string)
| 179 | }, |
| 180 | |
| 181 | async readAiConfig(cwd: string): Promise<WorkspaceAiCred | null> { |
| 182 | const tomlRaw = await readWorkspaceFile(cwd, CODEX_CONFIG_PATH); |
| 183 | const envRaw = await readWorkspaceFile(cwd, CODEX_ENV_PATH); |
| 184 | if (tomlRaw === null && envRaw === null) return null; |
| 185 | |
| 186 | let baseUrl: string | null = null; |
| 187 | let wireApi: 'chat' | 'responses' | null = null; |
| 188 | let model: string | null = null; |
| 189 | if (tomlRaw) { |
| 190 | // Shape-specific extraction: we always write the provider section as |
| 191 | // `[model_providers.workspace]` with `base_url`, `wire_api`, plus |
| 192 | // top-level `model`. Regex is brittle in general but our shape is |
| 193 | // controlled (writer above produces deterministic output). |
| 194 | const providerBlock = tomlRaw.match(/\[model_providers\.workspace\][^\[]*/); |
| 195 | if (providerBlock) { |
| 196 | const block = providerBlock[0]; |
| 197 | const base = block.match(/base_url\s*=\s*"([^"]*)"/); |
| 198 | if (base) baseUrl = base[1] ?? null; |
| 199 | const wire = block.match(/wire_api\s*=\s*"(chat|responses)"/); |
| 200 | if (wire) wireApi = wire[1] as 'chat' | 'responses'; |
| 201 | } |
| 202 | const modelMatch = tomlRaw.match(/^model\s*=\s*"([^"]*)"\s*$/m); |
| 203 | if (modelMatch) model = modelMatch[1] ?? null; |
| 204 | } |
| 205 | |
| 206 | let apiKey: string | null = null; |
| 207 | if (envRaw) { |
| 208 | try { |
| 209 | const env = JSON.parse(envRaw) as Record<string, unknown>; |
| 210 | const k = env[CODEX_KEY_ENV_NAME]; |
| 211 | if (typeof k === 'string') apiKey = k; |
| 212 | } catch { /* ignore parse error, leave apiKey null */ } |
| 213 | } |
| 214 | |
| 215 | if (baseUrl === null && apiKey === null && model === null && wireApi === null) return null; |
| 216 | // Codex is Responses-only, so the unified wireShape is always openai-responses. |
| 217 | return { baseUrl, apiKey, model, wireApi, wireShape: 'openai-responses' }; |
| 218 | }, |
| 219 | |
| 220 | /** |
| 221 | * Set `CODEX_HOME` only when workspace has its own `.codex/` directory |
nothing calls this directly
no test coverage detected