From 422cf087eeace29abc8e2c5513746a3e0d1c27ac Mon Sep 17 00:00:00 2001
From: Ben Davis <45952064+bmdavis419@users.noreply.github.com>
Date: Fri, 24 Jul 2026 23:50:20 -0700
Subject: [PATCH] fix: make copy buttons work over plain http and surface the
restart command
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
`navigator.clipboard` only exists in a secure context, so it is undefined
over plain http — which is how T3 is reached on a LAN or Tailscale host.
Every copy button on such an origin threw before copying, so nothing landed
on the clipboard and no success state ever rendered. That included the
button handing over a pairing command the user cannot reasonably retype.
Fall back to the legacy execCommand path when the async API is missing, and
also when a secure-context write is rejected, since a permissions-policy or
user-activation refusal can still succeed the old way. Focus restore is
duck-typed rather than `instanceof HTMLElement`: that global is absent in
non-DOM environments, where a bare reference throws instead of being falsy,
and losing focus is never worth failing a copy over.
The restart step spelled its command inline as prose while the two steps
above it had copy buttons, so the one command that activates the pairing was
the one you had to retype. Give it the same treatment, and say plainly that
running in the foreground is expected without an installed service, since it
looks like a hang.
Co-Authored-By: Claude Opus 5 (1M context)
---
.../AddProviderInstanceDialog.logic.ts | 6 ++
.../settings/AddProviderInstanceDialog.tsx | 40 +++++++++-
apps/web/src/hooks/useCopyToClipboard.test.ts | 68 +++++++++++++++++
apps/web/src/hooks/useCopyToClipboard.ts | 75 +++++++++++++++----
4 files changed, 172 insertions(+), 17 deletions(-)
diff --git a/apps/web/src/components/settings/AddProviderInstanceDialog.logic.ts b/apps/web/src/components/settings/AddProviderInstanceDialog.logic.ts
index 10030681c7..bd7ef3caa3 100644
--- a/apps/web/src/components/settings/AddProviderInstanceDialog.logic.ts
+++ b/apps/web/src/components/settings/AddProviderInstanceDialog.logic.ts
@@ -41,6 +41,12 @@ export function createHermesProviderInstanceId(label: string, randomUuid: () =>
*/
export const HERMES_PLUGIN_INSTALL_COMMAND = "./integrations/hermes-t3-gateway/install.sh" as const;
+/**
+ * Activates the pairing. The gateway only constructs the platform adapter at
+ * startup, so it keeps reporting offline until it is restarted.
+ */
+export const HERMES_GATEWAY_RESTART_COMMAND = "hermes gateway restart" as const;
+
export function isHermesInstanceRemovedError(error: unknown): boolean {
return (
typeof error === "object" &&
diff --git a/apps/web/src/components/settings/AddProviderInstanceDialog.tsx b/apps/web/src/components/settings/AddProviderInstanceDialog.tsx
index d86f80db8f..1d2eccc6ba 100644
--- a/apps/web/src/components/settings/AddProviderInstanceDialog.tsx
+++ b/apps/web/src/components/settings/AddProviderInstanceDialog.tsx
@@ -37,6 +37,7 @@ import { AnimatedHeight } from "../AnimatedHeight";
import {
ADD_PROVIDER_WIZARD_STEPS,
createHermesProviderInstanceId,
+ HERMES_GATEWAY_RESTART_COMMAND,
HERMES_PLUGIN_INSTALL_COMMAND,
isHermesInstanceRemovedError,
isOwnedHermesEnrollmentRetry,
@@ -208,6 +209,16 @@ export function AddProviderInstanceDialog({ open, onOpenChange }: AddProviderIns
description: "Run it from the T3 Code checkout on the Hermes host.",
}),
});
+ const { copyToClipboard: copyRestartCommand, isCopied: isRestartCommandCopied } =
+ useCopyToClipboard({
+ target: "Hermes gateway restart command",
+ onCopy: () =>
+ toastManager.add({
+ type: "success",
+ title: "Restart command copied",
+ description: "Run it on the Hermes host to activate the pairing.",
+ }),
+ });
// Rollback of a failed Hermes enrollment must survive the dialog closing
// mid-failure, so the pending undo lives in a ref that an unmount-safe
@@ -675,10 +686,31 @@ export function AddProviderInstanceDialog({ open, onOpenChange }: AddProviderIns
3. Restart the gateway on that host
- Run hermes gateway restart. This step is required — the plugin
- only dials T3 Code after the restart, so nothing is wrong while this panel
- still says {hermesGatewayStatusLabel(hermesWaitingState.statusLabelState)}.
- This page updates itself the moment Hermes connects.
+ This step is required — the plugin only dials T3 Code after the restart, so
+ nothing is wrong while this panel still says{" "}
+ {hermesGatewayStatusLabel(hermesWaitingState.statusLabelState)}. This page
+ updates itself the moment Hermes connects.
+
+
+
+ {HERMES_GATEWAY_RESTART_COMMAND}
+
+
+
+
+ Without an installed service this runs in the foreground and keeps the
+ terminal — that is expected. Use hermes gateway install to run
+ it as a background service instead.
diff --git a/apps/web/src/hooks/useCopyToClipboard.test.ts b/apps/web/src/hooks/useCopyToClipboard.test.ts
index ccac333cd4..8d3194363f 100644
--- a/apps/web/src/hooks/useCopyToClipboard.test.ts
+++ b/apps/web/src/hooks/useCopyToClipboard.test.ts
@@ -55,4 +55,72 @@ describe("writeTextToClipboard", () => {
await expect(writeTextToClipboard("", "plan")).resolves.toBe(false);
expect(writeText).not.toHaveBeenCalled();
});
+
+ // `navigator.clipboard` only exists in a secure context, so it is undefined
+ // over plain http — which is how T3 is reached on a LAN or Tailscale host.
+ // Without the legacy fallback every copy button on such an origin silently
+ // does nothing, including the one handing over a pairing command.
+ it("falls back to execCommand in an insecure context", async () => {
+ const execCommand = vi.fn(() => true);
+ vi.stubGlobal("window", {});
+ vi.stubGlobal("navigator", {});
+ const appended: Array> = [];
+ const makeElement = () => {
+ const element: Record = {
+ style: {},
+ value: "",
+ setAttribute: () => {},
+ select: () => {},
+ setSelectionRange: () => {},
+ remove: () => {},
+ };
+ return element;
+ };
+ vi.stubGlobal("document", {
+ createElement: () => {
+ const element = makeElement();
+ appended.push(element);
+ return element;
+ },
+ body: { appendChild: () => {} },
+ activeElement: null,
+ execCommand,
+ });
+
+ await expect(writeTextToClipboard("hermes t3 connect --url x", "command")).resolves.toBe(true);
+ expect(execCommand).toHaveBeenCalledWith("copy");
+ });
+
+ it("falls back to execCommand when a secure-context write is rejected", async () => {
+ const writeText = vi.fn(() => Promise.reject(new Error("denied")));
+ const execCommand = vi.fn(() => true);
+ vi.stubGlobal("window", {});
+ vi.stubGlobal("navigator", { clipboard: { writeText } });
+ const appended: Array> = [];
+ const makeElement = () => {
+ const element: Record = {
+ style: {},
+ value: "",
+ setAttribute: () => {},
+ select: () => {},
+ setSelectionRange: () => {},
+ remove: () => {},
+ };
+ return element;
+ };
+ vi.stubGlobal("document", {
+ createElement: () => {
+ const element = makeElement();
+ appended.push(element);
+ return element;
+ },
+ body: { appendChild: () => {} },
+ activeElement: null,
+ execCommand,
+ });
+
+ await expect(writeTextToClipboard("value", "command")).resolves.toBe(true);
+ expect(writeText).toHaveBeenCalled();
+ expect(execCommand).toHaveBeenCalledWith("copy");
+ });
});
diff --git a/apps/web/src/hooks/useCopyToClipboard.ts b/apps/web/src/hooks/useCopyToClipboard.ts
index 0129f2d659..7119d97bb1 100644
--- a/apps/web/src/hooks/useCopyToClipboard.ts
+++ b/apps/web/src/hooks/useCopyToClipboard.ts
@@ -24,12 +24,51 @@ export class ClipboardWriteError extends Schema.TaggedErrorClass({