Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(history): 衔接首次读取期间的详情变更通知
Dash574dda587b51
diff --git a/apps/desktop/src/main/device-link/__tests__/dispatchSendSafety.test.ts b/apps/desktop/src/main/device-link/__tests__/dispatchSendSafety.test.tsindex f2a69ca5f8..437105e25b 100644--- a/apps/desktop/src/main/device-link/__tests__/dispatchSendSafety.test.ts+++ b/apps/desktop/src/main/device-link/__tests__/dispatchSendSafety.test.ts@@ -46,6 +46,7 @@ import { __testing, runInvoke, wireInboundDispatch } from '../dispatch';import { __testing as registry } from '../invoke-registry';import { setRemoteBotSessionLookup } from '../remoteBotSessionBoundary';import { getDeviceLinkInvokeContext } from '../invoke-context';+import { HistoryViewController, type HistoryViewPage, type HistoryMessageSource } from '@cindy/maker-shared/message-window';import * as subscriptions from '../subscriptions';/** 最小 mock client:只实现被测路径用到的两个发送方法。 */@@ -195,6 +196,48 @@ describe('history detail interest', () => {__testing.forwardPush('maker:event', payload);expect(client.sendPush.mock.calls.some(([peer]) => peer === 'changed')).toBe(false);});+ it.each([false, true])('invalidates a sampled pending view even when notice precedes its result: %s', async (finishBeforeNotice) => {+ vi.useFakeTimers();+ const page: HistoryViewPage<HistoryMessageSource> = { version: 1, items: [], hasMore: false, nextCursor: null };+ let finish!: (value: typeof page) => void;+ const read = vi.fn().mockImplementationOnce(() => new Promise(resolve => { finish = resolve; }))+ .mockResolvedValue(page);+ const view = new HistoryViewController<HistoryMessageSource>({ page: read,+ details: async () => ({ version: 1, messages: [], hasMore: false, nextCursor: null }),+ expanded: async () => undefined });+ try {+ const client = mkClient();+ client.sendPush.mockImplementation((peer, channel) => {+ if (peer === 'pending' && channel === 'maker:history-view-changed') view.invalidate();+ });+ __testing.setActiveClient(client as never);+ for (const peer of ['pending', 'legacy']) subscriptions.subscribe(peer, ['session:s1']);+ const captured = subscriptions.prepareHistoryView('pending', 's1')!;+ const request = view.refresh();+ const payload = { sessionId: 's1', event: { type: 'thinking', data: { stage: 'delta', blockId: 'b', text: 'new' } } };+ for (let n = 0; n < 10; n++) __testing.forwardPush('maker:event', payload);+ expect(client.sendPush.mock.calls.filter(([peer, channel]) => peer === 'pending' && channel === 'maker:event')).toHaveLength(10);+ if (!finishBeforeNotice) {+ await vi.advanceTimersByTimeAsync(1000);+ expect(read).toHaveBeenCalledTimes(1);+ }+ captured.update(['work']);+ finish(page);+ await request;+ await vi.advanceTimersByTimeAsync(1000);+ expect(read).toHaveBeenCalledTimes(2);+ expect(client.sendPush.mock.calls.filter(([, channel]) => channel === 'maker:history-view-changed'))+ .toEqual([['pending', 'maker:history-view-changed', { sessionId: 's1' }]]);+ client.sendPush.mockClear();+ __testing.forwardPush('maker:event', payload);+ await vi.advanceTimersByTimeAsync(1000);+ expect(client.sendPush.mock.calls).toEqual([['legacy', 'maker:event', payload]]);+ } finally {+ view.setActive(false);+ __testing.reset();+ vi.useRealTimers();+ }+ });it.each(['first', 'second'])('sends full thinking to peers with %s streaming group expanded and coalesces folded summaries', async (expandedKey) => {vi.useFakeTimers();try {diff --git a/apps/desktop/src/main/device-link/__tests__/historyViewPush.test.ts b/apps/desktop/src/main/device-link/__tests__/historyViewPush.test.tsindex f938dbaa88..ff97c94ec8 100644--- a/apps/desktop/src/main/device-link/__tests__/historyViewPush.test.ts+++ b/apps/desktop/src/main/device-link/__tests__/historyViewPush.test.ts@@ -20,6 +20,7 @@ describe('per-controller deferred history', () => {const other = subscriptions.prepareHistoryView('b', 's')!;old.setExpanded(['w']);expect(subscriptions.hasHistoryView('a', 's')).toBe(false);+ expect(subscriptions.hasHistoryView('a', 's', true)).toBe(true);expect(subscriptions.projectsHistoryDetails('a', 's')).toBe(false);old.update(['w']);old.setExpanded(['w']);@@ -32,6 +33,7 @@ describe('per-controller deferred history', () => {old.update(['w']);old.setExpanded(['w']);expect(subscriptions.hasHistoryView('a', 's')).toBe(false);+ expect(subscriptions.hasHistoryView('a', 's', true)).toBe(false);const current = subscriptions.prepareHistoryView('a', 's')!;current.update(['new']);old.update(['old']);@@ -93,6 +95,7 @@ it('restores raw pushes only for the disabled view and rejects its late reads/inold.update(['work']);old.setExpanded(['work']);expect(subscriptions.hasHistoryView('a', 's')).toBe(false);+ expect(subscriptions.hasHistoryView('a', 's', true)).toBe(false);expect(subscriptions.projectsHistoryDetails('a', 's')).toBe(false);expect(subscriptions.projectsHistoryDetails('b', 's')).toBe(true);subscriptions.prepareHistoryView('a', 's')!.update(['new']);diff --git a/apps/desktop/src/main/device-link/dispatch.ts b/apps/desktop/src/main/device-link/dispatch.tsindex 31561a0daa..1d9abefe86 100644--- a/apps/desktop/src/main/device-link/dispatch.ts+++ b/apps/desktop/src/main/device-link/dispatch.ts@@ -1697,7 +1697,9 @@ function forwardPush(channel: string, payload: unknown, ownerStamp?: PushOwnerSt}for (const dst of liveTargets) {let targetPayload = payloadFor(dst);- if (deferred && historySessionId && subscriptions.hasHistoryView(dst, historySessionId)) {+ // A pending read also needs notices: its sampled rows can precede this push.+ // Filtering still requires ready in projectsHistoryDetails, so raw survives.+ if (deferred && historySessionId && subscriptions.hasHistoryView(dst, historySessionId, true)) {const folded = subscriptions.projectsHistoryDetails(dst, historySessionId);const event = (remotePayload as { event?: { type?: string; data?: { stage?: string } } })?.event;// A folded duration ticks locally. Token deltas do not change its summary.diff --git a/apps/desktop/src/main/device-link/subscriptions.ts b/apps/desktop/src/main/device-link/subscriptions.tsindex d5a82e4b34..ca4d2294e0 100644--- a/apps/desktop/src/main/device-link/subscriptions.ts+++ b/apps/desktop/src/main/device-link/subscriptions.ts@@ -80,8 +80,9 @@ export function clearHistoryViews(deviceId: string): void {historyViewsByController.delete(deviceId);}-export function hasHistoryView(deviceId: string, sessionId: string): boolean {- return historyViewsByController.get(deviceId)?.get(sessionId)?.ready === true;+export function hasHistoryView(deviceId: string, sessionId: string, includePending = false): boolean {+ const view = historyViewsByController.get(deviceId)?.get(sessionId);+ return !!view && (includePending || view.ready);}export function projectsHistoryDetails(deviceId: string, sessionId: string): boolean {