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-shared): count blank lines in Write/Edit diff stats

Zhao Dengfeng1fadcc491cd7
diff --git a/packages/maker-shared/src/__tests__/payloadSummary.test.ts b/packages/maker-shared/src/__tests__/payloadSummary.test.ts
index 2da665b853..7ac3b63c19 100644
--- a/packages/maker-shared/src/__tests__/payloadSummary.test.ts
+++ b/packages/maker-shared/src/__tests__/payloadSummary.test.ts
@@ -138,6 +138,10 @@ describe('payloadSummary', () => {
],
});
+ // 中间空行计入改动行;结尾换行不额外多算一行。
+ expect(buildPayloadToolDiff('Write', { file_path: '/repo/a.txt', content: 'a\n\nb' })?.insertions).toBe(3);
+ expect(buildPayloadToolDiff('Write', { file_path: '/repo/a.txt', content: 'a\n' })?.insertions).toBe(1);
+
expect(buildPayloadToolDiff('Read', { file_path: '/repo/app.ts' })).toBeUndefined();
expect(buildPayloadToolDiff('Edit', { old_string: 'a', new_string: 'b' })).toBeUndefined();
});
diff --git a/packages/maker-shared/src/payloadSummary.ts b/packages/maker-shared/src/payloadSummary.ts
index a9990b7ee0..a67fc16bc7 100644
--- a/packages/maker-shared/src/payloadSummary.ts
+++ b/packages/maker-shared/src/payloadSummary.ts
@@ -1242,5 +1242,8 @@ function createPayloadToolDiff(
function countPayloadChangedLines(value: string): number {
if (!value) return 0;
- return value.split('\n').filter((line) => line.length > 0).length || 1;
+ // 中间空行也是改动行;只去掉结尾换行切出的哨兵空段。
+ const lines = value.split('\n');
+ if (lines.length > 1 && lines[lines.length - 1] === '') lines.pop();
+ return lines.length;
}