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(desktop): gate stop scope and short context on the capability

zqchris998424a06652
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
index c1ed360e7a..1cd71849dd 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/chatServer.test.ts
@@ -1350,16 +1350,17 @@ describe('Chat Server result delivery and refresh', () => {
const otherHuman = '30000000-0000-4000-8000-000000000002';
const member = (id: string, kind: 'human' | 'bot', ownerActorId: string, role = 'member') =>
({ id, kind, name: id === botId ? 'Bot' : 'Peer', displayName: 'Peer', nickname: null, avatar: null, ownerActorId, ownerName: 'Owner', state: 'joined', role, guestAccess: 'chat', accessRevision: 1 });
- const members = (role = 'member') => [member(selfId, 'human', selfId, role), member(botId, 'bot', selfId), member(otherBot, 'bot', selfId), member(otherHuman, 'human', otherHuman), member(foreignBot, 'bot', otherHuman)];
+ // botRole: the account's own teammate may hold the owner/admin role instead of its human.
+ const members = (role = 'member', botRole = 'member') => [member(selfId, 'human', selfId, role), member(botId, 'bot', selfId), member(otherBot, 'bot', selfId, botRole), member(otherHuman, 'human', otherHuman), member(foreignBot, 'bot', otherHuman)];
const message = (id: string, text: string, extra: object = {}) => ({ id, seq: '1', authorId: selfId, author: { kind: 'human', name: 'Dash' }, origin: 'user',
content: [{ type: 'text', text }], createdAt: '2026-10-03T00:00:00Z', deleted: false, threadRootId: null, mentions: [], ...extra });
- function singleSpeaker(extra: (route: string, method?: string, body?: Record<string, unknown>) => unknown = () => undefined, role = 'member') {
+ function singleSpeaker(extra: (route: string, method?: string, body?: Record<string, unknown>) => unknown = () => undefined, role = 'member', botRole = 'member') {
fixture.handle.mockImplementation((route, method, body) => {
const override = extra(route, method, body);
if (override) return override;
if (route === '/me') return { body: { actor: { id: selfId }, capabilities: { groupSingleSpeaker: 1 } } };
- if (route.endsWith('/snapshot')) return { body: { room: room(roomId), members: members(role), messages: [], cursor: '1' } };
- if (route.endsWith('/members')) return { body: members(role) };
+ if (route.endsWith('/snapshot')) return { body: { room: room(roomId), members: members(role, botRole), messages: [], cursor: '1' } };
+ if (route.endsWith('/members')) return { body: members(role, botRole) };
return response(route);
});
}
@@ -1442,18 +1443,40 @@ describe('Chat Server result delivery and refresh', () => {
['a member stops only their own requests and teammates', 'member', undefined, [['own', undefined], ['bot', otherBot]]],
['an owner may stop everyone', 'owner', 'all', [['own', undefined], ['bot', undefined], ['foreign', undefined]]],
['an owner who did not ask for all stops only their own', 'owner', undefined, [['own', undefined], ['bot', otherBot]]],
- ] as const)('%s', async (_label, role, scope, expected) => {
+ ['a member whose own teammate is admin stops everyone as that teammate', 'member', 'all', [['own', undefined], ['bot', otherBot], ['foreign', otherBot]], 'admin'],
+ ] as const)('%s', async (_label, role, scope, expected, botRole?: string) => {
const ids = { own: '40000000-0000-4000-8000-00000000000a', bot: '40000000-0000-4000-8000-00000000000b', foreign: '40000000-0000-4000-8000-00000000000c' };
singleSpeaker(route => route === `/conversations/${roomId}/executions` ? { body: [
{ ...execution, id: ids.own, status: 'queued', bot_id: foreignBot, requester_id: selfId },
{ ...execution, id: ids.bot, status: 'running', bot_id: otherBot, requester_id: otherHuman },
{ ...execution, id: ids.foreign, status: 'queued', bot_id: foreignBot, requester_id: otherHuman },
- ] } : undefined, role);
+ ] } : undefined, role, botRole ?? 'member');
const from = fixture.requests.length;
expect(await service.stopRound(roomId, scope)).toEqual({ ok: true });
const stops = fixture.requests.slice(from).filter(r => r.url.endsWith('/control'));
expect(stops.map(r => [Object.entries(ids).find(([, id]) => r.url.includes(id))![0], r.actor || undefined])).toEqual(expected);
});
+
+ // Without the capability the server still runs rounds: Stop ends the whole round and replies read the full main group.
+ const olderServer = (extra: (route: string) => unknown = () => undefined) =>
+ singleSpeaker(route => route === '/me' ? { body: { actor: { id: selfId } } } : extra(route));
+ it('keeps the whole-round stop on an older server', async () => {
+ olderServer(route => route === `/conversations/${roomId}/executions` ? { body: [
+ { ...execution, id: '40000000-0000-4000-8000-00000000000a', status: 'queued', bot_id: foreignBot, requester_id: selfId },
+ { ...execution, id: '40000000-0000-4000-8000-00000000000c', status: 'queued', bot_id: foreignBot, requester_id: otherHuman },
+ ] } : undefined);
+ await vi.advanceTimersByTimeAsync(0);
+ const from = fixture.requests.length;
+ expect(await service.stopRound(roomId)).toEqual({ ok: true });
+ expect(fixture.requests.slice(from).filter(r => r.url.endsWith('/control'))).toHaveLength(2);
+ });
+ it('keeps the full main-group context on an older server', async () => {
+ const history = Array.from({ length: 15 }, (_, n) => message(`50000000-0000-4000-8000-0000000001${String(n).padStart(2, '0')}`, `earlier message ${n}`));
+ olderServer(route => route.includes('/messages?all=true') ? { body: history } : undefined);
+ await start();
+ expect(prompt()).toContain('earlier message 0');
+ expect(prompt()).not.toContain('earlierMessagesOmitted');
+ });
});
it('falls back to ordinary claims when an old strict server rejects the added capability', async () => {
diff --git a/apps/desktop/src/main/maker-ipc/chatServer.ts b/apps/desktop/src/main/maker-ipc/chatServer.ts
index a8f9c58587..b01520e2da 100644
--- a/apps/desktop/src/main/maker-ipc/chatServer.ts
+++ b/apps/desktop/src/main/maker-ipc/chatServer.ts
@@ -1181,7 +1181,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
const lastView = last ? messageView(last, s.members) : null;
// The sidebar never resolves shares: it names the sharer and never quotes the card's text.
const lastIsShare = !!last && !!readBotGroupThreadShareCard(last);
- return { serverBacked: true, reactionRevision: reactionRevisions.get(roomId)?.room ?? runtimeReactionRevision, reactionRevisions: { ...reactionRevisions.get(roomId)?.messages }, supportsGroupLeave: true, supportsDissolve, supportsListRemoval, dissolvedAt: s.room.dissolved_at ?? null, migrationPending: [...upgradeErrors.keys()].some(source => upgradedGroups.get(source) === roomId), archived: s.room.archived, selfActorId: selfId, topic: s.room.topic, description: s.room.description, revision: s.room.revision, canInvite: !s.room.dissolved_at && s.members.some(m => m.ownerActorId === selfId && m.state === 'joined' && ['owner', 'admin'].includes(m.role)), canStopAll: s.members.some(m => m.id === selfId && m.state === 'joined' && ['owner', 'admin'].includes(m.role)), ...(singleSpeaker ? { singleSpeaker: true } : {}), id: s.room.id, name: s.room.name, replyMode: s.room.response_mode, speakingMode: s.room.speaking_mode,
+ return { serverBacked: true, reactionRevision: reactionRevisions.get(roomId)?.room ?? runtimeReactionRevision, reactionRevisions: { ...reactionRevisions.get(roomId)?.messages }, supportsGroupLeave: true, supportsDissolve, supportsListRemoval, dissolvedAt: s.room.dissolved_at ?? null, migrationPending: [...upgradeErrors.keys()].some(source => upgradedGroups.get(source) === roomId), archived: s.room.archived, selfActorId: selfId, topic: s.room.topic, description: s.room.description, revision: s.room.revision, canInvite: !s.room.dissolved_at && s.members.some(m => m.ownerActorId === selfId && m.state === 'joined' && ['owner', 'admin'].includes(m.role)), canStopAll: !!managementActor(s), ...(singleSpeaker ? { singleSpeaker: true } : {}), id: s.room.id, name: s.room.name, replyMode: s.room.response_mode, speakingMode: s.room.speaking_mode,
members: s.members.filter(m => m.state === 'joined').map(m => {
const p = localBot(m.id);
return { botId: p?.id ?? m.id, actorId: m.id, actorKind: m.kind, isSelf: m.id === selfId,
@@ -1212,7 +1212,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
steps: plan.steps.map(s => ({ ...s, botId: localBot(s.botId)?.id ?? s.botId })), currentStep: plan.current_step,
workDir: workspace?.plans[plan.id]?.workDir ?? null, branch: workspace?.plans[plan.id]?.branch ?? null,
...(plan.kind ? { kind: plan.kind,
- canManage: plan.creator_id === selfId || members.some(m => m.id === selfId && ['owner', 'admin'].includes(m.role)) } : {}),
+ canManage: plan.creator_id === selfId || members.some(m => m.ownerActorId === selfId && m.state === 'joined' && ['owner', 'admin'].includes(m.role)) } : {}),
createdAt: Date.parse(plan.created_at), updatedAt: Date.parse(plan.updated_at) };
}
async function actPlan(input: unknown, action: string) {
@@ -1226,8 +1226,11 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
// The shared UI uses dismiss for both an unstarted proposal and ending a paused plan.
// Chat Server distinguishes these actions; preserve the local service's waiting semantics.
const serverAction = action === 'dismiss' && plan.status === 'waiting' ? 'stop' : i.action ?? action;
+ // Someone else's plan is managed as the account's owner/admin member, which may be its own teammate.
+ const manager = plan.creator_id === selfId ? undefined : managementActor(await recentSnapshot(room));
+ const asManager = manager === selfId ? undefined : manager;
await api(`/conversations/${room}/plans/${plan.id}`, 'POST', { operationId: randomUUID(), expectedRevision: plan.revision,
- action: serverAction, position: i.position, botId });
+ action: serverAction, position: i.position, botId }, asManager);
changed(room); return { ok: true as const };
}
async function decideArrangement(s: Snapshot, sourceId: string, text: string, forced: boolean, attachments: BotGroupAttachment[], intent: PlanIntent, quote: BotGroupQuoteView | null = null) {
@@ -1634,7 +1637,10 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
const conversation = thread ? {
thread: { root: thread.root ? focusMessage(thread.root) : { id: threadRootId, unavailable: true },
replies: chronological(thread.replies).map(focusMessage), earlierRepliesOmitted: thread.earlierRepliesOmitted },
- } : run.plan?.kind === 'talk' ? {} : mainGroupContext(chronological(history.filter(message => !message.threadRootId)), promptMessage);
+ } : run.plan?.kind === 'talk' ? {}
+ // The shortened main-group context belongs to single-speaker servers; older ones keep the full projection.
+ : singleSpeaker ? mainGroupContext(chronological(history.filter(message => !message.threadRootId)), promptMessage)
+ : { messages: chronological(history.filter(message => !message.threadRootId)).map(promptMessage) };
const talk = run.plan?.kind === 'talk' ? run.plan : undefined;
const prompt = [
run.context.kind === 'member.joined'
@@ -2235,9 +2241,23 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
stopRound: (roomId, scopeInput) => safe(async () => {
const room = await groupRoom(id.parse(roomId));
await replacePlanIntent(room);
+ // Older servers keep the whole-round stop; the narrower scope belongs to single-speaker groups (§4.0).
+ if (!singleSpeaker) {
+ const plans = await api<ServerPlan[]>(`/conversations/${room}/plans`);
+ for (const plan of plans.filter(p => ['proposed','running','waiting'].includes(p.status))) await actPlan({ groupId: room, planId: plan.id }, 'stop');
+ const executions = await api<Execution[]>(`/conversations/${room}/executions`);
+ for (const e of executions.filter(e => ['queued', 'running', 'needs_input'].includes(e.status) && !e.plan_id)) {
+ await api(`/conversations/${room}/executions/${e.id}/control`, 'POST', { operationId: randomUUID(), action: 'stop' });
+ const run = running.get(e.bot_id);
+ if (run?.execution.id === e.id) { running.delete(e.bot_id); if (run.sessionId) await deps.abortLane(run.sessionId); }
+ }
+ changed(room); return { ok: true as const };
+ }
const s = await recentSnapshot(room);
- const manager = s.members.some(m => m.id === selfId && ['owner', 'admin'].includes(m.role));
- const everything = scopeInput === 'all' && manager;
+ // Owners and admins may be the account's own teammate; that member acts for everyone's work.
+ const manager = managementActor(s);
+ const everything = scopeInput === 'all' && !!manager;
+ const asManager = manager === selfId ? undefined : manager;
const ownBot = (botId: string) => !!localBot(botId) || s.members.some(m => m.id === botId && m.ownerActorId === selfId);
const refused = (error: unknown) => error instanceof ChatResponseError && [403, 404, 409].includes(error.status);
const plans = await api<ServerPlan[]>(`/conversations/${room}/plans`);
@@ -2251,7 +2271,7 @@ function createChatServer(local: BotGroupChatService, deps: BotGroupChatServiceD
// Your own teammate stops its work for others as itself; a request you made, as you.
const asBot = !everything && e.requester_id !== selfId && ownBot(e.bot_id);
if (!everything && !asBot && e.requester_id !== selfId) continue;
- try { await api(`/conversations/${room}/executions/${e.id}/control`, 'POST', { operationId: randomUUID(), action: 'stop' }, asBot ? e.bot_id : undefined); }
+ try { await api(`/conversations/${room}/executions/${e.id}/control`, 'POST', { operationId: randomUUID(), action: 'stop' }, asBot ? e.bot_id : everything && e.requester_id !== selfId ? asManager : undefined); }
catch (error) { if (refused(error)) continue; throw error; }
const run = running.get(e.bot_id);
if (run?.execution.id === e.id) { running.delete(e.bot_id); if (run.sessionId) await deps.abortLane(run.sessionId); }
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupLiveStatus.tsx b/apps/desktop/src/renderer/features/bots/BotGroupLiveStatus.tsx
index 70f85e19b6..03bfe25ad3 100644
--- a/apps/desktop/src/renderer/features/bots/BotGroupLiveStatus.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotGroupLiveStatus.tsx
@@ -130,6 +130,8 @@ export function BotGroupProgressStrip({
if (!step && (!lead || now - since < BOT_GROUP_PROGRESS_STRIP_DELAY_MS)) return null;
const member = step ? step.member : lead?.member;
const name = step ? step.displayName : lead?.displayName ?? '';
+ // A queue turn is someone speaking, not a numbered step of work.
+ const workStep = step && step.plan.kind !== 'talk' ? step : null;
// The Session's compact detail may still be the previous turn's silence marker (NO_REPLY);
// that is not an action anyone should read.
const rawAction = live?.compactDetail?.trim() || '';
@@ -147,13 +149,13 @@ export function BotGroupProgressStrip({
<div className={cn('flex min-h-9 min-w-0 items-center gap-2 py-1', expanded && canView ? 'px-3' : 'pl-2 pr-1')}>
{member ? <BotAvatar bot={member} size="xs" /> : null}
<p role="status" aria-live="polite" className="flex min-w-0 flex-1 items-center gap-1 truncate text-12 leading-5 text-[var(--text-secondary)]">
- {step ? (
+ {workStep ? (
<span className="shrink-0 font-medium text-[var(--text-primary)]">
- {t('bots.groupChat.progress.step', { step: step.index, total: step.total })}
+ {t('bots.groupChat.progress.step', { step: workStep.index, total: workStep.total })}
</span>
) : null}
<span className="min-w-0 truncate">
- {step ? ` · ${name} ${step.step.task}` : t('bots.groupChat.progress.speaking', { name })}
+ {workStep ? ` · ${name} ${workStep.step.task}` : t('bots.groupChat.progress.speaking', { name })}
</span>
<span className="shrink-0 tabular-nums">
{' · '}
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
index 4a1c1674fe..53dd74e5a9 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
@@ -2976,6 +2976,22 @@ describe('Telegram / Slack-grade timeline', () => {
}
});
+ // bot-group-chat.md §7.0: a queue turn is someone speaking, not a numbered step with an empty task.
+ it('labels a running queue turn as speaking in the progress strip', async () => {
+ const turn = plan({
+ status: 'running', currentStep: 0, kind: 'talk', updatedAt: Date.now() - 125_000,
+ steps: [{ ...plan().steps[0]!, task: '', status: 'running' }, { ...plan().steps[1]!, task: '' }],
+ });
+ mocks.getBotGroup.mockResolvedValue({ ok: true, group: withPlan(turn, [], {
+ speakingBotIds: ['mimi'],
+ round: { status: 'running', speakers: [{ botId: 'mimi', sessionId: 'plan-mimi', activity: 'step' }], canContinue: false },
+ }) });
+ renderView();
+ const strip = await screen.findByTestId('bot-group-progress');
+ expect(strip.textContent).toContain('bots.groupChat.progress.speaking');
+ expect(strip.textContent).not.toContain('bots.groupChat.progress.step');
+ });
+
it('pins a progress strip above the composer while a plan step runs', async () => {
const running = plan({
status: 'running',
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 4f25fde12e..c36e4d7288 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -2464,7 +2464,7 @@ Chat Server `/me` 追加 `capabilities.groupSingleSpeaker: 1`,服务端派发
新 Desktop 只在看到该能力时:不再发 `deferExecution`、不做发送前的辅助判断、不发 `continueDiscussion`;
队列停着等继续时新消息按新请求发送(不作为补充)。队列前 5 位由服务端自动接续,无需客户端参与。
`chat_plan.kind` 是附加字段,旧客户端忽略;新客户端缺字段时按旧分工卡呈现。
-停止的范围收窄只在执行端实现(成员只停自己的请求与伙伴,管理员可 `all`),沿用既有 control /
+停止的范围收窄与主群上下文精简都只在看到该能力时启用,旧服务器保留整轮停止与完整主群历史;收窄只在执行端实现(成员只停自己的请求与伙伴,群主或管理员——含本账号拥有的管理员伙伴——可 `all`),沿用既有 control /
plan action 的服务端权限,IPC `bot-group:stop` 追加可选 `scope`;
手机经电脑的远程动作不变(停止为本人范围)。发布顺序:服务端整集群先上,再发客户端。