Skip to content

Your lightweight open-source personal agent.

fix(webui): render remote revocation commands as copyable code blocks

Xubin Ren47c587217db7
diff --git a/webui/src/components/remote/QuickPairSetup.tsx b/webui/src/components/remote/QuickPairSetup.tsx
index 3e734f105..455735f9c 100644
--- a/webui/src/components/remote/QuickPairSetup.tsx
+++ b/webui/src/components/remote/QuickPairSetup.tsx
@@ -8,6 +8,7 @@ import { Textarea } from "@/components/ui/textarea";
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { useClient } from "@/providers/ClientProvider";
import { copyTextToClipboard } from "@/lib/clipboard";
+import { CodeBlock } from "@/components/CodeBlock";
import { remoteAction } from "@/lib/remote-instances";
import { pairingReturnOrigin, type PairReturn } from "@/lib/remote-pair-return";
import type { ConnectionStatus } from "@/lib/types";
@@ -164,7 +165,7 @@ export function QuickPairSetup({ returned, onSSH, onClose }: { returned?: PairRe
<Disclosure className="text-xs text-muted-foreground" summaryClassName="flex min-h-9 items-center gap-2 rounded-xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
summary={<><ChevronDown aria-hidden className="h-3.5 w-3.5 shrink-0 transition-transform group-data-[state=open]/disclosure:rotate-180 motion-reduce:transition-none" />{t("remote.pair.security")}</>}>
<p className="my-2 leading-5">{t("remote.pair.fingerprint")}</p><code className="block break-all">{preview.fingerprint}</code>
- <p className="mb-2 mt-4 leading-5">{t("remote.pair.revoke")}</p><code className="block break-all">{preview.revoke_command}</code>
+ <p className="mb-2 mt-4 leading-5">{t("remote.pair.revoke")}</p><CodeBlock language="bash" code={preview.revoke_command} highlight={false} className="min-w-0 [&_pre]:[overflow-wrap:anywhere]" />
</Disclosure>
{saved && error && <div className="space-y-2"><p className="text-xs leading-5 text-muted-foreground">{t("remote.pair.retryHint")}</p>
<Disclosure summaryClassName="flex min-h-9 items-center gap-2 rounded-xl text-xs text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" contentClassName="pt-2"
diff --git a/webui/src/components/remote/RemoteConnectionsPage.tsx b/webui/src/components/remote/RemoteConnectionsPage.tsx
index 4cce9f9e1..a53d7b526 100644
--- a/webui/src/components/remote/RemoteConnectionsPage.tsx
+++ b/webui/src/components/remote/RemoteConnectionsPage.tsx
@@ -2,6 +2,7 @@ import { useEffect, useId, useRef, useState, useSyncExternalStore, type ReactNod
import { AlertCircle, ArrowUpRight, Check, ChevronDown, ChevronLeft, FolderOpen, Laptop, Loader2, MoreHorizontal, Plus, Server } from "lucide-react";
import { useTranslation } from "react-i18next";
import { SettingsGroup } from "@/components/settings/shared/SettingsControls";
+import { CodeBlock } from "@/components/CodeBlock";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { DisclosureContent } from "@/components/ui/disclosure";
@@ -470,7 +471,7 @@ export function RemoteConnectionsPage({ mainNavigationExpanded = false, hostChro
<Dialog open={!!removing} onOpenChange={(value) => { if (!value && !busy) setRemoving(null); }}>
<DialogContent className="max-h-[85dvh] max-w-sm overflow-y-auto"><DialogHeader className="pr-5 text-left"><DialogTitle className="break-words leading-snug">{t(removalIsShared ? "remote.sameInstance.forgetTitle" : "remote.forgetTitle", { name: removalProfile?.name })}</DialogTitle><DialogDescription>{t(removalIsShared ? "remote.sameInstance.forgetHint" : "remote.forgetDescription")}</DialogDescription></DialogHeader>
{removalProfile && (removalProfile.connected || connections.openHostIds.includes(removalProfile.id)) && <p role="note" className="rounded-xl bg-muted/40 p-3 text-xs leading-5">{t("remote.activeForgetWarning")}</p>}
- {removalProfile?.paired && <div className="space-y-2 text-xs text-muted-foreground"><p>{t("remote.pair.forgetHint")}</p><code className="block break-all">{removalProfile.revoke_command}</code></div>}
+ {removalProfile?.paired && <div className="space-y-2 text-xs text-muted-foreground"><p>{t("remote.pair.forgetHint")}</p>{removalProfile.revoke_command && <CodeBlock language="bash" code={removalProfile.revoke_command} highlight={false} className="min-w-0 [&_pre]:[overflow-wrap:anywhere]" />}</div>}
{error && <p role="alert" className="flex items-start gap-2 text-[13px] leading-5 text-foreground"><AlertCircle aria-hidden="true" className="mt-0.5 h-4 w-4 shrink-0 text-muted-foreground" />{error}</p>}
<div className="grid grid-cols-2 gap-2"><Button variant="ghost" disabled={!!busy} onClick={() => setRemoving(null)}>{t("common.cancel")}</Button><Button variant="destructive" className="h-auto min-h-10 min-w-0" disabled={!!busy} aria-busy={!!busy} onClick={() => { void remove(); }}>{busy && <Loader2 aria-hidden className="mr-2 h-4 w-4 shrink-0 animate-spin motion-reduce:animate-none" />}<span className="whitespace-normal break-words">{t(removalIsShared ? "remote.sameInstance.forgetAction" : "remote.forget")}</span></Button></div>
</DialogContent>
diff --git a/webui/src/tests/quick-pair.test.tsx b/webui/src/tests/quick-pair.test.tsx
index b437f9acc..0afe9ddb9 100644
--- a/webui/src/tests/quick-pair.test.tsx
+++ b/webui/src/tests/quick-pair.test.tsx
@@ -65,6 +65,17 @@ async function reviewed() {
}
describe("quick pairing", () => {
+ it("uses the same copyable revocation code block in pairing details", async () => {
+ returnedView();
+ await screen.findByRole("heading", { name: "Open this nanobot?" });
+ fireEvent.click(screen.getByRole("button", { name: "Connection details & revocation" }));
+ expect(screen.getByText(preview.revoke_command).closest("pre")).not.toBeNull();
+ fireEvent.click(screen.getByRole("button", { name: "Copy code" }));
+ expect(await screen.findByRole("button", { name: "Copied" })).toBeVisible();
+ expect(mocks.copy).toHaveBeenCalledWith(preview.revoke_command);
+ expect(mocks.connect).not.toHaveBeenCalled();
+ expect(mocks.action.mock.calls.some(([action]) => action === "remote.pair_finish")).toBe(false);
+ });
it("explains an existing instance and saves its additional authorization only on confirmation", async () => {
mocks.action.mockImplementation(async (action: string) => {
if (action === "remote.pair_preview") return { ...preview, existing_connection: { id: "saved-server", name: "My team", connected: true } };
diff --git a/webui/src/tests/remote-instances.test.tsx b/webui/src/tests/remote-instances.test.tsx
index 00f079755..64ae85828 100644
--- a/webui/src/tests/remote-instances.test.tsx
+++ b/webui/src/tests/remote-instances.test.tsx
@@ -7,6 +7,7 @@ import { Sidebar } from "@/components/Sidebar";
import { HOST_BRIDGE } from "@/components/remote/host-bridge";
import { readSelectedRemote, readRecentRemotes, rememberSelectedRemote, validateRemoteConnection, type RemoteConnection } from "@/lib/remote-instances";
import i18n from "@/i18n";
+import * as clipboard from "@/lib/clipboard";
import { clearPairReturn, initializePairReturn } from "@/lib/remote-pair-return";
import type { Window as HappyWindow } from "happy-dom";
@@ -91,6 +92,24 @@ function chooseExistingSSH() {
}
describe("remote instance UX", () => {
+ it("shows revocation as a shared copyable code block without executing it or forgetting the connection", async () => {
+ const command = "nanobot remote revoke 0dec816f-55e8-47ab-a8ad-13251e2a4f30 --ssh-user ubuntu";
+ const copy = vi.spyOn(clipboard, "copyTextToClipboard").mockResolvedValue(true);
+ mocks.read.mockResolvedValue({ available: true, profiles: [{ ...profile, paired: true, revoke_command: command }] });
+ view(); await openDirectory();
+ fireEvent.pointerDown(screen.getByRole("button", { name: "Manage Team server" }), { button: 0, ctrlKey: false });
+ fireEvent.click(screen.getByRole("menuitem", { name: "Forget server" }));
+ const dialog = await screen.findByRole("dialog", { name: "Forget Team server?" });
+ const code = within(dialog).getByText(command);
+ expect(code.closest("pre")).not.toBeNull();
+ expect(code.closest(".not-prose")).toHaveClass("rounded-floating", "bg-secondary/70", "[&_pre]:[overflow-wrap:anywhere]");
+ fireEvent.click(within(dialog).getByRole("button", { name: "Copy code" }));
+ expect(await within(dialog).findByRole("button", { name: "Copied" })).toBeVisible();
+ expect(copy).toHaveBeenCalledWith(command);
+ expect(mocks.request).not.toHaveBeenCalled();
+ fireEvent.click(within(dialog).getByRole("button", { name: "Cancel", exact: true }));
+ expect(mocks.request).not.toHaveBeenCalled();
+ });
it("shows one verified instance in management and the switcher while retaining both grants in details", async () => {
const second = { ...profile, id: "f1b18099-61d5-41d7-9c1d-6f647f7000e5", paired: true, instance_id: profile.id };
mocks.read.mockResolvedValue({ available: true, profiles: [{ ...profile, paired: true, instance_id: profile.id }, second] });