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