/** * 编码 parity 批(docs/CC-TOOL-PARITY-SWEEP-2026-07.md P0)— file encoding + line-ending detection * for the Read/Edit/Write band, ported from CC's `utils/fileRead.ts` mechanism and hardened where CC * is lossy: * * - BOM detection: `FF FE` → utf16le, `EF BB BF` → utf8-with-BOM, else plain utf8. (CC 88→2.1.187 * dynamic-verified: detection is BOM-only; UTF-16BE / heuristic sniffing deliberately NOT done — * a wrong guess silently corrupts, and the BOM-less case stays a refusal at the Read layer.) * - The MODEL-FACING text is BOM-stripped and CRLF-normalized (CC parity: what the model quotes in * `old_string` must match what Read showed it). * - Write-back re-encodes with the ORIGINAL encoding, PRESERVES the BOM (CC drops it on Write — its * lossy face, dynamic-verified W1; we keep it, recorded as a deliberate improvement), and restores * the file's dominant line endings for Edit (Write keeps the model's endings as-is, CC decision). */ /** Detected byte-level encoding of a text file (BOM-driven; utf8 is the no-BOM default). */ export interface DetectedFileEncoding { encoding: "utf8" | "utf16le"; hadBom: boolean; } export type DetectedLineEndings = "CRLF" | "LF"; export interface DecodedTextFile { /** Model-facing text: BOM stripped, `\r\n` normalized to `\n`. The staleness-hash coordinate. */ text: string; encoding: DetectedFileEncoding; /** Dominant line ending of the ORIGINAL bytes (majority vote, CC detectLineEndings parity). * Deliberately NOT per-line lossless: a mixed-endings file is unified to the dominant ending on * the first edit (codex 镜头1/2 LOW, accepted non-goal — CC behaves the same way). */ endings: DetectedLineEndings; /** codex 双镜头 MED: a utf16le body with an ODD byte count is TRUNCATED/corrupt — decoding would * silently drop the dangling byte and a later write-back would destroy it permanently. Flagged so * the tool layer fails closed instead of "repairing" the file. */ malformed?: true; } /** BOM-only encoding detection (CC `detectEncodingForResolvedPath` parity — no content heuristics). */ export declare function detectFileEncoding(bytes: Uint8Array): DetectedFileEncoding; /** Decode file bytes into the model-facing normalized form + the metadata needed to write back losslessly. */ export declare function decodeTextBytes(bytes: Uint8Array): DecodedTextFile; /** * Re-encode text for writing back to a file that was decoded with {@link decodeTextBytes}. * * @param text normalized (`\n`) text when `endings` is CRLF/LF (Edit path — restore the file's * dominant endings); pass `endings:"preserve"` to write the text's OWN line endings untouched * (Write path — CC decision: the model sent explicit endings in `content` and meant them). * @returns a plain string for the no-BOM utf8 + LF-or-preserve fast path (byte-compatible with the * pre-batch writer), else the exact bytes (BOM + encoded body). */ export declare function encodeTextForFile(text: string, encoding: DetectedFileEncoding, endings: DetectedLineEndings | "preserve"): string | Uint8Array; /** Normalize model-supplied match/replacement text the same way the file text was normalized * (CC FileEditTool parity: `old_string`/`new_string` are CRLF-normalized before matching). */ export declare function normalizeEditText(s: string): string; //# sourceMappingURL=encoding.d.ts.map