Skip to content

Commit 4a2c821

Browse files
committed
release: add usage extension
1 parent ae46a8f commit 4a2c821

8 files changed

Lines changed: 1314 additions & 4 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This repo is a pnpm workspace monorepo. Each extension under `extensions/` can b
2121
- [simplify](#simplify)
2222
- [status-line](#status-line)
2323
- [team-mode](#team-mode)
24+
- [usage](#usage)
2425

2526
## Installation
2627

@@ -436,3 +437,21 @@ Full details: [extensions/team-mode/README.md](extensions/team-mode/README.md).
436437
```bash
437438
pi install npm:pi-mono-team-mode
438439
```
440+
441+
### usage
442+
443+
The `usage` extension adds a `/usage` command that aggregates local pi session files and renders an inline dashboard with three views:
444+
445+
- **Summary** — totals, top providers (with horizontal bars), and an environmental footprint estimate (kWh, kg CO₂e, real-world equivalences) computed from [`impact-equivalences`](https://www.npmjs.com/package/impact-equivalences).
446+
- **Providers** — per-provider table that expands into per-model rows on `Enter`.
447+
- **Patterns** — cost-driver insights for the selected period (parallel sessions, oversized contexts, large uncached prompts, marathon sessions, top-session concentration).
448+
449+
`Tab`/arrows cycle the period (Today / This Week / Last Week / All Time). `v` or `1`/`2`/`3` switch view. `q`/`Esc` close the panel.
450+
451+
Full details: [extensions/usage/README.md](extensions/usage/README.md).
452+
453+
#### Install
454+
455+
```bash
456+
pi install npm:pi-mono-usage
457+
```

extensions/all/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# pi-mono-all
22

3+
## 1.1.0
4+
5+
### Minor Changes
6+
7+
### Enhanced: all
8+
9+
- Bundle the new `pi-mono-usage` extension in the all-in-one package.
10+
311
## 1.0.1
412

513
### Patch Changes

extensions/all/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pi-mono-all",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "All pi-mono extensions and bundled skills",
55
"type": "module",
66
"keywords": [
@@ -24,7 +24,8 @@
2424
"pi-mono-sentinel": "workspace:*",
2525
"pi-mono-simplify": "workspace:*",
2626
"pi-mono-status-line": "workspace:*",
27-
"pi-mono-team-mode": "workspace:*"
27+
"pi-mono-team-mode": "workspace:*",
28+
"pi-mono-usage": "workspace:*"
2829
},
2930
"bundledDependencies": [
3031
"pi-mono-ask-user-question",
@@ -42,7 +43,8 @@
4243
"pi-mono-sentinel",
4344
"pi-mono-simplify",
4445
"pi-mono-status-line",
45-
"pi-mono-team-mode"
46+
"pi-mono-team-mode",
47+
"pi-mono-usage"
4648
],
4749
"peerDependencies": {
4850
"@earendil-works/pi-ai": "*",
@@ -66,7 +68,8 @@
6668
"./node_modules/pi-mono-sentinel/index.ts",
6769
"./node_modules/pi-mono-simplify/index.ts",
6870
"./node_modules/pi-mono-status-line/index.ts",
69-
"./node_modules/pi-mono-team-mode/index.ts"
71+
"./node_modules/pi-mono-team-mode/index.ts",
72+
"./node_modules/pi-mono-usage/index.ts"
7073
],
7174
"skills": [
7275
"./node_modules/pi-mono-figma/skills",

extensions/usage/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# pi-mono-usage
2+
3+
## 0.1.0
4+
5+
### Initial release
6+
7+
- `/usage` command renders an inline dashboard over local pi session files.
8+
- Three views: Summary (with sustainability impact), Providers (table with model expansion), Patterns (cost-driver insights).
9+
- Period selector for Today / This Week / Last Week / All Time.
10+
- Sustainability impact powered by `impact-equivalences` (electricity, carbon, real-world equivalences).
11+
- Tabular layout adapts to terminal width (full → compact → minimal).

extensions/usage/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# usage extension
2+
3+
Adds a `/usage` slash command that reads your local pi session files, aggregates token spend, and renders an inline dashboard with three views.
4+
5+
## Install
6+
7+
```bash
8+
pi install npm:pi-mono-usage
9+
```
10+
11+
## Views
12+
13+
- **Summary** — totals, top providers, and an environmental footprint estimate (kWh, kg CO₂e, real-world equivalences) computed from [`impact-equivalences`](https://www.npmjs.com/package/impact-equivalences).
14+
- **Providers** — per-provider table that expands into per-model rows. Includes session/call counts, cost, and token breakdown (input, output, cache).
15+
- **Patterns** — cost-driver insights for the selected period: parallel sessions, oversized contexts, large uncached prompts, marathon sessions, and top-session concentration.
16+
17+
## Period selector
18+
19+
Tab between `Today`, `This Week`, `Last Week`, and `All Time`. Each period is computed once on open from the same parsed dataset, so cycling is instant.
20+
21+
## Keybindings
22+
23+
| Key | Action |
24+
| ----------------- | -------------------------------------- |
25+
| `Tab` / `` / `` | Cycle period |
26+
| `v` | Cycle view |
27+
| `1` / `2` / `3` | Jump to Summary / Providers / Patterns |
28+
| `` / `` | Move provider cursor (Providers view) |
29+
| `Enter` / `Space` | Expand / collapse a provider |
30+
| `q` / `Esc` | Close the panel |
31+
32+
## Data source
33+
34+
Reads `~/.pi/agent/sessions/**/*.jsonl` (or `$PI_CODING_AGENT_DIR/sessions`). For each `assistant` message with a `usage` block, the extension records cost and token counts. Duplicate turns from branched session files are deduplicated by a fingerprint over timestamp + token counts.
35+
36+
## Sustainability estimate
37+
38+
The Summary view feeds the period's charged tokens (`input + output + cacheWrite`) into `impact-equivalences` `estimateAiImpact`, which returns electricity (kWh) and carbon (kg CO₂e) ranges along with formatted real-world equivalences (e.g. _"~X average US households for a day"_). Estimates are illustrative — see the package's source attribution for boundaries and assumptions.

0 commit comments

Comments
 (0)