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(device-link): 保留所有展开运行组的实时详情

Dash8f976ab24b5e
diff --git a/apps/desktop/src/main/device-link/__tests__/dispatchSendSafety.test.ts b/apps/desktop/src/main/device-link/__tests__/dispatchSendSafety.test.ts
index 8036b2c4d3..f2a69ca5f8 100644
--- a/apps/desktop/src/main/device-link/__tests__/dispatchSendSafety.test.ts
+++ b/apps/desktop/src/main/device-link/__tests__/dispatchSendSafety.test.ts
@@ -146,17 +146,17 @@ describe('history detail interest', () => {
const pending = new Promise<void>((resolve) => { finish = resolve; });
setRemoteBotSessionLookup(async () => { await pending; return 'ordinary'; });
subscriptions.subscribe('ctrl', ['session:s1']);
- subscriptions.prepareHistoryView('ctrl', 's1')!.update('work');
+ subscriptions.prepareHistoryView('ctrl', 's1')!.update(['work']);
registry.register(channel, () => {
const view = getDeviceLinkInvokeContext()?.historyView;
- if (channel.endsWith(':view')) view?.update('stale');
+ if (channel.endsWith(':view')) view?.update(['stale']);
else view?.setExpanded(['new']);
return {};
});
const request = runInvoke('ctrl', { channel, args: ['s1'] });
subscriptions.clearHistoryViews('ctrl');
const current = subscriptions.prepareHistoryView('ctrl', 's1')!;
- current.update('new');
+ current.update(['new']);
finish();
expect(await request).toMatchObject({ ok: true });
expect(subscriptions.projectsHistoryDetails('ctrl', 's1')).toBe(true);
@@ -166,7 +166,7 @@ describe('history detail interest', () => {
it('does not clear working history when link acceptance fails', () => {
const client = mkClient();
subscriptions.subscribe('ctrl', ['session:s1']);
- subscriptions.prepareHistoryView('ctrl', 's1')!.update('work');
+ subscriptions.prepareHistoryView('ctrl', 's1')!.update(['work']);
client.sendLinkAccept.mockImplementation(() => { throw new Error('backpressure'); });
__testing.handleLinkOpen(client as never, 'ctrl', 'failed-open', undefined);
expect(subscriptions.hasHistoryView('ctrl', 's1')).toBe(true);
@@ -177,32 +177,32 @@ describe('history detail interest', () => {
__testing.setActiveClient(client as never);
for (const peer of ['changed', 'untouched']) {
subscriptions.subscribe(peer, ['session:s1']);
- subscriptions.prepareHistoryView(peer, 's1')!.update('work');
+ subscriptions.prepareHistoryView(peer, 's1')!.update(['work']);
}
const old = subscriptions.prepareHistoryView('changed', 's1')!;
if (offline) subscriptions.clearController('changed');
__testing.handleLinkOpen(client as never, 'changed', 'new-link', undefined);
subscriptions.subscribe('changed', ['session:s1']);
- old.update('work');
+ old.update(['work']);
old.setExpanded(['work']);
client.sendPush.mockClear();
const payload = { sessionId: 's1', event: { type: 'thinking', data: { stage: 'delta', text: 'full detail' } } };
__testing.forwardPush('maker:event', payload);
expect(client.sendPush).toHaveBeenCalledWith('changed', 'maker:event', payload);
expect(client.sendPush.mock.calls.some(([peer]) => peer === 'untouched')).toBe(false);
- subscriptions.prepareHistoryView('changed', 's1')!.update('work');
+ subscriptions.prepareHistoryView('changed', 's1')!.update(['work']);
client.sendPush.mockClear();
__testing.forwardPush('maker:event', payload);
expect(client.sendPush.mock.calls.some(([peer]) => peer === 'changed')).toBe(false);
});
- it('sends full thinking only to expanded/legacy peers and coalesces folded summaries', async () => {
+ it.each(['first', 'second'])('sends full thinking to peers with %s streaming group expanded and coalesces folded summaries', async (expandedKey) => {
vi.useFakeTimers();
try {
const client = mkClient();
__testing.setActiveClient(client as never);
for (const peer of ['folded', 'expanded', 'legacy']) subscriptions.subscribe(peer, ['session:s1']);
- for (const peer of ['folded', 'expanded']) subscriptions.prepareHistoryView(peer, 's1')!.update('work');
- subscriptions.prepareHistoryView('expanded', 's1')!.setExpanded(['work']);
+ for (const peer of ['folded', 'expanded']) subscriptions.prepareHistoryView(peer, 's1')!.update(['first', 'second']);
+ subscriptions.prepareHistoryView('expanded', 's1')!.setExpanded([expandedKey]);
const push = (stage: string) => ({ sessionId: 's1', event: { type: 'thinking', data: { stage, blockId: 'b', text: 'private detail' } } });
__testing.forwardPush('maker:event', push('start'));
for (let n = 0; n < 100; n++) __testing.forwardPush('maker:event', push('delta'));
diff --git a/apps/desktop/src/main/device-link/__tests__/historyViewPush.test.ts b/apps/desktop/src/main/device-link/__tests__/historyViewPush.test.ts
index e1c7842413..069995ad1c 100644
--- a/apps/desktop/src/main/device-link/__tests__/historyViewPush.test.ts
+++ b/apps/desktop/src/main/device-link/__tests__/historyViewPush.test.ts
@@ -5,7 +5,7 @@ afterEach(() => subscriptions.__testing.reset());
describe('per-controller deferred history', () => {
it('separates collapsed, expanded and legacy peers and refuses late intent after unsubscribe', () => {
for (const peer of ['closed', 'open', 'old']) subscriptions.subscribe(peer, ['session:s']);
- for (const peer of ['closed', 'open']) subscriptions.prepareHistoryView(peer, 's')!.update('w');
+ for (const peer of ['closed', 'open']) subscriptions.prepareHistoryView(peer, 's')!.update(['w']);
subscriptions.prepareHistoryView('open', 's')!.setExpanded(['w']);
expect(subscriptions.projectsHistoryDetails('closed', 's')).toBe(true);
expect(subscriptions.projectsHistoryDetails('open', 's')).toBe(false);
@@ -21,7 +21,7 @@ describe('per-controller deferred history', () => {
old.setExpanded(['w']);
expect(subscriptions.hasHistoryView('a', 's')).toBe(false);
expect(subscriptions.projectsHistoryDetails('a', 's')).toBe(false);
- old.update('w');
+ old.update(['w']);
old.setExpanded(['w']);
if (boundary === 'disconnect') subscriptions.clearController('a');
if (boundary === 'reopen') subscriptions.clearHistoryViews('a');
@@ -29,21 +29,42 @@ describe('per-controller deferred history', () => {
if (boundary === 'revoke') subscriptions.forgetKnownController('a');
if (boundary === 'clear-all') subscriptions.clearAll();
subscriptions.subscribe('a', ['session:s']);
- old.update('w');
+ old.update(['w']);
old.setExpanded(['w']);
expect(subscriptions.hasHistoryView('a', 's')).toBe(false);
const current = subscriptions.prepareHistoryView('a', 's')!;
- current.update('new');
- old.update('old');
+ current.update(['new']);
+ old.update(['old']);
old.setExpanded(['new']);
expect(subscriptions.projectsHistoryDetails('a', 's')).toBe(true);
current.setExpanded(['new']);
expect(subscriptions.projectsHistoryDetails('a', 's')).toBe(false);
- other.update('b-work');
+ other.update(['b-work']);
other.setExpanded(['b-work']);
expect(subscriptions.hasHistoryView('b', 's')).toBe(boundary !== 'clear-all');
expect(subscriptions.projectsHistoryDetails('b', 's')).toBe(false);
});
+ it('tracks all streaming groups and replaces the accepted page keys', () => {
+ subscriptions.subscribe('a', ['session:s']);
+ subscriptions.subscribe('b', ['session:s']);
+ const view = subscriptions.prepareHistoryView('a', 's')!;
+ view.update(['first', 'second']);
+ view.setExpanded(['second']);
+ expect(subscriptions.projectsHistoryDetails('a', 's')).toBe(false);
+ expect(subscriptions.projectsHistoryDetails('b', 's')).toBe(false); // legacy
+ view.setExpanded(['completed']);
+ expect(subscriptions.projectsHistoryDetails('a', 's')).toBe(true);
+ view.setExpanded(['second']);
+ view.update(['third']);
+ expect(subscriptions.projectsHistoryDetails('a', 's')).toBe(true);
+ view.setExpanded(['third']);
+ expect(subscriptions.projectsHistoryDetails('a', 's')).toBe(false);
+ view.setExpanded([]);
+ expect(subscriptions.projectsHistoryDetails('a', 's')).toBe(true);
+ view.setExpanded(['third']);
+ view.update([]);
+ expect(subscriptions.projectsHistoryDetails('a', 's')).toBe(true);
+ });
it('defers thinking/tool bodies but retains prose, interactions, errors and artifacts', () => {
const push = (type: string, data: unknown) => ({ sessionId: 's', event: { type, data } });
const names = () => 'Read';
diff --git a/apps/desktop/src/main/device-link/subscriptions.ts b/apps/desktop/src/main/device-link/subscriptions.ts
index 199f90336e..d4890e3a7c 100644
--- a/apps/desktop/src/main/device-link/subscriptions.ts
+++ b/apps/desktop/src/main/device-link/subscriptions.ts
@@ -48,20 +48,20 @@ const rememberedTopicsByController = new Map<string, Set<StoredTopic>>();
* 新控制端误判成 legacy,否则 set-model 的显式 provider null 会被当成占位。
*/
const rememberedCapabilitiesByController = new Map<string, Set<string>>();
-const historyViewsByController = new Map<string, Map<string, { ready: boolean; liveKey: string | null; expanded: Set<string> }>>();
+const historyViewsByController = new Map<string, Map<string, { ready: boolean; liveKeys: readonly string[]; expanded: Set<string> }>>();
/** Capture this subscription before reading; only its successful result may enable filtering. */
export function prepareHistoryView(deviceId: string, sessionId: string) {
if (!controllerHasTopic(deviceId, `session:${sessionId}`)) return undefined;
const views = historyViewsByController.get(deviceId) ?? new Map();
- const view = views.get(sessionId) ?? { ready: false, liveKey: null, expanded: new Set<string>() };
+ const view = views.get(sessionId) ?? { ready: false, liveKeys: [], expanded: new Set<string>() };
views.set(sessionId, view);
historyViewsByController.set(deviceId, views);
const isCurrent = () => historyViewsByController.get(deviceId)?.get(sessionId) === view;
return {
- update(liveKey: string | null): void {
+ update(liveKeys: readonly string[]): void {
if (!isCurrent()) return;
- view.liveKey = liveKey;
+ view.liveKeys = [...liveKeys];
view.ready = true;
},
setExpanded(keys: readonly string[]): void {
@@ -83,7 +83,7 @@ export function hasHistoryView(deviceId: string, sessionId: string): boolean {
export function projectsHistoryDetails(deviceId: string, sessionId: string): boolean {
const view = historyViewsByController.get(deviceId)?.get(sessionId);
- return !!view?.ready && (!view.liveKey || !view.expanded.has(view.liveKey));
+ return !!view?.ready && !view.liveKeys.some((key) => view.expanded.has(key));
}
/**
diff --git a/apps/desktop/src/main/localDb/ipc/messages.ts b/apps/desktop/src/main/localDb/ipc/messages.ts
index 58d3b16f01..c387329789 100644
--- a/apps/desktop/src/main/localDb/ipc/messages.ts
+++ b/apps/desktop/src/main/localDb/ipc/messages.ts
@@ -382,8 +382,9 @@ export function registerMessageIpc(
const before = (opts as { before?: unknown } | null)?.before;
const page = await historyView.page(sid, before == null ? undefined : requireString(before, 'before'));
if (before == null) {
- const live = historyViewLeaves(page.items).find((item) => item.type === 'work' && item.summary.isStreaming);
- getDeviceLinkInvokeContext()?.historyView?.update(live?.key ?? null);
+ const liveKeys = historyViewLeaves(page.items)
+ .filter((item) => item.type === 'work' && item.summary.isStreaming).map((item) => item.key);
+ getDeviceLinkInvokeContext()?.historyView?.update(liveKeys);
}
return page;
});