@firstpick/pi-package-webui 0.10.6 → 0.10.8

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/DEVELOPMENT.md +95 -15
  2. package/README.md +1 -1
  3. package/TECHNICAL.md +6 -4
  4. package/bin/pi-webui-launcher.mjs +6 -3
  5. package/bin/pi-webui-native-update-guardian.mjs +37 -0
  6. package/bin/pi-webui-native-update-runner.mjs +148 -0
  7. package/bin/pi-webui-rpc-supervisor.mjs +85 -10
  8. package/bin/pi-webui-update-context.mjs +83 -0
  9. package/bin/pi-webui.mjs +537 -339
  10. package/lib/component-update-state.mjs +4 -4
  11. package/lib/rpc-supervisor-client.mjs +4 -0
  12. package/lib/rpc-supervisor-protocol.mjs +17 -4
  13. package/lib/update/coordination.mjs +207 -0
  14. package/lib/update/discovery.mjs +58 -0
  15. package/lib/update/migration.mjs +115 -0
  16. package/lib/update/native-jobs.mjs +215 -0
  17. package/lib/update/native-targets.mjs +81 -0
  18. package/lib/update/path-pi.mjs +76 -0
  19. package/lib/update/supervisor.mjs +50 -29
  20. package/lib/update/verification.mjs +18 -0
  21. package/lib/update-commands.mjs +17 -27
  22. package/package.json +3 -3
  23. package/public/app.js +170 -201
  24. package/public/index.html +5 -3
  25. package/public/styles.css +29 -1
  26. package/tests/browser/control-deck-component-updates.spec.mjs +90 -141
  27. package/tests/browser/update-reconnect.spec.mjs +37 -1
  28. package/tests/component-update-api-static.test.mjs +13 -11
  29. package/tests/control-deck-component-updates-static.test.mjs +25 -25
  30. package/tests/cwd-footer-reliability-static.test.mjs +4 -1
  31. package/tests/http-endpoints-harness.test.mjs +32 -9
  32. package/tests/mobile-static.test.mjs +9 -6
  33. package/tests/native-update-discovery.test.mjs +69 -0
  34. package/tests/native-update-lifecycle.test.mjs +90 -0
  35. package/tests/native-update-shell-survival.test.mjs +68 -0
  36. package/tests/native-update-verification.test.mjs +17 -0
  37. package/tests/rpc-supervisor-host.test.mjs +63 -1
  38. package/tests/rpc-supervisor-protocol.test.mjs +8 -0
  39. package/tests/run-all.mjs +6 -2
  40. package/tests/update-api-harness.test.mjs +57 -50
  41. package/tests/update-commands.test.mjs +29 -15
  42. package/tests/update-executor-process-tree-harness.test.mjs +84 -1
  43. package/tests/update-journal-harness.test.mjs +9 -1
  44. package/tests/update-lock-multiprocess-harness.test.mjs +60 -1
  45. package/tests/update-owners.test.mjs +32 -0
  46. package/tests/update-plan.test.mjs +110 -0
  47. package/tests/update-resolver.test.mjs +36 -0
  48. package/tests/update-supervisor-harness.test.mjs +74 -1
  49. package/tests/update-tab-restore-harness.test.mjs +9 -2
  50. package/bin/pi-webui-update-supervisor.mjs +0 -86
package/public/app.js CHANGED
@@ -526,6 +526,7 @@ const elements = {
526
526
  piReleaseNotesGithubLink: $("#piReleaseNotesGithubLink"),
527
527
  piReleaseNotesCloseButton: $("#piReleaseNotesCloseButton"),
528
528
  piComponentUpdateStatus: $("#piComponentUpdateStatus"),
529
+ piComponentUpdateOutput: $("#piComponentUpdateOutput"),
529
530
  piComponentUpdateButton: $("#piComponentUpdateButton"),
530
531
  webuiPackageDialog: $("#webuiPackageDialog"),
531
532
  webuiPackageTitle: $("#webuiPackageTitle"),
@@ -534,6 +535,7 @@ const elements = {
534
535
  webuiPackageNpmButton: $("#webuiPackageNpmButton"),
535
536
  webuiPackageCloseButton: $("#webuiPackageCloseButton"),
536
537
  webuiComponentUpdateStatus: $("#webuiComponentUpdateStatus"),
538
+ webuiComponentUpdateOutput: $("#webuiComponentUpdateOutput"),
537
539
  webuiComponentUpdateButton: $("#webuiComponentUpdateButton"),
538
540
  dialog: $("#extensionDialog"),
539
541
  dialogTitle: $("#dialogTitle"),
@@ -1250,6 +1252,9 @@ let updateStatusRefreshTimer = null;
1250
1252
  let updateNotificationHideTimer = null;
1251
1253
  let componentUpdatePollTimer = null;
1252
1254
  let componentUpdateStartInProgress = false;
1255
+ const observedNativeJobs = { pi: null, webui: null };
1256
+ const uncertainApplyJobs = { pi: null, webui: null };
1257
+ let nativeJobPollError = "";
1253
1258
  let backendOfflineNoticeShown = false;
1254
1259
  let latestMessages = [];
1255
1260
  let latestMessagesSessionKey = "";
@@ -9216,17 +9221,14 @@ function renderUpdateNotification(status = latestUpdateStatus, { force = false }
9216
9221
  return;
9217
9222
  }
9218
9223
 
9219
- const canRunUpdate = latestUpdateStatus.canRunUpdate !== false;
9224
+ const canRunUpdate = latestUpdateStatus.canRunUpdate !== false && !latestUpdateStatus.nativeJobDiscoveryError;
9220
9225
  const hasPiUpdate = !!latestUpdateStatus.pi?.updateAvailable;
9221
9226
  const hasPackageUpdate = !!latestUpdateStatus.webui?.updateAvailable;
9222
9227
  if (elements.updateNotificationTitle) elements.updateNotificationTitle.textContent = items.length === 1 ? `${items[0]} available` : "Pi updates available";
9223
9228
  if (elements.updateNotificationMessage) {
9224
- let message = "Updates are available. Direct Web UI updates are only enabled from localhost on the host machine.";
9225
- if (canRunUpdate) {
9226
- if (hasPiUpdate && hasPackageUpdate) message = "Create and confirm an exact combined update plan for eligible Pi, Web UI, and Pi-owned Optional Features; managed runtimes are staged, verified, activated, and restarted with rollback protection.";
9227
- else if (hasPackageUpdate) message = "Create and confirm an exact package update plan; managed Web UI runtimes are staged, verified, activated, and restarted with rollback protection.";
9228
- else message = "Create and confirm an exact Pi update plan; bundled Pi is staged with the Web UI, while an independent Pi executable is delegated to and verified.";
9229
- }
9229
+ const message = canRunUpdate
9230
+ ? "Choose Pi or Web UI separately. Confirm the exact native command and installation before it runs."
9231
+ : "Updates must start locally, with no other update in progress. Open a version tag for status and recovery guidance.";
9230
9232
  elements.updateNotificationMessage.textContent = message;
9231
9233
  }
9232
9234
  const details = [
@@ -9238,13 +9240,13 @@ function renderUpdateNotification(status = latestUpdateStatus, { force = false }
9238
9240
  if (elements.updateNotificationUpdateButton) {
9239
9241
  elements.updateNotificationUpdateButton.hidden = !canRunUpdate || !hasPiUpdate;
9240
9242
  elements.updateNotificationUpdateButton.disabled = updateRequestInProgress || latestUpdateStatus.updateInProgress;
9241
- elements.updateNotificationUpdateButton.textContent = latestUpdateStatus.updateInProgress ? "Updating…" : "Update Pi & restart";
9243
+ elements.updateNotificationUpdateButton.textContent = "Update Pi";
9242
9244
  }
9243
9245
  if (elements.updateNotificationUpdateAllButton) {
9244
9246
  elements.updateNotificationUpdateAllButton.hidden = !canRunUpdate || !hasPackageUpdate;
9245
9247
  elements.updateNotificationUpdateAllButton.disabled = updateRequestInProgress || latestUpdateStatus.updateInProgress;
9246
9248
  elements.updateNotificationUpdateAllButton.classList.toggle("primary", !hasPiUpdate);
9247
- elements.updateNotificationUpdateAllButton.textContent = latestUpdateStatus.updateInProgress ? "Updating…" : "Update all & restart";
9249
+ elements.updateNotificationUpdateAllButton.textContent = "Update Web UI";
9248
9250
  }
9249
9251
  clearTimeout(updateNotificationHideTimer);
9250
9252
  panel.hidden = false;
@@ -9255,7 +9257,13 @@ async function refreshUpdateStatus({ force = false, notify = true } = {}) {
9255
9257
  const path = force ? "/api/update-status?refresh=1" : "/api/update-status";
9256
9258
  const response = await api(path, { scoped: false });
9257
9259
  latestUpdateStatus = response.data || null;
9258
- if (latestUpdateStatus?.pi?.currentVersion) setPiVersion(latestUpdateStatus.pi.currentVersion);
9260
+ for (const target of COMPONENT_UPDATE_TARGETS) {
9261
+ if (latestUpdateStatus?.nativeJobs && Object.hasOwn(latestUpdateStatus.nativeJobs, target)) {
9262
+ if (latestUpdateStatus.nativeJobs[target] || !uncertainApplyJobs[target]) observedNativeJobs[target] = latestUpdateStatus.nativeJobs[target];
9263
+ }
9264
+ }
9265
+ if (latestUpdateStatus?.nativeJobs && !latestUpdateStatus.nativeJobDiscoveryError) nativeJobPollError = "";
9266
+ if (latestUpdateStatus?.pi?.activeRuntimeVersion && latestUpdateStatus.pi.activeRuntimeVersion !== "unknown") setPiVersion(latestUpdateStatus.pi.activeRuntimeVersion);
9259
9267
  if (notify) renderUpdateNotification(latestUpdateStatus);
9260
9268
  renderComponentUpdateIndicators();
9261
9269
  renderComponentUpdateDialogs();
@@ -9283,11 +9291,21 @@ function componentUpdateJob(target) {
9283
9291
  return job && typeof job === "object" ? job : null;
9284
9292
  }
9285
9293
 
9294
+ function nativeUpdateJob(target) {
9295
+ return observedNativeJobs[target];
9296
+ }
9297
+
9298
+ function nativeUpdateUnsettled(job) {
9299
+ return job && !["success", "partial", "failed", "unchanged", "unknown"].includes(job.phase);
9300
+ }
9301
+
9286
9302
  function componentUpdateTagState(target) {
9287
- const job = componentUpdateJob(target);
9288
- if (job?.state === "running") return "running";
9289
- if (job?.state === "failed") return "failed";
9290
- if (job?.state === "succeeded") return "succeeded";
9303
+ const job = nativeUpdateJob(target);
9304
+ if (job?.phase === "unknown" || latestUpdateStatus?.nativeJobDiscoveryError || nativeJobPollError) return "unknown";
9305
+ if (job?.phase === "partial") return "partial";
9306
+ if (job?.phase === "failed") return "failed";
9307
+ if (job?.phase === "success") return "succeeded";
9308
+ if (nativeUpdateUnsettled(job)) return "running";
9291
9309
  if (latestUpdateStatus?.[target]?.updateAvailable) return "available";
9292
9310
  return "";
9293
9311
  }
@@ -9296,6 +9314,8 @@ function componentUpdateTagStateText(state) {
9296
9314
  switch (state) {
9297
9315
  case "running": return "update running";
9298
9316
  case "failed": return "update failed";
9317
+ case "partial": return "update partially succeeded";
9318
+ case "unknown": return "update status unknown";
9299
9319
  case "succeeded": return "update succeeded";
9300
9320
  case "available": return "update available";
9301
9321
  default: return "";
@@ -9303,7 +9323,7 @@ function componentUpdateTagStateText(state) {
9303
9323
  }
9304
9324
 
9305
9325
  function anyComponentUpdateRunning() {
9306
- return COMPONENT_UPDATE_TARGETS.some((target) => componentUpdateJob(target)?.state === "running");
9326
+ return COMPONENT_UPDATE_TARGETS.some((target) => nativeUpdateUnsettled(nativeUpdateJob(target)));
9307
9327
  }
9308
9328
 
9309
9329
  function renderComponentUpdateIndicators() {
@@ -9313,27 +9333,34 @@ function renderComponentUpdateIndicators() {
9313
9333
 
9314
9334
  function componentUpdateStatusText(target) {
9315
9335
  const label = componentUpdateLabel(target);
9316
- const job = componentUpdateJob(target);
9336
+ const job = nativeUpdateJob(target);
9317
9337
  const pkg = latestUpdateStatus?.[target] || {};
9318
- const current = formatWebuiVersion(pkg.currentVersion || (target === "pi" ? piVersion : webuiVersion) || "");
9338
+ if (latestUpdateStatus?.nativeJobDiscoveryError || nativeJobPollError) {
9339
+ return { text: `Update status cannot be verified: ${latestUpdateStatus?.nativeJobDiscoveryError || nativeJobPollError}. Do not retry until the host is checked.`, level: "error" };
9340
+ }
9341
+ if (!job && latestUpdateStatus?.updateInProgress) {
9342
+ return { text: "An update is in progress, but its job ID is not available. Do not retry until its status is known.", level: "warn" };
9343
+ }
9344
+ if (job) {
9345
+ const id = `Job ${job.transactionId || "unknown"}`;
9346
+ const error = job.error ? ` ${String(job.error).slice(0, 600)}` : "";
9347
+ switch (job.phase) {
9348
+ case "unknown": return { text: `${id}: completion is unknown.${error} Do not retry or restart; check the host and recover manually.`, level: "error" };
9349
+ case "partial": return { text: `${id}: partial result. Some installations failed or were unverified.${error} Verified healthy active changes may have restarted; inspect each receipt before any retry.`, level: "warn" };
9350
+ case "failed": return { text: `${id}: update failed or could not be verified.${error} Inspect receipts and installation health before retrying.`, level: "error" };
9351
+ case "unchanged": return { text: `${id}: commands finished but no installation changed. No automatic restart was needed.`, level: "info" };
9352
+ case "success": return { text: `${id}: changed installations verified. Any healthy changed active component was automatically restarted after idle; unchanged or separate PATH installations were not.`, level: "success" };
9353
+ case "restart-authorized": return { text: `${id}: commands completed and healthy changed active components are waiting for idle before automatic restart.`, level: "warn" };
9354
+ case "restart-in-progress": return { text: `${id}: automatic restart is in progress; reconnecting to the same job.`, level: "warn" };
9355
+ case "restart-pending": return { text: `${id}: successor health and session restoration are not yet confirmed. Do not infer restart success.`, level: "warn" };
9356
+ default: return { text: `${id}: ${job.phase || "status pending"}. Waiting for command completion and verification.`, level: "warn" };
9357
+ }
9358
+ }
9359
+ const current = formatWebuiVersion((target === "pi" ? pkg.pathInstallationVersion : pkg.currentVersion) || (target === "pi" ? piVersion : webuiVersion) || "");
9319
9360
  const latest = formatWebuiVersion(pkg.latestVersion || "");
9320
- if (job?.state === "running") return { text: job.message || `Updating ${label}…`, level: "warn" };
9321
- if (job?.state === "succeeded") {
9322
- const activation = target === "pi"
9323
- ? "New or reloaded Pi sessions use the update; already-running tabs keep their current runtime until restarted."
9324
- : "The managed Web UI runtime was activated automatically; the browser reconnects after the verified restart.";
9325
- return { text: `${job.message || `${label} update completed.`} ${activation}`, level: "success" };
9326
- }
9327
- if (job?.state === "failed") {
9328
- const detail = job.error ? ` ${job.error}` : "";
9329
- return { text: `${job.message || `${label} update failed.`}${detail} You can retry the update.`, level: "error" };
9330
- }
9331
- const availability = pkg.updateAvailable
9332
- ? (latest ? `${label} ${current || "current"} → ${latest} is available.` : `${label} update is available.`)
9333
- : "";
9334
- if (job && job.canStart === false && job.unavailableReason) {
9335
- return { text: [availability, job.unavailableReason].filter(Boolean).join(" "), level: "warn" };
9336
- }
9361
+ const availability = pkg.updateAvailable ? `${label} ${current || "current"} → ${latest || "new version"} is available.` : "";
9362
+ const guidance = target === "pi" ? pkg.pathGuidance : (latestUpdateStatus?.webuiDev ? "Active source checkout stays unchanged; separately proven installations may be eligible." : "");
9363
+ if (guidance) return { text: [availability, guidance].filter(Boolean).join(" "), level: "warn" };
9337
9364
  if (availability) return { text: availability, level: "info" };
9338
9365
  if (pkg.checked && latest) return { text: `${label} is up to date.`, level: "info" };
9339
9366
  if (pkg.skippedReason) return { text: `Update check skipped: ${pkg.skippedReason}.`, level: "info" };
@@ -9342,16 +9369,13 @@ function componentUpdateStatusText(target) {
9342
9369
 
9343
9370
  function componentUpdateButtonState(target) {
9344
9371
  const label = componentUpdateLabel(target);
9345
- const job = componentUpdateJob(target);
9346
- const pkg = latestUpdateStatus?.[target] || {};
9347
- if (job?.state === "running") return { disabled: true, label: "Updating…" };
9348
- if (job && job.canStart === false) return { disabled: true, label: `Update ${label}` };
9372
+ const job = nativeUpdateJob(target);
9349
9373
  if (componentUpdateStartInProgress) return { disabled: true, label: "Starting…" };
9350
- if (updateRequestInProgress || latestUpdateStatus?.updateInProgress || anyComponentUpdateRunning()) {
9374
+ if (nativeJobPollError || latestUpdateStatus?.nativeJobDiscoveryError || latestUpdateStatus?.canRunUpdate === false ||
9375
+ latestUpdateStatus?.updateInProgress || anyComponentUpdateRunning() || job?.phase === "unknown" ||
9376
+ updateRequestInProgress) {
9351
9377
  return { disabled: true, label: `Update ${label}` };
9352
9378
  }
9353
- if (job?.state === "failed") return { disabled: false, label: `Retry ${label} update` };
9354
- if (pkg.checked && !pkg.updateAvailable) return { disabled: true, label: "Up to date" };
9355
9379
  return { disabled: false, label: `Update ${label}` };
9356
9380
  }
9357
9381
 
@@ -9361,6 +9385,21 @@ function renderComponentUpdatePanel(target, statusElement, buttonElement) {
9361
9385
  statusElement.hidden = false;
9362
9386
  statusElement.textContent = text;
9363
9387
  statusElement.dataset.level = level;
9388
+ if (nativeUpdateUnsettled(nativeUpdateJob(target))) statusElement.dataset.updateRunning = "";
9389
+ else delete statusElement.dataset.updateRunning;
9390
+ const output = target === "pi" ? elements.piComponentUpdateOutput : elements.webuiComponentUpdateOutput;
9391
+ const job = nativeUpdateJob(target);
9392
+ if (output) {
9393
+ const lines = (job?.receipts || []).map((receipt) => [
9394
+ `${receipt.id || "Installation"}: ${receipt.status || "unknown"}${receipt.afterVersion ? ` (installed ${receipt.afterVersion})` : ""}`,
9395
+ receipt.stdout ? `stdout: ${String(receipt.stdout).slice(0, 2000)}` : "",
9396
+ receipt.stderr ? `stderr: ${String(receipt.stderr).slice(0, 2000)}` : "",
9397
+ receipt.error ? `error: ${String(receipt.error).slice(0, 600)}` : "",
9398
+ ].filter(Boolean).join("\n"));
9399
+ const verification = (job?.verifiedTargets || []).map((item) => `${item.id}: verification ${item.status || "unproven"}`);
9400
+ output.textContent = [...lines, ...verification].join("\n\n").slice(0, 8000);
9401
+ output.hidden = !output.textContent;
9402
+ }
9364
9403
  const buttonState = componentUpdateButtonState(target);
9365
9404
  buttonElement.disabled = buttonState.disabled;
9366
9405
  buttonElement.textContent = buttonState.label;
@@ -9379,14 +9418,33 @@ function renderComponentUpdateDialogs() {
9379
9418
  }
9380
9419
 
9381
9420
  function syncComponentUpdatePolling() {
9382
- if (anyComponentUpdateRunning()) {
9421
+ if (anyComponentUpdateRunning() || latestUpdateStatus?.updateInProgress) {
9383
9422
  if (componentUpdatePollTimer === null) {
9384
- componentUpdatePollTimer = setTimeout(() => {
9423
+ componentUpdatePollTimer = setTimeout(async () => {
9385
9424
  componentUpdatePollTimer = null;
9386
- refreshUpdateStatus({ notify: false }).catch((error) => {
9387
- addEvent(`Component update status check failed: ${error.message || String(error)}`, "warn");
9388
- if (anyComponentUpdateRunning()) syncComponentUpdatePolling();
9389
- });
9425
+ try {
9426
+ for (const target of COMPONENT_UPDATE_TARGETS) {
9427
+ const job = nativeUpdateJob(target);
9428
+ if (nativeUpdateUnsettled(job) && job.transactionId) {
9429
+ observedNativeJobs[target] = (await api(`/api/update/transactions/${encodeURIComponent(job.transactionId)}`, { scoped: false })).data;
9430
+ }
9431
+ }
9432
+ await refreshUpdateStatus({ notify: false });
9433
+ for (const target of COMPONENT_UPDATE_TARGETS) {
9434
+ if (uncertainApplyJobs[target] && observedNativeJobs[target]?.phase === "planned" &&
9435
+ latestUpdateStatus?.nativeJobs?.[target] === null && !latestUpdateStatus.updateInProgress) {
9436
+ uncertainApplyJobs[target] = null;
9437
+ observedNativeJobs[target] = null;
9438
+ } else if (uncertainApplyJobs[target] && observedNativeJobs[target]?.phase !== "planned" &&
9439
+ observedNativeJobs[target]?.phase !== "launching") uncertainApplyJobs[target] = null;
9440
+ }
9441
+ renderComponentUpdateDialogs();
9442
+ syncComponentUpdatePolling();
9443
+ } catch (error) {
9444
+ nativeJobPollError = error.message || String(error);
9445
+ renderComponentUpdateDialogs();
9446
+ syncComponentUpdatePolling();
9447
+ }
9390
9448
  }, COMPONENT_UPDATE_POLL_MS);
9391
9449
  }
9392
9450
  } else if (componentUpdatePollTimer !== null) {
@@ -9395,69 +9453,77 @@ function syncComponentUpdatePolling() {
9395
9453
  }
9396
9454
  }
9397
9455
 
9398
- function separatePathPiPlanNotice(plan) {
9399
- const identities = Array.isArray(plan?.identities) ? plan.identities : [];
9400
- const activePi = identities.find((identity) => identity?.kind === "pi" && identity.source !== "path");
9401
- const pathPi = identities.find((identity) => identity?.kind === "pi" && identity.source === "path" && identity.canonicalId !== activePi?.canonicalId);
9402
- return pathPi ? `PATH Pi${pathPi.version ? ` v${pathPi.version}` : ""} is a separate installation and will remain untouched. Run pi update in a terminal to update it.` : "";
9403
- }
9404
-
9405
- function componentUpdateConfirmationText(target) {
9406
- const pkg = latestUpdateStatus?.[target] || {};
9407
- const versionText = pkg.updateAvailable ? `\n\nDetected update: ${packageUpdateText(componentUpdateLabel(target), pkg)}.` : "";
9408
- if (target === "pi") {
9409
- return `Create and apply an exact Pi update plan now?${versionText}\n\nBundled Pi updates are staged with the current Web UI in a side-by-side managed runtime and activated with a health-gated restart. A verified independent Pi executable delegates to that exact executable and is rejected if it cannot reach the confirmed version.`;
9410
- }
9411
- return `Create and apply an exact Web UI update plan now?${versionText}\n\nThe confirmed Web UI and Pi versions are staged outside the live installation, probed, and activated through the stable launcher. Activation restarts the Web UI automatically and rolls back the runtime pointer if health verification fails.`;
9456
+ function componentUpdateConfirmationText(plan) {
9457
+ const context = plan.context || {};
9458
+ const active = plan.active || {};
9459
+ const installations = (plan.targets || []).map((item) => [
9460
+ `${item.id}: ${item.packageName} ${item.beforeVersion} at ${item.installedRoot}`,
9461
+ `Affected root: ${item.effectRoot}`,
9462
+ `Executable: ${item.command.command}`,
9463
+ `Command argv: ${JSON.stringify(item.command.args)}`,
9464
+ ].join("\n")).join("\n\n");
9465
+ return [
9466
+ `Update ${componentUpdateLabel(plan.requested)} with this exact plan?`,
9467
+ `Active Pi: ${active.pi || "unknown"} at ${active.piRoot || "unknown"}.`,
9468
+ plan.pathPi?.eligible
9469
+ ? `Confirmed PATH Pi: ${plan.pathPi.version} at ${plan.pathPi.packageRoot}; executable ${plan.pathPi.executable}; CLI ${plan.pathPi.cli}. It may differ from active Pi.`
9470
+ : `PATH Pi unproven: ${plan.pathPi?.guidance || "No verified PATH Pi version/root was returned; only confirmed commands below are eligible."}`,
9471
+ `Active Web UI: ${active.webui || "unknown"} at ${active.webuiRoot || "unknown"}.`,
9472
+ `Shell: ${context.shell || "unknown"}\nWorking directory: ${context.cwd || "unknown"}\nAgent directory: ${context.agentDir || "unknown"}\nNpm prefix: ${context.npmPrefix || "not applicable"}`,
9473
+ installations,
9474
+ plan.refusals?.length ? `Skipped/manual: ${plan.refusals.join(" · ")}` : "",
9475
+ plan.warning || "Native package lifecycle scripts may run under your existing configuration; no automatic elevation or sandbox is provided.",
9476
+ "Known affected work must be idle. Only changed, verified healthy active components restart automatically after all commands finish and work is idle. Native updates cannot be rolled back automatically.",
9477
+ `Plan digest: ${plan.digest}`,
9478
+ ].filter(Boolean).join("\n\n");
9412
9479
  }
9413
9480
 
9414
9481
  async function startComponentUpdate(target) {
9415
9482
  if (componentUpdateStartInProgress) return;
9416
9483
  const label = componentUpdateLabel(target);
9417
- const job = componentUpdateJob(target);
9418
- if (job?.state === "running" || anyComponentUpdateRunning() || updateRequestInProgress || latestUpdateStatus?.updateInProgress) return;
9419
- if (job && job.canStart === false) {
9420
- addEvent(job.unavailableReason || `${label} update is currently unavailable.`, "warn");
9421
- renderComponentUpdateDialogs();
9422
- return;
9423
- }
9484
+ if (componentUpdateButtonState(target).disabled) return;
9485
+ componentUpdateStartInProgress = true;
9486
+ renderComponentUpdateDialogs();
9424
9487
  let plan;
9425
9488
  try {
9426
9489
  plan = (await api("/api/update/plan", { method: "POST", body: { targets: [target] }, scoped: false }))?.data?.plan;
9427
9490
  } catch (error) {
9428
9491
  addEvent(error.message || String(error), "error");
9492
+ componentUpdateStartInProgress = false;
9493
+ renderComponentUpdateDialogs();
9494
+ return;
9495
+ }
9496
+ if (plan?.requested !== target || !plan.transactionId || !plan.digest || !Array.isArray(plan.targets) || !plan.targets.length) {
9497
+ addEvent("Update preview is incomplete; no command was launched.", "error");
9498
+ componentUpdateStartInProgress = false;
9499
+ renderComponentUpdateDialogs();
9429
9500
  return;
9430
9501
  }
9431
- const planNotice = separatePathPiPlanNotice(plan);
9432
- const confirmed = await appConfirmText(`${componentUpdateConfirmationText(target)}${planNotice ? `\n\n${planNotice}` : ""}\n\nExact plan digest: ${plan.digest}`, {
9433
- affected: target === "pi" ? "The verified active Pi installation on the Web UI host" : "A side-by-side managed Web UI runtime",
9434
- confirmLabel: job?.state === "failed" ? `Retry ${label} update` : `Apply exact ${label} plan`,
9502
+ const confirmed = await appConfirmText(componentUpdateConfirmationText(plan), {
9503
+ affected: plan.targets.map((item) => `${item.id}: ${item.installedRoot}`).join(" · "),
9504
+ confirmLabel: `Run ${label} update`,
9435
9505
  danger: false,
9436
9506
  });
9437
- if (!confirmed) return;
9438
- componentUpdateStartInProgress = true;
9439
- renderComponentUpdateDialogs();
9440
- setServerRestartOverlay(true, `Starting exact ${label} update…`, { phase: "updating" });
9507
+ if (!confirmed) {
9508
+ componentUpdateStartInProgress = false;
9509
+ renderComponentUpdateDialogs();
9510
+ return;
9511
+ }
9441
9512
  try {
9442
9513
  const response = await api("/api/update/apply", { method: "POST", body: { transactionId: plan.transactionId, planDigest: plan.digest }, scoped: false });
9443
- const acceptedState = ["applying", "verifying", "activating"].includes(response?.data?.state)
9444
- ? "running"
9445
- : response?.data?.outcome === "success" ? "succeeded" : "failed";
9446
- const accepted = { target, state: acceptedState, canStart: false, message: `Exact ${label} update ${response?.data?.state || response?.data?.outcome || "accepted"}.`, receipts: response?.data?.receipts || [] };
9447
- if (accepted && typeof accepted === "object") {
9448
- latestUpdateStatus = {
9449
- ...(latestUpdateStatus || {}),
9450
- updateInProgress: true,
9451
- componentUpdates: { ...(latestUpdateStatus?.componentUpdates || {}), [target]: accepted },
9452
- };
9453
- }
9454
- addEvent(`${label} update started in the background`, "info");
9514
+ if (response?.data?.transactionId !== plan.transactionId) throw new Error("Accepted job identity did not match the confirmed plan.");
9515
+ uncertainApplyJobs[target] = null;
9516
+ observedNativeJobs[target] = { transactionId: plan.transactionId, plan, phase: response.data.phase, receipts: [], verifiedTargets: [] };
9517
+ latestUpdateStatus = { ...(latestUpdateStatus || {}), updateInProgress: true };
9518
+ addEvent(`${label} job ${plan.transactionId} launched; watching its durable status`, "info");
9455
9519
  } catch (error) {
9456
- addEvent(error.message || String(error), "error");
9457
- if (error?.statusCode === 409) await refreshUpdateStatus({ notify: false }).catch(() => {});
9520
+ nativeJobPollError = error.message || String(error);
9521
+ uncertainApplyJobs[target] = plan.transactionId;
9522
+ observedNativeJobs[target] = { transactionId: plan.transactionId, plan, phase: "launching", receipts: [], verifiedTargets: [] };
9523
+ latestUpdateStatus = { ...(latestUpdateStatus || {}), updateInProgress: true };
9524
+ addEvent(`${label} launch was not confirmed: ${nativeJobPollError}. Checking job ${plan.transactionId} before any retry.`, "error");
9458
9525
  } finally {
9459
9526
  componentUpdateStartInProgress = false;
9460
- setServerRestartOverlay(false);
9461
9527
  renderComponentUpdateIndicators();
9462
9528
  renderComponentUpdateDialogs();
9463
9529
  syncComponentUpdatePolling();
@@ -9483,109 +9549,6 @@ function initializeUpdateNotifications() {
9483
9549
  }, UPDATE_STATUS_INITIAL_DELAY_MS);
9484
9550
  }
9485
9551
 
9486
- function piUpdateConfirmationText({ all = false, plan = null } = {}) {
9487
- const items = updateNotificationItems();
9488
- const workingWarning = hasWorkingTab() ? "\n\nOne or more Pi tabs look busy or blocked. Finish or abort in-flight work before updating if you need to preserve it." : "";
9489
- const versionText = items.length ? `\n\nDetected update: ${items.join(" · ")}.` : "";
9490
- const scope = all ? "the verified active Pi and Web UI targets" : "the verified active Pi target";
9491
- const refusals = Array.isArray(plan?.refusals) && plan.refusals.length ? `\n\nRefused automatic targets: ${plan.refusals.map((item) => `${item.id}: ${item.guidance}`).join(" · ")}` : "";
9492
- const separatePathPi = separatePathPiPlanNotice(plan);
9493
- const pathNotice = separatePathPi ? `\n\n${separatePathPi}` : "";
9494
- const digest = plan?.digest ? `\n\nExact immutable plan digest: ${plan.digest}` : "";
9495
- return `Apply ${scope} now?${versionText}${refusals}${pathNotice}${digest}\n\nThe server will use only this persisted exact-target plan; it will not re-resolve latest or scan package roots. Managed Web UI activation is health-gated and automatically rolls back on failure.${workingWarning}`;
9496
- }
9497
-
9498
- async function runPiUpdateAndRestart({ all = false } = {}) {
9499
- if (updateRequestInProgress) return;
9500
- if (latestUpdateStatus?.canRunUpdate === false) {
9501
- addEvent("Pi updates can only be started from localhost on the Web UI host", "warn");
9502
- renderUpdateNotification(latestUpdateStatus, { force: true });
9503
- return;
9504
- }
9505
- let plan;
9506
- try {
9507
- plan = (await api("/api/update/plan", { method: "POST", body: { targets: all ? ["pi", "webui"] : ["pi"] }, scoped: false }))?.data?.plan;
9508
- } catch (error) {
9509
- const message = error.message || String(error);
9510
- setServerActionStatus(message, "error");
9511
- addEvent(message, "error");
9512
- renderUpdateNotification(latestUpdateStatus, { force: true });
9513
- return;
9514
- }
9515
- const planTargets = Array.isArray(plan?.targets) ? plan.targets : [];
9516
- if (planTargets.length === 0) {
9517
- const refused = Array.isArray(plan?.refusals) ? plan.refusals.map((item) => `${item.id}: ${item.guidance}`).join(" · ") : "";
9518
- const message = refused ? `No update targets were accepted. ${refused}` : "No update targets were accepted; nothing was changed.";
9519
- setServerActionStatus(message, "error");
9520
- addEvent(message, "error");
9521
- renderUpdateNotification(latestUpdateStatus, { force: true });
9522
- return;
9523
- }
9524
- if (!(await appConfirmText(piUpdateConfirmationText({ all, plan }), { affected: "Only targets accepted by the exact server-owned plan", confirmLabel: all ? "Apply exact update plan" : "Apply exact Pi plan" }))) return;
9525
-
9526
- const updateLabel = all ? "Pi and Web UI exact updates" : "Pi exact update";
9527
- const plannedRestart = planTargets.some((target) => target?.metadata?.managedRuntime === true);
9528
- const progressMessage = plannedRestart
9529
- ? `Running ${updateLabel}. The server will restart after activation…`
9530
- : `Running ${updateLabel}…`;
9531
- updateRequestInProgress = true;
9532
- hideUpdateNotification();
9533
- setServerActionBusy("Updating…");
9534
- setServerActionStatus(progressMessage, "warn");
9535
- setServerRestartOverlay(true, progressMessage, { phase: "updating" });
9536
- try {
9537
- const applyData = (await api("/api/update/apply", { method: "POST", body: { transactionId: plan.transactionId, planDigest: plan.digest }, scoped: false }))?.data || null;
9538
- if (applyData?.state !== "activating") {
9539
- updateRequestInProgress = false;
9540
- setServerRestartOverlay(false);
9541
- resetServerActionControls();
9542
- const outcome = applyData?.outcome || applyData?.state || "failed";
9543
- const succeeded = outcome === "success";
9544
- const partial = outcome === "partial";
9545
- const message = succeeded
9546
- ? `${updateLabel} completed without a Web UI restart.`
9547
- : partial
9548
- ? `${updateLabel} completed partially; review the update receipts before retrying.`
9549
- : `${updateLabel} did not complete; no Web UI restart was requested.`;
9550
- const level = succeeded ? "success" : partial ? "warn" : "error";
9551
- setServerActionStatus(message, level);
9552
- addEvent(message, level === "success" ? "info" : level);
9553
- if (succeeded) hideUpdateNotification({ remember: true });
9554
- else renderUpdateNotification(latestUpdateStatus, { force: true });
9555
- refreshUpdateStatus({ force: true, notify: false }).catch(() => {});
9556
- return;
9557
- }
9558
- addEvent(`${updateLabel} verified; Pi Web UI server activation requested`, "warn");
9559
- } catch (error) {
9560
- if (!error?.backendOffline) {
9561
- updateRequestInProgress = false;
9562
- setServerRestartOverlay(false);
9563
- resetServerActionControls();
9564
- const message = error.message || String(error);
9565
- setServerActionStatus(message, "error");
9566
- addEvent(message, "error");
9567
- renderUpdateNotification(latestUpdateStatus, { force: true });
9568
- return;
9569
- }
9570
- addEvent("Pi Web UI server connection dropped during update activation", "warn");
9571
- }
9572
-
9573
- setBackendOffline(true, new Error("update activation requested from side panel"));
9574
- const restarted = await waitForServerRestart(serverBootIdentity);
9575
- updateRequestInProgress = false;
9576
- resetServerActionControls();
9577
- if (restarted) {
9578
- hideUpdateNotification({ remember: true });
9579
- setServerActionStatus("Updated, restarted, and reconnected.", "success");
9580
- refreshUpdateStatus({ force: true, notify: false }).catch(() => {});
9581
- } else {
9582
- setServerRestartOverlay(false);
9583
- setBackendOffline(true, new Error("update restart reconnect timed out"));
9584
- setServerActionStatus("Update activation started, but the server did not reconnect automatically.", "error");
9585
- addEvent("Pi Web UI server did not come back online after update activation", "error");
9586
- }
9587
- }
9588
-
9589
9552
  function formatBytes(bytes) {
9590
9553
  const value = Number(bytes) || 0;
9591
9554
  if (value < 1024) return `${value} B`;
@@ -47750,11 +47713,11 @@ function updateServerActionButton() {
47750
47713
  const button = elements.runServerActionButton;
47751
47714
  if (!button) return;
47752
47715
  button.disabled = !action;
47753
- button.textContent = action === "restart" ? "Restart" : action === "update" || action === "update-all" ? "Update" : action === "stop" ? "Stop" : "Run";
47716
+ button.textContent = action === "restart" ? "Restart" : action === "update" || action === "update-webui" ? "Update" : action === "stop" ? "Stop" : "Run";
47754
47717
  button.classList.toggle("danger", action === "stop");
47755
47718
  if (action === "restart") setServerActionStatus("Ready to restart the Web UI server.", "info");
47756
- else if (action === "update") setServerActionStatus("Ready to create and confirm an exact Pi-only update plan.", "info");
47757
- else if (action === "update-all") setServerActionStatus("Ready to create and confirm an exact combined update plan for eligible Pi, Web UI, and Pi-owned Optional Features.", "info");
47719
+ else if (action === "update") setServerActionStatus("Ready to preview the verified PATH Pi update.", "info");
47720
+ else if (action === "update-webui") setServerActionStatus("Ready to preview eligible Web UI installations separately from Pi.", "info");
47758
47721
  else if (action === "stop") setServerActionStatus("Ready to stop the Web UI server.", "info");
47759
47722
  else setServerActionStatus();
47760
47723
  }
@@ -47879,8 +47842,14 @@ async function stopServer() {
47879
47842
  async function runSelectedServerAction() {
47880
47843
  const action = elements.serverActionSelect?.value || "";
47881
47844
  if (action === "restart") await restartServer();
47882
- else if (action === "update") await runPiUpdateAndRestart();
47883
- else if (action === "update-all") await runPiUpdateAndRestart({ all: true });
47845
+ else if (action === "update" || action === "update-webui") {
47846
+ const target = action === "update" ? "pi" : "webui";
47847
+ if (componentUpdateButtonState(target).disabled) {
47848
+ setServerActionStatus(componentUpdateStatusText(target).text || "Update status is not safe to start. Check the version tag for details.", "warn");
47849
+ return;
47850
+ }
47851
+ await startComponentUpdate(target);
47852
+ }
47884
47853
  else if (action === "stop") await stopServer();
47885
47854
  }
47886
47855
 
@@ -50455,8 +50424,8 @@ elements.remoteQrDialog?.addEventListener("close", () => {
50455
50424
  });
50456
50425
  elements.serverActionSelect.addEventListener("change", updateServerActionButton);
50457
50426
  elements.runServerActionButton.addEventListener("click", () => runSelectedServerAction().catch((error) => addEvent(error.message || String(error), "error")));
50458
- elements.updateNotificationUpdateButton?.addEventListener("click", () => runPiUpdateAndRestart().catch((error) => addEvent(error.message || String(error), "error")));
50459
- elements.updateNotificationUpdateAllButton?.addEventListener("click", () => runPiUpdateAndRestart({ all: true }).catch((error) => addEvent(error.message || String(error), "error")));
50427
+ elements.updateNotificationUpdateButton?.addEventListener("click", () => startComponentUpdate("pi").catch((error) => addEvent(error.message || String(error), "error")));
50428
+ elements.updateNotificationUpdateAllButton?.addEventListener("click", () => startComponentUpdate("webui").catch((error) => addEvent(error.message || String(error), "error")));
50460
50429
  elements.updateNotificationDismissButton?.addEventListener("click", () => hideUpdateNotification({ remember: true }));
50461
50430
  updateServerActionButton();
50462
50431
  elements.agentDoneNotificationsToggle.addEventListener("change", () => {
package/public/index.html CHANGED
@@ -123,8 +123,8 @@
123
123
  <p id="updateNotificationMessage">A newer Pi version is available.</p>
124
124
  <p id="updateNotificationDetail" class="update-notification-detail muted"></p>
125
125
  <div class="update-notification-actions">
126
- <button id="updateNotificationUpdateButton" class="primary" type="button">Update Pi &amp; restart</button>
127
- <button id="updateNotificationUpdateAllButton" type="button">Update all &amp; restart</button>
126
+ <button id="updateNotificationUpdateButton" class="primary" type="button">Update Pi</button>
127
+ <button id="updateNotificationUpdateAllButton" type="button">Update Web UI</button>
128
128
  <button id="updateNotificationDismissButton" type="button">Later</button>
129
129
  </div>
130
130
  </div>
@@ -964,7 +964,7 @@
964
964
  <option value="" selected>Choose action…</option>
965
965
  <option value="restart">Restart Server</option>
966
966
  <option value="update">Apply exact Pi update</option>
967
- <option value="update-all">Apply exact Pi + Web UI update</option>
967
+ <option value="update-webui">Update Web UI</option>
968
968
  <option value="stop">Stop Server</option>
969
969
  </select>
970
970
  <button id="runServerActionButton" type="button" disabled>Run</button>
@@ -1327,6 +1327,7 @@
1327
1327
  <p id="piReleaseNotesStatus" class="pi-release-notes-status muted" role="status" aria-live="polite"></p>
1328
1328
  <section class="component-update-panel" aria-label="Pi background update">
1329
1329
  <p id="piComponentUpdateStatus" class="component-update-status muted" role="status" aria-live="polite"></p>
1330
+ <pre id="piComponentUpdateOutput" class="component-update-output" aria-label="Pi update command results" hidden></pre>
1330
1331
  <button id="piComponentUpdateButton" class="component-update-button primary" type="button">Update Pi</button>
1331
1332
  </section>
1332
1333
  <div id="piReleaseNotesBody" class="pi-release-notes-body markdown-body"></div>
@@ -1357,6 +1358,7 @@
1357
1358
  </div>
1358
1359
  </dl>
1359
1360
  <p id="webuiComponentUpdateStatus" class="component-update-status muted" role="status" aria-live="polite"></p>
1361
+ <pre id="webuiComponentUpdateOutput" class="component-update-output" aria-label="Web UI update command results" hidden></pre>
1360
1362
  <menu>
1361
1363
  <button id="webuiPackageNpmButton" class="webui-package-npm-link" type="button">View on npm</button>
1362
1364
  <button id="webuiComponentUpdateButton" class="component-update-button primary" type="button">Update Web UI</button>
package/public/styles.css CHANGED
@@ -1466,7 +1466,11 @@ body.embedded-split .side-panel-backdrop {
1466
1466
  color: var(--ctp-green);
1467
1467
  }
1468
1468
  .pi-version-button[data-update-state="failed"]::after,
1469
- .webui-version-button[data-update-state="failed"]::after {
1469
+ .webui-version-button[data-update-state="failed"]::after,
1470
+ .pi-version-button[data-update-state="unknown"]::after,
1471
+ .webui-version-button[data-update-state="unknown"]::after,
1472
+ .pi-version-button[data-update-state="partial"]::after,
1473
+ .webui-version-button[data-update-state="partial"]::after {
1470
1474
  content: "!";
1471
1475
  color: var(--ctp-red);
1472
1476
  }
@@ -11917,6 +11921,30 @@ body:not(.mobile-keyboard-open) .composer-input-row:has(.composer-workflow-mode-
11917
11921
  .component-update-status[data-level="success"] { color: var(--ctp-green); }
11918
11922
  .component-update-status[data-level="warn"] { color: var(--ctp-yellow); }
11919
11923
  .component-update-status[data-level="error"] { color: var(--ctp-red); }
11924
+ .component-update-panel .component-update-output { flex-basis: 100%; }
11925
+ .component-update-output {
11926
+ max-height: 12rem;
11927
+ overflow: auto;
11928
+ white-space: pre-wrap;
11929
+ overflow-wrap: anywhere;
11930
+ font-size: 0.78rem;
11931
+ }
11932
+ .component-update-output[hidden] { display: none; }
11933
+ .component-update-status[data-update-running]::before {
11934
+ content: "";
11935
+ display: inline-block;
11936
+ width: 0.65rem;
11937
+ height: 0.65rem;
11938
+ margin-right: 0.45rem;
11939
+ border: 2px solid currentColor;
11940
+ border-right-color: transparent;
11941
+ border-radius: 50%;
11942
+ animation: component-update-spin 0.8s linear infinite;
11943
+ }
11944
+ @keyframes component-update-spin { to { transform: rotate(360deg); } }
11945
+ @media (prefers-reduced-motion: reduce) {
11946
+ .component-update-status[data-update-running]::before { animation: none; }
11947
+ }
11920
11948
  .component-update-button { flex-shrink: 0; }
11921
11949
 
11922
11950
  .extension-dialog.webui-package-dialog {