pi-status-footer 1.0.5 β 1.0.7
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 +9 -5
- package/package.json +8 -3
- package/stats-footer.ts +89 -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 π° $0.420 +$0.020000 β‘42 t/s β³ 4:32 π¬ 1:18
|
|
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, session cost with the current run's cost (π°), tokens per second (live while streaming), agent run timer (β³), current turn timer (π¬).
|
|
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 agent run'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; a fresh session shows a `$0.000` placeholder and 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,17 +48,20 @@ 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
|
|---|---|---|
|
|
54
55
|
| π¦context | `π¦ 38%/128k` | `ctx.getContextUsage()`, color-coded by percent |
|
|
55
56
|
| πΎcache | `πΎ 63%` | `cacheRead / (input + cacheRead + cacheWrite)` |
|
|
56
57
|
| βinput βoutput | `β5.2k β8.1k` | Session `usage.input / usage.output` (accumulated across all entries) |
|
|
58
|
+
| π° cost | `π° $0.420 +$0.020000` | Session sum of `usage.cost.total`, plus the current agent run's cost |
|
|
57
59
|
| β‘tps | `β‘42 t/s` | Live during generation; last completed rate shown between turns |
|
|
58
60
|
| β³ working | `β³ 4:32` | Elapsed time since `agent_start`, HH:MM:SS above 1h |
|
|
59
61
|
| π¬ turn | `π¬ 1:18` | Elapsed time since last `turn_start` |
|
|
60
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 sampled at `agent_start` subtracted from the current total, so it covers the same window as the β³ run timer and freezes when the run settles. It is deliberately **not** sampled per turn: in pi a "turn" is one assistant message inside the agentic tool loop, so a per-turn baseline was rewritten after every message and the delta flashed at `message_end` and was gone again before the next message finished streaming. 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`; before any usage the segment renders a `$0.000` placeholder so it is present from the first frame.
|
|
64
|
+
|
|
61
65
|
### Line 2 β Project & model
|
|
62
66
|
|
|
63
67
|
| Segment | Example | Source |
|
|
@@ -73,8 +77,8 @@ After installation, the footer appears automatically on the next pi TUI session.
|
|
|
73
77
|
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
|
-
- **`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
|
|
80
|
+
- **`agent_start` / `agent_settled`** β controls the agent-run timer and a 1-second interval that triggers git diff refresh; also samples the session cost at `agent_start` as the baseline for the run's cost delta
|
|
81
|
+
- **`turn_start` / `turn_end`** β drives the per-turn timer. It deliberately does *not* touch the cost baseline: see the cost notes above.
|
|
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.7",
|
|
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,43 @@ 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-run 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 there is nothing to report, but the segment still renders as a
|
|
69
|
+
* `$0.000` placeholder rather than vanishing.
|
|
70
|
+
*/
|
|
71
|
+
export function formatCost(usd: number, hasTokens = true): string {
|
|
72
|
+
if (!Number.isFinite(usd) || usd < 0) return "n/a";
|
|
73
|
+
if (usd === 0) return hasTokens ? "n/a" : `$${(0).toFixed(COST_DECIMALS)}`;
|
|
74
|
+
return `$${usd.toFixed(COST_DECIMALS)}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Cost added by the current (or last) agent run as a `+$x.xxxxxx` suffix, at
|
|
79
|
+
* 6 decimals β one wokey run costs cents, so 3 would quantise the delta to
|
|
80
|
+
* zero. Empty while the run has not spent anything, so the caller can append
|
|
81
|
+
* it blindly.
|
|
82
|
+
*/
|
|
83
|
+
export function formatCostDelta(usd: number): string {
|
|
84
|
+
if (!Number.isFinite(usd) || usd <= 0) return "";
|
|
85
|
+
return `+$${usd.toFixed(COST_DELTA_DECIMALS)}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
51
88
|
/**
|
|
52
89
|
* Output tokens per second for an assistant message generation window.
|
|
53
90
|
* Returns null when too little time has elapsed for a meaningful rate.
|
|
@@ -345,6 +382,32 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
345
382
|
let gitDeleted = 0;
|
|
346
383
|
let gitFetching = false;
|
|
347
384
|
let lastGitFetch = 0;
|
|
385
|
+
// Session-manager handle, kept so agent_start can read the cumulative cost
|
|
386
|
+
// synchronously (renders are throttled, so a cached total can still be
|
|
387
|
+
// missing the previous run's final message when a new run begins).
|
|
388
|
+
let sessionManager: { getEntries(): SessionEntry[] } | null = null;
|
|
389
|
+
// Cumulative session cost at the start of the current agent run; the delta
|
|
390
|
+
// is the current cumulative minus this baseline β so the sum and the delta
|
|
391
|
+
// cover the session and the run, the same windows as the token totals and
|
|
392
|
+
// the run timer.
|
|
393
|
+
//
|
|
394
|
+
// Sampled at agent_start, NOT turn_start: in pi a "turn" is one assistant
|
|
395
|
+
// message inside the agentic tool loop (agent-session.js resets _turnIndex
|
|
396
|
+
// on agent_start and increments it on every turn_end), so a per-turn
|
|
397
|
+
// baseline was rewritten after every message. The delta appeared at
|
|
398
|
+
// message_end and was gone again by the next turn_start β never on screen
|
|
399
|
+
// for the whole time the next message was streaming.
|
|
400
|
+
let costAtRunStart = 0;
|
|
401
|
+
|
|
402
|
+
/** Cumulative session cost right now, read straight from the session. */
|
|
403
|
+
const readSessionCost = (): number => {
|
|
404
|
+
if (sessionManager === null) return 0;
|
|
405
|
+
try {
|
|
406
|
+
return collectSessionStats(sessionManager.getEntries()).usage.cost;
|
|
407
|
+
} catch {
|
|
408
|
+
return 0;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
348
411
|
|
|
349
412
|
const rerender = () => tuiRef?.requestRender();
|
|
350
413
|
const stopTimer = () => {
|
|
@@ -388,6 +451,10 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
388
451
|
lastTps = null;
|
|
389
452
|
deltaChars = 0;
|
|
390
453
|
sessionCwd = ctx.cwd;
|
|
454
|
+
sessionManager = ctx.sessionManager;
|
|
455
|
+
// Baseline the delta at whatever the (possibly resumed) session already
|
|
456
|
+
// spent, so a delta only ever appears once a run actually spends.
|
|
457
|
+
costAtRunStart = readSessionCost();
|
|
391
458
|
folderName = basename(ctx.cwd);
|
|
392
459
|
const repoRoot = findRepoRoot(ctx.cwd);
|
|
393
460
|
repoName = repoRoot === null ? null : basename(repoRoot);
|
|
@@ -457,7 +524,20 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
457
524
|
? computeTps(liveOutput, genStart, Date.now())
|
|
458
525
|
: null;
|
|
459
526
|
const tpsValue = liveTps ?? lastTps;
|
|
460
|
-
//
|
|
527
|
+
// Cost: session sum plus the current agent run's delta. It sits
|
|
528
|
+
// next to the token counters it is derived from, ahead of the
|
|
529
|
+
// live rate and the timers.
|
|
530
|
+
const spentTokens =
|
|
531
|
+
usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
532
|
+
const runCost = Math.max(0, usage.cost - costAtRunStart);
|
|
533
|
+
const costDelta = formatCostDelta(runCost);
|
|
534
|
+
// Always rendered, so a fresh session shows a $0.000 placeholder
|
|
535
|
+
// rather than the segment appearing out of nowhere later.
|
|
536
|
+
const costSegment =
|
|
537
|
+
`π° ${theme.fg("accent", formatCost(usage.cost, spentTokens > 0))}${
|
|
538
|
+
costDelta === "" ? "" : theme.fg("dim", ` ${costDelta}`)
|
|
539
|
+
}`;
|
|
540
|
+
// Line 1 β stats only (context, cache, tokens, TPS, timers, cost). Every
|
|
461
541
|
// segment always renders; on very narrow terminals the line overflows
|
|
462
542
|
// and the TUI clips it rather than dropping stats.
|
|
463
543
|
const statsLine = joinSegments(
|
|
@@ -471,6 +551,7 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
471
551
|
"dim",
|
|
472
552
|
`β${formatTokens(usage.input)} β${formatTokens(usage.output)}`,
|
|
473
553
|
),
|
|
554
|
+
costSegment,
|
|
474
555
|
theme.fg("dim", `β‘${Math.round(tpsValue ?? 0)} t/s`),
|
|
475
556
|
`β³ ${theme.fg("accent", formatDuration(elapsed))}`,
|
|
476
557
|
`π¬ ${theme.fg("accent", formatDuration(turnElapsed))}`,
|
|
@@ -529,6 +610,11 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
529
610
|
pi.on("agent_start", () => {
|
|
530
611
|
if (runStart === null) runStart = Date.now();
|
|
531
612
|
lastRunDuration = 0;
|
|
613
|
+
// Baseline for the cost delta, read from the session rather than reused
|
|
614
|
+
// from the last render: agent_settled requests a render, but that render
|
|
615
|
+
// may not have run yet when the next run starts, which would fold the
|
|
616
|
+
// previous run's cost into this one. Once per run, not once per turn.
|
|
617
|
+
costAtRunStart = readSessionCost();
|
|
532
618
|
stopTimer();
|
|
533
619
|
timer = setInterval(() => {
|
|
534
620
|
if (sessionCwd !== null) fetchGitDiff(sessionCwd);
|
|
@@ -567,6 +653,8 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
567
653
|
lastTps = null;
|
|
568
654
|
deltaChars = 0;
|
|
569
655
|
sessionCwd = null;
|
|
656
|
+
sessionManager = null;
|
|
657
|
+
costAtRunStart = 0;
|
|
570
658
|
folderName = null;
|
|
571
659
|
repoName = null;
|
|
572
660
|
gitAdded = 0;
|