/** * Pluggable filesystem backend. * * Mirrors `python/src/adk_fluent/_fs/`. Workspace tools route every I/O * call through a `FsBackend` so they can be unit-tested without a real * disk and re-targeted at in-memory or remote storage without touching * the tool code. * * Three concrete backends: * - `LocalBackend` — real on-disk I/O via Node's `fs` module. * - `MemoryBackend` — dict-backed fake for tests and ephemeral * scratch workspaces. POSIX semantics regardless of host OS. * - `SandboxedBackend` — decorator wrapping any backend with a * `SandboxPolicy`; refuses operations that would escape the * workspace. */ import type { SandboxPolicy } from "./sandbox.js"; /** * Node's `BufferEncoding` is a global type supplied by `@types/node`. * We re-declare it locally so `eslint`'s `no-undef` rule (which does not * know about ambient global types) stays quiet without sacrificing the * strongly-typed surface. */ type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "utf-16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex"; /** Minimal stat result returned by `FsBackend.stat()`. */ export interface FsStat { path: string; size: number; isDir: boolean; isFile: boolean; /** Modification time in milliseconds since epoch. */ mtime: number; } /** One entry produced by `FsBackend.listDir()`. */ export interface FsEntry { name: string; path: string; isDir: boolean; isFile: boolean; } /** * The subset of filesystem operations workspace tools need. * * A backend that wants to expose extras (random-access seeks, chunked * reads, partial writes) is free to do so through subclass-specific * methods, but the tools themselves never reach for anything outside * this interface. */ export interface FsBackend { exists(path: string): boolean; stat(path: string): FsStat; readText(path: string, options?: { encoding?: BufferEncoding; }): string; readBytes(path: string): Uint8Array; writeText(path: string, content: string, options?: { encoding?: BufferEncoding; }): void; writeBytes(path: string, content: Uint8Array): void; delete_(path: string): void; mkdir(path: string, options?: { parents?: boolean; existOk?: boolean; }): void; listDir(path: string): FsEntry[]; iterFiles(root: string): IterableIterator; glob(pattern: string, options?: { root?: string; }): string[]; } /** * `FsBackend` backed by Node's real filesystem via `node:fs`. * * This backend does **no** sandboxing. Wrap it with * `SandboxedBackend` to enforce a workspace scope. */ export declare class LocalBackend implements FsBackend { private readonly root; constructor(root?: string); private resolve; exists(target: string): boolean; stat(target: string): FsStat; readText(target: string, options?: { encoding?: BufferEncoding; }): string; readBytes(target: string): Uint8Array; writeText(target: string, content: string, options?: { encoding?: BufferEncoding; }): void; writeBytes(target: string, content: Uint8Array): void; delete_(target: string): void; mkdir(target: string, options?: { parents?: boolean; existOk?: boolean; }): void; listDir(target: string): FsEntry[]; iterFiles(root: string): IterableIterator; glob(pattern: string, options?: { root?: string; }): string[]; } /** * In-memory `FsBackend` for tests and ephemeral workspaces. * * Files are stored as `Uint8Array` in an internal map keyed by * normalised POSIX-style absolute path. Directories are tracked * separately so `listDir` can distinguish "empty dir" from "no such * dir". Internal semantics are POSIX regardless of host OS so tests * are portable across Linux/Mac/Windows. */ export declare class MemoryBackend implements FsBackend { private readonly files; private readonly dirs; private readonly mtimes; constructor(files?: Record); private static norm; exists(target: string): boolean; stat(target: string): FsStat; readText(target: string, options?: { encoding?: BufferEncoding; }): string; readBytes(target: string): Uint8Array; writeText(target: string, content: string, options?: { encoding?: BufferEncoding; }): void; writeBytes(target: string, content: Uint8Array): void; delete_(target: string): void; mkdir(target: string, options?: { parents?: boolean; existOk?: boolean; }): void; listDir(target: string): FsEntry[]; iterFiles(root: string): IterableIterator; glob(pattern: string, options?: { root?: string; }): string[]; } /** * Raised when a `SandboxedBackend` refuses an operation that would * escape the allowed workspace. */ export declare class SandboxViolation extends Error { constructor(message: string); } /** * Decorator wrapping any `FsBackend` with a `SandboxPolicy`. * * Every operation resolves its path through the policy and refuses * the call if the resolved path escapes the workspace. Read and write * operations route through `checkRead` / `checkWrite` respectively so * extra read/write paths supplied to the policy apply uniformly. */ export declare class SandboxedBackend implements FsBackend { private readonly innerBackend; private readonly sandboxPolicy; constructor(inner: FsBackend, sandbox: SandboxPolicy); get sandbox(): SandboxPolicy; get inner(): FsBackend; private checkRead; private checkWrite; exists(target: string): boolean; stat(target: string): FsStat; readText(target: string, options?: { encoding?: BufferEncoding; }): string; readBytes(target: string): Uint8Array; writeText(target: string, content: string, options?: { encoding?: BufferEncoding; }): void; writeBytes(target: string, content: Uint8Array): void; delete_(target: string): void; mkdir(target: string, options?: { parents?: boolean; existOk?: boolean; }): void; listDir(target: string): FsEntry[]; iterFiles(root: string): IterableIterator; glob(pattern: string, options?: { root?: string; }): string[]; } export {}; //# sourceMappingURL=fs.d.ts.map