export type FileSystemEntryType = "file" | "directory" | "symlink"; export type BufferEncoding = | "utf8" | "utf-8" | "ascii" | "binary" | "base64" | "hex" | "latin1"; export type FileContent = string | Uint8Array; /** Stat result returned by FileSystem.stat / FileSystem.lstat. */ export interface FsStat { type: FileSystemEntryType; size: number; mtime: Date; mode?: number; } /** Directory entry returned by FileSystem.readdirWithFileTypes. */ export interface FileSystemDirent { name: string; type: FileSystemEntryType; } export interface MkdirOptions { recursive?: boolean; } export interface RmOptions { recursive?: boolean; force?: boolean; } export interface CpOptions { recursive?: boolean; } /** * Minimal filesystem abstraction. Both `InMemoryFs` and the * `WorkspaceFileSystem` adapter implement this interface so that * `FileSystemStateBackend` can wrap either one. * * Contracts: * - `readFile` / `readFileBytes` / `stat` / `lstat` throw `ENOENT` * when the path does not exist (never return null). * - `exists` never throws. * - `glob` returns absolute paths matching the pattern, sorted. */ export interface FileSystem { readFile(path: string): Promise; readFileBytes(path: string): Promise; writeFile(path: string, content: string): Promise; writeFileBytes(path: string, content: Uint8Array): Promise; appendFile(path: string, content: string | Uint8Array): Promise; exists(path: string): Promise; /** Follows symlinks. Throws ENOENT if path does not exist. */ stat(path: string): Promise; /** Does not follow the final symlink. Throws ENOENT if path does not exist. */ lstat(path: string): Promise; mkdir(path: string, options?: MkdirOptions): Promise; readdir(path: string): Promise; readdirWithFileTypes(path: string): Promise; rm(path: string, options?: RmOptions): Promise; cp(src: string, dest: string, options?: CpOptions): Promise; mv(src: string, dest: string): Promise; symlink(target: string, linkPath: string): Promise; readlink(path: string): Promise; realpath(path: string): Promise; resolvePath(base: string, path: string): string; glob(pattern: string): Promise; } // ── InMemoryFs constructor helpers ──────────────────────────────────── export interface ReadFileOptions { encoding?: BufferEncoding | null; } export interface WriteFileOptions { encoding?: BufferEncoding; } export interface FileEntry { type: "file"; content: string | Uint8Array; mode: number; mtime: Date; } export interface DirectoryEntry { type: "directory"; mode: number; mtime: Date; } export interface SymlinkEntry { type: "symlink"; target: string; mode: number; mtime: Date; } export interface LazyFileEntry { type: "file"; lazy: () => string | Uint8Array | Promise; mode: number; mtime: Date; } export type FsEntry = FileEntry | LazyFileEntry | DirectoryEntry | SymlinkEntry; export interface FileInit { content: FileContent; mode?: number; mtime?: Date; } export type LazyFileProvider = () => | string | Uint8Array | Promise; export type InitialFiles = Record< string, FileContent | FileInit | LazyFileProvider >;