pi-status-footer 1.3.0 → 1.4.1
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 +11 -5
- package/package.json +3 -3
- package/stats-footer.ts +190 -56
package/README.md
CHANGED
|
@@ -8,10 +8,12 @@ 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
|
|
11
|
+
| `stats-footer.ts` | (no command; TUI footer widget) | Renders a footer: line 1 usage/spend/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
|
|
|
15
|
+
Both data lines spread their groups across the terminal width — left, middle, right — instead of hugging the left edge, so a wide terminal uses its space. Narrow terminals fall back to a compact left-aligned line.
|
|
16
|
+
|
|
15
17
|
## Install
|
|
16
18
|
|
|
17
19
|
```bash
|
|
@@ -34,14 +36,18 @@ The footer appears automatically in the next TUI session.
|
|
|
34
36
|
Just run `pi` in the TUI. Example footer:
|
|
35
37
|
|
|
36
38
|
```
|
|
37
|
-
38%/128k 63% ↑5.2k ↓8.1k $0.420 +$0.020000
|
|
38
|
-
my-project
|
|
39
|
+
38%/128k 63% ↑5.2k ↓8.1k 42 t/s 08:23:30 $0.420 +$0.020000 4:32 1:18
|
|
40
|
+
my-project ▸ main +3 -1 openai/gpt-4o medium
|
|
39
41
|
bg 1 running · Shift↓
|
|
40
42
|
```
|
|
41
43
|
|
|
42
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.
|
|
43
45
|
|
|
44
|
-
Line 1: context used/limit, cache hit rate, input/output tokens, session cost + current-run delta,
|
|
46
|
+
Line 1 is three groups: usage on the left (context used/limit, cache hit rate, input/output tokens, tokens/sec, and the completion clock), spend in the middle (session cost + current-run delta), 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
|
+
|
|
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
|
+
|
|
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.
|
|
45
51
|
|
|
46
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.
|
|
47
53
|
|
|
@@ -75,7 +81,7 @@ git clone https://github.com/kslamph/pi-status-footer.git
|
|
|
75
81
|
cd pi-status-footer
|
|
76
82
|
pi install ./ # local copy loads in place
|
|
77
83
|
pi -e ./stats-footer.ts # single run from inside the repo
|
|
78
|
-
npm test # runs test-layout, test-
|
|
84
|
+
npm test # runs test-live-tps, test-layout, test-cost, test-done-at
|
|
79
85
|
```
|
|
80
86
|
|
|
81
87
|
No build step; pi loads the TypeScript file directly. Optional typecheck: install the peer deps as devDependencies, then `npx tsc --noEmit stats-footer.ts`.
|
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, cost, TPS, cache hit rate, context usage, live git diff, working/turn timers, plus a conditional third line for other extensions' status segments.",
|
|
3
|
+
"version": "1.4.1",
|
|
4
|
+
"description": "Compact status footer for pi: model, thinking level, tokens, cost, 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",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"streaming"
|
|
36
36
|
],
|
|
37
37
|
"scripts": {
|
|
38
|
-
"test": "node --experimental-strip-types test-live-tps.ts && node --experimental-strip-types test-layout.ts && node --experimental-strip-types test-cost.ts"
|
|
38
|
+
"test": "node --experimental-strip-types test-live-tps.ts && node --experimental-strip-types test-layout.ts && node --experimental-strip-types test-cost.ts && node --experimental-strip-types test-done-at.ts"
|
|
39
39
|
},
|
|
40
40
|
"license": "MIT",
|
|
41
41
|
"repository": {
|
package/stats-footer.ts
CHANGED
|
@@ -40,6 +40,8 @@ export const ICONS = {
|
|
|
40
40
|
folder: "\u{F114}", // fa-folder-o
|
|
41
41
|
model: "\u{F2DB}", // fa-microchip
|
|
42
42
|
thinking: "\u{F09D1}", // md-brain
|
|
43
|
+
clock: "\u{F017}", // fa-clock-o (run completion time)
|
|
44
|
+
branch: "\u{E725}", // nf-cod-git_branch
|
|
43
45
|
} as const;
|
|
44
46
|
|
|
45
47
|
const THINKING_THEME_COLOR = {
|
|
@@ -71,6 +73,18 @@ export function formatDuration(ms: number): string {
|
|
|
71
73
|
return `${minutes}:${pad(seconds)}`;
|
|
72
74
|
}
|
|
73
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Local wall-clock completion time, 24-hour with seconds (`08:23:30`), the
|
|
78
|
+
* same shape pi-done-at notifies with. The date is omitted on purpose: the
|
|
79
|
+
* footer always describes the current session, where a bare clock time is
|
|
80
|
+
* unambiguous and costs 8 columns instead of 14.
|
|
81
|
+
*/
|
|
82
|
+
export function formatDoneAt(when: Date | number = Date.now()): string {
|
|
83
|
+
const date = typeof when === "number" ? new Date(when) : when;
|
|
84
|
+
const pad = (n: number): string => String(n).padStart(2, "0");
|
|
85
|
+
return `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
74
88
|
/** Decimals for the session sum and for the per-run delta. */
|
|
75
89
|
const COST_DECIMALS = 3;
|
|
76
90
|
const COST_DELTA_DECIMALS = 6;
|
|
@@ -272,6 +286,63 @@ function joinSegments(segments: string[], separator: string): string {
|
|
|
272
286
|
return segments.filter(Boolean).join(separator);
|
|
273
287
|
}
|
|
274
288
|
|
|
289
|
+
export interface LineGroup {
|
|
290
|
+
/** Rendered text; "" groups are dropped before layout. */
|
|
291
|
+
text: string;
|
|
292
|
+
align: "left" | "center" | "right";
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Lay groups out across the full terminal width: left groups start at column
|
|
297
|
+
* 0, a centered group sits on the middle of the line, right groups end at the
|
|
298
|
+
* right edge. Without this a wide footer collapses into one left-hugging run
|
|
299
|
+
* of text and the right half of the terminal reads as empty space.
|
|
300
|
+
*
|
|
301
|
+
* Groups keep at least one separator of clearance, so a centered group that
|
|
302
|
+
* would collide is pushed instead of overlapping. Returns null when the
|
|
303
|
+
* groups plus their separators cannot fit at this width — callers then fall
|
|
304
|
+
* back to a compact left-aligned flow (or to their own fitting rules).
|
|
305
|
+
*/
|
|
306
|
+
export function distributeGroups(
|
|
307
|
+
groups: readonly LineGroup[],
|
|
308
|
+
width: number,
|
|
309
|
+
separator: string,
|
|
310
|
+
): string | null {
|
|
311
|
+
const budget = width - SAFETY_MARGIN;
|
|
312
|
+
const gap = Math.max(1, measureWidth(separator));
|
|
313
|
+
const items = groups
|
|
314
|
+
.filter((group) => group.text !== "")
|
|
315
|
+
.map((group) => ({ ...group, w: measureWidth(group.text) }));
|
|
316
|
+
if (items.length === 0) return "";
|
|
317
|
+
const minWidth =
|
|
318
|
+
items.reduce((sum, item) => sum + item.w, 0) + gap * (items.length - 1);
|
|
319
|
+
if (budget < minWidth) return null;
|
|
320
|
+
|
|
321
|
+
let line = "";
|
|
322
|
+
let cursor = 0;
|
|
323
|
+
for (let index = 0; index < items.length; index++) {
|
|
324
|
+
const item = items[index]!;
|
|
325
|
+
// Room the later groups need, so a centered group can never shove a
|
|
326
|
+
// right-aligned one past the edge.
|
|
327
|
+
let suffix = 0;
|
|
328
|
+
for (let rest = index + 1; rest < items.length; rest++) {
|
|
329
|
+
suffix += items[rest]!.w + gap;
|
|
330
|
+
}
|
|
331
|
+
const earliest = cursor + (index > 0 ? gap : 0);
|
|
332
|
+
const latest = budget - item.w - suffix;
|
|
333
|
+
let start =
|
|
334
|
+
item.align === "left"
|
|
335
|
+
? earliest
|
|
336
|
+
: item.align === "right"
|
|
337
|
+
? latest
|
|
338
|
+
: Math.round((budget - item.w) / 2);
|
|
339
|
+
start = Math.max(earliest, Math.min(start, latest));
|
|
340
|
+
line += " ".repeat(start - cursor) + item.text;
|
|
341
|
+
cursor = start + item.w;
|
|
342
|
+
}
|
|
343
|
+
return line;
|
|
344
|
+
}
|
|
345
|
+
|
|
275
346
|
/** Below this terminal width the footer gives up fitting and lets the line
|
|
276
347
|
* overflow (the TUI clips it); shortening arithmetic degenerates here. */
|
|
277
348
|
const MIN_FIT_WIDTH = 50;
|
|
@@ -388,6 +459,10 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
388
459
|
let timer: ReturnType<typeof setInterval> | null = null;
|
|
389
460
|
let runStart: number | null = null;
|
|
390
461
|
let lastRunDuration = 0;
|
|
462
|
+
// Wall-clock time of the last settled run — the "done at" segment. Null
|
|
463
|
+
// while a run is in flight, and after an aborted run, which never gets a
|
|
464
|
+
// completion time.
|
|
465
|
+
let settledAt: number | null = null;
|
|
391
466
|
// Turn timer: elapsed time since the current turn began (frozen at turn_end).
|
|
392
467
|
let turnStart: number | null = null;
|
|
393
468
|
let lastTurnDuration = 0;
|
|
@@ -477,6 +552,7 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
477
552
|
stopTimer();
|
|
478
553
|
runStart = null;
|
|
479
554
|
lastRunDuration = 0;
|
|
555
|
+
settledAt = null;
|
|
480
556
|
turnStart = null;
|
|
481
557
|
lastTurnDuration = 0;
|
|
482
558
|
genStart = null;
|
|
@@ -558,8 +634,10 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
558
634
|
: null;
|
|
559
635
|
const tpsValue = liveTps ?? lastTps;
|
|
560
636
|
// Cost: session sum plus the current agent run's delta. It sits
|
|
561
|
-
//
|
|
562
|
-
//
|
|
637
|
+
// in the middle of line 1, between the usage counters on the
|
|
638
|
+
// left and the timers on the right, so a wide terminal spreads
|
|
639
|
+
// the run's three kinds of information instead of stacking all
|
|
640
|
+
// of it against the left edge.
|
|
563
641
|
const spentTokens =
|
|
564
642
|
usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
565
643
|
const runCost = Math.max(0, usage.cost - costAtRunStart);
|
|
@@ -570,61 +648,110 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
570
648
|
`${ICONS.cost} ${theme.fg("accent", formatCost(usage.cost, spentTokens > 0))}${
|
|
571
649
|
costDelta === "" ? "" : theme.fg("dim", ` ${costDelta}`)
|
|
572
650
|
}`;
|
|
573
|
-
|
|
574
|
-
//
|
|
575
|
-
//
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
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.
|
|
657
|
+
const leftSegments = [
|
|
658
|
+
`${ICONS.context} ${theme.fg(contextColor, contextText)}`,
|
|
659
|
+
theme.fg(
|
|
660
|
+
"dim",
|
|
661
|
+
`${ICONS.cache} ${cacheRate === null ? "-" : `${cacheRate.toFixed(0)}%`}`,
|
|
662
|
+
),
|
|
663
|
+
theme.fg(
|
|
664
|
+
"dim",
|
|
665
|
+
`↑${formatTokens(usage.input)} ↓${formatTokens(usage.output)}`,
|
|
666
|
+
),
|
|
667
|
+
// The rate belongs beside the output tokens it is derived
|
|
668
|
+
// from, not next to the spend figure.
|
|
669
|
+
theme.fg("dim", `${ICONS.tps} ${Math.round(tpsValue ?? 0)} t/s`),
|
|
670
|
+
// Wall-clock time of the last settled run, right after the rate:
|
|
671
|
+
// shown from agent_settled until the next run starts, and never
|
|
672
|
+
// for an aborted run — the same rule pi-done-at's notification
|
|
673
|
+
// uses. It keeps its slot as the last usage-side fact instead of
|
|
674
|
+
// floating off at the right edge.
|
|
675
|
+
settledAt === null
|
|
676
|
+
? ""
|
|
677
|
+
: `${ICONS.clock} ${theme.fg("dim", formatDoneAt(settledAt))}`,
|
|
678
|
+
];
|
|
679
|
+
const rightSegments = [
|
|
680
|
+
`${ICONS.runTimer} ${theme.fg("accent", formatDuration(elapsed))}`,
|
|
681
|
+
`${ICONS.turnTimer} ${theme.fg("accent", formatDuration(turnElapsed))}`,
|
|
682
|
+
];
|
|
683
|
+
const statsLine =
|
|
684
|
+
distributeGroups(
|
|
685
|
+
[
|
|
686
|
+
{ text: joinSegments(leftSegments, separator), align: "left" },
|
|
687
|
+
{ text: costSegment, align: "center" },
|
|
688
|
+
{ text: joinSegments(rightSegments, separator), align: "right" },
|
|
689
|
+
],
|
|
690
|
+
width,
|
|
691
|
+
separator,
|
|
692
|
+
) ??
|
|
693
|
+
joinSegments(
|
|
694
|
+
[...leftSegments, costSegment, ...rightSegments],
|
|
695
|
+
separator,
|
|
696
|
+
);
|
|
697
|
+
// Line 2 — folder on the left, git (branch + diff) in the middle,
|
|
698
|
+
// model/thinking on the right. The folder always shows (repo root
|
|
699
|
+
// basename, or plain cwd basename outside a repo). When the spread
|
|
700
|
+
// layout does not fit, fitSecondLine shortens the model id from
|
|
701
|
+
// the left and, as a last resort, drops the whole git group.
|
|
598
702
|
const branch = footerData.getGitBranch();
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
703
|
+
const isRepo = repoName !== null;
|
|
704
|
+
const folderText =
|
|
705
|
+
folderName === null
|
|
706
|
+
? ""
|
|
707
|
+
: `${ICONS.folder} ${theme.fg("accent", repoName ?? folderName)}`;
|
|
708
|
+
const branchText =
|
|
709
|
+
isRepo && branch ? `▸ ${ICONS.branch} ${branch}` : "";
|
|
710
|
+
const diffText = `${theme.fg("toolDiffAdded", `+${gitAdded}`)} ${theme.fg("toolDiffRemoved", `-${gitDeleted}`)}`;
|
|
711
|
+
const provider = ctx.model?.provider ?? "";
|
|
712
|
+
const modelId = ctx.model?.id ?? "no-model";
|
|
713
|
+
const modelPrefix = `${ICONS.model} `;
|
|
714
|
+
const modelSuffix = ` ${thinkingText}`;
|
|
715
|
+
const styleModelId = (text: string) => theme.fg("accent", text);
|
|
716
|
+
const modelText = `${modelPrefix}${styleModelId(
|
|
717
|
+
`${provider ? `${provider}/` : ""}${modelId}`,
|
|
718
|
+
)}${modelSuffix}`;
|
|
719
|
+
const gitLine =
|
|
720
|
+
distributeGroups(
|
|
721
|
+
[
|
|
722
|
+
{ text: folderText, align: "left" },
|
|
723
|
+
{
|
|
724
|
+
text: isRepo
|
|
725
|
+
? joinSegments([branchText, diffText], separator)
|
|
726
|
+
: "",
|
|
727
|
+
align: "center",
|
|
728
|
+
},
|
|
729
|
+
{ text: modelText, align: "right" },
|
|
730
|
+
],
|
|
731
|
+
width,
|
|
623
732
|
separator,
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
733
|
+
) ??
|
|
734
|
+
fitSecondLine(
|
|
735
|
+
{
|
|
736
|
+
// Compact fallback keeps the old look: folder, branch and
|
|
737
|
+
// diff joined by single spaces so a narrow line stays tight.
|
|
738
|
+
gitGroup: joinSegments(
|
|
739
|
+
[
|
|
740
|
+
folderText,
|
|
741
|
+
branchText === "" ? "" : ` ${branchText}`,
|
|
742
|
+
isRepo ? ` ${diffText}` : "",
|
|
743
|
+
],
|
|
744
|
+
"",
|
|
745
|
+
),
|
|
746
|
+
modelPrefix,
|
|
747
|
+
provider,
|
|
748
|
+
modelId,
|
|
749
|
+
modelSuffix,
|
|
750
|
+
separator,
|
|
751
|
+
styleModelId,
|
|
752
|
+
},
|
|
753
|
+
width,
|
|
754
|
+
);
|
|
628
755
|
|
|
629
756
|
// Extension statuses set via ctx.ui.setStatus() are rendered by
|
|
630
757
|
// the built-in footer, which this custom footer replaces. Surface
|
|
@@ -658,6 +785,9 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
658
785
|
pi.on("agent_start", () => {
|
|
659
786
|
if (runStart === null) runStart = Date.now();
|
|
660
787
|
lastRunDuration = 0;
|
|
788
|
+
// The previous run's completion clock is stale as soon as a new run
|
|
789
|
+
// starts; the segment reappears at the next agent_settled.
|
|
790
|
+
settledAt = null;
|
|
661
791
|
// Baseline for the cost delta, read from the session rather than reused
|
|
662
792
|
// from the last render: agent_settled requests a render, but that render
|
|
663
793
|
// may not have run yet when the next run starts, which would fold the
|
|
@@ -670,9 +800,12 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
670
800
|
}, 1_000);
|
|
671
801
|
rerender();
|
|
672
802
|
});
|
|
673
|
-
pi.on("agent_settled", () => {
|
|
803
|
+
pi.on("agent_settled", (event?: { aborted?: boolean }) => {
|
|
674
804
|
if (runStart !== null) lastRunDuration = Date.now() - runStart;
|
|
675
805
|
runStart = null;
|
|
806
|
+
// A cancelled run has no completion time; mirror pi-done-at, which also
|
|
807
|
+
// stays silent for aborted runs. Older hosts may omit the flag.
|
|
808
|
+
settledAt = event?.aborted ? null : Date.now();
|
|
676
809
|
genStart = null;
|
|
677
810
|
liveOutput = 0;
|
|
678
811
|
stopTimer();
|
|
@@ -694,6 +827,7 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
694
827
|
stopTimer();
|
|
695
828
|
tuiRef = null;
|
|
696
829
|
runStart = null;
|
|
830
|
+
settledAt = null;
|
|
697
831
|
turnStart = null;
|
|
698
832
|
lastTurnDuration = 0;
|
|
699
833
|
genStart = null;
|