@bismawy/pi-arnative 0.6.1 → 0.6.2
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/CHANGELOG.md +8 -0
- package/extensions/footer.ts +13 -1
- package/lib/usage-store.ts +8 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.6.2] - 2026-10-20
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- **The usage cache no longer loses another session's rollup.** `saveDiskCache` wrote its whole in-memory map, so of two pi sessions sharing one agent dir the later writer dropped the entries the other had cached for its own files. It now re-reads the disk cache before the rename and keeps the keys this session does not have — only while their session file still exists, so a prune done by this scan stays pruned (`lib/usage-store.ts`).
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- **The footer cache cell falls back to pi's own usage.** `pi-cache-optimizer` only reports providers it has an adapter for; a provider it does not recognize (a custom one such as `hark.ts`) publishes no `pi-cache-stats` status and the cell stayed empty. It now shows `pi X%`, computed as `cacheRead / (input + cacheRead)` from the usage pi already records on the branch — the optimizer's own string still wins when present (`extensions/footer.ts`).
|
|
10
|
+
|
|
3
11
|
## [0.6.1] - 2026-10-19
|
|
4
12
|
|
|
5
13
|
### Fixed
|
package/extensions/footer.ts
CHANGED
|
@@ -598,6 +598,14 @@ function parseOptimizer(raw: string | undefined): string | null {
|
|
|
598
598
|
return m ? `${m[1]} ${m[2]} (${m[3]})` : null;
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
+
// Pi's own per-message usage: shown when pi-cache-optimizer has no adapter for the
|
|
602
|
+
// provider (a custom one like hark.ts publishes no pi-cache-stats status).
|
|
603
|
+
let usageTotals = { inp: 0, read: 0 };
|
|
604
|
+
export function piCacheHit(): string | null {
|
|
605
|
+
const total = usageTotals.inp + usageTotals.read;
|
|
606
|
+
return total > 0 ? "pi " + ((usageTotals.read / total) * 100).toFixed(1) + "%" : null;
|
|
607
|
+
}
|
|
608
|
+
|
|
601
609
|
let usageScanAt = 0;
|
|
602
610
|
let usageScanLen = -1;
|
|
603
611
|
let usageScanNums = { inp: 0, out: 0, read: 0 };
|
|
@@ -650,6 +658,7 @@ export function getUsage(
|
|
|
650
658
|
usageScanAt = Date.now();
|
|
651
659
|
usageScanLen = branch.length;
|
|
652
660
|
}
|
|
661
|
+
usageTotals = { inp, read };
|
|
653
662
|
const parts: string[] = [];
|
|
654
663
|
if (inp > 0) parts.push(`${acc("↑")}${soft(formatTokens(inp))}`);
|
|
655
664
|
if (out > 0) parts.push(`${acc("↓")}${soft(formatTokens(out))}`);
|
|
@@ -1015,13 +1024,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
1015
1024
|
if (k !== "mcp" && k !== "pi-cache-stats") groups.push(cleanStatus(s));
|
|
1016
1025
|
}
|
|
1017
1026
|
|
|
1018
|
-
const opt = parseOptimizer(rawCache);
|
|
1019
1027
|
let usageStr = "";
|
|
1020
1028
|
try {
|
|
1021
1029
|
usageStr = getUsage(ctx, acc, secondarySoft);
|
|
1022
1030
|
} catch {
|
|
1023
1031
|
// fallback
|
|
1024
1032
|
}
|
|
1033
|
+
const opt = parseOptimizer(rawCache) ?? piCacheHit();
|
|
1025
1034
|
const speedStr = latestSpeed !== null && latestSpeed > 0 ? `${acc("\udb81\udcc5")} ${secondarySoft(`${latestSpeed.toFixed(1)} tok/s`)}` : "";
|
|
1026
1035
|
const metricCells = [speedStr, opt ? `${acc("\udb80\udf5b")} ${secondarySoft(opt)}` : "", usageStr].filter(Boolean);
|
|
1027
1036
|
|
|
@@ -1353,6 +1362,9 @@ if (isMain(import.meta.url)) {
|
|
|
1353
1362
|
usageBranch.push({ type: "message", message: { role: "assistant", usage: { input: 1000, output: 2500, cacheRead: 0 } } });
|
|
1354
1363
|
const s3 = getUsage(usageCtx, id, id);
|
|
1355
1364
|
assert(s3.includes("↑1.1k") && s3.includes("↓2.6k"), "branch length changed: full rescan");
|
|
1365
|
+
// No pi-cache-stats status (provider without an optimizer adapter): the cache cell
|
|
1366
|
+
// falls back to Pi's own usage, cacheRead / (input + cacheRead) = 10 / 1110.
|
|
1367
|
+
assert(piCacheHit() === "pi 0.9%", "cache fallback reads Pi's built-in usage: " + piCacheHit());
|
|
1356
1368
|
|
|
1357
1369
|
// regression: a refresh arriving while one is in flight is re-run with the newest
|
|
1358
1370
|
// cwd, not dropped (the footer's git state no longer stays stale until the next trigger).
|
package/lib/usage-store.ts
CHANGED
|
@@ -233,6 +233,14 @@ function saveDiskCache(map: Map<string, FileCacheItem>): void {
|
|
|
233
233
|
try {
|
|
234
234
|
// Temp file + rename: a concurrent pi session never reads a half-written cache.
|
|
235
235
|
const path = cacheFilePath();
|
|
236
|
+
// Re-read: another pi session may have cached its own files since this one loaded.
|
|
237
|
+
// Skip keys whose session file is gone, so a prune done by this scan stays pruned.
|
|
238
|
+
try {
|
|
239
|
+
const disk = JSON.parse(readFileSync(path, "utf8")) as Record<string, FileCacheItem>;
|
|
240
|
+
for (const [k, v] of Object.entries(disk)) if (!map.has(k) && existsSync(k)) map.set(k, v);
|
|
241
|
+
} catch {
|
|
242
|
+
// absent or corrupt: write this session's entries alone
|
|
243
|
+
}
|
|
236
244
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
237
245
|
mkdirSync(dirname(path), { recursive: true });
|
|
238
246
|
writeFileSync(tmp, JSON.stringify(Object.fromEntries(map)), "utf8");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bismawy/pi-arnative",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Refined aesthetics. Cohesive tools. Built for Pi. Warm themes, rounded tool boxes, tabbed header, compact footer and a /usage dashboard.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|