Skip to content

The agent that grows with you

feat(bot-mode): render room @mentions as inline references and add Reply to @bot

teknium1e04ce9d12288
diff --git a/apps/desktop/src/components/assistant-ui/markdown-text.tsx b/apps/desktop/src/components/assistant-ui/markdown-text.tsx
index 4d219f747f1..62606b61ea8 100644
--- a/apps/desktop/src/components/assistant-ui/markdown-text.tsx
+++ b/apps/desktop/src/components/assistant-ui/markdown-text.tsx
@@ -8,7 +8,7 @@ import {
tailBoundedRemend
} from '@assistant-ui/react-streamdown'
import type { code as streamdownCode } from '@streamdown/code'
-import { type ComponentProps, memo, useEffect, useMemo, useState } from 'react'
+import { type ComponentProps, memo, type ReactNode, useEffect, useMemo, useState } from 'react'
import { ExpandableBlock } from '@/components/chat/expandable-block'
import { PreviewAttachment } from '@/components/chat/preview-attachment'
@@ -463,6 +463,11 @@ interface MarkdownTextSurfaceProps {
disableArtifacts?: boolean
/** Foreign history must not load images or mount live transcript directives. */
previewOnly?: boolean
+ /** Re-render the direct text nodes of paragraph-level containers (p / li /
+ * td) — a transcript surface styles its own inline tokens (a Bot Mode room's
+ * routed @mentions) without owning the Markdown pipeline. Nested inline
+ * markup and code are left as rendered. */
+ decorateText?: (children: ReactNode) => ReactNode
}
// Headings shrink to chat scale rather than the prose default (h1≈xl). Kept
@@ -578,6 +583,7 @@ function MarkdownParagraph({
function MarkdownTextSurface({
containerClassName,
containerProps,
+ decorateText,
defer,
disableArtifacts,
previewOnly,
@@ -608,11 +614,13 @@ function MarkdownTextSurface({
h4: ({ className, ...props }: ComponentProps<'h4'>) => (
<h4 className={cn('my-1 font-semibold', HEADING_SIZES.h4, className)} {...props} />
),
- p: (props: ComponentProps<'p'>) =>
+ p: ({ children, ...props }: ComponentProps<'p'>) =>
previewOnly ? (
- <p {...props} />
+ <p {...props}>{decorateText ? decorateText(children) : children}</p>
) : (
- <MarkdownParagraph {...props} scratchpad={scratchpad} streaming={isStreaming} />
+ <MarkdownParagraph {...props} scratchpad={scratchpad} streaming={isStreaming}>
+ {decorateText ? decorateText(children) : children}
+ </MarkdownParagraph>
),
a: previewOnly ? ({ children }: ComponentProps<'a'>) => <span>{children}</span> : MarkdownLink,
// Inline code must not vote when an ancestor resolves `dir="auto"`
@@ -659,8 +667,10 @@ function MarkdownTextSurface({
ol: ({ className, ...props }: ComponentProps<'ol'>) => (
<ol className={cn('my-1 gap-0', className)} dir="auto" {...props} />
),
- li: ({ className, ...props }: ComponentProps<'li'>) => (
- <li className={cn('leading-(--dt-line-height)', className)} {...props} />
+ li: ({ children, className, ...props }: ComponentProps<'li'>) => (
+ <li className={cn('leading-(--dt-line-height)', className)} {...props}>
+ {decorateText ? decorateText(children) : children}
+ </li>
),
// Columns are drag-resizable; the widths live outside the transcript
// (see markdown-table-widths.ts) so a new turn or a session switch
@@ -670,8 +680,10 @@ function MarkdownTextSurface({
<thead className={cn('m-0 bg-muted/35 text-muted-foreground', className)} {...props} />
),
th: ResizableMarkdownTh,
- td: ({ className, ...props }: ComponentProps<'td'>) => (
- <td className={cn('px-2.5 py-1.5 align-top text-[0.8125rem] leading-snug', className)} {...props} />
+ td: ({ children, className, ...props }: ComponentProps<'td'>) => (
+ <td className={cn('px-2.5 py-1.5 align-top text-[0.8125rem] leading-snug', className)} {...props}>
+ {decorateText ? decorateText(children) : children}
+ </td>
),
img: previewOnly ? ({ alt }: ComponentProps<'img'>) => <span>{alt}</span> : MarkdownImage,
// ```mermaid / ```svg fences route to their lazy renderers; substantial
@@ -696,7 +708,7 @@ function MarkdownTextSurface({
)
}
}) as StreamdownTextComponents,
- [disableArtifacts, isStreaming, previewOnly, scratchpad]
+ [decorateText, disableArtifacts, isStreaming, previewOnly, scratchpad]
)
if (text.length > MAX_MARKDOWN_CHARS) {
@@ -761,8 +773,19 @@ interface MarkdownTextContentProps extends MarkdownTextSurfaceProps {
* against the ACTIVE gateway, so a message written on another machine (a
* Connections Bot in a cross-machine room) must not have its path read here —
* that is a broken image at best and a same-path local file at worst. */
-export function MessageTextContent({ media = true, text }: { media?: boolean; text: string }) {
- return <MarkdownTextContent disableArtifacts isRunning={false} text={media ? renderMediaTags(text) : text} />
+export function MessageTextContent({
+ decorateText,
+ media = true,
+ text
+}: Pick<MarkdownTextSurfaceProps, 'decorateText'> & { media?: boolean; text: string }) {
+ return (
+ <MarkdownTextContent
+ decorateText={decorateText}
+ disableArtifacts
+ isRunning={false}
+ text={media ? renderMediaTags(text) : text}
+ />
+ )
}
export function MarkdownTextContent({ isRunning, text, ...surfaceProps }: MarkdownTextContentProps) {
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx b/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
index 76953511616..67228b24c0c 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
@@ -42,6 +42,7 @@ import {
$botMeta,
$lastRoster,
botHandle,
+ botMentionTag,
botMetaV2Active,
botSourceStatus,
noteBotMetaWrite,
@@ -80,6 +81,7 @@ import {
groupWorkspaceOwnerKey,
liveGroupChatNames
} from './group-membership'
+import { groupMentionComponents, groupMentionText } from './group-mention-text'
import {
clearGroupComposerDraft,
closeGroupChatMainTab,
@@ -973,6 +975,35 @@ export function GroupChatWorkspace({ group, members, onBack, visible = true }: G
</Button>
)
+ // #91359: recognized @mentions render as inline references; recomputed
+ // only when the roster changes since the classifier consults the members.
+ const mentionComponents = useMemo(() => groupMentionComponents(members), [members])
+ const mentionText = useMemo(() => groupMentionText(members), [members])
+
+ // #89883: answer ONE bot from its message. Seeds `@tag ` into the composer
+ // that owns this entry's thread — the open reply box when it is this
+ // thread's, else the main composer — so parseGroupChatMentions routes the
+ // next turn to that member only. Insert-only: the user still sends.
+ const replyToMember = (entry: GroupMessage, member: GroupMember | null) => {
+ const tag = String(botMentionTag(member || { name: entry.from.name }) || botHandle(entry.from.name, member || undefined)).trim()
+
+ if (!tag) {
+ return
+ }
+
+ const seed = (current: string) => (current.includes(`@${tag}`) ? current : `@${tag} ${current}`.replace(/\s+$/, ' '))
+ const thread = groupThreadOf(entry)
+
+ if (replyThread === thread) {
+ setReplyDrafts(prev => ({
+ ...prev,
+ [thread]: seed(prev[thread] || '')
+ }))
+ } else {
+ setDraft(seed)
+ }
+ }
+
// One log entry, rendered exactly as before conversation folding existed.
const renderEntry = (entry: GroupMessage, index: number) => {
const isUser = entry.from.kind === 'user'
@@ -1054,9 +1085,22 @@ export function GroupChatWorkspace({ group, members, onBack, visible = true }: G
</Button>
)}
<span className="text-[0.625rem] text-(--ui-text-quaternary)">{relativeTime(entry.at)}</span>
- {entry.text.trim() ? (
- <div className="ml-auto shrink-0 opacity-0 pointer-events-none group-hover:pointer-events-auto group-hover:opacity-100 focus-within:pointer-events-auto focus-within:opacity-100">
- <CopyButton appearance="icon" buttonSize="icon" stopPropagation text={entry.text} />
+ {entry.text.trim() || !isUser ? (
+ <div className="ml-auto flex shrink-0 items-center gap-0.5 opacity-0 pointer-events-none group-hover:pointer-events-auto group-hover:opacity-100 focus-within:pointer-events-auto focus-within:opacity-100">
+ {isUser ? null : (
+ <Tip label={`Reply to @${botMentionTag(member || { name: entry.from.name }) || botHandle(entry.from.name, member || undefined)}`}>
+ <Button
+ aria-label={`Reply to ${display}`}
+ className="text-(--ui-text-tertiary) hover:text-foreground"
+ onClick={() => replyToMember(entry, member)}
+ size="icon"
+ variant="ghost"
+ >
+ <Codicon name="reply" />
+ </Button>
+ </Tip>
+ )}
+ {entry.text.trim() ? <CopyButton appearance="icon" buttonSize="icon" stopPropagation text={entry.text} /> : null}
</div>
) : null}
</div>
@@ -1066,9 +1110,9 @@ export function GroupChatWorkspace({ group, members, onBack, visible = true }: G
data-selectable-text="true"
>
{MessageTextContent ? (
- <MessageTextContent media={!member?.remoteSource} text={entry.text} />
+ <MessageTextContent decorateText={mentionText} media={!member?.remoteSource} text={entry.text} />
) : Streamdown ? (
- <Streamdown>{entry.text}</Streamdown>
+ <Streamdown components={mentionComponents}>{entry.text}</Streamdown>
) : (
entry.text
)}
diff --git a/apps/desktop/src/plugins/hermes-bots/group-mention-text.test.tsx b/apps/desktop/src/plugins/hermes-bots/group-mention-text.test.tsx
new file mode 100644
index 00000000000..63e475739a9
--- /dev/null
+++ b/apps/desktop/src/plugins/hermes-bots/group-mention-text.test.tsx
@@ -0,0 +1,53 @@
+/**
+ * #91359 — recognized group @mentions render as semantic inline references;
+ * everything else stays prose. The classifier is the round loop's own parser,
+ * so a token is styled exactly when routing would honour it.
+ */
+
+import { renderToStaticMarkup } from 'react-dom/server'
+import { describe, expect, it, vi } from 'vitest'
+
+import { classifyGroupMention, renderGroupMentionText } from './group-mention-text'
+import type { GroupMember } from './types'
+
+vi.mock('@hermes/plugin-sdk', async () => {
+ const { atom } = await import('nanostores')
+
+ return {
+ atom,
+ host: {
+ request: vi.fn(),
+ state: { connectionId: { get: () => 'local' }, profile: { get: () => 'default' } }
+ },
+ queryClient: { invalidateQueries: vi.fn() },
+ useQuery: vi.fn(),
+ useValue: vi.fn()
+ }
+})
+
+vi.mock('./shared', () => ({ getPluginCtx: () => null, ID: 'hermes-bots' }))
+
+const members = [{ name: 'planner', handle: 'planner' }, { name: 'reviewer-mac-mini', handle: 'reviewer-mac-mini' }] as GroupMember[]
+
+describe('group mention rendering', () => {
+ it('classifies seated bots, the human and broadcasts, and leaves unknown tokens plain', () => {
+ expect(classifyGroupMention('planner', members)).toBe('agent')
+ expect(classifyGroupMention('reviewer-mac-mini', members)).toBe('agent')
+ expect(classifyGroupMention('user', members)).toBe('human')
+ expect(classifyGroupMention('everyone', members)).toBe('broadcast')
+ expect(classifyGroupMention('all', members)).toBe('broadcast')
+ expect(classifyGroupMention('stranger', members)).toBeNull()
+ })
+
+ it('wraps only recognized mentions and keeps the visible text byte-identical', () => {
+ const text = '@planner compare the options, then @user picks; mail [email protected] — @everyone review'
+ const html = renderToStaticMarkup(<>{renderGroupMentionText(text, members)}</>)
+
+ expect(html).toContain('<span class="ref font-medium" data-ref="agent"')
+ expect(html).toContain('data-ref="human"')
+ expect(html).toContain('data-ref="broadcast"')
+ // `@example.com` is not a room identity — no span around it.
+ expect(html).not.toContain('data-ref="agent" title="Bot in this room">@example')
+ expect(html.replace(/<[^>]+>/g, '')).toBe(text)
+ })
+})
diff --git a/apps/desktop/src/plugins/hermes-bots/group-mention-text.tsx b/apps/desktop/src/plugins/hermes-bots/group-mention-text.tsx
new file mode 100644
index 00000000000..be5be07cf65
--- /dev/null
+++ b/apps/desktop/src/plugins/hermes-bots/group-mention-text.tsx
@@ -0,0 +1,105 @@
+/**
+ * Semantic @mention rendering for group-room transcripts (#91359).
+ *
+ * Presentation only: the stored text, the copy button, prompt payloads and
+ * `parseGroupChatMentions` are untouched. At render time every `@token` in a
+ * text node is classified with the SAME parser the round loop uses, so a token
+ * is styled exactly when routing would honour it — unknown handles, e-mail
+ * addresses and Matrix ids stay plain prose. Recognized mentions become the
+ * app's inline-reference form (`.ref` + `data-ref` kind: `agent` / `human` /
+ * `broadcast`), i.e. accent text with weight, never a pill.
+ */
+
+import type { ComponentProps, ReactNode } from 'react'
+import { Children, Fragment } from 'react'
+
+import { parseGroupChatMentions } from './group-rounds'
+import type { GroupMember } from './types'
+
+export type GroupMentionKind = 'agent' | 'broadcast' | 'human'
+
+const MENTION = /@([a-z0-9][a-z0-9._-]*)/gi
+
+/** What a lone `@token` means in this room, or null when routing ignores it. */
+export function classifyGroupMention(token: string, members: GroupMember[]): GroupMentionKind | null {
+ const handle = token.toLowerCase()
+
+ if (handle === 'user') {
+ return 'human'
+ }
+
+ const parsed = parseGroupChatMentions(`@${token}`, members)
+
+ if (parsed.everyone) {
+ return 'broadcast'
+ }
+
+ return parsed.mentioned.size ? 'agent' : null
+}
+
+const TITLES: Record<GroupMentionKind, string> = {
+ agent: 'Bot in this room',
+ broadcast: 'Everyone in the room',
+ human: 'You — the room is waiting on a human'
+}
+
+/** Split one text node into prose and recognized mention spans. */
+export function renderGroupMentionText(text: string, members: GroupMember[]): ReactNode {
+ const parts: ReactNode[] = []
+ let last = 0
+
+ for (const match of text.matchAll(MENTION)) {
+ const kind = classifyGroupMention(match[1], members)
+
+ if (!kind) {
+ continue
+ }
+
+ const start = match.index ?? 0
+
+ if (start > last) {
+ parts.push(text.slice(last, start))
+ }
+
+ parts.push(
+ <span className="ref font-medium" data-ref={kind} key={`${start}:${match[0]}`} title={TITLES[kind]}>
+ {match[0]}
+ </span>
+ )
+ last = start + match[0].length
+ }
+
+ if (!parts.length) {
+ return text
+ }
+
+ if (last < text.length) {
+ parts.push(text.slice(last))
+ }
+
+ return <Fragment>{parts}</Fragment>
+}
+
+function mapTextChildren(children: ReactNode, members: GroupMember[]): ReactNode {
+ return Children.map(children, child => (typeof child === 'string' ? renderGroupMentionText(child, members) : child))
+}
+
+/** `decorateText` hook for the shell's `MessageTextContent`: the same
+ * splitter, applied to the direct text nodes of its paragraph-level
+ * containers (p / li / td). */
+export function groupMentionText(members: GroupMember[]) {
+ return (children: ReactNode) => mapTextChildren(children, members)
+}
+
+/** Streamdown `components` override (older shells without
+ * `MessageTextContent`): paragraph-level containers re-render
+ * their direct text nodes through the mention splitter. Nested inline
+ * markup (bold, links) and code stay as Streamdown produced them, so a
+ * mention inside a backtick span is left literal on purpose. */
+export function groupMentionComponents(members: GroupMember[]) {
+ return {
+ li: ({ children, ...props }: ComponentProps<'li'>) => <li {...props}>{mapTextChildren(children, members)}</li>,
+ p: ({ children, ...props }: ComponentProps<'p'>) => <p {...props}>{mapTextChildren(children, members)}</p>,
+ td: ({ children, ...props }: ComponentProps<'td'>) => <td {...props}>{mapTextChildren(children, members)}</td>
+ }
+}
diff --git a/apps/desktop/src/styles.css b/apps/desktop/src/styles.css
index 08f7343920e..e1ea2271e05 100644
--- a/apps/desktop/src/styles.css
+++ b/apps/desktop/src/styles.css
@@ -852,6 +852,21 @@
--ref-color: color-mix(in srgb, var(--ui-warm) 82%, var(--foreground));
}
+/* Bot Mode group-room mentions (#91359): a routed @bot reads as an agent
+ reference, @user as a human handoff the room is waiting on, and
+ @everyone/@all as a quieter broadcast. Text, not pills — same contract. */
+[data-ref='agent'] {
+ --ref-color: color-mix(in srgb, var(--ui-accent) 82%, var(--foreground));
+}
+
+[data-ref='human'] {
+ --ref-color: color-mix(in srgb, var(--ui-warm) 82%, var(--foreground));
+}
+
+[data-ref='broadcast'] {
+ --ref-color: color-mix(in srgb, var(--foreground) 70%, var(--ui-accent));
+}
+
.ref {
--ref-color: var(--dt-primary);
diff --git a/website/docs/user-guide/bot-mode.md b/website/docs/user-guide/bot-mode.md
index f87284aa304..3b263f3c396 100644
--- a/website/docs/user-guide/bot-mode.md
+++ b/website/docs/user-guide/bot-mode.md
@@ -129,6 +129,9 @@ Use the **Move up** and **Move down** arrows beside a room to choose its positio
- Each member keeps its own persistent room session, so room context survives like any other conversation.
- **Not every Bot replies to every message.** Speaking is each member's own choice — a Bot replies only when it has something new to add and passes otherwise, and @-mentioning specific members scopes the round to them. Expect the members you addressed (or whoever has something to say) to speak, and the rest to stay quiet.
- **Rooms keep running when you close the Desktop.** When every member of a room lives on the same gateway, that gateway owns turn scheduling through a durable driver: closing Hermes Desktop (or losing its connection) does not stop a room mid-discussion, and the Desktop simply catches up from the room's log when it reconnects. `groups.capabilities` on the gateway reports `driver: true` when this applies. More than one room worker may share a home — the messaging gateway (`hermes gateway run`) and the Desktop's own backend (`hermes serve`) both run one — and whichever holds the room's driver lease runs the next turn; a member's room session is held only for the duration of its turn, so the lease can move between workers without a turn being refused. Rooms whose members span several machines are different: each member's turns run on its own gateway, and the cross-connection courier described under *Bot-to-bot messaging* still applies to them.
+
+- **Rooms keep running when you close the Desktop.** When every member of a room lives on the same gateway, that gateway owns turn scheduling through a durable driver: closing Hermes Desktop (or losing its connection) does not stop a room mid-discussion, and the Desktop simply catches up from the room's log when it reconnects. `groups.capabilities` on the gateway reports `driver: true` when this applies. Rooms whose members span several machines are different: each member's turns run on its own gateway, and the cross-connection courier described under *Bot-to-bot messaging* still applies to them.
+- **Mentions read as identities.** In the transcript a routed `@bot` mention, the human handoff `@user`, and the broadcasts `@everyone` / `@all` render as inline references (accent text, not pills); unknown `@words` and e-mail addresses stay plain. Hover a Bot's message and use **Reply to @handle** to seed `@handle ` into the composer, so your next send goes to that Bot only — **Reply in thread** still continues the whole thread.
- **Rooms can span machines.** The New Group Chat picker seats Bots from any registered connection; each member's turns run on its own machine, in its own room session there. Cross-machine members carry a device badge (`dixie · Mac Mini`) in the room and in other members' transcripts, and the disambiguated `@name-device` handle works in room mentions — so same-named agents on two machines never blur together.
- **Plugins can watch members work.** The durable room log records `turn.started` and `turn.settled`; what a member does in between (tools, approvals, streamed text) is projected to plugins through the [`on_room_member_activity`](/user-guide/features/hooks#on_room_member_activity) hook with room, member and turn coordinates, so community clients can build tool cards and live member status on top of Group Chat without reading Hermes internals.