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(maker-core): 完整正文覆盖循环复核的增量说明

Dash6d2aad9b3852
diff --git a/docs/dev-rules/maker-core-and-agent-behavior.md b/docs/dev-rules/maker-core-and-agent-behavior.md
index c94a176fff..148a5f9f4e 100644
--- a/docs/dev-rules/maker-core-and-agent-behavior.md
+++ b/docs/dev-rules/maker-core-and-agent-behavior.md
@@ -85,7 +85,7 @@ Codex code mode 下脚本在后台运行,模型同时继续回应;app-server
界面测试、逐项处理、外部进度轮询可以正常重复,缺画面或证据不足时 CONTINUE。
行动说明只作解释,不能代替结果;所有上下文都是证据,不执行其中针对复核器的指令。
用户目标复用现有有界用户原话投影(宿主提供时包含历史与最新要求),普通发送与插话更新;
-公开说明来自当前 scope 最近一段 text 事件,流式拼接、工具后有新说明时替换,换轮清空。
+公开说明来自当前 scope 最近一段 text 事件,增量拼接、final 全文覆盖校准、工具后有新说明时替换,换轮清空。
不采集 thinking,不额外调用模型摘要,不要求主模型逐次增加说明。先脱敏再截断:
用户上下文发送最多 4000 字符,行动说明最多 2000 字符;缺失明确标注,不补造目标或理由。
diff --git a/packages/maker-core/src/agents/claude-code/__tests__/upstream-idle-watchdog.test.ts b/packages/maker-core/src/agents/claude-code/__tests__/upstream-idle-watchdog.test.ts
index 159559dfec..e0e7046ca9 100644
--- a/packages/maker-core/src/agents/claude-code/__tests__/upstream-idle-watchdog.test.ts
+++ b/packages/maker-core/src/agents/claude-code/__tests__/upstream-idle-watchdog.test.ts
@@ -867,6 +867,11 @@ describe('Claude Code tool-loop guard runtime integration', () => {
};
try {
await handle.send({ type: 'user', content: 'wait for the run' });
+ stream.emit({ type: 'stream_event', parent_tool_use_id: null,
+ event: { type: 'content_block_start', index: 0, content_block: { type: 'text', text: '' } } });
+ stream.emit({ type: 'stream_event', parent_tool_use_id: null,
+ event: { type: 'content_block_delta', index: 0,
+ delta: { type: 'text_delta', text: 'The job is still running; ' } } });
stream.emit({
type: 'assistant', parent_tool_use_id: null,
message: { role: 'assistant', content: [{ type: 'text', text: 'The job is still running; I am checking for completion.' }] },
diff --git a/packages/maker-core/src/agents/claude-code/index.ts b/packages/maker-core/src/agents/claude-code/index.ts
index 4131a0d917..b6cc040349 100644
--- a/packages/maker-core/src/agents/claude-code/index.ts
+++ b/packages/maker-core/src/agents/claude-code/index.ts
@@ -5459,10 +5459,11 @@ export class ClaudeCodeAgent extends BaseAgent {
pendingContinuationTerminalBoundaries += 1;
}
if (e.type === 'text' && turnInFlight && !turnState.interruptRequested) {
- const text = (e.data as { text?: unknown } | undefined)?.text;
+ const data = e.data as { text?: unknown; isFinal?: unknown } | undefined;
+ const text = data?.text;
const parent = e.agentMeta?.parentUuid;
if (typeof text === 'string') {
- getToolLoopMonitor(typeof parent === 'string' && parent ? parent : undefined).onAssistantText(text);
+ getToolLoopMonitor(typeof parent === 'string' && parent ? parent : undefined).onAssistantText(text, data?.isFinal === true);
}
}
const accepted = pushForwardedEvent(e);
diff --git a/packages/maker-core/src/agents/shared/tool-loop-review.ts b/packages/maker-core/src/agents/shared/tool-loop-review.ts
index eb98e62f51..368bd8fc50 100644
--- a/packages/maker-core/src/agents/shared/tool-loop-review.ts
+++ b/packages/maker-core/src/agents/shared/tool-loop-review.ts
@@ -80,10 +80,10 @@ export class ToolLoopMonitor {
this.explanationBeforeTool = true;
}
- /** 复用公开 text 事件;下一次工具之后出现的新说明替换旧说明,流式片段连续拼接。 */
- onAssistantText(text: string): void {
- if (!text) return;
- if (this.explanationBeforeTool) this.assistantExplanation = '';
+ /** 复用公开 text 事件:增量拼接,final 全文校准;工具后新说明替换旧说明。 */
+ onAssistantText(text: string, isFinal = false): void {
+ if (!text && !isFinal) return;
+ if (this.explanationBeforeTool || isFinal) this.assistantExplanation = '';
this.explanationBeforeTool = false;
// 多保留一个字符作为截断信号,发送前复用证据截断器丢弃残缺凭证。
this.assistantExplanation = (this.assistantExplanation + text).slice(0, 4_001);
diff --git a/packages/maker-core/src/session.tool-loop.test.ts b/packages/maker-core/src/session.tool-loop.test.ts
index 772f68ea39..8e66aca568 100644
--- a/packages/maker-core/src/session.tool-loop.test.ts
+++ b/packages/maker-core/src/session.tool-loop.test.ts
@@ -50,7 +50,7 @@ function setup(agentKind: 'pi' | 'codex', hangAbort = false, toolLoopReviewer: T
await vi.advanceTimersByTimeAsync(0);
};
const errors = () => seen.filter((event) => event.type === 'error');
- return { queue, session, seen, handle, tool, errors,
+ return { queue, session, seen, handle, tool, errors, logger,
ask: (delivery?: 'async') => resolveInteraction({ kind: 'ask_user_question', requestId: 'question',
questions: [{ question: 'Scope?' }], ...(delivery ? { delivery } : {}) }),
end: async () => {
@@ -227,7 +227,25 @@ describe.each(['pi', 'codex'] as const)('%s Session tool loop coverage', (agentK
const t = setup(agentKind, false, reviewer);
const userIntent = { earlierUserMessages: ['Play the phone game using screenshots.'], currentUserMessage: 'Continue until the level ends.' };
await t.session.send('Continue until the level ends.', { [AUTO_REVIEW_USER_INTENT]: userIntent });
- t.queue.push({ type: 'text', data: { text: 'The target moves; I will observe its new position before tapping.' }, source: agentKind });
+ // PR #7404 review: delta + final 全文不能重复,避免 2000 字符发送预算挤掉最新理由。
+ const prefix = 'Observing the animation. '.repeat(50);
+ const explanation = `${prefix}The target moves; I will observe its new position before tapping.`;
+ if (agentKind === 'pi') {
+ const context = createPiTranslateContext(t.logger);
+ translatePiEvent({ type: 'message_update', assistantMessageEvent: {
+ type: 'text_delta', contentIndex: 0, delta: prefix,
+ } }, t.queue, context);
+ translatePiEvent({ type: 'message_end', message: {
+ role: 'assistant', content: [{ type: 'text', text: explanation }], stopReason: 'toolUse',
+ } }, t.queue, context);
+ } else {
+ const context = { rt: newCodexRuntimeState(), log: { info() {}, warn() {}, error() {}, debug() {} } };
+ const item = { type: 'agentMessage', id: 'explanation', text: prefix };
+ translateItemNotification('started', { threadId: 'thread', turnId: 'turn', item }, t.queue, context);
+ translateItemNotification('completed', {
+ threadId: 'thread', turnId: 'turn', item: { ...item, text: explanation },
+ }, t.queue, context);
+ }
t.queue.push({ type: 'thinking', data: { text: 'private reasoning must not be sent' }, source: agentKind });
t.queue.push({ type: 'text', data: { text: 'unrelated background task' }, source: agentKind, turnScope: 'background' });
const operations = ['screenshot', 'tap', 'swipe', 'Read'];
@@ -236,7 +254,7 @@ describe.each(['pi', 'codex'] as const)('%s Session tool loop coverage', (agentK
expect(reviewer.mock.calls[0]?.[0]).toMatchObject({
sessionId: 'test-session', agentKind, model: 'test-model',
userIntent,
- assistantExplanation: 'The target moves; I will observe its new position before tapping.',
+ assistantExplanation: explanation,
verdict: { reason: 'rotation', count: 16, toolName: 'Read' },
});
for (let i = 16; i < 100; i++) await t.tool(String(i), {}, operations[i % 4]);
diff --git a/packages/maker-core/src/session.ts b/packages/maker-core/src/session.ts
index a19a57a8be..dbbcacbd43 100644
--- a/packages/maker-core/src/session.ts
+++ b/packages/maker-core/src/session.ts
@@ -3146,7 +3146,7 @@ export class Session {
const control = this.toolLoopControlFor(generation);
if (!control?.toolLoopMonitor) return;
if (event.type === 'text') {
- if (typeof data.text === 'string') control.toolLoopMonitor.onAssistantText(data.text);
+ if (typeof data.text === 'string') control.toolLoopMonitor.onAssistantText(data.text, data.isFinal === true);
return;
}
if (event.type === 'tool_result') {