Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 主人在非主力电脑上打开群时,群任务卡按快照显示,不在本机查不存在的任务
Chris7c3d57b7b43d
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsxindex a11644d473..52c8b2d7ff 100644--- a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx+++ b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx@@ -1117,10 +1117,11 @@ function BotGroupTimelineItem({) : (<>{quoteDisplay ? <BotGroupQuoteBlock display={quoteDisplay} onLocate={onLocateQuote} /> : null}- {/* A task this teammate started from the group; mine is live, another owner's is a snapshot.- An author no longer in the group is unknown: its task may run on another computer, so it- stays a snapshot rather than a lookup on this one. */}- {message.task ? <BotGroupTaskCard task={message.task} owned={member !== undefined && member.isOwned !== false} /> : null}+ {/* A task this teammate started from the group; mine is live where it runs, another owner's is+ a snapshot. An author no longer in the group is unknown: its task may run on another+ computer, so it stays a snapshot rather than a lookup on this one. */}+ {message.task ? <BotGroupTaskCard task={message.task} owned={member !== undefined && member.isOwned !== false}+ botId={member?.botId ?? null} /> : null}{hasText ? (<div className={`min-w-0 text-[var(--msg-assistant-text)] ${CHAT_BODY_CLASS}`}><MarkdownRenderer workingDir="" content={message.content} allowPrivilegedLinks={false} />diff --git a/apps/desktop/src/renderer/features/bots/BotGroupTaskCard.tsx b/apps/desktop/src/renderer/features/bots/BotGroupTaskCard.tsxindex 5e2831149e..0b607ad8a7 100644--- a/apps/desktop/src/renderer/features/bots/BotGroupTaskCard.tsx+++ b/apps/desktop/src/renderer/features/bots/BotGroupTaskCard.tsx@@ -1,17 +1,24 @@/*** An independent task a teammate started from this group (bot-group-chat.md §10).*- * My own teammate's task: the live task link (status icon, click to open), read from the- * delegation row on this computer. Someone else's teammate: the card as it was posted —- * title and state — because that task runs on their computer.+ * My own teammate's task, when this computer is its home: the live task link (status icon,+ * click to open), read from the delegation row here. Someone else's teammate, or mine opened on+ * another of my computers: the card as it was posted — title and state — because that task runs+ * on the companion's home computer.*/import { ListTodo } from 'lucide-react';import { useTranslation } from 'react-i18next';import type { BotGroupTaskCardView } from '../../../shared/botGroupChat';import { BotSessionTaskLink } from './BotSessionTaskLink';+import { useBotProfiles } from './botStore';+import { companionRunsHere } from './companionCloudPresentation';+import { useCompanionCloud } from './companionCloudStore';-export function BotGroupTaskCard({ task, owned }: { task: BotGroupTaskCardView; owned: boolean }) {+export function BotGroupTaskCard({ task, owned, botId }: { task: BotGroupTaskCardView; owned: boolean; botId: string | null }) {const { t } = useTranslation();+ const profiles = useBotProfiles();+ const cloud = useCompanionCloud();+ const live = owned && botId !== null && companionRunsHere(cloud, profiles.map((bot) => bot.id), botId);const state = t(`bots.groupChat.task.state.${task.state}`);return (<div@@ -21,7 +28,7 @@ export function BotGroupTaskCard({ task, owned }: { task: BotGroupTaskCardView;><ListTodo size={14} aria-hidden className="mt-[5px] shrink-0 text-[var(--text-tertiary)]" /><div className="flex min-w-0 flex-1 flex-col gap-0.5">- {owned ? (+ {live ? (<BotSessionTaskLink card={task.meta} sessionId={task.meta.parentSessionId ?? undefined} />) : (<span className="truncate text-14 leading-6 text-[var(--text-primary)]">{task.title}</span>diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTaskCard.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTaskCard.test.tsxindex 26f6aa05f6..9e7c0e97f7 100644--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTaskCard.test.tsx+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupTaskCard.test.tsx@@ -2,11 +2,16 @@import { cleanup, render, screen } from '@testing-library/react';import { afterEach, describe, expect, it, vi } from 'vitest';import type { BotGroupTaskCardView } from '../../../../shared/botGroupChat';+import { EMPTY_COMPANION_CLOUD_SNAPSHOT, type CompanionCloudSnapshot } from '../../../../shared/companionCloud';++const stores = vi.hoisted(() => ({ profileIds: ['bot-a'] as string[], cloud: null as CompanionCloudSnapshot | null }));+vi.mock('../botStore', () => ({ useBotProfiles: () => stores.profileIds.map((id) => ({ id })) }));+vi.mock('../companionCloudStore', () => ({ useCompanionCloud: () => stores.cloud }));vi.mock('react-i18next', () => ({useTranslation: () => ({ t: (key: string) => key.replace('bots.groupChat.task.state.', 'state:') }),}));-// Another owner's task never reaches the live link; the component must not need its stores.+// The live link reads stores of its own; the card only decides whether to show it.vi.mock('../BotSessionTaskLink', () => ({ BotSessionTaskLink: () => <span data-testid="live-link">live</span> }));import { BotGroupTaskCard } from '../BotGroupTaskCard';@@ -17,11 +22,21 @@ const task = (state: BotGroupTaskCardView['state'], summary?: string): BotGroupTstate, title: 'Launch post', ...(summary ? { summary } : {}),});-afterEach(cleanup);+afterEach(() => {+ cleanup();+ stores.profileIds = ['bot-a'];+ stores.cloud = EMPTY_COMPANION_CLOUD_SNAPSHOT;+});+stores.cloud = EMPTY_COMPANION_CLOUD_SNAPSHOT;++const homedOn = (homeDeviceId: string): CompanionCloudSnapshot => ({+ ...EMPTY_COMPANION_CLOUD_SNAPSHOT, enabled: true, selfDeviceId: 'this-desktop',+ actors: [{ id: 'actor-a', externalId: 'bot-a', name: 'LiZi', avatar: null, homeDeviceId }],+});describe('BotGroupTaskCard', () => {it('shows another owner\'s task as the posted snapshot: title and state', () => {- render(<BotGroupTaskCard task={task('completed')} owned={false} />);+ render(<BotGroupTaskCard task={task('completed')} owned={false} botId="bot-b" />);const card = screen.getByTestId('bot-group-task');expect(card.dataset.state).toBe('completed');expect(card.textContent).toContain('Launch post');@@ -30,13 +45,39 @@ describe('BotGroupTaskCard', () => {});it('shows what a waiting task asks for', () => {- render(<BotGroupTaskCard task={task('waiting', 'Which audience?')} owned={false} />);+ render(<BotGroupTaskCard task={task('waiting', 'Which audience?')} owned={false} botId="bot-b" />);expect(screen.getByTestId('bot-group-task').textContent).toContain('state:waiting · Which audience?');});it('shows my own teammate\'s task as the live link', () => {- render(<BotGroupTaskCard task={task('started')} owned />);+ render(<BotGroupTaskCard task={task('started')} owned botId="bot-a" />);expect(screen.getByTestId('live-link')).toBeTruthy();expect(screen.getByTestId('bot-group-task').textContent).toContain('state:started');});++ it('shows my own teammate\'s task live on its home computer', () => {+ stores.cloud = homedOn('this-desktop');+ render(<BotGroupTaskCard task={task('started')} owned botId="bot-a" />);+ expect(screen.getByTestId('live-link')).toBeTruthy();+ });++ it('shows my own teammate\'s task as the snapshot on another of my computers: it runs on its home', () => {+ // A local copy whose home is elsewhere holds neither the group lane nor the task.+ stores.cloud = homedOn('home-desktop');+ render(<BotGroupTaskCard task={task('started')} owned botId="bot-a" />);+ expect(screen.queryByTestId('live-link')).toBeNull();+ expect(screen.getByTestId('bot-group-task').textContent).toContain('Launch post');+ cleanup();+ // No copy here at all.+ stores.cloud = EMPTY_COMPANION_CLOUD_SNAPSHOT;+ stores.profileIds = [];+ render(<BotGroupTaskCard task={task('started')} owned botId="bot-a" />);+ expect(screen.queryByTestId('live-link')).toBeNull();+ cleanup();+ // A copy shadowed after its home moved away.+ stores.profileIds = ['bot-a'];+ stores.cloud = { ...EMPTY_COMPANION_CLOUD_SNAPSHOT, demotedBotIds: ['bot-a'] };+ render(<BotGroupTaskCard task={task('started')} owned botId="bot-a" />);+ expect(screen.queryByTestId('live-link')).toBeNull();+ });});diff --git a/apps/desktop/src/renderer/features/bots/companionCloudPresentation.ts b/apps/desktop/src/renderer/features/bots/companionCloudPresentation.tsindex 975d1b362f..ba2bf2d1f9 100644--- a/apps/desktop/src/renderer/features/bots/companionCloudPresentation.ts+++ b/apps/desktop/src/renderer/features/bots/companionCloudPresentation.ts@@ -67,3 +67,14 @@ export function homeDeviceName(cloud: CompanionCloudSnapshot, botId: string, falconst actor = cloud.actors.find((candidate) => candidate.externalId === botId);return actor?.homeDevice?.name?.trim() || fallback;}++/**+ * Whether this computer runs `botId`: it holds the profile, the copy is not shadowed, and the+ * companion's known home (when the feature is on) is this computer. Sessions and tasks of a+ * companion live only on its home computer, so only there can they be looked up locally.+ */+export function companionRunsHere(cloud: CompanionCloudSnapshot, localBotIds: readonly string[], botId: string): boolean {+ if (!localBotIds.includes(botId) || cloud.demotedBotIds.includes(botId)) return false;+ const home = cloud.enabled ? cloud.actors.find((actor) => actor.externalId === botId)?.homeDeviceId : undefined;+ return !home || home === cloud.selfDeviceId;+}diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.mdindex 1dfcc0bce1..0b527f013d 100644--- a/docs/product-rules/bot-group-chat.md+++ b/docs/product-rules/bot-group-chat.md@@ -349,7 +349,7 @@ Chris 已明确扩展到多人各带伙伴,并选择「主人按群预先授群专线的 `role=group` 是来源身份,不等于只读历史任务,也不单独构成授权。读取自己的 Profile、能力与 Skill 目录时,必须核对活跃执行、伙伴归属、成员状态、授权版本及执行租约;只聊天的专线仍不可读取私人资料。群主身份不能替代伙伴主人身份。-只有伙伴主人发起且当前授权有效的执行,才能从群里启动独立开发任务或发送私聊。独立任务保留群内调用身份与来源范围,沿用普通任务的权限档、审批、隔离目录和工作目录注册。**从群里启动的任务住在这个群里**:父任务就是发起它的群专线,不再改挂或新建私聊。任务一建立,伙伴就以自己的身份在群里发一条带任务卡(`cindy.task` 卡片块,带 fallback 文字;fallback 由发送端按本机界面语言生成,卡片数据本身不含语言)的消息;群通道暂时不可用时,这条「进行中」卡在任务仍在进行期间按退避持续重试,应用重启后由启动恢复再发一次(按幂等 ID 去重,不会重复出现),任务已结束就不再补发;子任务要确认时再发一条「等你确认」的卡(权限请求只说需要批准,不带工具名和参数;提问带问题原文),主人从卡片打开任务作答;任务结束后结果正文、终态卡与交付文件作为伙伴的群消息回到群里。终态卡与主人实时任务卡同一口径:超时任务显示「已超时」,不是「失败了」。交付文件逐个上传,本机发不出去的文件(空文件、超过 100 MB)和服务端明确拒绝的文件跳过并记日志,其余照常送达;只有临时故障才整条稍后重试。超过一条消息 20 个附件上限的文件,与超长正文一样,在同一幂等 ID 家族的后续消息里继续发,不截断。这些消息在任何执行之外以伙伴 actor 发出,不唤醒群专线,也不唤醒私聊;工具返回 `completion_destination=group`,伙伴只需告诉群里开了什么。群的消息通道明确拒绝(伙伴已不在群、群已归档、本机旧式群)时,结果退回该主人与该伙伴的私聊,不丢失。主人的桌面与手机看到的是实时任务卡(读本机委派行;手机直接从 Chat Server 进入的群没有电脑路由,按该伙伴的主力电脑读,主力电脑未知时退回快照),其他成员看到卡片发出时的标题与状态。非主人获得的群工具授权不包含此独立任务能力。群内只能查询或控制由同一授权专线创建的独立任务;主人仍可从私聊管理已启动的任务。群执行结束不会取消已经正式启动的独立任务,后续群内操作必须重新验证当前执行。主人在桌面或手机上从群里的实时任务卡点「停止任务」是主人自己的操作,不是群工具调用:只要求这张卡所在的专线能看到该任务,不要求发起它的群执行仍在进行。+只有伙伴主人发起且当前授权有效的执行,才能从群里启动独立开发任务或发送私聊。独立任务保留群内调用身份与来源范围,沿用普通任务的权限档、审批、隔离目录和工作目录注册。**从群里启动的任务住在这个群里**:父任务就是发起它的群专线,不再改挂或新建私聊。任务一建立,伙伴就以自己的身份在群里发一条带任务卡(`cindy.task` 卡片块,带 fallback 文字;fallback 由发送端按本机界面语言生成,卡片数据本身不含语言)的消息;群通道暂时不可用时,这条「进行中」卡在任务仍在进行期间按退避持续重试,应用重启后由启动恢复再发一次(按幂等 ID 去重,不会重复出现),任务已结束就不再补发;子任务要确认时再发一条「等你确认」的卡(权限请求只说需要批准,不带工具名和参数;提问带问题原文),主人从卡片打开任务作答;任务结束后结果正文、终态卡与交付文件作为伙伴的群消息回到群里。终态卡与主人实时任务卡同一口径:超时任务显示「已超时」,不是「失败了」。交付文件逐个上传,本机发不出去的文件(空文件、超过 100 MB)和服务端明确拒绝的文件跳过并记日志,其余照常送达;只有临时故障才整条稍后重试。超过一条消息 20 个附件上限的文件,与超长正文一样,在同一幂等 ID 家族的后续消息里继续发,不截断。这些消息在任何执行之外以伙伴 actor 发出,不唤醒群专线,也不唤醒私聊;工具返回 `completion_destination=group`,伙伴只需告诉群里开了什么。群的消息通道明确拒绝(伙伴已不在群、群已归档、本机旧式群)时,结果退回该主人与该伙伴的私聊,不丢失。主人的桌面与手机看到的是实时任务卡(桌面在伙伴的主力电脑上读本机委派行,主人在自己的其他电脑上打开群时看快照;手机直接从 Chat Server 进入的群没有电脑路由,按该伙伴的主力电脑读,主力电脑未知时退回快照),其他成员看到卡片发出时的标题与状态。非主人获得的群工具授权不包含此独立任务能力。群内只能查询或控制由同一授权专线创建的独立任务;主人仍可从私聊管理已启动的任务。群执行结束不会取消已经正式启动的独立任务,后续群内操作必须重新验证当前执行。主人在桌面或手机上从群里的实时任务卡点「停止任务」是主人自己的操作,不是群工具调用:只要求这张卡所在的专线能看到该任务,不要求发起它的群执行仍在进行。非主人群工具授权仅允许读取伙伴自身资料、已选能力和自己的技能;应用级能力目录与默认模型查询仍须当前主人执行授权。