agentleFS
VercelKnown publishervercel-labs/node-vfs-polyfill/CLAUDE.md

node-vfs-polyfill

CLAUDE.md40 starsChanged 10 months agoMITView on GitHub

User-land implementation of the Node.js Virtual File System (VFS) based on nodejs/node#61478. This library allows mounting an in-memory filesystem that intercepts standard fs module calls through monkey-patching. Run a single test: We do not modify vendor/vfs-upstream/. The vendor directory contains code based on the upstream Node.js VFS PR. All extensions are layered on top via src/ and index.js. See UPSTREAM.md for details on our extensions.

  • Installs packages

The file

We split this CLAUDE.md into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run a single test:

    line 20
  2. Very specific:

    Mount-based Interception: When vfs.mount('/prefix') is called:

    line 48
  3. Very specific:

    Overlay Mode: When overlay: true, the VFS only handles paths that exist in the virtual filesystem, allowing real files to show through.

    line 54
  4. Distinctive:

    VFS File Descriptors: Start at 10000 to avoid conflicts with real OS file descriptors.

    line 56

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

User-land implementation of the Node.js Virtual File System (VFS) based on nodejs/node#61478. This library allows mounting an in-memory filesystem that intercepts standard fs module calls through monkey-patching.

Commands

pnpm install          # Install dependencies
pnpm test             # Run test suite
pnpm lint             # Check linting with Biome
pnpm lint:fix         # Fix linting issues
pnpm format           # Format code with Biome
pnpm knip             # Check for unused exports/dependencies

Run a single test:

node vendor/vfs-upstream/run-tests.js test-vfs-basic.js

Architecture

Design Principle

We do not modify vendor/vfs-upstream/. The vendor directory contains code based on the upstream Node.js VFS PR. All extensions are layered on top via src/ and index.js. See UPSTREAM.md for details on our extensions.

Core Components

  • index.js - Entry point that loads vendor classes and layers on extensions
  • vendor/vfs-upstream/lib/internal/vfs/file_system.js - VirtualFileSystem class (upstream)
  • vendor/vfs-upstream/lib/internal/vfs/provider.js - VirtualProvider base class (upstream)
  • vendor/vfs-upstream/lib/internal/vfs/providers/memory.js - MemoryProvider (upstream)
  • vendor/vfs-upstream/lib/internal/vfs/module_hooks.js - fs monkey-patching (upstream)
  • src/write-stream.js - VirtualWriteStream extension (our addition)
  • src/loader.js - Loads vendor modules with injected primordials/internalBinding
  • src/primordials.js - Shims for Node.js internal frozen built-ins
  • src/internal-binding.js - Shims for native bindings (UV errors, fs constants)
  • src/internal-modules.js - Shims for internal modules (errors, Stats, Dirent)

Key Design Patterns

  1. Provider Pattern: VirtualFileSystem delegates storage operations to a VirtualProvider. The MemoryProvider is the default, but custom providers (e.g., NFS, WebDAV) can be implemented.
  2. Mount-based Interception: When vfs.mount('/prefix') is called:
    • The VFS registers with module_hooks.js
    • All fs.* calls are intercepted
    • Paths under the mount point are routed to the VFS provider
    • Other paths fall through to the real filesystem
  3. Overlay Mode: When overlay: true, the VFS only handles paths that exist in the virtual filesystem, allowing real files to show through.
  4. VFS File Descriptors: Start at 10000 to avoid conflicts with real OS file descriptors.
  5. Layered Extensions: Extensions like WriteStream are added via prototype patching in index.js, keeping vendor code untouched.

File Structure

index.js                    # Entry point, wires extensions to upstream
src/
  loader.js                 # Module loader for vendor code
  primordials.js            # Node.js primordials shims
  internal-binding.js       # Native binding shims
  internal-modules.js       # Internal module shims (errors, Stats, etc.)
  write-stream.js           # VirtualWriteStream extension
vendor/vfs-upstream/
  lib/internal/vfs/         # Core VFS implementation (upstream)
    file_system.js          # VirtualFileSystem class
    provider.js             # VirtualProvider base class
    providers/memory.js     # MemoryProvider
    providers/real.js       # RealFSProvider
    module_hooks.js         # fs module interception
    file_handle.js          # File handle classes
    stats.js                # Stats creation
    errors.js               # Error factories
    streams.js              # VirtualReadStream
    watcher.js              # File watching
    router.js               # Path utilities
    fd.js                   # File descriptor management
  test/parallel/            # Tests
  run-tests.js              # Test runner

Documentation

  • UPSTREAM.md - Documents our extensions to upstream (WriteStream, etc.)
  • REVIEW.md - Code review with recommendations

Code Style

  • Biome for linting and formatting
  • Single quotes, semicolons, ES5 trailing commas
  • 2-space indentation
  • CommonJS modules (not ESM)
  • Requires Node.js >= 22.0.0

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.