/** * Bounded, no-follow, lossless UTF-8 source ingestion shared by `work create` * and `work amend-brief`. * * Policy (documented in docs/work.md): * - Never follow a symbolic link. The path is lstat'ed first and a link (or any * non-regular entry) is refused before it is opened. The open adds O_NOFOLLOW * where the platform has it (not on Windows); either way the opened * descriptor's device/inode must equal the lstat'ed entry (bigint, so large * Windows file IDs compare exactly), and the path is lstat'ed again after the * open: it must still be that same non-link entry. A swap to a link or another * file therefore fails closed. Residual (no O_NOFOLLOW, i.e. Windows): a link * that appears and disappears entirely between the two checks can only be * traversed to the verified file itself — never to different bytes. * - The opened descriptor must be a regular file. Directories, FIFOs, sockets, * and devices are rejected even when opening them succeeds. * - A pre-read size check rejects sources larger than the documented bound. * The descriptor read itself is capped at bound + 1 bytes, so a file that * grows after the size check is still rejected instead of unboundedly read. * - A post-read identity check fails closed on source swap or in-place growth: * device/inode must be unchanged, the final size must equal the bytes read, * and mtime must be unchanged. Virtual files that misreport size (st_size 0 * with readable content) are rejected as changed during read. * - Bytes decode as strict UTF-8 (fatal) and must round-trip exactly, so a * malformed sequence is never silently stored as U+FFFD. A leading UTF-8 BOM * is preserved as U+FEFF (it re-encodes to the original bytes); valid * Unicode and CRLF line endings pass through untouched. */ export declare const BRIEF_SOURCE_LIMIT = 1048576; export interface BriefSource { bytes: Buffer; text: string; digest: string; } export declare function sha256Bytes(value: Buffer): string; /** Test seams for the portable no-follow open; production callers pass nothing. */ export interface BriefSourceOpenOptions { /** Override the platform O_NOFOLLOW flag (`null` simulates a platform without it, e.g. Windows). */ noFollowFlag?: number | null; /** Runs between the lstat check and the open, to exercise swap races. */ afterLinkCheck?: () => void; } /** * Open one brief source without following symbolic links, verify it, and read * its exact bytes. Throws INVALID_INPUT before any caller publishes state. */ export declare function readBriefSourceBytes(source: string, displayPath: string, openOptions?: BriefSourceOpenOptions): BriefSource; /** * Read at most the limit plus one byte from an already verified descriptor, * then fail closed when the source changed identity or size mid-read. */ export declare function readBoundedBriefDescriptor(descriptor: number): Buffer; interface SourceIdentity { dev: number | bigint; ino: number | bigint; size: number; mtimeMs: number; } /** Fail closed when the descriptor no longer names the verified source bytes. */ export declare function assertStableSourceIdentity(before: SourceIdentity, after: SourceIdentity, bytesRead: number): void; /** Strictly decode source bytes; malformed input never becomes U+FFFD. */ export declare function decodeBriefSourceBytes(bytes: Buffer, displayPath: string): BriefSource; export {}; //# sourceMappingURL=brief-source.d.ts.map