@firstpick/pi-package-webui 0.7.6 → 0.7.8
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 +60 -4
- package/bin/pi-webui-rpc-supervisor.mjs +612 -0
- package/bin/pi-webui.mjs +1051 -95
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
- package/lib/rpc-supervisor-client.mjs +317 -0
- package/lib/rpc-supervisor-protocol.mjs +245 -0
- package/lib/rpc-supervisor-state.mjs +165 -0
- package/lib/trust-boundaries.mjs +1 -0
- package/package.json +4 -4
- package/public/app.js +1986 -170
- package/public/index.html +388 -25
- package/public/issue-bot-client.mjs +344 -0
- package/public/issue-wizard-state.mjs +443 -0
- package/public/service-worker.js +8 -1
- package/public/styles.css +578 -52
- package/public/subagent-gate-visibility.mjs +36 -0
- package/public/workflow-status-stack.mjs +69 -0
- package/tests/app-runner-process-tree-harness.test.mjs +37 -3
- package/tests/boot-failure-diagnostics.test.mjs +180 -0
- package/tests/completion-signal-contract.test.mjs +156 -0
- package/tests/cwd-footer-reliability-static.test.mjs +107 -0
- package/tests/durable-rpc-supervisor-harness.test.mjs +275 -0
- package/tests/fast-mode-client-static.test.mjs +2 -2
- package/tests/fixtures/fake-pi.mjs +90 -6
- package/tests/footer-context-contrast-static.test.mjs +10 -0
- package/tests/git-panel-file-preview-static.test.mjs +221 -0
- package/tests/git-panel-render-stability-static.test.mjs +11 -1
- package/tests/http-endpoints-harness.test.mjs +458 -33
- package/tests/issue-bot-client.test.mjs +135 -0
- package/tests/issue-wizard-state.test.mjs +126 -0
- package/tests/mobile-static.test.mjs +79 -16
- package/tests/native-parity-harness.test.mjs +2 -1
- package/tests/native-parity.test.mjs +13 -2
- package/tests/numpad-decimal-input-static.test.mjs +128 -0
- package/tests/open-issue-wizard-static.test.mjs +75 -0
- package/tests/prompt-routing-input-clear-static.test.mjs +34 -0
- package/tests/prompt-routing-tab-status.test.mjs +108 -0
- package/tests/rpc-supervisor-host.test.mjs +408 -0
- package/tests/rpc-supervisor-protocol.test.mjs +93 -0
- package/tests/rpc-supervisor-state.test.mjs +62 -0
- package/tests/run-all.mjs +4 -1
- package/tests/streaming-ui-coupling.test.mjs +18 -2
- package/tests/subagent-gate-visibility.test.mjs +66 -0
- package/tests/subagent-launch-slots-static.test.mjs +1 -1
- package/tests/subagents-helper.test.mjs +136 -0
- package/tests/terminal-tab-workspace-static.test.mjs +99 -0
- package/tests/workflow-status-stack.test.mjs +87 -0
- package/webui-rpc-helper.mjs +160 -2
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, open, readFile, rename, rm, stat, writeFile, chmod } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { RPC_SUPERVISOR_PROTOCOL, sanitizeSupervisorData } from "./rpc-supervisor-protocol.mjs";
|
|
6
|
+
|
|
7
|
+
const STATE_FILE_MODE = 0o600;
|
|
8
|
+
const DIRECTORY_MODE = 0o700;
|
|
9
|
+
const STARTUP_LOCK_STALE_MS = 30_000;
|
|
10
|
+
|
|
11
|
+
function scopeDigest(agentDir, port) {
|
|
12
|
+
return createHash("sha256").update(`${path.resolve(agentDir)}\0${port}`).digest("hex");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function secureMkdir(directory) {
|
|
16
|
+
await mkdir(directory, { recursive: true, mode: DIRECTORY_MODE });
|
|
17
|
+
if (process.platform !== "win32") await chmod(directory, DIRECTORY_MODE);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function supervisorPaths({ agentDir, port, runtimeDir } = {}) {
|
|
21
|
+
if (!agentDir || typeof agentDir !== "string") throw new TypeError("agentDir is required");
|
|
22
|
+
if (!Number.isInteger(Number(port)) || Number(port) < 1 || Number(port) > 65535) throw new TypeError("port must be an integer between 1 and 65535");
|
|
23
|
+
const root = runtimeDir ? path.resolve(runtimeDir) : path.join(path.resolve(agentDir), "webui-rpc-supervisor");
|
|
24
|
+
const scopeId = scopeDigest(agentDir, Number(port));
|
|
25
|
+
const socketPath = process.platform === "win32"
|
|
26
|
+
? `\\\\.\\pipe\\pi-webui-rpc-${scopeId}`
|
|
27
|
+
: path.join(root, `${scopeId.slice(0, 24)}.sock`);
|
|
28
|
+
return {
|
|
29
|
+
root,
|
|
30
|
+
scopeId,
|
|
31
|
+
socketPath,
|
|
32
|
+
stateFile: path.join(root, `${scopeId}.json`),
|
|
33
|
+
journalFile: path.join(root, `${scopeId}.journal.jsonl`),
|
|
34
|
+
lockFile: path.join(root, `${scopeId}.start.lock`),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function ensureSupervisorRuntime(paths) {
|
|
39
|
+
await secureMkdir(paths.root);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function newSupervisorToken() {
|
|
43
|
+
return randomBytes(32).toString("base64url");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function validateState(value, paths) {
|
|
47
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
|
|
48
|
+
if (value.scopeId !== paths.scopeId || value.socketPath !== paths.socketPath) return null;
|
|
49
|
+
if (!value.token || typeof value.token !== "string" || !value.instanceId || typeof value.instanceId !== "string") return null;
|
|
50
|
+
if (!Number.isInteger(value.pid) || value.pid < 1) return null;
|
|
51
|
+
if (!value.version || !Number.isInteger(value.version.major) || !Number.isInteger(value.version.minor)) return null;
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function readSupervisorState(paths) {
|
|
56
|
+
try {
|
|
57
|
+
const text = await readFile(paths.stateFile, "utf8");
|
|
58
|
+
return validateState(JSON.parse(text), paths);
|
|
59
|
+
} catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function writeSupervisorState(paths, state) {
|
|
65
|
+
await ensureSupervisorRuntime(paths);
|
|
66
|
+
const payload = {
|
|
67
|
+
scopeId: paths.scopeId,
|
|
68
|
+
socketPath: paths.socketPath,
|
|
69
|
+
version: RPC_SUPERVISOR_PROTOCOL,
|
|
70
|
+
...sanitizeSupervisorData(state),
|
|
71
|
+
};
|
|
72
|
+
// The local token is needed by the server adapter; sanitizer intentionally
|
|
73
|
+
// never receives it so no secret-key heuristic can remove the state token.
|
|
74
|
+
if (typeof state?.token === "string") payload.token = state.token;
|
|
75
|
+
const temporary = `${paths.stateFile}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`;
|
|
76
|
+
await writeFile(temporary, `${JSON.stringify(payload)}\n`, { mode: STATE_FILE_MODE });
|
|
77
|
+
if (process.platform !== "win32") await chmod(temporary, STATE_FILE_MODE);
|
|
78
|
+
await rename(temporary, paths.stateFile);
|
|
79
|
+
if (process.platform !== "win32") await chmod(paths.stateFile, STATE_FILE_MODE);
|
|
80
|
+
return payload;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function supervisorPidIsAlive(pid) {
|
|
84
|
+
if (!Number.isInteger(pid) || pid < 1) return false;
|
|
85
|
+
try {
|
|
86
|
+
process.kill(pid, 0);
|
|
87
|
+
return true;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
return error?.code === "EPERM";
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Remove private runtime files only for the recorded supervisor incarnation.
|
|
95
|
+
* Startup callers must hold the startup lock and independently confirm death.
|
|
96
|
+
*/
|
|
97
|
+
export async function removeSupervisorState(paths, { removeSocket = false, instanceId } = {}) {
|
|
98
|
+
if (instanceId !== undefined) {
|
|
99
|
+
const current = await readSupervisorState(paths);
|
|
100
|
+
if (!current || current.instanceId !== instanceId) return false;
|
|
101
|
+
}
|
|
102
|
+
await rm(paths.stateFile, { force: true });
|
|
103
|
+
if (removeSocket && process.platform !== "win32") {
|
|
104
|
+
const info = await lstat(paths.socketPath).catch(() => null);
|
|
105
|
+
if (info?.isSocket()) await rm(paths.socketPath, { force: true });
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Append an intentionally secret-stripped bounded metadata record. */
|
|
111
|
+
export async function appendSupervisorJournal(paths, entry, { maxBytes = 256 * 1024 } = {}) {
|
|
112
|
+
await ensureSupervisorRuntime(paths);
|
|
113
|
+
const record = `${JSON.stringify(sanitizeSupervisorData({ at: new Date().toISOString(), ...entry }))}\n`;
|
|
114
|
+
if (Buffer.byteLength(record) > 64 * 1024) throw new RangeError("supervisor journal record exceeds 65536 bytes");
|
|
115
|
+
const existing = await stat(paths.journalFile).catch(() => null);
|
|
116
|
+
if (existing?.size && existing.size + Buffer.byteLength(record) > maxBytes) {
|
|
117
|
+
await writeFile(paths.journalFile, record, { mode: STATE_FILE_MODE });
|
|
118
|
+
} else {
|
|
119
|
+
await writeFile(paths.journalFile, record, { flag: "a", mode: STATE_FILE_MODE });
|
|
120
|
+
}
|
|
121
|
+
if (process.platform !== "win32") await chmod(paths.journalFile, STATE_FILE_MODE);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function acquireStartupLock(paths, { staleMs = STARTUP_LOCK_STALE_MS } = {}) {
|
|
125
|
+
await ensureSupervisorRuntime(paths);
|
|
126
|
+
try {
|
|
127
|
+
const handle = await open(paths.lockFile, "wx", STATE_FILE_MODE);
|
|
128
|
+
await handle.writeFile(`${JSON.stringify({ pid: process.pid, createdAt: Date.now() })}\n`);
|
|
129
|
+
return async () => {
|
|
130
|
+
await handle.close().catch(() => {});
|
|
131
|
+
await rm(paths.lockFile, { force: true }).catch(() => {});
|
|
132
|
+
};
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (error?.code !== "EEXIST") throw error;
|
|
135
|
+
const lock = await stat(paths.lockFile).catch(() => null);
|
|
136
|
+
if (lock && Date.now() - lock.mtimeMs > staleMs) {
|
|
137
|
+
await rm(paths.lockFile, { force: true });
|
|
138
|
+
return acquireStartupLock(paths, { staleMs });
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export async function waitForSupervisorState(paths, { timeoutMs = 8_000, intervalMs = 50 } = {}) {
|
|
145
|
+
const deadline = Date.now() + timeoutMs;
|
|
146
|
+
while (Date.now() < deadline) {
|
|
147
|
+
const state = await readSupervisorState(paths);
|
|
148
|
+
if (state) return state;
|
|
149
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function sanitizedSupervisorEnvironment(source = process.env) {
|
|
155
|
+
const env = {};
|
|
156
|
+
for (const [key, value] of Object.entries(source)) {
|
|
157
|
+
if (/^PI_WEBUI_RPC_SUPERVISOR(?:_|$)/i.test(key) || /^RPC_SUPERVISOR_(?:TOKEN|SECRET)/i.test(key)) continue;
|
|
158
|
+
env[key] = value;
|
|
159
|
+
}
|
|
160
|
+
return env;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function defaultAgentDir() {
|
|
164
|
+
return process.env.PI_CODING_AGENT_DIR || path.join(tmpdir(), "pi-agent");
|
|
165
|
+
}
|
package/lib/trust-boundaries.mjs
CHANGED
|
@@ -13,6 +13,7 @@ export const LOCALHOST_ONLY_POST_ROUTES = new Map([
|
|
|
13
13
|
["/api/network/open", "Opening to the network is only allowed from localhost"],
|
|
14
14
|
["/api/network/close", "Closing network access is only allowed from localhost"],
|
|
15
15
|
["/api/remote-auth/settings", "Remote PIN authentication settings are only allowed from localhost"],
|
|
16
|
+
["/api/workflow-policy", "Workflow policy setup is only allowed from localhost"],
|
|
16
17
|
["/api/subagents/config", "Saving subagent launch-slot configuration is only allowed from localhost"],
|
|
17
18
|
["/api/recovery/plan", "Opening recovery plans is only allowed from localhost"],
|
|
18
19
|
["/api/restart", "Restart is only allowed from localhost"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@firstpick/pi-package-webui",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.8",
|
|
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",
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
"pi-webui": "./bin/pi-webui.mjs"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
|
-
"check": "node --check public/app.js && node --check public/fast-output-live.mjs && node --check public/subagent-launch-slot-state.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/subagent-launch-slots.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/issue-wizard-state.mjs && node --check public/issue-bot-client.mjs && node --check public/workflow-status-stack.mjs && node --check public/fast-output-live.mjs && node --check public/subagent-launch-slot-state.mjs && node --check public/subagent-gate-visibility.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 bin/pi-webui-rpc-supervisor.mjs && node --check lib/rpc-supervisor-protocol.mjs && node --check lib/rpc-supervisor-state.mjs && node --check lib/rpc-supervisor-client.mjs && node --check webui-rpc-helper.mjs && node --check lib/subagent-launch-slots.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": {
|
|
58
|
-
"@earendil-works/pi-coding-agent": "^0.82.
|
|
58
|
+
"@earendil-works/pi-coding-agent": "^0.82.1",
|
|
59
59
|
"@firstpick/pi-utils": "^0.2.5",
|
|
60
60
|
"mermaid": "^11.15.0",
|
|
61
61
|
"typebox": "^1.3.6"
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@firstpick/pi-extension-stats": "^0.2.9",
|
|
73
73
|
"@firstpick/pi-extension-todo-progress": "^0.2.9",
|
|
74
74
|
"@firstpick/pi-extension-tools": "^0.1.7",
|
|
75
|
-
"@firstpick/pi-extension-workflows": "^0.1.
|
|
75
|
+
"@firstpick/pi-extension-workflows": "^0.1.7",
|
|
76
76
|
"@firstpick/pi-package-remote-webui": "^0.1.8",
|
|
77
77
|
"@firstpick/pi-prompts-git-pr": "^0.1.5",
|
|
78
78
|
"@firstpick/pi-themes-bundle": "^0.1.5",
|