pi-status-footer 1.0.5 → 1.0.6
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/README.md +8 -4
- package/package.json +8 -3
- package/stats-footer.ts +81 -1
package/README.md
CHANGED
|
@@ -7,11 +7,11 @@ A compact, zero-config two-line status footer for [pi](https://github.com/earend
|
|
|
7
7
|

|
|
8
8
|
|
|
9
9
|
```
|
|
10
|
-
📦 38%/128k 💾 63% ↑5.2k ↓8.1k ⚡42 t/s ⏳ 4:32 💬 1:18
|
|
10
|
+
📦 38%/128k 💾 63% ↑5.2k ↓8.1k ⚡42 t/s ⏳ 4:32 💬 1:18 💰 $0.420 +$0.020000
|
|
11
11
|
📁 my-project ▸ main +3 -1 🤖 openai/ry-very-long-modelid-4o 💭 medium
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
**Line 1 — Stats & timers:** context window usage with color-coded fullness (green < 60%, yellow < 80%, red ≥ 80%), cache hit rate, input/output tokens, tokens per second (live while streaming), agent run timer (⏳), current turn timer (💬).
|
|
14
|
+
**Line 1 — Stats & timers:** context window usage with color-coded fullness (green < 60%, yellow < 80%, red ≥ 80%), cache hit rate, input/output tokens, tokens per second (live while streaming), agent run timer (⏳), current turn timer (💬), and session cost (💰) with the current turn's delta.
|
|
15
15
|
|
|
16
16
|
**Line 2 — Project & model:** repo folder name, git branch, live working-tree diff from HEAD (+N added lines, -M deleted), provider/model, thinking level with themed color.
|
|
17
17
|
|
|
@@ -23,6 +23,7 @@ Everything auto-fits to your terminal width. Line 1 always keeps every segment (
|
|
|
23
23
|
- **Live TPS** — shows tokens/second during generation, stays visible between turns
|
|
24
24
|
- **Git awareness** — asynchronous, debounced `git diff --shortstat HEAD` so typing never blocks; branch changes detected automatically via `footerData.onBranchChange`
|
|
25
25
|
- **Cache hit rate** — percentage of prompt tokens served from cache
|
|
26
|
+
- **Cost, sum + delta** — session total with the current turn's cost alongside it, at fixed precision (sum 3 decimals, delta 6) so the segment width never changes and no value is abbreviated into scientific notation; models with no catalog pricing read `n/a` instead of a misleading `$0.00`
|
|
26
27
|
- **Context gauge** — percentage and raw max; shifts from green → yellow → red as you approach the limit
|
|
27
28
|
- **Thinking level** — color-coded to match pi's thinking theme
|
|
28
29
|
- **Responsive model id** — shortened from the left (with an `…` marker) when space is tight, so the provider and thinking level stay fully readable; the folder/git group drops only when the model still can't share the line
|
|
@@ -47,7 +48,7 @@ After installation, the footer appears automatically on the next pi TUI session.
|
|
|
47
48
|
|
|
48
49
|
## Display reference
|
|
49
50
|
|
|
50
|
-
### Line 1 — Stats & timers
|
|
51
|
+
### Line 1 — Stats, cost & timers
|
|
51
52
|
|
|
52
53
|
| Segment | Example | Source |
|
|
53
54
|
|---|---|---|
|
|
@@ -57,6 +58,9 @@ After installation, the footer appears automatically on the next pi TUI session.
|
|
|
57
58
|
| ⚡tps | `⚡42 t/s` | Live during generation; last completed rate shown between turns |
|
|
58
59
|
| ⏳ working | `⏳ 4:32` | Elapsed time since `agent_start`, HH:MM:SS above 1h |
|
|
59
60
|
| 💬 turn | `💬 1:18` | Elapsed time since last `turn_start` |
|
|
61
|
+
| 💰 cost | `💰 $0.420 +$0.020000` | Session sum of `usage.cost.total` across all entries, plus the current turn's delta |
|
|
62
|
+
|
|
63
|
+
Cost notes: the sum accumulates every usage-bearing entry (assistant messages, tool results, compaction, branch summaries) and survives a session resume, since pi persists per-message cost in the session file. The delta is the session cost read at `turn_start` subtracted from the current total, so it never folds the previous turn into the current one. The sum is rounded to 3 decimals and the delta to 6 — fixed precision, so the segment width is stable and nothing is ever rendered in scientific notation; a rate that is wrong by 1e6 shows as `$0.000`, which is visibly broken on purpose. A model that declares no catalog pricing (aggregator providers) reports zero cost and renders `n/a`, and a session with no usage at all renders no cost segment. Because the cost segment is last on line 1, it is also the first thing a narrow terminal clips.
|
|
60
64
|
|
|
61
65
|
### Line 2 — Project & model
|
|
62
66
|
|
|
@@ -74,7 +78,7 @@ The extension hooks into six pi lifecycle events:
|
|
|
74
78
|
|
|
75
79
|
- **`session_start`** — registers the footer via `ctx.ui.setFooter()`, discovers repo root, starts branch-change listener
|
|
76
80
|
- **`agent_start` / `agent_settled`** — controls the agent-run timer and a 1-second interval that triggers git diff refresh
|
|
77
|
-
- **`turn_start` / `turn_end`** — drives the per-turn timer
|
|
81
|
+
- **`turn_start` / `turn_end`** — drives the per-turn timer, and snapshots the session cost at `turn_start` as the baseline for the turn's cost delta
|
|
78
82
|
- **`message_start` / `message_update` / `message_end`** — tracks the generation window for live TPS. Most providers only report output-token usage at message end, so `message_update` estimates tokens live from the streamed delta characters (text/thinking/toolcall), calibrated against each message's real usage at `message_end`
|
|
79
83
|
- **`model_select`** — clears stale TPS on model switch
|
|
80
84
|
- **`session_shutdown`** — cleans up all state
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-status-footer",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Compact two-line status footer for pi: model, thinking level, tokens, TPS, cache hit rate, context usage, live git diff, and working/turn timers.",
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "Compact two-line status footer for pi: model, thinking level, tokens, cost, TPS, cache hit rate, context usage, live git diff, and working/turn timers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
7
7
|
"pi",
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"tokens",
|
|
15
15
|
"tps",
|
|
16
16
|
"tokens-per-second",
|
|
17
|
+
"cost",
|
|
18
|
+
"spend",
|
|
19
|
+
"usd",
|
|
20
|
+
"budget",
|
|
21
|
+
"pricing",
|
|
17
22
|
"cache",
|
|
18
23
|
"context",
|
|
19
24
|
"usage",
|
|
@@ -29,7 +34,7 @@
|
|
|
29
34
|
"streaming"
|
|
30
35
|
],
|
|
31
36
|
"scripts": {
|
|
32
|
-
"test": "node --experimental-strip-types test-live-tps.ts && node --experimental-strip-types test-layout.ts"
|
|
37
|
+
"test": "node --experimental-strip-types test-live-tps.ts && node --experimental-strip-types test-layout.ts && node --experimental-strip-types test-cost.ts"
|
|
33
38
|
},
|
|
34
39
|
"license": "MIT",
|
|
35
40
|
"repository": {
|
package/stats-footer.ts
CHANGED
|
@@ -48,6 +48,42 @@ export function formatDuration(ms: number): string {
|
|
|
48
48
|
return `${minutes}:${pad(seconds)}`;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/** Decimals for the session sum and for the per-turn delta. */
|
|
52
|
+
const COST_DECIMALS = 3;
|
|
53
|
+
const COST_DELTA_DECIMALS = 6;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Session cost in USD, fixed to 3 decimals. Fixed decimals rather than
|
|
57
|
+
* precision that follows the magnitude: the segment width then never changes
|
|
58
|
+
* as the total grows, and the value is never abbreviated away.
|
|
59
|
+
*
|
|
60
|
+
* Fixed decimals also mean no exponential fallback is ever needed. Dividing a
|
|
61
|
+
* rate by 1e6 twice is a real failure mode on this box (it happened), and
|
|
62
|
+
* `$0.000000` is a loud, obviously-broken number, whereas `$3.6e-9` could be
|
|
63
|
+
* read as a plausible price.
|
|
64
|
+
*
|
|
65
|
+
* A zero cost with tokens on the clock means the model carries no catalog
|
|
66
|
+
* pricing (aggregator/custom providers declare no rates, so pi records 0) —
|
|
67
|
+
* that is missing data, not a free session, so it reads `n/a`. Before any
|
|
68
|
+
* usage at all it is simply `-`.
|
|
69
|
+
*/
|
|
70
|
+
export function formatCost(usd: number, hasTokens = true): string {
|
|
71
|
+
if (!Number.isFinite(usd) || usd < 0) return "n/a";
|
|
72
|
+
if (usd === 0) return hasTokens ? "n/a" : "-";
|
|
73
|
+
return `$${usd.toFixed(COST_DECIMALS)}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Cost added by the current (or last) turn as a `+$x.xxxxxx` suffix, at 6
|
|
78
|
+
* decimals — a single wokey turn costs cents, so 3 would quantise the delta
|
|
79
|
+
* to zero. Empty while the turn has not spent anything, so the caller can
|
|
80
|
+
* append it blindly.
|
|
81
|
+
*/
|
|
82
|
+
export function formatCostDelta(usd: number): string {
|
|
83
|
+
if (!Number.isFinite(usd) || usd <= 0) return "";
|
|
84
|
+
return `+$${usd.toFixed(COST_DELTA_DECIMALS)}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
51
87
|
/**
|
|
52
88
|
* Output tokens per second for an assistant message generation window.
|
|
53
89
|
* Returns null when too little time has elapsed for a meaningful rate.
|
|
@@ -345,6 +381,23 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
345
381
|
let gitDeleted = 0;
|
|
346
382
|
let gitFetching = false;
|
|
347
383
|
let lastGitFetch = 0;
|
|
384
|
+
// Session-manager handle, kept so turn_start can read the cumulative cost
|
|
385
|
+
// synchronously (renders are throttled, so a cached total can still be
|
|
386
|
+
// missing the previous turn's final message when a new turn begins).
|
|
387
|
+
let sessionManager: { getEntries(): SessionEntry[] } | null = null;
|
|
388
|
+
// Cumulative session cost at the start of the current turn; the turn's
|
|
389
|
+
// delta is the current cumulative minus this baseline.
|
|
390
|
+
let costAtTurnStart = 0;
|
|
391
|
+
|
|
392
|
+
/** Cumulative session cost right now, read straight from the session. */
|
|
393
|
+
const readSessionCost = (): number => {
|
|
394
|
+
if (sessionManager === null) return 0;
|
|
395
|
+
try {
|
|
396
|
+
return collectSessionStats(sessionManager.getEntries()).usage.cost;
|
|
397
|
+
} catch {
|
|
398
|
+
return 0;
|
|
399
|
+
}
|
|
400
|
+
};
|
|
348
401
|
|
|
349
402
|
const rerender = () => tuiRef?.requestRender();
|
|
350
403
|
const stopTimer = () => {
|
|
@@ -388,6 +441,10 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
388
441
|
lastTps = null;
|
|
389
442
|
deltaChars = 0;
|
|
390
443
|
sessionCwd = ctx.cwd;
|
|
444
|
+
sessionManager = ctx.sessionManager;
|
|
445
|
+
// Baseline the turn delta at whatever the (possibly resumed) session
|
|
446
|
+
// already spent, so a delta only ever appears once a turn runs.
|
|
447
|
+
costAtTurnStart = readSessionCost();
|
|
391
448
|
folderName = basename(ctx.cwd);
|
|
392
449
|
const repoRoot = findRepoRoot(ctx.cwd);
|
|
393
450
|
repoName = repoRoot === null ? null : basename(repoRoot);
|
|
@@ -457,7 +514,22 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
457
514
|
? computeTps(liveOutput, genStart, Date.now())
|
|
458
515
|
: null;
|
|
459
516
|
const tpsValue = liveTps ?? lastTps;
|
|
460
|
-
//
|
|
517
|
+
// Cost: session sum plus the current turn's delta. Cost is derived
|
|
518
|
+
// from tokens, and it is the slowest-changing value on the line
|
|
519
|
+
// (it only ticks up at message boundaries), so it goes last: on a
|
|
520
|
+
// narrow terminal the right-edge clip drops the cost before the
|
|
521
|
+
// context/cache/token readouts.
|
|
522
|
+
const spentTokens =
|
|
523
|
+
usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
524
|
+
const turnCost = Math.max(0, usage.cost - costAtTurnStart);
|
|
525
|
+
const costDelta = formatCostDelta(turnCost);
|
|
526
|
+
const costSegment =
|
|
527
|
+
spentTokens === 0
|
|
528
|
+
? ""
|
|
529
|
+
: `💰 ${theme.fg("accent", formatCost(usage.cost))}${
|
|
530
|
+
costDelta === "" ? "" : ` ${theme.fg("dim", costDelta)}`
|
|
531
|
+
}`;
|
|
532
|
+
// Line 1 — stats only (context, cache, tokens, TPS, timers, cost). Every
|
|
461
533
|
// segment always renders; on very narrow terminals the line overflows
|
|
462
534
|
// and the TUI clips it rather than dropping stats.
|
|
463
535
|
const statsLine = joinSegments(
|
|
@@ -474,6 +546,7 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
474
546
|
theme.fg("dim", `⚡${Math.round(tpsValue ?? 0)} t/s`),
|
|
475
547
|
`⏳ ${theme.fg("accent", formatDuration(elapsed))}`,
|
|
476
548
|
`💬 ${theme.fg("accent", formatDuration(turnElapsed))}`,
|
|
549
|
+
costSegment,
|
|
477
550
|
],
|
|
478
551
|
separator,
|
|
479
552
|
);
|
|
@@ -550,6 +623,11 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
550
623
|
pi.on("turn_start", () => {
|
|
551
624
|
turnStart = Date.now();
|
|
552
625
|
lastTurnDuration = 0;
|
|
626
|
+
// Baseline for the turn's cost delta, read from the session rather
|
|
627
|
+
// than reused from the last render: agent_settled requests a render,
|
|
628
|
+
// but that render may not have run yet when the next turn starts,
|
|
629
|
+
// which would fold the previous turn's cost into this one.
|
|
630
|
+
costAtTurnStart = readSessionCost();
|
|
553
631
|
});
|
|
554
632
|
pi.on("turn_end", () => {
|
|
555
633
|
if (turnStart !== null) lastTurnDuration = Date.now() - turnStart;
|
|
@@ -567,6 +645,8 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
567
645
|
lastTps = null;
|
|
568
646
|
deltaChars = 0;
|
|
569
647
|
sessionCwd = null;
|
|
648
|
+
sessionManager = null;
|
|
649
|
+
costAtTurnStart = 0;
|
|
570
650
|
folderName = null;
|
|
571
651
|
repoName = null;
|
|
572
652
|
gitAdded = 0;
|