Skip to content

Commit ebb7760

Browse files
unhappychoiceclaude
andcommitted
feat(fetcher): add codex_usage — local Codex CLI session rollup
Walks `~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl` (or `$CODEX_HOME/sessions/...`) via the helpers shipped in the family scaffold, extracts per-turn token usage from each `event_msg` of type `token_count`, and aggregates by project / model / day. The `turn_context` event that precedes each turn carries the model id and `cwd`; we thread that state forward as we parse so usage gets attributed to the right turn. Shape coverage matches `claude_code_usage`: Text / TextBlock / MarkdownTextBlock / Entries / Bars / NumberSeries / Badge (seven). Options mirror it too — `since` (today/7d/30d/all), `limit`, `group_by` (project/model/day). `Safety::Safe` — every read is local; unknown models contribute $0 rather than hiding their token activity behind an error. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent b8c1be2 commit ebb7760

2 files changed

Lines changed: 844 additions & 9 deletions

File tree

‎src/fetcher/codex/mod.rs‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
//! Codex (OpenAI Codex CLI) fetchers.
22
//!
3-
//! Scaffolding for the family. Individual fetchers (`codex_usage`, `codex_subscription`,
4-
//! etc.) live as siblings of [`common`] and register through [`fetchers`].
3+
//! - [`usage::CodexUsage`] aggregates the local `rollout-*.jsonl` files Codex CLI writes for
4+
//! every session, with zero configuration and no network.
55
//!
6-
//! `Safety::Safe` — every member of the family reads from `~/.codex/sessions/` (or the
7-
//! `CODEX_HOME` override) and never opens a network connection.
6+
//! `Safety::Safe` — every read is rooted at `~/.codex/sessions/` (or the `CODEX_HOME`
7+
//! override) and no network connection is opened.
88
99
mod common;
10+
mod usage;
1011

1112
use std::sync::Arc;
1213

1314
use crate::fetcher::Fetcher;
1415

1516
pub fn fetchers() -> Vec<Arc<dyn Fetcher>> {
16-
Vec::new()
17+
vec![Arc::new(usage::CodexUsage)]
1718
}
1819

1920
#[cfg(test)]
2021
mod tests {
2122
use super::*;
2223

2324
#[test]
24-
fn fetchers_entry_point_starts_empty_until_members_are_registered() {
25-
// Commit-1 contract: the entry point exists and returns an empty vec. Member fetchers
26-
// are added by subsequent commits; this assertion is amended as they land.
27-
assert!(fetchers().is_empty());
25+
fn fetchers_entry_point_registers_each_member_under_codex_prefix() {
26+
let names: Vec<String> = fetchers().iter().map(|f| f.name().to_string()).collect();
27+
for name in &names {
28+
assert!(
29+
name.starts_with("codex_"),
30+
"{name} must use the `codex_` family prefix"
31+
);
32+
}
33+
assert!(names.contains(&"codex_usage".to_string()));
2834
}
2935
}

0 commit comments

Comments
 (0)