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。

Merge origin/main into fix/6761-group-reply-files

ylliuuu669d447644826a
diff --cc apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
index a7a388a9e0,c71f1adbf8..a33237acf7
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
@@@ -1821,40 -1708,146 +1915,169 @@@ describe('Chat Server result delivery a
expect(deliveries()[0][2]).not.toHaveProperty('continueDiscussion');
});
+ it.each(['talk', 'work'] as const)('delivers explicit files for talk replies without changing the work pipeline (%s)', async kind => {
+ const planId = '80000000-0000-4000-8000-000000000001';
+ const plan = { id: planId, revision: 1, source_message_id: execution.source_message_id, request_text: 'Report', organizer_id: botId, creator_id: selfId,
+ status: 'running', current_step: 0, kind, steps: [{ position: 0, botId, botName: 'Bot', task: 'report', status: 'running' }] };
+ singleSpeaker(route => {
+ if (route === '/executions/claim' && !claimed) { claimed = true; return { body: { execution: { ...execution, access_mode: kind === 'talk' ? 'owner' : 'chat', plan_id: planId, plan_step: 0 } } }; }
+ if (route.includes('/plans?ids=')) return { body: [plan] };
+ if (route.endsWith(`/messages/${execution.source_message_id}`)) return { body: message(execution.source_message_id, 'Report') };
+ return undefined;
+ });
+ replyFiles.prepare.mockResolvedValue({ text: 'Report', attachments: [{ id: 'pdf', name: 'report.pdf' }] });
+ fixture.upload.mockImplementationOnce(async () => kind === 'talk' ? [{ type: 'media', mediaId: 'pdf', caption: 'report.pdf' }] : []);
+ if (kind === 'talk') await startFileReply(); else await start();
+ await service.settleLaneTurn({ ...terminal, resultText: '[Report](./report.pdf)' });
+ expect(deliveries()[0][2]).not.toHaveProperty('continueDiscussion');
+ if (kind === 'talk') {
+ expect(deliveries()[0][2].content).toEqual([{ type: 'text', text: 'Report' }, { type: 'media', mediaId: 'pdf', caption: 'report.pdf' }]);
+ } else {
+ expect(replyFiles.prepare).not.toHaveBeenCalled();
+ expect(deliveries()[0][2].content).toEqual([{ type: 'text', text: '[Report](./report.pdf)' }]);
+ }
+ });
+
- it('sends without holding the request for a helper-model arrangement decision', async () => {
- singleSpeaker();
- deps.decidePlan = vi.fn() as typeof deps.decidePlan;
- expect(await service.sendMessage({ groupId: roomId, text: 'Make a draft', clientId: 'single-speaker-send', mentions: { all: false, botIds: [] }, division: true }))
- .toMatchObject({ ok: true });
- await vi.advanceTimersByTimeAsync(0);
- const post = fixture.handle.mock.calls.find(([route, method]) => route === `/conversations/${roomId}/messages` && method === 'POST')!;
- expect(post[2].deferExecution).toBe(false);
- expect(deps.decidePlan).not.toHaveBeenCalled();
+ // A queue turn builds on the answer just before it (a 分工 hand-off's 2000 characters); older
+ // answers get a main-group message's 600, so a long queue does not resend every answer in full.
+ it('shortens the earlier answers a queue turn reads', async () => {
+ const planId = '80000000-0000-4000-8000-000000000003';
+ const ids = ['50000000-0000-4000-8000-000000000041', '50000000-0000-4000-8000-000000000042', '50000000-0000-4000-8000-000000000043'];
+ const texts = ['a'.repeat(601), 'b'.repeat(600), 'c'.repeat(2001)];
+ const plan = { id: planId, revision: 1, source_message_id: execution.source_message_id, request_text: 'Q', organizer_id: otherBot, creator_id: selfId,
+ note_message_ids: [], status: 'running', current_step: 3, kind: 'talk', created_at: '2026-10-03T00:00:00Z', updated_at: '2026-10-03T00:00:00Z',
+ steps: [...ids.map((resultMessageId, position) => ({ position, botId: otherBot, botName: 'Peer', task: '', status: 'done', resultMessageId })),
+ { position: 3, botId, botName: 'Bot', task: '', status: 'running' }] };
+ singleSpeaker(route => {
+ if (route === '/executions/claim' && !claimed) { claimed = true; return { body: { execution: { ...execution, access_mode: 'owner', plan_id: planId, plan_step: 3 } } }; }
+ if (route.includes('/plans?ids=')) return { body: [plan] };
+ if (route.includes('/messages?all=true')) return { body: ids.map((id, index) => message(id, texts[index]!, { authorId: otherBot, author: { kind: 'bot', name: 'Peer' }, origin: 'bot' })) };
+ if (route.endsWith(`/messages/${execution.source_message_id}`)) return { body: message(execution.source_message_id, 'Q') };
+ return undefined;
+ });
+ await start();
+ const block = prompt().split('<untrusted-data>\n').map(part => part.split('\n</untrusted-data>')[0]!).find(part => part.includes('earlierAnswers'))!;
+ expect(JSON.parse(block).earlierAnswers).toEqual([
+ { from: 'Peer', text: `${'a'.repeat(600)}…`, shortened: true },
+ { from: 'Peer', text: 'b'.repeat(600) },
+ { from: 'Peer', text: `${'c'.repeat(2000)}…`, shortened: true },
+ ]);
+ });
+
+ // bot-group-chat.md §7.0 (2026-10-23): 「安排分工」 is back on these servers. A request that writes
+ // out who does what becomes that card and starts, with no helper model; otherwise the organizer
+ // arranges it. The request is held so the server's own queue does not answer it first.
+ describe('安排分工', () => {
+ const sourceId = '50000000-0000-4000-8000-000000000031', planId = '80000000-0000-4000-8000-000000000031';
+ const named = () => members().map(m => m.id === otherBot ? { ...m, name: 'Nova' } : m);
+ function divisionServer(open: object[] = []) {
+ singleSpeaker((route, method) => {
+ if (route.endsWith('/snapshot')) return { body: { room: room(roomId), members: named(), messages: [], cursor: '1' } };
+ if (route === `/conversations/${roomId}/messages` && method === 'POST') return { body: { id: sourceId } };
+ if (route === `/conversations/${roomId}/plans` && method === 'POST') return { body: { id: planId, revision: 1 } };
+ if (route === `/conversations/${roomId}/plans`) return { body: open };
+ return undefined;
+ });
+ }
+ const posts = () => fixture.handle.mock.calls.filter(([, method]) => method === 'POST');
+ const send = async (text: string) => {
+ expect(await service.sendMessage({ groupId: roomId, text, clientId: `division-${text.length}`, mentions: { all: false, botIds: [] }, division: true }))
+ .toMatchObject({ ok: true });
+ await vi.advanceTimersByTimeAsync(0);
+ };
+
+ it('starts the card a request writes out, without the organizer', async () => {
+ divisionServer();
+ deps.decidePlan = vi.fn() as typeof deps.decidePlan;
+ await send('登录页:@Bot (Owner) 出方案,然后 @Nova (Owner) 按方案实现');
+ expect(posts().find(([route]) => route === `/conversations/${roomId}/messages`)![2]).toMatchObject({ deferExecution: true });
+ expect(posts().find(([route]) => route === `/conversations/${roomId}/plans`)![2]).toMatchObject({ sourceMessageId: sourceId,
+ steps: [{ botId, task: '出方案' }, { botId: otherBot, task: '按方案实现' }] });
+ expect(posts().find(([route]) => route === `/conversations/${roomId}/plans/${planId}`)![2]).toMatchObject({ action: 'start', expectedRevision: 1 });
+ expect(deps.decidePlan).not.toHaveBeenCalled();
+ // Only a 分工 asked for here follows this computer's 自动交接.
+ expect(workspaceSettings.get(roomId)).toMatchObject({ startedHere: [planId] });
+ });
+
+ it('lets the organizer arrange it when a picked teammate no longer reads in the text', async () => {
+ divisionServer();
+ deps.decidePlan = vi.fn(async () => ({ needsPlan: true as const, steps: [{ botId, task: 'design' }, { botId: otherBot, task: 'build' }] }));
+ // Bot was picked as @OldName and renamed before sending: its step must not be dropped.
+ expect(await service.sendMessage({ groupId: roomId, text: '@OldName 出方案,然后 @Nova (Owner) 按方案实现', clientId: 'division-renamed',
+ mentions: { all: false, botIds: [botId, otherBot] }, division: true })).toMatchObject({ ok: true });
+ await vi.advanceTimersByTimeAsync(0);
+ expect(deps.decidePlan).toHaveBeenCalled();
+ expect(posts().some(([route]) => route === `/conversations/${roomId}/plans/${planId}`)).toBe(false);
+ });
+
+ it('answers the request when nobody can arrange it, and later messages still go out', async () => {
+ divisionServer();
+ deps.decidePlan = undefined;
+ await send('Make a draft');
+ expect(posts().some(([route]) => route === `/conversations/${roomId}/messages/${sourceId}/continue`)).toBe(true);
+ expect(await service.sendMessage({ groupId: roomId, text: 'Another thing', clientId: 'after-no-organizer', mentions: { all: false, botIds: [] } }))
+ .toMatchObject({ ok: true });
+ });
+
+ // §4.0: in a mention-only group an unaddressed message wakes nobody, not even the helper revising your proposed card.
+ it.each([['all', true], ['mentioned', false]] as const)('in %s mode, unaddressed words revise your proposed card: %s', async (mode, revises) => {
+ const proposed = { id: planId, revision: 1, source_message_id: execution.source_message_id, request_text: 'Q', organizer_id: botId, creator_id: selfId,
+ note_message_ids: [], status: 'proposed', current_step: null, kind: 'work', created_at: '2026-10-03T00:00:00Z', updated_at: '2026-10-03T00:00:00Z',
+ steps: [{ position: 0, botId, botName: 'Bot', task: 'draft', status: 'pending' }] };
+ singleSpeaker((route, method) => {
+ if (route.endsWith('/snapshot')) return { body: { room: { ...room(roomId), response_mode: mode }, members: named(), messages: [], cursor: '1' } };
+ if (route === `/conversations/${roomId}/messages` && method === 'POST') return { body: { id: sourceId } };
+ if (route === `/conversations/${roomId}/plans`) return { body: [proposed] };
+ return undefined;
+ });
+ deps.decidePlan = vi.fn(async () => null);
+ expect(await service.sendMessage({ groupId: roomId, text: 'Make it shorter', clientId: `revise-${mode}`, mentions: { all: false, botIds: [] } }))
+ .toMatchObject({ ok: true });
+ await vi.advanceTimersByTimeAsync(0);
+ expect(posts().find(([route]) => route === `/conversations/${roomId}/messages`)![2]).toMatchObject({ deferExecution: revises });
+ expect(vi.mocked(deps.decidePlan!).mock.calls.length > 0).toBe(revises);
+ });
+
+ // The server cannot release a held request, so a newer message must not replace one still being arranged.
+ it('refuses a newer message while the organizer is arranging', async () => {
+ divisionServer();
+ deps.decidePlan = vi.fn(() => new Promise<never>(() => {}));
+ await send('Make a draft');
+ expect(await service.sendMessage({ groupId: roomId, text: 'Another thing', clientId: 'after-division', mentions: { all: false, botIds: [] } }))
+ .toMatchObject({ ok: false, errorCode: 'PLAN_OPEN' });
+ expect(posts().filter(([route]) => route === `/conversations/${roomId}/messages`)).toHaveLength(1);
+ });
+
+ it('asks the organizer when the steps are not written out', async () => {
+ divisionServer();
+ deps.decidePlan = vi.fn(async () => ({ needsPlan: true as const, steps: [{ botId: otherBot, task: 'build' }] }));
+ await send('@Bot (Owner) 和 @Nova (Owner) 一起做登录页');
+ expect(deps.decidePlan).toHaveBeenCalledWith(expect.objectContaining({ mode: 'forced' }), expect.anything());
+ expect(posts().find(([route]) => route === `/conversations/${roomId}/plans`)![2]).toMatchObject({ steps: [{ botId: otherBot, task: 'build' }] });
+ expect(posts().some(([route]) => route === `/conversations/${roomId}/plans/${planId}`)).toBe(false);
+ });
+
+ it('answers the request at once when no card comes of it, instead of a queue two minutes later', async () => {
+ divisionServer();
+ deps.decidePlan = vi.fn(async () => { throw new Error('model unavailable'); });
+ await send('Make a draft');
+ expect(posts().some(([route]) => route === `/conversations/${roomId}/messages/${sourceId}/continue`)).toBe(true);
+ });
+
+ it('ends your queue waiting for 继续 before opening the card', async () => {
+ const queue = { id: '80000000-0000-4000-8000-000000000032', revision: 4, source_message_id: execution.source_message_id, request_text: 'Q', organizer_id: botId,
+ creator_id: selfId, note_message_ids: [], status: 'waiting', current_step: 4, kind: 'talk', created_at: '2026-10-03T00:00:00Z', updated_at: '2026-10-03T00:00:00Z',
+ steps: [{ position: 4, botId, botName: 'Bot', task: '', status: 'done' }] };
+ divisionServer([queue]);
+ await send('@Bot (Owner) 出方案');
+ const routes = posts().map(([route]) => route);
+ expect(routes.indexOf(`/conversations/${roomId}/plans/${queue.id}`)).toBeLessThan(routes.indexOf(`/conversations/${roomId}/plans`));
+ expect(posts().find(([route]) => route === `/conversations/${roomId}/plans/${queue.id}`)![2]).toMatchObject({ action: 'stop', expectedRevision: 4 });
+ });
});
+ // Words for a card under way reach its current step when they would wake anyone: the requester
+ // adding to a turn, or asking the teammate who just finished a 分工 step to redo it (§4.0, §7.4).
it.each([
['waiting for 继续: a new request replaces it', 'waiting', `/conversations/${roomId}/messages`],
['mid-turn: the words go to the teammate answering', 'running', `/conversations/${roomId}/plans/80000000-0000-4000-8000-000000000002/messages`],
diff --cc apps/desktop/src/main/maker-ipc/chatServer.ts
index 06a3a98df7,37194bbd6b..86cbd7fa0e
--- a/apps/desktop/src/main/maker-ipc/chatServer.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts
@@@ -19,10 -17,10 +19,11 @@@ import { request as httpsRequest } fro
import { migrateLocalGroups, type ChatContentBlock } from './chatServerMigration.js';
import { chatErrorDiagnostic, chatGroupFailure, missingGroupCode } from './chatServerErrors.js';
import { createChatMedia } from './chatServerMedia.js';
+import { mergeChatReplyAttachments } from './chatServerReplyAttachments.js';
import { prepareChatReplyImages } from './chatServerReplyImages.js';
import { chatServerWorkspaces } from './chatServerWorkspaces.js';
- import { buildPlanStepBrief } from './botGroupDivision.js';
+ import { buildPlanStepBrief, draftPlanSteps, type PlanStepDraft } from './botGroupDivision.js';
+ import { splitBotGroupRelaySteps } from '@cindy/maker-shared/botGroupMentions';
import { chatMigrationReceipts } from './chatMigrationReceipts.js';
import { prepareBotGroupTaskPost, type BotGroupTaskPostSnapshot } from './botGroupTaskPostSnapshot.js';
import { registerGroupToolAuthority, GroupToolAuthorizationError } from './botGroupToolAuthorization.js';