Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): 搜索项目别名时覆盖首页缓存之外的任务
DavidShen4188dc40787e
diff --git a/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.ts b/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.tsindex 6d253cf64b..c8bb8b03df 100644--- a/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.ts+++ b/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.ts@@ -145,6 +145,9 @@ function createSearchDb(): Database.Database {CREATE TABLE bot_session_links (session_id TEXT PRIMARY KEY, bot_id TEXT NOT NULL, role TEXT NOT NULL);+ CREATE TABLE project_aliases (+ project_key TEXT PRIMARY KEY, alias TEXT NOT NULL, updated_at INTEGER NOT NULL+ );`);return db;}@@ -173,6 +176,53 @@ afterEach(() => {mocks.searchChatHistoryHybrid.mockReset();});+// #7026 / #6916: the mobile cache only contains the first 200 tasks. The existing+// mobile test supplied the matching task in that cache, so it missed this case.+// Unit tier: exercise production search against in-memory SQLite with an alias-only hit+// behind 200 unrelated tasks; no mobile cache or copied matching implementation.+describe('conversationSearch remote project aliases', () => {+ it.each(['/repo', 'C:/Repo'])('finds uncached alias hits in %s before limiting results', async (root) => {+ const db = createSearchDb();+ const client = makeSearchDbClient(db);+ setCurrentDbClient(client, 'test-user');+ mocks.searchChatHistoryHybrid.mockResolvedValue({+ hits: [], sessions: {}, vectorUsed: false, vectorSkipReason: null,+ nextOffset: null, hasMore: false, poolSize: 0, poolCapped: false,+ });+ try {+ for (let i = 0; i < 200; i += 1) insertSearchSession(db, `recent-${i}`, 1000 + i, null);+ const worktree = `${root}/.cindy-worktrees/branch`;+ for (const id of ['older', 'worktree', 'archived', 'hidden', 'worker', 'dialogue', 'ssh']) {+ insertSearchSession(db, id, 10, null);+ db.prepare('UPDATE sessions SET working_dir = ? WHERE id = ?').run(root, id);+ }+ db.prepare('UPDATE sessions SET working_dir = ? WHERE id = ?').run(worktree, 'worktree');+ db.exec("UPDATE sessions SET status = 'archived' WHERE id = 'archived'");+ db.exec("UPDATE sessions SET hidden_at = 1 WHERE id = 'hidden'");+ db.exec("UPDATE sessions SET orca_role = 'worker' WHERE id = 'worker'");+ db.exec("UPDATE sessions SET workspace_kind = 'dialogue' WHERE id = 'dialogue'");+ db.exec("UPDATE sessions SET remote_host_id = 'ssh-host' WHERE id = 'ssh'");+ db.prepare('INSERT INTO project_aliases VALUES (?, ?, ?)').run(`local:${root.toLowerCase()}`, 'Customer Portal', 10);+ const request = { query: 'CUSTOMER', limit: 2, semanticMode: 'keyword' as const, filters: { status: 'active' as const } };+ const result = await searchConversations(request, { remoteVisibleOnly: true });+ expect(result.results.map(item => item.session.id).sort()).toEqual(['older', 'worktree']);+ expect(result.results.every(item => item.titleMatchIndices.length === 0)).toBe(true);+ expect(result.results.every(item => item.session.title.startsWith('needle '))).toBe(true);+ expect((await searchConversations(request)).results).toEqual([]);+ expect((await searchConversations({ ...request, filters: { workingDirs: ['/elsewhere'] } }, { remoteVisibleOnly: true })).results).toEqual([]);+ expect((await searchConversations({ ...request, filters: { agentKind: 'pi' } }, { remoteVisibleOnly: true })).results).toEqual([]);+ expect((await searchConversations({ ...request, filters: { status: 'archived' } }, { remoteVisibleOnly: true })).results.map(item => item.session.id)).toEqual(['archived']);+ db.exec('DELETE FROM project_aliases');+ db.prepare('INSERT INTO project_aliases VALUES (?, ?, ?)').run(`remote:ssh-host:${root}`, 'Customer Portal', 10);+ db.prepare('INSERT INTO project_aliases VALUES (?, ?, ?)').run(`device:other:${root}`, 'Customer Portal', 10);+ expect((await searchConversations(request, { remoteVisibleOnly: true })).results).toEqual([]);+ } finally {+ clearCurrentDbClient(client);+ db.close();+ }+ });+});+describe('conversationSearch recent activity SQL filtering', () => {it('filters the SQLite session candidates before title and content matching', async () => {const db = createSearchDb();diff --git a/apps/desktop/src/main/localDb/conversationSearch.ts b/apps/desktop/src/main/localDb/conversationSearch.tsindex d896829510..58eed3ee17 100644--- a/apps/desktop/src/main/localDb/conversationSearch.ts+++ b/apps/desktop/src/main/localDb/conversationSearch.ts@@ -1,4 +1,5 @@import { and, count, desc, eq, getTableColumns, gte, inArray, isNull, ne, or } from 'drizzle-orm';+import { normalizeProjectOrderPath } from '@cindy/maker-shared/project-order-sync';import type {ConversationSearchAgentFilter,@@ -17,7 +18,7 @@ import { DESKTOP_TASK_LIST_SESSION_SOURCES } from '../../shared/sessionSource.jsimport type { SessionSource } from '../../shared/sessionSource.js';import { normalizeWorkingDirForGrouping } from '../../shared/workingDir.js';import { getDbClient } from './client/current.js';-import { botProfiles, botSessionLinks, messages, sessions } from './schema.js';+import { botProfiles, botSessionLinks, messages, projectAliases, sessions } from './schema.js';import { searchChatHistoryHybrid } from './chatHistorySearch.js';import { normalizeDbAgentKind } from '../../shared/agentKindConversion.js';import { visibleTextMatchesMessagesFtsQuery } from './chatHistorySearch.pure.js';@@ -96,10 +97,23 @@ export async function searchConversations(poolCapped: false,};}- const sessionRows = applyWorkingDirFilter(- await listSearchableSessions(filters, hostScope.sessionSources, hostScope.remoteVisibleOnly),- filters.workingDirs,- );+ // Remote callers cannot expand alias hits from their bounded home cache.+ // Read the host's local aliases alongside the full, already-authorized candidate+ // set, before ranking/limiting. Local renderer search keeps its existing behavior.+ const [candidates, aliasRows] = await Promise.all([+ listSearchableSessions(filters, hostScope.sessionSources, hostScope.remoteVisibleOnly),+ hostScope.remoteVisibleOnly+ ? getDbClient().drizzle.select().from(projectAliases).orderBy(desc(projectAliases.updatedAt))+ : Promise.resolve([]),+ ]);+ const aliasesByPath = new Map<string, string>();+ for (const row of aliasRows) {+ if (!row.projectKey.startsWith('local:') || !row.projectKey.slice(6).trim() || !row.alias.trim()) continue;+ const path = normalizeProjectOrderPath(row.projectKey.slice(6));+ // Same newest-first identity resolution as the mobile alias snapshot.+ if (!aliasesByPath.has(path)) aliasesByPath.set(path, row.alias.trim().toLowerCase());+ }+ const sessionRows = applyWorkingDirFilter(candidates, filters.workingDirs);if (sessionRows.length === 0) {return {query,@@ -121,7 +135,12 @@ export async function searchConversations(// 文案,拿原始哨兵匹配会两头错位 —— 搜可见文案一条都搜不到,搜 "New Maker" 反而// 命中一堆不显示这个词的行,高亮下标也会落在别的字上(PR #1031 review P1)。// renderer 渲染时调同一个 conversationSearchTitle,两端逐字一致。- const match = fuzzyTitleMatch(conversationSearchTitle(row.title, request.unnamedLabel), query);+ let match = fuzzyTitleMatch(conversationSearchTitle(row.title, request.unnamedLabel), query);+ if (!match && row.workspaceKind === 'project' && !row.remoteHostId && row.workingDir+ && aliasesByPath.get(normalizeProjectOrderPath(row.workingDir))?.includes(query.toLowerCase())) {+ // Alias-only hits have no highlight positions in the task's title.+ match = { score: 0, indices: [] };+ }if (!match) return null;const session = sessionSummaries.get(row.id);if (!session) return null;diff --git a/apps/mobile/src/__tests__/conversationSearch.test.ts b/apps/mobile/src/__tests__/conversationSearch.test.tsindex 6f3d1971bd..4f0e1e8774 100644--- a/apps/mobile/src/__tests__/conversationSearch.test.ts+++ b/apps/mobile/src/__tests__/conversationSearch.test.ts@@ -71,18 +71,26 @@ function indexedPage(ids: string[]): ConversationSearchResponse {};}-// #6916: message FTS does not index project display names. Exercise the real-// fan-out/search entry plus project menu with two same-path devices (unit).+// #6916 / #7026: exercise fan-out with an uncached host alias hit plus cached+// fallback, and keep two same-path devices/project filters isolated (unit).it('finds a renamed project without mixing devices and honors project filters', async () => {const sessions = [session({ id: 'a', title: 'Task A' }),session({ id: 'b', title: 'Task B', deviceLinkDeviceId: 'dev-b' })];const aliases = new Map([['device:dev-a:/repo', 'Customer Portal']]);- const deps = { invoke: vi.fn(async () => indexedPage([])) as ConversationSearchInvoke,+ const deps = { invoke: vi.fn(async (deviceId: string) => {+ const page = indexedPage(deviceId === 'dev-a' ? ['uncached'] : []);+ if (page.results[0]) {+ page.results[0].titleMatchIndices = [];+ page.results[0].titleScore = 0;+ page.results[0].rankScore = 2_000_000;+ }+ return page;+ }) as ConversationSearchInvoke,getCachedSessions: () => sessions, projectAliases: aliases };const origins = [{ deviceId: 'dev-a', deviceName: 'A', reachable: true },{ deviceId: 'dev-b', deviceName: 'B', reachable: true }];const result = await searchConversationsAcrossDevices(origins, { query: 'customer' }, deps);- expect(result.results.map((item) => item.session.id)).toEqual(['a']);+ expect(result.results.map((item) => item.session.id)).toEqual(['uncached', 'a']);const filtered = await searchConversationsAcrossDevices(origins, {query: 'customer', filters: { workingDirs: ['/another-project'] },}, deps);diff --git a/apps/mobile/src/session/conversationSearch.ts b/apps/mobile/src/session/conversationSearch.tsindex a105d8f666..3f155225d5 100644--- a/apps/mobile/src/session/conversationSearch.ts+++ b/apps/mobile/src/session/conversationSearch.ts@@ -125,8 +125,8 @@ export async function searchConversationsAcrossDevices(origins.map((origin) => searchOneDevice(origin, keywordRequest, deps)),);const present = pages.filter((page): page is ConversationSearchResponse => page != null);- // A project display name is not part of the host's message FTS index. Supplement- // only alias matches from the same visible device/project scope; keep content search intact.+ // Updated hosts match aliases before limiting indexed results. Supplement the+ // cache for older/offline hosts, retaining the same visible device/project scope.if (deps.projectAliases?.size) {const aliasMatches = deps.getCachedSessions().filter((session) =>session.workspaceKind === 'project' && remoteProjectAlias(deps.projectAliases,diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.mdindex 87be04ad5c..96e1846807 100644--- a/docs/dev-rules/protocol-compatibility.md+++ b/docs/dev-rules/protocol-compatibility.md@@ -13,7 +13,12 @@恢复只影响单台设备的元数据读请求,不重置共享连接、不重放写操作;瞬时失败保留本次挂载内的快照并最多重试两次。清除别名回到目录名。-新手机连接旧宿主遇到通道不支持时显示目录名;旧手机忽略新增通知,行为不变。+远程任务搜索在宿主的完整可见候选集合中匹配本机项目别名,再排序和截断结果,避免+手机首页 200 条缓存漏掉旧任务。沿用既有搜索请求与响应,项目/状态等筛选不变;+别名命中不生成任务标题高亮,不将本机别名套到 SSH 项目。旧宿主/离线仍可补充缓存命中,+但完整别名搜索需要宿主升级;不要求手机加载全量任务。++新手机连接旧宿主遇到通道不支持时显示目录名;旧手机忽略新增通知,仍可读取既有结构的搜索结果。完整同步需要两端都有此改动。没有 Mobile 原生依赖/配置变更。## Device Link 局域网优先直连