Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): hold the preview window through paginated rereads and recheck seeded chips
MagicLizicb425c006464
diff --git a/apps/desktop/src/renderer/__tests__/controlledBannerPlacement.test.ts b/apps/desktop/src/renderer/__tests__/controlledBannerPlacement.test.tsindex eb7086cb42..82edb97886 100644--- a/apps/desktop/src/renderer/__tests__/controlledBannerPlacement.test.ts+++ b/apps/desktop/src/renderer/__tests__/controlledBannerPlacement.test.ts@@ -7,6 +7,7 @@ const R = resolve(__dirname, '..');const read = (rel: string) => readFileSync(resolve(R, rel), 'utf8').replace(/\r\n?/g, '\n');const sessionViewSource = read('features/cc-agent/CCAgentSessionView.tsx');+const overlayMetricsSource = read('features/cc-agent/useComposerOverlayMetrics.ts');const splitViewSource = read('features/cc-agent/OrcaSplitView.tsx');const routeSource = read('features/cc-agent/OrcaWorkflowRoute.tsx');const workerPanelSource = read('features/cc-agent/OrcaWorkerPanel.tsx');@@ -111,10 +112,10 @@ describe('controlled banner placement', () => {);expect(todoListSource).toContain('data-plan-pill-anchor="true"');expect(todoListSource).toContain('data-plan-flyout-positioner="composer"');- expect(sessionViewSource).toContain(- 'const mutationObserver = new MutationObserver(syncResizeTargetsAndMeasure);',+ expect(overlayMetricsSource).toContain(+ 'const mutationObserver = new MutationObserver(() => syncResizeTargetsAndMeasure(true));',);- expect(sessionViewSource).toContain(+ expect(overlayMetricsSource).toContain('mutationObserver.observe(overlayEl, { childList: true, subtree: true });',);expect(sessionViewSource).not.toContain('fitContent=');diff --git a/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsx b/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsxindex bda14deb07..af8791f660 100644--- a/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsx+++ b/apps/desktop/src/renderer/components/chat/GeneratedFilesCard.tsx@@ -769,6 +769,8 @@ export const GeneratedFilesCard = memo(function GeneratedFilesCard({filesRef.current = files;const visibleRef = useRef<GeneratedFileRef[] | null>(initialVisible);// 首屏来自缓存的结论仍要整卡复核一次:缓存只负责不留空白帧,不替代本次 stat。+ // 复核结果真正应用后才收起标记:检查中途被 checkKey 变化取消时,下一轮必须继续+ // 整卡重查,否则缓存里已被删除的路径会被当成已确认而永远留在屏上。const seededRef = useRef(initialVisible !== null);const checkEnvRef = useRef({ remoteOrigin, workingDir: fileCtx.workingDir });const turnWindowRef = useRef({ turnStartMs, turnEndMs, turnSealed });@@ -811,7 +813,6 @@ export const GeneratedFilesCard = memo(function GeneratedFilesCard({turnWindowRef.current.turnEndMs !== turnEndMs ||turnWindowRef.current.turnSealed !== turnSealed;const forceRestat = remoteVerdictGenRef.current !== remoteVerdictGen || seededRef.current;- seededRef.current = false;checkEnvRef.current = { remoteOrigin, workingDir: fileCtx.workingDir };turnWindowRef.current = { turnStartMs, turnEndMs, turnSealed };remoteVerdictGenRef.current = remoteVerdictGen;@@ -894,6 +895,9 @@ export const GeneratedFilesCard = memo(function GeneratedFilesCard({visibleRef.current = merged;onVisibilityChange?.(checkKey, merged.length > 0);setExisting((prev) => reuseGeneratedFilesIfUnchanged(prev, merged));+ // The seeded conclusion is now re-checked by real stats; only then does+ // the pending-review mark go away.+ seededRef.current = false;})();return () => {diff --git a/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsxindex 7696bddd2f..87c391d225 100644--- a/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsx+++ b/apps/desktop/src/renderer/components/chat/__tests__/GeneratedFilesCard.localSeed.test.tsx@@ -34,20 +34,30 @@ function stubStat(statPath: ReturnType<typeof vi.fn>) {function renderCard(props: {renderItemKey: string;+ files?: readonly GeneratedFileRef[];turnStartMs: number;turnEndMs?: number | null;}) {- return render(+ return render(cardElement(props));+}++function cardElement(props: {+ renderItemKey: string;+ files?: readonly GeneratedFileRef[];+ turnStartMs: number;+ turnEndMs?: number | null;+}) {+ return (<ChatSessionFileProvidervalue={{ sessionId: 'local-task', workingDir: 'C:\\work', origin: { kind: 'local' } }}><GeneratedFilesCardrenderItemKey={props.renderItemKey}- files={[report]}+ files={props.files ?? [report]}turnStartMs={props.turnStartMs}turnEndMs={props.turnEndMs ?? null}/>- </ChatSessionFileProvider>,+ </ChatSessionFileProvider>);}@@ -99,6 +109,42 @@ describe('local generated files remount', () => {await waitFor(() => expect(screen.queryByText('report.md')).toBeNull());});+ it('re-checks a seeded path when another file finishes during the first check', async () => {+ const notes: GeneratedFileRef = {+ path: 'C:\\work\\notes.md',+ name: 'notes.md',+ source: 'tool',+ ready: true,+ };+ const pending: Array<(stat: unknown) => void> = [];+ const statPath = vi.fn((path: string) =>+ path === notes.path+ ? Promise.resolve({ kind: 'file', birthtimeMs: START + 5_000, mtimeMs: START + 5_000 })+ : new Promise((resolve) => {+ pending.push(resolve);+ }),+ );+ stubStat(statPath);+ const first = renderCard({ renderItemKey: 'genfiles-a', turnStartMs: START });+ await waitFor(() => expect(pending).toHaveLength(1));+ pending[0]({ kind: 'file', birthtimeMs: START + 5_000, mtimeMs: START + 5_000 });+ await waitFor(() => expect(screen.getByText('report.md')).toBeTruthy());+ first.unmount();++ // Remount seeds report.md from the stat cache; its re-check hangs mid-turn.+ const second = renderCard({ renderItemKey: 'genfiles-a', turnStartMs: START });+ expect(screen.getByText('report.md')).toBeTruthy();+ await waitFor(() => expect(pending).toHaveLength(2));+ // notes.md finishes while the seeded re-check is still in flight. The check+ // fingerprint changes and cancels that run before its verdict can land.+ second.rerender(cardElement({ renderItemKey: 'genfiles-a', turnStartMs: START, files: [report, notes] }));+ await waitFor(() => expect(pending).toHaveLength(3));+ // The replacement re-check still verifies the seeded path and finds it gone.+ pending[2]({ kind: 'missing' });+ await waitFor(() => expect(screen.queryByText('report.md')).toBeNull());+ expect(screen.getByText('notes.md')).toBeTruthy();+ });+it('applies the current turn window to cached stats', async () => {const statPath = vi.fn()diff --git a/packages/maker-shared/src/__tests__/historyView.test.ts b/packages/maker-shared/src/__tests__/historyView.test.tsindex f99c8e39fc..27906a281e 100644--- a/packages/maker-shared/src/__tests__/historyView.test.ts+++ b/packages/maker-shared/src/__tests__/historyView.test.ts@@ -649,6 +649,48 @@ describe('locating folded history preserves display expansion', () => {view.setActive(false);});+ it('keeps the previous window until a paginated reread lands the slid tail', async () => {+ const rows = Array.from({ length: 8 }, (_, i) => row(i + 1, 'thinking', `detail-${i}`));+ const items = projectHistoryView(rows, true);+ if (items[0].type !== 'work') throw new Error('missing work');+ const summary = items[0].summary;+ summary.preview = { ...summary, key: 'preview', revision: 'r1', firstMessageId: rows[0].id, lastMessageId: rows[4].id };+ const reads: Array<(page: import('../historyView.js').HistoryDetailPage<HistoryMessageSource>) => void> = [];+ const view = new HistoryViewController<HistoryMessageSource>({+ page: async () => ({ version: 1, items, hasMore: false, nextCursor: null }),+ details: () => new Promise(resolve => { reads.push(resolve); }),+ expanded: async () => undefined,+ });+ await view.refresh();+ view.setExpanded('preview', true);+ reads[0]({ version: 1, messages: rows.slice(0, 5), hasMore: false, nextCursor: null });+ await new Promise(done => setTimeout(done, 0));+ const structure = { ...ungroupedStructure,+ placeholder: (ref: import('../historyView.js').HistoryWorkSummary) => ({ ...row(0, 'thinking', ''), clientId: `placeholder:${ref.key}` }) };+ const render = () => renderHistoryView({ view, snapshot: view.getSnapshot(), liveMessages: [], streaming: true,+ build: messages => messages.map(message => message.clientId), structure });+ const placeholderId = `placeholder:${summary.key}`;+ const previousWindow = rows.slice(0, 5).map(message => message.clientId);+ expect(render()).toEqual([placeholderId, ...previousWindow]);++ // Three new activities slide the latest-five preview from rows[0..4] to rows[3..7].+ summary.preview = { ...summary, key: 'preview', revision: 'r2', firstMessageId: rows[3].id, lastMessageId: rows[7].id };+ void view.refresh();+ await new Promise(done => setTimeout(done, 0));+ expect(reads).toHaveLength(2);+ reads[1]({ version: 1, messages: [rows[3]], hasMore: true, nextCursor: rows[3].id });+ await new Promise(done => setTimeout(done, 0));+ // The first page of the new range must not replace the previous window with a partial slice.+ expect(view.getSnapshot().details.get('preview')?.messages.map(message => message.clientId)).toEqual(previousWindow);+ expect(render()).toEqual([placeholderId, ...previousWindow]);+ reads[2]({ version: 1, messages: rows.slice(4), hasMore: false, nextCursor: null });+ await new Promise(done => setTimeout(done, 0));+ const slidWindow = rows.slice(3, 8).map(message => message.clientId);+ expect(view.getSnapshot().details.get('preview')?.messages.map(message => message.clientId)).toEqual(slidWindow);+ expect(render()).toEqual([placeholderId, ...slidWindow]);+ view.setActive(false);+ });+it('does not replace a located complete range with an in-flight partial expansion', async () => {const rows = [row(1, 'thinking', 'one'), row(2, 'thinking', 'two')];const items = projectHistoryView(rows, false);diff --git a/packages/maker-shared/src/historyViewController.ts b/packages/maker-shared/src/historyViewController.tsindex ca287c936f..beff22dd42 100644--- a/packages/maker-shared/src/historyViewController.ts+++ b/packages/maker-shared/src/historyViewController.ts@@ -230,7 +230,14 @@ export class HistoryViewController<T extends HistoryMessageSource> {const completed = this.state.details.get(summary.key);if (completed?.complete && completed.revision === summary.revision && !patch.complete) return;const details = new Map(this.state.details);- details.set(summary.key, { messages: collected.length ? collected : (existing?.messages ?? []), revision: summary.revision,+ // A reread keeps the previous window until it settles. Publishing each+ // incoming page would replace the old window with a partial slice of the+ // new range: the rendered list collapses to the first page and shifts a+ // bottom-pinned stream before the tail lands.+ const settled = patch.complete === true;+ const messages = !settled && existing?.messages?.length ? existing.messages+ : collected.length ? collected : (existing?.messages ?? []);+ details.set(summary.key, { messages, revision: summary.revision,lastMessageId: summary.lastMessageId, loading: true, complete: false, error: null, ...patch });this.publish({ details });};