@bismawy/pi-arnative 0.16.1 → 0.18.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.
Files changed (61) hide show
  1. package/README.md +25 -16
  2. package/extensions/index.ts +41 -0
  3. package/lib/active-clock.ts +91 -0
  4. package/lib/ansi.ts +40 -78
  5. package/lib/box.ts +49 -68
  6. package/lib/chatbox.ts +371 -0
  7. package/lib/color.ts +3 -31
  8. package/lib/compat.ts +0 -60
  9. package/lib/edit-diff.ts +199 -0
  10. package/{extensions → lib/features}/arnative.ts +96 -423
  11. package/{extensions/autocompact.ts → lib/features/auto-compact.ts} +30 -327
  12. package/{extensions → lib/features}/budget.ts +17 -242
  13. package/lib/features/footer.ts +2232 -0
  14. package/{extensions/section-headers.ts → lib/features/headers.ts} +38 -49
  15. package/{extensions → lib/features}/model-heal.ts +5 -28
  16. package/lib/features/progress-group.ts +1691 -0
  17. package/{extensions → lib/features}/render-cache.ts +391 -218
  18. package/{extensions → lib/features}/timestamps.ts +18 -94
  19. package/{extensions → lib/features}/todos.ts +44 -158
  20. package/lib/features/tools.ts +1202 -0
  21. package/lib/features/ui-render-tweaks.ts +606 -0
  22. package/lib/features/usage.ts +786 -0
  23. package/lib/format.ts +22 -4
  24. package/lib/git-status.ts +164 -0
  25. package/lib/list-picker.ts +1 -127
  26. package/lib/model-heal.ts +70 -162
  27. package/lib/patch.ts +0 -63
  28. package/lib/preset-store.ts +17 -133
  29. package/lib/provider-store.ts +573 -0
  30. package/lib/provider.ts +52 -851
  31. package/lib/runtime.ts +209 -0
  32. package/lib/shortcuts.ts +8 -58
  33. package/lib/spinner.ts +88 -162
  34. package/lib/status-widget.ts +4 -30
  35. package/lib/todos.ts +20 -143
  36. package/lib/usage-pricing.ts +143 -0
  37. package/lib/usage-store.ts +44 -378
  38. package/package.json +48 -49
  39. package/themes/arnative-blossom.json +0 -0
  40. package/themes/arnative-crimson.json +0 -0
  41. package/themes/arnative-cyberpunk.json +0 -0
  42. package/themes/arnative-dracula.json +0 -0
  43. package/themes/arnative-earthy.json +0 -0
  44. package/themes/arnative-garden.json +0 -0
  45. package/themes/arnative-gruvbox.json +0 -0
  46. package/themes/arnative-lemonade.json +0 -0
  47. package/themes/arnative-magical.json +0 -0
  48. package/themes/arnative-matrix.json +0 -0
  49. package/themes/arnative-neutral.json +0 -0
  50. package/themes/arnative-nord.json +0 -0
  51. package/themes/arnative-zinc.json +0 -0
  52. package/themes/arnative.json +0 -0
  53. package/CHANGELOG.md +0 -683
  54. package/extensions/animations.ts +0 -242
  55. package/extensions/footer.ts +0 -2617
  56. package/extensions/tools.ts +0 -2231
  57. package/extensions/ui-render-tweaks.ts +0 -1005
  58. package/extensions/usage-export.ts +0 -283
  59. package/extensions/usage.ts +0 -1406
  60. package/lib/check.ts +0 -21
  61. package/themes/gen-themes.mjs +0 -715
@@ -5,30 +5,31 @@
5
5
  * Screens share one chrome and one title shape ({@link renderScreen}); a box border takes
6
6
  * the session's thinking slot (`lib/ansi.ts`), so it belongs to the active model.
7
7
  */
8
- import { bindSetModel } from "../lib/provider.ts";
8
+ import { bindSetModel, openProviders } from "../provider.ts";
9
9
  import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
10
- import { visibleWidth, matchesKey, type AutocompleteItem } from "@earendil-works/pi-tui";
11
- import { stripAnsi } from "../lib/ansi.ts";
12
- import { screenTitle } from "../lib/box.ts";
13
- import { announce } from "../lib/status-widget.ts";
14
- import { assert, isMain } from "../lib/check.ts";
15
- import { markedLabels, ROW_DIVIDER } from "../lib/format.ts";
16
- import { SPINNER_GRADIENT_KEY, SPINNER_PRESET_KEY, SPINNER_PRESETS, type SpinnerPreset } from "../lib/spinner.ts";
10
+ import { matchesKey, type AutocompleteItem } from "@earendil-works/pi-tui";
11
+ import { screenTitle } from "../box.ts";
12
+ import { announce } from "../status-widget.ts";
13
+ import { markedLabels } from "../format.ts";
17
14
  import {
15
+ PREVIEW_TICK_MS,
16
+ SPINNER_GRADIENT_KEY,
17
+ SPINNER_PRESET_KEY,
18
+ SPINNER_PRESETS,
18
19
  activeSpinnerGradient,
19
- animationsPickerText,
20
20
  activeSpinnerPreset,
21
21
  animationRowNote,
22
22
  animationRows,
23
- PREVIEW_TICK_MS,
23
+ animationsPickerText,
24
24
  setSpinnerGradient,
25
25
  setSpinnerPreset,
26
- } from "./animations.ts";
27
- import { CHATBOX_DIALOG_KEY, CHATBOX_PRESET_KEY, CHATBOX_PROMPT_KEY, EDIT_DIFF_KEY, FOOTER_COST_KEY, FOOTER_PRESET_KEY, HEADER_PRESET_KEY, BUDGET_DAY_KEY, BUDGET_ENFORCE_KEY, BUDGET_MONTH_KEY, PAYLOAD_LIMIT_KEY, RENDER_CACHE_KEY, ensureChoices } from "../lib/preset-store.ts";
26
+ type SpinnerPreset,
27
+ } from "../spinner.ts";
28
+ import { CHATBOX_DIALOG_KEY, CHATBOX_PRESET_KEY, CHATBOX_PROMPT_KEY, EDIT_DIFF_KEY, FOOTER_COST_KEY, FOOTER_PRESET_KEY, HEADER_PRESET_KEY, BUDGET_DAY_KEY, BUDGET_ENFORCE_KEY, BUDGET_MONTH_KEY, PAYLOAD_LIMIT_KEY, RENDER_CACHE_KEY, TOOL_LAYOUT_KEY, ensureChoices } from "../preset-store.ts";
28
29
  import { EDIT_DIFF_CHOICES, activeEditDiff, setEditDiff, type EditDiffMode } from "./tools.ts";
29
- import { CHATBOX_DIALOGS, CHATBOX_PRESETS, CHATBOX_PROMPTS, DEFAULT_CHATBOX_DIALOG, FOOTER_PRESETS, activeChatboxDialog, activeChatboxPreset, activeChatboxPrompt, activeFooterCost, activeFooterPreset, nextChatboxDialog, nextChatboxPrompt, setChatboxDialog, setChatboxPreset, setChatboxPrompt, setFooterCost, setFooterPreset, type ChatboxPreset } from "./footer.ts";
30
+ import { CHATBOX_PRESETS, CHATBOX_PROMPTS, DEFAULT_CHATBOX_DIALOG, FOOTER_PRESETS, activeChatboxDialog, activeChatboxPreset, activeChatboxPrompt, activeFooterCost, activeFooterPreset, nextChatboxDialog, nextChatboxPrompt, setChatboxDialog, setChatboxPreset, setChatboxPrompt, setFooterCost, setFooterPreset, type ChatboxPreset } from "./footer.ts";
30
31
  import { activeBudgetDay, activeBudgetEnforce, activeBudgetMonth, openBudget } from "./budget.ts";
31
- import { HEADER_PRESETS, activeHeaderPreset, setHeaderPreset } from "./section-headers.ts";
32
+ import { HEADER_PRESETS, activeHeaderPreset, setHeaderPreset } from "./headers.ts";
32
33
  import {
33
34
  AUTO_COMPACT_CHOICES,
34
35
  AUTO_COMPACT_KEY,
@@ -44,21 +45,26 @@ import {
44
45
  setPayloadLimit,
45
46
  type AutoCompactChoice,
46
47
  type PayloadLimitPreset,
47
- } from "./autocompact.ts";
48
+ } from "./auto-compact.ts";
48
49
  import { cancelManualHeal, healNow } from "./model-heal.ts";
49
- import { MODEL_HEAL_CHOICES, MODEL_HEAL_KEY, activeModelHeal, setModelHeal, type ModelHealChoice } from "../lib/model-heal.ts";
50
+ import { MODEL_HEAL_CHOICES, MODEL_HEAL_KEY, activeModelHeal, setModelHeal, type ModelHealChoice } from "../model-heal.ts";
50
51
  import {
51
52
  RENDER_CACHE_CHOICES,
52
53
  activeRenderCache,
53
54
  setRenderCache,
54
55
  type RenderCacheChoice,
55
56
  } from "./render-cache.ts";
56
- import { INPUT_LEGEND, InputPicker, LIST_LEGEND_LIVE, LIST_LEGEND_MOVE, LIST_LEGEND_ROOT, ListPicker, nameRows, rowText, type ListPickerText, type ListRow } from "../lib/list-picker.ts";
57
- import { openProviders } from "../lib/provider.ts";
57
+ import {
58
+ TOOL_LAYOUT_CHOICES,
59
+ activeToolLayout,
60
+ setToolLayout,
61
+ type ToolLayoutMode,
62
+ } from "./progress-group.ts";
63
+ import { INPUT_LEGEND, InputPicker, LIST_LEGEND_LIVE, LIST_LEGEND_MOVE, LIST_LEGEND_ROOT, ListPicker, nameRows, rowText, type ListPickerText, type ListRow } from "../list-picker.ts";
58
64
  import { openUsage } from "./usage.ts";
59
- import { SHORTCUT_OPEN_ARNATIVE } from "../lib/shortcuts.ts";
65
+ import { SHORTCUT_OPEN_ARNATIVE } from "../shortcuts.ts";
60
66
 
61
- export type MenuGroup = "Appearance" | "Performance" | "Models" | "Spend";
67
+ export type MenuGroup = "Appearance" | "Display" | "Models & Context" | "Spend";
62
68
 
63
69
  export interface MenuCategory {
64
70
  label: MenuGroup;
@@ -66,9 +72,9 @@ export interface MenuCategory {
66
72
  }
67
73
 
68
74
  export const MENU_CATEGORIES: readonly MenuCategory[] = [
69
- { label: "Appearance", description: "themes, headers, footers, chatbox, animations, diffs" },
70
- { label: "Performance", description: "auto-compact, render cache, payload limit" },
71
- { label: "Models", description: "custom providers, model heal" },
75
+ { label: "Appearance", description: "themes, headers, footers, chatbox" },
76
+ { label: "Display", description: "animations, diffs, tool layout, render cache" },
77
+ { label: "Models & Context", description: "custom providers, model heal, auto-compact, payload limit" },
72
78
  { label: "Spend", description: "usage dashboard, budget caps" },
73
79
  ];
74
80
 
@@ -397,7 +403,7 @@ export function autoCompactRows(opened: AutoCompactChoice): ListRow[] {
397
403
  }
398
404
 
399
405
  /** A plain (non-live) picker: the choice is committed by Enter, nothing previews. The
400
- * trigger itself lives in `extensions/autocompact.ts` and fires on the next settle. */
406
+ * trigger itself lives in `lib/features/auto-compact.ts` and fires on the next settle. */
401
407
  const openAutoCompact = (ctx: ExtensionCommandContext): Promise<boolean | void> => {
402
408
  const opened = activeAutoCompact();
403
409
  return openChoicePicker(ctx, {
@@ -512,6 +518,40 @@ const openDiffs = (ctx: ExtensionCommandContext): Promise<boolean | void> => {
512
518
  });
513
519
  };
514
520
 
521
+ const TOOL_LAYOUT_PICKER_TEXT: ListPickerText = {
522
+ title: screenTitle("Tool layout"),
523
+ description: "Selection previews live — ADE grouped phase progress box or classic per-tool boxes.",
524
+ legend: LIST_LEGEND_LIVE,
525
+ };
526
+
527
+ const TOOL_LAYOUT_NOTES: Record<ToolLayoutMode, string> = {
528
+ Grouped: "one clickable chronological phase box per turn, conclusion below (default)",
529
+ Classic: "render each tool call in its own standalone box",
530
+ };
531
+
532
+ /** Rows for `/arnative` → Tool layout: Grouped / Classic. */
533
+ export function toolLayoutRows(): ListRow[] {
534
+ return TOOL_LAYOUT_CHOICES.map((c) => ({
535
+ label: c,
536
+ note: TOOL_LAYOUT_NOTES[c],
537
+ }));
538
+ }
539
+
540
+ const openToolLayout = (ctx: ExtensionCommandContext): Promise<boolean | void> => {
541
+ const opened = activeToolLayout();
542
+ return openLivePicker(ctx, {
543
+ choices: TOOL_LAYOUT_CHOICES,
544
+ rows: toolLayoutRows(),
545
+ opened,
546
+ text: TOOL_LAYOUT_PICKER_TEXT,
547
+ label: "Tool layout",
548
+ current: activeToolLayout,
549
+ apply: setToolLayout,
550
+ headlessLabels: TOOL_LAYOUT_CHOICES.map((c) => (c === opened ? `${c} ✓` : c)),
551
+ cancel: true,
552
+ });
553
+ };
554
+
515
555
  const openRenderCache = (ctx: ExtensionCommandContext): Promise<boolean | void> => {
516
556
  const opened = activeRenderCache();
517
557
  return openChoicePicker(ctx, {
@@ -691,51 +731,58 @@ export const MENUS: ArnativeMenu[] = [
691
731
  value: "animations",
692
732
  label: "Animations",
693
733
  description: "choose the working spinner",
694
- group: "Appearance",
734
+ group: "Display",
695
735
  open: openAnimations,
696
736
  },
697
737
  {
698
738
  value: "diffs",
699
739
  label: "Diffs",
700
740
  description: "side-by-side Before/After or unified diff",
701
- group: "Appearance",
741
+ group: "Display",
702
742
  open: openDiffs,
703
743
  },
704
744
  {
705
- value: "compact",
706
- label: "Auto-compact",
707
- description: "smart by window or a fixed token budget (off by default)",
708
- group: "Performance",
709
- open: openAutoCompact,
745
+ value: "tools",
746
+ label: "Tool layout",
747
+ description: "ADE grouped phase progress box or classic per-tool boxes",
748
+ group: "Display",
749
+ open: openToolLayout,
710
750
  },
711
751
  {
712
752
  value: "render",
713
753
  label: "Render cache",
714
754
  description: "cache settled transcript rows across frames (on by default)",
715
- group: "Performance",
755
+ group: "Display",
716
756
  open: openRenderCache,
717
757
  },
718
- {
719
- value: "payload",
720
- label: "Payload limit",
721
- description: "max HTTP request size for remote proxies (1 MB by default)",
722
- group: "Performance",
723
- open: openPayloadLimit,
724
- },
725
758
  {
726
759
  value: "providers",
727
760
  label: "Providers",
728
761
  description: "custom endpoints: endpoint, key, name — the rest is automatic",
729
- group: "Models",
762
+ group: "Models & Context",
730
763
  open: openProviders,
731
764
  },
732
765
  {
733
766
  value: "heal",
734
767
  label: "Model heal",
735
768
  description: "auto-fix models.json: compat flags, limits, thinking levels (on by default)",
736
- group: "Models",
769
+ group: "Models & Context",
737
770
  open: openModelHeal,
738
771
  },
772
+ {
773
+ value: "compact",
774
+ label: "Auto-compact",
775
+ description: "smart by window or a fixed token budget (off by default)",
776
+ group: "Models & Context",
777
+ open: openAutoCompact,
778
+ },
779
+ {
780
+ value: "payload",
781
+ label: "Payload limit",
782
+ description: "max HTTP request size for remote proxies (1 MB by default)",
783
+ group: "Models & Context",
784
+ open: openPayloadLimit,
785
+ },
739
786
  {
740
787
  value: "usage",
741
788
  label: "Usage",
@@ -821,7 +868,7 @@ async function openMainMenu(ctx: ExtensionCommandContext, startGroup?: MenuGroup
821
868
  }
822
869
  }
823
870
 
824
- export async function arnativeHandler(args: string, ctx: ExtensionCommandContext): Promise<void> {
871
+ async function arnativeHandler(args: string, ctx: ExtensionCommandContext): Promise<void> {
825
872
  if (!ctx.hasUI) return;
826
873
  const sub = args.trim().toLowerCase();
827
874
 
@@ -852,7 +899,7 @@ export function arnativeCompletions(prefix: string): AutocompleteItem[] | null {
852
899
 
853
900
  /** The theme this package ships. Applied only when pi has no theme setting of its own, so a
854
901
  * fresh install lands on Arnative without ever overriding a choice someone made. */
855
- export const DEFAULT_THEME = "arnative";
902
+ const DEFAULT_THEME = "arnative";
856
903
 
857
904
  /** A theme of this package's family: `arnative` itself or an `arnative-<variant>`. The
858
905
  * generator (`themes/gen-themes.mjs`) ships only such names, so the name is the identity —
@@ -899,6 +946,7 @@ export function recordProfile(): void {
899
946
  [SPINNER_PRESET_KEY]: activeSpinnerPreset(),
900
947
  [SPINNER_GRADIENT_KEY]: activeSpinnerGradient() ? "on" : "off",
901
948
  [EDIT_DIFF_KEY]: activeEditDiff(),
949
+ [TOOL_LAYOUT_KEY]: activeToolLayout(),
902
950
  [AUTO_COMPACT_KEY]: activeAutoCompact(),
903
951
  [PAYLOAD_LIMIT_KEY]: savedPayloadLimit(),
904
952
  [MODEL_HEAL_KEY]: activeModelHeal(),
@@ -930,383 +978,8 @@ export default function (pi: ExtensionAPI) {
930
978
  }
931
979
  }
932
980
 
933
- // Self-check: `node extensions/arnative.ts`
934
- if (isMain(import.meta.url)) {
935
- assert(markedLabels(["a", "b"], "b")[1] === "● b", "markedLabels marks the active theme");
936
- assert(markedLabels(["a", "b"], "b")[0] === " a", "markedLabels leaves others unmarked");
937
- assert(markedLabels(["a"], undefined)[0] === " a", "markedLabels handles no active theme");
938
- const labels = menuRows(MENUS);
939
- assert(labels.length === MENUS.length, "menuRows one row per menu");
940
- assert(rowText(labels[0]!) === "Themes · arnative themes only (all themes: /settings → Theme)", "menu row text format");
941
- assert(labels[0]!.label === "Themes" && labels[0]!.note === "arnative themes only (all themes: /settings → Theme)", "menu row keeps label and note apart");
942
- assert(MENU_TITLE === "Settings - Arnative\u2819", `the menu title is the pinned string, got ${MENU_TITLE}`);
943
- assert(MENU_DESC === "Themes, headers, footers, chatbox, animations, auto-compact, render, payload, providers, usage, budget", `the menu description is the pinned string, got ${MENU_DESC}`);
944
- // Every menu row is reachable and the description names them all, so a new screen cannot
945
- // be added to MENUS and forgotten in the copy a user reads first.
946
- assert(MENUS.length === 13, "thirteen settings screens");
947
- {
948
- const catRows = menuRows([...MENU_CATEGORIES]);
949
- assert(catRows.map((r) => r.label).join(",") === "Appearance,Performance,Models,Spend", "root menu lists the four categories in order");
950
- const totalGrouped = MENU_CATEGORIES.reduce((n, c) => n + categoryMenus(c.label).length, 0);
951
- assert(totalGrouped === MENUS.length, "every menu item belongs to one of the four categories");
952
- const perf = categoryMenus("Performance");
953
- assert(perf.map((m) => m.value).join(",") === "compact,render,payload", "Performance group lists Auto-compact, Render cache, Payload limit in order");
954
- const heal = modelHealRows("Flags");
955
- assert(heal.map((r) => r.label).join(",") === "Full,Flags,Off,Run now", "Model heal rows: three modes then Run now");
956
- assert(heal.filter((r) => r.chosen).map((r) => r.label).join(",") === "Flags", "Model heal marks only the saved mode");
957
- const rc = renderCacheRows("On");
958
- assert(rc.map((r) => r.label).join(",") === "On,Off", "Render cache rows: On then Off");
959
- assert(rc.filter((r) => r.chosen).map((r) => r.label).join(",") === "On", "Render cache marks only the saved mode");
960
- const dRows = diffRows();
961
- assert(dRows.map((r) => r.label).join(",") === "Split,Unified", "Diffs rows: Split then Unified");
962
- const pl = payloadLimitRows("16 MB");
963
- assert(pl.map((r) => r.label).join(",") === "Off,1 MB,4 MB,8 MB,16 MB,32 MB,Custom", "Payload limit rows list presets then Custom");
964
- assert(pl.filter((r) => r.chosen).map((r) => r.label).join(",") === "16 MB", "Payload limit marks the active preset");
965
- const plCustom = payloadLimitRows("11 MB");
966
- assert(plCustom.filter((r) => r.chosen).map((r) => r.label).join(",") === "Custom", "Payload limit marks Custom when a non-preset MB is active");
967
- assert(plCustom[plCustom.length - 1]!.note!.includes("11 MB"), "Custom row displays the active custom MB");
968
- }
969
- for (const label of ["Themes", "Headers", "Footers", "Chatbox", "Animations", "Diffs", "Auto-compact", "Render cache", "Payload limit", "Providers", "Usage", "Budget"]) {
970
- assert(MENUS.some((m) => m.label === label), `MENUS carries the ${label} screen`);
971
- }
972
- assert(/^Settings - Arnative/.test(MENU_TITLE), "title follows `<setting> - <extension>`");
973
- assert(MENU_TITLE.indexOf("\u2819") > 0 && !/\ufffd/.test(MENU_TITLE), "title carries the Braille glyph, not a blank/replacement cell");
974
- assert(MENUS.every((m) => typeof m.open === "function"), "every menu opens");
975
- assert(MENUS.some((m) => m.value === "headers"), "headers menu registered");
976
-
977
- assert(arnativeCompletions("th")!.length === 1, "completions match prefix");
978
- assert(arnativeCompletions("th")![0]!.value === "themes", "completions value = menu value");
979
- assert(arnativeCompletions("he")![0]!.value === "headers", "headers menu has completions");
980
- assert(arnativeCompletions("fo")![0]!.value === "footers", "footers menu has completions");
981
- assert(MENUS.some((m) => m.value === "footers"), "footers menu registered");
982
- assert(arnativeCompletions("ch")![0]!.value === "chatbox", "chatbox menu has completions");
983
- assert(MENUS.some((m) => m.value === "chatbox"), "chatbox menu registered");
984
- assert(arnativeCompletions("co")![0]!.value === "compact", "compact menu has completions");
985
- assert(MENUS.some((m) => m.value === "compact"), "compact menu registered");
986
-
987
- // The Auto-compact picker marks the saved choice with a green ✓ at the row's end.
988
- const acRows = autoCompactRows("Smart");
989
- assert(acRows[0]!.label === "Off" && acRows[1]!.label === "Smart", "labels stay clean — the marker is not part of the label");
990
- assert(acRows[1]!.chosen === true && acRows[0]!.chosen !== true, "the ✓ follows the saved choice");
991
- assert(acRows.every((r) => r.note!.length > 0), "every Auto-compact row carries its note");
992
- assert(autoCompactRows("Off")[0]!.chosen === true, "the marker moves when the saved choice changes");
993
- assert(arnativeCompletions("re")![0]!.value === "render", "render cache menu has completions");
994
- assert(MENUS.some((m) => m.value === "render"), "render cache menu registered");
995
- assert(arnativeCompletions("pa")![0]!.value === "payload", "payload limit menu has completions");
996
- assert(MENUS.some((m) => m.value === "payload"), "payload limit menu registered");
997
- assert(arnativeCompletions("pr")![0]!.value === "providers", "providers menu has completions");
998
- assert(MENUS.some((m) => m.value === "providers"), "providers menu registered");
999
- // Every slash command, and the one alias: `/providers` must land on the providers screen.
1000
- {
1001
- const registered = new Map<string, { description: string; handler: unknown }>();
1002
- registerCommands({ registerCommand: (name, options) => { registered.set(name, options as never); } } as never);
1003
- assert([...registered.keys()].join(",") === "arnative,providers", "two commands: /arnative and /providers");
1004
- assert(typeof registered.get("providers")!.handler === "function", "/providers has a handler");
1005
- assert(MENUS.some((m) => m.value === "providers"), "/providers routes to a menu row that exists");
1006
- assert(
1007
- registered.get("arnative")!.description === "Arnative settings menu: themes, headers, footers, chatbox, animations, auto-compact, model heal, render cache, payload limit, providers, usage, budget",
1008
- "the /arnative command description names every screen: " + registered.get("arnative")!.description,
1009
- );
1010
- }
1011
- // Usage is reachable from /arnative even though it is a dashboard, not a setting.
1012
- assert(MENUS.some((m) => m.value === "usage"), "usage menu registered");
1013
- assert(arnativeCompletions("us")![0]!.value === "usage", "usage menu has completions");
1014
- assert(typeof MENUS.find((m) => m.value === "usage")!.open === "function", "the usage row opens the dashboard");
1015
- // The Budget row: warn-only caps, enforce on blocks the next turn.
1016
- assert(MENUS.some((m) => m.value === "budget" && typeof m.open === "function"), "budget menu registered");
1017
- assert(arnativeCompletions("b")![0]!.value === "budget", "budget menu has completions");
1018
- assert(
1019
- rowText(labels[labels.length - 1]!) === "Budget · warn-only spend caps on today / 30d; enforce on blocks the next turn",
1020
- "the budget row text is pinned: " + rowText(labels[labels.length - 1]!),
1021
- );
1022
-
1023
- // The /arnative picker lists the package's family only; everything else (system, dark,
1024
- // light, a theme of the user's own) stays in /settings → Theme.
1025
- assert(isArnativeThemeName("arnative"), "the default theme is family");
1026
- assert(isArnativeThemeName("arnative-cyberpunk"), "a variant is family");
1027
- for (const outsider of ["system", "dark", "light", "omarchy-system", "arnativeX", ""])
1028
- assert(!isArnativeThemeName(outsider), `${JSON.stringify(outsider)} is not family`);
1029
-
1030
- // The shipped theme is applied only when pi has no theme setting of its own.
1031
- assert(shouldApplyDefaultTheme(undefined, [{ name: "arnative" }]), "an unset theme installs Arnative");
1032
- assert(!shouldApplyDefaultTheme("arnative", [{ name: "arnative" }]), "an explicit Arnative setting is left alone");
1033
- assert(!shouldApplyDefaultTheme("gruvbox", [{ name: "arnative" }]), "a chosen theme is never overridden");
1034
- assert(!shouldApplyDefaultTheme(undefined, [{ name: "dark" }]), "no install when the theme did not load");
1035
- assert(arnativeCompletions("zz") === null, "completions null when nothing matches");
1036
-
1037
- // Live-preview picker (shared by Themes and Headers): move = preview, Enter = keep, Esc = revert.
1038
- const fakeTheme = { fg: (_c: string, t: string) => t, bold: (t: string) => t };
1039
- const pickerText: ListPickerText = { title: screenTitle("Themes"), description: "sub", legend: "[Esc] Back" };
1040
- const previews: string[] = [];
1041
- let reverted = 0;
1042
- let done = 0;
1043
- // Wrap means one step down from the last row lands on the initial value, leaving
1044
- // nothing for Esc to revert, so the list carries a third row for this assertion.
1045
- const picker = new ListPicker(fakeTheme, nameRows(["arnative", "arnative-cyberpunk", "arnative-mono"]), "arnative", {
1046
- preview: (n) => previews.push(n),
1047
- revert: () => reverted++,
1048
- done: () => done++,
1049
- requestRender: () => {},
1050
- }, pickerText);
1051
- const lines = picker.render(50);
1052
- assert(lines[0]!.startsWith("╭") && lines[lines.length - 1]!.startsWith("╰"), "picker framed");
1053
- assert(lines.every((l) => visibleWidth(l) === 50), "picker lines fit width 50");
1054
- assert(lines.some((l) => l.includes(screenTitle("Themes"))), "picker renders the configured title");
1055
- assert(lines.some((l) => l.includes("❯ arnative")), "the cursor marks the live value");
1056
- assert(!lines.some((l) => l.includes("●")), "no redundant ● column next to the ❯ cursor");
1057
- picker.handleInput("\x1b[B"); // down
1058
- assert(previews.length === 1 && previews[0] === "arnative-cyberpunk", "move previews immediately");
1059
- assert(picker.render(50).some((l) => l.includes("❯ arnative-cyberpunk")), "the cursor follows the preview");
1060
- picker.handleInput("\r"); // enter
1061
- assert(done === 1 && reverted === 0, "Enter keeps (no revert)");
1062
- picker.handleInput("\x1b[B");
1063
- picker.handleInput("\x1b"); // escape
1064
- assert(reverted === 1 && done === 2, "Esc reverts after preview");
1065
-
1066
- // `←` reports upward instead of closing on a screen with a parent, reverting the live
1067
- // preview first; the root menu has nothing behind it and omits the key.
1068
- assert(LIST_LEGEND_ROOT === "[↑↓] Move [Enter] Select [Esc] Close", "root menu legend omits ←");
1069
- assert(LIST_LEGEND_MOVE === "[↑↓] Move [Enter] Select [Esc] Back", "submenu legend advertises Esc Back");
1070
- assert(LIST_LEGEND_LIVE === "[↑↓] Preview [Enter] Select [Esc] Back", "live legend advertises Esc Back");
1071
- let backs = 0;
1072
- let backReverts = 0;
1073
- const childPicker = new ListPicker(fakeTheme, nameRows(["a", "b"]), "a", {
1074
- preview: () => {},
1075
- revert: () => backReverts++,
1076
- done: () => {},
1077
- back: () => backs++,
1078
- requestRender: () => {},
1079
- }, pickerText);
1080
- childPicker.handleInput("\x1b[D"); // ←
1081
- childPicker.handleInput("\x1b"); // Esc
1082
- assert(backs === 2 && backReverts === 0, "Esc and ← both report back; the parent owns the revert");
1083
- // The root menu has no parent, so the same keys must still leave the screen.
1084
- let rootCancels = 0;
1085
- const rootPicker = new ListPicker(fakeTheme, nameRows(["a"]), undefined, {
1086
- preview: () => {},
1087
- revert: () => {},
1088
- done: () => {},
1089
- cancel: () => rootCancels++,
1090
- requestRender: () => {},
1091
- }, pickerText, false);
1092
- rootPicker.handleInput("\x1b[D");
1093
- rootPicker.handleInput("\x1b"); // Esc
1094
- assert(rootCancels === 2, "Esc and ← close the root menu, which has no parent");
1095
-
1096
- // The main menu reuses the picker with preview/revert as no-ops: moving changes no
1097
- // setting, only Enter opens a row. `reverted` proves it.
1098
- let menuReverts = 0;
1099
- let menuCancelled = false;
1100
- const categoryRows = menuRows([...MENU_CATEGORIES]);
1101
- const mainPicker = new ListPicker(fakeTheme, categoryRows, undefined, {
1102
- preview: () => {},
1103
- revert: () => { menuReverts++; },
1104
- done: () => {},
1105
- cancel: () => { menuCancelled = true; },
1106
- requestRender: () => {},
1107
- }, { title: MENU_TITLE, description: MENU_DESC, legend: LIST_LEGEND_ROOT }, false);
1108
- // 120 columns: the description names the screens (a tripwire — a screen added to MENUS must
1109
- // be added to the copy too), and that one-liner no longer fits 100.
1110
- const menuLines = mainPicker.render(120);
1111
- assert(menuLines.some((l) => l.includes(MENU_TITLE)), "the main menu renders its title");
1112
- assert(menuLines.some((l) => l.includes("[Esc] Close") && !l.includes("←")), "the root menu legend renders without a back key");
1113
- assert(menuLines.some((l) => l.includes(MENU_DESC)), "the main menu renders the description under the title");
1114
- assert(menuLines.findIndex((l) => l.includes(MENU_TITLE)) < menuLines.findIndex((l) => l.includes(MENU_DESC)), "description sits below the title");
1115
- assert(menuLines.every((l) => visibleWidth(l) === 120), "main menu lines fit the width");
1116
- // The pinned /arnative layout: `❯ Appearance · themes, headers…`, every `·` in one column.
1117
- const plainMenu = menuLines.map(stripAnsi);
1118
- const row0 = menuLines.map(stripAnsi).find((l) => l.includes("❯ Appearance"))!;
1119
- // The row is `│ ❯ <label padded to the widest label><divider><note>`: assert the shape,
1120
- // not a literal run of spaces, so adding a wider screen cannot break the layout test.
1121
- const widest = Math.max(...MENU_CATEGORIES.map((c) => c.label.length));
1122
- assert(
1123
- row0.startsWith(`│ ❯ ${"Appearance".padEnd(widest)}${ROW_DIVIDER}themes, headers, footers`),
1124
- `menu row layout, got ${JSON.stringify(row0)}`,
1125
- );
1126
- assert(plainMenu.filter((l) => l.includes(ROW_DIVIDER)).every((l) => l.indexOf(ROW_DIVIDER) === row0.indexOf(ROW_DIVIDER)), "every divider sits in one column");
1127
- assert(
1128
- plainMenu.some((l) => l.startsWith(`│ ${"Performance".padEnd(widest)}${ROW_DIVIDER}`)),
1129
- "unselected rows indent to the marker column",
1130
- );
1131
-
1132
- // A menu opened with a `current` row starts there. The handler passes the row it last
1133
- // used, so a submenu reopened by `←` lands back on that row instead of jumping to the
1134
- // top of the list — the cursor is the user's place, not the component's business.
1135
- const resumed = new ListPicker(fakeTheme, categoryRows, "Models", {
1136
- preview: () => {},
1137
- revert: () => {},
1138
- done: () => {},
1139
- requestRender: () => {},
1140
- }, { title: MENU_TITLE, description: MENU_DESC, legend: LIST_LEGEND_ROOT }, false);
1141
- const resumedRows = resumed.render(60).map(stripAnsi);
1142
- assert(resumedRows.some((l) => l.startsWith("│ ❯ Models")), "the menu reopens on the row it was left on");
1143
- assert(!resumedRows.some((l) => l.startsWith("│ ❯ Appearance")), "and not on the first row");
1144
-
1145
- // The box border follows the session's thinking level (theme `thinking*` slot), so the
1146
- // menu reads as belonging to the active model.
1147
- const tagged = { fg: (c: string, t: string) => `<${c}>${t}</>`, bold: (t: string) => `<bold>${t}</bold>` };
1148
- const thinkingPicker = new ListPicker(tagged, categoryRows, undefined, {
1149
- preview: () => {},
1150
- revert: () => {},
1151
- done: () => {},
1152
- requestRender: () => {},
1153
- }, { title: MENU_TITLE, description: MENU_DESC, legend: "f" }, false, "high");
1154
- const taggedLines = thinkingPicker.render(200);
1155
- assert(taggedLines[0]!.includes("<thinkingHigh>"), "the menu border uses the session's thinking slot");
1156
- assert(taggedLines[taggedLines.length - 1]!.includes("<thinkingHigh>"), "the bottom border uses the thinking slot too");
1157
- assert(!taggedLines[0]!.includes("<accentSoft>"), "the border is not accentSoft any more");
1158
- // Every frame part must use the same painter: mixing soft walls with thinking rails made
1159
- // the frame two-toned (accentSoft `│` walls, thinking `╭─╮` rails).
1160
- const walls = taggedLines.filter((l) => l.startsWith("<thinkingHigh>│"));
1161
- assert(walls.length >= 5, `every wall is painted by the thinking painter, got ${walls.length}`);
1162
- assert(
1163
- !taggedLines.some((l) => l.startsWith("<accentSoft>│") || l.startsWith("<accentSoft>╭") || l.startsWith("<accentSoft>╰")),
1164
- "no frame glyph is left on accentSoft",
1165
- );
1166
- // The chosen row's label takes the `accentSoft` token (bold), never a hand-written colour; the
1167
- // `❯` marker stays on `accent` so the cursor is still findable when the theme has no accentSoft.
1168
- assert(
1169
- taggedLines.some((l) => l.includes("<accent>❯ </><accentSoft><bold>")),
1170
- "the chosen label is the accentSoft token in bold",
1171
- );
1172
- assert(taggedLines.some((l) => l.includes("<accent>❯ ")), "the ❯ marker keeps the accent voice");
1173
- const offPicker = new ListPicker(tagged, categoryRows, undefined, {
1174
- preview: () => {},
1175
- revert: () => {},
1176
- done: () => {},
1177
- requestRender: () => {},
1178
- }, { title: MENU_TITLE, description: MENU_DESC, legend: "f" }, false, undefined);
1179
- assert(offPicker.render(200)[0]!.includes("<thinkingOff>"), "a missing level paints thinkingOff");
1180
- mainPicker.handleInput("\x1b[B");
1181
- assert(mainPicker.index === 1, "the selection is readable for the caller to open");
1182
- mainPicker.handleInput("\x1b[B");
1183
- assert(mainPicker.index === 2, "index tracks further moves");
1184
- assert(menuReverts === 0, "moving never reverts: the menu changes no setting");
1185
- // Esc closes the menu (cancel), it does not go through the keep path.
1186
- mainPicker.handleInput("\x1b");
1187
- assert(menuCancelled, "Esc cancels the main menu");
1188
- assert(menuReverts === 0, "cancel does not revert either");
1189
-
1190
- // Headers reuses the same picker with its own copy and presets.
1191
- assert(HEADER_PRESETS[0] === "Pi (system)", "built-in header preset is listed first");
1192
- const headerPicker = new ListPicker(fakeTheme, nameRows(HEADER_PRESETS), "Arnative (Full)", { preview: () => {}, revert: () => {}, done: () => {}, requestRender: () => {} }, HEADERS_PICKER_TEXT);
1193
- const headerLines = headerPicker.render(50);
1194
- assert(headerLines.some((l) => l.includes(screenTitle("Headers"))), "headers picker title");
1195
- assert(headerLines.some((l) => l.includes("❯ Arnative (Full)")), "headers picker cursors the active preset");
1196
- assert(headerLines.some((l) => l.includes(" Pi (system)")), "headers picker lists the built-in preset");
1197
-
1198
- // Footers reuses the same picker too.
1199
- assert(FOOTER_PRESETS[0] === "Pi (system)", "built-in footer preset is listed first");
1200
- const footerPicker = new ListPicker(fakeTheme, nameRows(FOOTER_PRESETS), "Pi (system)", { preview: () => {}, revert: () => {}, done: () => {}, requestRender: () => {} }, footersPickerText());
1201
- const footerLines = footerPicker.render(50);
1202
- assert(footerLines.some((l) => l.includes(screenTitle("Footers"))), "footers picker title");
1203
- assert(footerLines.some((l) => l.includes("❯ Pi (system)")), "footers picker cursors the active preset");
1204
- assert(footerLines.some((l) => l.includes("Arnative (Minimal)")), "footers picker lists the minimal preset");
1205
- assert(footerLines.filter((l) => l.includes("Arnative (")).length === 2, "both arnative footer presets are selectable");
1206
- assert(/\[c\] Cost (on|off)/.test(footersPickerText().legend), "footers legend advertises the cost switch and its live state");
1207
-
1208
- // Chatbox reuses the same picker with summary rows (Box/Icon/Dialog), Pi (system) first and Arnative second.
1209
- assert(CHATBOX_PRESETS[0] === "Pi (system)" && CHATBOX_PRESETS[1] === "Arnative", "chatbox presets list Pi (system) then Arnative");
1210
- assert(CHATBOX_DIALOGS.includes(activeChatboxDialog()), "active chatbox dialog is valid");
1211
- const chatboxTagTheme = { fg: (c: string, t: string) => `<${c}>${t}</${c}>` };
1212
- const chatboxTagged = chatboxSummary(chatboxTagTheme);
1213
- assert(chatboxTagged.some((l) => l.includes("<dim>Box </dim><dim> · </dim><text>")), "chatbox summary renders dim Box label and separator");
1214
- assert(chatboxTagged.some((l) => l.startsWith("<dim>Icon </dim><dim> · </dim>") && l.includes(`<accent>${activeChatboxPrompt()}</accent>`) && l.includes(" ") && !l.includes("|")), "chatbox summary highlights the active icon in accent with double spacing and no |");
1215
- const expectedDialogTag = activeChatboxDialog() === DEFAULT_CHATBOX_DIALOG ? " <dim>(default)</dim>" : "";
1216
- assert(chatboxTagged.some((l) => l === `<dim>Dialog</dim><dim> · </dim><text>${activeChatboxDialog().toLowerCase()}</text>${expectedDialogTag}`), "chatbox summary renders dim Dialog label, separator, and default tag");
1217
- const chatboxPicker = new ListPicker(fakeTheme, chatboxRows(), "Arnative", { preview: () => {}, revert: () => {}, done: () => {}, requestRender: () => {}, summary: () => chatboxSummary(fakeTheme) }, CHATBOX_PICKER_TEXT);
1218
- const chatboxLines = chatboxPicker.render(84);
1219
- assert(chatboxLines.some((l) => l.includes(screenTitle("Chatbox"))), "chatbox picker title");
1220
- assert(chatboxLines.some((l) => l.includes("Box · Arnative")), "chatbox picker shows Box summary");
1221
- assert(chatboxLines.some((l) => l.includes("❯ Arnative")), "chatbox picker cursors the active preset");
1222
- assert(chatboxLines.some((l) => l.includes(" Pi (system)")), "chatbox picker lists the built-in preset");
1223
- assert(CHATBOX_PICKER_TEXT.legend.includes("[i] Icon [D] Dialog"), "chatbox legend advertises [i] Icon and [D] Dialog");
1224
-
1225
- // Animations picker: "Pi (system)" carries a note AND renders "(system)" in dim
1226
- const animPicker = new ListPicker(
1227
- { fg: (c, t) => `<${c}>${t}</${c}>`, bold: (t) => `<bold>${t}</bold>` },
1228
- animationRows(),
1229
- "Pi (system)",
1230
- { preview: () => {}, revert: () => {}, done: () => {}, requestRender: () => {} },
1231
- animationsPickerText(),
1232
- );
1233
- const animLines = animPicker.render(120);
1234
- assert(animLines.some((l) => l.includes("Pi ") && l.includes("<dim>(system)</dim>")), "animations picker dims (system)");
1235
-
1236
- // `g` reaches only a screen that passes the hook, and its legend follows the toggle.
1237
- const quiet = (): void => undefined;
1238
- let gradientOn = false;
1239
- const gradientPicker = new ListPicker(
1240
- fakeTheme,
1241
- animationRows(),
1242
- "Pi (system)",
1243
- {
1244
- preview: quiet,
1245
- revert: quiet,
1246
- done: quiet,
1247
- requestRender: quiet,
1248
- toggleGradient: () => {
1249
- gradientOn = !gradientOn;
1250
- },
1251
- legend: () => `[g] Gradient ${gradientOn ? "on" : "off"}`,
1252
- },
1253
- animationsPickerText(),
1254
- );
1255
- gradientPicker.handleInput("g");
1256
- assert(gradientOn, "g reaches the screen's own toggle");
1257
- assert(gradientPicker.render(120).some((l) => l.includes("[g] Gradient on")), "the legend follows the toggle");
1258
- assert(gradientPicker.index === 0, "g is not a row key: the cursor stays put");
1259
- mainPicker.handleInput("g");
1260
- assert(gradientOn, "a screen without the hook ignores g");
1261
-
1262
- // Multi-select (Providers → model list): Space toggles, `[x]` marks, the cursor still moves.
1263
- const picked: string[] = [];
1264
- const chosen = new Set<string>(["a"]);
1265
- const multiRows = nameRows(["a", "b", "c"]);
1266
- const multiPicker = new ListPicker(fakeTheme, multiRows, "a", {
1267
- preview: quiet,
1268
- revert: quiet,
1269
- done: quiet,
1270
- requestRender: quiet,
1271
- toggle: () => {
1272
- const label = multiRows[multiPicker.index]!.label;
1273
- if (chosen.has(label)) chosen.delete(label);
1274
- else chosen.add(label);
1275
- picked.push(label);
1276
- },
1277
- marked: (label) => chosen.has(label),
1278
- }, { title: screenTitle("Providers"), description: "pick models", legend: "[Space] Toggle" }, false);
1279
- const multiLines = multiPicker.render(50).map(stripAnsi);
1280
- assert(multiLines.some((l) => l.includes("❯ [x] a")), "a checked row shows [x] behind the cursor");
1281
- assert(multiLines.some((l) => l.includes("[ ] b")), "unchecked rows show [ ]");
1282
- multiPicker.handleInput(" ");
1283
- assert(picked[0] === "a" && !chosen.has("a"), "Space toggles the row under the cursor");
1284
- multiPicker.handleInput("\x1b[B");
1285
- multiPicker.handleInput(" ");
1286
- assert(chosen.has("b"), "Space toggles the row the cursor moved to");
1287
- assert(multiPicker.render(50).map(stripAnsi).some((l) => l.includes("❯ [x] b")), "the check follows the cursor");
1288
- mainPicker.handleInput(" ");
1289
- assert(chosen.has("b") && picked.length === 2, "a screen without the toggle hook ignores Space");
1290
-
1291
- // Unhandled keys reach the screen's own switch (`press`), and no hook means no route.
1292
- let pressed: string[] = [];
1293
- const pressPicker = new ListPicker(fakeTheme, nameRows(["a", "b", "c"]), "a", {
1294
- preview: quiet,
1295
- revert: quiet,
1296
- done: quiet,
1297
- requestRender: quiet,
1298
- press: (keyData) => pressed.push(keyData),
1299
- }, { title: screenTitle("Providers"), description: "pick models", legend: "[a] API" }, false);
1300
- pressPicker.handleInput("a");
1301
- assert(pressed.length === 1 && pressed[0] === "a", "an unhandled key reaches the screen via press");
1302
- const routed = new ListPicker(fakeTheme, nameRows(["a"]), undefined, {
1303
- preview: quiet,
1304
- revert: quiet,
1305
- done: quiet,
1306
- requestRender: quiet,
1307
- });
1308
- routed.handleInput("a");
1309
- assert(pressed.length === 1, "a screen without press ignores stray letters");
1310
-
1311
- console.log("arnative.ts self-check OK");
1312
- }
981
+ export const __test = {
982
+ footersPickerText,
983
+ HEADERS_PICKER_TEXT,
984
+ CHATBOX_PICKER_TEXT,
985
+ };