The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): introduce a renamed primary bot by its own @tag in group-turn prompts
teknium12b267f946736
diff --git a/apps/desktop/e2e/group-prompt-renamed-primary-handle.spec.ts b/apps/desktop/e2e/group-prompt-renamed-primary-handle.spec.tsnew file mode 100644index 00000000000..9b4bf36a5f7--- /dev/null+++ b/apps/desktop/e2e/group-prompt-renamed-primary-handle.spec.ts@@ -0,0 +1,157 @@+import { readFileSync, writeFileSync } from 'node:fs'+import { join } from 'node:path'++import {+ buildAppEnv,+ createSandbox,+ launchDesktop,+ type MockBackendFixture,+ waitForAppReady,+ writeEnvFile,+ writeMockProviderConfig+} from './fixtures'+import { startMockServer } from '../../../tests-js/scripts/mock-server'+import { expect, test } from './test'++// The primary profile (`default`) renamed to a Bot Mode title ("Bobby") is+// addressed by the roster, autocomplete and mention routing as @bobby — but the+// group-turn prompt introduced it to itself as @hermes, so a member told+// "You are @hermes" read `@bobby …` as a message for someone else and passed.+// The mock inference server scripts a member's line by the `You are @<handle>`+// opener, so the assertion is exactly that mismatch: with a script for+// `bobby`, the renamed primary must answer (the persisted room log carries an+// entry authored by `default`), not settle silently.++let fixture: MockBackendFixture | null = null++type Page = MockBackendFixture['page']++interface RoomLogEntry {+ from?: { kind?: string; name?: string }+ text?: string+}++const GROUP = 'Bobby, Code Farmer'++async function openBots(page: Page): Promise<void> {+ const tab = page+ .getByRole('button', { name: 'Bots', exact: true })+ .or(page.getByRole('tab', { name: 'Bots', exact: true }))+ .first()++ await tab.click()+ await expect(page.getByRole('button', { name: 'New bot or group chat' })).toBeVisible()+}++async function createAgent(page: Page, name: string, title: string): Promise<void> {+ await page.getByRole('button', { name: 'New bot or group chat' }).click()+ await page.getByRole('menuitem', { name: 'New Bot' }).click()++ const dialog = page.getByRole('dialog', { name: 'New Bot' })+ await dialog.getByPlaceholder('inbox-triage').fill(name)+ await dialog.getByPlaceholder('Inbox Triage').fill(title)+ await dialog.getByRole('button', { name: 'Create Bot' }).click()+ await expect(dialog).toBeHidden({ timeout: 30_000 })+ await expect(page.getByRole('button', { name: new RegExp(`^${title}\\b`) }).first()).toBeVisible({ timeout: 30_000 })+}++async function roomLog(page: Page, group: string): Promise<RoomLogEntry[]> {+ return page.evaluate(name => {+ const raw = window.localStorage.getItem('hermes.plugin.hermes-bots.group-chats')+ const rooms = raw ? (JSON.parse(raw) as Record<string, { log?: RoomLogEntry[] }>) : {}++ return rooms[name]?.log ?? []+ }, group)+}++test.beforeAll(async () => {+ const mock = await startMockServer()+ const sandbox = createSandbox('renamed-primary')+ writeMockProviderConfig(sandbox.hermesHome, mock.url)+ writeEnvFile(sandbox.hermesHome)+ // The primary profile carries a Bot Mode title — what `hermes profile rename`+ // / the Edit Profile dialog persist into profile.yaml's ui_meta.+ writeFileSync(+ join(sandbox.hermesHome, 'profile.yaml'),+ 'ui_meta:\n hermes-bots:\n title: Bobby\n shape: circle\n color: "#4f8"\n',+ 'utf8'+ )++ const { app, page } = await launchDesktop(buildAppEnv(sandbox))++ fixture = {+ app,+ page,+ mock,+ mockUrl: mock.url,+ sandbox,+ cleanup: async () => {+ await app.close().catch(() => undefined)+ await mock.close()+ sandbox.cleanup()+ }+ }+ await waitForAppReady(fixture, 120_000)+})++// eslint-disable-next-line no-empty-pattern+test.afterEach(async ({}, info) => {+ if (!fixture) {+ return+ }++ await info.attach('room-log', {+ body: JSON.stringify(await roomLog(fixture.page, GROUP), null, 2),+ contentType: 'application/json'+ })+ await info.attach('native-window', { body: await fixture.page.screenshot(), contentType: 'image/png' })+ await info.attach('desktop-log', {+ body: readFileSync(join(fixture.sandbox.hermesHome, 'logs/desktop.log')),+ contentType: 'text/plain'+ })+})++test.afterAll(async () => {+ await fixture?.cleanup()+ fixture = null+})++test('a renamed primary bot is addressed by its own @tag in the group-turn prompt', async () => {+ test.setTimeout(420_000)+ const page = fixture!.page++ await openBots(page)+ await expect(page.getByRole('button', { name: /^Bobby\b/ }).first()).toBeVisible({ timeout: 30_000 })+ await createAgent(page, 'code-farmer', 'Code Farmer')++ await page.getByRole('button', { name: 'New bot or group chat' }).click()+ await page.getByRole('menuitem', { name: 'New Group Chat' }).click()++ const dialog = page.getByRole('dialog', { name: 'New Group Chat' })++ for (const title of ['Bobby', 'Code Farmer']) {+ await dialog.getByText(title, { exact: true }).locator('xpath=ancestor::label').getByRole('checkbox').click()+ }++ await dialog.getByRole('textbox', { name: 'Group name' }).fill(GROUP)+ await dialog.getByRole('button', { name: 'Create Group (2)' }).click()++ const composer = page.getByRole('textbox', { name: `Message ${GROUP}` }).filter({ visible: true })+ await expect(composer).toBeVisible({ timeout: 20_000 })++ // Only the renamed primary is addressed, by its friendly tag. Its scripted+ // line is keyed to `bobby`: the member only speaks when its turn prompt+ // introduces it as @bobby (the control, code-farmer, is scripted too so a+ // wrong-handle prompt cannot be mistaken for an idle room).+ await composer.fill('@bobby Please reply with one line only. E2E_SAY(bobby)[B] E2E_SAY(code-farmer)[C]')+ await composer.press('Enter')++ await expect+ .poll(async () => (await roomLog(page, GROUP)).some(e => e.from?.name === 'default' && (e.text || '').trim() === 'B'), {+ timeout: 180_000,+ message: 'the renamed primary (default / Bobby) was introduced to itself as @hermes and never answered @bobby'+ })+ .toBe(true)++ await expect(page.getByText('B', { exact: true }).filter({ visible: true }).first()).toBeVisible()+})diff --git a/apps/desktop/src/plugins/hermes-bots/group-round-prompt.ts b/apps/desktop/src/plugins/hermes-bots/group-round-prompt.tsindex e372287da16..7694facea83 100644--- a/apps/desktop/src/plugins/hermes-bots/group-round-prompt.ts+++ b/apps/desktop/src/plugins/hermes-bots/group-round-prompt.ts@@ -1,4 +1,4 @@-import { botHandle } from './data'+import { botMentionTag } from './data'import { groupSpeakerLabel } from './group-chat'import { groupMemberKey } from './group-membership'import type { GroupMember, GroupMessage, GroupMessageAuthor } from './types'@@ -96,14 +96,14 @@ export function buildGroupChatTurnPrompt({ groupName, members, viewer, deltaLineconst peerNames = peers.map(m => {- const handle = m.title ? `${m.title} (@${botHandle(m.name, m)})` : `@${botHandle(m.name, m)}`+ const handle = m.title ? `${m.title} (@${botMentionTag(m)})` : `@${botMentionTag(m)}`return m.remoteSource ? `${handle} [on ${m.connectionLabel || m.connectionId}]` : handle}).join(', ')return [- `[Group chat: "${groupName}"] You are @${botHandle(viewer.name, viewer)}, one participant in a group chat with ${peerNames || 'no one else yet'} and the user.`,+ `[Group chat: "${groupName}"] You are @${botMentionTag(viewer)}, one participant in a group chat with ${peerNames || 'no one else yet'} and the user.`,'','New messages in the room since your last turn (oldest first):',...deltaLines.map(line => ` ${line}`),diff --git a/apps/desktop/src/plugins/hermes-bots/group-rounds.test.ts b/apps/desktop/src/plugins/hermes-bots/group-rounds.test.tsindex fc45d145f3a..36d273a62a1 100644--- a/apps/desktop/src/plugins/hermes-bots/group-rounds.test.ts+++ b/apps/desktop/src/plugins/hermes-bots/group-rounds.test.ts@@ -577,6 +577,37 @@ describe('turn prompt', () => {expect(peer).toMatch(/group chat with @hermes/)})+ // #89720: a renamed primary is @bobby to the roster, autocomplete and the+ // mention resolver; introducing it to itself as @hermes made it treat+ // `@bobby …` as someone else's message and pass.+ it('introduces a renamed primary by the same @tag the room resolves', async () => {+ const { rounds } = await loadRoom()+ const { buildGroupChatTurnPrompt } = await import('./group-round-prompt')++ const members: GroupMember[] = [+ { name: 'default', title: 'Bobby' },+ { name: 'builder', title: '' }+ ]++ const own = buildGroupChatTurnPrompt({+ deltaLines: [],+ groupName: 'Core',+ members,+ viewer: members[0]+ })++ expect(own).toMatch(/You are @bobby,/)++ const peer = buildGroupChatTurnPrompt({+ deltaLines: [],+ groupName: 'Core',+ members,+ viewer: members[1]+ })++ expect(peer).toMatch(/group chat with Bobby \(@bobby\)/)+ })+it('asks for full-quality results and short chatter, not short results', async () => {const { rounds } = await loadRoom()const { buildGroupChatTurnPrompt } = await import('./group-round-prompt')diff --git a/website/docs/user-guide/bot-mode.md b/website/docs/user-guide/bot-mode.mdindex ca17f5979d6..281e6e30296 100644--- a/website/docs/user-guide/bot-mode.md+++ b/website/docs/user-guide/bot-mode.md@@ -152,7 +152,7 @@ Use the **Move up** and **Move down** arrows beside a room to choose its positioBots message each other with attribution, and you can hand work off from any chat:- **@mentions** — type `@researcher have a look at this` in any chat and the composer's `@` autocomplete helps you pick the right Bot; on send, the mention is resolved against the live roster and the active Bot is told exactly who you mean (profile, friendly name, and device for cross-connection Bots). The Bot then composes its own message and sends it with `message_agent` — your text is never forwarded verbatim, and the reply comes back attributed to that agent. An email address or an unknown `@` passes through untouched. Bots on other connected machines are reachable the same way: the Desktop relays the message over that connection's own socket (see *Bots across machines* below).-- **Renamed Bots keep their tags in sync** — give a Bot a friendly name (the pencil in its chat header, or `hermes profile rename`) and it becomes taggable by that name: a Bot titled *Research Buddy* answers to `@research-buddy` (and `@researchbuddy`), in regular chats and in group rooms alike. The composer's `@` autocomplete offers the renamed tag and also matches when you type the old profile name, which keeps resolving too.+- **Renamed Bots keep their tags in sync** — give a Bot a friendly name (the pencil in its chat header, or `hermes profile rename`) and it becomes taggable by that name: a Bot titled *Research Buddy* answers to `@research-buddy` (and `@researchbuddy`), in regular chats and in group rooms alike. The composer's `@` autocomplete offers the renamed tag and also matches when you type the old profile name, which keeps resolving too. This includes the primary Bot: rename it *Maia* and group-turn prompts introduce it as `@maia`, its inter-agent messages sign as `Message from 🤖 Maia (@hermes)`, and teammates can `message_agent(target="maia")` it — `@hermes` stays a working alias.- **Direct messages** — every Bot Chat carries the `message_agent` tool: a Bot messages a teammate by calling `message_agent(target="researcher", message="…")`. The tool validates the target against the live roster, prefixes the sender's `Message from 🤖 <sender> (@<sender>):` attribution automatically, and delivers into the teammate's canonical Bot Chat. Delivery is **fire-and-forget**: the sender gets an acknowledgement, finishes its turn, and the reply arrives later as a background completion notification. The message travels as a real parameter (nothing shell-interpreted — quotes, `$(...)`, and backticks arrive verbatim), and the Bot composes its own message rather than forwarding your words. The teammate roster — names **and roles** from each profile's title/description — is part of every Bot Chat's system prompt, so Bots know who does what before choosing a recipient. The tool exists **only** in canonical Bot Chat sessions on Bot-Mode-managed installs; regular chats, group-room member sessions, and CLI sessions never see it.Local messages also reach a Bot Chat that stays open in Desktop or the TUI. The receiving backend keeps ownership: it reads durable ingress on its existing notification poller, admits immediately when idle, or waits until the running turn and already queued human prompts finish. A `queued` acknowledgement confirms durable admission, **not** a completed reply. The target profile retains the delivery ID and receipt under `runtime/bot_live_delivery/`; `settled` confirms completion. A crashed or cancelled imported turn is not automatically replayed, and pending work pinned to a departed owner remains inspectable rather than being silently rerun. Do not resend a delivery whose outcome is unknown. Older backends without live-delivery capability retain the existing ownership refusal; restart that backend after upgrading.