pi-status-footer 1.0.7 β†’ 1.1.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 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 πŸ’° $0.420 +$0.020000 ⚑42 t/s ⏳ 4:32 πŸ’¬ 1:18
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, session cost with the current run's cost (πŸ’°), tokens per second (live while streaming), agent run timer (⏳), current turn timer (πŸ’¬).
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 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
- - **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
- | πŸ’° cost | `πŸ’° $0.420 +$0.020000` | Session sum of `usage.cost.total`, plus the current agent run's cost |
59
- | ⚑tps | `⚑42 t/s` | Live during generation; last completed rate shown between turns |
60
- | ⏳ working | `⏳ 4:32` | Elapsed time since `agent_start`, HH:MM:SS above 1h |
61
- | πŸ’¬ turn | `πŸ’¬ 1:18` | Elapsed time since last `turn_start` |
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 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.
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; 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
- - **`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.7",
3
+ "version": "1.1.1",
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
@@ -129,6 +129,16 @@ export function collectSessionStats(entries: readonly SessionEntry[]): {
129
129
  }
130
130
  if (entry.type === "branch_summary" || entry.type === "compaction") {
131
131
  addUsage(usage, entry.usage);
132
+ continue;
133
+ }
134
+ // Model work outside the conversation β€” today only cache warming
135
+ // (`kind: "cache_warm"`) β€” is recorded *only* as a usage entry: no
136
+ // assistant message, no tool result. Pi counts these in session
137
+ // totals (docs/session-format.md), so skipping them would under-report
138
+ // cost, tokens and the cache-hit rate against `/session`. Unknown
139
+ // kinds are counted like any other usage, per the same doc.
140
+ if (entry.type === "usage") {
141
+ addUsage(usage, entry.usage);
132
142
  }
133
143
  }
134
144