Truncate tool summaries by code point
Claude-Session: https://claude.ai/code/session_01JtuZTCMW9TyogEmBgGf8JT
This commit is contained in:
@@ -23,4 +23,10 @@ describe("summarizeToolCall", () => {
|
||||
expect(long).toHaveLength(80);
|
||||
expect(long.endsWith("...")).toBe(true);
|
||||
});
|
||||
it("truncates by code point so a non-BMP character at the cut is not split", () => {
|
||||
const s = summarizeToolCall("bash", { command: "x".repeat(70) + "😀" + "y".repeat(20) });
|
||||
expect(s.endsWith("...")).toBe(true);
|
||||
expect(Array.from(s)).toHaveLength(80);
|
||||
expect(s).not.toMatch(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,5 +51,6 @@ export function summarizeToolCall(toolName: string, args: unknown): string {
|
||||
break;
|
||||
}
|
||||
const summary = detail ? `${toolName}: ${detail}` : toolName;
|
||||
return summary.length > SUMMARY_MAX ? `${summary.slice(0, SUMMARY_MAX - 3)}...` : summary;
|
||||
const chars = Array.from(summary);
|
||||
return chars.length > SUMMARY_MAX ? `${chars.slice(0, SUMMARY_MAX - 3).join("")}...` : summary;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user