@giladbarnea/pi-custom-footer 0.1.7 → 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 +5 -3
- package/index.ts +13 -7
- package/package.json +5 -5
- package/skill-tracker.ts +15 -7
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
last_updated: 2026-
|
|
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
|
-
|
|
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
|
|
|
@@ -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
|
|
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
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* or 200k, ignoring the known physical window from getContextUsage().
|
|
26
26
|
*/
|
|
27
27
|
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
28
|
-
import type { ExtensionAPI, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
28
|
+
import type { ExtensionAPI, ExtensionContext, SessionEntry, Theme } from "@earendil-works/pi-coding-agent";
|
|
29
29
|
import { truncateToWidth, visibleWidth, type TUI } from "@earendil-works/pi-tui";
|
|
30
30
|
|
|
31
31
|
import { getLoadedSkills, type SkillLocation } from "./skill-tracker.ts";
|
|
@@ -489,7 +489,7 @@ interface SessionStats {
|
|
|
489
489
|
lastContextTokens: number; // input+output+cacheRead+cacheWrite of the last valid turn
|
|
490
490
|
}
|
|
491
491
|
|
|
492
|
-
function getSessionStats(
|
|
492
|
+
function getSessionStats(branch: readonly SessionEntry[]): SessionStats {
|
|
493
493
|
let turnCount = 0;
|
|
494
494
|
let totalCost = 0;
|
|
495
495
|
let totalReused = 0;
|
|
@@ -499,7 +499,7 @@ function getSessionStats(ctx: any): SessionStats {
|
|
|
499
499
|
let cacheWasReported = false;
|
|
500
500
|
let latestCacheHitRate: number | null = null;
|
|
501
501
|
let latestCacheMissTokens: number | null = null;
|
|
502
|
-
for (const entry of
|
|
502
|
+
for (const entry of branch) {
|
|
503
503
|
if (entry.type === "compaction" || entry.type === "branch_summary") {
|
|
504
504
|
previousPromptTokens = null;
|
|
505
505
|
cacheWasReported = false;
|
|
@@ -587,13 +587,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
587
587
|
let thinkingLevel = "off";
|
|
588
588
|
let loadedSkills: Array<{ name: string; tokenAge: number | null }> = [];
|
|
589
589
|
let skillsDirty = true;
|
|
590
|
+
let skillContextChangeId: string | undefined;
|
|
590
591
|
let snapshot: FooterSnapshot | undefined;
|
|
591
592
|
|
|
592
593
|
// ── Rendering ────────────────────────────────────────────────────────
|
|
593
594
|
|
|
594
|
-
function refreshLoadedSkills(ctx:
|
|
595
|
+
function refreshLoadedSkills(ctx: ExtensionContext, currentContextTokens: number | null): void {
|
|
595
596
|
loadedSkills = getLoadedSkills(
|
|
596
|
-
ctx.sessionManager.
|
|
597
|
+
ctx.sessionManager.buildSessionProjection().entries,
|
|
597
598
|
getSkillLocations(pi),
|
|
598
599
|
ctx.cwd,
|
|
599
600
|
).map(({ name, loadedAtTokens }) => ({
|
|
@@ -611,9 +612,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
611
612
|
const leafId = manager.getLeafId();
|
|
612
613
|
const model: ExtensionContext["model"] = currentCtx.model;
|
|
613
614
|
if (snapshot && snapshot.manager === manager && snapshot.sessionId === sessionId && snapshot.leafId === leafId && snapshot.model === model) return snapshot;
|
|
614
|
-
const
|
|
615
|
+
const branch = manager.getBranch();
|
|
616
|
+
const stats = getSessionStats(branch);
|
|
615
617
|
const usage = currentCtx.getContextUsage();
|
|
616
|
-
|
|
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;
|
|
617
623
|
skillsDirty = false;
|
|
618
624
|
snapshot = {
|
|
619
625
|
manager, sessionId, leafId, model, stats,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@giladbarnea/pi-custom-footer",
|
|
3
|
-
"version": "0.1.
|
|
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": ">=
|
|
39
|
-
"@earendil-works/pi-coding-agent": ">=
|
|
40
|
-
"@earendil-works/pi-tui": ">=
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
86
|
+
entries: readonly ProjectedSessionEntry[],
|
|
84
87
|
skills: readonly SkillLocation[],
|
|
85
88
|
cwd: string,
|
|
86
89
|
): LoadedSkill[] {
|
|
87
|
-
const
|
|
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
|
}
|