npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@aigne/afs-local-fs

v1.2.4

Published

AIGNE AFS module for local filesystem storage

Readme

@aigne/afs-local-fs

@aigne/afs-local-fs is an AFS module that provides local file system access for AI agents. It allows agents to browse, read, write, and search files in specified directories through the AFS virtual file system interface.

Overview

LocalFS mounts local directories into the AFS virtual file system, enabling AI agents to interact with your local files as if they were part of a unified file system. It provides sandboxed access with powerful search capabilities using ripgrep.

Features

  • Directory Mounting: Mount any local directory at a custom AFS path
  • File Operations: List, read, and write files with full metadata
  • Recursive Listing: Browse directories with configurable depth control
  • Fast Search: Lightning-fast text search using ripgrep
  • Glob Support: Pattern-based file matching
  • Metadata: File size, timestamps, permissions, and type information
  • Sandboxed Access: Operations are restricted to mounted directories
  • AI-Friendly: Designed for seamless AI agent integration

Installation

npm install @aigne/afs-local-fs @aigne/afs
# or
yarn add @aigne/afs-local-fs @aigne/afs
# or
pnpm add @aigne/afs-local-fs @aigne/afs

Quick Start

import { AFS } from "@aigne/afs";
import { LocalFS } from "@aigne/afs-local-fs";

// Create AFS instance
const afs = new AFS();

// Mount a local directory
afs.mount(new LocalFS({
  localPath: '/path/to/documentation',  // Local directory path
  description: 'Project documentation' // Description for AI
}));
// Accessible at /modules/local-fs

// List files
const { list } = await afs.list('/modules/local-fs');

// Read a file
const { result } = await afs.read('/modules/local-fs/README.md');
console.log(result.content);

// Search for content
const { list: results } = await afs.search('/modules/local-fs', 'installation');

// Write a file
await afs.write('/modules/local-fs/notes.txt', {
  content: 'My notes about the project'
});

Configuration

LocalFSOptions

interface LocalFSOptions {
  localPath: string;    // Local file system path to mount
  description?: string; // Optional description for AI agents
}

Example:

afs.mount(new LocalFS({
  localPath: '/Users/john/my-project',
  description: 'My web application source code'
}));
// Accessible at /modules/local-fs

Operations

list(path, options?)

List files and directories:

const { list, message } = await afs.list('/modules/local-fs', {
  maxDepth: 3  // Limit recursion depth
});

// list is an array of AFS entries:
[
  {
    id: '/modules/local-fs/README.md',
    path: '/modules/local-fs/README.md',
    createdAt: Date,
    updatedAt: Date,
    metadata: {
      type: 'file',      // 'file' or 'directory'
      size: 1024,        // File size in bytes
      mode: 33188        // Unix file permissions
    }
  },
  ...
]

Options:

  • maxDepth: Maximum recursion depth (default: 1)

read(path)

Read file contents and metadata:

const { result } = await afs.read('/modules/local-fs/README.md');

console.log(result.content);   // File contents as string
console.log(result.metadata);  // File metadata
console.log(result.createdAt); // Creation timestamp
console.log(result.updatedAt); // Last modified timestamp

Returns:

  • result.content: File contents (undefined for directories)
  • result.metadata: File information (type, size, mode)
  • result.createdAt: File creation time
  • result.updatedAt: Last modification time

write(path, content)

Write or update file contents:

const { result } = await afs.write('/modules/local-fs/notes.txt', {
  content: 'My notes',
  summary: 'Personal notes about the project',
  metadata: { category: 'personal' }
});

Features:

  • Automatically creates parent directories if needed
  • Supports string content directly
  • Supports object content (automatically JSON stringified)
  • Returns the written entry with updated metadata

search(path, query, options?)

Search for files containing specific text:

const { list, message } = await afs.search('/modules/local-fs', 'authentication');

// Results include matching files with context
list.forEach(entry => {
  console.log(entry.path);      // File path
  console.log(entry.summary);   // Matching line snippet
});

Features:

  • Uses ripgrep for extremely fast text search
  • Automatically deduplicates results
  • Returns file paths with matching line snippets

Integration with AI Agents

LocalFS integrates seamlessly with AIGNE agents:

import { AIAgent, AIGNE } from "@aigne/core";
import { AFS } from "@aigne/afs";
import { LocalFS } from "@aigne/afs-local-fs";
import { OpenAIChatModel } from "@aigne/openai";

// Setup AIGNE
const aigne = new AIGNE({
  model: new OpenAIChatModel({ apiKey: process.env.OPENAI_API_KEY })
});

// Setup AFS with LocalFS
const afs = new AFS();

afs.mount(new LocalFS({
  name: 'codebase',
  localPath: './src',
  description: 'Application source code'
}));
// Accessible at /modules/codebase

afs.mount(new LocalFS({
  name: 'docs',
  localPath: './docs',
  description: 'Project documentation'
}));
// Accessible at /modules/docs

// Create agent with AFS access
const agent = AIAgent.from({
  name: "code-assistant",
  instructions: "You are a helpful coding assistant with access to the codebase and documentation",
  afs: afs
});

// Use the agent
const context = aigne.newContext();
const result = await context.invoke(agent, {
  message: "Find all authentication-related files in the codebase"
});

The agent automatically gets these tools:

  • afs_list: Browse directories
  • afs_read: Read file contents
  • afs_write: Create or modify files
  • afs_search: Search for content

Multiple Mounts

You can mount multiple directories with different names:

// Mount source code
afs.mount(new LocalFS({
  name: 'src',
  localPath: './src',
  description: 'Application source code'
}));
// Accessible at /modules/src

// Mount tests
afs.mount(new LocalFS({
  name: 'tests',
  localPath: './tests',
  description: 'Test files'
}));
// Accessible at /modules/tests

// Mount configuration
afs.mount(new LocalFS({
  name: 'config',
  localPath: './config',
  description: 'Configuration files'
}));
// Accessible at /modules/config

// Now agents can access all mounted directories
await afs.list('/modules/src');
await afs.read('/modules/config/app.json');
await afs.search('/modules/tests', 'test suite');

File Metadata

LocalFS provides detailed file metadata:

const { result } = await afs.read('/modules/local-fs/README.md');

result.metadata = {
  type: 'file',           // 'file' or 'directory'
  size: 2048,            // File size in bytes
  mode: 33188            // Unix permissions (e.g., 0644)
}

result.createdAt  // File creation date
result.updatedAt  // Last modification date

Security Considerations

Sandboxed Access:

  • LocalFS operations are restricted to the mounted directory
  • Cannot access files outside the mounted path
  • Path traversal attempts are prevented by Node.js path operations

Best Practices:

  • Only mount directories that should be accessible to agents
  • Use descriptive mount paths (e.g., /readonly-docs, /workspace)
  • Consider file permissions when mounting sensitive directories
  • Review agent instructions to limit file write operations if needed

Ripgrep Integration

LocalFS uses ripgrep for high-performance text search:

  • Fast: Optimized for searching large codebases
  • Smart Filtering: Automatically ignores binary files
  • Accurate: Provides line-by-line match context
  • Reliable: Mature and widely-used search tool

Examples

See the LocalFS example for a complete working implementation.

TypeScript Support

This package includes full TypeScript type definitions:

import type { LocalFS, LocalFSOptions } from "@aigne/afs-local-fs";

Related Packages

License

Elastic-2.0