Files
orca/src/shared/posix-printf-encoding.ts
T
Brennan Benson da3148053a fix: restore OMP commit messages and chat names (#34644)
* fix: deliver OMP generation prompts through owned files

* test: preserve the OMP contract suite entry point

* Preserve complete OMP generation prompts and retry owned cleanup

* Load OMP cleanup fixture module outside test timeout

* Deliver WSL generation prompts inside the execution guest

* Cover deadline expiry before WSL generation authorization
2026-10-28 20:55:13 -07:00

26 lines
894 B
TypeScript

export const POSIX_PRINTF_RECORD_MAX_BYTES = 1_024
const PRINTF_ESCAPED_BYTES = new Set([0x21, 0x27, 0x5c])
export function* encodePosixPrintfRecords(command: string): Generator<string> {
let chunk = ''
let chunkBytes = 0
for (const character of command) {
const codePoint = character.codePointAt(0)!
const isSafePrintableAscii =
codePoint >= 0x20 && codePoint <= 0x7e && !PRINTF_ESCAPED_BYTES.has(codePoint)
const encodedCharacter =
codePoint > 0x7f || isSafePrintableAscii
? character
: `\\0${codePoint.toString(8).padStart(3, '0')}`
const encodedBytes = codePoint > 0x7f ? Buffer.byteLength(character) : encodedCharacter.length
if (chunkBytes + encodedBytes > POSIX_PRINTF_RECORD_MAX_BYTES) {
yield chunk
chunk = ''
chunkBytes = 0
}
chunk += encodedCharacter
chunkBytes += encodedBytes
}
yield chunk
}