@firstpick/pi-package-webui 0.9.8 → 0.10.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.
Files changed (59) hide show
  1. package/DEVELOPMENT.md +911 -0
  2. package/README.md +8 -8
  3. package/TECHNICAL.md +415 -0
  4. package/bin/pi-webui.mjs +237 -64
  5. package/index.ts +23 -33
  6. package/lib/git-workflow-preferences.mjs +51 -12
  7. package/lib/tui-model-profile-selector.mjs +183 -0
  8. package/lib/tui-resource-selector.mjs +173 -0
  9. package/lib/windows-drive-roots.mjs +114 -0
  10. package/package.json +3 -1
  11. package/public/app.js +274 -90
  12. package/public/index.html +7 -3
  13. package/public/service-worker.js +1 -1
  14. package/public/styles.css +76 -16
  15. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  16. package/tests/browser/intercom-conversation-viewer.spec.mjs +76 -53
  17. package/tests/browser/user-noticeable-fixes.spec.mjs +51 -0
  18. package/tests/browser/windows-drive-parent.spec.mjs +198 -0
  19. package/tests/codex-fast-mode-static.test.mjs +2 -2
  20. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  21. package/tests/control-visibility-static.test.mjs +3 -3
  22. package/tests/controls-layout-static.test.mjs +3 -3
  23. package/tests/durable-rpc-supervisor-harness.test.mjs +9 -0
  24. package/tests/events-tree-context-menu-static.test.mjs +3 -3
  25. package/tests/fast-mode-client-static.test.mjs +1 -1
  26. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  27. package/tests/file-viewer-image-static.test.mjs +3 -3
  28. package/tests/fixtures/fake-pi.mjs +3 -3
  29. package/tests/guided-git-activation-static.test.mjs +24 -12
  30. package/tests/guided-git-fallback-runtime.test.mjs +209 -270
  31. package/tests/guided-git-fallback-ui-static.test.mjs +2 -2
  32. package/tests/guided-git-message-reliability-static.test.mjs +2 -1
  33. package/tests/guided-git-optional-feature.test.mjs +8 -5
  34. package/tests/http-endpoints-harness.test.mjs +22 -4
  35. package/tests/intercom-conversation-viewer-static.test.mjs +7 -6
  36. package/tests/intercom-tag-layout-static.test.mjs +35 -16
  37. package/tests/intercom-tag-overflow-layout.test.mjs +87 -0
  38. package/tests/main-output-loading-static.test.mjs +3 -3
  39. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  40. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  41. package/tests/mobile-foundation-static.test.mjs +3 -3
  42. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  43. package/tests/mobile-static.test.mjs +11 -6
  44. package/tests/open-issue-wizard-static.test.mjs +1 -1
  45. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  46. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  47. package/tests/questionnaire-dialog.test.mjs +3 -3
  48. package/tests/remote-auth-settings-harness.test.mjs +18 -3
  49. package/tests/resource-tui-extension.test.mjs +2 -1
  50. package/tests/session-sampling-ui-static.test.mjs +3 -3
  51. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  52. package/tests/subagent-observability-static.test.mjs +2 -2
  53. package/tests/syntax-highlighting-static.test.mjs +3 -3
  54. package/tests/theme-customizer-static.test.mjs +1 -1
  55. package/tests/tui-model-profile-selector.test.mjs +102 -0
  56. package/tests/tui-resource-selector.test.mjs +74 -0
  57. package/tests/webui-settings-locking.test.mjs +32 -1
  58. package/tests/windows-drive-cwd-picker-static.test.mjs +81 -0
  59. package/tests/windows-drive-roots.test.mjs +130 -0
@@ -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
- return Promise.all(names.map(async (name) => {
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 = JSON.parse(await readFile(recordFile, "utf8"));
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
- return { ...value, name, recordFile, valid };
255
- } catch {
256
- return { name, recordFile, valid: false };
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 token = `${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
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 removedDeadOwner = false;
361
+ let removedStaleRecord = false;
331
362
  for (const record of records) {
332
- if (record.valid && lockOwnerIsDead(record.pid)) {
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
- removedDeadOwner = true;
373
+ removedStaleRecord = true;
335
374
  }
336
375
  }
337
- if (removedDeadOwner) continue;
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
+ }
@@ -0,0 +1,114 @@
1
+ import { win32 } from "node:path";
2
+
3
+ export const WINDOWS_DRIVES_PICKER_PATH = "::pi-webui-windows-drives::";
4
+ export const WINDOWS_DRIVE_DISCOVERY_TIMEOUT_MS = 3_000;
5
+ export const WINDOWS_DRIVE_DISCOVERY_MAX_OUTPUT = 4_096;
6
+ export const WINDOWS_DRIVE_DISCOVERY_CACHE_TTL_MS = 10_000;
7
+
8
+ const WINDOWS_DRIVE_ROOT_PATTERN = /^[A-Za-z]:[\\/]$/;
9
+ const WINDOWS_DRIVE_DESIGNATOR_PATTERN = /^[A-Za-z]:$/;
10
+ const WINDOWS_DRIVE_DISCOVERY_SCRIPT = [
11
+ "[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false);",
12
+ "[System.IO.DriveInfo]::GetDrives()",
13
+ "| Where-Object { try { $_.IsReady } catch { $false } }",
14
+ "| ForEach-Object { $_.RootDirectory.FullName }",
15
+ ].join(" ");
16
+
17
+ export function normalizeWindowsDriveRoot(value) {
18
+ const root = String(value ?? "");
19
+ if (!WINDOWS_DRIVE_ROOT_PATTERN.test(root)) return null;
20
+ return `${root[0].toUpperCase()}:\\`;
21
+ }
22
+
23
+ export function isWindowsDriveRoot(value) {
24
+ return normalizeWindowsDriveRoot(value) !== null;
25
+ }
26
+
27
+ export function parseWindowsDriveRoots(output) {
28
+ return mergeWindowsDriveRoots(String(output ?? "").split(/\r?\n/));
29
+ }
30
+
31
+ export function windowsDriveRootsFromKnownPaths(values) {
32
+ const roots = [];
33
+ for (const value of values || []) {
34
+ const candidate = String(value ?? "");
35
+ if (!candidate) continue;
36
+ if (WINDOWS_DRIVE_DESIGNATOR_PATTERN.test(candidate)) {
37
+ roots.push(`${candidate}\\`);
38
+ continue;
39
+ }
40
+ roots.push(win32.parse(candidate).root);
41
+ }
42
+ return mergeWindowsDriveRoots(roots);
43
+ }
44
+
45
+ export function mergeWindowsDriveRoots(...groups) {
46
+ const roots = new Map();
47
+ for (const group of groups) {
48
+ for (const value of group || []) {
49
+ const root = normalizeWindowsDriveRoot(value);
50
+ if (root) roots.set(root.toLowerCase(), root);
51
+ }
52
+ }
53
+ return [...roots.values()].sort((left, right) => left.localeCompare(right, "en", { sensitivity: "base" }));
54
+ }
55
+
56
+ export function windowsDrivesPickerData(driveRoots, roots = []) {
57
+ return {
58
+ cwd: "",
59
+ displayCwd: "This PC",
60
+ parent: null,
61
+ roots,
62
+ directories: mergeWindowsDriveRoots(driveRoots).map((root) => ({
63
+ name: root,
64
+ cwd: root,
65
+ displayCwd: root,
66
+ hidden: false,
67
+ })),
68
+ truncated: false,
69
+ selectable: false,
70
+ };
71
+ }
72
+
73
+ export function createWindowsDriveRootDiscovery({
74
+ runCommand,
75
+ now = Date.now,
76
+ cacheTtlMs = WINDOWS_DRIVE_DISCOVERY_CACHE_TTL_MS,
77
+ } = {}) {
78
+ if (typeof runCommand !== "function") throw new TypeError("runCommand is required");
79
+
80
+ let cached = { expiresAt: 0, roots: [] };
81
+ let pending = null;
82
+
83
+ async function discover(cwd) {
84
+ let roots = [];
85
+ try {
86
+ const result = await runCommand("powershell.exe", [
87
+ "-NoLogo",
88
+ "-NoProfile",
89
+ "-NonInteractive",
90
+ "-Command",
91
+ WINDOWS_DRIVE_DISCOVERY_SCRIPT,
92
+ ], {
93
+ cwd,
94
+ timeoutMs: WINDOWS_DRIVE_DISCOVERY_TIMEOUT_MS,
95
+ maxOutputLength: WINDOWS_DRIVE_DISCOVERY_MAX_OUTPUT,
96
+ utf8Output: true,
97
+ });
98
+ if (result?.exitCode === 0 && !result.timedOut && !result.stdoutTruncated && !result.error) {
99
+ roots = parseWindowsDriveRoots(result.stdout);
100
+ }
101
+ } catch {
102
+ // Known roots keep the picker usable when PowerShell is unavailable.
103
+ }
104
+ cached = { expiresAt: now() + Math.max(0, cacheTtlMs), roots };
105
+ return roots;
106
+ }
107
+
108
+ return async function getWindowsDriveRoots({ cwd, knownPaths = [] } = {}) {
109
+ const knownRoots = windowsDriveRootsFromKnownPaths(knownPaths);
110
+ if (cached.expiresAt > now()) return mergeWindowsDriveRoots(cached.roots, knownRoots);
111
+ if (!pending) pending = discover(cwd).finally(() => { pending = null; });
112
+ return mergeWindowsDriveRoots(await pending, knownRoots);
113
+ };
114
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firstpick/pi-package-webui",
3
- "version": "0.9.8",
3
+ "version": "0.10.0",
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",
@@ -56,6 +56,8 @@
56
56
  "tests",
57
57
  "lib/WEBUI_TUI_NATIVE_PARITY.json",
58
58
  "README.md",
59
+ "TECHNICAL.md",
60
+ "DEVELOPMENT.md",
59
61
  "LICENSE"
60
62
  ],
61
63
  "engines": {