@firstpick/pi-package-webui 0.10.1 → 0.10.3

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 (55) hide show
  1. package/DEVELOPMENT.md +41 -19
  2. package/README.md +13 -3
  3. package/TECHNICAL.md +16 -2
  4. package/bin/pi-webui.mjs +257 -76
  5. package/index.ts +1 -256
  6. package/lib/append-system-selection.mjs +311 -0
  7. package/lib/git-workflow-preferences.mjs +6 -0
  8. package/lib/trust-boundaries.mjs +37 -0
  9. package/package.json +1 -1
  10. package/public/app.js +162 -7
  11. package/public/index.html +5 -2
  12. package/public/service-worker.js +1 -1
  13. package/tests/append-system-http.test.mjs +622 -0
  14. package/tests/append-system-selection.test.mjs +259 -0
  15. package/tests/append-system-selector-static.test.mjs +95 -0
  16. package/tests/boot-failure-diagnostics.test.mjs +2 -2
  17. package/tests/codex-fast-mode-static.test.mjs +2 -2
  18. package/tests/common-options-submenus-interaction-static.test.mjs +4 -0
  19. package/tests/common-options-submenus-markup-static.test.mjs +2 -1
  20. package/tests/composer-action-grid-reorder-static.test.mjs +2 -2
  21. package/tests/control-visibility-static.test.mjs +2 -2
  22. package/tests/controls-layout-static.test.mjs +2 -2
  23. package/tests/events-tree-context-menu-static.test.mjs +2 -2
  24. package/tests/fast-mode-client-static.test.mjs +1 -1
  25. package/tests/feature-decision-output-popup-static.test.mjs +1 -1
  26. package/tests/file-viewer-image-static.test.mjs +2 -2
  27. package/tests/guided-git-activation-static.test.mjs +10 -3
  28. package/tests/guided-git-fallback-runtime.test.mjs +46 -21
  29. package/tests/guided-git-fallback-ui-static.test.mjs +3 -3
  30. package/tests/intercom-conversation-viewer-static.test.mjs +2 -2
  31. package/tests/main-output-loading-static.test.mjs +2 -2
  32. package/tests/middle-button-drag-scroll-static.test.mjs +2 -2
  33. package/tests/mobile-continuity-tablet-static.test.mjs +2 -2
  34. package/tests/mobile-foundation-static.test.mjs +2 -2
  35. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  36. package/tests/mobile-static.test.mjs +3 -2
  37. package/tests/native-parity-harness.test.mjs +7 -0
  38. package/tests/open-issue-wizard-static.test.mjs +1 -1
  39. package/tests/optional-feature-prompt-impact-static.test.mjs +2 -2
  40. package/tests/persistent-ui-layout-static.test.mjs +2 -2
  41. package/tests/prompt-input-vertical-scroll-static.test.mjs +2 -2
  42. package/tests/questionnaire-dialog.test.mjs +2 -2
  43. package/tests/resource-tui-extension.test.mjs +4 -18
  44. package/tests/session-sampling-ui-static.test.mjs +2 -2
  45. package/tests/side-panel-section-height-removal-static.test.mjs +2 -2
  46. package/tests/subagent-observability-static.test.mjs +2 -2
  47. package/tests/syntax-highlighting-static.test.mjs +2 -2
  48. package/tests/terminal-tab-prompt-tooltip-static.test.mjs +147 -0
  49. package/tests/terminal-tab-workspace-static.test.mjs +1 -1
  50. package/tests/theme-customizer-static.test.mjs +1 -1
  51. package/tests/windows-drive-cwd-picker-static.test.mjs +2 -2
  52. package/lib/tui-model-profile-selector.mjs +0 -183
  53. package/lib/tui-resource-selector.mjs +0 -173
  54. package/tests/tui-model-profile-selector.test.mjs +0 -102
  55. package/tests/tui-resource-selector.test.mjs +0 -74
@@ -34,7 +34,7 @@ assert.match(html, /role="alert" hidden>[\s\S]*Replace this exact target\?/, "ov
34
34
 
35
35
  assert.match(app, /from "\.\/theme-contract\.mjs"/, "frontend should consume the shared browser-safe theme contract");
36
36
  assert.match(serviceWorker, /"\/theme-contract\.mjs"/, "the PWA app shell should cache the startup-critical theme contract");
37
- assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v153"/, "adding the theme contract to the startup graph should advance the PWA cache identity");
37
+ assert.match(serviceWorker, /const CACHE_NAME = "pi-webui-pwa-v154"/, "adding the theme contract to the startup graph should advance the PWA cache identity");
38
38
  assert.match(pkg, /node --check public\/theme-contract\.mjs/, "the package check should syntax-check the startup-critical theme contract");
39
39
  assert.match(app, /function themeDraftFromCatalog\(theme, name = theme\?\.name\)[\s\S]*colors: cloneThemeDraft\(theme\?\.colors \|\| \{\}\)/, "catalog metadata should be projected into a schema-only editable draft");
40
40
  assert.match(app, /for \(const \{ name, label \} of group\.tokens\)/, "visual controls should render from the exact shared token inventory");
@@ -75,7 +75,7 @@ assert.match(development, /virtual \*\*This PC\*\* response with an empty cwd an
75
75
  assert.ok(packageJson.files.includes("TECHNICAL.md"), "the published package should include its advanced user reference");
76
76
  assert.ok(packageJson.files.includes("DEVELOPMENT.md"), "the published package should include its contributor guide");
77
77
  assert.match(html, /styles\.css\?v=152/, "the existing picker layout should retain its stylesheet revision");
78
- assert.match(html, /app\.js\?v=182/, "the changed picker behavior should advance the app revision");
79
- assert.match(serviceWorker, /pi-webui-pwa-v153/, "the changed browser assets should advance the PWA cache identity");
78
+ assert.match(html, /app\.js\?v=183/, "the changed picker behavior should advance the app revision");
79
+ assert.match(serviceWorker, /pi-webui-pwa-v154/, "the changed browser assets should advance the PWA cache identity");
80
80
 
81
81
  console.log("windows-drive-cwd-picker-static.test.mjs passed");
@@ -1,183 +0,0 @@
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
- }
@@ -1,173 +0,0 @@
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
- }
@@ -1,102 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { KeybindingsManager, setKeybindings, TUI_KEYBINDINGS } from "@earendil-works/pi-tui";
3
- import { TuiModelProfileSelectorComponent } from "../lib/tui-model-profile-selector.mjs";
4
-
5
- const theme = {
6
- fg: (_color, text) => text,
7
- bold: (text) => text,
8
- };
9
-
10
- function createSelector(config) {
11
- const selected = [];
12
- let cancelled = 0;
13
- const selector = new TuiModelProfileSelectorComponent(
14
- {
15
- title: "Tools Model Profile",
16
- subtitle: "Choose a profile to edit. This does not switch the active model.",
17
- configuredModelKeys: [],
18
- ...config,
19
- },
20
- theme,
21
- {
22
- onSelect: (model) => selected.push(model),
23
- onCancel: () => cancelled++,
24
- },
25
- );
26
- return { selector, selected, cancelled: () => cancelled };
27
- }
28
-
29
- setKeybindings(new KeybindingsManager(TUI_KEYBINDINGS));
30
-
31
- {
32
- const models = Array.from({ length: 15 }, (_, index) => ({
33
- provider: index % 2 === 0 ? "alpha" : "beta",
34
- id: `model-${String(index).padStart(2, "0")}`,
35
- name: `Model ${index}`,
36
- }));
37
- const active = models[12];
38
- const { selector, selected } = createSelector({
39
- models,
40
- activeModelKey: `${active.provider}\0${active.id}`,
41
- configuredModelKeys: [`${active.provider}\0${active.id}`],
42
- });
43
- const rendered = selector.render(120).join("\n");
44
- assert.match(rendered, /model-12 \[alpha\] \[active\] \[profile\]/, "the picker should open around the active model and mark configured profiles");
45
- assert.match(rendered, /Model Name: Model 12 · Profile: configured/);
46
-
47
- selector.handleInput("\x1b[B");
48
- selector.handleInput("\r");
49
- assert.equal(selected[0], models[13], "selection should return the exact model object rather than decoding its label");
50
- }
51
-
52
- {
53
- const models = Array.from({ length: 15 }, (_, index) => ({
54
- provider: "alpha",
55
- id: `model-${String(index).padStart(2, "0")}`,
56
- name: `Model ${index}`,
57
- }));
58
- const active = models[12];
59
- const { selector, selected } = createSelector({ models, activeModelKey: `${active.provider}\0${active.id}` });
60
- for (const character of "model-00") selector.handleInput(character);
61
- selector.handleInput("\r");
62
- assert.equal(selected[0], models[0], "a narrowing search should select its first match instead of retaining a stale list index");
63
- }
64
-
65
- {
66
- const models = [
67
- { provider: "alpha", id: "shared-a", name: "Shared Model" },
68
- { provider: "beta", id: "shared-b", name: "Shared Model" },
69
- { provider: "gamma", id: "other", name: "Other" },
70
- ];
71
- const { selector, selected } = createSelector({ models, activeModelKey: "" });
72
- for (const character of "beta") selector.handleInput(character);
73
- assert.equal(selector.getSearchInput().getValue(), "beta");
74
- assert.doesNotMatch(selector.render(100).join("\n"), /\[alpha\]/);
75
- selector.handleInput("\r");
76
- assert.equal(selected[0], models[1], "provider search should disambiguate models with the same display name");
77
- }
78
-
79
- {
80
- const { selector, cancelled } = createSelector({
81
- models: [{ provider: "alpha", id: "one", name: "One" }],
82
- activeModelKey: "",
83
- });
84
- for (const character of "missing") selector.handleInput(character);
85
- assert.match(selector.render(100).join("\n"), /No matching models/);
86
- selector.handleInput("\x03");
87
- assert.equal(selector.getSearchInput().getValue(), "", "Ctrl+C should clear search before cancelling");
88
- assert.equal(cancelled(), 0);
89
- selector.handleInput("\x03");
90
- assert.equal(cancelled(), 1);
91
- }
92
-
93
- {
94
- const { selector, cancelled } = createSelector({
95
- models: [{ provider: "alpha", id: "one", name: "One" }],
96
- activeModelKey: "",
97
- });
98
- selector.handleInput("\x1b");
99
- assert.equal(cancelled(), 1, "Escape should cancel model profile selection");
100
- }
101
-
102
- console.log("tui-model-profile-selector.test.mjs passed");
@@ -1,74 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { KeybindingsManager, setKeybindings, TUI_KEYBINDINGS } from "@earendil-works/pi-tui";
3
- import { TuiResourceSelectorComponent } from "../lib/tui-resource-selector.mjs";
4
-
5
- const theme = {
6
- fg: (_color, text) => text,
7
- bold: (text) => text,
8
- };
9
-
10
- function createSelector(enabledResourceNames = ["alpha", "gamma"]) {
11
- const saved = [];
12
- let cancelled = 0;
13
- const selector = new TuiResourceSelectorComponent(
14
- {
15
- title: "Tools Configuration",
16
- subtitle: "Session only. Changes apply only after Ctrl+S.",
17
- resources: ["alpha", "beta", "gamma"],
18
- enabledResourceNames,
19
- },
20
- theme,
21
- {
22
- onSave: (selection) => saved.push(selection),
23
- onCancel: () => cancelled++,
24
- },
25
- );
26
- return { selector, saved, cancelled: () => cancelled };
27
- }
28
-
29
- setKeybindings(new KeybindingsManager(TUI_KEYBINDINGS));
30
-
31
- {
32
- const { selector, saved } = createSelector();
33
- selector.handleInput("\x1b[B");
34
- selector.handleInput("\r");
35
- assert.match(selector.render(100).join("\n"), /3\/3 enabled.*\(unsaved\)/);
36
- selector.handleInput("\x13");
37
- assert.deepEqual(saved, [["alpha", "beta", "gamma"]], "Ctrl+S should save the current explicit selection");
38
- }
39
-
40
- {
41
- const { selector, saved } = createSelector();
42
- selector.handleInput("b");
43
- selector.handleInput("e");
44
- assert.equal(selector.getSearchInput().getValue(), "be");
45
- assert.doesNotMatch(selector.render(100).join("\n"), /alpha/);
46
-
47
- selector.handleInput("\x18");
48
- selector.handleInput("\x13");
49
- assert.deepEqual(saved.at(-1), ["alpha", "gamma"], "Ctrl+X should clear only resources matching the active search");
50
-
51
- selector.handleInput("\x01");
52
- selector.handleInput("\x13");
53
- assert.deepEqual(saved.at(-1), ["alpha", "beta", "gamma"], "Ctrl+A should enable only resources matching the active search");
54
- }
55
-
56
- {
57
- const { selector, cancelled } = createSelector();
58
- selector.handleInput("z");
59
- selector.handleInput("z");
60
- assert.match(selector.render(100).join("\n"), /No matching resources/);
61
- selector.handleInput("\x03");
62
- assert.equal(selector.getSearchInput().getValue(), "", "Ctrl+C should clear a non-empty search before cancelling");
63
- assert.equal(cancelled(), 0);
64
- selector.handleInput("\x03");
65
- assert.equal(cancelled(), 1, "Ctrl+C on an empty search should cancel");
66
- }
67
-
68
- {
69
- const { selector, cancelled } = createSelector();
70
- selector.handleInput("\x1b");
71
- assert.equal(cancelled(), 1, "Escape should cancel without saving");
72
- }
73
-
74
- console.log("tui-resource-selector.test.mjs passed");