@dexto/tools-filesystem 1.5.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 (62) hide show
  1. package/LICENSE +44 -0
  2. package/dist/directory-approval.integration.test.cjs +467 -0
  3. package/dist/directory-approval.integration.test.d.cts +2 -0
  4. package/dist/directory-approval.integration.test.d.ts +2 -0
  5. package/dist/directory-approval.integration.test.js +444 -0
  6. package/dist/edit-file-tool.cjs +181 -0
  7. package/dist/edit-file-tool.d.cts +17 -0
  8. package/dist/edit-file-tool.d.ts +17 -0
  9. package/dist/edit-file-tool.js +147 -0
  10. package/dist/error-codes.cjs +53 -0
  11. package/dist/error-codes.d.cts +32 -0
  12. package/dist/error-codes.d.ts +32 -0
  13. package/dist/error-codes.js +29 -0
  14. package/dist/errors.cjs +302 -0
  15. package/dist/errors.d.cts +112 -0
  16. package/dist/errors.d.ts +112 -0
  17. package/dist/errors.js +278 -0
  18. package/dist/file-tool-types.cjs +16 -0
  19. package/dist/file-tool-types.d.cts +46 -0
  20. package/dist/file-tool-types.d.ts +46 -0
  21. package/dist/file-tool-types.js +0 -0
  22. package/dist/filesystem-service.cjs +526 -0
  23. package/dist/filesystem-service.d.cts +107 -0
  24. package/dist/filesystem-service.d.ts +107 -0
  25. package/dist/filesystem-service.js +492 -0
  26. package/dist/glob-files-tool.cjs +70 -0
  27. package/dist/glob-files-tool.d.cts +16 -0
  28. package/dist/glob-files-tool.d.ts +16 -0
  29. package/dist/glob-files-tool.js +46 -0
  30. package/dist/grep-content-tool.cjs +86 -0
  31. package/dist/grep-content-tool.d.cts +16 -0
  32. package/dist/grep-content-tool.d.ts +16 -0
  33. package/dist/grep-content-tool.js +62 -0
  34. package/dist/index.cjs +55 -0
  35. package/dist/index.d.cts +14 -0
  36. package/dist/index.d.ts +14 -0
  37. package/dist/index.js +22 -0
  38. package/dist/path-validator.cjs +232 -0
  39. package/dist/path-validator.d.cts +90 -0
  40. package/dist/path-validator.d.ts +90 -0
  41. package/dist/path-validator.js +198 -0
  42. package/dist/path-validator.test.cjs +444 -0
  43. package/dist/path-validator.test.d.cts +2 -0
  44. package/dist/path-validator.test.d.ts +2 -0
  45. package/dist/path-validator.test.js +443 -0
  46. package/dist/read-file-tool.cjs +117 -0
  47. package/dist/read-file-tool.d.cts +17 -0
  48. package/dist/read-file-tool.d.ts +17 -0
  49. package/dist/read-file-tool.js +83 -0
  50. package/dist/tool-provider.cjs +108 -0
  51. package/dist/tool-provider.d.cts +74 -0
  52. package/dist/tool-provider.d.ts +74 -0
  53. package/dist/tool-provider.js +84 -0
  54. package/dist/types.cjs +16 -0
  55. package/dist/types.d.cts +172 -0
  56. package/dist/types.d.ts +172 -0
  57. package/dist/types.js +0 -0
  58. package/dist/write-file-tool.cjs +177 -0
  59. package/dist/write-file-tool.d.cts +17 -0
  60. package/dist/write-file-tool.d.ts +17 -0
  61. package/dist/write-file-tool.js +143 -0
  62. package/package.json +42 -0
@@ -0,0 +1,147 @@
1
+ import * as path from "node:path";
2
+ import { z } from "zod";
3
+ import { createPatch } from "diff";
4
+ import { ApprovalType } from "@dexto/core";
5
+ import { ToolError } from "@dexto/core";
6
+ import { ToolErrorCode } from "@dexto/core";
7
+ import { DextoRuntimeError } from "@dexto/core";
8
+ const EditFileInputSchema = z.object({
9
+ file_path: z.string().describe("Absolute path to the file to edit"),
10
+ old_string: z.string().describe("Text to replace (must be unique unless replace_all is true)"),
11
+ new_string: z.string().describe("Replacement text"),
12
+ replace_all: z.boolean().optional().default(false).describe("Replace all occurrences (default: false, requires unique match)")
13
+ }).strict();
14
+ function generateDiffPreview(filePath, originalContent, newContent) {
15
+ const unified = createPatch(filePath, originalContent, newContent, "before", "after", {
16
+ context: 3
17
+ });
18
+ const additions = (unified.match(/^\+[^+]/gm) || []).length;
19
+ const deletions = (unified.match(/^-[^-]/gm) || []).length;
20
+ return {
21
+ type: "diff",
22
+ unified,
23
+ filename: filePath,
24
+ additions,
25
+ deletions
26
+ };
27
+ }
28
+ function createEditFileTool(options) {
29
+ const { fileSystemService, directoryApproval } = options;
30
+ let pendingApprovalParentDir;
31
+ return {
32
+ id: "edit_file",
33
+ description: "Edit a file by replacing text. By default, old_string must be unique in the file (will error if found multiple times). Set replace_all=true to replace all occurrences. Automatically creates backup before editing. Requires approval. Returns success status, path, number of changes made, and backup path.",
34
+ inputSchema: EditFileInputSchema,
35
+ /**
36
+ * Check if this edit operation needs directory access approval.
37
+ * Returns custom approval request if the file is outside allowed paths.
38
+ */
39
+ getApprovalOverride: (args) => {
40
+ const { file_path } = args;
41
+ if (!file_path) return null;
42
+ const isAllowed = fileSystemService.isPathWithinConfigAllowed(file_path);
43
+ if (isAllowed) {
44
+ return null;
45
+ }
46
+ if (directoryApproval?.isSessionApproved(file_path)) {
47
+ return null;
48
+ }
49
+ const absolutePath = path.resolve(file_path);
50
+ const parentDir = path.dirname(absolutePath);
51
+ pendingApprovalParentDir = parentDir;
52
+ return {
53
+ type: ApprovalType.DIRECTORY_ACCESS,
54
+ metadata: {
55
+ path: absolutePath,
56
+ parentDir,
57
+ operation: "edit",
58
+ toolName: "edit_file"
59
+ }
60
+ };
61
+ },
62
+ /**
63
+ * Handle approved directory access - remember the directory for session
64
+ */
65
+ onApprovalGranted: (response) => {
66
+ if (!directoryApproval || !pendingApprovalParentDir) return;
67
+ const data = response.data;
68
+ const rememberDirectory = data?.rememberDirectory ?? false;
69
+ directoryApproval.addApproved(
70
+ pendingApprovalParentDir,
71
+ rememberDirectory ? "session" : "once"
72
+ );
73
+ pendingApprovalParentDir = void 0;
74
+ },
75
+ /**
76
+ * Generate preview for approval UI - shows diff without modifying file
77
+ * Throws ToolError.validationFailed() for validation errors (file not found, string not found)
78
+ */
79
+ generatePreview: async (input, _context) => {
80
+ const { file_path, old_string, new_string, replace_all } = input;
81
+ try {
82
+ const originalFile = await fileSystemService.readFile(file_path);
83
+ const originalContent = originalFile.content;
84
+ if (!replace_all) {
85
+ const occurrences = originalContent.split(old_string).length - 1;
86
+ if (occurrences > 1) {
87
+ throw ToolError.validationFailed(
88
+ "edit_file",
89
+ `String found ${occurrences} times in file. Set replace_all=true to replace all, or provide more context to make old_string unique.`,
90
+ { file_path, occurrences }
91
+ );
92
+ }
93
+ }
94
+ const newContent = replace_all ? originalContent.split(old_string).join(new_string) : originalContent.replace(old_string, new_string);
95
+ if (originalContent === newContent) {
96
+ throw ToolError.validationFailed(
97
+ "edit_file",
98
+ `String not found in file: "${old_string.slice(0, 50)}${old_string.length > 50 ? "..." : ""}"`,
99
+ { file_path, old_string_preview: old_string.slice(0, 100) }
100
+ );
101
+ }
102
+ return generateDiffPreview(file_path, originalContent, newContent);
103
+ } catch (error) {
104
+ if (error instanceof DextoRuntimeError && error.code === ToolErrorCode.VALIDATION_FAILED) {
105
+ throw error;
106
+ }
107
+ if (error instanceof DextoRuntimeError) {
108
+ throw ToolError.validationFailed("edit_file", error.message, {
109
+ file_path,
110
+ originalErrorCode: error.code
111
+ });
112
+ }
113
+ return null;
114
+ }
115
+ },
116
+ execute: async (input, _context) => {
117
+ const { file_path, old_string, new_string, replace_all } = input;
118
+ const originalFile = await fileSystemService.readFile(file_path);
119
+ const originalContent = originalFile.content;
120
+ const result = await fileSystemService.editFile(
121
+ file_path,
122
+ {
123
+ oldString: old_string,
124
+ newString: new_string,
125
+ replaceAll: replace_all
126
+ },
127
+ {
128
+ backup: true
129
+ // Always create backup for internal tools
130
+ }
131
+ );
132
+ const newFile = await fileSystemService.readFile(file_path);
133
+ const newContent = newFile.content;
134
+ const _display = generateDiffPreview(file_path, originalContent, newContent);
135
+ return {
136
+ success: result.success,
137
+ path: result.path,
138
+ changes_count: result.changesCount,
139
+ ...result.backupPath && { backup_path: result.backupPath },
140
+ _display
141
+ };
142
+ }
143
+ };
144
+ }
145
+ export {
146
+ createEditFileTool
147
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var error_codes_exports = {};
20
+ __export(error_codes_exports, {
21
+ FileSystemErrorCode: () => FileSystemErrorCode
22
+ });
23
+ module.exports = __toCommonJS(error_codes_exports);
24
+ var FileSystemErrorCode = /* @__PURE__ */ ((FileSystemErrorCode2) => {
25
+ FileSystemErrorCode2["FILE_NOT_FOUND"] = "FILESYSTEM_FILE_NOT_FOUND";
26
+ FileSystemErrorCode2["DIRECTORY_NOT_FOUND"] = "FILESYSTEM_DIRECTORY_NOT_FOUND";
27
+ FileSystemErrorCode2["PERMISSION_DENIED"] = "FILESYSTEM_PERMISSION_DENIED";
28
+ FileSystemErrorCode2["PATH_NOT_ALLOWED"] = "FILESYSTEM_PATH_NOT_ALLOWED";
29
+ FileSystemErrorCode2["PATH_BLOCKED"] = "FILESYSTEM_PATH_BLOCKED";
30
+ FileSystemErrorCode2["INVALID_PATH"] = "FILESYSTEM_INVALID_PATH";
31
+ FileSystemErrorCode2["PATH_TRAVERSAL_DETECTED"] = "FILESYSTEM_PATH_TRAVERSAL_DETECTED";
32
+ FileSystemErrorCode2["INVALID_FILE_EXTENSION"] = "FILESYSTEM_INVALID_FILE_EXTENSION";
33
+ FileSystemErrorCode2["INVALID_ENCODING"] = "FILESYSTEM_INVALID_ENCODING";
34
+ FileSystemErrorCode2["FILE_TOO_LARGE"] = "FILESYSTEM_FILE_TOO_LARGE";
35
+ FileSystemErrorCode2["TOO_MANY_RESULTS"] = "FILESYSTEM_TOO_MANY_RESULTS";
36
+ FileSystemErrorCode2["READ_FAILED"] = "FILESYSTEM_READ_FAILED";
37
+ FileSystemErrorCode2["WRITE_FAILED"] = "FILESYSTEM_WRITE_FAILED";
38
+ FileSystemErrorCode2["BACKUP_FAILED"] = "FILESYSTEM_BACKUP_FAILED";
39
+ FileSystemErrorCode2["EDIT_FAILED"] = "FILESYSTEM_EDIT_FAILED";
40
+ FileSystemErrorCode2["STRING_NOT_UNIQUE"] = "FILESYSTEM_STRING_NOT_UNIQUE";
41
+ FileSystemErrorCode2["STRING_NOT_FOUND"] = "FILESYSTEM_STRING_NOT_FOUND";
42
+ FileSystemErrorCode2["GLOB_FAILED"] = "FILESYSTEM_GLOB_FAILED";
43
+ FileSystemErrorCode2["SEARCH_FAILED"] = "FILESYSTEM_SEARCH_FAILED";
44
+ FileSystemErrorCode2["INVALID_PATTERN"] = "FILESYSTEM_INVALID_PATTERN";
45
+ FileSystemErrorCode2["REGEX_TIMEOUT"] = "FILESYSTEM_REGEX_TIMEOUT";
46
+ FileSystemErrorCode2["INVALID_CONFIG"] = "FILESYSTEM_INVALID_CONFIG";
47
+ FileSystemErrorCode2["SERVICE_NOT_INITIALIZED"] = "FILESYSTEM_SERVICE_NOT_INITIALIZED";
48
+ return FileSystemErrorCode2;
49
+ })(FileSystemErrorCode || {});
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ FileSystemErrorCode
53
+ });
@@ -0,0 +1,32 @@
1
+ /**
2
+ * FileSystem Service Error Codes
3
+ *
4
+ * Standardized error codes for file system operations
5
+ */
6
+ declare enum FileSystemErrorCode {
7
+ FILE_NOT_FOUND = "FILESYSTEM_FILE_NOT_FOUND",
8
+ DIRECTORY_NOT_FOUND = "FILESYSTEM_DIRECTORY_NOT_FOUND",
9
+ PERMISSION_DENIED = "FILESYSTEM_PERMISSION_DENIED",
10
+ PATH_NOT_ALLOWED = "FILESYSTEM_PATH_NOT_ALLOWED",
11
+ PATH_BLOCKED = "FILESYSTEM_PATH_BLOCKED",
12
+ INVALID_PATH = "FILESYSTEM_INVALID_PATH",
13
+ PATH_TRAVERSAL_DETECTED = "FILESYSTEM_PATH_TRAVERSAL_DETECTED",
14
+ INVALID_FILE_EXTENSION = "FILESYSTEM_INVALID_FILE_EXTENSION",
15
+ INVALID_ENCODING = "FILESYSTEM_INVALID_ENCODING",
16
+ FILE_TOO_LARGE = "FILESYSTEM_FILE_TOO_LARGE",
17
+ TOO_MANY_RESULTS = "FILESYSTEM_TOO_MANY_RESULTS",
18
+ READ_FAILED = "FILESYSTEM_READ_FAILED",
19
+ WRITE_FAILED = "FILESYSTEM_WRITE_FAILED",
20
+ BACKUP_FAILED = "FILESYSTEM_BACKUP_FAILED",
21
+ EDIT_FAILED = "FILESYSTEM_EDIT_FAILED",
22
+ STRING_NOT_UNIQUE = "FILESYSTEM_STRING_NOT_UNIQUE",
23
+ STRING_NOT_FOUND = "FILESYSTEM_STRING_NOT_FOUND",
24
+ GLOB_FAILED = "FILESYSTEM_GLOB_FAILED",
25
+ SEARCH_FAILED = "FILESYSTEM_SEARCH_FAILED",
26
+ INVALID_PATTERN = "FILESYSTEM_INVALID_PATTERN",
27
+ REGEX_TIMEOUT = "FILESYSTEM_REGEX_TIMEOUT",
28
+ INVALID_CONFIG = "FILESYSTEM_INVALID_CONFIG",
29
+ SERVICE_NOT_INITIALIZED = "FILESYSTEM_SERVICE_NOT_INITIALIZED"
30
+ }
31
+
32
+ export { FileSystemErrorCode };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * FileSystem Service Error Codes
3
+ *
4
+ * Standardized error codes for file system operations
5
+ */
6
+ declare enum FileSystemErrorCode {
7
+ FILE_NOT_FOUND = "FILESYSTEM_FILE_NOT_FOUND",
8
+ DIRECTORY_NOT_FOUND = "FILESYSTEM_DIRECTORY_NOT_FOUND",
9
+ PERMISSION_DENIED = "FILESYSTEM_PERMISSION_DENIED",
10
+ PATH_NOT_ALLOWED = "FILESYSTEM_PATH_NOT_ALLOWED",
11
+ PATH_BLOCKED = "FILESYSTEM_PATH_BLOCKED",
12
+ INVALID_PATH = "FILESYSTEM_INVALID_PATH",
13
+ PATH_TRAVERSAL_DETECTED = "FILESYSTEM_PATH_TRAVERSAL_DETECTED",
14
+ INVALID_FILE_EXTENSION = "FILESYSTEM_INVALID_FILE_EXTENSION",
15
+ INVALID_ENCODING = "FILESYSTEM_INVALID_ENCODING",
16
+ FILE_TOO_LARGE = "FILESYSTEM_FILE_TOO_LARGE",
17
+ TOO_MANY_RESULTS = "FILESYSTEM_TOO_MANY_RESULTS",
18
+ READ_FAILED = "FILESYSTEM_READ_FAILED",
19
+ WRITE_FAILED = "FILESYSTEM_WRITE_FAILED",
20
+ BACKUP_FAILED = "FILESYSTEM_BACKUP_FAILED",
21
+ EDIT_FAILED = "FILESYSTEM_EDIT_FAILED",
22
+ STRING_NOT_UNIQUE = "FILESYSTEM_STRING_NOT_UNIQUE",
23
+ STRING_NOT_FOUND = "FILESYSTEM_STRING_NOT_FOUND",
24
+ GLOB_FAILED = "FILESYSTEM_GLOB_FAILED",
25
+ SEARCH_FAILED = "FILESYSTEM_SEARCH_FAILED",
26
+ INVALID_PATTERN = "FILESYSTEM_INVALID_PATTERN",
27
+ REGEX_TIMEOUT = "FILESYSTEM_REGEX_TIMEOUT",
28
+ INVALID_CONFIG = "FILESYSTEM_INVALID_CONFIG",
29
+ SERVICE_NOT_INITIALIZED = "FILESYSTEM_SERVICE_NOT_INITIALIZED"
30
+ }
31
+
32
+ export { FileSystemErrorCode };
@@ -0,0 +1,29 @@
1
+ var FileSystemErrorCode = /* @__PURE__ */ ((FileSystemErrorCode2) => {
2
+ FileSystemErrorCode2["FILE_NOT_FOUND"] = "FILESYSTEM_FILE_NOT_FOUND";
3
+ FileSystemErrorCode2["DIRECTORY_NOT_FOUND"] = "FILESYSTEM_DIRECTORY_NOT_FOUND";
4
+ FileSystemErrorCode2["PERMISSION_DENIED"] = "FILESYSTEM_PERMISSION_DENIED";
5
+ FileSystemErrorCode2["PATH_NOT_ALLOWED"] = "FILESYSTEM_PATH_NOT_ALLOWED";
6
+ FileSystemErrorCode2["PATH_BLOCKED"] = "FILESYSTEM_PATH_BLOCKED";
7
+ FileSystemErrorCode2["INVALID_PATH"] = "FILESYSTEM_INVALID_PATH";
8
+ FileSystemErrorCode2["PATH_TRAVERSAL_DETECTED"] = "FILESYSTEM_PATH_TRAVERSAL_DETECTED";
9
+ FileSystemErrorCode2["INVALID_FILE_EXTENSION"] = "FILESYSTEM_INVALID_FILE_EXTENSION";
10
+ FileSystemErrorCode2["INVALID_ENCODING"] = "FILESYSTEM_INVALID_ENCODING";
11
+ FileSystemErrorCode2["FILE_TOO_LARGE"] = "FILESYSTEM_FILE_TOO_LARGE";
12
+ FileSystemErrorCode2["TOO_MANY_RESULTS"] = "FILESYSTEM_TOO_MANY_RESULTS";
13
+ FileSystemErrorCode2["READ_FAILED"] = "FILESYSTEM_READ_FAILED";
14
+ FileSystemErrorCode2["WRITE_FAILED"] = "FILESYSTEM_WRITE_FAILED";
15
+ FileSystemErrorCode2["BACKUP_FAILED"] = "FILESYSTEM_BACKUP_FAILED";
16
+ FileSystemErrorCode2["EDIT_FAILED"] = "FILESYSTEM_EDIT_FAILED";
17
+ FileSystemErrorCode2["STRING_NOT_UNIQUE"] = "FILESYSTEM_STRING_NOT_UNIQUE";
18
+ FileSystemErrorCode2["STRING_NOT_FOUND"] = "FILESYSTEM_STRING_NOT_FOUND";
19
+ FileSystemErrorCode2["GLOB_FAILED"] = "FILESYSTEM_GLOB_FAILED";
20
+ FileSystemErrorCode2["SEARCH_FAILED"] = "FILESYSTEM_SEARCH_FAILED";
21
+ FileSystemErrorCode2["INVALID_PATTERN"] = "FILESYSTEM_INVALID_PATTERN";
22
+ FileSystemErrorCode2["REGEX_TIMEOUT"] = "FILESYSTEM_REGEX_TIMEOUT";
23
+ FileSystemErrorCode2["INVALID_CONFIG"] = "FILESYSTEM_INVALID_CONFIG";
24
+ FileSystemErrorCode2["SERVICE_NOT_INITIALIZED"] = "FILESYSTEM_SERVICE_NOT_INITIALIZED";
25
+ return FileSystemErrorCode2;
26
+ })(FileSystemErrorCode || {});
27
+ export {
28
+ FileSystemErrorCode
29
+ };
@@ -0,0 +1,302 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var errors_exports = {};
20
+ __export(errors_exports, {
21
+ FileSystemError: () => FileSystemError
22
+ });
23
+ module.exports = __toCommonJS(errors_exports);
24
+ var import_core = require("@dexto/core");
25
+ var import_error_codes = require("./error-codes.js");
26
+ class FileSystemError {
27
+ constructor() {
28
+ }
29
+ /**
30
+ * File not found error
31
+ */
32
+ static fileNotFound(path) {
33
+ return new import_core.DextoRuntimeError(
34
+ import_error_codes.FileSystemErrorCode.FILE_NOT_FOUND,
35
+ import_core.ErrorScope.FILESYSTEM,
36
+ import_core.ErrorType.NOT_FOUND,
37
+ `File not found: ${path}`,
38
+ { path }
39
+ );
40
+ }
41
+ /**
42
+ * Directory not found error
43
+ */
44
+ static directoryNotFound(path) {
45
+ return new import_core.DextoRuntimeError(
46
+ import_error_codes.FileSystemErrorCode.DIRECTORY_NOT_FOUND,
47
+ import_core.ErrorScope.FILESYSTEM,
48
+ import_core.ErrorType.NOT_FOUND,
49
+ `Directory not found: ${path}`,
50
+ { path }
51
+ );
52
+ }
53
+ /**
54
+ * Permission denied error
55
+ */
56
+ static permissionDenied(path, operation) {
57
+ return new import_core.DextoRuntimeError(
58
+ import_error_codes.FileSystemErrorCode.PERMISSION_DENIED,
59
+ import_core.ErrorScope.FILESYSTEM,
60
+ import_core.ErrorType.FORBIDDEN,
61
+ `Permission denied: cannot ${operation} ${path}`,
62
+ { path, operation }
63
+ );
64
+ }
65
+ /**
66
+ * Path not allowed error
67
+ */
68
+ static pathNotAllowed(path, allowedPaths) {
69
+ return new import_core.DextoRuntimeError(
70
+ import_error_codes.FileSystemErrorCode.PATH_NOT_ALLOWED,
71
+ import_core.ErrorScope.FILESYSTEM,
72
+ import_core.ErrorType.USER,
73
+ `Path not allowed: ${path}. Must be within allowed paths: ${allowedPaths.join(", ")}`,
74
+ { path, allowedPaths },
75
+ "Ensure the path is within the configured allowed paths"
76
+ );
77
+ }
78
+ /**
79
+ * Path blocked error
80
+ */
81
+ static pathBlocked(path, reason) {
82
+ return new import_core.DextoRuntimeError(
83
+ import_error_codes.FileSystemErrorCode.PATH_BLOCKED,
84
+ import_core.ErrorScope.FILESYSTEM,
85
+ import_core.ErrorType.FORBIDDEN,
86
+ `Path is blocked: ${path}. Reason: ${reason}`,
87
+ { path, reason }
88
+ );
89
+ }
90
+ /**
91
+ * Invalid path error
92
+ */
93
+ static invalidPath(path, reason) {
94
+ return new import_core.DextoRuntimeError(
95
+ import_error_codes.FileSystemErrorCode.INVALID_PATH,
96
+ import_core.ErrorScope.FILESYSTEM,
97
+ import_core.ErrorType.USER,
98
+ `Invalid path: ${path}. ${reason}`,
99
+ { path, reason }
100
+ );
101
+ }
102
+ /**
103
+ * Path traversal detected
104
+ */
105
+ static pathTraversal(path) {
106
+ return new import_core.DextoRuntimeError(
107
+ import_error_codes.FileSystemErrorCode.PATH_TRAVERSAL_DETECTED,
108
+ import_core.ErrorScope.FILESYSTEM,
109
+ import_core.ErrorType.FORBIDDEN,
110
+ `Path traversal detected in: ${path}`,
111
+ { path }
112
+ );
113
+ }
114
+ /**
115
+ * Invalid file extension error
116
+ */
117
+ static invalidExtension(path, blockedExtensions) {
118
+ return new import_core.DextoRuntimeError(
119
+ import_error_codes.FileSystemErrorCode.INVALID_FILE_EXTENSION,
120
+ import_core.ErrorScope.FILESYSTEM,
121
+ import_core.ErrorType.USER,
122
+ `Invalid file extension: ${path}. Blocked extensions: ${blockedExtensions.join(", ")}`,
123
+ { path, blockedExtensions }
124
+ );
125
+ }
126
+ /**
127
+ * File too large error
128
+ */
129
+ static fileTooLarge(path, size, maxSize) {
130
+ return new import_core.DextoRuntimeError(
131
+ import_error_codes.FileSystemErrorCode.FILE_TOO_LARGE,
132
+ import_core.ErrorScope.FILESYSTEM,
133
+ import_core.ErrorType.USER,
134
+ `File too large: ${path} (${size} bytes). Maximum allowed: ${maxSize} bytes`,
135
+ { path, size, maxSize }
136
+ );
137
+ }
138
+ /**
139
+ * Too many results error
140
+ */
141
+ static tooManyResults(operation, count, maxResults) {
142
+ return new import_core.DextoRuntimeError(
143
+ import_error_codes.FileSystemErrorCode.TOO_MANY_RESULTS,
144
+ import_core.ErrorScope.FILESYSTEM,
145
+ import_core.ErrorType.USER,
146
+ `Too many results from ${operation}: ${count}. Maximum allowed: ${maxResults}`,
147
+ { operation, count, maxResults },
148
+ "Narrow your search pattern or increase maxResults limit"
149
+ );
150
+ }
151
+ /**
152
+ * Read operation failed
153
+ */
154
+ static readFailed(path, cause) {
155
+ return new import_core.DextoRuntimeError(
156
+ import_error_codes.FileSystemErrorCode.READ_FAILED,
157
+ import_core.ErrorScope.FILESYSTEM,
158
+ import_core.ErrorType.SYSTEM,
159
+ `Failed to read file: ${path}. ${cause}`,
160
+ { path, cause }
161
+ );
162
+ }
163
+ /**
164
+ * Write operation failed
165
+ */
166
+ static writeFailed(path, cause) {
167
+ return new import_core.DextoRuntimeError(
168
+ import_error_codes.FileSystemErrorCode.WRITE_FAILED,
169
+ import_core.ErrorScope.FILESYSTEM,
170
+ import_core.ErrorType.SYSTEM,
171
+ `Failed to write file: ${path}. ${cause}`,
172
+ { path, cause }
173
+ );
174
+ }
175
+ /**
176
+ * Backup creation failed
177
+ */
178
+ static backupFailed(path, cause) {
179
+ return new import_core.DextoRuntimeError(
180
+ import_error_codes.FileSystemErrorCode.BACKUP_FAILED,
181
+ import_core.ErrorScope.FILESYSTEM,
182
+ import_core.ErrorType.SYSTEM,
183
+ `Failed to create backup for: ${path}. ${cause}`,
184
+ { path, cause }
185
+ );
186
+ }
187
+ /**
188
+ * Edit operation failed
189
+ */
190
+ static editFailed(path, cause) {
191
+ return new import_core.DextoRuntimeError(
192
+ import_error_codes.FileSystemErrorCode.EDIT_FAILED,
193
+ import_core.ErrorScope.FILESYSTEM,
194
+ import_core.ErrorType.SYSTEM,
195
+ `Failed to edit file: ${path}. ${cause}`,
196
+ { path, cause }
197
+ );
198
+ }
199
+ /**
200
+ * String not unique error
201
+ */
202
+ static stringNotUnique(path, searchString, occurrences) {
203
+ return new import_core.DextoRuntimeError(
204
+ import_error_codes.FileSystemErrorCode.STRING_NOT_UNIQUE,
205
+ import_core.ErrorScope.FILESYSTEM,
206
+ import_core.ErrorType.USER,
207
+ `String is not unique in ${path}: "${searchString}" found ${occurrences} times. Use replaceAll=true or provide a more specific string.`,
208
+ { path, searchString, occurrences },
209
+ "Use replaceAll option or provide more context in the search string"
210
+ );
211
+ }
212
+ /**
213
+ * String not found error
214
+ */
215
+ static stringNotFound(path, searchString) {
216
+ return new import_core.DextoRuntimeError(
217
+ import_error_codes.FileSystemErrorCode.STRING_NOT_FOUND,
218
+ import_core.ErrorScope.FILESYSTEM,
219
+ import_core.ErrorType.USER,
220
+ `String not found in ${path}: "${searchString}"`,
221
+ { path, searchString }
222
+ );
223
+ }
224
+ /**
225
+ * Glob operation failed
226
+ */
227
+ static globFailed(pattern, cause) {
228
+ return new import_core.DextoRuntimeError(
229
+ import_error_codes.FileSystemErrorCode.GLOB_FAILED,
230
+ import_core.ErrorScope.FILESYSTEM,
231
+ import_core.ErrorType.SYSTEM,
232
+ `Glob operation failed for pattern: ${pattern}. ${cause}`,
233
+ { pattern, cause }
234
+ );
235
+ }
236
+ /**
237
+ * Search operation failed
238
+ */
239
+ static searchFailed(pattern, cause) {
240
+ return new import_core.DextoRuntimeError(
241
+ import_error_codes.FileSystemErrorCode.SEARCH_FAILED,
242
+ import_core.ErrorScope.FILESYSTEM,
243
+ import_core.ErrorType.SYSTEM,
244
+ `Search operation failed for pattern: ${pattern}. ${cause}`,
245
+ { pattern, cause }
246
+ );
247
+ }
248
+ /**
249
+ * Invalid pattern error
250
+ */
251
+ static invalidPattern(pattern, cause) {
252
+ return new import_core.DextoRuntimeError(
253
+ import_error_codes.FileSystemErrorCode.INVALID_PATTERN,
254
+ import_core.ErrorScope.FILESYSTEM,
255
+ import_core.ErrorType.USER,
256
+ `Invalid pattern: ${pattern}. ${cause}`,
257
+ { pattern, cause }
258
+ );
259
+ }
260
+ /**
261
+ * Regex timeout error
262
+ */
263
+ static regexTimeout(pattern) {
264
+ return new import_core.DextoRuntimeError(
265
+ import_error_codes.FileSystemErrorCode.REGEX_TIMEOUT,
266
+ import_core.ErrorScope.FILESYSTEM,
267
+ import_core.ErrorType.TIMEOUT,
268
+ `Regex operation timed out for pattern: ${pattern}`,
269
+ { pattern },
270
+ "Simplify your regex pattern or increase timeout"
271
+ );
272
+ }
273
+ /**
274
+ * Invalid configuration error
275
+ */
276
+ static invalidConfig(reason) {
277
+ return new import_core.DextoRuntimeError(
278
+ import_error_codes.FileSystemErrorCode.INVALID_CONFIG,
279
+ import_core.ErrorScope.FILESYSTEM,
280
+ import_core.ErrorType.USER,
281
+ `Invalid FileSystem configuration: ${reason}`,
282
+ { reason }
283
+ );
284
+ }
285
+ /**
286
+ * Service not initialized error
287
+ */
288
+ static notInitialized() {
289
+ return new import_core.DextoRuntimeError(
290
+ import_error_codes.FileSystemErrorCode.SERVICE_NOT_INITIALIZED,
291
+ import_core.ErrorScope.FILESYSTEM,
292
+ import_core.ErrorType.SYSTEM,
293
+ "FileSystemService has not been initialized",
294
+ {},
295
+ "Initialize the FileSystemService before using it"
296
+ );
297
+ }
298
+ }
299
+ // Annotate the CommonJS export names for ESM import in node:
300
+ 0 && (module.exports = {
301
+ FileSystemError
302
+ });