fix(imessage): keep CLI stderr tails UTF-16 safe (#102626)

* fix(imessage): keep CLI stderr tail truncation UTF-16 safe

* test(imessage): hit stderr surrogate boundary

* fix(imessage): use plugin sdk text helper

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
wings1029 2026-07-09 22:04:07 +08:00 committed by GitHub
parent 11dda0e5fd
commit 4c55d46254
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -17,4 +17,11 @@ describe("iMessage CLI output bounds", () => {
expect(result).toBe("recent-error");
});
it("does not split a surrogate pair at the tail boundary", () => {
const input = `x🚀${"y".repeat(10)}`;
expect(input.slice(-11)).toBe(`\ude80${"y".repeat(10)}`);
expect(appendIMessageCliStderrTail("", input, 11)).toBe("y".repeat(10));
});
});

View file

@ -1,5 +1,6 @@
// Imessage plugin module implements cli output behavior.
import type { ChildProcessWithoutNullStreams } from "node:child_process";
import { sliceUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
const IMESSAGE_CLI_STDOUT_MAX_CHARS = 8 * 1024 * 1024;
const IMESSAGE_CLI_STDERR_TAIL_CHARS = 64 * 1024;
@ -50,5 +51,5 @@ export function appendIMessageCliStderrTail(
maxChars = IMESSAGE_CLI_STDERR_TAIL_CHARS,
): string {
const next = current + chunkToString(chunk);
return next.length > maxChars ? next.slice(-maxChars) : next;
return next.length > maxChars ? sliceUtf16Safe(next, -maxChars) : next;
}