@bismawy/pi-vision-watcher 1.3.0 → 1.4.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.
@@ -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 is the checked row [x], chain members ⇆ (providers style)
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,
@@ -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 uses `ctrl+shift+r` because R reads as Reset. It is unbound in every
84
- * default terminal (VTE, Konsole, Windows Terminal, iTerm2 — kitty is the lone
85
- * exception, where it resizes a window) and unbound anywhere in pi. On legacy
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
- /** Hint printed next to the async toggle in the detail pane (and the legend).
94
- * `ctrl+alt+a` is the Linux-safe half: AltGr occupies alt+a on intl layouts
95
- * (`@`, `ł`), so the selector accepts both chords. */
96
- const ASYNC_KEY_HINT = "[Ctrl+alt+a]";
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
- private listContainer: Container;
167
- private footerText: Text;
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,7 +197,12 @@ 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
- /** Transient hint (e.g. chain cap hit), rendered in the detail pane. */
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;
177
207
 
178
208
  private _focused = false;
@@ -181,7 +211,9 @@ export class VisionModelSelectorComponent implements Component {
181
211
  }
182
212
  set focused(value: boolean) {
183
213
  this._focused = value;
184
- this.searchInput.focused = value;
214
+ // The field owns the cursor only while typing; idle it is a dim prompt line,
215
+ // so pi focusing the component must not paint a fake cursor into it.
216
+ this.searchInput.focused = value && this.typing;
185
217
  }
186
218
 
187
219
  constructor(
@@ -218,12 +250,10 @@ export class VisionModelSelectorComponent implements Component {
218
250
  // A bare `> ` gives no hint that this line filters the list, so the field
219
251
  // carries an inline placeholder until something is typed.
220
252
  this.searchInput = new Input({
221
- placeholder: "type to filter models…",
253
+ prompt: this.theme.fg("accent", "> "),
254
+ placeholder: "Type to filter models…",
222
255
  placeholderStyle: (text) => this.theme.fg("muted", text),
223
256
  });
224
- this.listContainer = new Container();
225
- this.footerText = new Text(this.getFooterText(), 0, 0);
226
-
227
257
  this.searchInput.onSubmit = () => this.save();
228
258
 
229
259
  this.updateList();
@@ -255,21 +285,103 @@ export class VisionModelSelectorComponent implements Component {
255
285
  ),
256
286
  );
257
287
  lines.push("");
258
- // Flush with the wall: boxRow already supplies the one-space pad, so the
259
- // field carries no prefix of its own — same column as the providers input.
260
- lines.push(...this.searchInput.render(Math.max(1, width)));
288
+ lines.push(...this.summaryLines(width));
261
289
  lines.push("");
262
- lines.push(...this.listContainer.render(width));
290
+ // Filter line, arnative style: idle it is a dim prompt the eye reads as a
291
+ // field but the keyboard does not own, so `/` starts typing and every
292
+ // letter stays a command until then. Flush with the wall: boxRow supplies
293
+ // the one-space pad.
294
+ lines.push(...this.filterLine(width));
263
295
  lines.push("");
264
- lines.push(...this.detailLines(width));
296
+ lines.push(...this.renderList(width));
265
297
  lines.push("");
266
- lines.push(...this.footerText.render(width));
298
+ lines.push(...this.noteLines(width));
299
+ lines.push(...this.legendLines(width));
267
300
  return lines;
268
301
  }
269
302
 
303
+ /** The idle prompt carries the kept query, so a filter that is no longer
304
+ * being typed still shows what it matches. */
305
+ private filterLine(width: number): string[] {
306
+ if (this.typing) return this.searchInput.render(Math.max(1, width));
307
+ const query = this.searchInput.getValue();
308
+ const shown = query
309
+ ? this.theme.fg("text", query)
310
+ : this.theme.fg("dim", "Type to filter models…");
311
+ return [this.theme.fg("borderMuted", "> ") + shown];
312
+ }
313
+
314
+ /** The configuration spelled out in model names: the primary, the failover
315
+ * chain in the order it is tried, and the thinking level. With 70 rows the
316
+ * picked models scroll out of the window, so this header is what answers
317
+ * "which models am I actually using" without hunting them down one by one.
318
+ * Labels share one column, arnative status-panel style, and a long row wraps
319
+ * under its own value instead of spilling to column 0. */
320
+ private summaryLines(width: number): string[] {
321
+ const labels = {
322
+ primary: "Primary",
323
+ fallback: "Fallback",
324
+ thinking: "Thinking",
325
+ };
326
+ const col = Math.max(...Object.values(labels).map((l) => visibleWidth(l)));
327
+
328
+ const row = (labelText: string, body: string, color: ThemeColor = "text") => {
329
+ const head = this.theme.fg("dim", labelText + " ".repeat(col - visibleWidth(labelText)));
330
+ const indent = " ".repeat(col + 3); // label column + " · "
331
+ const wrapped = wrapTextWithAnsi(body, Math.max(8, width - indent.length));
332
+ const out = [head + this.theme.fg("dim", " · ") + this.theme.fg(color, wrapped[0] ?? "")];
333
+ for (const extra of wrapped.slice(1)) out.push(indent + this.theme.fg(color, extra));
334
+ return out;
335
+ };
336
+
337
+ const chain = this.currentRef ? this.chainBehindPrimary() : [];
338
+ // Every value uses the same colour. A dim label next to a bright value read
339
+ // as "only the primary is real"; the label column is chrome, the value is
340
+ // the fact. An absent value (no primary) stays muted so it cannot be
341
+ // mistaken for a model name.
342
+ const out: string[] = [];
343
+ out.push(
344
+ ...row(
345
+ labels.primary,
346
+ this.currentRef ? this.refLabel(this.currentRef) : "none — vision watcher off",
347
+ this.currentRef ? "text" : "muted",
348
+ ),
349
+ );
350
+ if (chain.length) {
351
+ out.push(...row(labels.fallback, chain.map((r) => this.refLabel(r)).join(" → ")));
352
+ }
353
+ out.push(...row(labels.thinking, this.thinking ? this.thinkingLevel : "off"));
354
+ return out;
355
+ }
356
+
357
+ /** Warnings under the list (highlighted row can't think; a refused chain add),
358
+ * the way arnative floats a warn line above its legend. */
359
+ private noteLines(width: number): string[] {
360
+ const out: string[] = [];
361
+ const highlighted = this.filteredItems[this.selectedIndex];
362
+ if (this.thinking && highlighted && !highlighted.none && !highlighted.reasoning) {
363
+ out.push(
364
+ ...wrapTextWithAnsi(
365
+ this.theme.fg(
366
+ "warning",
367
+ `Warning: ${highlighted.modelId} declares no reasoning, so thinking will be ignored`,
368
+ ),
369
+ width,
370
+ ),
371
+ );
372
+ }
373
+ if (this.notice) {
374
+ out.push(...wrapTextWithAnsi(this.theme.fg("warning", this.notice), width));
375
+ }
376
+ return out.length ? [...out, ""] : [];
377
+ }
378
+
270
379
  handleInput(data: string): void {
271
380
  const kb = getKeybindings();
272
381
 
382
+ // The filter owns the keyboard only while `/` has handed it over.
383
+ if (this.searchKey(data)) return;
384
+
273
385
  if (kb.matches(data, "tui.select.up")) {
274
386
  if (this.filteredItems.length === 0) return;
275
387
  this.selectedIndex =
@@ -331,10 +443,9 @@ export class VisionModelSelectorComponent implements Component {
331
443
  }
332
444
 
333
445
  // Space selects the highlighted model as the primary describer; pressing it
334
- // again on the same model clears it back to "None". While a filter query is
335
- // present, space is left to the search input so multi-word queries like
336
- // "gemini 3.8" stay typeable.
337
- if ((data === " " || matchesKey(data, Key.space)) && !this.searchInput.getValue()) {
446
+ // again on the same model clears it back to "None". Typing already owns the
447
+ // key (searchKey runs first), so a kept query does not steal it back.
448
+ if ((data === " " || matchesKey(data, Key.space)) && !this.typing) {
338
449
  const item = this.filteredItems[this.selectedIndex];
339
450
  if (item) this.selectPrimary(item.ref);
340
451
  return;
@@ -345,7 +456,8 @@ export class VisionModelSelectorComponent implements Component {
345
456
  // chosen together. Intercepted before the search input (like the other ctrl
346
457
  // shortcuts) so the key never lands in the filter text. See
347
458
  // {@link FALLBACK_KEY} for why it isn't ctrl+f.
348
- if (matchesKey(data, "ctrl+shift+r")) {
459
+ // `r` is Reset; `ctrl+shift+r` stays as the older chord.
460
+ if (data === "r" || data === "R" || matchesKey(data, "ctrl+shift+r")) {
349
461
  this.clearFallbacks();
350
462
  return;
351
463
  }
@@ -356,11 +468,16 @@ export class VisionModelSelectorComponent implements Component {
356
468
  return;
357
469
  }
358
470
 
359
- // alt+a on Windows/macOS, ctrl+alt+a on Linux where AltGr takes alt+a
360
- // (intl layouts: `@`, `ł`). `ctrl+a` is the editor's cursorLineStart (Home)
361
- // and GNU Screen / tmux's command prefix, so it cannot be repurposed here.
362
- // Intercepted before the search input so it never lands in the filter text.
363
- if (matchesKey(data, Key.alt("a")) || matchesKey(data, Key.ctrlAlt("a"))) {
471
+ // `a` is Async; alt+a and ctrl+alt+a stay as aliases. `ctrl+a` is the
472
+ // editor's cursorLineStart (Home) and GNU Screen / tmux's command prefix, so
473
+ // it is left alone. Intercepted before the search input so the key never
474
+ // lands in the filter text.
475
+ if (
476
+ data === "a" ||
477
+ data === "A" ||
478
+ matchesKey(data, Key.alt("a")) ||
479
+ matchesKey(data, Key.ctrlAlt("a"))
480
+ ) {
364
481
  this.asyncClipboardHandoff = !this.asyncClipboardHandoff;
365
482
  this.updateList();
366
483
  return;
@@ -376,14 +493,51 @@ export class VisionModelSelectorComponent implements Component {
376
493
  return;
377
494
  }
378
495
 
496
+ // Nothing else is a command: a stray letter must not type into a filter
497
+ // the user has not opened (that is what `/` is for).
498
+ }
499
+
500
+ /** Hand `data` to the filter while typing. Outside typing only `/` starts;
501
+ * while typing `/`, Enter and Esc stop typing and KEEP the query, so the
502
+ * rows it matched stay filtered and the commands act on them. Arrows stay
503
+ * navigation even while typing, so a match is reachable without leaving the
504
+ * field. Ctrl+C drops the query and the field together. */
505
+ private searchKey(data: string): boolean {
506
+ if (!this.typing) {
507
+ if (data !== "/") return false;
508
+ this.setTyping(true);
509
+ return true;
510
+ }
511
+ if (data === "/" || matchesKey(data, Key.enter) || matchesKey(data, Key.escape)) {
512
+ this.setTyping(false);
513
+ return true;
514
+ }
515
+ if (matchesKey(data, Key.ctrl("c"))) {
516
+ this.searchInput.setValue("");
517
+ this.setTyping(false);
518
+ this.refresh();
519
+ return true;
520
+ }
521
+ if (matchesKey(data, "up") || matchesKey(data, "down")) return false;
522
+ const before = this.searchInput.getValue();
379
523
  this.searchInput.handleInput(data);
380
- this.refresh();
524
+ if (this.searchInput.getValue() !== before) {
525
+ this.selectedIndex = 0;
526
+ this.refresh();
527
+ } else {
528
+ this.updateList();
529
+ }
530
+ return true;
531
+ }
532
+
533
+ private setTyping(typing: boolean): void {
534
+ this.typing = typing;
535
+ this.searchInput.focused = typing;
536
+ this.updateList();
381
537
  }
382
538
 
383
539
  invalidate(): void {
384
540
  this.searchInput.invalidate();
385
- this.listContainer.invalidate();
386
- this.footerText.invalidate();
387
541
  }
388
542
 
389
543
  // Internal helpers
@@ -430,32 +584,55 @@ export class VisionModelSelectorComponent implements Component {
430
584
  return [...items, ...visionModels];
431
585
  }
432
586
 
433
- private getFooterText(): string {
587
+ /** The legend, packed greedily into rows that fit the frame: a truncated
588
+ * legend advertises keys nobody can read, and a key is never worth splitting.
589
+ * The count opens the first row the way arnative prints `34/44 picked · …`.
590
+ * Toggle state sits beside the key that owns it (`[c] Session cost`), so the
591
+ * screen needs no status panel. */
592
+ private legendLines(width: number): string[] {
434
593
  const totalCount = this.allItems.length - 1; // exclude the None row
594
+ // The None row is not a model, and a filter can drop it, so count the rows
595
+ // that name one instead of subtracting a row that may not be there.
435
596
  const count = this.searchInput.getValue()
436
- ? `${this.filteredItems.length - 1} matches`
597
+ ? `${this.filteredItems.filter((i) => !i.none).length} matches`
437
598
  : `${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
599
  const confirm = keyText("tui.select.confirm");
446
- const legend = [
447
- "[↑↓] Move",
448
- `[${confirm.charAt(0).toUpperCase()}${confirm.slice(1)}] Done`,
449
- "[Space] Vision",
600
+ const keys = [
601
+ "[Space] Primary",
450
602
  "[Tab] Fallback",
451
- "[Ctrl+shift+r] Reset",
452
603
  "[Shift+tab] Think",
604
+ `${ASYNC_KEY_HINT} Async ${this.asyncClipboardHandoff ? "on" : "off"}`,
605
+ "[/] Filter",
606
+ `${RESET_KEY_HINT} Reset`,
607
+ `[${confirm.charAt(0).toUpperCase()}${confirm.slice(1)}] Save`,
453
608
  "[Esc] Cancel",
454
- ].join(" ");
609
+ ];
610
+
611
+ // The count sits in front of the first row, so the first row's budget is
612
+ // narrower than the frame by exactly that prefix.
613
+ const prefix = `${count} · `;
614
+ const rows: string[] = [];
615
+ let row = "";
616
+ for (const key of keys) {
617
+ const next = row ? `${row} ${key}` : key;
618
+ const budget = rows.length === 0 ? width - visibleWidth(prefix) : width;
619
+ if (row && visibleWidth(next) > budget) {
620
+ rows.push(row);
621
+ row = key;
622
+ } else {
623
+ row = next;
624
+ }
625
+ }
626
+ if (row) rows.push(row);
455
627
 
456
628
  // No prefix: boxRow's own pad is the one space, exactly like the providers
457
- // legend row (`│ 34/44 picked · … │`).
458
- return `${this.theme.fg("accent", count)}${this.theme.fg("dim", ` · ${legend}`)}`;
629
+ // legend row. The count takes the accent so it is the first thing the eye
630
+ // lands on; the keys stay dim so they do not compete with the list.
631
+ return rows.map((line, index) =>
632
+ index === 0
633
+ ? `${this.theme.fg("accent", count)}${this.theme.fg("dim", ` · ${line}`)}`
634
+ : this.theme.fg("dim", line),
635
+ );
459
636
  }
460
637
 
461
638
  /** Move `ref` one row up/down in the display list. The None row is pinned at
@@ -502,6 +679,30 @@ export class VisionModelSelectorComponent implements Component {
502
679
  this.updateList();
503
680
  }
504
681
 
682
+ private itemByRef(ref: string): DisplayItem | undefined {
683
+ return this.allItems.find((i) => i.ref === ref);
684
+ }
685
+
686
+ /** "Gemini 3.8 Flash (Antigravity)", or the raw ref when the model is not in
687
+ * the registry right now (stale config), so it stays visible instead of blank. */
688
+ private refLabel(ref: string): string {
689
+ const item = this.itemByRef(ref);
690
+ if (!item) return ref;
691
+ const provider = providerLabel(item.provider);
692
+ // Model display names often already carry the vendor — "Gemini 3.8 Flash
693
+ // (Antigravity)" would otherwise come out as "… (Antigravity) (Antigravity)".
694
+ return item.modelName.toLowerCase().includes(provider.toLowerCase())
695
+ ? item.modelName
696
+ : `${item.modelName} (${provider})`;
697
+ }
698
+
699
+ /** The models behind the primary, in the order they are tried. The primary is
700
+ * excluded: it is tried first, so it is not a numbered fallback even when the
701
+ * config lists it in the chain. */
702
+ private chainBehindPrimary(): string[] {
703
+ return this.orderedFallbacks().filter((r) => r !== this.currentRef);
704
+ }
705
+
505
706
  /** Fallback refs in list order (models the picker didn't show — e.g. one that
506
707
  * is no longer resolvable — are appended so a config value can't be
507
708
  * silently dropped just by opening the picker). */
@@ -530,12 +731,11 @@ export class VisionModelSelectorComponent implements Component {
530
731
  }
531
732
 
532
733
  private updateList(): void {
533
- this.listContainer.clear();
734
+ this.listEntries = [];
735
+ const chain = this.chainBehindPrimary();
534
736
 
535
737
  if (this.filteredItems.length === 0) {
536
- this.listContainer.addChild(
537
- new Text(this.theme.fg("muted", "No matching models"), 0, 0),
538
- );
738
+ this.listEntries.push({ kind: "line", text: this.theme.fg("muted", "No matching models") });
539
739
  }
540
740
 
541
741
  const startIndex = Math.max(
@@ -550,9 +750,7 @@ export class VisionModelSelectorComponent implements Component {
550
750
  // Hidden rows are announced like the providers list, never silently cut: the
551
751
  // ↑ count sits above the window, the ↓ count below it.
552
752
  if (startIndex > 0) {
553
- this.listContainer.addChild(
554
- new Text(this.theme.fg("dim", `↑ ${startIndex} more`), 0, 0),
555
- );
753
+ this.listEntries.push({ kind: "line", text: this.theme.fg("dim", `↑ ${startIndex} more`) });
556
754
  }
557
755
 
558
756
  for (let i = startIndex; i < endIndex; i++) {
@@ -561,150 +759,126 @@ export class VisionModelSelectorComponent implements Component {
561
759
 
562
760
  const isSelected = i === this.selectedIndex;
563
761
  const prefix = isSelected ? this.theme.fg("accent", "→ ") : " ";
762
+ const labelText = this.rowLabel(item);
564
763
 
565
764
  let label: string;
566
765
  if (item.none) {
567
- label = this.theme.fg("warning", item.modelName);
766
+ label = this.theme.fg("warning", labelText);
568
767
  } else {
569
768
  // Providers style: the bare `provider/id` ref, no badges — unselected
570
- // rows sit in muted, the selected row takes the soft tier in bold.
769
+ // rows sit in muted, the highlighted row takes the soft tier in bold.
770
+
771
+ // The primary keeps the accent even when it is not highlighted, so the
772
+ // picked model is visible without reading the note column.
571
773
  label = isSelected
572
- ? softPainter(this.theme, "accent", "accent")(this.theme.bold(item.ref!))
573
- : this.theme.fg("muted", item.ref!);
774
+ ? softPainter(this.theme, "accent", "accent")(this.theme.bold(labelText))
775
+ : item.ref === this.currentRef
776
+ ? this.theme.fg("accent", labelText)
777
+ : this.theme.fg("muted", labelText);
574
778
  }
575
779
 
576
- // Providers-style checkbox: the picked state is chrome, `[x]` accent / `[ ]`
577
- // dim — it replaces the old ✓ marker so the primary reads like a checked row.
578
- const marked = item.none ? this.currentRef === null : item.ref === this.currentRef;
579
- const mark = marked ? this.theme.fg("accent", "[x] ") : this.theme.fg("dim", "[ ] ");
580
-
581
- // Fallback marker — distinct from the primary's check so a model can visibly
582
- // be both the primary and a fallback (Sonnet as primary, Gemini as the
583
- // chain behind it).
584
- const fallbackMark =
585
- item.ref && this.fallbacks.has(item.ref)
586
- ? this.theme.fg("warning", " ⇆")
587
- : "";
588
-
589
- this.listContainer.addChild(new Text(`${prefix}${mark}${label}${fallbackMark}`, 0, 0));
780
+ // No checkbox: the choice is single, so the row states its role instead
781
+ // (`✓ primary`, `✓ fallback 1`) and the fact follows in parentheses.
782
+ const isPrimary = item.ref !== null && item.ref === this.currentRef;
783
+ // Numbered among the models behind the primary: the primary is tried
784
+ // first, so it is not `fallback 1` even when the config lists it first.
785
+ const chainIndex = isPrimary || !item.ref ? -1 : chain.indexOf(item.ref);
786
+ // The None row counts as picked when nothing is, so it carries the
787
+ // "(no handoff)" fact the way a picked row carries its own.
788
+ const isPicked = item.none ? this.currentRef === null : isPrimary || chainIndex >= 0;
789
+ const role = isPrimary
790
+ ? this.theme.fg("accent", "✓ primary")
791
+ : chainIndex >= 0
792
+ ? this.tone(`✓ fallback ${chainIndex + 1}`)
793
+ : null;
794
+ this.listEntries.push({
795
+ kind: "row",
796
+ prefix,
797
+ label,
798
+ labelText,
799
+ role,
800
+ // The parenthetical belongs to a picked row: on every other row it would
801
+ // repeat `(no thinking)` down the whole list.
802
+ detail: isPicked ? this.rowDetail(item, isPrimary) : null,
803
+ });
590
804
  }
591
805
 
592
806
  if (endIndex < this.filteredItems.length) {
593
- this.listContainer.addChild(
594
- new Text(this.theme.fg("dim", `↓ ${this.filteredItems.length - endIndex} more`), 0, 0),
595
- );
807
+ this.listEntries.push({
808
+ kind: "line",
809
+ text: this.theme.fg("dim", `↓ ${this.filteredItems.length - endIndex} more`),
810
+ });
596
811
  }
597
-
598
- this.footerText.setText(this.getFooterText());
599
812
  }
600
813
 
601
- private itemByRef(ref: string): DisplayItem | undefined {
602
- return this.allItems.find((i) => i.ref === ref);
814
+ /** One row, hug-style: the ref, then `✓ primary`, then `(thinking off)`.
815
+ * No column padding, so the marker sits right after the ref instead of
816
+ * drifting right with the longest ref in the registry. The fact is worth more
817
+ * than the ref tail, so a narrow frame truncates the ref first (down to 12
818
+ * columns, then drops the parenthetical, then the marker). */
819
+ private renderList(width: number): string[] {
820
+ return this.listEntries.map((entry) => {
821
+ if (entry.kind === "line") return truncateToWidth(entry.text, width, "");
822
+
823
+ const head = entry.prefix;
824
+ const fixed = visibleWidth(head);
825
+ const labelWidth = visibleWidth(entry.label);
826
+ const tail = [entry.role, entry.detail].filter(Boolean).join(" ");
827
+ const tailWidth = tail ? visibleWidth(tail) + 1 : 0;
828
+
829
+ // Everything fits: ref, role, fact.
830
+ if (fixed + labelWidth + tailWidth <= width) {
831
+ return truncateToWidth(`${head}${entry.label}${tail ? ` ${tail}` : ""}`, width, "");
832
+ }
833
+ // Keep the role and the fact, cut the ref tail.
834
+ if (tail && width - fixed - tailWidth >= 12) {
835
+ const shown = truncateToWidth(entry.label, width - fixed - tailWidth, "…");
836
+ return `${head}${shown} ${tail}`;
837
+ }
838
+ // Keep the role only.
839
+ const roleWidth = entry.role ? visibleWidth(entry.role) + 1 : 0;
840
+ if (entry.role && width - fixed - roleWidth >= 12) {
841
+ const shown = truncateToWidth(entry.label, width - fixed - roleWidth, "…");
842
+ return `${head}${shown} ${entry.role}`;
843
+ }
844
+ return truncateToWidth(`${head}${entry.label}${entry.role ? ` ${entry.role}` : ""}`, width, "");
845
+ });
603
846
  }
604
847
 
605
- /** "Gemini 3.8 Flash (Antigravity)", or the raw ref when it isn't in the
606
- * registry right now (stale config) so it stays visible instead of blank. */
607
- private refLabel(ref: string): string {
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})`;
848
+ /** The plain label a row renders before paint and padding. */
849
+ private rowLabel(item: DisplayItem): string {
850
+ return item.none ? "None" : item.ref!;
616
851
  }
617
852
 
618
- /** The detail pane summarises the *configuration* (primary, failover chain
619
- * and toggles) rather than the highlighted row, so each space / tab
620
- * press shows exactly what will be saved.
621
- *
622
- * Built per frame rather than cached in a child component because the
623
- * label/value split only pays off once the width is known: a long fallback
624
- * chain then wraps under its own value instead of spilling to column 0. */
625
- private detailLines(width: number): string[] {
626
- const out: string[] = [];
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
- );
853
+ /** What the row means right now, in the note column: its role (primary, chain
854
+ * position) and whether thinking can do anything for it. Both are facts an
855
+ * arnative row would state instead of hiding in a side panel. */
856
+ /** The fact in parentheses after the role. It belongs to the primary (the
857
+ * model that will actually be asked) and to any model that cannot think at
858
+ * all, so the row says that without opening a detail panel. */
859
+ private rowDetail(item: DisplayItem, isPrimary: boolean): string | null {
860
+ if (item.none) {
861
+ return this.currentRef === null ? this.theme.fg("dim", "(no handoff)") : null;
703
862
  }
863
+ const fact = !item.reasoning
864
+ ? "no thinking"
865
+ : isPrimary
866
+ ? this.thinking
867
+ ? `thinking ${this.thinkingLevel}`
868
+ : "thinking off"
869
+ : null;
870
+ return fact ? this.theme.fg("dim", `(${fact})`) : null;
871
+ }
704
872
 
705
- if (this.notice) note(this.theme.fg("warning", ` ${this.notice}`));
706
-
707
- return out;
873
+ /** The arnative primary tone for a chain marker. pi's theme tokens have no
874
+ * `primary` slot, so use the theme's own when it declares one and fall back
875
+ * to `warning`, the same warm hue in every built-in theme. */
876
+ private tone(text: string): string {
877
+ try {
878
+ return this.theme.fg("primary" as ThemeColor, text);
879
+ } catch {
880
+ return this.theme.fg("warning", text);
881
+ }
708
882
  }
709
883
 
710
884
  private save(): void {