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

+110
View File
@@ -2626,6 +2626,24 @@ describe("ThreadComposer", () => {
expect(onSend).toHaveBeenCalledWith(text, undefined, undefined);
});
it("highlights only the leading bang with the skill-reference color and preserves literal command text", () => {
const onSend = vi.fn();
render(<ThreadComposer onSend={onSend} />);
const input = screen.getByLabelText("Message input") as HTMLTextAreaElement;
fireEvent.change(input, { target: { value: "$workflow " } });
const referenceColor = screen.getByTestId("composer-skill-reference-workflow").style.color;
const command = ' !echo "hello! $workflow @typography"\nWrite-Output done';
fireEvent.change(input, { target: { value: command } });
const bang = screen.getByTestId("composer-shell-prefix");
expect(bang).toHaveTextContent(/^!$/);
expect(bang.style.color).toBe(referenceColor);
expect(input.previousElementSibling).toHaveAttribute("aria-hidden", "true");
expect(input.previousElementSibling?.textContent).toBe(command);
expect(input).toHaveValue(command);
fireEvent.keyDown(input, { key: "Enter" });
expect(onSend).toHaveBeenCalledWith(command.trim(), undefined, { sideChannel: true, userShell: true });
});
it.each(["", "/history "])("mirrors inline references during composition without submitting the IME confirmation: %s", (prefix) => {
const onSend = vi.fn();
render(<ThreadComposer onSend={onSend} slashCommands={COMMANDS} />);
@@ -3243,6 +3261,98 @@ describe("ThreadComposer", () => {
expect(onSend).toHaveBeenCalledWith("Draw a friendly robot", undefined, undefined);
});
it.each(["!pwd", " ! pwd ", "!Write-Output first\nWrite-Output second", "!"])("runs bang input directly without a configured model: %s", (command) => {
const onSend = vi.fn();
render(<ThreadComposer onSend={onSend} modelNeedsSetup />);
const input = screen.getByLabelText("Message input");
fireEvent.change(input, { target: { value: command } });
fireEvent.click(screen.getByRole("button", { name: "Run Shell command" }));
expect(onSend).toHaveBeenCalledWith(command.trim(), undefined, { sideChannel: true, userShell: true });
expect(input).toHaveValue("");
});
it("keeps bang commands separate from pending guidance and the active turn", async () => {
const onSend = vi.fn();
const onStop = vi.fn();
const { rerender } = render(<ThreadComposer onSend={onSend} onStop={onStop} isStreaming />);
const input = screen.getByLabelText("Message input");
fireEvent.change(input, { target: { value: "waiting guidance" } });
fireEvent.keyDown(input, { key: "Enter" });
fireEvent.change(input, { target: { value: "!pwd" } });
fireEvent.keyDown(input, { key: "Enter" });
expect(onSend).toHaveBeenCalledOnce();
expect(onSend).toHaveBeenCalledWith("!pwd", undefined, { sideChannel: true, userShell: true });
expect(within(screen.getByRole("group", { name: "Waiting to send" })).getByText("waiting guidance")).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Stop response" })).toBeInTheDocument();
expect(onStop).not.toHaveBeenCalled();
rerender(<ThreadComposer onSend={onSend} onStop={onStop} isStreaming={false} />);
await waitFor(() => expect(onSend).toHaveBeenCalledTimes(2));
expect(onSend).toHaveBeenLastCalledWith("waiting guidance");
});
it.each(["!echo @gimp", "!echo $weather"])("keeps bang arguments literal instead of opening a mention or skill menu: %s", (command) => {
const onSend = vi.fn();
render(<ThreadComposer onSend={onSend} cliApps={CLI_APPS} skills={[{ name: "weather", description: "Weather", source: "builtin", available: true }]} />);
const input = screen.getByLabelText("Message input");
fireEvent.change(input, { target: { value: command, selectionStart: command.length } });
expect(input).toHaveValue(command);
fireEvent.keyDown(input, { key: "Enter" });
expect(onSend).toHaveBeenCalledWith(command, undefined, { sideChannel: true, userShell: true });
});
it("keeps exclamation marks inside ordinary messages on the chat path", () => {
const onSend = vi.fn();
render(<ThreadComposer onSend={onSend} />);
fireEvent.change(screen.getByLabelText("Message input"), { target: { value: "Please explain !pwd" } });
fireEvent.keyDown(screen.getByLabelText("Message input"), { key: "Enter" });
expect(onSend).toHaveBeenCalledWith("Please explain !pwd", undefined, undefined);
});
it("retains a bang draft when delivery is rejected without retrying it", async () => {
const onSend = vi.fn().mockRejectedValue(new Error("Shell send rejected"));
const { rerender } = render(<ThreadComposer onSend={onSend} />);
const input = screen.getByLabelText("Message input");
fireEvent.change(input, { target: { value: "!pwd" } });
fireEvent.keyDown(input, { key: "Enter" });
await waitFor(() => expect(screen.getByRole("alert")).toHaveTextContent("Shell send rejected"));
expect(input).toHaveValue("!pwd");
rerender(<ThreadComposer onSend={onSend} isStreaming={false} />);
expect(onSend).toHaveBeenCalledOnce();
expect(onSend).toHaveBeenCalledWith("!pwd", undefined, { sideChannel: true, userShell: true });
});
it("rejects attachments on bang input without losing the draft or attachment", async () => {
const onSend = vi.fn();
const { container } = render(<ThreadComposer onSend={onSend} />);
fireEvent.change(container.querySelector('input[type="file"]')!, {
target: { files: [new File(["image"], "photo.png", { type: "image/png" })] },
});
const input = screen.getByLabelText("Message input");
fireEvent.change(input, { target: { value: "!pwd" } });
await waitFor(() => expect(screen.getByRole("button", { name: "Run Shell command" })).toBeEnabled());
fireEvent.keyDown(input, { key: "Enter" });
expect(screen.getByRole("alert")).toHaveTextContent("Remove attachments and quoted text before running a command.");
expect(onSend).not.toHaveBeenCalled();
expect(input).toHaveValue("!pwd");
expect(screen.getByRole("button", { name: "Remove attachment" })).toHaveAttribute("aria-description", "photo.png");
});
it("rejects quoted context on bang input without clearing it", () => {
const onSend = vi.fn();
const onQuotedContextChange = vi.fn();
render(<ThreadComposer onSend={onSend} quotedContext="keep this quote" onQuotedContextChange={onQuotedContextChange} />);
const input = screen.getByLabelText("Message input");
fireEvent.change(input, { target: { value: "!pwd" } });
fireEvent.keyDown(input, { key: "Enter" });
expect(screen.getByRole("alert")).toHaveTextContent("Remove attachments and quoted text before running a command.");
expect(input).toHaveValue("!pwd");
expect(onSend).not.toHaveBeenCalled();
expect(onQuotedContextChange).not.toHaveBeenCalled();
});
it("marks known slash commands as side-channel sends", () => {
const onSend = vi.fn();
render(