@firstpick/pi-package-webui 0.6.9 → 0.7.1
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 +7 -2
- package/bin/pi-webui.mjs +407 -31
- package/index.ts +7 -91
- package/package.json +8 -7
- package/public/app.js +1140 -100
- package/public/aur-review-payload.mjs +108 -0
- package/public/guided-git-command-state.mjs +34 -0
- package/public/guided-git-review-state.mjs +137 -0
- package/public/index.html +54 -1
- package/public/styles.css +290 -20
- package/tests/aur-review-payload.test.mjs +57 -0
- package/tests/aur-review-widget-static.test.mjs +38 -0
- package/tests/compaction-resume-harness.test.mjs +55 -3
- package/tests/compaction-static.test.mjs +3 -3
- package/tests/fixtures/compacting-pi.mjs +10 -5
- package/tests/fixtures/fake-pi.mjs +46 -0
- package/tests/guided-git-aur-review.test.mjs +183 -0
- package/tests/http-endpoints-harness.test.mjs +118 -1
- package/tests/mobile-static.test.mjs +123 -12
- package/tests/staged-content-hash-contract.test.mjs +174 -0
- package/tests/subagents-helper.test.mjs +83 -4
- package/tests/transport-hardening-harness.test.mjs +157 -0
- package/webui-rpc-helper.mjs +108 -25
package/index.ts
CHANGED
|
@@ -3,6 +3,9 @@ import path from "node:path";
|
|
|
3
3
|
import type { Readable } from "node:stream";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import { delay, takeValue, tokenizeArgs } from "@firstpick/pi-utils";
|
|
7
|
+
import { detachChildProcess as releaseStartedChild, isProcessRunning, terminateChildProcess as terminateFailedChild } from "@firstpick/pi-utils/process";
|
|
8
|
+
import { fetchJsonWithTimeout as fetchJsonWithTimeoutBase } from "@firstpick/pi-utils/http";
|
|
6
9
|
import {
|
|
7
10
|
gitWorkflowPreferencesSummary,
|
|
8
11
|
readGitWorkflowPreferences,
|
|
@@ -58,53 +61,6 @@ type RestorableWebuiTab = {
|
|
|
58
61
|
|
|
59
62
|
type WebuiChild = ChildProcessByStdio<null, Readable, Readable>;
|
|
60
63
|
|
|
61
|
-
function tokenizeArgs(input: string): string[] {
|
|
62
|
-
const tokens: string[] = [];
|
|
63
|
-
let current = "";
|
|
64
|
-
let quote: '"' | "'" | undefined;
|
|
65
|
-
let escaped = false;
|
|
66
|
-
|
|
67
|
-
for (const char of input) {
|
|
68
|
-
if (escaped) {
|
|
69
|
-
current += char;
|
|
70
|
-
escaped = false;
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (char === "\\") {
|
|
74
|
-
escaped = true;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (quote) {
|
|
78
|
-
if (char === quote) quote = undefined;
|
|
79
|
-
else current += char;
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (char === '"' || char === "'") {
|
|
83
|
-
quote = char;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (/\s/.test(char)) {
|
|
87
|
-
if (current) {
|
|
88
|
-
tokens.push(current);
|
|
89
|
-
current = "";
|
|
90
|
-
}
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
current += char;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (escaped) current += "\\";
|
|
97
|
-
if (quote) throw new Error(`Unclosed ${quote} quote`);
|
|
98
|
-
if (current) tokens.push(current);
|
|
99
|
-
return tokens;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function takeValue(tokens: string[], index: number, flag: string): string {
|
|
103
|
-
const value = tokens[index + 1];
|
|
104
|
-
if (!value || value.startsWith("--")) throw new Error(`${flag} requires a value`);
|
|
105
|
-
return value;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
64
|
function parseStartWebuiArgs(args: string): StartWebuiOptions {
|
|
109
65
|
const options: StartWebuiOptions = {
|
|
110
66
|
host: DEFAULT_HOST,
|
|
@@ -210,18 +166,8 @@ function urlFor(options: WebuiAddress): string {
|
|
|
210
166
|
return `http://${host}:${options.port}/`;
|
|
211
167
|
}
|
|
212
168
|
|
|
213
|
-
async function fetchJsonWithTimeout(url: string, init: RequestInit = {}, timeoutMs = 900): Promise<{ ok: boolean; status: number; body
|
|
214
|
-
|
|
215
|
-
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
216
|
-
try {
|
|
217
|
-
const response = await fetch(url, { ...init, signal: controller.signal });
|
|
218
|
-
const body = await response.json().catch(() => undefined);
|
|
219
|
-
return { ok: response.ok, status: response.status, body };
|
|
220
|
-
} catch {
|
|
221
|
-
return null;
|
|
222
|
-
} finally {
|
|
223
|
-
clearTimeout(timeout);
|
|
224
|
-
}
|
|
169
|
+
async function fetchJsonWithTimeout(url: string, init: RequestInit = {}, timeoutMs = 900): Promise<{ ok: boolean; status: number; body?: any }> {
|
|
170
|
+
return fetchJsonWithTimeoutBase(url, init, { timeoutMs });
|
|
225
171
|
}
|
|
226
172
|
|
|
227
173
|
async function probeExistingWebui(url: string): Promise<ExistingWebui | null> {
|
|
@@ -324,15 +270,11 @@ async function fetchRestorableTabs(url: string, existing: ExistingWebui, options
|
|
|
324
270
|
return mergeRestorableTabsFromStatusSources([statusData?.restorableTabs, existing.restorableTabs], options);
|
|
325
271
|
}
|
|
326
272
|
|
|
327
|
-
function sleep(ms: number): Promise<void> {
|
|
328
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
329
|
-
}
|
|
330
|
-
|
|
331
273
|
async function waitForWebuiToStop(url: string, timeoutMs = 7_000): Promise<boolean> {
|
|
332
274
|
const deadline = Date.now() + timeoutMs;
|
|
333
275
|
while (Date.now() < deadline) {
|
|
334
276
|
if (!(await probeExistingWebui(url))) return true;
|
|
335
|
-
await
|
|
277
|
+
await delay(180);
|
|
336
278
|
}
|
|
337
279
|
return !(await probeExistingWebui(url));
|
|
338
280
|
}
|
|
@@ -342,15 +284,6 @@ async function requestWebuiShutdown(url: string): Promise<boolean> {
|
|
|
342
284
|
return result?.ok === true && result.body?.ok === true;
|
|
343
285
|
}
|
|
344
286
|
|
|
345
|
-
function isProcessRunning(pid: number): boolean {
|
|
346
|
-
try {
|
|
347
|
-
process.kill(pid, 0);
|
|
348
|
-
return true;
|
|
349
|
-
} catch (error) {
|
|
350
|
-
return (error as NodeJS.ErrnoException)?.code === "EPERM";
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
287
|
async function terminatePid(pid: number): Promise<void> {
|
|
355
288
|
if (!Number.isInteger(pid) || pid <= 0 || pid === process.pid || !isProcessRunning(pid)) return;
|
|
356
289
|
try {
|
|
@@ -362,7 +295,7 @@ async function terminatePid(pid: number): Promise<void> {
|
|
|
362
295
|
const deadline = Date.now() + 4_000;
|
|
363
296
|
while (Date.now() < deadline) {
|
|
364
297
|
if (!isProcessRunning(pid)) return;
|
|
365
|
-
await
|
|
298
|
+
await delay(160);
|
|
366
299
|
}
|
|
367
300
|
|
|
368
301
|
try {
|
|
@@ -472,23 +405,6 @@ function openDefaultBrowser(url: string): void {
|
|
|
472
405
|
child.unref();
|
|
473
406
|
}
|
|
474
407
|
|
|
475
|
-
function releaseStartedChild(child: WebuiChild): void {
|
|
476
|
-
child.stdout.removeAllListeners("data");
|
|
477
|
-
child.stderr.removeAllListeners("data");
|
|
478
|
-
(child.stdout as Readable & { unref?: () => void }).unref?.();
|
|
479
|
-
(child.stderr as Readable & { unref?: () => void }).unref?.();
|
|
480
|
-
child.unref();
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
function terminateFailedChild(child: WebuiChild): void {
|
|
484
|
-
if (child.exitCode === null) child.kill("SIGTERM");
|
|
485
|
-
setTimeout(() => {
|
|
486
|
-
if (child.exitCode === null) child.kill("SIGKILL");
|
|
487
|
-
}, 2000).unref?.();
|
|
488
|
-
child.stdout.destroy();
|
|
489
|
-
child.stderr.destroy();
|
|
490
|
-
}
|
|
491
|
-
|
|
492
408
|
function startupTimeoutMs(restoreTabCount: number): number {
|
|
493
409
|
const extraTabs = Math.max(0, restoreTabCount - 1);
|
|
494
410
|
return Math.min(START_TIMEOUT_MAX_MS, START_TIMEOUT_MS + extraTabs * START_TIMEOUT_PER_RESTORED_TAB_MS);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firstpick/pi-package-webui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
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",
|
|
@@ -51,27 +51,28 @@
|
|
|
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 bin/pi-webui.mjs && node --check webui-rpc-helper.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/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/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": {
|
|
58
|
-
"@earendil-works/pi-coding-agent": "^0.80.
|
|
58
|
+
"@earendil-works/pi-coding-agent": "^0.80.10",
|
|
59
|
+
"@firstpick/pi-utils": "^0.2.4",
|
|
59
60
|
"mermaid": "^11.15.0"
|
|
60
61
|
},
|
|
61
62
|
"optionalDependencies": {
|
|
62
63
|
"@firstpick/pi-extension-bang-command-autocomplete": "^0.2.1",
|
|
63
64
|
"@firstpick/pi-extension-btw": "^0.1.3",
|
|
64
65
|
"@firstpick/pi-extension-fish-user-bash": "^0.2.1",
|
|
65
|
-
"@firstpick/pi-extension-git-footer-status": "^0.4.
|
|
66
|
+
"@firstpick/pi-extension-git-footer-status": "^0.4.1",
|
|
66
67
|
"@firstpick/pi-extension-release-aur": "^0.1.7",
|
|
67
|
-
"@firstpick/pi-extension-release-npm": "^0.4.
|
|
68
|
+
"@firstpick/pi-extension-release-npm": "^0.4.3",
|
|
68
69
|
"@firstpick/pi-extension-safety-guard": "^0.2.5",
|
|
69
70
|
"@firstpick/pi-extension-setup-skills": "^0.1.8",
|
|
70
71
|
"@firstpick/pi-extension-stats": "^0.2.8",
|
|
71
72
|
"@firstpick/pi-extension-todo-progress": "^0.2.8",
|
|
72
73
|
"@firstpick/pi-extension-tools": "^0.1.6",
|
|
73
|
-
"@firstpick/pi-extension-workflows": "^0.1.
|
|
74
|
-
"@firstpick/pi-package-remote-webui": "^0.1.
|
|
74
|
+
"@firstpick/pi-extension-workflows": "^0.1.4",
|
|
75
|
+
"@firstpick/pi-package-remote-webui": "^0.1.6",
|
|
75
76
|
"@firstpick/pi-prompts-git-pr": "^0.1.3",
|
|
76
77
|
"@firstpick/pi-themes-bundle": "^0.1.4"
|
|
77
78
|
},
|