pi-status-footer 1.0.6 β†’ 1.1.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.
Files changed (3) hide show
  1. package/README.md +48 -75
  2. package/package.json +1 -1
  3. package/stats-footer.ts +42 -34
package/README.md CHANGED
@@ -1,107 +1,80 @@
1
1
  # pi-status-footer
2
2
 
3
- A compact, zero-config two-line status footer for [pi](https://github.com/earendil-works/pi-coding-agent) β€” shows everything you want at a glance, fits on any terminal width.
3
+ Compact two-line status footer for the pi TUI: context usage, tokens, cost, live TPS, git diff, and run timers.
4
4
 
5
- ## What it looks like
5
+ See [pi.dev docs](https://pi.dev) for how extensions work.
6
6
 
7
- ![pi-status-footer demo](docs/footer-demo.png)
7
+ ## What's included
8
8
 
9
- ```
10
- πŸ“¦ 38%/128k πŸ’Ύ 63% ↑5.2k ↓8.1k ⚑42 t/s ⏳ 4:32 πŸ’¬ 1:18 πŸ’° $0.420 +$0.020000
11
- πŸ“ my-project β–Έ ξœ₯ main +3 -1 πŸ€– openai/ry-very-long-modelid-4o πŸ’­ medium
12
- ```
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 (πŸ’¬), and session cost (πŸ’°) with the current turn's delta.
15
-
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
-
18
- Everything auto-fits to your terminal width. Line 1 always keeps every segment (it clips only on very narrow terminals). On line 2 the model is mandatory: the model id is shortened from the left, keeping the provider and thinking level intact β€” only if even that can't fit does the folder/git group drop off.
19
-
20
- ## Features
9
+ | Extension | Command / shortcut | What it does |
10
+ |---|---|---|
11
+ | `stats-footer.ts` | (no command; TUI footer widget) | Renders a two-line footer: line 1 stats/timers, line 2 folder, git branch/diff, model, thinking level |
21
12
 
22
- - **Zero config** β€” drop it in and it works
23
- - **Live TPS** β€” shows tokens/second during generation, stays visible between turns
24
- - **Git awareness** β€” asynchronous, debounced `git diff --shortstat HEAD` so typing never blocks; branch changes detected automatically via `footerData.onBranchChange`
25
- - **Cache hit rate** β€” percentage of prompt tokens served from cache
26
- - **Cost, sum + delta** β€” session total with the current turn'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; models with no catalog pricing read `n/a` instead of a misleading `$0.00`
27
- - **Context gauge** β€” percentage and raw max; shifts from green β†’ yellow β†’ red as you approach the limit
28
- - **Thinking level** β€” color-coded to match pi's thinking theme
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
30
- - **Line 1 never drops stats** β€” every stat segment always renders; on very narrow terminals the line clips instead
31
- - **East Asian safe** β€” explicit ambiguous-width handling for CJK-friendly terminals
32
- - **Safe at all times** β€” footer rendering never crashes the TUI, even on edge cases
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.
33
14
 
34
- ## Installation
15
+ ## Install
35
16
 
36
17
  ```bash
37
- # Option 1: git (recommended, no npm account needed)
38
- pi install git:github.com/kslamph/pi-status-footer@v1.0.0
39
-
40
- # Option 2: npm
41
18
  pi install npm:pi-status-footer
42
-
43
- # Option 3: local directory
44
- pi install /path/to/pi-status-footer
19
+ pi install git:github.com/kslamph/pi-status-footer
20
+ pi install ./pi-status-footer
45
21
  ```
46
22
 
47
- After installation, the footer appears automatically on the next pi TUI session. No configuration or activation needed.
23
+ Try without installing (one run only, nothing saved):
48
24
 
49
- ## Display reference
25
+ ```bash
26
+ pi -e npm:pi-status-footer
27
+ pi -e ./stats-footer.ts
28
+ ```
50
29
 
51
- ### Line 1 β€” Stats, cost & timers
30
+ The footer appears automatically in the next TUI session.
52
31
 
53
- | Segment | Example | Source |
54
- |---|---|---|
55
- | πŸ“¦context | `πŸ“¦ 38%/128k` | `ctx.getContextUsage()`, color-coded by percent |
56
- | πŸ’Ύcache | `πŸ’Ύ 63%` | `cacheRead / (input + cacheRead + cacheWrite)` |
57
- | ↑input ↓output | `↑5.2k ↓8.1k` | Session `usage.input / usage.output` (accumulated across all entries) |
58
- | ⚑tps | `⚑42 t/s` | Live during generation; last completed rate shown between turns |
59
- | ⏳ working | `⏳ 4:32` | Elapsed time since `agent_start`, HH:MM:SS above 1h |
60
- | πŸ’¬ 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 |
32
+ ## Usage
62
33
 
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 read at `turn_start` subtracted from the current total, so it never folds the previous turn into the current one. 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`, and a session with no usage at all renders no cost segment. Because the cost segment is last on line 1, it is also the first thing a narrow terminal clips.
34
+ Just run `pi` in the TUI. Example footer:
64
35
 
65
- ### Line 2 β€” Project & model
36
+ ```
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
+ ```
66
40
 
67
- | Segment | Example | Source |
68
- |---|---|---|
69
- | πŸ“ repo | `πŸ“ my-project` | Git repo root basename (from `ctx.cwd` walk-up) |
70
- | β–Έ ξœ₯ branch | `β–Έ ξœ₯ main` | `footerData.getGitBranch()`, auto-updates |
71
- | +N -M diff | `+3 -1` | Async `git diff --shortstat HEAD` (1s debounced) |
72
- | πŸ€– model | `πŸ€– openai/gpt-4o` | `ctx.model.provider / ctx.model.id`, id shortened from the left when narrow |
73
- | πŸ’­ thinking | `πŸ’­ high` | `ctx.thinkingLevel`, themed via `theme.fg()` |
41
+ 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.
74
42
 
75
- ## How it works
43
+ ## Configuration
76
44
 
77
- The extension hooks into six pi lifecycle events:
45
+ Zero config. No env vars, no settings keys.
78
46
 
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, and snapshots the session cost at `turn_start` as the baseline for the turn's cost delta
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
- - **`model_select`** β€” clears stale TPS on model switch
84
- - **`session_shutdown`** β€” cleans up all state
47
+ ## Security note
85
48
 
86
- Git diff is fetched asynchronously via `execFile` with a 1-second debounce and `--no-optional-locks` to avoid contention. The render function caches the last result, so the footer stays responsive regardless of repo size.
49
+ Runs in-process with your OS permissions. It reads session entries (token usage, cost, 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.
87
50
 
88
- ## Requirements
51
+ ## Update / remove / enable-disable
89
52
 
90
- - pi coding agent (any recent version with `ctx.ui.setFooter` and `footerData` support)
91
- - git available on `PATH` for git diff and branch features (optional β€” footer degrades gracefully without it)
53
+ ```bash
54
+ pi update --extensions # update all packages
55
+ pi update npm:pi-status-footer
56
+ pi remove pi-status-footer
57
+ pi list
58
+ pi config # enable/disable resources
59
+ ```
92
60
 
93
- ## Development
61
+ ## Compatibility
94
62
 
95
- The extension is a single TypeScript file (`stats-footer.ts`) that pi loads via [jiti](https://github.com/unjs/jiti). There is no build step.
63
+ - Peer deps: `@earendil-works/pi-ai`, `@earendil-works/pi-coding-agent`, `@earendil-works/pi-tui` (any version with `ctx.ui.setFooter`)
64
+ - TODO: confirm exact tested Pi version and OS coverage (developed on Linux)
96
65
 
97
- TypeScript types are provided by the pi runtime packages:
66
+ ## Development
98
67
 
99
68
  ```bash
100
- # Install peer dependencies for type checking (optional)
101
- npm install --save-dev @earendil-works/pi-ai @earendil-works/pi-coding-agent @earendil-works/pi-tui
102
- npx tsc --noEmit stats-footer.ts
69
+ git clone https://github.com/kslamph/pi-status-footer.git
70
+ cd pi-status-footer
71
+ pi install ./ # local copy loads in place
72
+ pi -e ./stats-footer.ts # single run from inside the repo
73
+ npm test # runs test-layout, test-live-tps, test-cost
103
74
  ```
104
75
 
105
- ## License
76
+ No build step; pi loads the TypeScript file directly. Optional typecheck: install the peer deps as devDependencies, then `npx tsc --noEmit stats-footer.ts`.
77
+
78
+ ## License + credits
106
79
 
107
- MIT β€” see [LICENSE](./LICENSE).
80
+ MIT β€” see [LICENSE](./LICENSE). Footer demo image: `docs/footer-demo.png`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-status-footer",
3
- "version": "1.0.6",
3
+ "version": "1.1.0",
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-turn delta. */
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 it is simply `-`.
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) turn as a `+$x.xxxxxx` suffix, at 6
78
- * decimals β€” a single wokey turn costs cents, so 3 would quantise the delta
79
- * to zero. Empty while the turn has not spent anything, so the caller can
80
- * append it blindly.
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 turn_start can read the cumulative cost
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 turn's final message when a new turn begins).
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 turn; the turn's
389
- // delta is the current cumulative minus this baseline.
390
- let costAtTurnStart = 0;
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 turn delta at whatever the (possibly resumed) session
446
- // already spent, so a delta only ever appears once a turn runs.
447
- costAtTurnStart = readSessionCost();
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 turn's delta. Cost is derived
518
- // from tokens, and it is the slowest-changing value on the line
519
- // (it only ticks up at message boundaries), so it goes last: on a
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 turnCost = Math.max(0, usage.cost - costAtTurnStart);
525
- const costDelta = formatCostDelta(turnCost);
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 === 0
528
- ? ""
529
- : `πŸ’° ${theme.fg("accent", formatCost(usage.cost))}${
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
- costAtTurnStart = 0;
657
+ costAtRunStart = 0;
650
658
  folderName = null;
651
659
  repoName = null;
652
660
  gitAdded = 0;