@giladbarnea/pi-custom-footer 0.1.6 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- last_updated: 2026-10-26T15-03
2
+ last_updated: 2026-11-06T23-44
3
3
  ---
4
4
 
5
5
  <div align="center">
@@ -20,7 +20,9 @@ A Pi footer that puts your session’s context, cache usage, cost, and loaded sk
20
20
  pi install npm:@giladbarnea/pi-custom-footer
21
21
  ```
22
22
 
23
- Above the editor, see your model, thinking level, session name and ID. Loaded skills get their own row, with token ages.
23
+ Supports Pi 1.4.x and 1.5.x, the latest stable minor and its predecessor.
24
+
25
+ Above the editor, see your model, thinking level, session name and ID. Loaded skills get their own row, with token ages. Compaction and context edits remove skills whose loaded text is no longer present verbatim. Restoring that text restores the skill.
24
26
 
25
27
  Below the editor, see:
26
28
 
@@ -31,7 +33,7 @@ Below the editor, see:
31
33
 
32
34
  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.
33
35
 
34
- Skills get up to 10% of the terminal's rows, rounded to the nearest row with a minimum of two. To fit, the row first drops token ages, then separators, then shortens long names in the middle (`caut…ctor`). Only then does it reserve the final row for a hidden-skill count.
36
+ 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.
35
37
 
36
38
  **Resize without rescanning the conversation.** The header and footer share cached values. Session changes refresh them, including forks and compaction.
37
39
 
@@ -45,4 +47,4 @@ npm test
45
47
  npm run check
46
48
  ```
47
49
 
48
- Tests cover rendered values, skill tracking, cache reuse, session changes, and forks. They make no model calls.
50
+ Tests cover rendered values, skill tracking, cache reuse, session changes, forks, compaction, and native context edits. SDK tests use a local scripted provider, with no external model calls.
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. Skills get one tenth of the
7
- * terminal's rows, rounded to the nearest row with a minimum of two. When
8
- * they do not fit, the row gives up the least important thing left:
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, reserve the final row for 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.
@@ -24,15 +25,20 @@
24
25
  * or 200k, ignoring the known physical window from getContextUsage().
25
26
  */
26
27
  import type { AssistantMessage } from "@earendil-works/pi-ai";
27
- import type { ExtensionAPI, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
28
+ import type { ExtensionAPI, ExtensionContext, SessionEntry, Theme } from "@earendil-works/pi-coding-agent";
28
29
  import { truncateToWidth, visibleWidth, type TUI } from "@earendil-works/pi-tui";
29
30
 
30
31
  import { getLoadedSkills, type SkillLocation } from "./skill-tracker.ts";
31
32
 
32
33
  // ── Layout constants ────────────────────────────────────────────────────────
33
34
 
34
- const MINIMUM_SKILL_ROWS = 2;
35
- const TERMINAL_ROWS_PER_SKILL_ROW = 10;
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;
36
42
  // A truncated name keeps four characters on each side of the ellipsis.
37
43
  const MIN_TRUNCATED_NAME_LENGTH = 9;
38
44
  const NARROW_SEPARATOR = " ";
@@ -174,17 +180,12 @@ function wrapParts(parts: string[], width: number, separator: string): string[][
174
180
  return lines;
175
181
  }
176
182
 
177
- type WrappedLine = { text: string; partCount: number };
178
-
179
- /** Wrap whole parts and retain the number of parts in each row.
183
+ /** Wrap whole parts into joined lines that fit the width.
180
184
  * @example
181
- * wrapJoinedLines(["one", "two"], 6, " · ") // [{ text: " one", partCount: 1 }, { text: " two", partCount: 1 }]
185
+ * wrapJoinedLines(["one", "two"], 6, " · ") // [" one", " two"]
182
186
  */
183
- function wrapJoinedLines(parts: string[], width: number, separator: string): WrappedLine[] {
184
- return wrapParts(parts, width, separator).map((lineParts) => ({
185
- text: truncateToWidth(joinedLine(lineParts, separator), width),
186
- partCount: lineParts.length,
187
- }));
187
+ function wrapJoinedLines(parts: string[], width: number, separator: string): string[] {
188
+ return wrapParts(parts, width, separator).map((lineParts) => truncateToWidth(joinedLine(lineParts, separator), width));
188
189
  }
189
190
 
190
191
  /** Pack rows onto lines. Rows share a line when they fit, and a row breaks only
@@ -194,7 +195,7 @@ function wrapJoinedLines(parts: string[], width: number, separator: string): Wra
194
195
  */
195
196
  function packRows(rows: string[][], width: number, separator: string): string[] {
196
197
  const rowLines = rows.flatMap((row) => wrapParts(row, width, separator).map((lineParts) => lineParts.join(separator)));
197
- return wrapJoinedLines(rowLines, width, separator).map((line) => line.text);
198
+ return wrapJoinedLines(rowLines, width, separator);
198
199
  }
199
200
 
200
201
  /** The ladder's fullest state among those that pack the facts onto the fewest lines.
@@ -488,7 +489,7 @@ interface SessionStats {
488
489
  lastContextTokens: number; // input+output+cacheRead+cacheWrite of the last valid turn
489
490
  }
490
491
 
491
- function getSessionStats(ctx: any): SessionStats {
492
+ function getSessionStats(branch: readonly SessionEntry[]): SessionStats {
492
493
  let turnCount = 0;
493
494
  let totalCost = 0;
494
495
  let totalReused = 0;
@@ -498,7 +499,7 @@ function getSessionStats(ctx: any): SessionStats {
498
499
  let cacheWasReported = false;
499
500
  let latestCacheHitRate: number | null = null;
500
501
  let latestCacheMissTokens: number | null = null;
501
- for (const entry of ctx.sessionManager?.getBranch?.() ?? []) {
502
+ for (const entry of branch) {
502
503
  if (entry.type === "compaction" || entry.type === "branch_summary") {
503
504
  previousPromptTokens = null;
504
505
  cacheWasReported = false;
@@ -586,13 +587,14 @@ export default function (pi: ExtensionAPI) {
586
587
  let thinkingLevel = "off";
587
588
  let loadedSkills: Array<{ name: string; tokenAge: number | null }> = [];
588
589
  let skillsDirty = true;
590
+ let skillContextChangeId: string | undefined;
589
591
  let snapshot: FooterSnapshot | undefined;
590
592
 
591
593
  // ── Rendering ────────────────────────────────────────────────────────
592
594
 
593
- function refreshLoadedSkills(ctx: any, currentContextTokens: number | null): void {
595
+ function refreshLoadedSkills(ctx: ExtensionContext, currentContextTokens: number | null): void {
594
596
  loadedSkills = getLoadedSkills(
595
- ctx.sessionManager.buildSessionContext().messages,
597
+ ctx.sessionManager.buildSessionProjection().entries,
596
598
  getSkillLocations(pi),
597
599
  ctx.cwd,
598
600
  ).map(({ name, loadedAtTokens }) => ({
@@ -610,9 +612,14 @@ export default function (pi: ExtensionAPI) {
610
612
  const leafId = manager.getLeafId();
611
613
  const model: ExtensionContext["model"] = currentCtx.model;
612
614
  if (snapshot && snapshot.manager === manager && snapshot.sessionId === sessionId && snapshot.leafId === leafId && snapshot.model === model) return snapshot;
613
- const stats = getSessionStats(currentCtx);
615
+ const branch = manager.getBranch();
616
+ const stats = getSessionStats(branch);
614
617
  const usage = currentCtx.getContextUsage();
615
- if (skillsDirty) refreshLoadedSkills(currentCtx, usage?.tokens ?? null);
618
+ // Boundary edits commit after turn_end, which may already have rendered the old projection.
619
+ const contextChangeId = branch.reduce<string | undefined>((latest, entry) =>
620
+ entry.type === "context_edit" || entry.type === "compaction" ? entry.id : latest, undefined);
621
+ if (skillsDirty || contextChangeId !== skillContextChangeId) refreshLoadedSkills(currentCtx, usage?.tokens ?? null);
622
+ skillContextChangeId = contextChangeId;
616
623
  skillsDirty = false;
617
624
  snapshot = {
618
625
  manager, sessionId, leafId, model, stats,
@@ -638,28 +645,27 @@ export default function (pi: ExtensionAPI) {
638
645
  };
639
646
  // No background here: the cwd pill is the one filled element in the whole
640
647
  // footer, and a second pill style would leave neither of them the anchor.
641
- const renderSkillLines = (layout: SkillLayout) => wrapJoinedLines(
642
- 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
- width,
648
- theme.fg("dim", layout.separator),
649
- );
648
+ const skillParts = (layout: SkillLayout) => loadedSkills.map(({ name, tokenAge }) => {
649
+ const nameText = paint.token(SKILL_TOKEN, middleTruncate(name, layout.maxNameLength));
650
+ const ageText = layout.ages && tokenAge !== null ? theme.fg("dim", ` -${formatTokens(tokenAge)}`) : "";
651
+ return `${nameText}${ageText}`;
652
+ });
653
+ const renderSkillLines = (parts: string[], layout: SkillLayout) => wrapJoinedLines(parts, width, theme.fg("dim", layout.separator));
650
654
  // Take the fullest layout that fits the row limit. Hiding skills behind a
651
- // count is the last resort, after the most compact layout.
652
- const maximumSkillRows = Math.max(MINIMUM_SKILL_ROWS, Math.round(terminalHeight / TERMINAL_ROWS_PER_SKILL_ROW));
655
+ // count is the last resort, after the most compact layout. The count ends
656
+ // the last row, so even a one-row limit still names some skills.
657
+ const maximumSkillRows = Math.max(MINIMUM_SKILL_ROWS, Math.floor((terminalHeight - TERMINAL_ROWS_BEFORE_SKILL_ROWS) / TERMINAL_ROWS_PER_SKILL_ROW));
653
658
  const layouts = skillLayouts(Math.max(0, ...loadedSkills.map(({ name }) => name.length)));
654
- const layout = layouts.find((candidate) => renderSkillLines(candidate).length <= maximumSkillRows) ?? layouts.at(-1)!;
655
- const skillLines = renderSkillLines(layout);
656
- const visibleSkillLines = skillLines.length > maximumSkillRows ? skillLines.slice(0, maximumSkillRows - 1) : skillLines;
657
- const hiddenSkillCount = skillLines.slice(visibleSkillLines.length).reduce((count, line) => count + line.partCount, 0);
658
- const overflowLines = hiddenSkillCount === 0 ? [] : [truncateToWidth(theme.fg("dim", ` +${hiddenSkillCount} skills`), width)];
659
+ const layout = layouts.find((candidate) => renderSkillLines(skillParts(candidate), candidate).length <= maximumSkillRows) ?? layouts.at(-1)!;
660
+ const parts = skillParts(layout);
661
+ const partsHiding = (hiddenCount: number) => hiddenCount === 0
662
+ ? parts
663
+ : [...parts.slice(0, parts.length - hiddenCount), theme.fg("dim", `+${hiddenCount}`)];
664
+ const hiddenSkillCount = Array.from({ length: parts.length + 1 }, (_, count) => count)
665
+ .find((count) => renderSkillLines(partsHiding(count), layout).length <= maximumSkillRows)!;
659
666
  return [
660
667
  ...fitFacts(headerFacts, HEADER_LADDER, width, theme),
661
- ...visibleSkillLines.map((line) => line.text),
662
- ...overflowLines,
668
+ ...renderSkillLines(partsHiding(hiddenSkillCount), layout),
663
669
  ];
664
670
  }
665
671
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@giladbarnea/pi-custom-footer",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Context, cache, cost, and loaded skills at a glance in Pi.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -28,16 +28,16 @@
28
28
  "LICENSE"
29
29
  ],
30
30
  "scripts": {
31
- "test": "node tests/skills.mjs && node tests/cache.mjs && node tests/layout.mjs && node tests/load.mjs",
31
+ "test": "node tests/skills.mjs && node tests/cache.mjs && node tests/layout.mjs && node tests/load.mjs && node --test tests/context.mjs",
32
32
  "check": "tsc --noEmit"
33
33
  },
34
34
  "engines": {
35
35
  "node": ">=22.19.0"
36
36
  },
37
37
  "peerDependencies": {
38
- "@earendil-works/pi-ai": ">=0.84.2",
39
- "@earendil-works/pi-coding-agent": ">=0.84.2",
40
- "@earendil-works/pi-tui": ">=0.84.2"
38
+ "@earendil-works/pi-ai": ">=1.4.0",
39
+ "@earendil-works/pi-coding-agent": ">=1.4.0",
40
+ "@earendil-works/pi-tui": ">=1.4.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@earendil-works/pi-ai": "1.4.0",
package/skill-tracker.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { ProjectedSessionEntry } from "@earendil-works/pi-coding-agent";
1
2
  import { homedir } from "node:os";
2
3
  import { resolve } from "node:path";
3
4
 
@@ -37,8 +38,10 @@ function isValidSkillName(name: string): boolean {
37
38
  return name.length <= MAX_SKILL_NAME_LENGTH && SKILL_NAME_PATTERN.test(name);
38
39
  }
39
40
 
40
- function expandedSkillNames(content: unknown): string[] {
41
- return [...textFromContent(content).matchAll(/<skill name="([^"]+)" location="[^"]+">/g)]
41
+ function expandedSkillNames(content: unknown, originalContent: unknown): string[] {
42
+ const text = textFromContent(content);
43
+ return [...textFromContent(originalContent).matchAll(/<skill name="([^"]+)" location="[^"]+">[\s\S]*?<\/skill>/g)]
44
+ .filter((match) => text.includes(match[0]))
42
45
  .map((match) => match[1]!)
43
46
  .filter(isValidSkillName);
44
47
  }
@@ -74,17 +77,21 @@ function latestCompactionTimestamp(history: readonly unknown[]): number | null {
74
77
  }
75
78
 
76
79
  /**
77
- * Return skills in the effective model history with their first valid post-load prompt size.
80
+ * Return skills whose loaded text survives verbatim in Pi's projection, with their first valid post-load prompt size.
78
81
  *
79
82
  * @example
80
83
  * getLoadedSkills([], [], "/workspace") // []
81
84
  */
82
85
  export function getLoadedSkills(
83
- history: readonly unknown[],
86
+ entries: readonly ProjectedSessionEntry[],
84
87
  skills: readonly SkillLocation[],
85
88
  cwd: string,
86
89
  ): LoadedSkill[] {
87
- const compactionTimestamp = latestCompactionTimestamp(history);
90
+ const history: Array<{ message: unknown; originalContent: unknown }> = entries.flatMap(({ sourceEntry, messages }) => messages.map((message) => ({
91
+ message,
92
+ originalContent: sourceEntry.type === "message" && "content" in sourceEntry.message ? sourceEntry.message.content : undefined,
93
+ })));
94
+ const compactionTimestamp = latestCompactionTimestamp(history.map(({ message }) => message));
88
95
  const loadedSkills = new Map<string, number | null>();
89
96
  const pendingBaselines = new Set<string>();
90
97
  const skillNamesByToolCall = new Map<string, string[]>();
@@ -94,16 +101,17 @@ export function getLoadedSkills(
94
101
  pendingBaselines.add(skillName);
95
102
  };
96
103
 
97
- for (const message of history) {
104
+ for (const { message, originalContent } of history) {
98
105
  if (!isRecord(message)) continue;
99
106
 
100
107
  if (message.role === "user") {
101
- for (const skillName of expandedSkillNames(message.content)) markLoaded(skillName);
108
+ for (const skillName of expandedSkillNames(message.content, originalContent)) markLoaded(skillName);
102
109
  continue;
103
110
  }
104
111
 
105
112
  if (message.role === "toolResult") {
106
113
  if (message.isError !== false || typeof message.toolCallId !== "string") continue;
114
+ if (!textFromContent(message.content).includes(textFromContent(originalContent))) continue;
107
115
  for (const skillName of skillNamesByToolCall.get(message.toolCallId) ?? []) markLoaded(skillName);
108
116
  continue;
109
117
  }