pi-status-footer 1.0.4 β†’ 1.0.5

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 +15 -14
  2. package/package.json +2 -2
  3. package/stats-footer.ts +111 -40
package/README.md CHANGED
@@ -7,15 +7,15 @@ A compact, zero-config two-line status footer for [pi](https://github.com/earend
7
7
  ![pi-status-footer demo](docs/footer-demo.png)
8
8
 
9
9
  ```
10
- πŸ€– openai/gpt-4o πŸ’­ medium ↑5.2k ↓8.1k ⚑42 t/s πŸ’Ύ63% πŸ“¦38%/128k
11
- πŸ“ my-project β–Έ ξœ₯ main +3 -1 ⏳ 4:32 πŸ’¬ 1:18
10
+ πŸ“¦ 38%/128k πŸ’Ύ 63% ↑5.2k ↓8.1k ⚑42 t/s ⏳ 4:32 πŸ’¬ 1:18
11
+ πŸ“ my-project β–Έ ξœ₯ main +3 -1 πŸ€– openai/ry-very-long-modelid-4o πŸ’­ medium
12
12
  ```
13
13
 
14
- **Line 1 β€” Model & stats:** provider/model, thinking level with themed color, input/output tokens, tokens per second (live while streaming), cache hit rate, context window usage with color-coded fullness (green < 60%, yellow < 80%, red β‰₯ 80%).
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 (πŸ’¬).
15
15
 
16
- **Line 2 β€” Project & timers:** repo folder name, git branch, live working-tree diff from HEAD (+N added lines, -M deleted), agent run timer (⏳), current turn timer (πŸ’¬).
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
17
 
18
- Everything auto-fits to your terminal width β€” lower-priority segments drop off when space is tight (model name is always shown, truncated if needed).
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
19
 
20
20
  ## Features
21
21
 
@@ -25,7 +25,8 @@ Everything auto-fits to your terminal width β€” lower-priority segments drop off
25
25
  - **Cache hit rate** β€” percentage of prompt tokens served from cache
26
26
  - **Context gauge** β€” percentage and raw max; shifts from green β†’ yellow β†’ red as you approach the limit
27
27
  - **Thinking level** β€” color-coded to match pi's thinking theme
28
- - **Segments drop gracefully** β€” only the model name is mandatory; everything else fits to width
28
+ - **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
29
+ - **Line 1 never drops stats** β€” every stat segment always renders; on very narrow terminals the line clips instead
29
30
  - **East Asian safe** β€” explicit ambiguous-width handling for CJK-friendly terminals
30
31
  - **Safe at all times** β€” footer rendering never crashes the TUI, even on edge cases
31
32
 
@@ -46,26 +47,26 @@ After installation, the footer appears automatically on the next pi TUI session.
46
47
 
47
48
  ## Display reference
48
49
 
49
- ### Line 1 β€” Model & stats
50
+ ### Line 1 β€” Stats & timers
50
51
 
51
52
  | Segment | Example | Source |
52
53
  |---|---|---|
53
- | πŸ€– model | `πŸ€– openai/gpt-4o` | `ctx.model.provider / ctx.model.id` |
54
- | πŸ’­ thinking | `πŸ’­ high` | `ctx.thinkingLevel`, themed via `theme.fg()` |
54
+ | πŸ“¦context | `πŸ“¦ 38%/128k` | `ctx.getContextUsage()`, color-coded by percent |
55
+ | πŸ’Ύcache | `πŸ’Ύ 63%` | `cacheRead / (input + cacheRead + cacheWrite)` |
55
56
  | ↑input ↓output | `↑5.2k ↓8.1k` | Session `usage.input / usage.output` (accumulated across all entries) |
56
57
  | ⚑tps | `⚑42 t/s` | Live during generation; last completed rate shown between turns |
57
- | πŸ’Ύcache | `πŸ’Ύ63%` | `cacheRead / (input + cacheRead + cacheWrite)` |
58
- | πŸ“¦context | `πŸ“¦38%/128k` | `ctx.getContextUsage()`, color-coded by percent |
58
+ | ⏳ working | `⏳ 4:32` | Elapsed time since `agent_start`, HH:MM:SS above 1h |
59
+ | πŸ’¬ turn | `πŸ’¬ 1:18` | Elapsed time since last `turn_start` |
59
60
 
60
- ### Line 2 β€” Project & timers
61
+ ### Line 2 β€” Project & model
61
62
 
62
63
  | Segment | Example | Source |
63
64
  |---|---|---|
64
65
  | πŸ“ repo | `πŸ“ my-project` | Git repo root basename (from `ctx.cwd` walk-up) |
65
66
  | β–Έ ξœ₯ branch | `β–Έ ξœ₯ main` | `footerData.getGitBranch()`, auto-updates |
66
67
  | +N -M diff | `+3 -1` | Async `git diff --shortstat HEAD` (1s debounced) |
67
- | ⏳ working | `⏳ 4:32` | Elapsed time since `agent_start`, HH:MM:SS above 1h |
68
- | πŸ’¬ turn | `πŸ’¬ 1:18` | Elapsed time since last `turn_start` |
68
+ | πŸ€– model | `πŸ€– openai/gpt-4o` | `ctx.model.provider / ctx.model.id`, id shortened from the left when narrow |
69
+ | πŸ’­ thinking | `πŸ’­ high` | `ctx.thinkingLevel`, themed via `theme.fg()` |
69
70
 
70
71
  ## How it works
71
72
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-status-footer",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Compact two-line status footer for pi: model, thinking level, tokens, TPS, cache hit rate, context usage, live git diff, and working/turn timers.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -29,7 +29,7 @@
29
29
  "streaming"
30
30
  ],
31
31
  "scripts": {
32
- "test": "node --experimental-strip-types test-live-tps.ts"
32
+ "test": "node --experimental-strip-types test-live-tps.ts && node --experimental-strip-types test-layout.ts"
33
33
  },
34
34
  "license": "MIT",
35
35
  "repository": {
package/stats-footer.ts CHANGED
@@ -202,24 +202,94 @@ function joinSegments(segments: string[], separator: string): string {
202
202
  return segments.filter(Boolean).join(separator);
203
203
  }
204
204
 
205
- function fitSegments(
206
- segments: string[],
207
- separator: string,
208
- width: number,
205
+ /** Below this terminal width the footer gives up fitting and lets the line
206
+ * overflow (the TUI clips it); shortening arithmetic degenerates here. */
207
+ const MIN_FIT_WIDTH = 50;
208
+
209
+ /**
210
+ * Shorten a model id by dropping leading characters, keeping the trailing
211
+ * part (model ids usually end in the distinguishing version, e.g. `...-4o`).
212
+ * A leading ellipsis marks the cut. Returns "" when nothing fits.
213
+ */
214
+ export function shortenModelId(
215
+ id: string,
216
+ budget: number,
217
+ ellipsis = "…",
209
218
  ): string {
210
- if (width <= 0 || segments.length === 0) return "";
211
- // The first segment (model + thinking level) has top priority. If it
212
- // alone is wider than the terminal, show a truncated prefix of it
213
- // instead of skipping it in favor of lower-priority segments.
214
- if (measureWidth(segments[0]!) > width) {
215
- return truncateSafe(segments[0]!, width, "...");
219
+ if (budget <= 0) return "";
220
+ if (measureWidth(id) <= budget) return id;
221
+ const ellipsisWidth = measureWidth(ellipsis);
222
+ if (budget < ellipsisWidth) return "";
223
+ const chars = Array.from(id);
224
+ for (let start = 0; start < chars.length; start++) {
225
+ const candidate = ellipsis + chars.slice(start).join("");
226
+ if (measureWidth(candidate) <= budget) return candidate;
216
227
  }
217
- const fitted: string[] = [segments[0]!];
218
- for (const segment of segments.slice(1)) {
219
- const candidate = joinSegments([...fitted, segment], separator);
220
- if (measureWidth(candidate) <= width) fitted.push(segment);
228
+ return ellipsis;
229
+ }
230
+
231
+ export interface SecondLineParts {
232
+ /** Folder/branch/diff group; "" when there is no folder to show. */
233
+ gitGroup: string;
234
+ /** Prefix before the provider, e.g. "πŸ€– ". */
235
+ modelPrefix: string;
236
+ /** Provider name; may be "" when no model is selected. */
237
+ provider: string;
238
+ /** Model id, shortened from the left when space is tight. */
239
+ modelId: string;
240
+ /** Everything after the model id, e.g. " πŸ’­ medium". */
241
+ modelSuffix: string;
242
+ /** Between-segment separator. */
243
+ separator: string;
244
+ /** Color wrapper applied to the `provider/id` text. */
245
+ styleModelId?: (text: string) => string;
246
+ }
247
+
248
+ /**
249
+ * Line 2 = folder/git group + model segment. The model (provider + thinking
250
+ * level) is mandatory: when space is tight the model id loses leading
251
+ * characters first, and if even a bare `provider/` cannot share the line the
252
+ * whole git group is dropped.
253
+ */
254
+ export function fitSecondLine(parts: SecondLineParts, width: number): string {
255
+ const {
256
+ gitGroup,
257
+ modelPrefix,
258
+ provider,
259
+ modelId,
260
+ modelSuffix,
261
+ separator,
262
+ styleModelId = (text: string) => text,
263
+ } = parts;
264
+ const providerPrefix = provider ? `${provider}/` : "";
265
+ const fixedWidth =
266
+ measureWidth(modelPrefix) +
267
+ measureWidth(providerPrefix) +
268
+ measureWidth(modelSuffix);
269
+ const buildModel = (budget: number): string | null => {
270
+ if (fixedWidth > budget) return null;
271
+ const idText = shortenModelId(modelId, budget - fixedWidth);
272
+ return `${modelPrefix}${styleModelId(`${providerPrefix}${idText}`)}${modelSuffix}`;
273
+ };
274
+
275
+ const fullModel = buildModel(Number.POSITIVE_INFINITY)!;
276
+ if (width < MIN_FIT_WIDTH) {
277
+ // Too narrow to fit meaningfully β€” render everything and let the TUI clip.
278
+ return joinSegments([gitGroup, fullModel], separator);
221
279
  }
222
- return truncateSafe(joinSegments(fitted, separator), width, "");
280
+ const maxWidth = Math.max(0, width - SAFETY_MARGIN);
281
+ if (!gitGroup) return buildModel(maxWidth) ?? fullModel;
282
+
283
+ const full = joinSegments([gitGroup, fullModel], separator);
284
+ if (measureWidth(full) <= maxWidth) return full;
285
+
286
+ const withGit = buildModel(
287
+ maxWidth - measureWidth(gitGroup) - measureWidth(separator),
288
+ );
289
+ if (withGit !== null) return joinSegments([gitGroup, withGit], separator);
290
+
291
+ // The model alone can't share the line: drop the whole folder/git group.
292
+ return buildModel(maxWidth) ?? fullModel;
223
293
  }
224
294
 
225
295
  /** Walk up from cwd to find the git repo root directory (or null). */
@@ -358,9 +428,6 @@ export default function statsFooter(pi: ExtensionAPI) {
358
428
  else contextColor = "success";
359
429
  }
360
430
 
361
- const modelId = ctx.model
362
- ? `${ctx.model.provider}/${ctx.model.id}`
363
- : "no-model";
364
431
  const thinkingLevel = ctx.thinkingLevel || "off";
365
432
  const contextText =
366
433
  contextPercent === null
@@ -385,34 +452,35 @@ export default function statsFooter(pi: ExtensionAPI) {
385
452
  // TPS: live rate while the current assistant message streams,
386
453
  // falling back to the last completed message's rate so the value
387
454
  // keeps a fixed position instead of flashing only at message_end.
388
- let tpsSuffix = "";
389
455
  const liveTps =
390
456
  genStart !== null && liveOutput > 0
391
457
  ? computeTps(liveOutput, genStart, Date.now())
392
458
  : null;
393
459
  const tpsValue = liveTps ?? lastTps;
394
- tpsSuffix = ` ⚑${Math.round(tpsValue ?? 0)} t/s`;
395
- // Line 1 β€” model + tokens/stats, each segment icon-prefixed.
396
- const statsLine = fitSegments(
460
+ // Line 1 β€” stats only (context, cache, tokens, TPS, timers). Every
461
+ // segment always renders; on very narrow terminals the line overflows
462
+ // and the TUI clips it rather than dropping stats.
463
+ const statsLine = joinSegments(
397
464
  [
398
- `πŸ€– ${theme.fg("accent", modelId)} ${thinkingText}`,
465
+ `πŸ“¦ ${theme.fg(contextColor, contextText)}`,
399
466
  theme.fg(
400
467
  "dim",
401
- `↑${formatTokens(usage.input)} ↓${formatTokens(usage.output)}${tpsSuffix}`,
468
+ `πŸ’Ύ ${cacheRate === null ? "-" : `${cacheRate.toFixed(0)}%`}`,
402
469
  ),
403
470
  theme.fg(
404
471
  "dim",
405
- `πŸ’Ύ ${cacheRate === null ? "-" : `${cacheRate.toFixed(0)}%`}`,
472
+ `↑${formatTokens(usage.input)} ↓${formatTokens(usage.output)}`,
406
473
  ),
407
- `πŸ“¦ ${theme.fg(contextColor, contextText)}`,
474
+ theme.fg("dim", `⚑${Math.round(tpsValue ?? 0)} t/s`),
475
+ `⏳ ${theme.fg("accent", formatDuration(elapsed))}`,
476
+ `πŸ’¬ ${theme.fg("accent", formatDuration(turnElapsed))}`,
408
477
  ],
409
478
  separator,
410
- Math.max(0, width - SAFETY_MARGIN),
411
479
  );
412
- // Line 2 β€” folder/git status + working/turn timers. The folder
413
- // name always shows (repo root basename, or plain cwd basename
414
- // when not inside a git repo); branch + diff only when git is
415
- // present.
480
+ // Line 2 β€” folder/git status + model/thinking. The folder name
481
+ // always shows (repo root basename, or plain cwd basename when
482
+ // not inside a git repo); branch + diff only when git is present.
483
+ // The model id is shortened from the left before git is dropped.
416
484
  const branch = footerData.getGitBranch();
417
485
  const gitSegments: string[] = [];
418
486
  if (folderName !== null) {
@@ -430,15 +498,18 @@ export default function statsFooter(pi: ExtensionAPI) {
430
498
  gitSegments.push(folderText);
431
499
  }
432
500
  }
433
- // ⏳ = work in progress (whole agent run), πŸ’¬ = current turn.
434
- gitSegments.push(
435
- `⏳ ${theme.fg("accent", formatDuration(elapsed))}`,
436
- `πŸ’¬ ${theme.fg("accent", formatDuration(turnElapsed))}`,
437
- );
438
- const gitLine = fitSegments(
439
- gitSegments,
440
- separator,
441
- Math.max(0, width - SAFETY_MARGIN),
501
+ const gitGroup = joinSegments(gitSegments, separator);
502
+ const gitLine = fitSecondLine(
503
+ {
504
+ gitGroup,
505
+ modelPrefix: "πŸ€– ",
506
+ provider: ctx.model?.provider ?? "",
507
+ modelId: ctx.model?.id ?? "no-model",
508
+ modelSuffix: ` ${thinkingText}`,
509
+ separator,
510
+ styleModelId: (text) => theme.fg("accent", text),
511
+ },
512
+ width,
442
513
  );
443
514
 
444
515
  return [