Skip to content

Commit 541f94c

Browse files
committed
ci: auto-sync npm metadata from Cargo.toml
1 parent 38e7970 commit 541f94c

File tree

9 files changed

+286
-39
lines changed

9 files changed

+286
-39
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,27 @@ env:
99
CARGO_TERM_COLOR: always
1010

1111
jobs:
12+
readme-sync-check:
13+
name: README sync script check
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
19+
- name: Sync npm README from root README
20+
run: ./scripts/sync-npm-readme.sh
21+
22+
- name: Report README drift (non-blocking)
23+
run: |
24+
set -euxo pipefail
25+
if ! git diff --quiet -- npm/tu/README.md; then
26+
echo "::notice::npm/tu/README.md differs from generated README. Release workflow auto-syncs this before npm publish."
27+
fi
28+
1229
lint-and-test:
1330
name: Lint + Test
1431
runs-on: ubuntu-latest
32+
needs: [readme-sync-check]
1533
steps:
1634
- name: Checkout
1735
uses: actions/checkout@v4
@@ -39,6 +57,7 @@ jobs:
3957
npm-package-check:
4058
name: npm package dry-run
4159
runs-on: ubuntu-latest
60+
needs: [readme-sync-check]
4261
steps:
4362
- name: Checkout
4463
uses: actions/checkout@v4
@@ -51,7 +70,7 @@ jobs:
5170
- name: Validate npm package can be published
5271
run: |
5372
set -euxo pipefail
54-
cargo_version=$(grep -E '^version[[:space:]]*=[[:space:]]*\"' Cargo.toml | head -n1 | cut -d'"' -f2)
73+
./scripts/sync-npm-version.sh
74+
./scripts/sync-npm-readme.sh
5575
cd npm/tu
56-
npm version "${cargo_version}" --no-git-tag-version --allow-same-version
5776
npm pack --dry-run --ignore-scripts

.github/workflows/release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,11 @@ jobs:
238238
fi
239239
cargo_version=$(grep -E '^version[[:space:]]*=[[:space:]]*\"' Cargo.toml | head -n1 | cut -d'"' -f2)
240240
test "${RELEASE_VERSION}" = "$cargo_version"
241+
./scripts/sync-npm-version.sh
242+
./scripts/sync-npm-readme.sh
241243
cd npm/tu
242-
npm version "${cargo_version}" --no-git-tag-version --allow-same-version
244+
npm_version=$(node -p "require('./package.json').version")
245+
test "${npm_version}" = "${cargo_version}"
243246
NODE_AUTH_TOKEN="${NPM_TOKEN}" npm publish --access public
244247
245248
publish-homebrew-tap:

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tokenusage"
3-
version = "1.2.1"
3+
version = "1.2.2"
44
edition = "2024"
55
description = "Fast Rust CLI/TUI/GUI token usage tracker for Codex usage and Claude Code usage."
66
license = "MIT"

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,32 @@ cargo binstall tokenusage --no-confirm
7373
## Quick Start
7474

7575
```bash
76+
# Daily report (default)
7677
tu
78+
79+
# Source-specific
80+
tu codex
81+
tu claude
82+
83+
# Date filter
84+
tu --since 2026-02-01 --until 2026-02-28
85+
86+
# Weekly / monthly
87+
tu weekly --start-of-week monday
88+
tu monthly
89+
90+
# Live monitor
7791
tu live
92+
tu live codex
93+
tu live claude
94+
95+
# GUI dashboard
7896
tu gui
79-
tu img --output tokenusage-share.png # daily view (today, hourly bars)
80-
tu img --period weekly --output tokenusage-week.png # weekly view (daily bars)
97+
98+
# Share image card (for social posting)
99+
tu img
100+
tu img day
101+
tu img week
81102
```
82103

83104
## Why tokenusage

npm/tu/README.md

Lines changed: 183 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,74 @@
22

33
Fast Rust CLI/TUI/GUI token usage tracker for Codex usage and Claude Code usage.
44

5-
- Unified report across Claude + Codex
6-
- Fast parallel scan + cache
7-
- CLI table, TUI, GUI (`iced` + `tiny-skia`)
8-
- Share image card generator (`tu img`)
9-
- Live monitor with progress bars
5+
[![CI](https://github.com/hanbu97/tokenusage/actions/workflows/ci.yml/badge.svg)](https://github.com/hanbu97/tokenusage/actions/workflows/ci.yml)
6+
[![Release](https://github.com/hanbu97/tokenusage/actions/workflows/release.yml/badge.svg)](https://github.com/hanbu97/tokenusage/actions/workflows/release.yml)
107

11-
Repository: [github.com/hanbu97/tokenusage](https://github.com/hanbu97/tokenusage)
12-
Crate: [crates.io/crates/tokenusage](https://crates.io/crates/tokenusage)
8+
`tu` scans local session logs and gives one merged token + cost view across Codex and Claude in CLI, live monitor, and GUI.
9+
10+
**Benchmark:** up to **131.1x faster than `ccusage`** on warm runs (**34.5x** on cold runs) with real local Codex logs. [See full benchmark](#benchmark-details).
11+
12+
## Screenshots
13+
14+
<table align="center" width="100%">
15+
<tr>
16+
<td valign="top" width="50%">
17+
<code>tu</code><br/>
18+
<p align="center">
19+
<a href="https://github.com/hanbu97/tokenusage/blob/main/docs/images/cli-demo-padded.png"><img src="https://raw.githubusercontent.com/hanbu97/tokenusage/main/docs/images/thumbs/cli-demo-padded.png" alt="tu cli demo" height="220" loading="lazy" /></a>
20+
</p>
21+
</td>
22+
<td valign="top" width="50%">
23+
<code>tu gui</code><br/>
24+
<p align="center">
25+
<a href="https://github.com/hanbu97/tokenusage/blob/main/docs/images/gui-demo.png"><img src="https://raw.githubusercontent.com/hanbu97/tokenusage/main/docs/images/thumbs/gui-demo.png" alt="tu gui demo" height="220" loading="lazy" /></a>
26+
</p>
27+
</td>
28+
</tr>
29+
<tr>
30+
<td valign="top" width="50%">
31+
<code>tu img day</code><br/>
32+
<p align="center">
33+
<a href="https://github.com/hanbu97/tokenusage/blob/main/docs/images/share-demo.png"><img src="https://raw.githubusercontent.com/hanbu97/tokenusage/main/docs/images/thumbs/share-demo.png" alt="tu img daily demo" height="260" loading="lazy" /></a>
34+
</p>
35+
</td>
36+
<td valign="top" width="50%">
37+
<code>tu img week</code><br/>
38+
<p align="center">
39+
<a href="https://github.com/hanbu97/tokenusage/blob/main/docs/images/share-week-demo.png"><img src="https://raw.githubusercontent.com/hanbu97/tokenusage/main/docs/images/thumbs/share-week-demo.png" alt="tu img weekly demo" height="260" loading="lazy" /></a>
40+
</p>
41+
</td>
42+
</tr>
43+
<tr>
44+
<td valign="top" colspan="2">
45+
<code>tu live codex</code><br/>
46+
<p align="center">
47+
<a href="https://github.com/hanbu97/tokenusage/blob/main/docs/images/live-demo.png"><img src="https://raw.githubusercontent.com/hanbu97/tokenusage/main/docs/images/thumbs/live-demo.png" alt="tu live demo" width="100%" loading="lazy" /></a>
48+
</p>
49+
</td>
50+
</tr>
51+
</table>
1352

1453
## Install
1554

55+
### cargo (crates.io)
56+
57+
```bash
58+
cargo install tokenusage --bin tu
59+
```
60+
61+
### npm
62+
1663
```bash
1764
npm install -g tokenusage
1865
```
1966

67+
### cargo-binstall (prebuilt binary)
68+
69+
```bash
70+
cargo binstall tokenusage --no-confirm
71+
```
72+
2073
## Quick Start
2174

2275
```bash
@@ -48,48 +101,147 @@ tu img day
48101
tu img week
49102
```
50103

51-
## Screenshots
104+
## Why tokenusage
105+
106+
- Faster feedback loop: native Rust + parallel scan/parsing + incremental cache.
107+
- One dashboard for both Codex and Claude, with merged totals and per-model breakdown.
108+
- Share-ready image card (`tu img`) for posting your token/cost trend.
109+
- Works in terminal and desktop GUI without sending your logs to a cloud service.
110+
111+
## FAQ
112+
113+
### Where does the data come from?
114+
115+
From local log directories only:
116+
- Claude: `~/.config/claude/projects`, `~/.claude/projects`
117+
- Codex: `~/.codex/sessions`, `~/.config/codex/sessions`
118+
119+
You can override with `--claude-projects-dir` and `--codex-sessions-dir`.
120+
121+
### How is cost estimated?
122+
123+
`tu` uses OpenRouter pricing when available, caches it for 6 hours, and falls back to built-in offline rates when network pricing is unavailable.
52124

53-
[![CLI demo](https://raw.githubusercontent.com/hanbu97/tokenusage/main/docs/images/cli-demo-padded.png)](https://github.com/hanbu97/tokenusage)
54-
[![GUI demo](https://raw.githubusercontent.com/hanbu97/tokenusage/main/docs/images/gui-demo.png)](https://github.com/hanbu97/tokenusage)
55-
[![Live demo](https://raw.githubusercontent.com/hanbu97/tokenusage/main/docs/images/live-demo.png)](https://github.com/hanbu97/tokenusage)
56-
[![Share card daily demo](https://raw.githubusercontent.com/hanbu97/tokenusage/main/docs/images/share-demo.png)](https://github.com/hanbu97/tokenusage)
57-
[![Share card weekly demo](https://raw.githubusercontent.com/hanbu97/tokenusage/main/docs/images/share-week-demo.png)](https://github.com/hanbu97/tokenusage)
125+
### Is my data private?
58126

59-
## Why `tu`
127+
Yes for usage logs: parsing is local. `tu` only requests pricing metadata unless you run `--offline`.
60128

61-
- Real-world benchmark vs `ccusage` on local Codex logs:
62-
- About **34.5x faster (cold)** and **131.1x faster (warm)**
63-
- Rust-native startup, parallel parsing, incremental cache reuse
129+
## Benchmark Details
64130

65-
## Data Sources (default)
131+
Benchmark setup:
66132

67-
- Claude:
68-
- `~/.config/claude/projects`
69-
- `~/.claude/projects`
70-
- Codex:
71-
- `~/.codex/sessions`
72-
- `~/.config/codex/sessions`
133+
- Machine: Apple M3 Max, macOS 15.6.1
134+
- Dataset: `~/.codex/sessions` (71 JSONL files, ~537 MB), date range `2025-09-01` to `2026-02-28`
135+
- `tu` version: `1.1.2`
136+
- `@ccusage/codex` version: `18.0.8`
137+
- Both in default mode (online pricing behavior, network enabled)
73138

74-
You can override with:
139+
Results:
75140

76-
- `--claude-projects-dir <PATH>` (repeatable)
77-
- `--codex-sessions-dir <PATH>` (repeatable)
141+
| Tool | Command | Time |
142+
|---|---|---:|
143+
| `tu` (cold, rebuild cache) | `tu codex --rebuild-cache -s 2025-09-01 -u 2026-02-28` | **0.19s** |
144+
| `@ccusage/codex` (single run) | `ccusage-codex daily -s 2025-09-01 -u 2026-02-28` | **6.56s** |
145+
| `tu` (warm, avg of 10 runs) | `tu codex -s 2025-09-01 -u 2026-02-28` | **0.052s** |
146+
| `@ccusage/codex` (warm, avg of 10 runs) | `ccusage-codex daily -s 2025-09-01 -u 2026-02-28` | **6.819s** |
78147

79-
## Config
148+
- Cold-run speedup: about **34.5x**
149+
- Warm-run speedup: about **131.1x**
80150

81-
Default config search:
151+
> Notes: results vary by hardware, filesystem cache state, and log volume.
82152
153+
## Command Overview
154+
155+
```text
156+
tu [daily|codex|claude|monthly|weekly|img|session|blocks|live|statusline|gui]
157+
```
158+
159+
Useful commands:
160+
- `tu daily --tui`
161+
- `tu daily --json`
162+
- `tu daily --jq '.rows[0]'`
163+
- `tu blocks --active`
164+
- `tu blocks --live`
165+
- `tu live`
166+
- `tu img --output tokenusage-share.png` (today, hourly)
167+
- `tu img --period weekly --output tokenusage-week.png` (7 days, daily)
168+
- `tu img --logo ./logo.png --brand-url tokenusage.dev`
169+
- `tu statusline`
170+
171+
## Config File
172+
173+
Config search order:
83174
1. `./.tu/tu.json`
84175
2. `~/.config/tu/tu.json`
85176
3. `~/.config/tokenusage/tokenusage.json`
86177

87-
Explicit config:
178+
Use an explicit config file:
88179

89180
```bash
90181
tu --config /path/to/tu.json
91182
```
92183

184+
Example:
185+
186+
```json
187+
{
188+
"defaults": {
189+
"timezone": "Asia/Shanghai",
190+
"workers": 16,
191+
"compact": false
192+
},
193+
"commands": {
194+
"daily": {
195+
"instances": true
196+
},
197+
"live": {
198+
"sessionLength": 5,
199+
"refreshInterval": 1
200+
},
201+
"img": {
202+
"period": "daily",
203+
"bars": 24,
204+
"brand": "tokenusage",
205+
"brandUrl": "https://github.com/hanbu97/tokenusage"
206+
},
207+
"weekly": {
208+
"startOfWeek": "monday"
209+
}
210+
}
211+
}
212+
```
213+
214+
## Pricing
215+
216+
```bash
217+
tu --pricing-file ./pricing.json
218+
```
219+
220+
Offline-only mode:
221+
222+
```bash
223+
tu --offline
224+
```
225+
226+
## Demo Dataset (No Real Data)
227+
228+
```bash
229+
python3 examples/demo/generate_demo_data.py
230+
tu daily --config ./examples/demo/tu.demo.json --since 2026-02-09 --until 2026-02-28
231+
tu live --config ./examples/demo/tu.demo.json
232+
tu gui --config ./examples/demo/tu.demo.json --since 2026-02-09 --until 2026-02-28
233+
tu img --config ./examples/demo/tu.demo.json --since 2026-02-28 --until 2026-02-28 --output ./docs/images/share-demo.png
234+
tu img --config ./examples/demo/tu.demo.json --period weekly --since 2026-02-22 --until 2026-02-28 --output ./docs/images/share-week-demo.png
235+
```
236+
237+
## Development
238+
239+
```bash
240+
cargo fmt
241+
cargo clippy --all-targets --all-features
242+
cargo check
243+
```
244+
93245
## License
94246

95-
MIT
247+
MIT. See [LICENSE](https://github.com/hanbu97/tokenusage/blob/main/LICENSE).

npm/tu/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tokenusage",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Fast Rust CLI/TUI/GUI token usage tracker for Codex usage and Claude Code usage.",
55
"license": "MIT",
66
"repository": {

0 commit comments

Comments
 (0)