//#region src/compact/utils.ts
/**
* Shared utilities for the compact module — extracted so the runner
* (`compact.ts`) and the restoration helper (`restore.ts`) don't carry
* redundant copies of the same low-level math.
*
* Kept zero-dependency by design: no Node/Bun imports, no zidane types
* either. Both `utf8ByteLength` and `estimateTokens` are total
* functions of a single `string` argument, so they're trivially
* portable to a worker/browser context if the compact module ever
* needs to render outside Node.
*/
/**
* UTF-8 byte length, matching `Buffer.byteLength(text, 'utf-8')` but
* without pulling `node:buffer` for a one-liner. Stable for surrogate
* pairs — a high+low surrogate pair counts as a single 4-byte sequence
* (not 2 × 3-byte). Cheap to call in hot loops.
*
* Pure. Identical bytes for identical input across every JS runtime.
*/
function utf8ByteLength(text) {
	let bytes = 0;
	for (let i = 0; i < text.length; i++) {
		const code = text.charCodeAt(i);
		if (code < 128) bytes += 1;
		else if (code < 2048) bytes += 2;
		else if (code >= 55296 && code <= 56319) {
			bytes += 4;
			i++;
		} else bytes += 3;
	}
	return bytes;
}
/** Same constant Claude Code's `CONTEXT_MANAGEMENT.md` documents. */
const BYTES_PER_TOKEN = 4;
/**
* Approximate token count for `text`. Mirrors Claude Code's
* `BYTES_PER_TOKEN = 4` heuristic — acceptable for budget arithmetic
* (sizing summarization scopes, enforcing per-file caps in restoration).
*
* Accurate to ~10% on English + code. Use a real tokenizer when exact
* counts matter (cost reporting, hard caps); this is for budget gates
* where being off by 10% is fine.
*
* Pure. Exported so callers (TUI, SDK consumers) can do their own
* pre-budgeting against the same heuristic the harness uses internally.
*/
function estimateTokens(text) {
	return Math.ceil(text.length / 4);
}
//#endregion
export { estimateTokens as n, utf8ByteLength as r, BYTES_PER_TOKEN as t };

//# sourceMappingURL=utils-ngQzYzZD.js.map