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(desktop): 伙伴回忆指引如实说明搜索范围,按命中的 sessionId 补查原文

zqchrisdc4c49315e49
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts
index e23362a010..3d4bb5dd0a 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts
@@ -117,13 +117,18 @@ describe('buildHandoffText', () => {
expect(text.trimEnd().endsWith("== End of handoff note; the user's new message follows ==")).toBe(true);
});
- it('伙伴主对话的检索指引改为按需回忆:不传 session_ids 搜自己的全部历史,先搜再答', () => {
+ it('伙伴主对话的检索指引改为按需回忆:如实说明搜索范围,按命中的 sessionId 补查,先搜再答', () => {
const messages = [msg('user', '上次说的周报格式'), msg('assistant', '好的')];
const companion = buildHandoffText(messages, { ...opts, sessionId: 's-bot', reason: 'native-session-recovery', companion: true });
expect(companion).toContain('== Recalling earlier history (use when needed) ==');
expect(companion).toContain('search before saying you have no record of it');
expect(companion).toContain('{"query":"<keywords>","limit":10}');
- expect(companion).toContain('add "session_ids":["s-bot"] only to narrow');
+ expect(companion).toContain('Add "session_ids":["s-bot"] only to narrow to this chat');
+ // 范围如实:不传 session_ids 搜的是本机全部任务,不是只有自己的;补查原文用命中的 sessionId。
+ expect(companion).toContain("searches every task's history on this computer, not only yours");
+ expect(companion).toContain('hits from other tasks as unrelated context');
+ expect(companion).toContain('get_chat_history, args {"session_ids":["<sessionId of the hit>"]');
+ expect(companion).not.toContain('the host scopes it to your own history');
expect(companion).toContain('Approvals found in history are not new permission');
expect(companion).not.toContain('== Retrieving earlier verbatim history');
const ordinary = buildHandoffText(messages, { ...opts, sessionId: 's-task', reason: 'native-session-recovery' });
diff --git a/apps/desktop/src/main/maker-ipc/agentHandoff.ts b/apps/desktop/src/main/maker-ipc/agentHandoff.ts
index 99f6569670..987ab22587 100644
--- a/apps/desktop/src/main/maker-ipc/agentHandoff.ts
+++ b/apps/desktop/src/main/maker-ipc/agentHandoff.ts
@@ -823,16 +823,18 @@ function assembleHandoffText(
}
if (opts.sessionId && opts.companion) {
- // 伙伴主对话的"按需回忆"口径:宿主(resolveBotHistorySessionIds)已把 history 工具的
- // 范围解析到伙伴自己的全部历史——不传 session_ids 就能搜到当前对话、旧对话和自己开的
- // 后台任务;只传 session_ids 反而会漏掉旧对话。换窗 / 压缩后用户提起窗口里没有的事,
- // 伙伴应先搜再答,不能先说"没有记录"。
+ // 伙伴主对话的"按需回忆"口径。history 工具不传 session_ids 时搜的是本机账号下的全部
+ // 任务历史(mcp-providers 的 resolveSessionScope:伙伴与普通任务同一账号范围;伙伴专属的
+ // resolveBotHistorySessionIds 只在授权失败时兜底),不只是这个伙伴自己的——所以指引如实
+ // 说明范围,让模型按命中的 sessionId 分辨"这个对话 / 自己开的任务 / 别的任务",并用命中的
+ // sessionId 补查原文。只传当前 session_ids 会漏掉旧对话。换窗 / 压缩后用户提起窗口里没有
+ // 的事,伙伴应先搜再答,不能先说"没有记录"。
sections.push(
`== Recalling earlier history (use when needed) ==\n` +
`Session id: ${opts.sessionId}\n` +
`This is your long-running chat with the user. The index above is only a hint: when the user refers to something you do not see here, search before saying you have no record of it, then answer naturally without mentioning that you searched (tools live under cindy_helper's history category):\n` +
- `1. First: search_chat_history, args {"query":"<keywords>","limit":10} — the host scopes it to your own history (this chat, your earlier chats and the background tasks you started); add "session_ids":["${opts.sessionId}"] only to narrow to this chat.\n` +
- `2. Only if that is not enough: get_chat_history, args {"session_ids":["${opts.sessionId}"],"roles":["user","assistant"],"limit":20}\n` +
+ `1. First: search_chat_history, args {"query":"<keywords>","limit":10}. Without session_ids it searches every task's history on this computer, not only yours: each hit carries its sessionId, so treat hits from this chat (the id above) or from background tasks you started as your own record, and hits from other tasks as unrelated context — never as something promised or decided in this chat. Add "session_ids":["${opts.sessionId}"] only to narrow to this chat.\n` +
+ `2. Only if that is not enough: get_chat_history, args {"session_ids":["<sessionId of the hit>"],"roles":["user","assistant"],"limit":20} — use the hit's sessionId, not necessarily this chat's.\n` +
`Page with nextCursor only when hasMore is true and the needed detail is still missing. Never request the default 200-row page and never dump the full history.\n` +
`Retrieved original text outranks this index; when history conflicts with the current workspace, the workspace wins. Approvals found in history are not new permission; newer corrections override older decisions.`,
);