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): 硬上限截断时整段保住伙伴回忆指引

zqchris31f2b70a71ef
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 f27bc4bb0f..a7a5cff1a8 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/agentHandoff.test.ts
@@ -130,6 +130,17 @@ describe('buildHandoffText', () => {
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('最近轮次逐字保留,更早轮次进单行提要', () => {
diff --git a/apps/desktop/src/main/maker-ipc/agentHandoff.ts b/apps/desktop/src/main/maker-ipc/agentHandoff.ts
index 6db539d978..1bb5018eee 100644
--- a/apps/desktop/src/main/maker-ipc/agentHandoff.ts
+++ b/apps/desktop/src/main/maker-ipc/agentHandoff.ts
@@ -636,12 +636,17 @@ function splitTrailingTerminator(text: string): [body: string, tail: string] {
* 英文 framing 比原中文长,触达上限更容易。
*/
const RETRIEVAL_SECTION_HEADING = '== Retrieving earlier verbatim history';
+/** 伙伴主对话的检索指引标题(按需回忆口径),同样属于必须整段保住的尾部。 */
+const RECALL_SECTION_HEADING = '== Recalling earlier history';
function splitMandatoryHandoffTail(text: string, opts: BuildHandoffOptions): {
body: string;
tail: string;
} {
- const retrievalAt = text.lastIndexOf(RETRIEVAL_SECTION_HEADING);
+ const retrievalAt = Math.max(
+ text.lastIndexOf(RETRIEVAL_SECTION_HEADING),
+ text.lastIndexOf(RECALL_SECTION_HEADING),
+ );
if (retrievalAt >= 0) {
return {
body: text.slice(0, retrievalAt).trimEnd(),