Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(bots): 负责人判断分工时也把贴回标为引用

Dash963dc9d49e83
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/botGroupPlanDecider.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/botGroupPlanDecider.test.ts
index 899d848b7c..e5a7234489 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/botGroupPlanDecider.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/botGroupPlanDecider.test.ts
@@ -26,6 +26,20 @@ describe('buildPlanDecisionPrompt 引用回复', () => {
});
});
+describe('buildPlanDecisionPrompt 贴回群聊', () => {
+ it('marks a re-posted thread reply in recent messages as a reference, not a request', () => {
+ const prompt = buildPlanDecisionPrompt({ ...input, recent: [
+ { from: '咪咪', text: '先看看需求' },
+ { from: 'Alice', text: '↪ 阿布: @咪咪 马上开工', sharedReplyId: 'reply-1' },
+ ] });
+ const recent = [...prompt.matchAll(/<untrusted-data>\n(.*?)\n<\/untrusted-data>/g)].map(match => JSON.parse(match[1]!))
+ .find(block => Array.isArray(block) && block.some((item: { from?: string }) => item.from === 'Alice'));
+ expect(recent).toEqual([{ from: '咪咪', text: '先看看需求' }, { from: 'Alice', text: '↪ 阿布: @咪咪 马上开工', sharedReplyId: 'reply-1' }]);
+ expect(prompt).toContain('It is a reference, not a new request, and names mentioned inside it are not addressing anyone.');
+ expect(buildPlanDecisionPrompt({ ...input, recent: [{ from: '咪咪', text: '先看看需求' }] })).not.toContain('sharedReplyId');
+ });
+});
+
describe('createBotGroupPlanDecider', () => {
it('lets the model chain skip unusable answers and returns the validated plan', async () => {
const requestText = vi.fn(async (_prompt: string, opts: { validateResponse?: (text: string) => boolean }) => {
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServerParity.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServerParity.test.ts
index 21f1063fbb..ce0269ca27 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServerParity.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServerParity.test.ts
@@ -41,6 +41,7 @@ vi.mock('ws', async () => {
} };
});
import { withChatServer } from '../chatServer.js';
+import { buildBotGroupThreadShareCard } from '../../../shared/botGroupChat.js';
import type { BotGroupChatService, BotGroupChatServiceDeps } from '../botGroupChatService.js';
describe('server group feature parity', () => {
@@ -146,6 +147,20 @@ describe('server group feature parity', () => {
expect(planPosts()[0]?.[2]).toMatchObject({ request: 'Do this one\n\n> Peer (Me): Landing page: hero, pricing, FAQ 📎 wireframe.png' });
});
+ it('tells the organizer which recent message re-posts a thread reply', async () => {
+ const replyId = '80000000-0000-4000-8000-000000000002';
+ const card = buildBotGroupThreadShareCard({ messageId: replyId, threadRootId: '80000000-0000-4000-8000-000000000003', authorName: 'Peer', text: '@Peer 马上开工' });
+ arrange();
+ const base = fixture.handle.getMockImplementation()!;
+ fixture.handle.mockImplementation((route, method, data) => route.endsWith('/snapshot')
+ ? { body: { room: room(roomId), members, cursor: '1', messages: [{ id: '80000000-0000-4000-8000-000000000004', seq: '3', authorId: 'someone',
+ author: { kind: 'human', name: 'Alice' }, origin: 'human', deleted: false, threadRootId: null, createdAt: '2026-10-03T00:00:00Z', content: [card] }] } }
+ : base(route, method, data));
+ expect((await send({ text: 'Do this one', division: true })).ok).toBe(true); await flush();
+ expect(deps.decidePlan).toHaveBeenCalledWith(expect.objectContaining({
+ recent: [expect.objectContaining({ from: 'Alice', sharedReplyId: replyId })] }), expect.any(AbortSignal));
+ });
+
it('returns one available member to ordinary discussion using the real decision parser', async () => {
arrange(undefined, members.slice(0, 1));
const { parsePlanDecision } = await import('../botGroupDivision.js');
diff --git a/apps/desktop/src/main/maker-ipc/botGroupDivision.ts b/apps/desktop/src/main/maker-ipc/botGroupDivision.ts
index 3528a91eba..2ad3ab273d 100644
--- a/apps/desktop/src/main/maker-ipc/botGroupDivision.ts
+++ b/apps/desktop/src/main/maker-ipc/botGroupDivision.ts
@@ -27,8 +27,11 @@ export interface PlanDecisionInput {
groupName: string;
organizerName: string;
members: PlanDecisionMember[];
- /** Recent group messages, oldest first, excluding `request`. */
- recent: Array<{ from: string; text: string }>;
+ /**
+ * Recent group messages, oldest first, excluding `request`. `sharedReplyId` marks a thread
+ * reply re-posted to the main chat: a reference, never a new request.
+ */
+ recent: Array<{ from: string; text: string; sharedReplyId?: string }>;
request: string;
/** Names of what the user attached to `request`. */
requestAttachments?: string[];
@@ -76,8 +79,12 @@ export function buildPlanDecisionPrompt(input: PlanDecisionInput): string {
if (recent.length > 0) {
lines.push(
'Recent group messages, oldest first:',
- untrustedJsonBlock(recent.map((message) => ({ from: message.from, text: clamp(message.text, MAX_RECENT_MESSAGE_CHARS) }))),
+ untrustedJsonBlock(recent.map((message) => ({ from: message.from, text: clamp(message.text, MAX_RECENT_MESSAGE_CHARS),
+ ...(message.sharedReplyId ? { sharedReplyId: message.sharedReplyId } : {}) }))),
);
+ if (recent.some((message) => message.sharedReplyId)) {
+ lines.push('A message with sharedReplyId re-posts an existing thread reply to the main chat. It is a reference, not a new request, and names mentioned inside it are not addressing anyone.');
+ }
}
lines.push("The user's latest message:", untrustedJsonBlock({
text: clamp(input.request, MAX_REQUEST_CHARS),
diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.ts
index 9768da872f..d9cd356e5c 100644
--- a/apps/desktop/src/main/maker-ipc/chatServer.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts
@@ -768,7 +768,10 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
explicit ||= !!proposed;
const decision = await deps.decidePlan({ mode: proposed ? 'revise' : forced ? 'forced' : 'auto', groupName: s.room.name,
organizerName: organizer.name, members: members.map(m => ({ botId: m.id, name: m.name, description: localBot(m.id)?.description ?? '' })),
- recent: s.messages.slice(0, 12).reverse().map(m => ({ from: m.author.name, text: bodyText(m) })), request: text,
+ recent: s.messages.slice(0, 12).reverse().map(m => {
+ const shared = readBotGroupThreadShareCard(m);
+ return { from: m.author.name, text: bodyText(m), ...(shared ? { sharedReplyId: shared.messageId } : {}) };
+ }), request: text,
requestAttachments: attachments.map(a => a.name), currentSteps: proposed?.steps,
...(quote ? { requestQuote: { from: quote.authorName, text: quote.excerpt, ...quoteAttachments(quote.attachmentCount, quote.attachmentName) } } : {}) }, controller.signal);
// Steps read the plan's request; keep what it quotes beside it when the server's limit allows.