@bismawy/pi-arnative 0.6.0 → 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 +17 -0
- package/extensions/animations.ts +1 -4
- package/extensions/arnative.ts +1 -4
- package/extensions/footer.ts +13 -1
- package/lib/format.ts +3 -0
- package/lib/preset-store.ts +25 -19
- package/lib/usage-store.ts +14 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
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
|
+
|
|
11
|
+
## [0.6.1] - 2026-10-19
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
- **A preset choice survives a second pi session.** `saveChoice` merged into a memo read once per process and wrote the whole file back, so a session that had already loaded the file dropped the keys another session had written: two concurrent saves left only the last one. Every save now re-reads the file, merges its one key, and replaces the file atomically (temp file + `rename`). The self-check writes the file behind the module and asserts the other key survives (`lib/preset-store.ts`).
|
|
15
|
+
- **The usage cache is replaced atomically.** `saveDiskCache` wrote in place, so a second pi session could read a truncated JSON, discard the cache and rescan every session file. It now writes a temp file and renames it, and `Object.fromEntries` replaces the manual copy loop (`lib/usage-store.ts`).
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- **`ROW_DIVIDER` has one definition.** The divider between a picker row label and its note was declared twice, once in the picker and once in the animations module. It now lives in `lib/format.ts` beside `markedLabels`, and both modules import it (`lib/format.ts`, `extensions/arnative.ts`, `extensions/animations.ts`).
|
|
19
|
+
|
|
3
20
|
## [0.6.0] - 2026-10-17
|
|
4
21
|
|
|
5
22
|
### Fixed
|
package/extensions/animations.ts
CHANGED
|
@@ -25,10 +25,7 @@ import {
|
|
|
25
25
|
type SpinnerPreset,
|
|
26
26
|
} from "../lib/spinner.ts";
|
|
27
27
|
import { assert, isMain } from "../lib/check.ts";
|
|
28
|
-
|
|
29
|
-
/** The row divider, matching the one `arnative.ts` draws (`Label · note`). Kept local so
|
|
30
|
-
* this module does not reach into the picker just for a separator string. */
|
|
31
|
-
const ROW_DIVIDER = " · ";
|
|
28
|
+
import { ROW_DIVIDER } from "../lib/format.ts";
|
|
32
29
|
|
|
33
30
|
/** The arnative editor instance, published by `footer.ts` so the live spinner is reachable. */
|
|
34
31
|
export const EDITOR_KEY = Symbol.for("pi-arnative.editor");
|
package/extensions/arnative.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { matchesKey, truncateToWidth, visibleWidth, type AutocompleteItem, type
|
|
|
10
10
|
import { softSecondaryOf, stripAnsi, thinkingColorOf } from "../lib/ansi.ts";
|
|
11
11
|
import { renderScreen, screenTitle, type ScreenText } from "../lib/box.ts";
|
|
12
12
|
import { assert, isMain } from "../lib/check.ts";
|
|
13
|
-
import { markedLabels } from "../lib/format.ts";
|
|
13
|
+
import { markedLabels, ROW_DIVIDER } from "../lib/format.ts";
|
|
14
14
|
import { LEGEND_LIVE, LEGEND_MOVE, matchesBack } from "../lib/shortcuts.ts";
|
|
15
15
|
import { SPINNER_PRESETS, type SpinnerPreset } from "../lib/spinner.ts";
|
|
16
16
|
import {
|
|
@@ -42,9 +42,6 @@ export interface ListRow {
|
|
|
42
42
|
note?: string;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/** Divider between row label and note, padded to align across rows. */
|
|
46
|
-
export const ROW_DIVIDER = " · ";
|
|
47
|
-
|
|
48
45
|
/** Menu rows: `Label · description` (same rhythm as /jev-eye's menu). */
|
|
49
46
|
export function menuRows(menus: Pick<ArnativeMenu, "label" | "description">[]): ListRow[] {
|
|
50
47
|
return menus.map((m) => ({ label: m.label, note: m.description }));
|
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/format.ts
CHANGED
|
@@ -23,6 +23,9 @@ export function modelDisplayParts(model?: { id?: string; name?: string; provider
|
|
|
23
23
|
return { name, provider };
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// Divider between a picker row label and its note (Label · note), shared by every /arnative list.
|
|
27
|
+
export const ROW_DIVIDER = " · ";
|
|
28
|
+
|
|
26
29
|
// Picker rows for every /arnative list (themes, header & footer presets):
|
|
27
30
|
// `● name` marks the active entry, everything else gets a two-space indent.
|
|
28
31
|
export function markedLabels(names: readonly string[], current: string | undefined): string[] {
|
package/lib/preset-store.ts
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* editing it directly would race the manager and could drop concurrent changes. The choices here
|
|
7
7
|
* belong to this package, not to pi.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* Reads are memoised per process; every write re-reads the file and replaces it atomically
|
|
10
|
+
* (temp file + rename), so concurrent pi sessions that write different keys keep both.
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
12
|
+
import { mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
13
13
|
import { tmpdir } from "node:os";
|
|
14
14
|
import { dirname, join } from "node:path";
|
|
15
15
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
@@ -23,20 +23,18 @@ const configPath = (): string => join(getAgentDir(), "arnative-config.json");
|
|
|
23
23
|
|
|
24
24
|
let memo: Record<string, unknown> | null = null;
|
|
25
25
|
|
|
26
|
-
function
|
|
27
|
-
if (memo) return memo;
|
|
28
|
-
memo = {};
|
|
26
|
+
function readDisk(): Record<string, unknown> {
|
|
29
27
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (raw && typeof raw === "object" && !Array.isArray(raw)) memo = raw as Record<string, unknown>;
|
|
33
|
-
}
|
|
28
|
+
const raw = JSON.parse(readFileSync(configPath(), "utf8")) as unknown;
|
|
29
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw)) return raw as Record<string, unknown>;
|
|
34
30
|
} catch {
|
|
35
|
-
// unreadable
|
|
31
|
+
// absent, unreadable or corrupt: fall back to defaults rather than crash the header
|
|
36
32
|
}
|
|
37
|
-
return
|
|
33
|
+
return {};
|
|
38
34
|
}
|
|
39
35
|
|
|
36
|
+
const readConfig = (): Record<string, unknown> => (memo ??= readDisk());
|
|
37
|
+
|
|
40
38
|
/** The stored value for `key`, or undefined when absent or not one of `allowed`. */
|
|
41
39
|
export function loadChoice<T extends string>(key: string, allowed: readonly T[]): T | undefined {
|
|
42
40
|
const value = readConfig()[key];
|
|
@@ -45,13 +43,15 @@ export function loadChoice<T extends string>(key: string, allowed: readonly T[])
|
|
|
45
43
|
|
|
46
44
|
/** Store a choice. Best effort: an unwritable agent dir must not break the TUI. */
|
|
47
45
|
export function saveChoice(key: string, value: string): void {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
if (readConfig()[key] === value) return;
|
|
47
|
+
// Re-read: another pi session may have written its own key since this one loaded.
|
|
48
|
+
memo = { ...readDisk(), [key]: value };
|
|
51
49
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
const path = configPath();
|
|
51
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
52
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
53
|
+
writeFileSync(tmp, `${JSON.stringify(memo, null, 2)}\n`, "utf8");
|
|
54
|
+
renameSync(tmp, path);
|
|
55
55
|
} catch {
|
|
56
56
|
// ignore: the choice still applies for this session
|
|
57
57
|
}
|
|
@@ -74,6 +74,12 @@ if (isMain(import.meta.url)) {
|
|
|
74
74
|
assert(loadChoice(HEADER_PRESET_KEY, ["a", "b"] as const) === "b", "a saved choice reads back");
|
|
75
75
|
assert(loadChoice(FOOTER_PRESET_KEY, ["a", "b"] as const) === "a", "a second key is stored without clobbering the first");
|
|
76
76
|
|
|
77
|
+
// Another pi session writes its own key after this one loaded; a save must keep it.
|
|
78
|
+
writeFileSync(join(fixture, "arnative-config.json"), JSON.stringify({ headerPreset: "b", footerPreset: "a", other: "x" }), "utf8");
|
|
79
|
+
saveChoice(FOOTER_PRESET_KEY, "b");
|
|
80
|
+
resetPresetCache();
|
|
81
|
+
assert(loadChoice("other", ["x"] as const) === "x", "a key written by another process survives a save");
|
|
82
|
+
|
|
77
83
|
// The point of the file: the choice outlives the process (drop the in-memory copy).
|
|
78
84
|
resetPresetCache();
|
|
79
85
|
assert(loadChoice(HEADER_PRESET_KEY, ["a", "b"] as const) === "b", "the choice survives a restart (read from disk)");
|
|
@@ -89,4 +95,4 @@ if (isMain(import.meta.url)) {
|
|
|
89
95
|
|
|
90
96
|
rmSync(fixture, { recursive: true, force: true });
|
|
91
97
|
console.log("preset-store.ts self-check OK");
|
|
92
|
-
}
|
|
98
|
+
}
|
package/lib/usage-store.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - No double counting: the active session is already in its own file, so it is
|
|
7
7
|
* NOT re-added from sessionManager (that inflated the ↑↓ totals).
|
|
8
8
|
*/
|
|
9
|
-
import { closeSync, existsSync, fstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { closeSync, existsSync, fstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
10
10
|
import { dirname, join } from "node:path";
|
|
11
11
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
12
12
|
|
|
@@ -231,13 +231,20 @@ function loadDiskCache(): Map<string, FileCacheItem> {
|
|
|
231
231
|
|
|
232
232
|
function saveDiskCache(map: Map<string, FileCacheItem>): void {
|
|
233
233
|
try {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
234
|
+
// Temp file + rename: a concurrent pi session never reads a half-written cache.
|
|
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
|
|
237
243
|
}
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
writeFileSync(
|
|
244
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
245
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
246
|
+
writeFileSync(tmp, JSON.stringify(Object.fromEntries(map)), "utf8");
|
|
247
|
+
renameSync(tmp, path);
|
|
241
248
|
} catch {
|
|
242
249
|
// ignore
|
|
243
250
|
}
|
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",
|