@ogulcancelik/pi-minimal-footer 0.1.14 → 0.1.15
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 -1
- package/index.ts +43 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ Minimal footer for [pi](https://github.com/earendil-works/pi) that replaces the
|
|
|
12
12
|
- **Subscription usage bars** — rolling window quotas with reset timers for supported providers
|
|
13
13
|
- **Shared usage cache** — all pi instances share one cached result per provider and account, so opening more sessions doesn't mean more quota API calls
|
|
14
14
|
- **Git integration** — branch name, dirty state, ahead/behind counts
|
|
15
|
+
- **Extension statuses** — text that other extensions set with `ctx.ui.setStatus()`, on its own line like pi's default footer
|
|
15
16
|
|
|
16
17
|
## Supported providers
|
|
17
18
|
|
|
@@ -46,7 +47,7 @@ Accepted false values: `0`, `false`, `no`, `off` (case-insensitive).
|
|
|
46
47
|
|
|
47
48
|
## How it works
|
|
48
49
|
|
|
49
|
-
The footer reads context usage from the
|
|
50
|
+
The footer reads context usage from pi's `ctx.getContextUsage()`, the same value as pi's default footer: the token counts of the last response, plus an estimate for the messages after it. After a compaction, pi does not know the new size until the next response, so the gauge shows `?/<window>`, like pi's default footer. Subscription usage is fetched from each provider's dedicated quota API using your existing auth tokens from Pi's agent directory (`~/.pi/agent/auth.json` by default) or environment variables.
|
|
50
51
|
|
|
51
52
|
Usage is cached in `~/.pi/agent/pi-minimal-footer/` and shared by every pi instance. Each instance re-reads the cache on startup, on model switch (Ctrl+P), and every 30 seconds. Only one instance fetches when the cache is older than 5 minutes. Failed fetches keep the last good numbers and retry after a minute, or after the provider's `retry-after` when rate-limited.
|
|
52
53
|
|
package/index.ts
CHANGED
|
@@ -48,6 +48,12 @@ interface GitCache {
|
|
|
48
48
|
behind: number;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
interface ContextInfo {
|
|
52
|
+
percentage: number | null;
|
|
53
|
+
used: number | null;
|
|
54
|
+
total: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
51
57
|
// ============ Usage Cache ============
|
|
52
58
|
|
|
53
59
|
// Usage is cached on disk and shared by every pi instance, so N open panes
|
|
@@ -121,10 +127,14 @@ function refreshGitCache(): boolean {
|
|
|
121
127
|
let next: GitCache | null = null;
|
|
122
128
|
|
|
123
129
|
try {
|
|
124
|
-
const status = execSync(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
130
|
+
const status = execSync(
|
|
131
|
+
"git status --porcelain=v2 --branch",
|
|
132
|
+
{
|
|
133
|
+
encoding: "utf8",
|
|
134
|
+
timeout: 1000,
|
|
135
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
136
|
+
},
|
|
137
|
+
);
|
|
128
138
|
next = parseGitStatus(status.trimEnd());
|
|
129
139
|
} catch {
|
|
130
140
|
next = null;
|
|
@@ -965,14 +975,15 @@ export default function (pi: ExtensionAPI) {
|
|
|
965
975
|
}
|
|
966
976
|
|
|
967
977
|
function renderContextGauge(
|
|
968
|
-
percentage: number,
|
|
978
|
+
percentage: number | null,
|
|
969
979
|
theme: any,
|
|
970
|
-
used?: number,
|
|
980
|
+
used?: number | null,
|
|
971
981
|
total?: number,
|
|
972
982
|
options?: { barWidth?: number; includeCounts?: boolean }
|
|
973
983
|
): string {
|
|
974
984
|
const barWidth = Math.max(4, options?.barWidth ?? CTX_GAUGE_WIDTH);
|
|
975
|
-
const
|
|
985
|
+
const known = percentage !== null;
|
|
986
|
+
const clamped = known ? Math.max(0, Math.min(100, percentage)) : 0;
|
|
976
987
|
const filled = Math.round((clamped / 100) * barWidth);
|
|
977
988
|
const empty = barWidth - filled;
|
|
978
989
|
|
|
@@ -983,11 +994,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
983
994
|
else color = "success";
|
|
984
995
|
|
|
985
996
|
const bar = theme.fg(color, BAR_FILLED.repeat(filled)) + theme.fg("dim", BAR_EMPTY.repeat(empty));
|
|
986
|
-
const pct = `${Math.round(clamped)}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
997
|
+
const pct = known ? `${Math.round(clamped)}%` : "?";
|
|
998
|
+
let counts = "";
|
|
999
|
+
if (options?.includeCounts !== false && total) {
|
|
1000
|
+
if (!known) counts = `/${formatTokenCount(total)}`;
|
|
1001
|
+
else if (used != null) counts = ` ${formatTokenCount(used)}/${formatTokenCount(total)}`;
|
|
1002
|
+
}
|
|
991
1003
|
|
|
992
1004
|
return theme.fg("dim", "ctx ") + bar + " " + theme.fg("dim", pct + counts);
|
|
993
1005
|
}
|
|
@@ -1042,6 +1054,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
1042
1054
|
return wrapFooterSegments(segments, width, sep);
|
|
1043
1055
|
}
|
|
1044
1056
|
|
|
1057
|
+
function renderExtensionStatuses(statuses: ReadonlyMap<string, string>): string {
|
|
1058
|
+
return Array.from(statuses.entries())
|
|
1059
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
1060
|
+
.map(([, text]) => text.replace(/[\r\n\t]/g, " ").replace(/ +/g, " ").trim())
|
|
1061
|
+
.filter(Boolean)
|
|
1062
|
+
.join(" ");
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1045
1065
|
function getThinkingLevel(ctx: any): string {
|
|
1046
1066
|
const entries = ctx.sessionManager.getEntries();
|
|
1047
1067
|
const leafId = ctx.sessionManager.getLeafId();
|
|
@@ -1049,7 +1069,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
1049
1069
|
return context.thinkingLevel || "off";
|
|
1050
1070
|
}
|
|
1051
1071
|
|
|
1052
|
-
function getContextInfo(ctx: any):
|
|
1072
|
+
function getContextInfo(ctx: any): ContextInfo {
|
|
1073
|
+
if (typeof ctx.getContextUsage !== "function") return getLastResponseContextInfo(ctx);
|
|
1074
|
+
const usage = ctx.getContextUsage();
|
|
1075
|
+
if (!usage) return { percentage: 0, used: 0, total: 0 };
|
|
1076
|
+
return { percentage: usage.percent, used: usage.tokens, total: usage.contextWindow };
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
function getLastResponseContextInfo(ctx: any): ContextInfo {
|
|
1053
1080
|
const model = ctx.model;
|
|
1054
1081
|
const contextWindow = model?.contextWindow ?? 0;
|
|
1055
1082
|
if (contextWindow === 0) return { percentage: 0, used: 0, total: 0 };
|
|
@@ -1249,6 +1276,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
1249
1276
|
lines.push(...renderUsageLine(latestUsage, width, theme));
|
|
1250
1277
|
}
|
|
1251
1278
|
|
|
1279
|
+
const statusLine = renderExtensionStatuses(footerData.getExtensionStatuses?.() ?? new Map());
|
|
1280
|
+
if (statusLine) lines.push(statusLine);
|
|
1281
|
+
|
|
1252
1282
|
return lines.map((line) => truncateToWidth(line, width));
|
|
1253
1283
|
},
|
|
1254
1284
|
};
|