@tmustier/pi-usage-extension 0.3.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/README.md +32 -5
- package/data.ts +964 -0
- package/graph.ts +386 -0
- package/index.ts +184 -561
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.6.0] - 2026-07-17
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **Interactive graph explorer.** New third view mode (cycle with `v`): a braille line chart of usage over time for the active period, with a legend showing per-series totals and shares.
|
|
7
|
+
- Metrics (`m`): cost, tokens, messages, reasoning tokens.
|
|
8
|
+
- Grouping (`g`): by provider, by model, by thinking level, or total only — top 6 series plus an `other` rollup, with a bold Total line always drawn.
|
|
9
|
+
- Cumulative running totals or per-bucket rates (`c`), hourly buckets for day/week periods and daily buckets for Last 30 Days / All Time.
|
|
10
|
+
- Legend filtering: `↑`/`↓` moves the cursor, `Enter`/`Space` hides or shows a series, `a` shows all. The y-axis rescales to the visible series so small series can be inspected by hiding large ones.
|
|
11
|
+
- **Thinking level and reasoning tokens.** Session parsing now replays `thinking_level_change` entries (compact and spaced JSON styles) to attribute a thinking level to each assistant message, and records `usage.reasoning` token counts. Messages before the first recorded change appear as `unknown`.
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
- On-disk cache format bumped to v2 (per-message thinking level and reasoning tokens). The first open after upgrading does a one-off full rebuild; older caches are ignored safely.
|
|
15
|
+
|
|
16
|
+
## [0.5.0] - 2026-07-17
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- **Last 30 Days period.** New tab between Last Week and All Time covering the last 30 calendar days including today (from midnight 29 days back, DST-safe). Available in both the table and insights views.
|
|
20
|
+
|
|
21
|
+
## [0.4.0] - 2026-07-17
|
|
22
|
+
|
|
23
|
+
### Performance
|
|
24
|
+
- `/usage` no longer re-reads and JSON-parses every session JSONL file on every open. On a real 5.2 GB / 3,310-file corpus, warm opens went from ~17 s to ~0.3 s (~50×) and the one-off cold build from ~17 s to ~7 s, with peak memory roughly halved.
|
|
25
|
+
- **On-disk cache.** Per-file extraction results are persisted to `<agentDir>/usage-extension-cache.json` (respects `PI_CODING_AGENT_DIR`), keyed by file size + mtime. Only new or changed session files are re-parsed; entries for deleted files are evicted. Deleting the cache file forces a full rebuild — it is recreated automatically.
|
|
26
|
+
- **Buffer-level pre-filter.** Session files are scanned as raw bytes and only lines that can be a session header or an assistant message are UTF-8-decoded and JSON-parsed; the multi-megabyte tool-result lines that dominate session files are skipped with a cheap byte search. Both compact (`"role":"assistant"`) and spaced (`"role": "assistant"`, seen in imported third-party session files) JSON styles are matched.
|
|
27
|
+
- Changed files are parsed with bounded concurrency, and a cancelled cold build persists partial progress so the next open resumes instead of restarting.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
- Data collection, caching, and insights moved from `index.ts` into `usage-extension/data.ts`, with tests in `tests/usage-data.test.mjs`. Verified equivalent to the previous parser across all 3,310 real session files (zero extraction mismatches).
|
|
31
|
+
- Files without a session header (which are ignored, as before) no longer register their messages in the branch-dedupe hash set, so an identical message in a later, valid session file is now counted instead of silently dropped.
|
|
32
|
+
|
|
3
33
|
## [0.3.2] - 2026-05-07
|
|
4
34
|
|
|
5
35
|
### Changed
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ A Pi extension that displays aggregated usage statistics across all sessions.
|
|
|
7
7
|
## Compatibility
|
|
8
8
|
|
|
9
9
|
- **Pi version:** 0.42.4+
|
|
10
|
-
- **Last updated:** 2026-
|
|
10
|
+
- **Last updated:** 2026-07-17 (0.6.0)
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -57,15 +57,28 @@ In Pi, run:
|
|
|
57
57
|
|
|
58
58
|
### Views
|
|
59
59
|
|
|
60
|
-
`/usage` has
|
|
60
|
+
`/usage` has three view modes, cycled with `v`:
|
|
61
61
|
|
|
62
62
|
- **Table** (default) — per-provider / per-model stats with cost and token breakdown (screenshot at the top of this page).
|
|
63
63
|
- **Insights** — narrative characteristics of your cost for the active time period, e.g. *"X% of your cost was at >150k context"*. Insights are **independent characteristics**, not a breakdown, so they overlap and can sum to more than 100%.
|
|
64
|
+
- **Graphs** — an interactive braille line-chart explorer for usage over time (details below).
|
|
64
65
|
|
|
65
66
|

|
|
66
67
|
|
|
67
68
|
**Unit:** insights are always weighted by recorded API cost (USD). Periods with no recorded cost show an explicit empty state rather than silently switching to a different unit.
|
|
68
69
|
|
|
70
|
+
### Graph explorer
|
|
71
|
+
|
|
72
|
+
The **Graphs** view plots usage over time for the active period as a braille line chart, with a legend showing per-series totals and shares.
|
|
73
|
+
|
|
74
|
+
- **Metric** (`m` to cycle): cost, tokens (input + output + cache write), messages, reasoning tokens.
|
|
75
|
+
- **Grouping** (`g` to cycle): by provider, by model, by thinking level, or total only. The top 6 series are shown individually; the rest merge into an `other` series. A bold **Total** line is always drawn.
|
|
76
|
+
- **Cumulative vs per-bucket** (`c` to toggle): running total across the period (default), or the raw per-bucket rate.
|
|
77
|
+
- **Filtering**: move the legend cursor with `↑`/`↓` and toggle series visibility with `Enter`/`Space` (`a` shows all again). The y-axis rescales to the visible series — hide the big lines to zoom into the small ones.
|
|
78
|
+
- **Buckets**: hourly for Today / This Week / Last Week, daily for Last 30 Days / All Time.
|
|
79
|
+
|
|
80
|
+
Thinking levels are replayed from `thinking_level_change` entries in each session file; messages before the first recorded change appear as `unknown`. Reasoning token counts come from `usage.reasoning` where providers report them.
|
|
81
|
+
|
|
69
82
|
The insights currently shown:
|
|
70
83
|
|
|
71
84
|
| Insight | Threshold |
|
|
@@ -83,6 +96,7 @@ The insights currently shown:
|
|
|
83
96
|
| **Today** | From midnight (00:00) today |
|
|
84
97
|
| **This Week** | From Monday 00:00 of the current week |
|
|
85
98
|
| **Last Week** | Previous week (Monday 00:00 → this Monday 00:00) |
|
|
99
|
+
| **Last 30 Days** | Rolling window: the last 30 calendar days including today (from midnight 29 days back) |
|
|
86
100
|
| **All Time** | All recorded sessions |
|
|
87
101
|
|
|
88
102
|
Use `Tab` or `←`/`→` to switch between periods.
|
|
@@ -113,11 +127,24 @@ On narrow terminals, `/usage` automatically switches to a compact table instead
|
|
|
113
127
|
| Key | Action |
|
|
114
128
|
|-----|--------|
|
|
115
129
|
| `Tab` / `←` `→` | Switch time period |
|
|
116
|
-
| `↑` `↓` | Select provider *(table
|
|
117
|
-
| `Enter` / `Space` | Expand/collapse provider
|
|
118
|
-
| `v` |
|
|
130
|
+
| `↑` `↓` | Select provider *(table)* / move legend cursor *(graphs)* |
|
|
131
|
+
| `Enter` / `Space` | Expand/collapse provider *(table)* / toggle series visibility *(graphs)* |
|
|
132
|
+
| `v` | Cycle Table → Insights → Graphs view |
|
|
133
|
+
| `m` | Cycle metric: cost / tokens / messages / reasoning *(graphs)* |
|
|
134
|
+
| `g` | Cycle grouping: provider / model / thinking level / total *(graphs)* |
|
|
135
|
+
| `c` | Toggle cumulative vs per-bucket *(graphs)* |
|
|
136
|
+
| `a` | Show all series *(graphs)* |
|
|
119
137
|
| `q` / `Esc` | Close |
|
|
120
138
|
|
|
139
|
+
## Performance & Caching
|
|
140
|
+
|
|
141
|
+
`/usage` builds its stats from every session JSONL file under `<agentDir>/sessions`. To keep opens fast on large histories (multi-GB, thousands of files):
|
|
142
|
+
|
|
143
|
+
- **On-disk cache.** Per-file extraction results are cached in `<agentDir>/usage-extension-cache.json` (respects `PI_CODING_AGENT_DIR`), keyed by file size + mtime. Warm opens only re-parse session files that changed since the last run — on a 5.2 GB / 3,310-file corpus that takes the open from ~17 s to ~0.3 s.
|
|
144
|
+
- **First open** after install (or after deleting the cache) does a one-off full build, showing the usual cancellable loader. Cancelling saves partial progress, so the next open resumes where it left off.
|
|
145
|
+
- The cache is safe to delete at any time; it is rebuilt automatically. Corrupt or version-mismatched caches are ignored and rebuilt rather than trusted.
|
|
146
|
+
- **0.6.0 bumps the cache format to v2** (adds thinking level and reasoning tokens per message). The first open after upgrading does a one-off full rebuild, then warm opens are fast again.
|
|
147
|
+
|
|
121
148
|
## Provider Notes
|
|
122
149
|
|
|
123
150
|
### Cost Tracking
|