@bismawy/pi-arnative 0.9.1 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/README.md +3 -3
- package/extensions/animations.ts +1 -1
- package/extensions/arnative.ts +23 -11
- package/extensions/autocompact.ts +0 -0
- package/extensions/footer.ts +0 -0
- package/extensions/model-heal.ts +93 -18
- package/extensions/section-headers.ts +0 -0
- package/extensions/timestamps.ts +0 -0
- package/extensions/todos.ts +43 -15
- package/extensions/tools.ts +128 -11
- package/extensions/ui-render-tweaks.ts +5 -5
- package/extensions/usage.ts +309 -19
- package/lib/ansi.ts +22 -12
- package/lib/box.ts +1 -1
- package/lib/check.ts +0 -0
- package/lib/compat.ts +13 -64
- package/lib/format.ts +0 -0
- package/lib/list-picker.ts +117 -22
- package/lib/model-heal.ts +78 -13
- package/lib/patch.ts +0 -0
- package/lib/preset-store.ts +0 -0
- package/lib/provider.ts +153 -66
- package/lib/shortcuts.ts +36 -20
- package/lib/spinner.ts +0 -0
- package/lib/status-widget.ts +14 -0
- package/lib/todos.ts +0 -0
- package/lib/usage-store.ts +227 -24
- package/package.json +1 -1
- package/themes/arnative-blossom.json +89 -0
- package/themes/arnative-crimson.json +89 -0
- package/themes/arnative-cyberpunk.json +28 -28
- package/themes/arnative-dracula.json +40 -39
- package/themes/arnative-earthy.json +89 -0
- package/themes/arnative-garden.json +89 -0
- package/themes/arnative-gruvbox.json +40 -39
- package/themes/arnative-lemonade.json +89 -0
- package/themes/{arnative-synthwave.json → arnative-magical.json} +32 -31
- package/themes/arnative-matrix.json +37 -36
- package/themes/arnative-neutral.json +89 -0
- package/themes/arnative-nord.json +43 -42
- package/themes/arnative-zinc.json +43 -42
- package/themes/arnative.json +32 -31
- package/themes/gen-themes.mjs +376 -129
- package/themes/arnative-emerald.json +0 -88
- package/themes/arnative-sun.json +0 -88
- package/themes/arnative-violet.json +0 -88
package/lib/provider.ts
CHANGED
|
@@ -187,7 +187,6 @@ export type ThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhi
|
|
|
187
187
|
* level travels to the endpoint unchanged — for models that take an effort parameter. */
|
|
188
188
|
export type ThinkingSetting = ThinkingLevel | "auto";
|
|
189
189
|
export const THINKING_LEVELS: ThinkingLevel[] = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
190
|
-
export const THINKING_SETTINGS: ThinkingSetting[] = ["off", "auto", ...THINKING_LEVELS.slice(1)];
|
|
191
190
|
|
|
192
191
|
export interface ProviderModel {
|
|
193
192
|
id: string;
|
|
@@ -317,22 +316,34 @@ export function withoutAuth(auth: unknown, name: string): Record<string, unknown
|
|
|
317
316
|
|
|
318
317
|
/** Rewrites one provider's model list and nothing else — compat, headers, name, every
|
|
319
318
|
* sibling field survives an edit exactly as it was stored. Levels serialize to pi's
|
|
320
|
-
* wire shape: `reasoning` for anything thinking, plus a `thinkingLevelMap`
|
|
321
|
-
*
|
|
319
|
+
* wire shape: `reasoning` for anything thinking, plus a `thinkingLevelMap` whose pinned
|
|
320
|
+
* level is a ceiling: every effort up to it maps to itself, every level above it is null,
|
|
321
|
+
* and `off` stays unmapped. pi reads null as unsupported, so the old map that nulled every
|
|
322
|
+
* level but one left the user stuck on that level, unable to lower it or turn thinking off. */
|
|
322
323
|
export function levelToWire(level: ThinkingSetting | undefined): { reasoning?: true; thinkingLevelMap?: Record<string, string | null> } {
|
|
323
324
|
if (level === undefined || level === "off") return {};
|
|
324
325
|
if (level === "auto") return { reasoning: true };
|
|
326
|
+
const ceiling = THINKING_LEVELS.indexOf(level);
|
|
325
327
|
const thinkingLevelMap: Record<string, string | null> = {};
|
|
326
|
-
|
|
328
|
+
THINKING_LEVELS.forEach((l, i) => {
|
|
329
|
+
if (l !== "off") thinkingLevelMap[l] = i <= ceiling ? l : null;
|
|
330
|
+
});
|
|
327
331
|
return { reasoning: true, thinkingLevelMap };
|
|
328
332
|
}
|
|
329
333
|
|
|
330
|
-
/** Reads pi's wire shape back into a level:
|
|
331
|
-
*
|
|
334
|
+
/** Reads pi's wire shape back into a level: the highest level mapped to itself is that level
|
|
335
|
+
* when every level above it is null (a ceiling, or the old single-pin shape). Any other map
|
|
336
|
+
* (heal's default, a probed remap) and `reasoning: true` alone are `auto`. */
|
|
332
337
|
export function wireToLevel(reasoning: unknown, map: unknown): ThinkingSetting {
|
|
333
|
-
if (map
|
|
334
|
-
const
|
|
335
|
-
|
|
338
|
+
if (isObj(map)) {
|
|
339
|
+
const levels = THINKING_LEVELS.filter((l) => l !== "off");
|
|
340
|
+
const top = levels.findLastIndex((l) => map[l] === l);
|
|
341
|
+
if (top !== -1 && levels.slice(top + 1).every((l) => map[l] === null)) {
|
|
342
|
+
// A ceiling maps every level below it to itself; the old single pin nulls them all.
|
|
343
|
+
// Anything else (an exact probed map with gaps) is a map, not a pin.
|
|
344
|
+
const below = levels.slice(0, top);
|
|
345
|
+
if (below.every((l) => map[l] === l) || below.every((l) => map[l] === null)) return levels[top]!;
|
|
346
|
+
}
|
|
336
347
|
}
|
|
337
348
|
return reasoning === true ? "auto" : "off";
|
|
338
349
|
}
|
|
@@ -490,7 +501,9 @@ export function loadProviderEntry(config: unknown, name: string): ProviderEntry
|
|
|
490
501
|
const contextWindow = typeof m.contextWindow === "number" ? m.contextWindow : undefined;
|
|
491
502
|
const maxTokens = typeof m.maxTokens === "number" ? m.maxTokens : undefined;
|
|
492
503
|
const meta = contextWindow === undefined && maxTokens === undefined ? undefined : { contextWindow, maxTokens };
|
|
493
|
-
|
|
504
|
+
// An `auto` model keeps its stored map, so a later save never wipes what a probe learned.
|
|
505
|
+
const map = level === "auto" && isObj(m.thinkingLevelMap) ? (m.thinkingLevelMap as Record<string, string | null>) : undefined;
|
|
506
|
+
return [{ id: m.id, ...(level === "off" ? {} : { level }), ...(map ? { map } : {}), ...(meta ? { meta } : {}), ...(isObj(m.compat) ? { compat: m.compat } : {}) }];
|
|
494
507
|
})
|
|
495
508
|
: [];
|
|
496
509
|
return {
|
|
@@ -512,13 +525,13 @@ const PROVIDERS_TEXT: ScreenText = {
|
|
|
512
525
|
|
|
513
526
|
const ADD_ROW = "+ Add provider";
|
|
514
527
|
|
|
515
|
-
const MODEL_LEGEND = "[
|
|
516
|
-
const MODEL_LEGEND_LOCKED = "[
|
|
528
|
+
const MODEL_LEGEND = "[/] Filter [Space] Toggle [a] API [Enter] Save [Esc] Back";
|
|
529
|
+
const MODEL_LEGEND_LOCKED = "[/] Filter [Space] Toggle [Enter] Save [Esc] Back";
|
|
517
530
|
/** Rows visible before the model list scrolls (a relay catalog can exceed the screen). */
|
|
518
531
|
const MODEL_VIEWPORT = 10;
|
|
519
532
|
|
|
520
533
|
/** One model-selection screen: Space checks rows, `a` cycles the API flavor (unless the
|
|
521
|
-
* stored api is final), Enter saves. Esc leaves without writing anything. */
|
|
534
|
+
* stored api is final), `/` filters by name, Enter saves. Esc leaves without writing anything. */
|
|
522
535
|
const pickModels = async (
|
|
523
536
|
ctx: ExtensionCommandContext,
|
|
524
537
|
models: string[],
|
|
@@ -552,6 +565,9 @@ const pickModels = async (
|
|
|
552
565
|
flavor = API_FLAVORS[(API_FLAVORS.indexOf(flavor) + 1) % API_FLAVORS.length]!;
|
|
553
566
|
},
|
|
554
567
|
description: () => `${FLAVOR_LABELS[flavor]}${opts.via ? ` · ${opts.via}` : ""}`,
|
|
568
|
+
// A relay catalog is long (one had 75 ids), so the same filter line / keeps on the
|
|
569
|
+
// Thinking screen narrows it here too: the count stays whole, the rows do not.
|
|
570
|
+
search: "models",
|
|
555
571
|
// The picked count lives in the legend, accented, next to the keys it refers to.
|
|
556
572
|
legend: () =>
|
|
557
573
|
`${theme.fg("accent", `${checked.size}/${models.length} picked`)}${theme.fg("dim", ` · ${opts.lockFlavor ? MODEL_LEGEND_LOCKED : MODEL_LEGEND}`)}`,
|
|
@@ -643,7 +659,7 @@ const addProviderFlow = async (ctx: ExtensionCommandContext): Promise<void> => {
|
|
|
643
659
|
|
|
644
660
|
const key = await readInput(ctx, "Provider", "API key — empty for local or keyless endpoints", "sk-…");
|
|
645
661
|
// Esc cancels the flow, Enter on an empty field means keyless: readInput keeps the two
|
|
646
|
-
// apart (undefined vs ""), and the field's own legend promises [Esc]
|
|
662
|
+
// apart (undefined vs ""), and the field's own legend promises [Esc] Back.
|
|
647
663
|
if (key === undefined) return;
|
|
648
664
|
|
|
649
665
|
const suggested = guessProviderName(endpoint);
|
|
@@ -724,14 +740,41 @@ const levelsSummary = (models: ProviderModel[]): string => {
|
|
|
724
740
|
|
|
725
741
|
/** Writes one provider's model list through to models.json (auth.json is untouched — the
|
|
726
742
|
* key only changes through add or delete). */
|
|
727
|
-
|
|
743
|
+
type ModelRef = { provider: string; id: string };
|
|
744
|
+
type SetModel = (model: ModelRef) => Promise<unknown>;
|
|
745
|
+
type RegistryRef = { refresh(options?: { allowNetwork?: boolean }): Promise<unknown>; find(provider: string, id: string): ModelRef | undefined };
|
|
746
|
+
|
|
747
|
+
let setSessionModel: SetModel | undefined;
|
|
748
|
+
/** pi.setModel lives on the extension API, not on a command ctx; the extension binds it once. */
|
|
749
|
+
export const bindSetModel = (fn: SetModel): void => {
|
|
750
|
+
setSessionModel = fn;
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
/** Load models.json into the running session. A registry refresh alone is not enough: pi keeps
|
|
754
|
+
* the session model object (and its thinkingLevelMap) until the model is picked again, so
|
|
755
|
+
* /thinking kept offering the old levels even after /reload. */
|
|
756
|
+
export async function reloadCurrentModel(ctx: { modelRegistry?: RegistryRef; model?: ModelRef }, setModel: SetModel | undefined = setSessionModel, signal?: AbortSignal): Promise<boolean> {
|
|
757
|
+
signal?.throwIfAborted();
|
|
758
|
+
const registry = ctx.modelRegistry;
|
|
759
|
+
if (!registry) return false;
|
|
760
|
+
const current = ctx.model;
|
|
761
|
+
await registry.refresh({ allowNetwork: false });
|
|
762
|
+
signal?.throwIfAborted();
|
|
763
|
+
if (!current) return true;
|
|
764
|
+
const fresh = registry.find(current.provider, current.id);
|
|
765
|
+
if (!fresh || fresh === current) return true;
|
|
766
|
+
if (!setModel) return false;
|
|
767
|
+
await setModel(fresh);
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
770
|
+
const saveModelsNamed = async (ctx: ExtensionCommandContext, name: string, models: ProviderModel[]): Promise<void> => {
|
|
728
771
|
try {
|
|
729
772
|
writeJson(modelsPath(), withProviderModels(readJson(modelsPath()), name, models));
|
|
730
773
|
} catch (error) {
|
|
731
774
|
ctx.ui.notify(`[arnative] Not saved: ${error instanceof Error ? error.message : "config file unreadable"}.`, "error");
|
|
732
775
|
return;
|
|
733
776
|
}
|
|
734
|
-
ctx.ui.notify(`[arnative] ${name}: ${models.length} models, ${levelsSummary(models)} — models.json updated.
|
|
777
|
+
ctx.ui.notify(`[arnative] ${name}: ${models.length} models, ${levelsSummary(models)} — ${(await reloadCurrentModel(ctx as never).catch(() => false)) ? "models.json updated and loaded." : "models.json updated. Pick the model again in /model to load it."}`, "info");
|
|
735
778
|
};
|
|
736
779
|
|
|
737
780
|
const selectModelsFlow = async (ctx: ExtensionCommandContext, name: string, entry: ProviderEntry): Promise<void> => {
|
|
@@ -746,7 +789,7 @@ const selectModelsFlow = async (ctx: ExtensionCommandContext, name: string, entr
|
|
|
746
789
|
if (answer === undefined || answer === "") return;
|
|
747
790
|
picked = answer.split(/[\s,]+/).filter(Boolean);
|
|
748
791
|
}
|
|
749
|
-
saveModelsNamed(ctx, name, mergeLevels(entry, picked));
|
|
792
|
+
await saveModelsNamed(ctx, name, mergeLevels(entry, picked));
|
|
750
793
|
};
|
|
751
794
|
|
|
752
795
|
const probeModelsFlow = async (ctx: ExtensionCommandContext, name: string, entry: ProviderEntry): Promise<void> => {
|
|
@@ -776,38 +819,54 @@ const probeModelsFlow = async (ctx: ExtensionCommandContext, name: string, entry
|
|
|
776
819
|
if (answer === undefined || answer === "") return;
|
|
777
820
|
picked = answer.split(/[\s,]+/).filter(Boolean);
|
|
778
821
|
}
|
|
779
|
-
saveModelsNamed(ctx, name, mergeLevels(entry, picked, result.meta));
|
|
822
|
+
await saveModelsNamed(ctx, name, mergeLevels(entry, picked, result.meta));
|
|
780
823
|
};
|
|
781
824
|
|
|
782
|
-
const THINKING_LEGEND = "[
|
|
825
|
+
const THINKING_LEGEND = "[/] Filter [Space] Off/auto [0-6] Levels [p] Probe [a/r] All auto/off [Enter] Save [Esc] Back";
|
|
826
|
+
// minimal … max: the efforts a map can offer; off is pi's own switch, not an effort.
|
|
827
|
+
const EFFORT_LEVELS = THINKING_LEVELS.slice(1);
|
|
783
828
|
|
|
784
|
-
/**
|
|
785
|
-
*
|
|
786
|
-
|
|
787
|
-
|
|
829
|
+
/** The levels pi offers for a map, read the way pi reads it: a null drops a level, and
|
|
830
|
+
* xhigh and max need an entry of their own. No map is pi's default scale. */
|
|
831
|
+
export function offeredLevels(map: Record<string, string | null> | undefined): ThinkingLevel[] {
|
|
832
|
+
return EFFORT_LEVELS.filter((l) => (map?.[l] === undefined ? l !== "xhigh" && l !== "max" : map[l] !== null));
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
/** Thinking says what each model can do; the level to use is picked per session in /thinking.
|
|
836
|
+
* Space switches a model between off (chat) and auto (reasoning). The levels auto offers come
|
|
837
|
+
* from a probe (p), from model heal, or from 1-6, which toggle minimal … max by hand for a
|
|
838
|
+
* relay that answers a probe and then ignores the effort. A pin an older version stored, or
|
|
839
|
+
* an id suffix such as -high, opens as the level list it allowed. */
|
|
788
840
|
const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: ProviderEntry): Promise<void> => {
|
|
789
|
-
const levels = new Map
|
|
841
|
+
const levels = new Map<string, ThinkingSetting>();
|
|
790
842
|
const probed = new Map<string, Record<string, string | null>>();
|
|
791
|
-
const
|
|
792
|
-
const
|
|
793
|
-
const
|
|
794
|
-
levels.set(
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
};
|
|
798
|
-
const rows: ListRow[] = entry.models.map((m) => ({ label: m.id }));
|
|
799
|
-
/** "medium→high, max off" — what a probed map actually changed. */
|
|
800
|
-
const summary = (map: Record<string, string | null>): string => {
|
|
801
|
-
const parts = Object.entries(map)
|
|
802
|
-
.filter(([level, value]) => value !== level && !(value === null && level === "off"))
|
|
803
|
-
.map(([level, value]) => (value === null ? `${level} off` : `${level}→${value}`));
|
|
804
|
-
return parts.length === 0 ? "all levels accepted" : parts.join(", ");
|
|
805
|
-
};
|
|
843
|
+
for (const m of entry.models) {
|
|
844
|
+
const level = m.level ?? detectLevel(m.id);
|
|
845
|
+
const map = m.map ?? (level === "off" || level === "auto" ? undefined : levelToWire(level).thinkingLevelMap);
|
|
846
|
+
levels.set(m.id, level === "off" ? "off" : "auto");
|
|
847
|
+
if (map) probed.set(m.id, map);
|
|
848
|
+
}
|
|
806
849
|
let busy: string | undefined;
|
|
807
850
|
let progress: string | undefined;
|
|
808
851
|
let warn: string | undefined;
|
|
809
852
|
let refresh: () => void = () => {};
|
|
810
853
|
let closed = false;
|
|
854
|
+
const cycle = (label: string): void => {
|
|
855
|
+
levels.set(label, levels.get(label) === "off" ? "auto" : "off");
|
|
856
|
+
};
|
|
857
|
+
const toggleLevel = (label: string, level: ThinkingLevel): void => {
|
|
858
|
+
const current = offeredLevels(probed.get(label));
|
|
859
|
+
const next = current.includes(level) ? current.filter((l) => l !== level) : [...current, level];
|
|
860
|
+
if (next.length === 0) {
|
|
861
|
+
warn = `${label}: keep at least one level, or press Space to turn thinking off.`;
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
probed.set(label, buildEffortMap(next)!);
|
|
865
|
+
levels.set(label, "auto");
|
|
866
|
+
};
|
|
867
|
+
const rows: ListRow[] = entry.models.map((m) => ({ label: m.id }));
|
|
868
|
+
/** "low high max": the levels /thinking will list for the model. */
|
|
869
|
+
const summary = (map: Record<string, string | null> | undefined): string => offeredLevels(map).join(" ");
|
|
811
870
|
const probe = async (label: string): Promise<void> => {
|
|
812
871
|
const model = entry.models.find((m) => m.id === label);
|
|
813
872
|
const compat = model?.compat ?? {};
|
|
@@ -834,11 +893,10 @@ const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: P
|
|
|
834
893
|
warn = `${label}: no effort level answered — the map is unchanged.`;
|
|
835
894
|
return;
|
|
836
895
|
}
|
|
837
|
-
const
|
|
838
|
-
|
|
839
|
-
if (next) probed.set(label, next);
|
|
896
|
+
const next = buildEffortMap(supported)!;
|
|
897
|
+
probed.set(label, next);
|
|
840
898
|
levels.set(label, "auto");
|
|
841
|
-
warn = `${label}: ${
|
|
899
|
+
warn = `${label}: accepts ${summary(next)}.`;
|
|
842
900
|
} finally {
|
|
843
901
|
busy = undefined;
|
|
844
902
|
progress = undefined;
|
|
@@ -875,35 +933,40 @@ const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: P
|
|
|
875
933
|
},
|
|
876
934
|
press: (keyData) => {
|
|
877
935
|
if (busy) return;
|
|
878
|
-
//
|
|
879
|
-
//
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
for (const id of levels.keys()) levels.set(id,
|
|
883
|
-
probed.clear();
|
|
936
|
+
// Letters reach here only outside the filter (/ toggles typing), so the commands are
|
|
937
|
+
// plain keys. Neither bulk key clears a map: it is what the model accepts.
|
|
938
|
+
if (matchesKey(keyData, "a") || matchesKey(keyData, "r")) {
|
|
939
|
+
const to = matchesKey(keyData, "a") ? "auto" : "off";
|
|
940
|
+
for (const id of levels.keys()) levels.set(id, to);
|
|
884
941
|
refresh();
|
|
885
942
|
return;
|
|
886
943
|
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
944
|
+
const label = rows[picker.index]?.label;
|
|
945
|
+
if (!label) return;
|
|
946
|
+
if (keyData === "0") {
|
|
947
|
+
probed.set(label, buildEffortMap([...EFFORT_LEVELS])!);
|
|
948
|
+
levels.set(label, "auto");
|
|
890
949
|
refresh();
|
|
891
950
|
return;
|
|
892
951
|
}
|
|
893
|
-
const
|
|
894
|
-
if (
|
|
895
|
-
|
|
952
|
+
const digit = EFFORT_LEVELS.findIndex((_l, i) => keyData === String(i + 1));
|
|
953
|
+
if (digit !== -1) {
|
|
954
|
+
toggleLevel(label, EFFORT_LEVELS[digit]!);
|
|
955
|
+
refresh();
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
if (matchesKey(keyData, "p")) void probe(label);
|
|
896
959
|
},
|
|
897
960
|
note: (label) => {
|
|
898
961
|
if (busy === label) return `probing ${progress ?? ""}`.trim();
|
|
899
|
-
|
|
900
|
-
return `${levels.get(label) ?? "off"}${map ? ` · ${summary(map)}` : ""}`;
|
|
962
|
+
return levels.get(label) === "auto" ? `auto · ${summary(probed.get(label))}` : "off";
|
|
901
963
|
},
|
|
902
|
-
description: () =>
|
|
964
|
+
description: () => "0 all · 1-6 minimal low medium high xhigh max · / filter, / or Enter done",
|
|
965
|
+
search: "models",
|
|
903
966
|
legend: () =>
|
|
904
967
|
`${theme.fg("accent", `${[...levels.values()].filter((l) => l !== "off").length}/${rows.length} thinking`)}${theme.fg("dim", ` · ${THINKING_LEGEND}`)}`,
|
|
905
968
|
},
|
|
906
|
-
{ title: screenTitle("Thinking"), description: "
|
|
969
|
+
{ title: screenTitle("Thinking"), description: "levels each model accepts — p probes, 1-6 toggle by hand", legend: THINKING_LEGEND },
|
|
907
970
|
false,
|
|
908
971
|
ctx.thinkingLevel,
|
|
909
972
|
MODEL_VIEWPORT,
|
|
@@ -912,17 +975,26 @@ const thinkingFlow = async (ctx: ExtensionCommandContext, name: string, entry: P
|
|
|
912
975
|
});
|
|
913
976
|
saved = outcome === true;
|
|
914
977
|
} else {
|
|
915
|
-
// No custom screens (RPC/headless): `id:
|
|
916
|
-
const
|
|
978
|
+
// No custom screens (RPC/headless): `id:off`, `id:auto` or `id:low+high+max`.
|
|
979
|
+
const current = [...levels].map(([id, l]) => `${id}:${l === "off" ? "off" : probed.has(id) ? offeredLevels(probed.get(id)).join("+") : "auto"}`);
|
|
980
|
+
const answer = await readInput(ctx, "Thinking", "id:off, id:auto or id:low+high+max — empty = cancel", "", current.join(", "));
|
|
917
981
|
if (answer === undefined || answer === "") return;
|
|
918
982
|
for (const pair of answer.split(/[\s,]+/).filter(Boolean)) {
|
|
919
|
-
const [id,
|
|
920
|
-
if (id
|
|
983
|
+
const [id, value] = pair.split(":");
|
|
984
|
+
if (!id || !value || !levels.has(id)) continue;
|
|
985
|
+
if (value === "off" || value === "auto") {
|
|
986
|
+
levels.set(id, value);
|
|
987
|
+
continue;
|
|
988
|
+
}
|
|
989
|
+
const list = value.split("+").filter((l) => (EFFORT_LEVELS as string[]).includes(l));
|
|
990
|
+
if (list.length === 0) continue;
|
|
991
|
+
probed.set(id, buildEffortMap(list)!);
|
|
992
|
+
levels.set(id, "auto");
|
|
921
993
|
}
|
|
922
994
|
saved = true;
|
|
923
995
|
}
|
|
924
996
|
if (!saved) return;
|
|
925
|
-
saveModelsNamed(
|
|
997
|
+
await saveModelsNamed(
|
|
926
998
|
ctx,
|
|
927
999
|
name,
|
|
928
1000
|
entry.models.map((m) => {
|
|
@@ -1276,6 +1348,14 @@ if (isMain(import.meta.url)) {
|
|
|
1276
1348
|
const picked0 = renderModels(new Set(["m1"]), [{ label: "m1" }, { label: "m2" }]);
|
|
1277
1349
|
assert(picked0.some((l) => l.includes("[x] m1")) && picked0.some((l) => l.includes("[ ] m2")), "checked and unchecked rows render");
|
|
1278
1350
|
assert(picked0.some((l) => l.includes("[a] API")), "the model legend advertises the flavor switch");
|
|
1351
|
+
// Models and Probe models share this screen, so the filter is checked once here.
|
|
1352
|
+
const searchable = new ListPicker(fakeTheme, [{ label: "river/flash" }, { label: "river/glm" }, { label: "other/kimi" }], undefined, { preview: () => {}, revert: () => {}, done: () => {}, requestRender: () => {}, search: "models" }, { title: screenTitle("Models"), description: "d", legend: MODEL_LEGEND }, false);
|
|
1353
|
+
assert(searchable.render(70).map(stripAnsi).some((l) => l.includes("> Type to filter models...")), "the idle model filter names the key-less placeholder");
|
|
1354
|
+
searchable.handleInput("/");
|
|
1355
|
+
for (const ch of "river glm") searchable.handleInput(ch);
|
|
1356
|
+
const narrowed = searchable.render(70).map(stripAnsi);
|
|
1357
|
+
assert(narrowed.filter((l) => /river\/(flash|glm)|other\/kimi/.test(l)).length === 1 && narrowed.some((l) => l.includes("river/glm")), "typing narrows the model list to the fuzzy match");
|
|
1358
|
+
assert(searchable.index === 1, "the selection follows the filtered row back to its model");
|
|
1279
1359
|
|
|
1280
1360
|
// The store reads with pi's own tolerance: a hand-edited models.json (comments, trailing
|
|
1281
1361
|
// commas) is exactly what pi itself accepts, and strings containing `//` or `,]` survive.
|
|
@@ -1310,7 +1390,15 @@ if (isMain(import.meta.url)) {
|
|
|
1310
1390
|
const wireHigh = levelToWire("high") as { reasoning?: boolean; thinkingLevelMap?: Record<string, string | null> };
|
|
1311
1391
|
assert(wireHigh.reasoning === true, "a pinned level sets reasoning");
|
|
1312
1392
|
assert(wireHigh.thinkingLevelMap?.high === "high", "the pinned level maps to itself");
|
|
1313
|
-
assert(
|
|
1393
|
+
assert(wireHigh.thinkingLevelMap?.medium === "medium" && wireHigh.thinkingLevelMap?.minimal === "minimal", "levels below the ceiling stay available");
|
|
1394
|
+
assert(wireHigh.thinkingLevelMap?.xhigh === null && wireHigh.thinkingLevelMap?.max === null, "levels above the ceiling are null");
|
|
1395
|
+
assert(!("off" in wireHigh.thinkingLevelMap!), "off stays unmapped, so thinking can still be turned off");
|
|
1396
|
+
assert(wireToLevel(true, { off: null, minimal: null, low: null, medium: null, high: null, xhigh: "xhigh", max: null }) === "xhigh", "the old single-pin shape still reads as its level");
|
|
1397
|
+
assert(wireToLevel(true, { low: "low", medium: "medium", high: "high", xhigh: "xhigh" }) === "auto", "heal's default map is auto, not an xhigh pin");
|
|
1398
|
+
assert(wireToLevel(true, { medium: "high" }) === "auto", "a probed remap is auto");
|
|
1399
|
+
assert(wireToLevel(true, { minimal: null, low: "low", medium: null, high: "high", xhigh: null, max: "max" }) === "auto", "an exact probed map with gaps is auto, not a max ceiling");
|
|
1400
|
+
assert(loadProviderEntry({ providers: { p: { models: [{ id: "m", reasoning: true, thinkingLevelMap: { medium: null } }] } } }, "p")?.models[0]?.map?.medium === null, "a probed map survives a reload");
|
|
1401
|
+
for (const l of ["minimal", "low", "medium", "high", "xhigh", "max"] as const) assert(wireToLevel(true, levelToWire(l).thinkingLevelMap) === l, `wire round-trips ${l}`);
|
|
1314
1402
|
assert(levelToWire("xhigh")!.thinkingLevelMap!.xhigh === "xhigh", "xhigh needs its explicit map entry");
|
|
1315
1403
|
const wireAuto = levelToWire("auto") as { reasoning?: boolean; thinkingLevelMap?: Record<string, string | null> };
|
|
1316
1404
|
assert(wireAuto.reasoning === true && wireAuto.thinkingLevelMap === undefined, "auto is reasoning without a map");
|
|
@@ -1355,7 +1443,6 @@ if (isMain(import.meta.url)) {
|
|
|
1355
1443
|
assert(levelsSummary([{ id: "a" }]) === "0 thinking", "an all-chat save says so plainly");
|
|
1356
1444
|
// The Thinking screen's bulk keys are Shift+letter: pi-tui lowercases a key id, so this
|
|
1357
1445
|
// pins that they stay distinct from the plain letters navigation already uses.
|
|
1358
|
-
assert(matchesKey("A", "shift+a") && !matchesKey("a", "shift+a"), "Shift+A is its own key, not plain a");
|
|
1359
1446
|
assert(matchesKey("R", "shift+r") && !matchesKey("r", "shift+r"), "Shift+R is its own key, not plain r");
|
|
1360
1447
|
|
|
1361
1448
|
// The stored key is read back from auth.json in an isolated agent dir (never the user's).
|
package/lib/shortcuts.ts
CHANGED
|
@@ -37,12 +37,14 @@ export const SHORTCUT_RELOAD = build("r");
|
|
|
37
37
|
export const SHORTCUT_TOGGLE_FOOTER = build("m");
|
|
38
38
|
/** Expand/collapse the task list widget. Same platform split: Alt+o on Windows/WSL. */
|
|
39
39
|
export const SHORTCUT_TOGGLE_TODOS = build("o");
|
|
40
|
+
/** Open the /arnative settings menu. Alt+a on Windows/WSL, Ctrl+alt+a elsewhere. */
|
|
41
|
+
export const SHORTCUT_OPEN_ARNATIVE = build("a");
|
|
40
42
|
/** Scroll the expanded task list: `j` down, `k` up, one task per press. */
|
|
41
43
|
export const SHORTCUT_SCROLL_TODOS_DOWN = build("j");
|
|
42
44
|
export const SHORTCUT_SCROLL_TODOS_UP = build("k");
|
|
43
45
|
|
|
44
|
-
/** The
|
|
45
|
-
*
|
|
46
|
+
/** The `←` byte matcher. Esc is the advertised way out of a screen (Back, or Close at the
|
|
47
|
+
* root); `←` stays as an alias so muscle memory keeps working, but no footer names it. */
|
|
46
48
|
export const BACK_KEY_LABEL = "←";
|
|
47
49
|
export function matchesBack(data: string): boolean {
|
|
48
50
|
return matchesKey(data, "left");
|
|
@@ -65,23 +67,34 @@ const MOVE = keySet("↑↓", "up", "down");
|
|
|
65
67
|
const CHOOSE = keySet("Enter", "enter");
|
|
66
68
|
const BACK = keySet(BACK_KEY_LABEL, "left");
|
|
67
69
|
const CANCEL = keySet("Esc", "escape");
|
|
68
|
-
|
|
70
|
+
/** The usage dashboard window switch: Tab forward, Shift+Tab back. */
|
|
71
|
+
const RANGE = keySet("Tab", "tab");
|
|
72
|
+
/** Upper case on purpose: the lower case keys already navigate, so a plain r cannot
|
|
73
|
+
* start a destructive flow by accident. Both footers name the capital letter. */
|
|
74
|
+
export const RESET_USAGE = keySet("R", "shift+r");
|
|
75
|
+
/** The undo of a reset, offered only while a reset is the last thing that happened. */
|
|
76
|
+
export const UNDO_USAGE = keySet("U", "shift+u");
|
|
69
77
|
|
|
70
78
|
const legend = (...pairs: [string, string][]): string => pairs.map(([key, action]) => `[${key}] ${action}`).join(" ");
|
|
71
79
|
|
|
72
|
-
/** Root `/arnative` menu: nothing behind it, so
|
|
80
|
+
/** Root `/arnative` menu: nothing behind it, so Esc closes. */
|
|
73
81
|
export const LEGEND_ROOT = legend([MOVE.label, "Move"], [CHOOSE.label, "Open"], [CANCEL.label, "Close"]);
|
|
74
|
-
/** Move-and-open list inside a submenu (the provider list, the provider actions):
|
|
75
|
-
*
|
|
76
|
-
export const LEGEND_MOVE = legend([MOVE.label, "Move"], [CHOOSE.label, "Open"], [
|
|
77
|
-
/** Live-preview list: moving applies, Enter keeps,
|
|
78
|
-
export const LEGEND_LIVE = legend([MOVE.label, "Preview"], [CHOOSE.label, "Select"], [
|
|
82
|
+
/** Move-and-open list inside a submenu (the provider list, the provider actions): Esc steps
|
|
83
|
+
* back to the screen above, exactly like ←. */
|
|
84
|
+
export const LEGEND_MOVE = legend([MOVE.label, "Move"], [CHOOSE.label, "Open"], [CANCEL.label, "Back"]);
|
|
85
|
+
/** Live-preview list: moving applies, Enter keeps, Esc drops the preview and steps out. */
|
|
86
|
+
export const LEGEND_LIVE = legend([MOVE.label, "Preview"], [CHOOSE.label, "Select"], [CANCEL.label, "Back"]);
|
|
79
87
|
/** A list you only read (the `/todos` recap): moving changes nothing, so there is no Open. */
|
|
80
88
|
export const LEGEND_READ_ONLY = legend([MOVE.label, "Move"], [CANCEL.label, "Close"]);
|
|
81
|
-
/** The
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
89
|
+
/** The usage dashboard. `reset` adds the key that deletes history, so a screen without
|
|
90
|
+
* that key never advertises it; `undo` appears only while a reset can be undone. */
|
|
91
|
+
export function legendUsage(width: number, opts: { reset?: boolean; undo?: boolean } = {}): string {
|
|
92
|
+
const pairs: [string, string][] = [[MOVE.label, "Move"], [RANGE.label, "Range"], ["Click", "Open/close"]];
|
|
93
|
+
if (opts.reset) pairs.push([CANCEL.label, "Back"], [RESET_USAGE.label, "Reset"]);
|
|
94
|
+
if (opts.undo) pairs.push([UNDO_USAGE.label, "Undo"]);
|
|
95
|
+
if (!opts.reset) pairs.push([CANCEL.label, "Back"]);
|
|
96
|
+
const full = legend(...pairs);
|
|
97
|
+
return width >= visibleWidth(full) ? full : legend([CANCEL.label, "Back"]);
|
|
85
98
|
}
|
|
86
99
|
|
|
87
100
|
if (isMain(import.meta.url)) {
|
|
@@ -117,20 +130,23 @@ if (isMain(import.meta.url)) {
|
|
|
117
130
|
assert(!matchesBack("h"), "a bare letter is not the back key");
|
|
118
131
|
// The legends are built from the same keys the handlers match, so a key cannot be
|
|
119
132
|
// advertised on one screen and handled on none.
|
|
120
|
-
assert(LEGEND_MOVE === "[↑↓] Move [Enter] Open [
|
|
121
|
-
assert(LEGEND_MOVE.includes("[←] Back"), "the root menu advertises ← Back");
|
|
133
|
+
assert(LEGEND_MOVE === "[↑↓] Move [Enter] Open [Esc] Back", `submenu legend pinned, got ${LEGEND_MOVE}`);
|
|
122
134
|
assert(LEGEND_READ_ONLY === "[↑↓] Move [Esc] Close", `read-only legend pinned, got ${LEGEND_READ_ONLY}`);
|
|
123
135
|
assert(
|
|
124
|
-
LEGEND_LIVE === `[↑↓] Preview [Enter] Select [${
|
|
136
|
+
LEGEND_LIVE === `[↑↓] Preview [Enter] Select [${CANCEL.label}] Back`,
|
|
125
137
|
`live legend pinned, got ${LEGEND_LIVE}`,
|
|
126
138
|
);
|
|
127
139
|
assert(MOVE.matches("\x1b[A") && MOVE.matches("\x1b[B"), "the ↑↓ key matches both arrows");
|
|
128
140
|
assert(CHOOSE.matches("\r"), "[Enter] matches carriage return");
|
|
129
|
-
assert(BACK.matches("\x1b[D"), "
|
|
141
|
+
assert(BACK.matches("\x1b[D"), "← is still the back key, even when the footer names only Esc");
|
|
130
142
|
assert(CANCEL.matches("\x1b"), "[Esc] matches escape");
|
|
131
|
-
assert(!CANCEL.matches("\x1b[D"), "[Esc] is not the
|
|
132
|
-
assert(legendUsage(120).includes(
|
|
143
|
+
assert(!CANCEL.matches("\x1b[D"), "[Esc] is not the ← byte sequence");
|
|
144
|
+
assert(legendUsage(120).includes("[Esc] Back"), "a wide usage legend advertises Esc Back");
|
|
133
145
|
assert(legendUsage(120).includes("[Click] Open/close"), "a wide usage legend advertises the mouse");
|
|
134
|
-
assert(legendUsage(20) === "[
|
|
146
|
+
assert(legendUsage(20) === "[Esc] Back", "a narrow usage legend degrades to the one key that still fits");
|
|
147
|
+
assert(legendUsage(160, { reset: true }).includes("[R] Reset"), "a reset-capable dashboard advertises R Reset");
|
|
148
|
+
assert(!legendUsage(160).includes("Reset"), "the read-only dashboard does not advertise a key it lacks");
|
|
149
|
+
assert(RESET_USAGE.matches("R") && !RESET_USAGE.matches("r"), "a capital R is shift+r, not r");
|
|
150
|
+
assert(UNDO_USAGE.matches("U") && !UNDO_USAGE.matches("u"), "a capital U is shift+u, not u");
|
|
135
151
|
console.log("shortcuts.ts self-check OK");
|
|
136
152
|
}
|
package/lib/spinner.ts
CHANGED
|
File without changes
|
package/lib/status-widget.ts
CHANGED
|
@@ -21,6 +21,15 @@ export const STATUS_ICON = "\ueb1b";
|
|
|
21
21
|
/** pi's own cap on a string-array widget (`InteractiveMode.MAX_WIDGET_LINES`). */
|
|
22
22
|
export const MAX_STATUS_ROWS = 10;
|
|
23
23
|
|
|
24
|
+
// A row that opens with its own Nerd Font glyph (a private-use code point) and a space keeps
|
|
25
|
+
// that glyph as its mark in place of STATUS_ICON, such as model-heal's U+F06DE.
|
|
26
|
+
function ownMark(row: string): boolean {
|
|
27
|
+
const cp = row.codePointAt(0);
|
|
28
|
+
if (cp === undefined) return false;
|
|
29
|
+
const pua = (cp >= 0xe000 && cp <= 0xf8ff) || (cp >= 0xf0000 && cp <= 0xffffd);
|
|
30
|
+
return pua && row[cp > 0xffff ? 2 : 1] === " ";
|
|
31
|
+
}
|
|
32
|
+
|
|
24
33
|
type FgTheme = { fg?(color: string, text: string): string } | null;
|
|
25
34
|
|
|
26
35
|
/** `dim(text)`, or the plain text when the theme is absent or rejects the token. */
|
|
@@ -38,6 +47,7 @@ export function statusRows(th: FgTheme, rows: string[], width = Number.POSITIVE_
|
|
|
38
47
|
const lines = rows
|
|
39
48
|
.slice(0, MAX_STATUS_ROWS)
|
|
40
49
|
.map((row, i) => {
|
|
50
|
+
if (i === 0 && ownMark(row)) return row.includes("\x1b") ? dim(th, " ") + row : dim(th, " " + row);
|
|
41
51
|
const prefix = i === 0 ? ` ${STATUS_ICON} ` : " ";
|
|
42
52
|
return row.includes("\x1b") ? dim(th, prefix) + row : dim(th, prefix + row);
|
|
43
53
|
});
|
|
@@ -52,6 +62,10 @@ if (isMain(import.meta.url)) {
|
|
|
52
62
|
"one space before the mark, one after, one dim span for the whole row",
|
|
53
63
|
);
|
|
54
64
|
assert(JSON.stringify(statusRows(null, ["plain"])) === JSON.stringify([" \ueb1b plain"]), "no theme renders the plain line");
|
|
65
|
+
assert(
|
|
66
|
+
JSON.stringify(statusRows(null, ["\u{f06de} model-heal: x", "y"])) === JSON.stringify([" \u{f06de} model-heal: x", " y"]),
|
|
67
|
+
"a row that opens with its own glyph keeps it as the mark",
|
|
68
|
+
);
|
|
55
69
|
assert(
|
|
56
70
|
JSON.stringify(statusRows({ fg: () => { throw new Error("unknown token"); } }, ["safe"])) === JSON.stringify([" \ueb1b safe"]),
|
|
57
71
|
"a theme that rejects the token does not crash the render",
|
package/lib/todos.ts
CHANGED
|
File without changes
|