@firstpick/pi-package-webui 0.9.9 → 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 (56) hide show
  1. package/DEVELOPMENT.md +42 -13
  2. package/README.md +7 -7
  3. package/TECHNICAL.md +8 -8
  4. package/bin/pi-webui.mjs +197 -63
  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/package.json +1 -1
  10. package/public/app.js +220 -73
  11. package/public/index.html +2 -2
  12. package/public/service-worker.js +1 -1
  13. package/public/styles.css +63 -15
  14. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  15. package/tests/browser/intercom-conversation-viewer.spec.mjs +76 -53
  16. package/tests/browser/user-noticeable-fixes.spec.mjs +51 -0
  17. package/tests/codex-fast-mode-static.test.mjs +2 -2
  18. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  19. package/tests/control-visibility-static.test.mjs +3 -3
  20. package/tests/controls-layout-static.test.mjs +3 -3
  21. package/tests/durable-rpc-supervisor-harness.test.mjs +9 -0
  22. package/tests/events-tree-context-menu-static.test.mjs +3 -3
  23. package/tests/fast-mode-client-static.test.mjs +1 -1
  24. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  25. package/tests/file-viewer-image-static.test.mjs +3 -3
  26. package/tests/fixtures/fake-pi.mjs +3 -3
  27. package/tests/guided-git-activation-static.test.mjs +24 -12
  28. package/tests/guided-git-fallback-runtime.test.mjs +209 -270
  29. package/tests/guided-git-fallback-ui-static.test.mjs +2 -2
  30. package/tests/guided-git-message-reliability-static.test.mjs +2 -1
  31. package/tests/guided-git-optional-feature.test.mjs +8 -5
  32. package/tests/http-endpoints-harness.test.mjs +22 -4
  33. package/tests/intercom-conversation-viewer-static.test.mjs +7 -6
  34. package/tests/intercom-tag-layout-static.test.mjs +35 -16
  35. package/tests/intercom-tag-overflow-layout.test.mjs +87 -0
  36. package/tests/main-output-loading-static.test.mjs +3 -3
  37. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  38. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  39. package/tests/mobile-foundation-static.test.mjs +3 -3
  40. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  41. package/tests/mobile-static.test.mjs +11 -6
  42. package/tests/open-issue-wizard-static.test.mjs +1 -1
  43. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  44. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  45. package/tests/questionnaire-dialog.test.mjs +3 -3
  46. package/tests/remote-auth-settings-harness.test.mjs +18 -3
  47. package/tests/resource-tui-extension.test.mjs +2 -1
  48. package/tests/session-sampling-ui-static.test.mjs +3 -3
  49. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  50. package/tests/subagent-observability-static.test.mjs +2 -2
  51. package/tests/syntax-highlighting-static.test.mjs +3 -3
  52. package/tests/theme-customizer-static.test.mjs +1 -1
  53. package/tests/tui-model-profile-selector.test.mjs +102 -0
  54. package/tests/tui-resource-selector.test.mjs +74 -0
  55. package/tests/webui-settings-locking.test.mjs +32 -1
  56. package/tests/windows-drive-cwd-picker-static.test.mjs +3 -3
@@ -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.9.9",
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",