@dexto/tools-filesystem 1.5.8 → 1.6.1

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 (95) hide show
  1. package/dist/directory-approval.cjs +98 -0
  2. package/dist/directory-approval.d.ts +24 -0
  3. package/dist/directory-approval.d.ts.map +1 -0
  4. package/dist/directory-approval.integration.test.cjs +175 -390
  5. package/dist/directory-approval.integration.test.d.ts +14 -2
  6. package/dist/directory-approval.integration.test.d.ts.map +1 -0
  7. package/dist/directory-approval.integration.test.js +178 -390
  8. package/dist/directory-approval.js +63 -0
  9. package/dist/edit-file-tool.cjs +109 -120
  10. package/dist/edit-file-tool.d.ts +22 -9
  11. package/dist/edit-file-tool.d.ts.map +1 -0
  12. package/dist/edit-file-tool.js +116 -110
  13. package/dist/edit-file-tool.test.cjs +109 -29
  14. package/dist/edit-file-tool.test.d.ts +7 -2
  15. package/dist/edit-file-tool.test.d.ts.map +1 -0
  16. package/dist/edit-file-tool.test.js +109 -29
  17. package/dist/error-codes.cjs +4 -0
  18. package/dist/error-codes.d.ts +6 -3
  19. package/dist/error-codes.d.ts.map +1 -0
  20. package/dist/error-codes.js +4 -0
  21. package/dist/errors.cjs +48 -0
  22. package/dist/errors.d.ts +20 -7
  23. package/dist/errors.d.ts.map +1 -0
  24. package/dist/errors.js +48 -0
  25. package/dist/file-tool-types.d.ts +8 -40
  26. package/dist/file-tool-types.d.ts.map +1 -0
  27. package/dist/filesystem-service.cjs +325 -10
  28. package/dist/filesystem-service.d.ts +41 -12
  29. package/dist/filesystem-service.d.ts.map +1 -0
  30. package/dist/filesystem-service.js +326 -11
  31. package/dist/filesystem-service.test.cjs +10 -2
  32. package/dist/filesystem-service.test.d.ts +7 -2
  33. package/dist/filesystem-service.test.d.ts.map +1 -0
  34. package/dist/filesystem-service.test.js +10 -2
  35. package/dist/glob-files-tool.cjs +32 -46
  36. package/dist/glob-files-tool.d.ts +19 -9
  37. package/dist/glob-files-tool.d.ts.map +1 -0
  38. package/dist/glob-files-tool.js +33 -47
  39. package/dist/grep-content-tool.cjs +40 -45
  40. package/dist/grep-content-tool.d.ts +28 -9
  41. package/dist/grep-content-tool.d.ts.map +1 -0
  42. package/dist/grep-content-tool.js +41 -46
  43. package/dist/index.cjs +6 -3
  44. package/dist/index.d.cts +852 -14
  45. package/dist/index.d.ts +11 -5
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +4 -2
  48. package/dist/path-validator.cjs +28 -2
  49. package/dist/path-validator.d.ts +20 -9
  50. package/dist/path-validator.d.ts.map +1 -0
  51. package/dist/path-validator.js +28 -2
  52. package/dist/path-validator.test.d.ts +7 -2
  53. package/dist/path-validator.test.d.ts.map +1 -0
  54. package/dist/read-file-tool.cjs +26 -59
  55. package/dist/read-file-tool.d.ts +19 -9
  56. package/dist/read-file-tool.d.ts.map +1 -0
  57. package/dist/read-file-tool.js +27 -50
  58. package/dist/tool-factory-config.cjs +61 -0
  59. package/dist/{tool-provider.d.ts → tool-factory-config.d.ts} +13 -30
  60. package/dist/tool-factory-config.d.ts.map +1 -0
  61. package/dist/tool-factory-config.js +36 -0
  62. package/dist/tool-factory.cjs +123 -0
  63. package/dist/tool-factory.d.ts +4 -0
  64. package/dist/tool-factory.d.ts.map +1 -0
  65. package/dist/tool-factory.js +102 -0
  66. package/dist/types.d.ts +82 -18
  67. package/dist/types.d.ts.map +1 -0
  68. package/dist/write-file-tool.cjs +93 -99
  69. package/dist/write-file-tool.d.ts +22 -9
  70. package/dist/write-file-tool.d.ts.map +1 -0
  71. package/dist/write-file-tool.js +97 -91
  72. package/dist/write-file-tool.test.cjs +139 -33
  73. package/dist/write-file-tool.test.d.ts +7 -2
  74. package/dist/write-file-tool.test.d.ts.map +1 -0
  75. package/dist/write-file-tool.test.js +139 -33
  76. package/package.json +5 -4
  77. package/dist/directory-approval.integration.test.d.cts +0 -2
  78. package/dist/edit-file-tool.d.cts +0 -17
  79. package/dist/edit-file-tool.test.d.cts +0 -2
  80. package/dist/error-codes.d.cts +0 -32
  81. package/dist/errors.d.cts +0 -112
  82. package/dist/file-tool-types.d.cts +0 -46
  83. package/dist/filesystem-service.d.cts +0 -112
  84. package/dist/filesystem-service.test.d.cts +0 -2
  85. package/dist/glob-files-tool.d.cts +0 -17
  86. package/dist/grep-content-tool.d.cts +0 -17
  87. package/dist/path-validator.d.cts +0 -97
  88. package/dist/path-validator.test.d.cts +0 -2
  89. package/dist/read-file-tool.d.cts +0 -17
  90. package/dist/tool-provider.cjs +0 -123
  91. package/dist/tool-provider.d.cts +0 -77
  92. package/dist/tool-provider.js +0 -99
  93. package/dist/types.d.cts +0 -178
  94. package/dist/write-file-tool.d.cts +0 -17
  95. package/dist/write-file-tool.test.d.cts +0 -2
@@ -1,99 +0,0 @@
1
- import { z } from "zod";
2
- import { FileSystemService } from "./filesystem-service.js";
3
- import { createReadFileTool } from "./read-file-tool.js";
4
- import { createWriteFileTool } from "./write-file-tool.js";
5
- import { createEditFileTool } from "./edit-file-tool.js";
6
- import { createGlobFilesTool } from "./glob-files-tool.js";
7
- import { createGrepContentTool } from "./grep-content-tool.js";
8
- const DEFAULT_ALLOWED_PATHS = ["."];
9
- const DEFAULT_BLOCKED_PATHS = [".git", "node_modules/.bin", ".env"];
10
- const DEFAULT_BLOCKED_EXTENSIONS = [".exe", ".dll", ".so"];
11
- const DEFAULT_MAX_FILE_SIZE = 10 * 1024 * 1024;
12
- const DEFAULT_ENABLE_BACKUPS = false;
13
- const DEFAULT_BACKUP_RETENTION_DAYS = 7;
14
- const FILESYSTEM_TOOL_NAMES = [
15
- "read_file",
16
- "write_file",
17
- "edit_file",
18
- "glob_files",
19
- "grep_content"
20
- ];
21
- const FileSystemToolsConfigSchema = z.object({
22
- type: z.literal("filesystem-tools"),
23
- allowedPaths: z.array(z.string()).default(DEFAULT_ALLOWED_PATHS).describe("List of allowed base paths for file operations"),
24
- blockedPaths: z.array(z.string()).default(DEFAULT_BLOCKED_PATHS).describe("List of blocked paths to exclude from operations"),
25
- blockedExtensions: z.array(z.string()).default(DEFAULT_BLOCKED_EXTENSIONS).describe("List of blocked file extensions"),
26
- maxFileSize: z.number().int().positive().default(DEFAULT_MAX_FILE_SIZE).describe(
27
- `Maximum file size in bytes (default: ${DEFAULT_MAX_FILE_SIZE / 1024 / 1024}MB)`
28
- ),
29
- workingDirectory: z.string().optional().describe("Working directory for file operations (defaults to process.cwd())"),
30
- enableBackups: z.boolean().default(DEFAULT_ENABLE_BACKUPS).describe("Enable automatic backups of modified files"),
31
- backupPath: z.string().optional().describe("Absolute path for storing file backups (if enableBackups is true)"),
32
- backupRetentionDays: z.number().int().positive().default(DEFAULT_BACKUP_RETENTION_DAYS).describe(
33
- `Number of days to retain backup files (default: ${DEFAULT_BACKUP_RETENTION_DAYS})`
34
- ),
35
- enabledTools: z.array(z.enum(FILESYSTEM_TOOL_NAMES)).optional().describe(
36
- `Subset of tools to enable. If not specified, all tools are enabled. Available: ${FILESYSTEM_TOOL_NAMES.join(", ")}`
37
- )
38
- }).strict();
39
- const fileSystemToolsProvider = {
40
- type: "filesystem-tools",
41
- configSchema: FileSystemToolsConfigSchema,
42
- create: (config, context) => {
43
- const { logger, services } = context;
44
- logger.debug("Creating FileSystemService for filesystem tools");
45
- const fileSystemService = new FileSystemService(
46
- {
47
- allowedPaths: config.allowedPaths,
48
- blockedPaths: config.blockedPaths,
49
- blockedExtensions: config.blockedExtensions,
50
- maxFileSize: config.maxFileSize,
51
- workingDirectory: config.workingDirectory || process.cwd(),
52
- enableBackups: config.enableBackups,
53
- backupPath: config.backupPath,
54
- backupRetentionDays: config.backupRetentionDays
55
- },
56
- logger
57
- );
58
- fileSystemService.initialize().catch((error) => {
59
- logger.error(`Failed to initialize FileSystemService: ${error.message}`);
60
- });
61
- logger.debug("FileSystemService created - initialization will complete on first tool use");
62
- const approvalManager = services?.approvalManager;
63
- if (approvalManager) {
64
- const approvalChecker = (filePath) => {
65
- return approvalManager.isDirectoryApproved(filePath);
66
- };
67
- fileSystemService.setDirectoryApprovalChecker(approvalChecker);
68
- logger.debug("Directory approval checker configured for FileSystemService");
69
- }
70
- const directoryApproval = approvalManager ? {
71
- isSessionApproved: (filePath) => approvalManager.isDirectorySessionApproved(filePath),
72
- addApproved: (directory, type) => approvalManager.addApprovedDirectory(directory, type)
73
- } : void 0;
74
- const fileToolOptions = {
75
- fileSystemService,
76
- directoryApproval
77
- };
78
- const toolCreators = {
79
- read_file: () => createReadFileTool(fileToolOptions),
80
- write_file: () => createWriteFileTool(fileToolOptions),
81
- edit_file: () => createEditFileTool(fileToolOptions),
82
- glob_files: () => createGlobFilesTool(fileToolOptions),
83
- grep_content: () => createGrepContentTool(fileToolOptions)
84
- };
85
- const toolsToCreate = config.enabledTools ?? FILESYSTEM_TOOL_NAMES;
86
- if (config.enabledTools) {
87
- logger.debug(`Creating subset of filesystem tools: ${toolsToCreate.join(", ")}`);
88
- }
89
- return toolsToCreate.map((toolName) => toolCreators[toolName]());
90
- },
91
- metadata: {
92
- displayName: "FileSystem Tools",
93
- description: "File system operations (read, write, edit, glob, grep)",
94
- category: "filesystem"
95
- }
96
- };
97
- export {
98
- fileSystemToolsProvider
99
- };
package/dist/types.d.cts DELETED
@@ -1,178 +0,0 @@
1
- /**
2
- * FileSystem Service Types
3
- *
4
- * Types and interfaces for file system operations including reading, writing,
5
- * searching, and validation.
6
- */
7
- type BufferEncoding = 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex';
8
- /**
9
- * File content with metadata
10
- */
11
- interface FileContent {
12
- content: string;
13
- lines: number;
14
- encoding: string;
15
- mimeType?: string;
16
- truncated: boolean;
17
- size: number;
18
- }
19
- /**
20
- * Options for reading files
21
- */
22
- interface ReadFileOptions {
23
- /** Maximum number of lines to read */
24
- limit?: number | undefined;
25
- /** Starting line number (1-based) */
26
- offset?: number | undefined;
27
- /** File encoding (default: utf-8) */
28
- encoding?: BufferEncoding | undefined;
29
- }
30
- /**
31
- * File metadata for glob results
32
- */
33
- interface FileMetadata {
34
- path: string;
35
- size: number;
36
- modified: Date;
37
- isDirectory: boolean;
38
- }
39
- /**
40
- * Options for glob operations
41
- */
42
- interface GlobOptions {
43
- /** Base directory to search from */
44
- cwd?: string | undefined;
45
- /** Maximum number of results */
46
- maxResults?: number | undefined;
47
- /** Include file metadata */
48
- includeMetadata?: boolean | undefined;
49
- }
50
- /**
51
- * Glob result
52
- */
53
- interface GlobResult {
54
- files: FileMetadata[];
55
- truncated: boolean;
56
- totalFound: number;
57
- }
58
- /**
59
- * Search match with context
60
- */
61
- interface SearchMatch {
62
- file: string;
63
- lineNumber: number;
64
- line: string;
65
- context?: {
66
- before: string[];
67
- after: string[];
68
- };
69
- }
70
- /**
71
- * Options for content search (grep)
72
- */
73
- interface GrepOptions {
74
- /** Base directory to search */
75
- path?: string | undefined;
76
- /** Glob pattern to filter files */
77
- glob?: string | undefined;
78
- /** Number of context lines before/after match */
79
- contextLines?: number | undefined;
80
- /** Case-insensitive search */
81
- caseInsensitive?: boolean | undefined;
82
- /** Maximum number of results */
83
- maxResults?: number | undefined;
84
- /** Include line numbers */
85
- lineNumbers?: boolean | undefined;
86
- }
87
- /**
88
- * Search result
89
- */
90
- interface SearchResult {
91
- matches: SearchMatch[];
92
- totalMatches: number;
93
- truncated: boolean;
94
- filesSearched: number;
95
- }
96
- /**
97
- * Options for writing files
98
- */
99
- interface WriteFileOptions {
100
- /** Create parent directories if they don't exist */
101
- createDirs?: boolean | undefined;
102
- /** File encoding (default: utf-8) */
103
- encoding?: BufferEncoding | undefined;
104
- /** Create backup before overwriting */
105
- backup?: boolean | undefined;
106
- }
107
- /**
108
- * Write result
109
- */
110
- interface WriteResult {
111
- success: boolean;
112
- path: string;
113
- bytesWritten: number;
114
- backupPath?: string | undefined;
115
- /** Original content if file was overwritten (undefined for new files) */
116
- originalContent?: string | undefined;
117
- }
118
- /**
119
- * Edit operation
120
- */
121
- interface EditOperation {
122
- oldString: string;
123
- newString: string;
124
- replaceAll?: boolean | undefined;
125
- }
126
- /**
127
- * Options for editing files
128
- */
129
- interface EditFileOptions {
130
- /** Create backup before editing */
131
- backup?: boolean;
132
- /** File encoding */
133
- encoding?: BufferEncoding;
134
- }
135
- /**
136
- * Edit result
137
- */
138
- interface EditResult {
139
- success: boolean;
140
- path: string;
141
- changesCount: number;
142
- backupPath?: string | undefined;
143
- /** Original content before edit (for diff generation) */
144
- originalContent: string;
145
- /** New content after edit (for diff generation) */
146
- newContent: string;
147
- }
148
- /**
149
- * Path validation result
150
- */
151
- interface PathValidation {
152
- isValid: boolean;
153
- error?: string;
154
- normalizedPath?: string;
155
- }
156
- /**
157
- * File system configuration
158
- */
159
- interface FileSystemConfig {
160
- /** Allowed base paths */
161
- allowedPaths: string[];
162
- /** Blocked paths (relative to allowed paths) */
163
- blockedPaths: string[];
164
- /** Blocked file extensions */
165
- blockedExtensions: string[];
166
- /** Maximum file size in bytes */
167
- maxFileSize: number;
168
- /** Enable automatic backups */
169
- enableBackups: boolean;
170
- /** Backup directory absolute path (required when enableBackups is true - provided by CLI enrichment) */
171
- backupPath?: string | undefined;
172
- /** Backup retention period in days (default: 7) */
173
- backupRetentionDays: number;
174
- /** Working directory for glob/grep operations (defaults to process.cwd()) */
175
- workingDirectory?: string | undefined;
176
- }
177
-
178
- export type { BufferEncoding, EditFileOptions, EditOperation, EditResult, FileContent, FileMetadata, FileSystemConfig, GlobOptions, GlobResult, GrepOptions, PathValidation, ReadFileOptions, SearchMatch, SearchResult, WriteFileOptions, WriteResult };
@@ -1,17 +0,0 @@
1
- import { InternalTool } from '@dexto/core';
2
- import { FileToolOptions } from './file-tool-types.cjs';
3
- import './filesystem-service.cjs';
4
- import './types.cjs';
5
-
6
- /**
7
- * Write File Tool
8
- *
9
- * Internal tool for writing content to files (requires approval)
10
- */
11
-
12
- /**
13
- * Create the write_file internal tool with directory approval support
14
- */
15
- declare function createWriteFileTool(options: FileToolOptions): InternalTool;
16
-
17
- export { createWriteFileTool };
@@ -1,2 +0,0 @@
1
-
2
- export { }