@giladbarnea/pi-custom-footer 0.1.5 → 0.1.7

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 +5 -1
  2. package/index.ts +35 -38
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ ---
2
+ last_updated: 2026-10-29T12-05
3
+ ---
4
+
1
5
  <div align="center">
2
6
 
3
7
  # Custom Footer
@@ -27,7 +31,7 @@ Below the editor, see:
27
31
 
28
32
  The layout follows your Pi theme. The header and the footer each take the fewest lines they can. To fit, they first drop labels, round readings, remove whitespace, and drop the branch icon. Only then does the footer hide facts: the reused/new split, the session hit rate, the token counts, and last the cost per turn.
29
33
 
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.
34
+ Skills get one row for every eight terminal rows past the first six, with a minimum of one. A 21-row phone screen gets one row, a 27-row screen two, and a 34-row screen three. To fit, the row first drops token ages, then separators, then shortens long names in the middle (`caut…ctor`). Only then does it hide skills from the end, behind a `+N` count at the end of the last row.
31
35
 
32
36
  **Resize without rescanning the conversation.** The header and footer share cached values. Session changes refresh them, including forks and compaction.
33
37
 
package/index.ts CHANGED
@@ -3,15 +3,16 @@
3
3
  *
4
4
  * Skill row. Each loaded skill shows its name and its token age: how far the
5
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:
6
+ * how deep in the context the skill now sits. Skills get one row for every
7
+ * eight terminal rows past the first six, rounded down, with a minimum of one.
8
+ * When they do not fit, the row gives up the least important thing left:
9
9
  * 1. The token ages.
10
10
  * 2. The separators between skills.
11
11
  * 3. The middle of the longest names, one character per step, down to four
12
12
  * characters on each side of the ellipsis. Names shorter than ten
13
13
  * characters never change.
14
- * 4. Last, three rows in the most compact layout plus a "+N skills" count.
14
+ * 4. Last, hide skills from the end behind a "+N" count that ends the
15
+ * last row.
15
16
  * Knowing which skills are loaded matters more than any detail about them, so
16
17
  * hiding a skill is the last resort. The Claude Code status line in
17
18
  * ~/.claude/statusline.sh uses the same order.
@@ -31,9 +32,13 @@ import { getLoadedSkills, type SkillLocation } from "./skill-tracker.ts";
31
32
 
32
33
  // ── Layout constants ────────────────────────────────────────────────────────
33
34
 
34
- const SHORT_TERMINAL_HEIGHT = 40;
35
- const SKILL_COLLAPSE_ROW_THRESHOLD = 4;
36
- const COLLAPSED_SKILL_ROWS = 3;
35
+ // The skill-row limit reads only the terminal height, never the todo list, editor or other widgets: predictable, and no measuring loop with taller-editor.
36
+ // Accepted cost: when a short screen and a long todo list overflow Pi's stack, Pi cuts the skill rows first, rather than us measuring Pi's internal layout.
37
+ // Calibrated on a phone over SSH: 21 terminal rows give one skill row, 22 to
38
+ // 29 give two, and 30 to 37 give three.
39
+ const MINIMUM_SKILL_ROWS = 1;
40
+ const TERMINAL_ROWS_BEFORE_SKILL_ROWS = 6;
41
+ const TERMINAL_ROWS_PER_SKILL_ROW = 8;
37
42
  // A truncated name keeps four characters on each side of the ellipsis.
38
43
  const MIN_TRUNCATED_NAME_LENGTH = 9;
39
44
  const NARROW_SEPARATOR = " ";
@@ -175,17 +180,12 @@ function wrapParts(parts: string[], width: number, separator: string): string[][
175
180
  return lines;
176
181
  }
177
182
 
178
- type WrappedLine = { text: string; partCount: number };
179
-
180
- /** Wrap whole parts and retain the number of parts in each row.
183
+ /** Wrap whole parts into joined lines that fit the width.
181
184
  * @example
182
- * wrapJoinedLines(["one", "two"], 6, " · ") // [{ text: " one", partCount: 1 }, { text: " two", partCount: 1 }]
185
+ * wrapJoinedLines(["one", "two"], 6, " · ") // [" one", " two"]
183
186
  */
184
- function wrapJoinedLines(parts: string[], width: number, separator: string): WrappedLine[] {
185
- return wrapParts(parts, width, separator).map((lineParts) => ({
186
- text: truncateToWidth(joinedLine(lineParts, separator), width),
187
- partCount: lineParts.length,
188
- }));
187
+ function wrapJoinedLines(parts: string[], width: number, separator: string): string[] {
188
+ return wrapParts(parts, width, separator).map((lineParts) => truncateToWidth(joinedLine(lineParts, separator), width));
189
189
  }
190
190
 
191
191
  /** Pack rows onto lines. Rows share a line when they fit, and a row breaks only
@@ -195,7 +195,7 @@ function wrapJoinedLines(parts: string[], width: number, separator: string): Wra
195
195
  */
196
196
  function packRows(rows: string[][], width: number, separator: string): string[] {
197
197
  const rowLines = rows.flatMap((row) => wrapParts(row, width, separator).map((lineParts) => lineParts.join(separator)));
198
- return wrapJoinedLines(rowLines, width, separator).map((line) => line.text);
198
+ return wrapJoinedLines(rowLines, width, separator);
199
199
  }
200
200
 
201
201
  /** The ladder's fullest state among those that pack the facts onto the fewest lines.
@@ -639,30 +639,27 @@ export default function (pi: ExtensionAPI) {
639
639
  };
640
640
  // No background here: the cwd pill is the one filled element in the whole
641
641
  // footer, and a second pill style would leave neither of them the anchor.
642
- const renderSkillLines = (layout: SkillLayout) => wrapJoinedLines(
643
- loadedSkills.map(({ name, tokenAge }) => {
644
- const nameText = paint.token(SKILL_TOKEN, middleTruncate(name, layout.maxNameLength));
645
- const ageText = layout.ages && tokenAge !== null ? theme.fg("dim", ` -${formatTokens(tokenAge)}`) : "";
646
- return `${nameText}${ageText}`;
647
- }),
648
- width,
649
- theme.fg("dim", layout.separator),
650
- );
651
- // A short terminal takes the fullest layout that fits the row limit. Hiding
652
- // skills behind a count is the last resort, after the most compact layout.
653
- const shortTerminal = terminalHeight <= SHORT_TERMINAL_HEIGHT;
642
+ const skillParts = (layout: SkillLayout) => loadedSkills.map(({ name, tokenAge }) => {
643
+ const nameText = paint.token(SKILL_TOKEN, middleTruncate(name, layout.maxNameLength));
644
+ const ageText = layout.ages && tokenAge !== null ? theme.fg("dim", ` -${formatTokens(tokenAge)}`) : "";
645
+ return `${nameText}${ageText}`;
646
+ });
647
+ const renderSkillLines = (parts: string[], layout: SkillLayout) => wrapJoinedLines(parts, width, theme.fg("dim", layout.separator));
648
+ // Take the fullest layout that fits the row limit. Hiding skills behind a
649
+ // count is the last resort, after the most compact layout. The count ends
650
+ // the last row, so even a one-row limit still names some skills.
651
+ const maximumSkillRows = Math.max(MINIMUM_SKILL_ROWS, Math.floor((terminalHeight - TERMINAL_ROWS_BEFORE_SKILL_ROWS) / TERMINAL_ROWS_PER_SKILL_ROW));
654
652
  const layouts = skillLayouts(Math.max(0, ...loadedSkills.map(({ name }) => name.length)));
655
- const candidates = shortTerminal ? layouts : layouts.slice(0, 1);
656
- const layout = candidates.find((candidate) => renderSkillLines(candidate).length <= SKILL_COLLAPSE_ROW_THRESHOLD) ?? candidates.at(-1)!;
657
- const skillLines = renderSkillLines(layout);
658
- const collapseSkills = shortTerminal && skillLines.length > SKILL_COLLAPSE_ROW_THRESHOLD;
659
- const visibleSkillLines = collapseSkills ? skillLines.slice(0, COLLAPSED_SKILL_ROWS) : skillLines;
660
- const hiddenSkillCount = skillLines.slice(visibleSkillLines.length).reduce((count, line) => count + line.partCount, 0);
661
- const overflowLines = hiddenSkillCount === 0 ? [] : [truncateToWidth(theme.fg("dim", ` +${hiddenSkillCount} skills`), width)];
653
+ const layout = layouts.find((candidate) => renderSkillLines(skillParts(candidate), candidate).length <= maximumSkillRows) ?? layouts.at(-1)!;
654
+ const parts = skillParts(layout);
655
+ const partsHiding = (hiddenCount: number) => hiddenCount === 0
656
+ ? parts
657
+ : [...parts.slice(0, parts.length - hiddenCount), theme.fg("dim", `+${hiddenCount}`)];
658
+ const hiddenSkillCount = Array.from({ length: parts.length + 1 }, (_, count) => count)
659
+ .find((count) => renderSkillLines(partsHiding(count), layout).length <= maximumSkillRows)!;
662
660
  return [
663
661
  ...fitFacts(headerFacts, HEADER_LADDER, width, theme),
664
- ...visibleSkillLines.map((line) => line.text),
665
- ...overflowLines,
662
+ ...renderSkillLines(partsHiding(hiddenSkillCount), layout),
666
663
  ];
667
664
  }
668
665
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-custom-footer",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Context, cache, cost, and loaded skills at a glance in Pi.",
5
5
  "type": "module",
6
6
  "license": "MIT",