@giladbarnea/pi-custom-footer 0.1.0 → 0.1.2

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 +2 -0
  2. package/index.ts +244 -84
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -27,6 +27,8 @@ Below the editor, see:
27
27
 
28
28
  The layout follows your Pi theme and condenses to two footer lines in narrow panes.
29
29
 
30
+ On terminals with 40 rows or fewer, skills get at most four rows. To fit, the row first drops token ages, then separators, then shortens long names in the middle (`caut…ctor`). Only then does it show three rows plus a hidden-skill count.
31
+
30
32
  **Resize without rescanning the conversation.** The header and footer share cached values. Session changes refresh them, including forks and compaction.
31
33
 
32
34
  Skill age measures context-token growth since the first response after a skill load. A cache miss compares consecutive prompt sizes with reported reuse. Costs use the model’s reported pricing, including when you use a subscription.
package/index.ts CHANGED
@@ -1,22 +1,85 @@
1
- /** Show session context, cache usage, cost, and loaded skills around the editor. */
1
+ /**
2
+ * Show session context, cache usage, cost, and loaded skills around the editor.
3
+ *
4
+ * Skill row. Each loaded skill shows its name and its token age: how far the
5
+ * context has grown since the first response that saw the skill. The age tells
6
+ * how deep in the context the skill now sits. On a terminal of 40 rows or
7
+ * fewer, the skills get at most four rows. When they do not fit, the row gives
8
+ * up the least important thing left, one step at a time:
9
+ * 1. The token ages.
10
+ * 2. The separators between skills.
11
+ * 3. The middle of the longest names, one character per step, down to four
12
+ * characters on each side of the ellipsis. Names shorter than ten
13
+ * characters never change.
14
+ * 4. Last, three rows in the most compact layout plus a "+N skills" count.
15
+ * Knowing which skills are loaded matters more than any detail about them, so
16
+ * hiding a skill is the last resort. The Claude Code status line in
17
+ * ~/.claude/statusline.sh uses the same order.
18
+ *
19
+ * Known gaps reviewed September 30, 2026, against Pi 0.99.0:
20
+ * - Costs omit codemode and nested-model usage recorded on tool results.
21
+ * - Loaded skills omit successful reads recorded in tool-result nestedCalls.
22
+ * - The header omits the routed physical model and thinking level.
23
+ * - After compaction, unknown usage falls back to the selected model's window
24
+ * or 200k, ignoring the known physical window from getContextUsage().
25
+ */
2
26
  import type { AssistantMessage } from "@earendil-works/pi-ai";
3
- import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
4
- import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
27
+ import type { ExtensionAPI, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
28
+ import { truncateToWidth, visibleWidth, type TUI } from "@earendil-works/pi-tui";
5
29
 
6
30
  import { getLoadedSkills, type SkillLocation } from "./skill-tracker.ts";
7
31
 
8
32
  // ── Layout constants ────────────────────────────────────────────────────────
9
33
 
10
34
  const NARROW_WIDTH = 56;
35
+ const SHORT_TERMINAL_HEIGHT = 40;
36
+ const SKILL_COLLAPSE_ROW_THRESHOLD = 4;
37
+ const COLLAPSED_SKILL_ROWS = 3;
38
+ // A truncated name keeps four characters on each side of the ellipsis.
39
+ const MIN_TRUNCATED_NAME_LENGTH = 9;
11
40
  const NARROW_SEPARATOR = " ";
12
41
  const WIDE_SEPARATOR = " · ";
13
- const CONTEXT_GAUGE_SYMBOLS = [" ", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"];
42
+ const CONTEXT_GAUGE_SYMBOLS = ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"];
14
43
  const CONTEXT_GAUGE_STEP_COUNT = CONTEXT_GAUGE_SYMBOLS.length;
15
- const CONTEXT_MUTED_THRESHOLD = 40;
16
- const CONTEXT_WARNING_THRESHOLD = 65;
17
- const CONTEXT_ERROR_THRESHOLD = 85;
18
44
  const CACHE_MISS_NOISE_FLOOR_TOKENS = 1_024;
19
- const ANSI_RESET = "\x1b[0m";
45
+ // Match Theme.fg, which resets the foreground only. A full reset would punch a
46
+ // hole in any background the caller has already opened, such as the cwd pill.
47
+ const ANSI_FG_RESET = "\x1b[39m";
48
+ const QUIET_BLEND = 0.38;
49
+
50
+ // ── Colour rules ────────────────────────────────────────────────────────────
51
+ // Hue means one of two things here and nothing else.
52
+ //
53
+ // 1. A RAMP is a measurement. Its colour moves with the value, and it is loud
54
+ // only where there is something to act on. CONTEXT_STOPS runs quiet to loud
55
+ // as the window fills. CACHE_STOPS is that same scale mirrored, because a
56
+ // full cache is the good end and an empty one is the problem.
57
+ // 2. A FAMILY is a category. One token per kind of fact, held everywhere it
58
+ // appears, so the shape of the footer becomes learnable:
59
+ // accent place cwd, branch, dirty marker
60
+ // warning spend total cost, cost per turn
61
+ // syntaxKeyword machine model name; thinking has its own theme ramp
62
+ // mdCode skills loaded skill names
63
+ // dim / muted labels, units, reference figures, session id
64
+ //
65
+ // Every colour resolves through the theme. No literal colours below this line.
66
+
67
+ type Stop = { at: number; token: string; quiet?: boolean };
68
+
69
+ const CONTEXT_STOPS: readonly Stop[] = [
70
+ { at: 0, token: "success", quiet: true },
71
+ { at: 40, token: "success" },
72
+ { at: 70, token: "warning" },
73
+ { at: 100, token: "error" },
74
+ ];
75
+
76
+ /** The context ramp mirrored, so a full cache is quiet and an empty one is loud. */
77
+ const CACHE_STOPS: readonly Stop[] = CONTEXT_STOPS.map((stop) => ({ ...stop, at: 100 - stop.at })).reverse();
78
+
79
+ const PLACE_TOKEN = "accent";
80
+ const SPEND_TOKEN = "warning";
81
+ const MACHINE_TOKEN = "syntaxKeyword";
82
+ const SKILL_TOKEN = "mdCode";
20
83
 
21
84
  const THINKING_LEVELS: Record<string, { full: string; short: string; token: string }> = {
22
85
  off: { full: "off", short: "o", token: "dim" },
@@ -38,9 +101,15 @@ function joinedLine(parts: string[], separator: string): string {
38
101
  return ` ${parts.join(separator)}`;
39
102
  }
40
103
 
41
- function wrapJoinedLines(parts: string[], width: number, separator: string): string[] {
104
+ type WrappedLine = { text: string; partCount: number };
105
+
106
+ /** Wrap whole parts and retain the number of parts in each row.
107
+ * @example
108
+ * wrapJoinedLines(["one", "two"], 6, " · ") // [{ text: " one", partCount: 1 }, { text: " two", partCount: 1 }]
109
+ */
110
+ function wrapJoinedLines(parts: string[], width: number, separator: string): WrappedLine[] {
42
111
  if (parts.length === 0) return [];
43
- const lines: string[] = [];
112
+ const lines: WrappedLine[] = [];
44
113
  const remainingParts = [...parts];
45
114
  while (remainingParts.length > 0) {
46
115
  const lineParts: string[] = [];
@@ -50,11 +119,42 @@ function wrapJoinedLines(parts: string[], width: number, separator: string): str
50
119
  lineParts.push(remainingParts.shift()!);
51
120
  if (visibleWidth(joinedLine(lineParts, separator)) >= width) break;
52
121
  }
53
- lines.push(truncateToWidth(joinedLine(lineParts, separator), width));
122
+ lines.push({ text: truncateToWidth(joinedLine(lineParts, separator), width), partCount: lineParts.length });
54
123
  }
55
124
  return lines;
56
125
  }
57
126
 
127
+ /** Cut the middle of a name down to maxLength, marking the cut with an ellipsis.
128
+ * @example
129
+ * middleTruncate("cautious-refactor", 9) // "caut…ctor"
130
+ */
131
+ function middleTruncate(name: string, maxLength: number): string {
132
+ if (name.length <= maxLength) return name;
133
+ const kept = maxLength - 1;
134
+ return `${name.slice(0, Math.ceil(kept / 2))}…${name.slice(name.length - Math.floor(kept / 2))}`;
135
+ }
136
+
137
+ type SkillLayout = { ages: boolean; separator: string; maxNameLength: number };
138
+
139
+ /** Skill row layouts, fullest first. Each step gives up the least important
140
+ * thing left: first the token ages, then the separators, then one more
141
+ * character of the longest names.
142
+ * @example
143
+ * skillLayouts(3).length // 3
144
+ */
145
+ function skillLayouts(longestName: number): SkillLayout[] {
146
+ const truncations = Array.from(
147
+ { length: Math.max(0, longestName - MIN_TRUNCATED_NAME_LENGTH) },
148
+ (_, index) => ({ ages: false, separator: NARROW_SEPARATOR, maxNameLength: longestName - 1 - index }),
149
+ );
150
+ return [
151
+ { ages: true, separator: WIDE_SEPARATOR, maxNameLength: longestName },
152
+ { ages: false, separator: WIDE_SEPARATOR, maxNameLength: longestName },
153
+ { ages: false, separator: NARROW_SEPARATOR, maxNameLength: longestName },
154
+ ...truncations,
155
+ ];
156
+ }
157
+
58
158
  function renderExtensionStatuses(
59
159
  extensionStatuses: ReadonlyMap<string, string>,
60
160
  width: number,
@@ -122,7 +222,6 @@ function getSkillLocations(pi: ExtensionAPI): SkillLocation[] {
122
222
  // ── ANSI color helpers ──────────────────────────────────────────────────────
123
223
 
124
224
  type RgbColor = { red: number; green: number; blue: number };
125
- type RgbTokens = { dim: RgbColor | null; muted: RgbColor | null; warning: RgbColor | null; error: RgbColor | null };
126
225
 
127
226
  function ansi256ToRgb(index: number): RgbColor {
128
227
  const basicPalette: RgbColor[] = [
@@ -167,7 +266,12 @@ function ansiCodeToRgb(code: number): RgbColor | null {
167
266
  }
168
267
 
169
268
  function getThemeTokenRgb(theme: any, token: string): RgbColor | null {
170
- const themed = theme.fg(token, "x");
269
+ let themed: string;
270
+ try {
271
+ themed = typeof theme.getFgAnsi === "function" ? theme.getFgAnsi(token) : theme.fg(token, "x");
272
+ } catch {
273
+ return null;
274
+ }
171
275
  const matches = [...themed.matchAll(/\x1b\[([0-9;]+)m/g)];
172
276
  for (let i = matches.length - 1; i >= 0; i -= 1) {
173
277
  const codes = matches[i]?.[1]?.split(";").map(Number) ?? [];
@@ -199,38 +303,65 @@ function blendRgb(start: RgbColor, end: RgbColor, ratio: number): RgbColor {
199
303
  }
200
304
 
201
305
  function colorizeRgb(text: string, rgb: RgbColor): string {
202
- return `\x1b[38;2;${rgb.red};${rgb.green};${rgb.blue}m${text}${ANSI_RESET}`;
306
+ return `\x1b[38;2;${rgb.red};${rgb.green};${rgb.blue}m${text}${ANSI_FG_RESET}`;
203
307
  }
204
308
 
205
- function renderContextUsage(
206
- theme: any,
207
- pct: number,
208
- text: string,
209
- rgbTokens: RgbTokens,
210
- ): string {
211
- const { dim, muted, warning, error } = rgbTokens;
212
- if (!dim || !muted || !warning || !error) {
213
- if (pct >= CONTEXT_ERROR_THRESHOLD) return theme.fg("error", text);
214
- if (pct >= CONTEXT_WARNING_THRESHOLD) return theme.fg("warning", text);
215
- if (pct >= CONTEXT_MUTED_THRESHOLD) return theme.fg("muted", text);
216
- return theme.fg("dim", text);
217
- }
218
- if (pct < CONTEXT_MUTED_THRESHOLD) {
219
- return colorizeRgb(text, blendRgb(dim, muted, pct / CONTEXT_MUTED_THRESHOLD));
220
- }
221
- if (pct < CONTEXT_WARNING_THRESHOLD) {
222
- return colorizeRgb(
223
- text,
224
- blendRgb(muted, warning, (pct - CONTEXT_MUTED_THRESHOLD) / (CONTEXT_WARNING_THRESHOLD - CONTEXT_MUTED_THRESHOLD)),
225
- );
226
- }
227
- if (pct < CONTEXT_ERROR_THRESHOLD) {
228
- return colorizeRgb(
229
- text,
230
- blendRgb(warning, error, (pct - CONTEXT_WARNING_THRESHOLD) / (CONTEXT_ERROR_THRESHOLD - CONTEXT_WARNING_THRESHOLD)),
231
- );
232
- }
233
- return theme.fg("error", text);
309
+ function nearestStop(stops: readonly Stop[], value: number): Stop {
310
+ return stops.reduce((best, stop) =>
311
+ Math.abs(stop.at - value) < Math.abs(best.at - value) ? stop : best,
312
+ );
313
+ }
314
+
315
+ export interface Painter {
316
+ /** A family colour, held wherever that kind of fact appears. */
317
+ token(name: string, text: string): string;
318
+ /** The same family colour, receded, for a figure subordinate to another. */
319
+ quiet(name: string, text: string): string;
320
+ /** A measurement, coloured by where it sits on its own scale. */
321
+ ramp(stops: readonly Stop[], value: number, text: string): string;
322
+ }
323
+
324
+ /**
325
+ * Resolve every colour the footer needs from the live theme.
326
+ *
327
+ * A 256-colour terminal cannot render a blend, so both the ramp and the quiet
328
+ * variant fall back to the nearest whole theme token rather than emitting
329
+ * truecolor the terminal would drop.
330
+ */
331
+ function makePainter(theme: any): Painter {
332
+ const blendable = theme.getColorMode?.() !== "256color";
333
+ const resolved = new Map<string, RgbColor | null>();
334
+ const rgbOf = (name: string): RgbColor | null => {
335
+ if (!resolved.has(name)) resolved.set(name, getThemeTokenRgb(theme, name));
336
+ return resolved.get(name) ?? null;
337
+ };
338
+ const quietRgb = (name: string): RgbColor | null => {
339
+ const base = rgbOf(name);
340
+ const dim = rgbOf("dim");
341
+ return base && dim ? blendRgb(base, dim, QUIET_BLEND) : null;
342
+ };
343
+ const stopRgb = (stop: Stop): RgbColor | null => (stop.quiet ? quietRgb(stop.token) : rgbOf(stop.token));
344
+
345
+ return {
346
+ token: (name, text) => theme.fg(name, text),
347
+ quiet(name, text) {
348
+ const rgb = blendable ? quietRgb(name) : null;
349
+ return rgb ? colorizeRgb(text, rgb) : theme.fg("dim", text);
350
+ },
351
+ ramp(stops, value, text) {
352
+ const clamped = Math.min(Math.max(value, stops[0]!.at), stops[stops.length - 1]!.at);
353
+ for (let i = 0; i < stops.length - 1; i += 1) {
354
+ const low = stops[i]!;
355
+ const high = stops[i + 1]!;
356
+ if (clamped > high.at) continue;
357
+ const lowRgb = stopRgb(low);
358
+ const highRgb = stopRgb(high);
359
+ if (!blendable || !lowRgb || !highRgb) return theme.fg(nearestStop(stops, clamped).token, text);
360
+ return colorizeRgb(text, blendRgb(lowRgb, highRgb, (clamped - low.at) / (high.at - low.at)));
361
+ }
362
+ return theme.fg(stops[stops.length - 1]!.token, text);
363
+ },
364
+ };
234
365
  }
235
366
 
236
367
  function ctxGauge(pct: number): string {
@@ -397,48 +528,64 @@ export default function (pi: ExtensionAPI) {
397
528
  return snapshot;
398
529
  }
399
530
 
400
- function renderAbove(width: number, theme: any): string[] {
531
+ function renderAbove(width: number, terminalHeight: number, theme: Theme): string[] {
401
532
  if (!currentCtx) return [];
533
+ const paint = makePainter(theme);
402
534
  const model = formatModel(currentCtx.model);
403
535
  const thinking = renderThinkingLabel(theme, thinkingLevel, true);
404
536
  const sessionParts = getSnapshot().sessionParts.map((part) => theme.fg(part.token, part.text));
405
- const skillPills = loadedSkills.map(({ name, tokenAge }) => {
406
- const nameText = theme.fg("mdHeading", ` ${name}`);
407
- const ageText = tokenAge === null ? "" : theme.fg("muted", ` -${formatTokens(tokenAge)}`);
408
- return theme.bg("toolPendingBg", `${nameText}${ageText} `);
409
- });
410
- const parts = [theme.fg("accent", theme.bold(model))];
537
+ // No background here: the cwd pill is the one filled element in the whole
538
+ // footer, and a second pill style would leave neither of them the anchor.
539
+ const renderSkillLines = (layout: SkillLayout) => wrapJoinedLines(
540
+ loadedSkills.map(({ name, tokenAge }) => {
541
+ const nameText = paint.token(SKILL_TOKEN, middleTruncate(name, layout.maxNameLength));
542
+ const ageText = layout.ages && tokenAge !== null ? theme.fg("dim", ` -${formatTokens(tokenAge)}`) : "";
543
+ return `${nameText}${ageText}`;
544
+ }),
545
+ width,
546
+ theme.fg("dim", layout.separator),
547
+ );
548
+ // Weight is reserved for the pill and for thinking at high and above, so
549
+ // the model carries its family hue and nothing more.
550
+ const parts = [paint.token(MACHINE_TOKEN, model)];
411
551
  if (thinking) parts.push(thinking);
412
552
  parts.push(...sessionParts);
413
553
  const separator = theme.fg("dim", WIDE_SEPARATOR);
554
+ // A short terminal takes the fullest layout that fits the row limit. Hiding
555
+ // skills behind a count is the last resort, after the most compact layout.
556
+ const shortTerminal = terminalHeight <= SHORT_TERMINAL_HEIGHT;
557
+ const layouts = skillLayouts(Math.max(0, ...loadedSkills.map(({ name }) => name.length)));
558
+ const candidates = shortTerminal ? layouts : layouts.slice(0, 1);
559
+ const layout = candidates.find((candidate) => renderSkillLines(candidate).length <= SKILL_COLLAPSE_ROW_THRESHOLD) ?? candidates.at(-1)!;
560
+ const skillLines = renderSkillLines(layout);
561
+ const collapseSkills = shortTerminal && skillLines.length > SKILL_COLLAPSE_ROW_THRESHOLD;
562
+ const visibleSkillLines = collapseSkills ? skillLines.slice(0, COLLAPSED_SKILL_ROWS) : skillLines;
563
+ const hiddenSkillCount = skillLines.slice(visibleSkillLines.length).reduce((count, line) => count + line.partCount, 0);
564
+ const overflowLines = hiddenSkillCount === 0 ? [] : [truncateToWidth(theme.fg("dim", ` +${hiddenSkillCount} skills`), width)];
414
565
  return [
415
- ...wrapJoinedLines(parts, width, separator),
416
- ...wrapJoinedLines(skillPills, width, separator),
566
+ ...wrapJoinedLines(parts, width, separator).map((line) => line.text),
567
+ ...visibleSkillLines.map((line) => line.text),
568
+ ...overflowLines,
417
569
  ];
418
570
  }
419
571
 
420
572
  function renderBelow(width: number, theme: any): string[] {
421
573
  if (!currentCtx) return [];
422
574
  const { stats, context: { pct, window, tokens } } = getSnapshot();
423
- const rgbTokens: RgbTokens = {
424
- dim: getThemeTokenRgb(theme, "dim"),
425
- muted: getThemeTokenRgb(theme, "muted"),
426
- warning: getThemeTokenRgb(theme, "warning"),
427
- error: getThemeTokenRgb(theme, "error"),
428
- };
575
+ const paint = makePainter(theme);
429
576
  return isNarrow(width)
430
- ? renderFooterNarrow(width, theme, stats, pct, window, rgbTokens)
431
- : renderFooterWide(width, theme, stats, pct, window, tokens, rgbTokens);
577
+ ? renderFooterNarrow(width, theme, paint, stats, pct, window)
578
+ : renderFooterWide(width, theme, paint, stats, pct, window, tokens);
432
579
  }
433
580
 
434
581
  function renderFooterWide(
435
582
  width: number,
436
583
  theme: any,
584
+ paint: Painter,
437
585
  stats: SessionStats,
438
586
  pct: number,
439
587
  window: number,
440
588
  tokens: number,
441
- rgbTokens: RgbTokens,
442
589
  ): string[] {
443
590
  const separator = theme.fg("dim", WIDE_SEPARATOR);
444
591
  const label = (text: string) => theme.fg("dim", text.padEnd(8));
@@ -446,36 +593,47 @@ export default function (pi: ExtensionAPI) {
446
593
 
447
594
  const locationParts: string[] = [];
448
595
  if (gitBranch) {
449
- const dirty = gitDirty ? theme.fg("warning", "*") : "";
450
- locationParts.push(`${theme.fg("accent", ` ${gitBranch}`)}${dirty}`);
596
+ // A dirty worktree is a property of the place, not a cost, so it stays
597
+ // in the place family and leaves `warning` meaning spend alone.
598
+ const dirty = gitDirty ? paint.token(PLACE_TOKEN, "*") : "";
599
+ locationParts.push(`${paint.token(PLACE_TOKEN, ` ${gitBranch}`)}${dirty}`);
451
600
  }
452
- locationParts.push(theme.bg("selectedBg", theme.fg("text", ` ${currentDirectoryName(cwd)}/ `)));
601
+ locationParts.push(theme.bg("selectedBg", paint.token(PLACE_TOKEN, theme.bold(` ${currentDirectoryName(cwd)}/ `))));
453
602
  const locationLine = truncateToWidth(` ${locationParts.join(separator)}`, width);
454
603
 
455
- const gauge = renderContextUsage(theme, pct, `${ctxGauge(pct)} ${Math.round(pct)}%`, rgbTokens);
456
- const contextValue = theme.fg("text", `${formatTokens(tokens)} / ${formatTokens(window)} tokens`);
604
+ const gauge = paint.ramp(CONTEXT_STOPS, pct, `${ctxGauge(pct)} ${Math.round(pct)}%`);
605
+ // Colour the figure that moves and leave its reference quiet, so the eye
606
+ // lands on the reading rather than on the window size beside it.
607
+ const contextValue =
608
+ paint.ramp(CONTEXT_STOPS, pct, formatTokens(tokens)) +
609
+ theme.fg("dim", ` / ${formatTokens(window)} tokens`);
457
610
  const usingSubscription = currentCtx.model
458
611
  ? currentCtx.modelRegistry?.isUsingOAuth?.(currentCtx.model)
459
612
  : false;
460
- const costText = theme.fg("warning", `$${formatCost(stats.totalCost)}`);
613
+ const costText = paint.token(SPEND_TOKEN, `$${formatCost(stats.totalCost)}`);
461
614
  const subLabel = usingSubscription ? theme.fg("muted", " sub") : "";
462
- const perTurn = theme.fg("dim", `$${formatCost(stats.averageCostPerTurn)}/turn`);
615
+ const perTurn = paint.quiet(SPEND_TOKEN, `$${formatCost(stats.averageCostPerTurn)}/turn`);
463
616
  const contextLine = truncateToWidth(
464
617
  ` ${label("context")}${gauge} ${contextValue}${separator}${costText}${subLabel} ${perTurn}`,
465
618
  width,
466
619
  );
467
620
 
621
+ // A hit rate is a measurement, so it rides the ramp. The old cliff at 80%
622
+ // made 79% and 20% look identical and threw the reading away.
468
623
  const sessionHit = stats.sessionCacheHitRate;
469
- const sessionHitToken = sessionHit != null && sessionHit >= 80 ? "success" : "muted";
470
- const sessionHitText = sessionHit != null ? `${sessionHit.toFixed(1)}% session` : "no cache yet";
624
+ const sessionHitText = sessionHit != null
625
+ ? paint.ramp(CACHE_STOPS, sessionHit, `${sessionHit.toFixed(1)}% session`)
626
+ : theme.fg("dim", "no cache yet");
471
627
  const latestHit = stats.latestCacheHitRate;
472
628
  const latestText = stats.latestCacheMissTokens != null
473
- ? theme.fg("warning", `latest miss ${formatTokens(stats.latestCacheMissTokens)} re-billed`)
629
+ ? theme.fg("error", `latest miss ${formatTokens(stats.latestCacheMissTokens)} re-billed`)
474
630
  : latestHit != null
475
- ? theme.fg(latestHit >= 80 ? "success" : "muted", `latest ${latestHit.toFixed(1)}%`)
631
+ ? paint.ramp(CACHE_STOPS, latestHit, `latest ${latestHit.toFixed(1)}%`)
476
632
  : null;
477
- const reuseSplit = theme.fg("dim", `${formatTokens(stats.totalReused)} reused / ${formatTokens(stats.totalFresh)} new`);
478
- const cacheParts = [theme.fg(sessionHitToken, sessionHitText), latestText, reuseSplit].filter(Boolean);
633
+ const reuseSplit =
634
+ paint.ramp(CACHE_STOPS, sessionHit ?? 0, formatTokens(stats.totalReused)) +
635
+ theme.fg("dim", ` reused / ${formatTokens(stats.totalFresh)} new`);
636
+ const cacheParts = [sessionHitText, latestText, reuseSplit].filter(Boolean);
479
637
  const cacheLine = truncateToWidth(` ${label("cache")}${cacheParts.join(separator)}`, width);
480
638
 
481
639
  return [locationLine, contextLine, cacheLine];
@@ -484,28 +642,30 @@ export default function (pi: ExtensionAPI) {
484
642
  function renderFooterNarrow(
485
643
  width: number,
486
644
  theme: any,
645
+ paint: Painter,
487
646
  stats: SessionStats,
488
647
  pct: number,
489
648
  window: number,
490
- rgbTokens: RgbTokens,
491
649
  ): string[] {
492
650
  const cwd = currentCtx.cwd || ".";
493
651
  const locationParts: string[] = [];
494
652
  if (gitBranch) {
495
- const dirty = gitDirty ? theme.fg("warning", "*") : "";
496
- locationParts.push(`${theme.fg("accent", gitBranch)}${dirty}`);
653
+ const dirty = gitDirty ? paint.token(PLACE_TOKEN, "*") : "";
654
+ locationParts.push(`${paint.token(PLACE_TOKEN, gitBranch)}${dirty}`);
497
655
  }
498
- locationParts.push(theme.fg("text", `${currentDirectoryName(cwd)}/`));
656
+ // The pill earns its two columns most here: a split pane is where you are
657
+ // least sure which session you are looking at.
658
+ locationParts.push(theme.bg("selectedBg", paint.token(PLACE_TOKEN, theme.bold(` ${currentDirectoryName(cwd)}/ `))));
499
659
  const locationLine = truncateToWidth(` ${locationParts.join(NARROW_SEPARATOR)}`, width);
500
660
 
501
- const gauge = renderContextUsage(theme, pct, `${Math.round(pct)}%/${formatTokens(window)}`, rgbTokens);
661
+ const gauge = paint.ramp(CONTEXT_STOPS, pct, `${Math.round(pct)}%/${formatTokens(window)}`);
502
662
  const latestHit = stats.latestCacheHitRate;
503
663
  const cache = stats.latestCacheMissTokens != null
504
- ? theme.fg("warning", `miss ${formatTokens(stats.latestCacheMissTokens)}`)
664
+ ? theme.fg("error", `miss ${formatTokens(stats.latestCacheMissTokens)}`)
505
665
  : latestHit != null
506
- ? theme.fg("muted", `latest ${Math.round(latestHit)}%`)
666
+ ? paint.ramp(CACHE_STOPS, latestHit, `latest ${Math.round(latestHit)}%`)
507
667
  : "";
508
- const cost = theme.fg("warning", `$${formatCost(stats.totalCost)}`);
668
+ const cost = paint.token(SPEND_TOKEN, `$${formatCost(stats.totalCost)}`);
509
669
  const dataLine = truncateToWidth(` ${[gauge, cache, cost].filter(Boolean).join(NARROW_SEPARATOR)}`, width);
510
670
 
511
671
  return [locationLine, dataLine];
@@ -577,11 +737,11 @@ export default function (pi: ExtensionAPI) {
577
737
 
578
738
  ctx.ui.setWidget(
579
739
  "custom-footer-above",
580
- (_tui: any, theme: any) => ({
740
+ (tui: TUI, theme: Theme) => ({
581
741
  dispose() {},
582
742
  invalidate() {},
583
743
  render(width: number): string[] {
584
- return renderAbove(width, theme);
744
+ return renderAbove(width, tui.terminal.rows, theme);
585
745
  },
586
746
  }),
587
747
  { placement: "aboveEditor" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-custom-footer",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Context, cache, cost, and loaded skills at a glance in Pi.",
5
5
  "type": "module",
6
6
  "license": "MIT",