@firstpick/pi-package-webui 0.11.2 → 0.11.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firstpick/pi-package-webui",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
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/pi-coding-agent-forge/tree/main/pi-package-webui#readme",
package/public/styles.css CHANGED
@@ -19625,6 +19625,8 @@ body:has(#undoToast:not([hidden])) .notice-toast-stack { bottom: calc(max(1rem,
19625
19625
  .chat { padding: 0.5rem 0.46rem; }
19626
19626
  .run-indicator-host { padding: 0 0.46rem 0.5rem; }
19627
19627
  .message { margin-bottom: 0.5rem; padding: 0.56rem 0.58rem; border-radius: 0.74rem; }
19628
+ /* Always-visible mobile reactions need room below the text. */
19629
+ .message.has-action-feedback { padding-bottom: calc(var(--mobile-control-size) + 0.38rem + 0.15rem); }
19628
19630
  .message-body { font-size: 0.84rem; }
19629
19631
  .message-header { gap: 0.4rem; margin-bottom: 0.3rem; font-size: var(--mobile-label-text); }
19630
19632
  .message-copy-button { top: 0.28rem; right: 0.32rem; width: 1.8rem; min-width: 1.8rem; min-height: 1.8rem; }
@@ -0,0 +1,251 @@
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
+ // Touch layouts keep reactions visible and need a strip below the text. Desktop
12
+ // reactions appear on hover and must preserve the original message height.
13
+
14
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..", "..");
15
+ const serverScript = join(root, "bin", "pi-webui.mjs");
16
+ const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
17
+
18
+ // Long enough to wrap to the full bubble width several times, so the last line reaches
19
+ // the right edge where the controls sit. Three paragraphs and a short closing line.
20
+ const TRANSCRIPT = [
21
+ {
22
+ role: "user",
23
+ content: "Fixture gutter prompt",
24
+ timestamp: 1_000,
25
+ },
26
+ {
27
+ role: "assistant",
28
+ content: [
29
+ {
30
+ type: "text",
31
+ text: [
32
+ "The layout pass moves the reserved strip into the message bubble instead of the header, so the transcript keeps a stable height while the reaction controls stay pinned to the bottom-right corner of the card and never expand it.",
33
+ "Measurements come from the rendered controls, not from a guessed constant: the button row is forty pixels tall on a narrow touch viewport and forty-three pixels on a desktop viewport, and the controls keep their own bottom offset inside the bubble.",
34
+ "When the strip is missing the last text line runs underneath the buttons, which is what a phone shows on every final answer, and the text stays partly unreadable until the message is long enough to scroll past the overlap.",
35
+ "Closing note: the strip is reserved by the class the renderer already applies.",
36
+ ].join("\n\n"),
37
+ },
38
+ ],
39
+ timestamp: 2_000,
40
+ },
41
+ ];
42
+
43
+ let child;
44
+ let baseURL;
45
+ let port;
46
+ let tempDir;
47
+ let output = "";
48
+
49
+ async function freePort() {
50
+ const server = createServer();
51
+ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
52
+ const { port: free } = server.address();
53
+ await new Promise((resolve) => server.close(resolve));
54
+ return free;
55
+ }
56
+
57
+ async function startServer() {
58
+ const env = Object.fromEntries(
59
+ Object.entries(process.env).filter(([key]) => !key.startsWith("PI_") && !key.startsWith("FAKE_PI_")),
60
+ );
61
+ child = spawn(
62
+ process.execPath,
63
+ [
64
+ serverScript,
65
+ "--cwd",
66
+ tempDir,
67
+ "--host",
68
+ "127.0.0.1",
69
+ "--port",
70
+ String(port),
71
+ "--pi",
72
+ fakePi,
73
+ "--",
74
+ "--session-dir",
75
+ join(tempDir, "sessions"),
76
+ ],
77
+ {
78
+ detached: true,
79
+ stdio: ["ignore", "pipe", "pipe"],
80
+ env: {
81
+ ...env,
82
+ NODE_ENV: "test",
83
+ HOME: join(tempDir, "home"),
84
+ PI_CODING_AGENT_DIR: join(tempDir, "agent"),
85
+ PI_WEBUI_RPC_SUPERVISOR: "0",
86
+ FAKE_PI_TRANSCRIPT_JSON: JSON.stringify(TRANSCRIPT),
87
+ },
88
+ },
89
+ );
90
+ child.stdout.on("data", (chunk) => {
91
+ output = (output + String(chunk)).slice(-8_000);
92
+ });
93
+ child.stderr.on("data", (chunk) => {
94
+ output = (output + String(chunk)).slice(-8_000);
95
+ });
96
+ for (let attempt = 0; attempt < 120; attempt += 1) {
97
+ if (child.exitCode !== null) throw new Error(`Pi Web UI exited during startup:\n${output}`);
98
+ try {
99
+ const response = await fetch(`${baseURL}/api/health`, { signal: AbortSignal.timeout(500) });
100
+ if (response.ok) return;
101
+ } catch {
102
+ // Server is still booting.
103
+ }
104
+ await delay(250);
105
+ }
106
+ throw new Error(`Pi Web UI did not start:\n${output}`);
107
+ }
108
+
109
+ async function stopServer() {
110
+ if (!child || child.exitCode !== null) return;
111
+ const exited = new Promise((resolve) => child.once("exit", resolve));
112
+ try {
113
+ process.kill(-child.pid, "SIGTERM");
114
+ } catch {
115
+ child.kill("SIGTERM");
116
+ }
117
+ await Promise.race([exited, delay(3_000)]);
118
+ try {
119
+ process.kill(-child.pid, "SIGKILL");
120
+ } catch {
121
+ // Already gone.
122
+ }
123
+ }
124
+
125
+ // Geometry of every message bubble that carries reaction controls. The text walk skips
126
+ // text inside a collapsed <details>: the browser reports client rects for it, but those
127
+ // pixels are not painted, so counting them would report a false overlap.
128
+ const MEASURE = () => {
129
+ const messages = [...document.querySelectorAll(".message.has-action-feedback")];
130
+ return messages.map((message) => {
131
+ const controls = message.querySelector(":scope > .action-feedback-controls");
132
+ const body = message.querySelector(":scope > .message-body");
133
+ if (!controls || !body) return { controls: false, overlaps: 0, gutter: null };
134
+ const box = controls.getBoundingClientRect();
135
+ const bodyRect = body.getBoundingClientRect();
136
+ let overlaps = 0;
137
+ const walker = document.createTreeWalker(body, NodeFilter.SHOW_TEXT);
138
+ while (walker.nextNode()) {
139
+ const node = walker.currentNode;
140
+ if (!node.textContent.trim()) continue;
141
+ if (node.parentElement?.closest("details:not([open])")) continue;
142
+ const range = document.createRange();
143
+ range.selectNodeContents(node);
144
+ for (const rect of range.getClientRects()) {
145
+ if (rect.width <= 1 || rect.height <= 1) continue;
146
+ const overlapX = Math.min(box.right, rect.right) - Math.max(box.left, rect.left);
147
+ const overlapY = Math.min(box.bottom, rect.bottom) - Math.max(box.top, rect.top);
148
+ if (overlapX > 1 && overlapY > 1) overlaps += 1;
149
+ }
150
+ }
151
+ return {
152
+ controls: true,
153
+ overlaps,
154
+ gutter: Math.round(box.top - bodyRect.bottom),
155
+ paddingBottom: getComputedStyle(message).paddingBottom,
156
+ text: body.innerText.trim().slice(0, 32),
157
+ };
158
+ });
159
+ };
160
+
161
+ async function openTranscript(page) {
162
+ await page.goto(baseURL, { waitUntil: "domcontentloaded" });
163
+ const bubble = page.locator(".message.has-action-feedback").first();
164
+ await expect(bubble).toBeVisible({ timeout: 20_000 });
165
+ await expect(bubble).toContainText("Closing note");
166
+ // The strip must already be laid out; wait for the controls to have a box.
167
+ await expect
168
+ .poll(() => bubble.locator(":scope > .action-feedback-controls").evaluate((element) => element.getClientRects().length > 0), {
169
+ timeout: 10_000,
170
+ })
171
+ .toBe(true);
172
+ }
173
+
174
+ async function expectNoOverlap(page) {
175
+ const measured = await page.evaluate(MEASURE);
176
+ assert.ok(measured.length > 0, "the transcript should render at least one message with reaction controls");
177
+ for (const message of measured) {
178
+ assert.equal(message.controls, true, "each action-feedback bubble should keep its controls as a direct child");
179
+ assert.equal(
180
+ message.overlaps,
181
+ 0,
182
+ `reaction controls should not cover text in "${message.text}": ${message.overlaps} intersecting text line(s)`,
183
+ );
184
+ assert.ok(
185
+ message.gutter >= 0,
186
+ `the bubble should reserve a strip under the text (controls top is ${message.gutter}px above the body bottom, padding-bottom ${message.paddingBottom})`,
187
+ );
188
+ }
189
+ const overflow = await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth);
190
+ assert.ok(overflow <= 1, `the reserved strip should not introduce horizontal overflow (${overflow}px)`);
191
+ }
192
+
193
+ test.describe.configure({ mode: "serial" });
194
+
195
+ test.beforeAll(async () => {
196
+ tempDir = await mkdtemp(join(tmpdir(), "pi-webui-action-feedback-gutter-"));
197
+ port = await freePort();
198
+ baseURL = `http://127.0.0.1:${port}`;
199
+ await startServer();
200
+ });
201
+
202
+ test.afterAll(async () => {
203
+ await stopServer();
204
+ await rm(tempDir, { recursive: true, force: true });
205
+ });
206
+
207
+ test.describe("390px touch viewport", () => {
208
+ test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true, serviceWorkers: "block" });
209
+
210
+ test("reaction controls stay off the last text line", async ({ page }) => {
211
+ await openTranscript(page);
212
+ await expectNoOverlap(page);
213
+ });
214
+ });
215
+
216
+ test.describe("320px touch viewport", () => {
217
+ test.use({ viewport: { width: 320, height: 700 }, hasTouch: true, isMobile: true, serviceWorkers: "block" });
218
+
219
+ test("reaction controls stay off the last text line", async ({ page }) => {
220
+ await openTranscript(page);
221
+ await expectNoOverlap(page);
222
+ });
223
+ });
224
+
225
+ for (const layout of ["classic", "focused"]) {
226
+ test.describe(`1440px ${layout} desktop viewport`, () => {
227
+ test.use({ viewport: { width: 1440, height: 900 }, serviceWorkers: "block", reducedMotion: "reduce" });
228
+
229
+ test("reaction controls do not increase message height", async ({ page }) => {
230
+ await page.addInitScript((desktopLayout) => {
231
+ localStorage.setItem("pi-webui-shell-preferences-v1", JSON.stringify({ v: 1, desktopLayout }));
232
+ }, layout);
233
+ await openTranscript(page);
234
+ await expect(page.locator("#focusedWorkspace")).toBeVisible({ visible: layout === "focused" });
235
+ const bubble = page.locator(".message.has-action-feedback").first();
236
+ const heights = await bubble.evaluate((message) => {
237
+ const withControls = message.getBoundingClientRect().height;
238
+ message.classList.remove("has-action-feedback");
239
+ try {
240
+ return { withControls, withoutControls: message.getBoundingClientRect().height };
241
+ } finally {
242
+ message.classList.add("has-action-feedback");
243
+ }
244
+ });
245
+ expect(heights.withControls).toBe(heights.withoutControls);
246
+ await bubble.hover();
247
+ await expect(bubble.locator(":scope > .action-feedback-controls")).toHaveCSS("opacity", "1");
248
+ expect(await bubble.evaluate((message) => message.getBoundingClientRect().height)).toBe(heights.withoutControls);
249
+ });
250
+ });
251
+ }