Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(cindy-make): overread legacy remote search candidates
MagicLizi0986072cd60f
diff --git a/apps/desktop/src/renderer/lib/__tests__/conversationSearchFanout.test.ts b/apps/desktop/src/renderer/lib/__tests__/conversationSearchFanout.test.tsindex 8f54addff5..56b0dddd09 100644--- a/apps/desktop/src/renderer/lib/__tests__/conversationSearchFanout.test.ts+++ b/apps/desktop/src/renderer/lib/__tests__/conversationSearchFanout.test.ts@@ -438,6 +438,38 @@ describe('searchConversationsAcrossOrigins', () => {semanticMode: 'hybrid',};+ it.each([1, 3, 24, 40])('finds ordinary hits behind %i Make hits on a bounded legacy host', async (hiddenCount) => {+ const candidates = [+ ...Array.from({ length: hiddenCount }, (_entry, index) => result('make-' + index, 100 - index, {+ source: index % 2 === 0 ? 'cindy-make' : 'cindy-make-merge',+ })),+ ...Array.from({ length: 4 }, (_entry, index) => result('ordinary-' + index, 4 - index, { source: 'desktop' })),+ ];+ const invokeRemote = vi.fn(async (_deviceId: string, _channel: string, args: unknown[]) => {+ const remoteRequest = args[0] as ConversationSearchRequest;+ return response(candidates.slice(0, Math.min(remoteRequest.limit ?? 20, 50)));+ });+ const searchLocal = vi.fn(async () => response([]));+ const page = await searchConversationsAcrossOrigins({ ...request, limit: 3 }, {+ origins: [+ { kind: 'local', sessionIds: null },+ { kind: 'remote', deviceId: 'dev-a', deviceName: 'Studio', connected: true, sessionIds: null },+ ],+ searchLocal,+ invokeRemote,+ listCachedRemoteSessions: () => [],+ });++ expect(page.results.map((item) => item.session.id)).toEqual(['ordinary-0', 'ordinary-1', 'ordinary-2']);+ expect(page.remoteResults?.map((item) => item.session.id)).toEqual([+ 'ordinary-0', 'ordinary-1', 'ordinary-2', 'ordinary-3',+ ]);+ expect(invokeRemote).toHaveBeenCalledExactlyOnceWith('dev-a', 'local-db:conversations:search', [+ expect.objectContaining({ limit: 50, semanticMode: 'keyword' }),+ ]);+ expect(searchLocal).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ limit: 3, semanticMode: 'hybrid' }));+ });+it('fans out, forces keyword on remotes, and survives a failed device', async () => {const invokeRemote = vi.fn(async (deviceId: string) => {if (deviceId === 'dev-b') throw new Error('[DEVICE_LINK_NOT_CONNECTED] closed');diff --git a/apps/desktop/src/renderer/lib/conversationSearchService.ts b/apps/desktop/src/renderer/lib/conversationSearchService.tsindex 0f3374fa06..3b2b51b4d7 100644--- a/apps/desktop/src/renderer/lib/conversationSearchService.ts+++ b/apps/desktop/src/renderer/lib/conversationSearchService.ts@@ -19,6 +19,7 @@ import {} from './conversationSearchFanout';import type { ConversationSearchResultItem } from '../../shared/conversationSearch';import { remoteProjectsStore } from '@/features/device-link/remoteProjectsStore';+import { remoteConversationSearchRequest } from '@cindy/maker-shared/conversation-search';function wrap<T>(p: Promise<T>): Promise<T> {return p.catch((err: unknown) => {@@ -144,7 +145,7 @@ async function searchRemoteIndexed(request: ConversationSearchRequest,invokeRemote: ConversationSearchFanoutDeps['invokeRemote'],): Promise<ConversationSearchResponse> {- const response = await invokeRemote(deviceId, 'local-db:conversations:search', [request]);+ const response = await invokeRemote(deviceId, 'local-db:conversations:search', [remoteConversationSearchRequest(request)]);return response as ConversationSearchResponse;}diff --git a/apps/mobile/src/__tests__/conversationSearch.test.ts b/apps/mobile/src/__tests__/conversationSearch.test.tsindex f540860d4f..b82ff1c285 100644--- a/apps/mobile/src/__tests__/conversationSearch.test.ts+++ b/apps/mobile/src/__tests__/conversationSearch.test.ts@@ -18,7 +18,7 @@ import {type ConversationSearchDeviceOrigin,type ConversationSearchInvoke,} from '@/session/conversationSearch';-import type { ConversationSearchResponse } from '@cindy/maker-shared/conversation-search';+import type { ConversationSearchRequest, ConversationSearchResponse } from '@cindy/maker-shared/conversation-search';import type { RemoteSession } from '@/session/types';function session(partial: Partial<RemoteSession> & Pick<RemoteSession, 'id' | 'title'>): RemoteSession {@@ -77,6 +77,30 @@ const studio: ConversationSearchDeviceOrigin = {};describe('searchConversationsAcrossDevices', () => {+ it.each([1, 3, 24, 40])('finds ordinary hits behind %i Make hits on a bounded legacy host', async (hiddenCount) => {+ const indexed = indexedPage([+ ...Array.from({ length: hiddenCount }, (_entry, index) => 'make-' + index),+ 'ordinary-0', 'ordinary-1', 'ordinary-2', 'ordinary-3',+ ]);+ for (const [index, item] of indexed.results.slice(0, hiddenCount).entries()) {+ item.session.source = index % 2 === 0 ? 'cindy-make' : 'cindy-make-merge';+ }+ const invoke = vi.fn(async (_deviceId: string, _channel: string, args: unknown[]) => {+ const remoteRequest = args[0] as ConversationSearchRequest;+ return { ...indexed, results: indexed.results.slice(0, Math.min(remoteRequest.limit ?? 20, 50)) };+ });+ const page = await searchConversationsAcrossDevices([studio], { query: 'needle', limit: 3 }, {+ invoke: invoke as ConversationSearchInvoke,+ getCachedSessions: () => [],+ });++ expect(page.results.map((item) => item.session.id)).toEqual(['ordinary-0', 'ordinary-1', 'ordinary-2']);+ expect(page.results.every((item) => item.session.deviceLinkDeviceId === 'dev-a')).toBe(true);+ expect(invoke).toHaveBeenCalledExactlyOnceWith('dev-a', 'local-db:conversations:search', [+ expect.objectContaining({ limit: 50, semanticMode: 'keyword' }),+ ]);+ });+it('excludes Make hits returned by an older desktop before the result limit', async () => {const indexed = indexedPage(['make', 'merge', 'ordinary']);indexed.results[0].session.source = 'cindy-make';diff --git a/apps/mobile/src/session/conversationSearch.ts b/apps/mobile/src/session/conversationSearch.tsindex 3fbc5c29e9..b43f1d3f74 100644--- a/apps/mobile/src/session/conversationSearch.ts+++ b/apps/mobile/src/session/conversationSearch.ts@@ -9,6 +9,7 @@ import {filterResultsByRequestFilters,mergeConversationSearchFanout,remoteIndexedSearchIgnoredWorkingDirs,+ remoteConversationSearchRequest,stampRemoteSearchResponse,type ConversationSearchAgentFilter,type ConversationSearchLastActivityFilter,@@ -148,7 +149,7 @@ async function searchOneDevice(invoke: deps.invoke,});const deviceRequest = requestForOrigin(origin, request);- const raw = await maker.searchConversations(deviceRequest);+ const raw = await maker.searchConversations(remoteConversationSearchRequest(deviceRequest));if (remoteIndexedSearchIgnoredWorkingDirs(raw, deviceRequest.filters?.workingDirs)) {return searchCachedDeviceSessions(origin, deviceRequest, deps.getCachedSessions());}diff --git a/packages/maker-shared/src/__tests__/conversationSearch.test.ts b/packages/maker-shared/src/__tests__/conversationSearch.test.tsindex 3a7c082163..ee15370de0 100644--- a/packages/maker-shared/src/__tests__/conversationSearch.test.ts+++ b/packages/maker-shared/src/__tests__/conversationSearch.test.ts@@ -1,17 +1,25 @@-import { describe, expect, it } from 'vitest';+import { afterEach, describe, expect, it, vi } from 'vitest';import {conversationSearchResultKey,emptyConversationSearchResponse,filterResultsByRequestFilters,filterResultsByWorkingDirs,mergeConversationSearchFanout,+ remoteConversationSearchRequest,remoteIndexedSearchIgnoredWorkingDirs,remoteResultsFromFanoutPages,stampRemoteSearchResponse,+ type ConversationSearchRequest,type ConversationSearchResponse,type ConversationSearchResultItem,} from '../conversationSearch.js';+const feature = vi.hoisted(() => ({ enabled: false }));+vi.mock('../cindyMakeFeature.js', async (importOriginal) => ({+ ...await importOriginal<typeof import('../cindyMakeFeature.js')>(),+ get CINDY_MAKE_ENABLED() { return feature.enabled; },+}));+function result(id: string,rankScore: number,@@ -50,6 +58,52 @@ function response(results: ConversationSearchResultItem[]): ConversationSearchRe};}+describe('remoteConversationSearchRequest', () => {+ afterEach(() => { feature.enabled = false; });++ it.each([undefined, 1, 3, 24, 50, 100])('uses the bounded remote candidate pool for limit %s', (limit) => {+ const request = { query: 'needle', limit };+ expect(remoteConversationSearchRequest(request)).toEqual({ query: 'needle', limit: 50 });+ expect(request.limit).toBe(limit);+ });++ it('preserves origin filters and search options without mutating the caller', () => {+ const request = Object.freeze<ConversationSearchRequest>({+ query: 'needle',+ limit: 3,+ sortBy: 'activityDesc',+ semanticMode: 'keyword',+ includeArchived: true,+ unnamedLabel: 'Untitled',+ filters: { sessionIds: ['ordinary'], workingDirs: ['/repo'], agentKind: 'pi', status: 'archived', lastActivity: '7d' },+ });+ const remoteRequest = remoteConversationSearchRequest(request);+ expect(remoteRequest).toEqual({ ...request, limit: 50 });+ expect(remoteRequest.filters).toBe(request.filters);+ expect(request.limit).toBe(3);+ });++ it('returns ordinary hits after an older host truncates the expanded request', () => {+ const request = { query: 'needle', limit: 1 };+ const candidates = [+ result('make', 100, { source: 'cindy-make', deviceLinkDeviceId: 'dev-a' }),+ result('merge', 99, { source: 'cindy-make-merge', deviceLinkDeviceId: 'dev-a' }),+ result('ordinary', 2, { source: 'desktop', deviceLinkDeviceId: 'dev-a' }),+ result('ordinary-next', 1, { source: 'desktop', deviceLinkDeviceId: 'dev-a' }),+ ];+ const remoteRequest = remoteConversationSearchRequest(request);+ const page = response(candidates.slice(0, remoteRequest.limit));+ expect(mergeConversationSearchFanout([page], request.limit).results.map((item) => item.session.id)).toEqual(['ordinary']);+ expect(remoteResultsFromFanoutPages([page]).map((item) => item.session.id)).toEqual(['ordinary', 'ordinary-next']);+ });++ it('leaves the original request unchanged when Cindy Make is enabled', () => {+ feature.enabled = true;+ const request = { query: 'needle', limit: 3 };+ expect(remoteConversationSearchRequest(request)).toBe(request);+ });+});+describe('merge and stamp', () => {it('excludes hidden Make sources before limiting indexed or reused remote hits', () => {const page = response([diff --git a/packages/maker-shared/src/conversationSearch.ts b/packages/maker-shared/src/conversationSearch.tsindex c829bbe591..88a248f92f 100644--- a/packages/maker-shared/src/conversationSearch.ts+++ b/packages/maker-shared/src/conversationSearch.ts@@ -114,6 +114,7 @@ const LAST_ACTIVITY_DAY_COUNTS: Record<'30d': 30,};const DAY_MS = 24 * 60 * 60 * 1000;+const REMOTE_CONVERSATION_SEARCH_LIMIT = 50;export function emptyConversationSearchResponse(query = ''): ConversationSearchResponse {return {@@ -125,6 +126,12 @@ export function emptyConversationSearchResponse(query = ''): ConversationSearchR};}+export function remoteConversationSearchRequest(+ request: ConversationSearchRequest,+): ConversationSearchRequest {+ return CINDY_MAKE_ENABLED ? request : { ...request, limit: REMOTE_CONVERSATION_SEARCH_LIMIT };+}+export function stampRemoteSearchResponse(response: ConversationSearchResponse,device: { deviceId: string; deviceName?: string | null },