Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
Merge latest main into cindy/wise-jepsen
Dash906faff1cf52
diff --cc apps/desktop/src/main/maker-ipc/chatServer.tsindex 4d484fe74f,994d86245f..2cf0c7a8e0--- a/apps/desktop/src/main/maker-ipc/chatServer.ts+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts@@@ -443,17 -443,15 +458,18 @@@ function createChatServer(local: BotGroif (event.type === 'ready') {memberJoinedClaims = true;reconnectDelay = 500; connected = true;+ threads.reset();ws.send(JSON.stringify({ type: 'subscribe', scope: `actor:${selfId}`, after: '0' }));- for (const roomId of rooms) ws.send(JSON.stringify({ type: 'subscribe', scope: `conversation:${roomId}`, after: '0' }));- for (const roomId of rooms) changed(roomId);+ for (const [roomId, cursor] of rooms) ws.send(JSON.stringify({ type: 'subscribe', scope: `conversation:${roomId}`, after: cursor }));+ for (const roomId of rooms.keys()) changed(roomId);} else if (event.type === 'changes') {- // This adapter stores no client history/cursor. Each invalidation re-reads- // authoritative state; reconnect always starts from zero.+ // This adapter stores no client history. Each invalidation re-reads authoritative+ // state; a reconnect resumes after the last cursor this process has read or acked.if (event.scope.startsWith('conversation:')) {const roomId = event.scope.slice(13);+ if (rooms.has(roomId)) advanceRoom(roomId, event.cursor);+ for (const change of event.changes ?? [])+ if (change.type === 'message.updated' || change.type === 'message.deleted') threads.invalidate(roomId, change.entityId);changed(roomId);for (const run of running.values()) if (run.execution.conversation_id === roomId) void checkLease(run);}@@@ -467,8 -465,7 +483,9 @@@if (event.error?.code === 'RESET_REQUIRED') {void api<Snapshot>(`/conversations/${roomId}/snapshot`).then(value => {if (!current() || socket !== ws || ws.readyState !== WebSocket.OPEN) return;+ if (rooms.has(roomId)) advanceRoom(roomId, value.cursor);+ // Edits and deletions before the new cursor will never be pushed.+ threads.reset();changed(roomId);ws.send(JSON.stringify({ type: 'subscribe', scope: event.scope, after: value.cursor }));}).catch(() => ws.close());@@@ -561,60 -566,30 +588,73 @@@return view;});}+ /**+ * Attach thread previews (roots) and resolved shares (main-chat references) to the views+ * of `page`. `snapshot` is the newest window across all threads. A share whose reply is+ * still being read is marked `loading`: the card's own fallback text is never shown here.+ */+ async function decorateThreads(roomId: string, views: BotGroupMessageView[], page: Message[], snapshot: Message[], members: Member[], withPreviews: boolean,+ shownShares: Array<{ id: string; messageId: string; threadRootId: string; sharerId?: string }> = []) {+ // Taken before reading, so a change while this read is in progress marks it stale.+ const version = threads.version();+ const previews = withPreviews ? threads.previews(roomId, page, snapshot) : new Map<string, Message[]>();+ const sources = threads.sources(roomId, [...page.flatMap(m => readBotGroupThreadShareCard(m)?.messageId ?? []),+ ...shownShares.map(share => share.messageId)], [...snapshot, ...page]);+ const shareable = [...sources.values()].filter((m): m is Message => !!m && isShareableThreadReply(m));+ const sourceViews = new Map((await messageViews(roomId, shareable, members)).map(view => [view.id, view]));+ const shareView = (card: { messageId: string; threadRootId: string }, sharerId?: string): BotGroupThreadShareView => {+ const source = sources.get(card.messageId);+ const resolved = source && source.threadRootId === card.threadRootId ? sourceViews.get(source.id) : undefined;+ return source && resolved ? {+ ...card, status: 'available', authorKind: resolved.authorKind, authorBotId: resolved.authorBotId, authorName: resolved.authorName,+ sharedByAuthor: source.authorId === sharerId, content: resolved.content, attachments: resolved.attachments,+ createdAt: resolved.createdAt, edited: (source.revision ?? 1) > 1, version,+ } : { ...card, status: sources.has(card.messageId) ? 'unavailable' : 'loading', authorKind: 'user', authorBotId: null, authorName: '', sharedByAuthor: false,+ content: '', attachments: [], createdAt: null, edited: false, version };+ };+ const byId = new Map(page.map(m => [m.id, m]));+ for (const view of views) {+ const message = byId.get(view.id);+ if (!message) continue;+ const replies = previews.get(message.id)?.flatMap(reply => {+ const replyView = messageView(reply, members);+ return replyView.kind === 'message' ? [{ id: reply.id, authorKind: replyView.authorKind, authorBotId: replyView.authorBotId,+ authorName: replyView.authorName, isSelf: replyView.isSelf, text: threadPreviewText(reply),+ attachments: threadPreviewAttachments(reply), createdAt: replyView.createdAt }] : [];+ });+ if (replies?.length) view.threadPreview = { replies };+ const card = readBotGroupThreadShareCard(message);+ if (card) view.threadShare = shareView(card, message.authorId);+ }+ // Shares on pages loaded earlier. The sharer ID only picks the label; content is the server's.+ return { version, updates: Object.fromEntries(shownShares.filter(share => !byId.has(share.id)).map(({ id: shareId, sharerId, ...card }) =>+ [shareId, shareView(card, sharerId && (actors.find(actor => actor.externalId === sharerId)?.id ?? sharerId))])) };+ }async function detail(roomId: string, options?: unknown, summaryOnly = false): Promise<BotGroupDetail> {- const s = await snapshot(roomId);+ id.parse(roomId);const o = z.object({ beforeSequence: z.number().int().positive().optional(), limit: z.number().int().min(1).max(100).optional(),- sourceMessageIds: z.array(id).optional() }).parse(options ?? {});+ sourceMessageIds: z.array(id).optional(),+ shownShares: z.array(z.object({ id, messageId: id, threadRootId: id, sharerId: z.string().min(1).max(200).optional() })).max(BOT_GROUP_SHOWN_SHARES_MAX).optional() }).parse(options ?? {});const query = new URLSearchParams({ limit: String(o.limit ?? 100) });if (o.beforeSequence) query.set('before', String(o.beforeSequence));- const page = summaryOnly ? s.messages : await api<Message[]>(`/conversations/${roomId}/messages?${query}`);- const executions = await api<Execution[]>(`/conversations/${roomId}/executions`);- const executionFailures = summaryOnly ? undefined : await failureSnapshot(roomId, s.members, [...(o.sourceMessageIds ?? []), ...page.map(m => m.id)], executions);+ // Independent reads share a round trip. Each is awaited in the former serial order, so the+ // first failure in snapshot → messages → executions → failures → plans is still the one+ // reported (a left room stays 「not found」), whichever request fails first in time.+ // A followed room reports every later change, so its snapshot may run alongside. A new+ // room first takes the snapshot cursor it will follow from, before the rest is read.+ const snapshotRead = snapshot(roomId);+ if (!rooms.has(roomId)) await snapshotRead;+ const messagesRead = summaryOnly ? null : api<Message[]>(`/conversations/${roomId}/messages?${query}`);+ const executionsRead = api<Execution[]>(`/conversations/${roomId}/executions`);+ for (const read of [messagesRead, executionsRead]) read?.catch(() => undefined);+ const s = await snapshotRead;+ const page = (await messagesRead) ?? s.messages;+ const executions = await executionsRead;const ids = page.flatMap(m => m.content.flatMap(b => b.namespace === 'cindy.plan' && typeof b.data?.planId === 'string' ? [id.parse(b.data.planId)] : []));- const serverPlans = await api<ServerPlan[]>(`/conversations/${roomId}/plans${ids.length ? `?ids=${ids.join(',')}` : ''}`);+ const plansRead = api<ServerPlan[]>(`/conversations/${roomId}/plans${ids.length ? `?ids=${ids.join(',')}` : ''}`);+ plansRead.catch(() => undefined);+ const executionFailures = summaryOnly ? undefined : await failureSnapshot(roomId, s.members, [...(o.sourceMessageIds ?? []), ...page.map(m => m.id)], executions);+ const serverPlans = await plansRead;const workspace = workspaces().read(roomId);const plans = serverPlans.map(plan => planView(plan, s.members, workspace));const open = plans.find(p => ['proposed', 'running', 'waiting'].includes(p.status));@@@ -1420,7 -1358,9 +1460,9 @@@continuePlan: input => safe(() => actPlan(input, 'continue')), retryPlan: input => safe(() => actPlan(input, 'retry')),editPlanStep: input => safe(() => actPlan(input, 'reassign')),dispose: () => {- disposed = true; clearInterval(timer); clearInterval(heartbeat); clearTimeout(reconnect); socket?.close();+ disposed = true; threads.dispose(); clearInterval(timer); clearInterval(heartbeat); clearTimeout(reconnect); socket?.close();+ for (const refresh of attachmentRefreshes.values()) clearTimeout(refresh);+ attachmentRefreshes.clear();for (const run of running.values()) {run.releaseToolAuthority?.();if (run.sessionId) void deps.abortLane(run.sessionId).catch(() => undefined);diff --cc apps/desktop/src/renderer/features/bots/BotGroupChatView.tsxindex 1e0edbc86b,ba078e50de..0c9c67bdd5--- a/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx+++ b/apps/desktop/src/renderer/features/bots/BotGroupChatView.tsx@@@ -805,44 -769,25 +815,63 @@@ function BotGroupChatContent({ groupId);}+/** Older shares checked before the latest edit, deletion or reset: they may be out of date. */+function staleBotGroupShares(older: readonly BotGroupMessageView[], version: number | undefined) {+ return older.filter(message => message.threadShare && version !== undefined && (message.threadShare.version ?? 0) < version);+}++/**+ * Which older shares one refresh re-checks: stale or still-loading ones first, then the+ * newest, up to the per-read cap. The rest are checked by later refreshes.+ */+function botGroupShownShares(older: readonly BotGroupMessageView[], version: number | undefined) {+ const withShares = older.filter(message => message.threadShare).reverse();+ const first = new Set(withShares.filter(message => message.threadShare!.status === 'loading'+ || (version !== undefined && (message.threadShare!.version ?? 0) < version)));+ return [...first, ...withShares.filter(message => !first.has(message))].slice(0, BOT_GROUP_SHOWN_SHARES_MAX).map(message => ({+ id: message.id, messageId: message.threadShare!.messageId, threadRootId: message.threadShare!.threadRootId,+ ...(message.authorBotId ? { sharerId: message.authorBotId } : {}) }));+}++/**+ * Apply the refreshed older shares. One this refresh could not check that is older than the+ * latest version stops quoting its old text until a later refresh confirms it.+ */+function applyBotGroupThreadShareUpdates(older: BotGroupMessageView[], group: Pick<BotGroupDetail, 'threadShareUpdates' | 'threadShareVersion'>) {+ const { threadShareUpdates: updates, threadShareVersion: version } = group;+ if (!updates && version === undefined) return older;+ let changed = false;+ const next = older.map(message => {+ const share = message.threadShare;+ if (!share) return message;+ const update = updates?.[message.id];+ if (update) { changed = true; return { ...message, threadShare: update }; }+ if (version === undefined || (share.version ?? 0) >= version || share.status !== 'available') return message;+ changed = true;+ return { ...message, threadShare: { ...share, status: 'loading' as const, authorName: '', authorBotId: null, content: '', attachments: [], edited: false } };+ });+ return changed ? next : older;+}++ function BotGroupTimelineLoading() {+ const { t } = useTranslation();+ const [visible, setVisible] = useState(false);+ useEffect(() => {+ const timer = setTimeout(() => setVisible(true), TIMELINE_LOADING_REVEAL_MS);+ return () => clearTimeout(timer);+ }, []);+ if (!visible) return null;+ return (+ <Spinner+ size={20}+ data-testid="bot-group-timeline-loading"+ className="text-[var(--text-tertiary)]"+ role="status"+ aria-label={t('ccAgent.common.loading')}+ />+ );+ }+function planCardPending(action: PlanPending['action'] | null): BotGroupPlanCardAction | null {return action === 'start' || action === 'dismiss' || action === 'edit' ? action : null;}