Skip to content

The agent that grows with you

fix(desktop): route url chips through the link surface

DavidMetcalfe010362cce4e8
diff --git a/apps/desktop/src/app/chat/composer/directive-actions.test.tsx b/apps/desktop/src/app/chat/composer/directive-actions.test.tsx
index b61a598538f..dc81c446f04 100644
--- a/apps/desktop/src/app/chat/composer/directive-actions.test.tsx
+++ b/apps/desktop/src/app/chat/composer/directive-actions.test.tsx
@@ -2,6 +2,7 @@ import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { I18nProvider } from '@/i18n'
+import { IS_MAC } from '@/lib/keybinds/combo'
import { $previewTabs, closeRightRail } from '@/store/preview'
import { ComposerDirectiveActions } from './directive-actions'
@@ -79,6 +80,22 @@ describe('ComposerDirectiveActions', () => {
expect(pillValue()).toBeNull()
})
+ // Platform-specific on purpose (same rule as lib/external-link.test.tsx):
+ // ⌘ on macOS, Ctrl elsewhere. The suite runs as non-mac.
+ it('sends the pill to the system browser on the platform open-elsewhere modifier', () => {
+ const openExternal = vi.fn().mockResolvedValue(undefined)
+
+ desktopWindow.hermesDesktop = { openExternal } as unknown as Window['hermesDesktop']
+
+ const editor = mountEditor([{ kind: 'url', value: 'https://example.com/docs' }])
+
+ hover(chips(editor, 'url')[0]!)
+ fireEvent.click(screen.getByRole('button'), IS_MAC ? { metaKey: true } : { ctrlKey: true })
+
+ expect(openExternal).toHaveBeenCalledWith('https://example.com/docs')
+ expect($previewTabs.get()).toHaveLength(0)
+ })
+
it('runs the kind-specific action — a session chip opens the session', async () => {
const editor = mountEditor([{ kind: 'session', value: 'default/20260722_204335_d62c16' }])
diff --git a/apps/desktop/src/app/chat/composer/directive-actions.tsx b/apps/desktop/src/app/chat/composer/directive-actions.tsx
index 07e46d03738..edf8c100071 100644
--- a/apps/desktop/src/app/chat/composer/directive-actions.tsx
+++ b/apps/desktop/src/app/chat/composer/directive-actions.tsx
@@ -17,6 +17,7 @@ import { DIRECTIVE_ACTIONS, type DirectiveAction } from '@/components/assistant-
import { composerFloatingPill } from '@/components/chat/composer-dock'
import { Codicon } from '@/components/ui/codicon'
import { useI18n } from '@/i18n'
+import { wantsNativeBrowser } from '@/lib/external-link'
import { cn } from '@/lib/utils'
/** Moving between the chip and the pill crosses a gap where neither is hovered.
@@ -139,8 +140,11 @@ export function ComposerDirectiveActions({ editorRef }: { editorRef: RefObject<H
>
<button
className={cn(composerFloatingPill, 'shadow-nous')}
- onClick={() => {
- anchor.action.run(anchor.value)
+ // The pill is the composer's stand-in for clicking the link, so it
+ // honours the same convention: ⌘/Ctrl-click escapes to the system
+ // browser instead of the in-app pane.
+ onClick={event => {
+ anchor.action.run(anchor.value, { native: wantsNativeBrowser(event.nativeEvent) })
setAnchor(null)
}}
// Never let the press reach the editor: mousedown inside a
diff --git a/apps/desktop/src/app/context-menu/app-context-menu.test.tsx b/apps/desktop/src/app/context-menu/app-context-menu.test.tsx
index 2e8a97b9bfb..293bdda821f 100644
--- a/apps/desktop/src/app/context-menu/app-context-menu.test.tsx
+++ b/apps/desktop/src/app/context-menu/app-context-menu.test.tsx
@@ -3,6 +3,7 @@ import { MemoryRouter } from 'react-router'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { registerTerminalContextMenu } from '@/app/right-sidebar/terminal/terminal-context-menu'
+import { DirectiveContent } from '@/components/assistant-ui/directive-text'
import { ContextMenu, ContextMenuTrigger, HERMES_CONTEXT_MENU_TRIGGER_ATTR } from '@/components/ui/context-menu'
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog'
import { formatCombo } from '@/lib/keybinds/combo'
@@ -107,6 +108,23 @@ describe('AppContextMenu', () => {
expect(screen.queryByText('Copy resolved URL')).toBeNull()
})
+ // The url chip used to be a `<button>`: `resolveDomTarget` only knows
+ // `a[href]`, so the right-click fell through to the shell fallback menu.
+ it('offers the link verbs on a message url chip right-click', async () => {
+ installBridge()
+ mountMenu()
+ // The coordinator binds to window in the capture phase, so a second
+ // render alongside the menu is fine — same as a real transcript.
+ render(<DirectiveContent text="@url:`https://example.com/pr/1`" />)
+ const chip = document.querySelector('[data-slot="aui_directive-chip"]')!
+
+ fireEvent.contextMenu(chip)
+
+ expect(await screen.findByText('Open in in-app browser')).toBeTruthy()
+ expect(screen.getByText('Open in external browser')).toBeTruthy()
+ expect(screen.getByText('Copy URL')).toBeTruthy()
+ })
+
it('opens the in-app browser from the link menu', async () => {
installBridge()
mountMenu()
diff --git a/apps/desktop/src/components/assistant-ui/directive-chip-links.test.tsx b/apps/desktop/src/components/assistant-ui/directive-chip-links.test.tsx
new file mode 100644
index 00000000000..24e2d01bb88
--- /dev/null
+++ b/apps/desktop/src/components/assistant-ui/directive-chip-links.test.tsx
@@ -0,0 +1,71 @@
+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+import { afterEach, describe, expect, it, vi } from 'vitest'
+
+import { IS_MAC } from '@/lib/keybinds/combo'
+import { $previewTabs, closeRightRail } from '@/store/preview'
+
+import { DirectiveContent } from './directive-text'
+
+const desktopWindow = window as unknown as { hermesDesktop?: Window['hermesDesktop'] }
+
+const PR_URL = 'https://github.com/NousResearch/hermes-agent/pull/107950'
+
+function installDesktopBridge() {
+ const openExternal = vi.fn().mockResolvedValue(undefined)
+
+ desktopWindow.hermesDesktop = {
+ fetchLinkTitle: vi.fn().mockResolvedValue(''),
+ openExternal
+ } as unknown as Window['hermesDesktop']
+
+ return openExternal
+}
+
+afterEach(() => {
+ closeRightRail()
+ vi.restoreAllMocks()
+ cleanup()
+ delete desktopWindow.hermesDesktop
+ document.body.replaceChildren()
+})
+
+// The wire form of a url chip in a SENT user message: a `<button>` had none of
+// the gestures a real link gets, which is exactly what these tests pin.
+describe('sent-message url chip', () => {
+ it('opens the in-app preview pane on a plain click', async () => {
+ const openExternal = installDesktopBridge()
+
+ render(<DirectiveContent text={`@url:\`${PR_URL}\``} />)
+
+ fireEvent.click(screen.getByRole('link'))
+
+ expect(openExternal).not.toHaveBeenCalled()
+ await waitFor(() => expect($previewTabs.get().at(-1)?.target.url).toBe(PR_URL))
+ })
+
+ // Platform-specific on purpose (same rule as lib/external-link.test.tsx):
+ // ⌘ on macOS, Ctrl elsewhere. The suite runs as non-mac.
+ it('escapes to the system browser on the platform open-elsewhere modifier', () => {
+ const openExternal = installDesktopBridge()
+
+ render(<DirectiveContent text={`@url:\`${PR_URL}\``} />)
+
+ fireEvent.click(screen.getByRole('link'), IS_MAC ? { metaKey: true } : { ctrlKey: true })
+
+ expect(openExternal).toHaveBeenCalledWith(PR_URL)
+ expect($previewTabs.get()).toHaveLength(0)
+ })
+
+ it('escapes to the system browser on middle-click', () => {
+ const openExternal = installDesktopBridge()
+
+ render(<DirectiveContent text={`@url:\`${PR_URL}\``} />)
+
+ // No fireEvent.auxClick in this Testing Library version — dispatch the
+ // real `auxclick` event React's onAuxClick listens for.
+ fireEvent(screen.getByRole('link'), new MouseEvent('auxclick', { bubbles: true, button: 1 }))
+
+ expect(openExternal).toHaveBeenCalledWith(PR_URL)
+ expect($previewTabs.get()).toHaveLength(0)
+ })
+})
diff --git a/apps/desktop/src/components/assistant-ui/directive-text.tsx b/apps/desktop/src/components/assistant-ui/directive-text.tsx
index 3e21698a6df..98fc0467c57 100644
--- a/apps/desktop/src/components/assistant-ui/directive-text.tsx
+++ b/apps/desktop/src/components/assistant-ui/directive-text.tsx
@@ -8,7 +8,7 @@ import { Fragment, useEffect, useMemo, useState } from 'react'
import { ZoomableImage } from '@/components/chat/zoomable-image'
import type { I18nContextValue } from '@/i18n'
import { extractEmbeddedImages } from '@/lib/embedded-images'
-import { openLink } from '@/lib/external-link'
+import { ExternalLink, openLink } from '@/lib/external-link'
import { triggerHaptic } from '@/lib/haptics'
import { gatewayMediaDataUrl, isRemoteGateway } from '@/lib/media'
import { useSessionLinkTitle } from '@/lib/session-link-title'
@@ -474,9 +474,15 @@ export function openSessionRef(value: string) {
* table. `icon`/`label` are for the pill; the transcript chip carries its own
* glyph and only reads `run`. */
export interface DirectiveAction {
+ /** The web target of a reference kind that IS a link. A kind with an `href`
+ * renders as a real anchor so it inherits the one link surface's gestures:
+ * plain click opens the in-app pane, ⌘/Ctrl-click (or middle-click) escapes
+ * to the system browser, and the context-menu coordinator resolves the link
+ * verbs. A button has neither. */
+ href?: (value: string) => string
icon: string
label: (t: I18nContextValue['t']) => string
- run: (value: string) => void
+ run: (value: string, options?: { native?: boolean }) => void
}
export const DIRECTIVE_ACTIONS: Record<string, DirectiveAction> = {
@@ -486,6 +492,7 @@ export const DIRECTIVE_ACTIONS: Record<string, DirectiveAction> = {
run: openSessionRef
},
url: {
+ href: value => value,
icon: 'link-external',
label: t => t.composer.openDirective,
run: openLink
@@ -539,17 +546,22 @@ const SlashChip: FC<{ kind: SlashChipKind; label: string; value: string }> = ({
</span>
)
-/** A directive reference in a sent message. A kind with a `DIRECTIVE_ACTIONS`
- * entry (a url, …) renders as a real button that runs it on click; everything
- * else is inert text. `onClick` overrides for chips that resolve their target
- * themselves (session, which needs the async navigator). */
+/** A directive reference in a sent message. A kind whose action declares an
+ * `href` (url) renders as a real anchor — every transcript link's gestures
+ * come from `ExternalLink` and the context-menu coordinator. An action
+ * without an `href` (a session, or an `onClick` override) stays a button;
+ * a kind with no action is an inert span. */
const DirectiveChip: FC<{
type: string
label: string
id: string
onClick?: () => void
}> = ({ type, label, id, onClick }) => {
- const activate = onClick ?? (DIRECTIVE_ACTIONS[type] ? () => DIRECTIVE_ACTIONS[type]!.run(id) : undefined)
+ // An `onClick` override is a bespoke activation, not the kind's link action —
+ // an override must not turn its carrier into a link.
+ const action = onClick ? undefined : DIRECTIVE_ACTIONS[type]
+ const activate = onClick ?? (action ? () => action.run(id) : undefined)
+ const href = action?.href?.(id)
const body = (
<>
@@ -565,6 +577,16 @@ const DirectiveChip: FC<{
title: id
}
+ if (href) {
+ return (
+ // The explicit className must come after the spread so it wins over the
+ // refAttrs className — `ExternalLink` prepends its own `ref` class.
+ <ExternalLink {...props} className="wrap-anywhere cursor-pointer" href={href}>
+ {body}
+ </ExternalLink>
+ )
+ }
+
return activate ? (
<button {...props} onClick={activate} type="button">
{body}
diff --git a/apps/desktop/src/components/assistant-ui/session-ref-open.test.tsx b/apps/desktop/src/components/assistant-ui/session-ref-open.test.tsx
index f8f3c5648ca..4e08d584e07 100644
--- a/apps/desktop/src/components/assistant-ui/session-ref-open.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/session-ref-open.test.tsx
@@ -60,7 +60,9 @@ describe('url refs open in the browser pane', () => {
const chip = screen.getByTitle('https://example.com/docs')
- expect(chip.tagName).toBe('BUTTON')
+ // A real anchor now — that is what gives the chip the link gestures
+ // (⌘-click escape, right-click link menu) that a button never had.
+ expect(chip.tagName).toBe('A')
fireEvent.click(chip)
expect(openExternal).not.toHaveBeenCalled()