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(bots): 搜索本机渠道任务并定位只读详情

xuzini-xzncf29285f79a6
diff --git a/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.ts b/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.ts
index b71dbf8b3a..72a579aaf2 100644
--- a/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.ts
+++ b/apps/desktop/src/main/localDb/__tests__/conversationSearch.test.ts
@@ -247,9 +247,11 @@ describe('conversationSearch plugin background tasks', () => {
});
// Production search entry + real SQLite. The prior source-only test could not
-// catch missing personal history or leaked imported channel lanes. Unit tier.
+// catch missing companion transcripts and accidentally exposed remote lanes. DB tier.
describe('conversationSearch personal companion chats', () => {
- it('finds hidden/archived personal threads and imported history, excluding internal lanes and deleted tasks', async () => {
+ // 测试价值: searchConversations 必须返回本机渠道记录并标成只读, 旧覆盖只验证渠道被排除。
+ // 最小输入: 一条渠道链接(含迁移来源)及同词消息; 验证远程、删除与群专线仍不放行。DB tier。
+ it('finds local channel transcripts like history while retaining remote and deletion boundaries', async () => {
const db = createSearchDb();
const client = makeSearchDbClient(db);
setCurrentDbClient(client, 'test-user');
@@ -265,6 +267,9 @@ describe('conversationSearch personal companion chats', () => {
['imported', 'feishu', 'history', 'archived'],
['group', 'bot', 'group', 'active'],
['channel', 'desktop', 'channel', 'active'],
+ ['feishu-channel', 'bot', 'channel', 'active'],
+ ['old-channel', 'feishu', 'channel', 'archived'],
+ ['deleted-channel', 'bot', 'channel', 'deleted'],
['deleted', 'bot', 'history', 'deleted'],
['task', 'desktop', 'delegation', 'active'],
['review', 'review', null, 'active'],
@@ -274,19 +279,49 @@ describe('conversationSearch personal companion chats', () => {
if (role) db.prepare('INSERT INTO bot_session_links VALUES (?, ?, ?)').run(id, 'bot', role);
}
const result = await searchConversations({ query: 'needle', semanticMode: 'keyword' });
- expect(result.results.map(item => item.session.id).sort()).toEqual(['imported', 'main', 'old', 'task']);
+ const localIds = ['channel', 'feishu-channel', 'imported', 'main', 'old', 'old-channel', 'task'];
+ expect(result.results.map(item => item.session.id).sort()).toEqual(localIds);
expect(result.results.find(item => item.session.id === 'old')?.session.companion).toEqual({
id: 'bot', name: 'Melody', role: 'history', readOnly: true,
});
expect(result.results.find(item => item.session.id === 'main')?.session.companion?.readOnly).toBe(false);
+ expect(result.results.find(item => item.session.id === 'feishu-channel')?.session.companion).toEqual({
+ id: 'bot', name: 'Melody', role: 'channel', readOnly: true,
+ });
expect(result.results.find(item => item.session.id === 'task')?.session.companion).toBeUndefined();
- expect(mocks.searchChatHistoryHybrid.mock.calls[0][0].sessionIds.sort()).toEqual(['imported', 'main', 'old', 'task']);
+ expect(mocks.searchChatHistoryHybrid.mock.calls[0][0].sessionIds.sort()).toEqual(localIds);
expect(mocks.searchChatHistoryHybrid.mock.calls[0][0].sessionSources).toBeNull();
+ const archived = await searchConversations({ query: 'needle', filters: { status: 'archived' } });
+ expect(archived.results.map(item => item.session.id).sort()).toEqual(['imported', 'old', 'old-channel']);
const remote = await searchConversations({ query: 'needle' }, { remoteVisibleOnly: true });
expect(remote.results.map(item => item.session.id)).toEqual(['task']);
db.exec("UPDATE bot_profiles SET hidden_at = NULL");
const visibleRemote = await searchConversations({ query: 'needle', filters: { status: 'archived' } }, { remoteVisibleOnly: true });
expect(visibleRemote.results.map(item => item.session.id).sort()).toEqual(['imported', 'old']);
+
+ // A content-only hit must retain its client id and read-only owner so the
+ // existing result handler can open history at the exact message.
+ db.prepare('INSERT INTO messages (id, client_id, session_id, role, content, created_at) VALUES (?, ?, ?, ?, ?, ?)')
+ .run('channel-message', 'channel-client', 'feishu-channel', 'assistant', 'contentneedle', 10);
+ mocks.searchChatHistoryHybrid.mockResolvedValue({
+ hits: [{ messageId: 'channel-message', sessionId: 'feishu-channel', role: 'assistant',
+ createdAt: 10, score: 1, ftsRank: 1, vectorRank: null,
+ context: [{ isHit: true, content: 'contentneedle' }] }],
+ sessions: {}, vectorUsed: false, vectorSkipReason: null,
+ nextOffset: null, hasMore: false, poolSize: 1, poolCapped: false,
+ });
+ const content = await searchConversations({ query: 'contentneedle', semanticMode: 'keyword' });
+ expect(content.results).toHaveLength(1);
+ expect(content.results[0]).toMatchObject({
+ matchKind: 'content',
+ session: { id: 'feishu-channel', companion: { role: 'channel', readOnly: true } },
+ contentHit: { messageId: 'channel-message', messageClientId: 'channel-client' },
+ });
+ const remoteContent = await searchConversations({ query: 'contentneedle' }, { remoteVisibleOnly: true });
+ expect(remoteContent.results).toEqual([]);
+ db.exec("UPDATE bot_profiles SET status = 'deleting'");
+ const deleting = await searchConversations({ query: 'needle' });
+ expect(deleting.results.some(item => ['channel', 'feishu-channel', 'old-channel'].includes(item.session.id))).toBe(false);
} finally {
clearCurrentDbClient(client);
db.close();
diff --git a/apps/desktop/src/main/localDb/conversationSearch.ts b/apps/desktop/src/main/localDb/conversationSearch.ts
index 9b232d1a92..7485a09037 100644
--- a/apps/desktop/src/main/localDb/conversationSearch.ts
+++ b/apps/desktop/src/main/localDb/conversationSearch.ts
@@ -347,7 +347,9 @@ async function listSearchableSessions(
? undefined
: or(gte(sessions.updatedAt, activityCutoff), gte(sessions.userSendAt, activityCutoff));
const personalChat = and(
- inArray(botSessionLinks.role, ['canonical', 'history']),
+ inArray(botSessionLinks.role, remoteVisibleOnly
+ ? ['canonical', 'history']
+ : ['canonical', 'history', 'channel']),
ne(botProfiles.status, 'deleting'),
);
return db
@@ -365,11 +367,16 @@ async function listSearchableSessions(
sessionSources === undefined
? or(inArray(sessions.source, DESKTOP_TASK_LIST_SESSION_SOURCES), personalChat)
: sessionSources === null ? undefined : inArray(sessions.source, sessionSources),
- // Migrated channel/group lanes may have an ordinary task source.
- or(isNull(botSessionLinks.role), and(
- ne(botSessionLinks.role, 'group'),
- ne(botSessionLinks.role, 'channel'),
- )),
+ // Group lanes remain private to their group. IM lanes are searchable on
+ // their own computer only, including migrated lanes with ordinary sources.
+ or(
+ isNull(botSessionLinks.role),
+ and(ne(botSessionLinks.role, 'group'), ne(botSessionLinks.role, 'channel')),
+ remoteVisibleOnly ? undefined : and(
+ eq(botSessionLinks.role, 'channel'),
+ ne(botProfiles.status, 'deleting'),
+ ),
+ ),
remoteVisibleOnly ? or(isNull(botProfiles.id), eq(botSessionLinks.role, 'delegation'), and(
or(isNull(botProfiles.hiddenAt), eq(botProfiles.hiddenAt, 0)),
ne(botProfiles.status, 'archived'),
@@ -441,12 +448,13 @@ function sessionSummaryFromRow(
orcaRole: row.orcaRole,
parentSessionId: row.parentSessionId,
...(row.companionId && row.companionName != null
- && (row.companionRole === 'canonical' || row.companionRole === 'history')
+ && (row.companionRole === 'canonical' || row.companionRole === 'history' || row.companionRole === 'channel')
? { companion: {
id: row.companionId,
name: row.companionName,
role: row.companionRole,
- readOnly: row.companionRole === 'history' || row.status !== 'active' || row.companionStatus !== 'active',
+ readOnly: row.companionRole === 'history' || row.companionRole === 'channel'
+ || row.status !== 'active' || row.companionStatus !== 'active',
} }
: {}),
userSendAt: row.userSendAt === null ? null : new Date(row.userSendAt).toISOString(),
diff --git a/apps/desktop/src/renderer/__tests__/conversationSearchBox.test.ts b/apps/desktop/src/renderer/__tests__/conversationSearchBox.test.ts
index 7d27bcc3ce..392dfc2a8d 100644
--- a/apps/desktop/src/renderer/__tests__/conversationSearchBox.test.ts
+++ b/apps/desktop/src/renderer/__tests__/conversationSearchBox.test.ts
@@ -754,14 +754,15 @@ describe('ConversationSearchBox live search', () => {
// Real search control: a hidden/unloaded companion must not fall back to an
// ordinary writable task, and the selected message anchor must survive. Unit tier.
-it.each(['canonical', 'history'] as const)('opens %s companion search results without the loaded roster', async role => {
+// 渠道结果同样必须使用现有历史路由与消息锚点; 不增加新 UI。既有个人历史覆盖缺少 channel。
+it.each(['canonical', 'history', 'channel'] as const)('opens %s companion search results without the loaded roster', async role => {
const hit = { messageId: 'message', messageClientId: 'client', role: 'assistant' as const,
createdAt: '2026-10-20T00:00:00Z', snippet: null, preview: 'needle reply', score: 1, ftsRank: 1, vectorRank: null };
vi.mocked(searchConversations).mockResolvedValue({ query: 'needle', results: [{
session: { id: 'chat', title: 'needle thread', workingDir: null, workspaceKind: 'dialogue',
agentKind: 'pi', status: role === 'history' ? 'archived' : 'active', source: 'bot',
userSendAt: null, updatedAt: '2026-10-20T00:00:00Z', createdAt: '2026-10-20T00:00:00Z', _count: { messages: 1 },
- companion: { id: 'bot', name: 'Melody', role, readOnly: role === 'history' } },
+ companion: { id: 'bot', name: 'Melody', role, readOnly: role !== 'canonical' } },
matchKind: 'content', titleMatchIndices: [], titleScore: null, contentHit: hit, contentHits: [hit], rankScore: 1,
}], vectorUsed: false, vectorSkipReason: null, poolCapped: false });
renderSearchBox();
@@ -771,7 +772,7 @@ it.each(['canonical', 'history'] as const)('opens %s companion search results wi
expect(result.textContent).toContain('Melody');
fireEvent.click(result);
await waitFor(() => expect(navigate).toHaveBeenCalledWith(
- role === 'history' ? '/bots/bot/history/chat' : '/bots/bot/session/chat',
+ role !== 'canonical' ? '/bots/bot/history/chat' : '/bots/bot/session/chat',
{ state: { searchJump: { kind: 'conversation-search', sessionId: 'chat', messageId: 'message', messageClientId: 'client' } } },
));
});
diff --git a/apps/desktop/src/shared/conversationSearch.ts b/apps/desktop/src/shared/conversationSearch.ts
index b25528e48f..327c6eb8d5 100644
--- a/apps/desktop/src/shared/conversationSearch.ts
+++ b/apps/desktop/src/shared/conversationSearch.ts
@@ -62,11 +62,11 @@ export interface ConversationSearchSessionSummary {
source?: SessionSource;
orcaRole?: ConversationSearchOrcaRole | null;
parentSessionId?: string | null;
- /** Host-verified personal companion chat; absent for ordinary/background tasks. */
+ /** Host-verified companion transcript; channel results are local-only and read-only. */
companion?: {
id: string;
name: string;
- role: 'canonical' | 'history';
+ role: 'canonical' | 'history' | 'channel';
readOnly: boolean;
};
userSendAt: string | null;
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 1de97d032d..699180f80d 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -62,6 +62,9 @@ Mobile 始终走原流程。Mobile 学到的这些结论绑定 device-link 连
既有 `local-db:conversations:search` 的结果 `session` 增加可选
`companion: { id, name, role: 'canonical' | 'history', readOnly }`。
归属由 Host 的 `bot_session_links` 关联确认;群聊与渠道专线不下发。
+本机搜索另允许渠道专线,并在 Desktop 本机结果中使用 `companion.role: 'channel'` 与 `readOnly: true`,
+沿用现有历史只读页及消息锚点。远程查询仍排除渠道专线,远程回包与 Mobile 消费的角色范围不变;
+不增加 IPC channel、请求参数或数据库字段。
`local-db:bots:get` 的远程精简资料增加个人 `sessions: [{ id, role, status }]`,
供控制端复核历史归属,不传提示词、工作目录或渠道配置。
搜索前按远程伙伴可见性筛选,缓存/排队回复投递时再次核查,保持原账号与隐藏边界。
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index 902caa324f..ce2edbcc00 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -243,10 +243,11 @@ tool 副作用时自动重放。原生后台工作尚未结束时不自动关闭
### 3.3 用户界面
-侧边栏全文搜索覆盖普通任务及伙伴个人主聊天、历史线程,默认包含归档历史。
+侧边栏全文搜索覆盖普通任务及伙伴个人主聊天、历史线程,本机还包含伙伴消息平台的渠道专线,默认包含归档历史。
搜索结果带伙伴姓名,点击后保持命中的线程与消息位置;不依赖伙伴在侧栏是否展开或已加载。
历史线程以伙伴身份只读打开,不切回当前主任务、不取消归档、不恢复发送队列。
-群聊/渠道内部专线不进入搜索;伙伴委派的普通后台任务保持普通任务入口。
+伙伴群聊内部专线不进入搜索;本机渠道专线的搜索结果沿用历史只读详情与消息定位,仍不进入普通任务列表,
+不因搜索恢复或归档任务。远程搜索继续排除渠道专线;伙伴委派的普通后台任务保持普通任务入口。
手机首页、设备页与任务抽屉采用同一结果归属与消息定位。远程仍遵守既有伙伴可见性:
整体隐藏或归档的伙伴只在所属电脑本地恢复,不能因新增搜索入口扩大远程权限。
实现见 `localDb/conversationSearch.ts`、`ConversationSearchBox.tsx` 与 Mobile