Skip to content

Commit 1b5d7b2

Browse files
unhappychoiceclaude
andcommitted
feat(fetcher): add codex_subscription — rate-limit utilisation from local JSONL
Codex CLI piggybacks plan rate-limit state on every `token_count` event in the session JSONL (`primary` = 5h window, `secondary` = 7d window, `plan_type`). This fetcher walks the newest session (via the discovery helpers from the codex scaffold) and reads the last such event — the same view Codex itself shows. Deliberately no network call even though OpenAI's API can return the same payload: the only way to re-fetch it is a billable inference request, which is not what a splash widget should do. Freshness is bounded by "when did the user last run Codex"; the renderer falls back to `resets now` for a window that has already rolled over, which surfaces the staleness honestly. Shape coverage matches `claude_subscription`: Ratio / Text / TextBlock / MarkdownTextBlock / Entries / Bars / Badge / Timeline (eight). `Safety::Safe`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent ebb7760 commit 1b5d7b2

2 files changed

Lines changed: 823 additions & 3 deletions

File tree

‎src/fetcher/codex/mod.rs‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22
//!
33
//! - [`usage::CodexUsage`] aggregates the local `rollout-*.jsonl` files Codex CLI writes for
44
//! every session, with zero configuration and no network.
5+
//! - [`subscription::CodexSubscription`] extracts rate-limit utilisation (5h / 7d windows +
6+
//! plan type) from the most recent session's last `token_count` event.
57
//!
6-
//! `Safety::Safe` — every read is rooted at `~/.codex/sessions/` (or the `CODEX_HOME`
7-
//! override) and no network connection is opened.
8+
//! Both are `Safety::Safe` — all reads are rooted at `~/.codex/sessions/`. No network, no
9+
//! token leaves the host (the rate-limit data is already cached in the JSONL by Codex CLI;
10+
//! re-fetching it would mean making an inference call, which costs money).
811
912
mod common;
13+
mod subscription;
1014
mod usage;
1115

1216
use std::sync::Arc;
1317

1418
use crate::fetcher::Fetcher;
1519

1620
pub fn fetchers() -> Vec<Arc<dyn Fetcher>> {
17-
vec![Arc::new(usage::CodexUsage)]
21+
vec![
22+
Arc::new(usage::CodexUsage),
23+
Arc::new(subscription::CodexSubscription),
24+
]
1825
}
1926

2027
#[cfg(test)]
@@ -31,5 +38,6 @@ mod tests {
3138
);
3239
}
3340
assert!(names.contains(&"codex_usage".to_string()));
41+
assert!(names.contains(&"codex_subscription".to_string()));
3442
}
3543
}

0 commit comments

Comments
 (0)