@bismawy/pi-arnative 0.8.1 → 0.8.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 +12 -1
- package/extensions/footer.ts +9 -8
- package/extensions/section-headers.ts +6 -7
- package/extensions/timestamps.ts +12 -11
- package/extensions/tools.ts +112 -28
- package/extensions/ui-render-tweaks.ts +34 -45
- package/lib/patch.ts +87 -0
- package/lib/spinner.ts +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.8.2] - 2026-10-28
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- **Test output uses the arnative glyphs.** Those marks come from Node, not from this repo: the built-in `spec` reporter paints `U+2714 U+2716 U+2139 U+26F3` and a direct `node --test` has no hook to restyle it. `scripts/reporter.mjs` replaces the reporter instead, emitting `U+2713` pass, `U+2717` fail, `U+1F6C8` summary and `U+2691` file-level failure, with the assertion message and stack kept. `npm test` passes `--test-reporter=./scripts/reporter.mjs`; `NODE_OPTIONS=--test-reporter=./scripts/reporter.mjs node --test` applies it to every run. A failing run still exits non-zero (verified with a temporary failing test).
|
|
7
|
+
|
|
8
|
+
### Fixed
|
|
9
|
+
- **`/reload` applies every patch now, in all five patched files.** `footer.ts` (2-line footer), `timestamps.ts` (bubble clock), `section-headers.ts` (loaded-resources tabs) and `ui-render-tweaks.ts` (reload box, selection colors, accent pill, select rows, package box, status widget, compaction line) sat behind `globalThis` guards, so only the first load's closures were ever installed and a UI fix needed a full pi restart. `lib/patch.ts` holds the one implementation: pi's method is recorded on the prototype under a symbol, every installed patch is marked, and each module reinstalls on load. `test/patch-reload.test.ts` imports all five modules twice and fails if a slot keeps the old patch (proven by temporarily restoring the guard: 2/5 fail).
|
|
10
|
+
- **No double box after `/reload`.** The reinstall captured the previous arnative patch as "the original", so the new patch wrapped its box around the old one (`✓ memory_write` inside a box inside a box, two `✓` on one row). Only an unmarked method is now taken as the original, and the self-check re-imports the module and asserts one box per call (`extensions/tools.ts`).
|
|
11
|
+
- **`/reload` now applies renderer changes.** Both `ToolExecutionComponent` prototype patches (gap strip, box/boxed-renderer routing) sat behind a `globalThis` guard. That flag survives extension reload, so only the first load's closures were ever installed and a UI fix needed a full pi restart. The originals now live on the prototype under a symbol and the patches reinstall on every module load; the self-check re-imports the module once to pin it (`extensions/tools.ts`).
|
|
12
|
+
- **MCP calls keep the arnative box.** pi-mcp-adapter ≥ 2.3x defaults to `toolResultRendering: "compact"`, and that mode declares `renderShell: "self"` while painting flat text (`mcp call x @ y`, no border). The generic boxing predicate read `self` as "this tool draws its own box", so every MCP call and result fell back to that flat line. The MCP names now stay boxed whatever shell they declare, and the `mcp`/`mcp__<server>` call box names the invoked tool (`✓ mcp cloudflare_execute @ cloudflare`) instead of reusing the adapter's flat line. Verified through `ToolExecutionComponent` in the self-check (`extensions/tools.ts`).
|
|
13
|
+
|
|
3
14
|
## [0.8.1] - 2026-10-26
|
|
4
15
|
|
|
5
16
|
### Changed
|
|
@@ -86,7 +97,7 @@
|
|
|
86
97
|
### Changed
|
|
87
98
|
- **`UsageModalComponent.hintText` is gone: the render path calls `legendUsage(width)` directly.** A private one-line method that returned another function added a name with no behaviour, so the call site now states what it wants (`extensions/usage.ts`).
|
|
88
99
|
- **`Claudeon`: the `Claude` preset, renamed and restyled — inspired by Claude.** The preset was called `Claude` and reused Claude Code's own dingbats; it is now `Claudeon`, a mark of this package's own that reads as the Claude-style pulse without borrowing Claude's name for a glyph set Claude does not use. The attribution lives in the row's note (`inspired by Claude — pulsing marks, 120ms`) rather than only in the code, and the paint mode and colour constant follow (`claude` → `claudeon`, `CLAUDE_RGB` → `CLAUDEON_RGB`); the grey-orange mark colour is kept, because that colour is what makes the pulse read as the Claude-style spinner. The preset had not shipped yet, so no stored config can reference the old name (`lib/spinner.ts`, `extensions/animations.ts`).
|
|
89
|
-
- **`Claudeon`'s frames are native-only, so the row cannot walk sideways.** The old set (`· ✢
|
|
100
|
+
- **`Claudeon`'s frames are native-only, so the row cannot walk sideways.** The old set (`· ✢ U+2733 * ✶ ✻ ✽`) mixed font-fallback widths: `✢` `✻` `✽` are absent from most monospace faces, so the terminal served them from a fallback font — measured in the terminal face (JetBrainsMono Nerd Font) `✢`/`✤`/`✻`/`✽`/`❋` advance **1.48** cells and `U+2733` **2.29**, against a **1.00** native cell, so the label shifted on every tick that used one and `U+2733` sheared the row. The set is now `· * ⋆ ✶` (U+00B7, U+002A, U+22C6, U+2736) — four marks that every monospace face checked (JetBrainsMono Nerd Font, Consolas, Cascadia, Lucida, Courier) reports at exactly 1.00 — giving an 8-frame there-and-back loop (`· * ⋆ ✶ ✶ ⋆ * ·`, the peak held for two frames as elsewhere in the package) at 120ms, so the displacement is 0.00 cells. There is no fifth mark to add: a scan of all 86 installed families found none covering the Dingbats block at ~1 em (`lib/spinner.ts`).
|
|
90
101
|
|
|
91
102
|
## [0.5.3] - 2026-10-14
|
|
92
103
|
|
package/extensions/footer.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { softOf, softSecondaryOf, stripAnsi } from "../lib/ansi.ts";
|
|
|
16
16
|
import { assert, isMain } from "../lib/check.ts";
|
|
17
17
|
import { capitalize, markedLabels, modelDisplayParts } from "../lib/format.ts";
|
|
18
18
|
import { IS_WINDOWS_LIKE, SHORTCUT_RELOAD, SHORTCUT_TOGGLE_FOOTER } from "../lib/shortcuts.ts";
|
|
19
|
+
import { markPatched, originalOf } from "../lib/patch.ts";
|
|
19
20
|
import { formatTokens } from "../lib/usage-store.ts";
|
|
20
21
|
import { FOOTER_PRESET_KEY as FOOTER_PRESET_CONFIG_KEY, loadChoice, resetPresetCache, saveChoice } from "../lib/preset-store.ts";
|
|
21
22
|
import { EDITOR_KEY, activeSpinnerGradient, activeSpinnerPreset } from "./animations.ts";
|
|
@@ -73,17 +74,17 @@ export function setFooterPreset(name: FooterPreset, ctx: ExtensionContext): void
|
|
|
73
74
|
applyFooterPreset(ctx);
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
// Intercept the built-in FooterComponent to force a pure 2-line footer
|
|
77
|
-
|
|
78
|
-
if (FooterComponent?.prototype?.render
|
|
79
|
-
|
|
80
|
-
const origRender =
|
|
81
|
-
|
|
77
|
+
// Intercept the built-in FooterComponent to force a pure 2-line footer.
|
|
78
|
+
// Reinstalled on every load (lib/patch.ts): `/reload` must pick up a footer change.
|
|
79
|
+
if (FooterComponent?.prototype?.render) {
|
|
80
|
+
const proto = FooterComponent.prototype as any;
|
|
81
|
+
const origRender = originalOf<(this: any, width: number) => string[]>(proto, "render");
|
|
82
|
+
proto.render = markPatched(function (this: any, width: number): string[] {
|
|
82
83
|
// "Pi (system)" preset = pi's own footer, so keep its stock line count.
|
|
83
84
|
if (activeFooterPreset() === "Pi (system)") return origRender.call(this, width);
|
|
84
85
|
const lines = origRender.call(this, width);
|
|
85
86
|
return lines.length > 2 ? lines.slice(0, 2) : lines;
|
|
86
|
-
};
|
|
87
|
+
});
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
let activeThemeProxy: { fg(color: string, text: string): string; bg?(color: string, text: string): string } | null = null;
|
|
@@ -1489,7 +1490,7 @@ if (isMain(import.meta.url)) {
|
|
|
1489
1490
|
// Self-check: the ponytail glyph. \uef51 carries no outline in the Windows Nerd Font
|
|
1490
1491
|
// build and renders blank there, so the status silently loses its icon (this is what
|
|
1491
1492
|
// a past commit did). Pin the codepoint so a swap back to an invisible one fails here.
|
|
1492
|
-
const ponyLine = ponytailStatusLine("
|
|
1493
|
+
const ponyLine = ponytailStatusLine("ponytail: FULL", (s) => s, (s) => s, (s) => s);
|
|
1493
1494
|
assert(ponyLine.includes("\uef04"), "the ponytail status renders the \\uef04 horse, not the blank \\uef51");
|
|
1494
1495
|
assert(!ponyLine.includes("\uef51"), "the blank \\uef51 glyph must never come back");
|
|
1495
1496
|
assert(ponytailStatusLine("ponytail: LITE", (s) => s, (s) => s, (s) => s).includes("LITE"), "the ponytail mode is read from the status text");
|
|
@@ -39,6 +39,7 @@ import { SHORTCUT_NEW_SESSION, SHORTCUT_NEXT_TAB, SHORTCUT_RELOAD } from "../lib
|
|
|
39
39
|
import { HEADER_PRESET_KEY as HEADER_PRESET_CONFIG_KEY, loadChoice, saveChoice } from "../lib/preset-store.ts";
|
|
40
40
|
import { formatTokens, getModelAllTimeUsage } from "../lib/usage-store.ts";
|
|
41
41
|
|
|
42
|
+
import { patchOnce } from "../lib/patch.ts";
|
|
42
43
|
export type TabKey = "Model" | "Directory" | "Context" | "Skills" | "Extensions" | "Shortcut";
|
|
43
44
|
|
|
44
45
|
// Tab order for the next-tab shortcut and for the menu line.
|
|
@@ -706,16 +707,14 @@ export function extensionIssuesLines(th: BoxTheme | null, width: number, rows: s
|
|
|
706
707
|
// Hooks the shared `app.tools.expand` key: `ctrl+o to expand` -> `[ctrl+o to expand]`.
|
|
707
708
|
const wrapHint = (key: string): string => `[${key} to expand]`;
|
|
708
709
|
|
|
709
|
-
// Intercept loadedResourcesContainer: capture data for the tabs and hide pi's own display
|
|
710
|
-
|
|
711
|
-
if (UserMessageComponent?.prototype
|
|
712
|
-
(globalThis as Record<symbol, boolean>)[SECTION_HEADER_KEY] = true;
|
|
710
|
+
// Intercept loadedResourcesContainer: capture data for the tabs and hide pi's own display.
|
|
711
|
+
// Reinstalled on every load (lib/patch.ts), otherwise `/reload` keeps the first closure.
|
|
712
|
+
if (UserMessageComponent?.prototype) {
|
|
713
713
|
const containerProto = Object.getPrototypeOf(UserMessageComponent.prototype) as {
|
|
714
714
|
addChild?: (child: unknown) => unknown;
|
|
715
715
|
};
|
|
716
716
|
if (typeof containerProto?.addChild === "function") {
|
|
717
|
-
|
|
718
|
-
containerProto.addChild = function (child: any): unknown {
|
|
717
|
+
patchOnce(containerProto, "addChild", (origAddChild) => function (this: any, child: any): unknown {
|
|
719
718
|
// "Pi (system)" preset = pi's own header, so leave pi's startup list untouched.
|
|
720
719
|
if (activeHeaderPreset() === "Pi (system)") return origAddChild.call(this, child);
|
|
721
720
|
try {
|
|
@@ -765,7 +764,7 @@ if (UserMessageComponent?.prototype && !(globalThis as Record<symbol, boolean>)[
|
|
|
765
764
|
// fail-safe
|
|
766
765
|
}
|
|
767
766
|
return origAddChild.call(this, child);
|
|
768
|
-
};
|
|
767
|
+
});
|
|
769
768
|
}
|
|
770
769
|
}
|
|
771
770
|
|
package/extensions/timestamps.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { AssistantMessageComponent, UserMessageComponent, type ExtensionAPI } fr
|
|
|
14
14
|
import { sliceByColumn, visibleWidth } from "@earendil-works/pi-tui";
|
|
15
15
|
import { ansiBgOpen, stripAnsi, themeOf } from "../lib/ansi.ts";
|
|
16
16
|
import { assert, isMain } from "../lib/check.ts";
|
|
17
|
+
import { markPatched, originalOf } from "../lib/patch.ts";
|
|
17
18
|
|
|
18
19
|
// Shared across reloads: /reload re-imports this module (moduleCache: false), but the
|
|
19
20
|
// prototype patches below survive on the class, so the patched closure and the newly
|
|
@@ -23,10 +24,9 @@ import { assert, isMain } from "../lib/check.ts";
|
|
|
23
24
|
type ThemeProxy = { fg(color: string, text: string): string; bg?(color: string, text: string): string } | null;
|
|
24
25
|
const TS_STATE_KEY = Symbol.for("pi-arnative.chatTimestampState");
|
|
25
26
|
const tsState = ((globalThis as Record<symbol, unknown>)[TS_STATE_KEY] ??= {
|
|
26
|
-
patched: false,
|
|
27
27
|
map: new Map<string, number>(),
|
|
28
28
|
theme: null as ThemeProxy,
|
|
29
|
-
}) as {
|
|
29
|
+
}) as { map: Map<string, number>; theme: ThemeProxy };
|
|
30
30
|
const USER_TIMESTAMPS_MAP = tsState.map;
|
|
31
31
|
|
|
32
32
|
function userTextOf(message: { content?: unknown }): string {
|
|
@@ -126,12 +126,12 @@ export function placeTimeAtRight(
|
|
|
126
126
|
return `${leftPart}${bgOpen}${pad}${timeBadge} ${reset}`;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
// Both patches reinstall on every load (lib/patch.ts) so a `/reload` applies them.
|
|
130
|
+
if (UserMessageComponent?.prototype?.render || AssistantMessageComponent?.prototype?.render) {
|
|
132
131
|
if (UserMessageComponent?.prototype?.render) {
|
|
133
|
-
const
|
|
134
|
-
|
|
132
|
+
const proto = UserMessageComponent.prototype as any;
|
|
133
|
+
const origRender = originalOf<(this: any, width: number) => string[]>(proto, "render");
|
|
134
|
+
proto.render = markPatched(function (this: any, width: number): string[] {
|
|
135
135
|
const lines = origRender.call(this, width);
|
|
136
136
|
if (lines.length < 2) return lines;
|
|
137
137
|
|
|
@@ -167,12 +167,13 @@ if (!tsState.patched) {
|
|
|
167
167
|
lines[0] = `${prefix}${placeTimeAtRight(rest, width, badge, timeW, bgOpen)}`;
|
|
168
168
|
}
|
|
169
169
|
return lines;
|
|
170
|
-
};
|
|
170
|
+
});
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
if (AssistantMessageComponent?.prototype?.render) {
|
|
174
|
-
const
|
|
175
|
-
|
|
174
|
+
const proto = AssistantMessageComponent.prototype as any;
|
|
175
|
+
const origRender = originalOf<(this: any, width: number) => string[]>(proto, "render");
|
|
176
|
+
proto.render = markPatched(function (this: any, width: number): string[] {
|
|
176
177
|
const lines = origRender.call(this, width);
|
|
177
178
|
const lastMsg = (this as { lastMessage?: AssistantMessage }).lastMessage;
|
|
178
179
|
|
|
@@ -217,7 +218,7 @@ if (!tsState.patched) {
|
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
return lines;
|
|
220
|
-
};
|
|
221
|
+
});
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
224
|
|
package/extensions/tools.ts
CHANGED
|
@@ -42,6 +42,7 @@ import { renderBoxLines as box } from "../lib/box.ts";
|
|
|
42
42
|
import { stripAnsi, softSecondaryOf } from "../lib/ansi.ts";
|
|
43
43
|
import { assert, isMain } from "../lib/check.ts";
|
|
44
44
|
import { expandKeyName } from "../lib/format.ts";
|
|
45
|
+
import { markPatched, originalOf } from "../lib/patch.ts";
|
|
45
46
|
|
|
46
47
|
type Theme = { fg(color: string, text: string): string; bg?(color: string, text: string): string };
|
|
47
48
|
type TResult = { content: Array<{ type: string; text?: string }>; isError?: boolean; details?: any };
|
|
@@ -246,16 +247,18 @@ export function stripEdgesKeepingImages(lines: string[]): string[] {
|
|
|
246
247
|
return [...head, ...lines.slice(firstImage)];
|
|
247
248
|
}
|
|
248
249
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
ToolExecutionComponent.prototype
|
|
250
|
+
// The patches below reinstall on every module load (pi's /reload re-evaluates the
|
|
251
|
+
// extension in the same process), so a UI fix applies without restarting pi; see
|
|
252
|
+
// lib/patch.ts for the originals/mark bookkeeping that makes that safe.
|
|
253
|
+
if (ToolExecutionComponent?.prototype?.render) {
|
|
254
|
+
const proto = ToolExecutionComponent.prototype as any;
|
|
255
|
+
const origRender = originalOf<(this: any, width: number) => string[]>(proto, "render");
|
|
256
|
+
proto.render = markPatched(function (this: any, width: number): string[] {
|
|
254
257
|
const lines = origRender.call(this, width);
|
|
255
258
|
return OWN_BOX.has(this.toolName) || boxTheirRenderers(this) || !hasOwnRendererDef(this)
|
|
256
259
|
? stripEdgesKeepingImages(lines)
|
|
257
260
|
: lines;
|
|
258
|
-
};
|
|
261
|
+
});
|
|
259
262
|
}
|
|
260
263
|
|
|
261
264
|
// --- Tools without their own renderer: same box, one-line summary ---
|
|
@@ -311,12 +314,16 @@ const MCP_TOOL = (name: string): boolean => name === "mcp" || name === "mcpScrip
|
|
|
311
314
|
// `powershell`/`ls` (their definitions spread `renderCall`/`renderResult` onto the
|
|
312
315
|
// tool object) and pi-mcp-adapter (`renderShell: "default"`) all fall in by shape.
|
|
313
316
|
//
|
|
317
|
+
// MCP is boxed even when pi-mcp-adapter declares `renderShell: "self"`: since 2.3x
|
|
318
|
+
// its default `toolResultRendering: "compact"` paints flat text (`mcp call x @ y`,
|
|
319
|
+
// no border), so a `self` shell there means "no box", not "my own box".
|
|
320
|
+
//
|
|
314
321
|
// `source_check` is the single exception: its partial phase (curator URLs + approval
|
|
315
322
|
// state) would disappear because our partial path returns nothing.
|
|
316
323
|
const NOT_BOXED = new Set(["source_check"]);
|
|
317
324
|
const boxTheirRenderers = (self: any): boolean =>
|
|
318
325
|
Boolean(self.toolDefinition) &&
|
|
319
|
-
self.toolDefinition.renderShell !== "self" &&
|
|
326
|
+
(self.toolDefinition.renderShell !== "self" || MCP_TOOL(self.toolName)) &&
|
|
320
327
|
!NOT_BOXED.has(self.toolName);
|
|
321
328
|
|
|
322
329
|
// The MCP box title names the invoked tool (full args when expanded).
|
|
@@ -368,13 +375,11 @@ const boxedRows = (icon: string, lines: string[]): string[] => {
|
|
|
368
375
|
*/
|
|
369
376
|
export const boxBgOf = (name: string): string | undefined => (name === "memory_write" ? "customMessageBg" : undefined);
|
|
370
377
|
|
|
371
|
-
|
|
372
|
-
if (ToolExecutionComponent?.prototype?.render && !(globalThis as Record<symbol, boolean>)[DEFAULT_TOOL_KEY]) {
|
|
373
|
-
(globalThis as Record<symbol, boolean>)[DEFAULT_TOOL_KEY] = true;
|
|
378
|
+
if (ToolExecutionComponent?.prototype?.render) {
|
|
374
379
|
const proto = ToolExecutionComponent.prototype as any;
|
|
375
|
-
const origCall = proto
|
|
376
|
-
const origResult = proto
|
|
377
|
-
const origShell = proto
|
|
380
|
+
const origCall = originalOf<(this: any) => any>(proto, "getCallRenderer");
|
|
381
|
+
const origResult = originalOf<(this: any) => any>(proto, "getResultRenderer");
|
|
382
|
+
const origShell = originalOf<(this: any) => string>(proto, "getRenderShell");
|
|
378
383
|
const hasOwnRenderer = (self: any): boolean =>
|
|
379
384
|
!boxTheirRenderers(self) && Boolean(origCall.call(self) || origResult.call(self));
|
|
380
385
|
// pi-fff splits title (renderCall) and result (renderResult) — both merge into one box.
|
|
@@ -387,37 +392,42 @@ if (ToolExecutionComponent?.prototype?.render && !(globalThis as Record<symbol,
|
|
|
387
392
|
// getCallRenderer/getResultRenderer — our patch is bypassed and the call renders
|
|
388
393
|
// as bare name + pretty-printed args. Claim those calls as defined so they take
|
|
389
394
|
// the same box path as any other renderer-less tool.
|
|
390
|
-
const origHasRendererDefinition = proto
|
|
391
|
-
proto.hasRendererDefinition = function (): boolean {
|
|
395
|
+
const origHasRendererDefinition = originalOf<(this: any) => boolean>(proto, "hasRendererDefinition");
|
|
396
|
+
proto.hasRendererDefinition = markPatched(function (this: any): boolean {
|
|
392
397
|
return origHasRendererDefinition.call(this) || this.toolDefinition === undefined;
|
|
393
|
-
};
|
|
398
|
+
});
|
|
394
399
|
|
|
395
|
-
proto.getRenderShell = function (): string {
|
|
400
|
+
proto.getRenderShell = markPatched(function (this: any): string {
|
|
396
401
|
if (boxTheirRenderers(this)) return "self";
|
|
397
402
|
return hasOwnRenderer(this) ? origShell.call(this) : "self";
|
|
398
|
-
};
|
|
403
|
+
});
|
|
399
404
|
|
|
400
|
-
proto.getCallRenderer = function () {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
// Chrome DevTools' own renderCall is a bare line
|
|
405
|
+
proto.getCallRenderer = markPatched(function (this: any) {
|
|
406
|
+
const name: string = this.toolName;
|
|
407
|
+
const mine = boxTheirRenderers(this);
|
|
408
|
+
const own = origCall.call(this);
|
|
409
|
+
// Chrome DevTools' own renderCall is a bare line and pi-mcp-adapter's compact one
|
|
410
|
+
// is the same flat text; ours replaces both (icon + name + invoked MCP tool).
|
|
405
411
|
if (own && !mine && !CDP_NAME.has(name)) return own;
|
|
406
412
|
return (args: any, th: Theme, ctx: TCtx) =>
|
|
407
413
|
new Lines((width) => {
|
|
408
414
|
if ((ctx.state as Record<string, unknown> | undefined)?.hasResult) return [];
|
|
409
415
|
const icon = CDP_NAME.has(name) ? th.fg("accent", CDP_ICON) : th.fg("warning", spinIcon());
|
|
410
|
-
const theirs =
|
|
416
|
+
const theirs =
|
|
417
|
+
own && !CDP_NAME.has(name) && !MCP_TOOL(name)
|
|
418
|
+
? componentLines(safeCall(() => own.call(this, args, th, ctx)), width - 6)
|
|
419
|
+
: [];
|
|
411
420
|
if (name === "todo" && theirs.length)
|
|
412
421
|
return box(th, width, formatTodoRows(theirs, th), "toolPendingBg");
|
|
413
422
|
if (mine && theirs.length)
|
|
414
423
|
return box(th, width, boxedRows(icon, capped(th, theirs, Boolean(this.expanded))));
|
|
415
424
|
const inner = Math.max(8, width - 4);
|
|
416
|
-
|
|
425
|
+
const rows = titleRow(th, icon, th.fg("accent", displayName(name)), mcpInfo(name, args, th), inner, "", false);
|
|
426
|
+
return box(th, width, rows, boxBgOf(name));
|
|
417
427
|
});
|
|
418
|
-
};
|
|
428
|
+
});
|
|
419
429
|
|
|
420
|
-
proto.getResultRenderer = function () {
|
|
430
|
+
proto.getResultRenderer = markPatched(function (this: any) {
|
|
421
431
|
const name: string = this.toolName;
|
|
422
432
|
const own = origResult.call(this);
|
|
423
433
|
// pi-fff splits title (renderCall) and result (renderResult); both go in one box.
|
|
@@ -480,7 +490,7 @@ if (ToolExecutionComponent?.prototype?.render && !(globalThis as Record<symbol,
|
|
|
480
490
|
return box(th, width, rows, boxBgOf(name));
|
|
481
491
|
});
|
|
482
492
|
};
|
|
483
|
-
};
|
|
493
|
+
});
|
|
484
494
|
}
|
|
485
495
|
|
|
486
496
|
// todo line format: \uf14a icon (success color) in the title, resHead prefix on the status line.
|
|
@@ -1147,6 +1157,40 @@ if (isMain(import.meta.url)) {
|
|
|
1147
1157
|
).render(96);
|
|
1148
1158
|
assert(mcpFull.length > mcpOut.length, "mcp: expand shows the full dump + args");
|
|
1149
1159
|
|
|
1160
|
+
// pi-mcp-adapter >= 2.3x defaults to `toolResultRendering: "compact"`, which sets
|
|
1161
|
+
// `renderShell: "self"` and paints flat text (`mcp call x @ y`, no border). That
|
|
1162
|
+
// `self` means "no box", not "my own box", so the MCP names must still be boxed.
|
|
1163
|
+
const mcpCompact = { toolName: "mcp", toolDefinition: { renderShell: "self", renderCall: mcpTheirs, renderResult: mcpTheirs } };
|
|
1164
|
+
assert(
|
|
1165
|
+
ToolExecutionComponent.prototype.getRenderShell.call(mcpCompact) === "self" &&
|
|
1166
|
+
(ToolExecutionComponent.prototype.getResultRenderer.call(mcpCompact) as any) !== mcpTheirs,
|
|
1167
|
+
"mcp compact (renderShell self): still boxed, their flat renderer skipped",
|
|
1168
|
+
);
|
|
1169
|
+
const mcpCompactOut = (ToolExecutionComponent.prototype.getResultRenderer.call(mcpCompact) as any)(
|
|
1170
|
+
{ content: [{ type: "text", text: "ok" }], details: {} },
|
|
1171
|
+
{ expanded: false, isPartial: false },
|
|
1172
|
+
th,
|
|
1173
|
+
{ args: { tool: "cloudflare_execute", server: "cloudflare" }, state: {} },
|
|
1174
|
+
).render(96);
|
|
1175
|
+
assert(
|
|
1176
|
+
mcpCompactOut[0].startsWith("\u256d") && mcpCompactOut.some((l: string) => l.includes("cloudflare_execute @ cloudflare")),
|
|
1177
|
+
"mcp compact: bordered box naming the invoked tool",
|
|
1178
|
+
);
|
|
1179
|
+
const mcpCompactCall = (ToolExecutionComponent.prototype.getCallRenderer.call(mcpCompact) as any)(
|
|
1180
|
+
{ tool: "cloudflare_execute", server: "cloudflare" },
|
|
1181
|
+
th,
|
|
1182
|
+
{ args: {}, state: {} },
|
|
1183
|
+
).render(96);
|
|
1184
|
+
assert(
|
|
1185
|
+
mcpCompactCall[0].startsWith("\u256d") && mcpCompactCall.some((l: string) => l.includes("cloudflare_execute @ cloudflare")),
|
|
1186
|
+
"mcp compact: the running box is ours too (no flat `mcp call ...` line)",
|
|
1187
|
+
);
|
|
1188
|
+
// A non-MCP fourth-party `renderShell: "self"` still draws its own box: untouched.
|
|
1189
|
+
assert(
|
|
1190
|
+
ToolExecutionComponent.prototype.getResultRenderer.call({ toolName: "other_ext", toolDefinition: { renderShell: "self", renderResult: mcpTheirs } })() === "renderer-mcp",
|
|
1191
|
+
"renderShell self outside MCP keeps its own renderer",
|
|
1192
|
+
);
|
|
1193
|
+
|
|
1150
1194
|
// Gap is only stripped for our own box lines.
|
|
1151
1195
|
// The default export registers the tools (filling OWN_BOX); a pi stub suffices.
|
|
1152
1196
|
arnativeTools({
|
|
@@ -1388,5 +1432,45 @@ if (isMain(import.meta.url)) {
|
|
|
1388
1432
|
assert(!TIMINGS.has("call_0") && TIMINGS.has("call_249"), "TIMINGS evicts oldest entries");
|
|
1389
1433
|
TIMINGS.clear();
|
|
1390
1434
|
|
|
1435
|
+
// /reload re-evaluates this module inside the same pi process. The prototype patches
|
|
1436
|
+
// must reinstall with the new closures; a globalThis guard bailed out on the second
|
|
1437
|
+
// load and kept the old ones, so a UI fix never appeared until pi restarted.
|
|
1438
|
+
{
|
|
1439
|
+
const before = ToolExecutionComponent.prototype.getResultRenderer;
|
|
1440
|
+
await import(`${import.meta.url}?reload=1`);
|
|
1441
|
+
const after = ToolExecutionComponent.prototype.getResultRenderer;
|
|
1442
|
+
assert(after !== before, "/reload: the prototype patch reinstalls on re-evaluation");
|
|
1443
|
+
// The stored original must stay pi's own method: capturing our previous patch
|
|
1444
|
+
// wrapped every box in a second one (double border + double ✓).
|
|
1445
|
+
const stored = (ToolExecutionComponent.prototype as any)[Symbol.for("pi-arnative.protoOriginals")];
|
|
1446
|
+
const patchedMark = Symbol.for("pi-arnative.patchedMethod");
|
|
1447
|
+
assert(
|
|
1448
|
+
!stored.render[patchedMark] && !stored.getResultRenderer[patchedMark],
|
|
1449
|
+
"/reload: originals stay pi's own methods, never a previous patch",
|
|
1450
|
+
);
|
|
1451
|
+
const plainAfter = (ToolExecutionComponent.prototype.getResultRenderer.call(noRenderer) as any)(
|
|
1452
|
+
{ content: [{ type: "text", text: "Appended to MEMORY.md" }] },
|
|
1453
|
+
{ expanded: false, isPartial: false },
|
|
1454
|
+
th,
|
|
1455
|
+
{ args: {}, state: {} },
|
|
1456
|
+
).render(60);
|
|
1457
|
+
assert(
|
|
1458
|
+
plainAfter.filter((l: string) => l.startsWith("\u256d")).length === 1,
|
|
1459
|
+
"/reload: a plain tool draws one box, not a box inside a box",
|
|
1460
|
+
);
|
|
1461
|
+
const mcpAfter = (after as any).call(mcpCompact);
|
|
1462
|
+
assert(mcpAfter !== mcpTheirs, "/reload: MCP stays boxed after re-evaluation");
|
|
1463
|
+
const out2 = mcpAfter(
|
|
1464
|
+
{ content: [{ type: "text", text: "ok" }], details: {} },
|
|
1465
|
+
{ expanded: false, isPartial: false },
|
|
1466
|
+
th,
|
|
1467
|
+
{ args: { tool: "cloudflare_execute", server: "cloudflare" }, state: {} },
|
|
1468
|
+
).render(96);
|
|
1469
|
+
assert(
|
|
1470
|
+
out2[0].startsWith("\u256d") && out2.some((l: string) => l.includes("cloudflare_execute @ cloudflare")),
|
|
1471
|
+
"/reload: the box still renders (no double-patch loop, originals kept once)",
|
|
1472
|
+
);
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1391
1475
|
console.log("OK");
|
|
1392
1476
|
}
|
|
@@ -43,6 +43,7 @@ import { ansiBgOpen, getActiveTheme, setActiveTheme, stripAnsi, themeOf, softSec
|
|
|
43
43
|
import { assert, isMain } from "../lib/check.ts";
|
|
44
44
|
import { contrast, oklchToRgb, parseOklch, toHex } from "../lib/color.ts";
|
|
45
45
|
import { expandKeyName } from "../lib/format.ts";
|
|
46
|
+
import { patchOnce } from "../lib/patch.ts";
|
|
46
47
|
|
|
47
48
|
type ActiveTheme = { fg(color: string, text: string): string; bg?(color: string, text: string): string } | null;
|
|
48
49
|
const activeTheme = () => getActiveTheme<Exclude<ActiveTheme, null>>();
|
|
@@ -68,16 +69,15 @@ export function shouldHideReloadBox(lines: readonly string[]): boolean {
|
|
|
68
69
|
const rows = lines.map((l) => stripAnsi(l).trim());
|
|
69
70
|
return rows.every((r) => r === "" || /^[─-]+$/.test(r) || RELOAD_TEXT.includes(r));
|
|
70
71
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
// Every patch below reinstalls on each load (lib/patch.ts): `/reload` re-evaluates the
|
|
73
|
+
// module in the same process, so a `globalThis` guard would freeze the first load.
|
|
74
|
+
if (UserMessageComponent?.prototype) {
|
|
74
75
|
const containerProto = Object.getPrototypeOf(UserMessageComponent.prototype) as { render?: (width: number) => string[] };
|
|
75
76
|
if (typeof containerProto?.render === "function") {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const lines = origContainerRender.call(this, width);
|
|
77
|
+
patchOnce(containerProto, "render", (orig) => function (this: any, width: number): string[] {
|
|
78
|
+
const lines = orig.call(this, width);
|
|
79
79
|
return shouldHideReloadBox(lines) ? [] : lines;
|
|
80
|
-
};
|
|
80
|
+
});
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -86,7 +86,6 @@ if (UserMessageComponent?.prototype && !(globalThis as Record<symbol, boolean>)[
|
|
|
86
86
|
// Drag selection in pi fullscreen: pi only wraps the selection in reverse video
|
|
87
87
|
// (\x1b[7m), unreadable in some terminals/themes. Replaced with explicit colors
|
|
88
88
|
// (bg selectedBg + fg text) so text always stays visible.
|
|
89
|
-
const SELECTION_COLOR_KEY = Symbol.for("pi-arnative.selectionColorsPatched");
|
|
90
89
|
|
|
91
90
|
export function recolorSelection(highlighted: string, fgOpen: string, bgOpen: string): string {
|
|
92
91
|
return highlighted.split("\x1b[7m").join(fgOpen + bgOpen).split("\x1b[27m").join("\x1b[39m\x1b[49m");
|
|
@@ -107,7 +106,6 @@ export function ansiFgOpen(th: { fg?(c: string, t: string): string } | null, col
|
|
|
107
106
|
// (grey) -> accent bg + darkened canvas text (contrast 9.6:1, WCAG AA). pi has no bg
|
|
108
107
|
// token for `accent` (7 exist, see PILL_INK), so the SGR escapes are swapped;
|
|
109
108
|
// `bg("accent")` would throw "Unknown theme background color" and stay unchanged.
|
|
110
|
-
const PILL_KEY = Symbol.for("pi-arnative.accentPill");
|
|
111
109
|
const PILL_MARK = "↓ Jump to latest message";
|
|
112
110
|
const PILL_INK = "toolPendingBg";
|
|
113
111
|
|
|
@@ -143,41 +141,37 @@ export function withAccentPill<T>(
|
|
|
143
141
|
}
|
|
144
142
|
}
|
|
145
143
|
|
|
146
|
-
if (TuiAltScreen?.prototype
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const highlighted = origHighlight.call(this, text);
|
|
144
|
+
if (TuiAltScreen?.prototype) {
|
|
145
|
+
const proto = TuiAltScreen.prototype as any;
|
|
146
|
+
if (typeof proto.applySelectionHighlight === "function") {
|
|
147
|
+
patchOnce(proto, "applySelectionHighlight", (orig) => function (this: any, text: string): string {
|
|
148
|
+
const highlighted = orig.call(this, text);
|
|
152
149
|
const fgOpen = ansiFgOpen(activeTheme());
|
|
153
150
|
const bgOpen = ansiBgOpen(activeTheme(), "selectedBg");
|
|
154
151
|
return fgOpen && bgOpen ? recolorSelection(highlighted, fgOpen, bgOpen) : highlighted;
|
|
155
|
-
};
|
|
152
|
+
});
|
|
156
153
|
}
|
|
157
154
|
}
|
|
158
155
|
|
|
159
|
-
if (TuiAltScreen?.prototype
|
|
160
|
-
(globalThis as Record<symbol, boolean>)[PILL_KEY] = true;
|
|
156
|
+
if (TuiAltScreen?.prototype) {
|
|
161
157
|
const proto = TuiAltScreen.prototype as unknown as {
|
|
162
158
|
compositeScrollToEndIndicator?: (screen: string[], layout: unknown, width: number) => string[];
|
|
163
159
|
};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
proto.compositeScrollToEndIndicator = function (
|
|
160
|
+
if (typeof proto.compositeScrollToEndIndicator === "function") {
|
|
161
|
+
patchOnce(proto, "compositeScrollToEndIndicator", (origComposite) => function (
|
|
167
162
|
this: { scrollToEndIndicator?: (() => string) | undefined },
|
|
168
163
|
screen: string[],
|
|
169
164
|
layout: unknown,
|
|
170
165
|
width: number,
|
|
171
166
|
) {
|
|
172
167
|
return withAccentPill(this, () => origComposite.call(this, screen, layout, width), activeTheme());
|
|
173
|
-
};
|
|
168
|
+
});
|
|
174
169
|
}
|
|
175
170
|
}
|
|
176
171
|
|
|
177
172
|
// 6. Select menus (ctx.ui.select -> ExtensionSelectorComponent.updateList): pi colors the
|
|
178
173
|
// whole selected row accent. Arnative keeps accent on the `→` marker and `·` separators
|
|
179
174
|
// and moves the selected text to soft (accent on themes without the token).
|
|
180
|
-
const SELECT_ROW_KEY = Symbol.for("pi-arnative.selectRowColors");
|
|
181
175
|
|
|
182
176
|
/** Selected row body: `·` separators accent, the text around them soft. */
|
|
183
177
|
export function selectRowText(row: string, th: { fg(c: string, t: string): string }): string {
|
|
@@ -188,16 +182,14 @@ export function selectRowText(row: string, th: { fg(c: string, t: string): strin
|
|
|
188
182
|
.join(th.fg("accent", "·"));
|
|
189
183
|
}
|
|
190
184
|
|
|
191
|
-
if (ExtensionSelectorComponent?.prototype
|
|
192
|
-
(globalThis as Record<symbol, boolean>)[SELECT_ROW_KEY] = true;
|
|
185
|
+
if (ExtensionSelectorComponent?.prototype) {
|
|
193
186
|
const proto = ExtensionSelectorComponent.prototype as unknown as {
|
|
194
187
|
options: string[];
|
|
195
188
|
selectedIndex: number;
|
|
196
189
|
listContainer: { clear(): void; addChild(c: unknown): void };
|
|
197
190
|
updateList(): void;
|
|
198
191
|
};
|
|
199
|
-
|
|
200
|
-
proto.updateList = function (this: typeof proto) {
|
|
192
|
+
patchOnce(proto, "updateList", (origUpdateList) => function (this: typeof proto) {
|
|
201
193
|
const th = activeTheme();
|
|
202
194
|
if (!th) return origUpdateList.call(this); // no theme yet -> pi's default
|
|
203
195
|
this.listContainer.clear();
|
|
@@ -208,7 +200,7 @@ if (ExtensionSelectorComponent?.prototype && !(globalThis as Record<symbol, bool
|
|
|
208
200
|
: ` ${th.fg("text", this.options[i]!)}`;
|
|
209
201
|
this.listContainer.addChild(new Text(text, 1, 0));
|
|
210
202
|
}
|
|
211
|
-
};
|
|
203
|
+
});
|
|
212
204
|
}
|
|
213
205
|
|
|
214
206
|
export default function uiRenderTweaks(pi: ExtensionAPI) {
|
|
@@ -255,13 +247,11 @@ export class PackageUpdateBoxComponent implements Component {
|
|
|
255
247
|
}
|
|
256
248
|
}
|
|
257
249
|
|
|
258
|
-
|
|
259
|
-
if (InteractiveMode?.prototype && !(globalThis as Record<symbol, boolean>)[PACKAGE_BOX_KEY]) {
|
|
260
|
-
(globalThis as Record<symbol, boolean>)[PACKAGE_BOX_KEY] = true;
|
|
250
|
+
if (InteractiveMode?.prototype) {
|
|
261
251
|
const proto = InteractiveMode.prototype as unknown as {
|
|
262
252
|
showPackageUpdateNotification(packages: string[]): void;
|
|
263
253
|
};
|
|
264
|
-
proto
|
|
254
|
+
patchOnce(proto, "showPackageUpdateNotification", () => function (this: typeof proto, packages: string[]) {
|
|
265
255
|
const self = this as unknown as {
|
|
266
256
|
chatContainer: { addChild(c: unknown): void };
|
|
267
257
|
ui: { requestRender(): void };
|
|
@@ -269,7 +259,7 @@ if (InteractiveMode?.prototype && !(globalThis as Record<symbol, boolean>)[PACKA
|
|
|
269
259
|
self.chatContainer.addChild(new Spacer(1));
|
|
270
260
|
self.chatContainer.addChild(new PackageUpdateBoxComponent(packages, activeTheme()));
|
|
271
261
|
self.ui.requestRender();
|
|
272
|
-
};
|
|
262
|
+
});
|
|
273
263
|
}
|
|
274
264
|
|
|
275
265
|
// arnative box border helper -> lib/box.ts (one definition for every box)
|
|
@@ -278,14 +268,16 @@ if (InteractiveMode?.prototype && !(globalThis as Record<symbol, boolean>)[PACKA
|
|
|
278
268
|
// array into unstyled `Text`, so an extension's status line ignores the theme and lands in
|
|
279
269
|
// the default foreground. Every such array is handed to a component factory instead, which
|
|
280
270
|
// receives the live theme: the arnative mark leads the block and every row is `dim`.
|
|
281
|
-
|
|
282
|
-
if (InteractiveMode?.prototype && !(globalThis as Record<symbol, boolean>)[STATUS_WIDGET_KEY]) {
|
|
283
|
-
(globalThis as Record<symbol, boolean>)[STATUS_WIDGET_KEY] = true;
|
|
271
|
+
if (InteractiveMode?.prototype) {
|
|
284
272
|
const proto = InteractiveMode.prototype as unknown as {
|
|
285
273
|
setExtensionWidget(key: string, content: unknown, options?: { placement?: string }): void;
|
|
286
274
|
};
|
|
287
|
-
|
|
288
|
-
|
|
275
|
+
patchOnce(proto, "setExtensionWidget", (origSetWidget) => function (
|
|
276
|
+
this: typeof proto,
|
|
277
|
+
key: string,
|
|
278
|
+
content: unknown,
|
|
279
|
+
options?: { placement?: string },
|
|
280
|
+
) {
|
|
289
281
|
if (Array.isArray(content) && content.every((line) => typeof line === "string")) {
|
|
290
282
|
const rows = content as string[];
|
|
291
283
|
content = (_tui: unknown, th: Parameters<typeof statusRows>[0]) => ({
|
|
@@ -301,7 +293,7 @@ if (InteractiveMode?.prototype && !(globalThis as Record<symbol, boolean>)[STATU
|
|
|
301
293
|
});
|
|
302
294
|
}
|
|
303
295
|
return origSetWidget.call(this, key, content, options);
|
|
304
|
-
};
|
|
296
|
+
});
|
|
305
297
|
}
|
|
306
298
|
|
|
307
299
|
export class JevReviewBoxComponent implements Component {
|
|
@@ -367,12 +359,9 @@ export function customMessageText(content: unknown): string {
|
|
|
367
359
|
return "";
|
|
368
360
|
}
|
|
369
361
|
|
|
370
|
-
|
|
371
|
-
if (CompactionSummaryMessageComponent?.prototype && !(globalThis as Record<symbol, boolean>)[COMPACTION_KEY]) {
|
|
372
|
-
(globalThis as Record<symbol, boolean>)[COMPACTION_KEY] = true;
|
|
362
|
+
if (CompactionSummaryMessageComponent?.prototype) {
|
|
373
363
|
const proto = CompactionSummaryMessageComponent.prototype as any;
|
|
374
|
-
|
|
375
|
-
proto.updateDisplay = function (): void {
|
|
364
|
+
patchOnce(proto, "updateDisplay", (origUpdateDisplay) => function (this: any): void {
|
|
376
365
|
const th = activeTheme();
|
|
377
366
|
if (!th) return origUpdateDisplay.call(this);
|
|
378
367
|
const message = this.message as { tokensBefore?: number; summary?: string } | undefined;
|
|
@@ -401,7 +390,7 @@ if (CompactionSummaryMessageComponent?.prototype && !(globalThis as Record<symbo
|
|
|
401
390
|
return { handled: true };
|
|
402
391
|
}),
|
|
403
392
|
);
|
|
404
|
-
};
|
|
393
|
+
});
|
|
405
394
|
}
|
|
406
395
|
|
|
407
396
|
// Self-check: `node extensions/ui-render-tweaks.ts`
|
package/lib/patch.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prototype patches that survive `/reload`.
|
|
3
|
+
*
|
|
4
|
+
* pi re-evaluates an extension in the SAME process on `/reload`, so a patch guarded
|
|
5
|
+
* by a `globalThis` flag is installed once and then frozen: every later reload keeps
|
|
6
|
+
* the first load's closures, and a UI fix looks broken until pi restarts.
|
|
7
|
+
*
|
|
8
|
+
* Two rules make a patch reload-safe:
|
|
9
|
+
* 1. the pi method behind a patched slot is kept ON the prototype (a symbol key),
|
|
10
|
+
* so it outlives the module instance and never becomes a previous patch;
|
|
11
|
+
* 2. every function we install is marked, so a reload cannot mistake our own patch
|
|
12
|
+
* for pi's original and wrap a box around a box.
|
|
13
|
+
*
|
|
14
|
+
* `originalOf` throws when a slot holds a marked method but no original was recorded:
|
|
15
|
+
* that can only happen if the bookkeeping was bypassed, and silently skipping the
|
|
16
|
+
* patch would leave the UI in the state this file exists to prevent.
|
|
17
|
+
*/
|
|
18
|
+
const ORIGINALS_KEY = Symbol.for("pi-arnative.protoOriginals");
|
|
19
|
+
const PATCHED_KEY = Symbol.for("pi-arnative.patchedMethod");
|
|
20
|
+
|
|
21
|
+
type AnyFn = (...args: any[]) => any;
|
|
22
|
+
type Marked = AnyFn & { [PATCHED_KEY]?: true };
|
|
23
|
+
|
|
24
|
+
/** Mark an installed patch so a later load never reads it back as an original. */
|
|
25
|
+
export function markPatched<T extends AnyFn>(fn: T): T {
|
|
26
|
+
(fn as Marked)[PATCHED_KEY] = true;
|
|
27
|
+
return fn;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** pi's own method for `key`, recorded once per prototype and returned on every load. */
|
|
31
|
+
export function originalOf<T extends AnyFn>(proto: Record<symbol | string, any>, key: string): T {
|
|
32
|
+
const originals = (proto[ORIGINALS_KEY] ??= {} as Record<string, Marked>);
|
|
33
|
+
const current: Marked | undefined = proto[key];
|
|
34
|
+
if (current && !current[PATCHED_KEY]) originals[key] = current;
|
|
35
|
+
const original = originals[key];
|
|
36
|
+
if (!original) throw new Error(`pi-arnative: ${key} has no recorded original (already patched by another package?)`);
|
|
37
|
+
return original as T;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Install `build(pi's method)` on `proto[key]`, reinstalled on every load. */
|
|
41
|
+
export function patchOnce(proto: Record<symbol | string, any>, key: string, build: (original: AnyFn) => AnyFn): void {
|
|
42
|
+
proto[key] = markPatched(build(originalOf(proto, key)));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Self-check: `node lib/patch.ts`.
|
|
46
|
+
import { assert, isMain } from "./check.ts";
|
|
47
|
+
if (isMain(import.meta.url)) {
|
|
48
|
+
const proto: any = { render(): string { return "pi"; } };
|
|
49
|
+
const first = originalOf<() => string>(proto, "render");
|
|
50
|
+
assert(first() === "pi", "the original is pi's own method");
|
|
51
|
+
proto.render = markPatched(function (): string {
|
|
52
|
+
return first();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// A reload: the slot holds OUR patch, and the second load must still see pi's method.
|
|
56
|
+
const second = originalOf<() => string>(proto, "render");
|
|
57
|
+
assert(second === first, "reload: the recorded original never becomes a previous patch");
|
|
58
|
+
const reinstalled = markPatched(function (): string {
|
|
59
|
+
return second();
|
|
60
|
+
});
|
|
61
|
+
proto.render = reinstalled;
|
|
62
|
+
assert(proto.render() === "pi", "the reinstalled patch still calls pi, not itself");
|
|
63
|
+
assert(proto.render !== first && proto.render === reinstalled, "the slot holds the newest patch");
|
|
64
|
+
assert(proto[Symbol.for("pi-arnative.protoOriginals")].render === first, "originals stay on the prototype (outlive the module)");
|
|
65
|
+
|
|
66
|
+
// A slot patched without bookkeeping cannot silently disable the patch.
|
|
67
|
+
const lost: any = { render: markPatched(() => "x") };
|
|
68
|
+
let threw = false;
|
|
69
|
+
try {
|
|
70
|
+
originalOf(lost, "render");
|
|
71
|
+
} catch {
|
|
72
|
+
threw = true;
|
|
73
|
+
}
|
|
74
|
+
assert(threw, "a marked slot with no recorded original fails loudly");
|
|
75
|
+
|
|
76
|
+
// patchOnce: the one-call form, still reload-safe.
|
|
77
|
+
const twice: any = { render(): string { return "pi"; } };
|
|
78
|
+
patchOnce(twice, "render", (orig) => function (this: any): string {
|
|
79
|
+
return `${orig.call(this)}!`;
|
|
80
|
+
});
|
|
81
|
+
patchOnce(twice, "render", (orig) => function (this: any): string {
|
|
82
|
+
return `${orig.call(this)}?`;
|
|
83
|
+
});
|
|
84
|
+
assert(twice.render() === "pi?", "patchOnce: the second load patches pi's method again, not the first patch");
|
|
85
|
+
|
|
86
|
+
console.log("OK");
|
|
87
|
+
}
|
package/lib/spinner.ts
CHANGED
|
@@ -52,7 +52,7 @@ interface Preset {
|
|
|
52
52
|
* Only one rule decides the set: every frame must be a glyph the terminal font *itself* carries,
|
|
53
53
|
* so it advances exactly one cell. A glyph the font lacks is served by a fallback font, and
|
|
54
54
|
* fallbacks are not monospaced — measured in the terminal face (JetBrainsMono Nerd Font), the
|
|
55
|
-
* Dingbats marks `✢` `✤` `✻` `✽` `❋` advance **1.48** cells and
|
|
55
|
+
* Dingbats marks `✢` `✤` `✻` `✽` `❋` advance **1.48** cells and `U+2733` **2.29**, against a **1.00**
|
|
56
56
|
* native cell, which walks the label sideways on every tick that uses one. `·` `*` `⋆` `✶` all
|
|
57
57
|
* advance 1.00 in that face (and in Consolas, Cascadia, Lucida, Courier), so the four-mark swell
|
|
58
58
|
* `· → * → ⋆ → ✶` is smooth on all of them. A scan of all 86 installed families found none that
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bismawy/pi-arnative",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.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",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
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/animations.ts --extension ./extensions/autocompact.ts --extension ./extensions/model-heal.ts --extension ./extensions/arnative.ts",
|
|
44
|
-
"test": "node lib/box.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 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/animations.ts && node extensions/autocompact.ts && node extensions/model-heal.ts && node extensions/arnative.ts && node --test",
|
|
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 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/animations.ts && node extensions/autocompact.ts && node extensions/model-heal.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
|
"themes": "node themes/gen-themes.mjs",
|
|
47
47
|
"release:check": "node scripts/release-check.mjs pre-tag",
|