Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): use group member names for companion owner labels
shenjiachenge337349e13bf
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.tsindex d804b99ab8..22c49f2926 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts@@ -162,6 +162,25 @@ describe('Chat Server result delivery and refresh', () => {service = withChatServer({ listGroups: vi.fn(async () => ({ ok: true, groups: [] })), settleLaneTurn: vi.fn(async () => false), dispose: vi.fn() } as unknown as BotGroupChatService, deps);});afterEach(() => { service.dispose(); vi.useRealTimers(); vi.unstubAllEnvs(); fixture.config = ''; vi.clearAllMocks(); });+ // #6907: getGroup feeds Desktop and remote phones. Existing fixtures never pair group name A+ // with the bot's account ownerName B; exercise the production projection (unit tier).+ it.each(['Nickname A', 'Account B', ' ', null] as const)('uses the current room owner name %s with safe account fallback', async name => {+ const ownerId = '30000000-0000-4000-8000-000000000002';+ const bot = { id: botId, kind: 'bot', name: 'Companion X', state: 'joined', role: 'member', ownerActorId: ownerId, ownerName: 'Account B' };+ const members = [bot, ...(name === null ? [] : [{ id: ownerId, kind: 'human', name, state: 'joined', role: 'member', ownerActorId: ownerId }])];+ const messages = [{ id: execution.source_message_id, seq: '1', authorId: botId, author: { kind: 'bot', name: 'Companion X' },+ content: [{ type: 'text', text: 'Example reply' }], createdAt: '2026-10-03T00:00:00Z', deleted: false, threadRootId: null }];+ if (name !== null) messages.push({ ...messages[0], id: '50000000-0000-4000-8000-000000000002', seq: '2', authorId: ownerId,+ author: { kind: 'human', name: 'Account B' }, content: [{ type: 'text', text: 'Example owner message' }], createdAt: '2026-10-03T00:06:00Z' });+ fixture.handle.mockImplementation(route => route.endsWith('/snapshot') ? { body: { room: room(roomId), members, messages, cursor: '1' } } : route.includes('/messages?') ? { body: messages } : response(route));+ const result = await service.getGroup(roomId);+ if (!result.ok) throw new Error(result.errorCode);+ const owner = name?.trim() || 'Account B';+ expect(result.group.members.find(m => m.actorId === botId)).toMatchObject({ name: `Companion X (${owner})`, ownerName: owner, ownerActorId: ownerId, isOwned: false });+ expect(result.group.messages[0]).toMatchObject({ authorName: `Companion X (${owner})`, authorBotId: botId });+ if (name !== null) expect(result.group.messages[1]).toMatchObject({ authorName: name, authorBotId: ownerId, authorKind: 'user' });+ expect(bot).toMatchObject({ name: 'Companion X', ownerName: 'Account B', ownerActorId: ownerId });+ });it('uses the mobile edited revision instead of a newer server snapshot when saving settings', async () => {await service.updateGroup({ groupId: roomId, name: 'Draft', expectedRevision: 7 });expect(fixture.handle).toHaveBeenCalledWith(`/conversations/${roomId}`, 'PATCH', expect.objectContaining({ name: 'Draft', expectedRevision: 7 }));diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.tsindex dc54875354..2f0f466e7c 100644--- a/apps/desktop/src/main/maker-ipc/chatServer.ts+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts@@ -46,7 +46,7 @@ import {import type { BotGroupChatService, BotGroupChatServiceDeps, BotGroupLaneTerminal, BotGroupTaskPostInput, BotGroupTaskPostResult } from './botGroupChatService.js';import { readPersistedReplyText } from './botGroupChatService.js';import { botGroupRuntimeFailureCode, botGroupRuntimeFailureDetail } from './botGroupRuntimeFailure.js';-import { botGroupExecutionFailureBatches } from '@cindy/maker-shared/botGroupPresentation';+import { chatGroupMemberName as memberName, chatGroupOwnerName, botGroupExecutionFailureBatches } from '@cindy/maker-shared/botGroupPresentation';import { createThreadProjection, isShareableThreadReply, threadPreviewAttachments, threadPreviewText } from './chatServerThreads.js';import { companionSnapshot, registerCompanionHomes } from '../companion-cloud/homes.js';import { startCompanionCloud, type CompanionCloudRuntime } from '../companion-cloud/runtime.js';@@ -259,8 +259,6 @@ function quoteContext(m: Message, history: readonly Message[]) {text: original ? botGroupQuoteExcerpt(quotedText(original)) : quote.excerpt,...(files ? quoteAttachments(files.length, botGroupQuoteAttachmentName(files)) : quoteAttachments(quote.attachmentCount, quote.attachmentName)) } };}-// Presentation only: keep actor IDs and stored names independent of ownership labels.-const memberName = (m: Member) => m.kind === 'bot' && m.ownerName.trim() ? `${m.name} (${m.ownerName.trim()})` : m.name;/** A person's request that 「继续讨论」 may restart; a re-posted thread reply is not a new request. */const discussionSource = (m: Message) => !m.deleted && m.origin !== 'system' && m.author.kind === 'human'&& !m.content.some(b => b.namespace === 'cindy.plan') && !readBotGroupThreadShareCard(m);@@ -1045,7 +1043,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceDconst task = m.deleted || planCard ? null : taskCardOf(m);return { id: m.id, sequence: Number(m.seq), deleted: m.deleted, kind: planCard ? 'plan' : 'message', authorKind: legacy?.authorKind === 'system' ? 'system' : m.author.kind === 'human' ? 'user' : 'bot',isSelf: m.authorId === selfId, threadRootId: m.threadRootId, replyCount: m.replyCount ?? 0, reactions: m.reactions ?? [], ...(quote ? { quote } : {}), ...(task ? { task } : {}),- authorBotId: localBot(m.authorId)?.id ?? m.authorId, authorName: legacy?.authorKind === 'system' && typeof legacy.authorName === 'string' ? legacy.authorName : member ? memberName(member) : m.author.name, content: displayText(m),+ authorBotId: localBot(m.authorId)?.id ?? m.authorId, authorName: legacy?.authorKind === 'system' && typeof legacy.authorName === 'string' ? legacy.authorName : member ? memberName(member, members) : m.author.name, content: displayText(m),mentions: { all: false, botIds: [] }, noticeCode: null, planId: typeof planCard?.data?.planId === 'string' ? planCard.data.planId : null, files: [], attachments: [], createdAt: Date.parse(m.createdAt) };}/**@@ -1310,13 +1308,13 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceDmembers: s.members.filter(m => m.state === 'joined').map(m => {const p = localBot(m.id);return { botId: p?.id ?? m.id, actorId: m.id, actorKind: m.kind, isSelf: m.id === selfId,- role: m.role, nickname: m.nickname, groupAvatar: m.groupAvatar ?? null, defaultAvatarUrl: m.defaultAvatarUrl ?? null, displayName: m.displayName, ownerActorId: m.ownerActorId, ownerName: m.ownerName,+ role: m.role, nickname: m.nickname, groupAvatar: m.groupAvatar ?? null, defaultAvatarUrl: m.defaultAvatarUrl ?? null, displayName: m.displayName, ownerActorId: m.ownerActorId, ownerName: m.kind === 'bot' ? chatGroupOwnerName(m, s.members) : m.ownerName,isOwned: m.ownerActorId === selfId, guestAccess: m.guestAccess, accessRevision: m.accessRevision,// Which computer runs my companion: a phone reaching this group through this computer// reads the companion's tasks there, not here (bot-group-chat.md §10)....(m.ownerActorId === selfId && m.kind === 'bot' ? { homeDeviceId: actors.find(a => a.id === m.id)?.homeDeviceId ?? null } : {}),avatarUrl: m.avatar?.startsWith('https://') ? m.avatar : null,- name: memberName(m), avatar: m.groupAvatar ? '' : p?.avatar ?? (m.avatar?.startsWith('https://') ? '' : m.avatar) ?? '', avatarColor: p?.avatarColor ?? 'violet', status: p?.status ?? 'active' };+ name: memberName(m, s.members), avatar: m.groupAvatar ? '' : p?.avatar ?? (m.avatar?.startsWith('https://') ? '' : m.avatar) ?? '', avatarColor: p?.avatarColor ?? 'violet', status: p?.status ?? 'active' };}), organizerBotId: s.room.organizer_id ? localBot(s.room.organizer_id)?.id ?? s.room.organizer_id : s.members.find(m => m.kind === 'bot' && m.state === 'joined')?.id ?? null, projectDir: workspace?.projectDir ?? null, lastMessage: last && lastView ? {isSelf: lastView.isSelf, authorKind: lastView.authorKind, authorName: lastView.authorName, noticeCode: lastView.noticeCode,preview: lastIsShare ? '' : (botGroupMessageSummaryText(lastView) || mediaNames(last)).slice(0, 80), createdAt: lastView.createdAt, ...(lastIsShare ? { threadShare: true } : {}),@@ -1436,7 +1434,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceDconst member = members.find(value => value.id === failure.botId);const cachedCode = failureCodes.get(`${failure.executionId}:${failure.epoch}`);return [{ ...failure, botId: localBot(failure.botId)?.id ?? failure.botId,- botName: member ? memberName(member) : actors.find(actor => actor.id === failure.botId)?.name ?? '',+ botName: member ? memberName(member, members) : actors.find(actor => actor.id === failure.botId)?.name ?? '',code: !isBotGroupRuntimeFailureCode((row as Record<string, unknown>).failure_code) && cachedCode ? cachedCode : failure.code }];});}@@ -2266,7 +2264,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceDconst members = await api<Member[]>(`/conversations/${room}/members`);const author = members.find(member => member.id === source.authorId);const card = buildBotGroupThreadShareCard({ messageId: source.id, threadRootId: source.threadRootId!,- authorName: author ? memberName(author) : source.author.name,+ authorName: author ? memberName(author, members) : source.author.name,text: threadPreviewText(source) || threadPreviewAttachments(source, attachmentName).map(file => file.name).join(', ') });try {const posted = await api<{ id: string }>(`/conversations/${room}/messages`, 'POST', {@@ -2333,7 +2331,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD}return { reactors: [...actorIds].map(actorId => {const member = members.find(m => m.id === actorId);- return { actorId, name: member ? memberName(member) : null, isSelf: actorId === self, formerMember: !!member && member.state !== 'joined' };+ return { actorId, name: member ? memberName(member, members) : null, isSelf: actorId === self, formerMember: !!member && member.state !== 'joined' };}) };}),createInvite: input => result(async () => {diff --git a/apps/mobile/src/__tests__/chatServerClient.test.ts b/apps/mobile/src/__tests__/chatServerClient.test.tsindex d3b365641a..a2b090f1e1 100644--- a/apps/mobile/src/__tests__/chatServerClient.test.ts+++ b/apps/mobile/src/__tests__/chatServerClient.test.ts@@ -13,6 +13,26 @@ const snapshot = (): ChatSnapshot => ({ room: room(), cursor: '9007199254741099'] });describe('direct Chat Server client', () => {+ // #6907: existing fixtures never pair a human's group name A with account ownerName B (unit tier).+ it('keeps owner labels scoped to each group and follows refreshed names without changing identities', () => {+ const human = { ...snapshot().members[0], name: 'Nickname A' };+ const bot = { ...human, id: id(12), kind: 'bot' as const, name: 'Companion X', ownerName: 'Account B' };+ const messages = [message(20), { ...message(21), authorId: bot.id, author: { kind: 'bot', name: bot.name } }];+ const group = (name: string, roomNumber = 1) => ({ ...snapshot(), room: room(roomNumber), members: [{ ...human, name }, bot], messages });+ const project = (s: ChatSnapshot) => chatGroupView({ snapshot: s, messages, before: null }, id(11));+ const first = group('Nickname A');+ expect(project(first).messages.map(m => m.authorName)).toEqual(['Nickname A', 'Companion X (Nickname A)']);+ expect(chatRoomRow(first.room, first).item.display.subtitle).toBe('Nickname A · Companion X (Nickname A)');+ expect(project(group('Nickname C')).messages[1].authorName).toBe('Companion X (Nickname C)');+ expect(project(group('Nickname D', 2)).messages[1].authorName).toBe('Companion X (Nickname D)');+ expect(project(first).messages[1].authorName).toBe('Companion X (Nickname A)');+ for (const name of ['Account B', ' ']) expect(project(group(name)).messages[1].authorName).toBe('Companion X (Account B)');+ expect(project({ ...first, members: [bot] }).messages[1].authorName).toBe('Companion X (Account B)');+ expect(project({ ...first, members: [{ ...human, state: 'left' }, bot] }).messages[1].authorName).toBe('Companion X (Account B)');+ expect(project({ ...first, members: [{ ...bot, ownerName: ' ' }] }).messages[1].authorName).toBe('Companion X');+ expect(project(first).members.find(m => m.actorId === bot.id)).toMatchObject({ botId: bot.id, isOwned: false });+ expect(bot).toMatchObject({ name: 'Companion X', ownerName: 'Account B', ownerActorId: human.id });+ });it('reads a 引用回复 card as the quote, keeps it out of text and previews, and marks a deleted original', () => {const card = buildBotGroupQuoteCard({ messageId: id(20), authorName: 'Other member', authorKind: 'user', excerpt: 'original words',attachmentCount: 0, attachmentName: null, sequence: 20 });diff --git a/apps/mobile/src/chat/chatServerClient.ts b/apps/mobile/src/chat/chatServerClient.tsindex fed3a29ef1..c44cf5896a 100644--- a/apps/mobile/src/chat/chatServerClient.ts+++ b/apps/mobile/src/chat/chatServerClient.ts@@ -1,7 +1,7 @@import { createConversationListState } from '@cindy/maker-shared/chatConversationList';/** The existing Chat Server HTTP contract; no device-link or executor registration. */import { botGroupMessageSummaryText, readBotGroupExecutionFailure, readBotGroupQuote, readBotGroupQuoteCard, readBotGroupTaskCard, readImportedBotGroupRuntimeFailureCode, type BotGroupAttachment, type BotGroupMemberView, type BotGroupMessageView, type BotGroupRemoteChatData } from '@cindy/maker-shared/botGroupChat';-import { botGroupExecutionFailureBatches, projectBotGroupExecutionFailures } from '@cindy/maker-shared/botGroupPresentation';+import { chatGroupMemberName as memberName, botGroupExecutionFailureBatches, projectBotGroupExecutionFailures } from '@cindy/maker-shared/botGroupPresentation';import type { HostedRemoteCollectionItem } from '@/device-link/remoteResources';// The app's `@/i18n` sets up this default instance; importing it here would pull React bindings into a plain client.import i18next from 'i18next';@@ -60,8 +60,6 @@ export function chatRejection(error: unknown, status: number, code: string): Recconst details = (error as { details?: unknown }).details;return details && typeof details === 'object' && !Array.isArray(details) ? details as Record<string, unknown> : {};}-const memberName = (member: ChatMember) => member.kind === 'bot' && member.ownerName?.trim()- ? `${member.name} (${member.ownerName.trim()})` : member.name;// A recognized 引用回复 card renders as the quote; an unknown revision keeps its readable fallback.// A task card is the message's task only on a teammate's own message (bot-group-chat.md §10).const taskCardOf = (message: ChatMessage) => message.author.kind === 'bot' ? message.content.map(readBotGroupTaskCard).find(Boolean) ?? null : null;@@ -86,14 +84,14 @@ export function chatRoomRow(room: ChatRoom, snapshot?: ChatSnapshot, selfId?: st.sort((a, b) => BigInt(chatCursor(a.seq)) < BigInt(chatCursor(b.seq)) ? 1 : -1)[0];return { key: `chat:${room.id}`, host: { deviceId: '', deviceName: '' },lastReplySequence: snapshot && selfId ? chatLastReplySequence(snapshot.messages, selfId) : undefined,- groupMembers: snapshot ? members.map(chatMemberIdentity) : undefined, item: {+ groupMembers: snapshot ? members.map(member => chatMemberIdentity(member, members)) : undefined, item: {ref: { collectionId: 'bot-groups', kind: 'bot-group', id: room.id },revision: String(room.head ?? room.revision), display: { title: room.name,- subtitle: members.map(memberName).join(' · '),- ...(snapshot ? { preview: last ? (botGroupMessageSummaryText({ content: contentText(last), task: taskCardOf(last) ?? undefined, deleted: last.deleted }) || mediaNames(last)).slice(0, 160) || members.map(memberName).join(' · ') : '' } : {}),+ subtitle: members.map(member => memberName(member, members)).join(' · '),+ ...(snapshot ? { preview: last ? (botGroupMessageSummaryText({ content: contentText(last), task: taskCardOf(last) ?? undefined, deleted: last.deleted }) || mediaNames(last)).slice(0, 160) || members.map(member => memberName(member, members)).join(' · ') : '' } : {}),timestamp: Date.parse(last?.createdAt ?? room.updated_at),lastReplyAt: snapshot && selfId ? chatLastReplyAt(snapshot.messages, selfId) : undefined },- links: members.map(member => ({ rel: 'member', label: memberName(member),+ links: members.map(member => ({ rel: 'member', label: memberName(member, members),target: { kind: 'resource', ref: { collectionId: 'teammates', kind: 'bot', id: member.id } } })),} };}@@ -132,8 +130,8 @@ function chatMemberAvatar(value: string | null): Pick<BotGroupMemberView, 'avatareturn { avatar, avatarUrl: null };}-function chatMemberIdentity(member: ChatMember) {- return { botId: member.id, name: memberName(member), ...chatMemberAvatar(member.avatar), avatarColor: '' };+function chatMemberIdentity(member: ChatMember, members: readonly ChatMember[]) {+ return { botId: member.id, name: memberName(member, members), ...chatMemberAvatar(member.avatar), avatarColor: '' };}/**@@ -144,7 +142,7 @@ export function chatGroupView(page: ChatPage, selfId: string, actors: readonly Cconst { room, members } = page.snapshot;const active = members.filter(member => member.state === 'joined');const memberViews: BotGroupMemberView[] = active.map(member => ({- ...chatMemberIdentity(member), actorId: member.id, actorKind: member.kind, isSelf: member.id === selfId,+ ...chatMemberIdentity(member, members), actorId: member.id, actorKind: member.kind, isSelf: member.id === selfId,isOwned: member.ownerActorId === selfId, role: member.role,...(member.ownerActorId === selfId && member.kind === 'bot'? { homeDeviceId: actors.find(actor => actor.id === member.id)?.homeDeviceId ?? null } : {}),@@ -169,7 +167,7 @@ export function chatGroupView(page: ChatPage, selfId: string, actors: readonly C...(task ? { task } : {}),authorKind: message.origin === 'system' ? 'system' : message.author.kind === 'human' ? 'user' : 'bot',authorBotId: message.authorId, authorName: joined && typeof joined.data?.displayName === 'string' ? joined.data.displayName- : member ? memberName(member) : message.author.name,+ : member ? memberName(member, members) : message.author.name,isSelf: message.authorId === selfId, content: contentText(message), mentions: { all: false, botIds: [] },...(quote ? { quote: deletedIds.has(quote.messageId) ? { ...quote, originalDeleted: true } : quote } : {}),noticeCode: joined ? 'member-joined' : null, planId: null, files: [],@@ -184,7 +182,7 @@ export function chatGroupView(page: ChatPage, selfId: string, actors: readonly Cconst failure = readBotGroupExecutionFailure(row, room.id);if (!failure) return [];const member = members.find(candidate => candidate.id === failure.botId);- return [{ ...failure, botName: member ? memberName(member) : '' }];+ return [{ ...failure, botName: member ? memberName(member, members) : '' }];});return { id: room.id, name: room.name, serverBacked: true, supportsGroupLeave: true, dissolvedAt: room.dissolved_at ?? null, archived: room.archived, selfActorId: selfId,revision: room.revision, members: memberViews, replyMode: room.response_mode, speakingMode: room.speaking_mode,diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.mdindex c0af3f433a..67f09daa28 100644--- a/docs/product-rules/bot-group-chat.md+++ b/docs/product-rules/bot-group-chat.md@@ -502,6 +502,7 @@ Desktop 主群输入框发送即乐观显示:点发送后消息立即接在时手机直连入口同样在发送前读取已加入成员、校验全部显式目标,再展开所有人。点名失效沿用本地化提示和草稿恢复,不把群页标为离线;重选当前成员后可以立即继续发送。回归见 `chatServerMobileEntry.test.tsx` 与 `BotGroupChatScreen.test.tsx`。多人群里的伙伴统一显示为 `伙伴名 (主人昵称)`,例如 `Cindy (Chris)`,便于区分不同人带来的同名伙伴。消息、Thread、成员列表、侧栏摘要与 @ 候选使用同一显示名;后缀仅用于展示,身份、授权和 @ 路由仍依据唯一 ID。已有短名 @ 继续可用,选取完整名字时只点名对应伙伴。+主人名称按 `ownerActorId` 关联当前群已加入的人类成员,复用其有效群名称(含群昵称),缺失或空白时回退到伙伴原有的 `ownerName`;均不可用时不加后缀。Desktop 与手机直连共用 `maker-shared/botGroupPresentation.ts` 的解析规则,手机经电脑读取沿用 Desktop 投影。昵称刷新沿既有成员资料读取与页面刷新规则生效,不重写历史消息、全局资料或归属字段。回归见 `chatServer.test.ts` 与 `chatServerClient.test.ts`。Desktop 主群与 Thread 的表情回应徽标参考 Telegram:某个表情的回应者不超过 3 人时,徽标直接显示他们的头像(替代数字,不需要悬停);超过 3 人时显示数字。头像按 Actor ID 从群成员投影取,同名伙伴各用自己的头像;diff --git a/packages/maker-shared/src/botGroupPresentation.ts b/packages/maker-shared/src/botGroupPresentation.tsindex 14e061584c..073bd5c69e 100644--- a/packages/maker-shared/src/botGroupPresentation.ts+++ b/packages/maker-shared/src/botGroupPresentation.ts@@ -18,6 +18,24 @@ import {type BotGroupSummary,} from './botGroupChat.js';+interface ChatGroupNamedMember {+ id: string; kind: string; state: string; name: string; ownerActorId?: string; ownerName?: string;+}++/** The server's member.name already includes that room's nickname override. Display only; never infer ownership from names. */+export function chatGroupOwnerName(member: ChatGroupNamedMember, members: readonly ChatGroupNamedMember[]): string {+ const owner = member.kind === 'bot' && member.ownerActorId+ ? members.find(candidate => candidate.id === member.ownerActorId && candidate.kind === 'human' && candidate.state === 'joined')+ : undefined;+ return owner?.name.trim() || member.ownerName?.trim() || '';+}++/** Group-scoped labels shared by Desktop and the direct phone client; raw member records stay unchanged. */+export function chatGroupMemberName(member: ChatGroupNamedMember, members: readonly ChatGroupNamedMember[]): string {+ const owner = chatGroupOwnerName(member, members);+ return member.kind === 'bot' && owner ? `${member.name} (${owner})` : member.name;+}+/** Only active members can be mentioned, speak, or keep a group sendable. */export function isActiveBotGroupMember(member: Pick<BotGroupMemberView, 'status'>): boolean {return member.status === 'active';