@erichll/pi-statusline 0.4.1 → 0.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/CHANGELOG.md +26 -0
- package/README.md +128 -295
- package/examples/statusline.json +4 -0
- package/package.json +1 -1
- package/src/config.ts +8 -2
- package/src/index.ts +8 -1
- package/src/panel.ts +1 -1
- package/src/quota.ts +155 -0
- package/src/render.ts +22 -3
- package/src/session.ts +16 -5
- package/src/types.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0 - 2026-10-14
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Add Codex subscription Usage (`quota`) with primary/secondary progress bars,
|
|
8
|
+
used percentages and live reset countdowns. Passively observe SSE response
|
|
9
|
+
headers and native WebSocket `codex.rate_limits` events on Pi 1.2+, with no
|
|
10
|
+
extra requests or credential lookups. Existing statusline features retain
|
|
11
|
+
Pi 1.1 support.
|
|
12
|
+
- Enable quota after context by default, including in existing configurations
|
|
13
|
+
that omit it. Explicit quota settings preserve enablement and order;
|
|
14
|
+
the panel supports disabling, reordering and styling it.
|
|
15
|
+
- Use accent/warning/error colors at the 70%/90% usage thresholds, with ASCII
|
|
16
|
+
support and narrow-screen fallback to bars, percentages or hiding the segment.
|
|
17
|
+
- Hide missing, malformed and expired quota windows; replace snapshots rather
|
|
18
|
+
than merge credentials' data. Clear old samples on model/provider/API/endpoint
|
|
19
|
+
changes, reload, new session, footer disable and no-quota WebSocket streams.
|
|
20
|
+
- Add quota parser, lifecycle, countdown and rendering tests, plus offline
|
|
21
|
+
regular/fullscreen PTY coverage for both headers and WebSocket events.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- Simplify context bars from `[██░░░░░░░░]20%` to `██░░░░░░░░ 20%`.
|
|
26
|
+
- Condense the README around installation, configuration, quota setup and
|
|
27
|
+
statistics; link to the complete example configuration instead of duplicating it.
|
|
28
|
+
|
|
3
29
|
## 0.4.1 - 2026-10-13
|
|
4
30
|
|
|
5
31
|
- Upgrade the Pi 1.2.0 development baseline (`pi-ai`, `pi-coding-agent`,
|
package/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# @erichll/pi-statusline
|
|
2
2
|
|
|
3
|
-
A configurable
|
|
3
|
+
A configurable native Pi footer with Git status, session usage, runtime/tool
|
|
4
|
+
activity and live configuration preview. Leaves the editor intact.
|
|
4
5
|
|
|
5
6
|
```text
|
|
6
|
-
Example model(high)
|
|
7
|
+
Example model(high) █░░░░░░░░░ 11.9% pi-packages main ● *2 ↑2 49.4k
|
|
7
8
|
Elapsed 5m 42s · Avg 45 tok/s · Cache 86% · Turns 3 · Compactions 1
|
|
8
9
|
```
|
|
9
10
|
|
|
@@ -13,31 +14,11 @@ Elapsed 5m 42s · Avg 45 tok/s · Cache 86% · Turns 3 · Compactions 1
|
|
|
13
14
|
pi install npm:@erichll/pi-statusline
|
|
14
15
|
```
|
|
15
16
|
|
|
16
|
-
Requires Node.js >=22.19
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
other
|
|
20
|
-
|
|
21
|
-
extension in `pi config` before enabling this one.
|
|
22
|
-
|
|
23
|
-
## Local use
|
|
24
|
-
|
|
25
|
-
From this repository, try the extension for one invocation:
|
|
26
|
-
|
|
27
|
-
```sh
|
|
28
|
-
npm install
|
|
29
|
-
pi --no-extensions --extension ./packages/pi-statusline/src/index.ts
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
`--no-extensions` disables other auto-discovered extensions for this invocation.
|
|
33
|
-
To use your other extensions, disable `pi-powerline-footer` in `pi config`
|
|
34
|
-
before starting Pi with `--extension ./packages/pi-statusline/src/index.ts`.
|
|
35
|
-
Only one extension should own the footer. The previous package can remain
|
|
36
|
-
installed for rollback. Loading this repository as a whole also discovers the
|
|
37
|
-
security extensions; use the statusline entrypoint to try it on its own.
|
|
38
|
-
|
|
39
|
-
This checkout is for development only. For a persistent install use the
|
|
40
|
-
published package, `npm:@erichll/pi-statusline`.
|
|
17
|
+
Requires Node.js >=22.19 and Pi >=1.1.0; subscription Usage requires Pi >=1.2.0.
|
|
18
|
+
Git is optional. The default Powerline layout requires a Nerd Font; choose
|
|
19
|
+
ASCII icons and plain separators for a font-independent layout.
|
|
20
|
+
Disable other footer extensions in `pi config`: only one should own the footer.
|
|
21
|
+
No extra network requests or credential lookups are made.
|
|
41
22
|
|
|
42
23
|
## Commands
|
|
43
24
|
|
|
@@ -46,292 +27,144 @@ published package, `npm:@erichll/pi-statusline`.
|
|
|
46
27
|
| `/statusline` | Open configuration and live preview |
|
|
47
28
|
| `/statusline on` | Enable for this session |
|
|
48
29
|
| `/statusline off` | Restore Pi's native footer for this session |
|
|
49
|
-
| `/statusline reload` | Reload saved configuration
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
the no-content threshold.
|
|
56
|
-
**Restore defaults in preview** changes only the draft until saved.
|
|
57
|
-
Preview uses the real footer renderer and current session data, or clearly
|
|
58
|
-
labelled example data for an empty session. A save error leaves the active
|
|
59
|
-
configuration unchanged and keeps the panel open.
|
|
30
|
+
| `/statusline reload` | Reload saved configuration |
|
|
31
|
+
|
|
32
|
+
In the panel: arrows navigate, Space toggles, Alt+Up/Down reorders segments,
|
|
33
|
+
Enter edits, and Esc backs out or cancels. **Save and apply globally** persists
|
|
34
|
+
changes; **Restore defaults in preview** only changes the draft until saved.
|
|
35
|
+
Thinking settings are under **model**; runtime settings are under **Runtime options**.
|
|
60
36
|
|
|
61
37
|
## Configuration
|
|
62
38
|
|
|
63
|
-
Settings
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
existing file to the new path before running `/reload`; the old path is no longer read.
|
|
39
|
+
Settings are global, stored at
|
|
40
|
+
`~/.pi/agent/extensions/pi-statusline/config.json` (`PI_CODING_AGENT_DIR` is
|
|
41
|
+
respected). After manual edits, run `/statusline reload`; after source edits,
|
|
42
|
+
run Pi's `/reload` instead. The old `~/.pi/agent/statusline.json` path is no
|
|
43
|
+
longer read—move an existing file to the new location when upgrading.
|
|
44
|
+
|
|
45
|
+
Use the panel or start with a partial configuration:
|
|
71
46
|
|
|
72
47
|
```json
|
|
73
48
|
{
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"pathMode": "basename",
|
|
80
|
-
"modelDisplay": "name",
|
|
81
|
-
"contextDisplay": "bar",
|
|
82
|
-
"spacing": 1,
|
|
83
|
-
"segments": [
|
|
84
|
-
{
|
|
85
|
-
"id": "model",
|
|
86
|
-
"enabled": true
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
"id": "thinking",
|
|
90
|
-
"enabled": true
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
"id": "context",
|
|
94
|
-
"enabled": true
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
"id": "directory",
|
|
98
|
-
"enabled": true
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
"id": "git",
|
|
102
|
-
"enabled": true
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
"id": "cost",
|
|
106
|
-
"enabled": false
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
"id": "input",
|
|
110
|
-
"enabled": false
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
"id": "output",
|
|
114
|
-
"enabled": false
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
"id": "tokens",
|
|
118
|
-
"enabled": true
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
"id": "cacheRead",
|
|
122
|
-
"enabled": false
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
"id": "cacheWrite",
|
|
126
|
-
"enabled": false
|
|
127
|
-
},
|
|
128
|
-
{
|
|
129
|
-
"id": "statuses",
|
|
130
|
-
"enabled": true
|
|
131
|
-
}
|
|
132
|
-
],
|
|
133
|
-
"runtime": {
|
|
134
|
-
"enabled": true,
|
|
135
|
-
"status": true,
|
|
136
|
-
"tools": true,
|
|
137
|
-
"noContent": true,
|
|
138
|
-
"noContentSeconds": 10,
|
|
139
|
-
"avg": true,
|
|
140
|
-
"cache": true,
|
|
141
|
-
"counts": true,
|
|
142
|
-
"retainSummary": true
|
|
143
|
-
}
|
|
49
|
+
"icons": "ascii",
|
|
50
|
+
"separator": "pipe",
|
|
51
|
+
"modelDisplay": "last",
|
|
52
|
+
"contextDisplay": "text",
|
|
53
|
+
"spacing": 0
|
|
144
54
|
}
|
|
145
55
|
```
|
|
146
56
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
even when a display name is configured. For example, `provider/a/b/c/d` becomes `d`.
|
|
160
|
-
Restoring defaults resets this preference to `name`.
|
|
161
|
-
- Context display: `bar` (default, `[██░░░░░░░░]20%`) or `text`
|
|
162
|
-
(`12.7k/272k(4.7%)`). Choose **Context display: bar** in the panel or set
|
|
163
|
-
`"contextDisplay": "bar"`.
|
|
164
|
-
The ten-cell bar uses whole blocks to avoid gaps inside partial glyphs. Fill
|
|
165
|
-
rounds to the nearest cell, with at least one filled cell for non-zero usage;
|
|
166
|
-
the percentage retains the more precise value. ASCII mode uses `#` and `-`.
|
|
167
|
-
Unknown usage shows `[??????????]?%`; values above 100% fill
|
|
168
|
-
the bar completely and retain the reported percentage. Both modes use the
|
|
169
|
-
existing context warning colors. Text mode includes token counts and capacity;
|
|
170
|
-
bar mode shows progress and percentage.
|
|
171
|
-
- Spacing: `1` (default), `0`, `2` or `3` blank lines above the statusline.
|
|
172
|
-
Pi renders the footer directly under the editor, so this is the only supported
|
|
173
|
-
way to add breathing room between the input box and the statusline; the editor's
|
|
174
|
-
own bottom border cannot be removed. Choose **Spacing above statusline** in the
|
|
175
|
-
panel or set `"spacing": 0` for a flush footer.
|
|
176
|
-
- `segments`: optional ordered array of `{ id, enabled, icon?, color?, iconColor?, background? }`.
|
|
177
|
-
An explicit list is authoritative: omitted segments are disabled but remain
|
|
178
|
-
available in the panel. The `statuses` segment always occupies the second row.
|
|
179
|
-
Preset layouts place context immediately after the model, before directory
|
|
180
|
-
and Git. Explicit saved segment order is respected and can be changed in the panel.
|
|
181
|
-
- Thinking is appended to the model as `(level)`, with no separate icon or
|
|
182
|
-
separator. In the panel, edit **model → Thinking level / Thinking color**.
|
|
183
|
-
The existing `thinking` configuration entry controls suffix enablement and an
|
|
184
|
-
optional color override; its position, icon and background are ignored. It
|
|
185
|
-
does not render on its own when the model is hidden or non-reasoning.
|
|
186
|
-
By default, `off`, `minimal`, `low`, and `medium` use their respective Pi theme
|
|
187
|
-
colors; `high`, `xhigh`, and `max` use a fixed violet/pink/orange/yellow/green/cyan/blue
|
|
188
|
-
palette independent of the Pi theme, distributed across the available characters.
|
|
189
|
-
The color or rainbow covers the entire `(level)`, including parentheses, and
|
|
190
|
-
the model's background covers the whole item.
|
|
191
|
-
- Icon `""` hides a glyph. In the panel, enter `:default` to restore its default.
|
|
192
|
-
Color fields accept `#RRGGBB` or `text`, `accent`, `muted`, `dim`, `success`,
|
|
193
|
-
`warning`, `error`, `border`, `borderAccent`, `borderMuted`, and Pi's
|
|
194
|
-
`thinkingOff/Minimal/Low/Medium/High/Xhigh/Max` tokens. Empty color input in the
|
|
195
|
-
panel restores the default. Explicit colors override automatic warning colors.
|
|
57
|
+
See [examples/statusline.json](examples/statusline.json) for the complete defaults.
|
|
58
|
+
|
|
59
|
+
| Setting | Values (default first) |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `enabled` | `true`, `false` (startup enablement) |
|
|
62
|
+
| `preset` | `powerline` only; colors adapt to Pi's light/dark theme |
|
|
63
|
+
| `icons` | `nerd`, `unicode`, `ascii` |
|
|
64
|
+
| `separator` | `powerline`, `pipe`, `dot`, `space` |
|
|
65
|
+
| `pathMode` | `basename`, `abbreviated`, `full` |
|
|
66
|
+
| `modelDisplay` | `name` (display name/ID), `last` (final model ID component) |
|
|
67
|
+
| `contextDisplay` | `bar` (`██░░░░░░░░ 20%`), `text` (`12.7k/272k(4.7%)`) |
|
|
68
|
+
| `spacing` | `1`, `0`, `2`, `3` blank lines above the footer |
|
|
196
69
|
|
|
197
70
|
Available segments:
|
|
198
71
|
|
|
199
72
|
| ID | Data | Default |
|
|
200
73
|
| --- | --- | --- |
|
|
201
|
-
| `model` |
|
|
202
|
-
| `
|
|
203
|
-
| `
|
|
204
|
-
| `directory` | Current
|
|
205
|
-
| `git` | Branch,
|
|
206
|
-
| `
|
|
207
|
-
| `
|
|
208
|
-
| `input`, `output` |
|
|
209
|
-
| `
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
##
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
token consumption. Unknown values, including immediately after compaction, show
|
|
284
|
-
`?` until Pi can provide an estimate. Yellow begins above 70%, red above 90%.
|
|
285
|
-
Pi 1.0 bases context estimates on persisted messages; in-flight usage updates
|
|
286
|
-
the cumulative token/cost segments while context refreshes after persistence.
|
|
287
|
-
|
|
288
|
-
Session totals include all usage already recorded in the current session file:
|
|
289
|
-
assistant messages, explicit usage entries, tool-result usage, compaction and
|
|
290
|
-
branch summaries, including pre-compaction and abandoned-branch consumption.
|
|
291
|
-
Streaming responses are provisional and counted once when persisted. The total
|
|
292
|
-
token segment sums input, output, cache-read and cache-write, matching Pi's
|
|
293
|
-
native session totals. Costs are **Pi-reported values, not provider invoices**;
|
|
294
|
-
zero means no cost recorded by Pi. No subscription-quota API or child-session
|
|
295
|
-
log is queried, and private `pi-subagents` result details are not parsed.
|
|
296
|
-
|
|
297
|
-
Git queries run asynchronously every two seconds and after tool/branch changes,
|
|
298
|
-
with a one-second timeout and optional index locks disabled. No repository hides
|
|
299
|
-
the segment; failures show `?`, never a false clean state. Large output above
|
|
300
|
-
8 MiB also falls back to unknown. Worktrees, detached HEAD, unborn branches and
|
|
301
|
-
filenames containing newlines are supported. Disabling the Git segment stops
|
|
302
|
-
its polling.
|
|
303
|
-
|
|
304
|
-
Rendering performs no file reads, Git queries or full-session scans. Streaming
|
|
305
|
-
refresh requests are coalesced to 100 ms. Narrow terminals shorten model/path
|
|
306
|
-
labels, then hide cost, cache/token counters, the thinking suffix, Git and directory in
|
|
307
|
-
that order, retaining model/context where possible. The secondary status row
|
|
308
|
-
drops extension text and cache/rate first, preserving
|
|
309
|
-
leading Elapsed and compaction status where possible, then truncates by terminal
|
|
310
|
-
cell width. Reload, session replacement, disabling and shutdown
|
|
311
|
-
release timers and subscriptions. RPC, JSON and print mode do not install UI
|
|
312
|
-
components or start polling.
|
|
313
|
-
|
|
314
|
-
## Development and rollback
|
|
74
|
+
| `model`, `thinking` | Model and colored `(level)` suffix | On |
|
|
75
|
+
| `context` | Current context usage | On |
|
|
76
|
+
| `quota` | Subscription Usage and reset countdowns; hidden without data | On |
|
|
77
|
+
| `directory` | Current directory | On |
|
|
78
|
+
| `git` | Branch, dirty/conflict state, staged/unstaged/untracked counts, ahead/behind | On |
|
|
79
|
+
| `tokens` | Cumulative session tokens | On |
|
|
80
|
+
| `cost` | Pi-recorded cumulative USD cost | Off |
|
|
81
|
+
| `input`, `output`, `cacheRead`, `cacheWrite` | Individual session token counters | Off |
|
|
82
|
+
| `statuses` | Other extensions' text on the second row | On |
|
|
83
|
+
|
|
84
|
+
`segments` is an ordered array of
|
|
85
|
+
`{ id, enabled, icon?, color?, iconColor?, background? }`. Omitted segments are
|
|
86
|
+
disabled, **except `quota`**: old configurations automatically gain it after
|
|
87
|
+
`context` (or at the end if context is absent). To keep it off, include
|
|
88
|
+
`{ "id": "quota", "enabled": false }`.
|
|
89
|
+
|
|
90
|
+
Colors accept `#RRGGBB` or supported Pi theme tokens such as `accent`, `muted`,
|
|
91
|
+
`success`, `warning` and `error`; explicit colors override automatic thresholds.
|
|
92
|
+
An empty icon hides it; enter `:default` in the panel to restore its default.
|
|
93
|
+
The `thinking` entry controls the model suffix, not a standalone segment.
|
|
94
|
+
|
|
95
|
+
Invalid configurations retain the last working settings and show a warning.
|
|
96
|
+
Removing the file restores defaults on reload; panel saves are atomic.
|
|
97
|
+
|
|
98
|
+
## Subscription Usage (Pi 1.2+)
|
|
99
|
+
|
|
100
|
+
Codex quota appears after context when valid data is available:
|
|
101
|
+
|
|
102
|
+
```text
|
|
103
|
+
█░░░░░░░░░ 4.6% ████░░░░░░ 40%[3h3m] | ██░░░░░░░░ 21%[4d9h]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Bars show **used** percentages for the primary and secondary windows (usually
|
|
107
|
+
5 hours and 7 days), with live reset countdowns. The default color is Pi's
|
|
108
|
+
accent, changing to warning above 70% and error above 90%. Narrow terminals
|
|
109
|
+
omit countdowns, then bars, then the segment rather than truncate a window.
|
|
110
|
+
|
|
111
|
+
Data is observed passively through Pi's provider events:
|
|
112
|
+
|
|
113
|
+
- **SSE:** `x-codex-{primary,secondary}-{used-percent,reset-at}` response headers.
|
|
114
|
+
CLIProxyAPI needs `requests.passthrough-headers: true`.
|
|
115
|
+
- **WebSocket:** native `codex.rate_limits` events with numeric `used_percent`
|
|
116
|
+
and `reset_at` in `rate_limits.primary` / `secondary`. Other named metered
|
|
117
|
+
buckets are ignored. The proxy must forward these events.
|
|
118
|
+
|
|
119
|
+
For CLIProxyAPI v8.0.28, each eligible Codex credential needs `websockets: true`
|
|
120
|
+
for the **proxy-to-upstream** WebSocket leg. A downstream WebSocket alone is
|
|
121
|
+
not enough: upstream SSE headers do not become quota frames. This setting is
|
|
122
|
+
separate from `ws-auth` and Pi's transport setting.
|
|
123
|
+
|
|
124
|
+
Missing, malformed or expired windows are hidden; a reported 0% remains visible.
|
|
125
|
+
Each response/event replaces the snapshot without merging credentials' windows.
|
|
126
|
+
Model/provider/API/endpoint changes, reload, new session and footer disable clear
|
|
127
|
+
old data. This is the responding upstream's quota, **not a proxy-pool aggregate**
|
|
128
|
+
or RPM/TPM rate limit.
|
|
129
|
+
|
|
130
|
+
## Statistics
|
|
131
|
+
|
|
132
|
+
- Context is Pi's current estimate, not cumulative consumption; unknown values
|
|
133
|
+
show `?`. Session totals include recorded usage across the whole session file,
|
|
134
|
+
including compaction and abandoned branches. Cost is Pi-reported, not an invoice.
|
|
135
|
+
- `Elapsed` spans retries, tools, UI waits and compaction. `Avg` is assistant
|
|
136
|
+
output tokens / total run seconds, **not inference speed**;
|
|
137
|
+
`Cache` is cache-read / (input + cache-read + cache-write). `Turns` counts Pi
|
|
138
|
+
turns, not upstream requests; `Compactions` counts successful session entries.
|
|
139
|
+
- Tool activity and `Awaiting input` appear while active. `No content 10s`
|
|
140
|
+
means no non-empty text, reasoning or tool-call delta was observed; it is not
|
|
141
|
+
a server timeout and is suppressed during tools, UI waits and compaction.
|
|
142
|
+
|
|
143
|
+
All runtime options default to enabled; `noContentSeconds` accepts 1–3600
|
|
144
|
+
(default 10). `retainSummary` keeps the last run until the next one;
|
|
145
|
+
`runtime.enabled: false` hides local runtime metrics. Reload/new session resets
|
|
146
|
+
in-memory runtime summaries, not persisted session totals.
|
|
147
|
+
|
|
148
|
+
Extension statuses remain display-only; a plain `tps` status of `Elapsed …`
|
|
149
|
+
replaces the local Elapsed label. Git updates asynchronously; no repository
|
|
150
|
+
hides the segment, and query failures show `?`. Narrow layouts prioritize model
|
|
151
|
+
and context. RPC, JSON and print mode do not install the footer or start polling.
|
|
152
|
+
|
|
153
|
+
## Development
|
|
154
|
+
|
|
155
|
+
From this repository, load only the statusline for one invocation:
|
|
315
156
|
|
|
316
157
|
```sh
|
|
158
|
+
npm install
|
|
159
|
+
pi --no-extensions --extension ./packages/pi-statusline/src/index.ts
|
|
160
|
+
|
|
317
161
|
npm run check --workspace @erichll/pi-statusline
|
|
318
162
|
npm test --workspace @erichll/pi-statusline
|
|
319
|
-
# Optional: POSIX PTY integration, using an offline simulated model
|
|
320
163
|
npm run smoke --workspace @erichll/pi-statusline
|
|
321
164
|
```
|
|
322
165
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
40-column layout, draft cancel/save, off/on, reload and new session. It writes
|
|
329
|
-
`/tmp/pi-statusline-pty-<layout>.log` for diagnosis. To roll back a persistent
|
|
330
|
-
installation, disable this extension in `pi config`, re-enable the previous
|
|
331
|
-
footer and reload Pi. `/statusline off` restores the native footer, not another
|
|
332
|
-
extension's editor or widgets.
|
|
333
|
-
|
|
334
|
-
The initial implementation is independently written, with design references to
|
|
335
|
-
[pi-powerline-footer](https://github.com/nicobailon/pi-powerline-footer).
|
|
336
|
-
|
|
337
|
-
MIT licensed.
|
|
166
|
+
The POSIX PTY smoke uses an offline provider in regular and fullscreen layouts.
|
|
167
|
+
For a persistent install, use the published npm package.
|
|
168
|
+
|
|
169
|
+
Independently implemented with design references to
|
|
170
|
+
[pi-powerline-footer](https://github.com/nicobailon/pi-powerline-footer). MIT licensed.
|
package/examples/statusline.json
CHANGED
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -10,7 +10,7 @@ export function validColor(value: unknown): value is ColorValue {
|
|
|
10
10
|
return typeof value === "string" && (/^#[\da-f]{6}$/i.test(value) || (COLORS as readonly string[]).includes(value));
|
|
11
11
|
}
|
|
12
12
|
export function presetConfig(): StatuslineConfig {
|
|
13
|
-
const enabled = new Set<string>(["model", "thinking", "directory", "git", "context", "tokens", "statuses"]);
|
|
13
|
+
const enabled = new Set<string>(["model", "thinking", "directory", "git", "context", "quota", "tokens", "statuses"]);
|
|
14
14
|
return {
|
|
15
15
|
version: 1, enabled: true, preset: "powerline", icons: "nerd",
|
|
16
16
|
separator: "powerline", pathMode: "basename", modelDisplay: "name", contextDisplay: "bar", spacing: 1,
|
|
@@ -78,7 +78,13 @@ export function parseConfig(raw: unknown): StatuslineConfig {
|
|
|
78
78
|
}
|
|
79
79
|
return result;
|
|
80
80
|
});
|
|
81
|
-
//
|
|
81
|
+
// Upgrade pre-quota lists once; an explicit quota entry (including disabled) wins.
|
|
82
|
+
if (!seen.has("quota")) {
|
|
83
|
+
const contextIndex = config.segments.findIndex((segment) => segment.id === "context");
|
|
84
|
+
config.segments.splice(contextIndex < 0 ? config.segments.length : contextIndex + 1, 0, { id: "quota", enabled: true });
|
|
85
|
+
seen.add("quota");
|
|
86
|
+
}
|
|
87
|
+
// All other omissions remain editable but disabled.
|
|
82
88
|
for (const id of SEGMENT_IDS) if (!seen.has(id)) config.segments.push({ id, enabled: false });
|
|
83
89
|
}
|
|
84
90
|
return config;
|
package/src/index.ts
CHANGED
|
@@ -24,6 +24,13 @@ export default function statusline(pi: ExtensionAPI): void {
|
|
|
24
24
|
session.install();
|
|
25
25
|
});
|
|
26
26
|
pi.on("session_shutdown", () => { generation++; session?.dispose(); session = undefined; });
|
|
27
|
+
pi.on("before_provider_request", (_event, ctx) => { session?.setContext(ctx); session?.beginProviderRequest(); });
|
|
28
|
+
pi.on("after_provider_response", (event, ctx) => { session?.setContext(ctx); session?.observeProviderResponse(event.headers); });
|
|
29
|
+
pi.on("provider_stream_event", (event, ctx) => {
|
|
30
|
+
if (!session?.active) return;
|
|
31
|
+
// Observe native quota events as well as disqualifying routed/mismatched requests.
|
|
32
|
+
if (session.quota.observeStream(event.provider, event.model, event.api, ctx.model, event.data)) session.schedule(true);
|
|
33
|
+
});
|
|
27
34
|
pi.on("agent_start", (_event, ctx) => { session?.setContext(ctx); session?.startRun(); session?.schedule(true); });
|
|
28
35
|
pi.on("turn_start", (_event, ctx) => { session?.setContext(ctx); session?.startTurn(); session?.schedule(true); });
|
|
29
36
|
pi.on("agent_before_settle", (event) => { session?.runtime.beforeSettle(event.outcome); });
|
|
@@ -53,7 +60,7 @@ export default function statusline(pi: ExtensionAPI): void {
|
|
|
53
60
|
const resetLive = (event: unknown, ctx: ExtensionContext) => { session?.setLive(undefined); refresh(event, ctx); };
|
|
54
61
|
pi.on("agent_end", resetLive);
|
|
55
62
|
pi.on("turn_end", (event, ctx) => { if (event.message.role === "assistant") session?.runtime.message(event.message, true); session?.runtime.turnEnd(); refresh(event, ctx); });
|
|
56
|
-
pi.on("model_select", refresh);
|
|
63
|
+
pi.on("model_select", (event, ctx) => { session?.quota.clear(); refresh(event, ctx); });
|
|
57
64
|
pi.on("thinking_level_select", refresh);
|
|
58
65
|
pi.on("session_compact", (event, ctx) => {
|
|
59
66
|
session?.compaction.finish("success", event.compactionEntry.id); session?.runtime.compaction(false); resetLive(event, ctx);
|
package/src/panel.ts
CHANGED
|
@@ -64,7 +64,7 @@ export class StatuslinePanel implements Component, Focusable {
|
|
|
64
64
|
{ value: "modelDisplay", label: `Model display: ${this.draft.modelDisplay}`, description: "name: display name · last: final model ID component" },
|
|
65
65
|
{ value: "contextDisplay", label: `Context display: ${this.draft.contextDisplay}`, description: "text: tokens/capacity(percent) · bar: progress and percent" },
|
|
66
66
|
{ value: "spacing", label: `Spacing above statusline: ${this.draft.spacing}`, description: "Blank lines between the input box and the statusline (0–3)" },
|
|
67
|
-
...this.draft.segments.filter((segment) => segment.id !== "thinking").map((segment) => ({ value: `segment:${segment.id}`, label: `[${segment.enabled ? "x" : " "}] ${segment.id}`, description: segment.id === "statuses" ? "Secondary row · Space toggles, Enter edits" : "Space toggles · Alt+Up/Down reorders · Enter edits" })),
|
|
67
|
+
...this.draft.segments.filter((segment) => segment.id !== "thinking").map((segment) => ({ value: `segment:${segment.id}`, label: `[${segment.enabled ? "x" : " "}] ${segment.id}`, description: segment.id === "statuses" ? "Secondary row · Space toggles, Enter edits" : segment.id === "quota" ? "Subscription Usage · passive headers/events; hidden without data" : "Space toggles · Alt+Up/Down reorders · Enter edits" })),
|
|
68
68
|
{ value: "runtime", label: "Runtime options" },
|
|
69
69
|
{ value: "save", label: "Save and apply globally" },
|
|
70
70
|
{ value: "reset", label: "Restore defaults in preview" },
|
package/src/quota.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
interface QuotaModel { provider: string; id: string; api: string; baseUrl: string; }
|
|
2
|
+
|
|
3
|
+
export interface QuotaWindow {
|
|
4
|
+
usedPercent: number;
|
|
5
|
+
resetAtSeconds: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SubscriptionQuota {
|
|
8
|
+
primary?: QuotaWindow;
|
|
9
|
+
secondary?: QuotaWindow;
|
|
10
|
+
}
|
|
11
|
+
export interface QuotaSnapshot {
|
|
12
|
+
primary?: QuotaWindow & { resetInMinutes: number };
|
|
13
|
+
secondary?: QuotaWindow & { resetInMinutes: number };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function headerNumber(value: unknown): number | undefined {
|
|
17
|
+
if (typeof value !== "string" || !/^\d+(?:\.\d+)?$/.test(value)) return undefined;
|
|
18
|
+
const number = Number(value);
|
|
19
|
+
return Number.isFinite(number) && number >= 0 ? number : undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function validatedWindow(usedPercent: unknown, resetAtSeconds: unknown): QuotaWindow | undefined {
|
|
23
|
+
if (typeof usedPercent !== "number" || !Number.isFinite(usedPercent) || usedPercent < 0 || usedPercent > 100) return undefined;
|
|
24
|
+
if (typeof resetAtSeconds !== "number" || !Number.isFinite(resetAtSeconds) || resetAtSeconds <= 0 || resetAtSeconds > 8.64e12) return undefined;
|
|
25
|
+
return { usedPercent, resetAtSeconds };
|
|
26
|
+
}
|
|
27
|
+
function record(value: unknown): value is Record<string, unknown> {
|
|
28
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29
|
+
}
|
|
30
|
+
function defaultQuotaEvent(data: Record<string, unknown>): boolean {
|
|
31
|
+
if (data.type !== "codex.rate_limits") return false;
|
|
32
|
+
// Other metered buckets are independent limits, not this default Codex allowance.
|
|
33
|
+
const limit = data.metered_limit_name ?? data.limit_name;
|
|
34
|
+
return limit == null || typeof limit === "string" && limit.trim().toLowerCase() === "codex";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Native WebSocket quota payload; read only known numeric fields, never account/credit data. */
|
|
38
|
+
export function readQuotaEvent(data: unknown): SubscriptionQuota | undefined {
|
|
39
|
+
if (!record(data) || !defaultQuotaEvent(data) || !record(data.rate_limits)) return undefined;
|
|
40
|
+
const quota: SubscriptionQuota = {};
|
|
41
|
+
for (const key of ["primary", "secondary"] as const) {
|
|
42
|
+
const value = data.rate_limits[key];
|
|
43
|
+
if (!record(value)) continue;
|
|
44
|
+
const window = validatedWindow(value.used_percent, value.reset_at);
|
|
45
|
+
if (window) quota[key] = window;
|
|
46
|
+
}
|
|
47
|
+
return quota.primary || quota.secondary ? quota : undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Read only Codex usage/reset headers, never credentials or full responses. */
|
|
51
|
+
export function readQuotaHeaders(headers: Record<string, string>): SubscriptionQuota | undefined {
|
|
52
|
+
const fields = new Map<string, string>();
|
|
53
|
+
for (const name of Object.keys(headers)) {
|
|
54
|
+
const lower = name.toLowerCase();
|
|
55
|
+
if (/^x-codex-(primary|secondary)-(used-percent|reset-at)$/.test(lower)) fields.set(lower, headers[name]!);
|
|
56
|
+
}
|
|
57
|
+
const quota: SubscriptionQuota = {};
|
|
58
|
+
for (const window of ["primary", "secondary"] as const) {
|
|
59
|
+
const prefix = `x-codex-${window}-`;
|
|
60
|
+
const usedPercent = headerNumber(fields.get(`${prefix}used-percent`));
|
|
61
|
+
const resetAtSeconds = headerNumber(fields.get(`${prefix}reset-at`));
|
|
62
|
+
// A percentage without a valid reset time cannot yield a trustworthy countdown.
|
|
63
|
+
const value = validatedWindow(usedPercent, resetAtSeconds);
|
|
64
|
+
if (value) quota[window] = value;
|
|
65
|
+
}
|
|
66
|
+
return quota.primary || quota.secondary ? quota : undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function modelKey(model: QuotaModel | undefined): string | undefined {
|
|
70
|
+
return model ? JSON.stringify([model.provider, model.id, model.api, model.baseUrl]) : undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Session-local response snapshot; never merge windows across requests or persist accounts. */
|
|
74
|
+
export class QuotaState {
|
|
75
|
+
private responseReceived = false;
|
|
76
|
+
private streamQuotaReceived = false;
|
|
77
|
+
private selected: string | undefined;
|
|
78
|
+
private request: string | undefined;
|
|
79
|
+
private quota: SubscriptionQuota | undefined;
|
|
80
|
+
|
|
81
|
+
select(model: QuotaModel | undefined): void {
|
|
82
|
+
const key = modelKey(model);
|
|
83
|
+
if (key !== this.selected) { this.clear(); this.selected = key; }
|
|
84
|
+
}
|
|
85
|
+
clear(): void {
|
|
86
|
+
this.request = undefined; this.quota = undefined;
|
|
87
|
+
this.responseReceived = false; this.streamQuotaReceived = false;
|
|
88
|
+
}
|
|
89
|
+
beginRequest(model: QuotaModel | undefined): void {
|
|
90
|
+
this.select(model);
|
|
91
|
+
this.responseReceived = false; this.streamQuotaReceived = false;
|
|
92
|
+
this.request = modelKey(model);
|
|
93
|
+
}
|
|
94
|
+
response(headers: Record<string, string>, model: QuotaModel | undefined): void {
|
|
95
|
+
this.select(model);
|
|
96
|
+
if (!this.request || this.request !== modelKey(model)) return;
|
|
97
|
+
this.responseReceived = true;
|
|
98
|
+
// Missing/malformed headers on a later response invalidate the old account snapshot.
|
|
99
|
+
this.quota = readQuotaHeaders(headers);
|
|
100
|
+
}
|
|
101
|
+
/** Returns true when the footer needs repainting; raw events are never retained. */
|
|
102
|
+
observeStream(provider: string, id: string, api: string, model: QuotaModel | undefined, data?: unknown): boolean {
|
|
103
|
+
this.select(model);
|
|
104
|
+
if (model && (provider !== model.provider || id !== model.id || api !== model.api)) {
|
|
105
|
+
this.clear();
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
if (!this.request || this.request !== modelKey(model)) return false;
|
|
109
|
+
if (record(data) && defaultQuotaEvent(data)) {
|
|
110
|
+
this.streamQuotaReceived = true;
|
|
111
|
+
// Replace the whole event snapshot; never merge two credentials' windows.
|
|
112
|
+
this.quota = readQuotaEvent(data);
|
|
113
|
+
return true; // A quota update (including invalidation) needs a repaint.
|
|
114
|
+
}
|
|
115
|
+
if (!this.streamQuotaReceived && !this.responseReceived) {
|
|
116
|
+
// WebSocket requests can stream successfully without an HTTP response hook.
|
|
117
|
+
// Never carry a previous SSE/account snapshot into that request.
|
|
118
|
+
const hadQuota = !!this.quota;
|
|
119
|
+
this.quota = undefined;
|
|
120
|
+
return hadQuota;
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
snapshot(model: QuotaModel | undefined, now = Date.now()): QuotaSnapshot | undefined {
|
|
125
|
+
this.select(model);
|
|
126
|
+
if (!this.quota) return undefined;
|
|
127
|
+
const result: QuotaSnapshot = {};
|
|
128
|
+
for (const window of ["primary", "secondary"] as const) {
|
|
129
|
+
const value = this.quota[window];
|
|
130
|
+
if (!value || value.resetAtSeconds * 1000 <= now) continue;
|
|
131
|
+
result[window] = { ...value, resetInMinutes: Math.ceil((value.resetAtSeconds * 1000 - now) / 60000) };
|
|
132
|
+
}
|
|
133
|
+
// Do not turn an expired sample into a made-up zero-usage window.
|
|
134
|
+
return result.primary || result.secondary ? result : undefined;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function formatReset(minutes: number): string {
|
|
139
|
+
if (minutes >= 1440) return `${Math.floor(minutes / 1440)}d${Math.floor(minutes % 1440 / 60)}h`;
|
|
140
|
+
if (minutes >= 60) return `${Math.floor(minutes / 60)}h${minutes % 60}m`;
|
|
141
|
+
return `${minutes}m`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function renderQuota(quota: QuotaSnapshot | undefined, ascii: boolean, detail: "full" | "bars" | "percent" = "full"): string | undefined {
|
|
145
|
+
if (!quota) return undefined;
|
|
146
|
+
const windows = [quota.primary, quota.secondary].filter((window) => window !== undefined);
|
|
147
|
+
if (!windows.length) return undefined;
|
|
148
|
+
return windows.map((window) => {
|
|
149
|
+
const percent = `${Number(window.usedPercent.toFixed(1))}%`;
|
|
150
|
+
if (detail === "percent") return percent;
|
|
151
|
+
const full = window.usedPercent > 0 ? Math.max(1, Math.round(window.usedPercent / 10)) : 0;
|
|
152
|
+
const bar = (ascii ? "#" : "█").repeat(full) + (ascii ? "-" : "░").repeat(10 - full);
|
|
153
|
+
return `${bar} ${percent}${detail === "full" ? `[${formatReset(window.resetInMinutes)}]` : ""}`;
|
|
154
|
+
}).join(" | ");
|
|
155
|
+
}
|
package/src/render.ts
CHANGED
|
@@ -7,13 +7,14 @@ import type { ColorValue, SegmentConfig, SegmentId, StatuslineConfig, Statusline
|
|
|
7
7
|
import { emptyGit } from "./git.ts";
|
|
8
8
|
import { emptyUsage } from "./usage.ts";
|
|
9
9
|
import { renderRuntime } from "./runtime-render.ts";
|
|
10
|
+
import { renderQuota } from "./quota.ts";
|
|
10
11
|
|
|
11
12
|
export type RenderTheme = Pick<Theme, "style" | "colors" | "appearance">;
|
|
12
13
|
// Keep rainbow hues independent of semantic theme colors, which can repeat.
|
|
13
14
|
const THINKING_RAINBOW = ["#c084fc", "#f472b6", "#fb923c", "#facc15", "#4ade80", "#22d3ee", "#60a5fa"].map((value) => parseColor(value));
|
|
14
15
|
const ICONS: Record<StatuslineConfig["icons"], Partial<Record<SegmentId, string>>> = {
|
|
15
16
|
unicode: { model: "", directory: "▸", git: "⑂", context: "◉", cost: "$", input: "↑", output: "↓", tokens: "Σ", cacheRead: "R", cacheWrite: "W" },
|
|
16
|
-
nerd: { model: "", directory: "", git: "", context: "", cost: "$", input: "↑", output: "↓", tokens: "", cacheRead: "R", cacheWrite: "W" },
|
|
17
|
+
nerd: { model: "", directory: "", git: "", context: "", quota: "", cost: "$", input: "↑", output: "↓", tokens: "", cacheRead: "R", cacheWrite: "W" },
|
|
17
18
|
ascii: { model: "", directory: "", git: "git:", context: "ctx:", cost: "$", input: "in:", output: "out:", tokens: "tok:", cacheRead: "R:", cacheWrite: "W:" },
|
|
18
19
|
};
|
|
19
20
|
const DROP_ORDER: SegmentId[] = ["cost", "cacheWrite", "cacheRead", "tokens", "output", "input", "thinking", "git", "directory"];
|
|
@@ -24,13 +25,13 @@ export function formatTokens(value: number): string {
|
|
|
24
25
|
}
|
|
25
26
|
function contextBar(percent: number | null, ascii: boolean): string {
|
|
26
27
|
const width = 10;
|
|
27
|
-
if (percent === null || !Number.isFinite(percent)) return
|
|
28
|
+
if (percent === null || !Number.isFinite(percent)) return `${"?".repeat(width)} ?%`;
|
|
28
29
|
const fill = Math.max(0, Math.min(100, percent)) / 100 * width;
|
|
29
30
|
// Whole cells avoid the blank right side of fractional glyphs such as ▌.
|
|
30
31
|
// Keep small, non-zero usage visible; the percentage gives the precise value.
|
|
31
32
|
const full = fill > 0 ? Math.max(1, Math.round(fill)) : 0;
|
|
32
33
|
const bar = (ascii ? "#" : "█").repeat(full) + (ascii ? "-" : "░").repeat(width - full);
|
|
33
|
-
return
|
|
34
|
+
return `${bar} ${Number(percent.toFixed(1))}%`;
|
|
34
35
|
}
|
|
35
36
|
function displayPath(data: StatuslineSnapshot, mode: StatuslineConfig["pathMode"]): string {
|
|
36
37
|
if (mode === "basename") return basename(data.cwd) || data.cwd;
|
|
@@ -69,6 +70,7 @@ function segmentText(id: SegmentId, data: StatuslineSnapshot, config: Statusline
|
|
|
69
70
|
const capacity = contextWindow > 0 ? formatTokens(contextWindow) : "?";
|
|
70
71
|
return `${tokens === null ? "?" : formatTokens(tokens)}/${capacity}(${percent === null ? "?" : Number(percent.toFixed(1))}%)`;
|
|
71
72
|
}
|
|
73
|
+
case "quota": return renderQuota(data.quota, config.icons === "ascii");
|
|
72
74
|
case "cost": return usage.cost.toFixed(3);
|
|
73
75
|
case "input": return formatTokens(usage.input);
|
|
74
76
|
case "output": return formatTokens(usage.output);
|
|
@@ -83,6 +85,10 @@ function defaultColor(id: SegmentId, data: StatuslineSnapshot): ColorValue {
|
|
|
83
85
|
if ((data.context.percent ?? 0) > 90) return "error";
|
|
84
86
|
if ((data.context.percent ?? 0) > 70) return "warning";
|
|
85
87
|
}
|
|
88
|
+
if (id === "quota") {
|
|
89
|
+
const used = Math.max(data.quota?.primary?.usedPercent ?? 0, data.quota?.secondary?.usedPercent ?? 0);
|
|
90
|
+
return used > 90 ? "error" : used > 70 ? "warning" : "accent";
|
|
91
|
+
}
|
|
86
92
|
if (id === "git") {
|
|
87
93
|
if (data.git.conflicts) return "error";
|
|
88
94
|
if (data.git.kind === "unknown" || data.git.staged + data.git.unstaged + data.git.untracked) return "warning";
|
|
@@ -196,6 +202,19 @@ export function renderFooter(width: number, data: StatuslineSnapshot, config: St
|
|
|
196
202
|
line = joinParts(parts, config, theme);
|
|
197
203
|
}
|
|
198
204
|
}
|
|
205
|
+
// Keep model/context readable; never leave a half-truncated quota window.
|
|
206
|
+
const quota = parts.find((part) => part.config.id === "quota");
|
|
207
|
+
if (quota && visibleWidth(line) > width) {
|
|
208
|
+
for (const detail of ["bars", "percent"] as const) {
|
|
209
|
+
quota.text = renderQuota(data.quota, config.icons === "ascii", detail)!;
|
|
210
|
+
line = joinParts(parts, config, theme);
|
|
211
|
+
if (visibleWidth(line) <= width) break;
|
|
212
|
+
}
|
|
213
|
+
if (visibleWidth(line) > width) {
|
|
214
|
+
parts.splice(parts.indexOf(quota), 1);
|
|
215
|
+
line = joinParts(parts, config, theme);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
199
218
|
const lines: string[] = [];
|
|
200
219
|
if (parts.length) lines.push(truncateToWidth(line, width, ellipsis));
|
|
201
220
|
const secondLine = renderRuntime(width, data, config, theme, secondary ? renderPart(secondary, theme) : undefined, elapsedStatus);
|
package/src/session.ts
CHANGED
|
@@ -8,10 +8,12 @@ import type { StatuslineConfig, StatuslineSnapshot } from "./types.ts";
|
|
|
8
8
|
import { UsageCache } from "./usage.ts";
|
|
9
9
|
import { RuntimeState } from "./runtime.ts";
|
|
10
10
|
import { CompactionState } from "./compaction.ts";
|
|
11
|
+
import { QuotaState } from "./quota.ts";
|
|
11
12
|
|
|
12
13
|
export class FooterSession {
|
|
13
14
|
readonly runtime = new RuntimeState();
|
|
14
15
|
readonly compaction = new CompactionState();
|
|
16
|
+
readonly quota = new QuotaState();
|
|
15
17
|
private ctx: ExtensionContext;
|
|
16
18
|
private config: StatuslineConfig;
|
|
17
19
|
private usage = new UsageCache();
|
|
@@ -35,7 +37,12 @@ export class FooterSession {
|
|
|
35
37
|
this.ctx = ctx; this.config = config; this.gitReader = gitReader;
|
|
36
38
|
}
|
|
37
39
|
get active(): boolean { return this.ownsFooter && !this.closed; }
|
|
38
|
-
setContext(ctx: ExtensionContext): void { this.ctx = ctx; this.watchSignal(); }
|
|
40
|
+
setContext(ctx: ExtensionContext): void { this.ctx = ctx; this.quota.select(ctx.model); this.watchSignal(); }
|
|
41
|
+
beginProviderRequest(): void { if (this.active) this.quota.beginRequest(this.ctx.model); }
|
|
42
|
+
observeProviderResponse(headers: Record<string, string>): void {
|
|
43
|
+
if (!this.active) return;
|
|
44
|
+
this.quota.response(headers, this.ctx.model); this.schedule(true);
|
|
45
|
+
}
|
|
39
46
|
private watchSignal(): void {
|
|
40
47
|
if (this.closed || !this.ownsFooter || !this.runtime.running) return;
|
|
41
48
|
const signal = this.ctx.signal;
|
|
@@ -81,15 +88,19 @@ export class FooterSession {
|
|
|
81
88
|
this.unsubscribe?.(); this.unsubscribe = undefined;
|
|
82
89
|
this.ownsFooter = false; this.tui = undefined; this.provider = undefined;
|
|
83
90
|
}
|
|
84
|
-
|
|
91
|
+
private uninstall(): void {
|
|
85
92
|
const restore = this.ownsFooter;
|
|
86
93
|
this.stopResources();
|
|
87
94
|
if (restore && !this.closed) this.ctx.ui.setFooter(undefined);
|
|
88
95
|
}
|
|
89
|
-
|
|
96
|
+
disable(): void { this.uninstall(); this.quota.clear(); }
|
|
97
|
+
dispose(): void { this.stopResources(); this.clearSignal(); this.quota.clear(); this.closed = true; }
|
|
90
98
|
apply(config: StatuslineConfig): void {
|
|
91
99
|
if (this.closed) return;
|
|
92
|
-
|
|
100
|
+
const keepQuota = this.active && config.enabled;
|
|
101
|
+
this.uninstall();
|
|
102
|
+
if (!keepQuota) this.quota.clear();
|
|
103
|
+
this.config = config;
|
|
93
104
|
if (config.enabled) this.install();
|
|
94
105
|
}
|
|
95
106
|
setLive(message: AssistantMessage | undefined): void { this.usage.setLive(message); }
|
|
@@ -129,7 +140,7 @@ export class FooterSession {
|
|
|
129
140
|
return {
|
|
130
141
|
model: this.ctx.model?.name || this.ctx.model?.id || "No model", modelId: this.ctx.model?.id ?? "", reasoning: this.ctx.model?.reasoning ?? false,
|
|
131
142
|
thinking: this.ctx.thinkingLevel ?? "off", cwd: this.ctx.cwd, home: homedir(),
|
|
132
|
-
context: this.context, usage: this.usage.snapshot(), git: this.git,
|
|
143
|
+
context: this.context, usage: this.usage.snapshot(), quota: this.quota.snapshot(this.ctx.model), git: this.git,
|
|
133
144
|
statuses: this.provider?.getExtensionStatuses() ?? new Map(),
|
|
134
145
|
runtime: this.runtime.snapshot(this.config.runtime.retainSummary), compaction: this.compaction.snapshot(),
|
|
135
146
|
};
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
|
|
3
|
-
export const SEGMENT_IDS = ["model", "thinking", "context", "directory", "git", "cost", "input", "output", "tokens", "cacheRead", "cacheWrite", "statuses"] as const;
|
|
3
|
+
export const SEGMENT_IDS = ["model", "thinking", "context", "quota", "directory", "git", "cost", "input", "output", "tokens", "cacheRead", "cacheWrite", "statuses"] as const;
|
|
4
4
|
export type SegmentId = typeof SEGMENT_IDS[number];
|
|
5
5
|
export type ColorValue = ThemeColor | `#${string}`;
|
|
6
6
|
export type Preset = "powerline";
|
|
@@ -65,6 +65,7 @@ export interface StatuslineSnapshot {
|
|
|
65
65
|
home: string;
|
|
66
66
|
context: { tokens: number | null; contextWindow: number; percent: number | null };
|
|
67
67
|
usage: UsageTotals;
|
|
68
|
+
quota?: import("./quota.ts").QuotaSnapshot;
|
|
68
69
|
git: GitState;
|
|
69
70
|
statuses: ReadonlyMap<string, string>;
|
|
70
71
|
runtime?: import("./runtime.ts").RuntimeSnapshot;
|