Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): preserve task titles in message previews and quotes
Chris990fbfc9c0f5
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.tsindex 807567b238..e060c8c3a5 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts@@ -747,6 +747,26 @@ describe('Chat Server result delivery and refresh', () => {expect(fixture.handle.mock.calls.some(([route, method]) => route.endsWith('/messages') && method === 'POST')).toBe(false);});+ it.each(['started', 'waiting'] as const)('keeps a %s card-only message readable in previews and posted quotes', async state => {+ const card = buildBotGroupTaskCard({ meta: taskMeta, state, title: 'Launch post' }, taskLabels);+ const original = { id: '90000000-0000-4000-8000-000000000003', seq: '3', authorId: botId, author: { kind: 'bot', name: 'Bot' }, origin: 'bot',+ deleted: false, threadRootId: null, createdAt: '2026-10-03T00:00:00Z', content: [card] };+ fixture.handle.mockImplementation((route, method) => route.endsWith(`/messages/${original.id}`) ? { body: original }+ : route.endsWith('/members') ? { body: [joined(botId, 'bot'), joined(selfId, 'human')] }+ : route.endsWith('/messages') && method === 'POST' ? { body: { id: 'quoted-task' } }+ : route.includes('/messages?') ? { body: [original] }+ : route.endsWith('/snapshot') ? { body: { room: room(roomId), members: [joined(botId, 'bot'), joined(selfId, 'human')], messages: [original], cursor: '3' } }+ : response(route));+ const result = await service.getGroup(roomId);+ if (!result.ok) throw new Error('Expected group');+ expect(result.group.messages[0]).toMatchObject({ content: '', task: { state, title: 'Launch post' } });+ expect(result.group.lastMessage?.preview).toBe('Launch post');+ expect(await service.sendMessage({ groupId: roomId, text: 'Follow up', clientId: `quote-task-${state}`, mentions: { all: false, botIds: [] },+ quote: { messageId: original.id } })).toMatchObject({ ok: true });+ const posted = fixture.handle.mock.calls.find(([route, method]) => route.endsWith('/messages') && method === 'POST')![2];+ expect(posted.content[0]).toMatchObject({ namespace: 'cindy.quote', data: { excerpt: 'Launch post' } });+ });+it('projects the card as the message\'s task, not as body text, and only on the teammate\'s own message', async () => {fixture.profiles = [{ id: 'local-bot', displayName: 'Bot', avatar: null, status: 'active' }];const at = '2026-10-03T00:00:00Z';diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.tsindex 4a315f09a4..f16ac1f1a4 100644--- a/apps/desktop/src/main/maker-ipc/chatServer.ts+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts@@ -34,7 +34,7 @@ import {readBotGroupExecutionFailure, type BotGroupExecutionFailureView,type BotGroupDetail, type BotGroupPlanView, type BotGroupFailure, type BotGroupMessageView, type BotGroupAttachment, type ChatServerApi,botGroupQuoteAttachmentName, botGroupQuoteExcerpt, botGroupQuoteFromMessage, buildBotGroupQuoteCard, readBotGroupQuote, readBotGroupQuoteCard, type BotGroupQuoteView,- readBotGroupTaskCard,+ readBotGroupTaskCard, botGroupMessageSummaryText,} from '../../shared/botGroupChat.js';import type { BotGroupChatService, BotGroupChatServiceDeps, BotGroupLaneTerminal, BotGroupTaskPostInput, BotGroupTaskPostResult } from './botGroupChatService.js';import { readPersistedReplyText } from './botGroupChatService.js';@@ -154,7 +154,10 @@ export function splitChatMessageText(text: string, max = CHAT_MESSAGE_TEXT_MAX):return pieces;}/** Words of a message for a quote excerpt; attachments are summarized separately. */-const quotedText = (m: Message) => bodyBlocks(m).filter(b => b.type !== 'media').map(b => b.text ?? b.fallback ?? '').join('\n');+const quotedText = (m: Message) => botGroupMessageSummaryText({+ content: bodyBlocks(m).filter(b => b.type !== 'media').map(b => b.text ?? b.fallback ?? '').join('\n'),+ task: taskCardOf(m) ?? undefined, deleted: m.deleted,+});const quotedAttachments = (m: Message) => m.content.flatMap(b => b.type === 'media' ? [{ name: b.caption?.trim() || '…' }] : []);/** A quote's attachment summary as model input: how many, and which file it names. */const quoteAttachments = (count: number, name: string | null) => count ? { attachments: count, ...(name ? { attachmentName: name } : {}) } : {};@@ -831,7 +834,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceDname: memberName(m), avatar: 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: (lastView.content.trim() || mediaNames(last)).slice(0, 80), createdAt: lastView.createdAt,+ preview: (botGroupMessageSummaryText(lastView) || mediaNames(last)).slice(0, 80), createdAt: lastView.createdAt,} : null, speakingBotIds: speakers.map(s => s.botId), planningBotId: planning.get(roomId)?.botId ?? null, openPlan: open ? { id: open.id, status: open.status, currentStep: open.currentStep, stepCount: open.steps.length, currentBotName: open.steps[open.currentStep ?? 0]?.botName ?? null, currentStepStatus: open.steps[open.currentStep ?? 0]?.status ?? null } : null,lastReplyAt: s.messages.reduce((latest, m) => !m.deleted && m.origin !== 'system' && m.authorId !== selfId? Math.max(latest, Date.parse(m.createdAt)) : latest, 0),diff --git a/apps/mobile/src/__tests__/chatServerClient.test.ts b/apps/mobile/src/__tests__/chatServerClient.test.tsindex e04b57e308..59f087b4b1 100644--- a/apps/mobile/src/__tests__/chatServerClient.test.ts+++ b/apps/mobile/src/__tests__/chatServerClient.test.ts@@ -1,7 +1,7 @@import { describe, expect, it, vi } from 'vitest';import { i18n } from '@/i18n';import { chatGroupView, chatRoomRow, chatReadAt, createChatServerClient, type ChatMessage, type ChatPage, type ChatRoom, type ChatSnapshot } from '@/chat/chatServerClient';-import { buildBotGroupQuoteCard, buildBotGroupTaskCard } from '@cindy/maker-shared/botGroupChat';+import { botGroupQuoteFromMessage, resolveBotGroupQuote, buildBotGroupQuoteCard, buildBotGroupTaskCard } from '@cindy/maker-shared/botGroupChat';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' });@@ -52,6 +52,18 @@ describe('direct Chat Server client', () => {expect(view.messages[0]).toMatchObject({ authorKind: 'bot', content: 'Started it.', task: { state: 'started', title: 'Launch post' } });expect(view.messages[1].task).toBeUndefined();expect(view.messages[1].content).toBe(`${card.fallback}\nPasted a card`);+ for (const state of ['started', 'waiting'] as const) {+ const onlyCard = { ...fromBot, content: [{ ...card, data: { ...card.data, state } }] };+ const single = chatGroupView({ snapshot: snapshot(), messages: [onlyCard], before: null }, id(11));+ expect(single.messages[0]).toMatchObject({ content: '', task: { state, title: 'Launch post' } });+ expect(single.lastMessage?.preview).toBe('Launch post');+ expect(chatRoomRow(room(), { ...snapshot(), messages: [onlyCard] }, id(11)).item.display.preview).toBe('Launch post');+ const quote = botGroupQuoteFromMessage(single.messages[0]);+ expect(quote.excerpt).toBe('Launch post');+ expect(resolveBotGroupQuote({ ...quote, excerpt: 'stale' }, single.messages)).toMatchObject({ state: 'live', excerpt: 'Launch post' });+ expect(resolveBotGroupQuote(quote, [])).toMatchObject({ state: 'snapshot', excerpt: 'Launch post' });+ }+ expect(botGroupQuoteFromMessage(view.messages[0]).excerpt).toBe('Started it.');});it('reconciles all loaded message pages in bounded requests and clears an old-source failure on refresh', async () => {diff --git a/apps/mobile/src/chat/chatServerClient.ts b/apps/mobile/src/chat/chatServerClient.tsindex fc99866154..842fb889c8 100644--- a/apps/mobile/src/chat/chatServerClient.ts+++ b/apps/mobile/src/chat/chatServerClient.ts@@ -1,5 +1,5 @@/** The existing Chat Server HTTP contract; no device-link or executor registration. */-import { readBotGroupExecutionFailure, readBotGroupQuote, readBotGroupQuoteCard, readBotGroupTaskCard, readImportedBotGroupRuntimeFailureCode, type BotGroupAttachment, type BotGroupMemberView, type BotGroupMessageView, type BotGroupRemoteChatData } from '@cindy/maker-shared/botGroupChat';+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 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.@@ -89,7 +89,7 @@ export function chatRoomRow(room: ChatRoom, snapshot?: ChatSnapshot, selfId?: stref: { 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 ? (contentText(last).trim() || mediaNames(last)).slice(0, 160) || 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(' · ') : '' } : {}),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),@@ -189,7 +189,7 @@ export function chatGroupView(page: ChatPage, selfId: string, actors: readonly Crevision: room.revision, members: memberViews, replyMode: room.response_mode, speakingMode: room.speaking_mode,organizerBotId: room.organizer_id ?? null, projectDir: null, projectDirName: null,createdAt: Date.parse(room.created_at), updatedAt: Date.parse(room.updated_at),- lastMessage: last ? { authorKind: last.authorKind, authorName: last.authorName, preview: last.content.slice(0, 80), createdAt: last.createdAt } : null,+ lastMessage: last ? { authorKind: last.authorKind, authorName: last.authorName, preview: botGroupMessageSummaryText(last).slice(0, 80), createdAt: last.createdAt } : null,speakingBotIds: [], planningBotId: null, openPlan: null, plans: [], messages: projectBotGroupExecutionFailures(messages, failures),hasMoreBefore: page.before !== null, round: { status: 'idle', speakers: [], canContinue: false }, supportsAttachments: false };}diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.mdindex 50dd8c89ca..0542d5c34f 100644--- a/docs/product-rules/bot-group-chat.md+++ b/docs/product-rules/bot-group-chat.md@@ -362,7 +362,7 @@ Chris 已明确扩展到多人各带伙伴,并选择「主人按群预先授群专线的 `role=group` 是来源身份,不等于只读历史任务,也不单独构成授权。读取自己的 Profile、能力与 Skill 目录时,必须核对活跃执行、伙伴归属、成员状态、授权版本及执行租约;只聊天的专线仍不可读取私人资料。群主身份不能替代伙伴主人身份。-只有伙伴主人发起且当前授权有效的执行,才能从群里启动独立开发任务或发送私聊。独立任务保留群内调用身份与来源范围,沿用普通任务的权限档、审批、隔离目录和工作目录注册。**从群里启动的任务住在这个群里**:父任务就是发起它的群专线,不再改挂或新建私聊。任务一建立,伙伴就以自己的身份在群里发一条带任务卡(`cindy.task` 卡片块,带 fallback 文字;fallback 由发送端按本机界面语言生成,卡片数据本身不含语言;群里每位成员都读得到卡片数据,所以卡片只带任务标题,不带伙伴写下的完整任务目标)的消息;群通道暂时不可用时,这条「进行中」卡在任务仍在进行期间按退避持续重试,应用重启后由启动恢复再发一次(按幂等 ID 去重,不会重复出现),任务已结束就不再补发;主人续接已结束的任务时,新一轮同样发一张「进行中」卡(幂等 ID 带轮次,首轮沿用原 ID),群里不再停在上一轮的终态;子任务要确认时再发一条「等你确认」的卡(权限请求只说需要批准,不带工具名和参数;提问带问题原文),主人从卡片打开任务作答;任务结束后结果正文、终态卡与交付文件作为伙伴的群消息回到群里。终态卡与主人实时任务卡同一口径:超时任务显示「已超时」,不是「失败了」。交付文件逐个上传,本机发不出去的文件(空文件、超过 100 MB)和服务端明确拒绝的文件跳过并记日志,其余照常送达;只有临时故障才整条稍后重试。超过一条消息 20 个附件上限的文件,与超长正文一样,在同一幂等 ID 家族的后续消息里继续发,不截断。这些消息在任何执行之外以伙伴 actor 发出,不唤醒群专线,也不唤醒私聊;工具返回 `completion_destination=group`,伙伴只需告诉群里开了什么;从本机旧式群(没有服务器房间)启动时返回 `completion_destination=private`,伙伴告诉群里结果会私下交给主人,不承诺在群里更新。群的消息通道明确拒绝(伙伴已不在群、群已归档、本机旧式群)时,结果退回该主人与该伙伴的私聊,不丢失。主人的桌面与手机看到的是实时任务卡(桌面在伙伴的主力电脑上读本机委派行,主人在自己的其他电脑上打开群时看快照;手机按该伙伴的主力电脑读,不论群是经哪台电脑打开还是直接从 Chat Server 进入;主力电脑未知时,经电脑打开的群读那台电脑,直接进入的群退回快照),其他成员看到卡片发出时的标题与状态。非主人获得的群工具授权不包含此独立任务能力。群内只能查询或控制由同一授权专线创建的独立任务;主人仍可从私聊管理已启动的任务。群执行结束不会取消已经正式启动的独立任务,后续群内操作必须重新验证当前执行。主人在桌面或手机上从群里的实时任务卡点「停止任务」是主人自己的操作,不是群工具调用:只要求这张卡所在的专线能看到该任务,不要求发起它的群执行仍在进行。+只有伙伴主人发起且当前授权有效的执行,才能从群里启动独立开发任务或发送私聊。独立任务保留群内调用身份与来源范围,沿用普通任务的权限档、审批、隔离目录和工作目录注册。**从群里启动的任务住在这个群里**:父任务就是发起它的群专线,不再改挂或新建私聊。任务一建立,伙伴就以自己的身份在群里发一条带任务卡(`cindy.task` 卡片块,带 fallback 文字;fallback 由发送端按本机界面语言生成,卡片数据本身不含语言;群里每位成员都读得到卡片数据,所以卡片只带任务标题,不带伙伴写下的完整任务目标)的消息;群通道暂时不可用时,这条「进行中」卡在任务仍在进行期间按退避持续重试,应用重启后由启动恢复再发一次(按幂等 ID 去重,不会重复出现),任务已结束就不再补发;主人续接已结束的任务时,新一轮同样发一张「进行中」卡(幂等 ID 带轮次,首轮沿用原 ID),群里不再停在上一轮的终态;子任务要确认时再发一条「等你确认」的卡(权限请求只说需要批准,不带工具名和参数;提问带问题原文),主人从卡片打开任务作答;任务结束后结果正文、终态卡与交付文件作为伙伴的群消息回到群里。终态卡与主人实时任务卡同一口径:超时任务显示「已超时」,不是「失败了」。交付文件逐个上传,本机发不出去的文件(空文件、超过 100 MB)和服务端明确拒绝的文件跳过并记日志,其余照常送达;只有临时故障才整条稍后重试。超过一条消息 20 个附件上限的文件,与超长正文一样,在同一幂等 ID 家族的后续消息里继续发,不截断。这些消息在任何执行之外以伙伴 actor 发出,不唤醒群专线,也不唤醒私聊;工具返回 `completion_destination=group`,伙伴只需告诉群里开了什么;从本机旧式群(没有服务器房间)启动时返回 `completion_destination=private`,伙伴告诉群里结果会私下交给主人,不承诺在群里更新。群的消息通道明确拒绝(伙伴已不在群、群已归档、本机旧式群)时,结果退回该主人与该伙伴的私聊,不丢失。主人的桌面与手机看到的是实时任务卡(桌面在伙伴的主力电脑上读本机委派行,主人在自己的其他电脑上打开群时看快照;手机按该伙伴的主力电脑读,不论群是经哪台电脑打开还是直接从 Chat Server 进入;主力电脑未知时,经电脑打开的群读那台电脑,直接进入的群退回快照),其他成员看到卡片发出时的标题与状态。已识别的任务卡不在正文重复显示 fallback;纯任务卡消息的侧栏预览与引用摘要使用任务标题,有正文时优先正文。非主人获得的群工具授权不包含此独立任务能力。群内只能查询或控制由同一授权专线创建的独立任务;主人仍可从私聊管理已启动的任务。群执行结束不会取消已经正式启动的独立任务,后续群内操作必须重新验证当前执行。主人在桌面或手机上从群里的实时任务卡点「停止任务」是主人自己的操作,不是群工具调用:只要求这张卡所在的专线能看到该任务,不要求发起它的群执行仍在进行。非主人群工具授权仅允许读取伙伴自身资料、已选能力和自己的技能;应用级能力目录与默认模型查询仍须当前主人执行授权。diff --git a/packages/maker-shared/src/botGroupQuote.ts b/packages/maker-shared/src/botGroupQuote.tsindex 455bca5a72..8ac31ad1c4 100644--- a/packages/maker-shared/src/botGroupQuote.ts+++ b/packages/maker-shared/src/botGroupQuote.ts@@ -10,6 +10,7 @@* 只有原消息不在本端时才显示快照。卡片内容是群成员提交的数据,读取时逐字段校验,* 不能当作指令或授权,也不能指向别的群或 Thread。*/+import { botGroupMessageSummaryText } from './botGroupTask';import type { BotGroupAttachment, BotGroupMessageView } from './botGroupChat';export const BOT_GROUP_QUOTE_NAMESPACE = 'cindy.quote';@@ -85,12 +86,12 @@ export function botGroupQuoteExcerpt(text: string): string {/** Snapshot of a message the reader can see, e.g. when picking 引用回复 in a timeline. */export function botGroupQuoteFromMessage(message: Pick<BotGroupMessageView,- 'id' | 'sequence' | 'authorKind' | 'authorName' | 'content'> & { attachments: readonly Pick<BotGroupAttachment, 'name'>[] }): BotGroupQuoteView {+ 'id' | 'sequence' | 'authorKind' | 'authorName' | 'content' | 'task' | 'deleted'> & { attachments: readonly Pick<BotGroupAttachment, 'name'>[] }): BotGroupQuoteView {return {messageId: message.id,authorName: clip(message.authorName.trim(), AUTHOR_NAME_MAX),authorKind: message.authorKind === 'user' ? 'user' : 'bot',- excerpt: botGroupQuoteExcerpt(message.content),+ excerpt: botGroupQuoteExcerpt(botGroupMessageSummaryText(message)),attachmentCount: message.attachments.length,attachmentName: botGroupQuoteAttachmentName(message.attachments),sequence: Number.isSafeInteger(message.sequence) && message.sequence > 0 ? message.sequence : null,@@ -200,7 +201,7 @@ export type BotGroupQuoteDisplay =export function resolveBotGroupQuote(quote: BotGroupQuoteView,- loaded: readonly Pick<BotGroupMessageView, 'id' | 'deleted' | 'threadRootId' | 'authorName' | 'content' | 'attachments'>[],+ loaded: readonly Pick<BotGroupMessageView, 'id' | 'deleted' | 'threadRootId' | 'authorName' | 'content' | 'attachments' | 'task'>[],): BotGroupQuoteDisplay {const original = loaded.find((message) => message.id === quote.messageId && !message.threadRootId);if (quote.originalDeleted) return { state: 'deleted', authorName: original?.authorName || quote.authorName };@@ -213,7 +214,7 @@ export function resolveBotGroupQuote(return {state: 'live',authorName: original.authorName || quote.authorName,- excerpt: botGroupQuoteExcerpt(original.content),+ excerpt: botGroupQuoteExcerpt(botGroupMessageSummaryText(original)),...(attachments.length? { attachmentCount: attachments.length, attachmentName: botGroupQuoteAttachmentName(attachments) }: { attachmentCount: quote.attachmentCount, attachmentName: quote.attachmentName }),diff --git a/packages/maker-shared/src/botGroupTask.ts b/packages/maker-shared/src/botGroupTask.tsindex 19e8a3d122..547e4baa68 100644--- a/packages/maker-shared/src/botGroupTask.ts+++ b/packages/maker-shared/src/botGroupTask.ts@@ -4,6 +4,7 @@* card, confirmations and result are posted there as the teammate's own messages,* each carrying one of these cards. Older clients read the `fallback` line.*/+import type { BotGroupMessageView } from './botGroupChat';import { readBotCollaborationMeta, type BotCollaborationMeta } from './botCollaboration';export const BOT_GROUP_TASK_NAMESPACE = 'cindy.task';@@ -31,6 +32,11 @@ export interface BotGroupTaskCard {data: { meta: BotCollaborationMeta; state: BotGroupTaskCardState; title: string; summary?: string };}+/** Preview/quote text without duplicating a task card in the message body. */+export function botGroupMessageSummaryText(message: Pick<BotGroupMessageView, 'content' | 'task' | 'deleted'>): string {+ return message.content.trim() || (message.deleted ? '' : message.task?.title.trim() ?? '');+}+const TITLE_MAX = 120;const SUMMARY_MAX = 400;