@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.
Files changed (51) hide show
  1. package/README.md +21 -3
  2. package/bin/pi-webui.mjs +287 -32
  3. package/lib/component-update-state.mjs +126 -0
  4. package/lib/git-workflow-preferences.mjs +246 -19
  5. package/lib/thinking-stream-recovery.mjs +156 -0
  6. package/lib/trust-boundaries.mjs +1 -0
  7. package/lib/ui-layout-settings.mjs +254 -0
  8. package/package.json +5 -3
  9. package/public/app.js +3072 -142
  10. package/public/index.html +188 -39
  11. package/public/service-worker.js +1 -1
  12. package/public/styles.css +1091 -39
  13. package/tests/boot-failure-diagnostics.test.mjs +63 -5
  14. package/tests/browser/composer-action-grid-reorder.spec.mjs +303 -0
  15. package/tests/browser/control-deck-component-updates.spec.mjs +180 -0
  16. package/tests/browser/feature-decision-output-popup.spec.mjs +156 -0
  17. package/tests/browser/interaction-continuity.spec.mjs +187 -0
  18. package/tests/browser/mobile-foundation.spec.mjs +11 -0
  19. package/tests/browser/persistent-ui-layout.spec.mjs +744 -0
  20. package/tests/browser/side-panel-section-reorder.spec.mjs +101 -0
  21. package/tests/browser/stats-overlay.spec.mjs +265 -0
  22. package/tests/codex-fast-mode-static.test.mjs +2 -2
  23. package/tests/component-update-api-static.test.mjs +67 -0
  24. package/tests/component-update-state.test.mjs +80 -0
  25. package/tests/composer-action-grid-reorder-static.test.mjs +63 -0
  26. package/tests/control-deck-component-updates-static.test.mjs +251 -0
  27. package/tests/fast-mode-client-static.test.mjs +2 -2
  28. package/tests/feature-decision-output-popup-static.test.mjs +172 -0
  29. package/tests/fixtures/fake-pi.mjs +180 -6
  30. package/tests/footer-provider-usage-visual-static.test.mjs +71 -0
  31. package/tests/git-workflow-preferences.test.mjs +4 -2
  32. package/tests/http-endpoints-harness.test.mjs +88 -1
  33. package/tests/interaction-state-stability-static.test.mjs +24 -4
  34. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  35. package/tests/mobile-foundation-static.test.mjs +6 -4
  36. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  37. package/tests/mobile-static.test.mjs +34 -16
  38. package/tests/native-parity-harness.test.mjs +2 -0
  39. package/tests/open-issue-wizard-static.test.mjs +1 -1
  40. package/tests/persistent-ui-layout-static.test.mjs +267 -0
  41. package/tests/questionnaire-dialog.test.mjs +511 -0
  42. package/tests/queue-edit-reorder-static.test.mjs +1 -0
  43. package/tests/remote-auth-settings-harness.test.mjs +1 -1
  44. package/tests/side-panel-resize-static.test.mjs +1 -0
  45. package/tests/side-panel-section-reorder-static.test.mjs +68 -0
  46. package/tests/sse-backpressure-harness.test.mjs +51 -12
  47. package/tests/stats-dashboard-static.test.mjs +266 -0
  48. package/tests/subagent-launch-slots.test.mjs +1 -1
  49. package/tests/thinking-stream-recovery.test.mjs +88 -0
  50. package/tests/ui-layout-settings.test.mjs +92 -0
  51. package/tests/webui-settings-locking.test.mjs +159 -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=98" />
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.
@@ -322,7 +322,7 @@
322
322
  aria-live="polite"
323
323
  >Follow-up</button>
324
324
  <div id="sessionSkillTags" class="composer-skill-tags" aria-live="polite" hidden></div>
325
- <span id="featureCategoryTag" class="composer-feature-category-tag" aria-live="polite" aria-atomic="true" hidden></span>
325
+ <button id="featureCategoryTag" class="composer-feature-category-tag" type="button" aria-haspopup="dialog" aria-controls="featureDecisionDialog" aria-live="polite" aria-atomic="true" disabled hidden></button>
326
326
  <button id="conversationModeChip" class="composer-conversation-mode-chip" type="button" aria-live="polite" hidden>Voice: off</button>
327
327
  <button id="workflowModeChip" class="composer-workflow-mode-chip" type="button" aria-live="polite" aria-pressed="true" hidden>Workflow: on</button>
328
328
  </div>
@@ -362,18 +362,20 @@
362
362
  <div class="composer-row">
363
363
  <button id="composerActionsButton" class="composer-actions-button" type="button" aria-controls="composerActionsPanel" aria-expanded="false" title="Open session, workflow, and follow-up actions">Actions</button>
364
364
  <div id="composerActionsPanel" class="composer-actions-panel" aria-label="Composer actions">
365
- <button id="newSessionButton" class="composer-new-button" type="button">New</button>
366
- <button id="compactButton" class="composer-compact-button" type="button" title="Compact the current Pi session context">Compact</button>
365
+ <button id="newSessionButton" class="composer-new-button" type="button" data-composer-action-id="new" data-composer-action-span="1">New</button>
366
+ <button id="compactButton" class="composer-compact-button" type="button" title="Compact the current Pi session context" data-composer-action-id="compact" data-composer-action-span="2">Compact</button>
367
367
  <button
368
368
  id="gitWorkflowButton"
369
369
  class="composer-icon-button composer-git-button"
370
+ data-composer-action-id="git"
371
+ data-composer-action-span="1"
370
372
  type="button"
371
373
  hidden
372
374
  title="Guided Git workflow"
373
375
  aria-label="Start guided Git workflow: stage all changes, generate and preview staged commit messages, optionally open a PR branch worktree, commit short or long there, then push or create a pull request. Cancel is available at each step."
374
376
  data-tooltip="Guided Git workflow:&#10;1. Stage all changes with git add .&#10;2. Generate and preview staged commit messages.&#10;3. Optional: create or type a PR branch worktree before committing.&#10;4. Commit with the short or long message in the worktree tab.&#10;5. Push normally, or push the PR worktree branch, generate/review /pr, and create the PR.&#10;Cancel is available at each step."
375
377
  ><svg class="composer-icon composer-icon-github" viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path fill="currentColor" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27s1.36.09 2 .27c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8Z"/></svg></button>
376
- <div class="composer-publish-menu" hidden>
378
+ <div class="composer-publish-menu" data-composer-action-id="publish" data-composer-action-span="1" hidden>
377
379
  <button
378
380
  id="publishButton"
379
381
  class="composer-icon-button composer-publish-button"
@@ -394,7 +396,7 @@
394
396
  </button>
395
397
  </div>
396
398
  </div>
397
- <div class="composer-publish-menu composer-native-command-menu" hidden>
399
+ <div class="composer-publish-menu composer-native-command-menu" data-composer-action-id="native-command" data-composer-action-span="1" hidden>
398
400
  <button
399
401
  id="nativeCommandMenuButton"
400
402
  class="composer-icon-button composer-publish-button composer-native-command-button"
@@ -415,7 +417,7 @@
415
417
  </button>
416
418
  </div>
417
419
  </div>
418
- <div class="composer-publish-menu composer-options-menu">
420
+ <div class="composer-publish-menu composer-options-menu" data-composer-action-id="options" data-composer-action-span="1">
419
421
  <button
420
422
  id="optionsMenuButton"
421
423
  class="composer-icon-button composer-publish-button composer-options-button"
@@ -478,7 +480,7 @@
478
480
  </button>
479
481
  </div>
480
482
  </div>
481
- <div id="appRunnerMenu" class="composer-publish-menu composer-app-runner-menu" hidden>
483
+ <div id="appRunnerMenu" class="composer-publish-menu composer-app-runner-menu" data-composer-action-id="app-runner" data-composer-action-span="2" hidden>
482
484
  <button
483
485
  id="appRunnerInfoButton"
484
486
  class="composer-icon-button composer-app-runner-info-button"
@@ -507,6 +509,8 @@
507
509
  <button
508
510
  id="steerButton"
509
511
  type="button"
512
+ data-composer-action-id="steer"
513
+ data-composer-action-span="2"
510
514
  title="Type your message first, then tap Steer to guide the active Pi run without sending a normal prompt. Use it for corrections or direction changes while Pi is working."
511
515
  aria-label="Steer: type your message first, then tap this button to guide the active Pi run."
512
516
  data-tooltip="Steer usage:&#10;1. Type your steering message in the textarea.&#10;2. Tap Steer to guide the active Pi run.&#10;Use for corrections or direction changes while Pi is working."
@@ -514,27 +518,33 @@
514
518
  <button
515
519
  id="followUpButton"
516
520
  type="button"
521
+ data-composer-action-id="follow-up"
522
+ data-composer-action-span="2"
517
523
  title="Type your message first, then tap Follow-up to send it as a follow-up instead of a normal prompt. Use it to add extra context or the next request."
518
524
  aria-label="Follow-up: type your message first, then tap this button to send it as a follow-up."
519
525
  data-tooltip="Follow-up usage:&#10;1. Type your message in the textarea.&#10;2. Tap Follow-up to send it as a follow-up.&#10;Use for extra context or the next request."
520
526
  >Follow-up</button>
521
- <div id="conversationVoiceMenu" class="composer-publish-menu composer-conversation-voice-menu" hidden>
527
+ <div id="conversationVoiceMenu" class="composer-publish-menu composer-conversation-voice-menu" data-composer-action-id="conversation-voice" data-composer-action-span="1" hidden>
522
528
  <button id="conversationVoiceButton" class="composer-publish-button composer-conversation-voice-button" type="button" title="Switch the spoken Piper voice. Voices marked with a size are downloaded when selected; progress shows on the voice chip." aria-label="Conversation voice" aria-haspopup="menu" aria-expanded="false" aria-controls="conversationVoiceMenuPanel"><span id="conversationVoiceButtonLabel">Voice</span></button>
523
529
  <div id="conversationVoiceMenuPanel" class="composer-publish-menu-panel composer-conversation-voice-menu-panel" role="menu" aria-label="Conversation voices"></div>
524
530
  </div>
525
- <button id="conversationModeEndButton" class="composer-conversation-end-button" type="button" title="End Natural Conversation Mode for this Pi tab" aria-label="End Natural Conversation Mode" hidden>End conversation</button>
526
- <button id="abortButton" class="composer-abort-button danger" type="button" title="Hold Esc or the Abort button for 3 seconds to abort the active Pi run" aria-label="Hold Esc or the Abort button for 3 seconds to abort the active Pi run" hidden disabled>Abort</button>
531
+ <button id="conversationModeEndButton" class="composer-conversation-end-button" type="button" title="End Natural Conversation Mode for this Pi tab" aria-label="End Natural Conversation Mode" data-composer-action-id="end-conversation" data-composer-action-span="1" hidden>End conversation</button>
532
+ <button id="abortButton" class="composer-abort-button danger" type="button" title="Hold Esc or the Abort button for 3 seconds to abort the active Pi run" aria-label="Hold Esc or the Abort button for 3 seconds to abort the active Pi run" data-composer-action-id="abort" data-composer-action-span="2" hidden disabled>Abort</button>
527
533
  <button
528
534
  id="btwButton"
529
535
  class="composer-icon-button composer-btw-button"
536
+ data-composer-action-id="btw"
537
+ data-composer-action-span="1"
530
538
  type="button"
531
539
  title="Ask as a /btw side question"
532
540
  aria-label="Ask the current composer text as a /btw side question"
533
541
  data-tooltip="/btw side question:&#10;Type a question, then tap /btw to ask without adding it to the main conversation."
534
542
  hidden
535
543
  ><svg class="composer-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5.5 6.5h10.75a2.25 2.25 0 0 1 2.25 2.25v4.5a2.25 2.25 0 0 1-2.25 2.25h-4.4L8 18.25V15.5H5.5a2.25 2.25 0 0 1-2.25-2.25v-4.5A2.25 2.25 0 0 1 5.5 6.5Z" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/><path d="m15.75 5.25 1.1-2.1 1.1 2.1 2.3 1.1-2.3 1.1-1.1 2.1-1.1-2.1-2.3-1.1 2.3-1.1Z" fill="currentColor"/><path d="M7.25 10.25h5.8M7.25 12.75h4.1" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/></svg></button>
536
- <button id="sendButton" type="submit" class="primary" title="Send prompt">Send</button>
544
+ <button id="sendButton" type="submit" class="primary" title="Send prompt" data-composer-action-id="send" data-composer-action-span="2">Send</button>
545
+ <div id="composerActionGridGuide" class="composer-action-grid-guide" aria-hidden="true" hidden></div>
537
546
  </div>
547
+ <p id="composerActionOrderStatus" class="sr-only" role="status" aria-live="polite" aria-atomic="true"></p>
538
548
  </form>
539
549
  <div id="remoteMicStreamingConsent" class="composer-remote-mic-consent" role="alert" hidden>
540
550
  <span id="remoteMicStreamingConsentText" class="composer-remote-mic-consent-text"></span>
@@ -608,7 +618,7 @@
608
618
  <strong class="side-panel-title">Control Deck</strong>
609
619
  <div class="side-panel-version-row" aria-label="Version and build information">
610
620
  <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>
621
+ <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
622
  <span id="webuiDevBadge" class="webui-dev-badge" aria-label="Pi Web UI dev server" hidden>DEV</span>
613
623
  </div>
614
624
  </div>
@@ -979,6 +989,7 @@
979
989
  <span id="subagentOpenModeStatus" class="muted">Overlay · saved in this browser</span>
980
990
  </div>
981
991
  <div class="subagents-status-row">
992
+ <button id="subagentsAutoClearButton" class="subagents-auto-clear-button" type="button" aria-pressed="false" aria-describedby="subagentsStatus">Auto-Clear</button>
982
993
  <p id="subagentsStatus" class="subagents-status muted" role="status" aria-live="polite">Checking running subagents…</p>
983
994
  <button id="subagentsClearFinishedButton" class="subagents-clear-finished-button" type="button" aria-describedby="subagentsStatus" disabled>Clear finished</button>
984
995
  </div>
@@ -1105,6 +1116,10 @@
1105
1116
  <button id="piReleaseNotesCloseButton" type="button" aria-label="Close Pi release notes">Close</button>
1106
1117
  </div>
1107
1118
  <p id="piReleaseNotesStatus" class="pi-release-notes-status muted" role="status" aria-live="polite"></p>
1119
+ <section class="component-update-panel" aria-label="Pi background update">
1120
+ <p id="piComponentUpdateStatus" class="component-update-status muted" role="status" aria-live="polite"></p>
1121
+ <button id="piComponentUpdateButton" class="component-update-button primary" type="button">Update Pi</button>
1122
+ </section>
1108
1123
  <div id="piReleaseNotesBody" class="pi-release-notes-body markdown-body"></div>
1109
1124
  <menu>
1110
1125
  <a id="piReleaseNotesGithubLink" class="pi-release-notes-link" target="_blank" rel="noopener noreferrer" hidden>View on GitHub</a>
@@ -1113,6 +1128,34 @@
1113
1128
  </form>
1114
1129
  </dialog>
1115
1130
 
1131
+ <dialog id="webuiPackageDialog" class="extension-dialog webui-package-dialog" aria-labelledby="webuiPackageTitle">
1132
+ <form method="dialog">
1133
+ <div class="webui-package-header">
1134
+ <div>
1135
+ <span class="webui-package-kicker">Web UI package</span>
1136
+ <h2 id="webuiPackageTitle">Pi Web UI package</h2>
1137
+ </div>
1138
+ <button id="webuiPackageCloseButton" type="button" aria-label="Close Web UI package details">Close</button>
1139
+ </div>
1140
+ <dl class="webui-package-versions">
1141
+ <div class="webui-package-version-row">
1142
+ <dt>Installed</dt>
1143
+ <dd id="webuiPackageCurrentVersion">Unknown</dd>
1144
+ </div>
1145
+ <div class="webui-package-version-row">
1146
+ <dt>Latest on npm</dt>
1147
+ <dd id="webuiPackageLatestVersion">Not checked</dd>
1148
+ </div>
1149
+ </dl>
1150
+ <p id="webuiComponentUpdateStatus" class="component-update-status muted" role="status" aria-live="polite"></p>
1151
+ <menu>
1152
+ <button id="webuiPackageNpmButton" class="webui-package-npm-link" type="button">View on npm</button>
1153
+ <button id="webuiComponentUpdateButton" class="component-update-button primary" type="button">Update Web UI</button>
1154
+ <button value="close">Close</button>
1155
+ </menu>
1156
+ </form>
1157
+ </dialog>
1158
+
1116
1159
  <dialog id="confirmationDialog" class="extension-dialog confirmation-dialog">
1117
1160
  <form method="dialog">
1118
1161
  <h2 id="confirmationTitle">Confirm action</h2>
@@ -1190,7 +1233,17 @@
1190
1233
  </form>
1191
1234
  </dialog>
1192
1235
 
1193
- <dialog id="extensionDialog" class="extension-dialog">
1236
+ <dialog id="featureDecisionDialog" class="extension-dialog feature-decision-dialog" aria-labelledby="featureDecisionDialogTitle">
1237
+ <form method="dialog">
1238
+ <h2 id="featureDecisionDialogTitle">Classifier output</h2>
1239
+ <pre id="featureDecisionDialogOutput" class="feature-decision-dialog-output"></pre>
1240
+ <menu>
1241
+ <button id="featureDecisionDialogCloseButton" type="submit" value="close">Close</button>
1242
+ </menu>
1243
+ </form>
1244
+ </dialog>
1245
+
1246
+ <dialog id="extensionDialog" class="extension-dialog" aria-labelledby="dialogTitle" aria-describedby="dialogMessage">
1194
1247
  <form id="dialogForm" method="dialog">
1195
1248
  <h2 id="dialogTitle">Pi request</h2>
1196
1249
  <p id="dialogMessage" class="muted"></p>
@@ -1265,7 +1318,7 @@
1265
1318
  </div>
1266
1319
  <p id="statsOverlayStatus" class="stats-overlay-status muted" role="status" aria-live="polite" hidden></p>
1267
1320
  <div id="statsOverlayTabs" class="stats-overlay-tabs" role="tablist" aria-label="Stats dashboard views"></div>
1268
- <div id="statsOverlayBody" class="stats-overlay-body"></div>
1321
+ <div id="statsOverlayBody" class="stats-overlay-body" role="tabpanel" tabindex="0"></div>
1269
1322
  </form>
1270
1323
  </dialog>
1271
1324
 
@@ -1468,7 +1521,7 @@
1468
1521
  </form>
1469
1522
  </dialog>
1470
1523
 
1471
- <script id="webuiBootLoader" data-app-src="/app.js?v=103">
1524
+ <script id="webuiBootLoader" data-app-src="/app.js?v=112">
1472
1525
  (() => {
1473
1526
  "use strict";
1474
1527
 
@@ -1481,6 +1534,8 @@
1481
1534
  const copyStatus = document.querySelector("#webuiBootFailureCopyStatus");
1482
1535
  const appSource = loader?.dataset?.appSrc || "/app.js";
1483
1536
  const bootStartedAt = new Date();
1537
+ const DIAGNOSTIC_REQUEST_TIMEOUT_MS = 3_000;
1538
+ const JAVASCRIPT_CONTENT_TYPES = ["text/javascript", "application/javascript"];
1484
1539
  let bootSettled = false;
1485
1540
  let bootFailed = false;
1486
1541
  let watchdog = null;
@@ -1507,29 +1562,64 @@
1507
1562
  return boundedSafeText(error);
1508
1563
  }
1509
1564
 
1510
- async function responseSummary(url, label, { parseHealth = false, readSource = false } = {}) {
1565
+ async function responseSummary(url, label, { parseHealth = false, readSource = false, expectedTypes = [] } = {}) {
1511
1566
  const safeUrl = sanitizedUrl(url);
1567
+ const controller = typeof AbortController === "function" ? new AbortController() : null;
1568
+ let timedOut = false;
1569
+ let timeoutId = null;
1512
1570
  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 };
1571
+ const request = (async () => {
1572
+ const response = await fetch(url, { cache: "no-store", credentials: "same-origin", ...(controller ? { signal: controller.signal } : {}) });
1573
+ const type = String(response.headers?.get?.("content-type") || "unknown").split(";", 1)[0].trim().toLowerCase();
1574
+ const contentTypeMismatch = response.ok && expectedTypes.length > 0 && !expectedTypes.includes(type);
1575
+ let suffix = contentTypeMismatch ? ` (expected ${expectedTypes.join(" or ")})` : "";
1576
+ let source = "";
1577
+ let invalidJson = false;
1578
+ if (parseHealth && response.ok) {
1579
+ const data = await response.clone().json().catch(() => null);
1580
+ invalidJson = !data || typeof data !== "object";
1581
+ const fields = [data?.ok === true ? "ok=true" : "", data?.webuiVersion ? `webuiVersion=${boundedSafeText(data.webuiVersion, 80)}` : ""].filter(Boolean);
1582
+ if (fields.length) suffix += ` (${fields.join(", ")})`;
1583
+ if (invalidJson) suffix += " (invalid JSON)";
1584
+ }
1585
+ if (readSource && response.ok) source = await response.text();
1586
+ else response.body?.cancel?.().catch?.(() => {});
1587
+ return {
1588
+ ok: response.ok && !contentTypeMismatch && !invalidJson,
1589
+ status: response.status,
1590
+ type,
1591
+ safeUrl,
1592
+ label,
1593
+ contentTypeMismatch,
1594
+ invalidJson,
1595
+ timedOut: false,
1596
+ line: `- ${label}: HTTP ${response.status} ${type}${suffix} — ${safeUrl}`,
1597
+ source,
1598
+ };
1599
+ })();
1600
+ const timeout = new Promise((_, reject) => {
1601
+ timeoutId = setTimeout(() => {
1602
+ timedOut = true;
1603
+ controller?.abort();
1604
+ const timeoutError = new Error(`Diagnostic request timed out after ${DIAGNOSTIC_REQUEST_TIMEOUT_MS / 1_000} seconds`);
1605
+ timeoutError.name = "DiagnosticTimeoutError";
1606
+ reject(timeoutError);
1607
+ }, DIAGNOSTIC_REQUEST_TIMEOUT_MS);
1608
+ });
1609
+ return await Promise.race([request, timeout]);
1525
1610
  } catch (error) {
1526
- return { ok: false, status: null, type: "unknown", safeUrl, label, line: `- ${label}: request failed (${boundedSafeText(errorText(error), 240)}) — ${safeUrl}`, source: "" };
1611
+ const detail = timedOut
1612
+ ? `diagnostic timed out after ${DIAGNOSTIC_REQUEST_TIMEOUT_MS / 1_000} seconds`
1613
+ : `request failed (${boundedSafeText(errorText(error), 240)})`;
1614
+ return { ok: false, status: null, type: "unknown", safeUrl, label, timedOut, contentTypeMismatch: false, invalidJson: false, line: `- ${label}: ${detail} — ${safeUrl}`, source: "" };
1615
+ } finally {
1616
+ clearTimeout(timeoutId);
1527
1617
  }
1528
1618
  }
1529
1619
 
1530
1620
  async function startupAssetReport() {
1531
1621
  const appUrl = new URL(appSource, window.location.href);
1532
- const app = await responseSummary(appUrl.href, "entry module", { readSource: true });
1622
+ const app = await responseSummary(appUrl.href, "entry module", { readSource: true, expectedTypes: JAVASCRIPT_CONTENT_TYPES });
1533
1623
  if (!app.source) return { probes: [app], lines: [app.line], failures: app.ok ? [] : [app] };
1534
1624
 
1535
1625
  const imported = [];
@@ -1542,15 +1632,30 @@
1542
1632
  if (imported.length >= 24) break;
1543
1633
  }
1544
1634
 
1545
- const importedProbes = await Promise.all(imported.map((item) => responseSummary(item.url, "imported module")));
1635
+ const importedProbes = await Promise.all(imported.map((item) => responseSummary(item.url, "imported module", { expectedTypes: JAVASCRIPT_CONTENT_TYPES })));
1546
1636
  const probes = [app, ...importedProbes];
1547
1637
  return { probes, lines: probes.map((probe) => probe.line), failures: probes.filter((probe) => !probe.ok) };
1548
1638
  }
1549
1639
 
1550
- function startupAssessment(health, assets, error) {
1640
+ async function webManifestReport() {
1641
+ const probe = await responseSummary(new URL("/manifest.webmanifest", window.location.href).href, "optional web manifest", {
1642
+ readSource: true,
1643
+ expectedTypes: ["application/manifest+json", "application/json"],
1644
+ });
1645
+ if (!probe.ok || !probe.source) return { ...probe, validJson: false };
1646
+ try {
1647
+ JSON.parse(probe.source);
1648
+ return { ...probe, validJson: true };
1649
+ } catch (error) {
1650
+ return { ...probe, validJson: false, line: `${probe.line} (invalid JSON: ${boundedSafeText(errorText(error), 160)})` };
1651
+ }
1652
+ }
1653
+
1654
+ function startupAssessment(health, assets, reason, error) {
1551
1655
  const missingImports = assets.failures.filter((probe) => probe.label === "imported module" && probe.status === 404);
1552
1656
  const firstFailure = assets.failures[0] || (!health.ok ? health : null);
1553
1657
  const originalError = boundedSafeText(errorText(error));
1658
+ const failureText = `${boundedSafeText(reason)}\n${originalError}`;
1554
1659
  if (missingImports.length) {
1555
1660
  const paths = missingImports.map((probe) => new URL(probe.safeUrl).pathname);
1556
1661
  return {
@@ -1562,8 +1667,25 @@
1562
1667
  };
1563
1668
  }
1564
1669
  if (firstFailure) {
1670
+ const path = new URL(firstFailure.safeUrl).pathname;
1671
+ if (firstFailure.timedOut) {
1672
+ return {
1673
+ summary: `A diagnostic check timed out while probing ${path}.`,
1674
+ likelyCause: firstFailure.label === "backend health"
1675
+ ? "The browser shell loaded, but the backend or browser network service did not answer the bounded health check."
1676
+ : "The startup asset request remained pending; check the backend, service worker, or browser network state.",
1677
+ failingUrls: [firstFailure.safeUrl],
1678
+ };
1679
+ }
1680
+ if (firstFailure.contentTypeMismatch) {
1681
+ return {
1682
+ summary: `Wrong content type for startup asset ${path}: ${firstFailure.type}.`,
1683
+ 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.",
1684
+ failingUrls: [firstFailure.safeUrl],
1685
+ };
1686
+ }
1565
1687
  return {
1566
- summary: `Startup request failed: ${new URL(firstFailure.safeUrl).pathname}${firstFailure.status ? ` (HTTP ${firstFailure.status})` : ""}.`,
1688
+ summary: `Startup request failed: ${path}${firstFailure.status ? ` (HTTP ${firstFailure.status})` : ""}.`,
1567
1689
  likelyCause: firstFailure.label === "backend health"
1568
1690
  ? "The browser shell loaded, but the WebUI backend is unavailable or unreachable."
1569
1691
  : "A startup asset is unavailable, blocked, or served with an unsuccessful response.",
@@ -1573,6 +1695,20 @@
1573
1695
  if (/critical stylesheet/i.test(originalError)) {
1574
1696
  return { summary: "The critical stylesheet failed to load.", likelyCause: "The stylesheet request failed even though the startup-module probes succeeded.", failingUrls: [] };
1575
1697
  }
1698
+ if (/\bSyntaxError\b|unexpected token|unexpected identifier|already been declared|invalid or unexpected token|missing[ )\]}]/i.test(failureText)) {
1699
+ return {
1700
+ summary: `JavaScript failed during startup: ${boundedSafeText(originalError, 180)}.`,
1701
+ 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.",
1702
+ failingUrls: [],
1703
+ };
1704
+ }
1705
+ if (/watchdog timed out|startup did not finish/i.test(failureText)) {
1706
+ return {
1707
+ summary: "WebUI startup stalled even though the current HTTP checks succeeded.",
1708
+ 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.",
1709
+ failingUrls: [],
1710
+ };
1711
+ }
1576
1712
  return {
1577
1713
  summary: "All probed startup URLs currently respond successfully, but module evaluation still failed.",
1578
1714
  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 +1718,16 @@
1582
1718
 
1583
1719
  async function troubleshootingReport(reason, error) {
1584
1720
  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);
1721
+ const [health, assets, manifest] = await Promise.all([
1722
+ responseSummary(new URL("/api/health", window.location.href).href, "backend health", { parseHealth: true, expectedTypes: ["application/json"] }),
1723
+ startupAssetReport(),
1724
+ webManifestReport(),
1725
+ ]);
1726
+ const assessment = startupAssessment(health, assets, reason, error);
1727
+ const manifestHasIssue = !manifest.ok || !manifest.validJson;
1728
+ const manifestImpact = manifestHasIssue
1729
+ ? "The web manifest has a separate problem that can produce DevTools console errors, but it does not execute or block app.js startup."
1730
+ : "The optional web manifest is valid and is not the startup blocker.";
1588
1731
  const failedProbes = [...(!health.ok ? [health] : []), ...assets.failures];
1589
1732
  const failingChecks = failedProbes.length
1590
1733
  ? failedProbes.map((probe) => probe.line)
@@ -1617,14 +1760,20 @@
1617
1760
  health.line,
1618
1761
  ...assets.lines,
1619
1762
  "",
1763
+ "Related browser checks",
1764
+ "----------------------",
1765
+ manifest.line,
1766
+ `- manifest impact: ${manifestImpact}`,
1767
+ "",
1620
1768
  "Suggested troubleshooting",
1621
1769
  "-------------------------",
1622
1770
  "1. In Pi, run: /webui-status detailed",
1623
1771
  `2. Check the backend: curl -i ${new URL("/api/health", pageUrl).href}`,
1624
1772
  failingAssetCommand,
1625
1773
  "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.",
1774
+ "5. For a JavaScript syntax/evaluation error during development, finish or revert the incomplete edit and run the package syntax check before reloading.",
1775
+ "6. After correcting files, run /webui-start again to restart the server and restore tabs.",
1776
+ "7. Share this complete report with your troubleshooting assistant.",
1628
1777
  ].join("\n");
1629
1778
  return { text, summary: assessment.summary };
1630
1779
  }
@@ -1,4 +1,4 @@
1
- const CACHE_NAME = "pi-webui-pwa-v61";
1
+ const CACHE_NAME = "pi-webui-pwa-v71";
2
2
  const APP_SHELL = [
3
3
  "/",
4
4
  "/index.html",