Skip to content

The agent that grows with you

fix(desktop): Bot Mode shows one @hermes when a real 'hermes' profile exists

Teknium5d399eb67acd
diff --git a/apps/desktop/src/lib/browser-connection.ts b/apps/desktop/src/lib/browser-connection.ts
index 9607098b020..fd5e170a32f 100644
--- a/apps/desktop/src/lib/browser-connection.ts
+++ b/apps/desktop/src/lib/browser-connection.ts
@@ -179,7 +179,8 @@ export function createBrowserConnectionBridge({ api, bootstrap }: BrowserConnect
connectionId: LOCAL_CONNECTION_ID,
connectionKind: 'local' as const,
connectionLabel,
- handle: profile === 'default' ? 'hermes' : profile,
+ // A real 'hermes' profile keeps @hermes; the default answers to @default then.
+ handle: profile === 'default' && !profiles.includes('hermes') ? 'hermes' : profile,
profile,
targetProfile: profile,
// Installed here, so listed, but served elsewhere or nowhere.
diff --git a/apps/desktop/src/plugins/hermes-bots/data.hermes-handle.test.ts b/apps/desktop/src/plugins/hermes-bots/data.hermes-handle.test.ts
new file mode 100644
index 00000000000..7927afe8051
--- /dev/null
+++ b/apps/desktop/src/plugins/hermes-bots/data.hermes-handle.test.ts
@@ -0,0 +1,70 @@
+/**
+ * @hermes belongs to the default bot only while its source has no real
+ * (pre-reservation) `hermes` profile. With one, the roster shows exactly one
+ * @hermes — the real profile — and the default answers to @default, so a
+ * typed @hermes reaches the same profile the backend's message_agent does.
+ */
+
+import { describe, expect, it, vi } from 'vitest'
+
+import { botHandle, botMentionTag, claimDefaultHandles, mergeMultiSourceRoster, resolveRosterMentions } from './data'
+import type { RosterRow } from './types'
+
+vi.mock('@hermes/plugin-sdk', async () => {
+ const { atom } = await import('nanostores')
+
+ return { atom, host: {}, queryClient: undefined, useQuery: vi.fn(), useValue: vi.fn() }
+})
+
+vi.mock('./shared', () => ({ getPluginCtx: () => null, ID: 'hermes-bots' }))
+
+function roster(names: string[]): RosterRow[] {
+ const local = { profiles: names.map(name => ({ name })) }
+
+ // What Electron's buildAgentRoster reports for a single local source: bare-name handles.
+ const union = {
+ agents: names.map(profile => ({
+ connectionId: 'local',
+ connectionKind: 'local' as const,
+ connectionLabel: 'This device',
+ handle: profile,
+ profile,
+ targetProfile: profile
+ })),
+ primaryConnectionId: 'local'
+ }
+
+ return mergeMultiSourceRoster(local, union, 'local').profiles as RosterRow[]
+}
+
+describe('the @hermes handle', () => {
+ it.each([
+ [['default', 'researcher'], 'default'],
+ [['default', 'hermes', 'researcher'], 'hermes']
+ ])('roster %j shows one @hermes and a typed @hermes reaches %s', (names, owner) => {
+ const rows = roster(names)
+ const handles = rows.map(row => botHandle(row.name, row))
+
+ expect(handles.filter(handle => handle === 'hermes')).toHaveLength(1)
+ expect(rows.map(row => botMentionTag(row)).filter(tag => tag === 'hermes')).toHaveLength(1)
+ expect(resolveRosterMentions('@hermes ping', rows, { name: 'researcher' }).map(row => row.name)).toEqual([owner])
+ })
+
+ it('names the default @default once a real hermes profile holds the handle', () => {
+ const rows = roster(['default', 'hermes', 'researcher'])
+ const byName = Object.fromEntries(rows.map(row => [row.name, botHandle(row.name, row)]))
+
+ expect(byName).toEqual({ default: 'default', hermes: 'hermes', researcher: 'researcher' })
+ expect(resolveRosterMentions('@default ping', rows, { name: 'researcher' }).map(row => row.name)).toEqual(['default'])
+ })
+
+ it('keeps each source separate: a remote hermes profile does not rename the local default', () => {
+ const rows = claimDefaultHandles<Partial<RosterRow>>([
+ { connectionId: 'local', name: 'default' },
+ { connectionId: 'mini', name: 'default' },
+ { connectionId: 'mini', name: 'hermes' }
+ ])
+
+ expect(rows.map(row => botHandle(String(row.name), row))).toEqual(['hermes', 'default', 'hermes'])
+ })
+})
diff --git a/apps/desktop/src/plugins/hermes-bots/data.ts b/apps/desktop/src/plugins/hermes-bots/data.ts
index 0ac5351c8b3..d86dfa082cb 100644
--- a/apps/desktop/src/plugins/hermes-bots/data.ts
+++ b/apps/desktop/src/plugins/hermes-bots/data.ts
@@ -870,10 +870,12 @@ async function fetchRosterSnapshot(activeConnectionId: null | string | undefined
}
}
- await reconcileBotMeta(Array.isArray(local?.profiles) ? local.profiles : [], issuedAt)
+ const profiles = claimDefaultHandles(Array.isArray(local?.profiles) ? local.profiles : [])
+ await reconcileBotMeta(profiles, issuedAt)
return {
...(local && typeof local === 'object' ? local : {}),
+ ...(Array.isArray(local?.profiles) ? { profiles } : {}),
fetchedAt: issuedAt
}
}
@@ -1168,7 +1170,7 @@ export function mergeMultiSourceRoster(
return {
...local,
- profiles
+ profiles: claimDefaultHandles(profiles)
}
}
@@ -1176,13 +1178,30 @@ export function mergeMultiSourceRoster(
* handle (bare name, or name-device when the profile exists on several
* registered sources) — prefer it when present. The primary profile's
* callable alias is 'hermes' — the mention middleware resolves it back to
- * 'default' — so the word 'default' never surfaces in the UI. */
+ * 'default' — so the word 'default' never surfaces in the UI, unless a real
+ * `hermes` profile on the same source holds that handle (`claimDefaultHandles`). */
export function botHandle(name: string, bot?: Partial<RosterRow> | null): string {
- if (bot?.handle && bot.handle !== name) {
+ if (bot?.handle && bot.handle !== name && !(bot.hermesHandleTaken && bot.handle === 'hermes')) {
return bot.handle
}
- return (name || '').trim().toLowerCase() === 'default' ? 'hermes' : name
+ return (name || '').trim().toLowerCase() === 'default' && !bot?.hermesHandleTaken ? 'hermes' : name
+}
+
+/** Mark each default row whose source also lists a real `hermes` profile, so
+ * that profile keeps @hermes and the roster never shows two (the backend's
+ * `tools/bot_mode_probe._handle` applies the same rule). Rows group by
+ * connection; rows without one are the active source. */
+export function claimDefaultHandles<T extends Partial<RosterRow>>(rows: T[]): T[] {
+ const taken = new Set(
+ rows.filter(row => String(row?.name || '').trim() === 'hermes').map(row => String(row?.connectionId || ''))
+ )
+
+ return rows.map(row =>
+ String(row?.name || '').trim() === 'default' && taken.has(String(row?.connectionId || ''))
+ ? { ...row, hermesHandleTaken: true }
+ : row
+ )
}
/** Taggable @-forms derived from a bot's friendly names — the core profile
diff --git a/apps/desktop/src/plugins/hermes-bots/relay.ts b/apps/desktop/src/plugins/hermes-bots/relay.ts
index 40bd20a167e..bc9beea890c 100644
--- a/apps/desktop/src/plugins/hermes-bots/relay.ts
+++ b/apps/desktop/src/plugins/hermes-bots/relay.ts
@@ -334,12 +334,17 @@ async function relayAgentsOn(
)
const profiles = Array.isArray(res?.profiles) ? res.profiles : []
+ // This connection's default is @hermes only while it has no real 'hermes' profile.
+ const hermesTaken = profiles.some(profile => profile?.name === 'hermes')
const label = labels.get(connection.id) || connection.id
const rows = profiles
.map(profile => ({
profile: String(profile?.name || ''),
- handle: botHandle(profile?.name, profile),
+ handle: botHandle(
+ profile?.name,
+ hermesTaken && profile?.name === 'default' ? { ...profile, hermesHandleTaken: true } : profile
+ ),
connection_id: connection.id,
connection_label: label,
title: String(profile?.ui_meta?.['hermes-bots']?.title || profile?.display_name || ''),
diff --git a/apps/desktop/src/plugins/hermes-bots/soul.ts b/apps/desktop/src/plugins/hermes-bots/soul.ts
index 5050a89bbc1..cf264c9e86d 100644
--- a/apps/desktop/src/plugins/hermes-bots/soul.ts
+++ b/apps/desktop/src/plugins/hermes-bots/soul.ts
@@ -18,7 +18,7 @@ import type { RosterRow } from './types'
* breaking @mentions for customized bots (@wesleysimplicio, #16). */
function messagingProtocolSection(name: string, roster: RosterRow[] | null | undefined): string {
const teammates = (roster || []).filter(b => b.name !== name)
- const handle = botHandle(name)
+ const handle = botHandle(name, (roster || []).find(b => b.name === name))
return [
'## Messaging other agents',
diff --git a/apps/desktop/src/plugins/hermes-bots/types.ts b/apps/desktop/src/plugins/hermes-bots/types.ts
index afff6f7da14..11e687edb24 100644
--- a/apps/desktop/src/plugins/hermes-bots/types.ts
+++ b/apps/desktop/src/plugins/hermes-bots/types.ts
@@ -104,6 +104,10 @@ export interface RosterRow {
/** An offline twin of a selected bot, kept visible so the row doesn't vanish. */
ghost?: boolean
handle?: string
+ /** A default row whose source also has a real (pre-reservation) `hermes`
+ * profile: that profile keeps @hermes and this row answers to @default.
+ * Set by `claimDefaultHandles`. */
+ hermesHandleTaken?: boolean
has_avatar?: boolean
/** The connection's backend identity (/api/status `install_id`) when the
* roster source has seen it — stable across Desktops, unlike `connectionId`