export declare const RESULT_FENCE = "result"; export declare const DEFAULT_MAX_RESULT_CHARS = 16000; export interface ExtractResult { result: string; hadFence: boolean; } export interface WindowOpts { maxChars: number; offset?: number; limit?: number; tail?: boolean; } export interface WindowResult { text: string; truncated: boolean; totalChars: number; returnedChars: number; nextOffset?: number; } export interface EnvelopeOpts { truncated: boolean; returnedChars: number; totalChars: number; nextOffset?: number; spilledFile?: string; } export declare function extractResultBlock(fullText: string): ExtractResult; export declare function applyWindow(text: string, opts: WindowOpts): WindowResult; export declare function spillToFile(taskId: string, fullText: string, dir: string): string; export declare function formatResultEnvelope(opts: EnvelopeOpts): string; /** * Read a window from a sidecar file by CHARACTER offset and limit. * * `offset` and `limit` follow the `applyWindow` contract: both are character * counts (UTF-16 code units), never byte offsets. The file is read in full * and sliced by character, so multi-byte UTF-8 content (CJK, emoji, etc.) * is never split mid-sequence: returned windows are always precise * contiguous character slices with no replacement characters. * * @param sidecarPath - Absolute path to the sidecar file * @param offset - Character offset to start reading * @param limit - Maximum number of characters to return * @returns The windowed substring, or `null` if file is missing (ENOENT) */ export declare function readSidecarWindow(sidecarPath: string, offset: number, limit: number): string | null; /** * Read the last N characters from a sidecar file (tail mode). * * `tailChars` is a character count (UTF-16 code units), never a byte count. * The file is read in full and sliced by character, so multi-byte UTF-8 * content (CJK, emoji, etc.) is never split mid-sequence and the result is * always exactly `tailChars` characters when the file is long enough. * * @param sidecarPath - Absolute path to the sidecar file * @param tailChars - Number of characters to read from the end * @returns The last N characters, or `null` if file is missing */ export declare function readSidecarTail(sidecarPath: string, tailChars: number): string | null; /** * Apply windowing (offset/limit or tail) directly from a sidecar file. * Falls back to returning `null` when the sidecar file is missing. * * This is the sidecar-aware variant of `applyWindow`. The sidecar stores * the full session text; `totalChars` comes from `MaterializedResultRef.totalChars`. * `offset`, `limit`, `maxChars`, and `nextOffset` all follow the character * (UTF-16 code unit) contract of `applyWindow` — multi-byte UTF-8 content is * sliced precisely, never by byte. * * @param sidecarPath - Absolute path to the sidecar file * @param opts - Windowing options (offset, limit, tail, maxChars) * @param totalChars - Total character count of the materialized text * @returns A WindowResult, or `null` if the sidecar file is missing */ export declare function applySidecarWindow(sidecarPath: string, opts: WindowOpts, totalChars: number): WindowResult | null; /** * Check whether a sidecar file exists on disk. */ export declare function resultSidecarExists(sidecarPath: string): boolean; /** * Build the filesystem path for a result sidecar file. */ export declare function resultSidecarPath(taskId: string, dir: string): string; /** * Write result text to a sidecar file atomically. * Reuses the atomic-write pattern (`.tmp` + `unlinkSync` + `renameSync`). * Creates parent directories as needed. * Returns the absolute path to the written file. */ export declare function writeResultSidecar(taskId: string, fullText: string, dir: string): string; /** * Read result text from a sidecar file. * Returns `null` when the file does not exist (ENOENT) — never throws for missing files. */ export declare function readResultSidecar(sidecarPath: string): string | null; /** * Default retention period for orphan sidecar result files (24 hours). * Sidecar files are eligible for cleanup when the owning DispatchTask no longer * exists and the file's mtime is older than this threshold. */ export declare const ORPHAN_SIDECAR_RETENTION_MS = 86400000; /** * Scan the result sidecar directory and delete orphan files — sidecar files * whose corresponding DispatchTask no longer exists and whose mtime exceeds * the retention threshold. * * @param dir Workspace directory (containing .rolebox/state/results/) * @param knownTasks Known active task IDs (from the in-memory tasks map). * Files for unknown task IDs are eligible for deletion. * @param retentionMs Retention period in ms (defaults to 24h) * @returns Number of orphan files cleaned */ export declare function cleanupOrphanSidecars(dir: string, knownTasks: ReadonlySet | ReadonlyMap, retentionMs?: number): number; //# sourceMappingURL=result-extractor.d.ts.map