MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / clipBytes

Function clipBytes

packages/agent-core/src/logging/formatter.ts:130–147  ·  view source on GitHub ↗
(text: string, maxBytes: number)

Source from the content-addressed store, hash-verified

128}
129
130function clipBytes(text: string, maxBytes: number): string {
131 if (Buffer.byteLength(text, 'utf-8') <= maxBytes) return text;
132 // Binary-search the longest prefix that fits.
133 let lo = 0;
134 let hi = text.length;
135 while (lo < hi) {
136 const mid = (lo + hi + 1) >> 1;
137 if (
138 Buffer.byteLength(text.slice(0, mid), 'utf-8') <=
139 maxBytes - Buffer.byteLength(TRUNCATED_TAIL, 'utf-8')
140 ) {
141 lo = mid;
142 } else {
143 hi = mid - 1;
144 }
145 }
146 return text.slice(0, lo) + TRUNCATED_TAIL;
147}
148
149function clipStack(stack: string): string {
150 if (Buffer.byteLength(stack, 'utf-8') <= STACK_MAX_BYTES) return stack;

Callers 2

clipStackFunction · 0.85
formatEntryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected