Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/adapters/codex-desktop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/adapters/transcript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/codex-watcher.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
20 changes: 15 additions & 5 deletions src/run-recorder.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading