@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,112 @@
1
+ import { DextoRuntimeError } from '@dexto/core';
2
+
3
+ /**
4
+ * FileSystem Service Errors
5
+ *
6
+ * Error classes for file system operations
7
+ */
8
+
9
+ interface FileSystemErrorContext {
10
+ path?: string;
11
+ pattern?: string;
12
+ size?: number;
13
+ maxSize?: number;
14
+ encoding?: string;
15
+ operation?: string;
16
+ }
17
+ /**
18
+ * Factory class for creating FileSystem-related errors
19
+ */
20
+ declare class FileSystemError {
21
+ private constructor();
22
+ /**
23
+ * File not found error
24
+ */
25
+ static fileNotFound(path: string): DextoRuntimeError;
26
+ /**
27
+ * Directory not found error
28
+ */
29
+ static directoryNotFound(path: string): DextoRuntimeError;
30
+ /**
31
+ * Permission denied error
32
+ */
33
+ static permissionDenied(path: string, operation: string): DextoRuntimeError;
34
+ /**
35
+ * Path not allowed error
36
+ */
37
+ static pathNotAllowed(path: string, allowedPaths: string[]): DextoRuntimeError;
38
+ /**
39
+ * Path blocked error
40
+ */
41
+ static pathBlocked(path: string, reason: string): DextoRuntimeError;
42
+ /**
43
+ * Invalid path error
44
+ */
45
+ static invalidPath(path: string, reason: string): DextoRuntimeError;
46
+ /**
47
+ * Path traversal detected
48
+ */
49
+ static pathTraversal(path: string): DextoRuntimeError;
50
+ /**
51
+ * Invalid file extension error
52
+ */
53
+ static invalidExtension(path: string, blockedExtensions: string[]): DextoRuntimeError;
54
+ /**
55
+ * File too large error
56
+ */
57
+ static fileTooLarge(path: string, size: number, maxSize: number): DextoRuntimeError;
58
+ /**
59
+ * Too many results error
60
+ */
61
+ static tooManyResults(operation: string, count: number, maxResults: number): DextoRuntimeError;
62
+ /**
63
+ * Read operation failed
64
+ */
65
+ static readFailed(path: string, cause: string): DextoRuntimeError;
66
+ /**
67
+ * Write operation failed
68
+ */
69
+ static writeFailed(path: string, cause: string): DextoRuntimeError;
70
+ /**
71
+ * Backup creation failed
72
+ */
73
+ static backupFailed(path: string, cause: string): DextoRuntimeError;
74
+ /**
75
+ * Edit operation failed
76
+ */
77
+ static editFailed(path: string, cause: string): DextoRuntimeError;
78
+ /**
79
+ * String not unique error
80
+ */
81
+ static stringNotUnique(path: string, searchString: string, occurrences: number): DextoRuntimeError;
82
+ /**
83
+ * String not found error
84
+ */
85
+ static stringNotFound(path: string, searchString: string): DextoRuntimeError;
86
+ /**
87
+ * Glob operation failed
88
+ */
89
+ static globFailed(pattern: string, cause: string): DextoRuntimeError;
90
+ /**
91
+ * Search operation failed
92
+ */
93
+ static searchFailed(pattern: string, cause: string): DextoRuntimeError;
94
+ /**
95
+ * Invalid pattern error
96
+ */
97
+ static invalidPattern(pattern: string, cause: string): DextoRuntimeError;
98
+ /**
99
+ * Regex timeout error
100
+ */
101
+ static regexTimeout(pattern: string): DextoRuntimeError;
102
+ /**
103
+ * Invalid configuration error
104
+ */
105
+ static invalidConfig(reason: string): DextoRuntimeError;
106
+ /**
107
+ * Service not initialized error
108
+ */
109
+ static notInitialized(): DextoRuntimeError;
110
+ }
111
+
112
+ export { FileSystemError, type FileSystemErrorContext };
@@ -0,0 +1,112 @@
1
+ import { DextoRuntimeError } from '@dexto/core';
2
+
3
+ /**
4
+ * FileSystem Service Errors
5
+ *
6
+ * Error classes for file system operations
7
+ */
8
+
9
+ interface FileSystemErrorContext {
10
+ path?: string;
11
+ pattern?: string;
12
+ size?: number;
13
+ maxSize?: number;
14
+ encoding?: string;
15
+ operation?: string;
16
+ }
17
+ /**
18
+ * Factory class for creating FileSystem-related errors
19
+ */
20
+ declare class FileSystemError {
21
+ private constructor();
22
+ /**
23
+ * File not found error
24
+ */
25
+ static fileNotFound(path: string): DextoRuntimeError;
26
+ /**
27
+ * Directory not found error
28
+ */
29
+ static directoryNotFound(path: string): DextoRuntimeError;
30
+ /**
31
+ * Permission denied error
32
+ */
33
+ static permissionDenied(path: string, operation: string): DextoRuntimeError;
34
+ /**
35
+ * Path not allowed error
36
+ */
37
+ static pathNotAllowed(path: string, allowedPaths: string[]): DextoRuntimeError;
38
+ /**
39
+ * Path blocked error
40
+ */
41
+ static pathBlocked(path: string, reason: string): DextoRuntimeError;
42
+ /**
43
+ * Invalid path error
44
+ */
45
+ static invalidPath(path: string, reason: string): DextoRuntimeError;
46
+ /**
47
+ * Path traversal detected
48
+ */
49
+ static pathTraversal(path: string): DextoRuntimeError;
50
+ /**
51
+ * Invalid file extension error
52
+ */
53
+ static invalidExtension(path: string, blockedExtensions: string[]): DextoRuntimeError;
54
+ /**
55
+ * File too large error
56
+ */
57
+ static fileTooLarge(path: string, size: number, maxSize: number): DextoRuntimeError;
58
+ /**
59
+ * Too many results error
60
+ */
61
+ static tooManyResults(operation: string, count: number, maxResults: number): DextoRuntimeError;
62
+ /**
63
+ * Read operation failed
64
+ */
65
+ static readFailed(path: string, cause: string): DextoRuntimeError;
66
+ /**
67
+ * Write operation failed
68
+ */
69
+ static writeFailed(path: string, cause: string): DextoRuntimeError;
70
+ /**
71
+ * Backup creation failed
72
+ */
73
+ static backupFailed(path: string, cause: string): DextoRuntimeError;
74
+ /**
75
+ * Edit operation failed
76
+ */
77
+ static editFailed(path: string, cause: string): DextoRuntimeError;
78
+ /**
79
+ * String not unique error
80
+ */
81
+ static stringNotUnique(path: string, searchString: string, occurrences: number): DextoRuntimeError;
82
+ /**
83
+ * String not found error
84
+ */
85
+ static stringNotFound(path: string, searchString: string): DextoRuntimeError;
86
+ /**
87
+ * Glob operation failed
88
+ */
89
+ static globFailed(pattern: string, cause: string): DextoRuntimeError;
90
+ /**
91
+ * Search operation failed
92
+ */
93
+ static searchFailed(pattern: string, cause: string): DextoRuntimeError;
94
+ /**
95
+ * Invalid pattern error
96
+ */
97
+ static invalidPattern(pattern: string, cause: string): DextoRuntimeError;
98
+ /**
99
+ * Regex timeout error
100
+ */
101
+ static regexTimeout(pattern: string): DextoRuntimeError;
102
+ /**
103
+ * Invalid configuration error
104
+ */
105
+ static invalidConfig(reason: string): DextoRuntimeError;
106
+ /**
107
+ * Service not initialized error
108
+ */
109
+ static notInitialized(): DextoRuntimeError;
110
+ }
111
+
112
+ export { FileSystemError, type FileSystemErrorContext };
package/dist/errors.js ADDED
@@ -0,0 +1,278 @@
1
+ import { DextoRuntimeError, ErrorScope, ErrorType } from "@dexto/core";
2
+ import { FileSystemErrorCode } from "./error-codes.js";
3
+ class FileSystemError {
4
+ constructor() {
5
+ }
6
+ /**
7
+ * File not found error
8
+ */
9
+ static fileNotFound(path) {
10
+ return new DextoRuntimeError(
11
+ FileSystemErrorCode.FILE_NOT_FOUND,
12
+ ErrorScope.FILESYSTEM,
13
+ ErrorType.NOT_FOUND,
14
+ `File not found: ${path}`,
15
+ { path }
16
+ );
17
+ }
18
+ /**
19
+ * Directory not found error
20
+ */
21
+ static directoryNotFound(path) {
22
+ return new DextoRuntimeError(
23
+ FileSystemErrorCode.DIRECTORY_NOT_FOUND,
24
+ ErrorScope.FILESYSTEM,
25
+ ErrorType.NOT_FOUND,
26
+ `Directory not found: ${path}`,
27
+ { path }
28
+ );
29
+ }
30
+ /**
31
+ * Permission denied error
32
+ */
33
+ static permissionDenied(path, operation) {
34
+ return new DextoRuntimeError(
35
+ FileSystemErrorCode.PERMISSION_DENIED,
36
+ ErrorScope.FILESYSTEM,
37
+ ErrorType.FORBIDDEN,
38
+ `Permission denied: cannot ${operation} ${path}`,
39
+ { path, operation }
40
+ );
41
+ }
42
+ /**
43
+ * Path not allowed error
44
+ */
45
+ static pathNotAllowed(path, allowedPaths) {
46
+ return new DextoRuntimeError(
47
+ FileSystemErrorCode.PATH_NOT_ALLOWED,
48
+ ErrorScope.FILESYSTEM,
49
+ ErrorType.USER,
50
+ `Path not allowed: ${path}. Must be within allowed paths: ${allowedPaths.join(", ")}`,
51
+ { path, allowedPaths },
52
+ "Ensure the path is within the configured allowed paths"
53
+ );
54
+ }
55
+ /**
56
+ * Path blocked error
57
+ */
58
+ static pathBlocked(path, reason) {
59
+ return new DextoRuntimeError(
60
+ FileSystemErrorCode.PATH_BLOCKED,
61
+ ErrorScope.FILESYSTEM,
62
+ ErrorType.FORBIDDEN,
63
+ `Path is blocked: ${path}. Reason: ${reason}`,
64
+ { path, reason }
65
+ );
66
+ }
67
+ /**
68
+ * Invalid path error
69
+ */
70
+ static invalidPath(path, reason) {
71
+ return new DextoRuntimeError(
72
+ FileSystemErrorCode.INVALID_PATH,
73
+ ErrorScope.FILESYSTEM,
74
+ ErrorType.USER,
75
+ `Invalid path: ${path}. ${reason}`,
76
+ { path, reason }
77
+ );
78
+ }
79
+ /**
80
+ * Path traversal detected
81
+ */
82
+ static pathTraversal(path) {
83
+ return new DextoRuntimeError(
84
+ FileSystemErrorCode.PATH_TRAVERSAL_DETECTED,
85
+ ErrorScope.FILESYSTEM,
86
+ ErrorType.FORBIDDEN,
87
+ `Path traversal detected in: ${path}`,
88
+ { path }
89
+ );
90
+ }
91
+ /**
92
+ * Invalid file extension error
93
+ */
94
+ static invalidExtension(path, blockedExtensions) {
95
+ return new DextoRuntimeError(
96
+ FileSystemErrorCode.INVALID_FILE_EXTENSION,
97
+ ErrorScope.FILESYSTEM,
98
+ ErrorType.USER,
99
+ `Invalid file extension: ${path}. Blocked extensions: ${blockedExtensions.join(", ")}`,
100
+ { path, blockedExtensions }
101
+ );
102
+ }
103
+ /**
104
+ * File too large error
105
+ */
106
+ static fileTooLarge(path, size, maxSize) {
107
+ return new DextoRuntimeError(
108
+ FileSystemErrorCode.FILE_TOO_LARGE,
109
+ ErrorScope.FILESYSTEM,
110
+ ErrorType.USER,
111
+ `File too large: ${path} (${size} bytes). Maximum allowed: ${maxSize} bytes`,
112
+ { path, size, maxSize }
113
+ );
114
+ }
115
+ /**
116
+ * Too many results error
117
+ */
118
+ static tooManyResults(operation, count, maxResults) {
119
+ return new DextoRuntimeError(
120
+ FileSystemErrorCode.TOO_MANY_RESULTS,
121
+ ErrorScope.FILESYSTEM,
122
+ ErrorType.USER,
123
+ `Too many results from ${operation}: ${count}. Maximum allowed: ${maxResults}`,
124
+ { operation, count, maxResults },
125
+ "Narrow your search pattern or increase maxResults limit"
126
+ );
127
+ }
128
+ /**
129
+ * Read operation failed
130
+ */
131
+ static readFailed(path, cause) {
132
+ return new DextoRuntimeError(
133
+ FileSystemErrorCode.READ_FAILED,
134
+ ErrorScope.FILESYSTEM,
135
+ ErrorType.SYSTEM,
136
+ `Failed to read file: ${path}. ${cause}`,
137
+ { path, cause }
138
+ );
139
+ }
140
+ /**
141
+ * Write operation failed
142
+ */
143
+ static writeFailed(path, cause) {
144
+ return new DextoRuntimeError(
145
+ FileSystemErrorCode.WRITE_FAILED,
146
+ ErrorScope.FILESYSTEM,
147
+ ErrorType.SYSTEM,
148
+ `Failed to write file: ${path}. ${cause}`,
149
+ { path, cause }
150
+ );
151
+ }
152
+ /**
153
+ * Backup creation failed
154
+ */
155
+ static backupFailed(path, cause) {
156
+ return new DextoRuntimeError(
157
+ FileSystemErrorCode.BACKUP_FAILED,
158
+ ErrorScope.FILESYSTEM,
159
+ ErrorType.SYSTEM,
160
+ `Failed to create backup for: ${path}. ${cause}`,
161
+ { path, cause }
162
+ );
163
+ }
164
+ /**
165
+ * Edit operation failed
166
+ */
167
+ static editFailed(path, cause) {
168
+ return new DextoRuntimeError(
169
+ FileSystemErrorCode.EDIT_FAILED,
170
+ ErrorScope.FILESYSTEM,
171
+ ErrorType.SYSTEM,
172
+ `Failed to edit file: ${path}. ${cause}`,
173
+ { path, cause }
174
+ );
175
+ }
176
+ /**
177
+ * String not unique error
178
+ */
179
+ static stringNotUnique(path, searchString, occurrences) {
180
+ return new DextoRuntimeError(
181
+ FileSystemErrorCode.STRING_NOT_UNIQUE,
182
+ ErrorScope.FILESYSTEM,
183
+ ErrorType.USER,
184
+ `String is not unique in ${path}: "${searchString}" found ${occurrences} times. Use replaceAll=true or provide a more specific string.`,
185
+ { path, searchString, occurrences },
186
+ "Use replaceAll option or provide more context in the search string"
187
+ );
188
+ }
189
+ /**
190
+ * String not found error
191
+ */
192
+ static stringNotFound(path, searchString) {
193
+ return new DextoRuntimeError(
194
+ FileSystemErrorCode.STRING_NOT_FOUND,
195
+ ErrorScope.FILESYSTEM,
196
+ ErrorType.USER,
197
+ `String not found in ${path}: "${searchString}"`,
198
+ { path, searchString }
199
+ );
200
+ }
201
+ /**
202
+ * Glob operation failed
203
+ */
204
+ static globFailed(pattern, cause) {
205
+ return new DextoRuntimeError(
206
+ FileSystemErrorCode.GLOB_FAILED,
207
+ ErrorScope.FILESYSTEM,
208
+ ErrorType.SYSTEM,
209
+ `Glob operation failed for pattern: ${pattern}. ${cause}`,
210
+ { pattern, cause }
211
+ );
212
+ }
213
+ /**
214
+ * Search operation failed
215
+ */
216
+ static searchFailed(pattern, cause) {
217
+ return new DextoRuntimeError(
218
+ FileSystemErrorCode.SEARCH_FAILED,
219
+ ErrorScope.FILESYSTEM,
220
+ ErrorType.SYSTEM,
221
+ `Search operation failed for pattern: ${pattern}. ${cause}`,
222
+ { pattern, cause }
223
+ );
224
+ }
225
+ /**
226
+ * Invalid pattern error
227
+ */
228
+ static invalidPattern(pattern, cause) {
229
+ return new DextoRuntimeError(
230
+ FileSystemErrorCode.INVALID_PATTERN,
231
+ ErrorScope.FILESYSTEM,
232
+ ErrorType.USER,
233
+ `Invalid pattern: ${pattern}. ${cause}`,
234
+ { pattern, cause }
235
+ );
236
+ }
237
+ /**
238
+ * Regex timeout error
239
+ */
240
+ static regexTimeout(pattern) {
241
+ return new DextoRuntimeError(
242
+ FileSystemErrorCode.REGEX_TIMEOUT,
243
+ ErrorScope.FILESYSTEM,
244
+ ErrorType.TIMEOUT,
245
+ `Regex operation timed out for pattern: ${pattern}`,
246
+ { pattern },
247
+ "Simplify your regex pattern or increase timeout"
248
+ );
249
+ }
250
+ /**
251
+ * Invalid configuration error
252
+ */
253
+ static invalidConfig(reason) {
254
+ return new DextoRuntimeError(
255
+ FileSystemErrorCode.INVALID_CONFIG,
256
+ ErrorScope.FILESYSTEM,
257
+ ErrorType.USER,
258
+ `Invalid FileSystem configuration: ${reason}`,
259
+ { reason }
260
+ );
261
+ }
262
+ /**
263
+ * Service not initialized error
264
+ */
265
+ static notInitialized() {
266
+ return new DextoRuntimeError(
267
+ FileSystemErrorCode.SERVICE_NOT_INITIALIZED,
268
+ ErrorScope.FILESYSTEM,
269
+ ErrorType.SYSTEM,
270
+ "FileSystemService has not been initialized",
271
+ {},
272
+ "Initialize the FileSystemService before using it"
273
+ );
274
+ }
275
+ }
276
+ export {
277
+ FileSystemError
278
+ };
@@ -0,0 +1,16 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var file_tool_types_exports = {};
16
+ module.exports = __toCommonJS(file_tool_types_exports);
@@ -0,0 +1,46 @@
1
+ import { FileSystemService } from './filesystem-service.cjs';
2
+ import '@dexto/core';
3
+ import './types.cjs';
4
+
5
+ /**
6
+ * File Tool Types
7
+ *
8
+ * Types shared between file tools for directory approval support.
9
+ */
10
+
11
+ /**
12
+ * Callbacks for directory access approval.
13
+ * Allows file tools to check and request approval for accessing paths
14
+ * outside the configured working directory.
15
+ */
16
+ interface DirectoryApprovalCallbacks {
17
+ /**
18
+ * Check if a path is within any session-approved directory.
19
+ * Used to determine if directory approval prompt is needed.
20
+ * @param filePath The file path to check (absolute or relative)
21
+ * @returns true if path is in a session-approved directory
22
+ */
23
+ isSessionApproved: (filePath: string) => boolean;
24
+ /**
25
+ * Add a directory to the approved list for this session.
26
+ * Called after user approves directory access.
27
+ * @param directory Absolute path to the directory to approve
28
+ * @param type 'session' (remembered) or 'once' (single use)
29
+ */
30
+ addApproved: (directory: string, type: 'session' | 'once') => void;
31
+ }
32
+ /**
33
+ * Options for creating file tools with directory approval support
34
+ */
35
+ interface FileToolOptions {
36
+ /** FileSystemService instance for file operations */
37
+ fileSystemService: FileSystemService;
38
+ /**
39
+ * Optional callbacks for directory approval.
40
+ * If provided, file tools can request approval for accessing paths
41
+ * outside the configured working directory.
42
+ */
43
+ directoryApproval?: DirectoryApprovalCallbacks | undefined;
44
+ }
45
+
46
+ export type { DirectoryApprovalCallbacks, FileToolOptions };
@@ -0,0 +1,46 @@
1
+ import { FileSystemService } from './filesystem-service.js';
2
+ import '@dexto/core';
3
+ import './types.js';
4
+
5
+ /**
6
+ * File Tool Types
7
+ *
8
+ * Types shared between file tools for directory approval support.
9
+ */
10
+
11
+ /**
12
+ * Callbacks for directory access approval.
13
+ * Allows file tools to check and request approval for accessing paths
14
+ * outside the configured working directory.
15
+ */
16
+ interface DirectoryApprovalCallbacks {
17
+ /**
18
+ * Check if a path is within any session-approved directory.
19
+ * Used to determine if directory approval prompt is needed.
20
+ * @param filePath The file path to check (absolute or relative)
21
+ * @returns true if path is in a session-approved directory
22
+ */
23
+ isSessionApproved: (filePath: string) => boolean;
24
+ /**
25
+ * Add a directory to the approved list for this session.
26
+ * Called after user approves directory access.
27
+ * @param directory Absolute path to the directory to approve
28
+ * @param type 'session' (remembered) or 'once' (single use)
29
+ */
30
+ addApproved: (directory: string, type: 'session' | 'once') => void;
31
+ }
32
+ /**
33
+ * Options for creating file tools with directory approval support
34
+ */
35
+ interface FileToolOptions {
36
+ /** FileSystemService instance for file operations */
37
+ fileSystemService: FileSystemService;
38
+ /**
39
+ * Optional callbacks for directory approval.
40
+ * If provided, file tools can request approval for accessing paths
41
+ * outside the configured working directory.
42
+ */
43
+ directoryApproval?: DirectoryApprovalCallbacks | undefined;
44
+ }
45
+
46
+ export type { DirectoryApprovalCallbacks, FileToolOptions };
File without changes