@firstpick/pi-package-webui 0.7.6 → 0.7.7
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 +37 -4
- package/bin/pi-webui-rpc-supervisor.mjs +518 -0
- package/bin/pi-webui.mjs +1003 -82
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
- package/lib/rpc-supervisor-client.mjs +301 -0
- package/lib/rpc-supervisor-protocol.mjs +236 -0
- package/lib/rpc-supervisor-state.mjs +165 -0
- package/lib/trust-boundaries.mjs +1 -0
- package/package.json +2 -2
- package/public/app.js +1237 -82
- package/public/index.html +334 -25
- package/public/service-worker.js +6 -1
- package/public/styles.css +366 -52
- package/public/subagent-gate-visibility.mjs +36 -0
- package/public/workflow-status-stack.mjs +69 -0
- package/tests/app-runner-process-tree-harness.test.mjs +37 -3
- package/tests/boot-failure-diagnostics.test.mjs +180 -0
- package/tests/durable-rpc-supervisor-harness.test.mjs +252 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/fixtures/compacting-pi.mjs +0 -0
- package/tests/fixtures/fake-pi.mjs +81 -2
- package/tests/git-panel-file-preview-static.test.mjs +221 -0
- package/tests/http-endpoints-harness.test.mjs +458 -33
- package/tests/mobile-static.test.mjs +74 -12
- package/tests/native-parity-harness.test.mjs +2 -1
- package/tests/native-parity.test.mjs +11 -0
- package/tests/numpad-decimal-input-static.test.mjs +128 -0
- package/tests/prompt-routing-input-clear-static.test.mjs +34 -0
- package/tests/prompt-routing-tab-status.test.mjs +103 -0
- package/tests/rpc-supervisor-host.test.mjs +275 -0
- package/tests/rpc-supervisor-protocol.test.mjs +67 -0
- package/tests/rpc-supervisor-state.test.mjs +62 -0
- package/tests/run-all.mjs +4 -1
- package/tests/streaming-ui-coupling.test.mjs +15 -0
- package/tests/subagent-gate-visibility.test.mjs +66 -0
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagents-helper.test.mjs +136 -0
- package/tests/workflow-status-stack.test.mjs +87 -0
- package/webui-rpc-helper.mjs +160 -2
package/public/index.html
CHANGED
|
@@ -12,9 +12,66 @@
|
|
|
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=
|
|
15
|
+
<link rel="stylesheet" href="/styles.css?v=84" />
|
|
16
|
+
<style id="webuiBootFailureStyles">
|
|
17
|
+
.webui-boot-failure[hidden] { display: none !important; }
|
|
18
|
+
.webui-boot-failure {
|
|
19
|
+
position: fixed;
|
|
20
|
+
inset: 0;
|
|
21
|
+
z-index: 1000;
|
|
22
|
+
display: grid;
|
|
23
|
+
place-items: center;
|
|
24
|
+
overflow: auto;
|
|
25
|
+
padding: 1rem;
|
|
26
|
+
color: #cdd6f4;
|
|
27
|
+
background: rgba(17, 17, 27, 0.96);
|
|
28
|
+
font: 16px/1.5 Inter, ui-sans-serif, system-ui, sans-serif;
|
|
29
|
+
}
|
|
30
|
+
.webui-boot-failure-card {
|
|
31
|
+
width: min(52rem, 100%);
|
|
32
|
+
padding: clamp(1.2rem, 4vw, 2rem);
|
|
33
|
+
border: 1px solid rgba(249, 226, 175, 0.5);
|
|
34
|
+
border-radius: 1rem;
|
|
35
|
+
background: #1e1e2e;
|
|
36
|
+
box-shadow: 0 1.2rem 4rem rgba(0, 0, 0, 0.6);
|
|
37
|
+
}
|
|
38
|
+
.webui-boot-failure-kicker { color: #f9e2af; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
|
|
39
|
+
.webui-boot-failure h1 { margin: 0.45rem 0; font-size: clamp(1.4rem, 4vw, 2rem); }
|
|
40
|
+
.webui-boot-failure p { margin: 0 0 1rem; }
|
|
41
|
+
.webui-boot-failure label { display: block; margin-bottom: 0.4rem; font-weight: 700; }
|
|
42
|
+
.webui-boot-failure textarea {
|
|
43
|
+
width: 100%;
|
|
44
|
+
min-height: min(42vh, 22rem);
|
|
45
|
+
padding: 0.8rem;
|
|
46
|
+
resize: vertical;
|
|
47
|
+
color: #cdd6f4;
|
|
48
|
+
background: #11111b;
|
|
49
|
+
border: 1px solid #45475a;
|
|
50
|
+
border-radius: 0.7rem;
|
|
51
|
+
font: 0.82rem/1.45 ui-monospace, SFMono-Regular, Consolas, monospace;
|
|
52
|
+
}
|
|
53
|
+
.webui-boot-failure-actions { display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: 0.8rem; }
|
|
54
|
+
.webui-boot-failure button { min-height: 44px; padding: 0.55rem 0.9rem; color: #cdd6f4; background: #313244; border: 1px solid #6c7086; border-radius: 0.7rem; cursor: pointer; font: inherit; }
|
|
55
|
+
.webui-boot-failure button:first-child { color: #11111b; background: #a6e3a1; border-color: #a6e3a1; font-weight: 800; }
|
|
56
|
+
.webui-boot-failure-status { min-height: 1.5em; margin-top: 0.65rem !important; color: #a6e3a1; }
|
|
57
|
+
</style>
|
|
16
58
|
</head>
|
|
17
59
|
<body>
|
|
60
|
+
<section id="webuiBootFailurePanel" class="webui-boot-failure" aria-live="assertive" hidden>
|
|
61
|
+
<div class="webui-boot-failure-card" role="alert">
|
|
62
|
+
<span class="webui-boot-failure-kicker">Frontend startup failed</span>
|
|
63
|
+
<h1>Pi Web UI could not load correctly</h1>
|
|
64
|
+
<p id="webuiBootFailureReason">The browser could not initialize the application. A bounded diagnostic report is being collected.</p>
|
|
65
|
+
<label for="webuiBootFailureReport">Copyable troubleshooting report</label>
|
|
66
|
+
<textarea id="webuiBootFailureReport" rows="14" readonly spellcheck="false">Collecting diagnostics…</textarea>
|
|
67
|
+
<div class="webui-boot-failure-actions">
|
|
68
|
+
<button id="copyWebuiBootFailureReportButton" type="button">Copy troubleshooting report</button>
|
|
69
|
+
<button id="reloadWebuiAfterBootFailureButton" type="button">Reload page</button>
|
|
70
|
+
</div>
|
|
71
|
+
<p id="webuiBootFailureCopyStatus" class="webui-boot-failure-status" role="status" aria-live="polite"></p>
|
|
72
|
+
</div>
|
|
73
|
+
</section>
|
|
74
|
+
|
|
18
75
|
<button id="sidePanelExpandButton" class="side-panel-expand-button" type="button" aria-controls="sidePanel" aria-expanded="false" aria-label="Expand side panel" title="Expand side panel">
|
|
19
76
|
<span class="side-panel-button-icon" aria-hidden="true">
|
|
20
77
|
<span></span><span></span><span></span>
|
|
@@ -136,6 +193,27 @@
|
|
|
136
193
|
<form id="composer" class="composer">
|
|
137
194
|
<div id="commandSuggest" class="command-suggest" role="listbox" aria-label="Command and path suggestions" hidden></div>
|
|
138
195
|
<div class="composer-input-row">
|
|
196
|
+
<div id="workflowModeControls" class="composer-workflow-mode-dock" role="group" aria-label="Workflow Mode controls" hidden>
|
|
197
|
+
<button
|
|
198
|
+
id="workflowOverlayOpenButton"
|
|
199
|
+
class="composer-icon-button composer-workflow-overlay-open-button"
|
|
200
|
+
type="button"
|
|
201
|
+
aria-label="Open workflow overlay"
|
|
202
|
+
aria-controls="widgetArea"
|
|
203
|
+
aria-expanded="false"
|
|
204
|
+
data-tooltip="Open the minimized workflow overlay."
|
|
205
|
+
hidden
|
|
206
|
+
><svg class="composer-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5 12h14M13 6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
|
|
207
|
+
<button
|
|
208
|
+
id="workflowModeButton"
|
|
209
|
+
class="composer-icon-button composer-workflow-mode-button"
|
|
210
|
+
type="button"
|
|
211
|
+
aria-label="Enable Workflow Mode"
|
|
212
|
+
aria-pressed="false"
|
|
213
|
+
data-tooltip="Workflow Mode: generate and run reusable JavaScript orchestration for substantive prompts."
|
|
214
|
+
hidden
|
|
215
|
+
><svg class="composer-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="3" y="3" width="8" height="8" rx="2" fill="none" stroke="currentColor" stroke-width="2"/><path d="M7 11v4a2 2 0 0 0 2 2h4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><rect x="13" y="13" width="8" height="8" rx="2" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
|
|
216
|
+
</div>
|
|
139
217
|
<div class="composer-context-tags">
|
|
140
218
|
<button
|
|
141
219
|
id="busyPromptBehaviorTag"
|
|
@@ -178,27 +256,6 @@
|
|
|
178
256
|
<div id="composerActionsPanel" class="composer-actions-panel" aria-label="Composer actions">
|
|
179
257
|
<button id="newSessionButton" class="composer-new-button" type="button">New</button>
|
|
180
258
|
<button id="compactButton" class="composer-compact-button" type="button" title="Compact the current Pi session context">Compact</button>
|
|
181
|
-
<div id="workflowModeControls" class="composer-publish-menu composer-workflow-mode-controls" hidden>
|
|
182
|
-
<button
|
|
183
|
-
id="workflowOverlayOpenButton"
|
|
184
|
-
class="composer-icon-button composer-workflow-overlay-open-button"
|
|
185
|
-
type="button"
|
|
186
|
-
aria-label="Open workflow overlay"
|
|
187
|
-
aria-controls="widgetArea"
|
|
188
|
-
aria-expanded="false"
|
|
189
|
-
data-tooltip="Open the minimized workflow overlay."
|
|
190
|
-
hidden
|
|
191
|
-
><svg class="composer-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M5 12h14M13 6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
|
|
192
|
-
<button
|
|
193
|
-
id="workflowModeButton"
|
|
194
|
-
class="composer-icon-button composer-workflow-mode-button"
|
|
195
|
-
type="button"
|
|
196
|
-
aria-label="Enable Workflow Mode"
|
|
197
|
-
aria-pressed="false"
|
|
198
|
-
data-tooltip="Workflow Mode: generate and run reusable JavaScript orchestration for substantive prompts."
|
|
199
|
-
hidden
|
|
200
|
-
><svg class="composer-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="3" y="3" width="8" height="8" rx="2" fill="none" stroke="currentColor" stroke-width="2"/><path d="M7 11v4a2 2 0 0 0 2 2h4" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><rect x="13" y="13" width="8" height="8" rx="2" fill="none" stroke="currentColor" stroke-width="2"/></svg></button>
|
|
201
|
-
</div>
|
|
202
259
|
<button
|
|
203
260
|
id="gitWorkflowButton"
|
|
204
261
|
class="composer-icon-button composer-git-button"
|
|
@@ -260,7 +317,7 @@
|
|
|
260
317
|
aria-haspopup="menu"
|
|
261
318
|
aria-expanded="false"
|
|
262
319
|
aria-controls="optionsMenu"
|
|
263
|
-
data-tooltip="Options: command palette, Safety Guard Setup, Guided Git Setup, Git-footer Visibility, natural conversation, resume, reload, remote, name, clone, settings, export, fork, or tree."
|
|
320
|
+
data-tooltip="Options: command palette, Workflow Permission Setup, Safety Guard Setup, Guided Git Setup, Git-footer Visibility, natural conversation, resume, reload, remote, name, clone, settings, export, fork, or tree."
|
|
264
321
|
><svg class="composer-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 7h16M4 12h16M4 17h16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/><circle cx="8" cy="7" r="1.6" fill="currentColor"/><circle cx="16" cy="12" r="1.6" fill="currentColor"/><circle cx="11" cy="17" r="1.6" fill="currentColor"/></svg></button>
|
|
265
322
|
<div id="optionsMenu" class="composer-publish-menu-panel composer-options-menu-panel composer-auto-height-menu-panel" role="menu" aria-label="Common Pi options">
|
|
266
323
|
<button id="optionsCommandPaletteButton" class="composer-publish-menu-item composer-options-menu-item" type="button" role="menuitem">
|
|
@@ -287,6 +344,9 @@
|
|
|
287
344
|
<button id="optionsSettingsButton" class="composer-publish-menu-item composer-options-menu-item" type="button" role="menuitem" data-command="/settings">
|
|
288
345
|
<span>Settings</span>
|
|
289
346
|
</button>
|
|
347
|
+
<button id="optionsWorkflowSetupButton" class="composer-publish-menu-item composer-options-menu-item" type="button" role="menuitem" data-command="/workflow-setup" hidden>
|
|
348
|
+
<span>Workflow Permission Setup</span>
|
|
349
|
+
</button>
|
|
290
350
|
<button id="optionsSafetyGuardSetupButton" class="composer-publish-menu-item composer-options-menu-item" type="button" role="menuitem" data-command="/safety-guard-setup" hidden>
|
|
291
351
|
<span>Safety Guard Setup</span>
|
|
292
352
|
</button>
|
|
@@ -400,7 +460,7 @@
|
|
|
400
460
|
<button id="fileViewerCloseButton" type="button" aria-label="Close file viewer">Close</button>
|
|
401
461
|
</div>
|
|
402
462
|
</header>
|
|
403
|
-
<p id="fileViewerHelp" class="file-viewer-help muted">Markdown files can be viewed as Preview or Source. Select text in
|
|
463
|
+
<p id="fileViewerHelp" class="file-viewer-help muted">Files opened from Git start in Changes mode. Markdown files can also be viewed as Preview or Source. Select text in Source or Preview, add a one-line comment, then Send to include the selection and surrounding context in this Pi session.</p>
|
|
404
464
|
<div id="fileSelectionBar" class="file-selection-bar" hidden>
|
|
405
465
|
<span id="fileSelectionSummary" class="file-selection-summary">No selection</span>
|
|
406
466
|
<input id="fileSelectionCommentInput" class="file-selection-comment" type="text" placeholder="Comment for Pi about this selection…" autocomplete="off" />
|
|
@@ -408,6 +468,7 @@
|
|
|
408
468
|
</div>
|
|
409
469
|
<div class="file-viewer-mode-row">
|
|
410
470
|
<div class="file-viewer-mode-toggle" role="group" aria-label="File view mode">
|
|
471
|
+
<button id="fileViewerChangesModeButton" type="button" aria-pressed="false" hidden>Changes</button>
|
|
411
472
|
<button id="fileViewerSourceModeButton" type="button" aria-pressed="true">Source</button>
|
|
412
473
|
<button id="fileViewerPreviewModeButton" type="button" aria-pressed="false">Preview</button>
|
|
413
474
|
</div>
|
|
@@ -415,6 +476,7 @@
|
|
|
415
476
|
<div class="file-viewer-content">
|
|
416
477
|
<textarea id="fileViewerEditor" class="file-viewer-editor" wrap="soft" spellcheck="false" aria-label="File contents"></textarea>
|
|
417
478
|
<div id="fileViewerPreview" class="file-viewer-preview markdown-body" tabindex="0" hidden></div>
|
|
479
|
+
<div id="fileViewerChanges" class="file-viewer-changes" tabindex="0" aria-label="Git changes for this file" hidden></div>
|
|
418
480
|
</div>
|
|
419
481
|
<p id="fileViewerStatus" class="file-viewer-status muted" role="status" aria-live="polite"></p>
|
|
420
482
|
</section>
|
|
@@ -1166,6 +1228,253 @@
|
|
|
1166
1228
|
</form>
|
|
1167
1229
|
</dialog>
|
|
1168
1230
|
|
|
1169
|
-
<script
|
|
1231
|
+
<script id="webuiBootLoader" data-app-src="/app.js?v=91">
|
|
1232
|
+
(() => {
|
|
1233
|
+
"use strict";
|
|
1234
|
+
|
|
1235
|
+
const loader = document.currentScript;
|
|
1236
|
+
const panel = document.querySelector("#webuiBootFailurePanel");
|
|
1237
|
+
const reasonElement = document.querySelector("#webuiBootFailureReason");
|
|
1238
|
+
const reportElement = document.querySelector("#webuiBootFailureReport");
|
|
1239
|
+
const copyButton = document.querySelector("#copyWebuiBootFailureReportButton");
|
|
1240
|
+
const reloadButton = document.querySelector("#reloadWebuiAfterBootFailureButton");
|
|
1241
|
+
const copyStatus = document.querySelector("#webuiBootFailureCopyStatus");
|
|
1242
|
+
const appSource = loader?.dataset?.appSrc || "/app.js";
|
|
1243
|
+
const bootStartedAt = new Date();
|
|
1244
|
+
let bootSettled = false;
|
|
1245
|
+
let bootFailed = false;
|
|
1246
|
+
let watchdog = null;
|
|
1247
|
+
|
|
1248
|
+
function sanitizedUrl(value) {
|
|
1249
|
+
try {
|
|
1250
|
+
const url = new URL(String(value || ""), window.location.href);
|
|
1251
|
+
return `${url.origin}${url.pathname}`;
|
|
1252
|
+
} catch {
|
|
1253
|
+
return String(value || "").split(/[?#]/, 1)[0];
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
function boundedSafeText(value, limit = 600) {
|
|
1258
|
+
const sanitized = String(value || "Unknown startup failure")
|
|
1259
|
+
.replace(/https?:\/\/[^\s)\]}]+/gi, (url) => sanitizedUrl(url))
|
|
1260
|
+
.replace(/\b(Bearer\s+)[^\s]+/gi, "$1[redacted]")
|
|
1261
|
+
.replace(/\b(token|password|secret|api[-_]?key)\s*[=:]\s*[^\s,;]+/gi, "$1=[redacted]");
|
|
1262
|
+
return sanitized.length > limit ? `${sanitized.slice(0, limit)}…` : sanitized;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
function errorText(error) {
|
|
1266
|
+
if (error instanceof Error) return `${error.name}: ${error.message}`;
|
|
1267
|
+
return boundedSafeText(error);
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
async function responseSummary(url, label, { parseHealth = false, readSource = false } = {}) {
|
|
1271
|
+
const safeUrl = sanitizedUrl(url);
|
|
1272
|
+
try {
|
|
1273
|
+
const response = await fetch(url, { cache: "no-store", credentials: "same-origin" });
|
|
1274
|
+
const type = String(response.headers?.get?.("content-type") || "unknown").split(";", 1)[0];
|
|
1275
|
+
let suffix = "";
|
|
1276
|
+
let source = "";
|
|
1277
|
+
if (parseHealth && response.ok) {
|
|
1278
|
+
const data = await response.clone().json().catch(() => null);
|
|
1279
|
+
const fields = [data?.ok === true ? "ok=true" : "", data?.webuiVersion ? `webuiVersion=${boundedSafeText(data.webuiVersion, 80)}` : ""].filter(Boolean);
|
|
1280
|
+
if (fields.length) suffix = ` (${fields.join(", ")})`;
|
|
1281
|
+
}
|
|
1282
|
+
if (readSource && response.ok) source = await response.text();
|
|
1283
|
+
else response.body?.cancel?.().catch?.(() => {});
|
|
1284
|
+
return { ok: response.ok, status: response.status, type, safeUrl, label, line: `- ${label}: HTTP ${response.status} ${type}${suffix} — ${safeUrl}`, source };
|
|
1285
|
+
} catch (error) {
|
|
1286
|
+
return { ok: false, status: null, type: "unknown", safeUrl, label, line: `- ${label}: request failed (${boundedSafeText(errorText(error), 240)}) — ${safeUrl}`, source: "" };
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
async function startupAssetReport() {
|
|
1291
|
+
const appUrl = new URL(appSource, window.location.href);
|
|
1292
|
+
const app = await responseSummary(appUrl.href, "entry module", { readSource: true });
|
|
1293
|
+
if (!app.source) return { probes: [app], lines: [app.line], failures: app.ok ? [] : [app] };
|
|
1294
|
+
|
|
1295
|
+
const imported = [];
|
|
1296
|
+
const importPattern = /(?:\bfrom\s+|\bimport\s*(?:\(\s*)?)["'](\.\/[^"']+)["']/g;
|
|
1297
|
+
for (const match of app.source.matchAll(importPattern)) {
|
|
1298
|
+
const assetUrl = new URL(match[1], appUrl);
|
|
1299
|
+
if (assetUrl.origin !== window.location.origin) continue;
|
|
1300
|
+
const key = `${assetUrl.origin}${assetUrl.pathname}`;
|
|
1301
|
+
if (!imported.some((item) => item.key === key)) imported.push({ key, url: assetUrl.href });
|
|
1302
|
+
if (imported.length >= 24) break;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
const importedProbes = await Promise.all(imported.map((item) => responseSummary(item.url, "imported module")));
|
|
1306
|
+
const probes = [app, ...importedProbes];
|
|
1307
|
+
return { probes, lines: probes.map((probe) => probe.line), failures: probes.filter((probe) => !probe.ok) };
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
function startupAssessment(health, assets, error) {
|
|
1311
|
+
const missingImports = assets.failures.filter((probe) => probe.label === "imported module" && probe.status === 404);
|
|
1312
|
+
const firstFailure = assets.failures[0] || (!health.ok ? health : null);
|
|
1313
|
+
const originalError = boundedSafeText(errorText(error));
|
|
1314
|
+
if (missingImports.length) {
|
|
1315
|
+
const paths = missingImports.map((probe) => new URL(probe.safeUrl).pathname);
|
|
1316
|
+
return {
|
|
1317
|
+
summary: `Missing startup module${paths.length === 1 ? "" : "s"}: ${paths.join(", ")} (HTTP 404).`,
|
|
1318
|
+
likelyCause: health.ok
|
|
1319
|
+
? "The backend is healthy, but the running server's static asset allowlist is out of sync with app.js."
|
|
1320
|
+
: "The startup module is unavailable and the backend health check also failed; verify the server process first.",
|
|
1321
|
+
failingUrls: missingImports.map((probe) => probe.safeUrl),
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
if (firstFailure) {
|
|
1325
|
+
return {
|
|
1326
|
+
summary: `Startup request failed: ${new URL(firstFailure.safeUrl).pathname}${firstFailure.status ? ` (HTTP ${firstFailure.status})` : ""}.`,
|
|
1327
|
+
likelyCause: firstFailure.label === "backend health"
|
|
1328
|
+
? "The browser shell loaded, but the WebUI backend is unavailable or unreachable."
|
|
1329
|
+
: "A startup asset is unavailable, blocked, or served with an unsuccessful response.",
|
|
1330
|
+
failingUrls: [firstFailure.safeUrl],
|
|
1331
|
+
};
|
|
1332
|
+
}
|
|
1333
|
+
if (/critical stylesheet/i.test(originalError)) {
|
|
1334
|
+
return { summary: "The critical stylesheet failed to load.", likelyCause: "The stylesheet request failed even though the startup-module probes succeeded.", failingUrls: [] };
|
|
1335
|
+
}
|
|
1336
|
+
return {
|
|
1337
|
+
summary: "All probed startup URLs currently respond successfully, but module evaluation still failed.",
|
|
1338
|
+
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.",
|
|
1339
|
+
failingUrls: [],
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
async function troubleshootingReport(reason, error) {
|
|
1344
|
+
const pageUrl = sanitizedUrl(window.location.href);
|
|
1345
|
+
const health = await responseSummary(new URL("/api/health", window.location.href).href, "backend health", { parseHealth: true });
|
|
1346
|
+
const assets = await startupAssetReport();
|
|
1347
|
+
const assessment = startupAssessment(health, assets, error);
|
|
1348
|
+
const failedProbes = [...(!health.ok ? [health] : []), ...assets.failures];
|
|
1349
|
+
const failingChecks = failedProbes.length
|
|
1350
|
+
? failedProbes.map((probe) => probe.line)
|
|
1351
|
+
: ["- none detected by the HTTP probes"];
|
|
1352
|
+
const failingAssetCommand = assessment.failingUrls[0]
|
|
1353
|
+
? `3. Recheck the failing asset: curl -i ${assessment.failingUrls[0]}`
|
|
1354
|
+
: "3. Reload once with the browser cache bypassed, then compare the new report.";
|
|
1355
|
+
const text = [
|
|
1356
|
+
"Pi Web UI startup failure",
|
|
1357
|
+
"=========================",
|
|
1358
|
+
`Time: ${new Date().toISOString()}`,
|
|
1359
|
+
`Page: ${pageUrl}`,
|
|
1360
|
+
`Reason: ${boundedSafeText(reason)}`,
|
|
1361
|
+
`Error: ${boundedSafeText(errorText(error))}`,
|
|
1362
|
+
`Document state: ${document.readyState}`,
|
|
1363
|
+
`Browser: ${boundedSafeText(navigator.userAgent, 300)}`,
|
|
1364
|
+
"",
|
|
1365
|
+
"Diagnosis",
|
|
1366
|
+
"---------",
|
|
1367
|
+
`Summary: ${assessment.summary}`,
|
|
1368
|
+
`Likely cause: ${assessment.likelyCause}`,
|
|
1369
|
+
"Browser note: a transitive import failure may be reported as app.js; the individual probes below identify the actual failing file.",
|
|
1370
|
+
"",
|
|
1371
|
+
"Failing checks",
|
|
1372
|
+
"--------------",
|
|
1373
|
+
...failingChecks,
|
|
1374
|
+
"",
|
|
1375
|
+
"All checks",
|
|
1376
|
+
"----------",
|
|
1377
|
+
health.line,
|
|
1378
|
+
...assets.lines,
|
|
1379
|
+
"",
|
|
1380
|
+
"Suggested troubleshooting",
|
|
1381
|
+
"-------------------------",
|
|
1382
|
+
"1. In Pi, run: /webui-status detailed",
|
|
1383
|
+
`2. Check the backend: curl -i ${new URL("/api/health", pageUrl).href}`,
|
|
1384
|
+
failingAssetCommand,
|
|
1385
|
+
"4. For an imported-module 404, synchronize the WebUI static allowlist and PWA app shell with app.js imports.",
|
|
1386
|
+
"5. After correcting files, run /webui-start again to restart the server and restore tabs.",
|
|
1387
|
+
"6. Share this complete report with your troubleshooting assistant.",
|
|
1388
|
+
].join("\n");
|
|
1389
|
+
return { text, summary: assessment.summary };
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
async function showBootFailure(reason, error) {
|
|
1393
|
+
if (bootSettled || bootFailed) return;
|
|
1394
|
+
bootFailed = true;
|
|
1395
|
+
clearTimeout(watchdog);
|
|
1396
|
+
if (reasonElement) reasonElement.textContent = boundedSafeText(reason, 300);
|
|
1397
|
+
if (panel) panel.hidden = false;
|
|
1398
|
+
if (reportElement) reportElement.value = "Collecting diagnostics…";
|
|
1399
|
+
const report = await troubleshootingReport(reason, error).catch((diagnosticError) => ({
|
|
1400
|
+
summary: boundedSafeText(reason, 300),
|
|
1401
|
+
text: [
|
|
1402
|
+
"Pi Web UI startup failure",
|
|
1403
|
+
`Time: ${new Date().toISOString()}`,
|
|
1404
|
+
`Page: ${sanitizedUrl(window.location.href)}`,
|
|
1405
|
+
`Reason: ${boundedSafeText(reason)}`,
|
|
1406
|
+
`Error: ${boundedSafeText(errorText(error))}`,
|
|
1407
|
+
`Diagnostic collection failed: ${boundedSafeText(errorText(diagnosticError))}`,
|
|
1408
|
+
"Run /webui-status detailed and share this text with your troubleshooting assistant.",
|
|
1409
|
+
].join("\n"),
|
|
1410
|
+
}));
|
|
1411
|
+
if (reasonElement) reasonElement.textContent = report.summary;
|
|
1412
|
+
if (reportElement) reportElement.value = report.text;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
function markBootReady() {
|
|
1416
|
+
if (bootFailed) return;
|
|
1417
|
+
bootSettled = true;
|
|
1418
|
+
clearTimeout(watchdog);
|
|
1419
|
+
window.removeEventListener("error", onWindowError, true);
|
|
1420
|
+
window.removeEventListener("unhandledrejection", onUnhandledRejection);
|
|
1421
|
+
if (panel) panel.hidden = true;
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
function onWindowError(event) {
|
|
1425
|
+
const target = event.target;
|
|
1426
|
+
const resource = target && target !== window ? target.src || target.href : "";
|
|
1427
|
+
const tag = String(target?.tagName || "").toUpperCase();
|
|
1428
|
+
if (resource && !["SCRIPT", "LINK"].includes(tag)) return;
|
|
1429
|
+
const reason = resource ? `A critical ${tag.toLowerCase()} resource failed to load: ${sanitizedUrl(resource)}` : "A JavaScript error stopped WebUI startup.";
|
|
1430
|
+
showBootFailure(reason, event.error || event.message || resource);
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
function onUnhandledRejection(event) {
|
|
1434
|
+
showBootFailure("An unhandled promise rejection stopped WebUI startup.", event.reason);
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
async function copyReport() {
|
|
1438
|
+
const report = reportElement?.value || "";
|
|
1439
|
+
try {
|
|
1440
|
+
if (!report) throw new Error("The report is empty.");
|
|
1441
|
+
if (navigator.clipboard?.writeText) await navigator.clipboard.writeText(report);
|
|
1442
|
+
else {
|
|
1443
|
+
reportElement.focus();
|
|
1444
|
+
reportElement.select();
|
|
1445
|
+
if (!document.execCommand?.("copy")) throw new Error("Clipboard API unavailable.");
|
|
1446
|
+
}
|
|
1447
|
+
if (copyStatus) copyStatus.textContent = "Troubleshooting report copied.";
|
|
1448
|
+
} catch {
|
|
1449
|
+
reportElement?.focus();
|
|
1450
|
+
reportElement?.select();
|
|
1451
|
+
if (copyStatus) copyStatus.textContent = "Automatic copy failed. The report is selected; copy it manually.";
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
window.addEventListener("error", onWindowError, true);
|
|
1456
|
+
window.addEventListener("unhandledrejection", onUnhandledRejection);
|
|
1457
|
+
copyButton?.addEventListener("click", copyReport);
|
|
1458
|
+
reloadButton?.addEventListener("click", () => window.location.reload());
|
|
1459
|
+
|
|
1460
|
+
watchdog = setTimeout(() => {
|
|
1461
|
+
showBootFailure(`WebUI startup did not finish within ${Math.round((Date.now() - bootStartedAt.getTime()) / 1000)} seconds.`, new Error("Startup watchdog timed out"));
|
|
1462
|
+
}, 12_000);
|
|
1463
|
+
|
|
1464
|
+
const importApp = typeof window.__PI_WEBUI_BOOT_IMPORT__ === "function"
|
|
1465
|
+
? window.__PI_WEBUI_BOOT_IMPORT__
|
|
1466
|
+
: (source) => import(source);
|
|
1467
|
+
const criticalStylesheet = document.querySelector('link[rel="stylesheet"]');
|
|
1468
|
+
const stylesheetReady = criticalStylesheet?.sheet
|
|
1469
|
+
? Promise.resolve()
|
|
1470
|
+
: fetch(criticalStylesheet?.href || "/styles.css", { cache: "no-store", credentials: "same-origin" }).then((response) => {
|
|
1471
|
+
if (!response.ok) throw new Error(`Critical stylesheet returned HTTP ${response.status}: ${sanitizedUrl(response.url || criticalStylesheet?.href)}`);
|
|
1472
|
+
response.body?.cancel?.().catch?.(() => {});
|
|
1473
|
+
});
|
|
1474
|
+
Promise.all([importApp(appSource), stylesheetReady]).then(markBootReady).catch((error) => {
|
|
1475
|
+
showBootFailure("The WebUI entry module, one of its imports, or the critical stylesheet failed to load or evaluate.", error);
|
|
1476
|
+
});
|
|
1477
|
+
})();
|
|
1478
|
+
</script>
|
|
1170
1479
|
</body>
|
|
1171
1480
|
</html>
|
package/public/service-worker.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
const CACHE_NAME = "pi-webui-pwa-
|
|
1
|
+
const CACHE_NAME = "pi-webui-pwa-v46";
|
|
2
2
|
const APP_SHELL = [
|
|
3
3
|
"/",
|
|
4
4
|
"/index.html",
|
|
5
5
|
"/styles.css",
|
|
6
6
|
"/app.js",
|
|
7
|
+
"/aur-review-payload.mjs",
|
|
8
|
+
"/guided-git-command-state.mjs",
|
|
9
|
+
"/guided-git-review-state.mjs",
|
|
7
10
|
"/fast-output-live.mjs",
|
|
8
11
|
"/subagent-launch-slot-state.mjs",
|
|
12
|
+
"/subagent-gate-visibility.mjs",
|
|
13
|
+
"/workflow-status-stack.mjs",
|
|
9
14
|
"/voice-conversation.mjs",
|
|
10
15
|
"/favicon.svg",
|
|
11
16
|
"/apple-touch-icon.png",
|