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): 保留工作中的进度文字并在完成后折叠过程

Dashe981b6175c82
diff --git a/apps/desktop/src/renderer/components/chat/MessageStream.tsx b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
index 65bb7159e0..70f086b67f 100644
--- a/apps/desktop/src/renderer/components/chat/MessageStream.tsx
+++ b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
@@ -6615,7 +6615,7 @@ export function MessageStream({
item={item}
context={workGroupRenderContext}
// 伙伴聊天与普通任务同一套工作过程:运行中露最近 5 条活动与计时,
- // 组头按内容宽;做完整块不再出现(simplifyBotRenderItems 丢弃完成组)。
+ // 组头按内容宽;最终答复后保留折叠过程,按需展开。
compact={false}
replyColumnSpacer={botReplyColumnSpacer}
/>
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botConversationPresentation.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/botConversationPresentation.test.ts
index e6e7b971c9..09765a1583 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/botConversationPresentation.test.ts
+++ b/apps/desktop/src/renderer/features/bots/__tests__/botConversationPresentation.test.ts
@@ -21,6 +21,21 @@ const shape = (items: readonly RenderItem[]): string => items.map((item) => item
const project = (items: RenderItem[], streaming: boolean) =>
simplifyBotRenderItems(groupWorkRuns(items, streaming), streaming);
+// Unit regression: same production grouping and projection as MessageStream.
+// Existing tests expected progress to disappear; exercise the metadata handoff.
+it('keeps working prose through streaming metadata and tools, folding only after the answer', () => {
+ const user = message('u', 'user');
+ const progress = message('progress', 'assistant', 'Checking the refresh', { isStreaming: true });
+ const marked = message('progress', 'assistant', 'Checking the refresh', { assistantPhase: 'commentary' });
+ for (const source of [[user, progress], [user, marked], [user, marked, tool('read')]]) {
+ expect(proseIds(project(source, true))).toContain('progress');
+ }
+ const completed = project([user, marked, tool('read'), message('final', 'assistant', 'Done', { turnCompleted: true })], false);
+ expect(proseIds(completed)).toEqual(['final']);
+ expect(allKeys(completed)).toContain('msg-progress');
+ expect(completed.some(item => item.type === 'work_group' && !item.isStreaming)).toBe(true);
+});
+
describe('teammate final-result presentation', () => {
// #6351: provider final_answer only closes a message, not a successful sample.
// Failed output remains in the expandable work history rather than being lifted
@@ -41,20 +56,15 @@ describe('teammate final-result presentation', () => {
: ending === 'retrying' ? [] : [message('error', 'error', 'Reply interrupted')]),
], ending === 'retrying');
expect(proseIds(result)).toEqual(ending === 'completed' ? ['intro', 'success'] : []);
- // Failed output stays in the live work history; once the turn ends the process leaves with it.
- if (ending === 'retrying') {
- expect(allKeys(result)).toContain('msg-failed');
- expect(allKeys(result)).toContain('msg-failed-commentary');
- } else {
- expect(allKeys(result)).not.toContain('msg-failed');
- expect(allKeys(result)).not.toContain('msg-failed-commentary');
- }
+ // Failed output remains reachable only inside the work history.
+ expect(allKeys(result)).toContain('msg-failed');
+ expect(allKeys(result)).toContain('msg-failed-commentary');
});
it('keeps coordination input hidden while process, explicit inputs, results and errors remain visible', () => {
const rows = [message('coordination', 'user', '[UI_ACTION_TRIGGER]File agreement', { isSyntheticTrigger: true }),
tool('audit'), message('visible-input', 'user', 'Requested status'),
message('result', 'assistant', 'Final result', { turnCompleted: true }), message('error', 'error', 'Action required')];
- expect(shape(project(rows, false))).toBe('msg-visible-input, msg-result, msg-error');
+ expect(shape(project(rows, false))).toBe('work-audit[tools-audit], msg-visible-input, msg-result, msg-error');
});
it('folds process rows into the normal work summary and keeps final answers without mutating history', () => {
@@ -63,30 +73,30 @@ describe('teammate final-result presentation', () => {
const result = project(input, false);
expect(proseIds(result)).toEqual(['final']);
// Same shape as a normal session: one outer summary with intermediate prose and inner groups.
- expect(shape(result)).toBe('msg-u, msg-final');
+ expect(shape(result)).toBe('msg-u, work-summary-t1[msg-a, work-t1[tools-t1], msg-b, work-t2[tools-t2]], msg-final');
expect(input[1]).toEqual(message('a', 'assistant'));
});
- it('keeps every unsealed segment out of the top level from its first delta while activity stays live', () => {
+ it('keeps every unsealed segment visible from its first delta until the final answer', () => {
const start = [message('u', 'user'), message('a', 'assistant', 'A', { isStreaming: true })];
- expect(proseIds(project(start, true))).toEqual([]);
+ expect(proseIds(project(start, true))).toEqual(['a']);
const work = [...start, tool('t1')];
- expect(proseIds(project(work, true))).toEqual([]);
- expect(shape(project(work, true))).toBe('msg-u, work-t1*[tools-t1]');
+ expect(proseIds(project(work, true))).toEqual(['a']);
+ expect(shape(project(work, true))).toBe('msg-u, msg-a, work-t1*[tools-t1]');
const continued = project([...work, message('b', 'assistant', 'B', { isStreaming: true })], true);
- expect(proseIds(continued)).toEqual([]);
- expect(shape(continued)).toBe('msg-u, work-t1[tools-t1]');
+ expect(proseIds(continued)).toEqual(['a', 'b']);
+ expect(shape(continued)).toBe('msg-u, msg-a, work-t1[tools-t1], msg-b');
const done = project([...work, message('b', 'assistant', 'B', { turnCompleted: true })], false);
expect(proseIds(done)).toEqual(['b']);
- expect(shape(done)).toBe('msg-u, msg-b');
+ expect(shape(done)).toBe('msg-u, work-summary-t1[msg-a, work-t1[tools-t1]], msg-b');
});
- it.each(['stopped', 'failed', 'history'])('retains the last useful text with no final: %s', () => {
+ it.each(['stopped', 'failed', 'history'])('retains useful progress with no final: %s', () => {
const input = [message('u', 'user'), message('a', 'assistant'), tool('t1'),
message('last', 'assistant'), tool('t2'), message('err', 'error')];
const result = project(input, false);
- expect(proseIds(result)).toEqual(['last']);
- expect(shape(result)).toBe('msg-u, msg-last, msg-err');
+ expect(proseIds(result)).toEqual(['a', 'last']);
+ expect(shape(result)).toBe('msg-u, msg-a, work-t1[tools-t1], msg-last, work-t2[tools-t2], msg-err');
});
it('keeps all blocks of sealed replies across continuation tools and history reloads', () => {
@@ -97,12 +107,8 @@ describe('teammate final-result presentation', () => {
for (const streaming of [true, false]) {
const result = project(input, streaming);
expect(proseIds(result)).toEqual(['first', 'second', 'third', 'fourth']);
- // An earlier background-wake reply is lifted out of the fold; while running the summary
- // keeps its key and the following activity group stays the same inner group. Once the
- // turn ends the work leaves and the replies remain.
- expect(shape(result)).toBe(streaming
- ? 'msg-u, work-summary-t1[msg-progress, work-t1[tools-t1]], msg-first, msg-second, work-t2[tools-t2], msg-third, msg-fourth'
- : 'msg-u, msg-first, msg-second, msg-third, msg-fourth');
+ // Earlier addressed replies stay outside the preserved work history.
+ expect(shape(result)).toBe('msg-u, work-summary-t1[msg-progress, work-t1[tools-t1]], msg-first, msg-second, work-t2[tools-t2], msg-third, msg-fourth');
}
});
@@ -110,7 +116,7 @@ describe('teammate final-result presentation', () => {
const result = simplifyBotRenderItems([message('progress', 'assistant'),
message('private', 'thinking'), message('first', 'assistant'),
message('second', 'assistant', 'Second', { turnCompleted: true })], true);
- expect(proseIds(result)).toEqual(['first', 'second']);
+ expect(proseIds(result)).toEqual(['progress', 'first', 'second']);
expect(allKeys(result)).not.toContain('msg-private');
});
@@ -122,13 +128,13 @@ describe('teammate final-result presentation', () => {
{ type: 'tool_media', key: 'media', items: [{ kind: 'image', url: '/picture.png' }] },
{ type: 'ghost_card', key: 'card', callId: 'call', ghostId: 'plugin', tool: 'render',
toolCall: { clientId: 'call', role: 'tool_use', content: '' }, settled: true },
- ])('does not restore preambles after delivery: $key', (delivery) => {
+ ])('preserves progress history when an attachment or card arrives: $key', (delivery) => {
const input = [message('u', 'user'), message('progress', 'assistant', '正在生成'), tool('t'), delivery];
for (const streaming of [true, false]) {
const result = project(input, streaming);
- expect(proseIds(result)).not.toContain('progress');
+ expect(proseIds(result)).toContain('progress');
expect(result.some((item) => item.key === delivery.key)).toBe(true);
- expect(allKeys(result)).not.toContain('msg-progress');
+ expect(allKeys(result)).toContain('msg-progress');
}
});
@@ -138,8 +144,8 @@ describe('teammate final-result presentation', () => {
systemCardData: { botCollaboration: { role: 'delegation-result' } },
});
const input = [message('u', 'user'), message('progress', 'assistant'), tool('t'), receipt];
- expect(shape(project(input, true))).toBe('msg-u, work-t*[tools-t], msg-receipt');
- expect(shape(project(input, false))).toBe('msg-u, msg-receipt');
+ expect(shape(project(input, true))).toBe('msg-u, msg-progress, work-t*[tools-t], msg-receipt');
+ expect(shape(project(input, false))).toBe('msg-u, msg-progress, work-t[tools-t], msg-receipt');
});
it('retains a later explanation after partial delivery and ignores unverified file candidates', () => {
@@ -161,8 +167,7 @@ describe('teammate final-result presentation', () => {
message('u2', 'user'), message('explanation', 'assistant'), tool('failed')];
const result = simplifyBotRenderItems(groupWorkRuns(input, false), false, new Set(['files']));
expect(proseIds(result)).toEqual(['final', 'explanation']);
- // Both turns are over: their work leaves, the answers, files and explanation stay.
- expect(shape(result)).toBe('msg-u, msg-final, files, msg-u2, msg-explanation');
+ expect(shape(result)).toBe('msg-u, work-summary-t[msg-progress, work-t[tools-t]], msg-final, files, msg-u2, msg-explanation, work-failed[tools-failed]');
});
it('does not extend a final seal or delivery fallback across a history gap without tools', () => {
@@ -182,8 +187,8 @@ describe('teammate final-result presentation', () => {
const input = [message('u', 'user'), message('long', 'assistant', text), tool('t'),
message('answer', 'assistant', '先安装')];
const result = project(input, false);
- expect(proseIds(result)).toEqual(['answer']);
- expect(allKeys(result)).not.toContain('msg-long');
+ expect(proseIds(result)).toEqual(['long', 'answer']);
+ expect(allKeys(result)).toContain('msg-long');
});
it('keeps completed answers across continuation tools, synthetic triggers and real user turns', () => {
@@ -191,7 +196,7 @@ describe('teammate final-result presentation', () => {
tool('t'), message('trigger', 'user', '', { isSyntheticTrigger: true }),
message('continuing', 'assistant'), tool('t2'), message('u2', 'user'), message('new', 'assistant')];
const result = project(input, true);
- expect(proseIds(result)).toEqual(['sealed', 'continuing']);
+ expect(proseIds(result)).toEqual(['sealed', 'continuing', 'new']);
expect(allKeys(result)).not.toContain('msg-trigger');
});
@@ -214,22 +219,22 @@ describe('teammate final-result presentation', () => {
const input: RenderItem[] = [message('u', 'user'), message('empty', 'assistant', ' '),
{ type: 'work_group', key: 'work-nested', isStreaming: false, children: [thinking, tool('t')] },
message('answer', 'assistant')];
- expect(shape(project(input, false))).toBe('msg-u, msg-answer');
+ expect(shape(project(input, false))).toBe('msg-u, work-nested[msg-private, tools-t], msg-answer');
expect(thinking).toEqual(message('private', 'thinking', 'Not public execution'));
});
- it('drops a finished turn\'s technical history, loaded or not, without calling its expansion or retry API', () => {
+ it('preserves a finished turn\'s lazy history without eagerly calling expansion or retry', () => {
const deferred = { owner: {}, key: 'range', expanded: false, loading: false, failed: false,
toggle: vi.fn(), retry: vi.fn(), setVisible: vi.fn() };
const group: RenderItem = { type: 'work_group', key: 'work-history', isStreaming: false,
children: [], deferred };
const input = [message('u', 'user'), group, message('final', 'assistant')];
const unloaded = simplifyBotRenderItems(input, false);
- expect(shape(unloaded)).toBe('msg-u, msg-final');
- expect(unloaded).not.toContain(group);
+ expect(shape(unloaded)).toBe('msg-u, work-history[], msg-final');
+ expect(unloaded).toContain(group);
const loaded = { ...group, children: [message('thinking', 'thinking'), message('public', 'assistant'), tool('t')] };
const result = simplifyBotRenderItems([input[0], loaded as RenderItem, input[2]], false);
- expect(shape(result)).toBe('msg-u, msg-final');
+ expect(shape(result)).toBe('msg-u, work-history[msg-thinking, msg-public, tools-t], msg-final');
expect(deferred.toggle).not.toHaveBeenCalled();
expect(deferred.retry).not.toHaveBeenCalled();
expect(group.deferred).toBe(deferred);
@@ -254,7 +259,7 @@ describe('teammate final-result presentation', () => {
expect(complete).toEqual([nested, reply]);
});
- it('shows a running turn as a live work group and a finished turn as the answer alone', () => {
+ it('shows a running turn as a live work group and preserves its fold beside the finished answer', () => {
const at = (offset: number) => new Date(Date.parse('2026-10-15T08:00:00Z') + offset).toISOString();
const running = [message('u', 'user', 'Fix it', { createdAt: at(0) }),
message('think', 'thinking', 'Looking at refresh', { createdAt: at(1000) }),
@@ -266,8 +271,7 @@ describe('teammate final-result presentation', () => {
const finished = project([...running,
message('answer', 'assistant', 'Done', { createdAt: at(9000), turnCompleted: true })], false);
- // A finished turn shows only the answer; the work process leaves with the turn.
- expect(shape(finished)).toBe('msg-u, msg-answer');
+ expect(shape(finished)).toBe('msg-u, work-think[msg-think, tools-read], msg-answer');
expect(proseIds(finished)).toEqual(['answer']);
});
@@ -312,7 +316,7 @@ it('nests only explicitly bound results, preserving original anchor and human me
const anchor = message('anchor', 'assistant', '', { systemCardType: 'bot-session-task' });
const final = message('final', 'assistant', 'Summary', { turnCompleted: true, botTaskResults: [card] });
const input = [anchor, receipt, message('human', 'user'), message('progress', 'assistant'), tool('t'), final];
- expect(shape(project(input, false))).toBe('msg-anchor, msg-human, msg-final');
+ expect(shape(project(input, false))).toBe('msg-anchor, msg-human, work-summary-t[msg-progress, work-t[tools-t]], msg-final');
expect(final.message.botTaskResults).toEqual([card]);
expect(allKeys(project(input.slice(0, -1), false))).toContain('msg-receipt');
expect(allKeys(project([receipt, message('unrelated', 'assistant', 'Other', { turnCompleted: true })], false))).toContain('msg-receipt');
@@ -322,20 +326,20 @@ it('nests only explicitly bound results, preserving original anchor and human me
it('keeps explicitly delivered group private messages while the private model is working and after another reply', () => {
const input = [message('u', 'user'), message('group', 'assistant', 'Group reply', { sourceGroup: { groupId: 'g-1' } }),
message('progress', 'assistant', 'Working'), tool('running')];
- expect(proseIds(project(input, true))).toEqual(['group']);
+ expect(proseIds(project(input, true))).toEqual(['group', 'progress']);
expect(proseIds(project([...input, message('final', 'assistant', 'Result', { turnCompleted: true })], false))).toEqual(['group', 'final']);
});
describe('provider final streaming', () => {
- it('keeps incremental final text visible before and after the seal, excluding commentary', () => {
+ it('keeps incremental final text and its contiguous prose visible like ordinary tasks', () => {
const prefix = [message('u', 'user'), message('process', 'assistant', 'Internal', { assistantPhase: 'commentary' })];
for (const text of ['A', 'Answer', 'Answer with a reference']) {
const final = message('answer', 'assistant', text, { assistantPhase: 'final_answer', isStreaming: true });
- expect(proseIds(project([...prefix, final], true))).toEqual(['answer']);
- expect(proseIds(project([...prefix, { ...final, message: { ...final.message, isStreaming: false } }], true))).toEqual(['answer']);
+ expect(proseIds(project([...prefix, final], true))).toEqual(['process', 'answer']);
+ expect(proseIds(project([...prefix, { ...final, message: { ...final.message, isStreaming: false } }], true))).toEqual(['process', 'answer']);
}
- expect(proseIds(project([...prefix, message('answer', 'assistant', 'Answer', { assistantPhase: 'final_answer', turnCompleted: true })], false))).toEqual(['answer']);
+ expect(proseIds(project([...prefix, message('answer', 'assistant', 'Answer', { assistantPhase: 'final_answer', turnCompleted: true })], false))).toEqual(['process', 'answer']);
});
});
diff --git a/apps/desktop/src/renderer/features/bots/botConversationPresentation.ts b/apps/desktop/src/renderer/features/bots/botConversationPresentation.ts
index a12516a862..e67e734833 100644
--- a/apps/desktop/src/renderer/features/bots/botConversationPresentation.ts
+++ b/apps/desktop/src/renderer/features/bots/botConversationPresentation.ts
@@ -1,6 +1,5 @@
import { hasRichAnswer } from '@cindy/maker-shared/rich-answer';
import { botTaskResultKey, readBotCollaborationMeta } from '@cindy/maker-shared/botCollaboration';
-import { extractRenderedMarkdownImageTargets } from '@/components/chat/markdownImageTargets';
import { HISTORY_GAP_SPLIT_MS } from '@/lib/historyGap';
import type { ChatMessage } from '@/lib/makerChatStore';
import {
@@ -30,21 +29,17 @@ function expandWorkGroups(items: readonly RenderItem[]): RenderItem[] {
/** A presentation-only projection. Never mutate messages or infer intent from prose.
* isFinal from the adapters closes a text block, not a turn (Pi/Claude can call
- * another tool afterwards). Reuse the normal work-group turn seal, showing provider-marked final prose immediately while keeping
- * unclassified top-level intermediate prose hidden. While a turn runs its work groups
- * show like a normal session; once the turn ends they are dropped, so a finished turn
- * shows only what the bot said, results and errors. Agent tasks and workflow cards pass through.
- * On stop/error or old history without a seal, expose the last useful
- * prose so an answer or plain-text question cannot disappear permanently.
+ * another tool afterwards). Normal task grouping owns progress visibility and
+ * completion folds. Keep its prose and work history; only lift addressed replies
+ * and remove companion-specific synthetic rows or duplicate result receipts.
*/
export function simplifyBotRenderItems(
items: readonly RenderItem[],
isStreaming: boolean,
- visibleGeneratedFileKeys?: ReadonlySet<string>,
+ _visibleGeneratedFileKeys?: ReadonlySet<string>,
): RenderItem[] {
- // Preserve the shared grouping's history-window boundary before filtering
- // prose (work groups carry timestamp anchors). Only the final window is
- // active; earlier legacy answers retain their own fallback.
+ // Preserve history-window boundaries while lifting addressed replies;
+ // a later seal must not promote prose across an unloaded history gap.
const result: RenderItem[] = [];
let window: RenderItem[] = [];
let previousEnd: number | null = null;
@@ -54,14 +49,14 @@ export function simplifyBotRenderItems(
const userBoundary = item.type === 'message' && item.message.role === 'user';
if (!userBoundary && previousEnd !== null && start !== null
&& start - previousEnd > HISTORY_GAP_SPLIT_MS) {
- result.push(...projectWindow(window, false, visibleGeneratedFileKeys));
+ result.push(...projectWindow(window));
window = [];
}
window.push(item);
if (userBoundary) previousEnd = end ?? previousEnd;
else if (end !== null) previousEnd = previousEnd === null ? end : Math.max(previousEnd, end);
}
- result.push(...projectWindow(window, isStreaming, visibleGeneratedFileKeys));
+ result.push(...projectWindow(window));
const attached = new Set(result.flatMap(item => item.type === 'message'
&& item.message.role === 'assistant' && item.message.turnCompleted === true && item.message.content.trim()
? (item.message.botTaskResults ?? []).map(botTaskResultKey) : []));
@@ -151,8 +146,6 @@ function liftRepliesFromWorkGroup(
function projectWindow(
items: readonly RenderItem[],
- isStreaming: boolean,
- visibleGeneratedFileKeys?: ReadonlySet<string>,
): RenderItem[] {
// A sealed answer may span several contiguous prose blocks; only the last carries
// the seal. groupWorkRuns folds earlier background-wake seals into work groups, so
@@ -175,62 +168,20 @@ function projectWindow(
&& (hasRichAnswer(message.content) || message.assistantPhase === 'final_answer' || Boolean(message.sourceGroup)
|| Boolean(message.explicitDelivery) || isCompletedAssistantMessage(message) || sealedAnswers.has(message));
const result: RenderItem[] = [];
- let turn: RenderItem[] = [];
- const flushTurn = (active: boolean) => {
- let lastProse = -1;
- let lastDelivery = -1;
- for (let index = 0; index < turn.length; index += 1) {
- const item = turn[index];
- if (isProse(item) && item.message.content.trim()) lastProse = index;
- if ((isProse(item) && (hasAttachments(item.message) || hasRichAnswer(item.message.content)
- || extractRenderedMarkdownImageTargets(item.message.content).length > 0))
- || (item.type === 'message' && item.message.systemCardType === 'bot-session-task-result')
- || (item.type === 'generated_files' && visibleGeneratedFileKeys?.has(item.key))
- || (item.type === 'tool_media' && item.items.length > 0)
- || (item.type === 'ghost_card' && (item.settled || Boolean(item.media?.length)))) {
- lastDelivery = index;
- }
- }
- // Only the card's checked visible files count, never unverified candidates.
- // A later attachment/card is already the result; do not resurrect its preamble.
- // Keep later explanatory text after a partial delivery on stop/error/history.
- const fallbackProse = !active && lastProse > lastDelivery ? lastProse : -1;
- turn.forEach((item, index) => {
- // Bots never produce change cards; keep them out like before. Thinking is
- // always folded into a work group by the shared grouping, never top level.
- if (item.type === 'turn_changes') return;
- // The work process shows only while its turn runs; a finished turn keeps only what
- // the bot said, results and errors (cindy-bots-runtime.md).
- if (!active && item.type === 'work_group') return;
- if (item.type === 'message' && item.message.role === 'thinking') return;
- if (item.type === 'message' && item.message.isSyntheticTrigger) return;
- if (isProse(item)) {
- if (!item.message.content.trim() && !hasAttachments(item.message) && !hasRichAnswer(item.message.content)) return;
- if (item.message.assistantPhase === 'commentary' && !item.message.explicitDelivery && !hasAttachments(item.message) && !hasRichAnswer(item.message.content)) return;
- if (item.message.assistantPhase !== 'final_answer' && !item.message.sourceGroup && !item.message.explicitDelivery && !isCompletedAssistantMessage(item.message) && !sealedAnswers.has(item.message)
- && !hasAttachments(item.message) && !hasRichAnswer(item.message.content) && index !== fallbackProse
- && extractRenderedMarkdownImageTargets(item.message.content).length === 0) {
- return;
- }
- }
- // Includes work groups, agent tasks, plans, authorization, answered
- // questions, errors and all delivery cards.
- result.push(item);
- });
- turn = [];
- };
-
const lifted = items.flatMap((item) => item.type !== 'work_group' ? [item]
: hasWorkContent(item) ? liftRepliesFromWorkGroup(item, isAddressedReply) : []);
- for (const item of lifted) {
- if (item.type === 'message' && item.message.role === 'user'
- && item.message.delivery !== 'steer') {
- flushTurn(false);
- if (!item.message.isSyntheticTrigger) result.push(item);
- } else {
- turn.push(item);
+ lifted.forEach((item) => {
+ // Bots never produce change cards; keep them out like before. Thinking is
+ // always folded into a work group by the shared grouping, never top level.
+ if (item.type === 'turn_changes') return;
+ if (item.type === 'message' && item.message.role === 'thinking') return;
+ if (item.type === 'message' && item.message.isSyntheticTrigger) return;
+ if (isProse(item)) {
+ if (!item.message.content.trim() && !hasAttachments(item.message) && !hasRichAnswer(item.message.content)) return;
+ if (item.message.failedSamplingAttempt) return;
}
- }
- flushTurn(isStreaming);
+ // Normal task grouping owns progress visibility and completed work folds.
+ result.push(item);
+ });
return result;
}
diff --git a/apps/mobile/src/__tests__/companionConversationPresentation.test.ts b/apps/mobile/src/__tests__/companionConversationPresentation.test.ts
index 622af3c4c2..16eaa564e8 100644
--- a/apps/mobile/src/__tests__/companionConversationPresentation.test.ts
+++ b/apps/mobile/src/__tests__/companionConversationPresentation.test.ts
@@ -11,6 +11,19 @@ const bodies = (messages: RemoteMessage[], running: boolean) => companionConvers
const base = [row('u0', 'user', 'Help'), row('a1', 'assistant', 'Public progress'),
row('t2', 'tool_use', { toolName: 'Read', toolUseId: 't', input: { path: 'private' } }),
row('r3', 'tool_result', { toolUseId: 't', result: 'technical details' })];
+// Unit regression: the real normalize → group → companion projection used to
+// hide prose as soon as commentary metadata or a later tool arrived.
+it('keeps working prose through streaming metadata and tools, folding only after the answer', () => {
+ const progress = row('a1', 'assistant', 'Checking the refresh');
+ const marked = { ...progress, agentMeta: { assistantPhase: 'commentary' } };
+ for (const source of [[base[0], progress], [base[0], marked], [base[0], marked, ...base.slice(2)]]) {
+ expect(bodies(source, true).filter(item => item.type === 'message').map(item => item.message.body))
+ .toContain('Checking the refresh');
+ }
+ const completed = bodies([base[0], marked, ...base.slice(2), row('a4', 'assistant', 'Done', { turnCompleted: true })], false);
+ expect(completed.filter(item => item.type === 'message').map(item => item.message.body)).toEqual(['Help', 'Done']);
+ expect(JSON.stringify(completed.find(item => item.type === 'work_group'))).toContain('Checking the refresh');
+});
// #6351: this consumer expands work groups and infers contiguous sealed runs,
// so grouping alone cannot prevent a failed sample becoming another reply.
it.each(['retrying', 'completed', 'exhausted'] as const)(
@@ -40,7 +53,7 @@ it.each(['retrying', 'completed', 'exhausted'] as const)(
// a user row, progress and one tool suffice to lose the only process entry.
it('keeps live work and completed process details reachable like Desktop', () => {
const active = bodies(base, true);
- expect(active.map(item => item.type)).toEqual(['message', 'work_group']);
+ expect(active.map(item => item.type)).toEqual(['message', 'message', 'work_group']);
expect(JSON.stringify(active)).toContain('technical details');
const complete = bodies([...base, row('a4', 'assistant', 'Answer', { turnCompleted: true })], false);
expect(complete.filter(item => item.type === 'message').map(item => item.message.body)).toEqual(['Help', 'Answer']);
@@ -105,7 +118,7 @@ it.each([false, true])('does not seal old commentary across an unloaded history
];
const texts = (source: RemoteMessage[]) => bodies(source, running)
.filter(item => item.type === 'message').map(item => item.message.body);
- expect(texts(messages)).toEqual(['Current answer, first part', 'Current answer, last part']);
+ expect(texts(messages)).toEqual(['Old commentary', 'Current answer, first part', 'Current answer, last part']);
// Once the actual user boundary is loaded, retain the older no-final reply
// through the existing per-turn fallback, independently of the newer seal.
expect(texts([messages[0], at(row('u2', 'user', 'New question'), currentStart - 1), ...messages.slice(1)]))
@@ -117,10 +130,10 @@ const receipt = row('r6', 'assistant', '', { botCollaboration: {
toBotId: null, toBotName: '', parentSessionId: 'chat', childSessionId: 'child', objective: 'Brief',
result: { runSequence: 1, status: 'completed', text: 'The completed brief', artifacts: [] },
} });
-it.each([false, true])('keeps the result receipt without resurrecting its preamble (streaming=%s)', (running) => {
+it.each([false, true])('keeps progress until a final reply even when a result receipt arrives (streaming=%s)', (running) => {
const items = bodies([...base, receipt], running);
expect(JSON.stringify(items)).toContain('The completed brief');
- expect(JSON.stringify(items)).not.toContain('Public progress');
+ expect(JSON.stringify(items)).toContain('Public progress');
});
it.each([false, true])('does not suppress an older reply across a history gap before a receipt (streaming=%s)', (running) => {
const oldReply = row('a1', 'assistant', 'Earlier useful reply');
@@ -193,8 +206,8 @@ it.each([true, false])('keeps guest-safe explicit delivery without sealing adjac
expect(JSON.stringify(messages)).not.toMatch(/private-group|Secret group/);
const text = bodies(messages, running).filter(item => item.type === 'message').map(item => item.message.body);
expect(text).toContain('Private delivery');
- expect(text).not.toContain('Before');
- expect(text).not.toContain('After');
+ expect(text.includes('Before')).toBe(running);
+ expect(text.includes('After')).toBe(running);
});
it('keeps a component progress answer visible before finalization and later tool calls', () => {
const content = '```cindy-ui\n' + JSON.stringify({ seq: 1, op: 'create', id: 'heading', kind: 'heading', props: { text: 'Result' } }) + '\n';
diff --git a/apps/mobile/src/__tests__/mobileHistoryRender.test.ts b/apps/mobile/src/__tests__/mobileHistoryRender.test.ts
index 7917829a58..084469f636 100644
--- a/apps/mobile/src/__tests__/mobileHistoryRender.test.ts
+++ b/apps/mobile/src/__tests__/mobileHistoryRender.test.ts
@@ -52,9 +52,9 @@ describe('remote history preserves original folding', () => {
// Regression: mobile's companion projection used to flatten away deferred
// work after history takeover. Verify the production controller's expansion
// still reads the original thinking/tool rows and never hides a provider final.
- it('preserves companion replies and lazy work through history takeover and expansion', async () => {
+ it.each(['final_answer', 'commentary'])('preserves companion %s and lazy work through history takeover and expansion', async (assistantPhase) => {
const rows = [row(0, 'user', 'Work'),
- { ...row(1, 'assistant', 'First reply'), agentMeta: { assistantPhase: 'final_answer' } },
+ { ...row(1, 'assistant', 'First reply'), agentMeta: { assistantPhase } },
thought(2), call(3), row(4, 'tool_result', 'Read result', 'tool-3')];
const { view, render, details } = harness(rows, true, true);
const raw = companionConversationItems(buildMobileMessageRenderItems(rows, { isSessionStreaming: true }));
diff --git a/apps/mobile/src/session/companionConversationPresentation.ts b/apps/mobile/src/session/companionConversationPresentation.ts
index 1cbc2e8005..2ac8049838 100644
--- a/apps/mobile/src/session/companionConversationPresentation.ts
+++ b/apps/mobile/src/session/companionConversationPresentation.ts
@@ -1,14 +1,8 @@
import { hasRichAnswer } from '@cindy/maker-shared/rich-answer';
import { botTaskResultKey, readBotTaskResults } from '@cindy/maker-shared/botCollaboration';
import { HISTORY_GAP_SPLIT_MS } from '@cindy/maker-shared/history-gap';
-import { collectMobileMarkdownImages } from './messageMarkdown';
import type { MobileMessageRenderItem, MobileWorkGroupItem, MobileWorkChildItem } from './messageRenderModel';
-const isDelivery = (item: MobileMessageRenderItem) => (item.type === 'message' && !item.message.failedSamplingAttempt && item.message.kind === 'assistant' && hasRichAnswer(item.message.body)) || item.type === 'tool_media' && item.tools.some(tool => !!tool.media?.length || !!tool.files?.length)
- || item.type === 'message' && !item.message.failedSamplingAttempt && (item.message.companion?.kind === 'task' && item.message.companion.meta.role === 'delegation-result'
- || !!item.message.attachments?.length || !!item.message.media?.length
- || !!item.message.files?.length || collectMobileMarkdownImages(item.message.body).length > 0);
-
const expandWorkGroups = (items: readonly MobileMessageRenderItem[]): MobileMessageRenderItem[] =>
items.flatMap(item => item.type === 'work_group' ? expandWorkGroups(item.children) : [item]);
@@ -75,23 +69,6 @@ export function companionConversationItems(items: readonly MobileMessageRenderIt
&& (item.message.source.agentMeta?.assistantPhase === 'final_answer' || item.message.turnCompleted
|| sealed.has(item.key) || Boolean(item.message.sourceGroup) || item.message.explicitDelivery || hasRichAnswer(item.message.body));
const flattened = items.flatMap(item => item.type === 'work_group' ? liftReplies(item, isAddressedReply) : [item]);
- // A later delivery is already the result. Do not restore its unsealed preamble.
- const deliveredAfter = new Set<string>();
- let delivery = false;
- let nextMessageAt: number | null = null;
- for (const item of [...flattened].reverse()) {
- if (item.type === 'message') {
- const createdAt = Date.parse(item.message.createdAt);
- if (Number.isFinite(createdAt)) {
- // A receipt in a newer loaded window cannot suppress an older reply.
- if (nextMessageAt !== null && nextMessageAt - createdAt > HISTORY_GAP_SPLIT_MS) delivery = false;
- nextMessageAt = createdAt;
- }
- }
- if (item.type === 'message' && item.message.kind === 'user') delivery = false;
- else if (isDelivery(item)) delivery = true;
- else if (delivery) deliveredAfter.add(item.key);
- }
const attached = new Set(flattened.flatMap(item => item.type === 'message'
&& item.message.kind === 'assistant' && !item.message.failedSamplingAttempt && item.message.turnCompleted === true && item.message.body.trim()
? readBotTaskResults(item.message.source.agentMeta?.botTaskResults).map(botTaskResultKey) : []));
@@ -111,9 +88,8 @@ export function companionConversationItems(items: readonly MobileMessageRenderIt
}
if (message.systemCardType) return true;
if (message.kind === 'thinking' || message.kind === 'tool') return false;
- if (message.kind === 'assistant' && message.source.agentMeta?.assistantPhase === 'commentary'
- && !message.explicitDelivery && !isDelivery(item)) return false;
- return message.kind !== 'assistant' || isAddressedReply(item) || isDelivery(item)
- || message.isTurnFinalAssistant && !deliveredAfter.has(item.key);
+ // Ordinary task grouping owns when prose enters the completed work fold.
+ // Metadata arriving after a text delta must not hide a still-visible row.
+ return true;
});
}
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index b61ada5b08..67096e9eca 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -274,11 +274,13 @@ tool 副作用时自动重放。原生后台工作尚未结束时不自动关闭
伙伴界面由入口验证过的持久归属与任务 ID 决定,不随异步运行快照的缺失、刷新或重连回退为普通任务界面。历史资料尚未加载或暂时失败时也保留伙伴呈现;手机保留同一账号、设备与任务内已确认的伙伴身份。切换任务、设备或账号时不得复用旧身份。此呈现规则不替代宿主的权限与归属校验。
-**伙伴聊天显示工作过程(2026-10-15,Chris:「你这么做不如改回当年 session 的思考了」→ 直接用 session 同一套)**:伙伴的回复列与普通任务共用同一个工作过程折叠块(`WorkGroupBlock`)——运行中露出最近几步(工具名/文件/命令/思考首句)与计时,组头按文字宽度,箭头紧跟计时,不再顶到最右;这一轮结束后整块工作过程不再出现,只留伙伴说的话、结果与错误(2026-10-20 Chris 裁决「做完了,去掉」,取代原先的「完成后折叠成已工作 Xs」)。运行中不在渲染前删掉 thinking、tool 与 work_group。伙伴明确说给用户听的回复(provider 标为 final、群投递、显式投递或已收尾的回复)永远不藏进折叠里:工作过程在这类回复前后分段。输入框上方不再有只会说大类词的「正在处理…」状态行;运行状态走普通任务同一条 `RunningStatusBar`。工作过程与回复正文同列(头像列留空),不重复画脸。实现见 `botConversationPresentation.ts` 与 `MessageStream.tsx`。
+**伙伴聊天显示工作过程(2026-10-25,Dash:工作中文字正常显示,最终结论出来后才折叠)**:伙伴的回复列与普通任务共用同一个工作过程折叠块(`WorkGroupBlock`)——运行中露出最近几步(工具名/文件/命令/思考首句)与计时,组头按文字宽度,箭头紧跟计时,不再顶到最右。工作中的正文持续可见,不因补上 `commentary` 标记、结束单条文本流或后续工具调用而消失;最终答复到来后,沿用普通任务的分组规则折叠前面的过程,保留展开查看入口。此规则取代 2026-10-20 的「完成后整块不再出现」。运行中不在渲染前删掉 thinking、tool 与 work_group。伙伴明确说给用户听的回复(provider 标为 final、群投递、显式投递或已收尾的回复)永远不藏进折叠里:工作过程在这类回复前后分段。输入框上方不再有只会说大类词的「正在处理…」状态行;运行状态走普通任务同一条 `RunningStatusBar`。工作过程与回复正文同列(头像列留空),不重复画脸。实现见 `botConversationPresentation.ts` 与 `MessageStream.tsx`。
**伙伴私聊的消息样式(2026-10-20,与群聊统一)**:伙伴的回复放进与群聊同一种气泡——卡片底色加 1px 默认边框、12px 圆角、不加阴影(DESIGN.md §6);宽度随内容,上限 720px,组件式回答在气泡内按上限宽度排版,进度轨与输入框改用 `--surface` 以免与气泡同色。用户自己的消息沿用 Cindy 用户气泡,上限同为 720px,图片与文件随正文进同一个气泡(编辑态照旧在上方)。正文与任务对话同一字号。操作栏与群聊同一种贴边紧凑栏(`BubbleHoverToolbar`):挂在气泡外侧(伙伴回复的右边、自己消息的左边),与气泡顶部齐平,悬停、键盘聚焦或触屏时出现;外露「回复」、编辑(最后一条自己的消息)与更多,复制、分享为图片、链接、删除与准确时间收进更多。为此两侧气泡上限在窄窗口下让出操作栏的宽度。手机端另行同步。
-手机端遵守同一展示规则(「完成后整块不再出现」与私聊气泡尚待手机端同步,目前手机仍折叠成「已工作 Xs」):`companionConversationPresentation.ts` 保留工作组及其历史详情加载入口,
+**信息优先级**:进度文字是用户了解当前行动、已有发现与下一步的主要入口,比工具名、命令和文件等执行细节更重要。界面精简应通过折叠工具细节与已完成的过程实现,不能隐藏运行中的进度文字,也不能只恢复工具轨而继续过滤正文。手机与电脑采用同一原则。
+
+手机端遵守同一展示规则(私聊气泡尚待手机端同步):`companionConversationPresentation.ts` 保留工作中的正文、工作组及其历史详情加载入口,
`MessageRenderer.tsx` 在运行中展示最近五条活动;旧电脑未下发活动行时读取已有预览范围。
provider 的 `final_answer` 从首段正文起可见,历史视图接管、后续工具调用和完成收口均不得把它过滤掉。
本链路验收同时覆盖普通任务与伙伴入口、实时消息转历史、折叠展开及重开;不能用桌面验收代替手机验收。