@bismawy/pi-arnative 0.18.3 → 0.19.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.
- package/extensions/index.ts +2 -0
- package/lib/ask-user.ts +596 -0
- package/lib/features/arnative.ts +246 -4
- package/lib/features/ask-user.ts +1036 -0
- package/lib/preset-store.ts +7 -1
- package/package.json +3 -2
package/lib/features/arnative.ts
CHANGED
|
@@ -25,7 +25,19 @@ import {
|
|
|
25
25
|
setSpinnerPreset,
|
|
26
26
|
type SpinnerPreset,
|
|
27
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
|
+
import { ASK_MODE_KEY, ASK_MODEL_KEY, ASK_THINKING_KEY, 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";
|
|
29
|
+
import {
|
|
30
|
+
ASK_MODE_CHOICES,
|
|
31
|
+
ASK_THINKING_CHOICES,
|
|
32
|
+
activeAskMode,
|
|
33
|
+
activeAskModel,
|
|
34
|
+
activeAskThinking,
|
|
35
|
+
setAskMode,
|
|
36
|
+
setAskModel,
|
|
37
|
+
setAskThinking,
|
|
38
|
+
type AskMode,
|
|
39
|
+
type AskThinking,
|
|
40
|
+
} from "../ask-user.ts";
|
|
29
41
|
import { EDIT_DIFF_CHOICES, activeEditDiff, setEditDiff, type EditDiffMode } from "./tools.ts";
|
|
30
42
|
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";
|
|
31
43
|
import { activeBudgetDay, activeBudgetEnforce, activeBudgetMonth, openBudget } from "./budget.ts";
|
|
@@ -74,7 +86,7 @@ export interface MenuCategory {
|
|
|
74
86
|
export const MENU_CATEGORIES: readonly MenuCategory[] = [
|
|
75
87
|
{ label: "Appearance", description: "themes, headers, footers, chatbox" },
|
|
76
88
|
{ label: "Display", description: "animations, diffs, tool layout, render cache" },
|
|
77
|
-
{ label: "Models & Context", description: "custom providers, model heal, auto-compact, payload limit" },
|
|
89
|
+
{ label: "Models & Context", description: "custom providers, ask model, model heal, auto-compact, payload limit" },
|
|
78
90
|
{ label: "Spend", description: "usage dashboard, budget caps" },
|
|
79
91
|
];
|
|
80
92
|
|
|
@@ -100,7 +112,7 @@ export function categoryMenus(group: MenuGroup, menus: readonly ArnativeMenu[] =
|
|
|
100
112
|
/** Title of the settings menu, derived from `screenTitle` so the format lives in one place. */
|
|
101
113
|
export const MENU_TITLE = screenTitle("Settings");
|
|
102
114
|
/** One-line description under the menu title. */
|
|
103
|
-
export const MENU_DESC = "Themes, headers, footers, chatbox, animations, auto-compact, render, payload, providers, usage, budget";
|
|
115
|
+
export const MENU_DESC = "Themes, headers, footers, chatbox, animations, ask, auto-compact, render, payload, providers, usage, budget";
|
|
104
116
|
|
|
105
117
|
const THEMES_PICKER_TEXT: ListPickerText = {
|
|
106
118
|
title: screenTitle("Themes"),
|
|
@@ -698,6 +710,226 @@ const openPayloadLimit = async (ctx: ExtensionCommandContext): Promise<boolean |
|
|
|
698
710
|
}
|
|
699
711
|
};
|
|
700
712
|
|
|
713
|
+
const ASK_ACTIVE_MODEL_LABEL = "Active model (default)";
|
|
714
|
+
|
|
715
|
+
const ASK_MODE_NOTES: Record<AskMode, string> = {
|
|
716
|
+
Hybrid: "refine drafted questions AND author from goal/ambiguities (recommended)",
|
|
717
|
+
Refine: "audit & upgrade drafted questions from the active model only",
|
|
718
|
+
Off: "never delegate — always show the active model's questions directly",
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
const ASK_THINKING_NOTES: Record<AskThinking, string> = {
|
|
722
|
+
off: "fastest — no reasoning tokens",
|
|
723
|
+
low: "quick quality pass (default)",
|
|
724
|
+
medium: "deeper trade-off analysis for complex specs",
|
|
725
|
+
high: "thorough architecture-grade question synthesis",
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
export function askSettingsRows(model: string, mode: AskMode, thinking: AskThinking): ListRow[] {
|
|
729
|
+
return [
|
|
730
|
+
{ label: "Question model", note: model || ASK_ACTIVE_MODEL_LABEL },
|
|
731
|
+
{ label: "Mode", note: `${mode} — ${ASK_MODE_NOTES[mode]}` },
|
|
732
|
+
{ label: "Thinking", note: `${thinking} — ${ASK_THINKING_NOTES[thinking]}` },
|
|
733
|
+
];
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
export function askModeRows(opened: AskMode): ListRow[] {
|
|
737
|
+
return ASK_MODE_CHOICES.map((c) => ({ label: c, note: ASK_MODE_NOTES[c], chosen: c === opened }));
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
export function askThinkingRows(opened: AskThinking): ListRow[] {
|
|
741
|
+
return ASK_THINKING_CHOICES.map((c) => ({ label: c, note: ASK_THINKING_NOTES[c], chosen: c === opened }));
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
function availableAskModels(ctx: ExtensionCommandContext): { spec: string; scoped: boolean }[] {
|
|
745
|
+
const scoped = (ctx as { scopedModels?: readonly { model: { provider: string; id: string } }[] }).scopedModels ?? [];
|
|
746
|
+
const available = ctx.modelRegistry?.getAvailable?.() ?? [];
|
|
747
|
+
const seen = new Set<string>();
|
|
748
|
+
const out: { spec: string; scoped: boolean }[] = [];
|
|
749
|
+
for (const entry of scoped) {
|
|
750
|
+
const m = entry?.model;
|
|
751
|
+
if (!m?.provider || !m?.id) continue;
|
|
752
|
+
const spec = `${m.provider}/${m.id}`;
|
|
753
|
+
if (seen.has(spec)) continue;
|
|
754
|
+
seen.add(spec);
|
|
755
|
+
out.push({ spec, scoped: true });
|
|
756
|
+
}
|
|
757
|
+
for (const m of available) {
|
|
758
|
+
if (!m?.provider || !m?.id) continue;
|
|
759
|
+
const spec = `${m.provider}/${m.id}`;
|
|
760
|
+
if (seen.has(spec)) continue;
|
|
761
|
+
seen.add(spec);
|
|
762
|
+
out.push({ spec, scoped: false });
|
|
763
|
+
}
|
|
764
|
+
return out;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
const openAskModelPicker = async (ctx: ExtensionCommandContext): Promise<void> => {
|
|
768
|
+
const current = activeAskModel();
|
|
769
|
+
const entries = availableAskModels(ctx);
|
|
770
|
+
const specs = entries.map((e) => e.spec);
|
|
771
|
+
const rows: ListRow[] = [
|
|
772
|
+
{
|
|
773
|
+
label: ASK_ACTIVE_MODEL_LABEL,
|
|
774
|
+
note: "use the session's active model (no delegation)",
|
|
775
|
+
chosen: current === "",
|
|
776
|
+
},
|
|
777
|
+
...entries.map((entry) => ({
|
|
778
|
+
label: entry.spec,
|
|
779
|
+
...(entry.scoped ? { note: "scoped" } : {}),
|
|
780
|
+
chosen: entry.spec === current,
|
|
781
|
+
})),
|
|
782
|
+
];
|
|
783
|
+
if (current && !specs.includes(current)) {
|
|
784
|
+
rows.splice(1, 0, { label: current, note: "configured (not currently available)", chosen: true });
|
|
785
|
+
}
|
|
786
|
+
const cursor = current || ASK_ACTIVE_MODEL_LABEL;
|
|
787
|
+
const pickerText: ListPickerText = {
|
|
788
|
+
title: screenTitle("Ask Model"),
|
|
789
|
+
description: "Model used to refine or author ask_user_question dialogs (press / to filter).",
|
|
790
|
+
legend: "[/] Filter [↑↓] Move [Enter] Select [Esc] Back",
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
if (ctx.mode !== "tui") {
|
|
794
|
+
const labels = rows.map((r) => (r.chosen ? `${r.label} ✓` : r.label));
|
|
795
|
+
const pick = await ctx.ui.select(pickerText.title, labels);
|
|
796
|
+
if (pick === undefined) return;
|
|
797
|
+
const idx = labels.indexOf(pick);
|
|
798
|
+
const chosen = idx === 0 ? "" : rows[idx]?.label ?? "";
|
|
799
|
+
setAskModel(chosen);
|
|
800
|
+
ctx.ui.notify(`[arnative] Ask model: ${chosen || ASK_ACTIVE_MODEL_LABEL}`, "info");
|
|
801
|
+
return;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
const picked = await ctx.ui.custom<number | null>((tui, theme, _kb, done) => {
|
|
805
|
+
const picker = new ListPicker(
|
|
806
|
+
theme,
|
|
807
|
+
rows,
|
|
808
|
+
cursor,
|
|
809
|
+
{
|
|
810
|
+
preview: () => {},
|
|
811
|
+
revert: () => {},
|
|
812
|
+
done: () => done(picker.index),
|
|
813
|
+
cancel: () => done(null),
|
|
814
|
+
back: () => done(null),
|
|
815
|
+
requestRender: () => tui.requestRender(),
|
|
816
|
+
search: "models",
|
|
817
|
+
},
|
|
818
|
+
pickerText,
|
|
819
|
+
false,
|
|
820
|
+
ctx.thinkingLevel,
|
|
821
|
+
10,
|
|
822
|
+
);
|
|
823
|
+
return picker;
|
|
824
|
+
});
|
|
825
|
+
if (picked === null || picked === undefined || picked < 0) return;
|
|
826
|
+
const chosen = picked === 0 ? "" : rows[picked]?.label ?? "";
|
|
827
|
+
setAskModel(chosen);
|
|
828
|
+
announce(ctx.ui, `Ask model: ${chosen || ASK_ACTIVE_MODEL_LABEL}.`);
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
const openAsk = async (ctx: ExtensionCommandContext): Promise<boolean | void> => {
|
|
832
|
+
let cursor: string | undefined;
|
|
833
|
+
for (;;) {
|
|
834
|
+
const model = activeAskModel();
|
|
835
|
+
const mode = activeAskMode();
|
|
836
|
+
const thinking = activeAskThinking();
|
|
837
|
+
const rows = askSettingsRows(model, mode, thinking);
|
|
838
|
+
const text: ListPickerText = {
|
|
839
|
+
title: screenTitle("Ask"),
|
|
840
|
+
description: "Delegate ask_user_question refinement/authoring to a flagship model.",
|
|
841
|
+
legend: LIST_LEGEND_MOVE,
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
if (ctx.mode !== "tui") {
|
|
845
|
+
const labels = rows.map(rowText);
|
|
846
|
+
const pick = await ctx.ui.select(text.title, labels);
|
|
847
|
+
if (pick === undefined) return;
|
|
848
|
+
const idx = labels.indexOf(pick);
|
|
849
|
+
if (idx === 0) await openAskModelPicker(ctx);
|
|
850
|
+
else if (idx === 1) {
|
|
851
|
+
const mPick = await ctx.ui.select(screenTitle("Ask Mode"), ASK_MODE_CHOICES.map((c) => (c === mode ? `${c} ✓` : c)));
|
|
852
|
+
if (mPick) {
|
|
853
|
+
const val = ASK_MODE_CHOICES[ASK_MODE_CHOICES.findIndex((c) => mPick.startsWith(c))];
|
|
854
|
+
if (val) {
|
|
855
|
+
setAskMode(val);
|
|
856
|
+
ctx.ui.notify(`[arnative] Ask mode: ${val}`, "info");
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
} else if (idx === 2) {
|
|
860
|
+
const tPick = await ctx.ui.select(screenTitle("Ask Thinking"), ASK_THINKING_CHOICES.map((c) => (c === thinking ? `${c} ✓` : c)));
|
|
861
|
+
if (tPick) {
|
|
862
|
+
const val = ASK_THINKING_CHOICES[ASK_THINKING_CHOICES.findIndex((c) => tPick.startsWith(c))];
|
|
863
|
+
if (val) {
|
|
864
|
+
setAskThinking(val);
|
|
865
|
+
ctx.ui.notify(`[arnative] Ask thinking: ${val}`, "info");
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
const choice = await ctx.ui.custom<{ index?: number; back?: boolean }>((tui, theme, _kb, done) => {
|
|
873
|
+
const picker = new ListPicker(
|
|
874
|
+
theme,
|
|
875
|
+
rows,
|
|
876
|
+
cursor,
|
|
877
|
+
{
|
|
878
|
+
preview: () => {},
|
|
879
|
+
revert: () => {},
|
|
880
|
+
done: () => done({ index: picker.index }),
|
|
881
|
+
cancel: () => done({ back: false }),
|
|
882
|
+
back: () => done({ back: true }),
|
|
883
|
+
requestRender: () => tui.requestRender(),
|
|
884
|
+
},
|
|
885
|
+
text,
|
|
886
|
+
false,
|
|
887
|
+
ctx.thinkingLevel,
|
|
888
|
+
);
|
|
889
|
+
return picker;
|
|
890
|
+
});
|
|
891
|
+
if (choice.index === undefined) return choice.back === true;
|
|
892
|
+
cursor = rows[choice.index]?.label;
|
|
893
|
+
if (choice.index === 0) {
|
|
894
|
+
await openAskModelPicker(ctx);
|
|
895
|
+
} else if (choice.index === 1) {
|
|
896
|
+
await openChoicePicker(ctx, {
|
|
897
|
+
choices: ASK_MODE_CHOICES,
|
|
898
|
+
rows: askModeRows(mode),
|
|
899
|
+
opened: mode,
|
|
900
|
+
text: {
|
|
901
|
+
title: screenTitle("Ask Mode"),
|
|
902
|
+
description: "How the custom question model participates in ask_user_question.",
|
|
903
|
+
legend: LIST_LEGEND_MOVE,
|
|
904
|
+
},
|
|
905
|
+
onCommit: (idx, isTui) => {
|
|
906
|
+
const val = ASK_MODE_CHOICES[idx]!;
|
|
907
|
+
setAskMode(val);
|
|
908
|
+
if (isTui) announce(ctx.ui, `Ask mode: ${val}.`);
|
|
909
|
+
else ctx.ui.notify(`[arnative] Ask mode: ${val}`, "info");
|
|
910
|
+
},
|
|
911
|
+
});
|
|
912
|
+
} else if (choice.index === 2) {
|
|
913
|
+
await openChoicePicker(ctx, {
|
|
914
|
+
choices: ASK_THINKING_CHOICES,
|
|
915
|
+
rows: askThinkingRows(thinking),
|
|
916
|
+
opened: thinking,
|
|
917
|
+
text: {
|
|
918
|
+
title: screenTitle("Ask Thinking"),
|
|
919
|
+
description: "Reasoning level passed to the delegated question model.",
|
|
920
|
+
legend: LIST_LEGEND_MOVE,
|
|
921
|
+
},
|
|
922
|
+
onCommit: (idx, isTui) => {
|
|
923
|
+
const val = ASK_THINKING_CHOICES[idx]!;
|
|
924
|
+
setAskThinking(val);
|
|
925
|
+
if (isTui) announce(ctx.ui, `Ask thinking: ${val}.`);
|
|
926
|
+
else ctx.ui.notify(`[arnative] Ask thinking: ${val}`, "info");
|
|
927
|
+
},
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
|
|
701
933
|
export const MENUS: ArnativeMenu[] = [
|
|
702
934
|
{
|
|
703
935
|
value: "themes",
|
|
@@ -762,6 +994,13 @@ export const MENUS: ArnativeMenu[] = [
|
|
|
762
994
|
group: "Models & Context",
|
|
763
995
|
open: openProviders,
|
|
764
996
|
},
|
|
997
|
+
{
|
|
998
|
+
value: "ask",
|
|
999
|
+
label: "Ask",
|
|
1000
|
+
description: "custom flagship model, mode & thinking level for ask_user_question",
|
|
1001
|
+
group: "Models & Context",
|
|
1002
|
+
open: openAsk,
|
|
1003
|
+
},
|
|
765
1004
|
{
|
|
766
1005
|
value: "heal",
|
|
767
1006
|
label: "Model heal",
|
|
@@ -921,7 +1160,7 @@ export function shouldApplyDefaultTheme(
|
|
|
921
1160
|
* set without starting a session. */
|
|
922
1161
|
export function registerCommands(pi: Pick<ExtensionAPI, "registerCommand">): void {
|
|
923
1162
|
pi.registerCommand("arnative", {
|
|
924
|
-
description: "Arnative settings menu: themes, headers, footers, chatbox, animations, auto-compact, model heal, render cache, payload limit, providers, usage, budget",
|
|
1163
|
+
description: "Arnative settings menu: themes, headers, footers, chatbox, animations, ask, auto-compact, model heal, render cache, payload limit, providers, usage, budget",
|
|
925
1164
|
getArgumentCompletions: arnativeCompletions,
|
|
926
1165
|
handler: arnativeHandler,
|
|
927
1166
|
});
|
|
@@ -947,6 +1186,9 @@ export function recordProfile(): void {
|
|
|
947
1186
|
[SPINNER_GRADIENT_KEY]: activeSpinnerGradient() ? "on" : "off",
|
|
948
1187
|
[EDIT_DIFF_KEY]: activeEditDiff(),
|
|
949
1188
|
[TOOL_LAYOUT_KEY]: activeToolLayout(),
|
|
1189
|
+
[ASK_MODEL_KEY]: activeAskModel(),
|
|
1190
|
+
[ASK_MODE_KEY]: activeAskMode(),
|
|
1191
|
+
[ASK_THINKING_KEY]: activeAskThinking(),
|
|
950
1192
|
[AUTO_COMPACT_KEY]: activeAutoCompact(),
|
|
951
1193
|
[PAYLOAD_LIMIT_KEY]: savedPayloadLimit(),
|
|
952
1194
|
[MODEL_HEAL_KEY]: activeModelHeal(),
|