Skip to content

Commit a9b8cd4

Browse files
committed
Merge branch 'main' into feat/named-pi-stores
Resolve conflicts with #1394 and #1396: - keep named pi store specs inside the new load_base_rows so --sections includes config-declared agents - adopt the #1394 session date filtering fix in load_pi_format_agent_rows - replace the pinned until-day drop bug test with the fixed-behavior test from main, adapted to the named-store test helpers
2 parents 6ac7506 + e2e0c5e commit a9b8cd4

33 files changed

Lines changed: 1979 additions & 149 deletions

‎.github/APPROVED_CONTRIBUTORS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ yamamuteki issue
2323
yukukotani pr
2424

2525
zcutlip pr
26+
27+
tackeyy pr

‎.github/workflows/pullfrog.yml‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎apps/ccusage/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ bunx ccusage pi daily --pi-path /path/to/sessions,/archive/pi/sessions
137137

138138
# Explicit unified report
139139
bunx ccusage daily --all
140+
bunx ccusage daily --sections daily,monthly,session --json
141+
bunx ccusage daily --by-agent --json
140142

141143
# Filters and options
142144
bunx ccusage daily --since 2026-04-25 --until 2026-05-16

‎apps/ccusage/justfile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ test-statusline-all:
3939
just test-statusline-opus4
4040
@echo 'Testing Sonnet 4.1:'
4141
just test-statusline-sonnet41
42+
@echo 'Testing Fable 5:'
43+
just test-statusline-fable5
4244

4345
test-statusline-opus4:
4446
just test-statusline-file test/statusline-test-opus4.json --offline
@@ -49,6 +51,9 @@ test-statusline-sonnet4:
4951
test-statusline-sonnet41:
5052
just test-statusline-file test/statusline-test-sonnet41.json --offline
5153

54+
test-statusline-fable5:
55+
just test-statusline-file test/statusline-test-fable5.json --offline
56+
5257
test-statusline-file file *args:
5358
cargo run --manifest-path ../../rust/Cargo.toml --bin ccusage -- statusline {{args}} < {{file}}
5459

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"session_id": "test-session-fable5",
3+
"transcript_path": "test/test-transcript.jsonl",
4+
"cwd": "/Users/test/project",
5+
"model": {
6+
"id": "claude-fable-5",
7+
"display_name": "Fable 5"
8+
},
9+
"workspace": {
10+
"current_dir": "/Users/test/project",
11+
"project_dir": "/Users/test/project"
12+
},
13+
"version": "2.1.202",
14+
"output_style": {
15+
"name": "default"
16+
},
17+
"cost": {
18+
"total_cost_usd": 0.0412,
19+
"total_duration_ms": 160000,
20+
"total_api_duration_ms": 10200,
21+
"total_lines_added": 0,
22+
"total_lines_removed": 0
23+
},
24+
"context_window": {
25+
"total_input_tokens": 52000,
26+
"total_output_tokens": 3800,
27+
"context_window_size": 200000
28+
},
29+
"effort": {
30+
"level": "high"
31+
},
32+
"exceeds_200k_tokens": false
33+
}

‎codex-speed-infer-plan.md‎

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Codex Speed Inference Plan
2+
3+
## Context
4+
5+
Codex logs do not currently record an explicit fast-mode flag per turn. The
6+
current `--speed auto` behavior reads the current `~/.codex/config.toml`
7+
`service_tier` and applies one speed choice to all historical Codex usage. That
8+
means historical cost can change when the current Codex config changes.
9+
10+
Recent log checks showed that raw TPS signals exist, but the denominator matters.
11+
Simple time between `token_count` events is too noisy because replayed history,
12+
sub-agent activity, tool calls, and tool output can distort the interval.
13+
14+
Ground-truth notes from local sessions:
15+
16+
- Weekdays in the previous week were mostly fast mode.
17+
- `kindle-alpha` should generally be treated as fast-mode usage.
18+
- For today's two sessions, the smaller session was fast and the larger session
19+
was not fast, so raw turn-level `output_tokens / duration_ms` can classify in
20+
the wrong direction.
21+
22+
## Goals
23+
24+
- Preserve existing `--speed auto` behavior for compatibility.
25+
- Add an opt-in inference mode instead of silently changing auto pricing.
26+
- Infer speed per turn, not per session or per report bucket.
27+
- Keep standard and fast usage in separate cost buckets so one multiplier is not
28+
applied to a mixed report.
29+
- Avoid overcharging uncertain turns.
30+
31+
## Proposed CLI Behavior
32+
33+
Add a new Codex speed option:
34+
35+
```sh
36+
ccusage codex daily --speed infer
37+
ccusage codex monthly --speed infer
38+
ccusage codex session --speed infer
39+
```
40+
41+
Speed modes:
42+
43+
- `--speed auto`: keep current behavior. Read Codex config and apply the resolved
44+
speed globally.
45+
- `--speed standard`: force all Codex usage to standard pricing.
46+
- `--speed fast`: force all Codex usage to fast pricing.
47+
- `--speed infer`: infer fast/standard/unknown per turn from log timing.
48+
49+
## Inference Strategy
50+
51+
Use `--speed infer` only.
52+
53+
Do not use raw time between `token_count` checkpoints as the primary metric.
54+
It is useful for diagnostics, but too noisy for pricing.
55+
56+
Prefer a model-output interval:
57+
58+
1. Track turn boundaries from `task_started`, `user_message`, and `turn_context`.
59+
2. Track model-output events such as `response_item` with `message` or
60+
`reasoning` payloads.
61+
3. Exclude tool call and tool output time from the denominator where possible.
62+
4. Compute TPS from output tokens over the model-output interval.
63+
5. Mark tiny, short, replayed, or structurally ambiguous samples as `unknown`.
64+
65+
Initial buckets:
66+
67+
- `fast`: strong fast signal, or `kindle-alpha` fast prior.
68+
- `standard`: strong standard signal.
69+
- `unknown`: borderline, too few valid steps, too few output tokens, missing
70+
timing events, or replay-like logs.
71+
72+
Initial fallback:
73+
74+
- Treat `unknown` as standard for cost calculation.
75+
76+
This is conservative and avoids bringing back the core bug where current config
77+
changes historical cost.
78+
79+
## Model Prior
80+
81+
For `--speed infer`, treat `kindle-alpha` as fast by default. Implement this in a
82+
small helper so it is easy to adjust or override later.
83+
84+
Do not apply this prior to `--speed auto`, `--speed standard`, or `--speed fast`.
85+
86+
## Data Model Changes
87+
88+
The current `CodexModelUsage` stores only one token aggregate per model. That is
89+
not enough once fast and standard usage can be mixed in the same day, month, or
90+
session.
91+
92+
Add speed-aware buckets, for example:
93+
94+
```text
95+
CodexModelUsage
96+
standard
97+
fast
98+
unknown
99+
```
100+
101+
Each bucket should carry the same token fields currently stored on
102+
`CodexModelUsage`:
103+
104+
- input tokens
105+
- cached input tokens
106+
- output tokens
107+
- reasoning output tokens
108+
- total tokens
109+
110+
Cost calculation should price each bucket separately:
111+
112+
- standard bucket: normal pricing
113+
- fast bucket: pricing multiplied by `fastMultiplier`
114+
- unknown bucket: standard pricing
115+
116+
## Parser Changes
117+
118+
Extend Codex parsing to collect timing metadata alongside token usage.
119+
120+
Each `CodexTokenUsageEvent` should have enough information for inference, such
121+
as:
122+
123+
- turn id, if available
124+
- model-output interval duration
125+
- output tokens for the inferred interval
126+
- inference confidence or bucket
127+
128+
If timing data is unavailable, keep the event usable for token accounting and
129+
mark the speed bucket as `unknown`.
130+
131+
## Tests
132+
133+
Use minimal JSONL fixtures. Do not include real prompt text or assistant output.
134+
135+
Required regression cases:
136+
137+
- `--speed auto` remains config-based and does not use TPS inference.
138+
- `--speed infer` separates standard and fast buckets within the same report
139+
period.
140+
- `kindle-alpha` is fast under `infer`.
141+
- Unknown or borderline turns fall back to standard pricing.
142+
- Today's smaller fast-like session is not misclassified as standard because of
143+
overhead.
144+
- Today's larger non-fast session is not misclassified as fast by raw
145+
`output_tokens / duration_ms`.
146+
- Reports apply `fastMultiplier` only to fast buckets.
147+
- `ccusage daily` all-agent reports use the same Codex inferred bucket costs as
148+
`ccusage codex daily`.
149+
150+
## Documentation Updates
151+
152+
If implemented, update:
153+
154+
- root `README.md`
155+
- `apps/ccusage/README.md`
156+
- `docs/guide/codex/index.md`
157+
- relevant all-report examples if they mention Codex speed pricing
158+
- CLI help snapshots and config schema artifacts
159+
160+
Docs should clearly state:
161+
162+
- Codex logs do not expose an authoritative fast flag.
163+
- `auto` is config-based.
164+
- `infer` is timing-based and heuristic.
165+
- `infer` is conservative for unknown turns.
166+
167+
## Rollout
168+
169+
1. Add `CodexSpeed::Infer` and CLI/config/schema support.
170+
2. Add failing tests for mixed standard/fast bucket pricing.
171+
3. Add parser timing extraction with minimal fixtures.
172+
4. Add inference helper and conservative bucket assignment.
173+
5. Split Codex aggregation into speed-aware buckets.
174+
6. Update Codex-focused reports.
175+
7. Update all-agent reports.
176+
8. Update docs and generated artifacts.
177+
9. Run focused Rust tests, then `just fmt` and the relevant repo checks.

‎docs/guide/all-reports.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ The `--all` flag is accepted for compatibility, but it is optional because unifi
2323
ccusage daily --all
2424
```
2525

26+
For automation, unified JSON reports can emit several report sections from one load:
27+
28+
```bash
29+
ccusage daily --sections daily,monthly,session --json
30+
ccusage daily --by-agent --json
31+
```
32+
33+
`--sections` accepts `daily`, `weekly`, `monthly`, and `session`. The invoked report section is always included, and table output prints each requested section as a separate table. `--by-agent` adds an `agents` array to daily, weekly, and monthly JSON rows; session rows are already source-specific.
34+
2635
## How Unified Views Work
2736

2837
ccusage detects local usage files from Claude Code, Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, Qwen, GitHub Copilot CLI, and Gemini CLI. The same daily, weekly, monthly, and session views can run in two modes:

‎docs/guide/cli-options.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,20 @@ ccusage monthly --config /path/to/team-config.json
129129

130130
## Command-Specific Options
131131

132+
### Unified Report Options
133+
134+
These options apply to `ccusage daily`, `ccusage weekly`, `ccusage monthly`, and `ccusage session` when they are aggregating all detected sources:
135+
136+
```bash
137+
# Emit several JSON report sections from one source load
138+
ccusage daily --sections daily,monthly,session --json
139+
140+
# Add per-agent breakdowns to daily, weekly, and monthly JSON rows
141+
ccusage daily --by-agent --json
142+
```
143+
144+
`--sections` accepts a comma-separated list of `daily`, `weekly`, `monthly`, and `session`. The invoked report section is always included. For table output, each requested section is printed as a separate table. `--by-agent` is JSON-only; session rows are already per-agent.
145+
132146
### Daily Command
133147

134148
Additional options for daily reports:

‎docs/guide/community-projects.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ These projects are maintained independently and are not affiliated with the ccus
2525
- [Straude](https://straude.com) - Strava-style Claude Code telemetry for logging usage, tracking spend, and comparing pace
2626
- [viberank](https://viberank.app) - A community-driven leaderboard for Claude Code usage. ([GitHub](https://github.com/sculptdotfun/viberank))
2727
- [CCWarriors](https://ccwarriors.xyz) - Live leaderboard of AI coding spend across Claude Code, Codex, Gemini, and other ccusage-readable agents, with per-tool filters and real-time updates. ([GitHub](https://github.com/distroinfinity/ccwarriors))
28+
- [Token Battle](https://tokenbattle.vercel.app) - AI coding cost leaderboard for comparing monthly ccusage exports from Claude Code, Codex CLI, and Gemini CLI, with dashboard uploads, public rankings, and shareable profiles.
2829

2930
## Contributing
3031

0 commit comments

Comments
 (0)