@firstpick/pi-package-webui 0.6.7 → 0.6.9
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 +14 -9
- package/bin/pi-webui.mjs +477 -157
- 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/trust-boundaries.mjs +1 -0
- package/package.json +8 -8
- package/public/app.js +1864 -238
- package/public/index.html +217 -102
- package/public/service-worker.js +1 -1
- package/public/styles.css +1144 -209
- package/tests/app-runner-process-tree-harness.test.mjs +162 -0
- package/tests/codex-usage-auth.test.mjs +65 -0
- package/tests/fixtures/fake-pi.mjs +77 -3
- 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 +240 -3
- package/tests/mobile-static.test.mjs +138 -27
- 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/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
|
+
});
|
|
@@ -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 || "";
|
|
@@ -79,6 +89,12 @@ function logJsonLine(entry) {
|
|
|
79
89
|
}
|
|
80
90
|
}
|
|
81
91
|
|
|
92
|
+
logJsonLine({
|
|
93
|
+
direction: "startup",
|
|
94
|
+
recoveryUrl: String(process.env.PI_WEBUI_RECOVERY_URL || ""),
|
|
95
|
+
recoveryTokenConfigured: Boolean(process.env.PI_WEBUI_RECOVERY_TOKEN),
|
|
96
|
+
});
|
|
97
|
+
|
|
82
98
|
function respond(payload) {
|
|
83
99
|
process.stdout.write(`${JSON.stringify(payload)}\n`);
|
|
84
100
|
}
|
|
@@ -202,11 +218,29 @@ function handleWebuiHelperPrompt(command, base) {
|
|
|
202
218
|
respond({ ...base, data: { output: "webui-helper handled" } });
|
|
203
219
|
switch (request.action) {
|
|
204
220
|
case "tools-state":
|
|
205
|
-
respondHelper({ requestId, ok: true, data: { tools:
|
|
221
|
+
respondHelper({ requestId, ok: true, data: { tools: fakeTools.map((tool) => ({ ...tool, enabled: enabledToolNames.has(tool.name) })) } });
|
|
206
222
|
return true;
|
|
223
|
+
case "tools-set": {
|
|
224
|
+
if (Array.isArray(request.payload?.enabledTools)) enabledToolNames = new Set(request.payload.enabledTools.map(String));
|
|
225
|
+
else if (Array.isArray(request.payload?.disabledTools)) {
|
|
226
|
+
const disabled = new Set(request.payload.disabledTools.map(String));
|
|
227
|
+
enabledToolNames = new Set(fakeTools.map((tool) => tool.name).filter((name) => !disabled.has(name)));
|
|
228
|
+
}
|
|
229
|
+
respondHelper({ requestId, ok: true, data: { tools: fakeTools.map((tool) => ({ ...tool, enabled: enabledToolNames.has(tool.name) })) } });
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
207
232
|
case "skills-state":
|
|
208
|
-
respondHelper({ requestId, ok: true, data: { skills:
|
|
233
|
+
respondHelper({ requestId, ok: true, data: { skills: fakeSkills.map((skill) => ({ ...skill, enabled: enabledSkillNames.has(skill.name) })) } });
|
|
234
|
+
return true;
|
|
235
|
+
case "skills-set": {
|
|
236
|
+
if (Array.isArray(request.payload?.enabledSkills)) enabledSkillNames = new Set(request.payload.enabledSkills.map(String));
|
|
237
|
+
else if (Array.isArray(request.payload?.disabledSkills)) {
|
|
238
|
+
const disabled = new Set(request.payload.disabledSkills.map(String));
|
|
239
|
+
enabledSkillNames = new Set(fakeSkills.map((skill) => skill.name).filter((name) => !disabled.has(name)));
|
|
240
|
+
}
|
|
241
|
+
respondHelper({ requestId, ok: true, data: { skills: fakeSkills.map((skill) => ({ ...skill, enabled: enabledSkillNames.has(skill.name) })) } });
|
|
209
242
|
return true;
|
|
243
|
+
}
|
|
210
244
|
case "subagent-output":
|
|
211
245
|
respondHelper({
|
|
212
246
|
requestId,
|
|
@@ -276,6 +310,34 @@ function handleSubagentFixturePrompt(command, base) {
|
|
|
276
310
|
return true;
|
|
277
311
|
}
|
|
278
312
|
|
|
313
|
+
function handleWorkflowFixturePrompt(command, base) {
|
|
314
|
+
const message = String(command.message || "").trim();
|
|
315
|
+
if (!/^fixture workflow inspector (running|completed|clear)$/.test(message)) return false;
|
|
316
|
+
const status = message.split(" ").at(-1);
|
|
317
|
+
const now = new Date().toISOString();
|
|
318
|
+
const runs = status === "clear" ? [] : [{
|
|
319
|
+
runId: "fixture-workflow-run",
|
|
320
|
+
workflowKey: "fixture-workflow",
|
|
321
|
+
workflowName: "Fixture Workflow",
|
|
322
|
+
status,
|
|
323
|
+
sourceType: "javascript",
|
|
324
|
+
input: { topic: "rpc" },
|
|
325
|
+
script: "export const meta = { name: 'fixture-workflow', description: 'Fixture Workflow' }\nreturn 1",
|
|
326
|
+
startedAt: now,
|
|
327
|
+
updatedAt: now,
|
|
328
|
+
...(status === "completed" ? { finishedAt: now, result: "fixture complete" } : {}),
|
|
329
|
+
phases: [{
|
|
330
|
+
phaseId: "audit", name: "Audit", status,
|
|
331
|
+
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 } } : {}) }],
|
|
332
|
+
}],
|
|
333
|
+
controls: { canPause: status === "running", canResume: status === "completed", canAbort: status === "running", canRetry: status === "completed", canSave: status === "completed" },
|
|
334
|
+
}];
|
|
335
|
+
const payload = { type: "firstpick.pi-extension-workflows.inspector", version: 1, updatedAt: now, mode: { enabled: true, behavior: "persistent", phase: "armed" }, runs };
|
|
336
|
+
respond({ ...base, data: { output: `fake workflow inspector ${status} emitted` } });
|
|
337
|
+
emitEvent({ type: "extension_ui_request", id: randomUUID(), method: "setWidget", widgetKey: "workflow:rpc", widgetLines: [`WORKFLOW_RPC_PAYLOAD ${JSON.stringify(payload)}`] });
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
|
|
279
341
|
function handleTalkPrompt(command, base) {
|
|
280
342
|
const message = String(command.message || "").trim();
|
|
281
343
|
const match = message.match(/^\/(talk|voice|conversation)(?:\s+(\S+))?/i);
|
|
@@ -311,7 +373,13 @@ rl.on("line", (line) => {
|
|
|
311
373
|
}
|
|
312
374
|
const { id, type } = command || {};
|
|
313
375
|
if (!id || !type) return;
|
|
314
|
-
logJsonLine({
|
|
376
|
+
logJsonLine({
|
|
377
|
+
direction: "command",
|
|
378
|
+
type,
|
|
379
|
+
...(command.message !== undefined ? { message: String(command.message) } : {}),
|
|
380
|
+
...(command.provider !== undefined ? { provider: String(command.provider) } : {}),
|
|
381
|
+
...(command.modelId !== undefined ? { modelId: String(command.modelId) } : {}),
|
|
382
|
+
});
|
|
315
383
|
const base = { type: "response", id, command: type, success: true };
|
|
316
384
|
|
|
317
385
|
switch (type) {
|
|
@@ -355,6 +423,7 @@ rl.on("line", (line) => {
|
|
|
355
423
|
{ name: "talk", source: "extension", description: "Toggle Natural Conversation Mode" },
|
|
356
424
|
{ name: "voice", source: "extension", description: "Natural Conversation Mode alias" },
|
|
357
425
|
{ name: "conversation", source: "extension", description: "Natural Conversation Mode alias" },
|
|
426
|
+
{ name: "workflow", source: "extension", description: "Run and inspect JavaScript workflows" },
|
|
358
427
|
],
|
|
359
428
|
},
|
|
360
429
|
});
|
|
@@ -380,6 +449,7 @@ rl.on("line", (line) => {
|
|
|
380
449
|
if (handleWebuiHelperPrompt(command, base)) return;
|
|
381
450
|
if (handleSubagentFixturePrompt(command, base)) return;
|
|
382
451
|
if (handleDocumentArtifactFixturePrompt(command, base)) return;
|
|
452
|
+
if (handleWorkflowFixturePrompt(command, base)) return;
|
|
383
453
|
if (handleTalkPrompt(command, base)) return;
|
|
384
454
|
if (handleVoiceScriptPrompt(command, base)) return;
|
|
385
455
|
respond({ ...base, data: { output: "fake prompt accepted" } });
|
|
@@ -391,6 +461,10 @@ rl.on("line", (line) => {
|
|
|
391
461
|
thinkingLevel = String(command.level || "off");
|
|
392
462
|
respond({ ...base, data: { level: thinkingLevel } });
|
|
393
463
|
return;
|
|
464
|
+
case "set_model":
|
|
465
|
+
if (command.modelId === "missing-model") respond({ ...base, success: false, error: "Model not found: fake/missing-model" });
|
|
466
|
+
else respond({ ...base, data: { provider: command.provider, id: command.modelId } });
|
|
467
|
+
return;
|
|
394
468
|
case "get_available_models":
|
|
395
469
|
respond({ ...base, data: { models: [{ provider: "fake", id: "fake-model", name: "Fake Model" }] } });
|
|
396
470
|
return;
|
|
@@ -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
|
|