@firstpick/pi-package-webui 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -157,7 +157,7 @@ Optional Natural Conversation server-side voice fallback variables:
157
157
  - Detected app runner dropdown for the active tab cwd, including Cargo, Bun, npm/npx/pnpm, Python/uv, Go/Golang, Zig, C/C++, Docker Compose, root/dev/scripts shell scripts, and other common project runners with live output pinned at the top of the terminal. Running app runners expose line-oriented stdin in the widget for interactive scripts. Projects can add browseable custom runners in `.pi-webui-runners.json` with a command (default `./`) plus a relative path to the file to run.
158
158
  - Guided Git workflow for existing repos and new repos: initialize, create README/.gitignore, initial commit, rename to `main`, add a GitHub remote, pull fetched incoming changes, stage, generate or type commit messages, push, and optionally create a PR.
159
159
  - Browser support for Pi extension UI prompts, widgets, status updates, `/btw` side-question output widgets with optional context transfer/live steering, browser notifications when a tab needs an extension UI response, and an optional side-panel toggle for agent-done notifications.
160
- - Localhost-only Pi/Web UI update checks with a top-right update notification and confirmed restart actions: **Update Pi & restart** runs `pi update` for Pi-only updates, while **Update Pi + Packages & Restart** runs `pi update --all` for Pi plus configured packages.
160
+ - Localhost-only Pi/Web UI update checks with a top-right update notification and confirmed restart actions: **Update Pi & restart** runs `pi update` for Pi-only updates, while **Update Pi + Packages & Restart** runs `pi update --all` plus detected Web UI/Optional Feature package-root updates for Pi plus configured, local agent, project, global npm, and global Bun package roots.
161
161
  - Feedback reactions (`👍`, `👎`, `?`) on final assistant output plus tool/bash action cards, which can ask Pi to create or update a LEARNING.
162
162
  - Mobile-friendly layout, PWA install support where the browser allows it, backend-offline recovery, and a dedicated server-restart overlay while confirmed restart/update actions run.
163
163
 
@@ -331,7 +331,7 @@ Useful browser endpoints exposed by the local server include:
331
331
  - `POST /api/action-feedback?tab=<tabId>` for feedback on final assistant output and action cards.
332
332
  - `GET /api/optional-features` for optional companion package install/update status.
333
333
  - `POST /api/optional-feature-install` for installing or updating known optional companion packages from the side panel.
334
- - `GET /api/update-status`, localhost-only `POST /api/restart`, and localhost-only `POST /api/update` for checking Pi/Web UI updates and restarting the Web UI. Use `POST /api/update?all=1` to run `pi update --all` for Pi plus configured packages.
334
+ - `GET /api/update-status`, localhost-only `POST /api/restart`, and localhost-only `POST /api/update` for checking Pi/Web UI updates and restarting the Web UI. Use `POST /api/update?all=1` to run `pi update --all` plus detected Web UI/Optional Feature package-root updates for Pi plus configured, local agent, project, global npm, and global Bun package roots.
335
335
  - `GET /api/network`, localhost-only `POST /api/network/open`, localhost-only `POST /api/network/close`, `GET /api/remote-auth`, `POST /api/remote-auth`, and localhost-only `POST /api/remote-auth/settings` for trusted-LAN exposure and optional 4-digit PIN authentication when serving non-local browser clients.
336
336
 
337
337
  For local development, run the checkout helper directly, for example:
package/bin/pi-webui.mjs CHANGED
@@ -81,7 +81,7 @@ const UPDATE_STATUS_CACHE_MS = 10 * 60 * 1000;
81
81
  const UPDATE_STATUS_TIMEOUT_MS = 10 * 1000;
82
82
  const PI_UPDATE_TIMEOUT_MS = 15 * 60 * 1000;
83
83
  const PI_UPDATE_OUTPUT_MAX_CHARS = 120_000;
84
- const UPDATE_PACKAGE_NAMES = [PI_CODING_AGENT_PACKAGE, WEBUI_PACKAGE];
84
+ const CORE_UPDATE_PACKAGE_NAMES = [PI_CODING_AGENT_PACKAGE, WEBUI_PACKAGE];
85
85
  const PACKAGE_UPDATE_TIMEOUT_MS = 15 * 60 * 1000;
86
86
  const PACKAGE_UPDATE_OUTPUT_MAX_CHARS = 120_000;
87
87
  const CODEX_USAGE_TIMEOUT_MS = 15 * 1000;
@@ -265,6 +265,11 @@ const WEBUI_CONTROLLED_PACKAGES = new Set([
265
265
  .filter(([featureId]) => featureId !== NATURAL_CONVERSATION_FEATURE_ID)
266
266
  .map(([, packageName]) => packageName),
267
267
  ]);
268
+ const UPDATE_PACKAGE_NAMES = [...new Set([
269
+ ...CORE_UPDATE_PACKAGE_NAMES,
270
+ ...WEBUI_CONTROLLED_PACKAGES,
271
+ ...OPTIONAL_FEATURE_PACKAGES.values(),
272
+ ])].sort();
268
273
  const NATURAL_CONVERSATION_STATUS_KEY = "natural-conversation";
269
274
  const NATURAL_CONVERSATION_COMMAND_NAMES = ["talk", "voice", "conversation"];
270
275
  const PACKAGE_NAME_CACHE = new Map();
@@ -675,7 +680,9 @@ function makeHttpError(statusCode, message) {
675
680
 
676
681
  function sendError(res, statusCode, error) {
677
682
  const message = statusCode >= 500 ? sanitizeError(error) : formatCliError(error);
678
- sendJson(res, statusCode, { ok: false, error: message });
683
+ const payload = { ok: false, error: message };
684
+ if (error?.optionalFeatureInstall) payload.optionalFeatureInstall = error.optionalFeatureInstall;
685
+ sendJson(res, statusCode, payload);
679
686
  }
680
687
 
681
688
  function formatBytes(bytes) {
@@ -1294,25 +1301,115 @@ async function optionalFeaturePackageStatuses() {
1294
1301
  return { features };
1295
1302
  }
1296
1303
 
1304
+ function optionalFeatureInstallOutputTail(result, maxLength = 4000) {
1305
+ const text = stripAnsi([result?.stderr, result?.stdout].filter(Boolean).join("\n").trim());
1306
+ if (text.length <= maxLength) return text;
1307
+ return `…${text.slice(-Math.max(0, maxLength - 1))}`;
1308
+ }
1309
+
1310
+ function optionalFeatureInstallFailureKind(result, message = "") {
1311
+ const combined = `${message}\n${result?.error || ""}\n${result?.stderr || ""}\n${result?.stdout || ""}`;
1312
+ if (result?.timedOut) return "timeout";
1313
+ if (/\b(?:ENOENT|command not found|not recognized|spawn\s+\S+\s+ENOENT)\b/i.test(combined)) return "npm-not-found";
1314
+ if (/\b(?:EACCES|EPERM|permission denied|access denied)\b/i.test(combined)) return "permission";
1315
+ if (/\b(?:EAI_AGAIN|ENOTFOUND|ECONNRESET|ETIMEDOUT|network timeout|registry\.npmjs\.org|fetch failed)\b/i.test(combined)) return "network";
1316
+ return "npm-exit";
1317
+ }
1318
+
1319
+ function optionalFeatureInstallFailureHint(kind, { command, installRoot } = {}) {
1320
+ switch (kind) {
1321
+ case "install-root":
1322
+ return `Set ${OPTIONAL_FEATURE_INSTALL_ROOT_ENV} to the Pi/Web UI npm package root, then retry.`;
1323
+ case "npm-not-found":
1324
+ return "npm could not be started. Install npm or set PI_WEBUI_NPM_BIN to an absolute npm-compatible executable path.";
1325
+ case "permission":
1326
+ return `The Web UI process cannot write to ${installRoot || "the selected npm prefix"}. Retry from the owning user or use ${OPTIONAL_FEATURE_INSTALL_ROOT_ENV} with a writable package root.`;
1327
+ case "network":
1328
+ return "npm could not reach the registry reliably. Check network/proxy/registry settings, then retry or run the copied command manually.";
1329
+ case "timeout":
1330
+ return "npm did not finish within 5 minutes. Check for a stuck package manager, lock contention, or slow network, then retry manually.";
1331
+ case "status-check":
1332
+ return "npm finished, but Web UI could not verify the package status. Reload the Web UI and recheck Optional features.";
1333
+ default:
1334
+ return command ? "Run the copied npm command manually on the Web UI host to see full package-manager diagnostics." : "Check the activity log and npm output, then retry.";
1335
+ }
1336
+ }
1337
+
1338
+ function makeOptionalFeatureInstallError(statusCode, message, details = {}) {
1339
+ const error = makeHttpError(statusCode, message);
1340
+ error.optionalFeatureInstall = {
1341
+ kind: details.kind || "unknown",
1342
+ featureId: details.featureId || "",
1343
+ packageName: details.packageName || "",
1344
+ installRoot: details.installRoot || "",
1345
+ command: details.command || "",
1346
+ exitCode: details.exitCode,
1347
+ timedOut: details.timedOut === true,
1348
+ message,
1349
+ hint: details.hint || optionalFeatureInstallFailureHint(details.kind, details),
1350
+ outputTail: details.outputTail || "",
1351
+ };
1352
+ return error;
1353
+ }
1354
+
1297
1355
  async function installOptionalFeaturePackage(featureId) {
1298
1356
  const beforeStatus = await optionalFeaturePackageStatus(featureId);
1299
1357
  const packageName = beforeStatus.packageName;
1300
1358
 
1301
- const installRoot = await optionalDependencyInstallRoot();
1359
+ let installRoot;
1360
+ try {
1361
+ installRoot = await optionalDependencyInstallRoot();
1362
+ } catch (error) {
1363
+ const message = formatCliError(error);
1364
+ throw makeOptionalFeatureInstallError(error?.statusCode || 500, message, {
1365
+ kind: "install-root",
1366
+ featureId,
1367
+ packageName,
1368
+ hint: optionalFeatureInstallFailureHint("install-root"),
1369
+ });
1370
+ }
1371
+
1302
1372
  const npmCommand = process.env.PI_WEBUI_NPM_BIN || "npm";
1303
1373
  const args = ["install", "--prefix", installRoot, packageName];
1374
+ const command = formatCommandForDisplay(npmCommand, args);
1304
1375
  const result = await runCommand(npmCommand, args, {
1305
1376
  cwd: installRoot,
1306
1377
  timeoutMs: 5 * 60 * 1000,
1307
1378
  maxOutputLength: 80000,
1308
1379
  });
1309
- const command = formatCommandForDisplay(npmCommand, args);
1310
1380
  const ok = result.exitCode === 0 && !result.timedOut && !result.error;
1311
1381
  if (!ok) {
1312
- const details = [result.error, result.timedOut ? "timed out" : undefined, result.stderr?.trim(), result.stdout?.trim()].filter(Boolean).join("\n");
1313
- throw makeHttpError(500, `Optional feature install failed: ${command}${details ? `\n${details}` : ""}`);
1382
+ const kind = optionalFeatureInstallFailureKind(result);
1383
+ const message = result.timedOut
1384
+ ? `Optional feature install timed out after 5 minutes: ${command}`
1385
+ : result.error
1386
+ ? `Optional feature install could not start: ${command}`
1387
+ : `Optional feature install failed with exit code ${result.exitCode ?? "unknown"}: ${command}`;
1388
+ throw makeOptionalFeatureInstallError(result.timedOut ? 504 : 500, message, {
1389
+ kind,
1390
+ featureId,
1391
+ packageName,
1392
+ installRoot,
1393
+ command,
1394
+ exitCode: result.exitCode,
1395
+ timedOut: result.timedOut,
1396
+ outputTail: optionalFeatureInstallOutputTail(result),
1397
+ });
1398
+ }
1399
+ let afterStatus;
1400
+ try {
1401
+ afterStatus = await optionalFeaturePackageStatus(featureId);
1402
+ } catch (error) {
1403
+ const message = `Optional feature install finished, but status verification failed: ${formatCliError(error)}`;
1404
+ throw makeOptionalFeatureInstallError(error?.statusCode || 500, message, {
1405
+ kind: "status-check",
1406
+ featureId,
1407
+ packageName,
1408
+ installRoot,
1409
+ command,
1410
+ outputTail: optionalFeatureInstallOutputTail(result),
1411
+ });
1314
1412
  }
1315
- const afterStatus = await optionalFeaturePackageStatus(featureId);
1316
1413
  const operation = beforeStatus.installed ? "Updated" : "Installed";
1317
1414
  return {
1318
1415
  featureId,
@@ -6226,7 +6323,7 @@ async function currentWebuiPackageUpdateTask() {
6226
6323
  const sourceCheckout = webuiDevServer || !String(packageRoot).split(path.sep).includes("node_modules");
6227
6324
  if (sourceCheckout) {
6228
6325
  const manifest = await readJsonFileIfExists(path.join(packageRoot, "package.json"));
6229
- const packages = Object.keys(manifest?.dependencies || {}).filter(isWebuiOrPiPackageName).sort();
6326
+ const packages = declaredWebuiPiPackageNames(manifest);
6230
6327
  return npmPrefixUpdateTask("current Web UI checkout package dependencies", packageRoot, packages);
6231
6328
  }
6232
6329
 
@@ -6241,6 +6338,36 @@ async function agentPackageRootUpdateTask() {
6241
6338
  return npmPrefixUpdateTask("Pi agent npm package root", installRoot, packages);
6242
6339
  }
6243
6340
 
6341
+ async function optionalFeatureInstallRootUpdateTask() {
6342
+ const configuredRoot = process.env[OPTIONAL_FEATURE_INSTALL_ROOT_ENV];
6343
+ if (!configuredRoot) return null;
6344
+ const installRoot = path.resolve(expandUserPath(configuredRoot));
6345
+ const packages = await packagesPresentInInstallPrefix(installRoot);
6346
+ return npmPrefixUpdateTask("configured optional-feature npm root", installRoot, packages);
6347
+ }
6348
+
6349
+ function activeProjectPackageRoots() {
6350
+ const roots = new Set();
6351
+ const add = (cwd) => {
6352
+ if (!cwd) return;
6353
+ roots.add(path.join(path.resolve(cwd), ".pi", "npm"));
6354
+ };
6355
+ add(options.cwd);
6356
+ for (const tab of tabs.values()) add(tab.cwd);
6357
+ for (const tab of closedRestorableTabs) add(tab.cwd);
6358
+ return [...roots].sort();
6359
+ }
6360
+
6361
+ async function projectPackageRootUpdateTasks() {
6362
+ const tasks = [];
6363
+ for (const installRoot of activeProjectPackageRoots()) {
6364
+ const packages = await packagesPresentInInstallPrefix(installRoot);
6365
+ const task = npmPrefixUpdateTask(`project Pi package root (${displayPath(path.dirname(installRoot))})`, installRoot, packages);
6366
+ if (task) tasks.push(task);
6367
+ }
6368
+ return tasks;
6369
+ }
6370
+
6244
6371
  async function npmGlobalNodeModulesRoot() {
6245
6372
  const npmCommand = npmCommandName();
6246
6373
  const result = await runCommand(npmCommand, ["root", "-g"], { timeoutMs: 5000, maxOutputLength: 8000 });
@@ -6305,8 +6432,33 @@ function uniqueUpdateTasks(tasks) {
6305
6432
  }
6306
6433
 
6307
6434
  async function resolveUpdateTasks({ all = false } = {}) {
6435
+ const piTask = await resolvePiUpdateCommand({ all });
6436
+ if (!all) return uniqueUpdateTasks([piTask]);
6437
+
6438
+ const [
6439
+ currentWebuiTask,
6440
+ agentTask,
6441
+ optionalFeatureTask,
6442
+ projectTasks,
6443
+ globalNpmTask,
6444
+ globalBunTask,
6445
+ ] = await Promise.all([
6446
+ currentWebuiPackageUpdateTask(),
6447
+ agentPackageRootUpdateTask(),
6448
+ optionalFeatureInstallRootUpdateTask(),
6449
+ projectPackageRootUpdateTasks(),
6450
+ npmGlobalPackageRootUpdateTask(),
6451
+ bunGlobalPackageRootUpdateTask(),
6452
+ ]);
6453
+
6308
6454
  return uniqueUpdateTasks([
6309
- await resolvePiUpdateCommand({ all }),
6455
+ piTask,
6456
+ currentWebuiTask,
6457
+ agentTask,
6458
+ optionalFeatureTask,
6459
+ ...projectTasks,
6460
+ globalNpmTask,
6461
+ globalBunTask,
6310
6462
  ]);
6311
6463
  }
6312
6464
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firstpick/pi-package-webui",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Pi Web UI companion package with a local browser UI CLI plus /webui-start and /webui-status commands.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/Firstp1ck/npm-packages/tree/main/pi-package-webui#readme",
@@ -53,21 +53,21 @@
53
53
  "test": "node tests/run-all.mjs"
54
54
  },
55
55
  "dependencies": {
56
- "@earendil-works/pi-coding-agent": "^0.80.2",
56
+ "@earendil-works/pi-coding-agent": "^0.80.3",
57
57
  "mermaid": "^11.15.0"
58
58
  },
59
59
  "optionalDependencies": {
60
- "@firstpick/pi-extension-btw": "^0.1.0",
61
- "@firstpick/pi-extension-git-footer-status": "^0.3.3",
60
+ "@firstpick/pi-extension-btw": "^0.1.1",
61
+ "@firstpick/pi-extension-git-footer-status": "^0.3.5",
62
62
  "@firstpick/pi-extension-release-aur": "^0.1.6",
63
63
  "@firstpick/pi-extension-release-npm": "^0.4.0",
64
64
  "@firstpick/pi-extension-safety-guard": "^0.2.3",
65
65
  "@firstpick/pi-extension-setup-skills": "^0.1.8",
66
- "@firstpick/pi-extension-stats": "^0.2.6",
67
- "@firstpick/pi-extension-todo-progress": "^0.2.5",
66
+ "@firstpick/pi-extension-stats": "^0.2.7",
67
+ "@firstpick/pi-extension-todo-progress": "^0.2.7",
68
68
  "@firstpick/pi-extension-tools": "^0.1.6",
69
- "@firstpick/pi-extension-workflows": "^0.1.0",
70
- "@firstpick/pi-package-remote-webui": "^0.1.2",
69
+ "@firstpick/pi-extension-workflows": "^0.1.1",
70
+ "@firstpick/pi-package-remote-webui": "^0.1.4",
71
71
  "@firstpick/pi-prompts-git-pr": "^0.1.2",
72
72
  "@firstpick/pi-themes-bundle": "^0.1.4"
73
73
  },