@robinpath/cli 1.75.0 → 1.76.0

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/modules/file.js CHANGED
@@ -1,361 +1,361 @@
1
- /**
2
- * Native file system module for RobinPath.
3
- * Provides Node.js-level fs operations.
4
- */
5
- import { readFile, writeFile, appendFile, rm, cp, rename, readdir, stat, mkdir } from 'node:fs/promises';
6
- import { existsSync, statSync } from 'node:fs';
7
- import { resolve, join, relative } from 'node:path';
8
- import { tmpdir } from 'node:os';
9
- import { toStr, requireArgs } from './_helpers.js';
10
-
11
- export const FileFunctions = {
12
-
13
- read: async (args) => {
14
- requireArgs('file.read', args, 1);
15
- const filePath = resolve(toStr(args[0]));
16
- const encoding = toStr(args[1], 'utf-8');
17
- return await readFile(filePath, { encoding });
18
- },
19
-
20
- readBinary: async (args) => {
21
- requireArgs('file.readBinary', args, 1);
22
- const filePath = resolve(toStr(args[0]));
23
- const buf = await readFile(filePath);
24
- return buf.toString('base64');
25
- },
26
-
27
- write: async (args) => {
28
- requireArgs('file.write', args, 2);
29
- const filePath = resolve(toStr(args[0]));
30
- const content = toStr(args[1]);
31
- const encoding = toStr(args[2], 'utf-8');
32
- await writeFile(filePath, content, { encoding });
33
- return true;
34
- },
35
-
36
- writeBinary: async (args) => {
37
- requireArgs('file.writeBinary', args, 2);
38
- const filePath = resolve(toStr(args[0]));
39
- const base64Data = toStr(args[1]);
40
- await writeFile(filePath, Buffer.from(base64Data, 'base64'));
41
- return true;
42
- },
43
-
44
- append: async (args) => {
45
- requireArgs('file.append', args, 2);
46
- const filePath = resolve(toStr(args[0]));
47
- const content = toStr(args[1]);
48
- await appendFile(filePath, content, 'utf-8');
49
- return true;
50
- },
51
-
52
- delete: async (args) => {
53
- requireArgs('file.delete', args, 1);
54
- const filePath = resolve(toStr(args[0]));
55
- await rm(filePath, { recursive: true, force: true });
56
- return true;
57
- },
58
-
59
- exists: (args) => {
60
- requireArgs('file.exists', args, 1);
61
- return existsSync(resolve(toStr(args[0])));
62
- },
63
-
64
- copy: async (args) => {
65
- requireArgs('file.copy', args, 2);
66
- const src = resolve(toStr(args[0]));
67
- const dest = resolve(toStr(args[1]));
68
- await cp(src, dest, { recursive: true });
69
- return true;
70
- },
71
-
72
- move: async (args) => {
73
- requireArgs('file.move', args, 2);
74
- const src = resolve(toStr(args[0]));
75
- const dest = resolve(toStr(args[1]));
76
- await rename(src, dest);
77
- return true;
78
- },
79
-
80
- rename: async (args) => {
81
- requireArgs('file.rename', args, 2);
82
- const src = resolve(toStr(args[0]));
83
- const dest = resolve(toStr(args[1]));
84
- await rename(src, dest);
85
- return true;
86
- },
87
-
88
- list: async (args) => {
89
- requireArgs('file.list', args, 1);
90
- const dirPath = resolve(toStr(args[0]));
91
- const recursive = args[1] === true || args[1] === 'true';
92
- const entries = await readdir(dirPath, { withFileTypes: true, recursive });
93
- return entries.map(e => ({
94
- name: e.name,
95
- isFile: e.isFile(),
96
- isDirectory: e.isDirectory(),
97
- path: e.parentPath ? join(e.parentPath, e.name) : join(dirPath, e.name)
98
- }));
99
- },
100
-
101
- stat: async (args) => {
102
- requireArgs('file.stat', args, 1);
103
- const filePath = resolve(toStr(args[0]));
104
- const s = await stat(filePath);
105
- return {
106
- size: s.size,
107
- isFile: s.isFile(),
108
- isDirectory: s.isDirectory(),
109
- isSymlink: s.isSymbolicLink(),
110
- created: s.birthtime.toISOString(),
111
- modified: s.mtime.toISOString(),
112
- accessed: s.atime.toISOString(),
113
- permissions: s.mode.toString(8)
114
- };
115
- },
116
-
117
- mkdir: async (args) => {
118
- requireArgs('file.mkdir', args, 1);
119
- const dirPath = resolve(toStr(args[0]));
120
- await mkdir(dirPath, { recursive: true });
121
- return true;
122
- },
123
-
124
- readJSON: async (args) => {
125
- requireArgs('file.readJSON', args, 1);
126
- const filePath = resolve(toStr(args[0]));
127
- const content = await readFile(filePath, 'utf-8');
128
- return JSON.parse(content);
129
- },
130
-
131
- writeJSON: async (args) => {
132
- requireArgs('file.writeJSON', args, 2);
133
- const filePath = resolve(toStr(args[0]));
134
- const data = args[1];
135
- const indent = args[2] != null ? Number(args[2]) : 2;
136
- await writeFile(filePath, JSON.stringify(data, null, indent) + '\n', 'utf-8');
137
- return true;
138
- },
139
-
140
- size: async (args) => {
141
- requireArgs('file.size', args, 1);
142
- const filePath = resolve(toStr(args[0]));
143
- const s = await stat(filePath);
144
- return s.size;
145
- },
146
-
147
- isFile: (args) => {
148
- requireArgs('file.isFile', args, 1);
149
- const filePath = resolve(toStr(args[0]));
150
- try { return statSync(filePath).isFile(); } catch { return false; }
151
- },
152
-
153
- isDir: (args) => {
154
- requireArgs('file.isDir', args, 1);
155
- const filePath = resolve(toStr(args[0]));
156
- try { return statSync(filePath).isDirectory(); } catch { return false; }
157
- },
158
-
159
- lines: async (args) => {
160
- requireArgs('file.lines', args, 1);
161
- const filePath = resolve(toStr(args[0]));
162
- const content = await readFile(filePath, 'utf-8');
163
- return content.split(/\r?\n/);
164
- },
165
-
166
- lineCount: async (args) => {
167
- requireArgs('file.lineCount', args, 1);
168
- const filePath = resolve(toStr(args[0]));
169
- const content = await readFile(filePath, 'utf-8');
170
- return content.split(/\r?\n/).length;
171
- },
172
-
173
- temp: (args) => {
174
- const prefix = toStr(args[0], 'rp_');
175
- const name = prefix + Date.now() + '_' + Math.random().toString(36).slice(2, 8);
176
- return join(tmpdir(), name);
177
- },
178
-
179
- cwd: () => {
180
- return process.cwd();
181
- }
182
- };
183
-
184
- export const FileFunctionMetadata = {
185
- read: {
186
- description: 'Read file contents as a string',
187
- parameters: [
188
- { name: 'path', dataType: 'string', description: 'File path to read', formInputType: 'text', required: true },
189
- { name: 'encoding', dataType: 'string', description: 'Encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
190
- ],
191
- returnType: 'string', returnDescription: 'File contents', example: 'file.read "data.txt"'
192
- },
193
- readBinary: {
194
- description: 'Read file as base64-encoded string',
195
- parameters: [
196
- { name: 'path', dataType: 'string', description: 'File path to read', formInputType: 'text', required: true }
197
- ],
198
- returnType: 'string', returnDescription: 'Base64-encoded file contents', example: 'file.readBinary "image.png"'
199
- },
200
- write: {
201
- description: 'Write string content to a file',
202
- parameters: [
203
- { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true },
204
- { name: 'content', dataType: 'string', description: 'Content to write', formInputType: 'textarea', required: true },
205
- { name: 'encoding', dataType: 'string', description: 'Encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
206
- ],
207
- returnType: 'boolean', returnDescription: 'true on success', example: 'file.write "out.txt" "Hello"'
208
- },
209
- writeBinary: {
210
- description: 'Write base64 data to a binary file',
211
- parameters: [
212
- { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true },
213
- { name: 'base64Data', dataType: 'string', description: 'Base64-encoded data', formInputType: 'textarea', required: true }
214
- ],
215
- returnType: 'boolean', returnDescription: 'true on success', example: 'file.writeBinary "out.bin" $data'
216
- },
217
- append: {
218
- description: 'Append content to a file',
219
- parameters: [
220
- { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true },
221
- { name: 'content', dataType: 'string', description: 'Content to append', formInputType: 'textarea', required: true }
222
- ],
223
- returnType: 'boolean', returnDescription: 'true on success', example: 'file.append "log.txt" "new line"'
224
- },
225
- delete: {
226
- description: 'Delete a file or directory (recursive)',
227
- parameters: [
228
- { name: 'path', dataType: 'string', description: 'Path to delete', formInputType: 'text', required: true }
229
- ],
230
- returnType: 'boolean', returnDescription: 'true on success', example: 'file.delete "temp/"'
231
- },
232
- exists: {
233
- description: 'Check if a file or directory exists',
234
- parameters: [
235
- { name: 'path', dataType: 'string', description: 'Path to check', formInputType: 'text', required: true }
236
- ],
237
- returnType: 'boolean', returnDescription: 'true if exists', example: 'file.exists "config.json"'
238
- },
239
- copy: {
240
- description: 'Copy a file or directory',
241
- parameters: [
242
- { name: 'source', dataType: 'string', description: 'Source path', formInputType: 'text', required: true },
243
- { name: 'destination', dataType: 'string', description: 'Destination path', formInputType: 'text', required: true }
244
- ],
245
- returnType: 'boolean', returnDescription: 'true on success', example: 'file.copy "a.txt" "b.txt"'
246
- },
247
- move: {
248
- description: 'Move/rename a file or directory',
249
- parameters: [
250
- { name: 'source', dataType: 'string', description: 'Source path', formInputType: 'text', required: true },
251
- { name: 'destination', dataType: 'string', description: 'Destination path', formInputType: 'text', required: true }
252
- ],
253
- returnType: 'boolean', returnDescription: 'true on success', example: 'file.move "old.txt" "new.txt"'
254
- },
255
- rename: {
256
- description: 'Rename a file or directory',
257
- parameters: [
258
- { name: 'source', dataType: 'string', description: 'Current name', formInputType: 'text', required: true },
259
- { name: 'destination', dataType: 'string', description: 'New name', formInputType: 'text', required: true }
260
- ],
261
- returnType: 'boolean', returnDescription: 'true on success', example: 'file.rename "old.txt" "new.txt"'
262
- },
263
- list: {
264
- description: 'List files and directories in a path',
265
- parameters: [
266
- { name: 'directory', dataType: 'string', description: 'Directory to list', formInputType: 'text', required: true },
267
- { name: 'recursive', dataType: 'boolean', description: 'List recursively (default: false)', formInputType: 'checkbox', required: false, defaultValue: false }
268
- ],
269
- returnType: 'array', returnDescription: 'Array of {name, isFile, isDirectory, path}', example: 'file.list "src/"'
270
- },
271
- stat: {
272
- description: 'Get file/directory metadata',
273
- parameters: [
274
- { name: 'path', dataType: 'string', description: 'Path to inspect', formInputType: 'text', required: true }
275
- ],
276
- returnType: 'object', returnDescription: 'Object with size, isFile, isDirectory, created, modified', example: 'file.stat "data.txt"'
277
- },
278
- mkdir: {
279
- description: 'Create a directory (recursive)',
280
- parameters: [
281
- { name: 'path', dataType: 'string', description: 'Directory path', formInputType: 'text', required: true }
282
- ],
283
- returnType: 'boolean', returnDescription: 'true on success', example: 'file.mkdir "output/data"'
284
- },
285
- readJSON: {
286
- description: 'Read and parse a JSON file',
287
- parameters: [
288
- { name: 'path', dataType: 'string', description: 'Path to JSON file', formInputType: 'text', required: true }
289
- ],
290
- returnType: 'object', returnDescription: 'Parsed JSON object', example: 'file.readJSON "config.json"'
291
- },
292
- writeJSON: {
293
- description: 'Write an object as JSON to a file',
294
- parameters: [
295
- { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true },
296
- { name: 'data', dataType: 'object', description: 'Object to write', formInputType: 'json', required: true },
297
- { name: 'indent', dataType: 'number', description: 'Indentation (default: 2)', formInputType: 'number', required: false, defaultValue: 2 }
298
- ],
299
- returnType: 'boolean', returnDescription: 'true on success', example: 'file.writeJSON "out.json" $data'
300
- },
301
- size: {
302
- description: 'Get file size in bytes',
303
- parameters: [
304
- { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true }
305
- ],
306
- returnType: 'number', returnDescription: 'Size in bytes', example: 'file.size "data.bin"'
307
- },
308
- isFile: {
309
- description: 'Check if path is a file',
310
- parameters: [
311
- { name: 'path', dataType: 'string', description: 'Path to check', formInputType: 'text', required: true }
312
- ],
313
- returnType: 'boolean', returnDescription: 'true if file', example: 'file.isFile "data.txt"'
314
- },
315
- isDir: {
316
- description: 'Check if path is a directory',
317
- parameters: [
318
- { name: 'path', dataType: 'string', description: 'Path to check', formInputType: 'text', required: true }
319
- ],
320
- returnType: 'boolean', returnDescription: 'true if directory', example: 'file.isDir "src/"'
321
- },
322
- lines: {
323
- description: 'Read file and split into array of lines',
324
- parameters: [
325
- { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true }
326
- ],
327
- returnType: 'array', returnDescription: 'Array of lines', example: 'file.lines "data.txt"'
328
- },
329
- lineCount: {
330
- description: 'Count number of lines in a file',
331
- parameters: [
332
- { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true }
333
- ],
334
- returnType: 'number', returnDescription: 'Number of lines', example: 'file.lineCount "data.txt"'
335
- },
336
- temp: {
337
- description: 'Generate a temporary file path',
338
- parameters: [
339
- { name: 'prefix', dataType: 'string', description: 'Filename prefix (default: rp_)', formInputType: 'text', required: false, defaultValue: 'rp_' }
340
- ],
341
- returnType: 'string', returnDescription: 'Temporary file path', example: 'file.temp "myapp_"'
342
- },
343
- cwd: {
344
- description: 'Get current working directory',
345
- parameters: [],
346
- returnType: 'string', returnDescription: 'Current working directory path', example: 'file.cwd'
347
- }
348
- };
349
-
350
- export const FileModuleMetadata = {
351
- description: 'File system operations: read, write, copy, move, delete, list, and more',
352
- methods: Object.keys(FileFunctions)
353
- };
354
-
355
- export default {
356
- name: 'file',
357
- functions: FileFunctions,
358
- functionMetadata: FileFunctionMetadata,
359
- moduleMetadata: FileModuleMetadata,
360
- global: false
361
- };
1
+ /**
2
+ * Native file system module for RobinPath.
3
+ * Provides Node.js-level fs operations.
4
+ */
5
+ import { readFile, writeFile, appendFile, rm, cp, rename, readdir, stat, mkdir } from 'node:fs/promises';
6
+ import { existsSync, statSync } from 'node:fs';
7
+ import { resolve, join, relative } from 'node:path';
8
+ import { tmpdir } from 'node:os';
9
+ import { toStr, requireArgs } from './_helpers.js';
10
+
11
+ export const FileFunctions = {
12
+
13
+ read: async (args) => {
14
+ requireArgs('file.read', args, 1);
15
+ const filePath = resolve(toStr(args[0]));
16
+ const encoding = toStr(args[1], 'utf-8');
17
+ return await readFile(filePath, { encoding });
18
+ },
19
+
20
+ readBinary: async (args) => {
21
+ requireArgs('file.readBinary', args, 1);
22
+ const filePath = resolve(toStr(args[0]));
23
+ const buf = await readFile(filePath);
24
+ return buf.toString('base64');
25
+ },
26
+
27
+ write: async (args) => {
28
+ requireArgs('file.write', args, 2);
29
+ const filePath = resolve(toStr(args[0]));
30
+ const content = toStr(args[1]);
31
+ const encoding = toStr(args[2], 'utf-8');
32
+ await writeFile(filePath, content, { encoding });
33
+ return true;
34
+ },
35
+
36
+ writeBinary: async (args) => {
37
+ requireArgs('file.writeBinary', args, 2);
38
+ const filePath = resolve(toStr(args[0]));
39
+ const base64Data = toStr(args[1]);
40
+ await writeFile(filePath, Buffer.from(base64Data, 'base64'));
41
+ return true;
42
+ },
43
+
44
+ append: async (args) => {
45
+ requireArgs('file.append', args, 2);
46
+ const filePath = resolve(toStr(args[0]));
47
+ const content = toStr(args[1]);
48
+ await appendFile(filePath, content, 'utf-8');
49
+ return true;
50
+ },
51
+
52
+ delete: async (args) => {
53
+ requireArgs('file.delete', args, 1);
54
+ const filePath = resolve(toStr(args[0]));
55
+ await rm(filePath, { recursive: true, force: true });
56
+ return true;
57
+ },
58
+
59
+ exists: (args) => {
60
+ requireArgs('file.exists', args, 1);
61
+ return existsSync(resolve(toStr(args[0])));
62
+ },
63
+
64
+ copy: async (args) => {
65
+ requireArgs('file.copy', args, 2);
66
+ const src = resolve(toStr(args[0]));
67
+ const dest = resolve(toStr(args[1]));
68
+ await cp(src, dest, { recursive: true });
69
+ return true;
70
+ },
71
+
72
+ move: async (args) => {
73
+ requireArgs('file.move', args, 2);
74
+ const src = resolve(toStr(args[0]));
75
+ const dest = resolve(toStr(args[1]));
76
+ await rename(src, dest);
77
+ return true;
78
+ },
79
+
80
+ rename: async (args) => {
81
+ requireArgs('file.rename', args, 2);
82
+ const src = resolve(toStr(args[0]));
83
+ const dest = resolve(toStr(args[1]));
84
+ await rename(src, dest);
85
+ return true;
86
+ },
87
+
88
+ list: async (args) => {
89
+ requireArgs('file.list', args, 1);
90
+ const dirPath = resolve(toStr(args[0]));
91
+ const recursive = args[1] === true || args[1] === 'true';
92
+ const entries = await readdir(dirPath, { withFileTypes: true, recursive });
93
+ return entries.map(e => ({
94
+ name: e.name,
95
+ isFile: e.isFile(),
96
+ isDirectory: e.isDirectory(),
97
+ path: e.parentPath ? join(e.parentPath, e.name) : join(dirPath, e.name)
98
+ }));
99
+ },
100
+
101
+ stat: async (args) => {
102
+ requireArgs('file.stat', args, 1);
103
+ const filePath = resolve(toStr(args[0]));
104
+ const s = await stat(filePath);
105
+ return {
106
+ size: s.size,
107
+ isFile: s.isFile(),
108
+ isDirectory: s.isDirectory(),
109
+ isSymlink: s.isSymbolicLink(),
110
+ created: s.birthtime.toISOString(),
111
+ modified: s.mtime.toISOString(),
112
+ accessed: s.atime.toISOString(),
113
+ permissions: s.mode.toString(8)
114
+ };
115
+ },
116
+
117
+ mkdir: async (args) => {
118
+ requireArgs('file.mkdir', args, 1);
119
+ const dirPath = resolve(toStr(args[0]));
120
+ await mkdir(dirPath, { recursive: true });
121
+ return true;
122
+ },
123
+
124
+ readJSON: async (args) => {
125
+ requireArgs('file.readJSON', args, 1);
126
+ const filePath = resolve(toStr(args[0]));
127
+ const content = await readFile(filePath, 'utf-8');
128
+ return JSON.parse(content);
129
+ },
130
+
131
+ writeJSON: async (args) => {
132
+ requireArgs('file.writeJSON', args, 2);
133
+ const filePath = resolve(toStr(args[0]));
134
+ const data = args[1];
135
+ const indent = args[2] != null ? Number(args[2]) : 2;
136
+ await writeFile(filePath, JSON.stringify(data, null, indent) + '\n', 'utf-8');
137
+ return true;
138
+ },
139
+
140
+ size: async (args) => {
141
+ requireArgs('file.size', args, 1);
142
+ const filePath = resolve(toStr(args[0]));
143
+ const s = await stat(filePath);
144
+ return s.size;
145
+ },
146
+
147
+ isFile: (args) => {
148
+ requireArgs('file.isFile', args, 1);
149
+ const filePath = resolve(toStr(args[0]));
150
+ try { return statSync(filePath).isFile(); } catch { return false; }
151
+ },
152
+
153
+ isDir: (args) => {
154
+ requireArgs('file.isDir', args, 1);
155
+ const filePath = resolve(toStr(args[0]));
156
+ try { return statSync(filePath).isDirectory(); } catch { return false; }
157
+ },
158
+
159
+ lines: async (args) => {
160
+ requireArgs('file.lines', args, 1);
161
+ const filePath = resolve(toStr(args[0]));
162
+ const content = await readFile(filePath, 'utf-8');
163
+ return content.split(/\r?\n/);
164
+ },
165
+
166
+ lineCount: async (args) => {
167
+ requireArgs('file.lineCount', args, 1);
168
+ const filePath = resolve(toStr(args[0]));
169
+ const content = await readFile(filePath, 'utf-8');
170
+ return content.split(/\r?\n/).length;
171
+ },
172
+
173
+ temp: (args) => {
174
+ const prefix = toStr(args[0], 'rp_');
175
+ const name = prefix + Date.now() + '_' + Math.random().toString(36).slice(2, 8);
176
+ return join(tmpdir(), name);
177
+ },
178
+
179
+ cwd: () => {
180
+ return process.cwd();
181
+ }
182
+ };
183
+
184
+ export const FileFunctionMetadata = {
185
+ read: {
186
+ description: 'Read file contents as a string',
187
+ parameters: [
188
+ { name: 'path', dataType: 'string', description: 'File path to read', formInputType: 'text', required: true },
189
+ { name: 'encoding', dataType: 'string', description: 'Encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
190
+ ],
191
+ returnType: 'string', returnDescription: 'File contents', example: 'file.read "data.txt"'
192
+ },
193
+ readBinary: {
194
+ description: 'Read file as base64-encoded string',
195
+ parameters: [
196
+ { name: 'path', dataType: 'string', description: 'File path to read', formInputType: 'text', required: true }
197
+ ],
198
+ returnType: 'string', returnDescription: 'Base64-encoded file contents', example: 'file.readBinary "image.png"'
199
+ },
200
+ write: {
201
+ description: 'Write string content to a file',
202
+ parameters: [
203
+ { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true },
204
+ { name: 'content', dataType: 'string', description: 'Content to write', formInputType: 'textarea', required: true },
205
+ { name: 'encoding', dataType: 'string', description: 'Encoding (default: utf-8)', formInputType: 'text', required: false, defaultValue: 'utf-8' }
206
+ ],
207
+ returnType: 'boolean', returnDescription: 'true on success', example: 'file.write "out.txt" "Hello"'
208
+ },
209
+ writeBinary: {
210
+ description: 'Write base64 data to a binary file',
211
+ parameters: [
212
+ { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true },
213
+ { name: 'base64Data', dataType: 'string', description: 'Base64-encoded data', formInputType: 'textarea', required: true }
214
+ ],
215
+ returnType: 'boolean', returnDescription: 'true on success', example: 'file.writeBinary "out.bin" $data'
216
+ },
217
+ append: {
218
+ description: 'Append content to a file',
219
+ parameters: [
220
+ { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true },
221
+ { name: 'content', dataType: 'string', description: 'Content to append', formInputType: 'textarea', required: true }
222
+ ],
223
+ returnType: 'boolean', returnDescription: 'true on success', example: 'file.append "log.txt" "new line"'
224
+ },
225
+ delete: {
226
+ description: 'Delete a file or directory (recursive)',
227
+ parameters: [
228
+ { name: 'path', dataType: 'string', description: 'Path to delete', formInputType: 'text', required: true }
229
+ ],
230
+ returnType: 'boolean', returnDescription: 'true on success', example: 'file.delete "temp/"'
231
+ },
232
+ exists: {
233
+ description: 'Check if a file or directory exists',
234
+ parameters: [
235
+ { name: 'path', dataType: 'string', description: 'Path to check', formInputType: 'text', required: true }
236
+ ],
237
+ returnType: 'boolean', returnDescription: 'true if exists', example: 'file.exists "config.json"'
238
+ },
239
+ copy: {
240
+ description: 'Copy a file or directory',
241
+ parameters: [
242
+ { name: 'source', dataType: 'string', description: 'Source path', formInputType: 'text', required: true },
243
+ { name: 'destination', dataType: 'string', description: 'Destination path', formInputType: 'text', required: true }
244
+ ],
245
+ returnType: 'boolean', returnDescription: 'true on success', example: 'file.copy "a.txt" "b.txt"'
246
+ },
247
+ move: {
248
+ description: 'Move/rename a file or directory',
249
+ parameters: [
250
+ { name: 'source', dataType: 'string', description: 'Source path', formInputType: 'text', required: true },
251
+ { name: 'destination', dataType: 'string', description: 'Destination path', formInputType: 'text', required: true }
252
+ ],
253
+ returnType: 'boolean', returnDescription: 'true on success', example: 'file.move "old.txt" "new.txt"'
254
+ },
255
+ rename: {
256
+ description: 'Rename a file or directory',
257
+ parameters: [
258
+ { name: 'source', dataType: 'string', description: 'Current name', formInputType: 'text', required: true },
259
+ { name: 'destination', dataType: 'string', description: 'New name', formInputType: 'text', required: true }
260
+ ],
261
+ returnType: 'boolean', returnDescription: 'true on success', example: 'file.rename "old.txt" "new.txt"'
262
+ },
263
+ list: {
264
+ description: 'List files and directories in a path',
265
+ parameters: [
266
+ { name: 'directory', dataType: 'string', description: 'Directory to list', formInputType: 'text', required: true },
267
+ { name: 'recursive', dataType: 'boolean', description: 'List recursively (default: false)', formInputType: 'checkbox', required: false, defaultValue: false }
268
+ ],
269
+ returnType: 'array', returnDescription: 'Array of {name, isFile, isDirectory, path}', example: 'file.list "src/"'
270
+ },
271
+ stat: {
272
+ description: 'Get file/directory metadata',
273
+ parameters: [
274
+ { name: 'path', dataType: 'string', description: 'Path to inspect', formInputType: 'text', required: true }
275
+ ],
276
+ returnType: 'object', returnDescription: 'Object with size, isFile, isDirectory, created, modified', example: 'file.stat "data.txt"'
277
+ },
278
+ mkdir: {
279
+ description: 'Create a directory (recursive)',
280
+ parameters: [
281
+ { name: 'path', dataType: 'string', description: 'Directory path', formInputType: 'text', required: true }
282
+ ],
283
+ returnType: 'boolean', returnDescription: 'true on success', example: 'file.mkdir "output/data"'
284
+ },
285
+ readJSON: {
286
+ description: 'Read and parse a JSON file',
287
+ parameters: [
288
+ { name: 'path', dataType: 'string', description: 'Path to JSON file', formInputType: 'text', required: true }
289
+ ],
290
+ returnType: 'object', returnDescription: 'Parsed JSON object', example: 'file.readJSON "config.json"'
291
+ },
292
+ writeJSON: {
293
+ description: 'Write an object as JSON to a file',
294
+ parameters: [
295
+ { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true },
296
+ { name: 'data', dataType: 'object', description: 'Object to write', formInputType: 'json', required: true },
297
+ { name: 'indent', dataType: 'number', description: 'Indentation (default: 2)', formInputType: 'number', required: false, defaultValue: 2 }
298
+ ],
299
+ returnType: 'boolean', returnDescription: 'true on success', example: 'file.writeJSON "out.json" $data'
300
+ },
301
+ size: {
302
+ description: 'Get file size in bytes',
303
+ parameters: [
304
+ { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true }
305
+ ],
306
+ returnType: 'number', returnDescription: 'Size in bytes', example: 'file.size "data.bin"'
307
+ },
308
+ isFile: {
309
+ description: 'Check if path is a file',
310
+ parameters: [
311
+ { name: 'path', dataType: 'string', description: 'Path to check', formInputType: 'text', required: true }
312
+ ],
313
+ returnType: 'boolean', returnDescription: 'true if file', example: 'file.isFile "data.txt"'
314
+ },
315
+ isDir: {
316
+ description: 'Check if path is a directory',
317
+ parameters: [
318
+ { name: 'path', dataType: 'string', description: 'Path to check', formInputType: 'text', required: true }
319
+ ],
320
+ returnType: 'boolean', returnDescription: 'true if directory', example: 'file.isDir "src/"'
321
+ },
322
+ lines: {
323
+ description: 'Read file and split into array of lines',
324
+ parameters: [
325
+ { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true }
326
+ ],
327
+ returnType: 'array', returnDescription: 'Array of lines', example: 'file.lines "data.txt"'
328
+ },
329
+ lineCount: {
330
+ description: 'Count number of lines in a file',
331
+ parameters: [
332
+ { name: 'path', dataType: 'string', description: 'File path', formInputType: 'text', required: true }
333
+ ],
334
+ returnType: 'number', returnDescription: 'Number of lines', example: 'file.lineCount "data.txt"'
335
+ },
336
+ temp: {
337
+ description: 'Generate a temporary file path',
338
+ parameters: [
339
+ { name: 'prefix', dataType: 'string', description: 'Filename prefix (default: rp_)', formInputType: 'text', required: false, defaultValue: 'rp_' }
340
+ ],
341
+ returnType: 'string', returnDescription: 'Temporary file path', example: 'file.temp "myapp_"'
342
+ },
343
+ cwd: {
344
+ description: 'Get current working directory',
345
+ parameters: [],
346
+ returnType: 'string', returnDescription: 'Current working directory path', example: 'file.cwd'
347
+ }
348
+ };
349
+
350
+ export const FileModuleMetadata = {
351
+ description: 'File system operations: read, write, copy, move, delete, list, and more',
352
+ methods: Object.keys(FileFunctions)
353
+ };
354
+
355
+ export default {
356
+ name: 'file',
357
+ functions: FileFunctions,
358
+ functionMetadata: FileFunctionMetadata,
359
+ moduleMetadata: FileModuleMetadata,
360
+ global: false
361
+ };