@firstpick/pi-package-webui 0.9.9 → 0.10.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/DEVELOPMENT.md +49 -15
- package/README.md +11 -9
- package/TECHNICAL.md +12 -8
- package/bin/pi-webui.mjs +202 -67
- package/index.ts +23 -33
- package/lib/git-workflow-preferences.mjs +51 -12
- package/lib/tui-model-profile-selector.mjs +183 -0
- package/lib/tui-resource-selector.mjs +173 -0
- package/package.json +1 -1
- package/public/app.js +365 -106
- package/public/index.html +10 -7
- package/public/service-worker.js +1 -1
- package/public/styles.css +114 -22
- package/tests/boot-failure-diagnostics.test.mjs +3 -3
- package/tests/browser/interaction-continuity.spec.mjs +9 -3
- package/tests/browser/intercom-conversation-viewer.spec.mjs +76 -53
- package/tests/browser/user-noticeable-fixes.spec.mjs +51 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
- package/tests/control-visibility-static.test.mjs +3 -3
- package/tests/controls-layout-static.test.mjs +3 -3
- package/tests/durable-rpc-supervisor-harness.test.mjs +9 -0
- package/tests/events-tree-context-menu-static.test.mjs +3 -3
- package/tests/fast-mode-client-static.test.mjs +1 -1
- package/tests/feature-decision-output-popup-static.test.mjs +2 -2
- package/tests/file-viewer-image-static.test.mjs +3 -3
- package/tests/fixtures/fake-pi.mjs +3 -3
- package/tests/guided-git-activation-static.test.mjs +24 -12
- package/tests/guided-git-fallback-runtime.test.mjs +209 -270
- package/tests/guided-git-fallback-ui-static.test.mjs +2 -2
- package/tests/guided-git-message-reliability-static.test.mjs +2 -1
- package/tests/guided-git-optional-feature.test.mjs +8 -5
- package/tests/guided-git-publication-backend-static.test.mjs +10 -5
- package/tests/http-endpoints-harness.test.mjs +27 -13
- package/tests/intercom-conversation-viewer-static.test.mjs +7 -6
- package/tests/intercom-tag-layout-static.test.mjs +35 -16
- package/tests/intercom-tag-overflow-layout.test.mjs +87 -0
- package/tests/main-output-loading-static.test.mjs +18 -12
- package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +3 -3
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +19 -11
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/optional-feature-prompt-impact-static.test.mjs +67 -0
- package/tests/persistent-ui-layout-static.test.mjs +3 -3
- package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
- package/tests/questionnaire-dialog.test.mjs +3 -3
- package/tests/remote-auth-settings-harness.test.mjs +18 -3
- package/tests/resource-tui-extension.test.mjs +2 -1
- package/tests/session-sampling-ui-static.test.mjs +3 -3
- package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
- package/tests/streaming-ui-coupling.test.mjs +2 -0
- package/tests/subagent-observability-static.test.mjs +2 -2
- package/tests/syntax-highlighting-static.test.mjs +3 -3
- package/tests/theme-customizer-static.test.mjs +1 -1
- package/tests/tui-model-profile-selector.test.mjs +102 -0
- package/tests/tui-resource-selector.test.mjs +74 -0
- package/tests/webui-settings-locking.test.mjs +32 -1
- package/tests/windows-drive-cwd-picker-static.test.mjs +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mkdir, open, readFile, readdir, rename, rm, rmdir } from "node:fs/promises";
|
|
1
|
+
import { mkdir, open, readFile, readdir, rename, rm, rmdir, stat } from "node:fs/promises";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { setTimeout as delay } from "node:timers/promises";
|
|
@@ -31,6 +31,7 @@ const WEBUI_SETTINGS_VERSION = 8;
|
|
|
31
31
|
const WEBUI_SETTINGS_FILE_ENV = "PI_WEBUI_SETTINGS_FILE";
|
|
32
32
|
const WEBUI_SETTINGS_LOCK_TIMEOUT_MS = 2_000;
|
|
33
33
|
const WEBUI_SETTINGS_LOCK_RETRY_MS = 25;
|
|
34
|
+
const WEBUI_SETTINGS_LOCK_INVALID_RECORD_GRACE_MS = 1_000;
|
|
34
35
|
export const WEBUI_SIDE_PANEL_WIDTH_MIN_PX = 320;
|
|
35
36
|
export const WEBUI_SIDE_PANEL_WIDTH_MAX_PX = 4096;
|
|
36
37
|
const webuiSettingsUpdateQueues = new Map();
|
|
@@ -240,22 +241,51 @@ function lockOwnerIsDead(pid) {
|
|
|
240
241
|
}
|
|
241
242
|
}
|
|
242
243
|
|
|
244
|
+
function settingsLockRecordNameMetadata(name) {
|
|
245
|
+
const match = name.match(/^(\d+)-(\d+)-[^/]+\.json$/);
|
|
246
|
+
if (!match) return {};
|
|
247
|
+
const ownerPid = Number(match[1]);
|
|
248
|
+
const createdAt = Number(match[2]);
|
|
249
|
+
return {
|
|
250
|
+
ownerPid: Number.isSafeInteger(ownerPid) && ownerPid > 0 ? ownerPid : undefined,
|
|
251
|
+
createdAt: Number.isSafeInteger(createdAt) && createdAt > 0 ? createdAt : undefined,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
243
255
|
async function readSettingsLockRecords(lockDirectory) {
|
|
244
256
|
const names = (await readdir(lockDirectory)).filter((name) => name.endsWith(".json")).sort();
|
|
245
|
-
|
|
257
|
+
const records = await Promise.all(names.map(async (name) => {
|
|
246
258
|
const recordFile = path.join(lockDirectory, name);
|
|
259
|
+
const nameMetadata = settingsLockRecordNameMetadata(name);
|
|
247
260
|
try {
|
|
248
|
-
const value =
|
|
261
|
+
const [value, fileStat] = await Promise.all([
|
|
262
|
+
readFile(recordFile, "utf8").then((text) => JSON.parse(text)),
|
|
263
|
+
stat(recordFile),
|
|
264
|
+
]);
|
|
249
265
|
const valid = Number.isSafeInteger(value?.pid)
|
|
250
266
|
&& value.pid > 0
|
|
251
267
|
&& typeof value?.token === "string"
|
|
252
268
|
&& value.token.length > 0
|
|
253
269
|
&& ["pending", "active"].includes(value?.state);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
270
|
+
const createdAt = Number.isSafeInteger(value?.createdAt) && value.createdAt > 0
|
|
271
|
+
? value.createdAt
|
|
272
|
+
: nameMetadata.createdAt;
|
|
273
|
+
return {
|
|
274
|
+
...value,
|
|
275
|
+
ownerPid: nameMetadata.ownerPid,
|
|
276
|
+
createdAt,
|
|
277
|
+
name,
|
|
278
|
+
recordFile,
|
|
279
|
+
mtimeMs: fileStat.mtimeMs,
|
|
280
|
+
valid,
|
|
281
|
+
};
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (error?.code === "ENOENT") return undefined;
|
|
284
|
+
const fileStat = await stat(recordFile).catch(() => undefined);
|
|
285
|
+
return { ...nameMetadata, name, recordFile, mtimeMs: fileStat?.mtimeMs, valid: false };
|
|
257
286
|
}
|
|
258
287
|
}));
|
|
288
|
+
return records.filter(Boolean);
|
|
259
289
|
}
|
|
260
290
|
|
|
261
291
|
async function renameWithWindowsRetry(source, target) {
|
|
@@ -306,9 +336,10 @@ export async function withWebuiSettingsLock(storageFile, operation, {
|
|
|
306
336
|
await mkdir(lockDirectory, { mode: 0o700 }).catch((error) => {
|
|
307
337
|
if (error?.code !== "EEXIST") throw error;
|
|
308
338
|
});
|
|
309
|
-
const
|
|
339
|
+
const createdAt = Date.now();
|
|
340
|
+
const token = `${process.pid}-${createdAt}-${Math.random().toString(16).slice(2)}`;
|
|
310
341
|
const recordFile = path.join(lockDirectory, `${token}.json`);
|
|
311
|
-
const ownRecord = { pid: process.pid, token, state: "pending" };
|
|
342
|
+
const ownRecord = { pid: process.pid, token, state: "pending", createdAt };
|
|
312
343
|
let handle;
|
|
313
344
|
try {
|
|
314
345
|
handle = await open(recordFile, "wx", 0o600);
|
|
@@ -327,14 +358,22 @@ export async function withWebuiSettingsLock(storageFile, operation, {
|
|
|
327
358
|
try {
|
|
328
359
|
while (!acquired) {
|
|
329
360
|
let records = await readSettingsLockRecords(lockDirectory);
|
|
330
|
-
let
|
|
361
|
+
let removedStaleRecord = false;
|
|
331
362
|
for (const record of records) {
|
|
332
|
-
|
|
363
|
+
const ownerPid = record.valid ? record.pid : record.ownerPid;
|
|
364
|
+
const ownerIsDead = lockOwnerIsDead(ownerPid);
|
|
365
|
+
const recordAgeMs = Math.max(
|
|
366
|
+
Number.isFinite(record.mtimeMs) ? Date.now() - record.mtimeMs : 0,
|
|
367
|
+
Number.isSafeInteger(record.createdAt) ? Date.now() - record.createdAt : 0,
|
|
368
|
+
);
|
|
369
|
+
const invalidRecordIsStale = !record.valid
|
|
370
|
+
&& (ownerIsDead || recordAgeMs >= WEBUI_SETTINGS_LOCK_INVALID_RECORD_GRACE_MS);
|
|
371
|
+
if ((record.valid && ownerIsDead) || invalidRecordIsStale) {
|
|
333
372
|
await rm(record.recordFile, { force: true });
|
|
334
|
-
|
|
373
|
+
removedStaleRecord = true;
|
|
335
374
|
}
|
|
336
375
|
}
|
|
337
|
-
if (
|
|
376
|
+
if (removedStaleRecord) continue;
|
|
338
377
|
|
|
339
378
|
const active = records.filter((record) => record.valid && record.state === "active");
|
|
340
379
|
if (active.length === 1 && active[0].token === token) {
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { DynamicBorder } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Container, fuzzyFilter, getKeybindings, Input, Key, matchesKey, Spacer, Text } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
function modelKey(model) {
|
|
5
|
+
return `${model.provider}\0${model.id}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function modelSearchText(model) {
|
|
9
|
+
return `${model.provider} ${model.id} ${model.name || ""}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class TuiModelProfileSelectorComponent extends Container {
|
|
13
|
+
constructor(config, theme, callbacks) {
|
|
14
|
+
super();
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
this.models = config.models.filter((model) => {
|
|
17
|
+
if (!model?.provider || !model?.id) return false;
|
|
18
|
+
const key = modelKey(model);
|
|
19
|
+
if (seen.has(key)) return false;
|
|
20
|
+
seen.add(key);
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
this.activeModelKey = config.activeModelKey || "";
|
|
24
|
+
this.configuredModelKeys = new Set(config.configuredModelKeys || []);
|
|
25
|
+
this.theme = theme;
|
|
26
|
+
this.callbacks = callbacks;
|
|
27
|
+
this.filteredModels = [...this.models];
|
|
28
|
+
const activeModel = this.models.find((model) => modelKey(model) === this.activeModelKey);
|
|
29
|
+
const configuredModel = this.models.find((model) => this.configuredModelKeys.has(modelKey(model)));
|
|
30
|
+
const initialKey = activeModel ? this.activeModelKey : configuredModel ? modelKey(configuredModel) : "";
|
|
31
|
+
this.selectedIndex = Math.max(0, this.filteredModels.findIndex((model) => modelKey(model) === initialKey));
|
|
32
|
+
this.lastQuery = "";
|
|
33
|
+
this.maxVisible = 10;
|
|
34
|
+
this._focused = false;
|
|
35
|
+
|
|
36
|
+
this.addChild(new DynamicBorder((text) => theme.fg("accent", text)));
|
|
37
|
+
this.addChild(new Spacer(1));
|
|
38
|
+
this.addChild(new Text(theme.fg("accent", theme.bold(config.title)), 0, 0));
|
|
39
|
+
this.addChild(new Text(theme.fg("muted", config.subtitle), 0, 0));
|
|
40
|
+
this.addChild(new Spacer(1));
|
|
41
|
+
|
|
42
|
+
this.searchInput = new Input();
|
|
43
|
+
this.addChild(this.searchInput);
|
|
44
|
+
this.addChild(new Spacer(1));
|
|
45
|
+
|
|
46
|
+
this.listContainer = new Container();
|
|
47
|
+
this.addChild(this.listContainer);
|
|
48
|
+
this.addChild(new Spacer(1));
|
|
49
|
+
|
|
50
|
+
this.footerText = new Text(this.footer(), 0, 0);
|
|
51
|
+
this.addChild(this.footerText);
|
|
52
|
+
this.addChild(new DynamicBorder((text) => theme.fg("accent", text)));
|
|
53
|
+
this.refresh();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get focused() {
|
|
57
|
+
return this._focused;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
set focused(value) {
|
|
61
|
+
this._focused = value;
|
|
62
|
+
this.searchInput.focused = value;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
footer() {
|
|
66
|
+
const position = this.filteredModels.length ? `${this.selectedIndex + 1}/${this.filteredModels.length}` : "0/0";
|
|
67
|
+
return this.theme.fg("dim", ` ↑/↓ navigate · Enter select · Ctrl+C clear/cancel · Esc cancel · ${position}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
refresh() {
|
|
71
|
+
const selectedKey = this.filteredModels[this.selectedIndex] ? modelKey(this.filteredModels[this.selectedIndex]) : "";
|
|
72
|
+
const query = this.searchInput.getValue();
|
|
73
|
+
const queryChanged = query !== this.lastQuery;
|
|
74
|
+
this.lastQuery = query;
|
|
75
|
+
this.filteredModels = query ? fuzzyFilter(this.models, query, modelSearchText) : [...this.models];
|
|
76
|
+
const retainedIndex = selectedKey
|
|
77
|
+
? this.filteredModels.findIndex((model) => modelKey(model) === selectedKey)
|
|
78
|
+
: -1;
|
|
79
|
+
this.selectedIndex = retainedIndex >= 0
|
|
80
|
+
? retainedIndex
|
|
81
|
+
: queryChanged
|
|
82
|
+
? 0
|
|
83
|
+
: Math.min(this.selectedIndex, Math.max(0, this.filteredModels.length - 1));
|
|
84
|
+
this.updateList();
|
|
85
|
+
this.footerText.setText(this.footer());
|
|
86
|
+
this.callbacks.onRender?.();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
updateList() {
|
|
90
|
+
this.listContainer.clear();
|
|
91
|
+
if (this.filteredModels.length === 0) {
|
|
92
|
+
this.listContainer.addChild(new Text(this.theme.fg("muted", " No matching models"), 0, 0));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const startIndex = Math.max(
|
|
97
|
+
0,
|
|
98
|
+
Math.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredModels.length - this.maxVisible),
|
|
99
|
+
);
|
|
100
|
+
const endIndex = Math.min(startIndex + this.maxVisible, this.filteredModels.length);
|
|
101
|
+
for (let index = startIndex; index < endIndex; index++) {
|
|
102
|
+
const model = this.filteredModels[index];
|
|
103
|
+
const key = modelKey(model);
|
|
104
|
+
const selected = index === this.selectedIndex;
|
|
105
|
+
const prefix = selected ? this.theme.fg("accent", "→ ") : " ";
|
|
106
|
+
const id = selected ? this.theme.fg("accent", model.id) : model.id;
|
|
107
|
+
const provider = this.theme.fg("muted", ` [${model.provider}]`);
|
|
108
|
+
const active = key === this.activeModelKey ? this.theme.fg("success", " [active]") : "";
|
|
109
|
+
const configured = this.configuredModelKeys.has(key) ? this.theme.fg("warning", " [profile]") : "";
|
|
110
|
+
this.listContainer.addChild(new Text(`${prefix}${id}${provider}${active}${configured}`, 0, 0));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (startIndex > 0 || endIndex < this.filteredModels.length) {
|
|
114
|
+
this.listContainer.addChild(
|
|
115
|
+
new Text(this.theme.fg("muted", ` (${this.selectedIndex + 1}/${this.filteredModels.length})`), 0, 0),
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const selectedModel = this.filteredModels[this.selectedIndex];
|
|
120
|
+
if (selectedModel) {
|
|
121
|
+
const profileState = this.configuredModelKeys.has(modelKey(selectedModel)) ? "configured" : "inherited";
|
|
122
|
+
this.listContainer.addChild(new Spacer(1));
|
|
123
|
+
this.listContainer.addChild(
|
|
124
|
+
new Text(this.theme.fg("muted", ` Model Name: ${selectedModel.name || selectedModel.id} · Profile: ${profileState}`), 0, 0),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
handleInput(data) {
|
|
130
|
+
const keybindings = getKeybindings();
|
|
131
|
+
if (keybindings.matches(data, "tui.select.up")) {
|
|
132
|
+
if (this.filteredModels.length > 0) {
|
|
133
|
+
this.selectedIndex = this.selectedIndex === 0 ? this.filteredModels.length - 1 : this.selectedIndex - 1;
|
|
134
|
+
this.updateList();
|
|
135
|
+
this.footerText.setText(this.footer());
|
|
136
|
+
this.callbacks.onRender?.();
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (keybindings.matches(data, "tui.select.down")) {
|
|
141
|
+
if (this.filteredModels.length > 0) {
|
|
142
|
+
this.selectedIndex = this.selectedIndex === this.filteredModels.length - 1 ? 0 : this.selectedIndex + 1;
|
|
143
|
+
this.updateList();
|
|
144
|
+
this.footerText.setText(this.footer());
|
|
145
|
+
this.callbacks.onRender?.();
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (keybindings.matches(data, "tui.select.confirm")) {
|
|
150
|
+
const model = this.filteredModels[this.selectedIndex];
|
|
151
|
+
if (model) this.callbacks.onSelect(model);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (matchesKey(data, Key.ctrl("c"))) {
|
|
155
|
+
if (this.searchInput.getValue()) {
|
|
156
|
+
this.searchInput.setValue("");
|
|
157
|
+
this.refresh();
|
|
158
|
+
} else {
|
|
159
|
+
this.callbacks.onCancel();
|
|
160
|
+
}
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (matchesKey(data, Key.escape)) {
|
|
164
|
+
this.callbacks.onCancel();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
this.searchInput.handleInput(data);
|
|
169
|
+
this.refresh();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
getSearchInput() {
|
|
173
|
+
return this.searchInput;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function selectTuiModelProfile(ctx, config) {
|
|
178
|
+
return await ctx.ui.custom((tui, theme, _keybindings, done) => new TuiModelProfileSelectorComponent(config, theme, {
|
|
179
|
+
onSelect: done,
|
|
180
|
+
onCancel: () => done(undefined),
|
|
181
|
+
onRender: () => tui.requestRender(),
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { DynamicBorder } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Container, fuzzyFilter, getKeybindings, Input, Key, matchesKey, Spacer, Text } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
function keyMatches(data, keybinding, fallback) {
|
|
5
|
+
const keybindings = getKeybindings();
|
|
6
|
+
return keybindings.matches(data, keybinding) || matchesKey(data, fallback);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class TuiResourceSelectorComponent extends Container {
|
|
10
|
+
constructor(config, theme, callbacks) {
|
|
11
|
+
super();
|
|
12
|
+
this.resources = [...new Set(config.resources)];
|
|
13
|
+
this.enabled = new Set(config.enabledResourceNames.filter((name) => this.resources.includes(name)));
|
|
14
|
+
this.theme = theme;
|
|
15
|
+
this.callbacks = callbacks;
|
|
16
|
+
this.filteredResources = [...this.resources];
|
|
17
|
+
this.selectedIndex = 0;
|
|
18
|
+
this.maxVisible = 10;
|
|
19
|
+
this.isDirty = false;
|
|
20
|
+
this._focused = false;
|
|
21
|
+
|
|
22
|
+
this.addChild(new DynamicBorder((text) => theme.fg("accent", text)));
|
|
23
|
+
this.addChild(new Spacer(1));
|
|
24
|
+
this.addChild(new Text(theme.fg("accent", theme.bold(config.title)), 0, 0));
|
|
25
|
+
this.addChild(new Text(theme.fg("muted", config.subtitle), 0, 0));
|
|
26
|
+
this.addChild(new Spacer(1));
|
|
27
|
+
|
|
28
|
+
this.searchInput = new Input();
|
|
29
|
+
this.addChild(this.searchInput);
|
|
30
|
+
this.addChild(new Spacer(1));
|
|
31
|
+
|
|
32
|
+
this.listContainer = new Container();
|
|
33
|
+
this.addChild(this.listContainer);
|
|
34
|
+
this.addChild(new Spacer(1));
|
|
35
|
+
|
|
36
|
+
this.footerText = new Text(this.footer(), 0, 0);
|
|
37
|
+
this.addChild(this.footerText);
|
|
38
|
+
this.addChild(new DynamicBorder((text) => theme.fg("accent", text)));
|
|
39
|
+
this.refresh();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get focused() {
|
|
43
|
+
return this._focused;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
set focused(value) {
|
|
47
|
+
this._focused = value;
|
|
48
|
+
this.searchInput.focused = value;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
footer() {
|
|
52
|
+
const text = ` Enter toggle · Ctrl+A all · Ctrl+X clear · Ctrl+S save · ${this.enabled.size}/${this.resources.length} enabled`;
|
|
53
|
+
return this.isDirty ? `${this.theme.fg("dim", text)} ${this.theme.fg("warning", "(unsaved)")}` : this.theme.fg("dim", text);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
refresh() {
|
|
57
|
+
const query = this.searchInput.getValue();
|
|
58
|
+
this.filteredResources = query ? fuzzyFilter(this.resources, query, (name) => name) : [...this.resources];
|
|
59
|
+
this.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredResources.length - 1));
|
|
60
|
+
this.updateList();
|
|
61
|
+
this.footerText.setText(this.footer());
|
|
62
|
+
this.callbacks.onRender?.();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
updateList() {
|
|
66
|
+
this.listContainer.clear();
|
|
67
|
+
if (this.filteredResources.length === 0) {
|
|
68
|
+
this.listContainer.addChild(new Text(this.theme.fg("muted", " No matching resources"), 0, 0));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const startIndex = Math.max(
|
|
73
|
+
0,
|
|
74
|
+
Math.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredResources.length - this.maxVisible),
|
|
75
|
+
);
|
|
76
|
+
const endIndex = Math.min(startIndex + this.maxVisible, this.filteredResources.length);
|
|
77
|
+
for (let index = startIndex; index < endIndex; index++) {
|
|
78
|
+
const name = this.filteredResources[index];
|
|
79
|
+
const selected = index === this.selectedIndex;
|
|
80
|
+
const prefix = selected ? this.theme.fg("accent", "→ ") : " ";
|
|
81
|
+
const label = selected ? this.theme.fg("accent", name) : name;
|
|
82
|
+
const status = this.enabled.has(name) ? this.theme.fg("success", " ✓") : this.theme.fg("dim", " ✗");
|
|
83
|
+
this.listContainer.addChild(new Text(`${prefix}${label}${status}`, 0, 0));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (startIndex > 0 || endIndex < this.filteredResources.length) {
|
|
87
|
+
this.listContainer.addChild(
|
|
88
|
+
new Text(this.theme.fg("muted", ` (${this.selectedIndex + 1}/${this.filteredResources.length})`), 0, 0),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
setFilteredEnabled(enabled) {
|
|
94
|
+
const targets = this.searchInput.getValue() ? this.filteredResources : this.resources;
|
|
95
|
+
for (const name of targets) {
|
|
96
|
+
if (enabled) this.enabled.add(name);
|
|
97
|
+
else this.enabled.delete(name);
|
|
98
|
+
}
|
|
99
|
+
this.isDirty = true;
|
|
100
|
+
this.refresh();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
handleInput(data) {
|
|
104
|
+
const keybindings = getKeybindings();
|
|
105
|
+
|
|
106
|
+
if (keybindings.matches(data, "tui.select.up")) {
|
|
107
|
+
if (this.filteredResources.length > 0) {
|
|
108
|
+
this.selectedIndex = this.selectedIndex === 0 ? this.filteredResources.length - 1 : this.selectedIndex - 1;
|
|
109
|
+
this.updateList();
|
|
110
|
+
this.callbacks.onRender?.();
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (keybindings.matches(data, "tui.select.down")) {
|
|
115
|
+
if (this.filteredResources.length > 0) {
|
|
116
|
+
this.selectedIndex = this.selectedIndex === this.filteredResources.length - 1 ? 0 : this.selectedIndex + 1;
|
|
117
|
+
this.updateList();
|
|
118
|
+
this.callbacks.onRender?.();
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (keybindings.matches(data, "tui.select.confirm")) {
|
|
123
|
+
const name = this.filteredResources[this.selectedIndex];
|
|
124
|
+
if (name) {
|
|
125
|
+
if (this.enabled.has(name)) this.enabled.delete(name);
|
|
126
|
+
else this.enabled.add(name);
|
|
127
|
+
this.isDirty = true;
|
|
128
|
+
this.refresh();
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (keyMatches(data, "app.models.enableAll", Key.ctrl("a"))) {
|
|
133
|
+
this.setFilteredEnabled(true);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (keyMatches(data, "app.models.clearAll", Key.ctrl("x"))) {
|
|
137
|
+
this.setFilteredEnabled(false);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (keyMatches(data, "app.models.save", Key.ctrl("s"))) {
|
|
141
|
+
this.callbacks.onSave(this.resources.filter((name) => this.enabled.has(name)));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (matchesKey(data, Key.ctrl("c"))) {
|
|
145
|
+
if (this.searchInput.getValue()) {
|
|
146
|
+
this.searchInput.setValue("");
|
|
147
|
+
this.refresh();
|
|
148
|
+
} else {
|
|
149
|
+
this.callbacks.onCancel();
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (matchesKey(data, Key.escape)) {
|
|
154
|
+
this.callbacks.onCancel();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
this.searchInput.handleInput(data);
|
|
159
|
+
this.refresh();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
getSearchInput() {
|
|
163
|
+
return this.searchInput;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function selectTuiResources(ctx, config) {
|
|
168
|
+
return await ctx.ui.custom((tui, theme, _keybindings, done) => new TuiResourceSelectorComponent(config, theme, {
|
|
169
|
+
onSave: done,
|
|
170
|
+
onCancel: () => done(undefined),
|
|
171
|
+
onRender: () => tui.requestRender(),
|
|
172
|
+
}));
|
|
173
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firstpick/pi-package-webui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Pi Web UI companion package with a local browser UI CLI plus /webui-start and /webui-status commands.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/Firstp1ck/pi-coding-agent-forge/tree/main/pi-package-webui#readme",
|