diff --git a/src/adapters/codex-desktop.mjs b/src/adapters/codex-desktop.mjs index 1ad678a..a7f114d 100644 --- a/src/adapters/codex-desktop.mjs +++ b/src/adapters/codex-desktop.mjs @@ -58,7 +58,7 @@ function extractUserMessage(body) { return m ? unescapeRust(m[1]).trim() : null; } -// Extract per-turn billed usage from response.completed WebSocket event +// Extract per-turn billed usage and model from response.completed WebSocket event function extractResponseUsage(body) { if (!body?.includes('"type":"response.completed"')) return null; try { @@ -71,6 +71,7 @@ function extractResponseUsage(body) { input_tokens: u.input_tokens ?? 0, output_tokens: u.output_tokens ?? 0, cached_tokens: u.input_tokens_details?.cached_tokens ?? 0, + model: data?.response?.model ?? null, }; } catch { return null; @@ -167,6 +168,7 @@ export async function readNewSessions(sinceId = 0, dbPath = DEFAULT_DB_PATH) { t.billed_input += u.input_tokens; t.billed_output += u.output_tokens; t.billed_cached += u.cached_tokens; + if (!t.model && u.model) t.model = u.model; } } diff --git a/src/adapters/transcript.mjs b/src/adapters/transcript.mjs index fcca2e7..5159e0f 100644 --- a/src/adapters/transcript.mjs +++ b/src/adapters/transcript.mjs @@ -49,7 +49,7 @@ export function extractFromTranscript(lines) { const msg = entry.message ?? {}; const u = msg.usage ?? {}; - if (msg.model && !model) model = msg.model; + if (msg.model && !model && !msg.model.startsWith('<')) model = msg.model; if (u.input_tokens != null || u.output_tokens != null) { hasUsage = true; diff --git a/src/codex-watcher.mjs b/src/codex-watcher.mjs index f4024f3..de217cf 100644 --- a/src/codex-watcher.mjs +++ b/src/codex-watcher.mjs @@ -99,7 +99,6 @@ async function recordCodexDesktopSession(session) { usage, session: { session_id: runId }, tools: { command_count: 0, commands: [] }, - files: { read_count: 0, reads: [] }, diff: { files_changed: countPatchFiles(patch) }, artifacts: { events: 'events.jsonl', diff --git a/src/run-recorder.mjs b/src/run-recorder.mjs index 802b460..da3993b 100644 --- a/src/run-recorder.mjs +++ b/src/run-recorder.mjs @@ -293,13 +293,23 @@ function inferModelFromArgs(command) { } async function readCodexConfiguredModel() { + // CODEX_MODEL env var takes priority + if (process.env.CODEX_MODEL) return process.env.CODEX_MODEL; + // Try config.toml try { - const config = await readFile(join(homedir(), '.codex', 'config.toml'), 'utf8'); - const match = config.match(/^model\s*=\s*"([^"]+)"/m); - return match?.[1] ?? null; - } catch { - return null; + const toml = await readFile(join(homedir(), '.codex', 'config.toml'), 'utf8'); + const m = toml.match(/^model\s*=\s*"([^"]+)"/m); + if (m) return m[1]; + } catch { /* no file */ } + // Try config.yaml / config.yml + for (const name of ['config.yaml', 'config.yml']) { + try { + const yaml = await readFile(join(homedir(), '.codex', name), 'utf8'); + const m = yaml.match(/^model\s*:\s*["']?([^\s"']+)/m); + if (m) return m[1]; + } catch { /* no file */ } } + return null; } function withoutType(observation) {