Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): 本机读不到的交付文件按单文件跳过;手机直连群按伙伴主力电脑开实时任务卡
Chris21d5eeca3546
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.tsindex 68d58387bb..cf6f51903c 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts@@ -625,6 +625,10 @@ describe('Chat Server result delivery and refresh', () => {['a transient upload failure is retried with the message', new Error('ECONNRESET'), { ok: false, retryable: true }, 0],['a file the server refuses is left out, the result still posts', new ChatResponseError('PAYLOAD_TOO_LARGE', 413), { ok: true }, 1],['a file too large to ever send is left out, the result still posts', new Error('ATTACHMENT_TOO_LARGE'), { ok: true }, 1],+ ['a file this computer cannot read is left out, the result still posts',+ Object.assign(new Error('EACCES: permission denied, open'), { code: 'EACCES', syscall: 'open', errno: -13 }), { ok: true }, 1],+ ['a file read that may succeed shortly is retried with the message',+ Object.assign(new Error('EBUSY: resource busy or locked, open'), { code: 'EBUSY', syscall: 'open', errno: -16 }), { ok: false, retryable: true }, 0],])('%s', async (_label, failure, expected, posts) => {fixture.profiles = [{ id: 'local-bot', displayName: 'Bot', avatar: null, status: 'active' }];fixture.upload.mockRejectedValueOnce(failure);diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.tsindex 2bcb83b71f..2eaf58f388 100644--- a/apps/desktop/src/main/maker-ipc/chatServer.ts+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts@@ -95,6 +95,15 @@ const retryableResponse = (error: ChatResponseError) => recoverableAuth(error)|| error.status >= 500 || [408, 429].includes(error.status);/** A file this computer will never be able to send (chatServerMedia): retrying cannot help. */const LOCAL_FILE_REFUSALS = new Set(['ATTACHMENT_TOO_LARGE', 'ATTACHMENT_UNAVAILABLE']);+/** Filesystem failures that may clear on their own; any other local read failure is permanent for this delivery. */+const TRANSIENT_FS_CODES = new Set(['EAGAIN', 'EBUSY', 'EINTR', 'EMFILE', 'ENFILE', 'ENOMEM', 'EIO']);+/** A delivery file this computer cannot read or send: refused once, never retried. */+function fileRefusedHere(error: unknown): boolean {+ if (!(error instanceof Error) || error instanceof ChatResponseError) return false;+ if (LOCAL_FILE_REFUSALS.has(error.message)) return true;+ const { code, syscall } = error as { code?: unknown; syscall?: unknown };+ return typeof syscall === 'string' && typeof code === 'string' && !TRANSIENT_FS_CODES.has(code);+}const id = z.string().uuid();const memberJoinedTrigger = z.object({ type: z.literal('member.joined'), messageId: id, actorId: id,displayName: z.string().min(1).refine(value => value.trim().length > 0) }).strict();@@ -1596,15 +1605,14 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD} catch { /* a file deleted since the task finished is simply not delivered */ }}// Files go up one at a time so a refused file never holds back the others: a file this- // computer cannot send (empty, over the size limit) or the server definitely refuses is- // left out with a warning, while a transient failure keeps the whole message for a retry.+ // computer cannot send (empty, over the size limit, unreadable) or the server definitely+ // refuses is left out with a warning, while a transient failure keeps the whole message for a retry.const uploaded: ChatContentBlock[] = [];for (const file of produced) {try {uploaded.push(...await media.upload(roomId, input.clientId, [file], actor.id));} catch (error) {- const refusedHere = error instanceof Error && !(error instanceof ChatResponseError) && LOCAL_FILE_REFUSALS.has(error.message);- if (!refusedHere && (!(error instanceof ChatResponseError) || retryableResponse(error))) throw error;+ if (!fileRefusedHere(error) && (!(error instanceof ChatResponseError) || retryableResponse(error))) throw error;deps.log?.warn('Chat task delivery file refused', { groupId: roomId, ...chatErrorDiagnostic(error) });}}diff --git a/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx b/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsxindex 1c0662b9f5..238c3824a6 100644--- a/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx+++ b/apps/mobile/src/__tests__/BotGroupChatScreen.test.tsx@@ -323,6 +323,23 @@ describe('group timeline', () => {expect(byId('botGroup.task.live')).toBeNull();});+ it('opens my own teammate\'s task live in a group entered straight from the Chat Server, via the companion\'s home computer', async () => {+ const meta = { v: 1 as const, role: 'delegation-request' as const, delegationId: 'task-3', fromBotId: 'mimi', fromBotName: '咪咪', toBotId: null,+ toBotName: 'Cindy', parentSessionId: 'group-lane', childSessionId: 'child-3', objective: '写官网首页' };+ const data = group({ serverBacked: true, members: [+ { botId: 'mimi', name: '咪咪', avatar: '🐱', avatarColor: 'red', status: 'active', isOwned: true, homeDeviceId: 'pc' },+ { botId: 'abu', name: '阿布', avatar: '🦉', avatarColor: 'blue', status: 'active', isOwned: true, homeDeviceId: null },+ ] });+ data.messages.push(message('t3', 22, { authorBotId: 'mimi', authorName: '咪咪', content: '我开了个任务', task: { meta, state: 'started', title: '官网首页' } }),+ message('t4', 23, { authorBotId: 'abu', authorName: '阿布', content: '我也开了', task: { meta: { ...meta, delegationId: 'task-4', fromBotId: 'abu' }, state: 'started', title: '整理行程' } }));+ h.chat = { ...h.chat, server: true, state: { kind: 'ready', group: data } };+ // No computer on the route: the direct Chat Server entry.+ await act(async () => root.render(el(BotGroupChatScreen, { deviceId: '', deviceName: '', groupId: 'g1' })));+ expect(all('botGroup.task.live')).toHaveLength(1);+ // A companion whose computer the account does not know stays a snapshot.+ expect(byId('botGroup.task')!.textContent).toContain('整理行程');+ });+it('shows a task from an author who has left the group as a snapshot, never a lookup on this phone\'s computer', async () => {const meta = { v: 1 as const, role: 'delegation-request' as const, delegationId: 'task-2', fromBotId: 'gone', fromBotName: '离开的伙伴', toBotId: null,toBotName: 'Cindy', parentSessionId: 'group-lane', childSessionId: 'child-2', objective: '整理行程' };diff --git a/apps/mobile/src/__tests__/chatServerClient.test.ts b/apps/mobile/src/__tests__/chatServerClient.test.tsindex d16949ed7b..5bbd830a50 100644--- a/apps/mobile/src/__tests__/chatServerClient.test.ts+++ b/apps/mobile/src/__tests__/chatServerClient.test.ts@@ -1,5 +1,5 @@import { describe, expect, it, vi } from 'vitest';-import { chatGroupView, chatRoomRow, chatReadAt, createChatServerClient, type ChatMessage, type ChatRoom, type ChatSnapshot } from '@/chat/chatServerClient';+import { chatGroupView, chatRoomRow, chatReadAt, createChatServerClient, type ChatMessage, type ChatPage, type ChatRoom, type ChatSnapshot } from '@/chat/chatServerClient';import { 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,@@ -29,6 +29,18 @@ describe('direct Chat Server client', () => {expect(deleted.messages[0].quote).toMatchObject({ messageId: id(20), originalDeleted: true });});+ it('names the home computer of my own companions from the account actors, never of other members', () => {+ const mine = { id: id(12), kind: 'bot' as const, name: 'Mine', state: 'joined', ownerActorId: id(11), ownerName: '', avatar: null, role: 'member' as const };+ const theirs = { id: id(13), kind: 'bot' as const, name: 'Theirs', state: 'joined', ownerActorId: id(10), ownerName: '', avatar: null, role: 'member' as const };+ const page: ChatPage = { snapshot: { ...snapshot(), members: [...snapshot().members, mine, theirs] }, messages: [], before: null };+ const actors = [{ id: id(12), kind: 'bot', externalId: 'mine', name: 'Mine', avatar: null, homeDeviceId: 'pc' }];+ const members = chatGroupView(page, id(11), actors).members;+ expect(members.find(member => member.botId === id(12))).toMatchObject({ isOwned: true, homeDeviceId: 'pc' });+ expect(members.find(member => member.botId === id(13))).not.toHaveProperty('homeDeviceId');+ // Without the actor list (older or failed read) an owned companion has no known computer.+ expect(chatGroupView(page, id(11)).members.find(member => member.botId === id(12))).toMatchObject({ homeDeviceId: null });+ });+it('reads a task card on a teammate message as its task, and only there (bot-group-chat.md §10)', () => {const card = buildBotGroupTaskCard({ meta: { v: 1, role: 'delegation-request', delegationId: 'task-1', fromBotId: 'bot', fromBotName: 'Bot',toBotId: null, toBotName: 'Cindy', parentSessionId: 'lane', childSessionId: 'child', objective: 'Launch post' }, state: 'started', title: 'Launch post' },diff --git a/apps/mobile/src/chat/chatServerClient.ts b/apps/mobile/src/chat/chatServerClient.tsindex 6c49fa8693..36ea2be5b3 100644--- a/apps/mobile/src/chat/chatServerClient.ts+++ b/apps/mobile/src/chat/chatServerClient.ts@@ -124,13 +124,18 @@ function chatMemberIdentity(member: ChatMember) {return { botId: member.id, name: memberName(member), ...chatMemberAvatar(member.avatar), avatarColor: '' };}-/** Sequence strings stay on the wire; numeric positions below are presentation order only. */-export function chatGroupView(page: ChatPage, selfId: string): BotGroupRemoteChatData {+/**+ * Sequence strings stay on the wire; numeric positions below are presentation order only.+ * `actors` (the account's own, from `/actors`) tell which computer runs each owned companion.+ */+export function chatGroupView(page: ChatPage, selfId: string, actors: readonly ChatActor[] = []): BotGroupRemoteChatData {const { 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,isOwned: member.ownerActorId === selfId, role: member.role,+ ...(member.ownerActorId === selfId && member.kind === 'bot'+ ? { homeDeviceId: actors.find(actor => actor.id === member.id)?.homeDeviceId ?? null } : {}),status: 'active',}));const deletedIds = new Set(page.messages.filter(message => message.deleted).map(message => message.id));diff --git a/apps/mobile/src/chat/useChatServer.ts b/apps/mobile/src/chat/useChatServer.tsindex 90708968d4..8035a1261c 100644--- a/apps/mobile/src/chat/useChatServer.ts+++ b/apps/mobile/src/chat/useChatServer.ts@@ -8,7 +8,7 @@ import { getActiveMobileSessionRealm, getMobileEndpointForRealm, loadMobileEndpoimport { markRemoteResourceRead } from '@/device-link/remoteResourceCache';import { useRemoteSyncCoordinator } from '@/device-link/remoteSyncTask';import type { BotGroupChatState } from '@/session/useBotGroupChat';-import { chatAccessLost, chatCursor, chatGroupView, chatHttpsUrl, chatRoomRow, chatReadAt, chatReadSequence, chatLastReplyAt, chatLastReplySequence, createChatServerClient, type ChatPage, type ChatRequest, type ChatSnapshot } from './chatServerClient';+import { chatAccessLost, chatCursor, chatGroupView, chatHttpsUrl, chatRoomRow, chatReadAt, chatReadSequence, chatLastReplyAt, chatLastReplySequence, createChatServerClient, type ChatActor, type ChatPage, type ChatRequest, type ChatSnapshot } from './chatServerClient';import { subscribeChatServer } from './chatServerSubscription';/** The account's Chat Server client, fenced to the current account, realm and mount. */@@ -143,7 +143,7 @@ export function useChatServerGroup(groupId: string, enabled: boolean) {const identity = `${api.owner}:${groupId}`;const active = useRef(identity); active.current = identity;const [state, setState] = useState<{ identity: string; value: BotGroupChatState; online: boolean; loadingOlder: boolean }>({ identity, value: { kind: 'loading' }, online: true, loadingOlder: false });- const page = useRef<{ identity: string; page: ChatPage; self: string } | null>(null);+ const page = useRef<{ identity: string; page: ChatPage; self: string; actors: ChatActor[] } | null>(null);const accessGeneration = useRef(0);const freshRead = useRef(false);const olderPending = useRef(false);@@ -159,12 +159,14 @@ export function useChatServerGroup(groupId: string, enabled: boolean) {try {const previous = page.current?.identity === identity ? page.current.page : null;const oldest = previous?.messages.reduce<string | undefined>((oldest, message) => !oldest || BigInt(message.seq) < BigInt(oldest) ? message.seq : oldest, undefined);- const [next, self] = await Promise.all([api.client.load(groupId, oldest), api.client.me()]);+ // The account's actors say which computer runs each owned companion (live task cards);+ // the group still reads when that list is unavailable.+ const [next, self, actors] = await Promise.all([api.client.load(groupId, oldest), api.client.me(), api.client.actors().catch((): ChatActor[] => [])]);if (run.isStale() || !valid() || generation !== accessGeneration.current) return;// Replace the reauthorized window; no stale history survives changed access.freshRead.current = true;- page.current = { identity, page: next, self };- setState({ identity, value: { kind: 'ready', group: chatGroupView(next, self) }, online: true, loadingOlder: false });+ page.current = { identity, page: next, self, actors };+ setState({ identity, value: { kind: 'ready', group: chatGroupView(next, self, actors) }, online: true, loadingOlder: false });} catch (error) {if (run.isStale() || !valid() || generation !== accessGeneration.current) return;if (chatAccessLost(error)) loseAccess();@@ -210,7 +212,7 @@ export function useChatServerGroup(groupId: string, enabled: boolean) {const next = await api.client.older(groupId, previous.page);if (!valid() || page.current !== previous) return;page.current = { ...previous, page: next };- setState({ identity, value: { kind: 'ready', group: chatGroupView(next, previous.self) }, online: true, loadingOlder: false });+ setState({ identity, value: { kind: 'ready', group: chatGroupView(next, previous.self, previous.actors) }, online: true, loadingOlder: false });} catch (error) {if (valid() && page.current === previous && chatAccessLost(error)) loseAccess();throw error;diff --git a/apps/mobile/src/session/BotGroupChatScreen.tsx b/apps/mobile/src/session/BotGroupChatScreen.tsxindex a7f59de664..c8464ca8d5 100644--- a/apps/mobile/src/session/BotGroupChatScreen.tsx+++ b/apps/mobile/src/session/BotGroupChatScreen.tsx@@ -540,8 +540,11 @@ function BotGroupTimelineItem({{quoteDisplay ? <BotGroupQuote display={quoteDisplay} /> : 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 (same rule as the desktop timeline). */}- {message.task ? <BotGroupTaskCard task={message.task} owned={member !== undefined && member.isOwned !== false} deviceId={deviceId} /> : null}+ stays a snapshot rather than a lookup on this one (same rule as the desktop timeline).+ A group opened straight from the Chat Server carries no computer: the live card reads+ the owned companion's home computer instead. */}+ {message.task ? <BotGroupTaskCard task={message.task} owned={member !== undefined && member.isOwned !== false}+ deviceId={deviceId || member?.homeDeviceId || ''} /> : null}{message.attachments?.length ? <BotGroupMessageAttachments messageId={message.id} attachments={message.attachments} align="left" onResolveRemoteMedia={resolveMedia} resolveServerMedia={resolveServerMedia} /> : null}{message.content.trim() ? <BotGroupMarkdownText content={message.content} /> : null}<BotGroupHandoffFiles files={message.files} />diff --git a/apps/mobile/src/session/BotGroupTaskCard.tsx b/apps/mobile/src/session/BotGroupTaskCard.tsxindex bdc2f2a4f9..a6cb64137d 100644--- a/apps/mobile/src/session/BotGroupTaskCard.tsx+++ b/apps/mobile/src/session/BotGroupTaskCard.tsx@@ -2,8 +2,9 @@* An independent task a teammate started from this group (bot-group-chat.md §10).** My own teammate's task: the live task card read from the computer that runs it (same card- * as a teammate chat). Someone else's teammate: the card as it was posted — title and state —- * because that task runs on their computer.+ * as a teammate chat); `deviceId` is that computer — the group's, or for a group opened straight+ * from the Chat Server the companion's home computer. Someone else's teammate, or a companion+ * whose computer is unknown: the card as it was posted — title and state.*/import { ListTodo } from 'lucide-react-native';import { StyleSheet, View } from 'react-native';diff --git a/docs/product-rules/bot-group-chat.md b/docs/product-rules/bot-group-chat.mdindex e57c3461b8..6e89ad22c0 100644--- a/docs/product-rules/bot-group-chat.md+++ b/docs/product-rules/bot-group-chat.md@@ -340,7 +340,7 @@ Chris 已明确扩展到多人各带伙伴,并选择「主人按群预先授群专线的 `role=group` 是来源身份,不等于只读历史任务,也不单独构成授权。读取自己的 Profile、能力与 Skill 目录时,必须核对活跃执行、伙伴归属、成员状态、授权版本及执行租约;只聊天的专线仍不可读取私人资料。群主身份不能替代伙伴主人身份。-只有伙伴主人发起且当前授权有效的执行,才能从群里启动独立开发任务或发送私聊。独立任务保留群内调用身份与来源范围,沿用普通任务的权限档、审批、隔离目录和工作目录注册。**从群里启动的任务住在这个群里**:父任务就是发起它的群专线,不再改挂或新建私聊。任务一建立,伙伴就以自己的身份在群里发一条带任务卡(`cindy.task` 卡片块,带 fallback 文字;fallback 由发送端按本机界面语言生成,卡片数据本身不含语言)的消息;子任务要确认时再发一条「等你确认」的卡(权限请求只说需要批准,不带工具名和参数;提问带问题原文),主人从卡片打开任务作答;任务结束后结果正文、终态卡与交付文件作为伙伴的群消息回到群里。终态卡与主人实时任务卡同一口径:超时任务显示「已超时」,不是「失败了」。交付文件逐个上传,本机发不出去的文件(空文件、超过 100 MB)和服务端明确拒绝的文件跳过并记日志,其余照常送达;只有临时故障才整条稍后重试。超过一条消息 20 个附件上限的文件,与超长正文一样,在同一幂等 ID 家族的后续消息里继续发,不截断。这些消息在任何执行之外以伙伴 actor 发出,不唤醒群专线,也不唤醒私聊;工具返回 `completion_destination=group`,伙伴只需告诉群里开了什么。群的消息通道明确拒绝(伙伴已不在群、群已归档、本机旧式群)时,结果退回该主人与该伙伴的私聊,不丢失。主人的桌面与手机看到的是实时任务卡(读本机委派行),其他成员看到卡片发出时的标题与状态。非主人获得的群工具授权不包含此独立任务能力。群内只能查询或控制由同一授权专线创建的独立任务;主人仍可从私聊管理已启动的任务。群执行结束不会取消已经正式启动的独立任务,后续群内操作必须重新验证当前执行。+只有伙伴主人发起且当前授权有效的执行,才能从群里启动独立开发任务或发送私聊。独立任务保留群内调用身份与来源范围,沿用普通任务的权限档、审批、隔离目录和工作目录注册。**从群里启动的任务住在这个群里**:父任务就是发起它的群专线,不再改挂或新建私聊。任务一建立,伙伴就以自己的身份在群里发一条带任务卡(`cindy.task` 卡片块,带 fallback 文字;fallback 由发送端按本机界面语言生成,卡片数据本身不含语言)的消息;子任务要确认时再发一条「等你确认」的卡(权限请求只说需要批准,不带工具名和参数;提问带问题原文),主人从卡片打开任务作答;任务结束后结果正文、终态卡与交付文件作为伙伴的群消息回到群里。终态卡与主人实时任务卡同一口径:超时任务显示「已超时」,不是「失败了」。交付文件逐个上传,本机发不出去的文件(空文件、超过 100 MB)和服务端明确拒绝的文件跳过并记日志,其余照常送达;只有临时故障才整条稍后重试。超过一条消息 20 个附件上限的文件,与超长正文一样,在同一幂等 ID 家族的后续消息里继续发,不截断。这些消息在任何执行之外以伙伴 actor 发出,不唤醒群专线,也不唤醒私聊;工具返回 `completion_destination=group`,伙伴只需告诉群里开了什么。群的消息通道明确拒绝(伙伴已不在群、群已归档、本机旧式群)时,结果退回该主人与该伙伴的私聊,不丢失。主人的桌面与手机看到的是实时任务卡(读本机委派行;手机直接从 Chat Server 进入的群没有电脑路由,按该伙伴的主力电脑读,主力电脑未知时退回快照),其他成员看到卡片发出时的标题与状态。非主人获得的群工具授权不包含此独立任务能力。群内只能查询或控制由同一授权专线创建的独立任务;主人仍可从私聊管理已启动的任务。群执行结束不会取消已经正式启动的独立任务,后续群内操作必须重新验证当前执行。非主人群工具授权仅允许读取伙伴自身资料、已选能力和自己的技能;应用级能力目录与默认模型查询仍须当前主人执行授权。diff --git a/packages/maker-shared/src/botGroupChat.ts b/packages/maker-shared/src/botGroupChat.tsindex ef8d11d0e1..5dfb92cbac 100644--- a/packages/maker-shared/src/botGroupChat.ts+++ b/packages/maker-shared/src/botGroupChat.ts@@ -126,6 +126,8 @@ export interface BotGroupMemberView {ownerActorId?: string;ownerName?: string;isOwned?: boolean;+ /** The computer running this owned companion (its Chat Server actor home); live task cards read there. */+ homeDeviceId?: string | null;avatarUrl?: string | null;guestAccess?: 'none' | 'chat' | 'tools';accessRevision?: number;