@firstpick/pi-package-webui 0.7.3 → 0.7.4

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/bin/pi-webui.mjs CHANGED
@@ -48,6 +48,16 @@ import {
48
48
  writeGitWorkflowPreferences,
49
49
  writeWebuiSettings,
50
50
  } from "../lib/git-workflow-preferences.mjs";
51
+ import {
52
+ encodeBrowserSseEvent,
53
+ isOutputModeSemanticBarrier,
54
+ negotiateOutputMode,
55
+ normalizeOutputMode,
56
+ OUTPUT_MODE_COMPACT_V1,
57
+ OUTPUT_MODE_NORMAL,
58
+ OUTPUT_MODE_PROTOCOL_VERSION,
59
+ resolveOutputModeDefault,
60
+ } from "../lib/webui-output-mode.mjs";
51
61
  import {
52
62
  evaluateDispatchTrustGuards,
53
63
  guardsForNativeCommand,
@@ -302,7 +312,13 @@ function isTruthyEnv(value) {
302
312
 
303
313
  function isSourceCheckout(root) {
304
314
  const normalized = String(root || "").replace(/\\/g, "/");
305
- return normalized.includes("/npm-packages/") && !normalized.includes("/node_modules/");
315
+ if (normalized.includes("/node_modules/")) return false;
316
+ try {
317
+ const gitMarker = statSync(path.join(root, "..", ".git"));
318
+ return gitMarker.isDirectory() || gitMarker.isFile();
319
+ } catch {
320
+ return false;
321
+ }
306
322
  }
307
323
 
308
324
  const NATIVE_SLASH_COMMANDS = nativeSlashCommandEntries(nativeParityMatrix);
@@ -365,6 +381,7 @@ Options:
365
381
  --name <name> Initial Web UI tab display name
366
382
  --remote-auth Enable startup PIN authentication for non-local clients
367
383
  --no-remote-auth Disable startup PIN authentication
384
+ --output-mode <mode> Web UI output default: normal or compact-v1
368
385
  -h, --help Show this help
369
386
  -v, --version Print version
370
387
 
@@ -392,6 +409,14 @@ function takeValue(argv, index, flag) {
392
409
  return value;
393
410
  }
394
411
 
412
+ function requiredOutputMode(value, source) {
413
+ const mode = String(value || "").trim();
414
+ if (![OUTPUT_MODE_NORMAL, OUTPUT_MODE_COMPACT_V1].includes(mode)) {
415
+ throw new Error(`${source} must be one of: ${OUTPUT_MODE_NORMAL}, ${OUTPUT_MODE_COMPACT_V1}`);
416
+ }
417
+ return mode;
418
+ }
419
+
395
420
  function parseArgs(argv) {
396
421
  const options = {
397
422
  host: process.env.PI_WEBUI_HOST || DEFAULT_HOST,
@@ -404,6 +429,8 @@ function parseArgs(argv) {
404
429
  name: undefined,
405
430
  remoteAuth: isTruthyEnv(process.env.PI_WEBUI_REMOTE_AUTH),
406
431
  remoteAuthExplicit: process.env.PI_WEBUI_REMOTE_AUTH !== undefined,
432
+ outputMode: undefined,
433
+ envOutputMode: process.env.PI_WEBUI_OUTPUT_MODE === undefined ? undefined : requiredOutputMode(process.env.PI_WEBUI_OUTPUT_MODE, "PI_WEBUI_OUTPUT_MODE"),
407
434
  piArgs: [],
408
435
  help: false,
409
436
  version: false,
@@ -458,6 +485,11 @@ function parseArgs(argv) {
458
485
  i++;
459
486
  continue;
460
487
  }
488
+ if (arg === "--output-mode") {
489
+ options.outputMode = requiredOutputMode(takeValue(argv, i, arg), "--output-mode");
490
+ i++;
491
+ continue;
492
+ }
461
493
  if (arg === "--remote-auth") {
462
494
  options.remoteAuth = true;
463
495
  options.remoteAuthExplicit = true;
@@ -1095,8 +1127,12 @@ function sendRemoteAuthRequired(req, res, url) {
1095
1127
  sendJson(res, 401, { ok: false, error: "Remote PIN required", remoteAuthRequired: true }, { "www-authenticate": "PiRemotePin" });
1096
1128
  }
1097
1129
 
1098
- function sendSse(res, event) {
1099
- res.write(`data: ${JSON.stringify(event)}\n\n`);
1130
+ function sendSse(client, event) {
1131
+ const res = client?.res || client;
1132
+ const payload = encodeBrowserSseEvent(event, { outputMode: client?.activeMode || OUTPUT_MODE_NORMAL });
1133
+ if (payload === undefined) return false;
1134
+ res.write(`data: ${payload}\n\n`);
1135
+ return true;
1100
1136
  }
1101
1137
 
1102
1138
  function rpcSuccess(command, data = {}) {
@@ -1481,8 +1517,33 @@ function statusEventSummary(event) {
1481
1517
  return summary;
1482
1518
  }
1483
1519
 
1520
+ function deltaHistorySummary(event) {
1521
+ const update = event?.assistantMessageEvent;
1522
+ if (event?.type !== "message_update" || !update || typeof update !== "object" || !["text_delta", "thinking_delta", "toolcall_delta"].includes(update.type) || typeof update.delta !== "string") return null;
1523
+ return {
1524
+ type: "message_update",
1525
+ firstTimestamp: new Date().toISOString(),
1526
+ lastTimestamp: new Date().toISOString(),
1527
+ tabId: event.tabId,
1528
+ updateType: update.type,
1529
+ contentIndex: update.contentIndex ?? event.contentIndex ?? null,
1530
+ deltaCount: 1,
1531
+ deltaChars: update.delta.length,
1532
+ deltaUtf8Bytes: Buffer.byteLength(update.delta),
1533
+ };
1534
+ }
1535
+
1484
1536
  function recordEvent(event) {
1485
- eventHistory.push(statusEventSummary(event));
1537
+ const delta = deltaHistorySummary(event);
1538
+ const previous = eventHistory.at(-1);
1539
+ if (delta && previous?.type === delta.type && previous.tabId === delta.tabId && previous.updateType === delta.updateType && previous.contentIndex === delta.contentIndex && Number.isInteger(previous.deltaCount)) {
1540
+ previous.lastTimestamp = delta.lastTimestamp;
1541
+ previous.deltaCount += delta.deltaCount;
1542
+ previous.deltaChars += delta.deltaChars;
1543
+ previous.deltaUtf8Bytes += delta.deltaUtf8Bytes;
1544
+ } else {
1545
+ eventHistory.push(delta || statusEventSummary(event));
1546
+ }
1486
1547
  if (eventHistory.length > EVENT_HISTORY_LIMIT) eventHistory.splice(0, eventHistory.length - EVENT_HISTORY_LIMIT);
1487
1548
  }
1488
1549
 
@@ -6983,7 +7044,7 @@ async function readBundledThemes() {
6983
7044
  function normalizeStaticPath(urlPath) {
6984
7045
  if (urlPath === "/") return "index.html";
6985
7046
  const name = urlPath.startsWith("/") ? urlPath.slice(1) : urlPath;
6986
- if (!["index.html", "app.js", "voice-conversation.mjs", "aur-review-payload.mjs", "guided-git-command-state.mjs", "guided-git-review-state.mjs", "styles.css", "favicon.svg", "apple-touch-icon.png", "icon-192.png", "icon-512.png", "catppuccin-mocha-background.png", "matrix-background.webp", "manifest.webmanifest", "service-worker.js"].includes(name)) return undefined;
7047
+ if (!["index.html", "app.js", "fast-output-live.mjs", "voice-conversation.mjs", "aur-review-payload.mjs", "guided-git-command-state.mjs", "guided-git-review-state.mjs", "styles.css", "favicon.svg", "apple-touch-icon.png", "icon-192.png", "icon-512.png", "catppuccin-mocha-background.png", "matrix-background.webp", "manifest.webmanifest", "service-worker.js"].includes(name)) return undefined;
6987
7048
  return name;
6988
7049
  }
6989
7050
 
@@ -7907,9 +7968,9 @@ function enforceNaturalConversationCommandAllowed(tab, command) {
7907
7968
  }
7908
7969
  }
7909
7970
 
7910
- function replayExtensionStatuses(tab, res) {
7971
+ function replayExtensionStatuses(tab, client) {
7911
7972
  for (const [statusKey, statusText] of extensionStatusMap(tab)) {
7912
- sendSse(res, {
7973
+ sendSseToClient(client, {
7913
7974
  type: "extension_ui_request",
7914
7975
  id: randomUUID(),
7915
7976
  method: "setStatus",
@@ -7924,10 +7985,10 @@ function replayExtensionStatuses(tab, res) {
7924
7985
  }
7925
7986
  }
7926
7987
 
7927
- function replayExtensionWidgets(tab, res) {
7988
+ function replayExtensionWidgets(tab, client) {
7928
7989
  const pendingExtensionUiRequestCount = pendingExtensionUiRequests(tab).length;
7929
7990
  for (const [widgetKey, request] of extensionWidgetMap(tab)) {
7930
- sendSse(res, {
7991
+ sendSseToClient(client, {
7931
7992
  ...request,
7932
7993
  type: "extension_ui_request",
7933
7994
  id: randomUUID(),
@@ -8214,10 +8275,10 @@ function clearPendingExtensionUiRequests(tab) {
8214
8275
  tab?.pendingExtensionUiRequests?.clear();
8215
8276
  }
8216
8277
 
8217
- function replayPendingExtensionUiRequests(tab, res) {
8278
+ function replayPendingExtensionUiRequests(tab, client) {
8218
8279
  const pending = pendingExtensionUiRequests(tab);
8219
8280
  for (const request of pending) {
8220
- sendSse(res, {
8281
+ sendSseToClient(client, {
8221
8282
  ...request,
8222
8283
  type: "extension_ui_request",
8223
8284
  replayed: true,
@@ -8416,7 +8477,7 @@ function attachRpcToTab(tab, rpc) {
8416
8477
  }
8417
8478
  scopedEvent = { ...scopedEvent, tabActivity: tabActivitySnapshot(tab), pendingExtensionUiRequestCount: pendingExtensionUiRequests(tab).length };
8418
8479
  recordEvent(scopedEvent);
8419
- for (const client of tab.sseClients) sendSse(client, scopedEvent);
8480
+ for (const client of tab.sseClients) sendSseToClient(client, scopedEvent);
8420
8481
  if (event?.type === "compaction_end") void flushCompactionQueue(tab, event);
8421
8482
  if (event?.type === "agent_settled") void restoreGitWorkflowGenerationProfile(tab);
8422
8483
  });
@@ -9223,7 +9284,7 @@ function rememberClosedRestorableTab(tab, state = null) {
9223
9284
 
9224
9285
  function broadcastTabEvent(tab, event) {
9225
9286
  recordEvent(event);
9226
- for (const client of tab.sseClients) sendSse(client, event);
9287
+ for (const client of tab.sseClients) sendSseToClient(client, event);
9227
9288
  }
9228
9289
 
9229
9290
  function broadcastServerEvent(event) {
@@ -9232,7 +9293,7 @@ function broadcastServerEvent(event) {
9232
9293
  for (const tab of tabs.values()) {
9233
9294
  for (const client of tab.sseClients) clients.add(client);
9234
9295
  }
9235
- for (const client of clients) sendSse(client, event);
9296
+ for (const client of clients) sendSseToClient(client, event);
9236
9297
  }
9237
9298
 
9238
9299
  const gitLiveWatcher = createGitLiveWatcher({
@@ -9306,10 +9367,7 @@ async function updateTabCwd(id, cwd) {
9306
9367
  const piCommand = await resolvePiCommand(piArgs);
9307
9368
  gitLiveWatcher.unsubscribe(tab.id);
9308
9369
  const restartingEvent = { type: "webui_tab_restarting", tabId: tab.id, tabTitle: tab.title, cwd: nextCwd, sessionFile };
9309
- recordEvent(restartingEvent);
9310
- for (const client of tab.sseClients) {
9311
- sendSse(client, restartingEvent);
9312
- }
9370
+ broadcastTabEvent(tab, restartingEvent);
9313
9371
 
9314
9372
  const oldRpc = tab.rpc;
9315
9373
  tab.rpcUnsubscribe?.();
@@ -9332,10 +9390,7 @@ async function updateTabCwd(id, cwd) {
9332
9390
  await primeTabRpc(tab).catch(() => {});
9333
9391
 
9334
9392
  const changedEvent = { type: "webui_cwd_changed", tabId: tab.id, tabTitle: tab.title, cwd: tab.cwd, pid: tab.rpc.child?.pid, sessionFile, tabActivity: tabActivitySnapshot(tab) };
9335
- recordEvent(changedEvent);
9336
- for (const client of tab.sseClients) {
9337
- sendSse(client, changedEvent);
9338
- }
9393
+ broadcastTabEvent(tab, changedEvent);
9339
9394
  return { tab, changed: true };
9340
9395
  }
9341
9396
 
@@ -9350,8 +9405,7 @@ async function restartTabRpc(tab, reason = "reload") {
9350
9405
  if (state.data?.sessionFile && !options.noSession) piArgs.push("--session", state.data.sessionFile);
9351
9406
  const piCommand = await resolvePiCommand(piArgs);
9352
9407
  const reloadingEvent = { type: "webui_tab_reloading", tabId: tab.id, tabTitle: tab.title, cwd: tab.cwd, reason, sessionFile: state.data?.sessionFile };
9353
- recordEvent(reloadingEvent);
9354
- for (const client of tab.sseClients) sendSse(client, reloadingEvent);
9408
+ broadcastTabEvent(tab, reloadingEvent);
9355
9409
 
9356
9410
  const oldRpc = tab.rpc;
9357
9411
  tab.rpcUnsubscribe?.();
@@ -9370,8 +9424,7 @@ async function restartTabRpc(tab, reason = "reload") {
9370
9424
  rpc.start();
9371
9425
 
9372
9426
  const reloadedEvent = { type: "webui_tab_reloaded", tabId: tab.id, tabTitle: tab.title, cwd: tab.cwd, pid: tab.rpc.child?.pid, reason, sessionFile: state.data?.sessionFile, tabActivity: tabActivitySnapshot(tab) };
9373
- recordEvent(reloadedEvent);
9374
- for (const client of tab.sseClients) sendSse(client, reloadedEvent);
9427
+ broadcastTabEvent(tab, reloadedEvent);
9375
9428
  return tab;
9376
9429
  }
9377
9430
 
@@ -11481,8 +11534,8 @@ async function closeTab(id) {
11481
11534
  const closingEvent = { type: "webui_tab_closing", tabId: tab.id, tabTitle: tab.title };
11482
11535
  recordEvent(closingEvent);
11483
11536
  for (const client of tab.sseClients) {
11484
- sendSse(client, closingEvent);
11485
- client.end();
11537
+ sendSseToClient(client, closingEvent);
11538
+ client.res.end();
11486
11539
  }
11487
11540
  tab.sseClients.clear();
11488
11541
  tab.rpcUnsubscribe?.();
@@ -11613,12 +11666,89 @@ async function createInitialTabs() {
11613
11666
  }
11614
11667
 
11615
11668
  const serverStartedAt = new Date().toISOString();
11616
- let persistedRemoteAuthEnabled = await readPersistedRemoteAuthEnabled();
11669
+ const persistedStartupSettings = await readWebuiSettings(undefined, { reportInvalidOutputMode: true });
11670
+ let persistedRemoteAuthEnabled = persistedStartupSettings.remoteAuthEnabled === true;
11671
+ let persistedOutputModeDefault = persistedStartupSettings.outputModeDefault;
11617
11672
  const initialTabs = await createInitialTabs();
11618
11673
  const initialTab = initialTabs[0];
11619
11674
  let currentHost = options.host;
11620
11675
  let networkRebindInProgress = false;
11621
11676
  let networkRebindTargetHost = null;
11677
+
11678
+ function resolvedOutputModeDefault() {
11679
+ return resolveOutputModeDefault({
11680
+ cliMode: options.outputMode,
11681
+ envMode: options.envOutputMode,
11682
+ persistedMode: persistedOutputModeDefault,
11683
+ });
11684
+ }
11685
+
11686
+ function outputModeMetadata() {
11687
+ const resolved = resolvedOutputModeDefault();
11688
+ return {
11689
+ persistedDefault: normalizeOutputMode(persistedOutputModeDefault),
11690
+ effectiveDefault: resolved.mode,
11691
+ source: resolved.source,
11692
+ overridden: resolved.source === "cli" || resolved.source === "env",
11693
+ };
11694
+ }
11695
+
11696
+ function tabHasActiveOutput(tab) {
11697
+ return tab?.activity?.isWorking === true || tab?.lastState?.isStreaming === true || tab?.lastState?.isCompacting === true;
11698
+ }
11699
+
11700
+ function activateOutputMode(client, activeMode, reason = "server-default-change") {
11701
+ const nextMode = normalizeOutputMode(activeMode);
11702
+ if (client.activeMode === nextMode) {
11703
+ client.pendingMode = undefined;
11704
+ return;
11705
+ }
11706
+ sendSse(client, {
11707
+ type: "webui_output_mode",
11708
+ protocolVersion: OUTPUT_MODE_PROTOCOL_VERSION,
11709
+ previousMode: client.activeMode,
11710
+ activeMode: nextMode,
11711
+ reason,
11712
+ });
11713
+ client.activeMode = nextMode;
11714
+ client.pendingMode = undefined;
11715
+ }
11716
+
11717
+ function sendSseToClient(client, event) {
11718
+ sendSse(client, event);
11719
+ if (client?.pendingMode && isOutputModeSemanticBarrier(event)) activateOutputMode(client, client.pendingMode);
11720
+ }
11721
+
11722
+ function refreshAutoOutputModes() {
11723
+ const resolved = resolvedOutputModeDefault();
11724
+ for (const tab of tabs.values()) {
11725
+ for (const client of tab.sseClients) {
11726
+ if (client.requestedMode !== "auto") continue;
11727
+ client.defaultSource = resolved.source;
11728
+ if (client.activeMode === resolved.mode) {
11729
+ client.pendingMode = undefined;
11730
+ } else if (tabHasActiveOutput(tab)) {
11731
+ client.pendingMode = resolved.mode;
11732
+ } else {
11733
+ activateOutputMode(client, resolved.mode);
11734
+ }
11735
+ }
11736
+ }
11737
+ }
11738
+
11739
+ async function saveOutputModeDefault(value) {
11740
+ let mode;
11741
+ try {
11742
+ mode = requiredOutputMode(value, "outputModeDefault");
11743
+ } catch (error) {
11744
+ throw makeHttpError(400, formatCliError(error));
11745
+ }
11746
+ const settings = await writeWebuiSettings({ outputModeDefault: mode });
11747
+ persistedOutputModeDefault = settings.outputModeDefault;
11748
+ refreshAutoOutputModes();
11749
+ return outputModeMetadata();
11750
+ }
11751
+
11622
11752
  const remoteAuth = {
11623
11753
  pin: undefined,
11624
11754
  token: undefined,
@@ -11751,8 +11881,8 @@ function closeSseClientsForRebind(nextHost) {
11751
11881
  };
11752
11882
  recordEvent(rebindEvent);
11753
11883
  for (const client of tab.sseClients) {
11754
- sendSse(client, rebindEvent);
11755
- client.end();
11884
+ sendSseToClient(client, rebindEvent);
11885
+ client.res.end();
11756
11886
  }
11757
11887
  tab.sseClients.clear();
11758
11888
  }
@@ -11768,8 +11898,8 @@ function closeSseClientsForRemoteAuthChange() {
11768
11898
  };
11769
11899
  recordEvent(authEvent);
11770
11900
  for (const client of tab.sseClients) {
11771
- sendSse(client, authEvent);
11772
- client.end();
11901
+ sendSseToClient(client, authEvent);
11902
+ client.res.end();
11773
11903
  }
11774
11904
  tab.sseClients.clear();
11775
11905
  }
@@ -11980,6 +12110,7 @@ async function webuiStatus({ detailed = false, eventLimit = 40, includeAuthPin =
11980
12110
  network,
11981
12111
  piPid: tab?.rpc.child?.pid,
11982
12112
  piRunning: !!tab?.rpc.child && tab.rpc.child.exitCode === null,
12113
+ outputMode: outputModeMetadata(),
11983
12114
  tabs: statusTabs,
11984
12115
  restorableTabs: mergeRestorableTabDescriptors(statusTabs),
11985
12116
  };
@@ -12046,6 +12177,17 @@ const server = createServer(async (req, res) => {
12046
12177
  return;
12047
12178
  }
12048
12179
 
12180
+ if (url.pathname === "/api/webui-output-mode" && req.method === "GET") {
12181
+ sendJson(res, 200, { ok: true, data: outputModeMetadata() });
12182
+ return;
12183
+ }
12184
+
12185
+ if (url.pathname === "/api/webui-output-mode" && req.method === "PUT") {
12186
+ const body = await readJsonBody(req);
12187
+ sendJson(res, 200, { ok: true, data: await saveOutputModeDefault(body.outputModeDefault) });
12188
+ return;
12189
+ }
12190
+
12049
12191
  if (url.pathname === "/api/tabs" && req.method === "GET") {
12050
12192
  sendJson(res, 200, { ok: true, data: { tabs: await listTabsWithReconciledActivity() } });
12051
12193
  return;
@@ -12096,6 +12238,20 @@ const server = createServer(async (req, res) => {
12096
12238
 
12097
12239
  if (url.pathname === "/api/events" && req.method === "GET") {
12098
12240
  const tab = getRequestedTab(req, url);
12241
+ const resolvedDefault = resolvedOutputModeDefault();
12242
+ const negotiated = negotiateOutputMode({
12243
+ requestedMode: url.searchParams.get("outputMode"),
12244
+ protocolVersion: url.searchParams.get("outputModeProtocol"),
12245
+ serverDefault: resolvedDefault.mode,
12246
+ });
12247
+ const client = {
12248
+ res,
12249
+ requestedMode: negotiated.requestedMode,
12250
+ protocolVersion: negotiated.protocolVersion,
12251
+ activeMode: negotiated.activeMode,
12252
+ pendingMode: undefined,
12253
+ defaultSource: resolvedDefault.source,
12254
+ };
12099
12255
  res.writeHead(200, {
12100
12256
  "content-type": "text/event-stream; charset=utf-8",
12101
12257
  "cache-control": "no-cache, no-transform",
@@ -12103,13 +12259,20 @@ const server = createServer(async (req, res) => {
12103
12259
  "x-content-type-options": "nosniff",
12104
12260
  });
12105
12261
  res.write(": connected\n\n");
12106
- tab.sseClients.add(res);
12107
- sendSse(res, {
12262
+ tab.sseClients.add(client);
12263
+ sendSseToClient(client, {
12108
12264
  type: "webui_connected",
12109
12265
  version: packageJson.version,
12110
12266
  piVersion: String(piPackageJson.version || ""),
12111
12267
  webuiDev: webuiDevServer,
12112
12268
  webuiMode: webuiDevServer ? "dev" : "production",
12269
+ outputMode: {
12270
+ protocolVersion: negotiated.protocolVersion,
12271
+ requestedMode: negotiated.requestedMode,
12272
+ activeMode: negotiated.activeMode,
12273
+ serverDefault: resolvedDefault.mode,
12274
+ serverDefaultSource: resolvedDefault.source,
12275
+ },
12113
12276
  tabId: tab.id,
12114
12277
  tabTitle: tab.title,
12115
12278
  pid: tab.rpc.child?.pid,
@@ -12119,13 +12282,13 @@ const server = createServer(async (req, res) => {
12119
12282
  pendingExtensionUiRequestCount: pendingExtensionUiRequests(tab).length,
12120
12283
  activeRun: publicAppRunnerState(tab.appRunner),
12121
12284
  });
12122
- replayExtensionStatuses(tab, res);
12123
- replayExtensionWidgets(tab, res);
12124
- replayPendingExtensionUiRequests(tab, res);
12285
+ replayExtensionStatuses(tab, client);
12286
+ replayExtensionWidgets(tab, client);
12287
+ replayPendingExtensionUiRequests(tab, client);
12125
12288
  const keepAlive = setInterval(() => res.write(": keepalive\n\n"), 15000);
12126
12289
  req.on("close", () => {
12127
12290
  clearInterval(keepAlive);
12128
- tab.sseClients.delete(res);
12291
+ tab.sseClients.delete(client);
12129
12292
  });
12130
12293
  return;
12131
12294
  }
@@ -12142,6 +12305,7 @@ const server = createServer(async (req, res) => {
12142
12305
  piPid: status.piPid,
12143
12306
  piRunning: status.piRunning,
12144
12307
  cwd: status.cwd,
12308
+ outputMode: status.outputMode,
12145
12309
  network: status.network,
12146
12310
  tabs: status.tabs,
12147
12311
  restorableTabs: status.restorableTabs,
package/index.ts CHANGED
@@ -33,6 +33,7 @@ type StartWebuiOptions = WebuiAddress & {
33
33
  open: boolean;
34
34
  noSession: boolean;
35
35
  remoteAuth: boolean;
36
+ outputMode?: "normal" | "compact-v1";
36
37
  name?: string;
37
38
  piArgs: string[];
38
39
  };
@@ -87,6 +88,13 @@ function parseStartWebuiArgs(args: string): StartWebuiOptions {
87
88
  options.noSession = true;
88
89
  continue;
89
90
  }
91
+ if (token === "--output-mode") {
92
+ const outputMode = takeValue(tokens, i, token);
93
+ if (outputMode !== "normal" && outputMode !== "compact-v1") throw new Error("--output-mode must be normal or compact-v1");
94
+ options.outputMode = outputMode;
95
+ i++;
96
+ continue;
97
+ }
90
98
  if (token === "--remote-auth") {
91
99
  options.remoteAuth = true;
92
100
  continue;
@@ -450,6 +458,7 @@ async function startWebui(options: StartWebuiOptions, ctx: ExtensionCommandConte
450
458
  const args = [webuiBin, "--host", options.host, "--port", String(options.port), "--cwd", ctx.cwd];
451
459
  if (options.noSession) args.push("--no-session");
452
460
  if (options.remoteAuth) args.push("--remote-auth");
461
+ if (options.outputMode) args.push("--output-mode", options.outputMode);
453
462
  if (options.name) args.push("--name", options.name);
454
463
  if (options.piArgs.length > 0) args.push("--", ...options.piArgs);
455
464
 
@@ -696,7 +705,7 @@ function formatWebuiStatus(result: WebuiStatusFetchResult, requestedDetailed: bo
696
705
 
697
706
  function usage(): string {
698
707
  return [
699
- "Usage: /webui-start [port] [--port N] [--no-open] [--no-session] [--remote-auth] [--name NAME] [-- --model provider/model]",
708
+ "Usage: /webui-start [port] [--port N] [--no-open] [--no-session] [--remote-auth] [--output-mode normal|compact-v1] [--name NAME] [-- --model provider/model]",
700
709
  "Starts the Pi Web UI companion server for the current cwd, prints the localhost URL, and opens it in your default browser.",
701
710
  ].join("\n");
702
711
  }
@@ -1,6 +1,7 @@
1
1
  import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
2
2
  import { homedir } from "node:os";
3
3
  import path from "node:path";
4
+ import { normalizeOutputMode, OUTPUT_MODE_NORMAL } from "./webui-output-mode.mjs";
4
5
 
5
6
  export const GIT_WORKFLOW_SETUP_VERSION = 1;
6
7
  export const GIT_WORKFLOW_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
@@ -22,7 +23,7 @@ export function supportedGitWorkflowThinkingLevels(model) {
22
23
  });
23
24
  }
24
25
 
25
- const WEBUI_SETTINGS_VERSION = 3;
26
+ const WEBUI_SETTINGS_VERSION = 4;
26
27
  const WEBUI_SETTINGS_FILE_ENV = "PI_WEBUI_SETTINGS_FILE";
27
28
 
28
29
  function cleanBoundedString(value, maxLength = 512) {
@@ -139,14 +140,20 @@ export function normalizeWebuiSettings(value) {
139
140
  return {
140
141
  version: WEBUI_SETTINGS_VERSION,
141
142
  remoteAuthEnabled: value?.remoteAuthEnabled === true,
143
+ outputModeDefault: normalizeOutputMode(value?.outputModeDefault, OUTPUT_MODE_NORMAL),
142
144
  gitWorkflow: normalizeGitWorkflowPreferences(value?.gitWorkflow),
143
145
  resourceDefaults: normalizeResourceDefaults(value?.resourceDefaults),
144
146
  };
145
147
  }
146
148
 
147
- export async function readWebuiSettings(storageFile = webuiSettingsFile()) {
149
+ export async function readWebuiSettings(storageFile = webuiSettingsFile(), { reportInvalidOutputMode = false } = {}) {
148
150
  try {
149
- return normalizeWebuiSettings(JSON.parse(await readFile(storageFile, "utf8")));
151
+ const raw = JSON.parse(await readFile(storageFile, "utf8"));
152
+ const normalized = normalizeWebuiSettings(raw);
153
+ if (reportInvalidOutputMode && raw?.outputModeDefault !== undefined && normalized.outputModeDefault !== raw.outputModeDefault) {
154
+ console.warn(`Invalid persisted Web UI output mode ${JSON.stringify(raw.outputModeDefault)} in ${storageFile}; using ${OUTPUT_MODE_NORMAL}.`);
155
+ }
156
+ return normalized;
150
157
  } catch (error) {
151
158
  if (error?.code === "ENOENT") return normalizeWebuiSettings({});
152
159
  throw new Error(`Cannot read Pi Web UI settings at ${storageFile}: ${error instanceof Error ? error.message : String(error)}`);
@@ -0,0 +1,97 @@
1
+ export const OUTPUT_MODE_NORMAL = "normal";
2
+ export const OUTPUT_MODE_COMPACT_V1 = "compact-v1";
3
+ export const OUTPUT_MODE_PROTOCOL_VERSION = 1;
4
+
5
+ const OUTPUT_MODES = new Set([OUTPUT_MODE_NORMAL, OUTPUT_MODE_COMPACT_V1]);
6
+ const COMPACT_MESSAGE_UPDATE_TYPES = new Set(["text_delta", "thinking_delta", "toolcall_delta"]);
7
+ const COMPACT_SELF_CONTAINED_END_TYPES = new Set(["text_end", "thinking_end", "toolcall_end", "tool_call_end"]);
8
+ const SEMANTIC_BARRIER_TYPES = new Set([
9
+ "message_end",
10
+ "tool_execution_end",
11
+ "agent_end",
12
+ "agent_settled",
13
+ "compaction_end",
14
+ "pi_process_exit",
15
+ "pi_process_error",
16
+ ]);
17
+
18
+ function cleanOutputMode(value) {
19
+ return typeof value === "string" ? value.trim() : "";
20
+ }
21
+
22
+ function hasProtocolVersionOne(value) {
23
+ return value === OUTPUT_MODE_PROTOCOL_VERSION || value === String(OUTPUT_MODE_PROTOCOL_VERSION);
24
+ }
25
+
26
+ function directSelfContainedEnd(update) {
27
+ if (!COMPACT_SELF_CONTAINED_END_TYPES.has(update?.type)) return false;
28
+ return Object.prototype.hasOwnProperty.call(update, "content")
29
+ || Object.prototype.hasOwnProperty.call(update, "toolCall")
30
+ || Object.prototype.hasOwnProperty.call(update, "error")
31
+ || Object.prototype.hasOwnProperty.call(update, "isError");
32
+ }
33
+
34
+ function compactAssistantMessageUpdate(event) {
35
+ if (!event || typeof event !== "object" || event.type !== "message_update") return null;
36
+ const update = event.assistantMessageEvent;
37
+ if (!update || typeof update !== "object" || Array.isArray(update)) return null;
38
+
39
+ const hasDirectDelta = COMPACT_MESSAGE_UPDATE_TYPES.has(update.type) && typeof update.delta === "string";
40
+ if (!hasDirectDelta && !directSelfContainedEnd(update)) return null;
41
+
42
+ const compactUpdate = { ...update };
43
+ delete compactUpdate.partial;
44
+ const compactEvent = { ...event, assistantMessageEvent: compactUpdate };
45
+ delete compactEvent.message;
46
+ return compactEvent;
47
+ }
48
+
49
+ export function normalizeOutputMode(value, fallback = OUTPUT_MODE_NORMAL) {
50
+ const normalizedFallback = OUTPUT_MODES.has(cleanOutputMode(fallback)) ? cleanOutputMode(fallback) : OUTPUT_MODE_NORMAL;
51
+ const normalizedValue = cleanOutputMode(value);
52
+ return OUTPUT_MODES.has(normalizedValue) ? normalizedValue : normalizedFallback;
53
+ }
54
+
55
+ export function resolveOutputModeDefault({ cliMode, envMode, persistedMode } = {}) {
56
+ const cli = cleanOutputMode(cliMode);
57
+ if (OUTPUT_MODES.has(cli)) return { mode: cli, source: "cli" };
58
+ const env = cleanOutputMode(envMode);
59
+ if (OUTPUT_MODES.has(env)) return { mode: env, source: "env" };
60
+ const persisted = cleanOutputMode(persistedMode);
61
+ if (OUTPUT_MODES.has(persisted)) return { mode: persisted, source: "persisted" };
62
+ return { mode: OUTPUT_MODE_NORMAL, source: "normal" };
63
+ }
64
+
65
+ export function negotiateOutputMode({ requestedMode, protocolVersion, serverDefault } = {}) {
66
+ const protocolAccepted = hasProtocolVersionOne(protocolVersion);
67
+ const requested = cleanOutputMode(requestedMode);
68
+ const validRequest = protocolAccepted && ["auto", OUTPUT_MODE_NORMAL, OUTPUT_MODE_COMPACT_V1].includes(requested);
69
+ if (!validRequest) {
70
+ return {
71
+ requestedMode: OUTPUT_MODE_NORMAL,
72
+ protocolVersion: 0,
73
+ activeMode: OUTPUT_MODE_NORMAL,
74
+ };
75
+ }
76
+
77
+ return {
78
+ requestedMode: requested,
79
+ protocolVersion: OUTPUT_MODE_PROTOCOL_VERSION,
80
+ activeMode: requested === "auto" ? normalizeOutputMode(serverDefault) : requested,
81
+ };
82
+ }
83
+
84
+ export function browserOutputEvent(event, { outputMode = OUTPUT_MODE_NORMAL } = {}) {
85
+ if (normalizeOutputMode(outputMode) !== OUTPUT_MODE_COMPACT_V1) return event;
86
+ if (event?.type === "tool_execution_update") return undefined;
87
+ return compactAssistantMessageUpdate(event) || event;
88
+ }
89
+
90
+ export function encodeBrowserSseEvent(event, { outputMode = OUTPUT_MODE_NORMAL } = {}) {
91
+ const browserEvent = browserOutputEvent(event, { outputMode });
92
+ return browserEvent === undefined ? undefined : JSON.stringify(browserEvent);
93
+ }
94
+
95
+ export function isOutputModeSemanticBarrier(event) {
96
+ return SEMANTIC_BARRIER_TYPES.has(event?.type);
97
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@firstpick/pi-package-webui",
3
- "version": "0.7.3",
3
+ "version": "0.7.4",
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
- "homepage": "https://github.com/Firstp1ck/npm-packages/tree/main/pi-package-webui#readme",
6
+ "homepage": "https://github.com/Firstp1ck/pi-coding-agent-forge/tree/main/pi-package-webui#readme",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/Firstp1ck/npm-packages.git",
9
+ "url": "git+https://github.com/Firstp1ck/pi-coding-agent-forge.git",
10
10
  "directory": "pi-package-webui"
11
11
  },
12
12
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  "extension"
21
21
  ],
22
22
  "pi": {
23
- "image": "https://raw.githubusercontent.com/Firstp1ck/npm-packages/main/pi-package-webui/images/Webui_MainWindow_v0.4.8.png",
23
+ "image": "https://raw.githubusercontent.com/Firstp1ck/pi-coding-agent-forge/main/pi-package-webui/images/Webui_MainWindow_v0.4.8.png",
24
24
  "extensions": [
25
25
  "./index.ts",
26
26
  "node_modules/@firstpick/pi-extension-bang-command-autocomplete/index.ts",
@@ -51,7 +51,7 @@
51
51
  "pi-webui": "./bin/pi-webui.mjs"
52
52
  },
53
53
  "scripts": {
54
- "check": "node --check public/app.js && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check bin/pi-webui.mjs && node --check webui-rpc-helper.mjs && node --check lib/git-live-watcher.mjs && node --check lib/git-message-artifacts.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
54
+ "check": "node --check public/app.js && node --check public/fast-output-live.mjs && node --check public/voice-conversation.mjs && node --check public/aur-review-payload.mjs && node --check public/guided-git-command-state.mjs && node --check public/guided-git-review-state.mjs && node --check bin/pi-webui.mjs && node --check webui-rpc-helper.mjs && node --check lib/git-live-watcher.mjs && node --check lib/git-message-artifacts.mjs && node --check lib/trust-boundaries.mjs && node --check lib/native-command-adapter.mjs && node --check lib/session-actions.mjs && node --check lib/auth-actions.mjs && node --check lib/temp-artifacts.mjs && node tests/run-all.mjs",
55
55
  "test": "node tests/run-all.mjs"
56
56
  },
57
57
  "dependencies": {