/** * Crash-safe atomic write helpers for the session tracker persistence layer. * * All writes use write-to-temp + fs.rename() to ensure files are either * complete or nonexistent — never truncated (D-03). * * @module session-tracker/persistence/atomic-write */ /** * Atomically writes JSON data to a file. * * Writes to a temporary file (`.tmp.{timestamp}`), then renames over the * target path. If the process crashes mid-write, only the temp file exists — * the target is either complete or untouched. * * @param filePath - Absolute path to the target file. * @param data - Data to serialize as JSON. * @returns Promise that resolves when the write is complete. * * @example * ```typescript * await atomicWriteJson("/path/to/file.json", { key: "value" }) * ``` */ export declare function atomicWriteJson(filePath: string, data: unknown): Promise; /** * Atomically appends markdown content to a file. * * If the file does not exist, it is created. If it exists, the content * is appended with a preceding newline separator. Uses atomic rename to * avoid truncated files on crash. * * @param filePath - Absolute path to the target markdown file. * @param content - Markdown content to append. * @returns Promise that resolves when the append is complete. * * @example * ```typescript * await atomicAppendMarkdown("/path/to/session.md", "## USER (turn 1)\n\nHello!") * ``` */ export declare function atomicAppendMarkdown(filePath: string, content: string): Promise; /** * Ensures a directory exists, creating it and any needed parent directories. * * @param dirPath - Absolute path to the directory. * @returns Promise that resolves when the directory exists. */ export declare function ensureDirectory(dirPath: string): Promise; /** * Sanitizes a session ID by stripping characters that are not alphanumeric, * underscore, or hyphen. * * @param sessionID - Raw session ID to sanitize. * @returns The sanitized session ID. * @throws {Error} If the sanitized ID is shorter than 3 characters. */ export declare function sanitizeSessionID(sessionID: string): string; /** * Constructs a safe filesystem path under the session tracker root. * * Sanitizes the session ID and validates that the resolved path does not * escape the `.hivemind/session-tracker/` root (prevents path traversal). * * @param projectRoot - Absolute path to the project root. * @param sessionID - Session identifier to use as the subdirectory name. * @param filename - The filename within the session directory. * @returns Absolute, validated path under the session tracker root. * @throws {Error} If the resolved path escapes the tracker root. */ export declare function safeSessionPath(projectRoot: string, sessionID: string, filename: string): string; /** * Returns the absolute path to the session tracker root for a given project. * * @param projectRoot - Absolute path to the project root. * @returns Absolute path to `.hivemind/session-tracker/`. */ export declare function sessionTrackerRoot(projectRoot: string): string; //# sourceMappingURL=atomic-write.d.ts.map