@rcs-lang/file-system
Section titled “@rcs-lang/file-system”The @rcs-lang/file-system package provides a unified file system abstraction layer for all RCL tooling. It enables consistent file operations across different environments (Node.js, browser, virtual file systems) and platforms.
Installation
Section titled “Installation”bun add @rcs-lang/file-systemOverview
Section titled “Overview”This package offers:
- Cross-platform file operations - Works on Windows, macOS, and Linux
- Virtual file system support - For in-memory operations and testing
- Async and sync APIs - Choose based on your needs
- Path normalization - Handles path differences across platforms
- File watching - Monitor RCL files for changes
- Encoding support - UTF-8, UTF-16, and other encodings
Features
Section titled “Features”File System Abstraction
Section titled “File System Abstraction”import { FileSystem, createFileSystem } from '@rcs-lang/file-system';
// Create platform-specific file systemconst fs = createFileSystem();
// Read RCL fileconst content = await fs.readFile('/path/to/agent.rcl', 'utf8');
// Write compiled outputawait fs.writeFile('/path/to/output.json', JSON.stringify(compiled));
// Check if file existsif (await fs.exists('/path/to/config.rcl')) { // Process configuration}Virtual File System
Section titled “Virtual File System”Perfect for testing and browser environments:
import { createVirtualFileSystem } from '@rcs-lang/file-system';
const vfs = createVirtualFileSystem({ '/src/agent.rcl': 'agent CustomerSupport { ... }', '/src/messages.rcl': 'messages Messages { ... }'});
// Use like regular file systemconst files = await vfs.readdir('/src');console.log(files); // ['agent.rcl', 'messages.rcl']File Watching
Section titled “File Watching”Monitor RCL files for changes:
import { watchFiles } from '@rcs-lang/file-system';
const watcher = watchFiles('**/*.rcl', { onChange: (path, eventType) => { console.log(`File ${path} was ${eventType}`); // Recompile on change }, ignorePatterns: ['**/node_modules/**', '**/dist/**']});
// Stop watchingwatcher.close();Path Utilities
Section titled “Path Utilities”import { normalizePath, joinPath, relativePath, isAbsolute, getExtension} from '@rcs-lang/file-system';
// Normalize paths across platformsconst normalized = normalizePath('src\\agents\\customer.rcl');// Result: 'src/agents/customer.rcl'
// Join path segments safelyconst fullPath = joinPath(projectRoot, 'src', 'agents', 'customer.rcl');
// Get relative pathsconst rel = relativePath('/project/src', '/project/src/agents/customer.rcl');// Result: 'agents/customer.rcl'Workspace Discovery
Section titled “Workspace Discovery”Find RCL files in a workspace:
import { findRCLFiles, WorkspaceScanner } from '@rcs-lang/file-system';
// Find all RCL filesconst files = await findRCLFiles('/path/to/project', { recursive: true, includePatterns: ['**/*.rcl'], excludePatterns: ['**/test/**']});
// Advanced workspace scanningconst scanner = new WorkspaceScanner({ rootPath: '/path/to/project', fileTypes: ['.rcl', '.rcl.json']});
const workspace = await scanner.scan();console.log(workspace.files); // All RCL-related filesconsole.log(workspace.dependencies); // File dependenciesIntegration
Section titled “Integration”The file system package is used by:
- @rcs-lang/cli - Reading source files and writing output
- @rcs-lang/compiler - File I/O operations
- @rcs-lang/language-service - Workspace file management
- VSCode Extension - File operations in the editor
Configuration
Section titled “Configuration”interface FileSystemConfig { // Default encoding for text files encoding?: BufferEncoding;
// Enable file caching cache?: boolean;
// Maximum file size to read (in bytes) maxFileSize?: number;
// Follow symbolic links followSymlinks?: boolean;}
const fs = createFileSystem({ encoding: 'utf8', cache: true, maxFileSize: 10 * 1024 * 1024, // 10MB followSymlinks: true});Error Handling
Section titled “Error Handling”import { FileSystemError, isFileSystemError } from '@rcs-lang/file-system';
try { await fs.readFile('/path/to/file.rcl');} catch (error) { if (isFileSystemError(error)) { switch (error.code) { case 'ENOENT': console.error('File not found'); break; case 'EACCES': console.error('Permission denied'); break; default: console.error(`File system error: ${error.message}`); } }}API Reference
Section titled “API Reference”Main Interfaces
Section titled “Main Interfaces”FileSystem- Core file system interfaceVirtualFileSystem- In-memory file systemFileWatcher- File watching interfaceWorkspaceScanner- Workspace analysis
Factory Functions
Section titled “Factory Functions”createFileSystem(config?)- Create platform file systemcreateVirtualFileSystem(files?)- Create virtual file systemwatchFiles(pattern, options)- Start watching files
Path Utilities
Section titled “Path Utilities”normalizePath(path)- Normalize path separatorsjoinPath(...segments)- Join path segmentsrelativePath(from, to)- Get relative pathisAbsolute(path)- Check if path is absolutegetExtension(path)- Get file extension