@bismawy/pi-vision-watcher 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +5 -4
- package/package.json +1 -1
- package/src/dataloader.ts +389 -389
- package/src/describer.ts +459 -561
- package/src/vision-model-selector.ts +123 -68
- package/vision-watcher.ts +1 -0
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* - Lists connected (authenticated) models, vision-capable ones first (✦ badge)
|
|
7
7
|
* - A leading "None" row clears the configured vision model
|
|
8
8
|
* - Space selects the highlighted model as the primary describer (toggle)
|
|
9
|
-
* -
|
|
10
|
-
* - Ctrl+Shift+R clears the failover chain,
|
|
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
13
|
* - The primary is marked ✓, chain members ⇆
|
|
@@ -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 {
|
|
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
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
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 =
|
|
53
|
-
const FALLBACK_KEY_HINT = "
|
|
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(
|
|
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(
|
|
@@ -221,8 +268,7 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
221
268
|
lines.push(...this.detailLines(width));
|
|
222
269
|
lines.push("");
|
|
223
270
|
lines.push(...this.footerText.render(width));
|
|
224
|
-
lines
|
|
225
|
-
return lines.map((line) => truncateToWidth(line, width, ""));
|
|
271
|
+
return lines;
|
|
226
272
|
}
|
|
227
273
|
|
|
228
274
|
handleInput(data: string): void {
|
|
@@ -324,12 +370,11 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
324
370
|
return;
|
|
325
371
|
}
|
|
326
372
|
|
|
327
|
-
//
|
|
328
|
-
//
|
|
329
|
-
//
|
|
330
|
-
//
|
|
331
|
-
|
|
332
|
-
if (matchesKey(data, Key.ctrlShift("t"))) {
|
|
373
|
+
// shift+tab walks the whole thinking ladder (off, minimal ... max, off). It is one
|
|
374
|
+
// sequence (ESC [ Z) on every terminal and is pi's own app.thinking.cycle, so the
|
|
375
|
+
// meaning carries over. ctrl+shift+t opened a new tab in Windows Terminal and GNOME
|
|
376
|
+
// Terminal and is pi's app.session.tree. Intercepted before the search input.
|
|
377
|
+
if (matchesKey(data, "shift+tab")) {
|
|
333
378
|
this.cycleThinking();
|
|
334
379
|
this.updateList();
|
|
335
380
|
return;
|
|
@@ -397,16 +442,18 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
397
442
|
|
|
398
443
|
// One legend line: the count carries the accent colour so it is the first
|
|
399
444
|
// thing the eye lands on, while the keys stay dim so they do not compete
|
|
400
|
-
// with the picker itself. The chords need roughly
|
|
401
|
-
// gracefully; the async
|
|
402
|
-
//
|
|
445
|
+
// with the picker itself. The chords need roughly 130 columns, which wraps
|
|
446
|
+
// gracefully; the async chord is hinted beside the state it toggles (and in
|
|
447
|
+
// the README) instead of bloating this strip. `Move` is the highlight, not
|
|
448
|
+
// the row: reordering is `alt+↑↓` and lives in the README.
|
|
403
449
|
const confirm = keyText("tui.select.confirm");
|
|
404
450
|
const legend = [
|
|
451
|
+
"[↑↓] Move",
|
|
405
452
|
`[${confirm.charAt(0).toUpperCase()}${confirm.slice(1)}] Done`,
|
|
406
453
|
"[Space] Vision",
|
|
407
|
-
"[
|
|
454
|
+
"[Tab] Fallback",
|
|
408
455
|
"[Ctrl+shift+r] Reset",
|
|
409
|
-
"[
|
|
456
|
+
"[Shift+tab] Think",
|
|
410
457
|
"[Esc] Cancel",
|
|
411
458
|
].join(" ");
|
|
412
459
|
|
|
@@ -514,7 +561,7 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
514
561
|
label = this.theme.fg("warning", item.modelName);
|
|
515
562
|
} else {
|
|
516
563
|
const labelled = isSelected
|
|
517
|
-
? this.theme
|
|
564
|
+
? softPainter(this.theme, "accent", "accent")(this.theme.bold(item.modelId))
|
|
518
565
|
: item.modelId;
|
|
519
566
|
const badge = item.vision ? this.theme.fg("success", " ✦") : this.theme.fg("muted", " ·");
|
|
520
567
|
const providerBadge = this.theme.fg("muted", ` [${item.provider}]`);
|
|
@@ -567,7 +614,7 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
567
614
|
}
|
|
568
615
|
|
|
569
616
|
/** The detail pane summarises the *configuration* (primary, failover chain
|
|
570
|
-
* and toggles) rather than the highlighted row, so each space /
|
|
617
|
+
* and toggles) rather than the highlighted row, so each space / tab
|
|
571
618
|
* press shows exactly what will be saved.
|
|
572
619
|
*
|
|
573
620
|
* Built per frame rather than cached in a child component because the
|
|
@@ -576,26 +623,33 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
576
623
|
private detailLines(width: number): string[] {
|
|
577
624
|
const out: string[] = [];
|
|
578
625
|
|
|
579
|
-
//
|
|
580
|
-
//
|
|
581
|
-
//
|
|
582
|
-
//
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
626
|
+
// Arnative status-panel rows: `Label · STATUS | detail`, the label column
|
|
627
|
+
// padded to the widest label so every `·` divider sits in one column, one
|
|
628
|
+
// status word per row (success = on, muted = off). A long detail wraps
|
|
629
|
+
// under its own value column instead of spilling to column 0.
|
|
630
|
+
const labels = {
|
|
631
|
+
vision: " Vision-capable ✦",
|
|
632
|
+
fallback: " Fallback ⇆",
|
|
633
|
+
thinking: " Thinking",
|
|
634
|
+
async: " Async pasted-path fallback",
|
|
635
|
+
};
|
|
636
|
+
const col = Math.max(...Object.values(labels).map((l) => visibleWidth(l)));
|
|
637
|
+
|
|
638
|
+
const row = (labelText: string, status: string, color: ThemeColor, detail: string) => {
|
|
639
|
+
const head =
|
|
640
|
+
this.theme.fg("dim", labelText) +
|
|
641
|
+
" ".repeat(col - visibleWidth(labelText)) +
|
|
642
|
+
this.theme.fg("dim", " · ") +
|
|
643
|
+
this.theme.fg(color, status);
|
|
644
|
+
// Continuations clear the " | " separator so they line up with the detail.
|
|
645
|
+
const indent = " ".repeat(visibleWidth(head) + 3);
|
|
646
|
+
const wrapped = wrapTextWithAnsi(detail, Math.max(8, width - indent.length));
|
|
647
|
+
out.push(`${head}${detail ? this.theme.fg("dim", " | ") + (wrapped[0] ?? "") : ""}`);
|
|
594
648
|
for (const extra of wrapped.slice(1)) out.push(indent + extra);
|
|
595
649
|
};
|
|
596
650
|
|
|
597
651
|
// Free-standing sentence (warning / transient notice), hanging-indented
|
|
598
|
-
// under its own
|
|
652
|
+
// under its own first word.
|
|
599
653
|
const note = (text: string) => {
|
|
600
654
|
const indent = " ";
|
|
601
655
|
wrapTextWithAnsi(text, Math.max(8, width - indent.length)).forEach(
|
|
@@ -603,34 +657,35 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
603
657
|
);
|
|
604
658
|
};
|
|
605
659
|
|
|
606
|
-
|
|
607
|
-
|
|
660
|
+
row(
|
|
661
|
+
labels.vision,
|
|
662
|
+
this.currentRef ? "ON" : "OFF",
|
|
663
|
+
this.currentRef ? "success" : "muted",
|
|
608
664
|
this.currentRef
|
|
609
665
|
? this.refLabel(this.currentRef)
|
|
610
666
|
: this.theme.fg("muted", "none — vision watcher disabled"),
|
|
611
667
|
);
|
|
612
668
|
|
|
613
669
|
const chain = this.orderedFallbacks();
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
chain.length
|
|
617
|
-
|
|
618
|
-
|
|
670
|
+
row(
|
|
671
|
+
labels.fallback,
|
|
672
|
+
chain.length ? "ON" : "OFF",
|
|
673
|
+
chain.length ? "success" : "muted",
|
|
674
|
+
chain.length ? `${chain.map((r) => this.refLabel(r)).join(" → ")} (max ${MAX_FALLBACKS})` : "",
|
|
619
675
|
);
|
|
620
676
|
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
this.thinking
|
|
624
|
-
|
|
625
|
-
|
|
677
|
+
row(
|
|
678
|
+
labels.thinking,
|
|
679
|
+
this.thinking ? "ON" : "OFF",
|
|
680
|
+
this.thinking ? "success" : "muted",
|
|
681
|
+
this.thinking ? this.thinkingLevel : "",
|
|
626
682
|
);
|
|
627
683
|
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
)}${this.theme.fg("dim", ` ${ASYNC_KEY_HINT}`)}`,
|
|
684
|
+
row(
|
|
685
|
+
labels.async,
|
|
686
|
+
this.asyncClipboardHandoff ? "ON" : "OFF",
|
|
687
|
+
this.asyncClipboardHandoff ? "success" : "muted",
|
|
688
|
+
ASYNC_KEY_HINT,
|
|
634
689
|
);
|
|
635
690
|
|
|
636
691
|
// The warning follows the *highlighted* row: it answers "what happens if I
|
|
@@ -640,7 +695,7 @@ export class VisionModelSelectorComponent implements Component {
|
|
|
640
695
|
note(
|
|
641
696
|
this.theme.fg(
|
|
642
697
|
"warning",
|
|
643
|
-
`
|
|
698
|
+
` Warning: ${highlighted.modelId} declares no reasoning — thinking will be ignored`,
|
|
644
699
|
),
|
|
645
700
|
);
|
|
646
701
|
}
|
package/vision-watcher.ts
CHANGED