The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat: sync bundled Bot Mode with multi-source roster (Hermes-Bot-Mode#68)
Teknium8236b417713d
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.jsindex 851db6f872f..cbb4486ffbe 100644--- a/apps/desktop/src/plugins/hermes-bots/plugin.js+++ b/apps/desktop/src/plugins/hermes-bots/plugin.js@@ -2015,12 +2015,29 @@ function useRoster() {return useQuery({queryKey: ROSTER_KEY,queryFn: async () => {- const res = await host.request('profiles.list', {})+ // Rich rows (last_session, ui_meta, has_avatar) come from the ACTIVE+ // gateway's profiles.list — unchanged single-source behavior.+ const local = await host.request('profiles.list', {})// Newer backends inject the teammate-messaging protocol into every// session's system prompt (agent.bot_mode_protocol) — SOUL.md must not// carry a second copy. Older gateways lack the flag: keep appending.- serverInjectsProtocol = Boolean(res?.bot_mode_protocol)- return res+ serverInjectsProtocol = Boolean(local?.bot_mode_protocol)++ // Multi-source desktops (hermes-agent #86875) also expose the union+ // agent roster across every registered connection. Merge agents from+ // OTHER sources in as additional rows. Feature-detected + best-effort:+ // an older Desktop build (no host.agents) or a roster hiccup leaves+ // the local list exactly as it was.+ if (typeof host.agents === 'function') {+ try {+ const union = await host.agents()+ return mergeMultiSourceRoster(local, union)+ } catch {+ /* older build or roster failure — single-source list stands */+ }+ }++ return local},refetchInterval: 5000,staleTime: 5000,@@ -2031,16 +2048,69 @@ function useRoster() {})}-/** The @handle users tag a bot with. 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. */-function botHandle(name) {+/** Merge the union agent roster (host.agents) over the active gateway's+ * profiles.list. Local-source rows are matched by profile name and only+ * ANNOTATED (handle, connectionId) — their rich fields stay authoritative.+ * Rows from other sources become new roster entries tagged with their+ * source label so BotRow can badge them and route open/warm through+ * ensureAgent/warmAgent. Pure — exercised directly by the tests. */+function mergeMultiSourceRoster(local, union) {+ const profiles = Array.isArray(local?.profiles) ? local.profiles.slice() : []+ const agents = Array.isArray(union?.agents) ? union.agents : []++ if (!agents.length) {+ return { ...local, profiles }+ }++ const localByName = new Map(profiles.map(p => [p.name, p]))++ for (const agent of agents) {+ const isLocalSource = agent.connectionKind === 'local'+ const row = isLocalSource ? localByName.get(agent.profile) : null++ if (row) {+ // Annotate in place: the @name-device handle only differs from the+ // bare name when the profile exists on several sources.+ row.handle = agent.handle+ row.connectionId = agent.connectionId+ continue+ }++ if (isLocalSource) {+ // Union saw a local profile profiles.list didn't return (older+ // backend mid-refresh) — skip rather than invent a thin row.+ continue+ }++ profiles.push({+ name: agent.profile,+ handle: agent.handle,+ connectionId: agent.connectionId,+ connectionKind: agent.connectionKind,+ connectionLabel: agent.connectionLabel,+ remoteSource: true+ })+ }++ return { ...local, profiles }+}++/** The @handle users tag a bot with. Multi-source rosters precompute the+ * 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. */+function botHandle(name, bot) {+ if (bot?.handle && bot.handle !== name) {+ return bot.handle+ }+return (name || '').trim().toLowerCase() === 'default' ? 'hermes' : name}-function showsHandle(name, meta) {+function showsHandle(name, meta, bot) {const display = displayName({ name }, meta)- return Boolean(name && display.toLowerCase() !== botHandle(name).toLowerCase())+ return Boolean(name && display.toLowerCase() !== botHandle(name, bot).toLowerCase())}// ── canonical bot chat ───────────────────────────────────────────────────────@@ -2192,8 +2262,13 @@ function filterBots(roster, metaByName, query) {return roster.filter(bot => {const display = displayName(bot, metaByName[bot.name]).toLowerCase()const profile = (bot.name || '').toLowerCase()- const handle = botHandle(bot.name).toLowerCase()- return display.includes(needle) || profile.includes(needle) || handle.includes(needle)+ const handle = botHandle(bot.name, bot).toLowerCase()+ // Multi-source rows also match on their device name ("homelab" finds+ // every bot living on the Homelab connection).+ const sourceLabel = (bot.connectionLabel || '').toLowerCase()+ return (+ display.includes(needle) || profile.includes(needle) || handle.includes(needle) || sourceLabel.includes(needle)+ )})}@@ -2956,6 +3031,17 @@ function BotRow({ bot, onDelete, onEdit, onGroup }) {: last?.preview || bot.description || 'No conversations yet — say hi'const warm = () => {+ // Multi-source row: pre-dial the agent's OWN source (feature-detected).+ if (bot.remoteSource && typeof host.warmAgent === 'function') {+ try {+ host.warmAgent(bot.connectionId, bot.name)+ } catch {+ /* warm is best-effort */+ }++ return+ }+if (typeof host.warmProfile !== 'function') {return}@@ -2977,6 +3063,29 @@ function BotRow({ bot, onDelete, onEdit, onGroup }) {$botUnread.set(next)}+ // Multi-source row: activate the agent's source gateway FIRST so the+ // canonical-chat RPCs (session.list / session.create / openSession)+ // land on the backend that actually owns this bot's state.db. Same+ // canonical-chat flow after that — one forever chat per bot, per source.+ if (bot.remoteSource) {+ if (typeof host.ensureAgent !== 'function') {+ host.notifyError?.(+ new Error('Update Hermes Desktop to chat with agents on other connections.'),+ bot.connectionLabel || 'Remote source'+ )++ return+ }++ try {+ await host.ensureAgent(bot.connectionId, bot.name)+ } catch (error) {+ host.notifyError?.(error, `Could not reach ${bot.connectionLabel || 'the remote source'}`)++ return+ }+ }+try {const id = await openBotCanonicalChat(bot.name, meta?.chat)@@ -3029,10 +3138,18 @@ function BotRow({ bot, onDelete, onEdit, onGroup }) {className: 'truncate text-[0.8125rem] font-medium',children: displayName(bot, meta)}),- showsHandle(bot.name, meta)+ showsHandle(bot.name, meta, bot)? jsx('span', {className: 'shrink-0 font-mono text-[0.6875rem] text-(--ui-text-quaternary)',- children: `@${botHandle(bot.name)}`+ children: `@${botHandle(bot.name, bot)}`+ })+ : null,+ bot.remoteSource+ ? jsx('span', {+ className:+ 'shrink-0 rounded bg-(--chrome-action-hover) px-1 font-mono text-[0.625rem] text-(--ui-text-tertiary)',+ title: `Lives on ${bot.connectionLabel}`,+ children: bot.connectionLabel}): null]diff --git a/apps/desktop/src/plugins/hermes-bots/tests/multi-source-roster.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/multi-source-roster.test.mjsnew file mode 100644index 00000000000..1ec2b20b197--- /dev/null+++ b/apps/desktop/src/plugins/hermes-bots/tests/multi-source-roster.test.mjs@@ -0,0 +1,128 @@+import assert from 'node:assert/strict'+import { readFileSync } from 'node:fs'+import test from 'node:test'+import vm from 'node:vm'++const source = readFileSync(new URL('../plugin.js', import.meta.url), 'utf8')++function runtime() {+ const atom = value => ({ get: () => value, set: () => undefined })+ const jsx = (type, props = {}) => ({ type, props })+ const context = {+ atom,+ jsx,+ jsxs: jsx,+ useQuery: () => ({}),+ useValue: value => (value?.get ? value.get() : value),+ useState: value => [value, () => undefined],+ document: { getElementById: () => null, createElement: () => ({}), head: { appendChild: () => undefined } },+ host: { state: { profile: { get: () => 'ops', listen: () => undefined } }, request: () => undefined },+ sdk: new Proxy({}, { get: () => undefined })+ }+ const code = source+ .replace(/^import \* as sdk from '@hermes\/plugin-sdk'\r?\n/m, '')+ .replace(/^import\s+\{[\s\S]*?\}\s+from '@hermes\/plugin-sdk'\r?\n/m, '')+ .replace(/^import .* from 'react'\r?\n/m, '')+ .replace(/^import .* from 'react\/jsx-runtime'\r?\n/m, '')+ .replace('export default {', 'globalThis.plugin = {')+ .concat(+ '\nglobalThis.__mergeMultiSourceRoster = mergeMultiSourceRoster;\nglobalThis.__botHandle = botHandle;\nglobalThis.__filterBots = filterBots;'+ )+ vm.runInNewContext(code, context)+ return context+}++test('merge: no union → local list untouched', () => {+ const { __mergeMultiSourceRoster: merge } = runtime()+ const local = { profiles: [{ name: 'default', last_session: { id: 's1' } }] }++ const out = merge(local, { agents: [] })+ assert.equal(out.profiles.length, 1)+ assert.equal(out.profiles[0].name, 'default')+ assert.equal(out.profiles[0].last_session.id, 's1')+})++test('merge: local rows are annotated, remote rows appended with source tags', () => {+ const { __mergeMultiSourceRoster: merge } = runtime()+ const local = { profiles: [{ name: 'research', last_session: { id: 's1' } }] }+ const union = {+ agents: [+ {+ connectionId: 'local',+ connectionKind: 'local',+ connectionLabel: 'This device',+ profile: 'research',+ handle: 'research-this-device'+ },+ {+ connectionId: 'homelab',+ connectionKind: 'remote',+ connectionLabel: 'Homelab',+ profile: 'research',+ handle: 'research-homelab'+ },+ { connectionId: 'homelab', connectionKind: 'remote', connectionLabel: 'Homelab', profile: 'coder', handle: 'coder' }+ ]+ }++ const out = merge(local, union)+ assert.equal(out.profiles.length, 3)++ const localRow = out.profiles.find(p => p.name === 'research' && !p.remoteSource)+ // Annotated in place — rich fields survive, handle attached.+ assert.equal(localRow.last_session.id, 's1')+ assert.equal(localRow.handle, 'research-this-device')+ assert.equal(localRow.remoteSource, undefined)++ const remoteRow = out.profiles.find(p => p.name === 'research' && p.remoteSource)+ assert.equal(remoteRow.handle, 'research-homelab')+ assert.equal(remoteRow.connectionId, 'homelab')+ assert.equal(remoteRow.connectionLabel, 'Homelab')++ const coder = out.profiles.find(p => p.name === 'coder')+ assert.equal(coder.remoteSource, true)+ assert.equal(coder.handle, 'coder')+})++test('merge: union-only local profiles are NOT invented as thin rows', () => {+ const { __mergeMultiSourceRoster: merge } = runtime()+ const local = { profiles: [{ name: 'default' }] }+ const union = {+ agents: [+ { connectionId: 'local', connectionKind: 'local', connectionLabel: 'This device', profile: 'ghost', handle: 'ghost' }+ ]+ }++ const out = merge(local, union)+ assert.equal(out.profiles.length, 1)+ assert.equal(out.profiles[0].name, 'default')+})++test('botHandle: precomputed multi-source handle wins; default stays hermes', () => {+ const { __botHandle: botHandle } = runtime()++ assert.equal(botHandle('research', { handle: 'research-homelab' }), 'research-homelab')+ assert.equal(botHandle('research', { handle: 'research' }), 'research')+ assert.equal(botHandle('research'), 'research')+ assert.equal(botHandle('default'), 'hermes')+})++test('filterBots: matches the source device name for remote rows', () => {+ const { __filterBots: filterBots } = runtime()+ const roster = [+ { name: 'research' },+ { name: 'research', remoteSource: true, connectionLabel: 'Homelab', handle: 'research-homelab' }+ ]++ const hits = filterBots(roster, {}, 'homelab')+ assert.equal(hits.length, 1)+ assert.equal(hits[0].remoteSource, true)++ // Handle search still narrows to the disambiguated row.+ const byHandle = filterBots(roster, {}, '@research-homelab')+ assert.equal(byHandle.length, 1)+ assert.equal(byHandle[0].handle, 'research-homelab')++ // Bare profile search keeps matching both rows.+ assert.equal(filterBots(roster, {}, 'research').length, 2)+})diff --git a/apps/desktop/src/plugins/hermes-bots/tests/soul-protocol-backfill.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/soul-protocol-backfill.test.mjsindex a405e9f0878..ef6688648c3 100644--- a/apps/desktop/src/plugins/hermes-bots/tests/soul-protocol-backfill.test.mjs+++ b/apps/desktop/src/plugins/hermes-bots/tests/soul-protocol-backfill.test.mjs@@ -6,7 +6,7 @@ import vm from 'node:vm'const source = readFileSync(new URL('../plugin.js', import.meta.url), 'utf8')function loadSoulHelpers({ serverInjects = false } = {}) {- const start = source.indexOf('function botHandle(name) {')+ const start = source.indexOf('function botHandle(name')const end = source.indexOf('// ── human-readable row helpers', start)assert.notEqual(start, -1, 'botHandle is missing')assert.notEqual(end, -1, 'soul-helper section delimiter is missing')