pi-status-footer 1.4.1 → 1.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/README.md +6 -6
- package/package.json +2 -7
- package/stats-footer.ts +19 -108
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# pi-status-footer
|
|
2
2
|
|
|
3
|
-
Compact status footer for the pi TUI: context usage, tokens,
|
|
3
|
+
Compact status footer for the pi TUI: context usage, tokens, live TPS, run completion time, git diff, and run timers, plus an optional third line for other extensions' status segments.
|
|
4
4
|
|
|
5
5
|
See [pi.dev docs](https://pi.dev) for how extensions work.
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ See [pi.dev docs](https://pi.dev) for how extensions work.
|
|
|
8
8
|
|
|
9
9
|
| Extension | Command / shortcut | What it does |
|
|
10
10
|
|---|---|---|
|
|
11
|
-
| `stats-footer.ts` | (no command; TUI footer widget) | Renders a footer: line 1 usage/
|
|
11
|
+
| `stats-footer.ts` | (no command; TUI footer widget) | Renders a footer: line 1 usage/completion clock/timers, line 2 folder/git/model, and a conditional line 3 carrying statuses other extensions set via `ctx.ui.setStatus()` |
|
|
12
12
|
|
|
13
13
|
It registers no slash commands, shortcuts, flags, tools, or providers. It hooks session/agent/turn/message events (`session_start`, `agent_start`, `agent_settled`, `turn_start/end`, `message_start/update/end`, `model_select`, `thinking_level_select`, `session_info_changed`, `session_shutdown`) to update the footer.
|
|
14
14
|
|
|
@@ -36,18 +36,18 @@ The footer appears automatically in the next TUI session.
|
|
|
36
36
|
Just run `pi` in the TUI. Example footer:
|
|
37
37
|
|
|
38
38
|
```
|
|
39
|
-
38%/128k 63% ↑5.2k ↓8.1k 42 t/s
|
|
39
|
+
38%/128k 63% ↑5.2k ↓8.1k 42 t/s 08:23:30 4:32 1:18
|
|
40
40
|
my-project ▸ main +3 -1 openai/gpt-4o medium
|
|
41
41
|
bg 1 running · Shift↓
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Icons are Nerd Font glyphs (Font Awesome / Material Design ranges), not emoji. Emoji are colour bitmaps whose rendering the terminal decides: some hosts (xterm.js/Chromium, iTerm2) paint them in full colour while others (Alacritty, kitty) draw flat monochrome silhouettes, so the same footer looked different per terminal. Nerd Font glyphs are single-cell line art everywhere. Requires a patched Nerd Font as the terminal font (for example `JetBrainsMono Nerd Font`); without one the icons show as boxes.
|
|
45
45
|
|
|
46
|
-
Line 1 is three groups: usage on the left (context used/limit, cache hit rate, input/output tokens, tokens/sec,
|
|
46
|
+
Line 1 is three groups: usage on the left (context used/limit, cache hit rate, input/output tokens, tokens/sec), the run completion clock in the middle, and the timers on the right (agent-run timer, current-turn timer). Tokens/sec sits with the output tokens it is derived from and is always rendered, so it shows from a session's first frame rather than appearing only once a rate exists. Line 2 is three groups too: folder (repo root, or cwd outside a repo) on the left, git branch + working-tree diff vs HEAD in the middle, provider/model + thinking level on the right.
|
|
47
47
|
|
|
48
48
|
The groups spread across the full width when the terminal is wide enough — the common case, and what stops the footer from piling everything against the left edge. When the line cannot hold the spread, the footer falls back to the compact left-aligned flow; on line 2 it then shortens the model id from the left and finally drops the git group.
|
|
49
49
|
|
|
50
|
-
The completion clock appears when a run settles, keeps the local wall-clock time frozen until the next run starts, and is never shown for an aborted run. It is the same fact `pi-done-at` notifies with, but persistent instead of a transient notification — so both can be installed, or `pi-done-at` can be dropped for a quieter TUI.
|
|
50
|
+
The completion clock appears centred on line 1 when a run settles, keeps the local wall-clock time frozen until the next run starts, and is never shown for an aborted run. It is the same fact `pi-done-at` notifies with, but persistent instead of a transient notification — so both can be installed, or `pi-done-at` can be dropped for a quieter TUI.
|
|
51
51
|
|
|
52
52
|
Line 3 is conditional: it appears only while an extension has status text registered through `ctx.ui.setStatus()` (for example `pi-background-tasks`'s `bg 1 running · Shift↓`, or `pi-subagents` progress), and it disappears as soon as the last status clears, so the footer returns to its two-line height. Segments keep their own styling and are truncated to the terminal width like the other lines. This matters because a custom footer replaces pi's built-in footer: a footer that never reads those statuses hides other extensions' progress entirely.
|
|
53
53
|
|
|
@@ -57,7 +57,7 @@ Zero config. No env vars, no settings keys.
|
|
|
57
57
|
|
|
58
58
|
## Security note
|
|
59
59
|
|
|
60
|
-
Runs in-process with your OS permissions. It reads session entries (token usage,
|
|
60
|
+
Runs in-process with your OS permissions. It reads session entries (token usage, model, context) and runs one shell command, debounced to 1s during agent runs: `git diff --shortstat HEAD` (with `--no-optional-locks`, 3s timeout) plus a walk-up check for `.git` to find the repo root. No network access, no file writes.
|
|
61
61
|
|
|
62
62
|
## Update / remove / enable-disable
|
|
63
63
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-status-footer",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Compact status footer for pi: model, thinking level, tokens,
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "Compact status footer for pi: model, thinking level, tokens, TPS, cache hit rate, context usage, live git diff, working/turn timers, run completion time, plus a conditional third line for other extensions' status segments.",
|
|
5
5
|
"author": "kslamph",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"pi-package",
|
|
@@ -15,11 +15,6 @@
|
|
|
15
15
|
"tokens",
|
|
16
16
|
"tps",
|
|
17
17
|
"tokens-per-second",
|
|
18
|
-
"cost",
|
|
19
|
-
"spend",
|
|
20
|
-
"usd",
|
|
21
|
-
"budget",
|
|
22
|
-
"pricing",
|
|
23
18
|
"cache",
|
|
24
19
|
"context",
|
|
25
20
|
"usage",
|
package/stats-footer.ts
CHANGED
|
@@ -33,7 +33,6 @@ type RenderTui = { requestRender(force?: boolean): void };
|
|
|
33
33
|
export const ICONS = {
|
|
34
34
|
context: "\u{F1B2}", // fa-cube
|
|
35
35
|
cache: "\u{F1C0}", // fa-database
|
|
36
|
-
cost: "\u{F155}", // fa-usd
|
|
37
36
|
tps: "\u{F0E7}", // fa-flash (bolt)
|
|
38
37
|
runTimer: "\u{F252}", // fa-hourglass-half
|
|
39
38
|
turnTimer: "\u{F0E5}", // fa-comment-o
|
|
@@ -85,43 +84,6 @@ export function formatDoneAt(when: Date | number = Date.now()): string {
|
|
|
85
84
|
return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
86
85
|
}
|
|
87
86
|
|
|
88
|
-
/** Decimals for the session sum and for the per-run delta. */
|
|
89
|
-
const COST_DECIMALS = 3;
|
|
90
|
-
const COST_DELTA_DECIMALS = 6;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Session cost in USD, fixed to 3 decimals. Fixed decimals rather than
|
|
94
|
-
* precision that follows the magnitude: the segment width then never changes
|
|
95
|
-
* as the total grows, and the value is never abbreviated away.
|
|
96
|
-
*
|
|
97
|
-
* Fixed decimals also mean no exponential fallback is ever needed. Dividing a
|
|
98
|
-
* rate by 1e6 twice is a real failure mode on this box (it happened), and
|
|
99
|
-
* `$0.000000` is a loud, obviously-broken number, whereas `$3.6e-9` could be
|
|
100
|
-
* read as a plausible price.
|
|
101
|
-
*
|
|
102
|
-
* A zero cost with tokens on the clock means the model carries no catalog
|
|
103
|
-
* pricing (aggregator/custom providers declare no rates, so pi records 0) —
|
|
104
|
-
* that is missing data, not a free session, so it reads `n/a`. Before any
|
|
105
|
-
* usage at all there is nothing to report, but the segment still renders as a
|
|
106
|
-
* `$0.000` placeholder rather than vanishing.
|
|
107
|
-
*/
|
|
108
|
-
export function formatCost(usd: number, hasTokens = true): string {
|
|
109
|
-
if (!Number.isFinite(usd) || usd < 0) return "n/a";
|
|
110
|
-
if (usd === 0) return hasTokens ? "n/a" : `$${(0).toFixed(COST_DECIMALS)}`;
|
|
111
|
-
return `$${usd.toFixed(COST_DECIMALS)}`;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Cost added by the current (or last) agent run as a `+$x.xxxxxx` suffix, at
|
|
116
|
-
* 6 decimals — one wokey run costs cents, so 3 would quantise the delta to
|
|
117
|
-
* zero. Empty while the run has not spent anything, so the caller can append
|
|
118
|
-
* it blindly.
|
|
119
|
-
*/
|
|
120
|
-
export function formatCostDelta(usd: number): string {
|
|
121
|
-
if (!Number.isFinite(usd) || usd <= 0) return "";
|
|
122
|
-
return `+$${usd.toFixed(COST_DELTA_DECIMALS)}`;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
87
|
/**
|
|
126
88
|
* Output tokens per second for an assistant message generation window.
|
|
127
89
|
* Returns null when too little time has elapsed for a meaningful rate.
|
|
@@ -172,8 +134,8 @@ export function collectSessionStats(entries: readonly SessionEntry[]): {
|
|
|
172
134
|
// (`kind: "cache_warm"`) — is recorded *only* as a usage entry: no
|
|
173
135
|
// assistant message, no tool result. Pi counts these in session
|
|
174
136
|
// totals (docs/session-format.md), so skipping them would under-report
|
|
175
|
-
//
|
|
176
|
-
//
|
|
137
|
+
// tokens and the cache-hit rate against `/session`. Unknown kinds are
|
|
138
|
+
// counted like any other usage, per the same doc.
|
|
177
139
|
if (entry.type === "usage") {
|
|
178
140
|
addUsage(usage, entry.usage);
|
|
179
141
|
}
|
|
@@ -490,32 +452,6 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
490
452
|
let gitDeleted = 0;
|
|
491
453
|
let gitFetching = false;
|
|
492
454
|
let lastGitFetch = 0;
|
|
493
|
-
// Session-manager handle, kept so agent_start can read the cumulative cost
|
|
494
|
-
// synchronously (renders are throttled, so a cached total can still be
|
|
495
|
-
// missing the previous run's final message when a new run begins).
|
|
496
|
-
let sessionManager: { getEntries(): SessionEntry[] } | null = null;
|
|
497
|
-
// Cumulative session cost at the start of the current agent run; the delta
|
|
498
|
-
// is the current cumulative minus this baseline — so the sum and the delta
|
|
499
|
-
// cover the session and the run, the same windows as the token totals and
|
|
500
|
-
// the run timer.
|
|
501
|
-
//
|
|
502
|
-
// Sampled at agent_start, NOT turn_start: in pi a "turn" is one assistant
|
|
503
|
-
// message inside the agentic tool loop (agent-session.js resets _turnIndex
|
|
504
|
-
// on agent_start and increments it on every turn_end), so a per-turn
|
|
505
|
-
// baseline was rewritten after every message. The delta appeared at
|
|
506
|
-
// message_end and was gone again by the next turn_start — never on screen
|
|
507
|
-
// for the whole time the next message was streaming.
|
|
508
|
-
let costAtRunStart = 0;
|
|
509
|
-
|
|
510
|
-
/** Cumulative session cost right now, read straight from the session. */
|
|
511
|
-
const readSessionCost = (): number => {
|
|
512
|
-
if (sessionManager === null) return 0;
|
|
513
|
-
try {
|
|
514
|
-
return collectSessionStats(sessionManager.getEntries()).usage.cost;
|
|
515
|
-
} catch {
|
|
516
|
-
return 0;
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
455
|
|
|
520
456
|
const rerender = () => tuiRef?.requestRender();
|
|
521
457
|
const stopTimer = () => {
|
|
@@ -560,10 +496,6 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
560
496
|
lastTps = null;
|
|
561
497
|
deltaChars = 0;
|
|
562
498
|
sessionCwd = ctx.cwd;
|
|
563
|
-
sessionManager = ctx.sessionManager;
|
|
564
|
-
// Baseline the delta at whatever the (possibly resumed) session already
|
|
565
|
-
// spent, so a delta only ever appears once a run actually spends.
|
|
566
|
-
costAtRunStart = readSessionCost();
|
|
567
499
|
folderName = basename(ctx.cwd);
|
|
568
500
|
const repoRoot = findRepoRoot(ctx.cwd);
|
|
569
501
|
repoName = repoRoot === null ? null : basename(repoRoot);
|
|
@@ -633,27 +565,12 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
633
565
|
? computeTps(liveOutput, genStart, Date.now())
|
|
634
566
|
: null;
|
|
635
567
|
const tpsValue = liveTps ?? lastTps;
|
|
636
|
-
//
|
|
637
|
-
//
|
|
638
|
-
//
|
|
639
|
-
//
|
|
640
|
-
//
|
|
641
|
-
|
|
642
|
-
usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
643
|
-
const runCost = Math.max(0, usage.cost - costAtRunStart);
|
|
644
|
-
const costDelta = formatCostDelta(runCost);
|
|
645
|
-
// Always rendered, so a fresh session shows a $0.000 placeholder
|
|
646
|
-
// rather than the segment appearing out of nowhere later.
|
|
647
|
-
const costSegment =
|
|
648
|
-
`${ICONS.cost} ${theme.fg("accent", formatCost(usage.cost, spentTokens > 0))}${
|
|
649
|
-
costDelta === "" ? "" : theme.fg("dim", ` ${costDelta}`)
|
|
650
|
-
}`;
|
|
651
|
-
// Line 1 — three groups spread across the full width: usage on
|
|
652
|
-
// the left (context, cache, tokens, live rate, completion clock),
|
|
653
|
-
// spend in the middle, timers on the right. Wide terminals therefore
|
|
654
|
-
// use their space instead of hugging the left edge; narrow ones fall
|
|
655
|
-
// back to one compact left-aligned run, which the TUI clips rather
|
|
656
|
-
// than reordering.
|
|
568
|
+
// Line 1 — three groups spread across the full width: the usage
|
|
569
|
+
// counters on the left (context, cache, tokens, live rate), the
|
|
570
|
+
// completion clock in the middle, the timers on the right. Wide
|
|
571
|
+
// terminals therefore use their space instead of hugging the left
|
|
572
|
+
// edge; narrow ones fall back to one compact left-aligned run,
|
|
573
|
+
// which the TUI clips rather than reordering.
|
|
657
574
|
const leftSegments = [
|
|
658
575
|
`${ICONS.context} ${theme.fg(contextColor, contextText)}`,
|
|
659
576
|
theme.fg(
|
|
@@ -665,17 +582,18 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
665
582
|
`↑${formatTokens(usage.input)} ↓${formatTokens(usage.output)}`,
|
|
666
583
|
),
|
|
667
584
|
// The rate belongs beside the output tokens it is derived
|
|
668
|
-
// from,
|
|
585
|
+
// from, so the usage counters read as one block.
|
|
669
586
|
theme.fg("dim", `${ICONS.tps} ${Math.round(tpsValue ?? 0)} t/s`),
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
587
|
+
];
|
|
588
|
+
// Wall-clock time of the last settled run, centred on line 1: shown
|
|
589
|
+
// from agent_settled until the next run starts, and never for an
|
|
590
|
+
// aborted run — the same rule pi-done-at's notification uses. The
|
|
591
|
+
// centre slot keeps it clear of both the usage counters and the
|
|
592
|
+
// timers, and an in-flight run simply leaves the slot empty.
|
|
593
|
+
const doneAtSegment =
|
|
675
594
|
settledAt === null
|
|
676
595
|
? ""
|
|
677
|
-
: `${ICONS.clock} ${theme.fg("dim", formatDoneAt(settledAt))}
|
|
678
|
-
];
|
|
596
|
+
: `${ICONS.clock} ${theme.fg("dim", formatDoneAt(settledAt))}`;
|
|
679
597
|
const rightSegments = [
|
|
680
598
|
`${ICONS.runTimer} ${theme.fg("accent", formatDuration(elapsed))}`,
|
|
681
599
|
`${ICONS.turnTimer} ${theme.fg("accent", formatDuration(turnElapsed))}`,
|
|
@@ -684,14 +602,14 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
684
602
|
distributeGroups(
|
|
685
603
|
[
|
|
686
604
|
{ text: joinSegments(leftSegments, separator), align: "left" },
|
|
687
|
-
{ text:
|
|
605
|
+
{ text: doneAtSegment, align: "center" },
|
|
688
606
|
{ text: joinSegments(rightSegments, separator), align: "right" },
|
|
689
607
|
],
|
|
690
608
|
width,
|
|
691
609
|
separator,
|
|
692
610
|
) ??
|
|
693
611
|
joinSegments(
|
|
694
|
-
[...leftSegments,
|
|
612
|
+
[...leftSegments, doneAtSegment, ...rightSegments],
|
|
695
613
|
separator,
|
|
696
614
|
);
|
|
697
615
|
// Line 2 — folder on the left, git (branch + diff) in the middle,
|
|
@@ -788,11 +706,6 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
788
706
|
// The previous run's completion clock is stale as soon as a new run
|
|
789
707
|
// starts; the segment reappears at the next agent_settled.
|
|
790
708
|
settledAt = null;
|
|
791
|
-
// Baseline for the cost delta, read from the session rather than reused
|
|
792
|
-
// from the last render: agent_settled requests a render, but that render
|
|
793
|
-
// may not have run yet when the next run starts, which would fold the
|
|
794
|
-
// previous run's cost into this one. Once per run, not once per turn.
|
|
795
|
-
costAtRunStart = readSessionCost();
|
|
796
709
|
stopTimer();
|
|
797
710
|
timer = setInterval(() => {
|
|
798
711
|
if (sessionCwd !== null) fetchGitDiff(sessionCwd);
|
|
@@ -835,8 +748,6 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
835
748
|
lastTps = null;
|
|
836
749
|
deltaChars = 0;
|
|
837
750
|
sessionCwd = null;
|
|
838
|
-
sessionManager = null;
|
|
839
|
-
costAtRunStart = 0;
|
|
840
751
|
folderName = null;
|
|
841
752
|
repoName = null;
|
|
842
753
|
gitAdded = 0;
|