mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-13 10:56:12 +00:00
* refactor(scripts): migrate JavaScript tools to TypeScript * fix(ci): keep changed-scope preflight zero-install * fix(ci): preserve zero-install script owners * fix(ci): complete script migration follow-through * fix(release): keep stable closeout zero-install * fix(scripts): preserve standalone execution boundaries * fix(scripts): repair standalone loader boundaries * fix(scripts): normalize gateway observation ids * fix(scripts): keep Docker packager standalone * test(scripts): preserve rebase cleanup helpers * test(sessions): use tracked temp directory
31 lines
878 B
TypeScript
31 lines
878 B
TypeScript
// Keeps child-process diagnostic tails byte-bounded without splitting UTF-8 characters.
|
|
|
|
function outputText(value: string | Buffer | null | undefined): string {
|
|
if (typeof value === "string") {
|
|
return value;
|
|
}
|
|
if (Buffer.isBuffer(value)) {
|
|
return value.toString("utf8");
|
|
}
|
|
return "";
|
|
}
|
|
|
|
function decodeUtf8Tail(buffer: Buffer): string {
|
|
let start = 0;
|
|
while (start < buffer.length && (buffer[start]! & 0b1100_0000) === 0b1000_0000) {
|
|
start += 1;
|
|
}
|
|
return buffer.subarray(start).toString("utf8");
|
|
}
|
|
|
|
export function outputTail(value: string | Buffer | null | undefined, maxBytes: number): string {
|
|
const text = outputText(value).trim();
|
|
if (!text) {
|
|
return "";
|
|
}
|
|
const bytes = Buffer.from(text, "utf8");
|
|
if (bytes.byteLength <= maxBytes) {
|
|
return text;
|
|
}
|
|
return decodeUtf8Tail(bytes.subarray(bytes.byteLength - maxBytes));
|
|
}
|