import type { FsStat, MkdirOptions, RmOptions, CpOptions, FileContent, InitialFiles, IFileSystem } from "just-bash/browser"; /** * Supported buffer encodings (matches just-bash) */ type BufferEncoding = "utf8" | "utf-8" | "ascii" | "binary" | "base64" | "hex" | "latin1"; /** * Options for reading files (matches just-bash) */ interface ReadFileOptions { encoding?: BufferEncoding | null; } /** * Options for reading files with line scoping (for agent use) */ export interface ReadFileLineOptions { /** Line number to start reading from (0-based). Default: 0 */ offset?: number; /** Number of lines to read. Default: all remaining lines */ limit?: number; } /** * Options for editing files using string replacement */ export interface EditFileOptions { /** The text to replace */ oldString: string; /** The text to replace it with (must be different from oldString) */ newString: string; /** Replace all occurrences (default: false) */ replaceAll?: boolean; } /** * Options for writing files (matches just-bash) */ interface WriteFileOptions { encoding?: BufferEncoding; } /** * Directory entry with type information (matches just-bash DirentEntry) */ interface DirentEntry { name: string; isFile: boolean; isDirectory: boolean; isSymbolicLink: boolean; } /** * Options for creating a Filesystem instance */ export interface FilesystemOptions { /** Maximum total size in bytes (default: 50MB) */ maxSizeBytes?: number; /** Initial files to populate */ initialFiles?: InitialFiles; } /** * In-memory virtual filesystem for sandlot sandboxes. * * All operations are synchronous in-memory. Use `getFiles()` to export * the current state for persistence, and `initialFiles` to restore. * * @example * ```ts * // Create filesystem * const fs = Filesystem.create({ initialFiles: { '/src/index.ts': 'export const x = 1;' } }); * * // Use filesystem * fs.writeFile('/src/app.ts', 'console.log("hello")'); * * // Export for persistence * const files = fs.getFiles(); * localStorage.setItem('my-project', JSON.stringify(files)); * * // Later, restore * const saved = JSON.parse(localStorage.getItem('my-project')); * const fs2 = Filesystem.create({ initialFiles: saved }); * ``` */ export declare class Filesystem { private entries; private maxSizeBytes; private constructor(); /** * Create a new Filesystem instance */ static create(options?: FilesystemOptions): Filesystem; /** * Get all files as a serializable object. * * Returns a Record that can be JSON-serialized and * used as `initialFiles` when creating a new filesystem. * * Note: Only includes files, not directories (directories are * automatically created from file paths). Binary files are * base64-encoded with a `data:` prefix. * * @example * ```ts * const files = fs.getFiles(); * // { '/src/index.ts': 'export const x = 1;', '/package.json': '{"name":"app"}' } * * // Persist however you want * localStorage.setItem('project', JSON.stringify(files)); * * // Restore later * const saved = JSON.parse(localStorage.getItem('project')); * const fs2 = Filesystem.create({ initialFiles: saved }); * ``` */ getFiles(): Record; /** * Get approximate size of all stored data in bytes */ getSize(): number; /** * Read a file with optional line scoping. * Returns content with line numbers (cat -n format). * Lines longer than 2000 chars are truncated. * * @param path - Absolute path to the file * @param options - Optional offset (0-based line) and limit (line count) */ readFile(path: string, options?: ReadFileLineOptions): string; /** * Read raw file content without line numbers or formatting. * This is the internal method for getting actual file content. */ readFileRaw(path: string, options?: ReadFileOptions | BufferEncoding): string; /** * Edit a file using string replacement. * Fails if oldString is not found or found multiple times (unless replaceAll is true). * * @param path - Absolute path to the file * @param options - oldString, newString, and optional replaceAll flag */ editFile(path: string, options: EditFileOptions): void; readFileBuffer(path: string): Uint8Array; writeFile(path: string, content: FileContent, _options?: WriteFileOptions | BufferEncoding): void; appendFile(path: string, content: FileContent, options?: WriteFileOptions | BufferEncoding): void; exists(path: string): boolean; stat(path: string): FsStat; lstat(path: string): FsStat; mkdir(path: string, options?: MkdirOptions): void; readdir(path: string): string[]; readdirWithFileTypes(path: string): DirentEntry[]; rm(path: string, options?: RmOptions): void; cp(src: string, dest: string, options?: CpOptions): void; mv(src: string, dest: string): void; resolvePath(base: string, path: string): string; getAllPaths(): string[]; chmod(path: string, mode: number): void; symlink(target: string, linkPath: string): void; link(existingPath: string, newPath: string): void; readlink(path: string): string; realpath(path: string): string; utimes(path: string, atime: Date, mtime: Date): void; private normalizePath; private static normalizePath; private getParentPath; private ensureParentDirs; private static ensureParentDirs; private resolveSymlinks; private entryToStat; private getContentSize; private cloneEntry; private checkSizeLimit; private getEncoding; private decodeBuffer; private encodeBase64; private concatBuffers; private static parseFileInit; } /** * Create an in-memory filesystem. * * @param initialFiles - Optional initial files to populate the filesystem * @returns A new Filesystem instance */ export declare function createFilesystem(options?: FilesystemOptions): Filesystem; export declare function wrapFilesystemForJustBash(fs: Filesystem): IFileSystem; export {}; //# sourceMappingURL=fs.d.ts.map