pi-status-footer 1.0.6 β 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 +7 -7
- package/package.json +1 -1
- package/stats-footer.ts +42 -34
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,7 +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
|
|
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`
|
|
27
27
|
- **Context gauge** β percentage and raw max; shifts from green β yellow β red as you approach the limit
|
|
28
28
|
- **Thinking level** β color-coded to match pi's thinking theme
|
|
29
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
|
|
@@ -55,12 +55,12 @@ After installation, the footer appears automatically on the next pi TUI session.
|
|
|
55
55
|
| π¦context | `π¦ 38%/128k` | `ctx.getContextUsage()`, color-coded by percent |
|
|
56
56
|
| πΎcache | `πΎ 63%` | `cacheRead / (input + cacheRead + cacheWrite)` |
|
|
57
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 |
|
|
58
59
|
| β‘tps | `β‘42 t/s` | Live during generation; last completed rate shown between turns |
|
|
59
60
|
| β³ working | `β³ 4:32` | Elapsed time since `agent_start`, HH:MM:SS above 1h |
|
|
60
61
|
| π¬ 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
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
|
|
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
64
|
|
|
65
65
|
### Line 2 β Project & model
|
|
66
66
|
|
|
@@ -77,8 +77,8 @@ Cost notes: the sum accumulates every usage-bearing entry (assistant messages, t
|
|
|
77
77
|
The extension hooks into six pi lifecycle events:
|
|
78
78
|
|
|
79
79
|
- **`session_start`** β registers the footer via `ctx.ui.setFooter()`, discovers repo root, starts branch-change listener
|
|
80
|
-
- **`agent_start` / `agent_settled`** β controls the agent-run timer and a 1-second interval that triggers git diff refresh
|
|
81
|
-
- **`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.
|
|
82
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`
|
|
83
83
|
- **`model_select`** β clears stale TPS on model switch
|
|
84
84
|
- **`session_shutdown`** β cleans up all state
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-status-footer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
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",
|
package/stats-footer.ts
CHANGED
|
@@ -48,7 +48,7 @@ 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-
|
|
51
|
+
/** Decimals for the session sum and for the per-run delta. */
|
|
52
52
|
const COST_DECIMALS = 3;
|
|
53
53
|
const COST_DELTA_DECIMALS = 6;
|
|
54
54
|
|
|
@@ -65,19 +65,20 @@ const COST_DELTA_DECIMALS = 6;
|
|
|
65
65
|
* A zero cost with tokens on the clock means the model carries no catalog
|
|
66
66
|
* pricing (aggregator/custom providers declare no rates, so pi records 0) β
|
|
67
67
|
* that is missing data, not a free session, so it reads `n/a`. Before any
|
|
68
|
-
* usage at all
|
|
68
|
+
* usage at all there is nothing to report, but the segment still renders as a
|
|
69
|
+
* `$0.000` placeholder rather than vanishing.
|
|
69
70
|
*/
|
|
70
71
|
export function formatCost(usd: number, hasTokens = true): string {
|
|
71
72
|
if (!Number.isFinite(usd) || usd < 0) return "n/a";
|
|
72
|
-
if (usd === 0) return hasTokens ? "n/a" :
|
|
73
|
+
if (usd === 0) return hasTokens ? "n/a" : `$${(0).toFixed(COST_DECIMALS)}`;
|
|
73
74
|
return `$${usd.toFixed(COST_DECIMALS)}`;
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
/**
|
|
77
|
-
* Cost added by the current (or last)
|
|
78
|
-
* decimals β
|
|
79
|
-
*
|
|
80
|
-
*
|
|
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.
|
|
81
82
|
*/
|
|
82
83
|
export function formatCostDelta(usd: number): string {
|
|
83
84
|
if (!Number.isFinite(usd) || usd <= 0) return "";
|
|
@@ -381,13 +382,22 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
381
382
|
let gitDeleted = 0;
|
|
382
383
|
let gitFetching = false;
|
|
383
384
|
let lastGitFetch = 0;
|
|
384
|
-
// Session-manager handle, kept so
|
|
385
|
+
// Session-manager handle, kept so agent_start can read the cumulative cost
|
|
385
386
|
// synchronously (renders are throttled, so a cached total can still be
|
|
386
|
-
// missing the previous
|
|
387
|
+
// missing the previous run's final message when a new run begins).
|
|
387
388
|
let sessionManager: { getEntries(): SessionEntry[] } | null = null;
|
|
388
|
-
// Cumulative session cost at the start of the current
|
|
389
|
-
//
|
|
390
|
-
|
|
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;
|
|
391
401
|
|
|
392
402
|
/** Cumulative session cost right now, read straight from the session. */
|
|
393
403
|
const readSessionCost = (): number => {
|
|
@@ -442,9 +452,9 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
442
452
|
deltaChars = 0;
|
|
443
453
|
sessionCwd = ctx.cwd;
|
|
444
454
|
sessionManager = ctx.sessionManager;
|
|
445
|
-
// Baseline the
|
|
446
|
-
//
|
|
447
|
-
|
|
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();
|
|
448
458
|
folderName = basename(ctx.cwd);
|
|
449
459
|
const repoRoot = findRepoRoot(ctx.cwd);
|
|
450
460
|
repoName = repoRoot === null ? null : basename(repoRoot);
|
|
@@ -514,21 +524,19 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
514
524
|
? computeTps(liveOutput, genStart, Date.now())
|
|
515
525
|
: null;
|
|
516
526
|
const tpsValue = liveTps ?? lastTps;
|
|
517
|
-
// Cost: session sum plus the current
|
|
518
|
-
//
|
|
519
|
-
//
|
|
520
|
-
// narrow terminal the right-edge clip drops the cost before the
|
|
521
|
-
// context/cache/token readouts.
|
|
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.
|
|
522
530
|
const spentTokens =
|
|
523
531
|
usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
524
|
-
const
|
|
525
|
-
const costDelta = formatCostDelta(
|
|
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.
|
|
526
536
|
const costSegment =
|
|
527
|
-
spentTokens
|
|
528
|
-
? ""
|
|
529
|
-
|
|
530
|
-
costDelta === "" ? "" : ` ${theme.fg("dim", costDelta)}`
|
|
531
|
-
}`;
|
|
537
|
+
`π° ${theme.fg("accent", formatCost(usage.cost, spentTokens > 0))}${
|
|
538
|
+
costDelta === "" ? "" : theme.fg("dim", ` ${costDelta}`)
|
|
539
|
+
}`;
|
|
532
540
|
// Line 1 β stats only (context, cache, tokens, TPS, timers, cost). Every
|
|
533
541
|
// segment always renders; on very narrow terminals the line overflows
|
|
534
542
|
// and the TUI clips it rather than dropping stats.
|
|
@@ -543,10 +551,10 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
543
551
|
"dim",
|
|
544
552
|
`β${formatTokens(usage.input)} β${formatTokens(usage.output)}`,
|
|
545
553
|
),
|
|
554
|
+
costSegment,
|
|
546
555
|
theme.fg("dim", `β‘${Math.round(tpsValue ?? 0)} t/s`),
|
|
547
556
|
`β³ ${theme.fg("accent", formatDuration(elapsed))}`,
|
|
548
557
|
`π¬ ${theme.fg("accent", formatDuration(turnElapsed))}`,
|
|
549
|
-
costSegment,
|
|
550
558
|
],
|
|
551
559
|
separator,
|
|
552
560
|
);
|
|
@@ -602,6 +610,11 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
602
610
|
pi.on("agent_start", () => {
|
|
603
611
|
if (runStart === null) runStart = Date.now();
|
|
604
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();
|
|
605
618
|
stopTimer();
|
|
606
619
|
timer = setInterval(() => {
|
|
607
620
|
if (sessionCwd !== null) fetchGitDiff(sessionCwd);
|
|
@@ -623,11 +636,6 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
623
636
|
pi.on("turn_start", () => {
|
|
624
637
|
turnStart = Date.now();
|
|
625
638
|
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();
|
|
631
639
|
});
|
|
632
640
|
pi.on("turn_end", () => {
|
|
633
641
|
if (turnStart !== null) lastTurnDuration = Date.now() - turnStart;
|
|
@@ -646,7 +654,7 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
646
654
|
deltaChars = 0;
|
|
647
655
|
sessionCwd = null;
|
|
648
656
|
sessionManager = null;
|
|
649
|
-
|
|
657
|
+
costAtRunStart = 0;
|
|
650
658
|
folderName = null;
|
|
651
659
|
repoName = null;
|
|
652
660
|
gitAdded = 0;
|