@firstpick/pi-package-webui 0.8.1 → 0.8.2

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 (32) hide show
  1. package/README.md +12 -0
  2. package/bin/pi-webui.mjs +190 -20
  3. package/lib/component-update-state.mjs +126 -0
  4. package/lib/trust-boundaries.mjs +1 -0
  5. package/package.json +1 -1
  6. package/public/app.js +1454 -101
  7. package/public/index.html +155 -27
  8. package/public/service-worker.js +1 -1
  9. package/public/styles.css +731 -2
  10. package/tests/boot-failure-diagnostics.test.mjs +63 -5
  11. package/tests/browser/control-deck-component-updates.spec.mjs +180 -0
  12. package/tests/browser/interaction-continuity.spec.mjs +158 -0
  13. package/tests/browser/mobile-foundation.spec.mjs +11 -0
  14. package/tests/browser/side-panel-section-reorder.spec.mjs +101 -0
  15. package/tests/browser/stats-overlay.spec.mjs +265 -0
  16. package/tests/codex-fast-mode-static.test.mjs +2 -2
  17. package/tests/component-update-api-static.test.mjs +67 -0
  18. package/tests/component-update-state.test.mjs +80 -0
  19. package/tests/control-deck-component-updates-static.test.mjs +251 -0
  20. package/tests/fast-mode-client-static.test.mjs +1 -1
  21. package/tests/fixtures/fake-pi.mjs +129 -5
  22. package/tests/footer-provider-usage-visual-static.test.mjs +71 -0
  23. package/tests/interaction-state-stability-static.test.mjs +21 -4
  24. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  25. package/tests/mobile-foundation-static.test.mjs +6 -4
  26. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  27. package/tests/mobile-static.test.mjs +2 -1
  28. package/tests/native-parity-harness.test.mjs +2 -0
  29. package/tests/open-issue-wizard-static.test.mjs +1 -1
  30. package/tests/side-panel-section-reorder-static.test.mjs +68 -0
  31. package/tests/sse-backpressure-harness.test.mjs +51 -12
  32. package/tests/stats-dashboard-static.test.mjs +266 -0
package/public/index.html CHANGED
@@ -12,7 +12,7 @@
12
12
  <link rel="manifest" href="/manifest.webmanifest" />
13
13
  <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
14
14
  <link rel="apple-touch-icon" href="/apple-touch-icon.png" />
15
- <link rel="stylesheet" href="/styles.css?v=92" />
15
+ <link rel="stylesheet" href="/styles.css?v=93" />
16
16
  <script>
17
17
  // Public-only issue-bot runtime configuration. Keep disabled unless the gateway,
18
18
  // Turnstile site key, exact CORS origin, and private-report destination are approved.
@@ -608,7 +608,7 @@
608
608
  <strong class="side-panel-title">Control Deck</strong>
609
609
  <div class="side-panel-version-row" aria-label="Version and build information">
610
610
  <button id="piVersionButton" class="pi-version-button" type="button" aria-label="View Pi release notes" aria-haspopup="dialog" aria-controls="piReleaseNotesDialog" hidden></button>
611
- <button id="webuiVersionButton" class="webui-version-button" type="button" aria-label="Open Pi Web UI package page" aria-haspopup="dialog" aria-controls="confirmationDialog" hidden></button>
611
+ <button id="webuiVersionButton" class="webui-version-button" type="button" aria-label="Open Pi Web UI package and update details" aria-haspopup="dialog" aria-controls="webuiPackageDialog" hidden></button>
612
612
  <span id="webuiDevBadge" class="webui-dev-badge" aria-label="Pi Web UI dev server" hidden>DEV</span>
613
613
  </div>
614
614
  </div>
@@ -1105,6 +1105,10 @@
1105
1105
  <button id="piReleaseNotesCloseButton" type="button" aria-label="Close Pi release notes">Close</button>
1106
1106
  </div>
1107
1107
  <p id="piReleaseNotesStatus" class="pi-release-notes-status muted" role="status" aria-live="polite"></p>
1108
+ <section class="component-update-panel" aria-label="Pi background update">
1109
+ <p id="piComponentUpdateStatus" class="component-update-status muted" role="status" aria-live="polite"></p>
1110
+ <button id="piComponentUpdateButton" class="component-update-button primary" type="button">Update Pi</button>
1111
+ </section>
1108
1112
  <div id="piReleaseNotesBody" class="pi-release-notes-body markdown-body"></div>
1109
1113
  <menu>
1110
1114
  <a id="piReleaseNotesGithubLink" class="pi-release-notes-link" target="_blank" rel="noopener noreferrer" hidden>View on GitHub</a>
@@ -1113,6 +1117,34 @@
1113
1117
  </form>
1114
1118
  </dialog>
1115
1119
 
1120
+ <dialog id="webuiPackageDialog" class="extension-dialog webui-package-dialog" aria-labelledby="webuiPackageTitle">
1121
+ <form method="dialog">
1122
+ <div class="webui-package-header">
1123
+ <div>
1124
+ <span class="webui-package-kicker">Web UI package</span>
1125
+ <h2 id="webuiPackageTitle">Pi Web UI package</h2>
1126
+ </div>
1127
+ <button id="webuiPackageCloseButton" type="button" aria-label="Close Web UI package details">Close</button>
1128
+ </div>
1129
+ <dl class="webui-package-versions">
1130
+ <div class="webui-package-version-row">
1131
+ <dt>Installed</dt>
1132
+ <dd id="webuiPackageCurrentVersion">Unknown</dd>
1133
+ </div>
1134
+ <div class="webui-package-version-row">
1135
+ <dt>Latest on npm</dt>
1136
+ <dd id="webuiPackageLatestVersion">Not checked</dd>
1137
+ </div>
1138
+ </dl>
1139
+ <p id="webuiComponentUpdateStatus" class="component-update-status muted" role="status" aria-live="polite"></p>
1140
+ <menu>
1141
+ <button id="webuiPackageNpmButton" class="webui-package-npm-link" type="button">View on npm</button>
1142
+ <button id="webuiComponentUpdateButton" class="component-update-button primary" type="button">Update Web UI</button>
1143
+ <button value="close">Close</button>
1144
+ </menu>
1145
+ </form>
1146
+ </dialog>
1147
+
1116
1148
  <dialog id="confirmationDialog" class="extension-dialog confirmation-dialog">
1117
1149
  <form method="dialog">
1118
1150
  <h2 id="confirmationTitle">Confirm action</h2>
@@ -1265,7 +1297,7 @@
1265
1297
  </div>
1266
1298
  <p id="statsOverlayStatus" class="stats-overlay-status muted" role="status" aria-live="polite" hidden></p>
1267
1299
  <div id="statsOverlayTabs" class="stats-overlay-tabs" role="tablist" aria-label="Stats dashboard views"></div>
1268
- <div id="statsOverlayBody" class="stats-overlay-body"></div>
1300
+ <div id="statsOverlayBody" class="stats-overlay-body" role="tabpanel" tabindex="0"></div>
1269
1301
  </form>
1270
1302
  </dialog>
1271
1303
 
@@ -1468,7 +1500,7 @@
1468
1500
  </form>
1469
1501
  </dialog>
1470
1502
 
1471
- <script id="webuiBootLoader" data-app-src="/app.js?v=103">
1503
+ <script id="webuiBootLoader" data-app-src="/app.js?v=104">
1472
1504
  (() => {
1473
1505
  "use strict";
1474
1506
 
@@ -1481,6 +1513,8 @@
1481
1513
  const copyStatus = document.querySelector("#webuiBootFailureCopyStatus");
1482
1514
  const appSource = loader?.dataset?.appSrc || "/app.js";
1483
1515
  const bootStartedAt = new Date();
1516
+ const DIAGNOSTIC_REQUEST_TIMEOUT_MS = 3_000;
1517
+ const JAVASCRIPT_CONTENT_TYPES = ["text/javascript", "application/javascript"];
1484
1518
  let bootSettled = false;
1485
1519
  let bootFailed = false;
1486
1520
  let watchdog = null;
@@ -1507,29 +1541,64 @@
1507
1541
  return boundedSafeText(error);
1508
1542
  }
1509
1543
 
1510
- async function responseSummary(url, label, { parseHealth = false, readSource = false } = {}) {
1544
+ async function responseSummary(url, label, { parseHealth = false, readSource = false, expectedTypes = [] } = {}) {
1511
1545
  const safeUrl = sanitizedUrl(url);
1546
+ const controller = typeof AbortController === "function" ? new AbortController() : null;
1547
+ let timedOut = false;
1548
+ let timeoutId = null;
1512
1549
  try {
1513
- const response = await fetch(url, { cache: "no-store", credentials: "same-origin" });
1514
- const type = String(response.headers?.get?.("content-type") || "unknown").split(";", 1)[0];
1515
- let suffix = "";
1516
- let source = "";
1517
- if (parseHealth && response.ok) {
1518
- const data = await response.clone().json().catch(() => null);
1519
- const fields = [data?.ok === true ? "ok=true" : "", data?.webuiVersion ? `webuiVersion=${boundedSafeText(data.webuiVersion, 80)}` : ""].filter(Boolean);
1520
- if (fields.length) suffix = ` (${fields.join(", ")})`;
1521
- }
1522
- if (readSource && response.ok) source = await response.text();
1523
- else response.body?.cancel?.().catch?.(() => {});
1524
- return { ok: response.ok, status: response.status, type, safeUrl, label, line: `- ${label}: HTTP ${response.status} ${type}${suffix} — ${safeUrl}`, source };
1550
+ const request = (async () => {
1551
+ const response = await fetch(url, { cache: "no-store", credentials: "same-origin", ...(controller ? { signal: controller.signal } : {}) });
1552
+ const type = String(response.headers?.get?.("content-type") || "unknown").split(";", 1)[0].trim().toLowerCase();
1553
+ const contentTypeMismatch = response.ok && expectedTypes.length > 0 && !expectedTypes.includes(type);
1554
+ let suffix = contentTypeMismatch ? ` (expected ${expectedTypes.join(" or ")})` : "";
1555
+ let source = "";
1556
+ let invalidJson = false;
1557
+ if (parseHealth && response.ok) {
1558
+ const data = await response.clone().json().catch(() => null);
1559
+ invalidJson = !data || typeof data !== "object";
1560
+ const fields = [data?.ok === true ? "ok=true" : "", data?.webuiVersion ? `webuiVersion=${boundedSafeText(data.webuiVersion, 80)}` : ""].filter(Boolean);
1561
+ if (fields.length) suffix += ` (${fields.join(", ")})`;
1562
+ if (invalidJson) suffix += " (invalid JSON)";
1563
+ }
1564
+ if (readSource && response.ok) source = await response.text();
1565
+ else response.body?.cancel?.().catch?.(() => {});
1566
+ return {
1567
+ ok: response.ok && !contentTypeMismatch && !invalidJson,
1568
+ status: response.status,
1569
+ type,
1570
+ safeUrl,
1571
+ label,
1572
+ contentTypeMismatch,
1573
+ invalidJson,
1574
+ timedOut: false,
1575
+ line: `- ${label}: HTTP ${response.status} ${type}${suffix} — ${safeUrl}`,
1576
+ source,
1577
+ };
1578
+ })();
1579
+ const timeout = new Promise((_, reject) => {
1580
+ timeoutId = setTimeout(() => {
1581
+ timedOut = true;
1582
+ controller?.abort();
1583
+ const timeoutError = new Error(`Diagnostic request timed out after ${DIAGNOSTIC_REQUEST_TIMEOUT_MS / 1_000} seconds`);
1584
+ timeoutError.name = "DiagnosticTimeoutError";
1585
+ reject(timeoutError);
1586
+ }, DIAGNOSTIC_REQUEST_TIMEOUT_MS);
1587
+ });
1588
+ return await Promise.race([request, timeout]);
1525
1589
  } catch (error) {
1526
- return { ok: false, status: null, type: "unknown", safeUrl, label, line: `- ${label}: request failed (${boundedSafeText(errorText(error), 240)}) — ${safeUrl}`, source: "" };
1590
+ const detail = timedOut
1591
+ ? `diagnostic timed out after ${DIAGNOSTIC_REQUEST_TIMEOUT_MS / 1_000} seconds`
1592
+ : `request failed (${boundedSafeText(errorText(error), 240)})`;
1593
+ return { ok: false, status: null, type: "unknown", safeUrl, label, timedOut, contentTypeMismatch: false, invalidJson: false, line: `- ${label}: ${detail} — ${safeUrl}`, source: "" };
1594
+ } finally {
1595
+ clearTimeout(timeoutId);
1527
1596
  }
1528
1597
  }
1529
1598
 
1530
1599
  async function startupAssetReport() {
1531
1600
  const appUrl = new URL(appSource, window.location.href);
1532
- const app = await responseSummary(appUrl.href, "entry module", { readSource: true });
1601
+ const app = await responseSummary(appUrl.href, "entry module", { readSource: true, expectedTypes: JAVASCRIPT_CONTENT_TYPES });
1533
1602
  if (!app.source) return { probes: [app], lines: [app.line], failures: app.ok ? [] : [app] };
1534
1603
 
1535
1604
  const imported = [];
@@ -1542,15 +1611,30 @@
1542
1611
  if (imported.length >= 24) break;
1543
1612
  }
1544
1613
 
1545
- const importedProbes = await Promise.all(imported.map((item) => responseSummary(item.url, "imported module")));
1614
+ const importedProbes = await Promise.all(imported.map((item) => responseSummary(item.url, "imported module", { expectedTypes: JAVASCRIPT_CONTENT_TYPES })));
1546
1615
  const probes = [app, ...importedProbes];
1547
1616
  return { probes, lines: probes.map((probe) => probe.line), failures: probes.filter((probe) => !probe.ok) };
1548
1617
  }
1549
1618
 
1550
- function startupAssessment(health, assets, error) {
1619
+ async function webManifestReport() {
1620
+ const probe = await responseSummary(new URL("/manifest.webmanifest", window.location.href).href, "optional web manifest", {
1621
+ readSource: true,
1622
+ expectedTypes: ["application/manifest+json", "application/json"],
1623
+ });
1624
+ if (!probe.ok || !probe.source) return { ...probe, validJson: false };
1625
+ try {
1626
+ JSON.parse(probe.source);
1627
+ return { ...probe, validJson: true };
1628
+ } catch (error) {
1629
+ return { ...probe, validJson: false, line: `${probe.line} (invalid JSON: ${boundedSafeText(errorText(error), 160)})` };
1630
+ }
1631
+ }
1632
+
1633
+ function startupAssessment(health, assets, reason, error) {
1551
1634
  const missingImports = assets.failures.filter((probe) => probe.label === "imported module" && probe.status === 404);
1552
1635
  const firstFailure = assets.failures[0] || (!health.ok ? health : null);
1553
1636
  const originalError = boundedSafeText(errorText(error));
1637
+ const failureText = `${boundedSafeText(reason)}\n${originalError}`;
1554
1638
  if (missingImports.length) {
1555
1639
  const paths = missingImports.map((probe) => new URL(probe.safeUrl).pathname);
1556
1640
  return {
@@ -1562,8 +1646,25 @@
1562
1646
  };
1563
1647
  }
1564
1648
  if (firstFailure) {
1649
+ const path = new URL(firstFailure.safeUrl).pathname;
1650
+ if (firstFailure.timedOut) {
1651
+ return {
1652
+ summary: `A diagnostic check timed out while probing ${path}.`,
1653
+ likelyCause: firstFailure.label === "backend health"
1654
+ ? "The browser shell loaded, but the backend or browser network service did not answer the bounded health check."
1655
+ : "The startup asset request remained pending; check the backend, service worker, or browser network state.",
1656
+ failingUrls: [firstFailure.safeUrl],
1657
+ };
1658
+ }
1659
+ if (firstFailure.contentTypeMismatch) {
1660
+ return {
1661
+ summary: `Wrong content type for startup asset ${path}: ${firstFailure.type}.`,
1662
+ likelyCause: "The URL responded, but it did not serve JavaScript with an executable MIME type; a fallback HTML/error response or stale server route is likely.",
1663
+ failingUrls: [firstFailure.safeUrl],
1664
+ };
1665
+ }
1565
1666
  return {
1566
- summary: `Startup request failed: ${new URL(firstFailure.safeUrl).pathname}${firstFailure.status ? ` (HTTP ${firstFailure.status})` : ""}.`,
1667
+ summary: `Startup request failed: ${path}${firstFailure.status ? ` (HTTP ${firstFailure.status})` : ""}.`,
1567
1668
  likelyCause: firstFailure.label === "backend health"
1568
1669
  ? "The browser shell loaded, but the WebUI backend is unavailable or unreachable."
1569
1670
  : "A startup asset is unavailable, blocked, or served with an unsuccessful response.",
@@ -1573,6 +1674,20 @@
1573
1674
  if (/critical stylesheet/i.test(originalError)) {
1574
1675
  return { summary: "The critical stylesheet failed to load.", likelyCause: "The stylesheet request failed even though the startup-module probes succeeded.", failingUrls: [] };
1575
1676
  }
1677
+ if (/\bSyntaxError\b|unexpected token|unexpected identifier|already been declared|invalid or unexpected token|missing[ )\]}]/i.test(failureText)) {
1678
+ return {
1679
+ summary: `JavaScript failed during startup: ${boundedSafeText(originalError, 180)}.`,
1680
+ likelyCause: "The entry module is reachable, but the browser could not parse or evaluate it. During development this commonly means a source file was briefly incomplete while being edited; otherwise check for stale mixed-version assets.",
1681
+ failingUrls: [],
1682
+ };
1683
+ }
1684
+ if (/watchdog timed out|startup did not finish/i.test(failureText)) {
1685
+ return {
1686
+ summary: "WebUI startup stalled even though the current HTTP checks succeeded.",
1687
+ likelyCause: "The entry-module import, stylesheet, or top-level module evaluation remained pending. During development, a file changing while the browser loads it can cause a transient mixed-version startup.",
1688
+ failingUrls: [],
1689
+ };
1690
+ }
1576
1691
  return {
1577
1692
  summary: "All probed startup URLs currently respond successfully, but module evaluation still failed.",
1578
1693
  likelyCause: "The failure may be a stale browser/PWA cache, a transient request failure, or a JavaScript evaluation error rather than a current HTTP 404.",
@@ -1582,9 +1697,16 @@
1582
1697
 
1583
1698
  async function troubleshootingReport(reason, error) {
1584
1699
  const pageUrl = sanitizedUrl(window.location.href);
1585
- const health = await responseSummary(new URL("/api/health", window.location.href).href, "backend health", { parseHealth: true });
1586
- const assets = await startupAssetReport();
1587
- const assessment = startupAssessment(health, assets, error);
1700
+ const [health, assets, manifest] = await Promise.all([
1701
+ responseSummary(new URL("/api/health", window.location.href).href, "backend health", { parseHealth: true, expectedTypes: ["application/json"] }),
1702
+ startupAssetReport(),
1703
+ webManifestReport(),
1704
+ ]);
1705
+ const assessment = startupAssessment(health, assets, reason, error);
1706
+ const manifestHasIssue = !manifest.ok || !manifest.validJson;
1707
+ const manifestImpact = manifestHasIssue
1708
+ ? "The web manifest has a separate problem that can produce DevTools console errors, but it does not execute or block app.js startup."
1709
+ : "The optional web manifest is valid and is not the startup blocker.";
1588
1710
  const failedProbes = [...(!health.ok ? [health] : []), ...assets.failures];
1589
1711
  const failingChecks = failedProbes.length
1590
1712
  ? failedProbes.map((probe) => probe.line)
@@ -1617,14 +1739,20 @@
1617
1739
  health.line,
1618
1740
  ...assets.lines,
1619
1741
  "",
1742
+ "Related browser checks",
1743
+ "----------------------",
1744
+ manifest.line,
1745
+ `- manifest impact: ${manifestImpact}`,
1746
+ "",
1620
1747
  "Suggested troubleshooting",
1621
1748
  "-------------------------",
1622
1749
  "1. In Pi, run: /webui-status detailed",
1623
1750
  `2. Check the backend: curl -i ${new URL("/api/health", pageUrl).href}`,
1624
1751
  failingAssetCommand,
1625
1752
  "4. For an imported-module 404, synchronize the WebUI static allowlist and PWA app shell with app.js imports.",
1626
- "5. After correcting files, run /webui-start again to restart the server and restore tabs.",
1627
- "6. Share this complete report with your troubleshooting assistant.",
1753
+ "5. For a JavaScript syntax/evaluation error during development, finish or revert the incomplete edit and run the package syntax check before reloading.",
1754
+ "6. After correcting files, run /webui-start again to restart the server and restore tabs.",
1755
+ "7. Share this complete report with your troubleshooting assistant.",
1628
1756
  ].join("\n");
1629
1757
  return { text, summary: assessment.summary };
1630
1758
  }
@@ -1,4 +1,4 @@
1
- const CACHE_NAME = "pi-webui-pwa-v61";
1
+ const CACHE_NAME = "pi-webui-pwa-v62";
2
2
  const APP_SHELL = [
3
3
  "/",
4
4
  "/index.html",