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): 四处历史恢复投影统一收紧;对账注入段限长

Kafeifeia3497cc62ece
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/planReconcile.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/planReconcile.test.ts
index 7ee858ce36..d81ead3354 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/planReconcile.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/planReconcile.test.ts
@@ -177,6 +177,21 @@ describe('buildPlanReconcileNote', () => {
expect(note).toContain('以下是用户的新消息');
});
+ it('clamps长步骤与步骤内换行,注入段大小与计划无关', () => {
+ // 步骤内容由模型自由生成、无长度约束:原样注入会让一份异常(或被诱导生成的)
+ // 计划显著占用下一轮上下文,极端情况把用户的真正问题挤过输入上限(review P2)。
+ const note = buildPlanReconcileNote({
+ openSteps: [`${'很长的步骤'.repeat(200)}\n第二行\n\n第三行`],
+ totalSteps: 1,
+ });
+ const stepLine = note.split('\n').find((line) => line.startsWith('- '));
+ expect(stepLine).toBeDefined();
+ // 换行折成空格 → 清单结构不被撑散;整行长度有界。
+ expect(stepLine!.length).toBeLessThanOrEqual(2 + 160 + 1);
+ expect(stepLine!.endsWith('…')).toBe(true);
+ expect(note.split('\n').filter((line) => line.startsWith('- ')).length).toBe(1);
+ });
+
it('caps the listed steps and notes the remainder', () => {
const note = buildPlanReconcileNote({
openSteps: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
diff --git a/apps/desktop/src/main/maker-ipc/planReconcile.ts b/apps/desktop/src/main/maker-ipc/planReconcile.ts
index cea9a8efa3..48d0fb9845 100644
--- a/apps/desktop/src/main/maker-ipc/planReconcile.ts
+++ b/apps/desktop/src/main/maker-ipc/planReconcile.ts
@@ -94,10 +94,30 @@ export function summarizeOpenPlan(
return { openSteps, totalSteps: insertion.todos.length };
}
+/** 最多列出的未完成步骤数,其余折成计数。 */
+const MAX_LISTED_STEPS = 6;
+/**
+ * 单条步骤文本的上限。步骤内容由模型自由生成、没有任何长度约束,原样注入会让
+ * 一份异常(或被提示诱导生成)的计划显著占用下一轮上下文,极端情况把用户的真正
+ * 问题挤过输入上限(review P2)。同时把步骤内换行折成空格——注入段用换行分隔
+ * 条目,步骤自带换行会把清单结构撑散。
+ */
+const MAX_STEP_TEXT_CHARS = 160;
+
+function clampStepText(step: string): string {
+ const collapsed = step.replace(/\s+/gu, ' ').trim();
+ return collapsed.length > MAX_STEP_TEXT_CHARS
+ ? `${collapsed.slice(0, MAX_STEP_TEXT_CHARS)}…`
+ : collapsed;
+}
+
/**
* 对账指示文本。三个出口穷尽所有情况(继续 / 修订 / 清掉),且明确授权删除——
* 不授权的话模型倾向于"计划不能丢",会把不相干的旧清单硬拖进新话题。
* 结尾用与 agentHandoff 同款的"以下是用户的新消息"边界,让正文归位。
+ *
+ * 注入段整体有界:最多 MAX_LISTED_STEPS 条 × MAX_STEP_TEXT_CHARS 字符 + 固定文案,
+ * 与计划本身的大小无关。
*/
export function buildPlanReconcileNote(summary: OpenPlanSummary): string {
// 全勾完但 turn 失败收尾的清单:没有未完成步骤可列,让 agent 确认后收口
@@ -110,9 +130,14 @@ export function buildPlanReconcileNote(summary: OpenPlanSummary): string {
'== 对账说明结束,以下是用户的新消息 ==',
].join('\n');
}
- const steps = summary.openSteps.slice(0, 6).map((step) => `- ${step}`).join('\n');
+ const steps = summary.openSteps
+ .slice(0, MAX_LISTED_STEPS)
+ .map((step) => `- ${clampStepText(step)}`)
+ .join('\n');
const more =
- summary.openSteps.length > 6 ? `\n(另有 ${summary.openSteps.length - 6} 项未列出)` : '';
+ summary.openSteps.length > MAX_LISTED_STEPS
+ ? `\n(另有 ${summary.openSteps.length - MAX_LISTED_STEPS} 项未列出)`
+ : '';
return [
'[计划对账]上一轮留有未完成的计划步骤:',
`${steps}${more}`,
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 29615ffed2..f33c1170f3 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -14466,7 +14466,8 @@ function mapServerMessages(serverMsgs: Message[]): ChatMessage[] {
...(typeof m.agentMeta?.model === 'string' && m.agentMeta.model
? { model: m.agentMeta.model }
: {}),
- ...(typeof m.agentMeta?.parentUuid === 'string' && m.agentMeta.parentUuid
+ ...(typeof m.agentMeta?.parentUuid === 'string' &&
+ isSubagentParentToolUseId(m.agentMeta.parentUuid)
? { parentToolUseId: m.agentMeta.parentUuid }
: {}),
};
@@ -14642,7 +14643,12 @@ function mapServerMessages(serverMsgs: Message[]): ChatMessage[] {
...(hookSource ? { hookSource } : {}),
// 子代理内部的 user 行(SDK parent_tool_use_id):投影给计划归属判定,
// 否则 maker-shared 会把它当成"用户开新话题"切断主线程计划 session。
- ...(typeof m.agentMeta?.parentUuid === 'string' && m.agentMeta.parentUuid
+ // 只提升 SDK tool-parent 形态:legacy Claude 导入把 transcript 链边
+ // (preceding-user-uuid 这类非 RFC 串)也存在 parentUuid 上,无条件提升会
+ // 反过来把**普通 user 行**当成子代理内部消息,新计划继续复用旧 session/key、
+ // 跨话题合并计划卡(review P1)。
+ ...(typeof m.agentMeta?.parentUuid === 'string' &&
+ isSubagentParentToolUseId(m.agentMeta.parentUuid)
? { parentToolUseId: m.agentMeta.parentUuid }
: {}),
};
@@ -14780,7 +14786,8 @@ function mapServerMessages(serverMsgs: Message[]): ChatMessage[] {
...(typeof m.agentMeta?.model === 'string' && m.agentMeta.model
? { model: m.agentMeta.model }
: {}),
- ...(typeof m.agentMeta?.parentUuid === 'string' && m.agentMeta.parentUuid
+ ...(typeof m.agentMeta?.parentUuid === 'string' &&
+ isSubagentParentToolUseId(m.agentMeta.parentUuid)
? { parentToolUseId: m.agentMeta.parentUuid }
: {}),
isStreaming: false,