@firstpick/pi-package-webui 0.7.7 → 0.7.9

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 (50) hide show
  1. package/README.md +23 -0
  2. package/bin/pi-webui-rpc-supervisor.mjs +115 -21
  3. package/bin/pi-webui.mjs +447 -88
  4. package/lib/queue-mutation.mjs +109 -0
  5. package/lib/rpc-supervisor-client.mjs +18 -2
  6. package/lib/rpc-supervisor-protocol.mjs +11 -2
  7. package/lib/scoped-models.mjs +19 -0
  8. package/lib/webui-workspaces.mjs +265 -0
  9. package/package.json +4 -4
  10. package/public/app.js +2227 -195
  11. package/public/index.html +143 -2
  12. package/public/issue-bot-client.mjs +344 -0
  13. package/public/issue-wizard-state.mjs +443 -0
  14. package/public/service-worker.js +3 -1
  15. package/public/styles.css +787 -56
  16. package/public/voice-conversation.mjs +1 -1
  17. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  18. package/tests/compaction-mutation-contract.test.mjs +166 -0
  19. package/tests/compaction-resume-harness.test.mjs +113 -2
  20. package/tests/compaction-static.test.mjs +5 -0
  21. package/tests/completion-signal-contract.test.mjs +156 -0
  22. package/tests/cwd-footer-reliability-static.test.mjs +112 -0
  23. package/tests/durable-rpc-supervisor-harness.test.mjs +25 -2
  24. package/tests/fast-mode-client-static.test.mjs +1 -1
  25. package/tests/file-selection-overlay-static.test.mjs +21 -0
  26. package/tests/file-viewer-search-static.test.mjs +65 -0
  27. package/tests/fixtures/compacting-pi.mjs +0 -0
  28. package/tests/fixtures/fake-pi.mjs +186 -49
  29. package/tests/footer-context-contrast-static.test.mjs +10 -0
  30. package/tests/git-panel-file-preview-static.test.mjs +20 -5
  31. package/tests/git-panel-render-stability-static.test.mjs +11 -1
  32. package/tests/http-endpoints-harness.test.mjs +160 -1
  33. package/tests/issue-bot-client.test.mjs +135 -0
  34. package/tests/issue-wizard-state.test.mjs +126 -0
  35. package/tests/mobile-static.test.mjs +61 -42
  36. package/tests/native-parity.test.mjs +3 -3
  37. package/tests/open-issue-wizard-static.test.mjs +75 -0
  38. package/tests/prompt-routing-tab-status.test.mjs +5 -0
  39. package/tests/queue-edit-reorder-static.test.mjs +101 -0
  40. package/tests/queue-mutation-contract.test.mjs +143 -0
  41. package/tests/rpc-supervisor-host.test.mjs +135 -2
  42. package/tests/rpc-supervisor-protocol.test.mjs +26 -0
  43. package/tests/scoped-models.test.mjs +42 -0
  44. package/tests/streaming-ui-coupling.test.mjs +3 -2
  45. package/tests/subagents-helper.test.mjs +216 -3
  46. package/tests/terminal-tab-workspace-static.test.mjs +101 -0
  47. package/tests/webui-workspaces-harness.test.mjs +223 -0
  48. package/tests/webui-workspaces.test.mjs +106 -0
  49. package/tests/workspace-save-load-static.test.mjs +69 -0
  50. package/webui-rpc-helper.mjs +300 -41
@@ -0,0 +1,443 @@
1
+ const CATEGORY_DEFINITIONS = Object.freeze([
2
+ { id: "feature", label: "Feature" },
3
+ { id: "bug", label: "Bug" },
4
+ { id: "ux", label: "UX" },
5
+ { id: "documentation", label: "Documentation" },
6
+ { id: "performance", label: "Performance" },
7
+ { id: "compatibility", label: "Compatibility" },
8
+ { id: "other", label: "Other" },
9
+ ]);
10
+
11
+ const TEMPLATE_DEFINITIONS = Object.freeze([
12
+ {
13
+ id: "feature-new-capability",
14
+ categoryIds: ["feature"],
15
+ label: "New capability",
16
+ description: "Propose a focused capability and define the outcome and acceptance boundary.",
17
+ fields: [
18
+ { id: "desiredOutcome", label: "Desired outcome", kind: "textarea", required: true },
19
+ {
20
+ id: "userImpact",
21
+ label: "Who benefits?",
22
+ kind: "select",
23
+ required: true,
24
+ options: [
25
+ { id: "all-users", label: "All users" },
26
+ { id: "new-users", label: "New users" },
27
+ { id: "advanced-users", label: "Advanced users" },
28
+ { id: "maintainers", label: "Maintainers" },
29
+ ],
30
+ },
31
+ { id: "acceptanceCriteria", label: "Acceptance criteria", kind: "textarea", required: true },
32
+ ],
33
+ },
34
+ {
35
+ id: "bug-defect-report",
36
+ categoryIds: ["bug"],
37
+ label: "Defect report",
38
+ description: "Report reproducible behavior that differs from the expected WebUI experience.",
39
+ fields: [
40
+ {
41
+ id: "severity",
42
+ label: "Severity",
43
+ kind: "choices",
44
+ required: true,
45
+ options: [
46
+ { id: "low", label: "Low — workaround available" },
47
+ { id: "medium", label: "Medium — degraded workflow" },
48
+ { id: "high", label: "High — key workflow blocked" },
49
+ ],
50
+ },
51
+ { id: "expectedBehavior", label: "Expected behavior", kind: "textarea", required: true },
52
+ { id: "actualBehavior", label: "Actual behavior", kind: "textarea", required: true },
53
+ { id: "reproductionSteps", label: "Steps to reproduce", kind: "textarea", required: true },
54
+ ],
55
+ },
56
+ {
57
+ id: "ux-interaction-improvement",
58
+ categoryIds: ["ux"],
59
+ label: "Interaction improvement",
60
+ description: "Describe a usability, workflow, onboarding, or accessibility improvement.",
61
+ fields: [
62
+ {
63
+ id: "affectedWorkflow",
64
+ label: "Affected workflow",
65
+ kind: "select",
66
+ required: true,
67
+ options: [
68
+ { id: "first-use", label: "First use or onboarding" },
69
+ { id: "daily-use", label: "Daily use" },
70
+ { id: "configuration", label: "Configuration" },
71
+ { id: "accessibility", label: "Accessibility" },
72
+ ],
73
+ },
74
+ { id: "currentExperience", label: "Current experience", kind: "textarea", required: true },
75
+ { id: "proposedExperience", label: "Proposed experience", kind: "textarea", required: true },
76
+ ],
77
+ },
78
+ {
79
+ id: "documentation-update",
80
+ categoryIds: ["documentation"],
81
+ label: "Documentation update",
82
+ description: "Identify missing or unclear guidance and the documentation change needed.",
83
+ fields: [
84
+ {
85
+ id: "documentationArea",
86
+ label: "Documentation area",
87
+ kind: "select",
88
+ required: true,
89
+ options: [
90
+ { id: "readme", label: "README or getting started" },
91
+ { id: "reference", label: "Reference documentation" },
92
+ { id: "examples", label: "Examples" },
93
+ { id: "troubleshooting", label: "Troubleshooting" },
94
+ ],
95
+ },
96
+ { id: "documentationGap", label: "What is missing or unclear?", kind: "textarea", required: true },
97
+ { id: "proposedChange", label: "Proposed change", kind: "textarea", required: true },
98
+ ],
99
+ },
100
+ {
101
+ id: "performance-regression",
102
+ categoryIds: ["performance"],
103
+ label: "Performance regression",
104
+ description: "Capture a measurable slowdown or resource-use regression and its impact.",
105
+ fields: [
106
+ {
107
+ id: "performanceArea",
108
+ label: "Affected area",
109
+ kind: "select",
110
+ required: true,
111
+ options: [
112
+ { id: "startup", label: "Startup" },
113
+ { id: "interaction", label: "Interaction or rendering" },
114
+ { id: "resource-use", label: "Resource use" },
115
+ { id: "background-work", label: "Background work" },
116
+ ],
117
+ },
118
+ { id: "observedPerformance", label: "Observed performance", kind: "textarea", required: true },
119
+ { id: "impact", label: "User impact", kind: "textarea", required: true },
120
+ { id: "measurement", label: "Measurement or comparison", kind: "textarea", required: true },
121
+ ],
122
+ },
123
+ {
124
+ id: "compatibility-environment-issue",
125
+ categoryIds: ["compatibility"],
126
+ label: "Environment issue",
127
+ description: "Report behavior tied to a browser, operating system, runtime, or integration.",
128
+ fields: [
129
+ {
130
+ id: "environmentType",
131
+ label: "Environment type",
132
+ kind: "choices",
133
+ required: true,
134
+ options: [
135
+ { id: "browser", label: "Browser" },
136
+ { id: "operating-system", label: "Operating system" },
137
+ { id: "runtime", label: "Runtime or package version" },
138
+ { id: "integration", label: "Integration" },
139
+ ],
140
+ },
141
+ { id: "environment", label: "Environment details", kind: "textarea", required: true },
142
+ { id: "expectedBehavior", label: "Expected behavior", kind: "textarea", required: true },
143
+ { id: "actualBehavior", label: "Actual behavior", kind: "textarea", required: true },
144
+ ],
145
+ },
146
+ {
147
+ id: "other-general-request",
148
+ categoryIds: ["other"],
149
+ label: "General request",
150
+ description: "Share a question, idea, or feedback that does not fit another category.",
151
+ fields: [
152
+ { id: "requestType", label: "Request type", kind: "choices", required: true, options: [
153
+ { id: "question", label: "Question" },
154
+ { id: "idea", label: "Idea" },
155
+ { id: "feedback", label: "Feedback" },
156
+ ] },
157
+ { id: "context", label: "Context", kind: "textarea", required: true },
158
+ { id: "request", label: "Request", kind: "textarea", required: true },
159
+ ],
160
+ },
161
+ ]);
162
+
163
+ export const ISSUE_WIZARD_STEP_COUNT = 5;
164
+ export const ISSUE_WIZARD_CATEGORIES = CATEGORY_DEFINITIONS;
165
+ export const ISSUE_WIZARD_TEMPLATES = TEMPLATE_DEFINITIONS;
166
+
167
+ function freezeCatalogEntry(entry) {
168
+ const options = entry.options?.map((option) => Object.freeze({ ...option }));
169
+ return Object.freeze({
170
+ ...entry,
171
+ ...(options ? { options: Object.freeze(options) } : {}),
172
+ });
173
+ }
174
+
175
+ function freezeTemplate(template) {
176
+ return Object.freeze({
177
+ ...template,
178
+ categoryIds: Object.freeze([...template.categoryIds]),
179
+ fields: Object.freeze(template.fields.map(freezeCatalogEntry)),
180
+ });
181
+ }
182
+
183
+ const FROZEN_CATEGORIES = Object.freeze(CATEGORY_DEFINITIONS.map((category) => Object.freeze({ ...category })));
184
+ const FROZEN_TEMPLATES = Object.freeze(TEMPLATE_DEFINITIONS.map(freezeTemplate));
185
+
186
+ function normalizedText(value, { multiline = true } = {}) {
187
+ const text = String(value ?? "")
188
+ .normalize("NFKC")
189
+ .replace(/\r\n?/g, "\n")
190
+ .replace(/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/g, "");
191
+ if (!multiline) return text.replace(/\s+/g, " ").trim();
192
+ return text.split("\n").map((line) => line.trimEnd()).join("\n").trim();
193
+ }
194
+
195
+ /** Normalize prose before validation or serialization without interpreting it as Markdown. */
196
+ export function normalizeIssueText(value, options) {
197
+ return normalizedText(value, options);
198
+ }
199
+
200
+ function normalizedTitleSummary(value) {
201
+ return normalizedText(value, { multiline: false }).replace(/[\[\]]/g, "").trim();
202
+ }
203
+
204
+ function componentSlug(label) {
205
+ return normalizedText(label, { multiline: false })
206
+ .toLowerCase()
207
+ .replace(/[^a-z0-9]+/g, "-")
208
+ .replace(/^-+|-+$/g, "") || "feature";
209
+ }
210
+
211
+ /**
212
+ * Builds the complete deterministic catalog. Optional feature labels are caller-owned
213
+ * input so this module never maintains a second optional-feature catalog.
214
+ */
215
+ export function createIssueWizardCatalog(optionalFeatureNames = []) {
216
+ const labels = Array.isArray(optionalFeatureNames) ? optionalFeatureNames : [];
217
+ const seenLabels = new Set(["webui"]);
218
+ const usedIds = new Set(["webui"]);
219
+ const optionalComponents = [];
220
+
221
+ for (const featureName of labels) {
222
+ const label = normalizedText(featureName, { multiline: false });
223
+ const labelKey = label.toLocaleLowerCase();
224
+ if (!label || seenLabels.has(labelKey)) continue;
225
+ seenLabels.add(labelKey);
226
+ const baseId = `feature-${componentSlug(label)}`;
227
+ let id = baseId;
228
+ let suffix = 2;
229
+ while (usedIds.has(id)) id = `${baseId}-${suffix++}`;
230
+ usedIds.add(id);
231
+ optionalComponents.push(Object.freeze({ id, label, source: "optional-feature" }));
232
+ }
233
+
234
+ return Object.freeze({
235
+ categories: FROZEN_CATEGORIES,
236
+ components: Object.freeze([
237
+ Object.freeze({ id: "webui", label: "WebUI", source: "webui" }),
238
+ ...optionalComponents,
239
+ ]),
240
+ templates: FROZEN_TEMPLATES,
241
+ });
242
+ }
243
+
244
+ export function createIssueWizardState() {
245
+ return {
246
+ step: 1,
247
+ categoryId: "",
248
+ componentId: "",
249
+ templateId: "",
250
+ summary: "",
251
+ fields: {},
252
+ };
253
+ }
254
+
255
+ function categoryFor(catalog, id) {
256
+ return catalog?.categories?.find((category) => category.id === id) || null;
257
+ }
258
+
259
+ function componentFor(catalog, id) {
260
+ return catalog?.components?.find((component) => component.id === id) || null;
261
+ }
262
+
263
+ function templateFor(catalog, id) {
264
+ return catalog?.templates?.find((template) => template.id === id) || null;
265
+ }
266
+
267
+ export function getCompatibleTemplates(catalog, categoryId, componentId) {
268
+ if (!categoryFor(catalog, categoryId) || !componentFor(catalog, componentId)) return [];
269
+ return (catalog?.templates || []).filter((template) => template.categoryIds.includes(categoryId));
270
+ }
271
+
272
+ export function isTemplateCompatible(catalog, categoryId, componentId, templateId) {
273
+ return getCompatibleTemplates(catalog, categoryId, componentId).some((template) => template.id === templateId);
274
+ }
275
+
276
+ function selectionError(message) {
277
+ return { valid: false, errors: { selection: message } };
278
+ }
279
+
280
+ export function validateIssueWizardState(state = {}, catalog) {
281
+ const errors = {};
282
+ const category = categoryFor(catalog, state.categoryId);
283
+ const component = componentFor(catalog, state.componentId);
284
+ const template = templateFor(catalog, state.templateId);
285
+
286
+ if (!category) errors.categoryId = "Choose a category.";
287
+ if (!component) errors.componentId = "Choose a component.";
288
+ if (category && component && (!template || !isTemplateCompatible(catalog, category.id, component.id, state.templateId))) {
289
+ errors.templateId = "Choose a compatible template.";
290
+ }
291
+ if (!normalizedTitleSummary(state.summary)) errors.summary = "Enter a short summary.";
292
+
293
+ if (template && category && component && isTemplateCompatible(catalog, category.id, component.id, template.id)) {
294
+ for (const field of template.fields) {
295
+ const value = normalizedText(state.fields?.[field.id], { multiline: field.kind === "textarea" });
296
+ if (field.required && !value) {
297
+ errors[field.id] = `${field.label} is required.`;
298
+ continue;
299
+ }
300
+ if (value && field.options && !field.options.some((option) => option.id === value)) {
301
+ errors[field.id] = `Choose a valid ${field.label.toLocaleLowerCase()}.`;
302
+ }
303
+ }
304
+ }
305
+
306
+ return { valid: Object.keys(errors).length === 0, errors };
307
+ }
308
+
309
+ export function isIssueWizardStepValid(state, catalog, step = state?.step) {
310
+ const category = categoryFor(catalog, state?.categoryId);
311
+ const component = componentFor(catalog, state?.componentId);
312
+ const template = templateFor(catalog, state?.templateId);
313
+ if (step === 1) return !!category;
314
+ if (step === 2) return !!component;
315
+ if (step === 3) return !!(category && component && template && isTemplateCompatible(catalog, category.id, component.id, template.id));
316
+ if (step === 4) {
317
+ if (!category || !component || !template || !isTemplateCompatible(catalog, category.id, component.id, template.id)) return false;
318
+ const validation = validateIssueWizardState(state, catalog);
319
+ return !Object.keys(validation.errors).some((key) => key !== "categoryId" && key !== "componentId" && key !== "templateId");
320
+ }
321
+ if (step === 5) return validateIssueWizardState(state, catalog).valid;
322
+ return false;
323
+ }
324
+
325
+ function resetTemplateSelection(state) {
326
+ return { ...state, templateId: "", fields: {} };
327
+ }
328
+
329
+ /** Apply a single pure state transition; invalid selection actions preserve state. */
330
+ export function reduceIssueWizardState(state = createIssueWizardState(), action = {}, catalog) {
331
+ const current = {
332
+ ...createIssueWizardState(),
333
+ ...state,
334
+ fields: { ...(state.fields || {}) },
335
+ };
336
+
337
+ switch (action.type) {
338
+ case "select-category": {
339
+ if (!categoryFor(catalog, action.categoryId)) return current;
340
+ return { ...resetTemplateSelection(current), categoryId: action.categoryId, step: Math.min(current.step, 2) };
341
+ }
342
+ case "select-component": {
343
+ if (!componentFor(catalog, action.componentId)) return current;
344
+ return { ...resetTemplateSelection(current), componentId: action.componentId, step: Math.min(current.step, 3) };
345
+ }
346
+ case "select-template": {
347
+ if (!isTemplateCompatible(catalog, current.categoryId, current.componentId, action.templateId)) return current;
348
+ return { ...current, templateId: action.templateId, fields: {}, step: Math.min(current.step, 4) };
349
+ }
350
+ case "set-summary":
351
+ return { ...current, summary: String(action.summary ?? "") };
352
+ case "set-field": {
353
+ const template = templateFor(catalog, current.templateId);
354
+ if (!template?.fields.some((field) => field.id === action.fieldId)) return current;
355
+ return { ...current, fields: { ...current.fields, [action.fieldId]: String(action.value ?? "") } };
356
+ }
357
+ case "next":
358
+ return isIssueWizardStepValid(current, catalog, current.step)
359
+ ? { ...current, step: Math.min(ISSUE_WIZARD_STEP_COUNT, current.step + 1) }
360
+ : current;
361
+ case "back":
362
+ return { ...current, step: Math.max(1, current.step - 1) };
363
+ case "reset":
364
+ return createIssueWizardState();
365
+ default:
366
+ return current;
367
+ }
368
+ }
369
+
370
+ function neutralizeGithubReferences(value) {
371
+ return value.replace(/@(?=[A-Za-z0-9_-])/gu, "@\u200B").replace(/#(?=\d)/gu, "#\u200B");
372
+ }
373
+
374
+ function escapeMarkdown(value) {
375
+ return neutralizeGithubReferences(normalizedText(value))
376
+ .replace(/\\/g, "\\\\")
377
+ .replace(/([`*_{}\[\]<>()[\]|])/g, "\\$1")
378
+ .replace(/^([>#]|[-+]|\d+\.)/gm, "\\$1");
379
+ }
380
+
381
+ function fieldValueForBody(field, value) {
382
+ const normalized = normalizedText(value, { multiline: field.kind === "textarea" });
383
+ const option = field.options?.find((candidate) => candidate.id === normalized);
384
+ return escapeMarkdown(option?.label || normalized);
385
+ }
386
+
387
+ export class IssueWizardValidationError extends Error {
388
+ constructor(errors) {
389
+ super("Issue wizard state is incomplete or invalid.");
390
+ this.name = "IssueWizardValidationError";
391
+ this.errors = errors;
392
+ }
393
+ }
394
+
395
+ /** Build the complete, I/O-free GitHub issue payload after validating the wizard state. */
396
+ export function buildIssuePayload(state, catalog) {
397
+ const validation = validateIssueWizardState(state, catalog);
398
+ if (!validation.valid) throw new IssueWizardValidationError(validation.errors);
399
+
400
+ const category = categoryFor(catalog, state.categoryId);
401
+ const component = componentFor(catalog, state.componentId);
402
+ const template = templateFor(catalog, state.templateId);
403
+ const summary = normalizedTitleSummary(state.summary);
404
+ const title = `[${category.label}] [${component.label}] [${template.label}] ${neutralizeGithubReferences(summary)}`;
405
+ const details = template.fields.flatMap((field) => [
406
+ `### ${field.label}`,
407
+ fieldValueForBody(field, state.fields[field.id]),
408
+ "",
409
+ ]);
410
+ const body = [
411
+ `## ${template.label}`,
412
+ "",
413
+ `**Category:** ${category.label}`,
414
+ `**Component:** ${component.label}`,
415
+ "",
416
+ "## Summary",
417
+ escapeMarkdown(summary),
418
+ "",
419
+ "## Details",
420
+ "",
421
+ ...details,
422
+ ].join("\n").trimEnd();
423
+
424
+ return Object.freeze({ title, body });
425
+ }
426
+
427
+ /** Serializes the exact title/body payload that a future adapter will receive. */
428
+ export function serializeIssuePayload(payload) {
429
+ return JSON.stringify({ title: String(payload?.title || ""), body: String(payload?.body || "") });
430
+ }
431
+
432
+ export function issueClipboardText(payload) {
433
+ return `${String(payload?.title || "")}\n\n${String(payload?.body || "")}`;
434
+ }
435
+
436
+ /** Future integration seam. It deliberately performs no network, storage, or GitHub I/O. */
437
+ export async function submitIssueToGithubBot(_payload) {
438
+ return Object.freeze({
439
+ ok: false,
440
+ status: "unavailable",
441
+ message: "Automatic submission is coming soon. Copy the issue instead.",
442
+ });
443
+ }
@@ -1,9 +1,11 @@
1
- const CACHE_NAME = "pi-webui-pwa-v46";
1
+ const CACHE_NAME = "pi-webui-pwa-v48";
2
2
  const APP_SHELL = [
3
3
  "/",
4
4
  "/index.html",
5
5
  "/styles.css",
6
6
  "/app.js",
7
+ "/issue-wizard-state.mjs",
8
+ "/issue-bot-client.mjs",
7
9
  "/aur-review-payload.mjs",
8
10
  "/guided-git-command-state.mjs",
9
11
  "/guided-git-review-state.mjs",