@firstpick/pi-package-webui 0.6.2 → 0.6.4
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 +6 -1
- package/bin/pi-webui.mjs +908 -14
- package/lib/trust-boundaries.mjs +2 -0
- package/package.json +11 -7
- package/public/app.js +1259 -12
- package/public/index.html +80 -2
- package/public/styles.css +488 -15
- package/tests/fixtures/fake-pi.mjs +59 -3
- package/tests/http-endpoints-harness.test.mjs +212 -2
- package/tests/mobile-static.test.mjs +41 -6
- package/tests/native-parity.test.mjs +1 -0
- package/webui-rpc-helper.mjs +29 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { spawn, spawnSync } from "node:child_process";
|
|
3
3
|
import { createServer } from "node:http";
|
|
4
|
-
import { chmod, mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import { chmod, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
|
|
5
5
|
import { networkInterfaces, tmpdir } from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { setTimeout as delay } from "node:timers/promises";
|
|
@@ -70,8 +70,19 @@ function runGitFixture(args, cwd, message) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-http-harness-"));
|
|
73
|
-
const
|
|
73
|
+
const harnessSideEffectsRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-http-harness-side-effects-"));
|
|
74
|
+
const settingsFile = path.join(harnessSideEffectsRoot, "webui-settings.json");
|
|
75
|
+
const openCommandLog = path.join(harnessSideEffectsRoot, "open-default.log");
|
|
76
|
+
const openCommandScript = path.join(harnessSideEffectsRoot, "fake-open-default.mjs");
|
|
77
|
+
const fakeOpenBinDir = path.join(harnessSideEffectsRoot, "bin");
|
|
74
78
|
await chmod(fakePi, 0o755);
|
|
79
|
+
await mkdir(fakeOpenBinDir, { recursive: true });
|
|
80
|
+
await writeFile(openCommandScript, `#!/usr/bin/env node\nimport { appendFile } from "node:fs/promises";\nawait appendFile(process.env.PI_WEBUI_OPEN_LOG, "custom-open\\t" + process.argv.slice(2).join("\\t") + "\\n", "utf8");\n`, "utf8");
|
|
81
|
+
await chmod(openCommandScript, 0o755);
|
|
82
|
+
await writeFile(path.join(fakeOpenBinDir, "xdg-open"), `#!/usr/bin/env node\nimport { appendFile } from "node:fs/promises";\nawait appendFile(process.env.PI_WEBUI_OPEN_LOG, "xdg-open\\t" + process.argv.slice(2).join("\\t") + "\\n", "utf8");\n`, "utf8");
|
|
83
|
+
await writeFile(path.join(fakeOpenBinDir, "gio"), `#!/usr/bin/env node\nimport { appendFile } from "node:fs/promises";\nawait appendFile(process.env.PI_WEBUI_OPEN_LOG, "gio\\t" + process.argv.slice(2).join("\\t") + "\\n", "utf8");\n`, "utf8");
|
|
84
|
+
await writeFile(path.join(fakeOpenBinDir, "xdg-mime"), `#!/usr/bin/env node\nconst [,, verb, mode, value = ""] = process.argv;\nif (verb === "query" && mode === "filetype") {\n if (value.endsWith(".piunknown")) console.log("application/x-pi-unknown");\n else if (value.endsWith(".md")) console.log("text/markdown");\n else console.log("text/plain");\n process.exit(0);\n}\nif (verb === "query" && mode === "default") {\n if (value === "text/plain") console.log("fake-text-editor.desktop");\n process.exit(0);\n}\nprocess.exit(1);\n`, "utf8");
|
|
85
|
+
await Promise.all(["xdg-open", "gio", "xdg-mime"].map((name) => chmod(path.join(fakeOpenBinDir, name), 0o755)));
|
|
75
86
|
|
|
76
87
|
const voiceProviderRequests = [];
|
|
77
88
|
const voiceProvider = createServer(async (req, res) => {
|
|
@@ -103,7 +114,12 @@ const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "0.
|
|
|
103
114
|
GIT_AUTHOR_EMAIL: "pi-webui-test@example.invalid",
|
|
104
115
|
GIT_COMMITTER_NAME: "Pi WebUI Test",
|
|
105
116
|
GIT_COMMITTER_EMAIL: "pi-webui-test@example.invalid",
|
|
117
|
+
PATH: `${fakeOpenBinDir}${path.delimiter}${process.env.PATH || ""}`,
|
|
118
|
+
PI_CODING_AGENT_DIR: path.join(harnessSideEffectsRoot, "agent"),
|
|
106
119
|
PI_WEBUI_SETTINGS_FILE: settingsFile,
|
|
120
|
+
...(process.platform === "linux" ? {} : { PI_WEBUI_OPEN_COMMAND: openCommandScript }),
|
|
121
|
+
PI_WEBUI_OPEN_LOG: openCommandLog,
|
|
122
|
+
FAKE_PI_VOICE_SCRIPTS: "1",
|
|
107
123
|
PI_VOICE_STT_URL: `http://127.0.0.1:${voiceProviderPort}/stt`,
|
|
108
124
|
PI_VOICE_TTS_URL: `http://127.0.0.1:${voiceProviderPort}/tts`,
|
|
109
125
|
},
|
|
@@ -201,6 +217,45 @@ try {
|
|
|
201
217
|
assert.equal(state.status, 200);
|
|
202
218
|
assert.equal(state.body?.data?.model?.provider, "fake", "state should come from the fake pi RPC");
|
|
203
219
|
|
|
220
|
+
const forkSourceTab = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd, title: "fork-running-source" } });
|
|
221
|
+
assert.equal(forkSourceTab.status, 201, `fork source tab should open: ${forkSourceTab.body?.error || ""}`);
|
|
222
|
+
const forkSourceTabId = forkSourceTab.body?.data?.tab?.id;
|
|
223
|
+
assert.ok(forkSourceTabId, "fork source tab should have an id");
|
|
224
|
+
const runningPrompt = "voice test slow fork fixture";
|
|
225
|
+
const runningPromptResponse = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { message: runningPrompt, tab: forkSourceTabId }, timeoutMs: 10_000 });
|
|
226
|
+
assert.equal(runningPromptResponse.status, 200, `slow scripted prompt should start: ${runningPromptResponse.body?.error || ""}`);
|
|
227
|
+
let streamingState;
|
|
228
|
+
for (let attempt = 0; attempt < 30; attempt++) {
|
|
229
|
+
streamingState = await request("127.0.0.1", `/api/state?tab=${encodeURIComponent(forkSourceTabId)}`);
|
|
230
|
+
if (streamingState.body?.data?.isStreaming === true) break;
|
|
231
|
+
await delay(100);
|
|
232
|
+
}
|
|
233
|
+
assert.equal(streamingState?.body?.data?.isStreaming, true, "source tab should still be running before fork");
|
|
234
|
+
const forkMessagesWhileRunning = await request("127.0.0.1", `/api/fork-messages?tab=${encodeURIComponent(forkSourceTabId)}`);
|
|
235
|
+
assert.equal(forkMessagesWhileRunning.status, 200, "fork selector data should load while the source tab is running");
|
|
236
|
+
const runningForkPoint = (forkMessagesWhileRunning.body?.data?.messages || []).find((item) => item.text === runningPrompt);
|
|
237
|
+
assert.ok(runningForkPoint?.entryId, "running prompt should be available as a fork point");
|
|
238
|
+
const forkWhileRunning = await request("127.0.0.1", "/api/fork", { method: "POST", body: { tab: forkSourceTabId, entryId: runningForkPoint.entryId }, timeoutMs: 10_000 });
|
|
239
|
+
assert.equal(forkWhileRunning.status, 200, `fork while running should succeed: ${forkWhileRunning.body?.error || ""}`);
|
|
240
|
+
const forkedTabId = forkWhileRunning.body?.data?.tab?.id;
|
|
241
|
+
assert.ok(forkedTabId, "fork response should include the opened fork tab");
|
|
242
|
+
assert.notEqual(forkedTabId, forkSourceTabId, "forking should create a new tab instead of replacing the running source tab");
|
|
243
|
+
assert.equal(forkWhileRunning.body?.data?.text, runningPrompt, "fork response should restore the selected prompt text for editing");
|
|
244
|
+
assert.ok((forkWhileRunning.body?.data?.tabs || []).some((tab) => tab.id === forkSourceTabId), "fork response should keep the original running tab in the tab list");
|
|
245
|
+
assert.ok((forkWhileRunning.body?.data?.tabs || []).some((tab) => tab.id === forkedTabId), "fork response should include the new fork tab in the tab list");
|
|
246
|
+
assert.match(String(forkWhileRunning.body?.data?.sessionFile || ""), /\.jsonl$/, "fork response should include the new session file");
|
|
247
|
+
const forkSessionContent = await readFile(forkWhileRunning.body.data.sessionFile, "utf8");
|
|
248
|
+
assert.match(forkSessionContent, /"type":"session"/, "forked session file should be written before opening its tab");
|
|
249
|
+
const sourceAfterFork = await request("127.0.0.1", `/api/state?tab=${encodeURIComponent(forkSourceTabId)}`);
|
|
250
|
+
assert.equal(sourceAfterFork.status, 200, "source tab should still respond after forking");
|
|
251
|
+
for (let attempt = 0; attempt < 40 && sourceAfterFork.body?.data?.isStreaming; attempt++) {
|
|
252
|
+
const next = await request("127.0.0.1", `/api/state?tab=${encodeURIComponent(forkSourceTabId)}`);
|
|
253
|
+
if (!next.body?.data?.isStreaming) break;
|
|
254
|
+
await delay(100);
|
|
255
|
+
}
|
|
256
|
+
const closeForkTestTabs = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [forkSourceTabId, forkedTabId] }, timeoutMs: 10_000 });
|
|
257
|
+
assert.equal(closeForkTestTabs.status, 200, "fork test tabs should close before continuing baseline endpoint checks");
|
|
258
|
+
|
|
204
259
|
const gitAvailable = spawnSync("git", ["--version"], { encoding: "utf8" }).status === 0;
|
|
205
260
|
if (gitAvailable) {
|
|
206
261
|
const gitInit = await request("127.0.0.1", "/api/git-workflow/init", { method: "POST", body: { tab: tabId } });
|
|
@@ -694,6 +749,144 @@ try {
|
|
|
694
749
|
assert.equal(copy.body?.data?.status, "succeeded", "native /copy should succeed through the adapter");
|
|
695
750
|
assert.equal(copy.body?.data?.copyText, "fake last text");
|
|
696
751
|
|
|
752
|
+
// File tree/viewer APIs stay scoped to the requested tab cwd and reject unsafe content.
|
|
753
|
+
const filesRoot = path.join(cwd, "files-fixture");
|
|
754
|
+
const viewerRelative = "files-fixture/viewer.txt";
|
|
755
|
+
const markdownRelative = "files-fixture/docs/readme.md";
|
|
756
|
+
const binaryRelative = "files-fixture/binary.bin";
|
|
757
|
+
const noDefaultRelative = "files-fixture/no-default.piunknown";
|
|
758
|
+
const largeRelative = "files-fixture/large.txt";
|
|
759
|
+
const depthEightFileRelative = "deep-search/f1/f2/f3/f4/f5/f6/depth-eight-file.txt";
|
|
760
|
+
const depthEightDirectoryRelative = "deep-search/d1/d2/d3/d4/d5/d6/depth-eight-dir";
|
|
761
|
+
const depthNineFileRelative = "deep-search/t1/t2/t3/t4/t5/t6/t7/too-deep-file.txt";
|
|
762
|
+
await mkdir(path.join(filesRoot, "docs"), { recursive: true });
|
|
763
|
+
await mkdir(path.join(cwd, path.dirname(depthEightFileRelative)), { recursive: true });
|
|
764
|
+
await mkdir(path.join(cwd, depthEightDirectoryRelative), { recursive: true });
|
|
765
|
+
await mkdir(path.join(cwd, path.dirname(depthNineFileRelative)), { recursive: true });
|
|
766
|
+
await writeFile(path.join(cwd, viewerRelative), "hello file viewer\nsecond line\n", "utf8");
|
|
767
|
+
await writeFile(path.join(cwd, markdownRelative), "# File Viewer\n\nMarkdown preview support.\n", "utf8");
|
|
768
|
+
await writeFile(path.join(cwd, noDefaultRelative), "unknown extension should use text/plain editor fallback\n", "utf8");
|
|
769
|
+
await writeFile(path.join(cwd, depthEightFileRelative), "depth 8 search fixture\n", "utf8");
|
|
770
|
+
await writeFile(path.join(cwd, depthNineFileRelative), "depth 9 search fixture\n", "utf8");
|
|
771
|
+
await writeFile(path.join(cwd, binaryRelative), Buffer.from([0, 1, 2, 3]));
|
|
772
|
+
await writeFile(path.join(cwd, largeRelative), Buffer.alloc(2 * 1024 * 1024 + 1, 0x61));
|
|
773
|
+
|
|
774
|
+
const fileTree = await request("127.0.0.1", `/api/files?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent("files-fixture")}`);
|
|
775
|
+
assert.equal(fileTree.status, 200, `file tree endpoint should list workspace directories: ${fileTree.body?.error || ""}`);
|
|
776
|
+
assert.equal(fileTree.body?.ok, true);
|
|
777
|
+
const fileTreeEntries = fileTree.body?.data?.entries || [];
|
|
778
|
+
assert.equal(fileTreeEntries.find((entry) => entry.name === "docs")?.type, "directory", "file tree should identify subdirectories");
|
|
779
|
+
assert.equal(fileTreeEntries.find((entry) => entry.name === "viewer.txt")?.type, "file", "file tree should identify regular files");
|
|
780
|
+
|
|
781
|
+
const fileSearch = await request("127.0.0.1", `/api/files/search?tab=${encodeURIComponent(tabId)}&q=${encodeURIComponent("readme")}`);
|
|
782
|
+
assert.equal(fileSearch.status, 200, `file search endpoint should search workspace files: ${fileSearch.body?.error || ""}`);
|
|
783
|
+
assert.equal(fileSearch.body?.ok, true);
|
|
784
|
+
const fileSearchEntries = fileSearch.body?.data?.entries || [];
|
|
785
|
+
assert.equal(fileSearchEntries.find((entry) => entry.path === markdownRelative)?.type, "file", "file search should find matching files recursively");
|
|
786
|
+
|
|
787
|
+
const directorySearch = await request("127.0.0.1", `/api/files/search?tab=${encodeURIComponent(tabId)}&q=${encodeURIComponent("docs")}`);
|
|
788
|
+
assert.equal(directorySearch.status, 200, `file search endpoint should search directories: ${directorySearch.body?.error || ""}`);
|
|
789
|
+
assert.equal(directorySearch.body?.data?.entries?.find((entry) => entry.path === "files-fixture/docs")?.type, "directory", "file search should find matching directories");
|
|
790
|
+
|
|
791
|
+
const depthLimitedSearch = await request("127.0.0.1", `/api/files/search?tab=${encodeURIComponent(tabId)}&q=${encodeURIComponent("depth")}`);
|
|
792
|
+
assert.equal(depthLimitedSearch.status, 200, `file search endpoint should honor depth-limited recursive search: ${depthLimitedSearch.body?.error || ""}`);
|
|
793
|
+
assert.equal(depthLimitedSearch.body?.data?.maxDepth, 8, "file search should advertise the recursive depth cap");
|
|
794
|
+
assert.equal(depthLimitedSearch.body?.data?.entries?.find((entry) => entry.path === depthEightFileRelative)?.type, "file", "file search should find matching files at depth 8");
|
|
795
|
+
assert.equal(depthLimitedSearch.body?.data?.entries?.find((entry) => entry.path === depthEightDirectoryRelative)?.type, "directory", "file search should find matching directories at depth 8");
|
|
796
|
+
assert.equal(depthLimitedSearch.body?.data?.entries?.some((entry) => entry.path === depthNineFileRelative), false, "file search should not descend past depth 8");
|
|
797
|
+
|
|
798
|
+
const emptyFileSearch = await request("127.0.0.1", `/api/files/search?tab=${encodeURIComponent(tabId)}&q=`);
|
|
799
|
+
assert.equal(emptyFileSearch.status, 200, "empty file search should be accepted");
|
|
800
|
+
assert.deepEqual(emptyFileSearch.body?.data?.entries, [], "empty file search should not scan the workspace");
|
|
801
|
+
|
|
802
|
+
const textContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(viewerRelative)}`);
|
|
803
|
+
assert.equal(textContent.status, 200, `text file should open in WebUI: ${textContent.body?.error || ""}`);
|
|
804
|
+
assert.equal(textContent.body?.data?.content, "hello file viewer\nsecond line\n");
|
|
805
|
+
assert.equal(textContent.body?.data?.language, "text");
|
|
806
|
+
|
|
807
|
+
const markdownContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(markdownRelative)}`);
|
|
808
|
+
assert.equal(markdownContent.status, 200, `markdown file should open in WebUI: ${markdownContent.body?.error || ""}`);
|
|
809
|
+
assert.equal(markdownContent.body?.data?.language, "markdown", "markdown files should get markdown viewer support metadata");
|
|
810
|
+
|
|
811
|
+
const emptyDefaultOpen = await request("127.0.0.1", "/api/files/open-default", { method: "POST", body: { tab: tabId, path: "" } });
|
|
812
|
+
assert.equal(emptyDefaultOpen.status, 400, "default editor opens should reject empty paths instead of opening the workspace root");
|
|
813
|
+
assert.match(String(emptyDefaultOpen.body?.error || ""), /Path to open is required/i);
|
|
814
|
+
|
|
815
|
+
const defaultOpen = await request("127.0.0.1", "/api/files/open-default", { method: "POST", body: { tab: tabId, path: viewerRelative } });
|
|
816
|
+
assert.equal(defaultOpen.status, 200, `default editor should open the requested file: ${defaultOpen.body?.error || ""}`);
|
|
817
|
+
assert.equal(defaultOpen.body?.data?.path, viewerRelative, "default editor endpoint should report the requested file path");
|
|
818
|
+
const openedAbsolutePath = path.join(cwd, viewerRelative);
|
|
819
|
+
let openLog = "";
|
|
820
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
821
|
+
openLog = await readFile(openCommandLog, "utf8").catch(() => "");
|
|
822
|
+
if (openLog.includes(openedAbsolutePath)) break;
|
|
823
|
+
await delay(50);
|
|
824
|
+
}
|
|
825
|
+
assert.ok(openLog.includes(openedAbsolutePath), "default editor command should receive the currently opened file path");
|
|
826
|
+
|
|
827
|
+
if (process.platform === "linux") {
|
|
828
|
+
const fallbackOpen = await request("127.0.0.1", "/api/files/open-default", { method: "POST", body: { tab: tabId, path: noDefaultRelative } });
|
|
829
|
+
assert.equal(fallbackOpen.status, 200, `default editor should fall back to the .txt editor for unassociated files: ${fallbackOpen.body?.error || ""}`);
|
|
830
|
+
assert.equal(fallbackOpen.body?.data?.path, noDefaultRelative, "default editor fallback should report the requested file path");
|
|
831
|
+
assert.equal(fallbackOpen.body?.data?.fallbackToTextEditor, true, "unassociated files should be opened through the text/plain fallback");
|
|
832
|
+
assert.equal(fallbackOpen.body?.data?.desktopFile, "fake-text-editor.desktop", "fallback should use the text/plain desktop app association");
|
|
833
|
+
const fallbackAbsolutePath = path.join(cwd, noDefaultRelative);
|
|
834
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
835
|
+
openLog = await readFile(openCommandLog, "utf8").catch(() => "");
|
|
836
|
+
if (openLog.includes(`gio\tlaunch\tfake-text-editor.desktop\t${fallbackAbsolutePath}`)) break;
|
|
837
|
+
await delay(50);
|
|
838
|
+
}
|
|
839
|
+
assert.ok(openLog.includes(`gio\tlaunch\tfake-text-editor.desktop\t${fallbackAbsolutePath}`), "default editor fallback should invoke the text/plain editor for the requested file");
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
const savedFile = await request("127.0.0.1", "/api/files/content", {
|
|
843
|
+
method: "POST",
|
|
844
|
+
body: { tab: tabId, path: viewerRelative, content: "updated from WebUI\n", mtimeMs: textContent.body?.data?.mtimeMs },
|
|
845
|
+
});
|
|
846
|
+
assert.equal(savedFile.status, 200, `file save should succeed from localhost: ${savedFile.body?.error || ""}`);
|
|
847
|
+
assert.equal(await readFile(path.join(cwd, viewerRelative), "utf8"), "updated from WebUI\n", "file save endpoint should write UTF-8 text content");
|
|
848
|
+
|
|
849
|
+
const binaryContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(binaryRelative)}`);
|
|
850
|
+
assert.equal(binaryContent.status, 415, "binary files should be rejected by the WebUI file viewer");
|
|
851
|
+
assert.match(String(binaryContent.body?.error || ""), /binary/i);
|
|
852
|
+
|
|
853
|
+
const oversizedContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(largeRelative)}`);
|
|
854
|
+
assert.equal(oversizedContent.status, 413, "oversized files should be rejected by the WebUI file viewer");
|
|
855
|
+
assert.match(String(oversizedContent.body?.error || ""), /too large/i);
|
|
856
|
+
|
|
857
|
+
const outsideRoot = await mkdtemp(path.join(tmpdir(), "pi-webui-files-outside-"));
|
|
858
|
+
try {
|
|
859
|
+
const outsideFile = path.join(outsideRoot, "outside.txt");
|
|
860
|
+
await writeFile(outsideFile, "outside\n", "utf8");
|
|
861
|
+
const outsideAbsolute = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent(outsideFile)}`);
|
|
862
|
+
assert.equal(outsideAbsolute.status, 403, "absolute paths outside the active tab cwd should be rejected");
|
|
863
|
+
assert.match(String(outsideAbsolute.body?.error || ""), /active tab working directory/i);
|
|
864
|
+
|
|
865
|
+
const symlinkPath = path.join(filesRoot, "outside-link.txt");
|
|
866
|
+
try {
|
|
867
|
+
await symlink(outsideFile, symlinkPath);
|
|
868
|
+
const symlinkEscape = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent("files-fixture/outside-link.txt")}`);
|
|
869
|
+
assert.equal(symlinkEscape.status, 403, "symlinks resolving outside the active tab cwd should be rejected");
|
|
870
|
+
assert.match(String(symlinkEscape.body?.error || ""), /escapes the active tab working directory/i);
|
|
871
|
+
} catch (error) {
|
|
872
|
+
if (!["EPERM", "EACCES", "EINVAL", "ENOTSUP"].includes(error?.code)) throw error;
|
|
873
|
+
console.log(`http-endpoints-harness: symlink unavailable (${error.code}); skipping file symlink confinement check`);
|
|
874
|
+
}
|
|
875
|
+
} finally {
|
|
876
|
+
await rmWithRetry(outsideRoot);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
const filesTab = await request("127.0.0.1", "/api/tabs", { method: "POST", body: { cwd: filesRoot, title: "files-fixture" } });
|
|
880
|
+
assert.equal(filesTab.status, 201, `file fixture tab should open: ${filesTab.body?.error || ""}`);
|
|
881
|
+
const filesTabId = filesTab.body?.data?.tab?.id;
|
|
882
|
+
assert.ok(filesTabId, "file fixture tab should have an id");
|
|
883
|
+
const scopedFileContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(filesTabId)}&path=${encodeURIComponent("viewer.txt")}`);
|
|
884
|
+
assert.equal(scopedFileContent.status, 200, "file paths should resolve against the requested tab cwd");
|
|
885
|
+
const wrongTabContent = await request("127.0.0.1", `/api/files/content?tab=${encodeURIComponent(tabId)}&path=${encodeURIComponent("viewer.txt")}`);
|
|
886
|
+
assert.equal(wrongTabContent.status, 404, "file paths should not bleed across tab cwd scopes");
|
|
887
|
+
const closeFilesTab = await request("127.0.0.1", "/api/tabs/close", { method: "POST", body: { ids: [filesTabId] }, timeoutMs: 10_000 });
|
|
888
|
+
assert.equal(closeFilesTab.status, 200, "file fixture tab should close after scoped file checks");
|
|
889
|
+
|
|
697
890
|
// Natural Conversation shell: /talk availability drives per-tab status and safety guards.
|
|
698
891
|
const conversationFeature = await request("127.0.0.1", `/api/features/natural-conversation?tab=${encodeURIComponent(tabId)}`);
|
|
699
892
|
assert.equal(conversationFeature.status, 200);
|
|
@@ -738,6 +931,10 @@ try {
|
|
|
738
931
|
assert.equal(blockedBash.status, 409, "user bash should be blocked while Natural Conversation is active");
|
|
739
932
|
assert.match(String(blockedBash.body?.error || ""), /bash is blocked|Natural Conversation Mode is active/);
|
|
740
933
|
|
|
934
|
+
const blockedFileSave = await request("127.0.0.1", "/api/files/content", { method: "POST", body: { tab: tabId, path: viewerRelative, content: "blocked by conversation mode\n" } });
|
|
935
|
+
assert.equal(blockedFileSave.status, 409, "file edits should be blocked while Natural Conversation is active");
|
|
936
|
+
assert.equal(blockedFileSave.body?.error, "file edits are blocked");
|
|
937
|
+
|
|
741
938
|
const allowedConversationPrompt = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { message: "Explain the current repo briefly", tab: tabId } });
|
|
742
939
|
assert.equal(allowedConversationPrompt.status, 200, "ordinary prompts remain allowed while Natural Conversation is active");
|
|
743
940
|
|
|
@@ -816,6 +1013,18 @@ try {
|
|
|
816
1013
|
});
|
|
817
1014
|
assert.equal(remoteDelete.status, 403, "session delete must be localhost-only");
|
|
818
1015
|
|
|
1016
|
+
const remoteFileSave = await request(lan, "/api/files/content", {
|
|
1017
|
+
method: "POST",
|
|
1018
|
+
body: { tab: tabId, path: viewerRelative, content: "remote save should be blocked\n" },
|
|
1019
|
+
});
|
|
1020
|
+
assert.equal(remoteFileSave.status, 403, "file saves must be localhost-only");
|
|
1021
|
+
|
|
1022
|
+
const remoteFileOpenDefault = await request(lan, "/api/files/open-default", {
|
|
1023
|
+
method: "POST",
|
|
1024
|
+
body: { tab: tabId, path: viewerRelative },
|
|
1025
|
+
});
|
|
1026
|
+
assert.equal(remoteFileOpenDefault.status, 403, "opening files in the default editor must be localhost-only");
|
|
1027
|
+
|
|
819
1028
|
const remoteExport = await request(lan, "/api/prompt", {
|
|
820
1029
|
method: "POST",
|
|
821
1030
|
body: { message: "/export", tab: tabId },
|
|
@@ -903,6 +1112,7 @@ try {
|
|
|
903
1112
|
}
|
|
904
1113
|
await new Promise((resolve) => voiceProvider.close(() => resolve()));
|
|
905
1114
|
await rmWithRetry(cwd);
|
|
1115
|
+
await rmWithRetry(harnessSideEffectsRoot);
|
|
906
1116
|
}
|
|
907
1117
|
|
|
908
1118
|
console.log("http-endpoints-harness.test.mjs passed");
|
|
@@ -23,16 +23,22 @@ const [pkgRaw, html, css, app, server, extension, readme, startScript, manifestR
|
|
|
23
23
|
]);
|
|
24
24
|
const pkg = JSON.parse(pkgRaw);
|
|
25
25
|
const manifest = JSON.parse(manifestRaw);
|
|
26
|
+
const lock = JSON.parse(await readFile(join(root, "package-lock.json"), "utf8"));
|
|
27
|
+
const helper = await readFile(join(root, "webui-rpc-helper.mjs"), "utf8");
|
|
26
28
|
const companionDependencies = {
|
|
27
|
-
"@firstpick/pi-extension-
|
|
28
|
-
"@firstpick/pi-extension-
|
|
29
|
-
"@firstpick/pi-extension-
|
|
29
|
+
"@firstpick/pi-extension-bang-command-autocomplete": "^0.2.1",
|
|
30
|
+
"@firstpick/pi-extension-btw": "^0.1.2",
|
|
31
|
+
"@firstpick/pi-extension-fish-user-bash": "^0.2.0",
|
|
32
|
+
"@firstpick/pi-extension-git-footer-status": "^0.3.6",
|
|
33
|
+
"@firstpick/pi-extension-release-aur": "^0.1.7",
|
|
30
34
|
"@firstpick/pi-extension-release-npm": "^0.4.0",
|
|
31
35
|
"@firstpick/pi-extension-safety-guard": "^0.2.3",
|
|
32
36
|
"@firstpick/pi-extension-setup-skills": "^0.1.8",
|
|
33
|
-
"@firstpick/pi-extension-stats": "^0.2.
|
|
34
|
-
"@firstpick/pi-extension-todo-progress": "^0.2.
|
|
37
|
+
"@firstpick/pi-extension-stats": "^0.2.8",
|
|
38
|
+
"@firstpick/pi-extension-todo-progress": "^0.2.7",
|
|
35
39
|
"@firstpick/pi-extension-tools": "^0.1.6",
|
|
40
|
+
"@firstpick/pi-extension-workflows": "^0.1.2",
|
|
41
|
+
"@firstpick/pi-package-remote-webui": "^0.1.5",
|
|
36
42
|
"@firstpick/pi-prompts-git-pr": "^0.1.2",
|
|
37
43
|
"@firstpick/pi-themes-bundle": "^0.1.4",
|
|
38
44
|
};
|
|
@@ -753,7 +759,10 @@ assert.match(css, /\.composer-remote-mic-consent[\s\S]*\.composer-remote-mic-con
|
|
|
753
759
|
assert.match(css, /\.composer-conversation-mode-chip\[data-voice-state="speaking"\]/, "conversation chip should style voice states");
|
|
754
760
|
assert.match(serviceWorker.toString(), /\/voice-conversation\.mjs/, "service worker app shell should include the voice module");
|
|
755
761
|
assert.ok(pkg.scripts.check.includes("node --check public/voice-conversation.mjs"), "npm run check should parse the voice module");
|
|
756
|
-
assert.match(app, /
|
|
762
|
+
assert.match(app, /id: "bangCommandAutocomplete"[\s\S]*packageName: "@firstpick\/pi-extension-bang-command-autocomplete"[\s\S]*capabilityLabel: "\/bang-status or \/bang-refresh"/, "optional features should list bang-command autocomplete by loaded command capability");
|
|
763
|
+
assert.match(app, /id: "fishUserBash"[\s\S]*packageName: "@firstpick\/pi-extension-fish-user-bash"[\s\S]*capabilityLabel: "\/user-bash-shell"/, "optional features should list fish user-bash by loaded command capability");
|
|
764
|
+
assert.match(app, /OPTIONAL_COMMAND_FEATURES = new Map\(\[[\s\S]*\["bang-refresh", "bangCommandAutocomplete"\][\s\S]*\["bang-status", "bangCommandAutocomplete"\][\s\S]*\["user-bash-shell", "fishUserBash"\]/, "optional command mapping should gate bang and fish companion commands");
|
|
765
|
+
assert.match(app, /function updateOptionalFeatureAvailability\(\)[\s\S]*hasAvailableCommand\("bang-status"\) \|\| hasAvailableCommand\("bang-refresh"\)[\s\S]*hasAvailableCommand\("user-bash-shell"\)[\s\S]*hasAvailableCommand\("git-staged-msg"\)[\s\S]*hasAvailableCommand\("release-npm"\)[\s\S]*hasAvailableCommand\("release-aur"\)[\s\S]*hasAvailableCommand\("safety-guard"\)[\s\S]*hasLoadedRpcCommand\("skills"\)[\s\S]*hasAvailableCommand\("todo-progress-status"\)[\s\S]*hasLoadedRpcCommand\("tools"\)[\s\S]*hasAvailableCommand\("remote"\)[\s\S]*NATURAL_CONVERSATION_COMMAND_NAMES\.some\(\(name\) => hasAvailableCommand\(name\)\)/, "optional feature detection should call RPC-visible commands directly and distinguish native resource selectors from TUI companions");
|
|
757
766
|
assert.match(app, /hasRemoteWebuiCommand = isOptionalFeatureEnabled\("remoteWebui"\) && hasAvailableCommand\("remote"\)[\s\S]*optionsRemoteButton\.hidden = !hasRemoteWebuiCommand[\s\S]*syncRemoteWebuiControlVisibility\(hasRemoteWebuiCommand\)/, "Options menu should track /remote availability and delegate network card visibility");
|
|
758
767
|
assert.match(app, /function syncRemoteWebuiControlVisibility[\s\S]*networkControlField\.hidden = !hasRemoteWebuiCommand/, "Remote WebUI network card should render whenever the optional feature and /remote command are enabled");
|
|
759
768
|
assert.match(app, /if \(featureId === "remoteWebui"\) syncRemoteWebuiControlVisibility\(false\)/, "Disabling Remote WebUI should immediately hide browser network controls before broader rerendering");
|
|
@@ -981,9 +990,16 @@ assert.match(app, /let pathSuggestActiveQuery = null/, "@ autocomplete should tr
|
|
|
981
990
|
assert.match(app, /pathSuggestActiveQuery === trigger\.query[\s\S]*?return;/, "@ autocomplete should skip duplicate same-query fetches from input and keyup events");
|
|
982
991
|
assert.match(app, /const keepExistingPathMenu = suggestionMode === "path"[\s\S]*?if \(!keepExistingPathMenu\) \{[\s\S]*?Finding paths…/, "@ autocomplete should keep the existing menu visible while refreshing a new path query");
|
|
983
992
|
assert.match(app, /elements\.commandSuggest\.setAttribute\("aria-busy", "true"\)/, "@ autocomplete should mark async path refreshes busy without clearing rendered suggestions");
|
|
993
|
+
assert.match(app, /function getBangTrigger\(\)/, "prompt composer should detect leading ! and !! shell command triggers");
|
|
994
|
+
assert.match(app, /function renderBangSuggestions\(trigger[\s\S]*api\(`\/api\/bang-suggestions\?query=\$\{encodeURIComponent\(trigger\.query\)\}`/, "bang autocomplete should load suggestions from the Web UI server as the user types");
|
|
995
|
+
assert.match(app, /function renderBangSuggestionItems\(trigger[\s\S]*insertBangSuggestion\(index\)/, "bang autocomplete should render clickable shell command suggestions");
|
|
996
|
+
assert.match(app, /function insertBangSuggestion\(index = commandSuggestIndex\)/, "accepting a bang suggestion should insert a shell command after the ! or !! prefix");
|
|
997
|
+
assert.match(app, /if \(suggestionMode === "bang"\) return insertBangSuggestion\(index\)/, "generic autocomplete insertion should route bang suggestions to the bang inserter");
|
|
998
|
+
assert.match(app, /isOptionalFeatureEnabled\("bangCommandAutocomplete"\)[\s\S]*renderBangSuggestions\(bangTrigger/, "bang autocomplete should only render when the optional companion is detected and enabled");
|
|
984
999
|
assert.match(app, /function setActiveCommandSuggestionFromPointerMove\(index, event\)/, "command and path autocomplete should route pointer selection through movement detection");
|
|
985
1000
|
assert.match(app, /item\.addEventListener\("pointermove", \(event\) => setActiveCommandSuggestionFromPointerMove\(index, event\)\);[\s\S]*?item\.addEventListener\("click", \(\) => insertCommandSuggestion\(index\)\);/, "slash command autocomplete should only follow pointer movement before click insertion");
|
|
986
1001
|
assert.match(app, /item\.addEventListener\("pointermove", \(event\) => setActiveCommandSuggestionFromPointerMove\(index, event\)\);[\s\S]*?item\.addEventListener\("click", \(\) => insertPathSuggestion\(index\)\);/, "path autocomplete should only follow pointer movement before click insertion");
|
|
1002
|
+
assert.match(app, /item\.addEventListener\("pointermove", \(event\) => setActiveCommandSuggestionFromPointerMove\(index, event\)\);[\s\S]*?item\.addEventListener\("click", \(\) => insertBangSuggestion\(index\)\);/, "bang autocomplete should only follow pointer movement before click insertion");
|
|
987
1003
|
assert.doesNotMatch(app, /addEventListener\("mouseenter", \(\) => setActiveCommandSuggestion\(index\)\)/, "autocomplete should not change active selection on stationary mouseenter");
|
|
988
1004
|
assert.match(app, /function resizePromptInput\(\)/, "prompt textarea should auto-resize from a one-line default");
|
|
989
1005
|
assert.match(app, /elements\.promptInput\.addEventListener\("input", \(\) => \{[\s\S]*?resizePromptInput\(\);/, "prompt textarea should resize whenever the user edits it");
|
|
@@ -1314,6 +1330,10 @@ assert.match(server, /function fastPicksStorageFile\(/, "server should define a
|
|
|
1314
1330
|
assert.match(server, /PI_WEBUI_FAST_PICKS_FILE/, "server should allow overriding the fast-picks storage path");
|
|
1315
1331
|
assert.match(server, /async function getPathSuggestionData\(tab, rawQuery\)/, "server should compute @ file\/path reference suggestions for the active tab cwd");
|
|
1316
1332
|
assert.match(server, /url\.pathname === "\/api\/path-suggestions" && req\.method === "GET"/, "server should expose GET /api/path-suggestions for @ reference autocomplete");
|
|
1333
|
+
assert.match(server, /async function getBangSuggestionData\(tab, rawQuery\)/, "server should compute ! and !! shell command suggestions for the active tab cwd");
|
|
1334
|
+
assert.match(server, /PI_BANG_AUTOCOMPLETE_INCLUDE_HISTORY/, "server bang suggestions should support the companion's history knob");
|
|
1335
|
+
assert.match(server, /PI_BANG_AUTOCOMPLETE_RUNTIME_STORE_PATH/, "server bang suggestions should support the companion's runtime-store knob");
|
|
1336
|
+
assert.match(server, /url\.pathname === "\/api\/bang-suggestions" && req\.method === "GET"/, "server should expose GET /api/bang-suggestions for bang-command autocomplete");
|
|
1317
1337
|
assert.match(server, /url\.pathname === "\/api\/path-fast-picks" && req\.method === "GET"/, "server should expose GET /api/path-fast-picks");
|
|
1318
1338
|
assert.match(server, /url\.pathname === "\/api\/path-fast-picks" && req\.method === "POST"/, "server should expose POST /api/path-fast-picks");
|
|
1319
1339
|
assert.match(server, /url\.pathname === "\/api\/scoped-models" && req\.method === "GET"/, "server should expose GET /api/scoped-models");
|
|
@@ -1329,6 +1349,8 @@ assert.match(server, /type: "set_follow_up_mode"/, "server should expose follow-
|
|
|
1329
1349
|
assert.match(server, /type: "set_auto_compaction"/, "server should expose auto-compaction changes for native /settings");
|
|
1330
1350
|
assert.match(server, /@firstpick\/pi-themes-bundle/, "server should discover themes from the optional theme package");
|
|
1331
1351
|
assert.match(server, /const OPTIONAL_FEATURE_PACKAGES = new Map/, "server should whitelist optional feature packages for install actions");
|
|
1352
|
+
assert.match(server, /\["bangCommandAutocomplete", "@firstpick\/pi-extension-bang-command-autocomplete"\]/, "server should allow installing the bang autocomplete optional feature");
|
|
1353
|
+
assert.match(server, /\["fishUserBash", "@firstpick\/pi-extension-fish-user-bash"\]/, "server should allow installing the fish user-bash optional feature");
|
|
1332
1354
|
assert.match(server, /\["btwCommand", "@firstpick\/pi-extension-btw"\]/, "server should allow installing the /btw optional feature");
|
|
1333
1355
|
assert.match(server, /\["safetyGuard", "@firstpick\/pi-extension-safety-guard"\]/, "server should allow installing the safety guard optional feature");
|
|
1334
1356
|
assert.match(server, /\["tuiSkillsCommand", "@firstpick\/pi-extension-setup-skills"\]/, "server should allow installing the TUI skills optional feature");
|
|
@@ -1376,6 +1398,8 @@ assert.match(readme, /Automatic tab naming from the first prompt/, "README shoul
|
|
|
1376
1398
|
assert.match(readme, /Feedback reactions \(`👍`, `👎`, `\?`\) on final assistant output plus tool\/bash action cards/, "README should describe final-output and action feedback reactions");
|
|
1377
1399
|
assert.match(readme, /POST \/api\/action-feedback\?tab=<tabId>/, "README should document the action-feedback endpoint");
|
|
1378
1400
|
assert.match(readme, /`@` file\/path references with live suggestions/, "README should describe @ file/path reference autocomplete");
|
|
1401
|
+
assert.match(readme, /optional `@firstpick\/pi-extension-bang-command-autocomplete` companion[\s\S]*GET \/api\/bang-suggestions\?tab=<tabId>&query=<command>/, "README should document optional bang-command autocomplete and its endpoint");
|
|
1402
|
+
assert.match(readme, /optional `@firstpick\/pi-extension-fish-user-bash` companion/, "README should document optional fish user-bash integration");
|
|
1379
1403
|
assert.match(readme, /GET \/api\/path-suggestions\?tab=<tabId>&query=<path>/, "README should document the path-suggestions endpoint");
|
|
1380
1404
|
assert.match(readme, /GET \/api\/optional-features/, "README should document optional feature status endpoint");
|
|
1381
1405
|
assert.match(readme, /POST \/api\/optional-feature-install/, "README should document optional feature install endpoint");
|
|
@@ -1407,12 +1431,17 @@ assert.ok(!pkg.files?.some((entry) => entry === "dev/scripts" || entry.startsWit
|
|
|
1407
1431
|
for (const [name, range] of Object.entries(companionDependencies)) {
|
|
1408
1432
|
assert.equal(pkg.optionalDependencies?.[name], range, `webui package should optionally depend on ${name}`);
|
|
1409
1433
|
assert.equal(pkg.dependencies?.[name], undefined, `webui package should not require optional companion ${name}`);
|
|
1434
|
+
assert.equal(lock.packages?.[""]?.optionalDependencies?.[name], range, `package-lock root should optionally depend on ${name}`);
|
|
1435
|
+
assert.equal(lock.packages?.[""]?.dependencies?.[name], undefined, `package-lock root should not require optional companion ${name}`);
|
|
1436
|
+
assert.ok(lock.packages?.[`node_modules/${name}`], `package-lock should include resolved optional companion ${name}`);
|
|
1410
1437
|
}
|
|
1411
1438
|
assert.equal(pkg.bundledDependencies, undefined, "webui optional companion packages should not be bundled into the tarball");
|
|
1412
1439
|
assert.equal(pkg.optionalDependencies?.["@firstpick/pi-package-natural-conversation"], undefined, "webui package should not optionally depend on the standalone Natural Conversation package");
|
|
1413
1440
|
assert.ok(!pkg.pi?.extensions?.some((entry) => String(entry).includes("pi-package-natural-conversation")), "webui Pi manifest should not load Natural Conversation directly; /talk must come from the standalone package");
|
|
1414
1441
|
assert.ok(pkg.pi?.extensions?.includes("./index.ts"), "webui Pi manifest should load its own extension");
|
|
1415
1442
|
for (const extensionPath of [
|
|
1443
|
+
"node_modules/@firstpick/pi-extension-bang-command-autocomplete/index.ts",
|
|
1444
|
+
"node_modules/@firstpick/pi-extension-fish-user-bash/index.ts",
|
|
1416
1445
|
"node_modules/@firstpick/pi-extension-git-footer-status/index.ts",
|
|
1417
1446
|
"node_modules/@firstpick/pi-extension-release-aur/index.ts",
|
|
1418
1447
|
"node_modules/@firstpick/pi-extension-release-npm/index.ts",
|
|
@@ -1425,6 +1454,8 @@ for (const extensionPath of [
|
|
|
1425
1454
|
assert.ok(pkg.pi?.extensions?.includes(extensionPath), `webui Pi manifest should load ${extensionPath} when present`);
|
|
1426
1455
|
}
|
|
1427
1456
|
for (const siblingExtensionPath of [
|
|
1457
|
+
"../pi-extension-bang-command-autocomplete/index.ts",
|
|
1458
|
+
"../pi-extension-fish-user-bash/index.ts",
|
|
1428
1459
|
"../pi-extension-git-footer-status/index.ts",
|
|
1429
1460
|
"../pi-extension-release-aur/index.ts",
|
|
1430
1461
|
"../pi-extension-release-npm/index.ts",
|
|
@@ -1436,6 +1467,10 @@ for (const siblingExtensionPath of [
|
|
|
1436
1467
|
]) {
|
|
1437
1468
|
assert.ok(!pkg.pi?.extensions?.includes(siblingExtensionPath), `webui Pi manifest should avoid duplicate sibling load path ${siblingExtensionPath}`);
|
|
1438
1469
|
}
|
|
1470
|
+
assert.match(helper, /function installRpcUserBashSupport\(\)/, "Web UI RPC helper should patch RPC bash execution for user_bash events");
|
|
1471
|
+
assert.match(helper, /runner\?\.hasHandlers\?\.\("user_bash"\)[\s\S]*runner\.emitUserBash/, "Web UI RPC helper should emit user_bash before default bash execution");
|
|
1472
|
+
assert.match(helper, /eventResult\?\.operations[\s\S]*original\.call\(this, command, onChunk, nextOptions\)/, "Web UI RPC helper should pass extension-provided bash operations to Pi execution");
|
|
1473
|
+
assert.match(helper, /eventResult\?\.result[\s\S]*recordBashResult/, "Web UI RPC helper should preserve extension-provided bash results in session history");
|
|
1439
1474
|
assert.ok(pkg.pi?.skills?.includes("node_modules/@firstpick/pi-extension-release-aur/skills"), "webui Pi manifest should load release-aur nested skills when present");
|
|
1440
1475
|
assert.ok(!pkg.pi?.skills?.includes("../pi-extension-release-aur/skills"), "webui Pi manifest should avoid duplicate release-aur sibling skills");
|
|
1441
1476
|
assert.ok(pkg.pi?.prompts?.includes("node_modules/@firstpick/pi-prompts-git-pr/prompts"), "webui Pi manifest should load guided-git nested prompts when present");
|
|
@@ -162,6 +162,7 @@ assert.match(server, /case "\/api\/abort-bash":[\s\S]*?return \{ type: "abort_ba
|
|
|
162
162
|
assert.match(app, /function parseUserBashInput\(message\)[\s\S]*?text\.startsWith\("!!"\)/, "frontend should detect !! bash commands before prompt forwarding");
|
|
163
163
|
assert.match(app, /const userBash = kind === "prompt" && attachments\.length === 0 \? parseUserBashInput\(originalMessage\) : null/, "prompt sending should intercept user bash only for plain prompt input");
|
|
164
164
|
assert.match(app, /api\("\/api\/bash", \{ method: "POST", body: \{ command, excludeFromContext \}/, "frontend should send user bash commands to the bash endpoint");
|
|
165
|
+
assert.match(app, /function isCompleteUserBashMessage\(message\)[\s\S]*?title\.includes\("complete"\)[\s\S]*?function shouldOpenMessageCollapseByDefault\(message\)[\s\S]*?isCompleteUserBashMessage\(message\)/, "frontend should expand completed user bash cards by default without toggling all tool output");
|
|
165
166
|
assert.match(app, /api\("\/api\/abort-bash", \{ method: "POST", body: \{\}, tabId: tabContext\.tabId \}\)/, "abort should target active user bash before agent abort");
|
|
166
167
|
assert.match(server, /async function cycleTabModel\(tab, direction = "forward"\)/, "server should provide scoped\/all model cycling helper");
|
|
167
168
|
assert.match(server, /url\.pathname === "\/api\/model-cycle" && req\.method === "POST"/, "server should expose model-cycle endpoint for shortcuts");
|
package/webui-rpc-helper.mjs
CHANGED
|
@@ -36,6 +36,35 @@ function installActiveCommandSessionCapture() {
|
|
|
36
36
|
|
|
37
37
|
installActiveCommandSessionCapture();
|
|
38
38
|
|
|
39
|
+
function installRpcUserBashSupport() {
|
|
40
|
+
const proto = AgentSession?.prototype;
|
|
41
|
+
if (!proto || proto.__webuiHelperUserBashSupportInstalled) return;
|
|
42
|
+
const original = proto.executeBash;
|
|
43
|
+
if (typeof original !== "function") return;
|
|
44
|
+
Object.defineProperty(proto, "__webuiHelperUserBashSupportInstalled", { value: true });
|
|
45
|
+
proto.executeBash = async function webuiHelperExecuteBash(command, onChunk, options = {}) {
|
|
46
|
+
const runner = this.extensionRunner;
|
|
47
|
+
const eventResult = runner?.hasHandlers?.("user_bash")
|
|
48
|
+
? await runner.emitUserBash({
|
|
49
|
+
type: "user_bash",
|
|
50
|
+
command,
|
|
51
|
+
excludeFromContext: options?.excludeFromContext === true,
|
|
52
|
+
cwd: this.sessionManager?.getCwd?.() || this._cwd || process.cwd(),
|
|
53
|
+
})
|
|
54
|
+
: undefined;
|
|
55
|
+
|
|
56
|
+
if (eventResult?.result) {
|
|
57
|
+
this.recordBashResult(command, eventResult.result, { excludeFromContext: options?.excludeFromContext === true });
|
|
58
|
+
return eventResult.result;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const nextOptions = eventResult?.operations ? { ...options, operations: eventResult.operations } : options;
|
|
62
|
+
return original.call(this, command, onChunk, nextOptions);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
installRpcUserBashSupport();
|
|
67
|
+
|
|
39
68
|
function responseMessage(payload) {
|
|
40
69
|
return `${RESPONSE_PREFIX}${JSON.stringify(payload)}`;
|
|
41
70
|
}
|