@linxiraos/pi-tui 1.4.13 → 1.5.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 +33 -34
- package/dist/types/chat/messages.d.ts +2 -0
- package/dist/types/chat/spotlight.d.ts +8 -3
- package/dist/types/chat/transcript-render-helpers.d.ts +5 -0
- package/dist/types/components/editor.d.ts +4 -1
- package/dist/types/html-form/data.d.ts +56 -0
- package/dist/types/html-form/dialog.d.ts +51 -0
- package/dist/types/html-form/media.d.ts +28 -0
- package/dist/types/html-form/paginate.d.ts +43 -0
- package/dist/types/html-form/parse.d.ts +99 -0
- package/dist/types/overlays/ask-dialog.d.ts +11 -6
- package/dist/types/overlays/copy-targets.d.ts +8 -6
- package/dist/types/overlays/directory-picker.d.ts +62 -0
- package/dist/types/overlays/hook-editor.d.ts +3 -1
- package/dist/types/overlays/hub-frame.d.ts +2 -0
- package/dist/types/overlays/model-hub.d.ts +2 -0
- package/dist/types/overlays/team-hub.d.ts +150 -0
- package/dist/types/render/row-moves.d.ts +41 -0
- package/dist/types/status-line/component.d.ts +5 -0
- package/dist/types/status-line/host.d.ts +2 -2
- package/dist/types/status-line/schema.d.ts +1 -1
- package/dist/types/status-line/types.d.ts +8 -0
- package/dist/types/tools/ask.d.ts +11 -49
- package/dist/types/tools/autoresearch.d.ts +2 -2
- package/dist/types/tools/eval.d.ts +4 -0
- package/dist/types/tools/grouped-file-output.d.ts +2 -0
- package/dist/types/tools/shell-viz.d.ts +6 -2
- package/dist/types/tools/xd-url.d.ts +6 -0
- package/dist/types/windows-input-mode.d.ts +8 -0
- package/package.json +9 -9
- package/src/charts/table-data.ts +18 -5
- package/src/chat/chat-transcript-builder.ts +27 -10
- package/src/chat/image-loading.ts +55 -0
- package/src/chat/messages.d.ts +2 -0
- package/src/chat/messages.ts +3 -0
- package/src/chat/spotlight.d.ts +8 -3
- package/src/chat/spotlight.ts +23 -11
- package/src/chat/tool-execution.ts +5 -0
- package/src/chat/transcript-render-helpers.d.ts +5 -0
- package/src/chat/transcript-render-helpers.ts +13 -0
- package/src/chrome/transcript-container.ts +1 -1
- package/src/components/editor.d.ts +4 -1
- package/src/components/editor.ts +3 -2
- package/src/components/markdown.ts +70 -12
- package/src/html-form/data.d.ts +56 -0
- package/src/html-form/data.ts +177 -0
- package/src/html-form/dialog.ts +1450 -0
- package/src/html-form/media.ts +105 -0
- package/src/html-form/paginate.ts +99 -0
- package/src/html-form/parse.d.ts +99 -0
- package/src/html-form/parse.ts +568 -0
- package/src/lang-from-path.ts +1 -0
- package/src/latex-block.ts +3 -3
- package/src/latex-to-unicode.ts +18 -5
- package/src/overlays/ask-dialog.ts +69 -52
- package/src/overlays/copy-targets.d.ts +8 -6
- package/src/overlays/copy-targets.ts +25 -46
- package/src/overlays/directory-picker.ts +387 -0
- package/src/overlays/hook-editor.ts +16 -15
- package/src/overlays/hub-frame.ts +8 -1
- package/src/overlays/model-hub.ts +12 -2
- package/src/overlays/spotlight-sheet.ts +18 -18
- package/src/overlays/team-hub.ts +901 -0
- package/src/render/row-moves.d.ts +41 -0
- package/src/render/row-moves.ts +109 -0
- package/src/setup/wizard-overlay.ts +7 -3
- package/src/status-line/component.ts +19 -0
- package/src/status-line/footer.ts +2 -2
- package/src/status-line/host.ts +2 -2
- package/src/status-line/presets.ts +6 -6
- package/src/status-line/schema.ts +2 -1
- package/src/status-line/segments.ts +31 -4
- package/src/status-line/startup.ts +1 -1
- package/src/status-line/types.ts +8 -0
- package/src/stdin-buffer.ts +15 -1
- package/src/terminal-capabilities.ts +12 -3
- package/src/terminal.ts +41 -3
- package/src/tools/ask.d.ts +11 -49
- package/src/tools/ask.ts +201 -606
- package/src/tools/autoresearch.ts +2 -2
- package/src/tools/debug.ts +31 -38
- package/src/tools/eval.d.ts +4 -0
- package/src/tools/eval.ts +4 -0
- package/src/tools/grep.ts +38 -16
- package/src/tools/grouped-file-output.d.ts +2 -0
- package/src/tools/grouped-file-output.ts +5 -0
- package/src/tools/shell-viz-render.ts +37 -6
- package/src/tools/shell-viz.d.ts +6 -2
- package/src/tools/shell-viz.ts +19 -6
- package/src/tools/xd-url.d.ts +6 -0
- package/src/tools/xd-url.ts +19 -1
- package/src/tui.ts +129 -1
- package/src/windows-input-mode.d.ts +8 -0
- package/src/windows-input-mode.ts +13 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/cd` directory picker: a folder-only browser for the current workspace.
|
|
3
|
+
*
|
|
4
|
+
* The picker never shows files. Windows lists its real volumes (internal,
|
|
5
|
+
* removable, network, optical), POSIX lists mount points; both then walk the
|
|
6
|
+
* chosen directory's subdirectories. Pinned paths sit at the top and act
|
|
7
|
+
* immediately: Enter or a click switches the session there, while Ctrl+R
|
|
8
|
+
* (or Ctrl+click) opens the resume picker filtered to that path's
|
|
9
|
+
* conversations.
|
|
10
|
+
*
|
|
11
|
+
* Keys: type to filter (always on), j/k and arrows to move, Enter to open a
|
|
12
|
+
* folder or use the current one, Backspace to go up, Esc to cancel, Ctrl+P to
|
|
13
|
+
* pin/unpin the highlighted folder, Ctrl+R to resume from it. Mouse: wheel
|
|
14
|
+
* scrolls, a click activates the row under the pointer.
|
|
15
|
+
*/
|
|
16
|
+
import * as path from "node:path";
|
|
17
|
+
import {
|
|
18
|
+
SelectList,
|
|
19
|
+
Text,
|
|
20
|
+
extractPrintableText,
|
|
21
|
+
matchesKey,
|
|
22
|
+
routeSgrMouseInput,
|
|
23
|
+
type SelectItem,
|
|
24
|
+
type SgrMouseEvent,
|
|
25
|
+
} from "../index";
|
|
26
|
+
import { getSelectListTheme, theme } from "../theme/theme";
|
|
27
|
+
import { OverlayPanel } from "../chrome/overlay-box";
|
|
28
|
+
import { routeSelectListMouseWithTopBorder } from "../chrome/select-list-mouse-routing";
|
|
29
|
+
import type { DescribeContext, NativeNode, NativeUiEvent } from "../native/node";
|
|
30
|
+
import { SelectListSheet } from "../native/picker";
|
|
31
|
+
import { tuiText, tuiTextFmt } from "../i18n";
|
|
32
|
+
|
|
33
|
+
/** One directory row the picker can show. */
|
|
34
|
+
export interface DirectoryPickerEntry {
|
|
35
|
+
/** Row label (a folder name, or a volume label for a root row). */
|
|
36
|
+
name: string;
|
|
37
|
+
/** Absolute path the row stands for. */
|
|
38
|
+
path: string;
|
|
39
|
+
/** Detail line under/next to the label: a volume kind, mount source, or path. */
|
|
40
|
+
detail?: string;
|
|
41
|
+
/** Named icon for the row. */
|
|
42
|
+
icon?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** What the picker shows at one level. */
|
|
46
|
+
export interface DirectoryPickerListing {
|
|
47
|
+
/** Directory being browsed; `null` on the roots screen (drives / mounts). */
|
|
48
|
+
current: string | null;
|
|
49
|
+
/** Parent directory, or `null` at a filesystem root or the roots screen. */
|
|
50
|
+
parent: string | null;
|
|
51
|
+
/** What the roots screen lists; the title is localized by this component. */
|
|
52
|
+
rootsKind?: "drives" | "mounts";
|
|
53
|
+
/** Volumes or mounts for the roots screen; empty while browsing a directory. */
|
|
54
|
+
roots: DirectoryPickerEntry[];
|
|
55
|
+
/** Pinned directories, always shown first. */
|
|
56
|
+
pins: DirectoryPickerEntry[];
|
|
57
|
+
/** Subdirectories of `current`, folders only. */
|
|
58
|
+
directories: DirectoryPickerEntry[];
|
|
59
|
+
/** Whether `current` itself can become the session directory. */
|
|
60
|
+
selectable: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Host filesystem access; synchronous so a repaint never waits on I/O. */
|
|
64
|
+
export interface DirectoryPickerSource {
|
|
65
|
+
list(directory: string | null): DirectoryPickerListing;
|
|
66
|
+
/** Persist a pin change; resolves to the new pinned state. */
|
|
67
|
+
togglePin(directory: string): Promise<boolean>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface DirectoryPickerOptions {
|
|
71
|
+
source: DirectoryPickerSource;
|
|
72
|
+
/** Directory that is currently the session workspace. */
|
|
73
|
+
initialPath: string;
|
|
74
|
+
/** Called when the user chooses a directory (Enter, click, or a pin). */
|
|
75
|
+
onSelect: (directory: string) => void;
|
|
76
|
+
/** Secondary action: open resume filtered to this directory's conversations. */
|
|
77
|
+
onResume: (directory: string) => void;
|
|
78
|
+
onCancel: () => void;
|
|
79
|
+
/** Home directory, abbreviated to `~` in breadcrumbs. */
|
|
80
|
+
home?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface Row {
|
|
84
|
+
kind: "use" | "parent" | "pin" | "root" | "dir";
|
|
85
|
+
entry: DirectoryPickerEntry;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export class DirectoryPickerOverlay extends OverlayPanel {
|
|
89
|
+
#source: DirectoryPickerSource;
|
|
90
|
+
#options: DirectoryPickerOptions;
|
|
91
|
+
#selectList: SelectList;
|
|
92
|
+
#sheet: SelectListSheet;
|
|
93
|
+
#statusText: Text;
|
|
94
|
+
#rows: Row[] = [];
|
|
95
|
+
/** True while typed characters filter; j/k move only outside it. */
|
|
96
|
+
#filtering = false;
|
|
97
|
+
#current: string | null;
|
|
98
|
+
#listing: DirectoryPickerListing;
|
|
99
|
+
#closed = false;
|
|
100
|
+
|
|
101
|
+
constructor(options: DirectoryPickerOptions) {
|
|
102
|
+
super(tuiText("cdPickerTitle", "Change directory"), "zeta.overlay.cd");
|
|
103
|
+
this.#options = options;
|
|
104
|
+
this.#source = options.source;
|
|
105
|
+
this.#current = options.initialPath;
|
|
106
|
+
this.#listing = this.#source.list(this.#current);
|
|
107
|
+
|
|
108
|
+
this.#selectList = new SelectList([], 14, getSelectListTheme(), {
|
|
109
|
+
// Folder browsing is short; typing must filter from the first key.
|
|
110
|
+
search: "always",
|
|
111
|
+
});
|
|
112
|
+
this.#selectList.onSelect = item => this.#activate(Number(item.value));
|
|
113
|
+
this.#selectList.onCancel = () => this.#cancel();
|
|
114
|
+
this.addChild(this.#selectList);
|
|
115
|
+
this.#statusText = new Text("", 1, 0);
|
|
116
|
+
this.addChild(this.#statusText);
|
|
117
|
+
this.#sheet = new SelectListSheet(this.#selectList, {
|
|
118
|
+
title: tuiText("cdPickerTitle", "Change directory"),
|
|
119
|
+
icon: "folderMove",
|
|
120
|
+
noun: "folders",
|
|
121
|
+
});
|
|
122
|
+
this.#rebuild();
|
|
123
|
+
this.#hint();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Directories listed at the current level (tests and hosts). */
|
|
127
|
+
get listing(): DirectoryPickerListing {
|
|
128
|
+
return this.#listing;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get current(): string | null {
|
|
132
|
+
return this.#current;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Highlighted row's directory, when the row names one. */
|
|
136
|
+
get highlightedPath(): string | undefined {
|
|
137
|
+
return this.#selectedRow()?.entry.path;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
override describe(cx: DescribeContext): NativeNode | null {
|
|
141
|
+
return cx.supports("picker") ? this.#sheet.describe() : super.describe(cx);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
handleNativeEvent(event: NativeUiEvent): void {
|
|
145
|
+
this.#sheet.handle(event);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
routeMouse(event: SgrMouseEvent, line: number, col: number): void {
|
|
149
|
+
// Ctrl+click is the secondary action on the row under the pointer.
|
|
150
|
+
if (event.leftClick && (event.button & 16) !== 0) {
|
|
151
|
+
const index = this.#selectList.hitTest(line - 1);
|
|
152
|
+
const row = index === undefined ? undefined : this.#rows[index];
|
|
153
|
+
if (row) {
|
|
154
|
+
this.#resume(row.entry.path);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
routeSelectListMouseWithTopBorder(this.#selectList, event, line, col);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
handleInput(data: string): void {
|
|
162
|
+
if (this.#closed) return;
|
|
163
|
+
if (routeSgrMouseInput(data, event => this.#handleMouse(event))) return;
|
|
164
|
+
if (matchesKey(data, "ctrl+p")) {
|
|
165
|
+
void this.#togglePin();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (matchesKey(data, "ctrl+r")) {
|
|
169
|
+
const row = this.#selectedRow();
|
|
170
|
+
if (row) this.#resume(row.entry.path);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (this.#filtering) {
|
|
174
|
+
if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
|
|
175
|
+
this.#filtering = false;
|
|
176
|
+
this.#selectList.setFilter("");
|
|
177
|
+
this.#hint();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (matchesKey(data, "backspace") && this.#selectList.getFilter().length === 0) {
|
|
181
|
+
this.#filtering = false;
|
|
182
|
+
this.#goUp();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
this.#selectList.handleInput(data);
|
|
186
|
+
this.invalidate();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
// Navigation mode: vim keys move, and typing starts a filter. `/` starts one
|
|
190
|
+
// explicitly, which is how a filter may begin with `j` or `k`.
|
|
191
|
+
if (matchesKey(data, "j")) {
|
|
192
|
+
this.#selectList.handleInput("\x1b[B");
|
|
193
|
+
this.invalidate();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (matchesKey(data, "k")) {
|
|
197
|
+
this.#selectList.handleInput("\x1b[A");
|
|
198
|
+
this.invalidate();
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (matchesKey(data, "/")) {
|
|
202
|
+
this.#filtering = true;
|
|
203
|
+
this.#selectList.setFilter("");
|
|
204
|
+
this.#hint();
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (matchesKey(data, "backspace")) {
|
|
208
|
+
this.#goUp();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (extractPrintableText(data) !== undefined) this.#filtering = true;
|
|
212
|
+
this.#selectList.handleInput(data);
|
|
213
|
+
this.#hint();
|
|
214
|
+
this.invalidate();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Footer line: the mode-specific key hints. */
|
|
218
|
+
#hint(): void {
|
|
219
|
+
this.#statusText.setText(
|
|
220
|
+
theme.fg(
|
|
221
|
+
"dim",
|
|
222
|
+
this.#filtering
|
|
223
|
+
? tuiText("cdPickerFilterHint", "type to filter · Enter open · Esc clear filter")
|
|
224
|
+
: tuiText(
|
|
225
|
+
"cdPickerNavHint",
|
|
226
|
+
"j/k move · type or / to filter · Enter open · ⌫ up · Ctrl+P pin · Ctrl+R resume",
|
|
227
|
+
),
|
|
228
|
+
),
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
#handleMouse(event: SgrMouseEvent): boolean {
|
|
233
|
+
this.routeMouse(event, event.row, event.col);
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
#selectedRow(): Row | undefined {
|
|
238
|
+
const selected = this.#selectList.pickerView().selected;
|
|
239
|
+
if (selected === null) return undefined;
|
|
240
|
+
return this.#rows[Number(selected)];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
#title(): string {
|
|
244
|
+
if (this.#current === null) {
|
|
245
|
+
return this.#listing.rootsKind === "mounts"
|
|
246
|
+
? tuiText("cdPickerMounts", "Mounts")
|
|
247
|
+
: tuiText("cdPickerDrives", "This PC");
|
|
248
|
+
}
|
|
249
|
+
return this.#abbreviate(this.#current);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#abbreviate(directory: string): string {
|
|
253
|
+
const home = this.#options.home;
|
|
254
|
+
if (!home) return directory;
|
|
255
|
+
const normalizedHome = path.resolve(home);
|
|
256
|
+
const normalized = path.resolve(directory);
|
|
257
|
+
if (normalized === normalizedHome) return "~";
|
|
258
|
+
if (normalized.startsWith(`${normalizedHome}${path.sep}`)) return `~${normalized.slice(normalizedHome.length)}`;
|
|
259
|
+
return normalized;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
#rebuild(): void {
|
|
263
|
+
this.#listing = this.#source.list(this.#current);
|
|
264
|
+
const rows: Row[] = [];
|
|
265
|
+
const items: SelectItem[] = [];
|
|
266
|
+
const push = (row: Row, item: Omit<SelectItem, "value">) => {
|
|
267
|
+
items.push({ ...item, value: String(rows.length) });
|
|
268
|
+
rows.push(row);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
if (this.#current !== null && this.#listing.selectable) {
|
|
272
|
+
push(
|
|
273
|
+
{ kind: "use", entry: { name: this.#title(), path: this.#current } },
|
|
274
|
+
{
|
|
275
|
+
label: tuiText("cdPickerUseThisFolder", "Use this folder"),
|
|
276
|
+
description: this.#title(),
|
|
277
|
+
},
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
if (this.#listing.parent) {
|
|
281
|
+
push(
|
|
282
|
+
{ kind: "parent", entry: { name: "..", path: this.#listing.parent } },
|
|
283
|
+
{ label: "..", description: this.#abbreviate(this.#listing.parent) },
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
for (const pin of this.#listing.pins) {
|
|
287
|
+
push(
|
|
288
|
+
{ kind: "pin", entry: pin },
|
|
289
|
+
{
|
|
290
|
+
label: pin.name,
|
|
291
|
+
description: pin.detail ?? this.#abbreviate(pin.path),
|
|
292
|
+
state: tuiText("cdPickerPinned", "pin"),
|
|
293
|
+
},
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
for (const root of this.#listing.roots) {
|
|
297
|
+
push(
|
|
298
|
+
{ kind: "root", entry: root },
|
|
299
|
+
{
|
|
300
|
+
label: root.name,
|
|
301
|
+
description: root.detail,
|
|
302
|
+
},
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
for (const directory of this.#listing.directories) {
|
|
306
|
+
push({ kind: "dir", entry: directory }, { label: `${directory.name}/`, description: directory.detail });
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
this.#rows = rows;
|
|
310
|
+
this.#selectList.setItems(items);
|
|
311
|
+
this.#selectList.setSelectedIndex(0);
|
|
312
|
+
// Keep the overlay's own chrome in sync with the level being shown.
|
|
313
|
+
this.title = `${tuiText("cdPickerTitle", "Change directory")} ${this.#title()}`;
|
|
314
|
+
this.invalidate();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
#activate(index: number): void {
|
|
318
|
+
const row = this.#rows[index];
|
|
319
|
+
if (!row) return;
|
|
320
|
+
switch (row.kind) {
|
|
321
|
+
case "use":
|
|
322
|
+
case "pin":
|
|
323
|
+
// A pin acts immediately: choosing it switches the workspace.
|
|
324
|
+
this.#select(row.entry.path);
|
|
325
|
+
return;
|
|
326
|
+
case "parent":
|
|
327
|
+
case "root":
|
|
328
|
+
case "dir":
|
|
329
|
+
this.#navigate(row.entry.path);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
#navigate(directory: string | null): void {
|
|
335
|
+
this.#current = directory;
|
|
336
|
+
this.#filtering = false;
|
|
337
|
+
this.#selectList.setFilter("");
|
|
338
|
+
this.#rebuild();
|
|
339
|
+
this.#hint();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
#goUp(): void {
|
|
343
|
+
if (this.#listing.parent) {
|
|
344
|
+
this.#navigate(this.#listing.parent);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (this.#current !== null) this.#navigate(null);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
#select(directory: string): void {
|
|
351
|
+
if (this.#closed) return;
|
|
352
|
+
this.#closed = true;
|
|
353
|
+
this.#options.onSelect(directory);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
#resume(directory: string): void {
|
|
357
|
+
if (this.#closed) return;
|
|
358
|
+
this.#closed = true;
|
|
359
|
+
this.#options.onResume(directory);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
#cancel(): void {
|
|
363
|
+
if (this.#closed) return;
|
|
364
|
+
this.#closed = true;
|
|
365
|
+
this.#options.onCancel();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
async #togglePin(): Promise<void> {
|
|
369
|
+
const row = this.#selectedRow();
|
|
370
|
+
const directory = row?.entry.path ?? this.#current;
|
|
371
|
+
if (!directory) return;
|
|
372
|
+
try {
|
|
373
|
+
const pinned = await this.#source.togglePin(directory);
|
|
374
|
+
this.#statusText.setText(
|
|
375
|
+
theme.fg(
|
|
376
|
+
"dim",
|
|
377
|
+
pinned
|
|
378
|
+
? tuiTextFmt("cdPickerPinnedFmt", "Pinned %s", directory)
|
|
379
|
+
: tuiTextFmt("cdPickerUnpinnedFmt", "Unpinned %s", directory),
|
|
380
|
+
),
|
|
381
|
+
);
|
|
382
|
+
} catch (error) {
|
|
383
|
+
this.#statusText.setText(theme.fg("error", String(error instanceof Error ? error.message : error)));
|
|
384
|
+
}
|
|
385
|
+
this.#rebuild();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
@@ -106,7 +106,7 @@ export class HookEditorComponent extends OverlayPanel implements Focusable {
|
|
|
106
106
|
#editor: Editor;
|
|
107
107
|
#field: FormField;
|
|
108
108
|
#onSubmitCallback: (value: string, images?: ImageContent[]) => void;
|
|
109
|
-
#onCancelCallback: () => void;
|
|
109
|
+
#onCancelCallback: (draft: string, images?: ImageContent[]) => void;
|
|
110
110
|
#tui: TUI;
|
|
111
111
|
#promptStyle: boolean;
|
|
112
112
|
#acceptImages: boolean;
|
|
@@ -128,7 +128,8 @@ export class HookEditorComponent extends OverlayPanel implements Focusable {
|
|
|
128
128
|
title: string,
|
|
129
129
|
prefill: string | undefined,
|
|
130
130
|
onSubmit: (value: string, images?: ImageContent[]) => void,
|
|
131
|
-
|
|
131
|
+
/** Receives the text and images left in the editor, so a host can offer them again. */
|
|
132
|
+
onCancel: (draft: string, images?: ImageContent[]) => void,
|
|
132
133
|
options?: HookEditorOptions,
|
|
133
134
|
) {
|
|
134
135
|
// First title line insets into the panel border; remaining lines (e.g. the
|
|
@@ -328,24 +329,22 @@ export class HookEditorComponent extends OverlayPanel implements Focusable {
|
|
|
328
329
|
this.#submitQueued = true;
|
|
329
330
|
return;
|
|
330
331
|
}
|
|
331
|
-
|
|
332
|
+
const { text, images } = this.#currentValue();
|
|
332
333
|
if (requireText && text.trim().length === 0) return;
|
|
333
|
-
let images: ImageContent[] | undefined;
|
|
334
|
-
if (this.#images.length > 0) {
|
|
335
|
-
// Path pastes attach as they finish loading; submit numbers images in text order.
|
|
336
|
-
const compacted = compactImageMarkers(text, this.#images.length, { byAppearance: true });
|
|
337
|
-
if (compacted) {
|
|
338
|
-
text = compacted.text;
|
|
339
|
-
images = compacted.keep.map(index => this.#images[index]);
|
|
340
|
-
} else {
|
|
341
|
-
images = this.#images;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
334
|
this.dispose();
|
|
345
335
|
if (images?.length) this.#onSubmitCallback(text, images);
|
|
346
336
|
else this.#onSubmitCallback(text);
|
|
347
337
|
}
|
|
348
338
|
|
|
339
|
+
/** Expanded editor text, with attached images renumbered in text order (path pastes attach as they load). */
|
|
340
|
+
#currentValue(): { text: string; images: ImageContent[] | undefined } {
|
|
341
|
+
const text = this.#editor.getExpandedText();
|
|
342
|
+
if (this.#images.length === 0) return { text, images: undefined };
|
|
343
|
+
const compacted = compactImageMarkers(text, this.#images.length, { byAppearance: true });
|
|
344
|
+
if (!compacted) return { text, images: this.#images };
|
|
345
|
+
return { text: compacted.text, images: compacted.keep.map(index => this.#images[index]) };
|
|
346
|
+
}
|
|
347
|
+
|
|
349
348
|
/** Whether this prompt opted into clipboard image attachments. */
|
|
350
349
|
get acceptsImages(): boolean {
|
|
351
350
|
return this.#acceptImages && !this.#disposed;
|
|
@@ -393,8 +392,10 @@ export class HookEditorComponent extends OverlayPanel implements Focusable {
|
|
|
393
392
|
}
|
|
394
393
|
|
|
395
394
|
#cancel(): void {
|
|
395
|
+
const { text, images } = this.#currentValue();
|
|
396
396
|
this.dispose();
|
|
397
|
-
this.#onCancelCallback();
|
|
397
|
+
if (images?.length) this.#onCancelCallback(text, images);
|
|
398
|
+
else this.#onCancelCallback(text);
|
|
398
399
|
}
|
|
399
400
|
|
|
400
401
|
/** Route non-bracketed paste transports (e.g. kitty's OSC 5522 enhanced clipboard)
|
|
@@ -148,7 +148,7 @@ export class HubFrame {
|
|
|
148
148
|
readonly #footer = new PanelRows();
|
|
149
149
|
readonly #bottom = new PanelRows();
|
|
150
150
|
readonly #stack: Stack;
|
|
151
|
-
|
|
151
|
+
#title: string;
|
|
152
152
|
readonly #sidebarBounds: { min: number; max: number };
|
|
153
153
|
/** Whether narrow layouts may reduce the body floor to keep the sidebar usable. */
|
|
154
154
|
readonly #preserveSidebar: boolean;
|
|
@@ -196,6 +196,13 @@ export class HubFrame {
|
|
|
196
196
|
this.#stack.invalidate();
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
+
/** Replace the frame title after asynchronous data supplies a display name. */
|
|
200
|
+
setTitle(title: string): void {
|
|
201
|
+
if (this.#title === title) return;
|
|
202
|
+
this.#title = title;
|
|
203
|
+
this.#stack.invalidate();
|
|
204
|
+
}
|
|
205
|
+
|
|
199
206
|
/** Measure labels and annotations within this hub's sidebar width bounds. */
|
|
200
207
|
sidebarWidth(entries: readonly SidebarEntry<string>[]): number {
|
|
201
208
|
let longest = 0;
|
|
@@ -161,6 +161,10 @@ export interface ModelHubCallbacks {
|
|
|
161
161
|
onFallbackChainChange?: (role: string, chain: string[]) => void;
|
|
162
162
|
/** Locked provider activation: forward to the /login flow. */
|
|
163
163
|
onLoginRequest?: (providerId: string) => void;
|
|
164
|
+
/** Returns the rebuilt `--models` scope for the hub to list; `undefined` keeps the current one. */
|
|
165
|
+
onCatalogRefreshed?: (
|
|
166
|
+
providerId?: string,
|
|
167
|
+
) => ReadonlyArray<ScopedModelItem> | undefined | Promise<ReadonlyArray<ScopedModelItem> | undefined>;
|
|
164
168
|
/** Save the current role assignments and default thinking level as a named model preset. */
|
|
165
169
|
onSavePreset?: (name: string) => void;
|
|
166
170
|
/**
|
|
@@ -550,7 +554,7 @@ export class ModelHubComponent implements Component {
|
|
|
550
554
|
this.#catalogRefreshing = true;
|
|
551
555
|
this.#registry
|
|
552
556
|
.refresh("online")
|
|
553
|
-
.then(() => this.#
|
|
557
|
+
.then(() => this.#afterRegistryRefresh())
|
|
554
558
|
.catch(error => {
|
|
555
559
|
this.#configError = error instanceof Error ? error.message : String(error);
|
|
556
560
|
})
|
|
@@ -1139,6 +1143,12 @@ export class ModelHubComponent implements Component {
|
|
|
1139
1143
|
this.#scheduledProviderRefreshes.set(providerId, timer);
|
|
1140
1144
|
}
|
|
1141
1145
|
|
|
1146
|
+
async #afterRegistryRefresh(providerId?: string): Promise<void> {
|
|
1147
|
+
const scope = await this.#callbacks.onCatalogRefreshed?.(providerId);
|
|
1148
|
+
if (scope) this.#scopedModels = scope;
|
|
1149
|
+
this.#syncFromRegistryState();
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1142
1152
|
async #refreshProviderInBackground(providerId: string, refreshCommandCredentials = false): Promise<void> {
|
|
1143
1153
|
try {
|
|
1144
1154
|
if (refreshCommandCredentials) {
|
|
@@ -1148,7 +1158,7 @@ export class ModelHubComponent implements Component {
|
|
|
1148
1158
|
}
|
|
1149
1159
|
// The provider refresh already updated the registry snapshot;
|
|
1150
1160
|
// re-reading it here stays purely in-memory.
|
|
1151
|
-
this.#
|
|
1161
|
+
await this.#afterRegistryRefresh(providerId);
|
|
1152
1162
|
} catch (error) {
|
|
1153
1163
|
this.#configError = error instanceof Error ? error.message : String(error);
|
|
1154
1164
|
} finally {
|
|
@@ -67,9 +67,9 @@ const LEGEND: readonly { cls: LineClass; tone: TspTone; label: string }[] = [
|
|
|
67
67
|
{ cls: "cut", tone: "muted", label: "cut" },
|
|
68
68
|
];
|
|
69
69
|
|
|
70
|
-
/** One legend entry (role `
|
|
70
|
+
/** One legend entry (role `zeta.spotlight.key`): a swatch and a muted label. */
|
|
71
71
|
function legendKey(swatch: NativeNode, label: string): NativeNode {
|
|
72
|
-
return row([swatch, text([span(label, "muted")])], { gap: "xs", align: "center", role: "
|
|
72
|
+
return row([swatch, text([span(label, "muted")])], { gap: "xs", align: "center", role: "zeta.spotlight.key" });
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/** A count with thousands separators. */
|
|
@@ -104,7 +104,7 @@ function nonBlankParams(params: SpotlightRequestParams): Param[] {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
|
-
* One parameter's row (role `
|
|
107
|
+
* One parameter's row (role `zeta.spotlight.param`): its name, then its non-blank values on one run of spaces and at
|
|
108
108
|
* most `lines` lines, whole in the tooltip; `end` (the toggle) last.
|
|
109
109
|
*/
|
|
110
110
|
function paramRow(param: Param, lines: number, end?: NativeNode): NativeNode {
|
|
@@ -115,11 +115,11 @@ function paramRow(param: Param, lines: number, end?: NativeNode): NativeNode {
|
|
|
115
115
|
return i === 0 ? [part] : [span(" · ", param.style ? `dim ${param.style}` : "dim"), part];
|
|
116
116
|
});
|
|
117
117
|
const shown = text(spans, { lines, truncate: "end", title: whole.join("\n") });
|
|
118
|
-
return row(compact([text(param.name), shown, end]), { gap: "md", align: "baseline", role: "
|
|
118
|
+
return row(compact([text(param.name), shown, end]), { gap: "md", align: "baseline", role: "zeta.spotlight.param" });
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
|
-
* What the result's Spotlight requests sent besides its lines (role `
|
|
122
|
+
* What the result's Spotlight requests sent besides its lines (role `zeta.spotlight.params`): collapsed, the first
|
|
123
123
|
* parameter (the intent) on one line and a toggle naming the rest; expanded, a row per parameter.
|
|
124
124
|
*/
|
|
125
125
|
function requestParams(params: SpotlightRequestParams, expanded: boolean): NativeNode | undefined {
|
|
@@ -129,14 +129,14 @@ function requestParams(params: SpotlightRequestParams, expanded: boolean): Nativ
|
|
|
129
129
|
const toggle =
|
|
130
130
|
rest.length > 0
|
|
131
131
|
? text(expanded ? "fewer ▾" : `${rest.map(param => param.name).join(", ")} ▸`, {
|
|
132
|
-
role: "
|
|
132
|
+
role: "zeta.spotlight.more",
|
|
133
133
|
actions: { click: "params" },
|
|
134
134
|
})
|
|
135
135
|
: undefined;
|
|
136
136
|
const rows = (expanded ? named : named.slice(0, 1)).map((param, i) =>
|
|
137
137
|
paramRow(param, expanded ? 2 : 1, i === 0 ? toggle : undefined),
|
|
138
138
|
);
|
|
139
|
-
return col(rows, { gap: "xs", role: "
|
|
139
|
+
return col(rows, { gap: "xs", role: "zeta.spotlight.params" });
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
/** The class the summary counts original line `i` (0-based) in; undefined without a reason. */
|
|
@@ -148,7 +148,7 @@ function lineClass(original: SpotlightOriginal, i: number): LineClass | undefine
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
/**
|
|
151
|
-
* The summary row (role `
|
|
151
|
+
* The summary row (role `zeta.spotlight.summary`): a legend swatch and count per class of the shown lines (with
|
|
152
152
|
* reasons), then the ranking step's budget and cutoff and whether the view is cut; undefined when it has nothing.
|
|
153
153
|
*/
|
|
154
154
|
function summary(original: SpotlightOriginal, shown: number, total: number): NativeNode | undefined {
|
|
@@ -161,7 +161,7 @@ function summary(original: SpotlightOriginal, shown: number, total: number): Nat
|
|
|
161
161
|
}
|
|
162
162
|
for (const { cls, tone, label } of LEGEND) {
|
|
163
163
|
const n = counts.get(cls);
|
|
164
|
-
if (n) items.push(legendKey(text("■", { role: "
|
|
164
|
+
if (n) items.push(legendKey(text("■", { role: "zeta.spotlight.swatch", tone }), `${label} ${count(n)}`));
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
const facts: string[] = [];
|
|
@@ -175,12 +175,12 @@ function summary(original: SpotlightOriginal, shown: number, total: number): Nat
|
|
|
175
175
|
}
|
|
176
176
|
if (shown < total) facts.push(`first ${count(shown)} of ${count(total)} lines`);
|
|
177
177
|
if (items.length === 0 && facts.length === 0) return undefined;
|
|
178
|
-
const budget = facts.length > 0 && text([span(facts.join(" · "), "muted")], { role: "
|
|
178
|
+
const budget = facts.length > 0 && text([span(facts.join(" · "), "muted")], { role: "zeta.spotlight.budget" });
|
|
179
179
|
return row(compact([...items, node("spacer", { grow: 1 }), budget]), {
|
|
180
180
|
gap: "md",
|
|
181
181
|
align: "center",
|
|
182
182
|
wrap: true,
|
|
183
|
-
role: "
|
|
183
|
+
role: "zeta.spotlight.summary",
|
|
184
184
|
});
|
|
185
185
|
}
|
|
186
186
|
|
|
@@ -280,7 +280,7 @@ function hotCard(sheet: SheetText, i: number): TspPropNode {
|
|
|
280
280
|
]),
|
|
281
281
|
why !== undefined && text([span(why, "error")]),
|
|
282
282
|
]),
|
|
283
|
-
{ gap: "xs", role: "
|
|
283
|
+
{ gap: "xs", role: "zeta.spotlight.card" },
|
|
284
284
|
),
|
|
285
285
|
);
|
|
286
286
|
}
|
|
@@ -333,7 +333,7 @@ function folds(sheet: SheetText): TspCodeFold[] {
|
|
|
333
333
|
const OVERVIEW_MIN_LINES = 60;
|
|
334
334
|
|
|
335
335
|
/**
|
|
336
|
-
* The original as one `code` element (role `
|
|
336
|
+
* The original as one `code` element (role `zeta.spotlight.code`): marks, folds, and the overview past
|
|
337
337
|
* {@link OVERVIEW_MIN_LINES}. Command output (no file) wraps, a file keeps its lines.
|
|
338
338
|
*/
|
|
339
339
|
function originalCode(sheet: SheetText): NativeNode {
|
|
@@ -341,7 +341,7 @@ function originalCode(sheet: SheetText): NativeNode {
|
|
|
341
341
|
const marks = compact(sheet.lines.map((_, i) => lineMark(original, i)));
|
|
342
342
|
const shut = folds(sheet);
|
|
343
343
|
return code(sheet.lines.join("\n"), {
|
|
344
|
-
role: "
|
|
344
|
+
role: "zeta.spotlight.code",
|
|
345
345
|
path: sheet.path,
|
|
346
346
|
start: original.start,
|
|
347
347
|
numbers: true,
|
|
@@ -368,20 +368,20 @@ function shapingNotes(sheet: SheetText, heldOut: boolean): NativeNode | undefine
|
|
|
368
368
|
const heading = heldOut ? "notes the model would have seen" : "notes the model saw";
|
|
369
369
|
return col([text([span(heading, "muted")]), ...notes.map(note => text([span(note, "muted mono")]))], {
|
|
370
370
|
gap: "xs",
|
|
371
|
-
role: "
|
|
371
|
+
role: "zeta.spotlight.notes",
|
|
372
372
|
});
|
|
373
373
|
}
|
|
374
374
|
|
|
375
375
|
/**
|
|
376
|
-
* The footer's key to the rows' wash (role `
|
|
376
|
+
* The footer's key to the rows' wash (role `zeta.spotlight.legend`): the heat ramp (role `zeta.spotlight.ramp`, drawn
|
|
377
377
|
* by the terminal) before the rank's parts in their order across a row.
|
|
378
378
|
*/
|
|
379
379
|
function rankLegend(rank: SpotlightRank): NativeNode {
|
|
380
380
|
const label =
|
|
381
381
|
rank.parts.length > 1 ? `row tint, left to right: ${rank.parts.join(" → ")}` : `row tint: ${rank.parts[0]}`;
|
|
382
|
-
return row([legendKey(text("", { role: "
|
|
382
|
+
return row([legendKey(text("", { role: "zeta.spotlight.ramp" }), label)], {
|
|
383
383
|
align: "center",
|
|
384
|
-
role: "
|
|
384
|
+
role: "zeta.spotlight.legend",
|
|
385
385
|
});
|
|
386
386
|
}
|
|
387
387
|
|