@firstpick/pi-package-webui 0.9.1 → 0.9.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.
Files changed (70) hide show
  1. package/README.md +21 -5
  2. package/bin/pi-webui-launcher.mjs +23 -12
  3. package/bin/pi-webui.mjs +479 -60
  4. package/lib/agent-run-adapters.mjs +500 -0
  5. package/lib/agent-run-protocol.mjs +262 -0
  6. package/lib/agent-run-registry.mjs +339 -0
  7. package/lib/git-workflow-preferences.mjs +11 -4
  8. package/lib/trust-boundaries.mjs +2 -0
  9. package/lib/ui-layout-settings.mjs +172 -28
  10. package/lib/update/package-layout.mjs +50 -0
  11. package/lib/update/plan.mjs +11 -0
  12. package/package.json +1 -1
  13. package/public/app.js +1261 -314
  14. package/public/index.html +113 -68
  15. package/public/service-worker.js +1 -1
  16. package/public/styles.css +371 -93
  17. package/tests/agent-run-adapters.test.mjs +217 -0
  18. package/tests/agent-run-launcher.test.mjs +41 -0
  19. package/tests/agent-run-protocol.test.mjs +82 -0
  20. package/tests/agent-run-registry.test.mjs +102 -0
  21. package/tests/boot-failure-diagnostics.test.mjs +3 -3
  22. package/tests/browser/control-deck-side-panels.spec.mjs +354 -0
  23. package/tests/browser/controls-layout.spec.mjs +122 -0
  24. package/tests/browser/file-tree-git-ignored.spec.mjs +113 -0
  25. package/tests/browser/interaction-continuity.spec.mjs +127 -0
  26. package/tests/browser/mobile-foundation.spec.mjs +26 -0
  27. package/tests/browser/model-search-focus.spec.mjs +96 -0
  28. package/tests/browser/optimistic-prompt.spec.mjs +22 -0
  29. package/tests/browser/persistent-ui-layout.spec.mjs +224 -66
  30. package/tests/browser/subagent-observability.spec.mjs +87 -0
  31. package/tests/codex-fast-mode-static.test.mjs +2 -2
  32. package/tests/component-update-api-static.test.mjs +2 -1
  33. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  34. package/tests/control-deck-component-updates-static.test.mjs +2 -0
  35. package/tests/control-deck-side-panels-static.test.mjs +68 -0
  36. package/tests/controls-layout-static.test.mjs +22 -0
  37. package/tests/fast-mode-client-static.test.mjs +1 -1
  38. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  39. package/tests/file-tree-git-ignored-static.test.mjs +152 -0
  40. package/tests/file-tree-search-layout-static.test.mjs +2 -1
  41. package/tests/fixtures/fake-pi.mjs +43 -7
  42. package/tests/git-workflow-preferences.test.mjs +55 -6
  43. package/tests/http-endpoints-harness.test.mjs +173 -14
  44. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  45. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  46. package/tests/mobile-foundation-static.test.mjs +3 -3
  47. package/tests/mobile-phone-experience-static.test.mjs +1 -1
  48. package/tests/mobile-static.test.mjs +13 -3
  49. package/tests/open-issue-wizard-static.test.mjs +2 -2
  50. package/tests/persistent-ui-layout-static.test.mjs +13 -13
  51. package/tests/questionnaire-dialog.test.mjs +3 -3
  52. package/tests/remote-auth-settings-harness.test.mjs +1 -1
  53. package/tests/session-sampling-ui-static.test.mjs +3 -3
  54. package/tests/side-panel-context-menu-static.test.mjs +1 -1
  55. package/tests/side-panel-resize-static.test.mjs +26 -16
  56. package/tests/side-panel-section-height-removal-static.test.mjs +4 -4
  57. package/tests/side-panel-section-reorder-static.test.mjs +16 -70
  58. package/tests/subagent-gate-visibility.test.mjs +2 -1
  59. package/tests/subagent-launch-slots.test.mjs +1 -1
  60. package/tests/subagent-observability-static.test.mjs +32 -0
  61. package/tests/subagent-reliability-integration.test.mjs +161 -0
  62. package/tests/subagents-helper.test.mjs +344 -4
  63. package/tests/terminal-tabs-resize-static.test.mjs +35 -0
  64. package/tests/theme-customizer-static.test.mjs +1 -1
  65. package/tests/ui-layout-settings.test.mjs +104 -32
  66. package/tests/update-api-harness.test.mjs +24 -10
  67. package/tests/update-package-layout.test.mjs +38 -0
  68. package/tests/update-plan.test.mjs +11 -1
  69. package/tests/webui-settings-locking.test.mjs +33 -3
  70. package/webui-rpc-helper.mjs +417 -28
@@ -367,6 +367,133 @@ test("same-context app-runner refresh preserves directional selection, control s
367
367
  await expect.poll(async () => (await tabIds(page)).length).toBe(1);
368
368
  });
369
369
 
370
+ test("unchanged background-tab polling keeps the followed transcript and terminal controls stable", async ({ page }) => {
371
+ await page.setViewportSize({ width: 1280, height: 800 });
372
+ await page.goto(baseURL);
373
+ const foregroundTabId = await activeTabId(page) || (await tabIds(page))[0];
374
+ const created = await api(page, "/api/tabs", { method: "POST", data: {} });
375
+ const backgroundTabId = created.data?.tab?.id;
376
+ assert.ok(backgroundTabId && backgroundTabId !== foregroundTabId, "background polling fixture requires a second terminal tab");
377
+
378
+ await page.reload();
379
+ await expect.poll(() => activeTabId(page)).toBe(foregroundTabId);
380
+ await expect(page.locator(`[data-tab-id="${backgroundTabId}"] .terminal-tab-button`)).toBeVisible();
381
+ await page.locator(`[data-tab-id="${backgroundTabId}"] .terminal-tab-button`).click();
382
+ await startContinuityRunner(page);
383
+ await page.locator(`[data-tab-id="${foregroundTabId}"] .terminal-tab-button`).click();
384
+ await expect.poll(() => activeTabId(page)).toBe(foregroundTabId);
385
+
386
+ // Let the first poll observe the background runner. Subsequent identical
387
+ // snapshots must not rebuild the terminal strip or disturb chat follow.
388
+ await page.waitForTimeout(1700);
389
+ const foregroundButton = await page.locator(`[data-tab-id="${foregroundTabId}"] .terminal-tab-button`).elementHandle();
390
+ assert.ok(foregroundButton, "foreground terminal control should be mounted before stability sampling");
391
+ const movement = await page.locator("#chat").evaluate(async (chat) => {
392
+ const spacer = document.createElement("div");
393
+ spacer.dataset.pollingContinuityFixture = "true";
394
+ spacer.style.height = "3000px";
395
+ chat.append(spacer);
396
+ chat.scrollTop = chat.scrollHeight;
397
+ const positions = [];
398
+ const started = performance.now();
399
+ while (performance.now() - started < 1800) {
400
+ positions.push(chat.scrollTop);
401
+ await new Promise((resolve) => requestAnimationFrame(resolve));
402
+ }
403
+ spacer.remove();
404
+ return Math.max(...positions) - Math.min(...positions);
405
+ });
406
+ assert.equal(await foregroundButton.evaluate((node) => node.isConnected), true, "an unchanged background-tab poll should preserve the existing foreground terminal control");
407
+ expect(movement).toBeLessThanOrEqual(1.5);
408
+
409
+ await api(page, `/api/tabs/${encodeURIComponent(backgroundTabId)}`, { method: "DELETE" });
410
+ await expect.poll(async () => (await tabIds(page)).length).toBe(1);
411
+ });
412
+
413
+ test("focus reconciliation and terminal switching keep the running status geometry stable", async ({ page }) => {
414
+ await page.setViewportSize({ width: 1280, height: 800 });
415
+ await page.goto(baseURL);
416
+ const foregroundTabId = await activeTabId(page) || (await tabIds(page))[0];
417
+ const created = await api(page, "/api/tabs", { method: "POST", data: {} });
418
+ const backgroundTabId = created.data?.tab?.id;
419
+ assert.ok(backgroundTabId && backgroundTabId !== foregroundTabId, "focus continuity requires a second terminal tab");
420
+ await page.reload();
421
+ await expect.poll(() => activeTabId(page)).toBe(foregroundTabId);
422
+ await expect(page.locator(`[data-tab-id="${backgroundTabId}"] .terminal-tab-button`)).toBeVisible();
423
+
424
+ await triggerDelayedStream(page, foregroundTabId);
425
+ await waitForFixtureSettlement(page, foregroundTabId);
426
+ await page.waitForTimeout(1500);
427
+ const runIndicator = page.locator("#runIndicatorHost .runIndicator");
428
+ await expect(runIndicator).toBeHidden();
429
+
430
+ const focusMovement = await page.locator("#chat").evaluate(async (chat) => {
431
+ chat.style.paddingBottom = "3000px";
432
+ chat.scrollTop = chat.scrollHeight;
433
+ await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
434
+ const sticky = document.querySelector("#stickyUserPromptButton");
435
+ window.dispatchEvent(new FocusEvent("focus"));
436
+ await new Promise((resolve) => setTimeout(resolve, 800));
437
+ const stickyChildren = [...sticky.children];
438
+ const samples = [];
439
+ window.dispatchEvent(new FocusEvent("focus"));
440
+ const started = performance.now();
441
+ while (performance.now() - started < 800) {
442
+ samples.push({
443
+ gap: chat.scrollHeight - chat.clientHeight - chat.scrollTop,
444
+ stickyStable: stickyChildren.every((node, index) => node === sticky.children[index] && node.isConnected),
445
+ });
446
+ await new Promise((resolve) => requestAnimationFrame(resolve));
447
+ }
448
+ chat.style.removeProperty("padding-bottom");
449
+ const gaps = samples.map((sample) => sample.gap);
450
+ return {
451
+ gapDrift: Math.max(...gaps) - Math.min(...gaps),
452
+ stickyStable: samples.every((sample) => sample.stickyStable),
453
+ };
454
+ });
455
+ expect(focusMovement.gapDrift).toBeLessThanOrEqual(1.5);
456
+ assert.equal(focusMovement.stickyStable, true, "focus reconciliation should preserve unchanged sticky-prompt children");
457
+
458
+ await triggerDelayedStream(page, foregroundTabId);
459
+ await expect(runIndicator).toBeVisible();
460
+ await page.locator(`[data-tab-id="${backgroundTabId}"] .terminal-tab-button`).click();
461
+ await expect.poll(() => activeTabId(page)).toBe(backgroundTabId);
462
+ await page.locator(`[data-tab-id="${foregroundTabId}"] .terminal-tab-button`).click();
463
+ const switchMovement = await page.evaluate(async () => {
464
+ const samples = [];
465
+ const started = performance.now();
466
+ while (performance.now() - started < 900) {
467
+ const indicator = document.querySelector("#runIndicatorHost .runIndicator");
468
+ samples.push({
469
+ connected: indicator?.isConnected === true,
470
+ indicatorTop: indicator?.getBoundingClientRect().top ?? null,
471
+ composerHeight: document.querySelector("#composer")?.getBoundingClientRect().height ?? null,
472
+ contextHeight: document.querySelector("#contextMeterBar")?.getBoundingClientRect().height ?? null,
473
+ });
474
+ await new Promise((resolve) => requestAnimationFrame(resolve));
475
+ }
476
+ const visibleSamples = samples.filter((sample) => sample.connected);
477
+ const range = (key) => {
478
+ const values = visibleSamples.map((sample) => sample[key]).filter(Number.isFinite);
479
+ return Math.max(...values) - Math.min(...values);
480
+ };
481
+ return {
482
+ observed: visibleSamples.length >= 5,
483
+ indicatorTop: range("indicatorTop"),
484
+ composerHeight: range("composerHeight"),
485
+ contextHeight: range("contextHeight"),
486
+ };
487
+ });
488
+ assert.equal(switchMovement.observed, true, "the running status should become visible again during the terminal switch");
489
+ expect(switchMovement.indicatorTop).toBeLessThanOrEqual(1.5);
490
+ expect(switchMovement.composerHeight).toBeLessThanOrEqual(1.5);
491
+ expect(switchMovement.contextHeight).toBeLessThanOrEqual(1.5);
492
+
493
+ await api(page, `/api/tabs/${encodeURIComponent(backgroundTabId)}`, { method: "DELETE" });
494
+ await expect.poll(async () => (await tabIds(page)).length).toBe(1);
495
+ });
496
+
370
497
  test("main output text selection survives streaming-tail and settlement rerenders", async ({ page }) => {
371
498
  await page.setViewportSize({ width: 1280, height: 800 });
372
499
  await page.goto(baseURL);
@@ -44,6 +44,7 @@ test.beforeAll(async () => {
44
44
  env: {
45
45
  ...process.env,
46
46
  PI_WEBUI_RPC_SUPERVISOR: "0",
47
+ FAKE_PI_CONTINUITY_MODE: "1",
47
48
  PI_CODING_AGENT_DIR: join(tempRoot, "agent"),
48
49
  PI_WEBUI_SETTINGS_FILE: join(tempRoot, "settings.json"),
49
50
  },
@@ -538,6 +539,31 @@ test("phone v2 destinations, canonical actions, history, and presentation remain
538
539
  await phoneContext.close();
539
540
  });
540
541
 
542
+ test("mobile model search retains focus while agent output streams", async ({ browser }) => {
543
+ const context = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true });
544
+ const page = await context.newPage();
545
+ await page.goto(`${baseURL}/?mobileShell=v2`);
546
+ await page.locator("#updateNotification").evaluate((notification) => { notification.hidden = true; notification.classList.remove("show"); });
547
+
548
+ await page.locator("#mobileMoreButton").click();
549
+ await page.getByRole("button", { name: "Settings" }).click();
550
+ await page.locator("#modelControlLabel").click();
551
+ const modelSearch = page.locator("#modelSearchInput");
552
+ await expect(modelSearch).toBeVisible();
553
+ await modelSearch.fill("gpt");
554
+
555
+ const tabsPayload = await (await page.request.get(`${baseURL}/api/tabs`)).json();
556
+ const streamingTabId = tabsPayload.data.activeTabId || tabsPayload.data.tabs[0].id;
557
+ const streamResponse = await page.request.post(`${baseURL}/api/prompt?tab=${encodeURIComponent(streamingTabId)}`, {
558
+ data: { message: "fixture continuity delayed stream", requestId: `model-search-focus-${Date.now()}` },
559
+ });
560
+ assert.equal(streamResponse.ok(), true);
561
+ await expect(page.locator(".message.assistant.streaming .streaming-markdown").last()).toContainText("continuity stream");
562
+ await expect(modelSearch).toBeFocused();
563
+ await expect(modelSearch).toHaveValue("gpt");
564
+ await context.close();
565
+ });
566
+
541
567
  test("mobile continuity preserves drafts, restores metadata honestly, and retries only on command", async ({ browser }) => {
542
568
  const context = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true });
543
569
  const page = await context.newPage();
@@ -0,0 +1,96 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawn } from "node:child_process";
3
+ import { createServer } from "node:net";
4
+ import { mkdtemp, rm } from "node:fs/promises";
5
+ import { tmpdir } from "node:os";
6
+ import { dirname, join } from "node:path";
7
+ import { setTimeout as delay } from "node:timers/promises";
8
+ import { fileURLToPath } from "node:url";
9
+ import { expect, test } from "@playwright/test";
10
+
11
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
12
+ const serverScript = join(root, "bin", "pi-webui.mjs");
13
+ const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
14
+
15
+ async function freePort() {
16
+ const server = createServer();
17
+ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
18
+ const { port } = server.address();
19
+ await new Promise((resolve) => server.close(resolve));
20
+ return port;
21
+ }
22
+
23
+ let child;
24
+ let baseURL;
25
+ let tempRoot;
26
+ let output = "";
27
+
28
+ test.beforeAll(async () => {
29
+ const port = await freePort();
30
+ tempRoot = await mkdtemp(join(tmpdir(), "pi-webui-model-search-focus-"));
31
+ baseURL = `http://127.0.0.1:${port}`;
32
+ child = spawn(process.execPath, [serverScript, "--cwd", tempRoot, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
33
+ stdio: ["ignore", "pipe", "pipe"],
34
+ env: {
35
+ ...process.env,
36
+ PI_WEBUI_RPC_SUPERVISOR: "0",
37
+ FAKE_PI_CONTINUITY_MODE: "1",
38
+ PI_CODING_AGENT_DIR: join(tempRoot, "agent"),
39
+ PI_WEBUI_SETTINGS_FILE: join(tempRoot, "settings.json"),
40
+ },
41
+ });
42
+ child.stdout.on("data", (chunk) => { output += String(chunk); });
43
+ child.stderr.on("data", (chunk) => { output += String(chunk); });
44
+ for (let attempt = 0; attempt < 80; attempt += 1) {
45
+ if (child.exitCode !== null) break;
46
+ try {
47
+ const response = await fetch(`${baseURL}/api/health`, { signal: AbortSignal.timeout(500) });
48
+ if (response.ok) return;
49
+ } catch {
50
+ // Wait for the local server and fake Pi fixture.
51
+ }
52
+ await delay(100);
53
+ }
54
+ throw new Error(`Pi Web UI did not start:\n${output}`);
55
+ });
56
+
57
+ test.afterAll(async () => {
58
+ child?.kill("SIGTERM");
59
+ if (child) await new Promise((resolve) => child.once("exit", resolve));
60
+ await rm(tempRoot, { recursive: true, force: true });
61
+ });
62
+
63
+ test("desktop model search retains focus while agent output streams", async ({ page }) => {
64
+ await page.setViewportSize({ width: 1440, height: 900 });
65
+ await page.goto(baseURL);
66
+ await page.locator("#updateNotification").evaluate((node) => { node.hidden = true; node.classList.remove("show"); });
67
+
68
+ const sidePanel = page.locator("#sidePanel");
69
+ if (!(await sidePanel.isVisible())) await page.locator("#sidePanelExpandButton").click();
70
+ const controlsToggle = page.locator('[data-side-panel-section-toggle="controls"]');
71
+ if (await controlsToggle.getAttribute("aria-expanded") !== "true") await controlsToggle.click();
72
+ await expect(page.locator("#sidePanelSectionControls")).toBeVisible();
73
+
74
+ await page.locator(".control-row-label:has(#modelControlLabel)").click();
75
+ const modelSearch = page.locator("#modelSearchInput");
76
+ await expect(modelSearch).toBeVisible();
77
+ await modelSearch.fill("claude");
78
+ await expect(modelSearch).toBeFocused();
79
+
80
+ const tabsPayload = await (await page.request.get(`${baseURL}/api/tabs`)).json();
81
+ const tabId = tabsPayload.data.activeTabId || tabsPayload.data.tabs[0].id;
82
+ const response = await page.request.post(`${baseURL}/api/prompt?tab=${encodeURIComponent(tabId)}`, {
83
+ data: { message: "fixture continuity delayed stream", requestId: `desktop-focus-${Date.now()}` },
84
+ });
85
+ assert.equal(response.ok(), true);
86
+
87
+ await expect(page.locator(".message.assistant.streaming .streaming-markdown").last()).toContainText("continuity stream");
88
+ await expect(modelSearch).toBeFocused();
89
+ await expect(modelSearch).toHaveValue("claude");
90
+ await expect.poll(async () => {
91
+ const state = await (await page.request.get(`${baseURL}/api/state?tab=${encodeURIComponent(tabId)}`)).json();
92
+ return state.data?.isStreaming === false;
93
+ }, { timeout: 15_000 }).toBe(true);
94
+ await expect(modelSearch).toBeFocused();
95
+ await expect(modelSearch).toHaveValue("claude");
96
+ });
@@ -120,6 +120,28 @@ test("run indicator remains visible and stable on mobile until delayed agent sta
120
120
  await expect(page.locator("#chat .message.assistant").last()).toContainText("continuity stream complete");
121
121
  });
122
122
 
123
+ test("run indicator keeps one-line geometry across changing activity text", async ({ page }) => {
124
+ await page.setViewportSize({ width: 760, height: 844 });
125
+ await page.goto(baseURL);
126
+ await page.locator("#promptInput").fill("fixture continuity delayed start");
127
+ await page.locator("#sendButton").click();
128
+
129
+ const runIndicator = page.locator("#runIndicatorHost .runIndicator");
130
+ await expect(runIndicator).toBeVisible();
131
+ const geometry = await runIndicator.evaluate((node) => {
132
+ const meta = node.querySelector(".run-indicator-meta");
133
+ const before = node.getBoundingClientRect();
134
+ meta.textContent = "Running tool: subagent_wait with a deliberately long activity description that must not wrap or resize the running status card · run time 1m 00s";
135
+ const after = node.getBoundingClientRect();
136
+ return {
137
+ heightDrift: Math.abs(after.height - before.height),
138
+ topDrift: Math.abs(after.top - before.top),
139
+ };
140
+ });
141
+ expect(geometry.heightDrift).toBeLessThanOrEqual(1.5);
142
+ expect(geometry.topDrift).toBeLessThanOrEqual(1.5);
143
+ });
144
+
123
145
  test("confirmed streaming replaces routing status before delayed activity events", async ({ page }) => {
124
146
  await page.goto(baseURL);
125
147
  await page.locator("#promptInput").fill("fixture continuity confirmed before tool");