@tmustier/pi-usage-extension 0.3.1 → 0.5.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 +23 -0
- package/README.md +10 -1
- package/data.ts +872 -0
- package/index.ts +14 -558
- package/package.json +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.5.0] - 2026-07-17
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **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.
|
|
7
|
+
|
|
8
|
+
## [0.4.0] - 2026-07-17
|
|
9
|
+
|
|
10
|
+
### Performance
|
|
11
|
+
- `/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.
|
|
12
|
+
- **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.
|
|
13
|
+
- **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.
|
|
14
|
+
- Changed files are parsed with bounded concurrency, and a cancelled cold build persists partial progress so the next open resumes instead of restarting.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- 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).
|
|
18
|
+
- 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.
|
|
19
|
+
|
|
20
|
+
## [0.3.2] - 2026-05-07
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- Declare the `@earendil-works` Pi peer and development dependencies used by runtime imports.
|
|
24
|
+
- Update Pi extension imports to the new `@earendil-works` namespace.
|
|
25
|
+
|
|
3
26
|
## 0.3.1 - 2026-04-19
|
|
4
27
|
- **Cost-only insights.** The Insights view now weights every insight by recorded USD cost, with no tokens fallback. The headline question is now "What's contributing to your cost?" and every bullet reads "X% of your cost …". Periods with no recorded cost show an explicit empty state instead of silently switching unit.
|
|
5
28
|
- **Long-running sessions use true lifetime.** The 8h+ insight now looks at each session's global lifetime across all session files, not just the span visible inside the selected period slice.
|
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.5.0)
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -83,6 +83,7 @@ The insights currently shown:
|
|
|
83
83
|
| **Today** | From midnight (00:00) today |
|
|
84
84
|
| **This Week** | From Monday 00:00 of the current week |
|
|
85
85
|
| **Last Week** | Previous week (Monday 00:00 → this Monday 00:00) |
|
|
86
|
+
| **Last 30 Days** | Rolling window: the last 30 calendar days including today (from midnight 29 days back) |
|
|
86
87
|
| **All Time** | All recorded sessions |
|
|
87
88
|
|
|
88
89
|
Use `Tab` or `←`/`→` to switch between periods.
|
|
@@ -118,6 +119,14 @@ On narrow terminals, `/usage` automatically switches to a compact table instead
|
|
|
118
119
|
| `v` | Toggle between Table and Insights view |
|
|
119
120
|
| `q` / `Esc` | Close |
|
|
120
121
|
|
|
122
|
+
## Performance & Caching
|
|
123
|
+
|
|
124
|
+
`/usage` builds its stats from every session JSONL file under `<agentDir>/sessions`. To keep opens fast on large histories (multi-GB, thousands of files):
|
|
125
|
+
|
|
126
|
+
- **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.
|
|
127
|
+
- **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.
|
|
128
|
+
- 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.
|
|
129
|
+
|
|
121
130
|
## Provider Notes
|
|
122
131
|
|
|
123
132
|
### Cost Tracking
|