@bismawy/pi-arnative 0.13.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,16 +24,26 @@ import {
24
24
  setSpinnerGradient,
25
25
  setSpinnerPreset,
26
26
  } from "./animations.ts";
27
- import { CHATBOX_DIALOG_KEY, CHATBOX_PRESET_KEY, CHATBOX_PROMPT_KEY, FOOTER_COST_KEY, FOOTER_PRESET_KEY, HEADER_PRESET_KEY, BUDGET_DAY_KEY, BUDGET_ENFORCE_KEY, BUDGET_MONTH_KEY, RENDER_CACHE_KEY, ensureChoices } from "../lib/preset-store.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";
28
+ import { EDIT_DIFF_CHOICES, activeEditDiff, setEditDiff, type EditDiffMode } from "./tools.ts";
28
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, type FooterPreset } from "./footer.ts";
29
30
  import { activeBudgetDay, activeBudgetEnforce, activeBudgetMonth, openBudget } from "./budget.ts";
30
31
  import { HEADER_PRESETS, activeHeaderPreset, setHeaderPreset, type HeaderPreset } from "./section-headers.ts";
31
32
  import {
32
33
  AUTO_COMPACT_CHOICES,
33
34
  AUTO_COMPACT_KEY,
35
+ PAYLOAD_LIMIT_PRESETS,
34
36
  activeAutoCompact,
37
+ activePayloadLimit,
38
+ ceilingsForMb,
39
+ envByteWallOverride,
40
+ parsePayloadLimit,
41
+ payloadLimitMb,
42
+ savedPayloadLimit,
35
43
  setAutoCompact,
44
+ setPayloadLimit,
36
45
  type AutoCompactChoice,
46
+ type PayloadLimitPreset,
37
47
  } from "./autocompact.ts";
38
48
  import { cancelManualHeal, healNow } from "./model-heal.ts";
39
49
  import { MODEL_HEAL_CHOICES, MODEL_HEAL_KEY, activeModelHeal, setModelHeal, type ModelHealChoice } from "../lib/model-heal.ts";
@@ -43,29 +53,49 @@ import {
43
53
  setRenderCache,
44
54
  type RenderCacheChoice,
45
55
  } from "./render-cache.ts";
46
- import { LIST_LEGEND_LIVE, LIST_LEGEND_MOVE, LIST_LEGEND_ROOT, ListPicker, nameRows, rowText, type ListPickerText, type ListRow } from "../lib/list-picker.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";
47
57
  import { BACK_KEY_LABEL } from "../lib/shortcuts.ts";
48
58
  import { openProviders } from "../lib/provider.ts";
49
59
  import { openUsage } from "./usage.ts";
50
60
  import { SHORTCUT_OPEN_ARNATIVE } from "../lib/shortcuts.ts";
51
61
 
62
+ export type MenuGroup = "Appearance" | "Performance" | "Models" | "Spend";
63
+
64
+ export interface MenuCategory {
65
+ label: MenuGroup;
66
+ description: string;
67
+ }
68
+
69
+ export const MENU_CATEGORIES: readonly MenuCategory[] = [
70
+ { label: "Appearance", description: "themes, headers, footers, chatbox, animations, diffs" },
71
+ { label: "Performance", description: "auto-compact, render cache, payload limit" },
72
+ { label: "Models", description: "custom providers, model heal" },
73
+ { label: "Spend", description: "usage dashboard, budget caps" },
74
+ ];
75
+
52
76
  export interface ArnativeMenu {
53
77
  value: string;
54
78
  label: string;
55
79
  description: string;
80
+ group: MenuGroup;
56
81
  /** Returns `true` when the screen asked to step back to the menu (`←`). */
57
82
  open: (ctx: ExtensionCommandContext) => Promise<boolean | void>;
58
83
  }
59
84
 
60
85
  /** Menu rows: `Label · description` (same rhythm as /jev-eye's menu). */
61
- export function menuRows(menus: Pick<ArnativeMenu, "label" | "description">[]): ListRow[] {
86
+ export function menuRows(menus: { label: string; description: string }[]): ListRow[] {
62
87
  return menus.map((m) => ({ label: m.label, note: m.description }));
63
88
  }
64
89
 
90
+ /** Items belonging to a single root category in display order. */
91
+ export function categoryMenus(group: MenuGroup, menus: readonly ArnativeMenu[] = MENUS): ArnativeMenu[] {
92
+ return menus.filter((m) => m.group === group);
93
+ }
94
+
65
95
  /** Title of the settings menu, derived from `screenTitle` so the format lives in one place. */
66
96
  export const MENU_TITLE = screenTitle("Settings");
67
97
  /** One-line description under the menu title. */
68
- export const MENU_DESC = "Themes, headers, footers, chatbox, animations, auto-compact, render, providers, usage, budget";
98
+ export const MENU_DESC = "Themes, headers, footers, chatbox, animations, auto-compact, render, payload, providers, usage, budget";
69
99
 
70
100
  const THEMES_PICKER_TEXT: ListPickerText = {
71
101
  title: screenTitle("Themes"),
@@ -525,6 +555,66 @@ export function renderCacheRows(opened: RenderCacheChoice): ListRow[] {
525
555
  return RENDER_CACHE_CHOICES.map((c) => ({ label: c, note: RENDER_CACHE_NOTES[c], chosen: c === opened }));
526
556
  }
527
557
 
558
+ const DIFFS_PICKER_TEXT: ListPickerText = {
559
+ title: screenTitle("Diffs"),
560
+ description: "Selection previews live — side-by-side Before │ After or unified +/- diff.",
561
+ legend: LIST_LEGEND_LIVE,
562
+ };
563
+
564
+ const EDIT_DIFF_NOTES: Record<EditDiffMode, string> = {
565
+ Split: "side-by-side Before │ After columns (default)",
566
+ Unified: "single-column +/- diff, easier to copy-paste",
567
+ };
568
+
569
+ /** Rows for `/arnative` → Diffs: Split / Unified. */
570
+ export function diffRows(): ListRow[] {
571
+ return EDIT_DIFF_CHOICES.map((c) => ({
572
+ label: c,
573
+ note: EDIT_DIFF_NOTES[c],
574
+ }));
575
+ }
576
+
577
+ const openDiffs = async (ctx: ExtensionCommandContext): Promise<boolean | void> => {
578
+ const opened = activeEditDiff();
579
+
580
+ if (ctx.mode !== "tui") {
581
+ const labels = EDIT_DIFF_CHOICES.map((c) => (c === opened ? `${c} ✓` : c));
582
+ const pick = await ctx.ui.select(DIFFS_PICKER_TEXT.title, labels);
583
+ if (pick === undefined) return;
584
+ const choice = EDIT_DIFF_CHOICES[labels.indexOf(pick)]!;
585
+ setEditDiff(choice);
586
+ ctx.ui.notify(`[arnative] Diffs: ${choice}`, "info");
587
+ return;
588
+ }
589
+
590
+ const goBack = await ctx.ui.custom<boolean>((tui, theme, _kb, done) => {
591
+ const picker = new ListPicker(
592
+ theme,
593
+ diffRows(),
594
+ opened,
595
+ {
596
+ preview: (name) => setEditDiff(name as EditDiffMode),
597
+ revert: () => setEditDiff(opened),
598
+ done: () => {
599
+ announce(ctx.ui, `Diffs: ${activeEditDiff()}.`);
600
+ done(false);
601
+ },
602
+ cancel: () => done(false),
603
+ back: () => {
604
+ if (activeEditDiff() !== opened) setEditDiff(opened);
605
+ done(true);
606
+ },
607
+ requestRender: () => tui.requestRender(),
608
+ },
609
+ DIFFS_PICKER_TEXT,
610
+ true,
611
+ ctx.thinkingLevel,
612
+ );
613
+ return picker;
614
+ });
615
+ return goBack === true;
616
+ };
617
+
528
618
  const openRenderCache = async (ctx: ExtensionCommandContext): Promise<boolean | void> => {
529
619
  const opened = activeRenderCache();
530
620
 
@@ -565,91 +655,278 @@ const openRenderCache = async (ctx: ExtensionCommandContext): Promise<boolean |
565
655
  return goBack === true;
566
656
  };
567
657
 
658
+ const PAYLOAD_CUSTOM_LABEL = "Custom";
659
+
660
+ const PAYLOAD_PRESET_NOTES: Record<PayloadLimitPreset, string> = {
661
+ Off: "disabled — send full history (may hit HTTP 413 on strict proxies)",
662
+ "1 MB": "safe default for standard 1 MB reverse proxies (trims at 900 KB)",
663
+ "4 MB": "small raised proxy limit (trims at 3.5 MB)",
664
+ "8 MB": "medium proxy limit (trims at 7.0 MB)",
665
+ "16 MB": "recommended for 1M-context models on 16 MB proxies (trims at 14.1 MB)",
666
+ "32 MB": "high ceiling for image-heavy sessions (trims at 28.1 MB)",
667
+ };
668
+
669
+ function payloadPickerText(): ListPickerText {
670
+ const envOverride = envByteWallOverride();
671
+ const description = envOverride
672
+ ? `Max HTTP request size for remote models (env PI_ARNATIVE_BYTE_WALL_MB=${payloadLimitMb(envOverride)} active now; picking overrides it).`
673
+ : "Max HTTP request size for remote models; older images, thinking, and tool outputs trim above it.";
674
+ return {
675
+ title: screenTitle("Payload limit"),
676
+ description,
677
+ legend: LIST_LEGEND_MOVE,
678
+ };
679
+ }
680
+
681
+ /** Rows for the Payload limit picker: presets plus Custom MB; the active value carries a green ✓. */
682
+ export function payloadLimitRows(opened: string): ListRow[] {
683
+ const isPreset = (PAYLOAD_LIMIT_PRESETS as readonly string[]).includes(opened);
684
+ const customNote = isPreset
685
+ ? "enter any limit in MB (e.g. 11, 24, 100)"
686
+ : `current: ${opened} — enter any limit in MB (1–1024)`;
687
+ return [
688
+ ...PAYLOAD_LIMIT_PRESETS.map((c) => ({ label: c, note: PAYLOAD_PRESET_NOTES[c], chosen: c === opened })),
689
+ { label: PAYLOAD_CUSTOM_LABEL, note: customNote, chosen: !isPreset },
690
+ ];
691
+ }
692
+
693
+ function applyPayloadChoice(ctx: ExtensionCommandContext, choice: string): void {
694
+ const applied = setPayloadLimit(choice);
695
+ const ceilings = applied === "Off" ? null : ceilingsForMb(payloadLimitMb(applied) ?? 1);
696
+ const detail = ceilings ? ` (trims at ${(ceilings.shedTriggerBytes / 1024 / 1024).toFixed(2)} MB)` : " (trimming disabled)";
697
+ announce(ctx.ui, `Payload limit: ${applied}${detail}.`);
698
+ }
699
+
700
+ const openPayloadLimit = async (ctx: ExtensionCommandContext): Promise<boolean | void> => {
701
+ for (;;) {
702
+ const opened = activePayloadLimit();
703
+ const isPreset = (PAYLOAD_LIMIT_PRESETS as readonly string[]).includes(opened);
704
+ const cursor = isPreset ? opened : PAYLOAD_CUSTOM_LABEL;
705
+ const pickerText = payloadPickerText();
706
+
707
+ if (ctx.mode !== "tui") {
708
+ const labels = [...PAYLOAD_LIMIT_PRESETS.map((c) => (c === opened ? `${c} ✓` : c)), isPreset ? PAYLOAD_CUSTOM_LABEL : `${PAYLOAD_CUSTOM_LABEL} (${opened}) ✓`];
709
+ const pick = await ctx.ui.select(pickerText.title, labels);
710
+ if (pick === undefined) return;
711
+ const index = labels.indexOf(pick);
712
+ if (index < PAYLOAD_LIMIT_PRESETS.length) {
713
+ applyPayloadChoice(ctx, PAYLOAD_LIMIT_PRESETS[index]!);
714
+ return;
715
+ }
716
+ const currentMb = payloadLimitMb(opened);
717
+ const raw = await ctx.ui.input("Payload limit (MB, 1–1024, or Off)", currentMb ? String(currentMb) : "16");
718
+ if (raw === undefined) return;
719
+ const parsed = parsePayloadLimit(raw);
720
+ if (!parsed) {
721
+ ctx.ui.notify("[arnative] Enter a number between 1 and 1024 MB (e.g. 11 or 16), or Off.", "warning");
722
+ return;
723
+ }
724
+ applyPayloadChoice(ctx, parsed);
725
+ return;
726
+ }
727
+
728
+ let pickCustom = false;
729
+ const goBack = await ctx.ui.custom<boolean>((tui, theme, _kb, done) => {
730
+ const picker = new ListPicker(
731
+ theme,
732
+ payloadLimitRows(opened),
733
+ cursor,
734
+ {
735
+ preview: () => {},
736
+ revert: () => {},
737
+ done: () => {
738
+ if (picker.index === PAYLOAD_LIMIT_PRESETS.length) {
739
+ pickCustom = true;
740
+ } else {
741
+ applyPayloadChoice(ctx, PAYLOAD_LIMIT_PRESETS[picker.index]!);
742
+ }
743
+ done(false);
744
+ },
745
+ cancel: () => done(false),
746
+ back: () => done(true),
747
+ requestRender: () => tui.requestRender(),
748
+ },
749
+ pickerText,
750
+ false,
751
+ ctx.thinkingLevel,
752
+ );
753
+ return picker;
754
+ });
755
+ if (goBack === true) return true;
756
+ if (!pickCustom) return false;
757
+
758
+ const currentMb = payloadLimitMb(opened);
759
+ const raw = await ctx.ui.custom<string | null>((tui, theme, _kb, done) =>
760
+ new InputPicker(
761
+ theme,
762
+ {
763
+ title: screenTitle("Payload limit"),
764
+ description: "Enter a number between 1 and 1024 MB (e.g. 11 or 16), or Off.",
765
+ legend: INPUT_LEGEND,
766
+ },
767
+ currentMb ? String(currentMb) : "",
768
+ {
769
+ done: (v) => done(v),
770
+ cancel: () => done(null),
771
+ requestRender: () => tui.requestRender(),
772
+ },
773
+ "16",
774
+ ctx.thinkingLevel,
775
+ ),
776
+ );
777
+ if (raw === null) continue;
778
+ const parsed = parsePayloadLimit(raw);
779
+ if (!parsed) {
780
+ ctx.ui.notify("[arnative] Enter a number between 1 and 1024 MB (e.g. 11 or 16), or Off.", "warning");
781
+ continue;
782
+ }
783
+ applyPayloadChoice(ctx, parsed);
784
+ return false;
785
+ }
786
+ };
787
+
568
788
  export const MENUS: ArnativeMenu[] = [
569
789
  {
570
790
  value: "themes",
571
791
  label: "Themes",
572
792
  description: "arnative themes only (all themes: /settings → Theme)",
793
+ group: "Appearance",
573
794
  open: openThemes,
574
795
  },
575
796
  {
576
797
  value: "headers",
577
798
  label: "Headers",
578
799
  description: "choose the header preset",
800
+ group: "Appearance",
579
801
  open: openHeaders,
580
802
  },
581
803
  {
582
804
  value: "footers",
583
805
  label: "Footers",
584
806
  description: "choose the footer preset",
807
+ group: "Appearance",
585
808
  open: openFooters,
586
809
  },
587
810
  {
588
811
  value: "chatbox",
589
812
  label: "Chatbox",
590
813
  description: "choose the input box preset",
814
+ group: "Appearance",
591
815
  open: openChatbox,
592
816
  },
593
817
  {
594
818
  value: "animations",
595
819
  label: "Animations",
596
820
  description: "choose the working spinner",
821
+ group: "Appearance",
597
822
  open: openAnimations,
598
823
  },
824
+ {
825
+ value: "diffs",
826
+ label: "Diffs",
827
+ description: "side-by-side Before/After or unified diff",
828
+ group: "Appearance",
829
+ open: openDiffs,
830
+ },
599
831
  {
600
832
  value: "compact",
601
833
  label: "Auto-compact",
602
834
  description: "smart by window or a fixed token budget (off by default)",
835
+ group: "Performance",
603
836
  open: openAutoCompact,
604
837
  },
605
- {
606
- value: "heal",
607
- label: "Model heal",
608
- description: "auto-fix models.json: compat flags, limits, thinking levels (on by default)",
609
- open: openModelHeal,
610
- },
611
838
  {
612
839
  value: "render",
613
840
  label: "Render cache",
614
841
  description: "cache settled transcript rows across frames (on by default)",
842
+ group: "Performance",
615
843
  open: openRenderCache,
616
844
  },
845
+ {
846
+ value: "payload",
847
+ label: "Payload limit",
848
+ description: "max HTTP request size for remote proxies (1 MB by default)",
849
+ group: "Performance",
850
+ open: openPayloadLimit,
851
+ },
617
852
  {
618
853
  value: "providers",
619
854
  label: "Providers",
620
855
  description: "custom endpoints: endpoint, key, name — the rest is automatic",
856
+ group: "Models",
621
857
  open: openProviders,
622
858
  },
859
+ {
860
+ value: "heal",
861
+ label: "Model heal",
862
+ description: "auto-fix models.json: compat flags, limits, thinking levels (on by default)",
863
+ group: "Models",
864
+ open: openModelHeal,
865
+ },
623
866
  {
624
867
  value: "usage",
625
868
  label: "Usage",
626
869
  description: "open the token & cost dashboard (same as /usage)",
870
+ group: "Spend",
627
871
  open: openUsage,
628
872
  },
629
873
  {
630
874
  value: "budget",
631
875
  label: "Budget",
632
876
  description: "warn-only spend caps on today / 30d; enforce on blocks the next turn",
877
+ group: "Spend",
633
878
  open: openBudget,
634
879
  },
635
880
  ];
636
881
 
637
- /** The settings menu and the loop that gives `←` its meaning: a screen returning `true`
638
- * reopens this menu, anything else ends navigation. `startLabel` is the row to open on,
639
- * so a screen left with `←` (or a direct subcommand) resumes where the user was. */
640
- async function openMainMenu(ctx: ExtensionCommandContext, startLabel?: string): Promise<void> {
641
- const rows = menuRows(MENUS);
882
+ /** Submenu for one category; returns `true` when the user presses `←` to return to the root menu. */
883
+ async function openCategoryMenu(ctx: ExtensionCommandContext, category: MenuCategory, startLabel?: string): Promise<boolean> {
884
+ const items = categoryMenus(category.label);
885
+ const rows = menuRows(items);
886
+ if (ctx.mode !== "tui") {
887
+ const labels = rows.map(rowText);
888
+ const pick = await ctx.ui.select(screenTitle(category.label), labels);
889
+ if (pick === undefined) return false;
890
+ await items[labels.indexOf(pick)]!.open(ctx);
891
+ return false;
892
+ }
893
+ let cursor = startLabel;
894
+ for (;;) {
895
+ const choice = await ctx.ui.custom<{ index?: number; back?: boolean }>((tui, theme, _kb, done) => {
896
+ const picker = new ListPicker(theme, rows, cursor, {
897
+ preview: () => {},
898
+ revert: () => {},
899
+ done: () => done({ index: picker.index }),
900
+ cancel: () => done({ back: false }),
901
+ back: () => done({ back: true }),
902
+ requestRender: () => tui.requestRender(),
903
+ }, { title: screenTitle(category.label), description: category.description[0]!.toUpperCase() + category.description.slice(1), legend: LIST_LEGEND_MOVE }, false, ctx.thinkingLevel);
904
+ return picker;
905
+ });
906
+ if (choice.index === undefined) return choice.back === true;
907
+ const menu = items[choice.index]!;
908
+ cursor = menu.label;
909
+ if ((await menu.open(ctx)) !== true) return false;
910
+ }
911
+ }
912
+
913
+ /** The 4-category settings menu. Selecting a category opens its submenu; `←` steps back
914
+ * up one level (screen → category → root) and remembers the last row at each level. */
915
+ async function openMainMenu(ctx: ExtensionCommandContext, startGroup?: MenuGroup, startItem?: string): Promise<void> {
916
+ const rows = menuRows([...MENU_CATEGORIES]);
642
917
  if (ctx.mode !== "tui") {
643
918
  // No custom components (RPC/headless): a title-only picker, no description row.
644
919
  const labels = rows.map(rowText);
645
920
  const pick = await ctx.ui.select(MENU_TITLE, labels);
646
921
  if (pick === undefined) return;
647
- await MENUS[labels.indexOf(pick)]!.open(ctx);
922
+ await openCategoryMenu(ctx, MENU_CATEGORIES[labels.indexOf(pick)]!);
648
923
  return;
649
924
  }
650
- // Same picker as the submenus, so the description row under the title is rendered by
651
- // one component instead of two dialogs that could drift apart.
652
- let cursor = startLabel;
925
+ if (startGroup && startItem) {
926
+ const cat = MENU_CATEGORIES.find((c) => c.label === startGroup);
927
+ if (cat && (await openCategoryMenu(ctx, cat, startItem)) !== true) return;
928
+ }
929
+ let cursor: string | undefined = startGroup;
653
930
  for (;;) {
654
931
  const index = await ctx.ui.custom<number | null>((tui, theme, _kb, done) => {
655
932
  const picker = new ListPicker(theme, rows, cursor, {
@@ -665,9 +942,9 @@ async function openMainMenu(ctx: ExtensionCommandContext, startLabel?: string):
665
942
  return picker;
666
943
  });
667
944
  if (index === null || index === undefined) return;
668
- cursor = rows[index]!.label;
669
- const wantsBack = await MENUS[index]!.open(ctx);
670
- if (wantsBack !== true) return;
945
+ const category = MENU_CATEGORIES[index]!;
946
+ cursor = category.label;
947
+ if ((await openCategoryMenu(ctx, category)) !== true) return;
671
948
  }
672
949
  }
673
950
 
@@ -685,9 +962,10 @@ export async function arnativeHandler(args: string, ctx: ExtensionCommandContext
685
962
  ctx.ui.notify(`[arnative] Unknown menu "${sub}". Menus: ${MENUS.map((m) => m.value).join(" | ")}`, "warning");
686
963
  return;
687
964
  }
688
- // A direct subcommand behaves like a menu row: `←` drops into the menu on that row,
965
+ // A direct subcommand behaves like a menu row: `←` drops into its category on that row,
689
966
  // so `/arnative usage` + `←` is not a dead key.
690
- if ((await MENUS[index]!.open(ctx)) === true) await openMainMenu(ctx, MENUS[index]!.label);
967
+ const menu = MENUS[index]!;
968
+ if ((await menu.open(ctx)) === true) await openMainMenu(ctx, menu.group, menu.label);
691
969
  }
692
970
 
693
971
  export function arnativeCompletions(prefix: string): AutocompleteItem[] | null {
@@ -723,7 +1001,7 @@ export function shouldApplyDefaultTheme(
723
1001
  * set without starting a session. */
724
1002
  export function registerCommands(pi: Pick<ExtensionAPI, "registerCommand">): void {
725
1003
  pi.registerCommand("arnative", {
726
- description: "Arnative settings menu: themes, headers, footers, chatbox, animations, auto-compact, model heal, render cache, providers, usage, budget",
1004
+ description: "Arnative settings menu: themes, headers, footers, chatbox, animations, auto-compact, model heal, render cache, payload limit, providers, usage, budget",
727
1005
  getArgumentCompletions: arnativeCompletions,
728
1006
  handler: arnativeHandler,
729
1007
  });
@@ -747,7 +1025,9 @@ export function recordProfile(): void {
747
1025
  [CHATBOX_DIALOG_KEY]: activeChatboxDialog(),
748
1026
  [SPINNER_PRESET_KEY]: activeSpinnerPreset(),
749
1027
  [SPINNER_GRADIENT_KEY]: activeSpinnerGradient() ? "on" : "off",
1028
+ [EDIT_DIFF_KEY]: activeEditDiff(),
750
1029
  [AUTO_COMPACT_KEY]: activeAutoCompact(),
1030
+ [PAYLOAD_LIMIT_KEY]: savedPayloadLimit(),
751
1031
  [MODEL_HEAL_KEY]: activeModelHeal(),
752
1032
  [RENDER_CACHE_KEY]: activeRenderCache(),
753
1033
  [BUDGET_DAY_KEY]: activeBudgetDay() === undefined ? "" : String(activeBudgetDay()),
@@ -787,22 +1067,33 @@ if (isMain(import.meta.url)) {
787
1067
  assert(rowText(labels[0]!) === "Themes · arnative themes only (all themes: /settings → Theme)", "menu row text format");
788
1068
  assert(labels[0]!.label === "Themes" && labels[0]!.note === "arnative themes only (all themes: /settings → Theme)", "menu row keeps label and note apart");
789
1069
  assert(MENU_TITLE === "Settings - Arnative\u2819", `the menu title is the pinned string, got ${MENU_TITLE}`);
790
- assert(MENU_DESC === "Themes, headers, footers, chatbox, animations, auto-compact, render, providers, usage, budget", `the menu description is the pinned string, got ${MENU_DESC}`);
1070
+ 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}`);
791
1071
  // Every menu row is reachable and the description names them all, so a new screen cannot
792
1072
  // be added to MENUS and forgotten in the copy a user reads first.
793
- assert(MENUS.length === 11, "eleven settings screens");
1073
+ assert(MENUS.length === 13, "thirteen settings screens");
794
1074
  {
795
- const values = MENUS.map((m) => m.value);
796
- assert(values.indexOf("heal") === values.indexOf("compact") + 1, "Model heal row sits right after Auto-compact");
797
- assert(values.indexOf("render") === values.indexOf("heal") + 1, "Render cache row sits right after Model heal");
1075
+ const catRows = menuRows([...MENU_CATEGORIES]);
1076
+ assert(catRows.map((r) => r.label).join(",") === "Appearance,Performance,Models,Spend", "root menu lists the four categories in order");
1077
+ const totalGrouped = MENU_CATEGORIES.reduce((n, c) => n + categoryMenus(c.label).length, 0);
1078
+ assert(totalGrouped === MENUS.length, "every menu item belongs to one of the four categories");
1079
+ const perf = categoryMenus("Performance");
1080
+ assert(perf.map((m) => m.value).join(",") === "compact,render,payload", "Performance group lists Auto-compact, Render cache, Payload limit in order");
798
1081
  const heal = modelHealRows("Flags");
799
1082
  assert(heal.map((r) => r.label).join(",") === "Full,Flags,Off,Run now", "Model heal rows: three modes then Run now");
800
1083
  assert(heal.filter((r) => r.chosen).map((r) => r.label).join(",") === "Flags", "Model heal marks only the saved mode");
801
1084
  const rc = renderCacheRows("On");
802
1085
  assert(rc.map((r) => r.label).join(",") === "On,Off", "Render cache rows: On then Off");
803
1086
  assert(rc.filter((r) => r.chosen).map((r) => r.label).join(",") === "On", "Render cache marks only the saved mode");
1087
+ const dRows = diffRows();
1088
+ assert(dRows.map((r) => r.label).join(",") === "Split,Unified", "Diffs rows: Split then Unified");
1089
+ const pl = payloadLimitRows("16 MB");
1090
+ 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");
1091
+ assert(pl.filter((r) => r.chosen).map((r) => r.label).join(",") === "16 MB", "Payload limit marks the active preset");
1092
+ const plCustom = payloadLimitRows("11 MB");
1093
+ assert(plCustom.filter((r) => r.chosen).map((r) => r.label).join(",") === "Custom", "Payload limit marks Custom when a non-preset MB is active");
1094
+ assert(plCustom[plCustom.length - 1]!.note!.includes("11 MB"), "Custom row displays the active custom MB");
804
1095
  }
805
- for (const label of ["Themes", "Headers", "Footers", "Chatbox", "Animations", "Auto-compact", "Render cache", "Providers", "Usage", "Budget"]) {
1096
+ for (const label of ["Themes", "Headers", "Footers", "Chatbox", "Animations", "Diffs", "Auto-compact", "Render cache", "Payload limit", "Providers", "Usage", "Budget"]) {
806
1097
  assert(MENUS.some((m) => m.label === label), `MENUS carries the ${label} screen`);
807
1098
  }
808
1099
  assert(/^Settings - Arnative/.test(MENU_TITLE), "title follows `<setting> - <extension>`");
@@ -828,6 +1119,8 @@ if (isMain(import.meta.url)) {
828
1119
  assert(autoCompactRows("Off")[0]!.chosen === true, "the marker moves when the saved choice changes");
829
1120
  assert(arnativeCompletions("re")![0]!.value === "render", "render cache menu has completions");
830
1121
  assert(MENUS.some((m) => m.value === "render"), "render cache menu registered");
1122
+ assert(arnativeCompletions("pa")![0]!.value === "payload", "payload limit menu has completions");
1123
+ assert(MENUS.some((m) => m.value === "payload"), "payload limit menu registered");
831
1124
  assert(arnativeCompletions("pr")![0]!.value === "providers", "providers menu has completions");
832
1125
  assert(MENUS.some((m) => m.value === "providers"), "providers menu registered");
833
1126
  // Every slash command, and the one alias: `/providers` must land on the providers screen.
@@ -838,7 +1131,7 @@ if (isMain(import.meta.url)) {
838
1131
  assert(typeof registered.get("providers")!.handler === "function", "/providers has a handler");
839
1132
  assert(MENUS.some((m) => m.value === "providers"), "/providers routes to a menu row that exists");
840
1133
  assert(
841
- registered.get("arnative")!.description === "Arnative settings menu: themes, headers, footers, chatbox, animations, auto-compact, model heal, render cache, providers, usage, budget",
1134
+ registered.get("arnative")!.description === "Arnative settings menu: themes, headers, footers, chatbox, animations, auto-compact, model heal, render cache, payload limit, providers, usage, budget",
842
1135
  "the /arnative command description names every screen: " + registered.get("arnative")!.description,
843
1136
  );
844
1137
  }
@@ -886,11 +1179,11 @@ if (isMain(import.meta.url)) {
886
1179
  assert(lines[0]!.startsWith("╭") && lines[lines.length - 1]!.startsWith("╰"), "picker framed");
887
1180
  assert(lines.every((l) => visibleWidth(l) === 50), "picker lines fit width 50");
888
1181
  assert(lines.some((l) => l.includes(screenTitle("Themes"))), "picker renders the configured title");
889
- assert(lines.some((l) => l.includes("→ arnative")), "the cursor marks the live value");
890
- assert(!lines.some((l) => l.includes("●")), "no redundant ● column next to the → cursor");
1182
+ assert(lines.some((l) => l.includes("❯ arnative")), "the cursor marks the live value");
1183
+ assert(!lines.some((l) => l.includes("●")), "no redundant ● column next to the ❯ cursor");
891
1184
  picker.handleInput("\x1b[B"); // down
892
1185
  assert(previews.length === 1 && previews[0] === "arnative-cyberpunk", "move previews immediately");
893
- assert(picker.render(50).some((l) => l.includes("→ arnative-cyberpunk")), "the cursor follows the preview");
1186
+ assert(picker.render(50).some((l) => l.includes("❯ arnative-cyberpunk")), "the cursor follows the preview");
894
1187
  picker.handleInput("\r"); // enter
895
1188
  assert(done === 1 && reverted === 0, "Enter keeps (no revert)");
896
1189
  picker.handleInput("\x1b[B");
@@ -931,54 +1224,55 @@ if (isMain(import.meta.url)) {
931
1224
  // setting, only Enter opens a row. `reverted` proves it.
932
1225
  let menuReverts = 0;
933
1226
  let menuCancelled = false;
934
- const mainPicker = new ListPicker(fakeTheme, labels, undefined, {
1227
+ const categoryRows = menuRows([...MENU_CATEGORIES]);
1228
+ const mainPicker = new ListPicker(fakeTheme, categoryRows, undefined, {
935
1229
  preview: () => {},
936
1230
  revert: () => { menuReverts++; },
937
1231
  done: () => {},
938
1232
  cancel: () => { menuCancelled = true; },
939
1233
  requestRender: () => {},
940
1234
  }, { title: MENU_TITLE, description: MENU_DESC, legend: LIST_LEGEND_ROOT }, false);
941
- // 100 columns: the description names the screens (a tripwire — a screen added to MENUS must
942
- // be added to the copy too), and that one-liner no longer fits 80.
943
- const menuLines = mainPicker.render(100);
1235
+ // 120 columns: the description names the screens (a tripwire — a screen added to MENUS must
1236
+ // be added to the copy too), and that one-liner no longer fits 100.
1237
+ const menuLines = mainPicker.render(120);
944
1238
  assert(menuLines.some((l) => l.includes(MENU_TITLE)), "the main menu renders its title");
945
1239
  assert(menuLines.some((l) => l.includes("[Esc] Close") && !l.includes("←")), "the root menu legend renders without a back key");
946
1240
  assert(menuLines.some((l) => l.includes(MENU_DESC)), "the main menu renders the description under the title");
947
1241
  assert(menuLines.findIndex((l) => l.includes(MENU_TITLE)) < menuLines.findIndex((l) => l.includes(MENU_DESC)), "description sits below the title");
948
- assert(menuLines.every((l) => visibleWidth(l) === 100), "main menu lines fit the width");
949
- // The pinned /arnative layout: `→ Themes · note`, every `·` in one column (skill rule 10).
1242
+ assert(menuLines.every((l) => visibleWidth(l) === 120), "main menu lines fit the width");
1243
+ // The pinned /arnative layout: `❯ Appearance · themes, headers…`, every `·` in one column.
950
1244
  const plainMenu = menuLines.map(stripAnsi);
951
- const row0 = menuLines.map(stripAnsi).find((l) => l.includes("→ Themes"))!;
952
- // The row is `│ → <label padded to the widest label><divider><note>`: assert the shape,
1245
+ const row0 = menuLines.map(stripAnsi).find((l) => l.includes("❯ Appearance"))!;
1246
+ // The row is `│ ❯ <label padded to the widest label><divider><note>`: assert the shape,
953
1247
  // not a literal run of spaces, so adding a wider screen cannot break the layout test.
954
- const widest = Math.max(...MENUS.map((m) => m.label.length));
1248
+ const widest = Math.max(...MENU_CATEGORIES.map((c) => c.label.length));
955
1249
  assert(
956
- row0.startsWith(`│ → ${"Themes".padEnd(widest)}${ROW_DIVIDER}arnative themes only`),
1250
+ row0.startsWith(`│ ❯ ${"Appearance".padEnd(widest)}${ROW_DIVIDER}themes, headers, footers`),
957
1251
  `menu row layout, got ${JSON.stringify(row0)}`,
958
1252
  );
959
1253
  assert(plainMenu.filter((l) => l.includes(ROW_DIVIDER)).every((l) => l.indexOf(ROW_DIVIDER) === row0.indexOf(ROW_DIVIDER)), "every divider sits in one column");
960
1254
  assert(
961
- plainMenu.some((l) => l.startsWith(`│ ${"Headers".padEnd(widest)}${ROW_DIVIDER}`)),
1255
+ plainMenu.some((l) => l.startsWith(`│ ${"Performance".padEnd(widest)}${ROW_DIVIDER}`)),
962
1256
  "unselected rows indent to the marker column",
963
1257
  );
964
1258
 
965
1259
  // A menu opened with a `current` row starts there. The handler passes the row it last
966
1260
  // used, so a submenu reopened by `←` lands back on that row instead of jumping to the
967
1261
  // top of the list — the cursor is the user's place, not the component's business.
968
- const resumed = new ListPicker(fakeTheme, labels, "Usage", {
1262
+ const resumed = new ListPicker(fakeTheme, categoryRows, "Models", {
969
1263
  preview: () => {},
970
1264
  revert: () => {},
971
1265
  done: () => {},
972
1266
  requestRender: () => {},
973
1267
  }, { title: MENU_TITLE, description: MENU_DESC, legend: LIST_LEGEND_ROOT }, false);
974
1268
  const resumedRows = resumed.render(60).map(stripAnsi);
975
- assert(resumedRows.some((l) => l.startsWith("│ → Usage")), "the menu reopens on the row it was left on");
976
- assert(!resumedRows.some((l) => l.startsWith("│ → Themes")), "and not on the first row");
1269
+ assert(resumedRows.some((l) => l.startsWith("│ ❯ Models")), "the menu reopens on the row it was left on");
1270
+ assert(!resumedRows.some((l) => l.startsWith("│ ❯ Appearance")), "and not on the first row");
977
1271
 
978
1272
  // The box border follows the session's thinking level (theme `thinking*` slot), so the
979
1273
  // menu reads as belonging to the active model.
980
1274
  const tagged = { fg: (c: string, t: string) => `<${c}>${t}</>`, bold: (t: string) => `<bold>${t}</bold>` };
981
- const thinkingPicker = new ListPicker(tagged, labels, undefined, {
1275
+ const thinkingPicker = new ListPicker(tagged, categoryRows, undefined, {
982
1276
  preview: () => {},
983
1277
  revert: () => {},
984
1278
  done: () => {},
@@ -997,13 +1291,13 @@ if (isMain(import.meta.url)) {
997
1291
  "no frame glyph is left on accentSoft",
998
1292
  );
999
1293
  // The chosen row's label takes the `accentSoft` token (bold), never a hand-written colour; the
1000
- // `→` marker stays on `accent` so the cursor is still findable when the theme has no accentSoft.
1294
+ // `❯` marker stays on `accent` so the cursor is still findable when the theme has no accentSoft.
1001
1295
  assert(
1002
- taggedLines.some((l) => l.includes("<accent>→ </><accentSoft><bold>")),
1296
+ taggedLines.some((l) => l.includes("<accent>❯ </><accentSoft><bold>")),
1003
1297
  "the chosen label is the accentSoft token in bold",
1004
1298
  );
1005
- assert(taggedLines.some((l) => l.includes("<accent>→ ")), "the → marker keeps the accent voice");
1006
- const offPicker = new ListPicker(tagged, labels, undefined, {
1299
+ assert(taggedLines.some((l) => l.includes("<accent>❯ ")), "the ❯ marker keeps the accent voice");
1300
+ const offPicker = new ListPicker(tagged, categoryRows, undefined, {
1007
1301
  preview: () => {},
1008
1302
  revert: () => {},
1009
1303
  done: () => {},
@@ -1025,7 +1319,7 @@ if (isMain(import.meta.url)) {
1025
1319
  const headerPicker = new ListPicker(fakeTheme, nameRows(HEADER_PRESETS), "Arnative (Full)", { preview: () => {}, revert: () => {}, done: () => {}, requestRender: () => {} }, HEADERS_PICKER_TEXT);
1026
1320
  const headerLines = headerPicker.render(50);
1027
1321
  assert(headerLines.some((l) => l.includes(screenTitle("Headers"))), "headers picker title");
1028
- assert(headerLines.some((l) => l.includes("→ Arnative (Full)")), "headers picker cursors the active preset");
1322
+ assert(headerLines.some((l) => l.includes("❯ Arnative (Full)")), "headers picker cursors the active preset");
1029
1323
  assert(headerLines.some((l) => l.includes(" Pi (system)")), "headers picker lists the built-in preset");
1030
1324
 
1031
1325
  // Footers reuses the same picker too.
@@ -1033,7 +1327,7 @@ if (isMain(import.meta.url)) {
1033
1327
  const footerPicker = new ListPicker(fakeTheme, nameRows(FOOTER_PRESETS), "Pi (system)", { preview: () => {}, revert: () => {}, done: () => {}, requestRender: () => {} }, footersPickerText());
1034
1328
  const footerLines = footerPicker.render(50);
1035
1329
  assert(footerLines.some((l) => l.includes(screenTitle("Footers"))), "footers picker title");
1036
- assert(footerLines.some((l) => l.includes("→ Pi (system)")), "footers picker cursors the active preset");
1330
+ assert(footerLines.some((l) => l.includes("❯ Pi (system)")), "footers picker cursors the active preset");
1037
1331
  assert(footerLines.some((l) => l.includes("Arnative (Minimal)")), "footers picker lists the minimal preset");
1038
1332
  assert(footerLines.filter((l) => l.includes("Arnative (")).length === 2, "both arnative footer presets are selectable");
1039
1333
  assert(/\[c\] Cost (on|off)/.test(footersPickerText().legend), "footers legend advertises the cost switch and its live state");
@@ -1051,7 +1345,7 @@ if (isMain(import.meta.url)) {
1051
1345
  const chatboxLines = chatboxPicker.render(84);
1052
1346
  assert(chatboxLines.some((l) => l.includes(screenTitle("Chatbox"))), "chatbox picker title");
1053
1347
  assert(chatboxLines.some((l) => l.includes("Box · Arnative")), "chatbox picker shows Box summary");
1054
- assert(chatboxLines.some((l) => l.includes("→ Arnative")), "chatbox picker cursors the active preset");
1348
+ assert(chatboxLines.some((l) => l.includes("❯ Arnative")), "chatbox picker cursors the active preset");
1055
1349
  assert(chatboxLines.some((l) => l.includes(" Pi (system)")), "chatbox picker lists the built-in preset");
1056
1350
  assert(CHATBOX_PICKER_TEXT.legend.includes("[i] Icon [D] Dialog"), "chatbox legend advertises [i] Icon and [D] Dialog");
1057
1351
 
@@ -1110,14 +1404,14 @@ if (isMain(import.meta.url)) {
1110
1404
  marked: (label) => chosen.has(label),
1111
1405
  }, { title: screenTitle("Providers"), description: "pick models", legend: "[Space] Toggle" }, false);
1112
1406
  const multiLines = multiPicker.render(50).map(stripAnsi);
1113
- assert(multiLines.some((l) => l.includes("→ [x] a")), "a checked row shows [x] behind the cursor");
1407
+ assert(multiLines.some((l) => l.includes("❯ [x] a")), "a checked row shows [x] behind the cursor");
1114
1408
  assert(multiLines.some((l) => l.includes("[ ] b")), "unchecked rows show [ ]");
1115
1409
  multiPicker.handleInput(" ");
1116
1410
  assert(picked[0] === "a" && !chosen.has("a"), "Space toggles the row under the cursor");
1117
1411
  multiPicker.handleInput("\x1b[B");
1118
1412
  multiPicker.handleInput(" ");
1119
1413
  assert(chosen.has("b"), "Space toggles the row the cursor moved to");
1120
- assert(multiPicker.render(50).map(stripAnsi).some((l) => l.includes("→ [x] b")), "the check follows the cursor");
1414
+ assert(multiPicker.render(50).map(stripAnsi).some((l) => l.includes("❯ [x] b")), "the check follows the cursor");
1121
1415
  mainPicker.handleInput(" ");
1122
1416
  assert(chosen.has("b") && picked.length === 2, "a screen without the toggle hook ignores Space");
1123
1417