Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 对齐双端群聊最近活动排序
nanacc4381e40290
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.tsindex bd31a9c38c..8e69d474aa 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/botGroupRemoteResourceProvider.test.ts@@ -245,6 +245,13 @@ describe('bot group remote resources', () => {} });});+ it('uses creation for empty group ordering without publishing a creation notice or counting settings edits', () => {+ const group = summary({ createdAt: 70, updatedAt: 100, lastMessage: null, openPlan: null });+ expect(botGroupRemoteItem(group).display).toMatchObject({ timestamp: 70 });+ expect(botGroupRemoteItem(group).display.preview).toBeUndefined();+ expect(botGroupRemoteItem({ ...group, lastMessage: summary().lastMessage }).display.timestamp).toBe(70);+ });+it('names who shared a thread reply, never the card text, the way the desktop sidebar does', () => {const share = (extra: Record<string, unknown>) => botGroupRemotePreview(summary({ openPlan: null,lastMessage: { authorName: '小满', preview: '', createdAt: 50, threadShare: true, ...extra } as never }));diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.tsindex 976edf0792..d045ce4868 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServerMembership.test.ts@@ -121,6 +121,15 @@ describe('Chat Server membership notices', () => {expect(result.ok && result.group.lastReplyAt).toBe(Date.parse(replyAt));});+ it('uses the latest visible topic activity for the sidebar, not snapshot array order or a deleted message', async () => {+ const topic = { ...joined(), id: '40000000-0000-4000-8000-000000000002', seq: '9007199254740993',+ origin: 'user', threadRootId: joined().id, createdAt: '2026-10-09T00:00:00Z',+ content: [{ type: 'text', text: 'Latest topic reply' }] } as unknown as ReturnType<typeof joined>;+ messages = [joined(), { ...joined(), seq: '9007199254740994', deleted: true }, topic];+ const result = await service.getGroup(roomId);+ expect(result.ok && result.group.lastMessage).toMatchObject({ preview: 'Latest topic reply', createdAt: Date.parse(topic.createdAt) });+ });+it('keeps separate admissions for the same member after leaving and rejoining', async () => {messages = [{ ...joined(), id: '40000000-0000-4000-8000-000000000002', seq: '20' }, joined()];const result = await service.getGroup(roomId);diff --git a/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.ts b/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.tsindex 0caa5102bf..4bf8d748f6 100644--- a/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.ts+++ b/apps/desktop/src/main/maker-ipc/botGroupRemoteResourceProvider.ts@@ -48,7 +48,7 @@ import {type BotGroupThreadShareView,} from '../../shared/botGroupChat.js';import type { BotGroupChatService } from './botGroupChatService.js';-import { projectBotGroupExecutionFailures } from '@cindy/maker-shared/botGroupPresentation';+import { botGroupActivityAt, projectBotGroupExecutionFailures } from '@cindy/maker-shared/botGroupPresentation';const FALLBACK_MESSAGES = 20;const FALLBACK_MESSAGE_CHARS = 280;@@ -174,7 +174,7 @@ export function botGroupRemoteItem(group: BotGroupSummary): RemoteCollectionItemtitle: group.name,subtitle: group.members.map((member) => member.name).join('、'),...(preview ? { preview } : {}),- timestamp: group.lastMessage?.createdAt ?? group.updatedAt,+ timestamp: botGroupActivityAt(group),lastReplyAt: group.lastReplyAt,...(busy ? { generation: { phase: 'processing', startedAt: null } } : {}),},diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.tsindex a6693e496d..02247dbfd3 100644--- a/apps/desktop/src/main/maker-ipc/chatServer.ts+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts@@ -56,7 +56,7 @@ import {import type { BotGroupChatService, BotGroupChatServiceDeps, BotGroupLaneTerminal, BotGroupTaskPostInput, BotGroupTaskPostResult } from './botGroupChatService.js';import { readPersistedReplyText } from './botGroupChatService.js';import { botGroupRuntimeFailureCode, botGroupRuntimeFailureDetail } from './botGroupRuntimeFailure.js';-import { chatGroupMemberName as memberName, chatGroupOwnerName, botGroupExecutionFailureBatches } from '@cindy/maker-shared/botGroupPresentation';+import { chatGroupMemberName as memberName, chatGroupOwnerName, botGroupExecutionFailureBatches, latestBotGroupMessage } 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';@@ -1602,7 +1602,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceDif (reads) for (const view of [...messages, ...(messageUpdates ?? [])]) if (!view.threadRootId && (view.replyCount ?? 0) > 0) view.threadUnread = threadUnread(view.id, s.messages, reads);const threadList = reads && !direct ? threadSummaries(roomId, s, page, reads) : undefined;messages.sort((a, b) => a.sequence - b.sequence);- const last = s.messages[0];+ const last = latestBotGroupMessage(s.messages);const lastView = last ? messageView(last, s.members, ownerMembers) : null;// The sidebar never resolves shares: it names the sharer and never quotes the card's text.const lastIsShare = !!last && !!readBotGroupThreadShareCard(last);diff --git a/apps/desktop/src/renderer/features/bots/BotGroupSidebarRow.tsx b/apps/desktop/src/renderer/features/bots/BotGroupSidebarRow.tsxindex eeafbf85c3..e9576cde2b 100644--- a/apps/desktop/src/renderer/features/bots/BotGroupSidebarRow.tsx+++ b/apps/desktop/src/renderer/features/bots/BotGroupSidebarRow.tsx@@ -26,6 +26,7 @@ import { BotGroupSidebarAvatar } from './BotGroupAvatars';import { isBotGroupLaneSession } from './botGroupLane';import {botGroupNoticeKey,+ botGroupActivityAt,botGroupPreviewLine,botGroupSidebarPlanPreview,isRunningBotGroupSidebarPreview,@@ -174,7 +175,7 @@ export function BotGroupSidebarRow({const mutedClass = selected ? 'opacity-70' : 'text-[var(--sidebar-list-muted)]';const unread = botGroupUnreadCount(group);const timestamp = formatBotListTimestamp(- !group.archived && group.speakingBotIds.length > 0 ? now : group.lastMessage?.createdAt ?? group.updatedAt,+ !group.archived && group.speakingBotIds.length > 0 ? now : botGroupActivityAt(group),now,t,);diff --git a/apps/desktop/src/renderer/features/bots/TeammatesSection.tsx b/apps/desktop/src/renderer/features/bots/TeammatesSection.tsxindex a3dec32804..8ec5c69f4f 100644--- a/apps/desktop/src/renderer/features/bots/TeammatesSection.tsx+++ b/apps/desktop/src/renderer/features/bots/TeammatesSection.tsx@@ -47,7 +47,7 @@ import { BotDeleteDialog } from './BotDeleteDialog';import { BotGroupSidebarRow } from './BotGroupSidebarRow';import { BotGroupSidebarAvatar } from './BotGroupAvatars';import { refreshBotGroups, useBotGroupList } from './botGroupStore';-import { BOT_GROUP_SETTINGS_PARAM } from './botGroupPresentation';+import { BOT_GROUP_SETTINGS_PARAM, botGroupActivityAt } from './botGroupPresentation';import { chatErrorKey } from './chatError';import { subscribeBotReadState, getBotLastReadAtMap, isBotGroupUnread } from './botReadState';import { withoutBotHiddenLanes } from './botGroupLane';@@ -332,7 +332,7 @@ export function TeammatesSection() {pinned: 'pinnedAt' in bot && Boolean(bot.pinnedAt),activityAt: 'activityAt' in bot ? bot.activityAt : bot.lastMessageAt ?? bot.createdAt })),...visibleGroups.map(group => ({ kind: 'group' as const, group, pinned: false,- activityAt: group.lastMessage?.createdAt ?? group.updatedAt })),+ activityAt: botGroupActivityAt(group) })),...(showCindy && currentCindy ? [{ kind: 'cindy' as const, pinned: cindyOptions.some(option => 'pinnedAt' in option.bot && Boolean(option.bot.pinnedAt)),activityAt: Math.max(...cindyOptions.map(option => 'activityAt' in option.bot ? option.bot.activityAt : option.bot.lastMessageAt ?? option.bot.createdAt)) }] : []),].sort((a, b) => Number(b.pinned) - Number(a.pinned) || b.activityAt - a.activityAt);diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botGroupMentions.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/botGroupMentions.test.tsindex 6ff3a5c7b3..95f663f725 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/botGroupMentions.test.ts+++ b/apps/desktop/src/renderer/features/bots/__tests__/botGroupMentions.test.ts@@ -12,9 +12,8 @@ import {import {continuableRoundEndId,mergeBotGroupMessages,- sortBotGroups,} from '../botGroupPresentation';-import type { BotGroupMessageView, BotGroupSummary } from '../../../../shared/botGroupChat';+import type { BotGroupMessageView } from '../../../../shared/botGroupChat';const members = [{ botId: 'mimi', name: '咪咪' },@@ -241,32 +240,11 @@ describe('group presentation', () => {expect(continuableRoundEndId(messages, { status: 'running', canContinue: true })).toBeNull();});- it('merges pages by sequence and sorts groups by latest activity', () => {+ it('merges pages by sequence', () => {const merged = mergeBotGroupMessages([message({ id: 'a', sequence: 1 }), message({ id: 'b', sequence: 2 })],[message({ id: 'b2', sequence: 2 }), message({ id: 'c', sequence: 3 })],);expect(merged.map((item) => item.id)).toEqual(['a', 'b2', 'c']);-- const group = (id: string, updatedAt: number, lastAt?: number): BotGroupSummary => ({- id,- name: id,- replyMode: 'all',- speakingMode: 'auto',- members: [],- organizerBotId: null,- projectDir: null,- lastMessage: lastAt ? { authorKind: 'user', authorName: '', preview: '', createdAt: lastAt } : null,- speakingBotIds: [],- planningBotId: null,- openPlan: null,- createdAt: 0,- updatedAt,- });- expect(sortBotGroups([group('old', 1), group('new', 1, 9), group('mid', 5)]).map((item) => item.id)).toEqual([- 'new',- 'mid',- 'old',- ]);});});diff --git a/apps/desktop/src/renderer/features/bots/botGroupPresentation.ts b/apps/desktop/src/renderer/features/bots/botGroupPresentation.tsindex d52858368e..c0a8a83afe 100644--- a/apps/desktop/src/renderer/features/bots/botGroupPresentation.ts+++ b/apps/desktop/src/renderer/features/bots/botGroupPresentation.ts@@ -31,7 +31,7 @@ export {projectBotGroupExecutionFailures,mergeBotGroupPlans,openBotGroupPlan,- sortBotGroups,+ botGroupActivityAt,type BotGroupComposerPlanState,type BotGroupPlanFollowUp,type BotGroupSidebarPlanPreview,diff --git a/apps/mobile/src/__tests__/chatServerClient.test.ts b/apps/mobile/src/__tests__/chatServerClient.test.tsindex 5a85a3e7ab..92b845d78b 100644--- a/apps/mobile/src/__tests__/chatServerClient.test.ts+++ b/apps/mobile/src/__tests__/chatServerClient.test.ts@@ -1,10 +1,12 @@import { describe, expect, it, vi } from 'vitest';+import { resolveRemoteText } from '@cindy/device-link';import { i18n } from '@/i18n';import { botGroupNewMessageCount } from '@cindy/maker-shared/botGroupPresentation';import { createChatHistory, type ChatHistoryState } from '@cindy/maker-shared/chat-history';import { chatGroupView, chatRoomRow, chatReadAt, createChatServerClient, type ChatMessage, type ChatPage, type ChatRoom, type ChatSnapshot } from '@/chat/chatServerClient';import type { ChatHistory } from '@cindy/maker-shared/chat-history';import { botGroupQuoteFromMessage, resolveBotGroupQuote, buildBotGroupQuoteCard, buildBotGroupTaskCard } from '@cindy/maker-shared/botGroupChat';+import { orderedBotGroups } from '@/session/botGroupRemote';const id = (n: number) => `00000000-0000-4000-8000-${String(n).padStart(12, '0')}`;const room = (n = 1, state = 'joined'): ChatRoom => ({ id: id(n), name: 'Discussion', kind: 'group', state, archived: false,revision: 1, created_at: '2026-10-01', updated_at: '2026-10-09', response_mode: 'all', speaking_mode: 'auto' });@@ -15,6 +17,51 @@ const snapshot = (): ChatSnapshot => ({ room: room(), cursor: '9007199254741099'{ id: id(10), kind: 'human', name: 'Other member', state: 'joined', ownerActorId: id(10), ownerName: '', avatar: null, role: 'member' },] });+describe('group list activity', () => {+ it('places a newly created empty group and a group with a new topic ahead of an older main chat', () => {+ const old = chatRoomRow(room(1), { ...snapshot(), messages: [{ ...message(20), createdAt: '2026-10-10T12:00:00Z' }] });+ const fresh = chatRoomRow({ ...room(2), created_at: '2026-10-11T12:00:00Z' }, { ...snapshot(), messages: [] });+ const topic = chatRoomRow(room(3), { ...snapshot(), messages: [{ ...message(21), threadRootId: id(20), createdAt: '2026-10-12T12:00:00Z' }] });+ expect(orderedBotGroups([old, fresh, topic], '', 'zh-CN').map(row => row.item.ref.id)).toEqual([id(3), id(2), id(1)]);+ });++ it('orders a new empty group by creation, without inventing a creation message or bumping on edits', () => {+ const empty = { ...room(), created_at: '2026-10-10T12:00:00Z', updated_at: '2026-10-20T12:00:00Z' };+ const row = chatRoomRow(empty, { ...snapshot(), room: empty });+ expect(row.item.display.timestamp).toBe(Date.parse(empty.created_at));+ expect(row.item.display.preview).toBe('');+ expect(chatRoomRow(empty).item.display.timestamp).toBe(Date.parse(empty.created_at));+ });++ it('uses the newest topic reply even when the snapshot is unordered, excluding deleted messages', () => {+ const main = { ...message(20), createdAt: '2026-10-10T12:00:00Z' };+ const topic = { ...message(21), threadRootId: main.id, createdAt: '2026-10-11T12:00:00Z' };+ const deleted = { ...message(22), deleted: true, createdAt: '2026-10-12T12:00:00Z' };+ const row = chatRoomRow(room(), { ...snapshot(), messages: [main, deleted, topic] });+ expect(row.item.display).toMatchObject({ timestamp: Date.parse(topic.createdAt), preview: '21' });+ });++ it('localizes shared joins for every reader without adding unread replies, then yields to a new message', () => {+ const reply = { ...message(20), createdAt: '2026-10-10T12:00:00Z' };+ const joined: ChatMessage = { ...message(21), origin: 'system', createdAt: '2026-10-11T12:00:00Z',+ content: [{ type: 'card', namespace: 'cindy.membership', schemaRevision: 1, fallback: 'Taylor joined the group',+ data: { type: 'member.joined', actorId: id(12), displayName: 'Taylor' } }] };+ const value = { ...snapshot(), messages: [reply, joined] };+ for (const self of [id(11), id(12)]) {+ const display = chatRoomRow(room(), value, self).item.display;+ expect(display).toMatchObject({+ timestamp: Date.parse(joined.createdAt), lastReplyAt: Date.parse(reply.createdAt),+ });+ expect(resolveRemoteText(display.preview!, 'zh-CN')).toBe('Taylor加入了群聊');+ }+ const later = { ...message(22), createdAt: '2026-10-12T12:00:00Z' };+ expect(chatRoomRow(room(), { ...value, messages: [reply, joined, later] }).item.display)+ .toMatchObject({ timestamp: Date.parse(later.createdAt), preview: '22' });+ expect(chatRoomRow(room(), { ...value, messages: [{ ...joined, origin: 'user' }] }).item.display.preview)+ .toBe('Taylor joined the group');+ });+});+// Merge regression: history generation changes while execution state is read.// Production load must retry, retaining both the new revision and fresh work.it('retains fresh executions when cached history changes during load', async () => {diff --git a/apps/mobile/src/__tests__/remoteResourceCache.test.ts b/apps/mobile/src/__tests__/remoteResourceCache.test.tsindex c93fa1a30e..55dfa34cbe 100644--- a/apps/mobile/src/__tests__/remoteResourceCache.test.ts+++ b/apps/mobile/src/__tests__/remoteResourceCache.test.ts@@ -1,4 +1,6 @@import { beforeEach, expect, it, vi } from 'vitest';+import { resolveRemoteText } from '@cindy/device-link';+import { i18n } from '@/i18n';const disk = vi.hoisted(() => new Map<string, string>());vi.mock('@react-native-async-storage/async-storage', () => ({ default: {getItem: vi.fn(async (key: string) => disk.get(key) ?? null),@@ -172,6 +174,35 @@ it('restores portable roster data after process restart and never persists runtiexpect(disk.size).toBe(0);});+it('resolves cached join notices in the current language without fetching the roster again', async () => {+ const language = i18n.language;+ await i18n.changeLanguage('zh-CN');+ try {+ const room: ChatSnapshot['room'] = { id: 'group', name: 'Group', kind: 'group', archived: false,+ created_at: '2026-10-01', updated_at: '2026-10-02', revision: 1, response_mode: 'all', speaking_mode: 'auto' };+ const row = chatRoomRow(room, { room, members: [], cursor: '1', messages: [{+ id: 'join', seq: '1', authorId: 'member', author: { kind: 'human', name: 'Taylor' },+ createdAt: '2026-10-02', deleted: false, threadRootId: null, origin: 'system',+ content: [{ type: 'card', namespace: 'cindy.membership', schemaRevision: 1,+ fallback: 'Taylor joined the group', data: { type: 'member.joined', displayName: 'Taylor' } }],+ }] });+ await cacheChatRoster('alice', 'global', [row], [room.id]);+ const saved = disk.get('cindy.remoteResources.v1.alice')!;+ await clearRemoteResourceCache(); disk.set('cindy.remoteResources.v1.alice', saved);+ const restored = (await readCachedChatRoster('alice', 'global'))!.items[0];+ for (const [locale, expected] of [+ ['en', 'Taylor joined the group'], ['ja', 'Taylorさんがグループに参加しました'],+ ['ko', 'Taylor 님이 그룹에 참여했습니다'], ['zh-TW', 'Taylor加入了群聊'], ['zh-CN', 'Taylor加入了群聊'],+ ]) {+ await i18n.changeLanguage(locale);+ expect(resolveRemoteText(row.item.display.preview!, i18n.language)).toBe(expected);+ expect(resolveRemoteText(restored.item.display.preview!, i18n.language)).toBe(expected);+ }+ } finally {+ await i18n.changeLanguage(language);+ }+});+// Review regression (unit): valid group/member data can exceed the shared 256 KiB// budget. Exercise persistence and cold read, not just the in-memory mirror.it('persists a bounded recent roster when group avatars exceed the disk budget', async () => {diff --git a/apps/mobile/src/chat/chatServerClient.ts b/apps/mobile/src/chat/chatServerClient.tsindex 1c257dfec6..d636156be2 100644--- a/apps/mobile/src/chat/chatServerClient.ts+++ b/apps/mobile/src/chat/chatServerClient.ts@@ -1,14 +1,13 @@import { inferBotTemplatePresetId } from '@cindy/maker-shared/bot-template-preset';import { createConversationListState } from '@cindy/maker-shared/chatConversationList';import type { ChatHistory } from '@cindy/maker-shared/chat-history';-/** 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 { chatGroupMemberName as memberName, botGroupExecutionFailureBatches, projectBotGroupExecutionFailures } from '@cindy/maker-shared/botGroupPresentation';+import { botGroupMessageSummaryText, botGroupQuoteFromMessage, buildBotGroupQuoteCard, readBotGroupExecutionFailure, readBotGroupQuote, readBotGroupQuoteCard, readBotGroupTaskCard, readImportedBotGroupRuntimeFailureCode, type BotGroupAttachment, type BotGroupMemberView, type BotGroupMessageView, type BotGroupRemoteChatData } from '@cindy/maker-shared/botGroupChat';+import { chatGroupMemberName as memberName, botGroupActivityAt, latestBotGroupMessage, 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';+import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from '@/i18n/locale';import { mobileMarkdownPreviewText } from '@/session/messageMarkdown';-import { botGroupQuoteFromMessage, buildBotGroupQuoteCard } from '@cindy/maker-shared/botGroupChat';export interface ChatRoom {id: string; name: string; state?: string; kind: string; archived: boolean; dissolved_at?: string | null;@@ -106,21 +105,37 @@ export const chatMessageAttachments = (message: ChatMessage): BotGroupAttachmentconst mediaNames = (message: ChatMessage) => message.deleted ? '' : message.content.flatMap(block => block.type === 'media' ? [attachmentName(block)] : []).join(', ');+function joinedMemberName(message: ChatMessage): string | undefined {+ const joined = message.origin === 'system' && !message.deleted && !message.threadRootId && message.content.find(block =>+ block.type === 'card' && block.namespace === 'cindy.membership' && block.schemaRevision === 1 && block.data?.type === 'member.joined');+ return joined && typeof joined.data?.displayName === 'string' && joined.data.displayName.trim() ? joined.data.displayName : undefined;+}+/** Empty device identity means a server-owned conversation, never a fictitious computer. */export function chatRoomRow(room: ChatRoom, snapshot?: ChatSnapshot, selfId?: string): HostedRemoteCollectionItem {const members = snapshot?.members.filter(member => member.state === 'joined') ?? [];- const last = snapshot?.messages.filter(message => !message.threadRootId && !message.deleted)- .sort((a, b) => BigInt(chatCursor(a.seq)) < BigInt(chatCursor(b.seq)) ? 1 : -1)[0];+ const last = latestBotGroupMessage(snapshot?.messages ?? []);+ const joinedName = last && joinedMemberName(last);+ // Cached rows resolve their copy at render time, even after an offline language change.+ const joinedPreview = joinedName && i18next.isInitialized ? {+ fallback: i18next.t('groupChat.notice.memberJoined', { name: joinedName, lng: DEFAULT_LOCALE }),+ translations: Object.fromEntries(SUPPORTED_LOCALES.map(lng => [lng,+ i18next.t('groupChat.notice.memberJoined', { name: joinedName, lng })])),+ } : undefined;const ownerMembers = room.kind === 'direct' ? [] : members;+ const subtitle = members.map(member => memberName(member, ownerMembers)).join(' · ');+ const preview = joinedPreview ?? (last+ ? mobileMarkdownPreviewText(botGroupMessageSummaryText({ content: contentText(last), task: taskCardOf(last) ?? undefined, deleted: last.deleted }) || mediaNames(last)).slice(0, 160) || subtitle+ : '');return { key: `chat:${room.id}`, host: { deviceId: '', deviceName: '' },lastReplySequence: snapshot && selfId ? chatLastReplySequence(snapshot.messages, selfId) : undefined,chatUnread: snapshot?.reads && selfId ? chatUnread(snapshot, selfId) : undefined,groupMembers: snapshot ? members.map(member => chatMemberIdentity(member, ownerMembers)) : 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(member => memberName(member, ownerMembers)).join(' · '),- ...(snapshot ? { preview: last ? mobileMarkdownPreviewText(botGroupMessageSummaryText({ content: contentText(last), task: taskCardOf(last) ?? undefined, deleted: last.deleted }) || mediaNames(last)).slice(0, 160) || members.map(member => memberName(member, ownerMembers)).join(' · ') : '' } : {}),- timestamp: Date.parse(last?.createdAt ?? room.updated_at),+ subtitle,+ ...(snapshot ? { preview } : {}),+ timestamp: botGroupActivityAt({ createdAt: Date.parse(room.created_at), lastMessage: last ? { createdAt: Date.parse(last.createdAt) } : null }),lastReplyAt: snapshot && selfId ? chatLastReplyAt(snapshot.messages, selfId) : undefined },links: members.map(member => ({ rel: 'member', label: memberName(member, ownerMembers),target: { kind: 'resource', ref: { collectionId: 'teammates', kind: 'bot', id: member.id } } })),@@ -206,18 +221,17 @@ export function chatGroupView(page: ChatPage, selfId: string, actors: readonly Ccontent: '', mentions: { all: false, botIds: [] }, noticeCode: runtimeFailureCode === 'RUNTIME_TIMEOUT' ? 'member-timeout' : 'member-failed',runtimeFailureCode, planId: null, files: [], attachments: [], createdAt: Date.parse(message.createdAt) };const member = active.find(candidate => candidate.id === message.authorId);- const joined = message.origin === 'system' && !message.deleted && message.content.find(block =>- block.type === 'card' && block.namespace === 'cindy.membership' && block.schemaRevision === 1 && block.data?.type === 'member.joined');+ const joinedName = joinedMemberName(message);const quote = message.origin === 'system' ? null : readBotGroupQuote(message.content);const task = message.origin === 'system' ? null : taskCardOf(message);return { id: message.id, sequence: index + 1, serverSequence: chatCursor(message.seq), kind: message.origin === 'system' ? 'notice' : 'message',...(task ? { task } : {}), threadRootId: message.threadRootId,authorKind: message.origin === 'system' ? 'system' : message.author.kind === 'human' ? 'user' : 'bot',- authorBotId: message.authorId, authorName: joined && typeof joined.data?.displayName === 'string' ? joined.data.displayName+ authorBotId: message.authorId, authorName: joinedName !== undefined ? joinedName: member ? memberName(member, ownerMembers) : message.author.name,isSelf: message.authorId === selfId, content: contentText(message), mentions: { all: false, botIds: message.mentions ?? [] },...(quote ? { quote: deletedIds.has(quote.messageId) ? { ...quote, originalDeleted: true } : quote } : {}),- noticeCode: joined ? 'member-joined' : null, planId: null, files: [],+ noticeCode: joinedName !== undefined ? 'member-joined' : null, planId: null, files: [],attachments: chatMessageAttachments(message), createdAt: Date.parse(message.createdAt) };});const last = messages.at(-1);diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.mdindex 39a7b085ab..47b3c12d70 100644--- a/docs/product-rules/bot-group-chat.md+++ b/docs/product-rules/bot-group-chat.md@@ -37,6 +37,8 @@- **群是独立的对象**,不是某位伙伴的主任务,也不是普通任务。它与伙伴私聊在侧栏同一列表,保留显式置顶,其余按最新消息排序;群有新消息时向前排列,不另设「群聊」分组,也不进入左侧任务列表。+ 群的最近活动取创建时间与最后一条未删除消息时间的较新值,包含话题回复和全群共享的入群事件;+ 修改群资料不算活动。空群按创建时间排序,但不增加创建提示消息。顶部统一用一个加号提供「新建伙伴」和「新建群聊」两个创建入口,分隔线下另有「输入邀请链接…」作为手动加群的后备;不再常驻单独的加群按钮。搜索同时覆盖伙伴与群聊。- **私聊右上角可以把伙伴带进群**:本机可用伙伴的私聊头部有「添加到群聊」:「发起群聊…」打开新建群聊并预选该伙伴;diff --git a/packages/maker-shared/src/__tests__/botGroupPresentation.test.ts b/packages/maker-shared/src/__tests__/botGroupPresentation.test.tsindex f0fc2d039c..ce34aece0f 100644--- a/packages/maker-shared/src/__tests__/botGroupPresentation.test.ts+++ b/packages/maker-shared/src/__tests__/botGroupPresentation.test.ts@@ -11,9 +11,34 @@ import {botGroupExecutionFailureBatches,chatGroupMembership,botGroupNewMessageCount,+ botGroupActivityAt,+ latestBotGroupMessage,} from '../botGroupPresentation.js';import { chatGroupTalkRouteKey, groupLaneOfRouteKey, isChatOnlyGroupLane, BOT_GROUP_RUNTIME_FAILURE_CODES, readBotGroupExecutionFailure, type BotGroupErrorCode, type BotGroupExecutionFailureView, type BotGroupMemberView, type BotGroupMessageView, type BotGroupNoticeCode, type BotGroupPlanView } from '../botGroupChat.js';+describe('group list activity', () => {+ it('keeps creation as a floor without treating settings edits as activity', () => {+ const group = { createdAt: 20, updatedAt: 100, lastMessage: null };+ expect(botGroupActivityAt(group)).toBe(20);+ expect(botGroupActivityAt({ ...group, lastMessage: { createdAt: 10 } })).toBe(20);+ expect(botGroupActivityAt({ ...group, lastMessage: { createdAt: 30 } })).toBe(30);+ expect(botGroupActivityAt({ createdAt: NaN, lastMessage: { createdAt: 30 } })).toBe(30);+ expect(botGroupActivityAt({ createdAt: 20, lastMessage: { createdAt: NaN } })).toBe(20);+ });++ it('selects topics and shared notices by exact server position without mutating the snapshot', () => {+ const main = { seq: '9007199254740992', deleted: false, threadRootId: null };+ const topic = { ...main, seq: '9007199254740993', threadRootId: 'root' };+ const joined = { ...main, seq: '9007199254740994', origin: 'system' };+ const deleted = { ...main, seq: '9007199254740995', deleted: true };+ const messages = Object.freeze([main, deleted, topic]);+ expect(latestBotGroupMessage(messages)).toBe(topic);+ expect(latestBotGroupMessage([joined, ...messages])).toBe(joined);+ expect(latestBotGroupMessage([deleted])).toBeUndefined();+ expect(latestBotGroupMessage([])).toBeUndefined();+ });+});+// Unit: history browsing needs an actionable count; old-page loads and repeated pushes are not arrivals.it('counts only new messages from other people and companions below the observed tail', () => {const message = { id: 'new', sequence: 11, kind: 'message', authorKind: 'bot' } as BotGroupMessageView;diff --git a/packages/maker-shared/src/botGroupPresentation.ts b/packages/maker-shared/src/botGroupPresentation.tsindex 594d27346f..4a20df00a2 100644--- a/packages/maker-shared/src/botGroupPresentation.ts+++ b/packages/maker-shared/src/botGroupPresentation.ts@@ -54,13 +54,19 @@ export function chatGroupMembership(group: Pick<BotGroupSummary, 'serverBacked'return { self, owner, manager, canLeave };}-/** Latest activity first, like every other chat list. */-export function sortBotGroups(groups: readonly BotGroupSummary[]): BotGroupSummary[] {- const activityAt = (group: BotGroupSummary) =>- Math.max(group.lastMessage?.createdAt ?? 0, group.updatedAt, group.createdAt);- return [...groups].sort(- (left, right) => activityAt(right) - activityAt(left) || left.id.localeCompare(right.id),- );+/** Group activity includes topic replies and system notices, but never deleted messages. */+export function latestBotGroupMessage<T extends { seq: string; deleted?: boolean }>(messages: readonly T[]): T | undefined {+ let latest: T | undefined;+ for (const message of messages) {+ if (!message.deleted && (!latest || BigInt(message.seq) > BigInt(latest.seq))) latest = message;+ }+ return latest;+}++/** Creation gives empty groups a position; profile/settings edits are not chat activity. */+export function botGroupActivityAt(group: { createdAt: number; lastMessage?: { createdAt: number } | null }): number {+ const lastAt = group.lastMessage?.createdAt ?? 0;+ return Math.max(Number.isFinite(lastAt) ? lastAt : 0, Number.isFinite(group.createdAt) ? group.createdAt : 0);}export function botGroupMemberNames(