@aigne/afs-fs 1.11.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,26 @@
1
+ # Proprietary License
2
+
3
+ Copyright (c) 2024-2025 ArcBlock, Inc. All Rights Reserved.
4
+
5
+ This software and associated documentation files (the "Software") are proprietary
6
+ and confidential. Unauthorized copying, modification, distribution, or use of
7
+ this Software, via any medium, is strictly prohibited.
8
+
9
+ The Software is provided for internal use only within ArcBlock, Inc. and its
10
+ authorized affiliates.
11
+
12
+ ## No License Granted
13
+
14
+ No license, express or implied, is granted to any party for any purpose.
15
+ All rights are reserved by ArcBlock, Inc.
16
+
17
+ ## Public Artifact Distribution
18
+
19
+ Portions of this Software may be released publicly under separate open-source
20
+ licenses (such as MIT License) through designated public repositories. Such
21
+ public releases are governed by their respective licenses and do not affect
22
+ the proprietary nature of this repository.
23
+
24
+ ## Contact
25
+
26
+ For licensing inquiries, contact: legal@arcblock.io
package/README.md ADDED
@@ -0,0 +1,337 @@
1
+ # @aigne/afs-fs
2
+
3
+ **@aigne/afs-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.
4
+
5
+ ## Overview
6
+
7
+ AFSFS 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.
8
+
9
+ ## Features
10
+
11
+ - **Directory Mounting**: Mount any local directory at a custom AFS path
12
+ - **File Operations**: List, read, and write files with full metadata
13
+ - **Recursive Listing**: Browse directories with configurable depth control
14
+ - **Fast Search**: Lightning-fast text search using ripgrep
15
+ - **Glob Support**: Pattern-based file matching
16
+ - **Metadata**: File size, timestamps, permissions, and type information
17
+ - **Sandboxed Access**: Operations are restricted to mounted directories
18
+ - **AI-Friendly**: Designed for seamless AI agent integration
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install @aigne/afs-fs @aigne/afs
24
+ # or
25
+ yarn add @aigne/afs-fs @aigne/afs
26
+ # or
27
+ pnpm add @aigne/afs-fs @aigne/afs
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ```typescript
33
+ import { AFS } from "@aigne/afs";
34
+ import { AFSFS } from "@aigne/afs-fs";
35
+
36
+ // Create AFS instance
37
+ const afs = new AFS();
38
+
39
+ // Mount a local directory
40
+ afs.mount(
41
+ new AFSFS({
42
+ localPath: "/path/to/documentation", // Local directory path
43
+ description: "Project documentation", // Description for AI
44
+ }),
45
+ );
46
+ // Accessible at /modules/fs
47
+
48
+ // List files
49
+ const { list } = await afs.list("/modules/fs");
50
+
51
+ // Read a file
52
+ const { result } = await afs.read("/modules/fs/README.md");
53
+ console.log(result.content);
54
+
55
+ // Search for content
56
+ const { list: results } = await afs.search("/modules/fs", "installation");
57
+
58
+ // Write a file
59
+ await afs.write("/modules/fs/notes.txt", {
60
+ content: "My notes about the project",
61
+ });
62
+ ```
63
+
64
+ ## Configuration
65
+
66
+ ### AFSFSOptions
67
+
68
+ ```typescript
69
+ interface AFSFSOptions {
70
+ localPath: string; // Local file system path to mount
71
+ description?: string; // Optional description for AI agents
72
+ }
73
+ ```
74
+
75
+ **Example:**
76
+
77
+ ```typescript
78
+ afs.mount(
79
+ new AFSFS({
80
+ localPath: "/Users/john/my-project",
81
+ description: "My web application source code",
82
+ }),
83
+ );
84
+ // Accessible at /modules/fs
85
+ ```
86
+
87
+ ## Operations
88
+
89
+ ### list(path, options?)
90
+
91
+ List files and directories:
92
+
93
+ ```typescript
94
+ const { list, message } = await afs.list('/modules/fs', {
95
+ maxDepth: 3 // Limit recursion depth
96
+ });
97
+
98
+ // list is an array of AFS entries:
99
+ [
100
+ {
101
+ id: '/modules/fs/README.md',
102
+ path: '/modules/fs/README.md',
103
+ createdAt: Date,
104
+ updatedAt: Date,
105
+ metadata: {
106
+ type: 'file', // 'file' or 'directory'
107
+ size: 1024, // File size in bytes
108
+ mode: 33188 // Unix file permissions
109
+ }
110
+ },
111
+ ...
112
+ ]
113
+ ```
114
+
115
+ **Options:**
116
+
117
+ - `maxDepth`: Maximum recursion depth (default: 1)
118
+
119
+ ### read(path)
120
+
121
+ Read file contents and metadata:
122
+
123
+ ```typescript
124
+ const { result } = await afs.read("/modules/fs/README.md");
125
+
126
+ console.log(result.content); // File contents as string
127
+ console.log(result.metadata); // File metadata
128
+ console.log(result.createdAt); // Creation timestamp
129
+ console.log(result.updatedAt); // Last modified timestamp
130
+ ```
131
+
132
+ **Returns:**
133
+
134
+ - `result.content`: File contents (undefined for directories)
135
+ - `result.metadata`: File information (type, size, mode)
136
+ - `result.createdAt`: File creation time
137
+ - `result.updatedAt`: Last modification time
138
+
139
+ ### write(path, content)
140
+
141
+ Write or update file contents:
142
+
143
+ ```typescript
144
+ const { result } = await afs.write("/modules/fs/notes.txt", {
145
+ content: "My notes",
146
+ summary: "Personal notes about the project",
147
+ metadata: { category: "personal" },
148
+ });
149
+ ```
150
+
151
+ **Features:**
152
+
153
+ - Automatically creates parent directories if needed
154
+ - Supports string content directly
155
+ - Supports object content (automatically JSON stringified)
156
+ - Returns the written entry with updated metadata
157
+
158
+ ### search(path, query, options?)
159
+
160
+ Search for files containing specific text:
161
+
162
+ ```typescript
163
+ const { list, message } = await afs.search(
164
+ "/modules/fs",
165
+ "authentication",
166
+ );
167
+
168
+ // Results include matching files with context
169
+ list.forEach((entry) => {
170
+ console.log(entry.path); // File path
171
+ console.log(entry.summary); // Matching line snippet
172
+ });
173
+ ```
174
+
175
+ **Features:**
176
+
177
+ - Uses ripgrep for extremely fast text search
178
+ - Automatically deduplicates results
179
+ - Returns file paths with matching line snippets
180
+
181
+ ## Integration with AI Agents
182
+
183
+ AFSFS integrates seamlessly with AIGNE agents:
184
+
185
+ ```typescript
186
+ import { AIAgent, AIGNE } from "@aigne/core";
187
+ import { AFS } from "@aigne/afs";
188
+ import { AFSFS } from "@aigne/afs-fs";
189
+ import { OpenAIChatModel } from "@aigne/openai";
190
+
191
+ // Setup AIGNE
192
+ const aigne = new AIGNE({
193
+ model: new OpenAIChatModel({ apiKey: process.env.OPENAI_API_KEY }),
194
+ });
195
+
196
+ // Setup AFS with AFSFS
197
+ const afs = new AFS();
198
+
199
+ afs.mount(
200
+ new AFSFS({
201
+ name: "codebase",
202
+ localPath: "./src",
203
+ description: "Application source code",
204
+ }),
205
+ );
206
+ // Accessible at /modules/codebase
207
+
208
+ afs.mount(
209
+ new AFSFS({
210
+ name: "docs",
211
+ localPath: "./docs",
212
+ description: "Project documentation",
213
+ }),
214
+ );
215
+ // Accessible at /modules/docs
216
+
217
+ // Create agent with AFS access
218
+ const agent = AIAgent.from({
219
+ name: "code-assistant",
220
+ instructions:
221
+ "You are a helpful coding assistant with access to the codebase and documentation",
222
+ afs: afs,
223
+ });
224
+
225
+ // Use the agent
226
+ const context = aigne.newContext();
227
+ const result = await context.invoke(agent, {
228
+ message: "Find all authentication-related files in the codebase",
229
+ });
230
+ ```
231
+
232
+ The agent automatically gets these tools:
233
+
234
+ - **afs_list**: Browse directories
235
+ - **afs_read**: Read file contents
236
+ - **afs_write**: Create or modify files
237
+ - **afs_search**: Search for content
238
+
239
+ ## Multiple Mounts
240
+
241
+ You can mount multiple directories with different names:
242
+
243
+ ```typescript
244
+ // Mount source code
245
+ afs.mount(
246
+ new AFSFS({
247
+ name: "src",
248
+ localPath: "./src",
249
+ description: "Application source code",
250
+ }),
251
+ );
252
+ // Accessible at /modules/src
253
+
254
+ // Mount tests
255
+ afs.mount(
256
+ new AFSFS({
257
+ name: "tests",
258
+ localPath: "./tests",
259
+ description: "Test files",
260
+ }),
261
+ );
262
+ // Accessible at /modules/tests
263
+
264
+ // Mount configuration
265
+ afs.mount(
266
+ new AFSFS({
267
+ name: "config",
268
+ localPath: "./config",
269
+ description: "Configuration files",
270
+ }),
271
+ );
272
+ // Accessible at /modules/config
273
+
274
+ // Now agents can access all mounted directories
275
+ await afs.list("/modules/src");
276
+ await afs.read("/modules/config/app.json");
277
+ await afs.search("/modules/tests", "test suite");
278
+ ```
279
+
280
+ ## File Metadata
281
+
282
+ AFSFS provides detailed file metadata:
283
+
284
+ ```typescript
285
+ const { result } = await afs.read("/modules/fs/README.md");
286
+
287
+ result.metadata = {
288
+ type: "file", // 'file' or 'directory'
289
+ size: 2048, // File size in bytes
290
+ mode: 33188, // Unix permissions (e.g., 0644)
291
+ };
292
+
293
+ result.createdAt; // File creation date
294
+ result.updatedAt; // Last modification date
295
+ ```
296
+
297
+ ## Security Considerations
298
+
299
+ **Sandboxed Access:**
300
+
301
+ - AFSFS operations are restricted to the mounted directory
302
+ - Cannot access files outside the mounted path
303
+ - Path traversal attempts are prevented by Node.js path operations
304
+
305
+ **Best Practices:**
306
+
307
+ - Only mount directories that should be accessible to agents
308
+ - Use descriptive mount paths (e.g., `/readonly-docs`, `/workspace`)
309
+ - Consider file permissions when mounting sensitive directories
310
+ - Review agent instructions to limit file write operations if needed
311
+
312
+ ## Ripgrep Integration
313
+
314
+ AFSFS uses ripgrep for high-performance text search:
315
+
316
+ - **Fast**: Optimized for searching large codebases
317
+ - **Smart Filtering**: Automatically ignores binary files
318
+ - **Accurate**: Provides line-by-line match context
319
+ - **Reliable**: Mature and widely-used search tool
320
+
321
+ ## Examples
322
+
323
+ See the [AFSFS example](../../examples/afs-local-fs) for a complete working implementation.
324
+
325
+ ## TypeScript Support
326
+
327
+ This package includes full TypeScript type definitions:
328
+
329
+ ```typescript
330
+ import type { AFSFS, AFSFSOptions } from "@aigne/afs-fs";
331
+ ```
332
+
333
+ ## Related Packages
334
+
335
+ - [@aigne/afs](../core/README.md) - AFS core package
336
+ - [@aigne/afs-user-profile-memory](../user-profile-memory/README.md) - User profile memory module
337
+
@@ -0,0 +1,11 @@
1
+
2
+ //#region \0@oxc-project+runtime@0.108.0/helpers/decorate.js
3
+ function __decorate(decorators, target, key, desc) {
4
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
7
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
8
+ }
9
+
10
+ //#endregion
11
+ exports.__decorate = __decorate;
@@ -0,0 +1,10 @@
1
+ //#region \0@oxc-project+runtime@0.108.0/helpers/decorate.js
2
+ function __decorate(decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ }
8
+
9
+ //#endregion
10
+ export { __decorate };
@@ -0,0 +1,29 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;