@firstpick/pi-package-webui 0.6.6 → 0.6.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 +15 -11
- package/bin/pi-webui.mjs +533 -172
- package/lib/WEBUI_TUI_NATIVE_PARITY.json +13 -0
- package/lib/auth-actions.mjs +30 -51
- package/lib/codex-usage-auth.mjs +61 -0
- package/lib/git-command-errors.mjs +68 -0
- package/lib/git-workflow-preferences.mjs +34 -1
- package/lib/native-export-payload.mjs +13 -0
- package/lib/npm-command.mjs +105 -0
- package/lib/process-tree.mjs +53 -0
- package/lib/update-commands.mjs +20 -0
- package/package.json +2 -2
- package/public/app.js +1765 -211
- package/public/index.html +48 -11
- package/public/styles.css +828 -174
- package/tests/app-runner-process-tree-harness.test.mjs +162 -0
- package/tests/codex-usage-auth.test.mjs +65 -0
- package/tests/document-artifact-static.test.mjs +18 -0
- package/tests/fixtures/fake-pi.mjs +72 -2
- package/tests/git-command-errors.test.mjs +42 -0
- package/tests/git-workflow-preferences.test.mjs +14 -2
- package/tests/http-endpoints-harness.test.mjs +182 -0
- package/tests/mobile-static.test.mjs +100 -19
- package/tests/native-export-payload.test.mjs +26 -0
- package/tests/native-parity-harness.test.mjs +1 -1
- package/tests/native-parity.test.mjs +11 -2
- package/tests/npm-command.test.mjs +64 -0
- package/tests/remote-auth-settings-harness.test.mjs +33 -1
- package/tests/resource-defaults-helper.test.mjs +126 -0
- package/tests/session-auth-harness.test.mjs +2 -2
- package/tests/update-commands.test.mjs +44 -0
- package/webui-rpc-helper.mjs +47 -16
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { chmod, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
|
|
10
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
11
|
+
const serverScript = join(root, "bin", "pi-webui.mjs");
|
|
12
|
+
const fakePi = join(root, "tests", "fixtures", "fake-pi.mjs");
|
|
13
|
+
const port = 30000 + Math.floor(Math.random() * 20000);
|
|
14
|
+
|
|
15
|
+
async function request(pathname, { method = "GET", body, timeoutMs = 5_000 } = {}) {
|
|
16
|
+
const response = await fetch(`http://127.0.0.1:${port}${pathname}`, {
|
|
17
|
+
method,
|
|
18
|
+
headers: body === undefined ? undefined : { "content-type": "application/json" },
|
|
19
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
20
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
21
|
+
});
|
|
22
|
+
const payload = await response.json().catch(() => undefined);
|
|
23
|
+
return { status: response.status, body: payload };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function waitFor(description, probe, { attempts = 80, intervalMs = 100 } = {}) {
|
|
27
|
+
let last;
|
|
28
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
29
|
+
last = await probe();
|
|
30
|
+
if (last) return last;
|
|
31
|
+
await delay(intervalMs);
|
|
32
|
+
}
|
|
33
|
+
assert.fail(`${description} did not happen in time${last ? `; last=${JSON.stringify(last)}` : ""}`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isProcessRunning(pid) {
|
|
37
|
+
if (!Number.isInteger(pid) || pid <= 0) return false;
|
|
38
|
+
try {
|
|
39
|
+
process.kill(pid, 0);
|
|
40
|
+
return true;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return error?.code === "EPERM";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function killFixtureProcess(pid) {
|
|
47
|
+
if (!isProcessRunning(pid)) return;
|
|
48
|
+
try {
|
|
49
|
+
process.kill(pid, "SIGKILL");
|
|
50
|
+
} catch {
|
|
51
|
+
// Best-effort cleanup after a failed assertion.
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-app-runner-tree-"));
|
|
56
|
+
const settingsFile = path.join(cwd, "webui-settings.json");
|
|
57
|
+
await chmod(fakePi, 0o755);
|
|
58
|
+
await writeFile(path.join(cwd, "tree-child.mjs"), "setInterval(() => {}, 1000);\n");
|
|
59
|
+
await writeFile(path.join(cwd, "tree-parent.mjs"), [
|
|
60
|
+
"import { spawn } from 'node:child_process';",
|
|
61
|
+
"import { writeFileSync } from 'node:fs';",
|
|
62
|
+
"import { fileURLToPath } from 'node:url';",
|
|
63
|
+
"const childPath = fileURLToPath(new URL('./tree-child.mjs', import.meta.url));",
|
|
64
|
+
"const child = spawn(process.execPath, [childPath], { stdio: 'ignore', windowsHide: true });",
|
|
65
|
+
"writeFileSync('tree-child.pid', `${child.pid}\\n`);",
|
|
66
|
+
"console.log(`tree runner ready ${child.pid}`);",
|
|
67
|
+
"setInterval(() => {}, 1000);",
|
|
68
|
+
"",
|
|
69
|
+
].join("\n"));
|
|
70
|
+
|
|
71
|
+
const server = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "127.0.0.1", "--port", String(port), "--pi", fakePi], {
|
|
72
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
73
|
+
env: {
|
|
74
|
+
...process.env,
|
|
75
|
+
PI_WEBUI_SETTINGS_FILE: settingsFile,
|
|
76
|
+
PI_WEBUI_APP_RUNNER_PTY: "off",
|
|
77
|
+
},
|
|
78
|
+
windowsHide: true,
|
|
79
|
+
});
|
|
80
|
+
let serverOutput = "";
|
|
81
|
+
let runnerPid = 0;
|
|
82
|
+
let treeChildPid = 0;
|
|
83
|
+
server.stdout.on("data", (chunk) => { serverOutput += String(chunk); });
|
|
84
|
+
server.stderr.on("data", (chunk) => { serverOutput += String(chunk); });
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
await waitFor("server health", async () => {
|
|
88
|
+
if (server.exitCode !== null) return false;
|
|
89
|
+
try {
|
|
90
|
+
const health = await request("/api/health", { timeoutMs: 1_000 });
|
|
91
|
+
return health.status === 200 && health.body?.ok === true ? health : false;
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}, { attempts: 100, intervalMs: 120 });
|
|
96
|
+
|
|
97
|
+
const tabsResponse = await request("/api/tabs");
|
|
98
|
+
const tabId = tabsResponse.body?.data?.tabs?.[0]?.id || tabsResponse.body?.tabs?.[0]?.id;
|
|
99
|
+
assert.ok(tabId, `startup tab should exist, output:\n${serverOutput}`);
|
|
100
|
+
|
|
101
|
+
const saved = await request("/api/app-runner-config", {
|
|
102
|
+
method: "POST",
|
|
103
|
+
body: { tab: tabId, runner: { label: "Process tree node", command: process.execPath, path: "tree-parent.mjs" } },
|
|
104
|
+
timeoutMs: 10_000,
|
|
105
|
+
});
|
|
106
|
+
assert.equal(saved.status, 200, `saving a process-tree runner should succeed: ${saved.body?.error || serverOutput}`);
|
|
107
|
+
const runner = saved.body?.data?.runners?.find((item) => item.custom === true && item.label === "Process tree node");
|
|
108
|
+
assert.ok(runner?.id, "process-tree custom runner should appear in detected app runners");
|
|
109
|
+
|
|
110
|
+
let state = await request("/api/app-runner", {
|
|
111
|
+
method: "POST",
|
|
112
|
+
body: { tab: tabId, runnerId: runner.id },
|
|
113
|
+
timeoutMs: 10_000,
|
|
114
|
+
});
|
|
115
|
+
assert.equal(state.status, 200, `process-tree runner should start: ${state.body?.error || serverOutput}`);
|
|
116
|
+
runnerPid = Number(state.body?.data?.activeRun?.pid) || 0;
|
|
117
|
+
|
|
118
|
+
await waitFor("runner parent and child startup", async () => {
|
|
119
|
+
state = await request(`/api/app-runners?tab=${encodeURIComponent(tabId)}`);
|
|
120
|
+
try {
|
|
121
|
+
treeChildPid = Number.parseInt((await readFile(path.join(cwd, "tree-child.pid"), "utf8")).trim(), 10);
|
|
122
|
+
} catch {
|
|
123
|
+
treeChildPid = 0;
|
|
124
|
+
}
|
|
125
|
+
const output = [
|
|
126
|
+
...(state.body?.data?.activeRun?.lines || []),
|
|
127
|
+
state.body?.data?.activeRun?.pendingLine || "",
|
|
128
|
+
].join("\n");
|
|
129
|
+
return isProcessRunning(treeChildPid) && /tree runner ready/.test(output) ? true : false;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const stopped = await request("/api/app-runner/stop", {
|
|
133
|
+
method: "POST",
|
|
134
|
+
body: { tab: tabId },
|
|
135
|
+
timeoutMs: 10_000,
|
|
136
|
+
});
|
|
137
|
+
assert.equal(stopped.status, 200, `process-tree stop should return ok: ${stopped.body?.error || serverOutput}`);
|
|
138
|
+
const stopOutput = (stopped.body?.data?.activeRun?.lines || []).join("\n");
|
|
139
|
+
if (process.platform === "win32") assert.match(stopOutput, /terminating Windows process tree/);
|
|
140
|
+
else assert.match(stopOutput, /sending Ctrl\+C/);
|
|
141
|
+
|
|
142
|
+
await waitFor("runner and descendant termination", async () => {
|
|
143
|
+
state = await request(`/api/app-runners?tab=${encodeURIComponent(tabId)}`);
|
|
144
|
+
const status = state.body?.data?.activeRun?.status;
|
|
145
|
+
return status && status !== "running" && !isProcessRunning(treeChildPid) ? true : false;
|
|
146
|
+
});
|
|
147
|
+
assert.equal(isProcessRunning(treeChildPid), false, "stopping an app runner must not orphan its server child");
|
|
148
|
+
|
|
149
|
+
await request("/api/shutdown", { method: "POST" }).catch(() => undefined);
|
|
150
|
+
for (let attempt = 0; attempt < 50 && server.exitCode === null; attempt += 1) await delay(100);
|
|
151
|
+
assert.notEqual(server.exitCode, null, "server should exit after /api/shutdown");
|
|
152
|
+
console.log("app-runner-process-tree-harness.test.mjs passed");
|
|
153
|
+
} finally {
|
|
154
|
+
if (server.exitCode === null) {
|
|
155
|
+
await request("/api/shutdown", { method: "POST", timeoutMs: 1_000 }).catch(() => undefined);
|
|
156
|
+
for (let attempt = 0; attempt < 20 && server.exitCode === null; attempt += 1) await delay(100);
|
|
157
|
+
if (server.exitCode === null) server.kill("SIGKILL");
|
|
158
|
+
}
|
|
159
|
+
killFixtureProcess(runnerPid);
|
|
160
|
+
killFixtureProcess(treeChildPid);
|
|
161
|
+
await rm(cwd, { recursive: true, force: true });
|
|
162
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { CODEX_TOKEN_REFRESH_SKEW_MS, resolveCodexUsageAuth } from "../lib/codex-usage-auth.mjs";
|
|
4
|
+
|
|
5
|
+
function fakeRuntime(initial, refresh) {
|
|
6
|
+
let credential = structuredClone(initial);
|
|
7
|
+
let tail = Promise.resolve();
|
|
8
|
+
const credentials = {
|
|
9
|
+
async read() { return structuredClone(credential); },
|
|
10
|
+
modify(_providerId, update) {
|
|
11
|
+
const operation = tail.then(async () => {
|
|
12
|
+
const next = await update(structuredClone(credential));
|
|
13
|
+
if (next !== undefined) credential = structuredClone(next);
|
|
14
|
+
return structuredClone(credential);
|
|
15
|
+
});
|
|
16
|
+
tail = operation.then(() => undefined, () => undefined);
|
|
17
|
+
return operation;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
credentials,
|
|
22
|
+
getProvider() { return { auth: { oauth: { refresh } } }; },
|
|
23
|
+
async getAuth() { throw new Error("OAuth tests must not use ordinary auth resolution"); },
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const NOW = 2_000_000_000_000;
|
|
28
|
+
const oauth = (access, expires) => ({ type: "oauth", access, refresh: "fake-refresh", expires, accountId: "acct_test" });
|
|
29
|
+
|
|
30
|
+
test("a 401 forces refresh of an otherwise unexpired Codex credential", async () => {
|
|
31
|
+
let refreshCalls = 0;
|
|
32
|
+
const runtime = fakeRuntime(oauth("rejected", NOW + 60 * 60 * 1000), async (current) => {
|
|
33
|
+
refreshCalls += 1;
|
|
34
|
+
return { ...current, access: "replacement", expires: NOW + 2 * 60 * 60 * 1000 };
|
|
35
|
+
});
|
|
36
|
+
const result = await resolveCodexUsageAuth(runtime, "openai-codex", { forceRefresh: true, now: NOW });
|
|
37
|
+
assert.equal(refreshCalls, 1);
|
|
38
|
+
assert.equal(result.accessToken, "replacement");
|
|
39
|
+
assert.equal(result.refreshed, true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("Codex OAuth refresh uses the five-minute proactive skew", async () => {
|
|
43
|
+
let refreshCalls = 0;
|
|
44
|
+
const nearExpiry = fakeRuntime(oauth("near", NOW + CODEX_TOKEN_REFRESH_SKEW_MS - 1), async (current) => {
|
|
45
|
+
refreshCalls += 1;
|
|
46
|
+
return { ...current, access: "near-refreshed", expires: NOW + 60 * 60 * 1000 };
|
|
47
|
+
});
|
|
48
|
+
assert.equal((await resolveCodexUsageAuth(nearExpiry, "openai-codex", { now: NOW })).accessToken, "near-refreshed");
|
|
49
|
+
assert.equal(refreshCalls, 1);
|
|
50
|
+
|
|
51
|
+
const farExpiry = fakeRuntime(oauth("far", NOW + CODEX_TOKEN_REFRESH_SKEW_MS + 1), async () => {
|
|
52
|
+
refreshCalls += 1;
|
|
53
|
+
throw new Error("must not refresh");
|
|
54
|
+
});
|
|
55
|
+
assert.equal((await resolveCodexUsageAuth(farExpiry, "openai-codex", { now: NOW })).accessToken, "far");
|
|
56
|
+
assert.equal(refreshCalls, 1);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("forced refresh never returns the same rejected credential", async () => {
|
|
60
|
+
const runtime = fakeRuntime(oauth("rejected", NOW + 60 * 60 * 1000), async (current) => ({ ...current }));
|
|
61
|
+
await assert.rejects(
|
|
62
|
+
resolveCodexUsageAuth(runtime, "openai-codex", { forceRefresh: true, now: NOW }),
|
|
63
|
+
/rejected credential/,
|
|
64
|
+
);
|
|
65
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
7
|
+
const [server, app, styles] = await Promise.all([
|
|
8
|
+
readFile(join(root, "bin", "pi-webui.mjs"), "utf8"),
|
|
9
|
+
readFile(join(root, "public", "app.js"), "utf8"),
|
|
10
|
+
readFile(join(root, "public", "styles.css"), "utf8"),
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
for (const contract of ["pi.artifact/v1", "registerDocumentArtifact", "rewriteArtifactsForTab", "documentArtifactRecord", "sendDocumentArtifactFile", "/api/artifacts/"]) assert.ok(server.includes(contract), `server should contain ${contract}`);
|
|
14
|
+
for (const privateField of ["manifestPath", "downloadPath", "outputPath", "sourcePath", "stagedPath", "pdfPath", "workspace", "recoveryPath"]) assert.match(server, new RegExp(`PRIVATE_ARTIFACT_KEYS[^;]+[\\s\\S]*?${privateField}`), `artifact sanitizer should cover ${privateField}`);
|
|
15
|
+
for (const feature of ["openDocumentArtifact", "appendDocumentArtifact", "Send page to composer", "Previous", "Rotate", "Semantic structure, revisions, warnings, and diff"]) assert.ok(app.includes(feature), `browser viewer should contain ${feature}`);
|
|
16
|
+
for (const selector of [".document-artifact-dialog", ".document-artifact-sidebar", ".document-artifact-page", "@media (max-width: 720px)"]) assert.ok(styles.includes(selector), `viewer stylesheet should contain ${selector}`);
|
|
17
|
+
assert.equal(/details\.artifact\s*=/.test(server), false, "server should replace details immutably rather than mutating raw RPC artifacts");
|
|
18
|
+
console.log("document-artifact-static.test.mjs passed");
|
|
@@ -26,6 +26,16 @@ let activeBash = 0;
|
|
|
26
26
|
let peakBash = 0;
|
|
27
27
|
let thinkingLevel = "off";
|
|
28
28
|
let conversationEnabled = false;
|
|
29
|
+
const fakeTools = [
|
|
30
|
+
{ name: "read", description: "Read files", sourceInfo: { source: "builtin", scope: "temporary", origin: "top-level" } },
|
|
31
|
+
{ name: "bash", description: "Run shell commands", sourceInfo: { source: "builtin", scope: "temporary", origin: "top-level" } },
|
|
32
|
+
];
|
|
33
|
+
const fakeSkills = [
|
|
34
|
+
{ name: "repo-explorer", description: "Explore repositories" },
|
|
35
|
+
{ name: "code-security", description: "Review code security" },
|
|
36
|
+
];
|
|
37
|
+
let enabledToolNames = new Set(fakeTools.map((tool) => tool.name));
|
|
38
|
+
let enabledSkillNames = new Set(fakeSkills.map((skill) => skill.name));
|
|
29
39
|
|
|
30
40
|
const voiceScriptsEnabled = process.env.FAKE_PI_VOICE_SCRIPTS === "1";
|
|
31
41
|
const commandLogFile = process.env.FAKE_PI_LOG_FILE || "";
|
|
@@ -202,11 +212,29 @@ function handleWebuiHelperPrompt(command, base) {
|
|
|
202
212
|
respond({ ...base, data: { output: "webui-helper handled" } });
|
|
203
213
|
switch (request.action) {
|
|
204
214
|
case "tools-state":
|
|
205
|
-
respondHelper({ requestId, ok: true, data: { tools:
|
|
215
|
+
respondHelper({ requestId, ok: true, data: { tools: fakeTools.map((tool) => ({ ...tool, enabled: enabledToolNames.has(tool.name) })) } });
|
|
206
216
|
return true;
|
|
217
|
+
case "tools-set": {
|
|
218
|
+
if (Array.isArray(request.payload?.enabledTools)) enabledToolNames = new Set(request.payload.enabledTools.map(String));
|
|
219
|
+
else if (Array.isArray(request.payload?.disabledTools)) {
|
|
220
|
+
const disabled = new Set(request.payload.disabledTools.map(String));
|
|
221
|
+
enabledToolNames = new Set(fakeTools.map((tool) => tool.name).filter((name) => !disabled.has(name)));
|
|
222
|
+
}
|
|
223
|
+
respondHelper({ requestId, ok: true, data: { tools: fakeTools.map((tool) => ({ ...tool, enabled: enabledToolNames.has(tool.name) })) } });
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
207
226
|
case "skills-state":
|
|
208
|
-
respondHelper({ requestId, ok: true, data: { skills:
|
|
227
|
+
respondHelper({ requestId, ok: true, data: { skills: fakeSkills.map((skill) => ({ ...skill, enabled: enabledSkillNames.has(skill.name) })) } });
|
|
209
228
|
return true;
|
|
229
|
+
case "skills-set": {
|
|
230
|
+
if (Array.isArray(request.payload?.enabledSkills)) enabledSkillNames = new Set(request.payload.enabledSkills.map(String));
|
|
231
|
+
else if (Array.isArray(request.payload?.disabledSkills)) {
|
|
232
|
+
const disabled = new Set(request.payload.disabledSkills.map(String));
|
|
233
|
+
enabledSkillNames = new Set(fakeSkills.map((skill) => skill.name).filter((name) => !disabled.has(name)));
|
|
234
|
+
}
|
|
235
|
+
respondHelper({ requestId, ok: true, data: { skills: fakeSkills.map((skill) => ({ ...skill, enabled: enabledSkillNames.has(skill.name) })) } });
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
210
238
|
case "subagent-output":
|
|
211
239
|
respondHelper({
|
|
212
240
|
requestId,
|
|
@@ -240,6 +268,17 @@ function handleWebuiHelperPrompt(command, base) {
|
|
|
240
268
|
}
|
|
241
269
|
}
|
|
242
270
|
|
|
271
|
+
function handleDocumentArtifactFixturePrompt(command, base) {
|
|
272
|
+
const message = String(command.message || "").trim();
|
|
273
|
+
if (message === "fixture document artifact clear") { for (let index = dynamicMessages.length - 1; index >= 0; index--) if (dynamicMessages[index]?.toolName === "docx_render") { dynamicMessages.splice(index, 1); dynamicEntries.splice(index, 1); } dynamicLeafId = dynamicEntries.at(-1)?.id || "u0000002"; respond({ ...base, data: { output: "fake document artifacts cleared" } }); return true; }
|
|
274
|
+
if (message !== "fixture document artifact" || !process.env.FAKE_PI_ARTIFACT_MANIFEST) return false;
|
|
275
|
+
const toolCallId = `artifact-${randomUUID()}`, artifact = { schema: "pi.artifact/v1", kind: "document", id: "fixture-document-artifact", revisionId: "fixture-revision", title: "fixture.docx", mimeType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", pageCount: 1, manifestPath: process.env.FAKE_PI_ARTIFACT_MANIFEST, downloadPath: process.env.FAKE_PI_ARTIFACT_DOWNLOAD, expiresAt: new Date(Date.now() + 60 * 60 * 1000).toISOString() }, result = { content: [{ type: "text", text: "Rendered fixture document" }], details: { artifact } };
|
|
276
|
+
appendDynamicMessage({ role: "toolResult", toolCallId, toolName: "docx_render", content: result.content, details: result.details, isError: false, timestamp: Date.now() });
|
|
277
|
+
respond({ ...base, data: { output: "fake document artifact emitted" } });
|
|
278
|
+
emitEvent({ type: "tool_execution_end", toolCallId, toolName: "docx_render", isError: false, result });
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
|
|
243
282
|
function handleSubagentFixturePrompt(command, base) {
|
|
244
283
|
const message = String(command.message || "").trim();
|
|
245
284
|
if (message !== "fixture subagents running" && message !== "fixture subagents clear") return false;
|
|
@@ -265,6 +304,34 @@ function handleSubagentFixturePrompt(command, base) {
|
|
|
265
304
|
return true;
|
|
266
305
|
}
|
|
267
306
|
|
|
307
|
+
function handleWorkflowFixturePrompt(command, base) {
|
|
308
|
+
const message = String(command.message || "").trim();
|
|
309
|
+
if (!/^fixture workflow inspector (running|completed|clear)$/.test(message)) return false;
|
|
310
|
+
const status = message.split(" ").at(-1);
|
|
311
|
+
const now = new Date().toISOString();
|
|
312
|
+
const runs = status === "clear" ? [] : [{
|
|
313
|
+
runId: "fixture-workflow-run",
|
|
314
|
+
workflowKey: "fixture-workflow",
|
|
315
|
+
workflowName: "Fixture Workflow",
|
|
316
|
+
status,
|
|
317
|
+
sourceType: "javascript",
|
|
318
|
+
input: { topic: "rpc" },
|
|
319
|
+
script: "export const meta = { name: 'fixture-workflow', description: 'Fixture Workflow' }\nreturn 1",
|
|
320
|
+
startedAt: now,
|
|
321
|
+
updatedAt: now,
|
|
322
|
+
...(status === "completed" ? { finishedAt: now, result: "fixture complete" } : {}),
|
|
323
|
+
phases: [{
|
|
324
|
+
phaseId: "audit", name: "Audit", status,
|
|
325
|
+
agents: [{ callId: "fixture-call", callIndex: 1, taskId: "inspect", label: "inspect", name: "Inspect", status, prompt: "Inspect fixture", options: { tools: ["read"] }, recentEvents: [{ type: "stdout", timestamp: now, line: "read fixture" }], ...(status === "completed" ? { result: "inspected", usage: { input: 2, output: 1 } } : {}) }],
|
|
326
|
+
}],
|
|
327
|
+
controls: { canPause: status === "running", canResume: status === "completed", canAbort: status === "running", canRetry: status === "completed", canSave: status === "completed" },
|
|
328
|
+
}];
|
|
329
|
+
const payload = { type: "firstpick.pi-extension-workflows.inspector", version: 1, updatedAt: now, mode: { enabled: true, behavior: "persistent", phase: "armed" }, runs };
|
|
330
|
+
respond({ ...base, data: { output: `fake workflow inspector ${status} emitted` } });
|
|
331
|
+
emitEvent({ type: "extension_ui_request", id: randomUUID(), method: "setWidget", widgetKey: "workflow:rpc", widgetLines: [`WORKFLOW_RPC_PAYLOAD ${JSON.stringify(payload)}`] });
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
|
|
268
335
|
function handleTalkPrompt(command, base) {
|
|
269
336
|
const message = String(command.message || "").trim();
|
|
270
337
|
const match = message.match(/^\/(talk|voice|conversation)(?:\s+(\S+))?/i);
|
|
@@ -344,6 +411,7 @@ rl.on("line", (line) => {
|
|
|
344
411
|
{ name: "talk", source: "extension", description: "Toggle Natural Conversation Mode" },
|
|
345
412
|
{ name: "voice", source: "extension", description: "Natural Conversation Mode alias" },
|
|
346
413
|
{ name: "conversation", source: "extension", description: "Natural Conversation Mode alias" },
|
|
414
|
+
{ name: "workflow", source: "extension", description: "Run and inspect JavaScript workflows" },
|
|
347
415
|
],
|
|
348
416
|
},
|
|
349
417
|
});
|
|
@@ -368,6 +436,8 @@ rl.on("line", (line) => {
|
|
|
368
436
|
case "prompt":
|
|
369
437
|
if (handleWebuiHelperPrompt(command, base)) return;
|
|
370
438
|
if (handleSubagentFixturePrompt(command, base)) return;
|
|
439
|
+
if (handleDocumentArtifactFixturePrompt(command, base)) return;
|
|
440
|
+
if (handleWorkflowFixturePrompt(command, base)) return;
|
|
371
441
|
if (handleTalkPrompt(command, base)) return;
|
|
372
442
|
if (handleVoiceScriptPrompt(command, base)) return;
|
|
373
443
|
respond({ ...base, data: { output: "fake prompt accepted" } });
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import {
|
|
3
|
+
classifyGitPathFailure,
|
|
4
|
+
classifyWindowsReservedGitPath,
|
|
5
|
+
findWindowsReservedGitPath,
|
|
6
|
+
windowsReservedGitPathFailure,
|
|
7
|
+
} from "../lib/git-command-errors.mjs";
|
|
8
|
+
|
|
9
|
+
assert.deepEqual(classifyWindowsReservedGitPath("NUL"), {
|
|
10
|
+
path: "NUL",
|
|
11
|
+
component: "NUL",
|
|
12
|
+
deviceName: "NUL",
|
|
13
|
+
});
|
|
14
|
+
assert.deepEqual(classifyWindowsReservedGitPath("nested/aux.txt"), {
|
|
15
|
+
path: "nested/aux.txt",
|
|
16
|
+
component: "aux.txt",
|
|
17
|
+
deviceName: "AUX",
|
|
18
|
+
});
|
|
19
|
+
assert.equal(classifyWindowsReservedGitPath("frontend/null-state.ts"), null);
|
|
20
|
+
assert.equal(classifyWindowsReservedGitPath("COM10.log"), null);
|
|
21
|
+
assert.equal(findWindowsReservedGitPath(["normal.txt", "nested/LPT1.log", "later.txt"])?.path, "nested/LPT1.log");
|
|
22
|
+
assert.equal(findWindowsReservedGitPath("normal.txt\0folder/PRN\0")?.path, "folder/PRN");
|
|
23
|
+
|
|
24
|
+
const exactFailure = classifyGitPathFailure({
|
|
25
|
+
exitCode: 128,
|
|
26
|
+
stderr: [
|
|
27
|
+
"error: short read while indexing NUL",
|
|
28
|
+
"error: NUL: failed to insert into database",
|
|
29
|
+
"error: unable to index file 'NUL'",
|
|
30
|
+
"fatal: adding files failed",
|
|
31
|
+
].join("\n"),
|
|
32
|
+
});
|
|
33
|
+
assert.equal(exactFailure?.code, "INVALID_WORKTREE_PATH");
|
|
34
|
+
assert.equal(exactFailure?.error, 'Git cannot index the Windows-reserved path "NUL".');
|
|
35
|
+
assert.match(exactFailure?.hint || "", /Delete or rename "NUL"/);
|
|
36
|
+
assert.match(exactFailure?.hint || "", /earlier failed git add may already have staged files/);
|
|
37
|
+
|
|
38
|
+
assert.equal(classifyGitPathFailure({ exitCode: 128, stderr: "fatal: not a git repository" }), null);
|
|
39
|
+
assert.equal(classifyGitPathFailure({ exitCode: 1, stderr: "error: unable to index file 'ordinary.txt'" }), null);
|
|
40
|
+
assert.equal(windowsReservedGitPathFailure("ordinary.txt"), null);
|
|
41
|
+
|
|
42
|
+
console.log("git command error tests passed");
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
readWebuiSettings,
|
|
11
11
|
supportedGitWorkflowThinkingLevels,
|
|
12
12
|
writeGitWorkflowPreferences,
|
|
13
|
+
writeWebuiSettings,
|
|
13
14
|
} from "../lib/git-workflow-preferences.mjs";
|
|
14
15
|
|
|
15
16
|
assert.deepEqual(supportedGitWorkflowThinkingLevels({ reasoning: false }), ["off"]);
|
|
@@ -30,9 +31,11 @@ const settingsFile = path.join(root, "settings.json");
|
|
|
30
31
|
try {
|
|
31
32
|
await writeFile(settingsFile, `${JSON.stringify({ version: 1, remoteAuthEnabled: true }, null, 2)}\n`, "utf8");
|
|
32
33
|
const migrated = await readWebuiSettings(settingsFile);
|
|
33
|
-
assert.equal(migrated.version,
|
|
34
|
+
assert.equal(migrated.version, 3);
|
|
34
35
|
assert.equal(migrated.remoteAuthEnabled, true, "legacy Remote PIN state should survive schema migration");
|
|
35
36
|
assert.equal(isGitWorkflowSetupComplete(migrated.gitWorkflow), false);
|
|
37
|
+
assert.equal(migrated.resourceDefaults.tools.enabledTools, null, "legacy settings should inherit Pi's normal tool defaults");
|
|
38
|
+
assert.equal(migrated.resourceDefaults.skills.enabledSkills, null, "legacy settings should inherit Pi's normal skill defaults");
|
|
36
39
|
assert.equal(migrated.gitWorkflow.stagingPolicy, "review");
|
|
37
40
|
assert.equal(migrated.gitWorkflow.generation.thinkingLevel, "low");
|
|
38
41
|
|
|
@@ -49,15 +52,24 @@ try {
|
|
|
49
52
|
assert.equal(saved.commit.defaultVariant, "long");
|
|
50
53
|
assert.equal(saved.stagingPolicy, "preserve");
|
|
51
54
|
|
|
55
|
+
await writeWebuiSettings({
|
|
56
|
+
resourceDefaults: {
|
|
57
|
+
tools: { enabledTools: ["read", " write ", "read", ""] },
|
|
58
|
+
skills: { enabledSkills: ["repo-explorer", "code-security"] },
|
|
59
|
+
},
|
|
60
|
+
}, settingsFile);
|
|
61
|
+
|
|
52
62
|
const partiallyUpdated = await writeGitWorkflowPreferences({ deliveryMode: "current" }, settingsFile);
|
|
53
63
|
assert.equal(partiallyUpdated.generation.modelId, "fake-model", "partial updates should preserve the selected model");
|
|
54
64
|
assert.equal(partiallyUpdated.commit.language, "de", "partial updates should preserve nested commit preferences");
|
|
55
65
|
assert.equal(partiallyUpdated.deliveryMode, "current");
|
|
56
66
|
|
|
57
67
|
const persisted = JSON.parse(await readFile(settingsFile, "utf8"));
|
|
58
|
-
assert.equal(persisted.version,
|
|
68
|
+
assert.equal(persisted.version, 3);
|
|
59
69
|
assert.equal(persisted.remoteAuthEnabled, true);
|
|
60
70
|
assert.equal(persisted.gitWorkflow.generation.provider, "fake");
|
|
71
|
+
assert.deepEqual(persisted.resourceDefaults.tools.enabledTools, ["read", "write"], "global tool defaults should be normalized and deduplicated");
|
|
72
|
+
assert.deepEqual(persisted.resourceDefaults.skills.enabledSkills, ["repo-explorer", "code-security"], "global skill defaults should persist beside other Web UI settings");
|
|
61
73
|
assert.match(gitWorkflowPreferencesSummary(await readGitWorkflowPreferences(settingsFile)), /fake\/fake-model/);
|
|
62
74
|
if (process.platform !== "win32") assert.equal((await stat(settingsFile)).mode & 0o777, 0o600);
|
|
63
75
|
|