@dexto/tools-filesystem 1.6.0 → 1.6.2

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.
Files changed (73) hide show
  1. package/dist/directory-approval.cjs +44 -40
  2. package/dist/directory-approval.d.ts +8 -4
  3. package/dist/directory-approval.d.ts.map +1 -1
  4. package/dist/directory-approval.integration.test.cjs +107 -356
  5. package/dist/directory-approval.integration.test.d.ts +6 -6
  6. package/dist/directory-approval.integration.test.js +109 -360
  7. package/dist/directory-approval.js +45 -41
  8. package/dist/edit-file-tool.cjs +69 -47
  9. package/dist/edit-file-tool.d.ts.map +1 -1
  10. package/dist/edit-file-tool.js +77 -48
  11. package/dist/edit-file-tool.test.cjs +54 -11
  12. package/dist/edit-file-tool.test.js +54 -11
  13. package/dist/error-codes.cjs +4 -0
  14. package/dist/error-codes.d.ts +4 -0
  15. package/dist/error-codes.d.ts.map +1 -1
  16. package/dist/error-codes.js +4 -0
  17. package/dist/errors.cjs +48 -0
  18. package/dist/errors.d.ts +16 -0
  19. package/dist/errors.d.ts.map +1 -1
  20. package/dist/errors.js +48 -0
  21. package/dist/filesystem-service.cjs +307 -9
  22. package/dist/filesystem-service.d.ts +28 -1
  23. package/dist/filesystem-service.d.ts.map +1 -1
  24. package/dist/filesystem-service.js +308 -10
  25. package/dist/glob-files-tool.cjs +12 -1
  26. package/dist/glob-files-tool.d.ts.map +1 -1
  27. package/dist/glob-files-tool.js +13 -2
  28. package/dist/grep-content-tool.cjs +13 -1
  29. package/dist/grep-content-tool.d.ts.map +1 -1
  30. package/dist/grep-content-tool.js +14 -2
  31. package/dist/index.cjs +3 -0
  32. package/dist/index.d.cts +852 -16
  33. package/dist/index.d.ts +2 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +2 -0
  36. package/dist/path-validator.cjs +28 -2
  37. package/dist/path-validator.d.ts +14 -0
  38. package/dist/path-validator.d.ts.map +1 -1
  39. package/dist/path-validator.js +28 -2
  40. package/dist/read-file-tool.cjs +7 -1
  41. package/dist/read-file-tool.d.ts.map +1 -1
  42. package/dist/read-file-tool.js +8 -2
  43. package/dist/tool-factory.cjs +21 -0
  44. package/dist/tool-factory.d.ts.map +1 -1
  45. package/dist/tool-factory.js +21 -0
  46. package/dist/types.d.ts +65 -0
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/write-file-tool.cjs +60 -38
  49. package/dist/write-file-tool.d.ts +1 -1
  50. package/dist/write-file-tool.d.ts.map +1 -1
  51. package/dist/write-file-tool.js +67 -39
  52. package/dist/write-file-tool.test.cjs +75 -13
  53. package/dist/write-file-tool.test.js +75 -13
  54. package/package.json +6 -6
  55. package/dist/directory-approval.d.cts +0 -22
  56. package/dist/directory-approval.integration.test.d.cts +0 -2
  57. package/dist/edit-file-tool.d.cts +0 -34
  58. package/dist/edit-file-tool.test.d.cts +0 -2
  59. package/dist/error-codes.d.cts +0 -32
  60. package/dist/errors.d.cts +0 -112
  61. package/dist/file-tool-types.d.cts +0 -18
  62. package/dist/filesystem-service.d.cts +0 -117
  63. package/dist/filesystem-service.test.d.cts +0 -2
  64. package/dist/glob-files-tool.d.cts +0 -31
  65. package/dist/grep-content-tool.d.cts +0 -40
  66. package/dist/path-validator.d.cts +0 -97
  67. package/dist/path-validator.test.d.cts +0 -2
  68. package/dist/read-file-tool.d.cts +0 -31
  69. package/dist/tool-factory-config.d.cts +0 -63
  70. package/dist/tool-factory.d.cts +0 -7
  71. package/dist/types.d.cts +0 -178
  72. package/dist/write-file-tool.d.cts +0 -34
  73. package/dist/write-file-tool.test.d.cts +0 -2
package/dist/index.d.cts CHANGED
@@ -1,16 +1,852 @@
1
- export { fileSystemToolsFactory } from './tool-factory.cjs';
2
- export { FileSystemServiceGetter } from './file-tool-types.cjs';
3
- export { FileSystemService } from './filesystem-service.cjs';
4
- export { PathValidator } from './path-validator.cjs';
5
- export { FileSystemError } from './errors.cjs';
6
- export { FileSystemErrorCode } from './error-codes.cjs';
7
- export { BufferEncoding, EditFileOptions, EditOperation, EditResult, FileContent, FileMetadata, FileSystemConfig, GlobOptions, GlobResult, GrepOptions, PathValidation, ReadFileOptions, SearchMatch, SearchResult, WriteFileOptions, WriteResult } from './types.cjs';
8
- export { createReadFileTool } from './read-file-tool.cjs';
9
- export { createWriteFileTool } from './write-file-tool.cjs';
10
- export { createEditFileTool } from './edit-file-tool.cjs';
11
- export { createGlobFilesTool } from './glob-files-tool.cjs';
12
- export { createGrepContentTool } from './grep-content-tool.cjs';
13
- import '@dexto/agent-config';
14
- import './tool-factory-config.cjs';
15
- import 'zod';
16
- import '@dexto/core';
1
+ import { ToolFactory } from '@dexto/agent-config';
2
+ import { z } from 'zod';
3
+ import { Logger, ToolExecutionContext, DextoRuntimeError, Tool } from '@dexto/core';
4
+
5
+ /**
6
+ * FileSystem Tools Factory
7
+ *
8
+ * Provides file operation tools by wrapping FileSystemService.
9
+ * When registered, the factory initializes FileSystemService and creates tools
10
+ * for file operations (read, write, edit, glob, grep).
11
+ */
12
+
13
+ /**
14
+ * Configuration schema for FileSystem tools factory.
15
+ *
16
+ * This is the SINGLE SOURCE OF TRUTH for all configuration:
17
+ * - Validation rules
18
+ * - Default values (using constants above)
19
+ * - Documentation
20
+ * - Type definitions
21
+ *
22
+ * Services receive fully-validated config from this schema and use it as-is,
23
+ * with no additional defaults or fallbacks needed.
24
+ */
25
+ declare const FileSystemToolsConfigSchema: z.ZodObject<{
26
+ type: z.ZodLiteral<"filesystem-tools">;
27
+ allowedPaths: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
28
+ blockedPaths: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
29
+ blockedExtensions: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
30
+ maxFileSize: z.ZodDefault<z.ZodNumber>;
31
+ workingDirectory: z.ZodOptional<z.ZodString>;
32
+ enableBackups: z.ZodDefault<z.ZodBoolean>;
33
+ backupPath: z.ZodOptional<z.ZodString>;
34
+ backupRetentionDays: z.ZodDefault<z.ZodNumber>;
35
+ enabledTools: z.ZodOptional<z.ZodArray<z.ZodEnum<["read_file", "write_file", "edit_file", "glob_files", "grep_content"]>, "many">>;
36
+ }, "strict", z.ZodTypeAny, {
37
+ allowedPaths: string[];
38
+ blockedExtensions: string[];
39
+ blockedPaths: string[];
40
+ maxFileSize: number;
41
+ enableBackups: boolean;
42
+ backupRetentionDays: number;
43
+ type: "filesystem-tools";
44
+ backupPath?: string | undefined;
45
+ workingDirectory?: string | undefined;
46
+ enabledTools?: ("read_file" | "write_file" | "edit_file" | "glob_files" | "grep_content")[] | undefined;
47
+ }, {
48
+ type: "filesystem-tools";
49
+ allowedPaths?: string[] | undefined;
50
+ blockedExtensions?: string[] | undefined;
51
+ backupPath?: string | undefined;
52
+ blockedPaths?: string[] | undefined;
53
+ maxFileSize?: number | undefined;
54
+ enableBackups?: boolean | undefined;
55
+ backupRetentionDays?: number | undefined;
56
+ workingDirectory?: string | undefined;
57
+ enabledTools?: ("read_file" | "write_file" | "edit_file" | "glob_files" | "grep_content")[] | undefined;
58
+ }>;
59
+ type FileSystemToolsConfig = z.output<typeof FileSystemToolsConfigSchema>;
60
+
61
+ declare const fileSystemToolsFactory: ToolFactory<FileSystemToolsConfig>;
62
+
63
+ /**
64
+ * FileSystem Service Types
65
+ *
66
+ * Types and interfaces for file system operations including reading, writing,
67
+ * searching, and validation.
68
+ */
69
+ type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
70
+ /**
71
+ * File content with metadata
72
+ */
73
+ interface FileContent {
74
+ content: string;
75
+ lines: number;
76
+ encoding: string;
77
+ mimeType?: string;
78
+ truncated: boolean;
79
+ size: number;
80
+ }
81
+ /**
82
+ * Options for reading files
83
+ */
84
+ interface ReadFileOptions {
85
+ /** Maximum number of lines to read */
86
+ limit?: number | undefined;
87
+ /** Starting line number (1-based) */
88
+ offset?: number | undefined;
89
+ /** File encoding (default: utf-8) */
90
+ encoding?: BufferEncoding | undefined;
91
+ }
92
+ /**
93
+ * File metadata for glob results
94
+ */
95
+ interface FileMetadata {
96
+ path: string;
97
+ size: number;
98
+ modified: Date;
99
+ isDirectory: boolean;
100
+ }
101
+ /**
102
+ * Directory entry metadata
103
+ */
104
+ interface DirectoryEntry {
105
+ name: string;
106
+ path: string;
107
+ isDirectory: boolean;
108
+ size: number;
109
+ modified: Date;
110
+ }
111
+ /**
112
+ * Options for listing directory contents
113
+ */
114
+ interface ListDirectoryOptions {
115
+ /** Include hidden files/directories (dotfiles) */
116
+ includeHidden?: boolean | undefined;
117
+ /** Include stat metadata */
118
+ includeMetadata?: boolean | undefined;
119
+ /** Maximum number of entries to return */
120
+ maxEntries?: number | undefined;
121
+ }
122
+ /**
123
+ * Directory listing result
124
+ */
125
+ interface ListDirectoryResult {
126
+ path: string;
127
+ entries: DirectoryEntry[];
128
+ truncated: boolean;
129
+ totalEntries: number;
130
+ }
131
+ /**
132
+ * Options for creating directories
133
+ */
134
+ interface CreateDirectoryOptions {
135
+ /** Create intermediate directories if they don't exist */
136
+ recursive?: boolean | undefined;
137
+ }
138
+ /**
139
+ * Create directory result
140
+ */
141
+ interface CreateDirectoryResult {
142
+ path: string;
143
+ created: boolean;
144
+ }
145
+ /**
146
+ * Options for deleting paths
147
+ */
148
+ interface DeletePathOptions {
149
+ /** Recursively delete directories */
150
+ recursive?: boolean | undefined;
151
+ }
152
+ /**
153
+ * Delete path result
154
+ */
155
+ interface DeletePathResult {
156
+ path: string;
157
+ deleted: boolean;
158
+ }
159
+ /**
160
+ * Rename path result
161
+ */
162
+ interface RenamePathResult {
163
+ from: string;
164
+ to: string;
165
+ }
166
+ /**
167
+ * Options for glob operations
168
+ */
169
+ interface GlobOptions {
170
+ /** Base directory to search from */
171
+ cwd?: string | undefined;
172
+ /** Maximum number of results */
173
+ maxResults?: number | undefined;
174
+ /** Include file metadata */
175
+ includeMetadata?: boolean | undefined;
176
+ }
177
+ /**
178
+ * Glob result
179
+ */
180
+ interface GlobResult {
181
+ files: FileMetadata[];
182
+ truncated: boolean;
183
+ totalFound: number;
184
+ }
185
+ /**
186
+ * Search match with context
187
+ */
188
+ interface SearchMatch {
189
+ file: string;
190
+ lineNumber: number;
191
+ line: string;
192
+ context?: {
193
+ before: string[];
194
+ after: string[];
195
+ };
196
+ }
197
+ /**
198
+ * Options for content search (grep)
199
+ */
200
+ interface GrepOptions {
201
+ /** Base directory to search */
202
+ path?: string | undefined;
203
+ /** Glob pattern to filter files */
204
+ glob?: string | undefined;
205
+ /** Number of context lines before/after match */
206
+ contextLines?: number | undefined;
207
+ /** Case-insensitive search */
208
+ caseInsensitive?: boolean | undefined;
209
+ /** Maximum number of results */
210
+ maxResults?: number | undefined;
211
+ /** Include line numbers */
212
+ lineNumbers?: boolean | undefined;
213
+ }
214
+ /**
215
+ * Search result
216
+ */
217
+ interface SearchResult {
218
+ matches: SearchMatch[];
219
+ totalMatches: number;
220
+ truncated: boolean;
221
+ filesSearched: number;
222
+ }
223
+ /**
224
+ * Options for writing files
225
+ */
226
+ interface WriteFileOptions {
227
+ /** Create parent directories if they don't exist */
228
+ createDirs?: boolean | undefined;
229
+ /** File encoding (default: utf-8) */
230
+ encoding?: BufferEncoding | undefined;
231
+ /** Create backup before overwriting */
232
+ backup?: boolean | undefined;
233
+ }
234
+ /**
235
+ * Write result
236
+ */
237
+ interface WriteResult {
238
+ success: boolean;
239
+ path: string;
240
+ bytesWritten: number;
241
+ backupPath?: string | undefined;
242
+ /** Original content if file was overwritten (undefined for new files) */
243
+ originalContent?: string | undefined;
244
+ }
245
+ /**
246
+ * Edit operation
247
+ */
248
+ interface EditOperation {
249
+ oldString: string;
250
+ newString: string;
251
+ replaceAll?: boolean | undefined;
252
+ }
253
+ /**
254
+ * Options for editing files
255
+ */
256
+ interface EditFileOptions {
257
+ /** Create backup before editing */
258
+ backup?: boolean;
259
+ /** File encoding */
260
+ encoding?: BufferEncoding;
261
+ }
262
+ /**
263
+ * Edit result
264
+ */
265
+ interface EditResult {
266
+ success: boolean;
267
+ path: string;
268
+ changesCount: number;
269
+ backupPath?: string | undefined;
270
+ /** Original content before edit (for diff generation) */
271
+ originalContent: string;
272
+ /** New content after edit (for diff generation) */
273
+ newContent: string;
274
+ }
275
+ /**
276
+ * Path validation result
277
+ */
278
+ interface PathValidation {
279
+ isValid: boolean;
280
+ error?: string;
281
+ normalizedPath?: string;
282
+ }
283
+ /**
284
+ * File system configuration
285
+ */
286
+ interface FileSystemConfig {
287
+ /** Allowed base paths */
288
+ allowedPaths: string[];
289
+ /** Blocked paths (relative to allowed paths) */
290
+ blockedPaths: string[];
291
+ /** Blocked file extensions */
292
+ blockedExtensions: string[];
293
+ /** Maximum file size in bytes */
294
+ maxFileSize: number;
295
+ /** Enable automatic backups */
296
+ enableBackups: boolean;
297
+ /** Backup directory absolute path (required when enableBackups is true - provided by CLI enrichment) */
298
+ backupPath?: string | undefined;
299
+ /** Backup retention period in days (default: 7) */
300
+ backupRetentionDays: number;
301
+ /** Working directory for glob/grep operations (defaults to process.cwd()) */
302
+ workingDirectory?: string | undefined;
303
+ }
304
+
305
+ /**
306
+ * FileSystem Service
307
+ *
308
+ * Secure file system operations for Dexto internal tools
309
+ */
310
+
311
+ /**
312
+ * FileSystemService - Handles all file system operations with security checks
313
+ *
314
+ * This service receives fully-validated configuration from the FileSystem Tools Factory.
315
+ * All defaults have been applied by the factory's schema, so the service trusts the config
316
+ * and uses it as-is without any fallback logic.
317
+ *
318
+ * TODO: instantiate only when internal file tools are enabled to avoid file dependencies which won't work in serverless
319
+ */
320
+ declare class FileSystemService {
321
+ private config;
322
+ private pathValidator;
323
+ private initialized;
324
+ private initPromise;
325
+ private logger;
326
+ private directoryApprovalChecker?;
327
+ /**
328
+ * Create a new FileSystemService with validated configuration.
329
+ *
330
+ * @param config - Fully-validated configuration from the factory schema.
331
+ * All required fields have values, defaults already applied.
332
+ * @param logger - Logger instance for this service
333
+ */
334
+ constructor(config: FileSystemConfig, logger: Logger);
335
+ /**
336
+ * Get backup directory path (context-aware with optional override)
337
+ * TODO: Migrate to explicit configuration via CLI enrichment layer (per-agent paths)
338
+ */
339
+ private getBackupDir;
340
+ /**
341
+ * Get the effective working directory for file operations.
342
+ * Falls back to process.cwd() if not configured.
343
+ */
344
+ getWorkingDirectory(): string;
345
+ /**
346
+ * Initialize the service.
347
+ * Safe to call multiple times - subsequent calls return the same promise.
348
+ */
349
+ initialize(): Promise<void>;
350
+ /**
351
+ * Internal initialization logic.
352
+ */
353
+ private doInitialize;
354
+ /**
355
+ * Ensure the service is initialized before use.
356
+ * Tools should call this at the start of their execute methods.
357
+ * Safe to call multiple times - will await the same initialization promise.
358
+ */
359
+ ensureInitialized(): Promise<void>;
360
+ /**
361
+ * Set a callback to check if a path is in an approved directory.
362
+ * This allows PathValidator to consult ApprovalManager without a direct dependency.
363
+ *
364
+ * @param checker Function that returns true if path is in an approved directory
365
+ */
366
+ setDirectoryApprovalChecker(checker: (filePath: string) => boolean): void;
367
+ /**
368
+ * Update the working directory at runtime (e.g., when workspace changes).
369
+ * Rebuilds the PathValidator so allowed/blocked path roots are recalculated.
370
+ */
371
+ setWorkingDirectory(workingDirectory: string): void;
372
+ /**
373
+ * Check if a file path is within the configured allowed paths (config only).
374
+ * This is used by file tools to determine if directory approval is needed.
375
+ *
376
+ * @param filePath The file path to check (can be relative or absolute)
377
+ * @returns true if the path is within config-allowed paths, false otherwise
378
+ */
379
+ isPathWithinConfigAllowed(filePath: string): Promise<boolean>;
380
+ private validateReadPath;
381
+ private readNormalizedFile;
382
+ /**
383
+ * Read a file with validation and size limits
384
+ */
385
+ readFile(filePath: string, options?: ReadFileOptions): Promise<FileContent>;
386
+ /**
387
+ * Preview-only file read that bypasses config-allowed roots.
388
+ *
389
+ * This is intended for UI previews (diffs, create previews) shown BEFORE a user
390
+ * confirms directory access for the tool call. The returned content is UI-only
391
+ * and should not be forwarded to the LLM.
392
+ */
393
+ readFileForToolPreview(filePath: string, options?: ReadFileOptions): Promise<FileContent>;
394
+ /**
395
+ * Find files matching a glob pattern
396
+ */
397
+ globFiles(pattern: string, options?: GlobOptions): Promise<GlobResult>;
398
+ /**
399
+ * List contents of a directory (non-recursive)
400
+ */
401
+ listDirectory(dirPath: string, options?: ListDirectoryOptions): Promise<ListDirectoryResult>;
402
+ private mapWithConcurrency;
403
+ /**
404
+ * Create a directory
405
+ */
406
+ createDirectory(dirPath: string, options?: CreateDirectoryOptions): Promise<CreateDirectoryResult>;
407
+ /**
408
+ * Delete a file or directory
409
+ */
410
+ deletePath(targetPath: string, options?: DeletePathOptions): Promise<DeletePathResult>;
411
+ /**
412
+ * Rename or move a file or directory
413
+ */
414
+ renamePath(fromPath: string, toPath: string): Promise<RenamePathResult>;
415
+ /**
416
+ * Search for content in files (grep-like functionality)
417
+ */
418
+ searchContent(pattern: string, options?: GrepOptions): Promise<SearchResult>;
419
+ /**
420
+ * Write content to a file
421
+ */
422
+ writeFile(filePath: string, content: string, options?: WriteFileOptions): Promise<WriteResult>;
423
+ /**
424
+ * Edit a file by replacing text
425
+ */
426
+ editFile(filePath: string, operation: EditOperation, options?: EditFileOptions): Promise<EditResult>;
427
+ /**
428
+ * Create a backup of a file
429
+ */
430
+ private createBackup;
431
+ /**
432
+ * Clean up old backup files based on retention policy
433
+ */
434
+ cleanupOldBackups(): Promise<number>;
435
+ /**
436
+ * Get service configuration
437
+ */
438
+ getConfig(): Readonly<FileSystemConfig>;
439
+ /**
440
+ * Check if a path is allowed (async for non-blocking symlink resolution)
441
+ */
442
+ isPathAllowed(filePath: string): Promise<boolean>;
443
+ }
444
+
445
+ /**
446
+ * File Tool Types
447
+ *
448
+ * Types shared between file tools and factories.
449
+ */
450
+
451
+ /**
452
+ * Getter for a lazily-initialized {@link FileSystemService}.
453
+ * Tool factories construct tools before runtime services are available, so tools
454
+ * resolve the service on-demand using {@link ToolExecutionContext}.
455
+ */
456
+ type FileSystemServiceGetter = (context: ToolExecutionContext) => Promise<FileSystemService>;
457
+
458
+ /**
459
+ * Path Validator
460
+ *
461
+ * Security-focused path validation for file system operations
462
+ */
463
+
464
+ /**
465
+ * Callback type for checking if a path is in an approved directory.
466
+ * Used to consult ApprovalManager without creating a direct dependency.
467
+ */
468
+ type DirectoryApprovalChecker = (filePath: string) => boolean;
469
+ /**
470
+ * PathValidator - Validates file paths for security and policy compliance
471
+ *
472
+ * Security checks:
473
+ * 1. Path traversal detection (../, symbolic links)
474
+ * 2. Allowed paths enforcement (whitelist + approved directories)
475
+ * 3. Blocked paths detection (blacklist)
476
+ * 4. File extension restrictions
477
+ * 5. Absolute path normalization
478
+ *
479
+ * PathValidator can optionally consult an external approval checker (e.g., ApprovalManager)
480
+ * to determine if paths outside the config's allowed paths are accessible.
481
+ */
482
+ declare class PathValidator {
483
+ private config;
484
+ private normalizedAllowedPaths;
485
+ private normalizedBlockedPaths;
486
+ private normalizedBlockedExtensions;
487
+ private logger;
488
+ private directoryApprovalChecker;
489
+ constructor(config: FileSystemConfig, logger: Logger);
490
+ /**
491
+ * Set a callback to check if a path is in an approved directory.
492
+ * This allows PathValidator to consult ApprovalManager without a direct dependency.
493
+ *
494
+ * @param checker Function that returns true if path is in an approved directory
495
+ */
496
+ setDirectoryApprovalChecker(checker: DirectoryApprovalChecker): void;
497
+ /**
498
+ * Validate a file path for security and policy compliance
499
+ */
500
+ validatePath(filePath: string): Promise<PathValidation>;
501
+ /**
502
+ * Validate a file path for preview purposes.
503
+ *
504
+ * This is identical to {@link validatePath} except it does NOT enforce config-allowed roots.
505
+ * It still enforces:
506
+ * - traversal protection
507
+ * - blocked paths (absolute blocked paths only; relative blocked paths are resolved against
508
+ * config-allowed roots and may not match paths outside those roots)
509
+ * - blocked extensions
510
+ *
511
+ * Used for generating UI-only previews (e.g., diffs) before the user approves directory access.
512
+ */
513
+ validatePathForPreview(filePath: string): Promise<PathValidation>;
514
+ private validatePathInternal;
515
+ /**
516
+ * Check if path contains traversal attempts
517
+ */
518
+ private hasPathTraversal;
519
+ /**
520
+ * Check if path is within allowed paths (whitelist check)
521
+ * Also consults the directory approval checker if configured.
522
+ * Uses the sync version since the path is already normalized at this point.
523
+ */
524
+ private isPathAllowed;
525
+ /**
526
+ * Check if path matches blocked patterns (blacklist check)
527
+ */
528
+ private isPathBlocked;
529
+ /**
530
+ * Quick check if a path is allowed (for internal use)
531
+ * Note: This assumes the path is already normalized/canonicalized
532
+ */
533
+ isPathAllowedQuick(normalizedPath: string): boolean;
534
+ /**
535
+ * Synchronous path allowed check (for already-normalized paths)
536
+ * This is used internally when we already have a canonicalized path
537
+ */
538
+ private isPathAllowedSync;
539
+ /**
540
+ * Check if a file path is within the configured allowed paths (from config only).
541
+ * This method does NOT consult ApprovalManager - it only checks the static config paths.
542
+ *
543
+ * This is used by file tools to determine if a path needs directory approval.
544
+ * Paths within config-allowed directories don't need directory approval prompts.
545
+ *
546
+ * @param filePath The file path to check (can be relative or absolute)
547
+ * @returns true if the path is within config-allowed paths, false otherwise
548
+ */
549
+ isPathWithinAllowed(filePath: string): Promise<boolean>;
550
+ /**
551
+ * Check if path is within config-allowed paths only (no approval checker).
552
+ * Used for prompting decisions.
553
+ */
554
+ private isInConfigAllowedPaths;
555
+ /**
556
+ * Get normalized allowed paths
557
+ */
558
+ getAllowedPaths(): string[];
559
+ /**
560
+ * Get blocked paths
561
+ */
562
+ getBlockedPaths(): string[];
563
+ }
564
+
565
+ /**
566
+ * FileSystem Service Errors
567
+ *
568
+ * Error classes for file system operations
569
+ */
570
+
571
+ /**
572
+ * Factory class for creating FileSystem-related errors
573
+ */
574
+ declare class FileSystemError {
575
+ private constructor();
576
+ /**
577
+ * File not found error
578
+ */
579
+ static fileNotFound(path: string): DextoRuntimeError;
580
+ /**
581
+ * Directory not found error
582
+ */
583
+ static directoryNotFound(path: string): DextoRuntimeError;
584
+ /**
585
+ * Permission denied error
586
+ */
587
+ static permissionDenied(path: string, operation: string): DextoRuntimeError;
588
+ /**
589
+ * Path not allowed error
590
+ */
591
+ static pathNotAllowed(path: string, allowedPaths: string[]): DextoRuntimeError;
592
+ /**
593
+ * Path blocked error
594
+ */
595
+ static pathBlocked(path: string, reason: string): DextoRuntimeError;
596
+ /**
597
+ * Invalid path error
598
+ */
599
+ static invalidPath(path: string, reason: string): DextoRuntimeError;
600
+ /**
601
+ * Path traversal detected
602
+ */
603
+ static pathTraversal(path: string): DextoRuntimeError;
604
+ /**
605
+ * Invalid file extension error
606
+ */
607
+ static invalidExtension(path: string, blockedExtensions: string[]): DextoRuntimeError;
608
+ /**
609
+ * File too large error
610
+ */
611
+ static fileTooLarge(path: string, size: number, maxSize: number): DextoRuntimeError;
612
+ /**
613
+ * Too many results error
614
+ */
615
+ static tooManyResults(operation: string, count: number, maxResults: number): DextoRuntimeError;
616
+ /**
617
+ * Read operation failed
618
+ */
619
+ static readFailed(path: string, cause: string): DextoRuntimeError;
620
+ /**
621
+ * List directory operation failed
622
+ */
623
+ static listFailed(path: string, cause: string): DextoRuntimeError;
624
+ /**
625
+ * Create directory operation failed
626
+ */
627
+ static createDirFailed(path: string, cause: string): DextoRuntimeError;
628
+ /**
629
+ * Delete operation failed
630
+ */
631
+ static deleteFailed(path: string, cause: string): DextoRuntimeError;
632
+ /**
633
+ * Rename operation failed
634
+ */
635
+ static renameFailed(path: string, cause: string): DextoRuntimeError;
636
+ /**
637
+ * Write operation failed
638
+ */
639
+ static writeFailed(path: string, cause: string): DextoRuntimeError;
640
+ /**
641
+ * Backup creation failed
642
+ */
643
+ static backupFailed(path: string, cause: string): DextoRuntimeError;
644
+ /**
645
+ * Edit operation failed
646
+ */
647
+ static editFailed(path: string, cause: string): DextoRuntimeError;
648
+ /**
649
+ * String not unique error
650
+ */
651
+ static stringNotUnique(path: string, searchString: string, occurrences: number): DextoRuntimeError;
652
+ /**
653
+ * String not found error
654
+ */
655
+ static stringNotFound(path: string, searchString: string): DextoRuntimeError;
656
+ /**
657
+ * Glob operation failed
658
+ */
659
+ static globFailed(pattern: string, cause: string): DextoRuntimeError;
660
+ /**
661
+ * Search operation failed
662
+ */
663
+ static searchFailed(pattern: string, cause: string): DextoRuntimeError;
664
+ /**
665
+ * Invalid pattern error
666
+ */
667
+ static invalidPattern(pattern: string, cause: string): DextoRuntimeError;
668
+ /**
669
+ * Regex timeout error
670
+ */
671
+ static regexTimeout(pattern: string): DextoRuntimeError;
672
+ /**
673
+ * Invalid configuration error
674
+ */
675
+ static invalidConfig(reason: string): DextoRuntimeError;
676
+ /**
677
+ * Service not initialized error
678
+ */
679
+ static notInitialized(): DextoRuntimeError;
680
+ }
681
+
682
+ /**
683
+ * FileSystem Service Error Codes
684
+ *
685
+ * Standardized error codes for file system operations
686
+ */
687
+ declare enum FileSystemErrorCode {
688
+ FILE_NOT_FOUND = "FILESYSTEM_FILE_NOT_FOUND",
689
+ DIRECTORY_NOT_FOUND = "FILESYSTEM_DIRECTORY_NOT_FOUND",
690
+ PERMISSION_DENIED = "FILESYSTEM_PERMISSION_DENIED",
691
+ PATH_NOT_ALLOWED = "FILESYSTEM_PATH_NOT_ALLOWED",
692
+ PATH_BLOCKED = "FILESYSTEM_PATH_BLOCKED",
693
+ INVALID_PATH = "FILESYSTEM_INVALID_PATH",
694
+ PATH_TRAVERSAL_DETECTED = "FILESYSTEM_PATH_TRAVERSAL_DETECTED",
695
+ INVALID_FILE_EXTENSION = "FILESYSTEM_INVALID_FILE_EXTENSION",
696
+ INVALID_ENCODING = "FILESYSTEM_INVALID_ENCODING",
697
+ FILE_TOO_LARGE = "FILESYSTEM_FILE_TOO_LARGE",
698
+ TOO_MANY_RESULTS = "FILESYSTEM_TOO_MANY_RESULTS",
699
+ READ_FAILED = "FILESYSTEM_READ_FAILED",
700
+ LIST_FAILED = "FILESYSTEM_LIST_FAILED",
701
+ WRITE_FAILED = "FILESYSTEM_WRITE_FAILED",
702
+ CREATE_DIR_FAILED = "FILESYSTEM_CREATE_DIR_FAILED",
703
+ DELETE_FAILED = "FILESYSTEM_DELETE_FAILED",
704
+ RENAME_FAILED = "FILESYSTEM_RENAME_FAILED",
705
+ BACKUP_FAILED = "FILESYSTEM_BACKUP_FAILED",
706
+ EDIT_FAILED = "FILESYSTEM_EDIT_FAILED",
707
+ STRING_NOT_UNIQUE = "FILESYSTEM_STRING_NOT_UNIQUE",
708
+ STRING_NOT_FOUND = "FILESYSTEM_STRING_NOT_FOUND",
709
+ GLOB_FAILED = "FILESYSTEM_GLOB_FAILED",
710
+ SEARCH_FAILED = "FILESYSTEM_SEARCH_FAILED",
711
+ INVALID_PATTERN = "FILESYSTEM_INVALID_PATTERN",
712
+ REGEX_TIMEOUT = "FILESYSTEM_REGEX_TIMEOUT",
713
+ INVALID_CONFIG = "FILESYSTEM_INVALID_CONFIG",
714
+ SERVICE_NOT_INITIALIZED = "FILESYSTEM_SERVICE_NOT_INITIALIZED"
715
+ }
716
+
717
+ /**
718
+ * Read File Tool
719
+ *
720
+ * Internal tool for reading file contents with size limits and pagination
721
+ */
722
+
723
+ declare const ReadFileInputSchema: z.ZodObject<{
724
+ file_path: z.ZodString;
725
+ limit: z.ZodOptional<z.ZodNumber>;
726
+ offset: z.ZodOptional<z.ZodNumber>;
727
+ }, "strict", z.ZodTypeAny, {
728
+ file_path: string;
729
+ limit?: number | undefined;
730
+ offset?: number | undefined;
731
+ }, {
732
+ file_path: string;
733
+ limit?: number | undefined;
734
+ offset?: number | undefined;
735
+ }>;
736
+ /**
737
+ * Create the read_file internal tool with directory approval support
738
+ */
739
+ declare function createReadFileTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof ReadFileInputSchema>;
740
+
741
+ /**
742
+ * Write File Tool
743
+ *
744
+ * Internal tool for writing content to files (requires approval)
745
+ */
746
+
747
+ declare const WriteFileInputSchema: z.ZodObject<{
748
+ file_path: z.ZodString;
749
+ content: z.ZodString;
750
+ create_dirs: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
751
+ encoding: z.ZodDefault<z.ZodOptional<z.ZodEnum<["utf-8", "ascii", "latin1", "utf16le"]>>>;
752
+ }, "strict", z.ZodTypeAny, {
753
+ content: string;
754
+ encoding: "ascii" | "utf-8" | "utf16le" | "latin1";
755
+ file_path: string;
756
+ create_dirs: boolean;
757
+ }, {
758
+ content: string;
759
+ file_path: string;
760
+ encoding?: "ascii" | "utf-8" | "utf16le" | "latin1" | undefined;
761
+ create_dirs?: boolean | undefined;
762
+ }>;
763
+ /**
764
+ * Create the write_file internal tool with directory approval support
765
+ */
766
+ declare function createWriteFileTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof WriteFileInputSchema>;
767
+
768
+ /**
769
+ * Edit File Tool
770
+ *
771
+ * Internal tool for editing files by replacing text (requires approval)
772
+ */
773
+
774
+ declare const EditFileInputSchema: z.ZodObject<{
775
+ file_path: z.ZodString;
776
+ old_string: z.ZodString;
777
+ new_string: z.ZodString;
778
+ replace_all: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
779
+ }, "strict", z.ZodTypeAny, {
780
+ file_path: string;
781
+ old_string: string;
782
+ new_string: string;
783
+ replace_all: boolean;
784
+ }, {
785
+ file_path: string;
786
+ old_string: string;
787
+ new_string: string;
788
+ replace_all?: boolean | undefined;
789
+ }>;
790
+ /**
791
+ * Create the edit_file internal tool with directory approval support
792
+ */
793
+ declare function createEditFileTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof EditFileInputSchema>;
794
+
795
+ /**
796
+ * Glob Files Tool
797
+ *
798
+ * Internal tool for finding files using glob patterns
799
+ */
800
+
801
+ declare const GlobFilesInputSchema: z.ZodObject<{
802
+ pattern: z.ZodString;
803
+ path: z.ZodOptional<z.ZodString>;
804
+ max_results: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
805
+ }, "strict", z.ZodTypeAny, {
806
+ pattern: string;
807
+ max_results: number;
808
+ path?: string | undefined;
809
+ }, {
810
+ pattern: string;
811
+ path?: string | undefined;
812
+ max_results?: number | undefined;
813
+ }>;
814
+ /**
815
+ * Create the glob_files internal tool with directory approval support
816
+ */
817
+ declare function createGlobFilesTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof GlobFilesInputSchema>;
818
+
819
+ /**
820
+ * Grep Content Tool
821
+ *
822
+ * Internal tool for searching file contents using regex patterns
823
+ */
824
+
825
+ declare const GrepContentInputSchema: z.ZodObject<{
826
+ pattern: z.ZodString;
827
+ path: z.ZodOptional<z.ZodString>;
828
+ glob: z.ZodOptional<z.ZodString>;
829
+ context_lines: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
830
+ case_insensitive: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
831
+ max_results: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
832
+ }, "strict", z.ZodTypeAny, {
833
+ pattern: string;
834
+ max_results: number;
835
+ context_lines: number;
836
+ case_insensitive: boolean;
837
+ path?: string | undefined;
838
+ glob?: string | undefined;
839
+ }, {
840
+ pattern: string;
841
+ path?: string | undefined;
842
+ max_results?: number | undefined;
843
+ glob?: string | undefined;
844
+ context_lines?: number | undefined;
845
+ case_insensitive?: boolean | undefined;
846
+ }>;
847
+ /**
848
+ * Create the grep_content internal tool with directory approval support
849
+ */
850
+ declare function createGrepContentTool(getFileSystemService: FileSystemServiceGetter): Tool<typeof GrepContentInputSchema>;
851
+
852
+ export { type BufferEncoding, type CreateDirectoryOptions, type CreateDirectoryResult, type DeletePathOptions, type DeletePathResult, type DirectoryEntry, type EditFileOptions, type EditOperation, type EditResult, type FileContent, type FileMetadata, type FileSystemConfig, FileSystemError, FileSystemErrorCode, FileSystemService, type FileSystemServiceGetter, type FileSystemToolsConfig, FileSystemToolsConfigSchema, type GlobOptions, type GlobResult, type GrepOptions, type ListDirectoryOptions, type ListDirectoryResult, type PathValidation, PathValidator, type ReadFileOptions, type RenamePathResult, type SearchMatch, type SearchResult, type WriteFileOptions, type WriteResult, createEditFileTool, createGlobFilesTool, createGrepContentTool, createReadFileTool, createWriteFileTool, fileSystemToolsFactory };