/** * Reserved setup path helpers and the shared private-write filesystem * primitives for the `hikoutei setup` CLI. * * Extracted as the dependency-free leaf of the CLI module graph so the * checkpoint module and the env-file writer can share these names without * importing each other (the previous checkpoint ↔ envFileWriter re-import * formed a benign but avoidable module cycle). This module imports only * ./errors.js for the setupPathSafetyError carrier factory and SETUP_ERROR_CODES. */ import { type Stats } from "node:fs"; /** Suffix of the fixed-name checkpoint sibling temp path. */ export declare const SETUP_STATE_TEMP_SUFFIX = ".tmp"; /** Suffix of the exclusive setup lock directory. */ export declare const SETUP_LOCK_SUFFIX = ".lock"; /** Atomic checkpoint temp path for a state file. */ export declare function setupStateTempPath(statePath: string): string; /** Exclusive setup lock path for a state file. */ export declare function setupLockPath(statePath: string): string; /** Canonical key path for credential-pool entry `index` (2-based). */ export declare function poolKeyPath(primaryKeyPath: string, index: number): string; /** `O_NOFOLLOW` where the platform defines it, else 0. */ export declare function noFollowFlag(): number; /** `O_NONBLOCK` where the platform defines it, else 0. */ export declare function nonBlockFlag(): number; export interface SetupStateWriteFs { openSync(path: string, flags: number, mode: number): number; fstatSync(fd: number): Stats; fchmodSync(fd: number, mode: number): void; /** * Descriptor write at a byte offset; returns the actual byte count written. * * `position` is `null` to write at (and advance) the current file * position. The contract matches `fs.writeSync(fd, buffer, offset, * length, position)` so the node implementation is assignable directly. */ writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number | null): number; fsyncSync(fd: number): void; closeSync(fd: number): void; lstatSync(path: string): Stats; unlinkSync(path: string): void; renameSync(from: string, to: string): void; /** * Opens the containing directory of a just-renamed file for its * durability fsync, with `O_NOFOLLOW`/`O_DIRECTORY` where the platform * defines them. */ openDirSync(path: string, flags: number): number; /** Fsyncs an open directory descriptor so a completed rename is durable. */ fsyncDirSync(fd: number): void; /** Never called by production; present so tests can prove the pathname chmod is unused. */ chmodSync(path: string, mode: number): void; } /** * The default filesystem for the private temp write; exported so callers * (and tests) can build an injected `SetupStateWriteFs` around the real * operations. */ export declare const defaultSetupStateWriteFs: SetupStateWriteFs; /** * Writes every UTF-8 byte of `content` to the descriptor, looping on short * writes. * * Works at the Buffer/byte level, so a partial write that splits a * multibyte character is still resumed at the exact byte offset and the * final content is byte-identical. A write that reports 0, a negative * value, a non-integer, or more bytes than remain is a safe failure (the * loop can never spin forever). Throws a SetupPathSafetyError with * SETUP_WRITE_NO_PROGRESS so the boundary catch preserves the specific * carrier code. */ export declare function writeAllSync(fd: number, content: string, write: SetupStateWriteFs["writeSync"]): void; /** * Fsyncs the containing directory of a just-renamed file so the rename is * durable across power loss. * * The `qualifier` selects the carrier code set ("checkpoint" for the state * file, "output" for the .env file) so the boundary catch preserves * machine-readable specificity per target path. Messages are byte-identical * regardless of qualifier. * * POSIX rename durability requires the directory entry change to be * flushed to stable storage; a directory fsync after the rename makes the * write-ahead checkpoint (and the `.env` output) survive a power loss. * The directory is opened WITHOUT following symlinks (`O_NOFOLLOW`) and * with `O_DIRECTORY` where the platform defines them, fsynced through the * descriptor, and closed exactly once. Open/fsync/close failures throw a * sanitized error; the caller must NOT roll back a completed rename — the * destination is already in place and the next run sees it. */ export declare function fsyncParentDirectory(parentPath: string, qualifier: "checkpoint" | "output", fs: SetupStateWriteFs): void; //# sourceMappingURL=setupPaths.d.ts.map