Skip to content

The agent that grows with you

fix(desktop): bot roster sections follow the roster to every desktop

teknium11197afc2b917
diff --git a/apps/desktop/src/plugins/hermes-bots/roster-pane-dialogs.tsx b/apps/desktop/src/plugins/hermes-bots/roster-pane-dialogs.tsx
index ddf4fa957e5..804fe000523 100644
--- a/apps/desktop/src/plugins/hermes-bots/roster-pane-dialogs.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/roster-pane-dialogs.tsx
@@ -81,7 +81,7 @@ export function renderRosterDialogs({
}}
onSubmit={name => {
if (sectionDialog?.mode === 'rename') {
- renameBotSection(sectionDialog.id, name)
+ renameBotSection(sectionDialog.id, name, roster)
} else {
const section = createBotSection(name, sectionDialog?.bot ? [sectionDialog.bot] : [])
diff --git a/apps/desktop/src/plugins/hermes-bots/roster-pane.tsx b/apps/desktop/src/plugins/hermes-bots/roster-pane.tsx
index 8e69c57b08b..a92dde9b798 100644
--- a/apps/desktop/src/plugins/hermes-bots/roster-pane.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/roster-pane.tsx
@@ -51,7 +51,7 @@ import { botNeedsHandleLabel, rosterGatewayOptions } from './roster-sections'
import { botWorkspaceOwnerKey, setBotsWorkspaceOwner } from './routing'
import { activeBots, useTurnBusy } from './row-helpers'
import type { BotMeta, GatewaySource, GroupMember, RosterActivityFilter, RosterKindFilter, RosterRow } from './types'
-import { $botSections, $draggingBot, type SectionDialogState } from './user-sections'
+import { $botSections, $draggingBot, adoptBotSectionsFromMeta, type SectionDialogState } from './user-sections'
import { useEscapeCancelsBotDrag } from './user-sections-ui'
// ── roster pane ──────────────────────────────────────────────────────────────
@@ -291,6 +291,13 @@ export function BotsPane() {
const { roster, activityOf, isPinned } = sortRosterBots(sourceWithSelectedOwner, allMeta)
+ // Sections made on ANOTHER desktop arrive as id + name on each member's
+ // ui_meta; rebuild the records this machine has never seen so the roster
+ // draws the same folders instead of a flat list (#114355).
+ useEffect(() => {
+ adoptBotSectionsFromMeta(roster, allMeta)
+ }, [roster, allMeta])
+
// React Query can briefly report neither loading nor data while the plugin
// and the persisted connection registry hydrate. Keep that transition in a
// neutral loading state instead of flashing the first-run "No bots" copy.
diff --git a/apps/desktop/src/plugins/hermes-bots/types.ts b/apps/desktop/src/plugins/hermes-bots/types.ts
index c0f18feb775..df397e1cb66 100644
--- a/apps/desktop/src/plugins/hermes-bots/types.ts
+++ b/apps/desktop/src/plugins/hermes-bots/types.ts
@@ -63,6 +63,11 @@ export interface BotMeta {
* the assignment rides the same profile.yaml sync every other bot setting
* already uses — so sections follow the profile to another machine. */
sectionId?: null | string
+ /** The section's display name, written beside `sectionId` on every filing.
+ * Section RECORDS live in the creating desktop's plugin storage; carrying
+ * the name with the membership lets another desktop on the same backend
+ * rebuild a section it never created instead of drawing a flat list. */
+ sectionName?: null | string
color?: string
/** Set when the user has customized the avatar, so defaults stop applying. */
custom?: boolean
diff --git a/apps/desktop/src/plugins/hermes-bots/user-sections.test.ts b/apps/desktop/src/plugins/hermes-bots/user-sections.test.ts
index a16ca4fccc3..50946da4ad3 100644
--- a/apps/desktop/src/plugins/hermes-bots/user-sections.test.ts
+++ b/apps/desktop/src/plugins/hermes-bots/user-sections.test.ts
@@ -14,7 +14,7 @@ const { saveBotMeta, storage } = vi.hoisted(() => ({
vi.mock('./data', async () => {
const { atom } = await import('nanostores')
- const $botMeta = atom<Record<string, { sectionId?: null | string }>>({})
+ const $botMeta = atom<Record<string, { sectionId?: null | string; sectionName?: null | string }>>({})
saveBotMeta.mockImplementation(async (bot: { name: string }, patch: Record<string, unknown>) => {
$botMeta.set({ ...$botMeta.get(), [bot.name]: { ...$botMeta.get()[bot.name], ...patch } })
@@ -42,11 +42,13 @@ import { $botMeta } from './data'
import type { RosterRow } from './types'
import {
$botSections,
+ adoptBotSectionsFromMeta,
createBotSection,
deleteBotSection,
groupRowsBySection,
loadBotSections,
moveBotsToSection,
+ renameBotSection,
UNASSIGNED_SECTION_KEY
} from './user-sections'
@@ -66,7 +68,7 @@ describe('user sections', () => {
// Membership rides the bot's own meta write (profile ui_meta), one per bot.
await vi.waitFor(() => expect(saveBotMeta).toHaveBeenCalledTimes(2))
- expect(saveBotMeta).toHaveBeenCalledWith(bot('nanox'), { sectionId: section.id })
+ expect(saveBotMeta).toHaveBeenCalledWith(bot('nanox'), { sectionId: section.id, sectionName: 'Clients' })
// A no-op move (already there) writes nothing.
await moveBotsToSection([bot('nanox')], section.id)
@@ -120,4 +122,42 @@ describe('user sections', () => {
expect($botSections.get().map(s => s.name)).toEqual(['Clients', 'Team'])
await vi.waitFor(() => expect($botMeta.get().nanox?.sectionId).toBe(section.id))
})
+
+ it('a second desktop rebuilds sections it never created from the id + name on each member', () => {
+ // This machine has no section records, only the members' synced ui_meta.
+ const meta = {
+ nanox: { sectionId: 'sec-clients', sectionName: 'Clients' },
+ scout: { sectionId: 'sec-clients', sectionName: 'Clients' },
+ ghost: { sectionId: 'sec-legacy' } // filed before names rode along: nothing to draw
+ }
+
+ adoptBotSectionsFromMeta([bot('nanox'), bot('scout'), bot('ghost')], meta)
+ expect($botSections.get()).toEqual([{ id: 'sec-clients', name: 'Clients' }])
+ expect(storage.get('bot-sections-v1')).toEqual([{ id: 'sec-clients', name: 'Clients' }])
+
+ // A known section takes the members' name only once every member agrees
+ // on it — a rename elsewhere, fully stamped. A half-stamped rename leaves
+ // the local name alone.
+ adoptBotSectionsFromMeta([bot('nanox'), bot('scout')], {
+ nanox: { sectionId: 'sec-clients', sectionName: 'Customers' },
+ scout: { sectionId: 'sec-clients', sectionName: 'Clients' }
+ })
+ expect($botSections.get()).toEqual([{ id: 'sec-clients', name: 'Clients' }])
+ adoptBotSectionsFromMeta([bot('nanox'), bot('scout')], {
+ nanox: { sectionId: 'sec-clients', sectionName: 'Customers' },
+ scout: { sectionId: 'sec-clients', sectionName: 'Customers' }
+ })
+ expect($botSections.get()).toEqual([{ id: 'sec-clients', name: 'Customers' }])
+ })
+
+ it('renaming re-stamps the members so the new name reaches other desktops', async () => {
+ const section = createBotSection('Clients', [bot('nanox')])!
+ await vi.waitFor(() => expect($botMeta.get().nanox?.sectionName).toBe('Clients'))
+ saveBotMeta.mockClear()
+
+ renameBotSection(section.id, 'Customers', [bot('nanox'), bot('scout')])
+ await vi.waitFor(() => expect(saveBotMeta).toHaveBeenCalledTimes(1))
+ expect(saveBotMeta).toHaveBeenCalledWith(bot('nanox'), { sectionId: section.id, sectionName: 'Customers' })
+ expect($botSections.get()).toEqual([{ id: section.id, name: 'Customers' }])
+ })
})
diff --git a/apps/desktop/src/plugins/hermes-bots/user-sections.ts b/apps/desktop/src/plugins/hermes-bots/user-sections.ts
index cb1a0609d63..fe02e448bf1 100644
--- a/apps/desktop/src/plugins/hermes-bots/user-sections.ts
+++ b/apps/desktop/src/plugins/hermes-bots/user-sections.ts
@@ -116,7 +116,7 @@ export function createBotSection(name: string, bots: RosterRow[] = []): BotSecti
return section
}
-export function renameBotSection(id: string, name: string): void {
+export function renameBotSection(id: string, name: string, roster: RosterRow[] = []): void {
const clean = String(name || '').trim()
if (!clean) {
@@ -124,6 +124,52 @@ export function renameBotSection(id: string, name: string): void {
}
persistBotSections($botSections.get().map(s => (s.id === id ? { ...s, name: clean } : s)))
+ // Members carry the name with their membership (see moveBotsToSection), so
+ // a rename re-stamps them — that is how the new name reaches other desktops.
+ void moveBotsToSection(
+ (roster || []).filter(bot => botSectionId(bot, $botMeta.get()) === id),
+ id
+ )
+}
+
+/**
+ * Sections another desktop made. The section RECORD lives in that machine's
+ * plugin storage, but every member's ui_meta reaches this machine carrying the
+ * section's id AND name — so rebuild the records we have never seen, and the
+ * roster draws the same folders here. A known section takes the members' name
+ * only when every member agrees on it (a rename elsewhere, fully stamped);
+ * while members disagree — a re-stamp still in flight — the local name stays.
+ * Order and empty sections remain this desktop's own. The roster pane calls
+ * this on every roster/meta change.
+ */
+export function adoptBotSectionsFromMeta(roster: RosterRow[], metaByName: Record<string, BotMeta>): void {
+ const names = new Map<string, Set<string>>()
+
+ for (const bot of roster || []) {
+ const meta = bot ? botRosterMeta(bot, metaByName) : null
+ const id = meta?.sectionId ? String(meta.sectionId) : null
+ const name = String(meta?.sectionName || '').trim()
+
+ if (id && name) {
+ names.set(id, (names.get(id) || new Set()).add(name))
+ }
+ }
+
+ const agreed = (id: string): null | string => {
+ const set = names.get(id)
+
+ return set?.size === 1 ? [...set][0]! : null
+ }
+
+ const local = $botSections.get()
+ const known = new Set(local.map(s => s.id))
+ const renamed = local.map(s => ({ ...s, name: agreed(s.id) ?? s.name }))
+ const adopted = [...names.keys()].filter(id => !known.has(id)).map(id => ({ id, name: [...names.get(id)!][0]! }))
+ const next = [...renamed, ...adopted]
+
+ if (next.some((s, i) => s.id !== local[i]?.id || s.name !== local[i]?.name)) {
+ persistBotSections(next)
+ }
}
/**
@@ -177,12 +223,22 @@ export function moveBotSection(id: string, delta: number): void {
* `null` clears the assignment (back to Unassigned). One `saveBotMeta` per
* bot — membership is a field on each bot's own profile, so that IS one write
* per profile — and the writes run in sequence rather than fanned out, so the
- * shared local snapshot is never committed by two saves at once.
+ * shared local snapshot is never committed by two saves at once. The section's
+ * NAME rides along: the record itself is local to the desktop that made it,
+ * and the name is what lets another desktop rebuild it (adoptBotSectionsFromMeta).
*/
export async function moveBotsToSection(bots: RosterRow[], sectionId: null | string): Promise<void> {
+ const sectionName = (sectionId && $botSections.get().find(s => s.id === sectionId)?.name) || null
+
for (const bot of bots || []) {
- if (bot && botSectionId(bot, $botMeta.get()) !== (sectionId || null)) {
- await saveBotMeta(bot, { sectionId: sectionId || null })
+ if (!bot) {
+ continue
+ }
+
+ const current = botRosterMeta(bot, $botMeta.get())
+
+ if (botSectionId(bot, $botMeta.get()) !== (sectionId || null) || (current?.sectionName || null) !== sectionName) {
+ await saveBotMeta(bot, { sectionId: sectionId || null, sectionName })
}
}
}
diff --git a/website/docs/user-guide/bot-mode.md b/website/docs/user-guide/bot-mode.md
index 6fc6499952a..47a9a5c72fa 100644
--- a/website/docs/user-guide/bot-mode.md
+++ b/website/docs/user-guide/bot-mode.md
@@ -41,7 +41,7 @@ Sections are folders you make yourself — **Clients**, **Team**, whatever fits
- **Rename, reorder, or delete** a section from its heading's right-click menu (or the **⋯** that appears on hover); double-click a heading to rename. Headings fold like the gateway headings do.
- **Deleting a section never deletes Bots** — they return to **Unassigned**, and the toast offers **Undo**. No confirmation is asked.
-Membership is stored in each Bot's profile metadata (`ui_meta`), so a Bot's section follows it to every desktop connected to that backend. When the roster shows more than one gateway, sections nest inside each gateway's bucket.
+Membership — the section's id **and name** — is stored in each Bot's profile metadata (`ui_meta`), so a Bot's section follows it to every desktop connected to that backend: a second desktop rebuilds the section headings from its members the first time it loads the roster, and a rename made on one desktop reaches the others the same way. The section list itself (order, empty sections) is kept per desktop, so deleting a section on one machine leaves an empty heading on the others until you delete it there too. Bots filed before this shipped carry only the id; re-file them once (or rename the section) to stamp the name. When the roster shows more than one gateway, sections nest inside each gateway's bucket.
## Creating a Bot