@firstpick/pi-package-webui 0.7.1 → 0.7.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/README.md +7 -5
- package/bin/pi-webui.mjs +507 -66
- package/index.ts +4 -0
- package/lib/git-live-watcher.mjs +135 -0
- package/lib/git-message-artifacts.mjs +103 -0
- package/lib/process-tree.mjs +3 -1
- package/lib/subagent-gate.mjs +618 -0
- package/package.json +8 -6
- package/public/app.js +1261 -117
- package/public/index.html +25 -3
- package/public/styles.css +479 -4
- package/tests/app-runner-windows-conpty-harness.test.mjs +140 -0
- package/tests/danger-button-contrast-static.test.mjs +32 -0
- package/tests/fixtures/fake-pi.mjs +22 -4
- package/tests/footer-middle-truncation.test.mjs +118 -0
- package/tests/git-live-watcher.test.mjs +93 -0
- package/tests/git-message-artifacts.test.mjs +59 -0
- package/tests/git-panel-live-updates-static.test.mjs +54 -0
- package/tests/git-panel-render-stability-static.test.mjs +43 -0
- package/tests/guided-git-message-reliability-static.test.mjs +38 -0
- package/tests/http-endpoints-harness.test.mjs +103 -5
- package/tests/image-payload-hardening-harness.test.mjs +115 -0
- package/tests/mobile-static.test.mjs +74 -10
- package/tests/pi-footer-calibration-static.test.mjs +55 -0
- package/tests/runtime-error-visibility.test.mjs +63 -0
- package/tests/side-panel-context-menu-static.test.mjs +74 -0
- package/tests/subagent-gate.test.mjs +300 -0
- package/tests/subagents-helper.test.mjs +34 -3
- package/webui-rpc-helper.mjs +165 -11
package/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-c
|
|
|
6
6
|
import { delay, takeValue, tokenizeArgs } from "@firstpick/pi-utils";
|
|
7
7
|
import { detachChildProcess as releaseStartedChild, isProcessRunning, terminateChildProcess as terminateFailedChild } from "@firstpick/pi-utils/process";
|
|
8
8
|
import { fetchJsonWithTimeout as fetchJsonWithTimeoutBase } from "@firstpick/pi-utils/http";
|
|
9
|
+
import { registerSubagentGate } from "./lib/subagent-gate.mjs";
|
|
9
10
|
import {
|
|
10
11
|
gitWorkflowPreferencesSummary,
|
|
11
12
|
readGitWorkflowPreferences,
|
|
@@ -849,6 +850,9 @@ async function runGitWorkflowSetup(ctx: ExtensionCommandContext): Promise<void>
|
|
|
849
850
|
}
|
|
850
851
|
|
|
851
852
|
export default function (pi: ExtensionAPI) {
|
|
853
|
+
const subagentGate = registerSubagentGate(pi);
|
|
854
|
+
pi.on("session_shutdown", () => subagentGate.dispose());
|
|
855
|
+
|
|
852
856
|
const startWebuiHandler = async (args: string, ctx: ExtensionCommandContext) => {
|
|
853
857
|
let options: StartWebuiOptions;
|
|
854
858
|
try {
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { watch as watchDirectory } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export const GIT_LIVE_WATCH_DEBOUNCE_MS = 250;
|
|
5
|
+
export const GIT_LIVE_WATCH_MAX_WAIT_MS = 2_000;
|
|
6
|
+
|
|
7
|
+
function cleanTabId(value) {
|
|
8
|
+
return String(value || "").trim();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function canonicalRoot(value) {
|
|
12
|
+
const root = String(value || "").trim();
|
|
13
|
+
return root ? path.resolve(root) : "";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createGitLiveWatcher({
|
|
17
|
+
watch = watchDirectory,
|
|
18
|
+
debounceMs = GIT_LIVE_WATCH_DEBOUNCE_MS,
|
|
19
|
+
maxWaitMs = GIT_LIVE_WATCH_MAX_WAIT_MS,
|
|
20
|
+
onChange = () => {},
|
|
21
|
+
onError = () => {},
|
|
22
|
+
} = {}) {
|
|
23
|
+
const roots = new Map();
|
|
24
|
+
const tabRoots = new Map();
|
|
25
|
+
const delayMs = Math.max(0, Number(debounceMs) || 0);
|
|
26
|
+
const maximumWaitMs = Math.max(0, Number(maxWaitMs) || GIT_LIVE_WATCH_MAX_WAIT_MS);
|
|
27
|
+
|
|
28
|
+
function reportError(root, error) {
|
|
29
|
+
try {
|
|
30
|
+
onError({ root, error });
|
|
31
|
+
} catch {
|
|
32
|
+
// Watcher diagnostics must never crash the Web UI server.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function closeRoot(root, { clearTabs = true } = {}) {
|
|
37
|
+
const record = roots.get(root);
|
|
38
|
+
if (!record) return false;
|
|
39
|
+
roots.delete(root);
|
|
40
|
+
if (record.timer) clearTimeout(record.timer);
|
|
41
|
+
try {
|
|
42
|
+
record.watcher?.close();
|
|
43
|
+
} catch {
|
|
44
|
+
// The watcher may already be closed after an error.
|
|
45
|
+
}
|
|
46
|
+
if (clearTabs) {
|
|
47
|
+
for (const tabId of record.tabs) {
|
|
48
|
+
if (tabRoots.get(tabId) === root) tabRoots.delete(tabId);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function failRoot(root, error) {
|
|
55
|
+
if (!roots.has(root)) return;
|
|
56
|
+
closeRoot(root);
|
|
57
|
+
reportError(root, error);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function scheduleChange(root) {
|
|
61
|
+
const record = roots.get(root);
|
|
62
|
+
if (!record) return;
|
|
63
|
+
if (record.timer) clearTimeout(record.timer);
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
if (!record.burstStartedAt) record.burstStartedAt = now;
|
|
66
|
+
const remainingMs = Math.max(0, maximumWaitMs - (now - record.burstStartedAt));
|
|
67
|
+
record.timer = setTimeout(() => {
|
|
68
|
+
const current = roots.get(root);
|
|
69
|
+
if (!current || current !== record) return;
|
|
70
|
+
current.timer = null;
|
|
71
|
+
current.burstStartedAt = 0;
|
|
72
|
+
try {
|
|
73
|
+
onChange({ root, changedAt: new Date().toISOString() });
|
|
74
|
+
} catch (error) {
|
|
75
|
+
reportError(root, error);
|
|
76
|
+
}
|
|
77
|
+
}, Math.min(delayMs, remainingMs));
|
|
78
|
+
record.timer.unref?.();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function ensureRoot(root) {
|
|
82
|
+
const existing = roots.get(root);
|
|
83
|
+
if (existing) return existing;
|
|
84
|
+
const record = { root, tabs: new Set(), watcher: null, timer: null, burstStartedAt: 0 };
|
|
85
|
+
roots.set(root, record);
|
|
86
|
+
try {
|
|
87
|
+
record.watcher = watch(root, { recursive: true, persistent: false }, () => scheduleChange(root));
|
|
88
|
+
record.watcher.on?.("error", (error) => failRoot(root, error));
|
|
89
|
+
return record;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
roots.delete(root);
|
|
92
|
+
reportError(root, error);
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function unsubscribe(tabIdValue) {
|
|
98
|
+
const tabId = cleanTabId(tabIdValue);
|
|
99
|
+
const root = tabRoots.get(tabId);
|
|
100
|
+
if (!root) return false;
|
|
101
|
+
tabRoots.delete(tabId);
|
|
102
|
+
const record = roots.get(root);
|
|
103
|
+
if (!record) return true;
|
|
104
|
+
record.tabs.delete(tabId);
|
|
105
|
+
if (!record.tabs.size) closeRoot(root, { clearTabs: false });
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function subscribe(tabIdValue, rootValue) {
|
|
110
|
+
const tabId = cleanTabId(tabIdValue);
|
|
111
|
+
const root = canonicalRoot(rootValue);
|
|
112
|
+
if (!tabId || !root) return false;
|
|
113
|
+
const previousRoot = tabRoots.get(tabId);
|
|
114
|
+
if (previousRoot === root && roots.has(root)) return true;
|
|
115
|
+
if (previousRoot) unsubscribe(tabId);
|
|
116
|
+
const record = ensureRoot(root);
|
|
117
|
+
if (!record) return false;
|
|
118
|
+
record.tabs.add(tabId);
|
|
119
|
+
tabRoots.set(tabId, root);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function closeAll() {
|
|
124
|
+
for (const root of [...roots.keys()]) closeRoot(root);
|
|
125
|
+
tabRoots.clear();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
subscribe,
|
|
130
|
+
unsubscribe,
|
|
131
|
+
closeAll,
|
|
132
|
+
watchedRootCount: () => roots.size,
|
|
133
|
+
subscribedRootForTab: (tabId) => tabRoots.get(cleanTabId(tabId)) || "",
|
|
134
|
+
};
|
|
135
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFile, stat } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
const DEFAULT_STABLE_READ_ATTEMPTS = 3;
|
|
5
|
+
const DEFAULT_STABLE_READ_DELAY_MS = 20;
|
|
6
|
+
|
|
7
|
+
function delay(ms) {
|
|
8
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function artifactIdentity(stats, bytes) {
|
|
12
|
+
return {
|
|
13
|
+
size: Number(stats.size),
|
|
14
|
+
mtimeNs: String(stats.mtimeNs),
|
|
15
|
+
ctimeNs: String(stats.ctimeNs),
|
|
16
|
+
ino: String(stats.ino),
|
|
17
|
+
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function sameStatIdentity(left, right) {
|
|
22
|
+
return left.size === right.size
|
|
23
|
+
&& left.mtimeNs === right.mtimeNs
|
|
24
|
+
&& left.ctimeNs === right.ctimeNs
|
|
25
|
+
&& left.ino === right.ino;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function sameGitMessageArtifactVersion(left, right) {
|
|
29
|
+
if (!left?.exists || !right?.exists) return left?.exists === right?.exists;
|
|
30
|
+
return left.size === right.size
|
|
31
|
+
&& left.mtimeNs === right.mtimeNs
|
|
32
|
+
&& left.ctimeNs === right.ctimeNs
|
|
33
|
+
&& left.ino === right.ino
|
|
34
|
+
&& left.sha256 === right.sha256;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function readStableGitMessageArtifact(filePath, {
|
|
38
|
+
attempts = DEFAULT_STABLE_READ_ATTEMPTS,
|
|
39
|
+
retryDelayMs = DEFAULT_STABLE_READ_DELAY_MS,
|
|
40
|
+
} = {}) {
|
|
41
|
+
let lastError;
|
|
42
|
+
for (let attempt = 0; attempt < Math.max(1, attempts); attempt += 1) {
|
|
43
|
+
try {
|
|
44
|
+
const before = await stat(filePath, { bigint: true });
|
|
45
|
+
if (!before.isFile()) return { exists: false, path: filePath, reason: "not-file" };
|
|
46
|
+
const bytes = await readFile(filePath);
|
|
47
|
+
const after = await stat(filePath, { bigint: true });
|
|
48
|
+
const beforeIdentity = artifactIdentity(before, bytes);
|
|
49
|
+
const afterIdentity = artifactIdentity(after, bytes);
|
|
50
|
+
if (sameStatIdentity(beforeIdentity, afterIdentity)) {
|
|
51
|
+
return {
|
|
52
|
+
exists: true,
|
|
53
|
+
path: filePath,
|
|
54
|
+
text: bytes.toString("utf8"),
|
|
55
|
+
...afterIdentity,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
lastError = new Error(`Git message artifact changed while it was being read: ${filePath}`);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (error?.code === "ENOENT" || error?.code === "ENOTDIR") {
|
|
61
|
+
return { exists: false, path: filePath, reason: "missing" };
|
|
62
|
+
}
|
|
63
|
+
lastError = error;
|
|
64
|
+
}
|
|
65
|
+
if (attempt + 1 < attempts && retryDelayMs > 0) await delay(retryDelayMs);
|
|
66
|
+
}
|
|
67
|
+
throw lastError || new Error(`Could not read a stable Git message artifact: ${filePath}`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function readStableGitMessageArtifactPair({ shortPath, longPath }, options) {
|
|
71
|
+
const [short, long] = await Promise.all([
|
|
72
|
+
readStableGitMessageArtifact(shortPath, options),
|
|
73
|
+
readStableGitMessageArtifact(longPath, options),
|
|
74
|
+
]);
|
|
75
|
+
return { short, long };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function sameGitMessageArtifactPair(left, right) {
|
|
79
|
+
return sameGitMessageArtifactVersion(left?.short, right?.short)
|
|
80
|
+
&& sameGitMessageArtifactVersion(left?.long, right?.long);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function gitMessageArtifactPairReadiness(baseline, current) {
|
|
84
|
+
const missing = [];
|
|
85
|
+
const unchanged = [];
|
|
86
|
+
const empty = [];
|
|
87
|
+
for (const key of ["short", "long"]) {
|
|
88
|
+
const before = baseline?.[key] || { exists: false };
|
|
89
|
+
const after = current?.[key] || { exists: false };
|
|
90
|
+
if (!after.exists) {
|
|
91
|
+
missing.push(key);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (sameGitMessageArtifactVersion(before, after)) unchanged.push(key);
|
|
95
|
+
if (!String(after.text || "").trim()) empty.push(key);
|
|
96
|
+
}
|
|
97
|
+
const ready = missing.length === 0 && unchanged.length === 0 && empty.length === 0;
|
|
98
|
+
let reason = "Generated commit message files are ready.";
|
|
99
|
+
if (missing.length) reason = `Waiting for generated ${missing.join(" and ")} message file${missing.length === 1 ? "" : "s"}.`;
|
|
100
|
+
else if (unchanged.length) reason = `Waiting for ${unchanged.join(" and ")} message file${unchanged.length === 1 ? "" : "s"} to be refreshed for this generation.`;
|
|
101
|
+
else if (empty.length) reason = `Waiting for generated ${empty.join(" and ")} message file${empty.length === 1 ? "" : "s"} to contain a message.`;
|
|
102
|
+
return { ready, reason, missing, unchanged, empty };
|
|
103
|
+
}
|
package/lib/process-tree.mjs
CHANGED
|
@@ -24,7 +24,9 @@ function windowsTaskkillCommand() {
|
|
|
24
24
|
* used instead of child.kill(), which only terminates the direct child.
|
|
25
25
|
*/
|
|
26
26
|
export function terminateProcessTree(target, signal = "SIGTERM") {
|
|
27
|
-
|
|
27
|
+
const hasExited = (target?.exitCode !== undefined && target.exitCode !== null)
|
|
28
|
+
|| (target?.signalCode !== undefined && target.signalCode !== null);
|
|
29
|
+
if (!target || hasExited) return false;
|
|
28
30
|
const pid = Number(target.pid);
|
|
29
31
|
|
|
30
32
|
if (process.platform === "win32" && Number.isInteger(pid) && pid > 0) {
|