@bismawy/pi-arnative 0.8.0 → 0.8.1

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.1] - 2026-10-26
4
+
5
+ ### Changed
6
+ - **`/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`).
7
+ - **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`.
8
+
9
+ ### Fixed
10
+ - **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`).
11
+
3
12
  ## [0.8.0] - 2026-10-26
4
13
 
5
14
  ### Added
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 |
@@ -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.registerCommand("arnative", {
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");
@@ -214,14 +214,16 @@ export function extractItemsFromBody(body: string, isExtensions = false): string
214
214
  }
215
215
  }
216
216
  if (!isExtensions) return items;
217
- return items.map((item) => {
217
+ // One row per package (like `pi list`): drop the `:subpath` of every module inside a
218
+ // package and repeat nothing. Local single-file extensions (`hark.ts`) stay as they are.
219
+ const labels = new Set<string>();
220
+ for (const item of items) {
218
221
  const colon = item.indexOf(":");
219
- const name = (colon === -1 ? item : item.slice(0, colon)).trim();
220
- const ver = installedVersion(name);
221
- if (!ver) return item;
222
- const at = colon === -1 ? item.length : colon;
223
- return item.slice(0, at) + `@${ver}` + item.slice(at);
224
- });
222
+ const base = (colon === -1 ? item : item.slice(0, colon)).trim();
223
+ const ver = installedVersion(base);
224
+ labels.add(ver ? `${base}@${ver}` : base);
225
+ }
226
+ return [...labels];
225
227
  }
226
228
 
227
229
  // Cheatsheet for the Shortcut tab. Mirrors README "Shortcuts" plus the bindings the
@@ -38,6 +38,7 @@ 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";
@@ -273,6 +274,36 @@ if (InteractiveMode?.prototype && !(globalThis as Record<symbol, boolean>)[PACKA
273
274
 
274
275
  // arnative box border helper -> lib/box.ts (one definition for every box)
275
276
 
277
+ // 7. Status rows above the chat column (pi's `aboveEditor` widget slot). pi turns a string
278
+ // array into unstyled `Text`, so an extension's status line ignores the theme and lands in
279
+ // the default foreground. Every such array is handed to a component factory instead, which
280
+ // receives the live theme: the arnative mark leads the block and every row is `dim`.
281
+ const STATUS_WIDGET_KEY = Symbol.for("pi-arnative.statusWidgetRows");
282
+ if (InteractiveMode?.prototype && !(globalThis as Record<symbol, boolean>)[STATUS_WIDGET_KEY]) {
283
+ (globalThis as Record<symbol, boolean>)[STATUS_WIDGET_KEY] = true;
284
+ const proto = InteractiveMode.prototype as unknown as {
285
+ setExtensionWidget(key: string, content: unknown, options?: { placement?: string }): void;
286
+ };
287
+ const origSetWidget = proto.setExtensionWidget;
288
+ proto.setExtensionWidget = function (key: string, content: unknown, options?: { placement?: string }) {
289
+ if (Array.isArray(content) && content.every((line) => typeof line === "string")) {
290
+ const rows = content as string[];
291
+ content = (_tui: unknown, th: Parameters<typeof statusRows>[0]) => ({
292
+ dispose() {
293
+ /* no listeners, no timers */
294
+ },
295
+ invalidate() {
296
+ /* the rows are fixed at set time */
297
+ },
298
+ render(width: number): string[] {
299
+ return statusRows(th ?? activeTheme(), rows, width);
300
+ },
301
+ });
302
+ }
303
+ return origSetWidget.call(this, key, content, options);
304
+ };
305
+ }
306
+
276
307
  export class JevReviewBoxComponent implements Component {
277
308
  private text: string;
278
309
  private th: { fg(c: string, t: string): string; bg?(c: string, t: string): string };
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(_width: number): string[] {
566
- return [theme.fg("dim", text)];
566
+ render(width: number): string[] {
567
+ return statusRows(theme, [text], width);
567
568
  },
568
569
  }),
569
570
  { placement: "aboveEditor" },
@@ -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.0",
3
+ "version": "0.8.1",
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/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",
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",