@bismawy/pi-arnative 0.8.0 → 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 +21 -1
- package/README.md +1 -0
- package/extensions/arnative.ts +25 -5
- package/extensions/footer.ts +9 -8
- package/extensions/section-headers.ts +15 -14
- package/extensions/timestamps.ts +12 -11
- package/extensions/tools.ts +112 -28
- package/extensions/ui-render-tweaks.ts +59 -39
- package/lib/patch.ts +87 -0
- package/lib/provider.ts +3 -2
- package/lib/spinner.ts +1 -1
- package/lib/status-widget.ts +71 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
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
|
+
|
|
14
|
+
## [0.8.1] - 2026-10-26
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- **`/providers` is its own command.** The provider screen was reachable only as `/arnative providers`; it now also answers to `/providers`, through the same handler, so the two cannot drift. Both are registered in `registerCommands` and the self-check pins the set (`extensions/arnative.ts`).
|
|
18
|
+
- **Status rows above the chat column now use the arnative mark and the theme's `dim` token.** pi renders a `setWidget` string array as unstyled `Text`, so every status line (model heal, the provider probe, other extensions' `setWidget` calls) landed in the default foreground. A render patch turns those arrays into a component factory that receives the live theme: the `\ueb1b` mark leads the block with one space, rows align under it, and a row another extension already painted keeps its own colour (an error row stays red). `lib/status-widget.ts`.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- **The Extensions tab lists packages, not every module inside them.** The header used to print one row per loaded entry point (`@bismawy/pi-arnative@0.8.0:footer.ts`, `:model-heal.ts`, …), so a twelve-module package filled the box on its own. The `:subpath` is dropped and each package appears once with its version — the count matches what `pi list` shows. Local single-file extensions (`hark.ts`) are unchanged (`extensions/section-headers.ts`, `extractItemsFromBody`).
|
|
22
|
+
|
|
3
23
|
## [0.8.0] - 2026-10-26
|
|
4
24
|
|
|
5
25
|
### Added
|
|
@@ -77,7 +97,7 @@
|
|
|
77
97
|
### Changed
|
|
78
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`).
|
|
79
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`).
|
|
80
|
-
- **`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`).
|
|
81
101
|
|
|
82
102
|
## [0.5.3] - 2026-10-14
|
|
83
103
|
|
package/README.md
CHANGED
|
@@ -77,6 +77,7 @@ npm run dev
|
|
|
77
77
|
| `ctrl+alt+m` · `alt+m` | Toggle Minimal footer |
|
|
78
78
|
| `/usage` | Token & cost dashboard (or `/arnative` → **Usage**) |
|
|
79
79
|
| `/arnative` | Settings menu (Themes, Headers, Footers, Animations, Auto-compact, Model heal, Providers, Usage) |
|
|
80
|
+
| `/providers` | Provider screen (or `/arnative` → **Providers**) |
|
|
80
81
|
| `/model-heal` | Heal `models.json` now (or `/arnative` → **Model heal**) |
|
|
81
82
|
| Click tool / `ctrl+o` | Toggle tool output box |
|
|
82
83
|
| `←` | Back — step back from submenus/dashboard to menu |
|
package/extensions/arnative.ts
CHANGED
|
@@ -514,6 +514,22 @@ export function shouldApplyDefaultTheme(
|
|
|
514
514
|
return themeSetting === undefined && themes.some((t) => t.name === DEFAULT_THEME);
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
+
/** Register every slash command this package owns. Exported so the self-check can assert the
|
|
518
|
+
* set without starting a session. */
|
|
519
|
+
export function registerCommands(pi: Pick<ExtensionAPI, "registerCommand">): void {
|
|
520
|
+
pi.registerCommand("arnative", {
|
|
521
|
+
description: "Arnative settings menu: themes, headers, footers, providers, usage",
|
|
522
|
+
getArgumentCompletions: arnativeCompletions,
|
|
523
|
+
handler: arnativeHandler,
|
|
524
|
+
});
|
|
525
|
+
// Shortcut for the screen people reach for by name: it goes through the same handler, so
|
|
526
|
+
// `/providers` and `/arnative providers` cannot drift apart.
|
|
527
|
+
pi.registerCommand("providers", {
|
|
528
|
+
description: "Custom endpoints: add, edit or remove a provider (same as /arnative providers)",
|
|
529
|
+
handler: (_args: string, ctx: ExtensionCommandContext) => arnativeHandler("providers", ctx),
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
|
|
517
533
|
export default function (pi: ExtensionAPI) {
|
|
518
534
|
pi.on("session_start", async (_event, ctx) => {
|
|
519
535
|
// `setTheme` writes the choice into pi's settings, so this runs once per install and the
|
|
@@ -521,11 +537,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
521
537
|
if (!shouldApplyDefaultTheme(pi.getSettings()?.theme, ctx.ui.getAllThemes())) return;
|
|
522
538
|
ctx.ui.setTheme(DEFAULT_THEME);
|
|
523
539
|
});
|
|
524
|
-
pi
|
|
525
|
-
description: "Arnative settings menu: themes, headers, footers, providers, usage",
|
|
526
|
-
getArgumentCompletions: arnativeCompletions,
|
|
527
|
-
handler: arnativeHandler,
|
|
528
|
-
});
|
|
540
|
+
registerCommands(pi);
|
|
529
541
|
}
|
|
530
542
|
|
|
531
543
|
// Self-check: `node extensions/arnative.ts`
|
|
@@ -573,6 +585,14 @@ if (isMain(import.meta.url)) {
|
|
|
573
585
|
assert(autoCompactRows("Off")[0]!.chosen === true, "the marker moves when the saved choice changes");
|
|
574
586
|
assert(arnativeCompletions("pr")![0]!.value === "providers", "providers menu has completions");
|
|
575
587
|
assert(MENUS.some((m) => m.value === "providers"), "providers menu registered");
|
|
588
|
+
// Every slash command, and the one alias: `/providers` must land on the providers screen.
|
|
589
|
+
{
|
|
590
|
+
const registered = new Map<string, { description: string; handler: unknown }>();
|
|
591
|
+
registerCommands({ registerCommand: (name, options) => { registered.set(name, options as never); } } as never);
|
|
592
|
+
assert([...registered.keys()].join(",") === "arnative,providers", "two commands: /arnative and /providers");
|
|
593
|
+
assert(typeof registered.get("providers")!.handler === "function", "/providers has a handler");
|
|
594
|
+
assert(MENUS.some((m) => m.value === "providers"), "/providers routes to a menu row that exists");
|
|
595
|
+
}
|
|
576
596
|
// Usage is reachable from /arnative even though it is a dashboard, not a setting.
|
|
577
597
|
assert(MENUS.some((m) => m.value === "usage"), "usage menu registered");
|
|
578
598
|
assert(arnativeCompletions("us")![0]!.value === "usage", "usage menu has completions");
|
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.
|
|
@@ -214,14 +215,16 @@ export function extractItemsFromBody(body: string, isExtensions = false): string
|
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
if (!isExtensions) return items;
|
|
217
|
-
|
|
218
|
+
// One row per package (like `pi list`): drop the `:subpath` of every module inside a
|
|
219
|
+
// package and repeat nothing. Local single-file extensions (`hark.ts`) stay as they are.
|
|
220
|
+
const labels = new Set<string>();
|
|
221
|
+
for (const item of items) {
|
|
218
222
|
const colon = item.indexOf(":");
|
|
219
|
-
const
|
|
220
|
-
const ver = installedVersion(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
});
|
|
223
|
+
const base = (colon === -1 ? item : item.slice(0, colon)).trim();
|
|
224
|
+
const ver = installedVersion(base);
|
|
225
|
+
labels.add(ver ? `${base}@${ver}` : base);
|
|
226
|
+
}
|
|
227
|
+
return [...labels];
|
|
225
228
|
}
|
|
226
229
|
|
|
227
230
|
// Cheatsheet for the Shortcut tab. Mirrors README "Shortcuts" plus the bindings the
|
|
@@ -704,16 +707,14 @@ export function extensionIssuesLines(th: BoxTheme | null, width: number, rows: s
|
|
|
704
707
|
// Hooks the shared `app.tools.expand` key: `ctrl+o to expand` -> `[ctrl+o to expand]`.
|
|
705
708
|
const wrapHint = (key: string): string => `[${key} to expand]`;
|
|
706
709
|
|
|
707
|
-
// Intercept loadedResourcesContainer: capture data for the tabs and hide pi's own display
|
|
708
|
-
|
|
709
|
-
if (UserMessageComponent?.prototype
|
|
710
|
-
(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) {
|
|
711
713
|
const containerProto = Object.getPrototypeOf(UserMessageComponent.prototype) as {
|
|
712
714
|
addChild?: (child: unknown) => unknown;
|
|
713
715
|
};
|
|
714
716
|
if (typeof containerProto?.addChild === "function") {
|
|
715
|
-
|
|
716
|
-
containerProto.addChild = function (child: any): unknown {
|
|
717
|
+
patchOnce(containerProto, "addChild", (origAddChild) => function (this: any, child: any): unknown {
|
|
717
718
|
// "Pi (system)" preset = pi's own header, so leave pi's startup list untouched.
|
|
718
719
|
if (activeHeaderPreset() === "Pi (system)") return origAddChild.call(this, child);
|
|
719
720
|
try {
|
|
@@ -763,7 +764,7 @@ if (UserMessageComponent?.prototype && !(globalThis as Record<symbol, boolean>)[
|
|
|
763
764
|
// fail-safe
|
|
764
765
|
}
|
|
765
766
|
return origAddChild.call(this, child);
|
|
766
|
-
};
|
|
767
|
+
});
|
|
767
768
|
}
|
|
768
769
|
}
|
|
769
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
|
}
|
|
@@ -38,10 +38,12 @@ import {
|
|
|
38
38
|
} from "@earendil-works/pi-tui";
|
|
39
39
|
import { readdirSync, readFileSync } from "node:fs";
|
|
40
40
|
import { renderBoxLines } from "../lib/box.ts";
|
|
41
|
+
import { statusRows } from "../lib/status-widget.ts";
|
|
41
42
|
import { ansiBgOpen, getActiveTheme, setActiveTheme, stripAnsi, themeOf, softSecondaryOf } from "../lib/ansi.ts";
|
|
42
43
|
import { assert, isMain } from "../lib/check.ts";
|
|
43
44
|
import { contrast, oklchToRgb, parseOklch, toHex } from "../lib/color.ts";
|
|
44
45
|
import { expandKeyName } from "../lib/format.ts";
|
|
46
|
+
import { patchOnce } from "../lib/patch.ts";
|
|
45
47
|
|
|
46
48
|
type ActiveTheme = { fg(color: string, text: string): string; bg?(color: string, text: string): string } | null;
|
|
47
49
|
const activeTheme = () => getActiveTheme<Exclude<ActiveTheme, null>>();
|
|
@@ -67,16 +69,15 @@ export function shouldHideReloadBox(lines: readonly string[]): boolean {
|
|
|
67
69
|
const rows = lines.map((l) => stripAnsi(l).trim());
|
|
68
70
|
return rows.every((r) => r === "" || /^[─-]+$/.test(r) || RELOAD_TEXT.includes(r));
|
|
69
71
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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) {
|
|
73
75
|
const containerProto = Object.getPrototypeOf(UserMessageComponent.prototype) as { render?: (width: number) => string[] };
|
|
74
76
|
if (typeof containerProto?.render === "function") {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const lines = origContainerRender.call(this, width);
|
|
77
|
+
patchOnce(containerProto, "render", (orig) => function (this: any, width: number): string[] {
|
|
78
|
+
const lines = orig.call(this, width);
|
|
78
79
|
return shouldHideReloadBox(lines) ? [] : lines;
|
|
79
|
-
};
|
|
80
|
+
});
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
|
|
@@ -85,7 +86,6 @@ if (UserMessageComponent?.prototype && !(globalThis as Record<symbol, boolean>)[
|
|
|
85
86
|
// Drag selection in pi fullscreen: pi only wraps the selection in reverse video
|
|
86
87
|
// (\x1b[7m), unreadable in some terminals/themes. Replaced with explicit colors
|
|
87
88
|
// (bg selectedBg + fg text) so text always stays visible.
|
|
88
|
-
const SELECTION_COLOR_KEY = Symbol.for("pi-arnative.selectionColorsPatched");
|
|
89
89
|
|
|
90
90
|
export function recolorSelection(highlighted: string, fgOpen: string, bgOpen: string): string {
|
|
91
91
|
return highlighted.split("\x1b[7m").join(fgOpen + bgOpen).split("\x1b[27m").join("\x1b[39m\x1b[49m");
|
|
@@ -106,7 +106,6 @@ export function ansiFgOpen(th: { fg?(c: string, t: string): string } | null, col
|
|
|
106
106
|
// (grey) -> accent bg + darkened canvas text (contrast 9.6:1, WCAG AA). pi has no bg
|
|
107
107
|
// token for `accent` (7 exist, see PILL_INK), so the SGR escapes are swapped;
|
|
108
108
|
// `bg("accent")` would throw "Unknown theme background color" and stay unchanged.
|
|
109
|
-
const PILL_KEY = Symbol.for("pi-arnative.accentPill");
|
|
110
109
|
const PILL_MARK = "↓ Jump to latest message";
|
|
111
110
|
const PILL_INK = "toolPendingBg";
|
|
112
111
|
|
|
@@ -142,41 +141,37 @@ export function withAccentPill<T>(
|
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
143
|
|
|
145
|
-
if (TuiAltScreen?.prototype
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
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);
|
|
151
149
|
const fgOpen = ansiFgOpen(activeTheme());
|
|
152
150
|
const bgOpen = ansiBgOpen(activeTheme(), "selectedBg");
|
|
153
151
|
return fgOpen && bgOpen ? recolorSelection(highlighted, fgOpen, bgOpen) : highlighted;
|
|
154
|
-
};
|
|
152
|
+
});
|
|
155
153
|
}
|
|
156
154
|
}
|
|
157
155
|
|
|
158
|
-
if (TuiAltScreen?.prototype
|
|
159
|
-
(globalThis as Record<symbol, boolean>)[PILL_KEY] = true;
|
|
156
|
+
if (TuiAltScreen?.prototype) {
|
|
160
157
|
const proto = TuiAltScreen.prototype as unknown as {
|
|
161
158
|
compositeScrollToEndIndicator?: (screen: string[], layout: unknown, width: number) => string[];
|
|
162
159
|
};
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
proto.compositeScrollToEndIndicator = function (
|
|
160
|
+
if (typeof proto.compositeScrollToEndIndicator === "function") {
|
|
161
|
+
patchOnce(proto, "compositeScrollToEndIndicator", (origComposite) => function (
|
|
166
162
|
this: { scrollToEndIndicator?: (() => string) | undefined },
|
|
167
163
|
screen: string[],
|
|
168
164
|
layout: unknown,
|
|
169
165
|
width: number,
|
|
170
166
|
) {
|
|
171
167
|
return withAccentPill(this, () => origComposite.call(this, screen, layout, width), activeTheme());
|
|
172
|
-
};
|
|
168
|
+
});
|
|
173
169
|
}
|
|
174
170
|
}
|
|
175
171
|
|
|
176
172
|
// 6. Select menus (ctx.ui.select -> ExtensionSelectorComponent.updateList): pi colors the
|
|
177
173
|
// whole selected row accent. Arnative keeps accent on the `→` marker and `·` separators
|
|
178
174
|
// and moves the selected text to soft (accent on themes without the token).
|
|
179
|
-
const SELECT_ROW_KEY = Symbol.for("pi-arnative.selectRowColors");
|
|
180
175
|
|
|
181
176
|
/** Selected row body: `·` separators accent, the text around them soft. */
|
|
182
177
|
export function selectRowText(row: string, th: { fg(c: string, t: string): string }): string {
|
|
@@ -187,16 +182,14 @@ export function selectRowText(row: string, th: { fg(c: string, t: string): strin
|
|
|
187
182
|
.join(th.fg("accent", "·"));
|
|
188
183
|
}
|
|
189
184
|
|
|
190
|
-
if (ExtensionSelectorComponent?.prototype
|
|
191
|
-
(globalThis as Record<symbol, boolean>)[SELECT_ROW_KEY] = true;
|
|
185
|
+
if (ExtensionSelectorComponent?.prototype) {
|
|
192
186
|
const proto = ExtensionSelectorComponent.prototype as unknown as {
|
|
193
187
|
options: string[];
|
|
194
188
|
selectedIndex: number;
|
|
195
189
|
listContainer: { clear(): void; addChild(c: unknown): void };
|
|
196
190
|
updateList(): void;
|
|
197
191
|
};
|
|
198
|
-
|
|
199
|
-
proto.updateList = function (this: typeof proto) {
|
|
192
|
+
patchOnce(proto, "updateList", (origUpdateList) => function (this: typeof proto) {
|
|
200
193
|
const th = activeTheme();
|
|
201
194
|
if (!th) return origUpdateList.call(this); // no theme yet -> pi's default
|
|
202
195
|
this.listContainer.clear();
|
|
@@ -207,7 +200,7 @@ if (ExtensionSelectorComponent?.prototype && !(globalThis as Record<symbol, bool
|
|
|
207
200
|
: ` ${th.fg("text", this.options[i]!)}`;
|
|
208
201
|
this.listContainer.addChild(new Text(text, 1, 0));
|
|
209
202
|
}
|
|
210
|
-
};
|
|
203
|
+
});
|
|
211
204
|
}
|
|
212
205
|
|
|
213
206
|
export default function uiRenderTweaks(pi: ExtensionAPI) {
|
|
@@ -254,13 +247,11 @@ export class PackageUpdateBoxComponent implements Component {
|
|
|
254
247
|
}
|
|
255
248
|
}
|
|
256
249
|
|
|
257
|
-
|
|
258
|
-
if (InteractiveMode?.prototype && !(globalThis as Record<symbol, boolean>)[PACKAGE_BOX_KEY]) {
|
|
259
|
-
(globalThis as Record<symbol, boolean>)[PACKAGE_BOX_KEY] = true;
|
|
250
|
+
if (InteractiveMode?.prototype) {
|
|
260
251
|
const proto = InteractiveMode.prototype as unknown as {
|
|
261
252
|
showPackageUpdateNotification(packages: string[]): void;
|
|
262
253
|
};
|
|
263
|
-
proto
|
|
254
|
+
patchOnce(proto, "showPackageUpdateNotification", () => function (this: typeof proto, packages: string[]) {
|
|
264
255
|
const self = this as unknown as {
|
|
265
256
|
chatContainer: { addChild(c: unknown): void };
|
|
266
257
|
ui: { requestRender(): void };
|
|
@@ -268,11 +259,43 @@ if (InteractiveMode?.prototype && !(globalThis as Record<symbol, boolean>)[PACKA
|
|
|
268
259
|
self.chatContainer.addChild(new Spacer(1));
|
|
269
260
|
self.chatContainer.addChild(new PackageUpdateBoxComponent(packages, activeTheme()));
|
|
270
261
|
self.ui.requestRender();
|
|
271
|
-
};
|
|
262
|
+
});
|
|
272
263
|
}
|
|
273
264
|
|
|
274
265
|
// arnative box border helper -> lib/box.ts (one definition for every box)
|
|
275
266
|
|
|
267
|
+
// 7. Status rows above the chat column (pi's `aboveEditor` widget slot). pi turns a string
|
|
268
|
+
// array into unstyled `Text`, so an extension's status line ignores the theme and lands in
|
|
269
|
+
// the default foreground. Every such array is handed to a component factory instead, which
|
|
270
|
+
// receives the live theme: the arnative mark leads the block and every row is `dim`.
|
|
271
|
+
if (InteractiveMode?.prototype) {
|
|
272
|
+
const proto = InteractiveMode.prototype as unknown as {
|
|
273
|
+
setExtensionWidget(key: string, content: unknown, options?: { placement?: string }): void;
|
|
274
|
+
};
|
|
275
|
+
patchOnce(proto, "setExtensionWidget", (origSetWidget) => function (
|
|
276
|
+
this: typeof proto,
|
|
277
|
+
key: string,
|
|
278
|
+
content: unknown,
|
|
279
|
+
options?: { placement?: string },
|
|
280
|
+
) {
|
|
281
|
+
if (Array.isArray(content) && content.every((line) => typeof line === "string")) {
|
|
282
|
+
const rows = content as string[];
|
|
283
|
+
content = (_tui: unknown, th: Parameters<typeof statusRows>[0]) => ({
|
|
284
|
+
dispose() {
|
|
285
|
+
/* no listeners, no timers */
|
|
286
|
+
},
|
|
287
|
+
invalidate() {
|
|
288
|
+
/* the rows are fixed at set time */
|
|
289
|
+
},
|
|
290
|
+
render(width: number): string[] {
|
|
291
|
+
return statusRows(th ?? activeTheme(), rows, width);
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return origSetWidget.call(this, key, content, options);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
276
299
|
export class JevReviewBoxComponent implements Component {
|
|
277
300
|
private text: string;
|
|
278
301
|
private th: { fg(c: string, t: string): string; bg?(c: string, t: string): string };
|
|
@@ -336,12 +359,9 @@ export function customMessageText(content: unknown): string {
|
|
|
336
359
|
return "";
|
|
337
360
|
}
|
|
338
361
|
|
|
339
|
-
|
|
340
|
-
if (CompactionSummaryMessageComponent?.prototype && !(globalThis as Record<symbol, boolean>)[COMPACTION_KEY]) {
|
|
341
|
-
(globalThis as Record<symbol, boolean>)[COMPACTION_KEY] = true;
|
|
362
|
+
if (CompactionSummaryMessageComponent?.prototype) {
|
|
342
363
|
const proto = CompactionSummaryMessageComponent.prototype as any;
|
|
343
|
-
|
|
344
|
-
proto.updateDisplay = function (): void {
|
|
364
|
+
patchOnce(proto, "updateDisplay", (origUpdateDisplay) => function (this: any): void {
|
|
345
365
|
const th = activeTheme();
|
|
346
366
|
if (!th) return origUpdateDisplay.call(this);
|
|
347
367
|
const message = this.message as { tokensBefore?: number; summary?: string } | undefined;
|
|
@@ -370,7 +390,7 @@ if (CompactionSummaryMessageComponent?.prototype && !(globalThis as Record<symbo
|
|
|
370
390
|
return { handled: true };
|
|
371
391
|
}),
|
|
372
392
|
);
|
|
373
|
-
};
|
|
393
|
+
});
|
|
374
394
|
}
|
|
375
395
|
|
|
376
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/provider.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { assert, isMain } from "../lib/check.ts";
|
|
|
16
16
|
import { buildEffortMap, isEffortProbeable, mergeMeta, parseModelMeta, probeEffort, suggestCompat, type Compat, type ModelMeta } from "./compat.ts";
|
|
17
17
|
import { screenTitle, type ScreenText } from "../lib/box.ts";
|
|
18
18
|
import { stripAnsi } from "../lib/ansi.ts";
|
|
19
|
+
import { statusRows } from "./status-widget.ts";
|
|
19
20
|
import { INPUT_LEGEND, InputPicker, LIST_LEGEND_MOVE, ListPicker, rowText, type ListRow } from "./list-picker.ts";
|
|
20
21
|
|
|
21
22
|
// ---------------------------------------------------------------- flavors
|
|
@@ -562,8 +563,8 @@ function probingStatus(ctx: ExtensionCommandContext, text: string | undefined):
|
|
|
562
563
|
(_tui: TUI, theme: Theme) => ({
|
|
563
564
|
dispose() { /* no listeners, no timers — nothing to clean up */ },
|
|
564
565
|
invalidate() { /* a static line, recomputed on every render anyway */ },
|
|
565
|
-
render(
|
|
566
|
-
return
|
|
566
|
+
render(width: number): string[] {
|
|
567
|
+
return statusRows(theme, [text], width);
|
|
567
568
|
},
|
|
568
569
|
}),
|
|
569
570
|
{ placement: "aboveEditor" },
|
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
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rows pinned above the chat column (pi's `aboveEditor` widget slot). One shape for every
|
|
3
|
+
* status line: the arnative mark, one space, then the text in the theme's `dim` token.
|
|
4
|
+
*
|
|
5
|
+
* pi renders a plain string array as unstyled `Text`, so `setWidget(key, ["…"])` ignores the
|
|
6
|
+
* theme and the line lands in the default foreground. The patch in
|
|
7
|
+
* `extensions/ui-render-tweaks.ts` turns every such array into a component factory, which
|
|
8
|
+
* receives the live theme; this module holds the formatting that patch renders.
|
|
9
|
+
*
|
|
10
|
+
* A row that already carries ANSI (another extension painted it) keeps its own colour: only
|
|
11
|
+
* the unstyled rows are painted `dim`, so an error row stays red instead of being re-tinted.
|
|
12
|
+
*
|
|
13
|
+
* Lives outside `extensions/*.ts` so pi never loads it as an extension.
|
|
14
|
+
*/
|
|
15
|
+
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
16
|
+
import { assert, isMain } from "./check.ts";
|
|
17
|
+
|
|
18
|
+
/** The mark that leads a block of rows above the chat column. */
|
|
19
|
+
export const STATUS_ICON = "\ueb1b";
|
|
20
|
+
|
|
21
|
+
/** pi's own cap on a string-array widget (`InteractiveMode.MAX_WIDGET_LINES`). */
|
|
22
|
+
export const MAX_STATUS_ROWS = 10;
|
|
23
|
+
|
|
24
|
+
type FgTheme = { fg?(color: string, text: string): string } | null;
|
|
25
|
+
|
|
26
|
+
/** `dim(text)`, or the plain text when the theme is absent or rejects the token. */
|
|
27
|
+
function dim(th: FgTheme, text: string): string {
|
|
28
|
+
try {
|
|
29
|
+
return th?.fg ? th.fg("dim", text) : text;
|
|
30
|
+
} catch {
|
|
31
|
+
return text;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Aligned under the mark; a long block is capped exactly like pi's own array widget, and
|
|
36
|
+
* every row is cut to `width` (a component owns its width, pi does not wrap it for us). */
|
|
37
|
+
export function statusRows(th: FgTheme, rows: string[], width = Number.POSITIVE_INFINITY): string[] {
|
|
38
|
+
const lines = rows
|
|
39
|
+
.slice(0, MAX_STATUS_ROWS)
|
|
40
|
+
.map((row, i) => {
|
|
41
|
+
const prefix = i === 0 ? ` ${STATUS_ICON} ` : " ";
|
|
42
|
+
return row.includes("\x1b") ? dim(th, prefix) + row : dim(th, prefix + row);
|
|
43
|
+
});
|
|
44
|
+
if (rows.length > MAX_STATUS_ROWS) lines.push(dim(th, " ... (widget truncated)"));
|
|
45
|
+
return Number.isFinite(width) ? lines.map((line) => truncateToWidth(line, width, "")) : lines;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isMain(import.meta.url)) {
|
|
49
|
+
const tag = (color: string, text: string) => `<${color}>${text}</${color}>`;
|
|
50
|
+
assert(
|
|
51
|
+
JSON.stringify(statusRows({ fg: tag }, ["model-heal: healed"])) === JSON.stringify(["<dim> \ueb1b model-heal: healed</dim>"]),
|
|
52
|
+
"one space before the mark, one after, one dim span for the whole row",
|
|
53
|
+
);
|
|
54
|
+
assert(JSON.stringify(statusRows(null, ["plain"])) === JSON.stringify([" \ueb1b plain"]), "no theme renders the plain line");
|
|
55
|
+
assert(
|
|
56
|
+
JSON.stringify(statusRows({ fg: () => { throw new Error("unknown token"); } }, ["safe"])) === JSON.stringify([" \ueb1b safe"]),
|
|
57
|
+
"a theme that rejects the token does not crash the render",
|
|
58
|
+
);
|
|
59
|
+
assert(
|
|
60
|
+
JSON.stringify(statusRows({ fg: tag }, ["one", "\x1b[31mtwo\x1b[39m"])) ===
|
|
61
|
+
JSON.stringify(["<dim> \ueb1b one</dim>", "<dim> </dim>\x1b[31mtwo\x1b[39m"]),
|
|
62
|
+
"an already-painted row keeps its own colour, continuation rows align under the text",
|
|
63
|
+
);
|
|
64
|
+
const long = statusRows({ fg: tag }, new Array(20).fill("x"));
|
|
65
|
+
assert(long.length === MAX_STATUS_ROWS + 1 && long.at(-1)!.includes("widget truncated"), "a long block is capped like pi's own");
|
|
66
|
+
assert(statusRows(null, []).length === 0, "an empty block renders nothing");
|
|
67
|
+
// A component owns its width: a line wider than the terminal must be cut, not wrapped.
|
|
68
|
+
const wide = statusRows({ fg: tag }, ["x".repeat(200)], 20);
|
|
69
|
+
assert(wide.length === 1 && visibleWidth(wide[0]!) === 20, "rows are cut to the render width");
|
|
70
|
+
console.log("status-widget.ts self-check OK");
|
|
71
|
+
}
|
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/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",
|