@dexto/tools-filesystem 1.5.8 → 1.6.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.
Files changed (83) hide show
  1. package/dist/directory-approval.cjs +94 -0
  2. package/dist/directory-approval.d.cts +22 -0
  3. package/dist/directory-approval.d.ts +20 -0
  4. package/dist/directory-approval.d.ts.map +1 -0
  5. package/dist/directory-approval.integration.test.cjs +303 -269
  6. package/dist/directory-approval.integration.test.d.ts +14 -2
  7. package/dist/directory-approval.integration.test.d.ts.map +1 -0
  8. package/dist/directory-approval.integration.test.js +309 -270
  9. package/dist/directory-approval.js +59 -0
  10. package/dist/edit-file-tool.cjs +57 -90
  11. package/dist/edit-file-tool.d.cts +20 -3
  12. package/dist/edit-file-tool.d.ts +22 -9
  13. package/dist/edit-file-tool.d.ts.map +1 -0
  14. package/dist/edit-file-tool.js +53 -76
  15. package/dist/edit-file-tool.test.cjs +66 -29
  16. package/dist/edit-file-tool.test.d.ts +7 -2
  17. package/dist/edit-file-tool.test.d.ts.map +1 -0
  18. package/dist/edit-file-tool.test.js +66 -29
  19. package/dist/error-codes.d.ts +2 -3
  20. package/dist/error-codes.d.ts.map +1 -0
  21. package/dist/errors.d.ts +4 -7
  22. package/dist/errors.d.ts.map +1 -0
  23. package/dist/file-tool-types.d.cts +7 -35
  24. package/dist/file-tool-types.d.ts +8 -40
  25. package/dist/file-tool-types.d.ts.map +1 -0
  26. package/dist/filesystem-service.cjs +18 -1
  27. package/dist/filesystem-service.d.cts +11 -6
  28. package/dist/filesystem-service.d.ts +14 -12
  29. package/dist/filesystem-service.d.ts.map +1 -0
  30. package/dist/filesystem-service.js +18 -1
  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 +22 -47
  36. package/dist/glob-files-tool.d.cts +17 -3
  37. package/dist/glob-files-tool.d.ts +19 -9
  38. package/dist/glob-files-tool.d.ts.map +1 -0
  39. package/dist/glob-files-tool.js +23 -48
  40. package/dist/grep-content-tool.cjs +29 -46
  41. package/dist/grep-content-tool.d.cts +26 -3
  42. package/dist/grep-content-tool.d.ts +28 -9
  43. package/dist/grep-content-tool.d.ts.map +1 -0
  44. package/dist/grep-content-tool.js +30 -47
  45. package/dist/index.cjs +3 -3
  46. package/dist/index.d.cts +4 -2
  47. package/dist/index.d.ts +10 -5
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +2 -2
  50. package/dist/path-validator.d.cts +2 -2
  51. package/dist/path-validator.d.ts +6 -9
  52. package/dist/path-validator.d.ts.map +1 -0
  53. package/dist/path-validator.test.d.ts +7 -2
  54. package/dist/path-validator.test.d.ts.map +1 -0
  55. package/dist/read-file-tool.cjs +21 -60
  56. package/dist/read-file-tool.d.cts +17 -3
  57. package/dist/read-file-tool.d.ts +19 -9
  58. package/dist/read-file-tool.d.ts.map +1 -0
  59. package/dist/read-file-tool.js +22 -51
  60. package/dist/tool-factory-config.cjs +61 -0
  61. package/dist/{tool-provider.d.ts → tool-factory-config.d.cts} +9 -23
  62. package/dist/{tool-provider.d.cts → tool-factory-config.d.ts} +13 -30
  63. package/dist/tool-factory-config.d.ts.map +1 -0
  64. package/dist/tool-factory-config.js +36 -0
  65. package/dist/tool-factory.cjs +102 -0
  66. package/dist/tool-factory.d.cts +7 -0
  67. package/dist/tool-factory.d.ts +4 -0
  68. package/dist/tool-factory.d.ts.map +1 -0
  69. package/dist/tool-factory.js +81 -0
  70. package/dist/types.d.ts +17 -18
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/write-file-tool.cjs +45 -73
  73. package/dist/write-file-tool.d.cts +20 -3
  74. package/dist/write-file-tool.d.ts +22 -9
  75. package/dist/write-file-tool.d.ts.map +1 -0
  76. package/dist/write-file-tool.js +46 -68
  77. package/dist/write-file-tool.test.cjs +76 -32
  78. package/dist/write-file-tool.test.d.ts +7 -2
  79. package/dist/write-file-tool.test.d.ts.map +1 -0
  80. package/dist/write-file-tool.test.js +76 -32
  81. package/package.json +4 -3
  82. package/dist/tool-provider.cjs +0 -123
  83. package/dist/tool-provider.js +0 -99
@@ -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
- };