@synet/fs-ai
Version:
AI-safe filesystem with path protection, audit trails, and consciousness integration
74 lines (73 loc) • 2.36 kB
TypeScript
/**
* @synet/fs-ai - AI-Safe Filesystem Adapter
*
* Simple, stateless adapter that provides AI safety through:
* - Home path for simplified AI navigation
* - Path allowlist/blocklist enforcement
* - Operation restrictions
* - Path traversal protection
* - Read-only mode support
*/
import type { IAsyncFileSystem } from "./async-filesystem.interface.js";
/**
* AI Safety Configuration
*/
export interface AISafetyConfig {
homePath?: string;
allowedPaths?: string[];
forbiddenPaths?: string[];
maxDepth?: number;
allowedOperations?: AIOperation[];
readOnly?: boolean;
}
/**
* AI filesystem operations
*/
export type AIOperation = "readFile" | "writeFile" | "exists" | "deleteFile" | "deleteDir" | "ensureDir" | "readDir" | "chmod";
/**
* AI-Safe Filesystem Adapter
*
* Stateless adapter that wraps any IAsyncFileSystem with AI safety restrictions.
* Can be composed with other filesystem adapters (caching, audit, etc.).
*/
export declare class AIFileSystem implements IAsyncFileSystem {
private readonly baseFileSystem;
private readonly config;
constructor(baseFileSystem: IAsyncFileSystem, config?: AISafetyConfig);
/**
* Resolve a path relative to the home directory
*/
private resolveFromHome;
/**
* Validate path is safe for AI access
*/
private validatePath; /**
* Validate operation is allowed
*/
private validateOperation;
readFile(path: string): Promise<string>;
writeFile(path: string, content: string): Promise<void>;
exists(path: string): Promise<boolean>;
deleteFile(path: string): Promise<void>;
createDir(path: string): Promise<void>;
ensureDir(path: string): Promise<void>;
deleteDir(path: string): Promise<void>;
chmod(path: string, mode: number): Promise<void>;
readDir(path: string): Promise<string[]>;
/**
* Get current AI safety configuration
*/
getSafetyConfig(): Required<AISafetyConfig>;
/**
* Check if operation is allowed
*/
isOperationAllowed(operation: AIOperation): boolean;
/**
* Check if path is allowed (without throwing)
*/
isPathAllowed(path: string): boolean;
}
/**
* Factory function to create AI-safe filesystem
*/
export declare function createAIFileSystem(baseFileSystem: IAsyncFileSystem, config?: AISafetyConfig): AIFileSystem;