@bismawy/pi-vision-watcher 1.1.0 → 1.3.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.
@@ -3,14 +3,14 @@
3
3
  * describes images during vision handoff.
4
4
  *
5
5
  * Uses the same patterns as pi's built-in selectors and pi-hide-providers:
6
- * - Lists connected (authenticated) models, vision-capable ones first (✦ badge)
6
+ * - Lists connected (authenticated) vision-capable models as bare `provider/id` refs
7
7
  * - A leading "None" row clears the configured vision model
8
8
  * - Space selects the highlighted model as the primary describer (toggle)
9
- * - Ctrl+Enter toggles the highlighted model in/out of the failover chain (max 3)
10
- * - Ctrl+Shift+R clears the failover chain, Ctrl+Shift+T walks the thinking ladder,
9
+ * - Tab toggles the highlighted model in/out of the failover chain (max 3)
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 marked ✓, chain members ⇆
13
+ * - The primary is the checked row [x], chain members ⇆ (providers style)
14
14
  */
15
15
 
16
16
  import {
@@ -28,20 +28,57 @@ import {
28
28
  } from "@earendil-works/pi-tui";
29
29
  import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
30
30
  import type { ThinkingLevel } from "@earendil-works/pi-ai";
31
- import { DynamicBorder, keyText } from "@earendil-works/pi-coding-agent";
31
+ import { keyText } from "@earendil-works/pi-coding-agent";
32
32
  import { formatModelRef, isVisionModel, 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. */
36
36
  export const MAX_FALLBACKS = 3;
37
37
 
38
+ type OklchLike = { kind?: string; l?: number; c?: number; h?: number };
39
+ type ThemeLike = Pick<Theme, "fg" | "bold"> & {
40
+ colors?: Readonly<Record<string, OklchLike>>;
41
+ style?(text: string, options: { fg: OklchLike }): string;
42
+ };
43
+
44
+ // pi >=1.2 rejects custom theme tokens (accentSoft), so the arnative soft tier is
45
+ // derived from an official token with the theme generator's recipe: L 0.82,
46
+ // chroma x 0.18, hue kept. Older runtimes without colors/style keep fallback.
47
+ const SOFT_L = 0.82;
48
+ const SOFT_CHROMA_SCALE = 0.18;
49
+
50
+ export function softPainter(th: ThemeLike, base: ThemeColor, fallback: ThemeColor): (text: string) => string {
51
+ const style = th.style?.bind(th);
52
+ const declared = th.colors?.accentSoft;
53
+ if (style && declared?.kind === "oklch") return (t) => style(t, { fg: declared });
54
+ const c = th.colors?.[base];
55
+ if (style && c?.kind === "oklch") {
56
+ const fg = { kind: "oklch", l: SOFT_L, c: (c.c ?? 0) * SOFT_CHROMA_SCALE, h: c.h ?? 0 };
57
+ return (t) => style(t, { fg });
58
+ }
59
+ return (t) => th.fg(fallback, t);
60
+ }
61
+
62
+ export function boxEdge(left: string, right: string, width: number, paint: (s: string) => string): string {
63
+ return width < 2 ? "" : paint(left + "─".repeat(width - 2) + right);
64
+ }
65
+
66
+ // Truncate before wrapping so a long row never pushes the right wall out of the frame.
67
+ export function boxRow(content: string, width: number, paint: (s: string) => string): string {
68
+ if (width < 4) return "";
69
+ const inner = truncateToWidth(content, width - 4, "");
70
+ const pad = " ".repeat(Math.max(0, width - 4 - visibleWidth(inner)));
71
+ return paint("│") + " " + inner + pad + " " + paint("│");
72
+ }
73
+
38
74
  /** Key that toggles failover-chain membership.
39
75
  *
40
- * `ctrl+enter` is the one chord that survives Windows conhost/Windows Terminal,
41
- * Linux/X11, macOS, tmux and SSH alike. The previous binding was `ctrl+q`, which
42
- * collides with POSIX tty flow control (IXON: ctrl+s freezes / ctrl+q resumes
43
- * output before the app sees it), with pi's own `app.message.followUp`, and —
44
- * for the reset chord — with VTE's window-level "close terminal" accelerator.
76
+ * Tab is one byte (0x09) on every terminal and OS, and no terminal, window manager
77
+ * or multiplexer binds it. The search input has no Tab handler, and this chord is
78
+ * intercepted before the input. ctrl+enter (1.1.0) maximises the window in some
79
+ * terminals, and without the kitty keyboard protocol it cannot be told from enter.
80
+ * ctrl+f is Search in herdr. The older ctrl+q hit POSIX tty flow control (IXON)
81
+ * and pi's app.message.followUp; ctrl+shift+q hit VTE's close-terminal accelerator.
45
82
  *
46
83
  * Reset uses `ctrl+shift+r` because R reads as Reset. It is unbound in every
47
84
  * default terminal (VTE, Konsole, Windows Terminal, iTerm2 — kitty is the lone
@@ -49,8 +86,8 @@ export const MAX_FALLBACKS = 3;
49
86
  * 7-bit terminals it degrades to plain `ctrl+r`, which the app does not use, so
50
87
  * the worst case is a no-op rather than a wrong action. The old `ctrl+shift+q`
51
88
  * was impossible to type on those terminals: both it and `ctrl+q` emit 0x11. */
52
- const FALLBACK_KEY = Key.ctrl("enter");
53
- const FALLBACK_KEY_HINT = "ctrl+enter";
89
+ const FALLBACK_KEY = "tab";
90
+ const FALLBACK_KEY_HINT = "tab";
54
91
  const REORDER_UP_KEY = Key.alt("up");
55
92
  const REORDER_DOWN_KEY = Key.alt("down");
56
93
  /** Hint printed next to the async toggle in the detail pane (and the legend).
@@ -116,6 +153,8 @@ export interface VisionModelSelectorResult {
116
153
  }
117
154
 
118
155
  export class VisionModelSelectorComponent implements Component {
156
+ /** Session thinking level; the frame follows it like Pi's own editor border. */
157
+ private readonly borderLevel?: Parameters<Theme["getThinkingBorderColor"]>[0];
119
158
  private theme: Theme;
120
159
  private done: (result: VisionModelSelectorResult) => void;
121
160
 
@@ -160,7 +199,9 @@ export class VisionModelSelectorComponent implements Component {
160
199
  currentAsyncClipboardHandoff: boolean,
161
200
  done: (result: VisionModelSelectorResult) => void,
162
201
  currentFallbacks: string[] = [],
202
+ borderLevel?: Parameters<Theme["getThinkingBorderColor"]>[0],
163
203
  ) {
204
+ this.borderLevel = borderLevel;
164
205
  this.theme = theme;
165
206
  this.done = done;
166
207
  this.currentRef = currentRef;
@@ -189,15 +230,21 @@ export class VisionModelSelectorComponent implements Component {
189
230
  }
190
231
 
191
232
  render(width: number): string[] {
233
+ // The user asked for the frame to follow the session thinking level, like Pi's editor border;
234
+ // the soft tier only applies when no level or no thinking-border API is available.
235
+ const thinkingBorder = this.borderLevel ? this.theme.getThinkingBorderColor?.(this.borderLevel) : undefined;
236
+ const border = thinkingBorder ?? softPainter(this.theme, "borderAccent", "accent");
237
+ const body = this.bodyLines(Math.max(1, width - 4)).flatMap((line) => line.split("\n"));
238
+ return [
239
+ boxEdge("╭", "╮", width, border),
240
+ ...body.map((line) => boxRow(line, width, border)),
241
+ boxEdge("╰", "╯", width, border),
242
+ ];
243
+ }
244
+
245
+ private bodyLines(width: number): string[] {
192
246
  const lines: string[] = [];
193
- lines.push(...new DynamicBorder((s) => this.theme.fg("accent", s)).render(width));
194
- lines.push(
195
- truncateToWidth(
196
- this.theme.fg("accent", this.theme.bold("Vision Watcher")),
197
- width,
198
- "",
199
- ),
200
- );
247
+ lines.push(this.theme.fg("accent", this.theme.bold("Vision Watcher")));
201
248
  lines.push(
202
249
  ...wrapTextWithAnsi(
203
250
  this.theme.fg(
@@ -208,21 +255,16 @@ export class VisionModelSelectorComponent implements Component {
208
255
  ),
209
256
  );
210
257
  lines.push("");
211
- // Indented to the list's two-column gutter: at column 0 the field reads as
212
- // a stray line rather than as the thing the list is filtered by.
213
- lines.push(
214
- ...this.searchInput
215
- .render(Math.max(1, width - 2))
216
- .map((line) => ` ${line}`),
217
- );
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)));
218
261
  lines.push("");
219
262
  lines.push(...this.listContainer.render(width));
220
263
  lines.push("");
221
264
  lines.push(...this.detailLines(width));
222
265
  lines.push("");
223
266
  lines.push(...this.footerText.render(width));
224
- lines.push(...new DynamicBorder((s) => this.theme.fg("accent", s)).render(width));
225
- return lines.map((line) => truncateToWidth(line, width, ""));
267
+ return lines;
226
268
  }
227
269
 
228
270
  handleInput(data: string): void {
@@ -324,12 +366,11 @@ export class VisionModelSelectorComponent implements Component {
324
366
  return;
325
367
  }
326
368
 
327
- // ctrl+t walks the whole thinking ladder (off → minimal → … → max → off) so
328
- // one key covers on/off *and* effort — no separate shift+tab binding.
329
- // Intercepted before the search input so it never lands in the filter text.
330
- // `ctrl+t` is readline transpose-chars and pi's app.thinking.toggle (tool
331
- // output); the ladder gets its own chord instead so both stay usable.
332
- if (matchesKey(data, Key.ctrlShift("t"))) {
369
+ // shift+tab walks the whole thinking ladder (off, minimal ... max, off). It is one
370
+ // sequence (ESC [ Z) on every terminal and is pi's own app.thinking.cycle, so the
371
+ // meaning carries over. ctrl+shift+t opened a new tab in Windows Terminal and GNOME
372
+ // Terminal and is pi's app.session.tree. Intercepted before the search input.
373
+ if (matchesKey(data, "shift+tab")) {
333
374
  this.cycleThinking();
334
375
  this.updateList();
335
376
  return;
@@ -397,20 +438,24 @@ export class VisionModelSelectorComponent implements Component {
397
438
 
398
439
  // One legend line: the count carries the accent colour so it is the first
399
440
  // thing the eye lands on, while the keys stay dim so they do not compete
400
- // with the picker itself. The chords need roughly 120 columns, which wraps
401
- // gracefully; the async and reorder keys are hinted beside the state they
402
- // toggle (and in the README) instead of bloating this strip.
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.
403
445
  const confirm = keyText("tui.select.confirm");
404
446
  const legend = [
447
+ "[↑↓] Move",
405
448
  `[${confirm.charAt(0).toUpperCase()}${confirm.slice(1)}] Done`,
406
449
  "[Space] Vision",
407
- "[Ctrl+enter] Fallback",
450
+ "[Tab] Fallback",
408
451
  "[Ctrl+shift+r] Reset",
409
- "[Ctrl+shift+t] Think",
452
+ "[Shift+tab] Think",
410
453
  "[Esc] Cancel",
411
454
  ].join(" ");
412
455
 
413
- return `${this.theme.fg("dim", " ")}${this.theme.fg("accent", count)}${this.theme.fg("dim", ` · ${legend}`)}`;
456
+ // 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}`)}`;
414
459
  }
415
460
 
416
461
  /** Move `ref` one row up/down in the display list. The None row is pinned at
@@ -489,7 +534,7 @@ export class VisionModelSelectorComponent implements Component {
489
534
 
490
535
  if (this.filteredItems.length === 0) {
491
536
  this.listContainer.addChild(
492
- new Text(this.theme.fg("muted", " No matching models"), 0, 0),
537
+ new Text(this.theme.fg("muted", "No matching models"), 0, 0),
493
538
  );
494
539
  }
495
540
 
@@ -502,6 +547,14 @@ export class VisionModelSelectorComponent implements Component {
502
547
  );
503
548
  const endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);
504
549
 
550
+ // Hidden rows are announced like the providers list, never silently cut: the
551
+ // ↑ count sits above the window, the ↓ count below it.
552
+ if (startIndex > 0) {
553
+ this.listContainer.addChild(
554
+ new Text(this.theme.fg("dim", `↑ ${startIndex} more`), 0, 0),
555
+ );
556
+ }
557
+
505
558
  for (let i = startIndex; i < endIndex; i++) {
506
559
  const item = this.filteredItems[i];
507
560
  if (!item) continue;
@@ -513,20 +566,19 @@ export class VisionModelSelectorComponent implements Component {
513
566
  if (item.none) {
514
567
  label = this.theme.fg("warning", item.modelName);
515
568
  } else {
516
- const labelled = isSelected
517
- ? this.theme.fg("accent", item.modelId)
518
- : item.modelId;
519
- const badge = item.vision ? this.theme.fg("success", " ✦") : this.theme.fg("muted", " ·");
520
- const providerBadge = this.theme.fg("muted", ` [${item.provider}]`);
521
- label = `${labelled}${providerBadge}${badge}`;
569
+ // Providers style: the bare `provider/id` ref, no badges — unselected
570
+ // rows sit in muted, the selected row takes the soft tier in bold.
571
+ label = isSelected
572
+ ? softPainter(this.theme, "accent", "accent")(this.theme.bold(item.ref!))
573
+ : this.theme.fg("muted", item.ref!);
522
574
  }
523
575
 
524
- const current = item.ref === this.currentRef && item.ref !== null
525
- ? this.theme.fg("success", " ✓")
526
- : item.none && this.currentRef === null
527
- ? this.theme.fg("success", " ✓")
528
- : "";
529
- // Fallback marker — distinct from the primary's ✓ so a model can visibly
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
530
582
  // be both the primary and a fallback (Sonnet as primary, Gemini as the
531
583
  // chain behind it).
532
584
  const fallbackMark =
@@ -534,15 +586,12 @@ export class VisionModelSelectorComponent implements Component {
534
586
  ? this.theme.fg("warning", " ⇆")
535
587
  : "";
536
588
 
537
- this.listContainer.addChild(new Text(`${prefix}${label}${current}${fallbackMark}`, 0, 0));
589
+ this.listContainer.addChild(new Text(`${prefix}${mark}${label}${fallbackMark}`, 0, 0));
538
590
  }
539
591
 
540
- if (startIndex > 0 || endIndex < this.filteredItems.length) {
592
+ if (endIndex < this.filteredItems.length) {
541
593
  this.listContainer.addChild(
542
- new Text(
543
- this.theme.fg("muted", ` (${this.selectedIndex + 1}/${this.filteredItems.length})`),
544
- 0, 0,
545
- ),
594
+ new Text(this.theme.fg("dim", `↓ ${this.filteredItems.length - endIndex} more`), 0, 0),
546
595
  );
547
596
  }
548
597
 
@@ -567,7 +616,7 @@ export class VisionModelSelectorComponent implements Component {
567
616
  }
568
617
 
569
618
  /** The detail pane summarises the *configuration* (primary, failover chain
570
- * and toggles) rather than the highlighted row, so each space / ctrl+enter
619
+ * and toggles) rather than the highlighted row, so each space / tab
571
620
  * press shows exactly what will be saved.
572
621
  *
573
622
  * Built per frame rather than cached in a child component because the
@@ -576,26 +625,33 @@ export class VisionModelSelectorComponent implements Component {
576
625
  private detailLines(width: number): string[] {
577
626
  const out: string[] = [];
578
627
 
579
- // The label — including the symbol, when it has one — wears the same
580
- // colour as the badge/marker it explains, so the two read as one legend
581
- // instead of as prose that happens to contain a glyph. The space before
582
- // `:` keeps the dim label and the symbol grid aligned with the labels
583
- // below (`Thinking:`, `Async …:`) which have no symbol.
584
- const label = (text: string, symbol: string, color: ThemeColor) =>
585
- `${this.theme.fg("dim", ` ${text} `)}${this.theme.fg(color, symbol)}${this.theme.fg("dim", " : ")}`;
586
-
587
- const value = (labelText: string, text: string) => {
588
- const indent = " ".repeat(2 + visibleWidth(labelText));
589
- const wrapped = wrapTextWithAnsi(
590
- text,
591
- Math.max(8, width - visibleWidth(indent)),
592
- );
593
- out.push(`${labelText}${wrapped[0] ?? ""}`);
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] ?? "") : ""}`);
594
650
  for (const extra of wrapped.slice(1)) out.push(indent + extra);
595
651
  };
596
652
 
597
653
  // Free-standing sentence (warning / transient notice), hanging-indented
598
- // under its own `⚠`/first word.
654
+ // under its own first word.
599
655
  const note = (text: string) => {
600
656
  const indent = " ";
601
657
  wrapTextWithAnsi(text, Math.max(8, width - indent.length)).forEach(
@@ -603,34 +659,35 @@ export class VisionModelSelectorComponent implements Component {
603
659
  );
604
660
  };
605
661
 
606
- value(
607
- label("Vision-capable", "✦", "success"),
662
+ row(
663
+ labels.vision,
664
+ this.currentRef ? "ON" : "OFF",
665
+ this.currentRef ? "success" : "muted",
608
666
  this.currentRef
609
667
  ? this.refLabel(this.currentRef)
610
668
  : this.theme.fg("muted", "none — vision watcher disabled"),
611
669
  );
612
670
 
613
671
  const chain = this.orderedFallbacks();
614
- value(
615
- label("Fallback", "⇆", "warning"),
616
- chain.length
617
- ? `${this.theme.fg("success", "on")} - ${chain.map((r) => this.refLabel(r)).join(", ")}`
618
- : this.theme.fg("muted", "off"),
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})` : "",
619
677
  );
620
678
 
621
- value(
622
- this.theme.fg("dim", " Thinking: "),
623
- this.thinking
624
- ? this.theme.fg("success", `on (${this.thinkingLevel})`)
625
- : this.theme.fg("muted", "off"),
679
+ row(
680
+ labels.thinking,
681
+ this.thinking ? "ON" : "OFF",
682
+ this.thinking ? "success" : "muted",
683
+ this.thinking ? this.thinkingLevel : "",
626
684
  );
627
685
 
628
- value(
629
- this.theme.fg("dim", " Async pasted-path fallback: "),
630
- `${this.theme.fg(
631
- this.asyncClipboardHandoff ? "success" : "muted",
632
- this.asyncClipboardHandoff ? "on" : "off",
633
- )}${this.theme.fg("dim", ` ${ASYNC_KEY_HINT}`)}`,
686
+ row(
687
+ labels.async,
688
+ this.asyncClipboardHandoff ? "ON" : "OFF",
689
+ this.asyncClipboardHandoff ? "success" : "muted",
690
+ ASYNC_KEY_HINT,
634
691
  );
635
692
 
636
693
  // The warning follows the *highlighted* row: it answers "what happens if I
@@ -640,7 +697,7 @@ export class VisionModelSelectorComponent implements Component {
640
697
  note(
641
698
  this.theme.fg(
642
699
  "warning",
643
- ` ⚠ ${highlighted.modelId} declares no reasoning — thinking will be ignored`,
700
+ ` Warning: ${highlighted.modelId} declares no reasoning — thinking will be ignored`,
644
701
  ),
645
702
  );
646
703
  }
package/vision-watcher.ts CHANGED
@@ -1233,6 +1233,7 @@ async function showSelector(ctx: ExtensionCommandContext): Promise<void> {
1233
1233
  config.asyncClipboardHandoff,
1234
1234
  (r) => done(r),
1235
1235
  config.fallbackModels,
1236
+ ctx.thinkingLevel,
1236
1237
  );
1237
1238
  return {
1238
1239
  render(width: number) {