feat(webui): complete bang commands and literal output (NAN-291) (#6173)

* feat(webui): complete direct bang shell commands

Reuse the gateway user-shell side channel, retain failed drafts without reconnect replay, and preserve literal output across live delivery and history. Highlight the bang prefix before and after sending.

NAN-291

* fix(clients): preserve literal shell output through display metadata
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-26 23:35:26 +08:00
1 parent f23a6d1485
commit 7e5dcb79e0
43 files changed
+805 -100

No files matched your search

+6 -2
View File
@@ -28,9 +28,13 @@ export function InlineReferencesFixture() {
<main className="mx-auto h-full max-w-[var(--content-column-width)] space-y-6 overflow-y-auto p-4">
{[answer, ...sent].map(message => <MessageBubble key={message.id} message={message} slashCommands={commands} />)}
<ThreadComposer compactWhenIdle sessions={[session]} modelLabel="Fixture" persistDraft={false} slashCommands={commands}
onSend={text => setSent(current => [...current, {
onSend={(text, _media, options) => setSent(current => [...current, {
id: `sent-${current.length}`, role: "user", content: text, createdAt: current.length + 2,
}])} />
}, ...(options?.userShell ? [{
id: `shell-${current.length}`, role: "assistant" as const, renderAs: "text" as const,
content: " __pycache__\n```mermaid\nflowchart LR\n```\n![preview](local.png)\n<b>raw</b>\n",
createdAt: current.length + 3,
}] : [])])} />
</main>
</ThemeProvider>;
}
+41
View File
@@ -1,3 +1,5 @@
import { EOL } from "node:os";
import { expect, test, type Locator } from "@playwright/test";
async function expectMatchingInputLayers(input: Locator) {
@@ -134,6 +136,45 @@ for (const narrow of [false, true]) {
await expect(command.locator("span")).toHaveCSS("opacity", "0.9");
await expect(page.locator("[data-user-text-bubble]").last().locator("p")).toHaveText(text);
await page.screenshot({ path: info.outputPath("slash-command-and-skill.png") });
const shellCommand = ' !echo "hello! $workflow @typography"\nWrite-Output "命令输出"';
await input.fill(shellCommand);
const bang = page.getByTestId("composer-shell-prefix");
await expect(bang).toHaveText("!");
await expect(bang).toHaveCSS("color", await page.getByTestId("message-skill-reference-workflow").evaluate(node => getComputedStyle(node).color));
await expect(bang).toHaveCSS("font-weight", "400");
await expectMatchingInputLayers(input);
await input.press("ControlOrMeta+a");
await input.press("ControlOrMeta+c");
expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(shellCommand);
await input.press("ArrowRight");
await page.screenshot({ path: info.outputPath("composer-bang.png") });
const prefixColor = await bang.evaluate(node => getComputedStyle(node).color);
await page.getByRole("button", { name: "Run Shell command", exact: true }).click();
const sentPrefix = page.getByTestId("message-shell-prefix");
await expect(sentPrefix).toHaveText("!");
await expect(sentPrefix).toHaveCSS("color", prefixColor);
await expect(sentPrefix).toHaveCSS("font-weight", "400");
const sentCommand = page.locator("[data-user-text-bubble]").last().locator("p");
expect(await sentCommand.textContent()).toBe(shellCommand.trim());
await sentCommand.evaluate(node => {
const range = document.createRange();
range.selectNodeContents(node);
const selection = window.getSelection()!;
selection.removeAllRanges();
selection.addRange(range);
});
await page.keyboard.press("ControlOrMeta+c");
expect(await page.evaluate(() => navigator.clipboard.readText())).toBe(shellCommand.trim().replaceAll("\n", EOL));
await page.evaluate(() => window.getSelection()?.removeAllRanges());
await page.screenshot({ path: info.outputPath("sent-bang.png") });
const output = page.getByTestId("plain-code-fallback");
const literal = " __pycache__\n```mermaid\nflowchart LR\n```\n![preview](local.png)\n<b>raw</b>\n";
expect(await output.textContent()).toBe(literal);
await expect(output.locator("img, b")).toHaveCount(0);
await page.getByRole("button", { name: "Copy code", exact: true }).click();
await expect.poll(() => page.evaluate(() => navigator.clipboard.readText())).toBe(literal);
expect(errors).toEqual([]);
});
}