@bismawy/pi-arnative 0.12.0 → 0.13.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 +28 -6
- package/README.md +13 -4
- package/extensions/arnative.ts +102 -19
- package/extensions/autocompact.ts +659 -63
- 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/lib/list-picker.ts +11 -3
- package/lib/patch.ts +26 -1
- package/lib/preset-store.ts +3 -1
- package/lib/status-widget.ts +5 -16
- package/package.json +3 -3
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
|
}
|
package/lib/list-picker.ts
CHANGED
|
@@ -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();
|
|
@@ -448,9 +451,14 @@ if (isMain(import.meta.url)) {
|
|
|
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
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
|
|
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,8 @@ 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";
|
|
29
31
|
|
|
30
32
|
// Resolved per call, not at import: the self-check points getAgentDir() at a fixture dir.
|
|
31
33
|
// Everything pi-arnative writes lives in one folder (agent dir/arnative); the config moved
|
|
@@ -93,7 +95,7 @@ export function loadNumber(key: string, range: { min: number; max: number }): nu
|
|
|
93
95
|
/** Reading order of `config.json`: the presets in the order the settings menu shows them,
|
|
94
96
|
* then `layoutVersion`, then anything else (a key from another module or a newer version).
|
|
95
97
|
* 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"];
|
|
98
|
+
const KEY_ORDER = ["headerPreset", "footerPreset", "footerCost", "chatboxPreset", "chatboxPrompt", "chatboxDialog", "budgetDay", "budgetMonth", "budgetEnforce", "spinnerPreset", "spinnerGradient", "layoutVersion", "autoCompact", "modelHeal", "renderCache"];
|
|
97
99
|
|
|
98
100
|
/** The record in {@link KEY_ORDER}; unknown keys keep the order they were written in. */
|
|
99
101
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bismawy/pi-arnative",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
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",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@earendil-works/pi-tui": "*"
|
|
41
41
|
},
|
|
42
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/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/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",
|
|
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
45
|
"preview": "node scripts/preview.mjs",
|
|
46
46
|
"overlay": "node scripts/overlay.mjs",
|
|
47
47
|
"themes": "node themes/gen-themes.mjs",
|