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: 远程展开运行中的工作组时保留已显示的活动行 (#5821)

Dashe99a72b79e23
diff --git a/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsx b/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsx
index df8d5b58d4..601f88fe12 100644
--- a/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/workGroupBlockLivePreview.test.tsx
@@ -672,6 +672,31 @@ describe('WorkGroupBlock — Host-projected running lines', () => {
expect(remote.setVisible).toHaveBeenLastCalledWith(true, false);
});
+ it('keeps the Host lines on screen after expanding until detail rows arrive', () => {
+ const lines = [{ kind: 'thinking' as const, key: 'c2', text: 'Checking the failing case' }];
+ const props = {
+ blockId: 'work:remote-hold', isStreaming: true,
+ childItems: [rendered('detail', 'Every detail row')],
+ };
+ const { container, rerender } = render(createElement(WorkGroupBlock, {
+ ...props, deferred: { ...deferred(lines), awaitingDetails: true },
+ }));
+ clickGroup('chat.workGroup.working');
+ expect(container.querySelector('[data-live-work-preview]')).not.toBeNull();
+ expect(screen.getByText('Checking the failing case')).toBeTruthy();
+ expect(screen.queryByTestId('assistant-progress')).toBeNull();
+ // The detail body is already open, so the handoff below swaps rows without replaying its expansion.
+ const body = container.querySelector('.grid');
+ expect(body).not.toBeNull();
+
+ rerender(createElement(WorkGroupBlock, {
+ ...props, deferred: { ...deferred(lines), awaitingDetails: false },
+ }));
+ expect(container.querySelector('[data-live-work-preview]')).toBeNull();
+ expect(container.querySelector('.grid')).toBe(body);
+ expect(screen.getByTestId('assistant-progress').textContent).toBe('Every detail row');
+ });
+
it('keeps the detail preview for a Host that sends no lines', () => {
const remote = deferred();
render(createElement(WorkGroupBlock, {
diff --git a/apps/desktop/src/renderer/components/chat/WorkGroupBlock.tsx b/apps/desktop/src/renderer/components/chat/WorkGroupBlock.tsx
index db4e0cf016..248f3dbf64 100644
--- a/apps/desktop/src/renderer/components/chat/WorkGroupBlock.tsx
+++ b/apps/desktop/src/renderer/components/chat/WorkGroupBlock.tsx
@@ -408,8 +408,11 @@ export function WorkGroupBlock({
hasBeyondPreviewChild ||
recentActivities.length > MAX_LIVE_WORK_ACTIVITIES;
const effectiveExpanded = expanded && canToggle;
+ // Expanding keeps the running lines on screen until the detail read has rows to replace them.
+ // The body opens right away (spinner only), so the handoff swaps rows inside an open Collapse.
+ const holdLines = effectiveExpanded && deferred?.awaitingDetails === true && !!workLines?.length;
const isLivePreviewVisible =
- !compact && isStreaming && !effectiveExpanded
+ !compact && isStreaming && (!effectiveExpanded || holdLines)
&& (workLines ? workLines.length > 0 : liveActivities.length > 0);
// 完成态只计算一次完整摘要;运行态保持折叠时走上面的反向 latest-five
// 热路径,用户主动展开后才投影全部历史。
@@ -548,7 +551,7 @@ export function WorkGroupBlock({
'flex flex-col gap-2',
)}
>
- {effectiveExpanded &&
+ {effectiveExpanded && !holdLines &&
childItems.map((child) => (
<Fragment key={child.key}>
<ExpandedWorkGroupChild
diff --git a/apps/mobile/src/__tests__/messageActionDesktopFirst.test.ts b/apps/mobile/src/__tests__/messageActionDesktopFirst.test.ts
index 05c83280b4..0ba571fa47 100644
--- a/apps/mobile/src/__tests__/messageActionDesktopFirst.test.ts
+++ b/apps/mobile/src/__tests__/messageActionDesktopFirst.test.ts
@@ -124,7 +124,7 @@ describe('mobile message actions desktop-first surface', () => {
const end = source.indexOf('function FoldablePanel', start);
const workGroupSource = source.slice(start, end);
const expandedBodyStart = workGroupSource.indexOf('{expanded ? (');
- const childrenMapStart = workGroupSource.indexOf('{item.children.map((child) => {');
+ const childrenMapStart = workGroupSource.indexOf('{!holdLines && item.children.map((child) => {');
// 运行中用状态图标,结束后回到桌面同款 Layers 工作摘要图标。
expect(source).toContain('Layers,');
@@ -137,8 +137,11 @@ describe('mobile message actions desktop-first surface', () => {
// 单行活动(deferred.lines),既不读工作明细,也不在本机重新解析工具输入。
expect(workGroupSource).not.toContain('defaultExpanded');
expect(workGroupSource).toContain('controlledExpanded={expanded}');
- expect(workGroupSource).toContain('const lines = isStreaming && !expanded ? item.deferred?.lines : undefined;');
- expect(workGroupSource).toContain('collapsedBody={lines?.length ? (');
+ // 展开后在明细读到之前继续显示这几行,不先清空再重新出现。
+ expect(workGroupSource).toContain('const lines = isStreaming ? item.deferred?.lines : undefined;');
+ expect(workGroupSource).toContain("const holdLines = expanded && item.deferred?.awaitingDetails === true && !!lines?.length;");
+ expect(workGroupSource).toContain('collapsedBody={lineRows ? <Rail layout={layout}>{lineRows}</Rail> : undefined}');
+ expect(workGroupSource).toContain('{holdLines && lineRows}');
expect(workGroupSource).toContain('<WorkLineRow key={line.key} line={line} onPress={onToggle} />');
expect(workGroupSource).toContain('formatToolRowText(line.descriptor, mobileToolRowWording)');
expect(workGroupSource).not.toContain('summarizeToolUseText');
diff --git a/apps/mobile/src/__tests__/pluginAttachmentBubble.test.tsx b/apps/mobile/src/__tests__/pluginAttachmentBubble.test.tsx
index 986b48a550..73fc2ab18b 100644
--- a/apps/mobile/src/__tests__/pluginAttachmentBubble.test.tsx
+++ b/apps/mobile/src/__tests__/pluginAttachmentBubble.test.tsx
@@ -3,7 +3,7 @@ import { act, createElement, useImperativeHandle, useState } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { describe, expect, it, vi } from 'vitest';
-const viewportHarness = vi.hoisted(() => ({ list: null as any, finishReveal: null as any, renders: 0 }));
+const viewportHarness = vi.hoisted(() => ({ list: null as any, finishReveal: null as any, renders: 0, expanded: false }));
// Keep the production list, bubble gate, invocation header, and message model.
// Only native surfaces and unrelated heavy viewers are replaced for Node rendering.
@@ -57,7 +57,7 @@ vi.mock('@/auth/AuthContext', () => ({ useAuth: () => ({ accountGeneration: 1 })
vi.mock('@/session/usePluginResultCard', () => ({ usePluginResultCard: () => ({}), useSessionPluginResource: () => ({ title: 'Art' }) }));
vi.mock('@/session/remoteMediaDiskCacheExpo', () => ({ downloadRemoteMediaShareTemp: vi.fn() }));
vi.mock('@/hooks/useReduceMotion', () => ({ useReduceMotionEnabled: () => true }));
-vi.mock('@/session/expandedBlockMemory', () => ({ useFoldableExpandedState: () => [false, vi.fn()] }));
+vi.mock('@/session/expandedBlockMemory', () => ({ useFoldableExpandedState: () => [viewportHarness.expanded, vi.fn()] }));
vi.mock('@/platform/chrome', () => ({ NativePullDownMenu: () => null, showActionMenu: vi.fn(), usesNativePullDownMenu: () => false, usesSystemActionMenu: () => false }));
vi.mock('@/session/MobileComposerInputRow', () => ({ MobileComposerInputRow: () => null, MOBILE_COMPOSER_VOICE_ANCHOR_RIGHT: 0, MOBILE_COMPOSER_CONTROL_SIZE: 44 }));
vi.mock('@/session/ImageLightbox', () => ({ ImageLightbox: () => null }));
@@ -123,6 +123,38 @@ describe('partner work feedback', () => {
});
});
+describe('running work group expansion', () => {
+ const render = (awaitingDetails: boolean) => {
+ const messages = [msg('u', 'user', 'Fix it'), msg('c', 'tool_use', {
+ toolName: 'Bash', toolUseId: 'c', input: { command: 'pnpm test' },
+ }, { toolUseId: 'c' })];
+ const items = buildMobileMessageRenderItems(messages, { isSessionStreaming: true })
+ .filter((item) => item.type === 'work_group')
+ .map((item) => ({ ...item, deferred: {
+ owner: {}, key: 'work-c', expanded: false, loading: awaitingDetails, failed: false, awaitingDetails,
+ lines: [{ kind: 'thinking' as const, key: 'line', text: 'Checking the failing case' }],
+ setVisible: vi.fn(), toggle: vi.fn(), retry: vi.fn(),
+ } }));
+ expect(items).toHaveLength(1);
+ viewportHarness.expanded = true;
+ try {
+ return renderToStaticMarkup(<MessageRenderer items={items} isSessionStreaming />);
+ } finally {
+ viewportHarness.expanded = false;
+ }
+ };
+
+ it('keeps the Host lines visible after expanding until detail rows arrive', () => {
+ const waiting = render(true);
+ expect(waiting).toContain('message.workLine');
+ expect(waiting).toContain('Collapse ');
+ expect(waiting).not.toContain('pnpm test');
+ const loaded = render(false);
+ expect(loaded).not.toContain('message.workLine');
+ expect(loaded).toContain('pnpm test');
+ });
+});
+
function renderClient(element: ReturnType<typeof createElement>): string {
const { act } = require('react') as typeof import('react');
const { createRoot } = require('react-dom/client') as typeof import('react-dom/client');
diff --git a/apps/mobile/src/session/MessageRenderer.tsx b/apps/mobile/src/session/MessageRenderer.tsx
index a36f3912f4..cc090b29c1 100644
--- a/apps/mobile/src/session/MessageRenderer.tsx
+++ b/apps/mobile/src/session/MessageRenderer.tsx
@@ -4761,7 +4761,14 @@ function WorkGroupCard({
const pluginWork = actions.companionPluginWork?.get(item.key);
// The Host projects running lines for this view; folded groups render them as they are,
// without building the hidden activity tree or reading any work details.
- const lines = isStreaming && !expanded ? item.deferred?.lines : undefined;
+ const lines = isStreaming ? item.deferred?.lines : undefined;
+ // Expanding keeps these lines on screen until the detail read has rows to replace them.
+ const holdLines = expanded && item.deferred?.awaitingDetails === true && !!lines?.length;
+ const lineRows = lines?.length ? (
+ <View style={styles.workActivityStack}>
+ {lines.map((line) => <WorkLineRow key={line.key} line={line} onPress={onToggle} />)}
+ </View>
+ ) : null;
return (
<>
{pluginWork ? <PluginInvocationHeader plugins={pluginWork.plugins} running={pluginWork.running}
@@ -4771,13 +4778,7 @@ function WorkGroupCard({
chevronPosition={header.chevronPosition}
chevronSize={header.chevronSize}
controlledExpanded={expanded}
- collapsedBody={lines?.length ? (
- <Rail layout={layout}>
- <View style={styles.workActivityStack}>
- {lines.map((line) => <WorkLineRow key={line.key} line={line} onPress={onToggle} />)}
- </View>
- </Rail>
- ) : undefined}
+ collapsedBody={lineRows ? <Rail layout={layout}>{lineRows}</Rail> : undefined}
onControlledToggle={onToggle}
title={title}
subtitle={header.subtitle ?? undefined}
@@ -4794,6 +4795,7 @@ function WorkGroupCard({
{expanded ? (
<Rail layout={layout}>
<View style={styles.workGroupStack}>
+ {holdLines && lineRows}
{item.deferred?.loading && <CompactActivityIndicator color={colors.textTertiary} size={header.iconSize} />}
{item.deferred?.failed && (
<MessageListActionButton
@@ -4806,7 +4808,7 @@ function WorkGroupCard({
<Text style={styles.payloadOpenButtonText}>{t('message.renderer.retryPreview')}</Text>
</MessageListActionButton>
)}
- {item.children.map((child) => {
+ {!holdLines && item.children.map((child) => {
if (child.type === 'thinking') {
return <ExpandedWorkThinkingRow key={child.key} item={child} />;
}
diff --git a/apps/mobile/src/session/messageRenderReconcile.ts b/apps/mobile/src/session/messageRenderReconcile.ts
index f0018ebd02..2a0b8301af 100644
--- a/apps/mobile/src/session/messageRenderReconcile.ts
+++ b/apps/mobile/src/session/messageRenderReconcile.ts
@@ -13,7 +13,7 @@ function sameDeferred(a?: DeferredHistoryWork, b?: DeferredHistoryWork): boolean
if (!a || !b) return a === b;
return a.owner === b.owner && a.key === b.key && a.revision === b.revision
&& a.expanded === b.expanded && a.loading === b.loading && a.failed === b.failed
- && a.previewComplete === b.previewComplete;
+ && a.previewComplete === b.previewComplete && a.awaitingDetails === b.awaitingDetails;
}
/**
diff --git a/packages/maker-shared/src/__tests__/historyWorkLines.test.ts b/packages/maker-shared/src/__tests__/historyWorkLines.test.ts
index 51e481b586..f3f4afe8e3 100644
--- a/packages/maker-shared/src/__tests__/historyWorkLines.test.ts
+++ b/packages/maker-shared/src/__tests__/historyWorkLines.test.ts
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import { HistoryViewController } from '../historyViewController.js';
-import type { HistoryMessageSource, HistoryViewPage, HistoryWorkPatch, HistoryWorkSummary } from '../historyView.js';
+import type { HistoryDetailPage, HistoryMessageSource, HistoryViewPage, HistoryWorkPatch, HistoryWorkSummary } from '../historyView.js';
import { renderHistoryView } from '../historyViewRender.js';
import { HISTORY_WORK_LINE_MAX_BYTES, HISTORY_WORK_LINES_MAX_BYTES, projectHistoryWorkLines } from '../historyWorkLines.js';
@@ -105,7 +105,7 @@ describe('HistoryViewController.applyWorkPatch', () => {
async function fixture() {
const transport = {
page: vi.fn(async () => page([answer, { type: 'work', key: 'work-c1', summary: summary('work-c1', 'r1', []) }])),
- details: vi.fn(async () => ({ version: 1 as const, messages: [], hasMore: false, nextCursor: null })),
+ details: vi.fn(async (): Promise<HistoryDetailPage<HistoryMessageSource>> => ({ version: 1, messages: [], hasMore: false, nextCursor: null })),
expanded: vi.fn(async () => undefined),
};
const view = new HistoryViewController(transport);
@@ -176,4 +176,26 @@ describe('HistoryViewController.applyWorkPatch', () => {
});
expect(items[0].deferred?.lines).toEqual([{ kind: 'thinking', key: 'c9', text: 'next' }]);
});
+
+ it('reports a group as awaiting details until its first detail rows land', async () => {
+ const { view, transport } = await fixture();
+ let finish!: (value: HistoryDetailPage<HistoryMessageSource>) => void;
+ transport.details.mockImplementationOnce(() => new Promise<HistoryDetailPage<HistoryMessageSource>>((resolve) => { finish = resolve; }));
+ type Item = { key: string; ids: string[]; children?: Item[]; deferred?: { awaitingDetails?: boolean } };
+ const awaiting = () => renderHistoryView<HistoryMessageSource, Item>({
+ view, snapshot: view.getSnapshot(), liveMessages: [], streaming: true,
+ build: (rows) => [{ key: 'work', ids: [], children: rows.map((r) => ({ key: r.clientId, ids: [r.clientId] })) }],
+ structure: {
+ placeholder: (value) => row('thinking', '', { clientId: `placeholder-${value.key}` }),
+ children: (item) => item.children,
+ sourceIds: (item) => item.ids,
+ rebuild: (item, children, deferred) => ({ ...item, children, deferred }),
+ },
+ })[0].deferred?.awaitingDetails;
+ expect(awaiting()).toBe(true);
+ view.setExpanded('work-c1', true);
+ expect(awaiting()).toBe(true);
+ finish({ version: 1, messages: [row('thinking', 'first', { id: 'm1', clientId: 'm1' })], hasMore: false, nextCursor: null });
+ await vi.waitFor(() => expect(awaiting()).toBe(false));
+ });
});
diff --git a/packages/maker-shared/src/historyView.ts b/packages/maker-shared/src/historyView.ts
index a72cb3d7f4..2793d5c594 100644
--- a/packages/maker-shared/src/historyView.ts
+++ b/packages/maker-shared/src/historyView.ts
@@ -80,6 +80,8 @@ export interface DeferredHistoryWork {
previewComplete?: boolean;
/** Host-projected running lines; when present a folded preview needs no detail read. */
lines?: readonly HistoryWorkLine[];
+ /** No detail rows are in hand yet; an expanded group keeps showing `lines` until they arrive. */
+ awaitingDetails?: boolean;
expanded: boolean;
loading: boolean;
failed: boolean;
diff --git a/packages/maker-shared/src/historyViewRender.ts b/packages/maker-shared/src/historyViewRender.ts
index 271fd31bfe..5780454b68 100644
--- a/packages/maker-shared/src/historyViewRender.ts
+++ b/packages/maker-shared/src/historyViewRender.ts
@@ -165,6 +165,7 @@ export function renderHistoryView<T extends HistoryMessageSource, TItem>(options
revision: summaries.map((summary) => summary.revision).join('|'),
previewComplete: summaries.every((summary) => summary.preview?.firstMessageId === summary.firstMessageId),
...(lines ? { lines } : {}),
+ awaitingDetails: states.some((state) => !state?.complete && !state?.messages.length),
loading: states.some((state) => state?.loading), failed: states.some((state) => !!state?.error),
setVisible,
toggle: () => setVisible(!expanded, false),