pi-status-footer 1.2.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.
Files changed (3) hide show
  1. package/README.md +13 -5
  2. package/package.json +3 -3
  3. package/stats-footer.ts +218 -61
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 stats/timers, line 2 folder, git branch/diff, model, thinking level, and a conditional line 3 carrying statuses other extensions set via `ctx.ui.setStatus()` |
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,12 +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 ⚡42 t/s ⏳ 4:32 💬 1:18
38
- 📁 my-project ▸  main +3 -1 🤖 openai/gpt-4o 💭 medium
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
- Line 1: context used/limit, cache hit rate, input/output tokens, session cost + current-run delta, tokens/sec (live while streaming, last rate when idle), agent-run timer, current-turn timer. Line 2: folder (repo root, or cwd outside a repo), branch, working-tree diff vs HEAD, provider/model, thinking level. Narrow terminals shorten the model id from the left first; the folder/git group drops only if the model still can't fit.
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
+
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.
43
51
 
44
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.
45
53
 
@@ -73,7 +81,7 @@ git clone https://github.com/kslamph/pi-status-footer.git
73
81
  cd pi-status-footer
74
82
  pi install ./ # local copy loads in place
75
83
  pi -e ./stats-footer.ts # single run from inside the repo
76
- npm test # runs test-layout, test-live-tps, test-cost
84
+ npm test # runs test-live-tps, test-layout, test-cost, test-done-at
77
85
  ```
78
86
 
79
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.2.0",
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
@@ -19,6 +19,31 @@ type UsageTotals = Pick<
19
19
 
20
20
  type RenderTui = { requestRender(force?: boolean): void };
21
21
 
22
+ /**
23
+ * Footer icon set: Nerd Font Private-Use-Area glyphs, deliberately not emoji.
24
+ *
25
+ * Emoji are colour bitmaps, and how a host draws them is not something the
26
+ * footer can control: xterm.js/Chromium (Orca, VS Code) and iTerm2 render
27
+ * full colour, while Alacritty and kitty rasterise the same code points as
28
+ * flat monochrome silhouettes. The footer therefore looked different from
29
+ * terminal to terminal. These glyphs sit in the patched Nerd Font ranges, so
30
+ * they render as one flat, single-cell line-art icon wherever a Nerd Font is
31
+ * installed.
32
+ */
33
+ export const ICONS = {
34
+ context: "\u{F1B2}", // fa-cube
35
+ cache: "\u{F1C0}", // fa-database
36
+ cost: "\u{F155}", // fa-usd
37
+ tps: "\u{F0E7}", // fa-flash (bolt)
38
+ runTimer: "\u{F252}", // fa-hourglass-half
39
+ turnTimer: "\u{F0E5}", // fa-comment-o
40
+ folder: "\u{F114}", // fa-folder-o
41
+ model: "\u{F2DB}", // fa-microchip
42
+ thinking: "\u{F09D1}", // md-brain
43
+ clock: "\u{F017}", // fa-clock-o (run completion time)
44
+ branch: "\u{E725}", // nf-cod-git_branch
45
+ } as const;
46
+
22
47
  const THINKING_THEME_COLOR = {
23
48
  off: "thinkingOff",
24
49
  minimal: "thinkingMinimal",
@@ -48,6 +73,18 @@ export function formatDuration(ms: number): string {
48
73
  return `${minutes}:${pad(seconds)}`;
49
74
  }
50
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
+
51
88
  /** Decimals for the session sum and for the per-run delta. */
52
89
  const COST_DECIMALS = 3;
53
90
  const COST_DELTA_DECIMALS = 6;
@@ -249,6 +286,63 @@ function joinSegments(segments: string[], separator: string): string {
249
286
  return segments.filter(Boolean).join(separator);
250
287
  }
251
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
+
252
346
  /** Below this terminal width the footer gives up fitting and lets the line
253
347
  * overflow (the TUI clips it); shortening arithmetic degenerates here. */
254
348
  const MIN_FIT_WIDTH = 50;
@@ -278,13 +372,13 @@ export function shortenModelId(
278
372
  export interface SecondLineParts {
279
373
  /** Folder/branch/diff group; "" when there is no folder to show. */
280
374
  gitGroup: string;
281
- /** Prefix before the provider, e.g. "🤖 ". */
375
+ /** Prefix before the provider, e.g. the model icon plus a space. */
282
376
  modelPrefix: string;
283
377
  /** Provider name; may be "" when no model is selected. */
284
378
  provider: string;
285
379
  /** Model id, shortened from the left when space is tight. */
286
380
  modelId: string;
287
- /** Everything after the model id, e.g. " 💭 medium". */
381
+ /** Everything after the model id, e.g. the thinking icon + level. */
288
382
  modelSuffix: string;
289
383
  /** Between-segment separator. */
290
384
  separator: string;
@@ -365,6 +459,10 @@ export default function statsFooter(pi: ExtensionAPI) {
365
459
  let timer: ReturnType<typeof setInterval> | null = null;
366
460
  let runStart: number | null = null;
367
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;
368
466
  // Turn timer: elapsed time since the current turn began (frozen at turn_end).
369
467
  let turnStart: number | null = null;
370
468
  let lastTurnDuration = 0;
@@ -454,6 +552,7 @@ export default function statsFooter(pi: ExtensionAPI) {
454
552
  stopTimer();
455
553
  runStart = null;
456
554
  lastRunDuration = 0;
555
+ settledAt = null;
457
556
  turnStart = null;
458
557
  lastTurnDuration = 0;
459
558
  genStart = null;
@@ -521,10 +620,10 @@ export default function statsFooter(pi: ExtensionAPI) {
521
620
  ] ?? "thinkingMedium";
522
621
  let thinkingText: string;
523
622
  try {
524
- thinkingText = `💭 ${theme.fg(thinkingColor, thinkingLevel)}`;
623
+ thinkingText = `${ICONS.thinking} ${theme.fg(thinkingColor, thinkingLevel)}`;
525
624
  } catch {
526
625
  // thinkingMax is optional in themes; fall back to a vivid level.
527
- thinkingText = `💭 ${theme.fg("thinkingHigh", thinkingLevel)}`;
626
+ thinkingText = `${ICONS.thinking} ${theme.fg("thinkingHigh", thinkingLevel)}`;
528
627
  }
529
628
  // TPS: live rate while the current assistant message streams,
530
629
  // falling back to the last completed message's rate so the value
@@ -535,8 +634,10 @@ export default function statsFooter(pi: ExtensionAPI) {
535
634
  : null;
536
635
  const tpsValue = liveTps ?? lastTps;
537
636
  // Cost: session sum plus the current agent run's delta. It sits
538
- // next to the token counters it is derived from, ahead of the
539
- // live rate and the timers.
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.
540
641
  const spentTokens =
541
642
  usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
542
643
  const runCost = Math.max(0, usage.cost - costAtRunStart);
@@ -544,64 +645,113 @@ export default function statsFooter(pi: ExtensionAPI) {
544
645
  // Always rendered, so a fresh session shows a $0.000 placeholder
545
646
  // rather than the segment appearing out of nowhere later.
546
647
  const costSegment =
547
- `💰 ${theme.fg("accent", formatCost(usage.cost, spentTokens > 0))}${
648
+ `${ICONS.cost} ${theme.fg("accent", formatCost(usage.cost, spentTokens > 0))}${
548
649
  costDelta === "" ? "" : theme.fg("dim", ` ${costDelta}`)
549
650
  }`;
550
- // Line 1 — stats only (context, cache, tokens, TPS, timers, cost). Every
551
- // segment always renders; on very narrow terminals the line overflows
552
- // and the TUI clips it rather than dropping stats.
553
- const statsLine = joinSegments(
554
- [
555
- `📦 ${theme.fg(contextColor, contextText)}`,
556
- theme.fg(
557
- "dim",
558
- `💾 ${cacheRate === null ? "-" : `${cacheRate.toFixed(0)}%`}`,
559
- ),
560
- theme.fg(
561
- "dim",
562
- `↑${formatTokens(usage.input)} ↓${formatTokens(usage.output)}`,
563
- ),
564
- costSegment,
565
- theme.fg("dim", `⚡${Math.round(tpsValue ?? 0)} t/s`),
566
- `⏳ ${theme.fg("accent", formatDuration(elapsed))}`,
567
- `💬 ${theme.fg("accent", formatDuration(turnElapsed))}`,
568
- ],
569
- separator,
570
- );
571
- // Line 2 — folder/git status + model/thinking. The folder name
572
- // always shows (repo root basename, or plain cwd basename when
573
- // not inside a git repo); branch + diff only when git is present.
574
- // The model id is shortened from the left before git is dropped.
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.
575
702
  const branch = footerData.getGitBranch();
576
- const gitSegments: string[] = [];
577
- if (folderName !== null) {
578
- const folderLabel = repoName ?? folderName;
579
- const folderText = `📁 ${theme.fg("accent", folderLabel)}`;
580
- if (repoName !== null) {
581
- const branchText = branch
582
- ? ` ▸ ${branch}`
583
- : "";
584
- gitSegments.push(
585
- folderText + branchText +
586
- ` ${theme.fg("toolDiffAdded", `+${gitAdded}`)} ${theme.fg("toolDiffRemoved", `-${gitDeleted}`)}`,
587
- );
588
- } else {
589
- gitSegments.push(folderText);
590
- }
591
- }
592
- const gitGroup = joinSegments(gitSegments, separator);
593
- const gitLine = fitSecondLine(
594
- {
595
- gitGroup,
596
- modelPrefix: "🤖 ",
597
- provider: ctx.model?.provider ?? "",
598
- modelId: ctx.model?.id ?? "no-model",
599
- modelSuffix: ` ${thinkingText}`,
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,
600
732
  separator,
601
- styleModelId: (text) => theme.fg("accent", text),
602
- },
603
- width,
604
- );
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
+ );
605
755
 
606
756
  // Extension statuses set via ctx.ui.setStatus() are rendered by
607
757
  // the built-in footer, which this custom footer replaces. Surface
@@ -635,6 +785,9 @@ export default function statsFooter(pi: ExtensionAPI) {
635
785
  pi.on("agent_start", () => {
636
786
  if (runStart === null) runStart = Date.now();
637
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;
638
791
  // Baseline for the cost delta, read from the session rather than reused
639
792
  // from the last render: agent_settled requests a render, but that render
640
793
  // may not have run yet when the next run starts, which would fold the
@@ -647,9 +800,12 @@ export default function statsFooter(pi: ExtensionAPI) {
647
800
  }, 1_000);
648
801
  rerender();
649
802
  });
650
- pi.on("agent_settled", () => {
803
+ pi.on("agent_settled", (event?: { aborted?: boolean }) => {
651
804
  if (runStart !== null) lastRunDuration = Date.now() - runStart;
652
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();
653
809
  genStart = null;
654
810
  liveOutput = 0;
655
811
  stopTimer();
@@ -671,6 +827,7 @@ export default function statsFooter(pi: ExtensionAPI) {
671
827
  stopTimer();
672
828
  tuiRef = null;
673
829
  runStart = null;
830
+ settledAt = null;
674
831
  turnStart = null;
675
832
  lastTurnDuration = 0;
676
833
  genStart = null;