@firstpick/pi-package-webui 0.8.1 → 0.8.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.
- package/README.md +21 -3
- package/bin/pi-webui.mjs +287 -32
- package/lib/component-update-state.mjs +126 -0
- package/lib/git-workflow-preferences.mjs +246 -19
- package/lib/thinking-stream-recovery.mjs +156 -0
- package/lib/trust-boundaries.mjs +1 -0
- package/lib/ui-layout-settings.mjs +254 -0
- package/package.json +5 -3
- package/public/app.js +3072 -142
- package/public/index.html +188 -39
- package/public/service-worker.js +1 -1
- package/public/styles.css +1091 -39
- package/tests/boot-failure-diagnostics.test.mjs +63 -5
- package/tests/browser/composer-action-grid-reorder.spec.mjs +303 -0
- package/tests/browser/control-deck-component-updates.spec.mjs +180 -0
- package/tests/browser/feature-decision-output-popup.spec.mjs +156 -0
- package/tests/browser/interaction-continuity.spec.mjs +187 -0
- package/tests/browser/mobile-foundation.spec.mjs +11 -0
- package/tests/browser/persistent-ui-layout.spec.mjs +744 -0
- package/tests/browser/side-panel-section-reorder.spec.mjs +101 -0
- package/tests/browser/stats-overlay.spec.mjs +265 -0
- package/tests/codex-fast-mode-static.test.mjs +2 -2
- package/tests/component-update-api-static.test.mjs +67 -0
- package/tests/component-update-state.test.mjs +80 -0
- package/tests/composer-action-grid-reorder-static.test.mjs +63 -0
- package/tests/control-deck-component-updates-static.test.mjs +251 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/feature-decision-output-popup-static.test.mjs +172 -0
- package/tests/fixtures/fake-pi.mjs +180 -6
- package/tests/footer-provider-usage-visual-static.test.mjs +71 -0
- package/tests/git-workflow-preferences.test.mjs +4 -2
- package/tests/http-endpoints-harness.test.mjs +88 -1
- package/tests/interaction-state-stability-static.test.mjs +24 -4
- package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
- package/tests/mobile-foundation-static.test.mjs +6 -4
- package/tests/mobile-phone-experience-static.test.mjs +1 -1
- package/tests/mobile-static.test.mjs +34 -16
- package/tests/native-parity-harness.test.mjs +2 -0
- package/tests/open-issue-wizard-static.test.mjs +1 -1
- package/tests/persistent-ui-layout-static.test.mjs +267 -0
- package/tests/questionnaire-dialog.test.mjs +511 -0
- package/tests/queue-edit-reorder-static.test.mjs +1 -0
- package/tests/remote-auth-settings-harness.test.mjs +1 -1
- package/tests/side-panel-resize-static.test.mjs +1 -0
- package/tests/side-panel-section-reorder-static.test.mjs +68 -0
- package/tests/sse-backpressure-harness.test.mjs +51 -12
- package/tests/stats-dashboard-static.test.mjs +266 -0
- package/tests/subagent-launch-slots.test.mjs +1 -1
- package/tests/thinking-stream-recovery.test.mjs +88 -0
- package/tests/ui-layout-settings.test.mjs +92 -0
- package/tests/webui-settings-locking.test.mjs +159 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
export const UI_LAYOUT_VERSION = 1;
|
|
4
|
+
export const UI_LAYOUT_REQUEST_MAX_BYTES = 32 * 1024;
|
|
5
|
+
export const UI_LAYOUT_LIMITS = Object.freeze({
|
|
6
|
+
idLength: 256,
|
|
7
|
+
titleLength: 160,
|
|
8
|
+
listItems: 128,
|
|
9
|
+
groups: 32,
|
|
10
|
+
gridColumns: 24,
|
|
11
|
+
gridSlots: 4096,
|
|
12
|
+
fileViewerWidthMin: 384,
|
|
13
|
+
fileViewerWidthMax: 4096,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const UNSAFE_OBJECT_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
17
|
+
const TERMINAL_TAB_LAYOUTS = new Set(["top", "left"]);
|
|
18
|
+
|
|
19
|
+
function objectValue(value) {
|
|
20
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function own(value, key) {
|
|
24
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function invalid(message) {
|
|
28
|
+
const error = new TypeError(message);
|
|
29
|
+
error.code = "UI_LAYOUT_INVALID";
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function assertOnlyKeys(value, allowed, label) {
|
|
34
|
+
const unknown = Object.keys(value).filter((key) => !allowed.has(key));
|
|
35
|
+
if (unknown.length) invalid(`${label} contains unsupported field${unknown.length === 1 ? "" : "s"}: ${unknown.join(", ")}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function boundedString(value, label, maxLength = UI_LAYOUT_LIMITS.idLength) {
|
|
39
|
+
if (typeof value !== "string" || value.length === 0 || value.length > maxLength || value !== value.trim() || /[\u0000-\u001f\u007f]/u.test(value)) {
|
|
40
|
+
invalid(`${label} must be a non-empty trimmed string of at most ${maxLength} characters without control characters`);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function boundedUniqueStringList(value, label) {
|
|
46
|
+
if (!Array.isArray(value) || value.length > UI_LAYOUT_LIMITS.listItems) invalid(`${label} must be an array with at most ${UI_LAYOUT_LIMITS.listItems} items`);
|
|
47
|
+
const seen = new Set();
|
|
48
|
+
return value.map((item, index) => {
|
|
49
|
+
const result = boundedString(item, `${label}[${index}]`);
|
|
50
|
+
if (seen.has(result)) invalid(`${label} must not contain duplicate values`);
|
|
51
|
+
seen.add(result);
|
|
52
|
+
return result;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function nullable(value, validate) {
|
|
57
|
+
return value === null ? null : validate(value);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function validateSidePanel(value, { partial = false } = {}) {
|
|
61
|
+
const source = objectValue(value);
|
|
62
|
+
if (!source) invalid("layout.sidePanel must be an object or null");
|
|
63
|
+
const fields = new Set(["sectionOrder", "collapsedSectionIds", "hiddenSectionIds", "collapsed"]);
|
|
64
|
+
assertOnlyKeys(source, fields, "layout.sidePanel");
|
|
65
|
+
if (partial && Object.keys(source).length === 0) invalid("layout.sidePanel must name at least one field");
|
|
66
|
+
const result = {};
|
|
67
|
+
for (const field of ["sectionOrder", "collapsedSectionIds", "hiddenSectionIds"]) {
|
|
68
|
+
if (!partial || own(source, field)) result[field] = nullable(source[field] ?? null, (entry) => boundedUniqueStringList(entry, `layout.sidePanel.${field}`));
|
|
69
|
+
}
|
|
70
|
+
if (!partial || own(source, "collapsed")) {
|
|
71
|
+
const collapsed = source.collapsed ?? null;
|
|
72
|
+
if (collapsed !== null && typeof collapsed !== "boolean") invalid("layout.sidePanel.collapsed must be a boolean or null");
|
|
73
|
+
result.collapsed = collapsed;
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function validateGrid(value) {
|
|
79
|
+
const source = objectValue(value);
|
|
80
|
+
if (!source) invalid("layout.composerActions.grid must be an object or null");
|
|
81
|
+
assertOnlyKeys(source, new Set(["version", "columns", "positions"]), "layout.composerActions.grid");
|
|
82
|
+
if (source.version !== 2) invalid("layout.composerActions.grid.version must be 2");
|
|
83
|
+
if (!Number.isInteger(source.columns) || source.columns < 1 || source.columns > UI_LAYOUT_LIMITS.gridColumns) {
|
|
84
|
+
invalid(`layout.composerActions.grid.columns must be an integer between 1 and ${UI_LAYOUT_LIMITS.gridColumns}`);
|
|
85
|
+
}
|
|
86
|
+
const positions = objectValue(source.positions);
|
|
87
|
+
if (!positions) invalid("layout.composerActions.grid.positions must be an object");
|
|
88
|
+
const entries = Object.entries(positions);
|
|
89
|
+
if (entries.length > UI_LAYOUT_LIMITS.listItems) invalid(`layout.composerActions.grid.positions must contain at most ${UI_LAYOUT_LIMITS.listItems} items`);
|
|
90
|
+
const result = {};
|
|
91
|
+
const usedSlots = new Set();
|
|
92
|
+
for (const [rawId, slot] of entries) {
|
|
93
|
+
const id = boundedString(rawId, "layout.composerActions.grid position id");
|
|
94
|
+
if (UNSAFE_OBJECT_KEYS.has(id)) invalid("layout.composerActions.grid contains an unsupported position id");
|
|
95
|
+
if (!Number.isInteger(slot) || slot < 0 || slot >= UI_LAYOUT_LIMITS.gridSlots) {
|
|
96
|
+
invalid(`layout.composerActions.grid positions must be integers between 0 and ${UI_LAYOUT_LIMITS.gridSlots - 1}`);
|
|
97
|
+
}
|
|
98
|
+
if (usedSlots.has(slot)) invalid("layout.composerActions.grid positions must not reuse a slot");
|
|
99
|
+
usedSlots.add(slot);
|
|
100
|
+
result[id] = slot;
|
|
101
|
+
}
|
|
102
|
+
return { version: 2, columns: source.columns, positions: result };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function validateComposerActions(value, { partial = false } = {}) {
|
|
106
|
+
const source = objectValue(value);
|
|
107
|
+
if (!source) invalid("layout.composerActions must be an object or null");
|
|
108
|
+
assertOnlyKeys(source, new Set(["order", "grid"]), "layout.composerActions");
|
|
109
|
+
if (partial && (!own(source, "order") || !own(source, "grid"))) {
|
|
110
|
+
invalid("layout.composerActions must include order and grid together");
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
order: nullable(source.order ?? null, (entry) => boundedUniqueStringList(entry, "layout.composerActions.order")),
|
|
114
|
+
grid: nullable(source.grid ?? null, validateGrid),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function validateCustomGroups(value) {
|
|
119
|
+
const source = objectValue(value);
|
|
120
|
+
if (!source) invalid("layout.terminalTabs.customGroups must be an object or null");
|
|
121
|
+
assertOnlyKeys(source, new Set(["version", "groups"]), "layout.terminalTabs.customGroups");
|
|
122
|
+
if (source.version !== 1) invalid("layout.terminalTabs.customGroups.version must be 1");
|
|
123
|
+
if (!Array.isArray(source.groups) || source.groups.length > UI_LAYOUT_LIMITS.groups) {
|
|
124
|
+
invalid(`layout.terminalTabs.customGroups.groups must be an array with at most ${UI_LAYOUT_LIMITS.groups} groups`);
|
|
125
|
+
}
|
|
126
|
+
const groupIds = new Set();
|
|
127
|
+
const claimedTabIds = new Set();
|
|
128
|
+
const groups = source.groups.map((group, index) => {
|
|
129
|
+
const record = objectValue(group);
|
|
130
|
+
if (!record) invalid(`layout.terminalTabs.customGroups.groups[${index}] must be an object`);
|
|
131
|
+
assertOnlyKeys(record, new Set(["id", "title", "tabIds"]), `layout.terminalTabs.customGroups.groups[${index}]`);
|
|
132
|
+
const id = boundedString(record.id, `layout.terminalTabs.customGroups.groups[${index}].id`);
|
|
133
|
+
if (groupIds.has(id)) invalid("layout.terminalTabs.customGroups group ids must be unique");
|
|
134
|
+
groupIds.add(id);
|
|
135
|
+
const title = boundedString(record.title, `layout.terminalTabs.customGroups.groups[${index}].title`, UI_LAYOUT_LIMITS.titleLength);
|
|
136
|
+
const tabIds = boundedUniqueStringList(record.tabIds, `layout.terminalTabs.customGroups.groups[${index}].tabIds`);
|
|
137
|
+
for (const tabId of tabIds) {
|
|
138
|
+
if (claimedTabIds.has(tabId)) invalid("layout.terminalTabs.customGroups tab ids may appear in only one group");
|
|
139
|
+
claimedTabIds.add(tabId);
|
|
140
|
+
}
|
|
141
|
+
return { id, title, tabIds };
|
|
142
|
+
});
|
|
143
|
+
return { version: 1, groups };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function validateTerminalTabs(value, { partial = false } = {}) {
|
|
147
|
+
const source = objectValue(value);
|
|
148
|
+
if (!source) invalid("layout.terminalTabs must be an object or null");
|
|
149
|
+
assertOnlyKeys(source, new Set(["layout", "customGroups"]), "layout.terminalTabs");
|
|
150
|
+
if (partial && Object.keys(source).length === 0) invalid("layout.terminalTabs must name at least one field");
|
|
151
|
+
const result = {};
|
|
152
|
+
if (!partial || own(source, "layout")) {
|
|
153
|
+
const layout = source.layout ?? null;
|
|
154
|
+
if (layout !== null && !TERMINAL_TAB_LAYOUTS.has(layout)) invalid("layout.terminalTabs.layout must be top, left, or null");
|
|
155
|
+
result.layout = layout;
|
|
156
|
+
}
|
|
157
|
+
if (!partial || own(source, "customGroups")) result.customGroups = nullable(source.customGroups ?? null, validateCustomGroups);
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function validateFileViewerWidth(value) {
|
|
162
|
+
if (!Number.isFinite(value) || value < UI_LAYOUT_LIMITS.fileViewerWidthMin || value > UI_LAYOUT_LIMITS.fileViewerWidthMax) {
|
|
163
|
+
invalid(`layout.fileViewerWidth must be between ${UI_LAYOUT_LIMITS.fileViewerWidthMin} and ${UI_LAYOUT_LIMITS.fileViewerWidthMax} pixels or null`);
|
|
164
|
+
}
|
|
165
|
+
return Math.round(value);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function defaultUiLayout() {
|
|
169
|
+
return {
|
|
170
|
+
version: UI_LAYOUT_VERSION,
|
|
171
|
+
sidePanel: { sectionOrder: null, collapsedSectionIds: null, hiddenSectionIds: null, collapsed: null },
|
|
172
|
+
composerActions: { order: null, grid: null },
|
|
173
|
+
footerScopedModelOrder: null,
|
|
174
|
+
terminalTabs: { layout: null, customGroups: null },
|
|
175
|
+
fileViewerWidth: null,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function softField(validate, fallback = null) {
|
|
180
|
+
try {
|
|
181
|
+
return validate();
|
|
182
|
+
} catch {
|
|
183
|
+
return fallback;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function normalizeUiLayout(value) {
|
|
188
|
+
const source = objectValue(value);
|
|
189
|
+
const defaults = defaultUiLayout();
|
|
190
|
+
if (!source || source.version !== UI_LAYOUT_VERSION) return defaults;
|
|
191
|
+
const sidePanel = objectValue(source.sidePanel);
|
|
192
|
+
const composerActions = objectValue(source.composerActions);
|
|
193
|
+
const terminalTabs = objectValue(source.terminalTabs);
|
|
194
|
+
return {
|
|
195
|
+
version: UI_LAYOUT_VERSION,
|
|
196
|
+
sidePanel: {
|
|
197
|
+
sectionOrder: softField(() => nullable(sidePanel?.sectionOrder ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.sidePanel.sectionOrder"))),
|
|
198
|
+
collapsedSectionIds: softField(() => nullable(sidePanel?.collapsedSectionIds ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.sidePanel.collapsedSectionIds"))),
|
|
199
|
+
hiddenSectionIds: softField(() => nullable(sidePanel?.hiddenSectionIds ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.sidePanel.hiddenSectionIds"))),
|
|
200
|
+
collapsed: typeof sidePanel?.collapsed === "boolean" ? sidePanel.collapsed : null,
|
|
201
|
+
},
|
|
202
|
+
composerActions: {
|
|
203
|
+
order: softField(() => nullable(composerActions?.order ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.composerActions.order"))),
|
|
204
|
+
grid: softField(() => nullable(composerActions?.grid ?? null, validateGrid)),
|
|
205
|
+
},
|
|
206
|
+
footerScopedModelOrder: softField(() => nullable(source.footerScopedModelOrder ?? null, (entry) => boundedUniqueStringList(entry, "uiLayout.footerScopedModelOrder"))),
|
|
207
|
+
terminalTabs: {
|
|
208
|
+
layout: TERMINAL_TAB_LAYOUTS.has(terminalTabs?.layout) ? terminalTabs.layout : null,
|
|
209
|
+
customGroups: softField(() => nullable(terminalTabs?.customGroups ?? null, validateCustomGroups)),
|
|
210
|
+
},
|
|
211
|
+
fileViewerWidth: softField(() => nullable(source.fileViewerWidth ?? null, validateFileViewerWidth)),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export function validateUiLayoutPatch(value) {
|
|
216
|
+
const source = objectValue(value);
|
|
217
|
+
if (!source) invalid("layout must be an object");
|
|
218
|
+
const allowed = new Set(["version", "sidePanel", "composerActions", "footerScopedModelOrder", "terminalTabs", "fileViewerWidth"]);
|
|
219
|
+
assertOnlyKeys(source, allowed, "layout");
|
|
220
|
+
if (own(source, "version") && source.version !== UI_LAYOUT_VERSION) invalid(`layout.version must be ${UI_LAYOUT_VERSION}`);
|
|
221
|
+
const mutableFields = [...allowed].filter((field) => field !== "version" && own(source, field));
|
|
222
|
+
if (mutableFields.length === 0) invalid("layout must name at least one mutable field");
|
|
223
|
+
const patch = {};
|
|
224
|
+
if (own(source, "sidePanel")) patch.sidePanel = nullable(source.sidePanel, (entry) => validateSidePanel(entry, { partial: true }));
|
|
225
|
+
if (own(source, "composerActions")) patch.composerActions = nullable(source.composerActions, (entry) => validateComposerActions(entry, { partial: true }));
|
|
226
|
+
if (own(source, "footerScopedModelOrder")) patch.footerScopedModelOrder = nullable(source.footerScopedModelOrder, (entry) => boundedUniqueStringList(entry, "layout.footerScopedModelOrder"));
|
|
227
|
+
if (own(source, "terminalTabs")) patch.terminalTabs = nullable(source.terminalTabs, (entry) => validateTerminalTabs(entry, { partial: true }));
|
|
228
|
+
if (own(source, "fileViewerWidth")) patch.fileViewerWidth = nullable(source.fileViewerWidth, validateFileViewerWidth);
|
|
229
|
+
return patch;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function mergeUiLayout(current, patch) {
|
|
233
|
+
const base = normalizeUiLayout(current);
|
|
234
|
+
const value = validateUiLayoutPatch(patch);
|
|
235
|
+
const merged = { ...base };
|
|
236
|
+
if (own(value, "sidePanel")) {
|
|
237
|
+
merged.sidePanel = value.sidePanel === null
|
|
238
|
+
? defaultUiLayout().sidePanel
|
|
239
|
+
: { ...base.sidePanel, ...value.sidePanel };
|
|
240
|
+
}
|
|
241
|
+
if (own(value, "composerActions")) merged.composerActions = value.composerActions === null ? defaultUiLayout().composerActions : value.composerActions;
|
|
242
|
+
if (own(value, "footerScopedModelOrder")) merged.footerScopedModelOrder = value.footerScopedModelOrder;
|
|
243
|
+
if (own(value, "terminalTabs")) {
|
|
244
|
+
merged.terminalTabs = value.terminalTabs === null
|
|
245
|
+
? defaultUiLayout().terminalTabs
|
|
246
|
+
: { ...base.terminalTabs, ...value.terminalTabs };
|
|
247
|
+
}
|
|
248
|
+
if (own(value, "fileViewerWidth")) merged.fileViewerWidth = value.fileViewerWidth;
|
|
249
|
+
return normalizeUiLayout(merged);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function uiLayoutRevision(value) {
|
|
253
|
+
return createHash("sha256").update(JSON.stringify(normalizeUiLayout(value))).digest("hex");
|
|
254
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firstpick/pi-package-webui",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
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",
|
|
@@ -36,10 +36,12 @@
|
|
|
36
36
|
"node_modules/@firstpick/pi-extension-stats/index.ts",
|
|
37
37
|
"node_modules/@firstpick/pi-extension-todo-progress/index.ts",
|
|
38
38
|
"node_modules/@firstpick/pi-extension-tools/index.ts",
|
|
39
|
-
"node_modules/@firstpick/pi-package-remote-webui/index.ts"
|
|
39
|
+
"node_modules/@firstpick/pi-package-remote-webui/index.ts",
|
|
40
|
+
"node_modules/@firstpick/pi-package-questionnaire/index.ts"
|
|
40
41
|
],
|
|
41
42
|
"skills": [
|
|
42
|
-
"node_modules/@firstpick/pi-extension-release-aur/skills"
|
|
43
|
+
"node_modules/@firstpick/pi-extension-release-aur/skills",
|
|
44
|
+
"node_modules/@firstpick/pi-package-questionnaire/skills"
|
|
43
45
|
],
|
|
44
46
|
"prompts": [
|
|
45
47
|
"node_modules/@firstpick/pi-prompts-git-pr/prompts"
|