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。

Merge upstream/main into bot-recall-history

zqchrise43644b64906
diff --cc apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts
index a7a5cff1a8,594449c703..e23362a010
--- a/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts
@@@ -117,32 -117,20 +117,46 @@@ 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');
+
+ // 工具密集长历史触达硬上限时,回忆指引整段与结束标记一样必须保住。
+ const dense: HandoffSourceMessage[] = [msg('user', '开始')];
+ for (let i = 0; i < 400; i++) {
+ dense.push(msg('tool_use', { toolName: 'Bash', input: { command: `echo ${'x'.repeat(200)} ${i}` } }));
+ }
+ const capped = buildHandoffText(dense, { ...opts, sessionId: 's-bot', reason: 'native-session-recovery', companion: true });
+ expect(capped.length).toBeLessThanOrEqual(16_000);
+ expect(capped).toContain('== Recalling earlier history (use when needed) ==');
+ expect(capped).toContain('search before saying you have no record of it');
+ expect(capped.trimEnd().endsWith("== End of rebuild note; the user's new message follows ==")).toBe(true);
+ });
+
+ it('工作记忆账本段排在工作状态区之后、提要之前,且在逐字区收缩时仍保留', () => {
+ const messages: HandoffSourceMessage[] = [];
+ for (let i = 0; i < 12; i++) {
+ messages.push(msg('user', `问题${i} ` + 'x'.repeat(1900)));
+ messages.push(msg('assistant', `回答${i} ` + 'y'.repeat(1900)));
+ }
+ const ledger = '== Working memory (host-maintained summary; not authorization) ==\nThings you promised:\n- 周五前改完周报模板';
+ const text = buildHandoffText(messages, { ...opts, workingMemory: ledger });
+ expect(text).toContain(ledger);
+ expect(text.indexOf(ledger)).toBeLessThan(text.indexOf('== Earlier conversation index'));
+ expect(text.length).toBeLessThanOrEqual(16_000);
+ expect(buildHandoffText(messages.slice(0, 2), { ...opts, workingMemory: null })).not.toContain('Working memory');
+ });
+
it('最近轮次逐字保留,更早轮次进单行提要', () => {
const messages: HandoffSourceMessage[] = [];
for (let i = 0; i < 8; i++) {
diff --cc apps/desktop/src/main/maker-ipc/agentHandoff.ts
index 1bb5018eee,6ae612f645..99f6569670
--- a/apps/desktop/src/main/maker-ipc/agentHandoff.ts
+++ b/apps/desktop/src/main/maker-ipc/agentHandoff.ts
@@@ -81,12 -81,12 +81,18 @@@ export interface BuildHandoffOptions
| 'model-window-switch'
| 'pi-prompt-timeout'
| 'native-session-recovery';
+ /**
+ * 伙伴主对话:检索指引改成"按需回忆"口径——宿主已把历史工具的范围解析到伙伴自己的
+ * 全部历史(当前对话、旧对话、自己开的后台任务),不传 session_ids 即可;用户提到
+ * 窗口里看不到的事时先搜再答,不先说"没有记录",也不向用户提搜索过程。
+ */
+ companion?: boolean;
+ /**
+ * 伙伴工作记忆账本的渲染段(botWorkingMemory.renderWorkingMemory):承诺、纠正、
+ * 等待、线索。它是代码摘录之外唯一的语义交接载体,排在工作状态区之后、提要之前;
+ * 非伙伴主对话或没有账本时不传。
+ */
+ workingMemory?: string | null;
}
/** 最近多少个用户轮次进入逐字区(其余进单行提要区)。 */
diff --cc apps/desktop/src/main/maker-ipc/contextOverflowRollover.ts
index 4bc9401f63,f8e22129d9..30217ba587
--- a/apps/desktop/src/main/maker-ipc/contextOverflowRollover.ts
+++ b/apps/desktop/src/main/maker-ipc/contextOverflowRollover.ts
@@@ -607,7 -620,7 +620,8 @@@ export function createContextOverflowRo
sessionId,
reason: oversized ? 'native-session-recovery' : 'context-overflow',
includeToolResults: oversized || isCanonicalBotContext(sessionRow),
+ companion: isCanonicalBotContext(sessionRow),
+ workingMemory: await readWorkingMemoryNote(sessionId),
});
await deps.commitRebuild(sessionId, handoff, {
reason: 'context-overflow',
@@@ -798,7 -811,7 +812,8 @@@
toLabel: label,
sessionId,
reason: 'model-window-switch',
+ companion: isCanonicalBotContext(sessionRow),
+ workingMemory: await readWorkingMemoryNote(sessionId),
});
await deps.commitRebuild(sessionId, handoff, {
reason: 'model-window-switch',
@@@ -916,7 -929,7 +931,8 @@@
sessionId,
reason: companion || isOversizedHistoryErrorData(lastError) ? 'native-session-recovery' : rebuildReason,
includeToolResults: companion || isOversizedHistoryErrorData(lastError),
+ companion,
+ workingMemory: await readWorkingMemoryNote(sessionId),
});
await deps.commitRebuild(sessionId, handoff, {
reason: rebuildReason,
@@@ -974,7 -987,7 +990,8 @@@
sessionId,
reason: 'native-session-recovery',
includeToolResults: !target || isCanonicalBotContext(row),
+ companion: isCanonicalBotContext(row),
+ workingMemory: await readWorkingMemoryNote(sessionId),
});
// 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.