@bismawy/pi-arnative 0.14.0 → 0.16.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/CHANGELOG.md +19 -0
- package/README.md +52 -67
- package/extensions/animations.ts +11 -26
- package/extensions/arnative.ts +290 -346
- package/extensions/autocompact.ts +5 -12
- package/extensions/budget.ts +87 -136
- package/extensions/footer.ts +27 -45
- package/extensions/render-cache.ts +5 -11
- package/extensions/section-headers.ts +4 -8
- package/extensions/todos.ts +83 -33
- package/extensions/tools.ts +229 -33
- package/extensions/usage-export.ts +3 -12
- package/lib/compat.ts +117 -17
- package/lib/list-picker.ts +5 -5
- package/lib/model-heal.ts +4 -8
- package/lib/preset-store.ts +66 -17
- package/lib/provider.ts +131 -17
- package/lib/spinner.ts +1 -1
- package/lib/usage-store.ts +11 -20
- package/package.json +1 -1
package/extensions/arnative.ts
CHANGED
|
@@ -24,10 +24,11 @@ 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, PAYLOAD_LIMIT_KEY, RENDER_CACHE_KEY, ensureChoices } from "../lib/preset-store.ts";
|
|
28
|
-
import {
|
|
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";
|
|
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";
|
|
29
30
|
import { activeBudgetDay, activeBudgetEnforce, activeBudgetMonth, openBudget } from "./budget.ts";
|
|
30
|
-
import { HEADER_PRESETS, activeHeaderPreset, setHeaderPreset
|
|
31
|
+
import { HEADER_PRESETS, activeHeaderPreset, setHeaderPreset } from "./section-headers.ts";
|
|
31
32
|
import {
|
|
32
33
|
AUTO_COMPACT_CHOICES,
|
|
33
34
|
AUTO_COMPACT_KEY,
|
|
@@ -53,7 +54,6 @@ import {
|
|
|
53
54
|
type RenderCacheChoice,
|
|
54
55
|
} from "./render-cache.ts";
|
|
55
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";
|
|
56
|
-
import { BACK_KEY_LABEL } from "../lib/shortcuts.ts";
|
|
57
57
|
import { openProviders } from "../lib/provider.ts";
|
|
58
58
|
import { openUsage } from "./usage.ts";
|
|
59
59
|
import { SHORTCUT_OPEN_ARNATIVE } from "../lib/shortcuts.ts";
|
|
@@ -66,7 +66,7 @@ export interface MenuCategory {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export const MENU_CATEGORIES: readonly MenuCategory[] = [
|
|
69
|
-
{ label: "Appearance", description: "themes, headers, footers, chatbox, animations" },
|
|
69
|
+
{ label: "Appearance", description: "themes, headers, footers, chatbox, animations, diffs" },
|
|
70
70
|
{ label: "Performance", description: "auto-compact, render cache, payload limit" },
|
|
71
71
|
{ label: "Models", description: "custom providers, model heal" },
|
|
72
72
|
{ label: "Spend", description: "usage dashboard, budget caps" },
|
|
@@ -102,161 +102,201 @@ const THEMES_PICKER_TEXT: ListPickerText = {
|
|
|
102
102
|
legend: LIST_LEGEND_LIVE,
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const goBack = await ctx.ui.custom<boolean>((tui, theme, _kb, done) =>
|
|
129
|
-
new ListPicker(theme, nameRows(names), current, {
|
|
130
|
-
preview: (name) => {
|
|
131
|
-
const result = ctx.ui.setTheme(name);
|
|
132
|
-
if (!result.success) ctx.ui.notify(`[arnative] ${result.error ?? `failed to apply ${name}`}`, "error");
|
|
133
|
-
},
|
|
134
|
-
revert: () => {
|
|
135
|
-
if (current) ctx.ui.setTheme(current);
|
|
136
|
-
},
|
|
137
|
-
done: () => {
|
|
138
|
-
const applied = ctx.ui.theme.name;
|
|
139
|
-
announce(ctx.ui, applied ? `Theme: ${applied}.` : "Theme changed.");
|
|
140
|
-
done(false);
|
|
141
|
-
},
|
|
142
|
-
back: () => {
|
|
143
|
-
// Back drops the live preview, then reports upward so the menu reopens.
|
|
144
|
-
// Guarded like `revert`: `theme.name` is optional, and `setTheme(undefined)`
|
|
145
|
-
// would reach pi's unguarded loader path.
|
|
146
|
-
if (current && ctx.ui.theme.name !== current) ctx.ui.setTheme(current);
|
|
147
|
-
done(true);
|
|
148
|
-
},
|
|
149
|
-
requestRender: () => tui.requestRender(),
|
|
150
|
-
}, THEMES_PICKER_TEXT, true, ctx.thinkingLevel),
|
|
151
|
-
);
|
|
152
|
-
return goBack === true;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/** The Footers screen copy. The legend states the cost switch's live value, like the
|
|
156
|
-
* Animations screen does for the gradient — a constant legend would advertise the value
|
|
157
|
-
* the screen opened with. */
|
|
158
|
-
const footersPickerText = (): ListPickerText => ({
|
|
159
|
-
title: screenTitle("Footers"),
|
|
160
|
-
description: "Selection applies live — custom footer or built-in.",
|
|
161
|
-
legend: `[↑↓] Preview [c] Cost ${activeFooterCost() ? "on" : "off"} [Enter] Select [Esc] Back`,
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
const openFooters = async (ctx: ExtensionCommandContext): Promise<boolean | void> => {
|
|
165
|
-
const opened = activeFooterPreset();
|
|
105
|
+
interface LivePickerSpec<T extends string> {
|
|
106
|
+
choices: readonly T[];
|
|
107
|
+
rows?: ListRow[];
|
|
108
|
+
opened: T | undefined;
|
|
109
|
+
text: ListPickerText | (() => ListPickerText);
|
|
110
|
+
apply: (value: T) => void;
|
|
111
|
+
current: () => T | undefined;
|
|
112
|
+
label: string;
|
|
113
|
+
headlessLabels?: string[];
|
|
114
|
+
onSelectHeadless?: (value: T) => void;
|
|
115
|
+
onDone?: () => void;
|
|
116
|
+
onRevert?: () => void;
|
|
117
|
+
onBack?: () => void;
|
|
118
|
+
cancel?: boolean;
|
|
119
|
+
press?: (keyData: string, requestRender: () => void) => void;
|
|
120
|
+
toggleGradient?: (requestRender: () => void) => void;
|
|
121
|
+
summary?: (theme: { fg(c: string, t: string): string }) => string[];
|
|
122
|
+
note?: (label: string) => string | undefined;
|
|
123
|
+
tickMs?: number;
|
|
124
|
+
}
|
|
166
125
|
|
|
126
|
+
/** Shared live-preview picker: ↑↓ previews immediately, Enter keeps, Esc/← reverts. */
|
|
127
|
+
async function openLivePicker<T extends string>(ctx: ExtensionCommandContext, spec: LivePickerSpec<T>): Promise<boolean | void> {
|
|
128
|
+
const getText = typeof spec.text === "function" ? spec.text : () => spec.text as ListPickerText;
|
|
167
129
|
if (ctx.mode !== "tui") {
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
const pick = await ctx.ui.select(footersPickerText().title, labels);
|
|
130
|
+
const labels = spec.headlessLabels ?? markedLabels(spec.choices, spec.opened);
|
|
131
|
+
const pick = await ctx.ui.select(getText().title, labels);
|
|
171
132
|
if (pick === undefined) return;
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
133
|
+
const chosen = spec.choices[labels.indexOf(pick)]!;
|
|
134
|
+
if (spec.onSelectHeadless) spec.onSelectHeadless(chosen);
|
|
135
|
+
else {
|
|
136
|
+
spec.apply(chosen);
|
|
137
|
+
ctx.ui.notify(`[arnative] ${spec.label}: ${chosen}`, "info");
|
|
138
|
+
}
|
|
175
139
|
return;
|
|
176
140
|
}
|
|
177
|
-
|
|
178
141
|
const goBack = await ctx.ui.custom<boolean>((tui, theme, _kb, done) =>
|
|
179
142
|
new ListPicker(
|
|
180
143
|
theme,
|
|
181
|
-
nameRows(
|
|
182
|
-
opened,
|
|
144
|
+
spec.rows ?? nameRows(spec.choices),
|
|
145
|
+
spec.opened,
|
|
183
146
|
{
|
|
184
|
-
preview: (name) =>
|
|
185
|
-
revert: () =>
|
|
147
|
+
preview: (name) => spec.apply(name as T),
|
|
148
|
+
revert: () => {
|
|
149
|
+
if (spec.onRevert) spec.onRevert();
|
|
150
|
+
else if (spec.opened !== undefined) spec.apply(spec.opened);
|
|
151
|
+
},
|
|
186
152
|
done: () => {
|
|
187
|
-
|
|
153
|
+
if (spec.onDone) spec.onDone();
|
|
154
|
+
else announce(ctx.ui, `${spec.label}: ${spec.current()}.`);
|
|
188
155
|
done(false);
|
|
189
156
|
},
|
|
157
|
+
...(spec.cancel ? { cancel: () => done(false) } : {}),
|
|
190
158
|
back: () => {
|
|
191
|
-
|
|
192
|
-
if (
|
|
159
|
+
if (spec.onBack) spec.onBack();
|
|
160
|
+
else if (spec.opened !== undefined && spec.current() !== spec.opened) spec.apply(spec.opened);
|
|
193
161
|
done(true);
|
|
194
162
|
},
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
},
|
|
202
|
-
legend: () => footersPickerText().legend,
|
|
163
|
+
...(spec.press ? { press: (k) => spec.press!(k, () => tui.requestRender()) } : {}),
|
|
164
|
+
...(spec.toggleGradient ? { toggleGradient: () => spec.toggleGradient!(() => tui.requestRender()) } : {}),
|
|
165
|
+
...(spec.summary ? { summary: () => spec.summary!(theme) } : {}),
|
|
166
|
+
...(spec.note ? { note: spec.note } : {}),
|
|
167
|
+
...(typeof spec.text === "function" ? { legend: () => getText().legend } : {}),
|
|
168
|
+
...(spec.tickMs !== undefined ? { tickMs: spec.tickMs } : {}),
|
|
203
169
|
requestRender: () => tui.requestRender(),
|
|
204
170
|
},
|
|
205
|
-
|
|
171
|
+
getText(),
|
|
206
172
|
true,
|
|
207
173
|
ctx.thinkingLevel,
|
|
208
174
|
),
|
|
209
175
|
);
|
|
210
176
|
return goBack === true;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const HEADERS_PICKER_TEXT: ListPickerText = {
|
|
214
|
-
title: screenTitle("Headers"),
|
|
215
|
-
description: "Selection applies live — custom header or built-in.",
|
|
216
|
-
legend: LIST_LEGEND_LIVE,
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const openHeaders = async (ctx: ExtensionCommandContext): Promise<boolean | void> => {
|
|
220
|
-
const opened = activeHeaderPreset();
|
|
177
|
+
}
|
|
221
178
|
|
|
179
|
+
/** Shared non-live choice picker: Enter commits the highlighted row, Esc/← leaves untouched. */
|
|
180
|
+
async function openChoicePicker<T extends string>(
|
|
181
|
+
ctx: ExtensionCommandContext,
|
|
182
|
+
spec: {
|
|
183
|
+
choices: readonly T[];
|
|
184
|
+
rows: ListRow[];
|
|
185
|
+
opened: T;
|
|
186
|
+
text: ListPickerText;
|
|
187
|
+
onCommit: (index: number, isTui: boolean) => void | Promise<void>;
|
|
188
|
+
},
|
|
189
|
+
): Promise<boolean | void> {
|
|
222
190
|
if (ctx.mode !== "tui") {
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
const pick = await ctx.ui.select(HEADERS_PICKER_TEXT.title, labels);
|
|
191
|
+
const labels = spec.choices.map((c) => (c === spec.opened ? `${c} ✓` : c));
|
|
192
|
+
const pick = await ctx.ui.select(spec.text.title, labels);
|
|
226
193
|
if (pick === undefined) return;
|
|
227
|
-
|
|
228
|
-
setHeaderPreset(name, ctx);
|
|
229
|
-
ctx.ui.notify(`[arnative] Header: ${name}`, "info");
|
|
194
|
+
await spec.onCommit(labels.indexOf(pick), false);
|
|
230
195
|
return;
|
|
231
196
|
}
|
|
232
|
-
|
|
233
|
-
const goBack = await ctx.ui.custom<boolean>((tui, theme, _kb, done) =>
|
|
234
|
-
new ListPicker(
|
|
197
|
+
let committed: number | undefined;
|
|
198
|
+
const goBack = await ctx.ui.custom<boolean>((tui, theme, _kb, done) => {
|
|
199
|
+
const picker = new ListPicker(
|
|
235
200
|
theme,
|
|
236
|
-
|
|
237
|
-
opened,
|
|
201
|
+
spec.rows,
|
|
202
|
+
spec.opened,
|
|
238
203
|
{
|
|
239
|
-
preview: (
|
|
240
|
-
revert: () =>
|
|
204
|
+
preview: () => {},
|
|
205
|
+
revert: () => {},
|
|
241
206
|
done: () => {
|
|
242
|
-
|
|
207
|
+
committed = picker.index;
|
|
243
208
|
done(false);
|
|
244
209
|
},
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (activeHeaderPreset() !== opened) setHeaderPreset(opened, ctx);
|
|
248
|
-
done(true);
|
|
249
|
-
},
|
|
210
|
+
cancel: () => done(false),
|
|
211
|
+
back: () => done(true),
|
|
250
212
|
requestRender: () => tui.requestRender(),
|
|
251
213
|
},
|
|
252
|
-
|
|
253
|
-
|
|
214
|
+
spec.text,
|
|
215
|
+
false,
|
|
254
216
|
ctx.thinkingLevel,
|
|
255
|
-
)
|
|
256
|
-
|
|
217
|
+
);
|
|
218
|
+
return picker;
|
|
219
|
+
});
|
|
220
|
+
if (committed !== undefined) await spec.onCommit(committed, true);
|
|
257
221
|
return goBack === true;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const openThemes = async (ctx: ExtensionCommandContext): Promise<boolean | void> => {
|
|
225
|
+
// Only this package's family (`arnative`, `arnative-<variant>`): the picker brands itself
|
|
226
|
+
// arnative, so pi's own themes and the user's belong in /settings → Theme, not here.
|
|
227
|
+
const names = ctx.ui.getAllThemes().map((t) => t.name).filter(isArnativeThemeName);
|
|
228
|
+
if (names.length === 0) {
|
|
229
|
+
ctx.ui.notify("[arnative] No arnative themes found. Reinstall pi-arnative, or pick any theme in /settings → Theme.", "warning");
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
const current = ctx.ui.theme.name;
|
|
233
|
+
return openLivePicker(ctx, {
|
|
234
|
+
choices: names,
|
|
235
|
+
opened: current,
|
|
236
|
+
text: THEMES_PICKER_TEXT,
|
|
237
|
+
label: "Theme",
|
|
238
|
+
current: () => ctx.ui.theme.name,
|
|
239
|
+
apply: (name) => {
|
|
240
|
+
const result = ctx.ui.setTheme(name);
|
|
241
|
+
if (!result.success) ctx.ui.notify(`[arnative] ${result.error ?? `failed to apply ${name}`}`, "error");
|
|
242
|
+
},
|
|
243
|
+
onSelectHeadless: (name) => {
|
|
244
|
+
const result = ctx.ui.setTheme(name);
|
|
245
|
+
ctx.ui.notify(result.success ? `[arnative] Theme: ${name}` : `[arnative] ${result.error ?? "failed"}`, result.success ? "info" : "error");
|
|
246
|
+
},
|
|
247
|
+
onRevert: () => {
|
|
248
|
+
if (current) ctx.ui.setTheme(current);
|
|
249
|
+
},
|
|
250
|
+
onBack: () => {
|
|
251
|
+
if (current && ctx.ui.theme.name !== current) ctx.ui.setTheme(current);
|
|
252
|
+
},
|
|
253
|
+
onDone: () => {
|
|
254
|
+
const applied = ctx.ui.theme.name;
|
|
255
|
+
announce(ctx.ui, applied ? `Theme: ${applied}.` : "Theme changed.");
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/** The Footers screen copy. The legend states the cost switch's live value, like the
|
|
261
|
+
* Animations screen does for the gradient — a constant legend would advertise the value
|
|
262
|
+
* the screen opened with. */
|
|
263
|
+
const footersPickerText = (): ListPickerText => ({
|
|
264
|
+
title: screenTitle("Footers"),
|
|
265
|
+
description: "Selection applies live — custom footer or built-in.",
|
|
266
|
+
legend: `[↑↓] Preview [c] Cost ${activeFooterCost() ? "on" : "off"} [Enter] Select [Esc] Back`,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
const openFooters = (ctx: ExtensionCommandContext): Promise<boolean | void> =>
|
|
270
|
+
openLivePicker(ctx, {
|
|
271
|
+
choices: FOOTER_PRESETS,
|
|
272
|
+
opened: activeFooterPreset(),
|
|
273
|
+
text: footersPickerText,
|
|
274
|
+
label: "Footer",
|
|
275
|
+
current: activeFooterPreset,
|
|
276
|
+
apply: (name) => setFooterPreset(name, ctx),
|
|
277
|
+
press: (keyData, requestRender) => {
|
|
278
|
+
if (!matchesKey(keyData, "c")) return;
|
|
279
|
+
setFooterCost(!activeFooterCost());
|
|
280
|
+
requestRender();
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
const HEADERS_PICKER_TEXT: ListPickerText = {
|
|
285
|
+
title: screenTitle("Headers"),
|
|
286
|
+
description: "Selection applies live — custom header or built-in.",
|
|
287
|
+
legend: LIST_LEGEND_LIVE,
|
|
258
288
|
};
|
|
259
289
|
|
|
290
|
+
const openHeaders = (ctx: ExtensionCommandContext): Promise<boolean | void> =>
|
|
291
|
+
openLivePicker(ctx, {
|
|
292
|
+
choices: HEADER_PRESETS,
|
|
293
|
+
opened: activeHeaderPreset(),
|
|
294
|
+
text: HEADERS_PICKER_TEXT,
|
|
295
|
+
label: "Header",
|
|
296
|
+
current: activeHeaderPreset,
|
|
297
|
+
apply: (name) => setHeaderPreset(name, ctx),
|
|
298
|
+
});
|
|
299
|
+
|
|
260
300
|
const CHATBOX_PICKER_TEXT: ListPickerText = {
|
|
261
301
|
title: screenTitle("Chatbox"),
|
|
262
302
|
description: "Selection applies when confirmed — rounded arnative box or built-in editor.",
|
|
@@ -285,114 +325,48 @@ export const chatboxSummary = (theme: { fg(c: string, t: string): string }): str
|
|
|
285
325
|
];
|
|
286
326
|
};
|
|
287
327
|
|
|
288
|
-
const openChatbox =
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
setChatboxPreset
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
announce(ctx.ui, `Chatbox: ${activeChatboxPreset()}.`);
|
|
311
|
-
done(false);
|
|
312
|
-
},
|
|
313
|
-
back: () => {
|
|
314
|
-
if (activeChatboxPreset() !== opened) setChatboxPreset(opened);
|
|
315
|
-
done(true);
|
|
316
|
-
},
|
|
317
|
-
press: (keyData) => {
|
|
318
|
-
if (matchesKey(keyData, "i") || keyData === "I") {
|
|
319
|
-
setChatboxPrompt(nextChatboxPrompt());
|
|
320
|
-
tui.requestRender();
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
if (matchesKey(keyData, "d") || keyData === "D") {
|
|
324
|
-
setChatboxDialog(nextChatboxDialog());
|
|
325
|
-
tui.requestRender();
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
summary: () => chatboxSummary(theme),
|
|
329
|
-
requestRender: () => tui.requestRender(),
|
|
330
|
-
},
|
|
331
|
-
CHATBOX_PICKER_TEXT,
|
|
332
|
-
true,
|
|
333
|
-
ctx.thinkingLevel,
|
|
334
|
-
),
|
|
335
|
-
);
|
|
336
|
-
return goBack === true;
|
|
337
|
-
};
|
|
328
|
+
const openChatbox = (ctx: ExtensionCommandContext): Promise<boolean | void> =>
|
|
329
|
+
openLivePicker(ctx, {
|
|
330
|
+
choices: CHATBOX_PRESETS,
|
|
331
|
+
rows: chatboxRows(),
|
|
332
|
+
opened: activeChatboxPreset(),
|
|
333
|
+
text: CHATBOX_PICKER_TEXT,
|
|
334
|
+
label: "Chatbox",
|
|
335
|
+
current: activeChatboxPreset,
|
|
336
|
+
apply: setChatboxPreset,
|
|
337
|
+
summary: chatboxSummary,
|
|
338
|
+
press: (keyData, requestRender) => {
|
|
339
|
+
if (matchesKey(keyData, "i") || keyData === "I") {
|
|
340
|
+
setChatboxPrompt(nextChatboxPrompt());
|
|
341
|
+
requestRender();
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (matchesKey(keyData, "d") || keyData === "D") {
|
|
345
|
+
setChatboxDialog(nextChatboxDialog());
|
|
346
|
+
requestRender();
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
});
|
|
338
350
|
|
|
339
351
|
/** Animations picker. Unlike Themes/Headers/Footers the choice has a visible effect only
|
|
340
352
|
* while a tool runs, so there is nothing to preview live on the screen itself — the row
|
|
341
353
|
* previews the frames instead, and Enter installs the preset for the next run. */
|
|
342
|
-
const openAnimations =
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
const goBack = await ctx.ui.custom<boolean>((tui, theme, _kb, done) =>
|
|
360
|
-
new ListPicker(
|
|
361
|
-
theme,
|
|
362
|
-
rows,
|
|
363
|
-
opened,
|
|
364
|
-
{
|
|
365
|
-
preview: (name) => setSpinnerPreset(name as SpinnerPreset),
|
|
366
|
-
revert: () => setSpinnerPreset(opened),
|
|
367
|
-
done: () => {
|
|
368
|
-
announce(ctx.ui, `Animation: ${activeSpinnerPreset()}.`);
|
|
369
|
-
done(false);
|
|
370
|
-
},
|
|
371
|
-
back: () => {
|
|
372
|
-
// Back restores the preset it opened with, then reports upward.
|
|
373
|
-
if (activeSpinnerPreset() !== opened) setSpinnerPreset(opened);
|
|
374
|
-
done(true);
|
|
375
|
-
},
|
|
376
|
-
// `[g]` is a switch, not a preview: it is a command the user asked for and the legend
|
|
377
|
-
// states its state, so Esc and `←` leave it on. Only the preset preview reverts.
|
|
378
|
-
toggleGradient: () => {
|
|
379
|
-
setSpinnerGradient(!activeSpinnerGradient());
|
|
380
|
-
tui.requestRender();
|
|
381
|
-
},
|
|
382
|
-
legend: () => animationsPickerText().legend,
|
|
383
|
-
// The row animates: its note is re-read each tick and the frame comes from the
|
|
384
|
-
// clock, so the picker shows motion instead of a static glyph list.
|
|
385
|
-
note: (label) => animationRowNote(label as SpinnerPreset),
|
|
386
|
-
tickMs: PREVIEW_TICK_MS,
|
|
387
|
-
requestRender: () => tui.requestRender(),
|
|
388
|
-
},
|
|
389
|
-
animationsPickerText(),
|
|
390
|
-
true,
|
|
391
|
-
ctx.thinkingLevel,
|
|
392
|
-
),
|
|
393
|
-
);
|
|
394
|
-
return goBack === true;
|
|
395
|
-
};
|
|
354
|
+
const openAnimations = (ctx: ExtensionCommandContext): Promise<boolean | void> =>
|
|
355
|
+
openLivePicker(ctx, {
|
|
356
|
+
choices: SPINNER_PRESETS,
|
|
357
|
+
rows: animationRows(),
|
|
358
|
+
opened: activeSpinnerPreset(),
|
|
359
|
+
text: animationsPickerText,
|
|
360
|
+
label: "Animation",
|
|
361
|
+
current: activeSpinnerPreset,
|
|
362
|
+
apply: setSpinnerPreset,
|
|
363
|
+
toggleGradient: (requestRender) => {
|
|
364
|
+
setSpinnerGradient(!activeSpinnerGradient());
|
|
365
|
+
requestRender();
|
|
366
|
+
},
|
|
367
|
+
note: (label) => animationRowNote(label as SpinnerPreset),
|
|
368
|
+
tickMs: PREVIEW_TICK_MS,
|
|
369
|
+
});
|
|
396
370
|
|
|
397
371
|
const AUTOCOMPACT_PICKER_TEXT: ListPickerText = {
|
|
398
372
|
title: screenTitle("Auto-compact"),
|
|
@@ -424,46 +398,25 @@ export function autoCompactRows(opened: AutoCompactChoice): ListRow[] {
|
|
|
424
398
|
|
|
425
399
|
/** A plain (non-live) picker: the choice is committed by Enter, nothing previews. The
|
|
426
400
|
* trigger itself lives in `extensions/autocompact.ts` and fires on the next settle. */
|
|
427
|
-
const openAutoCompact =
|
|
401
|
+
const openAutoCompact = (ctx: ExtensionCommandContext): Promise<boolean | void> => {
|
|
428
402
|
const opened = activeAutoCompact();
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
theme,
|
|
446
|
-
autoCompactRows(opened),
|
|
447
|
-
opened,
|
|
448
|
-
{
|
|
449
|
-
preview: () => {},
|
|
450
|
-
revert: () => {},
|
|
451
|
-
done: () => {
|
|
452
|
-
setAutoCompact(AUTO_COMPACT_CHOICES[picker.index]!);
|
|
453
|
-
announce(ctx.ui, `Auto-compact: ${AUTO_COMPACT_CHOICES[picker.index]}.`);
|
|
454
|
-
done(false);
|
|
455
|
-
},
|
|
456
|
-
cancel: () => done(false),
|
|
457
|
-
back: () => done(true),
|
|
458
|
-
requestRender: () => tui.requestRender(),
|
|
459
|
-
},
|
|
460
|
-
AUTOCOMPACT_PICKER_TEXT,
|
|
461
|
-
false,
|
|
462
|
-
ctx.thinkingLevel,
|
|
463
|
-
);
|
|
464
|
-
return picker;
|
|
403
|
+
return openChoicePicker(ctx, {
|
|
404
|
+
choices: AUTO_COMPACT_CHOICES,
|
|
405
|
+
rows: autoCompactRows(opened),
|
|
406
|
+
opened,
|
|
407
|
+
text: AUTOCOMPACT_PICKER_TEXT,
|
|
408
|
+
onCommit: (index, isTui) => {
|
|
409
|
+
const choice = AUTO_COMPACT_CHOICES[index]!;
|
|
410
|
+
setAutoCompact(choice);
|
|
411
|
+
if (isTui) announce(ctx.ui, `Auto-compact: ${choice}.`);
|
|
412
|
+
else {
|
|
413
|
+
ctx.ui.notify(
|
|
414
|
+
`[arnative] Auto-compact: ${choice === "Off" ? "off" : choice === "Smart" ? "smart (tiered by context window)" : `above ${choice} tokens of context`}`,
|
|
415
|
+
"info",
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
},
|
|
465
419
|
});
|
|
466
|
-
return goBack === true;
|
|
467
420
|
};
|
|
468
421
|
|
|
469
422
|
const MODEL_HEAL_PICKER_TEXT: ListPickerText = {
|
|
@@ -489,53 +442,24 @@ export function modelHealRows(opened: ModelHealChoice): ListRow[] {
|
|
|
489
442
|
];
|
|
490
443
|
}
|
|
491
444
|
|
|
492
|
-
const openModelHeal =
|
|
445
|
+
const openModelHeal = (ctx: ExtensionCommandContext): Promise<boolean | void> => {
|
|
493
446
|
const opened = activeModelHeal();
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
let runNow = false;
|
|
510
|
-
const goBack = await ctx.ui.custom<boolean>((tui, theme, _kb, done) => {
|
|
511
|
-
const picker = new ListPicker(
|
|
512
|
-
theme,
|
|
513
|
-
modelHealRows(opened),
|
|
514
|
-
opened,
|
|
515
|
-
{
|
|
516
|
-
preview: () => {},
|
|
517
|
-
revert: () => {},
|
|
518
|
-
done: () => {
|
|
519
|
-
if (picker.index === MODEL_HEAL_CHOICES.length) runNow = true;
|
|
520
|
-
else {
|
|
521
|
-
setModelHeal(MODEL_HEAL_CHOICES[picker.index]!);
|
|
522
|
-
announce(ctx.ui, `Model heal: ${MODEL_HEAL_CHOICES[picker.index]}.`);
|
|
523
|
-
}
|
|
524
|
-
done(false);
|
|
525
|
-
},
|
|
526
|
-
cancel: () => done(false),
|
|
527
|
-
back: () => done(true),
|
|
528
|
-
requestRender: () => tui.requestRender(),
|
|
529
|
-
},
|
|
530
|
-
MODEL_HEAL_PICKER_TEXT,
|
|
531
|
-
false,
|
|
532
|
-
ctx.thinkingLevel,
|
|
533
|
-
);
|
|
534
|
-
return picker;
|
|
447
|
+
return openChoicePicker(ctx, {
|
|
448
|
+
choices: [...MODEL_HEAL_CHOICES, MODEL_HEAL_RUN_NOW],
|
|
449
|
+
rows: modelHealRows(opened),
|
|
450
|
+
opened,
|
|
451
|
+
text: MODEL_HEAL_PICKER_TEXT,
|
|
452
|
+
onCommit: async (index, isTui) => {
|
|
453
|
+
if (index === MODEL_HEAL_CHOICES.length) {
|
|
454
|
+
await healNow(ctx);
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const choice = MODEL_HEAL_CHOICES[index]!;
|
|
458
|
+
setModelHeal(choice);
|
|
459
|
+
if (isTui) announce(ctx.ui, `Model heal: ${choice}.`);
|
|
460
|
+
else ctx.ui.notify(`[arnative] Model heal: ${choice}`, "info");
|
|
461
|
+
},
|
|
535
462
|
});
|
|
536
|
-
// After the picker closed: the run notifies, and a notice under an open overlay is lost.
|
|
537
|
-
if (runNow) await healNow(ctx);
|
|
538
|
-
return goBack === true;
|
|
539
463
|
};
|
|
540
464
|
|
|
541
465
|
const RENDER_CACHE_PICKER_TEXT: ListPickerText = {
|
|
@@ -554,44 +478,54 @@ export function renderCacheRows(opened: RenderCacheChoice): ListRow[] {
|
|
|
554
478
|
return RENDER_CACHE_CHOICES.map((c) => ({ label: c, note: RENDER_CACHE_NOTES[c], chosen: c === opened }));
|
|
555
479
|
}
|
|
556
480
|
|
|
557
|
-
const
|
|
558
|
-
|
|
481
|
+
const DIFFS_PICKER_TEXT: ListPickerText = {
|
|
482
|
+
title: screenTitle("Diffs"),
|
|
483
|
+
description: "Selection previews live — side-by-side Before │ After or unified +/- diff.",
|
|
484
|
+
legend: LIST_LEGEND_LIVE,
|
|
485
|
+
};
|
|
559
486
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
const choice = RENDER_CACHE_CHOICES[labels.indexOf(pick)]!;
|
|
565
|
-
setRenderCache(choice);
|
|
566
|
-
ctx.ui.notify(`[arnative] Render cache: ${choice}`, "info");
|
|
567
|
-
return;
|
|
568
|
-
}
|
|
487
|
+
const EDIT_DIFF_NOTES: Record<EditDiffMode, string> = {
|
|
488
|
+
Split: "side-by-side Before │ After columns (default)",
|
|
489
|
+
Unified: "single-column +/- diff, easier to copy-paste",
|
|
490
|
+
};
|
|
569
491
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
492
|
+
/** Rows for `/arnative` → Diffs: Split / Unified. */
|
|
493
|
+
export function diffRows(): ListRow[] {
|
|
494
|
+
return EDIT_DIFF_CHOICES.map((c) => ({
|
|
495
|
+
label: c,
|
|
496
|
+
note: EDIT_DIFF_NOTES[c],
|
|
497
|
+
}));
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const openDiffs = (ctx: ExtensionCommandContext): Promise<boolean | void> => {
|
|
501
|
+
const opened = activeEditDiff();
|
|
502
|
+
return openLivePicker(ctx, {
|
|
503
|
+
choices: EDIT_DIFF_CHOICES,
|
|
504
|
+
rows: diffRows(),
|
|
505
|
+
opened,
|
|
506
|
+
text: DIFFS_PICKER_TEXT,
|
|
507
|
+
label: "Diffs",
|
|
508
|
+
current: activeEditDiff,
|
|
509
|
+
apply: setEditDiff,
|
|
510
|
+
headlessLabels: EDIT_DIFF_CHOICES.map((c) => (c === opened ? `${c} ✓` : c)),
|
|
511
|
+
cancel: true,
|
|
512
|
+
});
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
const openRenderCache = (ctx: ExtensionCommandContext): Promise<boolean | void> => {
|
|
516
|
+
const opened = activeRenderCache();
|
|
517
|
+
return openChoicePicker(ctx, {
|
|
518
|
+
choices: RENDER_CACHE_CHOICES,
|
|
519
|
+
rows: renderCacheRows(opened),
|
|
520
|
+
opened,
|
|
521
|
+
text: RENDER_CACHE_PICKER_TEXT,
|
|
522
|
+
onCommit: (index, isTui) => {
|
|
523
|
+
const choice = RENDER_CACHE_CHOICES[index]!;
|
|
524
|
+
setRenderCache(choice);
|
|
525
|
+
if (isTui) announce(ctx.ui, `Render cache: ${choice}.`);
|
|
526
|
+
else ctx.ui.notify(`[arnative] Render cache: ${choice}`, "info");
|
|
527
|
+
},
|
|
593
528
|
});
|
|
594
|
-
return goBack === true;
|
|
595
529
|
};
|
|
596
530
|
|
|
597
531
|
const PAYLOAD_CUSTOM_LABEL = "Custom";
|
|
@@ -760,6 +694,13 @@ export const MENUS: ArnativeMenu[] = [
|
|
|
760
694
|
group: "Appearance",
|
|
761
695
|
open: openAnimations,
|
|
762
696
|
},
|
|
697
|
+
{
|
|
698
|
+
value: "diffs",
|
|
699
|
+
label: "Diffs",
|
|
700
|
+
description: "side-by-side Before/After or unified diff",
|
|
701
|
+
group: "Appearance",
|
|
702
|
+
open: openDiffs,
|
|
703
|
+
},
|
|
763
704
|
{
|
|
764
705
|
value: "compact",
|
|
765
706
|
label: "Auto-compact",
|
|
@@ -957,6 +898,7 @@ export function recordProfile(): void {
|
|
|
957
898
|
[CHATBOX_DIALOG_KEY]: activeChatboxDialog(),
|
|
958
899
|
[SPINNER_PRESET_KEY]: activeSpinnerPreset(),
|
|
959
900
|
[SPINNER_GRADIENT_KEY]: activeSpinnerGradient() ? "on" : "off",
|
|
901
|
+
[EDIT_DIFF_KEY]: activeEditDiff(),
|
|
960
902
|
[AUTO_COMPACT_KEY]: activeAutoCompact(),
|
|
961
903
|
[PAYLOAD_LIMIT_KEY]: savedPayloadLimit(),
|
|
962
904
|
[MODEL_HEAL_KEY]: activeModelHeal(),
|
|
@@ -1001,7 +943,7 @@ if (isMain(import.meta.url)) {
|
|
|
1001
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}`);
|
|
1002
944
|
// Every menu row is reachable and the description names them all, so a new screen cannot
|
|
1003
945
|
// be added to MENUS and forgotten in the copy a user reads first.
|
|
1004
|
-
assert(MENUS.length ===
|
|
946
|
+
assert(MENUS.length === 13, "thirteen settings screens");
|
|
1005
947
|
{
|
|
1006
948
|
const catRows = menuRows([...MENU_CATEGORIES]);
|
|
1007
949
|
assert(catRows.map((r) => r.label).join(",") === "Appearance,Performance,Models,Spend", "root menu lists the four categories in order");
|
|
@@ -1015,6 +957,8 @@ if (isMain(import.meta.url)) {
|
|
|
1015
957
|
const rc = renderCacheRows("On");
|
|
1016
958
|
assert(rc.map((r) => r.label).join(",") === "On,Off", "Render cache rows: On then Off");
|
|
1017
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");
|
|
1018
962
|
const pl = payloadLimitRows("16 MB");
|
|
1019
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");
|
|
1020
964
|
assert(pl.filter((r) => r.chosen).map((r) => r.label).join(",") === "16 MB", "Payload limit marks the active preset");
|
|
@@ -1022,7 +966,7 @@ if (isMain(import.meta.url)) {
|
|
|
1022
966
|
assert(plCustom.filter((r) => r.chosen).map((r) => r.label).join(",") === "Custom", "Payload limit marks Custom when a non-preset MB is active");
|
|
1023
967
|
assert(plCustom[plCustom.length - 1]!.note!.includes("11 MB"), "Custom row displays the active custom MB");
|
|
1024
968
|
}
|
|
1025
|
-
for (const label of ["Themes", "Headers", "Footers", "Chatbox", "Animations", "Auto-compact", "Render cache", "Payload limit", "Providers", "Usage", "Budget"]) {
|
|
969
|
+
for (const label of ["Themes", "Headers", "Footers", "Chatbox", "Animations", "Diffs", "Auto-compact", "Render cache", "Payload limit", "Providers", "Usage", "Budget"]) {
|
|
1026
970
|
assert(MENUS.some((m) => m.label === label), `MENUS carries the ${label} screen`);
|
|
1027
971
|
}
|
|
1028
972
|
assert(/^Settings - Arnative/.test(MENU_TITLE), "title follows `<setting> - <extension>`");
|