@giladbarnea/pi-custom-footer 0.1.8 → 0.1.9
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 +2 -2
- package/index.ts +20 -4
- package/package.json +1 -1
- package/skill-tracker.ts +63 -2
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
last_updated: 2026-11-
|
|
2
|
+
last_updated: 2026-11-07T17-30
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
<div align="center">
|
|
@@ -22,7 +22,7 @@ pi install npm:@giladbarnea/pi-custom-footer
|
|
|
22
22
|
|
|
23
23
|
Supports Pi 1.4.x and 1.5.x, the latest stable minor and its predecessor.
|
|
24
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.
|
|
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. A skill read inside a codemode script counts when the script output carries that read verbatim. Pi does not keep nested read results, so the footer records the read text in a custom session entry that is never sent to the model.
|
|
26
26
|
|
|
27
27
|
Below the editor, see:
|
|
28
28
|
|
package/index.ts
CHANGED
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
*
|
|
20
20
|
* Known gaps reviewed September 30, 2026, against Pi 0.99.0:
|
|
21
21
|
* - Costs omit codemode and nested-model usage recorded on tool results.
|
|
22
|
-
* - Loaded skills omit successful reads recorded in tool-result nestedCalls
|
|
22
|
+
* - Loaded skills omit successful reads recorded in tool-result nestedCalls
|
|
23
|
+
* that ran without this extension, which records their returned text.
|
|
23
24
|
* - The header omits the routed physical model and thinking level.
|
|
24
25
|
* - After compaction, unknown usage falls back to the selected model's window
|
|
25
26
|
* or 200k, ignoring the known physical window from getContextUsage().
|
|
@@ -28,7 +29,10 @@ import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
|
28
29
|
import type { ExtensionAPI, ExtensionContext, SessionEntry, Theme } from "@earendil-works/pi-coding-agent";
|
|
29
30
|
import { truncateToWidth, visibleWidth, type TUI } from "@earendil-works/pi-tui";
|
|
30
31
|
|
|
31
|
-
import {
|
|
32
|
+
import {
|
|
33
|
+
getLoadedSkills, isNestedSkillRead, NESTED_SKILL_READ_ENTRY, nestedReadText, nestedSkillReadTexts,
|
|
34
|
+
type NestedSkillRead, type SkillLocation,
|
|
35
|
+
} from "./skill-tracker.ts";
|
|
32
36
|
|
|
33
37
|
// ── Layout constants ────────────────────────────────────────────────────────
|
|
34
38
|
|
|
@@ -586,17 +590,19 @@ export default function (pi: ExtensionAPI) {
|
|
|
586
590
|
let gitDirty = false;
|
|
587
591
|
let thinkingLevel = "off";
|
|
588
592
|
let loadedSkills: Array<{ name: string; tokenAge: number | null }> = [];
|
|
593
|
+
const runningNestedSkillReads = new Set<string>();
|
|
589
594
|
let skillsDirty = true;
|
|
590
595
|
let skillContextChangeId: string | undefined;
|
|
591
596
|
let snapshot: FooterSnapshot | undefined;
|
|
592
597
|
|
|
593
598
|
// ── Rendering ────────────────────────────────────────────────────────
|
|
594
599
|
|
|
595
|
-
function refreshLoadedSkills(ctx: ExtensionContext, currentContextTokens: number | null): void {
|
|
600
|
+
function refreshLoadedSkills(ctx: ExtensionContext, branch: readonly SessionEntry[], currentContextTokens: number | null): void {
|
|
596
601
|
loadedSkills = getLoadedSkills(
|
|
597
602
|
ctx.sessionManager.buildSessionProjection().entries,
|
|
598
603
|
getSkillLocations(pi),
|
|
599
604
|
ctx.cwd,
|
|
605
|
+
nestedSkillReadTexts(branch),
|
|
600
606
|
).map(({ name, loadedAtTokens }) => ({
|
|
601
607
|
name,
|
|
602
608
|
tokenAge:
|
|
@@ -618,7 +624,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
618
624
|
// Boundary edits commit after turn_end, which may already have rendered the old projection.
|
|
619
625
|
const contextChangeId = branch.reduce<string | undefined>((latest, entry) =>
|
|
620
626
|
entry.type === "context_edit" || entry.type === "compaction" ? entry.id : latest, undefined);
|
|
621
|
-
if (skillsDirty || contextChangeId !== skillContextChangeId) refreshLoadedSkills(currentCtx, usage?.tokens ?? null);
|
|
627
|
+
if (skillsDirty || contextChangeId !== skillContextChangeId) refreshLoadedSkills(currentCtx, branch, usage?.tokens ?? null);
|
|
622
628
|
skillContextChangeId = contextChangeId;
|
|
623
629
|
skillsDirty = false;
|
|
624
630
|
snapshot = {
|
|
@@ -804,10 +810,20 @@ export default function (pi: ExtensionAPI) {
|
|
|
804
810
|
gitBranch = null;
|
|
805
811
|
gitDirty = false;
|
|
806
812
|
loadedSkills = [];
|
|
813
|
+
runningNestedSkillReads.clear();
|
|
807
814
|
snapshot = undefined;
|
|
808
815
|
skillsDirty = true;
|
|
809
816
|
});
|
|
810
817
|
|
|
818
|
+
pi.on("tool_execution_start", async (event, ctx) => {
|
|
819
|
+
if (isNestedSkillRead(event, getSkillLocations(pi), ctx.cwd)) runningNestedSkillReads.add(event.toolCallId);
|
|
820
|
+
});
|
|
821
|
+
pi.on("tool_execution_end", async (event) => {
|
|
822
|
+
if (!runningNestedSkillReads.delete(event.toolCallId)) return;
|
|
823
|
+
const readText = nestedReadText(event);
|
|
824
|
+
if (readText !== null) pi.appendEntry<NestedSkillRead>(NESTED_SKILL_READ_ENTRY, { toolCallId: event.toolCallId, text: readText });
|
|
825
|
+
});
|
|
826
|
+
|
|
811
827
|
pi.on("model_select", async (_event: any, ctx: any) => updateCtx(ctx));
|
|
812
828
|
pi.on("thinking_level_select", async (event: any) => {
|
|
813
829
|
thinkingLevel = event.level;
|
package/package.json
CHANGED
package/skill-tracker.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ProjectedSessionEntry } from "@earendil-works/pi-coding-agent";
|
|
1
|
+
import type { ProjectedSessionEntry, SessionEntry, ToolExecutionEndEvent, ToolExecutionStartEvent } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
|
|
@@ -12,6 +12,14 @@ export type LoadedSkill = {
|
|
|
12
12
|
name: string;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
/** A successful nested skill read's returned text, kept as a custom session entry because Pi does not persist nested results. */
|
|
16
|
+
export type NestedSkillRead = {
|
|
17
|
+
toolCallId: string;
|
|
18
|
+
text: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const NESTED_SKILL_READ_ENTRY = "custom-footer-nested-skill-read";
|
|
22
|
+
|
|
15
23
|
type UnknownRecord = Record<string, unknown>;
|
|
16
24
|
|
|
17
25
|
const MAX_SKILL_NAME_LENGTH = 64;
|
|
@@ -59,6 +67,57 @@ function skillNamesForReadPath(rawPath: string, skills: readonly SkillLocation[]
|
|
|
59
67
|
return skills.flatMap((skill) => path === resolvePath(cwd, skill.filePath) ? [skill.name] : []);
|
|
60
68
|
}
|
|
61
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Whether a starting tool call is a nested skill read, such as one from a codemode script.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* isNestedSkillRead({ type: "tool_execution_start", toolCallId: "c/1", toolName: "read", args: { path: "/s/SKILL.md" }, parentToolCallId: "c" }, [{ name: "s", filePath: "/s/SKILL.md" }], "/") // true
|
|
75
|
+
*/
|
|
76
|
+
export function isNestedSkillRead(event: ToolExecutionStartEvent, skills: readonly SkillLocation[], cwd: string): boolean {
|
|
77
|
+
return event.parentToolCallId !== undefined && readPaths({ name: event.toolName, arguments: event.args })
|
|
78
|
+
.some((path) => skillNamesForReadPath(path, skills, cwd).length > 0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The text a successful nested read returned to its caller, to match against the parent result later.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* nestedReadText({ type: "tool_execution_end", toolCallId: "c/1", toolName: "read", result: { content: [{ type: "text", text: "Body." }] }, isError: false }) // "Body."
|
|
86
|
+
*/
|
|
87
|
+
export function nestedReadText(event: ToolExecutionEndEvent): string | null {
|
|
88
|
+
return event.isError ? null : textFromContent(event.result?.content);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Nested read texts recorded on a session branch, by nested tool call id.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* nestedSkillReadTexts([]) // Map(0) {}
|
|
96
|
+
*/
|
|
97
|
+
export function nestedSkillReadTexts(branch: readonly SessionEntry[]): Map<string, string> {
|
|
98
|
+
return new Map(branch.flatMap((entry) => {
|
|
99
|
+
if (entry.type !== "custom" || entry.customType !== NESTED_SKILL_READ_ENTRY) return [];
|
|
100
|
+
const { toolCallId, text } = entry.data as NestedSkillRead;
|
|
101
|
+
return [[toolCallId, text]];
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Skills whose nested read text, captured when the read succeeded, survives verbatim in the projected parent result. */
|
|
106
|
+
function deliveredNestedSkillNames(
|
|
107
|
+
message: UnknownRecord,
|
|
108
|
+
skills: readonly SkillLocation[],
|
|
109
|
+
cwd: string,
|
|
110
|
+
nestedReadTexts: ReadonlyMap<string, string>,
|
|
111
|
+
): string[] {
|
|
112
|
+
if (!isRecord(message.nestedCalls) || !Array.isArray(message.nestedCalls.calls)) return [];
|
|
113
|
+
const deliveredText = textFromContent(message.content);
|
|
114
|
+
return message.nestedCalls.calls.filter(isRecord).flatMap((call) => {
|
|
115
|
+
const readText = typeof call.id === "string" ? nestedReadTexts.get(call.id) : undefined;
|
|
116
|
+
if (readText === undefined || !deliveredText.includes(readText)) return [];
|
|
117
|
+
return readPaths(call).flatMap((path) => skillNamesForReadPath(path, skills, cwd));
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
62
121
|
function assistantPromptTokens(message: UnknownRecord, compactionTimestamp: number | null): number | null {
|
|
63
122
|
if (message.role !== "assistant" || message.stopReason === "error" || message.stopReason === "aborted") return null;
|
|
64
123
|
if (compactionTimestamp !== null && (typeof message.timestamp !== "number" || message.timestamp <= compactionTimestamp)) return null;
|
|
@@ -80,12 +139,13 @@ function latestCompactionTimestamp(history: readonly unknown[]): number | null {
|
|
|
80
139
|
* Return skills whose loaded text survives verbatim in Pi's projection, with their first valid post-load prompt size.
|
|
81
140
|
*
|
|
82
141
|
* @example
|
|
83
|
-
* getLoadedSkills([], [], "/workspace") // []
|
|
142
|
+
* getLoadedSkills([], [], "/workspace", new Map()) // []
|
|
84
143
|
*/
|
|
85
144
|
export function getLoadedSkills(
|
|
86
145
|
entries: readonly ProjectedSessionEntry[],
|
|
87
146
|
skills: readonly SkillLocation[],
|
|
88
147
|
cwd: string,
|
|
148
|
+
nestedReadTexts: ReadonlyMap<string, string>,
|
|
89
149
|
): LoadedSkill[] {
|
|
90
150
|
const history: Array<{ message: unknown; originalContent: unknown }> = entries.flatMap(({ sourceEntry, messages }) => messages.map((message) => ({
|
|
91
151
|
message,
|
|
@@ -110,6 +170,7 @@ export function getLoadedSkills(
|
|
|
110
170
|
}
|
|
111
171
|
|
|
112
172
|
if (message.role === "toolResult") {
|
|
173
|
+
for (const skillName of deliveredNestedSkillNames(message, skills, cwd, nestedReadTexts)) markLoaded(skillName);
|
|
113
174
|
if (message.isError !== false || typeof message.toolCallId !== "string") continue;
|
|
114
175
|
if (!textFromContent(message.content).includes(textFromContent(originalContent))) continue;
|
|
115
176
|
for (const skillName of skillNamesByToolCall.get(message.toolCallId) ?? []) markLoaded(skillName);
|