@bismawy/pi-vision-watcher 1.3.1 → 1.4.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 +26 -0
- package/README.md +7 -6
- package/package.json +72 -72
- package/src/describer.ts +7 -0
- package/src/index.ts +77 -11
- package/src/router.ts +291 -0
- package/src/vision-model-selector.ts +378 -198
- package/vision-watcher.ts +222 -44
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
* - Ctrl+Shift+R clears the failover chain, Shift+Tab walks the thinking ladder,
|
|
11
11
|
* Alt+A / Ctrl+Alt+A toggles async paste handoff, Alt+↑↓ reorders rows
|
|
12
12
|
* - Enter or Ctrl+S saves, Esc / Ctrl+C cancels
|
|
13
|
-
* - The primary
|
|
13
|
+
* - The primary and chain members are named in a note column, not a checkbox:
|
|
14
|
+
* a single-choice list has nothing to check
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
import {
|
|
17
|
-
Container,
|
|
18
18
|
type Component,
|
|
19
19
|
fuzzyFilter,
|
|
20
20
|
getKeybindings,
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
|
|
30
30
|
import type { ThinkingLevel } from "@earendil-works/pi-ai";
|
|
31
31
|
import { keyText } from "@earendil-works/pi-coding-agent";
|
|
32
|
-
import { formatModelRef,
|
|
32
|
+
import { formatModelRef, isEffectiveVisionModel, THINKING_LEVELS } from "./index.js";
|
|
33
33
|
|
|
34
34
|
/** Failover chain length cap — three is already far past the point where a
|
|
35
35
|
* fourth describer would ever be reached. */
|
|
@@ -80,20 +80,19 @@ export function boxRow(content: string, width: number, paint: (s: string) => str
|
|
|
80
80
|
* ctrl+f is Search in herdr. The older ctrl+q hit POSIX tty flow control (IXON)
|
|
81
81
|
* and pi's app.message.followUp; ctrl+shift+q hit VTE's close-terminal accelerator.
|
|
82
82
|
*
|
|
83
|
-
* Reset
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* 7-bit terminals it degrades to plain `ctrl+r`, which the app does not use, so
|
|
87
|
-
* the worst case is a no-op rather than a wrong action. The old `ctrl+shift+q`
|
|
88
|
-
* was impossible to type on those terminals: both it and `ctrl+q` emit 0x11. */
|
|
83
|
+
* Reset is `r` now that letters are free (the field owns text only while `/`
|
|
84
|
+
* opened it). `ctrl+shift+r` stays as an alias for muscle memory; it is unbound
|
|
85
|
+
* in every default terminal except kitty, where it resizes a window. */
|
|
89
86
|
const FALLBACK_KEY = "tab";
|
|
90
87
|
const FALLBACK_KEY_HINT = "tab";
|
|
91
88
|
const REORDER_UP_KEY = Key.alt("up");
|
|
92
89
|
const REORDER_DOWN_KEY = Key.alt("down");
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
* (
|
|
96
|
-
|
|
90
|
+
/** Legend hints. A bare letter is free because letters are only text while `/`
|
|
91
|
+
* owns the field. The old chords stay as aliases for muscle memory: `alt+a`
|
|
92
|
+
* (Windows/macOS) and `ctrl+alt+a` (Linux, where AltGr takes `alt+a` on intl
|
|
93
|
+
* layouts), and `ctrl+shift+r` for reset. */
|
|
94
|
+
const ASYNC_KEY_HINT = "[A]";
|
|
95
|
+
const RESET_KEY_HINT = "[R]";
|
|
97
96
|
|
|
98
97
|
/** Provider ids that don't title-case cleanly. Everything else falls back to
|
|
99
98
|
* word-capitalisation (`custom-openrouter-ai` → "Custom Openrouter AI"). */
|
|
@@ -136,6 +135,31 @@ interface DisplayItem {
|
|
|
136
135
|
none?: boolean;
|
|
137
136
|
}
|
|
138
137
|
|
|
138
|
+
/** One rendered list row kept in parts: the note column is dropped from the tail
|
|
139
|
+
* at render time when the frame is narrow, so a note never gets cut mid-word. */
|
|
140
|
+
interface ListRow {
|
|
141
|
+
kind: "row";
|
|
142
|
+
/** "-> " (selected) or two spaces, already painted. */
|
|
143
|
+
prefix: string;
|
|
144
|
+
/** The row label, already painted. */
|
|
145
|
+
label: string;
|
|
146
|
+
/** Same label without paint, for the column width. */
|
|
147
|
+
labelText: string;
|
|
148
|
+
/** Painted role marker: `✓ primary` in accent, `✓ fallback 1` in the primary
|
|
149
|
+
* tone, or null when the row is neither. */
|
|
150
|
+
role: string | null;
|
|
151
|
+
/** Painted `(thinking off)` / `(no thinking)` in dim, or null. */
|
|
152
|
+
detail: string | null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** A painted line with no columns: the ↑/↓ counts and the empty-list notice. */
|
|
156
|
+
interface ListLine {
|
|
157
|
+
kind: "line";
|
|
158
|
+
text: string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
type ListEntry = ListRow | ListLine;
|
|
162
|
+
|
|
139
163
|
export interface VisionModelSelectorResult {
|
|
140
164
|
/** The selected "provider/id", or null if the user picked "None" / cancelled. */
|
|
141
165
|
ref: string | null;
|
|
@@ -163,8 +187,9 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
163
187
|
private selectedIndex = 0;
|
|
164
188
|
private readonly maxVisible = 10;
|
|
165
189
|
private searchInput: Input;
|
|
166
|
-
|
|
167
|
-
|
|
190
|
+
/** List rows kept in parts: the note column is padded and thinned at render
|
|
191
|
+
* time because how much room a note gets depends on the frame width. */
|
|
192
|
+
private listEntries: ListEntry[] = [];
|
|
168
193
|
|
|
169
194
|
private currentRef: string | null;
|
|
170
195
|
private thinking: boolean;
|
|
@@ -172,8 +197,16 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
172
197
|
private asyncClipboardHandoff: boolean;
|
|
173
198
|
/** Fallback-chain membership, toggled in-place with {@link FALLBACK_KEY}. */
|
|
174
199
|
private fallbacks: Set<string>;
|
|
175
|
-
/**
|
|
200
|
+
/** Whether `/` has handed the keyboard to the filter field. Idle, the line is a
|
|
201
|
+
* dim prompt (like every arnative screen), so letters stay commands; typing,
|
|
202
|
+
* every printable key is text. `/`, Enter or Esc leave typing and keep the
|
|
203
|
+
* query, so the keys act on the rows it matched. */
|
|
204
|
+
private typing = false;
|
|
205
|
+
/** Transient hint (e.g. chain cap hit), rendered above the legend. */
|
|
176
206
|
private notice: string | null = null;
|
|
207
|
+
/** Whether the user explicitly toggled primary with Space or edited the fallback chain. */
|
|
208
|
+
private touchedPrimary = false;
|
|
209
|
+
private editedChain = false;
|
|
177
210
|
|
|
178
211
|
private _focused = false;
|
|
179
212
|
get focused(): boolean {
|
|
@@ -181,7 +214,9 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
181
214
|
}
|
|
182
215
|
set focused(value: boolean) {
|
|
183
216
|
this._focused = value;
|
|
184
|
-
|
|
217
|
+
// The field owns the cursor only while typing; idle it is a dim prompt line,
|
|
218
|
+
// so pi focusing the component must not paint a fake cursor into it.
|
|
219
|
+
this.searchInput.focused = value && this.typing;
|
|
185
220
|
}
|
|
186
221
|
|
|
187
222
|
constructor(
|
|
@@ -218,12 +253,10 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
218
253
|
// A bare `> ` gives no hint that this line filters the list, so the field
|
|
219
254
|
// carries an inline placeholder until something is typed.
|
|
220
255
|
this.searchInput = new Input({
|
|
221
|
-
|
|
256
|
+
prompt: this.theme.fg("accent", "> "),
|
|
257
|
+
placeholder: "Type to filter models…",
|
|
222
258
|
placeholderStyle: (text) => this.theme.fg("muted", text),
|
|
223
259
|
});
|
|
224
|
-
this.listContainer = new Container();
|
|
225
|
-
this.footerText = new Text(this.getFooterText(), 0, 0);
|
|
226
|
-
|
|
227
260
|
this.searchInput.onSubmit = () => this.save();
|
|
228
261
|
|
|
229
262
|
this.updateList();
|
|
@@ -255,21 +288,103 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
255
288
|
),
|
|
256
289
|
);
|
|
257
290
|
lines.push("");
|
|
258
|
-
|
|
259
|
-
// field carries no prefix of its own — same column as the providers input.
|
|
260
|
-
lines.push(...this.searchInput.render(Math.max(1, width)));
|
|
291
|
+
lines.push(...this.summaryLines(width));
|
|
261
292
|
lines.push("");
|
|
262
|
-
|
|
293
|
+
// Filter line, arnative style: idle it is a dim prompt the eye reads as a
|
|
294
|
+
// field but the keyboard does not own, so `/` starts typing and every
|
|
295
|
+
// letter stays a command until then. Flush with the wall: boxRow supplies
|
|
296
|
+
// the one-space pad.
|
|
297
|
+
lines.push(...this.filterLine(width));
|
|
263
298
|
lines.push("");
|
|
264
|
-
lines.push(...this.
|
|
299
|
+
lines.push(...this.renderList(width));
|
|
265
300
|
lines.push("");
|
|
266
|
-
lines.push(...this.
|
|
301
|
+
lines.push(...this.noteLines(width));
|
|
302
|
+
lines.push(...this.legendLines(width));
|
|
267
303
|
return lines;
|
|
268
304
|
}
|
|
269
305
|
|
|
306
|
+
/** The idle prompt carries the kept query, so a filter that is no longer
|
|
307
|
+
* being typed still shows what it matches. */
|
|
308
|
+
private filterLine(width: number): string[] {
|
|
309
|
+
if (this.typing) return this.searchInput.render(Math.max(1, width));
|
|
310
|
+
const query = this.searchInput.getValue();
|
|
311
|
+
const shown = query
|
|
312
|
+
? this.theme.fg("text", query)
|
|
313
|
+
: this.theme.fg("dim", "Type to filter models…");
|
|
314
|
+
return [this.theme.fg("borderMuted", "> ") + shown];
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** The configuration spelled out in model names: the primary, the failover
|
|
318
|
+
* chain in the order it is tried, and the thinking level. With 70 rows the
|
|
319
|
+
* picked models scroll out of the window, so this header is what answers
|
|
320
|
+
* "which models am I actually using" without hunting them down one by one.
|
|
321
|
+
* Labels share one column, arnative status-panel style, and a long row wraps
|
|
322
|
+
* under its own value instead of spilling to column 0. */
|
|
323
|
+
private summaryLines(width: number): string[] {
|
|
324
|
+
const labels = {
|
|
325
|
+
primary: "Primary",
|
|
326
|
+
fallback: "Fallback",
|
|
327
|
+
thinking: "Thinking",
|
|
328
|
+
};
|
|
329
|
+
const col = Math.max(...Object.values(labels).map((l) => visibleWidth(l)));
|
|
330
|
+
|
|
331
|
+
const row = (labelText: string, body: string, color: ThemeColor = "text") => {
|
|
332
|
+
const head = this.theme.fg("dim", labelText + " ".repeat(col - visibleWidth(labelText)));
|
|
333
|
+
const indent = " ".repeat(col + 3); // label column + " · "
|
|
334
|
+
const wrapped = wrapTextWithAnsi(body, Math.max(8, width - indent.length));
|
|
335
|
+
const out = [head + this.theme.fg("dim", " · ") + this.theme.fg(color, wrapped[0] ?? "")];
|
|
336
|
+
for (const extra of wrapped.slice(1)) out.push(indent + this.theme.fg(color, extra));
|
|
337
|
+
return out;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
const chain = this.currentRef ? this.chainBehindPrimary() : [];
|
|
341
|
+
// Every value uses the same colour. A dim label next to a bright value read
|
|
342
|
+
// as "only the primary is real"; the label column is chrome, the value is
|
|
343
|
+
// the fact. An absent value (no primary) stays muted so it cannot be
|
|
344
|
+
// mistaken for a model name.
|
|
345
|
+
const out: string[] = [];
|
|
346
|
+
out.push(
|
|
347
|
+
...row(
|
|
348
|
+
labels.primary,
|
|
349
|
+
this.currentRef ? this.refLabel(this.currentRef) : "none — vision watcher off",
|
|
350
|
+
this.currentRef ? "text" : "muted",
|
|
351
|
+
),
|
|
352
|
+
);
|
|
353
|
+
if (chain.length) {
|
|
354
|
+
out.push(...row(labels.fallback, chain.map((r) => this.refLabel(r)).join(" → ")));
|
|
355
|
+
}
|
|
356
|
+
out.push(...row(labels.thinking, this.thinking ? this.thinkingLevel : "off"));
|
|
357
|
+
return out;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** Warnings under the list (highlighted row can't think; a refused chain add),
|
|
361
|
+
* the way arnative floats a warn line above its legend. */
|
|
362
|
+
private noteLines(width: number): string[] {
|
|
363
|
+
const out: string[] = [];
|
|
364
|
+
const highlighted = this.filteredItems[this.selectedIndex];
|
|
365
|
+
if (this.thinking && highlighted && !highlighted.none && !highlighted.reasoning) {
|
|
366
|
+
out.push(
|
|
367
|
+
...wrapTextWithAnsi(
|
|
368
|
+
this.theme.fg(
|
|
369
|
+
"warning",
|
|
370
|
+
`Warning: ${highlighted.modelId} declares no reasoning, so thinking will be ignored`,
|
|
371
|
+
),
|
|
372
|
+
width,
|
|
373
|
+
),
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
if (this.notice) {
|
|
377
|
+
out.push(...wrapTextWithAnsi(this.theme.fg("warning", this.notice), width));
|
|
378
|
+
}
|
|
379
|
+
return out.length ? [...out, ""] : [];
|
|
380
|
+
}
|
|
381
|
+
|
|
270
382
|
handleInput(data: string): void {
|
|
271
383
|
const kb = getKeybindings();
|
|
272
384
|
|
|
385
|
+
// The filter owns the keyboard only while `/` has handed it over.
|
|
386
|
+
if (this.searchKey(data)) return;
|
|
387
|
+
|
|
273
388
|
if (kb.matches(data, "tui.select.up")) {
|
|
274
389
|
if (this.filteredItems.length === 0) return;
|
|
275
390
|
this.selectedIndex =
|
|
@@ -301,15 +416,14 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
301
416
|
return;
|
|
302
417
|
}
|
|
303
418
|
|
|
304
|
-
// Confirming saves the configuration.
|
|
305
|
-
//
|
|
306
|
-
//
|
|
307
|
-
// model
|
|
308
|
-
// be saved silently.
|
|
419
|
+
// Confirming saves the configuration. Adopt the highlighted row when a filter
|
|
420
|
+
// query is active OR when no primary has been picked yet (and the user
|
|
421
|
+
// hasn't toggled it off with Space or edited fallbacks), so highlighting a
|
|
422
|
+
// model and pressing Enter works intuitively on first setup.
|
|
309
423
|
if (kb.matches(data, "tui.select.confirm") || matchesKey(data, Key.ctrl("s"))) {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
424
|
+
const item = this.filteredItems[this.selectedIndex];
|
|
425
|
+
if (item && (this.searchInput.getValue() || (this.currentRef === null && !this.touchedPrimary && !this.editedChain && item.ref !== null))) {
|
|
426
|
+
this.currentRef = item.ref;
|
|
313
427
|
}
|
|
314
428
|
this.save();
|
|
315
429
|
return;
|
|
@@ -331,10 +445,9 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
331
445
|
}
|
|
332
446
|
|
|
333
447
|
// Space selects the highlighted model as the primary describer; pressing it
|
|
334
|
-
// again on the same model clears it back to "None".
|
|
335
|
-
//
|
|
336
|
-
|
|
337
|
-
if ((data === " " || matchesKey(data, Key.space)) && !this.searchInput.getValue()) {
|
|
448
|
+
// again on the same model clears it back to "None". Typing already owns the
|
|
449
|
+
// key (searchKey runs first), so a kept query does not steal it back.
|
|
450
|
+
if ((data === " " || matchesKey(data, Key.space)) && !this.typing) {
|
|
338
451
|
const item = this.filteredItems[this.selectedIndex];
|
|
339
452
|
if (item) this.selectPrimary(item.ref);
|
|
340
453
|
return;
|
|
@@ -345,7 +458,8 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
345
458
|
// chosen together. Intercepted before the search input (like the other ctrl
|
|
346
459
|
// shortcuts) so the key never lands in the filter text. See
|
|
347
460
|
// {@link FALLBACK_KEY} for why it isn't ctrl+f.
|
|
348
|
-
|
|
461
|
+
// `r` is Reset; `ctrl+shift+r` stays as the older chord.
|
|
462
|
+
if (data === "r" || data === "R" || matchesKey(data, "ctrl+shift+r")) {
|
|
349
463
|
this.clearFallbacks();
|
|
350
464
|
return;
|
|
351
465
|
}
|
|
@@ -356,11 +470,16 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
356
470
|
return;
|
|
357
471
|
}
|
|
358
472
|
|
|
359
|
-
// alt+a
|
|
360
|
-
//
|
|
361
|
-
//
|
|
362
|
-
//
|
|
363
|
-
if (
|
|
473
|
+
// `a` is Async; alt+a and ctrl+alt+a stay as aliases. `ctrl+a` is the
|
|
474
|
+
// editor's cursorLineStart (Home) and GNU Screen / tmux's command prefix, so
|
|
475
|
+
// it is left alone. Intercepted before the search input so the key never
|
|
476
|
+
// lands in the filter text.
|
|
477
|
+
if (
|
|
478
|
+
data === "a" ||
|
|
479
|
+
data === "A" ||
|
|
480
|
+
matchesKey(data, Key.alt("a")) ||
|
|
481
|
+
matchesKey(data, Key.ctrlAlt("a"))
|
|
482
|
+
) {
|
|
364
483
|
this.asyncClipboardHandoff = !this.asyncClipboardHandoff;
|
|
365
484
|
this.updateList();
|
|
366
485
|
return;
|
|
@@ -376,14 +495,51 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
376
495
|
return;
|
|
377
496
|
}
|
|
378
497
|
|
|
498
|
+
// Nothing else is a command: a stray letter must not type into a filter
|
|
499
|
+
// the user has not opened (that is what `/` is for).
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** Hand `data` to the filter while typing. Outside typing only `/` starts;
|
|
503
|
+
* while typing `/`, Enter and Esc stop typing and KEEP the query, so the
|
|
504
|
+
* rows it matched stay filtered and the commands act on them. Arrows stay
|
|
505
|
+
* navigation even while typing, so a match is reachable without leaving the
|
|
506
|
+
* field. Ctrl+C drops the query and the field together. */
|
|
507
|
+
private searchKey(data: string): boolean {
|
|
508
|
+
if (!this.typing) {
|
|
509
|
+
if (data !== "/") return false;
|
|
510
|
+
this.setTyping(true);
|
|
511
|
+
return true;
|
|
512
|
+
}
|
|
513
|
+
if (data === "/" || matchesKey(data, Key.enter) || matchesKey(data, Key.escape)) {
|
|
514
|
+
this.setTyping(false);
|
|
515
|
+
return true;
|
|
516
|
+
}
|
|
517
|
+
if (matchesKey(data, Key.ctrl("c"))) {
|
|
518
|
+
this.searchInput.setValue("");
|
|
519
|
+
this.setTyping(false);
|
|
520
|
+
this.refresh();
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
if (matchesKey(data, "up") || matchesKey(data, "down")) return false;
|
|
524
|
+
const before = this.searchInput.getValue();
|
|
379
525
|
this.searchInput.handleInput(data);
|
|
380
|
-
this.
|
|
526
|
+
if (this.searchInput.getValue() !== before) {
|
|
527
|
+
this.selectedIndex = 0;
|
|
528
|
+
this.refresh();
|
|
529
|
+
} else {
|
|
530
|
+
this.updateList();
|
|
531
|
+
}
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
private setTyping(typing: boolean): void {
|
|
536
|
+
this.typing = typing;
|
|
537
|
+
this.searchInput.focused = typing;
|
|
538
|
+
this.updateList();
|
|
381
539
|
}
|
|
382
540
|
|
|
383
541
|
invalidate(): void {
|
|
384
542
|
this.searchInput.invalidate();
|
|
385
|
-
this.listContainer.invalidate();
|
|
386
|
-
this.footerText.invalidate();
|
|
387
543
|
}
|
|
388
544
|
|
|
389
545
|
// Internal helpers
|
|
@@ -420,42 +576,65 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
420
576
|
provider: m.provider,
|
|
421
577
|
modelId: m.id,
|
|
422
578
|
modelName: m.name || m.id,
|
|
423
|
-
vision:
|
|
579
|
+
vision: isEffectiveVisionModel(m),
|
|
424
580
|
reasoning: !!m.reasoning,
|
|
425
581
|
});
|
|
426
582
|
|
|
427
583
|
// Only vision-capable models are listed — a text-only model can't describe
|
|
428
584
|
// images, so it would only produce "[Image: description unavailable]" errors.
|
|
429
|
-
const visionModels = allModels.filter((m) =>
|
|
585
|
+
const visionModels = allModels.filter((m) => isEffectiveVisionModel(m)).map(make);
|
|
430
586
|
return [...items, ...visionModels];
|
|
431
587
|
}
|
|
432
588
|
|
|
433
|
-
|
|
589
|
+
/** The legend, packed greedily into rows that fit the frame: a truncated
|
|
590
|
+
* legend advertises keys nobody can read, and a key is never worth splitting.
|
|
591
|
+
* The count opens the first row the way arnative prints `34/44 picked · …`.
|
|
592
|
+
* Toggle state sits beside the key that owns it (`[c] Session cost`), so the
|
|
593
|
+
* screen needs no status panel. */
|
|
594
|
+
private legendLines(width: number): string[] {
|
|
434
595
|
const totalCount = this.allItems.length - 1; // exclude the None row
|
|
596
|
+
// The None row is not a model, and a filter can drop it, so count the rows
|
|
597
|
+
// that name one instead of subtracting a row that may not be there.
|
|
435
598
|
const count = this.searchInput.getValue()
|
|
436
|
-
? `${this.filteredItems.
|
|
599
|
+
? `${this.filteredItems.filter((i) => !i.none).length} matches`
|
|
437
600
|
: `${totalCount} models`;
|
|
438
|
-
|
|
439
|
-
// One legend line: the count carries the accent colour so it is the first
|
|
440
|
-
// thing the eye lands on, while the keys stay dim so they do not compete
|
|
441
|
-
// with the picker itself. The chords need roughly 130 columns, which wraps
|
|
442
|
-
// gracefully; the async chord is hinted beside the state it toggles (and in
|
|
443
|
-
// the README) instead of bloating this strip. `Move` is the highlight, not
|
|
444
|
-
// the row: reordering is `alt+↑↓` and lives in the README.
|
|
445
601
|
const confirm = keyText("tui.select.confirm");
|
|
446
|
-
const
|
|
447
|
-
"[
|
|
448
|
-
`[${confirm.charAt(0).toUpperCase()}${confirm.slice(1)}] Done`,
|
|
449
|
-
"[Space] Vision",
|
|
602
|
+
const keys = [
|
|
603
|
+
"[Space] Primary",
|
|
450
604
|
"[Tab] Fallback",
|
|
451
|
-
"[Ctrl+shift+r] Reset",
|
|
452
605
|
"[Shift+tab] Think",
|
|
606
|
+
`${ASYNC_KEY_HINT} Async ${this.asyncClipboardHandoff ? "on" : "off"}`,
|
|
607
|
+
"[/] Filter",
|
|
608
|
+
`${RESET_KEY_HINT} Reset`,
|
|
609
|
+
`[${confirm.charAt(0).toUpperCase()}${confirm.slice(1)}] Save`,
|
|
453
610
|
"[Esc] Cancel",
|
|
454
|
-
]
|
|
611
|
+
];
|
|
612
|
+
|
|
613
|
+
// The count sits in front of the first row, so the first row's budget is
|
|
614
|
+
// narrower than the frame by exactly that prefix.
|
|
615
|
+
const prefix = `${count} · `;
|
|
616
|
+
const rows: string[] = [];
|
|
617
|
+
let row = "";
|
|
618
|
+
for (const key of keys) {
|
|
619
|
+
const next = row ? `${row} ${key}` : key;
|
|
620
|
+
const budget = rows.length === 0 ? width - visibleWidth(prefix) : width;
|
|
621
|
+
if (row && visibleWidth(next) > budget) {
|
|
622
|
+
rows.push(row);
|
|
623
|
+
row = key;
|
|
624
|
+
} else {
|
|
625
|
+
row = next;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
if (row) rows.push(row);
|
|
455
629
|
|
|
456
630
|
// No prefix: boxRow's own pad is the one space, exactly like the providers
|
|
457
|
-
// legend row
|
|
458
|
-
|
|
631
|
+
// legend row. The count takes the accent so it is the first thing the eye
|
|
632
|
+
// lands on; the keys stay dim so they do not compete with the list.
|
|
633
|
+
return rows.map((line, index) =>
|
|
634
|
+
index === 0
|
|
635
|
+
? `${this.theme.fg("accent", count)}${this.theme.fg("dim", ` · ${line}`)}`
|
|
636
|
+
: this.theme.fg("dim", line),
|
|
637
|
+
);
|
|
459
638
|
}
|
|
460
639
|
|
|
461
640
|
/** Move `ref` one row up/down in the display list. The None row is pinned at
|
|
@@ -468,6 +647,7 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
468
647
|
this.allItems.splice(to, 0, item!);
|
|
469
648
|
this.filteredItems = this.allItems;
|
|
470
649
|
this.selectedIndex = to;
|
|
650
|
+
this.editedChain = true;
|
|
471
651
|
this.updateList();
|
|
472
652
|
}
|
|
473
653
|
|
|
@@ -475,6 +655,7 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
475
655
|
if (this.fallbacks.size === 0) return;
|
|
476
656
|
this.fallbacks.clear();
|
|
477
657
|
this.notice = null;
|
|
658
|
+
this.editedChain = true;
|
|
478
659
|
this.updateList();
|
|
479
660
|
}
|
|
480
661
|
|
|
@@ -482,6 +663,7 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
482
663
|
* (the chain is tried in order, so the config array must be deterministic
|
|
483
664
|
* rather than Set-iteration order). */
|
|
484
665
|
private toggleFallback(ref: string): void {
|
|
666
|
+
this.editedChain = true;
|
|
485
667
|
if (this.fallbacks.has(ref)) {
|
|
486
668
|
this.fallbacks.delete(ref);
|
|
487
669
|
this.notice = null;
|
|
@@ -497,11 +679,36 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
497
679
|
/** Space toggles the primary describer; picking the current one again clears
|
|
498
680
|
* it (same as the None row), so one key both sets and unsets. */
|
|
499
681
|
private selectPrimary(ref: string | null): void {
|
|
682
|
+
this.touchedPrimary = true;
|
|
500
683
|
this.currentRef = this.currentRef === ref ? null : ref;
|
|
501
684
|
this.notice = null;
|
|
502
685
|
this.updateList();
|
|
503
686
|
}
|
|
504
687
|
|
|
688
|
+
private itemByRef(ref: string): DisplayItem | undefined {
|
|
689
|
+
return this.allItems.find((i) => i.ref === ref);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/** "Gemini 3.8 Flash (Antigravity)", or the raw ref when the model is not in
|
|
693
|
+
* the registry right now (stale config), so it stays visible instead of blank. */
|
|
694
|
+
private refLabel(ref: string): string {
|
|
695
|
+
const item = this.itemByRef(ref);
|
|
696
|
+
if (!item) return ref;
|
|
697
|
+
const provider = providerLabel(item.provider);
|
|
698
|
+
// Model display names often already carry the vendor — "Gemini 3.8 Flash
|
|
699
|
+
// (Antigravity)" would otherwise come out as "… (Antigravity) (Antigravity)".
|
|
700
|
+
return item.modelName.toLowerCase().includes(provider.toLowerCase())
|
|
701
|
+
? item.modelName
|
|
702
|
+
: `${item.modelName} (${provider})`;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/** The models behind the primary, in the order they are tried. The primary is
|
|
706
|
+
* excluded: it is tried first, so it is not a numbered fallback even when the
|
|
707
|
+
* config lists it in the chain. */
|
|
708
|
+
private chainBehindPrimary(): string[] {
|
|
709
|
+
return this.orderedFallbacks().filter((r) => r !== this.currentRef);
|
|
710
|
+
}
|
|
711
|
+
|
|
505
712
|
/** Fallback refs in list order (models the picker didn't show — e.g. one that
|
|
506
713
|
* is no longer resolvable — are appended so a config value can't be
|
|
507
714
|
* silently dropped just by opening the picker). */
|
|
@@ -530,12 +737,11 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
530
737
|
}
|
|
531
738
|
|
|
532
739
|
private updateList(): void {
|
|
533
|
-
this.
|
|
740
|
+
this.listEntries = [];
|
|
741
|
+
const chain = this.chainBehindPrimary();
|
|
534
742
|
|
|
535
743
|
if (this.filteredItems.length === 0) {
|
|
536
|
-
this.
|
|
537
|
-
new Text(this.theme.fg("muted", "No matching models"), 0, 0),
|
|
538
|
-
);
|
|
744
|
+
this.listEntries.push({ kind: "line", text: this.theme.fg("muted", "No matching models") });
|
|
539
745
|
}
|
|
540
746
|
|
|
541
747
|
const startIndex = Math.max(
|
|
@@ -550,9 +756,7 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
550
756
|
// Hidden rows are announced like the providers list, never silently cut: the
|
|
551
757
|
// ↑ count sits above the window, the ↓ count below it.
|
|
552
758
|
if (startIndex > 0) {
|
|
553
|
-
this.
|
|
554
|
-
new Text(this.theme.fg("dim", `↑ ${startIndex} more`), 0, 0),
|
|
555
|
-
);
|
|
759
|
+
this.listEntries.push({ kind: "line", text: this.theme.fg("dim", `↑ ${startIndex} more`) });
|
|
556
760
|
}
|
|
557
761
|
|
|
558
762
|
for (let i = startIndex; i < endIndex; i++) {
|
|
@@ -561,150 +765,126 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
561
765
|
|
|
562
766
|
const isSelected = i === this.selectedIndex;
|
|
563
767
|
const prefix = isSelected ? this.theme.fg("accent", "→ ") : " ";
|
|
768
|
+
const labelText = this.rowLabel(item);
|
|
564
769
|
|
|
565
770
|
let label: string;
|
|
566
771
|
if (item.none) {
|
|
567
|
-
label = this.theme.fg("warning",
|
|
772
|
+
label = this.theme.fg("warning", labelText);
|
|
568
773
|
} else {
|
|
569
774
|
// Providers style: the bare `provider/id` ref, no badges — unselected
|
|
570
|
-
// rows sit in muted, the
|
|
775
|
+
// rows sit in muted, the highlighted row takes the soft tier in bold.
|
|
776
|
+
|
|
777
|
+
// The primary keeps the accent even when it is not highlighted, so the
|
|
778
|
+
// picked model is visible without reading the note column.
|
|
571
779
|
label = isSelected
|
|
572
|
-
? softPainter(this.theme, "accent", "accent")(this.theme.bold(
|
|
573
|
-
:
|
|
780
|
+
? softPainter(this.theme, "accent", "accent")(this.theme.bold(labelText))
|
|
781
|
+
: item.ref === this.currentRef
|
|
782
|
+
? this.theme.fg("accent", labelText)
|
|
783
|
+
: this.theme.fg("muted", labelText);
|
|
574
784
|
}
|
|
575
785
|
|
|
576
|
-
//
|
|
577
|
-
//
|
|
578
|
-
const
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
//
|
|
583
|
-
//
|
|
584
|
-
const
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
786
|
+
// No checkbox: the choice is single, so the row states its role instead
|
|
787
|
+
// (`✓ primary`, `✓ fallback 1`) and the fact follows in parentheses.
|
|
788
|
+
const isPrimary = item.ref !== null && item.ref === this.currentRef;
|
|
789
|
+
// Numbered among the models behind the primary: the primary is tried
|
|
790
|
+
// first, so it is not `fallback 1` even when the config lists it first.
|
|
791
|
+
const chainIndex = isPrimary || !item.ref ? -1 : chain.indexOf(item.ref);
|
|
792
|
+
// The None row counts as picked when nothing is, so it carries the
|
|
793
|
+
// "(no handoff)" fact the way a picked row carries its own.
|
|
794
|
+
const isPicked = item.none ? this.currentRef === null : isPrimary || chainIndex >= 0;
|
|
795
|
+
const role = isPrimary
|
|
796
|
+
? this.theme.fg("accent", "✓ primary")
|
|
797
|
+
: chainIndex >= 0
|
|
798
|
+
? this.tone(`✓ fallback ${chainIndex + 1}`)
|
|
799
|
+
: null;
|
|
800
|
+
this.listEntries.push({
|
|
801
|
+
kind: "row",
|
|
802
|
+
prefix,
|
|
803
|
+
label,
|
|
804
|
+
labelText,
|
|
805
|
+
role,
|
|
806
|
+
// The parenthetical belongs to a picked row: on every other row it would
|
|
807
|
+
// repeat `(no thinking)` down the whole list.
|
|
808
|
+
detail: isPicked ? this.rowDetail(item, isPrimary) : null,
|
|
809
|
+
});
|
|
590
810
|
}
|
|
591
811
|
|
|
592
812
|
if (endIndex < this.filteredItems.length) {
|
|
593
|
-
this.
|
|
594
|
-
|
|
595
|
-
|
|
813
|
+
this.listEntries.push({
|
|
814
|
+
kind: "line",
|
|
815
|
+
text: this.theme.fg("dim", `↓ ${this.filteredItems.length - endIndex} more`),
|
|
816
|
+
});
|
|
596
817
|
}
|
|
597
|
-
|
|
598
|
-
this.footerText.setText(this.getFooterText());
|
|
599
818
|
}
|
|
600
819
|
|
|
601
|
-
|
|
602
|
-
|
|
820
|
+
/** One row, hug-style: the ref, then `✓ primary`, then `(thinking off)`.
|
|
821
|
+
* No column padding, so the marker sits right after the ref instead of
|
|
822
|
+
* drifting right with the longest ref in the registry. The fact is worth more
|
|
823
|
+
* than the ref tail, so a narrow frame truncates the ref first (down to 12
|
|
824
|
+
* columns, then drops the parenthetical, then the marker). */
|
|
825
|
+
private renderList(width: number): string[] {
|
|
826
|
+
return this.listEntries.map((entry) => {
|
|
827
|
+
if (entry.kind === "line") return truncateToWidth(entry.text, width, "");
|
|
828
|
+
|
|
829
|
+
const head = entry.prefix;
|
|
830
|
+
const fixed = visibleWidth(head);
|
|
831
|
+
const labelWidth = visibleWidth(entry.label);
|
|
832
|
+
const tail = [entry.role, entry.detail].filter(Boolean).join(" ");
|
|
833
|
+
const tailWidth = tail ? visibleWidth(tail) + 1 : 0;
|
|
834
|
+
|
|
835
|
+
// Everything fits: ref, role, fact.
|
|
836
|
+
if (fixed + labelWidth + tailWidth <= width) {
|
|
837
|
+
return truncateToWidth(`${head}${entry.label}${tail ? ` ${tail}` : ""}`, width, "");
|
|
838
|
+
}
|
|
839
|
+
// Keep the role and the fact, cut the ref tail.
|
|
840
|
+
if (tail && width - fixed - tailWidth >= 12) {
|
|
841
|
+
const shown = truncateToWidth(entry.label, width - fixed - tailWidth, "…");
|
|
842
|
+
return `${head}${shown} ${tail}`;
|
|
843
|
+
}
|
|
844
|
+
// Keep the role only.
|
|
845
|
+
const roleWidth = entry.role ? visibleWidth(entry.role) + 1 : 0;
|
|
846
|
+
if (entry.role && width - fixed - roleWidth >= 12) {
|
|
847
|
+
const shown = truncateToWidth(entry.label, width - fixed - roleWidth, "…");
|
|
848
|
+
return `${head}${shown} ${entry.role}`;
|
|
849
|
+
}
|
|
850
|
+
return truncateToWidth(`${head}${entry.label}${entry.role ? ` ${entry.role}` : ""}`, width, "");
|
|
851
|
+
});
|
|
603
852
|
}
|
|
604
853
|
|
|
605
|
-
/**
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
const item = this.itemByRef(ref);
|
|
609
|
-
if (!item) return ref;
|
|
610
|
-
const provider = providerLabel(item.provider);
|
|
611
|
-
// Model display names often already carry the vendor — "Gemini 3.8 Flash
|
|
612
|
-
// (Antigravity)" would otherwise come out as "… (Antigravity) (Antigravity)".
|
|
613
|
-
return item.modelName.toLowerCase().includes(provider.toLowerCase())
|
|
614
|
-
? item.modelName
|
|
615
|
-
: `${item.modelName} (${provider})`;
|
|
854
|
+
/** The plain label a row renders before paint and padding. */
|
|
855
|
+
private rowLabel(item: DisplayItem): string {
|
|
856
|
+
return item.none ? "None" : item.ref!;
|
|
616
857
|
}
|
|
617
858
|
|
|
618
|
-
/**
|
|
619
|
-
* and
|
|
620
|
-
*
|
|
621
|
-
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
// Arnative status-panel rows: `Label · STATUS | detail`, the label column
|
|
629
|
-
// padded to the widest label so every `·` divider sits in one column, one
|
|
630
|
-
// status word per row (success = on, muted = off). A long detail wraps
|
|
631
|
-
// under its own value column instead of spilling to column 0.
|
|
632
|
-
const labels = {
|
|
633
|
-
vision: " Vision-capable ✦",
|
|
634
|
-
fallback: " Fallback ⇆",
|
|
635
|
-
thinking: " Thinking",
|
|
636
|
-
async: " Async pasted-path fallback",
|
|
637
|
-
};
|
|
638
|
-
const col = Math.max(...Object.values(labels).map((l) => visibleWidth(l)));
|
|
639
|
-
|
|
640
|
-
const row = (labelText: string, status: string, color: ThemeColor, detail: string) => {
|
|
641
|
-
const head =
|
|
642
|
-
this.theme.fg("dim", labelText) +
|
|
643
|
-
" ".repeat(col - visibleWidth(labelText)) +
|
|
644
|
-
this.theme.fg("dim", " · ") +
|
|
645
|
-
this.theme.fg(color, status);
|
|
646
|
-
// Continuations clear the " | " separator so they line up with the detail.
|
|
647
|
-
const indent = " ".repeat(visibleWidth(head) + 3);
|
|
648
|
-
const wrapped = wrapTextWithAnsi(detail, Math.max(8, width - indent.length));
|
|
649
|
-
out.push(`${head}${detail ? this.theme.fg("dim", " | ") + (wrapped[0] ?? "") : ""}`);
|
|
650
|
-
for (const extra of wrapped.slice(1)) out.push(indent + extra);
|
|
651
|
-
};
|
|
652
|
-
|
|
653
|
-
// Free-standing sentence (warning / transient notice), hanging-indented
|
|
654
|
-
// under its own first word.
|
|
655
|
-
const note = (text: string) => {
|
|
656
|
-
const indent = " ";
|
|
657
|
-
wrapTextWithAnsi(text, Math.max(8, width - indent.length)).forEach(
|
|
658
|
-
(part, i) => out.push(i === 0 ? part : indent + part),
|
|
659
|
-
);
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
row(
|
|
663
|
-
labels.vision,
|
|
664
|
-
this.currentRef ? "ON" : "OFF",
|
|
665
|
-
this.currentRef ? "success" : "muted",
|
|
666
|
-
this.currentRef
|
|
667
|
-
? this.refLabel(this.currentRef)
|
|
668
|
-
: this.theme.fg("muted", "none — vision watcher disabled"),
|
|
669
|
-
);
|
|
670
|
-
|
|
671
|
-
const chain = this.orderedFallbacks();
|
|
672
|
-
row(
|
|
673
|
-
labels.fallback,
|
|
674
|
-
chain.length ? "ON" : "OFF",
|
|
675
|
-
chain.length ? "success" : "muted",
|
|
676
|
-
chain.length ? `${chain.map((r) => this.refLabel(r)).join(" → ")} (max ${MAX_FALLBACKS})` : "",
|
|
677
|
-
);
|
|
678
|
-
|
|
679
|
-
row(
|
|
680
|
-
labels.thinking,
|
|
681
|
-
this.thinking ? "ON" : "OFF",
|
|
682
|
-
this.thinking ? "success" : "muted",
|
|
683
|
-
this.thinking ? this.thinkingLevel : "",
|
|
684
|
-
);
|
|
685
|
-
|
|
686
|
-
row(
|
|
687
|
-
labels.async,
|
|
688
|
-
this.asyncClipboardHandoff ? "ON" : "OFF",
|
|
689
|
-
this.asyncClipboardHandoff ? "success" : "muted",
|
|
690
|
-
ASYNC_KEY_HINT,
|
|
691
|
-
);
|
|
692
|
-
|
|
693
|
-
// The warning follows the *highlighted* row: it answers "what happens if I
|
|
694
|
-
// pick this model", which is also how you'd notice it while browsing.
|
|
695
|
-
const highlighted = this.filteredItems[this.selectedIndex];
|
|
696
|
-
if (this.thinking && highlighted && !highlighted.none && !highlighted.reasoning) {
|
|
697
|
-
note(
|
|
698
|
-
this.theme.fg(
|
|
699
|
-
"warning",
|
|
700
|
-
` Warning: ${highlighted.modelId} declares no reasoning — thinking will be ignored`,
|
|
701
|
-
),
|
|
702
|
-
);
|
|
859
|
+
/** What the row means right now, in the note column: its role (primary, chain
|
|
860
|
+
* position) and whether thinking can do anything for it. Both are facts an
|
|
861
|
+
* arnative row would state instead of hiding in a side panel. */
|
|
862
|
+
/** The fact in parentheses after the role. It belongs to the primary (the
|
|
863
|
+
* model that will actually be asked) and to any model that cannot think at
|
|
864
|
+
* all, so the row says that without opening a detail panel. */
|
|
865
|
+
private rowDetail(item: DisplayItem, isPrimary: boolean): string | null {
|
|
866
|
+
if (item.none) {
|
|
867
|
+
return this.currentRef === null ? this.theme.fg("dim", "(no handoff)") : null;
|
|
703
868
|
}
|
|
869
|
+
const fact = !item.reasoning
|
|
870
|
+
? "no thinking"
|
|
871
|
+
: isPrimary
|
|
872
|
+
? this.thinking
|
|
873
|
+
? `thinking ${this.thinkingLevel}`
|
|
874
|
+
: "thinking off"
|
|
875
|
+
: null;
|
|
876
|
+
return fact ? this.theme.fg("dim", `(${fact})`) : null;
|
|
877
|
+
}
|
|
704
878
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
879
|
+
/** The arnative primary tone for a chain marker. pi's theme tokens have no
|
|
880
|
+
* `primary` slot, so use the theme's own when it declares one and fall back
|
|
881
|
+
* to `warning`, the same warm hue in every built-in theme. */
|
|
882
|
+
private tone(text: string): string {
|
|
883
|
+
try {
|
|
884
|
+
return this.theme.fg("primary" as ThemeColor, text);
|
|
885
|
+
} catch {
|
|
886
|
+
return this.theme.fg("warning", text);
|
|
887
|
+
}
|
|
708
888
|
}
|
|
709
889
|
|
|
710
890
|
private save(): void {
|