Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 伙伴换窗交接改用按需回忆的检索指引
zqchris78d9d889db53
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.tsindex b3457044a7..f27bc4bb0f 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts@@ -117,6 +117,21 @@ describe('buildHandoffText', () => {expect(text.trimEnd().endsWith("== End of handoff note; the user's new message follows ==")).toBe(true);});+ it('伙伴主对话的检索指引改为按需回忆:不传 session_ids 搜自己的全部历史,先搜再答', () => {+ 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('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' });+ expect(ordinary).toContain('== Retrieving earlier verbatim history (use when needed) ==');+ expect(ordinary).toContain('"session_ids":["s-task"],"limit":10');+ expect(ordinary).not.toContain('Recalling earlier history');+ });+it('最近轮次逐字保留,更早轮次进单行提要', () => {const messages: HandoffSourceMessage[] = [];for (let i = 0; i < 8; i++) {diff --git a/apps/desktop/src/main/maker-ipc/__tests__/contextOverflowRollover.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/contextOverflowRollover.test.tsindex 2b3f934d5e..6f20c2bb47 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/contextOverflowRollover.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/contextOverflowRollover.test.ts@@ -378,6 +378,9 @@ describe('createContextOverflowRollover', () => {expect(handoff).toContain('Keep the game keyboard accessible');expect(handoff).toContain('Saved index.html; keyboard test passed');expect(handoff).toContain('Next: add touch controls');+ // 伙伴主对话用"按需回忆"口径:宿主已按伙伴范围解析历史工具,不传 session_ids。+ expect(handoff).toContain('== Recalling earlier history (use when needed) ==');+ expect(handoff).toContain('{"query":"<keywords>","limit":10}');expect(handoff.length).toBeLessThanOrEqual(16_000);expect(deps.replayUserMessage).not.toHaveBeenCalled();// Persisted reset prevents another checkpoint after a cold restart.diff --git a/apps/desktop/src/main/maker-ipc/agentHandoff.ts b/apps/desktop/src/main/maker-ipc/agentHandoff.tsindex 52eee3c1d4..6db539d978 100644--- a/apps/desktop/src/main/maker-ipc/agentHandoff.ts+++ b/apps/desktop/src/main/maker-ipc/agentHandoff.ts@@ -81,6 +81,12 @@ export interface BuildHandoffOptions {| 'model-window-switch'| 'pi-prompt-timeout'| 'native-session-recovery';+ /**+ * 伙伴主对话:检索指引改成"按需回忆"口径——宿主已把历史工具的范围解析到伙伴自己的+ * 全部历史(当前对话、旧对话、自己开的后台任务),不传 session_ids 即可;用户提到+ * 窗口里看不到的事时先搜再答,不先说"没有记录",也不向用户提搜索过程。+ */+ companion?: boolean;}/** 最近多少个用户轮次进入逐字区(其余进单行提要区)。 */@@ -802,7 +808,21 @@ function assembleHandoffText(sections.push('== No new messages while you were away ==');}- if (opts.sessionId) {+ if (opts.sessionId && opts.companion) {+ // 伙伴主对话的"按需回忆"口径:宿主(resolveBotHistorySessionIds)已把 history 工具的+ // 范围解析到伙伴自己的全部历史——不传 session_ids 就能搜到当前对话、旧对话和自己开的+ // 后台任务;只传 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` ++ `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.`,+ );+ } else if (opts.sessionId) {// 早期原文检索指引:逐字窗口外的内容只剩单行提要,用户追问细节时模型必须能// 翻到原文。工具名 / 参数是确定性事实(@cindy/mcps xdt-helper,session_ids 过滤,// 两个工具均支持),写死在指引里比让模型自己发现可靠(规则 9)。diff --git a/apps/desktop/src/main/maker-ipc/contextOverflowRollover.ts b/apps/desktop/src/main/maker-ipc/contextOverflowRollover.tsindex 098c5d4d9b..4bc9401f63 100644--- a/apps/desktop/src/main/maker-ipc/contextOverflowRollover.ts+++ b/apps/desktop/src/main/maker-ipc/contextOverflowRollover.ts@@ -607,6 +607,7 @@ export function createContextOverflowRollover(deps: ContextOverflowRolloverDeps)sessionId,reason: oversized ? 'native-session-recovery' : 'context-overflow',includeToolResults: oversized || isCanonicalBotContext(sessionRow),+ companion: isCanonicalBotContext(sessionRow),});await deps.commitRebuild(sessionId, handoff, {reason: 'context-overflow',@@ -797,6 +798,7 @@ export function createContextOverflowRollover(deps: ContextOverflowRolloverDeps)toLabel: label,sessionId,reason: 'model-window-switch',+ companion: isCanonicalBotContext(sessionRow),});await deps.commitRebuild(sessionId, handoff, {reason: 'model-window-switch',@@ -914,6 +916,7 @@ export function createContextOverflowRollover(deps: ContextOverflowRolloverDeps)sessionId,reason: companion || isOversizedHistoryErrorData(lastError) ? 'native-session-recovery' : rebuildReason,includeToolResults: companion || isOversizedHistoryErrorData(lastError),+ companion,});await deps.commitRebuild(sessionId, handoff, {reason: rebuildReason,@@ -971,6 +974,7 @@ export function createContextOverflowRollover(deps: ContextOverflowRolloverDeps)sessionId,reason: 'native-session-recovery',includeToolResults: !target || isCanonicalBotContext(row),+ companion: isCanonicalBotContext(row),});// Durable handoff, SDK reset and complete target route succeed or fail together.// No user turn or tool call is replayed by this control-plane operation.