()
| 1208 | } |
| 1209 | |
| 1210 | export async function getCodexAuthIndicators(): Promise<CodexAuthIndicators> { |
| 1211 | const result: CodexAuthIndicators = { |
| 1212 | hasAuthFile: false, |
| 1213 | hasOAuthToken: false, |
| 1214 | hasApiKey: false, |
| 1215 | }; |
| 1216 | |
| 1217 | try { |
| 1218 | const authContent = await systemPathReadFile(getCodexAuthPath()); |
| 1219 | result.hasAuthFile = true; |
| 1220 | |
| 1221 | try { |
| 1222 | const authJson = JSON.parse(authContent) as Record<string, unknown>; |
| 1223 | result.hasOAuthToken = hasNonEmptyStringField(authJson, CODEX_OAUTH_KEYS); |
| 1224 | result.hasApiKey = hasNonEmptyStringField(authJson, CODEX_API_KEY_KEYS); |
| 1225 | const nestedTokens = getNestedTokens(authJson); |
| 1226 | if (nestedTokens) { |
| 1227 | result.hasOAuthToken = |
| 1228 | result.hasOAuthToken || hasNonEmptyStringField(nestedTokens, CODEX_OAUTH_KEYS); |
| 1229 | result.hasApiKey = |
| 1230 | result.hasApiKey || hasNonEmptyStringField(nestedTokens, CODEX_API_KEY_KEYS); |
| 1231 | } |
| 1232 | } catch { |
| 1233 | // Ignore parse errors; file exists but contents are unreadable |
| 1234 | } |
| 1235 | } catch { |
| 1236 | // Auth file not found or inaccessible |
| 1237 | } |
| 1238 | |
| 1239 | return result; |
| 1240 | } |
| 1241 | |
| 1242 | // ============================================================================= |
| 1243 | // OpenCode CLI Detection |
no test coverage detected