@bismawy/pi-arnative 0.12.0 → 0.14.0
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 +43 -6
- package/README.md +13 -4
- package/extensions/arnative.ts +374 -68
- package/extensions/autocompact.ts +772 -64
- package/extensions/budget.ts +4 -3
- package/extensions/footer.ts +43 -39
- package/extensions/model-heal.ts +14 -17
- package/extensions/render-cache.ts +638 -0
- package/extensions/tools.ts +52 -2
- package/extensions/ui-render-tweaks.ts +23 -7
- package/extensions/usage.ts +3 -4
- package/lib/color.ts +34 -0
- package/lib/list-picker.ts +20 -12
- package/lib/patch.ts +26 -1
- package/lib/preset-store.ts +10 -1
- package/lib/status-widget.ts +5 -16
- package/lib/usage-store.ts +4 -5
- package/package.json +49 -49
- package/themes/arnative-blossom.json +9 -9
- package/themes/arnative-crimson.json +10 -10
- package/themes/arnative-cyberpunk.json +9 -9
- package/themes/arnative-dracula.json +9 -9
- package/themes/arnative-earthy.json +10 -10
- package/themes/arnative-garden.json +10 -10
- package/themes/arnative-gruvbox.json +10 -10
- package/themes/arnative-lemonade.json +9 -9
- package/themes/arnative-magical.json +9 -9
- package/themes/arnative-matrix.json +9 -9
- package/themes/arnative-neutral.json +9 -9
- package/themes/arnative-nord.json +8 -8
- package/themes/arnative-zinc.json +9 -9
- package/themes/arnative.json +9 -9
- package/themes/gen-themes.mjs +43 -15
package/extensions/tools.ts
CHANGED
|
@@ -276,6 +276,51 @@ export function stripEdgesKeepingImages(lines: string[]): string[] {
|
|
|
276
276
|
// copyable. Recomputed on every render, because the label moves with the width and the key.
|
|
277
277
|
const HINT_SPANS = Symbol.for("pi-arnative.toolBoxHintSpans");
|
|
278
278
|
const SCROLL_OFFSET = Symbol.for("pi-arnative.toolBoxScrollOffset");
|
|
279
|
+
const SCROLL_HOLD = Symbol.for("pi-arnative.toolBoxScrollHold");
|
|
280
|
+
const HOLD_DELAY_MS = 250;
|
|
281
|
+
const HOLD_REPEAT_MS = 90;
|
|
282
|
+
|
|
283
|
+
type HoldTimers = { delay?: ReturnType<typeof setTimeout>; repeat?: ReturnType<typeof setInterval> };
|
|
284
|
+
|
|
285
|
+
function stopScrollHold(comp: Record<symbol, unknown>): void {
|
|
286
|
+
const timers = comp[SCROLL_HOLD] as HoldTimers | undefined;
|
|
287
|
+
if (!timers) return;
|
|
288
|
+
if (timers.delay) clearTimeout(timers.delay);
|
|
289
|
+
if (timers.repeat) clearInterval(timers.repeat);
|
|
290
|
+
comp[SCROLL_HOLD] = undefined;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function startScrollHold(
|
|
294
|
+
comp: Record<symbol, unknown> & { expanded?: boolean; ui?: { requestRender?: () => void } },
|
|
295
|
+
dir: -1 | 1,
|
|
296
|
+
): void {
|
|
297
|
+
stopScrollHold(comp);
|
|
298
|
+
const timers: HoldTimers = {};
|
|
299
|
+
comp[SCROLL_HOLD] = timers;
|
|
300
|
+
const stepOnce = (): boolean => {
|
|
301
|
+
if (!comp.expanded) {
|
|
302
|
+
stopScrollHold(comp);
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
const meta = (comp[SCROLL_META] as { maxOffset: number; step: number } | undefined) ?? { maxOffset: 0, step: 6 };
|
|
306
|
+
const cur = Number(comp[SCROLL_OFFSET] ?? 0);
|
|
307
|
+
const next = Math.max(0, Math.min(meta.maxOffset, cur + dir * meta.step));
|
|
308
|
+
if (next === cur) {
|
|
309
|
+
stopScrollHold(comp);
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
comp[SCROLL_OFFSET] = next;
|
|
313
|
+
comp.ui?.requestRender?.();
|
|
314
|
+
return true;
|
|
315
|
+
};
|
|
316
|
+
timers.delay = setTimeout(() => {
|
|
317
|
+
timers.delay = undefined;
|
|
318
|
+
if (!stepOnce()) return;
|
|
319
|
+
if (comp[SCROLL_HOLD] === timers && timers.repeat === undefined) {
|
|
320
|
+
timers.repeat = setInterval(stepOnce, HOLD_REPEAT_MS);
|
|
321
|
+
}
|
|
322
|
+
}, HOLD_DELAY_MS);
|
|
323
|
+
}
|
|
279
324
|
const SCROLL_UP_SPANS = Symbol.for("pi-arnative.toolBoxScrollUpSpans");
|
|
280
325
|
const SCROLL_DOWN_SPANS = Symbol.for("pi-arnative.toolBoxScrollDownSpans");
|
|
281
326
|
const SCROLL_META = Symbol.for("pi-arnative.toolBoxScrollMeta");
|
|
@@ -378,7 +423,7 @@ if (ToolExecutionComponent?.prototype?.render) {
|
|
|
378
423
|
maxBody,
|
|
379
424
|
width,
|
|
380
425
|
boxTokenPaint(["dim"]),
|
|
381
|
-
boxTokenPaint(["
|
|
426
|
+
boxTokenPaint(["dim"]),
|
|
382
427
|
);
|
|
383
428
|
drawn = capped.lines;
|
|
384
429
|
this[SCROLL_OFFSET] = Math.max(0, Math.min(Number(this[SCROLL_OFFSET] ?? 0), capped.maxOffset));
|
|
@@ -389,6 +434,7 @@ if (ToolExecutionComponent?.prototype?.render) {
|
|
|
389
434
|
? textSpans([drawn[capped.botRow]!], capped.belowLabel).map((s) => ({ ...s, row: capped.botRow }))
|
|
390
435
|
: [];
|
|
391
436
|
} else {
|
|
437
|
+
stopScrollHold(this);
|
|
392
438
|
this[SCROLL_OFFSET] = 0;
|
|
393
439
|
this[SCROLL_UP_SPANS] = [];
|
|
394
440
|
this[SCROLL_DOWN_SPANS] = [];
|
|
@@ -422,6 +468,7 @@ if (ToolExecutionComponent?.prototype?.render) {
|
|
|
422
468
|
? inSpans(this[SCROLL_DOWN_SPANS] as TextSpan[], event.y, event.x)
|
|
423
469
|
: false;
|
|
424
470
|
if ((onHint || onUp || onDown) && event.type === "press" && event.button === "left") {
|
|
471
|
+
stopScrollHold(this);
|
|
425
472
|
// A child of the box (an image preview) keeps its own press.
|
|
426
473
|
const childHit = origMouse.call(this, event);
|
|
427
474
|
if (childHit) return childHit;
|
|
@@ -433,13 +480,16 @@ if (ToolExecutionComponent?.prototype?.render) {
|
|
|
433
480
|
}
|
|
434
481
|
const meta = (this[SCROLL_META] as { maxOffset: number; step: number } | undefined) ?? { maxOffset: 0, step: 6 };
|
|
435
482
|
const cur = Number(this[SCROLL_OFFSET] ?? 0);
|
|
436
|
-
const
|
|
483
|
+
const dir: -1 | 1 = onUp ? -1 : 1;
|
|
484
|
+
const next = Math.max(0, Math.min(meta.maxOffset, cur + dir * meta.step));
|
|
437
485
|
this[SCROLL_OFFSET] = next;
|
|
438
486
|
this[PRESS_TOGGLED] = true;
|
|
487
|
+
startScrollHold(this, dir);
|
|
439
488
|
this.ui?.requestRender?.();
|
|
440
489
|
return { handled: true, render: true };
|
|
441
490
|
}
|
|
442
491
|
if (this[PRESS_TOGGLED] && (event.type === "release" || event.type === "click")) {
|
|
492
|
+
stopScrollHold(this);
|
|
443
493
|
if (event.type === "click") this[PRESS_TOGGLED] = false;
|
|
444
494
|
return { handled: true, render: false };
|
|
445
495
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 5. `↓ Jump to latest message` pill (fullscreen): bg selectedBg (grey) -> accent,
|
|
13
13
|
* text darkened (theme canvas) so contrast stays high (9.6:1).
|
|
14
14
|
* 6. `ctx.ui.select` rows: pi paints the whole selected row accent -> keep accent on
|
|
15
|
-
* the
|
|
15
|
+
* the `❯` marker and `·` separators, selected text in soft.
|
|
16
16
|
*/
|
|
17
17
|
import {
|
|
18
18
|
AssistantMessageComponent,
|
|
@@ -40,9 +40,9 @@ import {
|
|
|
40
40
|
import { readdirSync, readFileSync } from "node:fs";
|
|
41
41
|
import { renderBoxLines } from "../lib/box.ts";
|
|
42
42
|
import { statusRows } from "../lib/status-widget.ts";
|
|
43
|
-
import { ansiBgOpen, getActiveTheme, setActiveTheme, stripAnsi, themeOf,
|
|
43
|
+
import { ansiBgOpen, getActiveTheme, setActiveTheme, stripAnsi, themeOf, softOf } from "../lib/ansi.ts";
|
|
44
44
|
import { assert, isMain } from "../lib/check.ts";
|
|
45
|
-
import { contrast, oklchToRgb, parseOklch, toHex } from "../lib/color.ts";
|
|
45
|
+
import { contrast, hexToRgb, oklchToRgb, parseOklch, rgbToAnsi256, toHex } from "../lib/color.ts";
|
|
46
46
|
import { expandKeyName } from "../lib/format.ts";
|
|
47
47
|
import { patchOnce } from "../lib/patch.ts";
|
|
48
48
|
|
|
@@ -171,12 +171,12 @@ if (TuiAltScreen?.prototype) {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
// 6. Select menus (ctx.ui.select -> ExtensionSelectorComponent.updateList): pi colors the
|
|
174
|
-
// whole selected row accent. Arnative keeps accent on the
|
|
174
|
+
// whole selected row accent. Arnative keeps accent on the `❯` marker and `·` separators
|
|
175
175
|
// and moves the selected text to soft (accent on themes without the token).
|
|
176
176
|
|
|
177
177
|
/** Selected row body: `·` separators accent, the text around them soft. */
|
|
178
178
|
export function selectRowText(row: string, th: { fg(c: string, t: string): string }): string {
|
|
179
|
-
const soft =
|
|
179
|
+
const soft = softOf(th);
|
|
180
180
|
return row
|
|
181
181
|
.split("·")
|
|
182
182
|
.map((part) => soft(part))
|
|
@@ -197,7 +197,7 @@ if (ExtensionSelectorComponent?.prototype) {
|
|
|
197
197
|
for (let i = 0; i < this.options.length; i++) {
|
|
198
198
|
const text =
|
|
199
199
|
i === this.selectedIndex
|
|
200
|
-
? th.fg("accent", "
|
|
200
|
+
? th.fg("accent", "❯ ") + selectRowText(this.options[i]!, th)
|
|
201
201
|
: ` ${th.fg("text", this.options[i]!)}`;
|
|
202
202
|
this.listContainer.addChild(new Text(text, 1, 0));
|
|
203
203
|
}
|
|
@@ -697,7 +697,7 @@ if (isMain(import.meta.url)) {
|
|
|
697
697
|
assert(accentPill("other text", thPill) === "other text", "pill: non-pill text untouched");
|
|
698
698
|
assert(accentPill(pillOriginal, null) === pillOriginal, "pill: no theme -> passed through");
|
|
699
699
|
|
|
700
|
-
// select rows:
|
|
700
|
+
// select rows: `❯` + `·` stay accent, selected text moves to accentSoft
|
|
701
701
|
const tagFg = { fg: (c: string, t: string) => `<${c}>${t}</${c}>` };
|
|
702
702
|
assert(
|
|
703
703
|
selectRowText("Routing · off", tagFg) === "<accentSoft>Routing </accentSoft><accent>·</accent><accentSoft> off</accentSoft>",
|
|
@@ -718,6 +718,13 @@ if (isMain(import.meta.url)) {
|
|
|
718
718
|
"searchMatchBg", "border", "borderAccent", "borderMuted", "mdCodeBlockBorder", "mdQuoteBorder", "mdHr",
|
|
719
719
|
"scrollbarTrack", "scrollbarThumb",
|
|
720
720
|
]);
|
|
721
|
+
// Every background a box or a highlight paints. These carry no text contrast
|
|
722
|
+
// requirement, but each must still be *visible*: a box the same color as the
|
|
723
|
+
// terminal canvas is not a box.
|
|
724
|
+
const BOX_TOKENS = [
|
|
725
|
+
"userMessageBg", "customMessageBg", "toolPendingBg", "toolSuccessBg", "toolErrorBg",
|
|
726
|
+
"selectedBg", "searchMatchBg",
|
|
727
|
+
];
|
|
721
728
|
const secondary = new Set(["muted", "dim", "mdQuote", "mdLinkUrl", "toolOutput", "toolDiffContext", "thinkingText", "syntaxComment"]);
|
|
722
729
|
// Thinking ramp: the higher the more readable; thinkingMax = accent (measured on the pill path).
|
|
723
730
|
const ramp: Record<string, number> = {
|
|
@@ -831,6 +838,15 @@ if (isMain(import.meta.url)) {
|
|
|
831
838
|
// Scrollbar thumb & highlight must be distinguishable from track/selection (they used to be identical).
|
|
832
839
|
assert(hex("scrollbarThumb") !== hex("scrollbarTrack"), `theme ${f}: scrollbarThumb still equals scrollbarTrack`);
|
|
833
840
|
assert(hex("searchMatchBg") !== hex("selectedBg"), `theme ${f}: searchMatchBg still equals selectedBg`);
|
|
841
|
+
// Every box must be visible on a pure-black terminal AND survive 256-color
|
|
842
|
+
// quantization. At L 0.19 the panel was `#001817` (1.14:1 on black) and every
|
|
843
|
+
// theme's boxes quantized to cube black (index 16) — invisible in both modes.
|
|
844
|
+
for (const tok of BOX_TOKENS) {
|
|
845
|
+
const color = hex(tok);
|
|
846
|
+
assert(contrast(color, "#000000") >= 1.4, `theme ${f}: ${tok} ${color} is invisible on a black terminal`);
|
|
847
|
+
const quantized = rgbToAnsi256(hexToRgb(color));
|
|
848
|
+
assert(quantized !== 16, `theme ${f}: ${tok} ${color} quantizes to index 16 (pure black) in 256-color mode`);
|
|
849
|
+
}
|
|
834
850
|
}
|
|
835
851
|
// Only `muted`, `text` and `selectedBg` exist. pi's Theme constructor maps whatever
|
|
836
852
|
// it gets — including the thinkingMax <- thinkingXhigh fallback — so these probe
|
package/extensions/usage.ts
CHANGED
|
@@ -88,7 +88,7 @@ const statsOf = (
|
|
|
88
88
|
type UsageView = "provider" | "project" | "prices";
|
|
89
89
|
|
|
90
90
|
/** Labels on the range bar, in tab order. */
|
|
91
|
-
const RANGE_LABELS: Record<UsageRange, string> = { all: "All", today: "Today", "7d": "7 day", "30d": "30 day"
|
|
91
|
+
const RANGE_LABELS: Record<UsageRange, string> = { all: "All", today: "Today", "7d": "7 day", "30d": "30 day" };
|
|
92
92
|
/** The three views `v` cycles, in that order, and the view a press would show next. */
|
|
93
93
|
const VIEW_LABELS: Record<UsageView, string> = { provider: "Provider", project: "Project", prices: "Prices" };
|
|
94
94
|
const NEXT_VIEW: Record<UsageView, UsageView> = { provider: "project", project: "prices", prices: "provider" };
|
|
@@ -1323,7 +1323,6 @@ if (isMain(import.meta.url)) {
|
|
|
1323
1323
|
assert(msgIn("today") === 1, "today counts only the message written today");
|
|
1324
1324
|
assert(msgIn("7d") === 1, "7 day stops before the ten-day record, so only today counts");
|
|
1325
1325
|
assert(msgIn("30d") === 2, "30 day covers today and ten days back, not forty-five");
|
|
1326
|
-
assert(msgIn("3m") === 3, "3 month covers all three");
|
|
1327
1326
|
// A window with nothing in it is empty, not an error: the bar can be pressed on a quiet day.
|
|
1328
1327
|
assert(collectUsageSummary(true, "today").totals.msgs >= 1, "today still reports the rows it has");
|
|
1329
1328
|
|
|
@@ -1339,11 +1338,11 @@ if (isMain(import.meta.url)) {
|
|
|
1339
1338
|
const reloaded = JSON.parse(readFileSync(cacheFile, "utf8")) as Record<string, { d?: unknown }>;
|
|
1340
1339
|
assert(Object.values(reloaded).some((item) => item.d !== undefined), "the re-parse writes the day buckets back");
|
|
1341
1340
|
|
|
1342
|
-
// The range bar:
|
|
1341
|
+
// The range bar: four windows, the active one accented, and the counter states how many
|
|
1343
1342
|
// rows exist past the viewport. Tab moves the window and the numbers follow it.
|
|
1344
1343
|
const barModal = new UsageModalComponent(fakeTheme, () => {}, () => {}, "high");
|
|
1345
1344
|
const barOnce = barModal.render(100).map(plain);
|
|
1346
|
-
const barLine = barOnce.find((l) => l.includes("All") && l.includes("Today") && l.includes("
|
|
1345
|
+
const barLine = barOnce.find((l) => l.includes("All") && l.includes("Today") && l.includes("30 day"));
|
|
1347
1346
|
assert(barLine !== undefined, "the range bar names every window on one line");
|
|
1348
1347
|
assert(USAGE_RANGES.every((r) => barLine!.includes(RANGE_LABELS[r])), "every range label is on the bar");
|
|
1349
1348
|
assert(barLine!.indexOf("All") < barLine!.indexOf("Today"), "the bar keeps tab order");
|
package/lib/color.ts
CHANGED
|
@@ -75,6 +75,34 @@ export function toHex(value: string): string {
|
|
|
75
75
|
throw new Error(`Not a hex/oklch color: ${value}`);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Nearest xterm-256 index for an sRGB color, mirroring `rgbToAnsi256` in
|
|
80
|
+
* @earendil-works/pi-tui (`colors.ts`). pi draws every theme color through that
|
|
81
|
+
* quantizer whenever the terminal is not truecolor, so a value that lands on the
|
|
82
|
+
* 6x6x6 cube black renders as `#000000` no matter what the theme file declared.
|
|
83
|
+
* Kept in sync by test/theme-canvas.test.ts.
|
|
84
|
+
*/
|
|
85
|
+
export function rgbToAnsi256(rgb: Rgb): number {
|
|
86
|
+
const CUBE = [0, 95, 135, 175, 215, 255];
|
|
87
|
+
const GRAY = Array.from({ length: 24 }, (_, i) => 8 + i * 10);
|
|
88
|
+
const nearest = (values: readonly number[], v: number) =>
|
|
89
|
+
values.reduce((best, x, i) => (Math.abs(x - v) < Math.abs(values[best]! - v) ? i : best), 0);
|
|
90
|
+
const distance = (a: Rgb, b: Rgb) => (a.r - b.r) ** 2 * 0.299 + (a.g - b.g) ** 2 * 0.587 + (a.b - b.b) ** 2 * 0.114;
|
|
91
|
+
const [ri, gi, bi] = [rgb.r, rgb.g, rgb.b].map((c) => nearest(CUBE, c)) as [number, number, number];
|
|
92
|
+
const cube = { r: CUBE[ri]!, g: CUBE[gi]!, b: CUBE[bi]! };
|
|
93
|
+
const grayIndex = nearest(GRAY, Math.round(0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b));
|
|
94
|
+
const gray = { r: GRAY[grayIndex]!, g: GRAY[grayIndex]!, b: GRAY[grayIndex]! };
|
|
95
|
+
const spread = Math.max(rgb.r, rgb.g, rgb.b) - Math.min(rgb.r, rgb.g, rgb.b);
|
|
96
|
+
if (spread < 10 && distance(rgb, gray) < distance(rgb, cube)) return 232 + grayIndex;
|
|
97
|
+
return 16 + 36 * ri + 6 * gi + bi;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** `#rrggbb` -> sRGB channels. Inverse of the hex branch of {@link toHex}. */
|
|
101
|
+
export function hexToRgb(hex: string): Rgb {
|
|
102
|
+
const v = toHex(hex);
|
|
103
|
+
return { r: parseInt(v.slice(1, 3), 16), g: parseInt(v.slice(3, 5), 16), b: parseInt(v.slice(5, 7), 16) };
|
|
104
|
+
}
|
|
105
|
+
|
|
78
106
|
function relativeLuminance(hex: string): number {
|
|
79
107
|
const [r, g, b] = [1, 3, 5]
|
|
80
108
|
.map((i) => parseInt(hex.slice(i, i + 2), 16) / 255)
|
|
@@ -122,5 +150,11 @@ if (isMain(import.meta.url)) {
|
|
|
122
150
|
const back = hexToOklch(FIXTURE.cyan);
|
|
123
151
|
assert(Math.abs(back.H - 218) < 6, `hexToOklch hue of ${FIXTURE.cyan} ~218 (got ${back.H.toFixed(1)})`);
|
|
124
152
|
assert(oklchToRgb(0.7, 0.4, 145).chroma < 0.4, "out-of-gamut chroma is reduced");
|
|
153
|
+
// Quantizer vectors taken from pi-tui's own table: cube black, the teal panel pi's
|
|
154
|
+
// dark theme uses, and a near-neutral that must fall on the grey ramp.
|
|
155
|
+
assert(rgbToAnsi256({ r: 0, g: 24, b: 23 }) === 16, "near-black quantizes to cube black (index 16)");
|
|
156
|
+
assert(rgbToAnsi256({ r: 33, g: 59, b: 73 }) === 23, "pi dark panel quantizes to 23");
|
|
157
|
+
assert(rgbToAnsi256({ r: 200, g: 200, b: 200 }) >= 232, "neutral grey uses the grey ramp");
|
|
158
|
+
assert(hexToRgb("#1c3f3d").g === 0x3f, "hexToRgb reads channels");
|
|
125
159
|
console.log("lib/color.ts OK");
|
|
126
160
|
}
|
package/lib/list-picker.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* can import it without importing the settings menu back (no import cycle).
|
|
6
6
|
*/
|
|
7
7
|
import { Input, matchesKey, truncateToWidth, visibleWidth, type Component, type Focusable } from "@earendil-works/pi-tui";
|
|
8
|
-
import {
|
|
8
|
+
import { softOf, thinkingColorOf } from "../lib/ansi.ts";
|
|
9
9
|
import { renderScreen, screenTitle, type ScreenText } from "../lib/box.ts";
|
|
10
10
|
import { assert, isMain } from "../lib/check.ts";
|
|
11
11
|
import { ROW_DIVIDER } from "../lib/format.ts";
|
|
@@ -33,7 +33,7 @@ export function rowText(row: ListRow): string {
|
|
|
33
33
|
return row.note ? `${row.label} · ${row.note}` : row.label;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/** Bare names (preset lists) as rows; the cursor's
|
|
36
|
+
/** Bare names (preset lists) as rows; the cursor's `❯` marks the live value. */
|
|
37
37
|
export const nameRows = (names: readonly string[]): ListRow[] => names.map((label) => ({ label }));
|
|
38
38
|
|
|
39
39
|
interface ListPickerHooks {
|
|
@@ -207,8 +207,11 @@ export class ListPicker implements Component {
|
|
|
207
207
|
|
|
208
208
|
private move(delta: number): void {
|
|
209
209
|
const shown = this.shown;
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
if (shown.length === 0) return;
|
|
211
|
+
// Wrap at both ends, matching the /jev-eye picker: the top row steps up to the
|
|
212
|
+
// last row and the last row steps down to the top, so a held key never sticks.
|
|
213
|
+
const next = (this.selected + delta + shown.length) % shown.length;
|
|
214
|
+
if (next === this.selected) return;
|
|
212
215
|
this.selected = next;
|
|
213
216
|
if (!this.livePreview) {
|
|
214
217
|
this.hooks.requestRender();
|
|
@@ -257,7 +260,7 @@ export class ListPicker implements Component {
|
|
|
257
260
|
render(width: number): string[] {
|
|
258
261
|
const th = this.theme;
|
|
259
262
|
const bold = th.bold ?? ((t: string) => `\x1b[1m${t}\x1b[22m`);
|
|
260
|
-
const soft =
|
|
263
|
+
const soft = softOf(th);
|
|
261
264
|
const edge = (text: string) => this.edge(text);
|
|
262
265
|
const column = Math.max(0, ...this.rows.map((r) => visibleWidth(r.label)));
|
|
263
266
|
const body: string[] = [];
|
|
@@ -269,7 +272,7 @@ export class ListPicker implements Component {
|
|
|
269
272
|
for (let i = windowStart; i < windowEnd; i++) {
|
|
270
273
|
const item = this.rows[shown[i]!]!;
|
|
271
274
|
const isSelected = i === this.selected;
|
|
272
|
-
const paint = isSelected ? (s: string) => soft(bold(s)) : (s: string) => th.fg(
|
|
275
|
+
const paint = isSelected ? (s: string) => soft(bold(s)) : (s: string) => th.fg("text", s);
|
|
273
276
|
const pad = " ".repeat(Math.max(0, column - visibleWidth(item.label)));
|
|
274
277
|
const noteText = this.hooks.note?.(item.label) ?? item.note;
|
|
275
278
|
const note = noteText ? `${th.fg("dim", ROW_DIVIDER)}${th.fg("dim", noteText)}` : "";
|
|
@@ -284,7 +287,7 @@ export class ListPicker implements Component {
|
|
|
284
287
|
const suffix = /(\(.*\))$/.exec(item.label)?.[1] ?? "";
|
|
285
288
|
const head = suffix ? item.label.slice(0, item.label.length - suffix.length) : item.label;
|
|
286
289
|
const tail = suffix ? th.fg("dim", suffix) : "";
|
|
287
|
-
const content = `${isSelected ? th.fg("accent", "
|
|
290
|
+
const content = `${isSelected ? th.fg("accent", "❯ ") : " "}${mark}${paint(head)}${tail}${pad}${note}${chosen}`;
|
|
288
291
|
body.push(truncateToWidth(content, width - 4, ""));
|
|
289
292
|
}
|
|
290
293
|
// Hidden rows are announced, never silently cut (an empty line is still a row).
|
|
@@ -399,7 +402,7 @@ if (isMain(import.meta.url)) {
|
|
|
399
402
|
const lines = picker.render(50);
|
|
400
403
|
assert(lines[0]!.startsWith("╭") && lines[lines.length - 1]!.startsWith("╰"), "picker framed");
|
|
401
404
|
assert(lines.every((l) => visibleWidth(l) === 50), "picker lines fit width 50");
|
|
402
|
-
assert(lines.some((l) => l.includes("
|
|
405
|
+
assert(lines.some((l) => l.includes("❯ a")), "the cursor marks the selection");
|
|
403
406
|
|
|
404
407
|
// The chosen marker: ✓ ends the saved row only, colored by the theme's success slot.
|
|
405
408
|
const chosenPicker = new ListPicker(
|
|
@@ -444,13 +447,18 @@ if (isMain(import.meta.url)) {
|
|
|
444
447
|
frame = scrolled.render(50);
|
|
445
448
|
assert(countItems(frame) === 10, "still 10 rows after scrolling");
|
|
446
449
|
assert(frame.some((l) => l.includes("↑ 9 more")) && frame.some((l) => l.includes("↓ 6 more")), "both ends announce their hidden rows");
|
|
447
|
-
assert(frame.some((l) => l.includes("
|
|
450
|
+
assert(frame.some((l) => l.includes("❯ m14")), "the cursor row stays visible");
|
|
448
451
|
scrolled.handleInput("\x1b[B");
|
|
449
452
|
const frameNext = scrolled.render(50);
|
|
450
453
|
assert(frameNext.length === frame.length && countItems(frameNext) === 10, "the frame height stays constant while scrolling inside the list");
|
|
451
|
-
for (let i = 0; i <
|
|
454
|
+
for (let i = 0; i < 9; i++) scrolled.handleInput("\x1b[B");
|
|
452
455
|
frame = scrolled.render(50);
|
|
453
|
-
assert(frame.some((l) => l.includes("
|
|
456
|
+
assert(frame.some((l) => l.includes("❯ m24")) && frame.some((l) => l.includes("↑ 15 more")) && !frame.some((l) => l.includes("↓")), "the bottom of the list announces only what is above");
|
|
457
|
+
// Wrap at both edges, matching the /jev-eye picker: a held key never sticks.
|
|
458
|
+
scrolled.handleInput("\x1b[B");
|
|
459
|
+
assert(scrolled.render(50).some((l) => l.includes("❯ m0")), "↓ at the last row wraps to the top");
|
|
460
|
+
scrolled.handleInput("\x1b[A");
|
|
461
|
+
assert(scrolled.render(50).some((l) => l.includes("❯ m24")), "↑ at the top row wraps to the last row");
|
|
454
462
|
const short = new ListPicker(fakeTheme, nameRows(["a", "b"]), "a", { preview: quiet, revert: quiet, done: quiet, requestRender: quiet }, { title: screenTitle("Test"), description: "d", legend: "l" }, false, undefined, 10);
|
|
455
463
|
assert(!short.render(50).some((l) => l.includes("more")), "a short list shows no scroll indicators");
|
|
456
464
|
|
|
@@ -503,7 +511,7 @@ if (isMain(import.meta.url)) {
|
|
|
503
511
|
|
|
504
512
|
const summarized = new ListPicker(fakeTheme, nameRows(["a", "b"]), "a", { preview: quiet, revert: quiet, done: quiet, requestRender: quiet, summary: () => ["Box · a"] }, { title: "T", description: "d", legend: "l" }, false);
|
|
505
513
|
const sumLines = summarized.render(40).map(plain);
|
|
506
|
-
assert(sumLines.some((l) => l.includes("Box · a")) && sumLines.indexOf(sumLines.find((l) => l.includes("Box · a"))!) < sumLines.indexOf(sumLines.find((l) => l.includes("
|
|
514
|
+
assert(sumLines.some((l) => l.includes("Box · a")) && sumLines.indexOf(sumLines.find((l) => l.includes("Box · a"))!) < sumLines.indexOf(sumLines.find((l) => l.includes("❯ a"))!), "summary renders above the picker rows");
|
|
507
515
|
|
|
508
516
|
console.log("list-picker.ts self-check OK");
|
|
509
517
|
}
|
package/lib/patch.ts
CHANGED
|
@@ -29,7 +29,13 @@ export function markPatched<T extends AnyFn>(fn: T): T {
|
|
|
29
29
|
|
|
30
30
|
/** pi's own method for `key`, recorded once per prototype and returned on every load. */
|
|
31
31
|
export function originalOf<T extends AnyFn>(proto: Record<symbol | string, any>, key: string): T {
|
|
32
|
-
|
|
32
|
+
// Own property only: an instance without its own map must never read or mutate its
|
|
33
|
+
// prototype's recorded originals across reloads.
|
|
34
|
+
let originals = Object.hasOwn(proto, ORIGINALS_KEY) ? (proto[ORIGINALS_KEY] as Record<string, Marked>) : undefined;
|
|
35
|
+
if (!originals) {
|
|
36
|
+
originals = {};
|
|
37
|
+
Object.defineProperty(proto, ORIGINALS_KEY, { value: originals, configurable: true });
|
|
38
|
+
}
|
|
33
39
|
const current: Marked | undefined = proto[key];
|
|
34
40
|
if (current && !current[PATCHED_KEY]) originals[key] = current;
|
|
35
41
|
const original = originals[key];
|
|
@@ -83,5 +89,24 @@ if (isMain(import.meta.url)) {
|
|
|
83
89
|
});
|
|
84
90
|
assert(twice.render() === "pi?", "patchOnce: the second load patches pi's method again, not the first patch");
|
|
85
91
|
|
|
92
|
+
// Instance vs prototype isolation: recording an original on a child object must never
|
|
93
|
+
// overwrite its prototype's recorded original.
|
|
94
|
+
class Parent {
|
|
95
|
+
render(): string { return "parent"; }
|
|
96
|
+
}
|
|
97
|
+
patchOnce(Parent.prototype, "render", (orig) => function (this: any): string {
|
|
98
|
+
return `[${orig.call(this)}]`;
|
|
99
|
+
});
|
|
100
|
+
const child = new Parent() as any;
|
|
101
|
+
child.render = () => "stale-instance";
|
|
102
|
+
patchOnce(child, "render", (orig) => function (this: any): string {
|
|
103
|
+
return `(${orig.call(this)})`;
|
|
104
|
+
});
|
|
105
|
+
patchOnce(Parent.prototype, "render", (orig) => function (this: any): string {
|
|
106
|
+
return `<${orig.call(this)}>`;
|
|
107
|
+
});
|
|
108
|
+
assert(new Parent().render() === "<parent>", "prototype original stays untouched when a child instance is patched");
|
|
109
|
+
assert(child.render() === "(stale-instance)", "instance keeps its own recorded original");
|
|
110
|
+
|
|
86
111
|
console.log("OK");
|
|
87
112
|
}
|
package/lib/preset-store.ts
CHANGED
|
@@ -26,6 +26,10 @@ export const CHATBOX_DIALOG_KEY = "chatboxDialog";
|
|
|
26
26
|
export const BUDGET_DAY_KEY = "budgetDay";
|
|
27
27
|
export const BUDGET_MONTH_KEY = "budgetMonth";
|
|
28
28
|
export const BUDGET_ENFORCE_KEY = "budgetEnforce";
|
|
29
|
+
/** Transcript render cache: `"On"` / `"Off"`, absent reads as `"On"`. */
|
|
30
|
+
export const RENDER_CACHE_KEY = "renderCache";
|
|
31
|
+
/** Remote proxy payload limit: `"Off"` or `"<N> MB"`, absent reads as `"1 MB"`. */
|
|
32
|
+
export const PAYLOAD_LIMIT_KEY = "payloadLimit";
|
|
29
33
|
|
|
30
34
|
// Resolved per call, not at import: the self-check points getAgentDir() at a fixture dir.
|
|
31
35
|
// Everything pi-arnative writes lives in one folder (agent dir/arnative); the config moved
|
|
@@ -81,6 +85,11 @@ export function loadChoice<T extends string>(key: string, allowed: readonly T[])
|
|
|
81
85
|
return typeof value === "string" && (allowed as readonly string[]).includes(value) ? (value as T) : undefined;
|
|
82
86
|
}
|
|
83
87
|
|
|
88
|
+
/** Raw stored value for `key` (used by callers with custom parsers like `payloadLimit`). */
|
|
89
|
+
export function loadSetting(key: string): unknown {
|
|
90
|
+
return readConfig()[key];
|
|
91
|
+
}
|
|
92
|
+
|
|
84
93
|
/** The stored value for `key` as a finite number in `[min, max]`, or undefined when absent, empty,
|
|
85
94
|
* unparsable or out of range. Amounts are stored as strings (`"5"`, `""` = unset) because
|
|
86
95
|
* `loadChoice` only accepts strings from an allowed set, so numbers get their own reader. */
|
|
@@ -93,7 +102,7 @@ export function loadNumber(key: string, range: { min: number; max: number }): nu
|
|
|
93
102
|
/** Reading order of `config.json`: the presets in the order the settings menu shows them,
|
|
94
103
|
* then `layoutVersion`, then anything else (a key from another module or a newer version).
|
|
95
104
|
* Times a user edits the file by hand or reads it back. */
|
|
96
|
-
const KEY_ORDER = ["headerPreset", "footerPreset", "footerCost", "chatboxPreset", "chatboxPrompt", "chatboxDialog", "budgetDay", "budgetMonth", "budgetEnforce", "spinnerPreset", "spinnerGradient", "layoutVersion", "autoCompact", "modelHeal"];
|
|
105
|
+
const KEY_ORDER = ["headerPreset", "footerPreset", "footerCost", "chatboxPreset", "chatboxPrompt", "chatboxDialog", "budgetDay", "budgetMonth", "budgetEnforce", "spinnerPreset", "spinnerGradient", "layoutVersion", "autoCompact", "payloadLimit", "modelHeal", "renderCache"];
|
|
97
106
|
|
|
98
107
|
/** The record in {@link KEY_ORDER}; unknown keys keep the order they were written in. */
|
|
99
108
|
function ordered(record: Record<string, unknown>): Record<string, unknown> {
|
package/lib/status-widget.ts
CHANGED
|
@@ -55,24 +55,13 @@ export function statusRows(th: FgTheme, rows: string[], width = Number.POSITIVE_
|
|
|
55
55
|
return Number.isFinite(width) ? lines.map((line) => truncateToWidth(line, width, "")) : lines;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/** Key for the one-line change notice above the editor. */
|
|
59
|
-
export const NOTICE_KEY = "arnative-notice";
|
|
60
|
-
/** How long a change notice stays before it clears itself. */
|
|
61
|
-
export const NOTICE_MS = 6_000;
|
|
62
|
-
let noticeTimer: ReturnType<typeof setTimeout> | undefined;
|
|
63
|
-
|
|
64
58
|
/**
|
|
65
|
-
* State what the last change did,
|
|
66
|
-
*
|
|
67
|
-
*
|
|
59
|
+
* State what the last change did, as a transcript notify (like pi-jev-eye) instead of the
|
|
60
|
+
* widget slot above the editor: the widget covered the prompt, while a scrollback line
|
|
61
|
+
* stays visible without blocking anything. A UI without notify (RPC/headless) is left alone.
|
|
68
62
|
*/
|
|
69
|
-
export function announce(ui: {
|
|
70
|
-
|
|
71
|
-
ui.setWidget(NOTICE_KEY, [message]);
|
|
72
|
-
if (noticeTimer) clearTimeout(noticeTimer);
|
|
73
|
-
noticeTimer = setTimeout(() => ui.setWidget?.(NOTICE_KEY, undefined), NOTICE_MS);
|
|
74
|
-
// Do not hold the process open just to hide a notice.
|
|
75
|
-
(noticeTimer as { unref?(): void }).unref?.();
|
|
63
|
+
export function announce(ui: { notify?(message: string, type?: string): void } | undefined, message: string): void {
|
|
64
|
+
ui?.notify?.("[arnative] " + message, "info");
|
|
76
65
|
}
|
|
77
66
|
|
|
78
67
|
if (isMain(import.meta.url)) {
|
package/lib/usage-store.ts
CHANGED
|
@@ -88,10 +88,10 @@ function addToRollup(r: Rollup, e: UsageEntry): void {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/** A time window the dashboard can show. `all` is the whole history. */
|
|
91
|
-
export type UsageRange = "all" | "today" | "7d" | "30d"
|
|
91
|
+
export type UsageRange = "all" | "today" | "7d" | "30d";
|
|
92
92
|
|
|
93
93
|
/** Tab order of the range bar. */
|
|
94
|
-
export const USAGE_RANGES: readonly UsageRange[] = ["all", "today", "7d", "30d"
|
|
94
|
+
export const USAGE_RANGES: readonly UsageRange[] = ["all", "today", "7d", "30d"];
|
|
95
95
|
|
|
96
96
|
/** UTC day bucket key (`YYYY-MM-DD`) of a timestamp. UTC on purpose: local time would make the
|
|
97
97
|
* on-disk cache depend on the timezone of the machine that wrote it, so a restore elsewhere
|
|
@@ -100,7 +100,7 @@ export function dayKey(ms: number): string {
|
|
|
100
100
|
return new Date(ms > 0 ? ms : 0).toISOString().slice(0, 10);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
/** UTC midnight where `range` starts: today, 7 or 30 calendar days back
|
|
103
|
+
/** UTC midnight where `range` starts: today, 7 or 30 calendar days back.
|
|
104
104
|
* `undefined` for `all`, which has no floor. UTC to match the day buckets: a local-midnight
|
|
105
105
|
* floor would cut a UTC+7 "today" at 7am local and drop the morning's spend. */
|
|
106
106
|
export function rangeStart(range: UsageRange, now = Date.now()): number | undefined {
|
|
@@ -108,8 +108,7 @@ export function rangeStart(range: UsageRange, now = Date.now()): number | undefi
|
|
|
108
108
|
const d = new Date(now);
|
|
109
109
|
d.setUTCHours(0, 0, 0, 0);
|
|
110
110
|
if (range === "today") return d.getTime();
|
|
111
|
-
|
|
112
|
-
else d.setUTCDate(d.getUTCDate() - (range === "7d" ? 6 : 29));
|
|
111
|
+
d.setUTCDate(d.getUTCDate() - (range === "7d" ? 6 : 29));
|
|
113
112
|
return d.getTime();
|
|
114
113
|
}
|
|
115
114
|
|
package/package.json
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
2
|
+
"name": "@bismawy/pi-arnative",
|
|
3
|
+
"version": "0.14.0",
|
|
4
|
+
"description": "Refined aesthetics. Cohesive tools. Built for Pi. Warm themes, rounded tool boxes, tabbed header, compact footer and a /usage dashboard.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi-theme",
|
|
8
|
+
"pi-extension"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/bismawy/pi-arnative.git"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/bismawy/pi-arnative#readme",
|
|
20
|
+
"files": [
|
|
21
|
+
"extensions",
|
|
22
|
+
"lib",
|
|
23
|
+
"themes",
|
|
24
|
+
"CHANGELOG.md",
|
|
25
|
+
"LICENSE",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"pi": {
|
|
29
|
+
"image": "https://raw.githubusercontent.com/bismawy/pi-arnative/main/assets/banner.webp",
|
|
30
|
+
"extensions": [
|
|
31
|
+
"./extensions/*.ts"
|
|
32
|
+
],
|
|
33
|
+
"themes": [
|
|
34
|
+
"./themes/*.json"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@earendil-works/pi-ai": "*",
|
|
39
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
40
|
+
"@earendil-works/pi-tui": "*"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"dev": "pi --extension ./extensions/tools.ts --extension ./extensions/section-headers.ts --extension ./extensions/footer.ts --extension ./extensions/timestamps.ts --extension ./extensions/ui-render-tweaks.ts --extension ./extensions/render-cache.ts --extension ./extensions/usage.ts --extension ./extensions/usage-export.ts --extension ./extensions/budget.ts --extension ./extensions/animations.ts --extension ./extensions/autocompact.ts --extension ./extensions/model-heal.ts --extension ./extensions/todos.ts --extension ./extensions/arnative.ts",
|
|
44
|
+
"test": "node lib/box.ts && node lib/patch.ts && node lib/ansi.ts && node lib/color.ts && node lib/shortcuts.ts && node lib/status-widget.ts && node lib/preset-store.ts && node lib/spinner.ts && node lib/todos.ts && node lib/usage-store.ts && node themes/gen-themes.mjs --check && node extensions/tools.ts && node lib/list-picker.ts && node lib/compat.ts && node lib/provider.ts && node lib/model-heal.ts && node extensions/footer.ts && node extensions/timestamps.ts && node extensions/ui-render-tweaks.ts && node extensions/render-cache.ts && node extensions/usage.ts && node extensions/usage-export.ts && node extensions/animations.ts && node extensions/autocompact.ts && node extensions/budget.ts && node extensions/model-heal.ts && node extensions/todos.ts && node extensions/arnative.ts && node scripts/reporter.mjs --self-check && node --test --test-reporter=./scripts/reporter.mjs",
|
|
45
|
+
"preview": "node scripts/preview.mjs",
|
|
46
|
+
"overlay": "node scripts/overlay.mjs",
|
|
47
|
+
"themes": "node themes/gen-themes.mjs",
|
|
48
|
+
"release:check": "node scripts/release-check.mjs pre-tag",
|
|
49
|
+
"prepublishOnly": "npm test && node scripts/release-check.mjs pre-publish"
|
|
50
|
+
}
|
|
51
51
|
}
|