/** * File system utilities for spec-kit * * Provides async file operations with custom error classes for * robust error handling in spec-kit operations. */ /** * Options for error construction with cause chaining. */ interface FsErrorOptions { cause?: unknown; } /** * Error thrown when a file or directory is not found. * * @example * ```typescript * throw new FileNotFoundError('Configuration file not found', '/path/to/config.json'); * ``` */ export declare class FileNotFoundError extends Error { readonly path?: string | undefined; readonly name = "FileNotFoundError"; readonly cause?: unknown; constructor(message: string, path?: string | undefined, options?: FsErrorOptions); } /** * Error thrown when file access is denied due to permissions. * * @example * ```typescript * throw new PermissionError('Cannot write to read-only file', '/path/to/file'); * ``` */ export declare class PermissionError extends Error { readonly path?: string | undefined; readonly name = "PermissionError"; readonly cause?: unknown; constructor(message: string, path?: string | undefined, options?: FsErrorOptions); } /** * Error thrown when no repository root is found. * * @example * ```typescript * throw new RepoNotFoundError('No git repository found', '/current/path'); * ``` */ export declare class RepoNotFoundError extends Error { readonly path?: string | undefined; readonly name = "RepoNotFoundError"; readonly cause?: unknown; constructor(message: string, path?: string | undefined, options?: FsErrorOptions); } /** * Check if a path exists. * * @param filePath - Path to check * @returns True if the path exists, false otherwise * * @example * ```typescript * if (await exists('/path/to/file')) { * console.log('File exists'); * } * ``` */ export declare function exists(filePath: string): Promise; /** * Check if a path is a directory. * * @param filePath - Path to check * @returns True if the path is a directory, false otherwise (including if path doesn't exist) * * @example * ```typescript * if (await isDirectory('/path/to/dir')) { * console.log('Path is a directory'); * } * ``` */ export declare function isDirectory(filePath: string): Promise; /** * Check if a path is a regular file. * * @param filePath - Path to check * @returns True if the path is a file, false otherwise (including if path doesn't exist) * * @example * ```typescript * if (await isFile('/path/to/file.txt')) { * console.log('Path is a file'); * } * ``` */ export declare function isFile(filePath: string): Promise; /** * Read a file as a UTF-8 string. * * @param filePath - Path to the file to read * @returns File contents as a string * @throws {FileNotFoundError} If the file doesn't exist * @throws {PermissionError} If access to the file is denied * * @example * ```typescript * const content = await readFile('/path/to/file.txt'); * console.log(content); * ``` */ export declare function readFile(filePath: string): Promise; /** * Write content to a file, creating parent directories if needed. * * @param filePath - Path to the file to write * @param content - Content to write * @throws {PermissionError} If access to the file is denied * * @example * ```typescript * await writeFile('/path/to/file.txt', 'Hello, world!'); * ``` */ export declare function writeFile(filePath: string, content: string): Promise; /** * Create a directory, optionally with all parent directories. * * @param dirPath - Path to the directory to create * @param recursive - Whether to create parent directories (default: true) * @throws {PermissionError} If access is denied * * @example * ```typescript * await mkdir('/path/to/new/dir'); * await mkdir('/path/to/new/dir', false); // Non-recursive * ``` */ export declare function mkdir(dirPath: string, recursive?: boolean): Promise; /** * List the contents of a directory. * * @param dirPath - Path to the directory to read * @returns Array of file and directory names * @throws {FileNotFoundError} If the directory doesn't exist * @throws {PermissionError} If access is denied * * @example * ```typescript * const files = await readDir('/path/to/dir'); * console.log(files); // ['file1.txt', 'file2.txt', 'subdir'] * ``` */ export declare function readDir(dirPath: string): Promise; /** * Find the repository root by looking for a .git directory. * * Traverses up from the start path looking for a .git directory. * * @param startPath - Path to start searching from (default: process.cwd()) * @returns Absolute path to the repository root * @throws {RepoNotFoundError} If no repository root is found * * @example * ```typescript * const repoRoot = await findRepoRoot(); * console.log(repoRoot); // '/path/to/repo' * * const otherRepo = await findRepoRoot('/path/to/subdir'); * ``` */ export declare function findRepoRoot(startPath?: string): Promise; export {}; //# sourceMappingURL=fs.d.ts.map