The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): New Group Chat is offered only when two bots are seatable
Teknium768cb788681b
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-capabilities.ts b/apps/desktop/src/plugins/hermes-bots/canonical-group-capabilities.tsindex b79b93ceaeb..88784158459 100644--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-capabilities.ts+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-capabilities.ts@@ -1,4 +1,8 @@-import { gatewayActivationEpoch, host } from '@hermes/plugin-sdk'+import { gatewayActivationEpoch, host, useValue } from '@hermes/plugin-sdk'+import { useEffect, useState } from 'react'++import { canonicalGroupRequest } from './canonical-groups'+import type { RosterRow } from './types'export type GroupExecutionMode = 'canonical' | 'legacy' | 'unavailable'@@ -55,3 +59,100 @@ export function groupCreationSource(route: { connectionId: string; profile: striroute.connectionId === host.state.connectionId.get() &&route.profile === host.state.profile.get() && host.state.gateway.get() === 'open'}++export interface GroupCapabilityState {+ activationEpoch: number+ mode: GroupExecutionMode+ seatable: null | Set<string>+ source: string+}++/** `groups.capabilities` for the active source while `active`, keyed by that+ * source so an answer from a source the window has left is never used. */+export function useGroupCapability(active: boolean) {+ const connectionId = useValue(host.state.connectionId)+ const profile = useValue(host.state.profile)+ const gateway = useValue(host.state.gateway)+ const activationEpoch = gatewayActivationEpoch()+ const source = JSON.stringify([connectionId, profile, gateway, activationEpoch])+ const [capability, setCapability] = useState<GroupCapabilityState | null>(null)++ useEffect(() => {+ let cancelled = false+ setCapability(null)++ if (!active || gateway !== 'open' || !connectionId) {+ return+ }++ const route = { connectionId, profile }+ const sourceCurrent = groupCreationSource(route, activationEpoch)++ const settle = (result: unknown, failed: boolean) => {+ if (!cancelled && sourceCurrent()) {+ setCapability({+ activationEpoch,+ mode: failed ? 'unavailable' : groupExecutionMode(result),+ seatable: failed ? null : groupSeatableProfiles(result),+ source+ })+ }+ }++ void canonicalGroupRequest<unknown>(route, 'groups.capabilities').then(+ result => settle(result, false),+ () => settle(null, true)+ )++ return () => { cancelled = true }+ }, [activationEpoch, active, connectionId, gateway, profile, source])++ const current = capability?.source === source ? capability : null++ return {+ capability,+ connectionId,+ mode: current ? current.mode : ('checking' as const),+ observedRoute: connectionId ? { connectionId, profile } : null,+ seatable: current ? current.seatable : null,+ source+ }+}++/** The roster rows New Group Chat may seat: never an outage placeholder; in+ * legacy mode every bot, otherwise only bots on the current connection that+ * the authority's seatable roster names (#141178). The ONE predicate behind+ * both the dialog's picker and the menu item that opens it. */+export function seatableGroupBots(+ roster: RosterRow[],+ { connectionId, mode, seatable }: { connectionId: null | string; mode: GroupExecutionMode | 'checking'; seatable: null | Set<string> }+): RosterRow[] {+ const currentConnection = String(connectionId || '').trim()++ const belongsToCurrentConnection = (bot: RosterRow) => {+ if (!currentConnection) {+ return false+ }++ if (bot.connectionId) {+ return bot.connectionId === currentConnection &&+ (!bot.route?.connectionId || bot.route.connectionId === currentConnection)+ }++ return !bot.remoteSource && (!bot.route?.connectionId || bot.route.connectionId === currentConnection)+ }++ return roster.filter(bot => {+ if (bot?.ghost) {+ return false+ }++ if (mode === 'legacy') {+ return true+ }++ // The profile is the one createCanonicalGroup will send.+ return belongsToCurrentConnection(bot) &&+ (!seatable || seatable.has(bot.route?.targetProfile ?? bot.targetProfile ?? bot.name))+ })+}diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-capability-gates.test.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-capability-gates.test.tsxindex 7edb6351ae5..cb1ad4480b1 100644--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-capability-gates.test.tsx+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-capability-gates.test.tsx@@ -12,7 +12,9 @@ import { $groupChats, $groupChatWorkspace, updateGroupChat } from './group-chat'import type * as GroupChatModule from './group-chat'import type * as GroupChatParts from './group-chat-parts'import { GroupChatWorkspace } from './group-chat-view'+import { botsText } from './i18n'import { translateBots } from './i18n-test-helper'+import { renderRosterToolbar } from './roster-pane-toolbar'import type { RosterRow } from './types'const { request, notify, openWorkspace, activation } = vi.hoisted(() => ({ request: vi.fn(), notify: vi.fn(), openWorkspace: vi.fn(), activation: { epoch: 1 } }))@@ -384,3 +386,49 @@ it.each(['profile', 'gateway', 'same-route-activation'] as const)('workspace: aexpect(pending.serverRooms.size).toBe(0)expect(openWorkspace).not.toHaveBeenCalled()})++// The New… menu opens New Group Chat. It is offered only when the dialog can+// seat two bots by the SAME rule the dialog's picker uses; counting the whole+// roster opened a dialog with one checkbox and a Create button that never woke.+it.each([+ ['one seatable bot', ['alpha', 'default'], true],+ ['two seatable bots', ['alpha', 'beta'], false]+])('New Group Chat in the New… menu, with %s', async (_label, seatable, disabled) => {+ const withParked: RosterRow[] = [...roster, { name: 'parked', connectionId: 'local' }]+ answer({ driver: true, persistent_process: true, seatable_profiles: seatable })+ const setGroupCreateOpen = vi.fn()++ render(+ renderRosterToolbar({+ activeFilterCount: 0,+ activeSourceRoster: withParked,+ activityFilter: 'all',+ activityToasts: false,+ b: botsText(),+ gatewayFilter: 'all',+ gatewayOptions: [],+ query: '',+ roster: withParked,+ rowKindFilter: 'all',+ setActivityFilter: vi.fn(),+ setCreateOpen: vi.fn(),+ setGatewayFilter: vi.fn(),+ setGroupCreateOpen,+ setQuery: vi.fn(),+ setRowKindFilter: vi.fn(),+ setSectionDialog: vi.fn(),+ showRosterFilters: false,+ showRosterSearch: false,+ showRosterTools: false+ })+ )++ fireEvent.keyDown(screen.getByRole('button', { name: botsText().roster.newBotOrGroup }), { key: 'Enter' })+ const item = await screen.findByRole('menuitem', { name: botsText().group.newTitle })++ // Settles once the authority's seatable roster is in: all three bots are on+ // this connection, but only the ones it will seat count.+ await waitFor(() => expect(item.hasAttribute('data-disabled')).toBe(disabled))+ fireEvent.click(item)+ expect(setGroupCreateOpen).toHaveBeenCalledTimes(disabled ? 0 : 1)+})diff --git a/apps/desktop/src/plugins/hermes-bots/create-dialog.tsx b/apps/desktop/src/plugins/hermes-bots/create-dialog.tsxindex 4830363433d..8e23e490111 100644--- a/apps/desktop/src/plugins/hermes-bots/create-dialog.tsx+++ b/apps/desktop/src/plugins/hermes-bots/create-dialog.tsx@@ -20,7 +20,6 @@ import {DialogHeader,DialogTitle,DisclosureCaret,- gatewayActivationEpoch,GlyphSpinner,host,Input,@@ -45,7 +44,13 @@ import { isBackfilledFacePng } from './avatar-image'import { AvatarPicker } from './avatar-picker'import { $selectedBot } from './bot-state'import { createCanonicalChat } from './canonical-chat'-import { groupCreationSource, groupExecutionMode, groupSeatableProfiles } from './canonical-group-capabilities'+import {+ groupCreationSource,+ groupExecutionMode,+ seatableGroupBots,+ useGroupCapability+} from './canonical-group-capabilities'+import type { GroupCapabilityState } from './canonical-group-capabilities'import { registerCanonicalGroup } from './canonical-group-registry'import type { CanonicalGroupOrigin } from './canonical-group-registry'import { canonicalGroupRequest, createCanonicalGroup } from './canonical-groups'@@ -1220,13 +1225,6 @@ interface CreateGroupChatDialogProps {roster: RosterRow[]}-type GroupCapabilityState = {- activationEpoch: number- mode: ReturnType<typeof groupExecutionMode>- seatable: null | Set<string>- source: string-}-async function revalidateGroupCreationMode(route: CanonicalGroupRoute,capability: GroupCapabilityState | null,@@ -1262,14 +1260,7 @@ export function CreateGroupChatDialog({ open, roster, onClose, onCreated }: Creaconst { t } = useI18n()const b = useBots()const allMeta: Record<string, BotMeta> = useValue($botMeta)- const connectionId = useValue(host.state.connectionId)- const profile = useValue(host.state.profile)- const gateway = useValue(host.state.gateway)- const activationEpoch = gatewayActivationEpoch()- const source = JSON.stringify([connectionId, profile, gateway, activationEpoch])- const observedRoute = connectionId ? { connectionId, profile } : null-- const [capability, setCapability] = useState<GroupCapabilityState | null>(null)+ const { capability, connectionId, mode, observedRoute, seatable, source } = useGroupCapability(open)const [query, setQuery] = useState('')const [checked, setChecked] = useState<Record<string, boolean>>({})@@ -1286,77 +1277,8 @@ export function CreateGroupChatDialog({ open, roster, onClose, onCreated }: Crea}}, [open])- useEffect(() => {- let cancelled = false- setCapability(null)-- if (!open || gateway !== 'open' || !connectionId) {- return- }-- const route = { connectionId, profile }- const sourceCurrent = groupCreationSource(route, activationEpoch)-- void canonicalGroupRequest<unknown>(route, 'groups.capabilities')- .then(result => {- if (!cancelled && sourceCurrent()) {- setCapability({- activationEpoch,- mode: groupExecutionMode(result),- seatable: groupSeatableProfiles(result),- source- })- }- })- .catch(() => {- if (!cancelled && sourceCurrent()) {- setCapability({- activationEpoch,- mode: 'unavailable',- seatable: null,- source- })- }- })-- return () => { cancelled = true }- }, [activationEpoch, connectionId, gateway, open, profile, source])-- const mode = capability?.source === source ? capability.mode : 'checking'- const seatable = capability?.source === source ? capability.seatable : null-- const currentConnection = String(connectionId || '').trim()-- const belongsToCurrentConnection = (bot: RosterRow) => {- if (!currentConnection) {- return false- }-- if (bot.connectionId) {- return bot.connectionId === currentConnection &&- (!bot.route?.connectionId || bot.route.connectionId === currentConnection)- }-- return !bot.remoteSource && (!bot.route?.connectionId || bot.route.connectionId === currentConnection)- }-- // An outage placeholder preserves one selected owner's identity in the- // sidebar, but it is not a routable room member. Never offer it here.- const selectableRoster = roster.filter(bot => {- if (bot?.ghost) {- return false- }-- if (mode === 'legacy') {- return true- }-- // Canonical: the authority's own seatable roster wins over connection- // membership, so a parked or unseatable bot is never offered (#141178).- // The profile is the one createCanonicalGroup will send.- return belongsToCurrentConnection(bot) &&- (!seatable || seatable.has(bot.route?.targetProfile ?? bot.targetProfile ?? bot.name))- })+ // An outage placeholder or a bot the authority will not seat is never offered.+ const selectableRoster = seatableGroupBots(roster, { connectionId, mode, seatable })const selected = selectableRoster.filter(bot => checked[botRosterKey(bot)])const visible: RosterRow[] = filterBots(selectableRoster, allMeta, query)diff --git a/apps/desktop/src/plugins/hermes-bots/roster-pane-toolbar.tsx b/apps/desktop/src/plugins/hermes-bots/roster-pane-toolbar.tsxindex 13049a99835..fe8db7e5844 100644--- a/apps/desktop/src/plugins/hermes-bots/roster-pane-toolbar.tsx+++ b/apps/desktop/src/plugins/hermes-bots/roster-pane-toolbar.tsx@@ -11,6 +11,7 @@ import {Tip} from '@hermes/plugin-sdk'+import { seatableGroupBots, useGroupCapability } from './canonical-group-capabilities'import { botSourceStatus } from './data'import type { useBots } from './i18n'import { setActivityToasts } from './roster-actions'@@ -18,12 +19,31 @@ import { GatewayKindGlyph } from './roster-sections'import type { rosterGatewayOptions } from './roster-sections'import type { RosterActivityFilter, RosterKindFilter, RosterRow } from './types'+interface NewGroupChatItemProps {+ label: string+ onSelect: () => void+ roster: RosterRow[]+}++/** Mounted only while the menu is open, so the capability read happens on+ * demand. Offered only when the dialog it opens can seat two bots: the same+ * predicate the dialog's picker uses, or it opened to a dead Create button. */+function NewGroupChatItem({ label, onSelect, roster }: NewGroupChatItemProps) {+ const { connectionId, mode, seatable } = useGroupCapability(true)++ return (+ <DropdownMenuItem disabled={seatableGroupBots(roster, { connectionId, mode, seatable }).length < 2} onSelect={onSelect}>+ <Codicon className="mr-1.5" name="organization" />+ {label}+ </DropdownMenuItem>+ )+}+interface renderRosterToolbarProps {b: ReturnType<typeof useBots>activityToasts: booleanactiveSourceRoster: RosterRow[]- /** Full roster used by the dialog. The dialog filters it by the active- * gateway mode before offering seats. */+ /** Full roster; New Group Chat seats only `seatableGroupBots` of it. */roster: RosterRow[]setCreateOpen: (value: boolean) => voidsetGroupCreateOpen: (value: boolean) => void@@ -104,14 +124,7 @@ export function renderRosterToolbar({<Codicon className="mr-1.5" name="hubot" />{b.bot.newTitle}</DropdownMenuItem>- {/* The dialog applies the gateway-mode member filter after it opens. */}- <DropdownMenuItem- disabled={roster.filter(bot => !bot?.ghost).length < 2}- onSelect={() => setGroupCreateOpen(true)}- >- <Codicon className="mr-1.5" name="organization" />- {b.group.newTitle}- </DropdownMenuItem>+ <NewGroupChatItem label={b.group.newTitle} onSelect={() => setGroupCreateOpen(true)} roster={roster} /><DropdownMenuSeparator /><DropdownMenuItem onSelect={() => setSectionDialog({ mode: 'create' })}><Codicon className="mr-1.5" name="new-folder" />